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