]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: msw/frame.cpp | |
3 | // Purpose: wxFrame | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #ifdef __GNUG__ | |
21 | #pragma implementation "frame.h" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
32 | #include "wx/frame.h" | |
33 | #include "wx/app.h" | |
34 | #include "wx/menu.h" | |
35 | #include "wx/utils.h" | |
36 | #include "wx/dialog.h" | |
37 | #include "wx/settings.h" | |
38 | #include "wx/dcclient.h" | |
39 | #include "wx/mdi.h" | |
40 | #include "wx/panel.h" | |
41 | #endif // WX_PRECOMP | |
42 | ||
43 | #include "wx/msw/private.h" | |
44 | ||
45 | #if wxUSE_STATUSBAR | |
46 | #include "wx/statusbr.h" | |
47 | #include "wx/generic/statusbr.h" | |
48 | #endif // wxUSE_STATUSBAR | |
49 | ||
50 | #if wxUSE_TOOLBAR | |
51 | #include "wx/toolbar.h" | |
52 | #endif // wxUSE_TOOLBAR | |
53 | ||
54 | #include "wx/menuitem.h" | |
55 | #include "wx/log.h" | |
56 | ||
57 | #ifdef __WXUNIVERSAL__ | |
58 | #include "wx/univ/theme.h" | |
59 | #include "wx/univ/colschem.h" | |
60 | #endif // __WXUNIVERSAL__ | |
61 | ||
62 | // ---------------------------------------------------------------------------- | |
63 | // globals | |
64 | // ---------------------------------------------------------------------------- | |
65 | ||
66 | extern const wxChar *wxFrameClassName; | |
67 | ||
68 | #if wxUSE_MENUS_NATIVE | |
69 | extern wxMenu *wxCurrentPopupMenu; | |
70 | #endif // wxUSE_MENUS_NATIVE | |
71 | ||
72 | // ---------------------------------------------------------------------------- | |
73 | // event tables | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
76 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) | |
77 | EVT_ACTIVATE(wxFrame::OnActivate) | |
78 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
79 | END_EVENT_TABLE() | |
80 | ||
81 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) | |
82 | ||
83 | // ============================================================================ | |
84 | // implementation | |
85 | // ============================================================================ | |
86 | ||
87 | // ---------------------------------------------------------------------------- | |
88 | // static class members | |
89 | // ---------------------------------------------------------------------------- | |
90 | ||
91 | #if wxUSE_STATUSBAR | |
92 | #if wxUSE_NATIVE_STATUSBAR | |
93 | bool wxFrame::m_useNativeStatusBar = TRUE; | |
94 | #else | |
95 | bool wxFrame::m_useNativeStatusBar = FALSE; | |
96 | #endif | |
97 | #endif // wxUSE_NATIVE_STATUSBAR | |
98 | ||
99 | // ---------------------------------------------------------------------------- | |
100 | // creation/destruction | |
101 | // ---------------------------------------------------------------------------- | |
102 | ||
103 | void wxFrame::Init() | |
104 | { | |
105 | #if wxUSE_TOOLTIPS | |
106 | m_hwndToolTip = 0; | |
107 | #endif | |
108 | ||
109 | // Data to save/restore when calling ShowFullScreen | |
110 | m_fsStatusBarFields = 0; | |
111 | m_fsStatusBarHeight = 0; | |
112 | m_fsToolBarHeight = 0; | |
113 | // m_fsMenu = 0; | |
114 | ||
115 | m_winLastFocused = (wxWindow *)NULL; | |
116 | } | |
117 | ||
118 | bool wxFrame::Create(wxWindow *parent, | |
119 | wxWindowID id, | |
120 | const wxString& title, | |
121 | const wxPoint& pos, | |
122 | const wxSize& size, | |
123 | long style, | |
124 | const wxString& name) | |
125 | { | |
126 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) | |
127 | return FALSE; | |
128 | ||
129 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
130 | ||
131 | wxModelessWindows.Append(this); | |
132 | ||
133 | return TRUE; | |
134 | } | |
135 | ||
136 | wxFrame::~wxFrame() | |
137 | { | |
138 | m_isBeingDeleted = TRUE; | |
139 | ||
140 | DeleteAllBars(); | |
141 | } | |
142 | ||
143 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. | |
144 | void wxFrame::DoGetClientSize(int *x, int *y) const | |
145 | { | |
146 | RECT rect; | |
147 | ::GetClientRect(GetHwnd(), &rect); | |
148 | ||
149 | #if wxUSE_STATUSBAR | |
150 | if ( GetStatusBar() && GetStatusBar()->IsShown() ) | |
151 | { | |
152 | int statusX, statusY; | |
153 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
154 | rect.bottom -= statusY; | |
155 | } | |
156 | #endif // wxUSE_STATUSBAR | |
157 | ||
158 | wxPoint pt(GetClientAreaOrigin()); | |
159 | rect.bottom -= pt.y; | |
160 | rect.right -= pt.x; | |
161 | ||
162 | if ( x ) | |
163 | *x = rect.right; | |
164 | if ( y ) | |
165 | *y = rect.bottom; | |
166 | } | |
167 | ||
168 | void wxFrame::DoSetClientSize(int width, int height) | |
169 | { | |
170 | // leave enough space for the status bar if we have (and show) it | |
171 | #if wxUSE_STATUSBAR | |
172 | wxStatusBar *statbar = GetStatusBar(); | |
173 | if ( statbar && statbar->IsShown() ) | |
174 | { | |
175 | height += statbar->GetSize().y; | |
176 | } | |
177 | #endif // wxUSE_STATUSBAR | |
178 | ||
179 | wxTopLevelWindow::DoSetClientSize(width, height); | |
180 | } | |
181 | ||
182 | // ---------------------------------------------------------------------------- | |
183 | // wxFrame: various geometry-related functions | |
184 | // ---------------------------------------------------------------------------- | |
185 | ||
186 | void wxFrame::Raise() | |
187 | { | |
188 | #ifdef __WIN16__ | |
189 | // no SetForegroundWindow() in Win16 | |
190 | wxFrameBase::Raise(); | |
191 | #else // Win32 | |
192 | ::SetForegroundWindow(GetHwnd()); | |
193 | #endif // Win16/32 | |
194 | } | |
195 | ||
196 | // generate an artificial resize event | |
197 | void wxFrame::SendSizeEvent() | |
198 | { | |
199 | if ( !m_iconized ) | |
200 | { | |
201 | RECT r = wxGetWindowRect(GetHwnd()); | |
202 | ||
203 | (void)::PostMessage(GetHwnd(), WM_SIZE, | |
204 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
205 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
206 | } | |
207 | } | |
208 | ||
209 | #if wxUSE_STATUSBAR | |
210 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, | |
211 | long style, | |
212 | wxWindowID id, | |
213 | const wxString& name) | |
214 | { | |
215 | wxStatusBar *statusBar = NULL; | |
216 | ||
217 | #if wxUSE_NATIVE_STATUSBAR | |
218 | if ( !UsesNativeStatusBar() ) | |
219 | { | |
220 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); | |
221 | } | |
222 | else | |
223 | #endif | |
224 | { | |
225 | statusBar = new wxStatusBar(this, id, style, name); | |
226 | } | |
227 | ||
228 | statusBar->SetFieldsCount(number); | |
229 | ||
230 | return statusBar; | |
231 | } | |
232 | ||
233 | void wxFrame::PositionStatusBar() | |
234 | { | |
235 | if ( !m_frameStatusBar ) | |
236 | return; | |
237 | ||
238 | int w, h; | |
239 | GetClientSize(&w, &h); | |
240 | int sw, sh; | |
241 | m_frameStatusBar->GetSize(&sw, &sh); | |
242 | ||
243 | // Since we wish the status bar to be directly under the client area, | |
244 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
245 | m_frameStatusBar->SetSize(0, h, w, sh); | |
246 | } | |
247 | #endif // wxUSE_STATUSBAR | |
248 | ||
249 | #if wxUSE_MENUS_NATIVE | |
250 | ||
251 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) | |
252 | { | |
253 | wxFrameBase::AttachMenuBar(menubar); | |
254 | ||
255 | if ( !menubar ) | |
256 | { | |
257 | // actually remove the menu from the frame | |
258 | m_hMenu = (WXHMENU)0; | |
259 | InternalSetMenuBar(); | |
260 | } | |
261 | else // set new non NULL menu bar | |
262 | { | |
263 | // Can set a menubar several times. | |
264 | if ( menubar->GetHMenu() ) | |
265 | { | |
266 | m_hMenu = menubar->GetHMenu(); | |
267 | } | |
268 | else // no HMENU yet | |
269 | { | |
270 | m_hMenu = menubar->Create(); | |
271 | ||
272 | if ( !m_hMenu ) | |
273 | { | |
274 | wxFAIL_MSG( _T("failed to create menu bar") ); | |
275 | return; | |
276 | } | |
277 | } | |
278 | ||
279 | InternalSetMenuBar(); | |
280 | } | |
281 | } | |
282 | ||
283 | void wxFrame::InternalSetMenuBar() | |
284 | { | |
285 | #ifndef __WXMICROWIN__ | |
286 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) | |
287 | { | |
288 | wxLogLastError(wxT("SetMenu")); | |
289 | } | |
290 | #endif | |
291 | } | |
292 | ||
293 | #endif // wxUSE_MENUS_NATIVE | |
294 | ||
295 | // Responds to colour changes, and passes event on to children. | |
296 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
297 | { | |
298 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
299 | Refresh(); | |
300 | ||
301 | #if wxUSE_STATUSBAR | |
302 | if ( m_frameStatusBar ) | |
303 | { | |
304 | wxSysColourChangedEvent event2; | |
305 | event2.SetEventObject( m_frameStatusBar ); | |
306 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); | |
307 | } | |
308 | #endif // wxUSE_STATUSBAR | |
309 | ||
310 | // Propagate the event to the non-top-level children | |
311 | wxWindow::OnSysColourChanged(event); | |
312 | } | |
313 | ||
314 | // Pass TRUE to show full screen, FALSE to restore. | |
315 | bool wxFrame::ShowFullScreen(bool show, long style) | |
316 | { | |
317 | if ( IsFullScreen() == show ) | |
318 | return FALSE; | |
319 | ||
320 | if (show) | |
321 | { | |
322 | #if wxUSE_TOOLBAR | |
323 | wxToolBar *theToolBar = GetToolBar(); | |
324 | if (theToolBar) | |
325 | theToolBar->GetSize(NULL, &m_fsToolBarHeight); | |
326 | ||
327 | // zap the toolbar, menubar, and statusbar | |
328 | ||
329 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
330 | { | |
331 | theToolBar->SetSize(-1,0); | |
332 | theToolBar->Show(FALSE); | |
333 | } | |
334 | #endif // wxUSE_TOOLBAR | |
335 | ||
336 | #ifndef __WXMICROWIN__ | |
337 | if (style & wxFULLSCREEN_NOMENUBAR) | |
338 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
339 | #endif | |
340 | ||
341 | #if wxUSE_STATUSBAR | |
342 | wxStatusBar *theStatusBar = GetStatusBar(); | |
343 | if (theStatusBar) | |
344 | theStatusBar->GetSize(NULL, &m_fsStatusBarHeight); | |
345 | ||
346 | // Save the number of fields in the statusbar | |
347 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
348 | { | |
349 | //m_fsStatusBarFields = theStatusBar->GetFieldsCount(); | |
350 | //SetStatusBar((wxStatusBar*) NULL); | |
351 | //delete theStatusBar; | |
352 | theStatusBar->Show(FALSE); | |
353 | } | |
354 | else | |
355 | m_fsStatusBarFields = 0; | |
356 | #endif // wxUSE_STATUSBAR | |
357 | } | |
358 | else | |
359 | { | |
360 | #if wxUSE_TOOLBAR | |
361 | wxToolBar *theToolBar = GetToolBar(); | |
362 | ||
363 | // restore the toolbar, menubar, and statusbar | |
364 | if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
365 | { | |
366 | theToolBar->SetSize(-1, m_fsToolBarHeight); | |
367 | theToolBar->Show(TRUE); | |
368 | } | |
369 | #endif // wxUSE_TOOLBAR | |
370 | ||
371 | #if wxUSE_STATUSBAR | |
372 | if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR ) | |
373 | { | |
374 | //CreateStatusBar(m_fsStatusBarFields); | |
375 | if (GetStatusBar()) | |
376 | { | |
377 | GetStatusBar()->Show(TRUE); | |
378 | PositionStatusBar(); | |
379 | } | |
380 | } | |
381 | #endif // wxUSE_STATUSBAR | |
382 | ||
383 | #ifndef __WXMICROWIN__ | |
384 | if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) | |
385 | SetMenu((HWND)GetHWND(), (HMENU)m_hMenu); | |
386 | #endif | |
387 | } | |
388 | ||
389 | return wxFrameBase::ShowFullScreen(show, style); | |
390 | } | |
391 | ||
392 | // Default activation behaviour - set the focus for the first child | |
393 | // subwindow found. | |
394 | void wxFrame::OnActivate(wxActivateEvent& event) | |
395 | { | |
396 | if ( event.GetActive() ) | |
397 | { | |
398 | // restore focus to the child which was last focused | |
399 | wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd); | |
400 | ||
401 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() | |
402 | : NULL; | |
403 | if ( !parent ) | |
404 | { | |
405 | parent = this; | |
406 | } | |
407 | ||
408 | wxSetFocusToChild(parent, &m_winLastFocused); | |
409 | } | |
410 | else // deactivating | |
411 | { | |
412 | // remember the last focused child if it is our child | |
413 | m_winLastFocused = FindFocus(); | |
414 | ||
415 | // so we NULL it out if it's a child from some other frame | |
416 | wxWindow *win = m_winLastFocused; | |
417 | while ( win ) | |
418 | { | |
419 | if ( win->IsTopLevel() ) | |
420 | { | |
421 | if ( win != this ) | |
422 | { | |
423 | m_winLastFocused = NULL; | |
424 | } | |
425 | ||
426 | break; | |
427 | } | |
428 | ||
429 | win = win->GetParent(); | |
430 | } | |
431 | ||
432 | wxLogTrace(_T("focus"), | |
433 | _T("wxFrame %08x deactivated, last focused: %08x."), | |
434 | m_hWnd, | |
435 | m_winLastFocused ? GetHwndOf(m_winLastFocused) | |
436 | : NULL); | |
437 | ||
438 | event.Skip(); | |
439 | } | |
440 | } | |
441 | ||
442 | // ---------------------------------------------------------------------------- | |
443 | // tool/status bar stuff | |
444 | // ---------------------------------------------------------------------------- | |
445 | ||
446 | #if wxUSE_TOOLBAR | |
447 | ||
448 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) | |
449 | { | |
450 | if ( wxFrameBase::CreateToolBar(style, id, name) ) | |
451 | { | |
452 | PositionToolBar(); | |
453 | } | |
454 | ||
455 | return m_frameToolBar; | |
456 | } | |
457 | ||
458 | void wxFrame::PositionToolBar() | |
459 | { | |
460 | RECT rect; | |
461 | ::GetClientRect(GetHwnd(), &rect); | |
462 | ||
463 | #if wxUSE_STATUSBAR | |
464 | if ( GetStatusBar() ) | |
465 | { | |
466 | int statusX, statusY; | |
467 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
468 | rect.bottom -= statusY; | |
469 | } | |
470 | #endif // wxUSE_STATUSBAR | |
471 | ||
472 | if ( GetToolBar() && GetToolBar()->IsShown() ) | |
473 | { | |
474 | int tw, th; | |
475 | GetToolBar()->GetSize(&tw, &th); | |
476 | ||
477 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
478 | { | |
479 | th = rect.bottom; | |
480 | } | |
481 | else | |
482 | { | |
483 | tw = rect.right; | |
484 | } | |
485 | ||
486 | // Use the 'real' MSW position here | |
487 | GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); | |
488 | } | |
489 | } | |
490 | #endif // wxUSE_TOOLBAR | |
491 | ||
492 | // ---------------------------------------------------------------------------- | |
493 | // frame state (iconized/maximized/...) | |
494 | // ---------------------------------------------------------------------------- | |
495 | ||
496 | // propagate our state change to all child frames: this allows us to emulate X | |
497 | // Windows behaviour where child frames float independently of the parent one | |
498 | // on the desktop, but are iconized/restored with it | |
499 | void wxFrame::IconizeChildFrames(bool bIconize) | |
500 | { | |
501 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); | |
502 | node; | |
503 | node = node->GetNext() ) | |
504 | { | |
505 | wxWindow *win = node->GetData(); | |
506 | ||
507 | // iconizing the frames with this style under Win95 shell puts them at | |
508 | // the bottom of the screen (as the MDI children) instead of making | |
509 | // them appear in the taskbar because they are, by virtue of this | |
510 | // style, not managed by the taskbar - instead leave Windows take care | |
511 | // of them | |
512 | #ifdef __WIN95__ | |
513 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) | |
514 | continue; | |
515 | #endif // Win95 | |
516 | ||
517 | // the child MDI frames are a special case and should not be touched by | |
518 | // the parent frame - instead, they are managed by the user | |
519 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
520 | if ( frame | |
521 | #if wxUSE_MDI_ARCHITECTURE | |
522 | && !wxDynamicCast(frame, wxMDIChildFrame) | |
523 | #endif // wxUSE_MDI_ARCHITECTURE | |
524 | ) | |
525 | { | |
526 | frame->Iconize(bIconize); | |
527 | } | |
528 | } | |
529 | } | |
530 | ||
531 | WXHICON wxFrame::GetDefaultIcon() const | |
532 | { | |
533 | return (WXHICON)(wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON | |
534 | : wxDEFAULT_FRAME_ICON); | |
535 | } | |
536 | ||
537 | // =========================================================================== | |
538 | // message processing | |
539 | // =========================================================================== | |
540 | ||
541 | // --------------------------------------------------------------------------- | |
542 | // preprocessing | |
543 | // --------------------------------------------------------------------------- | |
544 | ||
545 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) | |
546 | { | |
547 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
548 | return TRUE; | |
549 | ||
550 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) | |
551 | // try the menu bar accels | |
552 | wxMenuBar *menuBar = GetMenuBar(); | |
553 | if ( !menuBar ) | |
554 | return FALSE; | |
555 | ||
556 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
557 | return acceleratorTable.Translate(this, pMsg); | |
558 | #else | |
559 | return FALSE; | |
560 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
561 | } | |
562 | ||
563 | // --------------------------------------------------------------------------- | |
564 | // our private (non virtual) message handlers | |
565 | // --------------------------------------------------------------------------- | |
566 | ||
567 | bool wxFrame::HandlePaint() | |
568 | { | |
569 | RECT rect; | |
570 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
571 | { | |
572 | #ifndef __WXMICROWIN__ | |
573 | if ( m_iconized ) | |
574 | { | |
575 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) | |
576 | : (HICON)GetDefaultIcon(); | |
577 | ||
578 | // Hold a pointer to the dc so long as the OnPaint() message | |
579 | // is being processed | |
580 | PAINTSTRUCT ps; | |
581 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
582 | ||
583 | // Erase background before painting or we get white background | |
584 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
585 | ||
586 | if ( hIcon ) | |
587 | { | |
588 | RECT rect; | |
589 | ::GetClientRect(GetHwnd(), &rect); | |
590 | ||
591 | // FIXME: why hardcoded? | |
592 | static const int icon_width = 32; | |
593 | static const int icon_height = 32; | |
594 | ||
595 | int icon_x = (int)((rect.right - icon_width)/2); | |
596 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
597 | ||
598 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
599 | } | |
600 | ||
601 | ::EndPaint(GetHwnd(), &ps); | |
602 | ||
603 | return TRUE; | |
604 | } | |
605 | else | |
606 | #endif | |
607 | { | |
608 | return wxWindow::HandlePaint(); | |
609 | } | |
610 | } | |
611 | else | |
612 | { | |
613 | // nothing to paint - processed | |
614 | return TRUE; | |
615 | } | |
616 | } | |
617 | ||
618 | bool wxFrame::HandleSize(int x, int y, WXUINT id) | |
619 | { | |
620 | bool processed = FALSE; | |
621 | #ifndef __WXMICROWIN__ | |
622 | ||
623 | switch ( id ) | |
624 | { | |
625 | case SIZENORMAL: | |
626 | // only do it it if we were iconized before, otherwise resizing the | |
627 | // parent frame has a curious side effect of bringing it under it's | |
628 | // children | |
629 | if ( !m_iconized ) | |
630 | break; | |
631 | ||
632 | // restore all child frames too | |
633 | IconizeChildFrames(FALSE); | |
634 | ||
635 | (void)SendIconizeEvent(FALSE); | |
636 | ||
637 | // fall through | |
638 | ||
639 | case SIZEFULLSCREEN: | |
640 | m_iconized = FALSE; | |
641 | break; | |
642 | ||
643 | case SIZEICONIC: | |
644 | // iconize all child frames too | |
645 | IconizeChildFrames(TRUE); | |
646 | ||
647 | (void)SendIconizeEvent(); | |
648 | ||
649 | m_iconized = TRUE; | |
650 | break; | |
651 | } | |
652 | #endif | |
653 | ||
654 | if ( !m_iconized ) | |
655 | { | |
656 | #if wxUSE_STATUSBAR | |
657 | PositionStatusBar(); | |
658 | #endif // wxUSE_STATUSBAR | |
659 | ||
660 | #if wxUSE_TOOLBAR | |
661 | PositionToolBar(); | |
662 | #endif // wxUSE_TOOLBAR | |
663 | ||
664 | wxSizeEvent event(wxSize(x, y), m_windowId); | |
665 | event.SetEventObject( this ); | |
666 | processed = GetEventHandler()->ProcessEvent(event); | |
667 | } | |
668 | ||
669 | return processed; | |
670 | } | |
671 | ||
672 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) | |
673 | { | |
674 | if ( control ) | |
675 | { | |
676 | // In case it's e.g. a toolbar. | |
677 | wxWindow *win = wxFindWinFromHandle(control); | |
678 | if ( win ) | |
679 | return win->MSWCommand(cmd, id); | |
680 | } | |
681 | ||
682 | // handle here commands from menus and accelerators | |
683 | if ( cmd == 0 || cmd == 1 ) | |
684 | { | |
685 | #if wxUSE_MENUS_NATIVE | |
686 | if ( wxCurrentPopupMenu ) | |
687 | { | |
688 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
689 | wxCurrentPopupMenu = NULL; | |
690 | ||
691 | return popupMenu->MSWCommand(cmd, id); | |
692 | } | |
693 | #endif // wxUSE_MENUS_NATIVE | |
694 | ||
695 | if ( ProcessCommand(id) ) | |
696 | { | |
697 | return TRUE; | |
698 | } | |
699 | } | |
700 | ||
701 | return FALSE; | |
702 | } | |
703 | ||
704 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) | |
705 | { | |
706 | int item; | |
707 | if ( flags == 0xFFFF && hMenu == 0 ) | |
708 | { | |
709 | // menu was removed from screen | |
710 | item = -1; | |
711 | } | |
712 | #ifndef __WXMICROWIN__ | |
713 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) | |
714 | { | |
715 | item = nItem; | |
716 | } | |
717 | #endif | |
718 | else | |
719 | { | |
720 | #if wxUSE_STATUSBAR | |
721 | // don't give hints for separators (doesn't make sense) nor for the | |
722 | // items opening popup menus (they don't have them anyhow) but do clear | |
723 | // the status line - otherwise, we would be left with the help message | |
724 | // for the previous item which doesn't apply any more | |
725 | wxStatusBar *statbar = GetStatusBar(); | |
726 | if ( statbar ) | |
727 | { | |
728 | statbar->SetStatusText(wxEmptyString); | |
729 | } | |
730 | #endif // wxUSE_STATUSBAR | |
731 | ||
732 | return FALSE; | |
733 | } | |
734 | ||
735 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
736 | event.SetEventObject( this ); | |
737 | ||
738 | return GetEventHandler()->ProcessEvent(event); | |
739 | } | |
740 | ||
741 | // --------------------------------------------------------------------------- | |
742 | // the window proc for wxFrame | |
743 | // --------------------------------------------------------------------------- | |
744 | ||
745 | long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
746 | { | |
747 | long rc = 0; | |
748 | bool processed = FALSE; | |
749 | ||
750 | switch ( message ) | |
751 | { | |
752 | case WM_CLOSE: | |
753 | // if we can't close, tell the system that we processed the | |
754 | // message - otherwise it would close us | |
755 | processed = !Close(); | |
756 | break; | |
757 | ||
758 | case WM_COMMAND: | |
759 | { | |
760 | WORD id, cmd; | |
761 | WXHWND hwnd; | |
762 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
763 | &id, &hwnd, &cmd); | |
764 | ||
765 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
766 | } | |
767 | break; | |
768 | ||
769 | #ifndef __WXMICROWIN__ | |
770 | case WM_MENUSELECT: | |
771 | { | |
772 | WXWORD item, flags; | |
773 | WXHMENU hmenu; | |
774 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
775 | ||
776 | processed = HandleMenuSelect(item, flags, hmenu); | |
777 | } | |
778 | break; | |
779 | #endif | |
780 | ||
781 | case WM_PAINT: | |
782 | processed = HandlePaint(); | |
783 | break; | |
784 | ||
785 | #ifndef __WXMICROWIN__ | |
786 | case WM_QUERYDRAGICON: | |
787 | { | |
788 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) | |
789 | : (HICON)GetDefaultIcon(); | |
790 | rc = (long)hIcon; | |
791 | processed = rc != 0; | |
792 | } | |
793 | break; | |
794 | #endif | |
795 | ||
796 | case WM_SIZE: | |
797 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
798 | break; | |
799 | } | |
800 | ||
801 | if ( !processed ) | |
802 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
803 | ||
804 | return rc; | |
805 | } | |
806 |