LCOV - code coverage report
Current view: top level - sw/source/core/fields - flddropdown.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 119 5.9 %
Date: 2012-08-25 Functions: 5 29 17.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 78 3.8 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <flddropdown.hxx>
      31                 :            : 
      32                 :            : #include <algorithm>
      33                 :            : #include <svl/poolitem.hxx>
      34                 :            : 
      35                 :            : #include <unofldmid.h>
      36                 :            : #include <unoprnms.hxx>
      37                 :            : 
      38                 :            : using namespace com::sun::star;
      39                 :            : 
      40                 :            : using rtl::OUString;
      41                 :            : using std::vector;
      42                 :            : 
      43                 :         95 : static String aEmptyString;
      44                 :            : 
      45                 :       1921 : SwDropDownFieldType::SwDropDownFieldType()
      46                 :       1921 :     : SwFieldType(RES_DROPDOWN)
      47                 :            : {
      48                 :       1921 : }
      49                 :            : 
      50                 :       1772 : SwDropDownFieldType::~SwDropDownFieldType()
      51                 :            : {
      52         [ -  + ]:       3544 : }
      53                 :            : 
      54                 :          0 : SwFieldType * SwDropDownFieldType::Copy() const
      55                 :            : {
      56         [ #  # ]:          0 :     return new SwDropDownFieldType;
      57                 :            : }
      58                 :            : 
      59                 :          0 : SwDropDownField::SwDropDownField(SwFieldType * pTyp)
      60         [ #  # ]:          0 :     : SwField(pTyp, 0, LANGUAGE_SYSTEM)
      61                 :            : {
      62                 :          0 : }
      63                 :            : 
      64                 :          0 : SwDropDownField::SwDropDownField(const SwDropDownField & rSrc)
      65                 :          0 :     : SwField(rSrc.GetTyp(), rSrc.GetFormat(), rSrc.GetLanguage()),
      66                 :            :       aValues(rSrc.aValues), aSelectedItem(rSrc.aSelectedItem),
      67         [ #  # ]:          0 :       aName(rSrc.aName), aHelp(rSrc.aHelp), aToolTip(rSrc.aToolTip)
      68                 :            : {
      69                 :          0 : }
      70                 :            : 
      71                 :          0 : SwDropDownField::~SwDropDownField()
      72                 :            : {
      73         [ #  # ]:          0 : }
      74                 :            : 
      75                 :          0 : String SwDropDownField::Expand() const
      76                 :            : {
      77                 :          0 :     String sSelect = GetSelectedItem();
      78         [ #  # ]:          0 :     if(!sSelect.Len())
      79                 :            :     {
      80                 :          0 :         vector<rtl::OUString>::const_iterator aIt = aValues.begin();
      81 [ #  # ][ #  # ]:          0 :         if ( aIt != aValues.end())
      82         [ #  # ]:          0 :             sSelect = *aIt;
      83                 :            :     }
      84                 :            :     //if still no list value is available a default text of 10 spaces is to be set
      85         [ #  # ]:          0 :     if(!sSelect.Len())
      86         [ #  # ]:          0 :         sSelect.AppendAscii ( RTL_CONSTASCII_STRINGPARAM ("          "));
      87                 :          0 :     return sSelect;
      88                 :            : }
      89                 :            : 
      90                 :          0 : SwField * SwDropDownField::Copy() const
      91                 :            : {
      92         [ #  # ]:          0 :     return new SwDropDownField(*this);
      93                 :            : }
      94                 :            : 
      95                 :          0 : const rtl::OUString & SwDropDownField::GetPar1() const
      96                 :            : {
      97                 :          0 :     return GetSelectedItem();
      98                 :            : }
      99                 :            : 
     100                 :          0 : rtl::OUString SwDropDownField::GetPar2() const
     101                 :            : {
     102                 :          0 :     return GetName();
     103                 :            : }
     104                 :            : 
     105                 :          0 : void SwDropDownField::SetPar1(const rtl::OUString & rStr)
     106                 :            : {
     107                 :          0 :     SetSelectedItem(rStr);
     108                 :          0 : }
     109                 :            : 
     110                 :          0 : void SwDropDownField::SetPar2(const rtl::OUString & rName)
     111                 :            : {
     112                 :          0 :     SetName(rName);
     113                 :          0 : }
     114                 :            : 
     115                 :          0 : void SwDropDownField::SetItems(const vector<rtl::OUString> & rItems)
     116                 :            : {
     117                 :          0 :     aValues = rItems;
     118                 :          0 :     aSelectedItem = aEmptyString;
     119                 :          0 : }
     120                 :            : 
     121                 :          0 : void SwDropDownField::SetItems(const uno::Sequence<OUString> & rItems)
     122                 :            : {
     123                 :          0 :     aValues.clear();
     124                 :            : 
     125                 :          0 :     sal_Int32 aCount = rItems.getLength();
     126         [ #  # ]:          0 :     for (int i = 0; i < aCount; i++)
     127                 :          0 :         aValues.push_back(rItems[i]);
     128                 :            : 
     129                 :          0 :     aSelectedItem = aEmptyString;
     130                 :          0 : }
     131                 :            : 
     132                 :          0 : uno::Sequence<OUString> SwDropDownField::GetItemSequence() const
     133                 :            : {
     134         [ #  # ]:          0 :     uno::Sequence<OUString> aSeq( aValues.size() );
     135         [ #  # ]:          0 :     OUString* pSeq = aSeq.getArray();
     136                 :          0 :     int i = 0;
     137                 :          0 :     vector<rtl::OUString>::const_iterator aIt;
     138                 :            : 
     139 [ #  # ][ #  # ]:          0 :     for (aIt = aValues.begin(); aIt != aValues.end(); ++aIt)
     140                 :            :     {
     141                 :          0 :         pSeq[i] = *aIt;
     142                 :          0 :         i++;
     143                 :            :     }
     144                 :            : 
     145                 :          0 :     return aSeq;
     146                 :            : }
     147                 :            : 
     148                 :          0 : const rtl::OUString & SwDropDownField::GetSelectedItem() const
     149                 :            : {
     150                 :          0 :     return aSelectedItem;
     151                 :            : }
     152                 :            : 
     153                 :          0 : const rtl::OUString & SwDropDownField::GetName() const
     154                 :            : {
     155                 :          0 :     return aName;
     156                 :            : }
     157                 :            : 
     158                 :          0 : const rtl::OUString & SwDropDownField::GetHelp() const
     159                 :            : {
     160                 :          0 :     return aHelp;
     161                 :            : }
     162                 :            : 
     163                 :          0 : const rtl::OUString & SwDropDownField::GetToolTip() const
     164                 :            : {
     165                 :          0 :     return aToolTip;
     166                 :            : }
     167                 :            : 
     168                 :          0 : sal_Bool SwDropDownField::SetSelectedItem(const rtl::OUString & rItem)
     169                 :            : {
     170                 :            :     vector<rtl::OUString>::const_iterator aIt =
     171 [ #  # ][ #  # ]:          0 :         std::find(aValues.begin(), aValues.end(), rItem);
     172                 :            : 
     173 [ #  # ][ #  # ]:          0 :     if (aIt != aValues.end())
     174                 :          0 :         aSelectedItem = *aIt;
     175                 :            :     else
     176                 :          0 :         aSelectedItem = rtl::OUString();
     177                 :            : 
     178         [ #  # ]:          0 :     return (aIt != aValues.end());
     179                 :            : }
     180                 :            : 
     181                 :          0 : void SwDropDownField::SetName(const rtl::OUString & rName)
     182                 :            : {
     183                 :          0 :     aName = rName;
     184                 :          0 : }
     185                 :            : 
     186                 :          0 : void SwDropDownField::SetHelp(const rtl::OUString & rHelp)
     187                 :            : {
     188                 :          0 :     aHelp = rHelp;
     189                 :          0 : }
     190                 :            : 
     191                 :          0 : void SwDropDownField::SetToolTip(const rtl::OUString & rToolTip)
     192                 :            : {
     193                 :          0 :     aToolTip = rToolTip;
     194                 :          0 : }
     195                 :            : 
     196                 :          0 : bool SwDropDownField::QueryValue(::uno::Any &rVal, sal_uInt16 nWhich) const
     197                 :            : {
     198                 :          0 :     nWhich &= ~CONVERT_TWIPS;
     199   [ #  #  #  #  :          0 :     switch( nWhich )
                   #  # ]
     200                 :            :     {
     201                 :            :     case FIELD_PROP_PAR1:
     202                 :          0 :         rVal <<= GetSelectedItem();
     203                 :          0 :         break;
     204                 :            :     case FIELD_PROP_PAR2:
     205                 :          0 :         rVal <<= GetName();
     206                 :          0 :         break;
     207                 :            :     case FIELD_PROP_PAR3:
     208                 :          0 :         rVal <<= GetHelp();
     209                 :          0 :         break;
     210                 :            :     case FIELD_PROP_PAR4:
     211                 :          0 :         rVal <<= GetToolTip();
     212                 :          0 :         break;
     213                 :            :     case FIELD_PROP_STRINGS:
     214         [ #  # ]:          0 :         rVal <<= GetItemSequence();
     215                 :            : 
     216                 :          0 :         break;
     217                 :            : 
     218                 :            :     default:
     219                 :            :         OSL_FAIL("illegal property");
     220                 :            :     }
     221                 :          0 :     return true;
     222                 :            : }
     223                 :            : 
     224                 :          0 : bool SwDropDownField::PutValue(const uno::Any &rVal,
     225                 :            :                                sal_uInt16 nWhich)
     226                 :            : {
     227   [ #  #  #  #  :          0 :     switch( nWhich )
                   #  # ]
     228                 :            :     {
     229                 :            :     case FIELD_PROP_PAR1:
     230                 :            :         {
     231                 :          0 :             rtl::OUString aTmpStr;
     232                 :          0 :             rVal >>= aTmpStr;
     233                 :            : 
     234         [ #  # ]:          0 :             SetSelectedItem(aTmpStr);
     235                 :            :         }
     236                 :          0 :         break;
     237                 :            : 
     238                 :            :     case FIELD_PROP_PAR2:
     239                 :            :         {
     240                 :          0 :             rtl::OUString aTmpStr;
     241                 :          0 :             rVal >>= aTmpStr;
     242                 :            : 
     243         [ #  # ]:          0 :             SetName(aTmpStr);
     244                 :            :         }
     245                 :          0 :         break;
     246                 :            : 
     247                 :            :     case FIELD_PROP_PAR3:
     248                 :            :         {
     249                 :          0 :             rtl::OUString aTmpStr;
     250                 :          0 :             rVal >>= aTmpStr;
     251                 :            : 
     252         [ #  # ]:          0 :             SetHelp(aTmpStr);
     253                 :            :         }
     254                 :          0 :         break;
     255                 :            : 
     256                 :            :     case FIELD_PROP_PAR4:
     257                 :            :         {
     258                 :          0 :             rtl::OUString aTmpStr;
     259                 :          0 :             rVal >>= aTmpStr;
     260                 :            : 
     261         [ #  # ]:          0 :             SetToolTip(aTmpStr);
     262                 :            :         }
     263                 :          0 :         break;
     264                 :            : 
     265                 :            :     case FIELD_PROP_STRINGS:
     266                 :            :         {
     267         [ #  # ]:          0 :             uno::Sequence<OUString> aSeq;
     268         [ #  # ]:          0 :             rVal >>= aSeq;
     269 [ #  # ][ #  # ]:          0 :             SetItems(aSeq);
     270                 :            :         }
     271                 :          0 :         break;
     272                 :            : 
     273                 :            :     default:
     274                 :            :         OSL_FAIL("illegal property");
     275                 :            :     }
     276                 :          0 :     return true;
     277 [ +  - ][ +  - ]:        285 : }
     278                 :            : 
     279                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10