1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "buttonnavigationhandler.hxx"
31 #include "formstrings.hxx"
32 #include "formmetadata.hxx"
33 #include "pushbuttonnavigation.hxx"
34 
35 /** === begin UNO includes === **/
36 /** === end UNO includes === **/
37 #include <tools/debug.hxx>
38 
39 //------------------------------------------------------------------------
40 extern "C" void SAL_CALL createRegistryInfo_ButtonNavigationHandler()
41 {
42     ::pcr::ButtonNavigationHandler::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 	//= ButtonNavigationHandler
59 	//====================================================================
60     DBG_NAME( ButtonNavigationHandler )
61 	//--------------------------------------------------------------------
62     ButtonNavigationHandler::ButtonNavigationHandler( const Reference< XComponentContext >& _rxContext )
63         :ButtonNavigationHandler_Base( _rxContext )
64     {
65         DBG_CTOR( ButtonNavigationHandler, NULL );
66 
67         m_aContext.createComponent(
68             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.FormComponentPropertyHandler" ) ),
69             m_xSlaveHandler );
70         if ( !m_xSlaveHandler.is() )
71             throw RuntimeException();
72     }
73 
74 	//--------------------------------------------------------------------
75     ButtonNavigationHandler::~ButtonNavigationHandler( )
76     {
77         DBG_DTOR( ButtonNavigationHandler, NULL );
78     }
79 
80     //--------------------------------------------------------------------
81     ::rtl::OUString SAL_CALL ButtonNavigationHandler::getImplementationName_static(  ) throw (RuntimeException)
82     {
83         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.ButtonNavigationHandler" ) );
84     }
85 
86     //--------------------------------------------------------------------
87     Sequence< ::rtl::OUString > SAL_CALL ButtonNavigationHandler::getSupportedServiceNames_static(  ) throw (RuntimeException)
88     {
89         Sequence< ::rtl::OUString > aSupported( 1 );
90         aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.ButtonNavigationHandler" ) );
91         return aSupported;
92     }
93 
94     //--------------------------------------------------------------------
95     void SAL_CALL ButtonNavigationHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException)
96     {
97         ButtonNavigationHandler_Base::inspect( _rxIntrospectee );
98         m_xSlaveHandler->inspect( _rxIntrospectee );
99     }
100 
101     //--------------------------------------------------------------------
102     PropertyState  SAL_CALL ButtonNavigationHandler::getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
103     {
104         ::osl::MutexGuard aGuard( m_aMutex );
105         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
106         PropertyState eState = PropertyState_DIRECT_VALUE;
107         switch ( nPropId )
108         {
109         case PROPERTY_ID_BUTTONTYPE:
110         {
111             PushButtonNavigation aHelper( m_xComponent );
112             eState = aHelper.getCurrentButtonTypeState();
113         }
114         break;
115         case PROPERTY_ID_TARGET_URL:
116         {
117             PushButtonNavigation aHelper( m_xComponent );
118             eState = aHelper.getCurrentTargetURLState();
119         }
120         break;
121 
122         default:
123             DBG_ERROR( "ButtonNavigationHandler::getPropertyState: cannot handle this property!" );
124             break;
125         }
126 
127         return eState;
128     }
129 
130     //--------------------------------------------------------------------
131     Any SAL_CALL ButtonNavigationHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
132     {
133         ::osl::MutexGuard aGuard( m_aMutex );
134         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
135 
136         Any aReturn;
137         switch ( nPropId )
138         {
139         case PROPERTY_ID_BUTTONTYPE:
140         {
141             PushButtonNavigation aHelper( m_xComponent );
142             aReturn = aHelper.getCurrentButtonType();
143         }
144         break;
145 
146         case PROPERTY_ID_TARGET_URL:
147         {
148             PushButtonNavigation aHelper( m_xComponent );
149             aReturn = aHelper.getCurrentTargetURL();
150         }
151         break;
152 
153         default:
154             DBG_ERROR( "ButtonNavigationHandler::getPropertyValue: cannot handle this property!" );
155             break;
156         }
157 
158         return aReturn;
159     }
160 
161     //--------------------------------------------------------------------
162     void SAL_CALL ButtonNavigationHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
163     {
164         ::osl::MutexGuard aGuard( m_aMutex );
165         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
166         switch ( nPropId )
167         {
168         case PROPERTY_ID_BUTTONTYPE:
169         {
170             PushButtonNavigation aHelper( m_xComponent );
171             aHelper.setCurrentButtonType( _rValue );
172         }
173         break;
174 
175         case PROPERTY_ID_TARGET_URL:
176         {
177             PushButtonNavigation aHelper( m_xComponent );
178             aHelper.setCurrentTargetURL( _rValue );
179         }
180         break;
181 
182         default:
183             OSL_ENSURE( sal_False, "ButtonNavigationHandler::setPropertyValue: cannot handle this id!" );
184         }
185     }
186 
187     //--------------------------------------------------------------------
188     bool ButtonNavigationHandler::isNavigationCapableButton( const Reference< XPropertySet >& _rxComponent )
189     {
190         Reference< XPropertySetInfo > xPSI;
191         if ( _rxComponent.is() )
192             xPSI = _rxComponent->getPropertySetInfo();
193 
194         return xPSI.is()
195             && xPSI->hasPropertyByName( PROPERTY_TARGET_URL )
196             && xPSI->hasPropertyByName( PROPERTY_BUTTONTYPE );
197     }
198 
199     //--------------------------------------------------------------------
200     Sequence< Property > SAL_CALL ButtonNavigationHandler::doDescribeSupportedProperties() const
201     {
202         ::std::vector< Property > aProperties;
203 
204         if ( isNavigationCapableButton( m_xComponent ) )
205         {
206             addStringPropertyDescription( aProperties, PROPERTY_TARGET_URL );
207             implAddPropertyDescription( aProperties, PROPERTY_BUTTONTYPE, ::getCppuType( static_cast< sal_Int32* >( NULL ) ) );
208         }
209 
210         if ( aProperties.empty() )
211             return Sequence< Property >();
212         return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
213     }
214 
215     //--------------------------------------------------------------------
216     Sequence< ::rtl::OUString > SAL_CALL ButtonNavigationHandler::getActuatingProperties( ) throw (RuntimeException)
217     {
218         Sequence< ::rtl::OUString > aActuating( 2 );
219         aActuating[0] = PROPERTY_BUTTONTYPE;
220         aActuating[1] = PROPERTY_TARGET_URL;
221         return aActuating;
222     }
223 
224     //--------------------------------------------------------------------
225     InteractiveSelectionResult SAL_CALL ButtonNavigationHandler::onInteractivePropertySelection( const ::rtl::OUString& _rPropertyName, sal_Bool _bPrimary, Any& _rData, const Reference< XObjectInspectorUI >& _rxInspectorUI ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
226     {
227         ::osl::MutexGuard aGuard( m_aMutex );
228         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
229 
230         InteractiveSelectionResult eReturn( InteractiveSelectionResult_Cancelled );
231 
232         switch ( nPropId )
233         {
234         case PROPERTY_ID_TARGET_URL:
235             eReturn = m_xSlaveHandler->onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
236             break;
237         default:
238             eReturn = ButtonNavigationHandler_Base::onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
239             break;
240         }
241 
242         return eReturn;
243     }
244 
245     //--------------------------------------------------------------------
246     void SAL_CALL ButtonNavigationHandler::actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& /*_rNewValue*/, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool /*_bFirstTimeInit*/ ) throw (NullPointerException, RuntimeException)
247     {
248         ::osl::MutexGuard aGuard( m_aMutex );
249         PropertyId nPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
250         switch ( nPropId )
251         {
252         case PROPERTY_ID_BUTTONTYPE:
253         {
254             PushButtonNavigation aHelper( m_xComponent );
255             _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_URL, aHelper.currentButtonTypeIsOpenURL() );
256         }
257         break;
258 
259         case PROPERTY_ID_TARGET_URL:
260         {
261             PushButtonNavigation aHelper( m_xComponent );
262             _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_FRAME, aHelper.hasNonEmptyCurrentTargetURL() );
263         }
264         break;
265 
266         default:
267             OSL_ENSURE( sal_False, "ButtonNavigationHandler::actuatingPropertyChanged: cannot handle this id!" );
268         }
269     }
270 
271     //--------------------------------------------------------------------
272     LineDescriptor SAL_CALL ButtonNavigationHandler::describePropertyLine( const ::rtl::OUString& _rPropertyName, const Reference< XPropertyControlFactory >& _rxControlFactory ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
273     {
274         ::osl::MutexGuard aGuard( m_aMutex );
275         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
276 
277         LineDescriptor aReturn;
278 
279         switch ( nPropId )
280         {
281         case PROPERTY_ID_TARGET_URL:
282             aReturn = m_xSlaveHandler->describePropertyLine( _rPropertyName, _rxControlFactory );
283             break;
284         default:
285             aReturn = ButtonNavigationHandler_Base::describePropertyLine( _rPropertyName, _rxControlFactory );
286             break;
287         }
288 
289         return aReturn;
290     }
291 
292 //........................................................................
293 }   // namespace pcr
294 //........................................................................
295 
296