]>
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 | |
223d09f6 | 410 | wxCHECK_RET( !menu_bar->GetFrame(), wxT("this menubar is already attached") ); |
2bda0e17 | 411 | |
c2dcfdef VZ |
412 | if (m_frameMenuBar) |
413 | delete m_frameMenuBar; | |
2bda0e17 | 414 | |
c2dcfdef | 415 | m_hMenu = menu_bar->Create(); |
2bda0e17 | 416 | |
c2dcfdef VZ |
417 | if ( !m_hMenu ) |
418 | return; | |
2bda0e17 | 419 | |
42e69d6b | 420 | InternalSetMenuBar(); |
2bda0e17 | 421 | |
c2dcfdef VZ |
422 | m_frameMenuBar = menu_bar; |
423 | menu_bar->Attach(this); | |
2bda0e17 KB |
424 | } |
425 | ||
42e69d6b | 426 | void wxFrame::InternalSetMenuBar() |
2bda0e17 | 427 | { |
42e69d6b | 428 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) |
2bda0e17 | 429 | { |
42e69d6b | 430 | wxLogLastError("SetMenu"); |
2bda0e17 | 431 | } |
2bda0e17 KB |
432 | } |
433 | ||
434 | // Responds to colour changes, and passes event on to children. | |
435 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
436 | { | |
437 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
438 | Refresh(); | |
439 | ||
440 | if ( m_frameStatusBar ) | |
441 | { | |
442 | wxSysColourChangedEvent event2; | |
443 | event2.SetEventObject( m_frameStatusBar ); | |
02800301 | 444 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); |
2bda0e17 KB |
445 | } |
446 | ||
447 | // Propagate the event to the non-top-level children | |
448 | wxWindow::OnSysColourChanged(event); | |
449 | } | |
450 | ||
451 | /* | |
452 | * Frame window | |
453 | * | |
454 | */ | |
455 | ||
837e5743 | 456 | bool wxFrame::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title, |
debe6624 | 457 | int x, int y, int width, int height, long style) |
2bda0e17 KB |
458 | |
459 | { | |
460 | m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); | |
461 | ||
462 | // If child windows aren't properly drawn initially, WS_CLIPCHILDREN | |
463 | // could be the culprit. But without it, you can get a lot of flicker. | |
464 | ||
2bda0e17 KB |
465 | DWORD msflags = 0; |
466 | if ((style & wxCAPTION) == wxCAPTION) | |
1c089c47 | 467 | msflags = WS_OVERLAPPED; |
2bda0e17 | 468 | else |
1c089c47 | 469 | msflags = WS_POPUP; |
2bda0e17 KB |
470 | |
471 | if (style & wxMINIMIZE_BOX) | |
472 | msflags |= WS_MINIMIZEBOX; | |
473 | if (style & wxMAXIMIZE_BOX) | |
474 | msflags |= WS_MAXIMIZEBOX; | |
475 | if (style & wxTHICK_FRAME) | |
476 | msflags |= WS_THICKFRAME; | |
477 | if (style & wxSYSTEM_MENU) | |
478 | msflags |= WS_SYSMENU; | |
479 | if ((style & wxMINIMIZE) || (style & wxICONIZE)) | |
480 | msflags |= WS_MINIMIZE; | |
481 | if (style & wxMAXIMIZE) | |
482 | msflags |= WS_MAXIMIZE; | |
483 | if (style & wxCAPTION) | |
484 | msflags |= WS_CAPTION; | |
1c089c47 JS |
485 | if (style & wxCLIP_CHILDREN) |
486 | msflags |= WS_CLIPCHILDREN; | |
2bda0e17 KB |
487 | |
488 | // Keep this in wxFrame because it saves recoding this function | |
489 | // in wxTinyFrame | |
47d67540 | 490 | #if wxUSE_ITSY_BITSY |
2bda0e17 KB |
491 | if (style & wxTINY_CAPTION_VERT) |
492 | msflags |= IBS_VERTCAPTION; | |
493 | if (style & wxTINY_CAPTION_HORIZ) | |
494 | msflags |= IBS_HORZCAPTION; | |
495 | #else | |
496 | if (style & wxTINY_CAPTION_VERT) | |
497 | msflags |= WS_CAPTION; | |
498 | if (style & wxTINY_CAPTION_HORIZ) | |
499 | msflags |= WS_CAPTION; | |
500 | #endif | |
501 | if ((style & wxTHICK_FRAME) == 0) | |
502 | msflags |= WS_BORDER; | |
503 | ||
504 | WXDWORD extendedStyle = MakeExtendedStyle(style); | |
505 | ||
2432b92d | 506 | #if !defined(__WIN16__) && !defined(__SC__) |
cd2df130 JS |
507 | if (style & wxFRAME_TOOL_WINDOW) |
508 | extendedStyle |= WS_EX_TOOLWINDOW; | |
1e6d9499 | 509 | #endif |
cd2df130 | 510 | |
2bda0e17 KB |
511 | if (style & wxSTAY_ON_TOP) |
512 | extendedStyle |= WS_EX_TOPMOST; | |
513 | ||
514 | m_iconized = FALSE; | |
a23fd0e1 VZ |
515 | if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height, |
516 | msflags, NULL, extendedStyle) ) | |
517 | return FALSE; | |
518 | ||
2bda0e17 KB |
519 | // Seems to be necessary if we use WS_POPUP |
520 | // style instead of WS_OVERLAPPED | |
521 | if (width > -1 && height > -1) | |
42e69d6b | 522 | ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height)); |
a23fd0e1 VZ |
523 | |
524 | return TRUE; | |
2bda0e17 KB |
525 | } |
526 | ||
2bda0e17 KB |
527 | // Default activation behaviour - set the focus for the first child |
528 | // subwindow found. | |
529 | void wxFrame::OnActivate(wxActivateEvent& event) | |
530 | { | |
319fefa9 VZ |
531 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
532 | node; | |
533 | node = node->GetNext() ) | |
2bda0e17 | 534 | { |
319fefa9 VZ |
535 | // FIXME all this is totally bogus - we need to do the same as wxPanel, |
536 | // but how to do it without duplicating the code? | |
537 | ||
538 | // restore focus | |
539 | wxWindow *child = node->GetData(); | |
540 | ||
541 | if ( !child->IsTopLevel() | |
542 | #if wxUSE_TOOLBAR | |
543 | && !wxDynamicCast(child, wxToolBar) | |
544 | #endif // wxUSE_TOOLBAR | |
545 | #if wxUSE_STATUSBAR | |
546 | && !wxDynamicCast(child, wxStatusBar) | |
547 | #endif // wxUSE_STATUSBAR | |
548 | ) | |
549 | { | |
550 | child->SetFocus(); | |
551 | return; | |
552 | } | |
2bda0e17 | 553 | } |
2bda0e17 KB |
554 | } |
555 | ||
7c0ea335 VZ |
556 | // ---------------------------------------------------------------------------- |
557 | // wxFrame size management: we exclude the areas taken by menu/status/toolbars | |
558 | // from the client area, so the client area is what's really available for the | |
559 | // frame contents | |
560 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 561 | |
81d66cf3 JS |
562 | // Checks if there is a toolbar, and returns the first free client position |
563 | wxPoint wxFrame::GetClientAreaOrigin() const | |
564 | { | |
565 | wxPoint pt(0, 0); | |
566 | if (GetToolBar()) | |
567 | { | |
568 | int w, h; | |
569 | GetToolBar()->GetSize(& w, & h); | |
570 | ||
571 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
572 | { | |
573 | pt.x += w; | |
574 | } | |
575 | else | |
576 | { | |
577 | pt.y += h; | |
578 | } | |
579 | } | |
580 | return pt; | |
581 | } | |
582 | ||
d59ceba5 | 583 | void wxFrame::DoScreenToClient(int *x, int *y) const |
87d1e11f | 584 | { |
d59ceba5 | 585 | wxWindow::DoScreenToClient(x, y); |
87d1e11f JS |
586 | |
587 | // We may be faking the client origin. | |
588 | // So a window that's really at (0, 30) may appear | |
589 | // (to wxWin apps) to be at (0, 0). | |
590 | wxPoint pt(GetClientAreaOrigin()); | |
591 | *x -= pt.x; | |
592 | *y -= pt.y; | |
593 | } | |
594 | ||
d59ceba5 | 595 | void wxFrame::DoClientToScreen(int *x, int *y) const |
87d1e11f JS |
596 | { |
597 | // We may be faking the client origin. | |
598 | // So a window that's really at (0, 30) may appear | |
599 | // (to wxWin apps) to be at (0, 0). | |
600 | wxPoint pt1(GetClientAreaOrigin()); | |
601 | *x += pt1.x; | |
602 | *y += pt1.y; | |
603 | ||
d59ceba5 | 604 | wxWindow::DoClientToScreen(x, y); |
87d1e11f JS |
605 | } |
606 | ||
7c0ea335 VZ |
607 | // ---------------------------------------------------------------------------- |
608 | // tool/status bar stuff | |
609 | // ---------------------------------------------------------------------------- | |
610 | ||
d427503c | 611 | #if wxUSE_TOOLBAR |
7c0ea335 | 612 | |
81d66cf3 JS |
613 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
614 | { | |
7c0ea335 | 615 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
81d66cf3 | 616 | { |
81d66cf3 | 617 | PositionToolBar(); |
81d66cf3 | 618 | } |
81d66cf3 | 619 | |
7c0ea335 | 620 | return m_frameToolBar; |
81d66cf3 JS |
621 | } |
622 | ||
bfc6fde4 | 623 | void wxFrame::PositionToolBar() |
81d66cf3 | 624 | { |
81d66cf3 | 625 | RECT rect; |
42e69d6b | 626 | ::GetClientRect(GetHwnd(), &rect); |
81d66cf3 | 627 | |
7c0ea335 | 628 | #if wxUSE_STATUSBAR |
81d66cf3 JS |
629 | if ( GetStatusBar() ) |
630 | { | |
7c0ea335 VZ |
631 | int statusX, statusY; |
632 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
633 | rect.bottom -= statusY; | |
81d66cf3 | 634 | } |
7c0ea335 | 635 | #endif // wxUSE_STATUSBAR |
81d66cf3 | 636 | |
7c0ea335 | 637 | if ( GetToolBar() ) |
81d66cf3 JS |
638 | { |
639 | int tw, th; | |
7c0ea335 | 640 | GetToolBar()->GetSize(&tw, &th); |
81d66cf3 | 641 | |
7c0ea335 | 642 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) |
81d66cf3 | 643 | { |
7c0ea335 | 644 | th = rect.bottom; |
81d66cf3 JS |
645 | } |
646 | else | |
647 | { | |
7c0ea335 | 648 | tw = rect.right; |
81d66cf3 | 649 | } |
7c0ea335 VZ |
650 | |
651 | // Use the 'real' MSW position here | |
652 | GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); | |
81d66cf3 JS |
653 | } |
654 | } | |
d427503c | 655 | #endif // wxUSE_TOOLBAR |
d2aef312 | 656 | |
7c0ea335 VZ |
657 | // ---------------------------------------------------------------------------- |
658 | // frame state (iconized/maximized/...) | |
659 | // ---------------------------------------------------------------------------- | |
660 | ||
a23fd0e1 VZ |
661 | // propagate our state change to all child frames: this allows us to emulate X |
662 | // Windows behaviour where child frames float independently of the parent one | |
663 | // on the desktop, but are iconized/restored with it | |
d2aef312 VZ |
664 | void wxFrame::IconizeChildFrames(bool bIconize) |
665 | { | |
a23fd0e1 VZ |
666 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
667 | node; | |
668 | node = node->GetNext() ) | |
669 | { | |
670 | wxWindow *win = node->GetData(); | |
671 | ||
672 | if ( win->IsKindOf(CLASSINFO(wxFrame)) ) | |
673 | { | |
674 | ((wxFrame *)win)->Iconize(bIconize); | |
675 | } | |
d2aef312 | 676 | } |
d2aef312 VZ |
677 | } |
678 | ||
a23fd0e1 | 679 | // =========================================================================== |
42e69d6b | 680 | // message processing |
a23fd0e1 VZ |
681 | // =========================================================================== |
682 | ||
42e69d6b VZ |
683 | // --------------------------------------------------------------------------- |
684 | // preprocessing | |
685 | // --------------------------------------------------------------------------- | |
686 | ||
687 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) | |
688 | { | |
689 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
690 | return TRUE; | |
691 | ||
692 | // try the menu bar accels | |
693 | wxMenuBar *menuBar = GetMenuBar(); | |
694 | if ( !menuBar ) | |
695 | return FALSE; | |
696 | ||
697 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
c50f1fb9 | 698 | return acceleratorTable.Translate(this, pMsg); |
42e69d6b VZ |
699 | } |
700 | ||
701 | // --------------------------------------------------------------------------- | |
702 | // our private (non virtual) message handlers | |
703 | // --------------------------------------------------------------------------- | |
704 | ||
705 | bool wxFrame::HandlePaint() | |
706 | { | |
707 | RECT rect; | |
708 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
709 | { | |
710 | if ( m_iconized ) | |
711 | { | |
c50f1fb9 | 712 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
42e69d6b VZ |
713 | : (HICON)m_defaultIcon; |
714 | ||
715 | // Hold a pointer to the dc so long as the OnPaint() message | |
716 | // is being processed | |
717 | PAINTSTRUCT ps; | |
718 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
719 | ||
720 | // Erase background before painting or we get white background | |
721 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
722 | ||
723 | if ( hIcon ) | |
724 | { | |
725 | RECT rect; | |
726 | ::GetClientRect(GetHwnd(), &rect); | |
727 | ||
728 | // FIXME: why hardcoded? | |
729 | static const int icon_width = 32; | |
730 | static const int icon_height = 32; | |
731 | ||
732 | int icon_x = (int)((rect.right - icon_width)/2); | |
733 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
734 | ||
735 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
736 | } | |
737 | ||
738 | ::EndPaint(GetHwnd(), &ps); | |
739 | ||
740 | return TRUE; | |
741 | } | |
742 | else | |
743 | { | |
5d1d2d46 | 744 | return wxWindow::HandlePaint(); |
42e69d6b VZ |
745 | } |
746 | } | |
747 | else | |
748 | { | |
749 | // nothing to paint - processed | |
750 | return TRUE; | |
751 | } | |
752 | } | |
753 | ||
754 | bool wxFrame::HandleSize(int x, int y, WXUINT id) | |
755 | { | |
756 | bool processed = FALSE; | |
757 | ||
758 | switch ( id ) | |
759 | { | |
760 | case SIZENORMAL: | |
761 | // only do it it if we were iconized before, otherwise resizing the | |
762 | // parent frame has a curious side effect of bringing it under it's | |
763 | // children | |
764 | if ( !m_iconized ) | |
765 | break; | |
766 | ||
767 | // restore all child frames too | |
768 | IconizeChildFrames(FALSE); | |
769 | ||
770 | // fall through | |
771 | ||
772 | case SIZEFULLSCREEN: | |
773 | m_iconized = FALSE; | |
774 | break; | |
775 | ||
776 | case SIZEICONIC: | |
777 | // iconize all child frames too | |
778 | IconizeChildFrames(TRUE); | |
779 | ||
780 | m_iconized = TRUE; | |
781 | break; | |
782 | } | |
783 | ||
784 | if ( !m_iconized ) | |
785 | { | |
786 | // forward WM_SIZE to status bar control | |
787 | #if wxUSE_NATIVE_STATUSBAR | |
788 | if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) | |
789 | { | |
790 | wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId()); | |
791 | event.SetEventObject( m_frameStatusBar ); | |
792 | ||
793 | ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); | |
794 | } | |
795 | #endif // wxUSE_NATIVE_STATUSBAR | |
796 | ||
797 | PositionStatusBar(); | |
798 | PositionToolBar(); | |
799 | ||
800 | wxSizeEvent event(wxSize(x, y), m_windowId); | |
801 | event.SetEventObject( this ); | |
802 | processed = GetEventHandler()->ProcessEvent(event); | |
803 | } | |
804 | ||
805 | return processed; | |
806 | } | |
807 | ||
808 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) | |
809 | { | |
810 | if ( control ) | |
811 | { | |
812 | // In case it's e.g. a toolbar. | |
813 | wxWindow *win = wxFindWinFromHandle(control); | |
814 | if ( win ) | |
815 | return win->MSWCommand(cmd, id); | |
816 | } | |
817 | ||
818 | // handle here commands from menus and accelerators | |
819 | if ( cmd == 0 || cmd == 1 ) | |
820 | { | |
821 | if ( wxCurrentPopupMenu ) | |
822 | { | |
823 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
824 | wxCurrentPopupMenu = NULL; | |
825 | ||
826 | return popupMenu->MSWCommand(cmd, id); | |
827 | } | |
828 | ||
829 | if ( ProcessCommand(id) ) | |
830 | { | |
831 | return TRUE; | |
832 | } | |
833 | } | |
834 | ||
835 | return FALSE; | |
836 | } | |
837 | ||
c219cecc | 838 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) |
a23fd0e1 VZ |
839 | { |
840 | int item; | |
c219cecc | 841 | if ( flags == 0xFFFF && hMenu == 0 ) |
a23fd0e1 | 842 | { |
c219cecc | 843 | // menu was removed from screen |
a23fd0e1 VZ |
844 | item = -1; |
845 | } | |
c219cecc | 846 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) |
a23fd0e1 VZ |
847 | { |
848 | item = nItem; | |
849 | } | |
850 | else | |
851 | { | |
c219cecc VZ |
852 | // don't give hints for separators (doesn't make sense) nor for the |
853 | // items opening popup menus (they don't have them anyhow) | |
a23fd0e1 VZ |
854 | return FALSE; |
855 | } | |
856 | ||
857 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
858 | event.SetEventObject( this ); | |
859 | ||
860 | return GetEventHandler()->ProcessEvent(event); | |
861 | } | |
862 | ||
863 | // --------------------------------------------------------------------------- | |
864 | // the window proc for wxFrame | |
865 | // --------------------------------------------------------------------------- | |
866 | ||
867 | long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) | |
868 | { | |
869 | long rc = 0; | |
870 | bool processed = FALSE; | |
871 | ||
872 | switch ( message ) | |
873 | { | |
42e69d6b VZ |
874 | case WM_CLOSE: |
875 | // if we can't close, tell the system that we processed the | |
876 | // message - otherwise it would close us | |
877 | processed = !Close(); | |
878 | break; | |
879 | ||
880 | case WM_COMMAND: | |
881 | { | |
882 | WORD id, cmd; | |
883 | WXHWND hwnd; | |
884 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
885 | &id, &hwnd, &cmd); | |
886 | ||
887 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
888 | } | |
889 | break; | |
890 | ||
a23fd0e1 VZ |
891 | case WM_MENUSELECT: |
892 | { | |
42e69d6b VZ |
893 | WXWORD item, flags; |
894 | WXHMENU hmenu; | |
895 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
896 | ||
897 | processed = HandleMenuSelect(item, flags, hmenu); | |
a23fd0e1 VZ |
898 | } |
899 | break; | |
42e69d6b VZ |
900 | |
901 | case WM_PAINT: | |
902 | processed = HandlePaint(); | |
903 | break; | |
904 | ||
905 | case WM_QUERYDRAGICON: | |
906 | { | |
c50f1fb9 | 907 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
42e69d6b VZ |
908 | : (HICON)(m_defaultIcon); |
909 | rc = (long)hIcon; | |
910 | processed = rc != 0; | |
911 | } | |
912 | break; | |
913 | ||
914 | case WM_SIZE: | |
915 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
916 | break; | |
a23fd0e1 VZ |
917 | } |
918 | ||
919 | if ( !processed ) | |
920 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
921 | ||
922 | return rc; | |
923 | } | |
21802234 | 924 |