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