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__
217 // ----------------------------------------------------------------------------
218 // wxFrame client size calculations
219 // ----------------------------------------------------------------------------
221 void wxFrame::DoSetClientSize(int width
, int height
)
223 // leave enough space for the status bar if we have (and show) it
225 wxStatusBar
*statbar
= GetStatusBar();
226 if ( statbar
&& statbar
->IsShown() )
228 height
+= statbar
->GetSize().y
;
230 #endif // wxUSE_STATUSBAR
232 // call GetClientAreaOrigin() to take the toolbar into account
233 wxPoint pt
= GetClientAreaOrigin();
238 wxToolBar
* const toolbar
= GetToolBar();
241 if ( toolbar
->HasFlag(wxTB_RIGHT
| wxTB_BOTTOM
) )
243 const wxSize sizeTB
= toolbar
->GetSize();
244 if ( toolbar
->HasFlag(wxTB_RIGHT
) )
249 //else: toolbar already taken into account by GetClientAreaOrigin()
251 #endif // wxUSE_TOOLBAR
253 wxTopLevelWindow::DoSetClientSize(width
, height
);
256 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
257 void wxFrame::DoGetClientSize(int *x
, int *y
) const
259 wxTopLevelWindow::DoGetClientSize(x
, y
);
261 // account for the possible toolbar
262 wxPoint pt
= GetClientAreaOrigin();
270 wxToolBar
* const toolbar
= GetToolBar();
273 if ( toolbar
->HasFlag(wxTB_RIGHT
| wxTB_BOTTOM
) )
275 const wxSize sizeTB
= toolbar
->GetSize();
276 if ( toolbar
->HasFlag(wxTB_RIGHT
) )
287 //else: toolbar already taken into account by GetClientAreaOrigin()
289 #endif // wxUSE_TOOLBAR
292 // adjust client area height to take the status bar into account
295 wxStatusBar
*statbar
= GetStatusBar();
296 if ( statbar
&& statbar
->IsShown() )
298 *y
-= statbar
->GetClientSize().y
;
301 #endif // wxUSE_STATUSBAR
304 // ----------------------------------------------------------------------------
305 // wxFrame: various geometry-related functions
306 // ----------------------------------------------------------------------------
308 void wxFrame::Raise()
310 ::SetForegroundWindow(GetHwnd());
313 // generate an artificial resize event
314 void wxFrame::SendSizeEvent(int flags
)
318 RECT r
= wxGetWindowRect(GetHwnd());
320 if ( flags
& wxSEND_EVENT_POST
)
322 ::PostMessage(GetHwnd(), WM_SIZE
,
323 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
324 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
328 ::SendMessage(GetHwnd(), WM_SIZE
,
329 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
330 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
336 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
339 const wxString
& name
)
341 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
343 #if wxUSE_NATIVE_STATUSBAR
344 if ( !UsesNativeStatusBar() )
346 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
351 statusBar
= new wxStatusBar(this, id
, style
, name
);
354 statusBar
->SetFieldsCount(number
);
359 void wxFrame::PositionStatusBar()
361 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
365 GetClientSize(&w
, &h
);
368 m_frameStatusBar
->GetSize(&sw
, &sh
);
372 wxToolBar
* const toolbar
= GetToolBar();
373 if ( toolbar
&& !toolbar
->HasFlag(wxTB_TOP
) )
375 const wxSize sizeTB
= toolbar
->GetSize();
377 if ( toolbar
->HasFlag(wxTB_LEFT
| wxTB_RIGHT
) )
379 if ( toolbar
->HasFlag(wxTB_LEFT
) )
386 // we need to position the status bar below the toolbar
390 //else: no adjustments necessary for the toolbar on top
391 #endif // wxUSE_TOOLBAR
393 // Since we wish the status bar to be directly under the client area,
394 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
395 m_frameStatusBar
->SetSize(x
, h
, w
, sh
);
398 #endif // wxUSE_STATUSBAR
400 #if wxUSE_MENUS_NATIVE
402 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
404 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
406 wxMenu
*autoMenu
= NULL
;
408 if( menubar
->GetMenuCount() == 1 )
410 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
411 SetRightMenu(wxID_ANY
, menubar
->GetMenuLabel(0), autoMenu
);
415 autoMenu
= new wxMenu
;
417 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
419 wxMenu
*item
= menubar
->GetMenu(n
);
420 wxString label
= menubar
->GetMenuLabel(n
);
421 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
422 autoMenu
->Append(wxID_ANY
, label
, new_item
);
425 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
428 #elif defined(WINCE_WITHOUT_COMMANDBAR)
431 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
432 wxDefaultPosition
, wxDefaultSize
,
433 wxBORDER_NONE
| wxTB_HORIZONTAL
,
434 wxToolBarNameStr
, menubar
);
436 menubar
->SetToolBar(toolBar
);
439 // When the main window is created using CW_USEDEFAULT the height of the
440 // menubar is not taken into account, so we resize it afterwards if a
441 // menubar is present
442 HWND hwndMenuBar
= SHFindMenuBar(GetHwnd());
446 ::GetWindowRect(hwndMenuBar
, &mbRect
);
447 const int menuHeight
= mbRect
.bottom
- mbRect
.top
;
450 ::GetWindowRect(GetHwnd(), &rc
);
451 // adjust for menu / titlebar height
452 rc
.bottom
-= (2*menuHeight
-1);
454 ::MoveWindow(Gethwnd(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
458 wxFrameBase::AttachMenuBar(menubar
);
462 // actually remove the menu from the frame
463 m_hMenu
= (WXHMENU
)0;
464 InternalSetMenuBar();
466 else // set new non NULL menu bar
468 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
469 // Can set a menubar several times.
470 if ( menubar
->GetHMenu() )
472 m_hMenu
= menubar
->GetHMenu();
476 m_hMenu
= menubar
->Create();
480 wxFAIL_MSG( _T("failed to create menu bar") );
485 InternalSetMenuBar();
489 void wxFrame::InternalSetMenuBar()
491 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
494 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
496 wxLogLastError(wxT("SetMenu"));
501 #endif // wxUSE_MENUS_NATIVE
503 // Responds to colour changes, and passes event on to children.
504 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
506 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
510 if ( m_frameStatusBar
)
512 wxSysColourChangedEvent event2
;
513 event2
.SetEventObject( m_frameStatusBar
);
514 m_frameStatusBar
->HandleWindowEvent(event2
);
516 #endif // wxUSE_STATUSBAR
518 // Propagate the event to the non-top-level children
519 wxWindow::OnSysColourChanged(event
);
522 // Pass true to show full screen, false to restore.
523 bool wxFrame::ShowFullScreen(bool show
, long style
)
525 // TODO-CE: add support for CE
526 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
527 if ( IsFullScreen() == show
)
532 // zap the toolbar, menubar, and statusbar if needed
534 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
536 wxToolBar
*theToolBar
= GetToolBar();
538 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
540 if ( theToolBar
->IsShown() )
542 theToolBar
->SetSize(wxDefaultCoord
,0);
543 theToolBar
->Show(false);
545 else // prevent it from being restored later
547 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
550 #endif // wxUSE_TOOLBAR
552 if (style
& wxFULLSCREEN_NOMENUBAR
)
553 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
556 wxStatusBar
*theStatusBar
= GetStatusBar();
558 // Save the number of fields in the statusbar
559 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
561 if ( theStatusBar
->IsShown() )
562 theStatusBar
->Show(false);
564 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
566 #endif // wxUSE_STATUSBAR
568 else // restore to normal
570 // restore the toolbar, menubar, and statusbar if we had hid them
572 wxToolBar
*theToolBar
= GetToolBar();
574 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
576 theToolBar
->Show(true);
578 #endif // wxUSE_TOOLBAR
581 if (m_fsStyle
& wxFULLSCREEN_NOMENUBAR
)
583 WXHMENU menu
= m_hMenu
;
585 #if wxUSE_MDI_ARCHITECTURE
586 wxMDIParentFrame
*frame
= wxDynamicCast(this, wxMDIParentFrame
);
589 wxMDIChildFrame
*child
= frame
->GetActiveChild();
592 menu
= child
->GetWinMenu();
595 #endif // wxUSE_MDI_ARCHITECTURE
599 ::SetMenu(GetHwnd(), (HMENU
)menu
);
602 #endif // wxUSE_MENUS
605 wxStatusBar
*theStatusBar
= GetStatusBar();
607 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
609 theStatusBar
->Show(true);
612 #endif // wxUSE_STATUSBAR
614 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
616 return wxFrameBase::ShowFullScreen(show
, style
);
619 // ----------------------------------------------------------------------------
620 // tool/status bar stuff
621 // ----------------------------------------------------------------------------
625 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
627 #if defined(WINCE_WITHOUT_COMMANDBAR)
628 // We may already have a toolbar from calling SetMenuBar.
632 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
637 return m_frameToolBar
;
640 void wxFrame::PositionToolBar()
642 // TODO: we want to do something different in WinCE, because the toolbar
643 // should be associated with the commandbar, instead of being
644 // independent window.
645 #if !defined(WINCE_WITHOUT_COMMANDBAR)
646 wxToolBar
*toolbar
= GetToolBar();
647 if ( toolbar
&& toolbar
->IsShown() )
649 // don't call our (or even wxTopLevelWindow) version because we want
650 // the real (full) client area size, not excluding the tool/status bar
652 wxWindow::DoGetClientSize(&width
, &height
);
655 wxStatusBar
*statbar
= GetStatusBar();
656 if ( statbar
&& statbar
->IsShown() )
658 height
-= statbar
->GetClientSize().y
;
660 #endif // wxUSE_STATUSBAR
663 toolbar
->GetPosition( &tx
, &ty
);
664 toolbar
->GetSize( &tw
, &th
);
667 if ( toolbar
->HasFlag(wxTB_BOTTOM
) )
672 else if ( toolbar
->HasFlag(wxTB_RIGHT
) )
683 #if defined(WINCE_WITH_COMMANDBAR)
684 // We're using a commandbar - so we have to allow for it.
685 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
688 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
689 y
= rect
.bottom
- rect
.top
;
691 #endif // WINCE_WITH_COMMANDBAR
693 if ( toolbar
->HasFlag(wxTB_BOTTOM
) )
695 if ( ty
< 0 && ( -ty
== th
) )
697 if ( tx
< 0 && (-tx
== tw
) )
700 else if ( toolbar
->HasFlag(wxTB_RIGHT
) )
702 if( ty
< 0 && ( -ty
== th
) )
704 if( tx
< 0 && ( -tx
== tw
) )
709 if (ty
< 0 && (-ty
== th
))
711 if (tx
< 0 && (-tx
== tw
))
718 if ( toolbar
->IsVertical() )
727 // use the 'real' MSW position here, don't offset relativly to the
728 // client area origin
730 // Optimise such that we don't have to always resize the toolbar
731 // when the frame changes, otherwise we'll get a lot of flicker.
732 bool heightChanging
wxDUMMY_INITIALIZE(true);
733 bool widthChanging
wxDUMMY_INITIALIZE(true);
735 if ( toolbar
->IsVertical() )
737 // It's OK if the current height is greater than what can be shown.
738 heightChanging
= (desiredH
> th
) ;
739 widthChanging
= (desiredW
!= tw
) ;
741 // The next time around, we may not have to set the size
743 desiredH
= desiredH
+ 200;
747 // It's OK if the current width is greater than what can be shown.
748 widthChanging
= (desiredW
> tw
) ;
749 heightChanging
= (desiredH
!= th
) ;
751 // The next time around, we may not have to set the size
753 desiredW
= desiredW
+ 200;
756 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
757 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
760 #endif // !WINCE_WITH_COMMANDBAR
763 #endif // wxUSE_TOOLBAR
765 // ----------------------------------------------------------------------------
766 // frame state (iconized/maximized/...)
767 // ----------------------------------------------------------------------------
769 // propagate our state change to all child frames: this allows us to emulate X
770 // Windows behaviour where child frames float independently of the parent one
771 // on the desktop, but are iconized/restored with it
772 void wxFrame::IconizeChildFrames(bool bIconize
)
774 m_iconized
= bIconize
;
776 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
778 node
= node
->GetNext() )
780 wxWindow
*win
= node
->GetData();
782 // iconizing the frames with this style under Win95 shell puts them at
783 // the bottom of the screen (as the MDI children) instead of making
784 // them appear in the taskbar because they are, by virtue of this
785 // style, not managed by the taskbar - instead leave Windows take care
787 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
790 // the child MDI frames are a special case and should not be touched by
791 // the parent frame - instead, they are managed by the user
792 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
794 #if wxUSE_MDI_ARCHITECTURE
795 && !frame
->IsMDIChild()
796 #endif // wxUSE_MDI_ARCHITECTURE
799 // we don't want to restore the child frames which had been
800 // iconized even before we were iconized, so save the child frame
801 // status when iconizing the parent frame and check it when
805 frame
->m_wasMinimized
= frame
->IsIconized();
808 // note that we shouldn't touch the hidden frames neither because
809 // iconizing/restoring them would show them as a side effect
810 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
811 frame
->Iconize(bIconize
);
816 WXHICON
wxFrame::GetDefaultIcon() const
818 // we don't have any standard icons (any more)
822 // ===========================================================================
823 // message processing
824 // ===========================================================================
826 // ---------------------------------------------------------------------------
828 // ---------------------------------------------------------------------------
830 bool wxFrame::MSWDoTranslateMessage(wxFrame
*frame
, WXMSG
*pMsg
)
832 if ( wxWindow::MSWTranslateMessage(pMsg
) )
835 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
836 // try the menu bar accelerators
837 wxMenuBar
*menuBar
= GetMenuBar();
838 if ( menuBar
&& menuBar
->GetAcceleratorTable()->Translate(frame
, pMsg
) )
840 #endif // wxUSE_MENUS && wxUSE_ACCEL
845 // ---------------------------------------------------------------------------
846 // our private (non virtual) message handlers
847 // ---------------------------------------------------------------------------
849 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
851 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
856 // only do it it if we were iconized before, otherwise resizing the
857 // parent frame has a curious side effect of bringing it under it's
862 // restore all child frames too
863 IconizeChildFrames(false);
865 (void)SendIconizeEvent(false);
869 // iconize all child frames too
870 IconizeChildFrames(true);
875 #endif // !__WXWINCE__
881 #endif // wxUSE_STATUSBAR
885 #endif // wxUSE_TOOLBAR
887 #if defined(WINCE_WITH_COMMANDBAR)
888 // Position the menu command bar
889 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
892 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
893 wxSize clientSz
= GetClientSize();
895 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
897 wxLogLastError(wxT("MoveWindow"));
901 #endif // WINCE_WITH_COMMANDBAR
904 // call the base class version to generate the appropriate events
908 bool wxFrame::HandleCommand(WXWORD id_
, WXWORD cmd
, WXHWND control
)
910 // we only need to handle the menu and accelerator commands from the items
911 // of our menu bar, base wxWindow class already handles the rest
912 if ( !control
&& (cmd
== 0 /* menu */ || cmd
== 1 /* accel */) )
914 #if wxUSE_MENUS_NATIVE
915 if ( !wxCurrentPopupMenu
)
916 #endif // wxUSE_MENUS_NATIVE
918 wxMenuBar
* const mbar
= GetMenuBar();
921 // sign extend to int from short before comparing with the
923 const int id
= (signed short)id_
;
925 wxMenuItem
* const mitem
= mbar
->FindItem(id
);
927 return ProcessCommand(mitem
);
932 return wxFrameBase::HandleCommand(id_
, cmd
, control
);;
937 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
940 if ( flags
== 0xFFFF && hMenu
== 0 )
942 // menu was removed from screen
945 #ifndef __WXMICROWIN__
946 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
953 // don't give hints for separators (doesn't make sense) nor for the
954 // items opening popup menus (they don't have them anyhow) but do clear
955 // the status line - otherwise, we would be left with the help message
956 // for the previous item which doesn't apply any more
957 DoGiveHelp(wxEmptyString
, true);
962 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
963 event
.SetEventObject(this);
965 return HandleWindowEvent(event
);
968 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
970 // we don't have the menu id here, so we use the id to specify if the event
971 // was from a popup menu or a normal one
972 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
973 event
.SetEventObject(this);
975 return HandleWindowEvent(event
);
978 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
983 int nCount
= GetMenuBar()->GetMenuCount();
984 for (int n
= 0; n
< nCount
; n
++)
986 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
988 menu
= GetMenuBar()->GetMenu(n
);
994 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
995 event
.SetEventObject(this);
997 return HandleWindowEvent(event
);
1000 #endif // wxUSE_MENUS
1002 // ---------------------------------------------------------------------------
1003 // the window proc for wxFrame
1004 // ---------------------------------------------------------------------------
1006 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1009 bool processed
= false;
1014 // if we can't close, tell the system that we processed the
1015 // message - otherwise it would close us
1016 processed
= !Close();
1020 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1027 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1030 HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1032 // don't pass WM_COMMAND to the base class whether we processed
1033 // it or not because we did generate an event for it (our
1034 // HandleCommand() calls the base class version) and we must
1035 // not do it again or the handlers which skip the event would
1041 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1043 case WM_INITMENUPOPUP
:
1044 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
1051 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1053 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1057 case WM_EXITMENULOOP
:
1058 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
1060 #endif // wxUSE_MENUS
1062 case WM_QUERYDRAGICON
:
1064 const wxIcon
& icon
= GetIcon();
1065 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1066 : (HICON
)GetDefaultIcon();
1067 rc
= (WXLRESULT
)hIcon
;
1068 processed
= rc
!= 0;
1071 #endif // !__WXMICROWIN__
1075 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1080 // ----------------------------------------------------------------------------
1081 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1082 // from the client area, so the client area is what's really available for the
1084 // ----------------------------------------------------------------------------
1086 // get the origin of the client area in the client coordinates
1087 wxPoint
wxFrame::GetClientAreaOrigin() const
1089 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1091 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1092 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1093 wxToolBar
* const toolbar
= GetToolBar();
1094 if ( toolbar
&& toolbar
->IsShown() )
1096 const wxSize sizeTB
= toolbar
->GetSize();
1098 if ( toolbar
->HasFlag(wxTB_TOP
) )
1102 else if ( toolbar
->HasFlag(wxTB_LEFT
) )
1107 #endif // wxUSE_TOOLBAR
1109 #if defined(WINCE_WITH_COMMANDBAR)
1110 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1113 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1114 pt
.y
+= (rect
.bottom
- rect
.top
);