lwp build fixes
[LibreOffice.git] / toolkit / source / awt / scrollabledialog.cxx
blob2d98a0c2574fadeb0db36bb13f546f2d509e3241
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 // ( ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL has the same value
30 // as ::com::sun::star::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 ) : 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 )
36 Link aLink( LINK( this, ScrollableWrapper, ScrollBarHdl ) );
37 maVScrollBar.SetScrollHdl( aLink );
38 maHScrollBar.SetScrollHdl( aLink );
40 ScrollBarVisibility aVis = None;
42 if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
44 if ( nStyle & WB_AUTOHSCROLL )
45 aVis = Hori;
46 if ( nStyle & WB_AUTOVSCROLL )
48 if ( aVis == Hori )
49 aVis = Both;
50 else
51 aVis = Vert;
54 setScrollVisibility( aVis );
55 mnScrWidth = T::GetSettings().GetStyleSettings().GetScrollBarSize();
58 template< class T>
59 void ScrollableWrapper<T>::setScrollVisibility( ScrollBarVisibility rVisState )
61 maScrollVis = rVisState;
62 if ( maScrollVis == Hori || maScrollVis == Both )
64 mbHasHoriBar = true;
65 maHScrollBar.Show();
67 if ( maScrollVis == Vert || maScrollVis == Both )
69 mbHasVertBar = true;
70 maVScrollBar.Show();
72 if ( mbHasHoriBar || mbHasVertBar )
73 this->SetStyle( T::GetStyle() | WB_CLIPCHILDREN | SCROLL_UPDATE );
76 template< class T>
77 ScrollableWrapper<T>::~ScrollableWrapper()
81 template< class T>
82 void ScrollableWrapper<T>::lcl_Scroll( long nX, long nY )
84 long nXScroll = mnScrollPos.X() - nX;
85 long nYScroll = mnScrollPos.Y() - nY;
86 mnScrollPos = Point( nX, nY );
88 Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
89 T::Scroll(nXScroll, nYScroll, aScrollableArea );
90 // Manually scroll all children ( except the scrollbars )
91 for ( int index = 0; index < T::GetChildCount(); ++index )
93 vcl::Window* pChild = T::GetChild( index );
94 if ( pChild && pChild != &maVScrollBar && pChild != &maHScrollBar )
96 Point aPos = pChild->GetPosPixel();
97 aPos += Point( nXScroll, nYScroll );
98 pChild->SetPosPixel( aPos );
103 //Can't use IMPL_LINK with the template
104 //IMPL_LINK( ScrollableWrapper, ScrollBarHdl, ScrollBar*, pSB )
106 template< class T>
107 long ScrollableWrapper<T>::LinkStubScrollBarHdl( void* pThis, void* pCaller)
109 return ((ScrollableWrapper<T>*)pThis )->ScrollBarHdl( (ScrollBar*)pCaller );
112 template< class T>
113 long ScrollableWrapper<T>::ScrollBarHdl( ScrollBar* pSB )
115 sal_uInt16 nPos = (sal_uInt16) pSB->GetThumbPos();
116 if( pSB == &maVScrollBar )
117 lcl_Scroll(mnScrollPos.X(), nPos );
118 else if( pSB == &maHScrollBar )
119 lcl_Scroll(nPos, mnScrollPos.Y() );
120 return 1;
123 template< class T>
124 void ScrollableWrapper<T>::SetScrollTop( long nTop )
126 Point aOld = mnScrollPos;
127 lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
128 maHScrollBar.SetThumbPos( 0 );
129 // new pos is 0,0
130 mnScrollPos = aOld;
132 template< class T>
133 void ScrollableWrapper<T>::SetScrollLeft( long nLeft )
135 Point aOld = mnScrollPos;
136 lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
137 maVScrollBar.SetThumbPos( 0 );
138 // new pos is 0,0
139 mnScrollPos = aOld;
141 template< class T>
142 void ScrollableWrapper<T>::SetScrollWidth( long nWidth )
144 maScrollArea.Width() = nWidth;
145 ResetScrollBars();
148 template< class T>
149 void ScrollableWrapper<T>::SetScrollHeight( long nHeight )
151 maScrollArea.Height() = nHeight;
152 ResetScrollBars();
155 template< class T>
156 void ScrollableWrapper<T>::Resize()
158 ResetScrollBars();
161 template< class T>
162 void ScrollableWrapper<T>::ResetScrollBars()
164 Size aOutSz = T::GetOutputSizePixel();
166 Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
167 Point aHPos( 0, aOutSz.Height() - mnScrWidth );
169 maVScrollBar.SetPosSizePixel( aVPos, Size( mnScrWidth, T::GetSizePixel().Height() - mnScrWidth ) );
170 maHScrollBar.SetPosSizePixel( aHPos, Size( T::GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );
172 maHScrollBar.SetRangeMax( maScrollArea.Width() + mnScrWidth );
173 maHScrollBar.SetVisibleSize( T::GetSizePixel().Width() );
175 maVScrollBar.SetRangeMax( maScrollArea.Height() + mnScrWidth );
176 maVScrollBar.SetVisibleSize( T::GetSizePixel().Height() );
179 template class ScrollableWrapper< Dialog >;
181 } // toolkit
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */