]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/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 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #include "wx/frame.h" | |
28 | ||
29 | #ifndef WX_PRECOMP | |
30 | #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly" | |
31 | #include "wx/app.h" | |
32 | #include "wx/menu.h" | |
33 | #include "wx/utils.h" | |
34 | #include "wx/dialog.h" | |
35 | #include "wx/settings.h" | |
36 | #include "wx/dcclient.h" | |
37 | #include "wx/mdi.h" | |
38 | #include "wx/panel.h" | |
39 | #include "wx/log.h" | |
40 | #include "wx/toolbar.h" | |
41 | #include "wx/statusbr.h" | |
42 | #include "wx/menuitem.h" | |
43 | #endif // WX_PRECOMP | |
44 | ||
45 | #include "wx/msw/private.h" | |
46 | ||
47 | #if defined(__POCKETPC__) || defined(__SMARTPHONE__) | |
48 | #include <ole2.h> | |
49 | #include <aygshell.h> | |
50 | #include "wx/msw/winundef.h" | |
51 | #endif | |
52 | ||
53 | #include "wx/generic/statusbr.h" | |
54 | ||
55 | #ifdef __WXUNIVERSAL__ | |
56 | #include "wx/univ/theme.h" | |
57 | #include "wx/univ/colschem.h" | |
58 | #endif // __WXUNIVERSAL__ | |
59 | ||
60 | // ---------------------------------------------------------------------------- | |
61 | // globals | |
62 | // ---------------------------------------------------------------------------- | |
63 | ||
64 | #if wxUSE_MENUS_NATIVE | |
65 | extern wxMenu *wxCurrentPopupMenu; | |
66 | #endif // wxUSE_MENUS_NATIVE | |
67 | ||
68 | // ---------------------------------------------------------------------------- | |
69 | // event tables | |
70 | // ---------------------------------------------------------------------------- | |
71 | ||
72 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) | |
73 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
74 | END_EVENT_TABLE() | |
75 | ||
76 | #if wxUSE_EXTENDED_RTTI | |
77 | WX_DEFINE_FLAGS( wxFrameStyle ) | |
78 | ||
79 | wxBEGIN_FLAGS( wxFrameStyle ) | |
80 | // new style border flags, we put them first to | |
81 | // use them for streaming out | |
82 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) | |
83 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
84 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
85 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
86 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
87 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
88 | ||
89 | // old style border flags | |
90 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) | |
91 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
92 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
93 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
94 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
95 | wxFLAGS_MEMBER(wxBORDER) | |
96 | ||
97 | // standard window styles | |
98 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) | |
99 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
100 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
101 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
102 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) | |
103 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) | |
104 | wxFLAGS_MEMBER(wxVSCROLL) | |
105 | wxFLAGS_MEMBER(wxHSCROLL) | |
106 | ||
107 | // frame styles | |
108 | wxFLAGS_MEMBER(wxSTAY_ON_TOP) | |
109 | wxFLAGS_MEMBER(wxCAPTION) | |
110 | #if WXWIN_COMPATIBILITY_2_6 | |
111 | wxFLAGS_MEMBER(wxTHICK_FRAME) | |
112 | #endif // WXWIN_COMPATIBILITY_2_6 | |
113 | wxFLAGS_MEMBER(wxSYSTEM_MENU) | |
114 | wxFLAGS_MEMBER(wxRESIZE_BORDER) | |
115 | #if WXWIN_COMPATIBILITY_2_6 | |
116 | wxFLAGS_MEMBER(wxRESIZE_BOX) | |
117 | #endif // WXWIN_COMPATIBILITY_2_6 | |
118 | wxFLAGS_MEMBER(wxCLOSE_BOX) | |
119 | wxFLAGS_MEMBER(wxMAXIMIZE_BOX) | |
120 | wxFLAGS_MEMBER(wxMINIMIZE_BOX) | |
121 | ||
122 | wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW) | |
123 | wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT) | |
124 | ||
125 | wxFLAGS_MEMBER(wxFRAME_SHAPED) | |
126 | ||
127 | wxEND_FLAGS( wxFrameStyle ) | |
128 | ||
129 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow,"wx/frame.h") | |
130 | ||
131 | wxBEGIN_PROPERTIES_TABLE(wxFrame) | |
132 | wxEVENT_PROPERTY( Menu , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent) | |
133 | ||
134 | wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
135 | wxPROPERTY_FLAGS( WindowStyle , wxFrameStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style | |
136 | wxPROPERTY( MenuBar , wxMenuBar * , SetMenuBar , GetMenuBar , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) | |
137 | wxEND_PROPERTIES_TABLE() | |
138 | ||
139 | wxBEGIN_HANDLERS_TABLE(wxFrame) | |
140 | wxEND_HANDLERS_TABLE() | |
141 | ||
142 | wxCONSTRUCTOR_6( wxFrame , wxWindow* , Parent , wxWindowID , Id , wxString , Title , wxPoint , Position , wxSize , Size , long , WindowStyle) | |
143 | ||
144 | #else | |
145 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) | |
146 | #endif | |
147 | ||
148 | // ============================================================================ | |
149 | // implementation | |
150 | // ============================================================================ | |
151 | ||
152 | // ---------------------------------------------------------------------------- | |
153 | // static class members | |
154 | // ---------------------------------------------------------------------------- | |
155 | ||
156 | #if wxUSE_STATUSBAR | |
157 | #if wxUSE_NATIVE_STATUSBAR | |
158 | bool wxFrame::m_useNativeStatusBar = true; | |
159 | #else | |
160 | bool wxFrame::m_useNativeStatusBar = false; | |
161 | #endif | |
162 | #endif // wxUSE_NATIVE_STATUSBAR | |
163 | ||
164 | // ---------------------------------------------------------------------------- | |
165 | // creation/destruction | |
166 | // ---------------------------------------------------------------------------- | |
167 | ||
168 | void wxFrame::Init() | |
169 | { | |
170 | #if wxUSE_MENUS | |
171 | m_hMenu = NULL; | |
172 | #endif // wxUSE_MENUS | |
173 | ||
174 | #if wxUSE_TOOLTIPS | |
175 | m_hwndToolTip = 0; | |
176 | #endif | |
177 | ||
178 | m_wasMinimized = false; | |
179 | } | |
180 | ||
181 | bool wxFrame::Create(wxWindow *parent, | |
182 | wxWindowID id, | |
183 | const wxString& title, | |
184 | const wxPoint& pos, | |
185 | const wxSize& size, | |
186 | long style, | |
187 | const wxString& name) | |
188 | { | |
189 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) | |
190 | return false; | |
191 | ||
192 | SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); | |
193 | ||
194 | #if defined(__SMARTPHONE__) | |
195 | SetLeftMenu(wxID_EXIT, _("Done")); | |
196 | #endif | |
197 | ||
198 | #if wxUSE_ACCEL && defined(__POCKETPC__) | |
199 | // The guidelines state that Ctrl+Q should quit the app. | |
200 | // Let's define an accelerator table to send wxID_EXIT. | |
201 | wxAcceleratorEntry entries[1]; | |
202 | entries[0].Set(wxACCEL_CTRL, 'Q', wxID_EXIT); | |
203 | wxAcceleratorTable accel(1, entries); | |
204 | SetAcceleratorTable(accel); | |
205 | #endif // wxUSE_ACCEL && __POCKETPC__ | |
206 | ||
207 | return true; | |
208 | } | |
209 | ||
210 | wxFrame::~wxFrame() | |
211 | { | |
212 | m_isBeingDeleted = true; | |
213 | DeleteAllBars(); | |
214 | } | |
215 | ||
216 | // ---------------------------------------------------------------------------- | |
217 | // wxFrame client size calculations | |
218 | // ---------------------------------------------------------------------------- | |
219 | ||
220 | void wxFrame::DoSetClientSize(int width, int height) | |
221 | { | |
222 | // leave enough space for the status bar if we have (and show) it | |
223 | #if wxUSE_STATUSBAR | |
224 | wxStatusBar *statbar = GetStatusBar(); | |
225 | if ( statbar && statbar->IsShown() ) | |
226 | { | |
227 | height += statbar->GetSize().y; | |
228 | } | |
229 | #endif // wxUSE_STATUSBAR | |
230 | ||
231 | // call GetClientAreaOrigin() to take the toolbar into account | |
232 | wxPoint pt = GetClientAreaOrigin(); | |
233 | width += pt.x; | |
234 | height += pt.y; | |
235 | ||
236 | wxTopLevelWindow::DoSetClientSize(width, height); | |
237 | } | |
238 | ||
239 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. | |
240 | void wxFrame::DoGetClientSize(int *x, int *y) const | |
241 | { | |
242 | wxTopLevelWindow::DoGetClientSize(x, y); | |
243 | ||
244 | // account for the possible toolbar | |
245 | wxPoint pt = GetClientAreaOrigin(); | |
246 | if ( x ) | |
247 | *x -= pt.x; | |
248 | ||
249 | if ( y ) | |
250 | *y -= pt.y; | |
251 | ||
252 | #if wxUSE_STATUSBAR | |
253 | // adjust client area height to take the status bar into account | |
254 | if ( y ) | |
255 | { | |
256 | wxStatusBar *statbar = GetStatusBar(); | |
257 | if ( statbar && statbar->IsShown() ) | |
258 | { | |
259 | *y -= statbar->GetClientSize().y; | |
260 | } | |
261 | } | |
262 | #endif // wxUSE_STATUSBAR | |
263 | } | |
264 | ||
265 | // ---------------------------------------------------------------------------- | |
266 | // wxFrame: various geometry-related functions | |
267 | // ---------------------------------------------------------------------------- | |
268 | ||
269 | void wxFrame::Raise() | |
270 | { | |
271 | ::SetForegroundWindow(GetHwnd()); | |
272 | } | |
273 | ||
274 | // generate an artificial resize event | |
275 | void wxFrame::SendSizeEvent() | |
276 | { | |
277 | if ( !m_iconized ) | |
278 | { | |
279 | RECT r = wxGetWindowRect(GetHwnd()); | |
280 | ||
281 | (void)::PostMessage(GetHwnd(), WM_SIZE, | |
282 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
283 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
284 | } | |
285 | } | |
286 | ||
287 | #if wxUSE_STATUSBAR | |
288 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, | |
289 | long style, | |
290 | wxWindowID id, | |
291 | const wxString& name) | |
292 | { | |
293 | wxStatusBar *statusBar wxDUMMY_INITIALIZE(NULL); | |
294 | ||
295 | #if wxUSE_NATIVE_STATUSBAR | |
296 | if ( !UsesNativeStatusBar() ) | |
297 | { | |
298 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); | |
299 | } | |
300 | else | |
301 | #endif | |
302 | { | |
303 | statusBar = new wxStatusBar(this, id, style, name); | |
304 | } | |
305 | ||
306 | statusBar->SetFieldsCount(number); | |
307 | ||
308 | return statusBar; | |
309 | } | |
310 | ||
311 | void wxFrame::PositionStatusBar() | |
312 | { | |
313 | if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() ) | |
314 | return; | |
315 | ||
316 | int w, h; | |
317 | GetClientSize(&w, &h); | |
318 | int sw, sh; | |
319 | m_frameStatusBar->GetSize(&sw, &sh); | |
320 | ||
321 | // Since we wish the status bar to be directly under the client area, | |
322 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
323 | m_frameStatusBar->SetSize(0, h, w, sh); | |
324 | } | |
325 | #endif // wxUSE_STATUSBAR | |
326 | ||
327 | #if wxUSE_MENUS_NATIVE | |
328 | ||
329 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) | |
330 | { | |
331 | #if defined(__SMARTPHONE__) && defined(__WXWINCE__) | |
332 | ||
333 | wxMenu *autoMenu = NULL; | |
334 | ||
335 | if( menubar->GetMenuCount() == 1 ) | |
336 | { | |
337 | autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0)); | |
338 | SetRightMenu(wxID_ANY, menubar->GetLabelTop(0), autoMenu); | |
339 | } | |
340 | else | |
341 | { | |
342 | autoMenu = new wxMenu; | |
343 | ||
344 | for( size_t n = 0; n < menubar->GetMenuCount(); n++ ) | |
345 | { | |
346 | wxMenu *item = menubar->GetMenu(n); | |
347 | wxString label = menubar->GetLabelTop(n); | |
348 | wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item); | |
349 | autoMenu->Append(wxID_ANY, label, new_item); | |
350 | } | |
351 | ||
352 | SetRightMenu(wxID_ANY, _("Menu"), autoMenu); | |
353 | } | |
354 | ||
355 | #elif defined(WINCE_WITHOUT_COMMANDBAR) | |
356 | if (!GetToolBar()) | |
357 | { | |
358 | wxToolMenuBar* toolBar = new wxToolMenuBar(this, wxID_ANY, | |
359 | wxDefaultPosition, wxDefaultSize, | |
360 | wxBORDER_NONE | wxTB_HORIZONTAL, | |
361 | wxToolBarNameStr, menubar); | |
362 | SetToolBar(toolBar); | |
363 | menubar->SetToolBar(toolBar); | |
364 | } | |
365 | // Now adjust size for menu bar | |
366 | int menuHeight = 26; | |
367 | ||
368 | //When the main window is created using CW_USEDEFAULT the height of the | |
369 | // is created is not taken into account). So we resize the window after | |
370 | // if a menubar is present | |
371 | { | |
372 | RECT rc; | |
373 | ::GetWindowRect((HWND) GetHWND(), &rc); | |
374 | // adjust for menu / titlebar height | |
375 | rc.bottom -= (2*menuHeight-1); | |
376 | ||
377 | ::MoveWindow((HWND) GetHWND(), rc.left, rc.top, rc.right, rc.bottom, FALSE); | |
378 | } | |
379 | #endif | |
380 | ||
381 | wxFrameBase::AttachMenuBar(menubar); | |
382 | ||
383 | if ( !menubar ) | |
384 | { | |
385 | // actually remove the menu from the frame | |
386 | m_hMenu = (WXHMENU)0; | |
387 | InternalSetMenuBar(); | |
388 | } | |
389 | else // set new non NULL menu bar | |
390 | { | |
391 | #if !defined(__WXWINCE__) || defined(WINCE_WITH_COMMANDBAR) | |
392 | // Can set a menubar several times. | |
393 | if ( menubar->GetHMenu() ) | |
394 | { | |
395 | m_hMenu = menubar->GetHMenu(); | |
396 | } | |
397 | else // no HMENU yet | |
398 | { | |
399 | m_hMenu = menubar->Create(); | |
400 | ||
401 | if ( !m_hMenu ) | |
402 | { | |
403 | wxFAIL_MSG( _T("failed to create menu bar") ); | |
404 | return; | |
405 | } | |
406 | } | |
407 | #endif | |
408 | InternalSetMenuBar(); | |
409 | } | |
410 | } | |
411 | ||
412 | void wxFrame::InternalSetMenuBar() | |
413 | { | |
414 | #if defined(__WXMICROWIN__) || defined(__WXWINCE__) | |
415 | // Nothing | |
416 | #else | |
417 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) | |
418 | { | |
419 | wxLogLastError(wxT("SetMenu")); | |
420 | } | |
421 | #endif | |
422 | } | |
423 | ||
424 | #endif // wxUSE_MENUS_NATIVE | |
425 | ||
426 | // Responds to colour changes, and passes event on to children. | |
427 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
428 | { | |
429 | SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); | |
430 | Refresh(); | |
431 | ||
432 | #if wxUSE_STATUSBAR | |
433 | if ( m_frameStatusBar ) | |
434 | { | |
435 | wxSysColourChangedEvent event2; | |
436 | event2.SetEventObject( m_frameStatusBar ); | |
437 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); | |
438 | } | |
439 | #endif // wxUSE_STATUSBAR | |
440 | ||
441 | // Propagate the event to the non-top-level children | |
442 | wxWindow::OnSysColourChanged(event); | |
443 | } | |
444 | ||
445 | // Pass true to show full screen, false to restore. | |
446 | bool wxFrame::ShowFullScreen(bool show, long style) | |
447 | { | |
448 | // TODO-CE: add support for CE | |
449 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
450 | if ( IsFullScreen() == show ) | |
451 | return false; | |
452 | ||
453 | if (show) | |
454 | { | |
455 | // zap the toolbar, menubar, and statusbar if needed | |
456 | // | |
457 | // TODO: hide commandbar for WINCE_WITH_COMMANDBAR | |
458 | #if wxUSE_TOOLBAR | |
459 | wxToolBar *theToolBar = GetToolBar(); | |
460 | ||
461 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
462 | { | |
463 | if ( theToolBar->IsShown() ) | |
464 | { | |
465 | theToolBar->SetSize(wxDefaultCoord,0); | |
466 | theToolBar->Show(false); | |
467 | } | |
468 | else // prevent it from being restored later | |
469 | { | |
470 | style &= ~wxFULLSCREEN_NOTOOLBAR; | |
471 | } | |
472 | } | |
473 | #endif // wxUSE_TOOLBAR | |
474 | ||
475 | if (style & wxFULLSCREEN_NOMENUBAR) | |
476 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
477 | ||
478 | #if wxUSE_STATUSBAR | |
479 | wxStatusBar *theStatusBar = GetStatusBar(); | |
480 | ||
481 | // Save the number of fields in the statusbar | |
482 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
483 | { | |
484 | if ( theStatusBar->IsShown() ) | |
485 | theStatusBar->Show(false); | |
486 | else | |
487 | style &= ~wxFULLSCREEN_NOSTATUSBAR; | |
488 | } | |
489 | #endif // wxUSE_STATUSBAR | |
490 | } | |
491 | else // restore to normal | |
492 | { | |
493 | // restore the toolbar, menubar, and statusbar if we had hid them | |
494 | #if wxUSE_TOOLBAR | |
495 | wxToolBar *theToolBar = GetToolBar(); | |
496 | ||
497 | if ((m_fsStyle & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
498 | { | |
499 | theToolBar->Show(true); | |
500 | } | |
501 | #endif // wxUSE_TOOLBAR | |
502 | ||
503 | if (m_fsStyle & wxFULLSCREEN_NOMENUBAR) | |
504 | { | |
505 | WXHMENU menu = m_hMenu; | |
506 | ||
507 | #if wxUSE_MDI_ARCHITECTURE | |
508 | wxMDIParentFrame *frame = wxDynamicCast(this, wxMDIParentFrame); | |
509 | if (frame) | |
510 | { | |
511 | wxMDIChildFrame *child = frame->GetActiveChild(); | |
512 | if (child) | |
513 | { | |
514 | menu = child->GetWinMenu(); | |
515 | } | |
516 | } | |
517 | #endif // wxUSE_MDI_ARCHITECTURE | |
518 | ||
519 | if (menu) | |
520 | { | |
521 | ::SetMenu(GetHwnd(), (HMENU)menu); | |
522 | } | |
523 | } | |
524 | ||
525 | #if wxUSE_STATUSBAR | |
526 | wxStatusBar *theStatusBar = GetStatusBar(); | |
527 | ||
528 | if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
529 | { | |
530 | theStatusBar->Show(true); | |
531 | PositionStatusBar(); | |
532 | } | |
533 | #endif // wxUSE_STATUSBAR | |
534 | } | |
535 | #endif // !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
536 | ||
537 | return wxFrameBase::ShowFullScreen(show, style); | |
538 | } | |
539 | ||
540 | // ---------------------------------------------------------------------------- | |
541 | // tool/status bar stuff | |
542 | // ---------------------------------------------------------------------------- | |
543 | ||
544 | #if wxUSE_TOOLBAR | |
545 | ||
546 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) | |
547 | { | |
548 | #if defined(WINCE_WITHOUT_COMMANDBAR) | |
549 | // We may already have a toolbar from calling SetMenuBar. | |
550 | if (GetToolBar()) | |
551 | return GetToolBar(); | |
552 | #endif | |
553 | if ( wxFrameBase::CreateToolBar(style, id, name) ) | |
554 | { | |
555 | PositionToolBar(); | |
556 | } | |
557 | ||
558 | return m_frameToolBar; | |
559 | } | |
560 | ||
561 | void wxFrame::PositionToolBar() | |
562 | { | |
563 | wxToolBar *toolbar = GetToolBar(); | |
564 | if ( toolbar && toolbar->IsShown() ) | |
565 | { | |
566 | #if defined(WINCE_WITHOUT_COMMANDBAR) | |
567 | // We want to do something different in WinCE, because | |
568 | // the toolbar should be associated with the commandbar, | |
569 | // and not an independent window. | |
570 | // TODO | |
571 | #else | |
572 | // don't call our (or even wxTopLevelWindow) version because we want | |
573 | // the real (full) client area size, not excluding the tool/status bar | |
574 | int width, height; | |
575 | wxWindow::DoGetClientSize(&width, &height); | |
576 | ||
577 | #if wxUSE_STATUSBAR | |
578 | wxStatusBar *statbar = GetStatusBar(); | |
579 | if ( statbar && statbar->IsShown() ) | |
580 | { | |
581 | height -= statbar->GetClientSize().y; | |
582 | } | |
583 | #endif // wxUSE_STATUSBAR | |
584 | ||
585 | int x = 0; | |
586 | int y = 0; | |
587 | #if defined(WINCE_WITH_COMMANDBAR) | |
588 | // We're using a commandbar - so we have to allow for it. | |
589 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) | |
590 | { | |
591 | RECT rect; | |
592 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
593 | y = rect.bottom - rect.top; | |
594 | } | |
595 | #endif | |
596 | ||
597 | int tx, ty; | |
598 | int tw, th; | |
599 | toolbar->GetPosition(&tx, &ty); | |
600 | toolbar->GetSize(&tw, &th); | |
601 | ||
602 | // Adjust | |
603 | if (ty < 0 && (-ty == th)) | |
604 | ty = 0; | |
605 | if (tx < 0 && (-tx == tw)) | |
606 | tx = 0; | |
607 | ||
608 | int desiredW = tw; | |
609 | int desiredH = th; | |
610 | ||
611 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
612 | { | |
613 | desiredH = height; | |
614 | } | |
615 | else | |
616 | { | |
617 | desiredW = width; | |
618 | // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT ) | |
619 | // desiredW -= 3; | |
620 | } | |
621 | ||
622 | // use the 'real' MSW position here, don't offset relativly to the | |
623 | // client area origin | |
624 | ||
625 | // Optimise such that we don't have to always resize the toolbar | |
626 | // when the frame changes, otherwise we'll get a lot of flicker. | |
627 | bool heightChanging wxDUMMY_INITIALIZE(true); | |
628 | bool widthChanging wxDUMMY_INITIALIZE(true); | |
629 | ||
630 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
631 | { | |
632 | // It's OK if the current height is greater than what can be shown. | |
633 | heightChanging = (desiredH > th) ; | |
634 | widthChanging = (desiredW != tw) ; | |
635 | ||
636 | // The next time around, we may not have to set the size | |
637 | if (heightChanging) | |
638 | desiredH = desiredH + 200; | |
639 | } | |
640 | else | |
641 | { | |
642 | // It's OK if the current width is greater than what can be shown. | |
643 | widthChanging = (desiredW > tw) ; | |
644 | heightChanging = (desiredH != th) ; | |
645 | ||
646 | // The next time around, we may not have to set the size | |
647 | if (widthChanging) | |
648 | desiredW = desiredW + 200; | |
649 | } | |
650 | ||
651 | if (tx != 0 || ty != 0 || widthChanging || heightChanging) | |
652 | toolbar->SetSize(x, y, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS); | |
653 | ||
654 | #endif // __WXWINCE__ | |
655 | } | |
656 | } | |
657 | ||
658 | #endif // wxUSE_TOOLBAR | |
659 | ||
660 | // ---------------------------------------------------------------------------- | |
661 | // frame state (iconized/maximized/...) | |
662 | // ---------------------------------------------------------------------------- | |
663 | ||
664 | // propagate our state change to all child frames: this allows us to emulate X | |
665 | // Windows behaviour where child frames float independently of the parent one | |
666 | // on the desktop, but are iconized/restored with it | |
667 | void wxFrame::IconizeChildFrames(bool bIconize) | |
668 | { | |
669 | m_iconized = bIconize; | |
670 | ||
671 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
672 | node; | |
673 | node = node->GetNext() ) | |
674 | { | |
675 | wxWindow *win = node->GetData(); | |
676 | ||
677 | // iconizing the frames with this style under Win95 shell puts them at | |
678 | // the bottom of the screen (as the MDI children) instead of making | |
679 | // them appear in the taskbar because they are, by virtue of this | |
680 | // style, not managed by the taskbar - instead leave Windows take care | |
681 | // of them | |
682 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) | |
683 | continue; | |
684 | ||
685 | // the child MDI frames are a special case and should not be touched by | |
686 | // the parent frame - instead, they are managed by the user | |
687 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
688 | if ( frame | |
689 | #if wxUSE_MDI_ARCHITECTURE | |
690 | && !frame->IsMDIChild() | |
691 | #endif // wxUSE_MDI_ARCHITECTURE | |
692 | ) | |
693 | { | |
694 | // we don't want to restore the child frames which had been | |
695 | // iconized even before we were iconized, so save the child frame | |
696 | // status when iconizing the parent frame and check it when | |
697 | // restoring it | |
698 | if ( bIconize ) | |
699 | { | |
700 | frame->m_wasMinimized = frame->IsIconized(); | |
701 | } | |
702 | ||
703 | // note that we shouldn't touch the hidden frames neither because | |
704 | // iconizing/restoring them would show them as a side effect | |
705 | if ( !frame->m_wasMinimized && frame->IsShown() ) | |
706 | frame->Iconize(bIconize); | |
707 | } | |
708 | } | |
709 | } | |
710 | ||
711 | WXHICON wxFrame::GetDefaultIcon() const | |
712 | { | |
713 | // we don't have any standard icons (any more) | |
714 | return (WXHICON)0; | |
715 | } | |
716 | ||
717 | // =========================================================================== | |
718 | // message processing | |
719 | // =========================================================================== | |
720 | ||
721 | // --------------------------------------------------------------------------- | |
722 | // preprocessing | |
723 | // --------------------------------------------------------------------------- | |
724 | ||
725 | bool wxFrame::MSWDoTranslateMessage(wxFrame *frame, WXMSG *pMsg) | |
726 | { | |
727 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
728 | return true; | |
729 | ||
730 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) | |
731 | // try the menu bar accels | |
732 | wxMenuBar *menuBar = GetMenuBar(); | |
733 | if ( menuBar ) | |
734 | { | |
735 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
736 | return acceleratorTable.Translate(frame, pMsg); | |
737 | } | |
738 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
739 | ||
740 | return false; | |
741 | } | |
742 | ||
743 | // --------------------------------------------------------------------------- | |
744 | // our private (non virtual) message handlers | |
745 | // --------------------------------------------------------------------------- | |
746 | ||
747 | bool wxFrame::HandlePaint() | |
748 | { | |
749 | RECT rect; | |
750 | if ( ::GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
751 | { | |
752 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
753 | if ( m_iconized ) | |
754 | { | |
755 | const wxIcon& icon = GetIcon(); | |
756 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
757 | : (HICON)GetDefaultIcon(); | |
758 | ||
759 | // Hold a pointer to the dc so long as the OnPaint() message | |
760 | // is being processed | |
761 | PAINTSTRUCT ps; | |
762 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
763 | ||
764 | // Erase background before painting or we get white background | |
765 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
766 | ||
767 | if ( hIcon ) | |
768 | { | |
769 | RECT rect; | |
770 | ::GetClientRect(GetHwnd(), &rect); | |
771 | ||
772 | // FIXME: why hardcoded? | |
773 | static const int icon_width = 32; | |
774 | static const int icon_height = 32; | |
775 | ||
776 | int icon_x = (int)((rect.right - icon_width)/2); | |
777 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
778 | ||
779 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
780 | } | |
781 | ||
782 | ::EndPaint(GetHwnd(), &ps); | |
783 | ||
784 | return true; | |
785 | } | |
786 | else | |
787 | #endif | |
788 | { | |
789 | return wxWindow::HandlePaint(); | |
790 | } | |
791 | } | |
792 | else | |
793 | { | |
794 | // nothing to paint - processed | |
795 | return true; | |
796 | } | |
797 | } | |
798 | ||
799 | bool wxFrame::HandleSize(int WXUNUSED(x), int WXUNUSED(y), WXUINT id) | |
800 | { | |
801 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
802 | switch ( id ) | |
803 | { | |
804 | case SIZE_RESTORED: | |
805 | case SIZE_MAXIMIZED: | |
806 | // only do it it if we were iconized before, otherwise resizing the | |
807 | // parent frame has a curious side effect of bringing it under it's | |
808 | // children | |
809 | if ( !m_iconized ) | |
810 | break; | |
811 | ||
812 | // restore all child frames too | |
813 | IconizeChildFrames(false); | |
814 | ||
815 | (void)SendIconizeEvent(false); | |
816 | break; | |
817 | ||
818 | case SIZE_MINIMIZED: | |
819 | // iconize all child frames too | |
820 | IconizeChildFrames(true); | |
821 | break; | |
822 | } | |
823 | #else | |
824 | wxUnusedVar(id); | |
825 | #endif // !__WXWINCE__ | |
826 | ||
827 | if ( !m_iconized ) | |
828 | { | |
829 | #if wxUSE_STATUSBAR | |
830 | PositionStatusBar(); | |
831 | #endif // wxUSE_STATUSBAR | |
832 | ||
833 | #if wxUSE_TOOLBAR | |
834 | PositionToolBar(); | |
835 | #endif // wxUSE_TOOLBAR | |
836 | ||
837 | #if defined(WINCE_WITH_COMMANDBAR) | |
838 | // Position the menu command bar | |
839 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) | |
840 | { | |
841 | RECT rect; | |
842 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
843 | wxSize clientSz = GetClientSize(); | |
844 | ||
845 | if ( !::MoveWindow((HWND) GetMenuBar()->GetCommandBar(), 0, 0, clientSz.x, rect.bottom - rect.top, true ) ) | |
846 | { | |
847 | wxLogLastError(wxT("MoveWindow")); | |
848 | } | |
849 | ||
850 | } | |
851 | #endif // WINCE_WITH_COMMANDBAR | |
852 | } | |
853 | ||
854 | // call the base class version to generate the appropriate events | |
855 | return false; | |
856 | } | |
857 | ||
858 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) | |
859 | { | |
860 | if ( control ) | |
861 | { | |
862 | // In case it's e.g. a toolbar. | |
863 | wxWindow *win = wxFindWinFromHandle(control); | |
864 | if ( win ) | |
865 | return win->MSWCommand(cmd, id); | |
866 | } | |
867 | ||
868 | // handle here commands from menus and accelerators | |
869 | if ( cmd == 0 || cmd == 1 ) | |
870 | { | |
871 | #if wxUSE_MENUS_NATIVE | |
872 | if ( wxCurrentPopupMenu ) | |
873 | { | |
874 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
875 | wxCurrentPopupMenu = NULL; | |
876 | ||
877 | return popupMenu->MSWCommand(cmd, id); | |
878 | } | |
879 | #endif // wxUSE_MENUS_NATIVE | |
880 | ||
881 | #if defined(__SMARTPHONE__) && defined(__WXWINCE__) | |
882 | // handle here commands from Smartphone menu bar | |
883 | if ( wxTopLevelWindow::HandleCommand(id, cmd, control ) ) | |
884 | { | |
885 | return true; | |
886 | } | |
887 | #endif // __SMARTPHONE__ && __WXWINCE__ | |
888 | ||
889 | if ( ProcessCommand(id) ) | |
890 | { | |
891 | return true; | |
892 | } | |
893 | } | |
894 | ||
895 | return false; | |
896 | } | |
897 | ||
898 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) | |
899 | { | |
900 | int item; | |
901 | if ( flags == 0xFFFF && hMenu == 0 ) | |
902 | { | |
903 | // menu was removed from screen | |
904 | item = -1; | |
905 | } | |
906 | #ifndef __WXMICROWIN__ | |
907 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) | |
908 | { | |
909 | item = nItem; | |
910 | } | |
911 | #endif | |
912 | else | |
913 | { | |
914 | // don't give hints for separators (doesn't make sense) nor for the | |
915 | // items opening popup menus (they don't have them anyhow) but do clear | |
916 | // the status line - otherwise, we would be left with the help message | |
917 | // for the previous item which doesn't apply any more | |
918 | DoGiveHelp(wxEmptyString, false); | |
919 | ||
920 | return false; | |
921 | } | |
922 | ||
923 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
924 | event.SetEventObject(this); | |
925 | ||
926 | return GetEventHandler()->ProcessEvent(event); | |
927 | } | |
928 | ||
929 | bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup) | |
930 | { | |
931 | // we don't have the menu id here, so we use the id to specify if the event | |
932 | // was from a popup menu or a normal one | |
933 | wxMenuEvent event(evtType, isPopup ? -1 : 0); | |
934 | event.SetEventObject(this); | |
935 | ||
936 | return GetEventHandler()->ProcessEvent(event); | |
937 | } | |
938 | ||
939 | // --------------------------------------------------------------------------- | |
940 | // the window proc for wxFrame | |
941 | // --------------------------------------------------------------------------- | |
942 | ||
943 | WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
944 | { | |
945 | WXLRESULT rc = 0; | |
946 | bool processed = false; | |
947 | ||
948 | switch ( message ) | |
949 | { | |
950 | case WM_CLOSE: | |
951 | // if we can't close, tell the system that we processed the | |
952 | // message - otherwise it would close us | |
953 | processed = !Close(); | |
954 | break; | |
955 | ||
956 | case WM_SIZE: | |
957 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
958 | break; | |
959 | ||
960 | case WM_COMMAND: | |
961 | { | |
962 | WORD id, cmd; | |
963 | WXHWND hwnd; | |
964 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
965 | &id, &hwnd, &cmd); | |
966 | ||
967 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
968 | } | |
969 | break; | |
970 | ||
971 | case WM_PAINT: | |
972 | processed = HandlePaint(); | |
973 | break; | |
974 | ||
975 | case WM_INITMENUPOPUP: | |
976 | processed = HandleInitMenuPopup((WXHMENU) wParam); | |
977 | break; | |
978 | ||
979 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) | |
980 | case WM_MENUSELECT: | |
981 | { | |
982 | WXWORD item, flags; | |
983 | WXHMENU hmenu; | |
984 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
985 | ||
986 | processed = HandleMenuSelect(item, flags, hmenu); | |
987 | } | |
988 | break; | |
989 | ||
990 | case WM_EXITMENULOOP: | |
991 | processed = HandleMenuLoop(wxEVT_MENU_CLOSE, (WXWORD)wParam); | |
992 | break; | |
993 | ||
994 | case WM_QUERYDRAGICON: | |
995 | { | |
996 | const wxIcon& icon = GetIcon(); | |
997 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
998 | : (HICON)GetDefaultIcon(); | |
999 | rc = (long)hIcon; | |
1000 | processed = rc != 0; | |
1001 | } | |
1002 | break; | |
1003 | #endif // !__WXMICROWIN__ | |
1004 | } | |
1005 | ||
1006 | if ( !processed ) | |
1007 | rc = wxFrameBase::MSWWindowProc(message, wParam, lParam); | |
1008 | ||
1009 | return rc; | |
1010 | } | |
1011 | ||
1012 | // handle WM_INITMENUPOPUP message | |
1013 | bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu) | |
1014 | { | |
1015 | wxMenu* menu = NULL; | |
1016 | if (GetMenuBar()) | |
1017 | { | |
1018 | int nCount = GetMenuBar()->GetMenuCount(); | |
1019 | for (int n = 0; n < nCount; n++) | |
1020 | { | |
1021 | if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu) | |
1022 | { | |
1023 | menu = GetMenuBar()->GetMenu(n); | |
1024 | break; | |
1025 | } | |
1026 | } | |
1027 | } | |
1028 | ||
1029 | wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu); | |
1030 | event.SetEventObject(this); | |
1031 | ||
1032 | return GetEventHandler()->ProcessEvent(event); | |
1033 | } | |
1034 | ||
1035 | // ---------------------------------------------------------------------------- | |
1036 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
1037 | // from the client area, so the client area is what's really available for the | |
1038 | // frame contents | |
1039 | // ---------------------------------------------------------------------------- | |
1040 | ||
1041 | // get the origin of the client area in the client coordinates | |
1042 | wxPoint wxFrame::GetClientAreaOrigin() const | |
1043 | { | |
1044 | wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin(); | |
1045 | ||
1046 | #if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__) && \ | |
1047 | (!defined(__WXWINCE__) || (_WIN32_WCE >= 400 && !defined(__POCKETPC__) && !defined(__SMARTPHONE__))) | |
1048 | wxToolBar *toolbar = GetToolBar(); | |
1049 | if ( toolbar && toolbar->IsShown() ) | |
1050 | { | |
1051 | int w, h; | |
1052 | toolbar->GetSize(&w, &h); | |
1053 | ||
1054 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
1055 | { | |
1056 | pt.x += w; | |
1057 | } | |
1058 | else | |
1059 | { | |
1060 | pt.y += h; | |
1061 | } | |
1062 | } | |
1063 | #endif // wxUSE_TOOLBAR | |
1064 | ||
1065 | #if defined(WINCE_WITH_COMMANDBAR) | |
1066 | if (GetMenuBar() && GetMenuBar()->GetCommandBar()) | |
1067 | { | |
1068 | RECT rect; | |
1069 | ::GetWindowRect((HWND) GetMenuBar()->GetCommandBar(), &rect); | |
1070 | pt.y += (rect.bottom - rect.top); | |
1071 | } | |
1072 | #endif | |
1073 | ||
1074 | return pt; | |
1075 | } |