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