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>
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/beans/XMultiPropertySet.hpp>
25 #include <toolkit/controls/unocontrolbase.hxx>
26 #include <helper/property.hxx>
28 #include <tools/debug.hxx>
30 using namespace com::sun::star
;
35 bool UnoControlBase::ImplHasProperty( sal_uInt16 nPropId
)
37 const OUString
& aPropName( GetPropertyName( nPropId
) );
38 return ImplHasProperty( aPropName
);
41 bool UnoControlBase::ImplHasProperty( const OUString
& aPropertyName
)
43 css::uno::Reference
< css::beans::XPropertySet
> xPSet( mxModel
, css::uno::UNO_QUERY
);
46 css::uno::Reference
< css::beans::XPropertySetInfo
> xInfo
= xPSet
->getPropertySetInfo();
50 return xInfo
->hasPropertyByName( aPropertyName
);
53 void UnoControlBase::ImplSetPropertyValues( const css::uno::Sequence
< OUString
>& aPropertyNames
, const css::uno::Sequence
< css::uno::Any
>& aValues
, bool bUpdateThis
)
55 css::uno::Reference
< css::beans::XMultiPropertySet
> xMPS( mxModel
, css::uno::UNO_QUERY
);
59 DBG_ASSERT( xMPS
.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" );
64 ImplLockPropertyChangeNotifications( aPropertyNames
, true );
68 xMPS
->setPropertyValues( aPropertyNames
, aValues
);
70 catch( const css::uno::Exception
& )
73 ImplLockPropertyChangeNotifications( aPropertyNames
, false );
76 ImplLockPropertyChangeNotifications( aPropertyNames
, false );
79 void UnoControlBase::ImplSetPropertyValue( const OUString
& aPropertyName
, const css::uno::Any
& aValue
, bool bUpdateThis
)
81 // Model might be logged off already but an event still fires
85 css::uno::Reference
< css::beans::XPropertySet
> xPSet( mxModel
, css::uno::UNO_QUERY
);
87 ImplLockPropertyChangeNotification( aPropertyName
, true );
91 xPSet
->setPropertyValue( aPropertyName
, aValue
);
93 catch( const css::uno::Exception
& )
96 ImplLockPropertyChangeNotification( aPropertyName
, false );
100 ImplLockPropertyChangeNotification( aPropertyName
, false );
103 css::uno::Any
UnoControlBase::ImplGetPropertyValue( const OUString
& aPropertyName
) const
105 css::uno::Reference
< css::beans::XPropertySet
> xPSet( mxModel
, css::uno::UNO_QUERY
);
107 return xPSet
->getPropertyValue( aPropertyName
);
109 return css::uno::Any();
112 template <typename T
> T
UnoControlBase::ImplGetPropertyValuePOD( sal_uInt16 nProp
)
117 css::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
123 template <typename T
> T
UnoControlBase::ImplGetPropertyValueClass( sal_uInt16 nProp
)
128 css::uno::Any aVal
= ImplGetPropertyValue( GetPropertyName( nProp
) );
134 bool UnoControlBase::ImplGetPropertyValue_BOOL( sal_uInt16 nProp
)
136 return ImplGetPropertyValuePOD
<bool>(nProp
);
139 sal_Int16
UnoControlBase::ImplGetPropertyValue_INT16( sal_uInt16 nProp
)
141 return ImplGetPropertyValuePOD
<sal_Int16
>(nProp
);
144 sal_Int32
UnoControlBase::ImplGetPropertyValue_INT32( sal_uInt16 nProp
)
146 return ImplGetPropertyValuePOD
<sal_Int32
>(nProp
);
149 double UnoControlBase::ImplGetPropertyValue_DOUBLE( sal_uInt16 nProp
)
151 return ImplGetPropertyValuePOD
<double>(nProp
);
154 OUString
UnoControlBase::ImplGetPropertyValue_UString( sal_uInt16 nProp
)
156 return ImplGetPropertyValueClass
<OUString
>(nProp
);
159 util::Date
UnoControlBase::ImplGetPropertyValue_Date( sal_uInt16 nProp
)
161 return ImplGetPropertyValueClass
<util::Date
>(nProp
);
164 util::Time
UnoControlBase::ImplGetPropertyValue_Time( sal_uInt16 nProp
)
166 return ImplGetPropertyValueClass
<util::Time
>(nProp
);
169 css::awt::Size
UnoControlBase::Impl_getMinimumSize()
172 css::uno::Reference
< css::awt::XWindowPeer
> xP
= ImplGetCompatiblePeer();
173 DBG_ASSERT( xP
.is(), "Layout: No Peer!" );
176 css::uno::Reference
< css::awt::XLayoutConstrains
> xL( xP
, css::uno::UNO_QUERY
);
178 aSz
= xL
->getMinimumSize();
180 if ( !getPeer().is() || ( getPeer() != xP
) )
186 css::awt::Size
UnoControlBase::Impl_getPreferredSize()
189 css::uno::Reference
< css::awt::XWindowPeer
> xP
= ImplGetCompatiblePeer();
190 DBG_ASSERT( xP
.is(), "Layout: No Peer!" );
193 css::uno::Reference
< css::awt::XLayoutConstrains
> xL( xP
, css::uno::UNO_QUERY
);
195 aSz
= xL
->getPreferredSize();
197 if ( !getPeer().is() || ( getPeer() != xP
) )
203 css::awt::Size
UnoControlBase::Impl_calcAdjustedSize( const css::awt::Size
& rNewSize
)
206 css::uno::Reference
< css::awt::XWindowPeer
> xP
= ImplGetCompatiblePeer();
207 DBG_ASSERT( xP
.is(), "Layout: No Peer!" );
210 css::uno::Reference
< css::awt::XLayoutConstrains
> xL( xP
, css::uno::UNO_QUERY
);
212 aSz
= xL
->calcAdjustedSize( rNewSize
);
214 if ( !getPeer().is() || ( getPeer() != xP
) )
220 css::awt::Size
UnoControlBase::Impl_getMinimumSize( sal_Int16 nCols
, sal_Int16 nLines
)
223 css::uno::Reference
< css::awt::XWindowPeer
> xP
= ImplGetCompatiblePeer();
224 DBG_ASSERT( xP
.is(), "Layout: No Peer!" );
227 css::uno::Reference
< css::awt::XTextLayoutConstrains
> xL( xP
, css::uno::UNO_QUERY
);
229 aSz
= xL
->getMinimumSize( nCols
, nLines
);
231 if ( !getPeer().is() || ( getPeer() != xP
) )
237 void UnoControlBase::Impl_getColumnsAndLines( sal_Int16
& nCols
, sal_Int16
& nLines
)
239 css::uno::Reference
< css::awt::XWindowPeer
> xP
= ImplGetCompatiblePeer();
240 DBG_ASSERT( xP
.is(), "Layout: No Peer!" );
243 css::uno::Reference
< css::awt::XTextLayoutConstrains
> xL( xP
, css::uno::UNO_QUERY
);
245 xL
->getColumnsAndLines( nCols
, nLines
);
247 if ( !getPeer().is() || ( getPeer() != xP
) )
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */