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