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