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