Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / toolkit / source / controls / unocontrolbase.cxx
blob961f6e0ac3ee5b56c8693e5a63e2bc51e3a155cc
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 // ----------------------------------------------------
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 );
42 if ( !xPSet.is() )
43 return sal_False;
44 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = xPSet->getPropertySetInfo();
45 if ( !xInfo.is() )
46 return sal_False;
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 );
54 if ( !mxModel.is() )
55 return;
57 DBG_ASSERT( xMPS.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" );
58 if ( xMPS.is() )
60 if ( !bUpdateThis )
61 ImplLockPropertyChangeNotifications( aPropertyNames, true );
63 try
65 xMPS->setPropertyValues( aPropertyNames, aValues );
67 catch( const ::com::sun::star::uno::Exception& )
69 if ( !bUpdateThis )
70 ImplLockPropertyChangeNotifications( aPropertyNames, false );
72 if ( !bUpdateThis )
73 ImplLockPropertyChangeNotifications( aPropertyNames, false );
75 else
77 int dummy = 0;
78 (void)dummy;
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
85 if ( mxModel.is() )
87 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
88 if ( !bUpdateThis )
89 ImplLockPropertyChangeNotification( aPropertyName, true );
91 try
93 xPSet->setPropertyValue( aPropertyName, aValue );
95 catch( const com::sun::star::uno::Exception& )
97 if ( !bUpdateThis )
98 ImplLockPropertyChangeNotification( aPropertyName, false );
99 throw;
101 if ( !bUpdateThis )
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 );
109 if ( xPSet.is() )
110 return xPSet->getPropertyValue( aPropertyName );
111 else
112 return ::com::sun::star::uno::Any();
115 sal_Bool UnoControlBase::ImplGetPropertyValue_BOOL( sal_uInt16 nProp )
117 sal_Bool b = sal_False;
118 if ( mxModel.is() )
120 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
121 aVal >>= b;
123 return b;
126 sal_Int16 UnoControlBase::ImplGetPropertyValue_INT16( sal_uInt16 nProp )
128 sal_Int16 n = 0;
129 if ( mxModel.is() )
131 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
132 aVal >>= n;
134 return n;
137 sal_Int32 UnoControlBase::ImplGetPropertyValue_INT32( sal_uInt16 nProp )
139 sal_Int32 n = 0;
140 if ( mxModel.is() )
142 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
143 aVal >>= n;
145 return n;
148 double UnoControlBase::ImplGetPropertyValue_DOUBLE( sal_uInt16 nProp )
150 double n = 0;
151 if ( mxModel.is() )
153 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
154 aVal >>= n;
156 return n;
159 ::rtl::OUString UnoControlBase::ImplGetPropertyValue_UString( sal_uInt16 nProp )
161 ::rtl::OUString aStr;
162 if ( mxModel.is() )
164 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
165 aVal >>= aStr;
167 return aStr;
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!" );
175 if ( xP.is() )
177 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
178 if ( xL.is() )
179 aSz = xL->getMinimumSize();
181 if ( !getPeer().is() || ( getPeer() != xP ) )
182 xP->dispose();
184 return aSz;
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!" );
192 if ( xP.is() )
194 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
195 if ( xL.is() )
196 aSz = xL->getPreferredSize();
198 if ( !getPeer().is() || ( getPeer() != xP ) )
199 xP->dispose();
201 return aSz;
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!" );
209 if ( xP.is() )
211 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
212 if ( xL.is() )
213 aSz = xL->calcAdjustedSize( rNewSize );
215 if ( !getPeer().is() || ( getPeer() != xP ) )
216 xP->dispose();
218 return aSz;
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!" );
226 if ( xP.is() )
228 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
229 if ( xL.is() )
230 aSz = xL->getMinimumSize( nCols, nLines );
232 if ( !getPeer().is() || ( getPeer() != xP ) )
233 xP->dispose();
235 return aSz;
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!" );
242 if ( xP.is() )
244 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
245 if ( xL.is() )
246 xL->getColumnsAndLines( nCols, nLines );
248 if ( !getPeer().is() || ( getPeer() != xP ) )
249 xP->dispose();
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */