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