1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <com/sun/star/frame/XModel.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
25 #include <com/sun/star/table/CellAddress.hpp>
26 #include <com/sun/star/table/CellRangeAddress.hpp>
27 #include <com/sun/star/form/binding/XValueBinding.hpp>
28 #include <com/sun/star/form/binding/XListEntrySource.hpp>
29 #include <com/sun/star/sheet/XSpreadsheet.hpp>
35 /** encapsulates functionality related to binding a form control to a spreadsheet cell
37 class CellBindingHelper final
39 css::uno::Reference
< css::beans::XPropertySet
>
40 m_xControlModel
; // the model we work for
41 css::uno::Reference
< css::sheet::XSpreadsheetDocument
>
42 m_xDocument
; // the document where the model lives
46 @param _rxControlModel
47 the control model which is or will be bound
50 const css::uno::Reference
< css::beans::XPropertySet
>& _rxControlModel
,
51 const css::uno::Reference
< css::frame::XModel
>& _rxContextDocument
54 /** determines whether the given model is a spreadsheet document model
56 <p>If this method returns <FALSE/>, you cannot instantiate a CellBindingHelper with
57 the document, since then no of its functionality will be available.</p>
59 static bool isSpreadsheetDocument(
60 const css::uno::Reference
< css::frame::XModel
>& _rxContextDocument
63 /** gets a cell binding for the given address
65 isCellBindingAllowed returns <TRUE/>
67 css::uno::Reference
< css::form::binding::XValueBinding
>
68 createCellBindingFromStringAddress(
69 const OUString
& _rAddress
,
70 bool _bSupportIntegerExchange
73 /** creates a cell binding (supporting integer exchange, if requested) for
74 the given address object
76 css::uno::Reference
< css::form::binding::XValueBinding
>
77 createCellBindingFromAddress(
78 const css::table::CellAddress
& _rAddress
,
79 bool _bSupportIntegerExchange
82 /** gets a cell range list source binding for the given address
84 css::uno::Reference
< css::form::binding::XListEntrySource
>
85 createCellListSourceFromStringAddress( const OUString
& _rAddress
) const;
87 /** creates a string representation for the given value binding's address
89 <p>If the sheet of the bound cell is the same as the sheet which our control belongs
90 to, then the sheet name is omitted in the resulting string representation.</p>
93 The binding is a valid cell binding, or <NULL/>
96 OUString
getStringAddressFromCellBinding(
97 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
100 /** creates an address object for the given value binding's address
103 The binding is a valid cell binding, or <NULL/>
105 <FALSE/> if and only if an error occurred and no valid address could be obtained
108 bool getAddressFromCellBinding(
109 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
,
110 css::table::CellAddress
& _rAddress
113 /** creates a string representation for the given list source's range address
115 <p>If the sheet of the cell range which acts as list source is the same as the
116 sheet which our control belongs to, then the sheet name is omitted in the
117 resulting string representation.</p>
120 The object is a valid cell range list source, or <NULL/>
121 @see isCellRangeListSource
123 OUString
getStringAddressFromCellListSource(
124 const css::uno::Reference
< css::form::binding::XListEntrySource
>& _rxSource
127 /** returns the current binding of our control model, if any.
129 css::uno::Reference
< css::form::binding::XValueBinding
>
130 getCurrentBinding( ) const;
132 /** returns the current external list source of the control model, if any
134 css::uno::Reference
< css::form::binding::XListEntrySource
>
135 getCurrentListSource( ) const;
137 /** sets a new binding for our control model
139 the control model is bindable (which is implied by <member>isCellBindingAllowed</member>
143 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
146 /** sets a list source for our control model
148 the control model is a list sink (which is implied by <member>isListCellRangeAllowed</member>
152 const css::uno::Reference
< css::form::binding::XListEntrySource
>& _rxSource
155 /** checks whether it's possible to bind the control model to a spreadsheet cell
157 bool isCellBindingAllowed( ) const;
159 /** checks whether it's possible to bind the control model to a spreadsheet cell,
160 with exchanging integer values
162 bool isCellIntegerBindingAllowed( ) const;
164 /** checks whether it's possible to bind the control model to range of spreadsheet cells
165 supplying the list entries
167 bool isListCellRangeAllowed( ) const;
169 /** checks whether a given binding is a spreadsheet cell binding
171 static bool isCellBinding(
172 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
175 /** checks whether a given binding is a spreadsheet cell binding, exchanging
178 static bool isCellIntegerBinding(
179 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
182 /** checks whether a given list source is a spreadsheet cell list source
184 static bool isCellRangeListSource(
185 const css::uno::Reference
< css::form::binding::XListEntrySource
>& _rxSource
188 /** retrieves the index of the sheet which our control belongs to
189 @return the index of the sheet which our control belongs to or -1, if an error occurred
191 sal_Int16
getControlSheetIndex(
192 css::uno::Reference
< css::sheet::XSpreadsheet
>& _out_rxSheet
196 /** creates an address object from a string representation of a cell address
198 bool convertStringAddress(
199 const OUString
& _rAddressDescription
,
200 css::table::CellAddress
& /* [out] */ _rAddress
203 /** creates an address range object from a string representation of a cell range address
205 bool convertStringAddress(
206 const OUString
& _rAddressDescription
,
207 css::table::CellRangeAddress
& /* [out] */ _rAddress
210 /** determines if our document is a spreadsheet document, *and* can supply
213 bool isSpreadsheetDocumentWhichSupplies( const OUString
& _rService
) const;
215 /** checks whether a given component supports a given service
217 static bool doesComponentSupport(
218 const css::uno::Reference
< css::uno::XInterface
>& _rxComponent
,
219 const OUString
& _rService
222 /** uses the document (it's factory interface, respectively) to create a component instance
225 @param _rArgumentName
226 the name of the single argument to pass during creation. May be empty, in this case
227 no arguments are passed
228 @param _rArgumentValue
229 the value of the instantiation argument. Not evaluated if <arg>_rArgumentName</arg>
232 css::uno::Reference
< css::uno::XInterface
>
233 createDocumentDependentInstance(
234 const OUString
& _rService
,
235 const OUString
& _rArgumentName
,
236 const css::uno::Any
& _rArgumentValue
239 /** converts an address representation into another one
241 @param _rInputProperty
242 the input property name for the conversion service
244 the input property value for the conversion service
245 @param _rOutputProperty
246 the output property name for the conversion service
248 the output property value for the conversion service
250 if <TRUE/>, the RangeAddressConversion service will be used, else
251 the AddressConversion service
254 <TRUE/> if any only if the conversion was successful
256 @see css::table::CellAddressConversion
257 @see css::table::CellRangeAddressConversion
259 bool doConvertAddressRepresentations(
260 const OUString
& _rInputProperty
,
261 const css::uno::Any
& _rInputValue
,
262 const OUString
& _rOutputProperty
,
263 css::uno::Any
& _rOutputValue
,
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */