1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_CELLBINDINGHELPER_HXX
#define INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_CELLBINDINGHELPER_HXX
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/table/CellAddress.hpp>
#include <com/sun/star/table/CellRangeAddress.hpp>
#include <com/sun/star/form/binding/XValueBinding.hpp>
#include <com/sun/star/form/binding/XListEntrySource.hpp>
#include <com/sun/star/sheet/XSpreadsheet.hpp>
namespace pcr
{
/** encapsulates functionality related to binding a form control to a spreadsheet cell
*/
class CellBindingHelper final
{
css::uno::Reference< css::beans::XPropertySet >
m_xControlModel; // the model we work for
css::uno::Reference< css::sheet::XSpreadsheetDocument >
m_xDocument; // the document where the model lives
public:
/** ctor
@param _rxControlModel
the control model which is or will be bound
*/
CellBindingHelper(
const css::uno::Reference< css::beans::XPropertySet >& _rxControlModel,
const css::uno::Reference< css::frame::XModel >& _rxContextDocument
);
/** determines whether the given model is a spreadsheet document model
<p>If this method returns <FALSE/>, you cannot instantiate a CellBindingHelper with
the document, since then no of its functionality will be available.</p>
*/
static bool isSpreadsheetDocument(
const css::uno::Reference< css::frame::XModel >& _rxContextDocument
);
/** gets a cell binding for the given address
@precond
isCellBindingAllowed returns <TRUE/>
*/
css::uno::Reference< css::form::binding::XValueBinding >
createCellBindingFromStringAddress(
const OUString& _rAddress,
bool _bSupportIntegerExchange
) const;
/** creates a cell binding (supporting integer exchange, if requested) for
the given address object
*/
css::uno::Reference< css::form::binding::XValueBinding >
createCellBindingFromAddress(
const css::table::CellAddress& _rAddress,
bool _bSupportIntegerExchange
) const;
/** gets a cell range list source binding for the given address
*/
css::uno::Reference< css::form::binding::XListEntrySource >
createCellListSourceFromStringAddress( const OUString& _rAddress ) const;
/** creates a string representation for the given value binding's address
<p>If the sheet of the bound cell is the same as the sheet which our control belongs
to, then the sheet name is omitted in the resulting string representation.</p>
@precond
The binding is a valid cell binding, or <NULL/>
@see isCellBinding
*/
OUString getStringAddressFromCellBinding(
const css::uno::Reference< css::form::binding::XValueBinding >& _rxBinding
) const;
/** creates an address object for the given value binding's address
@precond
The binding is a valid cell binding, or <NULL/>
@return
<FALSE/> if and only if an error occurred and no valid address could be obtained
@see isCellBinding
*/
bool getAddressFromCellBinding(
const css::uno::Reference< css::form::binding::XValueBinding >& _rxBinding,
css::table::CellAddress& _rAddress
) const;
/** creates a string representation for the given list source's range address
<p>If the sheet of the cell range which acts as list source is the same as the
sheet which our control belongs to, then the sheet name is omitted in the
resulting string representation.</p>
@precond
The object is a valid cell range list source, or <NULL/>
@see isCellRangeListSource
*/
OUString getStringAddressFromCellListSource(
const css::uno::Reference< css::form::binding::XListEntrySource >& _rxSource
) const;
/** returns the current binding of our control model, if any.
*/
css::uno::Reference< css::form::binding::XValueBinding >
getCurrentBinding( ) const;
/** returns the current external list source of the control model, if any
*/
css::uno::Reference< css::form::binding::XListEntrySource >
getCurrentListSource( ) const;
/** sets a new binding for our control model
@precond
the control model is bindable (which is implied by <member>isCellBindingAllowed</member>
returning <TRUE/>)
*/
void setBinding(
const css::uno::Reference< css::form::binding::XValueBinding >& _rxBinding
);
/** sets a list source for our control model
@precond
the control model is a list sink (which is implied by <member>isListCellRangeAllowed</member>
returning <TRUE/>)
*/
void setListSource(
const css::uno::Reference< css::form::binding::XListEntrySource >& _rxSource
);
/** checks whether it's possible to bind the control model to a spreadsheet cell
*/
bool isCellBindingAllowed( ) const;
/** checks whether it's possible to bind the control model to a spreadsheet cell,
with exchanging integer values
*/
bool isCellIntegerBindingAllowed( ) const;
/** checks whether it's possible to bind the control model to range of spreadsheet cells
supplying the list entries
*/
bool isListCellRangeAllowed( ) const;
/** checks whether a given binding is a spreadsheet cell binding
*/
static bool isCellBinding(
const css::uno::Reference< css::form::binding::XValueBinding >& _rxBinding
);
/** checks whether a given binding is a spreadsheet cell binding, exchanging
integer values
*/
static bool isCellIntegerBinding(
const css::uno::Reference< css::form::binding::XValueBinding >& _rxBinding
);
/** checks whether a given list source is a spreadsheet cell list source
*/
static bool isCellRangeListSource(
const css::uno::Reference< css::form::binding::XListEntrySource >& _rxSource
);
/** retrieves the index of the sheet which our control belongs to
@return the index of the sheet which our control belongs to or -1, if an error occurred
*/
sal_Int16 getControlSheetIndex(
css::uno::Reference< css::sheet::XSpreadsheet >& _out_rxSheet
) const;
private:
/** creates an address object from a string representation of a cell address
*/
bool convertStringAddress(
const OUString& _rAddressDescription,
css::table::CellAddress& /* [out] */ _rAddress
) const;
/** creates an address range object from a string representation of a cell range address
*/
bool convertStringAddress(
const OUString& _rAddressDescription,
css::table::CellRangeAddress& /* [out] */ _rAddress
) const;
/** determines if our document is a spreadsheet document, *and* can supply
the given service
*/
bool isSpreadsheetDocumentWhichSupplies( const OUString& _rService ) const;
/** checks whether a given component supports a given service
*/
static bool doesComponentSupport(
const css::uno::Reference< css::uno::XInterface >& _rxComponent,
const OUString& _rService
);
/** uses the document (it's factory interface, respectively) to create a component instance
@param _rService
the service name
@param _rArgumentName
the name of the single argument to pass during creation. May be empty, in this case
no arguments are passed
@param _rArgumentValue
the value of the instantiation argument. Not evaluated if <arg>_rArgumentName</arg>
is empty.
*/
css::uno::Reference< css::uno::XInterface >
createDocumentDependentInstance(
const OUString& _rService,
const OUString& _rArgumentName,
const css::uno::Any& _rArgumentValue
) const;
/** converts an address representation into another one
@param _rInputProperty
the input property name for the conversion service
@param _rInputValue
the input property value for the conversion service
@param _rOutputProperty
the output property name for the conversion service
@param _rOutputValue
the output property value for the conversion service
@param _bIsRange
if <TRUE/>, the RangeAddressConversion service will be used, else
the AddressConversion service
@return
<TRUE/> if any only if the conversion was successful
@see css::table::CellAddressConversion
@see css::table::CellRangeAddressConversion
*/
bool doConvertAddressRepresentations(
const OUString& _rInputProperty,
const css::uno::Any& _rInputValue,
const OUString& _rOutputProperty,
css::uno::Any& _rOutputValue,
bool _bIsRange
) const;
};
} // namespace pcr
#endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_CELLBINDINGHELPER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|