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();
238 wxToolBar
*toolbar
= GetToolBar();
239 if ( toolbar
&& toolbar
->HasFlag(wxTB_RIGHT
) )
241 width
-= toolbar
->GetClientSize().x
;
243 if ( toolbar
&& toolbar
->HasFlag( wxTB_BOTTOM
) )
245 height
-= toolbar
->GetClientSize().y
;
250 wxTopLevelWindow::DoSetClientSize(width
, height
);
253 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
254 void wxFrame::DoGetClientSize(int *x
, int *y
) const
256 wxTopLevelWindow::DoGetClientSize(x
, y
);
258 // account for the possible toolbar
259 wxPoint pt
= GetClientAreaOrigin();
268 wxToolBar
*toolbar
= GetToolBar();
269 if( toolbar
&& toolbar
->HasFlag( wxTB_BOTTOM
) )
271 *y
-= toolbar
->GetClientSize().y
;
276 wxToolBar
*toolbar
= GetToolBar();
277 if ( toolbar
&& toolbar
->HasFlag(wxTB_RIGHT
) )
279 *x
-= toolbar
->GetClientSize().x
;
284 // adjust client area height to take the status bar into account
287 wxStatusBar
*statbar
= GetStatusBar();
288 if ( statbar
&& statbar
->IsShown() )
290 *y
-= statbar
->GetClientSize().y
;
293 #endif // wxUSE_STATUSBAR
296 // ----------------------------------------------------------------------------
297 // wxFrame: various geometry-related functions
298 // ----------------------------------------------------------------------------
300 void wxFrame::Raise()
302 ::SetForegroundWindow(GetHwnd());
305 // generate an artificial resize event
306 void wxFrame::SendSizeEvent()
310 RECT r
= wxGetWindowRect(GetHwnd());
312 (void)::PostMessage(GetHwnd(), WM_SIZE
,
313 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
314 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
319 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
322 const wxString
& name
)
324 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
326 #if wxUSE_NATIVE_STATUSBAR
327 if ( !UsesNativeStatusBar() )
329 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
334 statusBar
= new wxStatusBar(this, id
, style
, name
);
337 statusBar
->SetFieldsCount(number
);
342 void wxFrame::PositionStatusBar()
344 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
348 GetClientSize(&w
, &h
);
350 wxToolBar
*toolbar
= GetToolBar();
351 if( toolbar
&& toolbar
->HasFlag( wxTB_BOTTOM
) )
352 h
+= toolbar
->GetClientRect().height
;
353 if( toolbar
&& toolbar
->HasFlag( wxTB_RIGHT
) )
354 w
+= toolbar
->GetClientRect().width
;
357 m_frameStatusBar
->GetSize(&sw
, &sh
);
359 // Since we wish the status bar to be directly under the client area,
360 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
361 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
363 #endif // wxUSE_STATUSBAR
365 #if wxUSE_MENUS_NATIVE
367 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
369 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
371 wxMenu
*autoMenu
= NULL
;
373 if( menubar
->GetMenuCount() == 1 )
375 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
376 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
380 autoMenu
= new wxMenu
;
382 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
384 wxMenu
*item
= menubar
->GetMenu(n
);
385 wxString label
= menubar
->GetLabelTop(n
);
386 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
387 autoMenu
->Append(wxID_ANY
, label
, new_item
);
390 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
393 #elif defined(WINCE_WITHOUT_COMMANDBAR)
396 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
397 wxDefaultPosition
, wxDefaultSize
,
398 wxBORDER_NONE
| wxTB_HORIZONTAL
,
399 wxToolBarNameStr
, menubar
);
401 menubar
->SetToolBar(toolBar
);
403 // Now adjust size for menu bar
406 //When the main window is created using CW_USEDEFAULT the height of the
407 // is created is not taken into account). So we resize the window after
408 // if a menubar is present
411 ::GetWindowRect((HWND
) GetHWND(), &rc
);
412 // adjust for menu / titlebar height
413 rc
.bottom
-= (2*menuHeight
-1);
415 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
419 wxFrameBase::AttachMenuBar(menubar
);
423 // actually remove the menu from the frame
424 m_hMenu
= (WXHMENU
)0;
425 InternalSetMenuBar();
427 else // set new non NULL menu bar
429 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
430 // Can set a menubar several times.
431 if ( menubar
->GetHMenu() )
433 m_hMenu
= menubar
->GetHMenu();
437 m_hMenu
= menubar
->Create();
441 wxFAIL_MSG( _T("failed to create menu bar") );
446 InternalSetMenuBar();
450 void wxFrame::InternalSetMenuBar()
452 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
455 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
457 wxLogLastError(wxT("SetMenu"));
462 #endif // wxUSE_MENUS_NATIVE
464 // Responds to colour changes, and passes event on to children.
465 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
467 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
471 if ( m_frameStatusBar
)
473 wxSysColourChangedEvent event2
;
474 event2
.SetEventObject( m_frameStatusBar
);
475 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
477 #endif // wxUSE_STATUSBAR
479 // Propagate the event to the non-top-level children
480 wxWindow::OnSysColourChanged(event
);
483 // Pass true to show full screen, false to restore.
484 bool wxFrame::ShowFullScreen(bool show
, long style
)
486 // TODO-CE: add support for CE
487 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
488 if ( IsFullScreen() == show
)
493 // zap the toolbar, menubar, and statusbar if needed
495 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
497 wxToolBar
*theToolBar
= GetToolBar();
499 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
501 if ( theToolBar
->IsShown() )
503 theToolBar
->SetSize(wxDefaultCoord
,0);
504 theToolBar
->Show(false);
506 else // prevent it from being restored later
508 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
511 #endif // wxUSE_TOOLBAR
513 if (style
& wxFULLSCREEN_NOMENUBAR
)
514 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
517 wxStatusBar
*theStatusBar
= GetStatusBar();
519 // Save the number of fields in the statusbar
520 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
522 if ( theStatusBar
->IsShown() )
523 theStatusBar
->Show(false);
525 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
527 #endif // wxUSE_STATUSBAR
529 else // restore to normal
531 // restore the toolbar, menubar, and statusbar if we had hid them
533 wxToolBar
*theToolBar
= GetToolBar();
535 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
537 theToolBar
->Show(true);
539 #endif // wxUSE_TOOLBAR
541 if (m_fsStyle
& wxFULLSCREEN_NOMENUBAR
)
543 WXHMENU menu
= m_hMenu
;
545 #if wxUSE_MDI_ARCHITECTURE
546 wxMDIParentFrame
*frame
= wxDynamicCast(this, wxMDIParentFrame
);
549 wxMDIChildFrame
*child
= frame
->GetActiveChild();
552 menu
= child
->GetWinMenu();
555 #endif // wxUSE_MDI_ARCHITECTURE
559 ::SetMenu(GetHwnd(), (HMENU
)menu
);
564 wxStatusBar
*theStatusBar
= GetStatusBar();
566 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
568 theStatusBar
->Show(true);
571 #endif // wxUSE_STATUSBAR
573 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
575 return wxFrameBase::ShowFullScreen(show
, style
);
578 // ----------------------------------------------------------------------------
579 // tool/status bar stuff
580 // ----------------------------------------------------------------------------
584 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
586 #if defined(WINCE_WITHOUT_COMMANDBAR)
587 // We may already have a toolbar from calling SetMenuBar.
591 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
596 return m_frameToolBar
;
599 void wxFrame::PositionToolBar()
602 wxToolBar
*toolbar
= GetToolBar();
603 if ( toolbar
&& toolbar
->IsShown() )
605 #if defined(WINCE_WITHOUT_COMMANDBAR)
606 // We want to do something different in WinCE, because
607 // the toolbar should be associated with the commandbar,
608 // and not an independent window.
611 // don't call our (or even wxTopLevelWindow) version because we want
612 // the real (full) client area size, not excluding the tool/status bar
614 wxWindow::DoGetClientSize(&width
, &height
);
617 wxStatusBar
*statbar
= GetStatusBar();
618 if ( statbar
&& statbar
->IsShown() )
620 height
-= statbar
->GetClientSize().y
;
622 #endif // wxUSE_STATUSBAR
624 toolbar
->GetPosition( &tx
, &ty
);
625 toolbar
->GetSize( &tw
, &th
);
626 if( ( toolbar
->GetWindowStyleFlag() & wxTB_HORIZONTAL
) || ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
) )
631 else if( toolbar
->GetWindowStyleFlag() & wxTB_BOTTOM
)
636 else if( toolbar
->HasFlag(wxTB_RIGHT
) )
641 #if defined(WINCE_WITH_COMMANDBAR)
642 // We're using a commandbar - so we have to allow for it.
643 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
646 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
647 y
= rect
.bottom
- rect
.top
;
650 if( ( toolbar
->GetWindowStyleFlag() & wxTB_HORIZONTAL
) || ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
) )
653 if (ty
< 0 && (-ty
== th
))
655 if (tx
< 0 && (-tx
== tw
))
658 else if( toolbar
->GetWindowStyleFlag() & wxTB_BOTTOM
)
660 if( ty
< 0 && ( -ty
== th
) )
662 if( tx
< 0 && ( -tx
== tw
) )
665 else if( toolbar
->HasFlag(wxTB_RIGHT
) )
667 if( ty
< 0 && ( -ty
== th
) )
669 if( tx
< 0 && ( -tx
== tw
) )
676 if ( toolbar
->IsVertical() )
683 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
687 // use the 'real' MSW position here, don't offset relativly to the
688 // client area origin
690 // Optimise such that we don't have to always resize the toolbar
691 // when the frame changes, otherwise we'll get a lot of flicker.
692 bool heightChanging
wxDUMMY_INITIALIZE(true);
693 bool widthChanging
wxDUMMY_INITIALIZE(true);
695 if ( toolbar
->IsVertical() )
697 // It's OK if the current height is greater than what can be shown.
698 heightChanging
= (desiredH
> th
) ;
699 widthChanging
= (desiredW
!= tw
) ;
701 // The next time around, we may not have to set the size
703 desiredH
= desiredH
+ 200;
707 // It's OK if the current width is greater than what can be shown.
708 widthChanging
= (desiredW
> tw
) ;
709 heightChanging
= (desiredH
!= th
) ;
711 // The next time around, we may not have to set the size
713 desiredW
= desiredW
+ 200;
716 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
717 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
719 #endif // __WXWINCE__
723 #endif // wxUSE_TOOLBAR
725 // ----------------------------------------------------------------------------
726 // frame state (iconized/maximized/...)
727 // ----------------------------------------------------------------------------
729 // propagate our state change to all child frames: this allows us to emulate X
730 // Windows behaviour where child frames float independently of the parent one
731 // on the desktop, but are iconized/restored with it
732 void wxFrame::IconizeChildFrames(bool bIconize
)
734 m_iconized
= bIconize
;
736 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
738 node
= node
->GetNext() )
740 wxWindow
*win
= node
->GetData();
742 // iconizing the frames with this style under Win95 shell puts them at
743 // the bottom of the screen (as the MDI children) instead of making
744 // them appear in the taskbar because they are, by virtue of this
745 // style, not managed by the taskbar - instead leave Windows take care
747 if ( win
->GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
750 // the child MDI frames are a special case and should not be touched by
751 // the parent frame - instead, they are managed by the user
752 wxFrame
*frame
= wxDynamicCast(win
, wxFrame
);
754 #if wxUSE_MDI_ARCHITECTURE
755 && !frame
->IsMDIChild()
756 #endif // wxUSE_MDI_ARCHITECTURE
759 // we don't want to restore the child frames which had been
760 // iconized even before we were iconized, so save the child frame
761 // status when iconizing the parent frame and check it when
765 frame
->m_wasMinimized
= frame
->IsIconized();
768 // note that we shouldn't touch the hidden frames neither because
769 // iconizing/restoring them would show them as a side effect
770 if ( !frame
->m_wasMinimized
&& frame
->IsShown() )
771 frame
->Iconize(bIconize
);
776 WXHICON
wxFrame::GetDefaultIcon() const
778 // we don't have any standard icons (any more)
782 // ===========================================================================
783 // message processing
784 // ===========================================================================
786 // ---------------------------------------------------------------------------
788 // ---------------------------------------------------------------------------
790 bool wxFrame::MSWDoTranslateMessage(wxFrame
*frame
, WXMSG
*pMsg
)
792 if ( wxWindow::MSWTranslateMessage(pMsg
) )
795 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
796 // try the menu bar accels
797 wxMenuBar
*menuBar
= GetMenuBar();
800 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
801 return acceleratorTable
.Translate(frame
, pMsg
);
803 #endif // wxUSE_MENUS && wxUSE_ACCEL
808 // ---------------------------------------------------------------------------
809 // our private (non virtual) message handlers
810 // ---------------------------------------------------------------------------
812 bool wxFrame::HandlePaint()
815 if ( ::GetUpdateRect(GetHwnd(), &rect
, FALSE
) )
817 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
820 const wxIcon
& icon
= GetIcon();
821 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
822 : (HICON
)GetDefaultIcon();
824 // Hold a pointer to the dc so long as the OnPaint() message
825 // is being processed
827 HDC hdc
= ::BeginPaint(GetHwnd(), &ps
);
829 // Erase background before painting or we get white background
830 MSWDefWindowProc(WM_ICONERASEBKGND
, (WORD
)(LONG
)ps
.hdc
, 0L);
835 ::GetClientRect(GetHwnd(), &rect
);
837 // FIXME: why hardcoded?
838 static const int icon_width
= 32;
839 static const int icon_height
= 32;
841 int icon_x
= (int)((rect
.right
- icon_width
)/2);
842 int icon_y
= (int)((rect
.bottom
- icon_height
)/2);
844 ::DrawIcon(hdc
, icon_x
, icon_y
, hIcon
);
847 ::EndPaint(GetHwnd(), &ps
);
854 return wxWindow::HandlePaint();
859 // nothing to paint - processed
864 bool wxFrame::HandleSize(int WXUNUSED(x
), int WXUNUSED(y
), WXUINT id
)
866 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
871 // only do it it if we were iconized before, otherwise resizing the
872 // parent frame has a curious side effect of bringing it under it's
877 // restore all child frames too
878 IconizeChildFrames(false);
880 (void)SendIconizeEvent(false);
884 // iconize all child frames too
885 IconizeChildFrames(true);
890 #endif // !__WXWINCE__
896 #endif // wxUSE_STATUSBAR
900 #endif // wxUSE_TOOLBAR
902 #if defined(WINCE_WITH_COMMANDBAR)
903 // Position the menu command bar
904 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
907 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
908 wxSize clientSz
= GetClientSize();
910 if ( !::MoveWindow((HWND
) GetMenuBar()->GetCommandBar(), 0, 0, clientSz
.x
, rect
.bottom
- rect
.top
, true ) )
912 wxLogLastError(wxT("MoveWindow"));
916 #endif // WINCE_WITH_COMMANDBAR
919 // call the base class version to generate the appropriate events
923 bool wxFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND control
)
927 // In case it's e.g. a toolbar.
928 wxWindow
*win
= wxFindWinFromHandle(control
);
930 return win
->MSWCommand(cmd
, id
);
933 // handle here commands from menus and accelerators
934 if ( cmd
== 0 || cmd
== 1 )
936 #if wxUSE_MENUS_NATIVE
937 if ( wxCurrentPopupMenu
)
939 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
940 wxCurrentPopupMenu
= NULL
;
942 return popupMenu
->MSWCommand(cmd
, id
);
944 #endif // wxUSE_MENUS_NATIVE
946 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
947 // handle here commands from Smartphone menu bar
948 if ( wxTopLevelWindow::HandleCommand(id
, cmd
, control
) )
952 #endif // __SMARTPHONE__ && __WXWINCE__
954 if ( ProcessCommand(id
) )
963 bool wxFrame::HandleMenuSelect(WXWORD nItem
, WXWORD flags
, WXHMENU hMenu
)
966 if ( flags
== 0xFFFF && hMenu
== 0 )
968 // menu was removed from screen
971 #ifndef __WXMICROWIN__
972 else if ( !(flags
& MF_POPUP
) && !(flags
& MF_SEPARATOR
) )
979 // don't give hints for separators (doesn't make sense) nor for the
980 // items opening popup menus (they don't have them anyhow) but do clear
981 // the status line - otherwise, we would be left with the help message
982 // for the previous item which doesn't apply any more
983 DoGiveHelp(wxEmptyString
, false);
988 wxMenuEvent
event(wxEVT_MENU_HIGHLIGHT
, item
);
989 event
.SetEventObject(this);
991 return GetEventHandler()->ProcessEvent(event
);
994 bool wxFrame::HandleMenuLoop(const wxEventType
& evtType
, WXWORD isPopup
)
996 // we don't have the menu id here, so we use the id to specify if the event
997 // was from a popup menu or a normal one
998 wxMenuEvent
event(evtType
, isPopup
? -1 : 0);
999 event
.SetEventObject(this);
1001 return GetEventHandler()->ProcessEvent(event
);
1004 // ---------------------------------------------------------------------------
1005 // the window proc for wxFrame
1006 // ---------------------------------------------------------------------------
1008 WXLRESULT
wxFrame::MSWWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1011 bool processed
= false;
1016 // if we can't close, tell the system that we processed the
1017 // message - otherwise it would close us
1018 processed
= !Close();
1022 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1029 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1032 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1037 processed
= HandlePaint();
1040 case WM_INITMENUPOPUP
:
1041 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
1044 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1049 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1051 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1055 case WM_EXITMENULOOP
:
1056 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
1059 case WM_QUERYDRAGICON
:
1061 const wxIcon
& icon
= GetIcon();
1062 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1063 : (HICON
)GetDefaultIcon();
1065 processed
= rc
!= 0;
1068 #endif // !__WXMICROWIN__
1072 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1077 // handle WM_INITMENUPOPUP message
1078 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1080 wxMenu
* menu
= NULL
;
1083 int nCount
= GetMenuBar()->GetMenuCount();
1084 for (int n
= 0; n
< nCount
; n
++)
1086 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1088 menu
= GetMenuBar()->GetMenu(n
);
1094 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1095 event
.SetEventObject(this);
1097 return GetEventHandler()->ProcessEvent(event
);
1100 // ----------------------------------------------------------------------------
1101 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1102 // from the client area, so the client area is what's really available for the
1104 // ----------------------------------------------------------------------------
1106 // get the origin of the client area in the client coordinates
1107 wxPoint
wxFrame::GetClientAreaOrigin() const
1109 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1111 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1112 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1113 wxToolBar
*toolbar
= GetToolBar();
1114 if ( toolbar
&& toolbar
->IsShown() )
1117 toolbar
->GetSize(&w
, &h
);
1119 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1123 else if( ( toolbar
->GetWindowStyleFlag() & wxTB_TOP
) )
1128 #endif // wxUSE_TOOLBAR
1130 #if defined(WINCE_WITH_COMMANDBAR)
1131 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1134 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1135 pt
.y
+= (rect
.bottom
- rect
.top
);