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/beans/XPropertySet.hpp>
23 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
24 #include <com/sun/star/table/CellAddress.hpp>
25 #include <com/sun/star/table/CellRangeAddress.hpp>
26 #include <com/sun/star/form/binding/XValueBinding.hpp>
27 #include <com/sun/star/form/binding/XListEntrySource.hpp>
28 #include <com/sun/star/frame/XModel.hpp>
33 //= FormCellBindingHelper
34 /** encapsulates functionality related to binding a form control to a spreadsheet cell
36 class FormCellBindingHelper
38 css::uno::Reference
< css::beans::XPropertySet
>
39 m_xControlModel
; // the model we work for
40 css::uno::Reference
< css::sheet::XSpreadsheetDocument
>
41 m_xDocument
; // the document where the model lives
44 /** determines whether the given control model lives in a spreadsheet document
45 <p>If this method returns <FALSE/>, you cannot instantiate a CellBindingHelper with
46 this model, since then no of its functionality will be available.</p>
48 static bool livesInSpreadsheetDocument(
49 const css::uno::Reference
< css::beans::XPropertySet
>& _rxControlModel
53 @param _rxControlModel
54 the control model which is or will be bound
56 the document. If this is <NULL/>, the document will be obtained from the model
57 itself by walk on up the chain of its ancestors.<br/>
58 This parameter can be used if the control model is not (yet) part of a document
61 FormCellBindingHelper(
62 const css::uno::Reference
< css::beans::XPropertySet
>& _rxControlModel
,
63 const css::uno::Reference
< css::frame::XModel
>& _rxDocument
66 /** gets a cell binding for the given address
68 isCellBindingAllowed returns <TRUE/>
70 css::uno::Reference
< css::form::binding::XValueBinding
>
71 createCellBindingFromStringAddress(
72 const OUString
& _rAddress
,
73 bool _bUseIntegerBinding
76 /** gets a cell range list source binding for the given address
78 css::uno::Reference
< css::form::binding::XListEntrySource
>
79 createCellListSourceFromStringAddress( const OUString
& _rAddress
) const;
81 /** creates a string representation for the given value binding's address
83 <p>If the sheet of the bound cell is the same as the sheet which our control belongs
84 to, then the sheet name is omitted in the resulting string representation.</p>
87 The binding is a valid cell binding, or <NULL/>
90 OUString
getStringAddressFromCellBinding(
91 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
94 /** creates a string representation for the given list source's range address
96 <p>If the sheet of the cell range which acts as list source is the same as the
97 sheet which our control belongs to, then the sheet name is omitted in the
98 resulting string representation.</p>
101 The object is a valid cell range list source, or <NULL/>
102 @see isCellRangeListSource
104 OUString
getStringAddressFromCellListSource(
105 const css::uno::Reference
< css::form::binding::XListEntrySource
>& _rxSource
108 /** returns the current binding of our control model, if any.
110 css::uno::Reference
< css::form::binding::XValueBinding
>
111 getCurrentBinding( ) const;
113 /** returns the current external list source of the control model, if any
115 css::uno::Reference
< css::form::binding::XListEntrySource
>
116 getCurrentListSource( ) const;
118 /** sets a new binding for our control model
120 the control model is bindable (which is implied by <member>isCellBindingAllowed</member>
124 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
127 /** sets a list source for our control model
129 the control model is a list sink (which is implied by <member>isListCellRangeAllowed</member>
133 const css::uno::Reference
< css::form::binding::XListEntrySource
>& _rxSource
136 /** checks whether it's possible to bind the control model to a spreadsheet cell
138 bool isCellBindingAllowed( ) const;
140 /** checks whether within the given document, it's possible to bind control models to spreadsheet cells
142 static bool isCellBindingAllowed(
143 const css::uno::Reference
< css::frame::XModel
>& _rxDocument
146 /** checks whether it's possible to bind the control model to a range of spreadsheet cells
147 supplying the list entries
149 bool isListCellRangeAllowed( ) const;
151 /** checks whether within the given document, it's possible to bind the control model to a range of
152 spreadsheet cells supplying the list entries
154 static bool isListCellRangeAllowed(
155 const css::uno::Reference
< css::frame::XModel
>& _rxDocument
158 /** checks whether a given binding is a spreadsheet cell binding
160 static bool isCellBinding(
161 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
164 /** checks whether a given binding is a spreadsheet cell binding, exchanging
167 static bool isCellIntegerBinding(
168 const css::uno::Reference
< css::form::binding::XValueBinding
>& _rxBinding
171 /** checks whether a given list source is a spreadsheet cell list source
173 static bool isCellRangeListSource(
174 const css::uno::Reference
< css::form::binding::XListEntrySource
>& _rxSource
178 /** creates an address object from a string representation of a cell address
180 bool convertStringAddress(
181 const OUString
& _rAddressDescription
,
182 css::table::CellAddress
& /* [out] */ _rAddress
185 /** creates an address range object from a string representation of a cell range address
187 bool convertStringAddress(
188 const OUString
& _rAddressDescription
,
189 css::table::CellRangeAddress
& /* [out] */ _rAddress
192 /** determines if our document is a spreadsheet document, *and* can supply
195 bool isSpreadsheetDocumentWhichSupplies( const OUString
& _rService
) const;
197 /** determines if our document is a spreadsheet document, *and* can supply
200 static bool isSpreadsheetDocumentWhichSupplies(
201 const css::uno::Reference
< css::sheet::XSpreadsheetDocument
>& _rxDocument
,
202 const OUString
& _rService
205 /** checks whether a given component supports a given service
207 static bool doesComponentSupport(
208 const css::uno::Reference
< css::uno::XInterface
>& _rxComponent
,
209 const OUString
& _rService
212 /** uses the document (it's factory interface, respectively) to create a component instance
215 @param _rArgumentName
216 the name of the single argument to pass during creation. May be empty, in this case
217 no arguments are passed
218 @param _rArgumentValue
219 the value of the instantiation argument. Not evaluated if <arg>_rArgumentName</arg>
222 css::uno::Reference
< css::uno::XInterface
>
223 createDocumentDependentInstance(
224 const OUString
& _rService
,
225 const OUString
& _rArgumentName
,
226 const css::uno::Any
& _rArgumentValue
229 /** converts an address representation into another one
231 @param _rInputProperty
232 the input property name for the conversion service
234 the input property value for the conversion service
235 @param _rOutputProperty
236 the output property name for the conversion service
238 the output property value for the conversion service
240 if <TRUE/>, the RangeAddressConversion service will be used, else
241 the AddressConversion service
244 <TRUE/> if any only if the conversion was successful
246 @see css::table::CellAddressConversion
247 @see css::table::CellRangeAddressConversion
249 bool doConvertAddressRepresentations(
250 const OUString
& _rInputProperty
,
251 const css::uno::Any
& _rInputValue
,
252 const OUString
& _rOutputProperty
,
253 css::uno::Any
& _rOutputValue
,
258 } // namespace xmloff
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */