Branch libreoffice-5-0-4
[LibreOffice.git] / include / svx / SmartTagMgr.hxx
blob321c7055ba71f44367dab8b44b5080e89f81439b
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/implbase2.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 <vector>
31 #include <map>
32 #include <set>
34 namespace com { namespace sun { namespace star { namespace uno {
35 class XComponentContext;
36 } } } }
38 namespace com { namespace sun { namespace star { namespace smarttags {
39 class XSmartTagRecognizer;
40 class XSmartTagAction;
41 } } } }
43 namespace com { namespace sun { namespace star { namespace text {
44 class XTextMarkup;
45 class XTextRange;
46 } } } }
48 namespace com { namespace sun { namespace star { namespace i18n {
49 class XBreakIterator;
50 } } } }
52 namespace com { namespace sun { namespace star { namespace lang {
53 struct Locale;
54 struct EventObject;
55 struct ChangesEvent;
56 } } } }
58 namespace com { namespace sun { namespace star { namespace beans {
59 class XPropertySet;
60 } } } }
62 namespace com { namespace sun { namespace star { namespace frame {
63 class XController;
64 } } } }
66 /** A reference to a smart tag action
68 An action service can support various actions. Therefore an ActionReference
69 consists of a reference to the service and index.
71 struct ActionReference
73 com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > mxSmartTagAction;
74 sal_Int32 mnSmartTagIndex;
75 ActionReference( com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > xSmartTagAction, sal_Int32 nSmartTagIndex )
76 : mxSmartTagAction( xSmartTagAction), mnSmartTagIndex( nSmartTagIndex ) {}
79 /** The smart tag manager maintains all installed action and recognizer services
81 This class organizes the available smarttag libraries and provides access functions
82 to these libraries. The smart tag manager is a singleton.
84 class SVX_DLLPUBLIC SmartTagMgr : public cppu::WeakImplHelper2< ::com::sun::star::util::XModifyListener,
85 ::com::sun::star::util::XChangesListener >
87 private:
89 const OUString maApplicationName;
90 std::vector< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagRecognizer > > maRecognizerList;
91 std::vector< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > > maActionList;
92 std::set< OUString > maDisabledSmartTagTypes;
93 std::multimap < OUString, ActionReference > maSmartTagMap;
94 mutable com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > mxBreakIter;
95 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext> mxContext;
96 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > mxConfigurationSettings;
97 bool mbLabelTextWithSmartTags;
99 /** Checks for installed smart tag recognizers/actions and stores them in
100 maRecognizerList and maActionList.
102 void LoadLibraries();
104 /** Prepare configuration access.
106 void PrepareConfiguration( const OUString& rConfigurationGroupName );
108 /** Reads the configuration data.
110 void ReadConfiguration( bool bExcludedTypes, bool bRecognize );
112 /** Registeres the smart tag manager as listener at the package manager.
114 void RegisterListener();
116 /** Sets up a map that maps smart tag type names to actions references.
118 void AssociateActionsWithRecognizers();
120 void CreateBreakIterator() const;
122 public:
124 SmartTagMgr( const OUString& rApplicationName );
125 virtual ~SmartTagMgr();
127 /** Triggeres configuration reading, library loading and listener registration
128 NOTE: MUST BE CALLED AFTER CONSTRUCTION!
130 void Init( const OUString& 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 com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup >& rMarkup,
156 const com::sun::star::uno::Reference< com::sun::star::frame::XController >& rController,
157 const com::sun::star::lang::Locale& rLocale,
158 sal_uInt32 nStart, sal_uInt32 nLen ) const;
160 void RecognizeTextRange(const com::sun::star::uno::Reference< com::sun::star::text::XTextRange>& rRange,
161 const com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup >& rMarkup,
162 const com::sun::star::uno::Reference< com::sun::star::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( com::sun::star::uno::Sequence < OUString >& rSmartTagTypes,
176 com::sun::star::uno::Sequence < com::sun::star::uno::Sequence< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > > >& rActionComponentsSequence,
177 com::sun::star::uno::Sequence < com::sun::star::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 com::sun::star::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 com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagRecognizer >
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 // ::com::sun::star::lang::XEventListener
221 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
223 // ::com::sun::star::util::XModifyListener
224 virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
226 // ::com::sun::star::util::XChangesListener
227 virtual void SAL_CALL changesOccurred( const ::com::sun::star::util::ChangesEvent& Event ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
230 #endif
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */