LCOV - code coverage report
Current view: top level - framework/source/uielement - fontmenucontroller.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 107 23.4 %
Date: 2012-08-25 Functions: 11 19 57.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 21 208 10.1 %

           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                 :            : #include <uielement/fontmenucontroller.hxx>
      30                 :            : 
      31                 :            : #include <threadhelp/resetableguard.hxx>
      32                 :            : #include "services.h"
      33                 :            : 
      34                 :            : #include <com/sun/star/awt/XDevice.hpp>
      35                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      36                 :            : #include <com/sun/star/awt/MenuItemStyle.hpp>
      37                 :            : #include <com/sun/star/frame/XDispatchProvider.hpp>
      38                 :            : 
      39                 :            : #include <vcl/menu.hxx>
      40                 :            : #include <vcl/svapp.hxx>
      41                 :            : #include <vcl/i18nhelp.hxx>
      42                 :            : #include <tools/urlobj.hxx>
      43                 :            : #include <rtl/ustrbuf.hxx>
      44                 :            : #include <vcl/mnemonic.hxx>
      45                 :            : #include <osl/mutex.hxx>
      46                 :            : 
      47                 :            : //_________________________________________________________________________________________________________________
      48                 :            : //  Defines
      49                 :            : //_________________________________________________________________________________________________________________
      50                 :            : 
      51                 :            : using namespace com::sun::star::uno;
      52                 :            : using namespace com::sun::star::lang;
      53                 :            : using namespace com::sun::star::frame;
      54                 :            : using namespace com::sun::star::beans;
      55                 :            : using namespace com::sun::star::util;
      56                 :            : 
      57                 :            : using namespace std;
      58                 :            : 
      59                 :          0 : bool lcl_I18nCompareString(const rtl::OUString& rStr1, const rtl::OUString& rStr2)
      60                 :            : {
      61                 :          0 :     const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
      62                 :          0 :     return rI18nHelper.CompareString( rStr1, rStr2 ) < 0 ? true : false;
      63                 :            : }
      64                 :            : 
      65                 :            : namespace framework
      66                 :            : {
      67                 :            : 
      68 [ +  - ][ +  - ]:         36 : DEFINE_XSERVICEINFO_MULTISERVICE        (   FontMenuController                      ,
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
                 [ #  # ]
      69                 :            :                                             OWeakObject                             ,
      70                 :            :                                             SERVICENAME_POPUPMENUCONTROLLER         ,
      71                 :            :                                             IMPLEMENTATIONNAME_FONTMENUCONTROLLER
      72                 :            :                                         )
      73                 :            : 
      74                 :          4 : DEFINE_INIT_SERVICE                     (   FontMenuController, {} )
      75                 :            : 
      76                 :          4 : FontMenuController::FontMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
      77                 :          4 :     svt::PopupMenuControllerBase( xServiceManager )
      78                 :            : {
      79                 :          4 : }
      80                 :            : 
      81                 :          4 : FontMenuController::~FontMenuController()
      82                 :            : {
      83         [ -  + ]:          8 : }
      84                 :            : 
      85                 :            : // private function
      86                 :          0 : void FontMenuController::fillPopupMenu( const Sequence< ::rtl::OUString >& rFontNameSeq, Reference< css::awt::XPopupMenu >& rPopupMenu )
      87                 :            : {
      88                 :          0 :     const rtl::OUString*    pFontNameArray = rFontNameSeq.getConstArray();
      89                 :          0 :     VCLXPopupMenu*          pPopupMenu = (VCLXPopupMenu *)VCLXMenu::GetImplementation( rPopupMenu );
      90                 :          0 :     PopupMenu*              pVCLPopupMenu = 0;
      91                 :            : 
      92         [ #  # ]:          0 :     SolarMutexGuard aSolarMutexGuard;
      93                 :            : 
      94         [ #  # ]:          0 :     resetPopupMenu( rPopupMenu );
      95         [ #  # ]:          0 :     if ( pPopupMenu )
      96                 :          0 :         pVCLPopupMenu = (PopupMenu *)pPopupMenu->GetMenu();
      97                 :            : 
      98         [ #  # ]:          0 :     if ( pVCLPopupMenu )
      99                 :            :     {
     100         [ #  # ]:          0 :         vector<rtl::OUString> aVector;
     101         [ #  # ]:          0 :         aVector.reserve(rFontNameSeq.getLength());
     102         [ #  # ]:          0 :         for ( sal_uInt16 i = 0; i < rFontNameSeq.getLength(); i++ )
     103                 :            :         {
     104 [ #  # ][ #  # ]:          0 :             aVector.push_back(MnemonicGenerator::EraseAllMnemonicChars(pFontNameArray[i]));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     105                 :            :         }
     106         [ #  # ]:          0 :         sort(aVector.begin(), aVector.end(), lcl_I18nCompareString );
     107                 :            : 
     108                 :          0 :         const rtl::OUString aFontNameCommandPrefix( ".uno:CharFontName?CharFontName.FamilyName:string=" );
     109                 :          0 :         const sal_Int16 nCount = (sal_Int16)aVector.size();
     110         [ #  # ]:          0 :         for ( sal_Int16 i = 0; i < nCount; i++ )
     111                 :            :         {
     112                 :          0 :             const rtl::OUString& rName = aVector[i];
     113 [ #  # ][ #  # ]:          0 :             m_xPopupMenu->insertItem( i+1, rName, css::awt::MenuItemStyle::RADIOCHECK | css::awt::MenuItemStyle::AUTOCHECK, i );
     114         [ #  # ]:          0 :             if ( rName == m_aFontFamilyName )
     115 [ #  # ][ #  # ]:          0 :                 m_xPopupMenu->checkItem( i+1, sal_True );
     116                 :            :             // use VCL popup menu pointer to set vital information that are not part of the awt implementation
     117         [ #  # ]:          0 :             rtl::OUStringBuffer aCommandBuffer( aFontNameCommandPrefix );
     118 [ #  # ][ #  # ]:          0 :             aCommandBuffer.append( INetURLObject::encode( rName, INetURLObject::PART_HTTP_QUERY, '%', INetURLObject::ENCODE_ALL ));
     119         [ #  # ]:          0 :             rtl::OUString aFontNameCommand = aCommandBuffer.makeStringAndClear();
     120 [ #  # ][ #  # ]:          0 :             pVCLPopupMenu->SetItemCommand( i+1, aFontNameCommand ); // Store font name into item command.
                 [ #  # ]
     121                 :          0 :         }
     122                 :            : 
     123         [ #  # ]:          0 :     }
     124                 :          0 : }
     125                 :            : 
     126                 :            : // XEventListener
     127                 :          0 : void SAL_CALL FontMenuController::disposing( const EventObject& ) throw ( RuntimeException )
     128                 :            : {
     129         [ #  # ]:          0 :     Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
     130                 :            : 
     131         [ #  # ]:          0 :     osl::MutexGuard aLock( m_aMutex );
     132                 :          0 :     m_xFrame.clear();
     133                 :          0 :     m_xDispatch.clear();
     134                 :          0 :     m_xFontListDispatch.clear();
     135                 :          0 :     m_xServiceManager.clear();
     136                 :            : 
     137         [ #  # ]:          0 :     if ( m_xPopupMenu.is() )
     138 [ #  # ][ #  # ]:          0 :         m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
                 [ #  # ]
     139         [ #  # ]:          0 :     m_xPopupMenu.clear();
     140                 :          0 : }
     141                 :            : 
     142                 :            : // XStatusListener
     143                 :          2 : void SAL_CALL FontMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
     144                 :            : {
     145                 :          2 :     com::sun::star::awt::FontDescriptor aFontDescriptor;
     146         [ +  - ]:          2 :     Sequence< rtl::OUString >           aFontNameSeq;
     147                 :            : 
     148 [ +  - ][ -  + ]:          2 :     if ( Event.State >>= aFontDescriptor )
     149                 :            :     {
     150         [ #  # ]:          0 :         osl::MutexGuard aLock( m_aMutex );
     151         [ #  # ]:          0 :         m_aFontFamilyName = aFontDescriptor.Name;
     152                 :            :     }
     153 [ +  - ][ -  + ]:          2 :     else if ( Event.State >>= aFontNameSeq )
     154                 :            :     {
     155         [ #  # ]:          0 :         osl::MutexGuard aLock( m_aMutex );
     156         [ #  # ]:          0 :         if ( m_xPopupMenu.is() )
     157 [ #  # ][ #  # ]:          0 :             fillPopupMenu( aFontNameSeq, m_xPopupMenu );
     158         [ +  - ]:          2 :     }
     159                 :          2 : }
     160                 :            : 
     161                 :            : // XMenuListener
     162                 :          0 : void FontMenuController::impl_select(const Reference< XDispatch >& _xDispatch,const ::com::sun::star::util::URL& aTargetURL)
     163                 :            : {
     164         [ #  # ]:          0 :     Sequence<PropertyValue>      aArgs;
     165                 :            :     OSL_ENSURE(_xDispatch.is(),"FontMenuController::impl_select: No dispatch");
     166         [ #  # ]:          0 :     if ( _xDispatch.is() )
     167 [ #  # ][ #  # ]:          0 :         _xDispatch->dispatch( aTargetURL, aArgs );
                 [ #  # ]
     168                 :          0 : }
     169                 :            : 
     170                 :          0 : void SAL_CALL FontMenuController::activate( const css::awt::MenuEvent& ) throw (RuntimeException)
     171                 :            : {
     172         [ #  # ]:          0 :     osl::MutexGuard aLock( m_aMutex );
     173                 :            : 
     174         [ #  # ]:          0 :     if ( m_xPopupMenu.is() )
     175                 :            :     {
     176                 :            :         // find new font name and set check mark!
     177                 :          0 :         sal_uInt16        nChecked = 0;
     178 [ #  # ][ #  # ]:          0 :         sal_uInt16        nItemCount = m_xPopupMenu->getItemCount();
     179                 :          0 :         rtl::OUString aEmpty;
     180         [ #  # ]:          0 :         for( sal_uInt16 i = 0; i < nItemCount; i++ )
     181                 :            :         {
     182 [ #  # ][ #  # ]:          0 :             sal_uInt16 nItemId = m_xPopupMenu->getItemId( i );
     183                 :            : 
     184 [ #  # ][ #  # ]:          0 :             if ( m_xPopupMenu->isItemChecked( nItemId ) )
                 [ #  # ]
     185                 :          0 :                 nChecked = nItemId;
     186                 :            : 
     187 [ #  # ][ #  # ]:          0 :             rtl::OUString aText = m_xPopupMenu->getItemText( nItemId );
     188                 :            : 
     189                 :            :             // TODO: must be replaced by implementation of VCL, when available
     190                 :          0 :             sal_Int32 nIndex = aText.indexOf( (sal_Unicode)'~' );
     191         [ #  # ]:          0 :             if ( nIndex >= 0 )
     192                 :          0 :                 aText = aText.replaceAt( nIndex, 1, aEmpty );
     193                 :            :             // TODO: must be replaced by implementation of VCL, when available
     194                 :            : 
     195         [ #  # ]:          0 :             if ( aText == m_aFontFamilyName )
     196                 :            :             {
     197 [ #  # ][ #  # ]:          0 :                 m_xPopupMenu->checkItem( nItemId, sal_True );
     198                 :          0 :                 return;
     199                 :            :             }
     200         [ #  # ]:          0 :         }
     201                 :            : 
     202         [ #  # ]:          0 :         if ( nChecked )
     203 [ #  # ][ #  # ]:          0 :             m_xPopupMenu->checkItem( nChecked, sal_False );
                 [ #  # ]
     204 [ #  # ][ #  # ]:          0 :     }
     205                 :            : }
     206                 :            : 
     207                 :            : // XPopupMenuController
     208                 :          0 : void FontMenuController::impl_setPopupMenu()
     209                 :            : {
     210         [ #  # ]:          0 :     Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
     211                 :            : 
     212                 :          0 :     com::sun::star::util::URL aTargetURL;
     213                 :            :     // Register for font list updates to get the current font list from the controller
     214                 :          0 :     aTargetURL.Complete = rtl::OUString( ".uno:FontNameList" );
     215 [ #  # ][ #  # ]:          0 :     m_xURLTransformer->parseStrict( aTargetURL );
     216 [ #  # ][ #  # ]:          0 :     m_xFontListDispatch = xDispatchProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
                 [ #  # ]
     217                 :          0 : }
     218                 :            : 
     219                 :          2 : void SAL_CALL FontMenuController::updatePopupMenu() throw ( ::com::sun::star::uno::RuntimeException )
     220                 :            : {
     221         [ +  - ]:          2 :     svt::PopupMenuControllerBase::updatePopupMenu();
     222                 :            : 
     223         [ +  - ]:          2 :     osl::ClearableMutexGuard aLock( m_aMutex );
     224                 :          2 :     Reference< XDispatch > xDispatch( m_xFontListDispatch );
     225                 :          2 :     com::sun::star::util::URL aTargetURL;
     226                 :          2 :     aTargetURL.Complete = rtl::OUString( ".uno:FontNameList" );
     227 [ +  - ][ +  - ]:          2 :     m_xURLTransformer->parseStrict( aTargetURL );
     228         [ +  - ]:          2 :     aLock.clear();
     229                 :            : 
     230         [ -  + ]:          2 :     if ( xDispatch.is() )
     231                 :            :     {
     232 [ #  # ][ #  # ]:          0 :         xDispatch->addStatusListener( (static_cast< XStatusListener* >(this)), aTargetURL );
                 [ #  # ]
     233 [ #  # ][ #  # ]:          0 :         xDispatch->removeStatusListener( (static_cast< XStatusListener* >(this)), aTargetURL );
                 [ #  # ]
     234         [ +  - ]:          2 :     }
     235                 :          2 : }
     236                 :            : 
     237                 :            : }
     238                 :            : 
     239                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10