]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
7c0ea335 | 2 | // Name: msw/frame.cpp |
0d53fc34 | 3 | // Purpose: wxFrame |
2bda0e17 KB |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
7c0ea335 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
7c0ea335 | 21 | #pragma implementation "frame.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
9f3362c4 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
9f3362c4 | 32 | #include "wx/frame.h" |
9f3362c4 | 33 | #include "wx/app.h" |
1e6feb95 | 34 | #include "wx/menu.h" |
9f3362c4 VZ |
35 | #include "wx/utils.h" |
36 | #include "wx/dialog.h" | |
37 | #include "wx/settings.h" | |
38 | #include "wx/dcclient.h" | |
d3cc7c65 | 39 | #include "wx/mdi.h" |
f6bcfd97 | 40 | #include "wx/panel.h" |
9f3362c4 | 41 | #endif // WX_PRECOMP |
2bda0e17 KB |
42 | |
43 | #include "wx/msw/private.h" | |
7c0ea335 VZ |
44 | |
45 | #if wxUSE_STATUSBAR | |
46 | #include "wx/statusbr.h" | |
ed791986 | 47 | #include "wx/generic/statusbr.h" |
7c0ea335 VZ |
48 | #endif // wxUSE_STATUSBAR |
49 | ||
50 | #if wxUSE_TOOLBAR | |
51 | #include "wx/toolbar.h" | |
52 | #endif // wxUSE_TOOLBAR | |
53 | ||
2bda0e17 | 54 | #include "wx/menuitem.h" |
6776a0b2 | 55 | #include "wx/log.h" |
2bda0e17 | 56 | |
1e6feb95 VZ |
57 | #ifdef __WXUNIVERSAL__ |
58 | #include "wx/univ/theme.h" | |
59 | #include "wx/univ/colschem.h" | |
60 | #endif // __WXUNIVERSAL__ | |
61 | ||
7c0ea335 VZ |
62 | // ---------------------------------------------------------------------------- |
63 | // globals | |
64 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 65 | |
2ffa221c | 66 | extern const wxChar *wxFrameClassName; |
1e6feb95 VZ |
67 | |
68 | #if wxUSE_MENUS_NATIVE | |
e1a6fc11 | 69 | extern wxMenu *wxCurrentPopupMenu; |
1e6feb95 | 70 | #endif // wxUSE_MENUS_NATIVE |
2bda0e17 | 71 | |
7c0ea335 VZ |
72 | // ---------------------------------------------------------------------------- |
73 | // event tables | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
0d53fc34 VS |
76 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
77 | EVT_ACTIVATE(wxFrame::OnActivate) | |
78 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
2bda0e17 KB |
79 | END_EVENT_TABLE() |
80 | ||
58b43418 | 81 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) |
2bda0e17 | 82 | |
7c0ea335 VZ |
83 | // ============================================================================ |
84 | // implementation | |
85 | // ============================================================================ | |
86 | ||
87 | // ---------------------------------------------------------------------------- | |
88 | // static class members | |
89 | // ---------------------------------------------------------------------------- | |
90 | ||
1e6feb95 VZ |
91 | #if wxUSE_STATUSBAR |
92 | #if wxUSE_NATIVE_STATUSBAR | |
0d53fc34 | 93 | bool wxFrame::m_useNativeStatusBar = TRUE; |
1e6feb95 | 94 | #else |
0d53fc34 | 95 | bool wxFrame::m_useNativeStatusBar = FALSE; |
1e6feb95 VZ |
96 | #endif |
97 | #endif // wxUSE_NATIVE_STATUSBAR | |
2bda0e17 | 98 | |
7c0ea335 VZ |
99 | // ---------------------------------------------------------------------------- |
100 | // creation/destruction | |
101 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 102 | |
0d53fc34 | 103 | void wxFrame::Init() |
2bda0e17 | 104 | { |
9f3362c4 VZ |
105 | #if wxUSE_TOOLTIPS |
106 | m_hwndToolTip = 0; | |
107 | #endif | |
a2327a9f JS |
108 | |
109 | // Data to save/restore when calling ShowFullScreen | |
a2327a9f JS |
110 | m_fsStatusBarFields = 0; |
111 | m_fsStatusBarHeight = 0; | |
112 | m_fsToolBarHeight = 0; | |
f6bcfd97 | 113 | // m_fsMenu = 0; |
f6bcfd97 | 114 | |
9327c3aa VZ |
115 | m_wasMinimized = FALSE; |
116 | ||
f6bcfd97 | 117 | m_winLastFocused = (wxWindow *)NULL; |
7c0ea335 | 118 | } |
9f3362c4 | 119 | |
0d53fc34 | 120 | bool wxFrame::Create(wxWindow *parent, |
7c0ea335 VZ |
121 | wxWindowID id, |
122 | const wxString& title, | |
123 | const wxPoint& pos, | |
124 | const wxSize& size, | |
125 | long style, | |
126 | const wxString& name) | |
127 | { | |
82c9f85c VZ |
128 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) |
129 | return FALSE; | |
d2aef312 | 130 | |
a756f210 | 131 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
2bda0e17 | 132 | |
82c9f85c | 133 | wxModelessWindows.Append(this); |
f6bcfd97 | 134 | |
82c9f85c | 135 | return TRUE; |
2bda0e17 KB |
136 | } |
137 | ||
0d53fc34 | 138 | wxFrame::~wxFrame() |
2bda0e17 | 139 | { |
82c9f85c | 140 | m_isBeingDeleted = TRUE; |
2bda0e17 | 141 | |
82c9f85c | 142 | DeleteAllBars(); |
2bda0e17 KB |
143 | } |
144 | ||
d4597e13 VZ |
145 | // ---------------------------------------------------------------------------- |
146 | // wxFrame client size calculations | |
147 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 148 | |
0d53fc34 | 149 | void wxFrame::DoSetClientSize(int width, int height) |
2bda0e17 | 150 | { |
82c9f85c | 151 | // leave enough space for the status bar if we have (and show) it |
7c0ea335 | 152 | #if wxUSE_STATUSBAR |
8d8bd249 VZ |
153 | wxStatusBar *statbar = GetStatusBar(); |
154 | if ( statbar && statbar->IsShown() ) | |
155 | { | |
8d8bd249 VZ |
156 | height += statbar->GetSize().y; |
157 | } | |
7c0ea335 | 158 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 159 | |
68d02db3 VZ |
160 | // call GetClientAreaOrigin() to take the toolbar into account |
161 | wxPoint pt = GetClientAreaOrigin(); | |
162 | width += pt.x; | |
163 | height += pt.y; | |
164 | ||
82c9f85c | 165 | wxTopLevelWindow::DoSetClientSize(width, height); |
2bda0e17 KB |
166 | } |
167 | ||
d4597e13 VZ |
168 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
169 | void wxFrame::DoGetClientSize(int *x, int *y) const | |
170 | { | |
171 | wxTopLevelWindow::DoGetClientSize(x, y); | |
172 | ||
68d02db3 VZ |
173 | // account for the possible toolbar |
174 | wxPoint pt = GetClientAreaOrigin(); | |
175 | if ( x ) | |
176 | *x -= pt.x; | |
177 | ||
178 | if ( y ) | |
179 | *y -= pt.y; | |
180 | ||
d4597e13 VZ |
181 | #if wxUSE_STATUSBAR |
182 | // adjust client area height to take the status bar into account | |
183 | if ( y ) | |
184 | { | |
185 | wxStatusBar *statbar = GetStatusBar(); | |
186 | if ( statbar && statbar->IsShown() ) | |
187 | { | |
188 | *y -= statbar->GetClientSize().y; | |
189 | } | |
190 | } | |
191 | #endif // wxUSE_STATUSBAR | |
192 | } | |
193 | ||
7c0ea335 | 194 | // ---------------------------------------------------------------------------- |
0d53fc34 | 195 | // wxFrame: various geometry-related functions |
7c0ea335 VZ |
196 | // ---------------------------------------------------------------------------- |
197 | ||
0d53fc34 | 198 | void wxFrame::Raise() |
c48926e1 VZ |
199 | { |
200 | #ifdef __WIN16__ | |
201 | // no SetForegroundWindow() in Win16 | |
202 | wxFrameBase::Raise(); | |
203 | #else // Win32 | |
204 | ::SetForegroundWindow(GetHwnd()); | |
205 | #endif // Win16/32 | |
206 | } | |
207 | ||
67bd5bad | 208 | // generate an artificial resize event |
0d53fc34 | 209 | void wxFrame::SendSizeEvent() |
67bd5bad | 210 | { |
67bd5bad GT |
211 | if ( !m_iconized ) |
212 | { | |
82c9f85c VZ |
213 | RECT r = wxGetWindowRect(GetHwnd()); |
214 | ||
67bd5bad GT |
215 | (void)::PostMessage(GetHwnd(), WM_SIZE, |
216 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
217 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
218 | } | |
219 | } | |
220 | ||
d427503c | 221 | #if wxUSE_STATUSBAR |
0d53fc34 | 222 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, |
7c0ea335 VZ |
223 | long style, |
224 | wxWindowID id, | |
225 | const wxString& name) | |
2bda0e17 KB |
226 | { |
227 | wxStatusBar *statusBar = NULL; | |
228 | ||
47d67540 | 229 | #if wxUSE_NATIVE_STATUSBAR |
1f0500b3 | 230 | if ( !UsesNativeStatusBar() ) |
2bda0e17 | 231 | { |
1f0500b3 | 232 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); |
2bda0e17 KB |
233 | } |
234 | else | |
235 | #endif | |
236 | { | |
1f0500b3 VZ |
237 | statusBar = new wxStatusBar(this, id, style, name); |
238 | } | |
ed791986 | 239 | |
1f0500b3 | 240 | statusBar->SetFieldsCount(number); |
2bda0e17 | 241 | |
7c0ea335 | 242 | return statusBar; |
2bda0e17 KB |
243 | } |
244 | ||
0d53fc34 | 245 | void wxFrame::PositionStatusBar() |
2bda0e17 | 246 | { |
d4597e13 | 247 | if ( !m_frameStatusBar || !m_frameStatusBar->IsShown() ) |
ed791986 VZ |
248 | return; |
249 | ||
cbc66a27 VZ |
250 | int w, h; |
251 | GetClientSize(&w, &h); | |
252 | int sw, sh; | |
253 | m_frameStatusBar->GetSize(&sw, &sh); | |
254 | ||
255 | // Since we wish the status bar to be directly under the client area, | |
256 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
257 | m_frameStatusBar->SetSize(0, h, w, sh); | |
2bda0e17 | 258 | } |
d427503c | 259 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 260 | |
6522713c | 261 | #if wxUSE_MENUS_NATIVE |
ea9a4296 | 262 | |
0d53fc34 | 263 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) |
2bda0e17 | 264 | { |
f008af16 | 265 | wxFrameBase::AttachMenuBar(menubar); |
6beb85c0 | 266 | |
f6bcfd97 | 267 | if ( !menubar ) |
c2dcfdef | 268 | { |
f6bcfd97 BP |
269 | // actually remove the menu from the frame |
270 | m_hMenu = (WXHMENU)0; | |
271 | InternalSetMenuBar(); | |
065de612 | 272 | } |
f6bcfd97 | 273 | else // set new non NULL menu bar |
065de612 | 274 | { |
f6bcfd97 | 275 | // Can set a menubar several times. |
f6bcfd97 BP |
276 | if ( menubar->GetHMenu() ) |
277 | { | |
278 | m_hMenu = menubar->GetHMenu(); | |
279 | } | |
f008af16 | 280 | else // no HMENU yet |
f6bcfd97 | 281 | { |
f6bcfd97 | 282 | m_hMenu = menubar->Create(); |
065de612 | 283 | |
f6bcfd97 | 284 | if ( !m_hMenu ) |
f008af16 VZ |
285 | { |
286 | wxFAIL_MSG( _T("failed to create menu bar") ); | |
f6bcfd97 | 287 | return; |
f008af16 | 288 | } |
f6bcfd97 | 289 | } |
065de612 | 290 | |
f6bcfd97 | 291 | InternalSetMenuBar(); |
1e6feb95 | 292 | } |
2bda0e17 KB |
293 | } |
294 | ||
0d53fc34 | 295 | void wxFrame::InternalSetMenuBar() |
2bda0e17 | 296 | { |
04ef50df | 297 | #ifndef __WXMICROWIN__ |
42e69d6b | 298 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) |
2bda0e17 | 299 | { |
f6bcfd97 | 300 | wxLogLastError(wxT("SetMenu")); |
2bda0e17 | 301 | } |
04ef50df | 302 | #endif |
2bda0e17 KB |
303 | } |
304 | ||
1e6feb95 VZ |
305 | #endif // wxUSE_MENUS_NATIVE |
306 | ||
2bda0e17 | 307 | // Responds to colour changes, and passes event on to children. |
0d53fc34 | 308 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) |
2bda0e17 | 309 | { |
a756f210 | 310 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
2bda0e17 KB |
311 | Refresh(); |
312 | ||
1e6feb95 | 313 | #if wxUSE_STATUSBAR |
2bda0e17 KB |
314 | if ( m_frameStatusBar ) |
315 | { | |
316 | wxSysColourChangedEvent event2; | |
317 | event2.SetEventObject( m_frameStatusBar ); | |
02800301 | 318 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); |
2bda0e17 | 319 | } |
1e6feb95 | 320 | #endif // wxUSE_STATUSBAR |
2bda0e17 KB |
321 | |
322 | // Propagate the event to the non-top-level children | |
323 | wxWindow::OnSysColourChanged(event); | |
324 | } | |
325 | ||
a2327a9f | 326 | // Pass TRUE to show full screen, FALSE to restore. |
0d53fc34 | 327 | bool wxFrame::ShowFullScreen(bool show, long style) |
a2327a9f | 328 | { |
c641b1d2 VS |
329 | if ( IsFullScreen() == show ) |
330 | return FALSE; | |
331 | ||
a2327a9f JS |
332 | if (show) |
333 | { | |
1e6feb95 | 334 | #if wxUSE_TOOLBAR |
f6bcfd97 | 335 | wxToolBar *theToolBar = GetToolBar(); |
a2327a9f | 336 | if (theToolBar) |
1e6feb95 | 337 | theToolBar->GetSize(NULL, &m_fsToolBarHeight); |
a2327a9f JS |
338 | |
339 | // zap the toolbar, menubar, and statusbar | |
340 | ||
341 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
342 | { | |
343 | theToolBar->SetSize(-1,0); | |
344 | theToolBar->Show(FALSE); | |
345 | } | |
1e6feb95 | 346 | #endif // wxUSE_TOOLBAR |
a2327a9f | 347 | |
04ef50df | 348 | #ifndef __WXMICROWIN__ |
a2327a9f JS |
349 | if (style & wxFULLSCREEN_NOMENUBAR) |
350 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
04ef50df | 351 | #endif |
a2327a9f | 352 | |
1e6feb95 VZ |
353 | #if wxUSE_STATUSBAR |
354 | wxStatusBar *theStatusBar = GetStatusBar(); | |
355 | if (theStatusBar) | |
356 | theStatusBar->GetSize(NULL, &m_fsStatusBarHeight); | |
357 | ||
a2327a9f JS |
358 | // Save the number of fields in the statusbar |
359 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
360 | { | |
579b10c2 JS |
361 | //m_fsStatusBarFields = theStatusBar->GetFieldsCount(); |
362 | //SetStatusBar((wxStatusBar*) NULL); | |
363 | //delete theStatusBar; | |
364 | theStatusBar->Show(FALSE); | |
a2327a9f JS |
365 | } |
366 | else | |
367 | m_fsStatusBarFields = 0; | |
1e6feb95 | 368 | #endif // wxUSE_STATUSBAR |
a2327a9f JS |
369 | } |
370 | else | |
371 | { | |
1e6feb95 | 372 | #if wxUSE_TOOLBAR |
a2327a9f JS |
373 | wxToolBar *theToolBar = GetToolBar(); |
374 | ||
375 | // restore the toolbar, menubar, and statusbar | |
376 | if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
377 | { | |
378 | theToolBar->SetSize(-1, m_fsToolBarHeight); | |
379 | theToolBar->Show(TRUE); | |
380 | } | |
1e6feb95 | 381 | #endif // wxUSE_TOOLBAR |
a2327a9f | 382 | |
1e6feb95 VZ |
383 | #if wxUSE_STATUSBAR |
384 | if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR ) | |
a2327a9f | 385 | { |
579b10c2 JS |
386 | //CreateStatusBar(m_fsStatusBarFields); |
387 | if (GetStatusBar()) | |
388 | { | |
389 | GetStatusBar()->Show(TRUE); | |
390 | PositionStatusBar(); | |
391 | } | |
a2327a9f | 392 | } |
1e6feb95 | 393 | #endif // wxUSE_STATUSBAR |
a2327a9f | 394 | |
04ef50df | 395 | #ifndef __WXMICROWIN__ |
a2327a9f JS |
396 | if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) |
397 | SetMenu((HWND)GetHWND(), (HMENU)m_hMenu); | |
04ef50df | 398 | #endif |
a2327a9f | 399 | } |
c641b1d2 VS |
400 | |
401 | return wxFrameBase::ShowFullScreen(show, style); | |
a2327a9f JS |
402 | } |
403 | ||
2bda0e17 KB |
404 | // Default activation behaviour - set the focus for the first child |
405 | // subwindow found. | |
0d53fc34 | 406 | void wxFrame::OnActivate(wxActivateEvent& event) |
2bda0e17 | 407 | { |
f6bcfd97 | 408 | if ( event.GetActive() ) |
00c4e897 | 409 | { |
f6bcfd97 | 410 | // restore focus to the child which was last focused |
0d53fc34 | 411 | wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd); |
00c4e897 | 412 | |
e9456d8d VZ |
413 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() |
414 | : NULL; | |
415 | if ( !parent ) | |
416 | { | |
417 | parent = this; | |
418 | } | |
419 | ||
420 | wxSetFocusToChild(parent, &m_winLastFocused); | |
00c4e897 | 421 | } |
e9456d8d | 422 | else // deactivating |
2bda0e17 | 423 | { |
e9456d8d | 424 | // remember the last focused child if it is our child |
f6bcfd97 | 425 | m_winLastFocused = FindFocus(); |
e9456d8d VZ |
426 | |
427 | // so we NULL it out if it's a child from some other frame | |
428 | wxWindow *win = m_winLastFocused; | |
429 | while ( win ) | |
319fefa9 | 430 | { |
e9456d8d VZ |
431 | if ( win->IsTopLevel() ) |
432 | { | |
433 | if ( win != this ) | |
434 | { | |
435 | m_winLastFocused = NULL; | |
436 | } | |
437 | ||
f6bcfd97 | 438 | break; |
e9456d8d | 439 | } |
f6bcfd97 | 440 | |
e9456d8d | 441 | win = win->GetParent(); |
319fefa9 | 442 | } |
f6bcfd97 BP |
443 | |
444 | wxLogTrace(_T("focus"), | |
0d53fc34 | 445 | _T("wxFrame %08x deactivated, last focused: %08x."), |
f6bcfd97 BP |
446 | m_hWnd, |
447 | m_winLastFocused ? GetHwndOf(m_winLastFocused) | |
448 | : NULL); | |
449 | ||
450 | event.Skip(); | |
2bda0e17 | 451 | } |
2bda0e17 KB |
452 | } |
453 | ||
7c0ea335 VZ |
454 | // ---------------------------------------------------------------------------- |
455 | // tool/status bar stuff | |
456 | // ---------------------------------------------------------------------------- | |
457 | ||
d427503c | 458 | #if wxUSE_TOOLBAR |
7c0ea335 | 459 | |
0d53fc34 | 460 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
81d66cf3 | 461 | { |
7c0ea335 | 462 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
81d66cf3 | 463 | { |
81d66cf3 | 464 | PositionToolBar(); |
81d66cf3 | 465 | } |
81d66cf3 | 466 | |
7c0ea335 | 467 | return m_frameToolBar; |
81d66cf3 JS |
468 | } |
469 | ||
0d53fc34 | 470 | void wxFrame::PositionToolBar() |
81d66cf3 | 471 | { |
d4597e13 VZ |
472 | wxToolBar *toolbar = GetToolBar(); |
473 | if ( toolbar && toolbar->IsShown() ) | |
474 | { | |
475 | // don't call our (or even wxTopLevelWindow) version because we want | |
476 | // the real (full) client area size, not excluding the tool/status bar | |
477 | int width, height; | |
478 | wxWindow::DoGetClientSize(&width, &height); | |
81d66cf3 | 479 | |
7c0ea335 | 480 | #if wxUSE_STATUSBAR |
d4597e13 VZ |
481 | wxStatusBar *statbar = GetStatusBar(); |
482 | if ( statbar && statbar->IsShown() ) | |
483 | { | |
484 | height -= statbar->GetClientSize().y; | |
485 | } | |
7c0ea335 | 486 | #endif // wxUSE_STATUSBAR |
81d66cf3 | 487 | |
81d66cf3 | 488 | int tw, th; |
d4597e13 | 489 | toolbar->GetSize(&tw, &th); |
81d66cf3 | 490 | |
d4597e13 | 491 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) |
81d66cf3 | 492 | { |
d4597e13 | 493 | th = height; |
81d66cf3 JS |
494 | } |
495 | else | |
496 | { | |
d4597e13 | 497 | tw = width; |
98b96436 RR |
498 | if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT ) |
499 | th -= 3; | |
81d66cf3 | 500 | } |
7c0ea335 | 501 | |
d4597e13 VZ |
502 | // use the 'real' MSW position here, don't offset relativly to the |
503 | // client area origin | |
504 | toolbar->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); | |
81d66cf3 JS |
505 | } |
506 | } | |
d4597e13 | 507 | |
d427503c | 508 | #endif // wxUSE_TOOLBAR |
d2aef312 | 509 | |
7c0ea335 VZ |
510 | // ---------------------------------------------------------------------------- |
511 | // frame state (iconized/maximized/...) | |
512 | // ---------------------------------------------------------------------------- | |
513 | ||
a23fd0e1 VZ |
514 | // propagate our state change to all child frames: this allows us to emulate X |
515 | // Windows behaviour where child frames float independently of the parent one | |
516 | // on the desktop, but are iconized/restored with it | |
0d53fc34 | 517 | void wxFrame::IconizeChildFrames(bool bIconize) |
d2aef312 | 518 | { |
a23fd0e1 VZ |
519 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
520 | node; | |
521 | node = node->GetNext() ) | |
522 | { | |
523 | wxWindow *win = node->GetData(); | |
524 | ||
3ca6a5f0 BP |
525 | // iconizing the frames with this style under Win95 shell puts them at |
526 | // the bottom of the screen (as the MDI children) instead of making | |
527 | // them appear in the taskbar because they are, by virtue of this | |
528 | // style, not managed by the taskbar - instead leave Windows take care | |
529 | // of them | |
530 | #ifdef __WIN95__ | |
531 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) | |
532 | continue; | |
533 | #endif // Win95 | |
534 | ||
3f7bc32b VZ |
535 | // the child MDI frames are a special case and should not be touched by |
536 | // the parent frame - instead, they are managed by the user | |
2e9f62da | 537 | wxFrame *frame = wxDynamicCast(win, wxFrame); |
1e6feb95 VZ |
538 | if ( frame |
539 | #if wxUSE_MDI_ARCHITECTURE | |
540 | && !wxDynamicCast(frame, wxMDIChildFrame) | |
541 | #endif // wxUSE_MDI_ARCHITECTURE | |
542 | ) | |
a23fd0e1 | 543 | { |
9327c3aa VZ |
544 | // we don't want to restore the child frames which had been |
545 | // iconized even before we were iconized, so save the child frame | |
546 | // status when iconizing the parent frame and check it when | |
547 | // restoring it | |
548 | if ( bIconize ) | |
549 | { | |
d7d02962 VZ |
550 | // note that we shouldn't touch the hidden frames neither |
551 | // because iconizing/restoring them would show them as a side | |
552 | // effect | |
553 | frame->m_wasMinimized = frame->IsIconized() || !frame->IsShown(); | |
9327c3aa VZ |
554 | } |
555 | ||
556 | // this test works for both iconizing and restoring | |
557 | if ( !frame->m_wasMinimized ) | |
558 | frame->Iconize(bIconize); | |
a23fd0e1 | 559 | } |
d2aef312 | 560 | } |
d2aef312 VZ |
561 | } |
562 | ||
0d53fc34 | 563 | WXHICON wxFrame::GetDefaultIcon() const |
82c9f85c VZ |
564 | { |
565 | return (WXHICON)(wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON | |
566 | : wxDEFAULT_FRAME_ICON); | |
567 | } | |
568 | ||
a23fd0e1 | 569 | // =========================================================================== |
42e69d6b | 570 | // message processing |
a23fd0e1 VZ |
571 | // =========================================================================== |
572 | ||
42e69d6b VZ |
573 | // --------------------------------------------------------------------------- |
574 | // preprocessing | |
575 | // --------------------------------------------------------------------------- | |
576 | ||
0d53fc34 | 577 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) |
42e69d6b VZ |
578 | { |
579 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
580 | return TRUE; | |
581 | ||
1e6feb95 | 582 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) |
42e69d6b VZ |
583 | // try the menu bar accels |
584 | wxMenuBar *menuBar = GetMenuBar(); | |
585 | if ( !menuBar ) | |
586 | return FALSE; | |
587 | ||
588 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
c50f1fb9 | 589 | return acceleratorTable.Translate(this, pMsg); |
1e6feb95 VZ |
590 | #else |
591 | return FALSE; | |
592 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
42e69d6b VZ |
593 | } |
594 | ||
595 | // --------------------------------------------------------------------------- | |
596 | // our private (non virtual) message handlers | |
597 | // --------------------------------------------------------------------------- | |
598 | ||
0d53fc34 | 599 | bool wxFrame::HandlePaint() |
42e69d6b VZ |
600 | { |
601 | RECT rect; | |
602 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
603 | { | |
04ef50df | 604 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
605 | if ( m_iconized ) |
606 | { | |
f618020a MB |
607 | const wxIcon& icon = GetIcon(); |
608 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
609 | : (HICON)GetDefaultIcon(); | |
42e69d6b VZ |
610 | |
611 | // Hold a pointer to the dc so long as the OnPaint() message | |
612 | // is being processed | |
613 | PAINTSTRUCT ps; | |
614 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
615 | ||
616 | // Erase background before painting or we get white background | |
617 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
618 | ||
619 | if ( hIcon ) | |
620 | { | |
621 | RECT rect; | |
622 | ::GetClientRect(GetHwnd(), &rect); | |
623 | ||
624 | // FIXME: why hardcoded? | |
625 | static const int icon_width = 32; | |
626 | static const int icon_height = 32; | |
627 | ||
628 | int icon_x = (int)((rect.right - icon_width)/2); | |
629 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
630 | ||
631 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
632 | } | |
633 | ||
634 | ::EndPaint(GetHwnd(), &ps); | |
635 | ||
636 | return TRUE; | |
637 | } | |
638 | else | |
04ef50df | 639 | #endif |
42e69d6b | 640 | { |
5d1d2d46 | 641 | return wxWindow::HandlePaint(); |
42e69d6b VZ |
642 | } |
643 | } | |
644 | else | |
645 | { | |
646 | // nothing to paint - processed | |
647 | return TRUE; | |
648 | } | |
649 | } | |
650 | ||
0d53fc34 | 651 | bool wxFrame::HandleSize(int x, int y, WXUINT id) |
42e69d6b VZ |
652 | { |
653 | bool processed = FALSE; | |
04ef50df | 654 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
655 | |
656 | switch ( id ) | |
657 | { | |
658 | case SIZENORMAL: | |
659 | // only do it it if we were iconized before, otherwise resizing the | |
660 | // parent frame has a curious side effect of bringing it under it's | |
661 | // children | |
662 | if ( !m_iconized ) | |
663 | break; | |
664 | ||
665 | // restore all child frames too | |
666 | IconizeChildFrames(FALSE); | |
667 | ||
3dd9b88a VZ |
668 | (void)SendIconizeEvent(FALSE); |
669 | ||
42e69d6b VZ |
670 | // fall through |
671 | ||
672 | case SIZEFULLSCREEN: | |
673 | m_iconized = FALSE; | |
674 | break; | |
675 | ||
676 | case SIZEICONIC: | |
677 | // iconize all child frames too | |
678 | IconizeChildFrames(TRUE); | |
679 | ||
3dd9b88a VZ |
680 | (void)SendIconizeEvent(); |
681 | ||
42e69d6b VZ |
682 | m_iconized = TRUE; |
683 | break; | |
684 | } | |
04ef50df | 685 | #endif |
42e69d6b VZ |
686 | |
687 | if ( !m_iconized ) | |
688 | { | |
1e6feb95 | 689 | #if wxUSE_STATUSBAR |
42e69d6b | 690 | PositionStatusBar(); |
1e6feb95 VZ |
691 | #endif // wxUSE_STATUSBAR |
692 | ||
693 | #if wxUSE_TOOLBAR | |
42e69d6b | 694 | PositionToolBar(); |
1e6feb95 | 695 | #endif // wxUSE_TOOLBAR |
42e69d6b VZ |
696 | |
697 | wxSizeEvent event(wxSize(x, y), m_windowId); | |
698 | event.SetEventObject( this ); | |
699 | processed = GetEventHandler()->ProcessEvent(event); | |
700 | } | |
701 | ||
702 | return processed; | |
703 | } | |
704 | ||
0d53fc34 | 705 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) |
42e69d6b VZ |
706 | { |
707 | if ( control ) | |
708 | { | |
709 | // In case it's e.g. a toolbar. | |
710 | wxWindow *win = wxFindWinFromHandle(control); | |
711 | if ( win ) | |
712 | return win->MSWCommand(cmd, id); | |
713 | } | |
714 | ||
715 | // handle here commands from menus and accelerators | |
716 | if ( cmd == 0 || cmd == 1 ) | |
717 | { | |
1e6feb95 | 718 | #if wxUSE_MENUS_NATIVE |
42e69d6b VZ |
719 | if ( wxCurrentPopupMenu ) |
720 | { | |
721 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
722 | wxCurrentPopupMenu = NULL; | |
723 | ||
724 | return popupMenu->MSWCommand(cmd, id); | |
725 | } | |
1e6feb95 | 726 | #endif // wxUSE_MENUS_NATIVE |
42e69d6b VZ |
727 | |
728 | if ( ProcessCommand(id) ) | |
729 | { | |
730 | return TRUE; | |
731 | } | |
732 | } | |
733 | ||
734 | return FALSE; | |
735 | } | |
736 | ||
0d53fc34 | 737 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) |
a23fd0e1 VZ |
738 | { |
739 | int item; | |
c219cecc | 740 | if ( flags == 0xFFFF && hMenu == 0 ) |
a23fd0e1 | 741 | { |
c219cecc | 742 | // menu was removed from screen |
a23fd0e1 VZ |
743 | item = -1; |
744 | } | |
04ef50df | 745 | #ifndef __WXMICROWIN__ |
c219cecc | 746 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) |
a23fd0e1 VZ |
747 | { |
748 | item = nItem; | |
749 | } | |
04ef50df | 750 | #endif |
a23fd0e1 VZ |
751 | else |
752 | { | |
1e6feb95 | 753 | #if wxUSE_STATUSBAR |
c219cecc | 754 | // don't give hints for separators (doesn't make sense) nor for the |
f6bcfd97 BP |
755 | // items opening popup menus (they don't have them anyhow) but do clear |
756 | // the status line - otherwise, we would be left with the help message | |
757 | // for the previous item which doesn't apply any more | |
758 | wxStatusBar *statbar = GetStatusBar(); | |
759 | if ( statbar ) | |
760 | { | |
761 | statbar->SetStatusText(wxEmptyString); | |
762 | } | |
1e6feb95 | 763 | #endif // wxUSE_STATUSBAR |
f6bcfd97 | 764 | |
a23fd0e1 VZ |
765 | return FALSE; |
766 | } | |
767 | ||
768 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
ccef86c7 VZ |
769 | event.SetEventObject(this); |
770 | ||
771 | return GetEventHandler()->ProcessEvent(event); | |
772 | } | |
773 | ||
774 | bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup) | |
775 | { | |
776 | // we don't have the menu id here, so we use the id to specify if the event | |
777 | // was from a popup menu or a normal one | |
778 | wxMenuEvent event(evtType, isPopup ? -1 : 0); | |
779 | event.SetEventObject(this); | |
a23fd0e1 VZ |
780 | |
781 | return GetEventHandler()->ProcessEvent(event); | |
782 | } | |
783 | ||
784 | // --------------------------------------------------------------------------- | |
0d53fc34 | 785 | // the window proc for wxFrame |
a23fd0e1 VZ |
786 | // --------------------------------------------------------------------------- |
787 | ||
0d53fc34 | 788 | long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
a23fd0e1 VZ |
789 | { |
790 | long rc = 0; | |
791 | bool processed = FALSE; | |
792 | ||
793 | switch ( message ) | |
794 | { | |
42e69d6b VZ |
795 | case WM_CLOSE: |
796 | // if we can't close, tell the system that we processed the | |
797 | // message - otherwise it would close us | |
798 | processed = !Close(); | |
799 | break; | |
800 | ||
ccef86c7 VZ |
801 | case WM_SIZE: |
802 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
803 | break; | |
804 | ||
42e69d6b VZ |
805 | case WM_COMMAND: |
806 | { | |
807 | WORD id, cmd; | |
808 | WXHWND hwnd; | |
809 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
810 | &id, &hwnd, &cmd); | |
811 | ||
812 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
813 | } | |
814 | break; | |
815 | ||
ccef86c7 VZ |
816 | case WM_PAINT: |
817 | processed = HandlePaint(); | |
818 | break; | |
819 | ||
04ef50df | 820 | #ifndef __WXMICROWIN__ |
a23fd0e1 VZ |
821 | case WM_MENUSELECT: |
822 | { | |
42e69d6b VZ |
823 | WXWORD item, flags; |
824 | WXHMENU hmenu; | |
825 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
826 | ||
827 | processed = HandleMenuSelect(item, flags, hmenu); | |
a23fd0e1 VZ |
828 | } |
829 | break; | |
42e69d6b | 830 | |
ccef86c7 VZ |
831 | #ifndef __WIN16__ |
832 | case WM_ENTERMENULOOP: | |
833 | processed = HandleMenuLoop(wxEVT_MENU_OPEN, wParam); | |
42e69d6b VZ |
834 | break; |
835 | ||
ccef86c7 VZ |
836 | case WM_EXITMENULOOP: |
837 | processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam); | |
838 | break; | |
839 | #endif // __WIN16__ | |
840 | ||
42e69d6b VZ |
841 | case WM_QUERYDRAGICON: |
842 | { | |
f618020a MB |
843 | const wxIcon& icon = GetIcon(); |
844 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
845 | : (HICON)GetDefaultIcon(); | |
42e69d6b VZ |
846 | rc = (long)hIcon; |
847 | processed = rc != 0; | |
848 | } | |
849 | break; | |
ccef86c7 | 850 | #endif // !__WXMICROWIN__ |
a23fd0e1 VZ |
851 | } |
852 | ||
853 | if ( !processed ) | |
854 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
855 | ||
856 | return rc; | |
857 | } | |
21802234 | 858 |