LCOV - code coverage report
Current view: top level - starmath/source - utility.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 154 30.5 %
Date: 2012-08-25 Functions: 13 35 37.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 30 156 19.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include <sfx2/app.hxx>
      21                 :            : #include <vcl/virdev.hxx>
      22                 :            : #include <tools/string.hxx>
      23                 :            : #include <tools/tenccvt.hxx>
      24                 :            : #include <osl/thread.h>
      25                 :            : 
      26                 :            : #include <tools/stream.hxx>
      27                 :            : 
      28                 :            : #include "starmath.hrc"
      29                 :            : 
      30                 :            : #include "utility.hxx"
      31                 :            : #include "dialog.hxx"
      32                 :            : #include "view.hxx"
      33                 :            : #include "smdll.hxx"
      34                 :            : 
      35                 :            : 
      36                 :            : ////////////////////////////////////////////////////////////
      37                 :            : 
      38                 :            : // return pointer to active SmViewShell, if this is not possible
      39                 :            : // return 0 instead.
      40                 :            : //!! Since this method is based on the current focus it is somewhat
      41                 :            : //!! unreliable and may return unexpected 0 pointers!
      42                 :       2142 : SmViewShell * SmGetActiveView()
      43                 :            : {
      44                 :       2142 :     SfxViewShell *pView = SfxViewShell::Current();
      45 [ +  + ][ +  + ]:       2142 :     return PTR_CAST(SmViewShell, pView);
      46                 :            : }
      47                 :            : 
      48                 :            : 
      49                 :            : ////////////////////////////////////////////////////////////
      50                 :            : 
      51                 :            : 
      52                 :            : /**************************************************************************/
      53                 :            : 
      54                 :         70 : SmPickList::SmPickList(sal_uInt16 nInitSize, sal_uInt16 nMaxSize) :
      55                 :         70 :     SfxPtrArr((sal_uInt8) nInitSize, 1)
      56                 :            : {
      57                 :         70 :     nSize = nMaxSize;
      58                 :         70 : }
      59                 :            : 
      60                 :            : 
      61                 :         28 : SmPickList::~SmPickList()
      62                 :            : {
      63         [ +  - ]:         28 :     Clear();
      64         [ -  + ]:         28 : }
      65                 :            : 
      66                 :            : 
      67                 :          0 : SmPickList& SmPickList::operator=(const SmPickList& rList)
      68                 :            : {
      69                 :            :     sal_uInt16  nPos;
      70                 :            : 
      71                 :          0 :     Clear();
      72                 :          0 :     nSize = rList.nSize;
      73         [ #  # ]:          0 :     for (nPos = 0; nPos < rList.Count(); nPos++)
      74                 :          0 :         InsertPtr(nPos, CreateItem(rList.Get(nPos)));
      75                 :            : 
      76                 :          0 :     return *this;
      77                 :            : }
      78                 :            : 
      79                 :            : 
      80                 :          0 : void SmPickList::Insert(const void *pItem)
      81                 :            : {
      82                 :          0 :     Remove(pItem);
      83                 :          0 :     InsertPtr(0, CreateItem(pItem));
      84                 :            : 
      85         [ #  # ]:          0 :     if (Count() > nSize)
      86                 :            :     {
      87                 :          0 :         DestroyItem(GetPtr(nSize));
      88                 :          0 :         RemovePtr(nSize, 1);
      89                 :            :     }
      90                 :          0 : }
      91                 :            : 
      92                 :            : 
      93                 :          0 : void SmPickList::Update(const void *pItem, const void *pNewItem)
      94                 :            : {
      95                 :            :     sal_uInt16  nPos;
      96                 :            : 
      97         [ #  # ]:          0 :     for (nPos = 0; nPos < Count(); nPos++)
      98         [ #  # ]:          0 :         if (CompareItem(GetPtr(nPos), pItem))
      99                 :            :         {
     100                 :          0 :             DestroyItem(GetPtr(nPos));
     101                 :          0 :             GetPtr(nPos) = CreateItem(pNewItem);
     102                 :          0 :             break;
     103                 :            :         }
     104                 :          0 : }
     105                 :            : 
     106                 :          0 : void SmPickList::Remove(const void *pItem)
     107                 :            : {
     108                 :            :     sal_uInt16  nPos;
     109                 :            : 
     110         [ #  # ]:          0 :     for (nPos = 0; nPos < Count(); nPos++)
     111         [ #  # ]:          0 :         if (CompareItem(GetPtr(nPos), pItem))
     112                 :            :         {
     113                 :          0 :             DestroyItem(GetPtr(nPos));
     114                 :          0 :             RemovePtr(nPos, 1);
     115                 :          0 :             break;
     116                 :            :         }
     117                 :          0 : }
     118                 :            : 
     119                 :         56 : void SmPickList::Clear()
     120                 :            : {
     121                 :            :     sal_uInt16  nPos;
     122                 :            : 
     123         [ -  + ]:         56 :     for (nPos = 0; nPos < Count(); nPos++)
     124                 :          0 :         DestroyItem(GetPtr(nPos));
     125                 :            : 
     126                 :         56 :     RemovePtr(0, Count());
     127                 :         56 : }
     128                 :            : 
     129                 :            : 
     130                 :            : /**************************************************************************/
     131                 :            : 
     132                 :          0 : void * SmFontPickList::CreateItem(const String& /*rString*/)
     133                 :            : {
     134         [ #  # ]:          0 :     return new Font();
     135                 :            : }
     136                 :            : 
     137                 :          0 : void * SmFontPickList::CreateItem(const void *pItem)
     138                 :            : {
     139         [ #  # ]:          0 :     return new Font(*((Font *) pItem));
     140                 :            : }
     141                 :            : 
     142                 :          0 : void SmFontPickList::DestroyItem(void *pItem)
     143                 :            : {
     144         [ #  # ]:          0 :     delete (Font *)pItem;
     145                 :          0 : }
     146                 :            : 
     147                 :          0 : bool SmFontPickList::CompareItem(const void *pFirstItem, const void *pSecondItem) const
     148                 :            : {
     149                 :            :     Font    *pFirstFont, *pSecondFont;
     150                 :            : 
     151                 :          0 :     pFirstFont  = (Font *)pFirstItem;
     152                 :          0 :     pSecondFont = (Font *)pSecondItem;
     153                 :            : 
     154         [ #  # ]:          0 :     if (pFirstFont->GetName() == pSecondFont->GetName())
     155   [ #  #  #  #  :          0 :         if ((pFirstFont->GetFamily()  == pSecondFont->GetFamily())  &&
             #  #  #  # ]
                 [ #  # ]
     156                 :          0 :             (pFirstFont->GetCharSet() == pSecondFont->GetCharSet()) &&
     157                 :          0 :             (pFirstFont->GetWeight()  == pSecondFont->GetWeight())  &&
     158                 :          0 :             (pFirstFont->GetItalic()  == pSecondFont->GetItalic()))
     159                 :          0 :             return (true);
     160                 :            : 
     161                 :          0 :     return false;
     162                 :            : }
     163                 :            : 
     164                 :          0 : String SmFontPickList::GetStringItem(void *pItem)
     165                 :            : {
     166                 :            :     Font   *pFont;
     167                 :          0 :     String  aString;
     168                 :          0 :     const sal_Char *pDelim = ", ";
     169                 :            : 
     170                 :          0 :     pFont = (Font *)pItem;
     171                 :            : 
     172 [ #  # ][ #  # ]:          0 :     aString = pFont->GetName();
     173                 :            : 
     174 [ #  # ][ #  # ]:          0 :     if (IsItalic( *pFont ))
     175                 :            :     {
     176         [ #  # ]:          0 :         aString.AppendAscii( pDelim );
     177 [ #  # ][ #  # ]:          0 :         aString += String(SmResId(RID_FONTITALIC));
         [ #  # ][ #  # ]
     178                 :            :     }
     179 [ #  # ][ #  # ]:          0 :     if (IsBold( *pFont ))
     180                 :            :     {
     181         [ #  # ]:          0 :         aString.AppendAscii( pDelim );
     182 [ #  # ][ #  # ]:          0 :         aString += String(SmResId(RID_FONTBOLD));
         [ #  # ][ #  # ]
     183                 :            :     }
     184                 :            : 
     185                 :          0 :     return (aString);
     186                 :            : }
     187                 :            : 
     188                 :          0 : void SmFontPickList::Insert(const Font &rFont)
     189                 :            : {
     190                 :          0 :     SmPickList::Insert((void *)&rFont);
     191                 :          0 : }
     192                 :            : 
     193                 :          0 : void SmFontPickList::Update(const Font &rFont, const Font &rNewFont)
     194                 :            : {
     195                 :          0 :     SmPickList::Update((void *)&rFont, (void *)&rNewFont);
     196                 :          0 : }
     197                 :            : 
     198                 :          0 : void SmFontPickList::Remove(const Font &rFont)
     199                 :            : {
     200                 :          0 :     SmPickList::Remove((void *)&rFont);
     201                 :          0 : }
     202                 :            : 
     203                 :            : 
     204                 :          0 : void SmFontPickList::ReadFrom(const SmFontDialog& rDialog)
     205                 :            : {
     206                 :          0 :     Insert(rDialog.GetFont());
     207                 :          0 : }
     208                 :            : 
     209                 :          0 : void SmFontPickList::WriteTo(SmFontDialog& rDialog) const
     210                 :            : {
     211         [ #  # ]:          0 :     rDialog.SetFont(Get());
     212                 :          0 : }
     213                 :            : 
     214                 :            : 
     215                 :            : /**************************************************************************/
     216                 :            : 
     217                 :            : 
     218                 :          0 : IMPL_LINK( SmFontPickListBox, SelectHdl, ListBox *, /*pListBox*/ )
     219                 :            : {
     220                 :            :     sal_uInt16  nPos;
     221         [ #  # ]:          0 :     String  aString;
     222                 :            : 
     223         [ #  # ]:          0 :     nPos = GetSelectEntryPos();
     224                 :            : 
     225         [ #  # ]:          0 :     if (nPos != 0)
     226                 :            :     {
     227 [ #  # ][ #  # ]:          0 :         SmFontPickList::Insert(Get(nPos));
                 [ #  # ]
     228 [ #  # ][ #  # ]:          0 :         aString = GetEntry(nPos);
                 [ #  # ]
     229         [ #  # ]:          0 :         RemoveEntry(nPos);
     230         [ #  # ]:          0 :         InsertEntry(aString, 0);
     231                 :            :     }
     232                 :            : 
     233         [ #  # ]:          0 :     SelectEntryPos(0);
     234                 :            : 
     235         [ #  # ]:          0 :     return 0;
     236                 :            : }
     237                 :            : 
     238                 :            : 
     239                 :          0 : SmFontPickListBox::SmFontPickListBox(Window* pParent, const ResId& rResId, sal_uInt16 nMax) :
     240                 :            :     SmFontPickList(nMax, nMax),
     241         [ #  # ]:          0 :     ListBox(pParent, rResId)
     242                 :            : {
     243         [ #  # ]:          0 :     SetSelectHdl(LINK(this, SmFontPickListBox, SelectHdl));
     244                 :          0 : }
     245                 :            : 
     246                 :            : 
     247                 :          0 : SmFontPickListBox& SmFontPickListBox::operator=(const SmFontPickList& rList)
     248                 :            : {
     249                 :            :     sal_uInt16 nPos;
     250                 :            : 
     251                 :          0 :     *(SmFontPickList *)this = rList;
     252                 :            : 
     253         [ #  # ]:          0 :     for (nPos = 0; nPos < Count(); nPos++)
     254         [ #  # ]:          0 :         InsertEntry(GetStringItem(GetPtr(nPos)), nPos);
     255                 :            : 
     256         [ #  # ]:          0 :     if (Count() > 0)
     257         [ #  # ]:          0 :         SelectEntry(GetStringItem(GetPtr(0)));
     258                 :            : 
     259                 :          0 :     return *this;
     260                 :            : }
     261                 :            : 
     262                 :          0 : void SmFontPickListBox::Insert(const Font &rFont)
     263                 :            : {
     264                 :          0 :     SmFontPickList::Insert(rFont);
     265                 :            : 
     266         [ #  # ]:          0 :     RemoveEntry(GetStringItem(GetPtr(0)));
     267         [ #  # ]:          0 :     InsertEntry(GetStringItem(GetPtr(0)), 0);
     268         [ #  # ]:          0 :     SelectEntry(GetStringItem(GetPtr(0)));
     269                 :            : 
     270         [ #  # ]:          0 :     while (GetEntryCount() > nSize)
     271                 :          0 :         RemoveEntry(GetEntryCount() - 1);
     272                 :            : 
     273                 :          0 :     return;
     274                 :            : }
     275                 :            : 
     276                 :            : 
     277                 :          0 : void SmFontPickListBox::Update(const Font &rFont, const Font &rNewFont)
     278                 :            : {
     279                 :          0 :     SmFontPickList::Update(rFont, rNewFont);
     280                 :            : 
     281                 :          0 :     return;
     282                 :            : }
     283                 :            : 
     284                 :            : 
     285                 :          0 : void SmFontPickListBox::Remove(const Font &rFont)
     286                 :            : {
     287                 :          0 :     SmFontPickList::Remove(rFont);
     288                 :            : 
     289                 :          0 :     return;
     290                 :            : }
     291                 :            : 
     292                 :            : ////////////////////////////////////////
     293                 :            : 
     294                 :      17190 : bool IsItalic( const Font &rFont )
     295                 :            : {
     296                 :      17190 :     FontItalic eItalic = rFont.GetItalic();
     297                 :            :     // the code below leaves only _NONE and _DONTKNOW as not italic
     298 [ +  + ][ +  - ]:      17190 :     return eItalic == ITALIC_OBLIQUE  ||  eItalic == ITALIC_NORMAL;
     299                 :            : }
     300                 :            : 
     301                 :            : 
     302                 :      13650 : bool IsBold( const Font &rFont )
     303                 :            : {
     304                 :      13650 :     FontWeight eWeight = rFont.GetWeight();
     305 [ +  - ][ +  + ]:      13650 :     return eWeight != WEIGHT_DONTKNOW && eWeight > WEIGHT_NORMAL;
     306                 :            : }
     307                 :            : 
     308                 :            : 
     309                 :      38680 : void SmFace::Impl_Init()
     310                 :            : {
     311                 :      38680 :     SetSize( GetSize() );
     312                 :      38680 :     SetTransparent( true );
     313                 :      38680 :     SetAlign( ALIGN_BASELINE );
     314         [ +  - ]:      38680 :     SetColor( COL_AUTO );
     315                 :      38680 : }
     316                 :            : 
     317                 :      64794 : void SmFace::SetSize(const Size& rSize)
     318                 :            : {
     319                 :      64794 :     Size  aSize (rSize);
     320                 :            : 
     321                 :            :     // check the requested size against minimum value
     322 [ +  + ][ +  - ]:      64794 :     static int const    nMinVal = SmPtsTo100th_mm(2);
     323                 :            : 
     324         [ +  + ]:      64794 :     if (aSize.Height() < nMinVal)
     325                 :      36350 :         aSize.Height() = nMinVal;
     326                 :            : 
     327                 :            :     //! we don't force a maximum value here because this may prevent eg the
     328                 :            :     //! parentheses in "left ( ... right )" from matching up with large
     329                 :            :     //! bodies (eg stack{...} with many entries).
     330                 :            :     //! Of course this is holds only if characters are used and not polygons.
     331                 :            : 
     332         [ +  - ]:      64794 :     Font::SetSize(aSize);
     333                 :      64794 : }
     334                 :            : 
     335                 :            : 
     336                 :      17792 : long SmFace::GetBorderWidth() const
     337                 :            : {
     338         [ +  + ]:      17792 :     if (nBorderWidth < 0)
     339                 :      11234 :         return GetDefaultBorderWidth();
     340                 :            :     else
     341                 :      17792 :         return nBorderWidth;
     342                 :            : }
     343                 :            : 
     344                 :      61564 : SmFace & SmFace::operator = (const SmFace &rFace)
     345                 :            : {
     346                 :      61564 :     Font::operator = (rFace);
     347                 :      61564 :     nBorderWidth = -1;
     348                 :      61564 :     return *this;
     349                 :            : }
     350                 :            : 
     351                 :            : 
     352                 :      16812 : SmFace & operator *= (SmFace &rFace, const Fraction &rFrac)
     353                 :            :     // scales the width and height of 'rFace' by 'rFrac' and returns a
     354                 :            :     // reference to 'rFace'.
     355                 :            :     // It's main use is to make scaling fonts look easier.
     356                 :      16812 : {   const Size &rFaceSize = rFace.GetSize();
     357                 :            : 
     358 [ +  - ][ +  - ]:      16812 :     rFace.SetSize(Size(Fraction(rFaceSize.Width())  *= rFrac,
     359 [ +  - ][ +  - ]:      33624 :                        Fraction(rFaceSize.Height()) *= rFrac));
         [ +  - ][ +  - ]
     360                 :      16812 :     return rFace;
     361 [ +  - ][ +  - ]:         30 : }
     362                 :            : 
     363                 :            : 
     364                 :            : 
     365                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10