]>
Commit | Line | Data |
---|---|---|
82c9f85c VZ |
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) | |
6c9a19aa | 9 | // License: wxWindows licence |
82c9f85c VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
82c9f85c VZ |
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 | |
3a922bb4 RL |
32 | #include "wx/app.h" |
33 | #include "wx/toplevel.h" | |
82c9f85c VZ |
34 | #include "wx/string.h" |
35 | #include "wx/log.h" | |
36 | #include "wx/intl.h" | |
14dd645e | 37 | #include "wx/frame.h" |
706d74ab | 38 | #include "wx/containr.h" // wxSetFocusToChild() |
82c9f85c VZ |
39 | #endif //WX_PRECOMP |
40 | ||
2b5f62a0 VZ |
41 | #include "wx/module.h" |
42 | ||
82c9f85c | 43 | #include "wx/msw/private.h" |
80a81a12 JS |
44 | |
45 | #if defined(__WXWINCE__) | |
46 | #include <ole2.h> | |
47 | #include <shellapi.h> | |
2d36b3d8 JS |
48 | #if _WIN32_WCE < 400 |
49 | #include <aygshell.h> | |
50 | #endif | |
51 | #include "wx/msw/wince/missing.h" | |
80a81a12 JS |
52 | #endif |
53 | ||
4676948b JS |
54 | #include "wx/msw/winundef.h" |
55 | ||
ffcb4ee4 JS |
56 | // This can't be undefed in winundef.h or |
57 | // there are further errors | |
58 | #if defined(__WXWINCE__) && defined(CreateDialog) | |
59 | #undef CreateDialog | |
60 | #endif | |
61 | ||
716645d3 | 62 | #include "wx/display.h" |
7e25f59e | 63 | |
e121a72a MB |
64 | #ifndef ICON_BIG |
65 | #define ICON_BIG 1 | |
66 | #endif | |
67 | ||
68 | #ifndef ICON_SMALL | |
69 | #define ICON_SMALL 0 | |
70 | #endif | |
71 | ||
82c9f85c VZ |
72 | // ---------------------------------------------------------------------------- |
73 | // stubs for missing functions under MicroWindows | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
76 | #ifdef __WXMICROWIN__ | |
77 | ||
c67d6888 | 78 | // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; } |
82c9f85c VZ |
79 | static inline bool IsZoomed(HWND WXUNUSED(hwnd)) { return FALSE; } |
80 | ||
81 | #endif // __WXMICROWIN__ | |
82 | ||
12447831 VZ |
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 | |
61179e28 VZ |
85 | LONG APIENTRY _EXPORT |
86 | wxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); | |
87 | ||
82c9f85c VZ |
88 | // ---------------------------------------------------------------------------- |
89 | // globals | |
90 | // ---------------------------------------------------------------------------- | |
91 | ||
92 | // list of all frames and modeless dialogs | |
93 | wxWindowList wxModelessWindows; | |
94 | ||
b225f659 VZ |
95 | // the name of the default wxWindows class |
96 | extern const wxChar *wxCanvasClassName; | |
97 | ||
2b5f62a0 VZ |
98 | // ---------------------------------------------------------------------------- |
99 | // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a | |
100 | // module to ensure that the window is always deleted) | |
101 | // ---------------------------------------------------------------------------- | |
102 | ||
103 | class wxTLWHiddenParentModule : public wxModule | |
104 | { | |
105 | public: | |
106 | // module init/finalize | |
107 | virtual bool OnInit(); | |
108 | virtual void OnExit(); | |
109 | ||
110 | // get the hidden window (creates on demand) | |
111 | static HWND GetHWND(); | |
112 | ||
113 | private: | |
114 | // the HWND of the hidden parent | |
115 | static HWND ms_hwnd; | |
116 | ||
117 | // the class used to create it | |
118 | static const wxChar *ms_className; | |
119 | ||
120 | DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule) | |
121 | }; | |
122 | ||
123 | IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule, wxModule) | |
9dfef5ac | 124 | |
82c9f85c VZ |
125 | // ============================================================================ |
126 | // wxTopLevelWindowMSW implementation | |
127 | // ============================================================================ | |
128 | ||
085ad686 VZ |
129 | BEGIN_EVENT_TABLE(wxTopLevelWindowMSW, wxTopLevelWindowBase) |
130 | EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate) | |
131 | END_EVENT_TABLE() | |
132 | ||
82c9f85c VZ |
133 | // ---------------------------------------------------------------------------- |
134 | // wxTopLevelWindowMSW creation | |
135 | // ---------------------------------------------------------------------------- | |
136 | ||
137 | void wxTopLevelWindowMSW::Init() | |
138 | { | |
139 | m_iconized = | |
140 | m_maximizeOnShow = FALSE; | |
b225f659 VZ |
141 | |
142 | // unlike (almost?) all other windows, frames are created hidden | |
143 | m_isShown = FALSE; | |
c641b1d2 VS |
144 | |
145 | // Data to save/restore when calling ShowFullScreen | |
146 | m_fsStyle = 0; | |
147 | m_fsOldWindowStyle = 0; | |
148 | m_fsIsMaximized = FALSE; | |
149 | m_fsIsShowing = FALSE; | |
085ad686 VZ |
150 | |
151 | m_winLastFocused = (wxWindow *)NULL; | |
b225f659 VZ |
152 | } |
153 | ||
b2d5a7ee | 154 | WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const |
b225f659 | 155 | { |
b2d5a7ee VZ |
156 | // let the base class deal with the common styles but fix the ones which |
157 | // don't make sense for us (we also deal with the borders ourselves) | |
158 | WXDWORD msflags = wxWindow::MSWGetStyle | |
159 | ( | |
160 | (style & ~wxBORDER_MASK) | wxBORDER_NONE, exflags | |
31e7e89f | 161 | ) & ~WS_CHILD & ~WS_VISIBLE; |
b225f659 VZ |
162 | |
163 | // first select the kind of window being created | |
dfb06c62 VZ |
164 | // |
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 | |
0e082993 | 168 | if ( style & wxFRAME_TOOL_WINDOW ) |
b2d5a7ee | 169 | msflags |= WS_POPUP; |
b225f659 | 170 | else |
39d2f9a7 JS |
171 | { |
172 | #ifdef __WXWINCE__ | |
173 | if (msflags & WS_BORDER) | |
174 | #endif | |
175 | msflags |= WS_OVERLAPPED; | |
176 | } | |
0e082993 VZ |
177 | |
178 | // border and caption styles | |
179 | if ( style & wxRESIZE_BORDER ) | |
4676948b JS |
180 | { |
181 | #ifndef __WXWINCE__ | |
0e082993 | 182 | msflags |= WS_THICKFRAME; |
4676948b JS |
183 | #endif |
184 | } | |
f8d56830 JS |
185 | else if ( exflags && ((style & wxBORDER_DOUBLE) || (style & wxBORDER_RAISED)) ) |
186 | *exflags |= WS_EX_DLGMODALFRAME; | |
0e082993 VZ |
187 | else if ( !(style & wxBORDER_NONE) ) |
188 | msflags |= WS_BORDER; | |
39d2f9a7 | 189 | #ifndef __WXWINCE__ |
dfb06c62 VZ |
190 | else |
191 | msflags |= WS_POPUP; | |
39d2f9a7 | 192 | #endif |
0e082993 VZ |
193 | |
194 | if ( style & wxCAPTION ) | |
195 | msflags |= WS_CAPTION; | |
39d2f9a7 | 196 | #ifndef __WXWINCE__ |
dfb06c62 | 197 | else |
b225f659 | 198 | msflags |= WS_POPUP; |
39d2f9a7 | 199 | #endif |
b225f659 VZ |
200 | |
201 | // next translate the individual flags | |
202 | if ( style & wxMINIMIZE_BOX ) | |
203 | msflags |= WS_MINIMIZEBOX; | |
204 | if ( style & wxMAXIMIZE_BOX ) | |
205 | msflags |= WS_MAXIMIZEBOX; | |
b225f659 VZ |
206 | if ( style & wxSYSTEM_MENU ) |
207 | msflags |= WS_SYSMENU; | |
4676948b | 208 | #ifndef __WXWINCE__ |
b225f659 VZ |
209 | if ( style & wxMINIMIZE ) |
210 | msflags |= WS_MINIMIZE; | |
211 | if ( style & wxMAXIMIZE ) | |
212 | msflags |= WS_MAXIMIZE; | |
4676948b | 213 | #endif |
0e082993 | 214 | |
b225f659 VZ |
215 | // Keep this here because it saves recoding this function in wxTinyFrame |
216 | #if wxUSE_ITSY_BITSY && !defined(__WIN32__) | |
217 | if ( style & wxTINY_CAPTION_VERT ) | |
218 | msflags |= IBS_VERTCAPTION; | |
219 | if ( style & wxTINY_CAPTION_HORIZ ) | |
220 | msflags |= IBS_HORZCAPTION; | |
221 | #else | |
222 | if ( style & (wxTINY_CAPTION_VERT | wxTINY_CAPTION_HORIZ) ) | |
223 | msflags |= WS_CAPTION; | |
224 | #endif | |
225 | ||
226 | if ( exflags ) | |
227 | { | |
f8d56830 | 228 | #if !defined(__WIN16__) |
35bf863b VZ |
229 | if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ) |
230 | { | |
9dfef5ac VZ |
231 | if ( style & wxFRAME_TOOL_WINDOW ) |
232 | { | |
233 | // create the palette-like window | |
35bf863b | 234 | *exflags |= WS_EX_TOOLWINDOW; |
404a4d93 VZ |
235 | |
236 | // tool windows shouldn't appear on the taskbar (as documented) | |
237 | style |= wxFRAME_NO_TASKBAR; | |
9dfef5ac VZ |
238 | } |
239 | ||
240 | // We have to solve 2 different problems here: | |
241 | // | |
242 | // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the | |
243 | // taskbar even if they don't have a parent | |
244 | // | |
245 | // 2. frames without this style should appear in the taskbar even | |
246 | // if they're owned (Windows only puts non owned windows into | |
247 | // the taskbar normally) | |
248 | // | |
249 | // The second one is solved here by using WS_EX_APPWINDOW flag, the | |
250 | // first one is dealt with in our MSWGetParent() method | |
251 | // implementation | |
4676948b | 252 | #ifndef __WXWINCE__ |
9dfef5ac VZ |
253 | if ( !(style & wxFRAME_NO_TASKBAR) && GetParent() ) |
254 | { | |
255 | // need to force the frame to appear in the taskbar | |
35bf863b | 256 | *exflags |= WS_EX_APPWINDOW; |
9dfef5ac | 257 | } |
4676948b | 258 | #endif |
9dfef5ac | 259 | //else: nothing to do [here] |
35bf863b VZ |
260 | } |
261 | #endif // !Win16 | |
b225f659 VZ |
262 | |
263 | if ( style & wxSTAY_ON_TOP ) | |
264 | *exflags |= WS_EX_TOPMOST; | |
265 | ||
266 | #ifdef __WIN32__ | |
b2d5a7ee | 267 | if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP ) |
68d02db3 | 268 | *exflags |= WS_EX_CONTEXTHELP; |
b225f659 VZ |
269 | #endif // __WIN32__ |
270 | } | |
271 | ||
272 | return msflags; | |
273 | } | |
274 | ||
9dfef5ac VZ |
275 | WXHWND wxTopLevelWindowMSW::MSWGetParent() const |
276 | { | |
277 | // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL | |
278 | // parent HWND or it would be always on top of its parent which is not what | |
279 | // we usually want (in fact, we only want it for frames with the | |
280 | // wxFRAME_FLOAT_ON_PARENT flag) | |
2b5f62a0 | 281 | HWND hwndParent = NULL; |
9dfef5ac VZ |
282 | if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) ) |
283 | { | |
2b5f62a0 | 284 | const wxWindow *parent = GetParent(); |
9dfef5ac | 285 | |
2b5f62a0 VZ |
286 | if ( !parent ) |
287 | { | |
288 | // this flag doesn't make sense then and will be ignored | |
289 | wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") ); | |
290 | } | |
291 | else | |
292 | { | |
293 | hwndParent = GetHwndOf(parent); | |
294 | } | |
9dfef5ac | 295 | } |
2b5f62a0 | 296 | //else: don't float on parent, must not be owned |
9dfef5ac VZ |
297 | |
298 | // now deal with the 2nd taskbar-related problem (see comments above in | |
299 | // MSWGetStyle()) | |
2b5f62a0 | 300 | if ( HasFlag(wxFRAME_NO_TASKBAR) && !hwndParent ) |
9dfef5ac | 301 | { |
2b5f62a0 VZ |
302 | // use hidden parent |
303 | hwndParent = wxTLWHiddenParentModule::GetHWND(); | |
9dfef5ac VZ |
304 | } |
305 | ||
2b5f62a0 | 306 | return (WXHWND)hwndParent; |
9dfef5ac VZ |
307 | } |
308 | ||
6e8515a3 | 309 | bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, |
b225f659 VZ |
310 | const wxString& title, |
311 | const wxPoint& pos, | |
312 | const wxSize& size) | |
313 | { | |
314 | #ifdef __WXMICROWIN__ | |
315 | // no dialogs support under MicroWin yet | |
316 | return CreateFrame(title, pos, size); | |
317 | #else // !__WXMICROWIN__ | |
318 | wxWindow *parent = GetParent(); | |
319 | ||
320 | // for the dialogs without wxDIALOG_NO_PARENT style, use the top level | |
321 | // app window as parent - this avoids creating modal dialogs without | |
322 | // parent | |
323 | if ( !parent && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) | |
324 | { | |
325 | parent = wxTheApp->GetTopWindow(); | |
e058b98d | 326 | |
39cc7a0b | 327 | if ( parent ) |
e058b98d | 328 | { |
39cc7a0b VZ |
329 | // don't use transient windows as parents, this is dangerous as it |
330 | // can lead to a crash if the parent is destroyed before the child | |
331 | // | |
332 | // also don't use the window which is currently hidden as then the | |
333 | // dialog would be hidden as well | |
334 | if ( (parent->GetExtraStyle() & wxWS_EX_TRANSIENT) || | |
335 | !parent->IsShown() ) | |
336 | { | |
337 | parent = NULL; | |
338 | } | |
e058b98d | 339 | } |
b225f659 VZ |
340 | } |
341 | ||
434005ca VZ |
342 | m_hWnd = (WXHWND)::CreateDialogIndirect |
343 | ( | |
344 | wxGetInstance(), | |
345 | (DLGTEMPLATE*)dlgTemplate, | |
346 | parent ? GetHwndOf(parent) : NULL, | |
347 | (DLGPROC)wxDlgProc | |
348 | ); | |
b225f659 VZ |
349 | |
350 | if ( !m_hWnd ) | |
351 | { | |
7e99eddf | 352 | wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?")); |
b225f659 | 353 | |
7e99eddf | 354 | wxLogSysError(wxT("Can't create dialog using memory template")); |
b225f659 VZ |
355 | |
356 | return FALSE; | |
357 | } | |
358 | ||
b2d5a7ee | 359 | WXDWORD exflags; |
b225f659 VZ |
360 | (void)MSWGetCreateWindowFlags(&exflags); |
361 | ||
362 | if ( exflags ) | |
363 | { | |
364 | ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exflags); | |
cef338d3 VZ |
365 | ::SetWindowPos(GetHwnd(), |
366 | exflags & WS_EX_TOPMOST ? HWND_TOPMOST : 0, | |
367 | 0, 0, 0, 0, | |
b225f659 VZ |
368 | SWP_NOSIZE | |
369 | SWP_NOMOVE | | |
cef338d3 | 370 | (exflags & WS_EX_TOPMOST ? 0 : SWP_NOZORDER) | |
b225f659 VZ |
371 | SWP_NOACTIVATE); |
372 | } | |
373 | ||
374 | #if defined(__WIN95__) | |
375 | // For some reason, the system menu is activated when we use the | |
376 | // WS_EX_CONTEXTHELP style, so let's set a reasonable icon | |
377 | if ( exflags & WS_EX_CONTEXTHELP ) | |
378 | { | |
379 | wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame); | |
380 | if ( winTop ) | |
381 | { | |
382 | wxIcon icon = winTop->GetIcon(); | |
383 | if ( icon.Ok() ) | |
384 | { | |
385 | ::SendMessage(GetHwnd(), WM_SETICON, | |
386 | (WPARAM)TRUE, | |
387 | (LPARAM)GetHiconOf(icon)); | |
388 | } | |
389 | } | |
390 | } | |
391 | #endif // __WIN95__ | |
392 | ||
393 | // move the dialog to its initial position without forcing repainting | |
394 | int x, y, w, h; | |
4c53c743 | 395 | if ( !MSWGetCreateWindowCoords(pos, size, x, y, w, h) ) |
b225f659 | 396 | { |
4c53c743 VZ |
397 | x = |
398 | w = (int)CW_USEDEFAULT; | |
399 | } | |
f04a0744 | 400 | |
4c53c743 VZ |
401 | // we can't use CW_USEDEFAULT here as we're not calling CreateWindow() |
402 | // and passing CW_USEDEFAULT to MoveWindow() results in resizing the | |
403 | // window to (0, 0) size which breaks quite a lot of things, e.g. the | |
404 | // sizer calculation in wxSizer::Fit() | |
405 | if ( w == (int)CW_USEDEFAULT ) | |
406 | { | |
407 | // the exact number doesn't matter, the dialog will be resized | |
408 | // again soon anyhow but it should be big enough to allow | |
409 | // calculation relying on "totalSize - clientSize > 0" work, i.e. | |
410 | // at least greater than the title bar height | |
411 | w = | |
412 | h = 100; | |
413 | } | |
f0adbe0f | 414 | |
4c53c743 VZ |
415 | if ( x == (int)CW_USEDEFAULT ) |
416 | { | |
417 | // centre it on the screen - what else can we do? | |
418 | wxSize sizeDpy = wxGetDisplaySize(); | |
419 | ||
420 | x = (sizeDpy.x - w) / 2; | |
421 | y = (sizeDpy.y - h) / 2; | |
422 | } | |
423 | ||
424 | if ( !::MoveWindow(GetHwnd(), x, y, w, h, FALSE) ) | |
425 | { | |
426 | wxLogLastError(wxT("MoveWindow")); | |
b225f659 | 427 | } |
b225f659 VZ |
428 | |
429 | if ( !title.empty() ) | |
430 | { | |
431 | ::SetWindowText(GetHwnd(), title); | |
432 | } | |
433 | ||
434 | SubclassWin(m_hWnd); | |
435 | ||
436 | return TRUE; | |
437 | #endif // __WXMICROWIN__/!__WXMICROWIN__ | |
438 | } | |
439 | ||
440 | bool wxTopLevelWindowMSW::CreateFrame(const wxString& title, | |
441 | const wxPoint& pos, | |
442 | const wxSize& size) | |
443 | { | |
b2d5a7ee VZ |
444 | WXDWORD exflags; |
445 | WXDWORD flags = MSWGetCreateWindowFlags(&exflags); | |
b225f659 VZ |
446 | |
447 | return MSWCreate(wxCanvasClassName, title, pos, size, flags, exflags); | |
82c9f85c VZ |
448 | } |
449 | ||
450 | bool wxTopLevelWindowMSW::Create(wxWindow *parent, | |
451 | wxWindowID id, | |
452 | const wxString& title, | |
453 | const wxPoint& pos, | |
454 | const wxSize& size, | |
455 | long style, | |
456 | const wxString& name) | |
457 | { | |
999836aa | 458 | bool ret wxDUMMY_INITIALIZE(false); |
9ca4dd06 | 459 | |
82c9f85c VZ |
460 | // init our fields |
461 | Init(); | |
462 | ||
463 | m_windowStyle = style; | |
464 | ||
465 | SetName(name); | |
466 | ||
467 | m_windowId = id == -1 ? NewControlId() : id; | |
468 | ||
469 | wxTopLevelWindows.Append(this); | |
470 | ||
471 | if ( parent ) | |
472 | parent->AddChild(this); | |
473 | ||
b225f659 VZ |
474 | if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG ) |
475 | { | |
b225f659 VZ |
476 | // we have different dialog templates to allows creation of dialogs |
477 | // with & without captions under MSWindows, resizeable or not (but a | |
478 | // resizeable dialog always has caption - otherwise it would look too | |
479 | // strange) | |
434005ca VZ |
480 | |
481 | // we need 3 additional WORDs for dialog menu, class and title (as we | |
482 | // don't use DS_SETFONT we don't need the fourth WORD for the font) | |
483 | static const int dlgsize = sizeof(DLGTEMPLATE) + (sizeof(WORD) * 3); | |
484 | DLGTEMPLATE *dlgTemplate = (DLGTEMPLATE *)malloc(dlgsize); | |
485 | memset(dlgTemplate, 0, dlgsize); | |
486 | ||
487 | // these values are arbitrary, they won't be used normally anyhow | |
6e8515a3 JS |
488 | dlgTemplate->x = 34; |
489 | dlgTemplate->y = 22; | |
490 | dlgTemplate->cx = 144; | |
491 | dlgTemplate->cy = 75; | |
492 | ||
434005ca VZ |
493 | // reuse the code in MSWGetStyle() but correct the results slightly for |
494 | // the dialog | |
495 | dlgTemplate->style = MSWGetStyle(style, NULL); | |
496 | ||
497 | // all dialogs are popups | |
498 | dlgTemplate->style |= WS_POPUP; | |
499 | ||
500 | // force 3D-look if necessary, it looks impossibly ugly otherwise | |
501 | if ( style & (wxRESIZE_BORDER | wxCAPTION) ) | |
502 | dlgTemplate->style |= DS_MODALFRAME; | |
b225f659 | 503 | |
9ca4dd06 | 504 | ret = CreateDialog(dlgTemplate, title, pos, size); |
6e8515a3 | 505 | free(dlgTemplate); |
b225f659 VZ |
506 | } |
507 | else // !dialog | |
508 | { | |
9ca4dd06 VS |
509 | ret = CreateFrame(title, pos, size); |
510 | } | |
511 | ||
512 | if ( ret && !(GetWindowStyleFlag() & wxCLOSE_BOX) ) | |
513 | { | |
514 | EnableCloseButton(false); | |
b225f659 | 515 | } |
9ca4dd06 VS |
516 | |
517 | return ret; | |
82c9f85c VZ |
518 | } |
519 | ||
520 | wxTopLevelWindowMSW::~wxTopLevelWindowMSW() | |
521 | { | |
82c9f85c VZ |
522 | if ( wxModelessWindows.Find(this) ) |
523 | wxModelessWindows.DeleteObject(this); | |
524 | ||
d6fb86a8 VZ |
525 | // after destroying an owned window, Windows activates the next top level |
526 | // window in Z order but it may be different from our owner (to reproduce | |
527 | // this simply Alt-TAB to another application and back before closing the | |
528 | // owned frame) whereas we always want to yield activation to our parent | |
529 | if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) ) | |
530 | { | |
531 | wxWindow *parent = GetParent(); | |
532 | if ( parent ) | |
533 | { | |
534 | ::BringWindowToTop(GetHwndOf(parent)); | |
535 | } | |
536 | } | |
82c9f85c VZ |
537 | } |
538 | ||
82c9f85c VZ |
539 | // ---------------------------------------------------------------------------- |
540 | // wxTopLevelWindowMSW showing | |
541 | // ---------------------------------------------------------------------------- | |
542 | ||
543 | void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd) | |
544 | { | |
545 | ::ShowWindow(GetHwnd(), nShowCmd); | |
546 | ||
547 | m_iconized = nShowCmd == SW_MINIMIZE; | |
548 | } | |
549 | ||
550 | bool wxTopLevelWindowMSW::Show(bool show) | |
551 | { | |
552 | // don't use wxWindow version as we want to call DoShowWindow() ourselves | |
553 | if ( !wxWindowBase::Show(show) ) | |
554 | return FALSE; | |
555 | ||
556 | int nShowCmd; | |
557 | if ( show ) | |
558 | { | |
559 | if ( m_maximizeOnShow ) | |
560 | { | |
561 | // show and maximize | |
562 | nShowCmd = SW_MAXIMIZE; | |
563 | ||
564 | m_maximizeOnShow = FALSE; | |
565 | } | |
566 | else // just show | |
567 | { | |
84cff965 JS |
568 | if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW ) |
569 | nShowCmd = SW_SHOWNA; | |
570 | else | |
571 | nShowCmd = SW_SHOW; | |
82c9f85c VZ |
572 | } |
573 | } | |
574 | else // hide | |
575 | { | |
576 | nShowCmd = SW_HIDE; | |
577 | } | |
578 | ||
579 | DoShowWindow(nShowCmd); | |
580 | ||
581 | if ( show ) | |
582 | { | |
583 | ::BringWindowToTop(GetHwnd()); | |
584 | ||
585 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); | |
586 | event.SetEventObject( this ); | |
587 | GetEventHandler()->ProcessEvent(event); | |
588 | } | |
589 | else // hide | |
590 | { | |
591 | // Try to highlight the correct window (the parent) | |
592 | if ( GetParent() ) | |
593 | { | |
594 | HWND hWndParent = GetHwndOf(GetParent()); | |
595 | if (hWndParent) | |
596 | ::BringWindowToTop(hWndParent); | |
597 | } | |
598 | } | |
599 | ||
600 | return TRUE; | |
601 | } | |
602 | ||
603 | // ---------------------------------------------------------------------------- | |
604 | // wxTopLevelWindowMSW maximize/minimize | |
605 | // ---------------------------------------------------------------------------- | |
606 | ||
607 | void wxTopLevelWindowMSW::Maximize(bool maximize) | |
608 | { | |
609 | if ( IsShown() ) | |
610 | { | |
611 | // just maximize it directly | |
612 | DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); | |
613 | } | |
614 | else // hidden | |
615 | { | |
616 | // we can't maximize the hidden frame because it shows it as well, so | |
617 | // just remember that we should do it later in this case | |
a0be434e | 618 | m_maximizeOnShow = maximize; |
82c9f85c VZ |
619 | } |
620 | } | |
621 | ||
622 | bool wxTopLevelWindowMSW::IsMaximized() const | |
623 | { | |
4676948b JS |
624 | #ifdef __WXWINCE__ |
625 | return FALSE; | |
626 | #else | |
82c9f85c | 627 | return ::IsZoomed(GetHwnd()) != 0; |
4676948b | 628 | #endif |
82c9f85c VZ |
629 | } |
630 | ||
631 | void wxTopLevelWindowMSW::Iconize(bool iconize) | |
632 | { | |
633 | DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); | |
634 | } | |
635 | ||
636 | bool wxTopLevelWindowMSW::IsIconized() const | |
637 | { | |
4676948b JS |
638 | #ifdef __WXWINCE__ |
639 | return FALSE; | |
640 | #else | |
82c9f85c VZ |
641 | // also update the current state |
642 | ((wxTopLevelWindowMSW *)this)->m_iconized = ::IsIconic(GetHwnd()) != 0; | |
643 | ||
644 | return m_iconized; | |
4676948b | 645 | #endif |
82c9f85c VZ |
646 | } |
647 | ||
648 | void wxTopLevelWindowMSW::Restore() | |
649 | { | |
650 | DoShowWindow(SW_RESTORE); | |
651 | } | |
652 | ||
c641b1d2 VS |
653 | // ---------------------------------------------------------------------------- |
654 | // wxTopLevelWindowMSW fullscreen | |
655 | // ---------------------------------------------------------------------------- | |
656 | ||
657 | bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style) | |
658 | { | |
716645d3 | 659 | if ( show == IsFullScreen() ) |
c641b1d2 | 660 | { |
716645d3 VZ |
661 | // nothing to do |
662 | return TRUE; | |
663 | } | |
664 | ||
665 | m_fsIsShowing = show; | |
c641b1d2 | 666 | |
716645d3 VZ |
667 | if ( show ) |
668 | { | |
c641b1d2 VS |
669 | m_fsStyle = style; |
670 | ||
671 | // zap the frame borders | |
672 | ||
673 | // save the 'normal' window style | |
716645d3 | 674 | m_fsOldWindowStyle = GetWindowLong(GetHwnd(), GWL_STYLE); |
c641b1d2 VS |
675 | |
676 | // save the old position, width & height, maximize state | |
677 | m_fsOldSize = GetRect(); | |
678 | m_fsIsMaximized = IsMaximized(); | |
679 | ||
680 | // decide which window style flags to turn off | |
681 | LONG newStyle = m_fsOldWindowStyle; | |
682 | LONG offFlags = 0; | |
683 | ||
684 | if (style & wxFULLSCREEN_NOBORDER) | |
4676948b JS |
685 | { |
686 | offFlags |= WS_BORDER; | |
687 | #ifndef __WXWINCE__ | |
688 | offFlags |= WS_THICKFRAME; | |
689 | #endif | |
690 | } | |
c641b1d2 | 691 | if (style & wxFULLSCREEN_NOCAPTION) |
716645d3 | 692 | offFlags |= WS_CAPTION | WS_SYSMENU; |
c641b1d2 | 693 | |
716645d3 | 694 | newStyle &= ~offFlags; |
c641b1d2 VS |
695 | |
696 | // change our window style to be compatible with full-screen mode | |
716645d3 | 697 | ::SetWindowLong(GetHwnd(), GWL_STYLE, newStyle); |
c641b1d2 | 698 | |
716645d3 VZ |
699 | wxRect rect; |
700 | #if wxUSE_DISPLAY | |
701 | // resize to the size of the display containing us | |
702 | int dpy = wxDisplay::GetFromWindow(this); | |
703 | if ( dpy != wxNOT_FOUND ) | |
704 | { | |
705 | rect = wxDisplay(dpy).GetGeometry(); | |
706 | } | |
707 | else // fall back to the main desktop | |
708 | #else // wxUSE_DISPLAY | |
709 | { | |
710 | // resize to the size of the desktop | |
711 | wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect); | |
80a81a12 JS |
712 | #ifdef __WXWINCE__ |
713 | // FIXME: size of the bottom menu (toolbar) | |
714 | // should be taken in account | |
715 | rect.height += rect.y; | |
716 | rect.y = 0; | |
4676948b | 717 | #endif |
716645d3 VZ |
718 | } |
719 | #endif // wxUSE_DISPLAY | |
c641b1d2 | 720 | |
716645d3 | 721 | SetSize(rect); |
c641b1d2 VS |
722 | |
723 | // now flush the window style cache and actually go full-screen | |
716645d3 | 724 | long flags = SWP_FRAMECHANGED; |
c641b1d2 | 725 | |
716645d3 VZ |
726 | // showing the frame full screen should also show it if it's still |
727 | // hidden | |
728 | if ( !IsShown() ) | |
729 | { | |
730 | // don't call wxWindow version to avoid flicker from calling | |
731 | // ::ShowWindow() -- we're going to show the window at the correct | |
732 | // location directly below -- but do call the wxWindowBase version | |
733 | // to sync the internal m_isShown flag | |
734 | wxWindowBase::Show(); | |
c641b1d2 | 735 | |
716645d3 VZ |
736 | flags |= SWP_SHOWWINDOW; |
737 | } | |
c641b1d2 | 738 | |
716645d3 VZ |
739 | SetWindowPos(GetHwnd(), HWND_TOP, |
740 | rect.x, rect.y, rect.width, rect.height, | |
741 | flags); | |
c641b1d2 | 742 | |
c0f98472 | 743 | #if defined(__WXWINCE__) && _WIN32_WCE < 400 |
80a81a12 JS |
744 | ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON); |
745 | #endif | |
746 | ||
716645d3 VZ |
747 | // finally send an event allowing the window to relayout itself &c |
748 | wxSizeEvent event(rect.GetSize(), GetId()); | |
749 | GetEventHandler()->ProcessEvent(event); | |
750 | } | |
751 | else // stop showing full screen | |
752 | { | |
c0f98472 | 753 | #if defined(__WXWINCE__) && _WIN32_WCE < 400 |
80a81a12 JS |
754 | ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON); |
755 | #endif | |
c641b1d2 | 756 | Maximize(m_fsIsMaximized); |
716645d3 VZ |
757 | SetWindowLong(GetHwnd(),GWL_STYLE, m_fsOldWindowStyle); |
758 | SetWindowPos(GetHwnd(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y, | |
c641b1d2 | 759 | m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED); |
c641b1d2 | 760 | } |
716645d3 VZ |
761 | |
762 | return TRUE; | |
c641b1d2 VS |
763 | } |
764 | ||
82c9f85c VZ |
765 | // ---------------------------------------------------------------------------- |
766 | // wxTopLevelWindowMSW misc | |
767 | // ---------------------------------------------------------------------------- | |
768 | ||
769 | void wxTopLevelWindowMSW::SetIcon(const wxIcon& icon) | |
770 | { | |
f618020a MB |
771 | SetIcons( wxIconBundle( icon ) ); |
772 | } | |
773 | ||
774 | void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons) | |
775 | { | |
776 | wxTopLevelWindowBase::SetIcons(icons); | |
82c9f85c VZ |
777 | |
778 | #if defined(__WIN95__) && !defined(__WXMICROWIN__) | |
f618020a MB |
779 | const wxIcon& sml = icons.GetIcon( wxSize( 16, 16 ) ); |
780 | if( sml.Ok() && sml.GetWidth() == 16 && sml.GetHeight() == 16 ) | |
781 | { | |
782 | ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_SMALL, | |
783 | (LPARAM)GetHiconOf(sml) ); | |
784 | } | |
785 | ||
786 | const wxIcon& big = icons.GetIcon( wxSize( 32, 32 ) ); | |
787 | if( big.Ok() && big.GetWidth() == 32 && big.GetHeight() == 32 ) | |
82c9f85c | 788 | { |
f618020a MB |
789 | ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_BIG, |
790 | (LPARAM)GetHiconOf(big) ); | |
82c9f85c VZ |
791 | } |
792 | #endif // __WIN95__ | |
793 | } | |
a91cf80c VZ |
794 | |
795 | bool wxTopLevelWindowMSW::EnableCloseButton(bool enable) | |
796 | { | |
4676948b | 797 | #if !defined(__WXMICROWIN__) |
a91cf80c | 798 | // get system (a.k.a. window) menu |
4676948b | 799 | HMENU hmenu = GetSystemMenu(GetHwnd(), FALSE /* get it */); |
a91cf80c VZ |
800 | if ( !hmenu ) |
801 | { | |
660b1906 VZ |
802 | // no system menu at all -- ok if we want to remove the close button |
803 | // anyhow, but bad if we want to show it | |
804 | return !enable; | |
a91cf80c VZ |
805 | } |
806 | ||
807 | // enabling/disabling the close item from it also automatically | |
808 | // disables/enables the close title bar button | |
aaf765a5 VZ |
809 | if ( ::EnableMenuItem(hmenu, SC_CLOSE, |
810 | MF_BYCOMMAND | | |
811 | (enable ? MF_ENABLED : MF_GRAYED)) == -1 ) | |
a91cf80c VZ |
812 | { |
813 | wxLogLastError(_T("EnableMenuItem(SC_CLOSE)")); | |
814 | ||
815 | return FALSE; | |
816 | } | |
817 | ||
818 | // update appearance immediately | |
819 | if ( !::DrawMenuBar(GetHwnd()) ) | |
820 | { | |
821 | wxLogLastError(_T("DrawMenuBar")); | |
822 | } | |
823 | #endif // !__WXMICROWIN__ | |
824 | ||
825 | return TRUE; | |
826 | } | |
827 | ||
1542ea39 RD |
828 | bool wxTopLevelWindowMSW::SetShape(const wxRegion& region) |
829 | { | |
4676948b JS |
830 | #ifdef __WXWINCE__ |
831 | return FALSE; | |
832 | #else | |
6a7e6411 RD |
833 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE, |
834 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); | |
835 | ||
1542ea39 RD |
836 | // The empty region signifies that the shape should be removed from the |
837 | // window. | |
838 | if ( region.IsEmpty() ) | |
839 | { | |
840 | if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0) | |
841 | { | |
842 | wxLogLastError(_T("SetWindowRgn")); | |
843 | return FALSE; | |
844 | } | |
845 | return TRUE; | |
846 | } | |
847 | ||
848 | // Windows takes ownership of the region, so | |
849 | // we'll have to make a copy of the region to give to it. | |
850 | DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL); | |
851 | RGNDATA *rgnData = (RGNDATA*) new char[noBytes]; | |
852 | ::GetRegionData(GetHrgnOf(region), noBytes, rgnData); | |
853 | HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData); | |
854 | delete[] (char*) rgnData; | |
855 | ||
856 | // SetWindowRgn expects the region to be in coordinants | |
857 | // relative to the window, not the client area. Figure | |
858 | // out the offset, if any. | |
859 | RECT rect; | |
860 | DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
861 | DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE); | |
862 | ::GetClientRect(GetHwnd(), &rect); | |
863 | ::AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle); | |
864 | ::OffsetRgn(hrgn, -rect.left, -rect.top); | |
865 | ||
866 | // Now call the shape API with the new region. | |
867 | if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0) | |
868 | { | |
869 | wxLogLastError(_T("SetWindowRgn")); | |
870 | return FALSE; | |
871 | } | |
872 | return TRUE; | |
4676948b | 873 | #endif |
1542ea39 RD |
874 | } |
875 | ||
085ad686 VZ |
876 | // ---------------------------------------------------------------------------- |
877 | // wxTopLevelWindow event handling | |
878 | // ---------------------------------------------------------------------------- | |
879 | ||
880 | // Default activation behaviour - set the focus for the first child | |
881 | // subwindow found. | |
882 | void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event) | |
883 | { | |
884 | if ( event.GetActive() ) | |
885 | { | |
2736a5de VZ |
886 | // restore focus to the child which was last focused unless we already |
887 | // have it | |
888 | wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd); | |
085ad686 | 889 | |
2736a5de VZ |
890 | wxWindow *winFocus = FindFocus(); |
891 | if ( !winFocus || wxGetTopLevelParent(winFocus) != this ) | |
085ad686 | 892 | { |
2736a5de VZ |
893 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() |
894 | : NULL; | |
895 | if ( !parent ) | |
896 | { | |
897 | parent = this; | |
898 | } | |
085ad686 | 899 | |
2736a5de VZ |
900 | wxSetFocusToChild(parent, &m_winLastFocused); |
901 | } | |
085ad686 VZ |
902 | } |
903 | else // deactivating | |
904 | { | |
905 | // remember the last focused child if it is our child | |
906 | m_winLastFocused = FindFocus(); | |
907 | ||
13834828 VZ |
908 | if ( m_winLastFocused ) |
909 | { | |
910 | // let it know that it doesn't have focus any more | |
77e00fe9 | 911 | m_winLastFocused->HandleKillFocus((WXHWND)NULL); |
13834828 | 912 | |
2736a5de VZ |
913 | // and don't remember it if it's a child from some other frame |
914 | if ( wxGetTopLevelParent(m_winLastFocused) != this ) | |
085ad686 | 915 | { |
2736a5de | 916 | m_winLastFocused = NULL; |
085ad686 | 917 | } |
085ad686 VZ |
918 | } |
919 | ||
920 | wxLogTrace(_T("focus"), | |
921 | _T("wxTLW %08x deactivated, last focused: %08x."), | |
9b601c24 GRG |
922 | (int) m_hWnd, |
923 | (int) (m_winLastFocused ? GetHwndOf(m_winLastFocused) | |
924 | : NULL)); | |
085ad686 VZ |
925 | |
926 | event.Skip(); | |
927 | } | |
928 | } | |
929 | ||
12447831 VZ |
930 | // the DialogProc for all wxWindows dialogs |
931 | LONG APIENTRY _EXPORT | |
2eb10e2a VZ |
932 | wxDlgProc(HWND WXUNUSED(hDlg), |
933 | UINT message, | |
934 | WPARAM WXUNUSED(wParam), | |
935 | LPARAM WXUNUSED(lParam)) | |
12447831 VZ |
936 | { |
937 | switch ( message ) | |
938 | { | |
939 | case WM_INITDIALOG: | |
940 | // for this message, returning TRUE tells system to set focus to | |
941 | // the first control in the dialog box, but as we set the focus | |
942 | // ourselves, we return FALSE from here as well, so fall through | |
943 | ||
944 | default: | |
945 | // for all the other ones, FALSE means that we didn't process the | |
946 | // message | |
947 | return FALSE; | |
948 | } | |
949 | } | |
950 | ||
2b5f62a0 VZ |
951 | // ============================================================================ |
952 | // wxTLWHiddenParentModule implementation | |
953 | // ============================================================================ | |
954 | ||
955 | HWND wxTLWHiddenParentModule::ms_hwnd = NULL; | |
956 | ||
957 | const wxChar *wxTLWHiddenParentModule::ms_className = NULL; | |
958 | ||
959 | bool wxTLWHiddenParentModule::OnInit() | |
960 | { | |
961 | ms_hwnd = NULL; | |
962 | ms_className = NULL; | |
963 | ||
964 | return TRUE; | |
965 | } | |
966 | ||
967 | void wxTLWHiddenParentModule::OnExit() | |
968 | { | |
969 | if ( ms_hwnd ) | |
970 | { | |
971 | if ( !::DestroyWindow(ms_hwnd) ) | |
972 | { | |
973 | wxLogLastError(_T("DestroyWindow(hidden TLW parent)")); | |
974 | } | |
975 | ||
976 | ms_hwnd = NULL; | |
977 | } | |
978 | ||
979 | if ( ms_className ) | |
980 | { | |
981 | if ( !::UnregisterClass(ms_className, wxGetInstance()) ) | |
982 | { | |
983 | wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")")); | |
984 | } | |
985 | ||
986 | ms_className = NULL; | |
987 | } | |
988 | } | |
989 | ||
990 | /* static */ | |
991 | HWND wxTLWHiddenParentModule::GetHWND() | |
992 | { | |
993 | if ( !ms_hwnd ) | |
994 | { | |
995 | if ( !ms_className ) | |
996 | { | |
997 | static const wxChar *HIDDEN_PARENT_CLASS = _T("wxTLWHiddenParent"); | |
998 | ||
999 | WNDCLASS wndclass; | |
1000 | wxZeroMemory(wndclass); | |
1001 | ||
1002 | wndclass.lpfnWndProc = DefWindowProc; | |
1003 | wndclass.hInstance = wxGetInstance(); | |
1004 | wndclass.lpszClassName = HIDDEN_PARENT_CLASS; | |
1005 | ||
1006 | if ( !::RegisterClass(&wndclass) ) | |
1007 | { | |
1008 | wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")")); | |
1009 | } | |
1010 | else | |
1011 | { | |
1012 | ms_className = HIDDEN_PARENT_CLASS; | |
1013 | } | |
1014 | } | |
1015 | ||
fda7962d | 1016 | ms_hwnd = ::CreateWindow(ms_className, wxEmptyString, 0, 0, 0, 0, 0, NULL, |
2b5f62a0 VZ |
1017 | (HMENU)NULL, wxGetInstance(), NULL); |
1018 | if ( !ms_hwnd ) | |
1019 | { | |
1020 | wxLogLastError(_T("CreateWindow(hidden TLW parent)")); | |
1021 | } | |
1022 | } | |
1023 | ||
1024 | return ms_hwnd; | |
1025 | } | |
1026 | ||
1542ea39 | 1027 |