1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b0724fc6SAndrew Rist  * distributed with this work for additional information
6*b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b0724fc6SAndrew Rist  *
11*b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b0724fc6SAndrew Rist  *
13*b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist  * under the License.
19*b0724fc6SAndrew Rist  *
20*b0724fc6SAndrew Rist  *************************************************************/
21*b0724fc6SAndrew Rist 
22*b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "vclxscroller.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <assert.h>
27cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
28cdf0e10cSrcweir #include <com/sun/star/awt/ScrollBarOrientation.hpp>
29cdf0e10cSrcweir #include <sal/macros.h>
30cdf0e10cSrcweir #include <toolkit/helper/property.hxx>
31cdf0e10cSrcweir #include <tools/debug.hxx>
32cdf0e10cSrcweir #include <vcl/scrbar.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "forward.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace layoutimpl
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir using namespace ::com::sun::star::awt;
41cdf0e10cSrcweir using namespace ::com::sun::star::lang;
42cdf0e10cSrcweir using namespace ::com::sun::star::beans;
43cdf0e10cSrcweir using namespace ::com::sun::star;
44cdf0e10cSrcweir 
DBG_NAME(VCLXScroller)45cdf0e10cSrcweir DBG_NAME( VCLXScroller )
46cdf0e10cSrcweir 
47cdf0e10cSrcweir VCLXScroller::VCLXScroller()
48cdf0e10cSrcweir   : VCLXWindow()
49cdf0e10cSrcweir   , Bin()
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     DBG_CTOR( VCLXScroller, NULL );
52cdf0e10cSrcweir     mpHorScrollBar = mpVerScrollBar = 0;
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
~VCLXScroller()55cdf0e10cSrcweir VCLXScroller::~VCLXScroller()
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     DBG_DTOR( VCLXScroller, NULL );
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir IMPLEMENT_2_FORWARD_XINTERFACE1( VCLXScroller, VCLXWindow, Container );
61cdf0e10cSrcweir 
62cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER1( VCLXScroller, VCLXWindow );
63cdf0e10cSrcweir 
dispose()64cdf0e10cSrcweir void SAL_CALL VCLXScroller::dispose() throw(RuntimeException)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir         ::vos::OGuard aGuard( GetMutex() );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         EventObject aDisposeEvent;
70cdf0e10cSrcweir         aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this);
71cdf0e10cSrcweir //            maTabListeners.disposeAndClear( aDisposeEvent );
72cdf0e10cSrcweir     }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     VCLXWindow::dispose();
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
ensureScrollBars()77cdf0e10cSrcweir void VCLXScroller::ensureScrollBars()
78cdf0e10cSrcweir {
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     if ( !mpVerScrollBar )
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         mpVerScrollBar = new ScrollBar( GetWindow() , WB_VERT );
83cdf0e10cSrcweir         mpVerScrollBar->SetLineSize( 4 );
84cdf0e10cSrcweir         mpVerScrollBar->SetPageSize( 15 );
85cdf0e10cSrcweir         mpVerScrollBar->Show();
86cdf0e10cSrcweir         mpVerScrollBar->SetScrollHdl( LINK( this, VCLXScroller, ScrollHdl ) );
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir     if ( !mpHorScrollBar )
89cdf0e10cSrcweir     {
90cdf0e10cSrcweir         mpHorScrollBar = new ScrollBar( GetWindow() , WB_HORZ );
91cdf0e10cSrcweir         mpHorScrollBar->SetLineSize( 4 );
92cdf0e10cSrcweir         mpHorScrollBar->SetPageSize( 15 );
93cdf0e10cSrcweir         mpHorScrollBar->Show();
94cdf0e10cSrcweir         mpHorScrollBar->SetScrollHdl( LINK( this, VCLXScroller, ScrollHdl ) );
95cdf0e10cSrcweir     } //        mpContent = new FixedImage( this, ImplGetWinBits( WindowAttributes, 0 ) );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
allocateArea(const::com::sun::star::awt::Rectangle & rArea)99cdf0e10cSrcweir void SAL_CALL VCLXScroller::allocateArea(
100cdf0e10cSrcweir     const ::com::sun::star::awt::Rectangle &rArea )
101cdf0e10cSrcweir     throw (::com::sun::star::uno::RuntimeException)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     ensureScrollBars();        // shouldn't be needed
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     maAllocation = rArea;
106cdf0e10cSrcweir     setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height, PosSize::POSSIZE );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     mpHorScrollBar->SetRangeMin( 0 );
109cdf0e10cSrcweir     mpHorScrollBar->SetRangeMax( SAL_MAX( maChildRequisition.Width - rArea.Width, 0 ) );
110cdf0e10cSrcweir     mpVerScrollBar->SetRangeMin( 0 );
111cdf0e10cSrcweir     mpVerScrollBar->SetRangeMax( SAL_MAX( maChildRequisition.Height - rArea.Height, 0 ) );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     int thumbX = mpHorScrollBar->GetThumbPos();
114cdf0e10cSrcweir     int thumbY = mpVerScrollBar->GetThumbPos();
115cdf0e10cSrcweir     int thumbWidth = mpVerScrollBar->GetSizePixel().getWidth();
116cdf0e10cSrcweir     int thumbHeight = mpHorScrollBar->GetSizePixel().getHeight();
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     mpHorScrollBar->SetPosSizePixel( rArea.X, rArea.Y + rArea.Height - thumbHeight - 2,
119cdf0e10cSrcweir                                      rArea.Width - thumbWidth, thumbHeight );
120cdf0e10cSrcweir     mpVerScrollBar->SetPosSizePixel( rArea.X + rArea.Width - thumbWidth - 2, rArea.Y-2,
121cdf0e10cSrcweir                                      thumbWidth, rArea.Height - thumbHeight );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     awt::Rectangle childRect( rArea.X - thumbX, rArea.Y - thumbY,
124cdf0e10cSrcweir                               SAL_MAX( maChildRequisition.Width, rArea.Width ) - thumbWidth - 4,
125cdf0e10cSrcweir                               SAL_MAX( maChildRequisition.Height, rArea.Height ) - thumbHeight - 4 );
126cdf0e10cSrcweir     if ( mxChild.is() )
127cdf0e10cSrcweir         allocateChildAt( mxChild, childRect );
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir #define MAX_CHILD_REQ 40
getMinimumSize()131cdf0e10cSrcweir ::com::sun::star::awt::Size SAL_CALL VCLXScroller::getMinimumSize()
132cdf0e10cSrcweir     throw(::com::sun::star::uno::RuntimeException)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     ensureScrollBars();
135cdf0e10cSrcweir     assert( mpHorScrollBar && mpVerScrollBar );
136cdf0e10cSrcweir     awt::Size childSize = Bin::getMinimumSize();
137cdf0e10cSrcweir     int thumbWidth = mpVerScrollBar->GetSizePixel().getWidth();
138cdf0e10cSrcweir     int thumbHeight = mpHorScrollBar->GetSizePixel().getHeight();
139cdf0e10cSrcweir     maRequisition = awt::Size(
140cdf0e10cSrcweir         SAL_MIN( MAX_CHILD_REQ, childSize.Width ) + thumbWidth,
141cdf0e10cSrcweir         SAL_MIN( MAX_CHILD_REQ, childSize.Height ) + thumbHeight );
142cdf0e10cSrcweir     return maRequisition;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
ProcessWindowEvent(const VclWindowEvent & _rVclWindowEvent)145cdf0e10cSrcweir void VCLXScroller::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir /*
148cdf0e10cSrcweir     ::vos::OClearableGuard aGuard( GetMutex() );
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     switch ( _rVclWindowEvent.GetId() )
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         default:
153cdf0e10cSrcweir             aGuard.clear();
154cdf0e10cSrcweir */
155cdf0e10cSrcweir             VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
156cdf0e10cSrcweir /*
157cdf0e10cSrcweir         break;
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir */
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
setProperty(const::rtl::OUString & PropertyName,const Any & Value)162cdf0e10cSrcweir void SAL_CALL VCLXScroller::setProperty( const ::rtl::OUString& PropertyName, const Any &Value ) throw(RuntimeException)
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     ::vos::OGuard aGuard( GetMutex() );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     if ( GetWindow() )
167cdf0e10cSrcweir     {
168cdf0e10cSrcweir /*
169cdf0e10cSrcweir         sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
170cdf0e10cSrcweir         switch ( nPropertyId )
171cdf0e10cSrcweir         {
172cdf0e10cSrcweir             default:
173cdf0e10cSrcweir */
174cdf0e10cSrcweir                 VCLXWindow::setProperty( PropertyName, Value );
175cdf0e10cSrcweir /*
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir */
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
getProperty(const::rtl::OUString & PropertyName)181cdf0e10cSrcweir Any SAL_CALL VCLXScroller::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     ::vos::OGuard aGuard( GetMutex() );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     Any aReturn;
186cdf0e10cSrcweir     if ( GetWindow() )
187cdf0e10cSrcweir     {
188cdf0e10cSrcweir /*
189cdf0e10cSrcweir         sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
190cdf0e10cSrcweir         switch ( nPropertyId )
191cdf0e10cSrcweir         {
192cdf0e10cSrcweir             default:
193cdf0e10cSrcweir */
194cdf0e10cSrcweir                 aReturn = VCLXWindow::getProperty( PropertyName );
195cdf0e10cSrcweir 
196cdf0e10cSrcweir //        }
197cdf0e10cSrcweir     }
198cdf0e10cSrcweir     return aReturn;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
IMPL_LINK(VCLXScroller,ScrollHdl,ScrollBar *,pScrollBar)201cdf0e10cSrcweir IMPL_LINK( VCLXScroller, ScrollHdl, ScrollBar *, pScrollBar )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     (void) pScrollBar;
204cdf0e10cSrcweir     forceRecalc();
205cdf0e10cSrcweir     return 0;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir } // namespace layoutimpl
209