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