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