1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "frame.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/dcclient.h"
43 #include "wx/msw/private.h"
50 #include "wx/statusbr.h"
51 #include "wx/generic/statusbr.h"
52 #endif // wxUSE_STATUSBAR
55 #include "wx/toolbar.h"
56 #endif // wxUSE_TOOLBAR
58 #include "wx/menuitem.h"
61 #ifdef __WXUNIVERSAL__
62 #include "wx/univ/theme.h"
63 #include "wx/univ/colschem.h"
64 #endif // __WXUNIVERSAL__
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 #if wxUSE_MENUS_NATIVE
71 extern wxMenu
*wxCurrentPopupMenu
;
72 #endif // wxUSE_MENUS_NATIVE
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
79 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
82 #if wxUSE_EXTENDED_RTTI
83 WX_DEFINE_FLAGS( wxFrameStyle
)
85 wxBEGIN_FLAGS( wxFrameStyle
)
86 // new style border flags, we put them first to
87 // use them for streaming out
88 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
89 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
90 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
91 wxFLAGS_MEMBER(wxBORDER_RAISED
)
92 wxFLAGS_MEMBER(wxBORDER_STATIC
)
93 wxFLAGS_MEMBER(wxBORDER_NONE
)
95 // old style border flags
96 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
97 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
98 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
99 wxFLAGS_MEMBER(wxRAISED_BORDER
)
100 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
101 wxFLAGS_MEMBER(wxBORDER
)
103 // standard window styles
104 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
105 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
106 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
107 wxFLAGS_MEMBER(wxWANTS_CHARS
)
108 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
109 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
110 wxFLAGS_MEMBER(wxVSCROLL
)
111 wxFLAGS_MEMBER(wxHSCROLL
)
114 wxFLAGS_MEMBER(wxSTAY_ON_TOP
)
115 wxFLAGS_MEMBER(wxCAPTION
)
116 wxFLAGS_MEMBER(wxTHICK_FRAME
)
117 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
118 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
119 wxFLAGS_MEMBER(wxRESIZE_BOX
)
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 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
);
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
) && m_hMenu
)
506 ::SetMenu(GetHwnd(), (HMENU
)m_hMenu
);
509 wxStatusBar
*theStatusBar
= GetStatusBar();
511 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
513 theStatusBar
->Show(true);
516 #endif // wxUSE_STATUSBAR
518 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
520 return wxFrameBase::ShowFullScreen(show
, style
);
523 // ----------------------------------------------------------------------------
524 // tool/status bar stuff
525 // ----------------------------------------------------------------------------
529 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
531 #if defined(WINCE_WITHOUT_COMMANDBAR)
532 // We may already have a toolbar from calling SetMenuBar.
536 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
541 return m_frameToolBar
;
544 void wxFrame::PositionToolBar()
546 wxToolBar
*toolbar
= GetToolBar();
547 if ( toolbar
&& toolbar
->IsShown() )
549 #if defined(WINCE_WITHOUT_COMMANDBAR)
550 // We want to do something different in WinCE, because
551 // the toolbar should be associated with the commandbar,
552 // and not an independent window.
555 // don't call our (or even wxTopLevelWindow) version because we want
556 // the real (full) client area size, not excluding the tool/status bar
558 wxWindow::DoGetClientSize(&width
, &height
);
561 wxStatusBar
*statbar
= GetStatusBar();
562 if ( statbar
&& statbar
->IsShown() )
564 height
-= statbar
->GetClientSize().y
;
566 #endif // wxUSE_STATUSBAR
570 #if defined(WINCE_WITH_COMMANDBAR)
571 // We're using a commandbar - so we have to allow for it.
572 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
575 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
576 y
= rect
.bottom
- rect
.top
;
582 toolbar
->GetPosition(&tx
, &ty
);
583 toolbar
->GetSize(&tw
, &th
);
586 if (ty
< 0 && (-ty
== th
))
588 if (tx
< 0 && (-tx
== tw
))
594 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
601 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
605 // use the 'real' MSW position here, don't offset relativly to the
606 // client area origin
608 // Optimise such that we don't have to always resize the toolbar
609 // when the frame changes, otherwise we'll get a lot of flicker.
610 bool heightChanging
wxDUMMY_INITIALIZE(true);
611 bool widthChanging
wxDUMMY_INITIALIZE(true);
613 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
615 // It's OK if the current height is greater than what can be shown.
616 heightChanging
= (desiredH
> th
) ;
617 widthChanging
= (desiredW
!= tw
) ;
619 // The next time around, we may not have to set the size
621 desiredH
= desiredH
+ 200;
625 // It's OK if the current width is greater than what can be shown.
626 widthChanging
= (desiredW
> tw
) ;
627 heightChanging
= (desiredH
!= th
) ;
629 // The next time around, we may not have to set the size
631 desiredW
= desiredW
+ 200;
634 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
635 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
637 #endif // __WXWINCE__
641 #endif // wxUSE_TOOLBAR
643 // ----------------------------------------------------------------------------
644 // frame state (iconized/maximized/...)
645 // ----------------------------------------------------------------------------
647 // propagate our state change to all child frames: this allows us to emulate X
648 // Windows behaviour where child frames float independently of the parent one
649 // on the desktop, but are iconized/restored with it
650 void wxFrame::IconizeChildFrames(bool bIconize
)
652 m_iconized
= bIconize
;
654 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
656 node
= node
->GetNext() )
658 wxWindow
*win
= node
->GetData();
660 // iconizing the frames with this style under Win95 shell puts them at
661 // the bottom of the screen (as the MDI children) instead of making
662 // them appear in the taskbar because they are, by virtue of this
663 // style, not managed by the taskbar - instead leave Windows take care
666 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
670 // the child MDI frames are a special case and should not be touched by
671 // the parent frame - instead, they are managed by the user
672 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
674 #if wxUSE_MDI_ARCHITECTURE
676 #endif // wxUSE_MDI_ARCHITECTURE
679 // we don't want to restore the child frames which had been
680 // iconized even before we were iconized, so save the child frame
681 // status when iconizing the parent frame and check it when
685 frame
->m_wasMinimized
= frame
->IsIconized();
688 // note that we shouldn't touch the hidden frames neither because
689 // iconizing/restoring them would show them as a side effect
690 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
691 frame
->Iconize(bIconize
);
696 WXHICON
wxFrame::GetDefaultIcon() const
698 // we don't have any standard icons (any more)
702 // ===========================================================================
703 // message processing
704 // ===========================================================================
706 // ---------------------------------------------------------------------------
708 // ---------------------------------------------------------------------------
710 bool wxFrame::MSWTranslateMessage(WXMSG
* pMsg
)
712 if ( wxWindow::MSWTranslateMessage(pMsg
) )
715 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
716 // try the menu bar accels
717 wxMenuBar
*menuBar
= GetMenuBar();
721 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
722 return acceleratorTable
.Translate(this, pMsg
);
725 #endif // wxUSE_MENUS && wxUSE_ACCEL
728 // ---------------------------------------------------------------------------
729 // our private (non virtual) message handlers
730 // ---------------------------------------------------------------------------
732 bool wxFrame::HandlePaint()
735 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
737 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
740 const wxIcon
& icon
= GetIcon();
741 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
742 : (HICON
)GetDefaultIcon();
744 // Hold a pointer to the dc so long as the OnPaint() message
745 // is being processed
747 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
749 // Erase background before painting or we get white background
750 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
755 ::GetClientRect(GetHwnd(), &rect
);
757 // FIXME: why hardcoded?
758 static const int icon_width
= 32;
759 static const int icon_height
= 32;
761 int icon_x
= (int)((rect
.right
- icon_width
)/2);
762 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
764 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
767 ::EndPaint(GetHwnd(), &ps
);
774 return wxWindow::HandlePaint();
779 // nothing to paint - processed
784 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
786 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
791 // only do it it if we were iconized before, otherwise resizing the
792 // parent frame has a curious side effect of bringing it under it's
797 // restore all child frames too
798 IconizeChildFrames(false);
800 (void)SendIconizeEvent(false);
804 // iconize all child frames too
805 IconizeChildFrames(true);
810 #endif // !__WXWINCE__
816 #endif // wxUSE_STATUSBAR
820 #endif // wxUSE_TOOLBAR
822 #if defined(WINCE_WITH_COMMANDBAR)
823 // Position the menu command bar
824 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
827 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
828 wxSize clientSz
= GetClientSize();
830 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
832 wxLogLastError(wxT("MoveWindow"));
836 #endif // WINCE_WITH_COMMANDBAR
839 // call the base class version to generate the appropriate events
843 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
847 // In case it's e.g. a toolbar.
848 wxWindow
*win
= wxFindWinFromHandle(control
);
850 return win
->MSWCommand(cmd
, id
);
853 // handle here commands from menus and accelerators
854 if ( cmd
== 0 || cmd
== 1 )
856 #if wxUSE_MENUS_NATIVE
857 if ( wxCurrentPopupMenu
)
859 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
860 wxCurrentPopupMenu
= NULL
;
862 return popupMenu
->MSWCommand(cmd
, id
);
864 #endif // wxUSE_MENUS_NATIVE
866 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
867 // handle here commands from Smartphone menu bar
868 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
872 #endif // __SMARTPHONE__ && __WXWINCE__
874 if ( ProcessCommand(id
) )
883 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
886 if ( flags
== 0xFFFF && hMenu
== 0 )
888 // menu was removed from screen
891 #ifndef __WXMICROWIN__
892 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
899 // don't give hints for separators (doesn't make sense) nor for the
900 // items opening popup menus (they don't have them anyhow) but do clear
901 // the status line - otherwise, we would be left with the help message
902 // for the previous item which doesn't apply any more
903 DoGiveHelp(wxEmptyString
, false);
908 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
909 event
.SetEventObject(this);
911 return GetEventHandler()->ProcessEvent(event
);
914 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
916 // we don't have the menu id here, so we use the id to specify if the event
917 // was from a popup menu or a normal one
918 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
919 event
.SetEventObject(this);
921 return GetEventHandler()->ProcessEvent(event
);
924 // ---------------------------------------------------------------------------
925 // the window proc for wxFrame
926 // ---------------------------------------------------------------------------
928 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
931 bool processed
= false;
936 // if we can't close, tell the system that we processed the
937 // message - otherwise it would close us
938 processed
= !Close();
942 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
949 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
952 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
957 processed
= HandlePaint();
960 case WM_INITMENUPOPUP
:
961 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
964 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
969 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
971 processed
= HandleMenuSelect(item
, flags
, hmenu
);
975 case WM_EXITMENULOOP
:
976 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
979 case WM_QUERYDRAGICON
:
981 const wxIcon
& icon
= GetIcon();
982 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
983 : (HICON
)GetDefaultIcon();
988 #endif // !__WXMICROWIN__
992 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
997 // handle WM_INITMENUPOPUP message
998 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1000 wxMenu
* menu
= NULL
;
1003 int nCount
= GetMenuBar()->GetMenuCount();
1004 for (int n
= 0; n
< nCount
; n
++)
1006 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1008 menu
= GetMenuBar()->GetMenu(n
);
1014 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1015 event
.SetEventObject(this);
1017 return GetEventHandler()->ProcessEvent(event
);
1020 // ----------------------------------------------------------------------------
1021 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1022 // from the client area, so the client area is what's really available for the
1024 // ----------------------------------------------------------------------------
1026 // get the origin of the client area in the client coordinates
1027 wxPoint
wxFrame::GetClientAreaOrigin() const
1029 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1031 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1032 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1033 wxToolBar
*toolbar
= GetToolBar();
1034 if ( toolbar
&& toolbar
->IsShown() )
1037 toolbar
->GetSize(&w
, &h
);
1039 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1048 #endif // wxUSE_TOOLBAR
1050 #if defined(WINCE_WITH_COMMANDBAR)
1051 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1054 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1055 pt
.y
+= (rect
.bottom
- rect
.top
);