LCOV - code coverage report
Current view: top level - svtools/source/control - stdmenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 120 0.0 %
Date: 2012-08-25 Functions: 0 14 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 172 0.0 %

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

Generated by: LCOV version 1.10