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