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