1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxscroller.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "vclxscroller.hxx"
35 #include <com/sun/star/awt/PosSize.hpp>
36 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
37 #include <sal/macros.h>
38 #include <toolkit/helper/property.hxx>
39 #include <tools/debug.hxx>
40 #include <vcl/scrbar.hxx>
42 #include "forward.hxx"
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::awt
;
49 using namespace ::com::sun::star::lang
;
50 using namespace ::com::sun::star::beans
;
51 using namespace ::com::sun::star
;
53 DBG_NAME( VCLXScroller
)
55 VCLXScroller::VCLXScroller()
59 DBG_CTOR( VCLXScroller
, NULL
);
60 mpHorScrollBar
= mpVerScrollBar
= 0;
63 VCLXScroller::~VCLXScroller()
65 DBG_DTOR( VCLXScroller
, NULL
);
68 IMPLEMENT_2_FORWARD_XINTERFACE1( VCLXScroller
, VCLXWindow
, Container
);
70 IMPLEMENT_FORWARD_XTYPEPROVIDER1( VCLXScroller
, VCLXWindow
);
72 void SAL_CALL
VCLXScroller::dispose() throw(RuntimeException
)
75 ::vos::OGuard
aGuard( GetMutex() );
77 EventObject aDisposeEvent
;
78 aDisposeEvent
.Source
= W3K_EXPLICIT_CAST (*this);
79 // maTabListeners.disposeAndClear( aDisposeEvent );
82 VCLXWindow::dispose();
85 void VCLXScroller::ensureScrollBars()
88 if ( !mpVerScrollBar
)
90 mpVerScrollBar
= new ScrollBar( GetWindow() , WB_VERT
);
91 mpVerScrollBar
->SetLineSize( 4 );
92 mpVerScrollBar
->SetPageSize( 15 );
93 mpVerScrollBar
->Show();
94 mpVerScrollBar
->SetScrollHdl( LINK( this, VCLXScroller
, ScrollHdl
) );
96 if ( !mpHorScrollBar
)
98 mpHorScrollBar
= new ScrollBar( GetWindow() , WB_HORZ
);
99 mpHorScrollBar
->SetLineSize( 4 );
100 mpHorScrollBar
->SetPageSize( 15 );
101 mpHorScrollBar
->Show();
102 mpHorScrollBar
->SetScrollHdl( LINK( this, VCLXScroller
, ScrollHdl
) );
103 } // mpContent = new FixedImage( this, ImplGetWinBits( WindowAttributes, 0 ) );
107 void SAL_CALL
VCLXScroller::allocateArea(
108 const ::com::sun::star::awt::Rectangle
&rArea
)
109 throw (::com::sun::star::uno::RuntimeException
)
111 ensureScrollBars(); // shouldn't be needed
113 maAllocation
= rArea
;
114 setPosSize( rArea
.X
, rArea
.Y
, rArea
.Width
, rArea
.Height
, PosSize::POSSIZE
);
116 mpHorScrollBar
->SetRangeMin( 0 );
117 mpHorScrollBar
->SetRangeMax( SAL_MAX( maChildRequisition
.Width
- rArea
.Width
, 0 ) );
118 mpVerScrollBar
->SetRangeMin( 0 );
119 mpVerScrollBar
->SetRangeMax( SAL_MAX( maChildRequisition
.Height
- rArea
.Height
, 0 ) );
121 int thumbX
= mpHorScrollBar
->GetThumbPos();
122 int thumbY
= mpVerScrollBar
->GetThumbPos();
123 int thumbWidth
= mpVerScrollBar
->GetSizePixel().getWidth();
124 int thumbHeight
= mpHorScrollBar
->GetSizePixel().getHeight();
126 mpHorScrollBar
->SetPosSizePixel( rArea
.X
, rArea
.Y
+ rArea
.Height
- thumbHeight
- 2,
127 rArea
.Width
- thumbWidth
, thumbHeight
);
128 mpVerScrollBar
->SetPosSizePixel( rArea
.X
+ rArea
.Width
- thumbWidth
- 2, rArea
.Y
-2,
129 thumbWidth
, rArea
.Height
- thumbHeight
);
131 awt::Rectangle
childRect( rArea
.X
- thumbX
, rArea
.Y
- thumbY
,
132 SAL_MAX( maChildRequisition
.Width
, rArea
.Width
) - thumbWidth
- 4,
133 SAL_MAX( maChildRequisition
.Height
, rArea
.Height
) - thumbHeight
- 4 );
135 allocateChildAt( mxChild
, childRect
);
138 #define MAX_CHILD_REQ 40
139 ::com::sun::star::awt::Size SAL_CALL
VCLXScroller::getMinimumSize()
140 throw(::com::sun::star::uno::RuntimeException
)
143 assert( mpHorScrollBar
&& mpVerScrollBar
);
144 awt::Size childSize
= Bin::getMinimumSize();
145 int thumbWidth
= mpVerScrollBar
->GetSizePixel().getWidth();
146 int thumbHeight
= mpHorScrollBar
->GetSizePixel().getHeight();
147 maRequisition
= awt::Size(
148 SAL_MIN( MAX_CHILD_REQ
, childSize
.Width
) + thumbWidth
,
149 SAL_MIN( MAX_CHILD_REQ
, childSize
.Height
) + thumbHeight
);
150 return maRequisition
;
153 void VCLXScroller::ProcessWindowEvent( const VclWindowEvent
& _rVclWindowEvent
)
156 ::vos::OClearableGuard aGuard( GetMutex() );
158 switch ( _rVclWindowEvent.GetId() )
163 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent
);
170 void SAL_CALL
VCLXScroller::setProperty( const ::rtl::OUString
& PropertyName
, const Any
&Value
) throw(RuntimeException
)
172 ::vos::OGuard
aGuard( GetMutex() );
177 sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
178 switch ( nPropertyId )
182 VCLXWindow::setProperty( PropertyName
, Value
);
189 Any SAL_CALL
VCLXScroller::getProperty( const ::rtl::OUString
& PropertyName
) throw(RuntimeException
)
191 ::vos::OGuard
aGuard( GetMutex() );
197 sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
198 switch ( nPropertyId )
202 aReturn
= VCLXWindow::getProperty( PropertyName
);
209 IMPL_LINK( VCLXScroller
, ScrollHdl
, ScrollBar
*, pScrollBar
)
216 } // namespace layoutimpl