xref: /trunk/main/forms/source/component/entrylisthelper.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 ) = 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 
106         /** helper for implementing setFastPropertyValueNoBroadcast
107 
108             <p>Will internally call stringItemListChanged after the new item list
109             has been set.</p>
110 
111             @precond
112                 not to be called when we have an external list source
113             @see hasExternalListSource
114         */
115         void        setNewStringItemList( const ::com::sun::star::uno::Any& _rValue, ControlModelLock& _rInstanceLock );
116 
117         /** announces that the list of entries has changed.
118 
119             <p>Derived classes have to override this. Most probably, they'll set the new
120             as model property.</p>
121 
122             @pure
123             @see getStringItemList
124         */
125         virtual void    stringItemListChanged( ControlModelLock& _rInstanceLock ) = 0;
126 
127         /** called whenever a connection to a new external list source has been established
128         */
129         virtual void    connectedExternalListSource( );
130 
131         /** called whenever a connection to a new external list source has been revoked
132         */
133         virtual void    disconnectedExternalListSource( );
134 
135         /** called when XRefreshable::refresh has been called, and we do *not* have an external
136             list source
137         */
138         virtual void    refreshInternalEntryList() = 0;
139 
140     private:
141         // XListEntrySink
142         virtual void SAL_CALL setListEntrySource( const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource );
143         virtual ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource > SAL_CALL getListEntrySource(  );
144 
145         // XListEntryListener
146         virtual void SAL_CALL entryChanged( const ::com::sun::star::form::binding::ListEntryEvent& _rSource );
147         virtual void SAL_CALL entryRangeInserted( const ::com::sun::star::form::binding::ListEntryEvent& _rSource );
148         virtual void SAL_CALL entryRangeRemoved( const ::com::sun::star::form::binding::ListEntryEvent& _rSource );
149         virtual void SAL_CALL allEntriesChanged( const ::com::sun::star::lang::EventObject& _rSource );
150 
151         // XRefreshable
152         virtual void SAL_CALL refresh();
153         virtual void SAL_CALL addRefreshListener(const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener>& _rxListener);
154         virtual void SAL_CALL removeRefreshListener(const ::com::sun::star::uno::Reference< ::com::sun::star::util::XRefreshListener>& _rxListener);
155 
156     private:
157         /** disconnects from the active external list source, if present
158             @see connectExternalListSource
159         */
160         void        disconnectExternalListSource( );
161 
162         /** connects to a new external list source
163             @param _rxSource
164                 the new list source. Must not be <NULL/>
165             @see disconnectExternalListSource
166         */
167         void        connectExternalListSource(
168                         const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntrySource >& _rxSource,
169                         ControlModelLock& _rInstanceLock
170                     );
171 
172         /** refreshes our list entries
173 
174             In case we have an external list source, its used to obtain the new entries, and then
175             stringItemListChanged is called to give the derived class the possibility to
176             react on this.
177 
178             In case we do not have an external list source, refreshInternalEntryList is called.
179         */
180         void        impl_lock_refreshList( ControlModelLock& _rInstanceLock );
181 
182     private:
183         OEntryListHelper();                                     // never implemented
184         OEntryListHelper( const OEntryListHelper& );            // never implemented
185         OEntryListHelper& operator=( const OEntryListHelper& ); // never implemented
186     };
187 
188 //.........................................................................
189 }   // namespace frm
190 //.........................................................................
191 
192 
193 #endif // FORMS_ENTRYLISTHELPER_HXX
194