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