]>
Commit | Line | Data |
---|---|---|
82c9f85c | 1 | /////////////////////////////////////////////////////////////////////////////// |
faa49bfd | 2 | // Name: src/msw/toplevel.cpp |
82c9f85c VZ |
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) | |
526954c5 | 9 | // Licence: wxWindows licence |
82c9f85c VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
82c9f85c VZ |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
1832043f WS |
27 | #include "wx/toplevel.h" |
28 | ||
82c9f85c | 29 | #ifndef WX_PRECOMP |
3a922bb4 | 30 | #include "wx/app.h" |
28b68852 | 31 | #include "wx/dialog.h" |
82c9f85c VZ |
32 | #include "wx/string.h" |
33 | #include "wx/log.h" | |
34 | #include "wx/intl.h" | |
14dd645e | 35 | #include "wx/frame.h" |
04f1f9b7 | 36 | #include "wx/menu.h" |
706d74ab | 37 | #include "wx/containr.h" // wxSetFocusToChild() |
02761f6c | 38 | #include "wx/module.h" |
82c9f85c VZ |
39 | #endif //WX_PRECOMP |
40 | ||
dc92adaf | 41 | #include "wx/dynlib.h" |
2b5f62a0 | 42 | |
82c9f85c | 43 | #include "wx/msw/private.h" |
3d487566 | 44 | #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) |
02761f6c WS |
45 | #include <ole2.h> |
46 | #include <shellapi.h> | |
47 | // Standard SDK doesn't have aygshell.dll: see include/wx/msw/wince/libraries.h | |
48 | #if _WIN32_WCE < 400 || !defined(__WINCE_STANDARDSDK__) | |
49 | #include <aygshell.h> | |
50 | #endif | |
80a81a12 JS |
51 | #endif |
52 | ||
4676948b | 53 | #include "wx/msw/winundef.h" |
a6c2e2c7 | 54 | #include "wx/msw/missing.h" |
4676948b | 55 | |
716645d3 | 56 | #include "wx/display.h" |
7e25f59e | 57 | |
e121a72a MB |
58 | #ifndef ICON_BIG |
59 | #define ICON_BIG 1 | |
60 | #endif | |
61 | ||
62 | #ifndef ICON_SMALL | |
63 | #define ICON_SMALL 0 | |
64 | #endif | |
65 | ||
82c9f85c VZ |
66 | // ---------------------------------------------------------------------------- |
67 | // stubs for missing functions under MicroWindows | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
70 | #ifdef __WXMICROWIN__ | |
71 | ||
bfbb0b4c WS |
72 | // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return false; } |
73 | static inline bool IsZoomed(HWND WXUNUSED(hwnd)) { return false; } | |
82c9f85c VZ |
74 | |
75 | #endif // __WXMICROWIN__ | |
76 | ||
12447831 VZ |
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 | |
61179e28 VZ |
79 | LONG APIENTRY _EXPORT |
80 | wxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam); | |
81 | ||
2b5f62a0 VZ |
82 | // ---------------------------------------------------------------------------- |
83 | // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a | |
84 | // module to ensure that the window is always deleted) | |
85 | // ---------------------------------------------------------------------------- | |
86 | ||
87 | class wxTLWHiddenParentModule : public wxModule | |
88 | { | |
89 | public: | |
90 | // module init/finalize | |
91 | virtual bool OnInit(); | |
92 | virtual void OnExit(); | |
93 | ||
94 | // get the hidden window (creates on demand) | |
95 | static HWND GetHWND(); | |
96 | ||
97 | private: | |
98 | // the HWND of the hidden parent | |
99 | static HWND ms_hwnd; | |
100 | ||
101 | // the class used to create it | |
102 | static const wxChar *ms_className; | |
103 | ||
104 | DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule) | |
105 | }; | |
106 | ||
107 | IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule, wxModule) | |
9dfef5ac | 108 | |
82c9f85c VZ |
109 | // ============================================================================ |
110 | // wxTopLevelWindowMSW implementation | |
111 | // ============================================================================ | |
112 | ||
085ad686 VZ |
113 | BEGIN_EVENT_TABLE(wxTopLevelWindowMSW, wxTopLevelWindowBase) |
114 | EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate) | |
115 | END_EVENT_TABLE() | |
116 | ||
82c9f85c VZ |
117 | // ---------------------------------------------------------------------------- |
118 | // wxTopLevelWindowMSW creation | |
119 | // ---------------------------------------------------------------------------- | |
120 | ||
121 | void wxTopLevelWindowMSW::Init() | |
122 | { | |
123 | m_iconized = | |
bfbb0b4c | 124 | m_maximizeOnShow = false; |
b225f659 | 125 | |
c641b1d2 VS |
126 | // Data to save/restore when calling ShowFullScreen |
127 | m_fsStyle = 0; | |
128 | m_fsOldWindowStyle = 0; | |
bfbb0b4c WS |
129 | m_fsIsMaximized = false; |
130 | m_fsIsShowing = false; | |
085ad686 | 131 | |
d3b9f782 | 132 | m_winLastFocused = NULL; |
fb8a56b7 | 133 | |
3180bc0e | 134 | #if defined(__SMARTPHONE__) && defined(__WXWINCE__) |
fb8a56b7 WS |
135 | m_MenuBarHWND = 0; |
136 | #endif | |
08b97268 WS |
137 | |
138 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) | |
139 | SHACTIVATEINFO* info = new SHACTIVATEINFO; | |
140 | wxZeroMemory(*info); | |
141 | info->cbSize = sizeof(SHACTIVATEINFO); | |
142 | ||
143 | m_activateInfo = (void*) info; | |
144 | #endif | |
ddae5262 VZ |
145 | |
146 | m_menuSystem = NULL; | |
b225f659 VZ |
147 | } |
148 | ||
b2d5a7ee | 149 | WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const |
b225f659 | 150 | { |
b2d5a7ee VZ |
151 | // let the base class deal with the common styles but fix the ones which |
152 | // don't make sense for us (we also deal with the borders ourselves) | |
153 | WXDWORD msflags = wxWindow::MSWGetStyle | |
154 | ( | |
155 | (style & ~wxBORDER_MASK) | wxBORDER_NONE, exflags | |
31e7e89f | 156 | ) & ~WS_CHILD & ~WS_VISIBLE; |
b225f659 | 157 | |
aa29eefa JS |
158 | // For some reason, WS_VISIBLE needs to be defined on creation for |
159 | // SmartPhone 2003. The title can fail to be displayed otherwise. | |
160 | #if defined(__SMARTPHONE__) || (defined(__WXWINCE__) && _WIN32_WCE < 400) | |
c1855476 | 161 | msflags |= WS_VISIBLE; |
aa29eefa | 162 | ((wxTopLevelWindowMSW*)this)->wxWindowBase::Show(true); |
c1855476 RR |
163 | #endif |
164 | ||
b225f659 | 165 | // first select the kind of window being created |
dfb06c62 VZ |
166 | // |
167 | // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and | |
0fcd3b92 VZ |
168 | // creates a window with both caption and border, hence we need to use |
169 | // WS_POPUP in a few cases just to avoid having caption/border which we | |
170 | // don't want | |
0e082993 VZ |
171 | |
172 | // border and caption styles | |
6f26f98e | 173 | if ( ( style & wxRESIZE_BORDER ) && !IsAlwaysMaximized()) |
0e082993 | 174 | msflags |= WS_THICKFRAME; |
f8d56830 JS |
175 | else if ( exflags && ((style & wxBORDER_DOUBLE) || (style & wxBORDER_RAISED)) ) |
176 | *exflags |= WS_EX_DLGMODALFRAME; | |
0e082993 VZ |
177 | else if ( !(style & wxBORDER_NONE) ) |
178 | msflags |= WS_BORDER; | |
9cce2fe2 | 179 | #ifndef __POCKETPC__ |
dfb06c62 VZ |
180 | else |
181 | msflags |= WS_POPUP; | |
82eda5ec | 182 | #endif |
0e082993 | 183 | |
9ceeecb9 | 184 | // normally we consider that all windows without a caption must be popups, |
f76858d8 VZ |
185 | // but CE is an exception: there windows normally do not have the caption |
186 | // but shouldn't be made popups as popups can't have menus and don't look | |
187 | // like normal windows anyhow | |
9ceeecb9 JS |
188 | |
189 | // TODO: Smartphone appears to like wxCAPTION, but we should check that | |
190 | // we need it. | |
191 | #if defined(__SMARTPHONE__) || !defined(__WXWINCE__) | |
0e082993 VZ |
192 | if ( style & wxCAPTION ) |
193 | msflags |= WS_CAPTION; | |
f76858d8 | 194 | #ifndef __WXWINCE__ |
dfb06c62 | 195 | else |
b225f659 | 196 | msflags |= WS_POPUP; |
f76858d8 | 197 | #endif // !__WXWINCE__ |
9ceeecb9 | 198 | #endif |
e5aa8b81 | 199 | |
b225f659 | 200 | // next translate the individual flags |
dc134969 VZ |
201 | |
202 | // WS_EX_CONTEXTHELP is incompatible with WS_MINIMIZEBOX and WS_MAXIMIZEBOX | |
203 | // and is ignored if we specify both of them, but chances are that if we | |
7ce6cc9b | 204 | // use wxWS_EX_CONTEXTHELP, we really do want to have the context help |
dc134969 VZ |
205 | // button while wxMINIMIZE/wxMAXIMIZE are included by default, so the help |
206 | // takes precedence | |
7ce6cc9b | 207 | if ( !(GetExtraStyle() & wxWS_EX_CONTEXTHELP) ) |
dc134969 VZ |
208 | { |
209 | if ( style & wxMINIMIZE_BOX ) | |
210 | msflags |= WS_MINIMIZEBOX; | |
211 | if ( style & wxMAXIMIZE_BOX ) | |
212 | msflags |= WS_MAXIMIZEBOX; | |
213 | } | |
9ceeecb9 | 214 | |
faa49bfd | 215 | #ifndef __WXWINCE__ |
2ccc5f11 VZ |
216 | // notice that if wxCLOSE_BOX is specified we need to use WS_SYSMENU too as |
217 | // otherwise the close box doesn't appear | |
218 | if ( style & (wxSYSTEM_MENU | wxCLOSE_BOX) ) | |
b225f659 | 219 | msflags |= WS_SYSMENU; |
2ccc5f11 | 220 | #endif // !__WXWINCE__ |
2a47cb1b | 221 | |
f76858d8 VZ |
222 | // NB: under CE these 2 styles are not supported currently, we should |
223 | // call Minimize()/Maximize() "manually" if we want to support them | |
b225f659 VZ |
224 | if ( style & wxMINIMIZE ) |
225 | msflags |= WS_MINIMIZE; | |
9ceeecb9 | 226 | |
b225f659 VZ |
227 | if ( style & wxMAXIMIZE ) |
228 | msflags |= WS_MAXIMIZE; | |
0e082993 | 229 | |
b225f659 | 230 | // Keep this here because it saves recoding this function in wxTinyFrame |
7282b067 | 231 | if ( style & wxTINY_CAPTION ) |
b225f659 | 232 | msflags |= WS_CAPTION; |
82eda5ec | 233 | |
b225f659 VZ |
234 | if ( exflags ) |
235 | { | |
f76858d8 | 236 | // there is no taskbar under CE, so omit all this |
45f27284 | 237 | #if !defined(__WXWINCE__) |
35bf863b VZ |
238 | if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ) |
239 | { | |
9dfef5ac VZ |
240 | if ( style & wxFRAME_TOOL_WINDOW ) |
241 | { | |
242 | // create the palette-like window | |
35bf863b | 243 | *exflags |= WS_EX_TOOLWINDOW; |
404a4d93 VZ |
244 | |
245 | // tool windows shouldn't appear on the taskbar (as documented) | |
246 | style |= wxFRAME_NO_TASKBAR; | |
9dfef5ac VZ |
247 | } |
248 | ||
249 | // We have to solve 2 different problems here: | |
250 | // | |
251 | // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the | |
252 | // taskbar even if they don't have a parent | |
253 | // | |
254 | // 2. frames without this style should appear in the taskbar even | |
255 | // if they're owned (Windows only puts non owned windows into | |
256 | // the taskbar normally) | |
257 | // | |
258 | // The second one is solved here by using WS_EX_APPWINDOW flag, the | |
259 | // first one is dealt with in our MSWGetParent() method | |
260 | // implementation | |
261 | if ( !(style & wxFRAME_NO_TASKBAR) && GetParent() ) | |
262 | { | |
263 | // need to force the frame to appear in the taskbar | |
35bf863b | 264 | *exflags |= WS_EX_APPWINDOW; |
9dfef5ac VZ |
265 | } |
266 | //else: nothing to do [here] | |
35bf863b | 267 | } |
b554cf63 | 268 | |
7ce6cc9b | 269 | if ( GetExtraStyle() & wxWS_EX_CONTEXTHELP ) |
b554cf63 | 270 | *exflags |= WS_EX_CONTEXTHELP; |
f76858d8 | 271 | #endif // !__WXWINCE__ |
b225f659 VZ |
272 | |
273 | if ( style & wxSTAY_ON_TOP ) | |
274 | *exflags |= WS_EX_TOPMOST; | |
b225f659 VZ |
275 | } |
276 | ||
277 | return msflags; | |
278 | } | |
279 | ||
9dfef5ac VZ |
280 | WXHWND wxTopLevelWindowMSW::MSWGetParent() const |
281 | { | |
282 | // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL | |
283 | // parent HWND or it would be always on top of its parent which is not what | |
284 | // we usually want (in fact, we only want it for frames with the | |
285 | // wxFRAME_FLOAT_ON_PARENT flag) | |
2b5f62a0 | 286 | HWND hwndParent = NULL; |
9dfef5ac VZ |
287 | if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) ) |
288 | { | |
2b5f62a0 | 289 | const wxWindow *parent = GetParent(); |
9dfef5ac | 290 | |
2b5f62a0 VZ |
291 | if ( !parent ) |
292 | { | |
293 | // this flag doesn't make sense then and will be ignored | |
9a83f860 | 294 | wxFAIL_MSG( wxT("wxFRAME_FLOAT_ON_PARENT but no parent?") ); |
2b5f62a0 VZ |
295 | } |
296 | else | |
297 | { | |
298 | hwndParent = GetHwndOf(parent); | |
299 | } | |
9dfef5ac | 300 | } |
2b5f62a0 | 301 | //else: don't float on parent, must not be owned |
9dfef5ac VZ |
302 | |
303 | // now deal with the 2nd taskbar-related problem (see comments above in | |
304 | // MSWGetStyle()) | |
2b5f62a0 | 305 | if ( HasFlag(wxFRAME_NO_TASKBAR) && !hwndParent ) |
9dfef5ac | 306 | { |
2b5f62a0 VZ |
307 | // use hidden parent |
308 | hwndParent = wxTLWHiddenParentModule::GetHWND(); | |
9dfef5ac VZ |
309 | } |
310 | ||
2b5f62a0 | 311 | return (WXHWND)hwndParent; |
9dfef5ac VZ |
312 | } |
313 | ||
b7e5ba8f JG |
314 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
315 | bool wxTopLevelWindowMSW::HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam) | |
316 | { | |
317 | SHACTIVATEINFO *info = (SHACTIVATEINFO*) m_activateInfo; | |
318 | if ( info ) | |
319 | { | |
1272e71b | 320 | SHHandleWMSettingChange(GetHwnd(), wParam, lParam, info); |
b7e5ba8f JG |
321 | } |
322 | ||
1272e71b | 323 | return wxWindowMSW::HandleSettingChange(wParam, lParam); |
b7e5ba8f JG |
324 | } |
325 | #endif | |
326 | ||
08b97268 WS |
327 | WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
328 | { | |
329 | WXLRESULT rc = 0; | |
330 | bool processed = false; | |
331 | ||
332 | switch ( message ) | |
333 | { | |
ddae5262 | 334 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
08b97268 WS |
335 | case WM_ACTIVATE: |
336 | { | |
337 | SHACTIVATEINFO* info = (SHACTIVATEINFO*) m_activateInfo; | |
338 | if (info) | |
339 | { | |
340 | DWORD flags = 0; | |
341 | if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) flags = SHA_INPUTDIALOG; | |
342 | SHHandleWMActivate(GetHwnd(), wParam, lParam, info, flags); | |
343 | } | |
344 | ||
345 | // This implicitly sends a wxEVT_ACTIVATE_APP event | |
346 | if (wxTheApp) | |
347 | wxTheApp->SetActive(wParam != 0, FindFocus()); | |
348 | ||
349 | break; | |
350 | } | |
08b97268 WS |
351 | case WM_HIBERNATE: |
352 | { | |
353 | if (wxTheApp) | |
354 | { | |
355 | wxActivateEvent event(wxEVT_HIBERNATE, true, wxID_ANY); | |
356 | event.SetEventObject(wxTheApp); | |
357 | processed = wxTheApp->ProcessEvent(event); | |
358 | } | |
359 | break; | |
360 | } | |
ddae5262 VZ |
361 | #endif // __SMARTPHONE__ || __POCKETPC__ |
362 | ||
363 | case WM_SYSCOMMAND: | |
ddae5262 VZ |
364 | { |
365 | // From MSDN: | |
366 | // | |
367 | // ... the four low-order bits of the wParam parameter are | |
368 | // used internally by the system. To obtain the correct | |
369 | // result when testing the value of wParam, an application | |
370 | // must combine the value 0xFFF0 with the wParam value by | |
371 | // using the bitwise AND operator. | |
372 | unsigned id = wParam & 0xfff0; | |
373 | ||
0c6dff03 VZ |
374 | // Preserve the focus when minimizing/restoring the window: we |
375 | // need to do it manually as DefWindowProc() doesn't appear to | |
376 | // do this for us for some reason (perhaps because we don't use | |
377 | // WM_NEXTDLGCTL for setting focus?). Moreover, our code in | |
378 | // OnActivate() doesn't work in this case as we receive the | |
379 | // deactivation event too late when the window is being | |
380 | // minimized and the focus is already NULL by then. Similarly, | |
381 | // we receive the activation event too early and restoring | |
382 | // focus in it fails because the window is still minimized. So | |
383 | // we need to do it here. | |
384 | if ( id == SC_MINIMIZE ) | |
385 | { | |
386 | // For minimization, it's simple enough: just save the | |
387 | // focus as usual. The important thing is that we're not | |
388 | // minimized yet, so this works correctly. | |
389 | DoSaveLastFocus(); | |
390 | } | |
391 | else if ( id == SC_RESTORE ) | |
392 | { | |
393 | // For restoring, it's trickier as DefWindowProc() sets | |
394 | // focus to the window itself. So run it first and restore | |
395 | // our saved focus only afterwards. | |
396 | processed = true; | |
397 | rc = wxTopLevelWindowBase::MSWWindowProc(message, | |
398 | wParam, lParam); | |
399 | ||
400 | DoRestoreLastFocus(); | |
401 | } | |
402 | ||
403 | #ifndef __WXUNIVERSAL__ | |
404 | // We need to generate events for the custom items added to the | |
405 | // system menu if it had been created (and presumably modified). | |
406 | // As SC_SIZE is the first of the system-defined commands, we | |
407 | // only do this for the custom commands before it and leave | |
408 | // SC_SIZE and everything after it to DefWindowProc(). | |
409 | if ( m_menuSystem && id < SC_SIZE ) | |
ddae5262 VZ |
410 | { |
411 | if ( m_menuSystem->MSWCommand(0 /* unused anyhow */, id) ) | |
412 | processed = true; | |
413 | } | |
fe62518e | 414 | #endif // #ifndef __WXUNIVERSAL__ |
0c6dff03 | 415 | } |
ddae5262 | 416 | break; |
08b97268 WS |
417 | } |
418 | ||
419 | if ( !processed ) | |
420 | rc = wxTopLevelWindowBase::MSWWindowProc(message, wParam, lParam); | |
421 | ||
422 | return rc; | |
423 | } | |
424 | ||
6e8515a3 | 425 | bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, |
b225f659 VZ |
426 | const wxString& title, |
427 | const wxPoint& pos, | |
428 | const wxSize& size) | |
429 | { | |
430 | #ifdef __WXMICROWIN__ | |
431 | // no dialogs support under MicroWin yet | |
432 | return CreateFrame(title, pos, size); | |
433 | #else // !__WXMICROWIN__ | |
8bda0ec6 | 434 | // static cast is valid as we're only ever called for dialogs |
4f73f25c | 435 | wxWindow * const |
cdc48273 | 436 | parent = static_cast<wxDialog *>(this)->GetParentForModalDialog(); |
b225f659 | 437 | |
434005ca VZ |
438 | m_hWnd = (WXHWND)::CreateDialogIndirect |
439 | ( | |
440 | wxGetInstance(), | |
441 | (DLGTEMPLATE*)dlgTemplate, | |
442 | parent ? GetHwndOf(parent) : NULL, | |
443 | (DLGPROC)wxDlgProc | |
444 | ); | |
b225f659 VZ |
445 | |
446 | if ( !m_hWnd ) | |
447 | { | |
7e99eddf | 448 | wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?")); |
b225f659 | 449 | |
7e99eddf | 450 | wxLogSysError(wxT("Can't create dialog using memory template")); |
b225f659 | 451 | |
bfbb0b4c | 452 | return false; |
b225f659 VZ |
453 | } |
454 | ||
b554cf63 | 455 | #if !defined(__WXWINCE__) |
b225f659 VZ |
456 | // For some reason, the system menu is activated when we use the |
457 | // WS_EX_CONTEXTHELP style, so let's set a reasonable icon | |
8e5dbcdd | 458 | if ( HasExtraStyle(wxWS_EX_CONTEXTHELP) ) |
b225f659 VZ |
459 | { |
460 | wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame); | |
461 | if ( winTop ) | |
462 | { | |
463 | wxIcon icon = winTop->GetIcon(); | |
a1b806b9 | 464 | if ( icon.IsOk() ) |
b225f659 VZ |
465 | { |
466 | ::SendMessage(GetHwnd(), WM_SETICON, | |
467 | (WPARAM)TRUE, | |
468 | (LPARAM)GetHiconOf(icon)); | |
469 | } | |
470 | } | |
471 | } | |
8e5dbcdd | 472 | #endif // !__WXWINCE__ |
b225f659 | 473 | |
8df14bed VS |
474 | if ( !title.empty() ) |
475 | { | |
476 | ::SetWindowText(GetHwnd(), title.wx_str()); | |
477 | } | |
478 | ||
479 | SubclassWin(m_hWnd); | |
480 | ||
5d8d4b66 | 481 | #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__) |
b225f659 VZ |
482 | // move the dialog to its initial position without forcing repainting |
483 | int x, y, w, h; | |
72a11184 | 484 | (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h); |
4c53c743 | 485 | |
26268100 RD |
486 | if ( x == (int)CW_USEDEFAULT ) |
487 | { | |
5d8d4b66 VZ |
488 | // Let the system position the window, just set its size. |
489 | ::SetWindowPos(GetHwnd(), 0, | |
490 | 0, 0, w, h, | |
7cb83a8b | 491 | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); |
26268100 | 492 | } |
5d8d4b66 | 493 | else // Move the window to the desired location and set its size too. |
4c53c743 | 494 | { |
5d8d4b66 VZ |
495 | if ( !::MoveWindow(GetHwnd(), x, y, w, h, FALSE) ) |
496 | { | |
497 | wxLogLastError(wxT("MoveWindow")); | |
498 | } | |
b225f659 | 499 | } |
5d8d4b66 | 500 | #endif // !__WXWINCE__ |
b225f659 | 501 | |
aa29eefa JS |
502 | #ifdef __SMARTPHONE__ |
503 | // Work around title non-display glitch | |
504 | Show(false); | |
faa49bfd | 505 | #endif |
b225f659 | 506 | |
bfbb0b4c | 507 | return true; |
b225f659 VZ |
508 | #endif // __WXMICROWIN__/!__WXMICROWIN__ |
509 | } | |
510 | ||
511 | bool wxTopLevelWindowMSW::CreateFrame(const wxString& title, | |
512 | const wxPoint& pos, | |
513 | const wxSize& size) | |
514 | { | |
b2d5a7ee VZ |
515 | WXDWORD exflags; |
516 | WXDWORD flags = MSWGetCreateWindowFlags(&exflags); | |
b225f659 | 517 | |
6fd54d58 | 518 | const wxSize sz = IsAlwaysMaximized() ? wxDefaultSize : size; |
6f26f98e | 519 | |
08a58133 | 520 | #ifndef __WXWINCE__ |
978af864 VZ |
521 | if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) |
522 | exflags |= WS_EX_LAYOUTRTL; | |
08a58133 | 523 | #endif |
978af864 | 524 | |
d9698bd4 VZ |
525 | return MSWCreate(MSWGetRegisteredClassName(), |
526 | title.wx_str(), pos, sz, flags, exflags); | |
82c9f85c VZ |
527 | } |
528 | ||
529 | bool wxTopLevelWindowMSW::Create(wxWindow *parent, | |
530 | wxWindowID id, | |
531 | const wxString& title, | |
532 | const wxPoint& pos, | |
533 | const wxSize& size, | |
534 | long style, | |
535 | const wxString& name) | |
536 | { | |
2a47cb1b VZ |
537 | wxSize sizeReal = size; |
538 | if ( !sizeReal.IsFullySpecified() ) | |
539 | { | |
540 | sizeReal.SetDefaults(GetDefaultSize()); | |
541 | } | |
82c9f85c | 542 | |
49c26530 VZ |
543 | // notice that we should append this window to wxTopLevelWindows list |
544 | // before calling CreateBase() as it behaves differently for TLW and | |
545 | // non-TLW windows | |
546 | wxTopLevelWindows.Append(this); | |
547 | ||
2973301f VZ |
548 | bool ret = CreateBase(parent, id, pos, sizeReal, style, name); |
549 | if ( !ret ) | |
550 | return false; | |
82c9f85c | 551 | |
82c9f85c VZ |
552 | if ( parent ) |
553 | parent->AddChild(this); | |
554 | ||
b225f659 VZ |
555 | if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG ) |
556 | { | |
b225f659 | 557 | // we have different dialog templates to allows creation of dialogs |
d13b34d3 DS |
558 | // with & without captions under MSWindows, resizable or not (but a |
559 | // resizable dialog always has caption - otherwise it would look too | |
b225f659 | 560 | // strange) |
434005ca VZ |
561 | |
562 | // we need 3 additional WORDs for dialog menu, class and title (as we | |
563 | // don't use DS_SETFONT we don't need the fourth WORD for the font) | |
564 | static const int dlgsize = sizeof(DLGTEMPLATE) + (sizeof(WORD) * 3); | |
565 | DLGTEMPLATE *dlgTemplate = (DLGTEMPLATE *)malloc(dlgsize); | |
566 | memset(dlgTemplate, 0, dlgsize); | |
567 | ||
568 | // these values are arbitrary, they won't be used normally anyhow | |
6e8515a3 JS |
569 | dlgTemplate->x = 34; |
570 | dlgTemplate->y = 22; | |
571 | dlgTemplate->cx = 144; | |
572 | dlgTemplate->cy = 75; | |
573 | ||
434005ca VZ |
574 | // reuse the code in MSWGetStyle() but correct the results slightly for |
575 | // the dialog | |
99ea81de VZ |
576 | // |
577 | // NB: we need a temporary variable as we can't pass pointer to | |
578 | // dwExtendedStyle directly, it's not aligned correctly for 64 bit | |
579 | // architectures | |
580 | WXDWORD dwExtendedStyle; | |
581 | dlgTemplate->style = MSWGetStyle(style, &dwExtendedStyle); | |
582 | dlgTemplate->dwExtendedStyle = dwExtendedStyle; | |
434005ca VZ |
583 | |
584 | // all dialogs are popups | |
585 | dlgTemplate->style |= WS_POPUP; | |
08a58133 WS |
586 | |
587 | #ifndef __WXWINCE__ | |
978af864 VZ |
588 | if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) |
589 | { | |
590 | dlgTemplate->dwExtendedStyle |= WS_EX_LAYOUTRTL; | |
591 | } | |
434005ca VZ |
592 | |
593 | // force 3D-look if necessary, it looks impossibly ugly otherwise | |
594 | if ( style & (wxRESIZE_BORDER | wxCAPTION) ) | |
595 | dlgTemplate->style |= DS_MODALFRAME; | |
9cce2fe2 | 596 | #endif |
b225f659 | 597 | |
2a47cb1b | 598 | ret = CreateDialog(dlgTemplate, title, pos, sizeReal); |
6e8515a3 | 599 | free(dlgTemplate); |
b225f659 VZ |
600 | } |
601 | else // !dialog | |
602 | { | |
2a47cb1b | 603 | ret = CreateFrame(title, pos, sizeReal); |
9ca4dd06 VS |
604 | } |
605 | ||
9ceeecb9 | 606 | #ifndef __WXWINCE__ |
9ca4dd06 VS |
607 | if ( ret && !(GetWindowStyleFlag() & wxCLOSE_BOX) ) |
608 | { | |
609 | EnableCloseButton(false); | |
b225f659 | 610 | } |
9ceeecb9 | 611 | #endif |
9ca4dd06 | 612 | |
d7e0024b VZ |
613 | // for standard dialogs the dialog manager generates WM_CHANGEUISTATE |
614 | // itself but for custom windows we have to do it ourselves in order to | |
615 | // make the keyboard indicators (such as underlines for accelerators and | |
616 | // focus rectangles) work under Win2k+ | |
bb655ead VZ |
617 | if ( ret ) |
618 | { | |
3ef092d6 | 619 | MSWUpdateUIState(UIS_INITIALIZE); |
bb655ead VZ |
620 | } |
621 | ||
f43255e8 WS |
622 | // Note: if we include PocketPC in this test, dialogs can fail to show up, |
623 | // for example the text entry dialog in the dialogs sample. Problem with Maximise()? | |
624 | #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__WINCE_STANDARDSDK__)) | |
6f26f98e | 625 | if ( ( style & wxMAXIMIZE ) || IsAlwaysMaximized() ) |
991420e6 WS |
626 | { |
627 | this->Maximize(); | |
628 | } | |
f43255e8 | 629 | #endif |
82eda5ec | 630 | |
3180bc0e | 631 | #if defined(__SMARTPHONE__) && defined(__WXWINCE__) |
fb8a56b7 WS |
632 | SetRightMenu(); // to nothing for initialization |
633 | #endif | |
634 | ||
9ca4dd06 | 635 | return ret; |
82c9f85c VZ |
636 | } |
637 | ||
638 | wxTopLevelWindowMSW::~wxTopLevelWindowMSW() | |
639 | { | |
ddae5262 VZ |
640 | delete m_menuSystem; |
641 | ||
c6212a0c VZ |
642 | SendDestroyEvent(); |
643 | ||
08b97268 WS |
644 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
645 | SHACTIVATEINFO* info = (SHACTIVATEINFO*) m_activateInfo; | |
646 | delete info; | |
647 | m_activateInfo = NULL; | |
648 | #endif | |
649 | ||
d6fb86a8 VZ |
650 | // after destroying an owned window, Windows activates the next top level |
651 | // window in Z order but it may be different from our owner (to reproduce | |
652 | // this simply Alt-TAB to another application and back before closing the | |
653 | // owned frame) whereas we always want to yield activation to our parent | |
654 | if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) ) | |
655 | { | |
656 | wxWindow *parent = GetParent(); | |
657 | if ( parent ) | |
658 | { | |
659 | ::BringWindowToTop(GetHwndOf(parent)); | |
660 | } | |
661 | } | |
82c9f85c VZ |
662 | } |
663 | ||
82c9f85c VZ |
664 | // ---------------------------------------------------------------------------- |
665 | // wxTopLevelWindowMSW showing | |
666 | // ---------------------------------------------------------------------------- | |
667 | ||
668 | void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd) | |
669 | { | |
670 | ::ShowWindow(GetHwnd(), nShowCmd); | |
671 | ||
af9c02ce VZ |
672 | // Hiding the window doesn't change its iconized state. |
673 | if ( nShowCmd != SW_HIDE ) | |
674 | { | |
675 | // Otherwise restoring, maximizing or showing the window normally also | |
676 | // makes it not iconized and only minimizing it does make it iconized. | |
677 | m_iconized = nShowCmd == SW_MINIMIZE; | |
678 | } | |
82c9f85c VZ |
679 | } |
680 | ||
dbc7ceb9 KO |
681 | void wxTopLevelWindowMSW::ShowWithoutActivating() |
682 | { | |
683 | if ( !wxWindowBase::Show(true) ) | |
335b5afa | 684 | return; |
fa5f4858 | 685 | |
dbc7ceb9 KO |
686 | DoShowWindow(SW_SHOWNA); |
687 | } | |
688 | ||
82c9f85c VZ |
689 | bool wxTopLevelWindowMSW::Show(bool show) |
690 | { | |
691 | // don't use wxWindow version as we want to call DoShowWindow() ourselves | |
692 | if ( !wxWindowBase::Show(show) ) | |
bfbb0b4c | 693 | return false; |
82c9f85c VZ |
694 | |
695 | int nShowCmd; | |
696 | if ( show ) | |
697 | { | |
698 | if ( m_maximizeOnShow ) | |
699 | { | |
700 | // show and maximize | |
701 | nShowCmd = SW_MAXIMIZE; | |
702 | ||
991420e6 | 703 | // This is necessary, or no window appears |
aa29eefa | 704 | #if defined( __WINCE_STANDARDSDK__) || defined(__SMARTPHONE__) |
991420e6 | 705 | DoShowWindow(SW_SHOW); |
a9928e9d JS |
706 | #endif |
707 | ||
bfbb0b4c | 708 | m_maximizeOnShow = false; |
82c9f85c | 709 | } |
7505b72e VZ |
710 | else if ( m_iconized ) |
711 | { | |
712 | // iconize and show | |
713 | nShowCmd = SW_MINIMIZE; | |
714 | } | |
82c9f85c VZ |
715 | else // just show |
716 | { | |
00f7f5a7 VZ |
717 | // we shouldn't use SW_SHOW which also activates the window for |
718 | // tool frames (as they shouldn't steal focus from the main window) | |
719 | // nor for the currently disabled windows as they would be enabled | |
720 | // as a side effect | |
721 | if ( HasFlag(wxFRAME_TOOL_WINDOW) || !IsEnabled() ) | |
722 | nShowCmd = SW_SHOWNA; | |
723 | else | |
724 | nShowCmd = SW_SHOW; | |
82c9f85c VZ |
725 | } |
726 | } | |
727 | else // hide | |
728 | { | |
729 | nShowCmd = SW_HIDE; | |
730 | } | |
731 | ||
9741fd45 | 732 | #if wxUSE_DEFERRED_SIZING |
e259ce57 VZ |
733 | // we only set pending size if we're maximized before being shown, now that |
734 | // we're shown we don't need it any more (it is reset in size event handler | |
735 | // for child windows but we have to do it ourselves for this parent window) | |
736 | // | |
737 | // make sure to reset it before actually showing the window as this will | |
738 | // generate WM_SIZE events and we want to use the correct client size from | |
739 | // them, not the size returned by WM_NCCALCSIZE in DoGetClientSize() which | |
740 | // turns out to be wrong for maximized windows (see #11762) | |
741 | m_pendingSize = wxDefaultSize; | |
9741fd45 | 742 | #endif // wxUSE_DEFERRED_SIZING |
e259ce57 | 743 | |
82c9f85c VZ |
744 | DoShowWindow(nShowCmd); |
745 | ||
a9928e9d JS |
746 | #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)) |
747 | // Addornments have to be added when the frame is the correct size | |
748 | wxFrame* frame = wxDynamicCast(this, wxFrame); | |
749 | if (frame && frame->GetMenuBar()) | |
750 | frame->GetMenuBar()->AddAdornments(GetWindowStyleFlag()); | |
751 | #endif | |
0567fdfc KH |
752 | |
753 | return true; | |
82c9f85c VZ |
754 | } |
755 | ||
7cee4f76 VZ |
756 | void wxTopLevelWindowMSW::Raise() |
757 | { | |
758 | ::SetForegroundWindow(GetHwnd()); | |
759 | } | |
760 | ||
82c9f85c VZ |
761 | // ---------------------------------------------------------------------------- |
762 | // wxTopLevelWindowMSW maximize/minimize | |
763 | // ---------------------------------------------------------------------------- | |
764 | ||
765 | void wxTopLevelWindowMSW::Maximize(bool maximize) | |
766 | { | |
767 | if ( IsShown() ) | |
768 | { | |
769 | // just maximize it directly | |
770 | DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); | |
771 | } | |
772 | else // hidden | |
773 | { | |
73c902d6 DS |
774 | // we can't maximize the hidden frame because it shows it as well, |
775 | // so just remember that we should do it later in this case | |
a0be434e | 776 | m_maximizeOnShow = maximize; |
ac2de323 | 777 | |
9741fd45 | 778 | #if wxUSE_DEFERRED_SIZING |
ac2de323 VZ |
779 | // after calling Maximize() the client code expects to get the frame |
780 | // "real" size and doesn't want to know that, because of implementation | |
781 | // details, the frame isn't really maximized yet but will be only once | |
782 | // it's shown, so return our size as it will be then in this case | |
7889b795 VZ |
783 | if ( maximize ) |
784 | { | |
6fd54d58 VZ |
785 | // we must only change pending size here, and not call SetSize() |
786 | // because otherwise Windows would think that this (full screen) | |
787 | // size is the natural size for the frame and so would use it when | |
788 | // the user clicks on "restore" title bar button instead of the | |
789 | // correct initial frame size | |
790 | // | |
791 | // NB: unfortunately we don't know which display we're on yet so we | |
792 | // have to use the default one | |
793 | m_pendingSize = wxGetClientDisplayRect().GetSize(); | |
7889b795 VZ |
794 | } |
795 | //else: can't do anything in this case, we don't have the old size | |
9741fd45 | 796 | #endif // wxUSE_DEFERRED_SIZING |
82c9f85c VZ |
797 | } |
798 | } | |
799 | ||
800 | bool wxTopLevelWindowMSW::IsMaximized() const | |
801 | { | |
979a0320 | 802 | return IsAlwaysMaximized() || |
a8e89343 JS |
803 | #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) && !defined(__WINCE_STANDARDSDK__) |
804 | ||
979a0320 | 805 | (::IsZoomed(GetHwnd()) != 0) || |
4676948b | 806 | #endif |
979a0320 | 807 | m_maximizeOnShow; |
82c9f85c VZ |
808 | } |
809 | ||
810 | void wxTopLevelWindowMSW::Iconize(bool iconize) | |
811 | { | |
57429bfd VZ |
812 | if ( iconize == m_iconized ) |
813 | { | |
814 | // Do nothing, in particular don't restore non-iconized windows when | |
815 | // Iconize(false) is called as this would wrongly un-maximize them. | |
816 | return; | |
817 | } | |
818 | ||
7505b72e VZ |
819 | if ( IsShown() ) |
820 | { | |
821 | // change the window state immediately | |
822 | DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); | |
823 | } | |
824 | else // hidden | |
825 | { | |
826 | // iconizing the window shouldn't show it so just remember that we need | |
827 | // to become iconized when shown later | |
828 | m_iconized = true; | |
829 | } | |
82c9f85c VZ |
830 | } |
831 | ||
832 | bool wxTopLevelWindowMSW::IsIconized() const | |
833 | { | |
4676948b | 834 | #ifdef __WXWINCE__ |
bfbb0b4c | 835 | return false; |
4676948b | 836 | #else |
7505b72e VZ |
837 | if ( !IsShown() ) |
838 | return m_iconized; | |
839 | ||
9f01395e VZ |
840 | // don't use m_iconized, it may be briefly out of sync with the real state |
841 | // as it's only modified when we receive a WM_SIZE and we could be called | |
842 | // from an event handler from one of the messages we receive before it, | |
843 | // such as WM_MOVE | |
844 | return ::IsIconic(GetHwnd()) != 0; | |
4676948b | 845 | #endif |
82c9f85c VZ |
846 | } |
847 | ||
848 | void wxTopLevelWindowMSW::Restore() | |
849 | { | |
850 | DoShowWindow(SW_RESTORE); | |
851 | } | |
852 | ||
978af864 VZ |
853 | void wxTopLevelWindowMSW::SetLayoutDirection(wxLayoutDirection dir) |
854 | { | |
855 | if ( dir == wxLayout_Default ) | |
856 | dir = wxTheApp->GetLayoutDirection(); | |
857 | ||
858 | if ( dir != wxLayout_Default ) | |
859 | wxTopLevelWindowBase::SetLayoutDirection(dir); | |
860 | } | |
861 | ||
d43eb2a0 VZ |
862 | // ---------------------------------------------------------------------------- |
863 | // wxTopLevelWindowMSW geometry | |
864 | // ---------------------------------------------------------------------------- | |
865 | ||
b7036299 WS |
866 | #ifndef __WXWINCE__ |
867 | ||
c5dc89a1 WS |
868 | void wxTopLevelWindowMSW::DoGetPosition(int *x, int *y) const |
869 | { | |
d43eb2a0 VZ |
870 | if ( IsIconized() ) |
871 | { | |
872 | WINDOWPLACEMENT wp; | |
873 | wp.length = sizeof(WINDOWPLACEMENT); | |
874 | if ( ::GetWindowPlacement(GetHwnd(), &wp) ) | |
875 | { | |
876 | RECT& rc = wp.rcNormalPosition; | |
877 | ||
878 | // the position returned by GetWindowPlacement() is in workspace | |
879 | // coordinates except for windows with WS_EX_TOOLWINDOW style | |
880 | if ( !HasFlag(wxFRAME_TOOL_WINDOW) ) | |
881 | { | |
882 | // we must use the correct display for the translation as the | |
883 | // task bar might be shown on one display but not the other one | |
884 | int n = wxDisplay::GetFromWindow(this); | |
885 | wxDisplay dpy(n == wxNOT_FOUND ? 0 : n); | |
886 | const wxPoint ptOfs = dpy.GetClientArea().GetPosition() - | |
887 | dpy.GetGeometry().GetPosition(); | |
888 | ||
889 | rc.left += ptOfs.x; | |
890 | rc.top += ptOfs.y; | |
891 | } | |
892 | ||
893 | if ( x ) | |
894 | *x = rc.left; | |
895 | if ( y ) | |
896 | *y = rc.top; | |
897 | ||
898 | return; | |
899 | } | |
900 | ||
9a83f860 | 901 | wxLogLastError(wxT("GetWindowPlacement")); |
d43eb2a0 VZ |
902 | } |
903 | //else: normal case | |
904 | ||
905 | wxTopLevelWindowBase::DoGetPosition(x, y); | |
906 | } | |
907 | ||
908 | void wxTopLevelWindowMSW::DoGetSize(int *width, int *height) const | |
909 | { | |
910 | if ( IsIconized() ) | |
911 | { | |
912 | WINDOWPLACEMENT wp; | |
913 | wp.length = sizeof(WINDOWPLACEMENT); | |
914 | if ( ::GetWindowPlacement(GetHwnd(), &wp) ) | |
915 | { | |
916 | const RECT& rc = wp.rcNormalPosition; | |
917 | ||
918 | if ( width ) | |
919 | *width = rc.right - rc.left; | |
920 | if ( height ) | |
921 | *height = rc.bottom - rc.top; | |
922 | ||
923 | return; | |
924 | } | |
925 | ||
9a83f860 | 926 | wxLogLastError(wxT("GetWindowPlacement")); |
d43eb2a0 VZ |
927 | } |
928 | //else: normal case | |
929 | ||
930 | wxTopLevelWindowBase::DoGetSize(width, height); | |
931 | } | |
932 | ||
c5dc89a1 WS |
933 | #endif // __WXWINCE__ |
934 | ||
fa5f4858 VZ |
935 | void |
936 | wxTopLevelWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos, | |
937 | const wxSize& size, | |
938 | int& x, int& y, | |
939 | int& w, int& h) const | |
940 | { | |
941 | // let the system position the window if no explicit position was specified | |
942 | if ( pos.x == wxDefaultCoord ) | |
943 | { | |
944 | // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we | |
945 | // can just as well set it to CW_USEDEFAULT as well | |
946 | x = | |
947 | y = CW_USEDEFAULT; | |
948 | } | |
949 | else | |
950 | { | |
951 | // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it | |
952 | // neither because it is not handled as a special value by Windows then | |
953 | // and so we have to choose some default value for it, even if a | |
954 | // completely arbitrary one | |
955 | static const int DEFAULT_Y = 200; | |
956 | ||
957 | x = pos.x; | |
958 | y = pos.y == wxDefaultCoord ? DEFAULT_Y : pos.y; | |
959 | } | |
960 | ||
961 | if ( size.x == wxDefaultCoord || size.y == wxDefaultCoord ) | |
962 | { | |
963 | // We don't use CW_USEDEFAULT here for several reasons: | |
964 | // | |
965 | // 1. It results in huge frames on modern screens (1000*800 is not | |
966 | // uncommon on my 1280*1024 screen) which is way too big for a half | |
967 | // empty frame of most of wxWidgets samples for example) | |
968 | // | |
969 | // 2. It is buggy for frames with wxFRAME_TOOL_WINDOW style for which | |
970 | // the default is for whatever reason 8*8 which breaks client <-> | |
971 | // window size calculations (it would be nice if it didn't, but it | |
972 | // does and the simplest way to fix it seemed to change the broken | |
973 | // default size anyhow) | |
974 | // | |
975 | // 3. There is just no advantage in doing it: with x and y it is | |
976 | // possible that [future versions of] Windows position the new top | |
977 | // level window in some smart way which we can't do, but we can | |
978 | // guess a reasonably good size for a new window just as well | |
979 | // ourselves | |
980 | // | |
981 | // The only exception is for the Windows CE platform where the system | |
982 | // does know better than we how should the windows be sized | |
983 | #ifdef _WIN32_WCE | |
984 | w = | |
985 | h = CW_USEDEFAULT; | |
986 | #else // !_WIN32_WCE | |
987 | wxSize sizeReal = size; | |
988 | sizeReal.SetDefaults(GetDefaultSize()); | |
989 | ||
990 | w = sizeReal.x; | |
991 | h = sizeReal.y; | |
992 | #endif // _WIN32_WCE/!_WIN32_WCE | |
993 | } | |
994 | else | |
995 | { | |
996 | w = size.x; | |
997 | h = size.y; | |
998 | } | |
999 | } | |
1000 | ||
c641b1d2 VS |
1001 | // ---------------------------------------------------------------------------- |
1002 | // wxTopLevelWindowMSW fullscreen | |
1003 | // ---------------------------------------------------------------------------- | |
1004 | ||
1005 | bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style) | |
1006 | { | |
716645d3 | 1007 | if ( show == IsFullScreen() ) |
c641b1d2 | 1008 | { |
716645d3 | 1009 | // nothing to do |
bfbb0b4c | 1010 | return true; |
716645d3 VZ |
1011 | } |
1012 | ||
1013 | m_fsIsShowing = show; | |
c641b1d2 | 1014 | |
716645d3 VZ |
1015 | if ( show ) |
1016 | { | |
c641b1d2 VS |
1017 | m_fsStyle = style; |
1018 | ||
1019 | // zap the frame borders | |
1020 | ||
1021 | // save the 'normal' window style | |
716645d3 | 1022 | m_fsOldWindowStyle = GetWindowLong(GetHwnd(), GWL_STYLE); |
c641b1d2 VS |
1023 | |
1024 | // save the old position, width & height, maximize state | |
1025 | m_fsOldSize = GetRect(); | |
1026 | m_fsIsMaximized = IsMaximized(); | |
1027 | ||
1028 | // decide which window style flags to turn off | |
1029 | LONG newStyle = m_fsOldWindowStyle; | |
1030 | LONG offFlags = 0; | |
1031 | ||
1032 | if (style & wxFULLSCREEN_NOBORDER) | |
4676948b JS |
1033 | { |
1034 | offFlags |= WS_BORDER; | |
1035 | #ifndef __WXWINCE__ | |
1036 | offFlags |= WS_THICKFRAME; | |
1037 | #endif | |
1038 | } | |
c641b1d2 | 1039 | if (style & wxFULLSCREEN_NOCAPTION) |
716645d3 | 1040 | offFlags |= WS_CAPTION | WS_SYSMENU; |
c641b1d2 | 1041 | |
716645d3 | 1042 | newStyle &= ~offFlags; |
c641b1d2 VS |
1043 | |
1044 | // change our window style to be compatible with full-screen mode | |
716645d3 | 1045 | ::SetWindowLong(GetHwnd(), GWL_STYLE, newStyle); |
c641b1d2 | 1046 | |
716645d3 VZ |
1047 | wxRect rect; |
1048 | #if wxUSE_DISPLAY | |
1049 | // resize to the size of the display containing us | |
1050 | int dpy = wxDisplay::GetFromWindow(this); | |
1051 | if ( dpy != wxNOT_FOUND ) | |
1052 | { | |
1053 | rect = wxDisplay(dpy).GetGeometry(); | |
1054 | } | |
1055 | else // fall back to the main desktop | |
86828e0f | 1056 | #endif // wxUSE_DISPLAY |
716645d3 VZ |
1057 | { |
1058 | // resize to the size of the desktop | |
1059 | wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect); | |
80a81a12 JS |
1060 | #ifdef __WXWINCE__ |
1061 | // FIXME: size of the bottom menu (toolbar) | |
1062 | // should be taken in account | |
1063 | rect.height += rect.y; | |
1064 | rect.y = 0; | |
4676948b | 1065 | #endif |
716645d3 | 1066 | } |
c641b1d2 | 1067 | |
716645d3 | 1068 | SetSize(rect); |
c641b1d2 VS |
1069 | |
1070 | // now flush the window style cache and actually go full-screen | |
716645d3 | 1071 | long flags = SWP_FRAMECHANGED; |
c641b1d2 | 1072 | |
716645d3 VZ |
1073 | // showing the frame full screen should also show it if it's still |
1074 | // hidden | |
1075 | if ( !IsShown() ) | |
1076 | { | |
1077 | // don't call wxWindow version to avoid flicker from calling | |
1078 | // ::ShowWindow() -- we're going to show the window at the correct | |
1079 | // location directly below -- but do call the wxWindowBase version | |
1080 | // to sync the internal m_isShown flag | |
1081 | wxWindowBase::Show(); | |
c641b1d2 | 1082 | |
716645d3 VZ |
1083 | flags |= SWP_SHOWWINDOW; |
1084 | } | |
c641b1d2 | 1085 | |
716645d3 VZ |
1086 | SetWindowPos(GetHwnd(), HWND_TOP, |
1087 | rect.x, rect.y, rect.width, rect.height, | |
1088 | flags); | |
c641b1d2 | 1089 | |
3d487566 | 1090 | #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400)) |
80a81a12 JS |
1091 | ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON); |
1092 | #endif | |
1093 | ||
716645d3 VZ |
1094 | // finally send an event allowing the window to relayout itself &c |
1095 | wxSizeEvent event(rect.GetSize(), GetId()); | |
df97a4ef | 1096 | event.SetEventObject(this); |
937013e0 | 1097 | HandleWindowEvent(event); |
716645d3 VZ |
1098 | } |
1099 | else // stop showing full screen | |
1100 | { | |
3d487566 | 1101 | #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400)) |
80a81a12 JS |
1102 | ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON); |
1103 | #endif | |
c641b1d2 | 1104 | Maximize(m_fsIsMaximized); |
716645d3 VZ |
1105 | SetWindowLong(GetHwnd(),GWL_STYLE, m_fsOldWindowStyle); |
1106 | SetWindowPos(GetHwnd(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y, | |
c641b1d2 | 1107 | m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED); |
c641b1d2 | 1108 | } |
716645d3 | 1109 | |
bfbb0b4c | 1110 | return true; |
c641b1d2 VS |
1111 | } |
1112 | ||
82c9f85c VZ |
1113 | // ---------------------------------------------------------------------------- |
1114 | // wxTopLevelWindowMSW misc | |
1115 | // ---------------------------------------------------------------------------- | |
1116 | ||
faa49bfd WS |
1117 | void wxTopLevelWindowMSW::SetTitle( const wxString& title) |
1118 | { | |
1119 | SetLabel(title); | |
1120 | } | |
1121 | ||
1122 | wxString wxTopLevelWindowMSW::GetTitle() const | |
1123 | { | |
1124 | return GetLabel(); | |
1125 | } | |
1126 | ||
0f278d77 | 1127 | bool wxTopLevelWindowMSW::DoSelectAndSetIcon(const wxIconBundle& icons, |
b9e66233 VZ |
1128 | int smX, |
1129 | int smY, | |
1130 | int i) | |
f618020a | 1131 | { |
b9e66233 | 1132 | const wxSize size(::GetSystemMetrics(smX), ::GetSystemMetrics(smY)); |
82c9f85c | 1133 | |
d928f019 | 1134 | wxIcon icon = icons.GetIcon(size, wxIconBundle::FALLBACK_NEAREST_LARGER); |
0f278d77 | 1135 | |
7fb5d9e4 VZ |
1136 | if ( !icon.IsOk() ) |
1137 | return false; | |
1138 | ||
1139 | ::SendMessage(GetHwnd(), WM_SETICON, i, (LPARAM)GetHiconOf(icon)); | |
1140 | return true; | |
b9e66233 | 1141 | } |
f618020a | 1142 | |
b9e66233 VZ |
1143 | void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons) |
1144 | { | |
1145 | wxTopLevelWindowBase::SetIcons(icons); | |
1146 | ||
13e451ae VS |
1147 | if ( icons.IsEmpty() ) |
1148 | { | |
1149 | // FIXME: SetIcons(wxNullIconBundle) should unset existing icons, | |
1150 | // but we currently don't do that | |
1151 | wxASSERT_MSG( m_icons.IsEmpty(), "unsetting icons doesn't work" ); | |
1152 | return; | |
1153 | } | |
1154 | ||
7fb5d9e4 VZ |
1155 | DoSelectAndSetIcon(icons, SM_CXSMICON, SM_CYSMICON, ICON_SMALL); |
1156 | DoSelectAndSetIcon(icons, SM_CXICON, SM_CYICON, ICON_BIG); | |
82c9f85c | 1157 | } |
a91cf80c VZ |
1158 | |
1159 | bool wxTopLevelWindowMSW::EnableCloseButton(bool enable) | |
1160 | { | |
4676948b | 1161 | #if !defined(__WXMICROWIN__) |
a91cf80c | 1162 | // get system (a.k.a. window) menu |
068959b9 | 1163 | HMENU hmenu = GetSystemMenu(GetHwnd(), FALSE /* get it */); |
a91cf80c VZ |
1164 | if ( !hmenu ) |
1165 | { | |
660b1906 VZ |
1166 | // no system menu at all -- ok if we want to remove the close button |
1167 | // anyhow, but bad if we want to show it | |
1168 | return !enable; | |
a91cf80c VZ |
1169 | } |
1170 | ||
1171 | // enabling/disabling the close item from it also automatically | |
1172 | // disables/enables the close title bar button | |
aaf765a5 VZ |
1173 | if ( ::EnableMenuItem(hmenu, SC_CLOSE, |
1174 | MF_BYCOMMAND | | |
1175 | (enable ? MF_ENABLED : MF_GRAYED)) == -1 ) | |
a91cf80c | 1176 | { |
9a83f860 | 1177 | wxLogLastError(wxT("EnableMenuItem(SC_CLOSE)")); |
a91cf80c | 1178 | |
bfbb0b4c | 1179 | return false; |
a91cf80c | 1180 | } |
960b193e | 1181 | #ifndef __WXWINCE__ |
a91cf80c VZ |
1182 | // update appearance immediately |
1183 | if ( !::DrawMenuBar(GetHwnd()) ) | |
1184 | { | |
9a83f860 | 1185 | wxLogLastError(wxT("DrawMenuBar")); |
a91cf80c | 1186 | } |
960b193e | 1187 | #endif |
a91cf80c VZ |
1188 | #endif // !__WXMICROWIN__ |
1189 | ||
bfbb0b4c | 1190 | return true; |
a91cf80c VZ |
1191 | } |
1192 | ||
dc92adaf VZ |
1193 | void wxTopLevelWindowMSW::RequestUserAttention(int flags) |
1194 | { | |
3a6b0a3e VZ |
1195 | // check if we can use FlashWindowEx(): unfortunately a simple test for |
1196 | // FLASHW_STOP doesn't work because MSVC6 headers do #define it but don't | |
1197 | // provide FlashWindowEx() declaration, so try to detect whether we have | |
1198 | // real headers for WINVER 0x0500 by checking for existence of a symbol not | |
1199 | // declated in MSVC6 header | |
a8ff046b | 1200 | #if defined(FLASHW_STOP) && defined(VK_XBUTTON1) && wxUSE_DYNLIB_CLASS |
dc92adaf VZ |
1201 | // available in the headers, check if it is supported by the system |
1202 | typedef BOOL (WINAPI *FlashWindowEx_t)(FLASHWINFO *pfwi); | |
3432c148 | 1203 | static FlashWindowEx_t s_pfnFlashWindowEx = NULL; |
dc92adaf VZ |
1204 | if ( !s_pfnFlashWindowEx ) |
1205 | { | |
9a83f860 | 1206 | wxDynamicLibrary dllUser32(wxT("user32.dll")); |
dc92adaf | 1207 | s_pfnFlashWindowEx = (FlashWindowEx_t) |
9a83f860 | 1208 | dllUser32.GetSymbol(wxT("FlashWindowEx")); |
dc92adaf | 1209 | |
3103e8a9 | 1210 | // we can safely unload user32.dll here, it's going to remain loaded as |
dc92adaf VZ |
1211 | // long as the program is running anyhow |
1212 | } | |
1213 | ||
1214 | if ( s_pfnFlashWindowEx ) | |
1215 | { | |
1216 | WinStruct<FLASHWINFO> fwi; | |
1217 | fwi.hwnd = GetHwnd(); | |
1218 | fwi.dwFlags = FLASHW_ALL; | |
1219 | if ( flags & wxUSER_ATTENTION_INFO ) | |
1220 | { | |
1221 | // just flash a few times | |
1222 | fwi.uCount = 3; | |
1223 | } | |
1224 | else // wxUSER_ATTENTION_ERROR | |
1225 | { | |
1226 | // flash until the user notices it | |
1227 | fwi.dwFlags |= FLASHW_TIMERNOFG; | |
1228 | } | |
1229 | ||
1230 | s_pfnFlashWindowEx(&fwi); | |
1231 | } | |
1232 | else // FlashWindowEx() not available | |
4f79eb79 | 1233 | #endif // FlashWindowEx() defined |
dc92adaf VZ |
1234 | { |
1235 | wxUnusedVar(flags); | |
068959b9 | 1236 | #ifndef __WXWINCE__ |
dc92adaf | 1237 | ::FlashWindow(GetHwnd(), TRUE); |
068959b9 | 1238 | #endif // __WXWINCE__ |
dc92adaf VZ |
1239 | } |
1240 | } | |
1241 | ||
ddae5262 VZ |
1242 | wxMenu *wxTopLevelWindowMSW::MSWGetSystemMenu() const |
1243 | { | |
fe62518e | 1244 | #ifndef __WXUNIVERSAL__ |
ddae5262 VZ |
1245 | if ( !m_menuSystem ) |
1246 | { | |
1247 | HMENU hmenu = ::GetSystemMenu(GetHwnd(), FALSE); | |
1248 | if ( !hmenu ) | |
1249 | { | |
1250 | wxLogLastError(wxT("GetSystemMenu()")); | |
1251 | return NULL; | |
1252 | } | |
1253 | ||
1254 | wxTopLevelWindowMSW * const | |
1255 | self = const_cast<wxTopLevelWindowMSW *>(this); | |
1256 | ||
1257 | self->m_menuSystem = wxMenu::MSWNewFromHMENU(hmenu); | |
1258 | ||
1259 | // We need to somehow associate this menu with this window to ensure | |
1260 | // that we get events from it. A natural idea would be to pretend that | |
1261 | // it's attached to our menu bar but this wouldn't work if we don't | |
1262 | // have any menu bar which is a common case for applications using | |
1263 | // custom items in the system menu (they mostly do it exactly because | |
1264 | // they don't have any other menus). | |
1265 | // | |
1266 | // So reuse the invoking window pointer instead, this is not exactly | |
1267 | // correct but doesn't seem to have any serious drawbacks. | |
1268 | m_menuSystem->SetInvokingWindow(self); | |
1269 | } | |
fe62518e | 1270 | #endif // #ifndef __WXUNIVERSAL__ |
ddae5262 VZ |
1271 | |
1272 | return m_menuSystem; | |
1273 | } | |
1274 | ||
1275 | // ---------------------------------------------------------------------------- | |
1276 | // Transparency support | |
50f3c41d RD |
1277 | // --------------------------------------------------------------------------- |
1278 | ||
07880314 | 1279 | bool wxTopLevelWindowMSW::SetTransparent(wxByte alpha) |
50f3c41d | 1280 | { |
a8ff046b | 1281 | #if wxUSE_DYNLIB_CLASS |
50f3c41d | 1282 | typedef DWORD (WINAPI *PSETLAYEREDWINDOWATTR)(HWND, DWORD, BYTE, DWORD); |
caf587aa VZ |
1283 | static PSETLAYEREDWINDOWATTR |
1284 | pSetLayeredWindowAttributes = (PSETLAYEREDWINDOWATTR)-1; | |
50f3c41d | 1285 | |
caf587aa | 1286 | if ( pSetLayeredWindowAttributes == (PSETLAYEREDWINDOWATTR)-1 ) |
50f3c41d | 1287 | { |
9a83f860 | 1288 | wxDynamicLibrary dllUser32(wxT("user32.dll")); |
caf587aa VZ |
1289 | |
1290 | // use RawGetSymbol() and not GetSymbol() to avoid error messages under | |
1291 | // Windows 95: there is nothing the user can do about this anyhow | |
50f3c41d | 1292 | pSetLayeredWindowAttributes = (PSETLAYEREDWINDOWATTR) |
caf587aa VZ |
1293 | dllUser32.RawGetSymbol(wxT("SetLayeredWindowAttributes")); |
1294 | ||
1295 | // it's ok to destroy dllUser32 here, we link statically to user32.dll | |
1296 | // anyhow so it won't be unloaded | |
50f3c41d | 1297 | } |
caf587aa VZ |
1298 | |
1299 | if ( !pSetLayeredWindowAttributes ) | |
50f3c41d | 1300 | return false; |
a8ff046b | 1301 | #endif // wxUSE_DYNLIB_CLASS |
50f3c41d RD |
1302 | |
1303 | LONG exstyle = GetWindowLong(GetHwnd(), GWL_EXSTYLE); | |
1304 | ||
1305 | // if setting alpha to fully opaque then turn off the layered style | |
1306 | if (alpha == 255) | |
1307 | { | |
1308 | SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyle & ~WS_EX_LAYERED); | |
1309 | Refresh(); | |
1310 | return true; | |
1311 | } | |
1312 | ||
a8ff046b | 1313 | #if wxUSE_DYNLIB_CLASS |
50f3c41d RD |
1314 | // Otherwise, set the layered style if needed and set the alpha value |
1315 | if ((exstyle & WS_EX_LAYERED) == 0 ) | |
1316 | SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyle | WS_EX_LAYERED); | |
1317 | ||
a8ff046b VZ |
1318 | if ( pSetLayeredWindowAttributes(GetHwnd(), 0, (BYTE)alpha, LWA_ALPHA) ) |
1319 | return true; | |
1320 | #endif // wxUSE_DYNLIB_CLASS | |
1321 | ||
1322 | return false; | |
50f3c41d RD |
1323 | } |
1324 | ||
07880314 | 1325 | bool wxTopLevelWindowMSW::CanSetTransparent() |
50f3c41d RD |
1326 | { |
1327 | // The API is available on win2k and above | |
02761f6c | 1328 | |
50f3c41d RD |
1329 | static int os_type = -1; |
1330 | static int ver_major = -1; | |
1331 | ||
1332 | if (os_type == -1) | |
1333 | os_type = ::wxGetOsVersion(&ver_major); | |
1334 | ||
406d283a | 1335 | return (os_type == wxOS_WINDOWS_NT && ver_major >= 5); |
50f3c41d RD |
1336 | } |
1337 | ||
17808a75 | 1338 | void wxTopLevelWindowMSW::DoFreeze() |
0dd9b9e2 | 1339 | { |
1c8e5c51 VS |
1340 | // do nothing: freezing toplevel window causes paint and mouse events |
1341 | // to go through it any TLWs under it, so the best we can do is to freeze | |
1342 | // all children -- and wxWindowBase::Freeze() does that | |
0dd9b9e2 RD |
1343 | } |
1344 | ||
17808a75 | 1345 | void wxTopLevelWindowMSW::DoThaw() |
0dd9b9e2 | 1346 | { |
1c8e5c51 | 1347 | // intentionally empty -- see DoFreeze() |
0dd9b9e2 RD |
1348 | } |
1349 | ||
1350 | ||
085ad686 VZ |
1351 | // ---------------------------------------------------------------------------- |
1352 | // wxTopLevelWindow event handling | |
1353 | // ---------------------------------------------------------------------------- | |
1354 | ||
0c6dff03 VZ |
1355 | void wxTopLevelWindowMSW::DoSaveLastFocus() |
1356 | { | |
1357 | if ( m_iconized ) | |
1358 | return; | |
1359 | ||
1360 | // remember the last focused child if it is our child | |
1361 | m_winLastFocused = FindFocus(); | |
1362 | ||
1363 | if ( m_winLastFocused ) | |
1364 | { | |
1365 | // and don't remember it if it's a child from some other frame | |
1366 | if ( wxGetTopLevelParent(m_winLastFocused) != this ) | |
1367 | { | |
1368 | m_winLastFocused = NULL; | |
1369 | } | |
1370 | } | |
1371 | } | |
1372 | ||
1373 | void wxTopLevelWindowMSW::DoRestoreLastFocus() | |
1374 | { | |
1375 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() | |
1376 | : NULL; | |
1377 | if ( !parent ) | |
1378 | { | |
1379 | parent = this; | |
1380 | } | |
1381 | ||
1382 | wxSetFocusToChild(parent, &m_winLastFocused); | |
1383 | } | |
1384 | ||
085ad686 VZ |
1385 | void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event) |
1386 | { | |
1387 | if ( event.GetActive() ) | |
1388 | { | |
0c6dff03 VZ |
1389 | // We get WM_ACTIVATE before being restored from iconized state, so we |
1390 | // can be still iconized here. In this case, avoid restoring the focus | |
1391 | // as it doesn't work anyhow and we will do when we're really restored. | |
1392 | if ( m_iconized ) | |
1393 | { | |
1394 | event.Skip(); | |
1395 | return; | |
1396 | } | |
1397 | ||
2736a5de VZ |
1398 | // restore focus to the child which was last focused unless we already |
1399 | // have it | |
9a83f860 | 1400 | wxLogTrace(wxT("focus"), wxT("wxTLW %p activated."), m_hWnd); |
085ad686 | 1401 | |
2736a5de VZ |
1402 | wxWindow *winFocus = FindFocus(); |
1403 | if ( !winFocus || wxGetTopLevelParent(winFocus) != this ) | |
0c6dff03 | 1404 | DoRestoreLastFocus(); |
085ad686 VZ |
1405 | } |
1406 | else // deactivating | |
1407 | { | |
0c6dff03 | 1408 | DoSaveLastFocus(); |
085ad686 | 1409 | |
9a83f860 VZ |
1410 | wxLogTrace(wxT("focus"), |
1411 | wxT("wxTLW %p deactivated, last focused: %p."), | |
dca0f651 VZ |
1412 | m_hWnd, |
1413 | m_winLastFocused ? GetHwndOf(m_winLastFocused) : NULL); | |
085ad686 VZ |
1414 | |
1415 | event.Skip(); | |
1416 | } | |
1417 | } | |
1418 | ||
77ffb593 | 1419 | // the DialogProc for all wxWidgets dialogs |
12447831 | 1420 | LONG APIENTRY _EXPORT |
0fc58b86 | 1421 | wxDlgProc(HWND hDlg, |
2eb10e2a | 1422 | UINT message, |
3c96418b JG |
1423 | WPARAM WXUNUSED(wParam), |
1424 | LPARAM WXUNUSED(lParam)) | |
12447831 | 1425 | { |
08b97268 | 1426 | switch ( message ) |
12447831 | 1427 | { |
08b97268 WS |
1428 | case WM_INITDIALOG: |
1429 | { | |
1430 | // under CE, add a "Ok" button in the dialog title bar and make it full | |
1431 | // screen | |
1432 | // | |
1433 | // TODO: find the window for this HWND, and take into account | |
1434 | // wxMAXIMIZE and wxCLOSE_BOX. For now, assume both are present. | |
1435 | // | |
1436 | // Standard SDK doesn't have aygshell.dll: see | |
1437 | // include/wx/msw/wince/libraries.h | |
3d487566 | 1438 | #if defined(__WXWINCE__) && !defined(__WINCE_STANDARDSDK__) && !defined(__HANDHELDPC__) |
08b97268 WS |
1439 | SHINITDLGINFO shidi; |
1440 | shidi.dwMask = SHIDIM_FLAGS; | |
1441 | shidi.dwFlags = SHIDIF_SIZEDLG // take account of the SIP or menubar | |
ef6d716b | 1442 | #ifndef __SMARTPHONE__ |
08b97268 | 1443 | | SHIDIF_DONEBUTTON |
ef6d716b WS |
1444 | #endif |
1445 | ; | |
08b97268 WS |
1446 | shidi.hDlg = hDlg; |
1447 | SHInitDialog( &shidi ); | |
a48e51ce | 1448 | #else // no SHInitDialog() |
08b97268 WS |
1449 | wxUnusedVar(hDlg); |
1450 | #endif | |
1451 | // for WM_INITDIALOG, returning TRUE tells system to set focus to | |
1452 | // the first control in the dialog box, but as we set the focus | |
1453 | // ourselves, we return FALSE for it as well | |
1454 | return FALSE; | |
1455 | } | |
12447831 | 1456 | } |
a48e51ce VZ |
1457 | |
1458 | // for almost all messages, returning FALSE means that we didn't process | |
1459 | // the message | |
a48e51ce | 1460 | return FALSE; |
12447831 VZ |
1461 | } |
1462 | ||
2b5f62a0 VZ |
1463 | // ============================================================================ |
1464 | // wxTLWHiddenParentModule implementation | |
1465 | // ============================================================================ | |
1466 | ||
1467 | HWND wxTLWHiddenParentModule::ms_hwnd = NULL; | |
1468 | ||
1469 | const wxChar *wxTLWHiddenParentModule::ms_className = NULL; | |
1470 | ||
1471 | bool wxTLWHiddenParentModule::OnInit() | |
1472 | { | |
1473 | ms_hwnd = NULL; | |
1474 | ms_className = NULL; | |
1475 | ||
bfbb0b4c | 1476 | return true; |
2b5f62a0 VZ |
1477 | } |
1478 | ||
1479 | void wxTLWHiddenParentModule::OnExit() | |
1480 | { | |
1481 | if ( ms_hwnd ) | |
1482 | { | |
1483 | if ( !::DestroyWindow(ms_hwnd) ) | |
1484 | { | |
9a83f860 | 1485 | wxLogLastError(wxT("DestroyWindow(hidden TLW parent)")); |
2b5f62a0 VZ |
1486 | } |
1487 | ||
1488 | ms_hwnd = NULL; | |
1489 | } | |
1490 | ||
1491 | if ( ms_className ) | |
1492 | { | |
1493 | if ( !::UnregisterClass(ms_className, wxGetInstance()) ) | |
1494 | { | |
9a83f860 | 1495 | wxLogLastError(wxT("UnregisterClass(\"wxTLWHiddenParent\")")); |
2b5f62a0 VZ |
1496 | } |
1497 | ||
1498 | ms_className = NULL; | |
1499 | } | |
1500 | } | |
1501 | ||
1502 | /* static */ | |
1503 | HWND wxTLWHiddenParentModule::GetHWND() | |
1504 | { | |
1505 | if ( !ms_hwnd ) | |
1506 | { | |
1507 | if ( !ms_className ) | |
1508 | { | |
9a83f860 | 1509 | static const wxChar *HIDDEN_PARENT_CLASS = wxT("wxTLWHiddenParent"); |
2b5f62a0 VZ |
1510 | |
1511 | WNDCLASS wndclass; | |
1512 | wxZeroMemory(wndclass); | |
1513 | ||
1514 | wndclass.lpfnWndProc = DefWindowProc; | |
1515 | wndclass.hInstance = wxGetInstance(); | |
1516 | wndclass.lpszClassName = HIDDEN_PARENT_CLASS; | |
1517 | ||
1518 | if ( !::RegisterClass(&wndclass) ) | |
1519 | { | |
9a83f860 | 1520 | wxLogLastError(wxT("RegisterClass(\"wxTLWHiddenParent\")")); |
2b5f62a0 VZ |
1521 | } |
1522 | else | |
1523 | { | |
1524 | ms_className = HIDDEN_PARENT_CLASS; | |
1525 | } | |
1526 | } | |
1527 | ||
fda7962d | 1528 | ms_hwnd = ::CreateWindow(ms_className, wxEmptyString, 0, 0, 0, 0, 0, NULL, |
2b5f62a0 VZ |
1529 | (HMENU)NULL, wxGetInstance(), NULL); |
1530 | if ( !ms_hwnd ) | |
1531 | { | |
9a83f860 | 1532 | wxLogLastError(wxT("CreateWindow(hidden TLW parent)")); |
2b5f62a0 VZ |
1533 | } |
1534 | } | |
1535 | ||
1536 | return ms_hwnd; | |
1537 | } |