LCOV - code coverage report
Current view: top level - starmath/source - utility.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 39 125 31.2 %
Date: 2014-11-03 Functions: 11 29 37.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10