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

Generated by: LCOV version 1.10