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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_toolkit.hxx" 30 #include "toolkit/controls/tkscrollbar.hxx" 31 #include "toolkit/helper/property.hxx" 32 #include "toolkit/helper/unopropertyarrayhelper.hxx" 33 #include <cppuhelper/typeprovider.hxx> 34 #include <tools/debug.hxx> 35 36 // for introspection 37 #include <toolkit/awt/vclxwindows.hxx> 38 39 //........................................................................ 40 namespace toolkit 41 { 42 //........................................................................ 43 44 using namespace ::com::sun::star; 45 46 //==================================================================== 47 //= UnoControlScrollBarModel 48 //==================================================================== 49 //-------------------------------------------------------------------- 50 UnoControlScrollBarModel::UnoControlScrollBarModel( const uno::Reference< lang::XMultiServiceFactory >& i_factory ) 51 :UnoControlModel( i_factory ) 52 { 53 UNO_CONTROL_MODEL_REGISTER_PROPERTIES( VCLXScrollBar ); 54 } 55 56 //-------------------------------------------------------------------- 57 ::rtl::OUString UnoControlScrollBarModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException) 58 { 59 return ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBarModel ); 60 } 61 62 //-------------------------------------------------------------------- 63 uno::Any UnoControlScrollBarModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const 64 { 65 switch ( nPropId ) 66 { 67 case BASEPROPERTY_LIVE_SCROLL: 68 return uno::makeAny( (sal_Bool)sal_False ); 69 case BASEPROPERTY_DEFAULTCONTROL: 70 return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlScrollBar ) ); 71 72 default: 73 return UnoControlModel::ImplGetDefaultValue( nPropId ); 74 } 75 } 76 77 //-------------------------------------------------------------------- 78 ::cppu::IPropertyArrayHelper& UnoControlScrollBarModel::getInfoHelper() 79 { 80 static UnoPropertyArrayHelper* pHelper = NULL; 81 if ( !pHelper ) 82 { 83 uno::Sequence<sal_Int32> aIDs = ImplGetPropertyIds(); 84 pHelper = new UnoPropertyArrayHelper( aIDs ); 85 } 86 return *pHelper; 87 } 88 89 //-------------------------------------------------------------------- 90 uno::Reference< beans::XPropertySetInfo > UnoControlScrollBarModel::getPropertySetInfo( ) throw(uno::RuntimeException) 91 { 92 static uno::Reference< beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 93 return xInfo; 94 } 95 96 97 //==================================================================== 98 //= UnoControlScrollBarModel 99 //==================================================================== 100 UnoScrollBarControl::UnoScrollBarControl( const uno::Reference< lang::XMultiServiceFactory >& i_factory ) 101 :UnoControlBase( i_factory ) 102 ,maAdjustmentListeners( *this ) 103 { 104 } 105 106 ::rtl::OUString UnoScrollBarControl::GetComponentServiceName() 107 { 108 return ::rtl::OUString::createFromAscii( "ScrollBar" ); 109 } 110 111 // ::com::sun::star::uno::XInterface 112 uno::Any UnoScrollBarControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException) 113 { 114 uno::Any aRet = ::cppu::queryInterface( rType, 115 SAL_STATIC_CAST( awt::XAdjustmentListener*, this ), 116 SAL_STATIC_CAST( awt::XScrollBar*, this ) ); 117 return (aRet.hasValue() ? aRet : UnoControlBase::queryAggregation( rType )); 118 } 119 120 // ::com::sun::star::lang::XTypeProvider 121 IMPL_XTYPEPROVIDER_START( UnoScrollBarControl ) 122 getCppuType( ( uno::Reference< awt::XAdjustmentListener>* ) NULL ), 123 getCppuType( ( uno::Reference< awt::XScrollBar>* ) NULL ), 124 UnoControlBase::getTypes() 125 IMPL_XTYPEPROVIDER_END 126 127 void UnoScrollBarControl::dispose() throw(uno::RuntimeException) 128 { 129 lang::EventObject aEvt; 130 aEvt.Source = (::cppu::OWeakObject*)this; 131 maAdjustmentListeners.disposeAndClear( aEvt ); 132 UnoControl::dispose(); 133 } 134 135 void UnoScrollBarControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer > & rParentPeer ) throw(uno::RuntimeException) 136 { 137 UnoControl::createPeer( rxToolkit, rParentPeer ); 138 139 uno::Reference < awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 140 xScrollBar->addAdjustmentListener( this ); 141 } 142 143 // ::com::sun::star::awt::XAdjustmentListener 144 void UnoScrollBarControl::adjustmentValueChanged( const ::com::sun::star::awt::AdjustmentEvent& rEvent ) throw(::com::sun::star::uno::RuntimeException) 145 { 146 switch ( rEvent.Type ) 147 { 148 case ::com::sun::star::awt::AdjustmentType_ADJUST_LINE: 149 case ::com::sun::star::awt::AdjustmentType_ADJUST_PAGE: 150 case ::com::sun::star::awt::AdjustmentType_ADJUST_ABS: 151 { 152 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 153 154 if ( xScrollBar.is() ) 155 { 156 uno::Any aAny; 157 aAny <<= xScrollBar->getValue(); 158 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_False ); 159 } 160 } 161 break; 162 default: 163 { 164 DBG_ERROR( "UnoScrollBarControl::adjustmentValueChanged - unknown Type" ); 165 166 } 167 } 168 169 if ( maAdjustmentListeners.getLength() ) 170 maAdjustmentListeners.adjustmentValueChanged( rEvent ); 171 } 172 173 // ::com::sun::star::awt::XScrollBar 174 void UnoScrollBarControl::addAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException) 175 { 176 maAdjustmentListeners.addInterface( l ); 177 } 178 179 void UnoScrollBarControl::removeAdjustmentListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XAdjustmentListener > & l ) throw(::com::sun::star::uno::RuntimeException) 180 { 181 maAdjustmentListeners.removeInterface( l ); 182 } 183 184 void UnoScrollBarControl::setValue( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 185 { 186 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), uno::makeAny( n ), sal_True ); 187 } 188 189 void UnoScrollBarControl::setValues( sal_Int32 nValue, sal_Int32 nVisible, sal_Int32 nMax ) throw(::com::sun::star::uno::RuntimeException) 190 { 191 uno::Any aAny; 192 aAny <<= nValue; 193 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE ), aAny, sal_True ); 194 aAny <<= nVisible; 195 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), aAny, sal_True ); 196 aAny <<= nMax; 197 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), aAny, sal_True ); 198 } 199 200 sal_Int32 UnoScrollBarControl::getValue() throw(::com::sun::star::uno::RuntimeException) 201 { 202 sal_Int32 n = 0; 203 if ( getPeer().is() ) 204 { 205 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 206 n = xScrollBar->getValue(); 207 } 208 return n; 209 } 210 211 void UnoScrollBarControl::setMaximum( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 212 { 213 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_SCROLLVALUE_MAX ), uno::makeAny( n ), sal_True ); 214 } 215 216 sal_Int32 UnoScrollBarControl::getMaximum() throw(::com::sun::star::uno::RuntimeException) 217 { 218 sal_Int32 n = 0; 219 if ( getPeer().is() ) 220 { 221 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 222 n = xScrollBar->getMaximum(); 223 } 224 return n; 225 } 226 227 void UnoScrollBarControl::setLineIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 228 { 229 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_LINEINCREMENT ), uno::makeAny( n ), sal_True ); 230 } 231 232 sal_Int32 UnoScrollBarControl::getLineIncrement() throw(::com::sun::star::uno::RuntimeException) 233 { 234 sal_Int32 n = 0; 235 if ( getPeer().is() ) 236 { 237 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 238 n = xScrollBar->getLineIncrement(); 239 } 240 return n; 241 } 242 243 void UnoScrollBarControl::setBlockIncrement( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 244 { 245 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_BLOCKINCREMENT ), uno::makeAny( n ), sal_True ); 246 } 247 248 sal_Int32 UnoScrollBarControl::getBlockIncrement() throw(::com::sun::star::uno::RuntimeException) 249 { 250 sal_Int32 n = 0; 251 if ( getPeer().is() ) 252 { 253 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 254 n = xScrollBar->getBlockIncrement(); 255 } 256 return n; 257 } 258 259 void UnoScrollBarControl::setVisibleSize( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 260 { 261 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_VISIBLESIZE ), uno::makeAny( n ), sal_True ); 262 } 263 264 sal_Int32 UnoScrollBarControl::getVisibleSize() throw(::com::sun::star::uno::RuntimeException) 265 { 266 sal_Int32 n = 0; 267 if ( getPeer().is() ) 268 { 269 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 270 n = xScrollBar->getVisibleSize(); 271 } 272 return n; 273 } 274 275 void UnoScrollBarControl::setOrientation( sal_Int32 n ) throw(::com::sun::star::uno::RuntimeException) 276 { 277 ImplSetPropertyValue( GetPropertyName( BASEPROPERTY_ORIENTATION ), uno::makeAny( n ), sal_True ); 278 } 279 280 sal_Int32 UnoScrollBarControl::getOrientation() throw(::com::sun::star::uno::RuntimeException) 281 { 282 sal_Int32 n = 0; 283 if ( getPeer().is() ) 284 { 285 uno::Reference< awt::XScrollBar > xScrollBar( getPeer(), uno::UNO_QUERY ); 286 n = xScrollBar->getOrientation(); 287 } 288 return n; 289 } 290 291 292 293 //........................................................................ 294 } // namespace toolkit 295 //........................................................................ 296 297