bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / propctrlr / cellbindinghelper.hxx
blobe0224aa9ed273ff2e5b52ce134c4600096104d67
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_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>
34 namespace pcr
37 /** encapsulates functionality related to binding a form control to a spreadsheet cell
39 class CellBindingHelper
41 protected:
42 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
43 m_xControlModel; // the model we work for
44 ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >
45 m_xDocument; // the document where the model lives
47 public:
48 /** ctor
49 @param _rxControlModel
50 the control model which is or will be bound
52 CellBindingHelper(
53 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControlModel,
54 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxContextDocument
57 public:
58 /** determines whether the given model is a spreadsheet document model
60 <p>If this method returns <FALSE/>, you cannot instantiate a CellBindingHelper with
61 the document, since then no of it's functionality will be available.</p>
63 static bool isSpreadsheetDocument(
64 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxContextDocument
67 /** gets a cell binding for the given address
68 @precond
69 isCellBindingAllowed returns <TRUE/>
71 ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >
72 createCellBindingFromStringAddress(
73 const OUString& _rAddress,
74 bool _bSupportIntegerExchange = false
75 ) const;
77 /** creates a cell binding (supporting integer exchange, if requested) for
78 the given address object
80 ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >
81 createCellBindingFromAddress(
82 const ::com::sun::star::table::CellAddress& _rAddress,
83 bool _bSupportIntegerExchange = false
84 ) const;
86 /** gets a cell range list source binding for the given address
88 ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >
89 createCellListSourceFromStringAddress( const OUString& _rAddress ) const;
91 /** creates a string representation for the given value binding's address
93 <p>If the sheet of the bound cell is the same as the sheet which our control belongs
94 to, then the sheet name is omitted in the resulting string representation.</p>
96 @precond
97 The binding is a valid cell binding, or <NULL/>
98 @see isCellBinding
100 OUString getStringAddressFromCellBinding(
101 const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding
102 ) const;
104 /** creates an address object for the given value binding's address
106 @precond
107 The binding is a valid cell binding, or <NULL/>
108 @return
109 <FALSE/> if and only if an error occurred and no valid address could be obtained
110 @see isCellBinding
112 bool getAddressFromCellBinding(
113 const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding,
114 ::com::sun::star::table::CellAddress& _rAddress
115 ) const;
117 /** creates a string representation for the given list source's range address
119 <p>If the sheet of the cell range which acts as list source is the same as the
120 sheet which our control belongs to, then the sheet name is omitted in the
121 resulting string representation.</p>
123 @precond
124 The object is a valid cell range list source, or <NULL/>
125 @see isCellRangeListSource
127 OUString getStringAddressFromCellListSource(
128 const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource
129 ) const;
131 /** returns the current binding of our control model, if any.
133 ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >
134 getCurrentBinding( ) const;
136 /** returns the current external list source of the control model, if any
138 ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >
139 getCurrentListSource( ) const;
141 /** sets a new binding for our control model
142 @precond
143 the control model is bindable (which is implied by <member>isCellBindingAllowed</member>
144 returning <TRUE/>)
146 void setBinding(
147 const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding
150 /** sets a list source for our control model
151 @precond
152 the control model is a list sink (which is implied by <member>isListCellRangeAllowed</member>
153 returning <TRUE/>)
155 void setListSource(
156 const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource
159 /** checks whether it's possible to bind the control model to a spreadsheet cell
161 bool isCellBindingAllowed( ) const;
163 /** checks whether it's possible to bind the control model to a spreadsheet cell,
164 with exchanging integer values
166 bool isCellIntegerBindingAllowed( ) const;
168 /** checks whether it's possible to bind the control model to range of spreadsheet cells
169 supplying the list entries
171 bool isListCellRangeAllowed( ) const;
173 /** checks whether a given binding is a spreadsheet cell binding
175 static bool isCellBinding(
176 const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding
179 /** checks whether a given binding is a spreadsheet cell binding, exchanging
180 integer values
182 static bool isCellIntegerBinding(
183 const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding
186 /** checks whether a given list source is a spreadsheet cell list source
188 static bool isCellRangeListSource(
189 const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource
192 /** retrieves the index of the sheet which our control belongs to
193 @return the index of the sheet which our control belongs to or -1, if an error occurred
195 sal_Int16 getControlSheetIndex(
196 ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >& _out_rxSheet
197 ) const;
199 protected:
200 /** creates an address object from a string representation of a cell address
202 bool convertStringAddress(
203 const OUString& _rAddressDescription,
204 ::com::sun::star::table::CellAddress& /* [out] */ _rAddress
205 ) const;
207 /** creates an address range object from a string representation of a cell range address
209 bool convertStringAddress(
210 const OUString& _rAddressDescription,
211 ::com::sun::star::table::CellRangeAddress& /* [out] */ _rAddress
212 ) const;
214 /** determines if our document is a spreadsheet document, *and* can supply
215 the given service
217 bool isSpreadsheetDocumentWhichSupplies( const OUString& _rService ) const;
219 /** checkes whether a given component supports a given servive
221 static bool doesComponentSupport(
222 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent,
223 const OUString& _rService
226 /** uses the document (it's factory interface, respectively) to create a component instance
227 @param _rService
228 the service name
229 @param _rArgumentName
230 the name of the single argument to pass during creation. May be empty, in this case
231 no arguments are passed
232 @param _rArgumentValue
233 the value of the instantiation argument. Not evaluated if <arg>_rArgumentName</arg>
234 is empty.
236 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
237 createDocumentDependentInstance(
238 const OUString& _rService,
239 const OUString& _rArgumentName,
240 const ::com::sun::star::uno::Any& _rArgumentValue
241 ) const;
243 /** converts an address representation into another one
245 @param _rInputProperty
246 the input property name for the conversion service
247 @param _rInputValue
248 the input property value for the conversion service
249 @param _rOutputProperty
250 the output property name for the conversion service
251 @param _rOutputValue
252 the output property value for the conversion service
253 @param _bIsRange
254 if <TRUE/>, the RangeAddressConversion service will be used, else
255 the AddressConversion service
257 @return
258 <TRUE/> if any only if the conversion was successful
260 @see com::sun::star::table::CellAddressConversion
261 @see com::sun::star::table::CellRangeAddressConversion
263 bool doConvertAddressRepresentations(
264 const OUString& _rInputProperty,
265 const ::com::sun::star::uno::Any& _rInputValue,
266 const OUString& _rOutputProperty,
267 ::com::sun::star::uno::Any& _rOutputValue,
268 bool _bIsRange
269 ) const;
273 } // namespace pcr
276 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_CELLBINDINGHELPER_HXX
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */