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"
33 #include "wx/dialog.h"
34 #include "wx/settings.h"
35 #include "wx/dcclient.h"
41 #include "wx/msw/private.h"
43 // include <commctrl.h> "properly"
44 #include "wx/msw/wrapcctl.h"
46 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
49 #include "wx/msw/winundef.h"
53 #include "wx/statusbr.h"
54 #include "wx/generic/statusbr.h"
55 #endif // wxUSE_STATUSBAR
58 #include "wx/toolbar.h"
59 #endif // wxUSE_TOOLBAR
61 #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 #if WXWIN_COMPATIBILITY_2_6
119 wxFLAGS_MEMBER(wxTHICK_FRAME
)
120 #endif // WXWIN_COMPATIBILITY_2_6
121 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
122 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
123 #if WXWIN_COMPATIBILITY_2_6
124 wxFLAGS_MEMBER(wxRESIZE_BOX
)
125 #endif // WXWIN_COMPATIBILITY_2_6
126 wxFLAGS_MEMBER(wxCLOSE_BOX
)
127 wxFLAGS_MEMBER(wxMAXIMIZE_BOX
)
128 wxFLAGS_MEMBER(wxMINIMIZE_BOX
)
130 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW
)
131 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT
)
133 wxFLAGS_MEMBER(wxFRAME_SHAPED
)
135 wxEND_FLAGS( wxFrameStyle
)
137 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame
, wxTopLevelWindow
,"wx/frame.h")
139 wxBEGIN_PROPERTIES_TABLE(wxFrame
)
140 wxEVENT_PROPERTY( Menu
, wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
)
142 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
143 wxPROPERTY_FLAGS( WindowStyle
, wxFrameStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
144 wxPROPERTY( MenuBar
, wxMenuBar
* , SetMenuBar
, GetMenuBar
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
145 wxEND_PROPERTIES_TABLE()
147 wxBEGIN_HANDLERS_TABLE(wxFrame
)
148 wxEND_HANDLERS_TABLE()
150 wxCONSTRUCTOR_6( wxFrame
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Title
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
153 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
156 // ============================================================================
158 // ============================================================================
160 // ----------------------------------------------------------------------------
161 // static class members
162 // ----------------------------------------------------------------------------
165 #if wxUSE_NATIVE_STATUSBAR
166 bool wxFrame::m_useNativeStatusBar
= true;
168 bool wxFrame::m_useNativeStatusBar
= false;
170 #endif // wxUSE_NATIVE_STATUSBAR
172 // ----------------------------------------------------------------------------
173 // creation/destruction
174 // ----------------------------------------------------------------------------
180 #endif // wxUSE_MENUS
186 m_wasMinimized
= false;
189 bool wxFrame::Create(wxWindow
*parent
,
191 const wxString
& title
,
195 const wxString
& name
)
197 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
200 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
202 #if defined(__SMARTPHONE__)
203 SetLeftMenu(wxID_EXIT
, _("Done"));
206 #if wxUSE_ACCEL && defined(__POCKETPC__)
207 // The guidelines state that Ctrl+Q should quit the app.
208 // Let's define an accelerator table to send wxID_EXIT.
209 wxAcceleratorEntry entries
[1];
210 entries
[0].Set(wxACCEL_CTRL
, 'Q', wxID_EXIT
);
211 wxAcceleratorTable
accel(1, entries
);
212 SetAcceleratorTable(accel
);
213 #endif // wxUSE_ACCEL && __POCKETPC__
220 m_isBeingDeleted
= true;
224 // ----------------------------------------------------------------------------
225 // wxFrame client size calculations
226 // ----------------------------------------------------------------------------
228 void wxFrame::DoSetClientSize(int width
, int height
)
230 // leave enough space for the status bar if we have (and show) it
232 wxStatusBar
*statbar
= GetStatusBar();
233 if ( statbar
&& statbar
->IsShown() )
235 height
+= statbar
->GetSize().y
;
237 #endif // wxUSE_STATUSBAR
239 // call GetClientAreaOrigin() to take the toolbar into account
240 wxPoint pt
= GetClientAreaOrigin();
244 wxTopLevelWindow::DoSetClientSize(width
, height
);
247 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
248 void wxFrame::DoGetClientSize(int *x
, int *y
) const
250 wxTopLevelWindow::DoGetClientSize(x
, y
);
252 // account for the possible toolbar
253 wxPoint pt
= GetClientAreaOrigin();
261 // adjust client area height to take the status bar into account
264 wxStatusBar
*statbar
= GetStatusBar();
265 if ( statbar
&& statbar
->IsShown() )
267 *y
-= statbar
->GetClientSize().y
;
270 #endif // wxUSE_STATUSBAR
273 // ----------------------------------------------------------------------------
274 // wxFrame: various geometry-related functions
275 // ----------------------------------------------------------------------------
277 void wxFrame::Raise()
279 ::SetForegroundWindow(GetHwnd());
282 // generate an artificial resize event
283 void wxFrame::SendSizeEvent()
287 RECT r
= wxGetWindowRect(GetHwnd());
289 (void)::PostMessage(GetHwnd(), WM_SIZE
,
290 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
291 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
296 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
299 const wxString
& name
)
301 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
303 #if wxUSE_NATIVE_STATUSBAR
304 if ( !UsesNativeStatusBar() )
306 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
311 statusBar
= new wxStatusBar(this, id
, style
, name
);
314 statusBar
->SetFieldsCount(number
);
319 void wxFrame::PositionStatusBar()
321 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
325 GetClientSize(&w
, &h
);
327 m_frameStatusBar
->GetSize(&sw
, &sh
);
329 // Since we wish the status bar to be directly under the client area,
330 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
331 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
333 #endif // wxUSE_STATUSBAR
335 #if wxUSE_MENUS_NATIVE
337 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
339 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
341 wxMenu
*autoMenu
= NULL
;
343 if( menubar
->GetMenuCount() == 1 )
345 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
346 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
350 autoMenu
= new wxMenu
;
352 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
354 wxMenu
*item
= menubar
->GetMenu(n
);
355 wxString label
= menubar
->GetLabelTop(n
);
356 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
357 autoMenu
->Append(wxID_ANY
, label
, new_item
);
360 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
363 #elif defined(WINCE_WITHOUT_COMMANDBAR)
366 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
367 wxDefaultPosition
, wxDefaultSize
,
368 wxBORDER_NONE
| wxTB_HORIZONTAL
,
369 wxToolBarNameStr
, menubar
);
371 menubar
->SetToolBar(toolBar
);
373 // Now adjust size for menu bar
376 //When the main window is created using CW_USEDEFAULT the height of the
377 // is created is not taken into account). So we resize the window after
378 // if a menubar is present
381 ::GetWindowRect((HWND
) GetHWND(), &rc
);
382 // adjust for menu / titlebar height
383 rc
.bottom
-= (2*menuHeight
-1);
385 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
389 wxFrameBase::AttachMenuBar(menubar
);
393 // actually remove the menu from the frame
394 m_hMenu
= (WXHMENU
)0;
395 InternalSetMenuBar();
397 else // set new non NULL menu bar
399 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
400 // Can set a menubar several times.
401 if ( menubar
->GetHMenu() )
403 m_hMenu
= menubar
->GetHMenu();
407 m_hMenu
= menubar
->Create();
411 wxFAIL_MSG( _T("failed to create menu bar") );
416 InternalSetMenuBar();
420 void wxFrame::InternalSetMenuBar()
422 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
425 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
427 wxLogLastError(wxT("SetMenu"));
432 #endif // wxUSE_MENUS_NATIVE
434 // Responds to colour changes, and passes event on to children.
435 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
437 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
441 if ( m_frameStatusBar
)
443 wxSysColourChangedEvent event2
;
444 event2
.SetEventObject( m_frameStatusBar
);
445 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
447 #endif // wxUSE_STATUSBAR
449 // Propagate the event to the non-top-level children
450 wxWindow::OnSysColourChanged(event
);
453 // Pass true to show full screen, false to restore.
454 bool wxFrame::ShowFullScreen(bool show
, long style
)
456 // TODO-CE: add support for CE
457 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
458 if ( IsFullScreen() == show
)
463 // zap the toolbar, menubar, and statusbar if needed
465 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
467 wxToolBar
*theToolBar
= GetToolBar();
469 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
471 if ( theToolBar
->IsShown() )
473 theToolBar
->SetSize(wxDefaultCoord
,0);
474 theToolBar
->Show(false);
476 else // prevent it from being restored later
478 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
481 #endif // wxUSE_TOOLBAR
483 if (style
& wxFULLSCREEN_NOMENUBAR
)
484 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
487 wxStatusBar
*theStatusBar
= GetStatusBar();
489 // Save the number of fields in the statusbar
490 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
492 if ( theStatusBar
->IsShown() )
493 theStatusBar
->Show(false);
495 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
497 #endif // wxUSE_STATUSBAR
499 else // restore to normal
501 // restore the toolbar, menubar, and statusbar if we had hid them
503 wxToolBar
*theToolBar
= GetToolBar();
505 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
507 theToolBar
->Show(true);
509 #endif // wxUSE_TOOLBAR
511 if (m_fsStyle
& wxFULLSCREEN_NOMENUBAR
)
513 WXHMENU menu
= m_hMenu
;
515 #if wxUSE_MDI_ARCHITECTURE
516 wxMDIParentFrame
*frame
= wxDynamicCast(this, wxMDIParentFrame
);
519 wxMDIChildFrame
*child
= frame
->GetActiveChild();
522 menu
= child
->GetWinMenu();
525 #endif // wxUSE_MDI_ARCHITECTURE
529 ::SetMenu(GetHwnd(), (HMENU
)menu
);
534 wxStatusBar
*theStatusBar
= GetStatusBar();
536 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
538 theStatusBar
->Show(true);
541 #endif // wxUSE_STATUSBAR
543 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
545 return wxFrameBase::ShowFullScreen(show
, style
);
548 // ----------------------------------------------------------------------------
549 // tool/status bar stuff
550 // ----------------------------------------------------------------------------
554 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
556 #if defined(WINCE_WITHOUT_COMMANDBAR)
557 // We may already have a toolbar from calling SetMenuBar.
561 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
566 return m_frameToolBar
;
569 void wxFrame::PositionToolBar()
571 wxToolBar
*toolbar
= GetToolBar();
572 if ( toolbar
&& toolbar
->IsShown() )
574 #if defined(WINCE_WITHOUT_COMMANDBAR)
575 // We want to do something different in WinCE, because
576 // the toolbar should be associated with the commandbar,
577 // and not an independent window.
580 // don't call our (or even wxTopLevelWindow) version because we want
581 // the real (full) client area size, not excluding the tool/status bar
583 wxWindow::DoGetClientSize(&width
, &height
);
586 wxStatusBar
*statbar
= GetStatusBar();
587 if ( statbar
&& statbar
->IsShown() )
589 height
-= statbar
->GetClientSize().y
;
591 #endif // wxUSE_STATUSBAR
595 #if defined(WINCE_WITH_COMMANDBAR)
596 // We're using a commandbar - so we have to allow for it.
597 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
600 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
601 y
= rect
.bottom
- rect
.top
;
607 toolbar
->GetPosition(&tx
, &ty
);
608 toolbar
->GetSize(&tw
, &th
);
611 if (ty
< 0 && (-ty
== th
))
613 if (tx
< 0 && (-tx
== tw
))
619 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
626 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
630 // use the 'real' MSW position here, don't offset relativly to the
631 // client area origin
633 // Optimise such that we don't have to always resize the toolbar
634 // when the frame changes, otherwise we'll get a lot of flicker.
635 bool heightChanging
wxDUMMY_INITIALIZE(true);
636 bool widthChanging
wxDUMMY_INITIALIZE(true);
638 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
640 // It's OK if the current height is greater than what can be shown.
641 heightChanging
= (desiredH
> th
) ;
642 widthChanging
= (desiredW
!= tw
) ;
644 // The next time around, we may not have to set the size
646 desiredH
= desiredH
+ 200;
650 // It's OK if the current width is greater than what can be shown.
651 widthChanging
= (desiredW
> tw
) ;
652 heightChanging
= (desiredH
!= th
) ;
654 // The next time around, we may not have to set the size
656 desiredW
= desiredW
+ 200;
659 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
660 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
662 #endif // __WXWINCE__
666 #endif // wxUSE_TOOLBAR
668 // ----------------------------------------------------------------------------
669 // frame state (iconized/maximized/...)
670 // ----------------------------------------------------------------------------
672 // propagate our state change to all child frames: this allows us to emulate X
673 // Windows behaviour where child frames float independently of the parent one
674 // on the desktop, but are iconized/restored with it
675 void wxFrame::IconizeChildFrames(bool bIconize
)
677 m_iconized
= bIconize
;
679 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
681 node
= node
->GetNext() )
683 wxWindow
*win
= node
->GetData();
685 // iconizing the frames with this style under Win95 shell puts them at
686 // the bottom of the screen (as the MDI children) instead of making
687 // them appear in the taskbar because they are, by virtue of this
688 // style, not managed by the taskbar - instead leave Windows take care
690 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
693 // the child MDI frames are a special case and should not be touched by
694 // the parent frame - instead, they are managed by the user
695 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
697 #if wxUSE_MDI_ARCHITECTURE
698 && !frame
->IsMDIChild()
699 #endif // wxUSE_MDI_ARCHITECTURE
702 // we don't want to restore the child frames which had been
703 // iconized even before we were iconized, so save the child frame
704 // status when iconizing the parent frame and check it when
708 frame
->m_wasMinimized
= frame
->IsIconized();
711 // note that we shouldn't touch the hidden frames neither because
712 // iconizing/restoring them would show them as a side effect
713 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
714 frame
->Iconize(bIconize
);
719 WXHICON
wxFrame::GetDefaultIcon() const
721 // we don't have any standard icons (any more)
725 // ===========================================================================
726 // message processing
727 // ===========================================================================
729 // ---------------------------------------------------------------------------
731 // ---------------------------------------------------------------------------
733 bool wxFrame::MSWDoTranslateMessage(wxFrame
*frame
, WXMSG
*pMsg
)
735 if ( wxWindow::MSWTranslateMessage(pMsg
) )
738 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
739 // try the menu bar accels
740 wxMenuBar
*menuBar
= GetMenuBar();
743 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
744 return acceleratorTable
.Translate(frame
, pMsg
);
746 #endif // wxUSE_MENUS && wxUSE_ACCEL
751 // ---------------------------------------------------------------------------
752 // our private (non virtual) message handlers
753 // ---------------------------------------------------------------------------
755 bool wxFrame::HandlePaint()
758 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
760 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
763 const wxIcon
& icon
= GetIcon();
764 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
765 : (HICON
)GetDefaultIcon();
767 // Hold a pointer to the dc so long as the OnPaint() message
768 // is being processed
770 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
772 // Erase background before painting or we get white background
773 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
778 ::GetClientRect(GetHwnd(), &rect
);
780 // FIXME: why hardcoded?
781 static const int icon_width
= 32;
782 static const int icon_height
= 32;
784 int icon_x
= (int)((rect
.right
- icon_width
)/2);
785 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
787 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
790 ::EndPaint(GetHwnd(), &ps
);
797 return wxWindow::HandlePaint();
802 // nothing to paint - processed
807 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
809 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
814 // only do it it if we were iconized before, otherwise resizing the
815 // parent frame has a curious side effect of bringing it under it's
820 // restore all child frames too
821 IconizeChildFrames(false);
823 (void)SendIconizeEvent(false);
827 // iconize all child frames too
828 IconizeChildFrames(true);
833 #endif // !__WXWINCE__
839 #endif // wxUSE_STATUSBAR
843 #endif // wxUSE_TOOLBAR
845 #if defined(WINCE_WITH_COMMANDBAR)
846 // Position the menu command bar
847 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
850 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
851 wxSize clientSz
= GetClientSize();
853 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
855 wxLogLastError(wxT("MoveWindow"));
859 #endif // WINCE_WITH_COMMANDBAR
862 // call the base class version to generate the appropriate events
866 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
870 // In case it's e.g. a toolbar.
871 wxWindow
*win
= wxFindWinFromHandle(control
);
873 return win
->MSWCommand(cmd
, id
);
876 // handle here commands from menus and accelerators
877 if ( cmd
== 0 || cmd
== 1 )
879 #if wxUSE_MENUS_NATIVE
880 if ( wxCurrentPopupMenu
)
882 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
883 wxCurrentPopupMenu
= NULL
;
885 return popupMenu
->MSWCommand(cmd
, id
);
887 #endif // wxUSE_MENUS_NATIVE
889 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
890 // handle here commands from Smartphone menu bar
891 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
895 #endif // __SMARTPHONE__ && __WXWINCE__
897 if ( ProcessCommand(id
) )
906 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
909 if ( flags
== 0xFFFF && hMenu
== 0 )
911 // menu was removed from screen
914 #ifndef __WXMICROWIN__
915 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
922 // don't give hints for separators (doesn't make sense) nor for the
923 // items opening popup menus (they don't have them anyhow) but do clear
924 // the status line - otherwise, we would be left with the help message
925 // for the previous item which doesn't apply any more
926 DoGiveHelp(wxEmptyString
, false);
931 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
932 event
.SetEventObject(this);
934 return GetEventHandler()->ProcessEvent(event
);
937 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
939 // we don't have the menu id here, so we use the id to specify if the event
940 // was from a popup menu or a normal one
941 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
942 event
.SetEventObject(this);
944 return GetEventHandler()->ProcessEvent(event
);
947 // ---------------------------------------------------------------------------
948 // the window proc for wxFrame
949 // ---------------------------------------------------------------------------
951 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
954 bool processed
= false;
959 // if we can't close, tell the system that we processed the
960 // message - otherwise it would close us
961 processed
= !Close();
965 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
972 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
975 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
980 processed
= HandlePaint();
983 case WM_INITMENUPOPUP
:
984 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
987 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
992 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
994 processed
= HandleMenuSelect(item
, flags
, hmenu
);
998 case WM_EXITMENULOOP
:
999 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
1002 case WM_QUERYDRAGICON
:
1004 const wxIcon
& icon
= GetIcon();
1005 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1006 : (HICON
)GetDefaultIcon();
1008 processed
= rc
!= 0;
1011 #endif // !__WXMICROWIN__
1015 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1020 // handle WM_INITMENUPOPUP message
1021 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1023 wxMenu
* menu
= NULL
;
1026 int nCount
= GetMenuBar()->GetMenuCount();
1027 for (int n
= 0; n
< nCount
; n
++)
1029 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1031 menu
= GetMenuBar()->GetMenu(n
);
1037 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1038 event
.SetEventObject(this);
1040 return GetEventHandler()->ProcessEvent(event
);
1043 // ----------------------------------------------------------------------------
1044 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1045 // from the client area, so the client area is what's really available for the
1047 // ----------------------------------------------------------------------------
1049 // get the origin of the client area in the client coordinates
1050 wxPoint
wxFrame::GetClientAreaOrigin() const
1052 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1054 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1055 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1056 wxToolBar
*toolbar
= GetToolBar();
1057 if ( toolbar
&& toolbar
->IsShown() )
1060 toolbar
->GetSize(&w
, &h
);
1062 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1071 #endif // wxUSE_TOOLBAR
1073 #if defined(WINCE_WITH_COMMANDBAR)
1074 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1077 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1078 pt
.y
+= (rect
.bottom
- rect
.top
);