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