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