]> git.saurik.com Git - wxWidgets.git/blob - src/msw/toplevel.cpp
oops, forgot do add fullscreen stuff to wxTLWBase
[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/string.h"
33 #include "wx/log.h"
34 #include "wx/intl.h"
35 #endif //WX_PRECOMP
36
37 #include "wx/msw/private.h"
38
39 // ----------------------------------------------------------------------------
40 // stubs for missing functions under MicroWindows
41 // ----------------------------------------------------------------------------
42
43 #ifdef __WXMICROWIN__
44
45 static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
46 static inline bool IsZoomed(HWND WXUNUSED(hwnd)) { return FALSE; }
47
48 #endif // __WXMICROWIN__
49
50 // ----------------------------------------------------------------------------
51 // globals
52 // ----------------------------------------------------------------------------
53
54 // list of all frames and modeless dialogs
55 wxWindowList wxModelessWindows;
56
57 // ============================================================================
58 // wxTopLevelWindowMSW implementation
59 // ============================================================================
60
61 // ----------------------------------------------------------------------------
62 // wxTopLevelWindowMSW creation
63 // ----------------------------------------------------------------------------
64
65 void wxTopLevelWindowMSW::Init()
66 {
67 m_iconized =
68 m_maximizeOnShow = FALSE;
69 }
70
71 bool wxTopLevelWindowMSW::Create(wxWindow *parent,
72 wxWindowID id,
73 const wxString& title,
74 const wxPoint& pos,
75 const wxSize& size,
76 long style,
77 const wxString& name)
78 {
79 // init our fields
80 Init();
81
82 m_windowStyle = style;
83
84 SetName(name);
85
86 m_windowId = id == -1 ? NewControlId() : id;
87
88 wxTopLevelWindows.Append(this);
89
90 if ( parent )
91 parent->AddChild(this);
92
93 return TRUE;
94 }
95
96 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
97 {
98 wxTopLevelWindows.DeleteObject(this);
99
100 if ( wxModelessWindows.Find(this) )
101 wxModelessWindows.DeleteObject(this);
102
103 // If this is the last top-level window, exit.
104 if ( wxTheApp && (wxTopLevelWindows.Number() == 0) )
105 {
106 wxTheApp->SetTopWindow(NULL);
107
108 if ( wxTheApp->GetExitOnFrameDelete() )
109 {
110 ::PostQuitMessage(0);
111 }
112 }
113 }
114
115 // ----------------------------------------------------------------------------
116 // wxTopLevelWindowMSW geometry
117 // ----------------------------------------------------------------------------
118
119 void wxTopLevelWindowMSW::DoSetClientSize(int width, int height)
120 {
121 HWND hWnd = GetHwnd();
122
123 RECT rectClient;
124 ::GetClientRect(hWnd, &rectClient);
125
126 RECT rectTotal;
127 ::GetWindowRect(hWnd, &rectTotal);
128
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
131 // window
132 width += rectTotal.right - rectTotal.left - rectClient.right;
133 height += rectTotal.bottom - rectTotal.top - rectClient.bottom;
134
135 // note that calling GetClientAreaOrigin() takes the toolbar into account
136 wxPoint pt = GetClientAreaOrigin();
137 width += pt.x;
138 height += pt.y;
139
140 if ( !::MoveWindow(hWnd, rectTotal.left, rectTotal.top,
141 width, height, TRUE /* redraw */) )
142 {
143 wxLogLastError(_T("MoveWindow"));
144 }
145
146 wxSizeEvent event(wxSize(width, height), m_windowId);
147 event.SetEventObject(this);
148 (void)GetEventHandler()->ProcessEvent(event);
149 }
150
151 // ----------------------------------------------------------------------------
152 // wxTopLevelWindowMSW showing
153 // ----------------------------------------------------------------------------
154
155 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd)
156 {
157 ::ShowWindow(GetHwnd(), nShowCmd);
158
159 m_iconized = nShowCmd == SW_MINIMIZE;
160 }
161
162 bool wxTopLevelWindowMSW::Show(bool show)
163 {
164 // don't use wxWindow version as we want to call DoShowWindow() ourselves
165 if ( !wxWindowBase::Show(show) )
166 return FALSE;
167
168 int nShowCmd;
169 if ( show )
170 {
171 if ( m_maximizeOnShow )
172 {
173 // show and maximize
174 nShowCmd = SW_MAXIMIZE;
175
176 m_maximizeOnShow = FALSE;
177 }
178 else // just show
179 {
180 nShowCmd = SW_SHOW;
181 }
182 }
183 else // hide
184 {
185 nShowCmd = SW_HIDE;
186 }
187
188 DoShowWindow(nShowCmd);
189
190 if ( show )
191 {
192 ::BringWindowToTop(GetHwnd());
193
194 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
195 event.SetEventObject( this );
196 GetEventHandler()->ProcessEvent(event);
197 }
198 else // hide
199 {
200 // Try to highlight the correct window (the parent)
201 if ( GetParent() )
202 {
203 HWND hWndParent = GetHwndOf(GetParent());
204 if (hWndParent)
205 ::BringWindowToTop(hWndParent);
206 }
207 }
208
209 return TRUE;
210 }
211
212 // ----------------------------------------------------------------------------
213 // wxTopLevelWindowMSW maximize/minimize
214 // ----------------------------------------------------------------------------
215
216 void wxTopLevelWindowMSW::Maximize(bool maximize)
217 {
218 if ( IsShown() )
219 {
220 // just maximize it directly
221 DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE);
222 }
223 else // hidden
224 {
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;
228 }
229 }
230
231 bool wxTopLevelWindowMSW::IsMaximized() const
232 {
233 return ::IsZoomed(GetHwnd()) != 0;
234 }
235
236 void wxTopLevelWindowMSW::Iconize(bool iconize)
237 {
238 DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE);
239 }
240
241 bool wxTopLevelWindowMSW::IsIconized() const
242 {
243 // also update the current state
244 ((wxTopLevelWindowMSW *)this)->m_iconized = ::IsIconic(GetHwnd()) != 0;
245
246 return m_iconized;
247 }
248
249 void wxTopLevelWindowMSW::Restore()
250 {
251 DoShowWindow(SW_RESTORE);
252 }
253
254 // ----------------------------------------------------------------------------
255 // wxTopLevelWindowMSW misc
256 // ----------------------------------------------------------------------------
257
258 void wxTopLevelWindowMSW::SetIcon(const wxIcon& icon)
259 {
260 // this sets m_icon
261 wxTopLevelWindowBase::SetIcon(icon);
262
263 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
264 if ( m_icon.Ok() )
265 {
266 ::SendMessage(GetHwnd(), WM_SETICON,
267 (WPARAM)TRUE, (LPARAM)GetHiconOf(m_icon));
268 }
269 #endif // __WIN95__
270 }