1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/frame.cpp
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/dcclient.h"
40 #include "wx/toolbar.h"
41 #include "wx/statusbr.h"
42 #include "wx/menuitem.h"
45 #include "wx/msw/private.h"
47 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
50 #include "wx/msw/winundef.h"
53 #include "wx/generic/statusbr.h"
55 #ifdef __WXUNIVERSAL__
56 #include "wx/univ/theme.h"
57 #include "wx/univ/colschem.h"
58 #endif // __WXUNIVERSAL__
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 #if wxUSE_MENUS_NATIVE
65 extern wxMenu
*wxCurrentPopupMenu
;
66 #endif // wxUSE_MENUS_NATIVE
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
73 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
76 #if wxUSE_EXTENDED_RTTI
77 WX_DEFINE_FLAGS( wxFrameStyle
)
79 wxBEGIN_FLAGS( wxFrameStyle
)
80 // new style border flags, we put them first to
81 // use them for streaming out
82 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
83 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
84 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
85 wxFLAGS_MEMBER(wxBORDER_RAISED
)
86 wxFLAGS_MEMBER(wxBORDER_STATIC
)
87 wxFLAGS_MEMBER(wxBORDER_NONE
)
89 // old style border flags
90 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
91 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
92 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
93 wxFLAGS_MEMBER(wxRAISED_BORDER
)
94 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
95 wxFLAGS_MEMBER(wxBORDER
)
97 // standard window styles
98 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
99 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
100 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
101 wxFLAGS_MEMBER(wxWANTS_CHARS
)
102 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
103 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
104 wxFLAGS_MEMBER(wxVSCROLL
)
105 wxFLAGS_MEMBER(wxHSCROLL
)
108 wxFLAGS_MEMBER(wxSTAY_ON_TOP
)
109 wxFLAGS_MEMBER(wxCAPTION
)
110 #if WXWIN_COMPATIBILITY_2_6
111 wxFLAGS_MEMBER(wxTHICK_FRAME
)
112 #endif // WXWIN_COMPATIBILITY_2_6
113 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
114 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
115 #if WXWIN_COMPATIBILITY_2_6
116 wxFLAGS_MEMBER(wxRESIZE_BOX
)
117 #endif // WXWIN_COMPATIBILITY_2_6
118 wxFLAGS_MEMBER(wxCLOSE_BOX
)
119 wxFLAGS_MEMBER(wxMAXIMIZE_BOX
)
120 wxFLAGS_MEMBER(wxMINIMIZE_BOX
)
122 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW
)
123 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT
)
125 wxFLAGS_MEMBER(wxFRAME_SHAPED
)
127 wxEND_FLAGS( wxFrameStyle
)
129 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame
, wxTopLevelWindow
,"wx/frame.h")
131 wxBEGIN_PROPERTIES_TABLE(wxFrame
)
132 wxEVENT_PROPERTY( Menu
, wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
)
134 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
135 wxPROPERTY_FLAGS( WindowStyle
, wxFrameStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
136 wxPROPERTY( MenuBar
, wxMenuBar
* , SetMenuBar
, GetMenuBar
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
137 wxEND_PROPERTIES_TABLE()
139 wxBEGIN_HANDLERS_TABLE(wxFrame
)
140 wxEND_HANDLERS_TABLE()
142 wxCONSTRUCTOR_6( wxFrame
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Title
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
145 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
148 // ============================================================================
150 // ============================================================================
152 // ----------------------------------------------------------------------------
153 // static class members
154 // ----------------------------------------------------------------------------
157 #if wxUSE_NATIVE_STATUSBAR
158 bool wxFrame::m_useNativeStatusBar
= true;
160 bool wxFrame::m_useNativeStatusBar
= false;
162 #endif // wxUSE_NATIVE_STATUSBAR
164 // ----------------------------------------------------------------------------
165 // creation/destruction
166 // ----------------------------------------------------------------------------
172 #endif // wxUSE_MENUS
178 m_wasMinimized
= false;
181 bool wxFrame::Create(wxWindow
*parent
,
183 const wxString
& title
,
187 const wxString
& name
)
189 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
192 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
194 #if defined(__SMARTPHONE__)
195 SetLeftMenu(wxID_EXIT
, _("Done"));
198 #if wxUSE_ACCEL && defined(__POCKETPC__)
199 // The guidelines state that Ctrl+Q should quit the app.
200 // Let's define an accelerator table to send wxID_EXIT.
201 wxAcceleratorEntry entries
[1];
202 entries
[0].Set(wxACCEL_CTRL
, 'Q', wxID_EXIT
);
203 wxAcceleratorTable
accel(1, entries
);
204 SetAcceleratorTable(accel
);
205 #endif // wxUSE_ACCEL && __POCKETPC__
212 m_isBeingDeleted
= true;
216 // ----------------------------------------------------------------------------
217 // wxFrame client size calculations
218 // ----------------------------------------------------------------------------
220 void wxFrame::DoSetClientSize(int width
, int height
)
222 // leave enough space for the status bar if we have (and show) it
224 wxStatusBar
*statbar
= GetStatusBar();
225 if ( statbar
&& statbar
->IsShown() )
227 height
+= statbar
->GetSize().y
;
229 #endif // wxUSE_STATUSBAR
231 // call GetClientAreaOrigin() to take the toolbar into account
232 wxPoint pt
= GetClientAreaOrigin();
237 wxToolBar
* const toolbar
= GetToolBar();
240 if ( toolbar
->HasFlag(wxTB_RIGHT
| wxTB_BOTTOM
) )
242 const wxSize sizeTB
= toolbar
->GetSize();
243 if ( toolbar
->HasFlag(wxTB_RIGHT
) )
248 //else: toolbar already taken into account by GetClientAreaOrigin()
250 #endif // wxUSE_TOOLBAR
252 wxTopLevelWindow::DoSetClientSize(width
, height
);
255 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
256 void wxFrame::DoGetClientSize(int *x
, int *y
) const
258 wxTopLevelWindow::DoGetClientSize(x
, y
);
260 // account for the possible toolbar
261 wxPoint pt
= GetClientAreaOrigin();
269 wxToolBar
* const toolbar
= GetToolBar();
272 if ( toolbar
->HasFlag(wxTB_RIGHT
| wxTB_BOTTOM
) )
274 const wxSize sizeTB
= toolbar
->GetSize();
275 if ( toolbar
->HasFlag(wxTB_RIGHT
) )
286 //else: toolbar already taken into account by GetClientAreaOrigin()
288 #endif // wxUSE_TOOLBAR
291 // adjust client area height to take the status bar into account
294 wxStatusBar
*statbar
= GetStatusBar();
295 if ( statbar
&& statbar
->IsShown() )
297 *y
-= statbar
->GetClientSize().y
;
300 #endif // wxUSE_STATUSBAR
303 // ----------------------------------------------------------------------------
304 // wxFrame: various geometry-related functions
305 // ----------------------------------------------------------------------------
307 void wxFrame::Raise()
309 ::SetForegroundWindow(GetHwnd());
312 // generate an artificial resize event
313 void wxFrame::SendSizeEvent()
317 RECT r
= wxGetWindowRect(GetHwnd());
319 (void)::PostMessage(GetHwnd(), WM_SIZE
,
320 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
321 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
326 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
329 const wxString
& name
)
331 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
333 #if wxUSE_NATIVE_STATUSBAR
334 if ( !UsesNativeStatusBar() )
336 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
341 statusBar
= new wxStatusBar(this, id
, style
, name
);
344 statusBar
->SetFieldsCount(number
);
349 void wxFrame::PositionStatusBar()
351 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
355 GetClientSize(&w
, &h
);
358 m_frameStatusBar
->GetSize(&sw
, &sh
);
362 wxToolBar
* const toolbar
= GetToolBar();
363 if ( toolbar
&& !toolbar
->HasFlag(wxTB_TOP
) )
365 const wxSize sizeTB
= toolbar
->GetSize();
367 if ( toolbar
->HasFlag(wxTB_LEFT
| wxTB_RIGHT
) )
369 if ( toolbar
->HasFlag(wxTB_LEFT
) )
376 // we need to position the status bar below the toolbar
380 //else: no adjustments necessary for the toolbar on top
381 #endif // wxUSE_TOOLBAR
383 // Since we wish the status bar to be directly under the client area,
384 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
385 m_frameStatusBar
->SetSize(x
, h
, w
, sh
);
388 #endif // wxUSE_STATUSBAR
390 #if wxUSE_MENUS_NATIVE
392 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
394 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
396 wxMenu
*autoMenu
= NULL
;
398 if( menubar
->GetMenuCount() == 1 )
400 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
401 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
405 autoMenu
= new wxMenu
;
407 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
409 wxMenu
*item
= menubar
->GetMenu(n
);
410 wxString label
= menubar
->GetLabelTop(n
);
411 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
412 autoMenu
->Append(wxID_ANY
, label
, new_item
);
415 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
418 #elif defined(WINCE_WITHOUT_COMMANDBAR)
421 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
422 wxDefaultPosition
, wxDefaultSize
,
423 wxBORDER_NONE
| wxTB_HORIZONTAL
,
424 wxToolBarNameStr
, menubar
);
426 menubar
->SetToolBar(toolBar
);
428 // Now adjust size for menu bar
431 //When the main window is created using CW_USEDEFAULT the height of the
432 // is created is not taken into account). So we resize the window after
433 // if a menubar is present
436 ::GetWindowRect((HWND
) GetHWND(), &rc
);
437 // adjust for menu / titlebar height
438 rc
.bottom
-= (2*menuHeight
-1);
440 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
444 wxFrameBase::AttachMenuBar(menubar
);
448 // actually remove the menu from the frame
449 m_hMenu
= (WXHMENU
)0;
450 InternalSetMenuBar();
452 else // set new non NULL menu bar
454 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
455 // Can set a menubar several times.
456 if ( menubar
->GetHMenu() )
458 m_hMenu
= menubar
->GetHMenu();
462 m_hMenu
= menubar
->Create();
466 wxFAIL_MSG( _T("failed to create menu bar") );
471 InternalSetMenuBar();
475 void wxFrame::InternalSetMenuBar()
477 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
480 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
482 wxLogLastError(wxT("SetMenu"));
487 #endif // wxUSE_MENUS_NATIVE
489 // Responds to colour changes, and passes event on to children.
490 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
492 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
496 if ( m_frameStatusBar
)
498 wxSysColourChangedEvent event2
;
499 event2
.SetEventObject( m_frameStatusBar
);
500 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
502 #endif // wxUSE_STATUSBAR
504 // Propagate the event to the non-top-level children
505 wxWindow::OnSysColourChanged(event
);
508 // Pass true to show full screen, false to restore.
509 bool wxFrame::ShowFullScreen(bool show
, long style
)
511 // TODO-CE: add support for CE
512 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
513 if ( IsFullScreen() == show
)
518 // zap the toolbar, menubar, and statusbar if needed
520 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
522 wxToolBar
*theToolBar
= GetToolBar();
524 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
526 if ( theToolBar
->IsShown() )
528 theToolBar
->SetSize(wxDefaultCoord
,0);
529 theToolBar
->Show(false);
531 else // prevent it from being restored later
533 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
536 #endif // wxUSE_TOOLBAR
538 if (style
& wxFULLSCREEN_NOMENUBAR
)
539 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
542 wxStatusBar
*theStatusBar
= GetStatusBar();
544 // Save the number of fields in the statusbar
545 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
547 if ( theStatusBar
->IsShown() )
548 theStatusBar
->Show(false);
550 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
552 #endif // wxUSE_STATUSBAR
554 else // restore to normal
556 // restore the toolbar, menubar, and statusbar if we had hid them
558 wxToolBar
*theToolBar
= GetToolBar();
560 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
562 theToolBar
->Show(true);
564 #endif // wxUSE_TOOLBAR
566 if (m_fsStyle
& wxFULLSCREEN_NOMENUBAR
)
568 WXHMENU menu
= m_hMenu
;
570 #if wxUSE_MDI_ARCHITECTURE
571 wxMDIParentFrame
*frame
= wxDynamicCast(this, wxMDIParentFrame
);
574 wxMDIChildFrame
*child
= frame
->GetActiveChild();
577 menu
= child
->GetWinMenu();
580 #endif // wxUSE_MDI_ARCHITECTURE
584 ::SetMenu(GetHwnd(), (HMENU
)menu
);
589 wxStatusBar
*theStatusBar
= GetStatusBar();
591 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
593 theStatusBar
->Show(true);
596 #endif // wxUSE_STATUSBAR
598 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
600 return wxFrameBase::ShowFullScreen(show
, style
);
603 // ----------------------------------------------------------------------------
604 // tool/status bar stuff
605 // ----------------------------------------------------------------------------
609 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
611 #if defined(WINCE_WITHOUT_COMMANDBAR)
612 // We may already have a toolbar from calling SetMenuBar.
616 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
621 return m_frameToolBar
;
624 void wxFrame::PositionToolBar()
626 // TODO: we want to do something different in WinCE, because the toolbar
627 // should be associated with the commandbar, instead of being
628 // independent window.
629 #if !defined(WINCE_WITHOUT_COMMANDBAR)
630 wxToolBar
*toolbar
= GetToolBar();
631 if ( toolbar
&& toolbar
->IsShown() )
633 // don't call our (or even wxTopLevelWindow) version because we want
634 // the real (full) client area size, not excluding the tool/status bar
636 wxWindow::DoGetClientSize(&width
, &height
);
639 wxStatusBar
*statbar
= GetStatusBar();
640 if ( statbar
&& statbar
->IsShown() )
642 height
-= statbar
->GetClientSize().y
;
644 #endif // wxUSE_STATUSBAR
647 toolbar
->GetPosition( &tx
, &ty
);
648 toolbar
->GetSize( &tw
, &th
);
651 if ( toolbar
->HasFlag(wxTB_BOTTOM
) )
656 else if ( toolbar
->HasFlag(wxTB_RIGHT
) )
667 #if defined(WINCE_WITH_COMMANDBAR)
668 // We're using a commandbar - so we have to allow for it.
669 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
672 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
673 y
= rect
.bottom
- rect
.top
;
675 #endif // WINCE_WITH_COMMANDBAR
677 if ( toolbar
->HasFlag(wxTB_BOTTOM
) )
679 if ( ty
< 0 && ( -ty
== th
) )
681 if ( tx
< 0 && (-tx
== tw
) )
684 else if ( toolbar
->HasFlag(wxTB_RIGHT
) )
686 if( ty
< 0 && ( -ty
== th
) )
688 if( tx
< 0 && ( -tx
== tw
) )
693 if (ty
< 0 && (-ty
== th
))
695 if (tx
< 0 && (-tx
== tw
))
702 if ( toolbar
->IsVertical() )
711 // use the 'real' MSW position here, don't offset relativly to the
712 // client area origin
714 // Optimise such that we don't have to always resize the toolbar
715 // when the frame changes, otherwise we'll get a lot of flicker.
716 bool heightChanging
wxDUMMY_INITIALIZE(true);
717 bool widthChanging
wxDUMMY_INITIALIZE(true);
719 if ( toolbar
->IsVertical() )
721 // It's OK if the current height is greater than what can be shown.
722 heightChanging
= (desiredH
> th
) ;
723 widthChanging
= (desiredW
!= tw
) ;
725 // The next time around, we may not have to set the size
727 desiredH
= desiredH
+ 200;
731 // It's OK if the current width is greater than what can be shown.
732 widthChanging
= (desiredW
> tw
) ;
733 heightChanging
= (desiredH
!= th
) ;
735 // The next time around, we may not have to set the size
737 desiredW
= desiredW
+ 200;
740 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
741 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
744 #endif // !WINCE_WITH_COMMANDBAR
747 #endif // wxUSE_TOOLBAR
749 // ----------------------------------------------------------------------------
750 // frame state (iconized/maximized/...)
751 // ----------------------------------------------------------------------------
753 // propagate our state change to all child frames: this allows us to emulate X
754 // Windows behaviour where child frames float independently of the parent one
755 // on the desktop, but are iconized/restored with it
756 void wxFrame::IconizeChildFrames(bool bIconize
)
758 m_iconized
= bIconize
;
760 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
762 node
= node
->GetNext() )
764 wxWindow
*win
= node
->GetData();
766 // iconizing the frames with this style under Win95 shell puts them at
767 // the bottom of the screen (as the MDI children) instead of making
768 // them appear in the taskbar because they are, by virtue of this
769 // style, not managed by the taskbar - instead leave Windows take care
771 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
774 // the child MDI frames are a special case and should not be touched by
775 // the parent frame - instead, they are managed by the user
776 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
778 #if wxUSE_MDI_ARCHITECTURE
779 && !frame
->IsMDIChild()
780 #endif // wxUSE_MDI_ARCHITECTURE
783 // we don't want to restore the child frames which had been
784 // iconized even before we were iconized, so save the child frame
785 // status when iconizing the parent frame and check it when
789 frame
->m_wasMinimized
= frame
->IsIconized();
792 // note that we shouldn't touch the hidden frames neither because
793 // iconizing/restoring them would show them as a side effect
794 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
795 frame
->Iconize(bIconize
);
800 WXHICON
wxFrame::GetDefaultIcon() const
802 // we don't have any standard icons (any more)
806 // ===========================================================================
807 // message processing
808 // ===========================================================================
810 // ---------------------------------------------------------------------------
812 // ---------------------------------------------------------------------------
814 bool wxFrame::MSWDoTranslateMessage(wxFrame
*frame
, WXMSG
*pMsg
)
816 if ( wxWindow::MSWTranslateMessage(pMsg
) )
819 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
820 // try the menu bar accels
821 wxMenuBar
*menuBar
= GetMenuBar();
824 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
825 return acceleratorTable
.Translate(frame
, pMsg
);
827 #endif // wxUSE_MENUS && wxUSE_ACCEL
832 // ---------------------------------------------------------------------------
833 // our private (non virtual) message handlers
834 // ---------------------------------------------------------------------------
836 bool wxFrame::HandlePaint()
839 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
841 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
844 const wxIcon
& icon
= GetIcon();
845 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
846 : (HICON
)GetDefaultIcon();
848 // Hold a pointer to the dc so long as the OnPaint() message
849 // is being processed
851 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
853 // Erase background before painting or we get white background
854 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
859 ::GetClientRect(GetHwnd(), &rect
);
861 // FIXME: why hardcoded?
862 static const int icon_width
= 32;
863 static const int icon_height
= 32;
865 int icon_x
= (int)((rect
.right
- icon_width
)/2);
866 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
868 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
871 ::EndPaint(GetHwnd(), &ps
);
878 return wxWindow::HandlePaint();
883 // nothing to paint - processed
888 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
890 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
895 // only do it it if we were iconized before, otherwise resizing the
896 // parent frame has a curious side effect of bringing it under it's
901 // restore all child frames too
902 IconizeChildFrames(false);
904 (void)SendIconizeEvent(false);
908 // iconize all child frames too
909 IconizeChildFrames(true);
914 #endif // !__WXWINCE__
920 #endif // wxUSE_STATUSBAR
924 #endif // wxUSE_TOOLBAR
926 #if defined(WINCE_WITH_COMMANDBAR)
927 // Position the menu command bar
928 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
931 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
932 wxSize clientSz
= GetClientSize();
934 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
936 wxLogLastError(wxT("MoveWindow"));
940 #endif // WINCE_WITH_COMMANDBAR
943 // call the base class version to generate the appropriate events
947 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
951 // In case it's e.g. a toolbar.
952 wxWindow
*win
= wxFindWinFromHandle(control
);
954 return win
->MSWCommand(cmd
, id
);
957 // handle here commands from menus and accelerators
958 if ( cmd
== 0 || cmd
== 1 )
960 #if wxUSE_MENUS_NATIVE
961 if ( wxCurrentPopupMenu
)
963 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
964 wxCurrentPopupMenu
= NULL
;
966 return popupMenu
->MSWCommand(cmd
, id
);
968 #endif // wxUSE_MENUS_NATIVE
970 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
971 // handle here commands from Smartphone menu bar
972 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
976 #endif // __SMARTPHONE__ && __WXWINCE__
978 if ( ProcessCommand(id
) )
987 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
990 if ( flags
== 0xFFFF && hMenu
== 0 )
992 // menu was removed from screen
995 #ifndef __WXMICROWIN__
996 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
1003 // don't give hints for separators (doesn't make sense) nor for the
1004 // items opening popup menus (they don't have them anyhow) but do clear
1005 // the status line - otherwise, we would be left with the help message
1006 // for the previous item which doesn't apply any more
1007 DoGiveHelp(wxEmptyString
, false);
1012 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
1013 event
.SetEventObject(this);
1015 return GetEventHandler()->ProcessEvent(event
);
1018 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
1020 // we don't have the menu id here, so we use the id to specify if the event
1021 // was from a popup menu or a normal one
1022 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
1023 event
.SetEventObject(this);
1025 return GetEventHandler()->ProcessEvent(event
);
1028 // ---------------------------------------------------------------------------
1029 // the window proc for wxFrame
1030 // ---------------------------------------------------------------------------
1032 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1035 bool processed
= false;
1040 // if we can't close, tell the system that we processed the
1041 // message - otherwise it would close us
1042 processed
= !Close();
1046 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1053 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1056 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1061 processed
= HandlePaint();
1064 case WM_INITMENUPOPUP
:
1065 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
1068 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1073 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1075 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1079 case WM_EXITMENULOOP
:
1080 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
1083 case WM_QUERYDRAGICON
:
1085 const wxIcon
& icon
= GetIcon();
1086 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1087 : (HICON
)GetDefaultIcon();
1089 processed
= rc
!= 0;
1092 #endif // !__WXMICROWIN__
1096 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1101 // handle WM_INITMENUPOPUP message
1102 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1104 wxMenu
* menu
= NULL
;
1107 int nCount
= GetMenuBar()->GetMenuCount();
1108 for (int n
= 0; n
< nCount
; n
++)
1110 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1112 menu
= GetMenuBar()->GetMenu(n
);
1118 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1119 event
.SetEventObject(this);
1121 return GetEventHandler()->ProcessEvent(event
);
1124 // ----------------------------------------------------------------------------
1125 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1126 // from the client area, so the client area is what's really available for the
1128 // ----------------------------------------------------------------------------
1130 // get the origin of the client area in the client coordinates
1131 wxPoint
wxFrame::GetClientAreaOrigin() const
1133 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1135 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1136 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1137 wxToolBar
* const toolbar
= GetToolBar();
1138 if ( toolbar
&& toolbar
->IsShown() )
1140 const wxSize sizeTB
= toolbar
->GetSize();
1142 if ( toolbar
->HasFlag(wxTB_TOP
) )
1146 else if ( toolbar
->HasFlag(wxTB_LEFT
) )
1151 #endif // wxUSE_TOOLBAR
1153 #if defined(WINCE_WITH_COMMANDBAR)
1154 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1157 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1158 pt
.y
+= (rect
.bottom
- rect
.top
);