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
DBG_NAME(VCLXScroller)45 DBG_NAME( VCLXScroller )
46
47 VCLXScroller::VCLXScroller()
48 : VCLXWindow()
49 , Bin()
50 {
51 DBG_CTOR( VCLXScroller, NULL );
52 mpHorScrollBar = mpVerScrollBar = 0;
53 }
54
~VCLXScroller()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
dispose()64 void SAL_CALL VCLXScroller::dispose() throw(RuntimeException)
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
ensureScrollBars()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
allocateArea(const::com::sun::star::awt::Rectangle & rArea)99 void SAL_CALL VCLXScroller::allocateArea(
100 const ::com::sun::star::awt::Rectangle &rArea )
101 throw (::com::sun::star::uno::RuntimeException)
102 {
103 ensureScrollBars(); // shouldn't be needed
104
105 maAllocation = rArea;
106 setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height, PosSize::POSSIZE );
107
108 mpHorScrollBar->SetRangeMin( 0 );
109 mpHorScrollBar->SetRangeMax( SAL_MAX( maChildRequisition.Width - rArea.Width, 0 ) );
110 mpVerScrollBar->SetRangeMin( 0 );
111 mpVerScrollBar->SetRangeMax( SAL_MAX( maChildRequisition.Height - rArea.Height, 0 ) );
112
113 int thumbX = mpHorScrollBar->GetThumbPos();
114 int thumbY = mpVerScrollBar->GetThumbPos();
115 int thumbWidth = mpVerScrollBar->GetSizePixel().getWidth();
116 int thumbHeight = mpHorScrollBar->GetSizePixel().getHeight();
117
118 mpHorScrollBar->SetPosSizePixel( rArea.X, rArea.Y + rArea.Height - thumbHeight - 2,
119 rArea.Width - thumbWidth, thumbHeight );
120 mpVerScrollBar->SetPosSizePixel( rArea.X + rArea.Width - thumbWidth - 2, rArea.Y-2,
121 thumbWidth, rArea.Height - thumbHeight );
122
123 awt::Rectangle childRect( rArea.X - thumbX, rArea.Y - thumbY,
124 SAL_MAX( maChildRequisition.Width, rArea.Width ) - thumbWidth - 4,
125 SAL_MAX( maChildRequisition.Height, rArea.Height ) - thumbHeight - 4 );
126 if ( mxChild.is() )
127 allocateChildAt( mxChild, childRect );
128 }
129
130 #define MAX_CHILD_REQ 40
getMinimumSize()131 ::com::sun::star::awt::Size SAL_CALL VCLXScroller::getMinimumSize()
132 throw(::com::sun::star::uno::RuntimeException)
133 {
134 ensureScrollBars();
135 assert( mpHorScrollBar && mpVerScrollBar );
136 awt::Size childSize = Bin::getMinimumSize();
137 int thumbWidth = mpVerScrollBar->GetSizePixel().getWidth();
138 int thumbHeight = mpHorScrollBar->GetSizePixel().getHeight();
139 maRequisition = awt::Size(
140 SAL_MIN( MAX_CHILD_REQ, childSize.Width ) + thumbWidth,
141 SAL_MIN( MAX_CHILD_REQ, childSize.Height ) + thumbHeight );
142 return maRequisition;
143 }
144
ProcessWindowEvent(const VclWindowEvent & _rVclWindowEvent)145 void VCLXScroller::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
146 {
147 /*
148 ::vos::OClearableGuard aGuard( GetMutex() );
149
150 switch ( _rVclWindowEvent.GetId() )
151 {
152 default:
153 aGuard.clear();
154 */
155 VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
156 /*
157 break;
158 }
159 */
160 }
161
setProperty(const::rtl::OUString & PropertyName,const Any & Value)162 void SAL_CALL VCLXScroller::setProperty( const ::rtl::OUString& PropertyName, const Any &Value ) throw(RuntimeException)
163 {
164 ::vos::OGuard aGuard( GetMutex() );
165
166 if ( GetWindow() )
167 {
168 /*
169 sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
170 switch ( nPropertyId )
171 {
172 default:
173 */
174 VCLXWindow::setProperty( PropertyName, Value );
175 /*
176 }
177 */
178 }
179 }
180
getProperty(const::rtl::OUString & PropertyName)181 Any SAL_CALL VCLXScroller::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException)
182 {
183 ::vos::OGuard aGuard( GetMutex() );
184
185 Any aReturn;
186 if ( GetWindow() )
187 {
188 /*
189 sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
190 switch ( nPropertyId )
191 {
192 default:
193 */
194 aReturn = VCLXWindow::getProperty( PropertyName );
195
196 // }
197 }
198 return aReturn;
199 }
200
IMPL_LINK(VCLXScroller,ScrollHdl,ScrollBar *,pScrollBar)201 IMPL_LINK( VCLXScroller, ScrollHdl, ScrollBar *, pScrollBar )
202 {
203 (void) pScrollBar;
204 forceRecalc();
205 return 0;
206 }
207
208 } // namespace layoutimpl
209