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