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