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