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