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