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 && !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 wxMenu
*wxCurrentPopupMenu
;
67 extern const wxChar
*wxMDIFrameClassName
; // from app.cpp
68 extern const wxChar
*wxMDIChildFrameClassName
;
69 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
);
213 msflags
&= ~WS_VSCROLL
;
214 msflags
&= ~WS_HSCROLL
;
216 if ( !wxWindow::MSWCreate(wxMDIFrameClassName
,
225 // unlike (almost?) all other windows, frames are created hidden
231 wxMDIParentFrame::~wxMDIParentFrame()
233 // see comment in ~wxMDIChildFrame
235 m_frameToolBar
= NULL
;
238 m_frameStatusBar
= NULL
;
239 #endif // wxUSE_STATUSBAR
246 m_windowMenu
= (wxMenu
*) NULL
;
249 // the MDI frame menubar is not automatically deleted by Windows unlike for
253 ::DestroyMenu((HMENU
)m_hMenu
);
254 m_hMenu
= (WXHMENU
)NULL
;
257 if ( m_clientWindow
)
259 if ( m_clientWindow
->MSWGetOldWndProc() )
260 m_clientWindow
->UnsubclassWin();
262 m_clientWindow
->SetHWND(0);
263 delete m_clientWindow
;
267 #if wxUSE_MENUS_NATIVE
269 void wxMDIParentFrame::InternalSetMenuBar()
271 m_parentFrameActive
= true;
273 InsertWindowMenu(GetClientWindow(), m_hMenu
, GetMDIWindowMenu(this));
276 #endif // wxUSE_MENUS_NATIVE
278 void wxMDIParentFrame::SetWindowMenu(wxMenu
* menu
)
284 // Remove old window menu
285 RemoveWindowMenu(GetClientWindow(), m_hMenu
);
289 m_windowMenu
= (wxMenu
*) NULL
;
297 InsertWindowMenu(GetClientWindow(), m_hMenu
,
298 GetHmenuOf(m_windowMenu
));
303 void wxMDIParentFrame::OnSize(wxSizeEvent
&)
305 if ( GetClientWindow() )
308 GetClientSize(&width
, &height
);
310 GetClientWindow()->SetSize(0, 0, width
, height
);
314 // Returns the active MDI child window
315 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild() const
317 HWND hWnd
= (HWND
)::SendMessage(GetWinHwnd(GetClientWindow()),
318 WM_MDIGETACTIVE
, 0, 0L);
322 return (wxMDIChildFrame
*)wxFindWinFromHandle((WXHWND
) hWnd
);
325 // Create the client window class (don't Create the window, just return a new
327 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient()
329 return new wxMDIClientWindow
;
332 // Responds to colour changes, and passes event on to children.
333 void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent
& event
)
335 if ( m_clientWindow
)
337 m_clientWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
));
338 m_clientWindow
->Refresh();
344 WXHICON
wxMDIParentFrame::GetDefaultIcon() const
346 // we don't have any standard icons (any more)
350 // ---------------------------------------------------------------------------
352 // ---------------------------------------------------------------------------
354 void wxMDIParentFrame::Cascade()
356 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE
, 0, 0);
359 // TODO: add a direction argument (hor/vert)
360 void wxMDIParentFrame::Tile()
362 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE
, MDITILE_HORIZONTAL
, 0);
365 void wxMDIParentFrame::ArrangeIcons()
367 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE
, 0, 0);
370 void wxMDIParentFrame::ActivateNext()
372 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 0);
375 void wxMDIParentFrame::ActivatePrevious()
377 ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT
, 0, 1);
380 // ---------------------------------------------------------------------------
381 // the MDI parent frame window proc
382 // ---------------------------------------------------------------------------
384 WXLRESULT
wxMDIParentFrame::MSWWindowProc(WXUINT message
,
389 bool processed
= false;
395 WXWORD state
, minimized
;
397 UnpackActivate(wParam
, lParam
, &state
, &minimized
, &hwnd
);
399 processed
= HandleActivate(state
, minimized
!= 0, hwnd
);
407 UnpackCommand(wParam
, lParam
, &id
, &hwnd
, &cmd
);
409 (void)HandleCommand(id
, cmd
, hwnd
);
411 // even if the frame didn't process it, there is no need to try it
412 // once again (i.e. call wxFrame::HandleCommand()) - we just did it,
413 // so pretend we processed the message anyhow
417 // always pass this message DefFrameProc(), otherwise MDI menu
418 // commands (and sys commands - more surprisingly!) won't work
419 MSWDefWindowProc(message
, wParam
, lParam
);
423 m_clientWindow
= OnCreateClient();
424 // Uses own style for client style
425 if ( !m_clientWindow
->CreateClient(this, GetWindowStyleFlag()) )
427 wxLogMessage(_("Failed to create MDI parent frame."));
438 // we erase background ourselves
446 UnpackMenuSelect(wParam
, lParam
, &item
, &flags
, &hmenu
);
448 if ( m_parentFrameActive
)
450 processed
= HandleMenuSelect(item
, flags
, hmenu
);
452 else if (m_currentChild
)
454 processed
= m_currentChild
->
455 HandleMenuSelect(item
, flags
, hmenu
);
461 // as we don't (usually) resize the MDI client to exactly fit the
462 // client area (we put it below the toolbar, above statusbar &c),
463 // we should not pass this one to DefFrameProc
468 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
473 bool wxMDIParentFrame::HandleActivate(int state
, bool minimized
, WXHWND activate
)
475 bool processed
= false;
477 if ( wxWindow::HandleActivate(state
, minimized
, activate
) )
483 // If this window is an MDI parent, we must also send an OnActivate message
484 // to the current child.
485 if ( (m_currentChild
!= NULL
) &&
486 ((state
== WA_ACTIVE
) || (state
== WA_CLICKACTIVE
)) )
488 wxActivateEvent
event(wxEVT_ACTIVATE
, true, m_currentChild
->GetId());
489 event
.SetEventObject( m_currentChild
);
490 if ( m_currentChild
->GetEventHandler()->ProcessEvent(event
) )
497 bool wxMDIParentFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
499 // In case it's e.g. a toolbar.
502 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
504 return win
->MSWCommand(cmd
, id
);
507 // is it one of standard MDI commands?
513 case IDM_WINDOWCASCADE
:
515 wParam
= MDITILE_SKIPDISABLED
;
518 case IDM_WINDOWTILEHOR
:
519 wParam
|= MDITILE_HORIZONTAL
;
522 case IDM_WINDOWTILEVERT
:
524 wParam
= MDITILE_VERTICAL
;
526 wParam
|= MDITILE_SKIPDISABLED
;
529 case IDM_WINDOWICONS
:
530 msg
= WM_MDIICONARRANGE
;
535 lParam
= 0; // next child
540 lParam
= 1; // previous child
549 ::SendMessage(GetWinHwnd(GetClientWindow()), msg
, wParam
, lParam
);
554 // FIXME VZ: what does this test do??
557 return false; // Get WndProc to call default proc
560 if ( IsMdiCommandId(id
) )
562 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
565 wxWindow
*child
= node
->GetData();
566 if ( child
->GetHWND() )
568 long childId
= wxGetWindowId(child
->GetHWND());
569 if (childId
== (long)id
)
571 ::SendMessage( GetWinHwnd(GetClientWindow()),
573 (WPARAM
)child
->GetHWND(), 0);
577 node
= node
->GetNext();
580 else if ( m_parentFrameActive
)
582 return ProcessCommand(id
);
584 else if ( m_currentChild
)
586 return m_currentChild
->HandleCommand(id
, cmd
, hwnd
);
590 // this shouldn't happen because it means that our messages are being
591 // lost (they're not sent to the parent frame nor to the children)
592 wxFAIL_MSG(wxT("MDI parent frame is not active, yet there is no active MDI child?"));
598 WXLRESULT
wxMDIParentFrame::MSWDefWindowProc(WXUINT message
,
603 if ( GetClientWindow() )
604 clientWnd
= GetClientWindow()->GetHWND();
608 return DefFrameProc(GetHwnd(), (HWND
)clientWnd
, message
, wParam
, lParam
);
611 bool wxMDIParentFrame::MSWTranslateMessage(WXMSG
* msg
)
613 MSG
*pMsg
= (MSG
*)msg
;
615 // first let the current child get it
616 if ( m_currentChild
&& m_currentChild
->GetHWND() &&
617 m_currentChild
->MSWTranslateMessage(msg
) )
622 // then try out accel table (will also check the menu accels)
623 if ( wxFrame::MSWTranslateMessage(msg
) )
628 // finally, check for MDI specific built in accel keys
629 if ( pMsg
->message
== WM_KEYDOWN
|| pMsg
->message
== WM_SYSKEYDOWN
)
631 if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg
))
638 // ===========================================================================
640 // ===========================================================================
642 void wxMDIChildFrame::Init()
644 m_needsResize
= true;
647 bool wxMDIChildFrame::Create(wxMDIParentFrame
*parent
,
649 const wxString
& title
,
653 const wxString
& name
)
656 wxWindowBase::Show(true); // MDI child frame starts off shown
661 m_windowId
= (int)NewControlId();
665 parent
->AddChild(this);
675 mcs
.szClass
= style
& wxFULL_REPAINT_ON_RESIZE
676 ? wxMDIChildFrameClassName
677 : wxMDIChildFrameClassNameNoRedraw
;
679 mcs
.hOwner
= wxGetInstance();
683 mcs
.x
= CW_USEDEFAULT
;
688 mcs
.y
= CW_USEDEFAULT
;
693 mcs
.cx
= CW_USEDEFAULT
;
698 mcs
.cy
= CW_USEDEFAULT
;
700 DWORD msflags
= WS_OVERLAPPED
| WS_CLIPCHILDREN
| WS_VISIBLE
;
701 if (style
& wxMINIMIZE_BOX
)
702 msflags
|= WS_MINIMIZEBOX
;
703 if (style
& wxMAXIMIZE_BOX
)
704 msflags
|= WS_MAXIMIZEBOX
;
705 if (style
& wxTHICK_FRAME
)
706 msflags
|= WS_THICKFRAME
;
707 if (style
& wxSYSTEM_MENU
)
708 msflags
|= WS_SYSMENU
;
709 if ((style
& wxMINIMIZE
) || (style
& wxICONIZE
))
710 msflags
|= WS_MINIMIZE
;
711 if (style
& wxMAXIMIZE
)
712 msflags
|= WS_MAXIMIZE
;
713 if (style
& wxCAPTION
)
714 msflags
|= WS_CAPTION
;
720 wxWindowCreationHook
hook(this);
722 m_hWnd
= (WXHWND
)::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
723 WM_MDICREATE
, 0, (LONG
)(LPSTR
)&mcs
);
725 wxAssociateWinWithHandle((HWND
) GetHWND(), this);
730 wxMDIChildFrame::~wxMDIChildFrame()
732 // will be destroyed by DestroyChildren() but reset them before calling it
733 // to avoid using dangling pointers if a callback comes in the meanwhile
735 m_frameToolBar
= NULL
;
738 m_frameStatusBar
= NULL
;
739 #endif // wxUSE_STATUSBAR
743 RemoveWindowMenu(NULL
, m_hMenu
);
748 // Set the client size (i.e. leave the calculation of borders etc.
750 void wxMDIChildFrame::DoSetClientSize(int width
, int height
)
752 HWND hWnd
= GetHwnd();
755 ::GetClientRect(hWnd
, &rect
);
758 GetWindowRect(hWnd
, &rect2
);
760 // Find the difference between the entire window (title bar and all)
761 // and the client area; add this to the new client size to move the
763 int actual_width
= rect2
.right
- rect2
.left
- rect
.right
+ width
;
764 int actual_height
= rect2
.bottom
- rect2
.top
- rect
.bottom
+ height
;
767 if (GetStatusBar() && GetStatusBar()->IsShown())
770 GetStatusBar()->GetSize(&sx
, &sy
);
773 #endif // wxUSE_STATUSBAR
776 point
.x
= rect2
.left
;
779 // If there's an MDI parent, must subtract the parent's top left corner
780 // since MoveWindow moves relative to the parent
781 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
782 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
784 MoveWindow(hWnd
, point
.x
, point
.y
, actual_width
, actual_height
, (BOOL
)true);
786 wxSizeEvent
event(wxSize(width
, height
), m_windowId
);
787 event
.SetEventObject( this );
788 GetEventHandler()->ProcessEvent(event
);
791 void wxMDIChildFrame::DoGetPosition(int *x
, int *y
) const
794 GetWindowRect(GetHwnd(), &rect
);
799 // Since we now have the absolute screen coords,
800 // if there's a parent we must subtract its top left corner
801 wxMDIParentFrame
*mdiParent
= (wxMDIParentFrame
*)GetParent();
802 ::ScreenToClient((HWND
) mdiParent
->GetClientWindow()->GetHWND(), &point
);
808 void wxMDIChildFrame::InternalSetMenuBar()
810 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
812 InsertWindowMenu(parent
->GetClientWindow(),
813 m_hMenu
, GetMDIWindowMenu(parent
));
815 parent
->m_parentFrameActive
= false;
818 WXHICON
wxMDIChildFrame::GetDefaultIcon() const
820 // we don't have any standard icons (any more)
824 // ---------------------------------------------------------------------------
826 // ---------------------------------------------------------------------------
828 void wxMDIChildFrame::Maximize(bool maximize
)
830 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
831 if ( parent
&& parent
->GetClientWindow() )
833 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()),
834 maximize
? WM_MDIMAXIMIZE
: WM_MDIRESTORE
,
835 (WPARAM
)GetHwnd(), 0);
839 void wxMDIChildFrame::Restore()
841 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
842 if ( parent
&& parent
->GetClientWindow() )
844 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIRESTORE
,
845 (WPARAM
) GetHwnd(), 0);
849 void wxMDIChildFrame::Activate()
851 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
852 if ( parent
&& parent
->GetClientWindow() )
854 ::SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIACTIVATE
,
855 (WPARAM
) GetHwnd(), 0);
859 // ---------------------------------------------------------------------------
860 // MDI window proc and message handlers
861 // ---------------------------------------------------------------------------
863 WXLRESULT
wxMDIChildFrame::MSWWindowProc(WXUINT message
,
868 bool processed
= false;
876 UnpackCommand((WXWPARAM
)wParam
, (WXLPARAM
)lParam
,
879 processed
= HandleCommand(id
, cmd
, (WXHWND
)hwnd
);
883 case WM_GETMINMAXINFO
:
884 processed
= HandleGetMinMaxInfo((MINMAXINFO
*)lParam
);
890 WXHWND hwndAct
, hwndDeact
;
891 UnpackMDIActivate(wParam
, lParam
, &act
, &hwndAct
, &hwndDeact
);
893 processed
= HandleMDIActivate(act
, hwndAct
, hwndDeact
);
898 // must pass WM_MOVE to DefMDIChildProc() to recalculate MDI client
899 // scrollbars if necessary
904 // must pass WM_SIZE to DefMDIChildProc(), otherwise many weird
906 MSWDefWindowProc(message
, wParam
, lParam
);
910 // DefMDIChildProc handles SC_{NEXT/PREV}WINDOW here, so pass it
911 // the message (the base class version does not)
912 return MSWDefWindowProc(message
, wParam
, lParam
);
914 case WM_WINDOWPOSCHANGING
:
915 processed
= HandleWindowPosChanging((LPWINDOWPOS
)lParam
);
920 rc
= wxFrame::MSWWindowProc(message
, wParam
, lParam
);
925 bool wxMDIChildFrame::HandleCommand(WXWORD id
, WXWORD cmd
, WXHWND hwnd
)
927 // In case it's e.g. a toolbar.
930 wxWindow
*win
= wxFindWinFromHandle(hwnd
);
932 return win
->MSWCommand(cmd
, id
);
935 if (wxCurrentPopupMenu
)
937 wxMenu
*popupMenu
= wxCurrentPopupMenu
;
938 wxCurrentPopupMenu
= NULL
;
939 if (popupMenu
->MSWCommand(cmd
, id
))
944 if (GetMenuBar() && GetMenuBar()->FindItem(id
))
946 processed
= ProcessCommand(id
);
956 bool wxMDIChildFrame::HandleMDIActivate(long WXUNUSED(activate
),
960 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
966 if ( m_hWnd
== hwndAct
)
969 parent
->m_currentChild
= this;
971 HMENU child_menu
= (HMENU
)GetWinMenu();
974 parent
->m_parentFrameActive
= false;
976 menuToSet
= child_menu
;
979 else if ( m_hWnd
== hwndDeact
)
981 wxASSERT_MSG( parent
->m_currentChild
== this,
982 wxT("can't deactivate MDI child which wasn't active!") );
985 parent
->m_currentChild
= NULL
;
987 HMENU parent_menu
= (HMENU
)parent
->GetWinMenu();
989 // activate the the parent menu only when there is no other child
990 // that has been activated
991 if ( parent_menu
&& !hwndAct
)
993 parent
->m_parentFrameActive
= true;
995 menuToSet
= parent_menu
;
1000 // we have nothing to do with it
1006 MDISetMenu(parent
->GetClientWindow(),
1007 menuToSet
, GetMDIWindowMenu(parent
));
1010 wxActivateEvent
event(wxEVT_ACTIVATE
, activated
, m_windowId
);
1011 event
.SetEventObject( this );
1013 ResetWindowStyle((void *)NULL
);
1015 return GetEventHandler()->ProcessEvent(event
);
1018 bool wxMDIChildFrame::HandleWindowPosChanging(void *pos
)
1020 WINDOWPOS
*lpPos
= (WINDOWPOS
*)pos
;
1021 #if defined(__WIN95__)
1022 if (!(lpPos
->flags
& SWP_NOSIZE
))
1025 DWORD dwExStyle
= ::GetWindowLong(GetHwnd(), GWL_EXSTYLE
);
1026 DWORD dwStyle
= ::GetWindowLong(GetHwnd(), GWL_STYLE
);
1027 if (ResetWindowStyle((void *) & rectClient
) && (dwStyle
& WS_MAXIMIZE
))
1029 ::AdjustWindowRectEx(&rectClient
, dwStyle
, false, dwExStyle
);
1030 lpPos
->x
= rectClient
.left
;
1031 lpPos
->y
= rectClient
.top
;
1032 lpPos
->cx
= rectClient
.right
- rectClient
.left
;
1033 lpPos
->cy
= rectClient
.bottom
- rectClient
.top
;
1036 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1037 if (pFrameWnd
&& pFrameWnd
->GetToolBar() && pFrameWnd
->GetToolBar()->IsShown())
1039 pFrameWnd
->GetToolBar()->Refresh();
1048 bool wxMDIChildFrame::HandleGetMinMaxInfo(void *mmInfo
)
1050 MINMAXINFO
*info
= (MINMAXINFO
*)mmInfo
;
1052 // let the default window proc calculate the size of MDI children
1053 // frames because it is based on the size of the MDI client window,
1054 // not on the values specified in wxWindow m_max variables
1055 bool processed
= MSWDefWindowProc(WM_GETMINMAXINFO
, 0, (LPARAM
)mmInfo
) != 0;
1057 int minWidth
= GetMinWidth(),
1058 minHeight
= GetMinHeight();
1060 // but allow GetSizeHints() to set the min size
1061 if ( minWidth
!= -1 )
1063 info
->ptMinTrackSize
.x
= minWidth
;
1068 if ( minHeight
!= -1 )
1070 info
->ptMinTrackSize
.y
= minHeight
;
1078 // ---------------------------------------------------------------------------
1079 // MDI specific message translation/preprocessing
1080 // ---------------------------------------------------------------------------
1082 WXLRESULT
wxMDIChildFrame::MSWDefWindowProc(WXUINT message
, WXWPARAM wParam
, WXLPARAM lParam
)
1084 return DefMDIChildProc(GetHwnd(),
1085 (UINT
)message
, (WPARAM
)wParam
, (LPARAM
)lParam
);
1088 bool wxMDIChildFrame::MSWTranslateMessage(WXMSG
* msg
)
1090 return wxFrame::MSWTranslateMessage(msg
);
1093 // ---------------------------------------------------------------------------
1095 // ---------------------------------------------------------------------------
1097 void wxMDIChildFrame::MSWDestroyWindow()
1099 invalidHandle
= GetHwnd();
1101 wxMDIParentFrame
*parent
= (wxMDIParentFrame
*)GetParent();
1103 // Must make sure this handle is invalidated (set to NULL) since all sorts
1104 // of things could happen after the child client is destroyed, but before
1105 // the wxFrame is destroyed.
1107 HWND oldHandle
= (HWND
)GetHWND();
1108 SendMessage(GetWinHwnd(parent
->GetClientWindow()), WM_MDIDESTROY
,
1109 (WPARAM
)oldHandle
, 0);
1111 if (parent
->GetActiveChild() == (wxMDIChildFrame
*) NULL
)
1112 ResetWindowStyle((void*) NULL
);
1118 ::DestroyMenu((HMENU
) m_hMenu
);
1121 wxRemoveHandleAssociation(this);
1125 // Change the client window's extended style so we don't get a client edge
1126 // style when a child is maximised (a double border looks silly.)
1127 bool wxMDIChildFrame::ResetWindowStyle(void *vrect
)
1129 #if defined(__WIN95__)
1130 RECT
*rect
= (RECT
*)vrect
;
1131 wxMDIParentFrame
* pFrameWnd
= (wxMDIParentFrame
*)GetParent();
1132 wxMDIChildFrame
* pChild
= pFrameWnd
->GetActiveChild();
1133 if (!pChild
|| (pChild
== this))
1135 HWND hwndClient
= GetWinHwnd(pFrameWnd
->GetClientWindow());
1136 DWORD dwStyle
= ::GetWindowLong(hwndClient
, GWL_EXSTYLE
);
1138 // we want to test whether there is a maximized child, so just set
1139 // dwThisStyle to 0 if there is no child at all
1140 DWORD dwThisStyle
= pChild
1141 ? ::GetWindowLong(GetWinHwnd(pChild
), GWL_STYLE
) : 0;
1142 DWORD dwNewStyle
= dwStyle
;
1143 if ( dwThisStyle
& WS_MAXIMIZE
)
1144 dwNewStyle
&= ~(WS_EX_CLIENTEDGE
);
1146 dwNewStyle
|= WS_EX_CLIENTEDGE
;
1148 if (dwStyle
!= dwNewStyle
)
1150 // force update of everything
1151 ::RedrawWindow(hwndClient
, NULL
, NULL
,
1152 RDW_INVALIDATE
| RDW_ALLCHILDREN
);
1153 ::SetWindowLong(hwndClient
, GWL_EXSTYLE
, dwNewStyle
);
1154 ::SetWindowPos(hwndClient
, NULL
, 0, 0, 0, 0,
1155 SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
1156 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
|
1159 ::GetClientRect(hwndClient
, rect
);
1169 // ===========================================================================
1170 // wxMDIClientWindow: the window of predefined (by Windows) class which
1171 // contains the child frames
1172 // ===========================================================================
1174 bool wxMDIClientWindow::CreateClient(wxMDIParentFrame
*parent
, long style
)
1176 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE
);
1178 CLIENTCREATESTRUCT ccs
;
1179 m_windowStyle
= style
;
1182 ccs
.hWindowMenu
= GetMDIWindowMenu(parent
);
1183 ccs
.idFirstChild
= wxFIRST_MDI_CHILD
;
1185 DWORD msStyle
= MDIS_ALLCHILDSTYLES
| WS_VISIBLE
| WS_CHILD
|
1186 WS_CLIPCHILDREN
| WS_CLIPSIBLINGS
;
1188 if ( style
& wxHSCROLL
)
1189 msStyle
|= WS_HSCROLL
;
1190 if ( style
& wxVSCROLL
)
1191 msStyle
|= WS_VSCROLL
;
1193 #if defined(__WIN95__)
1194 DWORD exStyle
= WS_EX_CLIENTEDGE
;
1199 wxWindowCreationHook
hook(this);
1200 m_hWnd
= (WXHWND
)::CreateWindowEx
1210 (LPSTR
)(LPCLIENTCREATESTRUCT
)&ccs
);
1213 wxLogLastError(wxT("CreateWindowEx(MDI client)"));
1218 SubclassWin(m_hWnd
);
1223 // Explicitly call default scroll behaviour
1224 void wxMDIClientWindow::OnScroll(wxScrollEvent
& event
)
1226 // Note: for client windows, the scroll position is not set in
1227 // WM_HSCROLL, WM_VSCROLL, so we can't easily determine what
1228 // scroll position we're at.
1229 // This makes it hard to paint patterns or bitmaps in the background,
1230 // and have the client area scrollable as well.
1232 if ( event
.GetOrientation() == wxHORIZONTAL
)
1233 m_scrollX
= event
.GetPosition(); // Always returns zero!
1235 m_scrollY
= event
.GetPosition(); // Always returns zero!
1240 void wxMDIClientWindow::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
1242 // Try to fix a problem whereby if you show an MDI child frame, then reposition the
1243 // client area, you can end up with a non-refreshed portion in the client window
1244 // (see OGL studio sample). So check if the position is changed and if so,
1245 // redraw the MDI child frames.
1247 wxPoint oldPos
= GetPosition();
1249 wxWindow::DoSetSize(x
, y
, width
, height
, sizeFlags
);
1251 wxPoint newPos
= GetPosition();
1253 if ((newPos
.x
!= oldPos
.x
) || (newPos
.y
!= oldPos
.y
))
1257 wxWindowList::compatibility_iterator node
= GetParent()->GetChildren().GetFirst();
1260 wxWindow
*child
= node
->GetData();
1261 if (child
->IsKindOf(CLASSINFO(wxMDIChildFrame
)))
1263 ::RedrawWindow(GetHwndOf(child
),
1270 node
= node
->GetNext();
1276 void wxMDIChildFrame::OnIdle(wxIdleEvent
& event
)
1278 // MDI child frames get their WM_SIZE when they're constructed but at this
1279 // moment they don't have any children yet so all child windows will be
1280 // positioned incorrectly when they are added later - to fix this, we
1281 // generate an artificial size event here
1282 if ( m_needsResize
)
1284 m_needsResize
= false; // avoid any possibility of recursion
1292 // ---------------------------------------------------------------------------
1293 // non member functions
1294 // ---------------------------------------------------------------------------
1296 static void MDISetMenu(wxWindow
*win
, HMENU hmenuFrame
, HMENU hmenuWindow
)
1298 ::SendMessage(GetWinHwnd(win
), WM_MDISETMENU
,
1300 (WPARAM
)hmenuFrame
, (LPARAM
)hmenuWindow
1302 0, MAKELPARAM(hmenuFrame
, hmenuWindow
)
1306 // update menu bar of the parent window
1307 wxWindow
*parent
= win
->GetParent();
1308 wxCHECK_RET( parent
, wxT("MDI client without parent frame? weird...") );
1310 ::SendMessage(GetWinHwnd(win
), WM_MDIREFRESHMENU
, 0, 0L);
1312 ::DrawMenuBar(GetWinHwnd(parent
));
1315 static void InsertWindowMenu(wxWindow
*win
, WXHMENU menu
, HMENU subMenu
)
1317 // Try to insert Window menu in front of Help, otherwise append it.
1318 HMENU hmenu
= (HMENU
)menu
;
1322 int N
= GetMenuItemCount(hmenu
);
1323 bool success
= false;
1324 for ( int i
= 0; i
< N
; i
++ )
1327 int chars
= GetMenuString(hmenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
);
1330 wxLogLastError(wxT("GetMenuString"));
1335 if ( wxStripMenuCodes(wxString(buf
)).IsSameAs(_("Help")) )
1338 ::InsertMenu(hmenu
, i
, MF_BYPOSITION
| MF_POPUP
| MF_STRING
,
1339 (UINT
)subMenu
, _("&Window"));
1346 ::AppendMenu(hmenu
, MF_POPUP
, (UINT
)subMenu
, _("&Window"));
1350 MDISetMenu(win
, hmenu
, subMenu
);
1353 static void RemoveWindowMenu(wxWindow
*win
, WXHMENU menu
)
1355 HMENU hMenu
= (HMENU
)menu
;
1361 int N
= ::GetMenuItemCount(hMenu
);
1362 for ( int i
= 0; i
< N
; i
++ )
1364 if ( !::GetMenuString(hMenu
, i
, buf
, WXSIZEOF(buf
), MF_BYPOSITION
) )
1366 // Ignore successful read of menu string with length 0 which
1367 // occurs, for example, for a maximized MDI childs system menu
1368 if ( ::GetLastError() != 0 )
1370 wxLogLastError(wxT("GetMenuString"));
1376 if ( wxStrcmp(buf
, _("&Window")) == 0 )
1378 if ( !::RemoveMenu(hMenu
, i
, MF_BYPOSITION
) )
1380 wxLogLastError(wxT("RemoveMenu"));
1390 // we don't change the windows menu, but we update the main one
1391 MDISetMenu(win
, hMenu
, NULL
);
1395 static void UnpackMDIActivate(WXWPARAM wParam
, WXLPARAM lParam
,
1396 WXWORD
*activate
, WXHWND
*hwndAct
, WXHWND
*hwndDeact
)
1399 *hwndAct
= (WXHWND
)lParam
;
1400 *hwndDeact
= (WXHWND
)wParam
;
1403 #endif // wxUSE_MDI && !defined(__WXUNIVERSAL__)