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 license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
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"
39 #include "wx/msw/private.h"
41 // ----------------------------------------------------------------------------
42 // stubs for missing functions under MicroWindows
43 // ----------------------------------------------------------------------------
47 static inline bool IsIconic(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
48 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
50 #endif // __WXMICROWIN__
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 // list of all frames and modeless dialogs
57 wxWindowList wxModelessWindows
;
59 // ============================================================================
60 // wxTopLevelWindowMSW implementation
61 // ============================================================================
63 // ----------------------------------------------------------------------------
64 // wxTopLevelWindowMSW creation
65 // ----------------------------------------------------------------------------
67 void wxTopLevelWindowMSW::Init()
70 m_maximizeOnShow
= FALSE
;
73 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
75 const wxString
& title
,
84 m_windowStyle
= style
;
88 m_windowId
= id
== -1 ? NewControlId() : id
;
90 wxTopLevelWindows
.Append(this);
93 parent
->AddChild(this);
98 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
100 wxTopLevelWindows
.DeleteObject(this);
102 if ( wxModelessWindows
.Find(this) )
103 wxModelessWindows
.DeleteObject(this);
105 // If this is the last top-level window, exit.
106 if ( wxTheApp
&& (wxTopLevelWindows
.Number() == 0) )
108 wxTheApp
->SetTopWindow(NULL
);
110 if ( wxTheApp
->GetExitOnFrameDelete() )
112 ::PostQuitMessage(0);
117 // ----------------------------------------------------------------------------
118 // wxTopLevelWindowMSW geometry
119 // ----------------------------------------------------------------------------
121 void wxTopLevelWindowMSW::DoSetClientSize(int width
, int height
)
123 HWND hWnd
= GetHwnd();
126 ::GetClientRect(hWnd
, &rectClient
);
129 ::GetWindowRect(hWnd
, &rectTotal
);
131 // Find the difference between the entire window (title bar and all)
132 // and the client area; add this to the new client size to move the
134 width
+= rectTotal
.right
- rectTotal
.left
- rectClient
.right
;
135 height
+= rectTotal
.bottom
- rectTotal
.top
- rectClient
.bottom
;
137 // note that calling GetClientAreaOrigin() takes the toolbar into account
138 wxPoint pt
= GetClientAreaOrigin();
142 if ( !::MoveWindow(hWnd
, rectTotal
.left
, rectTotal
.top
,
143 width
, height
, TRUE
/* redraw */) )
145 wxLogLastError(_T("MoveWindow"));
148 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
149 event
.SetEventObject(this);
150 (void)GetEventHandler()->ProcessEvent(event
);
153 // ----------------------------------------------------------------------------
154 // wxTopLevelWindowMSW showing
155 // ----------------------------------------------------------------------------
157 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
159 ::ShowWindow(GetHwnd(), nShowCmd
);
161 m_iconized
= nShowCmd
== SW_MINIMIZE
;
164 bool wxTopLevelWindowMSW::Show(bool show
)
166 // don't use wxWindow version as we want to call DoShowWindow() ourselves
167 if ( !wxWindowBase::Show(show
) )
173 if ( m_maximizeOnShow
)
176 nShowCmd
= SW_MAXIMIZE
;
178 m_maximizeOnShow
= FALSE
;
190 DoShowWindow(nShowCmd
);
194 ::BringWindowToTop(GetHwnd());
196 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
197 event
.SetEventObject( this );
198 GetEventHandler()->ProcessEvent(event
);
202 // Try to highlight the correct window (the parent)
205 HWND hWndParent
= GetHwndOf(GetParent());
207 ::BringWindowToTop(hWndParent
);
214 // ----------------------------------------------------------------------------
215 // wxTopLevelWindowMSW maximize/minimize
216 // ----------------------------------------------------------------------------
218 void wxTopLevelWindowMSW::Maximize(bool maximize
)
222 // just maximize it directly
223 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
227 // we can't maximize the hidden frame because it shows it as well, so
228 // just remember that we should do it later in this case
229 m_maximizeOnShow
= TRUE
;
233 bool wxTopLevelWindowMSW::IsMaximized() const
235 return ::IsZoomed(GetHwnd()) != 0;
238 void wxTopLevelWindowMSW::Iconize(bool iconize
)
240 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
243 bool wxTopLevelWindowMSW::IsIconized() const
245 // also update the current state
246 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
251 void wxTopLevelWindowMSW::Restore()
253 DoShowWindow(SW_RESTORE
);
256 // ----------------------------------------------------------------------------
257 // wxTopLevelWindowMSW misc
258 // ----------------------------------------------------------------------------
260 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
263 wxTopLevelWindowBase::SetIcon(icon
);
265 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
268 ::SendMessage(GetHwnd(), WM_SETICON
,
269 (WPARAM
)TRUE
, (LPARAM
)GetHiconOf(m_icon
));