1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef FORMS_ENTRYLISTHELPER_HXX
25 #define FORMS_ENTRYLISTHELPER_HXX
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/form/binding/XListEntrySink.hpp>
29 #include <com/sun/star/util/XRefreshable.hpp>
30 #include <com/sun/star/form/binding/XListEntryListener.hpp>
31 #include <com/sun/star/lang/IllegalArgumentException.hpp>
32 /** === end UNO includes === **/
33 
34 #include <cppuhelper/implbase3.hxx>
35 #include <cppuhelper/interfacecontainer.hxx>
36 
37 //.........................................................................
38 namespace frm
39 {
40 //.........................................................................
41 
42     class OControlModel;
43     class ControlModelLock;
44 
45     //=====================================================================
46     //= OEntryListHelper
47     //=====================================================================
48     typedef ::cppu::ImplHelper3 <      ::com::sun::star::form::binding::XListEntrySink
49                                 ,   ::com::sun::star::form::binding::XListEntryListener
50                                 ,   ::com::sun::star::util::XRefreshable
51 							    >	OEntryListHelper_BASE;
52 
53     class OEntryListHelper : public OEntryListHelper_BASE
54     {
55     private:
56         OControlModel&  m_rControlModel;
57 
58         ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >
59                         m_xListSource;      /// our external list source
60         ::com::sun::star::uno::Sequence< ::rtl::OUString >
61                         m_aStringItems;     /// "overridden" StringItemList property value
62         ::cppu::OInterfaceContainerHelper
63                         m_aRefreshListeners;
64 
65 
66     protected:
67         OEntryListHelper( OControlModel& _rControlModel );
68         OEntryListHelper( const OEntryListHelper& _rSource, OControlModel& _rControlModel );
69         virtual ~OEntryListHelper( );
70 
71         /// returns the current string item list
72         inline const ::com::sun::star::uno::Sequence< ::rtl::OUString >&
getStringItemList() const73                     getStringItemList() const { return m_aStringItems; }
74         inline const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >&
getExternalListEntrySource() const75                     getExternalListEntrySource() const { return m_xListSource; }
76 
77         /// determines whether we actually have an external list source
hasExternalListSource() const78         inline bool hasExternalListSource( ) const { return m_xListSource.is(); }
79 
80         /** handling the XEventListener::disposing call for the case where
81             our list source is being disposed
82             @return
83                 <TRUE/> if and only if the disposed object was our list source, and so the
84                 event was handled
85         */
86         bool        handleDisposing( const ::com::sun::star::lang::EventObject& _rEvent );
87 
88         /** to be called by derived classes' instances when they're being disposed
89         */
90         void        disposing( );
91 
92         // prevent method hiding
93         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException) = 0;
94 
95         /** helper for implementing convertFastPropertyValue( StringItemList )
96 
97             <p>The signature of this method and the return type have the same semantics
98             as convertFastPropertyValue.</p>
99         */
100         sal_Bool    convertNewListSourceProperty(
101                         ::com::sun::star::uno::Any& _rConvertedValue,
102                         ::com::sun::star::uno::Any& _rOldValue,
103                         const ::com::sun::star::uno::Any& _rValue
104                     )
105                     SAL_THROW( ( ::com::sun::star::lang::IllegalArgumentException ) );
106 
107         /** helper for implementing setFastPropertyValueNoBroadcast
108 
109             <p>Will internally call stringItemListChanged after the new item list
110             has been set.</p>
111 
112             @precond
113                 not to be called when we have an external list source
114             @see hasExternalListSource
115         */
116         void        setNewStringItemList( const ::com::sun::star::uno::Any& _rValue, ControlModelLock& _rInstanceLock );
117 
118         /** announces that the list of entries has changed.
119 
120             <p>Derived classes have to override this. Most probably, they'll set the new
121             as model property.</p>
122 
123             @pure
124             @see getStringItemList
125         */
126         virtual void    stringItemListChanged( ControlModelLock& _rInstanceLock ) = 0;
127 
128         /** called whenever a connection to a new external list source has been established
129         */
130         virtual void    connectedExternalListSource( );
131 
132         /** called whenever a connection to a new external list source has been revoked
133         */
134         virtual void    disconnectedExternalListSource( );
135 
136         /** called when XRefreshable::refresh has been called, and we do *not* have an external
137             list source
138         */
139         virtual void    refreshInternalEntryList() = 0;
140 
141     private:
142         // XListEntrySink
143         virtual void SAL_CALL setListEntrySource( const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource ) throw (::com::sun::star::uno::RuntimeException);
144         virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource > SAL_CALL getListEntrySource(  ) throw (::com::sun::star::uno::RuntimeException);
145 
146         // XListEntryListener
147         virtual void SAL_CALL entryChanged( const ::com::sun::star::form::binding::ListEntryEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
148         virtual void SAL_CALL entryRangeInserted( const ::com::sun::star::form::binding::ListEntryEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
149         virtual void SAL_CALL entryRangeRemoved( const ::com::sun::star::form::binding::ListEntryEvent& _rSource ) throw (::com::sun::star::uno::RuntimeException);
150         virtual void SAL_CALL allEntriesChanged( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException);
151 
152         // XRefreshable
153         virtual void SAL_CALL refresh() throw(::com::sun::star::uno::RuntimeException);
154         virtual void SAL_CALL addRefreshListener(const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
155         virtual void SAL_CALL removeRefreshListener(const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
156 
157     private:
158         /** disconnects from the active external list source, if present
159             @see connectExternalListSource
160         */
161         void        disconnectExternalListSource( );
162 
163         /** connects to a new external list source
164             @param _rxSource
165                 the new list source. Must not be <NULL/>
166             @see disconnectExternalListSource
167         */
168         void        connectExternalListSource(
169                         const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource,
170                         ControlModelLock& _rInstanceLock
171                     );
172 
173         /** refreshes our list entries
174 
175             In case we have an external list source, its used to obtain the new entries, and then
176             stringItemListChanged is called to give the derived class the possibility to
177             react on this.
178 
179             In case we do not have an external list source, refreshInternalEntryList is called.
180         */
181         void        impl_lock_refreshList( ControlModelLock& _rInstanceLock );
182 
183     private:
184         OEntryListHelper();                                     // never implemented
185         OEntryListHelper( const OEntryListHelper& );            // never implemented
186         OEntryListHelper& operator=( const OEntryListHelper& ); // never implemented
187     };
188 
189 //.........................................................................
190 }   // namespace frm
191 //.........................................................................
192 
193 
194 #endif // FORMS_ENTRYLISTHELPER_HXX
195