Fix crash that may occur when handle_reshape in called before the window is fully created.

Not sure if this affects any renderer but the tinydisplay renderer.
This commit is contained in:
rdb 2015-01-05 22:38:09 +01:00
parent 8a5f07f9c3
commit b19ff5b10e
3 changed files with 148 additions and 143 deletions

View File

@ -33,7 +33,7 @@ TypeHandle TinyWinGraphicsWindow::_type_handle;
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
TinyWinGraphicsWindow:: TinyWinGraphicsWindow::
TinyWinGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe, TinyWinGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
const string &name, const string &name,
const FrameBufferProperties &fb_prop, const FrameBufferProperties &fb_prop,
const WindowProperties &win_prop, const WindowProperties &win_prop,
@ -85,7 +85,7 @@ begin_frame(FrameMode mode, Thread *current_thread) {
tinygsg->_current_frame_buffer = _frame_buffer; tinygsg->_current_frame_buffer = _frame_buffer;
tinygsg->reset_if_new(); tinygsg->reset_if_new();
_gsg->set_current_properties(&get_fb_properties()); _gsg->set_current_properties(&get_fb_properties());
return _gsg->begin_frame(current_thread); return _gsg->begin_frame(current_thread);
} }
@ -152,7 +152,7 @@ end_flip() {
bmdc, 0, 0,fb_xsize, fb_ysize, bmdc, 0, 0,fb_xsize, fb_ysize,
SRCCOPY); SRCCOPY);
} }
DeleteDC(bmdc); DeleteDC(bmdc);
DeleteObject(bm); DeleteObject(bm);
GdiFlush(); GdiFlush();
@ -220,7 +220,7 @@ open_window() {
} else { } else {
DCAST_INTO_R(tinygsg, _gsg, false); DCAST_INTO_R(tinygsg, _gsg, false);
} }
_hdc = GetDC(_hWnd); _hdc = GetDC(_hWnd);
create_frame_buffer(); create_frame_buffer();
@ -231,7 +231,7 @@ open_window() {
} }
tinygsg->_current_frame_buffer = _frame_buffer; tinygsg->_current_frame_buffer = _frame_buffer;
tinygsg->reset_if_new(); tinygsg->reset_if_new();
if (!tinygsg->is_valid()) { if (!tinygsg->is_valid()) {
close_window(); close_window();
@ -251,8 +251,10 @@ open_window() {
void TinyWinGraphicsWindow:: void TinyWinGraphicsWindow::
handle_reshape() { handle_reshape() {
WinGraphicsWindow::handle_reshape(); WinGraphicsWindow::handle_reshape();
ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size()); if (_frame_buffer != NULL) {
setup_bitmap_info(); ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size());
setup_bitmap_info();
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -107,6 +107,8 @@ void
ZB_resize(ZBuffer * zb, void *frame_buffer, int xsize, int ysize) { ZB_resize(ZBuffer * zb, void *frame_buffer, int xsize, int ysize) {
int size; int size;
nassertv(zb != NULL);
/* xsize must be a multiple of 4 */ /* xsize must be a multiple of 4 */
xsize = (xsize + 3) & ~3; xsize = (xsize + 3) & ~3;

View File

@ -26,8 +26,6 @@
#include <tchar.h> #include <tchar.h>
TypeHandle WinGraphicsWindow::_type_handle; TypeHandle WinGraphicsWindow::_type_handle;
TypeHandle WinGraphicsWindow::WinWindowHandle::_type_handle; TypeHandle WinGraphicsWindow::WinWindowHandle::_type_handle;
@ -86,7 +84,7 @@ WinGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
const WindowProperties &win_prop, const WindowProperties &win_prop,
int flags, int flags,
GraphicsStateGuardian *gsg, GraphicsStateGuardian *gsg,
GraphicsOutput *host) : GraphicsOutput *host) :
GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host) GraphicsWindow(engine, pipe, name, fb_prop, win_prop, flags, gsg, host)
{ {
initialize_input_devices(); initialize_input_devices();
@ -124,7 +122,7 @@ WinGraphicsWindow::
// Function: WinGraphicsWindow::move_pointer // Function: WinGraphicsWindow::move_pointer
// Access: Published, Virtual // Access: Published, Virtual
// Description: Forces the pointer to the indicated position within // Description: Forces the pointer to the indicated position within
// the window, if possible. // the window, if possible.
// //
// Returns true if successful, false on failure. This // Returns true if successful, false on failure. This
// may fail if the mouse is not currently within the // may fail if the mouse is not currently within the
@ -142,7 +140,7 @@ move_pointer(int device, int x, int y) {
if (device == 0) { if (device == 0) {
// Move the system mouse pointer. // Move the system mouse pointer.
if (!_properties.get_foreground() ) if (!_properties.get_foreground() )
// !_input_devices[0].get_pointer().get_in_window()) // !_input_devices[0].get_pointer().get_in_window())
{ {
// If the window doesn't have input focus, or the mouse isn't // If the window doesn't have input focus, or the mouse isn't
// currently within the window, forget it. // currently within the window, forget it.
@ -151,7 +149,7 @@ move_pointer(int device, int x, int y) {
RECT view_rect; RECT view_rect;
get_client_rect_screen(_hWnd, &view_rect); get_client_rect_screen(_hWnd, &view_rect);
SetCursorPos(view_rect.left + x, view_rect.top + y); SetCursorPos(view_rect.left + x, view_rect.top + y);
_input_devices[0].set_pointer_in_window(x, y); _input_devices[0].set_pointer_in_window(x, y);
return true; return true;
@ -235,11 +233,11 @@ process_events() {
} }
_return_control_to_app = false; _return_control_to_app = false;
} else } else
*/ */
MSG msg; MSG msg;
// Handle all the messages on the queue in a row. Some of these // Handle all the messages on the queue in a row. Some of these
// might be for another window, but they will get dispatched // might be for another window, but they will get dispatched
// appropriately. // appropriately.
@ -314,18 +312,18 @@ set_properties_now(WindowProperties &properties) {
WindowProperties::ZOrder last_z_order = _properties.get_z_order(); WindowProperties::ZOrder last_z_order = _properties.get_z_order();
_properties.set_z_order(properties.get_z_order()); _properties.set_z_order(properties.get_z_order());
adjust_z_order(last_z_order, properties.get_z_order()); adjust_z_order(last_z_order, properties.get_z_order());
properties.clear_z_order(); properties.clear_z_order();
} }
if (properties.has_foreground() && properties.get_foreground()) { if (properties.has_foreground() && properties.get_foreground()) {
if (!SetActiveWindow(_hWnd)) { if (!SetActiveWindow(_hWnd)) {
windisplay_cat.warning() windisplay_cat.warning()
<< "SetForegroundWindow() failed!\n"; << "SetForegroundWindow() failed!\n";
} else { } else {
_properties.set_foreground(true); _properties.set_foreground(true);
} }
properties.clear_foreground(); properties.clear_foreground();
} }
@ -446,11 +444,11 @@ open_window() {
// Now that we have a window handle, store it in our global map, so // Now that we have a window handle, store it in our global map, so
// future messages for this window can be routed properly. // future messages for this window can be routed properly.
_window_handles.insert(WindowHandles::value_type(_hWnd, this)); _window_handles.insert(WindowHandles::value_type(_hWnd, this));
// move window to top of zorder. // move window to top of zorder.
SetWindowPos(_hWnd, HWND_TOP, 0,0,0,0, SetWindowPos(_hWnd, HWND_TOP, 0,0,0,0,
SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE); SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE);
// need to do twice to override any minimized flags in StartProcessInfo // need to do twice to override any minimized flags in StartProcessInfo
if (want_minimized) { if (want_minimized) {
ShowWindow(_hWnd, SW_MINIMIZE); ShowWindow(_hWnd, SW_MINIMIZE);
@ -492,8 +490,8 @@ open_window() {
// Registers to receive the WM_INPUT messages // Registers to receive the WM_INPUT messages
if ((pRegisterRawInputDevices)&&(_input_devices.size() > 1)) { if ((pRegisterRawInputDevices)&&(_input_devices.size() > 1)) {
RAWINPUTDEVICE Rid; RAWINPUTDEVICE Rid;
Rid.usUsagePage = 0x01; Rid.usUsagePage = 0x01;
Rid.usUsage = 0x02; Rid.usUsage = 0x02;
Rid.dwFlags = 0;// RIDEV_NOLEGACY; // adds HID mouse and also ignores legacy mouse messages Rid.dwFlags = 0;// RIDEV_NOLEGACY; // adds HID mouse and also ignores legacy mouse messages
Rid.hwndTarget = _hWnd; Rid.hwndTarget = _hWnd;
pRegisterRawInputDevices(&Rid, 1, sizeof (Rid)); pRegisterRawInputDevices(&Rid, 1, sizeof (Rid));
@ -517,7 +515,7 @@ open_window() {
#ifdef HAVE_WIN_TOUCHINPUT #ifdef HAVE_WIN_TOUCHINPUT
RegisterTouchWindow(_hWnd, 0); RegisterTouchWindow(_hWnd, 0);
#endif #endif
return true; return true;
} }
@ -537,13 +535,13 @@ initialize_input_devices() {
PRAWINPUTDEVICELIST pRawInputDeviceList; PRAWINPUTDEVICELIST pRawInputDeviceList;
nassertv(_input_devices.size() == 0); nassertv(_input_devices.size() == 0);
// Clear the handle array, and set up the system keyboard/mouse // Clear the handle array, and set up the system keyboard/mouse
memset(_input_device_handle, 0, sizeof(_input_device_handle)); memset(_input_device_handle, 0, sizeof(_input_device_handle));
GraphicsWindowInputDevice device = GraphicsWindowInputDevice device =
GraphicsWindowInputDevice::pointer_and_keyboard(this, "keyboard_mouse"); GraphicsWindowInputDevice::pointer_and_keyboard(this, "keyboard_mouse");
add_input_device(device); add_input_device(device);
// Try initializing the Raw Input function pointers. // Try initializing the Raw Input function pointers.
if (pRegisterRawInputDevices==0) { if (pRegisterRawInputDevices==0) {
HMODULE user32 = LoadLibrary("user32.dll"); HMODULE user32 = LoadLibrary("user32.dll");
@ -554,7 +552,7 @@ initialize_input_devices() {
pGetRawInputData = (tGetRawInputData) GetProcAddress(user32,"GetRawInputData"); pGetRawInputData = (tGetRawInputData) GetProcAddress(user32,"GetRawInputData");
} }
} }
if (pRegisterRawInputDevices==0) return; if (pRegisterRawInputDevices==0) return;
if (pGetRawInputDeviceList==0) return; if (pGetRawInputDeviceList==0) return;
if (pGetRawInputDeviceInfoA==0) return; if (pGetRawInputDeviceInfoA==0) return;
@ -563,7 +561,7 @@ initialize_input_devices() {
// Get the number of devices. // Get the number of devices.
if (pGetRawInputDeviceList(NULL, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) != 0) if (pGetRawInputDeviceList(NULL, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) != 0)
return; return;
// Allocate the array to hold the DeviceList // Allocate the array to hold the DeviceList
pRawInputDeviceList = (PRAWINPUTDEVICELIST)alloca(sizeof(RAWINPUTDEVICELIST) * nInputDevices); pRawInputDeviceList = (PRAWINPUTDEVICELIST)alloca(sizeof(RAWINPUTDEVICELIST) * nInputDevices);
if (pRawInputDeviceList==0) return; if (pRawInputDeviceList==0) return;
@ -571,7 +569,7 @@ initialize_input_devices() {
// Fill the Array // Fill the Array
if (pGetRawInputDeviceList(pRawInputDeviceList, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) == -1) if (pGetRawInputDeviceList(pRawInputDeviceList, &nInputDevices, sizeof(RAWINPUTDEVICELIST)) == -1)
return; return;
// Loop through all raw devices and find the raw mice // Loop through all raw devices and find the raw mice
for (int i = 0; i < (int)nInputDevices; i++) { for (int i = 0; i < (int)nInputDevices; i++) {
if (pRawInputDeviceList[i].dwType == RIM_TYPEMOUSE) { if (pRawInputDeviceList[i].dwType == RIM_TYPEMOUSE) {
@ -668,7 +666,7 @@ do_reshape_request(int x_origin, int y_origin, bool has_origin,
has_origin = false; has_origin = false;
} }
} }
// Compute the appropriate size and placement for the window, // Compute the appropriate size and placement for the window,
// including decorations. // including decorations.
RECT view_rect; RECT view_rect;
@ -725,7 +723,7 @@ handle_reshape() {
// But in practice, GetClientRect() doesn't really fail, but just // But in practice, GetClientRect() doesn't really fail, but just
// returns all zeroes. Ignore this too. // returns all zeroes. Ignore this too.
if (view_rect.left == 0 && view_rect.right == 0 && if (view_rect.left == 0 && view_rect.right == 0 &&
view_rect.bottom == 0 && view_rect.top == 0) { view_rect.bottom == 0 && view_rect.top == 0) {
if (windisplay_cat.is_debug()) { if (windisplay_cat.is_debug()) {
windisplay_cat.debug() windisplay_cat.debug()
@ -746,17 +744,17 @@ handle_reshape() {
} }
return; return;
} }
WindowProperties properties; WindowProperties properties;
properties.set_size((view_rect.right - view_rect.left), properties.set_size((view_rect.right - view_rect.left),
(view_rect.bottom - view_rect.top)); (view_rect.bottom - view_rect.top));
// _props origin should reflect upper left of view rectangle // _props origin should reflect upper left of view rectangle
properties.set_origin(view_rect.left, view_rect.top); properties.set_origin(view_rect.left, view_rect.top);
if (windisplay_cat.is_spam()) { if (windisplay_cat.is_spam()) {
windisplay_cat.spam() windisplay_cat.spam()
<< "reshape to origin: (" << properties.get_x_origin() << "," << "reshape to origin: (" << properties.get_x_origin() << ","
<< properties.get_y_origin() << "), size: (" << properties.get_x_size() << properties.get_y_origin() << "), size: (" << properties.get_x_size()
<< "," << properties.get_y_size() << ")\n"; << "," << properties.get_y_size() << ")\n";
} }
@ -788,22 +786,22 @@ do_fullscreen_resize(int x_size, int y_size) {
if (!find_acceptable_display_mode(x_size, y_size, if (!find_acceptable_display_mode(x_size, y_size,
dwFullScreenBitDepth, dm)) { dwFullScreenBitDepth, dm)) {
windisplay_cat.error() windisplay_cat.error()
<< "window resize(" << x_size << ", " << y_size << "window resize(" << x_size << ", " << y_size
<< ") failed, no compatible fullscreen display mode found!\n"; << ") failed, no compatible fullscreen display mode found!\n";
return false; return false;
} }
// this causes WM_SIZE msg to be produced // this causes WM_SIZE msg to be produced
SetWindowPos(_hWnd, NULL, 0,0, x_size, y_size, SetWindowPos(_hWnd, NULL, 0,0, x_size, y_size,
SWP_NOZORDER | SWP_NOMOVE | SWP_NOSENDCHANGING); SWP_NOZORDER | SWP_NOMOVE | SWP_NOSENDCHANGING);
int chg_result = ChangeDisplaySettings(&dm, CDS_FULLSCREEN); int chg_result = ChangeDisplaySettings(&dm, CDS_FULLSCREEN);
if (chg_result != DISP_CHANGE_SUCCESSFUL) { if (chg_result != DISP_CHANGE_SUCCESSFUL) {
windisplay_cat.error() windisplay_cat.error()
<< "resize ChangeDisplaySettings failed (error code: " << "resize ChangeDisplaySettings failed (error code: "
<< chg_result << ") for specified res: " << chg_result << ") for specified res: "
<< dm.dmPelsWidth << " x " << dm.dmPelsHeight << dm.dmPelsWidth << " x " << dm.dmPelsHeight
<< " x " << dm.dmBitsPerPel << ", " << " x " << dm.dmBitsPerPel << ", "
<< dm.dmDisplayFrequency << " Hz\n"; << dm.dmDisplayFrequency << " Hz\n";
return false; return false;
} }
@ -811,7 +809,7 @@ do_fullscreen_resize(int x_size, int y_size) {
_fullscreen_display_mode = dm; _fullscreen_display_mode = dm;
windisplay_cat.info() windisplay_cat.info()
<< "Resized fullscreen window to " << x_size << ", " << y_size << "Resized fullscreen window to " << x_size << ", " << y_size
<< " bitdepth " << dwFullScreenBitDepth << ", " << " bitdepth " << dwFullScreenBitDepth << ", "
<< dm.dmDisplayFrequency << "Hz\n"; << dm.dmDisplayFrequency << "Hz\n";
@ -866,7 +864,7 @@ do_windowed_switch() {
if (!calculate_metrics(false, window_style, metrics, has_origin)){ if (!calculate_metrics(false, window_style, metrics, has_origin)){
return false; return false;
} }
// We send SWP_FRAMECHANGED so that the new styles are taken into account. // We send SWP_FRAMECHANGED so that the new styles are taken into account.
// Also, we place the Windows at 0,0 to play safe until we decide how to // Also, we place the Windows at 0,0 to play safe until we decide how to
// get Panda to remember the windowed origin. // get Panda to remember the windowed origin.
@ -950,7 +948,7 @@ calculate_metrics(bool fullscreen, DWORD window_style, WINDOW_METRICS &metrics,
if (!fullscreen && has_origin) { if (!fullscreen && has_origin) {
metrics.x = _properties.get_x_origin(); metrics.x = _properties.get_x_origin();
metrics.y = _properties.get_y_origin(); metrics.y = _properties.get_y_origin();
// A coordinate of -2 means to center the window in its client area. // A coordinate of -2 means to center the window in its client area.
if (metrics.x == -2) { if (metrics.x == -2) {
metrics.x = 0.5 * (_pipe->get_display_width() - _properties.get_x_size()); metrics.x = 0.5 * (_pipe->get_display_width() - _properties.get_x_size());
@ -974,7 +972,7 @@ calculate_metrics(bool fullscreen, DWORD window_style, WINDOW_METRICS &metrics,
RECT win_rect; RECT win_rect;
SetRect(&win_rect, metrics.x, metrics.y, SetRect(&win_rect, metrics.x, metrics.y,
metrics.x + metrics.width, metrics.y + metrics.height); metrics.x + metrics.width, metrics.y + metrics.height);
// Compute window size based on desired client area size // Compute window size based on desired client area size
if (!AdjustWindowRect(&win_rect, window_style, FALSE)) { if (!AdjustWindowRect(&win_rect, window_style, FALSE)) {
windisplay_cat.error() windisplay_cat.error()
@ -1004,7 +1002,7 @@ calculate_metrics(bool fullscreen, DWORD window_style, WINDOW_METRICS &metrics,
bool WinGraphicsWindow:: bool WinGraphicsWindow::
open_graphic_window(bool fullscreen) { open_graphic_window(bool fullscreen) {
DWORD window_style = make_style(fullscreen); DWORD window_style = make_style(fullscreen);
wstring title; wstring title;
if (_properties.has_title()) { if (_properties.has_title()) {
TextEncoder encoder; TextEncoder encoder;
@ -1026,7 +1024,7 @@ open_graphic_window(bool fullscreen) {
HINSTANCE hinstance = GetModuleHandle(NULL); HINSTANCE hinstance = GetModuleHandle(NULL);
_hparent = NULL; _hparent = NULL;
if (!fullscreen){ if (!fullscreen){
WindowHandle *window_handle = _properties.get_parent_window(); WindowHandle *window_handle = _properties.get_parent_window();
if (window_handle != NULL) { if (window_handle != NULL) {
@ -1036,7 +1034,7 @@ open_graphic_window(bool fullscreen) {
if (os_handle != NULL) { if (os_handle != NULL) {
windisplay_cat.info() windisplay_cat.info()
<< "os_handle type " << os_handle->get_type() << "\n"; << "os_handle type " << os_handle->get_type() << "\n";
if (os_handle->is_of_type(NativeWindowHandle::WinHandle::get_class_type())) { if (os_handle->is_of_type(NativeWindowHandle::WinHandle::get_class_type())) {
NativeWindowHandle::WinHandle *win_handle = DCAST(NativeWindowHandle::WinHandle, os_handle); NativeWindowHandle::WinHandle *win_handle = DCAST(NativeWindowHandle::WinHandle, os_handle);
_hparent = win_handle->get_handle(); _hparent = win_handle->get_handle();
@ -1052,7 +1050,7 @@ open_graphic_window(bool fullscreen) {
} }
if (!_hparent) { // This can be a regular window or a fullscreen window if (!_hparent) { // This can be a regular window or a fullscreen window
_hWnd = CreateWindowW(wclass._name.c_str(), title.c_str(), window_style, _hWnd = CreateWindowW(wclass._name.c_str(), title.c_str(), window_style,
metrics.x, metrics.y, metrics.x, metrics.y,
metrics.width, metrics.width,
metrics.height, metrics.height,
@ -1060,18 +1058,18 @@ open_graphic_window(bool fullscreen) {
} else { // This is a regular window with a parent } else { // This is a regular window with a parent
int x_origin = 0; int x_origin = 0;
int y_origin = 0; int y_origin = 0;
if (!fullscreen && has_origin) { if (!fullscreen && has_origin) {
x_origin = _properties.get_x_origin(); x_origin = _properties.get_x_origin();
y_origin = _properties.get_y_origin(); y_origin = _properties.get_y_origin();
} }
_hWnd = CreateWindowW(wclass._name.c_str(), title.c_str(), _hWnd = CreateWindowW(wclass._name.c_str(), title.c_str(),
WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS , WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS ,
x_origin, y_origin, x_origin, y_origin,
_properties.get_x_size(), _properties.get_y_size(), _properties.get_x_size(), _properties.get_y_size(),
_hparent, NULL, hinstance, 0); _hparent, NULL, hinstance, 0);
if (_hWnd) { if (_hWnd) {
// join our keyboard state with the parents // join our keyboard state with the parents
@ -1079,13 +1077,13 @@ open_graphic_window(bool fullscreen) {
// It causes problems with the browser plugin--it deadlocks when // It causes problems with the browser plugin--it deadlocks when
// the parent process is waiting on the child process. // the parent process is waiting on the child process.
//AttachThreadInput(GetWindowThreadProcessId(_hparent,NULL), GetCurrentThreadId(),TRUE); //AttachThreadInput(GetWindowThreadProcessId(_hparent,NULL), GetCurrentThreadId(),TRUE);
WindowProperties properties; WindowProperties properties;
properties.set_foreground(true); properties.set_foreground(true);
system_changed_properties(properties); system_changed_properties(properties);
} }
} }
if (!_hWnd) { if (!_hWnd) {
windisplay_cat.error() windisplay_cat.error()
<< "CreateWindow() failed!" << endl; << "CreateWindow() failed!" << endl;
@ -1123,7 +1121,7 @@ do_fullscreen_enable() {
// DWORD cur_scrnwidth = GetDeviceCaps(scrnDC, HORZRES); // DWORD cur_scrnwidth = GetDeviceCaps(scrnDC, HORZRES);
// DWORD cur_scrnheight = GetDeviceCaps(scrnDC, VERTRES); // DWORD cur_scrnheight = GetDeviceCaps(scrnDC, VERTRES);
ReleaseDC(hDesktopWindow, scrnDC); ReleaseDC(hDesktopWindow, scrnDC);
DWORD dwWidth = _properties.get_x_size(); DWORD dwWidth = _properties.get_x_size();
DWORD dwHeight = _properties.get_y_size(); DWORD dwHeight = _properties.get_y_size();
DWORD dwFullScreenBitDepth = cur_bitdepth; DWORD dwFullScreenBitDepth = cur_bitdepth;
@ -1131,7 +1129,7 @@ do_fullscreen_enable() {
DEVMODE dm; DEVMODE dm;
reconsider_fullscreen_size(dwWidth, dwHeight, dwFullScreenBitDepth); reconsider_fullscreen_size(dwWidth, dwHeight, dwFullScreenBitDepth);
if (!find_acceptable_display_mode(dwWidth, dwHeight, dwFullScreenBitDepth, dm)) { if (!find_acceptable_display_mode(dwWidth, dwHeight, dwFullScreenBitDepth, dm)) {
windisplay_cat.error() windisplay_cat.error()
<< "Videocard has no supported display resolutions at specified res (" << "Videocard has no supported display resolutions at specified res ("
<< dwWidth << " x " << dwHeight << " x " << dwFullScreenBitDepth <<")\n"; << dwWidth << " x " << dwHeight << " x " << dwFullScreenBitDepth <<")\n";
return false; return false;
@ -1147,7 +1145,7 @@ do_fullscreen_enable() {
<< "ChangeDisplaySettings failed (error code: " << "ChangeDisplaySettings failed (error code: "
<< chg_result << ") for specified res: " << chg_result << ") for specified res: "
<< dm.dmPelsWidth << " x " << dm.dmPelsHeight << dm.dmPelsWidth << " x " << dm.dmPelsHeight
<< " x " << dm.dmBitsPerPel << ", " << " x " << dm.dmBitsPerPel << ", "
<< dm.dmDisplayFrequency << " Hz\n"; << dm.dmDisplayFrequency << " Hz\n";
return false; return false;
} }
@ -1202,13 +1200,13 @@ adjust_z_order(WindowProperties::ZOrder last_z_order,
WindowProperties::ZOrder this_z_order) { WindowProperties::ZOrder this_z_order) {
HWND order; HWND order;
bool do_change = false; bool do_change = false;
switch (this_z_order) { switch (this_z_order) {
case WindowProperties::Z_bottom: case WindowProperties::Z_bottom:
order = HWND_BOTTOM; order = HWND_BOTTOM;
do_change = true; do_change = true;
break; break;
case WindowProperties::Z_normal: case WindowProperties::Z_normal:
if ((last_z_order != WindowProperties::Z_normal) && if ((last_z_order != WindowProperties::Z_normal) &&
// If we aren't changing the window order, don't move it to // If we aren't changing the window order, don't move it to
@ -1223,14 +1221,14 @@ adjust_z_order(WindowProperties::ZOrder last_z_order,
do_change = true; do_change = true;
} }
break; break;
case WindowProperties::Z_top: case WindowProperties::Z_top:
order = HWND_TOPMOST; order = HWND_TOPMOST;
do_change = true; do_change = true;
break; break;
} }
if (do_change) { if (do_change) {
BOOL result = SetWindowPos(_hWnd, order, 0,0,0,0, BOOL result = SetWindowPos(_hWnd, order, 0,0,0,0,
SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE); SWP_NOMOVE | SWP_NOSENDCHANGING | SWP_NOSIZE);
if (!result) { if (!result) {
windisplay_cat.warning() windisplay_cat.warning()
@ -1265,13 +1263,13 @@ track_mouse_leaving(HWND hwnd) {
}; };
// tell win32 to post WM_MOUSELEAVE msgs // tell win32 to post WM_MOUSELEAVE msgs
BOOL bSucceeded = winpipe->_pfnTrackMouseEvent(&tme); BOOL bSucceeded = winpipe->_pfnTrackMouseEvent(&tme);
if ((!bSucceeded) && windisplay_cat.is_debug()) { if ((!bSucceeded) && windisplay_cat.is_debug()) {
windisplay_cat.debug() windisplay_cat.debug()
<< "TrackMouseEvent failed!, LastError=" << GetLastError() << endl; << "TrackMouseEvent failed!, LastError=" << GetLastError() << endl;
} }
_tracking_mouse_leaving = true; _tracking_mouse_leaving = true;
} }
} }
@ -1331,7 +1329,7 @@ LONG WinGraphicsWindow::
window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
if (windisplay_cat.is_spam()) { if (windisplay_cat.is_spam()) {
windisplay_cat.spam() windisplay_cat.spam()
<< ClockObject::get_global_clock()->get_real_time() << ClockObject::get_global_clock()->get_real_time()
<< " window_proc(" << (void *)this << ", " << hwnd << ", " << " window_proc(" << (void *)this << ", " << hwnd << ", "
<< msg << ", " << wparam << ", " << lparam << ")\n"; << msg << ", " << wparam << ", " << lparam << ")\n";
} }
@ -1339,7 +1337,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
int button = -1; int button = -1;
switch (msg) { switch (msg) {
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
if (!_tracking_mouse_leaving) { if (!_tracking_mouse_leaving) {
// need to re-call TrackMouseEvent every time mouse re-enters window // need to re-call TrackMouseEvent every time mouse re-enters window
track_mouse_leaving(hwnd); track_mouse_leaving(hwnd);
@ -1348,22 +1346,22 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
if(handle_mouse_motion(translate_mouse(LOWORD(lparam)), translate_mouse(HIWORD(lparam)))) if(handle_mouse_motion(translate_mouse(LOWORD(lparam)), translate_mouse(HIWORD(lparam))))
return 0; return 0;
break; break;
case WM_INPUT: case WM_INPUT:
handle_raw_input((HRAWINPUT)lparam); handle_raw_input((HRAWINPUT)lparam);
break; break;
case WM_MOUSELEAVE: case WM_MOUSELEAVE:
_tracking_mouse_leaving = false; _tracking_mouse_leaving = false;
handle_mouse_exit(); handle_mouse_exit();
set_cursor_out_of_window(); set_cursor_out_of_window();
break; break;
case WM_CREATE: case WM_CREATE:
{ {
track_mouse_leaving(hwnd); track_mouse_leaving(hwnd);
ClearToBlack(hwnd, _properties); ClearToBlack(hwnd, _properties);
POINT cpos; POINT cpos;
GetCursorPos(&cpos); GetCursorPos(&cpos);
ScreenToClient(hwnd, &cpos); ScreenToClient(hwnd, &cpos);
@ -1399,7 +1397,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
} }
break; break;
*/ */
case WM_CLOSE: case WM_CLOSE:
// This is a message from the system indicating that the user // This is a message from the system indicating that the user
// has requested to close the window (e.g. alt-f4). // has requested to close the window (e.g. alt-f4).
@ -1410,14 +1408,14 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
// the request and process it directly. // the request and process it directly.
throw_event(close_request_event); throw_event(close_request_event);
return 0; return 0;
} else { } else {
// In this case, the default case, the app does not intend // In this case, the default case, the app does not intend
// to service the request, so we do by closing the window. // to service the request, so we do by closing the window.
close_window(); close_window();
properties.set_open(false); properties.set_open(false);
system_changed_properties(properties); system_changed_properties(properties);
// TODO: make sure we release the GSG properly. // TODO: make sure we release the GSG properly.
} }
} }
@ -1429,17 +1427,17 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
<< "WM_CHILDACTIVATE: " << hwnd << "\n"; << "WM_CHILDACTIVATE: " << hwnd << "\n";
} }
break; break;
case WM_ACTIVATE: case WM_ACTIVATE:
if (windisplay_cat.is_debug()) { if (windisplay_cat.is_debug()) {
windisplay_cat.debug() windisplay_cat.debug()
<< "WM_ACTIVATE: " << hwnd << ", " << wparam << ", " << lparam << "\n"; << "WM_ACTIVATE: " << hwnd << ", " << wparam << ", " << lparam << "\n";
} }
properties.set_minimized((wparam & 0xffff0000) != 0); properties.set_minimized((wparam & 0xffff0000) != 0);
if ((wparam & 0xffff) != WA_INACTIVE) if ((wparam & 0xffff) != WA_INACTIVE)
{ {
properties.set_foreground(true); properties.set_foreground(true);
if (is_fullscreen()) if (is_fullscreen())
{ {
// When a fullscreen window goes active, it automatically gets // When a fullscreen window goes active, it automatically gets
// un-minimized. // un-minimized.
@ -1448,10 +1446,10 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
if (chg_result != DISP_CHANGE_SUCCESSFUL) { if (chg_result != DISP_CHANGE_SUCCESSFUL) {
const DEVMODE &dm = _fullscreen_display_mode; const DEVMODE &dm = _fullscreen_display_mode;
windisplay_cat.error() windisplay_cat.error()
<< "restore ChangeDisplaySettings failed (error code: " << "restore ChangeDisplaySettings failed (error code: "
<< chg_result << ") for specified res: " << chg_result << ") for specified res: "
<< dm.dmPelsWidth << " x " << dm.dmPelsHeight << dm.dmPelsWidth << " x " << dm.dmPelsHeight
<< " x " << dm.dmBitsPerPel << ", " << " x " << dm.dmBitsPerPel << ", "
<< dm.dmDisplayFrequency << " Hz\n"; << dm.dmDisplayFrequency << " Hz\n";
} }
@ -1460,10 +1458,10 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
fullscreen_restored(properties); fullscreen_restored(properties);
} }
} }
else else
{ {
properties.set_foreground(false); properties.set_foreground(false);
if (is_fullscreen()) if (is_fullscreen())
{ {
// When a fullscreen window goes inactive, it automatically // When a fullscreen window goes inactive, it automatically
// gets minimized. // gets minimized.
@ -1489,7 +1487,10 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
<< "WM_SIZE: " << hwnd << ", " << wparam << "\n"; << "WM_SIZE: " << hwnd << ", " << wparam << "\n";
} }
handle_reshape(); // Resist calling handle_reshape before the window has opened.
if (_hWnd == NULL) {
handle_reshape();
}
break; break;
case WM_EXITSIZEMOVE: case WM_EXITSIZEMOVE:
@ -1524,7 +1525,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
// A button-click in the window means to grab the keyboard focus. // A button-click in the window means to grab the keyboard focus.
set_focus(); set_focus();
return 0; return 0;
case WM_MBUTTONDOWN: case WM_MBUTTONDOWN:
if (_lost_keypresses) { if (_lost_keypresses) {
resend_lost_keypresses(); resend_lost_keypresses();
@ -1562,7 +1563,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
} }
} }
return 0; return 0;
case WM_LBUTTONUP: case WM_LBUTTONUP:
if (_lost_keypresses) { if (_lost_keypresses) {
resend_lost_keypresses(); resend_lost_keypresses();
@ -1628,7 +1629,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
} }
break; break;
case WM_IME_SETCONTEXT: case WM_IME_SETCONTEXT:
if (!ime_hide) if (!ime_hide)
break; break;
@ -1640,15 +1641,15 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
windisplay_cat.debug() << "SendMessage failed for " << _ime_hWnd << endl; windisplay_cat.debug() << "SendMessage failed for " << _ime_hWnd << endl;
else else
windisplay_cat.debug() << "SendMessage Succeeded for " << _ime_hWnd << endl; windisplay_cat.debug() << "SendMessage Succeeded for " << _ime_hWnd << endl;
windisplay_cat.debug() << "wparam is " << wparam << ", lparam is " << lparam << endl; windisplay_cat.debug() << "wparam is " << wparam << ", lparam is " << lparam << endl;
lparam &= ~ISC_SHOWUIALL; lparam &= ~ISC_SHOWUIALL;
if (ImmIsUIMessage(_ime_hWnd, msg, wparam, lparam)) if (ImmIsUIMessage(_ime_hWnd, msg, wparam, lparam))
windisplay_cat.debug() << "wparam is " << wparam << ", lparam is " << lparam << endl; windisplay_cat.debug() << "wparam is " << wparam << ", lparam is " << lparam << endl;
break; break;
case WM_IME_NOTIFY: case WM_IME_NOTIFY:
if (wparam == IMN_SETOPENSTATUS) { if (wparam == IMN_SETOPENSTATUS) {
HIMC hIMC = ImmGetContext(hwnd); HIMC hIMC = ImmGetContext(hwnd);
@ -1663,20 +1664,20 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
CANDIDATEFORM canf; CANDIDATEFORM canf;
ImmGetCompositionWindow(hIMC, &comf); ImmGetCompositionWindow(hIMC, &comf);
ImmGetCandidateWindow(hIMC, 0, &canf); ImmGetCandidateWindow(hIMC, 0, &canf);
windisplay_cat.debug() << windisplay_cat.debug() <<
"comf style " << comf.dwStyle << "comf style " << comf.dwStyle <<
" comf point: x" << comf.ptCurrentPos.x << ",y " << comf.ptCurrentPos.y << " comf point: x" << comf.ptCurrentPos.x << ",y " << comf.ptCurrentPos.y <<
" comf rect: l " << comf.rcArea.left << ",t " << comf.rcArea.top << ",r " << " comf rect: l " << comf.rcArea.left << ",t " << comf.rcArea.top << ",r " <<
comf.rcArea.right << ",b " << comf.rcArea.bottom << endl; comf.rcArea.right << ",b " << comf.rcArea.bottom << endl;
windisplay_cat.debug() << windisplay_cat.debug() <<
"canf style " << canf.dwStyle << "canf style " << canf.dwStyle <<
" canf point: x" << canf.ptCurrentPos.x << ",y " << canf.ptCurrentPos.y << " canf point: x" << canf.ptCurrentPos.x << ",y " << canf.ptCurrentPos.y <<
" canf rect: l " << canf.rcArea.left << ",t " << canf.rcArea.top << ",r " << " canf rect: l " << canf.rcArea.left << ",t " << canf.rcArea.top << ",r " <<
canf.rcArea.right << ",b " << canf.rcArea.bottom << endl; canf.rcArea.right << ",b " << canf.rcArea.bottom << endl;
comf.dwStyle = CFS_POINT; comf.dwStyle = CFS_POINT;
comf.ptCurrentPos.x = 2000; comf.ptCurrentPos.x = 2000;
comf.ptCurrentPos.y = 2000; comf.ptCurrentPos.y = 2000;
canf.dwStyle = CFS_EXCLUDE; canf.dwStyle = CFS_EXCLUDE;
canf.dwIndex = 0; canf.dwIndex = 0;
canf.ptCurrentPos.x = 0; canf.ptCurrentPos.x = 0;
@ -1685,14 +1686,14 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
canf.rcArea.top = 0; canf.rcArea.top = 0;
canf.rcArea.right = 640; canf.rcArea.right = 640;
canf.rcArea.bottom = 480; canf.rcArea.bottom = 480;
#if 0 #if 0
comf.rcArea.left = 200; comf.rcArea.left = 200;
comf.rcArea.top = 200; comf.rcArea.top = 200;
comf.rcArea.right = 0; comf.rcArea.right = 0;
comf.rcArea.bottom = 0; comf.rcArea.bottom = 0;
#endif #endif
if (ImmSetCompositionWindow(hIMC, &comf)) if (ImmSetCompositionWindow(hIMC, &comf))
windisplay_cat.debug() << "set composition form: success\n"; windisplay_cat.debug() << "set composition form: success\n";
for (int i=0; i<3; ++i) { for (int i=0; i<3; ++i) {
@ -1705,12 +1706,12 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
ImmReleaseContext(hwnd, hIMC); ImmReleaseContext(hwnd, hIMC);
} }
break; break;
case WM_IME_STARTCOMPOSITION: case WM_IME_STARTCOMPOSITION:
support_overlay_window(true); support_overlay_window(true);
_ime_active = true; _ime_active = true;
break; break;
case WM_IME_ENDCOMPOSITION: case WM_IME_ENDCOMPOSITION:
support_overlay_window(false); support_overlay_window(false);
_ime_active = false; _ime_active = false;
@ -1719,9 +1720,9 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
wstring ws; wstring ws;
_input_devices[0].candidate(ws, 0, 0, 0); _input_devices[0].candidate(ws, 0, 0, 0);
} }
break; break;
case WM_IME_COMPOSITION: case WM_IME_COMPOSITION:
if (ime_aware) { if (ime_aware) {
@ -1736,13 +1737,13 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
HIMC hIMC = ImmGetContext(hwnd); HIMC hIMC = ImmGetContext(hwnd);
nassertr(hIMC != 0, 0); nassertr(hIMC != 0, 0);
DWORD result_size = 0; DWORD result_size = 0;
static const int ime_buffer_size = 256; static const int ime_buffer_size = 256;
static const int ime_buffer_size_bytes = ime_buffer_size / sizeof(wchar_t); static const int ime_buffer_size_bytes = ime_buffer_size / sizeof(wchar_t);
wchar_t ime_buffer[ime_buffer_size]; wchar_t ime_buffer[ime_buffer_size];
size_t cursor_pos, delta_start; size_t cursor_pos, delta_start;
if (lparam & GCS_RESULTSTR) { if (lparam & GCS_RESULTSTR) {
result_size = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR, result_size = ImmGetCompositionStringW(hIMC, GCS_RESULTSTR,
ime_buffer, ime_buffer_size_bytes); ime_buffer, ime_buffer_size_bytes);
@ -1755,21 +1756,21 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
if (lparam & GCS_COMPSTR) { if (lparam & GCS_COMPSTR) {
result_size = ImmGetCompositionStringW(hIMC, GCS_CURSORPOS, NULL, 0); result_size = ImmGetCompositionStringW(hIMC, GCS_CURSORPOS, NULL, 0);
cursor_pos = result_size & 0xffff; cursor_pos = result_size & 0xffff;
result_size = ImmGetCompositionStringW(hIMC, GCS_DELTASTART, NULL, 0); result_size = ImmGetCompositionStringW(hIMC, GCS_DELTASTART, NULL, 0);
delta_start = result_size & 0xffff; delta_start = result_size & 0xffff;
result_size = ImmGetCompositionStringW(hIMC, GCS_COMPSTR, ime_buffer, ime_buffer_size); result_size = ImmGetCompositionStringW(hIMC, GCS_COMPSTR, ime_buffer, ime_buffer_size);
size_t num_chars = result_size / sizeof(wchar_t); size_t num_chars = result_size / sizeof(wchar_t);
_input_devices[0].candidate(wstring(ime_buffer, num_chars), _input_devices[0].candidate(wstring(ime_buffer, num_chars),
min(cursor_pos, delta_start), min(cursor_pos, delta_start),
max(cursor_pos, delta_start), max(cursor_pos, delta_start),
cursor_pos); cursor_pos);
} }
ImmReleaseContext(hwnd, hIMC); ImmReleaseContext(hwnd, hIMC);
} }
break; break;
case WM_CHAR: case WM_CHAR:
// Ignore WM_CHAR messages if we have the IME open, since // Ignore WM_CHAR messages if we have the IME open, since
// everything will come in through WM_IME_COMPOSITION. (It's // everything will come in through WM_IME_COMPOSITION. (It's
@ -1786,8 +1787,8 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
_input_devices[0].keystroke(wparam); _input_devices[0].keystroke(wparam);
} }
break; break;
case WM_SYSKEYDOWN: case WM_SYSKEYDOWN:
if (_lost_keypresses) { if (_lost_keypresses) {
resend_lost_keypresses(); resend_lost_keypresses();
} }
@ -1802,7 +1803,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
POINT point; POINT point;
GetCursorPos(&point); GetCursorPos(&point);
ScreenToClient(hwnd, &point); ScreenToClient(hwnd, &point);
handle_keypress(lookup_key(wparam), point.x, point.y, handle_keypress(lookup_key(wparam), point.x, point.y,
get_message_time()); get_message_time());
if ((lparam & 0x40000000) == 0) { if ((lparam & 0x40000000) == 0) {
@ -1836,7 +1837,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
} }
} }
break; break;
case WM_SYSCOMMAND: case WM_SYSCOMMAND:
if (wparam == SC_KEYMENU) { if (wparam == SC_KEYMENU) {
// if Alt is released (alone w/o other keys), defwindproc will // if Alt is released (alone w/o other keys), defwindproc will
@ -1850,8 +1851,8 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
return 0; return 0;
} }
break; break;
case WM_KEYDOWN: case WM_KEYDOWN:
if (_lost_keypresses) { if (_lost_keypresses) {
resend_lost_keypresses(); resend_lost_keypresses();
} }
@ -1905,7 +1906,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
!_input_devices.empty()) { !_input_devices.empty()) {
HGLOBAL hglb; HGLOBAL hglb;
char *lptstr; char *lptstr;
if (IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(NULL)) { if (IsClipboardFormatAvailable(CF_TEXT) && OpenClipboard(NULL)) {
// Maybe we should support CF_UNICODETEXT if it is available // Maybe we should support CF_UNICODETEXT if it is available
// too? // too?
@ -1985,7 +1986,7 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
} }
} }
break; break;
case WM_SYSKEYUP: case WM_SYSKEYUP:
case WM_KEYUP: case WM_KEYUP:
if (_lost_keypresses) { if (_lost_keypresses) {
@ -2031,8 +2032,8 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
} }
} }
break; break;
case WM_KILLFOCUS: case WM_KILLFOCUS:
if (windisplay_cat.is_debug()) { if (windisplay_cat.is_debug()) {
windisplay_cat.debug() windisplay_cat.debug()
<< "killfocus\n"; << "killfocus\n";
@ -2042,8 +2043,8 @@ window_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
properties.set_foreground(false); properties.set_foreground(false);
system_changed_properties(properties); system_changed_properties(properties);
break; break;
case WM_SETFOCUS: case WM_SETFOCUS:
// You would think that this would be a good time to call // You would think that this would be a good time to call
// resend_lost_keypresses(), but it turns out that we get // resend_lost_keypresses(), but it turns out that we get
// WM_SETFOCUS slightly before Windows starts resending key // WM_SETFOCUS slightly before Windows starts resending key
@ -2196,9 +2197,9 @@ update_cursor_window(WinGraphicsWindow *to_window) {
// We are leaving a graphics window; we should restore the Win2000 // We are leaving a graphics window; we should restore the Win2000
// effects. // effects.
if (_got_saved_params) { if (_got_saved_params) {
SystemParametersInfo(SPI_SETMOUSETRAILS, NULL, SystemParametersInfo(SPI_SETMOUSETRAILS, NULL,
(PVOID)_saved_mouse_trails, NULL); (PVOID)_saved_mouse_trails, NULL);
SystemParametersInfo(SPI_SETCURSORSHADOW, NULL, SystemParametersInfo(SPI_SETCURSORSHADOW, NULL,
(PVOID)_saved_cursor_shadow, NULL); (PVOID)_saved_cursor_shadow, NULL);
SystemParametersInfo(SPI_SETMOUSEVANISH, NULL, SystemParametersInfo(SPI_SETMOUSEVANISH, NULL,
(PVOID)_saved_mouse_vanish, NULL); (PVOID)_saved_mouse_vanish, NULL);
@ -2216,11 +2217,11 @@ update_cursor_window(WinGraphicsWindow *to_window) {
// These parameters are only defined for Win2000/XP, but they // These parameters are only defined for Win2000/XP, but they
// should just cause a silent error on earlier OS's, which is OK. // should just cause a silent error on earlier OS's, which is OK.
if (!_got_saved_params) { if (!_got_saved_params) {
SystemParametersInfo(SPI_GETMOUSETRAILS, NULL, SystemParametersInfo(SPI_GETMOUSETRAILS, NULL,
&_saved_mouse_trails, NULL); &_saved_mouse_trails, NULL);
SystemParametersInfo(SPI_GETCURSORSHADOW, NULL, SystemParametersInfo(SPI_GETCURSORSHADOW, NULL,
&_saved_cursor_shadow, NULL); &_saved_cursor_shadow, NULL);
SystemParametersInfo(SPI_GETMOUSEVANISH, NULL, SystemParametersInfo(SPI_GETMOUSEVANISH, NULL,
&_saved_mouse_vanish, NULL); &_saved_mouse_vanish, NULL);
_got_saved_params = true; _got_saved_params = true;
@ -2231,7 +2232,7 @@ update_cursor_window(WinGraphicsWindow *to_window) {
SetCursor(to_window->_cursor); SetCursor(to_window->_cursor);
} }
hide_or_show_cursor(hide_cursor); hide_or_show_cursor(hide_cursor);
_cursor_window = to_window; _cursor_window = to_window;
@ -2280,18 +2281,18 @@ find_acceptable_display_mode(DWORD dwWidth, DWORD dwHeight, DWORD bpp,
while (1) { while (1) {
ZeroMemory(&dm, sizeof(dm)); ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm); dm.dmSize = sizeof(dm);
if (!EnumDisplaySettings(NULL, modenum, &dm)) { if (!EnumDisplaySettings(NULL, modenum, &dm)) {
break; break;
} }
if ((dm.dmPelsWidth == dwWidth) && (dm.dmPelsHeight == dwHeight) && if ((dm.dmPelsWidth == dwWidth) && (dm.dmPelsHeight == dwHeight) &&
(dm.dmBitsPerPel == bpp)) { (dm.dmBitsPerPel == bpp)) {
return true; return true;
} }
modenum++; modenum++;
} }
return false; return false;
} }
@ -2309,7 +2310,7 @@ show_error_message(DWORD message_id) {
if (message_id == 0) { if (message_id == 0) {
message_id = GetLastError(); message_id = GetLastError();
} }
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, message_id, NULL, message_id,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //The user default language MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), //The user default language
@ -2681,26 +2682,26 @@ handle_raw_input(HRAWINPUT hraw) {
if (pGetRawInputData(hraw, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER)) == -1) { if (pGetRawInputData(hraw, RID_INPUT, NULL, &dwSize, sizeof(RAWINPUTHEADER)) == -1) {
return; return;
} }
lpb = (LPBYTE)alloca(sizeof(LPBYTE) * dwSize); lpb = (LPBYTE)alloca(sizeof(LPBYTE) * dwSize);
if (lpb == NULL) { if (lpb == NULL) {
return; return;
} }
if (pGetRawInputData(hraw, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize) { if (pGetRawInputData(hraw, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)) != dwSize) {
return; return;
} }
RAWINPUT *raw = (RAWINPUT *)lpb; RAWINPUT *raw = (RAWINPUT *)lpb;
if (raw->header.hDevice == 0) { if (raw->header.hDevice == 0) {
return; return;
} }
for (int i = 1; i < (int)(_input_devices.size()); ++i) { for (int i = 1; i < (int)(_input_devices.size()); ++i) {
if (_input_device_handle[i] == raw->header.hDevice) { if (_input_device_handle[i] == raw->header.hDevice) {
int adjx = raw->data.mouse.lLastX; int adjx = raw->data.mouse.lLastX;
int adjy = raw->data.mouse.lLastY; int adjy = raw->data.mouse.lLastY;
if (raw->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) { if (raw->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE) {
_input_devices[i].set_pointer_in_window(adjx, adjy); _input_devices[i].set_pointer_in_window(adjx, adjy);
} else { } else {
@ -2708,7 +2709,7 @@ handle_raw_input(HRAWINPUT hraw) {
int oldy = _input_devices[i].get_raw_pointer().get_y(); int oldy = _input_devices[i].get_raw_pointer().get_y();
_input_devices[i].set_pointer_in_window(oldx + adjx, oldy + adjy); _input_devices[i].set_pointer_in_window(oldx + adjx, oldy + adjy);
} }
if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_DOWN) { if (raw->data.mouse.usButtonFlags & RI_MOUSE_BUTTON_1_DOWN) {
_input_devices[i].button_down(MouseButton::button(0), get_message_time()); _input_devices[i].button_down(MouseButton::button(0), get_message_time());
} }
@ -2871,7 +2872,7 @@ get_cursor(const Filename &filename) {
} }
static HCURSOR get_cursor(const Filename &filename); static HCURSOR get_cursor(const Filename &filename);
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: WinGraphicsWindow::register_window_class // Function: WinGraphicsWindow::register_window_class
// Access: Private, Static // Access: Private, Static
@ -2912,7 +2913,7 @@ register_window_class(const WindowProperties &props) {
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL; wc.lpszMenuName = NULL;
wc.lpszClassName = wclass._name.c_str(); wc.lpszClassName = wclass._name.c_str();
if (!RegisterClassW(&wc)) { if (!RegisterClassW(&wc)) {
windisplay_cat.error() windisplay_cat.error()
<< "could not register window class " << wclass._name << "!" << endl; << "could not register window class " << wclass._name << "!" << endl;
@ -2925,7 +2926,7 @@ register_window_class(const WindowProperties &props) {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: WinGraphicsWindow::WinWindowHandle::Constructor // Function: WinGraphicsWindow::WinWindowHandle::Constructor
// Access: Public // Access: Public
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
WinGraphicsWindow::WinWindowHandle:: WinGraphicsWindow::WinWindowHandle::
WinWindowHandle(WinGraphicsWindow *window, const WindowHandle &copy) : WinWindowHandle(WinGraphicsWindow *window, const WindowHandle &copy) :
@ -3033,7 +3034,7 @@ void get_client_rect_screen(HWND hwnd, RECT *view_rect) {
// Access: Public, Virtual // Access: Public, Virtual
// Description: Adds the specified Windows proc event handler to be called // Description: Adds the specified Windows proc event handler to be called
// whenever a Windows event occurs. // whenever a Windows event occurs.
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void WinGraphicsWindow::add_window_proc( const GraphicsWindowProc* wnd_proc ){ void WinGraphicsWindow::add_window_proc( const GraphicsWindowProc* wnd_proc ){
nassertv(wnd_proc != NULL); nassertv(wnd_proc != NULL);
@ -3044,7 +3045,7 @@ void WinGraphicsWindow::add_window_proc( const GraphicsWindowProc* wnd_proc ){
// Function: WinGraphicsWindow::remove_window_proc // Function: WinGraphicsWindow::remove_window_proc
// Access: Public, Virtual // Access: Public, Virtual
// Description: Removes the specified Windows proc event handler. // Description: Removes the specified Windows proc event handler.
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void WinGraphicsWindow::remove_window_proc( const GraphicsWindowProc* wnd_proc ){ void WinGraphicsWindow::remove_window_proc( const GraphicsWindowProc* wnd_proc ){
nassertv(wnd_proc != NULL); nassertv(wnd_proc != NULL);
@ -3055,7 +3056,7 @@ void WinGraphicsWindow::remove_window_proc( const GraphicsWindowProc* wnd_proc )
// Function: WinGraphicsWindow::clear_window_procs // Function: WinGraphicsWindow::clear_window_procs
// Access: Public, Virtual // Access: Public, Virtual
// Description: Removes all Windows proc event handlers. // Description: Removes all Windows proc event handlers.
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void WinGraphicsWindow::clear_window_procs(){ void WinGraphicsWindow::clear_window_procs(){
_window_proc_classes.clear(); _window_proc_classes.clear();
@ -3065,7 +3066,7 @@ void WinGraphicsWindow::clear_window_procs(){
// Function: WinGraphicsWindow::supports_window_procs // Function: WinGraphicsWindow::supports_window_procs
// Access: Public, Virtual // Access: Public, Virtual
// Description: Returns whether this window supports adding of windows proc handlers. // Description: Returns whether this window supports adding of windows proc handlers.
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool WinGraphicsWindow::supports_window_procs() const{ bool WinGraphicsWindow::supports_window_procs() const{
return true; return true;
@ -3075,7 +3076,7 @@ bool WinGraphicsWindow::supports_window_procs() const{
// Function: WinGraphicsWindow::is_touch_event // Function: WinGraphicsWindow::is_touch_event
// Access: Public, Virtual // Access: Public, Virtual
// Description: Returns whether the specified event msg is a touch message. // Description: Returns whether the specified event msg is a touch message.
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool WinGraphicsWindow:: bool WinGraphicsWindow::
is_touch_event(GraphicsWindowProcCallbackData* callbackData){ is_touch_event(GraphicsWindowProcCallbackData* callbackData){
@ -3090,7 +3091,7 @@ is_touch_event(GraphicsWindowProcCallbackData* callbackData){
// Function: WinGraphicsWindow::get_num_touches // Function: WinGraphicsWindow::get_num_touches
// Access: Public, Virtual // Access: Public, Virtual
// Description: Returns the current number of touches on this window. // Description: Returns the current number of touches on this window.
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
int WinGraphicsWindow:: int WinGraphicsWindow::
get_num_touches(){ get_num_touches(){
@ -3105,7 +3106,7 @@ get_num_touches(){
// Function: WinGraphicsWindow::get_touch_info // Function: WinGraphicsWindow::get_touch_info
// Access: Public, Virtual // Access: Public, Virtual
// Description: Returns the TouchInfo object describing the specified touch. // Description: Returns the TouchInfo object describing the specified touch.
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
TouchInfo WinGraphicsWindow:: TouchInfo WinGraphicsWindow::
get_touch_info(int index){ get_touch_info(int index){