LibreOffice Module extensions (master) 1
editpropertyhandler.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include "formstrings.hxx"
22#include "formmetadata.hxx"
23
24#include <com/sun/star/inspection/XObjectInspectorUI.hpp>
25#include <com/sun/star/lang/NullPointerException.hpp>
27
28namespace
29{
30 enum class TextType
31 {
32 SINGLELINE = 0,
33 MULTILINE = 1,
34 RICHTEXT = 2
35 };
36};
37namespace pcr
38{
39
40
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;
47
48
49 //= EditPropertyHandler
50
51
52 EditPropertyHandler::EditPropertyHandler( const Reference< XComponentContext >& _rxContext )
53 :PropertyHandlerComponent( _rxContext )
54 {
55 }
56
57
59 {
60 }
61
62
64 {
65 return "com.sun.star.comp.extensions.EditPropertyHandler";
66 }
67
68
70 {
71 return { "com.sun.star.form.inspection.EditPropertyHandler" };
72 }
73
74
75 Any SAL_CALL EditPropertyHandler::getPropertyValue( const OUString& _rPropertyName )
76 {
77 ::osl::MutexGuard aGuard( m_aMutex );
78 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
79
80 Any aReturn;
81 try
82 {
83 switch ( nPropId )
84 {
86 {
87 bool bHasVScroll = false;
88 m_xComponent->getPropertyValue( PROPERTY_VSCROLL ) >>= bHasVScroll;
89 bool bHasHScroll = false;
90 m_xComponent->getPropertyValue( PROPERTY_HSCROLL ) >>= bHasHScroll;
91
92 aReturn <<= static_cast<sal_Int32>( ( bHasVScroll ? 2 : 0 ) + ( bHasHScroll ? 1 : 0 ) );
93 }
94 break;
95
97 {
98 TextType nTextType = TextType::SINGLELINE;
99 bool bRichText = false;
100 OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_RICHTEXT ) >>= bRichText );
101 if ( bRichText )
102 nTextType = TextType::RICHTEXT;
103 else
104 {
105 bool bMultiLine = false;
106 OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_MULTILINE ) >>= bMultiLine );
107 if ( bMultiLine )
108 nTextType = TextType::MULTILINE;
109 else
110 nTextType = TextType::SINGLELINE;
111 }
112 aReturn <<= static_cast<sal_Int32>(nTextType);
113 }
114 break;
115
116
117 default:
118 OSL_FAIL( "EditPropertyHandler::getPropertyValue: cannot handle this property!" );
119 break;
120 }
121 }
122 catch( const Exception& )
123 {
124 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "EditPropertyHandler::getPropertyValue" );
125 }
126
127 return aReturn;
128 }
129
130
131 void SAL_CALL EditPropertyHandler::setPropertyValue( const OUString& _rPropertyName, const Any& _rValue )
132 {
133 ::osl::MutexGuard aGuard( m_aMutex );
134 PropertyId nPropId( impl_getPropertyId_throwUnknownProperty( _rPropertyName ) );
135
136 try
137 {
138 switch ( nPropId )
139 {
141 {
142 sal_Int32 nScrollbars = 0;
143 _rValue >>= nScrollbars;
144
145 bool bHasVScroll = 0 != ( nScrollbars & 2 );
146 bool bHasHScroll = 0 != ( nScrollbars & 1 );
147
148 m_xComponent->setPropertyValue( PROPERTY_VSCROLL, Any( bHasVScroll ) );
149 m_xComponent->setPropertyValue( PROPERTY_HSCROLL, Any( bHasHScroll ) );
150 }
151 break;
152
154 {
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) )
160 {
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;
164 default:
165 OSL_FAIL( "EditPropertyHandler::setPropertyValue: invalid text type!" );
166 }
167
168 m_xComponent->setPropertyValue( PROPERTY_MULTILINE, Any( bMultiLine ) );
169 m_xComponent->setPropertyValue( PROPERTY_RICHTEXT, Any( bRichText ) );
170 }
171 break;
172
173 default:
174 OSL_FAIL( "EditPropertyHandler::setPropertyValue: cannot handle this id!" );
175 }
176 }
177 catch( const Exception& )
178 {
179 TOOLS_WARN_EXCEPTION( "extensions.propctrlr", "EditPropertyHandler::setPropertyValue" );
180 }
181 }
182
183
185 {
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();
190
191 return xPSI.is()
192 && xPSI->hasPropertyByName( PROPERTY_HSCROLL )
193 && xPSI->hasPropertyByName( PROPERTY_VSCROLL );
194 }
195
196
198 {
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();
203
204 return xPSI.is()
205 && xPSI->hasPropertyByName( PROPERTY_RICHTEXT )
206 && xPSI->hasPropertyByName( PROPERTY_MULTILINE );
207 }
208
209
211 {
212 std::vector< Property > aProperties;
213
216
219
220 if ( aProperties.empty() )
221 return Sequence< Property >();
223 }
224
225
226 Sequence< OUString > SAL_CALL EditPropertyHandler::getSupersededProperties( )
227 {
228 ::osl::MutexGuard aGuard( m_aMutex );
229 std::vector< OUString > aSuperseded;
231 {
232 aSuperseded.push_back( PROPERTY_HSCROLL );
233 aSuperseded.push_back( PROPERTY_VSCROLL );
234 }
236 {
237 aSuperseded.push_back( PROPERTY_RICHTEXT );
238 aSuperseded.push_back( PROPERTY_MULTILINE );
239 }
240 if ( aSuperseded.empty() )
241 return Sequence< OUString >();
242 return comphelper::containerToSequence(aSuperseded);
243 }
244
245
246 Sequence< OUString > SAL_CALL EditPropertyHandler::getActuatingProperties( )
247 {
248 ::osl::MutexGuard aGuard( m_aMutex );
249 std::vector< OUString > aInterestingActuatingProps;
251 aInterestingActuatingProps.push_back( PROPERTY_TEXTTYPE );
252 aInterestingActuatingProps.push_back( PROPERTY_MULTILINE );
253 return comphelper::containerToSequence(aInterestingActuatingProps);
254 }
255
256
257 void SAL_CALL EditPropertyHandler::actuatingPropertyChanged( const OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool )
258 {
259 if ( !_rxInspectorUI.is() )
260 throw NullPointerException();
261
262 ::osl::MutexGuard aGuard( m_aMutex );
263 PropertyId nActuatingPropId( impl_getPropertyId_throwRuntime( _rActuatingPropertyName ) );
264 switch ( nActuatingPropId )
265 {
267 {
268 sal_Int32 nTextTypeInt = static_cast<sal_Int32>(TextType::SINGLELINE);
269 getPropertyValue( PROPERTY_TEXTTYPE ) >>= nTextTypeInt;
270
271 TextType nTextType = static_cast<TextType>(nTextTypeInt);
272
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 );
283
284 _rxInspectorUI->showCategory( "Data", nTextType != TextType::RICHTEXT );
285 }
286 break;
287
289 {
290 bool bIsMultiline = false;
291 _rNewValue >>= bIsMultiline;
292
293 _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, bIsMultiline );
294 _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, !bIsMultiline );
295 _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, bIsMultiline );
296 }
297 break;
298
299 default:
300 OSL_FAIL( "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
301 }
302 }
303
304
305} // namespace pcr
306
307extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
309 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
310{
311 return cppu::acquire(new pcr::EditPropertyHandler(context));
312}
313
314/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesInfo aProperties
mutable::osl::Mutex m_aMutex
a property handler for any virtual string properties
bool implHaveBothScrollBarProperties() const
virtual void SAL_CALL setPropertyValue(const OUString &_rPropertyName, const css::uno::Any &_rValue) override
virtual void SAL_CALL actuatingPropertyChanged(const OUString &_rActuatingPropertyName, const css::uno::Any &_rNewValue, const css::uno::Any &_rOldValue, const css::uno::Reference< css::inspection::XObjectInspectorUI > &_rxInspectorUI, sal_Bool) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &_rPropertyName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual ~EditPropertyHandler() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupersededProperties() override
virtual css::uno::Sequence< css::beans::Property > doDescribeSupportedProperties() const override
EditPropertyHandler(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< OUString > SAL_CALL getActuatingProperties() override
PropertyHandler implementation which additionally supports XServiceInfo.
bool impl_isSupportedProperty_nothrow(PropertyId _nPropId) const
determines whether a given property id is part of our supported properties
PropertyId impl_getPropertyId_throwUnknownProperty(const OUString &_rPropertyName) const
retrieves the property id for a given property name
void addInt32PropertyDescription(std::vector< css::beans::Property > &_rProperties, const OUString &_rPropertyName, sal_Int16 _nAttribs=0) const
adds a description for the given int32 property to the given property vector
css::uno::Reference< css::beans::XPropertySet > m_xComponent
the component we're inspecting
PropertyId impl_getPropertyId_throwRuntime(const OUString &_rPropertyName) const
retrieves the property id for a given property name
#define TOOLS_WARN_EXCEPTION(area, stream)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * extensions_propctrlr_EditPropertyHandler_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define PROPERTY_ID_WORDBREAK
#define PROPERTY_ID_SHOW_SCROLLBARS
#define PROPERTY_ID_TEXTTYPE
#define PROPERTY_ID_MULTILINE
constexpr OUStringLiteral PROPERTY_RICHTEXT
constexpr OUStringLiteral PROPERTY_DEFAULT_TEXT
Definition: formstrings.hxx:62
constexpr OUStringLiteral PROPERTY_VERTICAL_ALIGN
Definition: formstrings.hxx:78
constexpr OUStringLiteral PROPERTY_LINEEND_FORMAT
constexpr OUStringLiteral PROPERTY_TEXTTYPE
constexpr OUStringLiteral PROPERTY_ALIGN
Definition: formstrings.hxx:77
constexpr OUStringLiteral PROPERTY_VSCROLL
constexpr OUStringLiteral PROPERTY_MAXTEXTLEN
Definition: formstrings.hxx:53
constexpr OUStringLiteral PROPERTY_HSCROLL
constexpr OUStringLiteral PROPERTY_FONT
constexpr OUStringLiteral PROPERTY_ECHO_CHAR
constexpr OUStringLiteral PROPERTY_SHOW_SCROLLBARS
constexpr OUStringLiteral PROPERTY_MULTILINE
Definition: formstrings.hxx:49
constexpr OUStringLiteral PROPERTY_WORDBREAK
Definition: formstrings.hxx:50
@ Exception
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
a property handler for any virtual string properties
Definition: browserline.cxx:39
sal_Int32 PropertyId
unsigned char sal_Bool