LCOV - code coverage report
Current view: top level - framework/inc/helper - mischelper.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 82 0.0 %
Date: 2014-04-14 Functions: 0 21 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_FRAMEWORK_INC_HELPER_MISCHELPER_HXX
      21             : #define INCLUDED_FRAMEWORK_INC_HELPER_MISCHELPER_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             : #include <com/sun/star/uno/XComponentContext.hpp>
      31             : 
      32             : #include <cppuhelper/implbase1.hxx>
      33             : 
      34             : #include <i18nlangtag/lang.h>
      35             : #include <svl/languageoptions.hxx>
      36             : #include <rtl/ustring.hxx>
      37             : #include <fwidllapi.h>
      38             : 
      39             : #include <set>
      40             : 
      41             : class SvtLanguageTable;
      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             : namespace framework
      49             : {
      50             : 
      51             : // menu ids for language status bar control
      52             : enum LangMenuIDs
      53             : {
      54             :     MID_LANG_SEL_1 = 1,     // need to start with 1 since xPopupMenu->execute will return 0 if the menu is cancelled
      55             :     MID_LANG_SEL_2,
      56             :     MID_LANG_SEL_3,
      57             :     MID_LANG_SEL_4,
      58             :     MID_LANG_SEL_5,
      59             :     MID_LANG_SEL_6,
      60             :     MID_LANG_SEL_7,
      61             :     MID_LANG_SEL_8,
      62             :     MID_LANG_SEL_9,
      63             :     MID_LANG_SEL_NONE,
      64             :     MID_LANG_SEL_RESET,
      65             :     MID_LANG_SEL_MORE,
      66             : 
      67             :     MID_LANG_PARA_SEPARATOR,
      68             :     MID_LANG_PARA_STRING,
      69             : 
      70             :     MID_LANG_PARA_1,
      71             :     MID_LANG_PARA_2,
      72             :     MID_LANG_PARA_3,
      73             :     MID_LANG_PARA_4,
      74             :     MID_LANG_PARA_5,
      75             :     MID_LANG_PARA_6,
      76             :     MID_LANG_PARA_7,
      77             :     MID_LANG_PARA_8,
      78             :     MID_LANG_PARA_9,
      79             :     MID_LANG_PARA_NONE,
      80             :     MID_LANG_PARA_RESET,
      81             :     MID_LANG_PARA_MORE,
      82             : };
      83             : 
      84           0 : inline bool IsScriptTypeMatchingToLanguage( sal_Int16 nScriptType, LanguageType nLang )
      85             : {
      86           0 :     return 0 != (nScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ));
      87             : }
      88             : 
      89           0 : inline void RetrieveTypeNameFromResourceURL( const OUString& aResourceURL, OUString& aType, OUString& aName )
      90             : {
      91           0 :     const sal_Int32 RESOURCEURL_PREFIX_SIZE = 17;
      92           0 :     const char      RESOURCEURL_PREFIX[] = "private:resource/";
      93             : 
      94           0 :     if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) &&
      95           0 :         ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
      96             :     {
      97           0 :         OUString aTmpStr( aResourceURL.copy( RESOURCEURL_PREFIX_SIZE ));
      98           0 :         sal_Int32 nToken = 0;
      99           0 :         sal_Int32 nPart  = 0;
     100           0 :         do
     101             :         {
     102           0 :             OUString sToken = aTmpStr.getToken( 0, '/', nToken);
     103           0 :             if ( !sToken.isEmpty() )
     104             :             {
     105           0 :                 if ( nPart == 0 )
     106           0 :                     aType = sToken;
     107           0 :                 else if ( nPart == 1 )
     108           0 :                     aName = sToken;
     109             :                 else
     110           0 :                     break;
     111           0 :                 nPart++;
     112           0 :             }
     113             :         }
     114           0 :         while( nToken >=0 );
     115             :     }
     116           0 : }
     117             : 
     118           0 : class FWI_DLLPUBLIC LanguageGuessingHelper
     119             : {
     120             :     mutable ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing >    m_xLanguageGuesser;
     121             :     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
     122             : 
     123             : public:
     124           0 :     LanguageGuessingHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _xContext) : m_xContext(_xContext){}
     125             : 
     126             :     ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing >  GetGuesser() const;
     127             : };
     128             : 
     129             : FWI_DLLPUBLIC OUString RetrieveLabelFromCommand( const OUString& aCmdURL
     130             :             ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&    _xContext
     131             :             ,::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >&        _xUICommandLabels
     132             :             ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame
     133             :             ,OUString& _rModuleIdentifier
     134             :             ,bool& _rIni
     135             :             ,const sal_Char* _pName);
     136             : 
     137             : FWI_DLLPUBLIC void FillLangItems( std::set< OUString > &rLangItems,
     138             :         const SvtLanguageTable &rLanguageTable,
     139             :         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame,
     140             :         const LanguageGuessingHelper & rLangGuessHelper,
     141             :         sal_Int16               nScriptType,
     142             :         const OUString & rCurLang,
     143             :         const OUString & rKeyboardLang,
     144             :         const OUString & rGuessedTextLang );
     145             : 
     146             : //It's common for an object to want to create and own a Broadcaster and set
     147             : //itself as a Listener on its own Broadcaster member.
     148             : 
     149             : //However, calling addListener on a Broadcaster means that the Broadcaster adds
     150             : //a reference to the Listener leading to an ownership cycle where the Listener
     151             : //owns the Broadcaster which "owns" the Listener.
     152             : 
     153             : //The WeakContainerListener allows breaking this cycle and retrofitting
     154             : //afflicted implentations fairly easily.
     155             : 
     156             : //OriginalListener owns the Broadcaster which "owns" the WeakContainerListener
     157             : //which forwards the events to the OriginalListener without taking ownership of
     158             : //it.
     159             : class WeakContainerListener : public ::cppu::WeakImplHelper1<com::sun::star::container::XContainerListener>
     160             : {
     161             :     private:
     162             :         com::sun::star::uno::WeakReference<com::sun::star::container::XContainerListener> mxOwner;
     163             : 
     164             :     public:
     165           0 :         WeakContainerListener(com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner)
     166           0 :             : mxOwner(xOwner)
     167             :         {
     168           0 :         }
     169             : 
     170           0 :         virtual ~WeakContainerListener()
     171           0 :         {
     172           0 :         }
     173             : 
     174             :         // container.XContainerListener
     175           0 :         virtual void SAL_CALL elementInserted(const com::sun::star::container::ContainerEvent& rEvent)
     176             :             throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     177             :         {
     178             :             com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
     179           0 :                 com::sun::star::uno::UNO_QUERY);
     180           0 :             if (xOwner.is())
     181           0 :                 xOwner->elementInserted(rEvent);
     182           0 :         }
     183             : 
     184           0 :         virtual void SAL_CALL elementRemoved(const com::sun::star::container::ContainerEvent& rEvent)
     185             :             throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     186             :         {
     187             :             com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
     188           0 :                 com::sun::star::uno::UNO_QUERY);
     189           0 :             if (xOwner.is())
     190           0 :                 xOwner->elementRemoved(rEvent);
     191           0 :         }
     192             : 
     193           0 :         virtual void SAL_CALL elementReplaced(const com::sun::star::container::ContainerEvent& rEvent)
     194             :             throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     195             :         {
     196             :             com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
     197           0 :                 com::sun::star::uno::UNO_QUERY);
     198           0 :             if (xOwner.is())
     199           0 :                 xOwner->elementReplaced(rEvent);
     200           0 :         }
     201             : 
     202             :         // lang.XEventListener
     203           0 :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     204             :             throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     205             :         {
     206             :             com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> xOwner(mxOwner.get(),
     207           0 :                 com::sun::star::uno::UNO_QUERY);
     208           0 :             if (xOwner.is())
     209           0 :                 xOwner->disposing(rEvent);
     210             : 
     211           0 :         }
     212             : };
     213             : 
     214             : class WeakChangesListener : public ::cppu::WeakImplHelper1<com::sun::star::util::XChangesListener>
     215             : {
     216             :     private:
     217             :         com::sun::star::uno::WeakReference<com::sun::star::util::XChangesListener> mxOwner;
     218             : 
     219             :     public:
     220           0 :         WeakChangesListener(com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner)
     221           0 :             : mxOwner(xOwner)
     222             :         {
     223           0 :         }
     224             : 
     225           0 :         virtual ~WeakChangesListener()
     226           0 :         {
     227           0 :         }
     228             : 
     229             :         // util.XChangesListener
     230           0 :         virtual void SAL_CALL changesOccurred(const com::sun::star::util::ChangesEvent& rEvent)
     231             :             throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     232             :         {
     233             :             com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner(mxOwner.get(),
     234           0 :                 com::sun::star::uno::UNO_QUERY);
     235           0 :             if (xOwner.is())
     236           0 :                 xOwner->changesOccurred(rEvent);
     237           0 :         }
     238             : 
     239             :         // lang.XEventListener
     240           0 :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     241             :             throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     242             :         {
     243             :             com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner(mxOwner.get(),
     244           0 :                 com::sun::star::uno::UNO_QUERY);
     245           0 :             if (xOwner.is())
     246           0 :                 xOwner->disposing(rEvent);
     247             : 
     248           0 :         }
     249             : };
     250             : 
     251             : class WeakEventListener : public ::cppu::WeakImplHelper1<com::sun::star::lang::XEventListener>
     252             : {
     253             :     private:
     254             :         com::sun::star::uno::WeakReference<com::sun::star::lang::XEventListener> mxOwner;
     255             : 
     256             :     public:
     257             :         WeakEventListener(com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xOwner)
     258             :             : mxOwner(xOwner)
     259             :         {
     260             :         }
     261             : 
     262             :         virtual ~WeakEventListener()
     263             :         {
     264             :         }
     265             : 
     266             :         // lang.XEventListener
     267             :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     268             :             throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     269             :         {
     270             :             com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xOwner(mxOwner.get(),
     271             :                 com::sun::star::uno::UNO_QUERY);
     272             :             if (xOwner.is())
     273             :                 xOwner->disposing(rEvent);
     274             : 
     275             :         }
     276             : };
     277             : 
     278             : class WeakDocumentEventListener : public ::cppu::WeakImplHelper1<com::sun::star::document::XEventListener>
     279             : {
     280             :     private:
     281             :         com::sun::star::uno::WeakReference<com::sun::star::document::XEventListener> mxOwner;
     282             : 
     283             :     public:
     284           0 :         WeakDocumentEventListener(com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner)
     285           0 :             : mxOwner(xOwner)
     286             :         {
     287           0 :         }
     288             : 
     289           0 :         virtual ~WeakDocumentEventListener()
     290           0 :         {
     291           0 :         }
     292             : 
     293           0 :         virtual void SAL_CALL notifyEvent(const com::sun::star::document::EventObject& rEvent)
     294             :             throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     295             :         {
     296             :             com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner(mxOwner.get(),
     297           0 :                 com::sun::star::uno::UNO_QUERY);
     298           0 :             if (xOwner.is())
     299           0 :                 xOwner->notifyEvent(rEvent);
     300             : 
     301           0 :         }
     302             : 
     303             :         // lang.XEventListener
     304           0 :         virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
     305             :             throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
     306             :         {
     307             :             com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner(mxOwner.get(),
     308           0 :                 com::sun::star::uno::UNO_QUERY);
     309           0 :             if (xOwner.is())
     310           0 :                 xOwner->disposing(rEvent);
     311             : 
     312           0 :         }
     313             : };
     314             : 
     315             : } // namespace framework
     316             : 
     317             : #endif // INCLUDED_FRAMEWORK_INC_HELPER_MISCHELPER_HXX
     318             : 
     319             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10