]> git.saurik.com Git - wxWidgets.git/blame - src/os2/toplevel.cpp
Minor cleanup
[wxWidgets.git] / src / os2 / toplevel.cpp
CommitLineData
f45e4fad 1///////////////////////////////////////////////////////////////////////////////
743e24aa 2// Name: src/os2/toplevel.cpp
76d81b4d 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()
ad4e3f7b 37 #include "wx/settings.h"
f45e4fad
DW
38#endif //WX_PRECOMP
39
542e68c7 40#include "wx/module.h" // wxSetFocusToChild()
f45e4fad
DW
41#include "wx/os2/private.h"
42
43// ----------------------------------------------------------------------------
44// stubs for missing functions under MicroWindows
45// ----------------------------------------------------------------------------
46
47
48// ----------------------------------------------------------------------------
49// globals
50// ----------------------------------------------------------------------------
51
77ffb593 52// the name of the default wxWidgets class
743e24aa
WS
53extern void wxAssociateWinWithHandle( HWND hWnd, wxWindowOS2* pWin );
54
55bool wxTopLevelWindowOS2::m_sbInitialized = false;
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 //
743e24aa 118 static HWND m_shWnd;
376ef4a1
DW
119
120 //
121 // The class used to create it
122 //
743e24aa 123 static const wxChar* m_szClassName;
376ef4a1
DW
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{
743e24aa 135 m_bIconized = m_bMaximizeOnShow = false;
f45e4fad
DW
136
137 //
138 // Unlike (almost?) all other windows, frames are created hidden
139 //
743e24aa 140 m_isShown = false;
f45e4fad
DW
141
142 //
143 // Data to save/restore when calling ShowFullScreen
144 m_lFsStyle = 0;
145 m_lFsOldWindowStyle = 0;
743e24aa
WS
146 m_bFsIsMaximized = false;
147 m_bFsIsShowing = false;
f45e4fad
DW
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 362
743e24aa 363 return false;
f45e4fad
DW
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 }
ad4e3f7b 411 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
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 {
743e24aa 421 return false;
626af800 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 434 SubclassWin(m_hWnd);
743e24aa 435 return true;
f45e4fad
DW
436} // end of wxTopLevelWindowOS2::CreateDialog
437
743e24aa
WS
438bool wxTopLevelWindowOS2::CreateFrame( const wxString& rsTitle,
439 const wxPoint& rPos,
440 const wxSize& rSize )
f45e4fad 441{
743e24aa
WS
442 WXDWORD lExflags;
443 WXDWORD lFlags = OS2GetCreateWindowFlags(&lExflags);
444 long lStyle = GetWindowStyleFlag();
445 int nX = rPos.x;
446 int nY = rPos.y;
447 int nWidth = rSize.x;
448 int nHeight = rSize.y;
449 ULONG ulStyleFlags = 0L;
450 ERRORID vError;
451 wxString sError;
452 wxWindow* pParent = GetParent();
453 HWND hParent;
454 HWND hFrame;
455 HWND hClient;
f45e4fad
DW
456
457 if (pParent)
458 hParent = GetHwndOf(pParent);
459 else
460 hParent = HWND_DESKTOP;
461
462 if ((lStyle & wxMINIMIZE) || (lStyle & wxICONIZE))
463 ulStyleFlags |= WS_MINIMIZED;
464 if (lStyle & wxMAXIMIZE)
465 ulStyleFlags |= WS_MAXIMIZED;
466
467 //
468 // Clear the visible flag, we always call show
469 //
470 ulStyleFlags &= (unsigned long)~WS_VISIBLE;
743e24aa 471 m_bIconized = false;
f45e4fad
DW
472
473 //
474 // Create the frame window: We break ranks with other ports now
475 // and instead of calling down into the base wxWindow class' OS2Create
476 // we do all our own stuff here. We will set the needed pieces
477 // of wxWindow manually, here.
478 //
479
480 hFrame = ::WinCreateStdWindow( hParent
481 ,ulStyleFlags // frame-window style
482 ,(PULONG)&lFlags // window style
483 ,(PSZ)wxFrameClassName // class name
484 ,(PSZ)rsTitle.c_str() // window title
485 ,0L // default client style
486 ,NULLHANDLE // resource in executable file
487 ,0 // resource id
488 ,&hClient // receives client window handle
489 );
490 if (!hFrame)
491 {
492 vError = ::WinGetLastError(vHabmain);
493 sError = wxPMErrorToStr(vError);
0fba44b4 494 wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str());
743e24aa 495 return false;
f45e4fad
DW
496 }
497
498 //
499 // wxWindow class' m_hWnd set here and needed associations
500 //
501 m_hFrame = hFrame;
502 m_hWnd = hClient;
503 wxAssociateWinWithHandle(m_hWnd, this);
504 wxAssociateWinWithHandle(m_hFrame, this);
505
ad4e3f7b 506 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
f45e4fad
DW
507
508 LONG lColor = (LONG)m_backgroundColour.GetPixel();
509
510 if (!::WinSetPresParam( m_hWnd
511 ,PP_BACKGROUNDCOLOR
512 ,sizeof(LONG)
513 ,(PVOID)&lColor
514 ))
515 {
516 vError = ::WinGetLastError(vHabmain);
517 sError = wxPMErrorToStr(vError);
0fba44b4 518 wxLogError(_T("Error creating frame. Error: %s\n"), sError.c_str());
743e24aa 519 return false;
f45e4fad
DW
520 }
521
522 //
523 // Now need to subclass window. Instead of calling the SubClassWin in wxWindow
524 // we manually subclass here because we don't want to use the main wxWndProc
525 // by default
526 //
527 m_fnOldWndProc = (WXFARPROC) ::WinSubclassWindow(m_hFrame, (PFNWP)wxFrameMainWndProc);
528
529 //
530 // Now size everything. If adding a menu the client will need to be resized.
531 //
532
533 if (pParent)
534 {
535 nY = pParent->GetSize().y - (nY + nHeight);
536 }
537 else
538 {
539 RECTL vRect;
540
541 ::WinQueryWindowRect(HWND_DESKTOP, &vRect);
542 nY = vRect.yTop - (nY + nHeight);
543 }
544 if (!::WinSetWindowPos( m_hFrame
545 ,HWND_TOP
546 ,nX
547 ,nY
548 ,nWidth
549 ,nHeight
550 ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_ZORDER
551 ))
552 {
553 vError = ::WinGetLastError(vHabmain);
554 sError = wxPMErrorToStr(vError);
0fba44b4 555 wxLogError(_T("Error sizing frame. Error: %s\n"), sError.c_str());
743e24aa 556 return false;
f45e4fad 557 }
54ffa107
DW
558 lStyle = ::WinQueryWindowULong( m_hWnd
559 ,QWL_STYLE
560 );
561 lStyle |= WS_CLIPCHILDREN;
562 ::WinSetWindowULong( m_hWnd
563 ,QWL_STYLE
564 ,lStyle
565 );
743e24aa 566 return true;
f45e4fad
DW
567} // end of wxTopLevelWindowOS2::CreateFrame
568
569bool wxTopLevelWindowOS2::Create(
570 wxWindow* pParent
571, wxWindowID vId
572, const wxString& rsTitle
573, const wxPoint& rPos
2d28c41c 574, const wxSize& rSizeOrig
f45e4fad
DW
575, long lStyle
576, const wxString& rsName
577)
578{
579 //
580 // Init our fields
581 //
582 Init();
583 m_windowStyle = lStyle;
584 SetName(rsName);
585 m_windowId = vId == -1 ? NewControlId() : vId;
2d28c41c
SN
586
587 // always create a frame of some reasonable, even if arbitrary, size (at
588 // least for MSW compatibility)
589 wxSize rSize = rSizeOrig;
590 if ( rSize.x == -1 || rSize.y == -1 )
591 {
592 wxSize sizeDpy = wxGetDisplaySize();
593 if ( rSize.x == -1 )
594 rSize.x = sizeDpy.x / 3;
595 if ( rSize.y == -1 )
596 rSize.y = sizeDpy.y / 5;
597 }
598
f45e4fad
DW
599 wxTopLevelWindows.Append(this);
600 if (pParent)
601 pParent->AddChild(this);
602
603 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
604 {
605 //
90e572f1 606 // We have different dialog templates to allow creation of dialogs
f45e4fad
DW
607 // with & without captions under OS2indows, resizeable or not (but a
608 // resizeable dialog always has caption - otherwise it would look too
609 // strange)
610 //
611 ULONG ulDlgTemplate;
612
613 if (lStyle & wxRESIZE_BORDER)
614 ulDlgTemplate = (ULONG)kResizeableDialog;
615 else if (lStyle & wxCAPTION)
616 ulDlgTemplate = (ULONG)kCaptionDialog;
617 else
618 ulDlgTemplate = (ULONG)kNoCaptionDialog;
619 return CreateDialog( ulDlgTemplate
620 ,rsTitle
621 ,rPos
622 ,rSize
623 );
624 }
625 else // !dialog
626 {
627 return CreateFrame( rsTitle
628 ,rPos
629 ,rSize
630 );
631 }
632} // end of wxTopLevelWindowOS2::Create
633
634wxTopLevelWindowOS2::~wxTopLevelWindowOS2()
635{
f45e4fad 636 //
a23692f0
DW
637 // After destroying an owned window, Windows activates the next top level
638 // window in Z order but it may be different from our owner (to reproduce
639 // this simply Alt-TAB to another application and back before closing the
640 // owned frame) whereas we always want to yield activation to our parent
641 //
642 if (HasFlag(wxFRAME_FLOAT_ON_PARENT))
643 {
644 wxWindow* pParent = GetParent();
645
646 if (pParent)
647 {
648 ::WinSetWindowPos( GetHwndOf(pParent)
649 ,HWND_TOP
650 ,0, 0, 0, 0
651 ,SWP_ZORDER
652 );
653 }
654 }
f45e4fad
DW
655} // end of wxTopLevelWindowOS2::~wxTopLevelWindowOS2
656
f45e4fad
DW
657// ----------------------------------------------------------------------------
658// wxTopLevelWindowOS2 client size
659// ----------------------------------------------------------------------------
660
661void wxTopLevelWindowOS2::DoSetClientSize(
662 int nWidth
663, int nHeight
664)
665{
666 //
667 // Call GetClientAreaOrigin() to take the toolbar into account
668 //
669 wxPoint vPt = GetClientAreaOrigin();
670
671 nWidth += vPt.x;
672 nHeight += vPt.y;
673
674 wxWindow::DoSetClientSize( nWidth
675 ,nHeight
676 );
677} // end of wxTopLevelWindowOS2::DoSetClientSize
678
679void wxTopLevelWindowOS2::DoGetClientSize(
680 int* pnX
681, int* pnY
682) const
683{
684 wxWindow::DoGetClientSize( pnX
685 ,pnY
686 );
687
688 wxPoint vPt = GetClientAreaOrigin();
689
690 if (pnX)
691 *pnX -= vPt.x;
692
693 if (pnY)
694 *pnY += vPt.y;
695} // end of wxTopLevelWindowOS2::DoGetClientSize
696
697// ----------------------------------------------------------------------------
698// wxTopLevelWindowOS2 showing
699// ----------------------------------------------------------------------------
700
701void wxTopLevelWindowOS2::DoShowWindow(
702 int nShowCmd
703)
704{
54ffa107 705 ::WinShowWindow(m_hFrame, (BOOL)(nShowCmd & SWP_SHOW));
239c2e96
DW
706
707 //
708 // Need to artificially send a size event as wxApps often expect to do some
709 // final child control sizing
710 SendSizeEvent();
f45e4fad
DW
711 m_bIconized = nShowCmd == SWP_MINIMIZE;
712} // end of wxTopLevelWindowOS2::DoShowWindow
713
743e24aa 714bool wxTopLevelWindowOS2::Show( bool bShow )
f45e4fad 715{
743e24aa
WS
716 int nShowCmd;
717 SWP vSwp;
f45e4fad 718
376ef4a1
DW
719 if (bShow != IsShown() )
720 {
721 m_isShown = bShow;
722 }
723 else
724 {
743e24aa 725 return false;
376ef4a1 726 }
f45e4fad
DW
727 if (bShow)
728 {
729 if (m_bMaximizeOnShow)
730 {
54ffa107 731 nShowCmd = SWP_MAXIMIZE;
743e24aa 732 m_bMaximizeOnShow = false;
f45e4fad
DW
733 }
734 else
735 {
54ffa107 736 nShowCmd = SWP_SHOW;
f45e4fad
DW
737 }
738 }
739 else // hide
740 {
741 nShowCmd = SWP_HIDE;
742 }
743 DoShowWindow(nShowCmd);
744
745 if (bShow)
746 {
743e24aa 747 wxActivateEvent vEvent(wxEVT_ACTIVATE, true, m_windowId);
f45e4fad
DW
748
749 ::WinQueryWindowPos(m_hFrame, &vSwp);
6670f564 750 m_bIconized = ( vSwp.fl & SWP_MINIMIZE ) == SWP_MINIMIZE ;
f45e4fad
DW
751 ::WinQueryWindowPos(m_hWnd, &m_vSwpClient);
752 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
4a46a5df 753 ::WinQueryWindowPos(m_hWnd, &vSwp);
f45e4fad 754 ::WinEnableWindow(m_hFrame, TRUE);
859e65de
DW
755
756 //
757 // Deal with children
758 //
759 MoveChildren(m_vSwpClient.cy - vSwp.cy);
f45e4fad
DW
760 vEvent.SetEventObject(this);
761 GetEventHandler()->ProcessEvent(vEvent);
762 }
763 else
764 {
765 //
766 // Try to highlight the correct window (the parent)
767 //
768 if (GetParent())
769 {
743e24aa 770 HWND hWndParent = GetHwndOf(GetParent());
f45e4fad
DW
771
772 ::WinQueryWindowPos(hWndParent, &vSwp);
6670f564 773 m_bIconized = (vSwp.fl & SWP_MINIMIZE)==SWP_MINIMIZE;
f45e4fad
DW
774 ::WinEnableWindow(hWndParent, TRUE);
775 }
776 }
743e24aa 777 return true;
f45e4fad
DW
778} // end of wxTopLevelWindowOS2::Show
779
780// ----------------------------------------------------------------------------
781// wxTopLevelWindowOS2 maximize/minimize
782// ----------------------------------------------------------------------------
783
784void wxTopLevelWindowOS2::Maximize(
785 bool bMaximize
786)
787{
788 if (IsShown())
789 {
790 //
791 // Just maximize it directly
792 //
793 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
794 }
795 else // hidden
796 {
797 //
798 // We can't maximize the hidden frame because it shows it as well, so
799 // just remember that we should do it later in this case
800 //
6e348b12 801 m_bMaximizeOnShow = bMaximize;
f45e4fad
DW
802 }
803} // end of wxTopLevelWindowOS2::Maximize
804
805bool wxTopLevelWindowOS2::IsMaximized() const
806{
f45e4fad 807 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
6670f564 808 return (m_vSwp.fl & SWP_MAXIMIZE) == SWP_MAXIMIZE;
f45e4fad
DW
809} // end of wxTopLevelWindowOS2::IsMaximized
810
743e24aa
WS
811void wxTopLevelWindowOS2::SetTitle( const wxString& title)
812{
813 SetLabel(title);
814}
815
816wxString wxTopLevelWindowOS2::GetTitle() const
817{
818 return GetLabel();
819}
820
821void wxTopLevelWindowOS2::Iconize( bool bIconize )
f45e4fad
DW
822{
823 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
824} // end of wxTopLevelWindowOS2::Iconize
825
826bool wxTopLevelWindowOS2::IsIconized() const
827{
828 // also update the current state
829 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
830 if (m_vSwp.fl & SWP_MINIMIZE)
743e24aa 831 ((wxTopLevelWindow*)this)->m_bIconized = true;
f45e4fad 832 else
743e24aa 833 ((wxTopLevelWindow*)this)->m_bIconized = false;
f45e4fad
DW
834 return m_bIconized;
835} // end of wxTopLevelWindowOS2::IsIconized
836
837void wxTopLevelWindowOS2::Restore()
838{
839 DoShowWindow(SWP_RESTORE);
840} // end of wxTopLevelWindowOS2::Restore
841
239c2e96
DW
842// generate an artificial resize event
843void wxTopLevelWindowOS2::SendSizeEvent()
844{
845 if (!m_bIconized)
846 {
847 RECTL vRect = wxGetWindowRect(GetHwnd());
848
849 (void)::WinPostMsg( m_hFrame
850 ,WM_SIZE
851 ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
852 ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
853 );
854 }
855} // end of wxTopLevelWindowOS2::SendSizeEvent
856
f45e4fad
DW
857// ----------------------------------------------------------------------------
858// wxTopLevelWindowOS2 fullscreen
859// ----------------------------------------------------------------------------
860
6670f564
WS
861bool wxTopLevelWindowOS2::ShowFullScreen( bool bShow,
862 long lStyle )
f45e4fad
DW
863{
864 if (bShow)
865 {
866 if (IsFullScreen())
6670f564 867 return false;
f45e4fad 868
6670f564 869 m_bFsIsShowing = true;
f45e4fad
DW
870 m_lFsStyle = lStyle;
871
872 //
873 // Zap the frame borders
874 //
875
876 //
877 // Save the 'normal' window lStyle
878 //
879 m_lFsOldWindowStyle = ::WinQueryWindowULong( (HWND)GetHWND()
880 ,QWL_STYLE
881 );
882
883 //
884 // Save the old position, width & height, maximize state
885 //
886 m_vFsOldSize = GetRect();
887 m_bFsIsMaximized = IsMaximized();
888
889 //
890 // Decide which window lStyle flags to turn off
891 //
6670f564
WS
892 LONG lNewStyle = m_lFsOldWindowStyle;
893 LONG lOffFlags = 0;
f45e4fad
DW
894
895 if (lStyle & wxFULLSCREEN_NOBORDER)
896 lOffFlags |= FCF_BORDER;
897 if (lStyle & wxFULLSCREEN_NOCAPTION)
898 lOffFlags |= (FCF_TASKLIST | FCF_SYSMENU);
899
900 lNewStyle &= (~lOffFlags);
901
902 //
903 // Change our window style to be compatible with full-screen mode
904 //
905 ::WinSetWindowULong( (HWND)GetHWND()
906 ,QWL_STYLE
907 ,lNewStyle
908 );
909
910 //
911 // Resize to the size of the desktop
912 //
6670f564
WS
913 int nWidth;
914 int nHeight;
915 RECTL vRect = wxGetWindowRect(HWND_DESKTOP);
f45e4fad
DW
916
917 nWidth = vRect.xRight - vRect.xLeft;
918 nHeight = vRect.yTop - vRect.yBottom;
919
6670f564 920 SetSize( nWidth, nHeight );
f45e4fad
DW
921
922 //
923 // Now flush the window style cache and actually go full-screen
924 //
925 ::WinSetWindowPos( m_hFrame
926 ,HWND_TOP
927 ,0
928 ,0
929 ,nWidth
930 ,nHeight
931 ,SWP_SIZE | SWP_MOVE
932 );
933
6670f564
WS
934 wxSize full( nWidth, nHeight );
935 wxSizeEvent vEvent( full, GetId() );
f45e4fad 936 GetEventHandler()->ProcessEvent(vEvent);
6670f564 937 return true;
f45e4fad
DW
938 }
939 else
940 {
941 if (!IsFullScreen())
6670f564 942 return false;
f45e4fad 943
6670f564 944 m_bFsIsShowing = false;
f45e4fad
DW
945 Maximize(m_bFsIsMaximized);
946 ::WinSetWindowULong( (HWND)GetHWND()
947 ,QWL_STYLE
948 ,m_lFsOldWindowStyle
949 );
950 ::WinSetWindowPos( m_hFrame
951 ,HWND_TOP
952 ,m_vFsOldSize.x
953 ,m_vFsOldSize.y
954 ,m_vFsOldSize.width
955 ,m_vFsOldSize.height
956 ,SWP_SIZE | SWP_MOVE
957 );
6670f564 958 return true;
f45e4fad
DW
959 }
960} // end of wxTopLevelWindowOS2::ShowFullScreen
961
962// ----------------------------------------------------------------------------
963// wxTopLevelWindowOS2 misc
964// ----------------------------------------------------------------------------
965
966void wxTopLevelWindowOS2::SetIcon(
967 const wxIcon& rIcon
968)
3437f881
DW
969{
970 SetIcons(wxIconBundle(rIcon));
971} // end of wxTopLevelWindowOS2::SetIcon
972
973void wxTopLevelWindowOS2::SetIcons(
974 const wxIconBundle& rIcons
975)
f45e4fad
DW
976{
977 //
978 // This sets m_icon
979 //
3437f881
DW
980 wxTopLevelWindowBase::SetIcons(rIcons);
981
982 const wxIcon& vIcon = rIcons.GetIcon(wxSize(32, 32));
f45e4fad 983
3437f881 984 if (vIcon.Ok() && vIcon.GetWidth() == 32 && vIcon.GetHeight() == 32)
f45e4fad
DW
985 {
986 ::WinSendMsg( m_hFrame
987 ,WM_SETICON
3437f881 988 ,(MPARAM)((HPOINTER)vIcon.GetHICON())
f45e4fad
DW
989 ,NULL
990 );
991 ::WinSendMsg( m_hFrame
992 ,WM_UPDATEFRAME
993 ,(MPARAM)FCF_ICON
994 ,(MPARAM)0
995 );
996 }
997} // end of wxTopLevelWindowOS2::SetIcon
998
743e24aa 999bool wxTopLevelWindowOS2::EnableCloseButton( bool bEnable )
f45e4fad
DW
1000{
1001 //
1002 // Get system (a.k.a. window) menu
1003 //
743e24aa 1004 HMENU hMenu = ::WinWindowFromID(m_hFrame, FID_SYSMENU);
f45e4fad
DW
1005
1006 if (!hMenu)
1007 {
1008 wxLogLastError(_T("GetSystemMenu"));
743e24aa 1009 return false;
f45e4fad
DW
1010 }
1011
1012 //
1013 // Enabling/disabling the close item from it also automatically
1014 // disables/enables the close title bar button
1015 //
1016 if (bEnable)
1017 (void)::WinSendMsg( hMenu
1018 ,MM_SETITEMATTR
1019 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1020 ,MPFROM2SHORT(MIA_DISABLED, FALSE)
1021 );
1022 else
1023 (void)::WinSendMsg( hMenu
1024 ,MM_SETITEMATTR
1025 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1026 ,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
1027 );
1028
1029 //
1030 // Update appearance immediately
1031 //
1032 ::WinSendMsg( m_hFrame
1033 ,WM_UPDATEFRAME
1034 ,(MPARAM)FCF_MENU
1035 ,(MPARAM)0
1036 );
743e24aa 1037 return true;
f45e4fad
DW
1038} // end of wxTopLevelWindowOS2::EnableCloseButton
1039
376ef4a1
DW
1040// ============================================================================
1041// wxTLWHiddenParentModule implementation
1042// ============================================================================
1043
1044HWND wxTLWHiddenParentModule::m_shWnd = NULL;
1045const wxChar* wxTLWHiddenParentModule::m_szClassName = NULL;
1046
1047bool wxTLWHiddenParentModule::OnInit()
1048{
1049 m_shWnd = NULL;
1050 m_szClassName = NULL;
743e24aa 1051 return true;
376ef4a1
DW
1052} // end of wxTLWHiddenParentModule::OnInit
1053
1054void wxTLWHiddenParentModule::OnExit()
1055{
1056 if (m_shWnd)
1057 {
1058 if (!::WinDestroyWindow(m_shWnd))
1059 {
1060 wxLogLastError(_T("DestroyWindow(hidden TLW parent)"));
1061 }
1062 m_shWnd = NULL;
1063 }
1064
1065 m_szClassName = NULL;
1066} // end of wxTLWHiddenParentModule::OnExit
1067
1068/* static */
1069HWND wxTLWHiddenParentModule::GetHWND()
1070{
1071 if (!m_shWnd)
1072 {
1073 if (!m_szClassName)
1074 {
1075 static const wxChar* zHIDDEN_PARENT_CLASS = _T("wxTLWHiddenParent");
1076
1077 if (!::WinRegisterClass( wxGetInstance()
0fba44b4 1078 ,(PSZ)zHIDDEN_PARENT_CLASS
376ef4a1
DW
1079 ,NULL
1080 ,0
1081 ,sizeof(ULONG)
1082 ))
1083 {
1084 wxLogLastError(_T("RegisterClass(\"wxTLWHiddenParent\")"));
1085 }
1086 else
1087 {
1088 m_szClassName = zHIDDEN_PARENT_CLASS;
1089 }
1090 }
743e24aa
WS
1091 m_shWnd = ::WinCreateWindow( HWND_DESKTOP,
1092 (PSZ)m_szClassName,
1093 "",
1094 0L,
1095 (LONG)0L,
1096 (LONG)0L,
1097 (LONG)0L,
1098 (LONG)0L,
1099 NULLHANDLE,
1100 HWND_TOP,
1101 0L,
1102 NULL,
1103 NULL );
376ef4a1
DW
1104 if (!m_shWnd)
1105 {
1106 wxLogLastError(_T("CreateWindow(hidden TLW parent)"));
1107 }
1108 }
1109 return m_shWnd;
1110} // end of wxTLWHiddenParentModule::GetHWND