]> git.saurik.com Git - wxWidgets.git/blob - src/msw/toplevel.cpp
Fix bug with using incorrect negative ids in wxEVT_MENU_HIGHLIGHT events.
[wxWidgets.git] / src / msw / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/toplevel.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #include "wx/dialog.h"
32 #include "wx/string.h"
33 #include "wx/log.h"
34 #include "wx/intl.h"
35 #include "wx/frame.h"
36 #include "wx/containr.h" // wxSetFocusToChild()
37 #include "wx/module.h"
38 #endif //WX_PRECOMP
39
40 #include "wx/dynlib.h"
41
42 #include "wx/msw/private.h"
43 #if defined(__WXWINCE__) && !defined(__HANDHELDPC__)
44 #include <ole2.h>
45 #include <shellapi.h>
46 // Standard SDK doesn't have aygshell.dll: see include/wx/msw/wince/libraries.h
47 #if _WIN32_WCE < 400 || !defined(__WINCE_STANDARDSDK__)
48 #include <aygshell.h>
49 #endif
50 #endif
51
52 #include "wx/msw/winundef.h"
53 #include "wx/msw/missing.h"
54
55 #include "wx/display.h"
56
57 #ifndef ICON_BIG
58 #define ICON_BIG 1
59 #endif
60
61 #ifndef ICON_SMALL
62 #define ICON_SMALL 0
63 #endif
64
65 // ----------------------------------------------------------------------------
66 // stubs for missing functions under MicroWindows
67 // ----------------------------------------------------------------------------
68
69 #ifdef __WXMICROWIN__
70
71 // static inline bool IsIconic(HWND WXUNUSED(hwnd)) { return false; }
72 static inline bool IsZoomed(HWND WXUNUSED(hwnd)) { return false; }
73
74 #endif // __WXMICROWIN__
75
76 // NB: wxDlgProc must be defined here and not in dialog.cpp because the latter
77 // is not included by wxUniv build which does need wxDlgProc
78 LONG APIENTRY _EXPORT
79 wxDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
80
81 // ----------------------------------------------------------------------------
82 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
83 // module to ensure that the window is always deleted)
84 // ----------------------------------------------------------------------------
85
86 class wxTLWHiddenParentModule : public wxModule
87 {
88 public:
89 // module init/finalize
90 virtual bool OnInit();
91 virtual void OnExit();
92
93 // get the hidden window (creates on demand)
94 static HWND GetHWND();
95
96 private:
97 // the HWND of the hidden parent
98 static HWND ms_hwnd;
99
100 // the class used to create it
101 static const wxChar *ms_className;
102
103 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule)
104 };
105
106 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule, wxModule)
107
108 // ============================================================================
109 // wxTopLevelWindowMSW implementation
110 // ============================================================================
111
112 BEGIN_EVENT_TABLE(wxTopLevelWindowMSW, wxTopLevelWindowBase)
113 EVT_ACTIVATE(wxTopLevelWindowMSW::OnActivate)
114 END_EVENT_TABLE()
115
116 // ----------------------------------------------------------------------------
117 // wxTopLevelWindowMSW creation
118 // ----------------------------------------------------------------------------
119
120 void wxTopLevelWindowMSW::Init()
121 {
122 m_iconized =
123 m_maximizeOnShow = false;
124
125 // Data to save/restore when calling ShowFullScreen
126 m_fsStyle = 0;
127 m_fsOldWindowStyle = 0;
128 m_fsIsMaximized = false;
129 m_fsIsShowing = false;
130
131 m_winLastFocused = NULL;
132
133 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
134 m_MenuBarHWND = 0;
135 #endif
136
137 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
138 SHACTIVATEINFO* info = new SHACTIVATEINFO;
139 wxZeroMemory(*info);
140 info->cbSize = sizeof(SHACTIVATEINFO);
141
142 m_activateInfo = (void*) info;
143 #endif
144 }
145
146 WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const
147 {
148 // let the base class deal with the common styles but fix the ones which
149 // don't make sense for us (we also deal with the borders ourselves)
150 WXDWORD msflags = wxWindow::MSWGetStyle
151 (
152 (style & ~wxBORDER_MASK) | wxBORDER_NONE, exflags
153 ) & ~WS_CHILD & ~WS_VISIBLE;
154
155 // For some reason, WS_VISIBLE needs to be defined on creation for
156 // SmartPhone 2003. The title can fail to be displayed otherwise.
157 #if defined(__SMARTPHONE__) || (defined(__WXWINCE__) && _WIN32_WCE < 400)
158 msflags |= WS_VISIBLE;
159 ((wxTopLevelWindowMSW*)this)->wxWindowBase::Show(true);
160 #endif
161
162 // first select the kind of window being created
163 //
164 // note that if we don't set WS_POPUP, Windows assumes WS_OVERLAPPED and
165 // creates a window with both caption and border, hence we need to use
166 // WS_POPUP in a few cases just to avoid having caption/border which we
167 // don't want
168
169 // border and caption styles
170 if ( ( style & wxRESIZE_BORDER ) && !IsAlwaysMaximized())
171 msflags |= WS_THICKFRAME;
172 else if ( exflags && ((style & wxBORDER_DOUBLE) || (style & wxBORDER_RAISED)) )
173 *exflags |= WS_EX_DLGMODALFRAME;
174 else if ( !(style & wxBORDER_NONE) )
175 msflags |= WS_BORDER;
176 #ifndef __POCKETPC__
177 else
178 msflags |= WS_POPUP;
179 #endif
180
181 // normally we consider that all windows without a caption must be popups,
182 // but CE is an exception: there windows normally do not have the caption
183 // but shouldn't be made popups as popups can't have menus and don't look
184 // like normal windows anyhow
185
186 // TODO: Smartphone appears to like wxCAPTION, but we should check that
187 // we need it.
188 #if defined(__SMARTPHONE__) || !defined(__WXWINCE__)
189 if ( style & wxCAPTION )
190 msflags |= WS_CAPTION;
191 #ifndef __WXWINCE__
192 else
193 msflags |= WS_POPUP;
194 #endif // !__WXWINCE__
195 #endif
196
197 // next translate the individual flags
198
199 // WS_EX_CONTEXTHELP is incompatible with WS_MINIMIZEBOX and WS_MAXIMIZEBOX
200 // and is ignored if we specify both of them, but chances are that if we
201 // use wxWS_EX_CONTEXTHELP, we really do want to have the context help
202 // button while wxMINIMIZE/wxMAXIMIZE are included by default, so the help
203 // takes precedence
204 if ( !(GetExtraStyle() & wxWS_EX_CONTEXTHELP) )
205 {
206 if ( style & wxMINIMIZE_BOX )
207 msflags |= WS_MINIMIZEBOX;
208 if ( style & wxMAXIMIZE_BOX )
209 msflags |= WS_MAXIMIZEBOX;
210 }
211
212 #ifndef __WXWINCE__
213 // notice that if wxCLOSE_BOX is specified we need to use WS_SYSMENU too as
214 // otherwise the close box doesn't appear
215 if ( style & (wxSYSTEM_MENU | wxCLOSE_BOX) )
216 msflags |= WS_SYSMENU;
217 #endif // !__WXWINCE__
218
219 // NB: under CE these 2 styles are not supported currently, we should
220 // call Minimize()/Maximize() "manually" if we want to support them
221 if ( style & wxMINIMIZE )
222 msflags |= WS_MINIMIZE;
223
224 if ( style & wxMAXIMIZE )
225 msflags |= WS_MAXIMIZE;
226
227 // Keep this here because it saves recoding this function in wxTinyFrame
228 if ( style & (wxTINY_CAPTION_VERT | wxTINY_CAPTION_HORIZ) )
229 msflags |= WS_CAPTION;
230
231 if ( exflags )
232 {
233 // there is no taskbar under CE, so omit all this
234 #if !defined(__WXWINCE__)
235 if ( !(GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) )
236 {
237 if ( style & wxFRAME_TOOL_WINDOW )
238 {
239 // create the palette-like window
240 *exflags |= WS_EX_TOOLWINDOW;
241
242 // tool windows shouldn't appear on the taskbar (as documented)
243 style |= wxFRAME_NO_TASKBAR;
244 }
245
246 // We have to solve 2 different problems here:
247 //
248 // 1. frames with wxFRAME_NO_TASKBAR flag shouldn't appear in the
249 // taskbar even if they don't have a parent
250 //
251 // 2. frames without this style should appear in the taskbar even
252 // if they're owned (Windows only puts non owned windows into
253 // the taskbar normally)
254 //
255 // The second one is solved here by using WS_EX_APPWINDOW flag, the
256 // first one is dealt with in our MSWGetParent() method
257 // implementation
258 if ( !(style & wxFRAME_NO_TASKBAR) && GetParent() )
259 {
260 // need to force the frame to appear in the taskbar
261 *exflags |= WS_EX_APPWINDOW;
262 }
263 //else: nothing to do [here]
264 }
265
266 if ( GetExtraStyle() & wxWS_EX_CONTEXTHELP )
267 *exflags |= WS_EX_CONTEXTHELP;
268 #endif // !__WXWINCE__
269
270 if ( style & wxSTAY_ON_TOP )
271 *exflags |= WS_EX_TOPMOST;
272 }
273
274 return msflags;
275 }
276
277 WXHWND wxTopLevelWindowMSW::MSWGetParent() const
278 {
279 // for the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
280 // parent HWND or it would be always on top of its parent which is not what
281 // we usually want (in fact, we only want it for frames with the
282 // wxFRAME_FLOAT_ON_PARENT flag)
283 HWND hwndParent = NULL;
284 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) )
285 {
286 const wxWindow *parent = GetParent();
287
288 if ( !parent )
289 {
290 // this flag doesn't make sense then and will be ignored
291 wxFAIL_MSG( wxT("wxFRAME_FLOAT_ON_PARENT but no parent?") );
292 }
293 else
294 {
295 hwndParent = GetHwndOf(parent);
296 }
297 }
298 //else: don't float on parent, must not be owned
299
300 // now deal with the 2nd taskbar-related problem (see comments above in
301 // MSWGetStyle())
302 if ( HasFlag(wxFRAME_NO_TASKBAR) && !hwndParent )
303 {
304 // use hidden parent
305 hwndParent = wxTLWHiddenParentModule::GetHWND();
306 }
307
308 return (WXHWND)hwndParent;
309 }
310
311 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
312 bool wxTopLevelWindowMSW::HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam)
313 {
314 SHACTIVATEINFO *info = (SHACTIVATEINFO*) m_activateInfo;
315 if ( info )
316 {
317 SHHandleWMSettingChange(GetHwnd(), wParam, lParam, info);
318 }
319
320 return wxWindowMSW::HandleSettingChange(wParam, lParam);
321 }
322 #endif
323
324 WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
325 {
326 WXLRESULT rc = 0;
327 bool processed = false;
328
329 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
330 switch ( message )
331 {
332 case WM_ACTIVATE:
333 {
334 SHACTIVATEINFO* info = (SHACTIVATEINFO*) m_activateInfo;
335 if (info)
336 {
337 DWORD flags = 0;
338 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) flags = SHA_INPUTDIALOG;
339 SHHandleWMActivate(GetHwnd(), wParam, lParam, info, flags);
340 }
341
342 // This implicitly sends a wxEVT_ACTIVATE_APP event
343 if (wxTheApp)
344 wxTheApp->SetActive(wParam != 0, FindFocus());
345
346 break;
347 }
348 case WM_HIBERNATE:
349 {
350 if (wxTheApp)
351 {
352 wxActivateEvent event(wxEVT_HIBERNATE, true, wxID_ANY);
353 event.SetEventObject(wxTheApp);
354 processed = wxTheApp->ProcessEvent(event);
355 }
356 break;
357 }
358 }
359 #endif
360
361 if ( !processed )
362 rc = wxTopLevelWindowBase::MSWWindowProc(message, wParam, lParam);
363
364 return rc;
365 }
366
367 bool wxTopLevelWindowMSW::CreateDialog(const void *dlgTemplate,
368 const wxString& title,
369 const wxPoint& pos,
370 const wxSize& size)
371 {
372 #ifdef __WXMICROWIN__
373 // no dialogs support under MicroWin yet
374 return CreateFrame(title, pos, size);
375 #else // !__WXMICROWIN__
376 // static cast is valid as we're only ever called for dialogs
377 wxWindow * const
378 parent = static_cast<wxDialog *>(this)->GetParentForModalDialog();
379
380 m_hWnd = (WXHWND)::CreateDialogIndirect
381 (
382 wxGetInstance(),
383 (DLGTEMPLATE*)dlgTemplate,
384 parent ? GetHwndOf(parent) : NULL,
385 (DLGPROC)wxDlgProc
386 );
387
388 if ( !m_hWnd )
389 {
390 wxFAIL_MSG(wxT("Failed to create dialog. Incorrect DLGTEMPLATE?"));
391
392 wxLogSysError(wxT("Can't create dialog using memory template"));
393
394 return false;
395 }
396
397 #if !defined(__WXWINCE__)
398 // For some reason, the system menu is activated when we use the
399 // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
400 if ( HasExtraStyle(wxWS_EX_CONTEXTHELP) )
401 {
402 wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame);
403 if ( winTop )
404 {
405 wxIcon icon = winTop->GetIcon();
406 if ( icon.Ok() )
407 {
408 ::SendMessage(GetHwnd(), WM_SETICON,
409 (WPARAM)TRUE,
410 (LPARAM)GetHiconOf(icon));
411 }
412 }
413 }
414 #endif // !__WXWINCE__
415
416 // move the dialog to its initial position without forcing repainting
417 int x, y, w, h;
418 (void)MSWGetCreateWindowCoords(pos, size, x, y, w, h);
419
420 if ( x == (int)CW_USEDEFAULT )
421 {
422 // centre it on the screen - what else can we do?
423 wxSize sizeDpy = wxGetDisplaySize();
424
425 x = (sizeDpy.x - w) / 2;
426 y = (sizeDpy.y - h) / 2;
427 }
428
429 #if !defined(__WXWINCE__) || defined(__WINCE_STANDARDSDK__)
430 if ( !::MoveWindow(GetHwnd(), x, y, w, h, FALSE) )
431 {
432 wxLogLastError(wxT("MoveWindow"));
433 }
434 #endif
435
436 if ( !title.empty() )
437 {
438 ::SetWindowText(GetHwnd(), title.wx_str());
439 }
440
441 SubclassWin(m_hWnd);
442
443 #ifdef __SMARTPHONE__
444 // Work around title non-display glitch
445 Show(false);
446 #endif
447
448 return true;
449 #endif // __WXMICROWIN__/!__WXMICROWIN__
450 }
451
452 bool wxTopLevelWindowMSW::CreateFrame(const wxString& title,
453 const wxPoint& pos,
454 const wxSize& size)
455 {
456 WXDWORD exflags;
457 WXDWORD flags = MSWGetCreateWindowFlags(&exflags);
458
459 const wxSize sz = IsAlwaysMaximized() ? wxDefaultSize : size;
460
461 #ifndef __WXWINCE__
462 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
463 exflags |= WS_EX_LAYOUTRTL;
464 #endif
465
466 return MSWCreate(MSWGetRegisteredClassName(),
467 title.wx_str(), pos, sz, flags, exflags);
468 }
469
470 bool wxTopLevelWindowMSW::Create(wxWindow *parent,
471 wxWindowID id,
472 const wxString& title,
473 const wxPoint& pos,
474 const wxSize& size,
475 long style,
476 const wxString& name)
477 {
478 wxSize sizeReal = size;
479 if ( !sizeReal.IsFullySpecified() )
480 {
481 sizeReal.SetDefaults(GetDefaultSize());
482 }
483
484 // notice that we should append this window to wxTopLevelWindows list
485 // before calling CreateBase() as it behaves differently for TLW and
486 // non-TLW windows
487 wxTopLevelWindows.Append(this);
488
489 bool ret = CreateBase(parent, id, pos, sizeReal, style, name);
490 if ( !ret )
491 return false;
492
493 if ( parent )
494 parent->AddChild(this);
495
496 if ( GetExtraStyle() & wxTOPLEVEL_EX_DIALOG )
497 {
498 // we have different dialog templates to allows creation of dialogs
499 // with & without captions under MSWindows, resizeable or not (but a
500 // resizeable dialog always has caption - otherwise it would look too
501 // strange)
502
503 // we need 3 additional WORDs for dialog menu, class and title (as we
504 // don't use DS_SETFONT we don't need the fourth WORD for the font)
505 static const int dlgsize = sizeof(DLGTEMPLATE) + (sizeof(WORD) * 3);
506 DLGTEMPLATE *dlgTemplate = (DLGTEMPLATE *)malloc(dlgsize);
507 memset(dlgTemplate, 0, dlgsize);
508
509 // these values are arbitrary, they won't be used normally anyhow
510 dlgTemplate->x = 34;
511 dlgTemplate->y = 22;
512 dlgTemplate->cx = 144;
513 dlgTemplate->cy = 75;
514
515 // reuse the code in MSWGetStyle() but correct the results slightly for
516 // the dialog
517 //
518 // NB: we need a temporary variable as we can't pass pointer to
519 // dwExtendedStyle directly, it's not aligned correctly for 64 bit
520 // architectures
521 WXDWORD dwExtendedStyle;
522 dlgTemplate->style = MSWGetStyle(style, &dwExtendedStyle);
523 dlgTemplate->dwExtendedStyle = dwExtendedStyle;
524
525 // all dialogs are popups
526 dlgTemplate->style |= WS_POPUP;
527
528 #ifndef __WXWINCE__
529 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
530 {
531 dlgTemplate->dwExtendedStyle |= WS_EX_LAYOUTRTL;
532 }
533
534 // force 3D-look if necessary, it looks impossibly ugly otherwise
535 if ( style & (wxRESIZE_BORDER | wxCAPTION) )
536 dlgTemplate->style |= DS_MODALFRAME;
537 #endif
538
539 ret = CreateDialog(dlgTemplate, title, pos, sizeReal);
540 free(dlgTemplate);
541 }
542 else // !dialog
543 {
544 ret = CreateFrame(title, pos, sizeReal);
545 }
546
547 #ifndef __WXWINCE__
548 if ( ret && !(GetWindowStyleFlag() & wxCLOSE_BOX) )
549 {
550 EnableCloseButton(false);
551 }
552 #endif
553
554 // for standard dialogs the dialog manager generates WM_CHANGEUISTATE
555 // itself but for custom windows we have to do it ourselves in order to
556 // make the keyboard indicators (such as underlines for accelerators and
557 // focus rectangles) work under Win2k+
558 if ( ret )
559 {
560 MSWUpdateUIState(UIS_INITIALIZE);
561 }
562
563 // Note: if we include PocketPC in this test, dialogs can fail to show up,
564 // for example the text entry dialog in the dialogs sample. Problem with Maximise()?
565 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__WINCE_STANDARDSDK__))
566 if ( ( style & wxMAXIMIZE ) || IsAlwaysMaximized() )
567 {
568 this->Maximize();
569 }
570 #endif
571
572 #if defined(__SMARTPHONE__) && defined(__WXWINCE__)
573 SetRightMenu(); // to nothing for initialization
574 #endif
575
576 return ret;
577 }
578
579 wxTopLevelWindowMSW::~wxTopLevelWindowMSW()
580 {
581 SendDestroyEvent();
582
583 #if defined(__SMARTPHONE__) || defined(__POCKETPC__)
584 SHACTIVATEINFO* info = (SHACTIVATEINFO*) m_activateInfo;
585 delete info;
586 m_activateInfo = NULL;
587 #endif
588
589 // after destroying an owned window, Windows activates the next top level
590 // window in Z order but it may be different from our owner (to reproduce
591 // this simply Alt-TAB to another application and back before closing the
592 // owned frame) whereas we always want to yield activation to our parent
593 if ( HasFlag(wxFRAME_FLOAT_ON_PARENT) )
594 {
595 wxWindow *parent = GetParent();
596 if ( parent )
597 {
598 ::BringWindowToTop(GetHwndOf(parent));
599 }
600 }
601 }
602
603 // ----------------------------------------------------------------------------
604 // wxTopLevelWindowMSW showing
605 // ----------------------------------------------------------------------------
606
607 void wxTopLevelWindowMSW::DoShowWindow(int nShowCmd)
608 {
609 ::ShowWindow(GetHwnd(), nShowCmd);
610
611 m_iconized = nShowCmd == SW_MINIMIZE;
612 }
613
614 void wxTopLevelWindowMSW::ShowWithoutActivating()
615 {
616 if ( !wxWindowBase::Show(true) )
617 return;
618
619 DoShowWindow(SW_SHOWNA);
620 }
621
622 bool wxTopLevelWindowMSW::Show(bool show)
623 {
624 // don't use wxWindow version as we want to call DoShowWindow() ourselves
625 if ( !wxWindowBase::Show(show) )
626 return false;
627
628 int nShowCmd;
629 if ( show )
630 {
631 if ( m_maximizeOnShow )
632 {
633 // show and maximize
634 nShowCmd = SW_MAXIMIZE;
635
636 // This is necessary, or no window appears
637 #if defined( __WINCE_STANDARDSDK__) || defined(__SMARTPHONE__)
638 DoShowWindow(SW_SHOW);
639 #endif
640
641 m_maximizeOnShow = false;
642 }
643 else if ( m_iconized )
644 {
645 // iconize and show
646 nShowCmd = SW_MINIMIZE;
647 }
648 else // just show
649 {
650 // we shouldn't use SW_SHOW which also activates the window for
651 // tool frames (as they shouldn't steal focus from the main window)
652 // nor for the currently disabled windows as they would be enabled
653 // as a side effect
654 if ( HasFlag(wxFRAME_TOOL_WINDOW) || !IsEnabled() )
655 nShowCmd = SW_SHOWNA;
656 else
657 nShowCmd = SW_SHOW;
658 }
659 }
660 else // hide
661 {
662 nShowCmd = SW_HIDE;
663 }
664
665 DoShowWindow(nShowCmd);
666
667 #if defined(__WXWINCE__) && (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))
668 // Addornments have to be added when the frame is the correct size
669 wxFrame* frame = wxDynamicCast(this, wxFrame);
670 if (frame && frame->GetMenuBar())
671 frame->GetMenuBar()->AddAdornments(GetWindowStyleFlag());
672 #endif
673
674 // we only set pending size if we're maximized before being shown, now that
675 // we're shown we don't need it any more (it is reset in size event handler
676 // for child windows but we have to do it ourselves for this parent window)
677 m_pendingSize = wxDefaultSize;
678
679 return true;
680 }
681
682 // ----------------------------------------------------------------------------
683 // wxTopLevelWindowMSW maximize/minimize
684 // ----------------------------------------------------------------------------
685
686 void wxTopLevelWindowMSW::Maximize(bool maximize)
687 {
688 if ( IsShown() )
689 {
690 // just maximize it directly
691 DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE);
692 }
693 else // hidden
694 {
695 // we can't maximize the hidden frame because it shows it as well,
696 // so just remember that we should do it later in this case
697 m_maximizeOnShow = maximize;
698
699 // after calling Maximize() the client code expects to get the frame
700 // "real" size and doesn't want to know that, because of implementation
701 // details, the frame isn't really maximized yet but will be only once
702 // it's shown, so return our size as it will be then in this case
703 if ( maximize )
704 {
705 // we must only change pending size here, and not call SetSize()
706 // because otherwise Windows would think that this (full screen)
707 // size is the natural size for the frame and so would use it when
708 // the user clicks on "restore" title bar button instead of the
709 // correct initial frame size
710 //
711 // NB: unfortunately we don't know which display we're on yet so we
712 // have to use the default one
713 m_pendingSize = wxGetClientDisplayRect().GetSize();
714 }
715 //else: can't do anything in this case, we don't have the old size
716 }
717 }
718
719 bool wxTopLevelWindowMSW::IsMaximized() const
720 {
721 return IsAlwaysMaximized() ||
722 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__) && !defined(__WINCE_STANDARDSDK__)
723
724 (::IsZoomed(GetHwnd()) != 0) ||
725 #endif
726 m_maximizeOnShow;
727 }
728
729 void wxTopLevelWindowMSW::Iconize(bool iconize)
730 {
731 if ( IsShown() )
732 {
733 // change the window state immediately
734 DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE);
735 }
736 else // hidden
737 {
738 // iconizing the window shouldn't show it so just remember that we need
739 // to become iconized when shown later
740 m_iconized = true;
741 }
742 }
743
744 bool wxTopLevelWindowMSW::IsIconized() const
745 {
746 #ifdef __WXWINCE__
747 return false;
748 #else
749 if ( !IsShown() )
750 return m_iconized;
751
752 // don't use m_iconized, it may be briefly out of sync with the real state
753 // as it's only modified when we receive a WM_SIZE and we could be called
754 // from an event handler from one of the messages we receive before it,
755 // such as WM_MOVE
756 return ::IsIconic(GetHwnd()) != 0;
757 #endif
758 }
759
760 void wxTopLevelWindowMSW::Restore()
761 {
762 DoShowWindow(SW_RESTORE);
763 }
764
765 void wxTopLevelWindowMSW::SetLayoutDirection(wxLayoutDirection dir)
766 {
767 if ( dir == wxLayout_Default )
768 dir = wxTheApp->GetLayoutDirection();
769
770 if ( dir != wxLayout_Default )
771 wxTopLevelWindowBase::SetLayoutDirection(dir);
772 }
773
774 // ----------------------------------------------------------------------------
775 // wxTopLevelWindowMSW geometry
776 // ----------------------------------------------------------------------------
777
778 #ifndef __WXWINCE__
779
780 void wxTopLevelWindowMSW::DoGetPosition(int *x, int *y) const
781 {
782 if ( IsIconized() )
783 {
784 WINDOWPLACEMENT wp;
785 wp.length = sizeof(WINDOWPLACEMENT);
786 if ( ::GetWindowPlacement(GetHwnd(), &wp) )
787 {
788 RECT& rc = wp.rcNormalPosition;
789
790 // the position returned by GetWindowPlacement() is in workspace
791 // coordinates except for windows with WS_EX_TOOLWINDOW style
792 if ( !HasFlag(wxFRAME_TOOL_WINDOW) )
793 {
794 // we must use the correct display for the translation as the
795 // task bar might be shown on one display but not the other one
796 int n = wxDisplay::GetFromWindow(this);
797 wxDisplay dpy(n == wxNOT_FOUND ? 0 : n);
798 const wxPoint ptOfs = dpy.GetClientArea().GetPosition() -
799 dpy.GetGeometry().GetPosition();
800
801 rc.left += ptOfs.x;
802 rc.top += ptOfs.y;
803 }
804
805 if ( x )
806 *x = rc.left;
807 if ( y )
808 *y = rc.top;
809
810 return;
811 }
812
813 wxLogLastError(wxT("GetWindowPlacement"));
814 }
815 //else: normal case
816
817 wxTopLevelWindowBase::DoGetPosition(x, y);
818 }
819
820 void wxTopLevelWindowMSW::DoGetSize(int *width, int *height) const
821 {
822 if ( IsIconized() )
823 {
824 WINDOWPLACEMENT wp;
825 wp.length = sizeof(WINDOWPLACEMENT);
826 if ( ::GetWindowPlacement(GetHwnd(), &wp) )
827 {
828 const RECT& rc = wp.rcNormalPosition;
829
830 if ( width )
831 *width = rc.right - rc.left;
832 if ( height )
833 *height = rc.bottom - rc.top;
834
835 return;
836 }
837
838 wxLogLastError(wxT("GetWindowPlacement"));
839 }
840 //else: normal case
841
842 wxTopLevelWindowBase::DoGetSize(width, height);
843 }
844
845 #endif // __WXWINCE__
846
847 void
848 wxTopLevelWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos,
849 const wxSize& size,
850 int& x, int& y,
851 int& w, int& h) const
852 {
853 // let the system position the window if no explicit position was specified
854 if ( pos.x == wxDefaultCoord )
855 {
856 // if x is set to CW_USEDEFAULT, y parameter is ignored anyhow so we
857 // can just as well set it to CW_USEDEFAULT as well
858 x =
859 y = CW_USEDEFAULT;
860 }
861 else
862 {
863 // OTOH, if x is not set to CW_USEDEFAULT, y shouldn't be set to it
864 // neither because it is not handled as a special value by Windows then
865 // and so we have to choose some default value for it, even if a
866 // completely arbitrary one
867 static const int DEFAULT_Y = 200;
868
869 x = pos.x;
870 y = pos.y == wxDefaultCoord ? DEFAULT_Y : pos.y;
871 }
872
873 if ( size.x == wxDefaultCoord || size.y == wxDefaultCoord )
874 {
875 // We don't use CW_USEDEFAULT here for several reasons:
876 //
877 // 1. It results in huge frames on modern screens (1000*800 is not
878 // uncommon on my 1280*1024 screen) which is way too big for a half
879 // empty frame of most of wxWidgets samples for example)
880 //
881 // 2. It is buggy for frames with wxFRAME_TOOL_WINDOW style for which
882 // the default is for whatever reason 8*8 which breaks client <->
883 // window size calculations (it would be nice if it didn't, but it
884 // does and the simplest way to fix it seemed to change the broken
885 // default size anyhow)
886 //
887 // 3. There is just no advantage in doing it: with x and y it is
888 // possible that [future versions of] Windows position the new top
889 // level window in some smart way which we can't do, but we can
890 // guess a reasonably good size for a new window just as well
891 // ourselves
892 //
893 // The only exception is for the Windows CE platform where the system
894 // does know better than we how should the windows be sized
895 #ifdef _WIN32_WCE
896 w =
897 h = CW_USEDEFAULT;
898 #else // !_WIN32_WCE
899 wxSize sizeReal = size;
900 sizeReal.SetDefaults(GetDefaultSize());
901
902 w = sizeReal.x;
903 h = sizeReal.y;
904 #endif // _WIN32_WCE/!_WIN32_WCE
905 }
906 else
907 {
908 w = size.x;
909 h = size.y;
910 }
911 }
912
913 // ----------------------------------------------------------------------------
914 // wxTopLevelWindowMSW fullscreen
915 // ----------------------------------------------------------------------------
916
917 bool wxTopLevelWindowMSW::ShowFullScreen(bool show, long style)
918 {
919 if ( show == IsFullScreen() )
920 {
921 // nothing to do
922 return true;
923 }
924
925 m_fsIsShowing = show;
926
927 if ( show )
928 {
929 m_fsStyle = style;
930
931 // zap the frame borders
932
933 // save the 'normal' window style
934 m_fsOldWindowStyle = GetWindowLong(GetHwnd(), GWL_STYLE);
935
936 // save the old position, width & height, maximize state
937 m_fsOldSize = GetRect();
938 m_fsIsMaximized = IsMaximized();
939
940 // decide which window style flags to turn off
941 LONG newStyle = m_fsOldWindowStyle;
942 LONG offFlags = 0;
943
944 if (style & wxFULLSCREEN_NOBORDER)
945 {
946 offFlags |= WS_BORDER;
947 #ifndef __WXWINCE__
948 offFlags |= WS_THICKFRAME;
949 #endif
950 }
951 if (style & wxFULLSCREEN_NOCAPTION)
952 offFlags |= WS_CAPTION | WS_SYSMENU;
953
954 newStyle &= ~offFlags;
955
956 // change our window style to be compatible with full-screen mode
957 ::SetWindowLong(GetHwnd(), GWL_STYLE, newStyle);
958
959 wxRect rect;
960 #if wxUSE_DISPLAY
961 // resize to the size of the display containing us
962 int dpy = wxDisplay::GetFromWindow(this);
963 if ( dpy != wxNOT_FOUND )
964 {
965 rect = wxDisplay(dpy).GetGeometry();
966 }
967 else // fall back to the main desktop
968 #endif // wxUSE_DISPLAY
969 {
970 // resize to the size of the desktop
971 wxCopyRECTToRect(wxGetWindowRect(::GetDesktopWindow()), rect);
972 #ifdef __WXWINCE__
973 // FIXME: size of the bottom menu (toolbar)
974 // should be taken in account
975 rect.height += rect.y;
976 rect.y = 0;
977 #endif
978 }
979
980 SetSize(rect);
981
982 // now flush the window style cache and actually go full-screen
983 long flags = SWP_FRAMECHANGED;
984
985 // showing the frame full screen should also show it if it's still
986 // hidden
987 if ( !IsShown() )
988 {
989 // don't call wxWindow version to avoid flicker from calling
990 // ::ShowWindow() -- we're going to show the window at the correct
991 // location directly below -- but do call the wxWindowBase version
992 // to sync the internal m_isShown flag
993 wxWindowBase::Show();
994
995 flags |= SWP_SHOWWINDOW;
996 }
997
998 SetWindowPos(GetHwnd(), HWND_TOP,
999 rect.x, rect.y, rect.width, rect.height,
1000 flags);
1001
1002 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
1003 ::SHFullScreen(GetHwnd(), SHFS_HIDETASKBAR | SHFS_HIDESIPBUTTON);
1004 #endif
1005
1006 // finally send an event allowing the window to relayout itself &c
1007 wxSizeEvent event(rect.GetSize(), GetId());
1008 HandleWindowEvent(event);
1009 }
1010 else // stop showing full screen
1011 {
1012 #if !defined(__HANDHELDPC__) && (defined(__WXWINCE__) && (_WIN32_WCE < 400))
1013 ::SHFullScreen(GetHwnd(), SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON);
1014 #endif
1015 Maximize(m_fsIsMaximized);
1016 SetWindowLong(GetHwnd(),GWL_STYLE, m_fsOldWindowStyle);
1017 SetWindowPos(GetHwnd(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
1018 m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
1019 }
1020
1021 return true;
1022 }
1023
1024 // ----------------------------------------------------------------------------
1025 // wxTopLevelWindowMSW misc
1026 // ----------------------------------------------------------------------------
1027
1028 void wxTopLevelWindowMSW::SetTitle( const wxString& title)
1029 {
1030 SetLabel(title);
1031 }
1032
1033 wxString wxTopLevelWindowMSW::GetTitle() const
1034 {
1035 return GetLabel();
1036 }
1037
1038 bool wxTopLevelWindowMSW::DoSelectAndSetIcon(const wxIconBundle& icons,
1039 int smX,
1040 int smY,
1041 int i)
1042 {
1043 const wxSize size(::GetSystemMetrics(smX), ::GetSystemMetrics(smY));
1044
1045 const wxIcon icon = icons.GetIconOfExactSize(size);
1046 if ( icon.Ok() )
1047 {
1048 ::SendMessage(GetHwnd(), WM_SETICON, i, (LPARAM)GetHiconOf(icon));
1049 return true;
1050 }
1051
1052 return false;
1053 }
1054
1055 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons)
1056 {
1057 wxTopLevelWindowBase::SetIcons(icons);
1058
1059 if ( icons.IsEmpty() )
1060 {
1061 // FIXME: SetIcons(wxNullIconBundle) should unset existing icons,
1062 // but we currently don't do that
1063 wxASSERT_MSG( m_icons.IsEmpty(), "unsetting icons doesn't work" );
1064 return;
1065 }
1066
1067 bool anySet =
1068 DoSelectAndSetIcon(icons, SM_CXSMICON, SM_CYSMICON, ICON_SMALL);
1069 if ( DoSelectAndSetIcon(icons, SM_CXICON, SM_CYICON, ICON_BIG) )
1070 anySet = true;
1071
1072 if ( !anySet )
1073 {
1074 wxFAIL_MSG( "icon bundle doesn't contain any suitable icon" );
1075 }
1076 }
1077
1078 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable)
1079 {
1080 #if !defined(__WXMICROWIN__)
1081 // get system (a.k.a. window) menu
1082 HMENU hmenu = GetSystemMenu(GetHwnd(), FALSE /* get it */);
1083 if ( !hmenu )
1084 {
1085 // no system menu at all -- ok if we want to remove the close button
1086 // anyhow, but bad if we want to show it
1087 return !enable;
1088 }
1089
1090 // enabling/disabling the close item from it also automatically
1091 // disables/enables the close title bar button
1092 if ( ::EnableMenuItem(hmenu, SC_CLOSE,
1093 MF_BYCOMMAND |
1094 (enable ? MF_ENABLED : MF_GRAYED)) == -1 )
1095 {
1096 wxLogLastError(wxT("EnableMenuItem(SC_CLOSE)"));
1097
1098 return false;
1099 }
1100 #ifndef __WXWINCE__
1101 // update appearance immediately
1102 if ( !::DrawMenuBar(GetHwnd()) )
1103 {
1104 wxLogLastError(wxT("DrawMenuBar"));
1105 }
1106 #endif
1107 #endif // !__WXMICROWIN__
1108
1109 return true;
1110 }
1111
1112 #ifndef __WXWINCE__
1113
1114 bool wxTopLevelWindowMSW::SetShape(const wxRegion& region)
1115 {
1116 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
1117 wxT("Shaped windows must be created with the wxFRAME_SHAPED style."));
1118
1119 // The empty region signifies that the shape should be removed from the
1120 // window.
1121 if ( region.IsEmpty() )
1122 {
1123 if (::SetWindowRgn(GetHwnd(), NULL, TRUE) == 0)
1124 {
1125 wxLogLastError(wxT("SetWindowRgn"));
1126 return false;
1127 }
1128 return true;
1129 }
1130
1131 // Windows takes ownership of the region, so
1132 // we'll have to make a copy of the region to give to it.
1133 DWORD noBytes = ::GetRegionData(GetHrgnOf(region), 0, NULL);
1134 RGNDATA *rgnData = (RGNDATA*) new char[noBytes];
1135 ::GetRegionData(GetHrgnOf(region), noBytes, rgnData);
1136 HRGN hrgn = ::ExtCreateRegion(NULL, noBytes, rgnData);
1137 delete[] (char*) rgnData;
1138
1139 // SetWindowRgn expects the region to be in coordinants
1140 // relative to the window, not the client area. Figure
1141 // out the offset, if any.
1142 RECT rect;
1143 DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE);
1144 DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE);
1145 ::GetClientRect(GetHwnd(), &rect);
1146 ::AdjustWindowRectEx(&rect, dwStyle, ::GetMenu(GetHwnd()) != NULL, dwExStyle);
1147 ::OffsetRgn(hrgn, -rect.left, -rect.top);
1148
1149 // Now call the shape API with the new region.
1150 if (::SetWindowRgn(GetHwnd(), hrgn, TRUE) == 0)
1151 {
1152 wxLogLastError(wxT("SetWindowRgn"));
1153 return false;
1154 }
1155 return true;
1156 }
1157
1158 #endif // !__WXWINCE__
1159
1160 void wxTopLevelWindowMSW::RequestUserAttention(int flags)
1161 {
1162 // check if we can use FlashWindowEx(): unfortunately a simple test for
1163 // FLASHW_STOP doesn't work because MSVC6 headers do #define it but don't
1164 // provide FlashWindowEx() declaration, so try to detect whether we have
1165 // real headers for WINVER 0x0500 by checking for existence of a symbol not
1166 // declated in MSVC6 header
1167 #if defined(FLASHW_STOP) && defined(VK_XBUTTON1) && wxUSE_DYNLIB_CLASS
1168 // available in the headers, check if it is supported by the system
1169 typedef BOOL (WINAPI *FlashWindowEx_t)(FLASHWINFO *pfwi);
1170 static FlashWindowEx_t s_pfnFlashWindowEx = NULL;
1171 if ( !s_pfnFlashWindowEx )
1172 {
1173 wxDynamicLibrary dllUser32(wxT("user32.dll"));
1174 s_pfnFlashWindowEx = (FlashWindowEx_t)
1175 dllUser32.GetSymbol(wxT("FlashWindowEx"));
1176
1177 // we can safely unload user32.dll here, it's going to remain loaded as
1178 // long as the program is running anyhow
1179 }
1180
1181 if ( s_pfnFlashWindowEx )
1182 {
1183 WinStruct<FLASHWINFO> fwi;
1184 fwi.hwnd = GetHwnd();
1185 fwi.dwFlags = FLASHW_ALL;
1186 if ( flags & wxUSER_ATTENTION_INFO )
1187 {
1188 // just flash a few times
1189 fwi.uCount = 3;
1190 }
1191 else // wxUSER_ATTENTION_ERROR
1192 {
1193 // flash until the user notices it
1194 fwi.dwFlags |= FLASHW_TIMERNOFG;
1195 }
1196
1197 s_pfnFlashWindowEx(&fwi);
1198 }
1199 else // FlashWindowEx() not available
1200 #endif // FlashWindowEx() defined
1201 {
1202 wxUnusedVar(flags);
1203 #ifndef __WXWINCE__
1204 ::FlashWindow(GetHwnd(), TRUE);
1205 #endif // __WXWINCE__
1206 }
1207 }
1208
1209 // ---------------------------------------------------------------------------
1210
1211 bool wxTopLevelWindowMSW::SetTransparent(wxByte alpha)
1212 {
1213 #if wxUSE_DYNLIB_CLASS
1214 typedef DWORD (WINAPI *PSETLAYEREDWINDOWATTR)(HWND, DWORD, BYTE, DWORD);
1215 static PSETLAYEREDWINDOWATTR
1216 pSetLayeredWindowAttributes = (PSETLAYEREDWINDOWATTR)-1;
1217
1218 if ( pSetLayeredWindowAttributes == (PSETLAYEREDWINDOWATTR)-1 )
1219 {
1220 wxDynamicLibrary dllUser32(wxT("user32.dll"));
1221
1222 // use RawGetSymbol() and not GetSymbol() to avoid error messages under
1223 // Windows 95: there is nothing the user can do about this anyhow
1224 pSetLayeredWindowAttributes = (PSETLAYEREDWINDOWATTR)
1225 dllUser32.RawGetSymbol(wxT("SetLayeredWindowAttributes"));
1226
1227 // it's ok to destroy dllUser32 here, we link statically to user32.dll
1228 // anyhow so it won't be unloaded
1229 }
1230
1231 if ( !pSetLayeredWindowAttributes )
1232 return false;
1233 #endif // wxUSE_DYNLIB_CLASS
1234
1235 LONG exstyle = GetWindowLong(GetHwnd(), GWL_EXSTYLE);
1236
1237 // if setting alpha to fully opaque then turn off the layered style
1238 if (alpha == 255)
1239 {
1240 SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyle & ~WS_EX_LAYERED);
1241 Refresh();
1242 return true;
1243 }
1244
1245 #if wxUSE_DYNLIB_CLASS
1246 // Otherwise, set the layered style if needed and set the alpha value
1247 if ((exstyle & WS_EX_LAYERED) == 0 )
1248 SetWindowLong(GetHwnd(), GWL_EXSTYLE, exstyle | WS_EX_LAYERED);
1249
1250 if ( pSetLayeredWindowAttributes(GetHwnd(), 0, (BYTE)alpha, LWA_ALPHA) )
1251 return true;
1252 #endif // wxUSE_DYNLIB_CLASS
1253
1254 return false;
1255 }
1256
1257 bool wxTopLevelWindowMSW::CanSetTransparent()
1258 {
1259 // The API is available on win2k and above
1260
1261 static int os_type = -1;
1262 static int ver_major = -1;
1263
1264 if (os_type == -1)
1265 os_type = ::wxGetOsVersion(&ver_major);
1266
1267 return (os_type == wxOS_WINDOWS_NT && ver_major >= 5);
1268 }
1269
1270
1271 void wxTopLevelWindowMSW::DoFreeze()
1272 {
1273 // do nothing: freezing toplevel window causes paint and mouse events
1274 // to go through it any TLWs under it, so the best we can do is to freeze
1275 // all children -- and wxWindowBase::Freeze() does that
1276 }
1277
1278 void wxTopLevelWindowMSW::DoThaw()
1279 {
1280 // intentionally empty -- see DoFreeze()
1281 }
1282
1283
1284 // ----------------------------------------------------------------------------
1285 // wxTopLevelWindow event handling
1286 // ----------------------------------------------------------------------------
1287
1288 // Default activation behaviour - set the focus for the first child
1289 // subwindow found.
1290 void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
1291 {
1292 if ( event.GetActive() )
1293 {
1294 // restore focus to the child which was last focused unless we already
1295 // have it
1296 wxLogTrace(wxT("focus"), wxT("wxTLW %p activated."), m_hWnd);
1297
1298 wxWindow *winFocus = FindFocus();
1299 if ( !winFocus || wxGetTopLevelParent(winFocus) != this )
1300 {
1301 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
1302 : NULL;
1303 if ( !parent )
1304 {
1305 parent = this;
1306 }
1307
1308 wxSetFocusToChild(parent, &m_winLastFocused);
1309 }
1310 }
1311 else // deactivating
1312 {
1313 // remember the last focused child if it is our child
1314 m_winLastFocused = FindFocus();
1315
1316 if ( m_winLastFocused )
1317 {
1318 // let it know that it doesn't have focus any more
1319 // But this will already be done via WM_KILLFOCUS, so we'll get two kill
1320 // focus events if we call it explicitly.
1321 // m_winLastFocused->HandleKillFocus((WXHWND)NULL);
1322
1323 // and don't remember it if it's a child from some other frame
1324 if ( wxGetTopLevelParent(m_winLastFocused) != this )
1325 {
1326 m_winLastFocused = NULL;
1327 }
1328 }
1329
1330 wxLogTrace(wxT("focus"),
1331 wxT("wxTLW %p deactivated, last focused: %p."),
1332 m_hWnd,
1333 m_winLastFocused ? GetHwndOf(m_winLastFocused) : NULL);
1334
1335 event.Skip();
1336 }
1337 }
1338
1339 // the DialogProc for all wxWidgets dialogs
1340 LONG APIENTRY _EXPORT
1341 wxDlgProc(HWND hDlg,
1342 UINT message,
1343 WPARAM WXUNUSED(wParam),
1344 LPARAM WXUNUSED(lParam))
1345 {
1346 switch ( message )
1347 {
1348 case WM_INITDIALOG:
1349 {
1350 // under CE, add a "Ok" button in the dialog title bar and make it full
1351 // screen
1352 //
1353 // TODO: find the window for this HWND, and take into account
1354 // wxMAXIMIZE and wxCLOSE_BOX. For now, assume both are present.
1355 //
1356 // Standard SDK doesn't have aygshell.dll: see
1357 // include/wx/msw/wince/libraries.h
1358 #if defined(__WXWINCE__) && !defined(__WINCE_STANDARDSDK__) && !defined(__HANDHELDPC__)
1359 SHINITDLGINFO shidi;
1360 shidi.dwMask = SHIDIM_FLAGS;
1361 shidi.dwFlags = SHIDIF_SIZEDLG // take account of the SIP or menubar
1362 #ifndef __SMARTPHONE__
1363 | SHIDIF_DONEBUTTON
1364 #endif
1365 ;
1366 shidi.hDlg = hDlg;
1367 SHInitDialog( &shidi );
1368 #else // no SHInitDialog()
1369 wxUnusedVar(hDlg);
1370 #endif
1371 // for WM_INITDIALOG, returning TRUE tells system to set focus to
1372 // the first control in the dialog box, but as we set the focus
1373 // ourselves, we return FALSE for it as well
1374 return FALSE;
1375 }
1376 }
1377
1378 // for almost all messages, returning FALSE means that we didn't process
1379 // the message
1380 return FALSE;
1381 }
1382
1383 // ============================================================================
1384 // wxTLWHiddenParentModule implementation
1385 // ============================================================================
1386
1387 HWND wxTLWHiddenParentModule::ms_hwnd = NULL;
1388
1389 const wxChar *wxTLWHiddenParentModule::ms_className = NULL;
1390
1391 bool wxTLWHiddenParentModule::OnInit()
1392 {
1393 ms_hwnd = NULL;
1394 ms_className = NULL;
1395
1396 return true;
1397 }
1398
1399 void wxTLWHiddenParentModule::OnExit()
1400 {
1401 if ( ms_hwnd )
1402 {
1403 if ( !::DestroyWindow(ms_hwnd) )
1404 {
1405 wxLogLastError(wxT("DestroyWindow(hidden TLW parent)"));
1406 }
1407
1408 ms_hwnd = NULL;
1409 }
1410
1411 if ( ms_className )
1412 {
1413 if ( !::UnregisterClass(ms_className, wxGetInstance()) )
1414 {
1415 wxLogLastError(wxT("UnregisterClass(\"wxTLWHiddenParent\")"));
1416 }
1417
1418 ms_className = NULL;
1419 }
1420 }
1421
1422 /* static */
1423 HWND wxTLWHiddenParentModule::GetHWND()
1424 {
1425 if ( !ms_hwnd )
1426 {
1427 if ( !ms_className )
1428 {
1429 static const wxChar *HIDDEN_PARENT_CLASS = wxT("wxTLWHiddenParent");
1430
1431 WNDCLASS wndclass;
1432 wxZeroMemory(wndclass);
1433
1434 wndclass.lpfnWndProc = DefWindowProc;
1435 wndclass.hInstance = wxGetInstance();
1436 wndclass.lpszClassName = HIDDEN_PARENT_CLASS;
1437
1438 if ( !::RegisterClass(&wndclass) )
1439 {
1440 wxLogLastError(wxT("RegisterClass(\"wxTLWHiddenParent\")"));
1441 }
1442 else
1443 {
1444 ms_className = HIDDEN_PARENT_CLASS;
1445 }
1446 }
1447
1448 ms_hwnd = ::CreateWindow(ms_className, wxEmptyString, 0, 0, 0, 0, 0, NULL,
1449 (HMENU)NULL, wxGetInstance(), NULL);
1450 if ( !ms_hwnd )
1451 {
1452 wxLogLastError(wxT("CreateWindow(hidden TLW parent)"));
1453 }
1454 }
1455
1456 return ms_hwnd;
1457 }