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