]> git.saurik.com Git - wxWidgets.git/blame - src/os2/toplevel.cpp
Typo, should be #if not #ifdef
[wxWidgets.git] / src / os2 / toplevel.cpp
CommitLineData
f45e4fad 1///////////////////////////////////////////////////////////////////////////////
76d81b4d
SN
2// Name: os2/toplevel.cpp
3// Purpose: implements wxTopLevelWindow for OS/2
f45e4fad
DW
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)
65571936 9// License: wxWindows licence
f45e4fad
DW
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
f45e4fad
DW
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"
7b048ef6 30 #include "wx/dialog.h"
f45e4fad
DW
31 #include "wx/string.h"
32 #include "wx/log.h"
33 #include "wx/intl.h"
34 #include "wx/frame.h"
a4a16252 35 #include "wx/control.h"
272ebf16 36 #include "wx/containr.h" // wxSetFocusToChild()
f45e4fad
DW
37#endif //WX_PRECOMP
38
542e68c7 39#include "wx/module.h" // wxSetFocusToChild()
f45e4fad
DW
40#include "wx/os2/private.h"
41
42// ----------------------------------------------------------------------------
43// stubs for missing functions under MicroWindows
44// ----------------------------------------------------------------------------
45
46
47// ----------------------------------------------------------------------------
48// globals
49// ----------------------------------------------------------------------------
50
77ffb593 51// the name of the default wxWidgets class
793c7f9b
DW
52extern void wxAssociateWinWithHandle( HWND hWnd
53 ,wxWindowOS2* pWin
54 );
45e0dc94 55bool wxTopLevelWindowOS2::m_sbInitialized = FALSE;
6ed98c6a 56wxWindow* wxTopLevelWindowOS2::m_spHiddenParent = NULL;
f45e4fad 57
47df2b8c
DW
58// ============================================================================
59// wxTopLevelWindowOS2 implementation
60// ============================================================================
61
62BEGIN_EVENT_TABLE(wxTopLevelWindowOS2, wxTopLevelWindowBase)
63 EVT_ACTIVATE(wxTopLevelWindowOS2::OnActivate)
64END_EVENT_TABLE()
65
f45e4fad
DW
66// ============================================================================
67// wxTopLevelWindowMSW implementation
68// ============================================================================
69
70// Dialog window proc
71MRESULT EXPENTRY wxDlgProc( HWND WXUNUSED(hWnd)
72 ,UINT uMessage
9923c37d
DW
73 ,void * WXUNUSED(wParam)
74 ,void * WXUNUSED(lParam)
f45e4fad
DW
75 )
76{
47df2b8c 77 switch(uMessage)
f45e4fad 78 {
47df2b8c
DW
79 case WM_INITDLG:
80 //
81 // For this message, returning TRUE tells system to set focus to
0256cfeb
DW
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
47df2b8c 84 //
0256cfeb 85 return (MRESULT)TRUE;
47df2b8c
DW
86 default:
87 //
88 // For all the other ones, FALSE means that we didn't process the
89 // message
90 //
91 return (MRESULT)FALSE;
f45e4fad
DW
92 }
93} // end of wxDlgProc
94
376ef4a1
DW
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
100class wxTLWHiddenParentModule : public wxModule
101{
102public:
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
114private:
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
127IMPLEMENT_DYNAMIC_CLASS(wxTLWHiddenParentModule, wxModule)
128
f45e4fad
DW
129// ----------------------------------------------------------------------------
130// wxTopLevelWindowOS2 creation
131// ----------------------------------------------------------------------------
132
133void 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));
47df2b8c 152 m_pWinLastFocused = (wxWindow *)NULL;
f45e4fad
DW
153} // end of wxTopLevelWindowIOS2::Init
154
47df2b8c
DW
155void wxTopLevelWindowOS2::OnActivate(
156 wxActivateEvent& rEvent
157)
158{
159 if (rEvent.GetActive())
160 {
161 //
162 // Restore focus to the child which was last focused
163 //
9923c37d 164 wxLogTrace(_T("focus"), _T("wxTLW %08lx activated."), m_hWnd);
47df2b8c
DW
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"),
9923c37d 203 _T("wxTLW %08lx deactivated, last focused: %08lx."),
47df2b8c
DW
204 m_hWnd,
205 m_pWinLastFocused ? GetHwndOf(m_pWinLastFocused)
206 : NULL);
207 rEvent.Skip();
208 }
209} // end of wxTopLevelWindowOS2::OnActivate
210
b9b1d6c8
DW
211WXDWORD wxTopLevelWindowOS2::OS2GetStyle(
212 long lStyle
213, WXDWORD* pdwExflags
f45e4fad
DW
214) const
215{
b9b1d6c8
DW
216 long lMsflags = wxWindow::OS2GetStyle( (lStyle & ~wxBORDER_MASK) | wxBORDER_NONE
217 ,pdwExflags
218 );
f45e4fad 219
76d81b4d 220 if ((lStyle & wxDEFAULT_FRAME_STYLE) == wxDEFAULT_FRAME_STYLE)
b9b1d6c8
DW
221 lMsflags |= FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU |
222 FCF_MINMAX | FCF_TASKLIST;
76d81b4d
SN
223
224 if ((lStyle & wxCAPTION) == wxCAPTION)
225 lMsflags |= FCF_TASKLIST;
f45e4fad 226 else
76d81b4d
SN
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)
f45e4fad 244 {
76d81b4d
SN
245 // Invalid for frame windows under PM
246 }
f45e4fad 247
76d81b4d
SN
248 if (lStyle & wxTINY_CAPTION_VERT)
249 lMsflags |= FCF_TASKLIST;
250 if (lStyle & wxTINY_CAPTION_HORIZ)
251 lMsflags |= FCF_TASKLIST;
f45e4fad 252
76d81b4d
SN
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;
f45e4fad 260
f45e4fad
DW
261 return lMsflags;
262} // end of wxTopLevelWindowOS2::OS2GetCreateWindowFlags
263
6ed98c6a
DW
264WXHWND wxTopLevelWindowOS2::OS2GetParent() const
265{
376ef4a1
DW
266 HWND hWndParent = NULL;
267
6ed98c6a
DW
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 //
6ed98c6a
DW
274 if (HasFlag(wxFRAME_FLOAT_ON_PARENT) )
275 {
376ef4a1 276 const wxWindow* pParent = GetParent();
6ed98c6a 277
376ef4a1 278 if (!pParent)
6ed98c6a 279 {
6ed98c6a 280 //
376ef4a1 281 // This flag doesn't make sense then and will be ignored
6ed98c6a 282 //
376ef4a1 283 wxFAIL_MSG( _T("wxFRAME_FLOAT_ON_PARENT but no parent?") );
6ed98c6a 284 }
376ef4a1
DW
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();
6ed98c6a 302 }
376ef4a1 303 return (WXHWND)hWndParent;
6ed98c6a
DW
304} // end of wxTopLevelWindowOS2::OS2GetParent
305
6670f564
WS
306
307bool wxTopLevelWindowOS2::CreateDialog( ULONG ulDlgTemplate,
308 const wxString& WXUNUSED(rsTitle),
309 const wxPoint& rPos,
310 const wxSize& rSize )
f45e4fad
DW
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;
1b086de1 340 HWND hWndOwner;
f45e4fad
DW
341
342 if (pParent)
1b086de1 343 hWndOwner = GetHwndOf(pParent);
f45e4fad 344 else
1b086de1 345 hWndOwner = HWND_DESKTOP;
f45e4fad 346
1b086de1
DW
347 hWndDlg = ::WinLoadDlg( HWND_DESKTOP
348 ,hWndOwner
f45e4fad
DW
349 ,(PFNWP)wxDlgProc
350 ,NULL
351 ,(ULONG)ulDlgTemplate
352 ,(PVOID)this
353 );
354
355 m_hWnd = (WXHWND) hWndDlg;
356
357 if ( !m_hWnd )
358 {
7e99eddf 359 wxFAIL_MSG(wxT("Did you forget to include wx/os2/wx.rc in your resources?"));
f45e4fad 360
9923c37d 361 wxLogSysError(wxT("Can't create dialog using template '%ld'"), ulDlgTemplate);
f45e4fad
DW
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 }
0fba44b4 411 m_backgroundColour.Set(wxString(wxT("LIGHT GREY")));
626af800
DW
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 }
b3260bce 423
f45e4fad
DW
424 ::WinSetWindowPos( GetHwnd()
425 ,HWND_TOP
426 ,nX
427 ,nY
428 ,nWidth
429 ,nHeight
0256cfeb 430 ,SWP_MOVE | SWP_SIZE | SWP_ZORDER | SWP_SHOW | SWP_ACTIVATE
f45e4fad 431 );
859e65de 432 ::WinQueryWindowPos(GetHwnd(), GetSwp());
626af800 433 m_hFrame = m_hWnd;
f45e4fad
DW
434 SubclassWin(m_hWnd);
435 return TRUE;
436} // end of wxTopLevelWindowOS2::CreateDialog
437
438bool wxTopLevelWindowOS2::CreateFrame(
439 const wxString& rsTitle
440, const wxPoint& rPos
441, const wxSize& rSize
442)
443{
b9b1d6c8
DW
444 WXDWORD lExflags;
445 WXDWORD lFlags = OS2GetCreateWindowFlags(&lExflags);
f45e4fad
DW
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);
0fba44b4 496 wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str());
f45e4fad
DW
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
0fba44b4 508 m_backgroundColour.Set(wxString(wxT("MEDIUM GREY")));
f45e4fad
DW
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);
0fba44b4 520 wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str());
f45e4fad
DW
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);
0fba44b4 557 wxLogError(_T("Error sizing frame. Error: %s\n"), sError.c_str());
f45e4fad
DW
558 return FALSE;
559 }
54ffa107
DW
560 lStyle = ::WinQueryWindowULong( m_hWnd
561 ,QWL_STYLE
562 );
563 lStyle |= WS_CLIPCHILDREN;
564 ::WinSetWindowULong( m_hWnd
565 ,QWL_STYLE
566 ,lStyle
567 );
f45e4fad
DW
568 return TRUE;
569} // end of wxTopLevelWindowOS2::CreateFrame
570
571bool wxTopLevelWindowOS2::Create(
572 wxWindow* pParent
573, wxWindowID vId
574, const wxString& rsTitle
575, const wxPoint& rPos
2d28c41c 576, const wxSize& rSizeOrig
f45e4fad
DW
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;
2d28c41c
SN
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
f45e4fad
DW
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
636wxTopLevelWindowOS2::~wxTopLevelWindowOS2()
637{
f45e4fad 638 //
a23692f0
DW
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 }
f45e4fad
DW
657} // end of wxTopLevelWindowOS2::~wxTopLevelWindowOS2
658
f45e4fad
DW
659// ----------------------------------------------------------------------------
660// wxTopLevelWindowOS2 client size
661// ----------------------------------------------------------------------------
662
663void 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
681void 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
703void wxTopLevelWindowOS2::DoShowWindow(
704 int nShowCmd
705)
706{
54ffa107 707 ::WinShowWindow(m_hFrame, (BOOL)(nShowCmd & SWP_SHOW));
239c2e96
DW
708
709 //
710 // Need to artificially send a size event as wxApps often expect to do some
711 // final child control sizing
712 SendSizeEvent();
f45e4fad
DW
713 m_bIconized = nShowCmd == SWP_MINIMIZE;
714} // end of wxTopLevelWindowOS2::DoShowWindow
715
716bool wxTopLevelWindowOS2::Show(
717 bool bShow
718)
719{
720 int nShowCmd;
721 SWP vSwp;
f45e4fad 722
376ef4a1
DW
723 if (bShow != IsShown() )
724 {
725 m_isShown = bShow;
726 }
727 else
728 {
729 return FALSE;
730 }
f45e4fad
DW
731 if (bShow)
732 {
733 if (m_bMaximizeOnShow)
734 {
54ffa107 735 nShowCmd = SWP_MAXIMIZE;
f45e4fad
DW
736 m_bMaximizeOnShow = FALSE;
737 }
738 else
739 {
54ffa107 740 nShowCmd = SWP_SHOW;
f45e4fad
DW
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);
6670f564 754 m_bIconized = ( vSwp.fl & SWP_MINIMIZE ) == SWP_MINIMIZE ;
f45e4fad
DW
755 ::WinQueryWindowPos(m_hWnd, &m_vSwpClient);
756 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
4a46a5df 757 ::WinQueryWindowPos(m_hWnd, &vSwp);
f45e4fad 758 ::WinEnableWindow(m_hFrame, TRUE);
859e65de
DW
759
760 //
761 // Deal with children
762 //
763 MoveChildren(m_vSwpClient.cy - vSwp.cy);
f45e4fad
DW
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);
6670f564 777 m_bIconized = (vSwp.fl & SWP_MINIMIZE)==SWP_MINIMIZE;
f45e4fad
DW
778 ::WinEnableWindow(hWndParent, TRUE);
779 }
780 }
781 return TRUE;
782} // end of wxTopLevelWindowOS2::Show
783
784// ----------------------------------------------------------------------------
785// wxTopLevelWindowOS2 maximize/minimize
786// ----------------------------------------------------------------------------
787
788void 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 //
6e348b12 805 m_bMaximizeOnShow = bMaximize;
f45e4fad
DW
806 }
807} // end of wxTopLevelWindowOS2::Maximize
808
809bool wxTopLevelWindowOS2::IsMaximized() const
810{
f45e4fad 811 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
6670f564 812 return (m_vSwp.fl & SWP_MAXIMIZE) == SWP_MAXIMIZE;
f45e4fad
DW
813} // end of wxTopLevelWindowOS2::IsMaximized
814
815void wxTopLevelWindowOS2::Iconize(
816 bool bIconize
817)
818{
819 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
820} // end of wxTopLevelWindowOS2::Iconize
821
822bool 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
833void wxTopLevelWindowOS2::Restore()
834{
835 DoShowWindow(SWP_RESTORE);
836} // end of wxTopLevelWindowOS2::Restore
837
239c2e96
DW
838// generate an artificial resize event
839void 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
f45e4fad
DW
853// ----------------------------------------------------------------------------
854// wxTopLevelWindowOS2 fullscreen
855// ----------------------------------------------------------------------------
856
6670f564
WS
857bool wxTopLevelWindowOS2::ShowFullScreen( bool bShow,
858 long lStyle )
f45e4fad
DW
859{
860 if (bShow)
861 {
862 if (IsFullScreen())
6670f564 863 return false;
f45e4fad 864
6670f564 865 m_bFsIsShowing = true;
f45e4fad
DW
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 //
6670f564
WS
888 LONG lNewStyle = m_lFsOldWindowStyle;
889 LONG lOffFlags = 0;
f45e4fad
DW
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 //
6670f564
WS
909 int nWidth;
910 int nHeight;
911 RECTL vRect = wxGetWindowRect(HWND_DESKTOP);
f45e4fad
DW
912
913 nWidth = vRect.xRight - vRect.xLeft;
914 nHeight = vRect.yTop - vRect.yBottom;
915
6670f564 916 SetSize( nWidth, nHeight );
f45e4fad
DW
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
6670f564
WS
930 wxSize full( nWidth, nHeight );
931 wxSizeEvent vEvent( full, GetId() );
f45e4fad 932 GetEventHandler()->ProcessEvent(vEvent);
6670f564 933 return true;
f45e4fad
DW
934 }
935 else
936 {
937 if (!IsFullScreen())
6670f564 938 return false;
f45e4fad 939
6670f564 940 m_bFsIsShowing = false;
f45e4fad
DW
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 );
6670f564 954 return true;
f45e4fad
DW
955 }
956} // end of wxTopLevelWindowOS2::ShowFullScreen
957
958// ----------------------------------------------------------------------------
959// wxTopLevelWindowOS2 misc
960// ----------------------------------------------------------------------------
961
962void wxTopLevelWindowOS2::SetIcon(
963 const wxIcon& rIcon
964)
3437f881
DW
965{
966 SetIcons(wxIconBundle(rIcon));
967} // end of wxTopLevelWindowOS2::SetIcon
968
969void wxTopLevelWindowOS2::SetIcons(
970 const wxIconBundle& rIcons
971)
f45e4fad
DW
972{
973 //
974 // This sets m_icon
975 //
3437f881
DW
976 wxTopLevelWindowBase::SetIcons(rIcons);
977
978 const wxIcon& vIcon = rIcons.GetIcon(wxSize(32, 32));
f45e4fad 979
3437f881 980 if (vIcon.Ok() && vIcon.GetWidth() == 32 && vIcon.GetHeight() == 32)
f45e4fad
DW
981 {
982 ::WinSendMsg( m_hFrame
983 ,WM_SETICON
3437f881 984 ,(MPARAM)((HPOINTER)vIcon.GetHICON())
f45e4fad
DW
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
995bool 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
376ef4a1
DW
1038// ============================================================================
1039// wxTLWHiddenParentModule implementation
1040// ============================================================================
1041
1042HWND wxTLWHiddenParentModule::m_shWnd = NULL;
1043const wxChar* wxTLWHiddenParentModule::m_szClassName = NULL;
1044
1045bool wxTLWHiddenParentModule::OnInit()
1046{
1047 m_shWnd = NULL;
1048 m_szClassName = NULL;
1049 return TRUE;
1050} // end of wxTLWHiddenParentModule::OnInit
1051
1052void 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 */
1067HWND 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()
0fba44b4 1076 ,(PSZ)zHIDDEN_PARENT_CLASS
376ef4a1
DW
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
0fba44b4 1090 ,(PSZ)m_szClassName
376ef4a1
DW
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