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