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