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 // Adding WS_CLIPCHILDREN causes children not to be properly
196 // drawn when first displaying them.
197 // if (style & wxCLIP_CHILDREN)
198 // msflags |= WS_CLIPCHILDREN;
200 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
203 wxModelessWindows
.Append(this);
208 wxMDIParentFrame::~wxMDIParentFrame()
212 ::DestroyMenu((HMENU
)m_windowMenu
);
215 if ( m_clientWindow
)
217 if ( m_clientWindow
->MSWGetOldWndProc() )
218 m_clientWindow
->UnsubclassWin();
220 m_clientWindow
->SetHWND(0);
221 delete m_clientWindow
;
225 void wxMDIParentFrame::InternalSetMenuBar()
227 HMENU subMenu
= GetSubMenu((HMENU
) m_windowMenu
, 0);
229 m_parentFrameActive
= TRUE
;
231 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
234 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
236 if ( GetClientWindow() )
239 GetClientSize(&width
, &height
);
241 GetClientWindow()->SetSize(0, 0, width
, height
);
245 // Returns the active MDI child window
246 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
248 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
249 WM_MDIGETACTIVE
, 0, 0L);
253 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
256 // Create the client window class (don't Create the window, just return a new
258 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
260 return new wxMDIClientWindow
;
263 // Responds to colour changes, and passes event on to children.
264 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
266 if ( m_clientWindow
)
268 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
269 m_clientWindow
->Refresh();
275 // ---------------------------------------------------------------------------
277 // ---------------------------------------------------------------------------
279 void wxMDIParentFrame::Cascade()
281 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
284 // TODO: add a direction argument (hor/vert)
285 void wxMDIParentFrame::Tile()
287 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
290 void wxMDIParentFrame::ArrangeIcons()
292 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
295 void wxMDIParentFrame::ActivateNext()
297 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
300 void wxMDIParentFrame::ActivatePrevious()
302 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
305 // ---------------------------------------------------------------------------
306 // the MDI parent frame window proc
307 // ---------------------------------------------------------------------------
309 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
314 bool processed
= FALSE
;
320 WXWORD state
, minimized
;
322 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
324 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
332 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
334 (void)HandleCommand(id
, cmd
, hwnd
);
336 // even if the frame didn't process it, there is no need to try it
337 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
338 // so pretend we processed the message anyhow
342 // always pass this message DefFrameProc(), otherwise MDI menu
343 // commands (and sys commands - more surprizingly!) won't work
344 MSWDefWindowProc(message
, wParam
, lParam
);
348 m_clientWindow
= OnCreateClient();
349 // Uses own style for client style
350 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
352 wxLogMessage(_("Failed to create MDI parent frame."));
363 // we erase background ourselves
371 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
373 if ( m_parentFrameActive
)
375 processed
= HandleMenuSelect(item
, flags
, hmenu
);
377 else if (m_currentChild
)
379 processed
= m_currentChild
->
380 HandleMenuSelect(item
, flags
, hmenu
);
386 // we will leave this message to the base class version, but we
387 // must pass it to DefFrameProc() too
388 MSWDefWindowProc(message
, wParam
, lParam
);
393 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
398 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
400 bool processed
= FALSE
;
402 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
408 // If this window is an MDI parent, we must also send an OnActivate message
409 // to the current child.
410 if ( (m_currentChild
!= NULL
) &&
411 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
413 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
414 event
.SetEventObject( m_currentChild
);
415 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
422 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
424 // In case it's e.g. a toolbar.
427 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
429 return win
->MSWCommand(cmd
, id
);
432 // is it one of standard MDI commands?
437 case IDM_WINDOWCASCADE
:
439 wParam
= MDITILE_SKIPDISABLED
;
442 case IDM_WINDOWTILEHOR
:
443 wParam
|= MDITILE_HORIZONTAL
;
446 case IDM_WINDOWTILEVERT
:
448 wParam
= MDITILE_VERTICAL
;
450 wParam
|= MDITILE_SKIPDISABLED
;
453 case IDM_WINDOWICONS
:
454 msg
= WM_MDIICONARRANGE
;
467 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
472 // FIXME VZ: what does this test do??
475 return FALSE
; // Get WndProc to call default proc
478 if ( IsMdiCommandId(id
) )
480 wxWindowList::Node
* node
= GetChildren().GetFirst();
483 wxWindow
* child
= node
->GetData();
484 if ( child
->GetHWND() )
486 long childId
= wxGetWindowId(child
->GetHWND());
489 ::SendMessage( GetWinHwnd(GetClientWindow()),
491 (WPARAM
)child
->GetHWND(), 0);
495 node
= node
->GetNext();
498 else if ( m_parentFrameActive
)
500 return ProcessCommand(id
);
502 else if ( m_currentChild
)
504 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
508 // this shouldn't happen because it means that our messages are being
509 // lost (they're not sent to the parent frame nor to the children)
510 wxFAIL_MSG(_T("MDI parent frame is not active, "
511 "yet there is no active MDI child?"));
517 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
522 if ( GetClientWindow() )
523 clientWnd
= GetClientWindow()->GetHWND();
527 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
530 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
532 MSG
*pMsg
= (MSG
*)msg
;
534 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
535 m_currentChild
->MSWTranslateMessage(msg
) )
540 if ( m_acceleratorTable
.Translate(this, msg
) )
545 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
547 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
554 // ===========================================================================
556 // ===========================================================================
558 wxMDIChildFrame::wxMDIChildFrame()
562 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
564 const wxString
& title
,
568 const wxString
& name
)
570 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
571 : wxDEFAULT_MDICHILDFRAME_ICON
);
578 m_windowId
= (int)NewControlId();
582 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
= SendMessage(GetWinHwnd(parent
->GetClientWindow()),
638 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
640 //handle = (HWND)LOWORD(Return);
641 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
642 m_hWnd
= (WXHWND
)Return
;
645 wxWinHandleList
->Append((long)GetHWND(), this);
647 // VZ: what's this? an act of piracy?
648 //SetWindowLong(GetHwnd(), 0, (long)this);
650 wxModelessWindows
.Append(this);
654 wxMDIChildFrame::~wxMDIChildFrame()
659 // Set the client size (i.e. leave the calculation of borders etc.
661 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
663 HWND hWnd
= GetHwnd();
666 ::GetClientRect(hWnd
, &rect
);
669 GetWindowRect(hWnd
, &rect2
);
671 // Find the difference between the entire window (title bar and all)
672 // and the client area; add this to the new client size to move the
674 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
675 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
680 GetStatusBar()->GetSize(&sx
, &sy
);
685 point
.x
= rect2
.left
;
688 // If there's an MDI parent, must subtract the parent's top left corner
689 // since MoveWindow moves relative to the parent
690 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
691 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
693 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
695 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
696 event
.SetEventObject( this );
697 GetEventHandler()->ProcessEvent(event
);
700 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
703 GetWindowRect(GetHwnd(), &rect
);
708 // Since we now have the absolute screen coords,
709 // if there's a parent we must subtract its top left corner
710 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
711 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
717 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
;
728 // ---------------------------------------------------------------------------
730 // ---------------------------------------------------------------------------
732 void wxMDIChildFrame::Maximize(bool maximize
)
734 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
735 if ( parent
&& parent
->GetClientWindow() )
737 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
738 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
739 (WPARAM
)GetHwnd(), 0);
743 void wxMDIChildFrame::Restore()
745 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
746 if ( parent
&& parent
->GetClientWindow() )
748 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
749 (WPARAM
) GetHwnd(), 0);
753 void wxMDIChildFrame::Activate()
755 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
756 if ( parent
&& parent
->GetClientWindow() )
758 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
759 (WPARAM
) GetHwnd(), 0);
763 // ---------------------------------------------------------------------------
764 // MDI window proc and message handlers
765 // ---------------------------------------------------------------------------
767 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
772 bool processed
= FALSE
;
780 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
783 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
787 case WM_GETMINMAXINFO
:
788 // let the default window proc calculate the size of MDI children
789 // frames because it is based on the size of the MDI client window,
790 // not on the values specified in wxWindow m_min/max variables
791 return MSWDefWindowProc(message
, wParam
, lParam
);
796 WXHWND hwndAct
, hwndDeact
;
797 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
799 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
804 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
805 // scrollbars if necessary
810 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
812 MSWDefWindowProc(message
, wParam
, lParam
);
816 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
817 // the message (the base class version does not)
818 return MSWDefWindowProc(message
, wParam
, lParam
);
820 case WM_WINDOWPOSCHANGING
:
821 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
826 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
831 bool wxMDIChildFrame::HandleSize(int x
, int y
, WXUINT id
)
833 HWND hwnd
= GetHwnd();
835 if ( !hwnd
|| hwnd
== invalidHandle
)
854 // forward WM_SIZE to status bar control
855 #if wxUSE_NATIVE_STATUSBAR
856 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
858 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
859 event
.SetEventObject( m_frameStatusBar
);
861 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
863 #endif // wxUSE_NATIVE_STATUSBAR
868 return wxWindow::HandleSize(x
, y
, id
);
876 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
878 // In case it's e.g. a toolbar.
881 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
883 return win
->MSWCommand(cmd
, id
);
886 if (wxCurrentPopupMenu
)
888 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
889 wxCurrentPopupMenu
= NULL
;
890 if (popupMenu
->MSWCommand(cmd
, id
))
894 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
905 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
909 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
915 if ( m_hWnd
== hwndAct
)
918 parent
->m_currentChild
= this;
920 HMENU child_menu
= (HMENU
)GetWinMenu();
923 parent
->m_parentFrameActive
= FALSE
;
925 menuToSet
= child_menu
;
928 else if ( m_hWnd
== hwndDeact
)
930 wxASSERT_MSG( parent
->m_currentChild
== this,
931 _T("can't deactivate MDI child which wasn't active!") );
934 parent
->m_currentChild
= NULL
;
936 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
939 parent
->m_parentFrameActive
= TRUE
;
941 menuToSet
= parent_menu
;
946 // we have nothing to with it
952 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
954 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
957 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
958 event
.SetEventObject( this );
960 return GetEventHandler()->ProcessEvent(event
);
963 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
965 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
966 #if defined(__WIN95__)
967 if (!(lpPos
->flags
& SWP_NOSIZE
))
970 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
971 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
972 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
974 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
975 lpPos
->x
= rectClient
.left
;
976 lpPos
->y
= rectClient
.top
;
977 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
978 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
980 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
981 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
983 pFrameWnd
->GetToolBar()->Refresh();
991 // ---------------------------------------------------------------------------
992 // MDI specific message translation/preprocessing
993 // ---------------------------------------------------------------------------
995 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
997 return DefMDIChildProc(GetHwnd(),
998 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1001 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1003 return m_acceleratorTable
.Translate(GetParent(), msg
);
1006 // ---------------------------------------------------------------------------
1008 // ---------------------------------------------------------------------------
1010 void wxMDIChildFrame::MSWDestroyWindow()
1012 MSWDetachWindowMenu();
1013 invalidHandle
= GetHwnd();
1015 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1017 // Must make sure this handle is invalidated (set to NULL) since all sorts
1018 // of things could happen after the child client is destroyed, but before
1019 // the wxFrame is destroyed.
1021 HWND oldHandle
= (HWND
)GetHWND();
1022 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1023 (WPARAM
)oldHandle
, 0);
1028 ::DestroyMenu((HMENU
) m_hMenu
);
1034 // Change the client window's extended style so we don't get a client edge
1035 // style when a child is maximised (a double border looks silly.)
1036 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1038 #if defined(__WIN95__)
1039 RECT
*rect
= (RECT
*)vrect
;
1040 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1041 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1042 if (!pChild
|| (pChild
== this))
1044 DWORD dwStyle
= ::GetWindowLong(GetWinHwnd(pFrameWnd
->GetClientWindow()), GWL_EXSTYLE
);
1045 DWORD dwThisStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1046 DWORD dwNewStyle
= dwStyle
;
1047 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1048 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1050 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1052 if (dwStyle
!= dwNewStyle
)
1054 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1055 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1056 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1057 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1058 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1059 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1062 ::GetClientRect(hwnd
, rect
);
1072 // ===========================================================================
1073 // wxMDIClientWindow: the window of predefined (by Windows) class which
1074 // contains the child frames
1075 // ===========================================================================
1077 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1079 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1081 CLIENTCREATESTRUCT ccs
;
1082 m_windowStyle
= style
;
1085 ccs
.hWindowMenu
= (HMENU
)parent
->GetWindowMenu();
1086 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1088 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1089 if ( style
& wxHSCROLL
)
1090 msStyle
|= WS_HSCROLL
;
1091 if ( style
& wxVSCROLL
)
1092 msStyle
|= WS_VSCROLL
;
1094 #if defined(__WIN95__)
1095 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1101 m_hWnd
= (WXHWND
)::CreateWindowEx
1111 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1114 wxLogLastError("CreateWindowEx(MDI client)");
1119 SubclassWin(m_hWnd
);
1125 // Explicitly call default scroll behaviour
1126 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1128 // Note: for client windows, the scroll position is not set in
1129 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1130 // scroll position we're at.
1131 // This makes it hard to paint patterns or bitmaps in the background,
1132 // and have the client area scrollable as well.
1134 if ( event
.GetOrientation() == wxHORIZONTAL
)
1135 m_scrollX
= event
.GetPosition(); // Always returns zero!
1137 m_scrollY
= event
.GetPosition(); // Always returns zero!
1142 // ---------------------------------------------------------------------------
1143 // non member functions
1144 // ---------------------------------------------------------------------------
1146 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1148 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1150 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
);
1152 0, MAKELPARAM(hmenuFrame
, hmenuWindow
));
1155 // update menu bar of the parent window
1156 wxWindow
*parent
= win
->GetParent();
1157 wxCHECK_RET( parent
, _T("MDI client without parent frame? weird...") );
1159 ::DrawMenuBar(GetWinHwnd(parent
));
1162 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1164 // Try to insert Window menu in front of Help, otherwise append it.
1165 HMENU hmenu
= (HMENU
)menu
;
1166 int N
= GetMenuItemCount(hmenu
);
1167 bool success
= FALSE
;
1168 for ( int i
= 0; i
< N
; i
++ )
1171 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1174 wxLogLastError(_T("GetMenuString"));
1179 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_T("Help")) )
1182 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1183 (UINT
)subMenu
, _T("&Window"));
1190 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _T("&Window"));
1193 MDISetMenu(win
, hmenu
, subMenu
);
1196 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1197 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1201 *hwndAct
= (WXHWND
)lParam
;
1202 *hwndDeact
= (WXHWND
)wParam
;
1204 *activate
= (WXWORD
)wParam
;
1205 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1206 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1207 #endif // Win32/Win16