bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / forms / formcellbinding.hxx
blob5abffefaefcd06ac75d200139d07fb1adc795bc6
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 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
42 m_xControlModel; // the model we work for
43 ::com::sun::star::uno::Reference< ::com::sun::star::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 it's functionality will be available.</p>
51 static bool livesInSpreadsheetDocument(
52 const ::com::sun::star::uno::Reference< ::com::sun::star::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 walkong 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 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControlModel,
66 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxDocument
69 public:
70 /** gets a cell binding for the given address
71 @precond
72 isCellBindingAllowed returns <TRUE/>
74 ::com::sun::star::uno::Reference< ::com::sun::star::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 ::com::sun::star::uno::Reference< ::com::sun::star::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 ::com::sun::star::uno::Reference< ::com::sun::star::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 ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource
110 ) const;
112 /** returns the current binding of our control model, if any.
114 ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >
115 getCurrentBinding( ) const;
117 /** returns the current external list source of the control model, if any
119 ::com::sun::star::uno::Reference< ::com::sun::star::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 ::com::sun::star::uno::Reference< ::com::sun::star::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 ::com::sun::star::uno::Reference< ::com::sun::star::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 ::com::sun::star::uno::Reference< ::com::sun::star::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 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxDocument
162 /** checks whether a given binding is a spreadsheet cell binding
164 static bool isCellBinding(
165 const ::com::sun::star::uno::Reference< ::com::sun::star::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 ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding
175 /** checks whether a given list source is a spreadsheet cell list source
177 static bool isCellRangeListSource(
178 const ::com::sun::star::uno::Reference< ::com::sun::star::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 ::com::sun::star::table::CellAddress& /* [out] */ _rAddress,
187 sal_Int16 _nAssumeSheet = -1
188 ) const;
190 /** creates an address range object from a string representation of a cell range address
192 bool convertStringAddress(
193 const OUString& _rAddressDescription,
194 ::com::sun::star::table::CellRangeAddress& /* [out] */ _rAddress
195 ) const;
197 /** determines if our document is a spreadsheet document, *and* can supply
198 the given service
200 bool isSpreadsheetDocumentWhichSupplies( const OUString& _rService ) const;
202 /** determines if our document is a spreadsheet document, *and* can supply
203 the given service
205 static bool isSpreadsheetDocumentWhichSupplies(
206 const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >& _rxDocument,
207 const OUString& _rService
210 /** checkes whether a given component supports a given servive
212 static bool doesComponentSupport(
213 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent,
214 const OUString& _rService
217 /** uses the document (it's factory interface, respectively) to create a component instance
218 @param _rService
219 the service name
220 @param _rArgumentName
221 the name of the single argument to pass during creation. May be empty, in this case
222 no arguments are passed
223 @param _rArgumentValue
224 the value of the instantiation argument. Not evaluated if <arg>_rArgumentName</arg>
225 is empty.
227 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
228 createDocumentDependentInstance(
229 const OUString& _rService,
230 const OUString& _rArgumentName,
231 const ::com::sun::star::uno::Any& _rArgumentValue
232 ) const;
234 /** converts an address representation into another one
236 @param _rInputProperty
237 the input property name for the conversion service
238 @param _rInputValue
239 the input property value for the conversion service
240 @param _rOutputProperty
241 the output property name for the conversion service
242 @param _rOutputValue
243 the output property value for the conversion service
244 @param _bIsRange
245 if <TRUE/>, the RangeAddressConversion service will be used, else
246 the AddressConversion service
248 @return
249 <TRUE/> if any only if the conversion was successful
251 @see com::sun::star::table::CellAddressConversion
252 @see com::sun::star::table::CellRangeAddressConversion
254 bool doConvertAddressRepresentations(
255 const OUString& _rInputProperty,
256 const ::com::sun::star::uno::Any& _rInputValue,
257 const OUString& _rOutputProperty,
258 ::com::sun::star::uno::Any& _rOutputValue,
259 bool _bIsRange
260 ) const;
263 } // namespace xmloff
265 #endif // INCLUDED_XMLOFF_SOURCE_FORMS_FORMCELLBINDING_HXX
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */