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