1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/dialog.h"
22 #include "wx/statusbr.h"
23 #include "wx/settings.h"
29 #include "wx/os2/private.h"
33 // ---------------------------------------------------------------------------
35 // ---------------------------------------------------------------------------
37 extern wxWindowList wxModelessWindows
; // from dialog.cpp
38 extern wxMenu
*wxCurrentPopupMenu
;
40 extern wxWindow
*wxWndHook
; // from window.cpp
42 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
44 static HWND invalidHandle
= 0;
46 // ---------------------------------------------------------------------------
48 // ---------------------------------------------------------------------------
50 static const int IDM_WINDOWTILE
= 4001;
51 static const int IDM_WINDOWTILEHOR
= 4001;
52 static const int IDM_WINDOWCASCADE
= 4002;
53 static const int IDM_WINDOWICONS
= 4003;
54 static const int IDM_WINDOWNEXT
= 4004;
55 static const int IDM_WINDOWTILEVERT
= 4005;
57 // This range gives a maximum of 500 MDI children. Should be enough :-)
58 static const int wxFIRST_MDI_CHILD
= 4100;
59 static const int wxLAST_MDI_CHILD
= 4600;
61 // Status border dimensions
62 static const int wxTHICK_LINE_BORDER
= 3;
63 static const int wxTHICK_LINE_WIDTH
= 1;
65 // ---------------------------------------------------------------------------
67 // ---------------------------------------------------------------------------
69 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
70 // of the parent of win (which is supposed to be the MDI client window)
71 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
73 // insert the window menu (subMenu) into menu just before "Help" submenu or at
74 // the very end if not found
75 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
77 // is this an id of an MDI child?
78 inline bool IsMdiCommandId(int id
)
80 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
83 // unpack the parameters of WM_MDIACTIVATE message
84 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
85 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
87 // return the HMENU of the MDI menu
88 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
90 wxMenu
*menu
= frame
->GetWindowMenu();
91 return menu
? GetHmenuOf(menu
) : 0;
94 // ===========================================================================
96 // ===========================================================================
98 // ---------------------------------------------------------------------------
100 // ---------------------------------------------------------------------------
102 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
103 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
104 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
106 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
107 EVT_SIZE(wxMDIParentFrame::OnSize
)
108 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
111 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
112 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
115 // ===========================================================================
116 // wxMDIParentFrame: the frame which contains the client window which manages
118 // ===========================================================================
120 wxMDIParentFrame::wxMDIParentFrame()
122 m_clientWindow
= NULL
;
123 m_currentChild
= NULL
;
125 m_parentFrameActive
= TRUE
;
128 bool wxMDIParentFrame::Create(wxWindow
*parent
,
130 const wxString
& title
,
134 const wxString
& name
)
136 m_hDefaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
138 m_clientWindow
= NULL
;
139 m_currentChild
= NULL
;
141 m_parentFrameActive
= TRUE
;
144 wxTopLevelWindows
.Append(this);
147 wxWindowBase::Show(TRUE
); // MDI child frame starts off shown
148 m_windowStyle
= style
;
150 if (parent
) parent
->AddChild(this);
155 m_windowId
= (int)NewControlId();
162 // TODO: m_windowMenu = (WXHMENU) ::LoadMenu(wxGetInstance(), wxT("wxWindowMenu"));
164 DWORD msflags = WS_OVERLAPPED;
165 if (style & wxMINIMIZE_BOX)
166 msflags |= WS_MINIMIZEBOX;
167 if (style & wxMAXIMIZE_BOX)
168 msflags |= WS_MAXIMIZEBOX;
169 if (style & wxTHICK_FRAME)
170 msflags |= WS_THICKFRAME;
171 if (style & wxSYSTEM_MENU)
172 msflags |= WS_SYSMENU;
173 if ((style & wxMINIMIZE) || (style & wxICONIZE))
174 msflags |= WS_MINIMIZE;
175 if (style & wxMAXIMIZE)
176 msflags |= WS_MAXIMIZE;
177 if (style & wxCAPTION)
178 msflags |= WS_CAPTION;
180 if (style & wxCLIP_CHILDREN)
181 msflags |= WS_CLIPCHILDREN;
183 wxWindow::MSWCreate(m_windowId, parent, wxMDIFrameClassName, this, title, x, y, width, height,
186 wxModelessWindows
.Append(this);
191 wxMDIParentFrame::~wxMDIParentFrame()
195 // TODO: ::DestroyMenu((HMENU)m_windowMenu);
198 if ( m_clientWindow
)
200 if ( m_clientWindow
->OS2GetOldWndProc() )
201 m_clientWindow
->UnsubclassWin();
203 m_clientWindow
->SetHWND(0);
204 delete m_clientWindow
;
208 void wxMDIParentFrame::InternalSetMenuBar()
212 HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
214 m_parentFrameActive = TRUE;
216 InsertWindowMenu(GetClientWindow(), m_hMenu, subMenu);
220 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
224 if ( GetClientWindow() )
227 GetClientSize(&width, &height);
229 GetClientWindow()->SetSize(0, 0, width, height);
234 // Returns the active MDI child window
235 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
237 HWND hWnd
= 0; // TODO: (HWND)::SendMessage(GetWinHwnd(GetClientWindow()),
238 // WM_MDIGETACTIVE, 0, 0L);
242 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
245 // Create the client window class (don't Create the window, just return a new
247 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
249 return new wxMDIClientWindow
;
252 // Responds to colour changes, and passes event on to children.
253 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
255 if ( m_clientWindow
)
257 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
258 m_clientWindow
->Refresh();
264 // ---------------------------------------------------------------------------
266 // ---------------------------------------------------------------------------
268 void wxMDIParentFrame::Cascade()
270 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE, 0, 0);
273 // TODO: add a direction argument (hor/vert)
274 void wxMDIParentFrame::Tile()
276 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE, MDITILE_HORIZONTAL, 0);
279 void wxMDIParentFrame::ArrangeIcons()
281 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE, 0, 0);
284 void wxMDIParentFrame::ActivateNext()
286 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 0);
289 void wxMDIParentFrame::ActivatePrevious()
291 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 1);
294 // ---------------------------------------------------------------------------
295 // the MDI parent frame window proc
296 // ---------------------------------------------------------------------------
298 MRESULT
wxMDIParentFrame::OS2WindowProc(WXUINT message
,
303 bool processed
= FALSE
;
311 WXWORD state, minimized;
313 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
315 processed = HandleActivate(state, minimized != 0, hwnd);
323 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
325 (void)HandleCommand(id, cmd, hwnd);
327 // even if the frame didn't process it, there is no need to try it
328 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
329 // so pretend we processed the message anyhow
333 // always pass this message DefFrameProc(), otherwise MDI menu
334 // commands (and sys commands - more surprizingly!) won't work
335 MSWDefWindowProc(message, wParam, lParam);
339 m_clientWindow = OnCreateClient();
340 // Uses own style for client style
341 if ( !m_clientWindow->CreateClient(this, GetWindowStyleFlag()) )
343 wxLogMessage(_("Failed to create MDI parent frame."));
354 // we erase background ourselves
362 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
364 if ( m_parentFrameActive )
366 processed = HandleMenuSelect(item, flags, hmenu);
368 else if (m_currentChild)
370 processed = m_currentChild->
371 HandleMenuSelect(item, flags, hmenu);
377 // as we don't (usually) resize the MDI client to exactly fit the
378 // client area (we put it below the toolbar, above statusbar &c),
379 // we should not pass this one to DefFrameProc
384 rc
= wxFrame::OS2WindowProc(message
, wParam
, lParam
);
389 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
391 bool processed
= FALSE
;
395 if ( wxWindow::HandleActivate(state, minimized, activate) )
401 // If this window is an MDI parent, we must also send an OnActivate message
402 // to the current child.
403 if ( (m_currentChild != NULL) &&
404 ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) )
406 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_currentChild->GetId());
407 event.SetEventObject( m_currentChild );
408 if ( m_currentChild->GetEventHandler()->ProcessEvent(event) )
415 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
417 // In case it's e.g. a toolbar.
420 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
422 return FALSE
; // Need to get wxWindow for OS/2 up to date: win->OS2Command(cmd, id);
425 // is it one of standard MDI commands?
433 case IDM_WINDOWCASCADE:
435 wParam = MDITILE_SKIPDISABLED;
438 case IDM_WINDOWTILEHOR:
439 wParam |= MDITILE_HORIZONTAL;
442 case IDM_WINDOWTILEVERT:
444 wParam = MDITILE_VERTICAL;
446 wParam |= MDITILE_SKIPDISABLED;
449 case IDM_WINDOWICONS:
450 msg = WM_MDIICONARRANGE;
463 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), msg, wParam, 0);
468 // FIXME VZ: what does this test do??
471 return FALSE
; // Get WndProc to call default proc
474 if ( IsMdiCommandId(id
) )
476 wxWindowList::Node
* node
= GetChildren().GetFirst();
479 wxWindow
* child
= node
->GetData();
480 if ( child
->GetHWND() )
482 long childId
= wxGetWindowId(child
->GetHWND());
483 if (childId
== (long)id
)
485 // TODO: ::SendMessage( GetWinHwnd(GetClientWindow()),
487 // (WPARAM)child->GetHWND(), 0);
491 node
= node
->GetNext();
494 else if ( m_parentFrameActive
)
496 return ProcessCommand(id
);
498 else if ( m_currentChild
)
500 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
504 // this shouldn't happen because it means that our messages are being
505 // lost (they're not sent to the parent frame nor to the children)
506 wxFAIL_MSG(wxT("MDI parent frame is not active, "
507 "yet there is no active MDI child?"));
513 MRESULT
wxMDIParentFrame::OS2DefWindowProc(WXUINT message
,
518 if ( GetClientWindow() )
519 clientWnd
= GetClientWindow()->GetHWND();
523 // TODO: return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam);
527 bool wxMDIParentFrame::OS2TranslateMessage(WXMSG
* msg
)
531 if ( m_currentChild && m_currentChild->GetHWND() &&
532 m_currentChild->OS2TranslateMessage(msg) )
537 if ( m_acceleratorTable.Translate(this, msg) )
542 if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN )
544 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg))
551 // ===========================================================================
553 // ===========================================================================
555 wxMDIChildFrame::wxMDIChildFrame()
559 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
561 const wxString
& title
,
565 const wxString
& name
)
567 m_hDefaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
568 : wxDEFAULT_MDICHILDFRAME_ICON
);
575 m_windowId
= (int)NewControlId();
579 parent
->AddChild(this);
593 mcs.szClass = wxMDIChildFrameClassName;
595 mcs.hOwner = wxGetInstance();
599 mcs.x = CW_USEDEFAULT;
604 mcs.y = CW_USEDEFAULT;
609 mcs.cx = CW_USEDEFAULT;
614 mcs.cy = CW_USEDEFAULT;
616 DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN;
617 if (style & wxMINIMIZE_BOX)
618 msflags |= WS_MINIMIZEBOX;
619 if (style & wxMAXIMIZE_BOX)
620 msflags |= WS_MAXIMIZEBOX;
621 if (style & wxTHICK_FRAME)
622 msflags |= WS_THICKFRAME;
623 if (style & wxSYSTEM_MENU)
624 msflags |= WS_SYSMENU;
625 if ((style & wxMINIMIZE) || (style & wxICONIZE))
626 msflags |= WS_MINIMIZE;
627 if (style & wxMAXIMIZE)
628 msflags |= WS_MAXIMIZE;
629 if (style & wxCAPTION)
630 msflags |= WS_CAPTION;
636 DWORD Return
= 0; // SendMessage(GetWinHwnd(parent->GetClientWindow()),
637 // WM_MDICREATE, 0, (LONG)(LPSTR)&mcs);
638 m_hWnd
= (WXHWND
)Return
;
641 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
643 // VZ: what's this? an act of piracy?
644 //SetWindowLong(GetHwnd(), 0, (long)this);
646 wxModelessWindows
.Append(this);
650 wxMDIChildFrame::~wxMDIChildFrame()
655 // Set the client size (i.e. leave the calculation of borders etc.
657 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
659 HWND hWnd
= GetHwnd();
664 ::GetClientRect(hWnd, &rect);
667 GetWindowRect(hWnd, &rect2);
669 // Find the difference between the entire window (title bar and all)
670 // and the client area; add this to the new client size to move the
672 int actual_width = rect2.right - rect2.left - rect.right + width;
673 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
678 GetStatusBar()->GetSize(&sx, &sy);
683 point.x = rect2.left;
686 // If there's an MDI parent, must subtract the parent's top left corner
687 // since MoveWindow moves relative to the parent
688 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
689 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
691 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
693 wxSizeEvent event(wxSize(width, height), m_windowId);
694 event.SetEventObject( this );
695 GetEventHandler()->ProcessEvent(event);
699 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
704 GetWindowRect(GetHwnd(), &rect);
709 // Since we now have the absolute screen coords,
710 // if there's a parent we must subtract its top left corner
711 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
712 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
719 void wxMDIChildFrame::InternalSetMenuBar()
724 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
726 HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
728 InsertWindowMenu(parent->GetClientWindow(), m_hMenu, subMenu);
730 parent->m_parentFrameActive = FALSE;
734 // ---------------------------------------------------------------------------
736 // ---------------------------------------------------------------------------
738 void wxMDIChildFrame::Maximize(bool maximize
)
740 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
743 if ( parent && parent->GetClientWindow() )
745 ::SendMessage(GetWinHwnd(parent->GetClientWindow()),
746 maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE,
747 (WPARAM)GetHwnd(), 0);
752 void wxMDIChildFrame::Restore()
756 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
757 if ( parent && parent->GetClientWindow() )
759 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE,
760 (WPARAM) GetHwnd(), 0);
765 void wxMDIChildFrame::Activate()
769 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
770 if ( parent && parent->GetClientWindow() )
772 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE,
773 (WPARAM) GetHwnd(), 0);
778 // ---------------------------------------------------------------------------
779 // MDI window proc and message handlers
780 // ---------------------------------------------------------------------------
782 MRESULT
wxMDIChildFrame::OS2WindowProc(WXUINT message
,
787 bool processed
= FALSE
;
797 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
800 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
804 case WM_GETMINMAXINFO:
805 // let the default window proc calculate the size of MDI children
806 // frames because it is based on the size of the MDI client window,
807 // not on the values specified in wxWindow m_min/max variables
808 return MSWDefWindowProc(message, wParam, lParam);
813 WXHWND hwndAct, hwndDeact;
814 UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact);
816 processed = HandleMDIActivate(act, hwndAct, hwndDeact);
821 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
822 // scrollbars if necessary
827 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
829 MSWDefWindowProc(message, wParam, lParam);
833 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
834 // the message (the base class version does not)
835 return MSWDefWindowProc(message, wParam, lParam);
837 case WM_WINDOWPOSCHANGING:
838 processed = HandleWindowPosChanging((LPWINDOWPOS)lParam);
843 rc
= wxFrame::OS2WindowProc(message
, wParam
, lParam
);
848 bool wxMDIChildFrame::HandleSize(int x
, int y
, WXUINT id
)
850 HWND hwnd
= GetHwnd();
852 if ( !hwnd
|| hwnd
== invalidHandle
)
873 // forward WM_SIZE to status bar control
874 #if wxUSE_NATIVE_STATUSBAR
875 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
877 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
878 event.SetEventObject( m_frameStatusBar );
880 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
882 #endif // wxUSE_NATIVE_STATUSBAR
887 return wxWindow::HandleSize(x, y, id);
897 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
899 // In case it's e.g. a toolbar.
902 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
904 // Fix dependent stuff return win->OS2Command(cmd, id);
907 if (wxCurrentPopupMenu
)
909 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
910 wxCurrentPopupMenu
= NULL
;
911 // Fix dependent stuff if (popupMenu->OS2Command(cmd, id))
915 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
926 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
930 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
936 if ( m_hWnd
== hwndAct
)
939 parent
->m_currentChild
= this;
941 HMENU child_menu
= (HMENU
)GetWinMenu();
944 parent
->m_parentFrameActive
= FALSE
;
946 menuToSet
= child_menu
;
949 else if ( m_hWnd
== hwndDeact
)
951 wxASSERT_MSG( parent
->m_currentChild
== this,
952 wxT("can't deactivate MDI child which wasn't active!") );
955 parent
->m_currentChild
= NULL
;
957 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
960 parent
->m_parentFrameActive
= TRUE
;
962 menuToSet
= parent_menu
;
967 // we have nothing to with it
973 HMENU subMenu
= 0; // TODO: GetSubMenu((HMENU) parent->GetWindowMenu(), 0);
975 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
978 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
979 event
.SetEventObject( this );
981 return GetEventHandler()->ProcessEvent(event
);
984 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
986 // WINDOWPOS *lpPos = (WINDOWPOS *)pos;
990 // ---------------------------------------------------------------------------
991 // MDI specific message translation/preprocessing
992 // ---------------------------------------------------------------------------
994 MRESULT
wxMDIChildFrame::OS2DefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
998 return DefMDIChildProc(GetHwnd(),
999 (UINT)message, (WPARAM)wParam, (LPARAM)lParam);
1004 bool wxMDIChildFrame::OS2TranslateMessage(WXMSG
* msg
)
1007 return m_acceleratorTable
.Translate(GetParent()->GetHWND(), msg
);
1010 #endif //wxUSE_ACCEL
1014 // ---------------------------------------------------------------------------
1016 // ---------------------------------------------------------------------------
1018 void wxMDIChildFrame::OS2DestroyWindow()
1020 // get wxWindow up to date OS2DetachWindowMenu();
1021 invalidHandle
= GetHwnd();
1023 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1025 // Must make sure this handle is invalidated (set to NULL) since all sorts
1026 // of things could happen after the child client is destroyed, but before
1027 // the wxFrame is destroyed.
1029 HWND oldHandle
= (HWND
)GetHWND();
1030 // TODO: SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY,
1031 // (WPARAM)oldHandle, 0);
1036 // TODO: ::DestroyMenu((HMENU) m_hMenu);
1042 // Change the client window's extended style so we don't get a client edge
1043 // style when a child is maximised (a double border looks silly.)
1044 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1049 // ===========================================================================
1050 // wxMDIClientWindow: the window of predefined (by Windows) class which
1051 // contains the child frames
1052 // ===========================================================================
1054 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1056 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1060 CLIENTCREATESTRUCT ccs;
1061 m_windowStyle = style;
1064 ccs.hWindowMenu = (HMENU)parent->GetWindowMenu();
1065 ccs.idFirstChild = wxFIRST_MDI_CHILD;
1067 DWORD msStyle = WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN;
1068 if ( style & wxHSCROLL )
1069 msStyle |= WS_HSCROLL;
1070 if ( style & wxVSCROLL )
1071 msStyle |= WS_VSCROLL;
1073 #if defined(__WIN95__)
1074 DWORD exStyle = WS_EX_CLIENTEDGE;
1080 m_hWnd = (WXHWND)::CreateWindowEx
1090 (LPSTR)(LPCLIENTCREATESTRUCT)&ccs);
1093 wxLogLastError("CreateWindowEx(MDI client)");
1098 SubclassWin(m_hWnd);
1104 // Explicitly call default scroll behaviour
1105 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1107 // Note: for client windows, the scroll position is not set in
1108 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1109 // scroll position we're at.
1110 // This makes it hard to paint patterns or bitmaps in the background,
1111 // and have the client area scrollable as well.
1113 if ( event
.GetOrientation() == wxHORIZONTAL
)
1114 m_scrollX
= event
.GetPosition(); // Always returns zero!
1116 m_scrollY
= event
.GetPosition(); // Always returns zero!
1121 // ---------------------------------------------------------------------------
1122 // non member functions
1123 // ---------------------------------------------------------------------------
1125 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1129 ::SendMessage(GetWinHwnd(win), WM_MDISETMENU,
1130 (WPARAM)hmenuFrame, (LPARAM)hmenuWindow);
1131 // update menu bar of the parent window
1132 wxWindow *parent = win->GetParent();
1133 wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") );
1135 ::DrawMenuBar(GetWinHwnd(parent));
1139 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1142 // Try to insert Window menu in front of Help, otherwise append it.
1143 HMENU hmenu = (HMENU)menu;
1144 int N = GetMenuItemCount(hmenu);
1145 bool success = FALSE;
1146 for ( int i = 0; i < N; i++ )
1149 int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION);
1152 wxLogLastError(wxT("GetMenuString"));
1157 if ( wxStripMenuCodes(wxString(buf)).IsSameAs(wxT("Help")) )
1160 ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
1161 (UINT)subMenu, wxT("&Window"));
1168 ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, wxT("&Window"));
1170 MDISetMenu(win, hmenu, subMenu);
1174 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1175 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1178 *hwndAct
= (WXHWND
)lParam
;
1179 *hwndDeact
= (WXHWND
)wParam
;