LCOV - code coverage report
Current view: top level - framework/inc/helper - mischelper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 20 70 28.6 %
Date: 2012-08-25 Functions: 11 23 47.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 9 112 8.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef __MISC_HELPER_HXX_
      30                 :            : #define __MISC_HELPER_HXX_
      31                 :            : 
      32                 :            : #include <com/sun/star/linguistic2/XLanguageGuessing.hpp>
      33                 :            : #include <com/sun/star/container/XNameAccess.hpp>
      34                 :            : #include <com/sun/star/document/XEventListener.hpp>
      35                 :            : #include <com/sun/star/lang/XEventListener.hpp>
      36                 :            : #include <com/sun/star/util/XChangesListener.hpp>
      37                 :            : #include <com/sun/star/container/XContainerListener.hpp>
      38                 :            : #include <com/sun/star/frame/XFrame.hpp>
      39                 :            : 
      40                 :            : #include <cppuhelper/implbase1.hxx>
      41                 :            : 
      42                 :            : #include <i18npool/lang.h>
      43                 :            : #include <svl/languageoptions.hxx>
      44                 :            : #include <rtl/ustring.hxx>
      45                 :            : #include <fwidllapi.h>
      46                 :            : 
      47                 :            : #include <set>
      48                 :            : 
      49                 :            : class SvtLanguageTable;
      50                 :            : 
      51                 :            : 
      52                 :            : // flags for script types in use within selection
      53                 :            : #define LS_SCRIPT_LATIN     0x0001
      54                 :            : #define LS_SCRIPT_ASIAN     0x0002
      55                 :            : #define LS_SCRIPT_COMPLEX   0x0004
      56                 :            : 
      57                 :            : 
      58                 :            : namespace framework
      59                 :            : {
      60                 :            : 
      61                 :            : // menu ids for language status bar control
      62                 :            : enum LangMenuIDs
      63                 :            : {
      64                 :            :     MID_LANG_SEL_1 = 1,     // need to start with 1 since xPopupMenu->execute will return 0 if the menu is cancelled
      65                 :            :     MID_LANG_SEL_2,
      66                 :            :     MID_LANG_SEL_3,
      67                 :            :     MID_LANG_SEL_4,
      68                 :            :     MID_LANG_SEL_5,
      69                 :            :     MID_LANG_SEL_6,
      70                 :            :     MID_LANG_SEL_7,
      71                 :            :     MID_LANG_SEL_8,
      72                 :            :     MID_LANG_SEL_9,
      73                 :            :     MID_LANG_SEL_NONE,
      74                 :            :     MID_LANG_SEL_RESET,
      75                 :            :     MID_LANG_SEL_MORE,
      76                 :            : 
      77                 :            :     MID_LANG_PARA_SEPERATOR,
      78                 :            :     MID_LANG_PARA_STRING,
      79                 :            : 
      80                 :            :     MID_LANG_PARA_1,
      81                 :            :     MID_LANG_PARA_2,
      82                 :            :     MID_LANG_PARA_3,
      83                 :            :     MID_LANG_PARA_4,
      84                 :            :     MID_LANG_PARA_5,
      85                 :            :     MID_LANG_PARA_6,
      86                 :            :     MID_LANG_PARA_7,
      87                 :            :     MID_LANG_PARA_8,
      88                 :            :     MID_LANG_PARA_9,
      89                 :            :     MID_LANG_PARA_NONE,
      90                 :            :     MID_LANG_PARA_RESET,
      91                 :            :     MID_LANG_PARA_MORE,
      92                 :            : };
      93                 :            : 
      94                 :            : 
      95                 :          0 : inline bool IsScriptTypeMatchingToLanguage( sal_Int16 nScriptType, LanguageType nLang )
      96                 :            : {
      97                 :          0 :     return 0 != (nScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ));
      98                 :            : }
      99                 :            : 
     100                 :            : 
     101                 :        764 : class FWI_DLLPUBLIC LanguageGuessingHelper
     102                 :            : {
     103                 :            :     mutable ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing >    m_xLanguageGuesser;
     104                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
     105                 :            : 
     106                 :            : public:
     107                 :        764 :     LanguageGuessingHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xServiceManager) : m_xServiceManager(_xServiceManager){}
     108                 :            : 
     109                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing >  GetGuesser() const;
     110                 :            : };
     111                 :            : 
     112                 :            : FWI_DLLPUBLIC ::rtl::OUString RetrieveLabelFromCommand( const ::rtl::OUString& aCmdURL
     113                 :            :             ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&    _xServiceFactory
     114                 :            :             ,::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >&        _xUICommandLabels
     115                 :            :             ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame
     116                 :            :             ,::rtl::OUString& _rModuleIdentifier
     117                 :            :             ,sal_Bool& _rIni
     118                 :            :             ,const sal_Char* _pName);
     119                 :            : 
     120                 :            : FWI_DLLPUBLIC void FillLangItems( std::set< ::rtl::OUString > &rLangItems,
     121                 :            :         const SvtLanguageTable &rLanguageTable,
     122                 :            :         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame,
     123                 :            :         const LanguageGuessingHelper & rLangGuessHelper,
     124                 :            :         sal_Int16               nScriptType,
     125                 :            :         const ::rtl::OUString & rCurLang,
     126                 :            :         const ::rtl::OUString & rKeyboardLang,
     127                 :            :         const ::rtl::OUString & rGuessedTextLang );
     128                 :            : 
     129                 :            : //It's common for an object to want to create and own a Broadcaster and set
     130                 :            : //itself as a Listener on its own Broadcaster member.
     131                 :            : //
     132                 :            : //However, calling addListener on a Broadcaster means that the Broadcaster adds
     133                 :            : //a reference to the Listener leading to an ownership cycle where the Listener
     134                 :            : //owns the Broadcaster which "owns" the Listener.
     135                 :            : //
     136                 :            : //The WeakContainerListener allows breaking this cycle and retrofitting
     137                 :            : //afflicted implentations fairly easily.
     138                 :            : //
     139                 :            : //OriginalListener owns the Broadcaster which "owns" the WeakContainerListener
     140                 :            : //which forwards the events to the OriginalListener without taking ownership of
     141                 :            : //it.
     142                 :            : class WeakContainerListener : public ::cppu::WeakImplHelper1<com::sun::star::container::XContainerListener>
     143                 :            : {
     144                 :            :     private:
     145                 :            :         com::sun::star::uno::WeakReference<com::sun::star::container::XContainerListener> mxOwner;
     146                 :            : 
     147                 :            :     public:
     148                 :        956 :         WeakContainerListener(com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner)
     149         [ +  - ]:        956 :             : mxOwner(xOwner)
     150                 :            :         {
     151                 :        956 :         }
     152                 :            : 
     153                 :       1872 :         virtual ~WeakContainerListener()
     154         [ +  - ]:        936 :         {
     155         [ -  + ]:       1872 :         }
     156                 :            : 
     157                 :            :         // container.XContainerListener
     158                 :          0 :         virtual void SAL_CALL elementInserted(const com::sun::star::container::ContainerEvent& rEvent)
     159                 :            :             throw(com::sun::star::uno::RuntimeException)
     160                 :            :         {
     161                 :            :             com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
     162 [ #  # ][ #  # ]:          0 :                 com::sun::star::uno::UNO_QUERY);
     163         [ #  # ]:          0 :             if (xOwner.is())
     164 [ #  # ][ #  # ]:          0 :                 xOwner->elementInserted(rEvent);
     165                 :          0 :         }
     166                 :            : 
     167                 :          0 :         virtual void SAL_CALL elementRemoved(const com::sun::star::container::ContainerEvent& rEvent)
     168                 :            :             throw(com::sun::star::uno::RuntimeException)
     169                 :            :         {
     170                 :            :             com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
     171 [ #  # ][ #  # ]:          0 :                 com::sun::star::uno::UNO_QUERY);
     172         [ #  # ]:          0 :             if (xOwner.is())
     173 [ #  # ][ #  # ]:          0 :                 xOwner->elementRemoved(rEvent);
     174                 :          0 :         }
     175                 :            : 
     176                 :          0 :         virtual void SAL_CALL elementReplaced(const com::sun::star::container::ContainerEvent& rEvent)
     177                 :            :             throw(com::sun::star::uno::RuntimeException)
     178                 :            :         {
     179                 :            :             com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
     180 [ #  # ][ #  # ]:          0 :                 com::sun::star::uno::UNO_QUERY);
     181         [ #  # ]:          0 :             if (xOwner.is())
     182 [ #  # ][ #  # ]:          0 :                 xOwner->elementReplaced(rEvent);
     183                 :          0 :         }
     184                 :            : 
     185                 :            :         // lang.XEventListener
     186                 :          0 :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     187                 :            :             throw(com::sun::star::uno::RuntimeException)
     188                 :            :         {
     189                 :            :             com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
     190 [ #  # ][ #  # ]:          0 :                 com::sun::star::uno::UNO_QUERY);
     191         [ #  # ]:          0 :             if (xOwner.is())
     192 [ #  # ][ #  # ]:          0 :                 xOwner->disposing(rEvent);
     193                 :            : 
     194                 :          0 :         }
     195                 :            : };
     196                 :            : 
     197                 :            : class WeakChangesListener : public ::cppu::WeakImplHelper1<com::sun::star::util::XChangesListener>
     198                 :            : {
     199                 :            :     private:
     200                 :            :         com::sun::star::uno::WeakReference<com::sun::star::util::XChangesListener> mxOwner;
     201                 :            : 
     202                 :            :     public:
     203                 :       2979 :         WeakChangesListener(com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner)
     204         [ +  - ]:       2979 :             : mxOwner(xOwner)
     205                 :            :         {
     206                 :       2979 :         }
     207                 :            : 
     208                 :       5958 :         virtual ~WeakChangesListener()
     209         [ +  - ]:       2979 :         {
     210         [ -  + ]:       5958 :         }
     211                 :            : 
     212                 :            :         // util.XChangesListener
     213                 :          0 :         virtual void SAL_CALL changesOccurred(const com::sun::star::util::ChangesEvent& rEvent)
     214                 :            :             throw(com::sun::star::uno::RuntimeException)
     215                 :            :         {
     216                 :            :             com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner(mxOwner.get(),
     217 [ #  # ][ #  # ]:          0 :                 com::sun::star::uno::UNO_QUERY);
     218         [ #  # ]:          0 :             if (xOwner.is())
     219 [ #  # ][ #  # ]:          0 :                 xOwner->changesOccurred(rEvent);
     220                 :          0 :         }
     221                 :            : 
     222                 :            :         // lang.XEventListener
     223                 :          0 :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     224                 :            :             throw(com::sun::star::uno::RuntimeException)
     225                 :            :         {
     226                 :            :             com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner(mxOwner.get(),
     227 [ #  # ][ #  # ]:          0 :                 com::sun::star::uno::UNO_QUERY);
     228         [ #  # ]:          0 :             if (xOwner.is())
     229 [ #  # ][ #  # ]:          0 :                 xOwner->disposing(rEvent);
     230                 :            : 
     231                 :          0 :         }
     232                 :            : };
     233                 :            : 
     234                 :            : class WeakEventListener : public ::cppu::WeakImplHelper1<com::sun::star::lang::XEventListener>
     235                 :            : {
     236                 :            :     private:
     237                 :            :         com::sun::star::uno::WeakReference<com::sun::star::lang::XEventListener> mxOwner;
     238                 :            : 
     239                 :            :     public:
     240                 :            :         WeakEventListener(com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xOwner)
     241                 :            :             : mxOwner(xOwner)
     242                 :            :         {
     243                 :            :         }
     244                 :            : 
     245                 :          0 :         virtual ~WeakEventListener()
     246         [ #  # ]:          0 :         {
     247         [ #  # ]:          0 :         }
     248                 :            : 
     249                 :            :         // lang.XEventListener
     250                 :          0 :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     251                 :            :             throw(com::sun::star::uno::RuntimeException)
     252                 :            :         {
     253                 :            :             com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xOwner(mxOwner.get(),
     254 [ #  # ][ #  # ]:          0 :                 com::sun::star::uno::UNO_QUERY);
     255         [ #  # ]:          0 :             if (xOwner.is())
     256 [ #  # ][ #  # ]:          0 :                 xOwner->disposing(rEvent);
     257                 :            : 
     258                 :          0 :         }
     259                 :            : };
     260                 :            : 
     261                 :            : class WeakDocumentEventListener : public ::cppu::WeakImplHelper1<com::sun::star::document::XEventListener>
     262                 :            : {
     263                 :            :     private:
     264                 :            :         com::sun::star::uno::WeakReference<com::sun::star::document::XEventListener> mxOwner;
     265                 :            : 
     266                 :            :     public:
     267                 :         96 :         WeakDocumentEventListener(com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner)
     268         [ +  - ]:         96 :             : mxOwner(xOwner)
     269                 :            :         {
     270                 :         96 :         }
     271                 :            : 
     272                 :        192 :         virtual ~WeakDocumentEventListener()
     273         [ +  - ]:         96 :         {
     274         [ -  + ]:        192 :         }
     275                 :            : 
     276                 :          0 :         virtual void SAL_CALL notifyEvent(const com::sun::star::document::EventObject& rEvent)
     277                 :            :             throw(com::sun::star::uno::RuntimeException)
     278                 :            :         {
     279                 :            :             com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner(mxOwner.get(),
     280 [ #  # ][ #  # ]:          0 :                 com::sun::star::uno::UNO_QUERY);
     281         [ #  # ]:          0 :             if (xOwner.is())
     282 [ #  # ][ #  # ]:          0 :                 xOwner->notifyEvent(rEvent);
     283                 :            : 
     284                 :          0 :         }
     285                 :            : 
     286                 :            :         // lang.XEventListener
     287                 :          0 :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     288                 :            :             throw(com::sun::star::uno::RuntimeException)
     289                 :            :         {
     290                 :            :             com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner(mxOwner.get(),
     291 [ #  # ][ #  # ]:          0 :                 com::sun::star::uno::UNO_QUERY);
     292         [ #  # ]:          0 :             if (xOwner.is())
     293 [ #  # ][ #  # ]:          0 :                 xOwner->disposing(rEvent);
     294                 :            : 
     295                 :          0 :         }
     296                 :            : };
     297                 :            : 
     298                 :            : 
     299                 :            : } // namespace framework
     300                 :            : 
     301                 :            : #endif // __MISC_HELPER_HXX_
     302                 :            : 
     303                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10