LCOV - code coverage report
Current view: top level - sw/source/core/fields - flddropdown.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 5 103 4.9 %
Date: 2014-11-03 Functions: 3 23 13.0 %
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 <flddropdown.hxx>
      21             : 
      22             : #include <algorithm>
      23             : #include <svl/poolitem.hxx>
      24             : 
      25             : #include <unofldmid.h>
      26             : #include <unoprnms.hxx>
      27             : 
      28             : using namespace com::sun::star;
      29             : 
      30             : using std::vector;
      31             : 
      32        5052 : SwDropDownFieldType::SwDropDownFieldType()
      33        5052 :     : SwFieldType(RES_DROPDOWN)
      34             : {
      35        5052 : }
      36             : 
      37       10090 : SwDropDownFieldType::~SwDropDownFieldType()
      38             : {
      39       10090 : }
      40             : 
      41           0 : SwFieldType * SwDropDownFieldType::Copy() const
      42             : {
      43           0 :     return new SwDropDownFieldType;
      44             : }
      45             : 
      46           0 : SwDropDownField::SwDropDownField(SwFieldType * pTyp)
      47           0 :     : SwField(pTyp, 0, LANGUAGE_SYSTEM)
      48             : {
      49           0 : }
      50             : 
      51           0 : SwDropDownField::SwDropDownField(const SwDropDownField & rSrc)
      52           0 :     : SwField(rSrc.GetTyp(), rSrc.GetFormat(), rSrc.GetLanguage()),
      53             :       aValues(rSrc.aValues), aSelectedItem(rSrc.aSelectedItem),
      54           0 :       aName(rSrc.aName), aHelp(rSrc.aHelp), aToolTip(rSrc.aToolTip)
      55             : {
      56           0 : }
      57             : 
      58           0 : SwDropDownField::~SwDropDownField()
      59             : {
      60           0 : }
      61             : 
      62           0 : OUString SwDropDownField::Expand() const
      63             : {
      64           0 :     OUString sSelect = GetSelectedItem();
      65           0 :     if (sSelect.isEmpty())
      66             :     {
      67           0 :         vector<OUString>::const_iterator aIt = aValues.begin();
      68           0 :         if ( aIt != aValues.end())
      69           0 :             sSelect = *aIt;
      70             :     }
      71             :     // if still no list value is available a default text of 10 spaces is to be set
      72           0 :     if (sSelect.isEmpty())
      73           0 :         sSelect = "          ";
      74           0 :     return sSelect;
      75             : }
      76             : 
      77           0 : SwField * SwDropDownField::Copy() const
      78             : {
      79           0 :     return new SwDropDownField(*this);
      80             : }
      81             : 
      82           0 : OUString SwDropDownField::GetPar1() const
      83             : {
      84           0 :     return GetSelectedItem();
      85             : }
      86             : 
      87           0 : OUString SwDropDownField::GetPar2() const
      88             : {
      89           0 :     return GetName();
      90             : }
      91             : 
      92           0 : void SwDropDownField::SetPar1(const OUString & rStr)
      93             : {
      94           0 :     SetSelectedItem(rStr);
      95           0 : }
      96             : 
      97           0 : void SwDropDownField::SetPar2(const OUString & rName)
      98             : {
      99           0 :     SetName(rName);
     100           0 : }
     101             : 
     102           0 : void SwDropDownField::SetItems(const vector<OUString> & rItems)
     103             : {
     104           0 :     aValues = rItems;
     105           0 :     aSelectedItem = OUString();
     106           0 : }
     107             : 
     108           0 : void SwDropDownField::SetItems(const uno::Sequence<OUString> & rItems)
     109             : {
     110           0 :     aValues.clear();
     111             : 
     112           0 :     sal_Int32 aCount = rItems.getLength();
     113           0 :     for (int i = 0; i < aCount; i++)
     114           0 :         aValues.push_back(rItems[i]);
     115             : 
     116           0 :     aSelectedItem = OUString();
     117           0 : }
     118             : 
     119           0 : uno::Sequence<OUString> SwDropDownField::GetItemSequence() const
     120             : {
     121           0 :     uno::Sequence<OUString> aSeq( aValues.size() );
     122           0 :     OUString* pSeq = aSeq.getArray();
     123           0 :     int i = 0;
     124           0 :     vector<OUString>::const_iterator aIt;
     125             : 
     126           0 :     for (aIt = aValues.begin(); aIt != aValues.end(); ++aIt)
     127             :     {
     128           0 :         pSeq[i] = *aIt;
     129           0 :         i++;
     130             :     }
     131             : 
     132           0 :     return aSeq;
     133             : }
     134             : 
     135             : 
     136             : 
     137             : 
     138             : 
     139           0 : bool SwDropDownField::SetSelectedItem(const OUString & rItem)
     140             : {
     141             :     vector<OUString>::const_iterator aIt =
     142           0 :         std::find(aValues.begin(), aValues.end(), rItem);
     143             : 
     144           0 :     if (aIt != aValues.end())
     145           0 :         aSelectedItem = *aIt;
     146             :     else
     147           0 :         aSelectedItem = OUString();
     148             : 
     149           0 :     return (aIt != aValues.end());
     150             : }
     151             : 
     152           0 : void SwDropDownField::SetName(const OUString & rName)
     153             : {
     154           0 :     aName = rName;
     155           0 : }
     156             : 
     157           0 : void SwDropDownField::SetHelp(const OUString & rHelp)
     158             : {
     159           0 :     aHelp = rHelp;
     160           0 : }
     161             : 
     162           0 : void SwDropDownField::SetToolTip(const OUString & rToolTip)
     163             : {
     164           0 :     aToolTip = rToolTip;
     165           0 : }
     166             : 
     167           0 : bool SwDropDownField::QueryValue(::uno::Any &rVal, sal_uInt16 nWhich) const
     168             : {
     169           0 :     nWhich &= ~CONVERT_TWIPS;
     170           0 :     switch( nWhich )
     171             :     {
     172             :     case FIELD_PROP_PAR1:
     173           0 :         rVal <<= aSelectedItem;
     174           0 :         break;
     175             :     case FIELD_PROP_PAR2:
     176           0 :         rVal <<= aName;
     177           0 :         break;
     178             :     case FIELD_PROP_PAR3:
     179           0 :         rVal <<= aHelp;
     180           0 :         break;
     181             :     case FIELD_PROP_PAR4:
     182           0 :         rVal <<= aToolTip;
     183           0 :         break;
     184             :     case FIELD_PROP_STRINGS:
     185           0 :         rVal <<= GetItemSequence();
     186             : 
     187           0 :         break;
     188             : 
     189             :     default:
     190             :         OSL_FAIL("illegal property");
     191             :     }
     192           0 :     return true;
     193             : }
     194             : 
     195           0 : bool SwDropDownField::PutValue(const uno::Any &rVal,
     196             :                                sal_uInt16 nWhich)
     197             : {
     198           0 :     switch( nWhich )
     199             :     {
     200             :     case FIELD_PROP_PAR1:
     201             :         {
     202           0 :             OUString aTmpStr;
     203           0 :             rVal >>= aTmpStr;
     204             : 
     205           0 :             SetSelectedItem(aTmpStr);
     206             :         }
     207           0 :         break;
     208             : 
     209             :     case FIELD_PROP_PAR2:
     210           0 :         rVal >>= aName;
     211           0 :         break;
     212             : 
     213             :     case FIELD_PROP_PAR3:
     214           0 :         rVal >>= aHelp;
     215           0 :         break;
     216             : 
     217             :     case FIELD_PROP_PAR4:
     218           0 :         rVal >>= aToolTip;
     219           0 :         break;
     220             : 
     221             :     case FIELD_PROP_STRINGS:
     222             :         {
     223           0 :             uno::Sequence<OUString> aSeq;
     224           0 :             rVal >>= aSeq;
     225           0 :             SetItems(aSeq);
     226             :         }
     227           0 :         break;
     228             : 
     229             :     default:
     230             :         OSL_FAIL("illegal property");
     231             :     }
     232           0 :     return true;
     233             : }
     234             : 
     235             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10