LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/svx - SmartTagMgr.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 6 50.0 %
Date: 2012-08-25 Functions: 2 5 40.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 4 25.0 %

           Branch data     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                 :            :     class XMultiServiceFactory;
      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                 :            : struct ActionReference
      72                 :            : {
      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 ) {}
      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 rtl::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< rtl::OUString > maDisabledSmartTagTypes;
      93                 :            :     std::multimap < rtl::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::lang::XMultiServiceFactory > mxMSF;
      96                 :            :     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext> mxContext;
      97                 :            :     com::sun::star::uno::Reference< com::sun::star::beans::XPropertySet > mxConfigurationSettings;
      98                 :            :     bool mbLabelTextWithSmartTags;
      99                 :            : 
     100                 :            :     /** Checks for installed smart tag recognizers/actions and stores them in
     101                 :            :         maRecognizerList and maActionList.
     102                 :            :     */
     103                 :            :     void LoadLibraries();
     104                 :            : 
     105                 :            :     /** Prepare configuration access.
     106                 :            :     */
     107                 :            :     void PrepareConfiguration( const rtl::OUString& rConfigurationGroupName );
     108                 :            : 
     109                 :            :     /** Reads the configuration data.
     110                 :            :     */
     111                 :            :     void ReadConfiguration( bool bExcludedTypes, bool bRecognize );
     112                 :            : 
     113                 :            :     /** Registeres the smart tag manager as listener at the package manager.
     114                 :            :     */
     115                 :            :     void RegisterListener();
     116                 :            : 
     117                 :            :     /** Sets up a map that maps smart tag type names to actions references.
     118                 :            :     */
     119                 :            :     void AssociateActionsWithRecognizers();
     120                 :            : 
     121                 :            :     void CreateBreakIterator() const;
     122                 :            : 
     123                 :            : public:
     124                 :            : 
     125                 :            :     SmartTagMgr( const rtl::OUString& rApplicationName );
     126                 :            :     virtual ~SmartTagMgr();
     127                 :            : 
     128                 :            :     /** Triggeres configuration reading, library loading and listener registration
     129                 :            :         NOTE: MUST BE CALLED AFTER CONSTRUCTION!
     130                 :            :     */
     131                 :            :     void Init( const rtl::OUString& rConfigurationGroupName );
     132                 :            : 
     133                 :            :     /** Dispatches the recognize call to all installed smart tag recognizers
     134                 :            : 
     135                 :            :         @param rText
     136                 :            :             The string to be scanned by the recognizers.
     137                 :            : 
     138                 :            :         @param xMarkup
     139                 :            :             The object allows the recognizers to store any found smart tags.
     140                 :            : 
     141                 :            :         @param xController
     142                 :            :                 The current controller of the document.
     143                 :            : 
     144                 :            :         @param rLocale
     145                 :            :             The locale of rText.
     146                 :            : 
     147                 :            :         @param nStart
     148                 :            :             The start offset of the text to be scanned in rText.
     149                 :            : 
     150                 :            :         @param nLen
     151                 :            :             The length of the text to be scanned.
     152                 :            : 
     153                 :            :     */
     154                 :            :     void Recognize( const rtl::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                 :            :     /** Returns all action references associated with a given list of smart tag types
     161                 :            : 
     162                 :            :         @param rSmartTagTypes
     163                 :            :             The list of types
     164                 :            : 
     165                 :            :         @param rActionComponentsSequence
     166                 :            :             Output parameter
     167                 :            : 
     168                 :            :         @param rActionIndicesSequence
     169                 :            :             Output parameter
     170                 :            :     */
     171                 :            :     void GetActionSequences( com::sun::star::uno::Sequence < rtl::OUString >& rSmartTagTypes,
     172                 :            :                              com::sun::star::uno::Sequence < com::sun::star::uno::Sequence< com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagAction > > >& rActionComponentsSequence,
     173                 :            :                              com::sun::star::uno::Sequence < com::sun::star::uno::Sequence< sal_Int32 > >& rActionIndicesSequence ) const;
     174                 :            : 
     175                 :            :     /** Returns the caption for a smart tag type.
     176                 :            : 
     177                 :            :         @param rSmartTagType
     178                 :            :             The given smart tag type.
     179                 :            : 
     180                 :            :         @param rLocale
     181                 :            :             The locale.
     182                 :            :     */
     183                 :            :     rtl::OUString GetSmartTagCaption( const rtl::OUString& rSmartTagType, const com::sun::star::lang::Locale& rLocale ) const;
     184                 :            : 
     185                 :            :     /** Returns true if the given smart tag type is enabled.
     186                 :            :     */
     187                 :            :     bool IsSmartTagTypeEnabled( const rtl::OUString& rSmartTagType ) const;
     188                 :            : 
     189                 :            :     /** Enable or disable smart tags.
     190                 :            :     */
     191                 :          0 :     bool IsLabelTextWithSmartTags() const { return mbLabelTextWithSmartTags; }
     192                 :            : 
     193                 :            :     /** Returns the number of registered recognizers.
     194                 :            :     */
     195                 :      11939 :     sal_uInt32 NumberOfRecognizers() const { return maRecognizerList.size(); }
     196                 :            : 
     197                 :            :     /** Returns a recognizer.
     198                 :            :     */
     199                 :            :     com::sun::star::uno::Reference< com::sun::star::smarttags::XSmartTagRecognizer >
     200                 :          0 :         GetRecognizer( sal_uInt32 i ) const  { return maRecognizerList[i]; }
     201                 :            : 
     202                 :            :     /** Is smart tag recognization active?
     203                 :            :     */
     204                 :      11939 :     bool IsSmartTagsEnabled() const { return 0 != NumberOfRecognizers() &&
     205 [ #  # ][ -  + ]:      11939 :                                       IsLabelTextWithSmartTags(); }
     206                 :            : 
     207                 :            :     /** Writes configuration settings.
     208                 :            :     */
     209                 :            :     void WriteConfiguration( const bool* bLabelTextWithSmartTags,
     210                 :            :                              const std::vector< rtl::OUString >* pDisabledTypes ) const;
     211                 :            : 
     212                 :            :     /** Returns the name of the application this instance has been created by.
     213                 :            :     */
     214                 :          0 :     const rtl::OUString GetApplicationName() const { return maApplicationName; }
     215                 :            : 
     216                 :            :     // ::com::sun::star::lang::XEventListener
     217                 :            :     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
     218                 :            : 
     219                 :            :     // ::com::sun::star::util::XModifyListener
     220                 :            :     virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw(::com::sun::star::uno::RuntimeException);
     221                 :            : 
     222                 :            :     // ::com::sun::star::util::XChangesListener
     223                 :            :       virtual void SAL_CALL changesOccurred( const ::com::sun::star::util::ChangesEvent& Event ) throw(::com::sun::star::uno::RuntimeException);
     224                 :            : };
     225                 :            : 
     226                 :            : #endif
     227                 :            : 
     228                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10