Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / toolkit / source / awt / scrollabledialog.cxx
blob968ec9f8a716a8f751151c697d94f3af416eebc0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <toolkit/awt/scrollabledialog.hxx>
21 #include <vcl/group.hxx>
23 namespace toolkit
26 // Using WB_AUTOHSCROLL, WB_AUTOVSCROLL here sucks big time, there is a
27 // problem in the toolkit class where there are some clashing IDs
28 // ( ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL has the same value
29 // as ::com::sun::star::awt::WindowAttribute::NODECORATION and they are used
30 // in the same bitmap :-( WB_VSCROLL & WB_HSCROLL apparently are only for
31 // child classes ( whole thing is a mess if you ask me )
32 template< class T>
33 ScrollableWrapper<T>::ScrollableWrapper( Window* pParent, WinBits nStyle ) : T( pParent, nStyle & ~( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) ), maHScrollBar( this, WB_HSCROLL | WB_DRAG), maVScrollBar( this, WB_VSCROLL | WB_DRAG ), mbHasHoriBar( false ), mbHasVertBar( false ), maScrollVis( None )
35 Link aLink( LINK( this, ScrollableWrapper, ScrollBarHdl ) );
36 maVScrollBar.SetScrollHdl( aLink );
37 maHScrollBar.SetScrollHdl( aLink );
39 ScrollBarVisibility aVis = None;
41 if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
43 if ( nStyle & WB_AUTOHSCROLL )
44 aVis = Hori;
45 if ( nStyle & WB_AUTOVSCROLL )
47 if ( aVis == Hori )
48 aVis = Both;
49 else
50 aVis = Vert;
53 setScrollVisibility( aVis );
54 mnScrWidth = T::GetSettings().GetStyleSettings().GetScrollBarSize();
57 template< class T>
58 void ScrollableWrapper<T>::setScrollVisibility( ScrollBarVisibility rVisState )
60 maScrollVis = rVisState;
61 if ( maScrollVis == Hori || maScrollVis == Both )
63 mbHasHoriBar = true;
64 maHScrollBar.Show();
66 if ( maScrollVis == Vert || maScrollVis == Both )
68 mbHasVertBar = true;
69 maVScrollBar.Show();
71 if ( mbHasHoriBar || mbHasVertBar )
72 this->SetStyle( T::GetStyle() | WB_CLIPCHILDREN | SCROLL_UPDATE );
75 template< class T>
76 ScrollableWrapper<T>::~ScrollableWrapper()
80 template< class T>
81 void ScrollableWrapper<T>::lcl_Scroll( long nX, long nY )
83 long nXScroll = mnScrollPos.X() - nX;
84 long nYScroll = mnScrollPos.Y() - nY;
85 mnScrollPos = Point( nX, nY );
87 Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
88 T::Scroll(nXScroll, nYScroll, aScrollableArea );
89 // Manually scroll all children ( except the scrollbars )
90 for ( int index = 0; index < T::GetChildCount(); ++index )
92 Window* pChild = T::GetChild( index );
93 if ( pChild && pChild != &maVScrollBar && pChild != &maHScrollBar )
95 Point aPos = pChild->GetPosPixel();
96 aPos += Point( nXScroll, nYScroll );
97 pChild->SetPosPixel( aPos );
102 //Can't use IMPL_LINK with the template
103 //IMPL_LINK( ScrollableWrapper, ScrollBarHdl, ScrollBar*, pSB )
105 template< class T>
106 long ScrollableWrapper<T>::LinkStubScrollBarHdl( void* pThis, void* pCaller)
108 return ((ScrollableWrapper<T>*)pThis )->ScrollBarHdl( (ScrollBar*)pCaller );
111 template< class T>
112 long ScrollableWrapper<T>::ScrollBarHdl( ScrollBar* pSB )
114 sal_uInt16 nPos = (sal_uInt16) pSB->GetThumbPos();
115 if( pSB == &maVScrollBar )
116 lcl_Scroll(mnScrollPos.X(), nPos );
117 else if( pSB == &maHScrollBar )
118 lcl_Scroll(nPos, mnScrollPos.Y() );
119 return 1;
122 template< class T>
123 void ScrollableWrapper<T>::SetScrollTop( long nTop )
125 Point aOld = mnScrollPos;
126 lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
127 maHScrollBar.SetThumbPos( 0 );
128 // new pos is 0,0
129 mnScrollPos = aOld;
131 template< class T>
132 void ScrollableWrapper<T>::SetScrollLeft( long nLeft )
134 Point aOld = mnScrollPos;
135 lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
136 maVScrollBar.SetThumbPos( 0 );
137 // new pos is 0,0
138 mnScrollPos = aOld;
140 template< class T>
141 void ScrollableWrapper<T>::SetScrollWidth( long nWidth )
143 maScrollArea.Width() = nWidth;
144 ResetScrollBars();
147 template< class T>
148 void ScrollableWrapper<T>::SetScrollHeight( long nHeight )
150 maScrollArea.Height() = nHeight;
151 ResetScrollBars();
154 template< class T>
155 void ScrollableWrapper<T>::Resize()
157 ResetScrollBars();
160 template< class T>
161 void ScrollableWrapper<T>::ResetScrollBars()
163 Size aOutSz = T::GetOutputSizePixel();
165 Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
166 Point aHPos( 0, aOutSz.Height() - mnScrWidth );
168 maVScrollBar.SetPosSizePixel( aVPos, Size( mnScrWidth, T::GetSizePixel().Height() - mnScrWidth ) );
169 maHScrollBar.SetPosSizePixel( aHPos, Size( T::GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );
171 maHScrollBar.SetRangeMax( maScrollArea.Width() + mnScrWidth );
172 maHScrollBar.SetVisibleSize( T::GetSizePixel().Width() );
174 maVScrollBar.SetRangeMax( maScrollArea.Height() + mnScrWidth );
175 maVScrollBar.SetVisibleSize( T::GetSizePixel().Height() );
178 template class ScrollableWrapper< Dialog >;
179 #if SCROLLABLEFRAME
180 template class ScrollableWrapper< GroupBox >;
181 #endif
183 } // toolkit
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */