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