1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_toolkit.hxx"
26 #include <com/sun/star/awt/XLayoutConstrains.hpp>
27 #include <com/sun/star/awt/XTextLayoutConstrains.hpp>
28
29 #include <toolkit/controls/unocontrolbase.hxx>
30 #include <toolkit/helper/property.hxx>
31 #include <comphelper/processfactory.hxx>
32
33 #include <tools/debug.hxx>
34
35 // ----------------------------------------------------
36 // class UnoControlBase
37 // ----------------------------------------------------
38
UnoControlBase()39 UnoControlBase::UnoControlBase()
40 :UnoControl( ::comphelper::getProcessServiceFactory() )
41 {
42 OSL_ENSURE( false, "UnoControlBase::UnoControlBase: not implemented. Well, not really." );
43 // just implemented to let the various FooImplInheritanceHelper compile, you should use the
44 // version taking a service factory
45 }
46
ImplHasProperty(sal_uInt16 nPropId)47 sal_Bool UnoControlBase::ImplHasProperty( sal_uInt16 nPropId )
48 {
49 ::rtl::OUString aPropName( GetPropertyName( nPropId ) );
50 return ImplHasProperty( aPropName );
51 }
52
ImplHasProperty(const::rtl::OUString & aPropertyName)53 sal_Bool UnoControlBase::ImplHasProperty( const ::rtl::OUString& aPropertyName )
54 {
55 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
56 if ( !xPSet.is() )
57 return sal_False;
58 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo = xPSet->getPropertySetInfo();
59 if ( !xInfo.is() )
60 return sal_False;
61
62 return xInfo->hasPropertyByName( aPropertyName );
63 }
64
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)65 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 )
66 {
67 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet > xMPS( mxModel, ::com::sun::star::uno::UNO_QUERY );
68 if ( !mxModel.is() )
69 return;
70
71 DBG_ASSERT( xMPS.is(), "UnoControlBase::ImplSetPropertyValues: no multi property set interface!" );
72 if ( xMPS.is() )
73 {
74 if ( !bUpdateThis )
75 ImplLockPropertyChangeNotifications( aPropertyNames, true );
76
77 try
78 {
79 xMPS->setPropertyValues( aPropertyNames, aValues );
80 }
81 catch( const ::com::sun::star::uno::Exception& )
82 {
83 if ( !bUpdateThis )
84 ImplLockPropertyChangeNotifications( aPropertyNames, false );
85 }
86 if ( !bUpdateThis )
87 ImplLockPropertyChangeNotifications( aPropertyNames, false );
88 }
89 else
90 {
91 int dummy = 0;
92 (void)dummy;
93 }
94 }
95
ImplSetPropertyValue(const::rtl::OUString & aPropertyName,const::com::sun::star::uno::Any & aValue,sal_Bool bUpdateThis)96 void UnoControlBase::ImplSetPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue, sal_Bool bUpdateThis )
97 {
98 // Model ggf. schon abgemeldet, aber ein Event schlaegt noch zu...
99 if ( mxModel.is() )
100 {
101 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
102 if ( !bUpdateThis )
103 ImplLockPropertyChangeNotification( aPropertyName, true );
104
105 try
106 {
107 xPSet->setPropertyValue( aPropertyName, aValue );
108 }
109 catch( const com::sun::star::uno::Exception& )
110 {
111 if ( !bUpdateThis )
112 ImplLockPropertyChangeNotification( aPropertyName, false );
113 throw;
114 }
115 if ( !bUpdateThis )
116 ImplLockPropertyChangeNotification( aPropertyName, false );
117 }
118 }
119
ImplGetPropertyValue(const::rtl::OUString & aPropertyName)120 ::com::sun::star::uno::Any UnoControlBase::ImplGetPropertyValue( const ::rtl::OUString& aPropertyName )
121 {
122 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPSet( mxModel, ::com::sun::star::uno::UNO_QUERY );
123 if ( xPSet.is() )
124 return xPSet->getPropertyValue( aPropertyName );
125 else
126 return ::com::sun::star::uno::Any();
127 }
128
ImplGetPropertyValue_BOOL(sal_uInt16 nProp)129 sal_Bool UnoControlBase::ImplGetPropertyValue_BOOL( sal_uInt16 nProp )
130 {
131 sal_Bool b = sal_False;
132 if ( mxModel.is() )
133 {
134 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
135 aVal >>= b;
136 }
137 return b;
138 }
139
ImplGetPropertyValue_INT16(sal_uInt16 nProp)140 sal_Int16 UnoControlBase::ImplGetPropertyValue_INT16( sal_uInt16 nProp )
141 {
142 sal_Int16 n = 0;
143 if ( mxModel.is() )
144 {
145 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
146 aVal >>= n;
147 }
148 return n;
149 }
150
ImplGetPropertyValue_UINT16(sal_uInt16 nProp)151 sal_uInt16 UnoControlBase::ImplGetPropertyValue_UINT16( sal_uInt16 nProp )
152 {
153 sal_uInt16 n = 0;
154 if ( mxModel.is() )
155 {
156 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
157 aVal >>= n;
158 }
159 return n;
160 }
161
ImplGetPropertyValue_INT32(sal_uInt16 nProp)162 sal_Int32 UnoControlBase::ImplGetPropertyValue_INT32( sal_uInt16 nProp )
163 {
164 sal_Int32 n = 0;
165 if ( mxModel.is() )
166 {
167 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
168 aVal >>= n;
169 }
170 return n;
171 }
172
ImplGetPropertyValue_UINT32(sal_uInt16 nProp)173 sal_uInt32 UnoControlBase::ImplGetPropertyValue_UINT32( sal_uInt16 nProp )
174 {
175 sal_uInt32 n = 0;
176 if ( mxModel.is() )
177 {
178 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
179 aVal >>= n;
180 }
181 return n;
182 }
183
ImplGetPropertyValue_DOUBLE(sal_uInt16 nProp)184 double UnoControlBase::ImplGetPropertyValue_DOUBLE( sal_uInt16 nProp )
185 {
186 double n = 0;
187 if ( mxModel.is() )
188 {
189 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
190 aVal >>= n;
191 }
192 return n;
193 }
194
ImplGetPropertyValue_UString(sal_uInt16 nProp)195 ::rtl::OUString UnoControlBase::ImplGetPropertyValue_UString( sal_uInt16 nProp )
196 {
197 ::rtl::OUString aStr;
198 if ( mxModel.is() )
199 {
200 ::com::sun::star::uno::Any aVal = ImplGetPropertyValue( GetPropertyName( nProp ) );
201 aVal >>= aStr;
202 }
203 return aStr;
204 }
205
Impl_getMinimumSize()206 ::com::sun::star::awt::Size UnoControlBase::Impl_getMinimumSize()
207 {
208 ::com::sun::star::awt::Size aSz;
209 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
210 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
211 if ( xP.is() )
212 {
213 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
214 if ( xL.is() )
215 aSz = xL->getMinimumSize();
216
217 if ( !getPeer().is() || ( getPeer() != xP ) )
218 xP->dispose();
219 }
220 return aSz;
221 }
222
Impl_getPreferredSize()223 ::com::sun::star::awt::Size UnoControlBase::Impl_getPreferredSize()
224 {
225 ::com::sun::star::awt::Size aSz;
226 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
227 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
228 if ( xP.is() )
229 {
230 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
231 if ( xL.is() )
232 aSz = xL->getPreferredSize();
233
234 if ( !getPeer().is() || ( getPeer() != xP ) )
235 xP->dispose();
236 }
237 return aSz;
238 }
239
Impl_calcAdjustedSize(const::com::sun::star::awt::Size & rNewSize)240 ::com::sun::star::awt::Size UnoControlBase::Impl_calcAdjustedSize( const ::com::sun::star::awt::Size& rNewSize )
241 {
242 ::com::sun::star::awt::Size aSz;
243 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
244 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
245 if ( xP.is() )
246 {
247 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
248 if ( xL.is() )
249 aSz = xL->calcAdjustedSize( rNewSize );
250
251 if ( !getPeer().is() || ( getPeer() != xP ) )
252 xP->dispose();
253 }
254 return aSz;
255 }
256
Impl_getMinimumSize(sal_Int16 nCols,sal_Int16 nLines)257 ::com::sun::star::awt::Size UnoControlBase::Impl_getMinimumSize( sal_Int16 nCols, sal_Int16 nLines )
258 {
259 ::com::sun::star::awt::Size aSz;
260 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
261 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
262 if ( xP.is() )
263 {
264 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
265 if ( xL.is() )
266 aSz = xL->getMinimumSize( nCols, nLines );
267
268 if ( !getPeer().is() || ( getPeer() != xP ) )
269 xP->dispose();
270 }
271 return aSz;
272 }
273
Impl_getColumnsAndLines(sal_Int16 & nCols,sal_Int16 & nLines)274 void UnoControlBase::Impl_getColumnsAndLines( sal_Int16& nCols, sal_Int16& nLines )
275 {
276 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xP = ImplGetCompatiblePeer( sal_True );
277 DBG_ASSERT( xP.is(), "Layout: No Peer!" );
278 if ( xP.is() )
279 {
280 ::com::sun::star::uno::Reference< ::com::sun::star::awt::XTextLayoutConstrains > xL( xP, ::com::sun::star::uno::UNO_QUERY );
281 if ( xL.is() )
282 xL->getColumnsAndLines( nCols, nLines );
283
284 if ( !getPeer().is() || ( getPeer() != xP ) )
285 xP->dispose();
286 }
287 }
288
289
290
291