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 "cellbindinghelper.hxx"
30 : : #include <com/sun/star/form/binding/XBindableValue.hpp>
31 : : #include <com/sun/star/form/binding/XListEntrySink.hpp>
32 : : #include <com/sun/star/form/FormComponentType.hpp>
33 : : #include <com/sun/star/form/XGridColumnFactory.hpp>
34 : : #include <com/sun/star/container/XChild.hpp>
35 : : #include <com/sun/star/container/XNamed.hpp>
36 : : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
37 : : #include <com/sun/star/table/XCellRange.hpp>
38 : : #include <com/sun/star/form/XFormsSupplier.hpp>
39 : : #include <com/sun/star/form/XForm.hpp>
40 : : #include <com/sun/star/lang/XServiceInfo.hpp>
41 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 : : #include <com/sun/star/beans/NamedValue.hpp>
43 : : #include <com/sun/star/sheet/XSpreadsheet.hpp>
44 : : #include <unotools/transliterationwrapper.hxx>
45 : : #include <osl/diagnose.h>
46 : : #include <tools/diagnose_ex.h>
47 : : #include "formstrings.hxx"
48 : :
49 : : #include <functional>
50 : : #include <algorithm>
51 : :
52 : : //............................................................................
53 : : namespace pcr
54 : : {
55 : : //............................................................................
56 : :
57 : : using namespace ::com::sun::star::uno;
58 : : using namespace ::com::sun::star::beans;
59 : : using namespace ::com::sun::star::frame;
60 : : using namespace ::com::sun::star::sheet;
61 : : using namespace ::com::sun::star::container;
62 : : using namespace ::com::sun::star::drawing;
63 : : using namespace ::com::sun::star::table;
64 : : using namespace ::com::sun::star::form;
65 : : using namespace ::com::sun::star::lang;
66 : : using namespace ::com::sun::star::i18n;
67 : : using namespace ::com::sun::star::form::binding;
68 : :
69 : : namespace
70 : : {
71 : : //....................................................................
72 : 0 : struct StringCompare : public ::std::unary_function< ::rtl::OUString, bool >
73 : : {
74 : : private:
75 : : ::rtl::OUString m_sReference;
76 : :
77 : : public:
78 : 0 : StringCompare( const ::rtl::OUString& _rReference ) : m_sReference( _rReference ) { }
79 : :
80 : 0 : inline bool operator()( const ::rtl::OUString& _rCompare )
81 : : {
82 : 0 : return ( _rCompare == m_sReference ) ? true : false;
83 : : }
84 : : };
85 : : }
86 : :
87 : : //========================================================================
88 : : //= CellBindingHelper
89 : : //========================================================================
90 : : //------------------------------------------------------------------------
91 : 0 : CellBindingHelper::CellBindingHelper( const Reference< XPropertySet >& _rxControlModel, const Reference< XModel >& _rxContextDocument )
92 : 0 : :m_xControlModel( _rxControlModel )
93 : : {
94 : : OSL_ENSURE( m_xControlModel.is(), "CellBindingHelper::CellBindingHelper: invalid control model!" );
95 : :
96 : 0 : m_xDocument = m_xDocument.query( _rxContextDocument );
97 : : OSL_ENSURE( m_xDocument.is(), "CellBindingHelper::CellBindingHelper: This is no spreadsheet document!" );
98 : :
99 : : OSL_ENSURE( isSpreadsheetDocumentWhichSupplies( SERVICE_ADDRESS_CONVERSION ),
100 : : "CellBindingHelper::CellBindingHelper: the document cannot convert address representations!" );
101 : 0 : }
102 : :
103 : : //------------------------------------------------------------------------
104 : 0 : sal_Bool CellBindingHelper::isSpreadsheetDocument( const Reference< XModel >& _rxContextDocument )
105 : : {
106 : 0 : return Reference< XSpreadsheetDocument >::query( _rxContextDocument ).is();
107 : : }
108 : :
109 : : //------------------------------------------------------------------------
110 : 0 : sal_Int16 CellBindingHelper::getControlSheetIndex( Reference< XSpreadsheet >& _out_rxSheet ) const
111 : : {
112 : 0 : sal_Int16 nSheetIndex = -1;
113 : : // every sheet has a draw page, and every draw page has a forms collection.
114 : : // Our control, OTOH, belongs to a forms collection. Match these ...
115 : : try
116 : : {
117 : : // for determining the draw page, we need the forms collection which
118 : : // the object belongs to. This is the first object up the hierarchy which is
119 : : // *no* XForm (and, well, no XGridColumnFactory)
120 : 0 : Reference< XChild > xCheck( m_xControlModel, UNO_QUERY );
121 : 0 : Reference< XForm > xParentAsForm; if ( xCheck.is() ) xParentAsForm = xParentAsForm.query( xCheck->getParent() );
122 : 0 : Reference< XGridColumnFactory > xParentAsGrid; if ( xCheck.is() ) xParentAsGrid = xParentAsGrid.query( xCheck->getParent() );
123 : :
124 : 0 : while ( ( xParentAsForm.is() || xParentAsGrid.is() ) && xCheck.is() )
125 : : {
126 : 0 : xCheck = xCheck.query( xCheck->getParent() );
127 : 0 : xParentAsForm = xParentAsForm.query( xCheck.is() ? xCheck->getParent() : (Reference< XInterface >) Reference< XForm >() );
128 : 0 : xParentAsGrid = xParentAsGrid.query( xCheck.is() ? xCheck->getParent() : (Reference< XInterface >) Reference< XGridColumnFactory >() );
129 : : }
130 : 0 : Reference< XInterface > xFormsCollection( xCheck.is() ? xCheck->getParent() : Reference< XInterface >() );
131 : :
132 : : // now iterate through the sheets
133 : 0 : Reference< XIndexAccess > xSheets( m_xDocument->getSheets(), UNO_QUERY );
134 : 0 : if ( xSheets.is() && xFormsCollection.is() )
135 : : {
136 : 0 : for ( sal_Int32 i = 0; i < xSheets->getCount(); ++i )
137 : : {
138 : 0 : Reference< XDrawPageSupplier > xSuppPage( xSheets->getByIndex( i ), UNO_QUERY_THROW );
139 : 0 : Reference< XFormsSupplier > xSuppForms( xSuppPage->getDrawPage(), UNO_QUERY_THROW );
140 : :
141 : 0 : if ( xSuppForms->getForms() == xFormsCollection )
142 : : { // found it
143 : 0 : nSheetIndex = (sal_Int16)i;
144 : 0 : _out_rxSheet.set( xSuppPage, UNO_QUERY_THROW );
145 : : break;
146 : : }
147 : 0 : }
148 : 0 : }
149 : : }
150 : 0 : catch( const Exception& )
151 : : {
152 : : DBG_UNHANDLED_EXCEPTION();
153 : : }
154 : :
155 : 0 : return nSheetIndex;
156 : : }
157 : :
158 : : //------------------------------------------------------------------------
159 : 0 : bool CellBindingHelper::convertStringAddress( const ::rtl::OUString& _rAddressDescription, CellAddress& /* [out] */ _rAddress ) const
160 : : {
161 : 0 : Any aAddress;
162 : : return doConvertAddressRepresentations(
163 : : PROPERTY_UI_REPRESENTATION,
164 : : makeAny( _rAddressDescription ),
165 : : PROPERTY_ADDRESS,
166 : : aAddress,
167 : : false
168 : 0 : )
169 : 0 : && ( aAddress >>= _rAddress );
170 : : }
171 : :
172 : : //------------------------------------------------------------------------
173 : 0 : bool CellBindingHelper::doConvertAddressRepresentations( const ::rtl::OUString& _rInputProperty, const Any& _rInputValue,
174 : : const ::rtl::OUString& _rOutputProperty, Any& _rOutputValue, bool _bIsRange ) const SAL_THROW(())
175 : : {
176 : 0 : bool bSuccess = false;
177 : :
178 : : Reference< XPropertySet > xConverter(
179 : : createDocumentDependentInstance(
180 : : _bIsRange ? SERVICE_RANGEADDRESS_CONVERSION : SERVICE_ADDRESS_CONVERSION,
181 : : ::rtl::OUString(),
182 : : Any()
183 : : ),
184 : : UNO_QUERY
185 : 0 : );
186 : : OSL_ENSURE( xConverter.is(), "CellBindingHelper::doConvertAddressRepresentations: could not get a converter service!" );
187 : 0 : if ( xConverter.is() )
188 : : {
189 : : try
190 : : {
191 : 0 : Reference< XSpreadsheet > xSheet;
192 : 0 : xConverter->setPropertyValue( PROPERTY_REFERENCE_SHEET, makeAny( (sal_Int32)getControlSheetIndex( xSheet ) ) );
193 : 0 : xConverter->setPropertyValue( _rInputProperty, _rInputValue );
194 : 0 : _rOutputValue = xConverter->getPropertyValue( _rOutputProperty );
195 : 0 : bSuccess = true;
196 : : }
197 : 0 : catch( const Exception& )
198 : : {
199 : : OSL_FAIL( "CellBindingHelper::doConvertAddressRepresentations: caught an exception!" );
200 : : }
201 : : }
202 : :
203 : 0 : return bSuccess;
204 : : }
205 : :
206 : : //------------------------------------------------------------------------
207 : 0 : bool CellBindingHelper::convertStringAddress( const ::rtl::OUString& _rAddressDescription,
208 : : CellRangeAddress& /* [out] */ _rAddress ) const
209 : : {
210 : 0 : Any aAddress;
211 : : return doConvertAddressRepresentations(
212 : : PROPERTY_UI_REPRESENTATION,
213 : : makeAny( _rAddressDescription ),
214 : : PROPERTY_ADDRESS,
215 : : aAddress,
216 : : true
217 : 0 : )
218 : 0 : && ( aAddress >>= _rAddress );
219 : : }
220 : :
221 : : //------------------------------------------------------------------------
222 : 0 : Reference< XValueBinding > CellBindingHelper::createCellBindingFromAddress( const CellAddress& _rAddress, bool _bSupportIntegerExchange ) const
223 : : {
224 : : Reference< XValueBinding > xBinding( createDocumentDependentInstance(
225 : : _bSupportIntegerExchange ? SERVICE_SHEET_CELL_INT_BINDING : SERVICE_SHEET_CELL_BINDING,
226 : : PROPERTY_BOUND_CELL,
227 : : makeAny( _rAddress )
228 : 0 : ), UNO_QUERY );
229 : :
230 : 0 : return xBinding;
231 : : }
232 : :
233 : : //------------------------------------------------------------------------
234 : 0 : Reference< XValueBinding > CellBindingHelper::createCellBindingFromStringAddress( const ::rtl::OUString& _rAddress, bool _bSupportIntegerExchange ) const
235 : : {
236 : 0 : Reference< XValueBinding > xBinding;
237 : 0 : if ( !m_xDocument.is() )
238 : : // very bad ...
239 : 0 : return xBinding;
240 : :
241 : : // get the UNO representation of the address
242 : 0 : CellAddress aAddress;
243 : 0 : if ( _rAddress.isEmpty() || !convertStringAddress( _rAddress, aAddress ) )
244 : 0 : return xBinding;
245 : :
246 : 0 : return createCellBindingFromAddress( aAddress, _bSupportIntegerExchange );
247 : : }
248 : :
249 : : //------------------------------------------------------------------------
250 : 0 : Reference< XListEntrySource > CellBindingHelper::createCellListSourceFromStringAddress( const ::rtl::OUString& _rAddress ) const
251 : : {
252 : 0 : Reference< XListEntrySource > xSource;
253 : :
254 : 0 : CellRangeAddress aRangeAddress;
255 : 0 : if ( _rAddress.isEmpty() || !convertStringAddress( _rAddress, aRangeAddress ) )
256 : : return xSource;
257 : :
258 : : // create a range object for this address
259 : : xSource = xSource.query( createDocumentDependentInstance(
260 : : SERVICE_SHEET_CELLRANGE_LISTSOURCE,
261 : : PROPERTY_LIST_CELL_RANGE,
262 : : makeAny( aRangeAddress )
263 : 0 : ) );
264 : :
265 : 0 : return xSource;
266 : : }
267 : :
268 : : //------------------------------------------------------------------------
269 : 0 : Reference< XInterface > CellBindingHelper::createDocumentDependentInstance( const ::rtl::OUString& _rService, const ::rtl::OUString& _rArgumentName,
270 : : const Any& _rArgumentValue ) const
271 : : {
272 : 0 : Reference< XInterface > xReturn;
273 : :
274 : 0 : Reference< XMultiServiceFactory > xDocumentFactory( m_xDocument, UNO_QUERY );
275 : : OSL_ENSURE( xDocumentFactory.is(), "CellBindingHelper::createDocumentDependentInstance: no document service factory!" );
276 : 0 : if ( xDocumentFactory.is() )
277 : : {
278 : : try
279 : : {
280 : 0 : if ( !_rArgumentName.isEmpty() )
281 : : {
282 : 0 : NamedValue aArg;
283 : 0 : aArg.Name = _rArgumentName;
284 : 0 : aArg.Value = _rArgumentValue;
285 : :
286 : 0 : Sequence< Any > aArgs( 1 );
287 : 0 : aArgs[ 0 ] <<= aArg;
288 : :
289 : 0 : xReturn = xDocumentFactory->createInstanceWithArguments( _rService, aArgs );
290 : : }
291 : : else
292 : : {
293 : 0 : xReturn = xDocumentFactory->createInstance( _rService );
294 : : }
295 : : }
296 : 0 : catch ( const Exception& )
297 : : {
298 : : OSL_FAIL( "CellBindingHelper::createDocumentDependentInstance: could not create the binding at the document!" );
299 : : }
300 : : }
301 : 0 : return xReturn;
302 : : }
303 : :
304 : : //------------------------------------------------------------------------
305 : 0 : bool CellBindingHelper::getAddressFromCellBinding(
306 : : const Reference< XValueBinding >& _rxBinding, CellAddress& _rAddress ) const
307 : : {
308 : : OSL_PRECOND( !_rxBinding.is() || isCellBinding( _rxBinding ), "CellBindingHelper::getAddressFromCellBinding: this is no cell binding!" );
309 : :
310 : 0 : bool bReturn = false;
311 : 0 : if ( !m_xDocument.is() )
312 : : // very bad ...
313 : 0 : return bReturn;
314 : :
315 : : try
316 : : {
317 : 0 : Reference< XPropertySet > xBindingProps( _rxBinding, UNO_QUERY );
318 : : OSL_ENSURE( xBindingProps.is() || !_rxBinding.is(), "CellBindingHelper::getAddressFromCellBinding: no property set for the binding!" );
319 : 0 : if ( xBindingProps.is() )
320 : : {
321 : 0 : CellAddress aAddress;
322 : 0 : bReturn = (bool)( xBindingProps->getPropertyValue( PROPERTY_BOUND_CELL ) >>= _rAddress );
323 : 0 : }
324 : : }
325 : 0 : catch( const Exception& )
326 : : {
327 : : OSL_FAIL( "CellBindingHelper::getAddressFromCellBinding: caught an exception!" );
328 : : }
329 : :
330 : 0 : return bReturn;
331 : : }
332 : :
333 : : //------------------------------------------------------------------------
334 : 0 : ::rtl::OUString CellBindingHelper::getStringAddressFromCellBinding( const Reference< XValueBinding >& _rxBinding ) const
335 : : {
336 : 0 : CellAddress aAddress;
337 : 0 : ::rtl::OUString sAddress;
338 : 0 : if ( getAddressFromCellBinding( _rxBinding, aAddress ) )
339 : : {
340 : 0 : Any aStringAddress;
341 : : doConvertAddressRepresentations( PROPERTY_ADDRESS, makeAny( aAddress ),
342 : 0 : PROPERTY_UI_REPRESENTATION, aStringAddress, false );
343 : :
344 : 0 : aStringAddress >>= sAddress;
345 : : }
346 : :
347 : 0 : return sAddress;
348 : : }
349 : :
350 : : //------------------------------------------------------------------------
351 : 0 : ::rtl::OUString CellBindingHelper::getStringAddressFromCellListSource( const Reference< XListEntrySource >& _rxSource ) const
352 : : {
353 : : OSL_PRECOND( !_rxSource.is() || isCellRangeListSource( _rxSource ), "CellBindingHelper::getStringAddressFromCellListSource: this is no cell list source!" );
354 : :
355 : 0 : ::rtl::OUString sAddress;
356 : 0 : if ( !m_xDocument.is() )
357 : : // very bad ...
358 : 0 : return sAddress;
359 : :
360 : : try
361 : : {
362 : 0 : Reference< XPropertySet > xSourceProps( _rxSource, UNO_QUERY );
363 : : OSL_ENSURE( xSourceProps.is() || !_rxSource.is(), "CellBindingHelper::getStringAddressFromCellListSource: no property set for the list source!" );
364 : 0 : if ( xSourceProps.is() )
365 : : {
366 : 0 : CellRangeAddress aRangeAddress;
367 : 0 : xSourceProps->getPropertyValue( PROPERTY_LIST_CELL_RANGE ) >>= aRangeAddress;
368 : :
369 : 0 : Any aStringAddress;
370 : : doConvertAddressRepresentations( PROPERTY_ADDRESS, makeAny( aRangeAddress ),
371 : 0 : PROPERTY_UI_REPRESENTATION, aStringAddress, true );
372 : 0 : aStringAddress >>= sAddress;
373 : 0 : }
374 : : }
375 : 0 : catch( const Exception& )
376 : : {
377 : : OSL_FAIL( "CellBindingHelper::getStringAddressFromCellListSource: caught an exception!" );
378 : : }
379 : :
380 : 0 : return sAddress;
381 : : }
382 : :
383 : : //------------------------------------------------------------------------
384 : 0 : bool CellBindingHelper::isSpreadsheetDocumentWhichSupplies( const ::rtl::OUString& _rService ) const
385 : : {
386 : 0 : bool bYesItIs = false;
387 : :
388 : 0 : Reference< XServiceInfo > xSI( m_xDocument, UNO_QUERY );
389 : 0 : if ( xSI.is() && xSI->supportsService( SERVICE_SPREADSHEET_DOCUMENT ) )
390 : : {
391 : 0 : Reference< XMultiServiceFactory > xDocumentFactory( m_xDocument, UNO_QUERY );
392 : : OSL_ENSURE( xDocumentFactory.is(), "CellBindingHelper::isSpreadsheetDocumentWhichSupplies: spreadsheet document, but no factory?" );
393 : :
394 : 0 : Sequence< ::rtl::OUString > aAvailableServices;
395 : 0 : if ( xDocumentFactory.is() )
396 : 0 : aAvailableServices = xDocumentFactory->getAvailableServiceNames( );
397 : :
398 : : const ::rtl::OUString* pFound = ::std::find_if(
399 : : aAvailableServices.getConstArray(),
400 : 0 : aAvailableServices.getConstArray() + aAvailableServices.getLength(),
401 : : StringCompare( _rService )
402 : 0 : );
403 : 0 : if ( pFound - aAvailableServices.getConstArray() < aAvailableServices.getLength() )
404 : : {
405 : 0 : bYesItIs = true;
406 : 0 : }
407 : : }
408 : :
409 : 0 : return bYesItIs;
410 : : }
411 : :
412 : : //------------------------------------------------------------------------
413 : 0 : bool CellBindingHelper::isListCellRangeAllowed( ) const
414 : : {
415 : 0 : bool bAllow( false );
416 : :
417 : 0 : Reference< XListEntrySink > xSink( m_xControlModel, UNO_QUERY );
418 : 0 : if ( xSink.is() )
419 : : {
420 : 0 : bAllow = isSpreadsheetDocumentWhichSupplies( SERVICE_SHEET_CELLRANGE_LISTSOURCE );
421 : : }
422 : :
423 : 0 : return bAllow;
424 : : }
425 : :
426 : : //------------------------------------------------------------------------
427 : 0 : bool CellBindingHelper::isCellIntegerBindingAllowed( ) const
428 : : {
429 : 0 : bool bAllow( true );
430 : :
431 : : // first, we only offer this for controls which allow bindings in general
432 : 0 : Reference< XBindableValue > xBindable( m_xControlModel, UNO_QUERY );
433 : 0 : if ( !xBindable.is() )
434 : 0 : bAllow = false;
435 : :
436 : : // then, we must live in a spreadsheet document which can provide the special
437 : : // service needed for exchanging integer values
438 : 0 : if ( bAllow )
439 : 0 : bAllow = isSpreadsheetDocumentWhichSupplies( SERVICE_SHEET_CELL_INT_BINDING );
440 : :
441 : : // then, we only offer this for list boxes
442 : 0 : if ( bAllow )
443 : : {
444 : : try
445 : : {
446 : 0 : sal_Int16 nClassId = FormComponentType::CONTROL;
447 : 0 : m_xControlModel->getPropertyValue( PROPERTY_CLASSID ) >>= nClassId;
448 : 0 : if ( FormComponentType::LISTBOX != nClassId )
449 : 0 : bAllow = false;
450 : : }
451 : 0 : catch( const Exception& )
452 : : {
453 : : OSL_FAIL( "CellBindingHelper::isCellIntegerBindingAllowed: caught an exception!" );
454 : : // are there really control models which survive isCellBindingAllowed, but don't have a ClassId
455 : : // property?
456 : 0 : bAllow = false;
457 : : }
458 : : }
459 : :
460 : 0 : return bAllow;
461 : : }
462 : :
463 : : //------------------------------------------------------------------------
464 : 0 : bool CellBindingHelper::isCellBindingAllowed( ) const
465 : : {
466 : 0 : bool bAllow( false );
467 : :
468 : 0 : Reference< XBindableValue > xBindable( m_xControlModel, UNO_QUERY );
469 : 0 : if ( xBindable.is() )
470 : : {
471 : : // the control can potentially be bound to an external value
472 : : // Does it live within a Calc document, and is able to supply CellBindings?
473 : 0 : bAllow = isSpreadsheetDocumentWhichSupplies( SERVICE_SHEET_CELL_BINDING );
474 : : }
475 : :
476 : : // disallow for some types
477 : : // TODO: shouldn't the XBindableValue supply a list of supported types, and we can distingusih
478 : : // using this list? The current behavior below is somewhat hackish ...
479 : 0 : if ( bAllow )
480 : : {
481 : : try
482 : : {
483 : 0 : sal_Int16 nClassId = FormComponentType::CONTROL;
484 : 0 : m_xControlModel->getPropertyValue( PROPERTY_CLASSID ) >>= nClassId;
485 : 0 : if ( ( FormComponentType::DATEFIELD == nClassId ) || ( FormComponentType::TIMEFIELD == nClassId ) )
486 : 0 : bAllow = false;
487 : : }
488 : 0 : catch( const Exception& )
489 : : {
490 : : OSL_FAIL( "CellBindingHelper::isCellBindingAllowed: caught an exception!" );
491 : 0 : bAllow = false;
492 : : }
493 : : }
494 : 0 : return bAllow;
495 : : }
496 : :
497 : : //------------------------------------------------------------------------
498 : 0 : bool CellBindingHelper::isCellBinding( const Reference< XValueBinding >& _rxBinding ) const
499 : : {
500 : 0 : return doesComponentSupport( _rxBinding.get(), SERVICE_SHEET_CELL_BINDING );
501 : : }
502 : :
503 : : //------------------------------------------------------------------------
504 : 0 : bool CellBindingHelper::isCellIntegerBinding( const Reference< XValueBinding >& _rxBinding ) const
505 : : {
506 : 0 : return doesComponentSupport( _rxBinding.get(), SERVICE_SHEET_CELL_INT_BINDING );
507 : : }
508 : :
509 : : //------------------------------------------------------------------------
510 : 0 : bool CellBindingHelper::isCellRangeListSource( const Reference< XListEntrySource >& _rxSource ) const
511 : : {
512 : 0 : return doesComponentSupport( _rxSource.get(), SERVICE_SHEET_CELLRANGE_LISTSOURCE );
513 : : }
514 : :
515 : : //------------------------------------------------------------------------
516 : 0 : bool CellBindingHelper::doesComponentSupport( const Reference< XInterface >& _rxComponent, const ::rtl::OUString& _rService ) const
517 : : {
518 : 0 : bool bDoes = false;
519 : 0 : Reference< XServiceInfo > xSI( _rxComponent, UNO_QUERY );
520 : 0 : bDoes = xSI.is() && xSI->supportsService( _rService );
521 : 0 : return bDoes;
522 : : }
523 : :
524 : : //------------------------------------------------------------------------
525 : 0 : Reference< XValueBinding > CellBindingHelper::getCurrentBinding( ) const
526 : : {
527 : 0 : Reference< XValueBinding > xBinding;
528 : 0 : Reference< XBindableValue > xBindable( m_xControlModel, UNO_QUERY );
529 : 0 : if ( xBindable.is() )
530 : 0 : xBinding = xBindable->getValueBinding();
531 : 0 : return xBinding;
532 : : }
533 : :
534 : : //------------------------------------------------------------------------
535 : 0 : Reference< XListEntrySource > CellBindingHelper::getCurrentListSource( ) const
536 : : {
537 : 0 : Reference< XListEntrySource > xSource;
538 : 0 : Reference< XListEntrySink > xSink( m_xControlModel, UNO_QUERY );
539 : 0 : if ( xSink.is() )
540 : 0 : xSource = xSink->getListEntrySource();
541 : 0 : return xSource;
542 : : }
543 : :
544 : : //------------------------------------------------------------------------
545 : 0 : void CellBindingHelper::setBinding( const Reference< XValueBinding >& _rxBinding )
546 : : {
547 : 0 : Reference< XBindableValue > xBindable( m_xControlModel, UNO_QUERY );
548 : : OSL_PRECOND( xBindable.is(), "CellBindingHelper::setBinding: the object is not bindable!" );
549 : 0 : if ( xBindable.is() )
550 : 0 : xBindable->setValueBinding( _rxBinding );
551 : 0 : }
552 : :
553 : : //------------------------------------------------------------------------
554 : 0 : void CellBindingHelper::setListSource( const Reference< XListEntrySource >& _rxSource )
555 : : {
556 : 0 : Reference< XListEntrySink > xSink( m_xControlModel, UNO_QUERY );
557 : : OSL_PRECOND( xSink.is(), "CellBindingHelper::setListSource: the object is no list entry sink!" );
558 : 0 : if ( xSink.is() )
559 : 0 : xSink->setListEntrySource( _rxSource );
560 : 0 : }
561 : :
562 : : //............................................................................
563 : : } // namespace pcr
564 : : //............................................................................
565 : :
566 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|