Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/windisplay/winGraphicsWindow.h

Go to the documentation of this file.
00001 // Filename: winGraphicsWindow.h
00002 // Created by:  drose (20Dec02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef WINGRAPHICSWINDOW_H
00020 #define WINGRAPHICSWINDOW_H
00021 
00022 // include win32 defns for everything up to WinServer2003, and assume I'm smart
00023 // enough to use GetProcAddress for backward compat on w95/w98 for
00024 // newer fns
00025 #define _WIN32_WINNT 0x0502
00026 
00027 #define WINDOWS_LEAN_AND_MEAN
00028 #include <windows.h>
00029 #undef WINDOWS_LEAN_AND_MEAN
00030 
00031 #include "pandabase.h"
00032 #include "graphicsWindow.h"
00033 
00034 class WinGraphicsPipe;
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //       Class : WinGraphicsWindow
00038 // Description : An abstract base class for glGraphicsWindow and
00039 //               dxGraphicsWindow (and, in general, graphics windows
00040 //               that interface with the Microsoft Windows API).
00041 //
00042 //               This class includes all the code for manipulating
00043 //               windows themselves: opening them, closing them,
00044 //               responding to user keyboard and mouse input, and so
00045 //               on.  It does not make any 3-D rendering calls into
00046 //               the window; that is the province of the
00047 //               GraphicsStateGuardian.
00048 ////////////////////////////////////////////////////////////////////
00049 class EXPCL_PANDAWIN WinGraphicsWindow : public GraphicsWindow {
00050 public:
00051   WinGraphicsWindow(GraphicsPipe *pipe, GraphicsStateGuardian *gsg);
00052   virtual ~WinGraphicsWindow();
00053 
00054   virtual void begin_flip();
00055 
00056   virtual void process_events();
00057   virtual void set_properties_now(WindowProperties &properties);
00058   virtual LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
00059   static LONG WINAPI static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
00060   virtual bool handle_mouse_motion(int x, int y);
00061   virtual void handle_mouse_exit(void);
00062 
00063 
00064 protected:
00065   virtual void close_window();
00066   virtual bool open_window();
00067   virtual void fullscreen_minimized(WindowProperties &properties);
00068   virtual void fullscreen_restored(WindowProperties &properties);
00069 
00070   virtual bool do_reshape_request(int x_origin, int y_origin, 
00071                                   int x_size, int y_size);
00072 
00073   virtual void handle_reshape();
00074   virtual bool do_fullscreen_resize(int x_size, int y_size);
00075 
00076   virtual void reconsider_fullscreen_size(DWORD &x_size, DWORD &y_size, 
00077                                           DWORD &bitdepth);
00078 
00079 private:
00080   bool open_fullscreen_window();
00081   bool open_regular_window();
00082   void track_mouse_leaving(HWND hwnd);
00083 
00084   static void process_1_event();
00085 
00086   INLINE void handle_keypress(ButtonHandle key, int x, int y);
00087   INLINE void handle_keyresume(ButtonHandle key);
00088   INLINE void handle_keyrelease(ButtonHandle key);
00089   ButtonHandle lookup_key(WPARAM wparam) const;
00090   INLINE int translate_mouse(int pos) const;
00091   INLINE void set_cursor_in_window();
00092   INLINE void set_cursor_out_of_window();
00093   static void update_cursor_window(WinGraphicsWindow *to_window);
00094 
00095   static void register_window_class();
00096   static bool find_acceptable_display_mode(DWORD dwWidth, DWORD dwHeight,
00097                                            DWORD bpp, DEVMODE &dm);
00098   static void show_error_message(DWORD message_id = 0);
00099 
00100 protected:
00101   HWND _hWnd;
00102 
00103 private:
00104   bool _ime_open;
00105   bool _ime_active;
00106   bool _ime_composition_w;
00107   bool _tracking_mouse_leaving;
00108   bool _maximized;
00109   bool _bCursor_in_WindowClientArea;
00110   DEVMODE _fullscreen_display_mode;
00111 
00112   // This is used to remember the state of the keyboard when keyboard
00113   // focus is lost.
00114   static const int num_virtual_keys = 256;
00115   BYTE _keyboard_state[num_virtual_keys];
00116 
00117 protected:
00118   static bool _loaded_custom_cursor;
00119   static HCURSOR _mouse_cursor;
00120   static const char * const _window_class_name;
00121   static bool _window_class_registered;
00122 
00123 private:
00124   // We need this map to support per-window calls to window_proc().
00125   typedef map<HWND, WinGraphicsWindow *> WindowHandles;
00126   static WindowHandles _window_handles;
00127 
00128   // And we need a static pointer to the current WinGraphicsWindow we
00129   // are creating at the moment, since CreateWindow() starts
00130   // generating window events before it gives us the window handle.
00131   static WinGraphicsWindow *_creating_window;
00132 
00133   // This tracks the current GraphicsWindow whose client area contains
00134   // the mouse.  There will only be one of these at a time, and
00135   // storing the pointer here allows us to handle ambiguities in the
00136   // order in which messages are passed from Windows to the various
00137   // windows we manage.  This pointer is used by
00138   // set_cursor_in_window() to determine when it is time to call
00139   // update_cursor() to hide the cursor (or do other related
00140   // operations).
00141   static WinGraphicsWindow *_cursor_window;
00142   static bool _cursor_hidden;
00143   static bool _got_saved_params;
00144   static int _saved_mouse_trails;
00145   static BOOL _saved_cursor_shadow;
00146   static BOOL _saved_mouse_vanish;
00147 
00148 public:
00149   static TypeHandle get_class_type() {
00150     return _type_handle;
00151   }
00152   static void init_type() {
00153     GraphicsWindow::init_type();
00154     register_type(_type_handle, "WinGraphicsWindow",
00155                   GraphicsWindow::get_class_type());
00156   }
00157   virtual TypeHandle get_type() const {
00158     return get_class_type();
00159   }
00160   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00161 
00162 private:
00163   static TypeHandle _type_handle;
00164 };
00165 
00166 
00167 #define PRINT_LAST_ERROR 0
00168 extern EXPCL_PANDAWIN void PrintErrorMessage(DWORD msgID);
00169 extern EXPCL_PANDAWIN void ClearToBlack(HWND hWnd, const WindowProperties &props);
00170 extern EXPCL_PANDAWIN void get_client_rect_screen(HWND hwnd, RECT *view_rect);
00171 
00172 #include "winGraphicsWindow.I"
00173 
00174 #endif

Generated on Fri May 2 00:44:48 2003 for Panda by doxygen1.3