1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "editpropertyhandler.hxx"
21 #include "formstrings.hxx"
22 #include "formmetadata.hxx"
23 #include "pcrservices.hxx"
25 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
27 #define TEXTTYPE_SINGLELINE 0
28 #define TEXTTYPE_MULTILINE 1
29 #define TEXTTYPE_RICHTEXT 2
32 extern "C" void SAL_CALL
createRegistryInfo_EditPropertyHandler()
34 ::pcr::EditPropertyHandler::registerImplementation();
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::lang
;
44 using namespace ::com::sun::star::beans
;
45 using namespace ::com::sun::star::script
;
46 using namespace ::com::sun::star::frame
;
47 using namespace ::com::sun::star::inspection
;
50 //= EditPropertyHandler
53 EditPropertyHandler::EditPropertyHandler( const Reference
< XComponentContext
>& _rxContext
)
54 :EditPropertyHandler_Base( _rxContext
)
59 EditPropertyHandler::~EditPropertyHandler( )
64 OUString SAL_CALL
EditPropertyHandler::getImplementationName_static( ) throw (RuntimeException
)
66 return OUString( "com.sun.star.comp.extensions.EditPropertyHandler" );
70 Sequence
< OUString
> SAL_CALL
EditPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException
)
72 Sequence
< OUString
> aSupported( 1 );
73 aSupported
[0] = "com.sun.star.form.inspection.EditPropertyHandler";
78 Any SAL_CALL
EditPropertyHandler::getPropertyValue( const OUString
& _rPropertyName
) throw (UnknownPropertyException
, RuntimeException
, std::exception
)
80 ::osl::MutexGuard
aGuard( m_aMutex
);
81 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
88 case PROPERTY_ID_SHOW_SCROLLBARS
:
90 bool bHasVScroll
= false;
91 m_xComponent
->getPropertyValue( PROPERTY_VSCROLL
) >>= bHasVScroll
;
92 bool bHasHScroll
= false;
93 m_xComponent
->getPropertyValue( PROPERTY_HSCROLL
) >>= bHasHScroll
;
95 aReturn
<<= (sal_Int32
)( ( bHasVScroll
? 2 : 0 ) + ( bHasHScroll
? 1 : 0 ) );
99 case PROPERTY_ID_TEXTTYPE
:
101 sal_Int32 nTextType
= TEXTTYPE_SINGLELINE
;
102 bool bRichText
= false;
103 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_RICHTEXT
) >>= bRichText
);
105 nTextType
= TEXTTYPE_RICHTEXT
;
108 bool bMultiLine
= false;
109 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_MULTILINE
) >>= bMultiLine
);
111 nTextType
= TEXTTYPE_MULTILINE
;
113 nTextType
= TEXTTYPE_SINGLELINE
;
115 aReturn
<<= nTextType
;
121 OSL_FAIL( "EditPropertyHandler::getPropertyValue: cannot handle this property!" );
125 catch( const Exception
& )
127 OSL_FAIL( "EditPropertyHandler::getPropertyValue: caught an exception!" );
134 void SAL_CALL
EditPropertyHandler::setPropertyValue( const OUString
& _rPropertyName
, const Any
& _rValue
) throw (UnknownPropertyException
, RuntimeException
, std::exception
)
136 ::osl::MutexGuard
aGuard( m_aMutex
);
137 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
143 case PROPERTY_ID_SHOW_SCROLLBARS
:
145 sal_Int32 nScrollbars
= 0;
146 _rValue
>>= nScrollbars
;
148 bool bHasVScroll
= 0 != ( nScrollbars
& 2 );
149 bool bHasHScroll
= 0 != ( nScrollbars
& 1 );
151 m_xComponent
->setPropertyValue( PROPERTY_VSCROLL
, makeAny( bHasVScroll
) );
152 m_xComponent
->setPropertyValue( PROPERTY_HSCROLL
, makeAny( bHasHScroll
) );
156 case PROPERTY_ID_TEXTTYPE
:
158 bool bMultiLine
= false;
159 bool bRichText
= false;
160 sal_Int32 nTextType
= TEXTTYPE_SINGLELINE
;
161 OSL_VERIFY( _rValue
>>= nTextType
);
164 case TEXTTYPE_SINGLELINE
: bMultiLine
= bRichText
= false; break;
165 case TEXTTYPE_MULTILINE
: bMultiLine
= true; bRichText
= false; break;
166 case TEXTTYPE_RICHTEXT
: bMultiLine
= true; bRichText
= true; break;
168 OSL_FAIL( "EditPropertyHandler::setPropertyValue: invalid text type!" );
171 m_xComponent
->setPropertyValue( PROPERTY_MULTILINE
, makeAny( bMultiLine
) );
172 m_xComponent
->setPropertyValue( PROPERTY_RICHTEXT
, makeAny( bRichText
) );
177 OSL_FAIL( "EditPropertyHandler::setPropertyValue: cannot handle this id!" );
180 catch( const Exception
& )
182 OSL_FAIL( "EditPropertyHandler::setPropertyValue: caught an exception!" );
187 bool EditPropertyHandler::implHaveBothScrollBarProperties() const
189 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
190 Reference
< XPropertySetInfo
> xPSI
;
191 if ( m_xComponent
.is() )
192 xPSI
= m_xComponent
->getPropertySetInfo();
195 && xPSI
->hasPropertyByName( PROPERTY_HSCROLL
)
196 && xPSI
->hasPropertyByName( PROPERTY_VSCROLL
);
200 bool EditPropertyHandler::implHaveTextTypeProperty() const
202 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
203 Reference
< XPropertySetInfo
> xPSI
;
204 if ( m_xComponent
.is() )
205 xPSI
= m_xComponent
->getPropertySetInfo();
208 && xPSI
->hasPropertyByName( PROPERTY_RICHTEXT
)
209 && xPSI
->hasPropertyByName( PROPERTY_MULTILINE
);
213 Sequence
< Property
> SAL_CALL
EditPropertyHandler::doDescribeSupportedProperties() const
215 ::std::vector
< Property
> aProperties
;
217 if ( implHaveBothScrollBarProperties() )
218 addInt32PropertyDescription( aProperties
, PROPERTY_SHOW_SCROLLBARS
);
220 if ( implHaveTextTypeProperty() )
221 addInt32PropertyDescription( aProperties
, PROPERTY_TEXTTYPE
);
223 if ( aProperties
.empty() )
224 return Sequence
< Property
>();
225 return Sequence
< Property
>( &(*aProperties
.begin()), aProperties
.size() );
229 Sequence
< OUString
> SAL_CALL
EditPropertyHandler::getSupersededProperties( ) throw (RuntimeException
, std::exception
)
231 ::osl::MutexGuard
aGuard( m_aMutex
);
232 ::std::vector
< OUString
> aSuperseded
;
233 if ( implHaveBothScrollBarProperties() )
235 aSuperseded
.push_back( static_cast<const OUString
&>(PROPERTY_HSCROLL
) );
236 aSuperseded
.push_back( static_cast<const OUString
&>(PROPERTY_VSCROLL
) );
238 if ( implHaveTextTypeProperty() )
240 aSuperseded
.push_back( static_cast<const OUString
&>(PROPERTY_RICHTEXT
) );
241 aSuperseded
.push_back( static_cast<const OUString
&>(PROPERTY_MULTILINE
) );
243 if ( aSuperseded
.empty() )
244 return Sequence
< OUString
>();
245 return Sequence
< OUString
>( &(*aSuperseded
.begin()), aSuperseded
.size() );
249 Sequence
< OUString
> SAL_CALL
EditPropertyHandler::getActuatingProperties( ) throw (RuntimeException
, std::exception
)
251 ::osl::MutexGuard
aGuard( m_aMutex
);
252 ::std::vector
< OUString
> aInterestingActuatingProps
;
253 if ( implHaveTextTypeProperty() )
254 aInterestingActuatingProps
.push_back( static_cast<const OUString
&>(PROPERTY_TEXTTYPE
) );
255 aInterestingActuatingProps
.push_back( static_cast<const OUString
&>(PROPERTY_MULTILINE
) );
256 return Sequence
< OUString
>( &(*aInterestingActuatingProps
.begin()), aInterestingActuatingProps
.size() );
260 void SAL_CALL
EditPropertyHandler::actuatingPropertyChanged( const OUString
& _rActuatingPropertyName
, const Any
& _rNewValue
, const Any
& /*_rOldValue*/, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool
) throw (NullPointerException
, RuntimeException
, std::exception
)
262 if ( !_rxInspectorUI
.is() )
263 throw NullPointerException();
265 ::osl::MutexGuard
aGuard( m_aMutex
);
266 PropertyId
nActuatingPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName
) );
267 switch ( nActuatingPropId
)
269 case PROPERTY_ID_TEXTTYPE
:
271 sal_Int32 nTextType
= TEXTTYPE_SINGLELINE
;
272 getPropertyValue( PROPERTY_TEXTTYPE
) >>= nTextType
;
274 if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_WORDBREAK
) )
275 _rxInspectorUI
->enablePropertyUI( PROPERTY_WORDBREAK
, nTextType
== TEXTTYPE_RICHTEXT
);
276 _rxInspectorUI
->enablePropertyUI( PROPERTY_MAXTEXTLEN
, nTextType
!= TEXTTYPE_RICHTEXT
);
277 _rxInspectorUI
->enablePropertyUI( PROPERTY_ECHO_CHAR
, nTextType
== TEXTTYPE_SINGLELINE
);
278 _rxInspectorUI
->enablePropertyUI( PROPERTY_FONT
, nTextType
!= TEXTTYPE_RICHTEXT
);
279 _rxInspectorUI
->enablePropertyUI( PROPERTY_ALIGN
, nTextType
!= TEXTTYPE_RICHTEXT
);
280 _rxInspectorUI
->enablePropertyUI( PROPERTY_DEFAULT_TEXT
, nTextType
!= TEXTTYPE_RICHTEXT
);
281 _rxInspectorUI
->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS
, nTextType
!= TEXTTYPE_SINGLELINE
);
282 _rxInspectorUI
->enablePropertyUI( PROPERTY_LINEEND_FORMAT
, nTextType
!= TEXTTYPE_SINGLELINE
);
283 _rxInspectorUI
->enablePropertyUI( PROPERTY_VERTICAL_ALIGN
, nTextType
== TEXTTYPE_SINGLELINE
);
285 _rxInspectorUI
->showCategory( OUString( "Data" ), nTextType
!= TEXTTYPE_RICHTEXT
);
289 case PROPERTY_ID_MULTILINE
:
291 bool bIsMultiline
= false;
292 _rNewValue
>>= bIsMultiline
;
294 _rxInspectorUI
->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS
, bIsMultiline
);
295 _rxInspectorUI
->enablePropertyUI( PROPERTY_ECHO_CHAR
, !bIsMultiline
);
296 _rxInspectorUI
->enablePropertyUI( PROPERTY_LINEEND_FORMAT
, bIsMultiline
);
301 OSL_FAIL( "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */