1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "vclxscroller.hxx"
29 
30 #include <assert.h>
31 #include <com/sun/star/awt/PosSize.hpp>
32 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
33 #include <sal/macros.h>
34 #include <toolkit/helper/property.hxx>
35 #include <tools/debug.hxx>
36 #include <vcl/scrbar.hxx>
37 
38 #include "forward.hxx"
39 
40 namespace layoutimpl
41 {
42 
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::awt;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star;
48 
49 DBG_NAME( VCLXScroller )
50 
51 VCLXScroller::VCLXScroller()
52   : VCLXWindow()
53   , Bin()
54 {
55     DBG_CTOR( VCLXScroller, NULL );
56     mpHorScrollBar = mpVerScrollBar = 0;
57 }
58 
59 VCLXScroller::~VCLXScroller()
60 {
61     DBG_DTOR( VCLXScroller, NULL );
62 }
63 
64 IMPLEMENT_2_FORWARD_XINTERFACE1( VCLXScroller, VCLXWindow, Container );
65 
66 IMPLEMENT_FORWARD_XTYPEPROVIDER1( VCLXScroller, VCLXWindow );
67 
68 void SAL_CALL VCLXScroller::dispose() throw(RuntimeException)
69 {
70     {
71         ::vos::OGuard aGuard( GetMutex() );
72 
73         EventObject aDisposeEvent;
74         aDisposeEvent.Source = W3K_EXPLICIT_CAST (*this);
75 //            maTabListeners.disposeAndClear( aDisposeEvent );
76     }
77 
78     VCLXWindow::dispose();
79 }
80 
81 void VCLXScroller::ensureScrollBars()
82 {
83 
84     if ( !mpVerScrollBar )
85     {
86         mpVerScrollBar = new ScrollBar( GetWindow() , WB_VERT );
87         mpVerScrollBar->SetLineSize( 4 );
88         mpVerScrollBar->SetPageSize( 15 );
89         mpVerScrollBar->Show();
90         mpVerScrollBar->SetScrollHdl( LINK( this, VCLXScroller, ScrollHdl ) );
91     }
92     if ( !mpHorScrollBar )
93     {
94         mpHorScrollBar = new ScrollBar( GetWindow() , WB_HORZ );
95         mpHorScrollBar->SetLineSize( 4 );
96         mpHorScrollBar->SetPageSize( 15 );
97         mpHorScrollBar->Show();
98         mpHorScrollBar->SetScrollHdl( LINK( this, VCLXScroller, ScrollHdl ) );
99     } //        mpContent = new FixedImage( this, ImplGetWinBits( WindowAttributes, 0 ) );
100 
101 }
102 
103 void SAL_CALL VCLXScroller::allocateArea(
104     const ::com::sun::star::awt::Rectangle &rArea )
105     throw (::com::sun::star::uno::RuntimeException)
106 {
107     ensureScrollBars();        // shouldn't be needed
108 
109     maAllocation = rArea;
110     setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height, PosSize::POSSIZE );
111 
112     mpHorScrollBar->SetRangeMin( 0 );
113     mpHorScrollBar->SetRangeMax( SAL_MAX( maChildRequisition.Width - rArea.Width, 0 ) );
114     mpVerScrollBar->SetRangeMin( 0 );
115     mpVerScrollBar->SetRangeMax( SAL_MAX( maChildRequisition.Height - rArea.Height, 0 ) );
116 
117     int thumbX = mpHorScrollBar->GetThumbPos();
118     int thumbY = mpVerScrollBar->GetThumbPos();
119     int thumbWidth = mpVerScrollBar->GetSizePixel().getWidth();
120     int thumbHeight = mpHorScrollBar->GetSizePixel().getHeight();
121 
122     mpHorScrollBar->SetPosSizePixel( rArea.X, rArea.Y + rArea.Height - thumbHeight - 2,
123                                      rArea.Width - thumbWidth, thumbHeight );
124     mpVerScrollBar->SetPosSizePixel( rArea.X + rArea.Width - thumbWidth - 2, rArea.Y-2,
125                                      thumbWidth, rArea.Height - thumbHeight );
126 
127     awt::Rectangle childRect( rArea.X - thumbX, rArea.Y - thumbY,
128                               SAL_MAX( maChildRequisition.Width, rArea.Width ) - thumbWidth - 4,
129                               SAL_MAX( maChildRequisition.Height, rArea.Height ) - thumbHeight - 4 );
130     if ( mxChild.is() )
131         allocateChildAt( mxChild, childRect );
132 }
133 
134 #define MAX_CHILD_REQ 40
135 ::com::sun::star::awt::Size SAL_CALL VCLXScroller::getMinimumSize()
136     throw(::com::sun::star::uno::RuntimeException)
137 {
138     ensureScrollBars();
139     assert( mpHorScrollBar && mpVerScrollBar );
140     awt::Size childSize = Bin::getMinimumSize();
141     int thumbWidth = mpVerScrollBar->GetSizePixel().getWidth();
142     int thumbHeight = mpHorScrollBar->GetSizePixel().getHeight();
143     maRequisition = awt::Size(
144         SAL_MIN( MAX_CHILD_REQ, childSize.Width ) + thumbWidth,
145         SAL_MIN( MAX_CHILD_REQ, childSize.Height ) + thumbHeight );
146     return maRequisition;
147 }
148 
149 void VCLXScroller::ProcessWindowEvent( const VclWindowEvent& _rVclWindowEvent )
150 {
151 /*
152     ::vos::OClearableGuard aGuard( GetMutex() );
153 
154     switch ( _rVclWindowEvent.GetId() )
155     {
156         default:
157             aGuard.clear();
158 */
159             VCLXWindow::ProcessWindowEvent( _rVclWindowEvent );
160 /*
161         break;
162     }
163 */
164 }
165 
166 void SAL_CALL VCLXScroller::setProperty( const ::rtl::OUString& PropertyName, const Any &Value ) throw(RuntimeException)
167 {
168     ::vos::OGuard aGuard( GetMutex() );
169 
170     if ( GetWindow() )
171     {
172 /*
173         sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
174         switch ( nPropertyId )
175         {
176             default:
177 */
178                 VCLXWindow::setProperty( PropertyName, Value );
179 /*
180         }
181 */
182     }
183 }
184 
185 Any SAL_CALL VCLXScroller::getProperty( const ::rtl::OUString& PropertyName ) throw(RuntimeException)
186 {
187     ::vos::OGuard aGuard( GetMutex() );
188 
189     Any aReturn;
190     if ( GetWindow() )
191     {
192 /*
193         sal_uInt16 nPropertyId = GetPropertyId( PropertyName );
194         switch ( nPropertyId )
195         {
196             default:
197 */
198                 aReturn = VCLXWindow::getProperty( PropertyName );
199 
200 //        }
201     }
202     return aReturn;
203 }
204 
205 IMPL_LINK( VCLXScroller, ScrollHdl, ScrollBar *, pScrollBar )
206 {
207     (void) pScrollBar;
208     forceRecalc();
209     return 0;
210 }
211 
212 } // namespace layoutimpl
213