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