LCOV - code coverage report
Current view: top level - svtools/source/control - stdmenu.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 121 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 14 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             : #include <string.h>
      21             : #include <vcl/svapp.hxx>
      22             : #include <vcl/settings.hxx>
      23             : #include <vcl/i18nhelp.hxx>
      24             : #include <svtools/ctrltool.hxx>
      25             : #include <svtools/stdmenu.hxx>
      26             : 
      27           0 : FontNameMenu::FontNameMenu()
      28             : {
      29           0 :     SetMenuFlags( GetMenuFlags() | MenuFlags::NoAutoMnemonics );
      30           0 : }
      31             : 
      32           0 : FontNameMenu::~FontNameMenu()
      33             : {
      34           0 : }
      35             : 
      36           0 : void FontNameMenu::Select()
      37             : {
      38           0 :     maCurName = GetItemText( GetCurItemId() );
      39           0 :     maSelectHdl.Call( this );
      40           0 : }
      41             : 
      42           0 : void FontNameMenu::Highlight()
      43             : {
      44           0 :     OUString aTempName = maCurName;
      45           0 :     maCurName = GetItemText( GetCurItemId() );
      46           0 :     maHighlightHdl.Call( this );
      47           0 :     maCurName = aTempName;
      48           0 : }
      49             : 
      50           0 : void FontNameMenu::Fill( const FontList* pList )
      51             : {
      52             :     // clear menu
      53           0 :     Clear();
      54             : 
      55             :     // add fonts
      56           0 :     if (pList)
      57             :     {
      58           0 :         const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
      59             :         // more than 100 fonts reduces the speed of opening the menu.
      60             :         // So only the first 100 fonts will be displayed.
      61           0 :         sal_uInt16 nFontCount = ::std::min( pList->GetFontNameCount(), static_cast< sal_uInt16 >(100) );
      62           0 :         for (sal_uInt16 i = 0; i < nFontCount; ++i)
      63             :         {
      64           0 :             const OUString& rName = pList->GetFontName( i ).GetName();
      65             : 
      66             :             // sort with the I18nHelper
      67           0 :             sal_uInt16 j = GetItemCount();
      68           0 :             while ( j )
      69             :             {
      70           0 :                 OUString aText = GetItemText( GetItemId( j-1 ) );
      71           0 :                 if ( rI18nHelper.CompareString( rName, aText ) > 0 )
      72           0 :                     break;
      73           0 :                 j--;
      74           0 :             }
      75           0 :             InsertItem( i+1, rName, MenuItemBits::RADIOCHECK | MenuItemBits::AUTOCHECK, OString(), j );
      76             :         }
      77             :     }
      78             : 
      79           0 :     SetCurName( maCurName );
      80           0 : }
      81             : 
      82           0 : void FontNameMenu::SetCurName(const OUString& rName)
      83             : {
      84           0 :     maCurName = rName;
      85             : 
      86             :     // check menu entry
      87           0 :     sal_uInt16 nChecked = 0;
      88           0 :     sal_uInt16 nItemCount = GetItemCount();
      89           0 :     for( sal_uInt16 i = 0; i < nItemCount; i++ )
      90             :     {
      91           0 :         sal_uInt16 nItemId = GetItemId( i );
      92             : 
      93           0 :         if ( IsItemChecked( nItemId ) )
      94           0 :             nChecked = nItemId;
      95             : 
      96           0 :         OUString aText = GetItemText( nItemId );
      97           0 :         if ( aText == maCurName )
      98             :         {
      99           0 :             CheckItem( nItemId, true );
     100           0 :             return;
     101             :         }
     102           0 :     }
     103             : 
     104           0 :     if ( nChecked )
     105           0 :         CheckItem( nChecked, false );
     106             : }
     107             : 
     108           0 : FontSizeMenu::FontSizeMenu()
     109             : :    mpHeightAry( NULL )
     110           0 : ,    mnCurHeight( 100 )
     111             : {
     112           0 :     SetMenuFlags( GetMenuFlags() | MenuFlags::NoAutoMnemonics );
     113           0 : }
     114             : 
     115           0 : FontSizeMenu::~FontSizeMenu()
     116             : {
     117           0 :     if ( mpHeightAry )
     118           0 :         delete[] mpHeightAry;
     119           0 : }
     120             : 
     121           0 : void FontSizeMenu::Select()
     122             : {
     123           0 :     const sal_uInt16 nCurItemId = GetCurItemId();
     124           0 :     mnCurHeight = mpHeightAry[ nCurItemId - 1 ];
     125           0 :     maSelectHdl.Call( this );
     126           0 : }
     127             : 
     128           0 : void FontSizeMenu::Highlight()
     129             : {
     130           0 :     const long nTempHeight = mnCurHeight;
     131           0 :     const sal_uInt16 nCurItemId = GetCurItemId();
     132           0 :     if ( !nCurItemId )
     133           0 :         mnCurHeight = 0;
     134             :     else
     135             :     {
     136             :         //sal_Int32 nValue = GetItemText( nCurItemId ).ToInt32();
     137           0 :         mnCurHeight = mpHeightAry[ nCurItemId - 1 ];
     138             :     }
     139           0 :     maHighlightHdl.Call( this );
     140           0 :     mnCurHeight = nTempHeight;
     141           0 : }
     142             : 
     143           0 : void FontSizeMenu::Fill( const vcl::FontInfo& rInfo, const FontList* pList )
     144             : {
     145           0 :     Clear();
     146             : 
     147             :     // setup font size array
     148           0 :     if ( mpHeightAry )
     149           0 :         delete[] mpHeightAry;
     150             : 
     151             :     const sal_IntPtr* pTempAry;
     152           0 :     const sal_IntPtr* pAry = pList->GetSizeAry( rInfo );
     153           0 :     sal_uInt16 nSizeCount = 0;
     154           0 :     while ( pAry[nSizeCount] )
     155           0 :         nSizeCount++;
     156             : 
     157           0 :     sal_uInt16 nPos = 0;
     158             : 
     159             :     // first insert font size names (for simplified/traditional chinese)
     160           0 :     FontSizeNames aFontSizeNames( Application::GetSettings().GetUILanguageTag().getLanguageType() );
     161           0 :     mpHeightAry = new long[nSizeCount+aFontSizeNames.Count()];
     162           0 :     if ( !aFontSizeNames.IsEmpty() )
     163             :     {
     164           0 :         if ( pAry == FontList::GetStdSizeAry() )
     165             :         {
     166             :             // for scalable fonts all font size names
     167           0 :             sal_uLong nCount = aFontSizeNames.Count();
     168           0 :             for( sal_uLong i = 0; i < nCount; i++ )
     169             :             {
     170           0 :                 OUString  aSizeName = aFontSizeNames.GetIndexName( i );
     171           0 :                 long      nSize = aFontSizeNames.GetIndexSize( i );
     172           0 :                 mpHeightAry[nPos] = nSize;
     173           0 :                 nPos++; // Id is nPos+1
     174           0 :                 InsertItem( nPos, aSizeName, MenuItemBits::RADIOCHECK | MenuItemBits::AUTOCHECK );
     175           0 :             }
     176             :         }
     177             :         else
     178             :         {
     179             :             // for fixed size fonts only selectable font size names
     180           0 :             pTempAry = pAry;
     181           0 :             while ( *pTempAry )
     182             :             {
     183           0 :                 OUString aSizeName = aFontSizeNames.Size2Name( *pTempAry );
     184           0 :                 if ( !aSizeName.isEmpty() )
     185             :                 {
     186           0 :                     mpHeightAry[nPos] = *pTempAry;
     187           0 :                     nPos++; // Id is nPos+1
     188           0 :                     InsertItem( nPos, aSizeName, MenuItemBits::RADIOCHECK | MenuItemBits::AUTOCHECK );
     189             :                 }
     190           0 :                 pTempAry++;
     191           0 :             }
     192             :         }
     193             :     }
     194             : 
     195             :     // then insert numerical font size values
     196           0 :     const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
     197           0 :     pTempAry = pAry;
     198           0 :     while ( *pTempAry )
     199             :     {
     200           0 :         mpHeightAry[nPos] = *pTempAry;
     201           0 :         nPos++; // Id is nPos+1
     202           0 :         InsertItem( nPos, rI18nHelper.GetNum( *pTempAry, 1, true, false ), MenuItemBits::RADIOCHECK | MenuItemBits::AUTOCHECK );
     203           0 :         pTempAry++;
     204             :     }
     205             : 
     206           0 :     SetCurHeight( mnCurHeight );
     207           0 : }
     208             : 
     209           0 : void FontSizeMenu::SetCurHeight( long nHeight )
     210             : {
     211           0 :     mnCurHeight = nHeight;
     212             : 
     213             :     // check menu item
     214           0 :     sal_uInt16      nChecked = 0;
     215           0 :     sal_uInt16      nItemCount = GetItemCount();
     216           0 :     for( sal_uInt16 i = 0; i < nItemCount; i++ )
     217             :     {
     218           0 :         sal_uInt16 nItemId = GetItemId( i );
     219             : 
     220           0 :         if ( mpHeightAry[i] == nHeight )
     221             :         {
     222           0 :             CheckItem( nItemId, true );
     223           0 :             return;
     224             :         }
     225             : 
     226           0 :         if ( IsItemChecked( nItemId ) )
     227           0 :             nChecked = nItemId;
     228             :     }
     229             : 
     230           0 :     if ( nChecked )
     231           0 :         CheckItem( nChecked, false );
     232             : }
     233             : 
     234             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11