]> git.saurik.com Git - wxWidgets.git/blob - src/os2/toplevel.cpp
File dialog fixes
[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 if (this == m_spHiddenParent)
596 {
597 //
598 // Stop [infinite] recursion which would otherwise happen when we do
599 // "delete ms_hiddenParent" below -- and we're not interested in doing
600 // anything of the rest below for that window because the rest of
601 // wxWindows doesn't even know about it
602 //
603 return;
604 }
605
606 if (wxModelessWindows.Find(this))
607 wxModelessWindows.DeleteObject(this);
608
609 //
610 // After destroying an owned window, Windows activates the next top level
611 // window in Z order but it may be different from our owner (to reproduce
612 // this simply Alt-TAB to another application and back before closing the
613 // owned frame) whereas we always want to yield activation to our parent
614 //
615 if (HasFlag(wxFRAME_FLOAT_ON_PARENT))
616 {
617 wxWindow* pParent = GetParent();
618
619 if (pParent)
620 {
621 ::WinSetWindowPos( GetHwndOf(pParent)
622 ,HWND_TOP
623 ,0, 0, 0, 0
624 ,SWP_ZORDER
625 );
626 }
627 }
628
629 //
630 // If this is the last top-level window, we're going to exit and we should
631 // delete ms_hiddenParent now to avoid leaking it
632 //
633 if (IsLastBeforeExit())
634 {
635 if (m_spHiddenParent)
636 {
637 delete m_spHiddenParent;
638 m_spHiddenParent = NULL;
639 }
640 }
641 } // end of wxTopLevelWindowOS2::~wxTopLevelWindowOS2
642
643 // ----------------------------------------------------------------------------
644 // wxTopLevelWindowOS2 client size
645 // ----------------------------------------------------------------------------
646
647 void wxTopLevelWindowOS2::DoSetClientSize(
648 int nWidth
649 , int nHeight
650 )
651 {
652 //
653 // Call GetClientAreaOrigin() to take the toolbar into account
654 //
655 wxPoint vPt = GetClientAreaOrigin();
656
657 nWidth += vPt.x;
658 nHeight += vPt.y;
659
660 wxWindow::DoSetClientSize( nWidth
661 ,nHeight
662 );
663 } // end of wxTopLevelWindowOS2::DoSetClientSize
664
665 void wxTopLevelWindowOS2::DoGetClientSize(
666 int* pnX
667 , int* pnY
668 ) const
669 {
670 wxWindow::DoGetClientSize( pnX
671 ,pnY
672 );
673
674 wxPoint vPt = GetClientAreaOrigin();
675
676 if (pnX)
677 *pnX -= vPt.x;
678
679 if (pnY)
680 *pnY += vPt.y;
681 } // end of wxTopLevelWindowOS2::DoGetClientSize
682
683 // ----------------------------------------------------------------------------
684 // wxTopLevelWindowOS2 showing
685 // ----------------------------------------------------------------------------
686
687 void wxTopLevelWindowOS2::DoShowWindow(
688 int nShowCmd
689 )
690 {
691 ::WinShowWindow(m_hFrame, (BOOL)(nShowCmd & SWP_SHOW));
692
693 //
694 // Need to artificially send a size event as wxApps often expect to do some
695 // final child control sizing
696 SendSizeEvent();
697 m_bIconized = nShowCmd == SWP_MINIMIZE;
698 } // end of wxTopLevelWindowOS2::DoShowWindow
699
700 bool wxTopLevelWindowOS2::Show(
701 bool bShow
702 )
703 {
704 int nShowCmd;
705 SWP vSwp;
706 RECTL vRect;
707
708 if (bShow)
709 {
710 if (m_bMaximizeOnShow)
711 {
712 nShowCmd = SWP_MAXIMIZE;
713 m_bMaximizeOnShow = FALSE;
714 }
715 else
716 {
717 nShowCmd = SWP_SHOW;
718 }
719 }
720 else // hide
721 {
722 nShowCmd = SWP_HIDE;
723 }
724 DoShowWindow(nShowCmd);
725
726 if (bShow)
727 {
728 wxActivateEvent vEvent(wxEVT_ACTIVATE, TRUE, m_windowId);
729
730 ::WinQueryWindowPos(m_hFrame, &vSwp);
731 m_bIconized = vSwp.fl & SWP_MINIMIZE;
732 ::WinQueryWindowPos(m_hWnd, &m_vSwpClient);
733 ::WinSendMsg(m_hFrame, WM_UPDATEFRAME, (MPARAM)~0, 0);
734 ::WinQueryWindowPos(m_hWnd, &vSwp);
735 ::WinEnableWindow(m_hFrame, TRUE);
736
737 //
738 // Deal with children
739 //
740 MoveChildren(m_vSwpClient.cy - vSwp.cy);
741 vEvent.SetEventObject(this);
742 GetEventHandler()->ProcessEvent(vEvent);
743 }
744 else
745 {
746 //
747 // Try to highlight the correct window (the parent)
748 //
749 if (GetParent())
750 {
751 HWND hWndParent = GetHwndOf(GetParent());
752
753 ::WinQueryWindowPos(hWndParent, &vSwp);
754 m_bIconized = vSwp.fl & SWP_MINIMIZE;
755 ::WinEnableWindow(hWndParent, TRUE);
756 }
757 }
758 return TRUE;
759 } // end of wxTopLevelWindowOS2::Show
760
761 // ----------------------------------------------------------------------------
762 // wxTopLevelWindowOS2 maximize/minimize
763 // ----------------------------------------------------------------------------
764
765 void wxTopLevelWindowOS2::Maximize(
766 bool bMaximize
767 )
768 {
769 if (IsShown())
770 {
771 //
772 // Just maximize it directly
773 //
774 DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE);
775 }
776 else // hidden
777 {
778 //
779 // We can't maximize the hidden frame because it shows it as well, so
780 // just remember that we should do it later in this case
781 //
782 m_bMaximizeOnShow = TRUE;
783 }
784 } // end of wxTopLevelWindowOS2::Maximize
785
786 bool wxTopLevelWindowOS2::IsMaximized() const
787 {
788 bool bIconic;
789
790 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
791 return (m_vSwp.fl & SWP_MAXIMIZE);
792 } // end of wxTopLevelWindowOS2::IsMaximized
793
794 void wxTopLevelWindowOS2::Iconize(
795 bool bIconize
796 )
797 {
798 DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE);
799 } // end of wxTopLevelWindowOS2::Iconize
800
801 bool wxTopLevelWindowOS2::IsIconized() const
802 {
803 // also update the current state
804 ::WinQueryWindowPos(m_hFrame, (PSWP)&m_vSwp);
805 if (m_vSwp.fl & SWP_MINIMIZE)
806 ((wxTopLevelWindow*)this)->m_bIconized = TRUE;
807 else
808 ((wxTopLevelWindow*)this)->m_bIconized = FALSE;
809 return m_bIconized;
810 } // end of wxTopLevelWindowOS2::IsIconized
811
812 void wxTopLevelWindowOS2::Restore()
813 {
814 DoShowWindow(SWP_RESTORE);
815 } // end of wxTopLevelWindowOS2::Restore
816
817 // generate an artificial resize event
818 void wxTopLevelWindowOS2::SendSizeEvent()
819 {
820 if (!m_bIconized)
821 {
822 RECTL vRect = wxGetWindowRect(GetHwnd());
823
824 (void)::WinPostMsg( m_hFrame
825 ,WM_SIZE
826 ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
827 ,MPFROM2SHORT(vRect.xRight - vRect.xLeft, vRect.yTop - vRect.yBottom)
828 );
829 }
830 } // end of wxTopLevelWindowOS2::SendSizeEvent
831
832 // ----------------------------------------------------------------------------
833 // wxTopLevelWindowOS2 fullscreen
834 // ----------------------------------------------------------------------------
835
836 bool wxTopLevelWindowOS2::ShowFullScreen(
837 bool bShow
838 , long lStyle
839 )
840 {
841 if (bShow)
842 {
843 if (IsFullScreen())
844 return FALSE;
845
846 m_bFsIsShowing = TRUE;
847 m_lFsStyle = lStyle;
848
849 //
850 // Zap the frame borders
851 //
852
853 //
854 // Save the 'normal' window lStyle
855 //
856 m_lFsOldWindowStyle = ::WinQueryWindowULong( (HWND)GetHWND()
857 ,QWL_STYLE
858 );
859
860 //
861 // Save the old position, width & height, maximize state
862 //
863 m_vFsOldSize = GetRect();
864 m_bFsIsMaximized = IsMaximized();
865
866 //
867 // Decide which window lStyle flags to turn off
868 //
869 LONG lNewStyle = m_lFsOldWindowStyle;
870 LONG lOffFlags = 0;
871
872 if (lStyle & wxFULLSCREEN_NOBORDER)
873 lOffFlags |= FCF_BORDER;
874 if (lStyle & wxFULLSCREEN_NOCAPTION)
875 lOffFlags |= (FCF_TASKLIST | FCF_SYSMENU);
876
877 lNewStyle &= (~lOffFlags);
878
879 //
880 // Change our window style to be compatible with full-screen mode
881 //
882 ::WinSetWindowULong( (HWND)GetHWND()
883 ,QWL_STYLE
884 ,lNewStyle
885 );
886
887 //
888 // Resize to the size of the desktop
889 //
890 int nWidth;
891 int nHeight;
892 RECTL vRect = wxGetWindowRect(HWND_DESKTOP);
893
894 nWidth = vRect.xRight - vRect.xLeft;
895 nHeight = vRect.yTop - vRect.yBottom;
896
897 SetSize( nWidth
898 ,nHeight
899 );
900
901 //
902 // Now flush the window style cache and actually go full-screen
903 //
904 ::WinSetWindowPos( m_hFrame
905 ,HWND_TOP
906 ,0
907 ,0
908 ,nWidth
909 ,nHeight
910 ,SWP_SIZE | SWP_MOVE
911 );
912
913 wxSizeEvent vEvent( wxSize( nWidth
914 ,nHeight
915 )
916 ,GetId()
917 );
918
919 GetEventHandler()->ProcessEvent(vEvent);
920 return TRUE;
921 }
922 else
923 {
924 if (!IsFullScreen())
925 return FALSE;
926
927 m_bFsIsShowing = FALSE;
928 Maximize(m_bFsIsMaximized);
929 ::WinSetWindowULong( (HWND)GetHWND()
930 ,QWL_STYLE
931 ,m_lFsOldWindowStyle
932 );
933 ::WinSetWindowPos( m_hFrame
934 ,HWND_TOP
935 ,m_vFsOldSize.x
936 ,m_vFsOldSize.y
937 ,m_vFsOldSize.width
938 ,m_vFsOldSize.height
939 ,SWP_SIZE | SWP_MOVE
940 );
941 return TRUE;
942 }
943 } // end of wxTopLevelWindowOS2::ShowFullScreen
944
945 // ----------------------------------------------------------------------------
946 // wxTopLevelWindowOS2 misc
947 // ----------------------------------------------------------------------------
948
949 void wxTopLevelWindowOS2::SetIcon(
950 const wxIcon& rIcon
951 )
952 {
953 SetIcons(wxIconBundle(rIcon));
954 } // end of wxTopLevelWindowOS2::SetIcon
955
956 void wxTopLevelWindowOS2::SetIcons(
957 const wxIconBundle& rIcons
958 )
959 {
960 //
961 // This sets m_icon
962 //
963 wxTopLevelWindowBase::SetIcons(rIcons);
964
965 const wxIcon& vIcon = rIcons.GetIcon(wxSize(32, 32));
966
967 if (vIcon.Ok() && vIcon.GetWidth() == 32 && vIcon.GetHeight() == 32)
968 {
969 ::WinSendMsg( m_hFrame
970 ,WM_SETICON
971 ,(MPARAM)((HPOINTER)vIcon.GetHICON())
972 ,NULL
973 );
974 ::WinSendMsg( m_hFrame
975 ,WM_UPDATEFRAME
976 ,(MPARAM)FCF_ICON
977 ,(MPARAM)0
978 );
979 }
980 } // end of wxTopLevelWindowOS2::SetIcon
981
982 bool wxTopLevelWindowOS2::EnableCloseButton(
983 bool bEnable
984 )
985 {
986 //
987 // Get system (a.k.a. window) menu
988 //
989 HMENU hMenu = ::WinWindowFromID(m_hFrame, FID_SYSMENU);
990
991 if (!hMenu)
992 {
993 wxLogLastError(_T("GetSystemMenu"));
994 return FALSE;
995 }
996
997 //
998 // Enabling/disabling the close item from it also automatically
999 // disables/enables the close title bar button
1000 //
1001 if (bEnable)
1002 (void)::WinSendMsg( hMenu
1003 ,MM_SETITEMATTR
1004 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1005 ,MPFROM2SHORT(MIA_DISABLED, FALSE)
1006 );
1007 else
1008 (void)::WinSendMsg( hMenu
1009 ,MM_SETITEMATTR
1010 ,MPFROM2SHORT(SC_CLOSE, FALSE)
1011 ,MPFROM2SHORT(MIA_DISABLED, MIA_DISABLED)
1012 );
1013
1014 //
1015 // Update appearance immediately
1016 //
1017 ::WinSendMsg( m_hFrame
1018 ,WM_UPDATEFRAME
1019 ,(MPARAM)FCF_MENU
1020 ,(MPARAM)0
1021 );
1022 return TRUE;
1023 } // end of wxTopLevelWindowOS2::EnableCloseButton
1024