1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/frame.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/dcclient.h"
40 #include "wx/toolbar.h"
41 #include "wx/statusbr.h"
42 #include "wx/menuitem.h"
45 #include "wx/msw/private.h"
47 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
50 #include "wx/msw/winundef.h"
53 #ifdef __WXUNIVERSAL__
54 #include "wx/univ/theme.h"
55 #include "wx/univ/colschem.h"
56 #endif // __WXUNIVERSAL__
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 #if wxUSE_MENUS_NATIVE
63 extern wxMenu
*wxCurrentPopupMenu
;
64 #endif // wxUSE_MENUS_NATIVE
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
71 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
74 #if wxUSE_EXTENDED_RTTI
75 WX_DEFINE_FLAGS( wxFrameStyle
)
77 wxBEGIN_FLAGS( wxFrameStyle
)
78 // new style border flags, we put them first to
79 // use them for streaming out
80 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
81 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
82 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
83 wxFLAGS_MEMBER(wxBORDER_RAISED
)
84 wxFLAGS_MEMBER(wxBORDER_STATIC
)
85 wxFLAGS_MEMBER(wxBORDER_NONE
)
87 // old style border flags
88 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
89 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
90 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
91 wxFLAGS_MEMBER(wxRAISED_BORDER
)
92 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
93 wxFLAGS_MEMBER(wxBORDER
)
95 // standard window styles
96 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
97 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
98 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
99 wxFLAGS_MEMBER(wxWANTS_CHARS
)
100 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
101 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
102 wxFLAGS_MEMBER(wxVSCROLL
)
103 wxFLAGS_MEMBER(wxHSCROLL
)
106 wxFLAGS_MEMBER(wxSTAY_ON_TOP
)
107 wxFLAGS_MEMBER(wxCAPTION
)
108 #if WXWIN_COMPATIBILITY_2_6
109 wxFLAGS_MEMBER(wxTHICK_FRAME
)
110 #endif // WXWIN_COMPATIBILITY_2_6
111 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
112 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
113 #if WXWIN_COMPATIBILITY_2_6
114 wxFLAGS_MEMBER(wxRESIZE_BOX
)
115 #endif // WXWIN_COMPATIBILITY_2_6
116 wxFLAGS_MEMBER(wxCLOSE_BOX
)
117 wxFLAGS_MEMBER(wxMAXIMIZE_BOX
)
118 wxFLAGS_MEMBER(wxMINIMIZE_BOX
)
120 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW
)
121 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT
)
123 wxFLAGS_MEMBER(wxFRAME_SHAPED
)
125 wxEND_FLAGS( wxFrameStyle
)
127 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame
, wxTopLevelWindow
,"wx/frame.h")
129 wxBEGIN_PROPERTIES_TABLE(wxFrame
)
130 wxEVENT_PROPERTY( Menu
, wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
)
132 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
133 wxPROPERTY_FLAGS( WindowStyle
, wxFrameStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
134 wxPROPERTY( MenuBar
, wxMenuBar
* , SetMenuBar
, GetMenuBar
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
135 wxEND_PROPERTIES_TABLE()
137 wxBEGIN_HANDLERS_TABLE(wxFrame
)
138 wxEND_HANDLERS_TABLE()
140 wxCONSTRUCTOR_6( wxFrame
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Title
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
143 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
146 // ============================================================================
148 // ============================================================================
150 // ----------------------------------------------------------------------------
151 // static class members
152 // ----------------------------------------------------------------------------
155 #if wxUSE_NATIVE_STATUSBAR
156 bool wxFrame::m_useNativeStatusBar
= true;
158 bool wxFrame::m_useNativeStatusBar
= false;
160 #endif // wxUSE_NATIVE_STATUSBAR
162 // ----------------------------------------------------------------------------
163 // creation/destruction
164 // ----------------------------------------------------------------------------
170 #endif // wxUSE_MENUS
176 m_wasMinimized
= false;
179 bool wxFrame::Create(wxWindow
*parent
,
181 const wxString
& title
,
185 const wxString
& name
)
187 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
190 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
192 #if defined(__SMARTPHONE__)
193 SetLeftMenu(wxID_EXIT
, _("Done"));
196 #if wxUSE_ACCEL && defined(__POCKETPC__)
197 // The guidelines state that Ctrl+Q should quit the app.
198 // Let's define an accelerator table to send wxID_EXIT.
199 wxAcceleratorEntry entries
[1];
200 entries
[0].Set(wxACCEL_CTRL
, 'Q', wxID_EXIT
);
201 wxAcceleratorTable
accel(1, entries
);
202 SetAcceleratorTable(accel
);
203 #endif // wxUSE_ACCEL && __POCKETPC__
210 m_isBeingDeleted
= true;
214 // ----------------------------------------------------------------------------
215 // wxFrame client size calculations
216 // ----------------------------------------------------------------------------
218 void wxFrame::DoSetClientSize(int width
, int height
)
220 // leave enough space for the status bar if we have (and show) it
222 wxStatusBar
*statbar
= GetStatusBar();
223 if ( statbar
&& statbar
->IsShown() )
225 height
+= statbar
->GetSize().y
;
227 #endif // wxUSE_STATUSBAR
229 // call GetClientAreaOrigin() to take the toolbar into account
230 wxPoint pt
= GetClientAreaOrigin();
234 wxTopLevelWindow::DoSetClientSize(width
, height
);
237 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
238 void wxFrame::DoGetClientSize(int *x
, int *y
) const
240 wxTopLevelWindow::DoGetClientSize(x
, y
);
242 // account for the possible toolbar
243 wxPoint pt
= GetClientAreaOrigin();
251 // adjust client area height to take the status bar into account
254 wxStatusBar
*statbar
= GetStatusBar();
255 if ( statbar
&& statbar
->IsShown() )
257 *y
-= statbar
->GetClientSize().y
;
260 #endif // wxUSE_STATUSBAR
263 // ----------------------------------------------------------------------------
264 // wxFrame: various geometry-related functions
265 // ----------------------------------------------------------------------------
267 void wxFrame::Raise()
269 ::SetForegroundWindow(GetHwnd());
272 // generate an artificial resize event
273 void wxFrame::SendSizeEvent()
277 RECT r
= wxGetWindowRect(GetHwnd());
279 (void)::PostMessage(GetHwnd(), WM_SIZE
,
280 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
281 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
286 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
289 const wxString
& name
)
291 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
293 #if wxUSE_NATIVE_STATUSBAR
294 if ( !UsesNativeStatusBar() )
296 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
301 statusBar
= new wxStatusBar(this, id
, style
, name
);
304 statusBar
->SetFieldsCount(number
);
309 void wxFrame::PositionStatusBar()
311 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
315 GetClientSize(&w
, &h
);
317 m_frameStatusBar
->GetSize(&sw
, &sh
);
319 // Since we wish the status bar to be directly under the client area,
320 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
321 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
323 #endif // wxUSE_STATUSBAR
325 #if wxUSE_MENUS_NATIVE
327 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
329 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
331 wxMenu
*autoMenu
= NULL
;
333 if( menubar
->GetMenuCount() == 1 )
335 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
336 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
340 autoMenu
= new wxMenu
;
342 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
344 wxMenu
*item
= menubar
->GetMenu(n
);
345 wxString label
= menubar
->GetLabelTop(n
);
346 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
347 autoMenu
->Append(wxID_ANY
, label
, new_item
);
350 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
353 #elif defined(WINCE_WITHOUT_COMMANDBAR)
356 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
357 wxDefaultPosition
, wxDefaultSize
,
358 wxBORDER_NONE
| wxTB_HORIZONTAL
,
359 wxToolBarNameStr
, menubar
);
361 menubar
->SetToolBar(toolBar
);
363 // Now adjust size for menu bar
366 //When the main window is created using CW_USEDEFAULT the height of the
367 // is created is not taken into account). So we resize the window after
368 // if a menubar is present
371 ::GetWindowRect((HWND
) GetHWND(), &rc
);
372 // adjust for menu / titlebar height
373 rc
.bottom
-= (2*menuHeight
-1);
375 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
379 wxFrameBase::AttachMenuBar(menubar
);
383 // actually remove the menu from the frame
384 m_hMenu
= (WXHMENU
)0;
385 InternalSetMenuBar();
387 else // set new non NULL menu bar
389 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
390 // Can set a menubar several times.
391 if ( menubar
->GetHMenu() )
393 m_hMenu
= menubar
->GetHMenu();
397 m_hMenu
= menubar
->Create();
401 wxFAIL_MSG( _T("failed to create menu bar") );
406 InternalSetMenuBar();
410 void wxFrame::InternalSetMenuBar()
412 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
415 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
417 wxLogLastError(wxT("SetMenu"));
422 #endif // wxUSE_MENUS_NATIVE
424 // Responds to colour changes, and passes event on to children.
425 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
427 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
431 if ( m_frameStatusBar
)
433 wxSysColourChangedEvent event2
;
434 event2
.SetEventObject( m_frameStatusBar
);
435 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
437 #endif // wxUSE_STATUSBAR
439 // Propagate the event to the non-top-level children
440 wxWindow::OnSysColourChanged(event
);
443 // Pass true to show full screen, false to restore.
444 bool wxFrame::ShowFullScreen(bool show
, long style
)
446 // TODO-CE: add support for CE
447 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
448 if ( IsFullScreen() == show
)
453 // zap the toolbar, menubar, and statusbar if needed
455 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
457 wxToolBar
*theToolBar
= GetToolBar();
459 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
461 if ( theToolBar
->IsShown() )
463 theToolBar
->SetSize(wxDefaultCoord
,0);
464 theToolBar
->Show(false);
466 else // prevent it from being restored later
468 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
471 #endif // wxUSE_TOOLBAR
473 if (style
& wxFULLSCREEN_NOMENUBAR
)
474 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
477 wxStatusBar
*theStatusBar
= GetStatusBar();
479 // Save the number of fields in the statusbar
480 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
482 if ( theStatusBar
->IsShown() )
483 theStatusBar
->Show(false);
485 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
487 #endif // wxUSE_STATUSBAR
489 else // restore to normal
491 // restore the toolbar, menubar, and statusbar if we had hid them
493 wxToolBar
*theToolBar
= GetToolBar();
495 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
497 theToolBar
->Show(true);
499 #endif // wxUSE_TOOLBAR
501 if (m_fsStyle
& wxFULLSCREEN_NOMENUBAR
)
503 WXHMENU menu
= m_hMenu
;
505 #if wxUSE_MDI_ARCHITECTURE
506 wxMDIParentFrame
*frame
= wxDynamicCast(this, wxMDIParentFrame
);
509 wxMDIChildFrame
*child
= frame
->GetActiveChild();
512 menu
= child
->GetWinMenu();
515 #endif // wxUSE_MDI_ARCHITECTURE
519 ::SetMenu(GetHwnd(), (HMENU
)menu
);
524 wxStatusBar
*theStatusBar
= GetStatusBar();
526 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
528 theStatusBar
->Show(true);
531 #endif // wxUSE_STATUSBAR
533 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
535 return wxFrameBase::ShowFullScreen(show
, style
);
538 // ----------------------------------------------------------------------------
539 // tool/status bar stuff
540 // ----------------------------------------------------------------------------
544 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
546 #if defined(WINCE_WITHOUT_COMMANDBAR)
547 // We may already have a toolbar from calling SetMenuBar.
551 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
556 return m_frameToolBar
;
559 void wxFrame::PositionToolBar()
561 wxToolBar
*toolbar
= GetToolBar();
562 if ( toolbar
&& toolbar
->IsShown() )
564 #if defined(WINCE_WITHOUT_COMMANDBAR)
565 // We want to do something different in WinCE, because
566 // the toolbar should be associated with the commandbar,
567 // and not an independent window.
570 // don't call our (or even wxTopLevelWindow) version because we want
571 // the real (full) client area size, not excluding the tool/status bar
573 wxWindow::DoGetClientSize(&width
, &height
);
576 wxStatusBar
*statbar
= GetStatusBar();
577 if ( statbar
&& statbar
->IsShown() )
579 height
-= statbar
->GetClientSize().y
;
581 #endif // wxUSE_STATUSBAR
585 #if defined(WINCE_WITH_COMMANDBAR)
586 // We're using a commandbar - so we have to allow for it.
587 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
590 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
591 y
= rect
.bottom
- rect
.top
;
597 toolbar
->GetPosition(&tx
, &ty
);
598 toolbar
->GetSize(&tw
, &th
);
601 if (ty
< 0 && (-ty
== th
))
603 if (tx
< 0 && (-tx
== tw
))
609 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
616 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
620 // use the 'real' MSW position here, don't offset relativly to the
621 // client area origin
623 // Optimise such that we don't have to always resize the toolbar
624 // when the frame changes, otherwise we'll get a lot of flicker.
625 bool heightChanging
wxDUMMY_INITIALIZE(true);
626 bool widthChanging
wxDUMMY_INITIALIZE(true);
628 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
630 // It's OK if the current height is greater than what can be shown.
631 heightChanging
= (desiredH
> th
) ;
632 widthChanging
= (desiredW
!= tw
) ;
634 // The next time around, we may not have to set the size
636 desiredH
= desiredH
+ 200;
640 // It's OK if the current width is greater than what can be shown.
641 widthChanging
= (desiredW
> tw
) ;
642 heightChanging
= (desiredH
!= th
) ;
644 // The next time around, we may not have to set the size
646 desiredW
= desiredW
+ 200;
649 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
650 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
652 #endif // __WXWINCE__
656 #endif // wxUSE_TOOLBAR
658 // ----------------------------------------------------------------------------
659 // frame state (iconized/maximized/...)
660 // ----------------------------------------------------------------------------
662 // propagate our state change to all child frames: this allows us to emulate X
663 // Windows behaviour where child frames float independently of the parent one
664 // on the desktop, but are iconized/restored with it
665 void wxFrame::IconizeChildFrames(bool bIconize
)
667 m_iconized
= bIconize
;
669 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
671 node
= node
->GetNext() )
673 wxWindow
*win
= node
->GetData();
675 // iconizing the frames with this style under Win95 shell puts them at
676 // the bottom of the screen (as the MDI children) instead of making
677 // them appear in the taskbar because they are, by virtue of this
678 // style, not managed by the taskbar - instead leave Windows take care
680 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
683 // the child MDI frames are a special case and should not be touched by
684 // the parent frame - instead, they are managed by the user
685 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
687 #if wxUSE_MDI_ARCHITECTURE
688 && !frame
->IsMDIChild()
689 #endif // wxUSE_MDI_ARCHITECTURE
692 // we don't want to restore the child frames which had been
693 // iconized even before we were iconized, so save the child frame
694 // status when iconizing the parent frame and check it when
698 frame
->m_wasMinimized
= frame
->IsIconized();
701 // note that we shouldn't touch the hidden frames neither because
702 // iconizing/restoring them would show them as a side effect
703 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
704 frame
->Iconize(bIconize
);
709 WXHICON
wxFrame::GetDefaultIcon() const
711 // we don't have any standard icons (any more)
715 // ===========================================================================
716 // message processing
717 // ===========================================================================
719 // ---------------------------------------------------------------------------
721 // ---------------------------------------------------------------------------
723 bool wxFrame::MSWDoTranslateMessage(wxFrame
*frame
, WXMSG
*pMsg
)
725 if ( wxWindow::MSWTranslateMessage(pMsg
) )
728 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
729 // try the menu bar accels
730 wxMenuBar
*menuBar
= GetMenuBar();
733 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
734 return acceleratorTable
.Translate(frame
, pMsg
);
736 #endif // wxUSE_MENUS && wxUSE_ACCEL
741 // ---------------------------------------------------------------------------
742 // our private (non virtual) message handlers
743 // ---------------------------------------------------------------------------
745 bool wxFrame::HandlePaint()
748 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
750 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
753 const wxIcon
& icon
= GetIcon();
754 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
755 : (HICON
)GetDefaultIcon();
757 // Hold a pointer to the dc so long as the OnPaint() message
758 // is being processed
760 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
762 // Erase background before painting or we get white background
763 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
768 ::GetClientRect(GetHwnd(), &rect
);
770 // FIXME: why hardcoded?
771 static const int icon_width
= 32;
772 static const int icon_height
= 32;
774 int icon_x
= (int)((rect
.right
- icon_width
)/2);
775 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
777 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
780 ::EndPaint(GetHwnd(), &ps
);
787 return wxWindow::HandlePaint();
792 // nothing to paint - processed
797 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
799 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
804 // only do it it if we were iconized before, otherwise resizing the
805 // parent frame has a curious side effect of bringing it under it's
810 // restore all child frames too
811 IconizeChildFrames(false);
813 (void)SendIconizeEvent(false);
817 // iconize all child frames too
818 IconizeChildFrames(true);
823 #endif // !__WXWINCE__
829 #endif // wxUSE_STATUSBAR
833 #endif // wxUSE_TOOLBAR
835 #if defined(WINCE_WITH_COMMANDBAR)
836 // Position the menu command bar
837 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
840 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
841 wxSize clientSz
= GetClientSize();
843 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
845 wxLogLastError(wxT("MoveWindow"));
849 #endif // WINCE_WITH_COMMANDBAR
852 // call the base class version to generate the appropriate events
856 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
860 // In case it's e.g. a toolbar.
861 wxWindow
*win
= wxFindWinFromHandle(control
);
863 return win
->MSWCommand(cmd
, id
);
866 // handle here commands from menus and accelerators
867 if ( cmd
== 0 || cmd
== 1 )
869 #if wxUSE_MENUS_NATIVE
870 if ( wxCurrentPopupMenu
)
872 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
873 wxCurrentPopupMenu
= NULL
;
875 return popupMenu
->MSWCommand(cmd
, id
);
877 #endif // wxUSE_MENUS_NATIVE
879 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
880 // handle here commands from Smartphone menu bar
881 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
885 #endif // __SMARTPHONE__ && __WXWINCE__
887 if ( ProcessCommand(id
) )
896 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
899 if ( flags
== 0xFFFF && hMenu
== 0 )
901 // menu was removed from screen
904 #ifndef __WXMICROWIN__
905 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
912 // don't give hints for separators (doesn't make sense) nor for the
913 // items opening popup menus (they don't have them anyhow) but do clear
914 // the status line - otherwise, we would be left with the help message
915 // for the previous item which doesn't apply any more
916 DoGiveHelp(wxEmptyString
, false);
921 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
922 event
.SetEventObject(this);
924 return GetEventHandler()->ProcessEvent(event
);
927 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
929 // we don't have the menu id here, so we use the id to specify if the event
930 // was from a popup menu or a normal one
931 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
932 event
.SetEventObject(this);
934 return GetEventHandler()->ProcessEvent(event
);
937 // ---------------------------------------------------------------------------
938 // the window proc for wxFrame
939 // ---------------------------------------------------------------------------
941 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
944 bool processed
= false;
949 // if we can't close, tell the system that we processed the
950 // message - otherwise it would close us
951 processed
= !Close();
955 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
962 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
965 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
970 processed
= HandlePaint();
973 case WM_INITMENUPOPUP
:
974 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
977 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
982 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
984 processed
= HandleMenuSelect(item
, flags
, hmenu
);
988 case WM_EXITMENULOOP
:
989 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
992 case WM_QUERYDRAGICON
:
994 const wxIcon
& icon
= GetIcon();
995 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
996 : (HICON
)GetDefaultIcon();
1001 #endif // !__WXMICROWIN__
1005 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1010 // handle WM_INITMENUPOPUP message
1011 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1013 wxMenu
* menu
= NULL
;
1016 int nCount
= GetMenuBar()->GetMenuCount();
1017 for (int n
= 0; n
< nCount
; n
++)
1019 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1021 menu
= GetMenuBar()->GetMenu(n
);
1027 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1028 event
.SetEventObject(this);
1030 return GetEventHandler()->ProcessEvent(event
);
1033 // ----------------------------------------------------------------------------
1034 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1035 // from the client area, so the client area is what's really available for the
1037 // ----------------------------------------------------------------------------
1039 // get the origin of the client area in the client coordinates
1040 wxPoint
wxFrame::GetClientAreaOrigin() const
1042 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1044 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1045 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1046 wxToolBar
*toolbar
= GetToolBar();
1047 if ( toolbar
&& toolbar
->IsShown() )
1050 toolbar
->GetSize(&w
, &h
);
1052 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1061 #endif // wxUSE_TOOLBAR
1063 #if defined(WINCE_WITH_COMMANDBAR)
1064 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1067 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1068 pt
.y
+= (rect
.bottom
- rect
.top
);