better tracking of key events when focus is lost

This commit is contained in:
David Rose 2003-01-10 21:05:51 +00:00
parent 05ba6d44b5
commit 78a3290325
2 changed files with 1489 additions and 1476 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,164 +1,169 @@
// Filename: winGraphicsWindow.h // Filename: winGraphicsWindow.h
// Created by: drose (20Dec02) // Created by: drose (20Dec02)
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// //
// PANDA 3D SOFTWARE // PANDA 3D SOFTWARE
// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved
// //
// All use of this software is subject to the terms of the Panda 3d // All use of this software is subject to the terms of the Panda 3d
// Software license. You should have received a copy of this license // Software license. You should have received a copy of this license
// along with this source code; you will also find a current copy of // along with this source code; you will also find a current copy of
// the license at http://www.panda3d.org/license.txt . // the license at http://www.panda3d.org/license.txt .
// //
// To contact the maintainers of this program write to // To contact the maintainers of this program write to
// panda3d@yahoogroups.com . // panda3d@yahoogroups.com .
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
#ifndef WINGRAPHICSWINDOW_H #ifndef WINGRAPHICSWINDOW_H
#define WINGRAPHICSWINDOW_H #define WINGRAPHICSWINDOW_H
// include win32 defns for everything up to XP, and assume I'm smart // include win32 defns for everything up to XP, and assume I'm smart
// enough to use GetProcAddress for backward compat on w95/w98 for // enough to use GetProcAddress for backward compat on w95/w98 for
// newer fns // newer fns
#define _WIN32_WINNT 0x0501 #define _WIN32_WINNT 0x0501
#define WINDOWS_LEAN_AND_MEAN #define WINDOWS_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#undef WINDOWS_LEAN_AND_MEAN #undef WINDOWS_LEAN_AND_MEAN
#include "pandabase.h" #include "pandabase.h"
#include "graphicsWindow.h" #include "graphicsWindow.h"
class WinGraphicsPipe; class WinGraphicsPipe;
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Class : WinGraphicsWindow // Class : WinGraphicsWindow
// Description : An abstract base class for glGraphicsWindow and // Description : An abstract base class for glGraphicsWindow and
// dxGraphicsWindow (and, in general, graphics windows // dxGraphicsWindow (and, in general, graphics windows
// that interface with the Microsoft Windows API). // that interface with the Microsoft Windows API).
// //
// This class includes all the code for manipulating // This class includes all the code for manipulating
// windows themselves: opening them, closing them, // windows themselves: opening them, closing them,
// responding to user keyboard and mouse input, and so // responding to user keyboard and mouse input, and so
// on. It does not make any 3-D rendering calls into // on. It does not make any 3-D rendering calls into
// the window; that is the province of the // the window; that is the province of the
// GraphicsStateGuardian. // GraphicsStateGuardian.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
class EXPCL_PANDAWIN WinGraphicsWindow : public GraphicsWindow { class EXPCL_PANDAWIN WinGraphicsWindow : public GraphicsWindow {
public: public:
WinGraphicsWindow(GraphicsPipe *pipe); WinGraphicsWindow(GraphicsPipe *pipe);
virtual ~WinGraphicsWindow(); virtual ~WinGraphicsWindow();
virtual void begin_flip(); virtual void begin_flip();
virtual void process_events(); virtual void process_events();
virtual void set_properties_now(WindowProperties &properties); virtual void set_properties_now(WindowProperties &properties);
protected: protected:
virtual void close_window(); virtual void close_window();
virtual bool open_window(); virtual bool open_window();
virtual void fullscreen_minimized(WindowProperties &properties); virtual void fullscreen_minimized(WindowProperties &properties);
virtual void fullscreen_restored(WindowProperties &properties); virtual void fullscreen_restored(WindowProperties &properties);
virtual bool do_reshape_request(int x_origin, int y_origin, virtual bool do_reshape_request(int x_origin, int y_origin,
int x_size, int y_size); int x_size, int y_size);
virtual void handle_reshape(); virtual void handle_reshape();
virtual bool do_fullscreen_resize(int x_size, int y_size); virtual bool do_fullscreen_resize(int x_size, int y_size);
void get_client_rect_screen(HWND hwnd, RECT *view_rect); void get_client_rect_screen(HWND hwnd, RECT *view_rect);
private: private:
bool open_fullscreen_window(); bool open_fullscreen_window();
bool open_regular_window(); bool open_regular_window();
void track_mouse_leaving(HWND hwnd); void track_mouse_leaving(HWND hwnd);
LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); LONG window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
static LONG WINAPI static LONG WINAPI
static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); static_window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
static void process_1_event(); static void process_1_event();
INLINE void handle_mouse_motion(int x, int y); INLINE void handle_mouse_motion(int x, int y);
INLINE void handle_mouse_exit(void); INLINE void handle_mouse_exit(void);
INLINE void handle_keypress(ButtonHandle key, int x, int y); INLINE void handle_keypress(ButtonHandle key, int x, int y);
INLINE void handle_keyrelease(ButtonHandle key); INLINE void handle_keyrelease(ButtonHandle key);
ButtonHandle lookup_key(WPARAM wparam) const; ButtonHandle lookup_key(WPARAM wparam) const;
INLINE int translate_mouse(int pos) const; INLINE int translate_mouse(int pos) const;
INLINE void set_cursor_in_window(); INLINE void set_cursor_in_window();
INLINE void set_cursor_out_of_window(); INLINE void set_cursor_out_of_window();
static void update_cursor_window(WinGraphicsWindow *to_window); static void update_cursor_window(WinGraphicsWindow *to_window);
static void register_window_class(); static void register_window_class();
static bool find_acceptable_display_mode(DWORD dwWidth, DWORD dwHeight, static bool find_acceptable_display_mode(DWORD dwWidth, DWORD dwHeight,
DWORD bpp, DEVMODE &dm); DWORD bpp, DEVMODE &dm);
static void show_error_message(DWORD message_id = 0); static void show_error_message(DWORD message_id = 0);
protected: protected:
HWND _mwindow; HWND _mwindow;
private: private:
bool _ime_open; bool _ime_open;
bool _ime_active; bool _ime_active;
bool _ime_composition_w; bool _ime_composition_w;
bool _tracking_mouse_leaving; bool _tracking_mouse_leaving;
bool _maximized; bool _maximized;
DEVMODE _fullscreen_display_mode; DEVMODE _fullscreen_display_mode;
static bool _got_dynamic_fns; static bool _got_dynamic_fns;
typedef BOOL (WINAPI *PFN_TRACKMOUSEEVENT)(LPTRACKMOUSEEVENT); typedef BOOL (WINAPI *PFN_TRACKMOUSEEVENT)(LPTRACKMOUSEEVENT);
static PFN_TRACKMOUSEEVENT _pfnTrackMouseEvent; static PFN_TRACKMOUSEEVENT _pfnTrackMouseEvent;
protected: // This is used to remember the state of the keyboard when keyboard
static bool _loaded_custom_cursor; // focus is lost.
static HCURSOR _mouse_cursor; static const int num_virtual_keys = 256;
static const char * const _window_class_name; BYTE _keyboard_state[num_virtual_keys];
static bool _window_class_registered;
protected:
private: static bool _loaded_custom_cursor;
// We need this map to support per-window calls to window_proc(). static HCURSOR _mouse_cursor;
typedef map<HWND, WinGraphicsWindow *> WindowHandles; static const char * const _window_class_name;
static WindowHandles _window_handles; static bool _window_class_registered;
// And we need a static pointer to the current WinGraphicsWindow we private:
// are creating at the moment, since CreateWindow() starts // We need this map to support per-window calls to window_proc().
// generating window events before it gives us the window handle. typedef map<HWND, WinGraphicsWindow *> WindowHandles;
static WinGraphicsWindow *_creating_window; static WindowHandles _window_handles;
// This tracks the current GraphicsWindow whose client area contains // And we need a static pointer to the current WinGraphicsWindow we
// the mouse. There will only be one of these at a time, and // are creating at the moment, since CreateWindow() starts
// storing the pointer here allows us to handle ambiguities in the // generating window events before it gives us the window handle.
// order in which messages are passed from Windows to the various static WinGraphicsWindow *_creating_window;
// windows we manage. This pointer is used by
// set_cursor_in_window() to determine when it is time to call // This tracks the current GraphicsWindow whose client area contains
// update_cursor() to hide the cursor (or do other related // the mouse. There will only be one of these at a time, and
// operations). // storing the pointer here allows us to handle ambiguities in the
static WinGraphicsWindow *_cursor_window; // order in which messages are passed from Windows to the various
static bool _cursor_hidden; // windows we manage. This pointer is used by
static bool _got_saved_params; // set_cursor_in_window() to determine when it is time to call
static int _saved_mouse_trails; // update_cursor() to hide the cursor (or do other related
static bool _saved_cursor_shadow; // operations).
static bool _saved_mouse_vanish; static WinGraphicsWindow *_cursor_window;
static bool _cursor_hidden;
public: static bool _got_saved_params;
static TypeHandle get_class_type() { static int _saved_mouse_trails;
return _type_handle; static bool _saved_cursor_shadow;
} static bool _saved_mouse_vanish;
static void init_type() {
GraphicsWindow::init_type(); public:
register_type(_type_handle, "WinGraphicsWindow", static TypeHandle get_class_type() {
GraphicsWindow::get_class_type()); return _type_handle;
} }
virtual TypeHandle get_type() const { static void init_type() {
return get_class_type(); GraphicsWindow::init_type();
} register_type(_type_handle, "WinGraphicsWindow",
virtual TypeHandle force_init_type() {init_type(); return get_class_type();} GraphicsWindow::get_class_type());
}
private: virtual TypeHandle get_type() const {
static TypeHandle _type_handle; return get_class_type();
}; }
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
#include "winGraphicsWindow.I"
private:
#endif static TypeHandle _type_handle;
};
#include "winGraphicsWindow.I"
#endif