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