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 wxChar wxMDIFrameClassName
[];
41 extern wxChar wxMDIChildFrameClassName
[];
42 extern wxWindow
*wxWndHook
; // from window.cpp
44 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
46 static HWND invalidHandle
= 0;
48 // ---------------------------------------------------------------------------
50 // ---------------------------------------------------------------------------
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;
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;
63 // Status border dimensions
64 static const int wxTHICK_LINE_BORDER
= 3;
65 static const int wxTHICK_LINE_WIDTH
= 1;
67 // ---------------------------------------------------------------------------
69 // ---------------------------------------------------------------------------
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
);
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
);
79 // is this an id of an MDI child?
80 inline bool IsMdiCommandId(int id
)
82 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
85 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
86 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
88 // ===========================================================================
90 // ===========================================================================
92 // ---------------------------------------------------------------------------
94 // ---------------------------------------------------------------------------
96 #if !USE_SHARED_LIBRARY
97 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
98 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
99 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
100 #endif // USE_SHARED_LIBRARY
102 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
103 EVT_SIZE(wxMDIParentFrame::OnSize
)
104 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
107 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
108 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
111 // ===========================================================================
112 // wxMDIParentFrame: the frame which contains the client window which manages
114 // ===========================================================================
116 wxMDIParentFrame::wxMDIParentFrame()
118 m_clientWindow
= NULL
;
119 m_currentChild
= NULL
;
121 m_parentFrameActive
= TRUE
;
124 bool wxMDIParentFrame::Create(wxWindow
*parent
,
126 const wxString
& title
,
130 const wxString
& name
)
132 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
134 m_clientWindow
= NULL
;
135 m_currentChild
= NULL
;
137 m_parentFrameActive
= TRUE
;
140 wxTopLevelWindows
.Append(this);
143 m_windowStyle
= style
;
145 if (parent
) parent
->AddChild(this);
150 m_windowId
= (int)NewControlId();
157 // TODO: m_windowMenu = (WXHMENU) ::LoadMenu(wxGetInstance(), wxT("wxWindowMenu"));
159 DWORD msflags = WS_OVERLAPPED;
160 if (style & wxMINIMIZE_BOX)
161 msflags |= WS_MINIMIZEBOX;
162 if (style & wxMAXIMIZE_BOX)
163 msflags |= WS_MAXIMIZEBOX;
164 if (style & wxTHICK_FRAME)
165 msflags |= WS_THICKFRAME;
166 if (style & wxSYSTEM_MENU)
167 msflags |= WS_SYSMENU;
168 if ((style & wxMINIMIZE) || (style & wxICONIZE))
169 msflags |= WS_MINIMIZE;
170 if (style & wxMAXIMIZE)
171 msflags |= WS_MAXIMIZE;
172 if (style & wxCAPTION)
173 msflags |= WS_CAPTION;
175 if (style & wxCLIP_CHILDREN)
176 msflags |= WS_CLIPCHILDREN;
178 wxWindow::MSWCreate(m_windowId, parent, wxMDIFrameClassName, this, title, x, y, width, height,
181 wxModelessWindows
.Append(this);
186 wxMDIParentFrame::~wxMDIParentFrame()
190 // TODO: ::DestroyMenu((HMENU)m_windowMenu);
193 if ( m_clientWindow
)
195 if ( m_clientWindow
->OS2GetOldWndProc() )
196 m_clientWindow
->UnsubclassWin();
198 m_clientWindow
->SetHWND(0);
199 delete m_clientWindow
;
203 void wxMDIParentFrame::InternalSetMenuBar()
207 HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
209 m_parentFrameActive = TRUE;
211 InsertWindowMenu(GetClientWindow(), m_hMenu, subMenu);
215 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
219 if ( GetClientWindow() )
222 GetClientSize(&width, &height);
224 GetClientWindow()->SetSize(0, 0, width, height);
229 // Returns the active MDI child window
230 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
232 HWND hWnd
= 0; // TODO: (HWND)::SendMessage(GetWinHwnd(GetClientWindow()),
233 // WM_MDIGETACTIVE, 0, 0L);
237 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
240 // Create the client window class (don't Create the window, just return a new
242 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
244 return new wxMDIClientWindow
;
247 // Responds to colour changes, and passes event on to children.
248 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
250 if ( m_clientWindow
)
252 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
253 m_clientWindow
->Refresh();
259 // ---------------------------------------------------------------------------
261 // ---------------------------------------------------------------------------
263 void wxMDIParentFrame::Cascade()
265 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE, 0, 0);
268 // TODO: add a direction argument (hor/vert)
269 void wxMDIParentFrame::Tile()
271 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE, MDITILE_HORIZONTAL, 0);
274 void wxMDIParentFrame::ArrangeIcons()
276 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE, 0, 0);
279 void wxMDIParentFrame::ActivateNext()
281 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 0);
284 void wxMDIParentFrame::ActivatePrevious()
286 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 1);
289 // ---------------------------------------------------------------------------
290 // the MDI parent frame window proc
291 // ---------------------------------------------------------------------------
293 MRESULT
wxMDIParentFrame::OS2WindowProc(HWND hwnd
,
299 bool processed
= FALSE
;
307 WXWORD state, minimized;
309 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
311 processed = HandleActivate(state, minimized != 0, hwnd);
319 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
321 (void)HandleCommand(id, cmd, hwnd);
323 // even if the frame didn't process it, there is no need to try it
324 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
325 // so pretend we processed the message anyhow
329 // always pass this message DefFrameProc(), otherwise MDI menu
330 // commands (and sys commands - more surprizingly!) won't work
331 MSWDefWindowProc(message, wParam, lParam);
335 m_clientWindow = OnCreateClient();
336 // Uses own style for client style
337 if ( !m_clientWindow->CreateClient(this, GetWindowStyleFlag()) )
339 wxLogMessage(_("Failed to create MDI parent frame."));
350 // we erase background ourselves
358 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
360 if ( m_parentFrameActive )
362 processed = HandleMenuSelect(item, flags, hmenu);
364 else if (m_currentChild)
366 processed = m_currentChild->
367 HandleMenuSelect(item, flags, hmenu);
373 // as we don't (usually) resize the MDI client to exactly fit the
374 // client area (we put it below the toolbar, above statusbar &c),
375 // we should not pass this one to DefFrameProc
380 rc
= wxFrame::OS2WindowProc(hwnd
, message
, wParam
, lParam
);
385 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
387 bool processed
= FALSE
;
391 if ( wxWindow::HandleActivate(state, minimized, activate) )
397 // If this window is an MDI parent, we must also send an OnActivate message
398 // to the current child.
399 if ( (m_currentChild != NULL) &&
400 ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) )
402 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_currentChild->GetId());
403 event.SetEventObject( m_currentChild );
404 if ( m_currentChild->GetEventHandler()->ProcessEvent(event) )
411 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
413 // In case it's e.g. a toolbar.
416 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
418 return FALSE
; // Need to get wxWindow for OS/2 up to date: win->OS2Command(cmd, id);
421 // is it one of standard MDI commands?
429 case IDM_WINDOWCASCADE:
431 wParam = MDITILE_SKIPDISABLED;
434 case IDM_WINDOWTILEHOR:
435 wParam |= MDITILE_HORIZONTAL;
438 case IDM_WINDOWTILEVERT:
440 wParam = MDITILE_VERTICAL;
442 wParam |= MDITILE_SKIPDISABLED;
445 case IDM_WINDOWICONS:
446 msg = WM_MDIICONARRANGE;
459 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), msg, wParam, 0);
464 // FIXME VZ: what does this test do??
467 return FALSE
; // Get WndProc to call default proc
470 if ( IsMdiCommandId(id
) )
472 wxWindowList::Node
* node
= GetChildren().GetFirst();
475 wxWindow
* child
= node
->GetData();
476 if ( child
->GetHWND() )
478 long childId
= wxGetWindowId(child
->GetHWND());
479 if (childId
== (long)id
)
481 // TODO: ::SendMessage( GetWinHwnd(GetClientWindow()),
483 // (WPARAM)child->GetHWND(), 0);
487 node
= node
->GetNext();
490 else if ( m_parentFrameActive
)
492 return ProcessCommand(id
);
494 else if ( m_currentChild
)
496 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
500 // this shouldn't happen because it means that our messages are being
501 // lost (they're not sent to the parent frame nor to the children)
502 wxFAIL_MSG(wxT("MDI parent frame is not active, "
503 "yet there is no active MDI child?"));
509 MRESULT
wxMDIParentFrame::OS2DefWindowProc(HWND hwnd
,
515 if ( GetClientWindow() )
516 clientWnd
= GetClientWindow()->GetHWND();
520 // TODO: return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam);
524 bool wxMDIParentFrame::OS2TranslateMessage(WXMSG
* msg
)
528 if ( m_currentChild && m_currentChild->GetHWND() &&
529 m_currentChild->OS2TranslateMessage(msg) )
534 if ( m_acceleratorTable.Translate(this, msg) )
539 if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN )
541 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg))
548 // ===========================================================================
550 // ===========================================================================
552 wxMDIChildFrame::wxMDIChildFrame()
556 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
558 const wxString
& title
,
562 const wxString
& name
)
564 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
565 : wxDEFAULT_MDICHILDFRAME_ICON
);
572 m_windowId
= (int)NewControlId();
576 parent
->AddChild(this);
590 mcs.szClass = wxMDIChildFrameClassName;
592 mcs.hOwner = wxGetInstance();
596 mcs.x = CW_USEDEFAULT;
601 mcs.y = CW_USEDEFAULT;
606 mcs.cx = CW_USEDEFAULT;
611 mcs.cy = CW_USEDEFAULT;
613 DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN;
614 if (style & wxMINIMIZE_BOX)
615 msflags |= WS_MINIMIZEBOX;
616 if (style & wxMAXIMIZE_BOX)
617 msflags |= WS_MAXIMIZEBOX;
618 if (style & wxTHICK_FRAME)
619 msflags |= WS_THICKFRAME;
620 if (style & wxSYSTEM_MENU)
621 msflags |= WS_SYSMENU;
622 if ((style & wxMINIMIZE) || (style & wxICONIZE))
623 msflags |= WS_MINIMIZE;
624 if (style & wxMAXIMIZE)
625 msflags |= WS_MAXIMIZE;
626 if (style & wxCAPTION)
627 msflags |= WS_CAPTION;
633 DWORD Return
= 0; // SendMessage(GetWinHwnd(parent->GetClientWindow()),
634 // WM_MDICREATE, 0, (LONG)(LPSTR)&mcs);
635 m_hWnd
= (WXHWND
)Return
;
638 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
640 // VZ: what's this? an act of piracy?
641 //SetWindowLong(GetHwnd(), 0, (long)this);
643 wxModelessWindows
.Append(this);
647 wxMDIChildFrame::~wxMDIChildFrame()
652 // Set the client size (i.e. leave the calculation of borders etc.
654 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
656 HWND hWnd
= GetHwnd();
661 ::GetClientRect(hWnd, &rect);
664 GetWindowRect(hWnd, &rect2);
666 // Find the difference between the entire window (title bar and all)
667 // and the client area; add this to the new client size to move the
669 int actual_width = rect2.right - rect2.left - rect.right + width;
670 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
675 GetStatusBar()->GetSize(&sx, &sy);
680 point.x = rect2.left;
683 // If there's an MDI parent, must subtract the parent's top left corner
684 // since MoveWindow moves relative to the parent
685 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
686 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
688 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
690 wxSizeEvent event(wxSize(width, height), m_windowId);
691 event.SetEventObject( this );
692 GetEventHandler()->ProcessEvent(event);
696 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
701 GetWindowRect(GetHwnd(), &rect);
706 // Since we now have the absolute screen coords,
707 // if there's a parent we must subtract its top left corner
708 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
709 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
716 void wxMDIChildFrame::InternalSetMenuBar()
721 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
723 HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
725 InsertWindowMenu(parent->GetClientWindow(), m_hMenu, subMenu);
727 parent->m_parentFrameActive = FALSE;
731 // ---------------------------------------------------------------------------
733 // ---------------------------------------------------------------------------
735 void wxMDIChildFrame::Maximize(bool maximize
)
737 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
740 if ( parent && parent->GetClientWindow() )
742 ::SendMessage(GetWinHwnd(parent->GetClientWindow()),
743 maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE,
744 (WPARAM)GetHwnd(), 0);
749 void wxMDIChildFrame::Restore()
753 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
754 if ( parent && parent->GetClientWindow() )
756 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE,
757 (WPARAM) GetHwnd(), 0);
762 void wxMDIChildFrame::Activate()
766 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
767 if ( parent && parent->GetClientWindow() )
769 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE,
770 (WPARAM) GetHwnd(), 0);
775 // ---------------------------------------------------------------------------
776 // MDI window proc and message handlers
777 // ---------------------------------------------------------------------------
779 MRESULT
wxMDIChildFrame::OS2WindowProc(HWND hwnd
,
785 bool processed
= FALSE
;
795 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
798 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
802 case WM_GETMINMAXINFO:
803 // let the default window proc calculate the size of MDI children
804 // frames because it is based on the size of the MDI client window,
805 // not on the values specified in wxWindow m_min/max variables
806 return MSWDefWindowProc(message, wParam, lParam);
811 WXHWND hwndAct, hwndDeact;
812 UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact);
814 processed = HandleMDIActivate(act, hwndAct, hwndDeact);
819 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
820 // scrollbars if necessary
825 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
827 MSWDefWindowProc(message, wParam, lParam);
831 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
832 // the message (the base class version does not)
833 return MSWDefWindowProc(message, wParam, lParam);
835 case WM_WINDOWPOSCHANGING:
836 processed = HandleWindowPosChanging((LPWINDOWPOS)lParam);
841 rc
= wxFrame::OS2WindowProc(hwnd
, message
, wParam
, lParam
);
846 bool wxMDIChildFrame::HandleSize(int x
, int y
, WXUINT id
)
848 HWND hwnd
= GetHwnd();
850 if ( !hwnd
|| hwnd
== invalidHandle
)
871 // forward WM_SIZE to status bar control
872 #if wxUSE_NATIVE_STATUSBAR
873 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
875 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
876 event.SetEventObject( m_frameStatusBar );
878 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
880 #endif // wxUSE_NATIVE_STATUSBAR
885 return wxWindow::HandleSize(x, y, id);
895 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
897 // In case it's e.g. a toolbar.
900 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
902 // Fix dependent stuff return win->OS2Command(cmd, id);
905 if (wxCurrentPopupMenu
)
907 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
908 wxCurrentPopupMenu
= NULL
;
909 // Fix dependent stuff if (popupMenu->OS2Command(cmd, id))
913 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
924 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
928 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
934 if ( m_hWnd
== hwndAct
)
937 parent
->m_currentChild
= this;
939 HMENU child_menu
= (HMENU
)GetWinMenu();
942 parent
->m_parentFrameActive
= FALSE
;
944 menuToSet
= child_menu
;
947 else if ( m_hWnd
== hwndDeact
)
949 wxASSERT_MSG( parent
->m_currentChild
== this,
950 wxT("can't deactivate MDI child which wasn't active!") );
953 parent
->m_currentChild
= NULL
;
955 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
958 parent
->m_parentFrameActive
= TRUE
;
960 menuToSet
= parent_menu
;
965 // we have nothing to with it
971 HMENU subMenu
= 0; // TODO: GetSubMenu((HMENU) parent->GetWindowMenu(), 0);
973 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
976 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
977 event
.SetEventObject( this );
979 return GetEventHandler()->ProcessEvent(event
);
982 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
984 // WINDOWPOS *lpPos = (WINDOWPOS *)pos;
988 // ---------------------------------------------------------------------------
989 // MDI specific message translation/preprocessing
990 // ---------------------------------------------------------------------------
992 MRESULT
wxMDIChildFrame::OS2DefWindowProc(HWND hwnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
996 return DefMDIChildProc(GetHwnd(),
997 (UINT)message, (WPARAM)wParam, (LPARAM)lParam);
1002 bool wxMDIChildFrame::OS2TranslateMessage(WXMSG
* msg
)
1004 return m_acceleratorTable
.Translate(GetParent(), msg
);
1007 // ---------------------------------------------------------------------------
1009 // ---------------------------------------------------------------------------
1011 void wxMDIChildFrame::OS2DestroyWindow()
1013 // get wxWindow up to date OS2DetachWindowMenu();
1014 invalidHandle
= GetHwnd();
1016 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
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.
1022 HWND oldHandle
= (HWND
)GetHWND();
1023 // TODO: SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY,
1024 // (WPARAM)oldHandle, 0);
1029 // TODO: ::DestroyMenu((HMENU) m_hMenu);
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
)
1042 // ===========================================================================
1043 // wxMDIClientWindow: the window of predefined (by Windows) class which
1044 // contains the child frames
1045 // ===========================================================================
1047 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1049 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1053 CLIENTCREATESTRUCT ccs;
1054 m_windowStyle = style;
1057 ccs.hWindowMenu = (HMENU)parent->GetWindowMenu();
1058 ccs.idFirstChild = wxFIRST_MDI_CHILD;
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;
1066 #if defined(__WIN95__)
1067 DWORD exStyle = WS_EX_CLIENTEDGE;
1073 m_hWnd = (WXHWND)::CreateWindowEx
1083 (LPSTR)(LPCLIENTCREATESTRUCT)&ccs);
1086 wxLogLastError("CreateWindowEx(MDI client)");
1091 SubclassWin(m_hWnd);
1097 // Explicitly call default scroll behaviour
1098 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
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.
1106 if ( event
.GetOrientation() == wxHORIZONTAL
)
1107 m_scrollX
= event
.GetPosition(); // Always returns zero!
1109 m_scrollY
= event
.GetPosition(); // Always returns zero!
1114 // ---------------------------------------------------------------------------
1115 // non member functions
1116 // ---------------------------------------------------------------------------
1118 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
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...") );
1128 ::DrawMenuBar(GetWinHwnd(parent));
1132 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
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++ )
1142 int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION);
1145 wxLogLastError(wxT("GetMenuString"));
1150 if ( wxStripMenuCodes(wxString(buf)).IsSameAs(wxT("Help")) )
1153 ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
1154 (UINT)subMenu, wxT("&Window"));
1161 ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, wxT("&Window"));
1163 MDISetMenu(win, hmenu, subMenu);
1167 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1168 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1171 *hwndAct
= (WXHWND
)lParam
;
1172 *hwndDeact
= (WXHWND
)wParam
;