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