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