Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / toolkit / source / awt / scrollabledialog.cxx
blobcc2c77135c75c0e6d4e8e2b618a0e3baa96ccdbc
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>
22 #include <vcl/settings.hxx>
24 namespace toolkit
27 // Using WB_AUTOHSCROLL, WB_AUTOVSCROLL here sucks big time, there is a
28 // problem in the toolkit class where there are some clashing IDs
29 // ( css::awt::VclWindowPeerAttribute::VSCROLL has the same value
30 // as css::awt::WindowAttribute::NODECORATION and they are used
31 // in the same bitmap :-( WB_VSCROLL & WB_HSCROLL apparently are only for
32 // child classes ( whole thing is a mess if you ask me )
33 template< class T>
34 ScrollableWrapper<T>::ScrollableWrapper( vcl::Window* pParent, WinBits nStyle, Dialog::InitFlag eFlag )
35 : T( pParent, nStyle & ~( WB_AUTOHSCROLL | WB_AUTOVSCROLL ), eFlag ),
36 maHScrollBar( VclPtr<ScrollBar>::Create(this, WB_HSCROLL | WB_DRAG) ),
37 maVScrollBar( VclPtr<ScrollBar>::Create(this, WB_VSCROLL | WB_DRAG) ),
38 mbHasHoriBar( false ),
39 mbHasVertBar( false ),
40 maScrollVis( None )
42 Link<ScrollBar*,void> aLink( LINK( this, ScrollableWrapper, ScrollBarHdl ) );
43 maVScrollBar->SetScrollHdl( aLink );
44 maHScrollBar->SetScrollHdl( aLink );
46 ScrollBarVisibility aVis = None;
48 if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
50 if ( nStyle & WB_AUTOHSCROLL )
51 aVis = Hori;
52 if ( nStyle & WB_AUTOVSCROLL )
54 if ( aVis == Hori )
55 aVis = Both;
56 else
57 aVis = Vert;
60 setScrollVisibility( aVis );
61 mnScrWidth = T::GetSettings().GetStyleSettings().GetScrollBarSize();
64 template< class T>
65 void ScrollableWrapper<T>::setScrollVisibility( ScrollBarVisibility rVisState )
67 maScrollVis = rVisState;
68 if ( maScrollVis == Hori || maScrollVis == Both )
70 mbHasHoriBar = true;
71 maHScrollBar->Show();
73 if ( maScrollVis == Vert || maScrollVis == Both )
75 mbHasVertBar = true;
76 maVScrollBar->Show();
78 if ( mbHasHoriBar || mbHasVertBar )
79 this->SetStyle( T::GetStyle() | WB_CLIPCHILDREN | WB_AUTOSIZE );
82 template< class T>
83 ScrollableWrapper<T>::~ScrollableWrapper()
85 T::disposeOnce();
88 template< class T>
89 void ScrollableWrapper<T>::dispose()
91 maHScrollBar.disposeAndClear();
92 maVScrollBar.disposeAndClear();
93 T::dispose();
96 template< class T>
97 void ScrollableWrapper<T>::lcl_Scroll( long nX, long nY )
99 long nXScroll = mnScrollPos.X() - nX;
100 long nYScroll = mnScrollPos.Y() - nY;
101 mnScrollPos = Point( nX, nY );
103 Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
104 T::Scroll(nXScroll, nYScroll, aScrollableArea );
105 // Manually scroll all children ( except the scrollbars )
106 for ( int index = 0; index < T::GetChildCount(); ++index )
108 vcl::Window* pChild = T::GetChild( index );
109 if ( pChild && pChild != maVScrollBar.get() && pChild != maHScrollBar.get() )
111 Point aPos = pChild->GetPosPixel();
112 aPos += Point( nXScroll, nYScroll );
113 pChild->SetPosPixel( aPos );
118 //Can't use IMPL_LINK_TYPED with the template
119 //IMPL_LINK_TYPED( ScrollableWrapper, ScrollBarHdl, ScrollBar*, pSB, void )
121 template< class T>
122 void ScrollableWrapper<T>::LinkStubScrollBarHdl( void* pThis, ScrollBar* pCaller)
124 static_cast<ScrollableWrapper<T>*>(pThis)->ScrollBarHdl( static_cast<ScrollBar*>(pCaller) );
127 template< class T>
128 void ScrollableWrapper<T>::ScrollBarHdl( ScrollBar* pSB )
130 sal_uInt16 nPos = (sal_uInt16) pSB->GetThumbPos();
131 if( pSB == maVScrollBar.get() )
132 lcl_Scroll(mnScrollPos.X(), nPos );
133 else if( pSB == maHScrollBar.get() )
134 lcl_Scroll(nPos, mnScrollPos.Y() );
137 template< class T>
138 void ScrollableWrapper<T>::SetScrollTop( long nTop )
140 Point aOld = mnScrollPos;
141 lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
142 maHScrollBar->SetThumbPos( 0 );
143 // new pos is 0,0
144 mnScrollPos = aOld;
146 template< class T>
147 void ScrollableWrapper<T>::SetScrollLeft( long nLeft )
149 Point aOld = mnScrollPos;
150 lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
151 maVScrollBar->SetThumbPos( 0 );
152 // new pos is 0,0
153 mnScrollPos = aOld;
155 template< class T>
156 void ScrollableWrapper<T>::SetScrollWidth( long nWidth )
158 maScrollArea.Width() = nWidth;
159 ResetScrollBars();
162 template< class T>
163 void ScrollableWrapper<T>::SetScrollHeight( long nHeight )
165 maScrollArea.Height() = nHeight;
166 ResetScrollBars();
169 template< class T>
170 void ScrollableWrapper<T>::Resize()
172 ResetScrollBars();
175 template< class T>
176 void ScrollableWrapper<T>::ResetScrollBars()
178 Size aOutSz = T::GetOutputSizePixel();
180 Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
181 Point aHPos( 0, aOutSz.Height() - mnScrWidth );
183 maVScrollBar->SetPosSizePixel( aVPos, Size( mnScrWidth, T::GetSizePixel().Height() - mnScrWidth ) );
184 maHScrollBar->SetPosSizePixel( aHPos, Size( T::GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );
186 maHScrollBar->SetRangeMax( maScrollArea.Width() + mnScrWidth );
187 maHScrollBar->SetVisibleSize( T::GetSizePixel().Width() );
189 maVScrollBar->SetRangeMax( maScrollArea.Height() + mnScrWidth );
190 maVScrollBar->SetVisibleSize( T::GetSizePixel().Height() );
193 template class ScrollableWrapper< Dialog >;
195 } // toolkit
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */