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