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
;
233 m_frameStatusBar
= NULL
;
235 // ::DestroyMenu((HMENU)m_windowMenu);
239 m_windowMenu
= (wxMenu
*) NULL
;
242 if ( m_clientWindow
)
244 if ( m_clientWindow
->MSWGetOldWndProc() )
245 m_clientWindow
->UnsubclassWin();
247 m_clientWindow
->SetHWND(0);
248 delete m_clientWindow
;
252 void wxMDIParentFrame::InternalSetMenuBar()
254 // HMENU subMenu = GetSubMenu((HMENU) m_windowMenu, 0);
256 m_parentFrameActive
= TRUE
;
258 HMENU subMenu
= (HMENU
) 0;
260 subMenu
= (HMENU
) GetWindowMenu()->GetHMenu();
262 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
265 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
271 // Remove old window menu
272 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
276 m_windowMenu
= (wxMenu
*) NULL
;
282 InsertWindowMenu(GetClientWindow(), m_hMenu
, (HMENU
) m_windowMenu
->GetHMenu());
286 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
288 if ( GetClientWindow() )
291 GetClientSize(&width
, &height
);
293 GetClientWindow()->SetSize(0, 0, width
, height
);
297 // Returns the active MDI child window
298 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
300 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
301 WM_MDIGETACTIVE
, 0, 0L);
305 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
308 // Create the client window class (don't Create the window, just return a new
310 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
312 return new wxMDIClientWindow
;
315 // Responds to colour changes, and passes event on to children.
316 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
318 if ( m_clientWindow
)
320 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
321 m_clientWindow
->Refresh();
327 // ---------------------------------------------------------------------------
329 // ---------------------------------------------------------------------------
331 void wxMDIParentFrame::Cascade()
333 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
336 // TODO: add a direction argument (hor/vert)
337 void wxMDIParentFrame::Tile()
339 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
342 void wxMDIParentFrame::ArrangeIcons()
344 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
347 void wxMDIParentFrame::ActivateNext()
349 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
352 void wxMDIParentFrame::ActivatePrevious()
354 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
357 // ---------------------------------------------------------------------------
358 // the MDI parent frame window proc
359 // ---------------------------------------------------------------------------
361 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
366 bool processed
= FALSE
;
372 WXWORD state
, minimized
;
374 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
376 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
384 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
386 (void)HandleCommand(id
, cmd
, hwnd
);
388 // even if the frame didn't process it, there is no need to try it
389 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
390 // so pretend we processed the message anyhow
394 // always pass this message DefFrameProc(), otherwise MDI menu
395 // commands (and sys commands - more surprizingly!) won't work
396 MSWDefWindowProc(message
, wParam
, lParam
);
400 m_clientWindow
= OnCreateClient();
401 // Uses own style for client style
402 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
404 wxLogMessage(_("Failed to create MDI parent frame."));
415 // we erase background ourselves
423 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
425 if ( m_parentFrameActive
)
427 processed
= HandleMenuSelect(item
, flags
, hmenu
);
429 else if (m_currentChild
)
431 processed
= m_currentChild
->
432 HandleMenuSelect(item
, flags
, hmenu
);
438 // as we don't (usually) resize the MDI client to exactly fit the
439 // client area (we put it below the toolbar, above statusbar &c),
440 // we should not pass this one to DefFrameProc
445 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
450 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
452 bool processed
= FALSE
;
454 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
460 // If this window is an MDI parent, we must also send an OnActivate message
461 // to the current child.
462 if ( (m_currentChild
!= NULL
) &&
463 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
465 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
466 event
.SetEventObject( m_currentChild
);
467 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
474 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
476 // In case it's e.g. a toolbar.
479 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
481 return win
->MSWCommand(cmd
, id
);
484 // is it one of standard MDI commands?
489 case IDM_WINDOWCASCADE
:
491 wParam
= MDITILE_SKIPDISABLED
;
494 case IDM_WINDOWTILEHOR
:
495 wParam
|= MDITILE_HORIZONTAL
;
498 case IDM_WINDOWTILEVERT
:
500 wParam
= MDITILE_VERTICAL
;
502 wParam
|= MDITILE_SKIPDISABLED
;
505 case IDM_WINDOWICONS
:
506 msg
= WM_MDIICONARRANGE
;
519 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
524 // FIXME VZ: what does this test do??
527 return FALSE
; // Get WndProc to call default proc
530 if ( IsMdiCommandId(id
) )
532 wxWindowList::Node
* node
= GetChildren().GetFirst();
535 wxWindow
* child
= node
->GetData();
536 if ( child
->GetHWND() )
538 long childId
= wxGetWindowId(child
->GetHWND());
539 if (childId
== (long)id
)
541 ::SendMessage( GetWinHwnd(GetClientWindow()),
543 (WPARAM
)child
->GetHWND(), 0);
547 node
= node
->GetNext();
550 else if ( m_parentFrameActive
)
552 return ProcessCommand(id
);
554 else if ( m_currentChild
)
556 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
560 // this shouldn't happen because it means that our messages are being
561 // lost (they're not sent to the parent frame nor to the children)
562 wxFAIL_MSG(wxT("MDI parent frame is not active, "
563 "yet there is no active MDI child?"));
569 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
574 if ( GetClientWindow() )
575 clientWnd
= GetClientWindow()->GetHWND();
579 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
582 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
584 MSG
*pMsg
= (MSG
*)msg
;
586 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
587 m_currentChild
->MSWTranslateMessage(msg
) )
592 if ( m_acceleratorTable
.Translate(this, msg
) )
597 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
599 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
606 // ===========================================================================
608 // ===========================================================================
610 wxMDIChildFrame::wxMDIChildFrame()
614 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
616 const wxString
& title
,
620 const wxString
& name
)
622 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
623 : wxDEFAULT_MDICHILDFRAME_ICON
);
630 m_windowId
= (int)NewControlId();
634 parent
->AddChild(this);
646 mcs
.szClass
= wxMDIChildFrameClassName
;
648 mcs
.hOwner
= wxGetInstance();
652 mcs
.x
= CW_USEDEFAULT
;
657 mcs
.y
= CW_USEDEFAULT
;
662 mcs
.cx
= CW_USEDEFAULT
;
667 mcs
.cy
= CW_USEDEFAULT
;
669 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
670 if (style
& wxMINIMIZE_BOX
)
671 msflags
|= WS_MINIMIZEBOX
;
672 if (style
& wxMAXIMIZE_BOX
)
673 msflags
|= WS_MAXIMIZEBOX
;
674 if (style
& wxTHICK_FRAME
)
675 msflags
|= WS_THICKFRAME
;
676 if (style
& wxSYSTEM_MENU
)
677 msflags
|= WS_SYSMENU
;
678 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
679 msflags
|= WS_MINIMIZE
;
680 if (style
& wxMAXIMIZE
)
681 msflags
|= WS_MAXIMIZE
;
682 if (style
& wxCAPTION
)
683 msflags
|= WS_CAPTION
;
689 DWORD Return
= SendMessage(GetWinHwnd(parent
->GetClientWindow()),
690 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
692 //handle = (HWND)LOWORD(Return);
693 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
694 m_hWnd
= (WXHWND
)Return
;
697 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
699 // VZ: what's this? an act of piracy?
700 //SetWindowLong(GetHwnd(), 0, (long)this);
702 wxModelessWindows
.Append(this);
706 wxMDIChildFrame::~wxMDIChildFrame()
710 // already delete by DestroyChildren()
711 m_frameToolBar
= NULL
;
712 m_frameStatusBar
= NULL
;
717 // Set the client size (i.e. leave the calculation of borders etc.
719 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
721 HWND hWnd
= GetHwnd();
724 ::GetClientRect(hWnd
, &rect
);
727 GetWindowRect(hWnd
, &rect2
);
729 // Find the difference between the entire window (title bar and all)
730 // and the client area; add this to the new client size to move the
732 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
733 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
735 if (GetStatusBar() && GetStatusBar()->IsShown())
738 GetStatusBar()->GetSize(&sx
, &sy
);
743 point
.x
= rect2
.left
;
746 // If there's an MDI parent, must subtract the parent's top left corner
747 // since MoveWindow moves relative to the parent
748 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
749 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
751 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
753 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
754 event
.SetEventObject( this );
755 GetEventHandler()->ProcessEvent(event
);
758 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
761 GetWindowRect(GetHwnd(), &rect
);
766 // Since we now have the absolute screen coords,
767 // if there's a parent we must subtract its top left corner
768 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
769 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
775 void wxMDIChildFrame::InternalSetMenuBar()
777 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
779 // HMENU subMenu = GetSubMenu((HMENU)parent->GetWindowMenu(), 0);
780 HMENU subMenu
= (HMENU
) 0;
781 if (parent
->GetWindowMenu())
782 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
784 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
786 parent
->m_parentFrameActive
= FALSE
;
789 // ---------------------------------------------------------------------------
791 // ---------------------------------------------------------------------------
793 void wxMDIChildFrame::Maximize(bool maximize
)
795 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
796 if ( parent
&& parent
->GetClientWindow() )
798 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
799 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
800 (WPARAM
)GetHwnd(), 0);
804 void wxMDIChildFrame::Restore()
806 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
807 if ( parent
&& parent
->GetClientWindow() )
809 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
810 (WPARAM
) GetHwnd(), 0);
814 void wxMDIChildFrame::Activate()
816 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
817 if ( parent
&& parent
->GetClientWindow() )
819 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
820 (WPARAM
) GetHwnd(), 0);
824 // ---------------------------------------------------------------------------
825 // MDI window proc and message handlers
826 // ---------------------------------------------------------------------------
828 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
833 bool processed
= FALSE
;
841 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
844 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
848 case WM_GETMINMAXINFO
:
849 // let the default window proc calculate the size of MDI children
850 // frames because it is based on the size of the MDI client window,
851 // not on the values specified in wxWindow m_min/max variables
852 return MSWDefWindowProc(message
, wParam
, lParam
);
857 WXHWND hwndAct
, hwndDeact
;
858 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
860 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
865 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
866 // scrollbars if necessary
871 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
873 MSWDefWindowProc(message
, wParam
, lParam
);
877 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
878 // the message (the base class version does not)
879 return MSWDefWindowProc(message
, wParam
, lParam
);
881 case WM_WINDOWPOSCHANGING
:
882 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
887 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
892 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
894 // In case it's e.g. a toolbar.
897 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
899 return win
->MSWCommand(cmd
, id
);
902 if (wxCurrentPopupMenu
)
904 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
905 wxCurrentPopupMenu
= NULL
;
906 if (popupMenu
->MSWCommand(cmd
, id
))
910 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
921 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
925 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
931 if ( m_hWnd
== hwndAct
)
934 parent
->m_currentChild
= this;
936 HMENU child_menu
= (HMENU
)GetWinMenu();
939 parent
->m_parentFrameActive
= FALSE
;
941 menuToSet
= child_menu
;
944 else if ( m_hWnd
== hwndDeact
)
946 wxASSERT_MSG( parent
->m_currentChild
== this,
947 wxT("can't deactivate MDI child which wasn't active!") );
950 parent
->m_currentChild
= NULL
;
952 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
955 parent
->m_parentFrameActive
= TRUE
;
957 menuToSet
= parent_menu
;
962 // we have nothing to do with it
968 HMENU subMenu
= (HMENU
) 0;
969 if (parent
->GetWindowMenu())
970 subMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
972 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
975 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
976 event
.SetEventObject( this );
978 return GetEventHandler()->ProcessEvent(event
);
981 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
983 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
984 #if defined(__WIN95__)
985 if (!(lpPos
->flags
& SWP_NOSIZE
))
988 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
989 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
990 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
992 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
993 lpPos
->x
= rectClient
.left
;
994 lpPos
->y
= rectClient
.top
;
995 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
996 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
998 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
999 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1001 pFrameWnd
->GetToolBar()->Refresh();
1009 // ---------------------------------------------------------------------------
1010 // MDI specific message translation/preprocessing
1011 // ---------------------------------------------------------------------------
1013 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1015 return DefMDIChildProc(GetHwnd(),
1016 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1019 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1021 return m_acceleratorTable
.Translate(GetParent(), msg
);
1024 // ---------------------------------------------------------------------------
1026 // ---------------------------------------------------------------------------
1028 void wxMDIChildFrame::MSWDestroyWindow()
1030 MSWDetachWindowMenu();
1031 invalidHandle
= GetHwnd();
1033 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1035 // Must make sure this handle is invalidated (set to NULL) since all sorts
1036 // of things could happen after the child client is destroyed, but before
1037 // the wxFrame is destroyed.
1039 HWND oldHandle
= (HWND
)GetHWND();
1040 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1041 (WPARAM
)oldHandle
, 0);
1043 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1044 ResetWindowStyle((void*) NULL
);
1050 ::DestroyMenu((HMENU
) m_hMenu
);
1053 wxRemoveHandleAssociation(this);
1057 // Change the client window's extended style so we don't get a client edge
1058 // style when a child is maximised (a double border looks silly.)
1059 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1061 #if defined(__WIN95__)
1062 RECT
*rect
= (RECT
*)vrect
;
1063 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1064 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1065 if (!pChild
|| (pChild
== this))
1067 DWORD dwStyle
= ::GetWindowLong(GetWinHwnd(pFrameWnd
->GetClientWindow()), GWL_EXSTYLE
);
1068 DWORD dwThisStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1069 DWORD dwNewStyle
= dwStyle
;
1070 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1071 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1073 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1075 if (dwStyle
!= dwNewStyle
)
1077 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1078 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1079 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1080 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1081 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1082 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1085 ::GetClientRect(hwnd
, rect
);
1095 // ===========================================================================
1096 // wxMDIClientWindow: the window of predefined (by Windows) class which
1097 // contains the child frames
1098 // ===========================================================================
1100 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1102 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1104 CLIENTCREATESTRUCT ccs
;
1105 m_windowStyle
= style
;
1108 ccs
.hWindowMenu
= (HMENU
) 0;
1109 if (parent
->GetWindowMenu())
1110 ccs
.hWindowMenu
= (HMENU
) parent
->GetWindowMenu()->GetHMenu();
1111 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1113 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1114 if ( style
& wxHSCROLL
)
1115 msStyle
|= WS_HSCROLL
;
1116 if ( style
& wxVSCROLL
)
1117 msStyle
|= WS_VSCROLL
;
1119 #if defined(__WIN95__)
1120 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1126 m_hWnd
= (WXHWND
)::CreateWindowEx
1136 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1139 wxLogLastError("CreateWindowEx(MDI client)");
1144 SubclassWin(m_hWnd
);
1150 // Explicitly call default scroll behaviour
1151 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1153 // Note: for client windows, the scroll position is not set in
1154 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1155 // scroll position we're at.
1156 // This makes it hard to paint patterns or bitmaps in the background,
1157 // and have the client area scrollable as well.
1159 if ( event
.GetOrientation() == wxHORIZONTAL
)
1160 m_scrollX
= event
.GetPosition(); // Always returns zero!
1162 m_scrollY
= event
.GetPosition(); // Always returns zero!
1167 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1169 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1170 // client area, you can end up with a non-refreshed portion in the client window
1171 // (see OGL studio sample). So check if the position is changed and if so,
1172 // redraw the MDI child frames.
1174 wxPoint oldPos
= GetPosition();
1176 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1178 wxPoint newPos
= GetPosition();
1180 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1184 wxNode
* node
= GetParent()->GetChildren().First();
1187 wxWindow
* child
= (wxWindow
*) node
->Data();
1188 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1190 HWND hWnd
= (HWND
) child
->GetHWND();
1191 ::RedrawWindow(hWnd
, NULL
, NULL
, RDW_FRAME
|RDW_ALLCHILDREN
|RDW_INVALIDATE
);
1193 node
= node
->Next();
1199 // ---------------------------------------------------------------------------
1200 // non member functions
1201 // ---------------------------------------------------------------------------
1203 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1205 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1207 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
);
1209 0, MAKELPARAM(hmenuFrame
, hmenuWindow
));
1212 // update menu bar of the parent window
1213 wxWindow
*parent
= win
->GetParent();
1214 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1216 ::DrawMenuBar(GetWinHwnd(parent
));
1219 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1221 // Try to insert Window menu in front of Help, otherwise append it.
1222 HMENU hmenu
= (HMENU
)menu
;
1226 int N
= GetMenuItemCount(hmenu
);
1227 bool success
= FALSE
;
1228 for ( int i
= 0; i
< N
; i
++ )
1231 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1234 wxLogLastError(wxT("GetMenuString"));
1239 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(wxT("Help")) )
1242 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1243 (UINT
)subMenu
, wxT("&Window"));
1250 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, wxT("&Window"));
1254 MDISetMenu(win
, hmenu
, subMenu
);
1257 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1259 // Try to insert Window menu in front of Help, otherwise append it.
1260 HMENU hmenu
= (HMENU
)menu
;
1261 int N
= GetMenuItemCount(hmenu
);
1262 bool success
= FALSE
;
1263 for ( int i
= 0; i
< N
; i
++ )
1266 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1269 wxLogLastError(wxT("GetMenuString"));
1274 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(wxT("Window")) )
1277 ::RemoveMenu(hmenu
, i
, MF_BYPOSITION
);
1282 // Does passing 0 for the window menu really work with WM_MDISETMENU?
1283 MDISetMenu(win
, hmenu
, 0);
1286 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1287 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1291 *hwndAct
= (WXHWND
)lParam
;
1292 *hwndDeact
= (WXHWND
)wParam
;
1294 *activate
= (WXWORD
)wParam
;
1295 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1296 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1297 #endif // Win32/Win16