]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
7c0ea335 | 2 | // Name: msw/frame.cpp |
2bda0e17 KB |
3 | // Purpose: wxFrame |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
7c0ea335 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
7c0ea335 | 21 | #pragma implementation "frame.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
9f3362c4 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
9f3362c4 VZ |
32 | #include "wx/setup.h" |
33 | #include "wx/frame.h" | |
34 | #include "wx/menu.h" | |
35 | #include "wx/app.h" | |
36 | #include "wx/utils.h" | |
37 | #include "wx/dialog.h" | |
38 | #include "wx/settings.h" | |
39 | #include "wx/dcclient.h" | |
d3cc7c65 | 40 | #include "wx/mdi.h" |
9f3362c4 | 41 | #endif // WX_PRECOMP |
2bda0e17 KB |
42 | |
43 | #include "wx/msw/private.h" | |
7c0ea335 VZ |
44 | |
45 | #if wxUSE_STATUSBAR | |
46 | #include "wx/statusbr.h" | |
ed791986 | 47 | #include "wx/generic/statusbr.h" |
7c0ea335 VZ |
48 | #endif // wxUSE_STATUSBAR |
49 | ||
50 | #if wxUSE_TOOLBAR | |
51 | #include "wx/toolbar.h" | |
52 | #endif // wxUSE_TOOLBAR | |
53 | ||
2bda0e17 | 54 | #include "wx/menuitem.h" |
6776a0b2 | 55 | #include "wx/log.h" |
2bda0e17 | 56 | |
7c0ea335 VZ |
57 | // ---------------------------------------------------------------------------- |
58 | // globals | |
59 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 60 | |
a23fd0e1 | 61 | extern wxWindowList wxModelessWindows; |
cde9f08e | 62 | extern wxList WXDLLEXPORT wxPendingDelete; |
2ffa221c | 63 | extern const wxChar *wxFrameClassName; |
e1a6fc11 | 64 | extern wxMenu *wxCurrentPopupMenu; |
2bda0e17 | 65 | |
7c0ea335 VZ |
66 | // ---------------------------------------------------------------------------- |
67 | // event tables | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
7c0ea335 VZ |
70 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
71 | EVT_ACTIVATE(wxFrame::OnActivate) | |
72 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
2bda0e17 KB |
73 | END_EVENT_TABLE() |
74 | ||
75 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) | |
2bda0e17 | 76 | |
7c0ea335 VZ |
77 | // ============================================================================ |
78 | // implementation | |
79 | // ============================================================================ | |
80 | ||
81 | // ---------------------------------------------------------------------------- | |
82 | // static class members | |
83 | // ---------------------------------------------------------------------------- | |
84 | ||
47d67540 | 85 | #if wxUSE_NATIVE_STATUSBAR |
9f3362c4 | 86 | bool wxFrame::m_useNativeStatusBar = TRUE; |
2bda0e17 | 87 | #else |
9f3362c4 | 88 | bool wxFrame::m_useNativeStatusBar = FALSE; |
2bda0e17 KB |
89 | #endif |
90 | ||
7c0ea335 VZ |
91 | // ---------------------------------------------------------------------------- |
92 | // creation/destruction | |
93 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 94 | |
7c0ea335 | 95 | void wxFrame::Init() |
2bda0e17 | 96 | { |
7c0ea335 VZ |
97 | m_iconized = FALSE; |
98 | ||
9f3362c4 VZ |
99 | #if wxUSE_TOOLTIPS |
100 | m_hwndToolTip = 0; | |
101 | #endif | |
a2327a9f JS |
102 | |
103 | // Data to save/restore when calling ShowFullScreen | |
104 | m_fsStyle = 0; | |
105 | m_fsOldWindowStyle = 0; | |
106 | m_fsStatusBarFields = 0; | |
107 | m_fsStatusBarHeight = 0; | |
108 | m_fsToolBarHeight = 0; | |
109 | // m_fsMenu = 0; | |
110 | m_fsIsMaximized = FALSE; | |
111 | m_fsIsShowing = FALSE; | |
7c0ea335 | 112 | } |
9f3362c4 | 113 | |
7c0ea335 VZ |
114 | bool wxFrame::Create(wxWindow *parent, |
115 | wxWindowID id, | |
116 | const wxString& title, | |
117 | const wxPoint& pos, | |
118 | const wxSize& size, | |
119 | long style, | |
120 | const wxString& name) | |
121 | { | |
2bda0e17 | 122 | SetName(name); |
2bda0e17 KB |
123 | m_windowStyle = style; |
124 | m_frameMenuBar = NULL; | |
7c0ea335 | 125 | m_frameToolBar = NULL; |
2bda0e17 KB |
126 | m_frameStatusBar = NULL; |
127 | ||
128 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
129 | ||
2bda0e17 KB |
130 | if ( id > -1 ) |
131 | m_windowId = id; | |
132 | else | |
133 | m_windowId = (int)NewControlId(); | |
134 | ||
135 | if (parent) parent->AddChild(this); | |
136 | ||
137 | int x = pos.x; | |
138 | int y = pos.y; | |
139 | int width = size.x; | |
140 | int height = size.y; | |
141 | ||
142 | m_iconized = FALSE; | |
d2aef312 VZ |
143 | |
144 | // we pass NULL as parent to MSWCreate because frames with parents behave | |
145 | // very strangely under Win95 shell | |
aeab10d0 JS |
146 | // Alteration by JACS: keep normal Windows behaviour (float on top of parent) |
147 | // with this style. | |
148 | if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0) | |
149 | parent = NULL; | |
150 | ||
319fefa9 VZ |
151 | if (!parent) |
152 | wxTopLevelWindows.Append(this); | |
153 | ||
aeab10d0 | 154 | MSWCreate(m_windowId, parent, wxFrameClassName, this, title, |
d2aef312 | 155 | x, y, width, height, style); |
2bda0e17 KB |
156 | |
157 | wxModelessWindows.Append(this); | |
158 | return TRUE; | |
159 | } | |
160 | ||
bfc6fde4 | 161 | wxFrame::~wxFrame() |
2bda0e17 KB |
162 | { |
163 | m_isBeingDeleted = TRUE; | |
164 | wxTopLevelWindows.DeleteObject(this); | |
165 | ||
7c0ea335 | 166 | DeleteAllBars(); |
2bda0e17 KB |
167 | |
168 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
169 | { | |
170 | wxTheApp->SetTopWindow(NULL); | |
171 | ||
172 | if (wxTheApp->GetExitOnFrameDelete()) | |
173 | { | |
174 | PostQuitMessage(0); | |
175 | } | |
176 | } | |
177 | ||
178 | wxModelessWindows.DeleteObject(this); | |
179 | ||
180 | // For some reason, wxWindows can activate another task altogether | |
181 | // when a frame is destroyed after a modal dialog has been invoked. | |
182 | // Try to bring the parent to the top. | |
36e2955a UM |
183 | // MT:Only do this if this frame is currently the active window, else weird |
184 | // things start to happen | |
185 | if ( wxGetActiveWindow() == this ) | |
2bda0e17 KB |
186 | if (GetParent() && GetParent()->GetHWND()) |
187 | ::BringWindowToTop((HWND) GetParent()->GetHWND()); | |
188 | } | |
189 | ||
81d66cf3 | 190 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
cc2b7472 | 191 | void wxFrame::DoGetClientSize(int *x, int *y) const |
2bda0e17 KB |
192 | { |
193 | RECT rect; | |
42e69d6b | 194 | ::GetClientRect(GetHwnd(), &rect); |
2bda0e17 | 195 | |
7c0ea335 | 196 | #if wxUSE_STATUSBAR |
a2327a9f | 197 | if ( GetStatusBar() && GetStatusBar()->IsShown() ) |
2bda0e17 | 198 | { |
81d66cf3 JS |
199 | int statusX, statusY; |
200 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
201 | rect.bottom -= statusY; | |
2bda0e17 | 202 | } |
7c0ea335 | 203 | #endif // wxUSE_STATUSBAR |
81d66cf3 JS |
204 | |
205 | wxPoint pt(GetClientAreaOrigin()); | |
206 | rect.bottom -= pt.y; | |
207 | rect.right -= pt.x; | |
208 | ||
0655ad29 VZ |
209 | if ( x ) |
210 | *x = rect.right; | |
211 | if ( y ) | |
212 | *y = rect.bottom; | |
2bda0e17 KB |
213 | } |
214 | ||
215 | // Set the client size (i.e. leave the calculation of borders etc. | |
216 | // to wxWindows) | |
bfc6fde4 | 217 | void wxFrame::DoSetClientSize(int width, int height) |
2bda0e17 | 218 | { |
42e69d6b | 219 | HWND hWnd = GetHwnd(); |
2bda0e17 KB |
220 | |
221 | RECT rect; | |
2de8030d | 222 | ::GetClientRect(hWnd, &rect); |
2bda0e17 KB |
223 | |
224 | RECT rect2; | |
225 | GetWindowRect(hWnd, &rect2); | |
226 | ||
227 | // Find the difference between the entire window (title bar and all) | |
228 | // and the client area; add this to the new client size to move the | |
229 | // window | |
230 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
231 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
232 | ||
7c0ea335 | 233 | #if wxUSE_STATUSBAR |
a2327a9f | 234 | if ( GetStatusBar() && GetStatusBar()->IsShown()) |
2bda0e17 | 235 | { |
81d66cf3 JS |
236 | int statusX, statusY; |
237 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
238 | actual_height += statusY; | |
2bda0e17 | 239 | } |
7c0ea335 | 240 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 241 | |
81d66cf3 JS |
242 | wxPoint pt(GetClientAreaOrigin()); |
243 | actual_width += pt.y; | |
244 | actual_height += pt.x; | |
245 | ||
2bda0e17 KB |
246 | POINT point; |
247 | point.x = rect2.left; | |
248 | point.y = rect2.top; | |
249 | ||
250 | MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE); | |
debe6624 | 251 | |
2bda0e17 KB |
252 | wxSizeEvent event(wxSize(width, height), m_windowId); |
253 | event.SetEventObject( this ); | |
254 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
255 | } |
256 | ||
cc2b7472 | 257 | void wxFrame::DoGetSize(int *width, int *height) const |
2bda0e17 KB |
258 | { |
259 | RECT rect; | |
42e69d6b | 260 | GetWindowRect(GetHwnd(), &rect); |
2bda0e17 KB |
261 | *width = rect.right - rect.left; |
262 | *height = rect.bottom - rect.top; | |
263 | } | |
264 | ||
cc2b7472 | 265 | void wxFrame::DoGetPosition(int *x, int *y) const |
2bda0e17 KB |
266 | { |
267 | RECT rect; | |
42e69d6b | 268 | GetWindowRect(GetHwnd(), &rect); |
2bda0e17 KB |
269 | POINT point; |
270 | point.x = rect.left; | |
271 | point.y = rect.top; | |
272 | ||
273 | *x = point.x; | |
274 | *y = point.y; | |
275 | } | |
276 | ||
7c0ea335 VZ |
277 | // ---------------------------------------------------------------------------- |
278 | // variations around ::ShowWindow() | |
279 | // ---------------------------------------------------------------------------- | |
280 | ||
281 | void wxFrame::DoShowWindow(int nShowCmd) | |
282 | { | |
283 | ::ShowWindow(GetHwnd(), nShowCmd); | |
284 | ||
285 | m_iconized = nShowCmd == SW_MINIMIZE; | |
286 | } | |
287 | ||
debe6624 | 288 | bool wxFrame::Show(bool show) |
2bda0e17 | 289 | { |
7c0ea335 | 290 | DoShowWindow(show ? SW_SHOW : SW_HIDE); |
2bda0e17 | 291 | |
7c0ea335 | 292 | if ( show ) |
2bda0e17 | 293 | { |
7c0ea335 | 294 | ::BringWindowToTop(GetHwnd()); |
2bda0e17 | 295 | |
7c0ea335 VZ |
296 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); |
297 | event.SetEventObject( this ); | |
298 | GetEventHandler()->ProcessEvent(event); | |
299 | } | |
300 | else | |
301 | { | |
302 | // Try to highlight the correct window (the parent) | |
303 | if ( GetParent() ) | |
304 | { | |
305 | HWND hWndParent = GetHwndOf(GetParent()); | |
306 | if (hWndParent) | |
307 | ::BringWindowToTop(hWndParent); | |
308 | } | |
309 | } | |
2bda0e17 | 310 | |
7c0ea335 | 311 | return TRUE; |
2bda0e17 KB |
312 | } |
313 | ||
debe6624 | 314 | void wxFrame::Iconize(bool iconize) |
2bda0e17 | 315 | { |
7c0ea335 | 316 | DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); |
2bda0e17 KB |
317 | } |
318 | ||
debe6624 | 319 | void wxFrame::Maximize(bool maximize) |
2bda0e17 | 320 | { |
7c0ea335 VZ |
321 | DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); |
322 | } | |
323 | ||
324 | void wxFrame::Restore() | |
325 | { | |
326 | DoShowWindow(SW_RESTORE); | |
2bda0e17 KB |
327 | } |
328 | ||
bfc6fde4 | 329 | bool wxFrame::IsIconized() const |
2bda0e17 | 330 | { |
42e69d6b | 331 | ((wxFrame *)this)->m_iconized = (::IsIconic(GetHwnd()) != 0); |
2bda0e17 KB |
332 | return m_iconized; |
333 | } | |
334 | ||
6f63ec3f | 335 | // Is it maximized? |
bfc6fde4 | 336 | bool wxFrame::IsMaximized() const |
6f63ec3f | 337 | { |
7c0ea335 | 338 | return (::IsZoomed(GetHwnd()) != 0); |
2bda0e17 KB |
339 | } |
340 | ||
341 | void wxFrame::SetIcon(const wxIcon& icon) | |
342 | { | |
7c0ea335 VZ |
343 | wxFrameBase::SetIcon(icon); |
344 | ||
2bda0e17 | 345 | #if defined(__WIN95__) |
7c0ea335 VZ |
346 | if ( m_icon.Ok() ) |
347 | { | |
348 | SendMessage(GetHwnd(), WM_SETICON, | |
349 | (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON()); | |
350 | } | |
351 | #endif // __WIN95__ | |
2bda0e17 KB |
352 | } |
353 | ||
d427503c | 354 | #if wxUSE_STATUSBAR |
7c0ea335 VZ |
355 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, |
356 | long style, | |
357 | wxWindowID id, | |
358 | const wxString& name) | |
2bda0e17 KB |
359 | { |
360 | wxStatusBar *statusBar = NULL; | |
361 | ||
47d67540 | 362 | #if wxUSE_NATIVE_STATUSBAR |
1f0500b3 | 363 | if ( !UsesNativeStatusBar() ) |
2bda0e17 | 364 | { |
1f0500b3 | 365 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); |
2bda0e17 KB |
366 | } |
367 | else | |
368 | #endif | |
369 | { | |
1f0500b3 VZ |
370 | statusBar = new wxStatusBar(this, id, style, name); |
371 | } | |
ed791986 | 372 | |
1f0500b3 VZ |
373 | // Set the height according to the font and the border size |
374 | wxClientDC dc(statusBar); | |
375 | dc.SetFont(statusBar->GetFont()); | |
ed791986 | 376 | |
1f0500b3 VZ |
377 | wxCoord y; |
378 | dc.GetTextExtent(_T("X"), NULL, &y ); | |
ed791986 | 379 | |
1f0500b3 | 380 | int height = (int)( (11*y)/10 + 2*statusBar->GetBorderY()); |
ed791986 | 381 | |
1f0500b3 | 382 | statusBar->SetSize(-1, -1, -1, height); |
ed791986 | 383 | |
1f0500b3 | 384 | statusBar->SetFieldsCount(number); |
2bda0e17 | 385 | |
7c0ea335 | 386 | return statusBar; |
2bda0e17 KB |
387 | } |
388 | ||
bfc6fde4 | 389 | void wxFrame::PositionStatusBar() |
2bda0e17 | 390 | { |
ed791986 VZ |
391 | if ( !m_frameStatusBar ) |
392 | return; | |
393 | ||
cbc66a27 VZ |
394 | int w, h; |
395 | GetClientSize(&w, &h); | |
396 | int sw, sh; | |
397 | m_frameStatusBar->GetSize(&sw, &sh); | |
398 | ||
399 | // Since we wish the status bar to be directly under the client area, | |
400 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
401 | m_frameStatusBar->SetSize(0, h, w, sh); | |
2bda0e17 | 402 | } |
d427503c | 403 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 404 | |
ea9a4296 UM |
405 | void wxFrame::DetachMenuBar() |
406 | { | |
407 | if (m_frameMenuBar) | |
408 | { | |
409 | m_frameMenuBar->Detach(); | |
410 | m_frameMenuBar = NULL; | |
411 | } | |
412 | } | |
413 | ||
2bda0e17 KB |
414 | void wxFrame::SetMenuBar(wxMenuBar *menu_bar) |
415 | { | |
c2dcfdef VZ |
416 | if (!menu_bar) |
417 | { | |
ea9a4296 | 418 | DetachMenuBar(); |
c2dcfdef VZ |
419 | return; |
420 | } | |
2bda0e17 | 421 | |
065de612 JS |
422 | m_frameMenuBar = NULL; |
423 | ||
424 | // Can set a menubar several times. | |
425 | // TODO: how to prevent a memory leak if you have a currently-unattached | |
426 | // menubar? wxWindows assumes that the frame will delete the menu (otherwise | |
427 | // there are problems for MDI). | |
428 | if (menu_bar->GetHMenu()) | |
429 | { | |
430 | m_hMenu = menu_bar->GetHMenu(); | |
431 | } | |
432 | else | |
433 | { | |
434 | menu_bar->Detach(); | |
435 | ||
436 | m_hMenu = menu_bar->Create(); | |
437 | ||
438 | if ( !m_hMenu ) | |
439 | return; | |
440 | } | |
441 | ||
442 | InternalSetMenuBar(); | |
443 | ||
444 | m_frameMenuBar = menu_bar; | |
445 | menu_bar->Attach(this); | |
446 | ||
447 | #if 0 // Old code that assumes only one call of SetMenuBar per frame. | |
448 | if (!menu_bar) | |
449 | { | |
450 | DetachMenuBar(); | |
451 | return; | |
452 | } | |
453 | ||
223d09f6 | 454 | wxCHECK_RET( !menu_bar->GetFrame(), wxT("this menubar is already attached") ); |
2bda0e17 | 455 | |
c2dcfdef VZ |
456 | if (m_frameMenuBar) |
457 | delete m_frameMenuBar; | |
2bda0e17 | 458 | |
c2dcfdef | 459 | m_hMenu = menu_bar->Create(); |
2bda0e17 | 460 | |
c2dcfdef VZ |
461 | if ( !m_hMenu ) |
462 | return; | |
2bda0e17 | 463 | |
42e69d6b | 464 | InternalSetMenuBar(); |
2bda0e17 | 465 | |
c2dcfdef VZ |
466 | m_frameMenuBar = menu_bar; |
467 | menu_bar->Attach(this); | |
065de612 | 468 | #endif |
2bda0e17 KB |
469 | } |
470 | ||
42e69d6b | 471 | void wxFrame::InternalSetMenuBar() |
2bda0e17 | 472 | { |
42e69d6b | 473 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) |
2bda0e17 | 474 | { |
42e69d6b | 475 | wxLogLastError("SetMenu"); |
2bda0e17 | 476 | } |
2bda0e17 KB |
477 | } |
478 | ||
479 | // Responds to colour changes, and passes event on to children. | |
480 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
481 | { | |
482 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
483 | Refresh(); | |
484 | ||
485 | if ( m_frameStatusBar ) | |
486 | { | |
487 | wxSysColourChangedEvent event2; | |
488 | event2.SetEventObject( m_frameStatusBar ); | |
02800301 | 489 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); |
2bda0e17 KB |
490 | } |
491 | ||
492 | // Propagate the event to the non-top-level children | |
493 | wxWindow::OnSysColourChanged(event); | |
494 | } | |
495 | ||
a2327a9f JS |
496 | // Pass TRUE to show full screen, FALSE to restore. |
497 | bool wxFrame::ShowFullScreen(bool show, long style) | |
498 | { | |
499 | if (show) | |
500 | { | |
501 | if (IsFullScreen()) | |
502 | return FALSE; | |
503 | ||
504 | m_fsIsShowing = TRUE; | |
505 | m_fsStyle = style; | |
506 | ||
507 | wxToolBar *theToolBar = GetToolBar(); | |
508 | wxStatusBar *theStatusBar = GetStatusBar(); | |
509 | ||
510 | int dummyWidth; | |
511 | ||
512 | if (theToolBar) | |
513 | theToolBar->GetSize(&dummyWidth, &m_fsToolBarHeight); | |
514 | if (theStatusBar) | |
515 | theStatusBar->GetSize(&dummyWidth, &m_fsStatusBarHeight); | |
516 | ||
517 | // zap the toolbar, menubar, and statusbar | |
518 | ||
519 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
520 | { | |
521 | theToolBar->SetSize(-1,0); | |
522 | theToolBar->Show(FALSE); | |
523 | } | |
524 | ||
525 | if (style & wxFULLSCREEN_NOMENUBAR) | |
526 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
527 | ||
528 | // Save the number of fields in the statusbar | |
529 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
530 | { | |
531 | m_fsStatusBarFields = theStatusBar->GetFieldsCount(); | |
532 | SetStatusBar((wxStatusBar*) NULL); | |
533 | delete theStatusBar; | |
534 | } | |
535 | else | |
536 | m_fsStatusBarFields = 0; | |
537 | ||
538 | // zap the frame borders | |
539 | ||
540 | // save the 'normal' window style | |
541 | m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE); | |
542 | ||
543 | // save the old position, width & height, maximize state | |
544 | m_fsOldSize = GetRect(); | |
545 | m_fsIsMaximized = IsMaximized(); | |
546 | ||
547 | // decide which window style flags to turn off | |
548 | LONG newStyle = m_fsOldWindowStyle; | |
549 | LONG offFlags = 0; | |
550 | ||
551 | if (style & wxFULLSCREEN_NOBORDER) | |
552 | offFlags |= WS_BORDER; | |
553 | if (style & wxFULLSCREEN_NOCAPTION) | |
554 | offFlags |= (WS_CAPTION | WS_SYSMENU); | |
555 | ||
556 | newStyle &= (~offFlags); | |
557 | ||
558 | // change our window style to be compatible with full-screen mode | |
559 | SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle); | |
560 | ||
561 | // resize to the size of the desktop | |
562 | int width, height; | |
563 | ||
564 | RECT rect; | |
565 | ::GetWindowRect(GetDesktopWindow(), &rect); | |
566 | width = rect.right - rect.left; | |
567 | height = rect.bottom - rect.top; | |
568 | ||
569 | SetSize(width, height); | |
570 | ||
571 | // now flush the window style cache and actually go full-screen | |
572 | SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED); | |
573 | ||
574 | wxSizeEvent event(wxSize(width, height), GetId()); | |
575 | GetEventHandler()->ProcessEvent(event); | |
576 | ||
577 | return TRUE; | |
578 | } | |
579 | else | |
580 | { | |
581 | if (!IsFullScreen()) | |
582 | return FALSE; | |
583 | ||
584 | m_fsIsShowing = FALSE; | |
585 | ||
586 | wxToolBar *theToolBar = GetToolBar(); | |
587 | ||
588 | // restore the toolbar, menubar, and statusbar | |
589 | if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
590 | { | |
591 | theToolBar->SetSize(-1, m_fsToolBarHeight); | |
592 | theToolBar->Show(TRUE); | |
593 | } | |
594 | ||
595 | if ((m_fsStyle & wxFULLSCREEN_NOSTATUSBAR) && (m_fsStatusBarFields > 0)) | |
596 | { | |
597 | CreateStatusBar(m_fsStatusBarFields); | |
598 | PositionStatusBar(); | |
599 | } | |
600 | ||
601 | if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) | |
602 | SetMenu((HWND)GetHWND(), (HMENU)m_hMenu); | |
603 | ||
604 | Maximize(m_fsIsMaximized); | |
605 | SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle); | |
606 | SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y, | |
607 | m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED); | |
608 | ||
609 | return TRUE; | |
610 | } | |
611 | } | |
612 | ||
2bda0e17 KB |
613 | /* |
614 | * Frame window | |
615 | * | |
616 | */ | |
617 | ||
837e5743 | 618 | bool wxFrame::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title, |
debe6624 | 619 | int x, int y, int width, int height, long style) |
2bda0e17 KB |
620 | |
621 | { | |
622 | m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); | |
623 | ||
624 | // If child windows aren't properly drawn initially, WS_CLIPCHILDREN | |
625 | // could be the culprit. But without it, you can get a lot of flicker. | |
626 | ||
2bda0e17 KB |
627 | DWORD msflags = 0; |
628 | if ((style & wxCAPTION) == wxCAPTION) | |
1c089c47 | 629 | msflags = WS_OVERLAPPED; |
2bda0e17 | 630 | else |
1c089c47 | 631 | msflags = WS_POPUP; |
2bda0e17 KB |
632 | |
633 | if (style & wxMINIMIZE_BOX) | |
634 | msflags |= WS_MINIMIZEBOX; | |
635 | if (style & wxMAXIMIZE_BOX) | |
636 | msflags |= WS_MAXIMIZEBOX; | |
637 | if (style & wxTHICK_FRAME) | |
638 | msflags |= WS_THICKFRAME; | |
639 | if (style & wxSYSTEM_MENU) | |
640 | msflags |= WS_SYSMENU; | |
641 | if ((style & wxMINIMIZE) || (style & wxICONIZE)) | |
642 | msflags |= WS_MINIMIZE; | |
643 | if (style & wxMAXIMIZE) | |
644 | msflags |= WS_MAXIMIZE; | |
645 | if (style & wxCAPTION) | |
646 | msflags |= WS_CAPTION; | |
1c089c47 JS |
647 | if (style & wxCLIP_CHILDREN) |
648 | msflags |= WS_CLIPCHILDREN; | |
2bda0e17 KB |
649 | |
650 | // Keep this in wxFrame because it saves recoding this function | |
651 | // in wxTinyFrame | |
8355a72f | 652 | #if wxUSE_ITSY_BITSY && !defined(__WIN32__) |
2bda0e17 KB |
653 | if (style & wxTINY_CAPTION_VERT) |
654 | msflags |= IBS_VERTCAPTION; | |
655 | if (style & wxTINY_CAPTION_HORIZ) | |
656 | msflags |= IBS_HORZCAPTION; | |
657 | #else | |
658 | if (style & wxTINY_CAPTION_VERT) | |
659 | msflags |= WS_CAPTION; | |
660 | if (style & wxTINY_CAPTION_HORIZ) | |
661 | msflags |= WS_CAPTION; | |
662 | #endif | |
663 | if ((style & wxTHICK_FRAME) == 0) | |
664 | msflags |= WS_BORDER; | |
665 | ||
666 | WXDWORD extendedStyle = MakeExtendedStyle(style); | |
667 | ||
2432b92d | 668 | #if !defined(__WIN16__) && !defined(__SC__) |
cd2df130 JS |
669 | if (style & wxFRAME_TOOL_WINDOW) |
670 | extendedStyle |= WS_EX_TOOLWINDOW; | |
1e6d9499 | 671 | #endif |
cd2df130 | 672 | |
2bda0e17 KB |
673 | if (style & wxSTAY_ON_TOP) |
674 | extendedStyle |= WS_EX_TOPMOST; | |
675 | ||
676 | m_iconized = FALSE; | |
a23fd0e1 VZ |
677 | if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height, |
678 | msflags, NULL, extendedStyle) ) | |
679 | return FALSE; | |
680 | ||
2bda0e17 KB |
681 | // Seems to be necessary if we use WS_POPUP |
682 | // style instead of WS_OVERLAPPED | |
683 | if (width > -1 && height > -1) | |
42e69d6b | 684 | ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height)); |
a23fd0e1 VZ |
685 | |
686 | return TRUE; | |
2bda0e17 KB |
687 | } |
688 | ||
2bda0e17 KB |
689 | // Default activation behaviour - set the focus for the first child |
690 | // subwindow found. | |
691 | void wxFrame::OnActivate(wxActivateEvent& event) | |
692 | { | |
00c4e897 VZ |
693 | if ( !event.GetActive() ) |
694 | { | |
695 | event.Skip(); | |
696 | ||
697 | return; | |
698 | } | |
699 | ||
700 | wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd); | |
701 | ||
319fefa9 VZ |
702 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
703 | node; | |
704 | node = node->GetNext() ) | |
2bda0e17 | 705 | { |
319fefa9 VZ |
706 | // FIXME all this is totally bogus - we need to do the same as wxPanel, |
707 | // but how to do it without duplicating the code? | |
708 | ||
709 | // restore focus | |
710 | wxWindow *child = node->GetData(); | |
711 | ||
712 | if ( !child->IsTopLevel() | |
713 | #if wxUSE_TOOLBAR | |
714 | && !wxDynamicCast(child, wxToolBar) | |
715 | #endif // wxUSE_TOOLBAR | |
716 | #if wxUSE_STATUSBAR | |
717 | && !wxDynamicCast(child, wxStatusBar) | |
718 | #endif // wxUSE_STATUSBAR | |
719 | ) | |
720 | { | |
721 | child->SetFocus(); | |
00c4e897 | 722 | break; |
319fefa9 | 723 | } |
2bda0e17 | 724 | } |
2bda0e17 KB |
725 | } |
726 | ||
7c0ea335 VZ |
727 | // ---------------------------------------------------------------------------- |
728 | // tool/status bar stuff | |
729 | // ---------------------------------------------------------------------------- | |
730 | ||
d427503c | 731 | #if wxUSE_TOOLBAR |
7c0ea335 | 732 | |
81d66cf3 JS |
733 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
734 | { | |
7c0ea335 | 735 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
81d66cf3 | 736 | { |
81d66cf3 | 737 | PositionToolBar(); |
81d66cf3 | 738 | } |
81d66cf3 | 739 | |
7c0ea335 | 740 | return m_frameToolBar; |
81d66cf3 JS |
741 | } |
742 | ||
bfc6fde4 | 743 | void wxFrame::PositionToolBar() |
81d66cf3 | 744 | { |
81d66cf3 | 745 | RECT rect; |
42e69d6b | 746 | ::GetClientRect(GetHwnd(), &rect); |
81d66cf3 | 747 | |
7c0ea335 | 748 | #if wxUSE_STATUSBAR |
81d66cf3 JS |
749 | if ( GetStatusBar() ) |
750 | { | |
7c0ea335 VZ |
751 | int statusX, statusY; |
752 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
753 | rect.bottom -= statusY; | |
81d66cf3 | 754 | } |
7c0ea335 | 755 | #endif // wxUSE_STATUSBAR |
81d66cf3 | 756 | |
a2327a9f | 757 | if ( GetToolBar() && GetToolBar()->IsShown() ) |
81d66cf3 JS |
758 | { |
759 | int tw, th; | |
7c0ea335 | 760 | GetToolBar()->GetSize(&tw, &th); |
81d66cf3 | 761 | |
7c0ea335 | 762 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) |
81d66cf3 | 763 | { |
7c0ea335 | 764 | th = rect.bottom; |
81d66cf3 JS |
765 | } |
766 | else | |
767 | { | |
7c0ea335 | 768 | tw = rect.right; |
81d66cf3 | 769 | } |
7c0ea335 VZ |
770 | |
771 | // Use the 'real' MSW position here | |
772 | GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); | |
81d66cf3 JS |
773 | } |
774 | } | |
d427503c | 775 | #endif // wxUSE_TOOLBAR |
d2aef312 | 776 | |
7c0ea335 VZ |
777 | // ---------------------------------------------------------------------------- |
778 | // frame state (iconized/maximized/...) | |
779 | // ---------------------------------------------------------------------------- | |
780 | ||
a23fd0e1 VZ |
781 | // propagate our state change to all child frames: this allows us to emulate X |
782 | // Windows behaviour where child frames float independently of the parent one | |
783 | // on the desktop, but are iconized/restored with it | |
d2aef312 VZ |
784 | void wxFrame::IconizeChildFrames(bool bIconize) |
785 | { | |
a23fd0e1 VZ |
786 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
787 | node; | |
788 | node = node->GetNext() ) | |
789 | { | |
790 | wxWindow *win = node->GetData(); | |
791 | ||
3f7bc32b VZ |
792 | // the child MDI frames are a special case and should not be touched by |
793 | // the parent frame - instead, they are managed by the user | |
794 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
795 | if ( frame && !wxDynamicCast(frame, wxMDIChildFrame) ) | |
a23fd0e1 | 796 | { |
3f7bc32b | 797 | frame->Iconize(bIconize); |
a23fd0e1 | 798 | } |
d2aef312 | 799 | } |
d2aef312 VZ |
800 | } |
801 | ||
a23fd0e1 | 802 | // =========================================================================== |
42e69d6b | 803 | // message processing |
a23fd0e1 VZ |
804 | // =========================================================================== |
805 | ||
42e69d6b VZ |
806 | // --------------------------------------------------------------------------- |
807 | // preprocessing | |
808 | // --------------------------------------------------------------------------- | |
809 | ||
810 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) | |
811 | { | |
812 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
813 | return TRUE; | |
814 | ||
815 | // try the menu bar accels | |
816 | wxMenuBar *menuBar = GetMenuBar(); | |
817 | if ( !menuBar ) | |
818 | return FALSE; | |
819 | ||
820 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
c50f1fb9 | 821 | return acceleratorTable.Translate(this, pMsg); |
42e69d6b VZ |
822 | } |
823 | ||
824 | // --------------------------------------------------------------------------- | |
825 | // our private (non virtual) message handlers | |
826 | // --------------------------------------------------------------------------- | |
827 | ||
828 | bool wxFrame::HandlePaint() | |
829 | { | |
830 | RECT rect; | |
831 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
832 | { | |
833 | if ( m_iconized ) | |
834 | { | |
c50f1fb9 | 835 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
42e69d6b VZ |
836 | : (HICON)m_defaultIcon; |
837 | ||
838 | // Hold a pointer to the dc so long as the OnPaint() message | |
839 | // is being processed | |
840 | PAINTSTRUCT ps; | |
841 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
842 | ||
843 | // Erase background before painting or we get white background | |
844 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
845 | ||
846 | if ( hIcon ) | |
847 | { | |
848 | RECT rect; | |
849 | ::GetClientRect(GetHwnd(), &rect); | |
850 | ||
851 | // FIXME: why hardcoded? | |
852 | static const int icon_width = 32; | |
853 | static const int icon_height = 32; | |
854 | ||
855 | int icon_x = (int)((rect.right - icon_width)/2); | |
856 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
857 | ||
858 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
859 | } | |
860 | ||
861 | ::EndPaint(GetHwnd(), &ps); | |
862 | ||
863 | return TRUE; | |
864 | } | |
865 | else | |
866 | { | |
5d1d2d46 | 867 | return wxWindow::HandlePaint(); |
42e69d6b VZ |
868 | } |
869 | } | |
870 | else | |
871 | { | |
872 | // nothing to paint - processed | |
873 | return TRUE; | |
874 | } | |
875 | } | |
876 | ||
877 | bool wxFrame::HandleSize(int x, int y, WXUINT id) | |
878 | { | |
879 | bool processed = FALSE; | |
880 | ||
881 | switch ( id ) | |
882 | { | |
883 | case SIZENORMAL: | |
884 | // only do it it if we were iconized before, otherwise resizing the | |
885 | // parent frame has a curious side effect of bringing it under it's | |
886 | // children | |
887 | if ( !m_iconized ) | |
888 | break; | |
889 | ||
890 | // restore all child frames too | |
891 | IconizeChildFrames(FALSE); | |
892 | ||
893 | // fall through | |
894 | ||
895 | case SIZEFULLSCREEN: | |
896 | m_iconized = FALSE; | |
897 | break; | |
898 | ||
899 | case SIZEICONIC: | |
900 | // iconize all child frames too | |
901 | IconizeChildFrames(TRUE); | |
902 | ||
903 | m_iconized = TRUE; | |
904 | break; | |
905 | } | |
906 | ||
907 | if ( !m_iconized ) | |
908 | { | |
42e69d6b VZ |
909 | PositionStatusBar(); |
910 | PositionToolBar(); | |
911 | ||
912 | wxSizeEvent event(wxSize(x, y), m_windowId); | |
913 | event.SetEventObject( this ); | |
914 | processed = GetEventHandler()->ProcessEvent(event); | |
915 | } | |
916 | ||
917 | return processed; | |
918 | } | |
919 | ||
920 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) | |
921 | { | |
922 | if ( control ) | |
923 | { | |
924 | // In case it's e.g. a toolbar. | |
925 | wxWindow *win = wxFindWinFromHandle(control); | |
926 | if ( win ) | |
927 | return win->MSWCommand(cmd, id); | |
928 | } | |
929 | ||
930 | // handle here commands from menus and accelerators | |
931 | if ( cmd == 0 || cmd == 1 ) | |
932 | { | |
933 | if ( wxCurrentPopupMenu ) | |
934 | { | |
935 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
936 | wxCurrentPopupMenu = NULL; | |
937 | ||
938 | return popupMenu->MSWCommand(cmd, id); | |
939 | } | |
940 | ||
941 | if ( ProcessCommand(id) ) | |
942 | { | |
943 | return TRUE; | |
944 | } | |
945 | } | |
946 | ||
947 | return FALSE; | |
948 | } | |
949 | ||
c219cecc | 950 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) |
a23fd0e1 VZ |
951 | { |
952 | int item; | |
c219cecc | 953 | if ( flags == 0xFFFF && hMenu == 0 ) |
a23fd0e1 | 954 | { |
c219cecc | 955 | // menu was removed from screen |
a23fd0e1 VZ |
956 | item = -1; |
957 | } | |
c219cecc | 958 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) |
a23fd0e1 VZ |
959 | { |
960 | item = nItem; | |
961 | } | |
962 | else | |
963 | { | |
c219cecc VZ |
964 | // don't give hints for separators (doesn't make sense) nor for the |
965 | // items opening popup menus (they don't have them anyhow) | |
a23fd0e1 VZ |
966 | return FALSE; |
967 | } | |
968 | ||
969 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
970 | event.SetEventObject( this ); | |
971 | ||
972 | return GetEventHandler()->ProcessEvent(event); | |
973 | } | |
974 | ||
975 | // --------------------------------------------------------------------------- | |
976 | // the window proc for wxFrame | |
977 | // --------------------------------------------------------------------------- | |
978 | ||
979 | long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
980 | { | |
981 | long rc = 0; | |
982 | bool processed = FALSE; | |
983 | ||
984 | switch ( message ) | |
985 | { | |
42e69d6b VZ |
986 | case WM_CLOSE: |
987 | // if we can't close, tell the system that we processed the | |
988 | // message - otherwise it would close us | |
989 | processed = !Close(); | |
990 | break; | |
991 | ||
992 | case WM_COMMAND: | |
993 | { | |
994 | WORD id, cmd; | |
995 | WXHWND hwnd; | |
996 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
997 | &id, &hwnd, &cmd); | |
998 | ||
999 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
1000 | } | |
1001 | break; | |
1002 | ||
a23fd0e1 VZ |
1003 | case WM_MENUSELECT: |
1004 | { | |
42e69d6b VZ |
1005 | WXWORD item, flags; |
1006 | WXHMENU hmenu; | |
1007 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
1008 | ||
1009 | processed = HandleMenuSelect(item, flags, hmenu); | |
a23fd0e1 VZ |
1010 | } |
1011 | break; | |
42e69d6b VZ |
1012 | |
1013 | case WM_PAINT: | |
1014 | processed = HandlePaint(); | |
1015 | break; | |
1016 | ||
1017 | case WM_QUERYDRAGICON: | |
1018 | { | |
c50f1fb9 | 1019 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
42e69d6b VZ |
1020 | : (HICON)(m_defaultIcon); |
1021 | rc = (long)hIcon; | |
1022 | processed = rc != 0; | |
1023 | } | |
1024 | break; | |
1025 | ||
1026 | case WM_SIZE: | |
1027 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
1028 | break; | |
a23fd0e1 VZ |
1029 | } |
1030 | ||
1031 | if ( !processed ) | |
1032 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
1033 | ||
1034 | return rc; | |
1035 | } | |
21802234 | 1036 |