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