merge the formfield patch from ooo-build
[ooovba.git] / extensions / source / propctrlr / editpropertyhandler.cxx
blobb78ee1355489d2d422baab48f8cde38bea6607d4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editpropertyhandler.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "editpropertyhandler.hxx"
34 #include "formstrings.hxx"
35 #include "formmetadata.hxx"
37 /** === begin UNO includes === **/
38 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
39 /** === end UNO includes === **/
40 #include <tools/debug.hxx>
42 #define TEXTTYPE_SINGLELINE 0
43 #define TEXTTYPE_MULTILINE 1
44 #define TEXTTYPE_RICHTEXT 2
46 //------------------------------------------------------------------------
47 extern "C" void SAL_CALL createRegistryInfo_EditPropertyHandler()
49 ::pcr::EditPropertyHandler::registerImplementation();
52 //........................................................................
53 namespace pcr
55 //........................................................................
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::lang;
59 using namespace ::com::sun::star::beans;
60 using namespace ::com::sun::star::script;
61 using namespace ::com::sun::star::frame;
62 using namespace ::com::sun::star::inspection;
64 //====================================================================
65 //= EditPropertyHandler
66 //====================================================================
67 DBG_NAME( EditPropertyHandler )
68 //--------------------------------------------------------------------
69 EditPropertyHandler::EditPropertyHandler( const Reference< XComponentContext >& _rxContext )
70 :EditPropertyHandler_Base( _rxContext )
72 DBG_CTOR( EditPropertyHandler, NULL );
75 //--------------------------------------------------------------------
76 EditPropertyHandler::~EditPropertyHandler( )
78 DBG_DTOR( EditPropertyHandler, NULL );
81 //--------------------------------------------------------------------
82 ::rtl::OUString SAL_CALL EditPropertyHandler::getImplementationName_static( ) throw (RuntimeException)
84 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.EditPropertyHandler" ) );
87 //--------------------------------------------------------------------
88 Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
90 Sequence< ::rtl::OUString > aSupported( 1 );
91 aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.EditPropertyHandler" ) );
92 return aSupported;
95 //--------------------------------------------------------------------
96 Any SAL_CALL EditPropertyHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
98 ::osl::MutexGuard aGuard( m_aMutex );
99 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
101 Any aReturn;
104 switch ( nPropId )
106 case PROPERTY_ID_SHOW_SCROLLBARS:
108 sal_Bool bHasVScroll = sal_False;
109 m_xComponent->getPropertyValue( PROPERTY_VSCROLL ) >>= bHasVScroll;
110 sal_Bool bHasHScroll = sal_False;
111 m_xComponent->getPropertyValue( PROPERTY_HSCROLL ) >>= bHasHScroll;
113 aReturn <<= (sal_Int32)( ( bHasVScroll ? 2 : 0 ) + ( bHasHScroll ? 1 : 0 ) );
115 break;
117 case PROPERTY_ID_TEXTTYPE:
119 sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
120 sal_Bool bRichText = sal_False;
121 OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_RICHTEXT ) >>= bRichText );
122 if ( bRichText )
123 nTextType = TEXTTYPE_RICHTEXT;
124 else
126 sal_Bool bMultiLine = sal_False;
127 OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_MULTILINE ) >>= bMultiLine );
128 if ( bMultiLine )
129 nTextType = TEXTTYPE_MULTILINE;
130 else
131 nTextType = TEXTTYPE_SINGLELINE;
133 aReturn <<= nTextType;
135 break;
138 default:
139 DBG_ERROR( "EditPropertyHandler::getPropertyValue: cannot handle this property!" );
140 break;
143 catch( const Exception& )
145 OSL_ENSURE( sal_False, "EditPropertyHandler::getPropertyValue: caught an exception!" );
148 return aReturn;
151 //--------------------------------------------------------------------
152 void SAL_CALL EditPropertyHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
154 ::osl::MutexGuard aGuard( m_aMutex );
155 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
159 switch ( nPropId )
161 case PROPERTY_ID_SHOW_SCROLLBARS:
163 sal_Int32 nScrollbars = 0;
164 _rValue >>= nScrollbars;
166 sal_Bool bHasVScroll = 0 != ( nScrollbars & 2 );
167 sal_Bool bHasHScroll = 0 != ( nScrollbars & 1 );
169 m_xComponent->setPropertyValue( PROPERTY_VSCROLL, makeAny( (sal_Bool)bHasVScroll ) );
170 m_xComponent->setPropertyValue( PROPERTY_HSCROLL, makeAny( (sal_Bool)bHasHScroll ) );
172 break;
174 case PROPERTY_ID_TEXTTYPE:
176 sal_Bool bMultiLine = sal_False;
177 sal_Bool bRichText = sal_False;
178 sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
179 OSL_VERIFY( _rValue >>= nTextType );
180 switch ( nTextType )
182 case TEXTTYPE_SINGLELINE: bMultiLine = bRichText = sal_False; break;
183 case TEXTTYPE_MULTILINE: bMultiLine = sal_True; bRichText = sal_False; break;
184 case TEXTTYPE_RICHTEXT: bMultiLine = sal_True; bRichText = sal_True; break;
185 default:
186 OSL_ENSURE( sal_False, "EditPropertyHandler::setPropertyValue: invalid text type!" );
189 m_xComponent->setPropertyValue( PROPERTY_MULTILINE, makeAny( bMultiLine ) );
190 m_xComponent->setPropertyValue( PROPERTY_RICHTEXT, makeAny( bRichText ) );
192 break;
194 default:
195 OSL_ENSURE( sal_False, "EditPropertyHandler::setPropertyValue: cannot handle this id!" );
198 catch( const Exception& )
200 OSL_ENSURE( sal_False, "EditPropertyHandler::setPropertyValue: caught an exception!" );
204 //--------------------------------------------------------------------
205 bool EditPropertyHandler::implHaveBothScrollBarProperties() const
207 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
208 Reference< XPropertySetInfo > xPSI;
209 if ( m_xComponent.is() )
210 xPSI = m_xComponent->getPropertySetInfo();
212 return xPSI.is()
213 && xPSI->hasPropertyByName( PROPERTY_HSCROLL )
214 && xPSI->hasPropertyByName( PROPERTY_VSCROLL );
217 //--------------------------------------------------------------------
218 bool EditPropertyHandler::implHaveTextTypeProperty() const
220 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
221 Reference< XPropertySetInfo > xPSI;
222 if ( m_xComponent.is() )
223 xPSI = m_xComponent->getPropertySetInfo();
225 return xPSI.is()
226 && xPSI->hasPropertyByName( PROPERTY_RICHTEXT )
227 && xPSI->hasPropertyByName( PROPERTY_MULTILINE );
230 //--------------------------------------------------------------------
231 Sequence< Property > SAL_CALL EditPropertyHandler::doDescribeSupportedProperties() const
233 ::std::vector< Property > aProperties;
235 if ( implHaveBothScrollBarProperties() )
236 addInt32PropertyDescription( aProperties, PROPERTY_SHOW_SCROLLBARS );
238 if ( implHaveTextTypeProperty() )
239 addInt32PropertyDescription( aProperties, PROPERTY_TEXTTYPE );
241 if ( aProperties.empty() )
242 return Sequence< Property >();
243 return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
246 //--------------------------------------------------------------------
247 Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupersededProperties( ) throw (RuntimeException)
249 ::osl::MutexGuard aGuard( m_aMutex );
250 ::std::vector< ::rtl::OUString > aSuperseded;
251 if ( implHaveBothScrollBarProperties() )
253 aSuperseded.push_back( PROPERTY_HSCROLL );
254 aSuperseded.push_back( PROPERTY_VSCROLL );
256 if ( implHaveTextTypeProperty() )
258 aSuperseded.push_back( PROPERTY_RICHTEXT );
259 aSuperseded.push_back( PROPERTY_MULTILINE );
261 if ( aSuperseded.empty() )
262 return Sequence< ::rtl::OUString >();
263 return Sequence< ::rtl::OUString >( &(*aSuperseded.begin()), aSuperseded.size() );
266 //--------------------------------------------------------------------
267 Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getActuatingProperties( ) throw (RuntimeException)
269 ::osl::MutexGuard aGuard( m_aMutex );
270 ::std::vector< ::rtl::OUString > aInterestingActuatingProps;
271 if ( implHaveTextTypeProperty() )
272 aInterestingActuatingProps.push_back( PROPERTY_TEXTTYPE );
273 aInterestingActuatingProps.push_back( PROPERTY_MULTILINE );
274 return Sequence< ::rtl::OUString >( &(*aInterestingActuatingProps.begin()), aInterestingActuatingProps.size() );;
277 //--------------------------------------------------------------------
278 void SAL_CALL EditPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool ) throw (NullPointerException, RuntimeException)
280 if ( !_rxInspectorUI.is() )
281 throw NullPointerException();
283 ::osl::MutexGuard aGuard( m_aMutex );
284 PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
285 switch ( nActuatingPropId )
287 case PROPERTY_ID_TEXTTYPE:
289 sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
290 getPropertyValue( PROPERTY_TEXTTYPE ) >>= nTextType;
292 if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_WORDBREAK ) )
293 _rxInspectorUI->enablePropertyUI( PROPERTY_WORDBREAK, nTextType == TEXTTYPE_RICHTEXT );
294 _rxInspectorUI->enablePropertyUI( PROPERTY_MAXTEXTLEN, nTextType != TEXTTYPE_RICHTEXT );
295 _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, nTextType == TEXTTYPE_SINGLELINE );
296 _rxInspectorUI->enablePropertyUI( PROPERTY_FONT, nTextType != TEXTTYPE_RICHTEXT );
297 _rxInspectorUI->enablePropertyUI( PROPERTY_ALIGN, nTextType != TEXTTYPE_RICHTEXT );
298 _rxInspectorUI->enablePropertyUI( PROPERTY_DEFAULT_TEXT, nTextType != TEXTTYPE_RICHTEXT );
299 _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, nTextType != TEXTTYPE_SINGLELINE );
300 _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, nTextType != TEXTTYPE_SINGLELINE );
302 _rxInspectorUI->showCategory( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Data" ) ), nTextType != TEXTTYPE_RICHTEXT );
304 break;
306 case PROPERTY_ID_MULTILINE:
308 sal_Bool bIsMultiline = sal_False;
309 _rNewValue >>= bIsMultiline;
311 _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, bIsMultiline );
312 _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, !bIsMultiline );
313 _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, bIsMultiline );
315 break;
317 default:
318 OSL_ENSURE( sal_False, "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
322 //........................................................................
323 } // namespace pcr
324 //........................................................................