1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_extensions.hxx"
26 #include "editpropertyhandler.hxx"
27 #include "formstrings.hxx"
28 #include "formmetadata.hxx"
29 
30 /** === begin UNO includes === **/
31 #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
32 /** === end UNO includes === **/
33 #include <tools/debug.hxx>
34 
35 #define TEXTTYPE_SINGLELINE     0
36 #define TEXTTYPE_MULTILINE      1
37 #define TEXTTYPE_RICHTEXT       2
38 
39 //------------------------------------------------------------------------
createRegistryInfo_EditPropertyHandler()40 extern "C" void SAL_CALL createRegistryInfo_EditPropertyHandler()
41 {
42     ::pcr::EditPropertyHandler::registerImplementation();
43 }
44 
45 //........................................................................
46 namespace pcr
47 {
48 //........................................................................
49 
50     using namespace ::com::sun::star::uno;
51     using namespace ::com::sun::star::lang;
52     using namespace ::com::sun::star::beans;
53     using namespace ::com::sun::star::script;
54     using namespace ::com::sun::star::frame;
55     using namespace ::com::sun::star::inspection;
56 
57     //====================================================================
58 	//= EditPropertyHandler
59 	//====================================================================
DBG_NAME(EditPropertyHandler)60     DBG_NAME( EditPropertyHandler )
61 	//--------------------------------------------------------------------
62     EditPropertyHandler::EditPropertyHandler( const Reference< XComponentContext >& _rxContext )
63         :EditPropertyHandler_Base( _rxContext )
64     {
65         DBG_CTOR( EditPropertyHandler, NULL );
66     }
67 
68 	//--------------------------------------------------------------------
~EditPropertyHandler()69     EditPropertyHandler::~EditPropertyHandler( )
70     {
71         DBG_DTOR( EditPropertyHandler, NULL );
72     }
73 
74     //--------------------------------------------------------------------
getImplementationName_static()75     ::rtl::OUString SAL_CALL EditPropertyHandler::getImplementationName_static(  ) throw (RuntimeException)
76     {
77         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.EditPropertyHandler" ) );
78     }
79 
80     //--------------------------------------------------------------------
getSupportedServiceNames_static()81     Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupportedServiceNames_static(  ) throw (RuntimeException)
82     {
83         Sequence< ::rtl::OUString > aSupported( 1 );
84         aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.EditPropertyHandler" ) );
85         return aSupported;
86     }
87 
88     //--------------------------------------------------------------------
getPropertyValue(const::rtl::OUString & _rPropertyName)89     Any SAL_CALL EditPropertyHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
90     {
91         ::osl::MutexGuard aGuard( m_aMutex );
92         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
93 
94         Any aReturn;
95         try
96         {
97             switch ( nPropId )
98             {
99             case PROPERTY_ID_SHOW_SCROLLBARS:
100             {
101                 sal_Bool bHasVScroll = sal_False;
102                 m_xComponent->getPropertyValue( PROPERTY_VSCROLL ) >>= bHasVScroll;
103                 sal_Bool bHasHScroll = sal_False;
104                 m_xComponent->getPropertyValue( PROPERTY_HSCROLL ) >>= bHasHScroll;
105 
106                 aReturn <<= (sal_Int32)( ( bHasVScroll ? 2 : 0 ) + ( bHasHScroll ? 1 : 0 ) );
107             }
108             break;
109 
110             case PROPERTY_ID_TEXTTYPE:
111             {
112                 sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
113                 sal_Bool bRichText = sal_False;
114                 OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_RICHTEXT ) >>= bRichText );
115                 if ( bRichText )
116                     nTextType = TEXTTYPE_RICHTEXT;
117                 else
118                 {
119                     sal_Bool bMultiLine = sal_False;
120                     OSL_VERIFY( m_xComponent->getPropertyValue( PROPERTY_MULTILINE ) >>= bMultiLine );
121                     if ( bMultiLine )
122                         nTextType = TEXTTYPE_MULTILINE;
123                     else
124                         nTextType = TEXTTYPE_SINGLELINE;
125                 }
126                 aReturn <<= nTextType;
127             }
128             break;
129 
130 
131             default:
132                 DBG_ERROR( "EditPropertyHandler::getPropertyValue: cannot handle this property!" );
133                 break;
134             }
135         }
136         catch( const Exception& )
137         {
138         	OSL_ENSURE( sal_False, "EditPropertyHandler::getPropertyValue: caught an exception!" );
139         }
140 
141         return aReturn;
142     }
143 
144     //--------------------------------------------------------------------
setPropertyValue(const::rtl::OUString & _rPropertyName,const Any & _rValue)145     void SAL_CALL EditPropertyHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
146     {
147         ::osl::MutexGuard aGuard( m_aMutex );
148         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
149 
150         try
151         {
152             switch ( nPropId )
153             {
154             case PROPERTY_ID_SHOW_SCROLLBARS:
155             {
156                 sal_Int32 nScrollbars = 0;
157                 _rValue >>= nScrollbars;
158 
159                 sal_Bool bHasVScroll = 0 != ( nScrollbars & 2 );
160                 sal_Bool bHasHScroll = 0 != ( nScrollbars & 1 );
161 
162                 m_xComponent->setPropertyValue( PROPERTY_VSCROLL, makeAny( (sal_Bool)bHasVScroll ) );
163                 m_xComponent->setPropertyValue( PROPERTY_HSCROLL, makeAny( (sal_Bool)bHasHScroll ) );
164             }
165             break;
166 
167             case PROPERTY_ID_TEXTTYPE:
168             {
169                 sal_Bool bMultiLine = sal_False;
170                 sal_Bool bRichText = sal_False;
171                 sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
172                 OSL_VERIFY( _rValue >>= nTextType );
173                 switch ( nTextType )
174                 {
175                 case TEXTTYPE_SINGLELINE: bMultiLine = bRichText = sal_False; break;
176                 case TEXTTYPE_MULTILINE:  bMultiLine = sal_True; bRichText = sal_False; break;
177                 case TEXTTYPE_RICHTEXT:   bMultiLine = sal_True; bRichText = sal_True; break;
178                 default:
179                     OSL_ENSURE( sal_False, "EditPropertyHandler::setPropertyValue: invalid text type!" );
180                 }
181 
182                 m_xComponent->setPropertyValue( PROPERTY_MULTILINE, makeAny( bMultiLine ) );
183                 m_xComponent->setPropertyValue( PROPERTY_RICHTEXT, makeAny( bRichText ) );
184             }
185             break;
186 
187             default:
188                 OSL_ENSURE( sal_False, "EditPropertyHandler::setPropertyValue: cannot handle this id!" );
189             }
190         }
191         catch( const Exception& )
192         {
193         	OSL_ENSURE( sal_False, "EditPropertyHandler::setPropertyValue: caught an exception!" );
194         }
195     }
196 
197     //--------------------------------------------------------------------
implHaveBothScrollBarProperties() const198     bool EditPropertyHandler::implHaveBothScrollBarProperties() const
199     {
200         // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
201         Reference< XPropertySetInfo > xPSI;
202         if ( m_xComponent.is() )
203             xPSI = m_xComponent->getPropertySetInfo();
204 
205         return xPSI.is()
206             && xPSI->hasPropertyByName( PROPERTY_HSCROLL )
207             && xPSI->hasPropertyByName( PROPERTY_VSCROLL );
208     }
209 
210     //--------------------------------------------------------------------
implHaveTextTypeProperty() const211     bool EditPropertyHandler::implHaveTextTypeProperty() const
212     {
213         // have a "Scrollbars" property if the object supports both "HScroll" and "VScroll"
214         Reference< XPropertySetInfo > xPSI;
215         if ( m_xComponent.is() )
216             xPSI = m_xComponent->getPropertySetInfo();
217 
218         return xPSI.is()
219             && xPSI->hasPropertyByName( PROPERTY_RICHTEXT )
220             && xPSI->hasPropertyByName( PROPERTY_MULTILINE );
221     }
222 
223     //--------------------------------------------------------------------
doDescribeSupportedProperties() const224     Sequence< Property > SAL_CALL EditPropertyHandler::doDescribeSupportedProperties() const
225     {
226         ::std::vector< Property > aProperties;
227 
228         if ( implHaveBothScrollBarProperties() )
229             addInt32PropertyDescription( aProperties, PROPERTY_SHOW_SCROLLBARS );
230 
231         if ( implHaveTextTypeProperty() )
232             addInt32PropertyDescription( aProperties, PROPERTY_TEXTTYPE );
233 
234         if ( aProperties.empty() )
235             return Sequence< Property >();
236         return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
237     }
238 
239     //--------------------------------------------------------------------
getSupersededProperties()240     Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getSupersededProperties( ) throw (RuntimeException)
241     {
242         ::osl::MutexGuard aGuard( m_aMutex );
243         ::std::vector< ::rtl::OUString > aSuperseded;
244         if ( implHaveBothScrollBarProperties() )
245         {
246             aSuperseded.push_back( PROPERTY_HSCROLL );
247             aSuperseded.push_back( PROPERTY_VSCROLL );
248         }
249         if ( implHaveTextTypeProperty() )
250         {
251             aSuperseded.push_back( PROPERTY_RICHTEXT );
252             aSuperseded.push_back( PROPERTY_MULTILINE );
253         }
254         if ( aSuperseded.empty() )
255             return Sequence< ::rtl::OUString >();
256         return Sequence< ::rtl::OUString >( &(*aSuperseded.begin()), aSuperseded.size() );
257     }
258 
259     //--------------------------------------------------------------------
getActuatingProperties()260     Sequence< ::rtl::OUString > SAL_CALL EditPropertyHandler::getActuatingProperties( ) throw (RuntimeException)
261     {
262         ::osl::MutexGuard aGuard( m_aMutex );
263         ::std::vector< ::rtl::OUString > aInterestingActuatingProps;
264         if ( implHaveTextTypeProperty() )
265             aInterestingActuatingProps.push_back( PROPERTY_TEXTTYPE );
266         aInterestingActuatingProps.push_back( PROPERTY_MULTILINE );
267         return Sequence< ::rtl::OUString >( &(*aInterestingActuatingProps.begin()), aInterestingActuatingProps.size() );;
268     }
269 
270     //--------------------------------------------------------------------
actuatingPropertyChanged(const::rtl::OUString & _rActuatingPropertyName,const Any & _rNewValue,const Any &,const Reference<XObjectInspectorUI> & _rxInspectorUI,sal_Bool)271     void SAL_CALL EditPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool ) throw (NullPointerException, RuntimeException)
272     {
273         if ( !_rxInspectorUI.is() )
274             throw NullPointerException();
275 
276         ::osl::MutexGuard aGuard( m_aMutex );
277         PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
278         switch ( nActuatingPropId )
279         {
280         case PROPERTY_ID_TEXTTYPE:
281         {
282             sal_Int32 nTextType = TEXTTYPE_SINGLELINE;
283             getPropertyValue( PROPERTY_TEXTTYPE ) >>= nTextType;
284 
285             if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_WORDBREAK ) )
286                 _rxInspectorUI->enablePropertyUI( PROPERTY_WORDBREAK,   nTextType == TEXTTYPE_RICHTEXT );
287             _rxInspectorUI->enablePropertyUI( PROPERTY_MAXTEXTLEN,      nTextType != TEXTTYPE_RICHTEXT );
288             _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR,       nTextType == TEXTTYPE_SINGLELINE );
289             _rxInspectorUI->enablePropertyUI( PROPERTY_FONT,            nTextType != TEXTTYPE_RICHTEXT );
290             _rxInspectorUI->enablePropertyUI( PROPERTY_ALIGN,           nTextType != TEXTTYPE_RICHTEXT );
291             _rxInspectorUI->enablePropertyUI( PROPERTY_DEFAULT_TEXT,    nTextType != TEXTTYPE_RICHTEXT );
292             _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, nTextType != TEXTTYPE_SINGLELINE );
293             _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT,  nTextType != TEXTTYPE_SINGLELINE );
294             _rxInspectorUI->enablePropertyUI( PROPERTY_VERTICAL_ALIGN,  nTextType == TEXTTYPE_SINGLELINE );
295 
296             _rxInspectorUI->showCategory( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Data" ) ), nTextType != TEXTTYPE_RICHTEXT );
297         }
298         break;
299 
300         case PROPERTY_ID_MULTILINE:
301         {
302             sal_Bool bIsMultiline = sal_False;
303             _rNewValue >>= bIsMultiline;
304 
305             _rxInspectorUI->enablePropertyUI( PROPERTY_SHOW_SCROLLBARS, bIsMultiline );
306             _rxInspectorUI->enablePropertyUI( PROPERTY_ECHO_CHAR, !bIsMultiline );
307             _rxInspectorUI->enablePropertyUI( PROPERTY_LINEEND_FORMAT, bIsMultiline );
308         }
309         break;
310 
311         default:
312             OSL_ENSURE( sal_False, "EditPropertyHandler::actuatingPropertyChanged: cannot handle this id!" );
313         }
314     }
315 
316 //........................................................................
317 }   // namespace pcr
318 //........................................................................
319 
320