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