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 char wxMDIFrameClassName
[];
61 extern char 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(), "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
344 m_clientWindow
= OnCreateClient();
345 // Uses own style for client style
346 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
348 wxLogMessage(_("Failed to create MDI parent frame."));
359 // we erase background ourselves
367 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
369 if ( m_parentFrameActive
)
371 processed
= HandleMenuSelect(item
, flags
, hmenu
);
373 else if (m_currentChild
)
375 processed
= m_currentChild
->
376 HandleMenuSelect(item
, flags
, hmenu
);
383 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
388 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
390 bool processed
= FALSE
;
392 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
398 // If this window is an MDI parent, we must also send an OnActivate message
399 // to the current child.
400 if ( (m_currentChild
!= NULL
) &&
401 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
403 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
404 event
.SetEventObject( m_currentChild
);
405 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
412 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
414 // In case it's e.g. a toolbar.
417 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
419 return win
->MSWCommand(cmd
, id
);
422 // 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 ::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());
479 ::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(_T("MDI parent frame is not active, "
501 "yet there is no active MDI child?"));
507 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
512 if ( GetClientWindow() )
513 clientWnd
= GetClientWindow()->GetHWND();
517 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
520 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
522 MSG
*pMsg
= (MSG
*)msg
;
524 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
525 m_currentChild
->MSWTranslateMessage(msg
) )
530 if ( m_acceleratorTable
.Ok() &&
531 ::TranslateAccelerator(GetHwnd(),
532 GetTableHaccel(m_acceleratorTable
),
538 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
540 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
547 // ===========================================================================
549 // ===========================================================================
551 wxMDIChildFrame::wxMDIChildFrame()
555 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
557 const wxString
& title
,
561 const wxString
& name
)
563 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
564 : wxDEFAULT_MDICHILDFRAME_ICON
);
571 m_windowId
= (int)NewControlId();
575 parent
->AddChild(this);
587 mcs
.szClass
= wxMDIChildFrameClassName
;
589 mcs
.hOwner
= wxGetInstance();
593 mcs
.x
= CW_USEDEFAULT
;
598 mcs
.y
= CW_USEDEFAULT
;
603 mcs
.cx
= CW_USEDEFAULT
;
608 mcs
.cy
= CW_USEDEFAULT
;
610 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
611 if (style
& wxMINIMIZE_BOX
)
612 msflags
|= WS_MINIMIZEBOX
;
613 if (style
& wxMAXIMIZE_BOX
)
614 msflags
|= WS_MAXIMIZEBOX
;
615 if (style
& wxTHICK_FRAME
)
616 msflags
|= WS_THICKFRAME
;
617 if (style
& wxSYSTEM_MENU
)
618 msflags
|= WS_SYSMENU
;
619 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
620 msflags
|= WS_MINIMIZE
;
621 if (style
& wxMAXIMIZE
)
622 msflags
|= WS_MAXIMIZE
;
623 if (style
& wxCAPTION
)
624 msflags
|= WS_CAPTION
;
630 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
631 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
633 //handle = (HWND)LOWORD(Return);
634 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
635 m_hWnd
= (WXHWND
)Return
;
637 // This gets reassigned so can't be stored
638 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
641 wxWinHandleList
->Append((long)GetHWND(), this);
643 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
645 wxModelessWindows
.Append(this);
649 wxMDIChildFrame::~wxMDIChildFrame()
654 // Set the client size (i.e. leave the calculation of borders etc.
656 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
658 HWND 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
);
695 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
698 GetWindowRect((HWND
) GetHWND(), &rect
);
703 // Since we now have the absolute screen coords,
704 // if there's a parent we must subtract its top left corner
705 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
706 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
712 void wxMDIChildFrame::InternalSetMenuBar()
714 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
716 HMENU subMenu
= GetSubMenu((HMENU
)parent
->GetWindowMenu(), 0);
718 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
720 parent
->m_parentFrameActive
= FALSE
;
723 // ---------------------------------------------------------------------------
725 // ---------------------------------------------------------------------------
727 void wxMDIChildFrame::Maximize()
729 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
730 if ( parent
&& parent
->GetClientWindow() )
731 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
734 void wxMDIChildFrame::Restore()
736 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
737 if ( parent
&& parent
->GetClientWindow() )
738 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
741 void wxMDIChildFrame::Activate()
743 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
744 if ( parent
&& parent
->GetClientWindow() )
745 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
748 // ---------------------------------------------------------------------------
749 // MDI window proc and message handlers
750 // ---------------------------------------------------------------------------
752 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
757 bool processed
= FALSE
;
765 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
768 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
773 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
776 case WM_GETMINMAXINFO
:
777 // let the default window proc calculate the size of MDI children
778 // frames because it is based on the size of the MDI client window,
779 // not on the values specified in wxWindow m_min/max variables
780 return MSWDefWindowProc(message
, wParam
, lParam
);
785 WXHWND hwndAct
, hwndDeact
;
786 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
788 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
792 case WM_WINDOWPOSCHANGING
:
793 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
798 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
803 bool wxMDIChildFrame::HandleSize(int x
, int y
, WXUINT id
)
805 HWND hwnd
= GetHwnd();
807 if ( !hwnd
|| hwnd
== invalidHandle
)
826 // forward WM_SIZE to status bar control
827 #if wxUSE_NATIVE_STATUSBAR
828 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
830 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
831 event
.SetEventObject( m_frameStatusBar
);
833 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
835 #endif // wxUSE_NATIVE_STATUSBAR
840 return wxWindow::HandleSize(x
, y
, id
);
848 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
850 // In case it's e.g. a toolbar.
853 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
855 return win
->MSWCommand(cmd
, id
);
858 if (wxCurrentPopupMenu
)
860 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
861 wxCurrentPopupMenu
= NULL
;
862 if (popupMenu
->MSWCommand(cmd
, id
))
866 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
877 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
881 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
887 if ( m_hWnd
== hwndAct
)
890 parent
->m_currentChild
= this;
892 HMENU child_menu
= (HMENU
)GetWinMenu();
895 parent
->m_parentFrameActive
= FALSE
;
897 menuToSet
= child_menu
;
900 else if ( m_hWnd
== hwndDeact
)
902 wxASSERT_MSG( parent
->m_currentChild
== this,
903 _T("can't deactivate MDI child which wasn't active!") );
906 parent
->m_currentChild
= NULL
;
908 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
911 parent
->m_parentFrameActive
= TRUE
;
913 menuToSet
= parent_menu
;
918 // we have nothing to with it
924 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
926 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
929 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
930 event
.SetEventObject( this );
932 return GetEventHandler()->ProcessEvent(event
);
935 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
937 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
938 #if defined(__WIN95__)
939 if (!(lpPos
->flags
& SWP_NOSIZE
))
942 DWORD dwExStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_EXSTYLE
);
943 DWORD dwStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
944 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
946 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
947 lpPos
->x
= rectClient
.left
;
948 lpPos
->y
= rectClient
.top
;
949 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
950 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
952 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
953 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
955 pFrameWnd
->GetToolBar()->Refresh();
963 // ---------------------------------------------------------------------------
964 // MDI specific message translation/preprocessing
965 // ---------------------------------------------------------------------------
967 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
969 return DefMDIChildProc(GetHwnd(),
970 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
973 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
975 MSG
*pMsg
= (MSG
*)msg
;
976 if ( m_acceleratorTable
.Ok() )
978 return ::TranslateAccelerator(GetWinHwnd(GetParent()),
979 GetTableHaccel(m_acceleratorTable
),
986 // ---------------------------------------------------------------------------
988 // ---------------------------------------------------------------------------
990 void wxMDIChildFrame::MSWDestroyWindow()
992 MSWDetachWindowMenu();
993 invalidHandle
= (HWND
) GetHWND();
995 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
997 // Must make sure this handle is invalidated (set to NULL) since all sorts
998 // of things could happen after the child client is destroyed, but before
999 // the wxFrame is destroyed.
1001 HWND oldHandle
= (HWND
)GetHWND();
1003 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
1005 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
1011 ::DestroyMenu((HMENU
) m_hMenu
);
1017 // Change the client window's extended style so we don't get a client edge
1018 // style when a child is maximised (a double border looks silly.)
1019 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1021 #if defined(__WIN95__)
1022 RECT
*rect
= (RECT
*)vrect
;
1023 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1024 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1025 if (!pChild
|| (pChild
== this))
1027 DWORD dwStyle
= ::GetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
);
1028 DWORD dwThisStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1029 DWORD dwNewStyle
= dwStyle
;
1030 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1031 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1033 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1035 if (dwStyle
!= dwNewStyle
)
1037 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1038 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1039 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1040 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1041 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1042 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1045 ::GetClientRect(hwnd
, rect
);
1055 // ===========================================================================
1056 // wxMDIClientWindow: the window of predefined (by Windows) class which
1057 // contains the child frames
1058 // ===========================================================================
1060 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1062 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1064 CLIENTCREATESTRUCT ccs
;
1065 m_windowStyle
= style
;
1068 ccs
.hWindowMenu
= (HMENU
)parent
->GetWindowMenu();
1069 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1071 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1072 if ( style
& wxHSCROLL
)
1073 msStyle
|= WS_HSCROLL
;
1074 if ( style
& wxVSCROLL
)
1075 msStyle
|= WS_VSCROLL
;
1077 #if defined(__WIN95__)
1078 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1084 m_hWnd
= (WXHWND
)::CreateWindowEx
1094 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1097 wxLogLastError("CreateWindowEx(MDI client)");
1102 SubclassWin(m_hWnd
);
1108 // Explicitly call default scroll behaviour
1109 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1111 // Note: for client windows, the scroll position is not set in
1112 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1113 // scroll position we're at.
1114 // This makes it hard to paint patterns or bitmaps in the background,
1115 // and have the client area scrollable as well.
1117 if ( event
.GetOrientation() == wxHORIZONTAL
)
1118 m_scrollX
= event
.GetPosition(); // Always returns zero!
1120 m_scrollY
= event
.GetPosition(); // Always returns zero!
1125 // ---------------------------------------------------------------------------
1126 // non member functions
1127 // ---------------------------------------------------------------------------
1129 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1131 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1133 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
);
1135 0, MAKELPARAM(hmenuFrame
, hmenuWindow
));
1138 // update menu bar of the parent window
1139 wxWindow
*parent
= win
->GetParent();
1140 wxCHECK_RET( parent
, "MDI client without parent frame? weird..." );
1142 ::DrawMenuBar(GetWinHwnd(parent
));
1145 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1147 // Try to insert Window menu in front of Help, otherwise append it.
1148 HMENU hmenu
= (HMENU
)menu
;
1149 int N
= GetMenuItemCount(hmenu
);
1150 bool success
= FALSE
;
1151 for ( int i
= 0; i
< N
; i
++ )
1154 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1157 wxLogLastError("GetMenuString");
1162 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1165 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1166 (UINT
)subMenu
, "&Window");
1173 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1176 MDISetMenu(win
, hmenu
, subMenu
);
1179 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1180 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1184 *hwndAct
= (WXHWND
)lParam
;
1185 *hwndDeact
= (WXHWND
)wParam
;
1187 *activate
= (WXWORD
)wParam
;
1188 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1189 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1190 #endif // Win32/Win16