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