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