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 .
20 #ifndef INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_CELLBINDINGHELPER_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_CELLBINDINGHELPER_HXX
23 #include <com/sun/star/frame/XModel.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
26 #include <com/sun/star/table/CellAddress.hpp>
27 #include <com/sun/star/table/CellRangeAddress.hpp>
28 #include <com/sun/star/form/binding/XValueBinding.hpp>
29 #include <com/sun/star/form/binding/XListEntrySource.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/sheet/XSpreadsheet.hpp>
37 /** encapsulates functionality related to binding a form control to a spreadsheet cell
39 class CellBindingHelper final
41 css::uno::Reference
< css::beans::XPropertySet
>
42 m_xControlModel
; // the model we work for
43 css::uno::Reference
< css::sheet::XSpreadsheetDocument
>
44 m_xDocument
; // the document where the model lives
48 @param _rxControlModel
49 the control model which is or will be bound
52 const css::uno::Reference
< css::beans::XPropertySet
>& _rxControlModel
,
53 const css::uno::Reference
< css::frame::XModel
>& _rxContextDocument
56 /** determines whether the given model is a spreadsheet document model
58 <p>If this method returns <FALSE/>, you cannot instantiate a CellBindingHelper with
59 the document, since then no of its functionality will be available.</p>
61 static bool isSpreadsheetDocument(
62 const css::uno::Reference
< css::frame::XModel
>& _rxContextDocument
65 /** gets a cell binding for the given address
67 isCellBindingAllowed returns <TRUE/>
69 css::uno::Reference
< css::form::binding::XValueBinding
>
70 createCellBindingFromStringAddress(
71 const OUString
& _rAddress
,
72 bool _bSupportIntegerExchange
75 /** creates a cell binding (supporting integer exchange, if requested) for
76 the given address object
78 css::uno::Reference
< css::form::binding::XValueBinding
>
79 createCellBindingFromAddress(
80 const css::table::CellAddress
& _rAddress
,
81 bool _bSupportIntegerExchange
84 /** gets a cell range list source binding for the given address
86 css::uno::Reference
< css::form::binding::XListEntrySource
>
87 createCellListSourceFromStringAddress( const OUString
& _rAddress
) const;
89 /** creates a string representation for the given value binding's address
91 <p>If the sheet of the bound cell is the same as the sheet which our control belongs
92 to, then the sheet name is omitted in the resulting string representation.</p>
95 The binding is a valid cell binding, or <NULL/>
98 OUString
getStringAddressFromCellBinding(
99 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
102 /** creates an address object for the given value binding's address
105 The binding is a valid cell binding, or <NULL/>
107 <FALSE/> if and only if an error occurred and no valid address could be obtained
110 bool getAddressFromCellBinding(
111 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
,
112 css::table::CellAddress
& _rAddress
115 /** creates a string representation for the given list source's range address
117 <p>If the sheet of the cell range which acts as list source is the same as the
118 sheet which our control belongs to, then the sheet name is omitted in the
119 resulting string representation.</p>
122 The object is a valid cell range list source, or <NULL/>
123 @see isCellRangeListSource
125 OUString
getStringAddressFromCellListSource(
126 const css::uno::Reference
< css::form::binding::XListEntrySource
>& _rxSource
129 /** returns the current binding of our control model, if any.
131 css::uno::Reference
< css::form::binding::XValueBinding
>
132 getCurrentBinding( ) const;
134 /** returns the current external list source of the control model, if any
136 css::uno::Reference
< css::form::binding::XListEntrySource
>
137 getCurrentListSource( ) const;
139 /** sets a new binding for our control model
141 the control model is bindable (which is implied by <member>isCellBindingAllowed</member>
145 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
148 /** sets a list source for our control model
150 the control model is a list sink (which is implied by <member>isListCellRangeAllowed</member>
154 const css::uno::Reference
< css::form::binding::XListEntrySource
>& _rxSource
157 /** checks whether it's possible to bind the control model to a spreadsheet cell
159 bool isCellBindingAllowed( ) const;
161 /** checks whether it's possible to bind the control model to a spreadsheet cell,
162 with exchanging integer values
164 bool isCellIntegerBindingAllowed( ) const;
166 /** checks whether it's possible to bind the control model to range of spreadsheet cells
167 supplying the list entries
169 bool isListCellRangeAllowed( ) const;
171 /** checks whether a given binding is a spreadsheet cell binding
173 static bool isCellBinding(
174 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
177 /** checks whether a given binding is a spreadsheet cell binding, exchanging
180 static bool isCellIntegerBinding(
181 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
184 /** checks whether a given list source is a spreadsheet cell list source
186 static bool isCellRangeListSource(
187 const css::uno::Reference
< css::form::binding::XListEntrySource
>& _rxSource
190 /** retrieves the index of the sheet which our control belongs to
191 @return the index of the sheet which our control belongs to or -1, if an error occurred
193 sal_Int16
getControlSheetIndex(
194 css::uno::Reference
< css::sheet::XSpreadsheet
>& _out_rxSheet
198 /** creates an address object from a string representation of a cell address
200 bool convertStringAddress(
201 const OUString
& _rAddressDescription
,
202 css::table::CellAddress
& /* [out] */ _rAddress
205 /** creates an address range object from a string representation of a cell range address
207 bool convertStringAddress(
208 const OUString
& _rAddressDescription
,
209 css::table::CellRangeAddress
& /* [out] */ _rAddress
212 /** determines if our document is a spreadsheet document, *and* can supply
215 bool isSpreadsheetDocumentWhichSupplies( const OUString
& _rService
) const;
217 /** checks whether a given component supports a given servive
219 static bool doesComponentSupport(
220 const css::uno::Reference
< css::uno::XInterface
>& _rxComponent
,
221 const OUString
& _rService
224 /** uses the document (it's factory interface, respectively) to create a component instance
227 @param _rArgumentName
228 the name of the single argument to pass during creation. May be empty, in this case
229 no arguments are passed
230 @param _rArgumentValue
231 the value of the instantiation argument. Not evaluated if <arg>_rArgumentName</arg>
234 css::uno::Reference
< css::uno::XInterface
>
235 createDocumentDependentInstance(
236 const OUString
& _rService
,
237 const OUString
& _rArgumentName
,
238 const css::uno::Any
& _rArgumentValue
241 /** converts an address representation into another one
243 @param _rInputProperty
244 the input property name for the conversion service
246 the input property value for the conversion service
247 @param _rOutputProperty
248 the output property name for the conversion service
250 the output property value for the conversion service
252 if <TRUE/>, the RangeAddressConversion service will be used, else
253 the AddressConversion service
256 <TRUE/> if any only if the conversion was successful
258 @see css::table::CellAddressConversion
259 @see css::table::CellRangeAddressConversion
261 bool doConvertAddressRepresentations(
262 const OUString
& _rInputProperty
,
263 const css::uno::Any
& _rInputValue
,
264 const OUString
& _rOutputProperty
,
265 css::uno::Any
& _rOutputValue
,
274 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_CELLBINDINGHELPER_HXX
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */