bump product version to 6.1.0.2
[LibreOffice.git] / toolkit / source / controls / unocontrolbase.cxx
blob8ecd3710347cc63f8d1d1672835dcb3f6c5dc2a4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <tools/debug.hxx>
28 using namespace com::sun::star;
31 // class UnoControlBase
34 bool UnoControlBase::ImplHasProperty( sal_uInt16 nPropId )
36 const OUString& aPropName( GetPropertyName( nPropId ) );
37 return ImplHasProperty( aPropName );
40 bool UnoControlBase::ImplHasProperty( const OUString& aPropertyName )
42 css::uno::Reference< css::beans::XPropertySet > xPSet( mxModel, css::uno::UNO_QUERY );
43 if ( !xPSet.is() )
44 return false;
45 css::uno::Reference< css::beans::XPropertySetInfo > xInfo = xPSet->getPropertySetInfo();
46 if ( !xInfo.is() )
47 return false;
49 return xInfo->hasPropertyByName( aPropertyName );
52 void UnoControlBase::ImplSetPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues, bool bUpdateThis )
54 css::uno::Reference< css::beans::XMultiPropertySet > xMPS( mxModel, css::uno::UNO_QUERY );
55 if ( !mxModel.is() )
56 return;
58 DBG_ASSERT( xMPS.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" );
59 if ( xMPS.is() )
61 if ( !bUpdateThis )
62 ImplLockPropertyChangeNotifications( aPropertyNames, true );
64 try
66 xMPS->setPropertyValues( aPropertyNames, aValues );
68 catch( const css::uno::Exception& )
70 if ( !bUpdateThis )
71 ImplLockPropertyChangeNotifications( aPropertyNames, false );
73 if ( !bUpdateThis )
74 ImplLockPropertyChangeNotifications( aPropertyNames, false );
78 void UnoControlBase::ImplSetPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue, bool bUpdateThis )
80 // Model might be logged off already but an event still fires
81 if ( mxModel.is() )
83 css::uno::Reference< css::beans::XPropertySet > xPSet( mxModel, css::uno::UNO_QUERY );
84 if ( !bUpdateThis )
85 ImplLockPropertyChangeNotification( aPropertyName, true );
87 try
89 xPSet->setPropertyValue( aPropertyName, aValue );
91 catch( const css::uno::Exception& )
93 if ( !bUpdateThis )
94 ImplLockPropertyChangeNotification( aPropertyName, false );
95 throw;
97 if ( !bUpdateThis )
98 ImplLockPropertyChangeNotification( aPropertyName, false );
102 css::uno::Any UnoControlBase::ImplGetPropertyValue( const OUString& aPropertyName )
104 css::uno::Reference< css::beans::XPropertySet > xPSet( mxModel, css::uno::UNO_QUERY );
105 if ( xPSet.is() )
106 return xPSet->getPropertyValue( aPropertyName );
107 else
108 return css::uno::Any();
111 template <typename T> T UnoControlBase::ImplGetPropertyValuePOD( sal_uInt16 nProp )
113 T t(0);
114 if ( mxModel.is() )
116 css::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
117 aVal >>= t;
119 return t;
122 template <typename T> T UnoControlBase::ImplGetPropertyValueClass( sal_uInt16 nProp )
124 T t;
125 if ( mxModel.is() )
127 css::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
128 aVal >>= t;
130 return t;
133 bool UnoControlBase::ImplGetPropertyValue_BOOL( sal_uInt16 nProp )
135 return ImplGetPropertyValuePOD<bool>(nProp);
138 sal_Int16 UnoControlBase::ImplGetPropertyValue_INT16( sal_uInt16 nProp )
140 return ImplGetPropertyValuePOD<sal_Int16>(nProp);
143 sal_Int32 UnoControlBase::ImplGetPropertyValue_INT32( sal_uInt16 nProp )
145 return ImplGetPropertyValuePOD<sal_Int32>(nProp);
148 double UnoControlBase::ImplGetPropertyValue_DOUBLE( sal_uInt16 nProp )
150 return ImplGetPropertyValuePOD<double>(nProp);
153 OUString UnoControlBase::ImplGetPropertyValue_UString( sal_uInt16 nProp )
155 return ImplGetPropertyValueClass<OUString>(nProp);
158 util::Date UnoControlBase::ImplGetPropertyValue_Date( sal_uInt16 nProp )
160 return ImplGetPropertyValueClass<util::Date>(nProp);
163 util::Time UnoControlBase::ImplGetPropertyValue_Time( sal_uInt16 nProp )
165 return ImplGetPropertyValueClass<util::Time>(nProp);
168 css::awt::Size UnoControlBase::Impl_getMinimumSize()
170 css::awt::Size aSz;
171 css::uno::Reference< css::awt::XWindowPeer > xP = ImplGetCompatiblePeer();
172 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
173 if ( xP.is() )
175 css::uno::Reference< css::awt::XLayoutConstrains > xL( xP, css::uno::UNO_QUERY );
176 if ( xL.is() )
177 aSz = xL->getMinimumSize();
179 if ( !getPeer().is() || ( getPeer() != xP ) )
180 xP->dispose();
182 return aSz;
185 css::awt::Size UnoControlBase::Impl_getPreferredSize()
187 css::awt::Size aSz;
188 css::uno::Reference< css::awt::XWindowPeer > xP = ImplGetCompatiblePeer();
189 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
190 if ( xP.is() )
192 css::uno::Reference< css::awt::XLayoutConstrains > xL( xP, css::uno::UNO_QUERY );
193 if ( xL.is() )
194 aSz = xL->getPreferredSize();
196 if ( !getPeer().is() || ( getPeer() != xP ) )
197 xP->dispose();
199 return aSz;
202 css::awt::Size UnoControlBase::Impl_calcAdjustedSize( const css::awt::Size& rNewSize )
204 css::awt::Size aSz;
205 css::uno::Reference< css::awt::XWindowPeer > xP = ImplGetCompatiblePeer();
206 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
207 if ( xP.is() )
209 css::uno::Reference< css::awt::XLayoutConstrains > xL( xP, css::uno::UNO_QUERY );
210 if ( xL.is() )
211 aSz = xL->calcAdjustedSize( rNewSize );
213 if ( !getPeer().is() || ( getPeer() != xP ) )
214 xP->dispose();
216 return aSz;
219 css::awt::Size UnoControlBase::Impl_getMinimumSize( sal_Int16 nCols, sal_Int16 nLines )
221 css::awt::Size aSz;
222 css::uno::Reference< css::awt::XWindowPeer > xP = ImplGetCompatiblePeer();
223 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
224 if ( xP.is() )
226 css::uno::Reference< css::awt::XTextLayoutConstrains > xL( xP, css::uno::UNO_QUERY );
227 if ( xL.is() )
228 aSz = xL->getMinimumSize( nCols, nLines );
230 if ( !getPeer().is() || ( getPeer() != xP ) )
231 xP->dispose();
233 return aSz;
236 void UnoControlBase::Impl_getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines )
238 css::uno::Reference< css::awt::XWindowPeer > xP = ImplGetCompatiblePeer();
239 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
240 if ( xP.is() )
242 css::uno::Reference< css::awt::XTextLayoutConstrains > xL( xP, css::uno::UNO_QUERY );
243 if ( xL.is() )
244 xL->getColumnsAndLines( nCols, nLines );
246 if ( !getPeer().is() || ( getPeer() != xP ) )
247 xP->dispose();
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */