]> git.saurik.com Git - wxWidgets.git/blob - src/msw/frame.cpp
wxUniv compilation fixes
[wxWidgets.git] / src / msw / frame.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/frame.cpp
3 // Purpose: wxFrameMSW
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "frame.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/frame.h"
33 #include "wx/app.h"
34 #include "wx/menu.h"
35 #include "wx/utils.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/dcclient.h"
39 #include "wx/mdi.h"
40 #include "wx/panel.h"
41 #endif // WX_PRECOMP
42
43 #include "wx/msw/private.h"
44
45 #if wxUSE_STATUSBAR
46 #include "wx/statusbr.h"
47 #include "wx/generic/statusbr.h"
48 #endif // wxUSE_STATUSBAR
49
50 #if wxUSE_TOOLBAR
51 #include "wx/toolbar.h"
52 #endif // wxUSE_TOOLBAR
53
54 #include "wx/menuitem.h"
55 #include "wx/log.h"
56
57 #ifdef __WXUNIVERSAL__
58 #include "wx/univ/theme.h"
59 #include "wx/univ/colschem.h"
60 #endif // __WXUNIVERSAL__
61
62 // ----------------------------------------------------------------------------
63 // globals
64 // ----------------------------------------------------------------------------
65
66 extern wxWindowList wxModelessWindows;
67 extern wxList WXDLLEXPORT wxPendingDelete;
68 extern const wxChar *wxFrameClassName;
69
70 #if wxUSE_MENUS_NATIVE
71 extern wxMenu *wxCurrentPopupMenu;
72 #endif // wxUSE_MENUS_NATIVE
73
74 // ----------------------------------------------------------------------------
75 // event tables
76 // ----------------------------------------------------------------------------
77
78 BEGIN_EVENT_TABLE(wxFrameMSW, wxFrameBase)
79 EVT_ACTIVATE(wxFrameMSW::OnActivate)
80 EVT_SYS_COLOUR_CHANGED(wxFrameMSW::OnSysColourChanged)
81 END_EVENT_TABLE()
82
83 #ifndef __WXUNIVERSAL__
84 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
85 #endif
86
87 // ============================================================================
88 // implementation
89 // ============================================================================
90
91 // ----------------------------------------------------------------------------
92 // static class members
93 // ----------------------------------------------------------------------------
94
95 #if wxUSE_STATUSBAR
96 #if wxUSE_NATIVE_STATUSBAR
97 bool wxFrameMSW::m_useNativeStatusBar = TRUE;
98 #else
99 bool wxFrameMSW::m_useNativeStatusBar = FALSE;
100 #endif
101 #endif // wxUSE_NATIVE_STATUSBAR
102
103 // ----------------------------------------------------------------------------
104 // creation/destruction
105 // ----------------------------------------------------------------------------
106
107 void wxFrameMSW::Init()
108 {
109 m_iconized =
110 m_maximizeOnShow = FALSE;
111
112 #if wxUSE_TOOLTIPS
113 m_hwndToolTip = 0;
114 #endif
115
116 // Data to save/restore when calling ShowFullScreen
117 m_fsStyle = 0;
118 m_fsOldWindowStyle = 0;
119 m_fsStatusBarFields = 0;
120 m_fsStatusBarHeight = 0;
121 m_fsToolBarHeight = 0;
122 // m_fsMenu = 0;
123 m_fsIsMaximized = FALSE;
124 m_fsIsShowing = FALSE;
125
126 m_winLastFocused = (wxWindow *)NULL;
127
128 // unlike (almost?) all other windows, frames are created hidden
129 m_isShown = FALSE;
130 }
131
132 bool wxFrameMSW::Create(wxWindow *parent,
133 wxWindowID id,
134 const wxString& title,
135 const wxPoint& pos,
136 const wxSize& size,
137 long style,
138 const wxString& name)
139 {
140 SetName(name);
141 m_windowStyle = style;
142 #if wxUSE_MENUS
143 m_frameMenuBar = NULL;
144 #endif // wxUSE_MENUS
145 #if wxUSE_TOOLBAR
146 m_frameToolBar = NULL;
147 #endif // wxUSE_TOOLBAR
148 #if wxUSE_STATUSBAR
149 m_frameStatusBar = NULL;
150 #endif // wxUSE_STATUSBAR
151
152 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
153
154 if ( id > -1 )
155 m_windowId = id;
156 else
157 m_windowId = (int)NewControlId();
158
159 if (parent) parent->AddChild(this);
160
161 int x = pos.x;
162 int y = pos.y;
163 int width = size.x;
164 int height = size.y;
165
166 m_iconized = FALSE;
167
168 wxTopLevelWindows.Append(this);
169
170 MSWCreate(m_windowId, parent, wxFrameClassName, this, title,
171 x, y, width, height, style);
172
173 wxModelessWindows.Append(this);
174
175 return TRUE;
176 }
177
178 wxFrameMSW::~wxFrameMSW()
179 {
180 m_isBeingDeleted = TRUE;
181 wxTopLevelWindows.DeleteObject(this);
182
183 // the ~wxToolBar() code relies on the previous line to be executed before
184 // this one, i.e. the frame should remove itself from wxTopLevelWindows
185 // before destorying its toolbar
186 DeleteAllBars();
187
188 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
189 {
190 wxTheApp->SetTopWindow(NULL);
191
192 if (wxTheApp->GetExitOnFrameDelete())
193 {
194 PostQuitMessage(0);
195 }
196 }
197
198 wxModelessWindows.DeleteObject(this);
199
200 // For some reason, wxWindows can activate another task altogether
201 // when a frame is destroyed after a modal dialog has been invoked.
202 // Try to bring the parent to the top.
203 // MT:Only do this if this frame is currently the active window, else weird
204 // things start to happen
205 if ( wxGetActiveWindow() == this )
206 if (GetParent() && GetParent()->GetHWND())
207 ::BringWindowToTop((HWND) GetParent()->GetHWND());
208 }
209
210 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
211 void wxFrameMSW::DoGetClientSize(int *x, int *y) const
212 {
213 RECT rect;
214 ::GetClientRect(GetHwnd(), &rect);
215
216 #if wxUSE_STATUSBAR
217 if ( GetStatusBar() && GetStatusBar()->IsShown() )
218 {
219 int statusX, statusY;
220 GetStatusBar()->GetClientSize(&statusX, &statusY);
221 rect.bottom -= statusY;
222 }
223 #endif // wxUSE_STATUSBAR
224
225 wxPoint pt(GetClientAreaOrigin());
226 rect.bottom -= pt.y;
227 rect.right -= pt.x;
228
229 if ( x )
230 *x = rect.right;
231 if ( y )
232 *y = rect.bottom;
233 }
234
235 // Set the client size (i.e. leave the calculation of borders etc.
236 // to wxWindows)
237 void wxFrameMSW::DoSetClientSize(int width, int height)
238 {
239 HWND hWnd = GetHwnd();
240
241 RECT rectClient;
242 ::GetClientRect(hWnd, &rectClient);
243
244 RECT rectTotal;
245 ::GetWindowRect(hWnd, &rectTotal);
246
247 // Find the difference between the entire window (title bar and all)
248 // and the client area; add this to the new client size to move the
249 // window
250 width += rectTotal.right - rectTotal.left - rectClient.right;
251 height += rectTotal.bottom - rectTotal.top - rectClient.bottom;
252
253 #if wxUSE_STATUSBAR
254 wxStatusBar *statbar = GetStatusBar();
255 if ( statbar && statbar->IsShown() )
256 {
257 // leave enough space for the status bar
258 height += statbar->GetSize().y;
259 }
260 #endif // wxUSE_STATUSBAR
261
262 // note that this takes the toolbar into account
263 wxPoint pt = GetClientAreaOrigin();
264 width += pt.x;
265 height += pt.y;
266
267 if ( !::MoveWindow(hWnd, rectTotal.left, rectTotal.top,
268 width, height, TRUE /* redraw */) )
269 {
270 wxLogLastError(_T("MoveWindow"));
271 }
272
273 wxSizeEvent event(wxSize(width, height), m_windowId);
274 event.SetEventObject(this);
275 GetEventHandler()->ProcessEvent(event);
276 }
277
278 void wxFrameMSW::DoGetSize(int *width, int *height) const
279 {
280 RECT rect;
281 ::GetWindowRect(GetHwnd(), &rect);
282
283 *width = rect.right - rect.left;
284 *height = rect.bottom - rect.top;
285 }
286
287 void wxFrameMSW::DoGetPosition(int *x, int *y) const
288 {
289 RECT rect;
290 ::GetWindowRect(GetHwnd(), &rect);
291
292 *x = rect.left;
293 *y = rect.top;
294 }
295
296 // ----------------------------------------------------------------------------
297 // variations around ::ShowWindow()
298 // ----------------------------------------------------------------------------
299
300 void wxFrameMSW::DoShowWindow(int nShowCmd)
301 {
302 ::ShowWindow(GetHwnd(), nShowCmd);
303
304 m_iconized = nShowCmd == SW_MINIMIZE;
305 }
306
307 bool wxFrameMSW::Show(bool show)
308 {
309 // don't use wxWindow version as we want to call DoShowWindow()
310 if ( !wxWindowBase::Show(show) )
311 return FALSE;
312
313 int nShowCmd;
314 if ( show )
315 {
316 if ( m_maximizeOnShow )
317 {
318 // show and maximize
319 nShowCmd = SW_MAXIMIZE;
320
321 m_maximizeOnShow = FALSE;
322 }
323 else // just show
324 {
325 nShowCmd = SW_SHOW;
326 }
327 }
328 else // hide
329 {
330 nShowCmd = SW_HIDE;
331 }
332
333 DoShowWindow(nShowCmd);
334
335 if ( show )
336 {
337 ::BringWindowToTop(GetHwnd());
338
339 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
340 event.SetEventObject( this );
341 GetEventHandler()->ProcessEvent(event);
342 }
343 else // hide
344 {
345 // Try to highlight the correct window (the parent)
346 if ( GetParent() )
347 {
348 HWND hWndParent = GetHwndOf(GetParent());
349 if (hWndParent)
350 ::BringWindowToTop(hWndParent);
351 }
352 }
353
354 return TRUE;
355 }
356
357 void wxFrameMSW::Iconize(bool iconize)
358 {
359 DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE);
360 }
361
362 void wxFrameMSW::Maximize(bool maximize)
363 {
364 if ( IsShown() )
365 {
366 // just maximize it directly
367 DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE);
368 }
369 else // hidden
370 {
371 // we can't maximize the hidden frame because it shows it as well, so
372 // just remember that we should do it later in this case
373 m_maximizeOnShow = TRUE;
374 }
375 }
376
377 void wxFrameMSW::Restore()
378 {
379 DoShowWindow(SW_RESTORE);
380 }
381
382 bool wxFrameMSW::IsIconized() const
383 {
384 #ifdef __WXMICROWIN__
385 // TODO
386 return FALSE;
387 #else
388 ((wxFrameMSW *)this)->m_iconized = (::IsIconic(GetHwnd()) != 0);
389 return m_iconized;
390 #endif
391 }
392
393 // Is it maximized?
394 bool wxFrameMSW::IsMaximized() const
395 {
396 #ifdef __WXMICROWIN__
397 // TODO
398 return FALSE;
399 #else
400 return (::IsZoomed(GetHwnd()) != 0);
401 #endif
402 }
403
404 void wxFrameMSW::SetIcon(const wxIcon& icon)
405 {
406 wxFrameBase::SetIcon(icon);
407
408 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
409 if ( m_icon.Ok() )
410 {
411 SendMessage(GetHwnd(), WM_SETICON,
412 (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON());
413 }
414 #endif // __WIN95__
415 }
416
417 // generate an artificial resize event
418 void wxFrameMSW::SendSizeEvent()
419 {
420 RECT r;
421 #ifdef __WIN16__
422 ::GetWindowRect(GetHwnd(), &r);
423 #else
424 if ( !::GetWindowRect(GetHwnd(), &r) )
425 {
426 wxLogLastError(_T("GetWindowRect"));
427 }
428 #endif
429
430 if ( !m_iconized )
431 {
432 (void)::PostMessage(GetHwnd(), WM_SIZE,
433 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
434 MAKELPARAM(r.right - r.left, r.bottom - r.top));
435 }
436 }
437
438 #if wxUSE_STATUSBAR
439 wxStatusBar *wxFrameMSW::OnCreateStatusBar(int number,
440 long style,
441 wxWindowID id,
442 const wxString& name)
443 {
444 wxStatusBar *statusBar = NULL;
445
446 #if wxUSE_NATIVE_STATUSBAR
447 if ( !UsesNativeStatusBar() )
448 {
449 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
450 }
451 else
452 #endif
453 {
454 statusBar = new wxStatusBar(this, id, style, name);
455 }
456
457 // Set the height according to the font and the border size
458 wxClientDC dc(statusBar);
459 dc.SetFont(statusBar->GetFont());
460
461 wxCoord y;
462 dc.GetTextExtent(_T("X"), NULL, &y );
463
464 int height = (int)( (11*y)/10 + 2*statusBar->GetBorderY());
465
466 statusBar->SetSize(-1, -1, -1, height);
467
468 statusBar->SetFieldsCount(number);
469
470 return statusBar;
471 }
472
473 void wxFrameMSW::PositionStatusBar()
474 {
475 if ( !m_frameStatusBar )
476 return;
477
478 int w, h;
479 GetClientSize(&w, &h);
480 int sw, sh;
481 m_frameStatusBar->GetSize(&sw, &sh);
482
483 // Since we wish the status bar to be directly under the client area,
484 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
485 m_frameStatusBar->SetSize(0, h, w, sh);
486 }
487 #endif // wxUSE_STATUSBAR
488
489 #if wxUSE_MENUS_NATIVE
490
491 void wxFrameMSW::AttachMenuBar(wxMenuBar *menubar)
492 {
493 if ( !menubar )
494 {
495 // actually remove the menu from the frame
496 m_hMenu = (WXHMENU)0;
497 InternalSetMenuBar();
498 }
499 else // set new non NULL menu bar
500 {
501 // Can set a menubar several times.
502 if ( menubar->GetHMenu() )
503 {
504 m_hMenu = menubar->GetHMenu();
505 }
506 else
507 {
508 if ( menubar->IsAttached() )
509 menubar->Detach();
510
511 m_hMenu = menubar->Create();
512
513 if ( !m_hMenu )
514 return;
515 }
516
517 InternalSetMenuBar();
518 }
519 }
520
521 void wxFrameMSW::InternalSetMenuBar()
522 {
523 #ifndef __WXMICROWIN__
524 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
525 {
526 wxLogLastError(wxT("SetMenu"));
527 }
528 #endif
529 }
530
531 #endif // wxUSE_MENUS_NATIVE
532
533 // Responds to colour changes, and passes event on to children.
534 void wxFrameMSW::OnSysColourChanged(wxSysColourChangedEvent& event)
535 {
536 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
537 Refresh();
538
539 #if wxUSE_STATUSBAR
540 if ( m_frameStatusBar )
541 {
542 wxSysColourChangedEvent event2;
543 event2.SetEventObject( m_frameStatusBar );
544 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
545 }
546 #endif // wxUSE_STATUSBAR
547
548 // Propagate the event to the non-top-level children
549 wxWindow::OnSysColourChanged(event);
550 }
551
552 // Pass TRUE to show full screen, FALSE to restore.
553 bool wxFrameMSW::ShowFullScreen(bool show, long style)
554 {
555 if (show)
556 {
557 if (IsFullScreen())
558 return FALSE;
559
560 m_fsIsShowing = TRUE;
561 m_fsStyle = style;
562
563 #if wxUSE_TOOLBAR
564 wxToolBar *theToolBar = GetToolBar();
565 if (theToolBar)
566 theToolBar->GetSize(NULL, &m_fsToolBarHeight);
567
568 // zap the toolbar, menubar, and statusbar
569
570 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
571 {
572 theToolBar->SetSize(-1,0);
573 theToolBar->Show(FALSE);
574 }
575 #endif // wxUSE_TOOLBAR
576
577 #ifndef __WXMICROWIN__
578 if (style & wxFULLSCREEN_NOMENUBAR)
579 SetMenu((HWND)GetHWND(), (HMENU) NULL);
580 #endif
581
582 #if wxUSE_STATUSBAR
583 wxStatusBar *theStatusBar = GetStatusBar();
584 if (theStatusBar)
585 theStatusBar->GetSize(NULL, &m_fsStatusBarHeight);
586
587 // Save the number of fields in the statusbar
588 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
589 {
590 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
591 //SetStatusBar((wxStatusBar*) NULL);
592 //delete theStatusBar;
593 theStatusBar->Show(FALSE);
594 }
595 else
596 m_fsStatusBarFields = 0;
597 #endif // wxUSE_STATUSBAR
598
599 // zap the frame borders
600
601 // save the 'normal' window style
602 m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE);
603
604 // save the old position, width & height, maximize state
605 m_fsOldSize = GetRect();
606 m_fsIsMaximized = IsMaximized();
607
608 // decide which window style flags to turn off
609 LONG newStyle = m_fsOldWindowStyle;
610 LONG offFlags = 0;
611
612 if (style & wxFULLSCREEN_NOBORDER)
613 offFlags |= WS_BORDER;
614 if (style & wxFULLSCREEN_NOCAPTION)
615 offFlags |= (WS_CAPTION | WS_SYSMENU);
616
617 newStyle &= (~offFlags);
618
619 // change our window style to be compatible with full-screen mode
620 SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle);
621
622 // resize to the size of the desktop
623 int width, height;
624
625 RECT rect;
626 ::GetWindowRect(GetDesktopWindow(), &rect);
627 width = rect.right - rect.left;
628 height = rect.bottom - rect.top;
629
630 SetSize(width, height);
631
632 // now flush the window style cache and actually go full-screen
633 SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
634
635 wxSizeEvent event(wxSize(width, height), GetId());
636 GetEventHandler()->ProcessEvent(event);
637
638 return TRUE;
639 }
640 else
641 {
642 if (!IsFullScreen())
643 return FALSE;
644
645 m_fsIsShowing = FALSE;
646
647 #if wxUSE_TOOLBAR
648 wxToolBar *theToolBar = GetToolBar();
649
650 // restore the toolbar, menubar, and statusbar
651 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
652 {
653 theToolBar->SetSize(-1, m_fsToolBarHeight);
654 theToolBar->Show(TRUE);
655 }
656 #endif // wxUSE_TOOLBAR
657
658 #if wxUSE_STATUSBAR
659 if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR )
660 {
661 //CreateStatusBar(m_fsStatusBarFields);
662 if (GetStatusBar())
663 {
664 GetStatusBar()->Show(TRUE);
665 PositionStatusBar();
666 }
667 }
668 #endif // wxUSE_STATUSBAR
669
670 #ifndef __WXMICROWIN__
671 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
672 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
673 #endif
674
675 Maximize(m_fsIsMaximized);
676 SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle);
677 SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
678 m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
679
680 return TRUE;
681 }
682 }
683
684 /*
685 * Frame window
686 *
687 */
688
689 bool wxFrameMSW::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title,
690 int x, int y, int width, int height, long style)
691
692 {
693 m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON);
694
695 // If child windows aren't properly drawn initially, WS_CLIPCHILDREN
696 // could be the culprit. But without it, you can get a lot of flicker.
697
698 DWORD msflags = 0;
699 if ( style & wxCAPTION )
700 {
701 if ( style & wxFRAME_TOOL_WINDOW )
702 msflags |= WS_POPUPWINDOW;
703 else
704 msflags |= WS_OVERLAPPED;
705 }
706 else
707 {
708 msflags |= WS_POPUP;
709 }
710
711 if (style & wxMINIMIZE_BOX)
712 msflags |= WS_MINIMIZEBOX;
713 if (style & wxMAXIMIZE_BOX)
714 msflags |= WS_MAXIMIZEBOX;
715 if (style & wxTHICK_FRAME)
716 msflags |= WS_THICKFRAME;
717 if (style & wxSYSTEM_MENU)
718 msflags |= WS_SYSMENU;
719 if ( style & wxMINIMIZE )
720 msflags |= WS_MINIMIZE;
721 if (style & wxMAXIMIZE)
722 msflags |= WS_MAXIMIZE;
723 if (style & wxCAPTION)
724 msflags |= WS_CAPTION;
725 if (style & wxCLIP_CHILDREN)
726 msflags |= WS_CLIPCHILDREN;
727
728 // Keep this in wxFrameMSW because it saves recoding this function
729 // in wxTinyFrame
730 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
731 if (style & wxTINY_CAPTION_VERT)
732 msflags |= IBS_VERTCAPTION;
733 if (style & wxTINY_CAPTION_HORIZ)
734 msflags |= IBS_HORZCAPTION;
735 #else
736 if (style & wxTINY_CAPTION_VERT)
737 msflags |= WS_CAPTION;
738 if (style & wxTINY_CAPTION_HORIZ)
739 msflags |= WS_CAPTION;
740 #endif
741 if ((style & wxTHICK_FRAME) == 0)
742 msflags |= WS_BORDER;
743
744 WXDWORD extendedStyle = MakeExtendedStyle(style);
745
746 // make all frames appear in the win9x shell taskbar unless
747 // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them
748 // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it
749 #if !defined(__WIN16__) && !defined(__SC__)
750 if ( (style & wxFRAME_TOOL_WINDOW) ||
751 (style & wxFRAME_NO_TASKBAR) )
752 extendedStyle |= WS_EX_TOOLWINDOW;
753 else if ( !(style & wxFRAME_NO_TASKBAR) )
754 extendedStyle |= WS_EX_APPWINDOW;
755 #endif
756
757 if (style & wxSTAY_ON_TOP)
758 extendedStyle |= WS_EX_TOPMOST;
759
760 #ifndef __WIN16__
761 if (m_exStyle & wxFRAME_EX_CONTEXTHELP)
762 extendedStyle |= WS_EX_CONTEXTHELP;
763 #endif
764
765 m_iconized = FALSE;
766 if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height,
767 msflags, NULL, extendedStyle) )
768 return FALSE;
769
770 // Seems to be necessary if we use WS_POPUP
771 // style instead of WS_OVERLAPPED
772 if (width > -1 && height > -1)
773 ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height));
774
775 return TRUE;
776 }
777
778 // Default activation behaviour - set the focus for the first child
779 // subwindow found.
780 void wxFrameMSW::OnActivate(wxActivateEvent& event)
781 {
782 if ( event.GetActive() )
783 {
784 // restore focus to the child which was last focused
785 wxLogTrace(_T("focus"), _T("wxFrameMSW %08x activated."), m_hWnd);
786
787 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
788 : NULL;
789 if ( !parent )
790 {
791 parent = this;
792 }
793
794 wxSetFocusToChild(parent, &m_winLastFocused);
795 }
796 else // deactivating
797 {
798 // remember the last focused child if it is our child
799 m_winLastFocused = FindFocus();
800
801 // so we NULL it out if it's a child from some other frame
802 wxWindow *win = m_winLastFocused;
803 while ( win )
804 {
805 if ( win->IsTopLevel() )
806 {
807 if ( win != this )
808 {
809 m_winLastFocused = NULL;
810 }
811
812 break;
813 }
814
815 win = win->GetParent();
816 }
817
818 wxLogTrace(_T("focus"),
819 _T("wxFrameMSW %08x deactivated, last focused: %08x."),
820 m_hWnd,
821 m_winLastFocused ? GetHwndOf(m_winLastFocused)
822 : NULL);
823
824 event.Skip();
825 }
826 }
827
828 // ----------------------------------------------------------------------------
829 // tool/status bar stuff
830 // ----------------------------------------------------------------------------
831
832 #if wxUSE_TOOLBAR
833
834 wxToolBar* wxFrameMSW::CreateToolBar(long style, wxWindowID id, const wxString& name)
835 {
836 if ( wxFrameBase::CreateToolBar(style, id, name) )
837 {
838 PositionToolBar();
839 }
840
841 return m_frameToolBar;
842 }
843
844 void wxFrameMSW::PositionToolBar()
845 {
846 RECT rect;
847 ::GetClientRect(GetHwnd(), &rect);
848
849 #if wxUSE_STATUSBAR
850 if ( GetStatusBar() )
851 {
852 int statusX, statusY;
853 GetStatusBar()->GetClientSize(&statusX, &statusY);
854 rect.bottom -= statusY;
855 }
856 #endif // wxUSE_STATUSBAR
857
858 if ( GetToolBar() && GetToolBar()->IsShown() )
859 {
860 int tw, th;
861 GetToolBar()->GetSize(&tw, &th);
862
863 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
864 {
865 th = rect.bottom;
866 }
867 else
868 {
869 tw = rect.right;
870 }
871
872 // Use the 'real' MSW position here
873 GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
874 }
875 }
876 #endif // wxUSE_TOOLBAR
877
878 // ----------------------------------------------------------------------------
879 // frame state (iconized/maximized/...)
880 // ----------------------------------------------------------------------------
881
882 // propagate our state change to all child frames: this allows us to emulate X
883 // Windows behaviour where child frames float independently of the parent one
884 // on the desktop, but are iconized/restored with it
885 void wxFrameMSW::IconizeChildFrames(bool bIconize)
886 {
887 for ( wxWindowList::Node *node = GetChildren().GetFirst();
888 node;
889 node = node->GetNext() )
890 {
891 wxWindow *win = node->GetData();
892
893 // iconizing the frames with this style under Win95 shell puts them at
894 // the bottom of the screen (as the MDI children) instead of making
895 // them appear in the taskbar because they are, by virtue of this
896 // style, not managed by the taskbar - instead leave Windows take care
897 // of them
898 #ifdef __WIN95__
899 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
900 continue;
901 #endif // Win95
902
903 // the child MDI frames are a special case and should not be touched by
904 // the parent frame - instead, they are managed by the user
905 wxFrameMSW *frame = wxDynamicCast(win, wxFrame);
906 if ( frame
907 #if wxUSE_MDI_ARCHITECTURE
908 && !wxDynamicCast(frame, wxMDIChildFrame)
909 #endif // wxUSE_MDI_ARCHITECTURE
910 )
911 {
912 frame->Iconize(bIconize);
913 }
914 }
915 }
916
917 // ===========================================================================
918 // message processing
919 // ===========================================================================
920
921 // ---------------------------------------------------------------------------
922 // preprocessing
923 // ---------------------------------------------------------------------------
924
925 bool wxFrameMSW::MSWTranslateMessage(WXMSG* pMsg)
926 {
927 if ( wxWindow::MSWTranslateMessage(pMsg) )
928 return TRUE;
929
930 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
931 // try the menu bar accels
932 wxMenuBar *menuBar = GetMenuBar();
933 if ( !menuBar )
934 return FALSE;
935
936 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
937 return acceleratorTable.Translate(this, pMsg);
938 #else
939 return FALSE;
940 #endif // wxUSE_MENUS && wxUSE_ACCEL
941 }
942
943 // ---------------------------------------------------------------------------
944 // our private (non virtual) message handlers
945 // ---------------------------------------------------------------------------
946
947 bool wxFrameMSW::HandlePaint()
948 {
949 RECT rect;
950 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
951 {
952 #ifndef __WXMICROWIN__
953 if ( m_iconized )
954 {
955 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
956 : (HICON)m_defaultIcon;
957
958 // Hold a pointer to the dc so long as the OnPaint() message
959 // is being processed
960 PAINTSTRUCT ps;
961 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
962
963 // Erase background before painting or we get white background
964 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
965
966 if ( hIcon )
967 {
968 RECT rect;
969 ::GetClientRect(GetHwnd(), &rect);
970
971 // FIXME: why hardcoded?
972 static const int icon_width = 32;
973 static const int icon_height = 32;
974
975 int icon_x = (int)((rect.right - icon_width)/2);
976 int icon_y = (int)((rect.bottom - icon_height)/2);
977
978 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
979 }
980
981 ::EndPaint(GetHwnd(), &ps);
982
983 return TRUE;
984 }
985 else
986 #endif
987 {
988 return wxWindow::HandlePaint();
989 }
990 }
991 else
992 {
993 // nothing to paint - processed
994 return TRUE;
995 }
996 }
997
998 bool wxFrameMSW::HandleSize(int x, int y, WXUINT id)
999 {
1000 bool processed = FALSE;
1001 #ifndef __WXMICROWIN__
1002
1003 switch ( id )
1004 {
1005 case SIZENORMAL:
1006 // only do it it if we were iconized before, otherwise resizing the
1007 // parent frame has a curious side effect of bringing it under it's
1008 // children
1009 if ( !m_iconized )
1010 break;
1011
1012 // restore all child frames too
1013 IconizeChildFrames(FALSE);
1014
1015 (void)SendIconizeEvent(FALSE);
1016
1017 // fall through
1018
1019 case SIZEFULLSCREEN:
1020 m_iconized = FALSE;
1021 break;
1022
1023 case SIZEICONIC:
1024 // iconize all child frames too
1025 IconizeChildFrames(TRUE);
1026
1027 (void)SendIconizeEvent();
1028
1029 m_iconized = TRUE;
1030 break;
1031 }
1032 #endif
1033
1034 if ( !m_iconized )
1035 {
1036 #if wxUSE_STATUSBAR
1037 PositionStatusBar();
1038 #endif // wxUSE_STATUSBAR
1039
1040 #if wxUSE_TOOLBAR
1041 PositionToolBar();
1042 #endif // wxUSE_TOOLBAR
1043
1044 wxSizeEvent event(wxSize(x, y), m_windowId);
1045 event.SetEventObject( this );
1046 processed = GetEventHandler()->ProcessEvent(event);
1047 }
1048
1049 return processed;
1050 }
1051
1052 bool wxFrameMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
1053 {
1054 if ( control )
1055 {
1056 // In case it's e.g. a toolbar.
1057 wxWindow *win = wxFindWinFromHandle(control);
1058 if ( win )
1059 return win->MSWCommand(cmd, id);
1060 }
1061
1062 // handle here commands from menus and accelerators
1063 if ( cmd == 0 || cmd == 1 )
1064 {
1065 #if wxUSE_MENUS_NATIVE
1066 if ( wxCurrentPopupMenu )
1067 {
1068 wxMenu *popupMenu = wxCurrentPopupMenu;
1069 wxCurrentPopupMenu = NULL;
1070
1071 return popupMenu->MSWCommand(cmd, id);
1072 }
1073 #endif // wxUSE_MENUS_NATIVE
1074
1075 if ( ProcessCommand(id) )
1076 {
1077 return TRUE;
1078 }
1079 }
1080
1081 return FALSE;
1082 }
1083
1084 bool wxFrameMSW::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
1085 {
1086 int item;
1087 if ( flags == 0xFFFF && hMenu == 0 )
1088 {
1089 // menu was removed from screen
1090 item = -1;
1091 }
1092 #ifndef __WXMICROWIN__
1093 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
1094 {
1095 item = nItem;
1096 }
1097 #endif
1098 else
1099 {
1100 #if wxUSE_STATUSBAR
1101 // don't give hints for separators (doesn't make sense) nor for the
1102 // items opening popup menus (they don't have them anyhow) but do clear
1103 // the status line - otherwise, we would be left with the help message
1104 // for the previous item which doesn't apply any more
1105 wxStatusBar *statbar = GetStatusBar();
1106 if ( statbar )
1107 {
1108 statbar->SetStatusText(wxEmptyString);
1109 }
1110 #endif // wxUSE_STATUSBAR
1111
1112 return FALSE;
1113 }
1114
1115 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
1116 event.SetEventObject( this );
1117
1118 return GetEventHandler()->ProcessEvent(event);
1119 }
1120
1121 // ---------------------------------------------------------------------------
1122 // the window proc for wxFrameMSW
1123 // ---------------------------------------------------------------------------
1124
1125 long wxFrameMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
1126 {
1127 long rc = 0;
1128 bool processed = FALSE;
1129
1130 switch ( message )
1131 {
1132 case WM_CLOSE:
1133 // if we can't close, tell the system that we processed the
1134 // message - otherwise it would close us
1135 processed = !Close();
1136 break;
1137
1138 case WM_COMMAND:
1139 {
1140 WORD id, cmd;
1141 WXHWND hwnd;
1142 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
1143 &id, &hwnd, &cmd);
1144
1145 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
1146 }
1147 break;
1148
1149 #ifndef __WXMICROWIN__
1150 case WM_MENUSELECT:
1151 {
1152 WXWORD item, flags;
1153 WXHMENU hmenu;
1154 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
1155
1156 processed = HandleMenuSelect(item, flags, hmenu);
1157 }
1158 break;
1159 #endif
1160
1161 case WM_PAINT:
1162 processed = HandlePaint();
1163 break;
1164
1165 #ifndef __WXMICROWIN__
1166 case WM_QUERYDRAGICON:
1167 {
1168 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
1169 : (HICON)(m_defaultIcon);
1170 rc = (long)hIcon;
1171 processed = rc != 0;
1172 }
1173 break;
1174 #endif
1175
1176 case WM_SIZE:
1177 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
1178 break;
1179 }
1180
1181 if ( !processed )
1182 rc = wxWindow::MSWWindowProc(message, wParam, lParam);
1183
1184 return rc;
1185 }
1186