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"
30 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/dcclient.h"
40 #include "wx/toolbar.h"
41 #include "wx/statusbr.h"
42 #include "wx/menuitem.h"
45 #include "wx/msw/private.h"
47 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
50 #include "wx/msw/winundef.h"
53 #include "wx/generic/statusbr.h"
55 #ifdef __WXUNIVERSAL__
56 #include "wx/univ/theme.h"
57 #include "wx/univ/colschem.h"
58 #endif // __WXUNIVERSAL__
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 #if wxUSE_MENUS_NATIVE
65 extern wxMenu
*wxCurrentPopupMenu
;
66 #endif // wxUSE_MENUS_NATIVE
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
73 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
76 #if wxUSE_EXTENDED_RTTI
77 WX_DEFINE_FLAGS( wxFrameStyle
)
79 wxBEGIN_FLAGS( wxFrameStyle
)
80 // new style border flags, we put them first to
81 // use them for streaming out
82 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
83 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
84 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
85 wxFLAGS_MEMBER(wxBORDER_RAISED
)
86 wxFLAGS_MEMBER(wxBORDER_STATIC
)
87 wxFLAGS_MEMBER(wxBORDER_NONE
)
89 // old style border flags
90 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
91 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
92 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
93 wxFLAGS_MEMBER(wxRAISED_BORDER
)
94 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
95 wxFLAGS_MEMBER(wxBORDER
)
97 // standard window styles
98 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
99 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
100 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
101 wxFLAGS_MEMBER(wxWANTS_CHARS
)
102 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
103 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
104 wxFLAGS_MEMBER(wxVSCROLL
)
105 wxFLAGS_MEMBER(wxHSCROLL
)
108 wxFLAGS_MEMBER(wxSTAY_ON_TOP
)
109 wxFLAGS_MEMBER(wxCAPTION
)
110 #if WXWIN_COMPATIBILITY_2_6
111 wxFLAGS_MEMBER(wxTHICK_FRAME
)
112 #endif // WXWIN_COMPATIBILITY_2_6
113 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
114 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
115 #if WXWIN_COMPATIBILITY_2_6
116 wxFLAGS_MEMBER(wxRESIZE_BOX
)
117 #endif // WXWIN_COMPATIBILITY_2_6
118 wxFLAGS_MEMBER(wxCLOSE_BOX
)
119 wxFLAGS_MEMBER(wxMAXIMIZE_BOX
)
120 wxFLAGS_MEMBER(wxMINIMIZE_BOX
)
122 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW
)
123 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT
)
125 wxFLAGS_MEMBER(wxFRAME_SHAPED
)
127 wxEND_FLAGS( wxFrameStyle
)
129 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame
, wxTopLevelWindow
,"wx/frame.h")
131 wxBEGIN_PROPERTIES_TABLE(wxFrame
)
132 wxEVENT_PROPERTY( Menu
, wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
)
134 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
135 wxPROPERTY_FLAGS( WindowStyle
, wxFrameStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
136 wxPROPERTY( MenuBar
, wxMenuBar
* , SetMenuBar
, GetMenuBar
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
137 wxEND_PROPERTIES_TABLE()
139 wxBEGIN_HANDLERS_TABLE(wxFrame
)
140 wxEND_HANDLERS_TABLE()
142 wxCONSTRUCTOR_6( wxFrame
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Title
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
145 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
148 // ============================================================================
150 // ============================================================================
152 // ----------------------------------------------------------------------------
153 // static class members
154 // ----------------------------------------------------------------------------
157 #if wxUSE_NATIVE_STATUSBAR
158 bool wxFrame::m_useNativeStatusBar
= true;
160 bool wxFrame::m_useNativeStatusBar
= false;
162 #endif // wxUSE_NATIVE_STATUSBAR
164 // ----------------------------------------------------------------------------
165 // creation/destruction
166 // ----------------------------------------------------------------------------
172 #endif // wxUSE_MENUS
178 m_wasMinimized
= false;
181 bool wxFrame::Create(wxWindow
*parent
,
183 const wxString
& title
,
187 const wxString
& name
)
189 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
192 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
194 #if defined(__SMARTPHONE__)
195 SetLeftMenu(wxID_EXIT
, _("Done"));
198 #if wxUSE_ACCEL && defined(__POCKETPC__)
199 // The guidelines state that Ctrl+Q should quit the app.
200 // Let's define an accelerator table to send wxID_EXIT.
201 wxAcceleratorEntry entries
[1];
202 entries
[0].Set(wxACCEL_CTRL
, 'Q', wxID_EXIT
);
203 wxAcceleratorTable
accel(1, entries
);
204 SetAcceleratorTable(accel
);
205 #endif // wxUSE_ACCEL && __POCKETPC__
212 m_isBeingDeleted
= true;
216 // ----------------------------------------------------------------------------
217 // wxFrame client size calculations
218 // ----------------------------------------------------------------------------
220 void wxFrame::DoSetClientSize(int width
, int height
)
222 // leave enough space for the status bar if we have (and show) it
224 wxStatusBar
*statbar
= GetStatusBar();
225 if ( statbar
&& statbar
->IsShown() )
227 height
+= statbar
->GetSize().y
;
229 #endif // wxUSE_STATUSBAR
231 // call GetClientAreaOrigin() to take the toolbar into account
232 wxPoint pt
= GetClientAreaOrigin();
237 wxToolBar
* const toolbar
= GetToolBar();
240 if ( toolbar
->HasFlag(wxTB_RIGHT
| wxTB_BOTTOM
) )
242 const wxSize sizeTB
= toolbar
->GetSize();
243 if ( toolbar
->HasFlag(wxTB_RIGHT
) )
248 //else: toolbar already taken into account by GetClientAreaOrigin()
250 #endif // wxUSE_TOOLBAR
252 wxTopLevelWindow::DoSetClientSize(width
, height
);
255 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
256 void wxFrame::DoGetClientSize(int *x
, int *y
) const
258 wxTopLevelWindow::DoGetClientSize(x
, y
);
260 // account for the possible toolbar
261 wxPoint pt
= GetClientAreaOrigin();
269 wxToolBar
* const toolbar
= GetToolBar();
272 if ( toolbar
->HasFlag(wxTB_RIGHT
| wxTB_BOTTOM
) )
274 const wxSize sizeTB
= toolbar
->GetSize();
275 if ( toolbar
->HasFlag(wxTB_RIGHT
) )
286 //else: toolbar already taken into account by GetClientAreaOrigin()
288 #endif // wxUSE_TOOLBAR
291 // adjust client area height to take the status bar into account
294 wxStatusBar
*statbar
= GetStatusBar();
295 if ( statbar
&& statbar
->IsShown() )
297 *y
-= statbar
->GetClientSize().y
;
300 #endif // wxUSE_STATUSBAR
303 // ----------------------------------------------------------------------------
304 // wxFrame: various geometry-related functions
305 // ----------------------------------------------------------------------------
307 void wxFrame::Raise()
309 ::SetForegroundWindow(GetHwnd());
312 // generate an artificial resize event
313 void wxFrame::SendSizeEvent(int flags
)
317 RECT r
= wxGetWindowRect(GetHwnd());
319 if ( flags
& wxSEND_EVENT_POST
)
321 ::PostMessage(GetHwnd(), WM_SIZE
,
322 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
323 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
327 ::SendMessage(GetHwnd(), WM_SIZE
,
328 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
329 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
335 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
338 const wxString
& name
)
340 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
342 #if wxUSE_NATIVE_STATUSBAR
343 if ( !UsesNativeStatusBar() )
345 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
350 statusBar
= new wxStatusBar(this, id
, style
, name
);
353 statusBar
->SetFieldsCount(number
);
358 void wxFrame::PositionStatusBar()
360 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
364 GetClientSize(&w
, &h
);
367 m_frameStatusBar
->GetSize(&sw
, &sh
);
371 wxToolBar
* const toolbar
= GetToolBar();
372 if ( toolbar
&& !toolbar
->HasFlag(wxTB_TOP
) )
374 const wxSize sizeTB
= toolbar
->GetSize();
376 if ( toolbar
->HasFlag(wxTB_LEFT
| wxTB_RIGHT
) )
378 if ( toolbar
->HasFlag(wxTB_LEFT
) )
385 // we need to position the status bar below the toolbar
389 //else: no adjustments necessary for the toolbar on top
390 #endif // wxUSE_TOOLBAR
392 // Since we wish the status bar to be directly under the client area,
393 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
394 m_frameStatusBar
->SetSize(x
, h
, w
, sh
);
397 #endif // wxUSE_STATUSBAR
399 #if wxUSE_MENUS_NATIVE
401 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
403 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
405 wxMenu
*autoMenu
= NULL
;
407 if( menubar
->GetMenuCount() == 1 )
409 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
410 SetRightMenu(wxID_ANY
, menubar
->GetMenuLabel(0), autoMenu
);
414 autoMenu
= new wxMenu
;
416 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
418 wxMenu
*item
= menubar
->GetMenu(n
);
419 wxString label
= menubar
->GetMenuLabel(n
);
420 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
421 autoMenu
->Append(wxID_ANY
, label
, new_item
);
424 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
427 #elif defined(WINCE_WITHOUT_COMMANDBAR)
430 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
431 wxDefaultPosition
, wxDefaultSize
,
432 wxBORDER_NONE
| wxTB_HORIZONTAL
,
433 wxToolBarNameStr
, menubar
);
435 menubar
->SetToolBar(toolBar
);
438 // When the main window is created using CW_USEDEFAULT the height of the
439 // menubar is not taken into account, so we resize it afterwards if a
440 // menubar is present
441 HWND hwndMenuBar
= SHFindMenuBar(GetHwnd());
445 ::GetWindowRect(hwndMenuBar
, &mbRect
);
446 const int menuHeight
= mbRect
.bottom
- mbRect
.top
;
449 ::GetWindowRect(GetHwnd(), &rc
);
450 // adjust for menu / titlebar height
451 rc
.bottom
-= (2*menuHeight
-1);
453 ::MoveWindow(Gethwnd(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
457 wxFrameBase::AttachMenuBar(menubar
);
461 // actually remove the menu from the frame
462 m_hMenu
= (WXHMENU
)0;
463 InternalSetMenuBar();
465 else // set new non NULL menu bar
467 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
468 // Can set a menubar several times.
469 if ( menubar
->GetHMenu() )
471 m_hMenu
= menubar
->GetHMenu();
475 m_hMenu
= menubar
->Create();
479 wxFAIL_MSG( _T("failed to create menu bar") );
484 InternalSetMenuBar();
488 void wxFrame::InternalSetMenuBar()
490 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
493 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
495 wxLogLastError(wxT("SetMenu"));
500 #endif // wxUSE_MENUS_NATIVE
502 // Responds to colour changes, and passes event on to children.
503 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
505 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
509 if ( m_frameStatusBar
)
511 wxSysColourChangedEvent event2
;
512 event2
.SetEventObject( m_frameStatusBar
);
513 m_frameStatusBar
->HandleWindowEvent(event2
);
515 #endif // wxUSE_STATUSBAR
517 // Propagate the event to the non-top-level children
518 wxWindow::OnSysColourChanged(event
);
521 // Pass true to show full screen, false to restore.
522 bool wxFrame::ShowFullScreen(bool show
, long style
)
524 // TODO-CE: add support for CE
525 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
526 if ( IsFullScreen() == show
)
531 // zap the toolbar, menubar, and statusbar if needed
533 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
535 wxToolBar
*theToolBar
= GetToolBar();
537 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
539 if ( theToolBar
->IsShown() )
541 theToolBar
->SetSize(wxDefaultCoord
,0);
542 theToolBar
->Show(false);
544 else // prevent it from being restored later
546 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
549 #endif // wxUSE_TOOLBAR
551 if (style
& wxFULLSCREEN_NOMENUBAR
)
552 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
555 wxStatusBar
*theStatusBar
= GetStatusBar();
557 // Save the number of fields in the statusbar
558 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
560 if ( theStatusBar
->IsShown() )
561 theStatusBar
->Show(false);
563 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
565 #endif // wxUSE_STATUSBAR
567 else // restore to normal
569 // restore the toolbar, menubar, and statusbar if we had hid them
571 wxToolBar
*theToolBar
= GetToolBar();
573 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
575 theToolBar
->Show(true);
577 #endif // wxUSE_TOOLBAR
580 if (m_fsStyle
& wxFULLSCREEN_NOMENUBAR
)
582 WXHMENU menu
= m_hMenu
;
584 #if wxUSE_MDI_ARCHITECTURE
585 wxMDIParentFrame
*frame
= wxDynamicCast(this, wxMDIParentFrame
);
588 wxMDIChildFrame
*child
= frame
->GetActiveChild();
591 menu
= child
->GetWinMenu();
594 #endif // wxUSE_MDI_ARCHITECTURE
598 ::SetMenu(GetHwnd(), (HMENU
)menu
);
601 #endif // wxUSE_MENUS
604 wxStatusBar
*theStatusBar
= GetStatusBar();
606 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
608 theStatusBar
->Show(true);
611 #endif // wxUSE_STATUSBAR
613 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
615 return wxFrameBase::ShowFullScreen(show
, style
);
618 // ----------------------------------------------------------------------------
619 // tool/status bar stuff
620 // ----------------------------------------------------------------------------
624 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
626 #if defined(WINCE_WITHOUT_COMMANDBAR)
627 // We may already have a toolbar from calling SetMenuBar.
631 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
636 return m_frameToolBar
;
639 void wxFrame::PositionToolBar()
641 // TODO: we want to do something different in WinCE, because the toolbar
642 // should be associated with the commandbar, instead of being
643 // independent window.
644 #if !defined(WINCE_WITHOUT_COMMANDBAR)
645 wxToolBar
*toolbar
= GetToolBar();
646 if ( toolbar
&& toolbar
->IsShown() )
648 // don't call our (or even wxTopLevelWindow) version because we want
649 // the real (full) client area size, not excluding the tool/status bar
651 wxWindow::DoGetClientSize(&width
, &height
);
654 wxStatusBar
*statbar
= GetStatusBar();
655 if ( statbar
&& statbar
->IsShown() )
657 height
-= statbar
->GetClientSize().y
;
659 #endif // wxUSE_STATUSBAR
662 toolbar
->GetPosition( &tx
, &ty
);
663 toolbar
->GetSize( &tw
, &th
);
666 if ( toolbar
->HasFlag(wxTB_BOTTOM
) )
671 else if ( toolbar
->HasFlag(wxTB_RIGHT
) )
682 #if defined(WINCE_WITH_COMMANDBAR)
683 // We're using a commandbar - so we have to allow for it.
684 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
687 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
688 y
= rect
.bottom
- rect
.top
;
690 #endif // WINCE_WITH_COMMANDBAR
692 if ( toolbar
->HasFlag(wxTB_BOTTOM
) )
694 if ( ty
< 0 && ( -ty
== th
) )
696 if ( tx
< 0 && (-tx
== tw
) )
699 else if ( toolbar
->HasFlag(wxTB_RIGHT
) )
701 if( ty
< 0 && ( -ty
== th
) )
703 if( tx
< 0 && ( -tx
== tw
) )
708 if (ty
< 0 && (-ty
== th
))
710 if (tx
< 0 && (-tx
== tw
))
717 if ( toolbar
->IsVertical() )
726 // use the 'real' MSW position here, don't offset relativly to the
727 // client area origin
729 // Optimise such that we don't have to always resize the toolbar
730 // when the frame changes, otherwise we'll get a lot of flicker.
731 bool heightChanging
wxDUMMY_INITIALIZE(true);
732 bool widthChanging
wxDUMMY_INITIALIZE(true);
734 if ( toolbar
->IsVertical() )
736 // It's OK if the current height is greater than what can be shown.
737 heightChanging
= (desiredH
> th
) ;
738 widthChanging
= (desiredW
!= tw
) ;
740 // The next time around, we may not have to set the size
742 desiredH
= desiredH
+ 200;
746 // It's OK if the current width is greater than what can be shown.
747 widthChanging
= (desiredW
> tw
) ;
748 heightChanging
= (desiredH
!= th
) ;
750 // The next time around, we may not have to set the size
752 desiredW
= desiredW
+ 200;
755 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
756 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
759 #endif // !WINCE_WITH_COMMANDBAR
762 #endif // wxUSE_TOOLBAR
764 // ----------------------------------------------------------------------------
765 // frame state (iconized/maximized/...)
766 // ----------------------------------------------------------------------------
768 // propagate our state change to all child frames: this allows us to emulate X
769 // Windows behaviour where child frames float independently of the parent one
770 // on the desktop, but are iconized/restored with it
771 void wxFrame::IconizeChildFrames(bool bIconize
)
773 m_iconized
= bIconize
;
775 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
777 node
= node
->GetNext() )
779 wxWindow
*win
= node
->GetData();
781 // iconizing the frames with this style under Win95 shell puts them at
782 // the bottom of the screen (as the MDI children) instead of making
783 // them appear in the taskbar because they are, by virtue of this
784 // style, not managed by the taskbar - instead leave Windows take care
786 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
789 // the child MDI frames are a special case and should not be touched by
790 // the parent frame - instead, they are managed by the user
791 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
793 #if wxUSE_MDI_ARCHITECTURE
794 && !frame
->IsMDIChild()
795 #endif // wxUSE_MDI_ARCHITECTURE
798 // we don't want to restore the child frames which had been
799 // iconized even before we were iconized, so save the child frame
800 // status when iconizing the parent frame and check it when
804 frame
->m_wasMinimized
= frame
->IsIconized();
807 // note that we shouldn't touch the hidden frames neither because
808 // iconizing/restoring them would show them as a side effect
809 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
810 frame
->Iconize(bIconize
);
815 WXHICON
wxFrame::GetDefaultIcon() const
817 // we don't have any standard icons (any more)
821 // ===========================================================================
822 // message processing
823 // ===========================================================================
825 // ---------------------------------------------------------------------------
827 // ---------------------------------------------------------------------------
829 bool wxFrame::MSWDoTranslateMessage(wxFrame
*frame
, WXMSG
*pMsg
)
831 if ( wxWindow::MSWTranslateMessage(pMsg
) )
834 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
835 // try the menu bar accelerators
836 wxMenuBar
*menuBar
= GetMenuBar();
837 if ( menuBar
&& menuBar
->GetAcceleratorTable()->Translate(frame
, pMsg
) )
839 #endif // wxUSE_MENUS && wxUSE_ACCEL
844 // ---------------------------------------------------------------------------
845 // our private (non virtual) message handlers
846 // ---------------------------------------------------------------------------
848 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
850 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
855 // only do it it if we were iconized before, otherwise resizing the
856 // parent frame has a curious side effect of bringing it under it's
861 // restore all child frames too
862 IconizeChildFrames(false);
864 (void)SendIconizeEvent(false);
868 // iconize all child frames too
869 IconizeChildFrames(true);
874 #endif // !__WXWINCE__
880 #endif // wxUSE_STATUSBAR
884 #endif // wxUSE_TOOLBAR
886 #if defined(WINCE_WITH_COMMANDBAR)
887 // Position the menu command bar
888 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
891 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
892 wxSize clientSz
= GetClientSize();
894 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
896 wxLogLastError(wxT("MoveWindow"));
900 #endif // WINCE_WITH_COMMANDBAR
903 // call the base class version to generate the appropriate events
907 bool wxFrame::HandleCommand(WXWORD id_
, WXWORD cmd
, WXHWND control
)
909 // we only need to handle the menu and accelerator commands from the items
910 // of our menu bar, base wxWindow class already handles the rest
911 if ( !control
&& (cmd
== 0 /* menu */ || cmd
== 1 /* accel */) )
913 #if wxUSE_MENUS_NATIVE
914 if ( !wxCurrentPopupMenu
)
915 #endif // wxUSE_MENUS_NATIVE
917 wxMenuBar
* const mbar
= GetMenuBar();
920 // sign extend to int from short before comparing with the
922 const int id
= (signed short)id_
;
924 wxMenuItem
* const mitem
= mbar
->FindItem(id
);
926 return ProcessCommand(mitem
);
931 return wxFrameBase::HandleCommand(id_
, cmd
, control
);;
936 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
939 if ( flags
== 0xFFFF && hMenu
== 0 )
941 // menu was removed from screen
944 #ifndef __WXMICROWIN__
945 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
952 // don't give hints for separators (doesn't make sense) nor for the
953 // items opening popup menus (they don't have them anyhow) but do clear
954 // the status line - otherwise, we would be left with the help message
955 // for the previous item which doesn't apply any more
956 DoGiveHelp(wxEmptyString
, true);
961 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
962 event
.SetEventObject(this);
964 return HandleWindowEvent(event
);
967 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
969 // we don't have the menu id here, so we use the id to specify if the event
970 // was from a popup menu or a normal one
971 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
972 event
.SetEventObject(this);
974 return HandleWindowEvent(event
);
977 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
982 int nCount
= GetMenuBar()->GetMenuCount();
983 for (int n
= 0; n
< nCount
; n
++)
985 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
987 menu
= GetMenuBar()->GetMenu(n
);
993 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
994 event
.SetEventObject(this);
996 return HandleWindowEvent(event
);
999 #endif // wxUSE_MENUS
1001 // ---------------------------------------------------------------------------
1002 // the window proc for wxFrame
1003 // ---------------------------------------------------------------------------
1005 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1008 bool processed
= false;
1013 // if we can't close, tell the system that we processed the
1014 // message - otherwise it would close us
1015 processed
= !Close();
1019 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1026 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1029 HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1031 // don't pass WM_COMMAND to the base class whether we processed
1032 // it or not because we did generate an event for it (our
1033 // HandleCommand() calls the base class version) and we must
1034 // not do it again or the handlers which skip the event would
1040 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1042 case WM_INITMENUPOPUP
:
1043 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
1050 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1052 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1056 case WM_EXITMENULOOP
:
1057 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
1059 #endif // wxUSE_MENUS
1061 case WM_QUERYDRAGICON
:
1063 const wxIcon
& icon
= GetIcon();
1064 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1065 : (HICON
)GetDefaultIcon();
1066 rc
= (WXLRESULT
)hIcon
;
1067 processed
= rc
!= 0;
1070 #endif // !__WXMICROWIN__
1074 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1079 // ----------------------------------------------------------------------------
1080 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1081 // from the client area, so the client area is what's really available for the
1083 // ----------------------------------------------------------------------------
1085 // get the origin of the client area in the client coordinates
1086 wxPoint
wxFrame::GetClientAreaOrigin() const
1088 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1090 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1091 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1092 wxToolBar
* const toolbar
= GetToolBar();
1093 if ( toolbar
&& toolbar
->IsShown() )
1095 const wxSize sizeTB
= toolbar
->GetSize();
1097 if ( toolbar
->HasFlag(wxTB_TOP
) )
1101 else if ( toolbar
->HasFlag(wxTB_LEFT
) )
1106 #endif // wxUSE_TOOLBAR
1108 #if defined(WINCE_WITH_COMMANDBAR)
1109 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1112 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1113 pt
.y
+= (rect
.bottom
- rect
.top
);