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"
49 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
50 #include "wx/msw/ole/oleutils.h"
52 #include "wx/msw/winundef.h"
56 #include "wx/statusbr.h"
57 #include "wx/generic/statusbr.h"
58 #endif // wxUSE_STATUSBAR
61 #include "wx/toolbar.h"
62 #endif // wxUSE_TOOLBAR
64 #include "wx/menuitem.h"
67 #ifdef __WXUNIVERSAL__
68 #include "wx/univ/theme.h"
69 #include "wx/univ/colschem.h"
70 #endif // __WXUNIVERSAL__
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 #if wxUSE_MENUS_NATIVE
77 extern wxMenu
*wxCurrentPopupMenu
;
78 #endif // wxUSE_MENUS_NATIVE
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 BEGIN_EVENT_TABLE(wxFrame
, wxFrameBase
)
85 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged
)
88 #if wxUSE_EXTENDED_RTTI
89 WX_DEFINE_FLAGS( wxFrameStyle
)
91 wxBEGIN_FLAGS( wxFrameStyle
)
92 // new style border flags, we put them first to
93 // use them for streaming out
94 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
95 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
96 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
97 wxFLAGS_MEMBER(wxBORDER_RAISED
)
98 wxFLAGS_MEMBER(wxBORDER_STATIC
)
99 wxFLAGS_MEMBER(wxBORDER_NONE
)
101 // old style border flags
102 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
103 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
104 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
105 wxFLAGS_MEMBER(wxRAISED_BORDER
)
106 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
107 wxFLAGS_MEMBER(wxBORDER
)
109 // standard window styles
110 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
111 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
112 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
113 wxFLAGS_MEMBER(wxWANTS_CHARS
)
114 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
115 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
116 wxFLAGS_MEMBER(wxVSCROLL
)
117 wxFLAGS_MEMBER(wxHSCROLL
)
120 wxFLAGS_MEMBER(wxSTAY_ON_TOP
)
121 wxFLAGS_MEMBER(wxCAPTION
)
122 wxFLAGS_MEMBER(wxTHICK_FRAME
)
123 wxFLAGS_MEMBER(wxSYSTEM_MENU
)
124 wxFLAGS_MEMBER(wxRESIZE_BORDER
)
125 wxFLAGS_MEMBER(wxRESIZE_BOX
)
126 wxFLAGS_MEMBER(wxCLOSE_BOX
)
127 wxFLAGS_MEMBER(wxMAXIMIZE_BOX
)
128 wxFLAGS_MEMBER(wxMINIMIZE_BOX
)
130 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW
)
131 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT
)
133 wxFLAGS_MEMBER(wxFRAME_SHAPED
)
135 wxEND_FLAGS( wxFrameStyle
)
137 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame
, wxTopLevelWindow
,"wx/frame.h")
139 wxBEGIN_PROPERTIES_TABLE(wxFrame
)
140 wxEVENT_PROPERTY( Menu
, wxEVT_COMMAND_MENU_SELECTED
, wxCommandEvent
)
142 wxPROPERTY( Title
,wxString
, SetTitle
, GetTitle
, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
143 wxPROPERTY_FLAGS( WindowStyle
, wxFrameStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
144 wxPROPERTY( MenuBar
, wxMenuBar
* , SetMenuBar
, GetMenuBar
, EMPTY_MACROVALUE
, 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
145 wxEND_PROPERTIES_TABLE()
147 wxBEGIN_HANDLERS_TABLE(wxFrame
)
148 wxEND_HANDLERS_TABLE()
150 wxCONSTRUCTOR_6( wxFrame
, wxWindow
* , Parent
, wxWindowID
, Id
, wxString
, Title
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
153 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
156 // ============================================================================
158 // ============================================================================
160 // ----------------------------------------------------------------------------
161 // static class members
162 // ----------------------------------------------------------------------------
165 #if wxUSE_NATIVE_STATUSBAR
166 bool wxFrame::m_useNativeStatusBar
= true;
168 bool wxFrame::m_useNativeStatusBar
= false;
170 #endif // wxUSE_NATIVE_STATUSBAR
172 // ----------------------------------------------------------------------------
173 // creation/destruction
174 // ----------------------------------------------------------------------------
180 #endif // wxUSE_MENUS
186 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
187 SHACTIVATEINFO
* info
= new SHACTIVATEINFO
;
188 memset(info
, 0, sizeof(SHACTIVATEINFO
));
189 info
->cbSize
= sizeof(SHACTIVATEINFO
);
191 m_activateInfo
= (void*) info
;
194 m_wasMinimized
= false;
197 bool wxFrame::Create(wxWindow
*parent
,
199 const wxString
& title
,
203 const wxString
& name
)
205 if ( !wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
) )
208 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
210 #if defined(__SMARTPHONE__)
211 SetLeftMenu(wxID_EXIT
, _("Done"));
214 #if defined(__POCKETPC__)
215 // The guidelines state that Ctrl+Q should quit the app.
216 // Let's define an accelerator table to send wxID_EXIT.
217 wxAcceleratorEntry entries
[1];
218 entries
[0].Set(wxACCEL_CTRL
, 'Q', wxID_EXIT
);
219 wxAcceleratorTable
accel(1, entries
);
220 SetAcceleratorTable(accel
);
228 m_isBeingDeleted
= true;
231 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
232 SHACTIVATEINFO
* info
= (SHACTIVATEINFO
*) m_activateInfo
;
234 m_activateInfo
= NULL
;
238 // ----------------------------------------------------------------------------
239 // wxFrame client size calculations
240 // ----------------------------------------------------------------------------
242 void wxFrame::DoSetClientSize(int width
, int height
)
244 // leave enough space for the status bar if we have (and show) it
246 wxStatusBar
*statbar
= GetStatusBar();
247 if ( statbar
&& statbar
->IsShown() )
249 height
+= statbar
->GetSize().y
;
251 #endif // wxUSE_STATUSBAR
253 // call GetClientAreaOrigin() to take the toolbar into account
254 wxPoint pt
= GetClientAreaOrigin();
258 wxTopLevelWindow::DoSetClientSize(width
, height
);
261 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
262 void wxFrame::DoGetClientSize(int *x
, int *y
) const
264 wxTopLevelWindow::DoGetClientSize(x
, y
);
266 // account for the possible toolbar
267 wxPoint pt
= GetClientAreaOrigin();
275 // adjust client area height to take the status bar into account
278 wxStatusBar
*statbar
= GetStatusBar();
279 if ( statbar
&& statbar
->IsShown() )
281 *y
-= statbar
->GetClientSize().y
;
284 #endif // wxUSE_STATUSBAR
287 // ----------------------------------------------------------------------------
288 // wxFrame: various geometry-related functions
289 // ----------------------------------------------------------------------------
291 void wxFrame::Raise()
293 ::SetForegroundWindow(GetHwnd());
296 // generate an artificial resize event
297 void wxFrame::SendSizeEvent()
301 RECT r
= wxGetWindowRect(GetHwnd());
303 (void)::PostMessage(GetHwnd(), WM_SIZE
,
304 IsMaximized() ? SIZE_MAXIMIZED
: SIZE_RESTORED
,
305 MAKELPARAM(r
.right
- r
.left
, r
.bottom
- r
.top
));
310 wxStatusBar
*wxFrame::OnCreateStatusBar(int number
,
313 const wxString
& name
)
315 wxStatusBar
*statusBar
wxDUMMY_INITIALIZE(NULL
);
317 #if wxUSE_NATIVE_STATUSBAR
318 if ( !UsesNativeStatusBar() )
320 statusBar
= (wxStatusBar
*)new wxStatusBarGeneric(this, id
, style
);
325 statusBar
= new wxStatusBar(this, id
, style
, name
);
328 statusBar
->SetFieldsCount(number
);
333 void wxFrame::PositionStatusBar()
335 if ( !m_frameStatusBar
|| !m_frameStatusBar
->IsShown() )
339 GetClientSize(&w
, &h
);
341 m_frameStatusBar
->GetSize(&sw
, &sh
);
343 // Since we wish the status bar to be directly under the client area,
344 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
345 m_frameStatusBar
->SetSize(0, h
, w
, sh
);
347 #endif // wxUSE_STATUSBAR
349 #if wxUSE_MENUS_NATIVE
351 void wxFrame::AttachMenuBar(wxMenuBar
*menubar
)
353 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
355 wxMenu
*autoMenu
= NULL
;
357 if( menubar
->GetMenuCount() == 1 )
359 autoMenu
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar
->GetMenu(0));
360 SetRightMenu(wxID_ANY
, menubar
->GetLabelTop(0), autoMenu
);
364 autoMenu
= new wxMenu
;
366 for( size_t n
= 0; n
< menubar
->GetMenuCount(); n
++ )
368 wxMenu
*item
= menubar
->GetMenu(n
);
369 wxString label
= menubar
->GetLabelTop(n
);
370 wxMenu
*new_item
= wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item
);
371 autoMenu
->Append(wxID_ANY
, label
, new_item
);
374 SetRightMenu(wxID_ANY
, _("Menu"), autoMenu
);
377 #elif defined(WINCE_WITHOUT_COMMANDBAR)
380 wxToolMenuBar
* toolBar
= new wxToolMenuBar(this, wxID_ANY
,
381 wxDefaultPosition
, wxDefaultSize
,
382 wxBORDER_NONE
| wxTB_HORIZONTAL
,
383 wxToolBarNameStr
, menubar
);
385 menubar
->SetToolBar(toolBar
);
387 // Now adjust size for menu bar
390 //When the main window is created using CW_USEDEFAULT the height of the
391 // is created is not taken into account). So we resize the window after
392 // if a menubar is present
395 ::GetWindowRect((HWND
) GetHWND(), &rc
);
396 // adjust for menu / titlebar height
397 rc
.bottom
-= (2*menuHeight
-1);
399 ::MoveWindow((HWND
) GetHWND(), rc
.left
, rc
.top
, rc
.right
, rc
.bottom
, FALSE
);
403 wxFrameBase::AttachMenuBar(menubar
);
407 // actually remove the menu from the frame
408 m_hMenu
= (WXHMENU
)0;
409 InternalSetMenuBar();
411 else // set new non NULL menu bar
413 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
414 // Can set a menubar several times.
415 if ( menubar
->GetHMenu() )
417 m_hMenu
= menubar
->GetHMenu();
421 m_hMenu
= menubar
->Create();
425 wxFAIL_MSG( _T("failed to create menu bar") );
430 InternalSetMenuBar();
434 void wxFrame::InternalSetMenuBar()
436 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
439 if ( !::SetMenu(GetHwnd(), (HMENU
)m_hMenu
) )
441 wxLogLastError(wxT("SetMenu"));
446 #endif // wxUSE_MENUS_NATIVE
448 // Responds to colour changes, and passes event on to children.
449 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
451 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
455 if ( m_frameStatusBar
)
457 wxSysColourChangedEvent event2
;
458 event2
.SetEventObject( m_frameStatusBar
);
459 m_frameStatusBar
->GetEventHandler()->ProcessEvent(event2
);
461 #endif // wxUSE_STATUSBAR
463 // Propagate the event to the non-top-level children
464 wxWindow::OnSysColourChanged(event
);
467 // Pass true to show full screen, false to restore.
468 bool wxFrame::ShowFullScreen(bool show
, long style
)
470 // TODO-CE: add support for CE
471 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
472 if ( IsFullScreen() == show
)
477 // zap the toolbar, menubar, and statusbar if needed
479 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
481 wxToolBar
*theToolBar
= GetToolBar();
483 if ((style
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
485 if ( theToolBar
->IsShown() )
487 theToolBar
->SetSize(wxDefaultCoord
,0);
488 theToolBar
->Show(false);
490 else // prevent it from being restored later
492 style
&= ~wxFULLSCREEN_NOTOOLBAR
;
495 #endif // wxUSE_TOOLBAR
497 if (style
& wxFULLSCREEN_NOMENUBAR
)
498 SetMenu((HWND
)GetHWND(), (HMENU
) NULL
);
501 wxStatusBar
*theStatusBar
= GetStatusBar();
503 // Save the number of fields in the statusbar
504 if ((style
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
506 if ( theStatusBar
->IsShown() )
507 theStatusBar
->Show(false);
509 style
&= ~wxFULLSCREEN_NOSTATUSBAR
;
511 #endif // wxUSE_STATUSBAR
513 else // restore to normal
515 // restore the toolbar, menubar, and statusbar if we had hid them
517 wxToolBar
*theToolBar
= GetToolBar();
519 if ((m_fsStyle
& wxFULLSCREEN_NOTOOLBAR
) && theToolBar
)
521 theToolBar
->Show(true);
523 #endif // wxUSE_TOOLBAR
525 if ((m_fsStyle
& wxFULLSCREEN_NOMENUBAR
) && m_hMenu
)
526 ::SetMenu(GetHwnd(), (HMENU
)m_hMenu
);
529 wxStatusBar
*theStatusBar
= GetStatusBar();
531 if ((m_fsStyle
& wxFULLSCREEN_NOSTATUSBAR
) && theStatusBar
)
533 theStatusBar
->Show(true);
536 #endif // wxUSE_STATUSBAR
538 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
540 return wxFrameBase::ShowFullScreen(show
, style
);
543 // ----------------------------------------------------------------------------
544 // tool/status bar stuff
545 // ----------------------------------------------------------------------------
549 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
551 #if defined(WINCE_WITHOUT_COMMANDBAR)
552 // We may already have a toolbar from calling SetMenuBar.
556 if ( wxFrameBase::CreateToolBar(style
, id
, name
) )
561 return m_frameToolBar
;
564 void wxFrame::PositionToolBar()
566 wxToolBar
*toolbar
= GetToolBar();
567 if ( toolbar
&& toolbar
->IsShown() )
569 #if defined(WINCE_WITHOUT_COMMANDBAR)
570 // We want to do something different in WinCE, because
571 // the toolbar should be associated with the commandbar,
572 // and not an independent window.
575 // don't call our (or even wxTopLevelWindow) version because we want
576 // the real (full) client area size, not excluding the tool/status bar
578 wxWindow::DoGetClientSize(&width
, &height
);
581 wxStatusBar
*statbar
= GetStatusBar();
582 if ( statbar
&& statbar
->IsShown() )
584 height
-= statbar
->GetClientSize().y
;
586 #endif // wxUSE_STATUSBAR
590 #if defined(WINCE_WITH_COMMANDBAR)
591 // We're using a commandbar - so we have to allow for it.
592 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
595 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
596 y
= rect
.bottom
- rect
.top
;
602 toolbar
->GetPosition(&tx
, &ty
);
603 toolbar
->GetSize(&tw
, &th
);
606 if (ty
< 0 && (-ty
== th
))
608 if (tx
< 0 && (-tx
== tw
))
614 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
621 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
625 // use the 'real' MSW position here, don't offset relativly to the
626 // client area origin
628 // Optimise such that we don't have to always resize the toolbar
629 // when the frame changes, otherwise we'll get a lot of flicker.
630 bool heightChanging
wxDUMMY_INITIALIZE(true);
631 bool widthChanging
wxDUMMY_INITIALIZE(true);
633 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
635 // It's OK if the current height is greater than what can be shown.
636 heightChanging
= (desiredH
> th
) ;
637 widthChanging
= (desiredW
!= tw
) ;
639 // The next time around, we may not have to set the size
641 desiredH
= desiredH
+ 200;
645 // It's OK if the current width is greater than what can be shown.
646 widthChanging
= (desiredW
> tw
) ;
647 heightChanging
= (desiredH
!= th
) ;
649 // The next time around, we may not have to set the size
651 desiredW
= desiredW
+ 200;
654 if (tx
!= 0 || ty
!= 0 || widthChanging
|| heightChanging
)
655 toolbar
->SetSize(x
, y
, desiredW
, desiredH
, wxSIZE_NO_ADJUSTMENTS
);
657 #endif // __WXWINCE__
661 #endif // wxUSE_TOOLBAR
663 // ----------------------------------------------------------------------------
664 // frame state (iconized/maximized/...)
665 // ----------------------------------------------------------------------------
667 // propagate our state change to all child frames: this allows us to emulate X
668 // Windows behaviour where child frames float independently of the parent one
669 // on the desktop, but are iconized/restored with it
670 void wxFrame::IconizeChildFrames(bool bIconize
)
672 m_iconized
= bIconize
;
674 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
676 node
= node
->GetNext() )
678 wxWindow
*win
= node
->GetData();
680 // iconizing the frames with this style under Win95 shell puts them at
681 // the bottom of the screen (as the MDI children) instead of making
682 // them appear in the taskbar because they are, by virtue of this
683 // style, not managed by the taskbar - instead leave Windows take care
686 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::MSWTranslateMessage(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();
741 const wxAcceleratorTable
& acceleratorTable
= menuBar
->GetAccelTable();
742 return acceleratorTable
.Translate(this, pMsg
);
745 #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;
955 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
958 SHACTIVATEINFO
* info
= (SHACTIVATEINFO
*) m_activateInfo
;
960 SHHandleWMActivate(GetHwnd(), wParam
, lParam
, info
, FALSE
);
962 // This implicitly sends a wxEVT_ACTIVATE_APP event
964 wxTheApp
->SetActive(wParam
!= 0, FindFocus());
967 case WM_SETTINGCHANGE
:
969 SHACTIVATEINFO
* info
= (SHACTIVATEINFO
*) m_activateInfo
;
971 SHHandleWMSettingChange(GetHwnd(), wParam
, lParam
, info
);
977 wxActivateEvent
event(wxEVT_HIBERNATE
, true, wxID_ANY
);
978 event
.SetEventObject(wxTheApp
);
982 processed
= wxTheApp
->ProcessEvent(event
);
989 // if we can't close, tell the system that we processed the
990 // message - otherwise it would close us
991 processed
= !Close();
995 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
1002 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
1005 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
1010 processed
= HandlePaint();
1013 case WM_INITMENUPOPUP
:
1014 processed
= HandleInitMenuPopup((WXHMENU
) wParam
);
1017 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
1022 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
1024 processed
= HandleMenuSelect(item
, flags
, hmenu
);
1028 case WM_EXITMENULOOP
:
1029 processed
= HandleMenuLoop(wxEVT_MENU_CLOSE
, (WXWORD
)wParam
);
1032 case WM_QUERYDRAGICON
:
1034 const wxIcon
& icon
= GetIcon();
1035 HICON hIcon
= icon
.Ok() ? GetHiconOf(icon
)
1036 : (HICON
)GetDefaultIcon();
1038 processed
= rc
!= 0;
1041 #endif // !__WXMICROWIN__
1045 rc
= wxFrameBase::MSWWindowProc(message
, wParam
, lParam
);
1050 // handle WM_INITMENUPOPUP message
1051 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu
)
1053 wxMenu
* menu
= NULL
;
1056 int nCount
= GetMenuBar()->GetMenuCount();
1057 for (int n
= 0; n
< nCount
; n
++)
1059 if (GetMenuBar()->GetMenu(n
)->GetHMenu() == hMenu
)
1061 menu
= GetMenuBar()->GetMenu(n
);
1067 wxMenuEvent
event(wxEVT_MENU_OPEN
, 0, menu
);
1068 event
.SetEventObject(this);
1070 return GetEventHandler()->ProcessEvent(event
);
1073 // ----------------------------------------------------------------------------
1074 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1075 // from the client area, so the client area is what's really available for the
1077 // ----------------------------------------------------------------------------
1079 // get the origin of the client area in the client coordinates
1080 wxPoint
wxFrame::GetClientAreaOrigin() const
1082 wxPoint pt
= wxTopLevelWindow::GetClientAreaOrigin();
1084 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1085 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1086 wxToolBar
*toolbar
= GetToolBar();
1087 if ( toolbar
&& toolbar
->IsShown() )
1090 toolbar
->GetSize(&w
, &h
);
1092 if ( toolbar
->GetWindowStyleFlag() & wxTB_VERTICAL
)
1101 #endif // wxUSE_TOOLBAR
1103 #if defined(WINCE_WITH_COMMANDBAR)
1104 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1107 ::GetWindowRect((HWND
) GetMenuBar()->GetCommandBar(), &rect
);
1108 pt
.y
+= (rect
.bottom
- rect
.top
);