bump product version to 4.1.6.2
[LibreOffice.git] / toolkit / source / controls / unocontrolbase.cxx
blob26f06be28c1a7e87db16c4e0fecc0512b44bc1ec
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>
25 #include <comphelper/processfactory.hxx>
27 #include <tools/debug.hxx>
29 using namespace com::sun::star;
31 // ----------------------------------------------------
32 // class UnoControlBase
33 // ----------------------------------------------------
35 sal_Bool UnoControlBase::ImplHasProperty( sal_uInt16 nPropId )
37 OUString aPropName( GetPropertyName( nPropId ) );
38 return ImplHasProperty( aPropName );
41 sal_Bool UnoControlBase::ImplHasProperty( const OUString& aPropertyName )
43 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
44 if ( !xPSet.is() )
45 return sal_False;
46 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = xPSet->getPropertySetInfo();
47 if ( !xInfo.is() )
48 return sal_False;
50 return xInfo->hasPropertyByName( aPropertyName );
53 void UnoControlBase::ImplSetPropertyValues( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aValues, sal_Bool bUpdateThis )
55 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > xMPS( mxModel, ::com::sun::star::uno::UNO_QUERY );
56 if ( !mxModel.is() )
57 return;
59 DBG_ASSERT( xMPS.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" );
60 if ( xMPS.is() )
62 if ( !bUpdateThis )
63 ImplLockPropertyChangeNotifications( aPropertyNames, true );
65 try
67 xMPS->setPropertyValues( aPropertyNames, aValues );
69 catch( const ::com::sun::star::uno::Exception& )
71 if ( !bUpdateThis )
72 ImplLockPropertyChangeNotifications( aPropertyNames, false );
74 if ( !bUpdateThis )
75 ImplLockPropertyChangeNotifications( aPropertyNames, false );
77 else
79 int dummy = 0;
80 (void)dummy;
84 void UnoControlBase::ImplSetPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue, sal_Bool bUpdateThis )
86 // Model might be logged off already but an event still fires
87 if ( mxModel.is() )
89 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
90 if ( !bUpdateThis )
91 ImplLockPropertyChangeNotification( aPropertyName, true );
93 try
95 xPSet->setPropertyValue( aPropertyName, aValue );
97 catch( const com::sun::star::uno::Exception& )
99 if ( !bUpdateThis )
100 ImplLockPropertyChangeNotification( aPropertyName, false );
101 throw;
103 if ( !bUpdateThis )
104 ImplLockPropertyChangeNotification( aPropertyName, false );
108 ::com::sun::star::uno::Any UnoControlBase::ImplGetPropertyValue( const OUString& aPropertyName )
110 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
111 if ( xPSet.is() )
112 return xPSet->getPropertyValue( aPropertyName );
113 else
114 return ::com::sun::star::uno::Any();
117 template <typename T> T UnoControlBase::ImplGetPropertyValuePOD( sal_uInt16 nProp )
119 T t(0);
120 if ( mxModel.is() )
122 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
123 aVal >>= t;
125 return t;
128 template <typename T> T UnoControlBase::ImplGetPropertyValueClass( sal_uInt16 nProp )
130 T t;
131 if ( mxModel.is() )
133 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
134 aVal >>= t;
136 return t;
139 sal_Bool UnoControlBase::ImplGetPropertyValue_BOOL( sal_uInt16 nProp )
141 return ImplGetPropertyValuePOD<sal_Bool>(nProp);
144 sal_Int16 UnoControlBase::ImplGetPropertyValue_INT16( sal_uInt16 nProp )
146 return ImplGetPropertyValuePOD<sal_Int16>(nProp);
149 sal_Int32 UnoControlBase::ImplGetPropertyValue_INT32( sal_uInt16 nProp )
151 return ImplGetPropertyValuePOD<sal_Int32>(nProp);
154 sal_Int64 UnoControlBase::ImplGetPropertyValue_INT64( sal_uInt16 nProp )
156 return ImplGetPropertyValuePOD<sal_Int64>(nProp);
159 double UnoControlBase::ImplGetPropertyValue_DOUBLE( sal_uInt16 nProp )
161 return ImplGetPropertyValuePOD<double>(nProp);
164 OUString UnoControlBase::ImplGetPropertyValue_UString( sal_uInt16 nProp )
166 return ImplGetPropertyValueClass<OUString>(nProp);
169 util::Date UnoControlBase::ImplGetPropertyValue_Date( sal_uInt16 nProp )
171 return ImplGetPropertyValueClass<util::Date>(nProp);
174 util::Time UnoControlBase::ImplGetPropertyValue_Time( sal_uInt16 nProp )
176 return ImplGetPropertyValueClass<util::Time>(nProp);
179 ::com::sun::star::awt::Size UnoControlBase::Impl_getMinimumSize()
181 ::com::sun::star::awt::Size aSz;
182 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
183 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
184 if ( xP.is() )
186 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
187 if ( xL.is() )
188 aSz = xL->getMinimumSize();
190 if ( !getPeer().is() || ( getPeer() != xP ) )
191 xP->dispose();
193 return aSz;
196 ::com::sun::star::awt::Size UnoControlBase::Impl_getPreferredSize()
198 ::com::sun::star::awt::Size aSz;
199 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
200 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
201 if ( xP.is() )
203 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
204 if ( xL.is() )
205 aSz = xL->getPreferredSize();
207 if ( !getPeer().is() || ( getPeer() != xP ) )
208 xP->dispose();
210 return aSz;
213 ::com::sun::star::awt::Size UnoControlBase::Impl_calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize )
215 ::com::sun::star::awt::Size aSz;
216 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
217 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
218 if ( xP.is() )
220 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
221 if ( xL.is() )
222 aSz = xL->calcAdjustedSize( rNewSize );
224 if ( !getPeer().is() || ( getPeer() != xP ) )
225 xP->dispose();
227 return aSz;
230 ::com::sun::star::awt::Size UnoControlBase::Impl_getMinimumSize( sal_Int16 nCols, sal_Int16 nLines )
232 ::com::sun::star::awt::Size aSz;
233 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
234 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
235 if ( xP.is() )
237 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
238 if ( xL.is() )
239 aSz = xL->getMinimumSize( nCols, nLines );
241 if ( !getPeer().is() || ( getPeer() != xP ) )
242 xP->dispose();
244 return aSz;
247 void UnoControlBase::Impl_getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines )
249 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
250 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
251 if ( xP.is() )
253 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
254 if ( xL.is() )
255 xL->getColumnsAndLines( nCols, nLines );
257 if ( !getPeer().is() || ( getPeer() != xP ) )
258 xP->dispose();
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */