xref: /trunk/main/sc/inc/fielduno.hxx (revision 9d37da743abb7db0a497688391f6e55a19f27c44)
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 SC_FIELDUNO_HXX
25 #define SC_FIELDUNO_HXX
26 
27 #include "address.hxx"
28 #include "mutexhlp.hxx"
29 
30 #include <svl/lstner.hxx>
31 #include <svl/itemprop.hxx>
32 #include <editeng/editdata.hxx>
33 #include <com/sun/star/text/XTextField.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/container/XContainer.hpp>
36 #include <com/sun/star/lang/XUnoTunnel.hpp>
37 #include <com/sun/star/container/XEnumerationAccess.hpp>
38 #include <com/sun/star/container/XIndexAccess.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/util/XRefreshable.hpp>
41 #include <cppuhelper/component.hxx>
42 #include <cppuhelper/implbase5.hxx>
43 #include <osl/mutex.hxx>
44 
45 class SvxEditSource;
46 class SvxFieldItem;
47 class ScCellFieldObj;
48 class ScHeaderFieldObj;
49 class ScHeaderFooterContentObj;
50 class ScDocShell;
51 
52 
53 //------------------------------------------------------------------
54 
55 
56 class ScCellFieldsObj : public cppu::WeakImplHelper5<
57                             com::sun::star::container::XEnumerationAccess,
58                             com::sun::star::container::XIndexAccess,
59                             com::sun::star::container::XContainer,
60                             com::sun::star::util::XRefreshable,
61                             com::sun::star::lang::XServiceInfo >,
62                         public SfxListener
63 {
64 private:
65     ScDocShell*             pDocShell;
66     ScAddress               aCellPos;
67     SvxEditSource*          pEditSource;
68     /// List of refresh listeners.
69     cppu::OInterfaceContainerHelper* mpRefreshListeners;
70     /// mutex to lock the InterfaceContainerHelper
71     osl::Mutex              aMutex;
72 
73     ScCellFieldObj*         GetObjectByIndex_Impl(sal_Int32 Index) const;
74 
75 public:
76                             ScCellFieldsObj(ScDocShell* pDocSh, const ScAddress& rPos);
77     virtual                 ~ScCellFieldsObj();
78 
79     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
80 
81                             // XIndexAccess
82     virtual sal_Int32 SAL_CALL getCount();
83     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index );
84 
85                             // XEnumerationAccess
86     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
87                             createEnumeration();
88 
89                             // XElementAccess
90     virtual ::com::sun::star::uno::Type SAL_CALL getElementType();
91     virtual sal_Bool SAL_CALL hasElements();
92 
93                             // XContainer
94     virtual void SAL_CALL   addContainerListener( const ::com::sun::star::uno::Reference<
95                                 ::com::sun::star::container::XContainerListener >& xListener );
96     virtual void SAL_CALL   removeContainerListener( const ::com::sun::star::uno::Reference<
97                                 ::com::sun::star::container::XContainerListener >& xListener );
98 
99                             // XRefreshable
100     virtual void SAL_CALL refresh(  );
101     virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference<
102                                 ::com::sun::star::util::XRefreshListener >& l );
103     virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference<
104                                 ::com::sun::star::util::XRefreshListener >& l );
105 
106                             // XServiceInfo
107     virtual ::rtl::OUString SAL_CALL getImplementationName();
108     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
109     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
110 };
111 
112 
113 class ScCellFieldObj : public ScMutexHelper,
114                         public ::cppu::OComponentHelper,
115                         public ::com::sun::star::text::XTextField,
116                         public ::com::sun::star::beans::XPropertySet,
117                         public ::com::sun::star::lang::XUnoTunnel,
118                         public ::com::sun::star::lang::XServiceInfo,
119                         public SfxListener
120 {
121 private:
122     const SfxItemPropertySet*       pPropSet;
123     ScDocShell*             pDocShell;
124     ScAddress               aCellPos;
125     SvxEditSource*          pEditSource;
126     ESelection              aSelection;
127 
128     String                  aUrl;               // Inhalt, wenn noch nicht eingefuegt (nur dann!)
129     String                  aRepresentation;
130     String                  aTarget;
131 
132     ScCellFieldObj(); // disabled
133 public:
134                             ScCellFieldObj(ScDocShell* pDocSh, const ScAddress& rPos,
135                                             const ESelection& rSel);
136     virtual                 ~ScCellFieldObj();
137 
138     virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
139 
140                             // per getImplementation gerufen:
141     void                    DeleteField();
142     sal_Bool                    IsInserted() const      { return pEditSource != NULL; }
143     SvxFieldItem            CreateFieldItem();
144     void                    InitDoc( ScDocShell* pDocSh, const ScAddress& rPos,
145                                         const ESelection& rSel );
146 
147     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(
148                                 const ::com::sun::star::uno::Type & rType );
149     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
150                                 const ::com::sun::star::uno::Type & rType );
151     virtual void SAL_CALL   acquire() throw();
152     virtual void SAL_CALL   release() throw();
153 
154                             // XTextField
155     virtual ::rtl::OUString SAL_CALL getPresentation( sal_Bool bShowCommand );
156 
157                             // XTextContent
158     virtual void SAL_CALL   attach( const ::com::sun::star::uno::Reference<
159                                 ::com::sun::star::text::XTextRange >& xTextRange );
160     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
161                             getAnchor();
162 
163                             // XComponent
164     virtual void SAL_CALL   dispose();
165     virtual void SAL_CALL   addEventListener( const ::com::sun::star::uno::Reference<
166                                 ::com::sun::star::lang::XEventListener >& xListener );
167     virtual void SAL_CALL   removeEventListener( const ::com::sun::star::uno::Reference<
168                                 ::com::sun::star::lang::XEventListener >& aListener );
169 
170                             // XPropertySet
171     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
172                             SAL_CALL getPropertySetInfo();
173     virtual void SAL_CALL   setPropertyValue( const ::rtl::OUString& aPropertyName,
174                                     const ::com::sun::star::uno::Any& aValue );
175     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
176                                     const ::rtl::OUString& PropertyName );
177     virtual void SAL_CALL   addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
178                                     const ::com::sun::star::uno::Reference<
179                                         ::com::sun::star::beans::XPropertyChangeListener >& xListener );
180     virtual void SAL_CALL   removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
181                                     const ::com::sun::star::uno::Reference<
182                                         ::com::sun::star::beans::XPropertyChangeListener >& aListener );
183     virtual void SAL_CALL   addVetoableChangeListener( const ::rtl::OUString& PropertyName,
184                                     const ::com::sun::star::uno::Reference<
185                                         ::com::sun::star::beans::XVetoableChangeListener >& aListener );
186     virtual void SAL_CALL   removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
187                                     const ::com::sun::star::uno::Reference<
188                                         ::com::sun::star::beans::XVetoableChangeListener >& aListener );
189 
190                             // XUnoTunnel
191     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
192                                     sal_Int8 >& aIdentifier );
193 
194     static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
195     static ScCellFieldObj* getImplementation( const com::sun::star::uno::Reference<
196                                     com::sun::star::text::XTextContent> xObj );
197 
198                             // XServiceInfo
199     virtual ::rtl::OUString SAL_CALL getImplementationName();
200     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
201     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
202 
203                             // XTypeProvider
204     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes();
205     virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId();
206 };
207 
208 //------------------------------------------------------------------
209 
210 class ScHeaderFieldsObj : public cppu::WeakImplHelper5<
211                             com::sun::star::container::XEnumerationAccess,
212                             com::sun::star::container::XIndexAccess,
213                             com::sun::star::container::XContainer,
214                             com::sun::star::util::XRefreshable,
215                             com::sun::star::lang::XServiceInfo >
216 {
217 private:
218     ScHeaderFooterContentObj*   pContentObj;
219     sal_uInt16                      nPart;
220     sal_uInt16                      nType;
221     SvxEditSource*              pEditSource;
222 
223     /// List of refresh listeners.
224     cppu::OInterfaceContainerHelper* mpRefreshListeners;
225     /// mutex to lock the InterfaceContainerHelper
226     osl::Mutex                  aMutex;
227 
228     ScHeaderFieldObj*       GetObjectByIndex_Impl(sal_Int32 Index) const;
229 
230 public:
231                             ScHeaderFieldsObj(ScHeaderFooterContentObj* pContent,
232                                                 sal_uInt16 nP, sal_uInt16 nT);
233     virtual                 ~ScHeaderFieldsObj();
234 
235                             // XIndexAccess
236     virtual sal_Int32 SAL_CALL getCount();
237     virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index );
238 
239                             // XEnumerationAccess
240     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
241                             createEnumeration();
242 
243                             // XElementAccess
244     virtual ::com::sun::star::uno::Type SAL_CALL getElementType();
245     virtual sal_Bool SAL_CALL hasElements();
246 
247                             // XContainer
248     virtual void SAL_CALL   addContainerListener( const ::com::sun::star::uno::Reference<
249                                 ::com::sun::star::container::XContainerListener >& xListener );
250     virtual void SAL_CALL   removeContainerListener( const ::com::sun::star::uno::Reference<
251                                 ::com::sun::star::container::XContainerListener >& xListener );
252 
253                             // XRefreshable
254     virtual void SAL_CALL refresh(  );
255     virtual void SAL_CALL addRefreshListener( const ::com::sun::star::uno::Reference<
256                                 ::com::sun::star::util::XRefreshListener >& l );
257     virtual void SAL_CALL removeRefreshListener( const ::com::sun::star::uno::Reference<
258                                 ::com::sun::star::util::XRefreshListener >& l );
259 
260                             // XServiceInfo
261     virtual ::rtl::OUString SAL_CALL getImplementationName();
262     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
263     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
264 };
265 
266 
267 class ScHeaderFieldObj : public ScMutexHelper,
268                             public ::cppu::OComponentHelper,
269                             public ::com::sun::star::text::XTextField,
270                             public ::com::sun::star::beans::XPropertySet,
271                             public ::com::sun::star::lang::XUnoTunnel,
272                             public ::com::sun::star::lang::XServiceInfo
273 {
274 private:
275     const SfxItemPropertySet*   pPropSet;
276     ScHeaderFooterContentObj*   pContentObj;
277     sal_uInt16                      nPart;
278     sal_uInt16                      nType;
279     SvxEditSource*              pEditSource;
280     ESelection                  aSelection;
281     sal_Int16                   nFileFormat;        // enum SvxFileFormat, valid if not inserted
282 
283     ScHeaderFieldObj(); // disabled
284 public:
285                             ScHeaderFieldObj(ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
286                                             sal_uInt16 nT, const ESelection& rSel);
287     virtual                 ~ScHeaderFieldObj();
288 
289                             // per getImplementation gerufen:
290     void                    DeleteField();
291     sal_Bool                    IsInserted() const      { return pEditSource != NULL; }
292     SvxFieldItem            CreateFieldItem();
293     void                    InitDoc( ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
294                                         const ESelection& rSel );
295 
296     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(
297                                 const ::com::sun::star::uno::Type & rType );
298     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
299                                 const ::com::sun::star::uno::Type & rType );
300     virtual void SAL_CALL   acquire() throw();
301     virtual void SAL_CALL   release() throw();
302 
303                             // XTextField
304     virtual ::rtl::OUString SAL_CALL getPresentation( sal_Bool bShowCommand );
305 
306                             // XTextContent
307     virtual void SAL_CALL   attach( const ::com::sun::star::uno::Reference<
308                                 ::com::sun::star::text::XTextRange >& xTextRange );
309     virtual ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange > SAL_CALL
310                             getAnchor();
311 
312                             // XComponent
313     virtual void SAL_CALL   dispose();
314     virtual void SAL_CALL   addEventListener( const ::com::sun::star::uno::Reference<
315                                 ::com::sun::star::lang::XEventListener >& xListener );
316     virtual void SAL_CALL   removeEventListener( const ::com::sun::star::uno::Reference<
317                                 ::com::sun::star::lang::XEventListener >& aListener );
318 
319                             // XPropertySet
320     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
321                             SAL_CALL getPropertySetInfo();
322     virtual void SAL_CALL   setPropertyValue( const ::rtl::OUString& aPropertyName,
323                                     const ::com::sun::star::uno::Any& aValue );
324     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
325                                     const ::rtl::OUString& PropertyName );
326     virtual void SAL_CALL   addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
327                                     const ::com::sun::star::uno::Reference<
328                                         ::com::sun::star::beans::XPropertyChangeListener >& xListener );
329     virtual void SAL_CALL   removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
330                                     const ::com::sun::star::uno::Reference<
331                                         ::com::sun::star::beans::XPropertyChangeListener >& aListener );
332     virtual void SAL_CALL   addVetoableChangeListener( const ::rtl::OUString& PropertyName,
333                                     const ::com::sun::star::uno::Reference<
334                                         ::com::sun::star::beans::XVetoableChangeListener >& aListener );
335     virtual void SAL_CALL   removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
336                                     const ::com::sun::star::uno::Reference<
337                                         ::com::sun::star::beans::XVetoableChangeListener >& aListener );
338 
339                             // XUnoTunnel
340     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
341                                     sal_Int8 >& aIdentifier );
342 
343     static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
344     static ScHeaderFieldObj* getImplementation( const com::sun::star::uno::Reference<
345                                     com::sun::star::text::XTextContent> xObj );
346 
347                             // XServiceInfo
348     virtual ::rtl::OUString SAL_CALL getImplementationName();
349     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
350     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
351 
352                             // XTypeProvider
353     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes();
354     virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId();
355 };
356 
357 #endif
358