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"
32 #include "wx/string.h"
37 #include "wx/msw/private.h"
39 // ----------------------------------------------------------------------------
40 // stubs for missing functions under MicroWindows
41 // ----------------------------------------------------------------------------
45 static inline bool IsIconic(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
46 static inline bool IsZoomed(HWND
WXUNUSED(hwnd
)) { return FALSE
; }
48 #endif // __WXMICROWIN__
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 // list of all frames and modeless dialogs
55 wxWindowList wxModelessWindows
;
57 // ============================================================================
58 // wxTopLevelWindowMSW implementation
59 // ============================================================================
61 // ----------------------------------------------------------------------------
62 // wxTopLevelWindowMSW creation
63 // ----------------------------------------------------------------------------
65 void wxTopLevelWindowMSW::Init()
68 m_maximizeOnShow
= FALSE
;
71 bool wxTopLevelWindowMSW::Create(wxWindow
*parent
,
73 const wxString
& title
,
82 m_windowStyle
= style
;
86 m_windowId
= id
== -1 ? NewControlId() : id
;
88 wxTopLevelWindows
.Append(this);
91 parent
->AddChild(this);
96 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
98 wxTopLevelWindows
.DeleteObject(this);
100 if ( wxModelessWindows
.Find(this) )
101 wxModelessWindows
.DeleteObject(this);
103 // If this is the last top-level window, exit.
104 if ( wxTheApp
&& (wxTopLevelWindows
.Number() == 0) )
106 wxTheApp
->SetTopWindow(NULL
);
108 if ( wxTheApp
->GetExitOnFrameDelete() )
110 ::PostQuitMessage(0);
115 // ----------------------------------------------------------------------------
116 // wxTopLevelWindowMSW geometry
117 // ----------------------------------------------------------------------------
119 void wxTopLevelWindowMSW::DoSetClientSize(int width
, int height
)
121 HWND hWnd
= GetHwnd();
124 ::GetClientRect(hWnd
, &rectClient
);
127 ::GetWindowRect(hWnd
, &rectTotal
);
129 // Find the difference between the entire window (title bar and all)
130 // and the client area; add this to the new client size to move the
132 width
+= rectTotal
.right
- rectTotal
.left
- rectClient
.right
;
133 height
+= rectTotal
.bottom
- rectTotal
.top
- rectClient
.bottom
;
135 // note that calling GetClientAreaOrigin() takes the toolbar into account
136 wxPoint pt
= GetClientAreaOrigin();
140 if ( !::MoveWindow(hWnd
, rectTotal
.left
, rectTotal
.top
,
141 width
, height
, TRUE
/* redraw */) )
143 wxLogLastError(_T("MoveWindow"));
146 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
147 event
.SetEventObject(this);
148 (void)GetEventHandler()->ProcessEvent(event
);
151 // ----------------------------------------------------------------------------
152 // wxTopLevelWindowMSW showing
153 // ----------------------------------------------------------------------------
155 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd
)
157 ::ShowWindow(GetHwnd(), nShowCmd
);
159 m_iconized
= nShowCmd
== SW_MINIMIZE
;
162 bool wxTopLevelWindowMSW::Show(bool show
)
164 // don't use wxWindow version as we want to call DoShowWindow() ourselves
165 if ( !wxWindowBase::Show(show
) )
171 if ( m_maximizeOnShow
)
174 nShowCmd
= SW_MAXIMIZE
;
176 m_maximizeOnShow
= FALSE
;
188 DoShowWindow(nShowCmd
);
192 ::BringWindowToTop(GetHwnd());
194 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_windowId
);
195 event
.SetEventObject( this );
196 GetEventHandler()->ProcessEvent(event
);
200 // Try to highlight the correct window (the parent)
203 HWND hWndParent
= GetHwndOf(GetParent());
205 ::BringWindowToTop(hWndParent
);
212 // ----------------------------------------------------------------------------
213 // wxTopLevelWindowMSW maximize/minimize
214 // ----------------------------------------------------------------------------
216 void wxTopLevelWindowMSW::Maximize(bool maximize
)
220 // just maximize it directly
221 DoShowWindow(maximize
? SW_MAXIMIZE
: SW_RESTORE
);
225 // we can't maximize the hidden frame because it shows it as well, so
226 // just remember that we should do it later in this case
227 m_maximizeOnShow
= TRUE
;
231 bool wxTopLevelWindowMSW::IsMaximized() const
233 return ::IsZoomed(GetHwnd()) != 0;
236 void wxTopLevelWindowMSW::Iconize(bool iconize
)
238 DoShowWindow(iconize
? SW_MINIMIZE
: SW_RESTORE
);
241 bool wxTopLevelWindowMSW::IsIconized() const
243 // also update the current state
244 ((wxTopLevelWindowMSW
*)this)->m_iconized
= ::IsIconic(GetHwnd()) != 0;
249 void wxTopLevelWindowMSW::Restore()
251 DoShowWindow(SW_RESTORE
);
254 // ----------------------------------------------------------------------------
255 // wxTopLevelWindowMSW misc
256 // ----------------------------------------------------------------------------
258 void wxTopLevelWindowMSW::SetIcon(const wxIcon
& icon
)
261 wxTopLevelWindowBase::SetIcon(icon
);
263 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
266 ::SendMessage(GetHwnd(), WM_SETICON
,
267 (WPARAM
)TRUE
, (LPARAM
)GetHiconOf(m_icon
));