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