LCOV - code coverage report
Current view: top level - sw/source/core/fields - flddropdown.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 5 111 4.5 %
Date: 2014-04-11 Functions: 3 27 11.1 %
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        1852 : SwDropDownFieldType::SwDropDownFieldType()
      33        1852 :     : SwFieldType(RES_DROPDOWN)
      34             : {
      35        1852 : }
      36             : 
      37        3696 : SwDropDownFieldType::~SwDropDownFieldType()
      38             : {
      39        3696 : }
      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           0 : OUString SwDropDownField::GetSelectedItem() const
     136             : {
     137           0 :     return aSelectedItem;
     138             : }
     139             : 
     140           0 : OUString SwDropDownField::GetName() const
     141             : {
     142           0 :     return aName;
     143             : }
     144             : 
     145           0 : OUString SwDropDownField::GetHelp() const
     146             : {
     147           0 :     return aHelp;
     148             : }
     149             : 
     150           0 : OUString SwDropDownField::GetToolTip() const
     151             : {
     152           0 :     return aToolTip;
     153             : }
     154             : 
     155           0 : sal_Bool SwDropDownField::SetSelectedItem(const OUString & rItem)
     156             : {
     157             :     vector<OUString>::const_iterator aIt =
     158           0 :         std::find(aValues.begin(), aValues.end(), rItem);
     159             : 
     160           0 :     if (aIt != aValues.end())
     161           0 :         aSelectedItem = *aIt;
     162             :     else
     163           0 :         aSelectedItem = OUString();
     164             : 
     165           0 :     return (aIt != aValues.end());
     166             : }
     167             : 
     168           0 : void SwDropDownField::SetName(const OUString & rName)
     169             : {
     170           0 :     aName = rName;
     171           0 : }
     172             : 
     173           0 : void SwDropDownField::SetHelp(const OUString & rHelp)
     174             : {
     175           0 :     aHelp = rHelp;
     176           0 : }
     177             : 
     178           0 : void SwDropDownField::SetToolTip(const OUString & rToolTip)
     179             : {
     180           0 :     aToolTip = rToolTip;
     181           0 : }
     182             : 
     183           0 : bool SwDropDownField::QueryValue(::uno::Any &rVal, sal_uInt16 nWhich) const
     184             : {
     185           0 :     nWhich &= ~CONVERT_TWIPS;
     186           0 :     switch( nWhich )
     187             :     {
     188             :     case FIELD_PROP_PAR1:
     189           0 :         rVal <<= aSelectedItem;
     190           0 :         break;
     191             :     case FIELD_PROP_PAR2:
     192           0 :         rVal <<= aName;
     193           0 :         break;
     194             :     case FIELD_PROP_PAR3:
     195           0 :         rVal <<= aHelp;
     196           0 :         break;
     197             :     case FIELD_PROP_PAR4:
     198           0 :         rVal <<= aToolTip;
     199           0 :         break;
     200             :     case FIELD_PROP_STRINGS:
     201           0 :         rVal <<= GetItemSequence();
     202             : 
     203           0 :         break;
     204             : 
     205             :     default:
     206             :         OSL_FAIL("illegal property");
     207             :     }
     208           0 :     return true;
     209             : }
     210             : 
     211           0 : bool SwDropDownField::PutValue(const uno::Any &rVal,
     212             :                                sal_uInt16 nWhich)
     213             : {
     214           0 :     switch( nWhich )
     215             :     {
     216             :     case FIELD_PROP_PAR1:
     217             :         {
     218           0 :             OUString aTmpStr;
     219           0 :             rVal >>= aTmpStr;
     220             : 
     221           0 :             SetSelectedItem(aTmpStr);
     222             :         }
     223           0 :         break;
     224             : 
     225             :     case FIELD_PROP_PAR2:
     226           0 :         rVal >>= aName;
     227           0 :         break;
     228             : 
     229             :     case FIELD_PROP_PAR3:
     230           0 :         rVal >>= aHelp;
     231           0 :         break;
     232             : 
     233             :     case FIELD_PROP_PAR4:
     234           0 :         rVal >>= aToolTip;
     235           0 :         break;
     236             : 
     237             :     case FIELD_PROP_STRINGS:
     238             :         {
     239           0 :             uno::Sequence<OUString> aSeq;
     240           0 :             rVal >>= aSeq;
     241           0 :             SetItems(aSeq);
     242             :         }
     243           0 :         break;
     244             : 
     245             :     default:
     246             :         OSL_FAIL("illegal property");
     247             :     }
     248           0 :     return true;
     249             : }
     250             : 
     251             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10