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 wxChar wxMDIFrameClassName
[];
67 extern wxChar wxMDIChildFrameClassName
[];
68 extern wxWindow
*wxWndHook
; // from window.cpp
70 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
72 static HWND invalidHandle
= 0;
74 // ---------------------------------------------------------------------------
76 // ---------------------------------------------------------------------------
78 static const int IDM_WINDOWTILE
= 4001;
79 static const int IDM_WINDOWTILEHOR
= 4001;
80 static const int IDM_WINDOWCASCADE
= 4002;
81 static const int IDM_WINDOWICONS
= 4003;
82 static const int IDM_WINDOWNEXT
= 4004;
83 static const int IDM_WINDOWTILEVERT
= 4005;
85 // This range gives a maximum of 500 MDI children. Should be enough :-)
86 static const int wxFIRST_MDI_CHILD
= 4100;
87 static const int wxLAST_MDI_CHILD
= 4600;
89 // Status border dimensions
90 static const int wxTHICK_LINE_BORDER
= 3;
91 static const int wxTHICK_LINE_WIDTH
= 1;
93 // ---------------------------------------------------------------------------
95 // ---------------------------------------------------------------------------
97 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
98 // of the parent of win (which is supposed to be the MDI client window)
99 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
101 // insert the window menu (subMenu) into menu just before "Help" submenu or at
102 // the very end if not found
103 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
105 // is this an id of an MDI child?
106 inline bool IsMdiCommandId(int id
)
108 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
111 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
112 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
114 // ===========================================================================
116 // ===========================================================================
118 // ---------------------------------------------------------------------------
120 // ---------------------------------------------------------------------------
122 #if !USE_SHARED_LIBRARY
123 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
124 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
125 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
126 #endif // USE_SHARED_LIBRARY
128 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
129 EVT_SIZE(wxMDIParentFrame::OnSize
)
130 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
133 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
134 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
137 // ===========================================================================
138 // wxMDIParentFrame: the frame which contains the client window which manages
140 // ===========================================================================
142 wxMDIParentFrame::wxMDIParentFrame()
144 m_clientWindow
= NULL
;
145 m_currentChild
= NULL
;
147 m_parentFrameActive
= TRUE
;
150 bool wxMDIParentFrame::Create(wxWindow
*parent
,
152 const wxString
& title
,
156 const wxString
& name
)
158 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
160 m_clientWindow
= NULL
;
161 m_currentChild
= NULL
;
163 m_parentFrameActive
= TRUE
;
166 wxTopLevelWindows
.Append(this);
169 m_windowStyle
= style
;
171 if (parent
) parent
->AddChild(this);
176 m_windowId
= (int)NewControlId();
183 m_windowMenu
= (WXHMENU
) ::LoadMenu(wxGetInstance(), wxT("wxWindowMenu"));
185 DWORD msflags
= WS_OVERLAPPED
;
186 if (style
& wxMINIMIZE_BOX
)
187 msflags
|= WS_MINIMIZEBOX
;
188 if (style
& wxMAXIMIZE_BOX
)
189 msflags
|= WS_MAXIMIZEBOX
;
190 if (style
& wxTHICK_FRAME
)
191 msflags
|= WS_THICKFRAME
;
192 if (style
& wxSYSTEM_MENU
)
193 msflags
|= WS_SYSMENU
;
194 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
195 msflags
|= WS_MINIMIZE
;
196 if (style
& wxMAXIMIZE
)
197 msflags
|= WS_MAXIMIZE
;
198 if (style
& wxCAPTION
)
199 msflags
|= WS_CAPTION
;
201 if (style
& wxCLIP_CHILDREN
)
202 msflags
|= WS_CLIPCHILDREN
;
204 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
207 wxModelessWindows
.Append(this);
212 wxMDIParentFrame::~wxMDIParentFrame()
215 // already delete by DestroyChildren()
216 m_frameToolBar
= NULL
;
218 ::DestroyMenu((HMENU
)m_windowMenu
);
221 if ( m_clientWindow
)
223 if ( m_clientWindow
->MSWGetOldWndProc() )
224 m_clientWindow
->UnsubclassWin();
226 m_clientWindow
->SetHWND(0);
227 delete m_clientWindow
;
231 void wxMDIParentFrame::InternalSetMenuBar()
233 HMENU subMenu
= GetSubMenu((HMENU
) m_windowMenu
, 0);
235 m_parentFrameActive
= TRUE
;
237 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
240 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
242 if ( GetClientWindow() )
245 GetClientSize(&width
, &height
);
247 GetClientWindow()->SetSize(0, 0, width
, height
);
251 // Returns the active MDI child window
252 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
254 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
255 WM_MDIGETACTIVE
, 0, 0L);
259 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
262 // Create the client window class (don't Create the window, just return a new
264 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
266 return new wxMDIClientWindow
;
269 // Responds to colour changes, and passes event on to children.
270 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
272 if ( m_clientWindow
)
274 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
275 m_clientWindow
->Refresh();
281 // ---------------------------------------------------------------------------
283 // ---------------------------------------------------------------------------
285 void wxMDIParentFrame::Cascade()
287 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
290 // TODO: add a direction argument (hor/vert)
291 void wxMDIParentFrame::Tile()
293 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
296 void wxMDIParentFrame::ArrangeIcons()
298 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
301 void wxMDIParentFrame::ActivateNext()
303 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
306 void wxMDIParentFrame::ActivatePrevious()
308 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
311 // ---------------------------------------------------------------------------
312 // the MDI parent frame window proc
313 // ---------------------------------------------------------------------------
315 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
320 bool processed
= FALSE
;
326 WXWORD state
, minimized
;
328 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
330 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
338 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
340 (void)HandleCommand(id
, cmd
, hwnd
);
342 // even if the frame didn't process it, there is no need to try it
343 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
344 // so pretend we processed the message anyhow
348 // always pass this message DefFrameProc(), otherwise MDI menu
349 // commands (and sys commands - more surprizingly!) won't work
350 MSWDefWindowProc(message
, wParam
, lParam
);
354 m_clientWindow
= OnCreateClient();
355 // Uses own style for client style
356 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
358 wxLogMessage(_("Failed to create MDI parent frame."));
369 // we erase background ourselves
377 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
379 if ( m_parentFrameActive
)
381 processed
= HandleMenuSelect(item
, flags
, hmenu
);
383 else if (m_currentChild
)
385 processed
= m_currentChild
->
386 HandleMenuSelect(item
, flags
, hmenu
);
392 // as we don't (usually) resize the MDI client to exactly fit the
393 // client area (we put it below the toolbar, above statusbar &c),
394 // we should not pass this one to DefFrameProc
399 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
404 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
406 bool processed
= FALSE
;
408 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
414 // If this window is an MDI parent, we must also send an OnActivate message
415 // to the current child.
416 if ( (m_currentChild
!= NULL
) &&
417 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
419 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
420 event
.SetEventObject( m_currentChild
);
421 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
428 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
430 // In case it's e.g. a toolbar.
433 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
435 return win
->MSWCommand(cmd
, id
);
438 // is it one of standard MDI commands?
443 case IDM_WINDOWCASCADE
:
445 wParam
= MDITILE_SKIPDISABLED
;
448 case IDM_WINDOWTILEHOR
:
449 wParam
|= MDITILE_HORIZONTAL
;
452 case IDM_WINDOWTILEVERT
:
454 wParam
= MDITILE_VERTICAL
;
456 wParam
|= MDITILE_SKIPDISABLED
;
459 case IDM_WINDOWICONS
:
460 msg
= WM_MDIICONARRANGE
;
473 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
478 // FIXME VZ: what does this test do??
481 return FALSE
; // Get WndProc to call default proc
484 if ( IsMdiCommandId(id
) )
486 wxWindowList::Node
* node
= GetChildren().GetFirst();
489 wxWindow
* child
= node
->GetData();
490 if ( child
->GetHWND() )
492 long childId
= wxGetWindowId(child
->GetHWND());
493 if (childId
== (long)id
)
495 ::SendMessage( GetWinHwnd(GetClientWindow()),
497 (WPARAM
)child
->GetHWND(), 0);
501 node
= node
->GetNext();
504 else if ( m_parentFrameActive
)
506 return ProcessCommand(id
);
508 else if ( m_currentChild
)
510 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
514 // this shouldn't happen because it means that our messages are being
515 // lost (they're not sent to the parent frame nor to the children)
516 wxFAIL_MSG(wxT("MDI parent frame is not active, "
517 "yet there is no active MDI child?"));
523 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
528 if ( GetClientWindow() )
529 clientWnd
= GetClientWindow()->GetHWND();
533 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
536 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
538 MSG
*pMsg
= (MSG
*)msg
;
540 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
541 m_currentChild
->MSWTranslateMessage(msg
) )
546 if ( m_acceleratorTable
.Translate(this, msg
) )
551 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
553 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
560 // ===========================================================================
562 // ===========================================================================
564 wxMDIChildFrame::wxMDIChildFrame()
568 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
570 const wxString
& title
,
574 const wxString
& name
)
576 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
577 : wxDEFAULT_MDICHILDFRAME_ICON
);
584 m_windowId
= (int)NewControlId();
588 parent
->AddChild(this);
600 mcs
.szClass
= wxMDIChildFrameClassName
;
602 mcs
.hOwner
= wxGetInstance();
606 mcs
.x
= CW_USEDEFAULT
;
611 mcs
.y
= CW_USEDEFAULT
;
616 mcs
.cx
= CW_USEDEFAULT
;
621 mcs
.cy
= CW_USEDEFAULT
;
623 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
624 if (style
& wxMINIMIZE_BOX
)
625 msflags
|= WS_MINIMIZEBOX
;
626 if (style
& wxMAXIMIZE_BOX
)
627 msflags
|= WS_MAXIMIZEBOX
;
628 if (style
& wxTHICK_FRAME
)
629 msflags
|= WS_THICKFRAME
;
630 if (style
& wxSYSTEM_MENU
)
631 msflags
|= WS_SYSMENU
;
632 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
633 msflags
|= WS_MINIMIZE
;
634 if (style
& wxMAXIMIZE
)
635 msflags
|= WS_MAXIMIZE
;
636 if (style
& wxCAPTION
)
637 msflags
|= WS_CAPTION
;
643 DWORD Return
= SendMessage(GetWinHwnd(parent
->GetClientWindow()),
644 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
646 //handle = (HWND)LOWORD(Return);
647 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
648 m_hWnd
= (WXHWND
)Return
;
651 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
653 // VZ: what's this? an act of piracy?
654 //SetWindowLong(GetHwnd(), 0, (long)this);
656 wxModelessWindows
.Append(this);
660 wxMDIChildFrame::~wxMDIChildFrame()
665 // Set the client size (i.e. leave the calculation of borders etc.
667 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
669 HWND hWnd
= GetHwnd();
672 ::GetClientRect(hWnd
, &rect
);
675 GetWindowRect(hWnd
, &rect2
);
677 // Find the difference between the entire window (title bar and all)
678 // and the client area; add this to the new client size to move the
680 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
681 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
686 GetStatusBar()->GetSize(&sx
, &sy
);
691 point
.x
= rect2
.left
;
694 // If there's an MDI parent, must subtract the parent's top left corner
695 // since MoveWindow moves relative to the parent
696 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
697 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
699 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
701 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
702 event
.SetEventObject( this );
703 GetEventHandler()->ProcessEvent(event
);
706 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
709 GetWindowRect(GetHwnd(), &rect
);
714 // Since we now have the absolute screen coords,
715 // if there's a parent we must subtract its top left corner
716 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
717 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
723 void wxMDIChildFrame::InternalSetMenuBar()
725 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
727 HMENU subMenu
= GetSubMenu((HMENU
)parent
->GetWindowMenu(), 0);
729 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
731 parent
->m_parentFrameActive
= FALSE
;
734 // ---------------------------------------------------------------------------
736 // ---------------------------------------------------------------------------
738 void wxMDIChildFrame::Maximize(bool maximize
)
740 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
741 if ( parent
&& parent
->GetClientWindow() )
743 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
744 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
745 (WPARAM
)GetHwnd(), 0);
749 void wxMDIChildFrame::Restore()
751 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
752 if ( parent
&& parent
->GetClientWindow() )
754 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
755 (WPARAM
) GetHwnd(), 0);
759 void wxMDIChildFrame::Activate()
761 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
762 if ( parent
&& parent
->GetClientWindow() )
764 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
765 (WPARAM
) GetHwnd(), 0);
769 // ---------------------------------------------------------------------------
770 // MDI window proc and message handlers
771 // ---------------------------------------------------------------------------
773 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
778 bool processed
= FALSE
;
786 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
789 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
793 case WM_GETMINMAXINFO
:
794 // let the default window proc calculate the size of MDI children
795 // frames because it is based on the size of the MDI client window,
796 // not on the values specified in wxWindow m_min/max variables
797 return MSWDefWindowProc(message
, wParam
, lParam
);
802 WXHWND hwndAct
, hwndDeact
;
803 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
805 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
810 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
811 // scrollbars if necessary
816 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
818 MSWDefWindowProc(message
, wParam
, lParam
);
822 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
823 // the message (the base class version does not)
824 return MSWDefWindowProc(message
, wParam
, lParam
);
826 case WM_WINDOWPOSCHANGING
:
827 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
832 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
837 bool wxMDIChildFrame::HandleSize(int x
, int y
, WXUINT id
)
839 HWND hwnd
= GetHwnd();
841 if ( !hwnd
|| hwnd
== invalidHandle
)
860 // forward WM_SIZE to status bar control
861 #if wxUSE_NATIVE_STATUSBAR
862 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
864 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
865 event
.SetEventObject( m_frameStatusBar
);
867 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
869 #endif // wxUSE_NATIVE_STATUSBAR
874 return wxWindow::HandleSize(x
, y
, id
);
882 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
884 // In case it's e.g. a toolbar.
887 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
889 return win
->MSWCommand(cmd
, id
);
892 if (wxCurrentPopupMenu
)
894 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
895 wxCurrentPopupMenu
= NULL
;
896 if (popupMenu
->MSWCommand(cmd
, id
))
900 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
911 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
915 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
921 if ( m_hWnd
== hwndAct
)
924 parent
->m_currentChild
= this;
926 HMENU child_menu
= (HMENU
)GetWinMenu();
929 parent
->m_parentFrameActive
= FALSE
;
931 menuToSet
= child_menu
;
934 else if ( m_hWnd
== hwndDeact
)
936 wxASSERT_MSG( parent
->m_currentChild
== this,
937 wxT("can't deactivate MDI child which wasn't active!") );
940 parent
->m_currentChild
= NULL
;
942 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
945 parent
->m_parentFrameActive
= TRUE
;
947 menuToSet
= parent_menu
;
952 // we have nothing to with it
958 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
960 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
963 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
964 event
.SetEventObject( this );
966 return GetEventHandler()->ProcessEvent(event
);
969 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
971 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
972 #if defined(__WIN95__)
973 if (!(lpPos
->flags
& SWP_NOSIZE
))
976 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
977 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
978 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
980 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
981 lpPos
->x
= rectClient
.left
;
982 lpPos
->y
= rectClient
.top
;
983 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
984 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
986 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
987 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
989 pFrameWnd
->GetToolBar()->Refresh();
997 // ---------------------------------------------------------------------------
998 // MDI specific message translation/preprocessing
999 // ---------------------------------------------------------------------------
1001 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1003 return DefMDIChildProc(GetHwnd(),
1004 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1007 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1009 return m_acceleratorTable
.Translate(GetParent(), msg
);
1012 // ---------------------------------------------------------------------------
1014 // ---------------------------------------------------------------------------
1016 void wxMDIChildFrame::MSWDestroyWindow()
1018 MSWDetachWindowMenu();
1019 invalidHandle
= GetHwnd();
1021 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1023 // Must make sure this handle is invalidated (set to NULL) since all sorts
1024 // of things could happen after the child client is destroyed, but before
1025 // the wxFrame is destroyed.
1027 HWND oldHandle
= (HWND
)GetHWND();
1028 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1029 (WPARAM
)oldHandle
, 0);
1034 ::DestroyMenu((HMENU
) m_hMenu
);
1040 // Change the client window's extended style so we don't get a client edge
1041 // style when a child is maximised (a double border looks silly.)
1042 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1044 #if defined(__WIN95__)
1045 RECT
*rect
= (RECT
*)vrect
;
1046 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1047 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1048 if (!pChild
|| (pChild
== this))
1050 DWORD dwStyle
= ::GetWindowLong(GetWinHwnd(pFrameWnd
->GetClientWindow()), GWL_EXSTYLE
);
1051 DWORD dwThisStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1052 DWORD dwNewStyle
= dwStyle
;
1053 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1054 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1056 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1058 if (dwStyle
!= dwNewStyle
)
1060 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1061 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1062 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1063 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1064 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1065 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1068 ::GetClientRect(hwnd
, rect
);
1078 // ===========================================================================
1079 // wxMDIClientWindow: the window of predefined (by Windows) class which
1080 // contains the child frames
1081 // ===========================================================================
1083 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1085 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1087 CLIENTCREATESTRUCT ccs
;
1088 m_windowStyle
= style
;
1091 ccs
.hWindowMenu
= (HMENU
)parent
->GetWindowMenu();
1092 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1094 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1095 if ( style
& wxHSCROLL
)
1096 msStyle
|= WS_HSCROLL
;
1097 if ( style
& wxVSCROLL
)
1098 msStyle
|= WS_VSCROLL
;
1100 #if defined(__WIN95__)
1101 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1107 m_hWnd
= (WXHWND
)::CreateWindowEx
1117 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1120 wxLogLastError("CreateWindowEx(MDI client)");
1125 SubclassWin(m_hWnd
);
1131 // Explicitly call default scroll behaviour
1132 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1134 // Note: for client windows, the scroll position is not set in
1135 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1136 // scroll position we're at.
1137 // This makes it hard to paint patterns or bitmaps in the background,
1138 // and have the client area scrollable as well.
1140 if ( event
.GetOrientation() == wxHORIZONTAL
)
1141 m_scrollX
= event
.GetPosition(); // Always returns zero!
1143 m_scrollY
= event
.GetPosition(); // Always returns zero!
1148 // ---------------------------------------------------------------------------
1149 // non member functions
1150 // ---------------------------------------------------------------------------
1152 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1154 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1156 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
);
1158 0, MAKELPARAM(hmenuFrame
, hmenuWindow
));
1161 // update menu bar of the parent window
1162 wxWindow
*parent
= win
->GetParent();
1163 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1165 ::DrawMenuBar(GetWinHwnd(parent
));
1168 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1170 // Try to insert Window menu in front of Help, otherwise append it.
1171 HMENU hmenu
= (HMENU
)menu
;
1172 int N
= GetMenuItemCount(hmenu
);
1173 bool success
= FALSE
;
1174 for ( int i
= 0; i
< N
; i
++ )
1177 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1180 wxLogLastError(wxT("GetMenuString"));
1185 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(wxT("Help")) )
1188 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1189 (UINT
)subMenu
, wxT("&Window"));
1196 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, wxT("&Window"));
1199 MDISetMenu(win
, hmenu
, subMenu
);
1202 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1203 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1207 *hwndAct
= (WXHWND
)lParam
;
1208 *hwndDeact
= (WXHWND
)wParam
;
1210 *activate
= (WXWORD
)wParam
;
1211 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1212 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1213 #endif // Win32/Win16