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