LibreOffice Module toolkit (master) 1
unocontrolbase.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
24
26#include <helper/property.hxx>
27
28#include <tools/debug.hxx>
29
30using namespace com::sun::star;
31
32
33
34
35bool UnoControlBase::ImplHasProperty( sal_uInt16 nPropId )
36{
37 const OUString& aPropName( GetPropertyName( nPropId ) );
38 return ImplHasProperty( aPropName );
39}
40
41bool UnoControlBase::ImplHasProperty( const OUString& aPropertyName )
42{
43 css::uno::Reference< css::beans::XPropertySet > xPSet( mxModel, css::uno::UNO_QUERY );
44 if ( !xPSet.is() )
45 return false;
46 css::uno::Reference< css::beans::XPropertySetInfo > xInfo = xPSet->getPropertySetInfo();
47 if ( !xInfo.is() )
48 return false;
49
50 return xInfo->hasPropertyByName( aPropertyName );
51}
52
53void UnoControlBase::ImplSetPropertyValues( const css::uno::Sequence< OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues, bool bUpdateThis )
54{
55 css::uno::Reference< css::beans::XMultiPropertySet > xMPS( mxModel, css::uno::UNO_QUERY );
56 if ( !mxModel.is() )
57 return;
58
59 DBG_ASSERT( xMPS.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" );
60 if ( !xMPS.is() )
61 return;
62
63 if ( !bUpdateThis )
64 ImplLockPropertyChangeNotifications( aPropertyNames, true );
65
66 try
67 {
68 xMPS->setPropertyValues( aPropertyNames, aValues );
69 }
70 catch( const css::uno::Exception& )
71 {
72 if ( !bUpdateThis )
73 ImplLockPropertyChangeNotifications( aPropertyNames, false );
74 }
75 if ( !bUpdateThis )
76 ImplLockPropertyChangeNotifications( aPropertyNames, false );
77}
78
79void UnoControlBase::ImplSetPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue, bool bUpdateThis )
80{
81 // Model might be logged off already but an event still fires
82 if ( !mxModel.is() )
83 return;
84
85 css::uno::Reference< css::beans::XPropertySet > xPSet( mxModel, css::uno::UNO_QUERY );
86 if ( !bUpdateThis )
87 ImplLockPropertyChangeNotification( aPropertyName, true );
88
89 try
90 {
91 xPSet->setPropertyValue( aPropertyName, aValue );
92 }
93 catch( const css::uno::Exception& )
94 {
95 if ( !bUpdateThis )
96 ImplLockPropertyChangeNotification( aPropertyName, false );
97 throw;
98 }
99 if ( !bUpdateThis )
100 ImplLockPropertyChangeNotification( aPropertyName, false );
101}
102
103css::uno::Any UnoControlBase::ImplGetPropertyValue( const OUString& aPropertyName ) const
104{
105 css::uno::Reference< css::beans::XPropertySet > xPSet( mxModel, css::uno::UNO_QUERY );
106 if ( xPSet.is() )
107 return xPSet->getPropertyValue( aPropertyName );
108 else
109 return css::uno::Any();
110}
111
112template <typename T> T UnoControlBase::ImplGetPropertyValuePOD( sal_uInt16 nProp )
113{
114 T t(0);
115 if ( mxModel.is() )
116 {
117 css::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
118 aVal >>= t;
119 }
120 return t;
121}
122
123template <typename T> T UnoControlBase::ImplGetPropertyValueClass( sal_uInt16 nProp )
124{
125 T t;
126 if ( mxModel.is() )
127 {
128 css::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
129 aVal >>= t;
130 }
131 return t;
132}
133
135{
136 return ImplGetPropertyValuePOD<bool>(nProp);
137}
138
140{
141 return ImplGetPropertyValuePOD<sal_Int16>(nProp);
142}
143
145{
146 return ImplGetPropertyValuePOD<sal_Int32>(nProp);
147}
148
150{
151 return ImplGetPropertyValuePOD<double>(nProp);
152}
153
155{
156 return ImplGetPropertyValueClass<OUString>(nProp);
157}
158
159util::Date UnoControlBase::ImplGetPropertyValue_Date( sal_uInt16 nProp )
160{
161 return ImplGetPropertyValueClass<util::Date>(nProp);
162}
163
164util::Time UnoControlBase::ImplGetPropertyValue_Time( sal_uInt16 nProp )
165{
166 return ImplGetPropertyValueClass<util::Time>(nProp);
167}
168
170{
171 css::awt::Size aSz;
172 css::uno::Reference< css::awt::XWindowPeer > xP = ImplGetCompatiblePeer();
173 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
174 if ( xP.is() )
175 {
176 css::uno::Reference< css::awt::XLayoutConstrains > xL( xP, css::uno::UNO_QUERY );
177 if ( xL.is() )
178 aSz = xL->getMinimumSize();
179
180 if ( !getPeer().is() || ( getPeer() != xP ) )
181 xP->dispose();
182 }
183 return aSz;
184}
185
187{
188 css::awt::Size aSz;
189 css::uno::Reference< css::awt::XWindowPeer > xP = ImplGetCompatiblePeer();
190 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
191 if ( xP.is() )
192 {
193 css::uno::Reference< css::awt::XLayoutConstrains > xL( xP, css::uno::UNO_QUERY );
194 if ( xL.is() )
195 aSz = xL->getPreferredSize();
196
197 if ( !getPeer().is() || ( getPeer() != xP ) )
198 xP->dispose();
199 }
200 return aSz;
201}
202
203css::awt::Size UnoControlBase::Impl_calcAdjustedSize( const css::awt::Size& rNewSize )
204{
205 css::awt::Size aSz;
206 css::uno::Reference< css::awt::XWindowPeer > xP = ImplGetCompatiblePeer();
207 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
208 if ( xP.is() )
209 {
210 css::uno::Reference< css::awt::XLayoutConstrains > xL( xP, css::uno::UNO_QUERY );
211 if ( xL.is() )
212 aSz = xL->calcAdjustedSize( rNewSize );
213
214 if ( !getPeer().is() || ( getPeer() != xP ) )
215 xP->dispose();
216 }
217 return aSz;
218}
219
220css::awt::Size UnoControlBase::Impl_getMinimumSize( sal_Int16 nCols, sal_Int16 nLines )
221{
222 css::awt::Size aSz;
223 css::uno::Reference< css::awt::XWindowPeer > xP = ImplGetCompatiblePeer();
224 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
225 if ( xP.is() )
226 {
227 css::uno::Reference< css::awt::XTextLayoutConstrains > xL( xP, css::uno::UNO_QUERY );
228 if ( xL.is() )
229 aSz = xL->getMinimumSize( nCols, nLines );
230
231 if ( !getPeer().is() || ( getPeer() != xP ) )
232 xP->dispose();
233 }
234 return aSz;
235}
236
237void UnoControlBase::Impl_getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines )
238{
239 css::uno::Reference< css::awt::XWindowPeer > xP = ImplGetCompatiblePeer();
240 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
241 if ( xP.is() )
242 {
243 css::uno::Reference< css::awt::XTextLayoutConstrains > xL( xP, css::uno::UNO_QUERY );
244 if ( xL.is() )
245 xL->getColumnsAndLines( nCols, nLines );
246
247 if ( !getPeer().is() || ( getPeer() != xP ) )
248 xP->dispose();
249 }
250}
251
252
253/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
sal_Int16 ImplGetPropertyValue_INT16(sal_uInt16 nProp)
double ImplGetPropertyValue_DOUBLE(sal_uInt16 nProp)
void Impl_getColumnsAndLines(sal_Int16 &nCols, sal_Int16 &nLines)
bool ImplHasProperty(sal_uInt16 nProp)
css::uno::Any ImplGetPropertyValue(const OUString &aPropertyName) const
void ImplSetPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue, bool bUpdateThis)
sal_Int32 ImplGetPropertyValue_INT32(sal_uInt16 nProp)
OUString ImplGetPropertyValue_UString(sal_uInt16 nProp)
css::awt::Size Impl_getMinimumSize()
void ImplSetPropertyValues(const css::uno::Sequence< OUString > &aPropertyNames, const css::uno::Sequence< css::uno::Any > &aValues, bool bUpdateThis)
css::util::Time ImplGetPropertyValue_Time(sal_uInt16 nProp)
T ImplGetPropertyValuePOD(sal_uInt16 nProp)
T ImplGetPropertyValueClass(sal_uInt16 nProp)
css::awt::Size Impl_calcAdjustedSize(const css::awt::Size &rNewSize)
css::awt::Size Impl_getPreferredSize()
css::util::Date ImplGetPropertyValue_Date(sal_uInt16 nProp)
bool ImplGetPropertyValue_BOOL(sal_uInt16 nProp)
css::uno::Reference< css::awt::XVclWindowPeer > ImplGetCompatiblePeer()
Definition: unocontrol.cxx:160
css::uno::Reference< css::awt::XControlModel > mxModel
Definition: unocontrol.hxx:93
void ImplLockPropertyChangeNotification(const OUString &rPropertyName, bool bLock)
Definition: unocontrol.cxx:434
css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getPeer() override
void ImplLockPropertyChangeNotifications(const css::uno::Sequence< OUString > &rPropertyNames, bool bLock)
Definition: unocontrol.cxx:455
#define DBG_ASSERT(sCon, aError)
OUString aPropName
const OUString & GetPropertyName(sal_uInt16 nPropertyId)
Definition: property.cxx:295