]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
3 | // Purpose: wxFrame | |
f0a56ab0 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
29435d81 | 6 | // Created: 10/27/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
f0a56ab0 | 8 | // Copyright: (c) David Webster |
0e320a79 DW |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
21802234 DW |
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" | |
f38374d0 DW |
27 | |
28 | #if wxUSE_STATUSBAR | |
29 | #include "wx/statusbr.h" | |
ea51d98d | 30 | #include "wx/generic/statusbr.h" |
f38374d0 DW |
31 | #endif // wxUSE_STATUSBAR |
32 | ||
33 | #if wxUSE_TOOLBAR | |
34 | #include "wx/toolbar.h" | |
35 | #endif // wxUSE_TOOLBAR | |
36 | ||
0e320a79 | 37 | #include "wx/menuitem.h" |
21802234 | 38 | #include "wx/log.h" |
0e320a79 | 39 | |
f38374d0 DW |
40 | // ---------------------------------------------------------------------------- |
41 | // globals | |
42 | // ---------------------------------------------------------------------------- | |
43 | ||
21802234 DW |
44 | extern wxWindowList wxModelessWindows; |
45 | extern wxList WXDLLEXPORT wxPendingDelete; | |
46 | extern wxChar wxFrameClassName[]; | |
47 | extern wxMenu *wxCurrentPopupMenu; | |
0e320a79 | 48 | |
f38374d0 DW |
49 | // ---------------------------------------------------------------------------- |
50 | // event tables | |
51 | // ---------------------------------------------------------------------------- | |
52 | ||
f38374d0 DW |
53 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
54 | EVT_ACTIVATE(wxFrame::OnActivate) | |
55 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
0e320a79 DW |
56 | END_EVENT_TABLE() |
57 | ||
58 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) | |
0e320a79 | 59 | |
f38374d0 DW |
60 | // ============================================================================ |
61 | // implementation | |
62 | // ============================================================================ | |
0e320a79 | 63 | |
f38374d0 DW |
64 | // ---------------------------------------------------------------------------- |
65 | // static class members | |
66 | // ---------------------------------------------------------------------------- | |
0e320a79 | 67 | |
f38374d0 DW |
68 | #if wxUSE_NATIVE_STATUSBAR |
69 | bool wxFrame::m_useNativeStatusBar = TRUE; | |
70 | #else | |
71 | bool wxFrame::m_useNativeStatusBar = FALSE; | |
72 | #endif | |
0e320a79 | 73 | |
f38374d0 DW |
74 | // ---------------------------------------------------------------------------- |
75 | // creation/destruction | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
78 | void wxFrame::Init() | |
0e320a79 | 79 | { |
f38374d0 DW |
80 | m_iconized = FALSE; |
81 | ||
21802234 DW |
82 | #if wxUSE_TOOLTIPS |
83 | m_hwndToolTip = 0; | |
84 | #endif | |
ea51d98d DW |
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 | } // end of wxFrame::Init | |
94 | ||
95 | bool wxFrame::Create( | |
96 | wxWindow* pParent | |
97 | , wxWindowID vId | |
98 | , const wxString& rsTitle | |
99 | , const wxPoint& rPos | |
100 | , const wxSize& rSize | |
101 | , long lStyle | |
102 | , const wxString& rsName | |
103 | ) | |
f38374d0 | 104 | { |
ea51d98d DW |
105 | int nX = rPos.x; |
106 | int nY = rPos.y; | |
107 | int nWidth = rSize.x; | |
108 | int nHeight = rSize.y; | |
109 | SWP vSwp; | |
110 | ||
111 | SetName(rsName); | |
112 | m_windowStyle = lStyle; | |
113 | m_frameMenuBar = NULL; | |
114 | m_frameToolBar = NULL; | |
115 | m_frameStatusBar = NULL; | |
116 | ||
117 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
118 | ||
119 | if (vId > -1 ) | |
120 | m_windowId = vId; | |
121 | else | |
122 | m_windowId = (int)NewControlId(); | |
123 | ||
124 | if (pParent) | |
125 | pParent->AddChild(this); | |
126 | ||
127 | m_bIconized = FALSE; | |
128 | ||
129 | // | |
130 | // We pass NULL as parent to MSWCreate because frames with parents behave | |
131 | // very strangely under Win95 shell. | |
132 | // Alteration by JACS: keep normal Windows behaviour (float on top of parent) | |
133 | // with this style. | |
134 | // | |
135 | if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0) | |
136 | pParent = NULL; | |
137 | ||
138 | if (!pParent) | |
139 | wxTopLevelWindows.Append(this); | |
140 | ||
141 | OS2Create( m_windowId | |
142 | ,pParent | |
143 | ,wxFrameClassName | |
144 | ,this | |
145 | ,rsTitle | |
146 | ,nX | |
147 | ,nY | |
148 | ,nWidth | |
149 | ,nHeight | |
150 | ,lStyle | |
151 | ); | |
152 | ||
153 | wxModelessWindows.Append(this); | |
154 | return TRUE; | |
155 | } // end of wxFrame::Create | |
0e320a79 DW |
156 | |
157 | wxFrame::~wxFrame() | |
158 | { | |
ea51d98d DW |
159 | m_isBeingDeleted = TRUE; |
160 | wxTopLevelWindows.DeleteObject(this); | |
0e320a79 | 161 | |
ea51d98d | 162 | DeleteAllBars(); |
29435d81 | 163 | |
ea51d98d DW |
164 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) |
165 | { | |
166 | wxTheApp->SetTopWindow(NULL); | |
0e320a79 | 167 | |
ea51d98d DW |
168 | if (wxTheApp->GetExitOnFrameDelete()) |
169 | { | |
170 | ::WinPostMsg(m_hwnd, WM_QUIT, 0, 0); | |
171 | } | |
172 | } | |
173 | wxModelessWindows.DeleteObject(this); | |
174 | ||
175 | // | |
176 | // For some reason, wxWindows can activate another task altogether | |
177 | // when a frame is destroyed after a modal dialog has been invoked. | |
178 | // Try to bring the parent to the top. | |
179 | // | |
180 | // MT:Only do this if this frame is currently the active window, else weird | |
181 | // things start to happen. | |
182 | // | |
183 | if (wxGetActiveWindow() == this) | |
0e320a79 | 184 | { |
ea51d98d DW |
185 | if (GetParent() && GetParent()->GetHWND()) |
186 | { | |
187 | ::WinQueryWindowPos( (HWND) GetParent()->GetHWND() | |
188 | ,&vSwp | |
189 | ); | |
190 | ::WinSetWindowPos( (HWND) GetParent()->GetHWND() | |
191 | ,HWND_TOP | |
192 | ,vSwp.x | |
193 | ,vSwp.y | |
194 | ,vSwp.cx | |
195 | ,vSwp,cy | |
196 | ,SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW | |
197 | ); | |
198 | } | |
0e320a79 | 199 | } |
ea51d98d | 200 | } // end of wxFrame::~wxFrame |
0e320a79 | 201 | |
ea51d98d | 202 | // |
0e320a79 | 203 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
ea51d98d | 204 | // |
21802234 | 205 | void wxFrame::DoGetClientSize(int *x, int *y) const |
0e320a79 | 206 | { |
29435d81 DW |
207 | // TODO: |
208 | /* | |
21802234 | 209 | RECT rect; |
29435d81 | 210 | ::GetClientRect(GetHwnd(), &rect); |
21802234 | 211 | |
f38374d0 | 212 | #if wxUSE_STATUSBAR |
21802234 DW |
213 | if ( GetStatusBar() ) |
214 | { | |
215 | int statusX, statusY; | |
216 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
29435d81 | 217 | rect.bottom -= statusY; |
21802234 | 218 | } |
f38374d0 | 219 | #endif // wxUSE_STATUSBAR |
21802234 DW |
220 | |
221 | wxPoint pt(GetClientAreaOrigin()); | |
21802234 DW |
222 | rect.bottom -= pt.y; |
223 | rect.right -= pt.x; | |
224 | ||
225 | if ( x ) | |
226 | *x = rect.right; | |
227 | if ( y ) | |
228 | *y = rect.bottom; | |
229 | */ | |
0e320a79 DW |
230 | } |
231 | ||
232 | // Set the client size (i.e. leave the calculation of borders etc. | |
233 | // to wxWindows) | |
21802234 | 234 | void wxFrame::DoSetClientSize(int width, int height) |
0e320a79 | 235 | { |
21802234 | 236 | HWND hWnd = GetHwnd(); |
0e320a79 | 237 | |
29435d81 DW |
238 | // TODO: |
239 | /* | |
21802234 | 240 | RECT rect; |
29435d81 | 241 | ::GetClientRect(hWnd, &rect); |
21802234 DW |
242 | |
243 | RECT rect2; | |
29435d81 | 244 | GetWindowRect(hWnd, &rect2); |
21802234 DW |
245 | |
246 | // Find the difference between the entire window (title bar and all) | |
247 | // and the client area; add this to the new client size to move the | |
248 | // window | |
21802234 DW |
249 | int actual_width = rect2.right - rect2.left - rect.right + width; |
250 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
29435d81 | 251 | |
f38374d0 | 252 | #if wxUSE_STATUSBAR |
21802234 DW |
253 | if ( GetStatusBar() ) |
254 | { | |
255 | int statusX, statusY; | |
256 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
29435d81 | 257 | actual_height += statusY; |
21802234 | 258 | } |
f38374d0 | 259 | #endif // wxUSE_STATUSBAR |
29435d81 | 260 | |
21802234 DW |
261 | wxPoint pt(GetClientAreaOrigin()); |
262 | actual_width += pt.y; | |
263 | actual_height += pt.x; | |
264 | ||
265 | POINT point; | |
21802234 DW |
266 | point.x = rect2.left; |
267 | point.y = rect2.top; | |
268 | ||
269 | MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE); | |
29435d81 | 270 | |
21802234 DW |
271 | wxSizeEvent event(wxSize(width, height), m_windowId); |
272 | event.SetEventObject( this ); | |
273 | GetEventHandler()->ProcessEvent(event); | |
29435d81 | 274 | */ |
0e320a79 DW |
275 | } |
276 | ||
21802234 | 277 | void wxFrame::DoGetSize(int *width, int *height) const |
0e320a79 | 278 | { |
29435d81 DW |
279 | // TODO: |
280 | /* | |
21802234 | 281 | RECT rect; |
29435d81 DW |
282 | GetWindowRect(GetHwnd(), &rect); |
283 | *width = rect.right - rect.left; | |
284 | *height = rect.bottom - rect.top; | |
285 | */ | |
0e320a79 DW |
286 | } |
287 | ||
21802234 | 288 | void wxFrame::DoGetPosition(int *x, int *y) const |
0e320a79 | 289 | { |
29435d81 DW |
290 | // TODO: |
291 | /* | |
21802234 | 292 | RECT rect; |
29435d81 DW |
293 | GetWindowRect(GetHwnd(), &rect); |
294 | POINT point; | |
295 | point.x = rect.left; | |
296 | point.y = rect.top; | |
21802234 DW |
297 | |
298 | *x = point.x; | |
299 | *y = point.y; | |
29435d81 | 300 | */ |
0e320a79 DW |
301 | } |
302 | ||
f38374d0 DW |
303 | // ---------------------------------------------------------------------------- |
304 | // variations around ::ShowWindow() | |
305 | // ---------------------------------------------------------------------------- | |
306 | ||
307 | void wxFrame::DoShowWindow(int nShowCmd) | |
0e320a79 | 308 | { |
29435d81 | 309 | // TODO: |
21802234 | 310 | /* |
f38374d0 | 311 | ::ShowWindow(GetHwnd(), nShowCmd); |
21802234 | 312 | |
f38374d0 | 313 | m_iconized = nShowCmd == SW_MINIMIZE; |
29435d81 | 314 | */ |
0e320a79 DW |
315 | } |
316 | ||
f38374d0 | 317 | bool wxFrame::Show(bool show) |
0e320a79 | 318 | { |
29435d81 DW |
319 | // TODO: |
320 | /* | |
f38374d0 | 321 | DoShowWindow(show ? SW_SHOW : SW_HIDE); |
21802234 | 322 | |
f38374d0 DW |
323 | if ( show ) |
324 | { | |
325 | ::BringWindowToTop(GetHwnd()); | |
326 | ||
327 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); | |
328 | event.SetEventObject( this ); | |
329 | GetEventHandler()->ProcessEvent(event); | |
330 | } | |
331 | else | |
332 | { | |
333 | // Try to highlight the correct window (the parent) | |
334 | if ( GetParent() ) | |
335 | { | |
336 | HWND hWndParent = GetHwndOf(GetParent()); | |
337 | if (hWndParent) | |
338 | ::BringWindowToTop(hWndParent); | |
339 | } | |
340 | } | |
29435d81 | 341 | */ |
f38374d0 DW |
342 | return TRUE; |
343 | } | |
344 | ||
345 | void wxFrame::Iconize(bool iconize) | |
346 | { | |
347 | // DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); | |
0e320a79 DW |
348 | } |
349 | ||
0e320a79 DW |
350 | void wxFrame::Maximize(bool maximize) |
351 | { | |
f38374d0 DW |
352 | // DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); |
353 | } | |
354 | ||
355 | void wxFrame::Restore() | |
356 | { | |
357 | // DoShowWindow(SW_RESTORE); | |
0e320a79 DW |
358 | } |
359 | ||
360 | bool wxFrame::IsIconized() const | |
361 | { | |
29435d81 DW |
362 | // TODO: |
363 | /* | |
364 | ((wxFrame *)this)->m_iconized = (::IsIconic(GetHwnd()) != 0); | |
21802234 | 365 | return m_iconized; |
29435d81 | 366 | */ |
f38374d0 | 367 | return FALSE; |
0e320a79 DW |
368 | } |
369 | ||
21802234 DW |
370 | // Is it maximized? |
371 | bool wxFrame::IsMaximized() const | |
0e320a79 | 372 | { |
f38374d0 DW |
373 | // TODO: |
374 | /* | |
375 | return (::IsZoomed(GetHwnd()) != 0); | |
376 | */ | |
377 | return FALSE; | |
0e320a79 DW |
378 | } |
379 | ||
380 | void wxFrame::SetIcon(const wxIcon& icon) | |
381 | { | |
f38374d0 DW |
382 | wxFrameBase::SetIcon(icon); |
383 | ||
29435d81 DW |
384 | // TODO: |
385 | /* | |
f38374d0 DW |
386 | if ( m_icon.Ok() ) |
387 | { | |
388 | SendMessage(GetHwnd(), WM_SETICON, | |
389 | (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON()); | |
390 | } | |
29435d81 | 391 | */ |
0e320a79 DW |
392 | } |
393 | ||
21802234 | 394 | #if wxUSE_STATUSBAR |
f38374d0 DW |
395 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, |
396 | long style, | |
397 | wxWindowID id, | |
398 | const wxString& name) | |
0e320a79 DW |
399 | { |
400 | wxStatusBar *statusBar = NULL; | |
0e320a79 | 401 | |
f38374d0 | 402 | statusBar = wxFrameBase::OnCreateStatusBar(number, style, id, name); |
0e320a79 | 403 | |
f38374d0 | 404 | return statusBar; |
0e320a79 DW |
405 | } |
406 | ||
407 | void wxFrame::PositionStatusBar() | |
408 | { | |
f38374d0 DW |
409 | // TODO: |
410 | /* | |
411 | // native status bar positions itself | |
412 | if ( m_frameStatusBar ) | |
413 | { | |
414 | int w, h; | |
415 | GetClientSize(&w, &h); | |
416 | int sw, sh; | |
417 | m_frameStatusBar->GetSize(&sw, &sh); | |
418 | ||
419 | // Since we wish the status bar to be directly under the client area, | |
420 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
421 | m_frameStatusBar->SetSize(0, h, w, sh); | |
422 | } | |
423 | */ | |
0e320a79 | 424 | } |
21802234 | 425 | #endif // wxUSE_STATUSBAR |
0e320a79 | 426 | |
21802234 | 427 | void wxFrame::DetachMenuBar() |
0e320a79 | 428 | { |
21802234 | 429 | if (m_frameMenuBar) |
0e320a79 | 430 | { |
29435d81 | 431 | m_frameMenuBar->Detach(); |
0e320a79 | 432 | m_frameMenuBar = NULL; |
21802234 DW |
433 | } |
434 | } | |
435 | ||
436 | void wxFrame::SetMenuBar(wxMenuBar *menu_bar) | |
437 | { | |
438 | if (!menu_bar) | |
439 | { | |
440 | DetachMenuBar(); | |
0e320a79 DW |
441 | return; |
442 | } | |
c3d43472 | 443 | |
29435d81 | 444 | wxCHECK_RET( !menu_bar->GetFrame(), wxT("this menubar is already attached") ); |
0e320a79 | 445 | |
21802234 DW |
446 | if (m_frameMenuBar) |
447 | delete m_frameMenuBar; | |
448 | ||
29435d81 | 449 | m_hMenu = menu_bar->Create(); |
21802234 DW |
450 | |
451 | if ( !m_hMenu ) | |
452 | return; | |
453 | ||
454 | InternalSetMenuBar(); | |
455 | ||
456 | m_frameMenuBar = menu_bar; | |
29435d81 | 457 | menu_bar->Attach(this); |
0e320a79 DW |
458 | } |
459 | ||
21802234 | 460 | void wxFrame::InternalSetMenuBar() |
0e320a79 | 461 | { |
21802234 | 462 | // TODO: |
29435d81 DW |
463 | /* |
464 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) | |
0e320a79 | 465 | { |
21802234 | 466 | wxLogLastError("SetMenu"); |
0e320a79 | 467 | } |
21802234 | 468 | */ |
0e320a79 DW |
469 | } |
470 | ||
471 | // Responds to colour changes, and passes event on to children. | |
472 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
473 | { | |
f38374d0 DW |
474 | // TODO: |
475 | /* | |
0e320a79 DW |
476 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); |
477 | Refresh(); | |
478 | ||
479 | if ( m_frameStatusBar ) | |
480 | { | |
481 | wxSysColourChangedEvent event2; | |
482 | event2.SetEventObject( m_frameStatusBar ); | |
21802234 | 483 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); |
0e320a79 DW |
484 | } |
485 | ||
486 | // Propagate the event to the non-top-level children | |
487 | wxWindow::OnSysColourChanged(event); | |
f38374d0 | 488 | */ |
0e320a79 DW |
489 | } |
490 | ||
21802234 DW |
491 | /* |
492 | * Frame window | |
493 | * | |
494 | */ | |
495 | ||
496 | bool wxFrame::OS2Create(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title, | |
497 | int x, int y, int width, int height, long style) | |
498 | ||
499 | { | |
500 | m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); | |
501 | ||
502 | // If child windows aren't properly drawn initially, WS_CLIPCHILDREN | |
503 | // could be the culprit. But without it, you can get a lot of flicker. | |
29435d81 | 504 | |
21802234 DW |
505 | // TODO: |
506 | /* | |
507 | DWORD msflags = 0; | |
508 | if ((style & wxCAPTION) == wxCAPTION) | |
509 | msflags = WS_OVERLAPPED; | |
510 | else | |
511 | msflags = WS_POPUP; | |
512 | ||
513 | if (style & wxMINIMIZE_BOX) | |
514 | msflags |= WS_MINIMIZEBOX; | |
515 | if (style & wxMAXIMIZE_BOX) | |
516 | msflags |= WS_MAXIMIZEBOX; | |
517 | if (style & wxTHICK_FRAME) | |
518 | msflags |= WS_THICKFRAME; | |
519 | if (style & wxSYSTEM_MENU) | |
520 | msflags |= WS_SYSMENU; | |
521 | if ((style & wxMINIMIZE) || (style & wxICONIZE)) | |
522 | msflags |= WS_MINIMIZE; | |
523 | if (style & wxMAXIMIZE) | |
524 | msflags |= WS_MAXIMIZE; | |
525 | if (style & wxCAPTION) | |
526 | msflags |= WS_CAPTION; | |
527 | if (style & wxCLIP_CHILDREN) | |
528 | msflags |= WS_CLIPCHILDREN; | |
529 | ||
530 | // Keep this in wxFrame because it saves recoding this function | |
531 | // in wxTinyFrame | |
532 | #if wxUSE_ITSY_BITSY | |
533 | if (style & wxTINY_CAPTION_VERT) | |
534 | msflags |= IBS_VERTCAPTION; | |
535 | if (style & wxTINY_CAPTION_HORIZ) | |
536 | msflags |= IBS_HORZCAPTION; | |
537 | #else | |
538 | if (style & wxTINY_CAPTION_VERT) | |
539 | msflags |= WS_CAPTION; | |
540 | if (style & wxTINY_CAPTION_HORIZ) | |
541 | msflags |= WS_CAPTION; | |
542 | #endif | |
543 | if ((style & wxTHICK_FRAME) == 0) | |
544 | msflags |= WS_BORDER; | |
545 | ||
546 | WXDWORD extendedStyle = MakeExtendedStyle(style); | |
547 | ||
548 | #if !defined(__WIN16__) && !defined(__SC__) | |
549 | if (style & wxFRAME_TOOL_WINDOW) | |
550 | extendedStyle |= WS_EX_TOOLWINDOW; | |
551 | #endif | |
552 | ||
553 | if (style & wxSTAY_ON_TOP) | |
554 | extendedStyle |= WS_EX_TOPMOST; | |
555 | ||
556 | m_iconized = FALSE; | |
29435d81 | 557 | if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height, |
21802234 DW |
558 | msflags, NULL, extendedStyle) ) |
559 | return FALSE; | |
560 | ||
561 | // Seems to be necessary if we use WS_POPUP | |
562 | // style instead of WS_OVERLAPPED | |
563 | if (width > -1 && height > -1) | |
564 | ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height)); | |
29435d81 | 565 | */ |
f38374d0 | 566 | return TRUE; |
0e320a79 DW |
567 | } |
568 | ||
569 | // Default activation behaviour - set the focus for the first child | |
570 | // subwindow found. | |
571 | void wxFrame::OnActivate(wxActivateEvent& event) | |
572 | { | |
21802234 DW |
573 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
574 | node; | |
575 | node = node->GetNext() ) | |
0e320a79 | 576 | { |
21802234 DW |
577 | // FIXME all this is totally bogus - we need to do the same as wxPanel, |
578 | // but how to do it without duplicating the code? | |
579 | ||
580 | // restore focus | |
581 | wxWindow *child = node->GetData(); | |
582 | ||
583 | if ( !child->IsTopLevel() | |
584 | #if wxUSE_TOOLBAR | |
585 | && !wxDynamicCast(child, wxToolBar) | |
586 | #endif // wxUSE_TOOLBAR | |
587 | #if wxUSE_STATUSBAR | |
588 | && !wxDynamicCast(child, wxStatusBar) | |
589 | #endif // wxUSE_STATUSBAR | |
590 | ) | |
591 | { | |
592 | child->SetFocus(); | |
593 | return; | |
594 | } | |
0e320a79 | 595 | } |
0e320a79 DW |
596 | } |
597 | ||
f38374d0 DW |
598 | // ---------------------------------------------------------------------------- |
599 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
600 | // from the client area, so the client area is what's really available for the | |
601 | // frame contents | |
602 | // ---------------------------------------------------------------------------- | |
0e320a79 DW |
603 | |
604 | // Checks if there is a toolbar, and returns the first free client position | |
605 | wxPoint wxFrame::GetClientAreaOrigin() const | |
606 | { | |
607 | wxPoint pt(0, 0); | |
608 | if (GetToolBar()) | |
609 | { | |
610 | int w, h; | |
611 | GetToolBar()->GetSize(& w, & h); | |
612 | ||
613 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
614 | { | |
615 | pt.x += w; | |
616 | } | |
617 | else | |
618 | { | |
619 | pt.y += h; | |
620 | } | |
621 | } | |
622 | return pt; | |
623 | } | |
624 | ||
e6ebb514 | 625 | void wxFrame::DoScreenToClient(int *x, int *y) const |
0e320a79 | 626 | { |
29435d81 | 627 | wxWindow::DoScreenToClient(x, y); |
0e320a79 DW |
628 | |
629 | // We may be faking the client origin. | |
630 | // So a window that's really at (0, 30) may appear | |
631 | // (to wxWin apps) to be at (0, 0). | |
632 | wxPoint pt(GetClientAreaOrigin()); | |
633 | *x -= pt.x; | |
634 | *y -= pt.y; | |
635 | } | |
636 | ||
e6ebb514 | 637 | void wxFrame::DoClientToScreen(int *x, int *y) const |
0e320a79 DW |
638 | { |
639 | // We may be faking the client origin. | |
640 | // So a window that's really at (0, 30) may appear | |
641 | // (to wxWin apps) to be at (0, 0). | |
642 | wxPoint pt1(GetClientAreaOrigin()); | |
643 | *x += pt1.x; | |
644 | *y += pt1.y; | |
645 | ||
e6ebb514 | 646 | wxWindow::DoClientToScreen(x, y); |
0e320a79 DW |
647 | } |
648 | ||
f38374d0 DW |
649 | // ---------------------------------------------------------------------------- |
650 | // tool/status bar stuff | |
651 | // ---------------------------------------------------------------------------- | |
652 | ||
21802234 | 653 | #if wxUSE_TOOLBAR |
f38374d0 | 654 | |
0e320a79 DW |
655 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
656 | { | |
f38374d0 | 657 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
0e320a79 | 658 | { |
0e320a79 | 659 | PositionToolBar(); |
0e320a79 | 660 | } |
0e320a79 | 661 | |
f38374d0 | 662 | return m_frameToolBar; |
0e320a79 DW |
663 | } |
664 | ||
665 | void wxFrame::PositionToolBar() | |
666 | { | |
29435d81 DW |
667 | // TODO: |
668 | /* | |
21802234 | 669 | RECT rect; |
29435d81 | 670 | ::GetClientRect(GetHwnd(), &rect); |
0e320a79 | 671 | |
f38374d0 | 672 | #if wxUSE_STATUSBAR |
0e320a79 DW |
673 | if ( GetStatusBar() ) |
674 | { | |
f38374d0 DW |
675 | int statusX, statusY; |
676 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
677 | rect.bottom -= statusY; | |
0e320a79 | 678 | } |
f38374d0 | 679 | #endif // wxUSE_STATUSBAR |
0e320a79 | 680 | |
f38374d0 | 681 | if ( GetToolBar() ) |
0e320a79 DW |
682 | { |
683 | int tw, th; | |
f38374d0 | 684 | GetToolBar()->GetSize(&tw, &th); |
0e320a79 | 685 | |
f38374d0 | 686 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) |
0e320a79 | 687 | { |
f38374d0 | 688 | th = rect.bottom; |
0e320a79 DW |
689 | } |
690 | else | |
691 | { | |
f38374d0 | 692 | tw = rect.right; |
21802234 | 693 | } |
f38374d0 DW |
694 | |
695 | // Use the 'real' MSW position here | |
696 | GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); | |
21802234 | 697 | } |
29435d81 | 698 | */ |
21802234 DW |
699 | } |
700 | #endif // wxUSE_TOOLBAR | |
701 | ||
f38374d0 DW |
702 | // ---------------------------------------------------------------------------- |
703 | // frame state (iconized/maximized/...) | |
704 | // ---------------------------------------------------------------------------- | |
705 | ||
21802234 DW |
706 | // propagate our state change to all child frames: this allows us to emulate X |
707 | // Windows behaviour where child frames float independently of the parent one | |
708 | // on the desktop, but are iconized/restored with it | |
709 | void wxFrame::IconizeChildFrames(bool bIconize) | |
710 | { | |
711 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); | |
712 | node; | |
713 | node = node->GetNext() ) | |
714 | { | |
715 | wxWindow *win = node->GetData(); | |
716 | ||
717 | if ( win->IsKindOf(CLASSINFO(wxFrame)) ) | |
718 | { | |
719 | ((wxFrame *)win)->Iconize(bIconize); | |
0e320a79 DW |
720 | } |
721 | } | |
722 | } | |
723 | ||
21802234 DW |
724 | // =========================================================================== |
725 | // message processing | |
726 | // =========================================================================== | |
727 | ||
728 | // --------------------------------------------------------------------------- | |
729 | // preprocessing | |
730 | // --------------------------------------------------------------------------- | |
731 | ||
732 | bool wxFrame::OS2TranslateMessage(WXMSG* pMsg) | |
733 | { | |
f38374d0 DW |
734 | // TODO: |
735 | /* | |
29435d81 DW |
736 | if ( wxWindow::OS2TranslateMessage(pMsg) ) |
737 | return TRUE; | |
f38374d0 | 738 | */ |
21802234 DW |
739 | // try the menu bar accels |
740 | wxMenuBar *menuBar = GetMenuBar(); | |
741 | if ( !menuBar ) | |
742 | return FALSE; | |
743 | ||
29435d81 DW |
744 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); |
745 | return acceleratorTable.Translate(this, pMsg); | |
21802234 DW |
746 | } |
747 | ||
748 | // --------------------------------------------------------------------------- | |
749 | // our private (non virtual) message handlers | |
750 | // --------------------------------------------------------------------------- | |
751 | ||
752 | bool wxFrame::HandlePaint() | |
753 | { | |
21802234 | 754 | // TODO: |
29435d81 DW |
755 | /* |
756 | RECT rect; | |
757 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
758 | { | |
759 | if ( m_iconized ) | |
760 | { | |
761 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) | |
762 | : (HICON)m_defaultIcon; | |
763 | ||
21802234 DW |
764 | // Hold a pointer to the dc so long as the OnPaint() message |
765 | // is being processed | |
29435d81 DW |
766 | PAINTSTRUCT ps; |
767 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
768 | ||
769 | // Erase background before painting or we get white background | |
770 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
771 | ||
772 | if ( hIcon ) | |
773 | { | |
774 | RECT rect; | |
775 | ::GetClientRect(GetHwnd(), &rect); | |
21802234 DW |
776 | |
777 | // FIXME: why hardcoded? | |
29435d81 DW |
778 | static const int icon_width = 32; |
779 | static const int icon_height = 32; | |
780 | ||
781 | int icon_x = (int)((rect.right - icon_width)/2); | |
782 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
783 | ||
784 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
785 | } | |
786 | ||
787 | ::EndPaint(GetHwnd(), &ps); | |
788 | ||
789 | return TRUE; | |
790 | } | |
791 | else | |
792 | { | |
793 | return wxWindow::HandlePaint(); | |
794 | } | |
795 | } | |
796 | else | |
797 | { | |
798 | // nothing to paint - processed | |
799 | return TRUE; | |
800 | } | |
801 | */ | |
802 | return FALSE; | |
21802234 DW |
803 | } |
804 | ||
805 | bool wxFrame::HandleSize(int x, int y, WXUINT id) | |
806 | { | |
807 | bool processed = FALSE; | |
808 | ||
29435d81 DW |
809 | // TODO: |
810 | /* | |
811 | switch ( id ) | |
21802234 DW |
812 | { |
813 | case SIZENORMAL: | |
814 | // only do it it if we were iconized before, otherwise resizing the | |
815 | // parent frame has a curious side effect of bringing it under it's | |
816 | // children | |
817 | if ( !m_iconized ) | |
818 | break; | |
819 | ||
820 | // restore all child frames too | |
821 | IconizeChildFrames(FALSE); | |
822 | ||
823 | // fall through | |
824 | ||
825 | case SIZEFULLSCREEN: | |
826 | m_iconized = FALSE; | |
827 | break; | |
828 | ||
829 | case SIZEICONIC: | |
830 | // iconize all child frames too | |
831 | IconizeChildFrames(TRUE); | |
832 | ||
833 | m_iconized = TRUE; | |
834 | break; | |
835 | } | |
f38374d0 | 836 | |
21802234 DW |
837 | if ( !m_iconized ) |
838 | { | |
29435d81 | 839 | // forward WM_SIZE to status bar control |
f38374d0 DW |
840 | #if wxUSE_NATIVE_STATUSBAR |
841 | if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) | |
842 | { | |
843 | wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId()); | |
844 | event.SetEventObject( m_frameStatusBar ); | |
845 | ||
846 | ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); | |
847 | } | |
848 | #endif // wxUSE_NATIVE_STATUSBAR | |
849 | ||
21802234 DW |
850 | PositionStatusBar(); |
851 | PositionToolBar(); | |
852 | ||
853 | wxSizeEvent event(wxSize(x, y), m_windowId); | |
854 | event.SetEventObject( this ); | |
855 | processed = GetEventHandler()->ProcessEvent(event); | |
856 | } | |
f38374d0 | 857 | */ |
21802234 DW |
858 | return processed; |
859 | } | |
860 | ||
861 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) | |
862 | { | |
f38374d0 DW |
863 | // TODO: |
864 | /* | |
21802234 DW |
865 | if ( control ) |
866 | { | |
867 | // In case it's e.g. a toolbar. | |
868 | wxWindow *win = wxFindWinFromHandle(control); | |
869 | if ( win ) | |
f38374d0 | 870 | return win->MSWCommand(cmd, id); |
21802234 DW |
871 | } |
872 | ||
873 | // handle here commands from menus and accelerators | |
874 | if ( cmd == 0 || cmd == 1 ) | |
875 | { | |
876 | if ( wxCurrentPopupMenu ) | |
877 | { | |
878 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
879 | wxCurrentPopupMenu = NULL; | |
880 | ||
f38374d0 | 881 | return popupMenu->MSWCommand(cmd, id); |
21802234 DW |
882 | } |
883 | ||
884 | if ( ProcessCommand(id) ) | |
885 | { | |
886 | return TRUE; | |
887 | } | |
888 | } | |
f38374d0 | 889 | */ |
21802234 DW |
890 | return FALSE; |
891 | } | |
892 | ||
893 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) | |
894 | { | |
895 | int item; | |
896 | if ( flags == 0xFFFF && hMenu == 0 ) | |
897 | { | |
898 | // menu was removed from screen | |
899 | item = -1; | |
900 | } | |
29435d81 | 901 | // TODO: |
21802234 DW |
902 | /* |
903 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) | |
904 | { | |
905 | item = nItem; | |
906 | } | |
21802234 DW |
907 | else |
908 | { | |
909 | // don't give hints for separators (doesn't make sense) nor for the | |
910 | // items opening popup menus (they don't have them anyhow) | |
911 | return FALSE; | |
912 | } | |
f38374d0 | 913 | */ |
21802234 DW |
914 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); |
915 | event.SetEventObject( this ); | |
916 | ||
917 | return GetEventHandler()->ProcessEvent(event); | |
918 | } | |
919 | ||
920 | // --------------------------------------------------------------------------- | |
921 | // the window proc for wxFrame | |
922 | // --------------------------------------------------------------------------- | |
923 | ||
924 | MRESULT wxFrame::OS2WindowProc(HWND hwnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
925 | { | |
f38374d0 | 926 | long rc = 0; |
21802234 DW |
927 | bool processed = FALSE; |
928 | ||
929 | // TODO: | |
930 | /* | |
931 | switch ( message ) | |
932 | { | |
933 | case WM_CLOSE: | |
934 | // if we can't close, tell the system that we processed the | |
935 | // message - otherwise it would close us | |
936 | processed = !Close(); | |
937 | break; | |
938 | ||
939 | case WM_COMMAND: | |
940 | { | |
941 | WORD id, cmd; | |
942 | WXHWND hwnd; | |
943 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
944 | &id, &hwnd, &cmd); | |
945 | ||
946 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
947 | } | |
948 | break; | |
949 | ||
950 | case WM_MENUSELECT: | |
951 | { | |
952 | WXWORD item, flags; | |
953 | WXHMENU hmenu; | |
954 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
955 | ||
956 | processed = HandleMenuSelect(item, flags, hmenu); | |
957 | } | |
958 | break; | |
959 | ||
960 | case WM_PAINT: | |
961 | processed = HandlePaint(); | |
962 | break; | |
963 | ||
964 | case WM_QUERYDRAGICON: | |
965 | { | |
966 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) | |
967 | : (HICON)(m_defaultIcon); | |
968 | rc = (long)hIcon; | |
969 | processed = rc != 0; | |
970 | } | |
971 | break; | |
972 | ||
973 | case WM_SIZE: | |
974 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
975 | break; | |
976 | } | |
f38374d0 | 977 | |
21802234 | 978 | if ( !processed ) |
f38374d0 | 979 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); |
21802234 DW |
980 | |
981 | return rc; | |
f38374d0 DW |
982 | */ |
983 | return (MRESULT)0; | |
21802234 DW |
984 | } |
985 |