Files
libreoffice/sw/source/ui/cctrl/swlbox.cxx

172 lines
4.2 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2000-09-18 16:15:01 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 16:15:01 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 16:15:01 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 16:15:01 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 16:15:01 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 16:15:01 +00:00
*
************************************************************************/
2010-10-20 15:36:15 +01:00
#include <osl/diagnose.h>
2000-09-18 16:15:01 +00:00
#include <unotools/charclass.hxx>
#include <swtypes.hxx>
#include <swlbox.hxx>
using namespace nsSwComboBoxStyle;
2000-09-18 16:15:01 +00:00
2010-10-20 15:36:15 +01:00
// Description: ListboxElement
2000-09-18 16:15:01 +00:00
SwBoxEntry::SwBoxEntry() :
bModified(sal_False),
bNew(sal_False),
2000-09-18 16:15:01 +00:00
nId(LISTBOX_APPEND)
{
}
SwBoxEntry::SwBoxEntry(const String& aNam, sal_uInt16 nIdx) :
bModified(sal_False),
bNew(sal_False),
2000-09-18 16:15:01 +00:00
aName(aNam),
nId(nIdx)
{
}
SwBoxEntry::SwBoxEntry(const SwBoxEntry& rOld) :
bModified(rOld.bModified),
2000-09-18 16:15:01 +00:00
bNew(rOld.bNew),
aName(rOld.aName),
nId(rOld.nId)
2000-09-18 16:15:01 +00:00
{
}
SwComboBox::SwComboBox(Window* pParent, const ResId& rId, sal_uInt16 nStyleBits ):
2000-09-18 16:15:01 +00:00
ComboBox(pParent, rId),
nStyle(nStyleBits)
{
// create administration for the resource's Stringlist
sal_uInt16 nSize = GetEntryCount();
for( sal_uInt16 i=0; i < nSize; ++i )
2000-09-18 16:15:01 +00:00
{
SwBoxEntry* pTmp = new SwBoxEntry(ComboBox::GetEntry(i), i);
aEntryLst.push_back(pTmp);
2000-09-18 16:15:01 +00:00
}
}
2010-10-20 15:36:15 +01:00
// Basic class Dtor
2000-09-18 16:15:01 +00:00
SwComboBox::~SwComboBox()
{
}
void SwComboBox::InsertEntry(const SwBoxEntry& rEntry)
{
InsertSorted(new SwBoxEntry(rEntry));
}
void SwComboBox::RemoveEntry(sal_uInt16 nPos)
2000-09-18 16:15:01 +00:00
{
if(nPos >= aEntryLst.size())
2000-09-18 16:15:01 +00:00
return;
2010-10-20 15:36:15 +01:00
// Remove old element
SwBoxEntry* pEntry = &aEntryLst[nPos];
2000-09-18 16:15:01 +00:00
ComboBox::RemoveEntry(nPos);
2010-10-20 15:36:15 +01:00
// Don't add new entries to the list
2000-09-18 16:15:01 +00:00
if(pEntry->bNew)
{
aEntryLst.erase(aEntryLst.begin() + nPos);
}
else
{
// add to DelEntryLst
aDelEntryLst.transfer(aDelEntryLst.end(),
aEntryLst.begin() + nPos, aEntryLst);
}
2000-09-18 16:15:01 +00:00
}
sal_uInt16 SwComboBox::GetEntryPos(const SwBoxEntry& rEntry) const
2000-09-18 16:15:01 +00:00
{
return ComboBox::GetEntryPos(rEntry.aName);
}
const SwBoxEntry& SwComboBox::GetEntry(sal_uInt16 nPos) const
2000-09-18 16:15:01 +00:00
{
if(nPos < aEntryLst.size())
return aEntryLst[nPos];
2000-09-18 16:15:01 +00:00
return aDefault;
}
sal_uInt16 SwComboBox::GetRemovedCount() const
2000-09-18 16:15:01 +00:00
{
return aDelEntryLst.size();
2000-09-18 16:15:01 +00:00
}
const SwBoxEntry& SwComboBox::GetRemovedEntry(sal_uInt16 nPos) const
2000-09-18 16:15:01 +00:00
{
if(nPos < aDelEntryLst.size())
return aDelEntryLst[nPos];
2000-09-18 16:15:01 +00:00
return aDefault;
}
void SwComboBox::InsertSorted(SwBoxEntry* pEntry)
{
ComboBox::InsertEntry(pEntry->aName);
sal_uInt16 nPos = ComboBox::GetEntryPos(pEntry->aName);
aEntryLst.insert( aEntryLst.begin() + nPos, pEntry );
2000-09-18 16:15:01 +00:00
}
void SwComboBox::KeyInput( const KeyEvent& rKEvt )
{
sal_uInt16 nChar = rKEvt.GetCharCode();
2000-09-18 16:15:01 +00:00
if(nStyle & CBS_FILENAME)
{
#if defined UNX
2000-09-18 16:15:01 +00:00
if(nChar == '/' || nChar == ' ' )
return;
#else
if(nChar == ':' || nChar == '\\' || nChar == '.' || nChar == ' ')
return;
#endif
}
ComboBox::KeyInput(rKEvt);
}
2010-10-20 15:36:15 +01:00
// Convert text according to option
2000-09-18 16:15:01 +00:00
String SwComboBox::GetText() const
{
String aTxt( ComboBox::GetText() );
if(nStyle & CBS_LOWER)
aTxt = GetAppCharClass().lowercase( aTxt );
2000-09-18 16:15:01 +00:00
else if( nStyle & CBS_UPPER )
aTxt = GetAppCharClass().uppercase( aTxt );
2000-09-18 16:15:01 +00:00
return aTxt;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */