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