1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/mdi.cpp
3 // Purpose: MDI classes for wxMSW
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
; // from app.cpp
67 extern const wxChar
*wxMDIChildFrameClassName
;
68 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
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;
85 static const int IDM_WINDOWPREV
= 4006;
87 // This range gives a maximum of 500 MDI children. Should be enough :-)
88 static const int wxFIRST_MDI_CHILD
= 4100;
89 static const int wxLAST_MDI_CHILD
= 4600;
91 // Status border dimensions
92 static const int wxTHICK_LINE_BORDER
= 3;
93 static const int wxTHICK_LINE_WIDTH
= 1;
95 // ---------------------------------------------------------------------------
97 // ---------------------------------------------------------------------------
99 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
100 // of the parent of win (which is supposed to be the MDI client window)
101 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
103 // insert the window menu (subMenu) into menu just before "Help" submenu or at
104 // the very end if not found
105 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
107 // Remove the window menu
108 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
110 // is this an id of an MDI child?
111 inline bool IsMdiCommandId(int id
)
113 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
116 // unpack the parameters of WM_MDIACTIVATE message
117 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
118 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
120 // return the HMENU of the MDI menu
121 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
123 wxMenu
*menu
= frame
->GetWindowMenu();
124 return menu
? GetHmenuOf(menu
) : 0;
127 // ===========================================================================
129 // ===========================================================================
131 // ---------------------------------------------------------------------------
133 // ---------------------------------------------------------------------------
135 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
136 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
137 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
139 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
140 EVT_SIZE(wxMDIParentFrame::OnSize
)
141 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
144 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
145 EVT_IDLE(wxMDIChildFrame::OnIdle
)
148 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
149 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
152 // ===========================================================================
153 // wxMDIParentFrame: the frame which contains the client window which manages
155 // ===========================================================================
157 wxMDIParentFrame::wxMDIParentFrame()
159 m_clientWindow
= NULL
;
160 m_currentChild
= NULL
;
161 m_windowMenu
= (wxMenu
*) NULL
;
162 m_parentFrameActive
= TRUE
;
165 bool wxMDIParentFrame::Create(wxWindow
*parent
,
167 const wxString
& title
,
171 const wxString
& name
)
173 m_clientWindow
= NULL
;
174 m_currentChild
= NULL
;
176 // this style can be used to prevent a window from having the standard MDI
178 if ( style
& wxFRAME_NO_WINDOW_MENU
)
180 m_windowMenu
= (wxMenu
*)NULL
;
182 else // normal case: we have the window menu, so construct it
184 m_windowMenu
= new wxMenu
;
186 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
187 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
188 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
189 m_windowMenu
->AppendSeparator();
190 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
191 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
192 m_windowMenu
->Append(IDM_WINDOWPREV
, _("&Previous"));
195 m_parentFrameActive
= TRUE
;
198 wxTopLevelWindows
.Append(this);
201 m_windowStyle
= style
;
204 parent
->AddChild(this);
209 m_windowId
= NewControlId();
212 WXDWORD msflags
= MSWGetCreateWindowFlags(&exflags
);
214 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
223 wxModelessWindows
.Append(this);
225 // unlike (almost?) all other windows, frames are created hidden
231 wxMDIParentFrame::~wxMDIParentFrame()
235 // already delete by DestroyChildren()
236 m_frameToolBar
= NULL
;
237 m_frameStatusBar
= NULL
;
242 m_windowMenu
= (wxMenu
*) NULL
;
245 // the MDI frame menubar is not automatically deleted by Windows unlike for
249 ::DestroyMenu((HMENU
)m_hMenu
);
250 m_hMenu
= (WXHMENU
)NULL
;
253 if ( m_clientWindow
)
255 if ( m_clientWindow
->MSWGetOldWndProc() )
256 m_clientWindow
->UnsubclassWin();
258 m_clientWindow
->SetHWND(0);
259 delete m_clientWindow
;
263 #if wxUSE_MENUS_NATIVE
265 void wxMDIParentFrame::InternalSetMenuBar()
267 m_parentFrameActive
= TRUE
;
269 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
272 #endif // wxUSE_MENUS_NATIVE
274 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
280 // Remove old window menu
281 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
285 m_windowMenu
= (wxMenu
*) NULL
;
293 InsertWindowMenu(GetClientWindow(), m_hMenu
,
294 GetHmenuOf(m_windowMenu
));
299 void wxMDIParentFrame::OnSize(wxSizeEvent
&)
301 if ( GetClientWindow() )
304 GetClientSize(&width
, &height
);
306 GetClientWindow()->SetSize(0, 0, width
, height
);
310 // Returns the active MDI child window
311 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
313 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
314 WM_MDIGETACTIVE
, 0, 0L);
318 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
321 // Create the client window class (don't Create the window, just return a new
323 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
325 return new wxMDIClientWindow
;
328 // Responds to colour changes, and passes event on to children.
329 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
331 if ( m_clientWindow
)
333 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
334 m_clientWindow
->Refresh();
340 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
342 return (WXHICON
)(wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
343 : wxDEFAULT_MDIPARENTFRAME_ICON
);
346 // ---------------------------------------------------------------------------
348 // ---------------------------------------------------------------------------
350 void wxMDIParentFrame::Cascade()
352 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
355 // TODO: add a direction argument (hor/vert)
356 void wxMDIParentFrame::Tile()
358 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
361 void wxMDIParentFrame::ArrangeIcons()
363 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
366 void wxMDIParentFrame::ActivateNext()
368 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
371 void wxMDIParentFrame::ActivatePrevious()
373 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
376 // ---------------------------------------------------------------------------
377 // the MDI parent frame window proc
378 // ---------------------------------------------------------------------------
380 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
385 bool processed
= FALSE
;
391 WXWORD state
, minimized
;
393 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
395 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
403 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
405 (void)HandleCommand(id
, cmd
, hwnd
);
407 // even if the frame didn't process it, there is no need to try it
408 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
409 // so pretend we processed the message anyhow
413 // always pass this message DefFrameProc(), otherwise MDI menu
414 // commands (and sys commands - more surprizingly!) won't work
415 MSWDefWindowProc(message
, wParam
, lParam
);
419 m_clientWindow
= OnCreateClient();
420 // Uses own style for client style
421 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
423 wxLogMessage(_("Failed to create MDI parent frame."));
434 // we erase background ourselves
442 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
444 if ( m_parentFrameActive
)
446 processed
= HandleMenuSelect(item
, flags
, hmenu
);
448 else if (m_currentChild
)
450 processed
= m_currentChild
->
451 HandleMenuSelect(item
, flags
, hmenu
);
457 // as we don't (usually) resize the MDI client to exactly fit the
458 // client area (we put it below the toolbar, above statusbar &c),
459 // we should not pass this one to DefFrameProc
464 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
469 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
471 bool processed
= FALSE
;
473 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
479 // If this window is an MDI parent, we must also send an OnActivate message
480 // to the current child.
481 if ( (m_currentChild
!= NULL
) &&
482 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
484 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, m_currentChild
->GetId());
485 event
.SetEventObject( m_currentChild
);
486 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
493 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
495 // In case it's e.g. a toolbar.
498 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
500 return win
->MSWCommand(cmd
, id
);
503 // is it one of standard MDI commands?
509 case IDM_WINDOWCASCADE
:
511 wParam
= MDITILE_SKIPDISABLED
;
514 case IDM_WINDOWTILEHOR
:
515 wParam
|= MDITILE_HORIZONTAL
;
518 case IDM_WINDOWTILEVERT
:
520 wParam
= MDITILE_VERTICAL
;
522 wParam
|= MDITILE_SKIPDISABLED
;
525 case IDM_WINDOWICONS
:
526 msg
= WM_MDIICONARRANGE
;
531 lParam
= 0; // next child
536 lParam
= 1; // previous child
545 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, lParam
);
550 // FIXME VZ: what does this test do??
553 return FALSE
; // Get WndProc to call default proc
556 if ( IsMdiCommandId(id
) )
558 wxWindowList::Node
* node
= GetChildren().GetFirst();
561 wxWindow
* child
= node
->GetData();
562 if ( child
->GetHWND() )
564 long childId
= wxGetWindowId(child
->GetHWND());
565 if (childId
== (long)id
)
567 ::SendMessage( GetWinHwnd(GetClientWindow()),
569 (WPARAM
)child
->GetHWND(), 0);
573 node
= node
->GetNext();
576 else if ( m_parentFrameActive
)
578 return ProcessCommand(id
);
580 else if ( m_currentChild
)
582 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
586 // this shouldn't happen because it means that our messages are being
587 // lost (they're not sent to the parent frame nor to the children)
588 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
594 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
599 if ( GetClientWindow() )
600 clientWnd
= GetClientWindow()->GetHWND();
604 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
607 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
609 MSG
*pMsg
= (MSG
*)msg
;
611 // first let the current child get it
612 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
613 m_currentChild
->MSWTranslateMessage(msg
) )
618 // then try out accel table (will also check the menu accels)
619 if ( wxFrame::MSWTranslateMessage(msg
) )
624 // finally, check for MDI specific built in accel keys
625 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
627 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
634 // ===========================================================================
636 // ===========================================================================
638 void wxMDIChildFrame::Init()
640 m_needsResize
= TRUE
;
643 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
645 const wxString
& title
,
649 const wxString
& name
)
652 wxWindowBase::Show(TRUE
); // MDI child frame starts off shown
657 m_windowId
= (int)NewControlId();
661 parent
->AddChild(this);
671 mcs
.szClass
= style
& wxNO_FULL_REPAINT_ON_RESIZE
672 ? wxMDIChildFrameClassNameNoRedraw
673 : wxMDIChildFrameClassName
;
675 mcs
.hOwner
= wxGetInstance();
679 mcs
.x
= CW_USEDEFAULT
;
684 mcs
.y
= CW_USEDEFAULT
;
689 mcs
.cx
= CW_USEDEFAULT
;
694 mcs
.cy
= CW_USEDEFAULT
;
696 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
| WS_THICKFRAME
| WS_VISIBLE
;
697 if (style
& wxMINIMIZE_BOX
)
698 msflags
|= WS_MINIMIZEBOX
;
699 if (style
& wxMAXIMIZE_BOX
)
700 msflags
|= WS_MAXIMIZEBOX
;
701 if (style
& wxTHICK_FRAME
)
702 msflags
|= WS_THICKFRAME
;
703 if (style
& wxSYSTEM_MENU
)
704 msflags
|= WS_SYSMENU
;
705 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
706 msflags
|= WS_MINIMIZE
;
707 if (style
& wxMAXIMIZE
)
708 msflags
|= WS_MAXIMIZE
;
709 if (style
& wxCAPTION
)
710 msflags
|= WS_CAPTION
;
716 wxWindowCreationHook
hook(this);
718 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
719 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
721 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
723 wxModelessWindows
.Append(this);
728 wxMDIChildFrame::~wxMDIChildFrame()
732 // already deleted by DestroyChildren()
733 m_frameToolBar
= NULL
;
734 m_frameStatusBar
= NULL
;
736 RemoveWindowMenu(NULL
, m_hMenu
);
741 // Set the client size (i.e. leave the calculation of borders etc.
743 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
745 HWND hWnd
= GetHwnd();
748 ::GetClientRect(hWnd
, &rect
);
751 GetWindowRect(hWnd
, &rect2
);
753 // Find the difference between the entire window (title bar and all)
754 // and the client area; add this to the new client size to move the
756 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
757 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
759 if (GetStatusBar() && GetStatusBar()->IsShown())
762 GetStatusBar()->GetSize(&sx
, &sy
);
767 point
.x
= rect2
.left
;
770 // If there's an MDI parent, must subtract the parent's top left corner
771 // since MoveWindow moves relative to the parent
772 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
773 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
775 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)TRUE
);
777 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
778 event
.SetEventObject( this );
779 GetEventHandler()->ProcessEvent(event
);
782 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
785 GetWindowRect(GetHwnd(), &rect
);
790 // Since we now have the absolute screen coords,
791 // if there's a parent we must subtract its top left corner
792 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
793 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
799 void wxMDIChildFrame::InternalSetMenuBar()
801 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
803 InsertWindowMenu(parent
->GetClientWindow(),
804 m_hMenu
, GetMDIWindowMenu(parent
));
806 parent
->m_parentFrameActive
= FALSE
;
809 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
811 return (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
812 : wxDEFAULT_MDICHILDFRAME_ICON
);
815 // ---------------------------------------------------------------------------
817 // ---------------------------------------------------------------------------
819 void wxMDIChildFrame::Maximize(bool maximize
)
821 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
822 if ( parent
&& parent
->GetClientWindow() )
824 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
825 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
826 (WPARAM
)GetHwnd(), 0);
830 void wxMDIChildFrame::Restore()
832 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
833 if ( parent
&& parent
->GetClientWindow() )
835 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
836 (WPARAM
) GetHwnd(), 0);
840 void wxMDIChildFrame::Activate()
842 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
843 if ( parent
&& parent
->GetClientWindow() )
845 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
846 (WPARAM
) GetHwnd(), 0);
850 // ---------------------------------------------------------------------------
851 // MDI window proc and message handlers
852 // ---------------------------------------------------------------------------
854 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
859 bool processed
= FALSE
;
867 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
870 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
874 case WM_GETMINMAXINFO
:
875 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
881 WXHWND hwndAct
, hwndDeact
;
882 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
884 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
889 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
890 // scrollbars if necessary
895 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
897 MSWDefWindowProc(message
, wParam
, lParam
);
901 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
902 // the message (the base class version does not)
903 return MSWDefWindowProc(message
, wParam
, lParam
);
905 case WM_WINDOWPOSCHANGING
:
906 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
911 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
916 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
918 // In case it's e.g. a toolbar.
921 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
923 return win
->MSWCommand(cmd
, id
);
926 if (wxCurrentPopupMenu
)
928 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
929 wxCurrentPopupMenu
= NULL
;
930 if (popupMenu
->MSWCommand(cmd
, id
))
935 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
937 processed
= ProcessCommand(id
);
947 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
951 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
957 if ( m_hWnd
== hwndAct
)
960 parent
->m_currentChild
= this;
962 HMENU child_menu
= (HMENU
)GetWinMenu();
965 parent
->m_parentFrameActive
= FALSE
;
967 menuToSet
= child_menu
;
970 else if ( m_hWnd
== hwndDeact
)
972 wxASSERT_MSG( parent
->m_currentChild
== this,
973 wxT("can't deactivate MDI child which wasn't active!") );
976 parent
->m_currentChild
= NULL
;
978 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
980 // activate the the parent menu only when there is no other child
981 // that has been activated
982 if ( parent_menu
&& !hwndAct
)
984 parent
->m_parentFrameActive
= TRUE
;
986 menuToSet
= parent_menu
;
991 // we have nothing to do with it
997 MDISetMenu(parent
->GetClientWindow(),
998 menuToSet
, GetMDIWindowMenu(parent
));
1001 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1002 event
.SetEventObject( this );
1004 ResetWindowStyle((void *)NULL
);
1006 return GetEventHandler()->ProcessEvent(event
);
1009 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1011 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1012 #if defined(__WIN95__)
1013 if (!(lpPos
->flags
& SWP_NOSIZE
))
1016 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1017 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1018 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1020 ::AdjustWindowRectEx(&rectClient
, dwStyle
, FALSE
, dwExStyle
);
1021 lpPos
->x
= rectClient
.left
;
1022 lpPos
->y
= rectClient
.top
;
1023 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1024 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1026 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1027 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1029 pFrameWnd
->GetToolBar()->Refresh();
1037 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1039 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1041 // let the default window proc calculate the size of MDI children
1042 // frames because it is based on the size of the MDI client window,
1043 // not on the values specified in wxWindow m_max variables
1044 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1046 int minWidth
= GetMinWidth(),
1047 minHeight
= GetMinHeight();
1049 // but allow GetSizeHints() to set the min size
1050 if ( minWidth
!= -1 )
1052 info
->ptMinTrackSize
.x
= minWidth
;
1057 if ( minHeight
!= -1 )
1059 info
->ptMinTrackSize
.y
= minHeight
;
1067 // ---------------------------------------------------------------------------
1068 // MDI specific message translation/preprocessing
1069 // ---------------------------------------------------------------------------
1071 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1073 return DefMDIChildProc(GetHwnd(),
1074 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1077 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1079 return wxFrame::MSWTranslateMessage(msg
);
1082 // ---------------------------------------------------------------------------
1084 // ---------------------------------------------------------------------------
1086 void wxMDIChildFrame::MSWDestroyWindow()
1088 invalidHandle
= GetHwnd();
1090 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1092 // Must make sure this handle is invalidated (set to NULL) since all sorts
1093 // of things could happen after the child client is destroyed, but before
1094 // the wxFrame is destroyed.
1096 HWND oldHandle
= (HWND
)GetHWND();
1097 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1098 (WPARAM
)oldHandle
, 0);
1100 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1101 ResetWindowStyle((void*) NULL
);
1107 ::DestroyMenu((HMENU
) m_hMenu
);
1110 wxRemoveHandleAssociation(this);
1114 // Change the client window's extended style so we don't get a client edge
1115 // style when a child is maximised (a double border looks silly.)
1116 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1118 #if defined(__WIN95__)
1119 RECT
*rect
= (RECT
*)vrect
;
1120 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1121 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1122 if (!pChild
|| (pChild
== this))
1124 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1125 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1127 // we want to test whether there is a maximized child, so just set
1128 // dwThisStyle to 0 if there is no child at all
1129 DWORD dwThisStyle
= pChild
1130 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1131 DWORD dwNewStyle
= dwStyle
;
1132 if ( dwThisStyle
& WS_MAXIMIZE
)
1133 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1135 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1137 if (dwStyle
!= dwNewStyle
)
1139 // force update of everything
1140 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1141 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1142 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1143 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1144 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1145 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1148 ::GetClientRect(hwndClient
, rect
);
1158 // ===========================================================================
1159 // wxMDIClientWindow: the window of predefined (by Windows) class which
1160 // contains the child frames
1161 // ===========================================================================
1163 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1165 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1167 CLIENTCREATESTRUCT ccs
;
1168 m_windowStyle
= style
;
1171 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1172 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1174 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1175 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1177 if ( style
& wxHSCROLL
)
1178 msStyle
|= WS_HSCROLL
;
1179 if ( style
& wxVSCROLL
)
1180 msStyle
|= WS_VSCROLL
;
1182 #if defined(__WIN95__)
1183 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1188 wxWindowCreationHook
hook(this);
1189 m_hWnd
= (WXHWND
)::CreateWindowEx
1199 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1202 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1207 SubclassWin(m_hWnd
);
1212 // Explicitly call default scroll behaviour
1213 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1215 // Note: for client windows, the scroll position is not set in
1216 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1217 // scroll position we're at.
1218 // This makes it hard to paint patterns or bitmaps in the background,
1219 // and have the client area scrollable as well.
1221 if ( event
.GetOrientation() == wxHORIZONTAL
)
1222 m_scrollX
= event
.GetPosition(); // Always returns zero!
1224 m_scrollY
= event
.GetPosition(); // Always returns zero!
1229 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1231 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1232 // client area, you can end up with a non-refreshed portion in the client window
1233 // (see OGL studio sample). So check if the position is changed and if so,
1234 // redraw the MDI child frames.
1236 wxPoint oldPos
= GetPosition();
1238 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1240 wxPoint newPos
= GetPosition();
1242 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1246 wxNode
* node
= GetParent()->GetChildren().First();
1249 wxWindow
* child
= (wxWindow
*) node
->Data();
1250 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1252 HWND hWnd
= (HWND
) child
->GetHWND();
1253 ::RedrawWindow(hWnd
, NULL
, NULL
, RDW_FRAME
|RDW_ALLCHILDREN
|RDW_INVALIDATE
);
1255 node
= node
->Next();
1261 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1263 // MDI child frames get their WM_SIZE when they're constructed but at this
1264 // moment they don't have any children yet so all child windows will be
1265 // positioned incorrectly when they are added later - to fix this, we
1266 // generate an artificial size event here
1267 if ( m_needsResize
)
1269 m_needsResize
= FALSE
; // avoid any possibility of recursion
1277 // ---------------------------------------------------------------------------
1278 // non member functions
1279 // ---------------------------------------------------------------------------
1281 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1283 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1285 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1287 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1291 // update menu bar of the parent window
1292 wxWindow
*parent
= win
->GetParent();
1293 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1296 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1299 ::DrawMenuBar(GetWinHwnd(parent
));
1302 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1304 // Try to insert Window menu in front of Help, otherwise append it.
1305 HMENU hmenu
= (HMENU
)menu
;
1309 int N
= GetMenuItemCount(hmenu
);
1310 bool success
= FALSE
;
1311 for ( int i
= 0; i
< N
; i
++ )
1314 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1317 wxLogLastError(wxT("GetMenuString"));
1322 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1325 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1326 (UINT
)subMenu
, _("&Window"));
1333 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1337 MDISetMenu(win
, hmenu
, subMenu
);
1340 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1342 HMENU hMenu
= (HMENU
)menu
;
1348 int N
= ::GetMenuItemCount(hMenu
);
1349 for ( int i
= 0; i
< N
; i
++ )
1351 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1353 wxLogLastError(wxT("GetMenuString"));
1358 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1360 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1362 wxLogLastError(wxT("RemoveMenu"));
1372 // we don't change the windows menu, but we update the main one
1373 MDISetMenu(win
, hMenu
, NULL
);
1377 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1378 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1382 *hwndAct
= (WXHWND
)lParam
;
1383 *hwndDeact
= (WXHWND
)wParam
;
1385 *activate
= (WXWORD
)wParam
;
1386 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1387 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1388 #endif // Win32/Win16