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