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