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

Generated by: LCOV version 1.10