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"
39 #include "wx/statusbr.h"
41 #include "wx/settings.h"
47 #include "wx/msw/private.h"
49 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
50 #include "wx/msw/statbr95.h"
54 #include "wx/toolbar.h"
55 #endif // wxUSE_TOOLBAR
59 // ---------------------------------------------------------------------------
61 // ---------------------------------------------------------------------------
63 extern wxWindowList wxModelessWindows
; // from dialog.cpp
64 extern wxMenu
*wxCurrentPopupMenu
;
66 extern const wxChar
*wxMDIFrameClassName
;
67 extern const wxChar
*wxMDIChildFrameClassName
;
68 extern wxWindow
*wxWndHook
; // from window.cpp
70 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
71 extern void wxRemoveHandleAssociation(wxWindow
*win
);
73 static HWND invalidHandle
= 0;
75 // ---------------------------------------------------------------------------
77 // ---------------------------------------------------------------------------
79 static const int IDM_WINDOWTILE
= 4001;
80 static const int IDM_WINDOWTILEHOR
= 4001;
81 static const int IDM_WINDOWCASCADE
= 4002;
82 static const int IDM_WINDOWICONS
= 4003;
83 static const int IDM_WINDOWNEXT
= 4004;
84 static const int IDM_WINDOWTILEVERT
= 4005;
86 // This range gives a maximum of 500 MDI children. Should be enough :-)
87 static const int wxFIRST_MDI_CHILD
= 4100;
88 static const int wxLAST_MDI_CHILD
= 4600;
90 // Status border dimensions
91 static const int wxTHICK_LINE_BORDER
= 3;
92 static const int wxTHICK_LINE_WIDTH
= 1;
94 // ---------------------------------------------------------------------------
96 // ---------------------------------------------------------------------------
98 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
99 // of the parent of win (which is supposed to be the MDI client window)
100 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
102 // insert the window menu (subMenu) into menu just before "Help" submenu or at
103 // the very end if not found
104 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
106 // Remove the window menu
107 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
109 // is this an id of an MDI child?
110 inline bool IsMdiCommandId(int id
)
112 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
115 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
116 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
118 // ===========================================================================
120 // ===========================================================================
122 // ---------------------------------------------------------------------------
124 // ---------------------------------------------------------------------------
126 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
127 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
128 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
130 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
131 EVT_SIZE(wxMDIParentFrame::OnSize
)
132 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
135 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
136 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
139 // ===========================================================================
140 // wxMDIParentFrame: the frame which contains the client window which manages
142 // ===========================================================================
144 wxMDIParentFrame::wxMDIParentFrame()
146 m_clientWindow
= NULL
;
147 m_currentChild
= NULL
;
148 m_windowMenu
= (wxMenu
*) NULL
;
149 m_parentFrameActive
= TRUE
;
152 bool wxMDIParentFrame::Create(wxWindow
*parent
,
154 const wxString
& title
,
158 const wxString
& name
)
160 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
162 m_clientWindow
= NULL
;
163 m_currentChild
= NULL
;
165 if (style
& wxFRAME_NO_WINDOW_MENU
)
166 m_windowMenu
= (wxMenu
*) NULL
;
169 // m_windowMenu = (WXHMENU) ::LoadMenu(wxGetInstance(), wxT("wxWindowMenu"));
170 m_windowMenu
= new wxMenu
;
173 m_windowMenu
->Append(4002, wxT("&Cascade"));
174 m_windowMenu
->Append(4001, wxT("Tile &Horizontally"));
175 m_windowMenu
->Append(4005, wxT("Tile &Vertically"));
176 m_windowMenu
->AppendSeparator();
177 m_windowMenu
->Append(4003, wxT("&Arrange Icons"));
178 m_windowMenu
->Append(4004, wxT("&Next"));
181 m_parentFrameActive
= TRUE
;
184 wxTopLevelWindows
.Append(this);
187 m_windowStyle
= style
;
189 if (parent
) parent
->AddChild(this);
194 m_windowId
= (int)NewControlId();
201 DWORD msflags
= WS_OVERLAPPED
;
202 if (style
& wxMINIMIZE_BOX
)
203 msflags
|= WS_MINIMIZEBOX
;
204 if (style
& wxMAXIMIZE_BOX
)
205 msflags
|= WS_MAXIMIZEBOX
;
206 if (style
& wxTHICK_FRAME
)
207 msflags
|= WS_THICKFRAME
;
208 if (style
& wxSYSTEM_MENU
)
209 msflags
|= WS_SYSMENU
;
210 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
211 msflags
|= WS_MINIMIZE
;
212 if (style
& wxMAXIMIZE
)
213 msflags
|= WS_MAXIMIZE
;
214 if (style
& wxCAPTION
)
215 msflags
|= WS_CAPTION
;
217 if (style
& wxCLIP_CHILDREN
)
218 msflags
|= WS_CLIPCHILDREN
;
220 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
223 wxModelessWindows
.Append(this);
228 wxMDIParentFrame::~wxMDIParentFrame()
231 // already delete by DestroyChildren()
232 m_frameToolBar
= NULL
;
234 // ::DestroyMenu((HMENU)m_windowMenu);
238 m_windowMenu
= (wxMenu
*) NULL
;
241 if ( m_clientWindow
)
243 if ( m_clientWindow
->MSWGetOldWndProc() )
244 m_clientWindow
->UnsubclassWin();
246 m_clientWindow
->SetHWND(0);
247 delete m_clientWindow
;
251 void wxMDIParentFrame::InternalSetMenuBar()
253 // HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
255 m_parentFrameActive
= TRUE
;
257 HMENU subMenu
= (HMENU
) 0;
259 subMenu
= (HMENU
) GetWindowMenu()->GetHMenu();
261 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
264 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
270 // Remove old window menu
271 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
275 m_windowMenu
= (wxMenu
*) NULL
;
281 InsertWindowMenu(GetClientWindow(), m_hMenu
, (HMENU
) m_windowMenu
->GetHMenu());
285 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
287 if ( GetClientWindow() )
290 GetClientSize(&width
, &height
);
292 GetClientWindow()->SetSize(0, 0, width
, height
);
296 // Returns the active MDI child window
297 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
299 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
300 WM_MDIGETACTIVE
, 0, 0L);
304 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
307 // Create the client window class (don't Create the window, just return a new
309 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
311 return new wxMDIClientWindow
;
314 // Responds to colour changes, and passes event on to children.
315 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
317 if ( m_clientWindow
)
319 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
320 m_clientWindow
->Refresh();
326 // ---------------------------------------------------------------------------
328 // ---------------------------------------------------------------------------
330 void wxMDIParentFrame::Cascade()
332 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
335 // TODO: add a direction argument (hor/vert)
336 void wxMDIParentFrame::Tile()
338 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
341 void wxMDIParentFrame::ArrangeIcons()
343 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
346 void wxMDIParentFrame::ActivateNext()
348 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
351 void wxMDIParentFrame::ActivatePrevious()
353 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
356 // ---------------------------------------------------------------------------
357 // the MDI parent frame window proc
358 // ---------------------------------------------------------------------------
360 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
365 bool processed
= FALSE
;
371 WXWORD state
, minimized
;
373 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
375 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
383 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
385 (void)HandleCommand(id
, cmd
, hwnd
);
387 // even if the frame didn't process it, there is no need to try it
388 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
389 // so pretend we processed the message anyhow
393 // always pass this message DefFrameProc(), otherwise MDI menu
394 // commands (and sys commands - more surprizingly!) won't work
395 MSWDefWindowProc(message
, wParam
, lParam
);
399 m_clientWindow
= OnCreateClient();
400 // Uses own style for client style
401 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
403 wxLogMessage(_("Failed to create MDI parent frame."));
414 // we erase background ourselves
422 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
424 if ( m_parentFrameActive
)
426 processed
= HandleMenuSelect(item
, flags
, hmenu
);
428 else if (m_currentChild
)
430 processed
= m_currentChild
->
431 HandleMenuSelect(item
, flags
, hmenu
);
437 // as we don't (usually) resize the MDI client to exactly fit the
438 // client area (we put it below the toolbar, above statusbar &c),
439 // we should not pass this one to DefFrameProc
444 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
449 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
451 bool processed
= FALSE
;
453 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
459 // If this window is an MDI parent, we must also send an OnActivate message
460 // to the current child.
461 if ( (m_currentChild
!= NULL
) &&
462 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
464 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
465 event
.SetEventObject( m_currentChild
);
466 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
473 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
475 // In case it's e.g. a toolbar.
478 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
480 return win
->MSWCommand(cmd
, id
);
483 // is it one of standard MDI commands?
488 case IDM_WINDOWCASCADE
:
490 wParam
= MDITILE_SKIPDISABLED
;
493 case IDM_WINDOWTILEHOR
:
494 wParam
|= MDITILE_HORIZONTAL
;
497 case IDM_WINDOWTILEVERT
:
499 wParam
= MDITILE_VERTICAL
;
501 wParam
|= MDITILE_SKIPDISABLED
;
504 case IDM_WINDOWICONS
:
505 msg
= WM_MDIICONARRANGE
;
518 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
523 // FIXME VZ: what does this test do??
526 return FALSE
; // Get WndProc to call default proc
529 if ( IsMdiCommandId(id
) )
531 wxWindowList::Node
* node
= GetChildren().GetFirst();
534 wxWindow
* child
= node
->GetData();
535 if ( child
->GetHWND() )
537 long childId
= wxGetWindowId(child
->GetHWND());
538 if (childId
== (long)id
)
540 ::SendMessage( GetWinHwnd(GetClientWindow()),
542 (WPARAM
)child
->GetHWND(), 0);
546 node
= node
->GetNext();
549 else if ( m_parentFrameActive
)
551 return ProcessCommand(id
);
553 else if ( m_currentChild
)
555 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
559 // this shouldn't happen because it means that our messages are being
560 // lost (they're not sent to the parent frame nor to the children)
561 wxFAIL_MSG(wxT("MDI parent frame is not active, "
562 "yet there is no active MDI child?"));
568 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
573 if ( GetClientWindow() )
574 clientWnd
= GetClientWindow()->GetHWND();
578 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
581 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
583 MSG
*pMsg
= (MSG
*)msg
;
585 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
586 m_currentChild
->MSWTranslateMessage(msg
) )
591 if ( m_acceleratorTable
.Translate(this, msg
) )
596 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
598 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
605 // ===========================================================================
607 // ===========================================================================
609 wxMDIChildFrame::wxMDIChildFrame()
613 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
615 const wxString
& title
,
619 const wxString
& name
)
621 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
622 : wxDEFAULT_MDICHILDFRAME_ICON
);
629 m_windowId
= (int)NewControlId();
633 parent
->AddChild(this);
645 mcs
.szClass
= wxMDIChildFrameClassName
;
647 mcs
.hOwner
= wxGetInstance();
651 mcs
.x
= CW_USEDEFAULT
;
656 mcs
.y
= CW_USEDEFAULT
;
661 mcs
.cx
= CW_USEDEFAULT
;
666 mcs
.cy
= CW_USEDEFAULT
;
668 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
669 if (style
& wxMINIMIZE_BOX
)
670 msflags
|= WS_MINIMIZEBOX
;
671 if (style
& wxMAXIMIZE_BOX
)
672 msflags
|= WS_MAXIMIZEBOX
;
673 if (style
& wxTHICK_FRAME
)
674 msflags
|= WS_THICKFRAME
;
675 if (style
& wxSYSTEM_MENU
)
676 msflags
|= WS_SYSMENU
;
677 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
678 msflags
|= WS_MINIMIZE
;
679 if (style
& wxMAXIMIZE
)
680 msflags
|= WS_MAXIMIZE
;
681 if (style
& wxCAPTION
)
682 msflags
|= WS_CAPTION
;
688 DWORD Return
= SendMessage(GetWinHwnd(parent
->GetClientWindow()),
689 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
691 //handle = (HWND)LOWORD(Return);
692 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
693 m_hWnd
= (WXHWND
)Return
;
696 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
698 // VZ: what's this? an act of piracy?
699 //SetWindowLong(GetHwnd(), 0, (long)this);
701 wxModelessWindows
.Append(this);
705 wxMDIChildFrame::~wxMDIChildFrame()
710 // Set the client size (i.e. leave the calculation of borders etc.
712 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
714 HWND hWnd
= GetHwnd();
717 ::GetClientRect(hWnd
, &rect
);
720 GetWindowRect(hWnd
, &rect2
);
722 // Find the difference between the entire window (title bar and all)
723 // and the client area; add this to the new client size to move the
725 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
726 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
728 if (GetStatusBar() && GetStatusBar()->IsShown())
731 GetStatusBar()->GetSize(&sx
, &sy
);
736 point
.x
= rect2
.left
;
739 // If there's an MDI parent, must subtract the parent's top left corner
740 // since MoveWindow moves relative to the parent
741 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
742 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
744 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
746 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
747 event
.SetEventObject( this );
748 GetEventHandler()->ProcessEvent(event
);
751 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
754 GetWindowRect(GetHwnd(), &rect
);
759 // Since we now have the absolute screen coords,
760 // if there's a parent we must subtract its top left corner
761 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
762 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
768 void wxMDIChildFrame::InternalSetMenuBar()
770 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
772 // HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
773 HMENU subMenu
= (HMENU
) 0;
774 if (parent
->GetWindowMenu())
775 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
777 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
779 parent
->m_parentFrameActive
= FALSE
;
782 // ---------------------------------------------------------------------------
784 // ---------------------------------------------------------------------------
786 void wxMDIChildFrame::Maximize(bool maximize
)
788 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
789 if ( parent
&& parent
->GetClientWindow() )
791 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
792 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
793 (WPARAM
)GetHwnd(), 0);
797 void wxMDIChildFrame::Restore()
799 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
800 if ( parent
&& parent
->GetClientWindow() )
802 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
803 (WPARAM
) GetHwnd(), 0);
807 void wxMDIChildFrame::Activate()
809 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
810 if ( parent
&& parent
->GetClientWindow() )
812 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
813 (WPARAM
) GetHwnd(), 0);
817 // ---------------------------------------------------------------------------
818 // MDI window proc and message handlers
819 // ---------------------------------------------------------------------------
821 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
826 bool processed
= FALSE
;
834 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
837 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
841 case WM_GETMINMAXINFO
:
842 // let the default window proc calculate the size of MDI children
843 // frames because it is based on the size of the MDI client window,
844 // not on the values specified in wxWindow m_min/max variables
845 return MSWDefWindowProc(message
, wParam
, lParam
);
850 WXHWND hwndAct
, hwndDeact
;
851 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
853 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
858 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
859 // scrollbars if necessary
864 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
866 MSWDefWindowProc(message
, wParam
, lParam
);
870 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
871 // the message (the base class version does not)
872 return MSWDefWindowProc(message
, wParam
, lParam
);
874 case WM_WINDOWPOSCHANGING
:
875 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
880 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
885 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
887 // In case it's e.g. a toolbar.
890 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
892 return win
->MSWCommand(cmd
, id
);
895 if (wxCurrentPopupMenu
)
897 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
898 wxCurrentPopupMenu
= NULL
;
899 if (popupMenu
->MSWCommand(cmd
, id
))
903 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
914 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
918 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
924 if ( m_hWnd
== hwndAct
)
927 parent
->m_currentChild
= this;
929 HMENU child_menu
= (HMENU
)GetWinMenu();
932 parent
->m_parentFrameActive
= FALSE
;
934 menuToSet
= child_menu
;
937 else if ( m_hWnd
== hwndDeact
)
939 wxASSERT_MSG( parent
->m_currentChild
== this,
940 wxT("can't deactivate MDI child which wasn't active!") );
943 parent
->m_currentChild
= NULL
;
945 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
948 parent
->m_parentFrameActive
= TRUE
;
950 menuToSet
= parent_menu
;
955 // we have nothing to do with it
961 HMENU subMenu
= (HMENU
) 0;
962 if (parent
->GetWindowMenu())
963 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
965 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
968 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
969 event
.SetEventObject( this );
971 return GetEventHandler()->ProcessEvent(event
);
974 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
976 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
977 #if defined(__WIN95__)
978 if (!(lpPos
->flags
& SWP_NOSIZE
))
981 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
982 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
983 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
985 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
986 lpPos
->x
= rectClient
.left
;
987 lpPos
->y
= rectClient
.top
;
988 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
989 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
991 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
992 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
994 pFrameWnd
->GetToolBar()->Refresh();
1002 // ---------------------------------------------------------------------------
1003 // MDI specific message translation/preprocessing
1004 // ---------------------------------------------------------------------------
1006 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1008 return DefMDIChildProc(GetHwnd(),
1009 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1012 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1014 return m_acceleratorTable
.Translate(GetParent(), msg
);
1017 // ---------------------------------------------------------------------------
1019 // ---------------------------------------------------------------------------
1021 void wxMDIChildFrame::MSWDestroyWindow()
1023 MSWDetachWindowMenu();
1024 invalidHandle
= GetHwnd();
1026 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1028 // Must make sure this handle is invalidated (set to NULL) since all sorts
1029 // of things could happen after the child client is destroyed, but before
1030 // the wxFrame is destroyed.
1032 HWND oldHandle
= (HWND
)GetHWND();
1033 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1034 (WPARAM
)oldHandle
, 0);
1036 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1037 ResetWindowStyle((void*) NULL
);
1043 ::DestroyMenu((HMENU
) m_hMenu
);
1046 wxRemoveHandleAssociation(this);
1050 // Change the client window's extended style so we don't get a client edge
1051 // style when a child is maximised (a double border looks silly.)
1052 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1054 #if defined(__WIN95__)
1055 RECT
*rect
= (RECT
*)vrect
;
1056 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1057 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1058 if (!pChild
|| (pChild
== this))
1060 DWORD dwStyle
= ::GetWindowLong(GetWinHwnd(pFrameWnd
->GetClientWindow()), GWL_EXSTYLE
);
1061 DWORD dwThisStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1062 DWORD dwNewStyle
= dwStyle
;
1063 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1064 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1066 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1068 if (dwStyle
!= dwNewStyle
)
1070 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1071 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1072 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1073 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1074 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1075 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1078 ::GetClientRect(hwnd
, rect
);
1088 // ===========================================================================
1089 // wxMDIClientWindow: the window of predefined (by Windows) class which
1090 // contains the child frames
1091 // ===========================================================================
1093 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1095 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1097 CLIENTCREATESTRUCT ccs
;
1098 m_windowStyle
= style
;
1101 ccs
.hWindowMenu
= (HMENU
) 0;
1102 if (parent
->GetWindowMenu())
1103 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
1104 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1106 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1107 if ( style
& wxHSCROLL
)
1108 msStyle
|= WS_HSCROLL
;
1109 if ( style
& wxVSCROLL
)
1110 msStyle
|= WS_VSCROLL
;
1112 #if defined(__WIN95__)
1113 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1119 m_hWnd
= (WXHWND
)::CreateWindowEx
1129 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1132 wxLogLastError("CreateWindowEx(MDI client)");
1137 SubclassWin(m_hWnd
);
1143 // Explicitly call default scroll behaviour
1144 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1146 // Note: for client windows, the scroll position is not set in
1147 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1148 // scroll position we're at.
1149 // This makes it hard to paint patterns or bitmaps in the background,
1150 // and have the client area scrollable as well.
1152 if ( event
.GetOrientation() == wxHORIZONTAL
)
1153 m_scrollX
= event
.GetPosition(); // Always returns zero!
1155 m_scrollY
= event
.GetPosition(); // Always returns zero!
1160 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1162 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1163 // client area, you can end up with a non-refreshed portion in the client window
1164 // (see OGL studio sample). So check if the position is changed and if so,
1165 // redraw the MDI child frames.
1167 wxPoint oldPos
= GetPosition();
1169 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1171 wxPoint newPos
= GetPosition();
1173 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1177 wxNode
* node
= GetParent()->GetChildren().First();
1180 wxWindow
* child
= (wxWindow
*) node
->Data();
1181 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1183 HWND hWnd
= (HWND
) child
->GetHWND();
1184 ::RedrawWindow(hWnd
, NULL
, NULL
, RDW_FRAME
|RDW_ALLCHILDREN
|RDW_INVALIDATE
);
1186 node
= node
->Next();
1192 // ---------------------------------------------------------------------------
1193 // non member functions
1194 // ---------------------------------------------------------------------------
1196 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1198 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1200 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
);
1202 0, MAKELPARAM(hmenuFrame
, hmenuWindow
));
1205 // update menu bar of the parent window
1206 wxWindow
*parent
= win
->GetParent();
1207 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1209 ::DrawMenuBar(GetWinHwnd(parent
));
1212 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1214 // Try to insert Window menu in front of Help, otherwise append it.
1215 HMENU hmenu
= (HMENU
)menu
;
1219 int N
= GetMenuItemCount(hmenu
);
1220 bool success
= FALSE
;
1221 for ( int i
= 0; i
< N
; i
++ )
1224 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1227 wxLogLastError(wxT("GetMenuString"));
1232 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(wxT("Help")) )
1235 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1236 (UINT
)subMenu
, wxT("&Window"));
1243 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, wxT("&Window"));
1247 MDISetMenu(win
, hmenu
, subMenu
);
1250 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1252 // Try to insert Window menu in front of Help, otherwise append it.
1253 HMENU hmenu
= (HMENU
)menu
;
1254 int N
= GetMenuItemCount(hmenu
);
1255 bool success
= FALSE
;
1256 for ( int i
= 0; i
< N
; i
++ )
1259 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1262 wxLogLastError(wxT("GetMenuString"));
1267 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(wxT("Window")) )
1270 ::RemoveMenu(hmenu
, i
, MF_BYPOSITION
);
1275 // Does passing 0 for the window menu really work with WM_MDISETMENU?
1276 MDISetMenu(win
, hmenu
, 0);
1279 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1280 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1284 *hwndAct
= (WXHWND
)lParam
;
1285 *hwndDeact
= (WXHWND
)wParam
;
1287 *activate
= (WXWORD
)wParam
;
1288 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1289 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1290 #endif // Win32/Win16