]>
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
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 | #ifdef __WXWINCE__ | |
46 | #include <commctrl.h> | |
47 | #endif | |
48 | ||
49 | #if wxUSE_STATUSBAR | |
50 | #include "wx/statusbr.h" | |
51 | #include "wx/generic/statusbr.h" | |
52 | #endif // wxUSE_STATUSBAR | |
53 | ||
54 | #if wxUSE_TOOLBAR | |
55 | #include "wx/toolbar.h" | |
56 | #endif // wxUSE_TOOLBAR | |
57 | ||
58 | #include "wx/menuitem.h" | |
59 | #include "wx/log.h" | |
60 | ||
61 | #ifdef __WXUNIVERSAL__ | |
62 | #include "wx/univ/theme.h" | |
63 | #include "wx/univ/colschem.h" | |
64 | #endif // __WXUNIVERSAL__ | |
65 | ||
66 | // ---------------------------------------------------------------------------- | |
67 | // globals | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
70 | #if wxUSE_MENUS_NATIVE | |
71 | extern wxMenu *wxCurrentPopupMenu; | |
72 | #endif // wxUSE_MENUS_NATIVE | |
73 | ||
74 | // ---------------------------------------------------------------------------- | |
75 | // event tables | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
78 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) | |
79 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
80 | END_EVENT_TABLE() | |
81 | ||
82 | #if wxUSE_EXTENDED_RTTI | |
83 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow,"wx/frame.h") | |
84 | ||
85 | WX_BEGIN_PROPERTIES_TABLE(wxFrame) | |
86 | WX_PROPERTY( Title,wxString, SetTitle, GetTitle, wxEmptyString , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
87 | /* | |
88 | TODO PROPERTIES | |
89 | ||
90 | style (wxDEFAULT_FRAME_STYLE) | |
91 | centered (bool, false ) | |
92 | */ | |
93 | WX_END_PROPERTIES_TABLE() | |
94 | ||
95 | WX_BEGIN_HANDLERS_TABLE(wxFrame) | |
96 | WX_END_HANDLERS_TABLE() | |
97 | ||
98 | WX_CONSTRUCTOR_6( wxFrame , wxWindow* , Parent , wxWindowID , Id , wxString , Title , wxPoint , Position , wxSize , Size , long , WindowStyle) | |
99 | ||
100 | #else | |
101 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) | |
102 | #endif | |
103 | ||
104 | // ============================================================================ | |
105 | // implementation | |
106 | // ============================================================================ | |
107 | ||
108 | // ---------------------------------------------------------------------------- | |
109 | // static class members | |
110 | // ---------------------------------------------------------------------------- | |
111 | ||
112 | #if wxUSE_STATUSBAR | |
113 | #if wxUSE_NATIVE_STATUSBAR | |
114 | bool wxFrame::m_useNativeStatusBar = TRUE; | |
115 | #else | |
116 | bool wxFrame::m_useNativeStatusBar = FALSE; | |
117 | #endif | |
118 | #endif // wxUSE_NATIVE_STATUSBAR | |
119 | ||
120 | // ---------------------------------------------------------------------------- | |
121 | // creation/destruction | |
122 | // ---------------------------------------------------------------------------- | |
123 | ||
124 | void wxFrame::Init() | |
125 | { | |
126 | #if wxUSE_TOOLTIPS | |
127 | m_hwndToolTip = 0; | |
128 | #endif | |
129 | ||
130 | // Data to save/restore when calling ShowFullScreen | |
131 | m_fsStatusBarFields = 0; | |
132 | m_fsStatusBarHeight = 0; | |
133 | m_fsToolBarHeight = 0; | |
134 | ||
135 | m_wasMinimized = FALSE; | |
136 | } | |
137 | ||
138 | bool wxFrame::Create(wxWindow *parent, | |
139 | wxWindowID id, | |
140 | const wxString& title, | |
141 | const wxPoint& pos, | |
142 | const wxSize& size, | |
143 | long style, | |
144 | const wxString& name) | |
145 | { | |
146 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) | |
147 | return FALSE; | |
148 | ||
149 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); | |
150 | ||
151 | wxModelessWindows.Append(this); | |
152 | ||
153 | return TRUE; | |
154 | } | |
155 | ||
156 | wxFrame::~wxFrame() | |
157 | { | |
158 | m_isBeingDeleted = TRUE; | |
159 | DeleteAllBars(); | |
160 | } | |
161 | ||
162 | // ---------------------------------------------------------------------------- | |
163 | // wxFrame client size calculations | |
164 | // ---------------------------------------------------------------------------- | |
165 | ||
166 | void wxFrame::DoSetClientSize(int width, int height) | |
167 | { | |
168 | // leave enough space for the status bar if we have (and show) it | |
169 | #if wxUSE_STATUSBAR | |
170 | wxStatusBar *statbar = GetStatusBar(); | |
171 | if ( statbar && statbar->IsShown() ) | |
172 | { | |
173 | height += statbar->GetSize().y; | |
174 | } | |
175 | #endif // wxUSE_STATUSBAR | |
176 | ||
177 | // call GetClientAreaOrigin() to take the toolbar into account | |
178 | wxPoint pt = GetClientAreaOrigin(); | |
179 | width += pt.x; | |
180 | height += pt.y; | |
181 | ||
182 | wxTopLevelWindow::DoSetClientSize(width, height); | |
183 | } | |
184 | ||
185 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. | |
186 | void wxFrame::DoGetClientSize(int *x, int *y) const | |
187 | { | |
188 | wxTopLevelWindow::DoGetClientSize(x, y); | |
189 | ||
190 | // account for the possible toolbar | |
191 | wxPoint pt = GetClientAreaOrigin(); | |
192 | if ( x ) | |
193 | *x -= pt.x; | |
194 | ||
195 | if ( y ) | |
196 | *y -= pt.y; | |
197 | ||
198 | #if wxUSE_STATUSBAR | |
199 | // adjust client area height to take the status bar into account | |
200 | if ( y ) | |
201 | { | |
202 | wxStatusBar *statbar = GetStatusBar(); | |
203 | if ( statbar && statbar->IsShown() ) | |
204 | { | |
205 | *y -= statbar->GetClientSize().y; | |
206 | } | |
207 | } | |
208 | #endif // wxUSE_STATUSBAR | |
209 | } | |
210 | ||
211 | // ---------------------------------------------------------------------------- | |
212 | // wxFrame: various geometry-related functions | |
213 | // ---------------------------------------------------------------------------- | |
214 | ||
215 | void wxFrame::Raise() | |
216 | { | |
217 | ::SetForegroundWindow(GetHwnd()); | |
218 | } | |
219 | ||
220 | // generate an artificial resize event | |
221 | void wxFrame::SendSizeEvent() | |
222 | { | |
223 | if ( !m_iconized ) | |
224 | { | |
225 | RECT r = wxGetWindowRect(GetHwnd()); | |
226 | ||
227 | (void)::PostMessage(GetHwnd(), WM_SIZE, | |
228 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
229 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
230 | } | |
231 | } | |
232 | ||
233 | #if wxUSE_STATUSBAR | |
234 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, | |
235 | long style, | |
236 | wxWindowID id, | |
237 | const wxString& name) | |
238 | { | |
239 | wxStatusBar *statusBar = NULL; | |
240 | ||
241 | #if wxUSE_NATIVE_STATUSBAR | |
242 | if ( !UsesNativeStatusBar() ) | |
243 | { | |
244 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); | |
245 | } | |
246 | else | |
247 | #endif | |
248 | { | |
249 | statusBar = new wxStatusBar(this, id, style, name); | |
250 | } | |
251 | ||
252 | statusBar->SetFieldsCount(number); | |
253 | ||
254 | return statusBar; | |
255 | } | |
256 | ||
257 | void wxFrame::PositionStatusBar() | |
258 | { | |
259 | if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() ) | |
260 | return; | |
261 | ||
262 | int w, h; | |
263 | GetClientSize(&w, &h); | |
264 | int sw, sh; | |
265 | m_frameStatusBar->GetSize(&sw, &sh); | |
266 | ||
267 | // Since we wish the status bar to be directly under the client area, | |
268 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
269 | m_frameStatusBar->SetSize(0, h, w, sh); | |
270 | } | |
271 | #endif // wxUSE_STATUSBAR | |
272 | ||
273 | #if wxUSE_MENUS_NATIVE | |
274 | ||
275 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) | |
276 | { | |
277 | wxFrameBase::AttachMenuBar(menubar); | |
278 | ||
279 | if ( !menubar ) | |
280 | { | |
281 | // actually remove the menu from the frame | |
282 | m_hMenu = (WXHMENU)0; | |
283 | InternalSetMenuBar(); | |
284 | } | |
285 | else // set new non NULL menu bar | |
286 | { | |
287 | #ifndef __WXWINCE__ | |
288 | // Can set a menubar several times. | |
289 | if ( menubar->GetHMenu() ) | |
290 | { | |
291 | m_hMenu = menubar->GetHMenu(); | |
292 | } | |
293 | else // no HMENU yet | |
294 | { | |
295 | m_hMenu = menubar->Create(); | |
296 | ||
297 | if ( !m_hMenu ) | |
298 | { | |
299 | wxFAIL_MSG( _T("failed to create menu bar") ); | |
300 | return; | |
301 | } | |
302 | } | |
303 | #endif | |
304 | InternalSetMenuBar(); | |
305 | } | |
306 | } | |
307 | ||
308 | void wxFrame::InternalSetMenuBar() | |
309 | { | |
310 | #ifdef __WXMICROWIN__ | |
311 | // Nothing | |
312 | #elif defined(__WXWINCE__) | |
313 | ||
314 | if (!GetToolBar()) | |
315 | { | |
316 | wxToolBar* toolBar = new wxToolBar(this, -1, | |
317 | wxDefaultPosition, wxDefaultSize, | |
318 | wxBORDER_NONE | wxTB_HORIZONTAL, | |
319 | wxToolBarNameStr, GetMenuBar()); | |
320 | SetToolBar(toolBar); | |
321 | } | |
322 | #else | |
323 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) | |
324 | { | |
325 | wxLogLastError(wxT("SetMenu")); | |
326 | } | |
327 | #endif | |
328 | } | |
329 | ||
330 | #endif // wxUSE_MENUS_NATIVE | |
331 | ||
332 | // Responds to colour changes, and passes event on to children. | |
333 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
334 | { | |
335 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); | |
336 | Refresh(); | |
337 | ||
338 | #if wxUSE_STATUSBAR | |
339 | if ( m_frameStatusBar ) | |
340 | { | |
341 | wxSysColourChangedEvent event2; | |
342 | event2.SetEventObject( m_frameStatusBar ); | |
343 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); | |
344 | } | |
345 | #endif // wxUSE_STATUSBAR | |
346 | ||
347 | // Propagate the event to the non-top-level children | |
348 | wxWindow::OnSysColourChanged(event); | |
349 | } | |
350 | ||
351 | // Pass TRUE to show full screen, FALSE to restore. | |
352 | bool wxFrame::ShowFullScreen(bool show, long style) | |
353 | { | |
354 | if ( IsFullScreen() == show ) | |
355 | return FALSE; | |
356 | ||
357 | if (show) | |
358 | { | |
359 | #if wxUSE_TOOLBAR | |
360 | #ifdef __WXWINCE__ | |
361 | // TODO: hide commandbar | |
362 | #else | |
363 | wxToolBar *theToolBar = GetToolBar(); | |
364 | if (theToolBar) | |
365 | theToolBar->GetSize(NULL, &m_fsToolBarHeight); | |
366 | ||
367 | // zap the toolbar, menubar, and statusbar | |
368 | ||
369 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
370 | { | |
371 | theToolBar->SetSize(-1,0); | |
372 | theToolBar->Show(FALSE); | |
373 | } | |
374 | #endif // __WXWINCE__ | |
375 | #endif // wxUSE_TOOLBAR | |
376 | ||
377 | // TODO: make it work for WinCE | |
378 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
379 | if (style & wxFULLSCREEN_NOMENUBAR) | |
380 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
381 | #endif | |
382 | ||
383 | #if wxUSE_STATUSBAR | |
384 | wxStatusBar *theStatusBar = GetStatusBar(); | |
385 | if (theStatusBar) | |
386 | theStatusBar->GetSize(NULL, &m_fsStatusBarHeight); | |
387 | ||
388 | // Save the number of fields in the statusbar | |
389 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
390 | { | |
391 | //m_fsStatusBarFields = theStatusBar->GetFieldsCount(); | |
392 | //SetStatusBar((wxStatusBar*) NULL); | |
393 | //delete theStatusBar; | |
394 | theStatusBar->Show(FALSE); | |
395 | } | |
396 | else | |
397 | m_fsStatusBarFields = 0; | |
398 | #endif // wxUSE_STATUSBAR | |
399 | } | |
400 | else | |
401 | { | |
402 | #if wxUSE_TOOLBAR | |
403 | #ifdef __WXWINCE__ | |
404 | // TODO: show commandbar | |
405 | #else | |
406 | wxToolBar *theToolBar = GetToolBar(); | |
407 | ||
408 | // restore the toolbar, menubar, and statusbar | |
409 | if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
410 | { | |
411 | theToolBar->SetSize(-1, m_fsToolBarHeight); | |
412 | theToolBar->Show(TRUE); | |
413 | } | |
414 | #endif // __WXWINCE__ | |
415 | #endif // wxUSE_TOOLBAR | |
416 | ||
417 | #if wxUSE_STATUSBAR | |
418 | if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR ) | |
419 | { | |
420 | //CreateStatusBar(m_fsStatusBarFields); | |
421 | if (GetStatusBar()) | |
422 | { | |
423 | GetStatusBar()->Show(TRUE); | |
424 | PositionStatusBar(); | |
425 | } | |
426 | } | |
427 | #endif // wxUSE_STATUSBAR | |
428 | ||
429 | // TODO: make it work for WinCE | |
430 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
431 | if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) | |
432 | SetMenu((HWND)GetHWND(), (HMENU)m_hMenu); | |
433 | #endif | |
434 | } | |
435 | ||
436 | return wxFrameBase::ShowFullScreen(show, style); | |
437 | } | |
438 | ||
439 | // ---------------------------------------------------------------------------- | |
440 | // tool/status bar stuff | |
441 | // ---------------------------------------------------------------------------- | |
442 | ||
443 | #if wxUSE_TOOLBAR | |
444 | ||
445 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) | |
446 | { | |
447 | #ifdef __WXWINCE__ | |
448 | // We may already have a toolbar from calling SetMenuBar. | |
449 | if (GetToolBar()) | |
450 | return GetToolBar(); | |
451 | #endif | |
452 | if ( wxFrameBase::CreateToolBar(style, id, name) ) | |
453 | { | |
454 | PositionToolBar(); | |
455 | } | |
456 | ||
457 | return m_frameToolBar; | |
458 | } | |
459 | ||
460 | void wxFrame::PositionToolBar() | |
461 | { | |
462 | wxToolBar *toolbar = GetToolBar(); | |
463 | if ( toolbar && toolbar->IsShown() ) | |
464 | { | |
465 | #ifdef __WXWINCE__ | |
466 | // We want to do something different in WinCE, because | |
467 | // the toolbar should be associated with the commandbar, | |
468 | // and not an independent window. | |
469 | // TODO | |
470 | #else | |
471 | // don't call our (or even wxTopLevelWindow) version because we want | |
472 | // the real (full) client area size, not excluding the tool/status bar | |
473 | int width, height; | |
474 | wxWindow::DoGetClientSize(&width, &height); | |
475 | ||
476 | #if wxUSE_STATUSBAR | |
477 | wxStatusBar *statbar = GetStatusBar(); | |
478 | if ( statbar && statbar->IsShown() ) | |
479 | { | |
480 | height -= statbar->GetClientSize().y; | |
481 | } | |
482 | #endif // wxUSE_STATUSBAR | |
483 | ||
484 | int tx, ty; | |
485 | int tw, th; | |
486 | toolbar->GetPosition(&tx, &ty); | |
487 | toolbar->GetSize(&tw, &th); | |
488 | ||
489 | // Adjust | |
490 | if (ty < 0 && (-ty == th)) | |
491 | ty = 0; | |
492 | if (tx < 0 && (-tx == tw)) | |
493 | tx = 0; | |
494 | ||
495 | int desiredW = tw; | |
496 | int desiredH = th; | |
497 | ||
498 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
499 | { | |
500 | desiredH = height; | |
501 | } | |
502 | else | |
503 | { | |
504 | desiredW = width; | |
505 | // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT ) | |
506 | // desiredW -= 3; | |
507 | } | |
508 | ||
509 | // use the 'real' MSW position here, don't offset relativly to the | |
510 | // client area origin | |
511 | ||
512 | // Optimise such that we don't have to always resize the toolbar | |
513 | // when the frame changes, otherwise we'll get a lot of flicker. | |
514 | bool heightChanging = TRUE; | |
515 | bool widthChanging = TRUE; | |
516 | ||
517 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
518 | { | |
519 | // It's OK if the current height is greater than what can be shown. | |
520 | heightChanging = (desiredH > th) ; | |
521 | widthChanging = (desiredW != tw) ; | |
522 | ||
523 | // The next time around, we may not have to set the size | |
524 | if (heightChanging) | |
525 | desiredH = desiredH + 200; | |
526 | } | |
527 | else | |
528 | { | |
529 | // It's OK if the current width is greater than what can be shown. | |
530 | widthChanging = (desiredW > tw) ; | |
531 | heightChanging = (desiredH != th) ; | |
532 | ||
533 | // The next time around, we may not have to set the size | |
534 | if (widthChanging) | |
535 | desiredW = desiredW + 200; | |
536 | } | |
537 | ||
538 | if (tx != 0 || ty != 0 || widthChanging || heightChanging) | |
539 | toolbar->SetSize(0, 0, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS); | |
540 | ||
541 | #endif // __WXWINCE__ | |
542 | } | |
543 | } | |
544 | ||
545 | #endif // wxUSE_TOOLBAR | |
546 | ||
547 | // ---------------------------------------------------------------------------- | |
548 | // frame state (iconized/maximized/...) | |
549 | // ---------------------------------------------------------------------------- | |
550 | ||
551 | // propagate our state change to all child frames: this allows us to emulate X | |
552 | // Windows behaviour where child frames float independently of the parent one | |
553 | // on the desktop, but are iconized/restored with it | |
554 | void wxFrame::IconizeChildFrames(bool bIconize) | |
555 | { | |
556 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
557 | node; | |
558 | node = node->GetNext() ) | |
559 | { | |
560 | wxWindow *win = node->GetData(); | |
561 | ||
562 | // iconizing the frames with this style under Win95 shell puts them at | |
563 | // the bottom of the screen (as the MDI children) instead of making | |
564 | // them appear in the taskbar because they are, by virtue of this | |
565 | // style, not managed by the taskbar - instead leave Windows take care | |
566 | // of them | |
567 | #ifdef __WIN95__ | |
568 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) | |
569 | continue; | |
570 | #endif // Win95 | |
571 | ||
572 | // the child MDI frames are a special case and should not be touched by | |
573 | // the parent frame - instead, they are managed by the user | |
574 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
575 | if ( frame | |
576 | #if wxUSE_MDI_ARCHITECTURE | |
577 | && !wxDynamicCast(frame, wxMDIChildFrame) | |
578 | #endif // wxUSE_MDI_ARCHITECTURE | |
579 | ) | |
580 | { | |
581 | // we don't want to restore the child frames which had been | |
582 | // iconized even before we were iconized, so save the child frame | |
583 | // status when iconizing the parent frame and check it when | |
584 | // restoring it | |
585 | if ( bIconize ) | |
586 | { | |
587 | // note that we shouldn't touch the hidden frames neither | |
588 | // because iconizing/restoring them would show them as a side | |
589 | // effect | |
590 | frame->m_wasMinimized = frame->IsIconized() || !frame->IsShown(); | |
591 | } | |
592 | ||
593 | // this test works for both iconizing and restoring | |
594 | if ( !frame->m_wasMinimized ) | |
595 | frame->Iconize(bIconize); | |
596 | } | |
597 | } | |
598 | } | |
599 | ||
600 | WXHICON wxFrame::GetDefaultIcon() const | |
601 | { | |
602 | // we don't have any standard icons (any more) | |
603 | return (WXHICON)0; | |
604 | } | |
605 | ||
606 | // =========================================================================== | |
607 | // message processing | |
608 | // =========================================================================== | |
609 | ||
610 | // --------------------------------------------------------------------------- | |
611 | // preprocessing | |
612 | // --------------------------------------------------------------------------- | |
613 | ||
614 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) | |
615 | { | |
616 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
617 | return TRUE; | |
618 | ||
619 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) | |
620 | // try the menu bar accels | |
621 | wxMenuBar *menuBar = GetMenuBar(); | |
622 | if ( !menuBar ) | |
623 | return FALSE; | |
624 | ||
625 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
626 | return acceleratorTable.Translate(this, pMsg); | |
627 | #else | |
628 | return FALSE; | |
629 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
630 | } | |
631 | ||
632 | // --------------------------------------------------------------------------- | |
633 | // our private (non virtual) message handlers | |
634 | // --------------------------------------------------------------------------- | |
635 | ||
636 | bool wxFrame::HandlePaint() | |
637 | { | |
638 | RECT rect; | |
639 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
640 | { | |
641 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
642 | if ( m_iconized ) | |
643 | { | |
644 | const wxIcon& icon = GetIcon(); | |
645 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
646 | : (HICON)GetDefaultIcon(); | |
647 | ||
648 | // Hold a pointer to the dc so long as the OnPaint() message | |
649 | // is being processed | |
650 | PAINTSTRUCT ps; | |
651 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
652 | ||
653 | // Erase background before painting or we get white background | |
654 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
655 | ||
656 | if ( hIcon ) | |
657 | { | |
658 | RECT rect; | |
659 | ::GetClientRect(GetHwnd(), &rect); | |
660 | ||
661 | // FIXME: why hardcoded? | |
662 | static const int icon_width = 32; | |
663 | static const int icon_height = 32; | |
664 | ||
665 | int icon_x = (int)((rect.right - icon_width)/2); | |
666 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
667 | ||
668 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
669 | } | |
670 | ||
671 | ::EndPaint(GetHwnd(), &ps); | |
672 | ||
673 | return TRUE; | |
674 | } | |
675 | else | |
676 | #endif | |
677 | { | |
678 | return wxWindow::HandlePaint(); | |
679 | } | |
680 | } | |
681 | else | |
682 | { | |
683 | // nothing to paint - processed | |
684 | return TRUE; | |
685 | } | |
686 | } | |
687 | ||
688 | bool wxFrame::HandleSize(int x, int y, WXUINT id) | |
689 | { | |
690 | bool processed = FALSE; | |
691 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
692 | ||
693 | switch ( id ) | |
694 | { | |
695 | case SIZENORMAL: | |
696 | // only do it it if we were iconized before, otherwise resizing the | |
697 | // parent frame has a curious side effect of bringing it under it's | |
698 | // children | |
699 | if ( !m_iconized ) | |
700 | break; | |
701 | ||
702 | // restore all child frames too | |
703 | IconizeChildFrames(FALSE); | |
704 | ||
705 | (void)SendIconizeEvent(FALSE); | |
706 | ||
707 | // fall through | |
708 | ||
709 | case SIZEFULLSCREEN: | |
710 | m_iconized = FALSE; | |
711 | break; | |
712 | ||
713 | case SIZEICONIC: | |
714 | // iconize all child frames too | |
715 | IconizeChildFrames(TRUE); | |
716 | ||
717 | (void)SendIconizeEvent(); | |
718 | ||
719 | m_iconized = TRUE; | |
720 | break; | |
721 | } | |
722 | #endif | |
723 | ||
724 | if ( !m_iconized ) | |
725 | { | |
726 | #if wxUSE_STATUSBAR | |
727 | PositionStatusBar(); | |
728 | #endif // wxUSE_STATUSBAR | |
729 | ||
730 | #if wxUSE_TOOLBAR | |
731 | PositionToolBar(); | |
732 | #endif // wxUSE_TOOLBAR | |
733 | ||
734 | processed = wxWindow::HandleSize(x, y, id); | |
735 | } | |
736 | ||
737 | return processed; | |
738 | } | |
739 | ||
740 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) | |
741 | { | |
742 | if ( control ) | |
743 | { | |
744 | // In case it's e.g. a toolbar. | |
745 | wxWindow *win = wxFindWinFromHandle(control); | |
746 | if ( win ) | |
747 | return win->MSWCommand(cmd, id); | |
748 | } | |
749 | ||
750 | // handle here commands from menus and accelerators | |
751 | if ( cmd == 0 || cmd == 1 ) | |
752 | { | |
753 | #if wxUSE_MENUS_NATIVE | |
754 | if ( wxCurrentPopupMenu ) | |
755 | { | |
756 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
757 | wxCurrentPopupMenu = NULL; | |
758 | ||
759 | return popupMenu->MSWCommand(cmd, id); | |
760 | } | |
761 | #endif // wxUSE_MENUS_NATIVE | |
762 | ||
763 | if ( ProcessCommand(id) ) | |
764 | { | |
765 | return TRUE; | |
766 | } | |
767 | } | |
768 | ||
769 | return FALSE; | |
770 | } | |
771 | ||
772 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) | |
773 | { | |
774 | int item; | |
775 | if ( flags == 0xFFFF && hMenu == 0 ) | |
776 | { | |
777 | // menu was removed from screen | |
778 | item = -1; | |
779 | } | |
780 | #ifndef __WXMICROWIN__ | |
781 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) | |
782 | { | |
783 | item = nItem; | |
784 | } | |
785 | #endif | |
786 | else | |
787 | { | |
788 | // don't give hints for separators (doesn't make sense) nor for the | |
789 | // items opening popup menus (they don't have them anyhow) but do clear | |
790 | // the status line - otherwise, we would be left with the help message | |
791 | // for the previous item which doesn't apply any more | |
792 | DoGiveHelp(wxEmptyString, FALSE); | |
793 | ||
794 | return FALSE; | |
795 | } | |
796 | ||
797 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
798 | event.SetEventObject(this); | |
799 | ||
800 | return GetEventHandler()->ProcessEvent(event); | |
801 | } | |
802 | ||
803 | bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup) | |
804 | { | |
805 | // we don't have the menu id here, so we use the id to specify if the event | |
806 | // was from a popup menu or a normal one | |
807 | wxMenuEvent event(evtType, isPopup ? -1 : 0); | |
808 | event.SetEventObject(this); | |
809 | ||
810 | return GetEventHandler()->ProcessEvent(event); | |
811 | } | |
812 | ||
813 | // --------------------------------------------------------------------------- | |
814 | // the window proc for wxFrame | |
815 | // --------------------------------------------------------------------------- | |
816 | ||
817 | long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
818 | { | |
819 | long rc = 0; | |
820 | bool processed = FALSE; | |
821 | ||
822 | switch ( message ) | |
823 | { | |
824 | case WM_CLOSE: | |
825 | // if we can't close, tell the system that we processed the | |
826 | // message - otherwise it would close us | |
827 | processed = !Close(); | |
828 | break; | |
829 | ||
830 | case WM_SIZE: | |
831 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
832 | break; | |
833 | ||
834 | case WM_COMMAND: | |
835 | { | |
836 | WORD id, cmd; | |
837 | WXHWND hwnd; | |
838 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
839 | &id, &hwnd, &cmd); | |
840 | ||
841 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
842 | } | |
843 | break; | |
844 | ||
845 | case WM_PAINT: | |
846 | processed = HandlePaint(); | |
847 | break; | |
848 | ||
849 | case WM_INITMENUPOPUP: | |
850 | processed = HandleInitMenuPopup((WXHMENU) wParam); | |
851 | break; | |
852 | ||
853 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
854 | case WM_MENUSELECT: | |
855 | { | |
856 | WXWORD item, flags; | |
857 | WXHMENU hmenu; | |
858 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
859 | ||
860 | processed = HandleMenuSelect(item, flags, hmenu); | |
861 | } | |
862 | break; | |
863 | ||
864 | case WM_EXITMENULOOP: | |
865 | processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam); | |
866 | break; | |
867 | ||
868 | case WM_QUERYDRAGICON: | |
869 | { | |
870 | const wxIcon& icon = GetIcon(); | |
871 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
872 | : (HICON)GetDefaultIcon(); | |
873 | rc = (long)hIcon; | |
874 | processed = rc != 0; | |
875 | } | |
876 | break; | |
877 | #endif // !__WXMICROWIN__ | |
878 | } | |
879 | ||
880 | if ( !processed ) | |
881 | rc = wxFrameBase::MSWWindowProc(message, wParam, lParam); | |
882 | ||
883 | return rc; | |
884 | } | |
885 | ||
886 | // handle WM_INITMENUPOPUP message | |
887 | bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu) | |
888 | { | |
889 | wxMenu* menu = NULL; | |
890 | if (GetMenuBar()) | |
891 | { | |
892 | int nCount = GetMenuBar()->GetMenuCount(); | |
893 | for (int n = 0; n < nCount; n++) | |
894 | { | |
895 | if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu) | |
896 | { | |
897 | menu = GetMenuBar()->GetMenu(n); | |
898 | break; | |
899 | } | |
900 | } | |
901 | } | |
902 | ||
903 | wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu); | |
904 | event.SetEventObject(this); | |
905 | ||
906 | return GetEventHandler()->ProcessEvent(event); | |
907 | } |