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 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
97 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
98 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
100 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
101 EVT_SIZE(wxMDIParentFrame::OnSize
)
102 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
105 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
106 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
109 // ===========================================================================
110 // wxMDIParentFrame: the frame which contains the client window which manages
112 // ===========================================================================
114 wxMDIParentFrame::wxMDIParentFrame()
116 m_clientWindow
= NULL
;
117 m_currentChild
= NULL
;
119 m_parentFrameActive
= TRUE
;
122 bool wxMDIParentFrame::Create(wxWindow
*parent
,
124 const wxString
& title
,
128 const wxString
& name
)
130 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
132 m_clientWindow
= NULL
;
133 m_currentChild
= NULL
;
135 m_parentFrameActive
= TRUE
;
138 wxTopLevelWindows
.Append(this);
141 m_windowStyle
= style
;
143 if (parent
) parent
->AddChild(this);
148 m_windowId
= (int)NewControlId();
155 // TODO: m_windowMenu = (WXHMENU) ::LoadMenu(wxGetInstance(), wxT("wxWindowMenu"));
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;
173 if (style & wxCLIP_CHILDREN)
174 msflags |= WS_CLIPCHILDREN;
176 wxWindow::MSWCreate(m_windowId, parent, wxMDIFrameClassName, this, title, x, y, width, height,
179 wxModelessWindows
.Append(this);
184 wxMDIParentFrame::~wxMDIParentFrame()
188 // TODO: ::DestroyMenu((HMENU)m_windowMenu);
191 if ( m_clientWindow
)
193 if ( m_clientWindow
->OS2GetOldWndProc() )
194 m_clientWindow
->UnsubclassWin();
196 m_clientWindow
->SetHWND(0);
197 delete m_clientWindow
;
201 void wxMDIParentFrame::InternalSetMenuBar()
205 HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
207 m_parentFrameActive = TRUE;
209 InsertWindowMenu(GetClientWindow(), m_hMenu, subMenu);
213 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
217 if ( GetClientWindow() )
220 GetClientSize(&width, &height);
222 GetClientWindow()->SetSize(0, 0, width, height);
227 // Returns the active MDI child window
228 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
230 HWND hWnd
= 0; // TODO: (HWND)::SendMessage(GetWinHwnd(GetClientWindow()),
231 // WM_MDIGETACTIVE, 0, 0L);
235 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
238 // Create the client window class (don't Create the window, just return a new
240 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
242 return new wxMDIClientWindow
;
245 // Responds to colour changes, and passes event on to children.
246 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
248 if ( m_clientWindow
)
250 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
251 m_clientWindow
->Refresh();
257 // ---------------------------------------------------------------------------
259 // ---------------------------------------------------------------------------
261 void wxMDIParentFrame::Cascade()
263 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE, 0, 0);
266 // TODO: add a direction argument (hor/vert)
267 void wxMDIParentFrame::Tile()
269 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE, MDITILE_HORIZONTAL, 0);
272 void wxMDIParentFrame::ArrangeIcons()
274 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE, 0, 0);
277 void wxMDIParentFrame::ActivateNext()
279 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 0);
282 void wxMDIParentFrame::ActivatePrevious()
284 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 1);
287 // ---------------------------------------------------------------------------
288 // the MDI parent frame window proc
289 // ---------------------------------------------------------------------------
291 MRESULT
wxMDIParentFrame::OS2WindowProc(HWND hwnd
,
297 bool processed
= FALSE
;
305 WXWORD state, minimized;
307 UnpackActivate(wParam, lParam, &state, &minimized, &hwnd);
309 processed = HandleActivate(state, minimized != 0, hwnd);
317 UnpackCommand(wParam, lParam, &id, &hwnd, &cmd);
319 (void)HandleCommand(id, cmd, hwnd);
321 // even if the frame didn't process it, there is no need to try it
322 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
323 // so pretend we processed the message anyhow
327 // always pass this message DefFrameProc(), otherwise MDI menu
328 // commands (and sys commands - more surprizingly!) won't work
329 MSWDefWindowProc(message, wParam, lParam);
333 m_clientWindow = OnCreateClient();
334 // Uses own style for client style
335 if ( !m_clientWindow->CreateClient(this, GetWindowStyleFlag()) )
337 wxLogMessage(_("Failed to create MDI parent frame."));
348 // we erase background ourselves
356 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
358 if ( m_parentFrameActive )
360 processed = HandleMenuSelect(item, flags, hmenu);
362 else if (m_currentChild)
364 processed = m_currentChild->
365 HandleMenuSelect(item, flags, hmenu);
371 // as we don't (usually) resize the MDI client to exactly fit the
372 // client area (we put it below the toolbar, above statusbar &c),
373 // we should not pass this one to DefFrameProc
378 rc
= wxFrame::OS2WindowProc(hwnd
, message
, wParam
, lParam
);
383 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
385 bool processed
= FALSE
;
389 if ( wxWindow::HandleActivate(state, minimized, activate) )
395 // If this window is an MDI parent, we must also send an OnActivate message
396 // to the current child.
397 if ( (m_currentChild != NULL) &&
398 ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) )
400 wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_currentChild->GetId());
401 event.SetEventObject( m_currentChild );
402 if ( m_currentChild->GetEventHandler()->ProcessEvent(event) )
409 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
411 // In case it's e.g. a toolbar.
414 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
416 return FALSE
; // Need to get wxWindow for OS/2 up to date: win->OS2Command(cmd, id);
419 // is it one of standard MDI commands?
427 case IDM_WINDOWCASCADE:
429 wParam = MDITILE_SKIPDISABLED;
432 case IDM_WINDOWTILEHOR:
433 wParam |= MDITILE_HORIZONTAL;
436 case IDM_WINDOWTILEVERT:
438 wParam = MDITILE_VERTICAL;
440 wParam |= MDITILE_SKIPDISABLED;
443 case IDM_WINDOWICONS:
444 msg = WM_MDIICONARRANGE;
457 // TODO: ::SendMessage(GetWinHwnd(GetClientWindow()), msg, wParam, 0);
462 // FIXME VZ: what does this test do??
465 return FALSE
; // Get WndProc to call default proc
468 if ( IsMdiCommandId(id
) )
470 wxWindowList::Node
* node
= GetChildren().GetFirst();
473 wxWindow
* child
= node
->GetData();
474 if ( child
->GetHWND() )
476 long childId
= wxGetWindowId(child
->GetHWND());
477 if (childId
== (long)id
)
479 // TODO: ::SendMessage( GetWinHwnd(GetClientWindow()),
481 // (WPARAM)child->GetHWND(), 0);
485 node
= node
->GetNext();
488 else if ( m_parentFrameActive
)
490 return ProcessCommand(id
);
492 else if ( m_currentChild
)
494 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
498 // this shouldn't happen because it means that our messages are being
499 // lost (they're not sent to the parent frame nor to the children)
500 wxFAIL_MSG(wxT("MDI parent frame is not active, "
501 "yet there is no active MDI child?"));
507 MRESULT
wxMDIParentFrame::OS2DefWindowProc(HWND hwnd
,
513 if ( GetClientWindow() )
514 clientWnd
= GetClientWindow()->GetHWND();
518 // TODO: return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam);
522 bool wxMDIParentFrame::OS2TranslateMessage(WXMSG
* msg
)
526 if ( m_currentChild && m_currentChild->GetHWND() &&
527 m_currentChild->OS2TranslateMessage(msg) )
532 if ( m_acceleratorTable.Translate(this, msg) )
537 if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN )
539 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg))
546 // ===========================================================================
548 // ===========================================================================
550 wxMDIChildFrame::wxMDIChildFrame()
554 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
556 const wxString
& title
,
560 const wxString
& name
)
562 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
563 : wxDEFAULT_MDICHILDFRAME_ICON
);
570 m_windowId
= (int)NewControlId();
574 parent
->AddChild(this);
588 mcs.szClass = wxMDIChildFrameClassName;
590 mcs.hOwner = wxGetInstance();
594 mcs.x = CW_USEDEFAULT;
599 mcs.y = CW_USEDEFAULT;
604 mcs.cx = CW_USEDEFAULT;
609 mcs.cy = CW_USEDEFAULT;
611 DWORD msflags = WS_OVERLAPPED | WS_CLIPCHILDREN;
612 if (style & wxMINIMIZE_BOX)
613 msflags |= WS_MINIMIZEBOX;
614 if (style & wxMAXIMIZE_BOX)
615 msflags |= WS_MAXIMIZEBOX;
616 if (style & wxTHICK_FRAME)
617 msflags |= WS_THICKFRAME;
618 if (style & wxSYSTEM_MENU)
619 msflags |= WS_SYSMENU;
620 if ((style & wxMINIMIZE) || (style & wxICONIZE))
621 msflags |= WS_MINIMIZE;
622 if (style & wxMAXIMIZE)
623 msflags |= WS_MAXIMIZE;
624 if (style & wxCAPTION)
625 msflags |= WS_CAPTION;
631 DWORD Return
= 0; // SendMessage(GetWinHwnd(parent->GetClientWindow()),
632 // WM_MDICREATE, 0, (LONG)(LPSTR)&mcs);
633 m_hWnd
= (WXHWND
)Return
;
636 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
638 // VZ: what's this? an act of piracy?
639 //SetWindowLong(GetHwnd(), 0, (long)this);
641 wxModelessWindows
.Append(this);
645 wxMDIChildFrame::~wxMDIChildFrame()
650 // Set the client size (i.e. leave the calculation of borders etc.
652 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
654 HWND hWnd
= GetHwnd();
659 ::GetClientRect(hWnd, &rect);
662 GetWindowRect(hWnd, &rect2);
664 // Find the difference between the entire window (title bar and all)
665 // and the client area; add this to the new client size to move the
667 int actual_width = rect2.right - rect2.left - rect.right + width;
668 int actual_height = rect2.bottom - rect2.top - rect.bottom + height;
673 GetStatusBar()->GetSize(&sx, &sy);
678 point.x = rect2.left;
681 // If there's an MDI parent, must subtract the parent's top left corner
682 // since MoveWindow moves relative to the parent
683 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
684 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
686 MoveWindow(hWnd, point.x, point.y, actual_width, actual_height, (BOOL)TRUE);
688 wxSizeEvent event(wxSize(width, height), m_windowId);
689 event.SetEventObject( this );
690 GetEventHandler()->ProcessEvent(event);
694 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
699 GetWindowRect(GetHwnd(), &rect);
704 // Since we now have the absolute screen coords,
705 // if there's a parent we must subtract its top left corner
706 wxMDIParentFrame *mdiParent = (wxMDIParentFrame *)GetParent();
707 ::ScreenToClient((HWND) mdiParent->GetClientWindow()->GetHWND(), &point);
714 void wxMDIChildFrame::InternalSetMenuBar()
719 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
721 HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
723 InsertWindowMenu(parent->GetClientWindow(), m_hMenu, subMenu);
725 parent->m_parentFrameActive = FALSE;
729 // ---------------------------------------------------------------------------
731 // ---------------------------------------------------------------------------
733 void wxMDIChildFrame::Maximize(bool maximize
)
735 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
738 if ( parent && parent->GetClientWindow() )
740 ::SendMessage(GetWinHwnd(parent->GetClientWindow()),
741 maximize ? WM_MDIMAXIMIZE : WM_MDIRESTORE,
742 (WPARAM)GetHwnd(), 0);
747 void wxMDIChildFrame::Restore()
751 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
752 if ( parent && parent->GetClientWindow() )
754 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIRESTORE,
755 (WPARAM) GetHwnd(), 0);
760 void wxMDIChildFrame::Activate()
764 wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent();
765 if ( parent && parent->GetClientWindow() )
767 ::SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIACTIVATE,
768 (WPARAM) GetHwnd(), 0);
773 // ---------------------------------------------------------------------------
774 // MDI window proc and message handlers
775 // ---------------------------------------------------------------------------
777 MRESULT
wxMDIChildFrame::OS2WindowProc(HWND hwnd
,
783 bool processed
= FALSE
;
793 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
796 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
800 case WM_GETMINMAXINFO:
801 // let the default window proc calculate the size of MDI children
802 // frames because it is based on the size of the MDI client window,
803 // not on the values specified in wxWindow m_min/max variables
804 return MSWDefWindowProc(message, wParam, lParam);
809 WXHWND hwndAct, hwndDeact;
810 UnpackMDIActivate(wParam, lParam, &act, &hwndAct, &hwndDeact);
812 processed = HandleMDIActivate(act, hwndAct, hwndDeact);
817 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
818 // scrollbars if necessary
823 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
825 MSWDefWindowProc(message, wParam, lParam);
829 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
830 // the message (the base class version does not)
831 return MSWDefWindowProc(message, wParam, lParam);
833 case WM_WINDOWPOSCHANGING:
834 processed = HandleWindowPosChanging((LPWINDOWPOS)lParam);
839 rc
= wxFrame::OS2WindowProc(hwnd
, message
, wParam
, lParam
);
844 bool wxMDIChildFrame::HandleSize(int x
, int y
, WXUINT id
)
846 HWND hwnd
= GetHwnd();
848 if ( !hwnd
|| hwnd
== invalidHandle
)
869 // forward WM_SIZE to status bar control
870 #if wxUSE_NATIVE_STATUSBAR
871 if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95)))
873 wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId());
874 event.SetEventObject( m_frameStatusBar );
876 ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event);
878 #endif // wxUSE_NATIVE_STATUSBAR
883 return wxWindow::HandleSize(x, y, id);
893 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
895 // In case it's e.g. a toolbar.
898 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
900 // Fix dependent stuff return win->OS2Command(cmd, id);
903 if (wxCurrentPopupMenu
)
905 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
906 wxCurrentPopupMenu
= NULL
;
907 // Fix dependent stuff if (popupMenu->OS2Command(cmd, id))
911 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
922 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
926 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
932 if ( m_hWnd
== hwndAct
)
935 parent
->m_currentChild
= this;
937 HMENU child_menu
= (HMENU
)GetWinMenu();
940 parent
->m_parentFrameActive
= FALSE
;
942 menuToSet
= child_menu
;
945 else if ( m_hWnd
== hwndDeact
)
947 wxASSERT_MSG( parent
->m_currentChild
== this,
948 wxT("can't deactivate MDI child which wasn't active!") );
951 parent
->m_currentChild
= NULL
;
953 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
956 parent
->m_parentFrameActive
= TRUE
;
958 menuToSet
= parent_menu
;
963 // we have nothing to with it
969 HMENU subMenu
= 0; // TODO: GetSubMenu((HMENU) parent->GetWindowMenu(), 0);
971 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
974 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
975 event
.SetEventObject( this );
977 return GetEventHandler()->ProcessEvent(event
);
980 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
982 // WINDOWPOS *lpPos = (WINDOWPOS *)pos;
986 // ---------------------------------------------------------------------------
987 // MDI specific message translation/preprocessing
988 // ---------------------------------------------------------------------------
990 MRESULT
wxMDIChildFrame::OS2DefWindowProc(HWND hwnd
, WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
994 return DefMDIChildProc(GetHwnd(),
995 (UINT)message, (WPARAM)wParam, (LPARAM)lParam);
1000 bool wxMDIChildFrame::OS2TranslateMessage(WXMSG
* msg
)
1002 return m_acceleratorTable
.Translate(GetParent(), msg
);
1005 // ---------------------------------------------------------------------------
1007 // ---------------------------------------------------------------------------
1009 void wxMDIChildFrame::OS2DestroyWindow()
1011 // get wxWindow up to date OS2DetachWindowMenu();
1012 invalidHandle
= GetHwnd();
1014 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1016 // Must make sure this handle is invalidated (set to NULL) since all sorts
1017 // of things could happen after the child client is destroyed, but before
1018 // the wxFrame is destroyed.
1020 HWND oldHandle
= (HWND
)GetHWND();
1021 // TODO: SendMessage(GetWinHwnd(parent->GetClientWindow()), WM_MDIDESTROY,
1022 // (WPARAM)oldHandle, 0);
1027 // TODO: ::DestroyMenu((HMENU) m_hMenu);
1033 // Change the client window's extended style so we don't get a client edge
1034 // style when a child is maximised (a double border looks silly.)
1035 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1040 // ===========================================================================
1041 // wxMDIClientWindow: the window of predefined (by Windows) class which
1042 // contains the child frames
1043 // ===========================================================================
1045 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1047 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1051 CLIENTCREATESTRUCT ccs;
1052 m_windowStyle = style;
1055 ccs.hWindowMenu = (HMENU)parent->GetWindowMenu();
1056 ccs.idFirstChild = wxFIRST_MDI_CHILD;
1058 DWORD msStyle = WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN;
1059 if ( style & wxHSCROLL )
1060 msStyle |= WS_HSCROLL;
1061 if ( style & wxVSCROLL )
1062 msStyle |= WS_VSCROLL;
1064 #if defined(__WIN95__)
1065 DWORD exStyle = WS_EX_CLIENTEDGE;
1071 m_hWnd = (WXHWND)::CreateWindowEx
1081 (LPSTR)(LPCLIENTCREATESTRUCT)&ccs);
1084 wxLogLastError("CreateWindowEx(MDI client)");
1089 SubclassWin(m_hWnd);
1095 // Explicitly call default scroll behaviour
1096 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1098 // Note: for client windows, the scroll position is not set in
1099 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1100 // scroll position we're at.
1101 // This makes it hard to paint patterns or bitmaps in the background,
1102 // and have the client area scrollable as well.
1104 if ( event
.GetOrientation() == wxHORIZONTAL
)
1105 m_scrollX
= event
.GetPosition(); // Always returns zero!
1107 m_scrollY
= event
.GetPosition(); // Always returns zero!
1112 // ---------------------------------------------------------------------------
1113 // non member functions
1114 // ---------------------------------------------------------------------------
1116 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1120 ::SendMessage(GetWinHwnd(win), WM_MDISETMENU,
1121 (WPARAM)hmenuFrame, (LPARAM)hmenuWindow);
1122 // update menu bar of the parent window
1123 wxWindow *parent = win->GetParent();
1124 wxCHECK_RET( parent, wxT("MDI client without parent frame? weird...") );
1126 ::DrawMenuBar(GetWinHwnd(parent));
1130 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1133 // Try to insert Window menu in front of Help, otherwise append it.
1134 HMENU hmenu = (HMENU)menu;
1135 int N = GetMenuItemCount(hmenu);
1136 bool success = FALSE;
1137 for ( int i = 0; i < N; i++ )
1140 int chars = GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION);
1143 wxLogLastError(wxT("GetMenuString"));
1148 if ( wxStripMenuCodes(wxString(buf)).IsSameAs(wxT("Help")) )
1151 ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
1152 (UINT)subMenu, wxT("&Window"));
1159 ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, wxT("&Window"));
1161 MDISetMenu(win, hmenu, subMenu);
1165 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1166 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1169 *hwndAct
= (WXHWND
)lParam
;
1170 *hwndDeact
= (WXHWND
)wParam
;