xref: /AOO41X/main/xmloff/source/forms/formcellbinding.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef XMLOFF_FORMS_FORMCELLBINDING
29*cdf0e10cSrcweir #define XMLOFF_FORMS_FORMCELLBINDING
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/table/CellAddress.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/table/CellRangeAddress.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/form/binding/XValueBinding.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/form/binding/XListEntrySource.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir //............................................................................
41*cdf0e10cSrcweir namespace xmloff
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir //............................................................................
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir     //========================================================================
46*cdf0e10cSrcweir     //= FormCellBindingHelper
47*cdf0e10cSrcweir     //========================================================================
48*cdf0e10cSrcweir     /** encapsulates functionality related to binding a form control to a spreadsheet cell
49*cdf0e10cSrcweir     */
50*cdf0e10cSrcweir     class FormCellBindingHelper
51*cdf0e10cSrcweir     {
52*cdf0e10cSrcweir     protected:
53*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
54*cdf0e10cSrcweir                     m_xControlModel;    // the model we work for
55*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >
56*cdf0e10cSrcweir                     m_xDocument;        // the document where the model lives
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir     public:
59*cdf0e10cSrcweir         /** determines whether the given control model lives in a spreadsheet document
60*cdf0e10cSrcweir             <p>If this method returns <FALSE/>, you cannot instantiate a CellBindingHelper with
61*cdf0e10cSrcweir             this model, since then no of it's functionality will be available.</p>
62*cdf0e10cSrcweir         */
63*cdf0e10cSrcweir         static  sal_Bool    livesInSpreadsheetDocument(
64*cdf0e10cSrcweir                                 const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControlModel
65*cdf0e10cSrcweir                             );
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir         /** ctor
68*cdf0e10cSrcweir             @param _rxControlModel
69*cdf0e10cSrcweir                 the control model which is or will be bound
70*cdf0e10cSrcweir             @param _rxDocument
71*cdf0e10cSrcweir                 the document. If this is <NULL/>, the document will be obtained from the model
72*cdf0e10cSrcweir                 itself by walkong up the chain of its ancestors.<br/>
73*cdf0e10cSrcweir                 This parameter can be used if the control model is not (yet) part of a document
74*cdf0e10cSrcweir                 model.
75*cdf0e10cSrcweir         */
76*cdf0e10cSrcweir         FormCellBindingHelper(
77*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxControlModel,
78*cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxDocument
79*cdf0e10cSrcweir         );
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     public:
82*cdf0e10cSrcweir         /** gets a cell binding for the given address
83*cdf0e10cSrcweir             @precond
84*cdf0e10cSrcweir                 isCellBindingAllowed returns <TRUE/>
85*cdf0e10cSrcweir         */
86*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >
87*cdf0e10cSrcweir                         createCellBindingFromStringAddress(
88*cdf0e10cSrcweir                             const ::rtl::OUString& _rAddress,
89*cdf0e10cSrcweir                             bool _bUseIntegerBinding
90*cdf0e10cSrcweir                         ) const;
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir         /** gets a cell range list source binding for the given address
93*cdf0e10cSrcweir         */
94*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >
95*cdf0e10cSrcweir                         createCellListSourceFromStringAddress( const ::rtl::OUString& _rAddress ) const;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir         /** creates a string representation for the given value binding's address
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir             <p>If the sheet of the bound cell is the same as the sheet which our control belongs
100*cdf0e10cSrcweir             to, then the sheet name is omitted in the resulting string representation.</p>
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir             @precond
103*cdf0e10cSrcweir                 The binding is a valid cell binding, or <NULL/>
104*cdf0e10cSrcweir             @see isCellBinding
105*cdf0e10cSrcweir         */
106*cdf0e10cSrcweir         ::rtl::OUString getStringAddressFromCellBinding(
107*cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding
108*cdf0e10cSrcweir                         ) const;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         /** creates a string representation for the given list source's range address
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir             <p>If the sheet of the cell range which acts as list source is the same as the
113*cdf0e10cSrcweir             sheet which our control belongs to, then the sheet name is omitted in the
114*cdf0e10cSrcweir             resulting string representation.</p>
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir             @precond
117*cdf0e10cSrcweir                 The object is a valid cell range list source, or <NULL/>
118*cdf0e10cSrcweir             @see isCellRangeListSource
119*cdf0e10cSrcweir         */
120*cdf0e10cSrcweir         ::rtl::OUString getStringAddressFromCellListSource(
121*cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource
122*cdf0e10cSrcweir                         ) const;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir         /** returns the current binding of our control model, if any.
125*cdf0e10cSrcweir         */
126*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >
127*cdf0e10cSrcweir                         getCurrentBinding( ) const;
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir         /** returns the current external list source of the control model, if any
130*cdf0e10cSrcweir         */
131*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >
132*cdf0e10cSrcweir                         getCurrentListSource( ) const;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir         /** sets a new binding for our control model
135*cdf0e10cSrcweir             @precond
136*cdf0e10cSrcweir                 the control model is bindable (which is implied by <member>isCellBindingAllowed</member>
137*cdf0e10cSrcweir                 returning <TRUE/>)
138*cdf0e10cSrcweir         */
139*cdf0e10cSrcweir         void            setBinding(
140*cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding
141*cdf0e10cSrcweir                         );
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir         /** sets a list source for our control model
144*cdf0e10cSrcweir             @precond
145*cdf0e10cSrcweir                 the control model is a list sink (which is implied by <member>isListCellRangeAllowed</member>
146*cdf0e10cSrcweir                 returning <TRUE/>)
147*cdf0e10cSrcweir         */
148*cdf0e10cSrcweir         void            setListSource(
149*cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource
150*cdf0e10cSrcweir                         );
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir         /** checks whether it's possible to bind the control model to a spreadsheet cell
153*cdf0e10cSrcweir         */
154*cdf0e10cSrcweir         bool            isCellBindingAllowed( ) const;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir         /** checks whether within the given document, it's possible to bind control models to spreadsheet cells
157*cdf0e10cSrcweir         */
158*cdf0e10cSrcweir         static bool     isCellBindingAllowed(
159*cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxDocument
160*cdf0e10cSrcweir                         );
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir         /** checks whether it's possible to bind the control model to a range of spreadsheet cells
163*cdf0e10cSrcweir             supplying the list entries
164*cdf0e10cSrcweir         */
165*cdf0e10cSrcweir         bool            isListCellRangeAllowed( ) const;
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir         /** checks whether within the given document, it's possible to bind the control model to a range of
168*cdf0e10cSrcweir             spreadsheet cells supplying the list entries
169*cdf0e10cSrcweir         */
170*cdf0e10cSrcweir         static bool     isListCellRangeAllowed(
171*cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxDocument
172*cdf0e10cSrcweir                         );
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir         /** checks whether a given binding is a spreadsheet cell binding
175*cdf0e10cSrcweir         */
176*cdf0e10cSrcweir         bool            isCellBinding(
177*cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding
178*cdf0e10cSrcweir                         ) const;
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir         /** checks whether a given binding is a spreadsheet cell binding, exchanging
181*cdf0e10cSrcweir             integer values
182*cdf0e10cSrcweir         */
183*cdf0e10cSrcweir         bool            isCellIntegerBinding(
184*cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XValueBinding >& _rxBinding
185*cdf0e10cSrcweir                         ) const;
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir         /** checks whether a given list source is a spreadsheet cell list source
188*cdf0e10cSrcweir         */
189*cdf0e10cSrcweir         bool            isCellRangeListSource(
190*cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource
191*cdf0e10cSrcweir                         ) const;
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir     protected:
194*cdf0e10cSrcweir         /** creates an address object from a string representation of a cell address
195*cdf0e10cSrcweir         */
196*cdf0e10cSrcweir         bool            convertStringAddress(
197*cdf0e10cSrcweir                             const ::rtl::OUString& _rAddressDescription,
198*cdf0e10cSrcweir                             ::com::sun::star::table::CellAddress& /* [out] */ _rAddress,
199*cdf0e10cSrcweir                             sal_Int16 _nAssumeSheet = -1
200*cdf0e10cSrcweir                         ) const;
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir         /** creates an address range object from a string representation of a cell range address
203*cdf0e10cSrcweir         */
204*cdf0e10cSrcweir         bool            convertStringAddress(
205*cdf0e10cSrcweir                             const ::rtl::OUString& _rAddressDescription,
206*cdf0e10cSrcweir                             ::com::sun::star::table::CellRangeAddress& /* [out] */ _rAddress
207*cdf0e10cSrcweir                         ) const;
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir         /** determines if our document is a spreadsheet document, *and* can supply
210*cdf0e10cSrcweir             the given service
211*cdf0e10cSrcweir         */
212*cdf0e10cSrcweir         bool            isSpreadsheetDocumentWhichSupplies( const ::rtl::OUString& _rService ) const  SAL_THROW(());
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir         /** determines if our document is a spreadsheet document, *and* can supply
215*cdf0e10cSrcweir             the given service
216*cdf0e10cSrcweir         */
217*cdf0e10cSrcweir         static bool     isSpreadsheetDocumentWhichSupplies(
218*cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >& _rxDocument,
219*cdf0e10cSrcweir                             const ::rtl::OUString& _rService
220*cdf0e10cSrcweir                         ) SAL_THROW(());
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir         /** checkes whether a given component supports a given servive
223*cdf0e10cSrcweir         */
224*cdf0e10cSrcweir         bool            doesComponentSupport(
225*cdf0e10cSrcweir                             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent,
226*cdf0e10cSrcweir                             const ::rtl::OUString& _rService
227*cdf0e10cSrcweir                         ) const;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir         /** uses the document (it's factory interface, respectively) to create a component instance
230*cdf0e10cSrcweir             @param _rService
231*cdf0e10cSrcweir                 the service name
232*cdf0e10cSrcweir             @param _rArgumentName
233*cdf0e10cSrcweir                 the name of the single argument to pass during creation. May be empty, in this case
234*cdf0e10cSrcweir                 no arguments are passed
235*cdf0e10cSrcweir             @param _rArgumentValue
236*cdf0e10cSrcweir                 the value of the instantiation argument. Not evaluated if <arg>_rArgumentName</arg>
237*cdf0e10cSrcweir                 is empty.
238*cdf0e10cSrcweir         */
239*cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
240*cdf0e10cSrcweir                         createDocumentDependentInstance(
241*cdf0e10cSrcweir                             const ::rtl::OUString& _rService,
242*cdf0e10cSrcweir                             const ::rtl::OUString& _rArgumentName,
243*cdf0e10cSrcweir                             const ::com::sun::star::uno::Any& _rArgumentValue
244*cdf0e10cSrcweir                         ) const;
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir         /** converts an address representation into another one
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir             @param _rInputProperty
249*cdf0e10cSrcweir                 the input property name for the conversion service
250*cdf0e10cSrcweir             @param _rInputValue
251*cdf0e10cSrcweir                 the input property value for the conversion service
252*cdf0e10cSrcweir             @param _rOutputProperty
253*cdf0e10cSrcweir                 the output property name for the conversion service
254*cdf0e10cSrcweir             @param _rOutputValue
255*cdf0e10cSrcweir                 the output property value for the conversion service
256*cdf0e10cSrcweir             @param _bIsRange
257*cdf0e10cSrcweir                 if <TRUE/>, the RangeAddressConversion service will be used, else
258*cdf0e10cSrcweir                 the AddressConversion service
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir             @return
261*cdf0e10cSrcweir                 <TRUE/> if any only if the conversion was successfull
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir             @see com::sun::star::table::CellAddressConversion
264*cdf0e10cSrcweir             @see com::sun::star::table::CellRangeAddressConversion
265*cdf0e10cSrcweir         */
266*cdf0e10cSrcweir         bool            doConvertAddressRepresentations(
267*cdf0e10cSrcweir                             const ::rtl::OUString& _rInputProperty,
268*cdf0e10cSrcweir                             const ::com::sun::star::uno::Any& _rInputValue,
269*cdf0e10cSrcweir                             const ::rtl::OUString& _rOutputProperty,
270*cdf0e10cSrcweir                                   ::com::sun::star::uno::Any& _rOutputValue,
271*cdf0e10cSrcweir                             bool _bIsRange
272*cdf0e10cSrcweir                         ) const SAL_THROW(());
273*cdf0e10cSrcweir     };
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir //............................................................................
276*cdf0e10cSrcweir }   // namespace xmloff
277*cdf0e10cSrcweir //............................................................................
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir #endif // XMLOFF_FORMS_FORMCELLBINDING
280