]> git.saurik.com Git - wxWidgets.git/blob - src/os2/toplevel.cpp
set error to GSOCK_TIMEOUT if the socket timed out (modified and extended patch 1303554)
[wxWidgets.git] / src / os2 / toplevel.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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
53 ,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 m_backgroundColour.Set(wxString(wxT("LIGHT GREY")));
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(
439 const wxString& rsTitle
440 , const wxPoint& rPos
441 , const wxSize& rSize
442 )
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 ,(PSZ)wxFrameClassName // class name
486 ,(PSZ)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(_T("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 m_backgroundColour.Set(wxString(wxT("MEDIUM GREY")));
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(_T("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 (pParent)
536 {
537 nY = pParent->GetSize().y - (nY + nHeight);
538 }
539 else
540 {
541 RECTL vRect;
542
543 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
544 nY = vRect.yTop - (nY + nHeight);
545 }
546 if (!::WinSetWindowPos( m_hFrame
547 ,HWND_TOP
548 ,nX
549 ,nY
550 ,nWidth
551 ,nHeight
552 ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_ZORDER
553 ))
554 {
555 vError = ::WinGetLastError(vHabmain);
556 sError = wxPMErrorToStr(vError);
557 wxLogError(_T("Error sizing frame. Error: %s\n"), sError.c_str());
558 return FALSE;
559 }
560 lStyle = ::WinQueryWindowULong( m_hWnd
561 ,QWL_STYLE
562 );
563 lStyle |= WS_CLIPCHILDREN;
564 ::WinSetWindowULong( m_hWnd
565 ,QWL_STYLE
566 ,lStyle
567 );
568 return TRUE;
569 } // end of wxTopLevelWindowOS2::CreateFrame
570
571 bool wxTopLevelWindowOS2::Create(
572 wxWindow* pParent
573 , wxWindowID vId
574 , const wxString& rsTitle
575 , const wxPoint& rPos
576 , const wxSize& rSizeOrig
577 , long lStyle
578 , const wxString& rsName
579 )
580 {
581 //
582 // Init our fields
583 //
584 Init();
585 m_windowStyle = lStyle;
586 SetName(rsName);
587 m_windowId = vId == -1 ? NewControlId() : vId;
588
589 // always create a frame of some reasonable, even if arbitrary, size (at
590 // least for MSW compatibility)
591 wxSize rSize = rSizeOrig;
592 if ( rSize.x == -1 || rSize.y == -1 )
593 {
594 wxSize sizeDpy = wxGetDisplaySize();
595 if ( rSize.x == -1 )
596 rSize.x = sizeDpy.x / 3;
597 if ( rSize.y == -1 )
598 rSize.y = sizeDpy.y / 5;
599 }
600
601 wxTopLevelWindows.Append(this);
602 if (pParent)
603 pParent->AddChild(this);
604
605 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
606 {
607 //
608 // We have different dialog templates to allows creation of dialogs
609 // with & without captions under OS2indows, resizeable or not (but a
610 // resizeable dialog always has caption - otherwise it would look too
611 // strange)
612 //
613 ULONG ulDlgTemplate;
614
615 if (lStyle & wxRESIZE_BORDER)
616 ulDlgTemplate = (ULONG)kResizeableDialog;
617 else if (lStyle & wxCAPTION)
618 ulDlgTemplate = (ULONG)kCaptionDialog;
619 else
620 ulDlgTemplate = (ULONG)kNoCaptionDialog;
621 return CreateDialog( ulDlgTemplate
622 ,rsTitle
623 ,rPos
624 ,rSize
625 );
626 }
627 else // !dialog
628 {
629 return CreateFrame( rsTitle
630 ,rPos
631 ,rSize
632 );
633 }
634 } // end of wxTopLevelWindowOS2::Create
635
636 wxTopLevelWindowOS2::~wxTopLevelWindowOS2()
637 {
638 //
639 // After destroying an owned window, Windows activates the next top level
640 // window in Z order but it may be different from our owner (to reproduce
641 // this simply Alt-TAB to another application and back before closing the
642 // owned frame) whereas we always want to yield activation to our parent
643 //
644 if (HasFlag(wxFRAME_FLOAT_ON_PARENT))
645 {
646 wxWindow* pParent = GetParent();
647
648 if (pParent)
649 {
650 ::WinSetWindowPos( GetHwndOf(pParent)
651 ,HWND_TOP
652 ,0, 0, 0, 0
653 ,SWP_ZORDER
654 );
655 }
656 }
657 } // end of wxTopLevelWindowOS2::~wxTopLevelWindowOS2
658
659 // ----------------------------------------------------------------------------
660 // wxTopLevelWindowOS2 client size
661 // ----------------------------------------------------------------------------
662
663 void wxTopLevelWindowOS2::DoSetClientSize(
664 int nWidth
665 , int nHeight
666 )
667 {
668 //
669 // Call GetClientAreaOrigin() to take the toolbar into account
670 //
671 wxPoint vPt = GetClientAreaOrigin();
672
673 nWidth += vPt.x;
674 nHeight += vPt.y;
675
676 wxWindow::DoSetClientSize( nWidth
677 ,nHeight
678 );
679 } // end of wxTopLevelWindowOS2::DoSetClientSize
680
681 void wxTopLevelWindowOS2::DoGetClientSize(
682 int* pnX
683 , int* pnY
684 ) const
685 {
686 wxWindow::DoGetClientSize( pnX
687 ,pnY
688 );
689
690 wxPoint vPt = GetClientAreaOrigin();
691
692 if (pnX)
693 *pnX -= vPt.x;
694
695 if (pnY)
696 *pnY += vPt.y;
697 } // end of wxTopLevelWindowOS2::DoGetClientSize
698
699 // ----------------------------------------------------------------------------
700 // wxTopLevelWindowOS2 showing
701 // ----------------------------------------------------------------------------
702
703 void wxTopLevelWindowOS2::DoShowWindow(
704 int nShowCmd
705 )
706 {
707 ::WinShowWindow(m_hFrame, (BOOL)(nShowCmd & SWP_SHOW));
708
709 //
710 // Need to artificially send a size event as wxApps often expect to do some
711 // final child control sizing
712 SendSizeEvent();
713 m_bIconized = nShowCmd == SWP_MINIMIZE;
714 } // end of wxTopLevelWindowOS2::DoShowWindow
715
716 bool wxTopLevelWindowOS2::Show(
717 bool bShow
718 )
719 {
720 int nShowCmd;
721 SWP vSwp;
722
723 if (bShow != IsShown() )
724 {
725 m_isShown = bShow;
726 }
727 else
728 {
729 return FALSE;
730 }
731 if (bShow)
732 {
733 if (m_bMaximizeOnShow)
734 {
735 nShowCmd = SWP_MAXIMIZE;
736 m_bMaximizeOnShow = FALSE;
737 }
738 else
739 {
740 nShowCmd = SWP_SHOW;
741 }
742 }
743 else // hide
744 {
745 nShowCmd = SWP_HIDE;
746 }
747 DoShowWindow(nShowCmd);
748
749 if (bShow)
750 {
751 wxActivateEvent vEvent(wxEVT_ACTIVATE, TRUE, m_windowId);
752
753 ::WinQueryWindowPos(m_hFrame, &vSwp);
754 m_bIconized = ( vSwp.fl & SWP_MINIMIZE ) == SWP_MINIMIZE ;
755 ::WinQueryWindowPos(m_hWnd, &m_vSwpClient);
756 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
757 ::WinQueryWindowPos(m_hWnd, &vSwp);
758 ::WinEnableWindow(m_hFrame, TRUE);
759
760 //
761 // Deal with children
762 //
763 MoveChildren(m_vSwpClient.cy - vSwp.cy);
764 vEvent.SetEventObject(this);
765 GetEventHandler()->ProcessEvent(vEvent);
766 }
767 else
768 {
769 //
770 // Try to highlight the correct window (the parent)
771 //
772 if (GetParent())
773 {
774 HWND hWndParent = GetHwndOf(GetParent());
775
776 ::WinQueryWindowPos(hWndParent, &vSwp);
777 m_bIconized = (vSwp.fl & SWP_MINIMIZE)==SWP_MINIMIZE;
778 ::WinEnableWindow(hWndParent, TRUE);
779 }
780 }
781 return TRUE;
782 } // end of wxTopLevelWindowOS2::Show
783
784 // ----------------------------------------------------------------------------
785 // wxTopLevelWindowOS2 maximize/minimize
786 // ----------------------------------------------------------------------------
787
788 void wxTopLevelWindowOS2::Maximize(
789 bool bMaximize
790 )
791 {
792 if (IsShown())
793 {
794 //
795 // Just maximize it directly
796 //
797 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
798 }
799 else // hidden
800 {
801 //
802 // We can't maximize the hidden frame because it shows it as well, so
803 // just remember that we should do it later in this case
804 //
805 m_bMaximizeOnShow = bMaximize;
806 }
807 } // end of wxTopLevelWindowOS2::Maximize
808
809 bool wxTopLevelWindowOS2::IsMaximized() const
810 {
811 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
812 return (m_vSwp.fl & SWP_MAXIMIZE) == 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( bool bShow,
858 long lStyle )
859 {
860 if (bShow)
861 {
862 if (IsFullScreen())
863 return false;
864
865 m_bFsIsShowing = true;
866 m_lFsStyle = lStyle;
867
868 //
869 // Zap the frame borders
870 //
871
872 //
873 // Save the 'normal' window lStyle
874 //
875 m_lFsOldWindowStyle = ::WinQueryWindowULong( (HWND)GetHWND()
876 ,QWL_STYLE
877 );
878
879 //
880 // Save the old position, width & height, maximize state
881 //
882 m_vFsOldSize = GetRect();
883 m_bFsIsMaximized = IsMaximized();
884
885 //
886 // Decide which window lStyle flags to turn off
887 //
888 LONG lNewStyle = m_lFsOldWindowStyle;
889 LONG lOffFlags = 0;
890
891 if (lStyle & wxFULLSCREEN_NOBORDER)
892 lOffFlags |= FCF_BORDER;
893 if (lStyle & wxFULLSCREEN_NOCAPTION)
894 lOffFlags |= (FCF_TASKLIST | FCF_SYSMENU);
895
896 lNewStyle &= (~lOffFlags);
897
898 //
899 // Change our window style to be compatible with full-screen mode
900 //
901 ::WinSetWindowULong( (HWND)GetHWND()
902 ,QWL_STYLE
903 ,lNewStyle
904 );
905
906 //
907 // Resize to the size of the desktop
908 //
909 int nWidth;
910 int nHeight;
911 RECTL vRect = wxGetWindowRect(HWND_DESKTOP);
912
913 nWidth = vRect.xRight - vRect.xLeft;
914 nHeight = vRect.yTop - vRect.yBottom;
915
916 SetSize( nWidth, nHeight );
917
918 //
919 // Now flush the window style cache and actually go full-screen
920 //
921 ::WinSetWindowPos( m_hFrame
922 ,HWND_TOP
923 ,0
924 ,0
925 ,nWidth
926 ,nHeight
927 ,SWP_SIZE | SWP_MOVE
928 );
929
930 wxSize full( nWidth, nHeight );
931 wxSizeEvent vEvent( full, GetId() );
932 GetEventHandler()->ProcessEvent(vEvent);
933 return true;
934 }
935 else
936 {
937 if (!IsFullScreen())
938 return false;
939
940 m_bFsIsShowing = false;
941 Maximize(m_bFsIsMaximized);
942 ::WinSetWindowULong( (HWND)GetHWND()
943 ,QWL_STYLE
944 ,m_lFsOldWindowStyle
945 );
946 ::WinSetWindowPos( m_hFrame
947 ,HWND_TOP
948 ,m_vFsOldSize.x
949 ,m_vFsOldSize.y
950 ,m_vFsOldSize.width
951 ,m_vFsOldSize.height
952 ,SWP_SIZE | SWP_MOVE
953 );
954 return true;
955 }
956 } // end of wxTopLevelWindowOS2::ShowFullScreen
957
958 // ----------------------------------------------------------------------------
959 // wxTopLevelWindowOS2 misc
960 // ----------------------------------------------------------------------------
961
962 void wxTopLevelWindowOS2::SetIcon(
963 const wxIcon& rIcon
964 )
965 {
966 SetIcons(wxIconBundle(rIcon));
967 } // end of wxTopLevelWindowOS2::SetIcon
968
969 void wxTopLevelWindowOS2::SetIcons(
970 const wxIconBundle& rIcons
971 )
972 {
973 //
974 // This sets m_icon
975 //
976 wxTopLevelWindowBase::SetIcons(rIcons);
977
978 const wxIcon& vIcon = rIcons.GetIcon(wxSize(32, 32));
979
980 if (vIcon.Ok() && vIcon.GetWidth() == 32 && vIcon.GetHeight() == 32)
981 {
982 ::WinSendMsg( m_hFrame
983 ,WM_SETICON
984 ,(MPARAM)((HPOINTER)vIcon.GetHICON())
985 ,NULL
986 );
987 ::WinSendMsg( m_hFrame
988 ,WM_UPDATEFRAME
989 ,(MPARAM)FCF_ICON
990 ,(MPARAM)0
991 );
992 }
993 } // end of wxTopLevelWindowOS2::SetIcon
994
995 bool wxTopLevelWindowOS2::EnableCloseButton(
996 bool bEnable
997 )
998 {
999 //
1000 // Get system (a.k.a. window) menu
1001 //
1002 HMENU hMenu = ::WinWindowFromID(m_hFrame, FID_SYSMENU);
1003
1004 if (!hMenu)
1005 {
1006 wxLogLastError(_T("GetSystemMenu"));
1007 return FALSE;
1008 }
1009
1010 //
1011 // Enabling/disabling the close item from it also automatically
1012 // disables/enables the close title bar button
1013 //
1014 if (bEnable)
1015 (void)::WinSendMsg( hMenu
1016 ,MM_SETITEMATTR
1017 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1018 ,MPFROM2SHORT(MIA_DISABLED, FALSE)
1019 );
1020 else
1021 (void)::WinSendMsg( hMenu
1022 ,MM_SETITEMATTR
1023 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1024 ,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
1025 );
1026
1027 //
1028 // Update appearance immediately
1029 //
1030 ::WinSendMsg( m_hFrame
1031 ,WM_UPDATEFRAME
1032 ,(MPARAM)FCF_MENU
1033 ,(MPARAM)0
1034 );
1035 return TRUE;
1036 } // end of wxTopLevelWindowOS2::EnableCloseButton
1037
1038 // ============================================================================
1039 // wxTLWHiddenParentModule implementation
1040 // ============================================================================
1041
1042 HWND wxTLWHiddenParentModule::m_shWnd = NULL;
1043 const wxChar* wxTLWHiddenParentModule::m_szClassName = NULL;
1044
1045 bool wxTLWHiddenParentModule::OnInit()
1046 {
1047 m_shWnd = NULL;
1048 m_szClassName = NULL;
1049 return TRUE;
1050 } // end of wxTLWHiddenParentModule::OnInit
1051
1052 void wxTLWHiddenParentModule::OnExit()
1053 {
1054 if (m_shWnd)
1055 {
1056 if (!::WinDestroyWindow(m_shWnd))
1057 {
1058 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1059 }
1060 m_shWnd = NULL;
1061 }
1062
1063 m_szClassName = NULL;
1064 } // end of wxTLWHiddenParentModule::OnExit
1065
1066 /* static */
1067 HWND wxTLWHiddenParentModule::GetHWND()
1068 {
1069 if (!m_shWnd)
1070 {
1071 if (!m_szClassName)
1072 {
1073 static const wxChar* zHIDDEN_PARENT_CLASS = _T("wxTLWHiddenParent");
1074
1075 if (!::WinRegisterClass( wxGetInstance()
1076 ,(PSZ)zHIDDEN_PARENT_CLASS
1077 ,NULL
1078 ,0
1079 ,sizeof(ULONG)
1080 ))
1081 {
1082 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1083 }
1084 else
1085 {
1086 m_szClassName = zHIDDEN_PARENT_CLASS;
1087 }
1088 }
1089 m_shWnd = ::WinCreateWindow( HWND_DESKTOP
1090 ,(PSZ)m_szClassName
1091 ,""
1092 ,0L
1093 ,(LONG)0L
1094 ,(LONG)0L
1095 ,(LONG)0L
1096 ,(LONG)0L
1097 ,NULLHANDLE
1098 ,HWND_TOP
1099 ,0L
1100 ,NULL
1101 ,NULL
1102 );
1103 if (!m_shWnd)
1104 {
1105 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));
1106 }
1107 }
1108 return m_shWnd;
1109 } // end of wxTLWHiddenParentModule::GetHWND