]>
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; |
2bda0e17 | 46 | extern char 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 KB |
89 | if (!parent) |
90 | wxTopLevelWindows.Append(this); | |
91 | ||
92 | SetName(name); | |
2bda0e17 KB |
93 | m_windowStyle = style; |
94 | m_frameMenuBar = NULL; | |
73e7daa0 | 95 | m_frameToolBar = NULL ; |
2bda0e17 KB |
96 | m_frameStatusBar = NULL; |
97 | ||
98 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
99 | ||
100 | // m_icon = NULL; | |
101 | if ( id > -1 ) | |
102 | m_windowId = id; | |
103 | else | |
104 | m_windowId = (int)NewControlId(); | |
105 | ||
106 | if (parent) parent->AddChild(this); | |
107 | ||
108 | int x = pos.x; | |
109 | int y = pos.y; | |
110 | int width = size.x; | |
111 | int height = size.y; | |
112 | ||
113 | m_iconized = FALSE; | |
d2aef312 VZ |
114 | |
115 | // we pass NULL as parent to MSWCreate because frames with parents behave | |
116 | // very strangely under Win95 shell | |
aeab10d0 JS |
117 | // Alteration by JACS: keep normal Windows behaviour (float on top of parent) |
118 | // with this style. | |
119 | if ((m_windowStyle & wxFRAME_FLOAT_ON_PARENT) == 0) | |
120 | parent = NULL; | |
121 | ||
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 | ||
81d66cf3 JS |
349 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, |
350 | const wxString& name) | |
2bda0e17 KB |
351 | { |
352 | wxStatusBar *statusBar = NULL; | |
353 | ||
47d67540 | 354 | #if wxUSE_NATIVE_STATUSBAR |
2bda0e17 KB |
355 | if (UsesNativeStatusBar()) |
356 | { | |
81d66cf3 | 357 | statusBar = new wxStatusBar95(this, id, style); |
2bda0e17 KB |
358 | } |
359 | else | |
360 | #endif | |
361 | { | |
81d66cf3 JS |
362 | statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), |
363 | style, name); | |
2bda0e17 KB |
364 | |
365 | // Set the height according to the font and the border size | |
366 | wxClientDC dc(statusBar); | |
c0ed460c | 367 | dc.SetFont(statusBar->GetFont()); |
2bda0e17 KB |
368 | |
369 | long x, y; | |
370 | dc.GetTextExtent("X", &x, &y); | |
371 | ||
372 | int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); | |
373 | ||
374 | statusBar->SetSize(-1, -1, 100, height); | |
375 | } | |
376 | ||
377 | statusBar->SetFieldsCount(number); | |
378 | return statusBar; | |
379 | } | |
380 | ||
81d66cf3 JS |
381 | wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id, |
382 | const wxString& name) | |
2bda0e17 KB |
383 | { |
384 | // VZ: calling CreateStatusBar twice is an error - why anyone would do it? | |
c2dcfdef | 385 | wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, |
1311c7a9 | 386 | "recreating status bar in wxFrame" ); |
2bda0e17 | 387 | |
81d66cf3 JS |
388 | m_frameStatusBar = OnCreateStatusBar(number, style, id, |
389 | name); | |
2bda0e17 KB |
390 | if ( m_frameStatusBar ) |
391 | { | |
392 | PositionStatusBar(); | |
81d66cf3 | 393 | return m_frameStatusBar; |
2bda0e17 KB |
394 | } |
395 | else | |
81d66cf3 | 396 | return NULL; |
2bda0e17 KB |
397 | } |
398 | ||
debe6624 | 399 | void wxFrame::SetStatusText(const wxString& text, int number) |
2bda0e17 | 400 | { |
1311c7a9 | 401 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); |
2bda0e17 KB |
402 | |
403 | m_frameStatusBar->SetStatusText(text, number); | |
404 | } | |
405 | ||
8b9518ee | 406 | void wxFrame::SetStatusWidths(int n, const int widths_field[]) |
2bda0e17 | 407 | { |
1311c7a9 | 408 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); |
2bda0e17 KB |
409 | |
410 | m_frameStatusBar->SetStatusWidths(n, widths_field); | |
411 | PositionStatusBar(); | |
412 | } | |
413 | ||
bfc6fde4 | 414 | void wxFrame::PositionStatusBar() |
2bda0e17 KB |
415 | { |
416 | // native status bar positions itself | |
417 | if (m_frameStatusBar | |
47d67540 | 418 | #if wxUSE_NATIVE_STATUSBAR |
2bda0e17 KB |
419 | && !m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)) |
420 | #endif | |
421 | ) | |
422 | { | |
423 | int w, h; | |
424 | GetClientSize(&w, &h); | |
425 | int sw, sh; | |
426 | m_frameStatusBar->GetSize(&sw, &sh); | |
81d66cf3 JS |
427 | |
428 | // Since we wish the status bar to be directly under the client area, | |
429 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
2bda0e17 KB |
430 | m_frameStatusBar->SetSize(0, h, w, sh); |
431 | } | |
432 | } | |
433 | ||
434 | void wxFrame::SetMenuBar(wxMenuBar *menu_bar) | |
435 | { | |
c2dcfdef VZ |
436 | if (!menu_bar) |
437 | { | |
438 | m_frameMenuBar = NULL; | |
439 | return; | |
440 | } | |
2bda0e17 | 441 | |
c2dcfdef | 442 | wxCHECK_RET( !menu_bar->GetFrame(), "this menubar is already attached" ); |
2bda0e17 | 443 | |
c2dcfdef VZ |
444 | if (m_frameMenuBar) |
445 | delete m_frameMenuBar; | |
2bda0e17 | 446 | |
c2dcfdef | 447 | m_hMenu = menu_bar->Create(); |
2bda0e17 | 448 | |
c2dcfdef VZ |
449 | if ( !m_hMenu ) |
450 | return; | |
2bda0e17 | 451 | |
42e69d6b | 452 | InternalSetMenuBar(); |
2bda0e17 | 453 | |
c2dcfdef VZ |
454 | m_frameMenuBar = menu_bar; |
455 | menu_bar->Attach(this); | |
2bda0e17 KB |
456 | } |
457 | ||
42e69d6b | 458 | void wxFrame::InternalSetMenuBar() |
2bda0e17 | 459 | { |
42e69d6b | 460 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) |
2bda0e17 | 461 | { |
42e69d6b | 462 | wxLogLastError("SetMenu"); |
2bda0e17 | 463 | } |
2bda0e17 KB |
464 | } |
465 | ||
466 | // Responds to colour changes, and passes event on to children. | |
467 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
468 | { | |
469 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
470 | Refresh(); | |
471 | ||
472 | if ( m_frameStatusBar ) | |
473 | { | |
474 | wxSysColourChangedEvent event2; | |
475 | event2.SetEventObject( m_frameStatusBar ); | |
02800301 | 476 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); |
2bda0e17 KB |
477 | } |
478 | ||
479 | // Propagate the event to the non-top-level children | |
480 | wxWindow::OnSysColourChanged(event); | |
481 | } | |
482 | ||
483 | /* | |
484 | * Frame window | |
485 | * | |
486 | */ | |
487 | ||
a23fd0e1 | 488 | bool wxFrame::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title, |
debe6624 | 489 | int x, int y, int width, int height, long style) |
2bda0e17 KB |
490 | |
491 | { | |
492 | m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); | |
493 | ||
494 | // If child windows aren't properly drawn initially, WS_CLIPCHILDREN | |
495 | // could be the culprit. But without it, you can get a lot of flicker. | |
496 | ||
2bda0e17 KB |
497 | DWORD msflags = 0; |
498 | if ((style & wxCAPTION) == wxCAPTION) | |
1c089c47 | 499 | msflags = WS_OVERLAPPED; |
2bda0e17 | 500 | else |
1c089c47 | 501 | msflags = WS_POPUP; |
2bda0e17 KB |
502 | |
503 | if (style & wxMINIMIZE_BOX) | |
504 | msflags |= WS_MINIMIZEBOX; | |
505 | if (style & wxMAXIMIZE_BOX) | |
506 | msflags |= WS_MAXIMIZEBOX; | |
507 | if (style & wxTHICK_FRAME) | |
508 | msflags |= WS_THICKFRAME; | |
509 | if (style & wxSYSTEM_MENU) | |
510 | msflags |= WS_SYSMENU; | |
511 | if ((style & wxMINIMIZE) || (style & wxICONIZE)) | |
512 | msflags |= WS_MINIMIZE; | |
513 | if (style & wxMAXIMIZE) | |
514 | msflags |= WS_MAXIMIZE; | |
515 | if (style & wxCAPTION) | |
516 | msflags |= WS_CAPTION; | |
1c089c47 JS |
517 | if (style & wxCLIP_CHILDREN) |
518 | msflags |= WS_CLIPCHILDREN; | |
2bda0e17 KB |
519 | |
520 | // Keep this in wxFrame because it saves recoding this function | |
521 | // in wxTinyFrame | |
47d67540 | 522 | #if wxUSE_ITSY_BITSY |
2bda0e17 KB |
523 | if (style & wxTINY_CAPTION_VERT) |
524 | msflags |= IBS_VERTCAPTION; | |
525 | if (style & wxTINY_CAPTION_HORIZ) | |
526 | msflags |= IBS_HORZCAPTION; | |
527 | #else | |
528 | if (style & wxTINY_CAPTION_VERT) | |
529 | msflags |= WS_CAPTION; | |
530 | if (style & wxTINY_CAPTION_HORIZ) | |
531 | msflags |= WS_CAPTION; | |
532 | #endif | |
533 | if ((style & wxTHICK_FRAME) == 0) | |
534 | msflags |= WS_BORDER; | |
535 | ||
536 | WXDWORD extendedStyle = MakeExtendedStyle(style); | |
537 | ||
2432b92d | 538 | #if !defined(__WIN16__) && !defined(__SC__) |
cd2df130 JS |
539 | if (style & wxFRAME_TOOL_WINDOW) |
540 | extendedStyle |= WS_EX_TOOLWINDOW; | |
1e6d9499 | 541 | #endif |
cd2df130 | 542 | |
2bda0e17 KB |
543 | if (style & wxSTAY_ON_TOP) |
544 | extendedStyle |= WS_EX_TOPMOST; | |
545 | ||
546 | m_iconized = FALSE; | |
a23fd0e1 VZ |
547 | if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height, |
548 | msflags, NULL, extendedStyle) ) | |
549 | return FALSE; | |
550 | ||
2bda0e17 KB |
551 | // Seems to be necessary if we use WS_POPUP |
552 | // style instead of WS_OVERLAPPED | |
553 | if (width > -1 && height > -1) | |
42e69d6b | 554 | ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height)); |
a23fd0e1 VZ |
555 | |
556 | return TRUE; | |
2bda0e17 KB |
557 | } |
558 | ||
a23fd0e1 VZ |
559 | // Default resizing behaviour - if only ONE subwindow, resize to client |
560 | // rectangle size | |
2bda0e17 KB |
561 | void wxFrame::OnSize(wxSizeEvent& event) |
562 | { | |
a23fd0e1 VZ |
563 | // if we're using constraints - do use them |
564 | #if wxUSE_CONSTRAINTS | |
565 | if ( GetAutoLayout() ) | |
566 | { | |
567 | Layout(); | |
568 | return; | |
cd70477b | 569 | } |
a23fd0e1 | 570 | #endif |
cd70477b | 571 | |
a23fd0e1 VZ |
572 | // do we have _exactly_ one child? |
573 | wxWindow *child = NULL; | |
574 | for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) | |
2bda0e17 | 575 | { |
a23fd0e1 VZ |
576 | wxWindow *win = (wxWindow *)node->Data(); |
577 | if ( !win->IsKindOf(CLASSINFO(wxFrame)) && | |
578 | !win->IsKindOf(CLASSINFO(wxDialog)) && | |
579 | (win != GetStatusBar()) && | |
580 | (win != GetToolBar()) ) | |
581 | { | |
582 | if ( child ) | |
583 | return; // it's our second subwindow - nothing to do | |
584 | child = win; | |
585 | } | |
2bda0e17 | 586 | } |
2bda0e17 | 587 | |
a23fd0e1 VZ |
588 | if ( child ) { |
589 | // we have exactly one child - set it's size to fill the whole frame | |
590 | int clientW, clientH; | |
591 | GetClientSize(&clientW, &clientH); | |
2bda0e17 | 592 | |
a23fd0e1 VZ |
593 | int x = 0; |
594 | int y = 0; | |
73e7daa0 | 595 | |
a23fd0e1 VZ |
596 | child->SetSize(x, y, clientW, clientH); |
597 | } | |
2bda0e17 KB |
598 | } |
599 | ||
600 | // Default activation behaviour - set the focus for the first child | |
601 | // subwindow found. | |
602 | void wxFrame::OnActivate(wxActivateEvent& event) | |
603 | { | |
c0ed460c | 604 | for(wxNode *node = GetChildren().First(); node; node = node->Next()) |
2bda0e17 KB |
605 | { |
606 | // Find a child that's a subwindow, but not a dialog box. | |
607 | wxWindow *child = (wxWindow *)node->Data(); | |
608 | if (!child->IsKindOf(CLASSINFO(wxFrame)) && | |
609 | !child->IsKindOf(CLASSINFO(wxDialog))) | |
610 | { | |
2bda0e17 KB |
611 | child->SetFocus(); |
612 | return; | |
613 | } | |
614 | } | |
615 | } | |
616 | ||
e3065973 | 617 | // The default implementation for the close window event. |
2bda0e17 KB |
618 | void wxFrame::OnCloseWindow(wxCloseEvent& event) |
619 | { | |
42e69d6b | 620 | Destroy(); |
47fa7969 JS |
621 | } |
622 | ||
2bda0e17 | 623 | // Destroy the window (delayed, if a managed window) |
bfc6fde4 | 624 | bool wxFrame::Destroy() |
2bda0e17 KB |
625 | { |
626 | if (!wxPendingDelete.Member(this)) | |
627 | wxPendingDelete.Append(this); | |
628 | return TRUE; | |
629 | } | |
630 | ||
631 | // Default menu selection behaviour - display a help string | |
632 | void wxFrame::OnMenuHighlight(wxMenuEvent& event) | |
633 | { | |
634 | if (GetStatusBar()) | |
635 | { | |
d20eef8a VZ |
636 | int menuId = event.GetMenuId(); |
637 | if ( menuId != -1 ) | |
2bda0e17 KB |
638 | { |
639 | wxMenuBar *menuBar = GetMenuBar(); | |
58abfef6 | 640 | if (menuBar && menuBar->FindItem(menuId)) |
2bda0e17 | 641 | { |
d20eef8a VZ |
642 | // set status text even if the string is empty - this will at |
643 | // least remove the string from the item which was previously | |
644 | // selected | |
645 | SetStatusText(menuBar->GetHelpString(menuId)); | |
2bda0e17 KB |
646 | } |
647 | } | |
648 | } | |
649 | } | |
650 | ||
bfc6fde4 | 651 | wxMenuBar *wxFrame::GetMenuBar() const |
2bda0e17 KB |
652 | { |
653 | return m_frameMenuBar; | |
654 | } | |
655 | ||
42e69d6b | 656 | bool wxFrame::ProcessCommand(int id) |
2bda0e17 | 657 | { |
42e69d6b VZ |
658 | wxMenuBar *bar = GetMenuBar() ; |
659 | if ( !bar ) | |
660 | return FALSE; | |
2bda0e17 | 661 | |
42e69d6b VZ |
662 | wxMenuItem *item = bar->FindItemForId(id); |
663 | if ( !item ) | |
664 | return FALSE; | |
e702ff0f | 665 | |
42e69d6b VZ |
666 | if ( item->IsCheckable() ) |
667 | { | |
668 | bar->Check(id, !bar->IsChecked(id)) ; | |
669 | } | |
e702ff0f | 670 | |
42e69d6b VZ |
671 | wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); |
672 | commandEvent.SetInt( id ); | |
673 | commandEvent.SetEventObject( this ); | |
6c41a418 | 674 | |
42e69d6b | 675 | return GetEventHandler()->ProcessEvent(commandEvent); |
2bda0e17 KB |
676 | } |
677 | ||
81d66cf3 JS |
678 | // Checks if there is a toolbar, and returns the first free client position |
679 | wxPoint wxFrame::GetClientAreaOrigin() const | |
680 | { | |
681 | wxPoint pt(0, 0); | |
682 | if (GetToolBar()) | |
683 | { | |
684 | int w, h; | |
685 | GetToolBar()->GetSize(& w, & h); | |
686 | ||
687 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
688 | { | |
689 | pt.x += w; | |
690 | } | |
691 | else | |
692 | { | |
693 | pt.y += h; | |
694 | } | |
695 | } | |
696 | return pt; | |
697 | } | |
698 | ||
87d1e11f JS |
699 | void wxFrame::ScreenToClient(int *x, int *y) const |
700 | { | |
701 | wxWindow::ScreenToClient(x, y); | |
702 | ||
703 | // We may be faking the client origin. | |
704 | // So a window that's really at (0, 30) may appear | |
705 | // (to wxWin apps) to be at (0, 0). | |
706 | wxPoint pt(GetClientAreaOrigin()); | |
707 | *x -= pt.x; | |
708 | *y -= pt.y; | |
709 | } | |
710 | ||
711 | void wxFrame::ClientToScreen(int *x, int *y) const | |
712 | { | |
713 | // We may be faking the client origin. | |
714 | // So a window that's really at (0, 30) may appear | |
715 | // (to wxWin apps) to be at (0, 0). | |
716 | wxPoint pt1(GetClientAreaOrigin()); | |
717 | *x += pt1.x; | |
718 | *y += pt1.y; | |
719 | ||
720 | wxWindow::ClientToScreen(x, y); | |
721 | } | |
722 | ||
81d66cf3 JS |
723 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
724 | { | |
725 | wxCHECK_MSG( m_frameToolBar == NULL, FALSE, | |
42e69d6b | 726 | "recreating toolbar in wxFrame" ); |
81d66cf3 JS |
727 | |
728 | wxToolBar* toolBar = OnCreateToolBar(style, id, name); | |
729 | if (toolBar) | |
730 | { | |
731 | SetToolBar(toolBar); | |
732 | PositionToolBar(); | |
733 | return toolBar; | |
734 | } | |
735 | else | |
736 | { | |
737 | return NULL; | |
738 | } | |
739 | } | |
740 | ||
741 | wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name) | |
742 | { | |
743 | return new wxToolBar(this, id, wxDefaultPosition, wxDefaultSize, style, name); | |
744 | } | |
745 | ||
bfc6fde4 | 746 | void wxFrame::PositionToolBar() |
81d66cf3 | 747 | { |
81d66cf3 | 748 | RECT rect; |
42e69d6b | 749 | ::GetClientRect(GetHwnd(), &rect); |
81d66cf3 JS |
750 | |
751 | if ( GetStatusBar() ) | |
752 | { | |
753 | int statusX, statusY; | |
754 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
755 | rect.bottom -= statusY; | |
756 | } | |
757 | ||
758 | if (GetToolBar()) | |
759 | { | |
760 | int tw, th; | |
761 | GetToolBar()->GetSize(& tw, & th); | |
762 | ||
763 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
764 | { | |
765 | // Use the 'real' MSW position | |
766 | GetToolBar()->SetSize(0, 0, tw, rect.bottom, wxSIZE_NO_ADJUSTMENTS); | |
767 | } | |
768 | else | |
769 | { | |
770 | // Use the 'real' MSW position | |
771 | GetToolBar()->SetSize(0, 0, rect.right, th, wxSIZE_NO_ADJUSTMENTS); | |
772 | } | |
773 | } | |
774 | } | |
d2aef312 | 775 | |
a23fd0e1 VZ |
776 | // propagate our state change to all child frames: this allows us to emulate X |
777 | // Windows behaviour where child frames float independently of the parent one | |
778 | // on the desktop, but are iconized/restored with it | |
d2aef312 VZ |
779 | void wxFrame::IconizeChildFrames(bool bIconize) |
780 | { | |
a23fd0e1 VZ |
781 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
782 | node; | |
783 | node = node->GetNext() ) | |
784 | { | |
785 | wxWindow *win = node->GetData(); | |
786 | ||
787 | if ( win->IsKindOf(CLASSINFO(wxFrame)) ) | |
788 | { | |
789 | ((wxFrame *)win)->Iconize(bIconize); | |
790 | } | |
d2aef312 | 791 | } |
d2aef312 VZ |
792 | } |
793 | ||
a23fd0e1 | 794 | // =========================================================================== |
42e69d6b | 795 | // message processing |
a23fd0e1 VZ |
796 | // =========================================================================== |
797 | ||
42e69d6b VZ |
798 | // --------------------------------------------------------------------------- |
799 | // preprocessing | |
800 | // --------------------------------------------------------------------------- | |
801 | ||
802 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) | |
803 | { | |
804 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
805 | return TRUE; | |
806 | ||
807 | // try the menu bar accels | |
808 | wxMenuBar *menuBar = GetMenuBar(); | |
809 | if ( !menuBar ) | |
810 | return FALSE; | |
811 | ||
812 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
813 | return acceleratorTable.Ok() && | |
814 | ::TranslateAccelerator(GetHwnd(), | |
815 | GetTableHaccel(acceleratorTable), | |
816 | (MSG *)pMsg); | |
817 | } | |
818 | ||
819 | // --------------------------------------------------------------------------- | |
820 | // our private (non virtual) message handlers | |
821 | // --------------------------------------------------------------------------- | |
822 | ||
823 | bool wxFrame::HandlePaint() | |
824 | { | |
825 | RECT rect; | |
826 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
827 | { | |
828 | if ( m_iconized ) | |
829 | { | |
830 | HICON hIcon = m_icon.Ok() ? GetIconHicon(m_icon) | |
831 | : (HICON)m_defaultIcon; | |
832 | ||
833 | // Hold a pointer to the dc so long as the OnPaint() message | |
834 | // is being processed | |
835 | PAINTSTRUCT ps; | |
836 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
837 | ||
838 | // Erase background before painting or we get white background | |
839 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
840 | ||
841 | if ( hIcon ) | |
842 | { | |
843 | RECT rect; | |
844 | ::GetClientRect(GetHwnd(), &rect); | |
845 | ||
846 | // FIXME: why hardcoded? | |
847 | static const int icon_width = 32; | |
848 | static const int icon_height = 32; | |
849 | ||
850 | int icon_x = (int)((rect.right - icon_width)/2); | |
851 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
852 | ||
853 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
854 | } | |
855 | ||
856 | ::EndPaint(GetHwnd(), &ps); | |
857 | ||
858 | return TRUE; | |
859 | } | |
860 | else | |
861 | { | |
862 | wxPaintEvent event(m_windowId); | |
863 | event.m_eventObject = this; | |
864 | ||
865 | return GetEventHandler()->ProcessEvent(event); | |
866 | } | |
867 | } | |
868 | else | |
869 | { | |
870 | // nothing to paint - processed | |
871 | return TRUE; | |
872 | } | |
873 | } | |
874 | ||
875 | bool wxFrame::HandleSize(int x, int y, WXUINT id) | |
876 | { | |
877 | bool processed = FALSE; | |
878 | ||
879 | switch ( id ) | |
880 | { | |
881 | case SIZENORMAL: | |
882 | // only do it it if we were iconized before, otherwise resizing the | |
883 | // parent frame has a curious side effect of bringing it under it's | |
884 | // children | |
885 | if ( !m_iconized ) | |
886 | break; | |
887 | ||
888 | // restore all child frames too | |
889 | IconizeChildFrames(FALSE); | |
890 | ||
891 | // fall through | |
892 | ||
893 | case SIZEFULLSCREEN: | |
894 | m_iconized = FALSE; | |
895 | break; | |
896 | ||
897 | case SIZEICONIC: | |
898 | // iconize all child frames too | |
899 | IconizeChildFrames(TRUE); | |
900 | ||
901 | m_iconized = TRUE; | |
902 | break; | |
903 | } | |
904 | ||
905 | if ( !m_iconized ) | |
906 | { | |
907 | // forward WM_SIZE to status bar control | |
908 | #if wxUSE_NATIVE_STATUSBAR | |
909 | if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) | |
910 | { | |
911 | wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId()); | |
912 | event.SetEventObject( m_frameStatusBar ); | |
913 | ||
914 | ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); | |
915 | } | |
916 | #endif // wxUSE_NATIVE_STATUSBAR | |
917 | ||
918 | PositionStatusBar(); | |
919 | PositionToolBar(); | |
920 | ||
921 | wxSizeEvent event(wxSize(x, y), m_windowId); | |
922 | event.SetEventObject( this ); | |
923 | processed = GetEventHandler()->ProcessEvent(event); | |
924 | } | |
925 | ||
926 | return processed; | |
927 | } | |
928 | ||
929 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) | |
930 | { | |
931 | if ( control ) | |
932 | { | |
933 | // In case it's e.g. a toolbar. | |
934 | wxWindow *win = wxFindWinFromHandle(control); | |
935 | if ( win ) | |
936 | return win->MSWCommand(cmd, id); | |
937 | } | |
938 | ||
939 | // handle here commands from menus and accelerators | |
940 | if ( cmd == 0 || cmd == 1 ) | |
941 | { | |
942 | if ( wxCurrentPopupMenu ) | |
943 | { | |
944 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
945 | wxCurrentPopupMenu = NULL; | |
946 | ||
947 | return popupMenu->MSWCommand(cmd, id); | |
948 | } | |
949 | ||
950 | if ( ProcessCommand(id) ) | |
951 | { | |
952 | return TRUE; | |
953 | } | |
954 | } | |
955 | ||
956 | return FALSE; | |
957 | } | |
958 | ||
a23fd0e1 VZ |
959 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD nFlags, WXHMENU hMenu) |
960 | { | |
961 | int item; | |
962 | if ( nFlags == 0xFFFF && hMenu == 0 ) | |
963 | { | |
964 | // FIXME: what does this do? does it ever happen? | |
965 | item = -1; | |
966 | } | |
967 | else if ((nFlags != MF_SEPARATOR) && (nItem != 0) && (nItem != 65535)) | |
968 | { | |
969 | item = nItem; | |
970 | } | |
971 | else | |
972 | { | |
973 | return FALSE; | |
974 | } | |
975 | ||
976 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
977 | event.SetEventObject( this ); | |
978 | ||
979 | return GetEventHandler()->ProcessEvent(event); | |
980 | } | |
981 | ||
982 | // --------------------------------------------------------------------------- | |
983 | // the window proc for wxFrame | |
984 | // --------------------------------------------------------------------------- | |
985 | ||
986 | long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
987 | { | |
988 | long rc = 0; | |
989 | bool processed = FALSE; | |
990 | ||
991 | switch ( message ) | |
992 | { | |
42e69d6b VZ |
993 | case WM_CLOSE: |
994 | // if we can't close, tell the system that we processed the | |
995 | // message - otherwise it would close us | |
996 | processed = !Close(); | |
997 | break; | |
998 | ||
999 | case WM_COMMAND: | |
1000 | { | |
1001 | WORD id, cmd; | |
1002 | WXHWND hwnd; | |
1003 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
1004 | &id, &hwnd, &cmd); | |
1005 | ||
1006 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
1007 | } | |
1008 | break; | |
1009 | ||
a23fd0e1 VZ |
1010 | case WM_MENUSELECT: |
1011 | { | |
42e69d6b VZ |
1012 | WXWORD item, flags; |
1013 | WXHMENU hmenu; | |
1014 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
1015 | ||
1016 | processed = HandleMenuSelect(item, flags, hmenu); | |
a23fd0e1 VZ |
1017 | } |
1018 | break; | |
42e69d6b VZ |
1019 | |
1020 | case WM_PAINT: | |
1021 | processed = HandlePaint(); | |
1022 | break; | |
1023 | ||
1024 | case WM_QUERYDRAGICON: | |
1025 | { | |
1026 | HICON hIcon = m_icon.Ok() ? GetIconHicon(m_icon) | |
1027 | : (HICON)(m_defaultIcon); | |
1028 | rc = (long)hIcon; | |
1029 | processed = rc != 0; | |
1030 | } | |
1031 | break; | |
1032 | ||
1033 | case WM_SIZE: | |
1034 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
1035 | break; | |
a23fd0e1 VZ |
1036 | } |
1037 | ||
1038 | if ( !processed ) | |
1039 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
1040 | ||
1041 | return rc; | |
1042 | } |