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"
43 #include "wx/msw/private.h"
45 // include <commctrl.h> "properly"
46 #include "wx/msw/wrapcctl.h"
48 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
51 #include "wx/msw/winundef.h"
54 #include "wx/generic/statusbr.h"
56 #include "wx/menuitem.h"
58 #ifdef __WXUNIVERSAL__
59 #include "wx/univ/theme.h"
60 #include "wx/univ/colschem.h"
61 #endif // __WXUNIVERSAL__
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 #if wxUSE_MENUS_NATIVE
68 extern wxMenu
*wxCurrentPopupMenu
;
69 #endif // wxUSE_MENUS_NATIVE
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
76 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
79 #if wxUSE_EXTENDED_RTTI
80 WX_DEFINE_FLAGS( wxFrameStyle
)
82 wxBEGIN_FLAGS( wxFrameStyle
)
83 // new style border flags, we put them first to
84 // use them for streaming out
85 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
86 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
87 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
88 wxFLAGS_MEMBER(wxBORDER_RAISED
)
89 wxFLAGS_MEMBER(wxBORDER_STATIC
)
90 wxFLAGS_MEMBER(wxBORDER_NONE
)
92 // old style border flags
93 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
94 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
95 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
96 wxFLAGS_MEMBER(wxRAISED_BORDER
)
97 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
98 wxFLAGS_MEMBER(wxBORDER
)
100 // standard window styles
101 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
102 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
103 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
104 wxFLAGS_MEMBER(wxWANTS_CHARS
)
105 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
106 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
107 wxFLAGS_MEMBER(wxVSCROLL
)
108 wxFLAGS_MEMBER(wxHSCROLL
)
111 wxFLAGS_MEMBER(wxSTAY_ON_TOP
)
112 wxFLAGS_MEMBER(wxCAPTION
)
113 #if WXWIN_COMPATIBILITY_2_6
114 wxFLAGS_MEMBER(wxTHICK_FRAME
)
115 #endif // WXWIN_COMPATIBILITY_2_6
116 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
117 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
118 #if WXWIN_COMPATIBILITY_2_6
119 wxFLAGS_MEMBER(wxRESIZE_BOX
)
120 #endif // WXWIN_COMPATIBILITY_2_6
121 wxFLAGS_MEMBER(wxCLOSE_BOX
)
122 wxFLAGS_MEMBER(wxMAXIMIZE_BOX
)
123 wxFLAGS_MEMBER(wxMINIMIZE_BOX
)
125 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW
)
126 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT
)
128 wxFLAGS_MEMBER(wxFRAME_SHAPED
)
130 wxEND_FLAGS( wxFrameStyle
)
132 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame
, wxTopLevelWindow
,"wx/frame.h")
134 wxBEGIN_PROPERTIES_TABLE(wxFrame
)
135 wxEVENT_PROPERTY( Menu
, wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
)
137 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
138 wxPROPERTY_FLAGS( WindowStyle
, wxFrameStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
139 wxPROPERTY( MenuBar
, wxMenuBar
* , SetMenuBar
, GetMenuBar
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
140 wxEND_PROPERTIES_TABLE()
142 wxBEGIN_HANDLERS_TABLE(wxFrame
)
143 wxEND_HANDLERS_TABLE()
145 wxCONSTRUCTOR_6( wxFrame
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Title
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
148 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
151 // ============================================================================
153 // ============================================================================
155 // ----------------------------------------------------------------------------
156 // static class members
157 // ----------------------------------------------------------------------------
160 #if wxUSE_NATIVE_STATUSBAR
161 bool wxFrame::m_useNativeStatusBar
= true;
163 bool wxFrame::m_useNativeStatusBar
= false;
165 #endif // wxUSE_NATIVE_STATUSBAR
167 // ----------------------------------------------------------------------------
168 // creation/destruction
169 // ----------------------------------------------------------------------------
175 #endif // wxUSE_MENUS
181 m_wasMinimized
= false;
184 bool wxFrame::Create(wxWindow
*parent
,
186 const wxString
& title
,
190 const wxString
& name
)
192 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
195 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
197 #if defined(__SMARTPHONE__)
198 SetLeftMenu(wxID_EXIT
, _("Done"));
201 #if wxUSE_ACCEL && defined(__POCKETPC__)
202 // The guidelines state that Ctrl+Q should quit the app.
203 // Let's define an accelerator table to send wxID_EXIT.
204 wxAcceleratorEntry entries
[1];
205 entries
[0].Set(wxACCEL_CTRL
, 'Q', wxID_EXIT
);
206 wxAcceleratorTable
accel(1, entries
);
207 SetAcceleratorTable(accel
);
208 #endif // wxUSE_ACCEL && __POCKETPC__
215 m_isBeingDeleted
= true;
219 // ----------------------------------------------------------------------------
220 // wxFrame client size calculations
221 // ----------------------------------------------------------------------------
223 void wxFrame::DoSetClientSize(int width
, int height
)
225 // leave enough space for the status bar if we have (and show) it
227 wxStatusBar
*statbar
= GetStatusBar();
228 if ( statbar
&& statbar
->IsShown() )
230 height
+= statbar
->GetSize().y
;
232 #endif // wxUSE_STATUSBAR
234 // call GetClientAreaOrigin() to take the toolbar into account
235 wxPoint pt
= GetClientAreaOrigin();
239 wxTopLevelWindow::DoSetClientSize(width
, height
);
242 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
243 void wxFrame::DoGetClientSize(int *x
, int *y
) const
245 wxTopLevelWindow::DoGetClientSize(x
, y
);
247 // account for the possible toolbar
248 wxPoint pt
= GetClientAreaOrigin();
256 // adjust client area height to take the status bar into account
259 wxStatusBar
*statbar
= GetStatusBar();
260 if ( statbar
&& statbar
->IsShown() )
262 *y
-= statbar
->GetClientSize().y
;
265 #endif // wxUSE_STATUSBAR
268 // ----------------------------------------------------------------------------
269 // wxFrame: various geometry-related functions
270 // ----------------------------------------------------------------------------
272 void wxFrame::Raise()
274 ::SetForegroundWindow(GetHwnd());
277 // generate an artificial resize event
278 void wxFrame::SendSizeEvent()
282 RECT r
= wxGetWindowRect(GetHwnd());
284 (void)::PostMessage(GetHwnd(), WM_SIZE
,
285 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
286 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
291 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
294 const wxString
& name
)
296 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
298 #if wxUSE_NATIVE_STATUSBAR
299 if ( !UsesNativeStatusBar() )
301 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
306 statusBar
= new wxStatusBar(this, id
, style
, name
);
309 statusBar
->SetFieldsCount(number
);
314 void wxFrame::PositionStatusBar()
316 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
320 GetClientSize(&w
, &h
);
322 m_frameStatusBar
->GetSize(&sw
, &sh
);
324 // Since we wish the status bar to be directly under the client area,
325 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
326 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
328 #endif // wxUSE_STATUSBAR
330 #if wxUSE_MENUS_NATIVE
332 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
334 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
336 wxMenu
*autoMenu
= NULL
;
338 if( menubar
->GetMenuCount() == 1 )
340 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
341 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
345 autoMenu
= new wxMenu
;
347 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
349 wxMenu
*item
= menubar
->GetMenu(n
);
350 wxString label
= menubar
->GetLabelTop(n
);
351 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
352 autoMenu
->Append(wxID_ANY
, label
, new_item
);
355 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
358 #elif defined(WINCE_WITHOUT_COMMANDBAR)
361 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
362 wxDefaultPosition
, wxDefaultSize
,
363 wxBORDER_NONE
| wxTB_HORIZONTAL
,
364 wxToolBarNameStr
, menubar
);
366 menubar
->SetToolBar(toolBar
);
368 // Now adjust size for menu bar
371 //When the main window is created using CW_USEDEFAULT the height of the
372 // is created is not taken into account). So we resize the window after
373 // if a menubar is present
376 ::GetWindowRect((HWND
) GetHWND(), &rc
);
377 // adjust for menu / titlebar height
378 rc
.bottom
-= (2*menuHeight
-1);
380 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
384 wxFrameBase::AttachMenuBar(menubar
);
388 // actually remove the menu from the frame
389 m_hMenu
= (WXHMENU
)0;
390 InternalSetMenuBar();
392 else // set new non NULL menu bar
394 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
395 // Can set a menubar several times.
396 if ( menubar
->GetHMenu() )
398 m_hMenu
= menubar
->GetHMenu();
402 m_hMenu
= menubar
->Create();
406 wxFAIL_MSG( _T("failed to create menu bar") );
411 InternalSetMenuBar();
415 void wxFrame::InternalSetMenuBar()
417 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
420 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
422 wxLogLastError(wxT("SetMenu"));
427 #endif // wxUSE_MENUS_NATIVE
429 // Responds to colour changes, and passes event on to children.
430 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
432 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
436 if ( m_frameStatusBar
)
438 wxSysColourChangedEvent event2
;
439 event2
.SetEventObject( m_frameStatusBar
);
440 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
442 #endif // wxUSE_STATUSBAR
444 // Propagate the event to the non-top-level children
445 wxWindow::OnSysColourChanged(event
);
448 // Pass true to show full screen, false to restore.
449 bool wxFrame::ShowFullScreen(bool show
, long style
)
451 // TODO-CE: add support for CE
452 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
453 if ( IsFullScreen() == show
)
458 // zap the toolbar, menubar, and statusbar if needed
460 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
462 wxToolBar
*theToolBar
= GetToolBar();
464 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
466 if ( theToolBar
->IsShown() )
468 theToolBar
->SetSize(wxDefaultCoord
,0);
469 theToolBar
->Show(false);
471 else // prevent it from being restored later
473 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
476 #endif // wxUSE_TOOLBAR
478 if (style
& wxFULLSCREEN_NOMENUBAR
)
479 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
482 wxStatusBar
*theStatusBar
= GetStatusBar();
484 // Save the number of fields in the statusbar
485 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
487 if ( theStatusBar
->IsShown() )
488 theStatusBar
->Show(false);
490 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
492 #endif // wxUSE_STATUSBAR
494 else // restore to normal
496 // restore the toolbar, menubar, and statusbar if we had hid them
498 wxToolBar
*theToolBar
= GetToolBar();
500 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
502 theToolBar
->Show(true);
504 #endif // wxUSE_TOOLBAR
506 if (m_fsStyle
& wxFULLSCREEN_NOMENUBAR
)
508 WXHMENU menu
= m_hMenu
;
510 #if wxUSE_MDI_ARCHITECTURE
511 wxMDIParentFrame
*frame
= wxDynamicCast(this, wxMDIParentFrame
);
514 wxMDIChildFrame
*child
= frame
->GetActiveChild();
517 menu
= child
->GetWinMenu();
520 #endif // wxUSE_MDI_ARCHITECTURE
524 ::SetMenu(GetHwnd(), (HMENU
)menu
);
529 wxStatusBar
*theStatusBar
= GetStatusBar();
531 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
533 theStatusBar
->Show(true);
536 #endif // wxUSE_STATUSBAR
538 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
540 return wxFrameBase::ShowFullScreen(show
, style
);
543 // ----------------------------------------------------------------------------
544 // tool/status bar stuff
545 // ----------------------------------------------------------------------------
549 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
551 #if defined(WINCE_WITHOUT_COMMANDBAR)
552 // We may already have a toolbar from calling SetMenuBar.
556 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
561 return m_frameToolBar
;
564 void wxFrame::PositionToolBar()
566 wxToolBar
*toolbar
= GetToolBar();
567 if ( toolbar
&& toolbar
->IsShown() )
569 #if defined(WINCE_WITHOUT_COMMANDBAR)
570 // We want to do something different in WinCE, because
571 // the toolbar should be associated with the commandbar,
572 // and not an independent window.
575 // don't call our (or even wxTopLevelWindow) version because we want
576 // the real (full) client area size, not excluding the tool/status bar
578 wxWindow::DoGetClientSize(&width
, &height
);
581 wxStatusBar
*statbar
= GetStatusBar();
582 if ( statbar
&& statbar
->IsShown() )
584 height
-= statbar
->GetClientSize().y
;
586 #endif // wxUSE_STATUSBAR
590 #if defined(WINCE_WITH_COMMANDBAR)
591 // We're using a commandbar - so we have to allow for it.
592 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
595 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
596 y
= rect
.bottom
- rect
.top
;
602 toolbar
->GetPosition(&tx
, &ty
);
603 toolbar
->GetSize(&tw
, &th
);
606 if (ty
< 0 && (-ty
== th
))
608 if (tx
< 0 && (-tx
== tw
))
614 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
621 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
625 // use the 'real' MSW position here, don't offset relativly to the
626 // client area origin
628 // Optimise such that we don't have to always resize the toolbar
629 // when the frame changes, otherwise we'll get a lot of flicker.
630 bool heightChanging
wxDUMMY_INITIALIZE(true);
631 bool widthChanging
wxDUMMY_INITIALIZE(true);
633 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
635 // It's OK if the current height is greater than what can be shown.
636 heightChanging
= (desiredH
> th
) ;
637 widthChanging
= (desiredW
!= tw
) ;
639 // The next time around, we may not have to set the size
641 desiredH
= desiredH
+ 200;
645 // It's OK if the current width is greater than what can be shown.
646 widthChanging
= (desiredW
> tw
) ;
647 heightChanging
= (desiredH
!= th
) ;
649 // The next time around, we may not have to set the size
651 desiredW
= desiredW
+ 200;
654 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
655 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
657 #endif // __WXWINCE__
661 #endif // wxUSE_TOOLBAR
663 // ----------------------------------------------------------------------------
664 // frame state (iconized/maximized/...)
665 // ----------------------------------------------------------------------------
667 // propagate our state change to all child frames: this allows us to emulate X
668 // Windows behaviour where child frames float independently of the parent one
669 // on the desktop, but are iconized/restored with it
670 void wxFrame::IconizeChildFrames(bool bIconize
)
672 m_iconized
= bIconize
;
674 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
676 node
= node
->GetNext() )
678 wxWindow
*win
= node
->GetData();
680 // iconizing the frames with this style under Win95 shell puts them at
681 // the bottom of the screen (as the MDI children) instead of making
682 // them appear in the taskbar because they are, by virtue of this
683 // style, not managed by the taskbar - instead leave Windows take care
685 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
688 // the child MDI frames are a special case and should not be touched by
689 // the parent frame - instead, they are managed by the user
690 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
692 #if wxUSE_MDI_ARCHITECTURE
693 && !frame
->IsMDIChild()
694 #endif // wxUSE_MDI_ARCHITECTURE
697 // we don't want to restore the child frames which had been
698 // iconized even before we were iconized, so save the child frame
699 // status when iconizing the parent frame and check it when
703 frame
->m_wasMinimized
= frame
->IsIconized();
706 // note that we shouldn't touch the hidden frames neither because
707 // iconizing/restoring them would show them as a side effect
708 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
709 frame
->Iconize(bIconize
);
714 WXHICON
wxFrame::GetDefaultIcon() const
716 // we don't have any standard icons (any more)
720 // ===========================================================================
721 // message processing
722 // ===========================================================================
724 // ---------------------------------------------------------------------------
726 // ---------------------------------------------------------------------------
728 bool wxFrame::MSWDoTranslateMessage(wxFrame
*frame
, WXMSG
*pMsg
)
730 if ( wxWindow::MSWTranslateMessage(pMsg
) )
733 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
734 // try the menu bar accels
735 wxMenuBar
*menuBar
= GetMenuBar();
738 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
739 return acceleratorTable
.Translate(frame
, pMsg
);
741 #endif // wxUSE_MENUS && wxUSE_ACCEL
746 // ---------------------------------------------------------------------------
747 // our private (non virtual) message handlers
748 // ---------------------------------------------------------------------------
750 bool wxFrame::HandlePaint()
753 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
755 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
758 const wxIcon
& icon
= GetIcon();
759 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
760 : (HICON
)GetDefaultIcon();
762 // Hold a pointer to the dc so long as the OnPaint() message
763 // is being processed
765 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
767 // Erase background before painting or we get white background
768 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
773 ::GetClientRect(GetHwnd(), &rect
);
775 // FIXME: why hardcoded?
776 static const int icon_width
= 32;
777 static const int icon_height
= 32;
779 int icon_x
= (int)((rect
.right
- icon_width
)/2);
780 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
782 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
785 ::EndPaint(GetHwnd(), &ps
);
792 return wxWindow::HandlePaint();
797 // nothing to paint - processed
802 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
804 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
809 // only do it it if we were iconized before, otherwise resizing the
810 // parent frame has a curious side effect of bringing it under it's
815 // restore all child frames too
816 IconizeChildFrames(false);
818 (void)SendIconizeEvent(false);
822 // iconize all child frames too
823 IconizeChildFrames(true);
828 #endif // !__WXWINCE__
834 #endif // wxUSE_STATUSBAR
838 #endif // wxUSE_TOOLBAR
840 #if defined(WINCE_WITH_COMMANDBAR)
841 // Position the menu command bar
842 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
845 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
846 wxSize clientSz
= GetClientSize();
848 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
850 wxLogLastError(wxT("MoveWindow"));
854 #endif // WINCE_WITH_COMMANDBAR
857 // call the base class version to generate the appropriate events
861 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
865 // In case it's e.g. a toolbar.
866 wxWindow
*win
= wxFindWinFromHandle(control
);
868 return win
->MSWCommand(cmd
, id
);
871 // handle here commands from menus and accelerators
872 if ( cmd
== 0 || cmd
== 1 )
874 #if wxUSE_MENUS_NATIVE
875 if ( wxCurrentPopupMenu
)
877 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
878 wxCurrentPopupMenu
= NULL
;
880 return popupMenu
->MSWCommand(cmd
, id
);
882 #endif // wxUSE_MENUS_NATIVE
884 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
885 // handle here commands from Smartphone menu bar
886 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
890 #endif // __SMARTPHONE__ && __WXWINCE__
892 if ( ProcessCommand(id
) )
901 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
904 if ( flags
== 0xFFFF && hMenu
== 0 )
906 // menu was removed from screen
909 #ifndef __WXMICROWIN__
910 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
917 // don't give hints for separators (doesn't make sense) nor for the
918 // items opening popup menus (they don't have them anyhow) but do clear
919 // the status line - otherwise, we would be left with the help message
920 // for the previous item which doesn't apply any more
921 DoGiveHelp(wxEmptyString
, false);
926 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
927 event
.SetEventObject(this);
929 return GetEventHandler()->ProcessEvent(event
);
932 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
934 // we don't have the menu id here, so we use the id to specify if the event
935 // was from a popup menu or a normal one
936 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
937 event
.SetEventObject(this);
939 return GetEventHandler()->ProcessEvent(event
);
942 // ---------------------------------------------------------------------------
943 // the window proc for wxFrame
944 // ---------------------------------------------------------------------------
946 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
949 bool processed
= false;
954 // if we can't close, tell the system that we processed the
955 // message - otherwise it would close us
956 processed
= !Close();
960 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
967 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
970 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
975 processed
= HandlePaint();
978 case WM_INITMENUPOPUP
:
979 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
982 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
987 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
989 processed
= HandleMenuSelect(item
, flags
, hmenu
);
993 case WM_EXITMENULOOP
:
994 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
997 case WM_QUERYDRAGICON
:
999 const wxIcon
& icon
= GetIcon();
1000 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1001 : (HICON
)GetDefaultIcon();
1003 processed
= rc
!= 0;
1006 #endif // !__WXMICROWIN__
1010 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1015 // handle WM_INITMENUPOPUP message
1016 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1018 wxMenu
* menu
= NULL
;
1021 int nCount
= GetMenuBar()->GetMenuCount();
1022 for (int n
= 0; n
< nCount
; n
++)
1024 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1026 menu
= GetMenuBar()->GetMenu(n
);
1032 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1033 event
.SetEventObject(this);
1035 return GetEventHandler()->ProcessEvent(event
);
1038 // ----------------------------------------------------------------------------
1039 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1040 // from the client area, so the client area is what's really available for the
1042 // ----------------------------------------------------------------------------
1044 // get the origin of the client area in the client coordinates
1045 wxPoint
wxFrame::GetClientAreaOrigin() const
1047 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1049 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1050 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1051 wxToolBar
*toolbar
= GetToolBar();
1052 if ( toolbar
&& toolbar
->IsShown() )
1055 toolbar
->GetSize(&w
, &h
);
1057 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1066 #endif // wxUSE_TOOLBAR
1068 #if defined(WINCE_WITH_COMMANDBAR)
1069 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1072 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1073 pt
.y
+= (rect
.bottom
- rect
.top
);