1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "mdi.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/dialog.h"
38 #include "wx/statusbr.h"
39 #include "wx/settings.h"
45 #include "wx/msw/private.h"
47 #if wxUSE_NATIVE_STATUSBAR
48 #include <wx/msw/statbr95.h>
53 // ---------------------------------------------------------------------------
55 // ---------------------------------------------------------------------------
57 extern wxWindowList wxModelessWindows
; // from dialog.cpp
58 extern wxMenu
*wxCurrentPopupMenu
;
60 extern wxChar wxMDIFrameClassName
[];
61 extern wxChar wxMDIChildFrameClassName
[];
62 extern wxWindow
*wxWndHook
; // from window.cpp
64 extern wxList
*wxWinHandleList
;
66 static HWND invalidHandle
= 0;
68 // ---------------------------------------------------------------------------
70 // ---------------------------------------------------------------------------
72 static const int IDM_WINDOWTILE
= 4001;
73 static const int IDM_WINDOWTILEHOR
= 4001;
74 static const int IDM_WINDOWCASCADE
= 4002;
75 static const int IDM_WINDOWICONS
= 4003;
76 static const int IDM_WINDOWNEXT
= 4004;
77 static const int IDM_WINDOWTILEVERT
= 4005;
79 // This range gives a maximum of 500 MDI children. Should be enough :-)
80 static const int wxFIRST_MDI_CHILD
= 4100;
81 static const int wxLAST_MDI_CHILD
= 4600;
83 // Status border dimensions
84 static const int wxTHICK_LINE_BORDER
= 3;
85 static const int wxTHICK_LINE_WIDTH
= 1;
87 // ---------------------------------------------------------------------------
89 // ---------------------------------------------------------------------------
91 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
92 // of the parent of win (which is supposed to be the MDI client window)
93 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
95 // insert the window menu (subMenu) into menu just before "Help" submenu or at
96 // the very end if not found
97 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
99 // is this an id of an MDI child?
100 inline bool IsMdiCommandId(int id
)
102 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
105 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
106 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
108 // ===========================================================================
110 // ===========================================================================
112 // ---------------------------------------------------------------------------
114 // ---------------------------------------------------------------------------
116 #if !USE_SHARED_LIBRARY
117 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
118 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
119 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
120 #endif // USE_SHARED_LIBRARY
122 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
123 EVT_SIZE(wxMDIParentFrame::OnSize
)
124 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
127 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
128 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
131 // ===========================================================================
132 // wxMDIParentFrame: the frame which contains the client window which manages
134 // ===========================================================================
136 wxMDIParentFrame::wxMDIParentFrame()
138 m_clientWindow
= NULL
;
139 m_currentChild
= NULL
;
141 m_parentFrameActive
= TRUE
;
144 bool wxMDIParentFrame::Create(wxWindow
*parent
,
146 const wxString
& title
,
150 const wxString
& name
)
152 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
154 m_clientWindow
= NULL
;
155 m_currentChild
= NULL
;
157 m_parentFrameActive
= TRUE
;
160 wxTopLevelWindows
.Append(this);
163 m_windowStyle
= style
;
165 if (parent
) parent
->AddChild(this);
170 m_windowId
= (int)NewControlId();
177 m_windowMenu
= (WXHMENU
) ::LoadMenu(wxGetInstance(), _T("wxWindowMenu"));
179 DWORD msflags
= WS_OVERLAPPED
;
180 if (style
& wxMINIMIZE_BOX
)
181 msflags
|= WS_MINIMIZEBOX
;
182 if (style
& wxMAXIMIZE_BOX
)
183 msflags
|= WS_MAXIMIZEBOX
;
184 if (style
& wxTHICK_FRAME
)
185 msflags
|= WS_THICKFRAME
;
186 if (style
& wxSYSTEM_MENU
)
187 msflags
|= WS_SYSMENU
;
188 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
189 msflags
|= WS_MINIMIZE
;
190 if (style
& wxMAXIMIZE
)
191 msflags
|= WS_MAXIMIZE
;
192 if (style
& wxCAPTION
)
193 msflags
|= WS_CAPTION
;
195 if (style
& wxCLIP_CHILDREN
)
196 msflags
|= WS_CLIPCHILDREN
;
198 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
201 wxModelessWindows
.Append(this);
206 wxMDIParentFrame::~wxMDIParentFrame()
210 ::DestroyMenu((HMENU
)m_windowMenu
);
213 if ( m_clientWindow
)
215 if ( m_clientWindow
->MSWGetOldWndProc() )
216 m_clientWindow
->UnsubclassWin();
218 m_clientWindow
->SetHWND(0);
219 delete m_clientWindow
;
223 void wxMDIParentFrame::InternalSetMenuBar()
225 HMENU subMenu
= GetSubMenu((HMENU
) m_windowMenu
, 0);
227 m_parentFrameActive
= TRUE
;
229 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
232 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
234 if ( GetClientWindow() )
237 GetClientSize(&width
, &height
);
239 GetClientWindow()->SetSize(0, 0, width
, height
);
243 // Returns the active MDI child window
244 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
246 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
247 WM_MDIGETACTIVE
, 0, 0L);
251 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
254 // Create the client window class (don't Create the window, just return a new
256 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
258 return new wxMDIClientWindow
;
261 // Responds to colour changes, and passes event on to children.
262 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
264 if ( m_clientWindow
)
266 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
267 m_clientWindow
->Refresh();
273 // ---------------------------------------------------------------------------
275 // ---------------------------------------------------------------------------
277 void wxMDIParentFrame::Cascade()
279 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
282 // TODO: add a direction argument (hor/vert)
283 void wxMDIParentFrame::Tile()
285 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
288 void wxMDIParentFrame::ArrangeIcons()
290 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
293 void wxMDIParentFrame::ActivateNext()
295 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
298 void wxMDIParentFrame::ActivatePrevious()
300 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
303 // ---------------------------------------------------------------------------
304 // the MDI parent frame window proc
305 // ---------------------------------------------------------------------------
307 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
312 bool processed
= FALSE
;
318 WXWORD state
, minimized
;
320 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
322 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
330 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
332 (void)HandleCommand(id
, cmd
, hwnd
);
334 // even if the frame didn't process it, there is no need to try it
335 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
336 // so pretend we processed the message anyhow
340 // always pass this message DefFrameProc(), otherwise MDI menu
341 // commands (and sys commands - more surprizingly!) won't work
342 MSWDefWindowProc(message
, wParam
, lParam
);
346 m_clientWindow
= OnCreateClient();
347 // Uses own style for client style
348 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
350 wxLogMessage(_("Failed to create MDI parent frame."));
361 // we erase background ourselves
369 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
371 if ( m_parentFrameActive
)
373 processed
= HandleMenuSelect(item
, flags
, hmenu
);
375 else if (m_currentChild
)
377 processed
= m_currentChild
->
378 HandleMenuSelect(item
, flags
, hmenu
);
384 // as we don't (usually) resize the MDI client to exactly fit the
385 // client area (we put it below the toolbar, above statusbar &c),
386 // we should not pass this one to DefFrameProc
391 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
396 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
398 bool processed
= FALSE
;
400 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
406 // If this window is an MDI parent, we must also send an OnActivate message
407 // to the current child.
408 if ( (m_currentChild
!= NULL
) &&
409 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
411 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
412 event
.SetEventObject( m_currentChild
);
413 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
420 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
422 // In case it's e.g. a toolbar.
425 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
427 return win
->MSWCommand(cmd
, id
);
430 // is it one of standard MDI commands?
435 case IDM_WINDOWCASCADE
:
437 wParam
= MDITILE_SKIPDISABLED
;
440 case IDM_WINDOWTILEHOR
:
441 wParam
|= MDITILE_HORIZONTAL
;
444 case IDM_WINDOWTILEVERT
:
446 wParam
= MDITILE_VERTICAL
;
448 wParam
|= MDITILE_SKIPDISABLED
;
451 case IDM_WINDOWICONS
:
452 msg
= WM_MDIICONARRANGE
;
465 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
470 // FIXME VZ: what does this test do??
473 return FALSE
; // Get WndProc to call default proc
476 if ( IsMdiCommandId(id
) )
478 wxWindowList::Node
* node
= GetChildren().GetFirst();
481 wxWindow
* child
= node
->GetData();
482 if ( child
->GetHWND() )
484 long childId
= wxGetWindowId(child
->GetHWND());
487 ::SendMessage( GetWinHwnd(GetClientWindow()),
489 (WPARAM
)child
->GetHWND(), 0);
493 node
= node
->GetNext();
496 else if ( m_parentFrameActive
)
498 return ProcessCommand(id
);
500 else if ( m_currentChild
)
502 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
506 // this shouldn't happen because it means that our messages are being
507 // lost (they're not sent to the parent frame nor to the children)
508 wxFAIL_MSG(_T("MDI parent frame is not active, "
509 "yet there is no active MDI child?"));
515 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
520 if ( GetClientWindow() )
521 clientWnd
= GetClientWindow()->GetHWND();
525 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
528 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
530 MSG
*pMsg
= (MSG
*)msg
;
532 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
533 m_currentChild
->MSWTranslateMessage(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_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
569 : wxDEFAULT_MDICHILDFRAME_ICON
);
576 m_windowId
= (int)NewControlId();
580 parent
->AddChild(this);
592 mcs
.szClass
= wxMDIChildFrameClassName
;
594 mcs
.hOwner
= wxGetInstance();
598 mcs
.x
= CW_USEDEFAULT
;
603 mcs
.y
= CW_USEDEFAULT
;
608 mcs
.cx
= CW_USEDEFAULT
;
613 mcs
.cy
= CW_USEDEFAULT
;
615 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
616 if (style
& wxMINIMIZE_BOX
)
617 msflags
|= WS_MINIMIZEBOX
;
618 if (style
& wxMAXIMIZE_BOX
)
619 msflags
|= WS_MAXIMIZEBOX
;
620 if (style
& wxTHICK_FRAME
)
621 msflags
|= WS_THICKFRAME
;
622 if (style
& wxSYSTEM_MENU
)
623 msflags
|= WS_SYSMENU
;
624 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
625 msflags
|= WS_MINIMIZE
;
626 if (style
& wxMAXIMIZE
)
627 msflags
|= WS_MAXIMIZE
;
628 if (style
& wxCAPTION
)
629 msflags
|= WS_CAPTION
;
635 DWORD Return
= SendMessage(GetWinHwnd(parent
->GetClientWindow()),
636 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
638 //handle = (HWND)LOWORD(Return);
639 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
640 m_hWnd
= (WXHWND
)Return
;
643 wxWinHandleList
->Append((long)GetHWND(), this);
645 // VZ: what's this? an act of piracy?
646 //SetWindowLong(GetHwnd(), 0, (long)this);
648 wxModelessWindows
.Append(this);
652 wxMDIChildFrame::~wxMDIChildFrame()
657 // Set the client size (i.e. leave the calculation of borders etc.
659 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
661 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
);
698 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
);
715 void wxMDIChildFrame::InternalSetMenuBar()
717 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
719 HMENU subMenu
= GetSubMenu((HMENU
)parent
->GetWindowMenu(), 0);
721 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
723 parent
->m_parentFrameActive
= FALSE
;
726 // ---------------------------------------------------------------------------
728 // ---------------------------------------------------------------------------
730 void wxMDIChildFrame::Maximize(bool maximize
)
732 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
733 if ( parent
&& parent
->GetClientWindow() )
735 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
736 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
737 (WPARAM
)GetHwnd(), 0);
741 void wxMDIChildFrame::Restore()
743 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
744 if ( parent
&& parent
->GetClientWindow() )
746 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
747 (WPARAM
) GetHwnd(), 0);
751 void wxMDIChildFrame::Activate()
753 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
754 if ( parent
&& parent
->GetClientWindow() )
756 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
757 (WPARAM
) GetHwnd(), 0);
761 // ---------------------------------------------------------------------------
762 // MDI window proc and message handlers
763 // ---------------------------------------------------------------------------
765 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
770 bool processed
= FALSE
;
778 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
781 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
785 case WM_GETMINMAXINFO
:
786 // let the default window proc calculate the size of MDI children
787 // frames because it is based on the size of the MDI client window,
788 // not on the values specified in wxWindow m_min/max variables
789 return MSWDefWindowProc(message
, wParam
, lParam
);
794 WXHWND hwndAct
, hwndDeact
;
795 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
797 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
802 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
803 // scrollbars if necessary
808 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
810 MSWDefWindowProc(message
, wParam
, lParam
);
814 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
815 // the message (the base class version does not)
816 return MSWDefWindowProc(message
, wParam
, lParam
);
818 case WM_WINDOWPOSCHANGING
:
819 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
824 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
829 bool wxMDIChildFrame::HandleSize(int x
, int y
, WXUINT id
)
831 HWND hwnd
= GetHwnd();
833 if ( !hwnd
|| hwnd
== invalidHandle
)
852 // forward WM_SIZE to status bar control
853 #if wxUSE_NATIVE_STATUSBAR
854 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
856 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
857 event
.SetEventObject( m_frameStatusBar
);
859 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
861 #endif // wxUSE_NATIVE_STATUSBAR
866 return wxWindow::HandleSize(x
, y
, id
);
874 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
876 // In case it's e.g. a toolbar.
879 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
881 return win
->MSWCommand(cmd
, id
);
884 if (wxCurrentPopupMenu
)
886 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
887 wxCurrentPopupMenu
= NULL
;
888 if (popupMenu
->MSWCommand(cmd
, id
))
892 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
903 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
907 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
913 if ( m_hWnd
== hwndAct
)
916 parent
->m_currentChild
= this;
918 HMENU child_menu
= (HMENU
)GetWinMenu();
921 parent
->m_parentFrameActive
= FALSE
;
923 menuToSet
= child_menu
;
926 else if ( m_hWnd
== hwndDeact
)
928 wxASSERT_MSG( parent
->m_currentChild
== this,
929 _T("can't deactivate MDI child which wasn't active!") );
932 parent
->m_currentChild
= NULL
;
934 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
937 parent
->m_parentFrameActive
= TRUE
;
939 menuToSet
= parent_menu
;
944 // we have nothing to with it
950 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
952 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
955 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
956 event
.SetEventObject( this );
958 return GetEventHandler()->ProcessEvent(event
);
961 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
963 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
964 #if defined(__WIN95__)
965 if (!(lpPos
->flags
& SWP_NOSIZE
))
968 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
969 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
970 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
972 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
973 lpPos
->x
= rectClient
.left
;
974 lpPos
->y
= rectClient
.top
;
975 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
976 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
978 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
979 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
981 pFrameWnd
->GetToolBar()->Refresh();
989 // ---------------------------------------------------------------------------
990 // MDI specific message translation/preprocessing
991 // ---------------------------------------------------------------------------
993 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
995 return DefMDIChildProc(GetHwnd(),
996 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
999 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1001 return m_acceleratorTable
.Translate(GetParent(), msg
);
1004 // ---------------------------------------------------------------------------
1006 // ---------------------------------------------------------------------------
1008 void wxMDIChildFrame::MSWDestroyWindow()
1010 MSWDetachWindowMenu();
1011 invalidHandle
= GetHwnd();
1013 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1015 // Must make sure this handle is invalidated (set to NULL) since all sorts
1016 // of things could happen after the child client is destroyed, but before
1017 // the wxFrame is destroyed.
1019 HWND oldHandle
= (HWND
)GetHWND();
1020 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1021 (WPARAM
)oldHandle
, 0);
1026 ::DestroyMenu((HMENU
) m_hMenu
);
1032 // Change the client window's extended style so we don't get a client edge
1033 // style when a child is maximised (a double border looks silly.)
1034 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1036 #if defined(__WIN95__)
1037 RECT
*rect
= (RECT
*)vrect
;
1038 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1039 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1040 if (!pChild
|| (pChild
== this))
1042 DWORD dwStyle
= ::GetWindowLong(GetWinHwnd(pFrameWnd
->GetClientWindow()), GWL_EXSTYLE
);
1043 DWORD dwThisStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1044 DWORD dwNewStyle
= dwStyle
;
1045 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1046 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1048 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1050 if (dwStyle
!= dwNewStyle
)
1052 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1053 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1054 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1055 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1056 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1057 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1060 ::GetClientRect(hwnd
, rect
);
1070 // ===========================================================================
1071 // wxMDIClientWindow: the window of predefined (by Windows) class which
1072 // contains the child frames
1073 // ===========================================================================
1075 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1077 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1079 CLIENTCREATESTRUCT ccs
;
1080 m_windowStyle
= style
;
1083 ccs
.hWindowMenu
= (HMENU
)parent
->GetWindowMenu();
1084 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1086 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1087 if ( style
& wxHSCROLL
)
1088 msStyle
|= WS_HSCROLL
;
1089 if ( style
& wxVSCROLL
)
1090 msStyle
|= WS_VSCROLL
;
1092 #if defined(__WIN95__)
1093 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1099 m_hWnd
= (WXHWND
)::CreateWindowEx
1109 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1112 wxLogLastError("CreateWindowEx(MDI client)");
1117 SubclassWin(m_hWnd
);
1123 // Explicitly call default scroll behaviour
1124 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1126 // Note: for client windows, the scroll position is not set in
1127 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1128 // scroll position we're at.
1129 // This makes it hard to paint patterns or bitmaps in the background,
1130 // and have the client area scrollable as well.
1132 if ( event
.GetOrientation() == wxHORIZONTAL
)
1133 m_scrollX
= event
.GetPosition(); // Always returns zero!
1135 m_scrollY
= event
.GetPosition(); // Always returns zero!
1140 // ---------------------------------------------------------------------------
1141 // non member functions
1142 // ---------------------------------------------------------------------------
1144 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1146 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1148 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
);
1150 0, MAKELPARAM(hmenuFrame
, hmenuWindow
));
1153 // update menu bar of the parent window
1154 wxWindow
*parent
= win
->GetParent();
1155 wxCHECK_RET( parent
, _T("MDI client without parent frame? weird...") );
1157 ::DrawMenuBar(GetWinHwnd(parent
));
1160 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1162 // Try to insert Window menu in front of Help, otherwise append it.
1163 HMENU hmenu
= (HMENU
)menu
;
1164 int N
= GetMenuItemCount(hmenu
);
1165 bool success
= FALSE
;
1166 for ( int i
= 0; i
< N
; i
++ )
1169 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1172 wxLogLastError(_T("GetMenuString"));
1177 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_T("Help")) )
1180 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1181 (UINT
)subMenu
, _T("&Window"));
1188 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _T("&Window"));
1191 MDISetMenu(win
, hmenu
, subMenu
);
1194 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1195 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1199 *hwndAct
= (WXHWND
)lParam
;
1200 *hwndDeact
= (WXHWND
)wParam
;
1202 *activate
= (WXWORD
)wParam
;
1203 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1204 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1205 #endif // Win32/Win16