1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_CELLVALUEBINDING_HXX
29 #define SC_CELLVALUEBINDING_HXX
30 
31 #include <com/sun/star/form/binding/XValueBinding.hpp>
32 #include <com/sun/star/util/XModifyBroadcaster.hpp>
33 #include <cppuhelper/compbase5.hxx>
34 #include <comphelper/propertycontainer.hxx>
35 #include <comphelper/uno3.hxx>
36 #include <comphelper/broadcasthelper.hxx>
37 #include <comphelper/proparrhlp.hxx>
38 #include <com/sun/star/table/XCell.hpp>
39 #include <com/sun/star/table/CellAddress.hpp>
40 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
41 #include <com/sun/star/text/XTextRange.hpp>
42 #include <com/sun/star/lang/DisposedException.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <com/sun/star/lang/XInitialization.hpp>
45 
46 
47 //.........................................................................
48 namespace calc
49 {
50 //.........................................................................
51 
52     //=====================================================================
53     //= OCellValueBinding
54     //=====================================================================
55     class OCellValueBinding;
56     // the base for our interfaces
57     typedef ::cppu::WeakAggComponentImplHelper5 <   ::com::sun::star::form::binding::XValueBinding
58                                                 ,   ::com::sun::star::lang::XServiceInfo
59                                                 ,   ::com::sun::star::util::XModifyBroadcaster
60                                                 ,   ::com::sun::star::util::XModifyListener
61                                                 ,   ::com::sun::star::lang::XInitialization
62                                                 >   OCellValueBinding_Base;
63     // the base for the property handling
64     typedef ::comphelper::OPropertyContainer        OCellValueBinding_PBase;
65     // the second base for property handling
66     typedef ::comphelper::OPropertyArrayUsageHelper< OCellValueBinding >
67                                                     OCellValueBinding_PABase;
68 
69     class OCellValueBinding :public ::comphelper::OBaseMutex
70                             ,public OCellValueBinding_Base      // order matters! before OCellValueBinding_PBase, so rBHelper gets initialized
71                             ,public OCellValueBinding_PBase
72 					        ,public OCellValueBinding_PABase
73     {
74     private:
75         ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >
76                     m_xDocument;            /// the document where our cell lives
77         ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >
78                     m_xCell;                /// the cell we're bound to, for double value access
79         ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange >
80                     m_xCellText;            /// the cell we're bound to, for text access
81     	::cppu::OInterfaceContainerHelper
82                     m_aModifyListeners;     /// our modify listeners
83         sal_Bool    m_bInitialized;         /// has XInitialization::initialize been called?
84         sal_Bool    m_bListPos;             /// constructed as ListPositionCellBinding?
85 
86     public:
87         OCellValueBinding(
88             const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >& _rxDocument,
89             sal_Bool _bListPos
90         );
91 
92         using OCellValueBinding_PBase::getFastPropertyValue;
93 
94     protected:
95         ~OCellValueBinding( );
96 
97     protected:
98         // XInterface
99         DECLARE_XINTERFACE()
100 
101         // XTypeProvider
102         DECLARE_XTYPEPROVIDER()
103 
104         // XValueBinding
105         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getSupportedValueTypes(  ) throw (::com::sun::star::uno::RuntimeException);
106         virtual sal_Bool SAL_CALL supportsType( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException);
107         virtual ::com::sun::star::uno::Any SAL_CALL getValue( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::form::binding::IncompatibleTypesException, ::com::sun::star::uno::RuntimeException);
108         virtual void SAL_CALL setValue( const ::com::sun::star::uno::Any& aValue ) throw (::com::sun::star::form::binding::IncompatibleTypesException, ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
109 
110         // OComponentHelper/XComponent
111         virtual void SAL_CALL disposing();
112 
113         // XServiceInfo
114         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
115         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
116         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
117 
118         // XPropertySet
119         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
120 
121         // OPropertySetHelper
122         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
123 	    virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& _rValue, sal_Int32 _nHandle ) const;
124 
125         // ::comphelper::OPropertyArrayUsageHelper
126 		virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
127 
128         // XModifyBroadcaster
129         virtual void SAL_CALL addModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
130         virtual void SAL_CALL removeModifyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) throw (::com::sun::star::uno::RuntimeException);
131 
132         // XModifyListener
133         virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
134         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
135 
136         // XInitialization
137         virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
138 
139     private:
140         void    checkDisposed( ) const
141                     SAL_THROW( ( ::com::sun::star::lang::DisposedException ) );
142         void    checkValueType( const ::com::sun::star::uno::Type& _rType ) const
143                     SAL_THROW( ( ::com::sun::star::form::binding::IncompatibleTypesException ) );
144         void    checkInitialized()
145                     SAL_THROW( ( ::com::sun::star::uno::RuntimeException ) );
146 
147         /** notifies our modify listeners
148             @precond
149                 our mutex is <em>not</em> locked
150         */
151         void    notifyModified();
152 
153         void    setBooleanFormat();
154 
155     private:
156         OCellValueBinding();                                        // never implemented
157         OCellValueBinding( const OCellValueBinding& );              // never implemented
158         OCellValueBinding& operator=( const OCellValueBinding& );   // never implemented
159 
160 #ifdef DBG_UTIL
161     private:
162         static  const char* checkConsistency_static( const void* _pThis );
163                 const char* checkConsistency( ) const;
164 #endif
165     };
166 
167 //.........................................................................
168 }   // namespace calc
169 //.........................................................................
170 
171 #endif // SC_CELLVALUEBINDING_HXX
172