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