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