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 // ----------------------------------------------------------------------------
176 // Data to save/restore when calling ShowFullScreen
177 m_fsStatusBarFields
= 0;
178 m_fsStatusBarHeight
= 0;
179 m_fsToolBarHeight
= 0;
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 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
197 #ifdef __SMARTPHONE__
198 SetLeftMenu(wxID_EXIT
, _("Done"));
206 m_isBeingDeleted
= true;
210 // ----------------------------------------------------------------------------
211 // wxFrame client size calculations
212 // ----------------------------------------------------------------------------
214 void wxFrame::DoSetClientSize(int width
, int height
)
216 // leave enough space for the status bar if we have (and show) it
218 wxStatusBar
*statbar
= GetStatusBar();
219 if ( statbar
&& statbar
->IsShown() )
221 height
+= statbar
->GetSize().y
;
223 #endif // wxUSE_STATUSBAR
225 // call GetClientAreaOrigin() to take the toolbar into account
226 wxPoint pt
= GetClientAreaOrigin();
230 wxTopLevelWindow::DoSetClientSize(width
, height
);
233 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
234 void wxFrame::DoGetClientSize(int *x
, int *y
) const
236 wxTopLevelWindow::DoGetClientSize(x
, y
);
238 // account for the possible toolbar
239 wxPoint pt
= GetClientAreaOrigin();
247 // adjust client area height to take the status bar into account
250 wxStatusBar
*statbar
= GetStatusBar();
251 if ( statbar
&& statbar
->IsShown() )
253 *y
-= statbar
->GetClientSize().y
;
256 #endif // wxUSE_STATUSBAR
259 // ----------------------------------------------------------------------------
260 // wxFrame: various geometry-related functions
261 // ----------------------------------------------------------------------------
263 void wxFrame::Raise()
265 ::SetForegroundWindow(GetHwnd());
268 // generate an artificial resize event
269 void wxFrame::SendSizeEvent()
273 RECT r
= wxGetWindowRect(GetHwnd());
275 (void)::PostMessage(GetHwnd(), WM_SIZE
,
276 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
277 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
282 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
285 const wxString
& name
)
287 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
289 #if wxUSE_NATIVE_STATUSBAR
290 if ( !UsesNativeStatusBar() )
292 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
297 statusBar
= new wxStatusBar(this, id
, style
, name
);
300 statusBar
->SetFieldsCount(number
);
305 void wxFrame::PositionStatusBar()
307 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
311 GetClientSize(&w
, &h
);
313 m_frameStatusBar
->GetSize(&sw
, &sh
);
315 // Since we wish the status bar to be directly under the client area,
316 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
317 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
319 #endif // wxUSE_STATUSBAR
321 #if wxUSE_MENUS_NATIVE
323 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
325 #if defined(__SMARTPHONE__)
327 wxMenu
*autoMenu
= NULL
;
329 if( menubar
->GetMenuCount() == 1 )
331 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
332 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
336 autoMenu
= new wxMenu
;
338 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
340 wxMenu
*item
= menubar
->GetMenu(n
);
341 wxString label
= menubar
->GetLabelTop(n
);
342 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
343 autoMenu
->Append(wxID_ANY
, label
, new_item
);
346 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
349 #elif defined(WINCE_WITHOUT_COMMANDBAR)
352 wxToolBar
* toolBar
= new wxToolBar(this, wxID_ANY
,
353 wxDefaultPosition
, wxDefaultSize
,
354 wxBORDER_NONE
| wxTB_HORIZONTAL
,
355 wxToolBarNameStr
, menubar
);
357 menubar
->SetToolBar(toolBar
);
359 // Now adjust size for menu bar
362 //When the main window is created using CW_USEDEFAULT the height of the
363 // is created is not taken into account). So we resize the window after
364 // if a menubar is present
367 ::GetWindowRect((HWND
) GetHWND(), &rc
);
368 // adjust for menu / titlebar height
369 rc
.bottom
-= (2*menuHeight
-1);
371 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
375 wxFrameBase::AttachMenuBar(menubar
);
379 // actually remove the menu from the frame
380 m_hMenu
= (WXHMENU
)0;
381 InternalSetMenuBar();
383 else // set new non NULL menu bar
385 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
386 // Can set a menubar several times.
387 if ( menubar
->GetHMenu() )
389 m_hMenu
= menubar
->GetHMenu();
393 m_hMenu
= menubar
->Create();
397 wxFAIL_MSG( _T("failed to create menu bar") );
402 InternalSetMenuBar();
406 void wxFrame::InternalSetMenuBar()
408 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
411 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
413 wxLogLastError(wxT("SetMenu"));
418 #endif // wxUSE_MENUS_NATIVE
420 // Responds to colour changes, and passes event on to children.
421 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
423 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
427 if ( m_frameStatusBar
)
429 wxSysColourChangedEvent event2
;
430 event2
.SetEventObject( m_frameStatusBar
);
431 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
433 #endif // wxUSE_STATUSBAR
435 // Propagate the event to the non-top-level children
436 wxWindow::OnSysColourChanged(event
);
439 // Pass true to show full screen, false to restore.
440 bool wxFrame::ShowFullScreen(bool show
, long style
)
442 if ( IsFullScreen() == show
)
449 #if defined(WINCE_WITH_COMMANDBAR)
450 // TODO: hide commandbar
452 wxToolBar
*theToolBar
= GetToolBar();
454 theToolBar
->GetSize(NULL
, &m_fsToolBarHeight
);
456 // zap the toolbar, menubar, and statusbar
458 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
460 theToolBar
->SetSize(wxDefaultCoord
,0);
461 theToolBar
->Show(false);
463 #endif // __WXWINCE__
464 #endif // wxUSE_TOOLBAR
466 #if defined(__WXMICROWIN__)
467 #elif defined(__WXWINCE__)
468 // TODO: make it work for WinCE
470 if (style
& wxFULLSCREEN_NOMENUBAR
)
471 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
475 wxStatusBar
*theStatusBar
= GetStatusBar();
477 theStatusBar
->GetSize(NULL
, &m_fsStatusBarHeight
);
479 // Save the number of fields in the statusbar
480 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
482 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
483 //SetStatusBar((wxStatusBar*) NULL);
484 //delete theStatusBar;
485 theStatusBar
->Show(false);
488 m_fsStatusBarFields
= 0;
489 #endif // wxUSE_STATUSBAR
494 #if defined(WINCE_WITHOUT_COMMANDBAR)
495 // TODO: show commandbar
497 wxToolBar
*theToolBar
= GetToolBar();
499 // restore the toolbar, menubar, and statusbar
500 if (theToolBar
&& (m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
))
502 theToolBar
->SetSize(wxDefaultCoord
, m_fsToolBarHeight
);
503 theToolBar
->Show(true);
505 #endif // __WXWINCE__
506 #endif // wxUSE_TOOLBAR
509 if ( m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
)
511 //CreateStatusBar(m_fsStatusBarFields);
514 GetStatusBar()->Show(true);
518 #endif // wxUSE_STATUSBAR
520 #if defined(__WXMICROWIN__)
521 #elif defined(__WXWINCE__)
522 // TODO: make it work for WinCE
524 if ((m_fsStyle
& wxFULLSCREEN_NOMENUBAR
) && (m_hMenu
!= 0))
525 SetMenu((HWND
)GetHWND(), (HMENU
)m_hMenu
);
529 return wxFrameBase::ShowFullScreen(show
, style
);
532 // ----------------------------------------------------------------------------
533 // tool/status bar stuff
534 // ----------------------------------------------------------------------------
538 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
540 #if defined(WINCE_WITHOUT_COMMANDBAR)
541 // We may already have a toolbar from calling SetMenuBar.
545 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
550 return m_frameToolBar
;
553 void wxFrame::PositionToolBar()
555 wxToolBar
*toolbar
= GetToolBar();
556 if ( toolbar
&& toolbar
->IsShown() )
558 #if defined(WINCE_WITHOUT_COMMANDBAR)
559 // We want to do something different in WinCE, because
560 // the toolbar should be associated with the commandbar,
561 // and not an independent window.
564 // don't call our (or even wxTopLevelWindow) version because we want
565 // the real (full) client area size, not excluding the tool/status bar
567 wxWindow::DoGetClientSize(&width
, &height
);
570 wxStatusBar
*statbar
= GetStatusBar();
571 if ( statbar
&& statbar
->IsShown() )
573 height
-= statbar
->GetClientSize().y
;
575 #endif // wxUSE_STATUSBAR
579 #if defined(WINCE_WITH_COMMANDBAR)
580 // We're using a commandbar - so we have to allow for it.
581 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
584 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
585 y
= rect
.bottom
- rect
.top
;
591 toolbar
->GetPosition(&tx
, &ty
);
592 toolbar
->GetSize(&tw
, &th
);
595 if (ty
< 0 && (-ty
== th
))
597 if (tx
< 0 && (-tx
== tw
))
603 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
610 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
614 // use the 'real' MSW position here, don't offset relativly to the
615 // client area origin
617 // Optimise such that we don't have to always resize the toolbar
618 // when the frame changes, otherwise we'll get a lot of flicker.
619 bool heightChanging
wxDUMMY_INITIALIZE(true);
620 bool widthChanging
wxDUMMY_INITIALIZE(true);
622 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
624 // It's OK if the current height is greater than what can be shown.
625 heightChanging
= (desiredH
> th
) ;
626 widthChanging
= (desiredW
!= tw
) ;
628 // The next time around, we may not have to set the size
630 desiredH
= desiredH
+ 200;
634 // It's OK if the current width is greater than what can be shown.
635 widthChanging
= (desiredW
> tw
) ;
636 heightChanging
= (desiredH
!= th
) ;
638 // The next time around, we may not have to set the size
640 desiredW
= desiredW
+ 200;
643 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
644 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
646 #endif // __WXWINCE__
650 #endif // wxUSE_TOOLBAR
652 // ----------------------------------------------------------------------------
653 // frame state (iconized/maximized/...)
654 // ----------------------------------------------------------------------------
656 // propagate our state change to all child frames: this allows us to emulate X
657 // Windows behaviour where child frames float independently of the parent one
658 // on the desktop, but are iconized/restored with it
659 void wxFrame::IconizeChildFrames(bool bIconize
)
661 m_iconized
= bIconize
;
663 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
665 node
= node
->GetNext() )
667 wxWindow
*win
= node
->GetData();
669 // iconizing the frames with this style under Win95 shell puts them at
670 // the bottom of the screen (as the MDI children) instead of making
671 // them appear in the taskbar because they are, by virtue of this
672 // style, not managed by the taskbar - instead leave Windows take care
675 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
679 // the child MDI frames are a special case and should not be touched by
680 // the parent frame - instead, they are managed by the user
681 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
683 #if wxUSE_MDI_ARCHITECTURE
684 && !wxDynamicCast(frame
, wxMDIChildFrame
)
685 #endif // wxUSE_MDI_ARCHITECTURE
688 // we don't want to restore the child frames which had been
689 // iconized even before we were iconized, so save the child frame
690 // status when iconizing the parent frame and check it when
694 frame
->m_wasMinimized
= frame
->IsIconized();
697 // note that we shouldn't touch the hidden frames neither because
698 // iconizing/restoring them would show them as a side effect
699 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
700 frame
->Iconize(bIconize
);
705 WXHICON
wxFrame::GetDefaultIcon() const
707 // we don't have any standard icons (any more)
711 // ===========================================================================
712 // message processing
713 // ===========================================================================
715 // ---------------------------------------------------------------------------
717 // ---------------------------------------------------------------------------
719 bool wxFrame::MSWTranslateMessage(WXMSG
* pMsg
)
721 if ( wxWindow::MSWTranslateMessage(pMsg
) )
724 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
725 // try the menu bar accels
726 wxMenuBar
*menuBar
= GetMenuBar();
730 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
731 return acceleratorTable
.Translate(this, pMsg
);
734 #endif // wxUSE_MENUS && wxUSE_ACCEL
737 // ---------------------------------------------------------------------------
738 // our private (non virtual) message handlers
739 // ---------------------------------------------------------------------------
741 bool wxFrame::HandlePaint()
744 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
746 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
749 const wxIcon
& icon
= GetIcon();
750 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
751 : (HICON
)GetDefaultIcon();
753 // Hold a pointer to the dc so long as the OnPaint() message
754 // is being processed
756 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
758 // Erase background before painting or we get white background
759 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
764 ::GetClientRect(GetHwnd(), &rect
);
766 // FIXME: why hardcoded?
767 static const int icon_width
= 32;
768 static const int icon_height
= 32;
770 int icon_x
= (int)((rect
.right
- icon_width
)/2);
771 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
773 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
776 ::EndPaint(GetHwnd(), &ps
);
783 return wxWindow::HandlePaint();
788 // nothing to paint - processed
793 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
795 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
800 // only do it it if we were iconized before, otherwise resizing the
801 // parent frame has a curious side effect of bringing it under it's
806 // restore all child frames too
807 IconizeChildFrames(false);
809 (void)SendIconizeEvent(false);
813 // iconize all child frames too
814 IconizeChildFrames(true);
819 #endif // !__WXWINCE__
825 #endif // wxUSE_STATUSBAR
829 #endif // wxUSE_TOOLBAR
831 #if defined(WINCE_WITH_COMMANDBAR)
832 // Position the menu command bar
833 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
836 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
837 wxSize clientSz
= GetClientSize();
839 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
841 wxLogLastError(wxT("MoveWindow"));
845 #endif // WINCE_WITH_COMMANDBAR
848 // call the base class version to generate the appropriate events
852 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
856 // In case it's e.g. a toolbar.
857 wxWindow
*win
= wxFindWinFromHandle(control
);
859 return win
->MSWCommand(cmd
, id
);
862 // handle here commands from menus and accelerators
863 if ( cmd
== 0 || cmd
== 1 )
865 #if wxUSE_MENUS_NATIVE
866 if ( wxCurrentPopupMenu
)
868 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
869 wxCurrentPopupMenu
= NULL
;
871 return popupMenu
->MSWCommand(cmd
, id
);
873 #endif // wxUSE_MENUS_NATIVE
875 #ifdef __SMARTPHONE__
876 // handle here commands from Smartphone menu bar
877 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
881 #endif // __SMARTPHONE__
883 if ( ProcessCommand(id
) )
892 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
895 if ( flags
== 0xFFFF && hMenu
== 0 )
897 // menu was removed from screen
900 #ifndef __WXMICROWIN__
901 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
908 // don't give hints for separators (doesn't make sense) nor for the
909 // items opening popup menus (they don't have them anyhow) but do clear
910 // the status line - otherwise, we would be left with the help message
911 // for the previous item which doesn't apply any more
912 DoGiveHelp(wxEmptyString
, false);
917 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
918 event
.SetEventObject(this);
920 return GetEventHandler()->ProcessEvent(event
);
923 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
925 // we don't have the menu id here, so we use the id to specify if the event
926 // was from a popup menu or a normal one
927 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
928 event
.SetEventObject(this);
930 return GetEventHandler()->ProcessEvent(event
);
933 // ---------------------------------------------------------------------------
934 // the window proc for wxFrame
935 // ---------------------------------------------------------------------------
937 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
940 bool processed
= false;
945 // if we can't close, tell the system that we processed the
946 // message - otherwise it would close us
947 processed
= !Close();
951 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
958 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
961 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
966 processed
= HandlePaint();
969 case WM_INITMENUPOPUP
:
970 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
973 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
978 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
980 processed
= HandleMenuSelect(item
, flags
, hmenu
);
984 case WM_EXITMENULOOP
:
985 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, wParam
);
988 case WM_QUERYDRAGICON
:
990 const wxIcon
& icon
= GetIcon();
991 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
992 : (HICON
)GetDefaultIcon();
997 #endif // !__WXMICROWIN__
1001 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1006 // handle WM_INITMENUPOPUP message
1007 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1009 wxMenu
* menu
= NULL
;
1012 int nCount
= GetMenuBar()->GetMenuCount();
1013 for (int n
= 0; n
< nCount
; n
++)
1015 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1017 menu
= GetMenuBar()->GetMenu(n
);
1023 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1024 event
.SetEventObject(this);
1026 return GetEventHandler()->ProcessEvent(event
);
1029 // ----------------------------------------------------------------------------
1030 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1031 // from the client area, so the client area is what's really available for the
1033 // ----------------------------------------------------------------------------
1035 // get the origin of the client area in the client coordinates
1036 wxPoint
wxFrame::GetClientAreaOrigin() const
1038 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1040 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1041 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1042 wxToolBar
*toolbar
= GetToolBar();
1043 if ( toolbar
&& toolbar
->IsShown() )
1046 toolbar
->GetSize(&w
, &h
);
1048 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1057 #endif // wxUSE_TOOLBAR
1059 #if defined(WINCE_WITH_COMMANDBAR)
1060 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1063 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1064 pt
.y
+= (rect
.bottom
- rect
.top
);