Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / svx / SmartTagMgr.hxx
blobdc8f8f4748319326f2b0b5b2581da28a9f4b8953
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVX_SMARTTAGMGR_HXX
21 #define INCLUDED_SVX_SMARTTAGMGR_HXX
23 #include <cppuhelper/implbase.hxx>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <com/sun/star/util/XModifyListener.hpp>
27 #include <com/sun/star/util/XChangesListener.hpp>
28 #include <svx/svxdllapi.h>
30 #include <utility>
31 #include <vector>
32 #include <map>
33 #include <set>
34 #include <string_view>
36 namespace com::sun::star::uno {
37 class XComponentContext;
40 namespace com::sun::star::smarttags {
41 class XSmartTagRecognizer;
42 class XSmartTagAction;
45 namespace com::sun::star::text {
46 class XTextMarkup;
47 class XTextRange;
50 namespace com::sun::star::i18n {
51 class XBreakIterator;
54 namespace com::sun::star::lang {
55 struct Locale;
56 struct EventObject;
57 struct ChangesEvent;
60 namespace com::sun::star::beans {
61 class XPropertySet;
64 namespace com::sun::star::frame {
65 class XController;
68 /** A reference to a smart tag action
70 An action service can support various actions. Therefore an ActionReference
71 consists of a reference to the service and index.
73 struct ActionReference
75 css::uno::Reference< css::smarttags::XSmartTagAction > mxSmartTagAction;
76 sal_Int32 mnSmartTagIndex;
77 ActionReference( css::uno::Reference< css::smarttags::XSmartTagAction > xSmartTagAction, sal_Int32 nSmartTagIndex )
78 : mxSmartTagAction(std::move( xSmartTagAction)), mnSmartTagIndex( nSmartTagIndex ) {}
81 /** The smart tag manager maintains all installed action and recognizer services
83 This class organizes the available smarttag libraries and provides access functions
84 to these libraries. The smart tag manager is a singleton.
86 class SVX_DLLPUBLIC SmartTagMgr : public cppu::WeakImplHelper< css::util::XModifyListener,
87 css::util::XChangesListener >
89 private:
91 const OUString maApplicationName;
92 std::vector< css::uno::Reference< css::smarttags::XSmartTagRecognizer > > maRecognizerList;
93 std::vector< css::uno::Reference< css::smarttags::XSmartTagAction > > maActionList;
94 std::set< OUString > maDisabledSmartTagTypes;
95 std::multimap < OUString, ActionReference > maSmartTagMap;
96 mutable css::uno::Reference< css::i18n::XBreakIterator > mxBreakIter;
97 css::uno::Reference< css::uno::XComponentContext> mxContext;
98 css::uno::Reference< css::beans::XPropertySet > mxConfigurationSettings;
99 bool mbLabelTextWithSmartTags;
101 /** Checks for installed smart tag recognizers/actions and stores them in
102 maRecognizerList and maActionList.
104 void LoadLibraries();
106 /** Prepare configuration access.
108 void PrepareConfiguration( std::u16string_view rConfigurationGroupName );
110 /** Reads the configuration data.
112 void ReadConfiguration( bool bExcludedTypes, bool bRecognize );
114 /** Registers the smart tag manager as listener at the package manager.
116 void RegisterListener();
118 /** Sets up a map that maps smart tag type names to actions references.
120 void AssociateActionsWithRecognizers();
122 public:
124 SmartTagMgr( OUString aApplicationName );
125 virtual ~SmartTagMgr() override;
127 /** Triggers configuration reading, library loading and listener registration
128 NOTE: MUST BE CALLED AFTER CONSTRUCTION!
130 void Init( std::u16string_view rConfigurationGroupName );
132 /** Dispatches the recognize call to all installed smart tag recognizers
134 @param rText
135 The string to be scanned by the recognizers.
137 @param xMarkup
138 The object allows the recognizers to store any found smart tags.
140 @param xController
141 The current controller of the document.
143 @param rLocale
144 The locale of rText.
146 @param nStart
147 The start offset of the text to be scanned in rText.
149 @param nLen
150 The length of the text to be scanned.
154 void RecognizeString( const OUString& rText,
155 const css::uno::Reference< css::text::XTextMarkup >& rMarkup,
156 const css::uno::Reference< css::frame::XController >& rController,
157 const css::lang::Locale& rLocale,
158 sal_uInt32 nStart, sal_uInt32 nLen ) const;
160 void RecognizeTextRange(const css::uno::Reference< css::text::XTextRange>& rRange,
161 const css::uno::Reference< css::text::XTextMarkup >& rMarkup,
162 const css::uno::Reference< css::frame::XController >& rController) const;
164 /** Returns all action references associated with a given list of smart tag types
166 @param rSmartTagTypes
167 The list of types
169 @param rActionComponentsSequence
170 Output parameter
172 @param rActionIndicesSequence
173 Output parameter
175 void GetActionSequences( std::vector< OUString >& rSmartTagTypes,
176 css::uno::Sequence < css::uno::Sequence< css::uno::Reference< css::smarttags::XSmartTagAction > > >& rActionComponentsSequence,
177 css::uno::Sequence < css::uno::Sequence< sal_Int32 > >& rActionIndicesSequence ) const;
179 /** Returns the caption for a smart tag type.
181 @param rSmartTagType
182 The given smart tag type.
184 @param rLocale
185 The locale.
187 OUString GetSmartTagCaption( const OUString& rSmartTagType, const css::lang::Locale& rLocale ) const;
189 /** Returns true if the given smart tag type is enabled.
191 bool IsSmartTagTypeEnabled( const OUString& rSmartTagType ) const;
193 /** Enable or disable smart tags.
195 bool IsLabelTextWithSmartTags() const { return mbLabelTextWithSmartTags; }
197 /** Returns the number of registered recognizers.
199 sal_uInt32 NumberOfRecognizers() const { return maRecognizerList.size(); }
201 /** Returns a recognizer.
203 css::uno::Reference< css::smarttags::XSmartTagRecognizer > const &
204 GetRecognizer( sal_uInt32 i ) const { return maRecognizerList[i]; }
206 /** Is smart tag recognition active?
208 bool IsSmartTagsEnabled() const { return 0 != NumberOfRecognizers() &&
209 IsLabelTextWithSmartTags(); }
211 /** Writes configuration settings.
213 void WriteConfiguration( const bool* bLabelTextWithSmartTags,
214 const std::vector< OUString >* pDisabledTypes ) const;
216 /** Returns the name of the application this instance has been created by.
218 const OUString& GetApplicationName() const { return maApplicationName; }
220 // css::lang::XEventListener
221 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
223 // css::util::XModifyListener
224 virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
226 // css::util::XChangesListener
227 virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& Event ) override;
230 #endif
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */