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 // ---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "mdi.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
31 #if wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__)
39 #include "wx/dialog.h"
41 #include "wx/statusbr.h"
43 #include "wx/settings.h"
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 extern void wxAssociateWinWithHandle(HWND hWnd
, wxWindow
*win
);
72 extern void wxRemoveHandleAssociation(wxWindow
*win
);
74 static HWND invalidHandle
= 0;
76 // ---------------------------------------------------------------------------
78 // ---------------------------------------------------------------------------
80 static const int IDM_WINDOWTILE
= 4001;
81 static const int IDM_WINDOWTILEHOR
= 4001;
82 static const int IDM_WINDOWCASCADE
= 4002;
83 static const int IDM_WINDOWICONS
= 4003;
84 static const int IDM_WINDOWNEXT
= 4004;
85 static const int IDM_WINDOWTILEVERT
= 4005;
86 static const int IDM_WINDOWPREV
= 4006;
88 // This range gives a maximum of 500 MDI children. Should be enough :-)
89 static const int wxFIRST_MDI_CHILD
= 4100;
90 static const int wxLAST_MDI_CHILD
= 4600;
92 // Status border dimensions
93 static const int wxTHICK_LINE_BORDER
= 3;
94 static const int wxTHICK_LINE_WIDTH
= 1;
96 // ---------------------------------------------------------------------------
98 // ---------------------------------------------------------------------------
100 // set the MDI menus (by sending the WM_MDISETMENU message) and update the menu
101 // of the parent of win (which is supposed to be the MDI client window)
102 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
);
104 // insert the window menu (subMenu) into menu just before "Help" submenu or at
105 // the very end if not found
106 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
);
108 // Remove the window menu
109 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
);
111 // is this an id of an MDI child?
112 inline bool IsMdiCommandId(int id
)
114 return (id
>= wxFIRST_MDI_CHILD
) && (id
<= wxLAST_MDI_CHILD
);
117 // unpack the parameters of WM_MDIACTIVATE message
118 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
119 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
);
121 // return the HMENU of the MDI menu
122 static inline HMENU
GetMDIWindowMenu(wxMDIParentFrame
*frame
)
124 wxMenu
*menu
= frame
->GetWindowMenu();
125 return menu
? GetHmenuOf(menu
) : 0;
128 // ===========================================================================
130 // ===========================================================================
132 // ---------------------------------------------------------------------------
134 // ---------------------------------------------------------------------------
136 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
, wxFrame
)
137 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
, wxFrame
)
138 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
, wxWindow
)
140 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
141 EVT_SIZE(wxMDIParentFrame::OnSize
)
142 EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged
)
145 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
146 EVT_IDLE(wxMDIChildFrame::OnIdle
)
149 BEGIN_EVENT_TABLE(wxMDIClientWindow
, wxWindow
)
150 EVT_SCROLL(wxMDIClientWindow::OnScroll
)
153 // ===========================================================================
154 // wxMDIParentFrame: the frame which contains the client window which manages
156 // ===========================================================================
158 wxMDIParentFrame::wxMDIParentFrame()
160 m_clientWindow
= NULL
;
161 m_currentChild
= NULL
;
162 m_windowMenu
= (wxMenu
*) NULL
;
163 m_parentFrameActive
= true;
166 bool wxMDIParentFrame::Create(wxWindow
*parent
,
168 const wxString
& title
,
172 const wxString
& name
)
174 m_clientWindow
= NULL
;
175 m_currentChild
= NULL
;
177 // this style can be used to prevent a window from having the standard MDI
179 if ( style
& wxFRAME_NO_WINDOW_MENU
)
181 m_windowMenu
= (wxMenu
*)NULL
;
183 else // normal case: we have the window menu, so construct it
185 m_windowMenu
= new wxMenu
;
187 m_windowMenu
->Append(IDM_WINDOWCASCADE
, _("&Cascade"));
188 m_windowMenu
->Append(IDM_WINDOWTILEHOR
, _("Tile &Horizontally"));
189 m_windowMenu
->Append(IDM_WINDOWTILEVERT
, _("Tile &Vertically"));
190 m_windowMenu
->AppendSeparator();
191 m_windowMenu
->Append(IDM_WINDOWICONS
, _("&Arrange Icons"));
192 m_windowMenu
->Append(IDM_WINDOWNEXT
, _("&Next"));
193 m_windowMenu
->Append(IDM_WINDOWPREV
, _("&Previous"));
196 m_parentFrameActive
= true;
199 wxTopLevelWindows
.Append(this);
202 m_windowStyle
= style
;
205 parent
->AddChild(this);
210 m_windowId
= NewControlId();
213 WXDWORD msflags
= MSWGetCreateWindowFlags(&exflags
);
214 msflags
&= ~WS_VSCROLL
;
215 msflags
&= ~WS_HSCROLL
;
217 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
226 wxModelessWindows
.Append(this);
228 // unlike (almost?) all other windows, frames are created hidden
234 wxMDIParentFrame::~wxMDIParentFrame()
236 // see comment in ~wxMDIChildFrame
237 m_frameToolBar
= NULL
;
238 m_frameStatusBar
= NULL
;
245 m_windowMenu
= (wxMenu
*) NULL
;
248 // the MDI frame menubar is not automatically deleted by Windows unlike for
252 ::DestroyMenu((HMENU
)m_hMenu
);
253 m_hMenu
= (WXHMENU
)NULL
;
256 if ( m_clientWindow
)
258 if ( m_clientWindow
->MSWGetOldWndProc() )
259 m_clientWindow
->UnsubclassWin();
261 m_clientWindow
->SetHWND(0);
262 delete m_clientWindow
;
266 #if wxUSE_MENUS_NATIVE
268 void wxMDIParentFrame::InternalSetMenuBar()
270 m_parentFrameActive
= true;
272 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
275 #endif // wxUSE_MENUS_NATIVE
277 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
283 // Remove old window menu
284 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
288 m_windowMenu
= (wxMenu
*) NULL
;
296 InsertWindowMenu(GetClientWindow(), m_hMenu
,
297 GetHmenuOf(m_windowMenu
));
302 void wxMDIParentFrame::OnSize(wxSizeEvent
&)
304 if ( GetClientWindow() )
307 GetClientSize(&width
, &height
);
309 GetClientWindow()->SetSize(0, 0, width
, height
);
313 // Returns the active MDI child window
314 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
316 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
317 WM_MDIGETACTIVE
, 0, 0L);
321 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
324 // Create the client window class (don't Create the window, just return a new
326 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
328 return new wxMDIClientWindow
;
331 // Responds to colour changes, and passes event on to children.
332 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
334 if ( m_clientWindow
)
336 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
337 m_clientWindow
->Refresh();
343 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
345 // we don't have any standard icons (any more)
349 // ---------------------------------------------------------------------------
351 // ---------------------------------------------------------------------------
353 void wxMDIParentFrame::Cascade()
355 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
358 // TODO: add a direction argument (hor/vert)
359 void wxMDIParentFrame::Tile()
361 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
364 void wxMDIParentFrame::ArrangeIcons()
366 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
369 void wxMDIParentFrame::ActivateNext()
371 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
374 void wxMDIParentFrame::ActivatePrevious()
376 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
379 // ---------------------------------------------------------------------------
380 // the MDI parent frame window proc
381 // ---------------------------------------------------------------------------
383 long wxMDIParentFrame::MSWWindowProc(WXUINT message
,
388 bool processed
= false;
394 WXWORD state
, minimized
;
396 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
398 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
406 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
408 (void)HandleCommand(id
, cmd
, hwnd
);
410 // even if the frame didn't process it, there is no need to try it
411 // once again (i.e. call wxFrame::HandleCommand()) - we just did it,
412 // so pretend we processed the message anyhow
416 // always pass this message DefFrameProc(), otherwise MDI menu
417 // commands (and sys commands - more surprisingly!) won't work
418 MSWDefWindowProc(message
, wParam
, lParam
);
422 m_clientWindow
= OnCreateClient();
423 // Uses own style for client style
424 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
426 wxLogMessage(_("Failed to create MDI parent frame."));
437 // we erase background ourselves
445 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
447 if ( m_parentFrameActive
)
449 processed
= HandleMenuSelect(item
, flags
, hmenu
);
451 else if (m_currentChild
)
453 processed
= m_currentChild
->
454 HandleMenuSelect(item
, flags
, hmenu
);
460 // as we don't (usually) resize the MDI client to exactly fit the
461 // client area (we put it below the toolbar, above statusbar &c),
462 // we should not pass this one to DefFrameProc
467 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
472 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
474 bool processed
= false;
476 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
482 // If this window is an MDI parent, we must also send an OnActivate message
483 // to the current child.
484 if ( (m_currentChild
!= NULL
) &&
485 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
487 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_currentChild
->GetId());
488 event
.SetEventObject( m_currentChild
);
489 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
496 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
498 // In case it's e.g. a toolbar.
501 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
503 return win
->MSWCommand(cmd
, id
);
506 // is it one of standard MDI commands?
512 case IDM_WINDOWCASCADE
:
514 wParam
= MDITILE_SKIPDISABLED
;
517 case IDM_WINDOWTILEHOR
:
518 wParam
|= MDITILE_HORIZONTAL
;
521 case IDM_WINDOWTILEVERT
:
523 wParam
= MDITILE_VERTICAL
;
525 wParam
|= MDITILE_SKIPDISABLED
;
528 case IDM_WINDOWICONS
:
529 msg
= WM_MDIICONARRANGE
;
534 lParam
= 0; // next child
539 lParam
= 1; // previous child
548 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, lParam
);
553 // FIXME VZ: what does this test do??
556 return false; // Get WndProc to call default proc
559 if ( IsMdiCommandId(id
) )
561 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
564 wxWindow
*child
= node
->GetData();
565 if ( child
->GetHWND() )
567 long childId
= wxGetWindowId(child
->GetHWND());
568 if (childId
== (long)id
)
570 ::SendMessage( GetWinHwnd(GetClientWindow()),
572 (WPARAM
)child
->GetHWND(), 0);
576 node
= node
->GetNext();
579 else if ( m_parentFrameActive
)
581 return ProcessCommand(id
);
583 else if ( m_currentChild
)
585 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
589 // this shouldn't happen because it means that our messages are being
590 // lost (they're not sent to the parent frame nor to the children)
591 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
597 long wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
602 if ( GetClientWindow() )
603 clientWnd
= GetClientWindow()->GetHWND();
607 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
610 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
612 MSG
*pMsg
= (MSG
*)msg
;
614 // first let the current child get it
615 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
616 m_currentChild
->MSWTranslateMessage(msg
) )
621 // then try out accel table (will also check the menu accels)
622 if ( wxFrame::MSWTranslateMessage(msg
) )
627 // finally, check for MDI specific built in accel keys
628 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
630 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
637 // ===========================================================================
639 // ===========================================================================
641 void wxMDIChildFrame::Init()
643 m_needsResize
= true;
646 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
648 const wxString
& title
,
652 const wxString
& name
)
655 wxWindowBase::Show(true); // MDI child frame starts off shown
660 m_windowId
= (int)NewControlId();
664 parent
->AddChild(this);
674 mcs
.szClass
= style
& wxFULL_REPAINT_ON_RESIZE
675 ? wxMDIChildFrameClassName
676 : wxMDIChildFrameClassNameNoRedraw
;
678 mcs
.hOwner
= wxGetInstance();
682 mcs
.x
= CW_USEDEFAULT
;
687 mcs
.y
= CW_USEDEFAULT
;
692 mcs
.cx
= CW_USEDEFAULT
;
697 mcs
.cy
= CW_USEDEFAULT
;
699 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
| WS_VISIBLE
;
700 if (style
& wxMINIMIZE_BOX
)
701 msflags
|= WS_MINIMIZEBOX
;
702 if (style
& wxMAXIMIZE_BOX
)
703 msflags
|= WS_MAXIMIZEBOX
;
704 if (style
& wxTHICK_FRAME
)
705 msflags
|= WS_THICKFRAME
;
706 if (style
& wxSYSTEM_MENU
)
707 msflags
|= WS_SYSMENU
;
708 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
709 msflags
|= WS_MINIMIZE
;
710 if (style
& wxMAXIMIZE
)
711 msflags
|= WS_MAXIMIZE
;
712 if (style
& wxCAPTION
)
713 msflags
|= WS_CAPTION
;
719 wxWindowCreationHook
hook(this);
721 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
722 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
724 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
726 wxModelessWindows
.Append(this);
731 wxMDIChildFrame::~wxMDIChildFrame()
733 // will be destroyed by DestroyChildren() but reset them before calling it
734 // to avoid using dangling pointers if a callback comes in the meanwhile
735 m_frameToolBar
= NULL
;
736 m_frameStatusBar
= NULL
;
740 RemoveWindowMenu(NULL
, m_hMenu
);
745 // Set the client size (i.e. leave the calculation of borders etc.
747 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
749 HWND hWnd
= GetHwnd();
752 ::GetClientRect(hWnd
, &rect
);
755 GetWindowRect(hWnd
, &rect2
);
757 // Find the difference between the entire window (title bar and all)
758 // and the client area; add this to the new client size to move the
760 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
761 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
763 if (GetStatusBar() && GetStatusBar()->IsShown())
766 GetStatusBar()->GetSize(&sx
, &sy
);
771 point
.x
= rect2
.left
;
774 // If there's an MDI parent, must subtract the parent's top left corner
775 // since MoveWindow moves relative to the parent
776 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
777 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
779 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)true);
781 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
782 event
.SetEventObject( this );
783 GetEventHandler()->ProcessEvent(event
);
786 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
789 GetWindowRect(GetHwnd(), &rect
);
794 // Since we now have the absolute screen coords,
795 // if there's a parent we must subtract its top left corner
796 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
797 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
803 void wxMDIChildFrame::InternalSetMenuBar()
805 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
807 InsertWindowMenu(parent
->GetClientWindow(),
808 m_hMenu
, GetMDIWindowMenu(parent
));
810 parent
->m_parentFrameActive
= false;
813 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
815 // we don't have any standard icons (any more)
819 // ---------------------------------------------------------------------------
821 // ---------------------------------------------------------------------------
823 void wxMDIChildFrame::Maximize(bool maximize
)
825 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
826 if ( parent
&& parent
->GetClientWindow() )
828 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
829 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
830 (WPARAM
)GetHwnd(), 0);
834 void wxMDIChildFrame::Restore()
836 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
837 if ( parent
&& parent
->GetClientWindow() )
839 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
840 (WPARAM
) GetHwnd(), 0);
844 void wxMDIChildFrame::Activate()
846 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
847 if ( parent
&& parent
->GetClientWindow() )
849 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
850 (WPARAM
) GetHwnd(), 0);
854 // ---------------------------------------------------------------------------
855 // MDI window proc and message handlers
856 // ---------------------------------------------------------------------------
858 long wxMDIChildFrame::MSWWindowProc(WXUINT message
,
863 bool processed
= false;
871 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
874 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
878 case WM_GETMINMAXINFO
:
879 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
885 WXHWND hwndAct
, hwndDeact
;
886 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
888 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
893 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
894 // scrollbars if necessary
899 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
901 MSWDefWindowProc(message
, wParam
, lParam
);
905 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
906 // the message (the base class version does not)
907 return MSWDefWindowProc(message
, wParam
, lParam
);
909 case WM_WINDOWPOSCHANGING
:
910 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
915 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
920 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
922 // In case it's e.g. a toolbar.
925 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
927 return win
->MSWCommand(cmd
, id
);
930 if (wxCurrentPopupMenu
)
932 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
933 wxCurrentPopupMenu
= NULL
;
934 if (popupMenu
->MSWCommand(cmd
, id
))
939 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
941 processed
= ProcessCommand(id
);
951 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
955 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
961 if ( m_hWnd
== hwndAct
)
964 parent
->m_currentChild
= this;
966 HMENU child_menu
= (HMENU
)GetWinMenu();
969 parent
->m_parentFrameActive
= false;
971 menuToSet
= child_menu
;
974 else if ( m_hWnd
== hwndDeact
)
976 wxASSERT_MSG( parent
->m_currentChild
== this,
977 wxT("can't deactivate MDI child which wasn't active!") );
980 parent
->m_currentChild
= NULL
;
982 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
984 // activate the the parent menu only when there is no other child
985 // that has been activated
986 if ( parent_menu
&& !hwndAct
)
988 parent
->m_parentFrameActive
= true;
990 menuToSet
= parent_menu
;
995 // we have nothing to do with it
1001 MDISetMenu(parent
->GetClientWindow(),
1002 menuToSet
, GetMDIWindowMenu(parent
));
1005 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1006 event
.SetEventObject( this );
1008 ResetWindowStyle((void *)NULL
);
1010 return GetEventHandler()->ProcessEvent(event
);
1013 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1015 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1016 #if defined(__WIN95__)
1017 if (!(lpPos
->flags
& SWP_NOSIZE
))
1020 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1021 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1022 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1024 ::AdjustWindowRectEx(&rectClient
, dwStyle
, false, dwExStyle
);
1025 lpPos
->x
= rectClient
.left
;
1026 lpPos
->y
= rectClient
.top
;
1027 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1028 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1030 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1031 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1033 pFrameWnd
->GetToolBar()->Refresh();
1041 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1043 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1045 // let the default window proc calculate the size of MDI children
1046 // frames because it is based on the size of the MDI client window,
1047 // not on the values specified in wxWindow m_max variables
1048 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1050 int minWidth
= GetMinWidth(),
1051 minHeight
= GetMinHeight();
1053 // but allow GetSizeHints() to set the min size
1054 if ( minWidth
!= -1 )
1056 info
->ptMinTrackSize
.x
= minWidth
;
1061 if ( minHeight
!= -1 )
1063 info
->ptMinTrackSize
.y
= minHeight
;
1071 // ---------------------------------------------------------------------------
1072 // MDI specific message translation/preprocessing
1073 // ---------------------------------------------------------------------------
1075 long wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXUINT wParam
, WXLPARAM lParam
)
1077 return DefMDIChildProc(GetHwnd(),
1078 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1081 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1083 return wxFrame::MSWTranslateMessage(msg
);
1086 // ---------------------------------------------------------------------------
1088 // ---------------------------------------------------------------------------
1090 void wxMDIChildFrame::MSWDestroyWindow()
1092 invalidHandle
= GetHwnd();
1094 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1096 // Must make sure this handle is invalidated (set to NULL) since all sorts
1097 // of things could happen after the child client is destroyed, but before
1098 // the wxFrame is destroyed.
1100 HWND oldHandle
= (HWND
)GetHWND();
1101 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1102 (WPARAM
)oldHandle
, 0);
1104 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1105 ResetWindowStyle((void*) NULL
);
1111 ::DestroyMenu((HMENU
) m_hMenu
);
1114 wxRemoveHandleAssociation(this);
1118 // Change the client window's extended style so we don't get a client edge
1119 // style when a child is maximised (a double border looks silly.)
1120 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1122 #if defined(__WIN95__)
1123 RECT
*rect
= (RECT
*)vrect
;
1124 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1125 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1126 if (!pChild
|| (pChild
== this))
1128 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1129 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1131 // we want to test whether there is a maximized child, so just set
1132 // dwThisStyle to 0 if there is no child at all
1133 DWORD dwThisStyle
= pChild
1134 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1135 DWORD dwNewStyle
= dwStyle
;
1136 if ( dwThisStyle
& WS_MAXIMIZE
)
1137 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1139 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1141 if (dwStyle
!= dwNewStyle
)
1143 // force update of everything
1144 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1145 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1146 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1147 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1148 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1149 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1152 ::GetClientRect(hwndClient
, rect
);
1162 // ===========================================================================
1163 // wxMDIClientWindow: the window of predefined (by Windows) class which
1164 // contains the child frames
1165 // ===========================================================================
1167 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1169 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1171 CLIENTCREATESTRUCT ccs
;
1172 m_windowStyle
= style
;
1175 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1176 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1178 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1179 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1181 if ( style
& wxHSCROLL
)
1182 msStyle
|= WS_HSCROLL
;
1183 if ( style
& wxVSCROLL
)
1184 msStyle
|= WS_VSCROLL
;
1186 #if defined(__WIN95__)
1187 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1192 wxWindowCreationHook
hook(this);
1193 m_hWnd
= (WXHWND
)::CreateWindowEx
1203 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1206 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1211 SubclassWin(m_hWnd
);
1216 // Explicitly call default scroll behaviour
1217 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1219 // Note: for client windows, the scroll position is not set in
1220 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1221 // scroll position we're at.
1222 // This makes it hard to paint patterns or bitmaps in the background,
1223 // and have the client area scrollable as well.
1225 if ( event
.GetOrientation() == wxHORIZONTAL
)
1226 m_scrollX
= event
.GetPosition(); // Always returns zero!
1228 m_scrollY
= event
.GetPosition(); // Always returns zero!
1233 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1235 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1236 // client area, you can end up with a non-refreshed portion in the client window
1237 // (see OGL studio sample). So check if the position is changed and if so,
1238 // redraw the MDI child frames.
1240 wxPoint oldPos
= GetPosition();
1242 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1244 wxPoint newPos
= GetPosition();
1246 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1250 wxWindowList::compatibility_iterator node
= GetParent()->GetChildren().GetFirst();
1253 wxWindow
*child
= node
->GetData();
1254 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1256 ::RedrawWindow(GetHwndOf(child
),
1263 node
= node
->GetNext();
1269 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1271 // MDI child frames get their WM_SIZE when they're constructed but at this
1272 // moment they don't have any children yet so all child windows will be
1273 // positioned incorrectly when they are added later - to fix this, we
1274 // generate an artificial size event here
1275 if ( m_needsResize
)
1277 m_needsResize
= false; // avoid any possibility of recursion
1285 // ---------------------------------------------------------------------------
1286 // non member functions
1287 // ---------------------------------------------------------------------------
1289 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1291 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1293 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1295 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1299 // update menu bar of the parent window
1300 wxWindow
*parent
= win
->GetParent();
1301 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1304 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1307 ::DrawMenuBar(GetWinHwnd(parent
));
1310 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1312 // Try to insert Window menu in front of Help, otherwise append it.
1313 HMENU hmenu
= (HMENU
)menu
;
1317 int N
= GetMenuItemCount(hmenu
);
1318 bool success
= false;
1319 for ( int i
= 0; i
< N
; i
++ )
1322 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1325 wxLogLastError(wxT("GetMenuString"));
1330 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1333 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1334 (UINT
)subMenu
, _("&Window"));
1341 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1345 MDISetMenu(win
, hmenu
, subMenu
);
1348 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1350 HMENU hMenu
= (HMENU
)menu
;
1356 int N
= ::GetMenuItemCount(hMenu
);
1357 for ( int i
= 0; i
< N
; i
++ )
1359 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1361 // Ignore successful read of menu string with length 0 which
1362 // occurs, for example, for a maximized MDI childs system menu
1363 if ( ::GetLastError() != 0 )
1365 wxLogLastError(wxT("GetMenuString"));
1371 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1373 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1375 wxLogLastError(wxT("RemoveMenu"));
1385 // we don't change the windows menu, but we update the main one
1386 MDISetMenu(win
, hMenu
, NULL
);
1390 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1391 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1395 *hwndAct
= (WXHWND
)lParam
;
1396 *hwndDeact
= (WXHWND
)wParam
;
1398 *activate
= (WXWORD
)wParam
;
1399 *hwndAct
= (WXHWND
)LOWORD(lParam
);
1400 *hwndDeact
= (WXHWND
)HIWORD(lParam
);
1401 #endif // Win32/Win16
1405 // wxUSE_MDI_ARCHITECTURE && !defined(__WXUNIVERSAL__)