LCOV - code coverage report
Current view: top level - libreoffice/framework/inc/helper - mischelper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 12 70 17.1 %
Date: 2012-12-27 Functions: 6 23 26.1 %
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 __MISC_HELPER_HXX_
      21             : #define __MISC_HELPER_HXX_
      22             : 
      23             : #include <com/sun/star/linguistic2/XLanguageGuessing.hpp>
      24             : #include <com/sun/star/container/XNameAccess.hpp>
      25             : #include <com/sun/star/document/XEventListener.hpp>
      26             : #include <com/sun/star/lang/XEventListener.hpp>
      27             : #include <com/sun/star/util/XChangesListener.hpp>
      28             : #include <com/sun/star/container/XContainerListener.hpp>
      29             : #include <com/sun/star/frame/XFrame.hpp>
      30             : 
      31             : #include <cppuhelper/implbase1.hxx>
      32             : 
      33             : #include <i18npool/lang.h>
      34             : #include <svl/languageoptions.hxx>
      35             : #include <rtl/ustring.hxx>
      36             : #include <fwidllapi.h>
      37             : 
      38             : #include <set>
      39             : 
      40             : class SvtLanguageTable;
      41             : 
      42             : 
      43             : // flags for script types in use within selection
      44             : #define LS_SCRIPT_LATIN     0x0001
      45             : #define LS_SCRIPT_ASIAN     0x0002
      46             : #define LS_SCRIPT_COMPLEX   0x0004
      47             : 
      48             : 
      49             : namespace framework
      50             : {
      51             : 
      52             : // menu ids for language status bar control
      53             : enum LangMenuIDs
      54             : {
      55             :     MID_LANG_SEL_1 = 1,     // need to start with 1 since xPopupMenu->execute will return 0 if the menu is cancelled
      56             :     MID_LANG_SEL_2,
      57             :     MID_LANG_SEL_3,
      58             :     MID_LANG_SEL_4,
      59             :     MID_LANG_SEL_5,
      60             :     MID_LANG_SEL_6,
      61             :     MID_LANG_SEL_7,
      62             :     MID_LANG_SEL_8,
      63             :     MID_LANG_SEL_9,
      64             :     MID_LANG_SEL_NONE,
      65             :     MID_LANG_SEL_RESET,
      66             :     MID_LANG_SEL_MORE,
      67             : 
      68             :     MID_LANG_PARA_SEPERATOR,
      69             :     MID_LANG_PARA_STRING,
      70             : 
      71             :     MID_LANG_PARA_1,
      72             :     MID_LANG_PARA_2,
      73             :     MID_LANG_PARA_3,
      74             :     MID_LANG_PARA_4,
      75             :     MID_LANG_PARA_5,
      76             :     MID_LANG_PARA_6,
      77             :     MID_LANG_PARA_7,
      78             :     MID_LANG_PARA_8,
      79             :     MID_LANG_PARA_9,
      80             :     MID_LANG_PARA_NONE,
      81             :     MID_LANG_PARA_RESET,
      82             :     MID_LANG_PARA_MORE,
      83             : };
      84             : 
      85             : 
      86           0 : inline bool IsScriptTypeMatchingToLanguage( sal_Int16 nScriptType, LanguageType nLang )
      87             : {
      88           0 :     return 0 != (nScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ));
      89             : }
      90             : 
      91             : 
      92           0 : class FWI_DLLPUBLIC LanguageGuessingHelper
      93             : {
      94             :     mutable ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing >    m_xLanguageGuesser;
      95             :     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
      96             : 
      97             : public:
      98           0 :     LanguageGuessingHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xServiceManager) : m_xServiceManager(_xServiceManager){}
      99             : 
     100             :     ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing >  GetGuesser() const;
     101             : };
     102             : 
     103             : FWI_DLLPUBLIC ::rtl::OUString RetrieveLabelFromCommand( const ::rtl::OUString& aCmdURL
     104             :             ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&    _xContext
     105             :             ,::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >&        _xUICommandLabels
     106             :             ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame
     107             :             ,::rtl::OUString& _rModuleIdentifier
     108             :             ,sal_Bool& _rIni
     109             :             ,const sal_Char* _pName);
     110             : 
     111             : FWI_DLLPUBLIC void FillLangItems( std::set< ::rtl::OUString > &rLangItems,
     112             :         const SvtLanguageTable &rLanguageTable,
     113             :         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame,
     114             :         const LanguageGuessingHelper & rLangGuessHelper,
     115             :         sal_Int16               nScriptType,
     116             :         const ::rtl::OUString & rCurLang,
     117             :         const ::rtl::OUString & rKeyboardLang,
     118             :         const ::rtl::OUString & rGuessedTextLang );
     119             : 
     120             : //It's common for an object to want to create and own a Broadcaster and set
     121             : //itself as a Listener on its own Broadcaster member.
     122             : //
     123             : //However, calling addListener on a Broadcaster means that the Broadcaster adds
     124             : //a reference to the Listener leading to an ownership cycle where the Listener
     125             : //owns the Broadcaster which "owns" the Listener.
     126             : //
     127             : //The WeakContainerListener allows breaking this cycle and retrofitting
     128             : //afflicted implentations fairly easily.
     129             : //
     130             : //OriginalListener owns the Broadcaster which "owns" the WeakContainerListener
     131             : //which forwards the events to the OriginalListener without taking ownership of
     132             : //it.
     133             : class WeakContainerListener : public ::cppu::WeakImplHelper1<com::sun::star::container::XContainerListener>
     134             : {
     135             :     private:
     136             :         com::sun::star::uno::WeakReference<com::sun::star::container::XContainerListener> mxOwner;
     137             : 
     138             :     public:
     139          42 :         WeakContainerListener(com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner)
     140          42 :             : mxOwner(xOwner)
     141             :         {
     142          42 :         }
     143             : 
     144          10 :         virtual ~WeakContainerListener()
     145           5 :         {
     146          10 :         }
     147             : 
     148             :         // container.XContainerListener
     149           0 :         virtual void SAL_CALL elementInserted(const com::sun::star::container::ContainerEvent& rEvent)
     150             :             throw(com::sun::star::uno::RuntimeException)
     151             :         {
     152             :             com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
     153           0 :                 com::sun::star::uno::UNO_QUERY);
     154           0 :             if (xOwner.is())
     155           0 :                 xOwner->elementInserted(rEvent);
     156           0 :         }
     157             : 
     158           0 :         virtual void SAL_CALL elementRemoved(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->elementRemoved(rEvent);
     165           0 :         }
     166             : 
     167           0 :         virtual void SAL_CALL elementReplaced(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->elementReplaced(rEvent);
     174           0 :         }
     175             : 
     176             :         // lang.XEventListener
     177           0 :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     178             :             throw(com::sun::star::uno::RuntimeException)
     179             :         {
     180             :             com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
     181           0 :                 com::sun::star::uno::UNO_QUERY);
     182           0 :             if (xOwner.is())
     183           0 :                 xOwner->disposing(rEvent);
     184             : 
     185           0 :         }
     186             : };
     187             : 
     188             : class WeakChangesListener : public ::cppu::WeakImplHelper1<com::sun::star::util::XChangesListener>
     189             : {
     190             :     private:
     191             :         com::sun::star::uno::WeakReference<com::sun::star::util::XChangesListener> mxOwner;
     192             : 
     193             :     public:
     194          19 :         WeakChangesListener(com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner)
     195          19 :             : mxOwner(xOwner)
     196             :         {
     197          19 :         }
     198             : 
     199          38 :         virtual ~WeakChangesListener()
     200          19 :         {
     201          38 :         }
     202             : 
     203             :         // util.XChangesListener
     204           0 :         virtual void SAL_CALL changesOccurred(const com::sun::star::util::ChangesEvent& rEvent)
     205             :             throw(com::sun::star::uno::RuntimeException)
     206             :         {
     207             :             com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner(mxOwner.get(),
     208           0 :                 com::sun::star::uno::UNO_QUERY);
     209           0 :             if (xOwner.is())
     210           0 :                 xOwner->changesOccurred(rEvent);
     211           0 :         }
     212             : 
     213             :         // lang.XEventListener
     214           0 :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     215             :             throw(com::sun::star::uno::RuntimeException)
     216             :         {
     217             :             com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner(mxOwner.get(),
     218           0 :                 com::sun::star::uno::UNO_QUERY);
     219           0 :             if (xOwner.is())
     220           0 :                 xOwner->disposing(rEvent);
     221             : 
     222           0 :         }
     223             : };
     224             : 
     225             : class WeakEventListener : public ::cppu::WeakImplHelper1<com::sun::star::lang::XEventListener>
     226             : {
     227             :     private:
     228             :         com::sun::star::uno::WeakReference<com::sun::star::lang::XEventListener> mxOwner;
     229             : 
     230             :     public:
     231             :         WeakEventListener(com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xOwner)
     232             :             : mxOwner(xOwner)
     233             :         {
     234             :         }
     235             : 
     236           0 :         virtual ~WeakEventListener()
     237           0 :         {
     238           0 :         }
     239             : 
     240             :         // lang.XEventListener
     241           0 :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     242             :             throw(com::sun::star::uno::RuntimeException)
     243             :         {
     244             :             com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xOwner(mxOwner.get(),
     245           0 :                 com::sun::star::uno::UNO_QUERY);
     246           0 :             if (xOwner.is())
     247           0 :                 xOwner->disposing(rEvent);
     248             : 
     249           0 :         }
     250             : };
     251             : 
     252             : class WeakDocumentEventListener : public ::cppu::WeakImplHelper1<com::sun::star::document::XEventListener>
     253             : {
     254             :     private:
     255             :         com::sun::star::uno::WeakReference<com::sun::star::document::XEventListener> mxOwner;
     256             : 
     257             :     public:
     258           0 :         WeakDocumentEventListener(com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner)
     259           0 :             : mxOwner(xOwner)
     260             :         {
     261           0 :         }
     262             : 
     263           0 :         virtual ~WeakDocumentEventListener()
     264           0 :         {
     265           0 :         }
     266             : 
     267           0 :         virtual void SAL_CALL notifyEvent(const com::sun::star::document::EventObject& rEvent)
     268             :             throw(com::sun::star::uno::RuntimeException)
     269             :         {
     270             :             com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner(mxOwner.get(),
     271           0 :                 com::sun::star::uno::UNO_QUERY);
     272           0 :             if (xOwner.is())
     273           0 :                 xOwner->notifyEvent(rEvent);
     274             : 
     275           0 :         }
     276             : 
     277             :         // lang.XEventListener
     278           0 :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     279             :             throw(com::sun::star::uno::RuntimeException)
     280             :         {
     281             :             com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner(mxOwner.get(),
     282           0 :                 com::sun::star::uno::UNO_QUERY);
     283           0 :             if (xOwner.is())
     284           0 :                 xOwner->disposing(rEvent);
     285             : 
     286           0 :         }
     287             : };
     288             : 
     289             : 
     290             : } // namespace framework
     291             : 
     292             : #endif // __MISC_HELPER_HXX_
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10