]> git.saurik.com Git - wxWidgets.git/blob - src/msw/frame.cpp
Documented help API extension and fixed gsocket compilation.
[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 wxString help;
640 int menuId = event.GetMenuId();
641 if ( menuId != -1 )
642 {
643 wxMenuBar *menuBar = GetMenuBar();
644 if (menuBar && menuBar->FindItem(menuId))
645 {
646 help = menuBar->GetHelpString(menuId);
647 }
648 }
649
650 // set status text even if the string is empty - this will at
651 // least remove the string from the item which was previously
652 // selected
653 SetStatusText(help);
654 }
655 }
656
657 wxMenuBar *wxFrame::GetMenuBar() const
658 {
659 return m_frameMenuBar;
660 }
661
662 bool wxFrame::ProcessCommand(int id)
663 {
664 wxMenuBar *bar = GetMenuBar() ;
665 if ( !bar )
666 return FALSE;
667
668 wxMenuItem *item = bar->FindItemForId(id);
669 if ( !item )
670 return FALSE;
671
672 if ( item->IsCheckable() )
673 {
674 bar->Check(id, !bar->IsChecked(id)) ;
675 }
676
677 wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
678 commandEvent.SetInt( id );
679 commandEvent.SetEventObject( this );
680
681 return GetEventHandler()->ProcessEvent(commandEvent);
682 }
683
684 // Checks if there is a toolbar, and returns the first free client position
685 wxPoint wxFrame::GetClientAreaOrigin() const
686 {
687 wxPoint pt(0, 0);
688 if (GetToolBar())
689 {
690 int w, h;
691 GetToolBar()->GetSize(& w, & h);
692
693 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
694 {
695 pt.x += w;
696 }
697 else
698 {
699 pt.y += h;
700 }
701 }
702 return pt;
703 }
704
705 void wxFrame::ScreenToClient(int *x, int *y) const
706 {
707 wxWindow::ScreenToClient(x, y);
708
709 // We may be faking the client origin.
710 // So a window that's really at (0, 30) may appear
711 // (to wxWin apps) to be at (0, 0).
712 wxPoint pt(GetClientAreaOrigin());
713 *x -= pt.x;
714 *y -= pt.y;
715 }
716
717 void wxFrame::ClientToScreen(int *x, int *y) const
718 {
719 // We may be faking the client origin.
720 // So a window that's really at (0, 30) may appear
721 // (to wxWin apps) to be at (0, 0).
722 wxPoint pt1(GetClientAreaOrigin());
723 *x += pt1.x;
724 *y += pt1.y;
725
726 wxWindow::ClientToScreen(x, y);
727 }
728
729 #if wxUSE_TOOLBAR
730 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
731 {
732 wxCHECK_MSG( m_frameToolBar == NULL, FALSE,
733 _T("recreating toolbar in wxFrame") );
734
735 wxToolBar* toolBar = OnCreateToolBar(style, id, name);
736 if (toolBar)
737 {
738 SetToolBar(toolBar);
739 PositionToolBar();
740 return toolBar;
741 }
742 else
743 {
744 return NULL;
745 }
746 }
747
748 wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name)
749 {
750 return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name);
751 }
752
753 void wxFrame::PositionToolBar()
754 {
755 RECT rect;
756 ::GetClientRect(GetHwnd(), &rect);
757
758 if ( GetStatusBar() )
759 {
760 int statusX, statusY;
761 GetStatusBar()->GetClientSize(&statusX, &statusY);
762 rect.bottom -= statusY;
763 }
764
765 if (GetToolBar())
766 {
767 int tw, th;
768 GetToolBar()->GetSize(& tw, & th);
769
770 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
771 {
772 // Use the 'real' MSW position
773 GetToolBar()->SetSize(0, 0, tw, rect.bottom, wxSIZE_NO_ADJUSTMENTS);
774 }
775 else
776 {
777 // Use the 'real' MSW position
778 GetToolBar()->SetSize(0, 0, rect.right, th, wxSIZE_NO_ADJUSTMENTS);
779 }
780 }
781 }
782 #endif // wxUSE_TOOLBAR
783
784 // propagate our state change to all child frames: this allows us to emulate X
785 // Windows behaviour where child frames float independently of the parent one
786 // on the desktop, but are iconized/restored with it
787 void wxFrame::IconizeChildFrames(bool bIconize)
788 {
789 for ( wxWindowList::Node *node = GetChildren().GetFirst();
790 node;
791 node = node->GetNext() )
792 {
793 wxWindow *win = node->GetData();
794
795 if ( win->IsKindOf(CLASSINFO(wxFrame)) )
796 {
797 ((wxFrame *)win)->Iconize(bIconize);
798 }
799 }
800 }
801
802
803 // make the window modal (all other windows unresponsive)
804 void wxFrame::MakeModal(bool modal)
805 {
806 if (modal) {
807 wxEnableTopLevelWindows(FALSE);
808 Enable(TRUE); // keep this window enabled
809 }
810 else {
811 wxEnableTopLevelWindows(TRUE);
812 }
813 }
814
815
816 // ===========================================================================
817 // message processing
818 // ===========================================================================
819
820 // ---------------------------------------------------------------------------
821 // preprocessing
822 // ---------------------------------------------------------------------------
823
824 bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
825 {
826 if ( wxWindow::MSWTranslateMessage(pMsg) )
827 return TRUE;
828
829 // try the menu bar accels
830 wxMenuBar *menuBar = GetMenuBar();
831 if ( !menuBar )
832 return FALSE;
833
834 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
835 return acceleratorTable.Translate(this, pMsg);
836 }
837
838 // ---------------------------------------------------------------------------
839 // our private (non virtual) message handlers
840 // ---------------------------------------------------------------------------
841
842 bool wxFrame::HandlePaint()
843 {
844 RECT rect;
845 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
846 {
847 if ( m_iconized )
848 {
849 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
850 : (HICON)m_defaultIcon;
851
852 // Hold a pointer to the dc so long as the OnPaint() message
853 // is being processed
854 PAINTSTRUCT ps;
855 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
856
857 // Erase background before painting or we get white background
858 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
859
860 if ( hIcon )
861 {
862 RECT rect;
863 ::GetClientRect(GetHwnd(), &rect);
864
865 // FIXME: why hardcoded?
866 static const int icon_width = 32;
867 static const int icon_height = 32;
868
869 int icon_x = (int)((rect.right - icon_width)/2);
870 int icon_y = (int)((rect.bottom - icon_height)/2);
871
872 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
873 }
874
875 ::EndPaint(GetHwnd(), &ps);
876
877 return TRUE;
878 }
879 else
880 {
881 return wxWindow::HandlePaint();
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 flags, WXHMENU hMenu)
976 {
977 int item;
978 if ( flags == 0xFFFF && hMenu == 0 )
979 {
980 // menu was removed from screen
981 item = -1;
982 }
983 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
984 {
985 item = nItem;
986 }
987 else
988 {
989 // don't give hints for separators (doesn't make sense) nor for the
990 // items opening popup menus (they don't have them anyhow)
991 return FALSE;
992 }
993
994 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
995 event.SetEventObject( this );
996
997 return GetEventHandler()->ProcessEvent(event);
998 }
999
1000 // ---------------------------------------------------------------------------
1001 // the window proc for wxFrame
1002 // ---------------------------------------------------------------------------
1003
1004 long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
1005 {
1006 long rc = 0;
1007 bool processed = FALSE;
1008
1009 switch ( message )
1010 {
1011 case WM_CLOSE:
1012 // if we can't close, tell the system that we processed the
1013 // message - otherwise it would close us
1014 processed = !Close();
1015 break;
1016
1017 case WM_COMMAND:
1018 {
1019 WORD id, cmd;
1020 WXHWND hwnd;
1021 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
1022 &id, &hwnd, &cmd);
1023
1024 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
1025 }
1026 break;
1027
1028 case WM_MENUSELECT:
1029 {
1030 WXWORD item, flags;
1031 WXHMENU hmenu;
1032 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
1033
1034 processed = HandleMenuSelect(item, flags, hmenu);
1035 }
1036 break;
1037
1038 case WM_PAINT:
1039 processed = HandlePaint();
1040 break;
1041
1042 case WM_QUERYDRAGICON:
1043 {
1044 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
1045 : (HICON)(m_defaultIcon);
1046 rc = (long)hIcon;
1047 processed = rc != 0;
1048 }
1049 break;
1050
1051 case WM_SIZE:
1052 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
1053 break;
1054 }
1055
1056 if ( !processed )
1057 rc = wxWindow::MSWWindowProc(message, wParam, lParam);
1058
1059 return rc;
1060 }