Fixes to warnings about assigning unused values.
[wxWidgets.git] / src / msw / frame.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "frame.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/frame.h"
33 #include "wx/app.h"
34 #include "wx/menu.h"
35 #include "wx/utils.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/dcclient.h"
39 #include "wx/mdi.h"
40 #include "wx/panel.h"
41 #endif // WX_PRECOMP
42
43 #include "wx/msw/private.h"
44
45 #ifdef __WXWINCE__
46 #include <commctrl.h>
47 #endif
48
49 #if wxUSE_STATUSBAR
50 #include "wx/statusbr.h"
51 #include "wx/generic/statusbr.h"
52 #endif // wxUSE_STATUSBAR
53
54 #if wxUSE_TOOLBAR
55 #include "wx/toolbar.h"
56 #endif // wxUSE_TOOLBAR
57
58 #include "wx/menuitem.h"
59 #include "wx/log.h"
60
61 #ifdef __WXUNIVERSAL__
62 #include "wx/univ/theme.h"
63 #include "wx/univ/colschem.h"
64 #endif // __WXUNIVERSAL__
65
66 // ----------------------------------------------------------------------------
67 // globals
68 // ----------------------------------------------------------------------------
69
70 #if wxUSE_MENUS_NATIVE
71 extern wxMenu *wxCurrentPopupMenu;
72 #endif // wxUSE_MENUS_NATIVE
73
74 // ----------------------------------------------------------------------------
75 // event tables
76 // ----------------------------------------------------------------------------
77
78 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
79 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
80 END_EVENT_TABLE()
81
82 #if wxUSE_EXTENDED_RTTI
83 WX_DEFINE_FLAGS( wxFrameStyle )
84
85 wxBEGIN_FLAGS( wxFrameStyle )
86 // new style border flags, we put them first to
87 // use them for streaming out
88 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
89 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
90 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
91 wxFLAGS_MEMBER(wxBORDER_RAISED)
92 wxFLAGS_MEMBER(wxBORDER_STATIC)
93 wxFLAGS_MEMBER(wxBORDER_NONE)
94
95 // old style border flags
96 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
97 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
98 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
99 wxFLAGS_MEMBER(wxRAISED_BORDER)
100 wxFLAGS_MEMBER(wxSTATIC_BORDER)
101 wxFLAGS_MEMBER(wxBORDER)
102
103 // standard window styles
104 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
105 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
106 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
107 wxFLAGS_MEMBER(wxWANTS_CHARS)
108 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
109 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
110 wxFLAGS_MEMBER(wxVSCROLL)
111 wxFLAGS_MEMBER(wxHSCROLL)
112
113 // frame styles
114 wxFLAGS_MEMBER(wxSTAY_ON_TOP)
115 wxFLAGS_MEMBER(wxCAPTION)
116 wxFLAGS_MEMBER(wxTHICK_FRAME)
117 wxFLAGS_MEMBER(wxSYSTEM_MENU)
118 wxFLAGS_MEMBER(wxRESIZE_BORDER)
119 wxFLAGS_MEMBER(wxRESIZE_BOX)
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_TOOLTIPS
173 m_hwndToolTip = 0;
174 #endif
175
176 // Data to save/restore when calling ShowFullScreen
177 m_fsStatusBarFields = 0;
178 m_fsStatusBarHeight = 0;
179 m_fsToolBarHeight = 0;
180
181 m_wasMinimized = FALSE;
182 }
183
184 bool wxFrame::Create(wxWindow *parent,
185 wxWindowID id,
186 const wxString& title,
187 const wxPoint& pos,
188 const wxSize& size,
189 long style,
190 const wxString& name)
191 {
192 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
193 return false;
194
195 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
196
197 #ifdef __SMARTPHONE__
198 SetLeftMenu(wxID_EXIT, _("Done"));
199 #endif
200
201 return true;
202 }
203
204 wxFrame::~wxFrame()
205 {
206 m_isBeingDeleted = TRUE;
207 DeleteAllBars();
208 }
209
210 // ----------------------------------------------------------------------------
211 // wxFrame client size calculations
212 // ----------------------------------------------------------------------------
213
214 void wxFrame::DoSetClientSize(int width, int height)
215 {
216 // leave enough space for the status bar if we have (and show) it
217 #if wxUSE_STATUSBAR
218 wxStatusBar *statbar = GetStatusBar();
219 if ( statbar && statbar->IsShown() )
220 {
221 height += statbar->GetSize().y;
222 }
223 #endif // wxUSE_STATUSBAR
224
225 // call GetClientAreaOrigin() to take the toolbar into account
226 wxPoint pt = GetClientAreaOrigin();
227 width += pt.x;
228 height += pt.y;
229
230 wxTopLevelWindow::DoSetClientSize(width, height);
231 }
232
233 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
234 void wxFrame::DoGetClientSize(int *x, int *y) const
235 {
236 wxTopLevelWindow::DoGetClientSize(x, y);
237
238 // account for the possible toolbar
239 wxPoint pt = GetClientAreaOrigin();
240 if ( x )
241 *x -= pt.x;
242
243 if ( y )
244 *y -= pt.y;
245
246 #if wxUSE_STATUSBAR
247 // adjust client area height to take the status bar into account
248 if ( y )
249 {
250 wxStatusBar *statbar = GetStatusBar();
251 if ( statbar && statbar->IsShown() )
252 {
253 *y -= statbar->GetClientSize().y;
254 }
255 }
256 #endif // wxUSE_STATUSBAR
257 }
258
259 // ----------------------------------------------------------------------------
260 // wxFrame: various geometry-related functions
261 // ----------------------------------------------------------------------------
262
263 void wxFrame::Raise()
264 {
265 ::SetForegroundWindow(GetHwnd());
266 }
267
268 // generate an artificial resize event
269 void wxFrame::SendSizeEvent()
270 {
271 if ( !m_iconized )
272 {
273 RECT r = wxGetWindowRect(GetHwnd());
274
275 (void)::PostMessage(GetHwnd(), WM_SIZE,
276 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
277 MAKELPARAM(r.right - r.left, r.bottom - r.top));
278 }
279 }
280
281 #if wxUSE_STATUSBAR
282 wxStatusBar *wxFrame::OnCreateStatusBar(int number,
283 long style,
284 wxWindowID id,
285 const wxString& name)
286 {
287 wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL);
288
289 #if wxUSE_NATIVE_STATUSBAR
290 if ( !UsesNativeStatusBar() )
291 {
292 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
293 }
294 else
295 #endif
296 {
297 statusBar = new wxStatusBar(this, id, style, name);
298 }
299
300 statusBar->SetFieldsCount(number);
301
302 return statusBar;
303 }
304
305 void wxFrame::PositionStatusBar()
306 {
307 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
308 return;
309
310 int w, h;
311 GetClientSize(&w, &h);
312 int sw, sh;
313 m_frameStatusBar->GetSize(&sw, &sh);
314
315 // Since we wish the status bar to be directly under the client area,
316 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
317 m_frameStatusBar->SetSize(0, h, w, sh);
318 }
319 #endif // wxUSE_STATUSBAR
320
321 #if wxUSE_MENUS_NATIVE
322
323 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
324 {
325 #if defined(__SMARTPHONE__)
326
327 wxMenu *autoMenu = NULL;
328
329 if( menubar->GetMenuCount() == 1 )
330 {
331 autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0));
332 SetRightMenu(wxID_ANY, menubar->GetLabelTop(0), autoMenu);
333 }
334 else
335 {
336 autoMenu = new wxMenu;
337
338 for( size_t n = 0; n < menubar->GetMenuCount(); n++ )
339 {
340 wxMenu *item = menubar->GetMenu(n);
341 wxString label = menubar->GetLabelTop(n);
342 wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item);
343 autoMenu->Append(wxID_ANY, label, new_item);
344 }
345
346 SetRightMenu(wxID_ANY, _("Menu"), autoMenu);
347 }
348
349 #elif defined(WINCE_WITHOUT_COMMANDBAR)
350 if (!GetToolBar())
351 {
352 wxToolBar* toolBar = new wxToolBar(this, -1,
353 wxDefaultPosition, wxDefaultSize,
354 wxBORDER_NONE | wxTB_HORIZONTAL,
355 wxToolBarNameStr, menubar);
356 SetToolBar(toolBar);
357 menubar->SetToolBar(toolBar);
358 }
359 // Now adjust size for menu bar
360 int menuHeight = 26;
361
362 //When the main window is created using CW_USEDEFAULT the height of the
363 // is created is not taken into account). So we resize the window after
364 // if a menubar is present
365 {
366 RECT rc;
367 ::GetWindowRect((HWND) GetHWND(), &rc);
368 // adjust for menu / titlebar height
369 rc.bottom -= (2*menuHeight-1);
370
371 MoveWindow((HWND) GetHWND(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
372 }
373 #endif
374
375 wxFrameBase::AttachMenuBar(menubar);
376
377 if ( !menubar )
378 {
379 // actually remove the menu from the frame
380 m_hMenu = (WXHMENU)0;
381 InternalSetMenuBar();
382 }
383 else // set new non NULL menu bar
384 {
385 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
386 // Can set a menubar several times.
387 if ( menubar->GetHMenu() )
388 {
389 m_hMenu = menubar->GetHMenu();
390 }
391 else // no HMENU yet
392 {
393 m_hMenu = menubar->Create();
394
395 if ( !m_hMenu )
396 {
397 wxFAIL_MSG( _T("failed to create menu bar") );
398 return;
399 }
400 }
401 #endif
402 InternalSetMenuBar();
403 }
404 }
405
406 void wxFrame::InternalSetMenuBar()
407 {
408 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
409 // Nothing
410 #else
411 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
412 {
413 wxLogLastError(wxT("SetMenu"));
414 }
415 #endif
416 }
417
418 #endif // wxUSE_MENUS_NATIVE
419
420 // Responds to colour changes, and passes event on to children.
421 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
422 {
423 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
424 Refresh();
425
426 #if wxUSE_STATUSBAR
427 if ( m_frameStatusBar )
428 {
429 wxSysColourChangedEvent event2;
430 event2.SetEventObject( m_frameStatusBar );
431 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
432 }
433 #endif // wxUSE_STATUSBAR
434
435 // Propagate the event to the non-top-level children
436 wxWindow::OnSysColourChanged(event);
437 }
438
439 // Pass TRUE to show full screen, FALSE to restore.
440 bool wxFrame::ShowFullScreen(bool show, long style)
441 {
442 if ( IsFullScreen() == show )
443 return FALSE;
444
445 if (show)
446 {
447 #if wxUSE_TOOLBAR
448
449 #if defined(WINCE_WITH_COMMANDBAR)
450 // TODO: hide commandbar
451 #else
452 wxToolBar *theToolBar = GetToolBar();
453 if (theToolBar)
454 theToolBar->GetSize(NULL, &m_fsToolBarHeight);
455
456 // zap the toolbar, menubar, and statusbar
457
458 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
459 {
460 theToolBar->SetSize(-1,0);
461 theToolBar->Show(FALSE);
462 }
463 #endif // __WXWINCE__
464 #endif // wxUSE_TOOLBAR
465
466 #if defined(__WXMICROWIN__)
467 #elif defined(__WXWINCE__)
468 // TODO: make it work for WinCE
469 #else
470 if (style & wxFULLSCREEN_NOMENUBAR)
471 SetMenu((HWND)GetHWND(), (HMENU) NULL);
472 #endif
473
474 #if wxUSE_STATUSBAR
475 wxStatusBar *theStatusBar = GetStatusBar();
476 if (theStatusBar)
477 theStatusBar->GetSize(NULL, &m_fsStatusBarHeight);
478
479 // Save the number of fields in the statusbar
480 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
481 {
482 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
483 //SetStatusBar((wxStatusBar*) NULL);
484 //delete theStatusBar;
485 theStatusBar->Show(FALSE);
486 }
487 else
488 m_fsStatusBarFields = 0;
489 #endif // wxUSE_STATUSBAR
490 }
491 else
492 {
493 #if wxUSE_TOOLBAR
494 #if defined(WINCE_WITHOUT_COMMANDBAR)
495 // TODO: show commandbar
496 #else
497 wxToolBar *theToolBar = GetToolBar();
498
499 // restore the toolbar, menubar, and statusbar
500 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
501 {
502 theToolBar->SetSize(-1, m_fsToolBarHeight);
503 theToolBar->Show(TRUE);
504 }
505 #endif // __WXWINCE__
506 #endif // wxUSE_TOOLBAR
507
508 #if wxUSE_STATUSBAR
509 if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR )
510 {
511 //CreateStatusBar(m_fsStatusBarFields);
512 if (GetStatusBar())
513 {
514 GetStatusBar()->Show(TRUE);
515 PositionStatusBar();
516 }
517 }
518 #endif // wxUSE_STATUSBAR
519
520 #if defined(__WXMICROWIN__)
521 #elif defined(__WXWINCE__)
522 // TODO: make it work for WinCE
523 #else
524 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
525 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
526 #endif
527 }
528
529 return wxFrameBase::ShowFullScreen(show, style);
530 }
531
532 // ----------------------------------------------------------------------------
533 // tool/status bar stuff
534 // ----------------------------------------------------------------------------
535
536 #if wxUSE_TOOLBAR
537
538 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
539 {
540 #if defined(WINCE_WITHOUT_COMMANDBAR)
541 // We may already have a toolbar from calling SetMenuBar.
542 if (GetToolBar())
543 return GetToolBar();
544 #endif
545 if ( wxFrameBase::CreateToolBar(style, id, name) )
546 {
547 PositionToolBar();
548 }
549
550 return m_frameToolBar;
551 }
552
553 void wxFrame::PositionToolBar()
554 {
555 wxToolBar *toolbar = GetToolBar();
556 if ( toolbar && toolbar->IsShown() )
557 {
558 #if defined(WINCE_WITHOUT_COMMANDBAR)
559 // We want to do something different in WinCE, because
560 // the toolbar should be associated with the commandbar,
561 // and not an independent window.
562 // TODO
563 #else
564 // don't call our (or even wxTopLevelWindow) version because we want
565 // the real (full) client area size, not excluding the tool/status bar
566 int width, height;
567 wxWindow::DoGetClientSize(&width, &height);
568
569 #if wxUSE_STATUSBAR
570 wxStatusBar *statbar = GetStatusBar();
571 if ( statbar && statbar->IsShown() )
572 {
573 height -= statbar->GetClientSize().y;
574 }
575 #endif // wxUSE_STATUSBAR
576
577 int x = 0;
578 int y = 0;
579 #if defined(WINCE_WITH_COMMANDBAR)
580 // We're using a commandbar - so we have to allow for it.
581 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
582 {
583 RECT rect;
584 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
585 y = rect.bottom - rect.top;
586 }
587 #endif
588
589 int tx, ty;
590 int tw, th;
591 toolbar->GetPosition(&tx, &ty);
592 toolbar->GetSize(&tw, &th);
593
594 // Adjust
595 if (ty < 0 && (-ty == th))
596 ty = 0;
597 if (tx < 0 && (-tx == tw))
598 tx = 0;
599
600 int desiredW = tw;
601 int desiredH = th;
602
603 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
604 {
605 desiredH = height;
606 }
607 else
608 {
609 desiredW = width;
610 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
611 // desiredW -= 3;
612 }
613
614 // use the 'real' MSW position here, don't offset relativly to the
615 // client area origin
616
617 // Optimise such that we don't have to always resize the toolbar
618 // when the frame changes, otherwise we'll get a lot of flicker.
619 bool heightChanging wxDUMMY_INITIALIZE(true);
620 bool widthChanging wxDUMMY_INITIALIZE(true);
621
622 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
623 {
624 // It's OK if the current height is greater than what can be shown.
625 heightChanging = (desiredH > th) ;
626 widthChanging = (desiredW != tw) ;
627
628 // The next time around, we may not have to set the size
629 if (heightChanging)
630 desiredH = desiredH + 200;
631 }
632 else
633 {
634 // It's OK if the current width is greater than what can be shown.
635 widthChanging = (desiredW > tw) ;
636 heightChanging = (desiredH != th) ;
637
638 // The next time around, we may not have to set the size
639 if (widthChanging)
640 desiredW = desiredW + 200;
641 }
642
643 if (tx != 0 || ty != 0 || widthChanging || heightChanging)
644 toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
645
646 #endif // __WXWINCE__
647 }
648 }
649
650 #endif // wxUSE_TOOLBAR
651
652 // ----------------------------------------------------------------------------
653 // frame state (iconized/maximized/...)
654 // ----------------------------------------------------------------------------
655
656 // propagate our state change to all child frames: this allows us to emulate X
657 // Windows behaviour where child frames float independently of the parent one
658 // on the desktop, but are iconized/restored with it
659 void wxFrame::IconizeChildFrames(bool bIconize)
660 {
661 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
662 node;
663 node = node->GetNext() )
664 {
665 wxWindow *win = node->GetData();
666
667 // iconizing the frames with this style under Win95 shell puts them at
668 // the bottom of the screen (as the MDI children) instead of making
669 // them appear in the taskbar because they are, by virtue of this
670 // style, not managed by the taskbar - instead leave Windows take care
671 // of them
672 #ifdef __WIN95__
673 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
674 continue;
675 #endif // Win95
676
677 // the child MDI frames are a special case and should not be touched by
678 // the parent frame - instead, they are managed by the user
679 wxFrame *frame = wxDynamicCast(win, wxFrame);
680 if ( frame
681 #if wxUSE_MDI_ARCHITECTURE
682 && !wxDynamicCast(frame, wxMDIChildFrame)
683 #endif // wxUSE_MDI_ARCHITECTURE
684 )
685 {
686 // we don't want to restore the child frames which had been
687 // iconized even before we were iconized, so save the child frame
688 // status when iconizing the parent frame and check it when
689 // restoring it
690 if ( bIconize )
691 {
692 frame->m_wasMinimized = frame->IsIconized();
693 }
694
695 // note that we shouldn't touch the hidden frames neither because
696 // iconizing/restoring them would show them as a side effect
697 if ( !frame->m_wasMinimized && frame->IsShown() )
698 frame->Iconize(bIconize);
699 }
700 }
701 }
702
703 WXHICON wxFrame::GetDefaultIcon() const
704 {
705 // we don't have any standard icons (any more)
706 return (WXHICON)0;
707 }
708
709 // ===========================================================================
710 // message processing
711 // ===========================================================================
712
713 // ---------------------------------------------------------------------------
714 // preprocessing
715 // ---------------------------------------------------------------------------
716
717 bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
718 {
719 if ( wxWindow::MSWTranslateMessage(pMsg) )
720 return TRUE;
721
722 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
723 // try the menu bar accels
724 wxMenuBar *menuBar = GetMenuBar();
725 if ( !menuBar )
726 return FALSE;
727
728 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
729 return acceleratorTable.Translate(this, pMsg);
730 #else
731 return FALSE;
732 #endif // wxUSE_MENUS && wxUSE_ACCEL
733 }
734
735 // ---------------------------------------------------------------------------
736 // our private (non virtual) message handlers
737 // ---------------------------------------------------------------------------
738
739 bool wxFrame::HandlePaint()
740 {
741 RECT rect;
742 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
743 {
744 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
745 if ( m_iconized )
746 {
747 const wxIcon& icon = GetIcon();
748 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
749 : (HICON)GetDefaultIcon();
750
751 // Hold a pointer to the dc so long as the OnPaint() message
752 // is being processed
753 PAINTSTRUCT ps;
754 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
755
756 // Erase background before painting or we get white background
757 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
758
759 if ( hIcon )
760 {
761 RECT rect;
762 ::GetClientRect(GetHwnd(), &rect);
763
764 // FIXME: why hardcoded?
765 static const int icon_width = 32;
766 static const int icon_height = 32;
767
768 int icon_x = (int)((rect.right - icon_width)/2);
769 int icon_y = (int)((rect.bottom - icon_height)/2);
770
771 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
772 }
773
774 ::EndPaint(GetHwnd(), &ps);
775
776 return TRUE;
777 }
778 else
779 #endif
780 {
781 return wxWindow::HandlePaint();
782 }
783 }
784 else
785 {
786 // nothing to paint - processed
787 return TRUE;
788 }
789 }
790
791 bool wxFrame::HandleSize(int x, int y, WXUINT id)
792 {
793 bool processed = FALSE;
794 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
795
796 switch ( id )
797 {
798 case SIZENORMAL:
799 // only do it it if we were iconized before, otherwise resizing the
800 // parent frame has a curious side effect of bringing it under it's
801 // children
802 if ( !m_iconized )
803 break;
804
805 // restore all child frames too
806 IconizeChildFrames(FALSE);
807
808 (void)SendIconizeEvent(FALSE);
809
810 // fall through
811
812 case SIZEFULLSCREEN:
813 m_iconized = FALSE;
814 break;
815
816 case SIZEICONIC:
817 // iconize all child frames too
818 IconizeChildFrames(TRUE);
819
820 (void)SendIconizeEvent();
821
822 m_iconized = TRUE;
823 break;
824 }
825 #endif
826
827 if ( !m_iconized )
828 {
829 #if wxUSE_STATUSBAR
830 PositionStatusBar();
831 #endif // wxUSE_STATUSBAR
832
833 #if wxUSE_TOOLBAR
834 PositionToolBar();
835 #endif // wxUSE_TOOLBAR
836
837 #if defined(WINCE_WITH_COMMANDBAR)
838 // Position the menu command bar
839 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
840 {
841 RECT rect;
842 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
843 wxSize clientSz = GetClientSize();
844
845 if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) )
846 {
847 wxLogLastError(wxT("MoveWindow"));
848 }
849
850 }
851 #endif
852
853
854 processed = wxWindow::HandleSize(x, y, id);
855 }
856
857 return processed;
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 #ifdef __SMARTPHONE__
884 // handle here commands from Smartphone menu bar
885 if ( wxTopLevelWindow::HandleCommand(id, cmd, control ) )
886 {
887 return true;
888 }
889 #endif // __SMARTPHONE__
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, 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 }