1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MDI classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "mdi.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #include "wx/dialog.h"
38 #include "wx/statusbr.h"
39 #include "wx/settings.h"
45 #include "wx/msw/private.h"
47 #if wxUSE_NATIVE_STATUSBAR
48 #include <wx/msw/statbr95.h>
53 // ---------------------------------------------------------------------------
55 // ---------------------------------------------------------------------------
57 extern wxWindowList wxModelessWindows
; // from dialog.cpp
58 extern wxMenu
*wxCurrentPopupMenu
;
60 extern wxChar wxMDIFrameClassName
[];
61 extern wxChar wxMDIChildFrameClassName
[];
62 extern wxWindow
*wxWndHook
; // from window.cpp
64 extern wxList
*wxWinHandleList
;
66 static HWND invalidHandle
= 0;
68 // ---------------------------------------------------------------------------
70 // ---------------------------------------------------------------------------
72 static const int IDM_WINDOWTILE
= 4001;
73 static const int IDM_WINDOWTILEHOR
= 4001;
74 static const int IDM_WINDOWCASCADE
= 4002;
75 static const int IDM_WINDOWICONS
= 4003;
76 static const int IDM_WINDOWNEXT
= 4004;
77 static const int IDM_WINDOWTILEVERT
= 4005;
79 // This range gives a maximum of 500 MDI children. Should be enough :-)
80 static const int wxFIRST_MDI_CHILD
= 4100;
81 static const int wxLAST_MDI_CHILD
= 4600;
83 // Status border dimensions
84 static const int wxTHICK_LINE_BORDER
= 3;
85 static const int wxTHICK_LINE_WIDTH
= 1;
87 // ---------------------------------------------------------------------------
89 // ---------------------------------------------------------------------------
91 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
92 // of the parent of win (which is supposed to be the MDI client window)
93 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
95 // insert the window menu (subMenu) into menu just before "Help" submenu or at
96 // the very end if not found
97 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
99 // is this an id of an MDI child?
100 inline bool IsMdiCommandId(int id
)
102 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
105 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
106 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
108 // ===========================================================================
110 // ===========================================================================
112 // ---------------------------------------------------------------------------
114 // ---------------------------------------------------------------------------
116 #if !USE_SHARED_LIBRARY
117 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
118 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
119 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
120 #endif // USE_SHARED_LIBRARY
122 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
123 EVT_SIZE(wxMDIParentFrame::OnSize
)
124 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
127 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
128 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
131 // ===========================================================================
132 // wxMDIParentFrame: the frame which contains the client window which manages
134 // ===========================================================================
136 wxMDIParentFrame::wxMDIParentFrame()
138 m_clientWindow
= NULL
;
139 m_currentChild
= NULL
;
141 m_parentFrameActive
= TRUE
;
144 bool wxMDIParentFrame::Create(wxWindow
*parent
,
146 const wxString
& title
,
150 const wxString
& name
)
152 m_defaultIcon
= (WXHICON
) (wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
: wxDEFAULT_MDIPARENTFRAME_ICON
);
154 m_clientWindow
= NULL
;
155 m_currentChild
= NULL
;
157 m_parentFrameActive
= TRUE
;
160 wxTopLevelWindows
.Append(this);
163 m_windowStyle
= style
;
165 if (parent
) parent
->AddChild(this);
170 m_windowId
= (int)NewControlId();
177 m_windowMenu
= (WXHMENU
) ::LoadMenu(wxGetInstance(), _T("wxWindowMenu"));
179 DWORD msflags
= WS_OVERLAPPED
;
180 if (style
& wxMINIMIZE_BOX
)
181 msflags
|= WS_MINIMIZEBOX
;
182 if (style
& wxMAXIMIZE_BOX
)
183 msflags
|= WS_MAXIMIZEBOX
;
184 if (style
& wxTHICK_FRAME
)
185 msflags
|= WS_THICKFRAME
;
186 if (style
& wxSYSTEM_MENU
)
187 msflags
|= WS_SYSMENU
;
188 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
189 msflags
|= WS_MINIMIZE
;
190 if (style
& wxMAXIMIZE
)
191 msflags
|= WS_MAXIMIZE
;
192 if (style
& wxCAPTION
)
193 msflags
|= WS_CAPTION
;
195 // Adding WS_CLIPCHILDREN causes children not to be properly
196 // drawn when first displaying them.
197 // if (style & wxCLIP_CHILDREN)
198 // msflags |= WS_CLIPCHILDREN;
200 wxWindow::MSWCreate(m_windowId
, parent
, wxMDIFrameClassName
, this, title
, x
, y
, width
, height
,
203 wxModelessWindows
.Append(this);
208 wxMDIParentFrame::~wxMDIParentFrame()
212 ::DestroyMenu((HMENU
)m_windowMenu
);
215 if ( m_clientWindow
)
217 if ( m_clientWindow
->MSWGetOldWndProc() )
218 m_clientWindow
->UnsubclassWin();
220 m_clientWindow
->SetHWND(0);
221 delete m_clientWindow
;
225 void wxMDIParentFrame::InternalSetMenuBar()
227 HMENU subMenu
= GetSubMenu((HMENU
) m_windowMenu
, 0);
229 m_parentFrameActive
= TRUE
;
231 InsertWindowMenu(GetClientWindow(), m_hMenu
, subMenu
);
234 void wxMDIParentFrame::OnSize(wxSizeEvent
& event
)
236 if ( GetClientWindow() )
239 GetClientSize(&width
, &height
);
241 GetClientWindow()->SetSize(0, 0, width
, height
);
245 // Returns the active MDI child window
246 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
248 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
249 WM_MDIGETACTIVE
, 0, 0L);
253 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
256 // Create the client window class (don't Create the window, just return a new
258 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
260 return new wxMDIClientWindow
;
263 // Responds to colour changes, and passes event on to children.
264 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
266 if ( m_clientWindow
)
268 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
));
269 m_clientWindow
->Refresh();
275 // ---------------------------------------------------------------------------
277 // ---------------------------------------------------------------------------
279 void wxMDIParentFrame::Cascade()
281 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
284 // TODO: add a direction argument (hor/vert)
285 void wxMDIParentFrame::Tile()
287 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
290 void wxMDIParentFrame::ArrangeIcons()
292 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
295 void wxMDIParentFrame::ActivateNext()
297 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
300 void wxMDIParentFrame::ActivatePrevious()
302 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
305 // ---------------------------------------------------------------------------
306 // the MDI parent frame window proc
307 // ---------------------------------------------------------------------------
309 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
314 bool processed
= FALSE
;
320 WXWORD state
, minimized
;
322 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
324 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
332 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
334 (void)HandleCommand(id
, cmd
, hwnd
);
336 // even if the frame didn't process it, there is no need to try it
337 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
338 // so pretend we processed the message anyhow
342 // always pass this message DefFrameProc(), otherwise MDI menu
343 // commands (and sys commands - more surprizingly!) won't work
344 MSWDefWindowProc(message
, wParam
, lParam
);
348 m_clientWindow
= OnCreateClient();
349 // Uses own style for client style
350 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
352 wxLogMessage(_("Failed to create MDI parent frame."));
363 // we erase background ourselves
371 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
373 if ( m_parentFrameActive
)
375 processed
= HandleMenuSelect(item
, flags
, hmenu
);
377 else if (m_currentChild
)
379 processed
= m_currentChild
->
380 HandleMenuSelect(item
, flags
, hmenu
);
386 // we will leave this message to the base class version, but we
387 // must pass it to DefFrameProc() too
388 MSWDefWindowProc(message
, wParam
, lParam
);
393 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
398 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
400 bool processed
= FALSE
;
402 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
408 // If this window is an MDI parent, we must also send an OnActivate message
409 // to the current child.
410 if ( (m_currentChild
!= NULL
) &&
411 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
413 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
414 event
.SetEventObject( m_currentChild
);
415 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
422 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
424 // In case it's e.g. a toolbar.
427 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
429 return win
->MSWCommand(cmd
, id
);
432 // is it one of standard MDI commands?
437 case IDM_WINDOWCASCADE
:
439 wParam
= MDITILE_SKIPDISABLED
;
442 case IDM_WINDOWTILEHOR
:
443 wParam
|= MDITILE_HORIZONTAL
;
446 case IDM_WINDOWTILEVERT
:
448 wParam
= MDITILE_VERTICAL
;
450 wParam
|= MDITILE_SKIPDISABLED
;
453 case IDM_WINDOWICONS
:
454 msg
= WM_MDIICONARRANGE
;
467 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, 0);
472 // FIXME VZ: what does this test do??
475 return FALSE
; // Get WndProc to call default proc
478 if ( IsMdiCommandId(id
) )
480 wxWindowList::Node
* node
= GetChildren().GetFirst();
483 wxWindow
* child
= node
->GetData();
484 if ( child
->GetHWND() )
486 long childId
= wxGetWindowId(child
->GetHWND());
489 ::SendMessage( GetWinHwnd(GetClientWindow()),
491 (WPARAM
)child
->GetHWND(), 0);
495 node
= node
->GetNext();
498 else if ( m_parentFrameActive
)
500 return ProcessCommand(id
);
502 else if ( m_currentChild
)
504 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
508 // this shouldn't happen because it means that our messages are being
509 // lost (they're not sent to the parent frame nor to the children)
510 wxFAIL_MSG(_T("MDI parent frame is not active, "
511 "yet there is no active MDI child?"));
517 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
522 if ( GetClientWindow() )
523 clientWnd
= GetClientWindow()->GetHWND();
527 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
530 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
532 MSG
*pMsg
= (MSG
*)msg
;
534 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
535 m_currentChild
->MSWTranslateMessage(msg
) )
540 if ( m_acceleratorTable
.Translate(this, msg
) )
545 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
547 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
554 // ===========================================================================
556 // ===========================================================================
558 wxMDIChildFrame::wxMDIChildFrame()
562 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
564 const wxString
& title
,
568 const wxString
& name
)
570 m_defaultIcon
= (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
571 : wxDEFAULT_MDICHILDFRAME_ICON
);
578 m_windowId
= (int)NewControlId();
582 parent
->AddChild(this);
594 mcs
.szClass
= wxMDIChildFrameClassName
;
596 mcs
.hOwner
= wxGetInstance();
600 mcs
.x
= CW_USEDEFAULT
;
605 mcs
.y
= CW_USEDEFAULT
;
610 mcs
.cx
= CW_USEDEFAULT
;
615 mcs
.cy
= CW_USEDEFAULT
;
617 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
;
618 if (style
& wxMINIMIZE_BOX
)
619 msflags
|= WS_MINIMIZEBOX
;
620 if (style
& wxMAXIMIZE_BOX
)
621 msflags
|= WS_MAXIMIZEBOX
;
622 if (style
& wxTHICK_FRAME
)
623 msflags
|= WS_THICKFRAME
;
624 if (style
& wxSYSTEM_MENU
)
625 msflags
|= WS_SYSMENU
;
626 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
627 msflags
|= WS_MINIMIZE
;
628 if (style
& wxMAXIMIZE
)
629 msflags
|= WS_MAXIMIZE
;
630 if (style
& wxCAPTION
)
631 msflags
|= WS_CAPTION
;
637 DWORD Return
= SendMessage(GetWinHwnd(parent
->GetClientWindow()),
638 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
640 //handle = (HWND)LOWORD(Return);
641 // Must be the DWORRD for WIN32. And in 16 bits, HIWORD=0 (says Microsoft)
642 m_hWnd
= (WXHWND
)Return
;
645 wxWinHandleList
->Append((long)GetHWND(), this);
647 // VZ: what's this? an act of piracy?
648 //SetWindowLong(GetHwnd(), 0, (long)this);
650 wxModelessWindows
.Append(this);
654 wxMDIChildFrame::~wxMDIChildFrame()
659 // Set the client size (i.e. leave the calculation of borders etc.
661 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
663 HWND hWnd
= GetHwnd();
666 ::GetClientRect(hWnd
, &rect
);
669 GetWindowRect(hWnd
, &rect2
);
671 // Find the difference between the entire window (title bar and all)
672 // and the client area; add this to the new client size to move the
674 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
675 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
680 GetStatusBar()->GetSize(&sx
, &sy
);
685 point
.x
= rect2
.left
;
688 // If there's an MDI parent, must subtract the parent's top left corner
689 // since MoveWindow moves relative to the parent
690 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
691 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
693 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
695 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
696 event
.SetEventObject( this );
697 GetEventHandler()->ProcessEvent(event
);
700 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
703 GetWindowRect(GetHwnd(), &rect
);
708 // Since we now have the absolute screen coords,
709 // if there's a parent we must subtract its top left corner
710 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
711 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
717 void wxMDIChildFrame::InternalSetMenuBar()
719 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
721 HMENU subMenu
= GetSubMenu((HMENU
)parent
->GetWindowMenu(), 0);
723 InsertWindowMenu(parent
->GetClientWindow(), m_hMenu
, subMenu
);
725 parent
->m_parentFrameActive
= FALSE
;
728 // ---------------------------------------------------------------------------
730 // ---------------------------------------------------------------------------
732 void wxMDIChildFrame::Maximize()
734 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
735 if ( parent
&& parent
->GetClientWindow() )
736 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIMAXIMIZE
, (WPARAM
) GetHwnd(), 0);
739 void wxMDIChildFrame::Restore()
741 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
742 if ( parent
&& parent
->GetClientWindow() )
743 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
, (WPARAM
) GetHwnd(), 0);
746 void wxMDIChildFrame::Activate()
748 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
749 if ( parent
&& parent
->GetClientWindow() )
750 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
, (WPARAM
) GetHwnd(), 0);
753 // ---------------------------------------------------------------------------
754 // MDI window proc and message handlers
755 // ---------------------------------------------------------------------------
757 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
762 bool processed
= FALSE
;
770 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
773 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
777 case WM_GETMINMAXINFO
:
778 // let the default window proc calculate the size of MDI children
779 // frames because it is based on the size of the MDI client window,
780 // not on the values specified in wxWindow m_min/max variables
781 return MSWDefWindowProc(message
, wParam
, lParam
);
786 WXHWND hwndAct
, hwndDeact
;
787 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
789 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
794 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
795 // scrollbars if necessary
800 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
802 MSWDefWindowProc(message
, wParam
, lParam
);
806 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
807 // the message (the base class version does not)
808 return MSWDefWindowProc(message
, wParam
, lParam
);
810 case WM_WINDOWPOSCHANGING
:
811 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
816 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
821 bool wxMDIChildFrame::HandleSize(int x
, int y
, WXUINT id
)
823 HWND hwnd
= GetHwnd();
825 if ( !hwnd
|| hwnd
== invalidHandle
)
844 // forward WM_SIZE to status bar control
845 #if wxUSE_NATIVE_STATUSBAR
846 if (m_frameStatusBar
&& m_frameStatusBar
->IsKindOf(CLASSINFO(wxStatusBar95
)))
848 wxSizeEvent
event(wxSize(x
, y
), m_frameStatusBar
->GetId());
849 event
.SetEventObject( m_frameStatusBar
);
851 ((wxStatusBar95
*)m_frameStatusBar
)->OnSize(event
);
853 #endif // wxUSE_NATIVE_STATUSBAR
858 return wxWindow::HandleSize(x
, y
, id
);
866 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
868 // In case it's e.g. a toolbar.
871 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
873 return win
->MSWCommand(cmd
, id
);
876 if (wxCurrentPopupMenu
)
878 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
879 wxCurrentPopupMenu
= NULL
;
880 if (popupMenu
->MSWCommand(cmd
, id
))
884 if (GetMenuBar() && GetMenuBar()->FindItemForId(id
))
895 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
899 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
905 if ( m_hWnd
== hwndAct
)
908 parent
->m_currentChild
= this;
910 HMENU child_menu
= (HMENU
)GetWinMenu();
913 parent
->m_parentFrameActive
= FALSE
;
915 menuToSet
= child_menu
;
918 else if ( m_hWnd
== hwndDeact
)
920 wxASSERT_MSG( parent
->m_currentChild
== this,
921 _T("can't deactivate MDI child which wasn't active!") );
924 parent
->m_currentChild
= NULL
;
926 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
929 parent
->m_parentFrameActive
= TRUE
;
931 menuToSet
= parent_menu
;
936 // we have nothing to with it
942 HMENU subMenu
= GetSubMenu((HMENU
) parent
->GetWindowMenu(), 0);
944 MDISetMenu(parent
->GetClientWindow(), menuToSet
, subMenu
);
947 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
948 event
.SetEventObject( this );
950 return GetEventHandler()->ProcessEvent(event
);
953 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
955 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
956 #if defined(__WIN95__)
957 if (!(lpPos
->flags
& SWP_NOSIZE
))
960 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
961 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
962 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
964 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
965 lpPos
->x
= rectClient
.left
;
966 lpPos
->y
= rectClient
.top
;
967 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
968 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
970 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
971 if (pFrameWnd
&& pFrameWnd
->GetToolBar())
973 pFrameWnd
->GetToolBar()->Refresh();
981 // ---------------------------------------------------------------------------
982 // MDI specific message translation/preprocessing
983 // ---------------------------------------------------------------------------
985 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
987 return DefMDIChildProc(GetHwnd(),
988 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
991 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
993 return m_acceleratorTable
.Translate(GetParent(), msg
);
996 // ---------------------------------------------------------------------------
998 // ---------------------------------------------------------------------------
1000 void wxMDIChildFrame::MSWDestroyWindow()
1002 MSWDetachWindowMenu();
1003 invalidHandle
= GetHwnd();
1005 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1007 // Must make sure this handle is invalidated (set to NULL) since all sorts
1008 // of things could happen after the child client is destroyed, but before
1009 // the wxFrame is destroyed.
1011 HWND oldHandle
= (HWND
)GetHWND();
1012 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1013 (WPARAM
)oldHandle
, 0);
1018 ::DestroyMenu((HMENU
) m_hMenu
);
1024 // Change the client window's extended style so we don't get a client edge
1025 // style when a child is maximised (a double border looks silly.)
1026 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1028 #if defined(__WIN95__)
1029 RECT
*rect
= (RECT
*)vrect
;
1030 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1031 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1032 if (!pChild
|| (pChild
== this))
1034 DWORD dwStyle
= ::GetWindowLong(GetWinHwnd(pFrameWnd
->GetClientWindow()), GWL_EXSTYLE
);
1035 DWORD dwThisStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1036 DWORD dwNewStyle
= dwStyle
;
1037 if (pChild
!= NULL
&& (dwThisStyle
& WS_MAXIMIZE
))
1038 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1040 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1042 if (dwStyle
!= dwNewStyle
)
1044 HWND hwnd
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1045 ::RedrawWindow(hwnd
, NULL
, NULL
, RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1046 ::SetWindowLong(hwnd
, GWL_EXSTYLE
, dwNewStyle
);
1047 ::SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0,
1048 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1049 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1052 ::GetClientRect(hwnd
, rect
);
1062 // ===========================================================================
1063 // wxMDIClientWindow: the window of predefined (by Windows) class which
1064 // contains the child frames
1065 // ===========================================================================
1067 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1069 m_backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE
);
1071 CLIENTCREATESTRUCT ccs
;
1072 m_windowStyle
= style
;
1075 ccs
.hWindowMenu
= (HMENU
)parent
->GetWindowMenu();
1076 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1078 DWORD msStyle
= WS_VISIBLE
| WS_CHILD
| WS_CLIPCHILDREN
;
1079 if ( style
& wxHSCROLL
)
1080 msStyle
|= WS_HSCROLL
;
1081 if ( style
& wxVSCROLL
)
1082 msStyle
|= WS_VSCROLL
;
1084 #if defined(__WIN95__)
1085 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1091 m_hWnd
= (WXHWND
)::CreateWindowEx
1101 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1104 wxLogLastError("CreateWindowEx(MDI client)");
1109 SubclassWin(m_hWnd
);
1115 // Explicitly call default scroll behaviour
1116 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1118 // Note: for client windows, the scroll position is not set in
1119 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1120 // scroll position we're at.
1121 // This makes it hard to paint patterns or bitmaps in the background,
1122 // and have the client area scrollable as well.
1124 if ( event
.GetOrientation() == wxHORIZONTAL
)
1125 m_scrollX
= event
.GetPosition(); // Always returns zero!
1127 m_scrollY
= event
.GetPosition(); // Always returns zero!
1132 // ---------------------------------------------------------------------------
1133 // non member functions
1134 // ---------------------------------------------------------------------------
1136 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1138 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1140 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
);
1142 0, MAKELPARAM(hmenuFrame
, hmenuWindow
));
1145 // update menu bar of the parent window
1146 wxWindow
*parent
= win
->GetParent();
1147 wxCHECK_RET( parent
, _T("MDI client without parent frame? weird...") );
1149 ::DrawMenuBar(GetWinHwnd(parent
));
1152 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1154 // Try to insert Window menu in front of Help, otherwise append it.
1155 HMENU hmenu
= (HMENU
)menu
;
1156 int N
= GetMenuItemCount(hmenu
);
1157 bool success
= FALSE
;
1158 for ( int i
= 0; i
< N
; i
++ )
1161 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1164 wxLogLastError(_T("GetMenuString"));
1169 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_T("Help")) )
1172 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1173 (UINT
)subMenu
, _T("&Window"));
1180 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _T("&Window"));
1183 MDISetMenu(win
, hmenu
, subMenu
);
1186 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1187 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1191 *hwndAct
= (WXHWND
)lParam
;
1192 *hwndDeact
= (WXHWND
)wParam
;
1194 *activate
= (WXWORD
)wParam
;
1195 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1196 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1197 #endif // Win32/Win16