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