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/dialog.h"
35 #include "wx/string.h"
39 #include "wx/containr.h" // wxSetFocusToChild()
42 #include "wx/module.h"
44 #include "wx/msw/private.h"
45 #if defined(__WXWINCE__)
51 #include "wx/msw/wince/missing.h"
54 #include "wx/msw/missing.h"
55 #include "wx/msw/winundef.h"
57 #include "wx/display.h"
67 // ----------------------------------------------------------------------------
68 // stubs for missing functions under MicroWindows
69 // ----------------------------------------------------------------------------
73 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
74 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
76 #endif // __WXMICROWIN__
78 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
79 // is not included by wxUniv build which does need wxDlgProc
81 wxDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
);
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // list of all frames and modeless dialogs
88 wxWindowList wxModelessWindows
;
90 // the name of the default wxWindows class
92 extern wxChar
*wxCanvasClassName
;
94 extern const wxChar
*wxCanvasClassName
;
97 // ----------------------------------------------------------------------------
98 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
99 // module to ensure that the window is always deleted)
100 // ----------------------------------------------------------------------------
102 class wxTLWHiddenParentModule
: public wxModule
105 // module init/finalize
106 virtual bool OnInit();
107 virtual void OnExit();
109 // get the hidden window (creates on demand)
110 static HWND
GetHWND();
113 // the HWND of the hidden parent
116 // the class used to create it
117 static const wxChar
*ms_className
;
119 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule
)
122 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule
, wxModule
)
124 // ============================================================================
125 // wxTopLevelWindowMSW implementation
126 // ============================================================================
128 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW
, wxTopLevelWindowBase
)
129 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate
)
132 // ----------------------------------------------------------------------------
133 // wxTopLevelWindowMSW creation
134 // ----------------------------------------------------------------------------
136 void wxTopLevelWindowMSW::Init()
139 m_maximizeOnShow
= FALSE
;
141 // Data to save/restore when calling ShowFullScreen
143 m_fsOldWindowStyle
= 0;
144 m_fsIsMaximized
= FALSE
;
145 m_fsIsShowing
= FALSE
;
147 m_winLastFocused
= (wxWindow
*)NULL
;
150 WXDWORD
wxTopLevelWindowMSW::MSWGetStyle(long style
, WXDWORD
*exflags
) const
152 // let the base class deal with the common styles but fix the ones which
153 // don't make sense for us (we also deal with the borders ourselves)
154 WXDWORD msflags
= wxWindow::MSWGetStyle
156 (style
& ~wxBORDER_MASK
) | wxBORDER_NONE
, exflags
157 ) & ~WS_CHILD
& ~WS_VISIBLE
;
159 #if defined(__WXWINCE__) && _WIN32_WCE < 400
160 msflags
|= WS_VISIBLE
;
163 // first select the kind of window being created
165 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
166 // creates a window with both caption and border, hence we also test it
167 // below in some other cases
168 if ( style
& wxFRAME_TOOL_WINDOW
)
172 //else: WS_OVERLAPPED is 0 anyhow, so it is on by default
174 // border and caption styles
175 if ( style
& wxRESIZE_BORDER
)
176 msflags
|= WS_THICKFRAME
;
177 else if ( exflags
&& ((style
& wxBORDER_DOUBLE
) || (style
& wxBORDER_RAISED
)) )
178 *exflags
|= WS_EX_DLGMODALFRAME
;
179 else if ( !(style
& wxBORDER_NONE
) )
180 msflags
|= WS_BORDER
;
184 // normally we consider that all windows without caption must be popups,
185 // but CE is an exception: there windows normally do not have the caption
186 // but shouldn't be made popups as popups can't have menus and don't look
187 // like normal windows anyhow
188 if ( style
& wxCAPTION
)
189 msflags
|= WS_CAPTION
;
193 #endif // !__WXWINCE__
195 // next translate the individual flags
196 if ( style
& wxMINIMIZE_BOX
)
197 msflags
|= WS_MINIMIZEBOX
;
198 if ( style
& wxMAXIMIZE_BOX
)
199 msflags
|= WS_MAXIMIZEBOX
;
200 if ( style
& wxSYSTEM_MENU
)
201 msflags
|= WS_SYSMENU
;
203 // NB: under CE these 2 styles are not supported currently, we should
204 // call Minimize()/Maximize() "manually" if we want to support them
205 if ( style
& wxMINIMIZE
)
206 msflags
|= WS_MINIMIZE
;
207 if ( style
& wxMAXIMIZE
)
208 msflags
|= WS_MAXIMIZE
;
210 // Keep this here because it saves recoding this function in wxTinyFrame
211 if ( style
& (wxTINY_CAPTION_VERT
| wxTINY_CAPTION_HORIZ
) )
212 msflags
|= WS_CAPTION
;
216 // there is no taskbar under CE, so omit all this
218 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
) )
220 if ( style
& wxFRAME_TOOL_WINDOW
)
222 // create the palette-like window
223 *exflags
|= WS_EX_TOOLWINDOW
;
225 // tool windows shouldn't appear on the taskbar (as documented)
226 style
|= wxFRAME_NO_TASKBAR
;
229 // We have to solve 2 different problems here:
231 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
232 // taskbar even if they don't have a parent
234 // 2. frames without this style should appear in the taskbar even
235 // if they're owned (Windows only puts non owned windows into
236 // the taskbar normally)
238 // The second one is solved here by using WS_EX_APPWINDOW flag, the
239 // first one is dealt with in our MSWGetParent() method
241 if ( !(style
& wxFRAME_NO_TASKBAR
) && GetParent() )
243 // need to force the frame to appear in the taskbar
244 *exflags
|= WS_EX_APPWINDOW
;
246 //else: nothing to do [here]
248 #endif // !__WXWINCE__
250 if ( style
& wxSTAY_ON_TOP
)
251 *exflags
|= WS_EX_TOPMOST
;
253 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP
)
254 *exflags
|= WS_EX_CONTEXTHELP
;
260 WXHWND
wxTopLevelWindowMSW::MSWGetParent() const
262 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
263 // parent HWND or it would be always on top of its parent which is not what
264 // we usually want (in fact, we only want it for frames with the
265 // wxFRAME_FLOAT_ON_PARENT flag)
266 HWND hwndParent
= NULL
;
267 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
269 const wxWindow
*parent
= GetParent();
273 // this flag doesn't make sense then and will be ignored
274 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
278 hwndParent
= GetHwndOf(parent
);
281 //else: don't float on parent, must not be owned
283 // now deal with the 2nd taskbar-related problem (see comments above in
285 if ( HasFlag(wxFRAME_NO_TASKBAR
) && !hwndParent
)
288 hwndParent
= wxTLWHiddenParentModule::GetHWND();
291 return (WXHWND
)hwndParent
;
294 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate
,
295 const wxString
& title
,
299 #ifdef __WXMICROWIN__
300 // no dialogs support under MicroWin yet
301 return CreateFrame(title
, pos
, size
);
302 #else // !__WXMICROWIN__
303 wxWindow
*parent
= GetParent();
305 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
306 // app window as parent - this avoids creating modal dialogs without
308 if ( !parent
&& !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) )
310 parent
= wxTheApp
->GetTopWindow();
314 // don't use transient windows as parents, this is dangerous as it
315 // can lead to a crash if the parent is destroyed before the child
317 // also don't use the window which is currently hidden as then the
318 // dialog would be hidden as well
319 if ( (parent
->GetExtraStyle() & wxWS_EX_TRANSIENT
) ||
327 m_hWnd
= (WXHWND
)::CreateDialogIndirect
330 (DLGTEMPLATE
*)dlgTemplate
,
331 parent
? GetHwndOf(parent
) : NULL
,
337 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
339 wxLogSysError(wxT("Can't create dialog using memory template"));
345 (void)MSWGetCreateWindowFlags(&exflags
);
349 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE
, exflags
);
350 ::SetWindowPos(GetHwnd(),
351 exflags
& WS_EX_TOPMOST
? HWND_TOPMOST
: 0,
355 (exflags
& WS_EX_TOPMOST
? 0 : SWP_NOZORDER
) |
359 #if defined(__WIN95__)
360 // For some reason, the system menu is activated when we use the
361 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
362 if ( exflags
& WS_EX_CONTEXTHELP
)
364 wxFrame
*winTop
= wxDynamicCast(wxTheApp
->GetTopWindow(), wxFrame
);
367 wxIcon icon
= winTop
->GetIcon();
370 ::SendMessage(GetHwnd(), WM_SETICON
,
372 (LPARAM
)GetHiconOf(icon
));
378 // move the dialog to its initial position without forcing repainting
380 (void)MSWGetCreateWindowCoords(pos
, size
, x
, y
, w
, h
);
382 if ( x
== (int)CW_USEDEFAULT
)
384 // centre it on the screen - what else can we do?
385 wxSize sizeDpy
= wxGetDisplaySize();
387 x
= (sizeDpy
.x
- w
) / 2;
388 y
= (sizeDpy
.y
- h
) / 2;
392 if ( !::MoveWindow(GetHwnd(), x
, y
, w
, h
, FALSE
) )
394 wxLogLastError(wxT("MoveWindow"));
398 if ( !title
.empty() )
400 ::SetWindowText(GetHwnd(), title
);
406 #endif // __WXMICROWIN__/!__WXMICROWIN__
409 bool wxTopLevelWindowMSW::CreateFrame(const wxString
& title
,
414 WXDWORD flags
= MSWGetCreateWindowFlags(&exflags
);
416 return MSWCreate(wxCanvasClassName
, title
, pos
, size
, flags
, exflags
);
419 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
421 const wxString
& title
,
425 const wxString
& name
)
427 bool ret
wxDUMMY_INITIALIZE(false);
432 wxSize sizeReal
= size
;
433 if ( !sizeReal
.IsFullySpecified() )
435 sizeReal
.SetDefaults(GetDefaultSize());
438 m_windowStyle
= style
;
442 m_windowId
= id
== -1 ? NewControlId() : id
;
444 wxTopLevelWindows
.Append(this);
447 parent
->AddChild(this);
449 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG
)
451 // we have different dialog templates to allows creation of dialogs
452 // with & without captions under MSWindows, resizeable or not (but a
453 // resizeable dialog always has caption - otherwise it would look too
456 // we need 3 additional WORDs for dialog menu, class and title (as we
457 // don't use DS_SETFONT we don't need the fourth WORD for the font)
458 static const int dlgsize
= sizeof(DLGTEMPLATE
) + (sizeof(WORD
) * 3);
459 DLGTEMPLATE
*dlgTemplate
= (DLGTEMPLATE
*)malloc(dlgsize
);
460 memset(dlgTemplate
, 0, dlgsize
);
462 // these values are arbitrary, they won't be used normally anyhow
465 dlgTemplate
->cx
= 144;
466 dlgTemplate
->cy
= 75;
468 // reuse the code in MSWGetStyle() but correct the results slightly for
470 dlgTemplate
->style
= MSWGetStyle(style
, NULL
);
472 // all dialogs are popups
473 dlgTemplate
->style
|= WS_POPUP
;
475 // force 3D-look if necessary, it looks impossibly ugly otherwise
476 if ( style
& (wxRESIZE_BORDER
| wxCAPTION
) )
477 dlgTemplate
->style
|= DS_MODALFRAME
;
479 ret
= CreateDialog(dlgTemplate
, title
, pos
, sizeReal
);
484 ret
= CreateFrame(title
, pos
, sizeReal
);
487 if ( ret
&& !(GetWindowStyleFlag() & wxCLOSE_BOX
) )
489 EnableCloseButton(false);
492 // for some reason we need to manually send ourselves this message as
493 // otherwise the mnemonics are always shown -- even if they're configured
494 // to be hidden until "Alt" is pressed in the control panel
496 // this could indicate a bug somewhere else but for now this is the only
504 MAKEWPARAM(UIS_INITIALIZE
, UISF_HIDEFOCUS
| UISF_HIDEACCEL
),
512 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
514 if ( wxModelessWindows
.Find(this) )
515 wxModelessWindows
.DeleteObject(this);
517 // after destroying an owned window, Windows activates the next top level
518 // window in Z order but it may be different from our owner (to reproduce
519 // this simply Alt-TAB to another application and back before closing the
520 // owned frame) whereas we always want to yield activation to our parent
521 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT
) )
523 wxWindow
*parent
= GetParent();
526 ::BringWindowToTop(GetHwndOf(parent
));
531 // ----------------------------------------------------------------------------
532 // wxTopLevelWindowMSW showing
533 // ----------------------------------------------------------------------------
535 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
537 ::ShowWindow(GetHwnd(), nShowCmd
);
539 m_iconized
= nShowCmd
== SW_MINIMIZE
;
542 bool wxTopLevelWindowMSW::Show(bool show
)
544 // don't use wxWindow version as we want to call DoShowWindow() ourselves
545 if ( !wxWindowBase::Show(show
) )
551 if ( m_maximizeOnShow
)
554 nShowCmd
= SW_MAXIMIZE
;
556 m_maximizeOnShow
= FALSE
;
560 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW
)
561 nShowCmd
= SW_SHOWNA
;
571 DoShowWindow(nShowCmd
);
575 ::BringWindowToTop(GetHwnd());
577 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
578 event
.SetEventObject( this );
579 GetEventHandler()->ProcessEvent(event
);
583 // Try to highlight the correct window (the parent)
586 HWND hWndParent
= GetHwndOf(GetParent());
588 ::BringWindowToTop(hWndParent
);
595 // ----------------------------------------------------------------------------
596 // wxTopLevelWindowMSW maximize/minimize
597 // ----------------------------------------------------------------------------
599 void wxTopLevelWindowMSW::Maximize(bool maximize
)
603 // just maximize it directly
604 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
608 // we can't maximize the hidden frame because it shows it as well, so
609 // just remember that we should do it later in this case
610 m_maximizeOnShow
= maximize
;
614 bool wxTopLevelWindowMSW::IsMaximized() const
619 return ::IsZoomed(GetHwnd()) != 0;
623 void wxTopLevelWindowMSW::Iconize(bool iconize
)
625 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
628 bool wxTopLevelWindowMSW::IsIconized() const
633 // also update the current state
634 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
640 void wxTopLevelWindowMSW::Restore()
642 DoShowWindow(SW_RESTORE
);
645 // ----------------------------------------------------------------------------
646 // wxTopLevelWindowMSW fullscreen
647 // ----------------------------------------------------------------------------
649 bool wxTopLevelWindowMSW::ShowFullScreen(bool show
, long style
)
651 if ( show
== IsFullScreen() )
657 m_fsIsShowing
= show
;
663 // zap the frame borders
665 // save the 'normal' window style
666 m_fsOldWindowStyle
= GetWindowLong(GetHwnd(), GWL_STYLE
);
668 // save the old position, width & height, maximize state
669 m_fsOldSize
= GetRect();
670 m_fsIsMaximized
= IsMaximized();
672 // decide which window style flags to turn off
673 LONG newStyle
= m_fsOldWindowStyle
;
676 if (style
& wxFULLSCREEN_NOBORDER
)
678 offFlags
|= WS_BORDER
;
680 offFlags
|= WS_THICKFRAME
;
683 if (style
& wxFULLSCREEN_NOCAPTION
)
684 offFlags
|= WS_CAPTION
| WS_SYSMENU
;
686 newStyle
&= ~offFlags
;
688 // change our window style to be compatible with full-screen mode
689 ::SetWindowLong(GetHwnd(), GWL_STYLE
, newStyle
);
693 // resize to the size of the display containing us
694 int dpy
= wxDisplay::GetFromWindow(this);
695 if ( dpy
!= wxNOT_FOUND
)
697 rect
= wxDisplay(dpy
).GetGeometry();
699 else // fall back to the main desktop
700 #else // wxUSE_DISPLAY
702 // resize to the size of the desktop
703 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect
);
705 // FIXME: size of the bottom menu (toolbar)
706 // should be taken in account
707 rect
.height
+= rect
.y
;
711 #endif // wxUSE_DISPLAY
715 // now flush the window style cache and actually go full-screen
716 long flags
= SWP_FRAMECHANGED
;
718 // showing the frame full screen should also show it if it's still
722 // don't call wxWindow version to avoid flicker from calling
723 // ::ShowWindow() -- we're going to show the window at the correct
724 // location directly below -- but do call the wxWindowBase version
725 // to sync the internal m_isShown flag
726 wxWindowBase::Show();
728 flags
|= SWP_SHOWWINDOW
;
731 SetWindowPos(GetHwnd(), HWND_TOP
,
732 rect
.x
, rect
.y
, rect
.width
, rect
.height
,
735 #if defined(__WXWINCE__) && _WIN32_WCE < 400
736 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR
| SHFS_HIDESIPBUTTON
);
739 // finally send an event allowing the window to relayout itself &c
740 wxSizeEvent
event(rect
.GetSize(), GetId());
741 GetEventHandler()->ProcessEvent(event
);
743 else // stop showing full screen
745 #if defined(__WXWINCE__) && _WIN32_WCE < 400
746 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR
| SHFS_SHOWSIPBUTTON
);
748 Maximize(m_fsIsMaximized
);
749 SetWindowLong(GetHwnd(),GWL_STYLE
, m_fsOldWindowStyle
);
750 SetWindowPos(GetHwnd(),HWND_TOP
,m_fsOldSize
.x
, m_fsOldSize
.y
,
751 m_fsOldSize
.width
, m_fsOldSize
.height
, SWP_FRAMECHANGED
);
757 // ----------------------------------------------------------------------------
758 // wxTopLevelWindowMSW misc
759 // ----------------------------------------------------------------------------
761 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
763 SetIcons( wxIconBundle( icon
) );
766 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle
& icons
)
768 wxTopLevelWindowBase::SetIcons(icons
);
770 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
771 const wxIcon
& sml
= icons
.GetIcon( wxSize( 16, 16 ) );
772 if( sml
.Ok() && sml
.GetWidth() == 16 && sml
.GetHeight() == 16 )
774 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_SMALL
,
775 (LPARAM
)GetHiconOf(sml
) );
778 const wxIcon
& big
= icons
.GetIcon( wxSize( 32, 32 ) );
779 if( big
.Ok() && big
.GetWidth() == 32 && big
.GetHeight() == 32 )
781 ::SendMessage( GetHwndOf( this ), WM_SETICON
, ICON_BIG
,
782 (LPARAM
)GetHiconOf(big
) );
787 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable
)
789 #if !defined(__WXMICROWIN__)
790 // get system (a.k.a. window) menu
791 HMENU hmenu
= GetSystemMenu(GetHwnd(), FALSE
/* get it */);
794 // no system menu at all -- ok if we want to remove the close button
795 // anyhow, but bad if we want to show it
799 // enabling/disabling the close item from it also automatically
800 // disables/enables the close title bar button
801 if ( ::EnableMenuItem(hmenu
, SC_CLOSE
,
803 (enable
? MF_ENABLED
: MF_GRAYED
)) == -1 )
805 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
810 // update appearance immediately
811 if ( !::DrawMenuBar(GetHwnd()) )
813 wxLogLastError(_T("DrawMenuBar"));
815 #endif // !__WXMICROWIN__
822 bool wxTopLevelWindowMSW::SetShape(const wxRegion
& region
)
824 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED
), FALSE
,
825 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
827 // The empty region signifies that the shape should be removed from the
829 if ( region
.IsEmpty() )
831 if (::SetWindowRgn(GetHwnd(), NULL
, TRUE
) == 0)
833 wxLogLastError(_T("SetWindowRgn"));
839 // Windows takes ownership of the region, so
840 // we'll have to make a copy of the region to give to it.
841 DWORD noBytes
= ::GetRegionData(GetHrgnOf(region
), 0, NULL
);
842 RGNDATA
*rgnData
= (RGNDATA
*) new char[noBytes
];
843 ::GetRegionData(GetHrgnOf(region
), noBytes
, rgnData
);
844 HRGN hrgn
= ::ExtCreateRegion(NULL
, noBytes
, rgnData
);
845 delete[] (char*) rgnData
;
847 // SetWindowRgn expects the region to be in coordinants
848 // relative to the window, not the client area. Figure
849 // out the offset, if any.
851 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
852 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
853 ::GetClientRect(GetHwnd(), &rect
);
854 ::AdjustWindowRectEx(&rect
, dwStyle
, FALSE
, dwExStyle
);
855 ::OffsetRgn(hrgn
, -rect
.left
, -rect
.top
);
857 // Now call the shape API with the new region.
858 if (::SetWindowRgn(GetHwnd(), hrgn
, TRUE
) == 0)
860 wxLogLastError(_T("SetWindowRgn"));
866 #endif // !__WXWINCE__
868 // ----------------------------------------------------------------------------
869 // wxTopLevelWindow event handling
870 // ----------------------------------------------------------------------------
872 // Default activation behaviour - set the focus for the first child
874 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent
& event
)
876 if ( event
.GetActive() )
878 // restore focus to the child which was last focused unless we already
880 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd
);
882 wxWindow
*winFocus
= FindFocus();
883 if ( !winFocus
|| wxGetTopLevelParent(winFocus
) != this )
885 wxWindow
*parent
= m_winLastFocused
? m_winLastFocused
->GetParent()
892 wxSetFocusToChild(parent
, &m_winLastFocused
);
897 // remember the last focused child if it is our child
898 m_winLastFocused
= FindFocus();
900 if ( m_winLastFocused
)
902 // let it know that it doesn't have focus any more
903 m_winLastFocused
->HandleKillFocus((WXHWND
)NULL
);
905 // and don't remember it if it's a child from some other frame
906 if ( wxGetTopLevelParent(m_winLastFocused
) != this )
908 m_winLastFocused
= NULL
;
912 wxLogTrace(_T("focus"),
913 _T("wxTLW %08x deactivated, last focused: %08x."),
915 (int) (m_winLastFocused
? GetHwndOf(m_winLastFocused
)
922 // the DialogProc for all wxWindows dialogs
923 LONG APIENTRY _EXPORT
926 WPARAM
WXUNUSED(wParam
),
927 LPARAM
WXUNUSED(lParam
))
932 // for this message, returning TRUE tells system to set focus to
933 // the first control in the dialog box, but as we set the focus
934 // ourselves, we return FALSE from here as well, so fall through
938 shidi
.dwMask
= SHIDIM_FLAGS
;
939 shidi
.dwFlags
= SHIDIF_DONEBUTTON
|
940 SHIDIF_SIZEDLGFULLSCREEN
;
942 SHInitDialog( &shidi
);
947 // for all the other ones, FALSE means that we didn't process the
953 // ============================================================================
954 // wxTLWHiddenParentModule implementation
955 // ============================================================================
957 HWND
wxTLWHiddenParentModule::ms_hwnd
= NULL
;
959 const wxChar
*wxTLWHiddenParentModule::ms_className
= NULL
;
961 bool wxTLWHiddenParentModule::OnInit()
969 void wxTLWHiddenParentModule::OnExit()
973 if ( !::DestroyWindow(ms_hwnd
) )
975 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
983 if ( !::UnregisterClass(ms_className
, wxGetInstance()) )
985 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
993 HWND
wxTLWHiddenParentModule::GetHWND()
999 static const wxChar
*HIDDEN_PARENT_CLASS
= _T("wxTLWHiddenParent");
1002 wxZeroMemory(wndclass
);
1004 wndclass
.lpfnWndProc
= DefWindowProc
;
1005 wndclass
.hInstance
= wxGetInstance();
1006 wndclass
.lpszClassName
= HIDDEN_PARENT_CLASS
;
1008 if ( !::RegisterClass(&wndclass
) )
1010 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1014 ms_className
= HIDDEN_PARENT_CLASS
;
1018 ms_hwnd
= ::CreateWindow(ms_className
, wxEmptyString
, 0, 0, 0, 0, 0, NULL
,
1019 (HMENU
)NULL
, wxGetInstance(), NULL
);
1022 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));