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

Generated by: LCOV version 1.10