LibreOffice Module sw (master)  1
unoatxt.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_UNOATXT_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_UNOATXT_HXX
21 
22 #include <com/sun/star/beans/XPropertySet.hpp>
23 #include <com/sun/star/container/XNamed.hpp>
24 #include <com/sun/star/document/XEventsSupplier.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/lang/XUnoTunnel.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/text/XAutoTextGroup.hpp>
29 #include <com/sun/star/text/XAutoTextEntry.hpp>
30 #include <com/sun/star/text/XAutoTextContainer2.hpp>
31 #include <com/sun/star/text/XText.hpp>
32 #include <svl/itemprop.hxx>
33 #include <svl/lstner.hxx>
34 #include <cppuhelper/basemutex.hxx>
35 #include <cppuhelper/compbase.hxx>
36 #include <cppuhelper/implbase.hxx>
37 #include <rtl/ref.hxx>
38 #include <svtools/unoevent.hxx>
39 
40 class SwTextBlocks;
41 class SwGlossaries;
42 class SwDoc;
43 class SwDocShell;
44 class SwXBodyText;
45 
46 #ifndef SW_DECL_SWDOCSHELL_DEFINED
47 #define SW_DECL_SWDOCSHELL_DEFINED
48 #include <tools/ref.hxx>
50 #endif
51 
52 class SwXAutoTextContainer : public cppu::WeakImplHelper
53 <
54  css::text::XAutoTextContainer2,
55  css::lang::XServiceInfo
56 >
57 {
59 
60 protected:
61  virtual ~SwXAutoTextContainer() override; // ref-counted objects are not to be deleted from outside -> protected dtor
62 
63 public:
65 
66  //XIndexAccess
67  virtual sal_Int32 SAL_CALL getCount( ) override;
68  virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
69 
70  //XNameAccess
71  virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override;
72  virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
73  virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
74 
75  //XElementAccess
76  virtual css::uno::Type SAL_CALL getElementType( ) override;
77  virtual sal_Bool SAL_CALL hasElements( ) override;
78 
79  //XAutoTextContainer
80  virtual css::uno::Reference< css::text::XAutoTextGroup > SAL_CALL insertNewByName(const OUString& aGroupName) override;
81  virtual void SAL_CALL removeByName(const OUString& aGroupName) override;
82 
83  //XServiceInfo
84  virtual OUString SAL_CALL getImplementationName() override;
85  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
86  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
87 
88 };
89 
90 class SwXAutoTextGroup : public cppu::WeakImplHelper
91 <
92  css::text::XAutoTextGroup,
93  css::beans::XPropertySet,
94  css::lang::XServiceInfo,
95  css::container::XIndexAccess,
96  css::container::XNamed,
97  css::lang::XUnoTunnel
98 >
99 {
102  OUString sName;
103  OUString m_sGroupName; // prefix m_ to disambiguate from some local vars in the implementation
104 
105 protected:
106  virtual ~SwXAutoTextGroup() override; // ref-counted objects are not to be deleted from outside -> protected dtor
107 
108 public:
109  SwXAutoTextGroup(const OUString& rName, SwGlossaries* pGloss);
110 
111  static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
112 
113  //XUnoTunnel
114  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
115 
116  //XAutoTextGroup
117  virtual css::uno::Sequence< OUString > SAL_CALL getTitles() override;
118  virtual void SAL_CALL renameByName(const OUString& aElementName, const OUString& aNewElementName, const OUString& aNewElementTitle) override;
119  virtual css::uno::Reference< css::text::XAutoTextEntry > SAL_CALL insertNewByName(const OUString& aName, const OUString& aTitle, const css::uno::Reference< css::text::XTextRange > & xTextRange) override;
120  virtual void SAL_CALL removeByName(const OUString& aEntryName) override;
121 
122  //XNamed
123  virtual OUString SAL_CALL getName() override;
124  virtual void SAL_CALL setName(const OUString& Name_) override;
125 
126  //XIndexAccess
127  virtual sal_Int32 SAL_CALL getCount( ) override;
128  virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override;
129 
130  //XNameAccess
131  virtual css::uno::Any SAL_CALL getByName(const OUString& Name) override;
132  virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
133  virtual sal_Bool SAL_CALL hasByName(const OUString& Name) override;
134 
135  //XElementAccess
136  virtual css::uno::Type SAL_CALL getElementType( ) override;
137  virtual sal_Bool SAL_CALL hasElements( ) override;
138 
139  //XServiceInfo
140  virtual OUString SAL_CALL getImplementationName() override;
141  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
142  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
143 
144  //XPropertySet
145  virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
146  virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
147  virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
148  virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
149  virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
150  virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
151  virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
152 
153  void Invalidate();
154 };
155 
156 class SwXAutoTextEntry final
157  :public SfxListener
158  ,public cppu::BaseMutex
159  ,public cppu::WeakComponentImplHelper
160  <
161  css::text::XAutoTextEntry,
162  css::lang::XServiceInfo,
163  css::lang::XUnoTunnel,
164  css::text::XText,
165  css::document::XEventsSupplier
166  >
167 {
169  OUString const sGroupName;
170  OUString const sEntryName;
174 
176  {
177  if ( !mxBodyText.is() )
178  GetBodyText();
179  }
180  void GetBodyText ();
181 
182  void SAL_CALL disposing() override;
183 
195  void implFlushDocument( bool _bCloseDoc = false );
196 
197  // SfxListener overridables
198  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
199 
200  virtual ~SwXAutoTextEntry() override; // ref-counted objects are not to be deleted from outside -> protected dtor
201 
202 public:
203  SwXAutoTextEntry(SwGlossaries* , const OUString& rGroupName, const OUString& rEntryName);
204 
205  static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
206 
207  //XUnoTunnel
208  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
209 
210  //XText
211  virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override;
212  virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > & aTextPosition) override;
213  virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > & xRange, const OUString& aString, sal_Bool bAbsorb) override;
214  virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > & xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override;
215  virtual void SAL_CALL insertTextContent(const css::uno::Reference< css::text::XTextRange > & xRange, const css::uno::Reference< css::text::XTextContent > & xContent, sal_Bool bAbsorb) override;
216  virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > & xContent) override;
217 
218  //XTextRange
219  virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override;
220  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override;
221  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override;
222  virtual OUString SAL_CALL getString() override;
223  virtual void SAL_CALL setString(const OUString& aString) override;
224 
225  //XAutoTextEntry
226  virtual void SAL_CALL applyTo(const css::uno::Reference< css::text::XTextRange > & xRange) override;
227 
228  //XServiceInfo
229  virtual OUString SAL_CALL getImplementationName() override;
230  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
231  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
232 
233  // XEventsSupplier
234  virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents( ) override;
235 
236  void Invalidate() {pGlossaries = nullptr;}
238  const OUString& GetGroupName() {return sGroupName;}
239  const OUString& GetEntryName() {return sEntryName;}
240 };
241 
244 {
246 
249 
250 public:
252 
253  virtual ~SwAutoTextEventDescriptor() override;
254 
255  virtual OUString SAL_CALL getImplementationName() override;
256 
257 protected:
258 
259  virtual void replaceByName(
260  const SvMacroItemId nEvent,
261  const SvxMacro& rMacro)
262  override;
263 
264  virtual void getByName(
265  SvxMacro& rMacro,
266  const SvMacroItemId nEvent )
267  override;
268 };
269 
270 #endif
271 
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwGlossaries * GetGlossaries()
Definition: unoatxt.hxx:237
virtual void SAL_CALL setName(const OUString &Name_) override
Definition: unoatxt.cxx:455
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unoatxt.cxx:687
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: unoatxt.cxx:580
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: unoatxt.cxx:639
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: unoatxt.cxx:738
virtual css::uno::Type SAL_CALL getElementType() override
Definition: unoatxt.cxx:518
OUString m_sGroupName
Definition: unoatxt.hxx:103
virtual css::uno::Any SAL_CALL getByName(const OUString &Name) override
Definition: unoatxt.cxx:105
virtual sal_Bool SAL_CALL hasElements() override
Definition: unoatxt.cxx:99
virtual sal_Bool SAL_CALL hasByName(const OUString &Name) override
Definition: unoatxt.cxx:138
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: unoatxt.cxx:833
Definition: doc.hxx:185
SvMacroItemId
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override
Definition: unoatxt.cxx:506
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unoatxt.cxx:950
virtual css::uno::Any SAL_CALL getByName(const OUString &rName) override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: unoatxt.cxx:543
virtual css::uno::Type SAL_CALL getElementType() override
Definition: unoatxt.cxx:93
void EnsureBodyText()
Definition: unoatxt.hxx:175
void SAL_CALL disposing() override
Definition: unoatxt.cxx:780
virtual OUString SAL_CALL getString() override
Definition: unoatxt.cxx:854
const OUString & GetGroupName()
Definition: unoatxt.hxx:238
virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > &xRange, const OUString &aString, sal_Bool bAbsorb) override
Definition: unoatxt.cxx:801
virtual css::uno::Sequence< OUString > SAL_CALL getTitles() override
Definition: unoatxt.cxx:251
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override
Definition: unoatxt.cxx:84
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: unoatxt.cxx:615
virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents() override
Definition: unoatxt.cxx:956
virtual void SAL_CALL applyTo(const css::uno::Reference< css::text::XTextRange > &xRange) override
Definition: unoatxt.cxx:868
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
Definition: unoatxt.cxx:786
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: unoatxt.cxx:692
SwXAutoTextGroup(const OUString &rName, SwGlossaries *pGloss)
Definition: unoatxt.cxx:236
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: unoatxt.cxx:120
OUString sName
Definition: unoatxt.hxx:102
virtual sal_Int32 SAL_CALL getCount() override
Definition: unoatxt.cxx:77
virtual void SAL_CALL removeByName(const OUString &aEntryName) override
Definition: unoatxt.cxx:435
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:666
virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > &xContent) override
Definition: unoatxt.cxx:825
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: unoatxt.cxx:840
SwXAutoTextEntry(SwGlossaries *, const OUString &rGroupName, const OUString &rEntryName)
Definition: unoatxt.cxx:703
virtual void SAL_CALL replaceByName(const OUString &rName, const css::uno::Any &rElement) override
virtual sal_Bool SAL_CALL hasElements() override
Definition: unoatxt.cxx:524
virtual sal_Int32 SAL_CALL getCount() override
Definition: unoatxt.cxx:497
const OUString & GetEntryName()
Definition: unoatxt.hxx:239
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:979
SwDocShellRef xDocSh
Definition: unoatxt.hxx:171
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unoatxt.cxx:654
unsigned char sal_Bool
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unoatxt.cxx:945
tools::SvRef< SwDocShell > SwDocShellRef
Definition: unoatxt.hxx:49
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unoatxt.cxx:671
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unoatxt.cxx:676
void implFlushDocument(bool _bCloseDoc=false)
ensure that the current content (which may only be in-memory so far) is flushed to the auto text grou...
Definition: unoatxt.cxx:720
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
Definition: unoatxt.cxx:644
virtual void replaceByName(const SvMacroItemId nEvent, const SvxMacro &rMacro) override
event (will be copied)
Definition: unoatxt.cxx:984
virtual ~SwXAutoTextContainer() override
Definition: unoatxt.cxx:72
OUString const sEntryName
Definition: unoatxt.hxx:170
OUString const sGroupName
Definition: unoatxt.hxx:169
virtual ~SwXAutoTextGroup() override
Definition: unoatxt.cxx:247
virtual OUString SAL_CALL getName() override
Definition: unoatxt.cxx:449
const SfxItemPropertySet * pPropSet
Definition: unoatxt.hxx:100
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: unoatxt.cxx:847
virtual sal_Bool SAL_CALL hasByName(const OUString &Name) override
Definition: unoatxt.cxx:559
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unoatxt.cxx:649
void Invalidate()
Definition: unoatxt.hxx:236
Implement the XNameAccess for the AutoText events.
Definition: unoatxt.hxx:243
virtual void SAL_CALL removeByName(const OUString &aGroupName) override
Definition: unoatxt.cxx:188
virtual void SAL_CALL setString(const OUString &aString) override
Definition: unoatxt.cxx:861
virtual ~SwXAutoTextEntry() override
Definition: unoatxt.cxx:712
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: unoatxt.cxx:586
virtual css::uno::Any SAL_CALL getByName(const OUString &Name) override
Definition: unoatxt.cxx:534
rtl::Reference< SwXBodyText > mxBodyText
Definition: unoatxt.hxx:173
virtual css::uno::Reference< css::text::XAutoTextGroup > SAL_CALL insertNewByName(const OUString &aGroupName) override
Definition: unoatxt.cxx:147
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unoatxt.cxx:208
virtual void getByName(SvxMacro &rMacro, const SvMacroItemId nEvent) override
item ID of event
Definition: unoatxt.cxx:1017
SwGlossaries * pGlossaries
Definition: unoatxt.hxx:101
virtual css::uno::Reference< css::text::XAutoTextEntry > SAL_CALL insertNewByName(const OUString &aName, const OUString &aTitle, const css::uno::Reference< css::text::XTextRange > &xTextRange) override
Definition: unoatxt.cxx:334
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unoatxt.cxx:203
virtual void SAL_CALL insertTextContent(const css::uno::Reference< css::text::XTextRange > &xRange, const css::uno::Reference< css::text::XTextContent > &xContent, sal_Bool bAbsorb) override
Definition: unoatxt.cxx:816
virtual void SAL_CALL renameByName(const OUString &aElementName, const OUString &aNewElementName, const OUString &aNewElementTitle) override
Definition: unoatxt.cxx:267
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:198
void Invalidate()
Definition: unoatxt.cxx:659
virtual ~SwAutoTextEventDescriptor() override
Definition: unoatxt.cxx:975
SwXAutoTextEntry & rAutoTextEntry
Definition: unoatxt.hxx:245
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: unoatxt.cxx:225
virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override
Definition: unoatxt.cxx:808
SwAutoTextEventDescriptor(SwXAutoTextEntry &rAutoText)
Definition: unoatxt.cxx:968
SwGlossaries * pGlossaries
Definition: unoatxt.hxx:58
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: unoatxt.cxx:220
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > &aTextPosition) override
Definition: unoatxt.cxx:793
void GetBodyText()
Definition: unoatxt.cxx:767
SwGlossaries * pGlossaries
Definition: unoatxt.hxx:168
virtual OUString SAL_CALL getImplementationName() override
Definition: unoatxt.cxx:940