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