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