]> git.saurik.com Git - wxWidgets.git/blob - src/os2/toplevel.cpp
cleanup - reformat
[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 #endif //WX_PRECOMP
38
39 #include "wx/module.h" // wxSetFocusToChild()
40 #include "wx/os2/private.h"
41
42 // ----------------------------------------------------------------------------
43 // stubs for missing functions under MicroWindows
44 // ----------------------------------------------------------------------------
45
46
47 // ----------------------------------------------------------------------------
48 // globals
49 // ----------------------------------------------------------------------------
50
51 // the name of the default wxWidgets class
52 extern void wxAssociateWinWithHandle( HWND hWnd, wxWindowOS2* pWin );
53
54 bool wxTopLevelWindowOS2::m_sbInitialized = false;
55 wxWindow* wxTopLevelWindowOS2::m_spHiddenParent = NULL;
56
57 // ============================================================================
58 // wxTopLevelWindowOS2 implementation
59 // ============================================================================
60
61 BEGIN_EVENT_TABLE(wxTopLevelWindowOS2, wxTopLevelWindowBase)
62 EVT_ACTIVATE(wxTopLevelWindowOS2::OnActivate)
63 END_EVENT_TABLE()
64
65 // ============================================================================
66 // wxTopLevelWindowMSW implementation
67 // ============================================================================
68
69 // Dialog window proc
70 MRESULT EXPENTRY wxDlgProc( HWND WXUNUSED(hWnd)
71 ,UINT uMessage
72 ,void * WXUNUSED(wParam)
73 ,void * WXUNUSED(lParam)
74 )
75 {
76 switch(uMessage)
77 {
78 case WM_INITDLG:
79 //
80 // For this message, returning TRUE tells system to set focus to
81 // the first control in the dialog box, but we set the focus
82 // ourselves, however in OS/2 we must return true to enable the dialog
83 //
84 return (MRESULT)TRUE;
85 default:
86 //
87 // For all the other ones, FALSE means that we didn't process the
88 // message
89 //
90 return (MRESULT)FALSE;
91 }
92 } // end of wxDlgProc
93
94 // ----------------------------------------------------------------------------
95 // wxTLWHiddenParentModule: used to manage the hidden parent window (we need a
96 // module to ensure that the window is always deleted)
97 // ----------------------------------------------------------------------------
98
99 class wxTLWHiddenParentModule : public wxModule
100 {
101 public:
102 //
103 // Module init/finalize
104 //
105 virtual bool OnInit(void);
106 virtual void OnExit(void);
107
108 //
109 // Get the hidden window (creates on demand)
110 //
111 static HWND GetHWND(void);
112
113 private:
114 //
115 // The HWND of the hidden parent
116 //
117 static HWND m_shWnd;
118
119 //
120 // The class used to create it
121 //
122 static const wxChar* m_szClassName;
123 DECLARE_DYNAMIC_CLASS(wxTLWHiddenParentModule)
124 }; // end of CLASS wxTLWHiddenParentModule
125
126 IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule, wxModule)
127
128 // ----------------------------------------------------------------------------
129 // wxTopLevelWindowOS2 creation
130 // ----------------------------------------------------------------------------
131
132 void wxTopLevelWindowOS2::Init()
133 {
134 m_bIconized = m_bMaximizeOnShow = false;
135
136 //
137 // Unlike (almost?) all other windows, frames are created hidden
138 //
139 m_isShown = false;
140
141 //
142 // Data to save/restore when calling ShowFullScreen
143 m_lFsStyle = 0;
144 m_lFsOldWindowStyle = 0;
145 m_bFsIsMaximized = false;
146 m_bFsIsShowing = false;
147
148 m_hFrame = NULLHANDLE;
149 memset(&m_vSwp, 0, sizeof(SWP));
150 memset(&m_vSwpClient, 0, sizeof(SWP));
151 m_pWinLastFocused = (wxWindow *)NULL;
152 } // end of wxTopLevelWindowIOS2::Init
153
154 void wxTopLevelWindowOS2::OnActivate(
155 wxActivateEvent& rEvent
156 )
157 {
158 if (rEvent.GetActive())
159 {
160 //
161 // Restore focus to the child which was last focused
162 //
163 wxLogTrace(_T("focus"), _T("wxTLW %08lx activated."), m_hWnd);
164
165 wxWindow* pParent = m_pWinLastFocused ? m_pWinLastFocused->GetParent()
166 : NULL;
167 if (!pParent)
168 {
169 pParent = this;
170 }
171
172 wxSetFocusToChild( pParent
173 ,&m_pWinLastFocused
174 );
175 }
176 else // deactivating
177 {
178 //
179 // Remember the last focused child if it is our child
180 //
181 m_pWinLastFocused = FindFocus();
182
183 //
184 // So we NULL it out if it's a child from some other frame
185 //
186 wxWindow* pWin = m_pWinLastFocused;
187
188 while (pWin)
189 {
190 if (pWin->IsTopLevel())
191 {
192 if (pWin != this)
193 {
194 m_pWinLastFocused = NULL;
195 }
196 break;
197 }
198 pWin = pWin->GetParent();
199 }
200
201 wxLogTrace(_T("focus"),
202 _T("wxTLW %08lx deactivated, last focused: %08lx."),
203 m_hWnd,
204 m_pWinLastFocused ? GetHwndOf(m_pWinLastFocused)
205 : NULL);
206 rEvent.Skip();
207 }
208 } // end of wxTopLevelWindowOS2::OnActivate
209
210 WXDWORD wxTopLevelWindowOS2::OS2GetStyle(
211 long lStyle
212 , WXDWORD* pdwExflags
213 ) const
214 {
215 long lMsflags = wxWindow::OS2GetStyle( (lStyle & ~wxBORDER_MASK) | wxBORDER_NONE
216 ,pdwExflags
217 );
218
219 if ((lStyle & wxDEFAULT_FRAME_STYLE) == wxDEFAULT_FRAME_STYLE)
220 lMsflags |= FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU |
221 FCF_MINMAX | FCF_TASKLIST;
222
223 if ((lStyle & wxCAPTION) == wxCAPTION)
224 lMsflags |= FCF_TASKLIST;
225 else
226 lMsflags |= FCF_NOMOVEWITHOWNER;
227
228 if ((lStyle & wxVSCROLL) == wxVSCROLL)
229 lMsflags |= FCF_VERTSCROLL;
230 if ((lStyle & wxHSCROLL) == wxHSCROLL)
231 lMsflags |= FCF_HORZSCROLL;
232 if (lStyle & wxMINIMIZE_BOX)
233 lMsflags |= FCF_MINBUTTON;
234 if (lStyle & wxMAXIMIZE_BOX)
235 lMsflags |= FCF_MAXBUTTON;
236 if (lStyle & wxTHICK_FRAME)
237 lMsflags |= FCF_DLGBORDER;
238 if (lStyle & wxSYSTEM_MENU)
239 lMsflags |= FCF_SYSMENU;
240 if (lStyle & wxCAPTION)
241 lMsflags |= FCF_TASKLIST;
242 if (lStyle & wxCLIP_CHILDREN)
243 {
244 // Invalid for frame windows under PM
245 }
246
247 if (lStyle & wxTINY_CAPTION_VERT)
248 lMsflags |= FCF_TASKLIST;
249 if (lStyle & wxTINY_CAPTION_HORIZ)
250 lMsflags |= FCF_TASKLIST;
251
252 if ((lStyle & wxTHICK_FRAME) == 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( _T("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 m_backgroundColour.Set(wxString(wxT("LIGHT GREY")));
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 ::WinSetWindowPos( GetHwnd()
424 ,HWND_TOP
425 ,nX
426 ,nY
427 ,nWidth
428 ,nHeight
429 ,SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_SHOW | SWP_ACTIVATE
430 );
431 ::WinQueryWindowPos(GetHwnd(), GetSwp());
432 m_hFrame = m_hWnd;
433 SubclassWin(m_hWnd);
434 return true;
435 } // end of wxTopLevelWindowOS2::CreateDialog
436
437 bool wxTopLevelWindowOS2::CreateFrame( const wxString& rsTitle,
438 const wxPoint& rPos,
439 const wxSize& rSize )
440 {
441 WXDWORD lExflags;
442 WXDWORD lFlags = OS2GetCreateWindowFlags(&lExflags);
443 long lStyle = GetWindowStyleFlag();
444 int nX = rPos.x;
445 int nY = rPos.y;
446 int nWidth = rSize.x;
447 int nHeight = rSize.y;
448 ULONG ulStyleFlags = 0L;
449 ERRORID vError;
450 wxString sError;
451 wxWindow* pParent = GetParent();
452 HWND hParent;
453 HWND hFrame;
454 HWND hClient;
455
456 if (pParent)
457 hParent = GetHwndOf(pParent);
458 else
459 hParent = HWND_DESKTOP;
460
461 if ((lStyle & wxMINIMIZE) || (lStyle & wxICONIZE))
462 ulStyleFlags |= WS_MINIMIZED;
463 if (lStyle & wxMAXIMIZE)
464 ulStyleFlags |= WS_MAXIMIZED;
465
466 //
467 // Clear the visible flag, we always call show
468 //
469 ulStyleFlags &= (unsigned long)~WS_VISIBLE;
470 m_bIconized = false;
471
472 //
473 // Create the frame window: We break ranks with other ports now
474 // and instead of calling down into the base wxWindow class' OS2Create
475 // we do all our own stuff here. We will set the needed pieces
476 // of wxWindow manually, here.
477 //
478
479 hFrame = ::WinCreateStdWindow( hParent
480 ,ulStyleFlags // frame-window style
481 ,(PULONG)&lFlags // window style
482 ,(PSZ)wxFrameClassName // class name
483 ,(PSZ)rsTitle.c_str() // window title
484 ,0L // default client style
485 ,NULLHANDLE // resource in executable file
486 ,0 // resource id
487 ,&hClient // receives client window handle
488 );
489 if (!hFrame)
490 {
491 vError = ::WinGetLastError(vHabmain);
492 sError = wxPMErrorToStr(vError);
493 wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str());
494 return false;
495 }
496
497 //
498 // wxWindow class' m_hWnd set here and needed associations
499 //
500 m_hFrame = hFrame;
501 m_hWnd = hClient;
502 wxAssociateWinWithHandle(m_hWnd, this);
503 wxAssociateWinWithHandle(m_hFrame, this);
504
505 m_backgroundColour.Set(wxString(wxT("MEDIUM GREY")));
506
507 LONG lColor = (LONG)m_backgroundColour.GetPixel();
508
509 if (!::WinSetPresParam( m_hWnd
510 ,PP_BACKGROUNDCOLOR
511 ,sizeof(LONG)
512 ,(PVOID)&lColor
513 ))
514 {
515 vError = ::WinGetLastError(vHabmain);
516 sError = wxPMErrorToStr(vError);
517 wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str());
518 return false;
519 }
520
521 //
522 // Now need to subclass window. Instead of calling the SubClassWin in wxWindow
523 // we manually subclass here because we don't want to use the main wxWndProc
524 // by default
525 //
526 m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(m_hFrame, (PFNWP)wxFrameMainWndProc);
527
528 //
529 // Now size everything. If adding a menu the client will need to be resized.
530 //
531
532 if (pParent)
533 {
534 nY = pParent->GetSize().y - (nY + nHeight);
535 }
536 else
537 {
538 RECTL vRect;
539
540 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
541 nY = vRect.yTop - (nY + nHeight);
542 }
543 if (!::WinSetWindowPos( m_hFrame
544 ,HWND_TOP
545 ,nX
546 ,nY
547 ,nWidth
548 ,nHeight
549 ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_ZORDER
550 ))
551 {
552 vError = ::WinGetLastError(vHabmain);
553 sError = wxPMErrorToStr(vError);
554 wxLogError(_T("Error sizing frame. Error: %s\n"), sError.c_str());
555 return false;
556 }
557 lStyle = ::WinQueryWindowULong( m_hWnd
558 ,QWL_STYLE
559 );
560 lStyle |= WS_CLIPCHILDREN;
561 ::WinSetWindowULong( m_hWnd
562 ,QWL_STYLE
563 ,lStyle
564 );
565 return true;
566 } // end of wxTopLevelWindowOS2::CreateFrame
567
568 bool wxTopLevelWindowOS2::Create(
569 wxWindow* pParent
570 , wxWindowID vId
571 , const wxString& rsTitle
572 , const wxPoint& rPos
573 , const wxSize& rSizeOrig
574 , long lStyle
575 , const wxString& rsName
576 )
577 {
578 //
579 // Init our fields
580 //
581 Init();
582 m_windowStyle = lStyle;
583 SetName(rsName);
584 m_windowId = vId == -1 ? NewControlId() : vId;
585
586 // always create a frame of some reasonable, even if arbitrary, size (at
587 // least for MSW compatibility)
588 wxSize rSize = rSizeOrig;
589 if ( rSize.x == -1 || rSize.y == -1 )
590 {
591 wxSize sizeDpy = wxGetDisplaySize();
592 if ( rSize.x == -1 )
593 rSize.x = sizeDpy.x / 3;
594 if ( rSize.y == -1 )
595 rSize.y = sizeDpy.y / 5;
596 }
597
598 wxTopLevelWindows.Append(this);
599 if (pParent)
600 pParent->AddChild(this);
601
602 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
603 {
604 //
605 // We have different dialog templates to allow creation of dialogs
606 // with & without captions under OS2indows, resizeable or not (but a
607 // resizeable dialog always has caption - otherwise it would look too
608 // strange)
609 //
610 ULONG ulDlgTemplate;
611
612 if (lStyle & wxRESIZE_BORDER)
613 ulDlgTemplate = (ULONG)kResizeableDialog;
614 else if (lStyle & wxCAPTION)
615 ulDlgTemplate = (ULONG)kCaptionDialog;
616 else
617 ulDlgTemplate = (ULONG)kNoCaptionDialog;
618 return CreateDialog( ulDlgTemplate
619 ,rsTitle
620 ,rPos
621 ,rSize
622 );
623 }
624 else // !dialog
625 {
626 return CreateFrame( rsTitle
627 ,rPos
628 ,rSize
629 );
630 }
631 } // end of wxTopLevelWindowOS2::Create
632
633 wxTopLevelWindowOS2::~wxTopLevelWindowOS2()
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( bool bShow )
714 {
715 int nShowCmd;
716 SWP vSwp;
717
718 if (bShow != IsShown() )
719 {
720 m_isShown = bShow;
721 }
722 else
723 {
724 return false;
725 }
726 if (bShow)
727 {
728 if (m_bMaximizeOnShow)
729 {
730 nShowCmd = SWP_MAXIMIZE;
731 m_bMaximizeOnShow = false;
732 }
733 else
734 {
735 nShowCmd = SWP_SHOW;
736 }
737 }
738 else // hide
739 {
740 nShowCmd = SWP_HIDE;
741 }
742 DoShowWindow(nShowCmd);
743
744 if (bShow)
745 {
746 wxActivateEvent vEvent(wxEVT_ACTIVATE, true, m_windowId);
747
748 ::WinQueryWindowPos(m_hFrame, &vSwp);
749 m_bIconized = ( vSwp.fl & SWP_MINIMIZE ) == SWP_MINIMIZE ;
750 ::WinQueryWindowPos(m_hWnd, &m_vSwpClient);
751 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
752 ::WinQueryWindowPos(m_hWnd, &vSwp);
753 ::WinEnableWindow(m_hFrame, TRUE);
754
755 //
756 // Deal with children
757 //
758 MoveChildren(m_vSwpClient.cy - vSwp.cy);
759 vEvent.SetEventObject(this);
760 GetEventHandler()->ProcessEvent(vEvent);
761 }
762 else
763 {
764 //
765 // Try to highlight the correct window (the parent)
766 //
767 if (GetParent())
768 {
769 HWND hWndParent = GetHwndOf(GetParent());
770
771 ::WinQueryWindowPos(hWndParent, &vSwp);
772 m_bIconized = (vSwp.fl & SWP_MINIMIZE)==SWP_MINIMIZE;
773 ::WinEnableWindow(hWndParent, TRUE);
774 }
775 }
776 return true;
777 } // end of wxTopLevelWindowOS2::Show
778
779 // ----------------------------------------------------------------------------
780 // wxTopLevelWindowOS2 maximize/minimize
781 // ----------------------------------------------------------------------------
782
783 void wxTopLevelWindowOS2::Maximize(
784 bool bMaximize
785 )
786 {
787 if (IsShown())
788 {
789 //
790 // Just maximize it directly
791 //
792 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
793 }
794 else // hidden
795 {
796 //
797 // We can't maximize the hidden frame because it shows it as well, so
798 // just remember that we should do it later in this case
799 //
800 m_bMaximizeOnShow = bMaximize;
801 }
802 } // end of wxTopLevelWindowOS2::Maximize
803
804 bool wxTopLevelWindowOS2::IsMaximized() const
805 {
806 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
807 return (m_vSwp.fl & SWP_MAXIMIZE) == SWP_MAXIMIZE;
808 } // end of wxTopLevelWindowOS2::IsMaximized
809
810 void wxTopLevelWindowOS2::SetTitle( const wxString& title)
811 {
812 SetLabel(title);
813 }
814
815 wxString wxTopLevelWindowOS2::GetTitle() const
816 {
817 return GetLabel();
818 }
819
820 void wxTopLevelWindowOS2::Iconize( bool bIconize )
821 {
822 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
823 } // end of wxTopLevelWindowOS2::Iconize
824
825 bool wxTopLevelWindowOS2::IsIconized() const
826 {
827 // also update the current state
828 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
829 if (m_vSwp.fl & SWP_MINIMIZE)
830 ((wxTopLevelWindow*)this)->m_bIconized = true;
831 else
832 ((wxTopLevelWindow*)this)->m_bIconized = false;
833 return m_bIconized;
834 } // end of wxTopLevelWindowOS2::IsIconized
835
836 void wxTopLevelWindowOS2::Restore()
837 {
838 DoShowWindow(SWP_RESTORE);
839 } // end of wxTopLevelWindowOS2::Restore
840
841 // generate an artificial resize event
842 void wxTopLevelWindowOS2::SendSizeEvent()
843 {
844 if (!m_bIconized)
845 {
846 RECTL vRect = wxGetWindowRect(GetHwnd());
847
848 (void)::WinPostMsg( m_hFrame
849 ,WM_SIZE
850 ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
851 ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
852 );
853 }
854 } // end of wxTopLevelWindowOS2::SendSizeEvent
855
856 // ----------------------------------------------------------------------------
857 // wxTopLevelWindowOS2 fullscreen
858 // ----------------------------------------------------------------------------
859
860 bool wxTopLevelWindowOS2::ShowFullScreen( bool bShow,
861 long lStyle )
862 {
863 if (bShow)
864 {
865 if (IsFullScreen())
866 return false;
867
868 m_bFsIsShowing = true;
869 m_lFsStyle = lStyle;
870
871 //
872 // Zap the frame borders
873 //
874
875 //
876 // Save the 'normal' window lStyle
877 //
878 m_lFsOldWindowStyle = ::WinQueryWindowULong( (HWND)GetHWND()
879 ,QWL_STYLE
880 );
881
882 //
883 // Save the old position, width & height, maximize state
884 //
885 m_vFsOldSize = GetRect();
886 m_bFsIsMaximized = IsMaximized();
887
888 //
889 // Decide which window lStyle flags to turn off
890 //
891 LONG lNewStyle = m_lFsOldWindowStyle;
892 LONG lOffFlags = 0;
893
894 if (lStyle & wxFULLSCREEN_NOBORDER)
895 lOffFlags |= FCF_BORDER;
896 if (lStyle & wxFULLSCREEN_NOCAPTION)
897 lOffFlags |= (FCF_TASKLIST | FCF_SYSMENU);
898
899 lNewStyle &= (~lOffFlags);
900
901 //
902 // Change our window style to be compatible with full-screen mode
903 //
904 ::WinSetWindowULong( (HWND)GetHWND()
905 ,QWL_STYLE
906 ,lNewStyle
907 );
908
909 //
910 // Resize to the size of the desktop
911 //
912 int nWidth;
913 int nHeight;
914 RECTL vRect = wxGetWindowRect(HWND_DESKTOP);
915
916 nWidth = vRect.xRight - vRect.xLeft;
917 nHeight = vRect.yTop - vRect.yBottom;
918
919 SetSize( nWidth, nHeight );
920
921 //
922 // Now flush the window style cache and actually go full-screen
923 //
924 ::WinSetWindowPos( m_hFrame
925 ,HWND_TOP
926 ,0
927 ,0
928 ,nWidth
929 ,nHeight
930 ,SWP_SIZE | SWP_MOVE
931 );
932
933 wxSize full( nWidth, nHeight );
934 wxSizeEvent vEvent( full, GetId() );
935 GetEventHandler()->ProcessEvent(vEvent);
936 return true;
937 }
938 else
939 {
940 if (!IsFullScreen())
941 return false;
942
943 m_bFsIsShowing = false;
944 Maximize(m_bFsIsMaximized);
945 ::WinSetWindowULong( (HWND)GetHWND()
946 ,QWL_STYLE
947 ,m_lFsOldWindowStyle
948 );
949 ::WinSetWindowPos( m_hFrame
950 ,HWND_TOP
951 ,m_vFsOldSize.x
952 ,m_vFsOldSize.y
953 ,m_vFsOldSize.width
954 ,m_vFsOldSize.height
955 ,SWP_SIZE | SWP_MOVE
956 );
957 return true;
958 }
959 } // end of wxTopLevelWindowOS2::ShowFullScreen
960
961 // ----------------------------------------------------------------------------
962 // wxTopLevelWindowOS2 misc
963 // ----------------------------------------------------------------------------
964
965 void wxTopLevelWindowOS2::SetIcon(
966 const wxIcon& rIcon
967 )
968 {
969 SetIcons(wxIconBundle(rIcon));
970 } // end of wxTopLevelWindowOS2::SetIcon
971
972 void wxTopLevelWindowOS2::SetIcons(
973 const wxIconBundle& rIcons
974 )
975 {
976 //
977 // This sets m_icon
978 //
979 wxTopLevelWindowBase::SetIcons(rIcons);
980
981 const wxIcon& vIcon = rIcons.GetIcon(wxSize(32, 32));
982
983 if (vIcon.Ok() && vIcon.GetWidth() == 32 && vIcon.GetHeight() == 32)
984 {
985 ::WinSendMsg( m_hFrame
986 ,WM_SETICON
987 ,(MPARAM)((HPOINTER)vIcon.GetHICON())
988 ,NULL
989 );
990 ::WinSendMsg( m_hFrame
991 ,WM_UPDATEFRAME
992 ,(MPARAM)FCF_ICON
993 ,(MPARAM)0
994 );
995 }
996 } // end of wxTopLevelWindowOS2::SetIcon
997
998 bool wxTopLevelWindowOS2::EnableCloseButton( bool bEnable )
999 {
1000 //
1001 // Get system (a.k.a. window) menu
1002 //
1003 HMENU hMenu = ::WinWindowFromID(m_hFrame, FID_SYSMENU);
1004
1005 if (!hMenu)
1006 {
1007 wxLogLastError(_T("GetSystemMenu"));
1008 return false;
1009 }
1010
1011 //
1012 // Enabling/disabling the close item from it also automatically
1013 // disables/enables the close title bar button
1014 //
1015 if (bEnable)
1016 (void)::WinSendMsg( hMenu
1017 ,MM_SETITEMATTR
1018 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1019 ,MPFROM2SHORT(MIA_DISABLED, FALSE)
1020 );
1021 else
1022 (void)::WinSendMsg( hMenu
1023 ,MM_SETITEMATTR
1024 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1025 ,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
1026 );
1027
1028 //
1029 // Update appearance immediately
1030 //
1031 ::WinSendMsg( m_hFrame
1032 ,WM_UPDATEFRAME
1033 ,(MPARAM)FCF_MENU
1034 ,(MPARAM)0
1035 );
1036 return true;
1037 } // end of wxTopLevelWindowOS2::EnableCloseButton
1038
1039 // ============================================================================
1040 // wxTLWHiddenParentModule implementation
1041 // ============================================================================
1042
1043 HWND wxTLWHiddenParentModule::m_shWnd = NULL;
1044 const wxChar* wxTLWHiddenParentModule::m_szClassName = NULL;
1045
1046 bool wxTLWHiddenParentModule::OnInit()
1047 {
1048 m_shWnd = NULL;
1049 m_szClassName = NULL;
1050 return true;
1051 } // end of wxTLWHiddenParentModule::OnInit
1052
1053 void wxTLWHiddenParentModule::OnExit()
1054 {
1055 if (m_shWnd)
1056 {
1057 if (!::WinDestroyWindow(m_shWnd))
1058 {
1059 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1060 }
1061 m_shWnd = NULL;
1062 }
1063
1064 m_szClassName = NULL;
1065 } // end of wxTLWHiddenParentModule::OnExit
1066
1067 /* static */
1068 HWND wxTLWHiddenParentModule::GetHWND()
1069 {
1070 if (!m_shWnd)
1071 {
1072 if (!m_szClassName)
1073 {
1074 static const wxChar* zHIDDEN_PARENT_CLASS = _T("wxTLWHiddenParent");
1075
1076 if (!::WinRegisterClass( wxGetInstance()
1077 ,(PSZ)zHIDDEN_PARENT_CLASS
1078 ,NULL
1079 ,0
1080 ,sizeof(ULONG)
1081 ))
1082 {
1083 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1084 }
1085 else
1086 {
1087 m_szClassName = zHIDDEN_PARENT_CLASS;
1088 }
1089 }
1090 m_shWnd = ::WinCreateWindow( HWND_DESKTOP,
1091 (PSZ)m_szClassName,
1092 "",
1093 0L,
1094 (LONG)0L,
1095 (LONG)0L,
1096 (LONG)0L,
1097 (LONG)0L,
1098 NULLHANDLE,
1099 HWND_TOP,
1100 0L,
1101 NULL,
1102 NULL );
1103 if (!m_shWnd)
1104 {
1105 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));
1106 }
1107 }
1108 return m_shWnd;
1109 } // end of wxTLWHiddenParentModule::GetHWND