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"
32 #include "wx/dialog.h"
33 #include "wx/settings.h"
34 #include "wx/dcclient.h"
39 #include "wx/msw/private.h"
45 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
48 #include "wx/msw/winundef.h"
52 #include "wx/statusbr.h"
53 #include "wx/generic/statusbr.h"
54 #endif // wxUSE_STATUSBAR
57 #include "wx/toolbar.h"
58 #endif // wxUSE_TOOLBAR
60 #include "wx/menuitem.h"
63 #ifdef __WXUNIVERSAL__
64 #include "wx/univ/theme.h"
65 #include "wx/univ/colschem.h"
66 #endif // __WXUNIVERSAL__
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 #if wxUSE_MENUS_NATIVE
73 extern wxMenu
*wxCurrentPopupMenu
;
74 #endif // wxUSE_MENUS_NATIVE
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
81 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
84 #if wxUSE_EXTENDED_RTTI
85 WX_DEFINE_FLAGS( wxFrameStyle
)
87 wxBEGIN_FLAGS( wxFrameStyle
)
88 // new style border flags, we put them first to
89 // use them for streaming out
90 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
91 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
92 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
93 wxFLAGS_MEMBER(wxBORDER_RAISED
)
94 wxFLAGS_MEMBER(wxBORDER_STATIC
)
95 wxFLAGS_MEMBER(wxBORDER_NONE
)
97 // old style border flags
98 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
99 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
100 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
101 wxFLAGS_MEMBER(wxRAISED_BORDER
)
102 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
103 wxFLAGS_MEMBER(wxBORDER
)
105 // standard window styles
106 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
107 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
108 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
109 wxFLAGS_MEMBER(wxWANTS_CHARS
)
110 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
111 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
112 wxFLAGS_MEMBER(wxVSCROLL
)
113 wxFLAGS_MEMBER(wxHSCROLL
)
116 wxFLAGS_MEMBER(wxSTAY_ON_TOP
)
117 wxFLAGS_MEMBER(wxCAPTION
)
118 wxFLAGS_MEMBER(wxTHICK_FRAME
)
119 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
120 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
121 wxFLAGS_MEMBER(wxRESIZE_BOX
)
122 wxFLAGS_MEMBER(wxCLOSE_BOX
)
123 wxFLAGS_MEMBER(wxMAXIMIZE_BOX
)
124 wxFLAGS_MEMBER(wxMINIMIZE_BOX
)
126 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW
)
127 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT
)
129 wxFLAGS_MEMBER(wxFRAME_SHAPED
)
131 wxEND_FLAGS( wxFrameStyle
)
133 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame
, wxTopLevelWindow
,"wx/frame.h")
135 wxBEGIN_PROPERTIES_TABLE(wxFrame
)
136 wxEVENT_PROPERTY( Menu
, wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
)
138 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
139 wxPROPERTY_FLAGS( WindowStyle
, wxFrameStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
140 wxPROPERTY( MenuBar
, wxMenuBar
* , SetMenuBar
, GetMenuBar
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
141 wxEND_PROPERTIES_TABLE()
143 wxBEGIN_HANDLERS_TABLE(wxFrame
)
144 wxEND_HANDLERS_TABLE()
146 wxCONSTRUCTOR_6( wxFrame
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Title
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
149 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
152 // ============================================================================
154 // ============================================================================
156 // ----------------------------------------------------------------------------
157 // static class members
158 // ----------------------------------------------------------------------------
161 #if wxUSE_NATIVE_STATUSBAR
162 bool wxFrame::m_useNativeStatusBar
= true;
164 bool wxFrame::m_useNativeStatusBar
= false;
166 #endif // wxUSE_NATIVE_STATUSBAR
168 // ----------------------------------------------------------------------------
169 // creation/destruction
170 // ----------------------------------------------------------------------------
176 #endif // wxUSE_MENUS
182 m_wasMinimized
= false;
185 bool wxFrame::Create(wxWindow
*parent
,
187 const wxString
& title
,
191 const wxString
& name
)
193 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
196 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
198 #if defined(__SMARTPHONE__)
199 SetLeftMenu(wxID_EXIT
, _("Done"));
202 #if wxUSE_ACCEL && defined(__POCKETPC__)
203 // The guidelines state that Ctrl+Q should quit the app.
204 // Let's define an accelerator table to send wxID_EXIT.
205 wxAcceleratorEntry entries
[1];
206 entries
[0].Set(wxACCEL_CTRL
, 'Q', wxID_EXIT
);
207 wxAcceleratorTable
accel(1, entries
);
208 SetAcceleratorTable(accel
);
209 #endif // wxUSE_ACCEL && __POCKETPC__
216 m_isBeingDeleted
= true;
220 // ----------------------------------------------------------------------------
221 // wxFrame client size calculations
222 // ----------------------------------------------------------------------------
224 void wxFrame::DoSetClientSize(int width
, int height
)
226 // leave enough space for the status bar if we have (and show) it
228 wxStatusBar
*statbar
= GetStatusBar();
229 if ( statbar
&& statbar
->IsShown() )
231 height
+= statbar
->GetSize().y
;
233 #endif // wxUSE_STATUSBAR
235 // call GetClientAreaOrigin() to take the toolbar into account
236 wxPoint pt
= GetClientAreaOrigin();
240 wxTopLevelWindow::DoSetClientSize(width
, height
);
243 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
244 void wxFrame::DoGetClientSize(int *x
, int *y
) const
246 wxTopLevelWindow::DoGetClientSize(x
, y
);
248 // account for the possible toolbar
249 wxPoint pt
= GetClientAreaOrigin();
257 // adjust client area height to take the status bar into account
260 wxStatusBar
*statbar
= GetStatusBar();
261 if ( statbar
&& statbar
->IsShown() )
263 *y
-= statbar
->GetClientSize().y
;
266 #endif // wxUSE_STATUSBAR
269 // ----------------------------------------------------------------------------
270 // wxFrame: various geometry-related functions
271 // ----------------------------------------------------------------------------
273 void wxFrame::Raise()
275 ::SetForegroundWindow(GetHwnd());
278 // generate an artificial resize event
279 void wxFrame::SendSizeEvent()
283 RECT r
= wxGetWindowRect(GetHwnd());
285 (void)::PostMessage(GetHwnd(), WM_SIZE
,
286 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
287 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
292 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
295 const wxString
& name
)
297 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
299 #if wxUSE_NATIVE_STATUSBAR
300 if ( !UsesNativeStatusBar() )
302 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
307 statusBar
= new wxStatusBar(this, id
, style
, name
);
310 statusBar
->SetFieldsCount(number
);
315 void wxFrame::PositionStatusBar()
317 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
321 GetClientSize(&w
, &h
);
323 m_frameStatusBar
->GetSize(&sw
, &sh
);
325 // Since we wish the status bar to be directly under the client area,
326 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
327 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
329 #endif // wxUSE_STATUSBAR
331 #if wxUSE_MENUS_NATIVE
333 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
335 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
337 wxMenu
*autoMenu
= NULL
;
339 if( menubar
->GetMenuCount() == 1 )
341 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
342 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
346 autoMenu
= new wxMenu
;
348 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
350 wxMenu
*item
= menubar
->GetMenu(n
);
351 wxString label
= menubar
->GetLabelTop(n
);
352 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
353 autoMenu
->Append(wxID_ANY
, label
, new_item
);
356 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
359 #elif defined(WINCE_WITHOUT_COMMANDBAR)
362 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
363 wxDefaultPosition
, wxDefaultSize
,
364 wxBORDER_NONE
| wxTB_HORIZONTAL
,
365 wxToolBarNameStr
, menubar
);
367 menubar
->SetToolBar(toolBar
);
369 // Now adjust size for menu bar
372 //When the main window is created using CW_USEDEFAULT the height of the
373 // is created is not taken into account). So we resize the window after
374 // if a menubar is present
377 ::GetWindowRect((HWND
) GetHWND(), &rc
);
378 // adjust for menu / titlebar height
379 rc
.bottom
-= (2*menuHeight
-1);
381 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
385 wxFrameBase::AttachMenuBar(menubar
);
389 // actually remove the menu from the frame
390 m_hMenu
= (WXHMENU
)0;
391 InternalSetMenuBar();
393 else // set new non NULL menu bar
395 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
396 // Can set a menubar several times.
397 if ( menubar
->GetHMenu() )
399 m_hMenu
= menubar
->GetHMenu();
403 m_hMenu
= menubar
->Create();
407 wxFAIL_MSG( _T("failed to create menu bar") );
412 InternalSetMenuBar();
416 void wxFrame::InternalSetMenuBar()
418 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
421 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
423 wxLogLastError(wxT("SetMenu"));
428 #endif // wxUSE_MENUS_NATIVE
430 // Responds to colour changes, and passes event on to children.
431 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
433 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
437 if ( m_frameStatusBar
)
439 wxSysColourChangedEvent event2
;
440 event2
.SetEventObject( m_frameStatusBar
);
441 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
443 #endif // wxUSE_STATUSBAR
445 // Propagate the event to the non-top-level children
446 wxWindow::OnSysColourChanged(event
);
449 // Pass true to show full screen, false to restore.
450 bool wxFrame::ShowFullScreen(bool show
, long style
)
452 // TODO-CE: add support for CE
453 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
454 if ( IsFullScreen() == show
)
459 // zap the toolbar, menubar, and statusbar if needed
461 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
463 wxToolBar
*theToolBar
= GetToolBar();
465 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
467 if ( theToolBar
->IsShown() )
469 theToolBar
->SetSize(wxDefaultCoord
,0);
470 theToolBar
->Show(false);
472 else // prevent it from being restored later
474 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
477 #endif // wxUSE_TOOLBAR
479 if (style
& wxFULLSCREEN_NOMENUBAR
)
480 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
483 wxStatusBar
*theStatusBar
= GetStatusBar();
485 // Save the number of fields in the statusbar
486 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
488 if ( theStatusBar
->IsShown() )
489 theStatusBar
->Show(false);
491 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
493 #endif // wxUSE_STATUSBAR
495 else // restore to normal
497 // restore the toolbar, menubar, and statusbar if we had hid them
499 wxToolBar
*theToolBar
= GetToolBar();
501 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
503 theToolBar
->Show(true);
505 #endif // wxUSE_TOOLBAR
507 if (m_fsStyle
& wxFULLSCREEN_NOMENUBAR
)
509 WXHMENU menu
= m_hMenu
;
511 #if wxUSE_MDI_ARCHITECTURE
512 wxMDIParentFrame
*frame
= wxDynamicCast(this, wxMDIParentFrame
);
515 wxMDIChildFrame
*child
= frame
->GetActiveChild();
518 menu
= child
->GetWinMenu();
521 #endif // wxUSE_MDI_ARCHITECTURE
525 ::SetMenu(GetHwnd(), (HMENU
)menu
);
530 wxStatusBar
*theStatusBar
= GetStatusBar();
532 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
534 theStatusBar
->Show(true);
537 #endif // wxUSE_STATUSBAR
539 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
541 return wxFrameBase::ShowFullScreen(show
, style
);
544 // ----------------------------------------------------------------------------
545 // tool/status bar stuff
546 // ----------------------------------------------------------------------------
550 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
552 #if defined(WINCE_WITHOUT_COMMANDBAR)
553 // We may already have a toolbar from calling SetMenuBar.
557 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
562 return m_frameToolBar
;
565 void wxFrame::PositionToolBar()
567 wxToolBar
*toolbar
= GetToolBar();
568 if ( toolbar
&& toolbar
->IsShown() )
570 #if defined(WINCE_WITHOUT_COMMANDBAR)
571 // We want to do something different in WinCE, because
572 // the toolbar should be associated with the commandbar,
573 // and not an independent window.
576 // don't call our (or even wxTopLevelWindow) version because we want
577 // the real (full) client area size, not excluding the tool/status bar
579 wxWindow::DoGetClientSize(&width
, &height
);
582 wxStatusBar
*statbar
= GetStatusBar();
583 if ( statbar
&& statbar
->IsShown() )
585 height
-= statbar
->GetClientSize().y
;
587 #endif // wxUSE_STATUSBAR
591 #if defined(WINCE_WITH_COMMANDBAR)
592 // We're using a commandbar - so we have to allow for it.
593 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
596 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
597 y
= rect
.bottom
- rect
.top
;
603 toolbar
->GetPosition(&tx
, &ty
);
604 toolbar
->GetSize(&tw
, &th
);
607 if (ty
< 0 && (-ty
== th
))
609 if (tx
< 0 && (-tx
== tw
))
615 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
622 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
626 // use the 'real' MSW position here, don't offset relativly to the
627 // client area origin
629 // Optimise such that we don't have to always resize the toolbar
630 // when the frame changes, otherwise we'll get a lot of flicker.
631 bool heightChanging
wxDUMMY_INITIALIZE(true);
632 bool widthChanging
wxDUMMY_INITIALIZE(true);
634 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
636 // It's OK if the current height is greater than what can be shown.
637 heightChanging
= (desiredH
> th
) ;
638 widthChanging
= (desiredW
!= tw
) ;
640 // The next time around, we may not have to set the size
642 desiredH
= desiredH
+ 200;
646 // It's OK if the current width is greater than what can be shown.
647 widthChanging
= (desiredW
> tw
) ;
648 heightChanging
= (desiredH
!= th
) ;
650 // The next time around, we may not have to set the size
652 desiredW
= desiredW
+ 200;
655 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
656 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
658 #endif // __WXWINCE__
662 #endif // wxUSE_TOOLBAR
664 // ----------------------------------------------------------------------------
665 // frame state (iconized/maximized/...)
666 // ----------------------------------------------------------------------------
668 // propagate our state change to all child frames: this allows us to emulate X
669 // Windows behaviour where child frames float independently of the parent one
670 // on the desktop, but are iconized/restored with it
671 void wxFrame::IconizeChildFrames(bool bIconize
)
673 m_iconized
= bIconize
;
675 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
677 node
= node
->GetNext() )
679 wxWindow
*win
= node
->GetData();
681 // iconizing the frames with this style under Win95 shell puts them at
682 // the bottom of the screen (as the MDI children) instead of making
683 // them appear in the taskbar because they are, by virtue of this
684 // style, not managed by the taskbar - instead leave Windows take care
686 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
689 // the child MDI frames are a special case and should not be touched by
690 // the parent frame - instead, they are managed by the user
691 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
693 #if wxUSE_MDI_ARCHITECTURE
694 && !frame
->IsMDIChild()
695 #endif // wxUSE_MDI_ARCHITECTURE
698 // we don't want to restore the child frames which had been
699 // iconized even before we were iconized, so save the child frame
700 // status when iconizing the parent frame and check it when
704 frame
->m_wasMinimized
= frame
->IsIconized();
707 // note that we shouldn't touch the hidden frames neither because
708 // iconizing/restoring them would show them as a side effect
709 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
710 frame
->Iconize(bIconize
);
715 WXHICON
wxFrame::GetDefaultIcon() const
717 // we don't have any standard icons (any more)
721 // ===========================================================================
722 // message processing
723 // ===========================================================================
725 // ---------------------------------------------------------------------------
727 // ---------------------------------------------------------------------------
729 bool wxFrame::MSWTranslateMessage(WXMSG
* pMsg
)
731 if ( wxWindow::MSWTranslateMessage(pMsg
) )
734 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
735 // try the menu bar accels
736 wxMenuBar
*menuBar
= GetMenuBar();
740 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
741 return acceleratorTable
.Translate(this, pMsg
);
744 #endif // wxUSE_MENUS && wxUSE_ACCEL
747 // ---------------------------------------------------------------------------
748 // our private (non virtual) message handlers
749 // ---------------------------------------------------------------------------
751 bool wxFrame::HandlePaint()
754 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
756 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
759 const wxIcon
& icon
= GetIcon();
760 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
761 : (HICON
)GetDefaultIcon();
763 // Hold a pointer to the dc so long as the OnPaint() message
764 // is being processed
766 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
768 // Erase background before painting or we get white background
769 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
774 ::GetClientRect(GetHwnd(), &rect
);
776 // FIXME: why hardcoded?
777 static const int icon_width
= 32;
778 static const int icon_height
= 32;
780 int icon_x
= (int)((rect
.right
- icon_width
)/2);
781 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
783 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
786 ::EndPaint(GetHwnd(), &ps
);
793 return wxWindow::HandlePaint();
798 // nothing to paint - processed
803 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
805 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
810 // only do it it if we were iconized before, otherwise resizing the
811 // parent frame has a curious side effect of bringing it under it's
816 // restore all child frames too
817 IconizeChildFrames(false);
819 (void)SendIconizeEvent(false);
823 // iconize all child frames too
824 IconizeChildFrames(true);
829 #endif // !__WXWINCE__
835 #endif // wxUSE_STATUSBAR
839 #endif // wxUSE_TOOLBAR
841 #if defined(WINCE_WITH_COMMANDBAR)
842 // Position the menu command bar
843 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
846 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
847 wxSize clientSz
= GetClientSize();
849 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
851 wxLogLastError(wxT("MoveWindow"));
855 #endif // WINCE_WITH_COMMANDBAR
858 // call the base class version to generate the appropriate events
862 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
866 // In case it's e.g. a toolbar.
867 wxWindow
*win
= wxFindWinFromHandle(control
);
869 return win
->MSWCommand(cmd
, id
);
872 // handle here commands from menus and accelerators
873 if ( cmd
== 0 || cmd
== 1 )
875 #if wxUSE_MENUS_NATIVE
876 if ( wxCurrentPopupMenu
)
878 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
879 wxCurrentPopupMenu
= NULL
;
881 return popupMenu
->MSWCommand(cmd
, id
);
883 #endif // wxUSE_MENUS_NATIVE
885 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
886 // handle here commands from Smartphone menu bar
887 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
891 #endif // __SMARTPHONE__ && __WXWINCE__
893 if ( ProcessCommand(id
) )
902 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
905 if ( flags
== 0xFFFF && hMenu
== 0 )
907 // menu was removed from screen
910 #ifndef __WXMICROWIN__
911 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
918 // don't give hints for separators (doesn't make sense) nor for the
919 // items opening popup menus (they don't have them anyhow) but do clear
920 // the status line - otherwise, we would be left with the help message
921 // for the previous item which doesn't apply any more
922 DoGiveHelp(wxEmptyString
, false);
927 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
928 event
.SetEventObject(this);
930 return GetEventHandler()->ProcessEvent(event
);
933 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
935 // we don't have the menu id here, so we use the id to specify if the event
936 // was from a popup menu or a normal one
937 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
938 event
.SetEventObject(this);
940 return GetEventHandler()->ProcessEvent(event
);
943 // ---------------------------------------------------------------------------
944 // the window proc for wxFrame
945 // ---------------------------------------------------------------------------
947 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
950 bool processed
= false;
955 // if we can't close, tell the system that we processed the
956 // message - otherwise it would close us
957 processed
= !Close();
961 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
968 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
971 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
976 processed
= HandlePaint();
979 case WM_INITMENUPOPUP
:
980 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
983 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
988 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
990 processed
= HandleMenuSelect(item
, flags
, hmenu
);
994 case WM_EXITMENULOOP
:
995 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
998 case WM_QUERYDRAGICON
:
1000 const wxIcon
& icon
= GetIcon();
1001 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1002 : (HICON
)GetDefaultIcon();
1004 processed
= rc
!= 0;
1007 #endif // !__WXMICROWIN__
1011 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1016 // handle WM_INITMENUPOPUP message
1017 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1019 wxMenu
* menu
= NULL
;
1022 int nCount
= GetMenuBar()->GetMenuCount();
1023 for (int n
= 0; n
< nCount
; n
++)
1025 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1027 menu
= GetMenuBar()->GetMenu(n
);
1033 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1034 event
.SetEventObject(this);
1036 return GetEventHandler()->ProcessEvent(event
);
1039 // ----------------------------------------------------------------------------
1040 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1041 // from the client area, so the client area is what's really available for the
1043 // ----------------------------------------------------------------------------
1045 // get the origin of the client area in the client coordinates
1046 wxPoint
wxFrame::GetClientAreaOrigin() const
1048 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1050 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1051 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1052 wxToolBar
*toolbar
= GetToolBar();
1053 if ( toolbar
&& toolbar
->IsShown() )
1056 toolbar
->GetSize(&w
, &h
);
1058 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1067 #endif // wxUSE_TOOLBAR
1069 #if defined(WINCE_WITH_COMMANDBAR)
1070 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1073 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1074 pt
.y
+= (rect
.bottom
- rect
.top
);