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()
216 // already delete by DestroyChildren()
217 m_frameToolBar
= NULL
;
219 ::DestroyMenu((HMENU
)m_windowMenu
);
222 if ( m_clientWindow
)
224 if ( m_clientWindow
->MSWGetOldWndProc() )
225 m_clientWindow
->UnsubclassWin();
227 m_clientWindow
->SetHWND(0);
228 delete m_clientWindow
;
232 void wxMDIParentFrame::InternalSetMenuBar()
234 HMENU subMenu
= GetSubMenu((HMENU
) m_windowMenu
, 0);
236 m_parentFrameActive
= TRUE
;
238 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
241 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
243 if ( GetClientWindow() )
246 GetClientSize(&width
, &height
);
248 GetClientWindow()->SetSize(0, 0, width
, height
);
252 // Returns the active MDI child window
253 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
255 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
256 WM_MDIGETACTIVE
, 0, 0L);
260 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
263 // Create the client window class (don't Create the window, just return a new
265 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
267 return new wxMDIClientWindow
;
270 // Responds to colour changes, and passes event on to children.
271 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
273 if ( m_clientWindow
)
275 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
276 m_clientWindow
->Refresh();
282 // ---------------------------------------------------------------------------
284 // ---------------------------------------------------------------------------
286 void wxMDIParentFrame::Cascade()
288 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
291 // TODO: add a direction argument (hor/vert)
292 void wxMDIParentFrame::Tile()
294 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
297 void wxMDIParentFrame::ArrangeIcons()
299 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
302 void wxMDIParentFrame::ActivateNext()
304 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
307 void wxMDIParentFrame::ActivatePrevious()
309 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
312 // ---------------------------------------------------------------------------
313 // the MDI parent frame window proc
314 // ---------------------------------------------------------------------------
316 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
321 bool processed
= FALSE
;
327 WXWORD state
, minimized
;
329 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
331 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
339 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
341 (void)HandleCommand(id
, cmd
, hwnd
);
343 // even if the frame didn't process it, there is no need to try it
344 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
345 // so pretend we processed the message anyhow
349 // always pass this message DefFrameProc(), otherwise MDI menu
350 // commands (and sys commands - more surprizingly!) won't work
351 MSWDefWindowProc(message
, wParam
, lParam
);
355 m_clientWindow
= OnCreateClient();
356 // Uses own style for client style
357 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
359 wxLogMessage(_("Failed to create MDI parent frame."));
370 // we erase background ourselves
378 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
380 if ( m_parentFrameActive
)
382 processed
= HandleMenuSelect(item
, flags
, hmenu
);
384 else if (m_currentChild
)
386 processed
= m_currentChild
->
387 HandleMenuSelect(item
, flags
, hmenu
);
393 // as we don't (usually) resize the MDI client to exactly fit the
394 // client area (we put it below the toolbar, above statusbar &c),
395 // we should not pass this one to DefFrameProc
400 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
405 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
407 bool processed
= FALSE
;
409 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
415 // If this window is an MDI parent, we must also send an OnActivate message
416 // to the current child.
417 if ( (m_currentChild
!= NULL
) &&
418 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
420 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
421 event
.SetEventObject( m_currentChild
);
422 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
429 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
431 // In case it's e.g. a toolbar.
434 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
436 return win
->MSWCommand(cmd
, id
);
439 // is it one of standard MDI commands?
444 case IDM_WINDOWCASCADE
:
446 wParam
= MDITILE_SKIPDISABLED
;
449 case IDM_WINDOWTILEHOR
:
450 wParam
|= MDITILE_HORIZONTAL
;
453 case IDM_WINDOWTILEVERT
:
455 wParam
= MDITILE_VERTICAL
;
457 wParam
|= MDITILE_SKIPDISABLED
;
460 case IDM_WINDOWICONS
:
461 msg
= WM_MDIICONARRANGE
;
474 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
479 // FIXME VZ: what does this test do??
482 return FALSE
; // Get WndProc to call default proc
485 if ( IsMdiCommandId(id
) )
487 wxWindowList::Node
* node
= GetChildren().GetFirst();
490 wxWindow
* child
= node
->GetData();
491 if ( child
->GetHWND() )
493 long childId
= wxGetWindowId(child
->GetHWND());
494 if (childId
== (long)id
)
496 ::SendMessage( GetWinHwnd(GetClientWindow()),
498 (WPARAM
)child
->GetHWND(), 0);
502 node
= node
->GetNext();
505 else if ( m_parentFrameActive
)
507 return ProcessCommand(id
);
509 else if ( m_currentChild
)
511 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
515 // this shouldn't happen because it means that our messages are being
516 // lost (they're not sent to the parent frame nor to the children)
517 wxFAIL_MSG(wxT("MDI parent frame is not active, "
518 "yet there is no active MDI child?"));
524 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
529 if ( GetClientWindow() )
530 clientWnd
= GetClientWindow()->GetHWND();
534 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
537 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
539 MSG
*pMsg
= (MSG
*)msg
;
541 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
542 m_currentChild
->MSWTranslateMessage(msg
) )
547 if ( m_acceleratorTable
.Translate(this, msg
) )
552 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
554 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
561 // ===========================================================================
563 // ===========================================================================
565 wxMDIChildFrame::wxMDIChildFrame()
569 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
571 const wxString
& title
,
575 const wxString
& name
)
577 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
578 : wxDEFAULT_MDICHILDFRAME_ICON
);
585 m_windowId
= (int)NewControlId();
589 parent
->AddChild(this);
601 mcs
.szClass
= wxMDIChildFrameClassName
;
603 mcs
.hOwner
= wxGetInstance();
607 mcs
.x
= CW_USEDEFAULT
;
612 mcs
.y
= CW_USEDEFAULT
;
617 mcs
.cx
= CW_USEDEFAULT
;
622 mcs
.cy
= CW_USEDEFAULT
;
624 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
625 if (style
& wxMINIMIZE_BOX
)
626 msflags
|= WS_MINIMIZEBOX
;
627 if (style
& wxMAXIMIZE_BOX
)
628 msflags
|= WS_MAXIMIZEBOX
;
629 if (style
& wxTHICK_FRAME
)
630 msflags
|= WS_THICKFRAME
;
631 if (style
& wxSYSTEM_MENU
)
632 msflags
|= WS_SYSMENU
;
633 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
634 msflags
|= WS_MINIMIZE
;
635 if (style
& wxMAXIMIZE
)
636 msflags
|= WS_MAXIMIZE
;
637 if (style
& wxCAPTION
)
638 msflags
|= WS_CAPTION
;
644 DWORD Return
= SendMessage(GetWinHwnd(parent
->GetClientWindow()),
645 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
647 //handle = (HWND)LOWORD(Return);
648 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
649 m_hWnd
= (WXHWND
)Return
;
652 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
654 // VZ: what's this? an act of piracy?
655 //SetWindowLong(GetHwnd(), 0, (long)this);
657 wxModelessWindows
.Append(this);
661 wxMDIChildFrame::~wxMDIChildFrame()
666 // Set the client size (i.e. leave the calculation of borders etc.
668 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
670 HWND hWnd
= GetHwnd();
673 ::GetClientRect(hWnd
, &rect
);
676 GetWindowRect(hWnd
, &rect2
);
678 // Find the difference between the entire window (title bar and all)
679 // and the client area; add this to the new client size to move the
681 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
682 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
687 GetStatusBar()->GetSize(&sx
, &sy
);
692 point
.x
= rect2
.left
;
695 // If there's an MDI parent, must subtract the parent's top left corner
696 // since MoveWindow moves relative to the parent
697 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
698 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
700 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
702 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
703 event
.SetEventObject( this );
704 GetEventHandler()->ProcessEvent(event
);
707 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
710 GetWindowRect(GetHwnd(), &rect
);
715 // Since we now have the absolute screen coords,
716 // if there's a parent we must subtract its top left corner
717 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
718 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
724 void wxMDIChildFrame::InternalSetMenuBar()
726 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
728 HMENU subMenu
= GetSubMenu((HMENU
)parent
->GetWindowMenu(), 0);
730 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
732 parent
->m_parentFrameActive
= FALSE
;
735 // ---------------------------------------------------------------------------
737 // ---------------------------------------------------------------------------
739 void wxMDIChildFrame::Maximize(bool maximize
)
741 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
742 if ( parent
&& parent
->GetClientWindow() )
744 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
745 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
746 (WPARAM
)GetHwnd(), 0);
750 void wxMDIChildFrame::Restore()
752 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
753 if ( parent
&& parent
->GetClientWindow() )
755 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
756 (WPARAM
) GetHwnd(), 0);
760 void wxMDIChildFrame::Activate()
762 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
763 if ( parent
&& parent
->GetClientWindow() )
765 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
766 (WPARAM
) GetHwnd(), 0);
770 // ---------------------------------------------------------------------------
771 // MDI window proc and message handlers
772 // ---------------------------------------------------------------------------
774 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
779 bool processed
= FALSE
;
787 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
790 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
794 case WM_GETMINMAXINFO
:
795 // let the default window proc calculate the size of MDI children
796 // frames because it is based on the size of the MDI client window,
797 // not on the values specified in wxWindow m_min/max variables
798 return MSWDefWindowProc(message
, wParam
, lParam
);
803 WXHWND hwndAct
, hwndDeact
;
804 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
806 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
811 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
812 // scrollbars if necessary
817 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
819 MSWDefWindowProc(message
, wParam
, lParam
);
823 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
824 // the message (the base class version does not)
825 return MSWDefWindowProc(message
, wParam
, lParam
);
827 case WM_WINDOWPOSCHANGING
:
828 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
833 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
838 bool wxMDIChildFrame::HandleSize(int x
, int y
, WXUINT id
)
840 HWND hwnd
= GetHwnd();
842 if ( !hwnd
|| hwnd
== invalidHandle
)
861 // forward WM_SIZE to status bar control
862 #if wxUSE_NATIVE_STATUSBAR
863 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
865 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
866 event
.SetEventObject( m_frameStatusBar
);
868 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
870 #endif // wxUSE_NATIVE_STATUSBAR
875 return wxWindow::HandleSize(x
, y
, id
);
883 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
885 // In case it's e.g. a toolbar.
888 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
890 return win
->MSWCommand(cmd
, id
);
893 if (wxCurrentPopupMenu
)
895 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
896 wxCurrentPopupMenu
= NULL
;
897 if (popupMenu
->MSWCommand(cmd
, id
))
901 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
912 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
916 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
922 if ( m_hWnd
== hwndAct
)
925 parent
->m_currentChild
= this;
927 HMENU child_menu
= (HMENU
)GetWinMenu();
930 parent
->m_parentFrameActive
= FALSE
;
932 menuToSet
= child_menu
;
935 else if ( m_hWnd
== hwndDeact
)
937 wxASSERT_MSG( parent
->m_currentChild
== this,
938 wxT("can't deactivate MDI child which wasn't active!") );
941 parent
->m_currentChild
= NULL
;
943 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
946 parent
->m_parentFrameActive
= TRUE
;
948 menuToSet
= parent_menu
;
953 // we have nothing to with it
959 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
961 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
964 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
965 event
.SetEventObject( this );
967 return GetEventHandler()->ProcessEvent(event
);
970 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
972 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
973 #if defined(__WIN95__)
974 if (!(lpPos
->flags
& SWP_NOSIZE
))
977 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
978 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
979 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
981 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
982 lpPos
->x
= rectClient
.left
;
983 lpPos
->y
= rectClient
.top
;
984 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
985 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
987 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
988 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
990 pFrameWnd
->GetToolBar()->Refresh();
998 // ---------------------------------------------------------------------------
999 // MDI specific message translation/preprocessing
1000 // ---------------------------------------------------------------------------
1002 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1004 return DefMDIChildProc(GetHwnd(),
1005 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1008 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1010 return m_acceleratorTable
.Translate(GetParent(), msg
);
1013 // ---------------------------------------------------------------------------
1015 // ---------------------------------------------------------------------------
1017 void wxMDIChildFrame::MSWDestroyWindow()
1019 MSWDetachWindowMenu();
1020 invalidHandle
= GetHwnd();
1022 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1024 // Must make sure this handle is invalidated (set to NULL) since all sorts
1025 // of things could happen after the child client is destroyed, but before
1026 // the wxFrame is destroyed.
1028 HWND oldHandle
= (HWND
)GetHWND();
1029 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1030 (WPARAM
)oldHandle
, 0);
1035 ::DestroyMenu((HMENU
) m_hMenu
);
1041 // Change the client window's extended style so we don't get a client edge
1042 // style when a child is maximised (a double border looks silly.)
1043 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1045 #if defined(__WIN95__)
1046 RECT
*rect
= (RECT
*)vrect
;
1047 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1048 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1049 if (!pChild
|| (pChild
== this))
1051 DWORD dwStyle
= ::GetWindowLong(GetWinHwnd(pFrameWnd
->GetClientWindow()), GWL_EXSTYLE
);
1052 DWORD dwThisStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1053 DWORD dwNewStyle
= dwStyle
;
1054 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1055 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1057 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1059 if (dwStyle
!= dwNewStyle
)
1061 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1062 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1063 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1064 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1065 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1066 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1069 ::GetClientRect(hwnd
, rect
);
1079 // ===========================================================================
1080 // wxMDIClientWindow: the window of predefined (by Windows) class which
1081 // contains the child frames
1082 // ===========================================================================
1084 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1086 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1088 CLIENTCREATESTRUCT ccs
;
1089 m_windowStyle
= style
;
1092 ccs
.hWindowMenu
= (HMENU
)parent
->GetWindowMenu();
1093 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1095 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1096 if ( style
& wxHSCROLL
)
1097 msStyle
|= WS_HSCROLL
;
1098 if ( style
& wxVSCROLL
)
1099 msStyle
|= WS_VSCROLL
;
1101 #if defined(__WIN95__)
1102 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1108 m_hWnd
= (WXHWND
)::CreateWindowEx
1118 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1121 wxLogLastError("CreateWindowEx(MDI client)");
1126 SubclassWin(m_hWnd
);
1132 // Explicitly call default scroll behaviour
1133 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1135 // Note: for client windows, the scroll position is not set in
1136 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1137 // scroll position we're at.
1138 // This makes it hard to paint patterns or bitmaps in the background,
1139 // and have the client area scrollable as well.
1141 if ( event
.GetOrientation() == wxHORIZONTAL
)
1142 m_scrollX
= event
.GetPosition(); // Always returns zero!
1144 m_scrollY
= event
.GetPosition(); // Always returns zero!
1149 // ---------------------------------------------------------------------------
1150 // non member functions
1151 // ---------------------------------------------------------------------------
1153 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1155 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1157 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
);
1159 0, MAKELPARAM(hmenuFrame
, hmenuWindow
));
1162 // update menu bar of the parent window
1163 wxWindow
*parent
= win
->GetParent();
1164 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1166 ::DrawMenuBar(GetWinHwnd(parent
));
1169 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1171 // Try to insert Window menu in front of Help, otherwise append it.
1172 HMENU hmenu
= (HMENU
)menu
;
1173 int N
= GetMenuItemCount(hmenu
);
1174 bool success
= FALSE
;
1175 for ( int i
= 0; i
< N
; i
++ )
1178 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1181 wxLogLastError(wxT("GetMenuString"));
1186 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(wxT("Help")) )
1189 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1190 (UINT
)subMenu
, wxT("&Window"));
1197 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, wxT("&Window"));
1200 MDISetMenu(win
, hmenu
, subMenu
);
1203 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1204 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1208 *hwndAct
= (WXHWND
)lParam
;
1209 *hwndDeact
= (WXHWND
)wParam
;
1211 *activate
= (WXWORD
)wParam
;
1212 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1213 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1214 #endif // Win32/Win16