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