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"
43 #include "wx/msw/private.h"
45 #if wxUSE_NATIVE_STATUSBAR
46 #include <wx/msw/statbr95.h>
51 // ---------------------------------------------------------------------------
53 // ---------------------------------------------------------------------------
55 extern wxWindowList wxModelessWindows
; // from dialog.cpp
56 extern wxMenu
*wxCurrentPopupMenu
;
58 extern char wxMDIFrameClassName
[];
59 extern char wxMDIChildFrameClassName
[];
60 extern wxWindow
*wxWndHook
; // from window.cpp
62 extern wxList
*wxWinHandleList
;
64 static HWND invalidHandle
= 0;
66 // ---------------------------------------------------------------------------
68 // ---------------------------------------------------------------------------
70 static const int IDM_WINDOWTILE
= 4001;
71 static const int IDM_WINDOWTILEHOR
= 4001;
72 static const int IDM_WINDOWCASCADE
= 4002;
73 static const int IDM_WINDOWICONS
= 4003;
74 static const int IDM_WINDOWNEXT
= 4004;
75 static const int IDM_WINDOWTILEVERT
= 4005;
77 // This range gives a maximum of 500 MDI children. Should be enough :-)
78 static const int wxFIRST_MDI_CHILD
= 4100;
79 static const int wxLAST_MDI_CHILD
= 4600;
81 // Status border dimensions
82 static const int wxTHICK_LINE_BORDER
= 3;
83 static const int wxTHICK_LINE_WIDTH
= 1;
85 // ---------------------------------------------------------------------------
87 // ---------------------------------------------------------------------------
89 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
90 // of the parent of win (which is supposed to be the MDI client window)
91 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
93 // insert the window menu (subMenu) into menu just before "Help" submenu or at
94 // the very end if not found
95 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
97 // is this an id of an MDI child?
98 inline bool IsMdiCommandId(int id
)
100 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
103 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
104 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
106 // ===========================================================================
108 // ===========================================================================
110 // ---------------------------------------------------------------------------
112 // ---------------------------------------------------------------------------
114 #if !USE_SHARED_LIBRARY
115 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
116 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
117 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
118 #endif // USE_SHARED_LIBRARY
120 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
121 EVT_SIZE(wxMDIParentFrame::OnSize
)
122 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
125 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
126 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
129 // ===========================================================================
130 // wxMDIParentFrame: the frame which contains the client window which manages
132 // ===========================================================================
134 wxMDIParentFrame::wxMDIParentFrame()
136 m_clientWindow
= NULL
;
137 m_currentChild
= NULL
;
139 m_parentFrameActive
= TRUE
;
142 bool wxMDIParentFrame::Create(wxWindow
*parent
,
144 const wxString
& title
,
148 const wxString
& name
)
150 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
152 m_clientWindow
= NULL
;
153 m_currentChild
= NULL
;
155 m_parentFrameActive
= TRUE
;
158 wxTopLevelWindows
.Append(this);
161 m_windowStyle
= style
;
163 if (parent
) parent
->AddChild(this);
168 m_windowId
= (int)NewControlId();
175 m_windowMenu
= (WXHMENU
) ::LoadMenu(wxGetInstance(), "wxWindowMenu");
177 DWORD msflags
= WS_OVERLAPPED
;
178 if (style
& wxMINIMIZE_BOX
)
179 msflags
|= WS_MINIMIZEBOX
;
180 if (style
& wxMAXIMIZE_BOX
)
181 msflags
|= WS_MAXIMIZEBOX
;
182 if (style
& wxTHICK_FRAME
)
183 msflags
|= WS_THICKFRAME
;
184 if (style
& wxSYSTEM_MENU
)
185 msflags
|= WS_SYSMENU
;
186 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
187 msflags
|= WS_MINIMIZE
;
188 if (style
& wxMAXIMIZE
)
189 msflags
|= WS_MAXIMIZE
;
190 if (style
& wxCAPTION
)
191 msflags
|= WS_CAPTION
;
193 // Adding WS_CLIPCHILDREN causes children not to be properly
194 // drawn when first displaying them.
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
342 m_clientWindow
= OnCreateClient();
343 // Uses own style for client style
344 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
346 wxLogMessage(_("Failed to create MDI parent frame."));
357 // we erase background ourselves
365 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
367 if ( m_parentFrameActive
)
369 processed
= HandleMenuSelect(item
, flags
, hmenu
);
371 else if (m_currentChild
)
373 processed
= m_currentChild
->
374 HandleMenuSelect(item
, flags
, hmenu
);
381 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
386 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
388 bool processed
= FALSE
;
390 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
396 // If this window is an MDI parent, we must also send an OnActivate message
397 // to the current child.
398 if ( (m_currentChild
!= NULL
) &&
399 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
401 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
402 event
.SetEventObject( m_currentChild
);
403 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
410 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
412 // In case it's e.g. a toolbar.
415 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
417 return win
->MSWCommand(cmd
, id
);
420 // is it one of standard MDI commands?
425 case IDM_WINDOWCASCADE
:
427 wParam
= MDITILE_SKIPDISABLED
;
430 case IDM_WINDOWTILEHOR
:
431 wParam
|= MDITILE_HORIZONTAL
;
434 case IDM_WINDOWTILEVERT
:
436 wParam
= MDITILE_VERTICAL
;
438 wParam
|= MDITILE_SKIPDISABLED
;
441 case IDM_WINDOWICONS
:
442 msg
= WM_MDIICONARRANGE
;
455 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
460 // FIXME VZ: what does this test do??
463 return FALSE
; // Get WndProc to call default proc
466 if ( IsMdiCommandId(id
) )
468 wxWindowList::Node
* node
= GetChildren().GetFirst();
471 wxWindow
* child
= node
->GetData();
472 if ( child
->GetHWND() )
474 long childId
= wxGetWindowId(child
->GetHWND());
477 ::SendMessage( GetWinHwnd(GetClientWindow()),
479 (WPARAM
)child
->GetHWND(), 0);
483 node
= node
->GetNext();
486 else if ( m_parentFrameActive
)
488 return ProcessCommand(id
);
490 else if ( m_currentChild
)
492 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
496 // this shouldn't happen because it means that our messages are being
497 // lost (they're not sent to the parent frame nor to the children)
498 wxFAIL_MSG(_T("MDI parent frame is not active, "
499 "yet there is no active MDI child?"));
505 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
510 if ( GetClientWindow() )
511 clientWnd
= GetClientWindow()->GetHWND();
515 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
518 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
520 MSG
*pMsg
= (MSG
*)msg
;
522 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
523 m_currentChild
->MSWTranslateMessage(msg
) )
528 if ( m_acceleratorTable
.Ok() &&
529 ::TranslateAccelerator(GetHwnd(),
530 GetTableHaccel(m_acceleratorTable
),
536 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
538 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
545 // ===========================================================================
547 // ===========================================================================
549 wxMDIChildFrame::wxMDIChildFrame()
553 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
555 const wxString
& title
,
559 const wxString
& name
)
561 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
562 : wxDEFAULT_MDICHILDFRAME_ICON
);
569 m_windowId
= (int)NewControlId();
573 parent
->AddChild(this);
585 mcs
.szClass
= wxMDIChildFrameClassName
;
587 mcs
.hOwner
= wxGetInstance();
591 mcs
.x
= CW_USEDEFAULT
;
596 mcs
.y
= CW_USEDEFAULT
;
601 mcs
.cx
= CW_USEDEFAULT
;
606 mcs
.cy
= CW_USEDEFAULT
;
608 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
609 if (style
& wxMINIMIZE_BOX
)
610 msflags
|= WS_MINIMIZEBOX
;
611 if (style
& wxMAXIMIZE_BOX
)
612 msflags
|= WS_MAXIMIZEBOX
;
613 if (style
& wxTHICK_FRAME
)
614 msflags
|= WS_THICKFRAME
;
615 if (style
& wxSYSTEM_MENU
)
616 msflags
|= WS_SYSMENU
;
617 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
618 msflags
|= WS_MINIMIZE
;
619 if (style
& wxMAXIMIZE
)
620 msflags
|= WS_MAXIMIZE
;
621 if (style
& wxCAPTION
)
622 msflags
|= WS_CAPTION
;
628 DWORD Return
= SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(),
629 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
631 //handle = (HWND)LOWORD(Return);
632 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
633 m_hWnd
= (WXHWND
)Return
;
635 // This gets reassigned so can't be stored
636 // m_windowId = GetWindowLong((HWND) m_hWnd, GWL_ID);
639 wxWinHandleList
->Append((long)GetHWND(), this);
641 SetWindowLong((HWND
) GetHWND(), 0, (long)this);
643 wxModelessWindows
.Append(this);
647 wxMDIChildFrame::~wxMDIChildFrame()
652 // Set the client size (i.e. leave the calculation of borders etc.
654 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
656 HWND hWnd
= (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
);
693 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
696 GetWindowRect((HWND
) GetHWND(), &rect
);
701 // Since we now have the absolute screen coords,
702 // if there's a parent we must subtract its top left corner
703 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
704 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
710 void wxMDIChildFrame::InternalSetMenuBar()
712 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
714 HMENU subMenu
= GetSubMenu((HMENU
)parent
->GetWindowMenu(), 0);
716 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
718 parent
->m_parentFrameActive
= FALSE
;
721 // ---------------------------------------------------------------------------
723 // ---------------------------------------------------------------------------
725 void wxMDIChildFrame::Maximize()
727 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
728 if ( parent
&& parent
->GetClientWindow() )
729 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIMAXIMIZE
, (WPARAM
) (HWND
) GetHWND(), 0);
732 void wxMDIChildFrame::Restore()
734 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
735 if ( parent
&& parent
->GetClientWindow() )
736 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIRESTORE
, (WPARAM
) (HWND
) GetHWND(), 0);
739 void wxMDIChildFrame::Activate()
741 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
742 if ( parent
&& parent
->GetClientWindow() )
743 ::SendMessage( (HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIACTIVATE
, (WPARAM
) (HWND
) GetHWND(), 0);
746 // ---------------------------------------------------------------------------
747 // MDI window proc and message handlers
748 // ---------------------------------------------------------------------------
750 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
755 bool processed
= FALSE
;
763 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
766 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
771 processed
= HandleSize(LOWORD(lParam
), HIWORD(lParam
), wParam
);
774 case WM_GETMINMAXINFO
:
775 // let the default window proc calculate the size of MDI children
776 // frames because it is based on the size of the MDI client window,
777 // not on the values specified in wxWindow m_min/max variables
778 return MSWDefWindowProc(message
, wParam
, lParam
);
783 WXHWND hwndAct
, hwndDeact
;
784 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
786 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
790 case WM_WINDOWPOSCHANGING
:
791 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
796 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
801 bool wxMDIChildFrame::HandleSize(int x
, int y
, WXUINT id
)
803 HWND hwnd
= GetHwnd();
805 if ( !hwnd
|| hwnd
== invalidHandle
)
824 // forward WM_SIZE to status bar control
825 #if wxUSE_NATIVE_STATUSBAR
826 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
828 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
829 event
.SetEventObject( m_frameStatusBar
);
831 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
833 #endif // wxUSE_NATIVE_STATUSBAR
838 return wxWindow::HandleSize(x
, y
, id
);
846 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
848 // In case it's e.g. a toolbar.
851 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
853 return win
->MSWCommand(cmd
, id
);
856 if (wxCurrentPopupMenu
)
858 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
859 wxCurrentPopupMenu
= NULL
;
860 if (popupMenu
->MSWCommand(cmd
, id
))
864 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
875 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
879 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
885 if ( m_hWnd
== hwndAct
)
888 parent
->m_currentChild
= this;
890 HMENU child_menu
= (HMENU
)GetWinMenu();
893 parent
->m_parentFrameActive
= FALSE
;
895 menuToSet
= child_menu
;
898 else if ( m_hWnd
== hwndDeact
)
900 wxASSERT_MSG( parent
->m_currentChild
== this,
901 _T("can't deactivate MDI child which wasn't active!") );
904 parent
->m_currentChild
= NULL
;
906 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
909 parent
->m_parentFrameActive
= TRUE
;
911 menuToSet
= parent_menu
;
916 // we have nothing to with it
922 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
924 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
927 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
928 event
.SetEventObject( this );
930 return GetEventHandler()->ProcessEvent(event
);
933 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
935 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
936 #if defined(__WIN95__)
937 if (!(lpPos
->flags
& SWP_NOSIZE
))
940 DWORD dwExStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_EXSTYLE
);
941 DWORD dwStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
942 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
944 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
945 lpPos
->x
= rectClient
.left
;
946 lpPos
->y
= rectClient
.top
;
947 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
948 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
950 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
951 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
953 pFrameWnd
->GetToolBar()->Refresh();
961 // ---------------------------------------------------------------------------
962 // MDI specific message translation/preprocessing
963 // ---------------------------------------------------------------------------
965 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
967 return DefMDIChildProc(GetHwnd(),
968 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
971 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
973 MSG
*pMsg
= (MSG
*)msg
;
974 if ( m_acceleratorTable
.Ok() )
976 return ::TranslateAccelerator(GetWinHwnd(GetParent()),
977 GetTableHaccel(m_acceleratorTable
),
984 // ---------------------------------------------------------------------------
986 // ---------------------------------------------------------------------------
988 void wxMDIChildFrame::MSWDestroyWindow()
990 MSWDetachWindowMenu();
991 invalidHandle
= (HWND
) GetHWND();
993 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
995 // Must make sure this handle is invalidated (set to NULL) since all sorts
996 // of things could happen after the child client is destroyed, but before
997 // the wxFrame is destroyed.
999 HWND oldHandle
= (HWND
)GetHWND();
1001 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (WPARAM
)oldHandle
, (LPARAM
)0);
1003 SendMessage((HWND
) parent
->GetClientWindow()->GetHWND(), WM_MDIDESTROY
, (HWND
)oldHandle
, 0);
1009 ::DestroyMenu((HMENU
) m_hMenu
);
1015 // Change the client window's extended style so we don't get a client edge
1016 // style when a child is maximised (a double border looks silly.)
1017 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1019 #if defined(__WIN95__)
1020 RECT
*rect
= (RECT
*)vrect
;
1021 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1022 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1023 if (!pChild
|| (pChild
== this))
1025 DWORD dwStyle
= ::GetWindowLong((HWND
) pFrameWnd
->GetClientWindow()->GetHWND(), GWL_EXSTYLE
);
1026 DWORD dwThisStyle
= ::GetWindowLong((HWND
) GetHWND(), GWL_STYLE
);
1027 DWORD dwNewStyle
= dwStyle
;
1028 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1029 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1031 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1033 if (dwStyle
!= dwNewStyle
)
1035 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1036 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1037 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1038 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1039 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1040 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1043 ::GetClientRect(hwnd
, rect
);
1053 // ===========================================================================
1054 // wxMDIClientWindow: the window of predefined (by Windows) class which
1055 // contains the child frames
1056 // ===========================================================================
1058 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1060 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1062 CLIENTCREATESTRUCT ccs
;
1063 m_windowStyle
= style
;
1066 ccs
.hWindowMenu
= (HMENU
)parent
->GetWindowMenu();
1067 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1069 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1070 if ( style
& wxHSCROLL
)
1071 msStyle
|= WS_HSCROLL
;
1072 if ( style
& wxVSCROLL
)
1073 msStyle
|= WS_VSCROLL
;
1075 #if defined(__WIN95__)
1076 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1082 m_hWnd
= (WXHWND
)::CreateWindowEx
1092 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1095 wxLogLastError("CreateWindowEx(MDI client)");
1100 SubclassWin(m_hWnd
);
1106 // Explicitly call default scroll behaviour
1107 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1109 // Note: for client windows, the scroll position is not set in
1110 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1111 // scroll position we're at.
1112 // This makes it hard to paint patterns or bitmaps in the background,
1113 // and have the client area scrollable as well.
1115 if ( event
.GetOrientation() == wxHORIZONTAL
)
1116 m_scrollX
= event
.GetPosition(); // Always returns zero!
1118 m_scrollY
= event
.GetPosition(); // Always returns zero!
1123 // ---------------------------------------------------------------------------
1124 // non member functions
1125 // ---------------------------------------------------------------------------
1127 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1129 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1131 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
);
1133 0, MAKELPARAM(hmenuFrame
, hmenuWindow
));
1136 // update menu bar of the parent window
1137 wxWindow
*parent
= win
->GetParent();
1138 wxCHECK_RET( parent
, "MDI client without parent frame? weird..." );
1140 ::DrawMenuBar(GetWinHwnd(parent
));
1143 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1145 // Try to insert Window menu in front of Help, otherwise append it.
1146 HMENU hmenu
= (HMENU
)menu
;
1147 int N
= GetMenuItemCount(hmenu
);
1148 bool success
= FALSE
;
1149 for ( int i
= 0; i
< N
; i
++ )
1152 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1155 wxLogLastError("GetMenuString");
1160 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1163 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1164 (UINT
)subMenu
, "&Window");
1171 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1174 MDISetMenu(win
, hmenu
, subMenu
);
1177 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1178 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1182 *hwndAct
= (WXHWND
)lParam
;
1183 *hwndDeact
= (WXHWND
)wParam
;
1185 *activate
= (WXWORD
)wParam
;
1186 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1187 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1188 #endif // Win32/Win16