LCOV - code coverage report
Current view: top level - include/svx - SmartTagMgr.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 9 0.0 %
Date: 2014-04-14 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      20             : #ifndef INCLUDED_SVX_SMARTTAGMGR_HXX
      21             : #define INCLUDED_SVX_SMARTTAGMGR_HXX
      22             : 
      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>
      29             : 
      30             : #include <vector>
      31             : #include <map>
      32             : #include <set>
      33             : 
      34             : namespace com { namespace sun { namespace star { namespace uno {
      35             :     class XComponentContext;
      36             : } } } }
      37             : 
      38             : namespace com { namespace sun { namespace star { namespace smarttags {
      39             :     class XSmartTagRecognizer;
      40             :     class XSmartTagAction;
      41             : } } } }
      42             : 
      43             : namespace com { namespace sun { namespace star { namespace text {
      44             :     class XTextMarkup;
      45             :     class XTextRange;
      46             : } } } }
      47             : 
      48             : namespace com { namespace sun { namespace star { namespace i18n {
      49             :     class XBreakIterator;
      50             : } } } }
      51             : 
      52             : namespace com { namespace sun { namespace star { namespace lang {
      53             :     struct Locale;
      54             :     struct EventObject;
      55             :     struct ChangesEvent;
      56             : } } } }
      57             : 
      58             : namespace com { namespace sun { namespace star { namespace beans {
      59             :     class XPropertySet;
      60             : } } } }
      61             : 
      62             : namespace com { namespace sun { namespace star { namespace frame {
      63             :     class XController;
      64             : } } } }
      65             : 
      66             : /** A reference to a smart tag action
      67             : 
      68             :      An action service can support various actions. Therefore an ActionReference
      69             :      consists of a reference to the service and and index.
      70             :  */
      71           0 : struct ActionReference
      72             : {
      73             :     com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > mxSmartTagAction;
      74             :     sal_Int32 mnSmartTagIndex;
      75           0 :     ActionReference( com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > xSmartTagAction, sal_Int32 nSmartTagIndex )
      76           0 :         : mxSmartTagAction( xSmartTagAction), mnSmartTagIndex( nSmartTagIndex ) {}
      77             : };
      78             : 
      79             : /** The smart tag manager maintains all installed action and recognizer services
      80             : 
      81             :     This class organizes the available smarttag libraries and provides access functions
      82             :     to these libraries. The smart tag manager is a singleton.
      83             : */
      84             : class SVX_DLLPUBLIC SmartTagMgr : public cppu::WeakImplHelper2< ::com::sun::star::util::XModifyListener,
      85             :                                                                 ::com::sun::star::util::XChangesListener >
      86             : {
      87             : private:
      88             : 
      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;
      98             : 
      99             :     /** Checks for installed smart tag recognizers/actions and stores them in
     100             :         maRecognizerList and maActionList.
     101             :     */
     102             :     void LoadLibraries();
     103             : 
     104             :     /** Prepare configuration access.
     105             :     */
     106             :     void PrepareConfiguration( const OUString& rConfigurationGroupName );
     107             : 
     108             :     /** Reads the configuration data.
     109             :     */
     110             :     void ReadConfiguration( bool bExcludedTypes, bool bRecognize );
     111             : 
     112             :     /** Registeres the smart tag manager as listener at the package manager.
     113             :     */
     114             :     void RegisterListener();
     115             : 
     116             :     /** Sets up a map that maps smart tag type names to actions references.
     117             :     */
     118             :     void AssociateActionsWithRecognizers();
     119             : 
     120             :     void CreateBreakIterator() const;
     121             : 
     122             : public:
     123             : 
     124             :     SmartTagMgr( const OUString& rApplicationName );
     125             :     virtual ~SmartTagMgr();
     126             : 
     127             :     /** Triggeres configuration reading, library loading and listener registration
     128             :         NOTE: MUST BE CALLED AFTER CONSTRUCTION!
     129             :     */
     130             :     void Init( const OUString& rConfigurationGroupName );
     131             : 
     132             :     /** Dispatches the recognize call to all installed smart tag recognizers
     133             : 
     134             :         @param rText
     135             :             The string to be scanned by the recognizers.
     136             : 
     137             :         @param xMarkup
     138             :             The object allows the recognizers to store any found smart tags.
     139             : 
     140             :         @param xController
     141             :                 The current controller of the document.
     142             : 
     143             :         @param rLocale
     144             :             The locale of rText.
     145             : 
     146             :         @param nStart
     147             :             The start offset of the text to be scanned in rText.
     148             : 
     149             :         @param nLen
     150             :             The length of the text to be scanned.
     151             : 
     152             :     */
     153             : 
     154             :     void RecognizeString( const OUString& rText,
     155             :                     const com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup > xMarkup,
     156             :                     const com::sun::star::uno::Reference< com::sun::star::frame::XController > xController,
     157             :                     const com::sun::star::lang::Locale& rLocale,
     158             :                     sal_uInt32 nStart, sal_uInt32 nLen ) const;
     159             : 
     160             :     void RecognizeTextRange(const com::sun::star::uno::Reference< com::sun::star::text::XTextRange> xRange,
     161             :                     const com::sun::star::uno::Reference< com::sun::star::text::XTextMarkup > xMarkup,
     162             :                     const com::sun::star::uno::Reference< com::sun::star::frame::XController > xController) const;
     163             : 
     164             :     /** Returns all action references associated with a given list of smart tag types
     165             : 
     166             :         @param rSmartTagTypes
     167             :             The list of types
     168             : 
     169             :         @param rActionComponentsSequence
     170             :             Output parameter
     171             : 
     172             :         @param rActionIndicesSequence
     173             :             Output parameter
     174             :     */
     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;
     178             : 
     179             :     /** Returns the caption for a smart tag type.
     180             : 
     181             :         @param rSmartTagType
     182             :             The given smart tag type.
     183             : 
     184             :         @param rLocale
     185             :             The locale.
     186             :     */
     187             :     OUString GetSmartTagCaption( const OUString& rSmartTagType, const com::sun::star::lang::Locale& rLocale ) const;
     188             : 
     189             :     /** Returns true if the given smart tag type is enabled.
     190             :     */
     191             :     bool IsSmartTagTypeEnabled( const OUString& rSmartTagType ) const;
     192             : 
     193             :     /** Enable or disable smart tags.
     194             :     */
     195           0 :     bool IsLabelTextWithSmartTags() const { return mbLabelTextWithSmartTags; }
     196             : 
     197             :     /** Returns the number of registered recognizers.
     198             :     */
     199           0 :     sal_uInt32 NumberOfRecognizers() const { return maRecognizerList.size(); }
     200             : 
     201             :     /** Returns a recognizer.
     202             :     */
     203             :     com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagRecognizer >
     204           0 :         GetRecognizer( sal_uInt32 i ) const  { return maRecognizerList[i]; }
     205             : 
     206             :     /** Is smart tag recognition active?
     207             :     */
     208           0 :     bool IsSmartTagsEnabled() const { return 0 != NumberOfRecognizers() &&
     209           0 :                                       IsLabelTextWithSmartTags(); }
     210             : 
     211             :     /** Writes configuration settings.
     212             :     */
     213             :     void WriteConfiguration( const bool* bLabelTextWithSmartTags,
     214             :                              const std::vector< OUString >* pDisabledTypes ) const;
     215             : 
     216             :     /** Returns the name of the application this instance has been created by.
     217             :     */
     218           0 :     const OUString GetApplicationName() const { return maApplicationName; }
     219             : 
     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;
     222             : 
     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;
     225             : 
     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;
     228             : };
     229             : 
     230             : #endif
     231             : 
     232             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10