1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/awt/XLayoutConstrains.hpp>
21 #include <com/sun/star/awt/XTextLayoutConstrains.hpp>
23 #include <toolkit/controls/unocontrolbase.hxx>
24 #include <toolkit/helper/property.hxx>
25 #include <comphelper/processfactory.hxx>
27 #include <tools/debug.hxx>
29 // ----------------------------------------------------
30 // class UnoControlBase
31 // ----------------------------------------------------
33 sal_Bool
UnoControlBase::ImplHasProperty( sal_uInt16 nPropId
)
35 ::rtl::OUString
aPropName( GetPropertyName( nPropId
) );
36 return ImplHasProperty( aPropName
);
39 sal_Bool
UnoControlBase::ImplHasProperty( const ::rtl::OUString
& aPropertyName
)
41 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xPSet( mxModel
, ::com::sun::star::uno::UNO_QUERY
);
44 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> xInfo
= xPSet
->getPropertySetInfo();
48 return xInfo
->hasPropertyByName( aPropertyName
);
51 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
)
53 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XMultiPropertySet
> xMPS( mxModel
, ::com::sun::star::uno::UNO_QUERY
);
57 DBG_ASSERT( xMPS
.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" );
61 ImplLockPropertyChangeNotifications( aPropertyNames
, true );
65 xMPS
->setPropertyValues( aPropertyNames
, aValues
);
67 catch( const ::com::sun::star::uno::Exception
& )
70 ImplLockPropertyChangeNotifications( aPropertyNames
, false );
73 ImplLockPropertyChangeNotifications( aPropertyNames
, false );
82 void UnoControlBase::ImplSetPropertyValue( const ::rtl::OUString
& aPropertyName
, const ::com::sun::star::uno::Any
& aValue
, sal_Bool bUpdateThis
)
84 // Model might be logged off already but an event still fires
87 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xPSet( mxModel
, ::com::sun::star::uno::UNO_QUERY
);
89 ImplLockPropertyChangeNotification( aPropertyName
, true );
93 xPSet
->setPropertyValue( aPropertyName
, aValue
);
95 catch( const com::sun::star::uno::Exception
& )
98 ImplLockPropertyChangeNotification( aPropertyName
, false );
102 ImplLockPropertyChangeNotification( aPropertyName
, false );
106 ::com::sun::star::uno::Any
UnoControlBase::ImplGetPropertyValue( const ::rtl::OUString
& aPropertyName
)
108 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> xPSet( mxModel
, ::com::sun::star::uno::UNO_QUERY
);
110 return xPSet
->getPropertyValue( aPropertyName
);
112 return ::com::sun::star::uno::Any();
115 sal_Bool
UnoControlBase::ImplGetPropertyValue_BOOL( sal_uInt16 nProp
)
117 sal_Bool b
= sal_False
;
120 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
126 sal_Int16
UnoControlBase::ImplGetPropertyValue_INT16( sal_uInt16 nProp
)
131 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
137 sal_Int32
UnoControlBase::ImplGetPropertyValue_INT32( sal_uInt16 nProp
)
142 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
148 double UnoControlBase::ImplGetPropertyValue_DOUBLE( sal_uInt16 nProp
)
153 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
159 ::rtl::OUString
UnoControlBase::ImplGetPropertyValue_UString( sal_uInt16 nProp
)
161 ::rtl::OUString aStr
;
164 ::com::sun::star::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
170 ::com::sun::star::awt::Size
UnoControlBase::Impl_getMinimumSize()
172 ::com::sun::star::awt::Size aSz
;
173 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> xP
= ImplGetCompatiblePeer( sal_True
);
174 DBG_ASSERT( xP
.is(), "Layout: No Peer!" );
177 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XLayoutConstrains
> xL( xP
, ::com::sun::star::uno::UNO_QUERY
);
179 aSz
= xL
->getMinimumSize();
181 if ( !getPeer().is() || ( getPeer() != xP
) )
187 ::com::sun::star::awt::Size
UnoControlBase::Impl_getPreferredSize()
189 ::com::sun::star::awt::Size aSz
;
190 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> xP
= ImplGetCompatiblePeer( sal_True
);
191 DBG_ASSERT( xP
.is(), "Layout: No Peer!" );
194 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XLayoutConstrains
> xL( xP
, ::com::sun::star::uno::UNO_QUERY
);
196 aSz
= xL
->getPreferredSize();
198 if ( !getPeer().is() || ( getPeer() != xP
) )
204 ::com::sun::star::awt::Size
UnoControlBase::Impl_calcAdjustedSize( const ::com::sun::star::awt::Size
& rNewSize
)
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
->calcAdjustedSize( rNewSize
);
215 if ( !getPeer().is() || ( getPeer() != xP
) )
221 ::com::sun::star::awt::Size
UnoControlBase::Impl_getMinimumSize( sal_Int16 nCols
, sal_Int16 nLines
)
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::XTextLayoutConstrains
> xL( xP
, ::com::sun::star::uno::UNO_QUERY
);
230 aSz
= xL
->getMinimumSize( nCols
, nLines
);
232 if ( !getPeer().is() || ( getPeer() != xP
) )
238 void UnoControlBase::Impl_getColumnsAndLines( sal_Int16
& nCols
, sal_Int16
& nLines
)
240 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> xP
= ImplGetCompatiblePeer( sal_True
);
241 DBG_ASSERT( xP
.is(), "Layout: No Peer!" );
244 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XTextLayoutConstrains
> xL( xP
, ::com::sun::star::uno::UNO_QUERY
);
246 xL
->getColumnsAndLines( nCols
, nLines
);
248 if ( !getPeer().is() || ( getPeer() != xP
) )
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */