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