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