Line data Source code
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 :
20 : #include "editpropertyhandler.hxx"
21 : #include "formstrings.hxx"
22 : #include "formmetadata.hxx"
23 :
24 : #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
25 : #include <tools/debug.hxx>
26 :
27 : #define TEXTTYPE_SINGLELINE 0
28 : #define TEXTTYPE_MULTILINE 1
29 : #define TEXTTYPE_RICHTEXT 2
30 :
31 : //------------------------------------------------------------------------
32 0 : extern "C" void SAL_CALL createRegistryInfo_EditPropertyHandler()
33 : {
34 0 : ::pcr::EditPropertyHandler::registerImplementation();
35 0 : }
36 :
37 : //........................................................................
38 : namespace pcr
39 : {
40 : //........................................................................
41 :
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;
48 :
49 : //====================================================================
50 : //= EditPropertyHandler
51 : //====================================================================
52 : DBG_NAME( EditPropertyHandler )
53 : //--------------------------------------------------------------------
54 0 : EditPropertyHandler::EditPropertyHandler( const Reference< XComponentContext >& _rxContext )
55 0 : :EditPropertyHandler_Base( _rxContext )
56 : {
57 : DBG_CTOR( EditPropertyHandler, NULL );
58 0 : }
59 :
60 : //--------------------------------------------------------------------
61 0 : EditPropertyHandler::~EditPropertyHandler( )
62 : {
63 : DBG_DTOR( EditPropertyHandler, NULL );
64 0 : }
65 :
66 : //--------------------------------------------------------------------
67 0 : ::rtl::OUString SAL_CALL EditPropertyHandler::getImplementationName_static( ) throw (RuntimeException)
68 : {
69 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.EditPropertyHandler" ) );
70 : }
71 :
72 : //--------------------------------------------------------------------
73 0 : Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
74 : {
75 0 : Sequence< ::rtl::OUString > aSupported( 1 );
76 0 : aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.EditPropertyHandler" ) );
77 0 : return aSupported;
78 : }
79 :
80 : //--------------------------------------------------------------------
81 0 : Any SAL_CALL EditPropertyHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
82 : {
83 0 : ::osl::MutexGuard aGuard( m_aMutex );
84 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
85 :
86 0 : Any aReturn;
87 : try
88 : {
89 0 : switch ( nPropId )
90 : {
91 : case PROPERTY_ID_SHOW_SCROLLBARS:
92 : {
93 0 : sal_Bool bHasVScroll = sal_False;
94 0 : m_xComponent->getPropertyValue( PROPERTY_VSCROLL ) >>= bHasVScroll;
95 0 : sal_Bool bHasHScroll = sal_False;
96 0 : m_xComponent->getPropertyValue( PROPERTY_HSCROLL ) >>= bHasHScroll;
97 :
98 0 : aReturn <<= (sal_Int32)( ( bHasVScroll ? 2 : 0 ) + ( bHasHScroll ? 1 : 0 ) );
99 : }
100 0 : break;
101 :
102 : case PROPERTY_ID_TEXTTYPE:
103 : {
104 0 : sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
105 0 : sal_Bool bRichText = sal_False;
106 0 : OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_RICHTEXT ) >>= bRichText );
107 0 : if ( bRichText )
108 0 : nTextType = TEXTTYPE_RICHTEXT;
109 : else
110 : {
111 0 : sal_Bool bMultiLine = sal_False;
112 0 : OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_MULTILINE ) >>= bMultiLine );
113 0 : if ( bMultiLine )
114 0 : nTextType = TEXTTYPE_MULTILINE;
115 : else
116 0 : nTextType = TEXTTYPE_SINGLELINE;
117 : }
118 0 : aReturn <<= nTextType;
119 : }
120 0 : break;
121 :
122 :
123 : default:
124 : OSL_FAIL( "EditPropertyHandler::getPropertyValue: cannot handle this property!" );
125 0 : break;
126 : }
127 : }
128 0 : catch( const Exception& )
129 : {
130 : OSL_FAIL( "EditPropertyHandler::getPropertyValue: caught an exception!" );
131 : }
132 :
133 0 : return aReturn;
134 : }
135 :
136 : //--------------------------------------------------------------------
137 0 : void SAL_CALL EditPropertyHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
138 : {
139 0 : ::osl::MutexGuard aGuard( m_aMutex );
140 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
141 :
142 : try
143 : {
144 0 : switch ( nPropId )
145 : {
146 : case PROPERTY_ID_SHOW_SCROLLBARS:
147 : {
148 0 : sal_Int32 nScrollbars = 0;
149 0 : _rValue >>= nScrollbars;
150 :
151 0 : sal_Bool bHasVScroll = 0 != ( nScrollbars & 2 );
152 0 : sal_Bool bHasHScroll = 0 != ( nScrollbars & 1 );
153 :
154 0 : m_xComponent->setPropertyValue( PROPERTY_VSCROLL, makeAny( (sal_Bool)bHasVScroll ) );
155 0 : m_xComponent->setPropertyValue( PROPERTY_HSCROLL, makeAny( (sal_Bool)bHasHScroll ) );
156 : }
157 0 : break;
158 :
159 : case PROPERTY_ID_TEXTTYPE:
160 : {
161 0 : sal_Bool bMultiLine = sal_False;
162 0 : sal_Bool bRichText = sal_False;
163 0 : sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
164 0 : OSL_VERIFY( _rValue >>= nTextType );
165 0 : switch ( nTextType )
166 : {
167 0 : case TEXTTYPE_SINGLELINE: bMultiLine = bRichText = sal_False; break;
168 0 : case TEXTTYPE_MULTILINE: bMultiLine = sal_True; bRichText = sal_False; break;
169 0 : case TEXTTYPE_RICHTEXT: bMultiLine = sal_True; bRichText = sal_True; break;
170 : default:
171 : OSL_FAIL( "EditPropertyHandler::setPropertyValue: invalid text type!" );
172 : }
173 :
174 0 : m_xComponent->setPropertyValue( PROPERTY_MULTILINE, makeAny( bMultiLine ) );
175 0 : m_xComponent->setPropertyValue( PROPERTY_RICHTEXT, makeAny( bRichText ) );
176 : }
177 0 : break;
178 :
179 : default:
180 : OSL_FAIL( "EditPropertyHandler::setPropertyValue: cannot handle this id!" );
181 : }
182 : }
183 0 : catch( const Exception& )
184 : {
185 : OSL_FAIL( "EditPropertyHandler::setPropertyValue: caught an exception!" );
186 0 : }
187 0 : }
188 :
189 : //--------------------------------------------------------------------
190 0 : bool EditPropertyHandler::implHaveBothScrollBarProperties() const
191 : {
192 : // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
193 0 : Reference< XPropertySetInfo > xPSI;
194 0 : if ( m_xComponent.is() )
195 0 : xPSI = m_xComponent->getPropertySetInfo();
196 :
197 0 : return xPSI.is()
198 0 : && xPSI->hasPropertyByName( PROPERTY_HSCROLL )
199 0 : && xPSI->hasPropertyByName( PROPERTY_VSCROLL );
200 : }
201 :
202 : //--------------------------------------------------------------------
203 0 : bool EditPropertyHandler::implHaveTextTypeProperty() const
204 : {
205 : // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
206 0 : Reference< XPropertySetInfo > xPSI;
207 0 : if ( m_xComponent.is() )
208 0 : xPSI = m_xComponent->getPropertySetInfo();
209 :
210 0 : return xPSI.is()
211 0 : && xPSI->hasPropertyByName( PROPERTY_RICHTEXT )
212 0 : && xPSI->hasPropertyByName( PROPERTY_MULTILINE );
213 : }
214 :
215 : //--------------------------------------------------------------------
216 0 : Sequence< Property > SAL_CALL EditPropertyHandler::doDescribeSupportedProperties() const
217 : {
218 0 : ::std::vector< Property > aProperties;
219 :
220 0 : if ( implHaveBothScrollBarProperties() )
221 0 : addInt32PropertyDescription( aProperties, PROPERTY_SHOW_SCROLLBARS );
222 :
223 0 : if ( implHaveTextTypeProperty() )
224 0 : addInt32PropertyDescription( aProperties, PROPERTY_TEXTTYPE );
225 :
226 0 : if ( aProperties.empty() )
227 0 : return Sequence< Property >();
228 0 : return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
229 : }
230 :
231 : //--------------------------------------------------------------------
232 0 : Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupersededProperties( ) throw (RuntimeException)
233 : {
234 0 : ::osl::MutexGuard aGuard( m_aMutex );
235 0 : ::std::vector< ::rtl::OUString > aSuperseded;
236 0 : if ( implHaveBothScrollBarProperties() )
237 : {
238 0 : aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_HSCROLL) );
239 0 : aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_VSCROLL) );
240 : }
241 0 : if ( implHaveTextTypeProperty() )
242 : {
243 0 : aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_RICHTEXT) );
244 0 : aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_MULTILINE) );
245 : }
246 0 : if ( aSuperseded.empty() )
247 0 : return Sequence< ::rtl::OUString >();
248 0 : return Sequence< ::rtl::OUString >( &(*aSuperseded.begin()), aSuperseded.size() );
249 : }
250 :
251 : //--------------------------------------------------------------------
252 0 : Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getActuatingProperties( ) throw (RuntimeException)
253 : {
254 0 : ::osl::MutexGuard aGuard( m_aMutex );
255 0 : ::std::vector< ::rtl::OUString > aInterestingActuatingProps;
256 0 : if ( implHaveTextTypeProperty() )
257 0 : aInterestingActuatingProps.push_back( static_cast<const rtl::OUString&>(PROPERTY_TEXTTYPE) );
258 0 : aInterestingActuatingProps.push_back( static_cast<const rtl::OUString&>(PROPERTY_MULTILINE) );
259 0 : return Sequence< ::rtl::OUString >( &(*aInterestingActuatingProps.begin()), aInterestingActuatingProps.size() );
260 : }
261 :
262 : //--------------------------------------------------------------------
263 0 : void SAL_CALL EditPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool ) throw (NullPointerException, RuntimeException)
264 : {
265 0 : if ( !_rxInspectorUI.is() )
266 0 : throw NullPointerException();
267 :
268 0 : ::osl::MutexGuard aGuard( m_aMutex );
269 0 : PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
270 0 : switch ( nActuatingPropId )
271 : {
272 : case PROPERTY_ID_TEXTTYPE:
273 : {
274 0 : sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
275 0 : getPropertyValue( PROPERTY_TEXTTYPE ) >>= nTextType;
276 :
277 0 : if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_WORDBREAK ) )
278 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_WORDBREAK, nTextType == TEXTTYPE_RICHTEXT );
279 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_MAXTEXTLEN, nTextType != TEXTTYPE_RICHTEXT );
280 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, nTextType == TEXTTYPE_SINGLELINE );
281 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_FONT, nTextType != TEXTTYPE_RICHTEXT );
282 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_ALIGN, nTextType != TEXTTYPE_RICHTEXT );
283 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_DEFAULT_TEXT, nTextType != TEXTTYPE_RICHTEXT );
284 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, nTextType != TEXTTYPE_SINGLELINE );
285 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, nTextType != TEXTTYPE_SINGLELINE );
286 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_VERTICAL_ALIGN, nTextType == TEXTTYPE_SINGLELINE );
287 :
288 0 : _rxInspectorUI->showCategory( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Data" ) ), nTextType != TEXTTYPE_RICHTEXT );
289 : }
290 0 : break;
291 :
292 : case PROPERTY_ID_MULTILINE:
293 : {
294 0 : sal_Bool bIsMultiline = sal_False;
295 0 : _rNewValue >>= bIsMultiline;
296 :
297 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, bIsMultiline );
298 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, !bIsMultiline );
299 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, bIsMultiline );
300 : }
301 0 : break;
302 :
303 : default:
304 : OSL_FAIL( "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
305 0 : }
306 0 : }
307 :
308 : //........................................................................
309 : } // namespace pcr
310 : //........................................................................
311 :
312 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|