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 FORMS_ENTRYLISTHELPER_HXX
29 #define FORMS_ENTRYLISTHELPER_HXX
30 
31 /** === begin UNO includes === **/
32 #include <com/sun/star/form/binding/XListEntrySink.hpp>
33 #include <com/sun/star/util/XRefreshable.hpp>
34 #include <com/sun/star/form/binding/XListEntryListener.hpp>
35 #include <com/sun/star/lang/IllegalArgumentException.hpp>
36 /** === end UNO includes === **/
37 
38 #include <cppuhelper/implbase3.hxx>
39 #include <cppuhelper/interfacecontainer.hxx>
40 
41 //.........................................................................
42 namespace frm
43 {
44 //.........................................................................
45 
46     class OControlModel;
47     class ControlModelLock;
48 
49     //=====================================================================
50     //= OEntryListHelper
51     //=====================================================================
52     typedef ::cppu::ImplHelper3 <      ::com::sun::star::form::binding::XListEntrySink
53                                 ,   ::com::sun::star::form::binding::XListEntryListener
54                                 ,   ::com::sun::star::util::XRefreshable
55 							    >	OEntryListHelper_BASE;
56 
57     class OEntryListHelper : public OEntryListHelper_BASE
58     {
59     private:
60         OControlModel&  m_rControlModel;
61 
62         ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >
63                         m_xListSource;      /// our external list source
64         ::com::sun::star::uno::Sequence< ::rtl::OUString >
65                         m_aStringItems;     /// "overridden" StringItemList property value
66         ::cppu::OInterfaceContainerHelper
67                         m_aRefreshListeners;
68 
69 
70     protected:
71         OEntryListHelper( OControlModel& _rControlModel );
72         OEntryListHelper( const OEntryListHelper& _rSource, OControlModel& _rControlModel );
73         virtual ~OEntryListHelper( );
74 
75         /// returns the current string item list
76         inline const ::com::sun::star::uno::Sequence< ::rtl::OUString >&
77                     getStringItemList() const { return m_aStringItems; }
78         inline const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >&
79                     getExternalListEntrySource() const { return m_xListSource; }
80 
81         /// determines whether we actually have an external list source
82         inline bool hasExternalListSource( ) const { return m_xListSource.is(); }
83 
84         /** handling the XEventListener::disposing call for the case where
85             our list source is being disposed
86             @return
87                 <TRUE/> if and only if the disposed object was our list source, and so the
88                 event was handled
89         */
90         bool        handleDisposing( const ::com::sun::star::lang::EventObject& _rEvent );
91 
92         /** to be called by derived classes' instances when they're being disposed
93         */
94         void        disposing( );
95 
96         // prevent method hiding
97         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException) = 0;
98 
99         /** helper for implementing convertFastPropertyValue( StringItemList )
100 
101             <p>The signature of this method and the return type have the same semantics
102             as convertFastPropertyValue.</p>
103         */
104         sal_Bool    convertNewListSourceProperty(
105                         ::com::sun::star::uno::Any& _rConvertedValue,
106                         ::com::sun::star::uno::Any& _rOldValue,
107                         const ::com::sun::star::uno::Any& _rValue
108                     )
109                     SAL_THROW( ( ::com::sun::star::lang::IllegalArgumentException ) );
110 
111         /** helper for implementing setFastPropertyValueNoBroadcast
112 
113             <p>Will internally call stringItemListChanged after the new item list
114             has been set.</p>
115 
116             @precond
117                 not to be called when we have an external list source
118             @see hasExternalListSource
119         */
120         void        setNewStringItemList( const ::com::sun::star::uno::Any& _rValue, ControlModelLock& _rInstanceLock );
121 
122         /** announces that the list of entries has changed.
123 
124             <p>Derived classes have to override this. Most probably, they'll set the new
125             as model property.</p>
126 
127             @pure
128             @see getStringItemList
129         */
130         virtual void    stringItemListChanged( ControlModelLock& _rInstanceLock ) = 0;
131 
132         /** called whenever a connection to a new external list source has been established
133         */
134         virtual void    connectedExternalListSource( );
135 
136         /** called whenever a connection to a new external list source has been revoked
137         */
138         virtual void    disconnectedExternalListSource( );
139 
140         /** called when XRefreshable::refresh has been called, and we do *not* have an external
141             list source
142         */
143         virtual void    refreshInternalEntryList() = 0;
144 
145     private:
146         // XListEntrySink
147         virtual void SAL_CALL setListEntrySource( const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource ) throw (::com::sun::star::uno::RuntimeException);
148         virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource > SAL_CALL getListEntrySource(  ) throw (::com::sun::star::uno::RuntimeException);
149 
150         // XListEntryListener
151         virtual void SAL_CALL entryChanged( const ::com::sun::star::form::binding::ListEntryEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
152         virtual void SAL_CALL entryRangeInserted( const ::com::sun::star::form::binding::ListEntryEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
153         virtual void SAL_CALL entryRangeRemoved( const ::com::sun::star::form::binding::ListEntryEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
154         virtual void SAL_CALL allEntriesChanged( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException);
155 
156         // XRefreshable
157         virtual void SAL_CALL refresh() throw(::com::sun::star::uno::RuntimeException);
158         virtual void SAL_CALL addRefreshListener(const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
159         virtual void SAL_CALL removeRefreshListener(const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
160 
161     private:
162         /** disconnects from the active external list source, if present
163             @see connectExternalListSource
164         */
165         void        disconnectExternalListSource( );
166 
167         /** connects to a new external list source
168             @param _rxSource
169                 the new list source. Must not be <NULL/>
170             @see disconnectExternalListSource
171         */
172         void        connectExternalListSource(
173                         const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource,
174                         ControlModelLock& _rInstanceLock
175                     );
176 
177         /** refreshes our list entries
178 
179             In case we have an external list source, its used to obtain the new entries, and then
180             stringItemListChanged is called to give the derived class the possibility to
181             react on this.
182 
183             In case we do not have an external list source, refreshInternalEntryList is called.
184         */
185         void        impl_lock_refreshList( ControlModelLock& _rInstanceLock );
186 
187     private:
188         OEntryListHelper();                                     // never implemented
189         OEntryListHelper( const OEntryListHelper& );            // never implemented
190         OEntryListHelper& operator=( const OEntryListHelper& ); // never implemented
191     };
192 
193 //.........................................................................
194 }   // namespace frm
195 //.........................................................................
196 
197 
198 #endif // FORMS_ENTRYLISTHELPER_HXX
199