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