don't include generic/statusbr.h directly
[wxWidgets.git] / src / msw / frame.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/frame.cpp
3 // Purpose: wxFrame
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/frame.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
31 #include "wx/app.h"
32 #include "wx/menu.h"
33 #include "wx/utils.h"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/dcclient.h"
37 #include "wx/mdi.h"
38 #include "wx/panel.h"
39 #include "wx/log.h"
40 #include "wx/toolbar.h"
41 #include "wx/statusbr.h"
42 #include "wx/menuitem.h"
43 #endif // WX_PRECOMP
44
45 #include "wx/msw/private.h"
46
47 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
48 #include <ole2.h>
49 #include <aygshell.h>
50 #include "wx/msw/winundef.h"
51 #endif
52
53 #ifdef __WXUNIVERSAL__
54 #include "wx/univ/theme.h"
55 #include "wx/univ/colschem.h"
56 #endif // __WXUNIVERSAL__
57
58 // ----------------------------------------------------------------------------
59 // globals
60 // ----------------------------------------------------------------------------
61
62 #if wxUSE_MENUS_NATIVE
63 extern wxMenu *wxCurrentPopupMenu;
64 #endif // wxUSE_MENUS_NATIVE
65
66 // ----------------------------------------------------------------------------
67 // event tables
68 // ----------------------------------------------------------------------------
69
70 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
71 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
72 END_EVENT_TABLE()
73
74 #if wxUSE_EXTENDED_RTTI
75 WX_DEFINE_FLAGS( wxFrameStyle )
76
77 wxBEGIN_FLAGS( wxFrameStyle )
78 // new style border flags, we put them first to
79 // use them for streaming out
80 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
81 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
82 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
83 wxFLAGS_MEMBER(wxBORDER_RAISED)
84 wxFLAGS_MEMBER(wxBORDER_STATIC)
85 wxFLAGS_MEMBER(wxBORDER_NONE)
86
87 // old style border flags
88 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
89 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
90 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
91 wxFLAGS_MEMBER(wxRAISED_BORDER)
92 wxFLAGS_MEMBER(wxSTATIC_BORDER)
93 wxFLAGS_MEMBER(wxBORDER)
94
95 // standard window styles
96 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
97 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
98 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
99 wxFLAGS_MEMBER(wxWANTS_CHARS)
100 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
101 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
102 wxFLAGS_MEMBER(wxVSCROLL)
103 wxFLAGS_MEMBER(wxHSCROLL)
104
105 // frame styles
106 wxFLAGS_MEMBER(wxSTAY_ON_TOP)
107 wxFLAGS_MEMBER(wxCAPTION)
108 #if WXWIN_COMPATIBILITY_2_6
109 wxFLAGS_MEMBER(wxTHICK_FRAME)
110 #endif // WXWIN_COMPATIBILITY_2_6
111 wxFLAGS_MEMBER(wxSYSTEM_MENU)
112 wxFLAGS_MEMBER(wxRESIZE_BORDER)
113 #if WXWIN_COMPATIBILITY_2_6
114 wxFLAGS_MEMBER(wxRESIZE_BOX)
115 #endif // WXWIN_COMPATIBILITY_2_6
116 wxFLAGS_MEMBER(wxCLOSE_BOX)
117 wxFLAGS_MEMBER(wxMAXIMIZE_BOX)
118 wxFLAGS_MEMBER(wxMINIMIZE_BOX)
119
120 wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW)
121 wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT)
122
123 wxFLAGS_MEMBER(wxFRAME_SHAPED)
124
125 wxEND_FLAGS( wxFrameStyle )
126
127 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow,"wx/frame.h")
128
129 wxBEGIN_PROPERTIES_TABLE(wxFrame)
130 wxEVENT_PROPERTY( Menu , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent)
131
132 wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
133 wxPROPERTY_FLAGS( WindowStyle , wxFrameStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
134 wxPROPERTY( MenuBar , wxMenuBar * , SetMenuBar , GetMenuBar , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
135 wxEND_PROPERTIES_TABLE()
136
137 wxBEGIN_HANDLERS_TABLE(wxFrame)
138 wxEND_HANDLERS_TABLE()
139
140 wxCONSTRUCTOR_6( wxFrame , wxWindow* , Parent , wxWindowID , Id , wxString , Title , wxPoint , Position , wxSize , Size , long , WindowStyle)
141
142 #else
143 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
144 #endif
145
146 // ============================================================================
147 // implementation
148 // ============================================================================
149
150 // ----------------------------------------------------------------------------
151 // static class members
152 // ----------------------------------------------------------------------------
153
154 #if wxUSE_STATUSBAR
155 #if wxUSE_NATIVE_STATUSBAR
156 bool wxFrame::m_useNativeStatusBar = true;
157 #else
158 bool wxFrame::m_useNativeStatusBar = false;
159 #endif
160 #endif // wxUSE_NATIVE_STATUSBAR
161
162 // ----------------------------------------------------------------------------
163 // creation/destruction
164 // ----------------------------------------------------------------------------
165
166 void wxFrame::Init()
167 {
168 #if wxUSE_MENUS
169 m_hMenu = NULL;
170 #endif // wxUSE_MENUS
171
172 #if wxUSE_TOOLTIPS
173 m_hwndToolTip = 0;
174 #endif
175
176 m_wasMinimized = false;
177 }
178
179 bool wxFrame::Create(wxWindow *parent,
180 wxWindowID id,
181 const wxString& title,
182 const wxPoint& pos,
183 const wxSize& size,
184 long style,
185 const wxString& name)
186 {
187 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
188 return false;
189
190 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
191
192 #if defined(__SMARTPHONE__)
193 SetLeftMenu(wxID_EXIT, _("Done"));
194 #endif
195
196 #if wxUSE_ACCEL && defined(__POCKETPC__)
197 // The guidelines state that Ctrl+Q should quit the app.
198 // Let's define an accelerator table to send wxID_EXIT.
199 wxAcceleratorEntry entries[1];
200 entries[0].Set(wxACCEL_CTRL, 'Q', wxID_EXIT);
201 wxAcceleratorTable accel(1, entries);
202 SetAcceleratorTable(accel);
203 #endif // wxUSE_ACCEL && __POCKETPC__
204
205 return true;
206 }
207
208 wxFrame::~wxFrame()
209 {
210 m_isBeingDeleted = true;
211 DeleteAllBars();
212 }
213
214 // ----------------------------------------------------------------------------
215 // wxFrame client size calculations
216 // ----------------------------------------------------------------------------
217
218 void wxFrame::DoSetClientSize(int width, int height)
219 {
220 // leave enough space for the status bar if we have (and show) it
221 #if wxUSE_STATUSBAR
222 wxStatusBar *statbar = GetStatusBar();
223 if ( statbar && statbar->IsShown() )
224 {
225 height += statbar->GetSize().y;
226 }
227 #endif // wxUSE_STATUSBAR
228
229 // call GetClientAreaOrigin() to take the toolbar into account
230 wxPoint pt = GetClientAreaOrigin();
231 width += pt.x;
232 height += pt.y;
233
234 wxTopLevelWindow::DoSetClientSize(width, height);
235 }
236
237 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
238 void wxFrame::DoGetClientSize(int *x, int *y) const
239 {
240 wxTopLevelWindow::DoGetClientSize(x, y);
241
242 // account for the possible toolbar
243 wxPoint pt = GetClientAreaOrigin();
244 if ( x )
245 *x -= pt.x;
246
247 if ( y )
248 *y -= pt.y;
249
250 #if wxUSE_STATUSBAR
251 // adjust client area height to take the status bar into account
252 if ( y )
253 {
254 wxStatusBar *statbar = GetStatusBar();
255 if ( statbar && statbar->IsShown() )
256 {
257 *y -= statbar->GetClientSize().y;
258 }
259 }
260 #endif // wxUSE_STATUSBAR
261 }
262
263 // ----------------------------------------------------------------------------
264 // wxFrame: various geometry-related functions
265 // ----------------------------------------------------------------------------
266
267 void wxFrame::Raise()
268 {
269 ::SetForegroundWindow(GetHwnd());
270 }
271
272 // generate an artificial resize event
273 void wxFrame::SendSizeEvent()
274 {
275 if ( !m_iconized )
276 {
277 RECT r = wxGetWindowRect(GetHwnd());
278
279 (void)::PostMessage(GetHwnd(), WM_SIZE,
280 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
281 MAKELPARAM(r.right - r.left, r.bottom - r.top));
282 }
283 }
284
285 #if wxUSE_STATUSBAR
286 wxStatusBar *wxFrame::OnCreateStatusBar(int number,
287 long style,
288 wxWindowID id,
289 const wxString& name)
290 {
291 wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL);
292
293 #if wxUSE_NATIVE_STATUSBAR
294 if ( !UsesNativeStatusBar() )
295 {
296 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
297 }
298 else
299 #endif
300 {
301 statusBar = new wxStatusBar(this, id, style, name);
302 }
303
304 statusBar->SetFieldsCount(number);
305
306 return statusBar;
307 }
308
309 void wxFrame::PositionStatusBar()
310 {
311 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
312 return;
313
314 int w, h;
315 GetClientSize(&w, &h);
316 int sw, sh;
317 m_frameStatusBar->GetSize(&sw, &sh);
318
319 // Since we wish the status bar to be directly under the client area,
320 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
321 m_frameStatusBar->SetSize(0, h, w, sh);
322 }
323 #endif // wxUSE_STATUSBAR
324
325 #if wxUSE_MENUS_NATIVE
326
327 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
328 {
329 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
330
331 wxMenu *autoMenu = NULL;
332
333 if( menubar->GetMenuCount() == 1 )
334 {
335 autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0));
336 SetRightMenu(wxID_ANY, menubar->GetLabelTop(0), autoMenu);
337 }
338 else
339 {
340 autoMenu = new wxMenu;
341
342 for( size_t n = 0; n < menubar->GetMenuCount(); n++ )
343 {
344 wxMenu *item = menubar->GetMenu(n);
345 wxString label = menubar->GetLabelTop(n);
346 wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item);
347 autoMenu->Append(wxID_ANY, label, new_item);
348 }
349
350 SetRightMenu(wxID_ANY, _("Menu"), autoMenu);
351 }
352
353 #elif defined(WINCE_WITHOUT_COMMANDBAR)
354 if (!GetToolBar())
355 {
356 wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY,
357 wxDefaultPosition, wxDefaultSize,
358 wxBORDER_NONE | wxTB_HORIZONTAL,
359 wxToolBarNameStr, menubar);
360 SetToolBar(toolBar);
361 menubar->SetToolBar(toolBar);
362 }
363 // Now adjust size for menu bar
364 int menuHeight = 26;
365
366 //When the main window is created using CW_USEDEFAULT the height of the
367 // is created is not taken into account). So we resize the window after
368 // if a menubar is present
369 {
370 RECT rc;
371 ::GetWindowRect((HWND) GetHWND(), &rc);
372 // adjust for menu / titlebar height
373 rc.bottom -= (2*menuHeight-1);
374
375 ::MoveWindow((HWND) GetHWND(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
376 }
377 #endif
378
379 wxFrameBase::AttachMenuBar(menubar);
380
381 if ( !menubar )
382 {
383 // actually remove the menu from the frame
384 m_hMenu = (WXHMENU)0;
385 InternalSetMenuBar();
386 }
387 else // set new non NULL menu bar
388 {
389 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
390 // Can set a menubar several times.
391 if ( menubar->GetHMenu() )
392 {
393 m_hMenu = menubar->GetHMenu();
394 }
395 else // no HMENU yet
396 {
397 m_hMenu = menubar->Create();
398
399 if ( !m_hMenu )
400 {
401 wxFAIL_MSG( _T("failed to create menu bar") );
402 return;
403 }
404 }
405 #endif
406 InternalSetMenuBar();
407 }
408 }
409
410 void wxFrame::InternalSetMenuBar()
411 {
412 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
413 // Nothing
414 #else
415 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
416 {
417 wxLogLastError(wxT("SetMenu"));
418 }
419 #endif
420 }
421
422 #endif // wxUSE_MENUS_NATIVE
423
424 // Responds to colour changes, and passes event on to children.
425 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
426 {
427 SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
428 Refresh();
429
430 #if wxUSE_STATUSBAR
431 if ( m_frameStatusBar )
432 {
433 wxSysColourChangedEvent event2;
434 event2.SetEventObject( m_frameStatusBar );
435 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
436 }
437 #endif // wxUSE_STATUSBAR
438
439 // Propagate the event to the non-top-level children
440 wxWindow::OnSysColourChanged(event);
441 }
442
443 // Pass true to show full screen, false to restore.
444 bool wxFrame::ShowFullScreen(bool show, long style)
445 {
446 // TODO-CE: add support for CE
447 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
448 if ( IsFullScreen() == show )
449 return false;
450
451 if (show)
452 {
453 // zap the toolbar, menubar, and statusbar if needed
454 //
455 // TODO: hide commandbar for WINCE_WITH_COMMANDBAR
456 #if wxUSE_TOOLBAR
457 wxToolBar *theToolBar = GetToolBar();
458
459 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
460 {
461 if ( theToolBar->IsShown() )
462 {
463 theToolBar->SetSize(wxDefaultCoord,0);
464 theToolBar->Show(false);
465 }
466 else // prevent it from being restored later
467 {
468 style &= ~wxFULLSCREEN_NOTOOLBAR;
469 }
470 }
471 #endif // wxUSE_TOOLBAR
472
473 if (style & wxFULLSCREEN_NOMENUBAR)
474 SetMenu((HWND)GetHWND(), (HMENU) NULL);
475
476 #if wxUSE_STATUSBAR
477 wxStatusBar *theStatusBar = GetStatusBar();
478
479 // Save the number of fields in the statusbar
480 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
481 {
482 if ( theStatusBar->IsShown() )
483 theStatusBar->Show(false);
484 else
485 style &= ~wxFULLSCREEN_NOSTATUSBAR;
486 }
487 #endif // wxUSE_STATUSBAR
488 }
489 else // restore to normal
490 {
491 // restore the toolbar, menubar, and statusbar if we had hid them
492 #if wxUSE_TOOLBAR
493 wxToolBar *theToolBar = GetToolBar();
494
495 if ((m_fsStyle & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
496 {
497 theToolBar->Show(true);
498 }
499 #endif // wxUSE_TOOLBAR
500
501 if (m_fsStyle & wxFULLSCREEN_NOMENUBAR)
502 {
503 WXHMENU menu = m_hMenu;
504
505 #if wxUSE_MDI_ARCHITECTURE
506 wxMDIParentFrame *frame = wxDynamicCast(this, wxMDIParentFrame);
507 if (frame)
508 {
509 wxMDIChildFrame *child = frame->GetActiveChild();
510 if (child)
511 {
512 menu = child->GetWinMenu();
513 }
514 }
515 #endif // wxUSE_MDI_ARCHITECTURE
516
517 if (menu)
518 {
519 ::SetMenu(GetHwnd(), (HMENU)menu);
520 }
521 }
522
523 #if wxUSE_STATUSBAR
524 wxStatusBar *theStatusBar = GetStatusBar();
525
526 if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
527 {
528 theStatusBar->Show(true);
529 PositionStatusBar();
530 }
531 #endif // wxUSE_STATUSBAR
532 }
533 #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
534
535 return wxFrameBase::ShowFullScreen(show, style);
536 }
537
538 // ----------------------------------------------------------------------------
539 // tool/status bar stuff
540 // ----------------------------------------------------------------------------
541
542 #if wxUSE_TOOLBAR
543
544 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
545 {
546 #if defined(WINCE_WITHOUT_COMMANDBAR)
547 // We may already have a toolbar from calling SetMenuBar.
548 if (GetToolBar())
549 return GetToolBar();
550 #endif
551 if ( wxFrameBase::CreateToolBar(style, id, name) )
552 {
553 PositionToolBar();
554 }
555
556 return m_frameToolBar;
557 }
558
559 void wxFrame::PositionToolBar()
560 {
561 wxToolBar *toolbar = GetToolBar();
562 if ( toolbar && toolbar->IsShown() )
563 {
564 #if defined(WINCE_WITHOUT_COMMANDBAR)
565 // We want to do something different in WinCE, because
566 // the toolbar should be associated with the commandbar,
567 // and not an independent window.
568 // TODO
569 #else
570 // don't call our (or even wxTopLevelWindow) version because we want
571 // the real (full) client area size, not excluding the tool/status bar
572 int width, height;
573 wxWindow::DoGetClientSize(&width, &height);
574
575 #if wxUSE_STATUSBAR
576 wxStatusBar *statbar = GetStatusBar();
577 if ( statbar && statbar->IsShown() )
578 {
579 height -= statbar->GetClientSize().y;
580 }
581 #endif // wxUSE_STATUSBAR
582
583 int x = 0;
584 int y = 0;
585 #if defined(WINCE_WITH_COMMANDBAR)
586 // We're using a commandbar - so we have to allow for it.
587 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
588 {
589 RECT rect;
590 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
591 y = rect.bottom - rect.top;
592 }
593 #endif
594
595 int tx, ty;
596 int tw, th;
597 toolbar->GetPosition(&tx, &ty);
598 toolbar->GetSize(&tw, &th);
599
600 // Adjust
601 if (ty < 0 && (-ty == th))
602 ty = 0;
603 if (tx < 0 && (-tx == tw))
604 tx = 0;
605
606 int desiredW = tw;
607 int desiredH = th;
608
609 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
610 {
611 desiredH = height;
612 }
613 else
614 {
615 desiredW = width;
616 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
617 // desiredW -= 3;
618 }
619
620 // use the 'real' MSW position here, don't offset relativly to the
621 // client area origin
622
623 // Optimise such that we don't have to always resize the toolbar
624 // when the frame changes, otherwise we'll get a lot of flicker.
625 bool heightChanging wxDUMMY_INITIALIZE(true);
626 bool widthChanging wxDUMMY_INITIALIZE(true);
627
628 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
629 {
630 // It's OK if the current height is greater than what can be shown.
631 heightChanging = (desiredH > th) ;
632 widthChanging = (desiredW != tw) ;
633
634 // The next time around, we may not have to set the size
635 if (heightChanging)
636 desiredH = desiredH + 200;
637 }
638 else
639 {
640 // It's OK if the current width is greater than what can be shown.
641 widthChanging = (desiredW > tw) ;
642 heightChanging = (desiredH != th) ;
643
644 // The next time around, we may not have to set the size
645 if (widthChanging)
646 desiredW = desiredW + 200;
647 }
648
649 if (tx != 0 || ty != 0 || widthChanging || heightChanging)
650 toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
651
652 #endif // __WXWINCE__
653 }
654 }
655
656 #endif // wxUSE_TOOLBAR
657
658 // ----------------------------------------------------------------------------
659 // frame state (iconized/maximized/...)
660 // ----------------------------------------------------------------------------
661
662 // propagate our state change to all child frames: this allows us to emulate X
663 // Windows behaviour where child frames float independently of the parent one
664 // on the desktop, but are iconized/restored with it
665 void wxFrame::IconizeChildFrames(bool bIconize)
666 {
667 m_iconized = bIconize;
668
669 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
670 node;
671 node = node->GetNext() )
672 {
673 wxWindow *win = node->GetData();
674
675 // iconizing the frames with this style under Win95 shell puts them at
676 // the bottom of the screen (as the MDI children) instead of making
677 // them appear in the taskbar because they are, by virtue of this
678 // style, not managed by the taskbar - instead leave Windows take care
679 // of them
680 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
681 continue;
682
683 // the child MDI frames are a special case and should not be touched by
684 // the parent frame - instead, they are managed by the user
685 wxFrame *frame = wxDynamicCast(win, wxFrame);
686 if ( frame
687 #if wxUSE_MDI_ARCHITECTURE
688 && !frame->IsMDIChild()
689 #endif // wxUSE_MDI_ARCHITECTURE
690 )
691 {
692 // we don't want to restore the child frames which had been
693 // iconized even before we were iconized, so save the child frame
694 // status when iconizing the parent frame and check it when
695 // restoring it
696 if ( bIconize )
697 {
698 frame->m_wasMinimized = frame->IsIconized();
699 }
700
701 // note that we shouldn't touch the hidden frames neither because
702 // iconizing/restoring them would show them as a side effect
703 if ( !frame->m_wasMinimized && frame->IsShown() )
704 frame->Iconize(bIconize);
705 }
706 }
707 }
708
709 WXHICON wxFrame::GetDefaultIcon() const
710 {
711 // we don't have any standard icons (any more)
712 return (WXHICON)0;
713 }
714
715 // ===========================================================================
716 // message processing
717 // ===========================================================================
718
719 // ---------------------------------------------------------------------------
720 // preprocessing
721 // ---------------------------------------------------------------------------
722
723 bool wxFrame::MSWDoTranslateMessage(wxFrame *frame, WXMSG *pMsg)
724 {
725 if ( wxWindow::MSWTranslateMessage(pMsg) )
726 return true;
727
728 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
729 // try the menu bar accels
730 wxMenuBar *menuBar = GetMenuBar();
731 if ( menuBar )
732 {
733 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
734 return acceleratorTable.Translate(frame, pMsg);
735 }
736 #endif // wxUSE_MENUS && wxUSE_ACCEL
737
738 return false;
739 }
740
741 // ---------------------------------------------------------------------------
742 // our private (non virtual) message handlers
743 // ---------------------------------------------------------------------------
744
745 bool wxFrame::HandlePaint()
746 {
747 RECT rect;
748 if ( ::GetUpdateRect(GetHwnd(), &rect, FALSE) )
749 {
750 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
751 if ( m_iconized )
752 {
753 const wxIcon& icon = GetIcon();
754 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
755 : (HICON)GetDefaultIcon();
756
757 // Hold a pointer to the dc so long as the OnPaint() message
758 // is being processed
759 PAINTSTRUCT ps;
760 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
761
762 // Erase background before painting or we get white background
763 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
764
765 if ( hIcon )
766 {
767 RECT rect;
768 ::GetClientRect(GetHwnd(), &rect);
769
770 // FIXME: why hardcoded?
771 static const int icon_width = 32;
772 static const int icon_height = 32;
773
774 int icon_x = (int)((rect.right - icon_width)/2);
775 int icon_y = (int)((rect.bottom - icon_height)/2);
776
777 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
778 }
779
780 ::EndPaint(GetHwnd(), &ps);
781
782 return true;
783 }
784 else
785 #endif
786 {
787 return wxWindow::HandlePaint();
788 }
789 }
790 else
791 {
792 // nothing to paint - processed
793 return true;
794 }
795 }
796
797 bool wxFrame::HandleSize(int WXUNUSED(x), int WXUNUSED(y), WXUINT id)
798 {
799 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
800 switch ( id )
801 {
802 case SIZE_RESTORED:
803 case SIZE_MAXIMIZED:
804 // only do it it if we were iconized before, otherwise resizing the
805 // parent frame has a curious side effect of bringing it under it's
806 // children
807 if ( !m_iconized )
808 break;
809
810 // restore all child frames too
811 IconizeChildFrames(false);
812
813 (void)SendIconizeEvent(false);
814 break;
815
816 case SIZE_MINIMIZED:
817 // iconize all child frames too
818 IconizeChildFrames(true);
819 break;
820 }
821 #else
822 wxUnusedVar(id);
823 #endif // !__WXWINCE__
824
825 if ( !m_iconized )
826 {
827 #if wxUSE_STATUSBAR
828 PositionStatusBar();
829 #endif // wxUSE_STATUSBAR
830
831 #if wxUSE_TOOLBAR
832 PositionToolBar();
833 #endif // wxUSE_TOOLBAR
834
835 #if defined(WINCE_WITH_COMMANDBAR)
836 // Position the menu command bar
837 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
838 {
839 RECT rect;
840 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
841 wxSize clientSz = GetClientSize();
842
843 if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) )
844 {
845 wxLogLastError(wxT("MoveWindow"));
846 }
847
848 }
849 #endif // WINCE_WITH_COMMANDBAR
850 }
851
852 // call the base class version to generate the appropriate events
853 return false;
854 }
855
856 bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
857 {
858 if ( control )
859 {
860 // In case it's e.g. a toolbar.
861 wxWindow *win = wxFindWinFromHandle(control);
862 if ( win )
863 return win->MSWCommand(cmd, id);
864 }
865
866 // handle here commands from menus and accelerators
867 if ( cmd == 0 || cmd == 1 )
868 {
869 #if wxUSE_MENUS_NATIVE
870 if ( wxCurrentPopupMenu )
871 {
872 wxMenu *popupMenu = wxCurrentPopupMenu;
873 wxCurrentPopupMenu = NULL;
874
875 return popupMenu->MSWCommand(cmd, id);
876 }
877 #endif // wxUSE_MENUS_NATIVE
878
879 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
880 // handle here commands from Smartphone menu bar
881 if ( wxTopLevelWindow::HandleCommand(id, cmd, control ) )
882 {
883 return true;
884 }
885 #endif // __SMARTPHONE__ && __WXWINCE__
886
887 if ( ProcessCommand(id) )
888 {
889 return true;
890 }
891 }
892
893 return false;
894 }
895
896 bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
897 {
898 int item;
899 if ( flags == 0xFFFF && hMenu == 0 )
900 {
901 // menu was removed from screen
902 item = -1;
903 }
904 #ifndef __WXMICROWIN__
905 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
906 {
907 item = nItem;
908 }
909 #endif
910 else
911 {
912 // don't give hints for separators (doesn't make sense) nor for the
913 // items opening popup menus (they don't have them anyhow) but do clear
914 // the status line - otherwise, we would be left with the help message
915 // for the previous item which doesn't apply any more
916 DoGiveHelp(wxEmptyString, false);
917
918 return false;
919 }
920
921 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
922 event.SetEventObject(this);
923
924 return GetEventHandler()->ProcessEvent(event);
925 }
926
927 bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup)
928 {
929 // we don't have the menu id here, so we use the id to specify if the event
930 // was from a popup menu or a normal one
931 wxMenuEvent event(evtType, isPopup ? -1 : 0);
932 event.SetEventObject(this);
933
934 return GetEventHandler()->ProcessEvent(event);
935 }
936
937 // ---------------------------------------------------------------------------
938 // the window proc for wxFrame
939 // ---------------------------------------------------------------------------
940
941 WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
942 {
943 WXLRESULT rc = 0;
944 bool processed = false;
945
946 switch ( message )
947 {
948 case WM_CLOSE:
949 // if we can't close, tell the system that we processed the
950 // message - otherwise it would close us
951 processed = !Close();
952 break;
953
954 case WM_SIZE:
955 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
956 break;
957
958 case WM_COMMAND:
959 {
960 WORD id, cmd;
961 WXHWND hwnd;
962 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
963 &id, &hwnd, &cmd);
964
965 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
966 }
967 break;
968
969 case WM_PAINT:
970 processed = HandlePaint();
971 break;
972
973 case WM_INITMENUPOPUP:
974 processed = HandleInitMenuPopup((WXHMENU) wParam);
975 break;
976
977 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
978 case WM_MENUSELECT:
979 {
980 WXWORD item, flags;
981 WXHMENU hmenu;
982 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
983
984 processed = HandleMenuSelect(item, flags, hmenu);
985 }
986 break;
987
988 case WM_EXITMENULOOP:
989 processed = HandleMenuLoop(wxEVT_MENU_CLOSE, (WXWORD)wParam);
990 break;
991
992 case WM_QUERYDRAGICON:
993 {
994 const wxIcon& icon = GetIcon();
995 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
996 : (HICON)GetDefaultIcon();
997 rc = (long)hIcon;
998 processed = rc != 0;
999 }
1000 break;
1001 #endif // !__WXMICROWIN__
1002 }
1003
1004 if ( !processed )
1005 rc = wxFrameBase::MSWWindowProc(message, wParam, lParam);
1006
1007 return rc;
1008 }
1009
1010 // handle WM_INITMENUPOPUP message
1011 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu)
1012 {
1013 wxMenu* menu = NULL;
1014 if (GetMenuBar())
1015 {
1016 int nCount = GetMenuBar()->GetMenuCount();
1017 for (int n = 0; n < nCount; n++)
1018 {
1019 if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu)
1020 {
1021 menu = GetMenuBar()->GetMenu(n);
1022 break;
1023 }
1024 }
1025 }
1026
1027 wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu);
1028 event.SetEventObject(this);
1029
1030 return GetEventHandler()->ProcessEvent(event);
1031 }
1032
1033 // ----------------------------------------------------------------------------
1034 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1035 // from the client area, so the client area is what's really available for the
1036 // frame contents
1037 // ----------------------------------------------------------------------------
1038
1039 // get the origin of the client area in the client coordinates
1040 wxPoint wxFrame::GetClientAreaOrigin() const
1041 {
1042 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
1043
1044 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1045 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1046 wxToolBar *toolbar = GetToolBar();
1047 if ( toolbar && toolbar->IsShown() )
1048 {
1049 int w, h;
1050 toolbar->GetSize(&w, &h);
1051
1052 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
1053 {
1054 pt.x += w;
1055 }
1056 else
1057 {
1058 pt.y += h;
1059 }
1060 }
1061 #endif // wxUSE_TOOLBAR
1062
1063 #if defined(WINCE_WITH_COMMANDBAR)
1064 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1065 {
1066 RECT rect;
1067 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
1068 pt.y += (rect.bottom - rect.top);
1069 }
1070 #endif
1071
1072 return pt;
1073 }