/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/toplevel.cpp
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/toplevel.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22