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