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