LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/starmath/source - utility.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 39 131 29.8 %
Date: 2013-07-09 Functions: 11 31 35.5 %
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         837 : SmViewShell * SmGetActiveView()
      42             : {
      43         837 :     SfxViewShell *pView = SfxViewShell::Current();
      44         837 :     return PTR_CAST(SmViewShell, pView);
      45             : }
      46             : 
      47             : 
      48             : ////////////////////////////////////////////////////////////
      49             : 
      50             : 
      51             : /**************************************************************************/
      52             : 
      53          14 : void SmFontPickList::Clear()
      54             : {
      55          14 :     aFontVec.clear();
      56          14 : }
      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 : Font SmFontPickList::operator [] (sal_uInt16 nPos) const
      69             : {
      70           0 :     return aFontVec[nPos];
      71             : }
      72             : 
      73           0 : Font SmFontPickList::Get(sal_uInt16 nPos) const
      74             : {
      75           0 :     return nPos < aFontVec.size() ? aFontVec[nPos] : Font();
      76             : }
      77             : 
      78           0 : bool SmFontPickList::Contains(const Font &rFont) const
      79             : {
      80           0 :     return std::find( aFontVec.begin(), aFontVec.end(), rFont ) != aFontVec.end();
      81             : }
      82             : 
      83             : 
      84             : 
      85             : 
      86           0 : bool SmFontPickList::CompareItem(const Font & rFirstFont, const Font & rSecondFont) const
      87             : {
      88           0 :   return rFirstFont.GetName() == rSecondFont.GetName() &&
      89           0 :         rFirstFont.GetFamily()  == rSecondFont.GetFamily()  &&
      90           0 :         rFirstFont.GetCharSet() == rSecondFont.GetCharSet() &&
      91           0 :         rFirstFont.GetWeight()  == rSecondFont.GetWeight()  &&
      92           0 :         rFirstFont.GetItalic()  == rSecondFont.GetItalic();
      93             : }
      94             : 
      95           0 : OUString SmFontPickList::GetStringItem(const Font &rFont)
      96             : {
      97           0 :     OUStringBuffer aString(rFont.GetName());
      98             : 
      99           0 :     if (IsItalic( rFont ))
     100             :     {
     101           0 :         aString.append(", ");
     102           0 :         aString.append(SM_RESSTR(RID_FONTITALIC));
     103             :     }
     104           0 :     if (IsBold( rFont ))
     105             :     {
     106           0 :         aString.append(", ");
     107           0 :         aString.append(SM_RESSTR(RID_FONTBOLD));
     108             :     }
     109             : 
     110           0 :     return aString.makeStringAndClear();
     111             : }
     112             : 
     113           0 : void SmFontPickList::Insert(const Font &rFont)
     114             : {
     115           0 :     Remove(rFont);
     116           0 :     aFontVec.push_front( rFont );
     117             : 
     118           0 :     if (aFontVec.size() > nMaxItems)
     119             :     {
     120           0 :         aFontVec.pop_back();
     121             :     }
     122           0 : }
     123             : 
     124           0 : void SmFontPickList::Update(const Font &rFont, const Font &rNewFont)
     125             : {
     126           0 :     for (sal_uInt16 nPos = 0; nPos < aFontVec.size(); nPos++)
     127           0 :         if (CompareItem( aFontVec[nPos], rFont ))
     128             :         {
     129           0 :             aFontVec[nPos] = rNewFont;
     130           0 :             break;
     131             :         }
     132           0 : }
     133             : 
     134           0 : void SmFontPickList::Remove(const Font &rFont)
     135             : {
     136           0 :     for (sal_uInt16 nPos = 0; nPos < aFontVec.size(); nPos++)
     137           0 :         if (CompareItem( aFontVec[nPos], rFont))
     138             :         {
     139           0 :             aFontVec.erase( aFontVec.begin() + nPos );
     140           0 :             break;
     141             :         }
     142           0 : }
     143             : 
     144             : 
     145           0 : void SmFontPickList::ReadFrom(const SmFontDialog& rDialog)
     146             : {
     147           0 :     Insert(rDialog.GetFont());
     148           0 : }
     149             : 
     150           0 : void SmFontPickList::WriteTo(SmFontDialog& rDialog) const
     151             : {
     152           0 :     rDialog.SetFont(Get());
     153           0 : }
     154             : 
     155             : 
     156             : /**************************************************************************/
     157             : 
     158           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSmFontPickListBox(Window* pParent, VclBuilder::stringmap &)
     159             : {
     160           0 :     return new SmFontPickListBox(pParent, WB_DROPDOWN);
     161             : }
     162             : 
     163           0 : SmFontPickListBox::SmFontPickListBox (Window* pParent, WinBits nBits) :
     164             :     SmFontPickList(4),
     165           0 :     ListBox(pParent, nBits)
     166             : {
     167           0 :     SetSelectHdl(LINK(this, SmFontPickListBox, SelectHdl));
     168           0 : }
     169             : 
     170           0 : IMPL_LINK( SmFontPickListBox, SelectHdl, ListBox *, /*pListBox*/ )
     171             : {
     172             :     sal_uInt16  nPos;
     173           0 :     OUString aString;
     174             : 
     175           0 :     nPos = GetSelectEntryPos();
     176             : 
     177           0 :     if (nPos != 0)
     178             :     {
     179           0 :         SmFontPickList::Insert(Get(nPos));
     180           0 :         aString = GetEntry(nPos);
     181           0 :         RemoveEntry(nPos);
     182           0 :         InsertEntry(aString, 0);
     183             :     }
     184             : 
     185           0 :     SelectEntryPos(0);
     186             : 
     187           0 :     return 0;
     188             : }
     189             : 
     190             : 
     191           0 : SmFontPickListBox::SmFontPickListBox(Window* pParent, const ResId& rResId) :
     192             :     SmFontPickList(4),
     193           0 :     ListBox(pParent, rResId)
     194             : {
     195           0 :     SetSelectHdl(LINK(this, SmFontPickListBox, SelectHdl));
     196           0 : }
     197             : 
     198             : 
     199           0 : SmFontPickListBox& SmFontPickListBox::operator=(const SmFontPickList& rList)
     200             : {
     201             :     sal_uInt16 nPos;
     202             : 
     203           0 :     *(SmFontPickList *)this = rList;
     204             : 
     205           0 :     for (nPos = 0; nPos < aFontVec.size(); nPos++)
     206           0 :         InsertEntry(GetStringItem(aFontVec[nPos]), nPos);
     207             : 
     208           0 :     if (aFontVec.size() > 0)
     209           0 :         SelectEntry(GetStringItem(aFontVec.front()));
     210             : 
     211           0 :     return *this;
     212             : }
     213             : 
     214           0 : void SmFontPickListBox::Insert(const Font &rFont)
     215             : {
     216           0 :     SmFontPickList::Insert(rFont);
     217             : 
     218           0 :     RemoveEntry(GetStringItem(aFontVec.front()));
     219           0 :     InsertEntry(GetStringItem(aFontVec.front()), 0);
     220           0 :     SelectEntry(GetStringItem(aFontVec.front()));
     221             : 
     222           0 :     while (GetEntryCount() > nMaxItems)
     223           0 :         RemoveEntry(GetEntryCount() - 1);
     224             : 
     225           0 :     return;
     226             : }
     227             : 
     228             : 
     229           0 : void SmFontPickListBox::Update(const Font &rFont, const Font &rNewFont)
     230             : {
     231           0 :     SmFontPickList::Update(rFont, rNewFont);
     232             : 
     233           0 :     return;
     234             : }
     235             : 
     236             : 
     237           0 : void SmFontPickListBox::Remove(const Font &rFont)
     238             : {
     239           0 :     SmFontPickList::Remove(rFont);
     240             : 
     241           0 :     return;
     242             : }
     243             : 
     244             : ////////////////////////////////////////
     245             : 
     246        6754 : bool IsItalic( const Font &rFont )
     247             : {
     248        6754 :     FontItalic eItalic = rFont.GetItalic();
     249             :     // the code below leaves only _NONE and _DONTKNOW as not italic
     250        6754 :     return eItalic == ITALIC_OBLIQUE  ||  eItalic == ITALIC_NORMAL;
     251             : }
     252             : 
     253             : 
     254        5525 : bool IsBold( const Font &rFont )
     255             : {
     256        5525 :     FontWeight eWeight = rFont.GetWeight();
     257        5525 :     return eWeight != WEIGHT_DONTKNOW && eWeight > WEIGHT_NORMAL;
     258             : }
     259             : 
     260             : 
     261       16194 : void SmFace::Impl_Init()
     262             : {
     263       16194 :     SetSize( GetSize() );
     264       16194 :     SetTransparent( true );
     265       16194 :     SetAlign( ALIGN_BASELINE );
     266       16194 :     SetColor( COL_AUTO );
     267       16194 : }
     268             : 
     269       27174 : void SmFace::SetSize(const Size& rSize)
     270             : {
     271       27174 :     Size  aSize (rSize);
     272             : 
     273             :     // check the requested size against minimum value
     274       27174 :     static int const    nMinVal = SmPtsTo100th_mm(2);
     275             : 
     276       27174 :     if (aSize.Height() < nMinVal)
     277       14813 :         aSize.Height() = nMinVal;
     278             : 
     279             :     //! we don't force a maximum value here because this may prevent eg the
     280             :     //! parentheses in "left ( ... right )" from matching up with large
     281             :     //! bodies (eg stack{...} with many entries).
     282             :     //! Of course this is holds only if characters are used and not polygons.
     283             : 
     284       27174 :     Font::SetSize(aSize);
     285       27174 : }
     286             : 
     287             : 
     288        7205 : long SmFace::GetBorderWidth() const
     289             : {
     290        7205 :     if (nBorderWidth < 0)
     291        4816 :         return GetDefaultBorderWidth();
     292             :     else
     293        2389 :         return nBorderWidth;
     294             : }
     295             : 
     296       23363 : SmFace & SmFace::operator = (const SmFace &rFace)
     297             : {
     298       23363 :     Font::operator = (rFace);
     299       23363 :     nBorderWidth = -1;
     300       23363 :     return *this;
     301             : }
     302             : 
     303             : 
     304        7016 : SmFace & operator *= (SmFace &rFace, const Fraction &rFrac)
     305             :     // scales the width and height of 'rFace' by 'rFrac' and returns a
     306             :     // reference to 'rFace'.
     307             :     // It's main use is to make scaling fonts look easier.
     308        7016 : {   const Size &rFaceSize = rFace.GetSize();
     309             : 
     310       14032 :     rFace.SetSize(Size(Fraction(rFaceSize.Width())  *= rFrac,
     311       21048 :                        Fraction(rFaceSize.Height()) *= rFrac));
     312        7016 :     return rFace;
     313          21 : }
     314             : 
     315             : 
     316             : 
     317             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10