]> git.saurik.com Git - wxWidgets.git/blob - src/msw/frame.cpp
wxFrameBase class for wxMSW and wxGTK
[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 and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
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/setup.h"
33 #include "wx/frame.h"
34 #include "wx/menu.h"
35 #include "wx/app.h"
36 #include "wx/utils.h"
37 #include "wx/dialog.h"
38 #include "wx/settings.h"
39 #include "wx/dcclient.h"
40 #endif // WX_PRECOMP
41
42 #include "wx/msw/private.h"
43
44 #if wxUSE_STATUSBAR
45 #include "wx/statusbr.h"
46
47 #if wxUSE_NATIVE_STATUSBAR
48 #include "wx/msw/statbr95.h"
49 #endif
50 #endif // wxUSE_STATUSBAR
51
52 #if wxUSE_TOOLBAR
53 #include "wx/toolbar.h"
54 #endif // wxUSE_TOOLBAR
55
56 #include "wx/menuitem.h"
57 #include "wx/log.h"
58
59 // ----------------------------------------------------------------------------
60 // globals
61 // ----------------------------------------------------------------------------
62
63 extern wxWindowList wxModelessWindows;
64 extern wxList WXDLLEXPORT wxPendingDelete;
65 extern wxChar wxFrameClassName[];
66 extern wxMenu *wxCurrentPopupMenu;
67
68 // ----------------------------------------------------------------------------
69 // event tables
70 // ----------------------------------------------------------------------------
71
72 #if !USE_SHARED_LIBRARY
73 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
74 EVT_ACTIVATE(wxFrame::OnActivate)
75 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
76 END_EVENT_TABLE()
77
78 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
79 #endif
80
81 // ============================================================================
82 // implementation
83 // ============================================================================
84
85 // ----------------------------------------------------------------------------
86 // static class members
87 // ----------------------------------------------------------------------------
88
89 #if wxUSE_NATIVE_STATUSBAR
90 bool wxFrame::m_useNativeStatusBar = TRUE;
91 #else
92 bool wxFrame::m_useNativeStatusBar = FALSE;
93 #endif
94
95 // ----------------------------------------------------------------------------
96 // creation/destruction
97 // ----------------------------------------------------------------------------
98
99 void wxFrame::Init()
100 {
101 m_iconized = FALSE;
102
103 #if wxUSE_TOOLTIPS
104 m_hwndToolTip = 0;
105 #endif
106 }
107
108 bool wxFrame::Create(wxWindow *parent,
109 wxWindowID id,
110 const wxString& title,
111 const wxPoint& pos,
112 const wxSize& size,
113 long style,
114 const wxString& name)
115 {
116 SetName(name);
117 m_windowStyle = style;
118 m_frameMenuBar = NULL;
119 m_frameToolBar = NULL;
120 m_frameStatusBar = NULL;
121
122 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
123
124 if ( id > -1 )
125 m_windowId = id;
126 else
127 m_windowId = (int)NewControlId();
128
129 if (parent) parent->AddChild(this);
130
131 int x = pos.x;
132 int y = pos.y;
133 int width = size.x;
134 int height = size.y;
135
136 m_iconized = FALSE;
137
138 // we pass NULL as parent to MSWCreate because frames with parents behave
139 // very strangely under Win95 shell
140 // Alteration by JACS: keep normal Windows behaviour (float on top of parent)
141 // with this style.
142 if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0)
143 parent = NULL;
144
145 if (!parent)
146 wxTopLevelWindows.Append(this);
147
148 MSWCreate(m_windowId, parent, wxFrameClassName, this, title,
149 x, y, width, height, style);
150
151 wxModelessWindows.Append(this);
152 return TRUE;
153 }
154
155 wxFrame::~wxFrame()
156 {
157 m_isBeingDeleted = TRUE;
158 wxTopLevelWindows.DeleteObject(this);
159
160 DeleteAllBars();
161
162 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
163 {
164 wxTheApp->SetTopWindow(NULL);
165
166 if (wxTheApp->GetExitOnFrameDelete())
167 {
168 PostQuitMessage(0);
169 }
170 }
171
172 wxModelessWindows.DeleteObject(this);
173
174 // For some reason, wxWindows can activate another task altogether
175 // when a frame is destroyed after a modal dialog has been invoked.
176 // Try to bring the parent to the top.
177 // MT:Only do this if this frame is currently the active window, else weird
178 // things start to happen
179 if ( wxGetActiveWindow() == this )
180 if (GetParent() && GetParent()->GetHWND())
181 ::BringWindowToTop((HWND) GetParent()->GetHWND());
182 }
183
184 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
185 void wxFrame::DoGetClientSize(int *x, int *y) const
186 {
187 RECT rect;
188 ::GetClientRect(GetHwnd(), &rect);
189
190 #if wxUSE_STATUSBAR
191 if ( GetStatusBar() )
192 {
193 int statusX, statusY;
194 GetStatusBar()->GetClientSize(&statusX, &statusY);
195 rect.bottom -= statusY;
196 }
197 #endif // wxUSE_STATUSBAR
198
199 wxPoint pt(GetClientAreaOrigin());
200 rect.bottom -= pt.y;
201 rect.right -= pt.x;
202
203 if ( x )
204 *x = rect.right;
205 if ( y )
206 *y = rect.bottom;
207 }
208
209 // Set the client size (i.e. leave the calculation of borders etc.
210 // to wxWindows)
211 void wxFrame::DoSetClientSize(int width, int height)
212 {
213 HWND hWnd = GetHwnd();
214
215 RECT rect;
216 ::GetClientRect(hWnd, &rect);
217
218 RECT rect2;
219 GetWindowRect(hWnd, &rect2);
220
221 // Find the difference between the entire window (title bar and all)
222 // and the client area; add this to the new client size to move the
223 // window
224 int actual_width = rect2.right - rect2.left - rect.right + width;
225 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
226
227 #if wxUSE_STATUSBAR
228 if ( GetStatusBar() )
229 {
230 int statusX, statusY;
231 GetStatusBar()->GetClientSize(&statusX, &statusY);
232 actual_height += statusY;
233 }
234 #endif // wxUSE_STATUSBAR
235
236 wxPoint pt(GetClientAreaOrigin());
237 actual_width += pt.y;
238 actual_height += pt.x;
239
240 POINT point;
241 point.x = rect2.left;
242 point.y = rect2.top;
243
244 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
245
246 wxSizeEvent event(wxSize(width, height), m_windowId);
247 event.SetEventObject( this );
248 GetEventHandler()->ProcessEvent(event);
249 }
250
251 void wxFrame::DoGetSize(int *width, int *height) const
252 {
253 RECT rect;
254 GetWindowRect(GetHwnd(), &rect);
255 *width = rect.right - rect.left;
256 *height = rect.bottom - rect.top;
257 }
258
259 void wxFrame::DoGetPosition(int *x, int *y) const
260 {
261 RECT rect;
262 GetWindowRect(GetHwnd(), &rect);
263 POINT point;
264 point.x = rect.left;
265 point.y = rect.top;
266
267 *x = point.x;
268 *y = point.y;
269 }
270
271 // ----------------------------------------------------------------------------
272 // variations around ::ShowWindow()
273 // ----------------------------------------------------------------------------
274
275 void wxFrame::DoShowWindow(int nShowCmd)
276 {
277 ::ShowWindow(GetHwnd(), nShowCmd);
278
279 m_iconized = nShowCmd == SW_MINIMIZE;
280 }
281
282 bool wxFrame::Show(bool show)
283 {
284 DoShowWindow(show ? SW_SHOW : SW_HIDE);
285
286 if ( show )
287 {
288 ::BringWindowToTop(GetHwnd());
289
290 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
291 event.SetEventObject( this );
292 GetEventHandler()->ProcessEvent(event);
293 }
294 else
295 {
296 // Try to highlight the correct window (the parent)
297 if ( GetParent() )
298 {
299 HWND hWndParent = GetHwndOf(GetParent());
300 if (hWndParent)
301 ::BringWindowToTop(hWndParent);
302 }
303 }
304
305 return TRUE;
306 }
307
308 void wxFrame::Iconize(bool iconize)
309 {
310 DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE);
311 }
312
313 void wxFrame::Maximize(bool maximize)
314 {
315 DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE);
316 }
317
318 void wxFrame::Restore()
319 {
320 DoShowWindow(SW_RESTORE);
321 }
322
323 bool wxFrame::IsIconized() const
324 {
325 ((wxFrame *)this)->m_iconized = (::IsIconic(GetHwnd()) != 0);
326 return m_iconized;
327 }
328
329 // Is it maximized?
330 bool wxFrame::IsMaximized() const
331 {
332 return (::IsZoomed(GetHwnd()) != 0);
333 }
334
335 void wxFrame::SetIcon(const wxIcon& icon)
336 {
337 wxFrameBase::SetIcon(icon);
338
339 #if defined(__WIN95__)
340 if ( m_icon.Ok() )
341 {
342 SendMessage(GetHwnd(), WM_SETICON,
343 (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON());
344 }
345 #endif // __WIN95__
346 }
347
348 #if wxUSE_STATUSBAR
349 wxStatusBar *wxFrame::OnCreateStatusBar(int number,
350 long style,
351 wxWindowID id,
352 const wxString& name)
353 {
354 wxStatusBar *statusBar = NULL;
355
356 #if wxUSE_NATIVE_STATUSBAR
357 if ( UsesNativeStatusBar() )
358 {
359 statusBar = new wxStatusBar95(this, id, style);
360 }
361 else
362 #endif
363 {
364 statusBar = wxFrameBase::OnCreateStatusBar(number, style, id, name);
365 }
366
367 return statusBar;
368 }
369
370 void wxFrame::PositionStatusBar()
371 {
372 // native status bar positions itself
373 if ( m_frameStatusBar
374 #if wxUSE_NATIVE_STATUSBAR
375 && !m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))
376 #endif
377 )
378 {
379 int w, h;
380 GetClientSize(&w, &h);
381 int sw, sh;
382 m_frameStatusBar->GetSize(&sw, &sh);
383
384 // Since we wish the status bar to be directly under the client area,
385 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
386 m_frameStatusBar->SetSize(0, h, w, sh);
387 }
388 }
389 #endif // wxUSE_STATUSBAR
390
391 void wxFrame::DetachMenuBar()
392 {
393 if (m_frameMenuBar)
394 {
395 m_frameMenuBar->Detach();
396 m_frameMenuBar = NULL;
397 }
398 }
399
400 void wxFrame::SetMenuBar(wxMenuBar *menu_bar)
401 {
402 if (!menu_bar)
403 {
404 DetachMenuBar();
405 return;
406 }
407
408 wxCHECK_RET( !menu_bar->GetFrame(), wxT("this menubar is already attached") );
409
410 if (m_frameMenuBar)
411 delete m_frameMenuBar;
412
413 m_hMenu = menu_bar->Create();
414
415 if ( !m_hMenu )
416 return;
417
418 InternalSetMenuBar();
419
420 m_frameMenuBar = menu_bar;
421 menu_bar->Attach(this);
422 }
423
424 void wxFrame::InternalSetMenuBar()
425 {
426 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
427 {
428 wxLogLastError("SetMenu");
429 }
430 }
431
432 // Responds to colour changes, and passes event on to children.
433 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
434 {
435 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
436 Refresh();
437
438 if ( m_frameStatusBar )
439 {
440 wxSysColourChangedEvent event2;
441 event2.SetEventObject( m_frameStatusBar );
442 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
443 }
444
445 // Propagate the event to the non-top-level children
446 wxWindow::OnSysColourChanged(event);
447 }
448
449 /*
450 * Frame window
451 *
452 */
453
454 bool wxFrame::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title,
455 int x, int y, int width, int height, long style)
456
457 {
458 m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
459
460 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
461 // could be the culprit. But without it, you can get a lot of flicker.
462
463 DWORD msflags = 0;
464 if ((style & wxCAPTION) == wxCAPTION)
465 msflags = WS_OVERLAPPED;
466 else
467 msflags = WS_POPUP;
468
469 if (style & wxMINIMIZE_BOX)
470 msflags |= WS_MINIMIZEBOX;
471 if (style & wxMAXIMIZE_BOX)
472 msflags |= WS_MAXIMIZEBOX;
473 if (style & wxTHICK_FRAME)
474 msflags |= WS_THICKFRAME;
475 if (style & wxSYSTEM_MENU)
476 msflags |= WS_SYSMENU;
477 if ((style & wxMINIMIZE) || (style & wxICONIZE))
478 msflags |= WS_MINIMIZE;
479 if (style & wxMAXIMIZE)
480 msflags |= WS_MAXIMIZE;
481 if (style & wxCAPTION)
482 msflags |= WS_CAPTION;
483 if (style & wxCLIP_CHILDREN)
484 msflags |= WS_CLIPCHILDREN;
485
486 // Keep this in wxFrame because it saves recoding this function
487 // in wxTinyFrame
488 #if wxUSE_ITSY_BITSY
489 if (style & wxTINY_CAPTION_VERT)
490 msflags |= IBS_VERTCAPTION;
491 if (style & wxTINY_CAPTION_HORIZ)
492 msflags |= IBS_HORZCAPTION;
493 #else
494 if (style & wxTINY_CAPTION_VERT)
495 msflags |= WS_CAPTION;
496 if (style & wxTINY_CAPTION_HORIZ)
497 msflags |= WS_CAPTION;
498 #endif
499 if ((style & wxTHICK_FRAME) == 0)
500 msflags |= WS_BORDER;
501
502 WXDWORD extendedStyle = MakeExtendedStyle(style);
503
504 #if !defined(__WIN16__) && !defined(__SC__)
505 if (style & wxFRAME_TOOL_WINDOW)
506 extendedStyle |= WS_EX_TOOLWINDOW;
507 #endif
508
509 if (style & wxSTAY_ON_TOP)
510 extendedStyle |= WS_EX_TOPMOST;
511
512 m_iconized = FALSE;
513 if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height,
514 msflags, NULL, extendedStyle) )
515 return FALSE;
516
517 // Seems to be necessary if we use WS_POPUP
518 // style instead of WS_OVERLAPPED
519 if (width > -1 && height > -1)
520 ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height));
521
522 return TRUE;
523 }
524
525 // Default activation behaviour - set the focus for the first child
526 // subwindow found.
527 void wxFrame::OnActivate(wxActivateEvent& event)
528 {
529 for ( wxWindowList::Node *node = GetChildren().GetFirst();
530 node;
531 node = node->GetNext() )
532 {
533 // FIXME all this is totally bogus - we need to do the same as wxPanel,
534 // but how to do it without duplicating the code?
535
536 // restore focus
537 wxWindow *child = node->GetData();
538
539 if ( !child->IsTopLevel()
540 #if wxUSE_TOOLBAR
541 && !wxDynamicCast(child, wxToolBar)
542 #endif // wxUSE_TOOLBAR
543 #if wxUSE_STATUSBAR
544 && !wxDynamicCast(child, wxStatusBar)
545 #endif // wxUSE_STATUSBAR
546 )
547 {
548 child->SetFocus();
549 return;
550 }
551 }
552 }
553
554 // ----------------------------------------------------------------------------
555 // wxFrame size management: we exclude the areas taken by menu/status/toolbars
556 // from the client area, so the client area is what's really available for the
557 // frame contents
558 // ----------------------------------------------------------------------------
559
560 // Checks if there is a toolbar, and returns the first free client position
561 wxPoint wxFrame::GetClientAreaOrigin() const
562 {
563 wxPoint pt(0, 0);
564 if (GetToolBar())
565 {
566 int w, h;
567 GetToolBar()->GetSize(& w, & h);
568
569 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
570 {
571 pt.x += w;
572 }
573 else
574 {
575 pt.y += h;
576 }
577 }
578 return pt;
579 }
580
581 void wxFrame::DoScreenToClient(int *x, int *y) const
582 {
583 wxWindow::DoScreenToClient(x, y);
584
585 // We may be faking the client origin.
586 // So a window that's really at (0, 30) may appear
587 // (to wxWin apps) to be at (0, 0).
588 wxPoint pt(GetClientAreaOrigin());
589 *x -= pt.x;
590 *y -= pt.y;
591 }
592
593 void wxFrame::DoClientToScreen(int *x, int *y) const
594 {
595 // We may be faking the client origin.
596 // So a window that's really at (0, 30) may appear
597 // (to wxWin apps) to be at (0, 0).
598 wxPoint pt1(GetClientAreaOrigin());
599 *x += pt1.x;
600 *y += pt1.y;
601
602 wxWindow::DoClientToScreen(x, y);
603 }
604
605 // ----------------------------------------------------------------------------
606 // tool/status bar stuff
607 // ----------------------------------------------------------------------------
608
609 #if wxUSE_TOOLBAR
610
611 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
612 {
613 if ( wxFrameBase::CreateToolBar(style, id, name) )
614 {
615 PositionToolBar();
616 }
617
618 return m_frameToolBar;
619 }
620
621 void wxFrame::PositionToolBar()
622 {
623 RECT rect;
624 ::GetClientRect(GetHwnd(), &rect);
625
626 #if wxUSE_STATUSBAR
627 if ( GetStatusBar() )
628 {
629 int statusX, statusY;
630 GetStatusBar()->GetClientSize(&statusX, &statusY);
631 rect.bottom -= statusY;
632 }
633 #endif // wxUSE_STATUSBAR
634
635 if ( GetToolBar() )
636 {
637 int tw, th;
638 GetToolBar()->GetSize(&tw, &th);
639
640 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
641 {
642 th = rect.bottom;
643 }
644 else
645 {
646 tw = rect.right;
647 }
648
649 // Use the 'real' MSW position here
650 GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
651 }
652 }
653 #endif // wxUSE_TOOLBAR
654
655 // ----------------------------------------------------------------------------
656 // frame state (iconized/maximized/...)
657 // ----------------------------------------------------------------------------
658
659 // propagate our state change to all child frames: this allows us to emulate X
660 // Windows behaviour where child frames float independently of the parent one
661 // on the desktop, but are iconized/restored with it
662 void wxFrame::IconizeChildFrames(bool bIconize)
663 {
664 for ( wxWindowList::Node *node = GetChildren().GetFirst();
665 node;
666 node = node->GetNext() )
667 {
668 wxWindow *win = node->GetData();
669
670 if ( win->IsKindOf(CLASSINFO(wxFrame)) )
671 {
672 ((wxFrame *)win)->Iconize(bIconize);
673 }
674 }
675 }
676
677 // ===========================================================================
678 // message processing
679 // ===========================================================================
680
681 // ---------------------------------------------------------------------------
682 // preprocessing
683 // ---------------------------------------------------------------------------
684
685 bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
686 {
687 if ( wxWindow::MSWTranslateMessage(pMsg) )
688 return TRUE;
689
690 // try the menu bar accels
691 wxMenuBar *menuBar = GetMenuBar();
692 if ( !menuBar )
693 return FALSE;
694
695 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
696 return acceleratorTable.Translate(this, pMsg);
697 }
698
699 // ---------------------------------------------------------------------------
700 // our private (non virtual) message handlers
701 // ---------------------------------------------------------------------------
702
703 bool wxFrame::HandlePaint()
704 {
705 RECT rect;
706 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
707 {
708 if ( m_iconized )
709 {
710 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
711 : (HICON)m_defaultIcon;
712
713 // Hold a pointer to the dc so long as the OnPaint() message
714 // is being processed
715 PAINTSTRUCT ps;
716 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
717
718 // Erase background before painting or we get white background
719 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
720
721 if ( hIcon )
722 {
723 RECT rect;
724 ::GetClientRect(GetHwnd(), &rect);
725
726 // FIXME: why hardcoded?
727 static const int icon_width = 32;
728 static const int icon_height = 32;
729
730 int icon_x = (int)((rect.right - icon_width)/2);
731 int icon_y = (int)((rect.bottom - icon_height)/2);
732
733 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
734 }
735
736 ::EndPaint(GetHwnd(), &ps);
737
738 return TRUE;
739 }
740 else
741 {
742 return wxWindow::HandlePaint();
743 }
744 }
745 else
746 {
747 // nothing to paint - processed
748 return TRUE;
749 }
750 }
751
752 bool wxFrame::HandleSize(int x, int y, WXUINT id)
753 {
754 bool processed = FALSE;
755
756 switch ( id )
757 {
758 case SIZENORMAL:
759 // only do it it if we were iconized before, otherwise resizing the
760 // parent frame has a curious side effect of bringing it under it's
761 // children
762 if ( !m_iconized )
763 break;
764
765 // restore all child frames too
766 IconizeChildFrames(FALSE);
767
768 // fall through
769
770 case SIZEFULLSCREEN:
771 m_iconized = FALSE;
772 break;
773
774 case SIZEICONIC:
775 // iconize all child frames too
776 IconizeChildFrames(TRUE);
777
778 m_iconized = TRUE;
779 break;
780 }
781
782 if ( !m_iconized )
783 {
784 // forward WM_SIZE to status bar control
785 #if wxUSE_NATIVE_STATUSBAR
786 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
787 {
788 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
789 event.SetEventObject( m_frameStatusBar );
790
791 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
792 }
793 #endif // wxUSE_NATIVE_STATUSBAR
794
795 PositionStatusBar();
796 PositionToolBar();
797
798 wxSizeEvent event(wxSize(x, y), m_windowId);
799 event.SetEventObject( this );
800 processed = GetEventHandler()->ProcessEvent(event);
801 }
802
803 return processed;
804 }
805
806 bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
807 {
808 if ( control )
809 {
810 // In case it's e.g. a toolbar.
811 wxWindow *win = wxFindWinFromHandle(control);
812 if ( win )
813 return win->MSWCommand(cmd, id);
814 }
815
816 // handle here commands from menus and accelerators
817 if ( cmd == 0 || cmd == 1 )
818 {
819 if ( wxCurrentPopupMenu )
820 {
821 wxMenu *popupMenu = wxCurrentPopupMenu;
822 wxCurrentPopupMenu = NULL;
823
824 return popupMenu->MSWCommand(cmd, id);
825 }
826
827 if ( ProcessCommand(id) )
828 {
829 return TRUE;
830 }
831 }
832
833 return FALSE;
834 }
835
836 bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
837 {
838 int item;
839 if ( flags == 0xFFFF && hMenu == 0 )
840 {
841 // menu was removed from screen
842 item = -1;
843 }
844 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
845 {
846 item = nItem;
847 }
848 else
849 {
850 // don't give hints for separators (doesn't make sense) nor for the
851 // items opening popup menus (they don't have them anyhow)
852 return FALSE;
853 }
854
855 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
856 event.SetEventObject( this );
857
858 return GetEventHandler()->ProcessEvent(event);
859 }
860
861 // ---------------------------------------------------------------------------
862 // the window proc for wxFrame
863 // ---------------------------------------------------------------------------
864
865 long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
866 {
867 long rc = 0;
868 bool processed = FALSE;
869
870 switch ( message )
871 {
872 case WM_CLOSE:
873 // if we can't close, tell the system that we processed the
874 // message - otherwise it would close us
875 processed = !Close();
876 break;
877
878 case WM_COMMAND:
879 {
880 WORD id, cmd;
881 WXHWND hwnd;
882 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
883 &id, &hwnd, &cmd);
884
885 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
886 }
887 break;
888
889 case WM_MENUSELECT:
890 {
891 WXWORD item, flags;
892 WXHMENU hmenu;
893 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
894
895 processed = HandleMenuSelect(item, flags, hmenu);
896 }
897 break;
898
899 case WM_PAINT:
900 processed = HandlePaint();
901 break;
902
903 case WM_QUERYDRAGICON:
904 {
905 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
906 : (HICON)(m_defaultIcon);
907 rc = (long)hIcon;
908 processed = rc != 0;
909 }
910 break;
911
912 case WM_SIZE:
913 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
914 break;
915 }
916
917 if ( !processed )
918 rc = wxWindow::MSWWindowProc(message, wParam, lParam);
919
920 return rc;
921 }
922