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