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