merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / cctrl / swlbox.cxx
blob9e705b1a7a2f6da269f971e6f8a200ed7923ebff
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: swlbox.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <tools/debug.hxx>
36 #include <unotools/charclass.hxx>
37 #include <swtypes.hxx>
38 #include <swlbox.hxx>
40 using namespace nsSwComboBoxStyle;
43 SV_IMPL_PTRARR(SwEntryLst, SwBoxEntry*)
45 /*--------------------------------------------------------------------
46 Beschreibung: Ein ListboxElement
47 --------------------------------------------------------------------*/
50 SwBoxEntry::SwBoxEntry() :
51 bModified(FALSE),
52 bNew(FALSE),
53 nId(LISTBOX_APPEND)
58 SwBoxEntry::SwBoxEntry(const String& aNam, USHORT nIdx) :
59 bModified(FALSE),
60 bNew(FALSE),
61 aName(aNam),
62 nId(nIdx)
67 SwBoxEntry::SwBoxEntry(const SwBoxEntry& rOld) :
68 bModified(rOld.bModified),
69 bNew(rOld.bNew),
70 aName(rOld.aName),
71 nId(rOld.nId)
78 SwComboBox::SwComboBox(Window* pParent, const ResId& rId, USHORT nStyleBits ):
79 ComboBox(pParent, rId),
80 nStyle(nStyleBits)
82 // Verwaltung fuer die Stringlist aus der Resource aufbauen
83 USHORT nSize = GetEntryCount();
84 for( USHORT i=0; i < nSize; ++i )
86 const SwBoxEntry* pTmp = new SwBoxEntry(ComboBox::GetEntry(i), i);
87 aEntryLst.Insert(pTmp, aEntryLst.Count() );
91 /*--------------------------------------------------------------------
92 Beschreibung: Basisklasse Dtor
93 --------------------------------------------------------------------*/
96 SwComboBox::~SwComboBox()
98 // das erledigen die Listen doch schon selbst im DTOR!
99 // aEntryLst.DeleteAndDestroy(0, aEntryLst.Count());
100 // aDelEntryLst.DeleteAndDestroy(0, aDelEntryLst.Count());
103 /*--------------------------------------------------------------------
104 Beschreibung: Eintrag in die ComboBox aufnehmen
105 --------------------------------------------------------------------*/
108 void SwComboBox::InsertEntry(const SwBoxEntry& rEntry)
110 InsertSorted(new SwBoxEntry(rEntry));
113 /*--------------------------------------------------------------------
114 Beschreibung: Eintrag aus der Liste loeschen
115 --------------------------------------------------------------------*/
118 void SwComboBox::RemoveEntry(USHORT nPos)
120 if(nPos >= aEntryLst.Count())
121 return;
123 // Altes Element austragen
124 SwBoxEntry* pEntry = aEntryLst[nPos];
125 aEntryLst.Remove(nPos, 1);
126 ComboBox::RemoveEntry(nPos);
128 // keine neuen Eintraege in die Liste mit aufnehmen
129 if(pEntry->bNew)
130 return;
132 // in DeleteListe eintragen
133 aDelEntryLst.C40_INSERT(SwBoxEntry, pEntry, aDelEntryLst.Count());
138 /*--------------------------------------------------------------------
139 Beschreibung: Position by Name
140 --------------------------------------------------------------------*/
142 USHORT SwComboBox::GetEntryPos(const SwBoxEntry& rEntry) const
144 return ComboBox::GetEntryPos(rEntry.aName);
147 /*--------------------------------------------------------------------
148 Beschreibung: Rund um die Entries
149 --------------------------------------------------------------------*/
152 const SwBoxEntry& SwComboBox::GetEntry(USHORT nPos) const
154 if(nPos < aEntryLst.Count())
155 return *aEntryLst[nPos];
157 return aDefault;
160 /*--------------------------------------------------------------------
161 Beschreibung: geloeschte Eintraege
162 --------------------------------------------------------------------*/
165 USHORT SwComboBox::GetRemovedCount() const
167 return aDelEntryLst.Count();
171 const SwBoxEntry& SwComboBox::GetRemovedEntry(USHORT nPos) const
173 if(nPos < aDelEntryLst.Count())
174 return *aDelEntryLst[nPos];
176 return aDefault;
179 /*--------------------------------------------------------------------
180 Beschreibung: Sortiert einfuegen
181 --------------------------------------------------------------------*/
184 void SwComboBox::InsertSorted(SwBoxEntry* pEntry)
186 ComboBox::InsertEntry(pEntry->aName);
187 USHORT nPos = ComboBox::GetEntryPos(pEntry->aName);
188 aEntryLst.C40_INSERT(SwBoxEntry, pEntry, nPos);
192 /*--------------------------------------------------------------------
193 Beschreibung: Je nach Option bestimmte Zeichen ausblenden
194 --------------------------------------------------------------------*/
197 void SwComboBox::KeyInput( const KeyEvent& rKEvt )
199 USHORT nChar = rKEvt.GetCharCode();
201 if(nStyle & CBS_FILENAME)
203 #if defined UNX
204 if(nChar == '/' || nChar == ' ' )
205 return;
206 #else
207 if(nChar == ':' || nChar == '\\' || nChar == '.' || nChar == ' ')
208 return;
209 #endif
211 ComboBox::KeyInput(rKEvt);
216 /*--------------------------------------------------------------------
217 Beschreibung: Text nach Option konvertieren
218 --------------------------------------------------------------------*/
221 String SwComboBox::GetText() const
223 String aTxt( ComboBox::GetText() );
225 if(nStyle & CBS_LOWER)
226 GetAppCharClass().toLower( aTxt );
227 else if( nStyle & CBS_UPPER )
228 GetAppCharClass().toUpper( aTxt );
230 return aTxt;