Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / xmloff / source / forms / formcellbinding.hxx
blob346669500501826bb8ce9df1377594a693b79476
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_XMLOFF_SOURCE_FORMS_FORMCELLBINDING_HXX
21 #define INCLUDED_XMLOFF_SOURCE_FORMS_FORMCELLBINDING_HXX
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/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/frame/XModel.hpp>
32 namespace xmloff
35 //= FormCellBindingHelper
36 /** encapsulates functionality related to binding a form control to a spreadsheet cell
38 class FormCellBindingHelper
40 protected:
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
46 public:
47 /** determines whether the given control model lives in a spreadsheet document
48 <p>If this method returns <FALSE/>, you cannot instantiate a CellBindingHelper with
49 this model, since then no of its functionality will be available.</p>
51 static bool livesInSpreadsheetDocument(
52 const css::uno::Reference< css::beans::XPropertySet >& _rxControlModel
55 /** ctor
56 @param _rxControlModel
57 the control model which is or will be bound
58 @param _rxDocument
59 the document. If this is <NULL/>, the document will be obtained from the model
60 itself by walkon up the chain of its ancestors.<br/>
61 This parameter can be used if the control model is not (yet) part of a document
62 model.
64 FormCellBindingHelper(
65 const css::uno::Reference< css::beans::XPropertySet >& _rxControlModel,
66 const css::uno::Reference< css::frame::XModel >& _rxDocument
69 public:
70 /** gets a cell binding for the given address
71 @precond
72 isCellBindingAllowed returns <TRUE/>
74 css::uno::Reference< css::form::binding::XValueBinding >
75 createCellBindingFromStringAddress(
76 const OUString& _rAddress,
77 bool _bUseIntegerBinding
78 ) const;
80 /** gets a cell range list source binding for the given address
82 css::uno::Reference< css::form::binding::XListEntrySource >
83 createCellListSourceFromStringAddress( const OUString& _rAddress ) const;
85 /** creates a string representation for the given value binding's address
87 <p>If the sheet of the bound cell is the same as the sheet which our control belongs
88 to, then the sheet name is omitted in the resulting string representation.</p>
90 @precond
91 The binding is a valid cell binding, or <NULL/>
92 @see isCellBinding
94 OUString getStringAddressFromCellBinding(
95 const css::uno::Reference< css::form::binding::XValueBinding >& _rxBinding
96 ) const;
98 /** creates a string representation for the given list source's range address
100 <p>If the sheet of the cell range which acts as list source is the same as the
101 sheet which our control belongs to, then the sheet name is omitted in the
102 resulting string representation.</p>
104 @precond
105 The object is a valid cell range list source, or <NULL/>
106 @see isCellRangeListSource
108 OUString getStringAddressFromCellListSource(
109 const css::uno::Reference< css::form::binding::XListEntrySource >& _rxSource
110 ) const;
112 /** returns the current binding of our control model, if any.
114 css::uno::Reference< css::form::binding::XValueBinding >
115 getCurrentBinding( ) const;
117 /** returns the current external list source of the control model, if any
119 css::uno::Reference< css::form::binding::XListEntrySource >
120 getCurrentListSource( ) const;
122 /** sets a new binding for our control model
123 @precond
124 the control model is bindable (which is implied by <member>isCellBindingAllowed</member>
125 returning <TRUE/>)
127 void setBinding(
128 const css::uno::Reference< css::form::binding::XValueBinding >& _rxBinding
131 /** sets a list source for our control model
132 @precond
133 the control model is a list sink (which is implied by <member>isListCellRangeAllowed</member>
134 returning <TRUE/>)
136 void setListSource(
137 const css::uno::Reference< css::form::binding::XListEntrySource >& _rxSource
140 /** checks whether it's possible to bind the control model to a spreadsheet cell
142 bool isCellBindingAllowed( ) const;
144 /** checks whether within the given document, it's possible to bind control models to spreadsheet cells
146 static bool isCellBindingAllowed(
147 const css::uno::Reference< css::frame::XModel >& _rxDocument
150 /** checks whether it's possible to bind the control model to a range of spreadsheet cells
151 supplying the list entries
153 bool isListCellRangeAllowed( ) const;
155 /** checks whether within the given document, it's possible to bind the control model to a range of
156 spreadsheet cells supplying the list entries
158 static bool isListCellRangeAllowed(
159 const css::uno::Reference< css::frame::XModel >& _rxDocument
162 /** checks whether a given binding is a spreadsheet cell binding
164 static bool isCellBinding(
165 const css::uno::Reference< css::form::binding::XValueBinding >& _rxBinding
168 /** checks whether a given binding is a spreadsheet cell binding, exchanging
169 integer values
171 static bool isCellIntegerBinding(
172 const css::uno::Reference< css::form::binding::XValueBinding >& _rxBinding
175 /** checks whether a given list source is a spreadsheet cell list source
177 static bool isCellRangeListSource(
178 const css::uno::Reference< css::form::binding::XListEntrySource >& _rxSource
181 protected:
182 /** creates an address object from a string representation of a cell address
184 bool convertStringAddress(
185 const OUString& _rAddressDescription,
186 css::table::CellAddress& /* [out] */ _rAddress
187 ) const;
189 /** creates an address range object from a string representation of a cell range address
191 bool convertStringAddress(
192 const OUString& _rAddressDescription,
193 css::table::CellRangeAddress& /* [out] */ _rAddress
194 ) const;
196 /** determines if our document is a spreadsheet document, *and* can supply
197 the given service
199 bool isSpreadsheetDocumentWhichSupplies( const OUString& _rService ) const;
201 /** determines if our document is a spreadsheet document, *and* can supply
202 the given service
204 static bool isSpreadsheetDocumentWhichSupplies(
205 const css::uno::Reference< css::sheet::XSpreadsheetDocument >& _rxDocument,
206 const OUString& _rService
209 /** checkes whether a given component supports a given servive
211 static bool doesComponentSupport(
212 const css::uno::Reference< css::uno::XInterface >& _rxComponent,
213 const OUString& _rService
216 /** uses the document (it's factory interface, respectively) to create a component instance
217 @param _rService
218 the service name
219 @param _rArgumentName
220 the name of the single argument to pass during creation. May be empty, in this case
221 no arguments are passed
222 @param _rArgumentValue
223 the value of the instantiation argument. Not evaluated if <arg>_rArgumentName</arg>
224 is empty.
226 css::uno::Reference< css::uno::XInterface >
227 createDocumentDependentInstance(
228 const OUString& _rService,
229 const OUString& _rArgumentName,
230 const css::uno::Any& _rArgumentValue
231 ) const;
233 /** converts an address representation into another one
235 @param _rInputProperty
236 the input property name for the conversion service
237 @param _rInputValue
238 the input property value for the conversion service
239 @param _rOutputProperty
240 the output property name for the conversion service
241 @param _rOutputValue
242 the output property value for the conversion service
243 @param _bIsRange
244 if <TRUE/>, the RangeAddressConversion service will be used, else
245 the AddressConversion service
247 @return
248 <TRUE/> if any only if the conversion was successful
250 @see css::table::CellAddressConversion
251 @see css::table::CellRangeAddressConversion
253 bool doConvertAddressRepresentations(
254 const OUString& _rInputProperty,
255 const css::uno::Any& _rInputValue,
256 const OUString& _rOutputProperty,
257 css::uno::Any& _rOutputValue,
258 bool _bIsRange
259 ) const;
262 } // namespace xmloff
264 #endif // INCLUDED_XMLOFF_SOURCE_FORMS_FORMCELLBINDING_HXX
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */