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"
24 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
25 #include <com/sun/star/lang/NullPointerException.hpp>
26 #include <comphelper/diagnose_ex.hxx>
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star::beans
;
44 using namespace ::com::sun::star::script
;
45 using namespace ::com::sun::star::frame
;
46 using namespace ::com::sun::star::inspection
;
49 //= EditPropertyHandler
52 EditPropertyHandler::EditPropertyHandler( const Reference
< XComponentContext
>& _rxContext
)
53 :PropertyHandlerComponent( _rxContext
)
58 EditPropertyHandler::~EditPropertyHandler( )
63 OUString
EditPropertyHandler::getImplementationName( )
65 return "com.sun.star.comp.extensions.EditPropertyHandler";
69 Sequence
< OUString
> EditPropertyHandler::getSupportedServiceNames( )
71 return { "com.sun.star.form.inspection.EditPropertyHandler" };
75 Any SAL_CALL
EditPropertyHandler::getPropertyValue( const OUString
& _rPropertyName
)
77 ::osl::MutexGuard
aGuard( m_aMutex
);
78 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
85 case PROPERTY_ID_SHOW_SCROLLBARS
:
87 bool bHasVScroll
= false;
88 m_xComponent
->getPropertyValue( PROPERTY_VSCROLL
) >>= bHasVScroll
;
89 bool bHasHScroll
= false;
90 m_xComponent
->getPropertyValue( PROPERTY_HSCROLL
) >>= bHasHScroll
;
92 aReturn
<<= static_cast<sal_Int32
>( ( bHasVScroll
? 2 : 0 ) + ( bHasHScroll
? 1 : 0 ) );
96 case PROPERTY_ID_TEXTTYPE
:
98 TextType nTextType
= TextType::SINGLELINE
;
99 bool bRichText
= false;
100 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_RICHTEXT
) >>= bRichText
);
102 nTextType
= TextType::RICHTEXT
;
105 bool bMultiLine
= false;
106 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_MULTILINE
) >>= bMultiLine
);
108 nTextType
= TextType::MULTILINE
;
110 nTextType
= TextType::SINGLELINE
;
112 aReturn
<<= static_cast<sal_Int32
>(nTextType
);
118 OSL_FAIL( "EditPropertyHandler::getPropertyValue: cannot handle this property!" );
122 catch( const Exception
& )
124 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "EditPropertyHandler::getPropertyValue" );
131 void SAL_CALL
EditPropertyHandler::setPropertyValue( const OUString
& _rPropertyName
, const Any
& _rValue
)
133 ::osl::MutexGuard
aGuard( m_aMutex
);
134 PropertyId
nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName
) );
140 case PROPERTY_ID_SHOW_SCROLLBARS
:
142 sal_Int32 nScrollbars
= 0;
143 _rValue
>>= nScrollbars
;
145 bool bHasVScroll
= 0 != ( nScrollbars
& 2 );
146 bool bHasHScroll
= 0 != ( nScrollbars
& 1 );
148 m_xComponent
->setPropertyValue( PROPERTY_VSCROLL
, Any( bHasVScroll
) );
149 m_xComponent
->setPropertyValue( PROPERTY_HSCROLL
, Any( bHasHScroll
) );
153 case PROPERTY_ID_TEXTTYPE
:
155 bool bMultiLine
= false;
156 bool bRichText
= false;
157 sal_Int32 nTextType
= static_cast<sal_Int32
>(TextType::SINGLELINE
);
158 OSL_VERIFY( _rValue
>>= nTextType
);
159 switch ( static_cast<TextType
>(nTextType
) )
161 case TextType::SINGLELINE
: bMultiLine
= bRichText
= false; break;
162 case TextType::MULTILINE
: bMultiLine
= true; bRichText
= false; break;
163 case TextType::RICHTEXT
: bMultiLine
= true; bRichText
= true; break;
165 OSL_FAIL( "EditPropertyHandler::setPropertyValue: invalid text type!" );
168 m_xComponent
->setPropertyValue( PROPERTY_MULTILINE
, Any( bMultiLine
) );
169 m_xComponent
->setPropertyValue( PROPERTY_RICHTEXT
, Any( bRichText
) );
174 OSL_FAIL( "EditPropertyHandler::setPropertyValue: cannot handle this id!" );
177 catch( const Exception
& )
179 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "EditPropertyHandler::setPropertyValue" );
184 bool EditPropertyHandler::implHaveBothScrollBarProperties() const
186 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
187 Reference
< XPropertySetInfo
> xPSI
;
188 if ( m_xComponent
.is() )
189 xPSI
= m_xComponent
->getPropertySetInfo();
192 && xPSI
->hasPropertyByName( PROPERTY_HSCROLL
)
193 && xPSI
->hasPropertyByName( PROPERTY_VSCROLL
);
197 bool EditPropertyHandler::implHaveTextTypeProperty() const
199 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
200 Reference
< XPropertySetInfo
> xPSI
;
201 if ( m_xComponent
.is() )
202 xPSI
= m_xComponent
->getPropertySetInfo();
205 && xPSI
->hasPropertyByName( PROPERTY_RICHTEXT
)
206 && xPSI
->hasPropertyByName( PROPERTY_MULTILINE
);
210 Sequence
< Property
> EditPropertyHandler::doDescribeSupportedProperties() const
212 std::vector
< Property
> aProperties
;
214 if ( implHaveBothScrollBarProperties() )
215 addInt32PropertyDescription( aProperties
, PROPERTY_SHOW_SCROLLBARS
);
217 if ( implHaveTextTypeProperty() )
218 addInt32PropertyDescription( aProperties
, PROPERTY_TEXTTYPE
);
220 if ( aProperties
.empty() )
221 return Sequence
< Property
>();
222 return comphelper::containerToSequence(aProperties
);
226 Sequence
< OUString
> SAL_CALL
EditPropertyHandler::getSupersededProperties( )
228 ::osl::MutexGuard
aGuard( m_aMutex
);
229 std::vector
< OUString
> aSuperseded
;
230 if ( implHaveBothScrollBarProperties() )
232 aSuperseded
.push_back( PROPERTY_HSCROLL
);
233 aSuperseded
.push_back( PROPERTY_VSCROLL
);
235 if ( implHaveTextTypeProperty() )
237 aSuperseded
.push_back( PROPERTY_RICHTEXT
);
238 aSuperseded
.push_back( PROPERTY_MULTILINE
);
240 if ( aSuperseded
.empty() )
241 return Sequence
< OUString
>();
242 return comphelper::containerToSequence(aSuperseded
);
246 Sequence
< OUString
> SAL_CALL
EditPropertyHandler::getActuatingProperties( )
248 ::osl::MutexGuard
aGuard( m_aMutex
);
249 std::vector
< OUString
> aInterestingActuatingProps
;
250 if ( implHaveTextTypeProperty() )
251 aInterestingActuatingProps
.push_back( PROPERTY_TEXTTYPE
);
252 aInterestingActuatingProps
.push_back( PROPERTY_MULTILINE
);
253 return comphelper::containerToSequence(aInterestingActuatingProps
);
257 void SAL_CALL
EditPropertyHandler::actuatingPropertyChanged( const OUString
& _rActuatingPropertyName
, const Any
& _rNewValue
, const Any
& /*_rOldValue*/, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool
)
259 if ( !_rxInspectorUI
.is() )
260 throw NullPointerException();
262 ::osl::MutexGuard
aGuard( m_aMutex
);
263 PropertyId
nActuatingPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName
) );
264 switch ( nActuatingPropId
)
266 case PROPERTY_ID_TEXTTYPE
:
268 sal_Int32 nTextTypeInt
= static_cast<sal_Int32
>(TextType::SINGLELINE
);
269 getPropertyValue( PROPERTY_TEXTTYPE
) >>= nTextTypeInt
;
271 TextType nTextType
= static_cast<TextType
>(nTextTypeInt
);
273 if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_WORDBREAK
) )
274 _rxInspectorUI
->enablePropertyUI( PROPERTY_WORDBREAK
, nTextType
== TextType::RICHTEXT
);
275 _rxInspectorUI
->enablePropertyUI( PROPERTY_MAXTEXTLEN
, nTextType
!= TextType::RICHTEXT
);
276 _rxInspectorUI
->enablePropertyUI( PROPERTY_ECHO_CHAR
, nTextType
== TextType::SINGLELINE
);
277 _rxInspectorUI
->enablePropertyUI( PROPERTY_FONT
, nTextType
!= TextType::RICHTEXT
);
278 _rxInspectorUI
->enablePropertyUI( PROPERTY_ALIGN
, nTextType
!= TextType::RICHTEXT
);
279 _rxInspectorUI
->enablePropertyUI( PROPERTY_DEFAULT_TEXT
, nTextType
!= TextType::RICHTEXT
);
280 _rxInspectorUI
->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS
, nTextType
!= TextType::SINGLELINE
);
281 _rxInspectorUI
->enablePropertyUI( PROPERTY_LINEEND_FORMAT
, nTextType
!= TextType::SINGLELINE
);
282 _rxInspectorUI
->enablePropertyUI( PROPERTY_VERTICAL_ALIGN
, nTextType
== TextType::SINGLELINE
);
284 _rxInspectorUI
->showCategory( "Data", nTextType
!= TextType::RICHTEXT
);
288 case PROPERTY_ID_MULTILINE
:
290 bool bIsMultiline
= false;
291 _rNewValue
>>= bIsMultiline
;
293 _rxInspectorUI
->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS
, bIsMultiline
);
294 _rxInspectorUI
->enablePropertyUI( PROPERTY_ECHO_CHAR
, !bIsMultiline
);
295 _rxInspectorUI
->enablePropertyUI( PROPERTY_LINEEND_FORMAT
, bIsMultiline
);
300 OSL_FAIL( "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
307 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
308 extensions_propctrlr_EditPropertyHandler_get_implementation(
309 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const&)
311 return cppu::acquire(new pcr::EditPropertyHandler(context
));
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */