]>
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 | |
229de929 | 477 | int tx, ty; |
81d66cf3 | 478 | int tw, th; |
229de929 | 479 | toolbar->GetPosition(&tx, &ty); |
d4597e13 | 480 | toolbar->GetSize(&tw, &th); |
229de929 JS |
481 | |
482 | // Adjust | |
483 | if (ty < 0 && (-ty == th)) | |
484 | ty = 0; | |
485 | if (tx < 0 && (-tx == tw)) | |
486 | tx = 0; | |
487 | ||
488 | int desiredW = tw; | |
489 | int desiredH = th; | |
81d66cf3 | 490 | |
d4597e13 | 491 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) |
81d66cf3 | 492 | { |
229de929 | 493 | desiredH = height; |
81d66cf3 JS |
494 | } |
495 | else | |
496 | { | |
229de929 JS |
497 | desiredW = width; |
498 | // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT ) | |
499 | // desiredW -= 3; | |
500 | } | |
7c0ea335 | 501 | |
d4597e13 VZ |
502 | // use the 'real' MSW position here, don't offset relativly to the |
503 | // client area origin | |
229de929 JS |
504 | |
505 | // Optimise such that we don't have to always resize the toolbar | |
506 | // when the frame changes, otherwise we'll get a lot of flicker. | |
507 | bool heightChanging = TRUE; | |
508 | bool widthChanging = TRUE; | |
509 | ||
510 | if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
511 | { | |
512 | // It's OK if the current height is greater than what can be shown. | |
513 | heightChanging = (desiredH > th) ; | |
514 | widthChanging = (desiredW != tw) ; | |
515 | ||
516 | // The next time around, we may not have to set the size | |
517 | if (heightChanging) | |
518 | desiredH = desiredH + 200; | |
519 | } | |
520 | else | |
521 | { | |
522 | // It's OK if the current width is greater than what can be shown. | |
523 | widthChanging = (desiredW > tw) ; | |
524 | heightChanging = (desiredH != th) ; | |
525 | ||
526 | // The next time around, we may not have to set the size | |
527 | if (widthChanging) | |
528 | desiredW = desiredW + 200; | |
529 | } | |
530 | ||
531 | if (tx != 0 || ty != 0 || widthChanging || heightChanging) | |
532 | toolbar->SetSize(0, 0, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS); | |
533 | ||
09785dd3 | 534 | #endif // __WXWINCE__ |
81d66cf3 JS |
535 | } |
536 | } | |
d4597e13 | 537 | |
d427503c | 538 | #endif // wxUSE_TOOLBAR |
d2aef312 | 539 | |
7c0ea335 VZ |
540 | // ---------------------------------------------------------------------------- |
541 | // frame state (iconized/maximized/...) | |
542 | // ---------------------------------------------------------------------------- | |
543 | ||
a23fd0e1 VZ |
544 | // propagate our state change to all child frames: this allows us to emulate X |
545 | // Windows behaviour where child frames float independently of the parent one | |
546 | // on the desktop, but are iconized/restored with it | |
0d53fc34 | 547 | void wxFrame::IconizeChildFrames(bool bIconize) |
d2aef312 | 548 | { |
222ed1d6 | 549 | for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
a23fd0e1 VZ |
550 | node; |
551 | node = node->GetNext() ) | |
552 | { | |
553 | wxWindow *win = node->GetData(); | |
554 | ||
3ca6a5f0 BP |
555 | // iconizing the frames with this style under Win95 shell puts them at |
556 | // the bottom of the screen (as the MDI children) instead of making | |
557 | // them appear in the taskbar because they are, by virtue of this | |
558 | // style, not managed by the taskbar - instead leave Windows take care | |
559 | // of them | |
560 | #ifdef __WIN95__ | |
561 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) | |
562 | continue; | |
563 | #endif // Win95 | |
564 | ||
3f7bc32b VZ |
565 | // the child MDI frames are a special case and should not be touched by |
566 | // the parent frame - instead, they are managed by the user | |
2e9f62da | 567 | wxFrame *frame = wxDynamicCast(win, wxFrame); |
1e6feb95 VZ |
568 | if ( frame |
569 | #if wxUSE_MDI_ARCHITECTURE | |
570 | && !wxDynamicCast(frame, wxMDIChildFrame) | |
571 | #endif // wxUSE_MDI_ARCHITECTURE | |
572 | ) | |
a23fd0e1 | 573 | { |
9327c3aa VZ |
574 | // we don't want to restore the child frames which had been |
575 | // iconized even before we were iconized, so save the child frame | |
576 | // status when iconizing the parent frame and check it when | |
577 | // restoring it | |
578 | if ( bIconize ) | |
579 | { | |
d7d02962 VZ |
580 | // note that we shouldn't touch the hidden frames neither |
581 | // because iconizing/restoring them would show them as a side | |
582 | // effect | |
583 | frame->m_wasMinimized = frame->IsIconized() || !frame->IsShown(); | |
9327c3aa VZ |
584 | } |
585 | ||
586 | // this test works for both iconizing and restoring | |
587 | if ( !frame->m_wasMinimized ) | |
588 | frame->Iconize(bIconize); | |
a23fd0e1 | 589 | } |
d2aef312 | 590 | } |
d2aef312 VZ |
591 | } |
592 | ||
0d53fc34 | 593 | WXHICON wxFrame::GetDefaultIcon() const |
82c9f85c | 594 | { |
94826170 VZ |
595 | // we don't have any standard icons (any more) |
596 | return (WXHICON)0; | |
82c9f85c VZ |
597 | } |
598 | ||
a23fd0e1 | 599 | // =========================================================================== |
42e69d6b | 600 | // message processing |
a23fd0e1 VZ |
601 | // =========================================================================== |
602 | ||
42e69d6b VZ |
603 | // --------------------------------------------------------------------------- |
604 | // preprocessing | |
605 | // --------------------------------------------------------------------------- | |
606 | ||
0d53fc34 | 607 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) |
42e69d6b VZ |
608 | { |
609 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
610 | return TRUE; | |
611 | ||
1e6feb95 | 612 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) |
42e69d6b VZ |
613 | // try the menu bar accels |
614 | wxMenuBar *menuBar = GetMenuBar(); | |
615 | if ( !menuBar ) | |
616 | return FALSE; | |
617 | ||
618 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
c50f1fb9 | 619 | return acceleratorTable.Translate(this, pMsg); |
1e6feb95 VZ |
620 | #else |
621 | return FALSE; | |
622 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
42e69d6b VZ |
623 | } |
624 | ||
625 | // --------------------------------------------------------------------------- | |
626 | // our private (non virtual) message handlers | |
627 | // --------------------------------------------------------------------------- | |
628 | ||
0d53fc34 | 629 | bool wxFrame::HandlePaint() |
42e69d6b VZ |
630 | { |
631 | RECT rect; | |
632 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
633 | { | |
4676948b | 634 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
42e69d6b VZ |
635 | if ( m_iconized ) |
636 | { | |
f618020a MB |
637 | const wxIcon& icon = GetIcon(); |
638 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
639 | : (HICON)GetDefaultIcon(); | |
42e69d6b VZ |
640 | |
641 | // Hold a pointer to the dc so long as the OnPaint() message | |
642 | // is being processed | |
643 | PAINTSTRUCT ps; | |
644 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
645 | ||
646 | // Erase background before painting or we get white background | |
647 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
648 | ||
649 | if ( hIcon ) | |
650 | { | |
651 | RECT rect; | |
652 | ::GetClientRect(GetHwnd(), &rect); | |
653 | ||
654 | // FIXME: why hardcoded? | |
655 | static const int icon_width = 32; | |
656 | static const int icon_height = 32; | |
657 | ||
658 | int icon_x = (int)((rect.right - icon_width)/2); | |
659 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
660 | ||
661 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
662 | } | |
663 | ||
664 | ::EndPaint(GetHwnd(), &ps); | |
665 | ||
666 | return TRUE; | |
667 | } | |
668 | else | |
04ef50df | 669 | #endif |
42e69d6b | 670 | { |
5d1d2d46 | 671 | return wxWindow::HandlePaint(); |
42e69d6b VZ |
672 | } |
673 | } | |
674 | else | |
675 | { | |
676 | // nothing to paint - processed | |
677 | return TRUE; | |
678 | } | |
679 | } | |
680 | ||
0d53fc34 | 681 | bool wxFrame::HandleSize(int x, int y, WXUINT id) |
42e69d6b VZ |
682 | { |
683 | bool processed = FALSE; | |
4676948b | 684 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
42e69d6b VZ |
685 | |
686 | switch ( id ) | |
687 | { | |
688 | case SIZENORMAL: | |
689 | // only do it it if we were iconized before, otherwise resizing the | |
690 | // parent frame has a curious side effect of bringing it under it's | |
691 | // children | |
692 | if ( !m_iconized ) | |
693 | break; | |
694 | ||
695 | // restore all child frames too | |
696 | IconizeChildFrames(FALSE); | |
697 | ||
3dd9b88a VZ |
698 | (void)SendIconizeEvent(FALSE); |
699 | ||
42e69d6b VZ |
700 | // fall through |
701 | ||
702 | case SIZEFULLSCREEN: | |
703 | m_iconized = FALSE; | |
704 | break; | |
705 | ||
706 | case SIZEICONIC: | |
707 | // iconize all child frames too | |
708 | IconizeChildFrames(TRUE); | |
709 | ||
3dd9b88a VZ |
710 | (void)SendIconizeEvent(); |
711 | ||
42e69d6b VZ |
712 | m_iconized = TRUE; |
713 | break; | |
714 | } | |
04ef50df | 715 | #endif |
42e69d6b VZ |
716 | |
717 | if ( !m_iconized ) | |
718 | { | |
1e6feb95 | 719 | #if wxUSE_STATUSBAR |
42e69d6b | 720 | PositionStatusBar(); |
1e6feb95 VZ |
721 | #endif // wxUSE_STATUSBAR |
722 | ||
723 | #if wxUSE_TOOLBAR | |
42e69d6b | 724 | PositionToolBar(); |
1e6feb95 | 725 | #endif // wxUSE_TOOLBAR |
42e69d6b | 726 | |
4e4a5fed | 727 | processed = wxWindow::HandleSize(x, y, id); |
42e69d6b VZ |
728 | } |
729 | ||
730 | return processed; | |
731 | } | |
732 | ||
0d53fc34 | 733 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) |
42e69d6b VZ |
734 | { |
735 | if ( control ) | |
736 | { | |
737 | // In case it's e.g. a toolbar. | |
738 | wxWindow *win = wxFindWinFromHandle(control); | |
739 | if ( win ) | |
740 | return win->MSWCommand(cmd, id); | |
741 | } | |
742 | ||
743 | // handle here commands from menus and accelerators | |
744 | if ( cmd == 0 || cmd == 1 ) | |
745 | { | |
1e6feb95 | 746 | #if wxUSE_MENUS_NATIVE |
42e69d6b VZ |
747 | if ( wxCurrentPopupMenu ) |
748 | { | |
749 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
750 | wxCurrentPopupMenu = NULL; | |
751 | ||
752 | return popupMenu->MSWCommand(cmd, id); | |
753 | } | |
1e6feb95 | 754 | #endif // wxUSE_MENUS_NATIVE |
42e69d6b VZ |
755 | |
756 | if ( ProcessCommand(id) ) | |
757 | { | |
758 | return TRUE; | |
759 | } | |
760 | } | |
761 | ||
762 | return FALSE; | |
763 | } | |
764 | ||
0d53fc34 | 765 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) |
a23fd0e1 VZ |
766 | { |
767 | int item; | |
c219cecc | 768 | if ( flags == 0xFFFF && hMenu == 0 ) |
a23fd0e1 | 769 | { |
c219cecc | 770 | // menu was removed from screen |
a23fd0e1 VZ |
771 | item = -1; |
772 | } | |
04ef50df | 773 | #ifndef __WXMICROWIN__ |
c219cecc | 774 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) |
a23fd0e1 VZ |
775 | { |
776 | item = nItem; | |
777 | } | |
04ef50df | 778 | #endif |
a23fd0e1 VZ |
779 | else |
780 | { | |
c219cecc | 781 | // don't give hints for separators (doesn't make sense) nor for the |
f6bcfd97 BP |
782 | // items opening popup menus (they don't have them anyhow) but do clear |
783 | // the status line - otherwise, we would be left with the help message | |
784 | // for the previous item which doesn't apply any more | |
1f361cdd | 785 | DoGiveHelp(wxEmptyString, FALSE); |
f6bcfd97 | 786 | |
a23fd0e1 VZ |
787 | return FALSE; |
788 | } | |
789 | ||
790 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
ccef86c7 VZ |
791 | event.SetEventObject(this); |
792 | ||
793 | return GetEventHandler()->ProcessEvent(event); | |
794 | } | |
795 | ||
796 | bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup) | |
797 | { | |
798 | // we don't have the menu id here, so we use the id to specify if the event | |
799 | // was from a popup menu or a normal one | |
800 | wxMenuEvent event(evtType, isPopup ? -1 : 0); | |
801 | event.SetEventObject(this); | |
a23fd0e1 VZ |
802 | |
803 | return GetEventHandler()->ProcessEvent(event); | |
804 | } | |
805 | ||
806 | // --------------------------------------------------------------------------- | |
0d53fc34 | 807 | // the window proc for wxFrame |
a23fd0e1 VZ |
808 | // --------------------------------------------------------------------------- |
809 | ||
0d53fc34 | 810 | long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
a23fd0e1 VZ |
811 | { |
812 | long rc = 0; | |
813 | bool processed = FALSE; | |
814 | ||
815 | switch ( message ) | |
816 | { | |
42e69d6b VZ |
817 | case WM_CLOSE: |
818 | // if we can't close, tell the system that we processed the | |
819 | // message - otherwise it would close us | |
820 | processed = !Close(); | |
821 | break; | |
822 | ||
ccef86c7 VZ |
823 | case WM_SIZE: |
824 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
825 | break; | |
826 | ||
42e69d6b VZ |
827 | case WM_COMMAND: |
828 | { | |
829 | WORD id, cmd; | |
830 | WXHWND hwnd; | |
831 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
832 | &id, &hwnd, &cmd); | |
833 | ||
834 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
835 | } | |
836 | break; | |
837 | ||
ccef86c7 VZ |
838 | case WM_PAINT: |
839 | processed = HandlePaint(); | |
840 | break; | |
841 | ||
92f1a59c JS |
842 | case WM_INITMENUPOPUP: |
843 | processed = HandleInitMenuPopup((WXHMENU) wParam); | |
844 | break; | |
845 | ||
4676948b | 846 | #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__) |
a23fd0e1 VZ |
847 | case WM_MENUSELECT: |
848 | { | |
42e69d6b VZ |
849 | WXWORD item, flags; |
850 | WXHMENU hmenu; | |
851 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
852 | ||
853 | processed = HandleMenuSelect(item, flags, hmenu); | |
a23fd0e1 VZ |
854 | } |
855 | break; | |
bc92cdf9 | 856 | |
ccef86c7 VZ |
857 | case WM_EXITMENULOOP: |
858 | processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam); | |
859 | break; | |
ccef86c7 | 860 | |
42e69d6b VZ |
861 | case WM_QUERYDRAGICON: |
862 | { | |
f618020a MB |
863 | const wxIcon& icon = GetIcon(); |
864 | HICON hIcon = icon.Ok() ? GetHiconOf(icon) | |
865 | : (HICON)GetDefaultIcon(); | |
42e69d6b VZ |
866 | rc = (long)hIcon; |
867 | processed = rc != 0; | |
868 | } | |
869 | break; | |
ccef86c7 | 870 | #endif // !__WXMICROWIN__ |
a23fd0e1 VZ |
871 | } |
872 | ||
873 | if ( !processed ) | |
7e25f59e | 874 | rc = wxFrameBase::MSWWindowProc(message, wParam, lParam); |
a23fd0e1 VZ |
875 | |
876 | return rc; | |
877 | } | |
21802234 | 878 | |
92f1a59c JS |
879 | // handle WM_INITMENUPOPUP message |
880 | bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu) | |
e39af974 | 881 | { |
92f1a59c JS |
882 | wxMenu* menu = NULL; |
883 | if (GetMenuBar()) | |
884 | { | |
885 | int nCount = GetMenuBar()->GetMenuCount(); | |
886 | for (int n = 0; n < nCount; n++) | |
887 | { | |
888 | if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu) | |
889 | { | |
890 | menu = GetMenuBar()->GetMenu(n); | |
891 | break; | |
892 | } | |
893 | } | |
894 | } | |
895 | ||
896 | wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu); | |
e39af974 JS |
897 | event.SetEventObject(this); |
898 | ||
899 | return GetEventHandler()->ProcessEvent(event); | |
e39af974 | 900 | } |