xref: /aoo41x/main/svx/inc/svx/SmartTagMgr.hxx (revision bbac9d2c)
13334a7e6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
33334a7e6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
43334a7e6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
53334a7e6SAndrew Rist  * distributed with this work for additional information
63334a7e6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
73334a7e6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
83334a7e6SAndrew Rist  * "License"); you may not use this file except in compliance
93334a7e6SAndrew Rist  * with the License.  You may obtain a copy of the License at
103334a7e6SAndrew Rist  *
113334a7e6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
123334a7e6SAndrew Rist  *
133334a7e6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
143334a7e6SAndrew Rist  * software distributed under the License is distributed on an
153334a7e6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
163334a7e6SAndrew Rist  * KIND, either express or implied.  See the License for the
173334a7e6SAndrew Rist  * specific language governing permissions and limitations
183334a7e6SAndrew Rist  * under the License.
193334a7e6SAndrew Rist  *
203334a7e6SAndrew Rist  *************************************************************/
213334a7e6SAndrew Rist 
223334a7e6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _SMARTTAGMGR_HXX
25cdf0e10cSrcweir #define _SMARTTAGMGR_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
28cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
29cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
30cdf0e10cSrcweir #include <com/sun/star/util/XModifyListener.hpp>
31cdf0e10cSrcweir #include <com/sun/star/util/XChangesListener.hpp>
32cdf0e10cSrcweir #include "svx/svxdllapi.h"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <vector>
35cdf0e10cSrcweir #include <map>
36cdf0e10cSrcweir #include <set>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace uno {
39cdf0e10cSrcweir     class XComponentContext;
40cdf0e10cSrcweir } } } }
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace smarttags {
43cdf0e10cSrcweir     class XSmartTagRecognizer;
44cdf0e10cSrcweir     class XSmartTagAction;
45cdf0e10cSrcweir } } } }
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace text {
48cdf0e10cSrcweir     class XTextMarkup;
49*bbac9d2cSJürgen Schmidt     class XTextRange;
50cdf0e10cSrcweir } } } }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace i18n {
53cdf0e10cSrcweir     class XBreakIterator;
54cdf0e10cSrcweir } } } }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace lang {
57cdf0e10cSrcweir     struct Locale;
58cdf0e10cSrcweir     struct EventObject;
59cdf0e10cSrcweir     struct ChangesEvent;
60cdf0e10cSrcweir     class XMultiServiceFactory;
61cdf0e10cSrcweir } } } }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace beans {
64cdf0e10cSrcweir     class XPropertySet;
65cdf0e10cSrcweir } } } }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace frame {
68cdf0e10cSrcweir     class XController;
69cdf0e10cSrcweir } } } }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir /** A reference to a smart tag action
72cdf0e10cSrcweir 
73cdf0e10cSrcweir      An action service can support various actions. Therefore an ActionReference
74cdf0e10cSrcweir      consists of a reference to the service and and index.
75cdf0e10cSrcweir  */
76cdf0e10cSrcweir struct ActionReference
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > mxSmartTagAction;
79cdf0e10cSrcweir     sal_Int32 mnSmartTagIndex;
ActionReferenceActionReference80cdf0e10cSrcweir     ActionReference( com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > xSmartTagAction, sal_Int32 nSmartTagIndex )
81cdf0e10cSrcweir         : mxSmartTagAction( xSmartTagAction), mnSmartTagIndex( nSmartTagIndex ) {}
82cdf0e10cSrcweir };
83cdf0e10cSrcweir 
84cdf0e10cSrcweir /** The smart tag manager maintains all installed action and recognizer services
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     This class organizes the available smarttag libraries and provides access functions
87cdf0e10cSrcweir     to these libraries. The smart tag manager is a singleton.
88cdf0e10cSrcweir */
89cdf0e10cSrcweir class SVX_DLLPUBLIC SmartTagMgr : public cppu::WeakImplHelper2< ::com::sun::star::util::XModifyListener,
90cdf0e10cSrcweir                                                                 ::com::sun::star::util::XChangesListener >
91cdf0e10cSrcweir {
92cdf0e10cSrcweir private:
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     const rtl::OUString maApplicationName;
95cdf0e10cSrcweir     std::vector< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagRecognizer > > maRecognizerList;
96cdf0e10cSrcweir     std::vector< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > > maActionList;
97cdf0e10cSrcweir     std::set< rtl::OUString > maDisabledSmartTagTypes;
98cdf0e10cSrcweir     std::multimap < rtl::OUString, ActionReference > maSmartTagMap;
99cdf0e10cSrcweir 	mutable com::sun::star::uno::Reference< com::sun::star::i18n::XBreakIterator > mxBreakIter;
100cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF;
101cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext> mxContext;
102cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > mxConfigurationSettings;
103cdf0e10cSrcweir     bool mbLabelTextWithSmartTags;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     /** Checks for installed smart tag recognizers/actions and stores them in
106cdf0e10cSrcweir         maRecognizerList and maActionList.
107cdf0e10cSrcweir     */
108cdf0e10cSrcweir     void LoadLibraries();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     /** Prepare configuration access.
111cdf0e10cSrcweir     */
112cdf0e10cSrcweir     void PrepareConfiguration( const rtl::OUString& rConfigurationGroupName );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     /** Reads the configuration data.
115cdf0e10cSrcweir     */
116cdf0e10cSrcweir     void ReadConfiguration( bool bExcludedTypes, bool bRecognize );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     /** Registeres the smart tag manager as listener at the package manager.
119cdf0e10cSrcweir     */
120cdf0e10cSrcweir     void RegisterListener();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     /** Sets up a map that maps smart tag type names to actions references.
123cdf0e10cSrcweir     */
124cdf0e10cSrcweir     void AssociateActionsWithRecognizers();
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     void CreateBreakIterator() const;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir public:
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     SmartTagMgr( const rtl::OUString& rApplicationName );
131cdf0e10cSrcweir     virtual ~SmartTagMgr();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     /** Triggeres configuration reading, library loading and listener registration
134cdf0e10cSrcweir         NOTE: MUST BE CALLED AFTER CONSTRUCTION!
135cdf0e10cSrcweir     */
136cdf0e10cSrcweir     void Init( const rtl::OUString& rConfigurationGroupName );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     /** Dispatches the recognize call to all installed smart tag recognizers
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         @param rText
141cdf0e10cSrcweir             The string to be scanned by the recognizers.
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         @param xMarkup
144cdf0e10cSrcweir             The object allows the recognizers to store any found smart tags.
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         @param xController
147cdf0e10cSrcweir                 The current controller of the document.
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         @param rLocale
150cdf0e10cSrcweir             The locale of rText.
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         @param nStart
153cdf0e10cSrcweir             The start offset of the text to be scanned in rText.
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         @param nLen
156cdf0e10cSrcweir             The length of the text to be scanned.
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     */
159*bbac9d2cSJürgen Schmidt     void RecognizeString( const rtl::OUString& rText,
160cdf0e10cSrcweir                     const com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup > xMarkup,
161cdf0e10cSrcweir                     const com::sun::star::uno::Reference< com::sun::star::frame::XController > xController,
162cdf0e10cSrcweir                     const com::sun::star::lang::Locale& rLocale,
163cdf0e10cSrcweir                     sal_uInt32 nStart, sal_uInt32 nLen ) const;
164cdf0e10cSrcweir 
165*bbac9d2cSJürgen Schmidt    void RecognizeTextRange(const com::sun::star::uno::Reference< com::sun::star::text::XTextRange> xRange,
166*bbac9d2cSJürgen Schmidt                     const com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup > xMarkup,
167*bbac9d2cSJürgen Schmidt                     const com::sun::star::uno::Reference< com::sun::star::frame::XController > xController) const;
168*bbac9d2cSJürgen Schmidt 
169*bbac9d2cSJürgen Schmidt 
170cdf0e10cSrcweir     /** Returns all action references associated with a given list of smart tag types
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         @param rSmartTagTypes
173cdf0e10cSrcweir             The list of types
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         @param rActionComponentsSequence
176cdf0e10cSrcweir             Output parameter
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         @param rActionIndicesSequence
179cdf0e10cSrcweir             Output parameter
180cdf0e10cSrcweir     */
181cdf0e10cSrcweir     void GetActionSequences( com::sun::star::uno::Sequence < rtl::OUString >& rSmartTagTypes,
182cdf0e10cSrcweir                              com::sun::star::uno::Sequence < com::sun::star::uno::Sequence< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > > >& rActionComponentsSequence,
183cdf0e10cSrcweir                              com::sun::star::uno::Sequence < com::sun::star::uno::Sequence< sal_Int32 > >& rActionIndicesSequence ) const;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     /** Returns the caption for a smart tag type.
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         @param rSmartTagType
188cdf0e10cSrcweir             The given smart tag type.
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         @param rLocale
191cdf0e10cSrcweir             The locale.
192cdf0e10cSrcweir     */
193cdf0e10cSrcweir     rtl::OUString GetSmartTagCaption( const rtl::OUString& rSmartTagType, const com::sun::star::lang::Locale& rLocale ) const;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     /** Returns true if the given smart tag type is enabled.
196cdf0e10cSrcweir     */
197cdf0e10cSrcweir     bool IsSmartTagTypeEnabled( const rtl::OUString& rSmartTagType ) const;
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     /** Enable or disable smart tags.
200cdf0e10cSrcweir     */
IsLabelTextWithSmartTags() const201cdf0e10cSrcweir     bool IsLabelTextWithSmartTags() const { return mbLabelTextWithSmartTags; }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir     /** Returns the number of registered recognizers.
204cdf0e10cSrcweir     */
NumberOfRecognizers() const205cdf0e10cSrcweir     sal_uInt32 NumberOfRecognizers() const { return maRecognizerList.size(); }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir     /** Returns a recognizer.
208cdf0e10cSrcweir     */
209cdf0e10cSrcweir     com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagRecognizer >
GetRecognizer(sal_uInt32 i) const210cdf0e10cSrcweir         GetRecognizer( sal_uInt32 i ) const  { return maRecognizerList[i]; }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     /** Is smart tag recognization active?
213cdf0e10cSrcweir     */
IsSmartTagsEnabled() const214cdf0e10cSrcweir     bool IsSmartTagsEnabled() const { return 0 != NumberOfRecognizers() &&
215cdf0e10cSrcweir                                       IsLabelTextWithSmartTags(); }
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     /** Writes configuration settings.
218cdf0e10cSrcweir     */
219cdf0e10cSrcweir     void WriteConfiguration( const bool* bLabelTextWithSmartTags,
220cdf0e10cSrcweir                              const std::vector< rtl::OUString >* pDisabledTypes ) const;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     /** Returns the name of the application this instance has been created by.
223cdf0e10cSrcweir     */
GetApplicationName() const224cdf0e10cSrcweir     const rtl::OUString GetApplicationName() const { return maApplicationName; }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     // ::com::sun::star::lang::XEventListener
227cdf0e10cSrcweir     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     // ::com::sun::star::util::XModifyListener
230cdf0e10cSrcweir     virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw(::com::sun::star::uno::RuntimeException);
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     // ::com::sun::star::util::XChangesListener
233cdf0e10cSrcweir   	virtual void SAL_CALL changesOccurred( const ::com::sun::star::util::ChangesEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
234cdf0e10cSrcweir };
235cdf0e10cSrcweir 
236cdf0e10cSrcweir #endif
237