]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: frame.cpp | |
3 | // Purpose: wxFrame | |
4 | // Author: David Webster | |
5 | // Modified by: | |
6 | // Created: 10/27/99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) David Webster | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/setup.h" | |
17 | #include "wx/frame.h" | |
18 | #include "wx/menu.h" | |
19 | #include "wx/app.h" | |
20 | #include "wx/utils.h" | |
21 | #include "wx/dialog.h" | |
22 | #include "wx/settings.h" | |
23 | #include "wx/dcclient.h" | |
24 | #endif // WX_PRECOMP | |
25 | ||
26 | #include "wx/os2/private.h" | |
27 | ||
28 | #if wxUSE_STATUSBAR | |
29 | #include "wx/statusbr.h" | |
30 | #include "wx/generic/statusbr.h" | |
31 | #endif // wxUSE_STATUSBAR | |
32 | ||
33 | #if wxUSE_TOOLBAR | |
34 | #include "wx/toolbar.h" | |
35 | #endif // wxUSE_TOOLBAR | |
36 | ||
37 | #include "wx/menuitem.h" | |
38 | #include "wx/log.h" | |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // globals | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
44 | extern wxWindowList wxModelessWindows; | |
45 | extern wxList WXDLLEXPORT wxPendingDelete; | |
46 | extern wxChar wxFrameClassName[]; | |
47 | extern wxMenu *wxCurrentPopupMenu; | |
48 | ||
49 | // ---------------------------------------------------------------------------- | |
50 | // event tables | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
53 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) | |
54 | EVT_ACTIVATE(wxFrame::OnActivate) | |
55 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
56 | END_EVENT_TABLE() | |
57 | ||
58 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) | |
59 | ||
60 | // ============================================================================ | |
61 | // implementation | |
62 | // ============================================================================ | |
63 | ||
64 | // ---------------------------------------------------------------------------- | |
65 | // static class members | |
66 | // ---------------------------------------------------------------------------- | |
67 | ||
68 | #if wxUSE_NATIVE_STATUSBAR | |
69 | bool wxFrame::m_bUseNativeStatusBar = TRUE; | |
70 | #else | |
71 | bool wxFrame::m_bUseNativeStatusBar = FALSE; | |
72 | #endif | |
73 | ||
74 | // ---------------------------------------------------------------------------- | |
75 | // creation/destruction | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
78 | void wxFrame::Init() | |
79 | { | |
80 | m_bIconized = FALSE; | |
81 | ||
82 | #if wxUSE_TOOLTIPS | |
83 | m_hWndToolTip = 0; | |
84 | #endif | |
85 | // Data to save/restore when calling ShowFullScreen | |
86 | m_lFsStyle = 0L; | |
87 | m_lFsOldWindowStyle = 0L; | |
88 | m_nFsStatusBarFields = 0; | |
89 | m_nFsStatusBarHeight = 0; | |
90 | m_nFsToolBarHeight = 0; | |
91 | m_bFsIsMaximized = FALSE; | |
92 | m_bFsIsShowing = FALSE; | |
93 | ||
94 | // | |
95 | // Initialize SWP's | |
96 | // | |
97 | memset(&m_vSwp, 0, sizeof(SWP)); | |
98 | memset(&m_vSwpClient, 0, sizeof(SWP)); | |
99 | memset(&m_vSwpTitleBar, 0, sizeof(SWP)); | |
100 | memset(&m_vSwpMenuBar, 0, sizeof(SWP)); | |
101 | memset(&m_vSwpHScroll, 0, sizeof(SWP)); | |
102 | memset(&m_vSwpVScroll, 0, sizeof(SWP)); | |
103 | memset(&m_vSwpStatusBar, 0, sizeof(SWP)); | |
104 | memset(&m_vSwpToolBar, 0, sizeof(SWP)); | |
105 | } // end of wxFrame::Init | |
106 | ||
107 | bool wxFrame::Create( | |
108 | wxWindow* pParent | |
109 | , wxWindowID vId | |
110 | , const wxString& rsTitle | |
111 | , const wxPoint& rPos | |
112 | , const wxSize& rSize | |
113 | , long lulStyle | |
114 | , const wxString& rsName | |
115 | ) | |
116 | { | |
117 | int nX = rPos.x; | |
118 | int nY = rPos.y; | |
119 | int nWidth = rSize.x; | |
120 | int nHeight = rSize.y; | |
121 | ||
122 | SetName(rsName); | |
123 | m_windowStyle = lulStyle; | |
124 | m_frameMenuBar = NULL; | |
125 | m_frameToolBar = NULL; | |
126 | m_frameStatusBar = NULL; | |
127 | ||
128 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
129 | ||
130 | if (vId > -1 ) | |
131 | m_windowId = vId; | |
132 | else | |
133 | m_windowId = (int)NewControlId(); | |
134 | ||
135 | if (pParent) | |
136 | pParent->AddChild(this); | |
137 | ||
138 | m_bIconized = FALSE; | |
139 | ||
140 | if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0) | |
141 | pParent = NULL; | |
142 | ||
143 | if (!pParent) | |
144 | wxTopLevelWindows.Append(this); | |
145 | ||
146 | OS2Create( m_windowId | |
147 | ,pParent | |
148 | ,wxFrameClassName | |
149 | ,this | |
150 | ,rsTitle | |
151 | ,nX | |
152 | ,nY | |
153 | ,nWidth | |
154 | ,nHeight | |
155 | ,lulStyle | |
156 | ); | |
157 | ||
158 | wxModelessWindows.Append(this); | |
159 | return TRUE; | |
160 | } // end of wxFrame::Create | |
161 | ||
162 | wxFrame::~wxFrame() | |
163 | { | |
164 | m_isBeingDeleted = TRUE; | |
165 | wxTopLevelWindows.DeleteObject(this); | |
166 | ||
167 | DeleteAllBars(); | |
168 | ||
169 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
170 | { | |
171 | wxTheApp->SetTopWindow(NULL); | |
172 | ||
173 | if (wxTheApp->GetExitOnFrameDelete()) | |
174 | { | |
175 | ::WinPostMsg(m_hFrame, WM_QUIT, 0, 0); | |
176 | } | |
177 | } | |
178 | wxModelessWindows.DeleteObject(this); | |
179 | ||
180 | // | |
181 | // For some reason, wxWindows can activate another task altogether | |
182 | // when a frame is destroyed after a modal dialog has been invoked. | |
183 | // Try to bring the parent to the top. | |
184 | // | |
185 | // MT:Only do this if this frame is currently the active window, else weird | |
186 | // things start to happen. | |
187 | // | |
188 | if (wxGetActiveWindow() == this) | |
189 | { | |
190 | if (GetParent() && GetParent()->GetHWND()) | |
191 | { | |
192 | ::WinSetWindowPos( (HWND) GetParent()->GetHWND() | |
193 | ,HWND_TOP | |
194 | ,0 | |
195 | ,0 | |
196 | ,0 | |
197 | ,0 | |
198 | ,SWP_ZORDER | |
199 | ); | |
200 | } | |
201 | } | |
202 | } // end of wxFrame::~wxFrame | |
203 | ||
204 | // | |
205 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. | |
206 | // | |
207 | void wxFrame::DoGetClientSize( | |
208 | int* pX | |
209 | , int* pY | |
210 | ) const | |
211 | { | |
212 | // | |
213 | // OS/2 PM's coordinates go from bottom-left not | |
214 | // top-left thus the += instead of the -= | |
215 | // | |
216 | RECTL vRect; | |
217 | ||
218 | // | |
219 | // PM has no GetClientRect that inherantly knows about the client window | |
220 | // We have to explicitly go fetch it! | |
221 | // | |
222 | ::WinQueryWindowRect(GetHwnd(), &vRect); | |
223 | ||
224 | #if wxUSE_STATUSBAR | |
225 | if ( GetStatusBar() ) | |
226 | { | |
227 | int nStatusX; | |
228 | int nStatusY; | |
229 | ||
230 | GetStatusBar()->GetClientSize( &nStatusX | |
231 | ,&nStatusY | |
232 | ); | |
233 | vRect.yBottom += nStatusY; | |
234 | } | |
235 | #endif // wxUSE_STATUSBAR | |
236 | ||
237 | wxPoint vPoint(GetClientAreaOrigin()); | |
238 | ||
239 | vRect.yBottom += vPoint.y; | |
240 | vRect.xRight -= vPoint.x; | |
241 | ||
242 | if (pX) | |
243 | *pX = vRect.xRight; | |
244 | if (pY) | |
245 | *pY = vRect.yBottom; | |
246 | } // end of wxFrame::DoGetClientSize | |
247 | ||
248 | // | |
249 | // Set the client size (i.e. leave the calculation of borders etc. | |
250 | // to wxWindows) | |
251 | // | |
252 | void wxFrame::DoSetClientSize( | |
253 | int nWidth | |
254 | , int nHeight | |
255 | ) | |
256 | { | |
257 | HWND hWnd = GetHwnd(); | |
258 | RECTL vRect; | |
259 | RECTL vRect2; | |
260 | ||
261 | ::WinQueryWindowRect(GetHwnd(), &vRect); | |
262 | ||
263 | ::WinQueryWindowRect(m_hFrame, &vRect2); | |
264 | ||
265 | // | |
266 | // Find the difference between the entire window (title bar and all) | |
267 | // and the client area; add this to the new client size to move the | |
268 | // window. Remember OS/2's backwards y coord system! | |
269 | // | |
270 | int nActualWidth = vRect2.xRight - vRect2.xLeft - vRect.xRight + nWidth; | |
271 | int nActualHeight = vRect2.yTop + vRect2.yTop - vRect.yTop + nHeight; | |
272 | ||
273 | #if wxUSE_STATUSBAR | |
274 | if ( GetStatusBar() ) | |
275 | { | |
276 | int nStatusX; | |
277 | int nStatusY; | |
278 | ||
279 | GetStatusBar()->GetClientSize( &nStatusX | |
280 | ,&nStatusY | |
281 | ); | |
282 | nActualHeight += nStatusY; | |
283 | } | |
284 | #endif // wxUSE_STATUSBAR | |
285 | ||
286 | wxPoint vPoint(GetClientAreaOrigin()); | |
287 | nActualWidth += vPoint.y; | |
288 | nActualHeight += vPoint.x; | |
289 | ||
290 | POINTL vPointl; | |
291 | ||
292 | vPointl.x = vRect2.xLeft; | |
293 | vPoint.y = vRect2.yTop; | |
294 | ||
295 | ::WinSetWindowPos( m_hFrame | |
296 | ,HWND_TOP | |
297 | ,vPointl.x | |
298 | ,vPointl.y | |
299 | ,nActualWidth | |
300 | ,nActualHeight | |
301 | ,SWP_MOVE | SWP_SIZE | SWP_SHOW | |
302 | ); | |
303 | ||
304 | wxSizeEvent vEvent( wxSize( nWidth | |
305 | ,nHeight | |
306 | ) | |
307 | ,m_windowId | |
308 | ); | |
309 | vEvent.SetEventObject(this); | |
310 | GetEventHandler()->ProcessEvent(vEvent); | |
311 | } // end of wxFrame::DoSetClientSize | |
312 | ||
313 | void wxFrame::DoGetSize( | |
314 | int* pWidth | |
315 | , int* pHeight | |
316 | ) const | |
317 | { | |
318 | RECTL vRect; | |
319 | ||
320 | ::WinQueryWindowRect(m_hFrame, &vRect); | |
321 | *pWidth = vRect.xRight - vRect.xLeft; | |
322 | *pHeight = vRect.yTop - vRect.yBottom; | |
323 | } // end of wxFrame::DoGetSize | |
324 | ||
325 | void wxFrame::DoGetPosition( | |
326 | int* pX | |
327 | , int* pY | |
328 | ) const | |
329 | { | |
330 | RECTL vRect; | |
331 | POINTL vPoint; | |
332 | ||
333 | ::WinQueryWindowRect(m_hFrame, &vRect); | |
334 | vPoint.x = vRect.xLeft; | |
335 | ||
336 | // | |
337 | // OS/2 is backwards [WIN32 it is vRect.yTop] | |
338 | // | |
339 | vPoint.y = vRect.yBottom; | |
340 | ||
341 | *pX = vPoint.x; | |
342 | *pY = vPoint.y; | |
343 | } // end of wxFrame::DoGetPosition | |
344 | ||
345 | // ---------------------------------------------------------------------------- | |
346 | // variations around ::ShowWindow() | |
347 | // ---------------------------------------------------------------------------- | |
348 | ||
349 | void wxFrame::DoShowWindow( | |
350 | int bShowCmd | |
351 | ) | |
352 | { | |
353 | HWND hClient = NULLHANDLE; | |
354 | SWP vSwp; | |
355 | ||
356 | // | |
357 | // Reset the window position | |
358 | // | |
359 | WinQueryWindowPos(m_hFrame, &vSwp); | |
360 | WinSetWindowPos( GetHwnd() | |
361 | ,HWND_TOP | |
362 | ,vSwp.x | |
363 | ,vSwp.y | |
364 | ,vSwp.cx | |
365 | ,vSwp.cy | |
366 | ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | |
367 | ); | |
368 | ::WinShowWindow(m_hFrame, (BOOL)bShowCmd); | |
369 | ::WinShowWindow(GetHwnd(), (BOOL)bShowCmd); | |
370 | } // end of wxFrame::DoShowWindow | |
371 | ||
372 | bool wxFrame::Show( | |
373 | bool bShow | |
374 | ) | |
375 | { | |
376 | SWP vSwp; | |
377 | ||
378 | DoShowWindow((int)bShow); | |
379 | ||
380 | if (bShow) | |
381 | { | |
382 | wxActivateEvent vEvent(wxEVT_ACTIVATE, TRUE, m_windowId); | |
383 | ||
384 | ::WinQueryWindowPos(m_hFrame, &vSwp); | |
385 | m_bIconized = vSwp.fl & SWP_MINIMIZE; | |
386 | ::WinEnableWindow(m_hFrame, TRUE); | |
387 | vEvent.SetEventObject(this); | |
388 | GetEventHandler()->ProcessEvent(vEvent); | |
389 | } | |
390 | else | |
391 | { | |
392 | // | |
393 | // Try to highlight the correct window (the parent) | |
394 | // | |
395 | if (GetParent()) | |
396 | { | |
397 | HWND hWndParent = GetHwndOf(GetParent()); | |
398 | ||
399 | ::WinQueryWindowPos(hWndParent, &vSwp); | |
400 | m_bIconized = vSwp.fl & SWP_MINIMIZE; | |
401 | if (hWndParent) | |
402 | ::WinSetWindowPos( hWndParent | |
403 | ,HWND_TOP | |
404 | ,vSwp.x | |
405 | ,vSwp.y | |
406 | ,vSwp.cx | |
407 | ,vSwp.cy | |
408 | ,SWP_ZORDER | SWP_ACTIVATE | SWP_SHOW | SWP_MOVE | |
409 | ); | |
410 | ::WinEnableWindow(hWndParent, TRUE); | |
411 | } | |
412 | } | |
413 | return TRUE; | |
414 | } // end of wxFrame::Show | |
415 | ||
416 | void wxFrame::Iconize( | |
417 | bool bIconize | |
418 | ) | |
419 | { | |
420 | DoShowWindow(bIconize ? SWP_MINIMIZE : SWP_RESTORE); | |
421 | } // end of wxFrame::Iconize | |
422 | ||
423 | void wxFrame::Maximize( | |
424 | bool bMaximize) | |
425 | { | |
426 | DoShowWindow(bMaximize ? SWP_MAXIMIZE : SWP_RESTORE); | |
427 | } // end of wxFrame::Maximize | |
428 | ||
429 | void wxFrame::Restore() | |
430 | { | |
431 | DoShowWindow(SWP_RESTORE); | |
432 | } // end of wxFrame::Restore | |
433 | ||
434 | bool wxFrame::IsIconized() const | |
435 | { | |
436 | SWP vSwp; | |
437 | bool bIconic; | |
438 | ||
439 | ::WinQueryWindowPos(GetHwnd(), &vSwp); | |
440 | ||
441 | if (vSwp.fl & SWP_MINIMIZE) | |
442 | ((wxFrame*)this)->m_bIconized = TRUE; | |
443 | else | |
444 | ((wxFrame*)this)->m_bIconized = FALSE; | |
445 | return m_bIconized; | |
446 | } // end of wxFrame::IsIconized | |
447 | ||
448 | // Is it maximized? | |
449 | bool wxFrame::IsMaximized() const | |
450 | { | |
451 | SWP vSwp; | |
452 | bool bIconic; | |
453 | ||
454 | ::WinQueryWindowPos(m_hFrame, &vSwp); | |
455 | return (vSwp.fl & SWP_MAXIMIZE); | |
456 | } // end of wxFrame::IsMaximized | |
457 | ||
458 | void wxFrame::SetIcon( | |
459 | const wxIcon& rIcon | |
460 | ) | |
461 | { | |
462 | wxFrameBase::SetIcon(rIcon); | |
463 | ||
464 | if ((m_icon.GetHICON()) != NULLHANDLE) | |
465 | { | |
466 | ::WinSendMsg( m_hFrame | |
467 | ,WM_SETICON | |
468 | ,(MPARAM)((HPOINTER)m_icon.GetHICON()) | |
469 | ,NULL | |
470 | ); | |
471 | ::WinSendMsg( m_hFrame | |
472 | ,WM_UPDATEFRAME | |
473 | ,(MPARAM)FCF_ICON | |
474 | ,(MPARAM)0 | |
475 | ); | |
476 | } | |
477 | } // end of wxFrame::SetIcon | |
478 | ||
479 | #if wxUSE_STATUSBAR | |
480 | wxStatusBar* wxFrame::OnCreateStatusBar( | |
481 | int nNumber | |
482 | , long lulStyle | |
483 | , wxWindowID vId | |
484 | , const wxString& rName | |
485 | ) | |
486 | { | |
487 | wxStatusBar* pStatusBar = NULL; | |
488 | SWP vSwp; | |
489 | ERRORID vError; | |
490 | wxString sError; | |
491 | HWND hWnd; | |
492 | ||
493 | pStatusBar = wxFrameBase::OnCreateStatusBar( nNumber | |
494 | ,lulStyle | |
495 | ,vId | |
496 | ,rName | |
497 | ); | |
498 | // | |
499 | // The default parent set for the Statusbar is m_hWnd which, of course, | |
500 | // is the handle to the client window of the frame. We don't want that, | |
501 | // so we have to set the parent to actually be the Frame. | |
502 | // | |
503 | hWnd = pStatusBar->GetHWND(); | |
504 | if (!::WinSetParent(hWnd, m_hFrame, FALSE)) | |
505 | { | |
506 | vError = ::WinGetLastError(vHabmain); | |
507 | sError = wxPMErrorToStr(vError); | |
508 | wxLogError("Error setting parent for statusbar. Error: %s\n", sError); | |
509 | return NULL; | |
510 | } | |
511 | ||
512 | // | |
513 | // Also we need to reset it positioning to enable the SHOW attribute | |
514 | // | |
515 | if (!::WinQueryWindowPos((HWND)pStatusBar->GetHWND(), &vSwp)) | |
516 | { | |
517 | vError = ::WinGetLastError(vHabmain); | |
518 | sError = wxPMErrorToStr(vError); | |
519 | wxLogError("Error querying frame for statusbar position. Error: %s\n", sError); | |
520 | return NULL; | |
521 | } | |
522 | if (!::WinSetWindowPos( (HWND)pStatusBar->GetHWND() | |
523 | ,HWND_TOP | |
524 | ,vSwp.cx | |
525 | ,vSwp.cy | |
526 | ,vSwp.x | |
527 | ,vSwp.y | |
528 | ,SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER | |
529 | )) | |
530 | { | |
531 | vError = ::WinGetLastError(vHabmain); | |
532 | sError = wxPMErrorToStr(vError); | |
533 | wxLogError("Error setting statusbar position. Error: %s\n", sError); | |
534 | return NULL; | |
535 | } | |
536 | return pStatusBar; | |
537 | } // end of wxFrame::OnCreateStatusBar | |
538 | ||
539 | void wxFrame::PositionStatusBar() | |
540 | { | |
541 | SWP vSwp; | |
542 | ERRORID vError; | |
543 | wxString sError; | |
544 | ||
545 | // | |
546 | // Native status bar positions itself | |
547 | // | |
548 | if (m_frameStatusBar) | |
549 | { | |
550 | int nWidth; | |
551 | int nHeight; | |
552 | int nStatbarWidth; | |
553 | int nStatbarHeight; | |
554 | HWND hWndClient; | |
555 | RECTL vRect; | |
556 | ||
557 | ::WinQueryWindowRect(GetHwnd(), &vRect); | |
558 | nWidth = vRect.xRight - vRect.xLeft; | |
559 | nHeight = vRect.yTop - vRect.yBottom; | |
560 | ||
561 | m_frameStatusBar->GetSize( &nStatbarWidth | |
562 | ,&nStatbarHeight | |
563 | ); | |
564 | ||
565 | // | |
566 | // Since we wish the status bar to be directly under the client area, | |
567 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
568 | // | |
569 | m_frameStatusBar->SetSize( 0 | |
570 | ,nHeight | |
571 | ,nWidth | |
572 | ,nStatbarHeight | |
573 | ); | |
574 | if (!::WinQueryWindowPos(m_frameStatusBar->GetHWND(), &vSwp)) | |
575 | { | |
576 | vError = ::WinGetLastError(vHabmain); | |
577 | sError = wxPMErrorToStr(vError); | |
578 | wxLogError("Error setting parent for submenu. Error: %s\n", sError); | |
579 | return; | |
580 | } | |
581 | if (!::WinSetWindowPos( m_frameStatusBar->GetHWND() | |
582 | ,HWND_TOP | |
583 | ,nStatbarWidth | |
584 | ,nStatbarHeight | |
585 | ,vSwp.x | |
586 | ,vSwp.y | |
587 | ,SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER | |
588 | )) | |
589 | { | |
590 | vError = ::WinGetLastError(vHabmain); | |
591 | sError = wxPMErrorToStr(vError); | |
592 | wxLogError("Error setting parent for submenu. Error: %s\n", sError); | |
593 | return; | |
594 | } | |
595 | } | |
596 | } // end of wxFrame::PositionStatusBar | |
597 | #endif // wxUSE_STATUSBAR | |
598 | ||
599 | void wxFrame::DetachMenuBar() | |
600 | { | |
601 | if (m_frameMenuBar) | |
602 | { | |
603 | m_frameMenuBar->Detach(); | |
604 | m_frameMenuBar = NULL; | |
605 | } | |
606 | } // end of wxFrame::DetachMenuBar | |
607 | ||
608 | void wxFrame::SetMenuBar( | |
609 | wxMenuBar* pMenuBar | |
610 | ) | |
611 | { | |
612 | ERRORID vError; | |
613 | wxString sError; | |
614 | HWND hClient = NULLHANDLE; | |
615 | HWND hFrame = NULLHANDLE; | |
616 | HWND hTitlebar = NULLHANDLE; | |
617 | HWND hHScroll = NULLHANDLE; | |
618 | HWND hVScroll = NULLHANDLE; | |
619 | HWND hMenuBar = NULLHANDLE; | |
620 | SWP vSwp; | |
621 | SWP vSwpTitlebar; | |
622 | SWP vSwpVScroll; | |
623 | SWP vSwpHScroll; | |
624 | SWP vSwpMenu; | |
625 | ||
626 | if (!pMenuBar) | |
627 | { | |
628 | DetachMenuBar(); | |
629 | return; | |
630 | } | |
631 | ||
632 | m_frameMenuBar = NULL; | |
633 | ||
634 | // Can set a menubar several times. | |
635 | // TODO: how to prevent a memory leak if you have a currently-unattached | |
636 | // menubar? wxWindows assumes that the frame will delete the menu (otherwise | |
637 | // there are problems for MDI). | |
638 | if (pMenuBar->GetHMenu()) | |
639 | { | |
640 | m_hMenu = pMenuBar->GetHMenu(); | |
641 | } | |
642 | else | |
643 | { | |
644 | pMenuBar->Detach(); | |
645 | ||
646 | m_hMenu = pMenuBar->Create(); | |
647 | ||
648 | if (!m_hMenu) | |
649 | return; | |
650 | } | |
651 | ||
652 | // | |
653 | // Set the parent and owner of the menubar to be the frame | |
654 | // | |
655 | if (!::WinSetParent(m_hMenu, m_hFrame, FALSE)) | |
656 | { | |
657 | vError = ::WinGetLastError(vHabmain); | |
658 | sError = wxPMErrorToStr(vError); | |
659 | wxLogError("Error setting parent for submenu. Error: %s\n", sError); | |
660 | } | |
661 | ||
662 | if (!::WinSetOwner(m_hMenu, m_hFrame)) | |
663 | { | |
664 | vError = ::WinGetLastError(vHabmain); | |
665 | sError = wxPMErrorToStr(vError); | |
666 | wxLogError("Error setting parent for submenu. Error: %s\n", sError); | |
667 | } | |
668 | InternalSetMenuBar(); | |
669 | ||
670 | m_frameMenuBar = pMenuBar; | |
671 | pMenuBar->Attach(this); | |
672 | ||
673 | // | |
674 | // Now resize the client to fit the new frame | |
675 | // | |
676 | WinQueryWindowPos(m_hFrame, &vSwp); | |
677 | hTitlebar = WinWindowFromID(m_hFrame, FID_TITLEBAR); | |
678 | WinQueryWindowPos(hTitlebar, &vSwpTitlebar); | |
679 | hHScroll = WinWindowFromID(m_hFrame, FID_HORZSCROLL); | |
680 | WinQueryWindowPos(hHScroll, &vSwpHScroll); | |
681 | hVScroll = WinWindowFromID(m_hFrame, FID_VERTSCROLL); | |
682 | WinQueryWindowPos(hVScroll, &vSwpVScroll); | |
683 | hMenuBar = WinWindowFromID(m_hFrame, FID_MENU); | |
684 | WinQueryWindowPos(hMenuBar, &vSwpMenu); | |
685 | WinSetWindowPos( GetHwnd() | |
686 | ,HWND_TOP | |
687 | ,SV_CXSIZEBORDER/2 | |
688 | ,(SV_CYSIZEBORDER/2) + vSwpHScroll.cy/2 | |
689 | ,vSwp.cx - ((SV_CXSIZEBORDER + 1) + vSwpVScroll.cx) | |
690 | ,vSwp.cy - ((SV_CYSIZEBORDER + 1) + vSwpTitlebar.cy + vSwpMenu.cy + vSwpHScroll.cy/2) | |
691 | ,SWP_SIZE | SWP_MOVE | |
692 | ); | |
693 | } // end of wxFrame::SetMenuBar | |
694 | ||
695 | void wxFrame::InternalSetMenuBar() | |
696 | { | |
697 | WinSendMsg((HWND)m_hFrame, WM_UPDATEFRAME, (MPARAM)FCF_MENU, (MPARAM)0); | |
698 | } // end of wxFrame::InternalSetMenuBar | |
699 | ||
700 | // | |
701 | // Responds to colour changes, and passes event on to children | |
702 | // | |
703 | void wxFrame::OnSysColourChanged( | |
704 | wxSysColourChangedEvent& rEvent | |
705 | ) | |
706 | { | |
707 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
708 | Refresh(); | |
709 | ||
710 | if (m_frameStatusBar) | |
711 | { | |
712 | wxSysColourChangedEvent vEvent2; | |
713 | ||
714 | vEvent2.SetEventObject(m_frameStatusBar); | |
715 | m_frameStatusBar->GetEventHandler()->ProcessEvent(vEvent2); | |
716 | } | |
717 | ||
718 | // | |
719 | // Propagate the event to the non-top-level children | |
720 | // | |
721 | wxWindow::OnSysColourChanged(rEvent); | |
722 | } // end of wxFrame::OnSysColourChanged | |
723 | ||
724 | // Pass TRUE to show full screen, FALSE to restore. | |
725 | bool wxFrame::ShowFullScreen( | |
726 | bool bShow | |
727 | , long lStyle | |
728 | ) | |
729 | { | |
730 | /* | |
731 | // TODO | |
732 | if (show) | |
733 | { | |
734 | if (IsFullScreen()) | |
735 | return FALSE; | |
736 | ||
737 | m_fsIsShowing = TRUE; | |
738 | m_fsStyle = style; | |
739 | ||
740 | wxToolBar *theToolBar = GetToolBar(); | |
741 | wxStatusBar *theStatusBar = GetStatusBar(); | |
742 | ||
743 | int dummyWidth; | |
744 | ||
745 | if (theToolBar) | |
746 | theToolBar->GetSize(&dummyWidth, &m_fsToolBarHeight); | |
747 | if (theStatusBar) | |
748 | theStatusBar->GetSize(&dummyWidth, &m_fsStatusBarHeight); | |
749 | ||
750 | // zap the toolbar, menubar, and statusbar | |
751 | ||
752 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
753 | { | |
754 | theToolBar->SetSize(-1,0); | |
755 | theToolBar->Show(FALSE); | |
756 | } | |
757 | ||
758 | if (style & wxFULLSCREEN_NOMENUBAR) | |
759 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
760 | ||
761 | // Save the number of fields in the statusbar | |
762 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
763 | { | |
764 | m_fsStatusBarFields = theStatusBar->GetFieldsCount(); | |
765 | SetStatusBar((wxStatusBar*) NULL); | |
766 | delete theStatusBar; | |
767 | } | |
768 | else | |
769 | m_fsStatusBarFields = 0; | |
770 | ||
771 | // zap the frame borders | |
772 | ||
773 | // save the 'normal' window style | |
774 | m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE); | |
775 | ||
776 | // save the old position, width & height, maximize state | |
777 | m_fsOldSize = GetRect(); | |
778 | m_fsIsMaximized = IsMaximized(); | |
779 | ||
780 | // decide which window style flags to turn off | |
781 | LONG newStyle = m_fsOldWindowStyle; | |
782 | LONG offFlags = 0; | |
783 | ||
784 | if (style & wxFULLSCREEN_NOBORDER) | |
785 | offFlags |= WS_BORDER; | |
786 | if (style & wxFULLSCREEN_NOCAPTION) | |
787 | offFlags |= (WS_CAPTION | WS_SYSMENU); | |
788 | ||
789 | newStyle &= (~offFlags); | |
790 | ||
791 | // change our window style to be compatible with full-screen mode | |
792 | SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle); | |
793 | ||
794 | // resize to the size of the desktop | |
795 | int width, height; | |
796 | ||
797 | RECT rect; | |
798 | ::GetWindowRect(GetDesktopWindow(), &rect); | |
799 | width = rect.right - rect.left; | |
800 | height = rect.bottom - rect.top; | |
801 | ||
802 | SetSize(width, height); | |
803 | ||
804 | // now flush the window style cache and actually go full-screen | |
805 | SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED); | |
806 | ||
807 | wxSizeEvent event(wxSize(width, height), GetId()); | |
808 | GetEventHandler()->ProcessEvent(event); | |
809 | ||
810 | return TRUE; | |
811 | } | |
812 | else | |
813 | { | |
814 | if (!IsFullScreen()) | |
815 | return FALSE; | |
816 | ||
817 | m_fsIsShowing = FALSE; | |
818 | ||
819 | wxToolBar *theToolBar = GetToolBar(); | |
820 | ||
821 | // restore the toolbar, menubar, and statusbar | |
822 | if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
823 | { | |
824 | theToolBar->SetSize(-1, m_fsToolBarHeight); | |
825 | theToolBar->Show(TRUE); | |
826 | } | |
827 | ||
828 | if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_fsStatusBarFields > 0)) | |
829 | { | |
830 | CreateStatusBar(m_fsStatusBarFields); | |
831 | PositionStatusBar(); | |
832 | } | |
833 | ||
834 | if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) | |
835 | SetMenu((HWND)GetHWND(), (HMENU)m_hMenu); | |
836 | ||
837 | Maximize(m_fsIsMaximized); | |
838 | SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle); | |
839 | SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y, | |
840 | m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED); | |
841 | ||
842 | return TRUE; | |
843 | } | |
844 | */ | |
845 | return TRUE; | |
846 | } // end of wxFrame::ShowFullScreen | |
847 | ||
848 | // | |
849 | // Frame window | |
850 | // | |
851 | bool wxFrame::OS2Create( | |
852 | int nId | |
853 | , wxWindow* pParent | |
854 | , const wxChar* zWclass | |
855 | , wxWindow* pWxWin | |
856 | , const wxChar* zTitle | |
857 | , int nX | |
858 | , int nY | |
859 | , int nWidth | |
860 | , int nHeight | |
861 | , long ulStyle | |
862 | ) | |
863 | { | |
864 | ULONG ulCreateFlags = 0L; | |
865 | ULONG ulStyleFlags = 0L; | |
866 | ULONG ulExtraFlags = 0L; | |
867 | FRAMECDATA vFrameCtlData; | |
868 | HWND hParent = NULLHANDLE; | |
869 | HWND hClient = NULLHANDLE; | |
870 | HWND hFrame = NULLHANDLE; | |
871 | HWND hTitlebar = NULLHANDLE; | |
872 | HWND hHScroll = NULLHANDLE; | |
873 | HWND hVScroll = NULLHANDLE; | |
874 | SWP vSwp[10]; | |
875 | RECTL vRect[10]; | |
876 | USHORT uCtlCount; | |
877 | ||
878 | m_hDefaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); | |
879 | ||
880 | if (pParent) | |
881 | hParent = GetWinHwnd(pParent); | |
882 | else | |
883 | hParent = HWND_DESKTOP; | |
884 | ||
885 | if (ulStyle == wxDEFAULT_FRAME_STYLE) | |
886 | ulCreateFlags = FCF_SIZEBORDER | FCF_TITLEBAR | FCF_SYSMENU | | |
887 | FCF_MINMAX | FCF_TASKLIST; | |
888 | else | |
889 | { | |
890 | if ((ulStyle & wxCAPTION) == wxCAPTION) | |
891 | ulCreateFlags = FCF_TASKLIST; | |
892 | else | |
893 | ulCreateFlags = FCF_NOMOVEWITHOWNER; | |
894 | ||
895 | if ((ulStyle & wxVSCROLL) == wxVSCROLL) | |
896 | ulCreateFlags |= FCF_VERTSCROLL; | |
897 | if ((ulStyle & wxHSCROLL) == wxHSCROLL) | |
898 | ulCreateFlags |= FCF_HORZSCROLL; | |
899 | if (ulStyle & wxMINIMIZE_BOX) | |
900 | ulCreateFlags |= FCF_MINBUTTON; | |
901 | if (ulStyle & wxMAXIMIZE_BOX) | |
902 | ulCreateFlags |= FCF_MAXBUTTON; | |
903 | if (ulStyle & wxTHICK_FRAME) | |
904 | ulCreateFlags |= FCF_DLGBORDER; | |
905 | if (ulStyle & wxSYSTEM_MENU) | |
906 | ulCreateFlags |= FCF_SYSMENU; | |
907 | if (ulStyle & wxCAPTION) | |
908 | ulCreateFlags |= FCF_TASKLIST; | |
909 | if (ulStyle & wxCLIP_CHILDREN) | |
910 | { | |
911 | // Invalid for frame windows under PM | |
912 | } | |
913 | ||
914 | if (ulStyle & wxTINY_CAPTION_VERT) | |
915 | ulCreateFlags |= FCF_TASKLIST; | |
916 | if (ulStyle & wxTINY_CAPTION_HORIZ) | |
917 | ulCreateFlags |= FCF_TASKLIST; | |
918 | ||
919 | if ((ulStyle & wxTHICK_FRAME) == 0) | |
920 | ulCreateFlags |= FCF_BORDER; | |
921 | if (ulStyle & wxFRAME_TOOL_WINDOW) | |
922 | ulExtraFlags = kFrameToolWindow; | |
923 | ||
924 | if (ulStyle & wxSTAY_ON_TOP) | |
925 | ulCreateFlags |= FCF_SYSMODAL; | |
926 | } | |
927 | if ((ulStyle & wxMINIMIZE) || (ulStyle & wxICONIZE)) | |
928 | ulStyleFlags |= WS_MINIMIZED; | |
929 | if (ulStyle & wxMAXIMIZE) | |
930 | ulStyleFlags |= WS_MAXIMIZED; | |
931 | ||
932 | // | |
933 | // Clear the visible flag, we always call show | |
934 | // | |
935 | ulStyleFlags &= (unsigned long)~WS_VISIBLE; | |
936 | m_bIconized = FALSE; | |
937 | ||
938 | // | |
939 | // Set the frame control block | |
940 | // | |
941 | vFrameCtlData.cb = sizeof(vFrameCtlData); | |
942 | vFrameCtlData.flCreateFlags = ulCreateFlags; | |
943 | vFrameCtlData.hmodResources = 0L; | |
944 | vFrameCtlData.idResources = 0; | |
945 | ||
946 | // | |
947 | // Create the frame window | |
948 | // | |
949 | if ((m_hFrame = ::WinCreateWindow( hParent // Frame is parent | |
950 | ,WC_FRAME // standard frame class | |
951 | ,(PSZ)zTitle // Window title | |
952 | ,0 // No styles | |
953 | ,0, 0, 0, 0 // Window position | |
954 | ,NULLHANDLE // Owner | |
955 | ,HWND_TOP // Sibling | |
956 | ,(ULONG)nId // ID | |
957 | ,(PVOID)&vFrameCtlData // Creation data | |
958 | ,NULL // Window Pres Params | |
959 | )) == 0L) | |
960 | { | |
961 | return FALSE; | |
962 | } | |
963 | ||
964 | if (!wxWindow::OS2Create( m_hFrame | |
965 | ,wxFrameClassName | |
966 | ,NULL | |
967 | ,0L | |
968 | ,0L | |
969 | ,0L | |
970 | ,0L | |
971 | ,0L | |
972 | ,NULLHANDLE | |
973 | ,HWND_TOP | |
974 | ,(unsigned long)FID_CLIENT | |
975 | ,NULL | |
976 | ,NULL | |
977 | )) | |
978 | { | |
979 | return FALSE; | |
980 | } | |
981 | ||
982 | // | |
983 | // Now size everything. If adding a menu the client will need to be resized. | |
984 | // | |
985 | if (!::WinSetWindowPos( m_hFrame | |
986 | ,HWND_TOP | |
987 | ,nX | |
988 | ,nY | |
989 | ,nWidth | |
990 | ,nHeight | |
991 | ,SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_ZORDER | |
992 | )) | |
993 | return FALSE; | |
994 | ||
995 | uCtlCount = SHORT1FROMMP(::WinSendMsg(m_hFrame, WM_FORMATFRAME, (MPARAM)vSwp, (MPARAM)vRect)); | |
996 | for (int i = 0; i < uCtlCount; i++) | |
997 | { | |
998 | if (vSwp[i].hwnd == m_hFrame) | |
999 | memcpy(&m_vSwp, &vSwp[i], sizeof(SWP)); | |
1000 | else if (vSwp[i].hwnd == m_hVScroll) | |
1001 | memcpy(&m_vSwpVScroll, &vSwp[i], sizeof(SWP)); | |
1002 | else if (vSwp[i].hwnd == m_hHScroll) | |
1003 | memcpy(&m_vSwpVScroll, &vSwp[i], sizeof(SWP)); | |
1004 | else if (vSwp[i].hwnd == m_hTitleBar) | |
1005 | memcpy(&m_vSwpTitleBar, &vSwp[i], sizeof(SWP)); | |
1006 | } | |
1007 | ||
1008 | // | |
1009 | // Now set the size of the client | |
1010 | // | |
1011 | WinSetWindowPos( hClient | |
1012 | ,HWND_TOP | |
1013 | ,SV_CXSIZEBORDER/2 | |
1014 | ,(SV_CYSIZEBORDER/2) + m_vSwpHScroll.cy/2 | |
1015 | ,m_vSwp.cx - ((SV_CXSIZEBORDER + 1) + m_vSwpVScroll.cx) | |
1016 | ,m_vSwp.cy - ((SV_CYSIZEBORDER + 1) + m_vSwpTitleBar.cy + m_vSwpHScroll.cy/2) | |
1017 | ,SWP_SIZE | SWP_MOVE | |
1018 | ); | |
1019 | ||
1020 | // | |
1021 | // Set the client window's background, otherwise it is transparent! | |
1022 | // | |
1023 | return TRUE; | |
1024 | } // end of wxFrame::OS2Create | |
1025 | ||
1026 | // | |
1027 | // Default activation behaviour - set the focus for the first child | |
1028 | // subwindow found. | |
1029 | // | |
1030 | void wxFrame::OnActivate( | |
1031 | wxActivateEvent& rEvent | |
1032 | ) | |
1033 | { | |
1034 | for (wxWindowList::Node* pNode = GetChildren().GetFirst(); | |
1035 | pNode; | |
1036 | pNode = pNode->GetNext()) | |
1037 | { | |
1038 | // FIXME all this is totally bogus - we need to do the same as wxPanel, | |
1039 | // but how to do it without duplicating the code? | |
1040 | ||
1041 | // restore focus | |
1042 | wxWindow* pChild = pNode->GetData(); | |
1043 | ||
1044 | if (!pChild->IsTopLevel() | |
1045 | #if wxUSE_TOOLBAR | |
1046 | && !wxDynamicCast(pChild, wxToolBar) | |
1047 | #endif // wxUSE_TOOLBAR | |
1048 | #if wxUSE_STATUSBAR | |
1049 | && !wxDynamicCast(pChild, wxStatusBar) | |
1050 | #endif // wxUSE_STATUSBAR | |
1051 | ) | |
1052 | { | |
1053 | pChild->SetFocus(); | |
1054 | return; | |
1055 | } | |
1056 | } | |
1057 | } // end of wxFrame::OnActivate | |
1058 | ||
1059 | // ---------------------------------------------------------------------------- | |
1060 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
1061 | // from the client area, so the client area is what's really available for the | |
1062 | // frame contents | |
1063 | // ---------------------------------------------------------------------------- | |
1064 | ||
1065 | // Checks if there is a toolbar, and returns the first free client position | |
1066 | wxPoint wxFrame::GetClientAreaOrigin() const | |
1067 | { | |
1068 | wxPoint vPoint(0, 0); | |
1069 | ||
1070 | if (GetToolBar()) | |
1071 | { | |
1072 | int nWidth; | |
1073 | int nHeight; | |
1074 | ||
1075 | GetToolBar()->GetSize( &nWidth | |
1076 | ,&nHeight | |
1077 | ); | |
1078 | ||
1079 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
1080 | { | |
1081 | vPoint.x += nWidth; | |
1082 | } | |
1083 | else | |
1084 | { | |
1085 | // PM is backwards from windows | |
1086 | vPoint.y += nHeight; | |
1087 | } | |
1088 | } | |
1089 | return vPoint; | |
1090 | } // end of wxFrame::GetClientAreaOrigin | |
1091 | ||
1092 | // ---------------------------------------------------------------------------- | |
1093 | // tool/status bar stuff | |
1094 | // ---------------------------------------------------------------------------- | |
1095 | ||
1096 | #if wxUSE_TOOLBAR | |
1097 | ||
1098 | wxToolBar* wxFrame::CreateToolBar( | |
1099 | long lStyle | |
1100 | , wxWindowID vId | |
1101 | , const wxString& rName | |
1102 | ) | |
1103 | { | |
1104 | if (wxFrameBase::CreateToolBar( lStyle | |
1105 | ,vId | |
1106 | ,rName | |
1107 | )) | |
1108 | { | |
1109 | PositionToolBar(); | |
1110 | } | |
1111 | return m_frameToolBar; | |
1112 | } // end of wxFrame::CreateToolBar | |
1113 | ||
1114 | void wxFrame::PositionToolBar() | |
1115 | { | |
1116 | HWND hWndClient; | |
1117 | RECTL vRect; | |
1118 | ||
1119 | ::WinQueryWindowRect(GetHwnd(), &vRect); | |
1120 | ||
1121 | #if wxUSE_STATUSBAR | |
1122 | if (GetStatusBar()) | |
1123 | { | |
1124 | int nStatusX; | |
1125 | int nStatusY; | |
1126 | ||
1127 | GetStatusBar()->GetClientSize( &nStatusX | |
1128 | ,&nStatusY | |
1129 | ); | |
1130 | // PM is backwards from windows | |
1131 | vRect.yBottom += nStatusY; | |
1132 | } | |
1133 | #endif // wxUSE_STATUSBAR | |
1134 | ||
1135 | if ( GetToolBar() ) | |
1136 | { | |
1137 | int nToolbarWidth; | |
1138 | int nToolbarHeight; | |
1139 | ||
1140 | GetToolBar()->GetSize( &nToolbarWidth | |
1141 | ,&nToolbarHeight | |
1142 | ); | |
1143 | ||
1144 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
1145 | { | |
1146 | nToolbarHeight = vRect.yBottom; | |
1147 | } | |
1148 | else | |
1149 | { | |
1150 | nToolbarWidth = vRect.xRight; | |
1151 | } | |
1152 | ||
1153 | // | |
1154 | // Use the 'real' PM position here | |
1155 | // | |
1156 | GetToolBar()->SetSize( 0 | |
1157 | ,0 | |
1158 | ,nToolbarWidth | |
1159 | ,nToolbarHeight | |
1160 | ,wxSIZE_NO_ADJUSTMENTS | |
1161 | ); | |
1162 | } | |
1163 | } // end of wxFrame::PositionToolBar | |
1164 | #endif // wxUSE_TOOLBAR | |
1165 | ||
1166 | // ---------------------------------------------------------------------------- | |
1167 | // frame state (iconized/maximized/...) | |
1168 | // ---------------------------------------------------------------------------- | |
1169 | ||
1170 | // | |
1171 | // propagate our state change to all child frames: this allows us to emulate X | |
1172 | // Windows behaviour where child frames float independently of the parent one | |
1173 | // on the desktop, but are iconized/restored with it | |
1174 | // | |
1175 | void wxFrame::IconizeChildFrames( | |
1176 | bool bIconize | |
1177 | ) | |
1178 | { | |
1179 | for (wxWindowList::Node* pNode = GetChildren().GetFirst(); | |
1180 | pNode; | |
1181 | pNode = pNode->GetNext() ) | |
1182 | { | |
1183 | wxWindow* pWin = pNode->GetData(); | |
1184 | ||
1185 | if (pWin->IsKindOf(CLASSINFO(wxFrame)) ) | |
1186 | { | |
1187 | ((wxFrame *)pWin)->Iconize(bIconize); | |
1188 | } | |
1189 | } | |
1190 | } // end of wxFrame::IconizeChildFrames | |
1191 | ||
1192 | // =========================================================================== | |
1193 | // message processing | |
1194 | // =========================================================================== | |
1195 | ||
1196 | // --------------------------------------------------------------------------- | |
1197 | // preprocessing | |
1198 | // --------------------------------------------------------------------------- | |
1199 | bool wxFrame::OS2TranslateMessage( | |
1200 | WXMSG* pMsg | |
1201 | ) | |
1202 | { | |
1203 | // | |
1204 | // try the menu bar accels | |
1205 | // | |
1206 | wxMenuBar* pMenuBar = GetMenuBar(); | |
1207 | ||
1208 | if (!pMenuBar ) | |
1209 | return FALSE; | |
1210 | ||
1211 | const wxAcceleratorTable& rAcceleratorTable = pMenuBar->GetAccelTable(); | |
1212 | return rAcceleratorTable.Translate(m_hFrame, pMsg); | |
1213 | } // end of wxFrame::OS2TranslateMessage | |
1214 | ||
1215 | // --------------------------------------------------------------------------- | |
1216 | // our private (non virtual) message handlers | |
1217 | // --------------------------------------------------------------------------- | |
1218 | bool wxFrame::HandlePaint() | |
1219 | { | |
1220 | RECTL vRect; | |
1221 | ||
1222 | if (::WinQueryUpdateRect(m_hFrame, &vRect)) | |
1223 | { | |
1224 | if (m_bIconized) | |
1225 | { | |
1226 | // | |
1227 | // Icons in PM are the same as "pointers" | |
1228 | // | |
1229 | HPOINTER hIcon; | |
1230 | ||
1231 | if (m_icon.Ok()) | |
1232 | hIcon = (HPOINTER)::WinSendMsg(m_hFrame, WM_QUERYICON, 0L, 0L); | |
1233 | else | |
1234 | hIcon = (HPOINTER)m_hDefaultIcon; | |
1235 | ||
1236 | // | |
1237 | // Hold a pointer to the dc so long as the OnPaint() message | |
1238 | // is being processed | |
1239 | // | |
1240 | RECTL vRect2; | |
1241 | HPS hPs = ::WinBeginPaint(m_hFrame, NULLHANDLE, &vRect2); | |
1242 | ||
1243 | // | |
1244 | // Erase background before painting or we get white background | |
1245 | // | |
1246 | OS2DefWindowProc(WM_ERASEBACKGROUND, (MPARAM)hPs, (MPARAM)&vRect2); | |
1247 | ||
1248 | if (hIcon) | |
1249 | { | |
1250 | HWND hWndClient; | |
1251 | RECTL vRect3; | |
1252 | ||
1253 | ::WinQueryWindowRect(GetHwnd(), &vRect3); | |
1254 | ||
1255 | static const int nIconWidth = 32; | |
1256 | static const int nIconHeight = 32; | |
1257 | int nIconX = (int)((vRect3.xRight - nIconWidth)/2); | |
1258 | int nIconY = (int)((vRect3.yBottom + nIconHeight)/2); | |
1259 | ||
1260 | ::WinDrawPointer(hPs, nIconX, nIconY, hIcon, DP_NORMAL); | |
1261 | } | |
1262 | ::WinEndPaint(hPs); | |
1263 | return TRUE; | |
1264 | } | |
1265 | else | |
1266 | { | |
1267 | HPS hPS; | |
1268 | RECTL vRect; | |
1269 | ||
1270 | hPS = WinBeginPaint(GetHwnd(), 0L, &vRect); | |
1271 | WinFillRect(hPS, &vRect, SYSCLR_WINDOW); | |
1272 | WinEndPaint(hPS); | |
1273 | ||
1274 | return wxWindow::HandlePaint(); | |
1275 | } | |
1276 | } | |
1277 | else | |
1278 | { | |
1279 | // nothing to paint - processed | |
1280 | return TRUE; | |
1281 | } | |
1282 | return FALSE; | |
1283 | } // end of wxFrame::HandlePaint | |
1284 | ||
1285 | bool wxFrame::HandleSize( | |
1286 | int nX | |
1287 | , int nY | |
1288 | , WXUINT nId | |
1289 | ) | |
1290 | { | |
1291 | bool bProcessed = FALSE; | |
1292 | ||
1293 | switch (nId) | |
1294 | { | |
1295 | case kSizeNormal: | |
1296 | // | |
1297 | // Only do it it if we were iconized before, otherwise resizing the | |
1298 | // parent frame has a curious side effect of bringing it under it's | |
1299 | // children | |
1300 | if (!m_bIconized ) | |
1301 | break; | |
1302 | ||
1303 | // | |
1304 | // restore all child frames too | |
1305 | // | |
1306 | IconizeChildFrames(FALSE); | |
1307 | ||
1308 | // | |
1309 | // fall through | |
1310 | // | |
1311 | ||
1312 | case kSizeMax: | |
1313 | m_bIconized = FALSE; | |
1314 | break; | |
1315 | ||
1316 | case kSizeMin: | |
1317 | // | |
1318 | // Iconize all child frames too | |
1319 | // | |
1320 | IconizeChildFrames(TRUE); | |
1321 | m_bIconized = TRUE; | |
1322 | break; | |
1323 | } | |
1324 | ||
1325 | if (!m_bIconized) | |
1326 | { | |
1327 | // | |
1328 | // forward WM_SIZE to status bar control | |
1329 | // | |
1330 | #if wxUSE_NATIVE_STATUSBAR | |
1331 | if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) | |
1332 | { | |
1333 | wxSizeEvent vEvent( wxSize( nX | |
1334 | ,nY | |
1335 | ) | |
1336 | ,m_frameStatusBar->GetId() | |
1337 | ); | |
1338 | ||
1339 | vEvent.SetEventObject(m_frameStatusBar); | |
1340 | m_frameStatusBar->OnSize(vEvent); | |
1341 | } | |
1342 | #endif // wxUSE_NATIVE_STATUSBAR | |
1343 | ||
1344 | PositionStatusBar(); | |
1345 | PositionToolBar(); | |
1346 | wxSizeEvent vEvent( wxSize( nX | |
1347 | ,nY | |
1348 | ) | |
1349 | ,m_windowId | |
1350 | ); | |
1351 | ||
1352 | vEvent.SetEventObject(this); | |
1353 | bProcessed = GetEventHandler()->ProcessEvent(vEvent); | |
1354 | } | |
1355 | return bProcessed; | |
1356 | } // end of wxFrame::HandleSize | |
1357 | ||
1358 | bool wxFrame::HandleCommand( | |
1359 | WXWORD nId | |
1360 | , WXWORD nCmd | |
1361 | , WXHWND hControl | |
1362 | ) | |
1363 | { | |
1364 | if (hControl) | |
1365 | { | |
1366 | // | |
1367 | // In case it's e.g. a toolbar. | |
1368 | // | |
1369 | wxWindow* pWin = wxFindWinFromHandle(hControl); | |
1370 | ||
1371 | if (pWin) | |
1372 | return pWin->OS2Command( nCmd | |
1373 | ,nId | |
1374 | ); | |
1375 | } | |
1376 | ||
1377 | // | |
1378 | // Handle here commands from menus and accelerators | |
1379 | // | |
1380 | if (nCmd == 0 || nCmd == 1) | |
1381 | { | |
1382 | if (wxCurrentPopupMenu) | |
1383 | { | |
1384 | wxMenu* pPopupMenu = wxCurrentPopupMenu; | |
1385 | ||
1386 | wxCurrentPopupMenu = NULL; | |
1387 | ||
1388 | return pPopupMenu->OS2Command( nCmd | |
1389 | ,nId | |
1390 | ); | |
1391 | } | |
1392 | ||
1393 | if (ProcessCommand(nId)) | |
1394 | { | |
1395 | return TRUE; | |
1396 | } | |
1397 | } | |
1398 | return FALSE; | |
1399 | } // end of wxFrame::HandleCommand | |
1400 | ||
1401 | bool wxFrame::HandleMenuSelect( | |
1402 | WXWORD nItem | |
1403 | , WXWORD nFlags | |
1404 | , WXHMENU hMenu | |
1405 | ) | |
1406 | { | |
1407 | int nMenuItem; | |
1408 | ||
1409 | if (nFlags == 0xFFFF && hMenu == 0) | |
1410 | { | |
1411 | // | |
1412 | // Menu was removed from screen | |
1413 | // | |
1414 | nMenuItem = -1; | |
1415 | } | |
1416 | else if (!(nFlags & MIS_SUBMENU) && !(nFlags & MIS_SEPARATOR)) | |
1417 | { | |
1418 | nMenuItem = nItem; | |
1419 | } | |
1420 | else | |
1421 | { | |
1422 | // | |
1423 | // Don't give hints for separators (doesn't make sense) nor for the | |
1424 | // items opening popup menus (they don't have them anyhow) | |
1425 | // | |
1426 | return FALSE; | |
1427 | } | |
1428 | wxMenuEvent vEvent(wxEVT_MENU_HIGHLIGHT, nMenuItem); | |
1429 | ||
1430 | vEvent.SetEventObject(this); | |
1431 | return GetEventHandler()->ProcessEvent(vEvent); | |
1432 | } // end of wxFrame::HandleMenuSelect | |
1433 | ||
1434 | // --------------------------------------------------------------------------- | |
1435 | // the window proc for wxFrame | |
1436 | // --------------------------------------------------------------------------- | |
1437 | ||
1438 | MRESULT wxFrame::OS2WindowProc( | |
1439 | WXUINT uMessage | |
1440 | , WXWPARAM wParam | |
1441 | , WXLPARAM lParam | |
1442 | ) | |
1443 | { | |
1444 | MRESULT mRc = 0L; | |
1445 | bool bProcessed = FALSE; | |
1446 | ||
1447 | switch (uMessage) | |
1448 | { | |
1449 | case WM_CLOSE: | |
1450 | // | |
1451 | // If we can't close, tell the system that we processed the | |
1452 | // message - otherwise it would close us | |
1453 | // | |
1454 | bProcessed = !Close(); | |
1455 | break; | |
1456 | ||
1457 | case WM_COMMAND: | |
1458 | { | |
1459 | WORD wId; | |
1460 | WORD wCmd; | |
1461 | WXHWND hWnd; | |
1462 | ||
1463 | UnpackCommand( (WXWPARAM)wParam | |
1464 | ,(WXLPARAM)lParam | |
1465 | ,&wId | |
1466 | ,&hWnd | |
1467 | ,&wCmd | |
1468 | ); | |
1469 | bProcessed = HandleCommand( wId | |
1470 | ,wCmd | |
1471 | ,(WXHWND)hWnd | |
1472 | ); | |
1473 | } | |
1474 | break; | |
1475 | ||
1476 | case WM_MENUSELECT: | |
1477 | { | |
1478 | WXWORD wItem; | |
1479 | WXWORD wFlags; | |
1480 | WXHMENU hMenu; | |
1481 | ||
1482 | UnpackMenuSelect( wParam | |
1483 | ,lParam | |
1484 | ,&wItem | |
1485 | ,&wFlags | |
1486 | ,&hMenu | |
1487 | ); | |
1488 | bProcessed = HandleMenuSelect( wItem | |
1489 | ,wFlags | |
1490 | ,hMenu | |
1491 | ); | |
1492 | } | |
1493 | break; | |
1494 | ||
1495 | case WM_PAINT: | |
1496 | bProcessed = HandlePaint(); | |
1497 | break; | |
1498 | ||
1499 | case WM_ERASEBACKGROUND: | |
1500 | // | |
1501 | // Return TRUE to request PM to paint the window background | |
1502 | // in SYSCLR_WINDOW. | |
1503 | // | |
1504 | bProcessed = TRUE; | |
1505 | mRc = (MRESULT)(TRUE); | |
1506 | break; | |
1507 | ||
1508 | case CM_QUERYDRAGIMAGE: | |
1509 | { | |
1510 | HPOINTER hIcon; | |
1511 | ||
1512 | if (m_icon.Ok()) | |
1513 | hIcon = (HPOINTER)::WinSendMsg(m_hFrame, WM_QUERYICON, 0L, 0L); | |
1514 | else | |
1515 | hIcon = (HPOINTER)m_hDefaultIcon; | |
1516 | mRc = (MRESULT)hIcon; | |
1517 | bProcessed = mRc != 0; | |
1518 | } | |
1519 | break; | |
1520 | ||
1521 | case WM_SIZE: | |
1522 | bProcessed = HandleSize(LOWORD(lParam), HIWORD(lParam), (WXUINT)wParam); | |
1523 | break; | |
1524 | } | |
1525 | ||
1526 | if (!bProcessed ) | |
1527 | mRc = wxWindow::OS2WindowProc( uMessage | |
1528 | ,wParam | |
1529 | ,lParam | |
1530 | ); | |
1531 | return (MRESULT)0; | |
1532 | } // wxFrame::OS2WindowProc | |
1533 |