]>
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) | |
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 | |
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 | ||
41 | #include "wx/msw/private.h" | |
42 | ||
7e25f59e VZ |
43 | #include "wx/popupwin.h" |
44 | ||
e121a72a MB |
45 | #ifndef ICON_BIG |
46 | #define ICON_BIG 1 | |
47 | #endif | |
48 | ||
49 | #ifndef ICON_SMALL | |
50 | #define ICON_SMALL 0 | |
51 | #endif | |
52 | ||
82c9f85c VZ |
53 | // ---------------------------------------------------------------------------- |
54 | // stubs for missing functions under MicroWindows | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
57 | #ifdef __WXMICROWIN__ | |
58 | ||
c67d6888 | 59 | // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; } |
82c9f85c VZ |
60 | static inline bool IsZoomed(HWND WXUNUSED(hwnd)) { return FALSE; } |
61 | ||
62 | #endif // __WXMICROWIN__ | |
63 | ||
12447831 VZ |
64 | // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter |
65 | // is not included by wxUniv build which does need wxDlgProc | |
61179e28 VZ |
66 | LONG APIENTRY _EXPORT |
67 | wxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); | |
68 | ||
82c9f85c VZ |
69 | // ---------------------------------------------------------------------------- |
70 | // globals | |
71 | // ---------------------------------------------------------------------------- | |
72 | ||
73 | // list of all frames and modeless dialogs | |
74 | wxWindowList wxModelessWindows; | |
75 | ||
b225f659 VZ |
76 | // the name of the default wxWindows class |
77 | extern const wxChar *wxCanvasClassName; | |
78 | ||
9dfef5ac VZ |
79 | // the hidden parent for wxFRAME_NO_TASKBAR unowned frames |
80 | wxWindow *wxTopLevelWindowMSW::ms_hiddenParent = NULL; | |
81 | ||
82c9f85c VZ |
82 | // ============================================================================ |
83 | // wxTopLevelWindowMSW implementation | |
84 | // ============================================================================ | |
85 | ||
085ad686 VZ |
86 | BEGIN_EVENT_TABLE(wxTopLevelWindowMSW, wxTopLevelWindowBase) |
87 | EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate) | |
88 | END_EVENT_TABLE() | |
89 | ||
82c9f85c VZ |
90 | // ---------------------------------------------------------------------------- |
91 | // wxTopLevelWindowMSW creation | |
92 | // ---------------------------------------------------------------------------- | |
93 | ||
94 | void wxTopLevelWindowMSW::Init() | |
95 | { | |
96 | m_iconized = | |
97 | m_maximizeOnShow = FALSE; | |
b225f659 VZ |
98 | |
99 | // unlike (almost?) all other windows, frames are created hidden | |
100 | m_isShown = FALSE; | |
c641b1d2 VS |
101 | |
102 | // Data to save/restore when calling ShowFullScreen | |
103 | m_fsStyle = 0; | |
104 | m_fsOldWindowStyle = 0; | |
105 | m_fsIsMaximized = FALSE; | |
106 | m_fsIsShowing = FALSE; | |
085ad686 VZ |
107 | |
108 | m_winLastFocused = (wxWindow *)NULL; | |
b225f659 VZ |
109 | } |
110 | ||
b2d5a7ee | 111 | WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const |
b225f659 | 112 | { |
b2d5a7ee VZ |
113 | // let the base class deal with the common styles but fix the ones which |
114 | // don't make sense for us (we also deal with the borders ourselves) | |
115 | WXDWORD msflags = wxWindow::MSWGetStyle | |
116 | ( | |
117 | (style & ~wxBORDER_MASK) | wxBORDER_NONE, exflags | |
118 | ) & ~WS_CHILD; | |
b225f659 VZ |
119 | |
120 | // first select the kind of window being created | |
dfb06c62 VZ |
121 | // |
122 | // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and | |
123 | // creates a window with both caption and border, hence we also test it | |
124 | // below in some other cases | |
0e082993 | 125 | if ( style & wxFRAME_TOOL_WINDOW ) |
b2d5a7ee | 126 | msflags |= WS_POPUP; |
b225f659 | 127 | else |
b2d5a7ee | 128 | msflags |= WS_OVERLAPPED; |
0e082993 VZ |
129 | |
130 | // border and caption styles | |
131 | if ( style & wxRESIZE_BORDER ) | |
132 | msflags |= WS_THICKFRAME; | |
133 | else if ( !(style & wxBORDER_NONE) ) | |
134 | msflags |= WS_BORDER; | |
dfb06c62 VZ |
135 | else |
136 | msflags |= WS_POPUP; | |
0e082993 VZ |
137 | |
138 | if ( style & wxCAPTION ) | |
139 | msflags |= WS_CAPTION; | |
dfb06c62 | 140 | else |
b225f659 | 141 | msflags |= WS_POPUP; |
b225f659 VZ |
142 | |
143 | // next translate the individual flags | |
144 | if ( style & wxMINIMIZE_BOX ) | |
145 | msflags |= WS_MINIMIZEBOX; | |
146 | if ( style & wxMAXIMIZE_BOX ) | |
147 | msflags |= WS_MAXIMIZEBOX; | |
b225f659 VZ |
148 | if ( style & wxSYSTEM_MENU ) |
149 | msflags |= WS_SYSMENU; | |
150 | if ( style & wxMINIMIZE ) | |
151 | msflags |= WS_MINIMIZE; | |
152 | if ( style & wxMAXIMIZE ) | |
153 | msflags |= WS_MAXIMIZE; | |
0e082993 | 154 | |
b225f659 VZ |
155 | // Keep this here because it saves recoding this function in wxTinyFrame |
156 | #if wxUSE_ITSY_BITSY && !defined(__WIN32__) | |
157 | if ( style & wxTINY_CAPTION_VERT ) | |
158 | msflags |= IBS_VERTCAPTION; | |
159 | if ( style & wxTINY_CAPTION_HORIZ ) | |
160 | msflags |= IBS_HORZCAPTION; | |
161 | #else | |
162 | if ( style & (wxTINY_CAPTION_VERT | wxTINY_CAPTION_HORIZ) ) | |
163 | msflags |= WS_CAPTION; | |
164 | #endif | |
165 | ||
166 | if ( exflags ) | |
167 | { | |
b225f659 | 168 | #if !defined(__WIN16__) && !defined(__SC__) |
35bf863b VZ |
169 | if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ) |
170 | { | |
9dfef5ac VZ |
171 | if ( style & wxFRAME_TOOL_WINDOW ) |
172 | { | |
173 | // create the palette-like window | |
35bf863b | 174 | *exflags |= WS_EX_TOOLWINDOW; |
9dfef5ac VZ |
175 | } |
176 | ||
177 | // We have to solve 2 different problems here: | |
178 | // | |
179 | // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the | |
180 | // taskbar even if they don't have a parent | |
181 | // | |
182 | // 2. frames without this style should appear in the taskbar even | |
183 | // if they're owned (Windows only puts non owned windows into | |
184 | // the taskbar normally) | |
185 | // | |
186 | // The second one is solved here by using WS_EX_APPWINDOW flag, the | |
187 | // first one is dealt with in our MSWGetParent() method | |
188 | // implementation | |
189 | if ( !(style & wxFRAME_NO_TASKBAR) && GetParent() ) | |
190 | { | |
191 | // need to force the frame to appear in the taskbar | |
35bf863b | 192 | *exflags |= WS_EX_APPWINDOW; |
9dfef5ac VZ |
193 | } |
194 | //else: nothing to do [here] | |
35bf863b VZ |
195 | } |
196 | #endif // !Win16 | |
b225f659 VZ |
197 | |
198 | if ( style & wxSTAY_ON_TOP ) | |
199 | *exflags |= WS_EX_TOPMOST; | |
200 | ||
201 | #ifdef __WIN32__ | |
b2d5a7ee | 202 | if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP ) |
68d02db3 | 203 | *exflags |= WS_EX_CONTEXTHELP; |
b225f659 VZ |
204 | #endif // __WIN32__ |
205 | } | |
206 | ||
207 | return msflags; | |
208 | } | |
209 | ||
9dfef5ac VZ |
210 | WXHWND wxTopLevelWindowMSW::MSWGetParent() const |
211 | { | |
212 | // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL | |
213 | // parent HWND or it would be always on top of its parent which is not what | |
214 | // we usually want (in fact, we only want it for frames with the | |
215 | // wxFRAME_FLOAT_ON_PARENT flag) | |
216 | wxWindow *parent; | |
217 | if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) ) | |
218 | { | |
219 | parent = GetParent(); | |
220 | ||
221 | // this flag doesn't make sense then and will be ignored | |
222 | wxASSERT_MSG( parent, | |
223 | _T("wxFRAME_FLOAT_ON_PARENT but no parent?") ); | |
224 | } | |
225 | else // don't float on parent, must not be owned | |
226 | { | |
227 | parent = NULL; | |
228 | } | |
229 | ||
230 | // now deal with the 2nd taskbar-related problem (see comments above in | |
231 | // MSWGetStyle()) | |
232 | if ( HasFlag(wxFRAME_NO_TASKBAR) && !parent ) | |
233 | { | |
234 | if ( !ms_hiddenParent ) | |
235 | { | |
236 | ms_hiddenParent = new wxTopLevelWindowMSW(NULL, -1, _T("")); | |
237 | ||
238 | // we shouldn't leave it in wxTopLevelWindows or we wouldn't | |
239 | // terminate the app when the last user-created frame is deleted -- | |
240 | // see ~wxTopLevelWindowMSW | |
241 | wxTopLevelWindows.DeleteObject(ms_hiddenParent); | |
242 | } | |
243 | ||
244 | parent = ms_hiddenParent; | |
245 | } | |
246 | ||
d285d708 | 247 | return parent ? parent->GetHWND() : WXHWND(NULL); |
9dfef5ac VZ |
248 | } |
249 | ||
6e8515a3 | 250 | bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, |
b225f659 VZ |
251 | const wxString& title, |
252 | const wxPoint& pos, | |
253 | const wxSize& size) | |
254 | { | |
255 | #ifdef __WXMICROWIN__ | |
256 | // no dialogs support under MicroWin yet | |
257 | return CreateFrame(title, pos, size); | |
258 | #else // !__WXMICROWIN__ | |
259 | wxWindow *parent = GetParent(); | |
260 | ||
261 | // for the dialogs without wxDIALOG_NO_PARENT style, use the top level | |
262 | // app window as parent - this avoids creating modal dialogs without | |
263 | // parent | |
264 | if ( !parent && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) | |
265 | { | |
266 | parent = wxTheApp->GetTopWindow(); | |
e058b98d | 267 | |
39cc7a0b | 268 | if ( parent ) |
e058b98d | 269 | { |
39cc7a0b VZ |
270 | // don't use transient windows as parents, this is dangerous as it |
271 | // can lead to a crash if the parent is destroyed before the child | |
272 | // | |
273 | // also don't use the window which is currently hidden as then the | |
274 | // dialog would be hidden as well | |
275 | if ( (parent->GetExtraStyle() & wxWS_EX_TRANSIENT) || | |
276 | !parent->IsShown() ) | |
277 | { | |
278 | parent = NULL; | |
279 | } | |
e058b98d | 280 | } |
b225f659 VZ |
281 | } |
282 | ||
434005ca VZ |
283 | m_hWnd = (WXHWND)::CreateDialogIndirect |
284 | ( | |
285 | wxGetInstance(), | |
286 | (DLGTEMPLATE*)dlgTemplate, | |
287 | parent ? GetHwndOf(parent) : NULL, | |
288 | (DLGPROC)wxDlgProc | |
289 | ); | |
b225f659 VZ |
290 | |
291 | if ( !m_hWnd ) | |
292 | { | |
6e8515a3 | 293 | wxFAIL_MSG(_("Failed to create dialog. Incorrect DLGTEMPLATE?")); |
b225f659 | 294 | |
6e8515a3 | 295 | wxLogSysError(_("Can't create dialog using memory template")); |
b225f659 VZ |
296 | |
297 | return FALSE; | |
298 | } | |
299 | ||
b2d5a7ee | 300 | WXDWORD exflags; |
b225f659 VZ |
301 | (void)MSWGetCreateWindowFlags(&exflags); |
302 | ||
303 | if ( exflags ) | |
304 | { | |
305 | ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exflags); | |
306 | ::SetWindowPos(GetHwnd(), NULL, 0, 0, 0, 0, | |
307 | SWP_NOSIZE | | |
308 | SWP_NOMOVE | | |
309 | SWP_NOZORDER | | |
310 | SWP_NOACTIVATE); | |
311 | } | |
312 | ||
313 | #if defined(__WIN95__) | |
314 | // For some reason, the system menu is activated when we use the | |
315 | // WS_EX_CONTEXTHELP style, so let's set a reasonable icon | |
316 | if ( exflags & WS_EX_CONTEXTHELP ) | |
317 | { | |
318 | wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame); | |
319 | if ( winTop ) | |
320 | { | |
321 | wxIcon icon = winTop->GetIcon(); | |
322 | if ( icon.Ok() ) | |
323 | { | |
324 | ::SendMessage(GetHwnd(), WM_SETICON, | |
325 | (WPARAM)TRUE, | |
326 | (LPARAM)GetHiconOf(icon)); | |
327 | } | |
328 | } | |
329 | } | |
330 | #endif // __WIN95__ | |
331 | ||
332 | // move the dialog to its initial position without forcing repainting | |
333 | int x, y, w, h; | |
4c53c743 | 334 | if ( !MSWGetCreateWindowCoords(pos, size, x, y, w, h) ) |
b225f659 | 335 | { |
4c53c743 VZ |
336 | x = |
337 | w = (int)CW_USEDEFAULT; | |
338 | } | |
f04a0744 | 339 | |
4c53c743 VZ |
340 | // we can't use CW_USEDEFAULT here as we're not calling CreateWindow() |
341 | // and passing CW_USEDEFAULT to MoveWindow() results in resizing the | |
342 | // window to (0, 0) size which breaks quite a lot of things, e.g. the | |
343 | // sizer calculation in wxSizer::Fit() | |
344 | if ( w == (int)CW_USEDEFAULT ) | |
345 | { | |
346 | // the exact number doesn't matter, the dialog will be resized | |
347 | // again soon anyhow but it should be big enough to allow | |
348 | // calculation relying on "totalSize - clientSize > 0" work, i.e. | |
349 | // at least greater than the title bar height | |
350 | w = | |
351 | h = 100; | |
352 | } | |
f0adbe0f | 353 | |
4c53c743 VZ |
354 | if ( x == (int)CW_USEDEFAULT ) |
355 | { | |
356 | // centre it on the screen - what else can we do? | |
357 | wxSize sizeDpy = wxGetDisplaySize(); | |
358 | ||
359 | x = (sizeDpy.x - w) / 2; | |
360 | y = (sizeDpy.y - h) / 2; | |
361 | } | |
362 | ||
363 | if ( !::MoveWindow(GetHwnd(), x, y, w, h, FALSE) ) | |
364 | { | |
365 | wxLogLastError(wxT("MoveWindow")); | |
b225f659 | 366 | } |
b225f659 VZ |
367 | |
368 | if ( !title.empty() ) | |
369 | { | |
370 | ::SetWindowText(GetHwnd(), title); | |
371 | } | |
372 | ||
373 | SubclassWin(m_hWnd); | |
374 | ||
375 | return TRUE; | |
376 | #endif // __WXMICROWIN__/!__WXMICROWIN__ | |
377 | } | |
378 | ||
379 | bool wxTopLevelWindowMSW::CreateFrame(const wxString& title, | |
380 | const wxPoint& pos, | |
381 | const wxSize& size) | |
382 | { | |
b2d5a7ee VZ |
383 | WXDWORD exflags; |
384 | WXDWORD flags = MSWGetCreateWindowFlags(&exflags); | |
b225f659 VZ |
385 | |
386 | return MSWCreate(wxCanvasClassName, title, pos, size, flags, exflags); | |
82c9f85c VZ |
387 | } |
388 | ||
389 | bool wxTopLevelWindowMSW::Create(wxWindow *parent, | |
390 | wxWindowID id, | |
391 | const wxString& title, | |
392 | const wxPoint& pos, | |
393 | const wxSize& size, | |
394 | long style, | |
395 | const wxString& name) | |
396 | { | |
397 | // init our fields | |
398 | Init(); | |
399 | ||
400 | m_windowStyle = style; | |
401 | ||
402 | SetName(name); | |
403 | ||
404 | m_windowId = id == -1 ? NewControlId() : id; | |
405 | ||
406 | wxTopLevelWindows.Append(this); | |
407 | ||
408 | if ( parent ) | |
409 | parent->AddChild(this); | |
410 | ||
b225f659 VZ |
411 | if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG ) |
412 | { | |
b225f659 VZ |
413 | // we have different dialog templates to allows creation of dialogs |
414 | // with & without captions under MSWindows, resizeable or not (but a | |
415 | // resizeable dialog always has caption - otherwise it would look too | |
416 | // strange) | |
434005ca VZ |
417 | |
418 | // we need 3 additional WORDs for dialog menu, class and title (as we | |
419 | // don't use DS_SETFONT we don't need the fourth WORD for the font) | |
420 | static const int dlgsize = sizeof(DLGTEMPLATE) + (sizeof(WORD) * 3); | |
421 | DLGTEMPLATE *dlgTemplate = (DLGTEMPLATE *)malloc(dlgsize); | |
422 | memset(dlgTemplate, 0, dlgsize); | |
423 | ||
424 | // these values are arbitrary, they won't be used normally anyhow | |
6e8515a3 JS |
425 | dlgTemplate->x = 34; |
426 | dlgTemplate->y = 22; | |
427 | dlgTemplate->cx = 144; | |
428 | dlgTemplate->cy = 75; | |
429 | ||
434005ca VZ |
430 | // reuse the code in MSWGetStyle() but correct the results slightly for |
431 | // the dialog | |
432 | dlgTemplate->style = MSWGetStyle(style, NULL); | |
433 | ||
434 | // all dialogs are popups | |
435 | dlgTemplate->style |= WS_POPUP; | |
436 | ||
437 | // force 3D-look if necessary, it looks impossibly ugly otherwise | |
438 | if ( style & (wxRESIZE_BORDER | wxCAPTION) ) | |
439 | dlgTemplate->style |= DS_MODALFRAME; | |
b225f659 | 440 | |
6e8515a3 JS |
441 | bool ret = CreateDialog(dlgTemplate, title, pos, size); |
442 | free(dlgTemplate); | |
434005ca | 443 | |
6e8515a3 | 444 | return ret; |
b225f659 VZ |
445 | } |
446 | else // !dialog | |
447 | { | |
448 | return CreateFrame(title, pos, size); | |
449 | } | |
82c9f85c VZ |
450 | } |
451 | ||
452 | wxTopLevelWindowMSW::~wxTopLevelWindowMSW() | |
453 | { | |
9dfef5ac VZ |
454 | if ( this == ms_hiddenParent ) |
455 | { | |
456 | // stop [infinite] recursion which would otherwise happen when we do | |
1cbee0b4 VZ |
457 | // "delete ms_hiddenParent" below -- and we're not interested in doing |
458 | // anything of the rest below for that window because the rest of | |
459 | // wxWindows doesn't even know about it | |
9dfef5ac VZ |
460 | return; |
461 | } | |
462 | ||
82c9f85c VZ |
463 | if ( wxModelessWindows.Find(this) ) |
464 | wxModelessWindows.DeleteObject(this); | |
465 | ||
d6fb86a8 VZ |
466 | // after destroying an owned window, Windows activates the next top level |
467 | // window in Z order but it may be different from our owner (to reproduce | |
468 | // this simply Alt-TAB to another application and back before closing the | |
469 | // owned frame) whereas we always want to yield activation to our parent | |
470 | if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) ) | |
471 | { | |
472 | wxWindow *parent = GetParent(); | |
473 | if ( parent ) | |
474 | { | |
475 | ::BringWindowToTop(GetHwndOf(parent)); | |
476 | } | |
477 | } | |
478 | ||
1cbee0b4 VZ |
479 | // if this is the last top-level window, we're going to exit and we should |
480 | // delete ms_hiddenParent now to avoid leaking it | |
481 | if ( IsLastBeforeExit() ) | |
82c9f85c | 482 | { |
9dfef5ac VZ |
483 | if ( ms_hiddenParent ) |
484 | { | |
485 | delete ms_hiddenParent; | |
486 | ms_hiddenParent = NULL; | |
487 | } | |
82c9f85c VZ |
488 | } |
489 | } | |
490 | ||
82c9f85c VZ |
491 | // ---------------------------------------------------------------------------- |
492 | // wxTopLevelWindowMSW showing | |
493 | // ---------------------------------------------------------------------------- | |
494 | ||
495 | void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd) | |
496 | { | |
497 | ::ShowWindow(GetHwnd(), nShowCmd); | |
498 | ||
499 | m_iconized = nShowCmd == SW_MINIMIZE; | |
500 | } | |
501 | ||
502 | bool wxTopLevelWindowMSW::Show(bool show) | |
503 | { | |
504 | // don't use wxWindow version as we want to call DoShowWindow() ourselves | |
505 | if ( !wxWindowBase::Show(show) ) | |
506 | return FALSE; | |
507 | ||
508 | int nShowCmd; | |
509 | if ( show ) | |
510 | { | |
511 | if ( m_maximizeOnShow ) | |
512 | { | |
513 | // show and maximize | |
514 | nShowCmd = SW_MAXIMIZE; | |
515 | ||
516 | m_maximizeOnShow = FALSE; | |
517 | } | |
518 | else // just show | |
519 | { | |
520 | nShowCmd = SW_SHOW; | |
521 | } | |
522 | } | |
523 | else // hide | |
524 | { | |
525 | nShowCmd = SW_HIDE; | |
526 | } | |
527 | ||
528 | DoShowWindow(nShowCmd); | |
529 | ||
530 | if ( show ) | |
531 | { | |
532 | ::BringWindowToTop(GetHwnd()); | |
533 | ||
534 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); | |
535 | event.SetEventObject( this ); | |
536 | GetEventHandler()->ProcessEvent(event); | |
537 | } | |
538 | else // hide | |
539 | { | |
540 | // Try to highlight the correct window (the parent) | |
541 | if ( GetParent() ) | |
542 | { | |
543 | HWND hWndParent = GetHwndOf(GetParent()); | |
544 | if (hWndParent) | |
545 | ::BringWindowToTop(hWndParent); | |
546 | } | |
547 | } | |
548 | ||
549 | return TRUE; | |
550 | } | |
551 | ||
552 | // ---------------------------------------------------------------------------- | |
553 | // wxTopLevelWindowMSW maximize/minimize | |
554 | // ---------------------------------------------------------------------------- | |
555 | ||
556 | void wxTopLevelWindowMSW::Maximize(bool maximize) | |
557 | { | |
558 | if ( IsShown() ) | |
559 | { | |
560 | // just maximize it directly | |
561 | DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); | |
562 | } | |
563 | else // hidden | |
564 | { | |
565 | // we can't maximize the hidden frame because it shows it as well, so | |
566 | // just remember that we should do it later in this case | |
567 | m_maximizeOnShow = TRUE; | |
568 | } | |
569 | } | |
570 | ||
571 | bool wxTopLevelWindowMSW::IsMaximized() const | |
572 | { | |
573 | return ::IsZoomed(GetHwnd()) != 0; | |
574 | } | |
575 | ||
576 | void wxTopLevelWindowMSW::Iconize(bool iconize) | |
577 | { | |
578 | DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); | |
579 | } | |
580 | ||
581 | bool wxTopLevelWindowMSW::IsIconized() const | |
582 | { | |
583 | // also update the current state | |
584 | ((wxTopLevelWindowMSW *)this)->m_iconized = ::IsIconic(GetHwnd()) != 0; | |
585 | ||
586 | return m_iconized; | |
587 | } | |
588 | ||
589 | void wxTopLevelWindowMSW::Restore() | |
590 | { | |
591 | DoShowWindow(SW_RESTORE); | |
592 | } | |
593 | ||
c641b1d2 VS |
594 | // ---------------------------------------------------------------------------- |
595 | // wxTopLevelWindowMSW fullscreen | |
596 | // ---------------------------------------------------------------------------- | |
597 | ||
598 | bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style) | |
599 | { | |
600 | if (show) | |
601 | { | |
602 | if (IsFullScreen()) | |
603 | return FALSE; | |
604 | ||
605 | m_fsIsShowing = TRUE; | |
606 | m_fsStyle = style; | |
607 | ||
608 | // zap the frame borders | |
609 | ||
610 | // save the 'normal' window style | |
611 | m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE); | |
612 | ||
613 | // save the old position, width & height, maximize state | |
614 | m_fsOldSize = GetRect(); | |
615 | m_fsIsMaximized = IsMaximized(); | |
616 | ||
617 | // decide which window style flags to turn off | |
618 | LONG newStyle = m_fsOldWindowStyle; | |
619 | LONG offFlags = 0; | |
620 | ||
621 | if (style & wxFULLSCREEN_NOBORDER) | |
622 | offFlags |= WS_BORDER | WS_THICKFRAME; | |
623 | if (style & wxFULLSCREEN_NOCAPTION) | |
624 | offFlags |= (WS_CAPTION | WS_SYSMENU); | |
625 | ||
626 | newStyle &= (~offFlags); | |
627 | ||
628 | // change our window style to be compatible with full-screen mode | |
629 | ::SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle); | |
630 | ||
631 | // resize to the size of the desktop | |
632 | int width, height; | |
633 | ||
634 | RECT rect = wxGetWindowRect(::GetDesktopWindow()); | |
635 | width = rect.right - rect.left; | |
636 | height = rect.bottom - rect.top; | |
637 | ||
638 | SetSize(width, height); | |
639 | ||
640 | // now flush the window style cache and actually go full-screen | |
641 | SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED); | |
642 | ||
643 | wxSizeEvent event(wxSize(width, height), GetId()); | |
644 | GetEventHandler()->ProcessEvent(event); | |
645 | ||
646 | return TRUE; | |
647 | } | |
648 | else | |
649 | { | |
650 | if (!IsFullScreen()) | |
651 | return FALSE; | |
652 | ||
653 | m_fsIsShowing = FALSE; | |
654 | ||
655 | Maximize(m_fsIsMaximized); | |
656 | SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle); | |
657 | SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y, | |
658 | m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED); | |
659 | ||
660 | return TRUE; | |
661 | } | |
662 | } | |
663 | ||
82c9f85c VZ |
664 | // ---------------------------------------------------------------------------- |
665 | // wxTopLevelWindowMSW misc | |
666 | // ---------------------------------------------------------------------------- | |
667 | ||
668 | void wxTopLevelWindowMSW::SetIcon(const wxIcon& icon) | |
669 | { | |
f618020a MB |
670 | SetIcons( wxIconBundle( icon ) ); |
671 | } | |
672 | ||
673 | void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons) | |
674 | { | |
675 | wxTopLevelWindowBase::SetIcons(icons); | |
82c9f85c VZ |
676 | |
677 | #if defined(__WIN95__) && !defined(__WXMICROWIN__) | |
f618020a MB |
678 | const wxIcon& sml = icons.GetIcon( wxSize( 16, 16 ) ); |
679 | if( sml.Ok() && sml.GetWidth() == 16 && sml.GetHeight() == 16 ) | |
680 | { | |
681 | ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_SMALL, | |
682 | (LPARAM)GetHiconOf(sml) ); | |
683 | } | |
684 | ||
685 | const wxIcon& big = icons.GetIcon( wxSize( 32, 32 ) ); | |
686 | if( big.Ok() && big.GetWidth() == 32 && big.GetHeight() == 32 ) | |
82c9f85c | 687 | { |
f618020a MB |
688 | ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_BIG, |
689 | (LPARAM)GetHiconOf(big) ); | |
82c9f85c VZ |
690 | } |
691 | #endif // __WIN95__ | |
692 | } | |
a91cf80c VZ |
693 | |
694 | bool wxTopLevelWindowMSW::EnableCloseButton(bool enable) | |
695 | { | |
696 | #ifndef __WXMICROWIN__ | |
697 | // get system (a.k.a. window) menu | |
698 | HMENU hmenu = ::GetSystemMenu(GetHwnd(), FALSE /* get it */); | |
699 | if ( !hmenu ) | |
700 | { | |
701 | wxLogLastError(_T("GetSystemMenu")); | |
702 | ||
703 | return FALSE; | |
704 | } | |
705 | ||
706 | // enabling/disabling the close item from it also automatically | |
707 | // disables/enables the close title bar button | |
aaf765a5 VZ |
708 | if ( ::EnableMenuItem(hmenu, SC_CLOSE, |
709 | MF_BYCOMMAND | | |
710 | (enable ? MF_ENABLED : MF_GRAYED)) == -1 ) | |
a91cf80c VZ |
711 | { |
712 | wxLogLastError(_T("EnableMenuItem(SC_CLOSE)")); | |
713 | ||
714 | return FALSE; | |
715 | } | |
716 | ||
717 | // update appearance immediately | |
718 | if ( !::DrawMenuBar(GetHwnd()) ) | |
719 | { | |
720 | wxLogLastError(_T("DrawMenuBar")); | |
721 | } | |
722 | #endif // !__WXMICROWIN__ | |
723 | ||
724 | return TRUE; | |
725 | } | |
726 | ||
085ad686 VZ |
727 | // ---------------------------------------------------------------------------- |
728 | // wxTopLevelWindow event handling | |
729 | // ---------------------------------------------------------------------------- | |
730 | ||
731 | // Default activation behaviour - set the focus for the first child | |
732 | // subwindow found. | |
733 | void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event) | |
734 | { | |
735 | if ( event.GetActive() ) | |
736 | { | |
737 | // restore focus to the child which was last focused | |
9b601c24 | 738 | wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd); |
085ad686 VZ |
739 | |
740 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() | |
741 | : NULL; | |
742 | if ( !parent ) | |
743 | { | |
744 | parent = this; | |
745 | } | |
746 | ||
747 | wxSetFocusToChild(parent, &m_winLastFocused); | |
748 | } | |
749 | else // deactivating | |
750 | { | |
751 | // remember the last focused child if it is our child | |
752 | m_winLastFocused = FindFocus(); | |
753 | ||
754 | // so we NULL it out if it's a child from some other frame | |
755 | wxWindow *win = m_winLastFocused; | |
756 | while ( win ) | |
757 | { | |
758 | if ( win->IsTopLevel() ) | |
759 | { | |
760 | if ( win != this ) | |
761 | { | |
762 | m_winLastFocused = NULL; | |
763 | } | |
764 | ||
765 | break; | |
766 | } | |
767 | ||
768 | win = win->GetParent(); | |
769 | } | |
770 | ||
771 | wxLogTrace(_T("focus"), | |
772 | _T("wxTLW %08x deactivated, last focused: %08x."), | |
9b601c24 GRG |
773 | (int) m_hWnd, |
774 | (int) (m_winLastFocused ? GetHwndOf(m_winLastFocused) | |
775 | : NULL)); | |
085ad686 VZ |
776 | |
777 | event.Skip(); | |
778 | } | |
779 | } | |
780 | ||
12447831 VZ |
781 | // the DialogProc for all wxWindows dialogs |
782 | LONG APIENTRY _EXPORT | |
783 | wxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) | |
784 | { | |
785 | switch ( message ) | |
786 | { | |
787 | case WM_INITDIALOG: | |
788 | // for this message, returning TRUE tells system to set focus to | |
789 | // the first control in the dialog box, but as we set the focus | |
790 | // ourselves, we return FALSE from here as well, so fall through | |
791 | ||
792 | default: | |
793 | // for all the other ones, FALSE means that we didn't process the | |
794 | // message | |
795 | return FALSE; | |
796 | } | |
797 | } | |
798 |