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