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__) && defined(__WXWINCE__)
197 SetLeftMenu(wxID_EXIT
, _("Done"));
205 m_isBeingDeleted
= true;
209 // ----------------------------------------------------------------------------
210 // wxFrame client size calculations
211 // ----------------------------------------------------------------------------
213 void wxFrame::DoSetClientSize(int width
, int height
)
215 // leave enough space for the status bar if we have (and show) it
217 wxStatusBar
*statbar
= GetStatusBar();
218 if ( statbar
&& statbar
->IsShown() )
220 height
+= statbar
->GetSize().y
;
222 #endif // wxUSE_STATUSBAR
224 // call GetClientAreaOrigin() to take the toolbar into account
225 wxPoint pt
= GetClientAreaOrigin();
229 wxTopLevelWindow::DoSetClientSize(width
, height
);
232 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
233 void wxFrame::DoGetClientSize(int *x
, int *y
) const
235 wxTopLevelWindow::DoGetClientSize(x
, y
);
237 // account for the possible toolbar
238 wxPoint pt
= GetClientAreaOrigin();
246 // adjust client area height to take the status bar into account
249 wxStatusBar
*statbar
= GetStatusBar();
250 if ( statbar
&& statbar
->IsShown() )
252 *y
-= statbar
->GetClientSize().y
;
255 #endif // wxUSE_STATUSBAR
258 // ----------------------------------------------------------------------------
259 // wxFrame: various geometry-related functions
260 // ----------------------------------------------------------------------------
262 void wxFrame::Raise()
264 ::SetForegroundWindow(GetHwnd());
267 // generate an artificial resize event
268 void wxFrame::SendSizeEvent()
272 RECT r
= wxGetWindowRect(GetHwnd());
274 (void)::PostMessage(GetHwnd(), WM_SIZE
,
275 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
276 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
281 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
284 const wxString
& name
)
286 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
288 #if wxUSE_NATIVE_STATUSBAR
289 if ( !UsesNativeStatusBar() )
291 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
296 statusBar
= new wxStatusBar(this, id
, style
, name
);
299 statusBar
->SetFieldsCount(number
);
304 void wxFrame::PositionStatusBar()
306 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
310 GetClientSize(&w
, &h
);
312 m_frameStatusBar
->GetSize(&sw
, &sh
);
314 // Since we wish the status bar to be directly under the client area,
315 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
316 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
318 #endif // wxUSE_STATUSBAR
320 #if wxUSE_MENUS_NATIVE
322 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
324 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
326 wxMenu
*autoMenu
= NULL
;
328 if( menubar
->GetMenuCount() == 1 )
330 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
331 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
335 autoMenu
= new wxMenu
;
337 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
339 wxMenu
*item
= menubar
->GetMenu(n
);
340 wxString label
= menubar
->GetLabelTop(n
);
341 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
342 autoMenu
->Append(wxID_ANY
, label
, new_item
);
345 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
348 #elif defined(WINCE_WITHOUT_COMMANDBAR)
351 wxToolBar
* toolBar
= new wxToolBar(this, wxID_ANY
,
352 wxDefaultPosition
, wxDefaultSize
,
353 wxBORDER_NONE
| wxTB_HORIZONTAL
,
354 wxToolBarNameStr
, menubar
);
356 menubar
->SetToolBar(toolBar
);
358 // Now adjust size for menu bar
361 //When the main window is created using CW_USEDEFAULT the height of the
362 // is created is not taken into account). So we resize the window after
363 // if a menubar is present
366 ::GetWindowRect((HWND
) GetHWND(), &rc
);
367 // adjust for menu / titlebar height
368 rc
.bottom
-= (2*menuHeight
-1);
370 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
374 wxFrameBase::AttachMenuBar(menubar
);
378 // actually remove the menu from the frame
379 m_hMenu
= (WXHMENU
)0;
380 InternalSetMenuBar();
382 else // set new non NULL menu bar
384 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
385 // Can set a menubar several times.
386 if ( menubar
->GetHMenu() )
388 m_hMenu
= menubar
->GetHMenu();
392 m_hMenu
= menubar
->Create();
396 wxFAIL_MSG( _T("failed to create menu bar") );
401 InternalSetMenuBar();
405 void wxFrame::InternalSetMenuBar()
407 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
410 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
412 wxLogLastError(wxT("SetMenu"));
417 #endif // wxUSE_MENUS_NATIVE
419 // Responds to colour changes, and passes event on to children.
420 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
422 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
426 if ( m_frameStatusBar
)
428 wxSysColourChangedEvent event2
;
429 event2
.SetEventObject( m_frameStatusBar
);
430 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
432 #endif // wxUSE_STATUSBAR
434 // Propagate the event to the non-top-level children
435 wxWindow::OnSysColourChanged(event
);
438 // Pass true to show full screen, false to restore.
439 bool wxFrame::ShowFullScreen(bool show
, long style
)
441 // TODO-CE: add support for CE
442 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
443 if ( IsFullScreen() == show
)
448 // zap the toolbar, menubar, and statusbar if needed
450 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
452 wxToolBar
*theToolBar
= GetToolBar();
454 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
456 if ( theToolBar
->IsShown() )
458 theToolBar
->SetSize(wxDefaultCoord
,0);
459 theToolBar
->Show(false);
461 else // prevent it from being restored later
463 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
466 #endif // wxUSE_TOOLBAR
468 if (style
& wxFULLSCREEN_NOMENUBAR
)
469 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
472 wxStatusBar
*theStatusBar
= GetStatusBar();
474 // Save the number of fields in the statusbar
475 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
477 if ( theStatusBar
->IsShown() )
478 theStatusBar
->Show(false);
480 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
482 #endif // wxUSE_STATUSBAR
484 else // restore to normal
486 // restore the toolbar, menubar, and statusbar if we had hid them
488 wxToolBar
*theToolBar
= GetToolBar();
490 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
492 theToolBar
->Show(true);
494 #endif // wxUSE_TOOLBAR
496 if ((m_fsStyle
& wxFULLSCREEN_NOMENUBAR
) && m_hMenu
)
497 ::SetMenu(GetHwnd(), (HMENU
)m_hMenu
);
500 wxStatusBar
*theStatusBar
= GetStatusBar();
502 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
504 theStatusBar
->Show(true);
507 #endif // wxUSE_STATUSBAR
509 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
511 return wxFrameBase::ShowFullScreen(show
, style
);
514 // ----------------------------------------------------------------------------
515 // tool/status bar stuff
516 // ----------------------------------------------------------------------------
520 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
522 #if defined(WINCE_WITHOUT_COMMANDBAR)
523 // We may already have a toolbar from calling SetMenuBar.
527 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
532 return m_frameToolBar
;
535 void wxFrame::PositionToolBar()
537 wxToolBar
*toolbar
= GetToolBar();
538 if ( toolbar
&& toolbar
->IsShown() )
540 #if defined(WINCE_WITHOUT_COMMANDBAR)
541 // We want to do something different in WinCE, because
542 // the toolbar should be associated with the commandbar,
543 // and not an independent window.
546 // don't call our (or even wxTopLevelWindow) version because we want
547 // the real (full) client area size, not excluding the tool/status bar
549 wxWindow::DoGetClientSize(&width
, &height
);
552 wxStatusBar
*statbar
= GetStatusBar();
553 if ( statbar
&& statbar
->IsShown() )
555 height
-= statbar
->GetClientSize().y
;
557 #endif // wxUSE_STATUSBAR
561 #if defined(WINCE_WITH_COMMANDBAR)
562 // We're using a commandbar - so we have to allow for it.
563 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
566 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
567 y
= rect
.bottom
- rect
.top
;
573 toolbar
->GetPosition(&tx
, &ty
);
574 toolbar
->GetSize(&tw
, &th
);
577 if (ty
< 0 && (-ty
== th
))
579 if (tx
< 0 && (-tx
== tw
))
585 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
592 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
596 // use the 'real' MSW position here, don't offset relativly to the
597 // client area origin
599 // Optimise such that we don't have to always resize the toolbar
600 // when the frame changes, otherwise we'll get a lot of flicker.
601 bool heightChanging
wxDUMMY_INITIALIZE(true);
602 bool widthChanging
wxDUMMY_INITIALIZE(true);
604 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
606 // It's OK if the current height is greater than what can be shown.
607 heightChanging
= (desiredH
> th
) ;
608 widthChanging
= (desiredW
!= tw
) ;
610 // The next time around, we may not have to set the size
612 desiredH
= desiredH
+ 200;
616 // It's OK if the current width is greater than what can be shown.
617 widthChanging
= (desiredW
> tw
) ;
618 heightChanging
= (desiredH
!= th
) ;
620 // The next time around, we may not have to set the size
622 desiredW
= desiredW
+ 200;
625 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
626 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
628 #endif // __WXWINCE__
632 #endif // wxUSE_TOOLBAR
634 // ----------------------------------------------------------------------------
635 // frame state (iconized/maximized/...)
636 // ----------------------------------------------------------------------------
638 // propagate our state change to all child frames: this allows us to emulate X
639 // Windows behaviour where child frames float independently of the parent one
640 // on the desktop, but are iconized/restored with it
641 void wxFrame::IconizeChildFrames(bool bIconize
)
643 m_iconized
= bIconize
;
645 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
647 node
= node
->GetNext() )
649 wxWindow
*win
= node
->GetData();
651 // iconizing the frames with this style under Win95 shell puts them at
652 // the bottom of the screen (as the MDI children) instead of making
653 // them appear in the taskbar because they are, by virtue of this
654 // style, not managed by the taskbar - instead leave Windows take care
657 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
661 // the child MDI frames are a special case and should not be touched by
662 // the parent frame - instead, they are managed by the user
663 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
665 #if wxUSE_MDI_ARCHITECTURE
666 && !wxDynamicCast(frame
, wxMDIChildFrame
)
667 #endif // wxUSE_MDI_ARCHITECTURE
670 // we don't want to restore the child frames which had been
671 // iconized even before we were iconized, so save the child frame
672 // status when iconizing the parent frame and check it when
676 frame
->m_wasMinimized
= frame
->IsIconized();
679 // note that we shouldn't touch the hidden frames neither because
680 // iconizing/restoring them would show them as a side effect
681 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
682 frame
->Iconize(bIconize
);
687 WXHICON
wxFrame::GetDefaultIcon() const
689 // we don't have any standard icons (any more)
693 // ===========================================================================
694 // message processing
695 // ===========================================================================
697 // ---------------------------------------------------------------------------
699 // ---------------------------------------------------------------------------
701 bool wxFrame::MSWTranslateMessage(WXMSG
* pMsg
)
703 if ( wxWindow::MSWTranslateMessage(pMsg
) )
706 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
707 // try the menu bar accels
708 wxMenuBar
*menuBar
= GetMenuBar();
712 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
713 return acceleratorTable
.Translate(this, pMsg
);
716 #endif // wxUSE_MENUS && wxUSE_ACCEL
719 // ---------------------------------------------------------------------------
720 // our private (non virtual) message handlers
721 // ---------------------------------------------------------------------------
723 bool wxFrame::HandlePaint()
726 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
728 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
731 const wxIcon
& icon
= GetIcon();
732 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
733 : (HICON
)GetDefaultIcon();
735 // Hold a pointer to the dc so long as the OnPaint() message
736 // is being processed
738 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
740 // Erase background before painting or we get white background
741 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
746 ::GetClientRect(GetHwnd(), &rect
);
748 // FIXME: why hardcoded?
749 static const int icon_width
= 32;
750 static const int icon_height
= 32;
752 int icon_x
= (int)((rect
.right
- icon_width
)/2);
753 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
755 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
758 ::EndPaint(GetHwnd(), &ps
);
765 return wxWindow::HandlePaint();
770 // nothing to paint - processed
775 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
777 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
782 // only do it it if we were iconized before, otherwise resizing the
783 // parent frame has a curious side effect of bringing it under it's
788 // restore all child frames too
789 IconizeChildFrames(false);
791 (void)SendIconizeEvent(false);
795 // iconize all child frames too
796 IconizeChildFrames(true);
801 #endif // !__WXWINCE__
807 #endif // wxUSE_STATUSBAR
811 #endif // wxUSE_TOOLBAR
813 #if defined(WINCE_WITH_COMMANDBAR)
814 // Position the menu command bar
815 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
818 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
819 wxSize clientSz
= GetClientSize();
821 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
823 wxLogLastError(wxT("MoveWindow"));
827 #endif // WINCE_WITH_COMMANDBAR
830 // call the base class version to generate the appropriate events
834 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
838 // In case it's e.g. a toolbar.
839 wxWindow
*win
= wxFindWinFromHandle(control
);
841 return win
->MSWCommand(cmd
, id
);
844 // handle here commands from menus and accelerators
845 if ( cmd
== 0 || cmd
== 1 )
847 #if wxUSE_MENUS_NATIVE
848 if ( wxCurrentPopupMenu
)
850 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
851 wxCurrentPopupMenu
= NULL
;
853 return popupMenu
->MSWCommand(cmd
, id
);
855 #endif // wxUSE_MENUS_NATIVE
857 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
858 // handle here commands from Smartphone menu bar
859 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
863 #endif // __SMARTPHONE__ && __WXWINCE__
865 if ( ProcessCommand(id
) )
874 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
877 if ( flags
== 0xFFFF && hMenu
== 0 )
879 // menu was removed from screen
882 #ifndef __WXMICROWIN__
883 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
890 // don't give hints for separators (doesn't make sense) nor for the
891 // items opening popup menus (they don't have them anyhow) but do clear
892 // the status line - otherwise, we would be left with the help message
893 // for the previous item which doesn't apply any more
894 DoGiveHelp(wxEmptyString
, false);
899 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
900 event
.SetEventObject(this);
902 return GetEventHandler()->ProcessEvent(event
);
905 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
907 // we don't have the menu id here, so we use the id to specify if the event
908 // was from a popup menu or a normal one
909 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
910 event
.SetEventObject(this);
912 return GetEventHandler()->ProcessEvent(event
);
915 // ---------------------------------------------------------------------------
916 // the window proc for wxFrame
917 // ---------------------------------------------------------------------------
919 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
922 bool processed
= false;
927 // if we can't close, tell the system that we processed the
928 // message - otherwise it would close us
929 processed
= !Close();
933 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
940 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
943 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
948 processed
= HandlePaint();
951 case WM_INITMENUPOPUP
:
952 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
955 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
960 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
962 processed
= HandleMenuSelect(item
, flags
, hmenu
);
966 case WM_EXITMENULOOP
:
967 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
970 case WM_QUERYDRAGICON
:
972 const wxIcon
& icon
= GetIcon();
973 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
974 : (HICON
)GetDefaultIcon();
979 #endif // !__WXMICROWIN__
983 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
988 // handle WM_INITMENUPOPUP message
989 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
994 int nCount
= GetMenuBar()->GetMenuCount();
995 for (int n
= 0; n
< nCount
; n
++)
997 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
999 menu
= GetMenuBar()->GetMenu(n
);
1005 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1006 event
.SetEventObject(this);
1008 return GetEventHandler()->ProcessEvent(event
);
1011 // ----------------------------------------------------------------------------
1012 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1013 // from the client area, so the client area is what's really available for the
1015 // ----------------------------------------------------------------------------
1017 // get the origin of the client area in the client coordinates
1018 wxPoint
wxFrame::GetClientAreaOrigin() const
1020 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1022 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1023 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1024 wxToolBar
*toolbar
= GetToolBar();
1025 if ( toolbar
&& toolbar
->IsShown() )
1028 toolbar
->GetSize(&w
, &h
);
1030 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1039 #endif // wxUSE_TOOLBAR
1041 #if defined(WINCE_WITH_COMMANDBAR)
1042 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1045 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1046 pt
.y
+= (rect
.bottom
- rect
.top
);