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