]> git.saurik.com Git - wxWidgets.git/blob - src/os2/toplevel.cpp
remove sizing controls when being in fullscreen mode
[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 & wxTHICK_FRAME)
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 & wxTHICK_FRAME) == 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 ::WinSetWindowPos( GetHwnd()
425 ,HWND_TOP
426 ,nX
427 ,nY
428 ,nWidth
429 ,nHeight
430 ,SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_SHOW | SWP_ACTIVATE
431 );
432 ::WinQueryWindowPos(GetHwnd(), GetSwp());
433 m_hFrame = m_hWnd;
434 SubclassWin(m_hWnd);
435 return true;
436 } // end of wxTopLevelWindowOS2::CreateDialog
437
438 bool wxTopLevelWindowOS2::CreateFrame( const wxString& rsTitle,
439 const wxPoint& rPos,
440 const wxSize& rSize )
441 {
442 WXDWORD lExflags;
443 WXDWORD lFlags = OS2GetCreateWindowFlags(&lExflags);
444 long lStyle = GetWindowStyleFlag();
445 int nX = rPos.x;
446 int nY = rPos.y;
447 int nWidth = rSize.x;
448 int nHeight = rSize.y;
449 ULONG ulStyleFlags = 0L;
450 ERRORID vError;
451 wxString sError;
452 wxWindow* pParent = GetParent();
453 HWND hParent;
454 HWND hFrame;
455 HWND hClient;
456
457 if (pParent)
458 hParent = GetHwndOf(pParent);
459 else
460 hParent = HWND_DESKTOP;
461
462 if ((lStyle & wxMINIMIZE) || (lStyle & wxICONIZE))
463 ulStyleFlags |= WS_MINIMIZED;
464 if (lStyle & wxMAXIMIZE)
465 ulStyleFlags |= WS_MAXIMIZED;
466
467 //
468 // Clear the visible flag, we always call show
469 //
470 ulStyleFlags &= (unsigned long)~WS_VISIBLE;
471 m_bIconized = false;
472
473 //
474 // Create the frame window: We break ranks with other ports now
475 // and instead of calling down into the base wxWindow class' OS2Create
476 // we do all our own stuff here. We will set the needed pieces
477 // of wxWindow manually, here.
478 //
479
480 hFrame = ::WinCreateStdWindow( hParent
481 ,ulStyleFlags // frame-window style
482 ,(PULONG)&lFlags // window style
483 ,(PSZ)wxFrameClassName // class name
484 ,(PSZ)rsTitle.c_str() // window title
485 ,0L // default client style
486 ,NULLHANDLE // resource in executable file
487 ,0 // resource id
488 ,&hClient // receives client window handle
489 );
490 if (!hFrame)
491 {
492 vError = ::WinGetLastError(vHabmain);
493 sError = wxPMErrorToStr(vError);
494 wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str());
495 return false;
496 }
497
498 //
499 // wxWindow class' m_hWnd set here and needed associations
500 //
501 m_hFrame = hFrame;
502 m_hWnd = hClient;
503 wxAssociateWinWithHandle(m_hWnd, this);
504 wxAssociateWinWithHandle(m_hFrame, this);
505
506 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
507
508 LONG lColor = (LONG)m_backgroundColour.GetPixel();
509
510 if (!::WinSetPresParam( m_hWnd
511 ,PP_BACKGROUNDCOLOR
512 ,sizeof(LONG)
513 ,(PVOID)&lColor
514 ))
515 {
516 vError = ::WinGetLastError(vHabmain);
517 sError = wxPMErrorToStr(vError);
518 wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str());
519 return false;
520 }
521
522 //
523 // Now need to subclass window. Instead of calling the SubClassWin in wxWindow
524 // we manually subclass here because we don't want to use the main wxWndProc
525 // by default
526 //
527 m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(m_hFrame, (PFNWP)wxFrameMainWndProc);
528
529 //
530 // Now size everything. If adding a menu the client will need to be resized.
531 //
532
533 if (pParent)
534 {
535 nY = pParent->GetSize().y - (nY + nHeight);
536 }
537 else
538 {
539 RECTL vRect;
540
541 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
542 nY = vRect.yTop - (nY + nHeight);
543 }
544 if (!::WinSetWindowPos( m_hFrame
545 ,HWND_TOP
546 ,nX
547 ,nY
548 ,nWidth
549 ,nHeight
550 ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_ZORDER
551 ))
552 {
553 vError = ::WinGetLastError(vHabmain);
554 sError = wxPMErrorToStr(vError);
555 wxLogError(_T("Error sizing frame. Error: %s\n"), sError.c_str());
556 return false;
557 }
558 lStyle = ::WinQueryWindowULong( m_hWnd
559 ,QWL_STYLE
560 );
561 lStyle |= WS_CLIPCHILDREN;
562 ::WinSetWindowULong( m_hWnd
563 ,QWL_STYLE
564 ,lStyle
565 );
566 return true;
567 } // end of wxTopLevelWindowOS2::CreateFrame
568
569 bool wxTopLevelWindowOS2::Create(
570 wxWindow* pParent
571 , wxWindowID vId
572 , const wxString& rsTitle
573 , const wxPoint& rPos
574 , const wxSize& rSizeOrig
575 , long lStyle
576 , const wxString& rsName
577 )
578 {
579 //
580 // Init our fields
581 //
582 Init();
583 m_windowStyle = lStyle;
584 SetName(rsName);
585 m_windowId = vId == -1 ? NewControlId() : vId;
586
587 // always create a frame of some reasonable, even if arbitrary, size (at
588 // least for MSW compatibility)
589 wxSize rSize = rSizeOrig;
590 if ( rSize.x == -1 || rSize.y == -1 )
591 {
592 wxSize sizeDpy = wxGetDisplaySize();
593 if ( rSize.x == -1 )
594 rSize.x = sizeDpy.x / 3;
595 if ( rSize.y == -1 )
596 rSize.y = sizeDpy.y / 5;
597 }
598
599 wxTopLevelWindows.Append(this);
600 if (pParent)
601 pParent->AddChild(this);
602
603 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
604 {
605 //
606 // We have different dialog templates to allow creation of dialogs
607 // with & without captions under OS2indows, resizeable or not (but a
608 // resizeable dialog always has caption - otherwise it would look too
609 // strange)
610 //
611 ULONG ulDlgTemplate;
612
613 if (lStyle & wxRESIZE_BORDER)
614 ulDlgTemplate = (ULONG)kResizeableDialog;
615 else if (lStyle & wxCAPTION)
616 ulDlgTemplate = (ULONG)kCaptionDialog;
617 else
618 ulDlgTemplate = (ULONG)kNoCaptionDialog;
619 return CreateDialog( ulDlgTemplate
620 ,rsTitle
621 ,rPos
622 ,rSize
623 );
624 }
625 else // !dialog
626 {
627 return CreateFrame( rsTitle
628 ,rPos
629 ,rSize
630 );
631 }
632 } // end of wxTopLevelWindowOS2::Create
633
634 wxTopLevelWindowOS2::~wxTopLevelWindowOS2()
635 {
636 //
637 // After destroying an owned window, Windows activates the next top level
638 // window in Z order but it may be different from our owner (to reproduce
639 // this simply Alt-TAB to another application and back before closing the
640 // owned frame) whereas we always want to yield activation to our parent
641 //
642 if (HasFlag(wxFRAME_FLOAT_ON_PARENT))
643 {
644 wxWindow* pParent = GetParent();
645
646 if (pParent)
647 {
648 ::WinSetWindowPos( GetHwndOf(pParent)
649 ,HWND_TOP
650 ,0, 0, 0, 0
651 ,SWP_ZORDER
652 );
653 }
654 }
655 } // end of wxTopLevelWindowOS2::~wxTopLevelWindowOS2
656
657 // ----------------------------------------------------------------------------
658 // wxTopLevelWindowOS2 client size
659 // ----------------------------------------------------------------------------
660
661 void wxTopLevelWindowOS2::DoSetClientSize(
662 int nWidth
663 , int nHeight
664 )
665 {
666 //
667 // Call GetClientAreaOrigin() to take the toolbar into account
668 //
669 wxPoint vPt = GetClientAreaOrigin();
670
671 nWidth += vPt.x;
672 nHeight += vPt.y;
673
674 wxWindow::DoSetClientSize( nWidth
675 ,nHeight
676 );
677 } // end of wxTopLevelWindowOS2::DoSetClientSize
678
679 void wxTopLevelWindowOS2::DoGetClientSize(
680 int* pnX
681 , int* pnY
682 ) const
683 {
684 wxWindow::DoGetClientSize( pnX
685 ,pnY
686 );
687
688 wxPoint vPt = GetClientAreaOrigin();
689
690 if (pnX)
691 *pnX -= vPt.x;
692
693 if (pnY)
694 *pnY += vPt.y;
695 } // end of wxTopLevelWindowOS2::DoGetClientSize
696
697 // ----------------------------------------------------------------------------
698 // wxTopLevelWindowOS2 showing
699 // ----------------------------------------------------------------------------
700
701 void wxTopLevelWindowOS2::DoShowWindow(
702 int nShowCmd
703 )
704 {
705 ::WinShowWindow(m_hFrame, (BOOL)(nShowCmd & SWP_SHOW));
706
707 //
708 // Need to artificially send a size event as wxApps often expect to do some
709 // final child control sizing
710 SendSizeEvent();
711 m_bIconized = nShowCmd == SWP_MINIMIZE;
712 } // end of wxTopLevelWindowOS2::DoShowWindow
713
714 bool wxTopLevelWindowOS2::Show( bool bShow )
715 {
716 int nShowCmd;
717 SWP vSwp;
718
719 if (bShow != IsShown() )
720 {
721 m_isShown = bShow;
722 }
723 else
724 {
725 return false;
726 }
727 if (bShow)
728 {
729 if (m_bMaximizeOnShow)
730 {
731 nShowCmd = SWP_MAXIMIZE;
732 m_bMaximizeOnShow = false;
733 }
734 else
735 {
736 nShowCmd = SWP_SHOW;
737 }
738 }
739 else // hide
740 {
741 nShowCmd = SWP_HIDE;
742 }
743 DoShowWindow(nShowCmd);
744
745 if (bShow)
746 {
747 wxActivateEvent vEvent(wxEVT_ACTIVATE, true, m_windowId);
748
749 ::WinQueryWindowPos(m_hFrame, &vSwp);
750 m_bIconized = ( vSwp.fl & SWP_MINIMIZE ) == SWP_MINIMIZE ;
751 ::WinQueryWindowPos(m_hWnd, &m_vSwpClient);
752 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
753 ::WinQueryWindowPos(m_hWnd, &vSwp);
754 ::WinEnableWindow(m_hFrame, TRUE);
755
756 //
757 // Deal with children
758 //
759 MoveChildren(m_vSwpClient.cy - vSwp.cy);
760 vEvent.SetEventObject(this);
761 GetEventHandler()->ProcessEvent(vEvent);
762 }
763 else
764 {
765 //
766 // Try to highlight the correct window (the parent)
767 //
768 if (GetParent())
769 {
770 HWND hWndParent = GetHwndOf(GetParent());
771
772 ::WinQueryWindowPos(hWndParent, &vSwp);
773 m_bIconized = (vSwp.fl & SWP_MINIMIZE)==SWP_MINIMIZE;
774 ::WinEnableWindow(hWndParent, TRUE);
775 }
776 }
777 return true;
778 } // end of wxTopLevelWindowOS2::Show
779
780 // ----------------------------------------------------------------------------
781 // wxTopLevelWindowOS2 maximize/minimize
782 // ----------------------------------------------------------------------------
783
784 void wxTopLevelWindowOS2::Maximize(
785 bool bMaximize
786 )
787 {
788 if (IsShown())
789 {
790 //
791 // Just maximize it directly
792 //
793 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
794 }
795 else // hidden
796 {
797 //
798 // We can't maximize the hidden frame because it shows it as well, so
799 // just remember that we should do it later in this case
800 //
801 m_bMaximizeOnShow = bMaximize;
802 }
803 } // end of wxTopLevelWindowOS2::Maximize
804
805 bool wxTopLevelWindowOS2::IsMaximized() const
806 {
807 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
808 return (m_vSwp.fl & SWP_MAXIMIZE) == SWP_MAXIMIZE;
809 } // end of wxTopLevelWindowOS2::IsMaximized
810
811 void wxTopLevelWindowOS2::SetTitle( const wxString& title)
812 {
813 SetLabel(title);
814 }
815
816 wxString wxTopLevelWindowOS2::GetTitle() const
817 {
818 return GetLabel();
819 }
820
821 void wxTopLevelWindowOS2::Iconize( bool bIconize )
822 {
823 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
824 } // end of wxTopLevelWindowOS2::Iconize
825
826 bool wxTopLevelWindowOS2::IsIconized() const
827 {
828 // also update the current state
829 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
830 if (m_vSwp.fl & SWP_MINIMIZE)
831 ((wxTopLevelWindow*)this)->m_bIconized = true;
832 else
833 ((wxTopLevelWindow*)this)->m_bIconized = false;
834 return m_bIconized;
835 } // end of wxTopLevelWindowOS2::IsIconized
836
837 void wxTopLevelWindowOS2::Restore()
838 {
839 DoShowWindow(SWP_RESTORE);
840 } // end of wxTopLevelWindowOS2::Restore
841
842 // generate an artificial resize event
843 void wxTopLevelWindowOS2::SendSizeEvent()
844 {
845 if (!m_bIconized)
846 {
847 RECTL vRect = wxGetWindowRect(GetHwnd());
848
849 (void)::WinPostMsg( m_hFrame
850 ,WM_SIZE
851 ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
852 ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
853 );
854 }
855 } // end of wxTopLevelWindowOS2::SendSizeEvent
856
857 // ----------------------------------------------------------------------------
858 // wxTopLevelWindowOS2 fullscreen
859 // ----------------------------------------------------------------------------
860
861 bool wxTopLevelWindowOS2::ShowFullScreen( bool bShow,
862 long lStyle )
863 {
864 if (bShow)
865 {
866 if (IsFullScreen())
867 return false;
868
869 m_bFsIsShowing = true;
870 m_lFsStyle = lStyle;
871
872 //
873 // Zap the frame borders
874 //
875
876 //
877 // Save the 'normal' window lStyle
878 //
879 m_lFsOldWindowStyle = ::WinQueryWindowULong( (HWND)GetHWND()
880 ,QWL_STYLE
881 );
882
883 //
884 // Save the old position, width & height, maximize state
885 //
886 m_vFsOldSize = GetRect();
887 m_bFsIsMaximized = IsMaximized();
888
889 //
890 // Decide which window lStyle flags to turn off
891 //
892 LONG lNewStyle = m_lFsOldWindowStyle;
893 LONG lOffFlags = 0;
894
895 if (lStyle & wxFULLSCREEN_NOBORDER)
896 lOffFlags |= FCF_BORDER;
897 if (lStyle & wxFULLSCREEN_NOCAPTION)
898 lOffFlags |= (FCF_TASKLIST | FCF_SYSMENU);
899
900 lNewStyle &= (~lOffFlags);
901
902 //
903 // Change our window style to be compatible with full-screen mode
904 //
905 ::WinSetWindowULong( (HWND)GetHWND()
906 ,QWL_STYLE
907 ,lNewStyle
908 );
909
910 //
911 // Resize to the size of the desktop
912 //
913 int nWidth;
914 int nHeight;
915 RECTL vRect = wxGetWindowRect(HWND_DESKTOP);
916
917 nWidth = vRect.xRight - vRect.xLeft;
918 nHeight = vRect.yTop - vRect.yBottom;
919
920 SetSize( nWidth, nHeight );
921
922 //
923 // Now flush the window style cache and actually go full-screen
924 //
925 ::WinSetWindowPos( m_hFrame
926 ,HWND_TOP
927 ,0
928 ,0
929 ,nWidth
930 ,nHeight
931 ,SWP_SIZE | SWP_MOVE
932 );
933
934 wxSize full( nWidth, nHeight );
935 wxSizeEvent vEvent( full, GetId() );
936 GetEventHandler()->ProcessEvent(vEvent);
937 return true;
938 }
939 else
940 {
941 if (!IsFullScreen())
942 return false;
943
944 m_bFsIsShowing = false;
945 Maximize(m_bFsIsMaximized);
946 ::WinSetWindowULong( (HWND)GetHWND()
947 ,QWL_STYLE
948 ,m_lFsOldWindowStyle
949 );
950 ::WinSetWindowPos( m_hFrame
951 ,HWND_TOP
952 ,m_vFsOldSize.x
953 ,m_vFsOldSize.y
954 ,m_vFsOldSize.width
955 ,m_vFsOldSize.height
956 ,SWP_SIZE | SWP_MOVE
957 );
958 return true;
959 }
960 } // end of wxTopLevelWindowOS2::ShowFullScreen
961
962 // ----------------------------------------------------------------------------
963 // wxTopLevelWindowOS2 misc
964 // ----------------------------------------------------------------------------
965
966 void wxTopLevelWindowOS2::SetIcon(
967 const wxIcon& rIcon
968 )
969 {
970 SetIcons(wxIconBundle(rIcon));
971 } // end of wxTopLevelWindowOS2::SetIcon
972
973 void wxTopLevelWindowOS2::SetIcons(
974 const wxIconBundle& rIcons
975 )
976 {
977 //
978 // This sets m_icon
979 //
980 wxTopLevelWindowBase::SetIcons(rIcons);
981
982 const wxIcon& vIcon = rIcons.GetIcon(wxSize(32, 32));
983
984 if (vIcon.Ok() && vIcon.GetWidth() == 32 && vIcon.GetHeight() == 32)
985 {
986 ::WinSendMsg( m_hFrame
987 ,WM_SETICON
988 ,(MPARAM)((HPOINTER)vIcon.GetHICON())
989 ,NULL
990 );
991 ::WinSendMsg( m_hFrame
992 ,WM_UPDATEFRAME
993 ,(MPARAM)FCF_ICON
994 ,(MPARAM)0
995 );
996 }
997 } // end of wxTopLevelWindowOS2::SetIcon
998
999 bool wxTopLevelWindowOS2::EnableCloseButton( bool bEnable )
1000 {
1001 //
1002 // Get system (a.k.a. window) menu
1003 //
1004 HMENU hMenu = ::WinWindowFromID(m_hFrame, FID_SYSMENU);
1005
1006 if (!hMenu)
1007 {
1008 wxLogLastError(_T("GetSystemMenu"));
1009 return false;
1010 }
1011
1012 //
1013 // Enabling/disabling the close item from it also automatically
1014 // disables/enables the close title bar button
1015 //
1016 if (bEnable)
1017 (void)::WinSendMsg( hMenu
1018 ,MM_SETITEMATTR
1019 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1020 ,MPFROM2SHORT(MIA_DISABLED, FALSE)
1021 );
1022 else
1023 (void)::WinSendMsg( hMenu
1024 ,MM_SETITEMATTR
1025 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1026 ,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
1027 );
1028
1029 //
1030 // Update appearance immediately
1031 //
1032 ::WinSendMsg( m_hFrame
1033 ,WM_UPDATEFRAME
1034 ,(MPARAM)FCF_MENU
1035 ,(MPARAM)0
1036 );
1037 return true;
1038 } // end of wxTopLevelWindowOS2::EnableCloseButton
1039
1040 // ============================================================================
1041 // wxTLWHiddenParentModule implementation
1042 // ============================================================================
1043
1044 HWND wxTLWHiddenParentModule::m_shWnd = NULL;
1045 const wxChar* wxTLWHiddenParentModule::m_szClassName = NULL;
1046
1047 bool wxTLWHiddenParentModule::OnInit()
1048 {
1049 m_shWnd = NULL;
1050 m_szClassName = NULL;
1051 return true;
1052 } // end of wxTLWHiddenParentModule::OnInit
1053
1054 void wxTLWHiddenParentModule::OnExit()
1055 {
1056 if (m_shWnd)
1057 {
1058 if (!::WinDestroyWindow(m_shWnd))
1059 {
1060 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1061 }
1062 m_shWnd = NULL;
1063 }
1064
1065 m_szClassName = NULL;
1066 } // end of wxTLWHiddenParentModule::OnExit
1067
1068 /* static */
1069 HWND wxTLWHiddenParentModule::GetHWND()
1070 {
1071 if (!m_shWnd)
1072 {
1073 if (!m_szClassName)
1074 {
1075 static const wxChar* zHIDDEN_PARENT_CLASS = _T("wxTLWHiddenParent");
1076
1077 if (!::WinRegisterClass( wxGetInstance()
1078 ,(PSZ)zHIDDEN_PARENT_CLASS
1079 ,NULL
1080 ,0
1081 ,sizeof(ULONG)
1082 ))
1083 {
1084 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1085 }
1086 else
1087 {
1088 m_szClassName = zHIDDEN_PARENT_CLASS;
1089 }
1090 }
1091 m_shWnd = ::WinCreateWindow( HWND_DESKTOP,
1092 (PSZ)m_szClassName,
1093 "",
1094 0L,
1095 (LONG)0L,
1096 (LONG)0L,
1097 (LONG)0L,
1098 (LONG)0L,
1099 NULLHANDLE,
1100 HWND_TOP,
1101 0L,
1102 NULL,
1103 NULL );
1104 if (!m_shWnd)
1105 {
1106 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));
1107 }
1108 }
1109 return m_shWnd;
1110 } // end of wxTLWHiddenParentModule::GetHWND