2010-10-14 08:30:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2011-03-31 10:05:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
2003-06-30 14:50:48 +00:00
|
|
|
*
|
2011-03-31 10:05:04 +02:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2003-06-30 14:50:48 +00:00
|
|
|
*
|
2011-03-31 10:05:04 +02:00
|
|
|
* This file incorporates work covered by the following license notice:
|
2003-06-30 14:50:48 +00:00
|
|
|
*
|
2011-03-31 10:05:04 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2003-06-30 14:50:48 +00:00
|
|
|
|
2004-08-23 09:53:43 +00:00
|
|
|
#include <flddropdown.hxx>
|
|
|
|
|
2003-06-30 14:50:48 +00:00
|
|
|
#include <algorithm>
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <svl/poolitem.hxx>
|
2004-08-23 09:53:43 +00:00
|
|
|
|
2003-06-30 14:50:48 +00:00
|
|
|
#include <unofldmid.h>
|
|
|
|
#include <unoprnms.hxx>
|
2004-08-23 09:53:43 +00:00
|
|
|
|
2007-09-27 07:49:24 +00:00
|
|
|
using namespace com::sun::star;
|
2004-08-23 09:53:43 +00:00
|
|
|
|
|
|
|
using std::vector;
|
2003-06-30 14:50:48 +00:00
|
|
|
|
|
|
|
SwDropDownFieldType::SwDropDownFieldType()
|
|
|
|
: SwFieldType(RES_DROPDOWN)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwDropDownFieldType::~SwDropDownFieldType()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwFieldType * SwDropDownFieldType::Copy() const
|
|
|
|
{
|
|
|
|
return new SwDropDownFieldType;
|
|
|
|
}
|
|
|
|
|
|
|
|
SwDropDownField::SwDropDownField(SwFieldType * pTyp)
|
|
|
|
: SwField(pTyp, 0, LANGUAGE_SYSTEM)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwDropDownField::SwDropDownField(const SwDropDownField & rSrc)
|
|
|
|
: SwField(rSrc.GetTyp(), rSrc.GetFormat(), rSrc.GetLanguage()),
|
|
|
|
aValues(rSrc.aValues), aSelectedItem(rSrc.aSelectedItem),
|
2007-03-09 12:15:10 +00:00
|
|
|
aName(rSrc.aName), aHelp(rSrc.aHelp), aToolTip(rSrc.aToolTip)
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwDropDownField::~SwDropDownField()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-14 15:21:18 +02:00
|
|
|
OUString SwDropDownField::Expand() const
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
2013-07-14 15:21:18 +02:00
|
|
|
OUString sSelect = GetSelectedItem();
|
|
|
|
if (sSelect.isEmpty())
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
vector<OUString>::const_iterator aIt = aValues.begin();
|
2003-06-30 14:50:48 +00:00
|
|
|
if ( aIt != aValues.end())
|
|
|
|
sSelect = *aIt;
|
|
|
|
}
|
2013-06-10 21:58:09 +02:00
|
|
|
// if still no list value is available a default text of 10 spaces is to be set
|
2013-07-14 15:21:18 +02:00
|
|
|
if (sSelect.isEmpty())
|
|
|
|
sSelect = " ";
|
2003-06-30 14:50:48 +00:00
|
|
|
return sSelect;
|
|
|
|
}
|
|
|
|
|
|
|
|
SwField * SwDropDownField::Copy() const
|
|
|
|
{
|
|
|
|
return new SwDropDownField(*this);
|
|
|
|
}
|
|
|
|
|
2013-07-14 15:21:18 +02:00
|
|
|
OUString SwDropDownField::GetPar1() const
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
return GetSelectedItem();
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString SwDropDownField::GetPar2() const
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
return GetName();
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SwDropDownField::SetPar1(const OUString & rStr)
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
SetSelectedItem(rStr);
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SwDropDownField::SetPar2(const OUString & rName)
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
SetName(rName);
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SwDropDownField::SetItems(const vector<OUString> & rItems)
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
aValues = rItems;
|
2013-07-14 15:21:18 +02:00
|
|
|
aSelectedItem = OUString();
|
2003-06-30 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
2007-09-27 07:49:24 +00:00
|
|
|
void SwDropDownField::SetItems(const uno::Sequence<OUString> & rItems)
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
aValues.clear();
|
|
|
|
|
|
|
|
sal_Int32 aCount = rItems.getLength();
|
|
|
|
for (int i = 0; i < aCount; i++)
|
|
|
|
aValues.push_back(rItems[i]);
|
|
|
|
|
2013-07-14 15:21:18 +02:00
|
|
|
aSelectedItem = OUString();
|
2003-06-30 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
2007-09-27 07:49:24 +00:00
|
|
|
uno::Sequence<OUString> SwDropDownField::GetItemSequence() const
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
2007-09-27 07:49:24 +00:00
|
|
|
uno::Sequence<OUString> aSeq( aValues.size() );
|
2003-06-30 14:50:48 +00:00
|
|
|
OUString* pSeq = aSeq.getArray();
|
|
|
|
int i = 0;
|
2013-04-07 12:06:47 +02:00
|
|
|
vector<OUString>::const_iterator aIt;
|
2003-06-30 14:50:48 +00:00
|
|
|
|
2010-12-23 12:51:06 +00:00
|
|
|
for (aIt = aValues.begin(); aIt != aValues.end(); ++aIt)
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
2012-03-07 16:52:06 +00:00
|
|
|
pSeq[i] = *aIt;
|
2003-06-30 14:50:48 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aSeq;
|
|
|
|
}
|
|
|
|
|
2013-07-14 15:21:18 +02:00
|
|
|
OUString SwDropDownField::GetSelectedItem() const
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
return aSelectedItem;
|
|
|
|
}
|
|
|
|
|
2013-07-14 15:21:18 +02:00
|
|
|
OUString SwDropDownField::GetName() const
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
return aName;
|
|
|
|
}
|
|
|
|
|
2013-07-14 15:21:18 +02:00
|
|
|
OUString SwDropDownField::GetHelp() const
|
2007-03-09 12:15:10 +00:00
|
|
|
{
|
|
|
|
return aHelp;
|
|
|
|
}
|
|
|
|
|
2013-07-14 15:21:18 +02:00
|
|
|
OUString SwDropDownField::GetToolTip() const
|
2007-03-09 12:15:10 +00:00
|
|
|
{
|
|
|
|
return aToolTip;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
sal_Bool SwDropDownField::SetSelectedItem(const OUString & rItem)
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
vector<OUString>::const_iterator aIt =
|
2004-08-23 09:53:43 +00:00
|
|
|
std::find(aValues.begin(), aValues.end(), rItem);
|
2003-06-30 14:50:48 +00:00
|
|
|
|
|
|
|
if (aIt != aValues.end())
|
|
|
|
aSelectedItem = *aIt;
|
|
|
|
else
|
2013-04-07 12:06:47 +02:00
|
|
|
aSelectedItem = OUString();
|
2003-06-30 14:50:48 +00:00
|
|
|
|
|
|
|
return (aIt != aValues.end());
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SwDropDownField::SetName(const OUString & rName)
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
aName = rName;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SwDropDownField::SetHelp(const OUString & rHelp)
|
2007-03-09 12:15:10 +00:00
|
|
|
{
|
|
|
|
aHelp = rHelp;
|
|
|
|
}
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
void SwDropDownField::SetToolTip(const OUString & rToolTip)
|
2007-03-09 12:15:10 +00:00
|
|
|
{
|
|
|
|
aToolTip = rToolTip;
|
|
|
|
}
|
|
|
|
|
2011-03-14 16:51:14 +00:00
|
|
|
bool SwDropDownField::QueryValue(::uno::Any &rVal, sal_uInt16 nWhich) const
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
2007-09-27 07:49:24 +00:00
|
|
|
nWhich &= ~CONVERT_TWIPS;
|
|
|
|
switch( nWhich )
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
case FIELD_PROP_PAR1:
|
2013-07-14 15:21:18 +02:00
|
|
|
rVal <<= aSelectedItem;
|
2003-06-30 14:50:48 +00:00
|
|
|
break;
|
|
|
|
case FIELD_PROP_PAR2:
|
2013-07-14 15:21:18 +02:00
|
|
|
rVal <<= aName;
|
2003-06-30 14:50:48 +00:00
|
|
|
break;
|
2007-03-09 12:15:10 +00:00
|
|
|
case FIELD_PROP_PAR3:
|
2013-07-14 15:21:18 +02:00
|
|
|
rVal <<= aHelp;
|
2007-03-09 12:15:10 +00:00
|
|
|
break;
|
|
|
|
case FIELD_PROP_PAR4:
|
2013-07-14 15:21:18 +02:00
|
|
|
rVal <<= aToolTip;
|
2007-03-09 12:15:10 +00:00
|
|
|
break;
|
2003-06-30 14:50:48 +00:00
|
|
|
case FIELD_PROP_STRINGS:
|
|
|
|
rVal <<= GetItemSequence();
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-03-01 19:09:12 +01:00
|
|
|
OSL_FAIL("illegal property");
|
2003-06-30 14:50:48 +00:00
|
|
|
}
|
2010-10-04 15:23:52 +01:00
|
|
|
return true;
|
2003-06-30 14:50:48 +00:00
|
|
|
}
|
|
|
|
|
2010-10-04 15:23:52 +01:00
|
|
|
bool SwDropDownField::PutValue(const uno::Any &rVal,
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nWhich)
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
2007-09-27 07:49:24 +00:00
|
|
|
switch( nWhich )
|
2003-06-30 14:50:48 +00:00
|
|
|
{
|
|
|
|
case FIELD_PROP_PAR1:
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aTmpStr;
|
2012-03-07 16:52:06 +00:00
|
|
|
rVal >>= aTmpStr;
|
2003-06-30 14:50:48 +00:00
|
|
|
|
|
|
|
SetSelectedItem(aTmpStr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIELD_PROP_PAR2:
|
2013-07-14 15:21:18 +02:00
|
|
|
rVal >>= aName;
|
2003-06-30 14:50:48 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-09 12:15:10 +00:00
|
|
|
case FIELD_PROP_PAR3:
|
2013-07-14 15:21:18 +02:00
|
|
|
rVal >>= aHelp;
|
2007-03-09 12:15:10 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FIELD_PROP_PAR4:
|
2013-07-14 15:21:18 +02:00
|
|
|
rVal >>= aToolTip;
|
2007-03-09 12:15:10 +00:00
|
|
|
break;
|
|
|
|
|
2003-06-30 14:50:48 +00:00
|
|
|
case FIELD_PROP_STRINGS:
|
|
|
|
{
|
2007-09-27 07:49:24 +00:00
|
|
|
uno::Sequence<OUString> aSeq;
|
2003-06-30 14:50:48 +00:00
|
|
|
rVal >>= aSeq;
|
|
|
|
SetItems(aSeq);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-03-01 19:09:12 +01:00
|
|
|
OSL_FAIL("illegal property");
|
2003-06-30 14:50:48 +00:00
|
|
|
}
|
2010-10-04 15:23:52 +01:00
|
|
|
return true;
|
2003-06-30 14:50:48 +00:00
|
|
|
}
|
2010-10-14 08:30:41 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|