1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for MSW
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "toplevel.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/toplevel.h"
34 #include "wx/string.h"
38 #include "wx/containr.h" // wxSetFocusToChild()
41 #include "wx/module.h"
43 #include "wx/msw/private.h"
44 #if defined(__WXWINCE__)
50 #include "wx/msw/wince/missing.h"
53 #include "wx/msw/missing.h"
54 #include "wx/msw/winundef.h"
56 // This can't be undefed in winundef.h or
57 // there are further errors
58 #if defined(__WXWINCE__) && defined(CreateDialog)
62 #include "wx/display.h"
72 // ----------------------------------------------------------------------------
73 // stubs for missing functions under MicroWindows
74 // ----------------------------------------------------------------------------
78 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
79 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
81 #endif // __WXMICROWIN__
83 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
84 // is not included by wxUniv build which does need wxDlgProc
86 wxDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
);
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 // list of all frames and modeless dialogs
93 wxWindowList wxModelessWindows
;
95 // the name of the default wxWindows class
96 extern const wxChar
*wxCanvasClassName
;
98 // ----------------------------------------------------------------------------
99 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
100 // module to ensure that the window is always deleted)
101 // ----------------------------------------------------------------------------
103 class wxTLWHiddenParentModule
: public wxModule
106 // module init/finalize
107 virtual bool OnInit();
108 virtual void OnExit();
110 // get the hidden window (creates on demand)
111 static HWND
GetHWND();
114 // the HWND of the hidden parent
117 // the class used to create it
118 static const wxChar
*ms_className
;
120 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule
)
123 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule
, wxModule
)
125 // ============================================================================
126 // wxTopLevelWindowMSW implementation
127 // ============================================================================
129 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW
, wxTopLevelWindowBase
)
130 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate
)
133 // ----------------------------------------------------------------------------
134 // wxTopLevelWindowMSW creation
135 // ----------------------------------------------------------------------------
137 void wxTopLevelWindowMSW::Init()
140 m_maximizeOnShow
= FALSE
;
142 // Data to save/restore when calling ShowFullScreen
144 m_fsOldWindowStyle
= 0;
145 m_fsIsMaximized
= FALSE
;
146 m_fsIsShowing
= FALSE
;
148 m_winLastFocused
= (wxWindow
*)NULL
;
151 WXDWORD
wxTopLevelWindowMSW::MSWGetStyle(long style
, WXDWORD
*exflags
) const
153 // let the base class deal with the common styles but fix the ones which
154 // don't make sense for us (we also deal with the borders ourselves)
155 WXDWORD msflags
= wxWindow::MSWGetStyle
157 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
158 ) & ~WS_CHILD
& ~WS_VISIBLE
;
160 // first select the kind of window being created
162 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
163 // creates a window with both caption and border, hence we also test it
164 // below in some other cases
165 if ( style
& wxFRAME_TOOL_WINDOW
)
170 if (msflags
& WS_BORDER
)
172 msflags
|= WS_OVERLAPPED
;
175 // border and caption styles
176 if ( style
& wxRESIZE_BORDER
)
179 msflags
|= WS_THICKFRAME
;
182 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
183 *exflags
|= WS_EX_DLGMODALFRAME
;
184 else if ( !(style
& wxBORDER_NONE
) )
185 msflags
|= WS_BORDER
;
191 if ( style
& wxCAPTION
)
192 msflags
|= WS_CAPTION
;
198 // next translate the individual flags
199 if ( style
& wxMINIMIZE_BOX
)
200 msflags
|= WS_MINIMIZEBOX
;
201 if ( style
& wxMAXIMIZE_BOX
)
202 msflags
|= WS_MAXIMIZEBOX
;
203 if ( style
& wxSYSTEM_MENU
)
204 msflags
|= WS_SYSMENU
;
206 if ( style
& wxMINIMIZE
)
207 msflags
|= WS_MINIMIZE
;
208 if ( style
& wxMAXIMIZE
)
209 msflags
|= WS_MAXIMIZE
;
212 // Keep this here because it saves recoding this function in wxTinyFrame
213 #if wxUSE_ITSY_BITSY && !defined(__WIN32__)
214 if ( style
& wxTINY_CAPTION_VERT
)
215 msflags
|= IBS_VERTCAPTION
;
216 if ( style
& wxTINY_CAPTION_HORIZ
)
217 msflags
|= IBS_HORZCAPTION
;
219 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
220 msflags
|= WS_CAPTION
;
225 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
227 if ( style
& wxFRAME_TOOL_WINDOW
)
229 // create the palette-like window
230 *exflags
|= WS_EX_TOOLWINDOW
;
232 // tool windows shouldn't appear on the taskbar (as documented)
233 style
|= wxFRAME_NO_TASKBAR
;
236 // We have to solve 2 different problems here:
238 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
239 // taskbar even if they don't have a parent
241 // 2. frames without this style should appear in the taskbar even
242 // if they're owned (Windows only puts non owned windows into
243 // the taskbar normally)
245 // The second one is solved here by using WS_EX_APPWINDOW flag, the
246 // first one is dealt with in our MSWGetParent() method
249 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
251 // need to force the frame to appear in the taskbar
252 *exflags
|= WS_EX_APPWINDOW
;
255 //else: nothing to do [here]
258 if ( style
& wxSTAY_ON_TOP
)
259 *exflags
|= WS_EX_TOPMOST
;
262 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
263 *exflags
|= WS_EX_CONTEXTHELP
;
270 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
272 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
273 // parent HWND or it would be always on top of its parent which is not what
274 // we usually want (in fact, we only want it for frames with the
275 // wxFRAME_FLOAT_ON_PARENT flag)
276 HWND hwndParent
= NULL
;
277 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
279 const wxWindow
*parent
= GetParent();
283 // this flag doesn't make sense then and will be ignored
284 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
288 hwndParent
= GetHwndOf(parent
);
291 //else: don't float on parent, must not be owned
293 // now deal with the 2nd taskbar-related problem (see comments above in
295 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
298 hwndParent
= wxTLWHiddenParentModule::GetHWND();
301 return (WXHWND
)hwndParent
;
304 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
305 const wxString
& title
,
309 #ifdef __WXMICROWIN__
310 // no dialogs support under MicroWin yet
311 return CreateFrame(title
, pos
, size
);
312 #else // !__WXMICROWIN__
313 wxWindow
*parent
= GetParent();
315 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
316 // app window as parent - this avoids creating modal dialogs without
318 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
320 parent
= wxTheApp
->GetTopWindow();
324 // don't use transient windows as parents, this is dangerous as it
325 // can lead to a crash if the parent is destroyed before the child
327 // also don't use the window which is currently hidden as then the
328 // dialog would be hidden as well
329 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
337 m_hWnd
= (WXHWND
)::CreateDialogIndirect
340 (DLGTEMPLATE
*)dlgTemplate
,
341 parent
? GetHwndOf(parent
) : NULL
,
347 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
349 wxLogSysError(wxT("Can't create dialog using memory template"));
355 (void)MSWGetCreateWindowFlags(&exflags
);
359 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
360 ::SetWindowPos(GetHwnd(),
361 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
365 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
369 #if defined(__WIN95__)
370 // For some reason, the system menu is activated when we use the
371 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
372 if ( exflags
& WS_EX_CONTEXTHELP
)
374 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
377 wxIcon icon
= winTop
->GetIcon();
380 ::SendMessage(GetHwnd(), WM_SETICON
,
382 (LPARAM
)GetHiconOf(icon
));
388 // move the dialog to its initial position without forcing repainting
390 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
392 if ( x
== (int)CW_USEDEFAULT
)
394 // centre it on the screen - what else can we do?
395 wxSize sizeDpy
= wxGetDisplaySize();
397 x
= (sizeDpy
.x
- w
) / 2;
398 y
= (sizeDpy
.y
- h
) / 2;
401 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
403 wxLogLastError(wxT("MoveWindow"));
406 if ( !title
.empty() )
408 ::SetWindowText(GetHwnd(), title
);
414 #endif // __WXMICROWIN__/!__WXMICROWIN__
417 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
422 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
424 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
427 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
429 const wxString
& title
,
433 const wxString
& name
)
435 bool ret
wxDUMMY_INITIALIZE(false);
440 w
= WidthDefault(size
.x
);
441 h
= HeightDefault(size
.y
);
443 m_windowStyle
= style
;
447 m_windowId
= id
== -1 ? NewControlId() : id
;
449 wxTopLevelWindows
.Append(this);
452 parent
->AddChild(this);
454 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
456 // we have different dialog templates to allows creation of dialogs
457 // with & without captions under MSWindows, resizeable or not (but a
458 // resizeable dialog always has caption - otherwise it would look too
461 // we need 3 additional WORDs for dialog menu, class and title (as we
462 // don't use DS_SETFONT we don't need the fourth WORD for the font)
463 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
464 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
465 memset(dlgTemplate
, 0, dlgsize
);
467 // these values are arbitrary, they won't be used normally anyhow
470 dlgTemplate
->cx
= 144;
471 dlgTemplate
->cy
= 75;
473 // reuse the code in MSWGetStyle() but correct the results slightly for
475 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
477 // all dialogs are popups
478 dlgTemplate
->style
|= WS_POPUP
;
480 // force 3D-look if necessary, it looks impossibly ugly otherwise
481 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
482 dlgTemplate
->style
|= DS_MODALFRAME
;
484 ret
= CreateDialog(dlgTemplate
, title
, pos
, wxSize(w
,h
));
489 ret
= CreateFrame(title
, pos
, wxSize(w
,h
));
492 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
494 EnableCloseButton(false);
497 // for some reason we need to manually send ourselves this message as
498 // otherwise the mnemonics are always shown -- even if they're configured
499 // to be hidden until "Alt" is pressed in the control panel
501 // this could indicate a bug somewhere else but for now this is the only
509 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
517 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
519 if ( wxModelessWindows
.Find(this) )
520 wxModelessWindows
.DeleteObject(this);
522 // after destroying an owned window, Windows activates the next top level
523 // window in Z order but it may be different from our owner (to reproduce
524 // this simply Alt-TAB to another application and back before closing the
525 // owned frame) whereas we always want to yield activation to our parent
526 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
528 wxWindow
*parent
= GetParent();
531 ::BringWindowToTop(GetHwndOf(parent
));
536 // ----------------------------------------------------------------------------
537 // wxTopLevelWindowMSW showing
538 // ----------------------------------------------------------------------------
540 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
542 ::ShowWindow(GetHwnd(), nShowCmd
);
544 m_iconized
= nShowCmd
== SW_MINIMIZE
;
547 bool wxTopLevelWindowMSW::Show(bool show
)
549 // don't use wxWindow version as we want to call DoShowWindow() ourselves
550 if ( !wxWindowBase::Show(show
) )
556 if ( m_maximizeOnShow
)
559 nShowCmd
= SW_MAXIMIZE
;
561 m_maximizeOnShow
= FALSE
;
565 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
566 nShowCmd
= SW_SHOWNA
;
576 DoShowWindow(nShowCmd
);
580 ::BringWindowToTop(GetHwnd());
582 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
583 event
.SetEventObject( this );
584 GetEventHandler()->ProcessEvent(event
);
588 // Try to highlight the correct window (the parent)
591 HWND hWndParent
= GetHwndOf(GetParent());
593 ::BringWindowToTop(hWndParent
);
600 // ----------------------------------------------------------------------------
601 // wxTopLevelWindowMSW maximize/minimize
602 // ----------------------------------------------------------------------------
604 void wxTopLevelWindowMSW::Maximize(bool maximize
)
608 // just maximize it directly
609 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
613 // we can't maximize the hidden frame because it shows it as well, so
614 // just remember that we should do it later in this case
615 m_maximizeOnShow
= maximize
;
619 bool wxTopLevelWindowMSW::IsMaximized() const
624 return ::IsZoomed(GetHwnd()) != 0;
628 void wxTopLevelWindowMSW::Iconize(bool iconize
)
630 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
633 bool wxTopLevelWindowMSW::IsIconized() const
638 // also update the current state
639 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
645 void wxTopLevelWindowMSW::Restore()
647 DoShowWindow(SW_RESTORE
);
650 // ----------------------------------------------------------------------------
651 // wxTopLevelWindowMSW fullscreen
652 // ----------------------------------------------------------------------------
654 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
656 if ( show
== IsFullScreen() )
662 m_fsIsShowing
= show
;
668 // zap the frame borders
670 // save the 'normal' window style
671 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
673 // save the old position, width & height, maximize state
674 m_fsOldSize
= GetRect();
675 m_fsIsMaximized
= IsMaximized();
677 // decide which window style flags to turn off
678 LONG newStyle
= m_fsOldWindowStyle
;
681 if (style
& wxFULLSCREEN_NOBORDER
)
683 offFlags
|= WS_BORDER
;
685 offFlags
|= WS_THICKFRAME
;
688 if (style
& wxFULLSCREEN_NOCAPTION
)
689 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
691 newStyle
&= ~offFlags
;
693 // change our window style to be compatible with full-screen mode
694 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
698 // resize to the size of the display containing us
699 int dpy
= wxDisplay::GetFromWindow(this);
700 if ( dpy
!= wxNOT_FOUND
)
702 rect
= wxDisplay(dpy
).GetGeometry();
704 else // fall back to the main desktop
705 #else // wxUSE_DISPLAY
707 // resize to the size of the desktop
708 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
710 // FIXME: size of the bottom menu (toolbar)
711 // should be taken in account
712 rect
.height
+= rect
.y
;
716 #endif // wxUSE_DISPLAY
720 // now flush the window style cache and actually go full-screen
721 long flags
= SWP_FRAMECHANGED
;
723 // showing the frame full screen should also show it if it's still
727 // don't call wxWindow version to avoid flicker from calling
728 // ::ShowWindow() -- we're going to show the window at the correct
729 // location directly below -- but do call the wxWindowBase version
730 // to sync the internal m_isShown flag
731 wxWindowBase::Show();
733 flags
|= SWP_SHOWWINDOW
;
736 SetWindowPos(GetHwnd(), HWND_TOP
,
737 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
740 #if defined(__WXWINCE__) && _WIN32_WCE < 400
741 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
744 // finally send an event allowing the window to relayout itself &c
745 wxSizeEvent
event(rect
.GetSize(), GetId());
746 GetEventHandler()->ProcessEvent(event
);
748 else // stop showing full screen
750 #if defined(__WXWINCE__) && _WIN32_WCE < 400
751 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
753 Maximize(m_fsIsMaximized
);
754 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
755 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
756 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
762 // ----------------------------------------------------------------------------
763 // wxTopLevelWindowMSW misc
764 // ----------------------------------------------------------------------------
766 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
768 SetIcons( wxIconBundle( icon
) );
771 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
773 wxTopLevelWindowBase::SetIcons(icons
);
775 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
776 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
777 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
779 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
780 (LPARAM
)GetHiconOf(sml
) );
783 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
784 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
786 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
787 (LPARAM
)GetHiconOf(big
) );
792 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
794 #if !defined(__WXMICROWIN__)
795 // get system (a.k.a. window) menu
796 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
799 // no system menu at all -- ok if we want to remove the close button
800 // anyhow, but bad if we want to show it
804 // enabling/disabling the close item from it also automatically
805 // disables/enables the close title bar button
806 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
808 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
810 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
815 // update appearance immediately
816 if ( !::DrawMenuBar(GetHwnd()) )
818 wxLogLastError(_T("DrawMenuBar"));
820 #endif // !__WXMICROWIN__
825 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
830 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
831 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
833 // The empty region signifies that the shape should be removed from the
835 if ( region
.IsEmpty() )
837 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
839 wxLogLastError(_T("SetWindowRgn"));
845 // Windows takes ownership of the region, so
846 // we'll have to make a copy of the region to give to it.
847 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
848 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
849 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
850 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
851 delete[] (char*) rgnData
;
853 // SetWindowRgn expects the region to be in coordinants
854 // relative to the window, not the client area. Figure
855 // out the offset, if any.
857 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
858 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
859 ::GetClientRect(GetHwnd(), &rect
);
860 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
861 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
863 // Now call the shape API with the new region.
864 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
866 wxLogLastError(_T("SetWindowRgn"));
873 // ----------------------------------------------------------------------------
874 // wxTopLevelWindow event handling
875 // ----------------------------------------------------------------------------
877 // Default activation behaviour - set the focus for the first child
879 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
881 if ( event
.GetActive() )
883 // restore focus to the child which was last focused unless we already
885 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
887 wxWindow
*winFocus
= FindFocus();
888 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
890 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
897 wxSetFocusToChild(parent
, &m_winLastFocused
);
902 // remember the last focused child if it is our child
903 m_winLastFocused
= FindFocus();
905 if ( m_winLastFocused
)
907 // let it know that it doesn't have focus any more
908 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
910 // and don't remember it if it's a child from some other frame
911 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
913 m_winLastFocused
= NULL
;
917 wxLogTrace(_T("focus"),
918 _T("wxTLW %08x deactivated, last focused: %08x."),
920 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
927 // the DialogProc for all wxWindows dialogs
928 LONG APIENTRY _EXPORT
929 wxDlgProc(HWND
WXUNUSED(hDlg
),
931 WPARAM
WXUNUSED(wParam
),
932 LPARAM
WXUNUSED(lParam
))
937 // for this message, returning TRUE tells system to set focus to
938 // the first control in the dialog box, but as we set the focus
939 // ourselves, we return FALSE from here as well, so fall through
942 // for all the other ones, FALSE means that we didn't process the
948 // ============================================================================
949 // wxTLWHiddenParentModule implementation
950 // ============================================================================
952 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
954 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
956 bool wxTLWHiddenParentModule::OnInit()
964 void wxTLWHiddenParentModule::OnExit()
968 if ( !::DestroyWindow(ms_hwnd
) )
970 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
978 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
980 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
988 HWND
wxTLWHiddenParentModule::GetHWND()
994 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
997 wxZeroMemory(wndclass
);
999 wndclass
.lpfnWndProc
= DefWindowProc
;
1000 wndclass
.hInstance
= wxGetInstance();
1001 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1003 if ( !::RegisterClass(&wndclass
) )
1005 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1009 ms_className
= HIDDEN_PARENT_CLASS
;
1013 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1014 (HMENU
)NULL
, wxGetInstance(), NULL
);
1017 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));