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"
39 #include "wx/toolbar.h"
40 #include "wx/statusbr.h"
41 #include "wx/menuitem.h"
44 #include "wx/msw/private.h"
46 // include <commctrl.h> "properly"
47 #include "wx/msw/wrapcctl.h"
49 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
52 #include "wx/msw/winundef.h"
55 #include "wx/generic/statusbr.h"
57 #ifdef __WXUNIVERSAL__
58 #include "wx/univ/theme.h"
59 #include "wx/univ/colschem.h"
60 #endif // __WXUNIVERSAL__
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 #if wxUSE_MENUS_NATIVE
67 extern wxMenu
*wxCurrentPopupMenu
;
68 #endif // wxUSE_MENUS_NATIVE
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
75 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
78 #if wxUSE_EXTENDED_RTTI
79 WX_DEFINE_FLAGS( wxFrameStyle
)
81 wxBEGIN_FLAGS( wxFrameStyle
)
82 // new style border flags, we put them first to
83 // use them for streaming out
84 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
85 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
86 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
87 wxFLAGS_MEMBER(wxBORDER_RAISED
)
88 wxFLAGS_MEMBER(wxBORDER_STATIC
)
89 wxFLAGS_MEMBER(wxBORDER_NONE
)
91 // old style border flags
92 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
93 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
94 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
95 wxFLAGS_MEMBER(wxRAISED_BORDER
)
96 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
97 wxFLAGS_MEMBER(wxBORDER
)
99 // standard window styles
100 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
101 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
102 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
103 wxFLAGS_MEMBER(wxWANTS_CHARS
)
104 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
105 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
106 wxFLAGS_MEMBER(wxVSCROLL
)
107 wxFLAGS_MEMBER(wxHSCROLL
)
110 wxFLAGS_MEMBER(wxSTAY_ON_TOP
)
111 wxFLAGS_MEMBER(wxCAPTION
)
112 #if WXWIN_COMPATIBILITY_2_6
113 wxFLAGS_MEMBER(wxTHICK_FRAME
)
114 #endif // WXWIN_COMPATIBILITY_2_6
115 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
116 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
117 #if WXWIN_COMPATIBILITY_2_6
118 wxFLAGS_MEMBER(wxRESIZE_BOX
)
119 #endif // WXWIN_COMPATIBILITY_2_6
120 wxFLAGS_MEMBER(wxCLOSE_BOX
)
121 wxFLAGS_MEMBER(wxMAXIMIZE_BOX
)
122 wxFLAGS_MEMBER(wxMINIMIZE_BOX
)
124 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW
)
125 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT
)
127 wxFLAGS_MEMBER(wxFRAME_SHAPED
)
129 wxEND_FLAGS( wxFrameStyle
)
131 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame
, wxTopLevelWindow
,"wx/frame.h")
133 wxBEGIN_PROPERTIES_TABLE(wxFrame
)
134 wxEVENT_PROPERTY( Menu
, wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
)
136 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
137 wxPROPERTY_FLAGS( WindowStyle
, wxFrameStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
138 wxPROPERTY( MenuBar
, wxMenuBar
* , SetMenuBar
, GetMenuBar
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
139 wxEND_PROPERTIES_TABLE()
141 wxBEGIN_HANDLERS_TABLE(wxFrame
)
142 wxEND_HANDLERS_TABLE()
144 wxCONSTRUCTOR_6( wxFrame
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Title
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
147 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
150 // ============================================================================
152 // ============================================================================
154 // ----------------------------------------------------------------------------
155 // static class members
156 // ----------------------------------------------------------------------------
159 #if wxUSE_NATIVE_STATUSBAR
160 bool wxFrame::m_useNativeStatusBar
= true;
162 bool wxFrame::m_useNativeStatusBar
= false;
164 #endif // wxUSE_NATIVE_STATUSBAR
166 // ----------------------------------------------------------------------------
167 // creation/destruction
168 // ----------------------------------------------------------------------------
174 #endif // wxUSE_MENUS
180 m_wasMinimized
= false;
183 bool wxFrame::Create(wxWindow
*parent
,
185 const wxString
& title
,
189 const wxString
& name
)
191 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
194 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
196 #if defined(__SMARTPHONE__)
197 SetLeftMenu(wxID_EXIT
, _("Done"));
200 #if wxUSE_ACCEL && defined(__POCKETPC__)
201 // The guidelines state that Ctrl+Q should quit the app.
202 // Let's define an accelerator table to send wxID_EXIT.
203 wxAcceleratorEntry entries
[1];
204 entries
[0].Set(wxACCEL_CTRL
, 'Q', wxID_EXIT
);
205 wxAcceleratorTable
accel(1, entries
);
206 SetAcceleratorTable(accel
);
207 #endif // wxUSE_ACCEL && __POCKETPC__
214 m_isBeingDeleted
= true;
218 // ----------------------------------------------------------------------------
219 // wxFrame client size calculations
220 // ----------------------------------------------------------------------------
222 void wxFrame::DoSetClientSize(int width
, int height
)
224 // leave enough space for the status bar if we have (and show) it
226 wxStatusBar
*statbar
= GetStatusBar();
227 if ( statbar
&& statbar
->IsShown() )
229 height
+= statbar
->GetSize().y
;
231 #endif // wxUSE_STATUSBAR
233 // call GetClientAreaOrigin() to take the toolbar into account
234 wxPoint pt
= GetClientAreaOrigin();
238 wxTopLevelWindow::DoSetClientSize(width
, height
);
241 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
242 void wxFrame::DoGetClientSize(int *x
, int *y
) const
244 wxTopLevelWindow::DoGetClientSize(x
, y
);
246 // account for the possible toolbar
247 wxPoint pt
= GetClientAreaOrigin();
255 // adjust client area height to take the status bar into account
258 wxStatusBar
*statbar
= GetStatusBar();
259 if ( statbar
&& statbar
->IsShown() )
261 *y
-= statbar
->GetClientSize().y
;
264 #endif // wxUSE_STATUSBAR
267 // ----------------------------------------------------------------------------
268 // wxFrame: various geometry-related functions
269 // ----------------------------------------------------------------------------
271 void wxFrame::Raise()
273 ::SetForegroundWindow(GetHwnd());
276 // generate an artificial resize event
277 void wxFrame::SendSizeEvent()
281 RECT r
= wxGetWindowRect(GetHwnd());
283 (void)::PostMessage(GetHwnd(), WM_SIZE
,
284 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
285 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
290 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
293 const wxString
& name
)
295 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
297 #if wxUSE_NATIVE_STATUSBAR
298 if ( !UsesNativeStatusBar() )
300 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
305 statusBar
= new wxStatusBar(this, id
, style
, name
);
308 statusBar
->SetFieldsCount(number
);
313 void wxFrame::PositionStatusBar()
315 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
319 GetClientSize(&w
, &h
);
321 m_frameStatusBar
->GetSize(&sw
, &sh
);
323 // Since we wish the status bar to be directly under the client area,
324 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
325 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
327 #endif // wxUSE_STATUSBAR
329 #if wxUSE_MENUS_NATIVE
331 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
333 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
335 wxMenu
*autoMenu
= NULL
;
337 if( menubar
->GetMenuCount() == 1 )
339 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
340 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
344 autoMenu
= new wxMenu
;
346 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
348 wxMenu
*item
= menubar
->GetMenu(n
);
349 wxString label
= menubar
->GetLabelTop(n
);
350 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
351 autoMenu
->Append(wxID_ANY
, label
, new_item
);
354 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
357 #elif defined(WINCE_WITHOUT_COMMANDBAR)
360 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
361 wxDefaultPosition
, wxDefaultSize
,
362 wxBORDER_NONE
| wxTB_HORIZONTAL
,
363 wxToolBarNameStr
, menubar
);
365 menubar
->SetToolBar(toolBar
);
367 // Now adjust size for menu bar
370 //When the main window is created using CW_USEDEFAULT the height of the
371 // is created is not taken into account). So we resize the window after
372 // if a menubar is present
375 ::GetWindowRect((HWND
) GetHWND(), &rc
);
376 // adjust for menu / titlebar height
377 rc
.bottom
-= (2*menuHeight
-1);
379 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
383 wxFrameBase::AttachMenuBar(menubar
);
387 // actually remove the menu from the frame
388 m_hMenu
= (WXHMENU
)0;
389 InternalSetMenuBar();
391 else // set new non NULL menu bar
393 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
394 // Can set a menubar several times.
395 if ( menubar
->GetHMenu() )
397 m_hMenu
= menubar
->GetHMenu();
401 m_hMenu
= menubar
->Create();
405 wxFAIL_MSG( _T("failed to create menu bar") );
410 InternalSetMenuBar();
414 void wxFrame::InternalSetMenuBar()
416 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
419 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
421 wxLogLastError(wxT("SetMenu"));
426 #endif // wxUSE_MENUS_NATIVE
428 // Responds to colour changes, and passes event on to children.
429 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
431 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
435 if ( m_frameStatusBar
)
437 wxSysColourChangedEvent event2
;
438 event2
.SetEventObject( m_frameStatusBar
);
439 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
441 #endif // wxUSE_STATUSBAR
443 // Propagate the event to the non-top-level children
444 wxWindow::OnSysColourChanged(event
);
447 // Pass true to show full screen, false to restore.
448 bool wxFrame::ShowFullScreen(bool show
, long style
)
450 // TODO-CE: add support for CE
451 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
452 if ( IsFullScreen() == show
)
457 // zap the toolbar, menubar, and statusbar if needed
459 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
461 wxToolBar
*theToolBar
= GetToolBar();
463 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
465 if ( theToolBar
->IsShown() )
467 theToolBar
->SetSize(wxDefaultCoord
,0);
468 theToolBar
->Show(false);
470 else // prevent it from being restored later
472 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
475 #endif // wxUSE_TOOLBAR
477 if (style
& wxFULLSCREEN_NOMENUBAR
)
478 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
481 wxStatusBar
*theStatusBar
= GetStatusBar();
483 // Save the number of fields in the statusbar
484 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
486 if ( theStatusBar
->IsShown() )
487 theStatusBar
->Show(false);
489 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
491 #endif // wxUSE_STATUSBAR
493 else // restore to normal
495 // restore the toolbar, menubar, and statusbar if we had hid them
497 wxToolBar
*theToolBar
= GetToolBar();
499 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
501 theToolBar
->Show(true);
503 #endif // wxUSE_TOOLBAR
505 if (m_fsStyle
& wxFULLSCREEN_NOMENUBAR
)
507 WXHMENU menu
= m_hMenu
;
509 #if wxUSE_MDI_ARCHITECTURE
510 wxMDIParentFrame
*frame
= wxDynamicCast(this, wxMDIParentFrame
);
513 wxMDIChildFrame
*child
= frame
->GetActiveChild();
516 menu
= child
->GetWinMenu();
519 #endif // wxUSE_MDI_ARCHITECTURE
523 ::SetMenu(GetHwnd(), (HMENU
)menu
);
528 wxStatusBar
*theStatusBar
= GetStatusBar();
530 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
532 theStatusBar
->Show(true);
535 #endif // wxUSE_STATUSBAR
537 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
539 return wxFrameBase::ShowFullScreen(show
, style
);
542 // ----------------------------------------------------------------------------
543 // tool/status bar stuff
544 // ----------------------------------------------------------------------------
548 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
550 #if defined(WINCE_WITHOUT_COMMANDBAR)
551 // We may already have a toolbar from calling SetMenuBar.
555 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
560 return m_frameToolBar
;
563 void wxFrame::PositionToolBar()
565 wxToolBar
*toolbar
= GetToolBar();
566 if ( toolbar
&& toolbar
->IsShown() )
568 #if defined(WINCE_WITHOUT_COMMANDBAR)
569 // We want to do something different in WinCE, because
570 // the toolbar should be associated with the commandbar,
571 // and not an independent window.
574 // don't call our (or even wxTopLevelWindow) version because we want
575 // the real (full) client area size, not excluding the tool/status bar
577 wxWindow::DoGetClientSize(&width
, &height
);
580 wxStatusBar
*statbar
= GetStatusBar();
581 if ( statbar
&& statbar
->IsShown() )
583 height
-= statbar
->GetClientSize().y
;
585 #endif // wxUSE_STATUSBAR
589 #if defined(WINCE_WITH_COMMANDBAR)
590 // We're using a commandbar - so we have to allow for it.
591 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
594 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
595 y
= rect
.bottom
- rect
.top
;
601 toolbar
->GetPosition(&tx
, &ty
);
602 toolbar
->GetSize(&tw
, &th
);
605 if (ty
< 0 && (-ty
== th
))
607 if (tx
< 0 && (-tx
== tw
))
613 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
620 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
624 // use the 'real' MSW position here, don't offset relativly to the
625 // client area origin
627 // Optimise such that we don't have to always resize the toolbar
628 // when the frame changes, otherwise we'll get a lot of flicker.
629 bool heightChanging
wxDUMMY_INITIALIZE(true);
630 bool widthChanging
wxDUMMY_INITIALIZE(true);
632 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
634 // It's OK if the current height is greater than what can be shown.
635 heightChanging
= (desiredH
> th
) ;
636 widthChanging
= (desiredW
!= tw
) ;
638 // The next time around, we may not have to set the size
640 desiredH
= desiredH
+ 200;
644 // It's OK if the current width is greater than what can be shown.
645 widthChanging
= (desiredW
> tw
) ;
646 heightChanging
= (desiredH
!= th
) ;
648 // The next time around, we may not have to set the size
650 desiredW
= desiredW
+ 200;
653 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
654 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
656 #endif // __WXWINCE__
660 #endif // wxUSE_TOOLBAR
662 // ----------------------------------------------------------------------------
663 // frame state (iconized/maximized/...)
664 // ----------------------------------------------------------------------------
666 // propagate our state change to all child frames: this allows us to emulate X
667 // Windows behaviour where child frames float independently of the parent one
668 // on the desktop, but are iconized/restored with it
669 void wxFrame::IconizeChildFrames(bool bIconize
)
671 m_iconized
= bIconize
;
673 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
675 node
= node
->GetNext() )
677 wxWindow
*win
= node
->GetData();
679 // iconizing the frames with this style under Win95 shell puts them at
680 // the bottom of the screen (as the MDI children) instead of making
681 // them appear in the taskbar because they are, by virtue of this
682 // style, not managed by the taskbar - instead leave Windows take care
684 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
687 // the child MDI frames are a special case and should not be touched by
688 // the parent frame - instead, they are managed by the user
689 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
691 #if wxUSE_MDI_ARCHITECTURE
692 && !frame
->IsMDIChild()
693 #endif // wxUSE_MDI_ARCHITECTURE
696 // we don't want to restore the child frames which had been
697 // iconized even before we were iconized, so save the child frame
698 // status when iconizing the parent frame and check it when
702 frame
->m_wasMinimized
= frame
->IsIconized();
705 // note that we shouldn't touch the hidden frames neither because
706 // iconizing/restoring them would show them as a side effect
707 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
708 frame
->Iconize(bIconize
);
713 WXHICON
wxFrame::GetDefaultIcon() const
715 // we don't have any standard icons (any more)
719 // ===========================================================================
720 // message processing
721 // ===========================================================================
723 // ---------------------------------------------------------------------------
725 // ---------------------------------------------------------------------------
727 bool wxFrame::MSWDoTranslateMessage(wxFrame
*frame
, WXMSG
*pMsg
)
729 if ( wxWindow::MSWTranslateMessage(pMsg
) )
732 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
733 // try the menu bar accels
734 wxMenuBar
*menuBar
= GetMenuBar();
737 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
738 return acceleratorTable
.Translate(frame
, pMsg
);
740 #endif // wxUSE_MENUS && wxUSE_ACCEL
745 // ---------------------------------------------------------------------------
746 // our private (non virtual) message handlers
747 // ---------------------------------------------------------------------------
749 bool wxFrame::HandlePaint()
752 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
754 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
757 const wxIcon
& icon
= GetIcon();
758 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
759 : (HICON
)GetDefaultIcon();
761 // Hold a pointer to the dc so long as the OnPaint() message
762 // is being processed
764 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
766 // Erase background before painting or we get white background
767 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
772 ::GetClientRect(GetHwnd(), &rect
);
774 // FIXME: why hardcoded?
775 static const int icon_width
= 32;
776 static const int icon_height
= 32;
778 int icon_x
= (int)((rect
.right
- icon_width
)/2);
779 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
781 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
784 ::EndPaint(GetHwnd(), &ps
);
791 return wxWindow::HandlePaint();
796 // nothing to paint - processed
801 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
803 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
808 // only do it it if we were iconized before, otherwise resizing the
809 // parent frame has a curious side effect of bringing it under it's
814 // restore all child frames too
815 IconizeChildFrames(false);
817 (void)SendIconizeEvent(false);
821 // iconize all child frames too
822 IconizeChildFrames(true);
827 #endif // !__WXWINCE__
833 #endif // wxUSE_STATUSBAR
837 #endif // wxUSE_TOOLBAR
839 #if defined(WINCE_WITH_COMMANDBAR)
840 // Position the menu command bar
841 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
844 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
845 wxSize clientSz
= GetClientSize();
847 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
849 wxLogLastError(wxT("MoveWindow"));
853 #endif // WINCE_WITH_COMMANDBAR
856 // call the base class version to generate the appropriate events
860 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
864 // In case it's e.g. a toolbar.
865 wxWindow
*win
= wxFindWinFromHandle(control
);
867 return win
->MSWCommand(cmd
, id
);
870 // handle here commands from menus and accelerators
871 if ( cmd
== 0 || cmd
== 1 )
873 #if wxUSE_MENUS_NATIVE
874 if ( wxCurrentPopupMenu
)
876 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
877 wxCurrentPopupMenu
= NULL
;
879 return popupMenu
->MSWCommand(cmd
, id
);
881 #endif // wxUSE_MENUS_NATIVE
883 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
884 // handle here commands from Smartphone menu bar
885 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
889 #endif // __SMARTPHONE__ && __WXWINCE__
891 if ( ProcessCommand(id
) )
900 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
903 if ( flags
== 0xFFFF && hMenu
== 0 )
905 // menu was removed from screen
908 #ifndef __WXMICROWIN__
909 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
916 // don't give hints for separators (doesn't make sense) nor for the
917 // items opening popup menus (they don't have them anyhow) but do clear
918 // the status line - otherwise, we would be left with the help message
919 // for the previous item which doesn't apply any more
920 DoGiveHelp(wxEmptyString
, false);
925 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
926 event
.SetEventObject(this);
928 return GetEventHandler()->ProcessEvent(event
);
931 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
933 // we don't have the menu id here, so we use the id to specify if the event
934 // was from a popup menu or a normal one
935 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
936 event
.SetEventObject(this);
938 return GetEventHandler()->ProcessEvent(event
);
941 // ---------------------------------------------------------------------------
942 // the window proc for wxFrame
943 // ---------------------------------------------------------------------------
945 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
948 bool processed
= false;
953 // if we can't close, tell the system that we processed the
954 // message - otherwise it would close us
955 processed
= !Close();
959 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
966 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
969 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
974 processed
= HandlePaint();
977 case WM_INITMENUPOPUP
:
978 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
981 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
986 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
988 processed
= HandleMenuSelect(item
, flags
, hmenu
);
992 case WM_EXITMENULOOP
:
993 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
996 case WM_QUERYDRAGICON
:
998 const wxIcon
& icon
= GetIcon();
999 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1000 : (HICON
)GetDefaultIcon();
1002 processed
= rc
!= 0;
1005 #endif // !__WXMICROWIN__
1009 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1014 // handle WM_INITMENUPOPUP message
1015 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1017 wxMenu
* menu
= NULL
;
1020 int nCount
= GetMenuBar()->GetMenuCount();
1021 for (int n
= 0; n
< nCount
; n
++)
1023 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1025 menu
= GetMenuBar()->GetMenu(n
);
1031 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1032 event
.SetEventObject(this);
1034 return GetEventHandler()->ProcessEvent(event
);
1037 // ----------------------------------------------------------------------------
1038 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1039 // from the client area, so the client area is what's really available for the
1041 // ----------------------------------------------------------------------------
1043 // get the origin of the client area in the client coordinates
1044 wxPoint
wxFrame::GetClientAreaOrigin() const
1046 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1048 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1049 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1050 wxToolBar
*toolbar
= GetToolBar();
1051 if ( toolbar
&& toolbar
->IsShown() )
1054 toolbar
->GetSize(&w
, &h
);
1056 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1065 #endif // wxUSE_TOOLBAR
1067 #if defined(WINCE_WITH_COMMANDBAR)
1068 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1071 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1072 pt
.y
+= (rect
.bottom
- rect
.top
);