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 "buttonnavigationhandler.hxx"
30 : : #include "formstrings.hxx"
31 : : #include "formmetadata.hxx"
32 : : #include "pushbuttonnavigation.hxx"
33 : :
34 : : #include <tools/debug.hxx>
35 : :
36 : : //------------------------------------------------------------------------
37 : 0 : extern "C" void SAL_CALL createRegistryInfo_ButtonNavigationHandler()
38 : : {
39 : 0 : ::pcr::ButtonNavigationHandler::registerImplementation();
40 : 0 : }
41 : :
42 : : //........................................................................
43 : : namespace pcr
44 : : {
45 : : //........................................................................
46 : :
47 : : using namespace ::com::sun::star::uno;
48 : : using namespace ::com::sun::star::lang;
49 : : using namespace ::com::sun::star::beans;
50 : : using namespace ::com::sun::star::script;
51 : : using namespace ::com::sun::star::frame;
52 : : using namespace ::com::sun::star::inspection;
53 : :
54 : : //====================================================================
55 : : //= ButtonNavigationHandler
56 : : //====================================================================
57 : : DBG_NAME( ButtonNavigationHandler )
58 : : //--------------------------------------------------------------------
59 : 0 : ButtonNavigationHandler::ButtonNavigationHandler( const Reference< XComponentContext >& _rxContext )
60 : 0 : :ButtonNavigationHandler_Base( _rxContext )
61 : : {
62 : : DBG_CTOR( ButtonNavigationHandler, NULL );
63 : :
64 : : m_aContext.createComponent(
65 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.FormComponentPropertyHandler" ) ),
66 : 0 : m_xSlaveHandler );
67 : 0 : if ( !m_xSlaveHandler.is() )
68 : 0 : throw RuntimeException();
69 : 0 : }
70 : :
71 : : //--------------------------------------------------------------------
72 : 0 : ButtonNavigationHandler::~ButtonNavigationHandler( )
73 : : {
74 : : DBG_DTOR( ButtonNavigationHandler, NULL );
75 : 0 : }
76 : :
77 : : //--------------------------------------------------------------------
78 : 0 : ::rtl::OUString SAL_CALL ButtonNavigationHandler::getImplementationName_static( ) throw (RuntimeException)
79 : : {
80 : 0 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.ButtonNavigationHandler" ) );
81 : : }
82 : :
83 : : //--------------------------------------------------------------------
84 : 0 : Sequence< ::rtl::OUString > SAL_CALL ButtonNavigationHandler::getSupportedServiceNames_static( ) throw (RuntimeException)
85 : : {
86 : 0 : Sequence< ::rtl::OUString > aSupported( 1 );
87 : 0 : aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.ButtonNavigationHandler" ) );
88 : 0 : return aSupported;
89 : : }
90 : :
91 : : //--------------------------------------------------------------------
92 : 0 : void SAL_CALL ButtonNavigationHandler::inspect( const Reference< XInterface >& _rxIntrospectee ) throw (RuntimeException, NullPointerException)
93 : : {
94 : 0 : ButtonNavigationHandler_Base::inspect( _rxIntrospectee );
95 : 0 : m_xSlaveHandler->inspect( _rxIntrospectee );
96 : 0 : }
97 : :
98 : : //--------------------------------------------------------------------
99 : 0 : PropertyState SAL_CALL ButtonNavigationHandler::getPropertyState( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
100 : : {
101 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
102 : 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
103 : 0 : PropertyState eState = PropertyState_DIRECT_VALUE;
104 : 0 : switch ( nPropId )
105 : : {
106 : : case PROPERTY_ID_BUTTONTYPE:
107 : : {
108 : 0 : PushButtonNavigation aHelper( m_xComponent );
109 : 0 : eState = aHelper.getCurrentButtonTypeState();
110 : : }
111 : 0 : break;
112 : : case PROPERTY_ID_TARGET_URL:
113 : : {
114 : 0 : PushButtonNavigation aHelper( m_xComponent );
115 : 0 : eState = aHelper.getCurrentTargetURLState();
116 : : }
117 : 0 : break;
118 : :
119 : : default:
120 : : OSL_FAIL( "ButtonNavigationHandler::getPropertyState: cannot handle this property!" );
121 : 0 : break;
122 : : }
123 : :
124 : 0 : return eState;
125 : : }
126 : :
127 : : //--------------------------------------------------------------------
128 : 0 : Any SAL_CALL ButtonNavigationHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
129 : : {
130 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
131 : 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
132 : :
133 : 0 : Any aReturn;
134 : 0 : switch ( nPropId )
135 : : {
136 : : case PROPERTY_ID_BUTTONTYPE:
137 : : {
138 : 0 : PushButtonNavigation aHelper( m_xComponent );
139 : 0 : aReturn = aHelper.getCurrentButtonType();
140 : : }
141 : 0 : break;
142 : :
143 : : case PROPERTY_ID_TARGET_URL:
144 : : {
145 : 0 : PushButtonNavigation aHelper( m_xComponent );
146 : 0 : aReturn = aHelper.getCurrentTargetURL();
147 : : }
148 : 0 : break;
149 : :
150 : : default:
151 : : OSL_FAIL( "ButtonNavigationHandler::getPropertyValue: cannot handle this property!" );
152 : 0 : break;
153 : : }
154 : :
155 : 0 : return aReturn;
156 : : }
157 : :
158 : : //--------------------------------------------------------------------
159 : 0 : void SAL_CALL ButtonNavigationHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
160 : : {
161 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
162 : 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
163 : 0 : switch ( nPropId )
164 : : {
165 : : case PROPERTY_ID_BUTTONTYPE:
166 : : {
167 : 0 : PushButtonNavigation aHelper( m_xComponent );
168 : 0 : aHelper.setCurrentButtonType( _rValue );
169 : : }
170 : 0 : break;
171 : :
172 : : case PROPERTY_ID_TARGET_URL:
173 : : {
174 : 0 : PushButtonNavigation aHelper( m_xComponent );
175 : 0 : aHelper.setCurrentTargetURL( _rValue );
176 : : }
177 : 0 : break;
178 : :
179 : : default:
180 : : OSL_FAIL( "ButtonNavigationHandler::setPropertyValue: cannot handle this id!" );
181 : 0 : }
182 : 0 : }
183 : :
184 : : //--------------------------------------------------------------------
185 : 0 : bool ButtonNavigationHandler::isNavigationCapableButton( const Reference< XPropertySet >& _rxComponent )
186 : : {
187 : 0 : Reference< XPropertySetInfo > xPSI;
188 : 0 : if ( _rxComponent.is() )
189 : 0 : xPSI = _rxComponent->getPropertySetInfo();
190 : :
191 : 0 : return xPSI.is()
192 : 0 : && xPSI->hasPropertyByName( PROPERTY_TARGET_URL )
193 : 0 : && xPSI->hasPropertyByName( PROPERTY_BUTTONTYPE );
194 : : }
195 : :
196 : : //--------------------------------------------------------------------
197 : 0 : Sequence< Property > SAL_CALL ButtonNavigationHandler::doDescribeSupportedProperties() const
198 : : {
199 : 0 : ::std::vector< Property > aProperties;
200 : :
201 : 0 : if ( isNavigationCapableButton( m_xComponent ) )
202 : : {
203 : 0 : addStringPropertyDescription( aProperties, PROPERTY_TARGET_URL );
204 : 0 : implAddPropertyDescription( aProperties, PROPERTY_BUTTONTYPE, ::getCppuType( static_cast< sal_Int32* >( NULL ) ) );
205 : : }
206 : :
207 : 0 : if ( aProperties.empty() )
208 : 0 : return Sequence< Property >();
209 : 0 : return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
210 : : }
211 : :
212 : : //--------------------------------------------------------------------
213 : 0 : Sequence< ::rtl::OUString > SAL_CALL ButtonNavigationHandler::getActuatingProperties( ) throw (RuntimeException)
214 : : {
215 : 0 : Sequence< ::rtl::OUString > aActuating( 2 );
216 : 0 : aActuating[0] = PROPERTY_BUTTONTYPE;
217 : 0 : aActuating[1] = PROPERTY_TARGET_URL;
218 : 0 : return aActuating;
219 : : }
220 : :
221 : : //--------------------------------------------------------------------
222 : 0 : InteractiveSelectionResult SAL_CALL ButtonNavigationHandler::onInteractivePropertySelection( const ::rtl::OUString& _rPropertyName, sal_Bool _bPrimary, Any& _rData, const Reference< XObjectInspectorUI >& _rxInspectorUI ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
223 : : {
224 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
225 : 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
226 : :
227 : 0 : InteractiveSelectionResult eReturn( InteractiveSelectionResult_Cancelled );
228 : :
229 : 0 : switch ( nPropId )
230 : : {
231 : : case PROPERTY_ID_TARGET_URL:
232 : 0 : eReturn = m_xSlaveHandler->onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
233 : 0 : break;
234 : : default:
235 : 0 : eReturn = ButtonNavigationHandler_Base::onInteractivePropertySelection( _rPropertyName, _bPrimary, _rData, _rxInspectorUI );
236 : 0 : break;
237 : : }
238 : :
239 : 0 : return eReturn;
240 : : }
241 : :
242 : : //--------------------------------------------------------------------
243 : 0 : 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)
244 : : {
245 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
246 : 0 : PropertyId nPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
247 : 0 : switch ( nPropId )
248 : : {
249 : : case PROPERTY_ID_BUTTONTYPE:
250 : : {
251 : 0 : PushButtonNavigation aHelper( m_xComponent );
252 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_URL, aHelper.currentButtonTypeIsOpenURL() );
253 : : }
254 : 0 : break;
255 : :
256 : : case PROPERTY_ID_TARGET_URL:
257 : : {
258 : 0 : PushButtonNavigation aHelper( m_xComponent );
259 : 0 : _rxInspectorUI->enablePropertyUI( PROPERTY_TARGET_FRAME, aHelper.hasNonEmptyCurrentTargetURL() );
260 : : }
261 : 0 : break;
262 : :
263 : : default:
264 : : OSL_FAIL( "ButtonNavigationHandler::actuatingPropertyChanged: cannot handle this id!" );
265 : 0 : }
266 : 0 : }
267 : :
268 : : //--------------------------------------------------------------------
269 : 0 : LineDescriptor SAL_CALL ButtonNavigationHandler::describePropertyLine( const ::rtl::OUString& _rPropertyName, const Reference< XPropertyControlFactory >& _rxControlFactory ) throw (UnknownPropertyException, NullPointerException, RuntimeException)
270 : : {
271 : 0 : ::osl::MutexGuard aGuard( m_aMutex );
272 : 0 : PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
273 : :
274 : 0 : LineDescriptor aReturn;
275 : :
276 : 0 : switch ( nPropId )
277 : : {
278 : : case PROPERTY_ID_TARGET_URL:
279 : 0 : aReturn = m_xSlaveHandler->describePropertyLine( _rPropertyName, _rxControlFactory );
280 : 0 : break;
281 : : default:
282 : 0 : aReturn = ButtonNavigationHandler_Base::describePropertyLine( _rPropertyName, _rxControlFactory );
283 : 0 : break;
284 : : }
285 : :
286 : 0 : return aReturn;
287 : : }
288 : :
289 : : //........................................................................
290 : : } // namespace pcr
291 : : //........................................................................
292 : :
293 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|