]> git.saurik.com Git - wxWidgets.git/blame - src/msw/toplevel.cpp
Moved wxToolBarSimple to deprecated library
[wxWidgets.git] / src / msw / toplevel.cpp
CommitLineData
82c9f85c
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/toplevel.cpp
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)
6c9a19aa 9// License: wxWindows licence
82c9f85c
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
82c9f85c
VZ
21 #pragma implementation "toplevel.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
3a922bb4
RL
32 #include "wx/app.h"
33 #include "wx/toplevel.h"
82c9f85c
VZ
34 #include "wx/string.h"
35 #include "wx/log.h"
36 #include "wx/intl.h"
14dd645e 37 #include "wx/frame.h"
706d74ab 38 #include "wx/containr.h" // wxSetFocusToChild()
82c9f85c
VZ
39#endif //WX_PRECOMP
40
2b5f62a0
VZ
41#include "wx/module.h"
42
82c9f85c 43#include "wx/msw/private.h"
4676948b
JS
44#include "wx/msw/winundef.h"
45
716645d3 46#include "wx/display.h"
7e25f59e 47
e121a72a
MB
48#ifndef ICON_BIG
49 #define ICON_BIG 1
50#endif
51
52#ifndef ICON_SMALL
53 #define ICON_SMALL 0
54#endif
55
82c9f85c
VZ
56// ----------------------------------------------------------------------------
57// stubs for missing functions under MicroWindows
58// ----------------------------------------------------------------------------
59
60#ifdef __WXMICROWIN__
61
c67d6888 62// static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return FALSE; }
82c9f85c
VZ
63static inline bool IsZoomed(HWND WXUNUSED(hwnd)) { return FALSE; }
64
65#endif // __WXMICROWIN__
66
12447831
VZ
67// NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
68// is not included by wxUniv build which does need wxDlgProc
61179e28
VZ
69LONG APIENTRY _EXPORT
70wxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
71
82c9f85c
VZ
72// ----------------------------------------------------------------------------
73// globals
74// ----------------------------------------------------------------------------
75
76// list of all frames and modeless dialogs
77wxWindowList wxModelessWindows;
78
b225f659
VZ
79// the name of the default wxWindows class
80extern const wxChar *wxCanvasClassName;
81
2b5f62a0
VZ
82// ----------------------------------------------------------------------------
83// wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
84// module to ensure that the window is always deleted)
85// ----------------------------------------------------------------------------
86
87class wxTLWHiddenParentModule : public wxModule
88{
89public:
90 // module init/finalize
91 virtual bool OnInit();
92 virtual void OnExit();
93
94 // get the hidden window (creates on demand)
95 static HWND GetHWND();
96
97private:
98 // the HWND of the hidden parent
99 static HWND ms_hwnd;
100
101 // the class used to create it
102 static const wxChar *ms_className;
103
104 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule)
105};
106
107IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule, wxModule)
9dfef5ac 108
82c9f85c
VZ
109// ============================================================================
110// wxTopLevelWindowMSW implementation
111// ============================================================================
112
085ad686
VZ
113BEGIN_EVENT_TABLE(wxTopLevelWindowMSW, wxTopLevelWindowBase)
114 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate)
115END_EVENT_TABLE()
116
82c9f85c
VZ
117// ----------------------------------------------------------------------------
118// wxTopLevelWindowMSW creation
119// ----------------------------------------------------------------------------
120
121void wxTopLevelWindowMSW::Init()
122{
123 m_iconized =
124 m_maximizeOnShow = FALSE;
b225f659
VZ
125
126 // unlike (almost?) all other windows, frames are created hidden
127 m_isShown = FALSE;
c641b1d2
VS
128
129 // Data to save/restore when calling ShowFullScreen
130 m_fsStyle = 0;
131 m_fsOldWindowStyle = 0;
132 m_fsIsMaximized = FALSE;
133 m_fsIsShowing = FALSE;
085ad686
VZ
134
135 m_winLastFocused = (wxWindow *)NULL;
b225f659
VZ
136}
137
b2d5a7ee 138WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const
b225f659 139{
b2d5a7ee
VZ
140 // let the base class deal with the common styles but fix the ones which
141 // don't make sense for us (we also deal with the borders ourselves)
142 WXDWORD msflags = wxWindow::MSWGetStyle
143 (
144 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exflags
31e7e89f 145 ) & ~WS_CHILD & ~WS_VISIBLE;
b225f659
VZ
146
147 // first select the kind of window being created
dfb06c62
VZ
148 //
149 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
150 // creates a window with both caption and border, hence we also test it
151 // below in some other cases
0e082993 152 if ( style & wxFRAME_TOOL_WINDOW )
b2d5a7ee 153 msflags |= WS_POPUP;
b225f659 154 else
39d2f9a7
JS
155 {
156#ifdef __WXWINCE__
157 if (msflags & WS_BORDER)
158#endif
159 msflags |= WS_OVERLAPPED;
160 }
0e082993
VZ
161
162 // border and caption styles
163 if ( style & wxRESIZE_BORDER )
4676948b
JS
164 {
165#ifndef __WXWINCE__
0e082993 166 msflags |= WS_THICKFRAME;
4676948b
JS
167#endif
168 }
0e082993
VZ
169 else if ( !(style & wxBORDER_NONE) )
170 msflags |= WS_BORDER;
39d2f9a7 171#ifndef __WXWINCE__
dfb06c62
VZ
172 else
173 msflags |= WS_POPUP;
39d2f9a7 174#endif
0e082993
VZ
175
176 if ( style & wxCAPTION )
177 msflags |= WS_CAPTION;
39d2f9a7 178#ifndef __WXWINCE__
dfb06c62 179 else
b225f659 180 msflags |= WS_POPUP;
39d2f9a7 181#endif
b225f659
VZ
182
183 // next translate the individual flags
184 if ( style & wxMINIMIZE_BOX )
185 msflags |= WS_MINIMIZEBOX;
186 if ( style & wxMAXIMIZE_BOX )
187 msflags |= WS_MAXIMIZEBOX;
b225f659
VZ
188 if ( style & wxSYSTEM_MENU )
189 msflags |= WS_SYSMENU;
4676948b 190#ifndef __WXWINCE__
b225f659
VZ
191 if ( style & wxMINIMIZE )
192 msflags |= WS_MINIMIZE;
193 if ( style & wxMAXIMIZE )
194 msflags |= WS_MAXIMIZE;
4676948b 195#endif
0e082993 196
b225f659
VZ
197 // Keep this here because it saves recoding this function in wxTinyFrame
198#if wxUSE_ITSY_BITSY && !defined(__WIN32__)
199 if ( style & wxTINY_CAPTION_VERT )
200 msflags |= IBS_VERTCAPTION;
201 if ( style & wxTINY_CAPTION_HORIZ )
202 msflags |= IBS_HORZCAPTION;
203#else
204 if ( style & (wxTINY_CAPTION_VERT | wxTINY_CAPTION_HORIZ) )
205 msflags |= WS_CAPTION;
206#endif
207
208 if ( exflags )
209 {
4ce1efe1 210#if !defined(__WIN16__)
35bf863b
VZ
211 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) )
212 {
9dfef5ac
VZ
213 if ( style & wxFRAME_TOOL_WINDOW )
214 {
215 // create the palette-like window
35bf863b 216 *exflags |= WS_EX_TOOLWINDOW;
9dfef5ac
VZ
217 }
218
219 // We have to solve 2 different problems here:
220 //
221 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
222 // taskbar even if they don't have a parent
223 //
224 // 2. frames without this style should appear in the taskbar even
225 // if they're owned (Windows only puts non owned windows into
226 // the taskbar normally)
227 //
228 // The second one is solved here by using WS_EX_APPWINDOW flag, the
229 // first one is dealt with in our MSWGetParent() method
230 // implementation
4676948b 231#ifndef __WXWINCE__
9dfef5ac
VZ
232 if ( !(style & wxFRAME_NO_TASKBAR) && GetParent() )
233 {
234 // need to force the frame to appear in the taskbar
35bf863b 235 *exflags |= WS_EX_APPWINDOW;
9dfef5ac 236 }
4676948b 237#endif
9dfef5ac 238 //else: nothing to do [here]
35bf863b
VZ
239 }
240#endif // !Win16
b225f659
VZ
241
242 if ( style & wxSTAY_ON_TOP )
243 *exflags |= WS_EX_TOPMOST;
244
245#ifdef __WIN32__
b2d5a7ee 246 if ( GetExtraStyle() & wxFRAME_EX_CONTEXTHELP )
68d02db3 247 *exflags |= WS_EX_CONTEXTHELP;
b225f659
VZ
248#endif // __WIN32__
249 }
250
251 return msflags;
252}
253
9dfef5ac
VZ
254WXHWND wxTopLevelWindowMSW::MSWGetParent() const
255{
256 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
257 // parent HWND or it would be always on top of its parent which is not what
258 // we usually want (in fact, we only want it for frames with the
259 // wxFRAME_FLOAT_ON_PARENT flag)
2b5f62a0 260 HWND hwndParent = NULL;
9dfef5ac
VZ
261 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) )
262 {
2b5f62a0 263 const wxWindow *parent = GetParent();
9dfef5ac 264
2b5f62a0
VZ
265 if ( !parent )
266 {
267 // this flag doesn't make sense then and will be ignored
268 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
269 }
270 else
271 {
272 hwndParent = GetHwndOf(parent);
273 }
9dfef5ac 274 }
2b5f62a0 275 //else: don't float on parent, must not be owned
9dfef5ac
VZ
276
277 // now deal with the 2nd taskbar-related problem (see comments above in
278 // MSWGetStyle())
2b5f62a0 279 if ( HasFlag(wxFRAME_NO_TASKBAR) && !hwndParent )
9dfef5ac 280 {
2b5f62a0
VZ
281 // use hidden parent
282 hwndParent = wxTLWHiddenParentModule::GetHWND();
9dfef5ac
VZ
283 }
284
2b5f62a0 285 return (WXHWND)hwndParent;
9dfef5ac
VZ
286}
287
6e8515a3 288bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate,
b225f659
VZ
289 const wxString& title,
290 const wxPoint& pos,
291 const wxSize& size)
292{
293#ifdef __WXMICROWIN__
294 // no dialogs support under MicroWin yet
295 return CreateFrame(title, pos, size);
296#else // !__WXMICROWIN__
297 wxWindow *parent = GetParent();
298
299 // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
300 // app window as parent - this avoids creating modal dialogs without
301 // parent
302 if ( !parent && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
303 {
304 parent = wxTheApp->GetTopWindow();
e058b98d 305
39cc7a0b 306 if ( parent )
e058b98d 307 {
39cc7a0b
VZ
308 // don't use transient windows as parents, this is dangerous as it
309 // can lead to a crash if the parent is destroyed before the child
310 //
311 // also don't use the window which is currently hidden as then the
312 // dialog would be hidden as well
313 if ( (parent->GetExtraStyle() & wxWS_EX_TRANSIENT) ||
314 !parent->IsShown() )
315 {
316 parent = NULL;
317 }
e058b98d 318 }
b225f659
VZ
319 }
320
434005ca
VZ
321 m_hWnd = (WXHWND)::CreateDialogIndirect
322 (
323 wxGetInstance(),
324 (DLGTEMPLATE*)dlgTemplate,
325 parent ? GetHwndOf(parent) : NULL,
326 (DLGPROC)wxDlgProc
327 );
b225f659
VZ
328
329 if ( !m_hWnd )
330 {
7e99eddf 331 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
b225f659 332
7e99eddf 333 wxLogSysError(wxT("Can't create dialog using memory template"));
b225f659
VZ
334
335 return FALSE;
336 }
337
b2d5a7ee 338 WXDWORD exflags;
b225f659
VZ
339 (void)MSWGetCreateWindowFlags(&exflags);
340
341 if ( exflags )
342 {
343 ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, exflags);
cef338d3
VZ
344 ::SetWindowPos(GetHwnd(),
345 exflags & WS_EX_TOPMOST ? HWND_TOPMOST : 0,
346 0, 0, 0, 0,
b225f659
VZ
347 SWP_NOSIZE |
348 SWP_NOMOVE |
cef338d3 349 (exflags & WS_EX_TOPMOST ? 0 : SWP_NOZORDER) |
b225f659
VZ
350 SWP_NOACTIVATE);
351 }
352
353#if defined(__WIN95__)
354 // For some reason, the system menu is activated when we use the
355 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
356 if ( exflags & WS_EX_CONTEXTHELP )
357 {
358 wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame);
359 if ( winTop )
360 {
361 wxIcon icon = winTop->GetIcon();
362 if ( icon.Ok() )
363 {
364 ::SendMessage(GetHwnd(), WM_SETICON,
365 (WPARAM)TRUE,
366 (LPARAM)GetHiconOf(icon));
367 }
368 }
369 }
370#endif // __WIN95__
371
372 // move the dialog to its initial position without forcing repainting
373 int x, y, w, h;
4c53c743 374 if ( !MSWGetCreateWindowCoords(pos, size, x, y, w, h) )
b225f659 375 {
4c53c743
VZ
376 x =
377 w = (int)CW_USEDEFAULT;
378 }
f04a0744 379
4c53c743
VZ
380 // we can't use CW_USEDEFAULT here as we're not calling CreateWindow()
381 // and passing CW_USEDEFAULT to MoveWindow() results in resizing the
382 // window to (0, 0) size which breaks quite a lot of things, e.g. the
383 // sizer calculation in wxSizer::Fit()
384 if ( w == (int)CW_USEDEFAULT )
385 {
386 // the exact number doesn't matter, the dialog will be resized
387 // again soon anyhow but it should be big enough to allow
388 // calculation relying on "totalSize - clientSize > 0" work, i.e.
389 // at least greater than the title bar height
390 w =
391 h = 100;
392 }
f0adbe0f 393
4c53c743
VZ
394 if ( x == (int)CW_USEDEFAULT )
395 {
396 // centre it on the screen - what else can we do?
397 wxSize sizeDpy = wxGetDisplaySize();
398
399 x = (sizeDpy.x - w) / 2;
400 y = (sizeDpy.y - h) / 2;
401 }
402
403 if ( !::MoveWindow(GetHwnd(), x, y, w, h, FALSE) )
404 {
405 wxLogLastError(wxT("MoveWindow"));
b225f659 406 }
b225f659
VZ
407
408 if ( !title.empty() )
409 {
410 ::SetWindowText(GetHwnd(), title);
411 }
412
413 SubclassWin(m_hWnd);
414
415 return TRUE;
416#endif // __WXMICROWIN__/!__WXMICROWIN__
417}
418
419bool wxTopLevelWindowMSW::CreateFrame(const wxString& title,
420 const wxPoint& pos,
421 const wxSize& size)
422{
b2d5a7ee
VZ
423 WXDWORD exflags;
424 WXDWORD flags = MSWGetCreateWindowFlags(&exflags);
b225f659
VZ
425
426 return MSWCreate(wxCanvasClassName, title, pos, size, flags, exflags);
82c9f85c
VZ
427}
428
429bool wxTopLevelWindowMSW::Create(wxWindow *parent,
430 wxWindowID id,
431 const wxString& title,
432 const wxPoint& pos,
433 const wxSize& size,
434 long style,
435 const wxString& name)
436{
9ca4dd06
VS
437 bool ret = false;
438
82c9f85c
VZ
439 // init our fields
440 Init();
441
442 m_windowStyle = style;
443
444 SetName(name);
445
446 m_windowId = id == -1 ? NewControlId() : id;
447
448 wxTopLevelWindows.Append(this);
449
450 if ( parent )
451 parent->AddChild(this);
452
b225f659
VZ
453 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
454 {
b225f659
VZ
455 // we have different dialog templates to allows creation of dialogs
456 // with & without captions under MSWindows, resizeable or not (but a
457 // resizeable dialog always has caption - otherwise it would look too
458 // strange)
434005ca
VZ
459
460 // we need 3 additional WORDs for dialog menu, class and title (as we
461 // don't use DS_SETFONT we don't need the fourth WORD for the font)
462 static const int dlgsize = sizeof(DLGTEMPLATE) + (sizeof(WORD) * 3);
463 DLGTEMPLATE *dlgTemplate = (DLGTEMPLATE *)malloc(dlgsize);
464 memset(dlgTemplate, 0, dlgsize);
465
466 // these values are arbitrary, they won't be used normally anyhow
6e8515a3
JS
467 dlgTemplate->x = 34;
468 dlgTemplate->y = 22;
469 dlgTemplate->cx = 144;
470 dlgTemplate->cy = 75;
471
434005ca
VZ
472 // reuse the code in MSWGetStyle() but correct the results slightly for
473 // the dialog
474 dlgTemplate->style = MSWGetStyle(style, NULL);
475
476 // all dialogs are popups
477 dlgTemplate->style |= WS_POPUP;
478
479 // force 3D-look if necessary, it looks impossibly ugly otherwise
480 if ( style & (wxRESIZE_BORDER | wxCAPTION) )
481 dlgTemplate->style |= DS_MODALFRAME;
b225f659 482
9ca4dd06 483 ret = CreateDialog(dlgTemplate, title, pos, size);
6e8515a3 484 free(dlgTemplate);
b225f659
VZ
485 }
486 else // !dialog
487 {
9ca4dd06
VS
488 ret = CreateFrame(title, pos, size);
489 }
490
491 if ( ret && !(GetWindowStyleFlag() & wxCLOSE_BOX) )
492 {
493 EnableCloseButton(false);
b225f659 494 }
9ca4dd06
VS
495
496 return ret;
82c9f85c
VZ
497}
498
499wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
500{
82c9f85c
VZ
501 if ( wxModelessWindows.Find(this) )
502 wxModelessWindows.DeleteObject(this);
503
d6fb86a8
VZ
504 // after destroying an owned window, Windows activates the next top level
505 // window in Z order but it may be different from our owner (to reproduce
506 // this simply Alt-TAB to another application and back before closing the
507 // owned frame) whereas we always want to yield activation to our parent
508 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) )
509 {
510 wxWindow *parent = GetParent();
511 if ( parent )
512 {
513 ::BringWindowToTop(GetHwndOf(parent));
514 }
515 }
82c9f85c
VZ
516}
517
82c9f85c
VZ
518// ----------------------------------------------------------------------------
519// wxTopLevelWindowMSW showing
520// ----------------------------------------------------------------------------
521
522void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd)
523{
524 ::ShowWindow(GetHwnd(), nShowCmd);
525
526 m_iconized = nShowCmd == SW_MINIMIZE;
527}
528
529bool wxTopLevelWindowMSW::Show(bool show)
530{
531 // don't use wxWindow version as we want to call DoShowWindow() ourselves
532 if ( !wxWindowBase::Show(show) )
533 return FALSE;
534
535 int nShowCmd;
536 if ( show )
537 {
538 if ( m_maximizeOnShow )
539 {
540 // show and maximize
541 nShowCmd = SW_MAXIMIZE;
542
543 m_maximizeOnShow = FALSE;
544 }
545 else // just show
546 {
84cff965
JS
547 if ( GetWindowStyle() & wxFRAME_TOOL_WINDOW )
548 nShowCmd = SW_SHOWNA;
549 else
550 nShowCmd = SW_SHOW;
82c9f85c
VZ
551 }
552 }
553 else // hide
554 {
555 nShowCmd = SW_HIDE;
556 }
557
558 DoShowWindow(nShowCmd);
559
560 if ( show )
561 {
562 ::BringWindowToTop(GetHwnd());
563
564 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId);
565 event.SetEventObject( this );
566 GetEventHandler()->ProcessEvent(event);
567 }
568 else // hide
569 {
570 // Try to highlight the correct window (the parent)
571 if ( GetParent() )
572 {
573 HWND hWndParent = GetHwndOf(GetParent());
574 if (hWndParent)
575 ::BringWindowToTop(hWndParent);
576 }
577 }
578
579 return TRUE;
580}
581
582// ----------------------------------------------------------------------------
583// wxTopLevelWindowMSW maximize/minimize
584// ----------------------------------------------------------------------------
585
586void wxTopLevelWindowMSW::Maximize(bool maximize)
587{
588 if ( IsShown() )
589 {
590 // just maximize it directly
591 DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE);
592 }
593 else // hidden
594 {
595 // we can't maximize the hidden frame because it shows it as well, so
596 // just remember that we should do it later in this case
a0be434e 597 m_maximizeOnShow = maximize;
82c9f85c
VZ
598 }
599}
600
601bool wxTopLevelWindowMSW::IsMaximized() const
602{
4676948b
JS
603#ifdef __WXWINCE__
604 return FALSE;
605#else
82c9f85c 606 return ::IsZoomed(GetHwnd()) != 0;
4676948b 607#endif
82c9f85c
VZ
608}
609
610void wxTopLevelWindowMSW::Iconize(bool iconize)
611{
612 DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE);
613}
614
615bool wxTopLevelWindowMSW::IsIconized() const
616{
4676948b
JS
617#ifdef __WXWINCE__
618 return FALSE;
619#else
82c9f85c
VZ
620 // also update the current state
621 ((wxTopLevelWindowMSW *)this)->m_iconized = ::IsIconic(GetHwnd()) != 0;
622
623 return m_iconized;
4676948b 624#endif
82c9f85c
VZ
625}
626
627void wxTopLevelWindowMSW::Restore()
628{
629 DoShowWindow(SW_RESTORE);
630}
631
c641b1d2
VS
632// ----------------------------------------------------------------------------
633// wxTopLevelWindowMSW fullscreen
634// ----------------------------------------------------------------------------
635
636bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style)
637{
716645d3 638 if ( show == IsFullScreen() )
c641b1d2 639 {
716645d3
VZ
640 // nothing to do
641 return TRUE;
642 }
643
644 m_fsIsShowing = show;
c641b1d2 645
716645d3
VZ
646 if ( show )
647 {
c641b1d2
VS
648 m_fsStyle = style;
649
650 // zap the frame borders
651
652 // save the 'normal' window style
716645d3 653 m_fsOldWindowStyle = GetWindowLong(GetHwnd(), GWL_STYLE);
c641b1d2
VS
654
655 // save the old position, width & height, maximize state
656 m_fsOldSize = GetRect();
657 m_fsIsMaximized = IsMaximized();
658
659 // decide which window style flags to turn off
660 LONG newStyle = m_fsOldWindowStyle;
661 LONG offFlags = 0;
662
663 if (style & wxFULLSCREEN_NOBORDER)
4676948b
JS
664 {
665 offFlags |= WS_BORDER;
666#ifndef __WXWINCE__
667 offFlags |= WS_THICKFRAME;
668#endif
669 }
c641b1d2 670 if (style & wxFULLSCREEN_NOCAPTION)
716645d3 671 offFlags |= WS_CAPTION | WS_SYSMENU;
c641b1d2 672
716645d3 673 newStyle &= ~offFlags;
c641b1d2
VS
674
675 // change our window style to be compatible with full-screen mode
716645d3 676 ::SetWindowLong(GetHwnd(), GWL_STYLE, newStyle);
c641b1d2 677
716645d3
VZ
678 wxRect rect;
679#if wxUSE_DISPLAY
680 // resize to the size of the display containing us
681 int dpy = wxDisplay::GetFromWindow(this);
682 if ( dpy != wxNOT_FOUND )
683 {
684 rect = wxDisplay(dpy).GetGeometry();
685 }
686 else // fall back to the main desktop
687#else // wxUSE_DISPLAY
688 {
4676948b
JS
689 // FIXME: implement for WinCE
690#ifndef __WXWINCE__
716645d3
VZ
691 // resize to the size of the desktop
692 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect);
4676948b 693#endif
716645d3
VZ
694 }
695#endif // wxUSE_DISPLAY
c641b1d2 696
716645d3 697 SetSize(rect);
c641b1d2
VS
698
699 // now flush the window style cache and actually go full-screen
716645d3 700 long flags = SWP_FRAMECHANGED;
c641b1d2 701
716645d3
VZ
702 // showing the frame full screen should also show it if it's still
703 // hidden
704 if ( !IsShown() )
705 {
706 // don't call wxWindow version to avoid flicker from calling
707 // ::ShowWindow() -- we're going to show the window at the correct
708 // location directly below -- but do call the wxWindowBase version
709 // to sync the internal m_isShown flag
710 wxWindowBase::Show();
c641b1d2 711
716645d3
VZ
712 flags |= SWP_SHOWWINDOW;
713 }
c641b1d2 714
716645d3
VZ
715 SetWindowPos(GetHwnd(), HWND_TOP,
716 rect.x, rect.y, rect.width, rect.height,
717 flags);
c641b1d2 718
716645d3
VZ
719 // finally send an event allowing the window to relayout itself &c
720 wxSizeEvent event(rect.GetSize(), GetId());
721 GetEventHandler()->ProcessEvent(event);
722 }
723 else // stop showing full screen
724 {
c641b1d2 725 Maximize(m_fsIsMaximized);
716645d3
VZ
726 SetWindowLong(GetHwnd(),GWL_STYLE, m_fsOldWindowStyle);
727 SetWindowPos(GetHwnd(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
c641b1d2 728 m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
c641b1d2 729 }
716645d3
VZ
730
731 return TRUE;
c641b1d2
VS
732}
733
82c9f85c
VZ
734// ----------------------------------------------------------------------------
735// wxTopLevelWindowMSW misc
736// ----------------------------------------------------------------------------
737
738void wxTopLevelWindowMSW::SetIcon(const wxIcon& icon)
739{
f618020a
MB
740 SetIcons( wxIconBundle( icon ) );
741}
742
743void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons)
744{
745 wxTopLevelWindowBase::SetIcons(icons);
82c9f85c
VZ
746
747#if defined(__WIN95__) && !defined(__WXMICROWIN__)
f618020a
MB
748 const wxIcon& sml = icons.GetIcon( wxSize( 16, 16 ) );
749 if( sml.Ok() && sml.GetWidth() == 16 && sml.GetHeight() == 16 )
750 {
751 ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_SMALL,
752 (LPARAM)GetHiconOf(sml) );
753 }
754
755 const wxIcon& big = icons.GetIcon( wxSize( 32, 32 ) );
756 if( big.Ok() && big.GetWidth() == 32 && big.GetHeight() == 32 )
82c9f85c 757 {
f618020a
MB
758 ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_BIG,
759 (LPARAM)GetHiconOf(big) );
82c9f85c
VZ
760 }
761#endif // __WIN95__
762}
a91cf80c
VZ
763
764bool wxTopLevelWindowMSW::EnableCloseButton(bool enable)
765{
4676948b 766#if !defined(__WXMICROWIN__)
a91cf80c 767 // get system (a.k.a. window) menu
4676948b 768 HMENU hmenu = GetSystemMenu(GetHwnd(), FALSE /* get it */);
a91cf80c
VZ
769 if ( !hmenu )
770 {
660b1906
VZ
771 // no system menu at all -- ok if we want to remove the close button
772 // anyhow, but bad if we want to show it
773 return !enable;
a91cf80c
VZ
774 }
775
776 // enabling/disabling the close item from it also automatically
777 // disables/enables the close title bar button
aaf765a5
VZ
778 if ( ::EnableMenuItem(hmenu, SC_CLOSE,
779 MF_BYCOMMAND |
780 (enable ? MF_ENABLED : MF_GRAYED)) == -1 )
a91cf80c
VZ
781 {
782 wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
783
784 return FALSE;
785 }
786
787 // update appearance immediately
788 if ( !::DrawMenuBar(GetHwnd()) )
789 {
790 wxLogLastError(_T("DrawMenuBar"));
791 }
792#endif // !__WXMICROWIN__
793
794 return TRUE;
795}
796
1542ea39
RD
797bool wxTopLevelWindowMSW::SetShape(const wxRegion& region)
798{
4676948b
JS
799#ifdef __WXWINCE__
800 return FALSE;
801#else
6a7e6411
RD
802 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), FALSE,
803 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
804
1542ea39
RD
805 // The empty region signifies that the shape should be removed from the
806 // window.
807 if ( region.IsEmpty() )
808 {
809 if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0)
810 {
811 wxLogLastError(_T("SetWindowRgn"));
812 return FALSE;
813 }
814 return TRUE;
815 }
816
817 // Windows takes ownership of the region, so
818 // we'll have to make a copy of the region to give to it.
819 DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL);
820 RGNDATA *rgnData = (RGNDATA*) new char[noBytes];
821 ::GetRegionData(GetHrgnOf(region), noBytes, rgnData);
822 HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData);
823 delete[] (char*) rgnData;
824
825 // SetWindowRgn expects the region to be in coordinants
826 // relative to the window, not the client area. Figure
827 // out the offset, if any.
828 RECT rect;
829 DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
830 DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
831 ::GetClientRect(GetHwnd(), &rect);
832 ::AdjustWindowRectEx(&rect, dwStyle, FALSE, dwExStyle);
833 ::OffsetRgn(hrgn, -rect.left, -rect.top);
834
835 // Now call the shape API with the new region.
836 if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0)
837 {
838 wxLogLastError(_T("SetWindowRgn"));
839 return FALSE;
840 }
841 return TRUE;
4676948b 842#endif
1542ea39
RD
843}
844
085ad686
VZ
845// ----------------------------------------------------------------------------
846// wxTopLevelWindow event handling
847// ----------------------------------------------------------------------------
848
849// Default activation behaviour - set the focus for the first child
850// subwindow found.
851void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
852{
853 if ( event.GetActive() )
854 {
855 // restore focus to the child which was last focused
9b601c24 856 wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd);
085ad686
VZ
857
858 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
859 : NULL;
860 if ( !parent )
861 {
862 parent = this;
863 }
864
865 wxSetFocusToChild(parent, &m_winLastFocused);
866 }
867 else // deactivating
868 {
869 // remember the last focused child if it is our child
870 m_winLastFocused = FindFocus();
871
13834828
VZ
872 if ( m_winLastFocused )
873 {
874 // let it know that it doesn't have focus any more
77e00fe9 875 m_winLastFocused->HandleKillFocus((WXHWND)NULL);
13834828
VZ
876 }
877
085ad686
VZ
878 // so we NULL it out if it's a child from some other frame
879 wxWindow *win = m_winLastFocused;
880 while ( win )
881 {
882 if ( win->IsTopLevel() )
883 {
884 if ( win != this )
885 {
886 m_winLastFocused = NULL;
887 }
888
889 break;
890 }
891
892 win = win->GetParent();
893 }
894
895 wxLogTrace(_T("focus"),
896 _T("wxTLW %08x deactivated, last focused: %08x."),
9b601c24
GRG
897 (int) m_hWnd,
898 (int) (m_winLastFocused ? GetHwndOf(m_winLastFocused)
899 : NULL));
085ad686
VZ
900
901 event.Skip();
902 }
903}
904
12447831
VZ
905// the DialogProc for all wxWindows dialogs
906LONG APIENTRY _EXPORT
2eb10e2a
VZ
907wxDlgProc(HWND WXUNUSED(hDlg),
908 UINT message,
909 WPARAM WXUNUSED(wParam),
910 LPARAM WXUNUSED(lParam))
12447831
VZ
911{
912 switch ( message )
913 {
914 case WM_INITDIALOG:
915 // for this message, returning TRUE tells system to set focus to
916 // the first control in the dialog box, but as we set the focus
917 // ourselves, we return FALSE from here as well, so fall through
918
919 default:
920 // for all the other ones, FALSE means that we didn't process the
921 // message
922 return FALSE;
923 }
924}
925
2b5f62a0
VZ
926// ============================================================================
927// wxTLWHiddenParentModule implementation
928// ============================================================================
929
930HWND wxTLWHiddenParentModule::ms_hwnd = NULL;
931
932const wxChar *wxTLWHiddenParentModule::ms_className = NULL;
933
934bool wxTLWHiddenParentModule::OnInit()
935{
936 ms_hwnd = NULL;
937 ms_className = NULL;
938
939 return TRUE;
940}
941
942void wxTLWHiddenParentModule::OnExit()
943{
944 if ( ms_hwnd )
945 {
946 if ( !::DestroyWindow(ms_hwnd) )
947 {
948 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
949 }
950
951 ms_hwnd = NULL;
952 }
953
954 if ( ms_className )
955 {
956 if ( !::UnregisterClass(ms_className, wxGetInstance()) )
957 {
958 wxLogLastError(_T("UnregisterClass(\"wxTLWHiddenParent\")"));
959 }
960
961 ms_className = NULL;
962 }
963}
964
965/* static */
966HWND wxTLWHiddenParentModule::GetHWND()
967{
968 if ( !ms_hwnd )
969 {
970 if ( !ms_className )
971 {
972 static const wxChar *HIDDEN_PARENT_CLASS = _T("wxTLWHiddenParent");
973
974 WNDCLASS wndclass;
975 wxZeroMemory(wndclass);
976
977 wndclass.lpfnWndProc = DefWindowProc;
978 wndclass.hInstance = wxGetInstance();
979 wndclass.lpszClassName = HIDDEN_PARENT_CLASS;
980
981 if ( !::RegisterClass(&wndclass) )
982 {
983 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
984 }
985 else
986 {
987 ms_className = HIDDEN_PARENT_CLASS;
988 }
989 }
990
fda7962d 991 ms_hwnd = ::CreateWindow(ms_className, wxEmptyString, 0, 0, 0, 0, 0, NULL,
2b5f62a0
VZ
992 (HMENU)NULL, wxGetInstance(), NULL);
993 if ( !ms_hwnd )
994 {
995 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));
996 }
997 }
998
999 return ms_hwnd;
1000}
1001
1542ea39 1002