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