LCOV - code coverage report
Current view: top level - svtools/source/control - ctrlbox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 386 978 39.5 %
Date: 2012-08-25 Functions: 44 102 43.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 326 1509 21.6 %

           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                 :            : #define _CTRLBOX_CXX
      31                 :            : #include <tools/stream.hxx>
      32                 :            : #include <vcl/svapp.hxx>
      33                 :            : #include <vcl/field.hxx>
      34                 :            : #include <vcl/helper.hxx>
      35                 :            : #include <sal/macros.h>
      36                 :            : #include <comphelper/processfactory.hxx>
      37                 :            : #include <comphelper/string.hxx>
      38                 :            : #include <unotools/charclass.hxx>
      39                 :            : 
      40                 :            : #include <svtools/sampletext.hxx>
      41                 :            : #include <svtools/svtresid.hxx>
      42                 :            : #include <svtools/svtools.hrc>
      43                 :            : #include <svtools/ctrlbox.hxx>
      44                 :            : #include <svtools/ctrltool.hxx>
      45                 :            : #include <svtools/borderhelper.hxx>
      46                 :            : 
      47                 :            : #include <vcl/i18nhelp.hxx>
      48                 :            : #include <vcl/fontcapabilities.hxx>
      49                 :            : #include <basegfx/polygon/b2dpolygon.hxx>
      50                 :            : #include <basegfx/polygon/b2dpolygontools.hxx>
      51                 :            : 
      52                 :            : #include <rtl/bootstrap.hxx>
      53                 :            : 
      54                 :            : #if OSL_DEBUG_LEVEL > 1
      55                 :            : #include <cstdio>
      56                 :            : #endif
      57                 :            : 
      58                 :            : #include <stdio.h>
      59                 :            : 
      60                 :            : #define IMGINNERTEXTSPACE 2
      61                 :            : #define IMGOUTERTEXTSPACE 5
      62                 :            : #define EXTRAFONTSIZE 5
      63                 :            : #define GAPTOEXTRAPREVIEW 10
      64                 :            : #define MAXPREVIEWWIDTH 120
      65                 :            : #define MINGAPWIDTH 2
      66                 :            : 
      67                 :            : #define FONTNAMEBOXMRUENTRIESFILE "/user/config/fontnameboxmruentries"
      68                 :            : 
      69                 :            : using namespace ::com::sun::star;
      70                 :            : 
      71                 :            : // ========================================================================
      72                 :            : // ColorListBox
      73                 :            : // ========================================================================
      74                 :            : 
      75                 :            : // --------------------
      76                 :            : // - ImplColorListData -
      77                 :            : // --------------------
      78                 :            : 
      79                 :            : class ImplColorListData
      80                 :            : {
      81                 :            : public:
      82                 :            :     Color       aColor;
      83                 :            :     sal_Bool        bColor;
      84                 :            : 
      85                 :          0 :                 ImplColorListData() : aColor( COL_BLACK ) { bColor = sal_False; }
      86                 :      24808 :                 ImplColorListData( const Color& rColor ) : aColor( rColor ) { bColor = sal_True; }
      87                 :            : };
      88                 :            : 
      89                 :            : // -----------------------------------------------------------------------
      90                 :            : 
      91                 :        258 : void ColorListBox::ImplInit()
      92                 :            : {
      93         [ +  - ]:        258 :     pColorList = new ImpColorList();
      94 [ +  - ][ +  - ]:        258 :     aImageSize.Width()  = GetTextWidth( rtl::OUString("xxx") );
                 [ +  - ]
      95                 :        258 :     aImageSize.Height() = GetTextHeight();
      96                 :        258 :     aImageSize.Height() -= 2;
      97                 :            : 
      98                 :        258 :     EnableUserDraw( sal_True );
      99                 :        258 :     SetUserItemSize( aImageSize );
     100                 :        258 : }
     101                 :            : 
     102                 :            : // -----------------------------------------------------------------------
     103                 :            : 
     104                 :        377 : void ColorListBox::ImplDestroyColorEntries()
     105                 :            : {
     106         [ +  + ]:      25185 :     for ( size_t n = pColorList->size(); n; )
     107                 :      24808 :         delete (*pColorList)[ --n ];
     108                 :        377 :     pColorList->clear();
     109                 :        377 : }
     110                 :            : 
     111                 :            : // -----------------------------------------------------------------------
     112                 :            : 
     113                 :        258 : ColorListBox::ColorListBox( Window* pParent, WinBits nWinStyle ) :
     114                 :        258 :     ListBox( pParent, nWinStyle )
     115                 :            : {
     116         [ +  - ]:        258 :     ImplInit();
     117                 :        258 : }
     118                 :            : 
     119                 :            : // -----------------------------------------------------------------------
     120                 :            : 
     121                 :          0 : ColorListBox::ColorListBox( Window* pParent, const ResId& rResId ) :
     122                 :          0 :     ListBox( pParent, rResId )
     123                 :            : {
     124         [ #  # ]:          0 :     ImplInit();
     125                 :          0 : }
     126                 :            : 
     127                 :            : // -----------------------------------------------------------------------
     128                 :            : 
     129                 :        258 : ColorListBox::~ColorListBox()
     130                 :            : {
     131         [ +  - ]:        258 :     ImplDestroyColorEntries();
     132         [ +  - ]:        258 :     delete pColorList;
     133         [ -  + ]:        258 : }
     134                 :            : 
     135                 :            : // -----------------------------------------------------------------------
     136                 :            : 
     137                 :          0 : sal_uInt16 ColorListBox::InsertEntry( const XubString& rStr, sal_uInt16 nPos )
     138                 :            : {
     139                 :          0 :     nPos = ListBox::InsertEntry( rStr, nPos );
     140         [ #  # ]:          0 :     if ( nPos != LISTBOX_ERROR )
     141                 :            :     {
     142         [ #  # ]:          0 :         ImplColorListData* pData = new ImplColorListData;
     143         [ #  # ]:          0 :         if ( nPos < pColorList->size() )
     144                 :            :         {
     145                 :          0 :             ImpColorList::iterator it = pColorList->begin();
     146         [ #  # ]:          0 :             ::std::advance( it, nPos );
     147         [ #  # ]:          0 :             pColorList->insert( it, pData );
     148                 :            :         }
     149                 :            :         else
     150                 :            :         {
     151         [ #  # ]:          0 :             pColorList->push_back( pData );
     152                 :          0 :             nPos = pColorList->size() - 1;
     153                 :            :         }
     154                 :            :     }
     155                 :          0 :     return nPos;
     156                 :            : }
     157                 :            : 
     158                 :            : // -----------------------------------------------------------------------
     159                 :            : 
     160                 :      24808 : sal_uInt16 ColorListBox::InsertEntry( const Color& rColor, const XubString& rStr,
     161                 :            :                                 sal_uInt16 nPos )
     162                 :            : {
     163                 :      24808 :     nPos = ListBox::InsertEntry( rStr, nPos );
     164         [ +  - ]:      24808 :     if ( nPos != LISTBOX_ERROR )
     165                 :            :     {
     166         [ +  - ]:      24808 :         ImplColorListData* pData = new ImplColorListData( rColor );
     167         [ -  + ]:      24808 :         if ( nPos < pColorList->size() )
     168                 :            :         {
     169                 :          0 :             ImpColorList::iterator it = pColorList->begin();
     170         [ #  # ]:          0 :             ::std::advance( it, nPos );
     171         [ #  # ]:          0 :             pColorList->insert( it, pData );
     172                 :            :         }
     173                 :            :         else
     174                 :            :         {
     175         [ +  - ]:      24808 :             pColorList->push_back( pData );
     176                 :      24808 :             nPos = pColorList->size() - 1;
     177                 :            :         }
     178                 :            :     }
     179                 :      24808 :     return nPos;
     180                 :            : }
     181                 :            : 
     182                 :            : // -----------------------------------------------------------------------
     183                 :            : 
     184                 :          0 : void ColorListBox::InsertAutomaticEntryColor(const Color &rColor)
     185                 :            : {
     186                 :            :     // insert the "Automatic"-entry always on the first position
     187 [ #  # ][ #  # ]:          0 :     InsertEntry( rColor, SVT_RESSTR(STR_SVT_AUTOMATIC_COLOR), 0 );
         [ #  # ][ #  # ]
     188                 :          0 : }
     189                 :            : 
     190                 :            : // -----------------------------------------------------------------------
     191                 :            : 
     192                 :          0 : void ColorListBox::RemoveEntry( sal_uInt16 nPos )
     193                 :            : {
     194                 :          0 :     ListBox::RemoveEntry( nPos );
     195         [ #  # ]:          0 :     if ( nPos < pColorList->size() )
     196                 :            :     {
     197                 :          0 :             ImpColorList::iterator it = pColorList->begin();
     198         [ #  # ]:          0 :             ::std::advance( it, nPos );
     199                 :          0 :             delete *it;
     200         [ #  # ]:          0 :             pColorList->erase( it );
     201                 :            :     }
     202                 :          0 : }
     203                 :            : 
     204                 :            : // -----------------------------------------------------------------------
     205                 :            : 
     206                 :        119 : void ColorListBox::Clear()
     207                 :            : {
     208                 :        119 :     ImplDestroyColorEntries();
     209                 :        119 :     ListBox::Clear();
     210                 :        119 : }
     211                 :            : 
     212                 :            : // -----------------------------------------------------------------------
     213                 :            : 
     214                 :          0 : void ColorListBox::CopyEntries( const ColorListBox& rBox )
     215                 :            : {
     216                 :            :     // Liste leeren
     217                 :          0 :     ImplDestroyColorEntries();
     218                 :            : 
     219                 :            :     // Daten kopieren
     220                 :          0 :     size_t nCount = rBox.pColorList->size();
     221         [ #  # ]:          0 :     for ( size_t n = 0; n < nCount; n++ )
     222                 :            :     {
     223                 :          0 :         ImplColorListData* pData = (*rBox.pColorList)[ n ];
     224         [ #  # ]:          0 :         sal_uInt16 nPos = InsertEntry( rBox.GetEntry( n ), LISTBOX_APPEND );
     225         [ #  # ]:          0 :         if ( nPos != LISTBOX_ERROR )
     226                 :            :         {
     227         [ #  # ]:          0 :             if ( nPos < pColorList->size() )
     228                 :            :             {
     229                 :          0 :                 ImpColorList::iterator it = pColorList->begin();
     230         [ #  # ]:          0 :                 ::std::advance( it, nPos );
     231 [ #  # ][ #  # ]:          0 :                 pColorList->insert( it, new ImplColorListData( *pData ) );
     232                 :            :             }
     233                 :            :             else
     234                 :            :             {
     235         [ #  # ]:          0 :                 pColorList->push_back( new ImplColorListData( *pData ) );
     236                 :            :             }
     237                 :            :         }
     238                 :            :     }
     239                 :          0 : }
     240                 :            : 
     241                 :            : // -----------------------------------------------------------------------
     242                 :            : 
     243                 :        260 : sal_uInt16 ColorListBox::GetEntryPos( const Color& rColor ) const
     244                 :            : {
     245         [ +  + ]:      19112 :     for( sal_uInt16 n = (sal_uInt16) pColorList->size(); n; )
     246                 :            :     {
     247                 :      19104 :         ImplColorListData* pData = (*pColorList)[ --n ];
     248 [ +  + ][ +  + ]:      19104 :         if ( pData->bColor && ( pData->aColor == rColor ) )
                 [ +  - ]
     249                 :        252 :             return n;
     250                 :            :     }
     251                 :        260 :     return LISTBOX_ENTRY_NOTFOUND;
     252                 :            : }
     253                 :            : 
     254                 :            : // -----------------------------------------------------------------------
     255                 :            : 
     256                 :        288 : Color ColorListBox::GetEntryColor( sal_uInt16 nPos ) const
     257                 :            : {
     258                 :        288 :     Color aColor;
     259         [ +  - ]:        288 :     ImplColorListData* pData = ( nPos < pColorList->size() ) ? (*pColorList)[ nPos ] : NULL;
     260 [ +  - ][ +  - ]:        288 :     if ( pData && pData->bColor )
     261                 :        288 :         aColor = pData->aColor;
     262                 :        288 :     return aColor;
     263                 :            : }
     264                 :            : 
     265                 :            : // -----------------------------------------------------------------------
     266                 :            : 
     267                 :        785 : void ColorListBox::UserDraw( const UserDrawEvent& rUDEvt )
     268                 :            : {
     269                 :        785 :     size_t nPos = rUDEvt.GetItemId();
     270         [ +  + ]:        785 :     ImplColorListData* pData = ( nPos < pColorList->size() ) ? (*pColorList)[ nPos ] : NULL;
     271         [ +  + ]:        785 :     if ( pData )
     272                 :            :     {
     273         [ +  - ]:        559 :         if ( pData->bColor )
     274                 :            :         {
     275                 :        559 :             Point aPos( rUDEvt.GetRect().TopLeft() );
     276                 :        559 :             aPos.X() += 2;
     277         [ +  - ]:        559 :             aPos.Y() += ( rUDEvt.GetRect().GetHeight() - aImageSize.Height() ) / 2;
     278         [ +  - ]:        559 :             rUDEvt.GetDevice()->Push();
     279         [ +  - ]:        559 :             rUDEvt.GetDevice()->SetFillColor( pData->aColor );
     280         [ +  - ]:        559 :             rUDEvt.GetDevice()->SetLineColor( rUDEvt.GetDevice()->GetTextColor() );
     281 [ +  - ][ +  - ]:        559 :             rUDEvt.GetDevice()->DrawRect( Rectangle( aPos, aImageSize ) );
     282         [ +  - ]:        559 :             rUDEvt.GetDevice()->Pop();
     283         [ +  - ]:        559 :             ListBox::DrawEntry( rUDEvt, sal_False, sal_True, sal_False );
     284                 :            :         }
     285                 :            :         else
     286                 :          0 :             ListBox::DrawEntry( rUDEvt, sal_False, sal_True, sal_True );
     287                 :            :     }
     288                 :            :     else
     289                 :        226 :         ListBox::DrawEntry( rUDEvt, sal_True, sal_True, sal_False );
     290                 :        785 : }
     291                 :            : 
     292                 :            : // =======================================================================
     293                 :            : // LineListBox
     294                 :            : // =======================================================================
     295                 :            : 
     296                 :     108636 : BorderWidthImpl::BorderWidthImpl( sal_uInt16 nFlags, double nRate1, double nRate2, double nRateGap ):
     297                 :            :     m_nFlags( nFlags ),
     298                 :            :     m_nRate1( nRate1 ),
     299                 :            :     m_nRate2( nRate2 ),
     300                 :     108636 :     m_nRateGap( nRateGap )
     301                 :            : {
     302                 :     108636 : }
     303                 :            : 
     304                 :      95077 : BorderWidthImpl& BorderWidthImpl::operator= ( const BorderWidthImpl& r )
     305                 :            : {
     306                 :      95077 :     m_nFlags = r.m_nFlags;
     307                 :      95077 :     m_nRate1 = r.m_nRate1;
     308                 :      95077 :     m_nRate2 = r.m_nRate2;
     309                 :      95077 :     m_nRateGap = r.m_nRateGap;
     310                 :      95077 :     return *this;
     311                 :            : }
     312                 :            : 
     313                 :      46150 : bool BorderWidthImpl::operator== ( const BorderWidthImpl& r ) const
     314                 :            : {
     315                 :            :     return ( m_nFlags == r.m_nFlags ) &&
     316                 :            :            ( m_nRate1 == r.m_nRate1 ) &&
     317                 :            :            ( m_nRate2 == r.m_nRate2 ) &&
     318 [ +  + ][ +  + ]:      46150 :            ( m_nRateGap == r.m_nRateGap );
         [ +  + ][ +  - ]
     319                 :            : }
     320                 :            : 
     321                 :     113373 : long BorderWidthImpl::GetLine1( long nWidth ) const
     322                 :            : {
     323                 :     113373 :     long result = static_cast<long>(m_nRate1);
     324         [ +  + ]:     113373 :     if ( ( m_nFlags & CHANGE_LINE1 ) > 0 )
     325                 :            :     {
     326         [ +  + ]:     112195 :         long const nConstant2 = (m_nFlags & CHANGE_LINE2) ? 0 : m_nRate2;
     327         [ +  + ]:     112195 :         long const nConstantD = (m_nFlags & CHANGE_DIST ) ? 0 : m_nRateGap;
     328                 :            :         result = std::max<long>(0,
     329                 :            :                     static_cast<long>((m_nRate1 * nWidth) + 0.5)
     330         [ +  - ]:     112195 :                         - (nConstant2 + nConstantD));
     331 [ -  + ][ #  # ]:     112195 :         if (result == 0 && m_nRate1 > 0.0 && nWidth > 0)
                 [ #  # ]
     332                 :            :         {   // fdo#51777: hack to essentially treat 1 twip DOUBLE border
     333                 :          0 :             result = 1;  // as 1 twip SINGLE border
     334                 :            :         }
     335                 :            :     }
     336                 :     113373 :     return result;
     337                 :            : }
     338                 :            : 
     339                 :     111469 : long BorderWidthImpl::GetLine2( long nWidth ) const
     340                 :            : {
     341                 :     111469 :     long result = static_cast<long>(m_nRate2);
     342         [ +  + ]:     111469 :     if ( ( m_nFlags & CHANGE_LINE2 ) > 0 )
     343                 :            :     {
     344         [ +  + ]:       1895 :         long const nConstant1 = (m_nFlags & CHANGE_LINE1) ? 0 : m_nRate1;
     345         [ +  + ]:       1895 :         long const nConstantD = (m_nFlags & CHANGE_DIST ) ? 0 : m_nRateGap;
     346                 :            :         result = std::max<long>(0,
     347                 :            :                     static_cast<long>((m_nRate2 * nWidth) + 0.5)
     348         [ +  - ]:       1895 :                         - (nConstant1 + nConstantD));
     349                 :            :     }
     350                 :     111469 :     return result;
     351                 :            : }
     352                 :            : 
     353                 :      94877 : long BorderWidthImpl::GetGap( long nWidth ) const
     354                 :            : {
     355                 :      94877 :     long result = static_cast<long>(m_nRateGap);
     356         [ +  + ]:      94877 :     if ( ( m_nFlags & CHANGE_DIST ) > 0 )
     357                 :            :     {
     358         [ +  + ]:       2836 :         long const nConstant1 = (m_nFlags & CHANGE_LINE1) ? 0 : m_nRate1;
     359         [ +  + ]:       2836 :         long const nConstant2 = (m_nFlags & CHANGE_LINE2) ? 0 : m_nRate2;
     360                 :            :         result = std::max<long>(0,
     361                 :            :                     static_cast<long>((m_nRateGap * nWidth) + 0.5)
     362         [ +  - ]:       2836 :                         - (nConstant1 + nConstant2));
     363                 :            :     }
     364                 :            : 
     365                 :            :     // Avoid having too small distances (less than 0.1pt)
     366 [ +  + ][ +  + ]:      94877 :     if ( result < MINGAPWIDTH && m_nRate1 > 0 && m_nRate2 > 0 )
                 [ -  + ]
     367                 :          0 :         result = MINGAPWIDTH;
     368                 :            : 
     369                 :      94877 :     return result;
     370                 :            : }
     371                 :            : 
     372                 :      13998 : double lcl_getGuessedWidth( long nTested, double nRate, bool nChanging )
     373                 :            : {
     374                 :      13998 :     double nWidth = -1.0;
     375         [ +  + ]:      13998 :     if ( nChanging )
     376                 :       6266 :         nWidth = double( nTested ) / nRate;
     377                 :            :     else
     378                 :            :     {
     379         [ +  + ]:       7732 :         if ( double( nTested ) == nRate )
     380                 :       5614 :             nWidth = nRate;
     381                 :            :     }
     382                 :            : 
     383                 :      13998 :     return nWidth;
     384                 :            : }
     385                 :            : 
     386                 :       4666 : long BorderWidthImpl::GuessWidth( long nLine1, long nLine2, long nGap )
     387                 :            : {
     388         [ +  - ]:       4666 :     std::vector< double > aToCompare;
     389                 :       4666 :     bool bInvalid = false;
     390                 :            : 
     391                 :       4666 :     bool bLine1Change = ( m_nFlags & CHANGE_LINE1 ) > 0;
     392                 :       4666 :     double nWidth1 = lcl_getGuessedWidth( nLine1, m_nRate1, bLine1Change );
     393         [ +  + ]:       4666 :     if ( bLine1Change )
     394         [ +  - ]:       3931 :         aToCompare.push_back( nWidth1 );
     395 [ +  - ][ +  + ]:        735 :     else if ( !bLine1Change && nWidth1 < 0 )
     396                 :        729 :         bInvalid = true;
     397                 :            : 
     398                 :       4666 :     bool bLine2Change = ( m_nFlags & CHANGE_LINE2 ) > 0;
     399                 :       4666 :     double nWidth2 = lcl_getGuessedWidth( nLine2, m_nRate2, bLine2Change );
     400         [ +  + ]:       4666 :     if ( bLine2Change )
     401         [ +  - ]:       1043 :         aToCompare.push_back( nWidth2 );
     402 [ +  - ][ +  + ]:       3623 :     else if ( !bLine2Change && nWidth2 < 0 )
     403                 :        813 :         bInvalid = true;
     404                 :            : 
     405                 :       4666 :     bool bGapChange = ( m_nFlags & CHANGE_DIST ) > 0;
     406                 :       4666 :     double nWidthGap = lcl_getGuessedWidth( nGap, m_nRateGap, bGapChange );
     407 [ +  - ][ +  + ]:       4666 :     if ( bGapChange && nGap > MINGAPWIDTH )
     408         [ +  - ]:       1292 :         aToCompare.push_back( nWidthGap );
     409 [ +  - ][ +  + ]:       3374 :     else if ( !bGapChange && nWidthGap < 0 )
     410                 :        576 :         bInvalid = true;
     411                 :            : 
     412                 :            :     // non-constant line width factors must sum to 1
     413                 :            :     assert((((bLine1Change) ? m_nRate1 : 0) +
     414                 :            :             ((bLine2Change) ? m_nRate2 : 0) +
     415                 :            :             ((bGapChange) ? m_nRateGap : 0)) - 1.0 < 0.00001 );
     416                 :            : 
     417                 :       4666 :     double nWidth = 0.0;
     418 [ +  + ][ +  - ]:       4666 :     if ( (!bInvalid) && (!aToCompare.empty()) )
                 [ +  + ]
     419                 :            :     {
     420         [ +  - ]:       3604 :         nWidth = *aToCompare.begin();
     421                 :       3604 :         std::vector< double >::iterator pIt = aToCompare.begin();
     422 [ +  - ][ +  + ]:       8126 :         while ( pIt != aToCompare.end() && !bInvalid )
         [ +  + ][ +  - ]
           [ +  +  #  # ]
     423                 :            :         {
     424         [ +  - ]:       4522 :             bInvalid = ( nWidth != *pIt );
     425         [ +  - ]:       4522 :             ++pIt;
     426                 :            :         }
     427         [ +  + ]:       3604 :         nWidth = (bInvalid) ?  0.0 : nLine1 + nLine2 + nGap;
     428                 :            :     }
     429                 :            : 
     430                 :       4666 :     return nWidth;
     431                 :            : }
     432                 :            : 
     433                 :            : /** Utility class storing the border line width, style and colors. The widths
     434                 :            :     are defined in Twips.
     435                 :            :   */
     436                 :            : class ImpLineListData
     437                 :            : {
     438                 :            : private:
     439                 :            :     BorderWidthImpl m_aWidthImpl;
     440                 :            : 
     441                 :            :     Color  ( *m_pColor1Fn )( Color );
     442                 :            :     Color  ( *m_pColor2Fn )( Color );
     443                 :            :     Color  ( *m_pColorDistFn )( Color, Color );
     444                 :            : 
     445                 :            :     long   m_nMinWidth;
     446                 :            :     sal_uInt16 m_nStyle;
     447                 :            : 
     448                 :            : public:
     449                 :            :     ImpLineListData( BorderWidthImpl aWidthImpl, sal_uInt16 nStyle,
     450                 :            :             long nMinWidth=0, Color ( *pColor1Fn ) ( Color ) = &sameColor,
     451                 :            :             Color ( *pColor2Fn ) ( Color ) = &sameColor, Color ( *pColorDistFn ) ( Color, Color ) = &sameDistColor );
     452                 :            : 
     453                 :            :     /** Returns the computed width of the line 1 in twips. */
     454                 :          0 :     long GetLine1ForWidth( long nWidth ) { return m_aWidthImpl.GetLine1( nWidth ); }
     455                 :            : 
     456                 :            :     /** Returns the computed width of the line 2 in twips. */
     457                 :          0 :     long GetLine2ForWidth( long nWidth ) { return m_aWidthImpl.GetLine2( nWidth ); }
     458                 :            : 
     459                 :            :     /** Returns the computed width of the gap in twips. */
     460                 :          0 :     long GetDistForWidth( long nWidth ) { return m_aWidthImpl.GetGap( nWidth ); }
     461                 :            : 
     462                 :            :     Color  GetColorLine1( const Color& aMain );
     463                 :            :     Color  GetColorLine2( const Color& aMain );
     464                 :            :     Color  GetColorDist( const Color& aMain, const Color& rDefault );
     465                 :            : 
     466                 :            :     /** Returns the minimum width in twips */
     467                 :            :     long   GetMinWidth( );
     468                 :            :     sal_uInt16 GetStyle( );
     469                 :            : };
     470                 :            : 
     471                 :          0 : ImpLineListData::ImpLineListData( BorderWidthImpl aWidthImpl,
     472                 :            :        sal_uInt16 nStyle, long nMinWidth, Color ( *pColor1Fn )( Color ),
     473                 :            :        Color ( *pColor2Fn )( Color ), Color ( *pColorDistFn )( Color, Color ) ) :
     474                 :            :     m_aWidthImpl( aWidthImpl ),
     475                 :            :     m_pColor1Fn( pColor1Fn ),
     476                 :            :     m_pColor2Fn( pColor2Fn ),
     477                 :            :     m_pColorDistFn( pColorDistFn ),
     478                 :            :     m_nMinWidth( nMinWidth ),
     479                 :          0 :     m_nStyle( nStyle )
     480                 :            : {
     481                 :          0 : }
     482                 :            : 
     483                 :          0 : long ImpLineListData::GetMinWidth( )
     484                 :            : {
     485                 :          0 :     return m_nMinWidth;
     486                 :            : }
     487                 :            : 
     488                 :          0 : Color ImpLineListData::GetColorLine1( const Color& rMain )
     489                 :            : {
     490                 :          0 :     return ( *m_pColor1Fn )( rMain );
     491                 :            : }
     492                 :            : 
     493                 :          0 : Color ImpLineListData::GetColorLine2( const Color& rMain )
     494                 :            : {
     495                 :          0 :     return ( *m_pColor2Fn )( rMain );
     496                 :            : }
     497                 :            : 
     498                 :          0 : Color ImpLineListData::GetColorDist( const Color& rMain, const Color& rDefault )
     499                 :            : {
     500                 :          0 :     return ( *m_pColorDistFn )( rMain, rDefault );
     501                 :            : }
     502                 :            : 
     503                 :          0 : sal_uInt16 LineListBox::GetSelectEntryStyle( sal_uInt16 nSelIndex ) const
     504                 :            : {
     505                 :          0 :     sal_uInt16 nStyle = STYLE_SOLID;
     506                 :          0 :     sal_uInt16 nPos = GetSelectEntryPos( nSelIndex );
     507         [ #  # ]:          0 :     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
     508                 :            :     {
     509         [ #  # ]:          0 :         if ( m_sNone.Len( ) > 0 )
     510                 :          0 :             nPos--;
     511                 :          0 :         nStyle = GetEntryStyle( nPos );
     512                 :            :     }
     513                 :            : 
     514                 :          0 :     return nStyle;
     515                 :            : }
     516                 :            : 
     517                 :          0 : sal_uInt16 ImpLineListData::GetStyle( )
     518                 :            : {
     519                 :          0 :     return m_nStyle;
     520                 :            : }
     521                 :            : 
     522                 :            : // -----------------------------------------------------------------------
     523                 :            : 
     524                 :          0 : void lclDrawPolygon( OutputDevice& rDev, const basegfx::B2DPolygon& rPolygon, long nWidth, sal_uInt16 nDashing )
     525                 :            : {
     526                 :          0 :     sal_uInt16 nOldAA = rDev.GetAntialiasing();
     527         [ #  # ]:          0 :     rDev.SetAntialiasing( nOldAA & !ANTIALIASING_ENABLE_B2DDRAW );
     528                 :            : 
     529         [ #  # ]:          0 :     basegfx::B2DPolyPolygon aPolygons = svtools::ApplyLineDashing( rPolygon, nDashing, rDev.GetMapMode().GetMapUnit() );
     530 [ #  # ][ #  # ]:          0 :     for ( sal_uInt32 i = 0; i < aPolygons.count( ); i++ )
     531                 :            :     {
     532         [ #  # ]:          0 :         basegfx::B2DPolygon aDash = aPolygons.getB2DPolygon( i );
     533         [ #  # ]:          0 :         basegfx::B2DPoint aStart = aDash.getB2DPoint( 0 );
     534 [ #  # ][ #  # ]:          0 :         basegfx::B2DPoint aEnd = aDash.getB2DPoint( aDash.count() - 1 );
     535                 :            : 
     536                 :          0 :         basegfx::B2DVector aVector( aEnd - aStart );
     537         [ #  # ]:          0 :         aVector.normalize( );
     538         [ #  # ]:          0 :         const basegfx::B2DVector aPerpendicular(basegfx::getPerpendicular(aVector));
     539                 :            : 
     540                 :            :         // Handle problems of width 1px in Pixel mode: 0.5px gives a 1px line
     541         [ #  # ]:          0 :         long nPix = rDev.PixelToLogic( Size( 0, 1 ) ).Height();
     542 [ #  # ][ #  # ]:          0 :         if ( rDev.GetMapMode().GetMapUnit() == MAP_PIXEL && nWidth == nPix )
                 [ #  # ]
     543                 :          0 :             nWidth = 0;
     544                 :            : 
     545                 :          0 :         const basegfx::B2DVector aWidthOffset( double( nWidth ) / 2 * aPerpendicular);
     546         [ #  # ]:          0 :         basegfx::B2DPolygon aDashPolygon;
     547         [ #  # ]:          0 :         aDashPolygon.append( aStart + aWidthOffset );
     548         [ #  # ]:          0 :         aDashPolygon.append( aEnd + aWidthOffset );
     549         [ #  # ]:          0 :         aDashPolygon.append( aEnd - aWidthOffset );
     550         [ #  # ]:          0 :         aDashPolygon.append( aStart - aWidthOffset );
     551         [ #  # ]:          0 :         aDashPolygon.setClosed( true );
     552                 :            : 
     553         [ #  # ]:          0 :         rDev.DrawPolygon( aDashPolygon );
     554 [ #  # ][ #  # ]:          0 :     }
     555                 :            : 
     556 [ #  # ][ #  # ]:          0 :     rDev.SetAntialiasing( nOldAA );
     557                 :          0 : }
     558                 :            : 
     559                 :            : namespace svtools
     560                 :            : {
     561                 :        439 :     std::vector < double > GetDashing( sal_uInt16 nDashing, MapUnit eUnit )
     562                 :            :     {
     563                 :        439 :         ::std::vector < double >aPattern;
     564      [ +  +  + ]:        439 :         switch ( nDashing )
     565                 :            :         {
     566                 :            :             case STYLE_DOTTED:
     567         [ -  + ]:         13 :                 if ( eUnit == MAP_TWIP )
     568                 :            :                 {
     569         [ #  # ]:          0 :                     aPattern.push_back( 30.0 );
     570         [ #  # ]:          0 :                     aPattern.push_back( 110.0 );
     571                 :            :                 }
     572         [ -  + ]:         13 :                 else if ( eUnit == MAP_100TH_MM )
     573                 :            :                 {
     574         [ #  # ]:          0 :                     aPattern.push_back( 50 );
     575         [ #  # ]:          0 :                     aPattern.push_back( 200 );
     576                 :            :                 }
     577         [ +  - ]:         13 :                 else if ( eUnit == MAP_PIXEL )
     578                 :            :                 {
     579         [ +  - ]:         13 :                     aPattern.push_back( 1.0 );
     580         [ +  - ]:         13 :                     aPattern.push_back( 3.0 );
     581                 :            :                 }
     582                 :         13 :                 break;
     583                 :            :             case STYLE_DASHED:
     584         [ -  + ]:         30 :                 if ( eUnit == MAP_TWIP )
     585                 :            :                 {
     586         [ #  # ]:          0 :                     aPattern.push_back( 110 );
     587         [ #  # ]:          0 :                     aPattern.push_back( 110 );
     588                 :            :                 }
     589         [ -  + ]:         30 :                 else if ( eUnit == MAP_100TH_MM )
     590                 :            :                 {
     591         [ #  # ]:          0 :                     aPattern.push_back( 200 );
     592         [ #  # ]:          0 :                     aPattern.push_back( 200 );
     593                 :            :                 }
     594         [ +  - ]:         30 :                 else if ( eUnit == MAP_PIXEL )
     595                 :            :                 {
     596         [ +  - ]:         30 :                     aPattern.push_back( 10 );
     597         [ +  - ]:         30 :                     aPattern.push_back( 20 );
     598                 :            :                 }
     599                 :         30 :                 break;
     600                 :            :             default:
     601                 :        396 :                 break;
     602                 :            :         }
     603                 :            : 
     604                 :        439 :         return aPattern;
     605                 :            :     }
     606                 :            : 
     607                 :          0 :     basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, MapUnit eUnit )
     608                 :            :     {
     609         [ #  # ]:          0 :         std::vector< double > aPattern = GetDashing( nDashing, eUnit );
     610         [ #  # ]:          0 :         basegfx::B2DPolyPolygon aPolygons;
     611         [ #  # ]:          0 :         if ( ! aPattern.empty() )
     612         [ #  # ]:          0 :             basegfx::tools::applyLineDashing( rPolygon, aPattern, &aPolygons );
     613                 :            :         else
     614         [ #  # ]:          0 :             aPolygons.append( rPolygon );
     615                 :            : 
     616                 :          0 :         return aPolygons;
     617                 :            :     }
     618                 :            : 
     619                 :        439 :     basegfx::B2DPolyPolygon ApplyLineDashing( const basegfx::B2DPolygon& rPolygon, sal_uInt16 nDashing, MapUnit eUnit, double fScale )
     620                 :            :     {
     621         [ +  - ]:        439 :         std::vector< double > aPattern = GetDashing( nDashing, eUnit );
     622                 :        439 :         std::vector< double >::iterator i = aPattern.begin();
     623 [ +  - ][ +  + ]:        525 :         while( i != aPattern.end() ) {
     624         [ +  - ]:         86 :             (*i) *= fScale;
     625         [ +  - ]:         86 :             ++i;
     626                 :            :         }
     627                 :            : 
     628         [ +  - ]:        439 :         basegfx::B2DPolyPolygon aPolygons;
     629         [ +  + ]:        439 :         if ( ! aPattern.empty() )
     630         [ +  - ]:         43 :             basegfx::tools::applyLineDashing( rPolygon, aPattern, &aPolygons );
     631                 :            :         else
     632         [ +  - ]:        396 :             aPolygons.append( rPolygon );
     633                 :            : 
     634                 :        439 :         return aPolygons;
     635                 :            :     }
     636                 :            : 
     637                 :          0 :     void DrawLine( OutputDevice& rDev, const Point& rP1, const Point& rP2,
     638                 :            :         sal_uInt32 nWidth, sal_uInt16 nDashing )
     639                 :            :     {
     640                 :          0 :         DrawLine( rDev, basegfx::B2DPoint( rP1.X(), rP1.Y() ),
     641         [ #  # ]:          0 :                 basegfx::B2DPoint( rP2.X(), rP2.Y( ) ), nWidth, nDashing );
     642                 :          0 :     }
     643                 :            : 
     644                 :          0 :     void DrawLine( OutputDevice& rDev, const basegfx::B2DPoint& rP1, const basegfx::B2DPoint& rP2,
     645                 :            :         sal_uInt32 nWidth, sal_uInt16 nDashing )
     646                 :            :     {
     647         [ #  # ]:          0 :         basegfx::B2DPolygon aPolygon;
     648         [ #  # ]:          0 :         aPolygon.append( rP1 );
     649         [ #  # ]:          0 :         aPolygon.append( rP2 );
     650 [ #  # ][ #  # ]:          0 :         lclDrawPolygon( rDev, aPolygon, nWidth, nDashing );
     651                 :          0 :     }
     652                 :            : }
     653                 :            : 
     654                 :          0 : void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
     655                 :            :                             Color aColor1, Color aColor2, Color aColorDist,
     656                 :            :                             sal_uInt16 nStyle, Bitmap& rBmp )
     657                 :            : {
     658                 :          0 :     Size aSize = GetOutputSizePixel();
     659                 :          0 :     aSize.Width() -= 20;
     660                 :          0 :     aSize.Width() -= aTxtSize.Width();
     661                 :          0 :     aSize.Height() = aTxtSize.Height();
     662                 :            : 
     663                 :            :     // SourceUnit nach Twips
     664         [ #  # ]:          0 :     if ( eSourceUnit == FUNIT_POINT )
     665                 :            :     {
     666                 :          0 :         nLine1      /= 5;
     667                 :          0 :         nLine2      /= 5;
     668                 :          0 :         nDistance   /= 5;
     669                 :            :     }
     670                 :            : 
     671                 :            :     // Linien malen
     672         [ #  # ]:          0 :     aSize = aVirDev.PixelToLogic( aSize );
     673         [ #  # ]:          0 :     long nPix = aVirDev.PixelToLogic( Size( 0, 1 ) ).Height();
     674                 :          0 :     sal_uInt32 n1 = nLine1;
     675                 :          0 :     sal_uInt32 n2 = nLine2;
     676                 :          0 :     long nDist  = nDistance;
     677                 :          0 :     n1 += nPix-1;
     678                 :          0 :     n1 -= n1%nPix;
     679         [ #  # ]:          0 :     if ( n2 )
     680                 :            :     {
     681                 :          0 :         nDist += nPix-1;
     682                 :          0 :         nDist -= nDist%nPix;
     683                 :          0 :         n2    += nPix-1;
     684                 :          0 :         n2    -= n2%nPix;
     685                 :            :     }
     686                 :          0 :     long nVirHeight = n1+nDist+n2;
     687         [ #  # ]:          0 :     if ( nVirHeight > aSize.Height() )
     688                 :          0 :         aSize.Height() = nVirHeight;
     689                 :            :     // negative Breiten muss und darf man nicht painten
     690         [ #  # ]:          0 :     if ( aSize.Width() > 0 )
     691                 :            :     {
     692         [ #  # ]:          0 :         Size aVirSize = aVirDev.LogicToPixel( aSize );
     693         [ #  # ]:          0 :         if ( aVirDev.GetOutputSizePixel() != aVirSize )
     694         [ #  # ]:          0 :             aVirDev.SetOutputSizePixel( aVirSize );
     695         [ #  # ]:          0 :         aVirDev.SetFillColor( aColorDist );
     696 [ #  # ][ #  # ]:          0 :         aVirDev.DrawRect( Rectangle( Point(), aSize ) );
     697                 :            : 
     698         [ #  # ]:          0 :         aVirDev.SetFillColor( aColor1 );
     699                 :            : 
     700                 :          0 :         double y1 = double( n1 ) / 2;
     701         [ #  # ]:          0 :         svtools::DrawLine( aVirDev, basegfx::B2DPoint( 0, y1 ), basegfx::B2DPoint( aSize.Width( ), y1 ), n1, nStyle );
     702                 :            : 
     703         [ #  # ]:          0 :         if ( n2 )
     704                 :            :         {
     705                 :          0 :             double y2 =  n1 + nDist + double( n2 ) / 2;
     706         [ #  # ]:          0 :             aVirDev.SetFillColor( aColor2 );
     707         [ #  # ]:          0 :             svtools::DrawLine( aVirDev, basegfx::B2DPoint( 0, y2 ), basegfx::B2DPoint( aSize.Width(), y2 ), n2, STYLE_SOLID );
     708                 :            :         }
     709 [ #  # ][ #  # ]:          0 :         rBmp = aVirDev.GetBitmap( Point(), Size( aSize.Width(), n1+nDist+n2 ) );
                 [ #  # ]
     710                 :            :     }
     711                 :          0 : }
     712                 :            : 
     713                 :            : // -----------------------------------------------------------------------
     714                 :            : 
     715                 :          0 : void LineListBox::ImplInit()
     716                 :            : {
     717 [ #  # ][ #  # ]:          0 :     aTxtSize.Width()  = GetTextWidth( rtl::OUString( " " ) );
                 [ #  # ]
     718                 :          0 :     aTxtSize.Height() = GetTextHeight();
     719         [ #  # ]:          0 :     pLineList   = new ImpLineList();
     720                 :          0 :     eUnit       = FUNIT_POINT;
     721                 :          0 :     eSourceUnit = FUNIT_POINT;
     722                 :            : 
     723                 :          0 :     aVirDev.SetLineColor();
     724         [ #  # ]:          0 :     aVirDev.SetMapMode( MapMode( MAP_TWIP ) );
     725                 :            : 
     726                 :          0 :     UpdatePaintLineColor();
     727                 :          0 : }
     728                 :            : 
     729                 :            : // -----------------------------------------------------------------------
     730                 :            : 
     731                 :          0 : LineListBox::LineListBox( Window* pParent, WinBits nWinStyle ) :
     732                 :            :     ListBox( pParent, nWinStyle ),
     733                 :            :     m_nWidth( 5 ),
     734                 :            :     m_sNone( ),
     735                 :            :     aColor( COL_BLACK ),
     736 [ #  # ][ #  # ]:          0 :     maPaintCol( COL_BLACK )
     737                 :            : {
     738         [ #  # ]:          0 :     ImplInit();
     739                 :          0 : }
     740                 :            : 
     741                 :            : // -----------------------------------------------------------------------
     742                 :            : 
     743                 :          0 : LineListBox::LineListBox( Window* pParent, const ResId& rResId ) :
     744                 :            :     ListBox( pParent, rResId ),
     745                 :            :     m_nWidth( 5 ),
     746                 :            :     m_sNone( ),
     747                 :            :     aColor( COL_BLACK ),
     748 [ #  # ][ #  # ]:          0 :     maPaintCol( COL_BLACK )
     749                 :            : {
     750         [ #  # ]:          0 :     ImplInit();
     751                 :          0 : }
     752                 :            : 
     753                 :            : // -----------------------------------------------------------------------
     754                 :            : 
     755 [ #  # ][ #  # ]:          0 : LineListBox::~LineListBox()
     756                 :            : {
     757         [ #  # ]:          0 :     for ( size_t i = 0, n = pLineList->size(); i < n; ++i ) {
     758         [ #  # ]:          0 :         if ( (*pLineList)[ i ] ) {
     759                 :          0 :             delete (*pLineList)[ i ];
     760                 :            :         }
     761                 :            :     }
     762                 :          0 :     pLineList->clear();
     763         [ #  # ]:          0 :     delete pLineList;
     764         [ #  # ]:          0 : }
     765                 :            : 
     766                 :          0 : sal_uInt16 LineListBox::GetStylePos( sal_uInt16 nListPos, long nWidth )
     767                 :            : {
     768                 :          0 :     sal_uInt16 nPos = LISTBOX_ENTRY_NOTFOUND;
     769         [ #  # ]:          0 :     if ( m_sNone.Len( ) > 0 )
     770                 :          0 :         nListPos--;
     771                 :            : 
     772                 :          0 :     sal_uInt16 i = 0;
     773                 :          0 :     sal_uInt16 n = 0;
     774                 :          0 :     sal_uInt16 nCount = pLineList->size();
     775 [ #  # ][ #  # ]:          0 :     while ( nPos == LISTBOX_ENTRY_NOTFOUND && i < nCount )
                 [ #  # ]
     776                 :            :     {
     777                 :          0 :         ImpLineListData* pData = (*pLineList)[ i ];
     778 [ #  # ][ #  # ]:          0 :         if ( pData && pData->GetMinWidth() <= nWidth )
                 [ #  # ]
     779                 :            :         {
     780         [ #  # ]:          0 :             if ( nListPos == n )
     781                 :          0 :                 nPos = i;
     782                 :          0 :             n++;
     783                 :            :         }
     784                 :          0 :         i++;
     785                 :            :     }
     786                 :            : 
     787                 :          0 :     return nPos;
     788                 :            : }
     789                 :            : 
     790                 :            : 
     791                 :          0 : void LineListBox::SelectEntry( sal_uInt16 nStyle, sal_Bool bSelect )
     792                 :            : {
     793                 :          0 :     sal_uInt16 nPos = GetEntryPos( nStyle );
     794         [ #  # ]:          0 :     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
     795                 :          0 :         ListBox::SelectEntryPos( nPos, bSelect );
     796                 :          0 : }
     797                 :            : 
     798                 :            : // -----------------------------------------------------------------------
     799                 :            : 
     800                 :          0 : sal_uInt16 LineListBox::InsertEntry( const XubString& rStr, sal_uInt16 nPos )
     801                 :            : {
     802                 :          0 :     nPos = ListBox::InsertEntry( rStr, nPos );
     803         [ #  # ]:          0 :     if ( nPos != LISTBOX_ERROR ) {
     804         [ #  # ]:          0 :         if ( nPos < pLineList->size() ) {
     805                 :          0 :             ImpLineList::iterator it = pLineList->begin();
     806         [ #  # ]:          0 :             ::std::advance( it, nPos );
     807         [ #  # ]:          0 :             pLineList->insert( it, NULL );
     808                 :            :         } else {
     809         [ #  # ]:          0 :             pLineList->push_back( NULL );
     810                 :            :         }
     811                 :            :     }
     812                 :          0 :     return nPos;
     813                 :            : }
     814                 :            : 
     815                 :            : // -----------------------------------------------------------------------
     816                 :            : 
     817                 :          0 : void LineListBox::InsertEntry(
     818                 :            :         BorderWidthImpl aWidthImpl,
     819                 :            :         sal_uInt16 nStyle, long nMinWidth,
     820                 :            :         Color ( *pColor1Fn )( Color ), Color ( *pColor2Fn )( Color ),
     821                 :            :         Color ( *pColorDistFn )( Color, Color ) )
     822                 :            : {
     823                 :            :     ImpLineListData* pData = new ImpLineListData(
     824                 :            :             aWidthImpl, nStyle, nMinWidth,
     825         [ #  # ]:          0 :            pColor1Fn, pColor2Fn, pColorDistFn );
     826         [ #  # ]:          0 :     pLineList->push_back( pData );
     827                 :          0 : }
     828                 :            : 
     829                 :            : // -----------------------------------------------------------------------
     830                 :            : 
     831                 :          0 : void LineListBox::RemoveEntry( sal_uInt16 nPos )
     832                 :            : {
     833                 :          0 :     ListBox::RemoveEntry( nPos );
     834                 :            : 
     835         [ #  # ]:          0 :     if ( nPos < pLineList->size() ) {
     836                 :          0 :         ImpLineList::iterator it = pLineList->begin();
     837         [ #  # ]:          0 :         ::std::advance( it, nPos );
     838         [ #  # ]:          0 :         if ( *it ) delete *it;
     839         [ #  # ]:          0 :         pLineList->erase( it );
     840                 :            :     }
     841                 :          0 : }
     842                 :            : 
     843                 :            : // -----------------------------------------------------------------------
     844                 :            : 
     845                 :          0 : void LineListBox::Clear()
     846                 :            : {
     847         [ #  # ]:          0 :     for ( size_t i = 0, n = pLineList->size(); i < n; ++i ) {
     848         [ #  # ]:          0 :         if ( (*pLineList)[ i ] ) {
     849                 :          0 :             delete (*pLineList)[ i ];
     850                 :            :         }
     851                 :            :     }
     852                 :          0 :     pLineList->clear();
     853                 :            : 
     854                 :          0 :     ListBox::Clear();
     855                 :          0 : }
     856                 :            : 
     857                 :            : // -----------------------------------------------------------------------
     858                 :            : 
     859                 :          0 : sal_uInt16 LineListBox::GetEntryPos( sal_uInt16 nStyle ) const
     860                 :            : {
     861         [ #  # ]:          0 :     for ( size_t i = 0, n = pLineList->size(); i < n; ++i ) {
     862                 :          0 :         ImpLineListData* pData = (*pLineList)[ i ];
     863         [ #  # ]:          0 :         if ( pData )
     864                 :            :         {
     865         [ #  # ]:          0 :             if ( GetEntryStyle( i ) == nStyle )
     866                 :            :             {
     867                 :          0 :                 size_t nPos = i;
     868         [ #  # ]:          0 :                 if ( m_sNone.Len() > 0 )
     869                 :          0 :                     nPos ++;
     870                 :          0 :                 return (sal_uInt16)nPos;
     871                 :            :             }
     872                 :            :         }
     873                 :            :     }
     874                 :          0 :     return LISTBOX_ENTRY_NOTFOUND;
     875                 :            : }
     876                 :            : 
     877                 :            : // -----------------------------------------------------------------------
     878                 :            : 
     879                 :          0 : sal_uInt16 LineListBox::GetEntryStyle( sal_uInt16 nPos ) const
     880                 :            : {
     881         [ #  # ]:          0 :     ImpLineListData* pData = (nPos < pLineList->size()) ? (*pLineList)[ nPos ] : NULL;
     882         [ #  # ]:          0 :     return ( pData ) ? pData->GetStyle() : STYLE_NONE;
     883                 :            : }
     884                 :            : 
     885                 :            : // -----------------------------------------------------------------------
     886                 :            : 
     887                 :          0 : sal_Bool LineListBox::UpdatePaintLineColor( void )
     888                 :            : {
     889                 :          0 :     sal_Bool                    bRet = sal_True;
     890                 :          0 :     const StyleSettings&    rSettings = GetSettings().GetStyleSettings();
     891 [ #  # ][ #  # ]:          0 :     Color                   aNewCol( rSettings.GetWindowColor().IsDark()? rSettings.GetLabelTextColor() : aColor );
     892                 :            : 
     893                 :          0 :     bRet = aNewCol != maPaintCol;
     894                 :            : 
     895         [ #  # ]:          0 :     if( bRet )
     896                 :          0 :         maPaintCol = aNewCol;
     897                 :            : 
     898                 :          0 :     return bRet;
     899                 :            : }
     900                 :            : 
     901                 :          0 : void LineListBox::UpdateEntries( long nOldWidth )
     902                 :            : {
     903                 :          0 :     SetUpdateMode( sal_False );
     904                 :            : 
     905                 :          0 :     UpdatePaintLineColor( );
     906                 :            : 
     907                 :          0 :     sal_uInt16      nSelEntry = GetSelectEntryPos();
     908                 :          0 :     sal_uInt16       nTypePos = GetStylePos( nSelEntry, nOldWidth );
     909                 :            : 
     910                 :            :     // Remove the old entries
     911         [ #  # ]:          0 :     while ( GetEntryCount( ) > 0 )
     912                 :          0 :         ListBox::RemoveEntry( 0 );
     913                 :            : 
     914                 :            :     // Add the new entries based on the defined width
     915         [ #  # ]:          0 :     if ( m_sNone.Len( ) > 0 )
     916                 :          0 :         ListBox::InsertEntry( m_sNone, LISTBOX_APPEND );
     917                 :            : 
     918                 :          0 :     sal_uInt16 n = 0;
     919                 :          0 :     sal_uInt16 nCount = pLineList->size( );
     920         [ #  # ]:          0 :     while ( n < nCount )
     921                 :            :     {
     922                 :          0 :         ImpLineListData* pData = (*pLineList)[ n ];
     923 [ #  # ][ #  # ]:          0 :         if ( pData && pData->GetMinWidth() <= m_nWidth )
                 [ #  # ]
     924                 :            :         {
     925         [ #  # ]:          0 :             Bitmap      aBmp;
     926                 :            :             ImpGetLine( pData->GetLine1ForWidth( m_nWidth ),
     927                 :            :                     pData->GetLine2ForWidth( m_nWidth ),
     928                 :            :                     pData->GetDistForWidth( m_nWidth ),
     929         [ #  # ]:          0 :                     GetColorLine1( GetEntryCount( ) ),
     930         [ #  # ]:          0 :                     GetColorLine2( GetEntryCount( ) ),
     931         [ #  # ]:          0 :                     GetColorDist( GetEntryCount( ) ),
     932 [ #  # ][ #  # ]:          0 :                     pData->GetStyle(), aBmp );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     933 [ #  # ][ #  # ]:          0 :             ListBox::InsertEntry( rtl::OUString( " " ), aBmp, LISTBOX_APPEND );
         [ #  # ][ #  # ]
                 [ #  # ]
     934         [ #  # ]:          0 :             if ( n == nTypePos )
     935 [ #  # ][ #  # ]:          0 :                 SelectEntryPos( GetEntryCount() - 1 );
                 [ #  # ]
     936                 :            :         }
     937         [ #  # ]:          0 :         else if ( n == nTypePos )
     938                 :          0 :             SetNoSelection();
     939                 :          0 :         n++;
     940                 :            :     }
     941                 :            : 
     942                 :          0 :     SetUpdateMode( sal_True );
     943                 :          0 :     Invalidate();
     944                 :          0 : }
     945                 :            : 
     946                 :            : // -----------------------------------------------------------------------
     947                 :            : 
     948                 :          0 : Color LineListBox::GetColorLine1( sal_uInt16 nPos )
     949                 :            : {
     950                 :          0 :     Color rResult = GetPaintColor( );
     951                 :            : 
     952                 :          0 :     sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
     953                 :          0 :     ImpLineListData* pData = (*pLineList)[ nStyle ];
     954         [ #  # ]:          0 :     if ( pData )
     955         [ #  # ]:          0 :         rResult = pData->GetColorLine1( GetColor( ) );
     956                 :            : 
     957                 :          0 :     return rResult;
     958                 :            : }
     959                 :            : 
     960                 :          0 : Color LineListBox::GetColorLine2( sal_uInt16 nPos )
     961                 :            : {
     962                 :          0 :     Color rResult = GetPaintColor( );
     963                 :            : 
     964                 :          0 :     sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
     965                 :          0 :     ImpLineListData* pData = (*pLineList)[ nStyle ];
     966         [ #  # ]:          0 :     if ( pData )
     967         [ #  # ]:          0 :         rResult = pData->GetColorLine2( GetColor( ) );
     968                 :            : 
     969                 :          0 :     return rResult;
     970                 :            : }
     971                 :            : 
     972                 :          0 : Color LineListBox::GetColorDist( sal_uInt16 nPos )
     973                 :            : {
     974                 :          0 :     Color rResult = GetSettings().GetStyleSettings().GetFieldColor();
     975                 :            : 
     976                 :          0 :     sal_uInt16 nStyle = GetStylePos( nPos, m_nWidth );
     977                 :          0 :     ImpLineListData* pData = (*pLineList)[ nStyle ];
     978         [ #  # ]:          0 :     if ( pData )
     979         [ #  # ]:          0 :         rResult = pData->GetColorDist( GetColor( ), rResult );
     980                 :            : 
     981                 :          0 :     return rResult;
     982                 :            : }
     983                 :            : 
     984                 :            : // -----------------------------------------------------------------------
     985                 :            : 
     986                 :          0 : void LineListBox::DataChanged( const DataChangedEvent& rDCEvt )
     987                 :            : {
     988                 :          0 :     ListBox::DataChanged( rDCEvt );
     989                 :            : 
     990 [ #  # ][ #  # ]:          0 :     if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
                 [ #  # ]
     991                 :          0 :         UpdateEntries( m_nWidth );
     992                 :          0 : }
     993                 :            : 
     994                 :            : 
     995                 :            : // ===================================================================
     996                 :            : // FontNameBox
     997                 :            : // ===================================================================
     998                 :            : 
     999                 :        116 : class ImplFontNameListData
    1000                 :            : {
    1001                 :            : public:
    1002                 :            :     FontInfo    maInfo;
    1003                 :            :     sal_uInt16      mnType;
    1004                 :            : 
    1005                 :        116 :                 ImplFontNameListData( const FontInfo& rInfo,
    1006                 :            :                                     sal_uInt16 nType ) :
    1007                 :            :                     maInfo( rInfo ),
    1008                 :        116 :                     mnType( nType )
    1009                 :        116 :                 {}
    1010                 :            : };
    1011                 :            : 
    1012                 :            : // -------------------------------------------------------------------
    1013                 :            : 
    1014                 :        961 : FontNameBox::FontNameBox( Window* pParent, WinBits nWinStyle ) :
    1015 [ +  - ][ +  - ]:        961 :     ComboBox( pParent, nWinStyle )
         [ +  - ][ +  - ]
    1016                 :            : {
    1017         [ +  - ]:        961 :     InitBitmaps();
    1018                 :        961 :     mpFontList = NULL;
    1019                 :        961 :     mbWYSIWYG = sal_False;
    1020                 :        961 :     mbSymbols = sal_False;
    1021         [ +  - ]:        961 :     InitFontMRUEntriesFile();
    1022                 :        961 : }
    1023                 :            : 
    1024                 :            : // -------------------------------------------------------------------
    1025                 :            : 
    1026                 :          0 : FontNameBox::FontNameBox( Window* pParent, const ResId& rResId ) :
    1027 [ #  # ][ #  # ]:          0 :     ComboBox( pParent, rResId )
         [ #  # ][ #  # ]
    1028                 :            : {
    1029         [ #  # ]:          0 :     InitBitmaps();
    1030                 :          0 :     mpFontList = NULL;
    1031                 :          0 :     mbWYSIWYG = sal_False;
    1032                 :          0 :     mbSymbols = sal_False;
    1033         [ #  # ]:          0 :     InitFontMRUEntriesFile();
    1034                 :          0 : }
    1035                 :            : 
    1036                 :            : // -------------------------------------------------------------------
    1037                 :            : 
    1038 [ +  - ][ +  - ]:        961 : FontNameBox::~FontNameBox()
         [ +  - ][ +  - ]
    1039                 :            : {
    1040         [ +  - ]:        961 :     SaveMRUEntries (maFontMRUEntriesFile);
    1041         [ +  - ]:        961 :     ImplDestroyFontList();
    1042         [ -  + ]:        961 : }
    1043                 :            : 
    1044                 :            : // -------------------------------------------------------------------
    1045                 :            : 
    1046                 :          0 : void FontNameBox::DataChanged( const DataChangedEvent& rDCEvt )
    1047                 :            : {
    1048                 :          0 :     ComboBox::DataChanged( rDCEvt );
    1049                 :            : 
    1050 [ #  # ][ #  # ]:          0 :     if( rDCEvt.GetType() == DATACHANGED_SETTINGS && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
                 [ #  # ]
    1051                 :          0 :         InitBitmaps();
    1052                 :          0 : }
    1053                 :            : 
    1054                 :            : // -------------------------------------------------------------------
    1055                 :            : 
    1056                 :        961 : void FontNameBox::SaveMRUEntries( const String& aFontMRUEntriesFile, xub_Unicode cSep ) const
    1057                 :            : {
    1058                 :            :     rtl::OString aEntries(rtl::OUStringToOString(GetMRUEntries(cSep),
    1059 [ +  - ][ +  - ]:        961 :         RTL_TEXTENCODING_UTF8));
         [ +  - ][ +  - ]
    1060                 :            : 
    1061 [ -  + ][ #  # ]:        961 :     if (aEntries.isEmpty() || !aFontMRUEntriesFile.Len())
                 [ +  - ]
    1062                 :            :         return;
    1063                 :            : 
    1064         [ #  # ]:          0 :     SvFileStream aStream;
    1065         [ #  # ]:          0 :     aStream.Open( aFontMRUEntriesFile, STREAM_WRITE | STREAM_TRUNC );
    1066 [ #  # ][ #  # ]:          0 :     if( ! (aStream.IsOpen() && aStream.IsWritable()) )
                 [ #  # ]
    1067                 :            :     {
    1068                 :            : #if OSL_DEBUG_LEVEL > 1
    1069                 :            :         fprintf( stderr, "FontNameBox::SaveMRUEntries: opening mru entries file %s failed\n", rtl::OUStringToOString(aFontMRUEntriesFile, RTL_TEXTENCODING_UTF8 ).getStr() );
    1070                 :            : #endif
    1071                 :            :         return;
    1072                 :            :     }
    1073                 :            : 
    1074                 :          0 :     aStream.SetLineDelimiter( LINEEND_LF );
    1075         [ #  # ]:          0 :     aStream.WriteLine( aEntries );
    1076 [ #  # ][ #  # ]:        961 :     aStream.WriteLine( rtl::OString() );
         [ #  # ][ -  + ]
    1077                 :            : }
    1078                 :            : 
    1079                 :            : // -------------------------------------------------------------------
    1080                 :            : 
    1081                 :          2 : void FontNameBox::LoadMRUEntries( const String& aFontMRUEntriesFile, xub_Unicode cSep )
    1082                 :            : {
    1083         [ +  - ]:          2 :     if( ! aFontMRUEntriesFile.Len() )
    1084                 :            :         return;
    1085                 :            : 
    1086         [ +  - ]:          2 :     SvFileStream aStream( aFontMRUEntriesFile, STREAM_READ );
    1087         [ +  - ]:          2 :     if( ! aStream.IsOpen() )
    1088                 :            :     {
    1089                 :            : #if OSL_DEBUG_LEVEL > 1
    1090                 :            :         fprintf( stderr, "FontNameBox::LoadMRUEntries: opening mru entries file %s failed\n", rtl::OUStringToOString(aFontMRUEntriesFile, RTL_TEXTENCODING_UTF8).getStr() );
    1091                 :            : #endif
    1092                 :            :         return;
    1093                 :            :     }
    1094                 :            : 
    1095                 :          0 :     rtl::OString aLine;
    1096         [ #  # ]:          0 :     aStream.ReadLine( aLine );
    1097                 :            :     rtl::OUString aEntries = rtl::OStringToOUString(aLine,
    1098         [ #  # ]:          0 :         RTL_TEXTENCODING_UTF8);
    1099 [ #  # ][ #  # ]:          2 :     SetMRUEntries( aEntries, cSep );
         [ #  # ][ +  - ]
                 [ -  + ]
    1100                 :            : }
    1101                 :            : 
    1102                 :            : // ------------------------------------------------------------------
    1103                 :            : 
    1104                 :        961 : void FontNameBox::InitFontMRUEntriesFile()
    1105                 :            : {
    1106         [ +  - ]:        961 :     rtl::OUString sUserConfigDir(RTL_CONSTASCII_USTRINGPARAM("${$BRAND_BASE_DIR/program/bootstrap.ini:UserInstallation}"));
    1107                 :        961 :     rtl::Bootstrap::expandMacros(sUserConfigDir);
    1108                 :            : 
    1109         [ +  - ]:        961 :     maFontMRUEntriesFile = sUserConfigDir;
    1110         [ +  - ]:        961 :     if( maFontMRUEntriesFile.Len() )
    1111                 :            :     {
    1112         [ +  - ]:        961 :         maFontMRUEntriesFile.AppendAscii( FONTNAMEBOXMRUENTRIESFILE );
    1113                 :        961 :     }
    1114                 :        961 : }
    1115                 :            : 
    1116                 :            : // -------------------------------------------------------------------
    1117                 :            : 
    1118                 :        961 : void FontNameBox::InitBitmaps( void )
    1119                 :            : {
    1120 [ +  - ][ +  - ]:        961 :     maImagePrinterFont = Image( SvtResId( RID_IMG_PRINTERFONT ) );
                 [ +  - ]
    1121 [ +  - ][ +  - ]:        961 :     maImageBitmapFont = Image( SvtResId( RID_IMG_BITMAPFONT ) );
                 [ +  - ]
    1122 [ +  - ][ +  - ]:        961 :     maImageScalableFont = Image( SvtResId( RID_IMG_SCALABLEFONT ) );
                 [ +  - ]
    1123                 :        961 : }
    1124                 :            : 
    1125                 :            : // -------------------------------------------------------------------
    1126                 :            : 
    1127                 :        963 : void FontNameBox::ImplDestroyFontList()
    1128                 :            : {
    1129         [ +  + ]:        963 :     if ( mpFontList )
    1130                 :            :     {
    1131         [ +  + ]:        118 :         for ( size_t i = 0, n = mpFontList->size(); i < n; ++i ) {
    1132         [ +  - ]:        116 :             delete (*mpFontList)[ i ];
    1133                 :            :         }
    1134                 :          2 :         mpFontList->clear();
    1135         [ +  - ]:          2 :         delete mpFontList;
    1136                 :            :     }
    1137                 :        963 : }
    1138                 :            : 
    1139                 :            : // -------------------------------------------------------------------
    1140                 :            : 
    1141                 :          2 : void FontNameBox::Fill( const FontList* pList )
    1142                 :            : {
    1143                 :            :     // store old text and clear box
    1144         [ +  - ]:          2 :     XubString aOldText = GetText();
    1145         [ +  - ]:          2 :     XubString rEntries = GetMRUEntries();
    1146                 :          2 :     sal_Bool bLoadFromFile = ! rEntries.Len();
    1147         [ +  - ]:          2 :     Clear();
    1148                 :            : 
    1149         [ +  - ]:          2 :     ImplDestroyFontList();
    1150 [ +  - ][ +  - ]:          2 :     mpFontList = new ImplFontList;
    1151                 :            : 
    1152                 :            :     // insert fonts
    1153         [ +  - ]:          2 :     sal_uInt16 nFontCount = pList->GetFontNameCount();
    1154         [ +  + ]:        118 :     for ( sal_uInt16 i = 0; i < nFontCount; i++ )
    1155                 :            :     {
    1156         [ +  - ]:        116 :         const FontInfo& rFontInfo = pList->GetFontName( i );
    1157 [ +  - ][ +  - ]:        116 :         sal_uLong nIndex = InsertEntry( rFontInfo.GetName() );
    1158         [ +  - ]:        116 :         if ( nIndex != LISTBOX_ERROR )
    1159                 :            :         {
    1160         [ +  - ]:        116 :             sal_uInt16 nType = pList->GetFontNameType( i );
    1161 [ +  - ][ +  - ]:        116 :             ImplFontNameListData* pData = new ImplFontNameListData( rFontInfo, nType );
    1162         [ -  + ]:        116 :             if ( nIndex < mpFontList->size() ) {
    1163                 :          0 :                 ImplFontList::iterator it = mpFontList->begin();
    1164         [ #  # ]:          0 :                 ::std::advance( it, nIndex );
    1165         [ #  # ]:          0 :                 mpFontList->insert( it, pData );
    1166                 :            :             } else {
    1167         [ +  - ]:        116 :                 mpFontList->push_back( pData );
    1168                 :            :             }
    1169                 :            :         }
    1170                 :            :     }
    1171                 :            : 
    1172         [ +  - ]:          2 :     if ( bLoadFromFile )
    1173         [ +  - ]:          2 :         LoadMRUEntries (maFontMRUEntriesFile);
    1174                 :            :     else
    1175         [ #  # ]:          0 :         SetMRUEntries( rEntries );
    1176                 :            : 
    1177         [ +  - ]:          2 :     ImplCalcUserItemSize();
    1178                 :            : 
    1179                 :            :     // restore text
    1180         [ +  - ]:          2 :     if ( aOldText.Len() )
    1181 [ +  - ][ +  - ]:          2 :         SetText( aOldText );
                 [ +  - ]
    1182                 :          2 : }
    1183                 :            : 
    1184                 :            : // -------------------------------------------------------------------
    1185                 :            : 
    1186                 :        961 : void FontNameBox::EnableWYSIWYG( sal_Bool bEnable )
    1187                 :            : {
    1188         [ +  - ]:        961 :     if ( bEnable != mbWYSIWYG )
    1189                 :            :     {
    1190                 :        961 :         mbWYSIWYG = bEnable;
    1191                 :        961 :         EnableUserDraw( mbWYSIWYG | mbSymbols );
    1192                 :        961 :         ImplCalcUserItemSize();
    1193                 :            :     }
    1194                 :        961 : }
    1195                 :            : 
    1196                 :            : // -------------------------------------------------------------------
    1197                 :            : 
    1198                 :        961 : void FontNameBox::EnableSymbols( sal_Bool bEnable )
    1199                 :            : {
    1200         [ +  - ]:        961 :     if ( bEnable != mbSymbols )
    1201                 :            :     {
    1202                 :        961 :         mbSymbols = bEnable;
    1203                 :        961 :         EnableUserDraw( mbWYSIWYG | mbSymbols );
    1204                 :        961 :         ImplCalcUserItemSize();
    1205                 :            :     }
    1206                 :        961 : }
    1207                 :            : 
    1208                 :            : // -------------------------------------------------------------------
    1209                 :            : 
    1210                 :       1924 : void FontNameBox::ImplCalcUserItemSize()
    1211                 :            : {
    1212                 :       1924 :     Size aUserItemSz;
    1213 [ +  + ][ +  - ]:       1924 :     if ( mbWYSIWYG && mpFontList )
    1214                 :            :     {
    1215         [ +  - ]:          2 :         aUserItemSz = Size(MAXPREVIEWWIDTH, GetTextHeight() );
    1216                 :          2 :         aUserItemSz.Height() *= 16;
    1217                 :          2 :         aUserItemSz.Height() /= 10;
    1218                 :            :     }
    1219         [ +  + ]:       1924 :     if ( mbSymbols )
    1220                 :            :     {
    1221         [ +  - ]:        963 :         Size aSz = maImageScalableFont.GetSizePixel();
    1222                 :        963 :         aUserItemSz.Width() += aSz.Width() + IMGINNERTEXTSPACE;
    1223                 :            : 
    1224 [ +  + ][ +  - ]:        963 :         if ( mbWYSIWYG && mpFontList )
    1225                 :          2 :             aUserItemSz.Width() += IMGOUTERTEXTSPACE;
    1226                 :            : 
    1227         [ +  + ]:        963 :         if ( aSz.Height() > aUserItemSz.Height() )
    1228                 :        963 :             aUserItemSz.Height() = aSz.Height();
    1229                 :            :     }
    1230         [ +  - ]:       1924 :     SetUserItemSize( aUserItemSz );
    1231                 :       1924 : }
    1232                 :            : 
    1233                 :            : namespace
    1234                 :            : {
    1235                 :          2 :     long shrinkFontToFit(rtl::OUString &rSampleText, long nH, Font &rFont, OutputDevice &rDevice, Rectangle &rTextRect)
    1236                 :            :     {
    1237                 :          2 :         long nWidth = 0;
    1238                 :            : 
    1239         [ +  - ]:          2 :         Size aSize( rFont.GetSize() );
    1240                 :            : 
    1241                 :            :         //Make sure it fits in the available height
    1242         [ +  - ]:          2 :         while (aSize.Height() > 0)
    1243                 :            :         {
    1244 [ +  - ][ +  - ]:          2 :             if (!rDevice.GetTextBoundRect(rTextRect, rSampleText, 0, 0))
         [ +  - ][ -  + ]
    1245                 :          0 :                 break;
    1246 [ +  - ][ +  - ]:          2 :             if (rTextRect.GetHeight() <= nH)
    1247                 :            :             {
    1248         [ +  - ]:          2 :                 nWidth = rTextRect.GetWidth();
    1249                 :          2 :                 break;
    1250                 :            :             }
    1251                 :            : 
    1252                 :          0 :             aSize.Height() -= EXTRAFONTSIZE;
    1253         [ #  # ]:          0 :             rFont.SetSize(aSize);
    1254         [ #  # ]:          0 :             rDevice.SetFont(rFont);
    1255                 :            :         }
    1256                 :            : 
    1257                 :          2 :         return nWidth;
    1258                 :            :     }
    1259                 :            : }
    1260                 :            : 
    1261                 :            : // -------------------------------------------------------------------
    1262                 :            : 
    1263                 :          2 : void FontNameBox::UserDraw( const UserDrawEvent& rUDEvt )
    1264                 :            : {
    1265                 :          2 :     ImplFontNameListData*   pData = (*mpFontList)[ rUDEvt.GetItemId() ];
    1266                 :          2 :     const FontInfo&         rInfo = pData->maInfo;
    1267                 :          2 :     sal_uInt16                  nType = pData->mnType;
    1268                 :          2 :     Point                   aTopLeft = rUDEvt.GetRect().TopLeft();
    1269                 :          2 :     long                    nX = aTopLeft.X();
    1270         [ +  - ]:          2 :     long                    nH = rUDEvt.GetRect().GetHeight();
    1271                 :            : 
    1272         [ +  - ]:          2 :     if ( mbSymbols )
    1273                 :            :     {
    1274                 :          2 :         nX += IMGINNERTEXTSPACE;
    1275                 :          2 :         Image* pImg = NULL;
    1276         [ -  + ]:          2 :         if ( (nType & (FONTLIST_FONTNAMETYPE_PRINTER | FONTLIST_FONTNAMETYPE_SCREEN)) == FONTLIST_FONTNAMETYPE_PRINTER )
    1277                 :          0 :             pImg = &maImagePrinterFont;
    1278         [ +  - ]:          2 :         else if ( nType & FONTLIST_FONTNAMETYPE_SCALABLE )
    1279                 :          2 :             pImg = &maImageScalableFont;
    1280                 :            :         else
    1281                 :          0 :             pImg = &maImageBitmapFont;
    1282                 :            : 
    1283         [ +  - ]:          2 :         if ( pImg )
    1284                 :            :         {
    1285         [ +  - ]:          2 :             Point aPos( nX, aTopLeft.Y() + (nH-pImg->GetSizePixel().Height())/2 );
    1286         [ +  - ]:          2 :             rUDEvt.GetDevice()->DrawImage( aPos, *pImg );
    1287                 :            :         }
    1288                 :            : 
    1289                 :            :         // X immer um gleiche Breite aendern, auch wenn kein Image ausgegeben.
    1290         [ +  - ]:          2 :         nX += maImagePrinterFont.GetSizePixel().Width();
    1291                 :            :     }
    1292                 :            : 
    1293 [ +  - ][ +  - ]:          2 :     if ( mbWYSIWYG && mpFontList )
    1294                 :            :     {
    1295                 :          2 :         nX += IMGOUTERTEXTSPACE;
    1296                 :            : 
    1297         [ +  - ]:          2 :         const bool bSymbolFont = isSymbolFont(rInfo);
    1298                 :            : 
    1299                 :          2 :         Color aTextColor = rUDEvt.GetDevice()->GetTextColor();
    1300         [ +  - ]:          2 :         Font aOldFont( rUDEvt.GetDevice()->GetFont() );
    1301         [ +  - ]:          2 :         Size aSize( aOldFont.GetSize() );
    1302                 :          2 :         aSize.Height() += EXTRAFONTSIZE;
    1303         [ +  - ]:          2 :         Font aFont( rInfo );
    1304         [ +  - ]:          2 :         aFont.SetSize( aSize );
    1305         [ +  - ]:          2 :         rUDEvt.GetDevice()->SetFont( aFont );
    1306         [ +  - ]:          2 :         rUDEvt.GetDevice()->SetTextColor( aTextColor );
    1307                 :            : 
    1308                 :          2 :         bool bUsingCorrectFont = true;
    1309         [ +  - ]:          2 :         Rectangle aTextRect;
    1310                 :            : 
    1311                 :            :         // Preview the font name
    1312 [ +  - ][ +  - ]:          2 :         rtl::OUString sFontName = rInfo.GetName();
    1313                 :            : 
    1314                 :            :         //If it shouldn't or can't draw its own name because it doesn't have the glyphs
    1315 [ +  - ][ -  + ]:          2 :         if (!canRenderNameOfSelectedFont(*rUDEvt.GetDevice()))
    1316                 :          0 :             bUsingCorrectFont = false;
    1317                 :            :         else
    1318                 :            :         {
    1319                 :            :             //Make sure it fits in the available height, shrinking the font if necessary
    1320         [ +  - ]:          2 :             bUsingCorrectFont = shrinkFontToFit(sFontName, nH, aFont, *rUDEvt.GetDevice(), aTextRect) != 0;
    1321                 :            :         }
    1322                 :            : 
    1323         [ -  + ]:          2 :         if (!bUsingCorrectFont)
    1324                 :            :         {
    1325         [ #  # ]:          0 :             rUDEvt.GetDevice()->SetFont(aOldFont);
    1326 [ #  # ][ #  # ]:          0 :             rUDEvt.GetDevice()->GetTextBoundRect(aTextRect, sFontName, 0, 0);
                 [ #  # ]
    1327                 :            :         }
    1328                 :            : 
    1329         [ +  - ]:          2 :         long nTextHeight = aTextRect.GetHeight();
    1330                 :          2 :         long nDesiredGap = (nH-nTextHeight)/2;
    1331                 :          2 :         long nVertAdjust = nDesiredGap - aTextRect.Top();
    1332                 :          2 :         Point aPos( nX, aTopLeft.Y() + nVertAdjust );
    1333 [ +  - ][ +  - ]:          2 :         rUDEvt.GetDevice()->DrawText( aPos, sFontName );
                 [ +  - ]
    1334         [ +  - ]:          2 :         Rectangle aHack(aPos.X(), aTopLeft.Y() + nH/2 - 5, aPos.X() + 40, aTopLeft.Y() + nH/2 + 5);
    1335         [ +  - ]:          2 :         long nTextX = aPos.X() + aTextRect.GetWidth() + GAPTOEXTRAPREVIEW;
    1336                 :            : 
    1337         [ -  + ]:          2 :         if (!bUsingCorrectFont)
    1338         [ #  # ]:          0 :             rUDEvt.GetDevice()->SetFont( aFont );
    1339                 :            : 
    1340                 :          2 :         rtl::OUString sSampleText;
    1341                 :            : 
    1342         [ +  - ]:          2 :         if (!bSymbolFont)
    1343                 :            :         {
    1344         [ +  - ]:          2 :             const bool bNameBeginsWithLatinText = rInfo.GetName().GetChar(0) <= 'z';
    1345                 :            : 
    1346 [ #  # ][ -  + ]:          2 :             if (bNameBeginsWithLatinText || !bUsingCorrectFont)
    1347         [ +  - ]:          2 :                 sSampleText = makeShortRepresentativeTextForSelectedFont(*rUDEvt.GetDevice());
    1348                 :            :         }
    1349                 :            : 
    1350                 :            :         //If we're not a symbol font, but could neither render our own name and
    1351                 :            :         //we can't determine what script it would like to render, then try a
    1352                 :            :         //few well known scripts
    1353 [ +  - ][ -  + ]:          2 :         if (sSampleText.isEmpty() && !bUsingCorrectFont)
                 [ -  + ]
    1354                 :            :         {
    1355                 :            :             static const UScriptCode aScripts[] =
    1356                 :            :             {
    1357                 :            :                 USCRIPT_ARABIC,
    1358                 :            :                 USCRIPT_HEBREW,
    1359                 :            : 
    1360                 :            :                 USCRIPT_BENGALI,
    1361                 :            :                 USCRIPT_GURMUKHI,
    1362                 :            :                 USCRIPT_GUJARATI,
    1363                 :            :                 USCRIPT_ORIYA,
    1364                 :            :                 USCRIPT_TAMIL,
    1365                 :            :                 USCRIPT_TELUGU,
    1366                 :            :                 USCRIPT_KANNADA,
    1367                 :            :                 USCRIPT_MALAYALAM,
    1368                 :            :                 USCRIPT_SINHALA,
    1369                 :            :                 USCRIPT_DEVANAGARI,
    1370                 :            : 
    1371                 :            :                 USCRIPT_THAI,
    1372                 :            :                 USCRIPT_LAO,
    1373                 :            :                 USCRIPT_GEORGIAN,
    1374                 :            :                 USCRIPT_TIBETAN,
    1375                 :            :                 USCRIPT_SYRIAC,
    1376                 :            :                 USCRIPT_MYANMAR,
    1377                 :            :                 USCRIPT_ETHIOPIC,
    1378                 :            :                 USCRIPT_KHMER,
    1379                 :            :                 USCRIPT_MONGOLIAN,
    1380                 :            : 
    1381                 :            :                 USCRIPT_KOREAN,
    1382                 :            :                 USCRIPT_JAPANESE,
    1383                 :            :                 USCRIPT_HAN,
    1384                 :            :                 USCRIPT_SIMPLIFIED_HAN,
    1385                 :            :                 USCRIPT_TRADITIONAL_HAN,
    1386                 :            : 
    1387                 :            :                 USCRIPT_GREEK
    1388                 :            :             };
    1389                 :            : 
    1390         [ #  # ]:          0 :             for (size_t i = 0; i < SAL_N_ELEMENTS(aScripts); ++i)
    1391                 :            :             {
    1392         [ #  # ]:          0 :                 rtl::OUString sText = makeShortRepresentativeTextForScript(aScripts[i]);
    1393         [ #  # ]:          0 :                 if (!sText.isEmpty())
    1394                 :            :                 {
    1395 [ #  # ][ #  # ]:          0 :                     bool bHasSampleTextGlyphs = (STRING_LEN == rUDEvt.GetDevice()->HasGlyphs(aFont, sText));
                 [ #  # ]
    1396         [ #  # ]:          0 :                     if (bHasSampleTextGlyphs)
    1397                 :            :                     {
    1398                 :          0 :                         sSampleText = sText;
    1399                 :            :                         break;
    1400                 :            :                     }
    1401                 :            :                 }
    1402         [ #  # ]:          0 :             }
    1403                 :            : 
    1404                 :            :             static const UScriptCode aMinimalScripts[] =
    1405                 :            :             {
    1406                 :            :                 USCRIPT_HEBREW, //e.g. biblical hebrew
    1407                 :            :                 USCRIPT_GREEK
    1408                 :            :             };
    1409                 :            : 
    1410         [ #  # ]:          0 :             for (size_t i = 0; i < SAL_N_ELEMENTS(aMinimalScripts); ++i)
    1411                 :            :             {
    1412         [ #  # ]:          0 :                 rtl::OUString sText = makeShortMinimalTextForScript(aMinimalScripts[i]);
    1413         [ #  # ]:          0 :                 if (!sText.isEmpty())
    1414                 :            :                 {
    1415 [ #  # ][ #  # ]:          0 :                     bool bHasSampleTextGlyphs = (STRING_LEN == rUDEvt.GetDevice()->HasGlyphs(aFont, sText));
                 [ #  # ]
    1416         [ #  # ]:          0 :                     if (bHasSampleTextGlyphs)
    1417                 :            :                     {
    1418                 :          0 :                         sSampleText = sText;
    1419                 :            :                         break;
    1420                 :            :                     }
    1421                 :            :                 }
    1422         [ #  # ]:          0 :             }
    1423                 :            :         }
    1424                 :            : 
    1425                 :            :         //If we're a symbol font, or for some reason the font still couldn't
    1426                 :            :         //render something representative of what it would like to render then
    1427                 :            :         //make up some semi-random text that it *can* display
    1428 [ +  - ][ -  + ]:          2 :         if (bSymbolFont || (!bUsingCorrectFont && sSampleText.isEmpty()))
         [ #  # ][ -  + ]
    1429         [ #  # ]:          0 :             sSampleText = makeShortRepresentativeSymbolTextForSelectedFont(*rUDEvt.GetDevice());
    1430                 :            : 
    1431         [ -  + ]:          2 :         if (!sSampleText.isEmpty())
    1432                 :            :         {
    1433         [ #  # ]:          0 :             const Size &rItemSize = rUDEvt.GetDevice()->GetOutputSize();
    1434                 :            :             //leave a little border at the edge
    1435                 :          0 :             long nSpace = rItemSize.Width() - nTextX - IMGOUTERTEXTSPACE;
    1436         [ #  # ]:          0 :             if (nSpace >= 0)
    1437                 :            :             {
    1438                 :            :                 //Make sure it fits in the available height, and get how wide that would be
    1439         [ #  # ]:          0 :                 long nWidth = shrinkFontToFit(sSampleText, nH, aFont, *rUDEvt.GetDevice(), aTextRect);
    1440                 :            :                 //Chop letters off until it fits in the available width
    1441 [ #  # ][ #  # ]:          0 :                 while (nWidth > nSpace || nWidth > MAXPREVIEWWIDTH)
                 [ #  # ]
    1442                 :            :                 {
    1443                 :          0 :                     sSampleText = sSampleText.copy(0, sSampleText.getLength()-1);
    1444 [ #  # ][ #  # ]:          0 :                     nWidth = rUDEvt.GetDevice()->GetTextBoundRect(aTextRect, sSampleText, 0, 0) ?
                 [ #  # ]
    1445 [ #  # ][ #  # ]:          0 :                              aTextRect.GetWidth() : 0;
    1446                 :            :                 }
    1447                 :            : 
    1448                 :            :                 //center the text on the line
    1449 [ #  # ][ #  # ]:          0 :                 if (!sSampleText.isEmpty() && nWidth)
                 [ #  # ]
    1450                 :            :                 {
    1451         [ #  # ]:          0 :                     nTextHeight = aTextRect.GetHeight();
    1452                 :          0 :                     nDesiredGap = (nH-nTextHeight)/2;
    1453                 :          0 :                     nVertAdjust = nDesiredGap - aTextRect.Top();
    1454                 :          0 :                     aPos = Point(nTextX + nSpace - nWidth, aTopLeft.Y() + nVertAdjust);
    1455 [ #  # ][ #  # ]:          0 :                     rUDEvt.GetDevice()->DrawText( aPos, sSampleText );
                 [ #  # ]
    1456                 :            :                 }
    1457                 :            :             }
    1458                 :            :         }
    1459                 :            : 
    1460         [ +  - ]:          2 :         rUDEvt.GetDevice()->SetFont( aOldFont );
    1461 [ +  - ][ +  - ]:          2 :         DrawEntry( rUDEvt, sal_False, sal_False);   // draw seperator
                 [ +  - ]
    1462                 :            :     }
    1463                 :            :     else
    1464                 :            :     {
    1465         [ #  # ]:          0 :         DrawEntry( rUDEvt, sal_True, sal_True );
    1466                 :            :     }
    1467                 :          2 : }
    1468                 :            : 
    1469                 :            : // ===================================================================
    1470                 :            : // FontStyleBox
    1471                 :            : // ===================================================================
    1472                 :            : 
    1473                 :          0 : FontStyleBox::FontStyleBox( Window* pParent, const ResId& rResId ) :
    1474         [ #  # ]:          0 :     ComboBox( pParent, rResId )
    1475                 :            : {
    1476 [ #  # ][ #  # ]:          0 :     aLastStyle = GetText();
                 [ #  # ]
    1477                 :          0 : }
    1478                 :            : 
    1479                 :            : // -------------------------------------------------------------------
    1480                 :            : 
    1481         [ #  # ]:          0 : FontStyleBox::~FontStyleBox()
    1482                 :            : {
    1483         [ #  # ]:          0 : }
    1484                 :            : 
    1485                 :            : // -------------------------------------------------------------------
    1486                 :            : 
    1487                 :          0 : void FontStyleBox::Select()
    1488                 :            : {
    1489                 :            :     // keep text over fill operation
    1490         [ #  # ]:          0 :     aLastStyle = GetText();
    1491                 :          0 :     ComboBox::Select();
    1492                 :          0 : }
    1493                 :            : 
    1494                 :            : // -------------------------------------------------------------------
    1495                 :            : 
    1496                 :          0 : void FontStyleBox::LoseFocus()
    1497                 :            : {
    1498                 :            :     // keep text over fill operation
    1499         [ #  # ]:          0 :     aLastStyle = GetText();
    1500                 :          0 :     ComboBox::LoseFocus();
    1501                 :          0 : }
    1502                 :            : 
    1503                 :            : // -------------------------------------------------------------------
    1504                 :            : 
    1505                 :          0 : void FontStyleBox::Modify()
    1506                 :            : {
    1507                 :            :     CharClass   aChrCls( ::comphelper::getProcessServiceFactory(),
    1508 [ #  # ][ #  # ]:          0 :                         GetSettings().GetLocale() );
                 [ #  # ]
    1509         [ #  # ]:          0 :     XubString   aStr = GetText();
    1510         [ #  # ]:          0 :     sal_uInt16      nEntryCount = GetEntryCount();
    1511                 :            : 
    1512 [ #  # ][ #  # ]:          0 :     if ( GetEntryPos( aStr ) == COMBOBOX_ENTRY_NOTFOUND )
    1513                 :            :     {
    1514 [ #  # ][ #  # ]:          0 :         aStr = aChrCls.uppercase(aStr);
                 [ #  # ]
    1515         [ #  # ]:          0 :         for ( sal_uInt16 i = 0; i < nEntryCount; i++ )
    1516                 :            :         {
    1517 [ #  # ][ #  # ]:          0 :             XubString aEntryText = aChrCls.uppercase(GetEntry(i));
         [ #  # ][ #  # ]
                 [ #  # ]
    1518                 :            : 
    1519 [ #  # ][ #  # ]:          0 :             if ( aStr == aEntryText )
    1520                 :            :             {
    1521 [ #  # ][ #  # ]:          0 :                 SetText( GetEntry( i ) );
                 [ #  # ]
    1522                 :            :                 break;
    1523                 :            :             }
    1524 [ #  # ][ #  # ]:          0 :         }
    1525                 :            :     }
    1526                 :            : 
    1527 [ #  # ][ #  # ]:          0 :     ComboBox::Modify();
                 [ #  # ]
    1528                 :          0 : }
    1529                 :            : 
    1530                 :            : // -------------------------------------------------------------------
    1531                 :            : 
    1532                 :          0 : void FontStyleBox::Fill( const XubString& rName, const FontList* pList )
    1533                 :            : {
    1534                 :            :     // note: this method must call ComboBox::SetText(),
    1535                 :            :     //   else aLastStyle will overwritten
    1536                 :            :     // store prior selection position and clear box
    1537         [ #  # ]:          0 :     XubString aOldText = GetText();
    1538         [ #  # ]:          0 :     sal_uInt16 nPos = GetEntryPos( aOldText );
    1539         [ #  # ]:          0 :     Clear();
    1540                 :            : 
    1541                 :            :     // does a font with this name already exist?
    1542         [ #  # ]:          0 :     sal_Handle hFontInfo = pList->GetFirstFontInfo( rName );
    1543         [ #  # ]:          0 :     if ( hFontInfo )
    1544                 :            :     {
    1545         [ #  # ]:          0 :         XubString   aStyleText;
    1546                 :          0 :         FontWeight  eLastWeight = WEIGHT_DONTKNOW;
    1547                 :          0 :         FontItalic  eLastItalic = ITALIC_NONE;
    1548                 :          0 :         FontWidth   eLastWidth = WIDTH_DONTKNOW;
    1549                 :          0 :         sal_Bool        bNormal = sal_False;
    1550                 :          0 :         sal_Bool        bItalic = sal_False;
    1551                 :          0 :         sal_Bool        bBold = sal_False;
    1552                 :          0 :         sal_Bool        bBoldItalic = sal_False;
    1553                 :          0 :         sal_Bool        bInsert = sal_False;
    1554         [ #  # ]:          0 :         FontInfo    aInfo;
    1555         [ #  # ]:          0 :         while ( hFontInfo )
    1556                 :            :         {
    1557 [ #  # ][ #  # ]:          0 :             aInfo = pList->GetFontInfo( hFontInfo );
    1558                 :            : 
    1559         [ #  # ]:          0 :             FontWeight  eWeight = aInfo.GetWeight();
    1560         [ #  # ]:          0 :             FontItalic  eItalic = aInfo.GetItalic();
    1561         [ #  # ]:          0 :             FontWidth   eWidth = aInfo.GetWidthType();
    1562                 :            :             // Only if the attributes are different, we insert the
    1563                 :            :             // Font to avoid double Entries in different languages
    1564 [ #  # ][ #  # ]:          0 :             if ( (eWeight != eLastWeight) || (eItalic != eLastItalic) ||
                 [ #  # ]
    1565                 :            :                  (eWidth != eLastWidth) )
    1566                 :            :             {
    1567         [ #  # ]:          0 :                 if ( bInsert )
    1568         [ #  # ]:          0 :                     InsertEntry( aStyleText );
    1569                 :            : 
    1570         [ #  # ]:          0 :                 if ( eWeight <= WEIGHT_NORMAL )
    1571                 :            :                 {
    1572         [ #  # ]:          0 :                     if ( eItalic != ITALIC_NONE )
    1573                 :          0 :                         bItalic = sal_True;
    1574                 :            :                     else
    1575                 :          0 :                         bNormal = sal_True;
    1576                 :            :                 }
    1577                 :            :                 else
    1578                 :            :                 {
    1579         [ #  # ]:          0 :                     if ( eItalic != ITALIC_NONE )
    1580                 :          0 :                         bBoldItalic = sal_True;
    1581                 :            :                     else
    1582                 :          0 :                         bBold = sal_True;
    1583                 :            :                 }
    1584                 :            : 
    1585                 :            :                 // For wrong StyleNames we replace this with the correct once
    1586 [ #  # ][ #  # ]:          0 :                 aStyleText = pList->GetStyleName( aInfo );
                 [ #  # ]
    1587         [ #  # ]:          0 :                 bInsert = GetEntryPos( aStyleText ) == LISTBOX_ENTRY_NOTFOUND;
    1588         [ #  # ]:          0 :                 if ( !bInsert )
    1589                 :            :                 {
    1590 [ #  # ][ #  # ]:          0 :                     aStyleText = pList->GetStyleName( eWeight, eItalic );
    1591         [ #  # ]:          0 :                     bInsert = GetEntryPos( aStyleText ) == LISTBOX_ENTRY_NOTFOUND;
    1592                 :            :                 }
    1593                 :            : 
    1594                 :          0 :                 eLastWeight = eWeight;
    1595                 :          0 :                 eLastItalic = eItalic;
    1596                 :          0 :                 eLastWidth = eWidth;
    1597                 :            :             }
    1598                 :            :             else
    1599                 :            :             {
    1600         [ #  # ]:          0 :                 if ( bInsert )
    1601                 :            :                 {
    1602                 :            :                     // If we have two names for the same attributes
    1603                 :            :                     // we prefer the translated standard names
    1604         [ #  # ]:          0 :                     const XubString& rAttrStyleText = pList->GetStyleName( eWeight, eItalic );
    1605 [ #  # ][ #  # ]:          0 :                     if ( rAttrStyleText != aStyleText )
    1606                 :            :                     {
    1607         [ #  # ]:          0 :                         XubString aTempStyleText = pList->GetStyleName( aInfo );
    1608 [ #  # ][ #  # ]:          0 :                         if ( rAttrStyleText == aTempStyleText )
    1609         [ #  # ]:          0 :                             aStyleText = rAttrStyleText;
    1610 [ #  # ][ #  # ]:          0 :                         bInsert = GetEntryPos( aStyleText ) == LISTBOX_ENTRY_NOTFOUND;
    1611                 :            :                     }
    1612                 :            :                 }
    1613                 :            :             }
    1614                 :            : 
    1615 [ #  # ][ #  # ]:          0 :             if ( !bItalic && (aStyleText == pList->GetItalicStr()) )
         [ #  # ][ #  # ]
    1616                 :          0 :                 bItalic = sal_True;
    1617 [ #  # ][ #  # ]:          0 :             else if ( !bBold && (aStyleText == pList->GetBoldStr()) )
         [ #  # ][ #  # ]
    1618                 :          0 :                 bBold = sal_True;
    1619 [ #  # ][ #  # ]:          0 :             else if ( !bBoldItalic && (aStyleText == pList->GetBoldItalicStr()) )
         [ #  # ][ #  # ]
    1620                 :          0 :                 bBoldItalic = sal_True;
    1621                 :            : 
    1622         [ #  # ]:          0 :             hFontInfo = pList->GetNextFontInfo( hFontInfo );
    1623                 :            :         }
    1624                 :            : 
    1625         [ #  # ]:          0 :         if ( bInsert )
    1626         [ #  # ]:          0 :             InsertEntry( aStyleText );
    1627                 :            : 
    1628                 :            :         // Bestimmte Styles als Nachbildung
    1629         [ #  # ]:          0 :         if ( bNormal )
    1630                 :            :         {
    1631         [ #  # ]:          0 :             if ( !bItalic )
    1632         [ #  # ]:          0 :                 InsertEntry( pList->GetItalicStr() );
    1633         [ #  # ]:          0 :             if ( !bBold )
    1634         [ #  # ]:          0 :                 InsertEntry( pList->GetBoldStr() );
    1635                 :            :         }
    1636         [ #  # ]:          0 :         if ( !bBoldItalic )
    1637                 :            :         {
    1638 [ #  # ][ #  # ]:          0 :             if ( bNormal || bItalic || bBold )
                 [ #  # ]
    1639         [ #  # ]:          0 :                 InsertEntry( pList->GetBoldItalicStr() );
    1640                 :            :         }
    1641         [ #  # ]:          0 :         if ( aOldText.Len() )
    1642                 :            :         {
    1643 [ #  # ][ #  # ]:          0 :             if ( GetEntryPos( aLastStyle ) != LISTBOX_ENTRY_NOTFOUND )
    1644         [ #  # ]:          0 :                 ComboBox::SetText( aLastStyle );
    1645                 :            :             else
    1646                 :            :             {
    1647 [ #  # ][ #  # ]:          0 :                 if ( nPos >= GetEntryCount() )
    1648 [ #  # ][ #  # ]:          0 :                     ComboBox::SetText( GetEntry( 0 ) );
                 [ #  # ]
    1649                 :            :                 else
    1650 [ #  # ][ #  # ]:          0 :                     ComboBox::SetText( GetEntry( nPos ) );
                 [ #  # ]
    1651                 :            :             }
    1652 [ #  # ][ #  # ]:          0 :         }
    1653                 :            :     }
    1654                 :            :     else
    1655                 :            :     {
    1656                 :            :         // Wenn Font nicht, dann Standard-Styles einfuegen
    1657         [ #  # ]:          0 :         InsertEntry( pList->GetNormalStr() );
    1658         [ #  # ]:          0 :         InsertEntry( pList->GetItalicStr() );
    1659         [ #  # ]:          0 :         InsertEntry( pList->GetBoldStr() );
    1660         [ #  # ]:          0 :         InsertEntry( pList->GetBoldItalicStr() );
    1661         [ #  # ]:          0 :         if ( aOldText.Len() )
    1662                 :            :         {
    1663 [ #  # ][ #  # ]:          0 :             if ( nPos > GetEntryCount() )
    1664 [ #  # ][ #  # ]:          0 :                 ComboBox::SetText( GetEntry( 0 ) );
                 [ #  # ]
    1665                 :            :             else
    1666 [ #  # ][ #  # ]:          0 :                 ComboBox::SetText( GetEntry( nPos ) );
                 [ #  # ]
    1667                 :            :         }
    1668         [ #  # ]:          0 :     }
    1669                 :          0 : }
    1670                 :            : 
    1671                 :            : // ===================================================================
    1672                 :            : // FontSizeBox
    1673                 :            : // ===================================================================
    1674                 :            : 
    1675                 :        961 : FontSizeBox::FontSizeBox( Window* pParent, WinBits nWinSize ) :
    1676         [ +  - ]:        961 :     MetricBox( pParent, nWinSize )
    1677                 :            : {
    1678         [ +  - ]:        961 :     ImplInit();
    1679                 :        961 : }
    1680                 :            : 
    1681                 :            : // -----------------------------------------------------------------------
    1682                 :            : 
    1683                 :          0 : FontSizeBox::FontSizeBox( Window* pParent, const ResId& rResId ) :
    1684         [ #  # ]:          0 :     MetricBox( pParent, rResId )
    1685                 :            : {
    1686         [ #  # ]:          0 :     ImplInit();
    1687                 :          0 : }
    1688                 :            : 
    1689                 :            : // -----------------------------------------------------------------------
    1690                 :            : 
    1691         [ +  - ]:        961 : FontSizeBox::~FontSizeBox()
    1692                 :            : {
    1693         [ -  + ]:        961 : }
    1694                 :            : 
    1695                 :            : // -----------------------------------------------------------------------
    1696                 :            : 
    1697                 :        961 : void FontSizeBox::ImplInit()
    1698                 :            : {
    1699                 :        961 :     EnableAutocomplete( sal_False );
    1700                 :            : 
    1701                 :        961 :     bRelativeMode   = sal_False;
    1702                 :        961 :     bPtRelative     = sal_False;
    1703                 :        961 :     bRelative       = sal_False;
    1704                 :        961 :     bStdSize        = sal_False;
    1705                 :        961 :     pFontList       = NULL;
    1706                 :            : 
    1707                 :        961 :     SetShowTrailingZeros( sal_False );
    1708                 :        961 :     SetDecimalDigits( 1 );
    1709                 :        961 :     SetMin( 20 );
    1710                 :        961 :     SetMax( 9999 );
    1711                 :        961 :     SetProminentEntryType( PROMINENT_MIDDLE );
    1712                 :        961 : }
    1713                 :            : 
    1714                 :            : // -----------------------------------------------------------------------
    1715                 :            : 
    1716                 :          0 : void FontSizeBox::Reformat()
    1717                 :            : {
    1718 [ #  # ][ #  # ]:          0 :     FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
    1719 [ #  # ][ #  # ]:          0 :     if ( !bRelativeMode || !aFontSizeNames.IsEmpty() )
                 [ #  # ]
    1720                 :            :     {
    1721 [ #  # ][ #  # ]:          0 :         long nNewValue = aFontSizeNames.Name2Size( GetText() );
                 [ #  # ]
    1722         [ #  # ]:          0 :         if ( nNewValue)
    1723                 :            :         {
    1724                 :          0 :             mnLastValue = nNewValue;
    1725                 :          0 :             return;
    1726                 :            :         }
    1727                 :            :     }
    1728                 :            : 
    1729         [ #  # ]:          0 :     MetricBox::Reformat();
    1730                 :            : }
    1731                 :            : 
    1732                 :            : // -----------------------------------------------------------------------
    1733                 :            : 
    1734                 :          0 : void FontSizeBox::Modify()
    1735                 :            : {
    1736                 :          0 :     MetricBox::Modify();
    1737                 :            : 
    1738         [ #  # ]:          0 :     if ( bRelativeMode )
    1739                 :            :     {
    1740 [ #  # ][ #  # ]:          0 :         XubString aStr = comphelper::string::stripStart(GetText(), ' ');
         [ #  # ][ #  # ]
                 [ #  # ]
    1741                 :            : 
    1742                 :          0 :         sal_Bool bNewMode = bRelative;
    1743                 :          0 :         sal_Bool bOldPtRelMode = bPtRelative;
    1744                 :            : 
    1745         [ #  # ]:          0 :         if ( bRelative )
    1746                 :            :         {
    1747                 :          0 :             bPtRelative = sal_False;
    1748                 :          0 :             const xub_Unicode* pStr = aStr.GetBuffer();
    1749         [ #  # ]:          0 :             while ( *pStr )
    1750                 :            :             {
    1751 [ #  # ][ #  # ]:          0 :                 if ( ((*pStr < '0') || (*pStr > '9')) && (*pStr != '%') )
                 [ #  # ]
    1752                 :            :                 {
    1753 [ #  # ][ #  # ]:          0 :                     if ( ('-' == *pStr || '+' == *pStr) && !bPtRelative )
                 [ #  # ]
    1754                 :          0 :                         bPtRelative = sal_True;
    1755 [ #  # ][ #  # ]:          0 :                     else if ( bPtRelative && 'p' == *pStr && 't' == *++pStr )
         [ #  # ][ #  # ]
    1756                 :            :                         ;
    1757                 :            :                     else
    1758                 :            :                     {
    1759                 :          0 :                         bNewMode = sal_False;
    1760                 :          0 :                         break;
    1761                 :            :                     }
    1762                 :            :                 }
    1763                 :          0 :                 pStr++;
    1764                 :            :             }
    1765                 :            :         }
    1766                 :            :         else
    1767                 :            :         {
    1768 [ #  # ][ #  # ]:          0 :             if ( STRING_NOTFOUND != aStr.Search( '%' ) )
    1769                 :            :             {
    1770                 :          0 :                 bNewMode = sal_True;
    1771                 :          0 :                 bPtRelative = sal_False;
    1772                 :            :             }
    1773                 :            : 
    1774 [ #  # ][ #  # ]:          0 :             if ( '-' == aStr.GetChar( 0 ) || '+' == aStr.GetChar( 0 ) )
                 [ #  # ]
    1775                 :            :             {
    1776                 :          0 :                 bNewMode = sal_True;
    1777                 :          0 :                 bPtRelative = sal_True;
    1778                 :            :             }
    1779                 :            :         }
    1780                 :            : 
    1781 [ #  # ][ #  # ]:          0 :         if ( bNewMode != bRelative || bPtRelative != bOldPtRelMode )
    1782 [ #  # ][ #  # ]:          0 :             SetRelative( bNewMode );
    1783                 :            :     }
    1784                 :          0 : }
    1785                 :            : 
    1786                 :            : // -----------------------------------------------------------------------
    1787                 :            : 
    1788                 :       1481 : void FontSizeBox::Fill( const FontInfo* pInfo, const FontList* pList )
    1789                 :            : {
    1790                 :            :     // remember for relative mode
    1791                 :       1481 :     pFontList = pList;
    1792                 :            : 
    1793                 :            :     // no font sizes need to be set for relative mode
    1794         [ +  - ]:       1481 :     if ( bRelative )
    1795                 :            :         return;
    1796                 :            : 
    1797                 :            :     // query font sizes
    1798                 :            :     const long* pTempAry;
    1799                 :       1481 :     const long* pAry = 0;
    1800                 :            : 
    1801         [ +  - ]:       1481 :     if( pInfo )
    1802                 :            :     {
    1803         [ +  - ]:       1481 :         aFontInfo = *pInfo;
    1804         [ +  - ]:       1481 :         pAry = pList->GetSizeAry( *pInfo );
    1805                 :            :     }
    1806                 :            :     else
    1807                 :            :     {
    1808         [ #  # ]:          0 :         pAry = pList->GetStdSizeAry();
    1809                 :            :     }
    1810                 :            : 
    1811                 :            :     // first insert font size names (for simplified/traditional chinese)
    1812 [ +  - ][ +  - ]:       1481 :     FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
    1813 [ +  - ][ +  - ]:       1481 :     if ( pAry == pList->GetStdSizeAry() )
    1814                 :            :     {
    1815                 :            :         // for standard sizes we don't need to bother
    1816 [ +  + ][ +  - ]:       1481 :         if ( bStdSize && GetEntryCount() && aFontSizeNames.IsEmpty() )
         [ +  - ][ +  - ]
                 [ +  + ]
    1817                 :            :             return;
    1818                 :        939 :         bStdSize = sal_True;
    1819                 :            :     }
    1820                 :            :     else
    1821                 :          0 :         bStdSize = sal_False;
    1822                 :            : 
    1823         [ +  - ]:        939 :     Selection aSelection = GetSelection();
    1824         [ +  - ]:        939 :     XubString aStr = GetText();
    1825                 :            : 
    1826         [ +  - ]:        939 :     Clear();
    1827                 :        939 :     sal_uInt16 nPos = 0;
    1828                 :            : 
    1829         [ -  + ]:        939 :     if ( !aFontSizeNames.IsEmpty() )
    1830                 :            :     {
    1831 [ #  # ][ #  # ]:          0 :         if ( pAry == pList->GetStdSizeAry() )
    1832                 :            :         {
    1833                 :            :             // for scalable fonts all font size names
    1834                 :          0 :             sal_uLong nCount = aFontSizeNames.Count();
    1835         [ #  # ]:          0 :             for( sal_uLong i = 0; i < nCount; i++ )
    1836                 :            :             {
    1837         [ #  # ]:          0 :                 String  aSizeName = aFontSizeNames.GetIndexName( i );
    1838         [ #  # ]:          0 :                 long    nSize = aFontSizeNames.GetIndexSize( i );
    1839         [ #  # ]:          0 :                 ComboBox::InsertEntry( aSizeName, nPos );
    1840         [ #  # ]:          0 :                 ComboBox::SetEntryData( nPos, (void*)(-nSize) ); // mark as special
    1841                 :          0 :                 nPos++;
    1842         [ #  # ]:          0 :             }
    1843                 :            :         }
    1844                 :            :         else
    1845                 :            :         {
    1846                 :            :             // for fixed size fonts only selectable font size names
    1847                 :          0 :             pTempAry = pAry;
    1848         [ #  # ]:          0 :             while ( *pTempAry )
    1849                 :            :             {
    1850         [ #  # ]:          0 :                 String aSizeName = aFontSizeNames.Size2Name( *pTempAry );
    1851         [ #  # ]:          0 :                 if ( aSizeName.Len() )
    1852                 :            :                 {
    1853         [ #  # ]:          0 :                     ComboBox::InsertEntry( aSizeName, nPos );
    1854         [ #  # ]:          0 :                     ComboBox::SetEntryData( nPos, (void*)(-(*pTempAry)) ); // mark as special
    1855                 :          0 :                     nPos++;
    1856                 :            :                 }
    1857                 :          0 :                 pTempAry++;
    1858         [ #  # ]:          0 :             }
    1859                 :            :         }
    1860                 :            :     }
    1861                 :            : 
    1862                 :            :     // then insert numerical font size values
    1863                 :        939 :     pTempAry = pAry;
    1864         [ +  + ]:      29109 :     while ( *pTempAry )
    1865                 :            :     {
    1866         [ +  - ]:      28170 :         InsertValue( *pTempAry, FUNIT_NONE, nPos );
    1867         [ +  - ]:      28170 :         ComboBox::SetEntryData( nPos, (void*)(*pTempAry) );
    1868                 :      28170 :         nPos++;
    1869                 :      28170 :         pTempAry++;
    1870                 :            :     }
    1871                 :            : 
    1872         [ +  - ]:        939 :     SetText( aStr );
    1873 [ +  - ][ +  - ]:       1481 :     SetSelection( aSelection );
    1874                 :            : }
    1875                 :            : 
    1876                 :            : // -----------------------------------------------------------------------
    1877                 :            : 
    1878                 :          0 : void FontSizeBox::EnableRelativeMode( sal_uInt16 nMin, sal_uInt16 nMax, sal_uInt16 nStep )
    1879                 :            : {
    1880                 :          0 :     bRelativeMode = sal_True;
    1881                 :          0 :     nRelMin       = nMin;
    1882                 :          0 :     nRelMax       = nMax;
    1883                 :          0 :     nRelStep      = nStep;
    1884                 :          0 :     SetUnit( FUNIT_POINT );
    1885                 :          0 : }
    1886                 :            : 
    1887                 :            : // -----------------------------------------------------------------------
    1888                 :            : 
    1889                 :          0 : void FontSizeBox::EnablePtRelativeMode( short nMin, short nMax, short nStep )
    1890                 :            : {
    1891                 :          0 :     bRelativeMode = sal_True;
    1892                 :          0 :     nPtRelMin     = nMin;
    1893                 :          0 :     nPtRelMax     = nMax;
    1894                 :          0 :     nPtRelStep    = nStep;
    1895                 :          0 :     SetUnit( FUNIT_POINT );
    1896                 :          0 : }
    1897                 :            : 
    1898                 :            : // -----------------------------------------------------------------------
    1899                 :            : 
    1900                 :          0 : void FontSizeBox::SetRelative( sal_Bool bNewRelative )
    1901                 :            : {
    1902         [ #  # ]:          0 :     if ( bRelativeMode )
    1903                 :            :     {
    1904         [ #  # ]:          0 :         Selection aSelection = GetSelection();
    1905 [ #  # ][ #  # ]:          0 :         XubString aStr = comphelper::string::stripStart(GetText(), ' ');
         [ #  # ][ #  # ]
                 [ #  # ]
    1906                 :            : 
    1907         [ #  # ]:          0 :         if ( bNewRelative )
    1908                 :            :         {
    1909                 :          0 :             bRelative = sal_True;
    1910                 :          0 :             bStdSize = sal_False;
    1911                 :            : 
    1912         [ #  # ]:          0 :             if ( bPtRelative )
    1913                 :            :             {
    1914         [ #  # ]:          0 :                 SetDecimalDigits( 1 );
    1915         [ #  # ]:          0 :                 SetMin( nPtRelMin );
    1916         [ #  # ]:          0 :                 SetMax( nPtRelMax );
    1917         [ #  # ]:          0 :                 SetUnit( FUNIT_POINT );
    1918                 :            : 
    1919         [ #  # ]:          0 :                 Clear();
    1920                 :            : 
    1921                 :          0 :                 short i = nPtRelMin, n = 0;
    1922                 :            :                 // JP 30.06.98: more than 100 values are not useful
    1923 [ #  # ][ #  # ]:          0 :                 while ( i <= nPtRelMax && n++ < 100 )
                 [ #  # ]
    1924                 :            :                 {
    1925         [ #  # ]:          0 :                     InsertValue( i );
    1926                 :          0 :                     i = i + nPtRelStep;
    1927                 :            :                 }
    1928                 :            :             }
    1929                 :            :             else
    1930                 :            :             {
    1931         [ #  # ]:          0 :                 SetDecimalDigits( 0 );
    1932         [ #  # ]:          0 :                 SetMin( nRelMin );
    1933         [ #  # ]:          0 :                 SetMax( nRelMax );
    1934 [ #  # ][ #  # ]:          0 :                 SetCustomUnitText(rtl::OUString('%'));
                 [ #  # ]
    1935         [ #  # ]:          0 :                 SetUnit( FUNIT_CUSTOM );
    1936                 :            : 
    1937         [ #  # ]:          0 :                 Clear();
    1938                 :          0 :                 sal_uInt16 i = nRelMin;
    1939         [ #  # ]:          0 :                 while ( i <= nRelMax )
    1940                 :            :                 {
    1941         [ #  # ]:          0 :                     InsertValue( i );
    1942                 :          0 :                     i = i + nRelStep;
    1943                 :            :                 }
    1944                 :            :             }
    1945                 :            :         }
    1946                 :            :         else
    1947                 :            :         {
    1948                 :          0 :             bRelative = bPtRelative = sal_False;
    1949         [ #  # ]:          0 :             SetDecimalDigits( 1 );
    1950         [ #  # ]:          0 :             SetMin( 20 );
    1951         [ #  # ]:          0 :             SetMax( 9999 );
    1952         [ #  # ]:          0 :             SetUnit( FUNIT_POINT );
    1953         [ #  # ]:          0 :             if ( pFontList )
    1954         [ #  # ]:          0 :                 Fill( &aFontInfo, pFontList );
    1955                 :            :         }
    1956                 :            : 
    1957         [ #  # ]:          0 :         SetText( aStr );
    1958 [ #  # ][ #  # ]:          0 :         SetSelection( aSelection );
    1959                 :            :     }
    1960                 :          0 : }
    1961                 :            : 
    1962                 :            : // -----------------------------------------------------------------------
    1963                 :            : 
    1964                 :      35401 : XubString FontSizeBox::CreateFieldText( sal_Int64 nValue ) const
    1965                 :            : {
    1966                 :      35401 :     XubString sRet( MetricBox::CreateFieldText( nValue ) );
    1967 [ #  # ][ #  # ]:      35401 :     if ( bRelativeMode && bPtRelative && (0 <= nValue) && sRet.Len() )
         [ #  # ][ -  + ]
                 [ -  + ]
    1968         [ #  # ]:          0 :         sRet.Insert( '+', 0 );
    1969                 :      35401 :     return sRet;
    1970                 :            : }
    1971                 :            : 
    1972                 :            : // -----------------------------------------------------------------------
    1973                 :            : 
    1974                 :       3387 : void FontSizeBox::SetValue( sal_Int64 nNewValue, FieldUnit eInUnit )
    1975                 :            : {
    1976         [ +  - ]:       3387 :     if ( !bRelative )
    1977                 :            :     {
    1978 [ +  - ][ +  - ]:       3387 :         sal_Int64 nTempValue = MetricField::ConvertValue( nNewValue, GetBaseValue(), GetDecimalDigits(), eInUnit, GetUnit() );
                 [ +  - ]
    1979 [ +  - ][ +  - ]:       3387 :         FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
    1980                 :            :         // conversion loses precision; however font sizes should
    1981                 :            :         // never have a problem with that
    1982         [ +  - ]:       3387 :         String aName = aFontSizeNames.Size2Name( static_cast<long>(nTempValue) );
    1983 [ -  + ][ #  # ]:       3387 :         if ( aName.Len() && (GetEntryPos( aName ) != LISTBOX_ENTRY_NOTFOUND) )
         [ #  # ][ -  + ]
    1984                 :            :         {
    1985                 :          0 :             mnLastValue = nTempValue;
    1986         [ #  # ]:          0 :             SetText( aName );
    1987                 :          0 :             mnFieldValue = mnLastValue;
    1988                 :       3387 :             SetEmptyFieldValueData( sal_False );
    1989                 :       3387 :             return;
    1990 [ +  - ][ +  - ]:       3387 :         }
    1991                 :            :     }
    1992                 :            : 
    1993                 :       3387 :     MetricBox::SetValue( nNewValue, eInUnit );
    1994                 :            : }
    1995                 :            : 
    1996                 :            : // -----------------------------------------------------------------------
    1997                 :            : 
    1998                 :       3387 : void FontSizeBox::SetValue( sal_Int64 nNewValue )
    1999                 :            : {
    2000                 :       3387 :     SetValue( nNewValue, FUNIT_NONE );
    2001                 :       3387 : }
    2002                 :            : 
    2003                 :       2963 : sal_Int64 FontSizeBox::GetValue( FieldUnit eOutUnit ) const
    2004                 :            : {
    2005         [ +  - ]:       2963 :     if ( !bRelative )
    2006                 :            :     {
    2007 [ +  - ][ +  - ]:       2963 :         FontSizeNames aFontSizeNames( GetSettings().GetUILanguage() );
    2008 [ +  - ][ +  - ]:       2963 :         sal_Int64 nValue = aFontSizeNames.Name2Size( GetText() );
                 [ +  - ]
    2009         [ -  + ]:       2963 :         if ( nValue)
    2010 [ #  # ][ #  # ]:       2963 :             return MetricField::ConvertValue( nValue, GetBaseValue(), GetDecimalDigits(), GetUnit(), eOutUnit );
                 [ #  # ]
    2011                 :            :     }
    2012                 :            : 
    2013                 :       2963 :     return MetricBox::GetValue( eOutUnit );
    2014                 :            : }
    2015                 :            : 
    2016                 :            : // -----------------------------------------------------------------------
    2017                 :            : 
    2018                 :       2963 : sal_Int64 FontSizeBox::GetValue() const
    2019                 :            : {
    2020                 :            :     // implementation not inline, because it is a virtual function
    2021                 :       2963 :     return GetValue( FUNIT_NONE );
    2022                 :            : }
    2023                 :            : 
    2024                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10