]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
7c0ea335 | 2 | // Name: msw/frame.cpp |
1e6feb95 | 3 | // Purpose: wxFrameMSW |
2bda0e17 KB |
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 | 32 | #include "wx/frame.h" |
9f3362c4 | 33 | #include "wx/app.h" |
1e6feb95 | 34 | #include "wx/menu.h" |
9f3362c4 VZ |
35 | #include "wx/utils.h" |
36 | #include "wx/dialog.h" | |
37 | #include "wx/settings.h" | |
38 | #include "wx/dcclient.h" | |
d3cc7c65 | 39 | #include "wx/mdi.h" |
f6bcfd97 | 40 | #include "wx/panel.h" |
9f3362c4 | 41 | #endif // WX_PRECOMP |
2bda0e17 KB |
42 | |
43 | #include "wx/msw/private.h" | |
7c0ea335 VZ |
44 | |
45 | #if wxUSE_STATUSBAR | |
46 | #include "wx/statusbr.h" | |
ed791986 | 47 | #include "wx/generic/statusbr.h" |
7c0ea335 VZ |
48 | #endif // wxUSE_STATUSBAR |
49 | ||
50 | #if wxUSE_TOOLBAR | |
51 | #include "wx/toolbar.h" | |
52 | #endif // wxUSE_TOOLBAR | |
53 | ||
2bda0e17 | 54 | #include "wx/menuitem.h" |
6776a0b2 | 55 | #include "wx/log.h" |
2bda0e17 | 56 | |
1e6feb95 VZ |
57 | #ifdef __WXUNIVERSAL__ |
58 | #include "wx/univ/theme.h" | |
59 | #include "wx/univ/colschem.h" | |
60 | #endif // __WXUNIVERSAL__ | |
61 | ||
7c0ea335 VZ |
62 | // ---------------------------------------------------------------------------- |
63 | // globals | |
64 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 65 | |
a23fd0e1 | 66 | extern wxWindowList wxModelessWindows; |
cde9f08e | 67 | extern wxList WXDLLEXPORT wxPendingDelete; |
2ffa221c | 68 | extern const wxChar *wxFrameClassName; |
1e6feb95 VZ |
69 | |
70 | #if wxUSE_MENUS_NATIVE | |
e1a6fc11 | 71 | extern wxMenu *wxCurrentPopupMenu; |
1e6feb95 | 72 | #endif // wxUSE_MENUS_NATIVE |
2bda0e17 | 73 | |
7c0ea335 VZ |
74 | // ---------------------------------------------------------------------------- |
75 | // event tables | |
76 | // ---------------------------------------------------------------------------- | |
77 | ||
1e6feb95 VZ |
78 | BEGIN_EVENT_TABLE(wxFrameMSW, wxFrameBase) |
79 | EVT_ACTIVATE(wxFrameMSW::OnActivate) | |
80 | EVT_SYS_COLOUR_CHANGED(wxFrameMSW::OnSysColourChanged) | |
2bda0e17 KB |
81 | END_EVENT_TABLE() |
82 | ||
1e6feb95 | 83 | IMPLEMENT_DYNAMIC_CLASS(wxFrameMSW, wxWindow) |
3a12b404 | 84 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxFrameMSW) |
2bda0e17 | 85 | |
7c0ea335 VZ |
86 | // ============================================================================ |
87 | // implementation | |
88 | // ============================================================================ | |
89 | ||
90 | // ---------------------------------------------------------------------------- | |
91 | // static class members | |
92 | // ---------------------------------------------------------------------------- | |
93 | ||
1e6feb95 VZ |
94 | #if wxUSE_STATUSBAR |
95 | #if wxUSE_NATIVE_STATUSBAR | |
96 | bool wxFrameMSW::m_useNativeStatusBar = TRUE; | |
97 | #else | |
98 | bool wxFrameMSW::m_useNativeStatusBar = FALSE; | |
99 | #endif | |
100 | #endif // wxUSE_NATIVE_STATUSBAR | |
2bda0e17 | 101 | |
7c0ea335 VZ |
102 | // ---------------------------------------------------------------------------- |
103 | // creation/destruction | |
104 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 105 | |
1e6feb95 | 106 | void wxFrameMSW::Init() |
2bda0e17 | 107 | { |
bf505d28 VZ |
108 | m_iconized = |
109 | m_maximizeOnShow = FALSE; | |
7c0ea335 | 110 | |
9f3362c4 VZ |
111 | #if wxUSE_TOOLTIPS |
112 | m_hwndToolTip = 0; | |
113 | #endif | |
a2327a9f JS |
114 | |
115 | // Data to save/restore when calling ShowFullScreen | |
116 | m_fsStyle = 0; | |
117 | m_fsOldWindowStyle = 0; | |
118 | m_fsStatusBarFields = 0; | |
119 | m_fsStatusBarHeight = 0; | |
120 | m_fsToolBarHeight = 0; | |
f6bcfd97 | 121 | // m_fsMenu = 0; |
a2327a9f JS |
122 | m_fsIsMaximized = FALSE; |
123 | m_fsIsShowing = FALSE; | |
f6bcfd97 BP |
124 | |
125 | m_winLastFocused = (wxWindow *)NULL; | |
126 | ||
127 | // unlike (almost?) all other windows, frames are created hidden | |
128 | m_isShown = FALSE; | |
7c0ea335 | 129 | } |
9f3362c4 | 130 | |
1e6feb95 | 131 | bool wxFrameMSW::Create(wxWindow *parent, |
7c0ea335 VZ |
132 | wxWindowID id, |
133 | const wxString& title, | |
134 | const wxPoint& pos, | |
135 | const wxSize& size, | |
136 | long style, | |
137 | const wxString& name) | |
138 | { | |
2bda0e17 | 139 | SetName(name); |
2bda0e17 | 140 | m_windowStyle = style; |
1e6feb95 | 141 | #if wxUSE_MENUS |
2bda0e17 | 142 | m_frameMenuBar = NULL; |
1e6feb95 VZ |
143 | #endif // wxUSE_MENUS |
144 | #if wxUSE_TOOLBAR | |
7c0ea335 | 145 | m_frameToolBar = NULL; |
1e6feb95 VZ |
146 | #endif // wxUSE_TOOLBAR |
147 | #if wxUSE_STATUSBAR | |
2bda0e17 | 148 | m_frameStatusBar = NULL; |
1e6feb95 | 149 | #endif // wxUSE_STATUSBAR |
2bda0e17 KB |
150 | |
151 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
152 | ||
2bda0e17 KB |
153 | if ( id > -1 ) |
154 | m_windowId = id; | |
155 | else | |
156 | m_windowId = (int)NewControlId(); | |
157 | ||
158 | if (parent) parent->AddChild(this); | |
159 | ||
160 | int x = pos.x; | |
161 | int y = pos.y; | |
162 | int width = size.x; | |
163 | int height = size.y; | |
164 | ||
165 | m_iconized = FALSE; | |
d2aef312 | 166 | |
f6bcfd97 | 167 | wxTopLevelWindows.Append(this); |
319fefa9 | 168 | |
aeab10d0 | 169 | MSWCreate(m_windowId, parent, wxFrameClassName, this, title, |
d2aef312 | 170 | x, y, width, height, style); |
2bda0e17 KB |
171 | |
172 | wxModelessWindows.Append(this); | |
f6bcfd97 | 173 | |
2bda0e17 KB |
174 | return TRUE; |
175 | } | |
176 | ||
1e6feb95 | 177 | wxFrameMSW::~wxFrameMSW() |
2bda0e17 KB |
178 | { |
179 | m_isBeingDeleted = TRUE; | |
180 | wxTopLevelWindows.DeleteObject(this); | |
181 | ||
f6bcfd97 BP |
182 | // the ~wxToolBar() code relies on the previous line to be executed before |
183 | // this one, i.e. the frame should remove itself from wxTopLevelWindows | |
184 | // before destorying its toolbar | |
7c0ea335 | 185 | DeleteAllBars(); |
2bda0e17 KB |
186 | |
187 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
188 | { | |
189 | wxTheApp->SetTopWindow(NULL); | |
190 | ||
191 | if (wxTheApp->GetExitOnFrameDelete()) | |
192 | { | |
193 | PostQuitMessage(0); | |
194 | } | |
195 | } | |
196 | ||
197 | wxModelessWindows.DeleteObject(this); | |
198 | ||
199 | // For some reason, wxWindows can activate another task altogether | |
200 | // when a frame is destroyed after a modal dialog has been invoked. | |
201 | // Try to bring the parent to the top. | |
36e2955a UM |
202 | // MT:Only do this if this frame is currently the active window, else weird |
203 | // things start to happen | |
204 | if ( wxGetActiveWindow() == this ) | |
2bda0e17 KB |
205 | if (GetParent() && GetParent()->GetHWND()) |
206 | ::BringWindowToTop((HWND) GetParent()->GetHWND()); | |
207 | } | |
208 | ||
81d66cf3 | 209 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
1e6feb95 | 210 | void wxFrameMSW::DoGetClientSize(int *x, int *y) const |
2bda0e17 KB |
211 | { |
212 | RECT rect; | |
42e69d6b | 213 | ::GetClientRect(GetHwnd(), &rect); |
2bda0e17 | 214 | |
7c0ea335 | 215 | #if wxUSE_STATUSBAR |
a2327a9f | 216 | if ( GetStatusBar() && GetStatusBar()->IsShown() ) |
2bda0e17 | 217 | { |
81d66cf3 JS |
218 | int statusX, statusY; |
219 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
220 | rect.bottom -= statusY; | |
2bda0e17 | 221 | } |
7c0ea335 | 222 | #endif // wxUSE_STATUSBAR |
81d66cf3 JS |
223 | |
224 | wxPoint pt(GetClientAreaOrigin()); | |
225 | rect.bottom -= pt.y; | |
226 | rect.right -= pt.x; | |
227 | ||
0655ad29 VZ |
228 | if ( x ) |
229 | *x = rect.right; | |
230 | if ( y ) | |
231 | *y = rect.bottom; | |
2bda0e17 KB |
232 | } |
233 | ||
234 | // Set the client size (i.e. leave the calculation of borders etc. | |
235 | // to wxWindows) | |
1e6feb95 | 236 | void wxFrameMSW::DoSetClientSize(int width, int height) |
2bda0e17 | 237 | { |
8d8bd249 | 238 | HWND hWnd = GetHwnd(); |
2bda0e17 | 239 | |
8d8bd249 VZ |
240 | RECT rectClient; |
241 | ::GetClientRect(hWnd, &rectClient); | |
2bda0e17 | 242 | |
8d8bd249 VZ |
243 | RECT rectTotal; |
244 | ::GetWindowRect(hWnd, &rectTotal); | |
2bda0e17 | 245 | |
8d8bd249 VZ |
246 | // Find the difference between the entire window (title bar and all) |
247 | // and the client area; add this to the new client size to move the | |
248 | // window | |
249 | width += rectTotal.right - rectTotal.left - rectClient.right; | |
250 | height += rectTotal.bottom - rectTotal.top - rectClient.bottom; | |
2bda0e17 | 251 | |
7c0ea335 | 252 | #if wxUSE_STATUSBAR |
8d8bd249 VZ |
253 | wxStatusBar *statbar = GetStatusBar(); |
254 | if ( statbar && statbar->IsShown() ) | |
255 | { | |
256 | // leave enough space for the status bar | |
257 | height += statbar->GetSize().y; | |
258 | } | |
7c0ea335 | 259 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 260 | |
8d8bd249 VZ |
261 | // note that this takes the toolbar into account |
262 | wxPoint pt = GetClientAreaOrigin(); | |
263 | width += pt.x; | |
264 | height += pt.y; | |
2bda0e17 | 265 | |
8d8bd249 VZ |
266 | if ( !::MoveWindow(hWnd, rectTotal.left, rectTotal.top, |
267 | width, height, TRUE /* redraw */) ) | |
268 | { | |
269 | wxLogLastError(_T("MoveWindow")); | |
270 | } | |
debe6624 | 271 | |
8d8bd249 VZ |
272 | wxSizeEvent event(wxSize(width, height), m_windowId); |
273 | event.SetEventObject(this); | |
274 | GetEventHandler()->ProcessEvent(event); | |
2bda0e17 KB |
275 | } |
276 | ||
1e6feb95 | 277 | void wxFrameMSW::DoGetSize(int *width, int *height) const |
2bda0e17 | 278 | { |
3dd9b88a VZ |
279 | RECT rect; |
280 | ::GetWindowRect(GetHwnd(), &rect); | |
281 | ||
282 | *width = rect.right - rect.left; | |
283 | *height = rect.bottom - rect.top; | |
2bda0e17 KB |
284 | } |
285 | ||
1e6feb95 | 286 | void wxFrameMSW::DoGetPosition(int *x, int *y) const |
2bda0e17 | 287 | { |
3dd9b88a VZ |
288 | RECT rect; |
289 | ::GetWindowRect(GetHwnd(), &rect); | |
2bda0e17 | 290 | |
3dd9b88a VZ |
291 | *x = rect.left; |
292 | *y = rect.top; | |
2bda0e17 KB |
293 | } |
294 | ||
7c0ea335 VZ |
295 | // ---------------------------------------------------------------------------- |
296 | // variations around ::ShowWindow() | |
297 | // ---------------------------------------------------------------------------- | |
298 | ||
1e6feb95 | 299 | void wxFrameMSW::DoShowWindow(int nShowCmd) |
7c0ea335 VZ |
300 | { |
301 | ::ShowWindow(GetHwnd(), nShowCmd); | |
302 | ||
303 | m_iconized = nShowCmd == SW_MINIMIZE; | |
304 | } | |
305 | ||
1e6feb95 | 306 | bool wxFrameMSW::Show(bool show) |
2bda0e17 | 307 | { |
f6bcfd97 BP |
308 | // don't use wxWindow version as we want to call DoShowWindow() |
309 | if ( !wxWindowBase::Show(show) ) | |
310 | return FALSE; | |
311 | ||
bf505d28 VZ |
312 | int nShowCmd; |
313 | if ( show ) | |
314 | { | |
315 | if ( m_maximizeOnShow ) | |
316 | { | |
317 | // show and maximize | |
318 | nShowCmd = SW_MAXIMIZE; | |
319 | ||
320 | m_maximizeOnShow = FALSE; | |
321 | } | |
322 | else // just show | |
323 | { | |
324 | nShowCmd = SW_SHOW; | |
325 | } | |
326 | } | |
327 | else // hide | |
328 | { | |
329 | nShowCmd = SW_HIDE; | |
330 | } | |
331 | ||
332 | DoShowWindow(nShowCmd); | |
2bda0e17 | 333 | |
7c0ea335 | 334 | if ( show ) |
2bda0e17 | 335 | { |
7c0ea335 | 336 | ::BringWindowToTop(GetHwnd()); |
2bda0e17 | 337 | |
7c0ea335 VZ |
338 | wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); |
339 | event.SetEventObject( this ); | |
340 | GetEventHandler()->ProcessEvent(event); | |
341 | } | |
bf505d28 | 342 | else // hide |
7c0ea335 VZ |
343 | { |
344 | // Try to highlight the correct window (the parent) | |
345 | if ( GetParent() ) | |
346 | { | |
347 | HWND hWndParent = GetHwndOf(GetParent()); | |
348 | if (hWndParent) | |
349 | ::BringWindowToTop(hWndParent); | |
350 | } | |
351 | } | |
2bda0e17 | 352 | |
7c0ea335 | 353 | return TRUE; |
2bda0e17 KB |
354 | } |
355 | ||
1e6feb95 | 356 | void wxFrameMSW::Iconize(bool iconize) |
2bda0e17 | 357 | { |
7c0ea335 | 358 | DoShowWindow(iconize ? SW_MINIMIZE : SW_RESTORE); |
2bda0e17 KB |
359 | } |
360 | ||
1e6feb95 | 361 | void wxFrameMSW::Maximize(bool maximize) |
2bda0e17 | 362 | { |
bf505d28 VZ |
363 | if ( IsShown() ) |
364 | { | |
365 | // just maximize it directly | |
366 | DoShowWindow(maximize ? SW_MAXIMIZE : SW_RESTORE); | |
367 | } | |
368 | else // hidden | |
369 | { | |
370 | // we can't maximize the hidden frame because it shows it as well, so | |
371 | // just remember that we should do it later in this case | |
372 | m_maximizeOnShow = TRUE; | |
373 | } | |
7c0ea335 VZ |
374 | } |
375 | ||
1e6feb95 | 376 | void wxFrameMSW::Restore() |
7c0ea335 VZ |
377 | { |
378 | DoShowWindow(SW_RESTORE); | |
2bda0e17 KB |
379 | } |
380 | ||
1e6feb95 | 381 | bool wxFrameMSW::IsIconized() const |
2bda0e17 | 382 | { |
04ef50df JS |
383 | #ifdef __WXMICROWIN__ |
384 | // TODO | |
385 | return FALSE; | |
386 | #else | |
1e6feb95 | 387 | ((wxFrameMSW *)this)->m_iconized = (::IsIconic(GetHwnd()) != 0); |
2bda0e17 | 388 | return m_iconized; |
04ef50df | 389 | #endif |
2bda0e17 KB |
390 | } |
391 | ||
6f63ec3f | 392 | // Is it maximized? |
1e6feb95 | 393 | bool wxFrameMSW::IsMaximized() const |
6f63ec3f | 394 | { |
04ef50df JS |
395 | #ifdef __WXMICROWIN__ |
396 | // TODO | |
397 | return FALSE; | |
398 | #else | |
7c0ea335 | 399 | return (::IsZoomed(GetHwnd()) != 0); |
04ef50df | 400 | #endif |
2bda0e17 KB |
401 | } |
402 | ||
1e6feb95 | 403 | void wxFrameMSW::SetIcon(const wxIcon& icon) |
2bda0e17 | 404 | { |
7c0ea335 VZ |
405 | wxFrameBase::SetIcon(icon); |
406 | ||
04ef50df | 407 | #if defined(__WIN95__) && !defined(__WXMICROWIN__) |
7c0ea335 VZ |
408 | if ( m_icon.Ok() ) |
409 | { | |
410 | SendMessage(GetHwnd(), WM_SETICON, | |
411 | (WPARAM)TRUE, (LPARAM)(HICON) m_icon.GetHICON()); | |
412 | } | |
413 | #endif // __WIN95__ | |
2bda0e17 KB |
414 | } |
415 | ||
67bd5bad | 416 | // generate an artificial resize event |
3a12b404 | 417 | void wxFrameMSW::SendSizeEvent() |
67bd5bad GT |
418 | { |
419 | RECT r; | |
420 | #ifdef __WIN16__ | |
421 | ::GetWindowRect(GetHwnd(), &r); | |
422 | #else | |
423 | if ( !::GetWindowRect(GetHwnd(), &r) ) | |
424 | { | |
425 | wxLogLastError(_T("GetWindowRect")); | |
426 | } | |
427 | #endif | |
428 | ||
429 | if ( !m_iconized ) | |
430 | { | |
431 | (void)::PostMessage(GetHwnd(), WM_SIZE, | |
432 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
433 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
434 | } | |
435 | } | |
436 | ||
d427503c | 437 | #if wxUSE_STATUSBAR |
1e6feb95 | 438 | wxStatusBar *wxFrameMSW::OnCreateStatusBar(int number, |
7c0ea335 VZ |
439 | long style, |
440 | wxWindowID id, | |
441 | const wxString& name) | |
2bda0e17 KB |
442 | { |
443 | wxStatusBar *statusBar = NULL; | |
444 | ||
47d67540 | 445 | #if wxUSE_NATIVE_STATUSBAR |
1f0500b3 | 446 | if ( !UsesNativeStatusBar() ) |
2bda0e17 | 447 | { |
1f0500b3 | 448 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); |
2bda0e17 KB |
449 | } |
450 | else | |
451 | #endif | |
452 | { | |
1f0500b3 VZ |
453 | statusBar = new wxStatusBar(this, id, style, name); |
454 | } | |
ed791986 | 455 | |
1f0500b3 VZ |
456 | // Set the height according to the font and the border size |
457 | wxClientDC dc(statusBar); | |
458 | dc.SetFont(statusBar->GetFont()); | |
ed791986 | 459 | |
1f0500b3 VZ |
460 | wxCoord y; |
461 | dc.GetTextExtent(_T("X"), NULL, &y ); | |
ed791986 | 462 | |
1f0500b3 | 463 | int height = (int)( (11*y)/10 + 2*statusBar->GetBorderY()); |
ed791986 | 464 | |
1f0500b3 | 465 | statusBar->SetSize(-1, -1, -1, height); |
ed791986 | 466 | |
1f0500b3 | 467 | statusBar->SetFieldsCount(number); |
2bda0e17 | 468 | |
7c0ea335 | 469 | return statusBar; |
2bda0e17 KB |
470 | } |
471 | ||
1e6feb95 | 472 | void wxFrameMSW::PositionStatusBar() |
2bda0e17 | 473 | { |
ed791986 VZ |
474 | if ( !m_frameStatusBar ) |
475 | return; | |
476 | ||
cbc66a27 VZ |
477 | int w, h; |
478 | GetClientSize(&w, &h); | |
479 | int sw, sh; | |
480 | m_frameStatusBar->GetSize(&sw, &sh); | |
481 | ||
482 | // Since we wish the status bar to be directly under the client area, | |
483 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
484 | m_frameStatusBar->SetSize(0, h, w, sh); | |
2bda0e17 | 485 | } |
d427503c | 486 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 487 | |
1e6feb95 | 488 | void wxFrameMSW::DetachMenuBar() |
ea9a4296 | 489 | { |
1e6feb95 | 490 | #if wxUSE_MENUS |
f6bcfd97 | 491 | if ( m_frameMenuBar ) |
ea9a4296 UM |
492 | { |
493 | m_frameMenuBar->Detach(); | |
494 | m_frameMenuBar = NULL; | |
495 | } | |
1e6feb95 | 496 | #endif // wxUSE_MENUS |
ea9a4296 UM |
497 | } |
498 | ||
1e6feb95 | 499 | void wxFrameMSW::SetMenuBar(wxMenuBar *menubar) |
2bda0e17 | 500 | { |
1e6feb95 VZ |
501 | #if wxUSE_MENUS |
502 | // detach the old menu bar in any case | |
503 | DetachMenuBar(); | |
504 | ||
505 | #if wxUSE_MENUS_NATIVE | |
f6bcfd97 | 506 | if ( !menubar ) |
c2dcfdef | 507 | { |
f6bcfd97 BP |
508 | // actually remove the menu from the frame |
509 | m_hMenu = (WXHMENU)0; | |
510 | InternalSetMenuBar(); | |
065de612 | 511 | } |
f6bcfd97 | 512 | else // set new non NULL menu bar |
065de612 | 513 | { |
f6bcfd97 | 514 | // Can set a menubar several times. |
f6bcfd97 BP |
515 | if ( menubar->GetHMenu() ) |
516 | { | |
517 | m_hMenu = menubar->GetHMenu(); | |
518 | } | |
519 | else | |
520 | { | |
ff8b6290 JS |
521 | if (menubar->IsAttached()) |
522 | menubar->Detach(); | |
065de612 | 523 | |
f6bcfd97 | 524 | m_hMenu = menubar->Create(); |
065de612 | 525 | |
f6bcfd97 BP |
526 | if ( !m_hMenu ) |
527 | return; | |
528 | } | |
065de612 | 529 | |
f6bcfd97 | 530 | InternalSetMenuBar(); |
1e6feb95 VZ |
531 | } |
532 | #endif // wxUSE_MENUS_NATIVE | |
065de612 | 533 | |
1e6feb95 VZ |
534 | if ( menubar ) |
535 | { | |
f6bcfd97 | 536 | m_frameMenuBar = menubar; |
1e6feb95 | 537 | menubar->Attach((wxFrame *)this); |
065de612 | 538 | } |
1e6feb95 | 539 | #endif // wxUSE_MENUS |
2bda0e17 KB |
540 | } |
541 | ||
1e6feb95 VZ |
542 | #if wxUSE_MENUS_NATIVE |
543 | ||
544 | void wxFrameMSW::InternalSetMenuBar() | |
2bda0e17 | 545 | { |
04ef50df | 546 | #ifndef __WXMICROWIN__ |
42e69d6b | 547 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) |
2bda0e17 | 548 | { |
f6bcfd97 | 549 | wxLogLastError(wxT("SetMenu")); |
2bda0e17 | 550 | } |
04ef50df | 551 | #endif |
2bda0e17 KB |
552 | } |
553 | ||
1e6feb95 VZ |
554 | #endif // wxUSE_MENUS_NATIVE |
555 | ||
2bda0e17 | 556 | // Responds to colour changes, and passes event on to children. |
1e6feb95 | 557 | void wxFrameMSW::OnSysColourChanged(wxSysColourChangedEvent& event) |
2bda0e17 KB |
558 | { |
559 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
560 | Refresh(); | |
561 | ||
1e6feb95 | 562 | #if wxUSE_STATUSBAR |
2bda0e17 KB |
563 | if ( m_frameStatusBar ) |
564 | { | |
565 | wxSysColourChangedEvent event2; | |
566 | event2.SetEventObject( m_frameStatusBar ); | |
02800301 | 567 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); |
2bda0e17 | 568 | } |
1e6feb95 | 569 | #endif // wxUSE_STATUSBAR |
2bda0e17 KB |
570 | |
571 | // Propagate the event to the non-top-level children | |
572 | wxWindow::OnSysColourChanged(event); | |
573 | } | |
574 | ||
a2327a9f | 575 | // Pass TRUE to show full screen, FALSE to restore. |
1e6feb95 | 576 | bool wxFrameMSW::ShowFullScreen(bool show, long style) |
a2327a9f JS |
577 | { |
578 | if (show) | |
579 | { | |
580 | if (IsFullScreen()) | |
581 | return FALSE; | |
582 | ||
583 | m_fsIsShowing = TRUE; | |
584 | m_fsStyle = style; | |
585 | ||
1e6feb95 | 586 | #if wxUSE_TOOLBAR |
f6bcfd97 | 587 | wxToolBar *theToolBar = GetToolBar(); |
a2327a9f | 588 | if (theToolBar) |
1e6feb95 | 589 | theToolBar->GetSize(NULL, &m_fsToolBarHeight); |
a2327a9f JS |
590 | |
591 | // zap the toolbar, menubar, and statusbar | |
592 | ||
593 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
594 | { | |
595 | theToolBar->SetSize(-1,0); | |
596 | theToolBar->Show(FALSE); | |
597 | } | |
1e6feb95 | 598 | #endif // wxUSE_TOOLBAR |
a2327a9f | 599 | |
04ef50df | 600 | #ifndef __WXMICROWIN__ |
a2327a9f JS |
601 | if (style & wxFULLSCREEN_NOMENUBAR) |
602 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
04ef50df | 603 | #endif |
a2327a9f | 604 | |
1e6feb95 VZ |
605 | #if wxUSE_STATUSBAR |
606 | wxStatusBar *theStatusBar = GetStatusBar(); | |
607 | if (theStatusBar) | |
608 | theStatusBar->GetSize(NULL, &m_fsStatusBarHeight); | |
609 | ||
a2327a9f JS |
610 | // Save the number of fields in the statusbar |
611 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
612 | { | |
579b10c2 JS |
613 | //m_fsStatusBarFields = theStatusBar->GetFieldsCount(); |
614 | //SetStatusBar((wxStatusBar*) NULL); | |
615 | //delete theStatusBar; | |
616 | theStatusBar->Show(FALSE); | |
a2327a9f JS |
617 | } |
618 | else | |
619 | m_fsStatusBarFields = 0; | |
1e6feb95 | 620 | #endif // wxUSE_STATUSBAR |
a2327a9f JS |
621 | |
622 | // zap the frame borders | |
623 | ||
624 | // save the 'normal' window style | |
625 | m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE); | |
626 | ||
f6bcfd97 | 627 | // save the old position, width & height, maximize state |
a2327a9f | 628 | m_fsOldSize = GetRect(); |
f6bcfd97 | 629 | m_fsIsMaximized = IsMaximized(); |
a2327a9f | 630 | |
f6bcfd97 | 631 | // decide which window style flags to turn off |
a2327a9f JS |
632 | LONG newStyle = m_fsOldWindowStyle; |
633 | LONG offFlags = 0; | |
634 | ||
635 | if (style & wxFULLSCREEN_NOBORDER) | |
636 | offFlags |= WS_BORDER; | |
637 | if (style & wxFULLSCREEN_NOCAPTION) | |
638 | offFlags |= (WS_CAPTION | WS_SYSMENU); | |
639 | ||
640 | newStyle &= (~offFlags); | |
641 | ||
642 | // change our window style to be compatible with full-screen mode | |
643 | SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle); | |
644 | ||
645 | // resize to the size of the desktop | |
646 | int width, height; | |
647 | ||
648 | RECT rect; | |
649 | ::GetWindowRect(GetDesktopWindow(), &rect); | |
650 | width = rect.right - rect.left; | |
651 | height = rect.bottom - rect.top; | |
652 | ||
653 | SetSize(width, height); | |
654 | ||
655 | // now flush the window style cache and actually go full-screen | |
656 | SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED); | |
657 | ||
658 | wxSizeEvent event(wxSize(width, height), GetId()); | |
659 | GetEventHandler()->ProcessEvent(event); | |
660 | ||
661 | return TRUE; | |
662 | } | |
663 | else | |
664 | { | |
665 | if (!IsFullScreen()) | |
666 | return FALSE; | |
667 | ||
668 | m_fsIsShowing = FALSE; | |
669 | ||
1e6feb95 | 670 | #if wxUSE_TOOLBAR |
a2327a9f JS |
671 | wxToolBar *theToolBar = GetToolBar(); |
672 | ||
673 | // restore the toolbar, menubar, and statusbar | |
674 | if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
675 | { | |
676 | theToolBar->SetSize(-1, m_fsToolBarHeight); | |
677 | theToolBar->Show(TRUE); | |
678 | } | |
1e6feb95 | 679 | #endif // wxUSE_TOOLBAR |
a2327a9f | 680 | |
1e6feb95 VZ |
681 | #if wxUSE_STATUSBAR |
682 | if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR ) | |
a2327a9f | 683 | { |
579b10c2 JS |
684 | //CreateStatusBar(m_fsStatusBarFields); |
685 | if (GetStatusBar()) | |
686 | { | |
687 | GetStatusBar()->Show(TRUE); | |
688 | PositionStatusBar(); | |
689 | } | |
a2327a9f | 690 | } |
1e6feb95 | 691 | #endif // wxUSE_STATUSBAR |
a2327a9f | 692 | |
04ef50df | 693 | #ifndef __WXMICROWIN__ |
a2327a9f JS |
694 | if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) |
695 | SetMenu((HWND)GetHWND(), (HMENU)m_hMenu); | |
04ef50df | 696 | #endif |
a2327a9f JS |
697 | |
698 | Maximize(m_fsIsMaximized); | |
699 | SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle); | |
700 | SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y, | |
701 | m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED); | |
702 | ||
703 | return TRUE; | |
704 | } | |
705 | } | |
706 | ||
2bda0e17 KB |
707 | /* |
708 | * Frame window | |
709 | * | |
710 | */ | |
711 | ||
1e6feb95 | 712 | bool wxFrameMSW::MSWCreate(int id, wxWindow *parent, const wxChar *wclass, wxWindow *wx_win, const wxChar *title, |
debe6624 | 713 | int x, int y, int width, int height, long style) |
2bda0e17 KB |
714 | |
715 | { | |
716 | m_defaultIcon = (WXHICON) (wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON : wxDEFAULT_FRAME_ICON); | |
717 | ||
718 | // If child windows aren't properly drawn initially, WS_CLIPCHILDREN | |
719 | // could be the culprit. But without it, you can get a lot of flicker. | |
720 | ||
2bda0e17 | 721 | DWORD msflags = 0; |
3ca6a5f0 BP |
722 | if ( style & wxCAPTION ) |
723 | { | |
724 | if ( style & wxFRAME_TOOL_WINDOW ) | |
725 | msflags |= WS_POPUPWINDOW; | |
726 | else | |
727 | msflags |= WS_OVERLAPPED; | |
728 | } | |
2bda0e17 | 729 | else |
3ca6a5f0 BP |
730 | { |
731 | msflags |= WS_POPUP; | |
732 | } | |
2bda0e17 KB |
733 | |
734 | if (style & wxMINIMIZE_BOX) | |
735 | msflags |= WS_MINIMIZEBOX; | |
736 | if (style & wxMAXIMIZE_BOX) | |
737 | msflags |= WS_MAXIMIZEBOX; | |
738 | if (style & wxTHICK_FRAME) | |
739 | msflags |= WS_THICKFRAME; | |
740 | if (style & wxSYSTEM_MENU) | |
741 | msflags |= WS_SYSMENU; | |
f6bcfd97 | 742 | if ( style & wxMINIMIZE ) |
2bda0e17 KB |
743 | msflags |= WS_MINIMIZE; |
744 | if (style & wxMAXIMIZE) | |
745 | msflags |= WS_MAXIMIZE; | |
746 | if (style & wxCAPTION) | |
747 | msflags |= WS_CAPTION; | |
1c089c47 JS |
748 | if (style & wxCLIP_CHILDREN) |
749 | msflags |= WS_CLIPCHILDREN; | |
2bda0e17 | 750 | |
1e6feb95 | 751 | // Keep this in wxFrameMSW because it saves recoding this function |
2bda0e17 | 752 | // in wxTinyFrame |
8355a72f | 753 | #if wxUSE_ITSY_BITSY && !defined(__WIN32__) |
2bda0e17 KB |
754 | if (style & wxTINY_CAPTION_VERT) |
755 | msflags |= IBS_VERTCAPTION; | |
756 | if (style & wxTINY_CAPTION_HORIZ) | |
757 | msflags |= IBS_HORZCAPTION; | |
758 | #else | |
759 | if (style & wxTINY_CAPTION_VERT) | |
760 | msflags |= WS_CAPTION; | |
761 | if (style & wxTINY_CAPTION_HORIZ) | |
762 | msflags |= WS_CAPTION; | |
763 | #endif | |
764 | if ((style & wxTHICK_FRAME) == 0) | |
765 | msflags |= WS_BORDER; | |
766 | ||
767 | WXDWORD extendedStyle = MakeExtendedStyle(style); | |
768 | ||
b0a6bb75 | 769 | // make all frames appear in the win9x shell taskbar unless |
b3daa5a3 | 770 | // wxFRAME_TOOL_WINDOW or wxFRAME_NO_TASKBAR is given - without giving them |
b0a6bb75 | 771 | // WS_EX_APPWINDOW style, the child (i.e. owned) frames wouldn't appear in it |
2432b92d | 772 | #if !defined(__WIN16__) && !defined(__SC__) |
4b9fc37a GT |
773 | if ( (style & wxFRAME_TOOL_WINDOW) || |
774 | (style & wxFRAME_NO_TASKBAR) ) | |
b0a6bb75 | 775 | extendedStyle |= WS_EX_TOOLWINDOW; |
b3daa5a3 | 776 | else if ( !(style & wxFRAME_NO_TASKBAR) ) |
b0a6bb75 | 777 | extendedStyle |= WS_EX_APPWINDOW; |
1e6d9499 | 778 | #endif |
cd2df130 | 779 | |
2bda0e17 KB |
780 | if (style & wxSTAY_ON_TOP) |
781 | extendedStyle |= WS_EX_TOPMOST; | |
782 | ||
4204da65 | 783 | #ifndef __WIN16__ |
b96340e6 JS |
784 | if (m_exStyle & wxFRAME_EX_CONTEXTHELP) |
785 | extendedStyle |= WS_EX_CONTEXTHELP; | |
4204da65 | 786 | #endif |
b96340e6 | 787 | |
2bda0e17 | 788 | m_iconized = FALSE; |
a23fd0e1 VZ |
789 | if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height, |
790 | msflags, NULL, extendedStyle) ) | |
791 | return FALSE; | |
792 | ||
2bda0e17 KB |
793 | // Seems to be necessary if we use WS_POPUP |
794 | // style instead of WS_OVERLAPPED | |
795 | if (width > -1 && height > -1) | |
42e69d6b | 796 | ::PostMessage(GetHwnd(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height)); |
a23fd0e1 VZ |
797 | |
798 | return TRUE; | |
2bda0e17 KB |
799 | } |
800 | ||
2bda0e17 KB |
801 | // Default activation behaviour - set the focus for the first child |
802 | // subwindow found. | |
1e6feb95 | 803 | void wxFrameMSW::OnActivate(wxActivateEvent& event) |
2bda0e17 | 804 | { |
f6bcfd97 | 805 | if ( event.GetActive() ) |
00c4e897 | 806 | { |
f6bcfd97 | 807 | // restore focus to the child which was last focused |
1e6feb95 | 808 | wxLogTrace(_T("focus"), _T("wxFrameMSW %08x activated."), m_hWnd); |
00c4e897 | 809 | |
e9456d8d VZ |
810 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() |
811 | : NULL; | |
812 | if ( !parent ) | |
813 | { | |
814 | parent = this; | |
815 | } | |
816 | ||
817 | wxSetFocusToChild(parent, &m_winLastFocused); | |
00c4e897 | 818 | } |
e9456d8d | 819 | else // deactivating |
2bda0e17 | 820 | { |
e9456d8d | 821 | // remember the last focused child if it is our child |
f6bcfd97 | 822 | m_winLastFocused = FindFocus(); |
e9456d8d VZ |
823 | |
824 | // so we NULL it out if it's a child from some other frame | |
825 | wxWindow *win = m_winLastFocused; | |
826 | while ( win ) | |
319fefa9 | 827 | { |
e9456d8d VZ |
828 | if ( win->IsTopLevel() ) |
829 | { | |
830 | if ( win != this ) | |
831 | { | |
832 | m_winLastFocused = NULL; | |
833 | } | |
834 | ||
f6bcfd97 | 835 | break; |
e9456d8d | 836 | } |
f6bcfd97 | 837 | |
e9456d8d | 838 | win = win->GetParent(); |
319fefa9 | 839 | } |
f6bcfd97 BP |
840 | |
841 | wxLogTrace(_T("focus"), | |
1e6feb95 | 842 | _T("wxFrameMSW %08x deactivated, last focused: %08x."), |
f6bcfd97 BP |
843 | m_hWnd, |
844 | m_winLastFocused ? GetHwndOf(m_winLastFocused) | |
845 | : NULL); | |
846 | ||
847 | event.Skip(); | |
2bda0e17 | 848 | } |
2bda0e17 KB |
849 | } |
850 | ||
7c0ea335 VZ |
851 | // ---------------------------------------------------------------------------- |
852 | // tool/status bar stuff | |
853 | // ---------------------------------------------------------------------------- | |
854 | ||
d427503c | 855 | #if wxUSE_TOOLBAR |
7c0ea335 | 856 | |
1e6feb95 | 857 | wxToolBar* wxFrameMSW::CreateToolBar(long style, wxWindowID id, const wxString& name) |
81d66cf3 | 858 | { |
7c0ea335 | 859 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
81d66cf3 | 860 | { |
81d66cf3 | 861 | PositionToolBar(); |
81d66cf3 | 862 | } |
81d66cf3 | 863 | |
7c0ea335 | 864 | return m_frameToolBar; |
81d66cf3 JS |
865 | } |
866 | ||
1e6feb95 | 867 | void wxFrameMSW::PositionToolBar() |
81d66cf3 | 868 | { |
81d66cf3 | 869 | RECT rect; |
42e69d6b | 870 | ::GetClientRect(GetHwnd(), &rect); |
81d66cf3 | 871 | |
7c0ea335 | 872 | #if wxUSE_STATUSBAR |
81d66cf3 JS |
873 | if ( GetStatusBar() ) |
874 | { | |
7c0ea335 VZ |
875 | int statusX, statusY; |
876 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
877 | rect.bottom -= statusY; | |
81d66cf3 | 878 | } |
7c0ea335 | 879 | #endif // wxUSE_STATUSBAR |
81d66cf3 | 880 | |
a2327a9f | 881 | if ( GetToolBar() && GetToolBar()->IsShown() ) |
81d66cf3 JS |
882 | { |
883 | int tw, th; | |
7c0ea335 | 884 | GetToolBar()->GetSize(&tw, &th); |
81d66cf3 | 885 | |
7c0ea335 | 886 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) |
81d66cf3 | 887 | { |
7c0ea335 | 888 | th = rect.bottom; |
81d66cf3 JS |
889 | } |
890 | else | |
891 | { | |
7c0ea335 | 892 | tw = rect.right; |
81d66cf3 | 893 | } |
7c0ea335 VZ |
894 | |
895 | // Use the 'real' MSW position here | |
896 | GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); | |
81d66cf3 JS |
897 | } |
898 | } | |
d427503c | 899 | #endif // wxUSE_TOOLBAR |
d2aef312 | 900 | |
7c0ea335 VZ |
901 | // ---------------------------------------------------------------------------- |
902 | // frame state (iconized/maximized/...) | |
903 | // ---------------------------------------------------------------------------- | |
904 | ||
a23fd0e1 VZ |
905 | // propagate our state change to all child frames: this allows us to emulate X |
906 | // Windows behaviour where child frames float independently of the parent one | |
907 | // on the desktop, but are iconized/restored with it | |
1e6feb95 | 908 | void wxFrameMSW::IconizeChildFrames(bool bIconize) |
d2aef312 | 909 | { |
a23fd0e1 VZ |
910 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
911 | node; | |
912 | node = node->GetNext() ) | |
913 | { | |
914 | wxWindow *win = node->GetData(); | |
915 | ||
3ca6a5f0 BP |
916 | // iconizing the frames with this style under Win95 shell puts them at |
917 | // the bottom of the screen (as the MDI children) instead of making | |
918 | // them appear in the taskbar because they are, by virtue of this | |
919 | // style, not managed by the taskbar - instead leave Windows take care | |
920 | // of them | |
921 | #ifdef __WIN95__ | |
922 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) | |
923 | continue; | |
924 | #endif // Win95 | |
925 | ||
3f7bc32b VZ |
926 | // the child MDI frames are a special case and should not be touched by |
927 | // the parent frame - instead, they are managed by the user | |
1e6feb95 VZ |
928 | wxFrameMSW *frame = wxDynamicCast(win, wxFrameMSW); |
929 | if ( frame | |
930 | #if wxUSE_MDI_ARCHITECTURE | |
931 | && !wxDynamicCast(frame, wxMDIChildFrame) | |
932 | #endif // wxUSE_MDI_ARCHITECTURE | |
933 | ) | |
a23fd0e1 | 934 | { |
3f7bc32b | 935 | frame->Iconize(bIconize); |
a23fd0e1 | 936 | } |
d2aef312 | 937 | } |
d2aef312 VZ |
938 | } |
939 | ||
a23fd0e1 | 940 | // =========================================================================== |
42e69d6b | 941 | // message processing |
a23fd0e1 VZ |
942 | // =========================================================================== |
943 | ||
42e69d6b VZ |
944 | // --------------------------------------------------------------------------- |
945 | // preprocessing | |
946 | // --------------------------------------------------------------------------- | |
947 | ||
1e6feb95 | 948 | bool wxFrameMSW::MSWTranslateMessage(WXMSG* pMsg) |
42e69d6b VZ |
949 | { |
950 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
951 | return TRUE; | |
952 | ||
1e6feb95 | 953 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) |
42e69d6b VZ |
954 | // try the menu bar accels |
955 | wxMenuBar *menuBar = GetMenuBar(); | |
956 | if ( !menuBar ) | |
957 | return FALSE; | |
958 | ||
959 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
c50f1fb9 | 960 | return acceleratorTable.Translate(this, pMsg); |
1e6feb95 VZ |
961 | #else |
962 | return FALSE; | |
963 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
42e69d6b VZ |
964 | } |
965 | ||
966 | // --------------------------------------------------------------------------- | |
967 | // our private (non virtual) message handlers | |
968 | // --------------------------------------------------------------------------- | |
969 | ||
1e6feb95 | 970 | bool wxFrameMSW::HandlePaint() |
42e69d6b VZ |
971 | { |
972 | RECT rect; | |
973 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
974 | { | |
04ef50df | 975 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
976 | if ( m_iconized ) |
977 | { | |
c50f1fb9 | 978 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
42e69d6b VZ |
979 | : (HICON)m_defaultIcon; |
980 | ||
981 | // Hold a pointer to the dc so long as the OnPaint() message | |
982 | // is being processed | |
983 | PAINTSTRUCT ps; | |
984 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
985 | ||
986 | // Erase background before painting or we get white background | |
987 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
988 | ||
989 | if ( hIcon ) | |
990 | { | |
991 | RECT rect; | |
992 | ::GetClientRect(GetHwnd(), &rect); | |
993 | ||
994 | // FIXME: why hardcoded? | |
995 | static const int icon_width = 32; | |
996 | static const int icon_height = 32; | |
997 | ||
998 | int icon_x = (int)((rect.right - icon_width)/2); | |
999 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
1000 | ||
1001 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
1002 | } | |
1003 | ||
1004 | ::EndPaint(GetHwnd(), &ps); | |
1005 | ||
1006 | return TRUE; | |
1007 | } | |
1008 | else | |
04ef50df | 1009 | #endif |
42e69d6b | 1010 | { |
5d1d2d46 | 1011 | return wxWindow::HandlePaint(); |
42e69d6b VZ |
1012 | } |
1013 | } | |
1014 | else | |
1015 | { | |
1016 | // nothing to paint - processed | |
1017 | return TRUE; | |
1018 | } | |
1019 | } | |
1020 | ||
1e6feb95 | 1021 | bool wxFrameMSW::HandleSize(int x, int y, WXUINT id) |
42e69d6b VZ |
1022 | { |
1023 | bool processed = FALSE; | |
04ef50df | 1024 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
1025 | |
1026 | switch ( id ) | |
1027 | { | |
1028 | case SIZENORMAL: | |
1029 | // only do it it if we were iconized before, otherwise resizing the | |
1030 | // parent frame has a curious side effect of bringing it under it's | |
1031 | // children | |
1032 | if ( !m_iconized ) | |
1033 | break; | |
1034 | ||
1035 | // restore all child frames too | |
1036 | IconizeChildFrames(FALSE); | |
1037 | ||
3dd9b88a VZ |
1038 | (void)SendIconizeEvent(FALSE); |
1039 | ||
42e69d6b VZ |
1040 | // fall through |
1041 | ||
1042 | case SIZEFULLSCREEN: | |
1043 | m_iconized = FALSE; | |
1044 | break; | |
1045 | ||
1046 | case SIZEICONIC: | |
1047 | // iconize all child frames too | |
1048 | IconizeChildFrames(TRUE); | |
1049 | ||
3dd9b88a VZ |
1050 | (void)SendIconizeEvent(); |
1051 | ||
42e69d6b VZ |
1052 | m_iconized = TRUE; |
1053 | break; | |
1054 | } | |
04ef50df | 1055 | #endif |
42e69d6b VZ |
1056 | |
1057 | if ( !m_iconized ) | |
1058 | { | |
1e6feb95 | 1059 | #if wxUSE_STATUSBAR |
42e69d6b | 1060 | PositionStatusBar(); |
1e6feb95 VZ |
1061 | #endif // wxUSE_STATUSBAR |
1062 | ||
1063 | #if wxUSE_TOOLBAR | |
42e69d6b | 1064 | PositionToolBar(); |
1e6feb95 | 1065 | #endif // wxUSE_TOOLBAR |
42e69d6b VZ |
1066 | |
1067 | wxSizeEvent event(wxSize(x, y), m_windowId); | |
1068 | event.SetEventObject( this ); | |
1069 | processed = GetEventHandler()->ProcessEvent(event); | |
1070 | } | |
1071 | ||
1072 | return processed; | |
1073 | } | |
1074 | ||
1e6feb95 | 1075 | bool wxFrameMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) |
42e69d6b VZ |
1076 | { |
1077 | if ( control ) | |
1078 | { | |
1079 | // In case it's e.g. a toolbar. | |
1080 | wxWindow *win = wxFindWinFromHandle(control); | |
1081 | if ( win ) | |
1082 | return win->MSWCommand(cmd, id); | |
1083 | } | |
1084 | ||
1085 | // handle here commands from menus and accelerators | |
1086 | if ( cmd == 0 || cmd == 1 ) | |
1087 | { | |
1e6feb95 | 1088 | #if wxUSE_MENUS_NATIVE |
42e69d6b VZ |
1089 | if ( wxCurrentPopupMenu ) |
1090 | { | |
1091 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
1092 | wxCurrentPopupMenu = NULL; | |
1093 | ||
1094 | return popupMenu->MSWCommand(cmd, id); | |
1095 | } | |
1e6feb95 | 1096 | #endif // wxUSE_MENUS_NATIVE |
42e69d6b VZ |
1097 | |
1098 | if ( ProcessCommand(id) ) | |
1099 | { | |
1100 | return TRUE; | |
1101 | } | |
1102 | } | |
1103 | ||
1104 | return FALSE; | |
1105 | } | |
1106 | ||
1e6feb95 | 1107 | bool wxFrameMSW::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) |
a23fd0e1 VZ |
1108 | { |
1109 | int item; | |
c219cecc | 1110 | if ( flags == 0xFFFF && hMenu == 0 ) |
a23fd0e1 | 1111 | { |
c219cecc | 1112 | // menu was removed from screen |
a23fd0e1 VZ |
1113 | item = -1; |
1114 | } | |
04ef50df | 1115 | #ifndef __WXMICROWIN__ |
c219cecc | 1116 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) |
a23fd0e1 VZ |
1117 | { |
1118 | item = nItem; | |
1119 | } | |
04ef50df | 1120 | #endif |
a23fd0e1 VZ |
1121 | else |
1122 | { | |
1e6feb95 | 1123 | #if wxUSE_STATUSBAR |
c219cecc | 1124 | // don't give hints for separators (doesn't make sense) nor for the |
f6bcfd97 BP |
1125 | // items opening popup menus (they don't have them anyhow) but do clear |
1126 | // the status line - otherwise, we would be left with the help message | |
1127 | // for the previous item which doesn't apply any more | |
1128 | wxStatusBar *statbar = GetStatusBar(); | |
1129 | if ( statbar ) | |
1130 | { | |
1131 | statbar->SetStatusText(wxEmptyString); | |
1132 | } | |
1e6feb95 | 1133 | #endif // wxUSE_STATUSBAR |
f6bcfd97 | 1134 | |
a23fd0e1 VZ |
1135 | return FALSE; |
1136 | } | |
1137 | ||
1138 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
1139 | event.SetEventObject( this ); | |
1140 | ||
1141 | return GetEventHandler()->ProcessEvent(event); | |
1142 | } | |
1143 | ||
1144 | // --------------------------------------------------------------------------- | |
1e6feb95 | 1145 | // the window proc for wxFrameMSW |
a23fd0e1 VZ |
1146 | // --------------------------------------------------------------------------- |
1147 | ||
1e6feb95 | 1148 | long wxFrameMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
a23fd0e1 VZ |
1149 | { |
1150 | long rc = 0; | |
1151 | bool processed = FALSE; | |
1152 | ||
1153 | switch ( message ) | |
1154 | { | |
42e69d6b VZ |
1155 | case WM_CLOSE: |
1156 | // if we can't close, tell the system that we processed the | |
1157 | // message - otherwise it would close us | |
1158 | processed = !Close(); | |
1159 | break; | |
1160 | ||
1161 | case WM_COMMAND: | |
1162 | { | |
1163 | WORD id, cmd; | |
1164 | WXHWND hwnd; | |
1165 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
1166 | &id, &hwnd, &cmd); | |
1167 | ||
1168 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
1169 | } | |
1170 | break; | |
1171 | ||
04ef50df | 1172 | #ifndef __WXMICROWIN__ |
a23fd0e1 VZ |
1173 | case WM_MENUSELECT: |
1174 | { | |
42e69d6b VZ |
1175 | WXWORD item, flags; |
1176 | WXHMENU hmenu; | |
1177 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
1178 | ||
1179 | processed = HandleMenuSelect(item, flags, hmenu); | |
a23fd0e1 VZ |
1180 | } |
1181 | break; | |
04ef50df | 1182 | #endif |
42e69d6b VZ |
1183 | |
1184 | case WM_PAINT: | |
1185 | processed = HandlePaint(); | |
1186 | break; | |
1187 | ||
04ef50df | 1188 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
1189 | case WM_QUERYDRAGICON: |
1190 | { | |
c50f1fb9 | 1191 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
42e69d6b VZ |
1192 | : (HICON)(m_defaultIcon); |
1193 | rc = (long)hIcon; | |
1194 | processed = rc != 0; | |
1195 | } | |
1196 | break; | |
04ef50df | 1197 | #endif |
42e69d6b VZ |
1198 | |
1199 | case WM_SIZE: | |
1200 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
1201 | break; | |
a23fd0e1 VZ |
1202 | } |
1203 | ||
1204 | if ( !processed ) | |
1205 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
1206 | ||
1207 | return rc; | |
1208 | } | |
21802234 | 1209 |