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"
42 #include "wx/msw/private.h"
44 // include <commctrl.h> "properly"
45 #include "wx/msw/wrapcctl.h"
47 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
50 #include "wx/msw/winundef.h"
54 #include "wx/statusbr.h"
55 #include "wx/generic/statusbr.h"
56 #endif // wxUSE_STATUSBAR
58 #include "wx/menuitem.h"
60 #ifdef __WXUNIVERSAL__
61 #include "wx/univ/theme.h"
62 #include "wx/univ/colschem.h"
63 #endif // __WXUNIVERSAL__
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 #if wxUSE_MENUS_NATIVE
70 extern wxMenu
*wxCurrentPopupMenu
;
71 #endif // wxUSE_MENUS_NATIVE
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
78 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
81 #if wxUSE_EXTENDED_RTTI
82 WX_DEFINE_FLAGS( wxFrameStyle
)
84 wxBEGIN_FLAGS( wxFrameStyle
)
85 // new style border flags, we put them first to
86 // use them for streaming out
87 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
88 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
89 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
90 wxFLAGS_MEMBER(wxBORDER_RAISED
)
91 wxFLAGS_MEMBER(wxBORDER_STATIC
)
92 wxFLAGS_MEMBER(wxBORDER_NONE
)
94 // old style border flags
95 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
96 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
97 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
98 wxFLAGS_MEMBER(wxRAISED_BORDER
)
99 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
100 wxFLAGS_MEMBER(wxBORDER
)
102 // standard window styles
103 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
104 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
105 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
106 wxFLAGS_MEMBER(wxWANTS_CHARS
)
107 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
108 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
109 wxFLAGS_MEMBER(wxVSCROLL
)
110 wxFLAGS_MEMBER(wxHSCROLL
)
113 wxFLAGS_MEMBER(wxSTAY_ON_TOP
)
114 wxFLAGS_MEMBER(wxCAPTION
)
115 #if WXWIN_COMPATIBILITY_2_6
116 wxFLAGS_MEMBER(wxTHICK_FRAME
)
117 #endif // WXWIN_COMPATIBILITY_2_6
118 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
119 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
120 #if WXWIN_COMPATIBILITY_2_6
121 wxFLAGS_MEMBER(wxRESIZE_BOX
)
122 #endif // WXWIN_COMPATIBILITY_2_6
123 wxFLAGS_MEMBER(wxCLOSE_BOX
)
124 wxFLAGS_MEMBER(wxMAXIMIZE_BOX
)
125 wxFLAGS_MEMBER(wxMINIMIZE_BOX
)
127 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW
)
128 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT
)
130 wxFLAGS_MEMBER(wxFRAME_SHAPED
)
132 wxEND_FLAGS( wxFrameStyle
)
134 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame
, wxTopLevelWindow
,"wx/frame.h")
136 wxBEGIN_PROPERTIES_TABLE(wxFrame
)
137 wxEVENT_PROPERTY( Menu
, wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
)
139 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
140 wxPROPERTY_FLAGS( WindowStyle
, wxFrameStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
141 wxPROPERTY( MenuBar
, wxMenuBar
* , SetMenuBar
, GetMenuBar
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
142 wxEND_PROPERTIES_TABLE()
144 wxBEGIN_HANDLERS_TABLE(wxFrame
)
145 wxEND_HANDLERS_TABLE()
147 wxCONSTRUCTOR_6( wxFrame
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Title
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
150 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
153 // ============================================================================
155 // ============================================================================
157 // ----------------------------------------------------------------------------
158 // static class members
159 // ----------------------------------------------------------------------------
162 #if wxUSE_NATIVE_STATUSBAR
163 bool wxFrame::m_useNativeStatusBar
= true;
165 bool wxFrame::m_useNativeStatusBar
= false;
167 #endif // wxUSE_NATIVE_STATUSBAR
169 // ----------------------------------------------------------------------------
170 // creation/destruction
171 // ----------------------------------------------------------------------------
177 #endif // wxUSE_MENUS
183 m_wasMinimized
= false;
186 bool wxFrame::Create(wxWindow
*parent
,
188 const wxString
& title
,
192 const wxString
& name
)
194 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
197 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
199 #if defined(__SMARTPHONE__)
200 SetLeftMenu(wxID_EXIT
, _("Done"));
203 #if wxUSE_ACCEL && defined(__POCKETPC__)
204 // The guidelines state that Ctrl+Q should quit the app.
205 // Let's define an accelerator table to send wxID_EXIT.
206 wxAcceleratorEntry entries
[1];
207 entries
[0].Set(wxACCEL_CTRL
, 'Q', wxID_EXIT
);
208 wxAcceleratorTable
accel(1, entries
);
209 SetAcceleratorTable(accel
);
210 #endif // wxUSE_ACCEL && __POCKETPC__
217 m_isBeingDeleted
= true;
221 // ----------------------------------------------------------------------------
222 // wxFrame client size calculations
223 // ----------------------------------------------------------------------------
225 void wxFrame::DoSetClientSize(int width
, int height
)
227 // leave enough space for the status bar if we have (and show) it
229 wxStatusBar
*statbar
= GetStatusBar();
230 if ( statbar
&& statbar
->IsShown() )
232 height
+= statbar
->GetSize().y
;
234 #endif // wxUSE_STATUSBAR
236 // call GetClientAreaOrigin() to take the toolbar into account
237 wxPoint pt
= GetClientAreaOrigin();
241 wxTopLevelWindow::DoSetClientSize(width
, height
);
244 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
245 void wxFrame::DoGetClientSize(int *x
, int *y
) const
247 wxTopLevelWindow::DoGetClientSize(x
, y
);
249 // account for the possible toolbar
250 wxPoint pt
= GetClientAreaOrigin();
258 // adjust client area height to take the status bar into account
261 wxStatusBar
*statbar
= GetStatusBar();
262 if ( statbar
&& statbar
->IsShown() )
264 *y
-= statbar
->GetClientSize().y
;
267 #endif // wxUSE_STATUSBAR
270 // ----------------------------------------------------------------------------
271 // wxFrame: various geometry-related functions
272 // ----------------------------------------------------------------------------
274 void wxFrame::Raise()
276 ::SetForegroundWindow(GetHwnd());
279 // generate an artificial resize event
280 void wxFrame::SendSizeEvent()
284 RECT r
= wxGetWindowRect(GetHwnd());
286 (void)::PostMessage(GetHwnd(), WM_SIZE
,
287 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
288 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
293 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
296 const wxString
& name
)
298 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
300 #if wxUSE_NATIVE_STATUSBAR
301 if ( !UsesNativeStatusBar() )
303 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
308 statusBar
= new wxStatusBar(this, id
, style
, name
);
311 statusBar
->SetFieldsCount(number
);
316 void wxFrame::PositionStatusBar()
318 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
322 GetClientSize(&w
, &h
);
324 m_frameStatusBar
->GetSize(&sw
, &sh
);
326 // Since we wish the status bar to be directly under the client area,
327 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
328 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
330 #endif // wxUSE_STATUSBAR
332 #if wxUSE_MENUS_NATIVE
334 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
336 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
338 wxMenu
*autoMenu
= NULL
;
340 if( menubar
->GetMenuCount() == 1 )
342 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
343 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
347 autoMenu
= new wxMenu
;
349 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
351 wxMenu
*item
= menubar
->GetMenu(n
);
352 wxString label
= menubar
->GetLabelTop(n
);
353 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
354 autoMenu
->Append(wxID_ANY
, label
, new_item
);
357 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
360 #elif defined(WINCE_WITHOUT_COMMANDBAR)
363 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
364 wxDefaultPosition
, wxDefaultSize
,
365 wxBORDER_NONE
| wxTB_HORIZONTAL
,
366 wxToolBarNameStr
, menubar
);
368 menubar
->SetToolBar(toolBar
);
370 // Now adjust size for menu bar
373 //When the main window is created using CW_USEDEFAULT the height of the
374 // is created is not taken into account). So we resize the window after
375 // if a menubar is present
378 ::GetWindowRect((HWND
) GetHWND(), &rc
);
379 // adjust for menu / titlebar height
380 rc
.bottom
-= (2*menuHeight
-1);
382 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
386 wxFrameBase::AttachMenuBar(menubar
);
390 // actually remove the menu from the frame
391 m_hMenu
= (WXHMENU
)0;
392 InternalSetMenuBar();
394 else // set new non NULL menu bar
396 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
397 // Can set a menubar several times.
398 if ( menubar
->GetHMenu() )
400 m_hMenu
= menubar
->GetHMenu();
404 m_hMenu
= menubar
->Create();
408 wxFAIL_MSG( _T("failed to create menu bar") );
413 InternalSetMenuBar();
417 void wxFrame::InternalSetMenuBar()
419 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
422 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
424 wxLogLastError(wxT("SetMenu"));
429 #endif // wxUSE_MENUS_NATIVE
431 // Responds to colour changes, and passes event on to children.
432 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
434 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
438 if ( m_frameStatusBar
)
440 wxSysColourChangedEvent event2
;
441 event2
.SetEventObject( m_frameStatusBar
);
442 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
444 #endif // wxUSE_STATUSBAR
446 // Propagate the event to the non-top-level children
447 wxWindow::OnSysColourChanged(event
);
450 // Pass true to show full screen, false to restore.
451 bool wxFrame::ShowFullScreen(bool show
, long style
)
453 // TODO-CE: add support for CE
454 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
455 if ( IsFullScreen() == show
)
460 // zap the toolbar, menubar, and statusbar if needed
462 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
464 wxToolBar
*theToolBar
= GetToolBar();
466 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
468 if ( theToolBar
->IsShown() )
470 theToolBar
->SetSize(wxDefaultCoord
,0);
471 theToolBar
->Show(false);
473 else // prevent it from being restored later
475 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
478 #endif // wxUSE_TOOLBAR
480 if (style
& wxFULLSCREEN_NOMENUBAR
)
481 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
484 wxStatusBar
*theStatusBar
= GetStatusBar();
486 // Save the number of fields in the statusbar
487 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
489 if ( theStatusBar
->IsShown() )
490 theStatusBar
->Show(false);
492 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
494 #endif // wxUSE_STATUSBAR
496 else // restore to normal
498 // restore the toolbar, menubar, and statusbar if we had hid them
500 wxToolBar
*theToolBar
= GetToolBar();
502 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
504 theToolBar
->Show(true);
506 #endif // wxUSE_TOOLBAR
508 if (m_fsStyle
& wxFULLSCREEN_NOMENUBAR
)
510 WXHMENU menu
= m_hMenu
;
512 #if wxUSE_MDI_ARCHITECTURE
513 wxMDIParentFrame
*frame
= wxDynamicCast(this, wxMDIParentFrame
);
516 wxMDIChildFrame
*child
= frame
->GetActiveChild();
519 menu
= child
->GetWinMenu();
522 #endif // wxUSE_MDI_ARCHITECTURE
526 ::SetMenu(GetHwnd(), (HMENU
)menu
);
531 wxStatusBar
*theStatusBar
= GetStatusBar();
533 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
535 theStatusBar
->Show(true);
538 #endif // wxUSE_STATUSBAR
540 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
542 return wxFrameBase::ShowFullScreen(show
, style
);
545 // ----------------------------------------------------------------------------
546 // tool/status bar stuff
547 // ----------------------------------------------------------------------------
551 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
553 #if defined(WINCE_WITHOUT_COMMANDBAR)
554 // We may already have a toolbar from calling SetMenuBar.
558 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
563 return m_frameToolBar
;
566 void wxFrame::PositionToolBar()
568 wxToolBar
*toolbar
= GetToolBar();
569 if ( toolbar
&& toolbar
->IsShown() )
571 #if defined(WINCE_WITHOUT_COMMANDBAR)
572 // We want to do something different in WinCE, because
573 // the toolbar should be associated with the commandbar,
574 // and not an independent window.
577 // don't call our (or even wxTopLevelWindow) version because we want
578 // the real (full) client area size, not excluding the tool/status bar
580 wxWindow::DoGetClientSize(&width
, &height
);
583 wxStatusBar
*statbar
= GetStatusBar();
584 if ( statbar
&& statbar
->IsShown() )
586 height
-= statbar
->GetClientSize().y
;
588 #endif // wxUSE_STATUSBAR
592 #if defined(WINCE_WITH_COMMANDBAR)
593 // We're using a commandbar - so we have to allow for it.
594 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
597 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
598 y
= rect
.bottom
- rect
.top
;
604 toolbar
->GetPosition(&tx
, &ty
);
605 toolbar
->GetSize(&tw
, &th
);
608 if (ty
< 0 && (-ty
== th
))
610 if (tx
< 0 && (-tx
== tw
))
616 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
623 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
627 // use the 'real' MSW position here, don't offset relativly to the
628 // client area origin
630 // Optimise such that we don't have to always resize the toolbar
631 // when the frame changes, otherwise we'll get a lot of flicker.
632 bool heightChanging
wxDUMMY_INITIALIZE(true);
633 bool widthChanging
wxDUMMY_INITIALIZE(true);
635 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
637 // It's OK if the current height is greater than what can be shown.
638 heightChanging
= (desiredH
> th
) ;
639 widthChanging
= (desiredW
!= tw
) ;
641 // The next time around, we may not have to set the size
643 desiredH
= desiredH
+ 200;
647 // It's OK if the current width is greater than what can be shown.
648 widthChanging
= (desiredW
> tw
) ;
649 heightChanging
= (desiredH
!= th
) ;
651 // The next time around, we may not have to set the size
653 desiredW
= desiredW
+ 200;
656 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
657 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
659 #endif // __WXWINCE__
663 #endif // wxUSE_TOOLBAR
665 // ----------------------------------------------------------------------------
666 // frame state (iconized/maximized/...)
667 // ----------------------------------------------------------------------------
669 // propagate our state change to all child frames: this allows us to emulate X
670 // Windows behaviour where child frames float independently of the parent one
671 // on the desktop, but are iconized/restored with it
672 void wxFrame::IconizeChildFrames(bool bIconize
)
674 m_iconized
= bIconize
;
676 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
678 node
= node
->GetNext() )
680 wxWindow
*win
= node
->GetData();
682 // iconizing the frames with this style under Win95 shell puts them at
683 // the bottom of the screen (as the MDI children) instead of making
684 // them appear in the taskbar because they are, by virtue of this
685 // style, not managed by the taskbar - instead leave Windows take care
687 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
690 // the child MDI frames are a special case and should not be touched by
691 // the parent frame - instead, they are managed by the user
692 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
694 #if wxUSE_MDI_ARCHITECTURE
695 && !frame
->IsMDIChild()
696 #endif // wxUSE_MDI_ARCHITECTURE
699 // we don't want to restore the child frames which had been
700 // iconized even before we were iconized, so save the child frame
701 // status when iconizing the parent frame and check it when
705 frame
->m_wasMinimized
= frame
->IsIconized();
708 // note that we shouldn't touch the hidden frames neither because
709 // iconizing/restoring them would show them as a side effect
710 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
711 frame
->Iconize(bIconize
);
716 WXHICON
wxFrame::GetDefaultIcon() const
718 // we don't have any standard icons (any more)
722 // ===========================================================================
723 // message processing
724 // ===========================================================================
726 // ---------------------------------------------------------------------------
728 // ---------------------------------------------------------------------------
730 bool wxFrame::MSWDoTranslateMessage(wxFrame
*frame
, WXMSG
*pMsg
)
732 if ( wxWindow::MSWTranslateMessage(pMsg
) )
735 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
736 // try the menu bar accels
737 wxMenuBar
*menuBar
= GetMenuBar();
740 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
741 return acceleratorTable
.Translate(frame
, pMsg
);
743 #endif // wxUSE_MENUS && wxUSE_ACCEL
748 // ---------------------------------------------------------------------------
749 // our private (non virtual) message handlers
750 // ---------------------------------------------------------------------------
752 bool wxFrame::HandlePaint()
755 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
757 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
760 const wxIcon
& icon
= GetIcon();
761 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
762 : (HICON
)GetDefaultIcon();
764 // Hold a pointer to the dc so long as the OnPaint() message
765 // is being processed
767 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
769 // Erase background before painting or we get white background
770 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
775 ::GetClientRect(GetHwnd(), &rect
);
777 // FIXME: why hardcoded?
778 static const int icon_width
= 32;
779 static const int icon_height
= 32;
781 int icon_x
= (int)((rect
.right
- icon_width
)/2);
782 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
784 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
787 ::EndPaint(GetHwnd(), &ps
);
794 return wxWindow::HandlePaint();
799 // nothing to paint - processed
804 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
806 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
811 // only do it it if we were iconized before, otherwise resizing the
812 // parent frame has a curious side effect of bringing it under it's
817 // restore all child frames too
818 IconizeChildFrames(false);
820 (void)SendIconizeEvent(false);
824 // iconize all child frames too
825 IconizeChildFrames(true);
830 #endif // !__WXWINCE__
836 #endif // wxUSE_STATUSBAR
840 #endif // wxUSE_TOOLBAR
842 #if defined(WINCE_WITH_COMMANDBAR)
843 // Position the menu command bar
844 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
847 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
848 wxSize clientSz
= GetClientSize();
850 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
852 wxLogLastError(wxT("MoveWindow"));
856 #endif // WINCE_WITH_COMMANDBAR
859 // call the base class version to generate the appropriate events
863 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
867 // In case it's e.g. a toolbar.
868 wxWindow
*win
= wxFindWinFromHandle(control
);
870 return win
->MSWCommand(cmd
, id
);
873 // handle here commands from menus and accelerators
874 if ( cmd
== 0 || cmd
== 1 )
876 #if wxUSE_MENUS_NATIVE
877 if ( wxCurrentPopupMenu
)
879 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
880 wxCurrentPopupMenu
= NULL
;
882 return popupMenu
->MSWCommand(cmd
, id
);
884 #endif // wxUSE_MENUS_NATIVE
886 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
887 // handle here commands from Smartphone menu bar
888 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
892 #endif // __SMARTPHONE__ && __WXWINCE__
894 if ( ProcessCommand(id
) )
903 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
906 if ( flags
== 0xFFFF && hMenu
== 0 )
908 // menu was removed from screen
911 #ifndef __WXMICROWIN__
912 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
919 // don't give hints for separators (doesn't make sense) nor for the
920 // items opening popup menus (they don't have them anyhow) but do clear
921 // the status line - otherwise, we would be left with the help message
922 // for the previous item which doesn't apply any more
923 DoGiveHelp(wxEmptyString
, false);
928 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
929 event
.SetEventObject(this);
931 return GetEventHandler()->ProcessEvent(event
);
934 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
936 // we don't have the menu id here, so we use the id to specify if the event
937 // was from a popup menu or a normal one
938 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
939 event
.SetEventObject(this);
941 return GetEventHandler()->ProcessEvent(event
);
944 // ---------------------------------------------------------------------------
945 // the window proc for wxFrame
946 // ---------------------------------------------------------------------------
948 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
951 bool processed
= false;
956 // if we can't close, tell the system that we processed the
957 // message - otherwise it would close us
958 processed
= !Close();
962 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
969 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
972 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
977 processed
= HandlePaint();
980 case WM_INITMENUPOPUP
:
981 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
984 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
989 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
991 processed
= HandleMenuSelect(item
, flags
, hmenu
);
995 case WM_EXITMENULOOP
:
996 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
999 case WM_QUERYDRAGICON
:
1001 const wxIcon
& icon
= GetIcon();
1002 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1003 : (HICON
)GetDefaultIcon();
1005 processed
= rc
!= 0;
1008 #endif // !__WXMICROWIN__
1012 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1017 // handle WM_INITMENUPOPUP message
1018 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1020 wxMenu
* menu
= NULL
;
1023 int nCount
= GetMenuBar()->GetMenuCount();
1024 for (int n
= 0; n
< nCount
; n
++)
1026 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1028 menu
= GetMenuBar()->GetMenu(n
);
1034 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1035 event
.SetEventObject(this);
1037 return GetEventHandler()->ProcessEvent(event
);
1040 // ----------------------------------------------------------------------------
1041 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1042 // from the client area, so the client area is what's really available for the
1044 // ----------------------------------------------------------------------------
1046 // get the origin of the client area in the client coordinates
1047 wxPoint
wxFrame::GetClientAreaOrigin() const
1049 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1051 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1052 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1053 wxToolBar
*toolbar
= GetToolBar();
1054 if ( toolbar
&& toolbar
->IsShown() )
1057 toolbar
->GetSize(&w
, &h
);
1059 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1068 #endif // wxUSE_TOOLBAR
1070 #if defined(WINCE_WITH_COMMANDBAR)
1071 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1074 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1075 pt
.y
+= (rect
.bottom
- rect
.top
);