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"
47 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
50 #include "wx/msw/winundef.h"
54 #include "wx/statusbr.h"
55 #include "wx/generic/statusbr.h"
56 #endif // wxUSE_STATUSBAR
59 #include "wx/toolbar.h"
60 #endif // wxUSE_TOOLBAR
62 #include "wx/menuitem.h"
64 #ifdef __WXUNIVERSAL__
65 #include "wx/univ/theme.h"
66 #include "wx/univ/colschem.h"
67 #endif // __WXUNIVERSAL__
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 #if wxUSE_MENUS_NATIVE
74 extern wxMenu
*wxCurrentPopupMenu
;
75 #endif // wxUSE_MENUS_NATIVE
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
82 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
85 #if wxUSE_EXTENDED_RTTI
86 WX_DEFINE_FLAGS( wxFrameStyle
)
88 wxBEGIN_FLAGS( wxFrameStyle
)
89 // new style border flags, we put them first to
90 // use them for streaming out
91 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
92 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
93 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
94 wxFLAGS_MEMBER(wxBORDER_RAISED
)
95 wxFLAGS_MEMBER(wxBORDER_STATIC
)
96 wxFLAGS_MEMBER(wxBORDER_NONE
)
98 // old style border flags
99 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
100 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
101 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
102 wxFLAGS_MEMBER(wxRAISED_BORDER
)
103 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
104 wxFLAGS_MEMBER(wxBORDER
)
106 // standard window styles
107 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
108 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
109 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
110 wxFLAGS_MEMBER(wxWANTS_CHARS
)
111 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
112 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
113 wxFLAGS_MEMBER(wxVSCROLL
)
114 wxFLAGS_MEMBER(wxHSCROLL
)
117 wxFLAGS_MEMBER(wxSTAY_ON_TOP
)
118 wxFLAGS_MEMBER(wxCAPTION
)
119 #if WXWIN_COMPATIBILITY_2_6
120 wxFLAGS_MEMBER(wxTHICK_FRAME
)
121 #endif // WXWIN_COMPATIBILITY_2_6
122 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
123 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
124 #if WXWIN_COMPATIBILITY_2_6
125 wxFLAGS_MEMBER(wxRESIZE_BOX
)
126 #endif // WXWIN_COMPATIBILITY_2_6
127 wxFLAGS_MEMBER(wxCLOSE_BOX
)
128 wxFLAGS_MEMBER(wxMAXIMIZE_BOX
)
129 wxFLAGS_MEMBER(wxMINIMIZE_BOX
)
131 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW
)
132 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT
)
134 wxFLAGS_MEMBER(wxFRAME_SHAPED
)
136 wxEND_FLAGS( wxFrameStyle
)
138 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame
, wxTopLevelWindow
,"wx/frame.h")
140 wxBEGIN_PROPERTIES_TABLE(wxFrame
)
141 wxEVENT_PROPERTY( Menu
, wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
)
143 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
144 wxPROPERTY_FLAGS( WindowStyle
, wxFrameStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
145 wxPROPERTY( MenuBar
, wxMenuBar
* , SetMenuBar
, GetMenuBar
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
146 wxEND_PROPERTIES_TABLE()
148 wxBEGIN_HANDLERS_TABLE(wxFrame
)
149 wxEND_HANDLERS_TABLE()
151 wxCONSTRUCTOR_6( wxFrame
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Title
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
154 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
157 // ============================================================================
159 // ============================================================================
161 // ----------------------------------------------------------------------------
162 // static class members
163 // ----------------------------------------------------------------------------
166 #if wxUSE_NATIVE_STATUSBAR
167 bool wxFrame::m_useNativeStatusBar
= true;
169 bool wxFrame::m_useNativeStatusBar
= false;
171 #endif // wxUSE_NATIVE_STATUSBAR
173 // ----------------------------------------------------------------------------
174 // creation/destruction
175 // ----------------------------------------------------------------------------
181 #endif // wxUSE_MENUS
187 m_wasMinimized
= false;
190 bool wxFrame::Create(wxWindow
*parent
,
192 const wxString
& title
,
196 const wxString
& name
)
198 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
201 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
203 #if defined(__SMARTPHONE__)
204 SetLeftMenu(wxID_EXIT
, _("Done"));
207 #if wxUSE_ACCEL && defined(__POCKETPC__)
208 // The guidelines state that Ctrl+Q should quit the app.
209 // Let's define an accelerator table to send wxID_EXIT.
210 wxAcceleratorEntry entries
[1];
211 entries
[0].Set(wxACCEL_CTRL
, 'Q', wxID_EXIT
);
212 wxAcceleratorTable
accel(1, entries
);
213 SetAcceleratorTable(accel
);
214 #endif // wxUSE_ACCEL && __POCKETPC__
221 m_isBeingDeleted
= true;
225 // ----------------------------------------------------------------------------
226 // wxFrame client size calculations
227 // ----------------------------------------------------------------------------
229 void wxFrame::DoSetClientSize(int width
, int height
)
231 // leave enough space for the status bar if we have (and show) it
233 wxStatusBar
*statbar
= GetStatusBar();
234 if ( statbar
&& statbar
->IsShown() )
236 height
+= statbar
->GetSize().y
;
238 #endif // wxUSE_STATUSBAR
240 // call GetClientAreaOrigin() to take the toolbar into account
241 wxPoint pt
= GetClientAreaOrigin();
245 wxTopLevelWindow::DoSetClientSize(width
, height
);
248 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
249 void wxFrame::DoGetClientSize(int *x
, int *y
) const
251 wxTopLevelWindow::DoGetClientSize(x
, y
);
253 // account for the possible toolbar
254 wxPoint pt
= GetClientAreaOrigin();
262 // adjust client area height to take the status bar into account
265 wxStatusBar
*statbar
= GetStatusBar();
266 if ( statbar
&& statbar
->IsShown() )
268 *y
-= statbar
->GetClientSize().y
;
271 #endif // wxUSE_STATUSBAR
274 // ----------------------------------------------------------------------------
275 // wxFrame: various geometry-related functions
276 // ----------------------------------------------------------------------------
278 void wxFrame::Raise()
280 ::SetForegroundWindow(GetHwnd());
283 // generate an artificial resize event
284 void wxFrame::SendSizeEvent()
288 RECT r
= wxGetWindowRect(GetHwnd());
290 (void)::PostMessage(GetHwnd(), WM_SIZE
,
291 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
292 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
297 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
300 const wxString
& name
)
302 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
304 #if wxUSE_NATIVE_STATUSBAR
305 if ( !UsesNativeStatusBar() )
307 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
312 statusBar
= new wxStatusBar(this, id
, style
, name
);
315 statusBar
->SetFieldsCount(number
);
320 void wxFrame::PositionStatusBar()
322 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
326 GetClientSize(&w
, &h
);
328 m_frameStatusBar
->GetSize(&sw
, &sh
);
330 // Since we wish the status bar to be directly under the client area,
331 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
332 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
334 #endif // wxUSE_STATUSBAR
336 #if wxUSE_MENUS_NATIVE
338 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
340 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
342 wxMenu
*autoMenu
= NULL
;
344 if( menubar
->GetMenuCount() == 1 )
346 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
347 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
351 autoMenu
= new wxMenu
;
353 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
355 wxMenu
*item
= menubar
->GetMenu(n
);
356 wxString label
= menubar
->GetLabelTop(n
);
357 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
358 autoMenu
->Append(wxID_ANY
, label
, new_item
);
361 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
364 #elif defined(WINCE_WITHOUT_COMMANDBAR)
367 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
368 wxDefaultPosition
, wxDefaultSize
,
369 wxBORDER_NONE
| wxTB_HORIZONTAL
,
370 wxToolBarNameStr
, menubar
);
372 menubar
->SetToolBar(toolBar
);
374 // Now adjust size for menu bar
377 //When the main window is created using CW_USEDEFAULT the height of the
378 // is created is not taken into account). So we resize the window after
379 // if a menubar is present
382 ::GetWindowRect((HWND
) GetHWND(), &rc
);
383 // adjust for menu / titlebar height
384 rc
.bottom
-= (2*menuHeight
-1);
386 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
390 wxFrameBase::AttachMenuBar(menubar
);
394 // actually remove the menu from the frame
395 m_hMenu
= (WXHMENU
)0;
396 InternalSetMenuBar();
398 else // set new non NULL menu bar
400 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
401 // Can set a menubar several times.
402 if ( menubar
->GetHMenu() )
404 m_hMenu
= menubar
->GetHMenu();
408 m_hMenu
= menubar
->Create();
412 wxFAIL_MSG( _T("failed to create menu bar") );
417 InternalSetMenuBar();
421 void wxFrame::InternalSetMenuBar()
423 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
426 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
428 wxLogLastError(wxT("SetMenu"));
433 #endif // wxUSE_MENUS_NATIVE
435 // Responds to colour changes, and passes event on to children.
436 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
438 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
442 if ( m_frameStatusBar
)
444 wxSysColourChangedEvent event2
;
445 event2
.SetEventObject( m_frameStatusBar
);
446 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
448 #endif // wxUSE_STATUSBAR
450 // Propagate the event to the non-top-level children
451 wxWindow::OnSysColourChanged(event
);
454 // Pass true to show full screen, false to restore.
455 bool wxFrame::ShowFullScreen(bool show
, long style
)
457 // TODO-CE: add support for CE
458 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
459 if ( IsFullScreen() == show
)
464 // zap the toolbar, menubar, and statusbar if needed
466 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
468 wxToolBar
*theToolBar
= GetToolBar();
470 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
472 if ( theToolBar
->IsShown() )
474 theToolBar
->SetSize(wxDefaultCoord
,0);
475 theToolBar
->Show(false);
477 else // prevent it from being restored later
479 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
482 #endif // wxUSE_TOOLBAR
484 if (style
& wxFULLSCREEN_NOMENUBAR
)
485 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
488 wxStatusBar
*theStatusBar
= GetStatusBar();
490 // Save the number of fields in the statusbar
491 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
493 if ( theStatusBar
->IsShown() )
494 theStatusBar
->Show(false);
496 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
498 #endif // wxUSE_STATUSBAR
500 else // restore to normal
502 // restore the toolbar, menubar, and statusbar if we had hid them
504 wxToolBar
*theToolBar
= GetToolBar();
506 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
508 theToolBar
->Show(true);
510 #endif // wxUSE_TOOLBAR
512 if (m_fsStyle
& wxFULLSCREEN_NOMENUBAR
)
514 WXHMENU menu
= m_hMenu
;
516 #if wxUSE_MDI_ARCHITECTURE
517 wxMDIParentFrame
*frame
= wxDynamicCast(this, wxMDIParentFrame
);
520 wxMDIChildFrame
*child
= frame
->GetActiveChild();
523 menu
= child
->GetWinMenu();
526 #endif // wxUSE_MDI_ARCHITECTURE
530 ::SetMenu(GetHwnd(), (HMENU
)menu
);
535 wxStatusBar
*theStatusBar
= GetStatusBar();
537 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
539 theStatusBar
->Show(true);
542 #endif // wxUSE_STATUSBAR
544 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
546 return wxFrameBase::ShowFullScreen(show
, style
);
549 // ----------------------------------------------------------------------------
550 // tool/status bar stuff
551 // ----------------------------------------------------------------------------
555 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
557 #if defined(WINCE_WITHOUT_COMMANDBAR)
558 // We may already have a toolbar from calling SetMenuBar.
562 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
567 return m_frameToolBar
;
570 void wxFrame::PositionToolBar()
572 wxToolBar
*toolbar
= GetToolBar();
573 if ( toolbar
&& toolbar
->IsShown() )
575 #if defined(WINCE_WITHOUT_COMMANDBAR)
576 // We want to do something different in WinCE, because
577 // the toolbar should be associated with the commandbar,
578 // and not an independent window.
581 // don't call our (or even wxTopLevelWindow) version because we want
582 // the real (full) client area size, not excluding the tool/status bar
584 wxWindow::DoGetClientSize(&width
, &height
);
587 wxStatusBar
*statbar
= GetStatusBar();
588 if ( statbar
&& statbar
->IsShown() )
590 height
-= statbar
->GetClientSize().y
;
592 #endif // wxUSE_STATUSBAR
596 #if defined(WINCE_WITH_COMMANDBAR)
597 // We're using a commandbar - so we have to allow for it.
598 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
601 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
602 y
= rect
.bottom
- rect
.top
;
608 toolbar
->GetPosition(&tx
, &ty
);
609 toolbar
->GetSize(&tw
, &th
);
612 if (ty
< 0 && (-ty
== th
))
614 if (tx
< 0 && (-tx
== tw
))
620 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
627 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
631 // use the 'real' MSW position here, don't offset relativly to the
632 // client area origin
634 // Optimise such that we don't have to always resize the toolbar
635 // when the frame changes, otherwise we'll get a lot of flicker.
636 bool heightChanging
wxDUMMY_INITIALIZE(true);
637 bool widthChanging
wxDUMMY_INITIALIZE(true);
639 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
641 // It's OK if the current height is greater than what can be shown.
642 heightChanging
= (desiredH
> th
) ;
643 widthChanging
= (desiredW
!= tw
) ;
645 // The next time around, we may not have to set the size
647 desiredH
= desiredH
+ 200;
651 // It's OK if the current width is greater than what can be shown.
652 widthChanging
= (desiredW
> tw
) ;
653 heightChanging
= (desiredH
!= th
) ;
655 // The next time around, we may not have to set the size
657 desiredW
= desiredW
+ 200;
660 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
661 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
663 #endif // __WXWINCE__
667 #endif // wxUSE_TOOLBAR
669 // ----------------------------------------------------------------------------
670 // frame state (iconized/maximized/...)
671 // ----------------------------------------------------------------------------
673 // propagate our state change to all child frames: this allows us to emulate X
674 // Windows behaviour where child frames float independently of the parent one
675 // on the desktop, but are iconized/restored with it
676 void wxFrame::IconizeChildFrames(bool bIconize
)
678 m_iconized
= bIconize
;
680 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
682 node
= node
->GetNext() )
684 wxWindow
*win
= node
->GetData();
686 // iconizing the frames with this style under Win95 shell puts them at
687 // the bottom of the screen (as the MDI children) instead of making
688 // them appear in the taskbar because they are, by virtue of this
689 // style, not managed by the taskbar - instead leave Windows take care
691 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
694 // the child MDI frames are a special case and should not be touched by
695 // the parent frame - instead, they are managed by the user
696 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
698 #if wxUSE_MDI_ARCHITECTURE
699 && !frame
->IsMDIChild()
700 #endif // wxUSE_MDI_ARCHITECTURE
703 // we don't want to restore the child frames which had been
704 // iconized even before we were iconized, so save the child frame
705 // status when iconizing the parent frame and check it when
709 frame
->m_wasMinimized
= frame
->IsIconized();
712 // note that we shouldn't touch the hidden frames neither because
713 // iconizing/restoring them would show them as a side effect
714 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
715 frame
->Iconize(bIconize
);
720 WXHICON
wxFrame::GetDefaultIcon() const
722 // we don't have any standard icons (any more)
726 // ===========================================================================
727 // message processing
728 // ===========================================================================
730 // ---------------------------------------------------------------------------
732 // ---------------------------------------------------------------------------
734 bool wxFrame::MSWDoTranslateMessage(wxFrame
*frame
, WXMSG
*pMsg
)
736 if ( wxWindow::MSWTranslateMessage(pMsg
) )
739 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
740 // try the menu bar accels
741 wxMenuBar
*menuBar
= GetMenuBar();
744 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
745 return acceleratorTable
.Translate(frame
, pMsg
);
747 #endif // wxUSE_MENUS && wxUSE_ACCEL
752 // ---------------------------------------------------------------------------
753 // our private (non virtual) message handlers
754 // ---------------------------------------------------------------------------
756 bool wxFrame::HandlePaint()
759 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
761 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
764 const wxIcon
& icon
= GetIcon();
765 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
766 : (HICON
)GetDefaultIcon();
768 // Hold a pointer to the dc so long as the OnPaint() message
769 // is being processed
771 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
773 // Erase background before painting or we get white background
774 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
779 ::GetClientRect(GetHwnd(), &rect
);
781 // FIXME: why hardcoded?
782 static const int icon_width
= 32;
783 static const int icon_height
= 32;
785 int icon_x
= (int)((rect
.right
- icon_width
)/2);
786 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
788 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
791 ::EndPaint(GetHwnd(), &ps
);
798 return wxWindow::HandlePaint();
803 // nothing to paint - processed
808 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
810 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
815 // only do it it if we were iconized before, otherwise resizing the
816 // parent frame has a curious side effect of bringing it under it's
821 // restore all child frames too
822 IconizeChildFrames(false);
824 (void)SendIconizeEvent(false);
828 // iconize all child frames too
829 IconizeChildFrames(true);
834 #endif // !__WXWINCE__
840 #endif // wxUSE_STATUSBAR
844 #endif // wxUSE_TOOLBAR
846 #if defined(WINCE_WITH_COMMANDBAR)
847 // Position the menu command bar
848 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
851 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
852 wxSize clientSz
= GetClientSize();
854 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
856 wxLogLastError(wxT("MoveWindow"));
860 #endif // WINCE_WITH_COMMANDBAR
863 // call the base class version to generate the appropriate events
867 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
871 // In case it's e.g. a toolbar.
872 wxWindow
*win
= wxFindWinFromHandle(control
);
874 return win
->MSWCommand(cmd
, id
);
877 // handle here commands from menus and accelerators
878 if ( cmd
== 0 || cmd
== 1 )
880 #if wxUSE_MENUS_NATIVE
881 if ( wxCurrentPopupMenu
)
883 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
884 wxCurrentPopupMenu
= NULL
;
886 return popupMenu
->MSWCommand(cmd
, id
);
888 #endif // wxUSE_MENUS_NATIVE
890 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
891 // handle here commands from Smartphone menu bar
892 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
896 #endif // __SMARTPHONE__ && __WXWINCE__
898 if ( ProcessCommand(id
) )
907 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
910 if ( flags
== 0xFFFF && hMenu
== 0 )
912 // menu was removed from screen
915 #ifndef __WXMICROWIN__
916 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
923 // don't give hints for separators (doesn't make sense) nor for the
924 // items opening popup menus (they don't have them anyhow) but do clear
925 // the status line - otherwise, we would be left with the help message
926 // for the previous item which doesn't apply any more
927 DoGiveHelp(wxEmptyString
, false);
932 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
933 event
.SetEventObject(this);
935 return GetEventHandler()->ProcessEvent(event
);
938 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
940 // we don't have the menu id here, so we use the id to specify if the event
941 // was from a popup menu or a normal one
942 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
943 event
.SetEventObject(this);
945 return GetEventHandler()->ProcessEvent(event
);
948 // ---------------------------------------------------------------------------
949 // the window proc for wxFrame
950 // ---------------------------------------------------------------------------
952 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
955 bool processed
= false;
960 // if we can't close, tell the system that we processed the
961 // message - otherwise it would close us
962 processed
= !Close();
966 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
973 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
976 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
981 processed
= HandlePaint();
984 case WM_INITMENUPOPUP
:
985 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
988 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
993 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
995 processed
= HandleMenuSelect(item
, flags
, hmenu
);
999 case WM_EXITMENULOOP
:
1000 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
1003 case WM_QUERYDRAGICON
:
1005 const wxIcon
& icon
= GetIcon();
1006 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1007 : (HICON
)GetDefaultIcon();
1009 processed
= rc
!= 0;
1012 #endif // !__WXMICROWIN__
1016 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1021 // handle WM_INITMENUPOPUP message
1022 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1024 wxMenu
* menu
= NULL
;
1027 int nCount
= GetMenuBar()->GetMenuCount();
1028 for (int n
= 0; n
< nCount
; n
++)
1030 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1032 menu
= GetMenuBar()->GetMenu(n
);
1038 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1039 event
.SetEventObject(this);
1041 return GetEventHandler()->ProcessEvent(event
);
1044 // ----------------------------------------------------------------------------
1045 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1046 // from the client area, so the client area is what's really available for the
1048 // ----------------------------------------------------------------------------
1050 // get the origin of the client area in the client coordinates
1051 wxPoint
wxFrame::GetClientAreaOrigin() const
1053 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1055 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1056 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1057 wxToolBar
*toolbar
= GetToolBar();
1058 if ( toolbar
&& toolbar
->IsShown() )
1061 toolbar
->GetSize(&w
, &h
);
1063 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1072 #endif // wxUSE_TOOLBAR
1074 #if defined(WINCE_WITH_COMMANDBAR)
1075 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1078 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1079 pt
.y
+= (rect
.bottom
- rect
.top
);