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