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