1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unocontrolbase.cxx,v $
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
);
56 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> xInfo
= xPSet
->getPropertySetInfo();
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
);
69 DBG_ASSERT( xMPS
.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" );
73 ImplLockPropertyChangeNotifications( aPropertyNames
, true );
77 xMPS
->setPropertyValues( aPropertyNames
, aValues
);
79 catch( const ::com::sun::star::uno::Exception
& )
82 ImplLockPropertyChangeNotifications( aPropertyNames
, false );
85 ImplLockPropertyChangeNotifications( aPropertyNames
, false );
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...
99 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xPSet( mxModel
, ::com::sun::star::uno::UNO_QUERY
);
101 ImplLockPropertyChangeNotification( aPropertyName
, true );
105 xPSet
->setPropertyValue( aPropertyName
, aValue
);
107 catch( const com::sun::star::uno::Exception
& )
110 ImplLockPropertyChangeNotification( aPropertyName
, false );
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
);
122 return xPSet
->getPropertyValue( aPropertyName
);
124 return ::com::sun::star::uno::Any();
127 sal_Bool
UnoControlBase::ImplGetPropertyValue_BOOL( sal_uInt16 nProp
)
129 sal_Bool b
= sal_False
;
132 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
138 sal_Int16
UnoControlBase::ImplGetPropertyValue_INT16( sal_uInt16 nProp
)
143 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
149 sal_uInt16
UnoControlBase::ImplGetPropertyValue_UINT16( sal_uInt16 nProp
)
154 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
160 sal_Int32
UnoControlBase::ImplGetPropertyValue_INT32( sal_uInt16 nProp
)
165 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
171 sal_uInt32
UnoControlBase::ImplGetPropertyValue_UINT32( sal_uInt16 nProp
)
176 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
182 double UnoControlBase::ImplGetPropertyValue_DOUBLE( sal_uInt16 nProp
)
187 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
193 ::rtl::OUString
UnoControlBase::ImplGetPropertyValue_UString( sal_uInt16 nProp
)
195 ::rtl::OUString aStr
;
198 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
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!" );
211 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XLayoutConstrains
> xL( xP
, ::com::sun::star::uno::UNO_QUERY
);
213 aSz
= xL
->getMinimumSize();
215 if ( !getPeer().is() || ( getPeer() != xP
) )
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!" );
228 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XLayoutConstrains
> xL( xP
, ::com::sun::star::uno::UNO_QUERY
);
230 aSz
= xL
->getPreferredSize();
232 if ( !getPeer().is() || ( getPeer() != xP
) )
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!" );
245 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XLayoutConstrains
> xL( xP
, ::com::sun::star::uno::UNO_QUERY
);
247 aSz
= xL
->calcAdjustedSize( rNewSize
);
249 if ( !getPeer().is() || ( getPeer() != xP
) )
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!" );
262 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTextLayoutConstrains
> xL( xP
, ::com::sun::star::uno::UNO_QUERY
);
264 aSz
= xL
->getMinimumSize( nCols
, nLines
);
266 if ( !getPeer().is() || ( getPeer() != xP
) )
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!" );
278 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTextLayoutConstrains
> xL( xP
, ::com::sun::star::uno::UNO_QUERY
);
280 xL
->getColumnsAndLines( nCols
, nLines
);
282 if ( !getPeer().is() || ( getPeer() != xP
) )