+ default:
+ wxFAIL_MSG( _T("unexpected WM_SIZE parameter") );
+ // fall through nevertheless
+
+ case SIZE_MAXIMIZED:
+ case SIZE_RESTORED:
+ processed = HandleSize(LOWORD(lParam), HIWORD(lParam),
+ wParam);
+ }
+ break;
+
+#ifndef __WXMICROWIN__
+ case WM_ACTIVATEAPP:
+ wxTheApp->SetActive(wParam != 0, FindFocus());
+ break;
+#endif
+
+ case WM_ACTIVATE:
+ {
+ WXWORD state, minimized;
+ WXHWND hwnd;
+ UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
+
+ processed = HandleActivate(state, minimized != 0, (WXHWND)hwnd);
+ }
+ break;
+
+ case WM_SETFOCUS:
+ processed = HandleSetFocus((WXHWND)(HWND)wParam);
+ break;
+
+ case WM_KILLFOCUS:
+ processed = HandleKillFocus((WXHWND)(HWND)wParam);
+ break;
+
+ case WM_PAINT:
+ processed = HandlePaint();
+ break;
+
+ case WM_CLOSE:
+ // don't let the DefWindowProc() destroy our window - we'll do it
+ // ourselves in ~wxWindow
+ processed = TRUE;
+ rc.result = TRUE;
+ break;
+
+ case WM_SHOWWINDOW:
+ processed = HandleShow(wParam != 0, (int)lParam);
+ break;
+
+ case WM_MOUSEMOVE:
+ processed = HandleMouseMove(GET_X_LPARAM(lParam),
+ GET_Y_LPARAM(lParam),
+ wParam);
+ break;
+
+#if wxUSE_MOUSEWHEEL
+ case WM_MOUSEWHEEL:
+ processed = HandleMouseWheel(wParam, lParam);
+ break;
+#endif
+
+ case WM_LBUTTONDOWN:
+ case WM_LBUTTONUP:
+ case WM_LBUTTONDBLCLK:
+ case WM_RBUTTONDOWN:
+ case WM_RBUTTONUP:
+ case WM_RBUTTONDBLCLK:
+ case WM_MBUTTONDOWN:
+ case WM_MBUTTONUP:
+ case WM_MBUTTONDBLCLK:
+ {
+ processed = FALSE;
+#ifdef __WXMICROWIN__
+ // MicroWindows seems to ignore the fact that a window is
+ // disabled. So catch mouse events and throw them away if
+ // necessary.
+ wxWindowMSW* win = this;
+ while (win)
+ {
+ if (!win->IsEnabled())
+ {
+ processed = TRUE;
+ break;
+ }
+ win = win->GetParent();
+ if (win && win->IsTopLevel())
+ break;
+ }
+#endif // __WXMICROWIN__
+ if (!processed)
+ {
+ if (message == WM_LBUTTONDOWN && AcceptsFocus())
+ SetFocus();
+ processed = HandleMouseEvent(message,
+ GET_X_LPARAM(lParam),
+ GET_Y_LPARAM(lParam),
+ wParam);
+ }
+ break;
+ }
+
+#ifdef __WXMICROWIN__
+ case WM_NCLBUTTONDOWN:
+ case WM_NCLBUTTONUP:
+ case WM_NCLBUTTONDBLCLK:
+ case WM_NCRBUTTONDOWN:
+ case WM_NCRBUTTONUP:
+ case WM_NCRBUTTONDBLCLK:
+#if 0
+ case WM_NCMBUTTONDOWN:
+ case WM_NCMBUTTONUP:
+ case WM_NCMBUTTONDBLCLK:
+#endif
+ {
+ // MicroWindows seems to ignore the fact that a window
+ // is disabled. So catch mouse events and throw them away if necessary.
+ processed = FALSE;
+ wxWindowMSW* win = this;
+ while (win)
+ {
+ if (!win->IsEnabled())
+ {
+ processed = TRUE;
+ break;
+ }
+ win = win->GetParent();
+ if (win && win->IsTopLevel())
+ break;
+ }
+ break;
+ }
+#endif // __WXMICROWIN__
+
+#ifdef MM_JOY1MOVE
+ case MM_JOY1MOVE:
+ case MM_JOY2MOVE:
+ case MM_JOY1ZMOVE:
+ case MM_JOY2ZMOVE:
+ case MM_JOY1BUTTONDOWN:
+ case MM_JOY2BUTTONDOWN:
+ case MM_JOY1BUTTONUP:
+ case MM_JOY2BUTTONUP:
+ processed = HandleJoystickEvent(message,
+ GET_X_LPARAM(lParam),
+ GET_Y_LPARAM(lParam),
+ wParam);
+ break;
+#endif // __WXMICROWIN__
+
+ case WM_SYSCOMMAND:
+ processed = HandleSysCommand(wParam, lParam);
+ break;
+
+ case WM_COMMAND:
+ {
+ WORD id, cmd;
+ WXHWND hwnd;
+ UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
+
+ processed = HandleCommand(id, cmd, hwnd);
+ }
+ break;
+
+#ifdef __WIN95__
+ case WM_NOTIFY:
+ processed = HandleNotify((int)wParam, lParam, &rc.result);
+ break;
+#endif // Win95
+
+ // for these messages we must return TRUE if process the message
+#ifdef WM_DRAWITEM
+ case WM_DRAWITEM:
+ case WM_MEASUREITEM:
+ {
+ int idCtrl = (UINT)wParam;
+ if ( message == WM_DRAWITEM )
+ {
+ processed = MSWOnDrawItem(idCtrl,
+ (WXDRAWITEMSTRUCT *)lParam);
+ }
+ else
+ {
+ processed = MSWOnMeasureItem(idCtrl,
+ (WXMEASUREITEMSTRUCT *)lParam);
+ }
+
+ if ( processed )
+ rc.result = TRUE;
+ }
+ break;
+#endif // defined(WM_DRAWITEM)
+
+ case WM_GETDLGCODE:
+ if ( GetWindowStyleFlag() & wxWANTS_CHARS )
+ {
+ // want everything: i.e. all keys and WM_CHAR message
+ rc.result = DLGC_WANTARROWS | DLGC_WANTCHARS |
+ DLGC_WANTTAB | DLGC_WANTMESSAGE;
+ processed = TRUE;
+ }
+ //else: get the dlg code from the DefWindowProc()
+ break;
+
+ case WM_SYSKEYDOWN:
+ case WM_KEYDOWN:
+ // If this has been processed by an event handler,
+ // return 0 now (we've handled it).
+ if ( HandleKeyDown((WORD) wParam, lParam) )
+ {
+ processed = TRUE;
+
+ break;
+ }
+
+ // we consider these message "not interesting" to OnChar
+ if ( wParam == VK_SHIFT || wParam == VK_CONTROL )
+ {
+ processed = TRUE;
+
+ break;
+ }
+
+ switch ( wParam )
+ {
+ // avoid duplicate messages to OnChar for these ASCII keys: they
+ // will be translated by TranslateMessage() and received in WM_CHAR
+ case VK_ESCAPE:
+ case VK_SPACE:
+ case VK_RETURN:
+ case VK_BACK:
+ case VK_TAB:
+ case VK_ADD:
+ case VK_SUBTRACT:
+ // but set processed to FALSE, not TRUE to still pass them to
+ // the control's default window proc - otherwise built-in
+ // keyboard handling won't work
+ processed = FALSE;
+
+ break;
+
+#ifdef VK_APPS
+ // special case of VK_APPS: treat it the same as right mouse
+ // click because both usually pop up a context menu
+ case VK_APPS:
+ {
+ WPARAM flags;
+ int x, y;
+
+ TranslateKbdEventToMouse(this, &x, &y, &flags);
+ processed = HandleMouseEvent(WM_RBUTTONDOWN, x, y, flags);
+ }
+ break;
+#endif // VK_APPS
+
+ case VK_LEFT:
+ case VK_RIGHT:
+ case VK_DOWN:
+ case VK_UP:
+ default:
+ processed = HandleChar((WORD)wParam, lParam);
+ }
+ break;
+
+ case WM_SYSKEYUP:
+ case WM_KEYUP:
+#ifdef VK_APPS
+ // special case of VK_APPS: treat it the same as right mouse button
+ if ( wParam == VK_APPS )
+ {
+ WPARAM flags;
+ int x, y;
+
+ TranslateKbdEventToMouse(this, &x, &y, &flags);
+ processed = HandleMouseEvent(WM_RBUTTONUP, x, y, flags);
+ }
+ else
+#endif // VK_APPS
+ {
+ processed = HandleKeyUp((WORD) wParam, lParam);
+ }
+ break;
+
+ case WM_SYSCHAR:
+ case WM_CHAR: // Always an ASCII character
+ processed = HandleChar((WORD)wParam, lParam, TRUE);
+ break;
+
+ case WM_HSCROLL:
+ case WM_VSCROLL:
+ {
+ WXWORD code, pos;
+ WXHWND hwnd;
+ UnpackScroll(wParam, lParam, &code, &pos, &hwnd);
+
+ processed = MSWOnScroll(message == WM_HSCROLL ? wxHORIZONTAL
+ : wxVERTICAL,
+ code, pos, hwnd);
+ }
+ break;
+
+ // CTLCOLOR messages are sent by children to query the parent for their
+ // colors#ifndef __WXMICROWIN__
+#ifndef __WXMICROWIN__
+#ifdef __WIN32__
+ case WM_CTLCOLORMSGBOX:
+ case WM_CTLCOLOREDIT:
+ case WM_CTLCOLORLISTBOX:
+ case WM_CTLCOLORBTN:
+ case WM_CTLCOLORDLG:
+ case WM_CTLCOLORSCROLLBAR:
+ case WM_CTLCOLORSTATIC:
+#else // Win16
+ case WM_CTLCOLOR:
+#endif // Win32/16
+ {
+ WXWORD nCtlColor;
+ WXHDC hdc;
+ WXHWND hwnd;
+ UnpackCtlColor(wParam, lParam, &nCtlColor, &hdc, &hwnd);
+
+ processed = HandleCtlColor(&rc.hBrush,
+ (WXHDC)hdc,
+ (WXHWND)hwnd,
+ nCtlColor,
+ message,
+ wParam,
+ lParam);
+ }
+ break;
+#endif // !__WXMICROWIN__
+
+ case WM_SYSCOLORCHANGE:
+ // the return value for this message is ignored
+ processed = HandleSysColorChange();
+ break;
+
+ case WM_DISPLAYCHANGE:
+ processed = HandleDisplayChange();
+ break;
+
+ case WM_PALETTECHANGED:
+ processed = HandlePaletteChanged((WXHWND) (HWND) wParam);
+ break;
+
+ case WM_QUERYNEWPALETTE:
+ processed = HandleQueryNewPalette();
+ break;
+
+ case WM_ERASEBKGND:
+ processed = HandleEraseBkgnd((WXHDC)(HDC)wParam);
+ if ( processed )
+ {
+ // we processed the message, i.e. erased the background
+ rc.result = TRUE;
+ }
+ break;
+
+ case WM_DROPFILES:
+ processed = HandleDropFiles(wParam);
+ break;
+
+ case WM_INITDIALOG:
+ processed = HandleInitDialog((WXHWND)(HWND)wParam);
+
+ if ( processed )
+ {
+ // we never set focus from here
+ rc.result = FALSE;
+ }
+ break;
+
+ case WM_QUERYENDSESSION:
+ processed = HandleQueryEndSession(lParam, &rc.allow);
+ break;
+
+ case WM_ENDSESSION:
+ processed = HandleEndSession(wParam != 0, lParam);
+ break;
+
+ case WM_GETMINMAXINFO:
+ processed = HandleGetMinMaxInfo((MINMAXINFO*)lParam);
+ break;
+
+ case WM_SETCURSOR:
+ processed = HandleSetCursor((WXHWND)(HWND)wParam,
+ LOWORD(lParam), // hit test
+ HIWORD(lParam)); // mouse msg
+
+ if ( processed )
+ {
+ // returning TRUE stops the DefWindowProc() from further
+ // processing this message - exactly what we need because we've
+ // just set the cursor.
+ rc.result = TRUE;
+ }
+ break;
+
+#if defined(__WIN32__) && defined(WM_HELP)
+ case WM_HELP:
+ {
+ HELPINFO* info = (HELPINFO*) lParam;
+ // Don't yet process menu help events, just windows
+ if (info->iContextType == HELPINFO_WINDOW)
+ {
+ wxWindowMSW* subjectOfHelp = this;
+ bool eventProcessed = FALSE;
+ while (subjectOfHelp && !eventProcessed)
+ {
+ wxHelpEvent helpEvent(wxEVT_HELP,
+ subjectOfHelp->GetId(),
+ wxPoint(info->MousePos.x,
+ info->MousePos.y) );
+ helpEvent.SetEventObject(this);
+ eventProcessed =
+ GetEventHandler()->ProcessEvent(helpEvent);
+
+ // Go up the window hierarchy until the event is
+ // handled (or not)
+ subjectOfHelp = subjectOfHelp->GetParent();
+ }
+
+ processed = eventProcessed;
+ }
+ else if (info->iContextType == HELPINFO_MENUITEM)
+ {
+ wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
+ helpEvent.SetEventObject(this);
+ processed = GetEventHandler()->ProcessEvent(helpEvent);
+
+ }
+ //else: processed is already FALSE
+ }
+ break;
+
+ case WM_CONTEXTMENU:
+ {
+ // we don't convert from screen to client coordinates as
+ // the event may be handled by a parent window
+ wxPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
+
+ wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt);
+ processed = GetEventHandler()->ProcessEvent(evtCtx);
+ }
+ break;
+#endif // __WIN32__
+ }
+
+ if ( !processed )
+ {
+#ifdef __WXDEBUG__
+ wxLogTrace(wxTraceMessages, wxT("Forwarding %s to DefWindowProc."),
+ wxGetMessageName(message));
+#endif // __WXDEBUG__
+ rc.result = MSWDefWindowProc(message, wParam, lParam);
+ }
+
+ return rc.result;
+}
+
+// ----------------------------------------------------------------------------
+// wxWindow <-> HWND map
+// ----------------------------------------------------------------------------
+
+wxWinHashTable *wxWinHandleHash = NULL;
+
+wxWindow *wxFindWinFromHandle(WXHWND hWnd)
+{
+ return wxWinHandleHash->Get((long)hWnd);
+}
+
+void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win)
+{
+ // adding NULL hWnd is (first) surely a result of an error and
+ // (secondly) breaks menu command processing
+ wxCHECK_RET( hWnd != (HWND)NULL,
+ wxT("attempt to add a NULL hWnd to window list ignored") );
+
+ wxWindow *oldWin = wxFindWinFromHandle((WXHWND) hWnd);
+#ifdef __WXDEBUG__
+ if ( oldWin && (oldWin != win) )
+ {
+ wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
+ hWnd, win->GetClassInfo()->GetClassName());
+ }
+ else
+#endif // __WXDEBUG__
+ if (!oldWin)
+ {
+ wxWinHandleHash->Put((long)hWnd, (wxWindow *)win);
+ }
+}
+
+void wxRemoveHandleAssociation(wxWindowMSW *win)
+{
+ wxWinHandleHash->Delete((long)win->GetHWND());
+}
+
+// ----------------------------------------------------------------------------
+// various MSW speciic class dependent functions
+// ----------------------------------------------------------------------------
+
+// Default destroyer - override if you destroy it in some other way
+// (e.g. with MDI child windows)
+void wxWindowMSW::MSWDestroyWindow()
+{
+}
+
+bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos,
+ const wxSize& size,
+ int& x, int& y,
+ int& w, int& h) const
+{
+ bool nonDefault = FALSE;
+
+ if ( pos.x == -1 )
+ {
+ // if set x to CW_USEDEFAULT, y parameter is ignored anyhow so we can
+ // just as well set it to CW_USEDEFAULT as well
+ x =
+ y = CW_USEDEFAULT;
+ }
+ else
+ {
+ x = pos.x;
+ y = pos.y == -1 ? CW_USEDEFAULT : pos.y;
+
+ nonDefault = TRUE;
+ }
+
+ /*
+ NB: there used to be some code here which set the initial size of the
+ window to the client size of the parent if no explicit size was
+ specified. This was wrong because wxWindows programs often assume
+ that they get a WM_SIZE (EVT_SIZE) upon creation, however this broke
+ it. To see why, you should understand that Windows sends WM_SIZE from
+ inside ::CreateWindow() anyhow. However, ::CreateWindow() is called
+ from some base class ctor and so this WM_SIZE is not processed in the
+ real class' OnSize() (because it's not fully constructed yet and the
+ event goes to some base class OnSize() instead). So the WM_SIZE we
+ rely on is the one sent when the parent frame resizes its children
+ but here is the problem: if the child already has just the right
+ size, nothing will happen as both wxWindows and Windows check for
+ this and ignore any attempts to change the window size to the size it
+ already has - so no WM_SIZE would be sent.
+ */
+ if ( size.x == -1 )
+ {
+ // as abobe, h is not used at all in this case anyhow
+ w =
+ h = CW_USEDEFAULT;
+ }
+ else
+ {
+ w = size.x;
+ h = size.y == -1 ? CW_USEDEFAULT : size.y;
+
+ nonDefault = TRUE;
+ }
+
+ return nonDefault;
+}
+
+bool wxWindowMSW::MSWCreate(const wxChar *wclass,
+ const wxChar *title,
+ const wxPoint& pos,
+ const wxSize& size,
+ WXDWORD style,
+ WXDWORD extendedStyle)
+{
+ // choose the position/size for the new window
+ int x, y, w, h;
+ (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h);
+
+ // find the correct parent HWND
+ wxWindow *parent = GetParent();
+ bool isChild = (style & WS_CHILD) != 0;
+ HWND hParent;
+ if ( GetWindowStyleFlag() & wxPOPUP_WINDOW )
+ {
+ // popup windows should have desktop as parent because they shouldn't
+ // be limited to the parents client area as child windows usually are
+ hParent = ::GetDesktopWindow();
+ }
+ else // !popup
+ {
+ if ( (isChild || HasFlag(wxFRAME_TOOL_WINDOW)) && parent )
+ {
+ // this is either a normal child window or a top level window with
+ // wxFRAME_TOOL_WINDOW style (see below)
+ hParent = GetHwndOf(parent);
+ }