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