]> git.saurik.com Git - wxWidgets.git/blob - src/msw/frame.cpp
String changes for translations,
[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 statusBar->SetFieldsCount(number);
362 }
363 else
364 #endif
365 {
366 statusBar = wxFrameBase::OnCreateStatusBar(number, style, id, name);
367 }
368
369 return statusBar;
370 }
371
372 void wxFrame::PositionStatusBar()
373 {
374 // native status bar positions itself
375 if ( m_frameStatusBar
376 #if wxUSE_NATIVE_STATUSBAR
377 && !m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))
378 #endif
379 )
380 {
381 int w, h;
382 GetClientSize(&w, &h);
383 int sw, sh;
384 m_frameStatusBar->GetSize(&sw, &sh);
385
386 // Since we wish the status bar to be directly under the client area,
387 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
388 m_frameStatusBar->SetSize(0, h, w, sh);
389 }
390 }
391 #endif // wxUSE_STATUSBAR
392
393 void wxFrame::DetachMenuBar()
394 {
395 if (m_frameMenuBar)
396 {
397 m_frameMenuBar->Detach();
398 m_frameMenuBar = NULL;
399 }
400 }
401
402 void wxFrame::SetMenuBar(wxMenuBar *menu_bar)
403 {
404 if (!menu_bar)
405 {
406 DetachMenuBar();
407 return;
408 }
409
410 m_frameMenuBar = NULL;
411
412 // Can set a menubar several times.
413 // TODO: how to prevent a memory leak if you have a currently-unattached
414 // menubar? wxWindows assumes that the frame will delete the menu (otherwise
415 // there are problems for MDI).
416 if (menu_bar->GetHMenu())
417 {
418 m_hMenu = menu_bar->GetHMenu();
419 }
420 else
421 {
422 menu_bar->Detach();
423
424 m_hMenu = menu_bar->Create();
425
426 if ( !m_hMenu )
427 return;
428 }
429
430 InternalSetMenuBar();
431
432 m_frameMenuBar = menu_bar;
433 menu_bar->Attach(this);
434
435 #if 0 // Old code that assumes only one call of SetMenuBar per frame.
436 if (!menu_bar)
437 {
438 DetachMenuBar();
439 return;
440 }
441
442 wxCHECK_RET( !menu_bar->GetFrame(), wxT("this menubar is already attached") );
443
444 if (m_frameMenuBar)
445 delete m_frameMenuBar;
446
447 m_hMenu = menu_bar->Create();
448
449 if ( !m_hMenu )
450 return;
451
452 InternalSetMenuBar();
453
454 m_frameMenuBar = menu_bar;
455 menu_bar->Attach(this);
456 #endif
457 }
458
459 void wxFrame::InternalSetMenuBar()
460 {
461 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
462 {
463 wxLogLastError("SetMenu");
464 }
465 }
466
467 // Responds to colour changes, and passes event on to children.
468 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
469 {
470 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
471 Refresh();
472
473 if ( m_frameStatusBar )
474 {
475 wxSysColourChangedEvent event2;
476 event2.SetEventObject( m_frameStatusBar );
477 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
478 }
479
480 // Propagate the event to the non-top-level children
481 wxWindow::OnSysColourChanged(event);
482 }
483
484 /*
485 * Frame window
486 *
487 */
488
489 bool wxFrame::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title,
490 int x, int y, int width, int height, long style)
491
492 {
493 m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
494
495 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
496 // could be the culprit. But without it, you can get a lot of flicker.
497
498 DWORD msflags = 0;
499 if ((style & wxCAPTION) == wxCAPTION)
500 msflags = WS_OVERLAPPED;
501 else
502 msflags = WS_POPUP;
503
504 if (style & wxMINIMIZE_BOX)
505 msflags |= WS_MINIMIZEBOX;
506 if (style & wxMAXIMIZE_BOX)
507 msflags |= WS_MAXIMIZEBOX;
508 if (style & wxTHICK_FRAME)
509 msflags |= WS_THICKFRAME;
510 if (style & wxSYSTEM_MENU)
511 msflags |= WS_SYSMENU;
512 if ((style & wxMINIMIZE) || (style & wxICONIZE))
513 msflags |= WS_MINIMIZE;
514 if (style & wxMAXIMIZE)
515 msflags |= WS_MAXIMIZE;
516 if (style & wxCAPTION)
517 msflags |= WS_CAPTION;
518 if (style & wxCLIP_CHILDREN)
519 msflags |= WS_CLIPCHILDREN;
520
521 // Keep this in wxFrame because it saves recoding this function
522 // in wxTinyFrame
523 #if wxUSE_ITSY_BITSY
524 if (style & wxTINY_CAPTION_VERT)
525 msflags |= IBS_VERTCAPTION;
526 if (style & wxTINY_CAPTION_HORIZ)
527 msflags |= IBS_HORZCAPTION;
528 #else
529 if (style & wxTINY_CAPTION_VERT)
530 msflags |= WS_CAPTION;
531 if (style & wxTINY_CAPTION_HORIZ)
532 msflags |= WS_CAPTION;
533 #endif
534 if ((style & wxTHICK_FRAME) == 0)
535 msflags |= WS_BORDER;
536
537 WXDWORD extendedStyle = MakeExtendedStyle(style);
538
539 #if !defined(__WIN16__) && !defined(__SC__)
540 if (style & wxFRAME_TOOL_WINDOW)
541 extendedStyle |= WS_EX_TOOLWINDOW;
542 #endif
543
544 if (style & wxSTAY_ON_TOP)
545 extendedStyle |= WS_EX_TOPMOST;
546
547 m_iconized = FALSE;
548 if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height,
549 msflags, NULL, extendedStyle) )
550 return FALSE;
551
552 // Seems to be necessary if we use WS_POPUP
553 // style instead of WS_OVERLAPPED
554 if (width > -1 && height > -1)
555 ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height));
556
557 return TRUE;
558 }
559
560 // Default activation behaviour - set the focus for the first child
561 // subwindow found.
562 void wxFrame::OnActivate(wxActivateEvent& event)
563 {
564 for ( wxWindowList::Node *node = GetChildren().GetFirst();
565 node;
566 node = node->GetNext() )
567 {
568 // FIXME all this is totally bogus - we need to do the same as wxPanel,
569 // but how to do it without duplicating the code?
570
571 // restore focus
572 wxWindow *child = node->GetData();
573
574 if ( !child->IsTopLevel()
575 #if wxUSE_TOOLBAR
576 && !wxDynamicCast(child, wxToolBar)
577 #endif // wxUSE_TOOLBAR
578 #if wxUSE_STATUSBAR
579 && !wxDynamicCast(child, wxStatusBar)
580 #endif // wxUSE_STATUSBAR
581 )
582 {
583 child->SetFocus();
584 return;
585 }
586 }
587 }
588
589 // ----------------------------------------------------------------------------
590 // tool/status bar stuff
591 // ----------------------------------------------------------------------------
592
593 #if wxUSE_TOOLBAR
594
595 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
596 {
597 if ( wxFrameBase::CreateToolBar(style, id, name) )
598 {
599 PositionToolBar();
600 }
601
602 return m_frameToolBar;
603 }
604
605 void wxFrame::PositionToolBar()
606 {
607 RECT rect;
608 ::GetClientRect(GetHwnd(), &rect);
609
610 #if wxUSE_STATUSBAR
611 if ( GetStatusBar() )
612 {
613 int statusX, statusY;
614 GetStatusBar()->GetClientSize(&statusX, &statusY);
615 rect.bottom -= statusY;
616 }
617 #endif // wxUSE_STATUSBAR
618
619 if ( GetToolBar() )
620 {
621 int tw, th;
622 GetToolBar()->GetSize(&tw, &th);
623
624 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
625 {
626 th = rect.bottom;
627 }
628 else
629 {
630 tw = rect.right;
631 }
632
633 // Use the 'real' MSW position here
634 GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
635 }
636 }
637 #endif // wxUSE_TOOLBAR
638
639 // ----------------------------------------------------------------------------
640 // frame state (iconized/maximized/...)
641 // ----------------------------------------------------------------------------
642
643 // propagate our state change to all child frames: this allows us to emulate X
644 // Windows behaviour where child frames float independently of the parent one
645 // on the desktop, but are iconized/restored with it
646 void wxFrame::IconizeChildFrames(bool bIconize)
647 {
648 for ( wxWindowList::Node *node = GetChildren().GetFirst();
649 node;
650 node = node->GetNext() )
651 {
652 wxWindow *win = node->GetData();
653
654 if ( win->IsKindOf(CLASSINFO(wxFrame)) )
655 {
656 ((wxFrame *)win)->Iconize(bIconize);
657 }
658 }
659 }
660
661 // ===========================================================================
662 // message processing
663 // ===========================================================================
664
665 // ---------------------------------------------------------------------------
666 // preprocessing
667 // ---------------------------------------------------------------------------
668
669 bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
670 {
671 if ( wxWindow::MSWTranslateMessage(pMsg) )
672 return TRUE;
673
674 // try the menu bar accels
675 wxMenuBar *menuBar = GetMenuBar();
676 if ( !menuBar )
677 return FALSE;
678
679 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
680 return acceleratorTable.Translate(this, pMsg);
681 }
682
683 // ---------------------------------------------------------------------------
684 // our private (non virtual) message handlers
685 // ---------------------------------------------------------------------------
686
687 bool wxFrame::HandlePaint()
688 {
689 RECT rect;
690 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
691 {
692 if ( m_iconized )
693 {
694 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
695 : (HICON)m_defaultIcon;
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 {
726 return wxWindow::HandlePaint();
727 }
728 }
729 else
730 {
731 // nothing to paint - processed
732 return TRUE;
733 }
734 }
735
736 bool wxFrame::HandleSize(int x, int y, WXUINT id)
737 {
738 bool processed = FALSE;
739
740 switch ( id )
741 {
742 case SIZENORMAL:
743 // only do it it if we were iconized before, otherwise resizing the
744 // parent frame has a curious side effect of bringing it under it's
745 // children
746 if ( !m_iconized )
747 break;
748
749 // restore all child frames too
750 IconizeChildFrames(FALSE);
751
752 // fall through
753
754 case SIZEFULLSCREEN:
755 m_iconized = FALSE;
756 break;
757
758 case SIZEICONIC:
759 // iconize all child frames too
760 IconizeChildFrames(TRUE);
761
762 m_iconized = TRUE;
763 break;
764 }
765
766 if ( !m_iconized )
767 {
768 // forward WM_SIZE to status bar control
769 #if wxUSE_NATIVE_STATUSBAR
770 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
771 {
772 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
773 event.SetEventObject( m_frameStatusBar );
774
775 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
776 }
777 #endif // wxUSE_NATIVE_STATUSBAR
778
779 PositionStatusBar();
780 PositionToolBar();
781
782 wxSizeEvent event(wxSize(x, y), m_windowId);
783 event.SetEventObject( this );
784 processed = GetEventHandler()->ProcessEvent(event);
785 }
786
787 return processed;
788 }
789
790 bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
791 {
792 if ( control )
793 {
794 // In case it's e.g. a toolbar.
795 wxWindow *win = wxFindWinFromHandle(control);
796 if ( win )
797 return win->MSWCommand(cmd, id);
798 }
799
800 // handle here commands from menus and accelerators
801 if ( cmd == 0 || cmd == 1 )
802 {
803 if ( wxCurrentPopupMenu )
804 {
805 wxMenu *popupMenu = wxCurrentPopupMenu;
806 wxCurrentPopupMenu = NULL;
807
808 return popupMenu->MSWCommand(cmd, id);
809 }
810
811 if ( ProcessCommand(id) )
812 {
813 return TRUE;
814 }
815 }
816
817 return FALSE;
818 }
819
820 bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
821 {
822 int item;
823 if ( flags == 0xFFFF && hMenu == 0 )
824 {
825 // menu was removed from screen
826 item = -1;
827 }
828 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
829 {
830 item = nItem;
831 }
832 else
833 {
834 // don't give hints for separators (doesn't make sense) nor for the
835 // items opening popup menus (they don't have them anyhow)
836 return FALSE;
837 }
838
839 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
840 event.SetEventObject( this );
841
842 return GetEventHandler()->ProcessEvent(event);
843 }
844
845 // ---------------------------------------------------------------------------
846 // the window proc for wxFrame
847 // ---------------------------------------------------------------------------
848
849 long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
850 {
851 long rc = 0;
852 bool processed = FALSE;
853
854 switch ( message )
855 {
856 case WM_CLOSE:
857 // if we can't close, tell the system that we processed the
858 // message - otherwise it would close us
859 processed = !Close();
860 break;
861
862 case WM_COMMAND:
863 {
864 WORD id, cmd;
865 WXHWND hwnd;
866 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
867 &id, &hwnd, &cmd);
868
869 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
870 }
871 break;
872
873 case WM_MENUSELECT:
874 {
875 WXWORD item, flags;
876 WXHMENU hmenu;
877 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
878
879 processed = HandleMenuSelect(item, flags, hmenu);
880 }
881 break;
882
883 case WM_PAINT:
884 processed = HandlePaint();
885 break;
886
887 case WM_QUERYDRAGICON:
888 {
889 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
890 : (HICON)(m_defaultIcon);
891 rc = (long)hIcon;
892 processed = rc != 0;
893 }
894 break;
895
896 case WM_SIZE:
897 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
898 break;
899 }
900
901 if ( !processed )
902 rc = wxWindow::MSWWindowProc(message, wParam, lParam);
903
904 return rc;
905 }
906