Removed every usage of obsolete wxTLW flags. 2.6 compatibility markup for them.
[wxWidgets.git] / src / os2 / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/toplevel.cpp
3 // Purpose: implements wxTopLevelWindow for OS/2
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 30.12.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 #ifndef WX_PRECOMP
28 #include "wx/app.h"
29 #include "wx/toplevel.h"
30 #include "wx/dialog.h"
31 #include "wx/string.h"
32 #include "wx/log.h"
33 #include "wx/intl.h"
34 #include "wx/frame.h"
35 #include "wx/control.h"
36 #include "wx/containr.h" // wxSetFocusToChild()
37 #include "wx/settings.h"
38 #endif //WX_PRECOMP
39
40 #include "wx/module.h" // wxSetFocusToChild()
41 #include "wx/os2/private.h"
42
43 // ----------------------------------------------------------------------------
44 // stubs for missing functions under MicroWindows
45 // ----------------------------------------------------------------------------
46
47
48 // ----------------------------------------------------------------------------
49 // globals
50 // ----------------------------------------------------------------------------
51
52 // the name of the default wxWidgets class
53 extern void wxAssociateWinWithHandle( HWND hWnd, wxWindowOS2* pWin );
54
55 bool wxTopLevelWindowOS2::m_sbInitialized = false;
56 wxWindow* wxTopLevelWindowOS2::m_spHiddenParent = NULL;
57
58 // ============================================================================
59 // wxTopLevelWindowOS2 implementation
60 // ============================================================================
61
62 BEGIN_EVENT_TABLE(wxTopLevelWindowOS2, wxTopLevelWindowBase)
63 EVT_ACTIVATE(wxTopLevelWindowOS2::OnActivate)
64 END_EVENT_TABLE()
65
66 // ============================================================================
67 // wxTopLevelWindowMSW implementation
68 // ============================================================================
69
70 // Dialog window proc
71 MRESULT EXPENTRY wxDlgProc( HWND WXUNUSED(hWnd)
72 ,UINT uMessage
73 ,void * WXUNUSED(wParam)
74 ,void * WXUNUSED(lParam)
75 )
76 {
77 switch(uMessage)
78 {
79 case WM_INITDLG:
80 //
81 // For this message, returning TRUE tells system to set focus to
82 // the first control in the dialog box, but we set the focus
83 // ourselves, however in OS/2 we must return true to enable the dialog
84 //
85 return (MRESULT)TRUE;
86 default:
87 //
88 // For all the other ones, FALSE means that we didn't process the
89 // message
90 //
91 return (MRESULT)FALSE;
92 }
93 } // end of wxDlgProc
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 //
104 // Module init/finalize
105 //
106 virtual bool OnInit(void);
107 virtual void OnExit(void);
108
109 //
110 // Get the hidden window (creates on demand)
111 //
112 static HWND GetHWND(void);
113
114 private:
115 //
116 // The HWND of the hidden parent
117 //
118 static HWND m_shWnd;
119
120 //
121 // The class used to create it
122 //
123 static const wxChar* m_szClassName;
124 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule)
125 }; // end of CLASS wxTLWHiddenParentModule
126
127 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule, wxModule)
128
129 // ----------------------------------------------------------------------------
130 // wxTopLevelWindowOS2 creation
131 // ----------------------------------------------------------------------------
132
133 void wxTopLevelWindowOS2::Init()
134 {
135 m_bIconized = m_bMaximizeOnShow = false;
136
137 //
138 // Unlike (almost?) all other windows, frames are created hidden
139 //
140 m_isShown = false;
141
142 //
143 // Data to save/restore when calling ShowFullScreen
144 m_lFsStyle = 0;
145 m_lFsOldWindowStyle = 0;
146 m_bFsIsMaximized = false;
147 m_bFsIsShowing = false;
148
149 m_hFrame = NULLHANDLE;
150 memset(&m_vSwp, 0, sizeof(SWP));
151 memset(&m_vSwpClient, 0, sizeof(SWP));
152 m_pWinLastFocused = (wxWindow *)NULL;
153 } // end of wxTopLevelWindowIOS2::Init
154
155 void wxTopLevelWindowOS2::OnActivate(
156 wxActivateEvent& rEvent
157 )
158 {
159 if (rEvent.GetActive())
160 {
161 //
162 // Restore focus to the child which was last focused
163 //
164 wxLogTrace(_T("focus"), _T("wxTLW %08lx activated."), m_hWnd);
165
166 wxWindow* pParent = m_pWinLastFocused ? m_pWinLastFocused->GetParent()
167 : NULL;
168 if (!pParent)
169 {
170 pParent = this;
171 }
172
173 wxSetFocusToChild( pParent
174 ,&m_pWinLastFocused
175 );
176 }
177 else // deactivating
178 {
179 //
180 // Remember the last focused child if it is our child
181 //
182 m_pWinLastFocused = FindFocus();
183
184 //
185 // So we NULL it out if it's a child from some other frame
186 //
187 wxWindow* pWin = m_pWinLastFocused;
188
189 while (pWin)
190 {
191 if (pWin->IsTopLevel())
192 {
193 if (pWin != this)
194 {
195 m_pWinLastFocused = NULL;
196 }
197 break;
198 }
199 pWin = pWin->GetParent();
200 }
201
202 wxLogTrace(_T("focus"),
203 _T("wxTLW %08lx deactivated, last focused: %08lx."),
204 m_hWnd,
205 m_pWinLastFocused ? GetHwndOf(m_pWinLastFocused)
206 : NULL);
207 rEvent.Skip();
208 }
209 } // end of wxTopLevelWindowOS2::OnActivate
210
211 WXDWORD wxTopLevelWindowOS2::OS2GetStyle(
212 long lStyle
213 , WXDWORD* pdwExflags
214 ) const
215 {
216 long lMsflags = wxWindow::OS2GetStyle( (lStyle & ~wxBORDER_MASK) | wxBORDER_NONE
217 ,pdwExflags
218 );
219
220 if ((lStyle & wxDEFAULT_FRAME_STYLE) == wxDEFAULT_FRAME_STYLE)
221 lMsflags |= FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU |
222 FCF_MINMAX | FCF_TASKLIST;
223
224 if ((lStyle & wxCAPTION) == wxCAPTION)
225 lMsflags |= FCF_TASKLIST;
226 else
227 lMsflags |= FCF_NOMOVEWITHOWNER;
228
229 if ((lStyle & wxVSCROLL) == wxVSCROLL)
230 lMsflags |= FCF_VERTSCROLL;
231 if ((lStyle & wxHSCROLL) == wxHSCROLL)
232 lMsflags |= FCF_HORZSCROLL;
233 if (lStyle & wxMINIMIZE_BOX)
234 lMsflags |= FCF_MINBUTTON;
235 if (lStyle & wxMAXIMIZE_BOX)
236 lMsflags |= FCF_MAXBUTTON;
237 if (lStyle & wxRESIZE_BORDER)
238 lMsflags |= FCF_DLGBORDER;
239 if (lStyle & wxSYSTEM_MENU)
240 lMsflags |= FCF_SYSMENU;
241 if (lStyle & wxCAPTION)
242 lMsflags |= FCF_TASKLIST;
243 if (lStyle & wxCLIP_CHILDREN)
244 {
245 // Invalid for frame windows under PM
246 }
247
248 if (lStyle & wxTINY_CAPTION_VERT)
249 lMsflags |= FCF_TASKLIST;
250 if (lStyle & wxTINY_CAPTION_HORIZ)
251 lMsflags |= FCF_TASKLIST;
252
253 if ((lStyle & wxRESIZE_BORDER) == 0)
254 lMsflags |= FCF_BORDER;
255 if (lStyle & wxFRAME_TOOL_WINDOW)
256 *pdwExflags = kFrameToolWindow;
257
258 if (lStyle & wxSTAY_ON_TOP)
259 lMsflags |= FCF_SYSMODAL;
260
261 return lMsflags;
262 } // end of wxTopLevelWindowOS2::OS2GetCreateWindowFlags
263
264 WXHWND wxTopLevelWindowOS2::OS2GetParent() const
265 {
266 HWND hWndParent = NULL;
267
268 //
269 // For the frames without wxFRAME_FLOAT_ON_PARENT style we should use NULL
270 // parent HWND or it would be always on top of its parent which is not what
271 // we usually want (in fact, we only want it for frames with the
272 // wxFRAME_FLOAT_ON_PARENT flag)
273 //
274 if (HasFlag(wxFRAME_FLOAT_ON_PARENT) )
275 {
276 const wxWindow* pParent = GetParent();
277
278 if (!pParent)
279 {
280 //
281 // This flag doesn't make sense then and will be ignored
282 //
283 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
284 }
285 else
286 {
287 hWndParent = GetHwndOf(pParent);
288 }
289 }
290 //else: don't float on parent, must not be owned
291
292 //
293 // Now deal with the 2nd taskbar-related problem (see comments above in
294 // OS2GetStyle())
295 //
296 if (HasFlag(wxFRAME_NO_TASKBAR) && !hWndParent)
297 {
298 //
299 // Use hidden parent
300 //
301 hWndParent = wxTLWHiddenParentModule::GetHWND();
302 }
303 return (WXHWND)hWndParent;
304 } // end of wxTopLevelWindowOS2::OS2GetParent
305
306
307 bool wxTopLevelWindowOS2::CreateDialog( ULONG ulDlgTemplate,
308 const wxString& WXUNUSED(rsTitle),
309 const wxPoint& rPos,
310 const wxSize& rSize )
311 {
312 wxWindow* pParent = GetParent();
313
314 //
315 // For the dialogs without wxDIALOG_NO_PARENT style, use the top level
316 // app window as parent - this avoids creating modal dialogs without
317 // parent
318 //
319 if (!pParent && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT))
320 {
321 pParent = wxTheApp->GetTopWindow();
322
323 if (pParent)
324 {
325 //
326 // Don't use transient windows as parents, this is dangerous as it
327 // can lead to a crash if the parent is destroyed before the child
328 //
329 // also don't use the window which is currently hidden as then the
330 // dialog would be hidden as well
331 if ((pParent->GetExtraStyle() & wxWS_EX_TRANSIENT) ||
332 !pParent->IsShown())
333 {
334 pParent = NULL;
335 }
336 }
337 }
338
339 HWND hWndDlg;
340 HWND hWndOwner;
341
342 if (pParent)
343 hWndOwner = GetHwndOf(pParent);
344 else
345 hWndOwner = HWND_DESKTOP;
346
347 hWndDlg = ::WinLoadDlg( HWND_DESKTOP
348 ,hWndOwner
349 ,(PFNWP)wxDlgProc
350 ,NULL
351 ,(ULONG)ulDlgTemplate
352 ,(PVOID)this
353 );
354
355 m_hWnd = (WXHWND) hWndDlg;
356
357 if ( !m_hWnd )
358 {
359 wxFAIL_MSG(wxT("Did you forget to include wx/os2/wx.rc in your resources?"));
360
361 wxLogSysError(wxT("Can't create dialog using template '%ld'"), ulDlgTemplate);
362
363 return false;
364 }
365
366 //
367 // Move the dialog to its initial position without forcing repainting
368 //
369 int nX;
370 int nY;
371 int nWidth;
372 int nHeight;
373
374 if (!OS2GetCreateWindowCoords( rPos
375 ,rSize
376 ,nX
377 ,nY
378 ,nWidth
379 ,nHeight
380 ))
381 {
382 nX = nWidth = (int)CW_USEDEFAULT;
383 }
384
385 //
386 // We can't use CW_USEDEFAULT here as we're not calling CreateWindow()
387 // and passing CW_USEDEFAULT to MoveWindow() results in resizing the
388 // window to (0, 0) size which breaks quite a lot of things, e.g. the
389 // sizer calculation in wxSizer::Fit()
390 //
391 if (nWidth == (int)CW_USEDEFAULT)
392 {
393 //
394 // The exact number doesn't matter, the dialog will be resized
395 // again soon anyhow but it should be big enough to allow
396 // calculation relying on "totalSize - clientSize > 0" work, i.e.
397 // at least greater than the title bar height
398 //
399 nWidth = nHeight = 100;
400 }
401 if (nX == (int)CW_USEDEFAULT)
402 {
403 //
404 // Centre it on the screen - what else can we do?
405 //
406 wxSize vSizeDpy = wxGetDisplaySize();
407
408 nX = (vSizeDpy.x - nWidth) / 2;
409 nY = (vSizeDpy.y - nHeight) / 2;
410 }
411 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
412
413 LONG lColor = (LONG)m_backgroundColour.GetPixel();
414
415 if (!::WinSetPresParam( m_hWnd
416 ,PP_BACKGROUNDCOLOR
417 ,sizeof(LONG)
418 ,(PVOID)&lColor
419 ))
420 {
421 return false;
422 }
423
424 // Convert to OS/2 coordinates
425 nY = GetOS2ParentHeight(pParent) - nY - nHeight;
426
427 ::WinSetWindowPos( GetHwnd()
428 ,HWND_TOP
429 ,nX
430 ,nY
431 ,nWidth
432 ,nHeight
433 ,SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_SHOW | SWP_ACTIVATE
434 );
435 ::WinQueryWindowPos(GetHwnd(), GetSwp());
436 m_hFrame = m_hWnd;
437 SubclassWin(m_hWnd);
438 return true;
439 } // end of wxTopLevelWindowOS2::CreateDialog
440
441 bool wxTopLevelWindowOS2::CreateFrame( const wxString& rsTitle,
442 const wxPoint& rPos,
443 const wxSize& rSize )
444 {
445 WXDWORD lExflags;
446 WXDWORD lFlags = OS2GetCreateWindowFlags(&lExflags);
447 long lStyle = GetWindowStyleFlag();
448 int nX = rPos.x;
449 int nY = rPos.y;
450 int nWidth = rSize.x;
451 int nHeight = rSize.y;
452 ULONG ulStyleFlags = 0L;
453 ERRORID vError;
454 wxString sError;
455 wxWindow* pParent = GetParent();
456 HWND hParent;
457 HWND hFrame;
458 HWND hClient;
459
460 if (pParent)
461 hParent = GetHwndOf(pParent);
462 else
463 hParent = HWND_DESKTOP;
464
465 if ((lStyle & wxMINIMIZE) || (lStyle & wxICONIZE))
466 ulStyleFlags |= WS_MINIMIZED;
467 if (lStyle & wxMAXIMIZE)
468 ulStyleFlags |= WS_MAXIMIZED;
469
470 //
471 // Clear the visible flag, we always call show
472 //
473 ulStyleFlags &= (unsigned long)~WS_VISIBLE;
474 m_bIconized = false;
475
476 //
477 // Create the frame window: We break ranks with other ports now
478 // and instead of calling down into the base wxWindow class' OS2Create
479 // we do all our own stuff here. We will set the needed pieces
480 // of wxWindow manually, here.
481 //
482
483 hFrame = ::WinCreateStdWindow( hParent
484 ,ulStyleFlags // frame-window style
485 ,(PULONG)&lFlags // window style
486 ,(PSZ)wxFrameClassName // class name
487 ,(PSZ)rsTitle.c_str() // window title
488 ,0L // default client style
489 ,NULLHANDLE // resource in executable file
490 ,0 // resource id
491 ,&hClient // receives client window handle
492 );
493 if (!hFrame)
494 {
495 vError = ::WinGetLastError(vHabmain);
496 sError = wxPMErrorToStr(vError);
497 wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str());
498 return false;
499 }
500
501 //
502 // wxWindow class' m_hWnd set here and needed associations
503 //
504 m_hFrame = hFrame;
505 m_hWnd = hClient;
506 wxAssociateWinWithHandle(m_hWnd, this);
507 wxAssociateWinWithHandle(m_hFrame, this);
508
509 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
510
511 LONG lColor = (LONG)m_backgroundColour.GetPixel();
512
513 if (!::WinSetPresParam( m_hWnd
514 ,PP_BACKGROUNDCOLOR
515 ,sizeof(LONG)
516 ,(PVOID)&lColor
517 ))
518 {
519 vError = ::WinGetLastError(vHabmain);
520 sError = wxPMErrorToStr(vError);
521 wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str());
522 return false;
523 }
524
525 //
526 // Now need to subclass window. Instead of calling the SubClassWin in wxWindow
527 // we manually subclass here because we don't want to use the main wxWndProc
528 // by default
529 //
530 m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(m_hFrame, (PFNWP)wxFrameMainWndProc);
531
532 //
533 // Now size everything. If adding a menu the client will need to be resized.
534 //
535
536 if (!OS2GetCreateWindowCoords( rPos
537 ,rSize
538 ,nX
539 ,nY
540 ,nWidth
541 ,nHeight
542 ))
543 {
544 nX = nWidth = (int)CW_USEDEFAULT;
545 }
546
547 //
548 // We can't use CW_USEDEFAULT here as we're not calling CreateWindow()
549 // and passing CW_USEDEFAULT to MoveWindow() results in resizing the
550 // window to (0, 0) size which breaks quite a lot of things, e.g. the
551 // sizer calculation in wxSizer::Fit()
552 //
553 if (nWidth == (int)CW_USEDEFAULT)
554 {
555 //
556 // The exact number doesn't matter, the dialog will be resized
557 // again soon anyhow but it should be big enough to allow
558 // calculation relying on "totalSize - clientSize > 0" work, i.e.
559 // at least greater than the title bar height
560 //
561 nWidth = nHeight = 100;
562 }
563 if (nX == (int)CW_USEDEFAULT)
564 {
565 //
566 // Centre it on the screen for now - what else can we do?
567 // TODO: We could try FCF_SHELLPOSITION but it will require moving
568 // things around a bit.
569 //
570 wxSize vSizeDpy = wxGetDisplaySize();
571
572 nX = (vSizeDpy.x - nWidth) / 2;
573 nY = (vSizeDpy.y - nHeight) / 2;
574 }
575
576 // Convert to OS/2 coordinates
577 nY = GetOS2ParentHeight(pParent) - nY - nHeight;
578
579 if (!::WinSetWindowPos( m_hFrame
580 ,HWND_TOP
581 ,nX
582 ,nY
583 ,nWidth
584 ,nHeight
585 ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_ZORDER
586 ))
587 {
588 vError = ::WinGetLastError(vHabmain);
589 sError = wxPMErrorToStr(vError);
590 wxLogError(_T("Error sizing frame. Error: %s\n"), sError.c_str());
591 return false;
592 }
593 lStyle = ::WinQueryWindowULong( m_hWnd
594 ,QWL_STYLE
595 );
596 lStyle |= WS_CLIPCHILDREN;
597 ::WinSetWindowULong( m_hWnd
598 ,QWL_STYLE
599 ,lStyle
600 );
601 return true;
602 } // end of wxTopLevelWindowOS2::CreateFrame
603
604 bool wxTopLevelWindowOS2::Create(
605 wxWindow* pParent
606 , wxWindowID vId
607 , const wxString& rsTitle
608 , const wxPoint& rPos
609 , const wxSize& rSizeOrig
610 , long lStyle
611 , const wxString& rsName
612 )
613 {
614 //
615 // Init our fields
616 //
617 Init();
618 m_windowStyle = lStyle;
619 SetName(rsName);
620 m_windowId = vId == -1 ? NewControlId() : vId;
621
622 // always create a frame of some reasonable, even if arbitrary, size (at
623 // least for MSW compatibility)
624 wxSize rSize = rSizeOrig;
625 if ( rSize.x == -1 || rSize.y == -1 )
626 {
627 wxSize sizeDpy = wxGetDisplaySize();
628 if ( rSize.x == -1 )
629 rSize.x = sizeDpy.x / 3;
630 if ( rSize.y == -1 )
631 rSize.y = sizeDpy.y / 5;
632 }
633
634 wxTopLevelWindows.Append(this);
635 if (pParent)
636 pParent->AddChild(this);
637
638 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
639 {
640 //
641 // We have different dialog templates to allow creation of dialogs
642 // with & without captions under OS2indows, resizeable or not (but a
643 // resizeable dialog always has caption - otherwise it would look too
644 // strange)
645 //
646 ULONG ulDlgTemplate;
647
648 if (lStyle & wxRESIZE_BORDER)
649 ulDlgTemplate = (ULONG)kResizeableDialog;
650 else if (lStyle & wxCAPTION)
651 ulDlgTemplate = (ULONG)kCaptionDialog;
652 else
653 ulDlgTemplate = (ULONG)kNoCaptionDialog;
654 return CreateDialog( ulDlgTemplate
655 ,rsTitle
656 ,rPos
657 ,rSize
658 );
659 }
660 else // !dialog
661 {
662 return CreateFrame( rsTitle
663 ,rPos
664 ,rSize
665 );
666 }
667 } // end of wxTopLevelWindowOS2::Create
668
669 wxTopLevelWindowOS2::~wxTopLevelWindowOS2()
670 {
671 //
672 // After destroying an owned window, Windows activates the next top level
673 // window in Z order but it may be different from our owner (to reproduce
674 // this simply Alt-TAB to another application and back before closing the
675 // owned frame) whereas we always want to yield activation to our parent
676 //
677 if (HasFlag(wxFRAME_FLOAT_ON_PARENT))
678 {
679 wxWindow* pParent = GetParent();
680
681 if (pParent)
682 {
683 ::WinSetWindowPos( GetHwndOf(pParent)
684 ,HWND_TOP
685 ,0, 0, 0, 0
686 ,SWP_ZORDER
687 );
688 }
689 }
690 } // end of wxTopLevelWindowOS2::~wxTopLevelWindowOS2
691
692 // ----------------------------------------------------------------------------
693 // wxTopLevelWindowOS2 client size
694 // ----------------------------------------------------------------------------
695
696 void wxTopLevelWindowOS2::DoSetClientSize(
697 int nWidth
698 , int nHeight
699 )
700 {
701 //
702 // Call GetClientAreaOrigin() to take the toolbar into account
703 //
704 wxPoint vPt = GetClientAreaOrigin();
705
706 nWidth += vPt.x;
707 nHeight += vPt.y;
708
709 wxWindow::DoSetClientSize( nWidth
710 ,nHeight
711 );
712 } // end of wxTopLevelWindowOS2::DoSetClientSize
713
714 void wxTopLevelWindowOS2::DoGetClientSize(
715 int* pnX
716 , int* pnY
717 ) const
718 {
719 wxWindow::DoGetClientSize( pnX
720 ,pnY
721 );
722
723 wxPoint vPt = GetClientAreaOrigin();
724
725 if (pnX)
726 *pnX -= vPt.x;
727
728 if (pnY)
729 *pnY += vPt.y;
730 } // end of wxTopLevelWindowOS2::DoGetClientSize
731
732 // ----------------------------------------------------------------------------
733 // wxTopLevelWindowOS2 showing
734 // ----------------------------------------------------------------------------
735
736 void wxTopLevelWindowOS2::DoShowWindow(
737 int nShowCmd
738 )
739 {
740 ::WinShowWindow(m_hFrame, (BOOL)(nShowCmd & SWP_SHOW));
741
742 //
743 // Need to artificially send a size event as wxApps often expect to do some
744 // final child control sizing
745 SendSizeEvent();
746 m_bIconized = nShowCmd == SWP_MINIMIZE;
747 } // end of wxTopLevelWindowOS2::DoShowWindow
748
749 bool wxTopLevelWindowOS2::Show( bool bShow )
750 {
751 int nShowCmd;
752 SWP vSwp;
753
754 if (bShow != IsShown() )
755 {
756 m_isShown = bShow;
757 }
758 else
759 {
760 return false;
761 }
762 if (bShow)
763 {
764 if (m_bMaximizeOnShow)
765 {
766 nShowCmd = SWP_MAXIMIZE;
767 m_bMaximizeOnShow = false;
768 }
769 else
770 {
771 nShowCmd = SWP_SHOW;
772 }
773 }
774 else // hide
775 {
776 nShowCmd = SWP_HIDE;
777 }
778 DoShowWindow(nShowCmd);
779
780 if (bShow)
781 {
782 wxActivateEvent vEvent(wxEVT_ACTIVATE, true, m_windowId);
783
784 ::WinQueryWindowPos(m_hFrame, &vSwp);
785 m_bIconized = ( vSwp.fl & SWP_MINIMIZE ) == SWP_MINIMIZE ;
786 ::WinQueryWindowPos(m_hWnd, &m_vSwpClient);
787 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
788 ::WinQueryWindowPos(m_hWnd, &vSwp);
789 ::WinEnableWindow(m_hFrame, TRUE);
790
791 vEvent.SetEventObject(this);
792 GetEventHandler()->ProcessEvent(vEvent);
793 }
794 else
795 {
796 //
797 // Try to highlight the correct window (the parent)
798 //
799 if (GetParent())
800 {
801 HWND hWndParent = GetHwndOf(GetParent());
802
803 ::WinQueryWindowPos(hWndParent, &vSwp);
804 m_bIconized = (vSwp.fl & SWP_MINIMIZE)==SWP_MINIMIZE;
805 ::WinEnableWindow(hWndParent, TRUE);
806 }
807 }
808 return true;
809 } // end of wxTopLevelWindowOS2::Show
810
811 // ----------------------------------------------------------------------------
812 // wxTopLevelWindowOS2 maximize/minimize
813 // ----------------------------------------------------------------------------
814
815 void wxTopLevelWindowOS2::Maximize(
816 bool bMaximize
817 )
818 {
819 if (IsShown())
820 {
821 //
822 // Just maximize it directly
823 //
824 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
825 }
826 else // hidden
827 {
828 //
829 // We can't maximize the hidden frame because it shows it as well, so
830 // just remember that we should do it later in this case
831 //
832 m_bMaximizeOnShow = bMaximize;
833 }
834 } // end of wxTopLevelWindowOS2::Maximize
835
836 bool wxTopLevelWindowOS2::IsMaximized() const
837 {
838 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
839 return (m_vSwp.fl & SWP_MAXIMIZE) == SWP_MAXIMIZE;
840 } // end of wxTopLevelWindowOS2::IsMaximized
841
842 void wxTopLevelWindowOS2::SetTitle( const wxString& title)
843 {
844 SetLabel(title);
845 }
846
847 wxString wxTopLevelWindowOS2::GetTitle() const
848 {
849 return GetLabel();
850 }
851
852 void wxTopLevelWindowOS2::Iconize( bool bIconize )
853 {
854 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
855 } // end of wxTopLevelWindowOS2::Iconize
856
857 bool wxTopLevelWindowOS2::IsIconized() const
858 {
859 // also update the current state
860 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
861 if (m_vSwp.fl & SWP_MINIMIZE)
862 ((wxTopLevelWindow*)this)->m_bIconized = true;
863 else
864 ((wxTopLevelWindow*)this)->m_bIconized = false;
865 return m_bIconized;
866 } // end of wxTopLevelWindowOS2::IsIconized
867
868 void wxTopLevelWindowOS2::Restore()
869 {
870 DoShowWindow(SWP_RESTORE);
871 } // end of wxTopLevelWindowOS2::Restore
872
873 // generate an artificial resize event
874 void wxTopLevelWindowOS2::SendSizeEvent()
875 {
876 if (!m_bIconized)
877 {
878 RECTL vRect = wxGetWindowRect(GetHwnd());
879
880 (void)::WinPostMsg( m_hFrame
881 ,WM_SIZE
882 ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
883 ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
884 );
885 }
886 } // end of wxTopLevelWindowOS2::SendSizeEvent
887
888 // ----------------------------------------------------------------------------
889 // wxTopLevelWindowOS2 fullscreen
890 // ----------------------------------------------------------------------------
891
892 bool wxTopLevelWindowOS2::ShowFullScreen( bool bShow,
893 long lStyle )
894 {
895 if (bShow)
896 {
897 if (IsFullScreen())
898 return false;
899
900 m_bFsIsShowing = true;
901 m_lFsStyle = lStyle;
902
903 //
904 // Zap the frame borders
905 //
906
907 //
908 // Save the 'normal' window lStyle
909 //
910 m_lFsOldWindowStyle = ::WinQueryWindowULong( (HWND)GetHWND()
911 ,QWL_STYLE
912 );
913
914 //
915 // Save the old position, width & height, maximize state
916 //
917 m_vFsOldSize = GetRect();
918 m_bFsIsMaximized = IsMaximized();
919
920 //
921 // Decide which window lStyle flags to turn off
922 //
923 LONG lNewStyle = m_lFsOldWindowStyle;
924 LONG lOffFlags = 0;
925
926 if (lStyle & wxFULLSCREEN_NOBORDER)
927 lOffFlags |= FCF_BORDER;
928 if (lStyle & wxFULLSCREEN_NOCAPTION)
929 lOffFlags |= (FCF_TASKLIST | FCF_SYSMENU);
930
931 lNewStyle &= (~lOffFlags);
932
933 //
934 // Change our window style to be compatible with full-screen mode
935 //
936 ::WinSetWindowULong( (HWND)GetHWND()
937 ,QWL_STYLE
938 ,lNewStyle
939 );
940
941 //
942 // Resize to the size of the desktop
943 //
944 int nWidth;
945 int nHeight;
946 RECTL vRect = wxGetWindowRect(HWND_DESKTOP);
947
948 nWidth = vRect.xRight - vRect.xLeft;
949 nHeight = vRect.yTop - vRect.yBottom;
950
951 SetSize( nWidth, nHeight );
952
953 //
954 // Now flush the window style cache and actually go full-screen
955 //
956 ::WinSetWindowPos( m_hFrame
957 ,HWND_TOP
958 ,0
959 ,0
960 ,nWidth
961 ,nHeight
962 ,SWP_SIZE | SWP_MOVE
963 );
964
965 wxSize full( nWidth, nHeight );
966 wxSizeEvent vEvent( full, GetId() );
967 GetEventHandler()->ProcessEvent(vEvent);
968 return true;
969 }
970 else
971 {
972 if (!IsFullScreen())
973 return false;
974
975 m_bFsIsShowing = false;
976 Maximize(m_bFsIsMaximized);
977 ::WinSetWindowULong( (HWND)GetHWND()
978 ,QWL_STYLE
979 ,m_lFsOldWindowStyle
980 );
981 ::WinSetWindowPos( m_hFrame
982 ,HWND_TOP
983 ,m_vFsOldSize.x
984 ,m_vFsOldSize.y
985 ,m_vFsOldSize.width
986 ,m_vFsOldSize.height
987 ,SWP_SIZE | SWP_MOVE
988 );
989 return true;
990 }
991 } // end of wxTopLevelWindowOS2::ShowFullScreen
992
993 // ----------------------------------------------------------------------------
994 // wxTopLevelWindowOS2 misc
995 // ----------------------------------------------------------------------------
996
997 void wxTopLevelWindowOS2::SetIcon(
998 const wxIcon& rIcon
999 )
1000 {
1001 SetIcons(wxIconBundle(rIcon));
1002 } // end of wxTopLevelWindowOS2::SetIcon
1003
1004 void wxTopLevelWindowOS2::SetIcons(
1005 const wxIconBundle& rIcons
1006 )
1007 {
1008 //
1009 // This sets m_icon
1010 //
1011 wxTopLevelWindowBase::SetIcons(rIcons);
1012
1013 const wxIcon& vIcon = rIcons.GetIcon(wxSize(32, 32));
1014
1015 if (vIcon.Ok() && vIcon.GetWidth() == 32 && vIcon.GetHeight() == 32)
1016 {
1017 ::WinSendMsg( m_hFrame
1018 ,WM_SETICON
1019 ,(MPARAM)((HPOINTER)vIcon.GetHICON())
1020 ,NULL
1021 );
1022 ::WinSendMsg( m_hFrame
1023 ,WM_UPDATEFRAME
1024 ,(MPARAM)FCF_ICON
1025 ,(MPARAM)0
1026 );
1027 }
1028 } // end of wxTopLevelWindowOS2::SetIcon
1029
1030 bool wxTopLevelWindowOS2::EnableCloseButton( bool bEnable )
1031 {
1032 //
1033 // Get system (a.k.a. window) menu
1034 //
1035 HMENU hMenu = ::WinWindowFromID(m_hFrame, FID_SYSMENU);
1036
1037 if (!hMenu)
1038 {
1039 wxLogLastError(_T("GetSystemMenu"));
1040 return false;
1041 }
1042
1043 //
1044 // Enabling/disabling the close item from it also automatically
1045 // disables/enables the close title bar button
1046 //
1047 if (bEnable)
1048 (void)::WinSendMsg( hMenu
1049 ,MM_SETITEMATTR
1050 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1051 ,MPFROM2SHORT(MIA_DISABLED, FALSE)
1052 );
1053 else
1054 (void)::WinSendMsg( hMenu
1055 ,MM_SETITEMATTR
1056 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1057 ,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
1058 );
1059
1060 //
1061 // Update appearance immediately
1062 //
1063 ::WinSendMsg( m_hFrame
1064 ,WM_UPDATEFRAME
1065 ,(MPARAM)FCF_MENU
1066 ,(MPARAM)0
1067 );
1068 return true;
1069 } // end of wxTopLevelWindowOS2::EnableCloseButton
1070
1071 // ============================================================================
1072 // wxTLWHiddenParentModule implementation
1073 // ============================================================================
1074
1075 HWND wxTLWHiddenParentModule::m_shWnd = NULL;
1076 const wxChar* wxTLWHiddenParentModule::m_szClassName = NULL;
1077
1078 bool wxTLWHiddenParentModule::OnInit()
1079 {
1080 m_shWnd = NULL;
1081 m_szClassName = NULL;
1082 return true;
1083 } // end of wxTLWHiddenParentModule::OnInit
1084
1085 void wxTLWHiddenParentModule::OnExit()
1086 {
1087 if (m_shWnd)
1088 {
1089 if (!::WinDestroyWindow(m_shWnd))
1090 {
1091 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1092 }
1093 m_shWnd = NULL;
1094 }
1095
1096 m_szClassName = NULL;
1097 } // end of wxTLWHiddenParentModule::OnExit
1098
1099 /* static */
1100 HWND wxTLWHiddenParentModule::GetHWND()
1101 {
1102 if (!m_shWnd)
1103 {
1104 if (!m_szClassName)
1105 {
1106 static const wxChar* zHIDDEN_PARENT_CLASS = _T("wxTLWHiddenParent");
1107
1108 if (!::WinRegisterClass( wxGetInstance()
1109 ,(PSZ)zHIDDEN_PARENT_CLASS
1110 ,NULL
1111 ,0
1112 ,sizeof(ULONG)
1113 ))
1114 {
1115 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1116 }
1117 else
1118 {
1119 m_szClassName = zHIDDEN_PARENT_CLASS;
1120 }
1121 }
1122 m_shWnd = ::WinCreateWindow( HWND_DESKTOP,
1123 (PSZ)m_szClassName,
1124 "",
1125 0L,
1126 (LONG)0L,
1127 (LONG)0L,
1128 (LONG)0L,
1129 (LONG)0L,
1130 NULLHANDLE,
1131 HWND_TOP,
1132 0L,
1133 NULL,
1134 NULL );
1135 if (!m_shWnd)
1136 {
1137 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));
1138 }
1139 }
1140 return m_shWnd;
1141 } // end of wxTLWHiddenParentModule::GetHWND