1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "editpropertyhandler.hxx"
31 #include "formstrings.hxx"
32 #include "formmetadata.hxx"
34 /** === begin UNO includes === **/
35 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
36 /** === end UNO includes === **/
37 #include <tools/debug.hxx>
39 #define TEXTTYPE_SINGLELINE 0
40 #define TEXTTYPE_MULTILINE 1
41 #define TEXTTYPE_RICHTEXT 2
43 //------------------------------------------------------------------------
44 extern "C" void SAL_CALL
createRegistryInfo_EditPropertyHandler()
46 ::pcr::EditPropertyHandler::registerImplementation();
49 //........................................................................
52 //........................................................................
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::lang
;
56 using namespace ::com::sun::star::beans
;
57 using namespace ::com::sun::star::script
;
58 using namespace ::com::sun::star::frame
;
59 using namespace ::com::sun::star::inspection
;
61 //====================================================================
62 //= EditPropertyHandler
63 //====================================================================
64 DBG_NAME( EditPropertyHandler
)
65 //--------------------------------------------------------------------
66 EditPropertyHandler::EditPropertyHandler( const Reference
< XComponentContext
>& _rxContext
)
67 :EditPropertyHandler_Base( _rxContext
)
69 DBG_CTOR( EditPropertyHandler
, NULL
);
72 //--------------------------------------------------------------------
73 EditPropertyHandler::~EditPropertyHandler( )
75 DBG_DTOR( EditPropertyHandler
, NULL
);
78 //--------------------------------------------------------------------
79 ::rtl::OUString SAL_CALL
EditPropertyHandler::getImplementationName_static( ) throw (RuntimeException
)
81 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.EditPropertyHandler" ) );
84 //--------------------------------------------------------------------
85 Sequence
< ::rtl::OUString
> SAL_CALL
EditPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException
)
87 Sequence
< ::rtl::OUString
> aSupported( 1 );
88 aSupported
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.EditPropertyHandler" ) );
92 //--------------------------------------------------------------------
93 Any SAL_CALL
EditPropertyHandler::getPropertyValue( const ::rtl::OUString
& _rPropertyName
) throw (UnknownPropertyException
, RuntimeException
)
95 ::osl::MutexGuard
aGuard( m_aMutex
);
96 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
103 case PROPERTY_ID_SHOW_SCROLLBARS
:
105 sal_Bool bHasVScroll
= sal_False
;
106 m_xComponent
->getPropertyValue( PROPERTY_VSCROLL
) >>= bHasVScroll
;
107 sal_Bool bHasHScroll
= sal_False
;
108 m_xComponent
->getPropertyValue( PROPERTY_HSCROLL
) >>= bHasHScroll
;
110 aReturn
<<= (sal_Int32
)( ( bHasVScroll
? 2 : 0 ) + ( bHasHScroll
? 1 : 0 ) );
114 case PROPERTY_ID_TEXTTYPE
:
116 sal_Int32 nTextType
= TEXTTYPE_SINGLELINE
;
117 sal_Bool bRichText
= sal_False
;
118 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_RICHTEXT
) >>= bRichText
);
120 nTextType
= TEXTTYPE_RICHTEXT
;
123 sal_Bool bMultiLine
= sal_False
;
124 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_MULTILINE
) >>= bMultiLine
);
126 nTextType
= TEXTTYPE_MULTILINE
;
128 nTextType
= TEXTTYPE_SINGLELINE
;
130 aReturn
<<= nTextType
;
136 DBG_ERROR( "EditPropertyHandler::getPropertyValue: cannot handle this property!" );
140 catch( const Exception
& )
142 OSL_ENSURE( sal_False
, "EditPropertyHandler::getPropertyValue: caught an exception!" );
148 //--------------------------------------------------------------------
149 void SAL_CALL
EditPropertyHandler::setPropertyValue( const ::rtl::OUString
& _rPropertyName
, const Any
& _rValue
) throw (UnknownPropertyException
, RuntimeException
)
151 ::osl::MutexGuard
aGuard( m_aMutex
);
152 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
158 case PROPERTY_ID_SHOW_SCROLLBARS
:
160 sal_Int32 nScrollbars
= 0;
161 _rValue
>>= nScrollbars
;
163 sal_Bool bHasVScroll
= 0 != ( nScrollbars
& 2 );
164 sal_Bool bHasHScroll
= 0 != ( nScrollbars
& 1 );
166 m_xComponent
->setPropertyValue( PROPERTY_VSCROLL
, makeAny( (sal_Bool
)bHasVScroll
) );
167 m_xComponent
->setPropertyValue( PROPERTY_HSCROLL
, makeAny( (sal_Bool
)bHasHScroll
) );
171 case PROPERTY_ID_TEXTTYPE
:
173 sal_Bool bMultiLine
= sal_False
;
174 sal_Bool bRichText
= sal_False
;
175 sal_Int32 nTextType
= TEXTTYPE_SINGLELINE
;
176 OSL_VERIFY( _rValue
>>= nTextType
);
179 case TEXTTYPE_SINGLELINE
: bMultiLine
= bRichText
= sal_False
; break;
180 case TEXTTYPE_MULTILINE
: bMultiLine
= sal_True
; bRichText
= sal_False
; break;
181 case TEXTTYPE_RICHTEXT
: bMultiLine
= sal_True
; bRichText
= sal_True
; break;
183 OSL_ENSURE( sal_False
, "EditPropertyHandler::setPropertyValue: invalid text type!" );
186 m_xComponent
->setPropertyValue( PROPERTY_MULTILINE
, makeAny( bMultiLine
) );
187 m_xComponent
->setPropertyValue( PROPERTY_RICHTEXT
, makeAny( bRichText
) );
192 OSL_ENSURE( sal_False
, "EditPropertyHandler::setPropertyValue: cannot handle this id!" );
195 catch( const Exception
& )
197 OSL_ENSURE( sal_False
, "EditPropertyHandler::setPropertyValue: caught an exception!" );
201 //--------------------------------------------------------------------
202 bool EditPropertyHandler::implHaveBothScrollBarProperties() const
204 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
205 Reference
< XPropertySetInfo
> xPSI
;
206 if ( m_xComponent
.is() )
207 xPSI
= m_xComponent
->getPropertySetInfo();
210 && xPSI
->hasPropertyByName( PROPERTY_HSCROLL
)
211 && xPSI
->hasPropertyByName( PROPERTY_VSCROLL
);
214 //--------------------------------------------------------------------
215 bool EditPropertyHandler::implHaveTextTypeProperty() const
217 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
218 Reference
< XPropertySetInfo
> xPSI
;
219 if ( m_xComponent
.is() )
220 xPSI
= m_xComponent
->getPropertySetInfo();
223 && xPSI
->hasPropertyByName( PROPERTY_RICHTEXT
)
224 && xPSI
->hasPropertyByName( PROPERTY_MULTILINE
);
227 //--------------------------------------------------------------------
228 Sequence
< Property
> SAL_CALL
EditPropertyHandler::doDescribeSupportedProperties() const
230 ::std::vector
< Property
> aProperties
;
232 if ( implHaveBothScrollBarProperties() )
233 addInt32PropertyDescription( aProperties
, PROPERTY_SHOW_SCROLLBARS
);
235 if ( implHaveTextTypeProperty() )
236 addInt32PropertyDescription( aProperties
, PROPERTY_TEXTTYPE
);
238 if ( aProperties
.empty() )
239 return Sequence
< Property
>();
240 return Sequence
< Property
>( &(*aProperties
.begin()), aProperties
.size() );
243 //--------------------------------------------------------------------
244 Sequence
< ::rtl::OUString
> SAL_CALL
EditPropertyHandler::getSupersededProperties( ) throw (RuntimeException
)
246 ::osl::MutexGuard
aGuard( m_aMutex
);
247 ::std::vector
< ::rtl::OUString
> aSuperseded
;
248 if ( implHaveBothScrollBarProperties() )
250 aSuperseded
.push_back( PROPERTY_HSCROLL
);
251 aSuperseded
.push_back( PROPERTY_VSCROLL
);
253 if ( implHaveTextTypeProperty() )
255 aSuperseded
.push_back( PROPERTY_RICHTEXT
);
256 aSuperseded
.push_back( PROPERTY_MULTILINE
);
258 if ( aSuperseded
.empty() )
259 return Sequence
< ::rtl::OUString
>();
260 return Sequence
< ::rtl::OUString
>( &(*aSuperseded
.begin()), aSuperseded
.size() );
263 //--------------------------------------------------------------------
264 Sequence
< ::rtl::OUString
> SAL_CALL
EditPropertyHandler::getActuatingProperties( ) throw (RuntimeException
)
266 ::osl::MutexGuard
aGuard( m_aMutex
);
267 ::std::vector
< ::rtl::OUString
> aInterestingActuatingProps
;
268 if ( implHaveTextTypeProperty() )
269 aInterestingActuatingProps
.push_back( PROPERTY_TEXTTYPE
);
270 aInterestingActuatingProps
.push_back( PROPERTY_MULTILINE
);
271 return Sequence
< ::rtl::OUString
>( &(*aInterestingActuatingProps
.begin()), aInterestingActuatingProps
.size() );;
274 //--------------------------------------------------------------------
275 void SAL_CALL
EditPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString
& _rActuatingPropertyName
, const Any
& _rNewValue
, const Any
& /*_rOldValue*/, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool
) throw (NullPointerException
, RuntimeException
)
277 if ( !_rxInspectorUI
.is() )
278 throw NullPointerException();
280 ::osl::MutexGuard
aGuard( m_aMutex
);
281 PropertyId
nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName
) );
282 switch ( nActuatingPropId
)
284 case PROPERTY_ID_TEXTTYPE
:
286 sal_Int32 nTextType
= TEXTTYPE_SINGLELINE
;
287 getPropertyValue( PROPERTY_TEXTTYPE
) >>= nTextType
;
289 if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_WORDBREAK
) )
290 _rxInspectorUI
->enablePropertyUI( PROPERTY_WORDBREAK
, nTextType
== TEXTTYPE_RICHTEXT
);
291 _rxInspectorUI
->enablePropertyUI( PROPERTY_MAXTEXTLEN
, nTextType
!= TEXTTYPE_RICHTEXT
);
292 _rxInspectorUI
->enablePropertyUI( PROPERTY_ECHO_CHAR
, nTextType
== TEXTTYPE_SINGLELINE
);
293 _rxInspectorUI
->enablePropertyUI( PROPERTY_FONT
, nTextType
!= TEXTTYPE_RICHTEXT
);
294 _rxInspectorUI
->enablePropertyUI( PROPERTY_ALIGN
, nTextType
!= TEXTTYPE_RICHTEXT
);
295 _rxInspectorUI
->enablePropertyUI( PROPERTY_DEFAULT_TEXT
, nTextType
!= TEXTTYPE_RICHTEXT
);
296 _rxInspectorUI
->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS
, nTextType
!= TEXTTYPE_SINGLELINE
);
297 _rxInspectorUI
->enablePropertyUI( PROPERTY_LINEEND_FORMAT
, nTextType
!= TEXTTYPE_SINGLELINE
);
298 _rxInspectorUI
->enablePropertyUI( PROPERTY_VERTICAL_ALIGN
, nTextType
== TEXTTYPE_SINGLELINE
);
300 _rxInspectorUI
->showCategory( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Data" ) ), nTextType
!= TEXTTYPE_RICHTEXT
);
304 case PROPERTY_ID_MULTILINE
:
306 sal_Bool bIsMultiline
= sal_False
;
307 _rNewValue
>>= bIsMultiline
;
309 _rxInspectorUI
->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS
, bIsMultiline
);
310 _rxInspectorUI
->enablePropertyUI( PROPERTY_ECHO_CHAR
, !bIsMultiline
);
311 _rxInspectorUI
->enablePropertyUI( PROPERTY_LINEEND_FORMAT
, bIsMultiline
);
316 OSL_ENSURE( sal_False
, "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
320 //........................................................................
322 //........................................................................