fixed problems with hanging inside IsDialogMessage or DefDlgProc by forcing all paren...
[wxWidgets.git] / src / msw / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for MSW
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 24.09.01
7 // RCS-ID: $Id$
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "toplevel.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/app.h"
33 #include "wx/toplevel.h"
34 #include "wx/string.h"
35 #include "wx/log.h"
36 #include "wx/intl.h"
37 #include "wx/frame.h"
38 #endif //WX_PRECOMP
39
40 #include "wx/msw/private.h"
41
42 #include "wx/popupwin.h"
43
44 #ifndef ICON_BIG
45 #define ICON_BIG 1
46 #endif
47
48 #ifndef ICON_SMALL
49 #define ICON_SMALL 0
50 #endif
51
52 // ----------------------------------------------------------------------------
53 // stubs for missing functions under MicroWindows
54 // ----------------------------------------------------------------------------
55
56 #ifdef __WXMICROWIN__
57
58 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
59 static inline bool IsZoomed(HWND WXUNUSED(hwnd)) { return FALSE; }
60
61 #endif // __WXMICROWIN__
62
63 // this is defined in dialog.cpp
64 LONG APIENTRY _EXPORT
65 wxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
66
67 // ----------------------------------------------------------------------------
68 // globals
69 // ----------------------------------------------------------------------------
70
71 // list of all frames and modeless dialogs
72 wxWindowList wxModelessWindows;
73
74 // the name of the default wxWindows class
75 extern const wxChar *wxCanvasClassName;
76
77 // the hidden parent for wxFRAME_NO_TASKBAR unowned frames
78 wxWindow *wxTopLevelWindowMSW::ms_hiddenParent = NULL;
79
80 // ============================================================================
81 // wxTopLevelWindowMSW implementation
82 // ============================================================================
83
84 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW, wxTopLevelWindowBase)
85 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate)
86 END_EVENT_TABLE()
87
88 // ----------------------------------------------------------------------------
89 // wxTopLevelWindowMSW creation
90 // ----------------------------------------------------------------------------
91
92 void wxTopLevelWindowMSW::Init()
93 {
94 m_iconized =
95 m_maximizeOnShow = FALSE;
96
97 // unlike (almost?) all other windows, frames are created hidden
98 m_isShown = FALSE;
99
100 // Data to save/restore when calling ShowFullScreen
101 m_fsStyle = 0;
102 m_fsOldWindowStyle = 0;
103 m_fsIsMaximized = FALSE;
104 m_fsIsShowing = FALSE;
105
106 m_winLastFocused = (wxWindow *)NULL;
107 }
108
109 WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const
110 {
111 // let the base class deal with the common styles but fix the ones which
112 // don't make sense for us (we also deal with the borders ourselves)
113 WXDWORD msflags = wxWindow::MSWGetStyle
114 (
115 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exflags
116 ) & ~WS_CHILD;
117
118 // first select the kind of window being created
119 //
120 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
121 // creates a window with both caption and border, hence we also test it
122 // below in some other cases
123 if ( style & wxFRAME_TOOL_WINDOW )
124 msflags |= WS_POPUP;
125 else
126 msflags |= WS_OVERLAPPED;
127
128 // border and caption styles
129 if ( style & wxRESIZE_BORDER )
130 msflags |= WS_THICKFRAME;
131 else if ( !(style & wxBORDER_NONE) )
132 msflags |= WS_BORDER;
133 else
134 msflags |= WS_POPUP;
135
136 if ( style & wxCAPTION )
137 msflags |= WS_CAPTION;
138 else
139 msflags |= WS_POPUP;
140
141 // next translate the individual flags
142 if ( style & wxMINIMIZE_BOX )
143 msflags |= WS_MINIMIZEBOX;
144 if ( style & wxMAXIMIZE_BOX )
145 msflags |= WS_MAXIMIZEBOX;
146 if ( style & wxSYSTEM_MENU )
147 msflags |= WS_SYSMENU;
148 if ( style & wxMINIMIZE )
149 msflags |= WS_MINIMIZE;
150 if ( style & wxMAXIMIZE )
151 msflags |= WS_MAXIMIZE;
152
153 // Keep this here because it saves recoding this function in wxTinyFrame
154 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
155 if ( style & wxTINY_CAPTION_VERT )
156 msflags |= IBS_VERTCAPTION;
157 if ( style & wxTINY_CAPTION_HORIZ )
158 msflags |= IBS_HORZCAPTION;
159 #else
160 if ( style & (wxTINY_CAPTION_VERT | wxTINY_CAPTION_HORIZ) )
161 msflags |= WS_CAPTION;
162 #endif
163
164 if ( exflags )
165 {
166 #if !defined(__WIN16__) && !defined(__SC__)
167 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) )
168 {
169 if ( style & wxFRAME_TOOL_WINDOW )
170 {
171 // create the palette-like window
172 *exflags |= WS_EX_TOOLWINDOW;
173 }
174
175 // We have to solve 2 different problems here:
176 //
177 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
178 // taskbar even if they don't have a parent
179 //
180 // 2. frames without this style should appear in the taskbar even
181 // if they're owned (Windows only puts non owned windows into
182 // the taskbar normally)
183 //
184 // The second one is solved here by using WS_EX_APPWINDOW flag, the
185 // first one is dealt with in our MSWGetParent() method
186 // implementation
187 if ( !(style & wxFRAME_NO_TASKBAR) && GetParent() )
188 {
189 // need to force the frame to appear in the taskbar
190 *exflags |= WS_EX_APPWINDOW;
191 }
192 //else: nothing to do [here]
193 }
194 #endif // !Win16
195
196 if ( style & wxSTAY_ON_TOP )
197 *exflags |= WS_EX_TOPMOST;
198
199 #ifdef __WIN32__
200 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP )
201 *exflags |= WS_EX_CONTEXTHELP;
202 #endif // __WIN32__
203 }
204
205 return msflags;
206 }
207
208 WXHWND wxTopLevelWindowMSW::MSWGetParent() const
209 {
210 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
211 // parent HWND or it would be always on top of its parent which is not what
212 // we usually want (in fact, we only want it for frames with the
213 // wxFRAME_FLOAT_ON_PARENT flag)
214 wxWindow *parent;
215 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) )
216 {
217 parent = GetParent();
218
219 // this flag doesn't make sense then and will be ignored
220 wxASSERT_MSG( parent,
221 _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
222 }
223 else // don't float on parent, must not be owned
224 {
225 parent = NULL;
226 }
227
228 // now deal with the 2nd taskbar-related problem (see comments above in
229 // MSWGetStyle())
230 if ( HasFlag(wxFRAME_NO_TASKBAR) && !parent )
231 {
232 if ( !ms_hiddenParent )
233 {
234 ms_hiddenParent = new wxTopLevelWindowMSW(NULL, -1, _T(""));
235
236 // we shouldn't leave it in wxTopLevelWindows or we wouldn't
237 // terminate the app when the last user-created frame is deleted --
238 // see ~wxTopLevelWindowMSW
239 wxTopLevelWindows.DeleteObject(ms_hiddenParent);
240 }
241
242 parent = ms_hiddenParent;
243 }
244
245 return parent ? parent->GetHWND() : NULL;
246 }
247
248 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate,
249 const wxString& title,
250 const wxPoint& pos,
251 const wxSize& size)
252 {
253 #ifdef __WXMICROWIN__
254 // no dialogs support under MicroWin yet
255 return CreateFrame(title, pos, size);
256 #else // !__WXMICROWIN__
257 wxWindow *parent = GetParent();
258
259 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
260 // app window as parent - this avoids creating modal dialogs without
261 // parent
262 if ( !parent && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
263 {
264 parent = wxTheApp->GetTopWindow();
265
266 if ( parent )
267 {
268 // don't use transient windows as parents, this is dangerous as it
269 // can lead to a crash if the parent is destroyed before the child
270 //
271 // also don't use the window which is currently hidden as then the
272 // dialog would be hidden as well
273 if ( (parent->GetExtraStyle() & wxWS_EX_TRANSIENT) ||
274 !parent->IsShown() )
275 {
276 parent = NULL;
277 }
278 }
279 }
280
281 m_hWnd = (WXHWND)::CreateDialogIndirect
282 (
283 wxGetInstance(),
284 (DLGTEMPLATE*)dlgTemplate,
285 parent ? GetHwndOf(parent) : NULL,
286 (DLGPROC)wxDlgProc
287 );
288
289 if ( !m_hWnd )
290 {
291 wxFAIL_MSG(_("Failed to create dialog. Incorrect DLGTEMPLATE?"));
292
293 wxLogSysError(_("Can't create dialog using memory template"));
294
295 return FALSE;
296 }
297
298 WXDWORD exflags;
299 (void)MSWGetCreateWindowFlags(&exflags);
300
301 if ( exflags )
302 {
303 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exflags);
304 ::SetWindowPos(GetHwnd(), NULL, 0, 0, 0, 0,
305 SWP_NOSIZE |
306 SWP_NOMOVE |
307 SWP_NOZORDER |
308 SWP_NOACTIVATE);
309 }
310
311 #if defined(__WIN95__)
312 // For some reason, the system menu is activated when we use the
313 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
314 if ( exflags & WS_EX_CONTEXTHELP )
315 {
316 wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame);
317 if ( winTop )
318 {
319 wxIcon icon = winTop->GetIcon();
320 if ( icon.Ok() )
321 {
322 ::SendMessage(GetHwnd(), WM_SETICON,
323 (WPARAM)TRUE,
324 (LPARAM)GetHiconOf(icon));
325 }
326 }
327 }
328 #endif // __WIN95__
329
330 // move the dialog to its initial position without forcing repainting
331 int x, y, w, h;
332 if ( !MSWGetCreateWindowCoords(pos, size, x, y, w, h) )
333 {
334 x =
335 w = (int)CW_USEDEFAULT;
336 }
337
338 // we can't use CW_USEDEFAULT here as we're not calling CreateWindow()
339 // and passing CW_USEDEFAULT to MoveWindow() results in resizing the
340 // window to (0, 0) size which breaks quite a lot of things, e.g. the
341 // sizer calculation in wxSizer::Fit()
342 if ( w == (int)CW_USEDEFAULT )
343 {
344 // the exact number doesn't matter, the dialog will be resized
345 // again soon anyhow but it should be big enough to allow
346 // calculation relying on "totalSize - clientSize > 0" work, i.e.
347 // at least greater than the title bar height
348 w =
349 h = 100;
350 }
351
352 if ( x == (int)CW_USEDEFAULT )
353 {
354 // centre it on the screen - what else can we do?
355 wxSize sizeDpy = wxGetDisplaySize();
356
357 x = (sizeDpy.x - w) / 2;
358 y = (sizeDpy.y - h) / 2;
359 }
360
361 if ( !::MoveWindow(GetHwnd(), x, y, w, h, FALSE) )
362 {
363 wxLogLastError(wxT("MoveWindow"));
364 }
365
366 if ( !title.empty() )
367 {
368 ::SetWindowText(GetHwnd(), title);
369 }
370
371 SubclassWin(m_hWnd);
372
373 return TRUE;
374 #endif // __WXMICROWIN__/!__WXMICROWIN__
375 }
376
377 bool wxTopLevelWindowMSW::CreateFrame(const wxString& title,
378 const wxPoint& pos,
379 const wxSize& size)
380 {
381 WXDWORD exflags;
382 WXDWORD flags = MSWGetCreateWindowFlags(&exflags);
383
384 return MSWCreate(wxCanvasClassName, title, pos, size, flags, exflags);
385 }
386
387 bool wxTopLevelWindowMSW::Create(wxWindow *parent,
388 wxWindowID id,
389 const wxString& title,
390 const wxPoint& pos,
391 const wxSize& size,
392 long style,
393 const wxString& name)
394 {
395 // init our fields
396 Init();
397
398 m_windowStyle = style;
399
400 SetName(name);
401
402 m_windowId = id == -1 ? NewControlId() : id;
403
404 wxTopLevelWindows.Append(this);
405
406 if ( parent )
407 parent->AddChild(this);
408
409 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
410 {
411 // we have different dialog templates to allows creation of dialogs
412 // with & without captions under MSWindows, resizeable or not (but a
413 // resizeable dialog always has caption - otherwise it would look too
414 // strange)
415
416 // we need 3 additional WORDs for dialog menu, class and title (as we
417 // don't use DS_SETFONT we don't need the fourth WORD for the font)
418 static const int dlgsize = sizeof(DLGTEMPLATE) + (sizeof(WORD) * 3);
419 DLGTEMPLATE *dlgTemplate = (DLGTEMPLATE *)malloc(dlgsize);
420 memset(dlgTemplate, 0, dlgsize);
421
422 // these values are arbitrary, they won't be used normally anyhow
423 dlgTemplate->x = 34;
424 dlgTemplate->y = 22;
425 dlgTemplate->cx = 144;
426 dlgTemplate->cy = 75;
427
428 // reuse the code in MSWGetStyle() but correct the results slightly for
429 // the dialog
430 dlgTemplate->style = MSWGetStyle(style, NULL);
431
432 // all dialogs are popups
433 dlgTemplate->style |= WS_POPUP;
434
435 // force 3D-look if necessary, it looks impossibly ugly otherwise
436 if ( style & (wxRESIZE_BORDER | wxCAPTION) )
437 dlgTemplate->style |= DS_MODALFRAME;
438
439 bool ret = CreateDialog(dlgTemplate, title, pos, size);
440 free(dlgTemplate);
441
442 return ret;
443 }
444 else // !dialog
445 {
446 return CreateFrame(title, pos, size);
447 }
448 }
449
450 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
451 {
452 if ( this == ms_hiddenParent )
453 {
454 // stop [infinite] recursion which would otherwise happen when we do
455 // "delete ms_hiddenParent" below
456 return;
457 }
458
459 wxTopLevelWindows.DeleteObject(this);
460
461 if ( wxModelessWindows.Find(this) )
462 wxModelessWindows.DeleteObject(this);
463
464 // after destroying an owned window, Windows activates the next top level
465 // window in Z order but it may be different from our owner (to reproduce
466 // this simply Alt-TAB to another application and back before closing the
467 // owned frame) whereas we always want to yield activation to our parent
468 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) )
469 {
470 wxWindow *parent = GetParent();
471 if ( parent )
472 {
473 ::BringWindowToTop(GetHwndOf(parent));
474 }
475 }
476
477 // If this is the last top-level window, exit.
478 if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
479 {
480 if ( ms_hiddenParent )
481 {
482 delete ms_hiddenParent;
483 ms_hiddenParent = NULL;
484 }
485
486 wxTheApp->SetTopWindow(NULL);
487
488 if ( wxTheApp->GetExitOnFrameDelete() )
489 {
490 ::PostQuitMessage(0);
491 }
492 }
493 }
494
495 // ----------------------------------------------------------------------------
496 // wxTopLevelWindowMSW showing
497 // ----------------------------------------------------------------------------
498
499 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd)
500 {
501 ::ShowWindow(GetHwnd(), nShowCmd);
502
503 m_iconized = nShowCmd == SW_MINIMIZE;
504 }
505
506 bool wxTopLevelWindowMSW::Show(bool show)
507 {
508 // don't use wxWindow version as we want to call DoShowWindow() ourselves
509 if ( !wxWindowBase::Show(show) )
510 return FALSE;
511
512 int nShowCmd;
513 if ( show )
514 {
515 if ( m_maximizeOnShow )
516 {
517 // show and maximize
518 nShowCmd = SW_MAXIMIZE;
519
520 m_maximizeOnShow = FALSE;
521 }
522 else // just show
523 {
524 nShowCmd = SW_SHOW;
525 }
526 }
527 else // hide
528 {
529 nShowCmd = SW_HIDE;
530 }
531
532 DoShowWindow(nShowCmd);
533
534 if ( show )
535 {
536 ::BringWindowToTop(GetHwnd());
537
538 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
539 event.SetEventObject( this );
540 GetEventHandler()->ProcessEvent(event);
541 }
542 else // hide
543 {
544 // Try to highlight the correct window (the parent)
545 if ( GetParent() )
546 {
547 HWND hWndParent = GetHwndOf(GetParent());
548 if (hWndParent)
549 ::BringWindowToTop(hWndParent);
550 }
551 }
552
553 return TRUE;
554 }
555
556 // ----------------------------------------------------------------------------
557 // wxTopLevelWindowMSW maximize/minimize
558 // ----------------------------------------------------------------------------
559
560 void wxTopLevelWindowMSW::Maximize(bool maximize)
561 {
562 if ( IsShown() )
563 {
564 // just maximize it directly
565 DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE);
566 }
567 else // hidden
568 {
569 // we can't maximize the hidden frame because it shows it as well, so
570 // just remember that we should do it later in this case
571 m_maximizeOnShow = TRUE;
572 }
573 }
574
575 bool wxTopLevelWindowMSW::IsMaximized() const
576 {
577 return ::IsZoomed(GetHwnd()) != 0;
578 }
579
580 void wxTopLevelWindowMSW::Iconize(bool iconize)
581 {
582 DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE);
583 }
584
585 bool wxTopLevelWindowMSW::IsIconized() const
586 {
587 // also update the current state
588 ((wxTopLevelWindowMSW *)this)->m_iconized = ::IsIconic(GetHwnd()) != 0;
589
590 return m_iconized;
591 }
592
593 void wxTopLevelWindowMSW::Restore()
594 {
595 DoShowWindow(SW_RESTORE);
596 }
597
598 // ----------------------------------------------------------------------------
599 // wxTopLevelWindowMSW fullscreen
600 // ----------------------------------------------------------------------------
601
602 bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style)
603 {
604 if (show)
605 {
606 if (IsFullScreen())
607 return FALSE;
608
609 m_fsIsShowing = TRUE;
610 m_fsStyle = style;
611
612 // zap the frame borders
613
614 // save the 'normal' window style
615 m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE);
616
617 // save the old position, width & height, maximize state
618 m_fsOldSize = GetRect();
619 m_fsIsMaximized = IsMaximized();
620
621 // decide which window style flags to turn off
622 LONG newStyle = m_fsOldWindowStyle;
623 LONG offFlags = 0;
624
625 if (style & wxFULLSCREEN_NOBORDER)
626 offFlags |= WS_BORDER | WS_THICKFRAME;
627 if (style & wxFULLSCREEN_NOCAPTION)
628 offFlags |= (WS_CAPTION | WS_SYSMENU);
629
630 newStyle &= (~offFlags);
631
632 // change our window style to be compatible with full-screen mode
633 ::SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle);
634
635 // resize to the size of the desktop
636 int width, height;
637
638 RECT rect = wxGetWindowRect(::GetDesktopWindow());
639 width = rect.right - rect.left;
640 height = rect.bottom - rect.top;
641
642 SetSize(width, height);
643
644 // now flush the window style cache and actually go full-screen
645 SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
646
647 wxSizeEvent event(wxSize(width, height), GetId());
648 GetEventHandler()->ProcessEvent(event);
649
650 return TRUE;
651 }
652 else
653 {
654 if (!IsFullScreen())
655 return FALSE;
656
657 m_fsIsShowing = FALSE;
658
659 Maximize(m_fsIsMaximized);
660 SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle);
661 SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
662 m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
663
664 return TRUE;
665 }
666 }
667
668 // ----------------------------------------------------------------------------
669 // wxTopLevelWindowMSW misc
670 // ----------------------------------------------------------------------------
671
672 void wxTopLevelWindowMSW::SetIcon(const wxIcon& icon)
673 {
674 SetIcons( wxIconBundle( icon ) );
675 }
676
677 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons)
678 {
679 wxTopLevelWindowBase::SetIcons(icons);
680
681 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
682 const wxIcon& sml = icons.GetIcon( wxSize( 16, 16 ) );
683 if( sml.Ok() && sml.GetWidth() == 16 && sml.GetHeight() == 16 )
684 {
685 ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_SMALL,
686 (LPARAM)GetHiconOf(sml) );
687 }
688
689 const wxIcon& big = icons.GetIcon( wxSize( 32, 32 ) );
690 if( big.Ok() && big.GetWidth() == 32 && big.GetHeight() == 32 )
691 {
692 ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_BIG,
693 (LPARAM)GetHiconOf(big) );
694 }
695 #endif // __WIN95__
696 }
697
698 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable)
699 {
700 #ifndef __WXMICROWIN__
701 // get system (a.k.a. window) menu
702 HMENU hmenu = ::GetSystemMenu(GetHwnd(), FALSE /* get it */);
703 if ( !hmenu )
704 {
705 wxLogLastError(_T("GetSystemMenu"));
706
707 return FALSE;
708 }
709
710 // enabling/disabling the close item from it also automatically
711 // disables/enables the close title bar button
712 if ( ::EnableMenuItem(hmenu, SC_CLOSE,
713 MF_BYCOMMAND |
714 (enable ? MF_ENABLED : MF_GRAYED)) == -1 )
715 {
716 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
717
718 return FALSE;
719 }
720
721 // update appearance immediately
722 if ( !::DrawMenuBar(GetHwnd()) )
723 {
724 wxLogLastError(_T("DrawMenuBar"));
725 }
726 #endif // !__WXMICROWIN__
727
728 return TRUE;
729 }
730
731 // ----------------------------------------------------------------------------
732 // wxTopLevelWindow event handling
733 // ----------------------------------------------------------------------------
734
735 // Default activation behaviour - set the focus for the first child
736 // subwindow found.
737 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
738 {
739 if ( event.GetActive() )
740 {
741 // restore focus to the child which was last focused
742 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), m_hWnd);
743
744 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
745 : NULL;
746 if ( !parent )
747 {
748 parent = this;
749 }
750
751 wxSetFocusToChild(parent, &m_winLastFocused);
752 }
753 else // deactivating
754 {
755 // remember the last focused child if it is our child
756 m_winLastFocused = FindFocus();
757
758 // so we NULL it out if it's a child from some other frame
759 wxWindow *win = m_winLastFocused;
760 while ( win )
761 {
762 if ( win->IsTopLevel() )
763 {
764 if ( win != this )
765 {
766 m_winLastFocused = NULL;
767 }
768
769 break;
770 }
771
772 win = win->GetParent();
773 }
774
775 wxLogTrace(_T("focus"),
776 _T("wxTLW %08x deactivated, last focused: %08x."),
777 m_hWnd,
778 m_winLastFocused ? GetHwndOf(m_winLastFocused)
779 : NULL);
780
781 event.Skip();
782 }
783 }
784