removed unnecessary (now that we leave Windows paint background itself) SetBackground...
[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 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
196 SetLeftMenu(wxID_EXIT, _("Done"));
197 #endif
198
199 return true;
200 }
201
202 wxFrame::~wxFrame()
203 {
204 m_isBeingDeleted = true;
205 DeleteAllBars();
206 }
207
208 // ----------------------------------------------------------------------------
209 // wxFrame client size calculations
210 // ----------------------------------------------------------------------------
211
212 void wxFrame::DoSetClientSize(int width, int height)
213 {
214 // leave enough space for the status bar if we have (and show) it
215 #if wxUSE_STATUSBAR
216 wxStatusBar *statbar = GetStatusBar();
217 if ( statbar && statbar->IsShown() )
218 {
219 height += statbar->GetSize().y;
220 }
221 #endif // wxUSE_STATUSBAR
222
223 // call GetClientAreaOrigin() to take the toolbar into account
224 wxPoint pt = GetClientAreaOrigin();
225 width += pt.x;
226 height += pt.y;
227
228 wxTopLevelWindow::DoSetClientSize(width, height);
229 }
230
231 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
232 void wxFrame::DoGetClientSize(int *x, int *y) const
233 {
234 wxTopLevelWindow::DoGetClientSize(x, y);
235
236 // account for the possible toolbar
237 wxPoint pt = GetClientAreaOrigin();
238 if ( x )
239 *x -= pt.x;
240
241 if ( y )
242 *y -= pt.y;
243
244 #if wxUSE_STATUSBAR
245 // adjust client area height to take the status bar into account
246 if ( y )
247 {
248 wxStatusBar *statbar = GetStatusBar();
249 if ( statbar && statbar->IsShown() )
250 {
251 *y -= statbar->GetClientSize().y;
252 }
253 }
254 #endif // wxUSE_STATUSBAR
255 }
256
257 // ----------------------------------------------------------------------------
258 // wxFrame: various geometry-related functions
259 // ----------------------------------------------------------------------------
260
261 void wxFrame::Raise()
262 {
263 ::SetForegroundWindow(GetHwnd());
264 }
265
266 // generate an artificial resize event
267 void wxFrame::SendSizeEvent()
268 {
269 if ( !m_iconized )
270 {
271 RECT r = wxGetWindowRect(GetHwnd());
272
273 (void)::PostMessage(GetHwnd(), WM_SIZE,
274 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
275 MAKELPARAM(r.right - r.left, r.bottom - r.top));
276 }
277 }
278
279 #if wxUSE_STATUSBAR
280 wxStatusBar *wxFrame::OnCreateStatusBar(int number,
281 long style,
282 wxWindowID id,
283 const wxString& name)
284 {
285 wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL);
286
287 #if wxUSE_NATIVE_STATUSBAR
288 if ( !UsesNativeStatusBar() )
289 {
290 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
291 }
292 else
293 #endif
294 {
295 statusBar = new wxStatusBar(this, id, style, name);
296 }
297
298 statusBar->SetFieldsCount(number);
299
300 return statusBar;
301 }
302
303 void wxFrame::PositionStatusBar()
304 {
305 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
306 return;
307
308 int w, h;
309 GetClientSize(&w, &h);
310 int sw, sh;
311 m_frameStatusBar->GetSize(&sw, &sh);
312
313 // Since we wish the status bar to be directly under the client area,
314 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
315 m_frameStatusBar->SetSize(0, h, w, sh);
316 }
317 #endif // wxUSE_STATUSBAR
318
319 #if wxUSE_MENUS_NATIVE
320
321 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
322 {
323 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
324
325 wxMenu *autoMenu = NULL;
326
327 if( menubar->GetMenuCount() == 1 )
328 {
329 autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0));
330 SetRightMenu(wxID_ANY, menubar->GetLabelTop(0), autoMenu);
331 }
332 else
333 {
334 autoMenu = new wxMenu;
335
336 for( size_t n = 0; n < menubar->GetMenuCount(); n++ )
337 {
338 wxMenu *item = menubar->GetMenu(n);
339 wxString label = menubar->GetLabelTop(n);
340 wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item);
341 autoMenu->Append(wxID_ANY, label, new_item);
342 }
343
344 SetRightMenu(wxID_ANY, _("Menu"), autoMenu);
345 }
346
347 #elif defined(WINCE_WITHOUT_COMMANDBAR)
348 if (!GetToolBar())
349 {
350 wxToolBar* toolBar = new wxToolBar(this, wxID_ANY,
351 wxDefaultPosition, wxDefaultSize,
352 wxBORDER_NONE | wxTB_HORIZONTAL,
353 wxToolBarNameStr, menubar);
354 SetToolBar(toolBar);
355 menubar->SetToolBar(toolBar);
356 }
357 // Now adjust size for menu bar
358 int menuHeight = 26;
359
360 //When the main window is created using CW_USEDEFAULT the height of the
361 // is created is not taken into account). So we resize the window after
362 // if a menubar is present
363 {
364 RECT rc;
365 ::GetWindowRect((HWND) GetHWND(), &rc);
366 // adjust for menu / titlebar height
367 rc.bottom -= (2*menuHeight-1);
368
369 ::MoveWindow((HWND) GetHWND(), rc.left, rc.top, rc.right, rc.bottom, FALSE);
370 }
371 #endif
372
373 wxFrameBase::AttachMenuBar(menubar);
374
375 if ( !menubar )
376 {
377 // actually remove the menu from the frame
378 m_hMenu = (WXHMENU)0;
379 InternalSetMenuBar();
380 }
381 else // set new non NULL menu bar
382 {
383 #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR)
384 // Can set a menubar several times.
385 if ( menubar->GetHMenu() )
386 {
387 m_hMenu = menubar->GetHMenu();
388 }
389 else // no HMENU yet
390 {
391 m_hMenu = menubar->Create();
392
393 if ( !m_hMenu )
394 {
395 wxFAIL_MSG( _T("failed to create menu bar") );
396 return;
397 }
398 }
399 #endif
400 InternalSetMenuBar();
401 }
402 }
403
404 void wxFrame::InternalSetMenuBar()
405 {
406 #if defined(__WXMICROWIN__) || defined(__WXWINCE__)
407 // Nothing
408 #else
409 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
410 {
411 wxLogLastError(wxT("SetMenu"));
412 }
413 #endif
414 }
415
416 #endif // wxUSE_MENUS_NATIVE
417
418 // Responds to colour changes, and passes event on to children.
419 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
420 {
421 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
422 Refresh();
423
424 #if wxUSE_STATUSBAR
425 if ( m_frameStatusBar )
426 {
427 wxSysColourChangedEvent event2;
428 event2.SetEventObject( m_frameStatusBar );
429 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
430 }
431 #endif // wxUSE_STATUSBAR
432
433 // Propagate the event to the non-top-level children
434 wxWindow::OnSysColourChanged(event);
435 }
436
437 // Pass true to show full screen, false to restore.
438 bool wxFrame::ShowFullScreen(bool show, long style)
439 {
440 if ( IsFullScreen() == show )
441 return false;
442
443 if (show)
444 {
445 #if wxUSE_TOOLBAR
446
447 #if defined(WINCE_WITH_COMMANDBAR)
448 // TODO: hide commandbar
449 #else
450 wxToolBar *theToolBar = GetToolBar();
451 if (theToolBar)
452 theToolBar->GetSize(NULL, &m_fsToolBarHeight);
453
454 // zap the toolbar, menubar, and statusbar
455
456 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
457 {
458 theToolBar->SetSize(wxDefaultCoord,0);
459 theToolBar->Show(false);
460 }
461 #endif // __WXWINCE__
462 #endif // wxUSE_TOOLBAR
463
464 #if defined(__WXMICROWIN__)
465 #elif defined(__WXWINCE__)
466 // TODO: make it work for WinCE
467 #else
468 if (style & wxFULLSCREEN_NOMENUBAR)
469 SetMenu((HWND)GetHWND(), (HMENU) NULL);
470 #endif
471
472 #if wxUSE_STATUSBAR
473 wxStatusBar *theStatusBar = GetStatusBar();
474 if (theStatusBar)
475 theStatusBar->GetSize(NULL, &m_fsStatusBarHeight);
476
477 // Save the number of fields in the statusbar
478 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
479 {
480 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
481 //SetStatusBar((wxStatusBar*) NULL);
482 //delete theStatusBar;
483 theStatusBar->Show(false);
484 }
485 else
486 m_fsStatusBarFields = 0;
487 #endif // wxUSE_STATUSBAR
488 }
489 else
490 {
491 #if wxUSE_TOOLBAR
492 #if defined(WINCE_WITHOUT_COMMANDBAR)
493 // TODO: show commandbar
494 #else
495 wxToolBar *theToolBar = GetToolBar();
496
497 // restore the toolbar, menubar, and statusbar
498 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
499 {
500 theToolBar->SetSize(wxDefaultCoord, m_fsToolBarHeight);
501 theToolBar->Show(true);
502 }
503 #endif // __WXWINCE__
504 #endif // wxUSE_TOOLBAR
505
506 #if wxUSE_STATUSBAR
507 if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR )
508 {
509 //CreateStatusBar(m_fsStatusBarFields);
510 if (GetStatusBar())
511 {
512 GetStatusBar()->Show(true);
513 PositionStatusBar();
514 }
515 }
516 #endif // wxUSE_STATUSBAR
517
518 #if defined(__WXMICROWIN__)
519 #elif defined(__WXWINCE__)
520 // TODO: make it work for WinCE
521 #else
522 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
523 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
524 #endif
525 }
526
527 return wxFrameBase::ShowFullScreen(show, style);
528 }
529
530 // ----------------------------------------------------------------------------
531 // tool/status bar stuff
532 // ----------------------------------------------------------------------------
533
534 #if wxUSE_TOOLBAR
535
536 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
537 {
538 #if defined(WINCE_WITHOUT_COMMANDBAR)
539 // We may already have a toolbar from calling SetMenuBar.
540 if (GetToolBar())
541 return GetToolBar();
542 #endif
543 if ( wxFrameBase::CreateToolBar(style, id, name) )
544 {
545 PositionToolBar();
546 }
547
548 return m_frameToolBar;
549 }
550
551 void wxFrame::PositionToolBar()
552 {
553 wxToolBar *toolbar = GetToolBar();
554 if ( toolbar && toolbar->IsShown() )
555 {
556 #if defined(WINCE_WITHOUT_COMMANDBAR)
557 // We want to do something different in WinCE, because
558 // the toolbar should be associated with the commandbar,
559 // and not an independent window.
560 // TODO
561 #else
562 // don't call our (or even wxTopLevelWindow) version because we want
563 // the real (full) client area size, not excluding the tool/status bar
564 int width, height;
565 wxWindow::DoGetClientSize(&width, &height);
566
567 #if wxUSE_STATUSBAR
568 wxStatusBar *statbar = GetStatusBar();
569 if ( statbar && statbar->IsShown() )
570 {
571 height -= statbar->GetClientSize().y;
572 }
573 #endif // wxUSE_STATUSBAR
574
575 int x = 0;
576 int y = 0;
577 #if defined(WINCE_WITH_COMMANDBAR)
578 // We're using a commandbar - so we have to allow for it.
579 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
580 {
581 RECT rect;
582 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
583 y = rect.bottom - rect.top;
584 }
585 #endif
586
587 int tx, ty;
588 int tw, th;
589 toolbar->GetPosition(&tx, &ty);
590 toolbar->GetSize(&tw, &th);
591
592 // Adjust
593 if (ty < 0 && (-ty == th))
594 ty = 0;
595 if (tx < 0 && (-tx == tw))
596 tx = 0;
597
598 int desiredW = tw;
599 int desiredH = th;
600
601 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
602 {
603 desiredH = height;
604 }
605 else
606 {
607 desiredW = width;
608 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
609 // desiredW -= 3;
610 }
611
612 // use the 'real' MSW position here, don't offset relativly to the
613 // client area origin
614
615 // Optimise such that we don't have to always resize the toolbar
616 // when the frame changes, otherwise we'll get a lot of flicker.
617 bool heightChanging wxDUMMY_INITIALIZE(true);
618 bool widthChanging wxDUMMY_INITIALIZE(true);
619
620 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
621 {
622 // It's OK if the current height is greater than what can be shown.
623 heightChanging = (desiredH > th) ;
624 widthChanging = (desiredW != tw) ;
625
626 // The next time around, we may not have to set the size
627 if (heightChanging)
628 desiredH = desiredH + 200;
629 }
630 else
631 {
632 // It's OK if the current width is greater than what can be shown.
633 widthChanging = (desiredW > tw) ;
634 heightChanging = (desiredH != th) ;
635
636 // The next time around, we may not have to set the size
637 if (widthChanging)
638 desiredW = desiredW + 200;
639 }
640
641 if (tx != 0 || ty != 0 || widthChanging || heightChanging)
642 toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
643
644 #endif // __WXWINCE__
645 }
646 }
647
648 #endif // wxUSE_TOOLBAR
649
650 // ----------------------------------------------------------------------------
651 // frame state (iconized/maximized/...)
652 // ----------------------------------------------------------------------------
653
654 // propagate our state change to all child frames: this allows us to emulate X
655 // Windows behaviour where child frames float independently of the parent one
656 // on the desktop, but are iconized/restored with it
657 void wxFrame::IconizeChildFrames(bool bIconize)
658 {
659 m_iconized = 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 WXUNUSED(x), int WXUNUSED(y), WXUINT id)
792 {
793 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
794 switch ( id )
795 {
796 case SIZE_RESTORED:
797 case SIZE_MAXIMIZED:
798 // only do it it if we were iconized before, otherwise resizing the
799 // parent frame has a curious side effect of bringing it under it's
800 // children
801 if ( !m_iconized )
802 break;
803
804 // restore all child frames too
805 IconizeChildFrames(false);
806
807 (void)SendIconizeEvent(false);
808 break;
809
810 case SIZE_MINIMIZED:
811 // iconize all child frames too
812 IconizeChildFrames(true);
813 break;
814 }
815 #else
816 wxUnusedVar(id);
817 #endif // !__WXWINCE__
818
819 if ( !m_iconized )
820 {
821 #if wxUSE_STATUSBAR
822 PositionStatusBar();
823 #endif // wxUSE_STATUSBAR
824
825 #if wxUSE_TOOLBAR
826 PositionToolBar();
827 #endif // wxUSE_TOOLBAR
828
829 #if defined(WINCE_WITH_COMMANDBAR)
830 // Position the menu command bar
831 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
832 {
833 RECT rect;
834 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
835 wxSize clientSz = GetClientSize();
836
837 if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) )
838 {
839 wxLogLastError(wxT("MoveWindow"));
840 }
841
842 }
843 #endif // WINCE_WITH_COMMANDBAR
844 }
845
846 // call the base class version to generate the appropriate events
847 return false;
848 }
849
850 bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
851 {
852 if ( control )
853 {
854 // In case it's e.g. a toolbar.
855 wxWindow *win = wxFindWinFromHandle(control);
856 if ( win )
857 return win->MSWCommand(cmd, id);
858 }
859
860 // handle here commands from menus and accelerators
861 if ( cmd == 0 || cmd == 1 )
862 {
863 #if wxUSE_MENUS_NATIVE
864 if ( wxCurrentPopupMenu )
865 {
866 wxMenu *popupMenu = wxCurrentPopupMenu;
867 wxCurrentPopupMenu = NULL;
868
869 return popupMenu->MSWCommand(cmd, id);
870 }
871 #endif // wxUSE_MENUS_NATIVE
872
873 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
874 // handle here commands from Smartphone menu bar
875 if ( wxTopLevelWindow::HandleCommand(id, cmd, control ) )
876 {
877 return true;
878 }
879 #endif // __SMARTPHONE__ && __WXWINCE__
880
881 if ( ProcessCommand(id) )
882 {
883 return true;
884 }
885 }
886
887 return false;
888 }
889
890 bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
891 {
892 int item;
893 if ( flags == 0xFFFF && hMenu == 0 )
894 {
895 // menu was removed from screen
896 item = -1;
897 }
898 #ifndef __WXMICROWIN__
899 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
900 {
901 item = nItem;
902 }
903 #endif
904 else
905 {
906 // don't give hints for separators (doesn't make sense) nor for the
907 // items opening popup menus (they don't have them anyhow) but do clear
908 // the status line - otherwise, we would be left with the help message
909 // for the previous item which doesn't apply any more
910 DoGiveHelp(wxEmptyString, false);
911
912 return false;
913 }
914
915 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
916 event.SetEventObject(this);
917
918 return GetEventHandler()->ProcessEvent(event);
919 }
920
921 bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup)
922 {
923 // we don't have the menu id here, so we use the id to specify if the event
924 // was from a popup menu or a normal one
925 wxMenuEvent event(evtType, isPopup ? -1 : 0);
926 event.SetEventObject(this);
927
928 return GetEventHandler()->ProcessEvent(event);
929 }
930
931 // ---------------------------------------------------------------------------
932 // the window proc for wxFrame
933 // ---------------------------------------------------------------------------
934
935 WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
936 {
937 WXLRESULT rc = 0;
938 bool processed = false;
939
940 switch ( message )
941 {
942 case WM_CLOSE:
943 // if we can't close, tell the system that we processed the
944 // message - otherwise it would close us
945 processed = !Close();
946 break;
947
948 case WM_SIZE:
949 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
950 break;
951
952 case WM_COMMAND:
953 {
954 WORD id, cmd;
955 WXHWND hwnd;
956 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
957 &id, &hwnd, &cmd);
958
959 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
960 }
961 break;
962
963 case WM_PAINT:
964 processed = HandlePaint();
965 break;
966
967 case WM_INITMENUPOPUP:
968 processed = HandleInitMenuPopup((WXHMENU) wParam);
969 break;
970
971 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
972 case WM_MENUSELECT:
973 {
974 WXWORD item, flags;
975 WXHMENU hmenu;
976 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
977
978 processed = HandleMenuSelect(item, flags, hmenu);
979 }
980 break;
981
982 case WM_EXITMENULOOP:
983 processed = HandleMenuLoop(wxEVT_MENU_CLOSE, (WXWORD)wParam);
984 break;
985
986 case WM_QUERYDRAGICON:
987 {
988 const wxIcon& icon = GetIcon();
989 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
990 : (HICON)GetDefaultIcon();
991 rc = (long)hIcon;
992 processed = rc != 0;
993 }
994 break;
995 #endif // !__WXMICROWIN__
996 }
997
998 if ( !processed )
999 rc = wxFrameBase::MSWWindowProc(message, wParam, lParam);
1000
1001 return rc;
1002 }
1003
1004 // handle WM_INITMENUPOPUP message
1005 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu)
1006 {
1007 wxMenu* menu = NULL;
1008 if (GetMenuBar())
1009 {
1010 int nCount = GetMenuBar()->GetMenuCount();
1011 for (int n = 0; n < nCount; n++)
1012 {
1013 if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu)
1014 {
1015 menu = GetMenuBar()->GetMenu(n);
1016 break;
1017 }
1018 }
1019 }
1020
1021 wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu);
1022 event.SetEventObject(this);
1023
1024 return GetEventHandler()->ProcessEvent(event);
1025 }
1026
1027 // ----------------------------------------------------------------------------
1028 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
1029 // from the client area, so the client area is what's really available for the
1030 // frame contents
1031 // ----------------------------------------------------------------------------
1032
1033 // get the origin of the client area in the client coordinates
1034 wxPoint wxFrame::GetClientAreaOrigin() const
1035 {
1036 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
1037
1038 #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \
1039 (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)))
1040 wxToolBar *toolbar = GetToolBar();
1041 if ( toolbar && toolbar->IsShown() )
1042 {
1043 int w, h;
1044 toolbar->GetSize(&w, &h);
1045
1046 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
1047 {
1048 pt.x += w;
1049 }
1050 else
1051 {
1052 pt.y += h;
1053 }
1054 }
1055 #endif // wxUSE_TOOLBAR
1056
1057 #if defined(WINCE_WITH_COMMANDBAR)
1058 if (GetMenuBar() && GetMenuBar()->GetCommandBar())
1059 {
1060 RECT rect;
1061 ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect);
1062 pt.y += (rect.bottom - rect.top);
1063 }
1064 #endif
1065
1066 return pt;
1067 }