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