]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
a967ef9d VZ |
2 | // Name: src/msw/mdi.cpp |
3 | // Purpose: MDI classes for wxMSW | |
2bda0e17 | 4 | // Author: Julian Smart |
6125428d | 5 | // Modified by: Vadim Zeitlin on 2008-11-04 to use the base classes |
2bda0e17 KB |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
6125428d VZ |
8 | // Copyright: (c) 1998 Julian Smart |
9 | // (c) 2008-2009 Vadim Zeitlin | |
65571936 | 10 | // Licence: wxWindows licence |
2bda0e17 KB |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
a23fd0e1 VZ |
13 | // =========================================================================== |
14 | // declarations | |
15 | // =========================================================================== | |
16 | ||
17 | // --------------------------------------------------------------------------- | |
18 | // headers | |
19 | // --------------------------------------------------------------------------- | |
20 | ||
2bda0e17 KB |
21 | // For compilers that support precompilation, includes "wx.h". |
22 | #include "wx/wxprec.h" | |
23 | ||
24 | #ifdef __BORLANDC__ | |
a23fd0e1 | 25 | #pragma hdrstop |
2bda0e17 KB |
26 | #endif |
27 | ||
efd17a1d | 28 | #if wxUSE_MDI && !defined(__WXUNIVERSAL__) |
b442f107 | 29 | |
59cf2e49 WS |
30 | #include "wx/mdi.h" |
31 | ||
2bda0e17 | 32 | #ifndef WX_PRECOMP |
a23fd0e1 VZ |
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" | |
3304646d | 38 | #include "wx/statusbr.h" |
a23fd0e1 | 39 | #include "wx/settings.h" |
0c589ad0 BM |
40 | #include "wx/intl.h" |
41 | #include "wx/log.h" | |
4e3e485b | 42 | #include "wx/toolbar.h" |
2bda0e17 KB |
43 | #endif |
44 | ||
e27d9a91 | 45 | #include "wx/stockitem.h" |
2bda0e17 KB |
46 | #include "wx/msw/private.h" |
47 | ||
2bda0e17 KB |
48 | #include <string.h> |
49 | ||
a23fd0e1 VZ |
50 | // --------------------------------------------------------------------------- |
51 | // global variables | |
52 | // --------------------------------------------------------------------------- | |
53 | ||
e1a6fc11 | 54 | extern wxMenu *wxCurrentPopupMenu; |
2bda0e17 | 55 | |
ac6482e0 | 56 | extern void wxRemoveHandleAssociation(wxWindow *win); |
a23fd0e1 | 57 | |
838e6ed7 VZ |
58 | namespace |
59 | { | |
60 | ||
a23fd0e1 VZ |
61 | // --------------------------------------------------------------------------- |
62 | // constants | |
63 | // --------------------------------------------------------------------------- | |
64 | ||
a23fd0e1 | 65 | // This range gives a maximum of 500 MDI children. Should be enough :-) |
838e6ed7 VZ |
66 | const int wxFIRST_MDI_CHILD = 4100; |
67 | const int wxLAST_MDI_CHILD = 4600; | |
68 | ||
69 | // The MDI "Window" menu label | |
70 | const char *WINDOW_MENU_LABEL = gettext_noop("&Window"); | |
2bda0e17 | 71 | |
42e69d6b VZ |
72 | // --------------------------------------------------------------------------- |
73 | // private functions | |
74 | // --------------------------------------------------------------------------- | |
75 | ||
76 | // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu | |
77 | // of the parent of win (which is supposed to be the MDI client window) | |
838e6ed7 | 78 | void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow); |
42e69d6b VZ |
79 | |
80 | // insert the window menu (subMenu) into menu just before "Help" submenu or at | |
81 | // the very end if not found | |
838e6ed7 | 82 | void MDIInsertWindowMenu(wxWindow *win, WXHMENU hMenu, HMENU subMenu); |
42e69d6b | 83 | |
df61c009 | 84 | // Remove the window menu |
838e6ed7 | 85 | void MDIRemoveWindowMenu(wxWindow *win, WXHMENU hMenu); |
df61c009 | 86 | |
4e152a23 | 87 | // unpack the parameters of WM_MDIACTIVATE message |
838e6ed7 VZ |
88 | void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam, |
89 | WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact); | |
42e69d6b | 90 | |
4e152a23 | 91 | // return the HMENU of the MDI menu |
ecc63060 VZ |
92 | // |
93 | // this function works correctly even when we don't have a window menu and just | |
94 | // returns 0 then | |
838e6ed7 | 95 | inline HMENU GetMDIWindowMenu(wxMDIParentFrame *frame) |
4e152a23 VZ |
96 | { |
97 | wxMenu *menu = frame->GetWindowMenu(); | |
98 | return menu ? GetHmenuOf(menu) : 0; | |
99 | } | |
100 | ||
838e6ed7 VZ |
101 | } // anonymous namespace |
102 | ||
a23fd0e1 VZ |
103 | // =========================================================================== |
104 | // implementation | |
105 | // =========================================================================== | |
106 | ||
107 | // --------------------------------------------------------------------------- | |
108 | // wxWin macros | |
109 | // --------------------------------------------------------------------------- | |
2bda0e17 | 110 | |
225fe9d6 VZ |
111 | IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame) |
112 | IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame) | |
113 | IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow) | |
2bda0e17 KB |
114 | |
115 | BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame) | |
a23fd0e1 | 116 | EVT_SIZE(wxMDIParentFrame::OnSize) |
6bbe97b7 | 117 | EVT_ICONIZE(wxMDIParentFrame::OnIconized) |
a23fd0e1 | 118 | EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged) |
1483e5db VZ |
119 | |
120 | #if wxUSE_MENUS | |
121 | EVT_MENU_RANGE(wxFIRST_MDI_CHILD, wxLAST_MDI_CHILD, | |
122 | wxMDIParentFrame::OnMDIChild) | |
123 | EVT_MENU_RANGE(wxID_MDI_WINDOW_FIRST, wxID_MDI_WINDOW_LAST, | |
124 | wxMDIParentFrame::OnMDICommand) | |
125 | #endif // wxUSE_MENUS | |
2bda0e17 KB |
126 | END_EVENT_TABLE() |
127 | ||
f6bcfd97 BP |
128 | BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame) |
129 | EVT_IDLE(wxMDIChildFrame::OnIdle) | |
130 | END_EVENT_TABLE() | |
131 | ||
2bda0e17 | 132 | BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) |
a23fd0e1 | 133 | EVT_SCROLL(wxMDIClientWindow::OnScroll) |
2bda0e17 KB |
134 | END_EVENT_TABLE() |
135 | ||
42e69d6b VZ |
136 | // =========================================================================== |
137 | // wxMDIParentFrame: the frame which contains the client window which manages | |
138 | // the children | |
139 | // =========================================================================== | |
2bda0e17 | 140 | |
2bda0e17 | 141 | bool wxMDIParentFrame::Create(wxWindow *parent, |
a23fd0e1 VZ |
142 | wxWindowID id, |
143 | const wxString& title, | |
144 | const wxPoint& pos, | |
145 | const wxSize& size, | |
146 | long style, | |
147 | const wxString& name) | |
2bda0e17 | 148 | { |
3d8dea7e VZ |
149 | // this style can be used to prevent a window from having the standard MDI |
150 | // "Window" menu | |
d2824cdb | 151 | if ( !(style & wxFRAME_NO_WINDOW_MENU) ) |
df61c009 | 152 | { |
d2824cdb | 153 | // normal case: we have the window menu, so construct it |
df61c009 JS |
154 | m_windowMenu = new wxMenu; |
155 | ||
1483e5db VZ |
156 | m_windowMenu->Append(wxID_MDI_WINDOW_CASCADE, _("&Cascade")); |
157 | m_windowMenu->Append(wxID_MDI_WINDOW_TILE_HORZ, _("Tile &Horizontally")); | |
158 | m_windowMenu->Append(wxID_MDI_WINDOW_TILE_VERT, _("Tile &Vertically")); | |
df61c009 | 159 | m_windowMenu->AppendSeparator(); |
1483e5db VZ |
160 | m_windowMenu->Append(wxID_MDI_WINDOW_ARRANGE_ICONS, _("&Arrange Icons")); |
161 | m_windowMenu->Append(wxID_MDI_WINDOW_NEXT, _("&Next")); | |
162 | m_windowMenu->Append(wxID_MDI_WINDOW_PREV, _("&Previous")); | |
df61c009 JS |
163 | } |
164 | ||
1483e5db VZ |
165 | #if wxUSE_MENUS && wxUSE_ACCEL |
166 | // the default menu doesn't have any accelerators (even if we have it) | |
167 | m_accelWindowMenu = NULL; | |
168 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
2bda0e17 KB |
169 | |
170 | if (!parent) | |
171 | wxTopLevelWindows.Append(this); | |
172 | ||
173 | SetName(name); | |
174 | m_windowStyle = style; | |
175 | ||
b225f659 VZ |
176 | if ( parent ) |
177 | parent->AddChild(this); | |
2bda0e17 | 178 | |
598ddd96 | 179 | if ( id != wxID_ANY ) |
2bda0e17 KB |
180 | m_windowId = id; |
181 | else | |
b225f659 | 182 | m_windowId = NewControlId(); |
2bda0e17 | 183 | |
912c192f VZ |
184 | WXDWORD exflags; |
185 | WXDWORD msflags = MSWGetCreateWindowFlags(&exflags); | |
ea723360 JS |
186 | msflags &= ~WS_VSCROLL; |
187 | msflags &= ~WS_HSCROLL; | |
2bda0e17 | 188 | |
d9698bd4 | 189 | if ( !wxWindow::MSWCreate(wxApp::GetRegisteredClassName(_T("wxMDIFrame")), |
e0a050e3 | 190 | title.wx_str(), |
b225f659 VZ |
191 | pos, size, |
192 | msflags, | |
193 | exflags) ) | |
3ca6a5f0 | 194 | { |
4f8090e0 | 195 | return false; |
3ca6a5f0 | 196 | } |
2bda0e17 | 197 | |
5bee6b2b VZ |
198 | SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
199 | ||
f6bcfd97 | 200 | // unlike (almost?) all other windows, frames are created hidden |
4f8090e0 | 201 | m_isShown = false; |
f6bcfd97 | 202 | |
4f8090e0 | 203 | return true; |
2bda0e17 KB |
204 | } |
205 | ||
c2dcfdef | 206 | wxMDIParentFrame::~wxMDIParentFrame() |
2bda0e17 | 207 | { |
d1e44484 | 208 | // see comment in ~wxMDIChildFrame |
1904aa72 | 209 | #if wxUSE_TOOLBAR |
f048e32f | 210 | m_frameToolBar = NULL; |
1904aa72 | 211 | #endif |
67a99992 | 212 | #if wxUSE_STATUSBAR |
c0bcc480 | 213 | m_frameStatusBar = NULL; |
67a99992 | 214 | #endif // wxUSE_STATUSBAR |
f048e32f | 215 | |
1483e5db VZ |
216 | #if wxUSE_MENUS && wxUSE_ACCEL |
217 | delete m_accelWindowMenu; | |
218 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
219 | ||
d1e44484 VZ |
220 | DestroyChildren(); |
221 | ||
4e152a23 VZ |
222 | // the MDI frame menubar is not automatically deleted by Windows unlike for |
223 | // the normal frames | |
224 | if ( m_hMenu ) | |
4e152a23 | 225 | ::DestroyMenu((HMENU)m_hMenu); |
4e152a23 | 226 | |
42e69d6b VZ |
227 | if ( m_clientWindow ) |
228 | { | |
229 | if ( m_clientWindow->MSWGetOldWndProc() ) | |
230 | m_clientWindow->UnsubclassWin(); | |
2bda0e17 | 231 | |
42e69d6b VZ |
232 | m_clientWindow->SetHWND(0); |
233 | delete m_clientWindow; | |
234 | } | |
2bda0e17 KB |
235 | } |
236 | ||
ecc63060 VZ |
237 | // ---------------------------------------------------------------------------- |
238 | // wxMDIParentFrame child management | |
239 | // ---------------------------------------------------------------------------- | |
240 | ||
51181d29 VZ |
241 | wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const |
242 | { | |
243 | HWND hWnd = (HWND)::SendMessage(GetWinHwnd(GetClientWindow()), | |
244 | WM_MDIGETACTIVE, 0, 0L); | |
1483e5db | 245 | if ( !hWnd ) |
51181d29 VZ |
246 | return NULL; |
247 | ||
1483e5db | 248 | return static_cast<wxMDIChildFrame *>(wxFindWinFromHandle(hWnd)); |
51181d29 VZ |
249 | } |
250 | ||
ecc63060 VZ |
251 | int wxMDIParentFrame::GetChildFramesCount() const |
252 | { | |
253 | int count = 0; | |
254 | for ( wxWindowList::const_iterator i = GetChildren().begin(); | |
255 | i != GetChildren().end(); | |
256 | ++i ) | |
257 | { | |
258 | if ( wxDynamicCast(*i, wxMDIChildFrame) ) | |
259 | count++; | |
260 | } | |
261 | ||
262 | return count; | |
263 | } | |
264 | ||
7e6d6840 VZ |
265 | #if wxUSE_MENUS |
266 | ||
ecc63060 VZ |
267 | void wxMDIParentFrame::AddMDIChild(wxMDIChildFrame * WXUNUSED(child)) |
268 | { | |
6125428d | 269 | switch ( GetChildFramesCount() ) |
ecc63060 | 270 | { |
6125428d VZ |
271 | case 1: |
272 | // first MDI child was just added, we need to insert the window | |
273 | // menu now if we have it | |
274 | AddWindowMenu(); | |
275 | ||
276 | // and disable the items which can't be used until we have more | |
277 | // than one child | |
278 | UpdateWindowMenu(false); | |
279 | break; | |
280 | ||
281 | case 2: | |
282 | // second MDI child was added, enable the menu items which were | |
283 | // disabled because they didn't make sense for a single window | |
284 | UpdateWindowMenu(true); | |
285 | break; | |
ecc63060 VZ |
286 | } |
287 | } | |
288 | ||
289 | void wxMDIParentFrame::RemoveMDIChild(wxMDIChildFrame * WXUNUSED(child)) | |
290 | { | |
6125428d | 291 | switch ( GetChildFramesCount() ) |
ecc63060 | 292 | { |
6125428d VZ |
293 | case 1: |
294 | // last MDI child is being removed, remove the now unnecessary | |
295 | // window menu too | |
296 | RemoveWindowMenu(); | |
297 | ||
298 | // there is no need to call UpdateWindowMenu(true) here so this is | |
299 | // not quite symmetric to AddMDIChild() above | |
300 | break; | |
301 | ||
302 | case 2: | |
303 | // only one MDI child is going to remain, disable the menu commands | |
304 | // which don't make sense for a single child window | |
305 | UpdateWindowMenu(false); | |
306 | break; | |
ecc63060 VZ |
307 | } |
308 | } | |
309 | ||
310 | // ---------------------------------------------------------------------------- | |
311 | // wxMDIParentFrame window menu handling | |
312 | // ---------------------------------------------------------------------------- | |
313 | ||
314 | void wxMDIParentFrame::AddWindowMenu() | |
315 | { | |
316 | if ( m_windowMenu ) | |
317 | MDIInsertWindowMenu(GetClientWindow(), m_hMenu, GetMDIWindowMenu(this)); | |
318 | } | |
319 | ||
320 | void wxMDIParentFrame::RemoveWindowMenu() | |
321 | { | |
322 | if ( m_windowMenu ) | |
323 | MDIRemoveWindowMenu(GetClientWindow(), m_hMenu); | |
324 | } | |
325 | ||
6125428d VZ |
326 | void wxMDIParentFrame::UpdateWindowMenu(bool enable) |
327 | { | |
328 | if ( m_windowMenu ) | |
329 | { | |
1483e5db VZ |
330 | m_windowMenu->Enable(wxID_MDI_WINDOW_NEXT, enable); |
331 | m_windowMenu->Enable(wxID_MDI_WINDOW_PREV, enable); | |
6125428d VZ |
332 | } |
333 | } | |
334 | ||
1e6feb95 VZ |
335 | #if wxUSE_MENUS_NATIVE |
336 | ||
42e69d6b | 337 | void wxMDIParentFrame::InternalSetMenuBar() |
2bda0e17 | 338 | { |
ecc63060 VZ |
339 | if ( GetActiveChild() ) |
340 | { | |
341 | AddWindowMenu(); | |
342 | } | |
343 | else // we don't have any MDI children yet | |
344 | { | |
345 | // wait until we do to add the window menu but do set the main menu for | |
346 | // now (this is done by AddWindowMenu() as a side effect) | |
347 | MDISetMenu(GetClientWindow(), (HMENU)m_hMenu, NULL); | |
348 | } | |
2bda0e17 KB |
349 | } |
350 | ||
1e6feb95 VZ |
351 | #endif // wxUSE_MENUS_NATIVE |
352 | ||
df61c009 JS |
353 | void wxMDIParentFrame::SetWindowMenu(wxMenu* menu) |
354 | { | |
1483e5db VZ |
355 | if ( menu != m_windowMenu ) |
356 | { | |
357 | // notice that Remove/AddWindowMenu() are safe to call even when | |
358 | // m_windowMenu is NULL | |
359 | RemoveWindowMenu(); | |
360 | ||
361 | delete m_windowMenu; | |
362 | ||
363 | m_windowMenu = menu; | |
df61c009 | 364 | |
1483e5db VZ |
365 | AddWindowMenu(); |
366 | } | |
4e152a23 | 367 | |
1483e5db VZ |
368 | #if wxUSE_ACCEL |
369 | delete m_accelWindowMenu; | |
370 | m_accelWindowMenu = NULL; | |
ecc63060 | 371 | |
1483e5db VZ |
372 | if ( menu && menu->HasAccels() ) |
373 | m_accelWindowMenu = menu->CreateAccelTable(); | |
374 | #endif // wxUSE_ACCEL | |
df61c009 JS |
375 | } |
376 | ||
51181d29 VZ |
377 | // ---------------------------------------------------------------------------- |
378 | // wxMDIParentFrame other menu-related stuff | |
379 | // ---------------------------------------------------------------------------- | |
380 | ||
6aca4628 CE |
381 | void wxMDIParentFrame::DoMenuUpdates(wxMenu* menu) |
382 | { | |
383 | wxMDIChildFrame *child = GetActiveChild(); | |
384 | if ( child ) | |
385 | { | |
386 | wxEvtHandler* source = child->GetEventHandler(); | |
387 | wxMenuBar* bar = child->GetMenuBar(); | |
388 | ||
389 | if (menu) | |
390 | { | |
391 | menu->UpdateUI(source); | |
392 | } | |
393 | else | |
394 | { | |
395 | if ( bar != NULL ) | |
396 | { | |
397 | int nCount = bar->GetMenuCount(); | |
398 | for (int n = 0; n < nCount; n++) | |
92218ce6 | 399 | bar->GetMenu(n)->UpdateUI(source); |
6aca4628 CE |
400 | } |
401 | } | |
402 | } | |
403 | else | |
404 | { | |
405 | wxFrameBase::DoMenuUpdates(menu); | |
406 | } | |
407 | } | |
408 | ||
79f9ea05 | 409 | wxMenuItem *wxMDIParentFrame::FindItemInMenuBar(int menuId) const |
10816efb | 410 | { |
79f9ea05 | 411 | wxMenuItem *item = wxFrame::FindItemInMenuBar(menuId); |
1483e5db | 412 | if ( !item && GetActiveChild() ) |
10816efb | 413 | { |
1483e5db | 414 | item = GetActiveChild()->FindItemInMenuBar(menuId); |
10816efb VZ |
415 | } |
416 | ||
79f9ea05 VZ |
417 | if ( !item && m_windowMenu ) |
418 | item = m_windowMenu->FindItem(menuId); | |
419 | ||
10816efb VZ |
420 | return item; |
421 | } | |
422 | ||
51181d29 VZ |
423 | WXHMENU wxMDIParentFrame::MSWGetActiveMenu() const |
424 | { | |
425 | wxMDIChildFrame * const child = GetActiveChild(); | |
426 | if ( child ) | |
427 | { | |
428 | const WXHMENU hmenu = child->MSWGetActiveMenu(); | |
429 | if ( hmenu ) | |
430 | return hmenu; | |
431 | } | |
432 | ||
433 | return wxFrame::MSWGetActiveMenu(); | |
434 | } | |
435 | ||
436 | #endif // wxUSE_MENUS | |
437 | ||
438 | // ---------------------------------------------------------------------------- | |
439 | // wxMDIParentFrame event handling | |
440 | // ---------------------------------------------------------------------------- | |
441 | ||
6bbe97b7 | 442 | void wxMDIParentFrame::UpdateClientSize() |
2bda0e17 | 443 | { |
2bda0e17 | 444 | if ( GetClientWindow() ) |
42e69d6b VZ |
445 | { |
446 | int width, height; | |
447 | GetClientSize(&width, &height); | |
2bda0e17 | 448 | |
42e69d6b VZ |
449 | GetClientWindow()->SetSize(0, 0, width, height); |
450 | } | |
2bda0e17 KB |
451 | } |
452 | ||
6bbe97b7 VZ |
453 | void wxMDIParentFrame::OnSize(wxSizeEvent& WXUNUSED(event)) |
454 | { | |
455 | UpdateClientSize(); | |
456 | ||
457 | // do not call event.Skip() here, it somehow messes up MDI client window | |
458 | } | |
459 | ||
460 | void wxMDIParentFrame::OnIconized(wxIconizeEvent& event) | |
461 | { | |
462 | event.Skip(); | |
463 | ||
6ad7799c | 464 | if ( !event.IsIconized() ) |
6bbe97b7 | 465 | UpdateClientSize(); |
6bbe97b7 VZ |
466 | } |
467 | ||
2bda0e17 KB |
468 | // Responds to colour changes, and passes event on to children. |
469 | void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
470 | { | |
471 | if ( m_clientWindow ) | |
472 | { | |
a756f210 | 473 | m_clientWindow->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
2bda0e17 KB |
474 | m_clientWindow->Refresh(); |
475 | } | |
2bda0e17 | 476 | |
42e69d6b | 477 | event.Skip(); |
2bda0e17 KB |
478 | } |
479 | ||
82c9f85c VZ |
480 | WXHICON wxMDIParentFrame::GetDefaultIcon() const |
481 | { | |
94826170 VZ |
482 | // we don't have any standard icons (any more) |
483 | return (WXHICON)0; | |
82c9f85c VZ |
484 | } |
485 | ||
42e69d6b | 486 | // --------------------------------------------------------------------------- |
2bda0e17 | 487 | // MDI operations |
42e69d6b VZ |
488 | // --------------------------------------------------------------------------- |
489 | ||
c2dcfdef | 490 | void wxMDIParentFrame::Cascade() |
2bda0e17 | 491 | { |
a23fd0e1 | 492 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE, 0, 0); |
2bda0e17 KB |
493 | } |
494 | ||
0d97c090 | 495 | void wxMDIParentFrame::Tile(wxOrientation orient) |
2bda0e17 | 496 | { |
0d97c090 VZ |
497 | wxASSERT_MSG( orient == wxHORIZONTAL || orient == wxVERTICAL, |
498 | _T("invalid orientation value") ); | |
499 | ||
500 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE, | |
501 | orient == wxHORIZONTAL ? MDITILE_HORIZONTAL | |
502 | : MDITILE_VERTICAL, 0); | |
2bda0e17 KB |
503 | } |
504 | ||
c2dcfdef | 505 | void wxMDIParentFrame::ArrangeIcons() |
2bda0e17 | 506 | { |
a23fd0e1 | 507 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE, 0, 0); |
2bda0e17 KB |
508 | } |
509 | ||
c2dcfdef | 510 | void wxMDIParentFrame::ActivateNext() |
2bda0e17 | 511 | { |
a23fd0e1 | 512 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 0); |
2bda0e17 KB |
513 | } |
514 | ||
c2dcfdef | 515 | void wxMDIParentFrame::ActivatePrevious() |
2bda0e17 | 516 | { |
a23fd0e1 | 517 | ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 1); |
2bda0e17 KB |
518 | } |
519 | ||
42e69d6b | 520 | // --------------------------------------------------------------------------- |
a23fd0e1 | 521 | // the MDI parent frame window proc |
42e69d6b VZ |
522 | // --------------------------------------------------------------------------- |
523 | ||
c140b7e7 | 524 | WXLRESULT wxMDIParentFrame::MSWWindowProc(WXUINT message, |
a23fd0e1 VZ |
525 | WXWPARAM wParam, |
526 | WXLPARAM lParam) | |
2bda0e17 | 527 | { |
c140b7e7 | 528 | WXLRESULT rc = 0; |
4f8090e0 | 529 | bool processed = false; |
2bda0e17 | 530 | |
a23fd0e1 VZ |
531 | switch ( message ) |
532 | { | |
42e69d6b VZ |
533 | case WM_ACTIVATE: |
534 | { | |
535 | WXWORD state, minimized; | |
536 | WXHWND hwnd; | |
537 | UnpackActivate(wParam, lParam, &state, &minimized, &hwnd); | |
538 | ||
539 | processed = HandleActivate(state, minimized != 0, hwnd); | |
540 | } | |
541 | break; | |
542 | ||
a23fd0e1 VZ |
543 | case WM_CREATE: |
544 | m_clientWindow = OnCreateClient(); | |
545 | // Uses own style for client style | |
546 | if ( !m_clientWindow->CreateClient(this, GetWindowStyleFlag()) ) | |
547 | { | |
548 | wxLogMessage(_("Failed to create MDI parent frame.")); | |
2bda0e17 | 549 | |
a23fd0e1 VZ |
550 | rc = -1; |
551 | } | |
2bda0e17 | 552 | |
4f8090e0 | 553 | processed = true; |
a23fd0e1 | 554 | break; |
2bda0e17 | 555 | |
a23fd0e1 | 556 | case WM_ERASEBKGND: |
4f8090e0 | 557 | processed = true; |
2bda0e17 | 558 | |
a23fd0e1 | 559 | // we erase background ourselves |
4f8090e0 | 560 | rc = true; |
a23fd0e1 VZ |
561 | break; |
562 | ||
b3818fbe | 563 | case WM_SIZE: |
31f658e4 CE |
564 | // though we don't (usually) resize the MDI client to exactly fit the |
565 | // client area we need to pass this one to DefFrameProc to allow the children to show | |
b3818fbe | 566 | break; |
a23fd0e1 | 567 | } |
2bda0e17 | 568 | |
a23fd0e1 VZ |
569 | if ( !processed ) |
570 | rc = wxFrame::MSWWindowProc(message, wParam, lParam); | |
2bda0e17 | 571 | |
a23fd0e1 | 572 | return rc; |
2bda0e17 KB |
573 | } |
574 | ||
42e69d6b | 575 | bool wxMDIParentFrame::HandleActivate(int state, bool minimized, WXHWND activate) |
2bda0e17 | 576 | { |
4f8090e0 | 577 | bool processed = false; |
a23fd0e1 | 578 | |
42e69d6b | 579 | if ( wxWindow::HandleActivate(state, minimized, activate) ) |
a23fd0e1 VZ |
580 | { |
581 | // already processed | |
4f8090e0 | 582 | processed = true; |
a23fd0e1 | 583 | } |
2bda0e17 KB |
584 | |
585 | // If this window is an MDI parent, we must also send an OnActivate message | |
586 | // to the current child. | |
1483e5db | 587 | if ( GetActiveChild() && |
a23fd0e1 | 588 | ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) ) |
c2dcfdef | 589 | { |
1483e5db VZ |
590 | wxActivateEvent event(wxEVT_ACTIVATE, true, GetActiveChild()->GetId()); |
591 | event.SetEventObject( GetActiveChild() ); | |
592 | if ( GetActiveChild()->HandleWindowEvent(event) ) | |
4f8090e0 | 593 | processed = true; |
2bda0e17 | 594 | } |
a23fd0e1 VZ |
595 | |
596 | return processed; | |
2bda0e17 KB |
597 | } |
598 | ||
1483e5db | 599 | #if wxUSE_MENUS |
8a0dce9c | 600 | |
1483e5db VZ |
601 | void wxMDIParentFrame::OnMDIChild(wxCommandEvent& event) |
602 | { | |
603 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
604 | while ( node ) | |
e1a6fc11 | 605 | { |
1483e5db VZ |
606 | wxWindow *child = node->GetData(); |
607 | if ( child->GetHWND() ) | |
608 | { | |
609 | int childId = wxGetWindowId(child->GetHWND()); | |
610 | if ( childId == event.GetId() ) | |
611 | { | |
612 | ::SendMessage( GetWinHwnd(GetClientWindow()), | |
613 | WM_MDIACTIVATE, | |
614 | (WPARAM)child->GetHWND(), 0); | |
615 | return; | |
616 | } | |
617 | } | |
e1a6fc11 | 618 | |
1483e5db | 619 | node = node->GetNext(); |
7dbe942a JS |
620 | } |
621 | ||
1483e5db VZ |
622 | wxFAIL_MSG( "unknown MDI child selected?" ); |
623 | } | |
624 | ||
625 | void wxMDIParentFrame::OnMDICommand(wxCommandEvent& event) | |
626 | { | |
42e69d6b | 627 | WXWPARAM wParam = 0; |
4f3b37fd | 628 | WXLPARAM lParam = 0; |
42e69d6b | 629 | int msg; |
1483e5db | 630 | switch ( event.GetId() ) |
2bda0e17 | 631 | { |
1483e5db | 632 | case wxID_MDI_WINDOW_CASCADE: |
42e69d6b VZ |
633 | msg = WM_MDICASCADE; |
634 | wParam = MDITILE_SKIPDISABLED; | |
635 | break; | |
636 | ||
1483e5db | 637 | case wxID_MDI_WINDOW_TILE_HORZ: |
42e69d6b VZ |
638 | wParam |= MDITILE_HORIZONTAL; |
639 | // fall through | |
640 | ||
1483e5db | 641 | case wxID_MDI_WINDOW_TILE_VERT: |
42e69d6b VZ |
642 | if ( !wParam ) |
643 | wParam = MDITILE_VERTICAL; | |
644 | msg = WM_MDITILE; | |
645 | wParam |= MDITILE_SKIPDISABLED; | |
646 | break; | |
647 | ||
1483e5db | 648 | case wxID_MDI_WINDOW_ARRANGE_ICONS: |
42e69d6b VZ |
649 | msg = WM_MDIICONARRANGE; |
650 | break; | |
651 | ||
1483e5db | 652 | case wxID_MDI_WINDOW_NEXT: |
42e69d6b | 653 | msg = WM_MDINEXT; |
4f3b37fd JS |
654 | lParam = 0; // next child |
655 | break; | |
656 | ||
1483e5db | 657 | case wxID_MDI_WINDOW_PREV: |
4f3b37fd JS |
658 | msg = WM_MDINEXT; |
659 | lParam = 1; // previous child | |
42e69d6b VZ |
660 | break; |
661 | ||
662 | default: | |
1483e5db VZ |
663 | wxFAIL_MSG( "unknown MDI command" ); |
664 | return; | |
2bda0e17 | 665 | } |
c2dcfdef | 666 | |
1483e5db VZ |
667 | ::SendMessage(GetWinHwnd(GetClientWindow()), msg, wParam, lParam); |
668 | } | |
42e69d6b | 669 | |
1483e5db | 670 | #endif // wxUSE_MENUS |
2bda0e17 | 671 | |
8cc208e3 | 672 | bool wxMDIParentFrame::TryBefore(wxEvent& event) |
1483e5db | 673 | { |
cd60273b VZ |
674 | // menu (and toolbar) events should be sent to the active child frame |
675 | // first, if any | |
676 | if ( event.GetEventType() == wxEVT_COMMAND_MENU_SELECTED ) | |
677 | { | |
678 | wxMDIChildFrame * const child = GetActiveChild(); | |
679 | if ( child && child->ProcessEventHere(event) ) | |
680 | return true; | |
681 | } | |
1483e5db | 682 | |
8cc208e3 | 683 | return wxMDIParentFrameBase::TryBefore(event); |
2bda0e17 KB |
684 | } |
685 | ||
c140b7e7 | 686 | WXLRESULT wxMDIParentFrame::MSWDefWindowProc(WXUINT message, |
42e69d6b VZ |
687 | WXWPARAM wParam, |
688 | WXLPARAM lParam) | |
2bda0e17 | 689 | { |
c2dcfdef VZ |
690 | WXHWND clientWnd; |
691 | if ( GetClientWindow() ) | |
692 | clientWnd = GetClientWindow()->GetHWND(); | |
693 | else | |
694 | clientWnd = 0; | |
2bda0e17 | 695 | |
a23fd0e1 | 696 | return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam); |
2bda0e17 KB |
697 | } |
698 | ||
57a7b7c1 JS |
699 | bool wxMDIParentFrame::MSWTranslateMessage(WXMSG* msg) |
700 | { | |
a23fd0e1 | 701 | MSG *pMsg = (MSG *)msg; |
2bda0e17 | 702 | |
f6bcfd97 | 703 | // first let the current child get it |
1483e5db VZ |
704 | wxMDIChildFrame * const child = GetActiveChild(); |
705 | if ( child && child->MSWTranslateMessage(msg) ) | |
a23fd0e1 | 706 | { |
4f8090e0 | 707 | return true; |
a23fd0e1 | 708 | } |
2bda0e17 | 709 | |
1483e5db VZ |
710 | // then try out accelerator table (will also check the accelerators for the |
711 | // normal menu items) | |
f6bcfd97 | 712 | if ( wxFrame::MSWTranslateMessage(msg) ) |
a23fd0e1 | 713 | { |
4f8090e0 | 714 | return true; |
a23fd0e1 | 715 | } |
2bda0e17 | 716 | |
1483e5db VZ |
717 | #if wxUSE_MENUS && wxUSE_ACCEL |
718 | // but it doesn't check for the (custom) accelerators of the window menu | |
719 | // items as it's not part of the menu bar as it's handled by Windows itself | |
720 | // so we need to do this explicitly | |
e61f95ea | 721 | if ( m_accelWindowMenu && m_accelWindowMenu->Translate(this, msg) ) |
1483e5db VZ |
722 | return true; |
723 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
724 | ||
725 | // finally, check for MDI specific built-in accelerators | |
a23fd0e1 VZ |
726 | if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN ) |
727 | { | |
728 | if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg)) | |
4f8090e0 | 729 | return true; |
a23fd0e1 | 730 | } |
57a7b7c1 | 731 | |
4f8090e0 | 732 | return false; |
2bda0e17 KB |
733 | } |
734 | ||
42e69d6b | 735 | // =========================================================================== |
a23fd0e1 | 736 | // wxMDIChildFrame |
42e69d6b | 737 | // =========================================================================== |
2bda0e17 | 738 | |
f6bcfd97 | 739 | void wxMDIChildFrame::Init() |
2bda0e17 | 740 | { |
4f8090e0 | 741 | m_needsResize = true; |
2596e9fb | 742 | m_needsInitialShow = true; |
2bda0e17 KB |
743 | } |
744 | ||
745 | bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, | |
a23fd0e1 VZ |
746 | wxWindowID id, |
747 | const wxString& title, | |
748 | const wxPoint& pos, | |
749 | const wxSize& size, | |
750 | long style, | |
751 | const wxString& name) | |
2bda0e17 | 752 | { |
d2824cdb VZ |
753 | m_mdiParent = parent; |
754 | ||
2bda0e17 KB |
755 | SetName(name); |
756 | ||
598ddd96 | 757 | if ( id != wxID_ANY ) |
2bda0e17 KB |
758 | m_windowId = id; |
759 | else | |
cf2810aa | 760 | m_windowId = NewControlId(); |
2bda0e17 | 761 | |
42e69d6b VZ |
762 | if ( parent ) |
763 | { | |
764 | parent->AddChild(this); | |
765 | } | |
2bda0e17 | 766 | |
2bda0e17 KB |
767 | int x = pos.x; |
768 | int y = pos.y; | |
769 | int width = size.x; | |
770 | int height = size.y; | |
771 | ||
772 | MDICREATESTRUCT mcs; | |
c2dcfdef | 773 | |
d9698bd4 VZ |
774 | wxString className = |
775 | wxApp::GetRegisteredClassName(_T("wxMDIChildFrame"), COLOR_WINDOW); | |
776 | if ( !(style & wxFULL_REPAINT_ON_RESIZE) ) | |
777 | className += wxApp::GetNoRedrawClassSuffix(); | |
778 | ||
779 | mcs.szClass = className.wx_str(); | |
e0a050e3 | 780 | mcs.szTitle = title.wx_str(); |
2bda0e17 | 781 | mcs.hOwner = wxGetInstance(); |
598ddd96 | 782 | if (x != wxDefaultCoord) |
42e69d6b VZ |
783 | mcs.x = x; |
784 | else | |
785 | mcs.x = CW_USEDEFAULT; | |
2bda0e17 | 786 | |
598ddd96 | 787 | if (y != wxDefaultCoord) |
42e69d6b VZ |
788 | mcs.y = y; |
789 | else | |
790 | mcs.y = CW_USEDEFAULT; | |
2bda0e17 | 791 | |
598ddd96 | 792 | if (width != wxDefaultCoord) |
42e69d6b VZ |
793 | mcs.cx = width; |
794 | else | |
795 | mcs.cx = CW_USEDEFAULT; | |
2bda0e17 | 796 | |
598ddd96 | 797 | if (height != wxDefaultCoord) |
42e69d6b VZ |
798 | mcs.cy = height; |
799 | else | |
800 | mcs.cy = CW_USEDEFAULT; | |
2bda0e17 | 801 | |
2596e9fb | 802 | DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN; |
2bda0e17 KB |
803 | if (style & wxMINIMIZE_BOX) |
804 | msflags |= WS_MINIMIZEBOX; | |
805 | if (style & wxMAXIMIZE_BOX) | |
806 | msflags |= WS_MAXIMIZEBOX; | |
1c067fe3 | 807 | if (style & wxRESIZE_BORDER) |
2bda0e17 KB |
808 | msflags |= WS_THICKFRAME; |
809 | if (style & wxSYSTEM_MENU) | |
810 | msflags |= WS_SYSMENU; | |
811 | if ((style & wxMINIMIZE) || (style & wxICONIZE)) | |
812 | msflags |= WS_MINIMIZE; | |
813 | if (style & wxMAXIMIZE) | |
814 | msflags |= WS_MAXIMIZE; | |
815 | if (style & wxCAPTION) | |
816 | msflags |= WS_CAPTION; | |
817 | ||
818 | mcs.style = msflags; | |
819 | ||
820 | mcs.lParam = 0; | |
821 | ||
b225f659 VZ |
822 | wxWindowCreationHook hook(this); |
823 | ||
3ca6a5f0 | 824 | m_hWnd = (WXHWND)::SendMessage(GetWinHwnd(parent->GetClientWindow()), |
dca0f651 | 825 | WM_MDICREATE, 0, (LPARAM)&mcs); |
2bda0e17 | 826 | |
05ae668c VZ |
827 | if ( !m_hWnd ) |
828 | { | |
829 | wxLogLastError(_T("WM_MDICREATE")); | |
830 | return false; | |
831 | } | |
832 | ||
833 | SubclassWin(m_hWnd); | |
2bda0e17 | 834 | |
ecc63060 VZ |
835 | parent->AddMDIChild(this); |
836 | ||
4f8090e0 | 837 | return true; |
2bda0e17 KB |
838 | } |
839 | ||
c2dcfdef | 840 | wxMDIChildFrame::~wxMDIChildFrame() |
2bda0e17 | 841 | { |
b38e5da1 VZ |
842 | // if we hadn't been created, there is nothing to destroy |
843 | if ( !m_hWnd ) | |
844 | return; | |
845 | ||
ecc63060 VZ |
846 | GetMDIParent()->RemoveMDIChild(this); |
847 | ||
d1e44484 VZ |
848 | // will be destroyed by DestroyChildren() but reset them before calling it |
849 | // to avoid using dangling pointers if a callback comes in the meanwhile | |
1904aa72 | 850 | #if wxUSE_TOOLBAR |
627a3091 | 851 | m_frameToolBar = NULL; |
1904aa72 | 852 | #endif |
67a99992 | 853 | #if wxUSE_STATUSBAR |
627a3091 | 854 | m_frameStatusBar = NULL; |
67a99992 | 855 | #endif // wxUSE_STATUSBAR |
627a3091 | 856 | |
d1e44484 VZ |
857 | DestroyChildren(); |
858 | ||
ecc63060 | 859 | MDIRemoveWindowMenu(NULL, m_hMenu); |
4e152a23 | 860 | |
c2dcfdef | 861 | MSWDestroyWindow(); |
2bda0e17 KB |
862 | } |
863 | ||
2596e9fb VS |
864 | bool wxMDIChildFrame::Show(bool show) |
865 | { | |
866 | m_needsInitialShow = false; | |
6fa30495 KH |
867 | |
868 | if (!wxFrame::Show(show)) | |
869 | return false; | |
870 | ||
871 | // KH: Without this call, new MDI children do not become active. | |
872 | // This was added here after the same BringWindowToTop call was | |
873 | // removed from wxTopLevelWindow::Show (November 2005) | |
874 | if ( show ) | |
875 | ::BringWindowToTop(GetHwnd()); | |
876 | ||
e45a6885 VZ |
877 | // we need to refresh the MDI frame window menu to include (or exclude if |
878 | // we've been hidden) this frame | |
d2824cdb | 879 | wxMDIParentFrame * const parent = GetMDIParent(); |
e45a6885 VZ |
880 | MDISetMenu(parent->GetClientWindow(), NULL, NULL); |
881 | ||
6fa30495 | 882 | return true; |
2596e9fb VS |
883 | } |
884 | ||
2bda0e17 | 885 | // Set the client size (i.e. leave the calculation of borders etc. |
77ffb593 | 886 | // to wxWidgets) |
cc2b7472 | 887 | void wxMDIChildFrame::DoSetClientSize(int width, int height) |
2bda0e17 | 888 | { |
b3818fbe | 889 | HWND hWnd = GetHwnd(); |
2bda0e17 KB |
890 | |
891 | RECT rect; | |
2de8030d | 892 | ::GetClientRect(hWnd, &rect); |
2bda0e17 KB |
893 | |
894 | RECT rect2; | |
895 | GetWindowRect(hWnd, &rect2); | |
896 | ||
897 | // Find the difference between the entire window (title bar and all) | |
898 | // and the client area; add this to the new client size to move the | |
899 | // window | |
900 | int actual_width = rect2.right - rect2.left - rect.right + width; | |
901 | int actual_height = rect2.bottom - rect2.top - rect.bottom + height; | |
902 | ||
67a99992 | 903 | #if wxUSE_STATUSBAR |
a2327a9f | 904 | if (GetStatusBar() && GetStatusBar()->IsShown()) |
2bda0e17 | 905 | { |
c2dcfdef VZ |
906 | int sx, sy; |
907 | GetStatusBar()->GetSize(&sx, &sy); | |
2bda0e17 KB |
908 | actual_height += sy; |
909 | } | |
67a99992 | 910 | #endif // wxUSE_STATUSBAR |
2bda0e17 KB |
911 | |
912 | POINT point; | |
913 | point.x = rect2.left; | |
914 | point.y = rect2.top; | |
915 | ||
916 | // If there's an MDI parent, must subtract the parent's top left corner | |
917 | // since MoveWindow moves relative to the parent | |
d2824cdb VZ |
918 | wxMDIParentFrame * const mdiParent = GetMDIParent(); |
919 | ::ScreenToClient(GetHwndOf(mdiParent->GetClientWindow()), &point); | |
2bda0e17 | 920 | |
4f8090e0 | 921 | MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)true); |
debe6624 | 922 | |
5c519b6c WS |
923 | wxSize size(width, height); |
924 | wxSizeEvent event(size, m_windowId); | |
debe6624 | 925 | event.SetEventObject( this ); |
937013e0 | 926 | HandleWindowEvent(event); |
2bda0e17 KB |
927 | } |
928 | ||
3e85709e VZ |
929 | // Unlike other wxTopLevelWindowBase, the mdi child's "GetPosition" is not the |
930 | // same as its GetScreenPosition | |
931 | void wxMDIChildFrame::DoGetScreenPosition(int *x, int *y) const | |
932 | { | |
933 | HWND hWnd = GetHwnd(); | |
934 | ||
935 | RECT rect; | |
936 | ::GetWindowRect(hWnd, &rect); | |
937 | if (x) | |
938 | *x = rect.left; | |
939 | if (y) | |
940 | *y = rect.top; | |
941 | } | |
942 | ||
943 | ||
cc2b7472 | 944 | void wxMDIChildFrame::DoGetPosition(int *x, int *y) const |
2bda0e17 KB |
945 | { |
946 | RECT rect; | |
b3818fbe | 947 | GetWindowRect(GetHwnd(), &rect); |
2bda0e17 KB |
948 | POINT point; |
949 | point.x = rect.left; | |
950 | point.y = rect.top; | |
951 | ||
952 | // Since we now have the absolute screen coords, | |
953 | // if there's a parent we must subtract its top left corner | |
d2824cdb VZ |
954 | wxMDIParentFrame * const mdiParent = GetMDIParent(); |
955 | ::ScreenToClient(GetHwndOf(mdiParent->GetClientWindow()), &point); | |
2bda0e17 | 956 | |
1696dde5 JS |
957 | if (x) |
958 | *x = point.x; | |
959 | if (y) | |
960 | *y = point.y; | |
2bda0e17 KB |
961 | } |
962 | ||
42e69d6b | 963 | void wxMDIChildFrame::InternalSetMenuBar() |
2bda0e17 | 964 | { |
d2824cdb | 965 | wxMDIParentFrame * const parent = GetMDIParent(); |
2bda0e17 | 966 | |
ecc63060 | 967 | MDIInsertWindowMenu(parent->GetClientWindow(), |
4e152a23 | 968 | m_hMenu, GetMDIWindowMenu(parent)); |
2bda0e17 KB |
969 | } |
970 | ||
e3307ddd CE |
971 | void wxMDIChildFrame::DetachMenuBar() |
972 | { | |
ecc63060 | 973 | MDIRemoveWindowMenu(NULL, m_hMenu); |
6bbe97b7 | 974 | wxFrame::DetachMenuBar(); |
e3307ddd CE |
975 | } |
976 | ||
82c9f85c VZ |
977 | WXHICON wxMDIChildFrame::GetDefaultIcon() const |
978 | { | |
94826170 VZ |
979 | // we don't have any standard icons (any more) |
980 | return (WXHICON)0; | |
82c9f85c VZ |
981 | } |
982 | ||
42e69d6b | 983 | // --------------------------------------------------------------------------- |
2bda0e17 | 984 | // MDI operations |
42e69d6b VZ |
985 | // --------------------------------------------------------------------------- |
986 | ||
9b73db3c | 987 | void wxMDIChildFrame::Maximize(bool maximize) |
2bda0e17 | 988 | { |
d2824cdb | 989 | wxMDIParentFrame * const parent = GetMDIParent(); |
2bda0e17 | 990 | if ( parent && parent->GetClientWindow() ) |
9b73db3c VZ |
991 | { |
992 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), | |
993 | maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE, | |
994 | (WPARAM)GetHwnd(), 0); | |
995 | } | |
2bda0e17 KB |
996 | } |
997 | ||
c2dcfdef | 998 | void wxMDIChildFrame::Restore() |
2bda0e17 | 999 | { |
d2824cdb | 1000 | wxMDIParentFrame * const parent = GetMDIParent(); |
2bda0e17 | 1001 | if ( parent && parent->GetClientWindow() ) |
9b73db3c VZ |
1002 | { |
1003 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE, | |
1004 | (WPARAM) GetHwnd(), 0); | |
1005 | } | |
2bda0e17 KB |
1006 | } |
1007 | ||
c2dcfdef | 1008 | void wxMDIChildFrame::Activate() |
2bda0e17 | 1009 | { |
d2824cdb | 1010 | wxMDIParentFrame * const parent = GetMDIParent(); |
2bda0e17 | 1011 | if ( parent && parent->GetClientWindow() ) |
9b73db3c VZ |
1012 | { |
1013 | ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE, | |
1014 | (WPARAM) GetHwnd(), 0); | |
1015 | } | |
2bda0e17 KB |
1016 | } |
1017 | ||
42e69d6b VZ |
1018 | // --------------------------------------------------------------------------- |
1019 | // MDI window proc and message handlers | |
1020 | // --------------------------------------------------------------------------- | |
1021 | ||
c140b7e7 | 1022 | WXLRESULT wxMDIChildFrame::MSWWindowProc(WXUINT message, |
42e69d6b VZ |
1023 | WXWPARAM wParam, |
1024 | WXLPARAM lParam) | |
1025 | { | |
c140b7e7 | 1026 | WXLRESULT rc = 0; |
4f8090e0 | 1027 | bool processed = false; |
42e69d6b VZ |
1028 | |
1029 | switch ( message ) | |
1030 | { | |
42e69d6b | 1031 | case WM_GETMINMAXINFO: |
3ebcfb76 VZ |
1032 | processed = HandleGetMinMaxInfo((MINMAXINFO *)lParam); |
1033 | break; | |
42e69d6b VZ |
1034 | |
1035 | case WM_MDIACTIVATE: | |
1036 | { | |
1037 | WXWORD act; | |
1038 | WXHWND hwndAct, hwndDeact; | |
1039 | UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact); | |
1040 | ||
1041 | processed = HandleMDIActivate(act, hwndAct, hwndDeact); | |
1042 | } | |
b3818fbe VZ |
1043 | // fall through |
1044 | ||
1045 | case WM_MOVE: | |
1046 | // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client | |
1047 | // scrollbars if necessary | |
1048 | ||
1049 | // fall through | |
1050 | ||
1051 | case WM_SIZE: | |
1052 | // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird | |
1053 | // things happen | |
1054 | MSWDefWindowProc(message, wParam, lParam); | |
42e69d6b VZ |
1055 | break; |
1056 | ||
b3818fbe VZ |
1057 | case WM_SYSCOMMAND: |
1058 | // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it | |
1059 | // the message (the base class version does not) | |
1060 | return MSWDefWindowProc(message, wParam, lParam); | |
1061 | ||
42e69d6b VZ |
1062 | case WM_WINDOWPOSCHANGING: |
1063 | processed = HandleWindowPosChanging((LPWINDOWPOS)lParam); | |
1064 | break; | |
1065 | } | |
1066 | ||
1067 | if ( !processed ) | |
1068 | rc = wxFrame::MSWWindowProc(message, wParam, lParam); | |
1069 | ||
1070 | return rc; | |
1071 | } | |
1072 | ||
42e69d6b VZ |
1073 | bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate), |
1074 | WXHWND hwndAct, | |
1075 | WXHWND hwndDeact) | |
2bda0e17 | 1076 | { |
d2824cdb | 1077 | wxMDIParentFrame * const parent = GetMDIParent(); |
2bda0e17 | 1078 | |
51181d29 | 1079 | WXHMENU hMenuToSet = 0; |
57a7b7c1 | 1080 | |
42e69d6b | 1081 | bool activated; |
57a7b7c1 | 1082 | |
42e69d6b VZ |
1083 | if ( m_hWnd == hwndAct ) |
1084 | { | |
4f8090e0 | 1085 | activated = true; |
1483e5db | 1086 | parent->SetActiveChild(this); |
2bda0e17 | 1087 | |
51181d29 VZ |
1088 | WXHMENU hMenuChild = m_hMenu; |
1089 | if ( hMenuChild ) | |
51181d29 | 1090 | hMenuToSet = hMenuChild; |
42e69d6b VZ |
1091 | } |
1092 | else if ( m_hWnd == hwndDeact ) | |
2bda0e17 | 1093 | { |
1483e5db | 1094 | wxASSERT_MSG( parent->GetActiveChild() == this, |
223d09f6 | 1095 | wxT("can't deactivate MDI child which wasn't active!") ); |
42e69d6b | 1096 | |
4f8090e0 | 1097 | activated = false; |
1483e5db | 1098 | parent->SetActiveChild(NULL); |
2bda0e17 | 1099 | |
51181d29 | 1100 | WXHMENU hMenuParent = parent->m_hMenu; |
f4075804 VZ |
1101 | |
1102 | // activate the the parent menu only when there is no other child | |
1103 | // that has been activated | |
51181d29 | 1104 | if ( hMenuParent && !hwndAct ) |
51181d29 | 1105 | hMenuToSet = hMenuParent; |
42e69d6b VZ |
1106 | } |
1107 | else | |
1108 | { | |
18d2e170 | 1109 | // we have nothing to do with it |
4f8090e0 | 1110 | return false; |
2bda0e17 | 1111 | } |
debe6624 | 1112 | |
51181d29 | 1113 | if ( hMenuToSet ) |
42e69d6b | 1114 | { |
4e152a23 | 1115 | MDISetMenu(parent->GetClientWindow(), |
51181d29 | 1116 | (HMENU)hMenuToSet, GetMDIWindowMenu(parent)); |
42e69d6b VZ |
1117 | } |
1118 | ||
1119 | wxActivateEvent event(wxEVT_ACTIVATE, activated, m_windowId); | |
debe6624 | 1120 | event.SetEventObject( this ); |
2bda0e17 | 1121 | |
d3b9f782 | 1122 | ResetWindowStyle(NULL); |
c03b48d7 | 1123 | |
937013e0 | 1124 | return HandleWindowEvent(event); |
42e69d6b VZ |
1125 | } |
1126 | ||
1127 | bool wxMDIChildFrame::HandleWindowPosChanging(void *pos) | |
1128 | { | |
1129 | WINDOWPOS *lpPos = (WINDOWPOS *)pos; | |
a71d815b | 1130 | |
42e69d6b | 1131 | if (!(lpPos->flags & SWP_NOSIZE)) |
2bda0e17 | 1132 | { |
42e69d6b | 1133 | RECT rectClient; |
b3818fbe VZ |
1134 | DWORD dwExStyle = ::GetWindowLong(GetHwnd(), GWL_EXSTYLE); |
1135 | DWORD dwStyle = ::GetWindowLong(GetHwnd(), GWL_STYLE); | |
42e69d6b VZ |
1136 | if (ResetWindowStyle((void *) & rectClient) && (dwStyle & WS_MAXIMIZE)) |
1137 | { | |
4f8090e0 | 1138 | ::AdjustWindowRectEx(&rectClient, dwStyle, false, dwExStyle); |
42e69d6b VZ |
1139 | lpPos->x = rectClient.left; |
1140 | lpPos->y = rectClient.top; | |
1141 | lpPos->cx = rectClient.right - rectClient.left; | |
1142 | lpPos->cy = rectClient.bottom - rectClient.top; | |
1143 | } | |
42e69d6b | 1144 | } |
42e69d6b | 1145 | |
4f8090e0 | 1146 | return false; |
42e69d6b VZ |
1147 | } |
1148 | ||
3ebcfb76 VZ |
1149 | bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo) |
1150 | { | |
1151 | MINMAXINFO *info = (MINMAXINFO *)mmInfo; | |
1152 | ||
1153 | // let the default window proc calculate the size of MDI children | |
1154 | // frames because it is based on the size of the MDI client window, | |
1155 | // not on the values specified in wxWindow m_max variables | |
d9f9aa2d | 1156 | bool processed = MSWDefWindowProc(WM_GETMINMAXINFO, 0, (LPARAM)mmInfo) != 0; |
3ebcfb76 | 1157 | |
e7dda1ff VS |
1158 | int minWidth = GetMinWidth(), |
1159 | minHeight = GetMinHeight(); | |
1160 | ||
3ebcfb76 | 1161 | // but allow GetSizeHints() to set the min size |
a71d815b | 1162 | if ( minWidth != wxDefaultCoord ) |
3ebcfb76 | 1163 | { |
e7dda1ff | 1164 | info->ptMinTrackSize.x = minWidth; |
3ebcfb76 | 1165 | |
4f8090e0 | 1166 | processed = true; |
3ebcfb76 VZ |
1167 | } |
1168 | ||
a71d815b | 1169 | if ( minHeight != wxDefaultCoord ) |
3ebcfb76 | 1170 | { |
e7dda1ff | 1171 | info->ptMinTrackSize.y = minHeight; |
3ebcfb76 | 1172 | |
4f8090e0 | 1173 | processed = true; |
3ebcfb76 VZ |
1174 | } |
1175 | ||
4c9d78a4 | 1176 | return processed; |
3ebcfb76 VZ |
1177 | } |
1178 | ||
42e69d6b VZ |
1179 | // --------------------------------------------------------------------------- |
1180 | // MDI specific message translation/preprocessing | |
1181 | // --------------------------------------------------------------------------- | |
2bda0e17 | 1182 | |
c140b7e7 | 1183 | WXLRESULT wxMDIChildFrame::MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
42e69d6b VZ |
1184 | { |
1185 | return DefMDIChildProc(GetHwnd(), | |
1186 | (UINT)message, (WPARAM)wParam, (LPARAM)lParam); | |
1187 | } | |
1188 | ||
1189 | bool wxMDIChildFrame::MSWTranslateMessage(WXMSG* msg) | |
1190 | { | |
1ac76609 VZ |
1191 | // we must pass the parent frame to ::TranslateAccelerator(), otherwise it |
1192 | // doesn't do its job correctly for MDI child menus | |
55ae1551 | 1193 | return MSWDoTranslateMessage(GetMDIParent(), msg); |
2bda0e17 KB |
1194 | } |
1195 | ||
42e69d6b VZ |
1196 | // --------------------------------------------------------------------------- |
1197 | // misc | |
1198 | // --------------------------------------------------------------------------- | |
1199 | ||
c2dcfdef | 1200 | void wxMDIChildFrame::MSWDestroyWindow() |
2bda0e17 | 1201 | { |
d2824cdb | 1202 | wxMDIParentFrame * const parent = GetMDIParent(); |
2bda0e17 | 1203 | |
42e69d6b VZ |
1204 | // Must make sure this handle is invalidated (set to NULL) since all sorts |
1205 | // of things could happen after the child client is destroyed, but before | |
1206 | // the wxFrame is destroyed. | |
2bda0e17 | 1207 | |
42e69d6b | 1208 | HWND oldHandle = (HWND)GetHWND(); |
b3818fbe VZ |
1209 | SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY, |
1210 | (WPARAM)oldHandle, 0); | |
18d2e170 | 1211 | |
ecc63060 VZ |
1212 | if (parent->GetActiveChild() == NULL) |
1213 | ResetWindowStyle(NULL); | |
18d2e170 | 1214 | |
42e69d6b VZ |
1215 | if (m_hMenu) |
1216 | { | |
1217 | ::DestroyMenu((HMENU) m_hMenu); | |
1218 | m_hMenu = 0; | |
1219 | } | |
ac6482e0 | 1220 | wxRemoveHandleAssociation(this); |
42e69d6b | 1221 | m_hWnd = 0; |
2bda0e17 KB |
1222 | } |
1223 | ||
42e69d6b VZ |
1224 | // Change the client window's extended style so we don't get a client edge |
1225 | // style when a child is maximised (a double border looks silly.) | |
2bda0e17 KB |
1226 | bool wxMDIChildFrame::ResetWindowStyle(void *vrect) |
1227 | { | |
2bda0e17 | 1228 | RECT *rect = (RECT *)vrect; |
d2824cdb | 1229 | wxMDIParentFrame * const pFrameWnd = GetMDIParent(); |
c2dcfdef | 1230 | wxMDIChildFrame* pChild = pFrameWnd->GetActiveChild(); |
a71d815b | 1231 | |
c2dcfdef VZ |
1232 | if (!pChild || (pChild == this)) |
1233 | { | |
47ca6bfb | 1234 | HWND hwndClient = GetWinHwnd(pFrameWnd->GetClientWindow()); |
8082a771 VZ |
1235 | DWORD dwStyle = ::GetWindowLong(hwndClient, GWL_EXSTYLE); |
1236 | ||
1237 | // we want to test whether there is a maximized child, so just set | |
1238 | // dwThisStyle to 0 if there is no child at all | |
1239 | DWORD dwThisStyle = pChild | |
1f3943e0 | 1240 | ? ::GetWindowLong(GetWinHwnd(pChild), GWL_STYLE) : 0; |
c2dcfdef | 1241 | DWORD dwNewStyle = dwStyle; |
8082a771 | 1242 | if ( dwThisStyle & WS_MAXIMIZE ) |
c2dcfdef VZ |
1243 | dwNewStyle &= ~(WS_EX_CLIENTEDGE); |
1244 | else | |
1245 | dwNewStyle |= WS_EX_CLIENTEDGE; | |
1246 | ||
1247 | if (dwStyle != dwNewStyle) | |
1248 | { | |
47ca6bfb VZ |
1249 | // force update of everything |
1250 | ::RedrawWindow(hwndClient, NULL, NULL, | |
1251 | RDW_INVALIDATE | RDW_ALLCHILDREN); | |
1252 | ::SetWindowLong(hwndClient, GWL_EXSTYLE, dwNewStyle); | |
1253 | ::SetWindowPos(hwndClient, NULL, 0, 0, 0, 0, | |
42e69d6b VZ |
1254 | SWP_FRAMECHANGED | SWP_NOACTIVATE | |
1255 | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | | |
1256 | SWP_NOCOPYBITS); | |
c2dcfdef | 1257 | if (rect) |
47ca6bfb | 1258 | ::GetClientRect(hwndClient, rect); |
2bda0e17 | 1259 | |
4f8090e0 | 1260 | return true; |
2bda0e17 | 1261 | } |
c2dcfdef | 1262 | } |
a23fd0e1 | 1263 | |
4f8090e0 | 1264 | return false; |
2bda0e17 KB |
1265 | } |
1266 | ||
42e69d6b VZ |
1267 | // =========================================================================== |
1268 | // wxMDIClientWindow: the window of predefined (by Windows) class which | |
1269 | // contains the child frames | |
1270 | // =========================================================================== | |
2bda0e17 | 1271 | |
debe6624 | 1272 | bool wxMDIClientWindow::CreateClient(wxMDIParentFrame *parent, long style) |
2bda0e17 | 1273 | { |
a756f210 | 1274 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE); |
2bda0e17 | 1275 | |
42e69d6b VZ |
1276 | CLIENTCREATESTRUCT ccs; |
1277 | m_windowStyle = style; | |
1278 | m_parent = parent; | |
c2dcfdef | 1279 | |
4e152a23 | 1280 | ccs.hWindowMenu = GetMDIWindowMenu(parent); |
42e69d6b | 1281 | ccs.idFirstChild = wxFIRST_MDI_CHILD; |
2bda0e17 | 1282 | |
5c44cd05 | 1283 | DWORD msStyle = MDIS_ALLCHILDSTYLES | WS_VISIBLE | WS_CHILD | |
b0766406 JS |
1284 | WS_CLIPCHILDREN | WS_CLIPSIBLINGS; |
1285 | ||
42e69d6b VZ |
1286 | if ( style & wxHSCROLL ) |
1287 | msStyle |= WS_HSCROLL; | |
1288 | if ( style & wxVSCROLL ) | |
1289 | msStyle |= WS_VSCROLL; | |
2bda0e17 | 1290 | |
42e69d6b | 1291 | DWORD exStyle = WS_EX_CLIENTEDGE; |
2bda0e17 | 1292 | |
b225f659 | 1293 | wxWindowCreationHook hook(this); |
42e69d6b VZ |
1294 | m_hWnd = (WXHWND)::CreateWindowEx |
1295 | ( | |
1296 | exStyle, | |
223d09f6 | 1297 | wxT("MDICLIENT"), |
42e69d6b VZ |
1298 | NULL, |
1299 | msStyle, | |
1300 | 0, 0, 0, 0, | |
1301 | GetWinHwnd(parent), | |
1302 | NULL, | |
1303 | wxGetInstance(), | |
1304 | (LPSTR)(LPCLIENTCREATESTRUCT)&ccs); | |
1305 | if ( !m_hWnd ) | |
1306 | { | |
f6bcfd97 | 1307 | wxLogLastError(wxT("CreateWindowEx(MDI client)")); |
2bda0e17 | 1308 | |
4f8090e0 | 1309 | return false; |
42e69d6b | 1310 | } |
2bda0e17 | 1311 | |
42e69d6b | 1312 | SubclassWin(m_hWnd); |
2bda0e17 | 1313 | |
4f8090e0 | 1314 | return true; |
2bda0e17 KB |
1315 | } |
1316 | ||
1317 | // Explicitly call default scroll behaviour | |
1318 | void wxMDIClientWindow::OnScroll(wxScrollEvent& event) | |
1319 | { | |
1320 | // Note: for client windows, the scroll position is not set in | |
1321 | // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what | |
1322 | // scroll position we're at. | |
1323 | // This makes it hard to paint patterns or bitmaps in the background, | |
1324 | // and have the client area scrollable as well. | |
1325 | ||
1326 | if ( event.GetOrientation() == wxHORIZONTAL ) | |
1327 | m_scrollX = event.GetPosition(); // Always returns zero! | |
1328 | else | |
1329 | m_scrollY = event.GetPosition(); // Always returns zero! | |
1330 | ||
42e69d6b VZ |
1331 | event.Skip(); |
1332 | } | |
1333 | ||
ec06b234 JS |
1334 | void wxMDIClientWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
1335 | { | |
1336 | // Try to fix a problem whereby if you show an MDI child frame, then reposition the | |
1337 | // client area, you can end up with a non-refreshed portion in the client window | |
1338 | // (see OGL studio sample). So check if the position is changed and if so, | |
1339 | // redraw the MDI child frames. | |
1340 | ||
6bbe97b7 | 1341 | const wxPoint oldPos = GetPosition(); |
ec06b234 | 1342 | |
6bbe97b7 | 1343 | wxWindow::DoSetSize(x, y, width, height, sizeFlags | wxSIZE_FORCE); |
ec06b234 | 1344 | |
6bbe97b7 | 1345 | const wxPoint newPos = GetPosition(); |
ec06b234 JS |
1346 | |
1347 | if ((newPos.x != oldPos.x) || (newPos.y != oldPos.y)) | |
1348 | { | |
1349 | if (GetParent()) | |
1350 | { | |
222ed1d6 | 1351 | wxWindowList::compatibility_iterator node = GetParent()->GetChildren().GetFirst(); |
ec06b234 JS |
1352 | while (node) |
1353 | { | |
d162a7ee | 1354 | wxWindow *child = node->GetData(); |
ec06b234 JS |
1355 | if (child->IsKindOf(CLASSINFO(wxMDIChildFrame))) |
1356 | { | |
d162a7ee VZ |
1357 | ::RedrawWindow(GetHwndOf(child), |
1358 | NULL, | |
1359 | NULL, | |
1360 | RDW_FRAME | | |
1361 | RDW_ALLCHILDREN | | |
1362 | RDW_INVALIDATE); | |
ec06b234 | 1363 | } |
4f8090e0 | 1364 | node = node->GetNext(); |
ec06b234 JS |
1365 | } |
1366 | } | |
1367 | } | |
1368 | } | |
1369 | ||
f6bcfd97 BP |
1370 | void wxMDIChildFrame::OnIdle(wxIdleEvent& event) |
1371 | { | |
2596e9fb VS |
1372 | // wxMSW prior to 2.5.3 created MDI child frames as visible, which resulted |
1373 | // in flicker e.g. when the frame contained controls with non-trivial | |
1374 | // layout. Since 2.5.3, the frame is created hidden as all other top level | |
1375 | // windows. In order to maintain backward compatibility, the frame is shown | |
1376 | // in OnIdle, unless Show(false) was called by the programmer before. | |
1377 | if ( m_needsInitialShow ) | |
1378 | { | |
1379 | Show(true); | |
1380 | } | |
5c519b6c | 1381 | |
f6bcfd97 BP |
1382 | // MDI child frames get their WM_SIZE when they're constructed but at this |
1383 | // moment they don't have any children yet so all child windows will be | |
1384 | // positioned incorrectly when they are added later - to fix this, we | |
1385 | // generate an artificial size event here | |
1386 | if ( m_needsResize ) | |
1387 | { | |
4f8090e0 | 1388 | m_needsResize = false; // avoid any possibility of recursion |
f6bcfd97 BP |
1389 | |
1390 | SendSizeEvent(); | |
1391 | } | |
1392 | ||
1393 | event.Skip(); | |
1394 | } | |
1395 | ||
42e69d6b | 1396 | // --------------------------------------------------------------------------- |
838e6ed7 | 1397 | // private helper functions |
42e69d6b VZ |
1398 | // --------------------------------------------------------------------------- |
1399 | ||
838e6ed7 VZ |
1400 | namespace |
1401 | { | |
1402 | ||
1403 | void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow) | |
42e69d6b | 1404 | { |
e45a6885 VZ |
1405 | if ( hmenuFrame || hmenuWindow ) |
1406 | { | |
1407 | if ( !::SendMessage(GetWinHwnd(win), | |
1408 | WM_MDISETMENU, | |
1409 | (WPARAM)hmenuFrame, | |
1410 | (LPARAM)hmenuWindow) ) | |
1411 | { | |
0d7c4404 VZ |
1412 | #ifdef __WXDEBUG__ |
1413 | DWORD err = ::GetLastError(); | |
1414 | if ( err ) | |
1415 | wxLogApiError(_T("SendMessage(WM_MDISETMENU)"), err); | |
1416 | #endif // __WXDEBUG__ | |
e45a6885 VZ |
1417 | } |
1418 | } | |
42e69d6b VZ |
1419 | |
1420 | // update menu bar of the parent window | |
1421 | wxWindow *parent = win->GetParent(); | |
223d09f6 | 1422 | wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") ); |
42e69d6b | 1423 | |
a967ef9d | 1424 | ::SendMessage(GetWinHwnd(win), WM_MDIREFRESHMENU, 0, 0L); |
788722ac | 1425 | |
42e69d6b VZ |
1426 | ::DrawMenuBar(GetWinHwnd(parent)); |
1427 | } | |
1428 | ||
838e6ed7 | 1429 | void MDIInsertWindowMenu(wxWindow *win, WXHMENU hMenu, HMENU menuWin) |
42e69d6b | 1430 | { |
838e6ed7 | 1431 | HMENU hmenu = (HMENU)hMenu; |
df61c009 | 1432 | |
838e6ed7 | 1433 | if ( menuWin ) |
df61c009 | 1434 | { |
838e6ed7 | 1435 | // Try to insert Window menu in front of Help, otherwise append it. |
4e152a23 | 1436 | int N = GetMenuItemCount(hmenu); |
838e6ed7 | 1437 | bool inserted = false; |
4e152a23 | 1438 | for ( int i = 0; i < N; i++ ) |
42e69d6b | 1439 | { |
4e152a23 | 1440 | wxChar buf[256]; |
838e6ed7 | 1441 | if ( !::GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) ) |
4e152a23 VZ |
1442 | { |
1443 | wxLogLastError(wxT("GetMenuString")); | |
42e69d6b | 1444 | |
4e152a23 VZ |
1445 | continue; |
1446 | } | |
1447 | ||
838e6ed7 VZ |
1448 | const wxString label = wxStripMenuCodes(buf); |
1449 | if ( label == wxGetStockLabel(wxID_HELP, wxSTOCK_NOFLAGS) ) | |
4e152a23 | 1450 | { |
838e6ed7 | 1451 | inserted = true; |
4e152a23 | 1452 | ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING, |
838e6ed7 VZ |
1453 | (UINT_PTR)menuWin, |
1454 | wxGetTranslation(WINDOW_MENU_LABEL).wx_str()); | |
4e152a23 VZ |
1455 | break; |
1456 | } | |
42e69d6b VZ |
1457 | } |
1458 | ||
838e6ed7 | 1459 | if ( !inserted ) |
42e69d6b | 1460 | { |
dca0f651 | 1461 | ::AppendMenu(hmenu, MF_POPUP, |
838e6ed7 VZ |
1462 | (UINT_PTR)menuWin, |
1463 | wxGetTranslation(WINDOW_MENU_LABEL).wx_str()); | |
42e69d6b VZ |
1464 | } |
1465 | } | |
1466 | ||
838e6ed7 | 1467 | MDISetMenu(win, hmenu, menuWin); |
42e69d6b VZ |
1468 | } |
1469 | ||
838e6ed7 | 1470 | void MDIRemoveWindowMenu(wxWindow *win, WXHMENU hMenu) |
df61c009 | 1471 | { |
838e6ed7 | 1472 | HMENU hmenu = (HMENU)hMenu; |
4e152a23 | 1473 | |
838e6ed7 | 1474 | if ( hmenu ) |
df61c009 | 1475 | { |
4e152a23 VZ |
1476 | wxChar buf[1024]; |
1477 | ||
838e6ed7 | 1478 | int N = ::GetMenuItemCount(hmenu); |
4e152a23 | 1479 | for ( int i = 0; i < N; i++ ) |
df61c009 | 1480 | { |
838e6ed7 | 1481 | if ( !::GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) ) |
4e152a23 | 1482 | { |
2c62b3c3 | 1483 | // Ignore successful read of menu string with length 0 which |
838e6ed7 | 1484 | // occurs, for example, for a maximized MDI child system menu |
2c62b3c3 VZ |
1485 | if ( ::GetLastError() != 0 ) |
1486 | { | |
1487 | wxLogLastError(wxT("GetMenuString")); | |
1488 | } | |
df61c009 | 1489 | |
4e152a23 VZ |
1490 | continue; |
1491 | } | |
df61c009 | 1492 | |
838e6ed7 | 1493 | if ( wxStrcmp(buf, wxGetTranslation(WINDOW_MENU_LABEL)) == 0 ) |
4e152a23 | 1494 | { |
838e6ed7 | 1495 | if ( !::RemoveMenu(hmenu, i, MF_BYPOSITION) ) |
4e152a23 VZ |
1496 | { |
1497 | wxLogLastError(wxT("RemoveMenu")); | |
1498 | } | |
1499 | ||
1500 | break; | |
1501 | } | |
df61c009 JS |
1502 | } |
1503 | } | |
1504 | ||
4e152a23 VZ |
1505 | if ( win ) |
1506 | { | |
1507 | // we don't change the windows menu, but we update the main one | |
838e6ed7 | 1508 | MDISetMenu(win, hmenu, NULL); |
4e152a23 | 1509 | } |
df61c009 JS |
1510 | } |
1511 | ||
838e6ed7 | 1512 | void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam, |
2917e920 | 1513 | WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact) |
42e69d6b | 1514 | { |
4f8090e0 | 1515 | *activate = true; |
42e69d6b VZ |
1516 | *hwndAct = (WXHWND)lParam; |
1517 | *hwndDeact = (WXHWND)wParam; | |
2bda0e17 | 1518 | } |
b9f933ab | 1519 | |
838e6ed7 VZ |
1520 | } // anonymous namespace |
1521 | ||
efd17a1d | 1522 | #endif // wxUSE_MDI && !defined(__WXUNIVERSAL__) |