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