merge the formfield patch from ooo-build
[ooovba.git] / toolkit / source / controls / unocontrolbase.cxx
blob9f315a0a6d584a5813a58fbafca665a4eea17a2e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unocontrolbase.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
33 #include <com/sun/star/awt/XLayoutConstrains.hpp>
34 #include <com/sun/star/awt/XTextLayoutConstrains.hpp>
36 #include <toolkit/controls/unocontrolbase.hxx>
37 #include <toolkit/helper/property.hxx>
39 #include <tools/debug.hxx>
41 // ----------------------------------------------------
42 // class UnoControlBase
43 // ----------------------------------------------------
45 sal_Bool UnoControlBase::ImplHasProperty( sal_uInt16 nPropId )
47 ::rtl::OUString aPropName( GetPropertyName( nPropId ) );
48 return ImplHasProperty( aPropName );
51 sal_Bool UnoControlBase::ImplHasProperty( const ::rtl::OUString& aPropertyName )
53 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
54 if ( !xPSet.is() )
55 return sal_False;
56 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = xPSet->getPropertySetInfo();
57 if ( !xInfo.is() )
58 return sal_False;
60 return xInfo->hasPropertyByName( aPropertyName );
63 void UnoControlBase::ImplSetPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aValues, sal_Bool bUpdateThis )
65 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > xMPS( mxModel, ::com::sun::star::uno::UNO_QUERY );
66 if ( !mxModel.is() )
67 return;
69 DBG_ASSERT( xMPS.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" );
70 if ( xMPS.is() )
72 if ( !bUpdateThis )
73 ImplLockPropertyChangeNotifications( aPropertyNames, true );
75 try
77 xMPS->setPropertyValues( aPropertyNames, aValues );
79 catch( const ::com::sun::star::uno::Exception& )
81 if ( !bUpdateThis )
82 ImplLockPropertyChangeNotifications( aPropertyNames, false );
84 if ( !bUpdateThis )
85 ImplLockPropertyChangeNotifications( aPropertyNames, false );
87 else
89 int dummy = 0;
90 (void)dummy;
94 void UnoControlBase::ImplSetPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue, sal_Bool bUpdateThis )
96 // Model ggf. schon abgemeldet, aber ein Event schlaegt noch zu...
97 if ( mxModel.is() )
99 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
100 if ( !bUpdateThis )
101 ImplLockPropertyChangeNotification( aPropertyName, true );
105 xPSet->setPropertyValue( aPropertyName, aValue );
107 catch( const com::sun::star::uno::Exception& )
109 if ( !bUpdateThis )
110 ImplLockPropertyChangeNotification( aPropertyName, false );
111 throw;
113 if ( !bUpdateThis )
114 ImplLockPropertyChangeNotification( aPropertyName, false );
118 ::com::sun::star::uno::Any UnoControlBase::ImplGetPropertyValue( const ::rtl::OUString& aPropertyName )
120 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
121 if ( xPSet.is() )
122 return xPSet->getPropertyValue( aPropertyName );
123 else
124 return ::com::sun::star::uno::Any();
127 sal_Bool UnoControlBase::ImplGetPropertyValue_BOOL( sal_uInt16 nProp )
129 sal_Bool b = sal_False;
130 if ( mxModel.is() )
132 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
133 aVal >>= b;
135 return b;
138 sal_Int16 UnoControlBase::ImplGetPropertyValue_INT16( sal_uInt16 nProp )
140 sal_Int16 n = 0;
141 if ( mxModel.is() )
143 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
144 aVal >>= n;
146 return n;
149 sal_uInt16 UnoControlBase::ImplGetPropertyValue_UINT16( sal_uInt16 nProp )
151 sal_uInt16 n = 0;
152 if ( mxModel.is() )
154 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
155 aVal >>= n;
157 return n;
160 sal_Int32 UnoControlBase::ImplGetPropertyValue_INT32( sal_uInt16 nProp )
162 sal_Int32 n = 0;
163 if ( mxModel.is() )
165 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
166 aVal >>= n;
168 return n;
171 sal_uInt32 UnoControlBase::ImplGetPropertyValue_UINT32( sal_uInt16 nProp )
173 sal_uInt32 n = 0;
174 if ( mxModel.is() )
176 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
177 aVal >>= n;
179 return n;
182 double UnoControlBase::ImplGetPropertyValue_DOUBLE( sal_uInt16 nProp )
184 double n = 0;
185 if ( mxModel.is() )
187 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
188 aVal >>= n;
190 return n;
193 ::rtl::OUString UnoControlBase::ImplGetPropertyValue_UString( sal_uInt16 nProp )
195 ::rtl::OUString aStr;
196 if ( mxModel.is() )
198 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
199 aVal >>= aStr;
201 return aStr;
204 ::com::sun::star::awt::Size UnoControlBase::Impl_getMinimumSize()
206 ::com::sun::star::awt::Size aSz;
207 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
208 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
209 if ( xP.is() )
211 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
212 if ( xL.is() )
213 aSz = xL->getMinimumSize();
215 if ( !getPeer().is() || ( getPeer() != xP ) )
216 xP->dispose();
218 return aSz;
221 ::com::sun::star::awt::Size UnoControlBase::Impl_getPreferredSize()
223 ::com::sun::star::awt::Size aSz;
224 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
225 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
226 if ( xP.is() )
228 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
229 if ( xL.is() )
230 aSz = xL->getPreferredSize();
232 if ( !getPeer().is() || ( getPeer() != xP ) )
233 xP->dispose();
235 return aSz;
238 ::com::sun::star::awt::Size UnoControlBase::Impl_calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize )
240 ::com::sun::star::awt::Size aSz;
241 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
242 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
243 if ( xP.is() )
245 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
246 if ( xL.is() )
247 aSz = xL->calcAdjustedSize( rNewSize );
249 if ( !getPeer().is() || ( getPeer() != xP ) )
250 xP->dispose();
252 return aSz;
255 ::com::sun::star::awt::Size UnoControlBase::Impl_getMinimumSize( sal_Int16 nCols, sal_Int16 nLines )
257 ::com::sun::star::awt::Size aSz;
258 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
259 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
260 if ( xP.is() )
262 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
263 if ( xL.is() )
264 aSz = xL->getMinimumSize( nCols, nLines );
266 if ( !getPeer().is() || ( getPeer() != xP ) )
267 xP->dispose();
269 return aSz;
272 void UnoControlBase::Impl_getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines )
274 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
275 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
276 if ( xP.is() )
278 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
279 if ( xL.is() )
280 xL->getColumnsAndLines( nCols, nLines );
282 if ( !getPeer().is() || ( getPeer() != xP ) )
283 xP->dispose();