Bump for 3.6-28
[LibreOffice.git] / extensions / source / propctrlr / editpropertyhandler.cxx
blob79c319c65ecd3dc4d603954ce6bd0decf96fcbf4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "editpropertyhandler.hxx"
30 #include "formstrings.hxx"
31 #include "formmetadata.hxx"
33 /** === begin UNO includes === **/
34 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
35 /** === end UNO includes === **/
36 #include <tools/debug.hxx>
38 #define TEXTTYPE_SINGLELINE 0
39 #define TEXTTYPE_MULTILINE 1
40 #define TEXTTYPE_RICHTEXT 2
42 //------------------------------------------------------------------------
43 extern "C" void SAL_CALL createRegistryInfo_EditPropertyHandler()
45 ::pcr::EditPropertyHandler::registerImplementation();
48 //........................................................................
49 namespace pcr
51 //........................................................................
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::lang;
55 using namespace ::com::sun::star::beans;
56 using namespace ::com::sun::star::script;
57 using namespace ::com::sun::star::frame;
58 using namespace ::com::sun::star::inspection;
60 //====================================================================
61 //= EditPropertyHandler
62 //====================================================================
63 DBG_NAME( EditPropertyHandler )
64 //--------------------------------------------------------------------
65 EditPropertyHandler::EditPropertyHandler( const Reference< XComponentContext >& _rxContext )
66 :EditPropertyHandler_Base( _rxContext )
68 DBG_CTOR( EditPropertyHandler, NULL );
71 //--------------------------------------------------------------------
72 EditPropertyHandler::~EditPropertyHandler( )
74 DBG_DTOR( EditPropertyHandler, NULL );
77 //--------------------------------------------------------------------
78 ::rtl::OUString SAL_CALL EditPropertyHandler::getImplementationName_static( ) throw (RuntimeException)
80 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.EditPropertyHandler" ) );
83 //--------------------------------------------------------------------
84 Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
86 Sequence< ::rtl::OUString > aSupported( 1 );
87 aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.EditPropertyHandler" ) );
88 return aSupported;
91 //--------------------------------------------------------------------
92 Any SAL_CALL EditPropertyHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
94 ::osl::MutexGuard aGuard( m_aMutex );
95 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
97 Any aReturn;
98 try
100 switch ( nPropId )
102 case PROPERTY_ID_SHOW_SCROLLBARS:
104 sal_Bool bHasVScroll = sal_False;
105 m_xComponent->getPropertyValue( PROPERTY_VSCROLL ) >>= bHasVScroll;
106 sal_Bool bHasHScroll = sal_False;
107 m_xComponent->getPropertyValue( PROPERTY_HSCROLL ) >>= bHasHScroll;
109 aReturn <<= (sal_Int32)( ( bHasVScroll ? 2 : 0 ) + ( bHasHScroll ? 1 : 0 ) );
111 break;
113 case PROPERTY_ID_TEXTTYPE:
115 sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
116 sal_Bool bRichText = sal_False;
117 OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_RICHTEXT ) >>= bRichText );
118 if ( bRichText )
119 nTextType = TEXTTYPE_RICHTEXT;
120 else
122 sal_Bool bMultiLine = sal_False;
123 OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_MULTILINE ) >>= bMultiLine );
124 if ( bMultiLine )
125 nTextType = TEXTTYPE_MULTILINE;
126 else
127 nTextType = TEXTTYPE_SINGLELINE;
129 aReturn <<= nTextType;
131 break;
134 default:
135 OSL_FAIL( "EditPropertyHandler::getPropertyValue: cannot handle this property!" );
136 break;
139 catch( const Exception& )
141 OSL_FAIL( "EditPropertyHandler::getPropertyValue: caught an exception!" );
144 return aReturn;
147 //--------------------------------------------------------------------
148 void SAL_CALL EditPropertyHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
150 ::osl::MutexGuard aGuard( m_aMutex );
151 PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
155 switch ( nPropId )
157 case PROPERTY_ID_SHOW_SCROLLBARS:
159 sal_Int32 nScrollbars = 0;
160 _rValue >>= nScrollbars;
162 sal_Bool bHasVScroll = 0 != ( nScrollbars & 2 );
163 sal_Bool bHasHScroll = 0 != ( nScrollbars & 1 );
165 m_xComponent->setPropertyValue( PROPERTY_VSCROLL, makeAny( (sal_Bool)bHasVScroll ) );
166 m_xComponent->setPropertyValue( PROPERTY_HSCROLL, makeAny( (sal_Bool)bHasHScroll ) );
168 break;
170 case PROPERTY_ID_TEXTTYPE:
172 sal_Bool bMultiLine = sal_False;
173 sal_Bool bRichText = sal_False;
174 sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
175 OSL_VERIFY( _rValue >>= nTextType );
176 switch ( nTextType )
178 case TEXTTYPE_SINGLELINE: bMultiLine = bRichText = sal_False; break;
179 case TEXTTYPE_MULTILINE: bMultiLine = sal_True; bRichText = sal_False; break;
180 case TEXTTYPE_RICHTEXT: bMultiLine = sal_True; bRichText = sal_True; break;
181 default:
182 OSL_FAIL( "EditPropertyHandler::setPropertyValue: invalid text type!" );
185 m_xComponent->setPropertyValue( PROPERTY_MULTILINE, makeAny( bMultiLine ) );
186 m_xComponent->setPropertyValue( PROPERTY_RICHTEXT, makeAny( bRichText ) );
188 break;
190 default:
191 OSL_FAIL( "EditPropertyHandler::setPropertyValue: cannot handle this id!" );
194 catch( const Exception& )
196 OSL_FAIL( "EditPropertyHandler::setPropertyValue: caught an exception!" );
200 //--------------------------------------------------------------------
201 bool EditPropertyHandler::implHaveBothScrollBarProperties() const
203 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
204 Reference< XPropertySetInfo > xPSI;
205 if ( m_xComponent.is() )
206 xPSI = m_xComponent->getPropertySetInfo();
208 return xPSI.is()
209 && xPSI->hasPropertyByName( PROPERTY_HSCROLL )
210 && xPSI->hasPropertyByName( PROPERTY_VSCROLL );
213 //--------------------------------------------------------------------
214 bool EditPropertyHandler::implHaveTextTypeProperty() const
216 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
217 Reference< XPropertySetInfo > xPSI;
218 if ( m_xComponent.is() )
219 xPSI = m_xComponent->getPropertySetInfo();
221 return xPSI.is()
222 && xPSI->hasPropertyByName( PROPERTY_RICHTEXT )
223 && xPSI->hasPropertyByName( PROPERTY_MULTILINE );
226 //--------------------------------------------------------------------
227 Sequence< Property > SAL_CALL EditPropertyHandler::doDescribeSupportedProperties() const
229 ::std::vector< Property > aProperties;
231 if ( implHaveBothScrollBarProperties() )
232 addInt32PropertyDescription( aProperties, PROPERTY_SHOW_SCROLLBARS );
234 if ( implHaveTextTypeProperty() )
235 addInt32PropertyDescription( aProperties, PROPERTY_TEXTTYPE );
237 if ( aProperties.empty() )
238 return Sequence< Property >();
239 return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
242 //--------------------------------------------------------------------
243 Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupersededProperties( ) throw (RuntimeException)
245 ::osl::MutexGuard aGuard( m_aMutex );
246 ::std::vector< ::rtl::OUString > aSuperseded;
247 if ( implHaveBothScrollBarProperties() )
249 aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_HSCROLL) );
250 aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_VSCROLL) );
252 if ( implHaveTextTypeProperty() )
254 aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_RICHTEXT) );
255 aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_MULTILINE) );
257 if ( aSuperseded.empty() )
258 return Sequence< ::rtl::OUString >();
259 return Sequence< ::rtl::OUString >( &(*aSuperseded.begin()), aSuperseded.size() );
262 //--------------------------------------------------------------------
263 Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getActuatingProperties( ) throw (RuntimeException)
265 ::osl::MutexGuard aGuard( m_aMutex );
266 ::std::vector< ::rtl::OUString > aInterestingActuatingProps;
267 if ( implHaveTextTypeProperty() )
268 aInterestingActuatingProps.push_back( static_cast<const rtl::OUString&>(PROPERTY_TEXTTYPE) );
269 aInterestingActuatingProps.push_back( static_cast<const rtl::OUString&>(PROPERTY_MULTILINE) );
270 return Sequence< ::rtl::OUString >( &(*aInterestingActuatingProps.begin()), aInterestingActuatingProps.size() );
273 //--------------------------------------------------------------------
274 void SAL_CALL EditPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool ) throw (NullPointerException, RuntimeException)
276 if ( !_rxInspectorUI.is() )
277 throw NullPointerException();
279 ::osl::MutexGuard aGuard( m_aMutex );
280 PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
281 switch ( nActuatingPropId )
283 case PROPERTY_ID_TEXTTYPE:
285 sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
286 getPropertyValue( PROPERTY_TEXTTYPE ) >>= nTextType;
288 if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_WORDBREAK ) )
289 _rxInspectorUI->enablePropertyUI( PROPERTY_WORDBREAK, nTextType == TEXTTYPE_RICHTEXT );
290 _rxInspectorUI->enablePropertyUI( PROPERTY_MAXTEXTLEN, nTextType != TEXTTYPE_RICHTEXT );
291 _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, nTextType == TEXTTYPE_SINGLELINE );
292 _rxInspectorUI->enablePropertyUI( PROPERTY_FONT, nTextType != TEXTTYPE_RICHTEXT );
293 _rxInspectorUI->enablePropertyUI( PROPERTY_ALIGN, nTextType != TEXTTYPE_RICHTEXT );
294 _rxInspectorUI->enablePropertyUI( PROPERTY_DEFAULT_TEXT, nTextType != TEXTTYPE_RICHTEXT );
295 _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, nTextType != TEXTTYPE_SINGLELINE );
296 _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, nTextType != TEXTTYPE_SINGLELINE );
297 _rxInspectorUI->enablePropertyUI( PROPERTY_VERTICAL_ALIGN, nTextType == TEXTTYPE_SINGLELINE );
299 _rxInspectorUI->showCategory( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Data" ) ), nTextType != TEXTTYPE_RICHTEXT );
301 break;
303 case PROPERTY_ID_MULTILINE:
305 sal_Bool bIsMultiline = sal_False;
306 _rNewValue >>= bIsMultiline;
308 _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, bIsMultiline );
309 _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, !bIsMultiline );
310 _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, bIsMultiline );
312 break;
314 default:
315 OSL_FAIL( "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
319 //........................................................................
320 } // namespace pcr
321 //........................................................................
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */