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