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