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;
56 static const int IDM_WINDOWPREV
= 4006;
58 // This range gives a maximum of 500 MDI children. Should be enough :-)
59 static const int wxFIRST_MDI_CHILD
= 4100;
60 static const int wxLAST_MDI_CHILD
= 4600;
62 // Status border dimensions
63 static const int wxTHICK_LINE_BORDER
= 3;
64 static const int wxTHICK_LINE_WIDTH
= 1;
66 // ---------------------------------------------------------------------------
68 // ---------------------------------------------------------------------------
70 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
71 // of the parent of win (which is supposed to be the MDI client window)
72 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
74 // insert the window menu (subMenu) into menu just before "Help" submenu or at
75 // the very end if not found
76 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
78 // is this an id of an MDI child?
79 inline bool IsMdiCommandId(int id
)
81 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
84 // unpack the parameters of WM_MDIACTIVATE message
85 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
86 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
88 // return the HMENU of the MDI menu
89 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
91 wxMenu
*menu
= frame
->GetWindowMenu();
92 return menu
? GetHmenuOf(menu
) : 0;
95 // ===========================================================================
97 // ===========================================================================
99 // ---------------------------------------------------------------------------
101 // ---------------------------------------------------------------------------
103 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
104 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
105 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
107 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
108 EVT_SIZE(wxMDIParentFrame::OnSize
)
109 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
112 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
113 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
116 // ===========================================================================
117 // wxMDIParentFrame: the frame which contains the client window which manages
119 // ===========================================================================
121 wxMDIParentFrame::wxMDIParentFrame()
123 m_clientWindow
= NULL
;
124 m_currentChild
= NULL
;
126 m_parentFrameActive
= TRUE
;
129 bool wxMDIParentFrame::Create(wxWindow
*parent
,
131 const wxString
& title
,
135 const wxString
& name
)
137 m_hDefaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
139 m_clientWindow
= NULL
;
140 m_currentChild
= NULL
;
142 m_parentFrameActive
= TRUE
;
145 wxTopLevelWindows
.Append(this);
148 wxWindowBase::Show(TRUE
); // MDI child frame starts off shown
149 m_windowStyle
= style
;
151 if (parent
) parent
->AddChild(this);
156 m_windowId
= (int)NewControlId();
163 // TODO: m_windowMenu = (WXHMENU) ::LoadMenu(wxGetInstance(), wxT("wxWindowMenu"));
165 DWORD msflags = WS_OVERLAPPED;
166 if (style & wxMINIMIZE_BOX)
167 msflags |= WS_MINIMIZEBOX;
168 if (style & wxMAXIMIZE_BOX)
169 msflags |= WS_MAXIMIZEBOX;
170 if (style & wxTHICK_FRAME)
171 msflags |= WS_THICKFRAME;
172 if (style & wxSYSTEM_MENU)
173 msflags |= WS_SYSMENU;
174 if ((style & wxMINIMIZE) || (style & wxICONIZE))
175 msflags |= WS_MINIMIZE;
176 if (style & wxMAXIMIZE)
177 msflags |= WS_MAXIMIZE;
178 if (style & wxCAPTION)
179 msflags |= WS_CAPTION;
181 if (style & wxCLIP_CHILDREN)
182 msflags |= WS_CLIPCHILDREN;
184 wxWindow::MSWCreate(m_windowId, parent, wxMDIFrameClassName, this, title, x, y, width, height,
187 wxModelessWindows
.Append(this);
192 wxMDIParentFrame::~wxMDIParentFrame()
196 // TODO: ::DestroyMenu((HMENU)m_windowMenu);
199 if ( m_clientWindow
)
201 if ( m_clientWindow
->OS2GetOldWndProc() )
202 m_clientWindow
->UnsubclassWin();
204 m_clientWindow
->SetHWND(0);
205 delete m_clientWindow
;
209 void wxMDIParentFrame::InternalSetMenuBar()
213 HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
215 m_parentFrameActive = TRUE;
217 InsertWindowMenu(GetClientWindow(), m_hMenu, subMenu);
221 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
225 if ( GetClientWindow() )
228 GetClientSize(&width, &height);
230 GetClientWindow()->SetSize(0, 0, width, height);
235 // Returns the active MDI child window
236 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
238 HWND hWnd
= 0; // TODO: (HWND)::SendMessage(GetWinHwnd(GetClientWindow()),
239 // WM_MDIGETACTIVE, 0, 0L);
243 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
246 // Create the client window class (don't Create the window, just return a new
248 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
250 return new wxMDIClientWindow
;
253 // Responds to colour changes, and passes event on to children.
254 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
256 if ( m_clientWindow
)
258 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
259 m_clientWindow
->Refresh();
265 // ---------------------------------------------------------------------------
267 // ---------------------------------------------------------------------------
269 void wxMDIParentFrame::Cascade()
271 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE, 0, 0);
274 // TODO: add a direction argument (hor/vert)
275 void wxMDIParentFrame::Tile()
277 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE, MDITILE_HORIZONTAL, 0);
280 void wxMDIParentFrame::ArrangeIcons()
282 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE, 0, 0);
285 void wxMDIParentFrame::ActivateNext()
287 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 0);
290 void wxMDIParentFrame::ActivatePrevious()
292 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 1);
295 // ---------------------------------------------------------------------------
296 // the MDI parent frame window proc
297 // ---------------------------------------------------------------------------
299 MRESULT
wxMDIParentFrame::OS2WindowProc(WXUINT message
,
304 bool processed
= FALSE
;
312 WXWORD state, minimized;
314 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
316 processed = HandleActivate(state, minimized != 0, hwnd);
324 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
326 (void)HandleCommand(id, cmd, hwnd);
328 // even if the frame didn't process it, there is no need to try it
329 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
330 // so pretend we processed the message anyhow
334 // always pass this message DefFrameProc(), otherwise MDI menu
335 // commands (and sys commands - more surprizingly!) won't work
336 MSWDefWindowProc(message, wParam, lParam);
340 m_clientWindow = OnCreateClient();
341 // Uses own style for client style
342 if ( !m_clientWindow->CreateClient(this, GetWindowStyleFlag()) )
344 wxLogMessage(_("Failed to create MDI parent frame."));
355 // we erase background ourselves
363 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
365 if ( m_parentFrameActive )
367 processed = HandleMenuSelect(item, flags, hmenu);
369 else if (m_currentChild)
371 processed = m_currentChild->
372 HandleMenuSelect(item, flags, hmenu);
378 // as we don't (usually) resize the MDI client to exactly fit the
379 // client area (we put it below the toolbar, above statusbar &c),
380 // we should not pass this one to DefFrameProc
385 rc
= wxFrame::OS2WindowProc(message
, wParam
, lParam
);
390 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
392 bool processed
= FALSE
;
396 if ( wxWindow::HandleActivate(state, minimized, activate) )
402 // If this window is an MDI parent, we must also send an OnActivate message
403 // to the current child.
404 if ( (m_currentChild != NULL) &&
405 ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) )
407 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_currentChild->GetId());
408 event.SetEventObject( m_currentChild );
409 if ( m_currentChild->GetEventHandler()->ProcessEvent(event) )
416 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
418 // In case it's e.g. a toolbar.
421 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
423 return FALSE
; // Need to get wxWindow for OS/2 up to date: win->OS2Command(cmd, id);
426 // is it one of standard MDI commands?
434 case IDM_WINDOWCASCADE:
436 wParam = MDITILE_SKIPDISABLED;
439 case IDM_WINDOWTILEHOR:
440 wParam |= MDITILE_HORIZONTAL;
443 case IDM_WINDOWTILEVERT:
445 wParam = MDITILE_VERTICAL;
447 wParam |= MDITILE_SKIPDISABLED;
450 case IDM_WINDOWICONS:
451 msg = WM_MDIICONARRANGE;
464 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), msg, wParam, 0);
469 // FIXME VZ: what does this test do??
472 return FALSE
; // Get WndProc to call default proc
475 if ( IsMdiCommandId(id
) )
477 wxWindowList::Node
* node
= GetChildren().GetFirst();
480 wxWindow
* child
= node
->GetData();
481 if ( child
->GetHWND() )
483 long childId
= wxGetWindowId(child
->GetHWND());
484 if (childId
== (long)id
)
486 // TODO: ::SendMessage( GetWinHwnd(GetClientWindow()),
488 // (WPARAM)child->GetHWND(), 0);
492 node
= node
->GetNext();
495 else if ( m_parentFrameActive
)
497 return ProcessCommand(id
);
499 else if ( m_currentChild
)
501 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
505 // this shouldn't happen because it means that our messages are being
506 // lost (they're not sent to the parent frame nor to the children)
507 wxFAIL_MSG(wxT("MDI parent frame is not active, "
508 "yet there is no active MDI child?"));
514 MRESULT
wxMDIParentFrame::OS2DefWindowProc(WXUINT message
,
519 if ( GetClientWindow() )
520 clientWnd
= GetClientWindow()->GetHWND();
524 // TODO: return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam);
528 bool wxMDIParentFrame::OS2TranslateMessage(WXMSG
* msg
)
532 if ( m_currentChild && m_currentChild->GetHWND() &&
533 m_currentChild->OS2TranslateMessage(msg) )
538 if ( m_acceleratorTable.Translate(this, msg) )
543 if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN )
545 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg))
552 // ===========================================================================
554 // ===========================================================================
556 wxMDIChildFrame::wxMDIChildFrame()
560 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
562 const wxString
& title
,
566 const wxString
& name
)
568 m_hDefaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
569 : wxDEFAULT_MDICHILDFRAME_ICON
);
576 m_windowId
= (int)NewControlId();
580 parent
->AddChild(this);
594 mcs.szClass = wxMDIChildFrameClassName;
596 mcs.hOwner = wxGetInstance();
600 mcs.x = CW_USEDEFAULT;
605 mcs.y = CW_USEDEFAULT;
610 mcs.cx = CW_USEDEFAULT;
615 mcs.cy = CW_USEDEFAULT;
617 DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN;
618 if (style & wxMINIMIZE_BOX)
619 msflags |= WS_MINIMIZEBOX;
620 if (style & wxMAXIMIZE_BOX)
621 msflags |= WS_MAXIMIZEBOX;
622 if (style & wxTHICK_FRAME)
623 msflags |= WS_THICKFRAME;
624 if (style & wxSYSTEM_MENU)
625 msflags |= WS_SYSMENU;
626 if ((style & wxMINIMIZE) || (style & wxICONIZE))
627 msflags |= WS_MINIMIZE;
628 if (style & wxMAXIMIZE)
629 msflags |= WS_MAXIMIZE;
630 if (style & wxCAPTION)
631 msflags |= WS_CAPTION;
637 DWORD Return
= 0; // SendMessage(GetWinHwnd(parent->GetClientWindow()),
638 // WM_MDICREATE, 0, (LONG)(LPSTR)&mcs);
639 m_hWnd
= (WXHWND
)Return
;
642 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
644 // VZ: what's this? an act of piracy?
645 //SetWindowLong(GetHwnd(), 0, (long)this);
647 wxModelessWindows
.Append(this);
651 wxMDIChildFrame::~wxMDIChildFrame()
656 // Set the client size (i.e. leave the calculation of borders etc.
658 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
660 HWND hWnd
= GetHwnd();
665 ::GetClientRect(hWnd, &rect);
668 GetWindowRect(hWnd, &rect2);
670 // Find the difference between the entire window (title bar and all)
671 // and the client area; add this to the new client size to move the
673 int actual_width = rect2.right - rect2.left - rect.right + width;
674 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
679 GetStatusBar()->GetSize(&sx, &sy);
684 point.x = rect2.left;
687 // If there's an MDI parent, must subtract the parent's top left corner
688 // since MoveWindow moves relative to the parent
689 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
690 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
692 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
694 wxSizeEvent event(wxSize(width, height), m_windowId);
695 event.SetEventObject( this );
696 GetEventHandler()->ProcessEvent(event);
700 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
705 GetWindowRect(GetHwnd(), &rect);
710 // Since we now have the absolute screen coords,
711 // if there's a parent we must subtract its top left corner
712 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
713 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
720 void wxMDIChildFrame::InternalSetMenuBar()
725 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
727 HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
729 InsertWindowMenu(parent->GetClientWindow(), m_hMenu, subMenu);
731 parent->m_parentFrameActive = FALSE;
735 // ---------------------------------------------------------------------------
737 // ---------------------------------------------------------------------------
739 void wxMDIChildFrame::Maximize(bool maximize
)
741 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
744 if ( parent && parent->GetClientWindow() )
746 ::SendMessage(GetWinHwnd(parent->GetClientWindow()),
747 maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE,
748 (WPARAM)GetHwnd(), 0);
753 void wxMDIChildFrame::Restore()
757 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
758 if ( parent && parent->GetClientWindow() )
760 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE,
761 (WPARAM) GetHwnd(), 0);
766 void wxMDIChildFrame::Activate()
770 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
771 if ( parent && parent->GetClientWindow() )
773 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE,
774 (WPARAM) GetHwnd(), 0);
779 // ---------------------------------------------------------------------------
780 // MDI window proc and message handlers
781 // ---------------------------------------------------------------------------
783 MRESULT
wxMDIChildFrame::OS2WindowProc(WXUINT message
,
788 bool processed
= FALSE
;
798 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
801 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
805 case WM_GETMINMAXINFO:
806 // let the default window proc calculate the size of MDI children
807 // frames because it is based on the size of the MDI client window,
808 // not on the values specified in wxWindow m_min/max variables
809 return MSWDefWindowProc(message, wParam, lParam);
814 WXHWND hwndAct, hwndDeact;
815 UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact);
817 processed = HandleMDIActivate(act, hwndAct, hwndDeact);
822 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
823 // scrollbars if necessary
828 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
830 MSWDefWindowProc(message, wParam, lParam);
834 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
835 // the message (the base class version does not)
836 return MSWDefWindowProc(message, wParam, lParam);
838 case WM_WINDOWPOSCHANGING:
839 processed = HandleWindowPosChanging((LPWINDOWPOS)lParam);
844 rc
= wxFrame::OS2WindowProc(message
, wParam
, lParam
);
849 bool wxMDIChildFrame::HandleSize(int x
, int y
, WXUINT id
)
851 HWND hwnd
= GetHwnd();
853 if ( !hwnd
|| hwnd
== invalidHandle
)
874 // forward WM_SIZE to status bar control
875 #if wxUSE_NATIVE_STATUSBAR
876 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
878 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
879 event.SetEventObject( m_frameStatusBar );
881 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
883 #endif // wxUSE_NATIVE_STATUSBAR
888 return wxWindow::HandleSize(x, y, id);
898 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
900 // In case it's e.g. a toolbar.
903 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
905 // Fix dependent stuff return win->OS2Command(cmd, id);
908 if (wxCurrentPopupMenu
)
910 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
911 wxCurrentPopupMenu
= NULL
;
912 // Fix dependent stuff if (popupMenu->OS2Command(cmd, id))
916 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
927 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
931 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
937 if ( m_hWnd
== hwndAct
)
940 parent
->m_currentChild
= this;
942 HMENU child_menu
= (HMENU
)GetWinMenu();
945 parent
->m_parentFrameActive
= FALSE
;
947 menuToSet
= child_menu
;
950 else if ( m_hWnd
== hwndDeact
)
952 wxASSERT_MSG( parent
->m_currentChild
== this,
953 wxT("can't deactivate MDI child which wasn't active!") );
956 parent
->m_currentChild
= NULL
;
958 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
961 parent
->m_parentFrameActive
= TRUE
;
963 menuToSet
= parent_menu
;
968 // we have nothing to with it
974 HMENU subMenu
= 0; // TODO: GetSubMenu((HMENU) parent->GetWindowMenu(), 0);
976 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
979 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
980 event
.SetEventObject( this );
982 return GetEventHandler()->ProcessEvent(event
);
985 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
987 // WINDOWPOS *lpPos = (WINDOWPOS *)pos;
991 // ---------------------------------------------------------------------------
992 // MDI specific message translation/preprocessing
993 // ---------------------------------------------------------------------------
995 MRESULT
wxMDIChildFrame::OS2DefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
999 return DefMDIChildProc(GetHwnd(),
1000 (UINT)message, (WPARAM)wParam, (LPARAM)lParam);
1005 bool wxMDIChildFrame::OS2TranslateMessage(WXMSG
* msg
)
1008 return m_acceleratorTable
.Translate(GetParent()->GetHWND(), msg
);
1011 #endif //wxUSE_ACCEL
1015 // ---------------------------------------------------------------------------
1017 // ---------------------------------------------------------------------------
1019 void wxMDIChildFrame::OS2DestroyWindow()
1021 // get wxWindow up to date OS2DetachWindowMenu();
1022 invalidHandle
= GetHwnd();
1024 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1026 // Must make sure this handle is invalidated (set to NULL) since all sorts
1027 // of things could happen after the child client is destroyed, but before
1028 // the wxFrame is destroyed.
1030 HWND oldHandle
= (HWND
)GetHWND();
1031 // TODO: SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY,
1032 // (WPARAM)oldHandle, 0);
1037 // TODO: ::DestroyMenu((HMENU) m_hMenu);
1043 // Change the client window's extended style so we don't get a client edge
1044 // style when a child is maximised (a double border looks silly.)
1045 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1050 // ===========================================================================
1051 // wxMDIClientWindow: the window of predefined (by Windows) class which
1052 // contains the child frames
1053 // ===========================================================================
1055 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1057 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1061 CLIENTCREATESTRUCT ccs;
1062 m_windowStyle = style;
1065 ccs.hWindowMenu = (HMENU)parent->GetWindowMenu();
1066 ccs.idFirstChild = wxFIRST_MDI_CHILD;
1068 DWORD msStyle = WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN;
1069 if ( style & wxHSCROLL )
1070 msStyle |= WS_HSCROLL;
1071 if ( style & wxVSCROLL )
1072 msStyle |= WS_VSCROLL;
1074 #if defined(__WIN95__)
1075 DWORD exStyle = WS_EX_CLIENTEDGE;
1081 m_hWnd = (WXHWND)::CreateWindowEx
1091 (LPSTR)(LPCLIENTCREATESTRUCT)&ccs);
1094 wxLogLastError("CreateWindowEx(MDI client)");
1099 SubclassWin(m_hWnd);
1105 // Explicitly call default scroll behaviour
1106 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1108 // Note: for client windows, the scroll position is not set in
1109 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1110 // scroll position we're at.
1111 // This makes it hard to paint patterns or bitmaps in the background,
1112 // and have the client area scrollable as well.
1114 if ( event
.GetOrientation() == wxHORIZONTAL
)
1115 m_scrollX
= event
.GetPosition(); // Always returns zero!
1117 m_scrollY
= event
.GetPosition(); // Always returns zero!
1122 // ---------------------------------------------------------------------------
1123 // non member functions
1124 // ---------------------------------------------------------------------------
1126 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1130 ::SendMessage(GetWinHwnd(win), WM_MDISETMENU,
1131 (WPARAM)hmenuFrame, (LPARAM)hmenuWindow);
1132 // update menu bar of the parent window
1133 wxWindow *parent = win->GetParent();
1134 wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") );
1136 ::DrawMenuBar(GetWinHwnd(parent));
1140 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1143 // Try to insert Window menu in front of Help, otherwise append it.
1144 HMENU hmenu = (HMENU)menu;
1145 int N = GetMenuItemCount(hmenu);
1146 bool success = FALSE;
1147 for ( int i = 0; i < N; i++ )
1150 int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION);
1153 wxLogLastError(wxT("GetMenuString"));
1158 if ( wxStripMenuCodes(wxString(buf)).IsSameAs(wxT("Help")) )
1161 ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
1162 (UINT)subMenu, wxT("&Window"));
1169 ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, wxT("&Window"));
1171 MDISetMenu(win, hmenu, subMenu);
1175 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1176 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1179 *hwndAct
= (WXHWND
)lParam
;
1180 *hwndDeact
= (WXHWND
)wParam
;