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