bump product version to 4.1.6.2
[LibreOffice.git] / include / svx / SmartTagMgr.hxx
blob836ff820650fae805d2b9d9d55ace7678f2f98c3
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 _SMARTTAGMGR_HXX
21 #define _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 } } } }
47 namespace com { namespace sun { namespace star { namespace i18n {
48 class XBreakIterator;
49 } } } }
51 namespace com { namespace sun { namespace star { namespace lang {
52 struct Locale;
53 struct EventObject;
54 struct ChangesEvent;
55 } } } }
57 namespace com { namespace sun { namespace star { namespace beans {
58 class XPropertySet;
59 } } } }
61 namespace com { namespace sun { namespace star { namespace frame {
62 class XController;
63 } } } }
65 /** A reference to a smart tag action
67 An action service can support various actions. Therefore an ActionReference
68 consists of a reference to the service and and index.
70 struct ActionReference
72 com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > mxSmartTagAction;
73 sal_Int32 mnSmartTagIndex;
74 ActionReference( com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > xSmartTagAction, sal_Int32 nSmartTagIndex )
75 : mxSmartTagAction( xSmartTagAction), mnSmartTagIndex( nSmartTagIndex ) {}
78 /** The smart tag manager maintains all installed action and recognizer services
80 This class organizes the available smarttag libraries and provides access functions
81 to these libraries. The smart tag manager is a singleton.
83 class SVX_DLLPUBLIC SmartTagMgr : public cppu::WeakImplHelper2< ::com::sun::star::util::XModifyListener,
84 ::com::sun::star::util::XChangesListener >
86 private:
88 const OUString maApplicationName;
89 std::vector< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagRecognizer > > maRecognizerList;
90 std::vector< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > > maActionList;
91 std::set< OUString > maDisabledSmartTagTypes;
92 std::multimap < OUString, ActionReference > maSmartTagMap;
93 mutable com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > mxBreakIter;
94 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext> mxContext;
95 com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > mxConfigurationSettings;
96 bool mbLabelTextWithSmartTags;
98 /** Checks for installed smart tag recognizers/actions and stores them in
99 maRecognizerList and maActionList.
101 void LoadLibraries();
103 /** Prepare configuration access.
105 void PrepareConfiguration( const OUString& rConfigurationGroupName );
107 /** Reads the configuration data.
109 void ReadConfiguration( bool bExcludedTypes, bool bRecognize );
111 /** Registeres the smart tag manager as listener at the package manager.
113 void RegisterListener();
115 /** Sets up a map that maps smart tag type names to actions references.
117 void AssociateActionsWithRecognizers();
119 void CreateBreakIterator() const;
121 public:
123 SmartTagMgr( const OUString& rApplicationName );
124 virtual ~SmartTagMgr();
126 /** Triggeres configuration reading, library loading and listener registration
127 NOTE: MUST BE CALLED AFTER CONSTRUCTION!
129 void Init( const OUString& rConfigurationGroupName );
131 /** Dispatches the recognize call to all installed smart tag recognizers
133 @param rText
134 The string to be scanned by the recognizers.
136 @param xMarkup
137 The object allows the recognizers to store any found smart tags.
139 @param xController
140 The current controller of the document.
142 @param rLocale
143 The locale of rText.
145 @param nStart
146 The start offset of the text to be scanned in rText.
148 @param nLen
149 The length of the text to be scanned.
152 void Recognize( const OUString& rText,
153 const com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup > xMarkup,
154 const com::sun::star::uno::Reference< com::sun::star::frame::XController > xController,
155 const com::sun::star::lang::Locale& rLocale,
156 sal_uInt32 nStart, sal_uInt32 nLen ) const;
158 /** Returns all action references associated with a given list of smart tag types
160 @param rSmartTagTypes
161 The list of types
163 @param rActionComponentsSequence
164 Output parameter
166 @param rActionIndicesSequence
167 Output parameter
169 void GetActionSequences( com::sun::star::uno::Sequence < OUString >& rSmartTagTypes,
170 com::sun::star::uno::Sequence < com::sun::star::uno::Sequence< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > > >& rActionComponentsSequence,
171 com::sun::star::uno::Sequence < com::sun::star::uno::Sequence< sal_Int32 > >& rActionIndicesSequence ) const;
173 /** Returns the caption for a smart tag type.
175 @param rSmartTagType
176 The given smart tag type.
178 @param rLocale
179 The locale.
181 OUString GetSmartTagCaption( const OUString& rSmartTagType, const com::sun::star::lang::Locale& rLocale ) const;
183 /** Returns true if the given smart tag type is enabled.
185 bool IsSmartTagTypeEnabled( const OUString& rSmartTagType ) const;
187 /** Enable or disable smart tags.
189 bool IsLabelTextWithSmartTags() const { return mbLabelTextWithSmartTags; }
191 /** Returns the number of registered recognizers.
193 sal_uInt32 NumberOfRecognizers() const { return maRecognizerList.size(); }
195 /** Returns a recognizer.
197 com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagRecognizer >
198 GetRecognizer( sal_uInt32 i ) const { return maRecognizerList[i]; }
200 /** Is smart tag recognization active?
202 bool IsSmartTagsEnabled() const { return 0 != NumberOfRecognizers() &&
203 IsLabelTextWithSmartTags(); }
205 /** Writes configuration settings.
207 void WriteConfiguration( const bool* bLabelTextWithSmartTags,
208 const std::vector< OUString >* pDisabledTypes ) const;
210 /** Returns the name of the application this instance has been created by.
212 const OUString GetApplicationName() const { return maApplicationName; }
214 // ::com::sun::star::lang::XEventListener
215 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
217 // ::com::sun::star::util::XModifyListener
218 virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw(::com::sun::star::uno::RuntimeException);
220 // ::com::sun::star::util::XChangesListener
221 virtual void SAL_CALL changesOccurred( const ::com::sun::star::util::ChangesEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
224 #endif
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */