1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/mdi.cpp
3 // Purpose: MDI classes for wxMSW
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
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"
46 #if wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__)
49 #include "wx/msw/private.h"
51 #if wxUSE_STATUSBAR && wxUSE_NATIVE_STATUSBAR
52 #include "wx/msw/statbr95.h"
56 #include "wx/toolbar.h"
57 #endif // wxUSE_TOOLBAR
61 // ---------------------------------------------------------------------------
63 // ---------------------------------------------------------------------------
65 extern wxWindowList wxModelessWindows
; // from dialog.cpp
66 extern wxMenu
*wxCurrentPopupMenu
;
68 extern const wxChar
*wxMDIFrameClassName
; // from app.cpp
69 extern const wxChar
*wxMDIChildFrameClassName
;
70 extern const wxChar
*wxMDIChildFrameClassNameNoRedraw
;
71 #ifdef __DIGITALMARS__
72 extern "C" void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
74 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
76 extern void wxRemoveHandleAssociation(wxWindow
*win
);
78 static HWND invalidHandle
= 0;
80 // ---------------------------------------------------------------------------
82 // ---------------------------------------------------------------------------
84 static const int IDM_WINDOWTILE
= 4001;
85 static const int IDM_WINDOWTILEHOR
= 4001;
86 static const int IDM_WINDOWCASCADE
= 4002;
87 static const int IDM_WINDOWICONS
= 4003;
88 static const int IDM_WINDOWNEXT
= 4004;
89 static const int IDM_WINDOWTILEVERT
= 4005;
90 static const int IDM_WINDOWPREV
= 4006;
92 // This range gives a maximum of 500 MDI children. Should be enough :-)
93 static const int wxFIRST_MDI_CHILD
= 4100;
94 static const int wxLAST_MDI_CHILD
= 4600;
96 // Status border dimensions
97 static const int wxTHICK_LINE_BORDER
= 3;
98 static const int wxTHICK_LINE_WIDTH
= 1;
100 // ---------------------------------------------------------------------------
102 // ---------------------------------------------------------------------------
104 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
105 // of the parent of win (which is supposed to be the MDI client window)
106 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
108 // insert the window menu (subMenu) into menu just before "Help" submenu or at
109 // the very end if not found
110 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
112 // Remove the window menu
113 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
115 // is this an id of an MDI child?
116 inline bool IsMdiCommandId(int id
)
118 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
121 // unpack the parameters of WM_MDIACTIVATE message
122 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
123 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
125 // return the HMENU of the MDI menu
126 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
128 wxMenu
*menu
= frame
->GetWindowMenu();
129 return menu
? GetHmenuOf(menu
) : 0;
132 // ===========================================================================
134 // ===========================================================================
136 // ---------------------------------------------------------------------------
138 // ---------------------------------------------------------------------------
140 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
141 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
142 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
144 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
145 EVT_SIZE(wxMDIParentFrame::OnSize
)
146 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
149 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
150 EVT_IDLE(wxMDIChildFrame::OnIdle
)
153 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
154 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
157 // ===========================================================================
158 // wxMDIParentFrame: the frame which contains the client window which manages
160 // ===========================================================================
162 wxMDIParentFrame::wxMDIParentFrame()
164 m_clientWindow
= NULL
;
165 m_currentChild
= NULL
;
166 m_windowMenu
= (wxMenu
*) NULL
;
167 m_parentFrameActive
= true;
170 bool wxMDIParentFrame::Create(wxWindow
*parent
,
172 const wxString
& title
,
176 const wxString
& name
)
178 m_clientWindow
= NULL
;
179 m_currentChild
= NULL
;
181 // this style can be used to prevent a window from having the standard MDI
183 if ( style
& wxFRAME_NO_WINDOW_MENU
)
185 m_windowMenu
= (wxMenu
*)NULL
;
187 else // normal case: we have the window menu, so construct it
189 m_windowMenu
= new wxMenu
;
191 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
192 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
193 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
194 m_windowMenu
->AppendSeparator();
195 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
196 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
197 m_windowMenu
->Append(IDM_WINDOWPREV
, _("&Previous"));
200 m_parentFrameActive
= true;
203 wxTopLevelWindows
.Append(this);
206 m_windowStyle
= style
;
209 parent
->AddChild(this);
214 m_windowId
= NewControlId();
217 WXDWORD msflags
= MSWGetCreateWindowFlags(&exflags
);
219 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
228 wxModelessWindows
.Append(this);
230 // unlike (almost?) all other windows, frames are created hidden
236 wxMDIParentFrame::~wxMDIParentFrame()
240 // already delete by DestroyChildren()
241 m_frameToolBar
= NULL
;
242 m_frameStatusBar
= NULL
;
247 m_windowMenu
= (wxMenu
*) NULL
;
250 // the MDI frame menubar is not automatically deleted by Windows unlike for
254 ::DestroyMenu((HMENU
)m_hMenu
);
255 m_hMenu
= (WXHMENU
)NULL
;
258 if ( m_clientWindow
)
260 if ( m_clientWindow
->MSWGetOldWndProc() )
261 m_clientWindow
->UnsubclassWin();
263 m_clientWindow
->SetHWND(0);
264 delete m_clientWindow
;
268 #if wxUSE_MENUS_NATIVE
270 void wxMDIParentFrame::InternalSetMenuBar()
272 m_parentFrameActive
= true;
274 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
277 #endif // wxUSE_MENUS_NATIVE
279 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
285 // Remove old window menu
286 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
290 m_windowMenu
= (wxMenu
*) NULL
;
298 InsertWindowMenu(GetClientWindow(), m_hMenu
,
299 GetHmenuOf(m_windowMenu
));
304 void wxMDIParentFrame::OnSize(wxSizeEvent
&)
306 if ( GetClientWindow() )
309 GetClientSize(&width
, &height
);
311 GetClientWindow()->SetSize(0, 0, width
, height
);
315 // Returns the active MDI child window
316 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
318 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
319 WM_MDIGETACTIVE
, 0, 0L);
323 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
326 // Create the client window class (don't Create the window, just return a new
328 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
330 return new wxMDIClientWindow
;
333 // Responds to colour changes, and passes event on to children.
334 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
336 if ( m_clientWindow
)
338 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
339 m_clientWindow
->Refresh();
345 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
347 return (WXHICON
)(wxSTD_MDIPARENTFRAME_ICON
? wxSTD_MDIPARENTFRAME_ICON
348 : wxDEFAULT_MDIPARENTFRAME_ICON
);
351 // ---------------------------------------------------------------------------
353 // ---------------------------------------------------------------------------
355 void wxMDIParentFrame::Cascade()
357 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
360 // TODO: add a direction argument (hor/vert)
361 void wxMDIParentFrame::Tile()
363 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
366 void wxMDIParentFrame::ArrangeIcons()
368 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
371 void wxMDIParentFrame::ActivateNext()
373 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
376 void wxMDIParentFrame::ActivatePrevious()
378 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
381 // ---------------------------------------------------------------------------
382 // the MDI parent frame window proc
383 // ---------------------------------------------------------------------------
385 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
390 bool processed
= false;
396 WXWORD state
, minimized
;
398 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
400 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
408 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
410 (void)HandleCommand(id
, cmd
, hwnd
);
412 // even if the frame didn't process it, there is no need to try it
413 // once again (i.e. call wxFrame::HandleCommand()) - we just dud it,
414 // so pretend we processed the message anyhow
418 // always pass this message DefFrameProc(), otherwise MDI menu
419 // commands (and sys commands - more surprizingly!) won't work
420 MSWDefWindowProc(message
, wParam
, lParam
);
424 m_clientWindow
= OnCreateClient();
425 // Uses own style for client style
426 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
428 wxLogMessage(_("Failed to create MDI parent frame."));
439 // we erase background ourselves
447 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
449 if ( m_parentFrameActive
)
451 processed
= HandleMenuSelect(item
, flags
, hmenu
);
453 else if (m_currentChild
)
455 processed
= m_currentChild
->
456 HandleMenuSelect(item
, flags
, hmenu
);
462 // as we don't (usually) resize the MDI client to exactly fit the
463 // client area (we put it below the toolbar, above statusbar &c),
464 // we should not pass this one to DefFrameProc
469 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
474 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
476 bool processed
= false;
478 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
484 // If this window is an MDI parent, we must also send an OnActivate message
485 // to the current child.
486 if ( (m_currentChild
!= NULL
) &&
487 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
489 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_currentChild
->GetId());
490 event
.SetEventObject( m_currentChild
);
491 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
498 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
500 // In case it's e.g. a toolbar.
503 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
505 return win
->MSWCommand(cmd
, id
);
508 // is it one of standard MDI commands?
514 case IDM_WINDOWCASCADE
:
516 wParam
= MDITILE_SKIPDISABLED
;
519 case IDM_WINDOWTILEHOR
:
520 wParam
|= MDITILE_HORIZONTAL
;
523 case IDM_WINDOWTILEVERT
:
525 wParam
= MDITILE_VERTICAL
;
527 wParam
|= MDITILE_SKIPDISABLED
;
530 case IDM_WINDOWICONS
:
531 msg
= WM_MDIICONARRANGE
;
536 lParam
= 0; // next child
541 lParam
= 1; // previous child
550 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, lParam
);
555 // FIXME VZ: what does this test do??
558 return false; // Get WndProc to call default proc
561 if ( IsMdiCommandId(id
) )
563 wxWindowList::Node
*node
= GetChildren().GetFirst();
566 wxWindow
*child
= node
->GetData();
567 if ( child
->GetHWND() )
569 long childId
= wxGetWindowId(child
->GetHWND());
570 if (childId
== (long)id
)
572 ::SendMessage( GetWinHwnd(GetClientWindow()),
574 (WPARAM
)child
->GetHWND(), 0);
578 node
= node
->GetNext();
581 else if ( m_parentFrameActive
)
583 return ProcessCommand(id
);
585 else if ( m_currentChild
)
587 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
591 // this shouldn't happen because it means that our messages are being
592 // lost (they're not sent to the parent frame nor to the children)
593 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
599 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
604 if ( GetClientWindow() )
605 clientWnd
= GetClientWindow()->GetHWND();
609 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
612 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
614 MSG
*pMsg
= (MSG
*)msg
;
616 // first let the current child get it
617 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
618 m_currentChild
->MSWTranslateMessage(msg
) )
623 // then try out accel table (will also check the menu accels)
624 if ( wxFrame::MSWTranslateMessage(msg
) )
629 // finally, check for MDI specific built in accel keys
630 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
632 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
639 // ===========================================================================
641 // ===========================================================================
643 void wxMDIChildFrame::Init()
645 m_needsResize
= true;
648 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
650 const wxString
& title
,
654 const wxString
& name
)
657 wxWindowBase::Show(true); // MDI child frame starts off shown
662 m_windowId
= (int)NewControlId();
666 parent
->AddChild(this);
676 mcs
.szClass
= style
& wxNO_FULL_REPAINT_ON_RESIZE
677 ? wxMDIChildFrameClassNameNoRedraw
678 : wxMDIChildFrameClassName
;
680 mcs
.hOwner
= wxGetInstance();
684 mcs
.x
= CW_USEDEFAULT
;
689 mcs
.y
= CW_USEDEFAULT
;
694 mcs
.cx
= CW_USEDEFAULT
;
699 mcs
.cy
= CW_USEDEFAULT
;
701 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
| WS_THICKFRAME
| WS_VISIBLE
;
702 if (style
& wxMINIMIZE_BOX
)
703 msflags
|= WS_MINIMIZEBOX
;
704 if (style
& wxMAXIMIZE_BOX
)
705 msflags
|= WS_MAXIMIZEBOX
;
706 if (style
& wxTHICK_FRAME
)
707 msflags
|= WS_THICKFRAME
;
708 if (style
& wxSYSTEM_MENU
)
709 msflags
|= WS_SYSMENU
;
710 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
711 msflags
|= WS_MINIMIZE
;
712 if (style
& wxMAXIMIZE
)
713 msflags
|= WS_MAXIMIZE
;
714 if (style
& wxCAPTION
)
715 msflags
|= WS_CAPTION
;
721 wxWindowCreationHook
hook(this);
723 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
724 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
726 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
728 wxModelessWindows
.Append(this);
733 wxMDIChildFrame::~wxMDIChildFrame()
737 // already deleted by DestroyChildren()
738 m_frameToolBar
= NULL
;
739 m_frameStatusBar
= NULL
;
741 RemoveWindowMenu(NULL
, m_hMenu
);
746 // Set the client size (i.e. leave the calculation of borders etc.
748 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
750 HWND hWnd
= GetHwnd();
753 ::GetClientRect(hWnd
, &rect
);
756 GetWindowRect(hWnd
, &rect2
);
758 // Find the difference between the entire window (title bar and all)
759 // and the client area; add this to the new client size to move the
761 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
762 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
764 if (GetStatusBar() && GetStatusBar()->IsShown())
767 GetStatusBar()->GetSize(&sx
, &sy
);
772 point
.x
= rect2
.left
;
775 // If there's an MDI parent, must subtract the parent's top left corner
776 // since MoveWindow moves relative to the parent
777 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
778 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
780 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)true);
782 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
783 event
.SetEventObject( this );
784 GetEventHandler()->ProcessEvent(event
);
787 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
790 GetWindowRect(GetHwnd(), &rect
);
795 // Since we now have the absolute screen coords,
796 // if there's a parent we must subtract its top left corner
797 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
798 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
804 void wxMDIChildFrame::InternalSetMenuBar()
806 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
808 InsertWindowMenu(parent
->GetClientWindow(),
809 m_hMenu
, GetMDIWindowMenu(parent
));
811 parent
->m_parentFrameActive
= false;
814 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
816 return (WXHICON
)(wxSTD_MDICHILDFRAME_ICON
? wxSTD_MDICHILDFRAME_ICON
817 : wxDEFAULT_MDICHILDFRAME_ICON
);
820 // ---------------------------------------------------------------------------
822 // ---------------------------------------------------------------------------
824 void wxMDIChildFrame::Maximize(bool maximize
)
826 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
827 if ( parent
&& parent
->GetClientWindow() )
829 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
830 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
831 (WPARAM
)GetHwnd(), 0);
835 void wxMDIChildFrame::Restore()
837 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
838 if ( parent
&& parent
->GetClientWindow() )
840 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
841 (WPARAM
) GetHwnd(), 0);
845 void wxMDIChildFrame::Activate()
847 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
848 if ( parent
&& parent
->GetClientWindow() )
850 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
851 (WPARAM
) GetHwnd(), 0);
855 // ---------------------------------------------------------------------------
856 // MDI window proc and message handlers
857 // ---------------------------------------------------------------------------
859 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
864 bool processed
= false;
872 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
875 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
879 case WM_GETMINMAXINFO
:
880 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
886 WXHWND hwndAct
, hwndDeact
;
887 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
889 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
894 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
895 // scrollbars if necessary
900 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
902 MSWDefWindowProc(message
, wParam
, lParam
);
906 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
907 // the message (the base class version does not)
908 return MSWDefWindowProc(message
, wParam
, lParam
);
910 case WM_WINDOWPOSCHANGING
:
911 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
916 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
921 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
923 // In case it's e.g. a toolbar.
926 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
928 return win
->MSWCommand(cmd
, id
);
931 if (wxCurrentPopupMenu
)
933 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
934 wxCurrentPopupMenu
= NULL
;
935 if (popupMenu
->MSWCommand(cmd
, id
))
940 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
942 processed
= ProcessCommand(id
);
952 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
956 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
962 if ( m_hWnd
== hwndAct
)
965 parent
->m_currentChild
= this;
967 HMENU child_menu
= (HMENU
)GetWinMenu();
970 parent
->m_parentFrameActive
= false;
972 menuToSet
= child_menu
;
975 else if ( m_hWnd
== hwndDeact
)
977 wxASSERT_MSG( parent
->m_currentChild
== this,
978 wxT("can't deactivate MDI child which wasn't active!") );
981 parent
->m_currentChild
= NULL
;
983 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
985 // activate the the parent menu only when there is no other child
986 // that has been activated
987 if ( parent_menu
&& !hwndAct
)
989 parent
->m_parentFrameActive
= true;
991 menuToSet
= parent_menu
;
996 // we have nothing to do with it
1002 MDISetMenu(parent
->GetClientWindow(),
1003 menuToSet
, GetMDIWindowMenu(parent
));
1006 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1007 event
.SetEventObject( this );
1009 ResetWindowStyle((void *)NULL
);
1011 return GetEventHandler()->ProcessEvent(event
);
1014 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1016 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1017 #if defined(__WIN95__)
1018 if (!(lpPos
->flags
& SWP_NOSIZE
))
1021 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1022 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1023 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1025 ::AdjustWindowRectEx(&rectClient
, dwStyle
, false, dwExStyle
);
1026 lpPos
->x
= rectClient
.left
;
1027 lpPos
->y
= rectClient
.top
;
1028 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1029 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1031 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1032 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1034 pFrameWnd
->GetToolBar()->Refresh();
1042 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1044 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1046 // let the default window proc calculate the size of MDI children
1047 // frames because it is based on the size of the MDI client window,
1048 // not on the values specified in wxWindow m_max variables
1049 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1051 int minWidth
= GetMinWidth(),
1052 minHeight
= GetMinHeight();
1054 // but allow GetSizeHints() to set the min size
1055 if ( minWidth
!= -1 )
1057 info
->ptMinTrackSize
.x
= minWidth
;
1062 if ( minHeight
!= -1 )
1064 info
->ptMinTrackSize
.y
= minHeight
;
1072 // ---------------------------------------------------------------------------
1073 // MDI specific message translation/preprocessing
1074 // ---------------------------------------------------------------------------
1076 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1078 return DefMDIChildProc(GetHwnd(),
1079 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1082 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1084 return wxFrame::MSWTranslateMessage(msg
);
1087 // ---------------------------------------------------------------------------
1089 // ---------------------------------------------------------------------------
1091 void wxMDIChildFrame::MSWDestroyWindow()
1093 invalidHandle
= GetHwnd();
1095 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1097 // Must make sure this handle is invalidated (set to NULL) since all sorts
1098 // of things could happen after the child client is destroyed, but before
1099 // the wxFrame is destroyed.
1101 HWND oldHandle
= (HWND
)GetHWND();
1102 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1103 (WPARAM
)oldHandle
, 0);
1105 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1106 ResetWindowStyle((void*) NULL
);
1112 ::DestroyMenu((HMENU
) m_hMenu
);
1115 wxRemoveHandleAssociation(this);
1119 // Change the client window's extended style so we don't get a client edge
1120 // style when a child is maximised (a double border looks silly.)
1121 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1123 #if defined(__WIN95__)
1124 RECT
*rect
= (RECT
*)vrect
;
1125 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1126 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1127 if (!pChild
|| (pChild
== this))
1129 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1130 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1132 // we want to test whether there is a maximized child, so just set
1133 // dwThisStyle to 0 if there is no child at all
1134 DWORD dwThisStyle
= pChild
1135 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1136 DWORD dwNewStyle
= dwStyle
;
1137 if ( dwThisStyle
& WS_MAXIMIZE
)
1138 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1140 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1142 if (dwStyle
!= dwNewStyle
)
1144 // force update of everything
1145 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1146 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1147 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1148 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1149 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1150 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1153 ::GetClientRect(hwndClient
, rect
);
1163 // ===========================================================================
1164 // wxMDIClientWindow: the window of predefined (by Windows) class which
1165 // contains the child frames
1166 // ===========================================================================
1168 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1170 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1172 CLIENTCREATESTRUCT ccs
;
1173 m_windowStyle
= style
;
1176 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1177 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1179 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1180 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1182 if ( style
& wxHSCROLL
)
1183 msStyle
|= WS_HSCROLL
;
1184 if ( style
& wxVSCROLL
)
1185 msStyle
|= WS_VSCROLL
;
1187 #if defined(__WIN95__)
1188 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1193 wxWindowCreationHook
hook(this);
1194 m_hWnd
= (WXHWND
)::CreateWindowEx
1204 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1207 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1212 SubclassWin(m_hWnd
);
1217 // Explicitly call default scroll behaviour
1218 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1220 // Note: for client windows, the scroll position is not set in
1221 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1222 // scroll position we're at.
1223 // This makes it hard to paint patterns or bitmaps in the background,
1224 // and have the client area scrollable as well.
1226 if ( event
.GetOrientation() == wxHORIZONTAL
)
1227 m_scrollX
= event
.GetPosition(); // Always returns zero!
1229 m_scrollY
= event
.GetPosition(); // Always returns zero!
1234 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1236 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1237 // client area, you can end up with a non-refreshed portion in the client window
1238 // (see OGL studio sample). So check if the position is changed and if so,
1239 // redraw the MDI child frames.
1241 wxPoint oldPos
= GetPosition();
1243 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1245 wxPoint newPos
= GetPosition();
1247 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1251 wxWindowList::Node
*node
= GetParent()->GetChildren().GetFirst();
1254 wxWindow
*child
= node
->GetData();
1255 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1257 ::RedrawWindow(GetHwndOf(child
),
1264 node
= node
->GetNext();
1270 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1272 // MDI child frames get their WM_SIZE when they're constructed but at this
1273 // moment they don't have any children yet so all child windows will be
1274 // positioned incorrectly when they are added later - to fix this, we
1275 // generate an artificial size event here
1276 if ( m_needsResize
)
1278 m_needsResize
= false; // avoid any possibility of recursion
1286 // ---------------------------------------------------------------------------
1287 // non member functions
1288 // ---------------------------------------------------------------------------
1290 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1292 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1294 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1296 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1300 // update menu bar of the parent window
1301 wxWindow
*parent
= win
->GetParent();
1302 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1305 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1308 ::DrawMenuBar(GetWinHwnd(parent
));
1311 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1313 // Try to insert Window menu in front of Help, otherwise append it.
1314 HMENU hmenu
= (HMENU
)menu
;
1318 int N
= GetMenuItemCount(hmenu
);
1319 bool success
= false;
1320 for ( int i
= 0; i
< N
; i
++ )
1323 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1326 wxLogLastError(wxT("GetMenuString"));
1331 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1334 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1335 (UINT
)subMenu
, _("&Window"));
1342 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1346 MDISetMenu(win
, hmenu
, subMenu
);
1349 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1351 HMENU hMenu
= (HMENU
)menu
;
1357 int N
= ::GetMenuItemCount(hMenu
);
1358 for ( int i
= 0; i
< N
; i
++ )
1360 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1362 // Ignore successful read of menu string with length 0 which
1363 // occurs, for example, for a maximized MDI childs system menu
1364 if ( ::GetLastError() != 0 )
1366 wxLogLastError(wxT("GetMenuString"));
1372 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1374 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1376 wxLogLastError(wxT("RemoveMenu"));
1386 // we don't change the windows menu, but we update the main one
1387 MDISetMenu(win
, hMenu
, NULL
);
1391 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1392 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1396 *hwndAct
= (WXHWND
)lParam
;
1397 *hwndDeact
= (WXHWND
)wParam
;
1399 *activate
= (WXWORD
)wParam
;
1400 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1401 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1402 #endif // Win32/Win16
1406 // wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__)