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
687 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
691 // the child MDI frames are a special case and should not be touched by
692 // the parent frame - instead, they are managed by the user
693 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
695 #if wxUSE_MDI_ARCHITECTURE
696 && !frame
->IsMDIChild()
697 #endif // wxUSE_MDI_ARCHITECTURE
700 // we don't want to restore the child frames which had been
701 // iconized even before we were iconized, so save the child frame
702 // status when iconizing the parent frame and check it when
706 frame
->m_wasMinimized
= frame
->IsIconized();
709 // note that we shouldn't touch the hidden frames neither because
710 // iconizing/restoring them would show them as a side effect
711 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
712 frame
->Iconize(bIconize
);
717 WXHICON
wxFrame::GetDefaultIcon() const
719 // we don't have any standard icons (any more)
723 // ===========================================================================
724 // message processing
725 // ===========================================================================
727 // ---------------------------------------------------------------------------
729 // ---------------------------------------------------------------------------
731 bool wxFrame::MSWTranslateMessage(WXMSG
* pMsg
)
733 if ( wxWindow::MSWTranslateMessage(pMsg
) )
736 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
737 // try the menu bar accels
738 wxMenuBar
*menuBar
= GetMenuBar();
742 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
743 return acceleratorTable
.Translate(this, pMsg
);
746 #endif // wxUSE_MENUS && wxUSE_ACCEL
749 // ---------------------------------------------------------------------------
750 // our private (non virtual) message handlers
751 // ---------------------------------------------------------------------------
753 bool wxFrame::HandlePaint()
756 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
758 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
761 const wxIcon
& icon
= GetIcon();
762 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
763 : (HICON
)GetDefaultIcon();
765 // Hold a pointer to the dc so long as the OnPaint() message
766 // is being processed
768 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
770 // Erase background before painting or we get white background
771 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
776 ::GetClientRect(GetHwnd(), &rect
);
778 // FIXME: why hardcoded?
779 static const int icon_width
= 32;
780 static const int icon_height
= 32;
782 int icon_x
= (int)((rect
.right
- icon_width
)/2);
783 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
785 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
788 ::EndPaint(GetHwnd(), &ps
);
795 return wxWindow::HandlePaint();
800 // nothing to paint - processed
805 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
807 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
812 // only do it it if we were iconized before, otherwise resizing the
813 // parent frame has a curious side effect of bringing it under it's
818 // restore all child frames too
819 IconizeChildFrames(false);
821 (void)SendIconizeEvent(false);
825 // iconize all child frames too
826 IconizeChildFrames(true);
831 #endif // !__WXWINCE__
837 #endif // wxUSE_STATUSBAR
841 #endif // wxUSE_TOOLBAR
843 #if defined(WINCE_WITH_COMMANDBAR)
844 // Position the menu command bar
845 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
848 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
849 wxSize clientSz
= GetClientSize();
851 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
853 wxLogLastError(wxT("MoveWindow"));
857 #endif // WINCE_WITH_COMMANDBAR
860 // call the base class version to generate the appropriate events
864 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
868 // In case it's e.g. a toolbar.
869 wxWindow
*win
= wxFindWinFromHandle(control
);
871 return win
->MSWCommand(cmd
, id
);
874 // handle here commands from menus and accelerators
875 if ( cmd
== 0 || cmd
== 1 )
877 #if wxUSE_MENUS_NATIVE
878 if ( wxCurrentPopupMenu
)
880 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
881 wxCurrentPopupMenu
= NULL
;
883 return popupMenu
->MSWCommand(cmd
, id
);
885 #endif // wxUSE_MENUS_NATIVE
887 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
888 // handle here commands from Smartphone menu bar
889 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
893 #endif // __SMARTPHONE__ && __WXWINCE__
895 if ( ProcessCommand(id
) )
904 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
907 if ( flags
== 0xFFFF && hMenu
== 0 )
909 // menu was removed from screen
912 #ifndef __WXMICROWIN__
913 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
920 // don't give hints for separators (doesn't make sense) nor for the
921 // items opening popup menus (they don't have them anyhow) but do clear
922 // the status line - otherwise, we would be left with the help message
923 // for the previous item which doesn't apply any more
924 DoGiveHelp(wxEmptyString
, false);
929 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
930 event
.SetEventObject(this);
932 return GetEventHandler()->ProcessEvent(event
);
935 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
937 // we don't have the menu id here, so we use the id to specify if the event
938 // was from a popup menu or a normal one
939 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
940 event
.SetEventObject(this);
942 return GetEventHandler()->ProcessEvent(event
);
945 // ---------------------------------------------------------------------------
946 // the window proc for wxFrame
947 // ---------------------------------------------------------------------------
949 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
952 bool processed
= false;
957 // if we can't close, tell the system that we processed the
958 // message - otherwise it would close us
959 processed
= !Close();
963 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
970 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
973 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
978 processed
= HandlePaint();
981 case WM_INITMENUPOPUP
:
982 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
985 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
990 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
992 processed
= HandleMenuSelect(item
, flags
, hmenu
);
996 case WM_EXITMENULOOP
:
997 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
1000 case WM_QUERYDRAGICON
:
1002 const wxIcon
& icon
= GetIcon();
1003 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1004 : (HICON
)GetDefaultIcon();
1006 processed
= rc
!= 0;
1009 #endif // !__WXMICROWIN__
1013 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1018 // handle WM_INITMENUPOPUP message
1019 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1021 wxMenu
* menu
= NULL
;
1024 int nCount
= GetMenuBar()->GetMenuCount();
1025 for (int n
= 0; n
< nCount
; n
++)
1027 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1029 menu
= GetMenuBar()->GetMenu(n
);
1035 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1036 event
.SetEventObject(this);
1038 return GetEventHandler()->ProcessEvent(event
);
1041 // ----------------------------------------------------------------------------
1042 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1043 // from the client area, so the client area is what's really available for the
1045 // ----------------------------------------------------------------------------
1047 // get the origin of the client area in the client coordinates
1048 wxPoint
wxFrame::GetClientAreaOrigin() const
1050 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1052 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1053 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1054 wxToolBar
*toolbar
= GetToolBar();
1055 if ( toolbar
&& toolbar
->IsShown() )
1058 toolbar
->GetSize(&w
, &h
);
1060 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1069 #endif // wxUSE_TOOLBAR
1071 #if defined(WINCE_WITH_COMMANDBAR)
1072 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1075 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1076 pt
.y
+= (rect
.bottom
- rect
.top
);