+
+// make the window modal (all other windows unresponsive)
+void wxFrame::MakeModal(bool modal)
+{
+ if (modal) {
+ wxEnableTopLevelWindows(FALSE);
+ Enable(TRUE); // keep this window enabled
+ }
+ else {
+ wxEnableTopLevelWindows(TRUE);
+ }
+}
+
+
+// ===========================================================================
+// message processing
+// ===========================================================================
+
+// ---------------------------------------------------------------------------
+// preprocessing
+// ---------------------------------------------------------------------------
+
+bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
+{
+ if ( wxWindow::MSWTranslateMessage(pMsg) )
+ return TRUE;
+
+ // try the menu bar accels
+ wxMenuBar *menuBar = GetMenuBar();
+ if ( !menuBar )
+ return FALSE;
+
+ const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
+ return acceleratorTable.Ok() &&
+ ::TranslateAccelerator(GetHwnd(),
+ GetTableHaccel(acceleratorTable),
+ (MSG *)pMsg);
+}
+
+// ---------------------------------------------------------------------------
+// our private (non virtual) message handlers
+// ---------------------------------------------------------------------------
+
+bool wxFrame::HandlePaint()
+{
+ RECT rect;
+ if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
+ {
+ if ( m_iconized )
+ {
+ HICON hIcon = m_icon.Ok() ? GetIconHicon(m_icon)
+ : (HICON)m_defaultIcon;
+
+ // Hold a pointer to the dc so long as the OnPaint() message
+ // is being processed
+ PAINTSTRUCT ps;
+ HDC hdc = ::BeginPaint(GetHwnd(), &ps);
+
+ // Erase background before painting or we get white background
+ MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
+
+ if ( hIcon )
+ {
+ RECT rect;
+ ::GetClientRect(GetHwnd(), &rect);
+
+ // FIXME: why hardcoded?
+ static const int icon_width = 32;
+ static const int icon_height = 32;
+
+ int icon_x = (int)((rect.right - icon_width)/2);
+ int icon_y = (int)((rect.bottom - icon_height)/2);
+
+ ::DrawIcon(hdc, icon_x, icon_y, hIcon);
+ }
+
+ ::EndPaint(GetHwnd(), &ps);
+
+ return TRUE;
+ }
+ else
+ {
+ wxPaintEvent event(m_windowId);
+ event.m_eventObject = this;
+
+ return GetEventHandler()->ProcessEvent(event);
+ }
+ }
+ else
+ {
+ // nothing to paint - processed
+ return TRUE;
+ }
+}
+
+bool wxFrame::HandleSize(int x, int y, WXUINT id)
+{
+ bool processed = FALSE;
+
+ switch ( id )
+ {
+ case SIZENORMAL:
+ // only do it it if we were iconized before, otherwise resizing the
+ // parent frame has a curious side effect of bringing it under it's
+ // children
+ if ( !m_iconized )
+ break;
+
+ // restore all child frames too
+ IconizeChildFrames(FALSE);
+
+ // fall through
+
+ case SIZEFULLSCREEN:
+ m_iconized = FALSE;
+ break;
+
+ case SIZEICONIC:
+ // iconize all child frames too
+ IconizeChildFrames(TRUE);
+
+ m_iconized = TRUE;
+ break;
+ }
+
+ if ( !m_iconized )
+ {
+ // forward WM_SIZE to status bar control
+#if wxUSE_NATIVE_STATUSBAR
+ if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
+ {
+ wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
+ event.SetEventObject( m_frameStatusBar );
+
+ ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
+ }
+#endif // wxUSE_NATIVE_STATUSBAR
+
+ PositionStatusBar();
+ PositionToolBar();
+
+ wxSizeEvent event(wxSize(x, y), m_windowId);
+ event.SetEventObject( this );
+ processed = GetEventHandler()->ProcessEvent(event);
+ }
+
+ return processed;
+}
+
+bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
+{
+ if ( control )
+ {
+ // In case it's e.g. a toolbar.
+ wxWindow *win = wxFindWinFromHandle(control);
+ if ( win )
+ return win->MSWCommand(cmd, id);
+ }
+
+ // handle here commands from menus and accelerators
+ if ( cmd == 0 || cmd == 1 )
+ {
+ if ( wxCurrentPopupMenu )
+ {
+ wxMenu *popupMenu = wxCurrentPopupMenu;
+ wxCurrentPopupMenu = NULL;
+
+ return popupMenu->MSWCommand(cmd, id);
+ }
+
+ if ( ProcessCommand(id) )
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD nFlags, WXHMENU hMenu)
+{
+ int item;
+ if ( nFlags == 0xFFFF && hMenu == 0 )
+ {
+ // FIXME: what does this do? does it ever happen?
+ item = -1;
+ }
+ else if ((nFlags != MF_SEPARATOR) && (nItem != 0) && (nItem != 65535))
+ {
+ item = nItem;
+ }
+ else
+ {
+ return FALSE;
+ }
+
+ wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
+ event.SetEventObject( this );
+
+ return GetEventHandler()->ProcessEvent(event);
+}
+
+// ---------------------------------------------------------------------------
+// the window proc for wxFrame
+// ---------------------------------------------------------------------------
+
+long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
+{
+ long rc = 0;
+ bool processed = FALSE;
+
+ switch ( message )
+ {
+ case WM_CLOSE:
+ // if we can't close, tell the system that we processed the
+ // message - otherwise it would close us
+ processed = !Close();
+ break;
+
+ case WM_COMMAND:
+ {
+ WORD id, cmd;
+ WXHWND hwnd;
+ UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
+ &id, &hwnd, &cmd);
+
+ processed = HandleCommand(id, cmd, (WXHWND)hwnd);
+ }
+ break;
+
+ case WM_MENUSELECT:
+ {
+ WXWORD item, flags;
+ WXHMENU hmenu;
+ UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
+
+ processed = HandleMenuSelect(item, flags, hmenu);
+ }
+ break;
+
+ case WM_PAINT:
+ processed = HandlePaint();
+ break;
+
+ case WM_QUERYDRAGICON:
+ {
+ HICON hIcon = m_icon.Ok() ? GetIconHicon(m_icon)
+ : (HICON)(m_defaultIcon);
+ rc = (long)hIcon;
+ processed = rc != 0;
+ }
+ break;
+
+ case WM_SIZE:
+ processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
+ break;
+ }
+
+ if ( !processed )
+ rc = wxWindow::MSWWindowProc(message, wParam, lParam);
+
+ return rc;
+}