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 <tools/debug.hxx>
27 #define TEXTTYPE_SINGLELINE 0
28 #define TEXTTYPE_MULTILINE 1
29 #define TEXTTYPE_RICHTEXT 2
31 //------------------------------------------------------------------------
32 extern "C" void SAL_CALL
createRegistryInfo_EditPropertyHandler()
34 ::pcr::EditPropertyHandler::registerImplementation();
37 //........................................................................
40 //........................................................................
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
;
49 //====================================================================
50 //= EditPropertyHandler
51 //====================================================================
52 DBG_NAME( EditPropertyHandler
)
53 //--------------------------------------------------------------------
54 EditPropertyHandler::EditPropertyHandler( const Reference
< XComponentContext
>& _rxContext
)
55 :EditPropertyHandler_Base( _rxContext
)
57 DBG_CTOR( EditPropertyHandler
, NULL
);
60 //--------------------------------------------------------------------
61 EditPropertyHandler::~EditPropertyHandler( )
63 DBG_DTOR( EditPropertyHandler
, NULL
);
66 //--------------------------------------------------------------------
67 OUString SAL_CALL
EditPropertyHandler::getImplementationName_static( ) throw (RuntimeException
)
69 return OUString( "com.sun.star.comp.extensions.EditPropertyHandler" );
72 //--------------------------------------------------------------------
73 Sequence
< OUString
> SAL_CALL
EditPropertyHandler::getSupportedServiceNames_static( ) throw (RuntimeException
)
75 Sequence
< OUString
> aSupported( 1 );
76 aSupported
[0] = OUString( "com.sun.star.form.inspection.EditPropertyHandler" );
80 //--------------------------------------------------------------------
81 Any SAL_CALL
EditPropertyHandler::getPropertyValue( const OUString
& _rPropertyName
) throw (UnknownPropertyException
, RuntimeException
)
83 ::osl::MutexGuard
aGuard( m_aMutex
);
84 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
91 case PROPERTY_ID_SHOW_SCROLLBARS
:
93 sal_Bool bHasVScroll
= sal_False
;
94 m_xComponent
->getPropertyValue( PROPERTY_VSCROLL
) >>= bHasVScroll
;
95 sal_Bool bHasHScroll
= sal_False
;
96 m_xComponent
->getPropertyValue( PROPERTY_HSCROLL
) >>= bHasHScroll
;
98 aReturn
<<= (sal_Int32
)( ( bHasVScroll
? 2 : 0 ) + ( bHasHScroll
? 1 : 0 ) );
102 case PROPERTY_ID_TEXTTYPE
:
104 sal_Int32 nTextType
= TEXTTYPE_SINGLELINE
;
105 sal_Bool bRichText
= sal_False
;
106 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_RICHTEXT
) >>= bRichText
);
108 nTextType
= TEXTTYPE_RICHTEXT
;
111 sal_Bool bMultiLine
= sal_False
;
112 OSL_VERIFY( m_xComponent
->getPropertyValue( PROPERTY_MULTILINE
) >>= bMultiLine
);
114 nTextType
= TEXTTYPE_MULTILINE
;
116 nTextType
= TEXTTYPE_SINGLELINE
;
118 aReturn
<<= nTextType
;
124 OSL_FAIL( "EditPropertyHandler::getPropertyValue: cannot handle this property!" );
128 catch( const Exception
& )
130 OSL_FAIL( "EditPropertyHandler::getPropertyValue: caught an exception!" );
136 //--------------------------------------------------------------------
137 void SAL_CALL
EditPropertyHandler::setPropertyValue( const OUString
& _rPropertyName
, const Any
& _rValue
) throw (UnknownPropertyException
, RuntimeException
)
139 ::osl::MutexGuard
aGuard( m_aMutex
);
140 PropertyId
nPropId( impl_getPropertyId_throw( _rPropertyName
) );
146 case PROPERTY_ID_SHOW_SCROLLBARS
:
148 sal_Int32 nScrollbars
= 0;
149 _rValue
>>= nScrollbars
;
151 sal_Bool bHasVScroll
= 0 != ( nScrollbars
& 2 );
152 sal_Bool bHasHScroll
= 0 != ( nScrollbars
& 1 );
154 m_xComponent
->setPropertyValue( PROPERTY_VSCROLL
, makeAny( (sal_Bool
)bHasVScroll
) );
155 m_xComponent
->setPropertyValue( PROPERTY_HSCROLL
, makeAny( (sal_Bool
)bHasHScroll
) );
159 case PROPERTY_ID_TEXTTYPE
:
161 sal_Bool bMultiLine
= sal_False
;
162 sal_Bool bRichText
= sal_False
;
163 sal_Int32 nTextType
= TEXTTYPE_SINGLELINE
;
164 OSL_VERIFY( _rValue
>>= nTextType
);
167 case TEXTTYPE_SINGLELINE
: bMultiLine
= bRichText
= sal_False
; break;
168 case TEXTTYPE_MULTILINE
: bMultiLine
= sal_True
; bRichText
= sal_False
; break;
169 case TEXTTYPE_RICHTEXT
: bMultiLine
= sal_True
; bRichText
= sal_True
; break;
171 OSL_FAIL( "EditPropertyHandler::setPropertyValue: invalid text type!" );
174 m_xComponent
->setPropertyValue( PROPERTY_MULTILINE
, makeAny( bMultiLine
) );
175 m_xComponent
->setPropertyValue( PROPERTY_RICHTEXT
, makeAny( bRichText
) );
180 OSL_FAIL( "EditPropertyHandler::setPropertyValue: cannot handle this id!" );
183 catch( const Exception
& )
185 OSL_FAIL( "EditPropertyHandler::setPropertyValue: caught an exception!" );
189 //--------------------------------------------------------------------
190 bool EditPropertyHandler::implHaveBothScrollBarProperties() const
192 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
193 Reference
< XPropertySetInfo
> xPSI
;
194 if ( m_xComponent
.is() )
195 xPSI
= m_xComponent
->getPropertySetInfo();
198 && xPSI
->hasPropertyByName( PROPERTY_HSCROLL
)
199 && xPSI
->hasPropertyByName( PROPERTY_VSCROLL
);
202 //--------------------------------------------------------------------
203 bool EditPropertyHandler::implHaveTextTypeProperty() const
205 // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
206 Reference
< XPropertySetInfo
> xPSI
;
207 if ( m_xComponent
.is() )
208 xPSI
= m_xComponent
->getPropertySetInfo();
211 && xPSI
->hasPropertyByName( PROPERTY_RICHTEXT
)
212 && xPSI
->hasPropertyByName( PROPERTY_MULTILINE
);
215 //--------------------------------------------------------------------
216 Sequence
< Property
> SAL_CALL
EditPropertyHandler::doDescribeSupportedProperties() const
218 ::std::vector
< Property
> aProperties
;
220 if ( implHaveBothScrollBarProperties() )
221 addInt32PropertyDescription( aProperties
, PROPERTY_SHOW_SCROLLBARS
);
223 if ( implHaveTextTypeProperty() )
224 addInt32PropertyDescription( aProperties
, PROPERTY_TEXTTYPE
);
226 if ( aProperties
.empty() )
227 return Sequence
< Property
>();
228 return Sequence
< Property
>( &(*aProperties
.begin()), aProperties
.size() );
231 //--------------------------------------------------------------------
232 Sequence
< OUString
> SAL_CALL
EditPropertyHandler::getSupersededProperties( ) throw (RuntimeException
)
234 ::osl::MutexGuard
aGuard( m_aMutex
);
235 ::std::vector
< OUString
> aSuperseded
;
236 if ( implHaveBothScrollBarProperties() )
238 aSuperseded
.push_back( static_cast<const OUString
&>(PROPERTY_HSCROLL
) );
239 aSuperseded
.push_back( static_cast<const OUString
&>(PROPERTY_VSCROLL
) );
241 if ( implHaveTextTypeProperty() )
243 aSuperseded
.push_back( static_cast<const OUString
&>(PROPERTY_RICHTEXT
) );
244 aSuperseded
.push_back( static_cast<const OUString
&>(PROPERTY_MULTILINE
) );
246 if ( aSuperseded
.empty() )
247 return Sequence
< OUString
>();
248 return Sequence
< OUString
>( &(*aSuperseded
.begin()), aSuperseded
.size() );
251 //--------------------------------------------------------------------
252 Sequence
< OUString
> SAL_CALL
EditPropertyHandler::getActuatingProperties( ) throw (RuntimeException
)
254 ::osl::MutexGuard
aGuard( m_aMutex
);
255 ::std::vector
< OUString
> aInterestingActuatingProps
;
256 if ( implHaveTextTypeProperty() )
257 aInterestingActuatingProps
.push_back( static_cast<const OUString
&>(PROPERTY_TEXTTYPE
) );
258 aInterestingActuatingProps
.push_back( static_cast<const OUString
&>(PROPERTY_MULTILINE
) );
259 return Sequence
< OUString
>( &(*aInterestingActuatingProps
.begin()), aInterestingActuatingProps
.size() );
262 //--------------------------------------------------------------------
263 void SAL_CALL
EditPropertyHandler::actuatingPropertyChanged( const OUString
& _rActuatingPropertyName
, const Any
& _rNewValue
, const Any
& /*_rOldValue*/, const Reference
< XObjectInspectorUI
>& _rxInspectorUI
, sal_Bool
) throw (NullPointerException
, RuntimeException
)
265 if ( !_rxInspectorUI
.is() )
266 throw NullPointerException();
268 ::osl::MutexGuard
aGuard( m_aMutex
);
269 PropertyId
nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName
) );
270 switch ( nActuatingPropId
)
272 case PROPERTY_ID_TEXTTYPE
:
274 sal_Int32 nTextType
= TEXTTYPE_SINGLELINE
;
275 getPropertyValue( PROPERTY_TEXTTYPE
) >>= nTextType
;
277 if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_WORDBREAK
) )
278 _rxInspectorUI
->enablePropertyUI( PROPERTY_WORDBREAK
, nTextType
== TEXTTYPE_RICHTEXT
);
279 _rxInspectorUI
->enablePropertyUI( PROPERTY_MAXTEXTLEN
, nTextType
!= TEXTTYPE_RICHTEXT
);
280 _rxInspectorUI
->enablePropertyUI( PROPERTY_ECHO_CHAR
, nTextType
== TEXTTYPE_SINGLELINE
);
281 _rxInspectorUI
->enablePropertyUI( PROPERTY_FONT
, nTextType
!= TEXTTYPE_RICHTEXT
);
282 _rxInspectorUI
->enablePropertyUI( PROPERTY_ALIGN
, nTextType
!= TEXTTYPE_RICHTEXT
);
283 _rxInspectorUI
->enablePropertyUI( PROPERTY_DEFAULT_TEXT
, nTextType
!= TEXTTYPE_RICHTEXT
);
284 _rxInspectorUI
->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS
, nTextType
!= TEXTTYPE_SINGLELINE
);
285 _rxInspectorUI
->enablePropertyUI( PROPERTY_LINEEND_FORMAT
, nTextType
!= TEXTTYPE_SINGLELINE
);
286 _rxInspectorUI
->enablePropertyUI( PROPERTY_VERTICAL_ALIGN
, nTextType
== TEXTTYPE_SINGLELINE
);
288 _rxInspectorUI
->showCategory( OUString( "Data" ), nTextType
!= TEXTTYPE_RICHTEXT
);
292 case PROPERTY_ID_MULTILINE
:
294 sal_Bool bIsMultiline
= sal_False
;
295 _rNewValue
>>= bIsMultiline
;
297 _rxInspectorUI
->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS
, bIsMultiline
);
298 _rxInspectorUI
->enablePropertyUI( PROPERTY_ECHO_CHAR
, !bIsMultiline
);
299 _rxInspectorUI
->enablePropertyUI( PROPERTY_LINEEND_FORMAT
, bIsMultiline
);
304 OSL_FAIL( "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
308 //........................................................................
310 //........................................................................
312 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */