Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "editpropertyhandler.hxx"
30 : : #include "formstrings.hxx"
31 : : #include "formmetadata.hxx"
32 : :
33 : : #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
34 : : #include <tools/debug.hxx>
35 : :
36 : : #define TEXTTYPE_SINGLELINE 0
37 : : #define TEXTTYPE_MULTILINE 1
38 : : #define TEXTTYPE_RICHTEXT 2
39 : :
40 : : //------------------------------------------------------------------------
41 : 0 : extern "C" void SAL_CALL createRegistryInfo_EditPropertyHandler()
42 : : {
43 : 0 : ::pcr::EditPropertyHandler::registerImplementation();
44 : 0 : }
45 : :
46 : : //........................................................................
47 : : namespace pcr
48 : : {
49 : : //........................................................................
50 : :
51 : : using namespace ::com::sun::star::uno;
52 : : using namespace ::com::sun::star::lang;
53 : : using namespace ::com::sun::star::beans;
54 : : using namespace ::com::sun::star::script;
55 : : using namespace ::com::sun::star::frame;
56 : : using namespace ::com::sun::star::inspection;
57 : :
58 : : //====================================================================
59 : : //= EditPropertyHandler
60 : : //====================================================================
61 : : DBG_NAME( EditPropertyHandler )
62 : : //--------------------------------------------------------------------
63 : 0 : EditPropertyHandler::EditPropertyHandler( const Reference< XComponentContext >& _rxContext )
64 : 0 : :EditPropertyHandler_Base( _rxContext )
65 : : {
66 : : DBG_CTOR( EditPropertyHandler, NULL );
67 : 0 : }
68 : :
69 : : //--------------------------------------------------------------------
70 : 0 : EditPropertyHandler::~EditPropertyHandler( )
71 : : {
72 : : DBG_DTOR( EditPropertyHandler, NULL );
73 : 0 : }
74 : :
75 : : //--------------------------------------------------------------------
76 : 0 : ::rtl::OUString SAL_CALL EditPropertyHandler::getImplementationName_static( ) throw (RuntimeException)
77 : : {
78 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.EditPropertyHandler" ) );
79 : : }
80 : :
81 : : //--------------------------------------------------------------------
82 : 0 : Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
83 : : {
84 : 0 : Sequence< ::rtl::OUString > aSupported( 1 );
85 : 0 : aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.EditPropertyHandler" ) );
86 : 0 : return aSupported;
87 : : }
88 : :
89 : : //--------------------------------------------------------------------
90 : 0 : Any SAL_CALL EditPropertyHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
91 : : {
92 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
93 : 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
94 : :
95 : 0 : Any aReturn;
96 : : try
97 : : {
98 : 0 : switch ( nPropId )
99 : : {
100 : : case PROPERTY_ID_SHOW_SCROLLBARS:
101 : : {
102 : 0 : sal_Bool bHasVScroll = sal_False;
103 : 0 : m_xComponent->getPropertyValue( PROPERTY_VSCROLL ) >>= bHasVScroll;
104 : 0 : sal_Bool bHasHScroll = sal_False;
105 : 0 : m_xComponent->getPropertyValue( PROPERTY_HSCROLL ) >>= bHasHScroll;
106 : :
107 : 0 : aReturn <<= (sal_Int32)( ( bHasVScroll ? 2 : 0 ) + ( bHasHScroll ? 1 : 0 ) );
108 : : }
109 : 0 : break;
110 : :
111 : : case PROPERTY_ID_TEXTTYPE:
112 : : {
113 : 0 : sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
114 : 0 : sal_Bool bRichText = sal_False;
115 : 0 : OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_RICHTEXT ) >>= bRichText );
116 : 0 : if ( bRichText )
117 : 0 : nTextType = TEXTTYPE_RICHTEXT;
118 : : else
119 : : {
120 : 0 : sal_Bool bMultiLine = sal_False;
121 : 0 : OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_MULTILINE ) >>= bMultiLine );
122 : 0 : if ( bMultiLine )
123 : 0 : nTextType = TEXTTYPE_MULTILINE;
124 : : else
125 : 0 : nTextType = TEXTTYPE_SINGLELINE;
126 : : }
127 : 0 : aReturn <<= nTextType;
128 : : }
129 : 0 : break;
130 : :
131 : :
132 : : default:
133 : : OSL_FAIL( "EditPropertyHandler::getPropertyValue: cannot handle this property!" );
134 : 0 : break;
135 : : }
136 : : }
137 : 0 : catch( const Exception& )
138 : : {
139 : : OSL_FAIL( "EditPropertyHandler::getPropertyValue: caught an exception!" );
140 : : }
141 : :
142 : 0 : return aReturn;
143 : : }
144 : :
145 : : //--------------------------------------------------------------------
146 : 0 : void SAL_CALL EditPropertyHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
147 : : {
148 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
149 : 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
150 : :
151 : : try
152 : : {
153 : 0 : switch ( nPropId )
154 : : {
155 : : case PROPERTY_ID_SHOW_SCROLLBARS:
156 : : {
157 : 0 : sal_Int32 nScrollbars = 0;
158 : 0 : _rValue >>= nScrollbars;
159 : :
160 : 0 : sal_Bool bHasVScroll = 0 != ( nScrollbars & 2 );
161 : 0 : sal_Bool bHasHScroll = 0 != ( nScrollbars & 1 );
162 : :
163 : 0 : m_xComponent->setPropertyValue( PROPERTY_VSCROLL, makeAny( (sal_Bool)bHasVScroll ) );
164 : 0 : m_xComponent->setPropertyValue( PROPERTY_HSCROLL, makeAny( (sal_Bool)bHasHScroll ) );
165 : : }
166 : 0 : break;
167 : :
168 : : case PROPERTY_ID_TEXTTYPE:
169 : : {
170 : 0 : sal_Bool bMultiLine = sal_False;
171 : 0 : sal_Bool bRichText = sal_False;
172 : 0 : sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
173 : 0 : OSL_VERIFY( _rValue >>= nTextType );
174 : 0 : switch ( nTextType )
175 : : {
176 : 0 : case TEXTTYPE_SINGLELINE: bMultiLine = bRichText = sal_False; break;
177 : 0 : case TEXTTYPE_MULTILINE: bMultiLine = sal_True; bRichText = sal_False; break;
178 : 0 : case TEXTTYPE_RICHTEXT: bMultiLine = sal_True; bRichText = sal_True; break;
179 : : default:
180 : : OSL_FAIL( "EditPropertyHandler::setPropertyValue: invalid text type!" );
181 : : }
182 : :
183 : 0 : m_xComponent->setPropertyValue( PROPERTY_MULTILINE, makeAny( bMultiLine ) );
184 : 0 : m_xComponent->setPropertyValue( PROPERTY_RICHTEXT, makeAny( bRichText ) );
185 : : }
186 : 0 : break;
187 : :
188 : : default:
189 : : OSL_FAIL( "EditPropertyHandler::setPropertyValue: cannot handle this id!" );
190 : : }
191 : : }
192 : 0 : catch( const Exception& )
193 : : {
194 : : OSL_FAIL( "EditPropertyHandler::setPropertyValue: caught an exception!" );
195 : 0 : }
196 : 0 : }
197 : :
198 : : //--------------------------------------------------------------------
199 : 0 : bool EditPropertyHandler::implHaveBothScrollBarProperties() const
200 : : {
201 : : // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
202 : 0 : Reference< XPropertySetInfo > xPSI;
203 : 0 : if ( m_xComponent.is() )
204 : 0 : xPSI = m_xComponent->getPropertySetInfo();
205 : :
206 : 0 : return xPSI.is()
207 : 0 : && xPSI->hasPropertyByName( PROPERTY_HSCROLL )
208 : 0 : && xPSI->hasPropertyByName( PROPERTY_VSCROLL );
209 : : }
210 : :
211 : : //--------------------------------------------------------------------
212 : 0 : bool EditPropertyHandler::implHaveTextTypeProperty() const
213 : : {
214 : : // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
215 : 0 : Reference< XPropertySetInfo > xPSI;
216 : 0 : if ( m_xComponent.is() )
217 : 0 : xPSI = m_xComponent->getPropertySetInfo();
218 : :
219 : 0 : return xPSI.is()
220 : 0 : && xPSI->hasPropertyByName( PROPERTY_RICHTEXT )
221 : 0 : && xPSI->hasPropertyByName( PROPERTY_MULTILINE );
222 : : }
223 : :
224 : : //--------------------------------------------------------------------
225 : 0 : Sequence< Property > SAL_CALL EditPropertyHandler::doDescribeSupportedProperties() const
226 : : {
227 : 0 : ::std::vector< Property > aProperties;
228 : :
229 : 0 : if ( implHaveBothScrollBarProperties() )
230 : 0 : addInt32PropertyDescription( aProperties, PROPERTY_SHOW_SCROLLBARS );
231 : :
232 : 0 : if ( implHaveTextTypeProperty() )
233 : 0 : addInt32PropertyDescription( aProperties, PROPERTY_TEXTTYPE );
234 : :
235 : 0 : if ( aProperties.empty() )
236 : 0 : return Sequence< Property >();
237 : 0 : return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
238 : : }
239 : :
240 : : //--------------------------------------------------------------------
241 : 0 : Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupersededProperties( ) throw (RuntimeException)
242 : : {
243 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
244 : 0 : ::std::vector< ::rtl::OUString > aSuperseded;
245 : 0 : if ( implHaveBothScrollBarProperties() )
246 : : {
247 : 0 : aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_HSCROLL) );
248 : 0 : aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_VSCROLL) );
249 : : }
250 : 0 : if ( implHaveTextTypeProperty() )
251 : : {
252 : 0 : aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_RICHTEXT) );
253 : 0 : aSuperseded.push_back( static_cast<const rtl::OUString&>(PROPERTY_MULTILINE) );
254 : : }
255 : 0 : if ( aSuperseded.empty() )
256 : 0 : return Sequence< ::rtl::OUString >();
257 : 0 : return Sequence< ::rtl::OUString >( &(*aSuperseded.begin()), aSuperseded.size() );
258 : : }
259 : :
260 : : //--------------------------------------------------------------------
261 : 0 : Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getActuatingProperties( ) throw (RuntimeException)
262 : : {
263 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
264 : 0 : ::std::vector< ::rtl::OUString > aInterestingActuatingProps;
265 : 0 : if ( implHaveTextTypeProperty() )
266 : 0 : aInterestingActuatingProps.push_back( static_cast<const rtl::OUString&>(PROPERTY_TEXTTYPE) );
267 : 0 : aInterestingActuatingProps.push_back( static_cast<const rtl::OUString&>(PROPERTY_MULTILINE) );
268 : 0 : return Sequence< ::rtl::OUString >( &(*aInterestingActuatingProps.begin()), aInterestingActuatingProps.size() );
269 : : }
270 : :
271 : : //--------------------------------------------------------------------
272 : 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)
273 : : {
274 : 0 : if ( !_rxInspectorUI.is() )
275 : 0 : throw NullPointerException();
276 : :
277 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
278 : 0 : PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
279 : 0 : switch ( nActuatingPropId )
280 : : {
281 : : case PROPERTY_ID_TEXTTYPE:
282 : : {
283 : 0 : sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
284 : 0 : getPropertyValue( PROPERTY_TEXTTYPE ) >>= nTextType;
285 : :
286 : 0 : if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_WORDBREAK ) )
287 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_WORDBREAK, nTextType == TEXTTYPE_RICHTEXT );
288 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_MAXTEXTLEN, nTextType != TEXTTYPE_RICHTEXT );
289 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, nTextType == TEXTTYPE_SINGLELINE );
290 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_FONT, nTextType != TEXTTYPE_RICHTEXT );
291 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_ALIGN, nTextType != TEXTTYPE_RICHTEXT );
292 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_DEFAULT_TEXT, nTextType != TEXTTYPE_RICHTEXT );
293 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, nTextType != TEXTTYPE_SINGLELINE );
294 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, nTextType != TEXTTYPE_SINGLELINE );
295 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_VERTICAL_ALIGN, nTextType == TEXTTYPE_SINGLELINE );
296 : :
297 : 0 : _rxInspectorUI->showCategory( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Data" ) ), nTextType != TEXTTYPE_RICHTEXT );
298 : : }
299 : 0 : break;
300 : :
301 : : case PROPERTY_ID_MULTILINE:
302 : : {
303 : 0 : sal_Bool bIsMultiline = sal_False;
304 : 0 : _rNewValue >>= bIsMultiline;
305 : :
306 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, bIsMultiline );
307 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, !bIsMultiline );
308 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, bIsMultiline );
309 : : }
310 : 0 : break;
311 : :
312 : : default:
313 : : OSL_FAIL( "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
314 : 0 : }
315 : 0 : }
316 : :
317 : : //........................................................................
318 : : } // namespace pcr
319 : : //........................................................................
320 : :
321 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|