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