]> git.saurik.com Git - wxWidgets.git/blob - src/msw/frame.cpp
Eliminated bizarre VC++ internal compiler errors, perhaps related to
[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 WX_BEGIN_FLAGS( wxFrameStyle )
86 // new style border flags, we put them first to
87 // use them for streaming out
88 WX_FLAGS_MEMBER(wxBORDER_SIMPLE)
89 WX_FLAGS_MEMBER(wxBORDER_SUNKEN)
90 WX_FLAGS_MEMBER(wxBORDER_DOUBLE)
91 WX_FLAGS_MEMBER(wxBORDER_RAISED)
92 WX_FLAGS_MEMBER(wxBORDER_STATIC)
93 WX_FLAGS_MEMBER(wxBORDER_NONE)
94
95 // old style border flags
96 WX_FLAGS_MEMBER(wxSIMPLE_BORDER)
97 WX_FLAGS_MEMBER(wxSUNKEN_BORDER)
98 WX_FLAGS_MEMBER(wxDOUBLE_BORDER)
99 WX_FLAGS_MEMBER(wxRAISED_BORDER)
100 WX_FLAGS_MEMBER(wxSTATIC_BORDER)
101 WX_FLAGS_MEMBER(wxNO_BORDER)
102
103 // standard window styles
104 WX_FLAGS_MEMBER(wxTAB_TRAVERSAL)
105 WX_FLAGS_MEMBER(wxCLIP_CHILDREN)
106 WX_FLAGS_MEMBER(wxTRANSPARENT_WINDOW)
107 WX_FLAGS_MEMBER(wxWANTS_CHARS)
108 WX_FLAGS_MEMBER(wxNO_FULL_REPAINT_ON_RESIZE)
109 WX_FLAGS_MEMBER(wxALWAYS_SHOW_SB )
110 WX_FLAGS_MEMBER(wxVSCROLL)
111 WX_FLAGS_MEMBER(wxHSCROLL)
112
113 // frame styles
114 WX_FLAGS_MEMBER(wxSTAY_ON_TOP)
115 WX_FLAGS_MEMBER(wxCAPTION)
116 WX_FLAGS_MEMBER(wxTHICK_FRAME)
117 WX_FLAGS_MEMBER(wxSYSTEM_MENU)
118 WX_FLAGS_MEMBER(wxRESIZE_BORDER)
119 WX_FLAGS_MEMBER(wxRESIZE_BOX)
120 WX_FLAGS_MEMBER(wxCLOSE_BOX)
121 WX_FLAGS_MEMBER(wxMAXIMIZE_BOX)
122 WX_FLAGS_MEMBER(wxMINIMIZE_BOX)
123
124 WX_FLAGS_MEMBER(wxFRAME_TOOL_WINDOW)
125 WX_FLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT)
126
127 WX_FLAGS_MEMBER(wxFRAME_SHAPED)
128
129 WX_END_FLAGS( wxFrameStyle )
130
131 IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow,"wx/frame.h")
132
133 WX_BEGIN_PROPERTIES_TABLE(wxFrame)
134 WX_PROPERTY( Title,wxString, SetTitle, GetTitle, wxEmptyString , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
135 WX_PROPERTY_FLAGS( WindowStyle , wxFrameStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
136 /*
137 TODO PROPERTIES
138
139 style (wxDEFAULT_FRAME_STYLE)
140 centered (bool, false )
141 */
142 WX_END_PROPERTIES_TABLE()
143
144 WX_BEGIN_HANDLERS_TABLE(wxFrame)
145 WX_END_HANDLERS_TABLE()
146
147 WX_CONSTRUCTOR_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_TOOLTIPS
176 m_hwndToolTip = 0;
177 #endif
178
179 // Data to save/restore when calling ShowFullScreen
180 m_fsStatusBarFields = 0;
181 m_fsStatusBarHeight = 0;
182 m_fsToolBarHeight = 0;
183
184 m_wasMinimized = FALSE;
185 }
186
187 bool wxFrame::Create(wxWindow *parent,
188 wxWindowID id,
189 const wxString& title,
190 const wxPoint& pos,
191 const wxSize& size,
192 long style,
193 const wxString& name)
194 {
195 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
196 return FALSE;
197
198 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
199
200 wxModelessWindows.Append(this);
201
202 return TRUE;
203 }
204
205 wxFrame::~wxFrame()
206 {
207 m_isBeingDeleted = TRUE;
208 DeleteAllBars();
209 }
210
211 // ----------------------------------------------------------------------------
212 // wxFrame client size calculations
213 // ----------------------------------------------------------------------------
214
215 void wxFrame::DoSetClientSize(int width, int height)
216 {
217 // leave enough space for the status bar if we have (and show) it
218 #if wxUSE_STATUSBAR
219 wxStatusBar *statbar = GetStatusBar();
220 if ( statbar && statbar->IsShown() )
221 {
222 height += statbar->GetSize().y;
223 }
224 #endif // wxUSE_STATUSBAR
225
226 // call GetClientAreaOrigin() to take the toolbar into account
227 wxPoint pt = GetClientAreaOrigin();
228 width += pt.x;
229 height += pt.y;
230
231 wxTopLevelWindow::DoSetClientSize(width, height);
232 }
233
234 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
235 void wxFrame::DoGetClientSize(int *x, int *y) const
236 {
237 wxTopLevelWindow::DoGetClientSize(x, y);
238
239 // account for the possible toolbar
240 wxPoint pt = GetClientAreaOrigin();
241 if ( x )
242 *x -= pt.x;
243
244 if ( y )
245 *y -= pt.y;
246
247 #if wxUSE_STATUSBAR
248 // adjust client area height to take the status bar into account
249 if ( y )
250 {
251 wxStatusBar *statbar = GetStatusBar();
252 if ( statbar && statbar->IsShown() )
253 {
254 *y -= statbar->GetClientSize().y;
255 }
256 }
257 #endif // wxUSE_STATUSBAR
258 }
259
260 // ----------------------------------------------------------------------------
261 // wxFrame: various geometry-related functions
262 // ----------------------------------------------------------------------------
263
264 void wxFrame::Raise()
265 {
266 ::SetForegroundWindow(GetHwnd());
267 }
268
269 // generate an artificial resize event
270 void wxFrame::SendSizeEvent()
271 {
272 if ( !m_iconized )
273 {
274 RECT r = wxGetWindowRect(GetHwnd());
275
276 (void)::PostMessage(GetHwnd(), WM_SIZE,
277 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
278 MAKELPARAM(r.right - r.left, r.bottom - r.top));
279 }
280 }
281
282 #if wxUSE_STATUSBAR
283 wxStatusBar *wxFrame::OnCreateStatusBar(int number,
284 long style,
285 wxWindowID id,
286 const wxString& name)
287 {
288 wxStatusBar *statusBar = NULL;
289
290 #if wxUSE_NATIVE_STATUSBAR
291 if ( !UsesNativeStatusBar() )
292 {
293 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
294 }
295 else
296 #endif
297 {
298 statusBar = new wxStatusBar(this, id, style, name);
299 }
300
301 statusBar->SetFieldsCount(number);
302
303 return statusBar;
304 }
305
306 void wxFrame::PositionStatusBar()
307 {
308 if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() )
309 return;
310
311 int w, h;
312 GetClientSize(&w, &h);
313 int sw, sh;
314 m_frameStatusBar->GetSize(&sw, &sh);
315
316 // Since we wish the status bar to be directly under the client area,
317 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
318 m_frameStatusBar->SetSize(0, h, w, sh);
319 }
320 #endif // wxUSE_STATUSBAR
321
322 #if wxUSE_MENUS_NATIVE
323
324 void wxFrame::AttachMenuBar(wxMenuBar *menubar)
325 {
326 wxFrameBase::AttachMenuBar(menubar);
327
328 if ( !menubar )
329 {
330 // actually remove the menu from the frame
331 m_hMenu = (WXHMENU)0;
332 InternalSetMenuBar();
333 }
334 else // set new non NULL menu bar
335 {
336 #ifndef __WXWINCE__
337 // Can set a menubar several times.
338 if ( menubar->GetHMenu() )
339 {
340 m_hMenu = menubar->GetHMenu();
341 }
342 else // no HMENU yet
343 {
344 m_hMenu = menubar->Create();
345
346 if ( !m_hMenu )
347 {
348 wxFAIL_MSG( _T("failed to create menu bar") );
349 return;
350 }
351 }
352 #endif
353 InternalSetMenuBar();
354 }
355 }
356
357 void wxFrame::InternalSetMenuBar()
358 {
359 #ifdef __WXMICROWIN__
360 // Nothing
361 #elif defined(__WXWINCE__)
362
363 if (!GetToolBar())
364 {
365 wxToolBar* toolBar = new wxToolBar(this, -1,
366 wxDefaultPosition, wxDefaultSize,
367 wxBORDER_NONE | wxTB_HORIZONTAL,
368 wxToolBarNameStr, GetMenuBar());
369 SetToolBar(toolBar);
370 }
371 #else
372 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
373 {
374 wxLogLastError(wxT("SetMenu"));
375 }
376 #endif
377 }
378
379 #endif // wxUSE_MENUS_NATIVE
380
381 // Responds to colour changes, and passes event on to children.
382 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
383 {
384 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
385 Refresh();
386
387 #if wxUSE_STATUSBAR
388 if ( m_frameStatusBar )
389 {
390 wxSysColourChangedEvent event2;
391 event2.SetEventObject( m_frameStatusBar );
392 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
393 }
394 #endif // wxUSE_STATUSBAR
395
396 // Propagate the event to the non-top-level children
397 wxWindow::OnSysColourChanged(event);
398 }
399
400 // Pass TRUE to show full screen, FALSE to restore.
401 bool wxFrame::ShowFullScreen(bool show, long style)
402 {
403 if ( IsFullScreen() == show )
404 return FALSE;
405
406 if (show)
407 {
408 #if wxUSE_TOOLBAR
409 #ifdef __WXWINCE__
410 // TODO: hide commandbar
411 #else
412 wxToolBar *theToolBar = GetToolBar();
413 if (theToolBar)
414 theToolBar->GetSize(NULL, &m_fsToolBarHeight);
415
416 // zap the toolbar, menubar, and statusbar
417
418 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
419 {
420 theToolBar->SetSize(-1,0);
421 theToolBar->Show(FALSE);
422 }
423 #endif // __WXWINCE__
424 #endif // wxUSE_TOOLBAR
425
426 // TODO: make it work for WinCE
427 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
428 if (style & wxFULLSCREEN_NOMENUBAR)
429 SetMenu((HWND)GetHWND(), (HMENU) NULL);
430 #endif
431
432 #if wxUSE_STATUSBAR
433 wxStatusBar *theStatusBar = GetStatusBar();
434 if (theStatusBar)
435 theStatusBar->GetSize(NULL, &m_fsStatusBarHeight);
436
437 // Save the number of fields in the statusbar
438 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
439 {
440 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
441 //SetStatusBar((wxStatusBar*) NULL);
442 //delete theStatusBar;
443 theStatusBar->Show(FALSE);
444 }
445 else
446 m_fsStatusBarFields = 0;
447 #endif // wxUSE_STATUSBAR
448 }
449 else
450 {
451 #if wxUSE_TOOLBAR
452 #ifdef __WXWINCE__
453 // TODO: show commandbar
454 #else
455 wxToolBar *theToolBar = GetToolBar();
456
457 // restore the toolbar, menubar, and statusbar
458 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
459 {
460 theToolBar->SetSize(-1, m_fsToolBarHeight);
461 theToolBar->Show(TRUE);
462 }
463 #endif // __WXWINCE__
464 #endif // wxUSE_TOOLBAR
465
466 #if wxUSE_STATUSBAR
467 if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR )
468 {
469 //CreateStatusBar(m_fsStatusBarFields);
470 if (GetStatusBar())
471 {
472 GetStatusBar()->Show(TRUE);
473 PositionStatusBar();
474 }
475 }
476 #endif // wxUSE_STATUSBAR
477
478 // TODO: make it work for WinCE
479 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
480 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
481 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
482 #endif
483 }
484
485 return wxFrameBase::ShowFullScreen(show, style);
486 }
487
488 // ----------------------------------------------------------------------------
489 // tool/status bar stuff
490 // ----------------------------------------------------------------------------
491
492 #if wxUSE_TOOLBAR
493
494 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
495 {
496 #ifdef __WXWINCE__
497 // We may already have a toolbar from calling SetMenuBar.
498 if (GetToolBar())
499 return GetToolBar();
500 #endif
501 if ( wxFrameBase::CreateToolBar(style, id, name) )
502 {
503 PositionToolBar();
504 }
505
506 return m_frameToolBar;
507 }
508
509 void wxFrame::PositionToolBar()
510 {
511 wxToolBar *toolbar = GetToolBar();
512 if ( toolbar && toolbar->IsShown() )
513 {
514 #ifdef __WXWINCE__
515 // We want to do something different in WinCE, because
516 // the toolbar should be associated with the commandbar,
517 // and not an independent window.
518 // TODO
519 #else
520 // don't call our (or even wxTopLevelWindow) version because we want
521 // the real (full) client area size, not excluding the tool/status bar
522 int width, height;
523 wxWindow::DoGetClientSize(&width, &height);
524
525 #if wxUSE_STATUSBAR
526 wxStatusBar *statbar = GetStatusBar();
527 if ( statbar && statbar->IsShown() )
528 {
529 height -= statbar->GetClientSize().y;
530 }
531 #endif // wxUSE_STATUSBAR
532
533 int tx, ty;
534 int tw, th;
535 toolbar->GetPosition(&tx, &ty);
536 toolbar->GetSize(&tw, &th);
537
538 // Adjust
539 if (ty < 0 && (-ty == th))
540 ty = 0;
541 if (tx < 0 && (-tx == tw))
542 tx = 0;
543
544 int desiredW = tw;
545 int desiredH = th;
546
547 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
548 {
549 desiredH = height;
550 }
551 else
552 {
553 desiredW = width;
554 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
555 // desiredW -= 3;
556 }
557
558 // use the 'real' MSW position here, don't offset relativly to the
559 // client area origin
560
561 // Optimise such that we don't have to always resize the toolbar
562 // when the frame changes, otherwise we'll get a lot of flicker.
563 bool heightChanging = TRUE;
564 bool widthChanging = TRUE;
565
566 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
567 {
568 // It's OK if the current height is greater than what can be shown.
569 heightChanging = (desiredH > th) ;
570 widthChanging = (desiredW != tw) ;
571
572 // The next time around, we may not have to set the size
573 if (heightChanging)
574 desiredH = desiredH + 200;
575 }
576 else
577 {
578 // It's OK if the current width is greater than what can be shown.
579 widthChanging = (desiredW > tw) ;
580 heightChanging = (desiredH != th) ;
581
582 // The next time around, we may not have to set the size
583 if (widthChanging)
584 desiredW = desiredW + 200;
585 }
586
587 if (tx != 0 || ty != 0 || widthChanging || heightChanging)
588 toolbar->SetSize(0, 0, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
589
590 #endif // __WXWINCE__
591 }
592 }
593
594 #endif // wxUSE_TOOLBAR
595
596 // ----------------------------------------------------------------------------
597 // frame state (iconized/maximized/...)
598 // ----------------------------------------------------------------------------
599
600 // propagate our state change to all child frames: this allows us to emulate X
601 // Windows behaviour where child frames float independently of the parent one
602 // on the desktop, but are iconized/restored with it
603 void wxFrame::IconizeChildFrames(bool bIconize)
604 {
605 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
606 node;
607 node = node->GetNext() )
608 {
609 wxWindow *win = node->GetData();
610
611 // iconizing the frames with this style under Win95 shell puts them at
612 // the bottom of the screen (as the MDI children) instead of making
613 // them appear in the taskbar because they are, by virtue of this
614 // style, not managed by the taskbar - instead leave Windows take care
615 // of them
616 #ifdef __WIN95__
617 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
618 continue;
619 #endif // Win95
620
621 // the child MDI frames are a special case and should not be touched by
622 // the parent frame - instead, they are managed by the user
623 wxFrame *frame = wxDynamicCast(win, wxFrame);
624 if ( frame
625 #if wxUSE_MDI_ARCHITECTURE
626 && !wxDynamicCast(frame, wxMDIChildFrame)
627 #endif // wxUSE_MDI_ARCHITECTURE
628 )
629 {
630 // we don't want to restore the child frames which had been
631 // iconized even before we were iconized, so save the child frame
632 // status when iconizing the parent frame and check it when
633 // restoring it
634 if ( bIconize )
635 {
636 // note that we shouldn't touch the hidden frames neither
637 // because iconizing/restoring them would show them as a side
638 // effect
639 frame->m_wasMinimized = frame->IsIconized() || !frame->IsShown();
640 }
641
642 // this test works for both iconizing and restoring
643 if ( !frame->m_wasMinimized )
644 frame->Iconize(bIconize);
645 }
646 }
647 }
648
649 WXHICON wxFrame::GetDefaultIcon() const
650 {
651 // we don't have any standard icons (any more)
652 return (WXHICON)0;
653 }
654
655 // ===========================================================================
656 // message processing
657 // ===========================================================================
658
659 // ---------------------------------------------------------------------------
660 // preprocessing
661 // ---------------------------------------------------------------------------
662
663 bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
664 {
665 if ( wxWindow::MSWTranslateMessage(pMsg) )
666 return TRUE;
667
668 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
669 // try the menu bar accels
670 wxMenuBar *menuBar = GetMenuBar();
671 if ( !menuBar )
672 return FALSE;
673
674 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
675 return acceleratorTable.Translate(this, pMsg);
676 #else
677 return FALSE;
678 #endif // wxUSE_MENUS && wxUSE_ACCEL
679 }
680
681 // ---------------------------------------------------------------------------
682 // our private (non virtual) message handlers
683 // ---------------------------------------------------------------------------
684
685 bool wxFrame::HandlePaint()
686 {
687 RECT rect;
688 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
689 {
690 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
691 if ( m_iconized )
692 {
693 const wxIcon& icon = GetIcon();
694 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
695 : (HICON)GetDefaultIcon();
696
697 // Hold a pointer to the dc so long as the OnPaint() message
698 // is being processed
699 PAINTSTRUCT ps;
700 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
701
702 // Erase background before painting or we get white background
703 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
704
705 if ( hIcon )
706 {
707 RECT rect;
708 ::GetClientRect(GetHwnd(), &rect);
709
710 // FIXME: why hardcoded?
711 static const int icon_width = 32;
712 static const int icon_height = 32;
713
714 int icon_x = (int)((rect.right - icon_width)/2);
715 int icon_y = (int)((rect.bottom - icon_height)/2);
716
717 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
718 }
719
720 ::EndPaint(GetHwnd(), &ps);
721
722 return TRUE;
723 }
724 else
725 #endif
726 {
727 return wxWindow::HandlePaint();
728 }
729 }
730 else
731 {
732 // nothing to paint - processed
733 return TRUE;
734 }
735 }
736
737 bool wxFrame::HandleSize(int x, int y, WXUINT id)
738 {
739 bool processed = FALSE;
740 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
741
742 switch ( id )
743 {
744 case SIZENORMAL:
745 // only do it it if we were iconized before, otherwise resizing the
746 // parent frame has a curious side effect of bringing it under it's
747 // children
748 if ( !m_iconized )
749 break;
750
751 // restore all child frames too
752 IconizeChildFrames(FALSE);
753
754 (void)SendIconizeEvent(FALSE);
755
756 // fall through
757
758 case SIZEFULLSCREEN:
759 m_iconized = FALSE;
760 break;
761
762 case SIZEICONIC:
763 // iconize all child frames too
764 IconizeChildFrames(TRUE);
765
766 (void)SendIconizeEvent();
767
768 m_iconized = TRUE;
769 break;
770 }
771 #endif
772
773 if ( !m_iconized )
774 {
775 #if wxUSE_STATUSBAR
776 PositionStatusBar();
777 #endif // wxUSE_STATUSBAR
778
779 #if wxUSE_TOOLBAR
780 PositionToolBar();
781 #endif // wxUSE_TOOLBAR
782
783 processed = wxWindow::HandleSize(x, y, id);
784 }
785
786 return processed;
787 }
788
789 bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
790 {
791 if ( control )
792 {
793 // In case it's e.g. a toolbar.
794 wxWindow *win = wxFindWinFromHandle(control);
795 if ( win )
796 return win->MSWCommand(cmd, id);
797 }
798
799 // handle here commands from menus and accelerators
800 if ( cmd == 0 || cmd == 1 )
801 {
802 #if wxUSE_MENUS_NATIVE
803 if ( wxCurrentPopupMenu )
804 {
805 wxMenu *popupMenu = wxCurrentPopupMenu;
806 wxCurrentPopupMenu = NULL;
807
808 return popupMenu->MSWCommand(cmd, id);
809 }
810 #endif // wxUSE_MENUS_NATIVE
811
812 if ( ProcessCommand(id) )
813 {
814 return TRUE;
815 }
816 }
817
818 return FALSE;
819 }
820
821 bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
822 {
823 int item;
824 if ( flags == 0xFFFF && hMenu == 0 )
825 {
826 // menu was removed from screen
827 item = -1;
828 }
829 #ifndef __WXMICROWIN__
830 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
831 {
832 item = nItem;
833 }
834 #endif
835 else
836 {
837 // don't give hints for separators (doesn't make sense) nor for the
838 // items opening popup menus (they don't have them anyhow) but do clear
839 // the status line - otherwise, we would be left with the help message
840 // for the previous item which doesn't apply any more
841 DoGiveHelp(wxEmptyString, FALSE);
842
843 return FALSE;
844 }
845
846 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
847 event.SetEventObject(this);
848
849 return GetEventHandler()->ProcessEvent(event);
850 }
851
852 bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup)
853 {
854 // we don't have the menu id here, so we use the id to specify if the event
855 // was from a popup menu or a normal one
856 wxMenuEvent event(evtType, isPopup ? -1 : 0);
857 event.SetEventObject(this);
858
859 return GetEventHandler()->ProcessEvent(event);
860 }
861
862 // ---------------------------------------------------------------------------
863 // the window proc for wxFrame
864 // ---------------------------------------------------------------------------
865
866 long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
867 {
868 long rc = 0;
869 bool processed = FALSE;
870
871 switch ( message )
872 {
873 case WM_CLOSE:
874 // if we can't close, tell the system that we processed the
875 // message - otherwise it would close us
876 processed = !Close();
877 break;
878
879 case WM_SIZE:
880 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
881 break;
882
883 case WM_COMMAND:
884 {
885 WORD id, cmd;
886 WXHWND hwnd;
887 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
888 &id, &hwnd, &cmd);
889
890 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
891 }
892 break;
893
894 case WM_PAINT:
895 processed = HandlePaint();
896 break;
897
898 case WM_INITMENUPOPUP:
899 processed = HandleInitMenuPopup((WXHMENU) wParam);
900 break;
901
902 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
903 case WM_MENUSELECT:
904 {
905 WXWORD item, flags;
906 WXHMENU hmenu;
907 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
908
909 processed = HandleMenuSelect(item, flags, hmenu);
910 }
911 break;
912
913 case WM_EXITMENULOOP:
914 processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam);
915 break;
916
917 case WM_QUERYDRAGICON:
918 {
919 const wxIcon& icon = GetIcon();
920 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
921 : (HICON)GetDefaultIcon();
922 rc = (long)hIcon;
923 processed = rc != 0;
924 }
925 break;
926 #endif // !__WXMICROWIN__
927 }
928
929 if ( !processed )
930 rc = wxFrameBase::MSWWindowProc(message, wParam, lParam);
931
932 return rc;
933 }
934
935 // handle WM_INITMENUPOPUP message
936 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu)
937 {
938 wxMenu* menu = NULL;
939 if (GetMenuBar())
940 {
941 int nCount = GetMenuBar()->GetMenuCount();
942 for (int n = 0; n < nCount; n++)
943 {
944 if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu)
945 {
946 menu = GetMenuBar()->GetMenu(n);
947 break;
948 }
949 }
950 }
951
952 wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu);
953 event.SetEventObject(this);
954
955 return GetEventHandler()->ProcessEvent(event);
956 }