1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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 )
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 ),
42 Link
<> 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
)
52 if ( nStyle
& WB_AUTOVSCROLL
)
60 setScrollVisibility( aVis
);
61 mnScrWidth
= T::GetSettings().GetStyleSettings().GetScrollBarSize();
65 void ScrollableWrapper
<T
>::setScrollVisibility( ScrollBarVisibility rVisState
)
67 maScrollVis
= rVisState
;
68 if ( maScrollVis
== Hori
|| maScrollVis
== Both
)
73 if ( maScrollVis
== Vert
|| maScrollVis
== Both
)
78 if ( mbHasHoriBar
|| mbHasVertBar
)
79 this->SetStyle( T::GetStyle() | WB_CLIPCHILDREN
| SCROLL_UPDATE
);
83 ScrollableWrapper
<T
>::~ScrollableWrapper()
89 void ScrollableWrapper
<T
>::dispose()
91 maHScrollBar
.disposeAndClear();
92 maVScrollBar
.disposeAndClear();
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 with the template
119 //IMPL_LINK( ScrollableWrapper, ScrollBarHdl, ScrollBar*, pSB )
122 sal_IntPtr ScrollableWrapper
<T
>::LinkStubScrollBarHdl( void* pThis
, void* pCaller
)
124 return static_cast<ScrollableWrapper
<T
>*>(pThis
)->ScrollBarHdl( static_cast<ScrollBar
*>(pCaller
) );
128 sal_IntPtr 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() );
139 void ScrollableWrapper
<T
>::SetScrollTop( long nTop
)
141 Point aOld
= mnScrollPos
;
142 lcl_Scroll( mnScrollPos
.X() , mnScrollPos
.Y() - nTop
);
143 maHScrollBar
->SetThumbPos( 0 );
148 void ScrollableWrapper
<T
>::SetScrollLeft( long nLeft
)
150 Point aOld
= mnScrollPos
;
151 lcl_Scroll( mnScrollPos
.X() - nLeft
, mnScrollPos
.Y() );
152 maVScrollBar
->SetThumbPos( 0 );
157 void ScrollableWrapper
<T
>::SetScrollWidth( long nWidth
)
159 maScrollArea
.Width() = nWidth
;
164 void ScrollableWrapper
<T
>::SetScrollHeight( long nHeight
)
166 maScrollArea
.Height() = nHeight
;
171 void ScrollableWrapper
<T
>::Resize()
177 void ScrollableWrapper
<T
>::ResetScrollBars()
179 Size aOutSz
= T::GetOutputSizePixel();
181 Point
aVPos( aOutSz
.Width() - mnScrWidth
, 0 );
182 Point
aHPos( 0, aOutSz
.Height() - mnScrWidth
);
184 maVScrollBar
->SetPosSizePixel( aVPos
, Size( mnScrWidth
, T::GetSizePixel().Height() - mnScrWidth
) );
185 maHScrollBar
->SetPosSizePixel( aHPos
, Size( T::GetSizePixel().Width() - mnScrWidth
, mnScrWidth
) );
187 maHScrollBar
->SetRangeMax( maScrollArea
.Width() + mnScrWidth
);
188 maHScrollBar
->SetVisibleSize( T::GetSizePixel().Width() );
190 maVScrollBar
->SetRangeMax( maScrollArea
.Height() + mnScrWidth
);
191 maVScrollBar
->SetVisibleSize( T::GetSizePixel().Height() );
194 template class ScrollableWrapper
< Dialog
>;
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */