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