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