]>
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__ |
b225f659 VZ |
224 | if ( style & wxSYSTEM_MENU ) |
225 | msflags |= WS_SYSMENU; | |
9ceeecb9 | 226 | #endif |
2a47cb1b | 227 | |
f76858d8 VZ |
228 | // NB: under CE these 2 styles are not supported currently, we should |
229 | // call Minimize()/Maximize() "manually" if we want to support them | |
b225f659 VZ |
230 | if ( style & wxMINIMIZE ) |
231 | msflags |= WS_MINIMIZE; | |
9ceeecb9 | 232 | |
b225f659 VZ |
233 | if ( style & wxMAXIMIZE ) |
234 | msflags |= WS_MAXIMIZE; | |
0e082993 | 235 | |
b225f659 | 236 | // Keep this here because it saves recoding this function in wxTinyFrame |
b225f659 VZ |
237 | if ( style & (wxTINY_CAPTION_VERT | wxTINY_CAPTION_HORIZ) ) |
238 | msflags |= WS_CAPTION; | |
82eda5ec | 239 | |
b225f659 VZ |
240 | if ( exflags ) |
241 | { | |
f76858d8 | 242 | // there is no taskbar under CE, so omit all this |
45f27284 | 243 | #if !defined(__WXWINCE__) |
35bf863b VZ |
244 | if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ) |
245 | { | |
9dfef5ac VZ |
246 | if ( style & wxFRAME_TOOL_WINDOW ) |
247 | { | |
248 | // create the palette-like window | |
35bf863b | 249 | *exflags |= WS_EX_TOOLWINDOW; |
404a4d93 VZ |
250 | |
251 | // tool windows shouldn't appear on the taskbar (as documented) | |
252 | style |= wxFRAME_NO_TASKBAR; | |
9dfef5ac VZ |
253 | } |
254 | ||
255 | // We have to solve 2 different problems here: | |
256 | // | |
257 | // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the | |
258 | // taskbar even if they don't have a parent | |
259 | // | |
260 | // 2. frames without this style should appear in the taskbar even | |
261 | // if they're owned (Windows only puts non owned windows into | |
262 | // the taskbar normally) | |
263 | // | |
264 | // The second one is solved here by using WS_EX_APPWINDOW flag, the | |
265 | // first one is dealt with in our MSWGetParent() method | |
266 | // implementation | |
267 | if ( !(style & wxFRAME_NO_TASKBAR) && GetParent() ) | |
268 | { | |
269 | // need to force the frame to appear in the taskbar | |
35bf863b | 270 | *exflags |= WS_EX_APPWINDOW; |
9dfef5ac VZ |
271 | } |
272 | //else: nothing to do [here] | |
35bf863b | 273 | } |
b554cf63 | 274 | |
7ce6cc9b | 275 | if ( GetExtraStyle() & wxWS_EX_CONTEXTHELP ) |
b554cf63 | 276 | *exflags |= WS_EX_CONTEXTHELP; |
f76858d8 | 277 | #endif // !__WXWINCE__ |
b225f659 VZ |
278 | |
279 | if ( style & wxSTAY_ON_TOP ) | |
280 | *exflags |= WS_EX_TOPMOST; | |
b225f659 VZ |
281 | } |
282 | ||
283 | return msflags; | |
284 | } | |
285 | ||
9dfef5ac VZ |
286 | WXHWND wxTopLevelWindowMSW::MSWGetParent() const |
287 | { | |
288 | // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL | |
289 | // parent HWND or it would be always on top of its parent which is not what | |
290 | // we usually want (in fact, we only want it for frames with the | |
291 | // wxFRAME_FLOAT_ON_PARENT flag) | |
2b5f62a0 | 292 | HWND hwndParent = NULL; |
9dfef5ac VZ |
293 | if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) ) |
294 | { | |
2b5f62a0 | 295 | const wxWindow *parent = GetParent(); |
9dfef5ac | 296 | |
2b5f62a0 VZ |
297 | if ( !parent ) |
298 | { | |
299 | // this flag doesn't make sense then and will be ignored | |
300 | wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") ); | |
301 | } | |
302 | else | |
303 | { | |
304 | hwndParent = GetHwndOf(parent); | |
305 | } | |
9dfef5ac | 306 | } |
2b5f62a0 | 307 | //else: don't float on parent, must not be owned |
9dfef5ac VZ |
308 | |
309 | // now deal with the 2nd taskbar-related problem (see comments above in | |
310 | // MSWGetStyle()) | |
2b5f62a0 | 311 | if ( HasFlag(wxFRAME_NO_TASKBAR) && !hwndParent ) |
9dfef5ac | 312 | { |
2b5f62a0 VZ |
313 | // use hidden parent |
314 | hwndParent = wxTLWHiddenParentModule::GetHWND(); | |
9dfef5ac VZ |
315 | } |
316 | ||
2b5f62a0 | 317 | return (WXHWND)hwndParent; |
9dfef5ac VZ |
318 | } |
319 | ||
b7e5ba8f JG |
320 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
321 | bool wxTopLevelWindowMSW::HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam) | |
322 | { | |
323 | SHACTIVATEINFO *info = (SHACTIVATEINFO*) m_activateInfo; | |
324 | if ( info ) | |
325 | { | |
1272e71b | 326 | SHHandleWMSettingChange(GetHwnd(), wParam, lParam, info); |
b7e5ba8f JG |
327 | } |
328 | ||
1272e71b | 329 | return wxWindowMSW::HandleSettingChange(wParam, lParam); |
b7e5ba8f JG |
330 | } |
331 | #endif | |
332 | ||
08b97268 WS |
333 | WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
334 | { | |
335 | WXLRESULT rc = 0; | |
336 | bool processed = false; | |
337 | ||
8b0df0e1 | 338 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
08b97268 WS |
339 | switch ( message ) |
340 | { | |
08b97268 WS |
341 | case WM_ACTIVATE: |
342 | { | |
343 | SHACTIVATEINFO* info = (SHACTIVATEINFO*) m_activateInfo; | |
344 | if (info) | |
345 | { | |
346 | DWORD flags = 0; | |
347 | if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) flags = SHA_INPUTDIALOG; | |
348 | SHHandleWMActivate(GetHwnd(), wParam, lParam, info, flags); | |
349 | } | |
350 | ||
351 | // This implicitly sends a wxEVT_ACTIVATE_APP event | |
352 | if (wxTheApp) | |
353 | wxTheApp->SetActive(wParam != 0, FindFocus()); | |
354 | ||
355 | break; | |
356 | } | |
08b97268 WS |
357 | case WM_HIBERNATE: |
358 | { | |
359 | if (wxTheApp) | |
360 | { | |
361 | wxActivateEvent event(wxEVT_HIBERNATE, true, wxID_ANY); | |
362 | event.SetEventObject(wxTheApp); | |
363 | processed = wxTheApp->ProcessEvent(event); | |
364 | } | |
365 | break; | |
366 | } | |
08b97268 | 367 | } |
8b0df0e1 | 368 | #endif |
08b97268 WS |
369 | |
370 | if ( !processed ) | |
371 | rc = wxTopLevelWindowBase::MSWWindowProc(message, wParam, lParam); | |
372 | ||
373 | return rc; | |
374 | } | |
375 | ||
6e8515a3 | 376 | bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate, |
b225f659 VZ |
377 | const wxString& title, |
378 | const wxPoint& pos, | |
379 | const wxSize& size) | |
380 | { | |
381 | #ifdef __WXMICROWIN__ | |
382 | // no dialogs support under MicroWin yet | |
383 | return CreateFrame(title, pos, size); | |
384 | #else // !__WXMICROWIN__ | |
385 | wxWindow *parent = GetParent(); | |
386 | ||
387 | // for the dialogs without wxDIALOG_NO_PARENT style, use the top level | |
388 | // app window as parent - this avoids creating modal dialogs without | |
389 | // parent | |
390 | if ( !parent && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) | |
391 | { | |
392 | parent = wxTheApp->GetTopWindow(); | |
e058b98d | 393 | |
39cc7a0b | 394 | if ( parent ) |
e058b98d | 395 | { |
39cc7a0b VZ |
396 | // don't use transient windows as parents, this is dangerous as it |
397 | // can lead to a crash if the parent is destroyed before the child | |
398 | // | |
399 | // also don't use the window which is currently hidden as then the | |
400 | // dialog would be hidden as well | |
401 | if ( (parent->GetExtraStyle() & wxWS_EX_TRANSIENT) || | |
402 | !parent->IsShown() ) | |
403 | { | |
404 | parent = NULL; | |
405 | } | |
e058b98d | 406 | } |
b225f659 VZ |
407 | } |
408 | ||
434005ca VZ |
409 | m_hWnd = (WXHWND)::CreateDialogIndirect |
410 | ( | |
411 | wxGetInstance(), | |
412 | (DLGTEMPLATE*)dlgTemplate, | |
413 | parent ? GetHwndOf(parent) : NULL, | |
414 | (DLGPROC)wxDlgProc | |
415 | ); | |
b225f659 VZ |
416 | |
417 | if ( !m_hWnd ) | |
418 | { | |
7e99eddf | 419 | wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?")); |
b225f659 | 420 | |
7e99eddf | 421 | wxLogSysError(wxT("Can't create dialog using memory template")); |
b225f659 | 422 | |
bfbb0b4c | 423 | return false; |
b225f659 VZ |
424 | } |
425 | ||
b2d5a7ee | 426 | WXDWORD exflags; |
b225f659 VZ |
427 | (void)MSWGetCreateWindowFlags(&exflags); |
428 | ||
429 | if ( exflags ) | |
430 | { | |
431 | ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exflags); | |
cef338d3 VZ |
432 | ::SetWindowPos(GetHwnd(), |
433 | exflags & WS_EX_TOPMOST ? HWND_TOPMOST : 0, | |
434 | 0, 0, 0, 0, | |
b225f659 VZ |
435 | SWP_NOSIZE | |
436 | SWP_NOMOVE | | |
cef338d3 | 437 | (exflags & WS_EX_TOPMOST ? 0 : SWP_NOZORDER) | |
b225f659 VZ |
438 | SWP_NOACTIVATE); |
439 | } | |
440 | ||
b554cf63 | 441 | #if !defined(__WXWINCE__) |
b225f659 VZ |
442 | // For some reason, the system menu is activated when we use the |
443 | // WS_EX_CONTEXTHELP style, so let's set a reasonable icon | |
444 | if ( exflags & WS_EX_CONTEXTHELP ) | |
445 | { | |
446 | wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame); | |
447 | if ( winTop ) | |
448 | { | |
449 | wxIcon icon = winTop->GetIcon(); | |
450 | if ( icon.Ok() ) | |
451 | { | |
452 | ::SendMessage(GetHwnd(), WM_SETICON, | |
453 | (WPARAM)TRUE, | |
454 | (LPARAM)GetHiconOf(icon)); | |
455 | } | |
456 | } | |
457 | } | |
b554cf63 | 458 | #endif |
b225f659 VZ |
459 | |
460 | // move the dialog to its initial position without forcing repainting | |
461 | int x, y, w, h; | |
72a11184 | 462 | (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h); |
4c53c743 | 463 | |
26268100 RD |
464 | if ( x == (int)CW_USEDEFAULT ) |
465 | { | |
466 | // centre it on the screen - what else can we do? | |
467 | wxSize sizeDpy = wxGetDisplaySize(); | |
468 | ||
469 | x = (sizeDpy.x - w) / 2; | |
470 | y = (sizeDpy.y - h) / 2; | |
471 | } | |
472 | ||
a9928e9d | 473 | #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__) |
4c53c743 VZ |
474 | if ( !::MoveWindow(GetHwnd(), x, y, w, h, FALSE) ) |
475 | { | |
476 | wxLogLastError(wxT("MoveWindow")); | |
b225f659 | 477 | } |
28c191aa | 478 | #endif |
b225f659 VZ |
479 | |
480 | if ( !title.empty() ) | |
481 | { | |
e0a050e3 | 482 | ::SetWindowText(GetHwnd(), title.wx_str()); |
b225f659 VZ |
483 | } |
484 | ||
485 | SubclassWin(m_hWnd); | |
faa49bfd | 486 | |
aa29eefa JS |
487 | #ifdef __SMARTPHONE__ |
488 | // Work around title non-display glitch | |
489 | Show(false); | |
faa49bfd | 490 | #endif |
b225f659 | 491 | |
bfbb0b4c | 492 | return true; |
b225f659 VZ |
493 | #endif // __WXMICROWIN__/!__WXMICROWIN__ |
494 | } | |
495 | ||
496 | bool wxTopLevelWindowMSW::CreateFrame(const wxString& title, | |
497 | const wxPoint& pos, | |
498 | const wxSize& size) | |
499 | { | |
b2d5a7ee VZ |
500 | WXDWORD exflags; |
501 | WXDWORD flags = MSWGetCreateWindowFlags(&exflags); | |
b225f659 | 502 | |
6fd54d58 | 503 | const wxSize sz = IsAlwaysMaximized() ? wxDefaultSize : size; |
6f26f98e | 504 | |
08a58133 | 505 | #ifndef __WXWINCE__ |
978af864 VZ |
506 | if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) |
507 | exflags |= WS_EX_LAYOUTRTL; | |
08a58133 | 508 | #endif |
978af864 | 509 | |
e0a050e3 | 510 | return MSWCreate(wxCanvasClassName, title.wx_str(), pos, sz, flags, exflags); |
82c9f85c VZ |
511 | } |
512 | ||
513 | bool wxTopLevelWindowMSW::Create(wxWindow *parent, | |
514 | wxWindowID id, | |
515 | const wxString& title, | |
516 | const wxPoint& pos, | |
517 | const wxSize& size, | |
518 | long style, | |
519 | const wxString& name) | |
520 | { | |
999836aa | 521 | bool ret wxDUMMY_INITIALIZE(false); |
2a47cb1b | 522 | |
82c9f85c VZ |
523 | // init our fields |
524 | Init(); | |
2a47cb1b VZ |
525 | |
526 | wxSize sizeReal = size; | |
527 | if ( !sizeReal.IsFullySpecified() ) | |
528 | { | |
529 | sizeReal.SetDefaults(GetDefaultSize()); | |
530 | } | |
82c9f85c VZ |
531 | |
532 | m_windowStyle = style; | |
533 | ||
534 | SetName(name); | |
535 | ||
bfbb0b4c | 536 | m_windowId = id == wxID_ANY ? NewControlId() : id; |
82c9f85c VZ |
537 | |
538 | wxTopLevelWindows.Append(this); | |
539 | ||
540 | if ( parent ) | |
541 | parent->AddChild(this); | |
542 | ||
b225f659 VZ |
543 | if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG ) |
544 | { | |
b225f659 VZ |
545 | // we have different dialog templates to allows creation of dialogs |
546 | // with & without captions under MSWindows, resizeable or not (but a | |
547 | // resizeable dialog always has caption - otherwise it would look too | |
548 | // strange) | |
434005ca VZ |
549 | |
550 | // we need 3 additional WORDs for dialog menu, class and title (as we | |
551 | // don't use DS_SETFONT we don't need the fourth WORD for the font) | |
552 | static const int dlgsize = sizeof(DLGTEMPLATE) + (sizeof(WORD) * 3); | |
553 | DLGTEMPLATE *dlgTemplate = (DLGTEMPLATE *)malloc(dlgsize); | |
554 | memset(dlgTemplate, 0, dlgsize); | |
555 | ||
556 | // these values are arbitrary, they won't be used normally anyhow | |
6e8515a3 JS |
557 | dlgTemplate->x = 34; |
558 | dlgTemplate->y = 22; | |
559 | dlgTemplate->cx = 144; | |
560 | dlgTemplate->cy = 75; | |
561 | ||
434005ca VZ |
562 | // reuse the code in MSWGetStyle() but correct the results slightly for |
563 | // the dialog | |
564 | dlgTemplate->style = MSWGetStyle(style, NULL); | |
565 | ||
566 | // all dialogs are popups | |
567 | dlgTemplate->style |= WS_POPUP; | |
08a58133 WS |
568 | |
569 | #ifndef __WXWINCE__ | |
978af864 VZ |
570 | if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft ) |
571 | { | |
572 | dlgTemplate->dwExtendedStyle |= WS_EX_LAYOUTRTL; | |
573 | } | |
434005ca VZ |
574 | |
575 | // force 3D-look if necessary, it looks impossibly ugly otherwise | |
576 | if ( style & (wxRESIZE_BORDER | wxCAPTION) ) | |
577 | dlgTemplate->style |= DS_MODALFRAME; | |
9cce2fe2 | 578 | #endif |
b225f659 | 579 | |
2a47cb1b | 580 | ret = CreateDialog(dlgTemplate, title, pos, sizeReal); |
6e8515a3 | 581 | free(dlgTemplate); |
b225f659 VZ |
582 | } |
583 | else // !dialog | |
584 | { | |
2a47cb1b | 585 | ret = CreateFrame(title, pos, sizeReal); |
9ca4dd06 VS |
586 | } |
587 | ||
9ceeecb9 | 588 | #ifndef __WXWINCE__ |
9ca4dd06 VS |
589 | if ( ret && !(GetWindowStyleFlag() & wxCLOSE_BOX) ) |
590 | { | |
591 | EnableCloseButton(false); | |
b225f659 | 592 | } |
9ceeecb9 | 593 | #endif |
9ca4dd06 | 594 | |
d7e0024b VZ |
595 | // for standard dialogs the dialog manager generates WM_CHANGEUISTATE |
596 | // itself but for custom windows we have to do it ourselves in order to | |
597 | // make the keyboard indicators (such as underlines for accelerators and | |
598 | // focus rectangles) work under Win2k+ | |
bb655ead VZ |
599 | if ( ret ) |
600 | { | |
3ef092d6 | 601 | MSWUpdateUIState(UIS_INITIALIZE); |
bb655ead VZ |
602 | } |
603 | ||
f43255e8 WS |
604 | // Note: if we include PocketPC in this test, dialogs can fail to show up, |
605 | // for example the text entry dialog in the dialogs sample. Problem with Maximise()? | |
606 | #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__WINCE_STANDARDSDK__)) | |
6f26f98e | 607 | if ( ( style & wxMAXIMIZE ) || IsAlwaysMaximized() ) |
991420e6 WS |
608 | { |
609 | this->Maximize(); | |
610 | } | |
f43255e8 | 611 | #endif |
82eda5ec | 612 | |
3180bc0e | 613 | #if defined(__SMARTPHONE__) && defined(__WXWINCE__) |
fb8a56b7 WS |
614 | SetRightMenu(); // to nothing for initialization |
615 | #endif | |
616 | ||
9ca4dd06 | 617 | return ret; |
82c9f85c VZ |
618 | } |
619 | ||
620 | wxTopLevelWindowMSW::~wxTopLevelWindowMSW() | |
621 | { | |
08b97268 WS |
622 | #if defined(__SMARTPHONE__) || defined(__POCKETPC__) |
623 | SHACTIVATEINFO* info = (SHACTIVATEINFO*) m_activateInfo; | |
624 | delete info; | |
625 | m_activateInfo = NULL; | |
626 | #endif | |
627 | ||
d6fb86a8 VZ |
628 | // after destroying an owned window, Windows activates the next top level |
629 | // window in Z order but it may be different from our owner (to reproduce | |
630 | // this simply Alt-TAB to another application and back before closing the | |
631 | // owned frame) whereas we always want to yield activation to our parent | |
632 | if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) ) | |
633 | { | |
634 | wxWindow *parent = GetParent(); | |
635 | if ( parent ) | |
636 | { | |
637 | ::BringWindowToTop(GetHwndOf(parent)); | |
638 | } | |
639 | } | |
82c9f85c VZ |
640 | } |
641 | ||
82c9f85c VZ |
642 | // ---------------------------------------------------------------------------- |
643 | // wxTopLevelWindowMSW showing | |
644 | // ---------------------------------------------------------------------------- | |
645 | ||
646 | void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd) | |
647 | { | |
648 | ::ShowWindow(GetHwnd(), nShowCmd); | |
649 | ||
650 | m_iconized = nShowCmd == SW_MINIMIZE; | |
651 | } | |
652 | ||
653 | bool wxTopLevelWindowMSW::Show(bool show) | |
654 | { | |
655 | // don't use wxWindow version as we want to call DoShowWindow() ourselves | |
656 | if ( !wxWindowBase::Show(show) ) | |
bfbb0b4c | 657 | return false; |
82c9f85c VZ |
658 | |
659 | int nShowCmd; | |
660 | if ( show ) | |
661 | { | |
662 | if ( m_maximizeOnShow ) | |
663 | { | |
664 | // show and maximize | |
665 | nShowCmd = SW_MAXIMIZE; | |
666 | ||
991420e6 | 667 | // This is necessary, or no window appears |
aa29eefa | 668 | #if defined( __WINCE_STANDARDSDK__) || defined(__SMARTPHONE__) |
991420e6 | 669 | DoShowWindow(SW_SHOW); |
a9928e9d JS |
670 | #endif |
671 | ||
bfbb0b4c | 672 | m_maximizeOnShow = false; |
82c9f85c VZ |
673 | } |
674 | else // just show | |
675 | { | |
84cff965 JS |
676 | if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW ) |
677 | nShowCmd = SW_SHOWNA; | |
678 | else | |
679 | nShowCmd = SW_SHOW; | |
82c9f85c VZ |
680 | } |
681 | } | |
682 | else // hide | |
683 | { | |
684 | nShowCmd = SW_HIDE; | |
685 | } | |
686 | ||
687 | DoShowWindow(nShowCmd); | |
688 | ||
a9928e9d JS |
689 | #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__)) |
690 | // Addornments have to be added when the frame is the correct size | |
691 | wxFrame* frame = wxDynamicCast(this, wxFrame); | |
692 | if (frame && frame->GetMenuBar()) | |
693 | frame->GetMenuBar()->AddAdornments(GetWindowStyleFlag()); | |
694 | #endif | |
0567fdfc | 695 | |
6fd54d58 VZ |
696 | // we only set pending size if we're maximized before being shown, now that |
697 | // we're shown we don't need it any more (it is reset in size event handler | |
698 | // for child windows but we have to do it ourselves for this parent window) | |
699 | m_pendingSize = wxDefaultSize; | |
700 | ||
0567fdfc | 701 | return true; |
82c9f85c VZ |
702 | } |
703 | ||
704 | // ---------------------------------------------------------------------------- | |
705 | // wxTopLevelWindowMSW maximize/minimize | |
706 | // ---------------------------------------------------------------------------- | |
707 | ||
708 | void wxTopLevelWindowMSW::Maximize(bool maximize) | |
709 | { | |
710 | if ( IsShown() ) | |
711 | { | |
712 | // just maximize it directly | |
713 | DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); | |
714 | } | |
715 | else // hidden | |
716 | { | |
73c902d6 DS |
717 | // we can't maximize the hidden frame because it shows it as well, |
718 | // so just remember that we should do it later in this case | |
a0be434e | 719 | m_maximizeOnShow = maximize; |
ac2de323 VZ |
720 | |
721 | // after calling Maximize() the client code expects to get the frame | |
722 | // "real" size and doesn't want to know that, because of implementation | |
723 | // details, the frame isn't really maximized yet but will be only once | |
724 | // it's shown, so return our size as it will be then in this case | |
7889b795 VZ |
725 | if ( maximize ) |
726 | { | |
6fd54d58 VZ |
727 | // we must only change pending size here, and not call SetSize() |
728 | // because otherwise Windows would think that this (full screen) | |
729 | // size is the natural size for the frame and so would use it when | |
730 | // the user clicks on "restore" title bar button instead of the | |
731 | // correct initial frame size | |
732 | // | |
733 | // NB: unfortunately we don't know which display we're on yet so we | |
734 | // have to use the default one | |
735 | m_pendingSize = wxGetClientDisplayRect().GetSize(); | |
7889b795 VZ |
736 | } |
737 | //else: can't do anything in this case, we don't have the old size | |
82c9f85c VZ |
738 | } |
739 | } | |
740 | ||
741 | bool wxTopLevelWindowMSW::IsMaximized() const | |
742 | { | |
979a0320 | 743 | return IsAlwaysMaximized() || |
a8e89343 JS |
744 | #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) && !defined(__WINCE_STANDARDSDK__) |
745 | ||
979a0320 | 746 | (::IsZoomed(GetHwnd()) != 0) || |
4676948b | 747 | #endif |
979a0320 | 748 | m_maximizeOnShow; |
82c9f85c VZ |
749 | } |
750 | ||
751 | void wxTopLevelWindowMSW::Iconize(bool iconize) | |
752 | { | |
753 | DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); | |
754 | } | |
755 | ||
756 | bool wxTopLevelWindowMSW::IsIconized() const | |
757 | { | |
4676948b | 758 | #ifdef __WXWINCE__ |
bfbb0b4c | 759 | return false; |
4676948b | 760 | #else |
9f01395e VZ |
761 | // don't use m_iconized, it may be briefly out of sync with the real state |
762 | // as it's only modified when we receive a WM_SIZE and we could be called | |
763 | // from an event handler from one of the messages we receive before it, | |
764 | // such as WM_MOVE | |
765 | return ::IsIconic(GetHwnd()) != 0; | |
4676948b | 766 | #endif |
82c9f85c VZ |
767 | } |
768 | ||
769 | void wxTopLevelWindowMSW::Restore() | |
770 | { | |
771 | DoShowWindow(SW_RESTORE); | |
772 | } | |
773 | ||
978af864 VZ |
774 | void wxTopLevelWindowMSW::SetLayoutDirection(wxLayoutDirection dir) |
775 | { | |
776 | if ( dir == wxLayout_Default ) | |
777 | dir = wxTheApp->GetLayoutDirection(); | |
778 | ||
779 | if ( dir != wxLayout_Default ) | |
780 | wxTopLevelWindowBase::SetLayoutDirection(dir); | |
781 | } | |
782 | ||
d43eb2a0 VZ |
783 | // ---------------------------------------------------------------------------- |
784 | // wxTopLevelWindowMSW geometry | |
785 | // ---------------------------------------------------------------------------- | |
786 | ||
b7036299 WS |
787 | #ifndef __WXWINCE__ |
788 | ||
c5dc89a1 WS |
789 | void wxTopLevelWindowMSW::DoGetPosition(int *x, int *y) const |
790 | { | |
d43eb2a0 VZ |
791 | if ( IsIconized() ) |
792 | { | |
793 | WINDOWPLACEMENT wp; | |
794 | wp.length = sizeof(WINDOWPLACEMENT); | |
795 | if ( ::GetWindowPlacement(GetHwnd(), &wp) ) | |
796 | { | |
797 | RECT& rc = wp.rcNormalPosition; | |
798 | ||
799 | // the position returned by GetWindowPlacement() is in workspace | |
800 | // coordinates except for windows with WS_EX_TOOLWINDOW style | |
801 | if ( !HasFlag(wxFRAME_TOOL_WINDOW) ) | |
802 | { | |
803 | // we must use the correct display for the translation as the | |
804 | // task bar might be shown on one display but not the other one | |
805 | int n = wxDisplay::GetFromWindow(this); | |
806 | wxDisplay dpy(n == wxNOT_FOUND ? 0 : n); | |
807 | const wxPoint ptOfs = dpy.GetClientArea().GetPosition() - | |
808 | dpy.GetGeometry().GetPosition(); | |
809 | ||
810 | rc.left += ptOfs.x; | |
811 | rc.top += ptOfs.y; | |
812 | } | |
813 | ||
814 | if ( x ) | |
815 | *x = rc.left; | |
816 | if ( y ) | |
817 | *y = rc.top; | |
818 | ||
819 | return; | |
820 | } | |
821 | ||
822 | wxLogLastError(_T("GetWindowPlacement")); | |
823 | } | |
824 | //else: normal case | |
825 | ||
826 | wxTopLevelWindowBase::DoGetPosition(x, y); | |
827 | } | |
828 | ||
829 | void wxTopLevelWindowMSW::DoGetSize(int *width, int *height) const | |
830 | { | |
831 | if ( IsIconized() ) | |
832 | { | |
833 | WINDOWPLACEMENT wp; | |
834 | wp.length = sizeof(WINDOWPLACEMENT); | |
835 | if ( ::GetWindowPlacement(GetHwnd(), &wp) ) | |
836 | { | |
837 | const RECT& rc = wp.rcNormalPosition; | |
838 | ||
839 | if ( width ) | |
840 | *width = rc.right - rc.left; | |
841 | if ( height ) | |
842 | *height = rc.bottom - rc.top; | |
843 | ||
844 | return; | |
845 | } | |
846 | ||
847 | wxLogLastError(_T("GetWindowPlacement")); | |
848 | } | |
849 | //else: normal case | |
850 | ||
851 | wxTopLevelWindowBase::DoGetSize(width, height); | |
852 | } | |
853 | ||
c5dc89a1 WS |
854 | #endif // __WXWINCE__ |
855 | ||
c641b1d2 VS |
856 | // ---------------------------------------------------------------------------- |
857 | // wxTopLevelWindowMSW fullscreen | |
858 | // ---------------------------------------------------------------------------- | |
859 | ||
860 | bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style) | |
861 | { | |
716645d3 | 862 | if ( show == IsFullScreen() ) |
c641b1d2 | 863 | { |
716645d3 | 864 | // nothing to do |
bfbb0b4c | 865 | return true; |
716645d3 VZ |
866 | } |
867 | ||
868 | m_fsIsShowing = show; | |
c641b1d2 | 869 | |
716645d3 VZ |
870 | if ( show ) |
871 | { | |
c641b1d2 VS |
872 | m_fsStyle = style; |
873 | ||
874 | // zap the frame borders | |
875 | ||
876 | // save the 'normal' window style | |
716645d3 | 877 | m_fsOldWindowStyle = GetWindowLong(GetHwnd(), GWL_STYLE); |
c641b1d2 VS |
878 | |
879 | // save the old position, width & height, maximize state | |
880 | m_fsOldSize = GetRect(); | |
881 | m_fsIsMaximized = IsMaximized(); | |
882 | ||
883 | // decide which window style flags to turn off | |
884 | LONG newStyle = m_fsOldWindowStyle; | |
885 | LONG offFlags = 0; | |
886 | ||
887 | if (style & wxFULLSCREEN_NOBORDER) | |
4676948b JS |
888 | { |
889 | offFlags |= WS_BORDER; | |
890 | #ifndef __WXWINCE__ | |
891 | offFlags |= WS_THICKFRAME; | |
892 | #endif | |
893 | } | |
c641b1d2 | 894 | if (style & wxFULLSCREEN_NOCAPTION) |
716645d3 | 895 | offFlags |= WS_CAPTION | WS_SYSMENU; |
c641b1d2 | 896 | |
716645d3 | 897 | newStyle &= ~offFlags; |
c641b1d2 VS |
898 | |
899 | // change our window style to be compatible with full-screen mode | |
716645d3 | 900 | ::SetWindowLong(GetHwnd(), GWL_STYLE, newStyle); |
c641b1d2 | 901 | |
716645d3 VZ |
902 | wxRect rect; |
903 | #if wxUSE_DISPLAY | |
904 | // resize to the size of the display containing us | |
905 | int dpy = wxDisplay::GetFromWindow(this); | |
906 | if ( dpy != wxNOT_FOUND ) | |
907 | { | |
908 | rect = wxDisplay(dpy).GetGeometry(); | |
909 | } | |
910 | else // fall back to the main desktop | |
86828e0f | 911 | #endif // wxUSE_DISPLAY |
716645d3 VZ |
912 | { |
913 | // resize to the size of the desktop | |
914 | wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect); | |
80a81a12 JS |
915 | #ifdef __WXWINCE__ |
916 | // FIXME: size of the bottom menu (toolbar) | |
917 | // should be taken in account | |
918 | rect.height += rect.y; | |
919 | rect.y = 0; | |
4676948b | 920 | #endif |
716645d3 | 921 | } |
c641b1d2 | 922 | |
716645d3 | 923 | SetSize(rect); |
c641b1d2 VS |
924 | |
925 | // now flush the window style cache and actually go full-screen | |
716645d3 | 926 | long flags = SWP_FRAMECHANGED; |
c641b1d2 | 927 | |
716645d3 VZ |
928 | // showing the frame full screen should also show it if it's still |
929 | // hidden | |
930 | if ( !IsShown() ) | |
931 | { | |
932 | // don't call wxWindow version to avoid flicker from calling | |
933 | // ::ShowWindow() -- we're going to show the window at the correct | |
934 | // location directly below -- but do call the wxWindowBase version | |
935 | // to sync the internal m_isShown flag | |
936 | wxWindowBase::Show(); | |
c641b1d2 | 937 | |
716645d3 VZ |
938 | flags |= SWP_SHOWWINDOW; |
939 | } | |
c641b1d2 | 940 | |
716645d3 VZ |
941 | SetWindowPos(GetHwnd(), HWND_TOP, |
942 | rect.x, rect.y, rect.width, rect.height, | |
943 | flags); | |
c641b1d2 | 944 | |
3d487566 | 945 | #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400)) |
80a81a12 JS |
946 | ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON); |
947 | #endif | |
948 | ||
716645d3 VZ |
949 | // finally send an event allowing the window to relayout itself &c |
950 | wxSizeEvent event(rect.GetSize(), GetId()); | |
951 | GetEventHandler()->ProcessEvent(event); | |
952 | } | |
953 | else // stop showing full screen | |
954 | { | |
3d487566 | 955 | #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400)) |
80a81a12 JS |
956 | ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON); |
957 | #endif | |
c641b1d2 | 958 | Maximize(m_fsIsMaximized); |
716645d3 VZ |
959 | SetWindowLong(GetHwnd(),GWL_STYLE, m_fsOldWindowStyle); |
960 | SetWindowPos(GetHwnd(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y, | |
c641b1d2 | 961 | m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED); |
c641b1d2 | 962 | } |
716645d3 | 963 | |
bfbb0b4c | 964 | return true; |
c641b1d2 VS |
965 | } |
966 | ||
82c9f85c VZ |
967 | // ---------------------------------------------------------------------------- |
968 | // wxTopLevelWindowMSW misc | |
969 | // ---------------------------------------------------------------------------- | |
970 | ||
faa49bfd WS |
971 | void wxTopLevelWindowMSW::SetTitle( const wxString& title) |
972 | { | |
973 | SetLabel(title); | |
974 | } | |
975 | ||
976 | wxString wxTopLevelWindowMSW::GetTitle() const | |
977 | { | |
978 | return GetLabel(); | |
979 | } | |
980 | ||
f618020a MB |
981 | void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons) |
982 | { | |
983 | wxTopLevelWindowBase::SetIcons(icons); | |
82c9f85c | 984 | |
a71d815b | 985 | #if !defined(__WXMICROWIN__) |
f605c258 VZ |
986 | const wxIcon& sml = icons.GetIconOfExactSize(16); |
987 | if( sml.Ok() ) | |
f618020a MB |
988 | { |
989 | ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_SMALL, | |
990 | (LPARAM)GetHiconOf(sml) ); | |
991 | } | |
992 | ||
f605c258 VZ |
993 | const wxIcon& big = icons.GetIconOfExactSize(32); |
994 | if( big.Ok() ) | |
82c9f85c | 995 | { |
f618020a MB |
996 | ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_BIG, |
997 | (LPARAM)GetHiconOf(big) ); | |
82c9f85c | 998 | } |
a71d815b | 999 | #endif // !__WXMICROWIN__ |
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 VZ |
1019 | { |
1020 | wxLogLastError(_T("EnableMenuItem(SC_CLOSE)")); | |
1021 | ||
bfbb0b4c | 1022 | return false; |
a91cf80c | 1023 | } |
960b193e | 1024 | #ifndef __WXWINCE__ |
a91cf80c VZ |
1025 | // update appearance immediately |
1026 | if ( !::DrawMenuBar(GetHwnd()) ) | |
1027 | { | |
1028 | wxLogLastError(_T("DrawMenuBar")); | |
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, |
6a7e6411 RD |
1041 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); |
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 | { | |
1049 | wxLogLastError(_T("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); | |
1070 | ::AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle); | |
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 | { | |
1076 | wxLogLastError(_T("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); | |
1094 | FlashWindowEx_t s_pfnFlashWindowEx = NULL; | |
1095 | if ( !s_pfnFlashWindowEx ) | |
1096 | { | |
1097 | wxDynamicLibrary dllUser32(_T("user32.dll")); | |
1098 | s_pfnFlashWindowEx = (FlashWindowEx_t) | |
1099 | dllUser32.GetSymbol(_T("FlashWindowEx")); | |
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 RD |
1138 | typedef DWORD (WINAPI *PSETLAYEREDWINDOWATTR)(HWND, DWORD, BYTE, DWORD); |
1139 | static PSETLAYEREDWINDOWATTR pSetLayeredWindowAttributes = NULL; | |
1140 | ||
50f3c41d RD |
1141 | if ( pSetLayeredWindowAttributes == NULL ) |
1142 | { | |
1143 | wxDynamicLibrary dllUser32(_T("user32.dll")); | |
1144 | pSetLayeredWindowAttributes = (PSETLAYEREDWINDOWATTR) | |
1145 | dllUser32.GetSymbol(wxT("SetLayeredWindowAttributes")); | |
1146 | } | |
1147 | if ( pSetLayeredWindowAttributes == NULL ) | |
1148 | return false; | |
a8ff046b | 1149 | #endif // wxUSE_DYNLIB_CLASS |
50f3c41d RD |
1150 | |
1151 | LONG exstyle = GetWindowLong(GetHwnd(), GWL_EXSTYLE); | |
1152 | ||
1153 | // if setting alpha to fully opaque then turn off the layered style | |
1154 | if (alpha == 255) | |
1155 | { | |
1156 | SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyle & ~WS_EX_LAYERED); | |
1157 | Refresh(); | |
1158 | return true; | |
1159 | } | |
1160 | ||
a8ff046b | 1161 | #if wxUSE_DYNLIB_CLASS |
50f3c41d RD |
1162 | // Otherwise, set the layered style if needed and set the alpha value |
1163 | if ((exstyle & WS_EX_LAYERED) == 0 ) | |
1164 | SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyle | WS_EX_LAYERED); | |
1165 | ||
a8ff046b VZ |
1166 | if ( pSetLayeredWindowAttributes(GetHwnd(), 0, (BYTE)alpha, LWA_ALPHA) ) |
1167 | return true; | |
1168 | #endif // wxUSE_DYNLIB_CLASS | |
1169 | ||
1170 | return false; | |
50f3c41d RD |
1171 | } |
1172 | ||
07880314 | 1173 | bool wxTopLevelWindowMSW::CanSetTransparent() |
50f3c41d RD |
1174 | { |
1175 | // The API is available on win2k and above | |
02761f6c | 1176 | |
50f3c41d RD |
1177 | static int os_type = -1; |
1178 | static int ver_major = -1; | |
1179 | ||
1180 | if (os_type == -1) | |
1181 | os_type = ::wxGetOsVersion(&ver_major); | |
1182 | ||
406d283a | 1183 | return (os_type == wxOS_WINDOWS_NT && ver_major >= 5); |
50f3c41d RD |
1184 | } |
1185 | ||
085ad686 VZ |
1186 | // ---------------------------------------------------------------------------- |
1187 | // wxTopLevelWindow event handling | |
1188 | // ---------------------------------------------------------------------------- | |
1189 | ||
1190 | // Default activation behaviour - set the focus for the first child | |
1191 | // subwindow found. | |
1192 | void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event) | |
1193 | { | |
1194 | if ( event.GetActive() ) | |
1195 | { | |
2736a5de VZ |
1196 | // restore focus to the child which was last focused unless we already |
1197 | // have it | |
1198 | wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd); | |
085ad686 | 1199 | |
2736a5de VZ |
1200 | wxWindow *winFocus = FindFocus(); |
1201 | if ( !winFocus || wxGetTopLevelParent(winFocus) != this ) | |
085ad686 | 1202 | { |
2736a5de VZ |
1203 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() |
1204 | : NULL; | |
1205 | if ( !parent ) | |
1206 | { | |
1207 | parent = this; | |
1208 | } | |
085ad686 | 1209 | |
2736a5de VZ |
1210 | wxSetFocusToChild(parent, &m_winLastFocused); |
1211 | } | |
085ad686 VZ |
1212 | } |
1213 | else // deactivating | |
1214 | { | |
1215 | // remember the last focused child if it is our child | |
1216 | m_winLastFocused = FindFocus(); | |
1217 | ||
13834828 VZ |
1218 | if ( m_winLastFocused ) |
1219 | { | |
1220 | // let it know that it doesn't have focus any more | |
77e00fe9 | 1221 | m_winLastFocused->HandleKillFocus((WXHWND)NULL); |
13834828 | 1222 | |
2736a5de VZ |
1223 | // and don't remember it if it's a child from some other frame |
1224 | if ( wxGetTopLevelParent(m_winLastFocused) != this ) | |
085ad686 | 1225 | { |
2736a5de | 1226 | m_winLastFocused = NULL; |
085ad686 | 1227 | } |
085ad686 VZ |
1228 | } |
1229 | ||
1230 | wxLogTrace(_T("focus"), | |
1231 | _T("wxTLW %08x deactivated, last focused: %08x."), | |
9b601c24 GRG |
1232 | (int) m_hWnd, |
1233 | (int) (m_winLastFocused ? GetHwndOf(m_winLastFocused) | |
1234 | : NULL)); | |
085ad686 VZ |
1235 | |
1236 | event.Skip(); | |
1237 | } | |
1238 | } | |
1239 | ||
77ffb593 | 1240 | // the DialogProc for all wxWidgets dialogs |
12447831 | 1241 | LONG APIENTRY _EXPORT |
0fc58b86 | 1242 | wxDlgProc(HWND hDlg, |
2eb10e2a | 1243 | UINT message, |
3c96418b JG |
1244 | WPARAM WXUNUSED(wParam), |
1245 | LPARAM WXUNUSED(lParam)) | |
12447831 | 1246 | { |
08b97268 | 1247 | switch ( message ) |
12447831 | 1248 | { |
08b97268 WS |
1249 | case WM_INITDIALOG: |
1250 | { | |
1251 | // under CE, add a "Ok" button in the dialog title bar and make it full | |
1252 | // screen | |
1253 | // | |
1254 | // TODO: find the window for this HWND, and take into account | |
1255 | // wxMAXIMIZE and wxCLOSE_BOX. For now, assume both are present. | |
1256 | // | |
1257 | // Standard SDK doesn't have aygshell.dll: see | |
1258 | // include/wx/msw/wince/libraries.h | |
3d487566 | 1259 | #if defined(__WXWINCE__) && !defined(__WINCE_STANDARDSDK__) && !defined(__HANDHELDPC__) |
08b97268 WS |
1260 | SHINITDLGINFO shidi; |
1261 | shidi.dwMask = SHIDIM_FLAGS; | |
1262 | shidi.dwFlags = SHIDIF_SIZEDLG // take account of the SIP or menubar | |
ef6d716b | 1263 | #ifndef __SMARTPHONE__ |
08b97268 | 1264 | | SHIDIF_DONEBUTTON |
ef6d716b WS |
1265 | #endif |
1266 | ; | |
08b97268 WS |
1267 | shidi.hDlg = hDlg; |
1268 | SHInitDialog( &shidi ); | |
a48e51ce | 1269 | #else // no SHInitDialog() |
08b97268 WS |
1270 | wxUnusedVar(hDlg); |
1271 | #endif | |
1272 | // for WM_INITDIALOG, returning TRUE tells system to set focus to | |
1273 | // the first control in the dialog box, but as we set the focus | |
1274 | // ourselves, we return FALSE for it as well | |
1275 | return FALSE; | |
1276 | } | |
12447831 | 1277 | } |
a48e51ce VZ |
1278 | |
1279 | // for almost all messages, returning FALSE means that we didn't process | |
1280 | // the message | |
a48e51ce | 1281 | return FALSE; |
12447831 VZ |
1282 | } |
1283 | ||
2b5f62a0 VZ |
1284 | // ============================================================================ |
1285 | // wxTLWHiddenParentModule implementation | |
1286 | // ============================================================================ | |
1287 | ||
1288 | HWND wxTLWHiddenParentModule::ms_hwnd = NULL; | |
1289 | ||
1290 | const wxChar *wxTLWHiddenParentModule::ms_className = NULL; | |
1291 | ||
1292 | bool wxTLWHiddenParentModule::OnInit() | |
1293 | { | |
1294 | ms_hwnd = NULL; | |
1295 | ms_className = NULL; | |
1296 | ||
bfbb0b4c | 1297 | return true; |
2b5f62a0 VZ |
1298 | } |
1299 | ||
1300 | void wxTLWHiddenParentModule::OnExit() | |
1301 | { | |
1302 | if ( ms_hwnd ) | |
1303 | { | |
1304 | if ( !::DestroyWindow(ms_hwnd) ) | |
1305 | { | |
1306 | wxLogLastError(_T("DestroyWindow(hidden TLW parent)")); | |
1307 | } | |
1308 | ||
1309 | ms_hwnd = NULL; | |
1310 | } | |
1311 | ||
1312 | if ( ms_className ) | |
1313 | { | |
1314 | if ( !::UnregisterClass(ms_className, wxGetInstance()) ) | |
1315 | { | |
1316 | wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")")); | |
1317 | } | |
1318 | ||
1319 | ms_className = NULL; | |
1320 | } | |
1321 | } | |
1322 | ||
1323 | /* static */ | |
1324 | HWND wxTLWHiddenParentModule::GetHWND() | |
1325 | { | |
1326 | if ( !ms_hwnd ) | |
1327 | { | |
1328 | if ( !ms_className ) | |
1329 | { | |
1330 | static const wxChar *HIDDEN_PARENT_CLASS = _T("wxTLWHiddenParent"); | |
1331 | ||
1332 | WNDCLASS wndclass; | |
1333 | wxZeroMemory(wndclass); | |
1334 | ||
1335 | wndclass.lpfnWndProc = DefWindowProc; | |
1336 | wndclass.hInstance = wxGetInstance(); | |
1337 | wndclass.lpszClassName = HIDDEN_PARENT_CLASS; | |
1338 | ||
1339 | if ( !::RegisterClass(&wndclass) ) | |
1340 | { | |
1341 | wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")")); | |
1342 | } | |
1343 | else | |
1344 | { | |
1345 | ms_className = HIDDEN_PARENT_CLASS; | |
1346 | } | |
1347 | } | |
1348 | ||
fda7962d | 1349 | ms_hwnd = ::CreateWindow(ms_className, wxEmptyString, 0, 0, 0, 0, 0, NULL, |
2b5f62a0 VZ |
1350 | (HMENU)NULL, wxGetInstance(), NULL); |
1351 | if ( !ms_hwnd ) | |
1352 | { | |
1353 | wxLogLastError(_T("CreateWindow(hidden TLW parent)")); | |
1354 | } | |
1355 | } | |
1356 | ||
1357 | return ms_hwnd; | |
1358 | } |