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