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