1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #ifndef EXTENSIONS_PROPCTRLR_CELLBINDINGHELPER_HXX
29 #define EXTENSIONS_PROPCTRLR_CELLBINDINGHELPER_HXX
31 /** === begin UNO includes === **/
32 #include <com/sun/star/frame/XModel.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
35 #include <com/sun/star/table/CellAddress.hpp>
36 #include <com/sun/star/table/CellRangeAddress.hpp>
37 #include <com/sun/star/form/binding/XValueBinding.hpp>
38 #include <com/sun/star/form/binding/XListEntrySource.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #include <com/sun/star/sheet/XSpreadsheet.hpp>
41 /** === end UNO includes === **/
43 //............................................................................
46 //............................................................................
48 //========================================================================
50 //========================================================================
51 /** encapsulates functionality related to binding a form control to a spreadsheet cell
53 class CellBindingHelper
56 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>
57 m_xControlModel
; // the model we work for
58 ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XSpreadsheetDocument
>
59 m_xDocument
; // the document where the model lives
63 @param _rxControlModel
64 the control model which is or will be bound
67 const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _rxControlModel
,
68 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& _rxContextDocument
72 /** determines whether the given model is a spreadsheet document model
74 <p>If this method returns <FALSE/>, you cannot instantiate a CellBindingHelper with
75 the document, since then no of it's functionality will be available.</p>
77 static sal_Bool
isSpreadsheetDocument(
78 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& _rxContextDocument
81 /** gets a cell binding for the given address
83 isCellBindingAllowed returns <TRUE/>
85 ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XValueBinding
>
86 createCellBindingFromStringAddress(
87 const ::rtl::OUString
& _rAddress
,
88 bool _bSupportIntegerExchange
= false
91 /** creates a cell binding (supporting integer exchange, if requested) for
92 the given address object
94 ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XValueBinding
>
95 createCellBindingFromAddress(
96 const ::com::sun::star::table::CellAddress
& _rAddress
,
97 bool _bSupportIntegerExchange
= false
100 /** gets a cell range list source binding for the given address
102 ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XListEntrySource
>
103 createCellListSourceFromStringAddress( const ::rtl::OUString
& _rAddress
) const;
105 /** creates a string representation for the given value binding's address
107 <p>If the sheet of the bound cell is the same as the sheet which our control belongs
108 to, then the sheet name is omitted in the resulting string representation.</p>
111 The binding is a valid cell binding, or <NULL/>
114 ::rtl::OUString
getStringAddressFromCellBinding(
115 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XValueBinding
>& _rxBinding
118 /** creates an address object for the given value binding's address
121 The binding is a valid cell binding, or <NULL/>
123 <FALSE/> if and only if an error occured and no valid address could be obtained
126 bool getAddressFromCellBinding(
127 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XValueBinding
>& _rxBinding
,
128 ::com::sun::star::table::CellAddress
& _rAddress
131 /** creates a string representation for the given list source's range address
133 <p>If the sheet of the cell range which acts as list source is the same as the
134 sheet which our control belongs to, then the sheet name is omitted in the
135 resulting string representation.</p>
138 The object is a valid cell range list source, or <NULL/>
139 @see isCellRangeListSource
141 ::rtl::OUString
getStringAddressFromCellListSource(
142 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XListEntrySource
>& _rxSource
145 /** returns the current binding of our control model, if any.
147 ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XValueBinding
>
148 getCurrentBinding( ) const;
150 /** returns the current external list source of the control model, if any
152 ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XListEntrySource
>
153 getCurrentListSource( ) const;
155 /** sets a new binding for our control model
157 the control model is bindable (which is implied by <member>isCellBindingAllowed</member>
161 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XValueBinding
>& _rxBinding
164 /** sets a list source for our control model
166 the control model is a list sink (which is implied by <member>isListCellRangeAllowed</member>
170 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XListEntrySource
>& _rxSource
173 /** checks whether it's possible to bind the control model to a spreadsheet cell
175 bool isCellBindingAllowed( ) const;
177 /** checks whether it's possible to bind the control model to a spreadsheet cell,
178 with exchanging integer values
180 bool isCellIntegerBindingAllowed( ) const;
182 /** checks whether it's possible to bind the control model to range of spreadsheet cells
183 supplying the list entries
185 bool isListCellRangeAllowed( ) const;
187 /** checks whether a given binding is a spreadsheet cell binding
190 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XValueBinding
>& _rxBinding
193 /** checks whether a given binding is a spreadsheet cell binding, exchanging
196 bool isCellIntegerBinding(
197 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XValueBinding
>& _rxBinding
200 /** checks whether a given list source is a spreadsheet cell list source
202 bool isCellRangeListSource(
203 const ::com::sun::star::uno::Reference
< ::com::sun::star::form::binding::XListEntrySource
>& _rxSource
206 /** retrieves the index of the sheet which our control belongs to
207 @return the index of the sheet which our control belongs to or -1, if an error occured
209 sal_Int16
getControlSheetIndex(
210 ::com::sun::star::uno::Reference
< ::com::sun::star::sheet::XSpreadsheet
>& _out_rxSheet
214 /** creates an address object from a string representation of a cell address
216 bool convertStringAddress(
217 const ::rtl::OUString
& _rAddressDescription
,
218 ::com::sun::star::table::CellAddress
& /* [out] */ _rAddress
221 /** creates an address range object from a string representation of a cell range address
223 bool convertStringAddress(
224 const ::rtl::OUString
& _rAddressDescription
,
225 ::com::sun::star::table::CellRangeAddress
& /* [out] */ _rAddress
228 /** determines if our document is a spreadsheet document, *and* can supply
231 bool isSpreadsheetDocumentWhichSupplies( const ::rtl::OUString
& _rService
) const;
233 /** checkes whether a given component supports a given servive
235 bool doesComponentSupport(
236 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxComponent
,
237 const ::rtl::OUString
& _rService
240 /** uses the document (it's factory interface, respectively) to create a component instance
243 @param _rArgumentName
244 the name of the single argument to pass during creation. May be empty, in this case
245 no arguments are passed
246 @param _rArgumentValue
247 the value of the instantiation argument. Not evaluated if <arg>_rArgumentName</arg>
250 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>
251 createDocumentDependentInstance(
252 const ::rtl::OUString
& _rService
,
253 const ::rtl::OUString
& _rArgumentName
,
254 const ::com::sun::star::uno::Any
& _rArgumentValue
257 /** converts an address representation into another one
259 @param _rInputProperty
260 the input property name for the conversion service
262 the input property value for the conversion service
263 @param _rOutputProperty
264 the output property name for the conversion service
266 the output property value for the conversion service
268 if <TRUE/>, the RangeAddressConversion service will be used, else
269 the AddressConversion service
272 <TRUE/> if any only if the conversion was successfull
274 @see com::sun::star::table::CellAddressConversion
275 @see com::sun::star::table::CellRangeAddressConversion
277 bool doConvertAddressRepresentations(
278 const ::rtl::OUString
& _rInputProperty
,
279 const ::com::sun::star::uno::Any
& _rInputValue
,
280 const ::rtl::OUString
& _rOutputProperty
,
281 ::com::sun::star::uno::Any
& _rOutputValue
,
283 ) const SAL_THROW(());
286 //............................................................................
288 //............................................................................
290 #endif // EXTENSIONS_PROPCTRLR_CELLBINDINGHELPER_HXX