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