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