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