1*2a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2a97ec55SAndrew Rist  * distributed with this work for additional information
6*2a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
9*2a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2a97ec55SAndrew Rist  *
11*2a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2a97ec55SAndrew Rist  *
13*2a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2a97ec55SAndrew Rist  * software distributed under the License is distributed on an
15*2a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2a97ec55SAndrew Rist  * specific language governing permissions and limitations
18*2a97ec55SAndrew Rist  * under the License.
19*2a97ec55SAndrew Rist  *
20*2a97ec55SAndrew Rist  *************************************************************/
21*2a97ec55SAndrew Rist 
22*2a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir #include "buttonnavigationhandler.hxx"
27cdf0e10cSrcweir #include "formstrings.hxx"
28cdf0e10cSrcweir #include "formmetadata.hxx"
29cdf0e10cSrcweir #include "pushbuttonnavigation.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /** === begin UNO includes === **/
32cdf0e10cSrcweir /** === end UNO includes === **/
33cdf0e10cSrcweir #include <tools/debug.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //------------------------------------------------------------------------
createRegistryInfo_ButtonNavigationHandler()36cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_ButtonNavigationHandler()
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     ::pcr::ButtonNavigationHandler::registerImplementation();
39cdf0e10cSrcweir }
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //........................................................................
42cdf0e10cSrcweir namespace pcr
43cdf0e10cSrcweir {
44cdf0e10cSrcweir //........................................................................
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
47cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
48cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
49cdf0e10cSrcweir     using namespace ::com::sun::star::script;
50cdf0e10cSrcweir     using namespace ::com::sun::star::frame;
51cdf0e10cSrcweir     using namespace ::com::sun::star::inspection;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     //====================================================================
54cdf0e10cSrcweir 	//= ButtonNavigationHandler
55cdf0e10cSrcweir 	//====================================================================
DBG_NAME(ButtonNavigationHandler)56cdf0e10cSrcweir     DBG_NAME( ButtonNavigationHandler )
57cdf0e10cSrcweir 	//--------------------------------------------------------------------
58cdf0e10cSrcweir     ButtonNavigationHandler::ButtonNavigationHandler( const Reference< XComponentContext >& _rxContext )
59cdf0e10cSrcweir         :ButtonNavigationHandler_Base( _rxContext )
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         DBG_CTOR( ButtonNavigationHandler, NULL );
62cdf0e10cSrcweir 
63cdf0e10cSrcweir         m_aContext.createComponent(
64cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.FormComponentPropertyHandler" ) ),
65cdf0e10cSrcweir             m_xSlaveHandler );
66cdf0e10cSrcweir         if ( !m_xSlaveHandler.is() )
67cdf0e10cSrcweir             throw RuntimeException();
68cdf0e10cSrcweir     }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	//--------------------------------------------------------------------
~ButtonNavigationHandler()71cdf0e10cSrcweir     ButtonNavigationHandler::~ButtonNavigationHandler( )
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         DBG_DTOR( ButtonNavigationHandler, NULL );
74cdf0e10cSrcweir     }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     //--------------------------------------------------------------------
getImplementationName_static()77cdf0e10cSrcweir     ::rtl::OUString SAL_CALL ButtonNavigationHandler::getImplementationName_static(  ) throw (RuntimeException)
78cdf0e10cSrcweir     {
79cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.ButtonNavigationHandler" ) );
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     //--------------------------------------------------------------------
getSupportedServiceNames_static()83cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL ButtonNavigationHandler::getSupportedServiceNames_static(  ) throw (RuntimeException)
84cdf0e10cSrcweir     {
85cdf0e10cSrcweir         Sequence< ::rtl::OUString > aSupported( 1 );
86cdf0e10cSrcweir         aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.ButtonNavigationHandler" ) );
87cdf0e10cSrcweir         return aSupported;
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     //--------------------------------------------------------------------
inspect(const Reference<XInterface> & _rxIntrospectee)91cdf0e10cSrcweir     void SAL_CALL ButtonNavigationHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException)
92cdf0e10cSrcweir     {
93cdf0e10cSrcweir         ButtonNavigationHandler_Base::inspect( _rxIntrospectee );
94cdf0e10cSrcweir         m_xSlaveHandler->inspect( _rxIntrospectee );
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     //--------------------------------------------------------------------
getPropertyState(const::rtl::OUString & _rPropertyName)98cdf0e10cSrcweir     PropertyState  SAL_CALL ButtonNavigationHandler::getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
101cdf0e10cSrcweir         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
102cdf0e10cSrcweir         PropertyState eState = PropertyState_DIRECT_VALUE;
103cdf0e10cSrcweir         switch ( nPropId )
104cdf0e10cSrcweir         {
105cdf0e10cSrcweir         case PROPERTY_ID_BUTTONTYPE:
106cdf0e10cSrcweir         {
107cdf0e10cSrcweir             PushButtonNavigation aHelper( m_xComponent );
108cdf0e10cSrcweir             eState = aHelper.getCurrentButtonTypeState();
109cdf0e10cSrcweir         }
110cdf0e10cSrcweir         break;
111cdf0e10cSrcweir         case PROPERTY_ID_TARGET_URL:
112cdf0e10cSrcweir         {
113cdf0e10cSrcweir             PushButtonNavigation aHelper( m_xComponent );
114cdf0e10cSrcweir             eState = aHelper.getCurrentTargetURLState();
115cdf0e10cSrcweir         }
116cdf0e10cSrcweir         break;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         default:
119cdf0e10cSrcweir             DBG_ERROR( "ButtonNavigationHandler::getPropertyState: cannot handle this property!" );
120cdf0e10cSrcweir             break;
121cdf0e10cSrcweir         }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         return eState;
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     //--------------------------------------------------------------------
getPropertyValue(const::rtl::OUString & _rPropertyName)127cdf0e10cSrcweir     Any SAL_CALL ButtonNavigationHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
130cdf0e10cSrcweir         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         Any aReturn;
133cdf0e10cSrcweir         switch ( nPropId )
134cdf0e10cSrcweir         {
135cdf0e10cSrcweir         case PROPERTY_ID_BUTTONTYPE:
136cdf0e10cSrcweir         {
137cdf0e10cSrcweir             PushButtonNavigation aHelper( m_xComponent );
138cdf0e10cSrcweir             aReturn = aHelper.getCurrentButtonType();
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir         break;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         case PROPERTY_ID_TARGET_URL:
143cdf0e10cSrcweir         {
144cdf0e10cSrcweir             PushButtonNavigation aHelper( m_xComponent );
145cdf0e10cSrcweir             aReturn = aHelper.getCurrentTargetURL();
146cdf0e10cSrcweir         }
147cdf0e10cSrcweir         break;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         default:
150cdf0e10cSrcweir             DBG_ERROR( "ButtonNavigationHandler::getPropertyValue: cannot handle this property!" );
151cdf0e10cSrcweir             break;
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         return aReturn;
155cdf0e10cSrcweir     }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     //--------------------------------------------------------------------
setPropertyValue(const::rtl::OUString & _rPropertyName,const Any & _rValue)158cdf0e10cSrcweir     void SAL_CALL ButtonNavigationHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
161cdf0e10cSrcweir         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
162cdf0e10cSrcweir         switch ( nPropId )
163cdf0e10cSrcweir         {
164cdf0e10cSrcweir         case PROPERTY_ID_BUTTONTYPE:
165cdf0e10cSrcweir         {
166cdf0e10cSrcweir             PushButtonNavigation aHelper( m_xComponent );
167cdf0e10cSrcweir             aHelper.setCurrentButtonType( _rValue );
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir         break;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir         case PROPERTY_ID_TARGET_URL:
172cdf0e10cSrcweir         {
173cdf0e10cSrcweir             PushButtonNavigation aHelper( m_xComponent );
174cdf0e10cSrcweir             aHelper.setCurrentTargetURL( _rValue );
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir         break;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         default:
179cdf0e10cSrcweir             OSL_ENSURE( sal_False, "ButtonNavigationHandler::setPropertyValue: cannot handle this id!" );
180cdf0e10cSrcweir         }
181cdf0e10cSrcweir     }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     //--------------------------------------------------------------------
isNavigationCapableButton(const Reference<XPropertySet> & _rxComponent)184cdf0e10cSrcweir     bool ButtonNavigationHandler::isNavigationCapableButton( const Reference< XPropertySet >& _rxComponent )
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         Reference< XPropertySetInfo > xPSI;
187cdf0e10cSrcweir         if ( _rxComponent.is() )
188cdf0e10cSrcweir             xPSI = _rxComponent->getPropertySetInfo();
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         return xPSI.is()
191cdf0e10cSrcweir             && xPSI->hasPropertyByName( PROPERTY_TARGET_URL )
192cdf0e10cSrcweir             && xPSI->hasPropertyByName( PROPERTY_BUTTONTYPE );
193cdf0e10cSrcweir     }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     //--------------------------------------------------------------------
doDescribeSupportedProperties() const196cdf0e10cSrcweir     Sequence< Property > SAL_CALL ButtonNavigationHandler::doDescribeSupportedProperties() const
197cdf0e10cSrcweir     {
198cdf0e10cSrcweir         ::std::vector< Property > aProperties;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir         if ( isNavigationCapableButton( m_xComponent ) )
201cdf0e10cSrcweir         {
202cdf0e10cSrcweir             addStringPropertyDescription( aProperties, PROPERTY_TARGET_URL );
203cdf0e10cSrcweir             implAddPropertyDescription( aProperties, PROPERTY_BUTTONTYPE, ::getCppuType( static_cast< sal_Int32* >( NULL ) ) );
204cdf0e10cSrcweir         }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir         if ( aProperties.empty() )
207cdf0e10cSrcweir             return Sequence< Property >();
208cdf0e10cSrcweir         return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
209cdf0e10cSrcweir     }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     //--------------------------------------------------------------------
getActuatingProperties()212cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL ButtonNavigationHandler::getActuatingProperties( ) throw (RuntimeException)
213cdf0e10cSrcweir     {
214cdf0e10cSrcweir         Sequence< ::rtl::OUString > aActuating( 2 );
215cdf0e10cSrcweir         aActuating[0] = PROPERTY_BUTTONTYPE;
216cdf0e10cSrcweir         aActuating[1] = PROPERTY_TARGET_URL;
217cdf0e10cSrcweir         return aActuating;
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     //--------------------------------------------------------------------
onInteractivePropertySelection(const::rtl::OUString & _rPropertyName,sal_Bool _bPrimary,Any & _rData,const Reference<XObjectInspectorUI> & _rxInspectorUI)221cdf0e10cSrcweir     InteractiveSelectionResult SAL_CALL ButtonNavigationHandler::onInteractivePropertySelection( const ::rtl::OUString& _rPropertyName, sal_Bool _bPrimary, Any& _rData, const Reference< XObjectInspectorUI >& _rxInspectorUI ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
222cdf0e10cSrcweir     {
223cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
224cdf0e10cSrcweir         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir         InteractiveSelectionResult eReturn( InteractiveSelectionResult_Cancelled );
227cdf0e10cSrcweir 
228cdf0e10cSrcweir         switch ( nPropId )
229cdf0e10cSrcweir         {
230cdf0e10cSrcweir         case PROPERTY_ID_TARGET_URL:
231cdf0e10cSrcweir             eReturn = m_xSlaveHandler->onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
232cdf0e10cSrcweir             break;
233cdf0e10cSrcweir         default:
234cdf0e10cSrcweir             eReturn = ButtonNavigationHandler_Base::onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
235cdf0e10cSrcweir             break;
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir         return eReturn;
239cdf0e10cSrcweir     }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     //--------------------------------------------------------------------
actuatingPropertyChanged(const::rtl::OUString & _rActuatingPropertyName,const Any &,const Any &,const Reference<XObjectInspectorUI> & _rxInspectorUI,sal_Bool)242cdf0e10cSrcweir     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)
243cdf0e10cSrcweir     {
244cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
245cdf0e10cSrcweir         PropertyId nPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
246cdf0e10cSrcweir         switch ( nPropId )
247cdf0e10cSrcweir         {
248cdf0e10cSrcweir         case PROPERTY_ID_BUTTONTYPE:
249cdf0e10cSrcweir         {
250cdf0e10cSrcweir             PushButtonNavigation aHelper( m_xComponent );
251cdf0e10cSrcweir             _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_URL, aHelper.currentButtonTypeIsOpenURL() );
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir         break;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir         case PROPERTY_ID_TARGET_URL:
256cdf0e10cSrcweir         {
257cdf0e10cSrcweir             PushButtonNavigation aHelper( m_xComponent );
258cdf0e10cSrcweir             _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_FRAME, aHelper.hasNonEmptyCurrentTargetURL() );
259cdf0e10cSrcweir         }
260cdf0e10cSrcweir         break;
261cdf0e10cSrcweir 
262cdf0e10cSrcweir         default:
263cdf0e10cSrcweir             OSL_ENSURE( sal_False, "ButtonNavigationHandler::actuatingPropertyChanged: cannot handle this id!" );
264cdf0e10cSrcweir         }
265cdf0e10cSrcweir     }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir     //--------------------------------------------------------------------
describePropertyLine(const::rtl::OUString & _rPropertyName,const Reference<XPropertyControlFactory> & _rxControlFactory)268cdf0e10cSrcweir     LineDescriptor SAL_CALL ButtonNavigationHandler::describePropertyLine( const ::rtl::OUString& _rPropertyName, const Reference< XPropertyControlFactory >& _rxControlFactory ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
269cdf0e10cSrcweir     {
270cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
271cdf0e10cSrcweir         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
272cdf0e10cSrcweir 
273cdf0e10cSrcweir         LineDescriptor aReturn;
274cdf0e10cSrcweir 
275cdf0e10cSrcweir         switch ( nPropId )
276cdf0e10cSrcweir         {
277cdf0e10cSrcweir         case PROPERTY_ID_TARGET_URL:
278cdf0e10cSrcweir             aReturn = m_xSlaveHandler->describePropertyLine( _rPropertyName, _rxControlFactory );
279cdf0e10cSrcweir             break;
280cdf0e10cSrcweir         default:
281cdf0e10cSrcweir             aReturn = ButtonNavigationHandler_Base::describePropertyLine( _rPropertyName, _rxControlFactory );
282cdf0e10cSrcweir             break;
283cdf0e10cSrcweir         }
284cdf0e10cSrcweir 
285cdf0e10cSrcweir         return aReturn;
286cdf0e10cSrcweir     }
287cdf0e10cSrcweir 
288cdf0e10cSrcweir //........................................................................
289cdf0e10cSrcweir }   // namespace pcr
290cdf0e10cSrcweir //........................................................................
291cdf0e10cSrcweir 
292