xref: /AOO41X/main/svtools/source/control/svxbox.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svtools.hxx"
30*cdf0e10cSrcweir #include <tools/debug.hxx>
31*cdf0e10cSrcweir #include <vcl/svapp.hxx>
32*cdf0e10cSrcweir #include <svtools/svxbox.hxx>
33*cdf0e10cSrcweir #include <unotools/charclass.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // -----------------------------------------------------------------------
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir SV_IMPL_PTRARR(SvxEntryLst, SvxBoxEntry*)
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir /*--------------------------------------------------------------------
40*cdf0e10cSrcweir 	 Beschreibung: Ein ListboxElement
41*cdf0e10cSrcweir  --------------------------------------------------------------------*/
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir SvxBoxEntry::SvxBoxEntry() :
44*cdf0e10cSrcweir     nId(LISTBOX_ENTRY_NOTFOUND),
45*cdf0e10cSrcweir     bModified(sal_False),
46*cdf0e10cSrcweir     bNew(sal_False)
47*cdf0e10cSrcweir {
48*cdf0e10cSrcweir }
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir SvxBoxEntry::SvxBoxEntry(const String& aNam, sal_uInt16 nIdx) :
52*cdf0e10cSrcweir     aName(aNam),
53*cdf0e10cSrcweir     nId(nIdx),
54*cdf0e10cSrcweir     bModified(sal_False),
55*cdf0e10cSrcweir     bNew(sal_False)
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir }
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir SvxBoxEntry::SvxBoxEntry(const SvxBoxEntry& rOld) :
61*cdf0e10cSrcweir 	aName(rOld.aName),
62*cdf0e10cSrcweir 	nId(rOld.nId),
63*cdf0e10cSrcweir     bModified(rOld.bModified),
64*cdf0e10cSrcweir     bNew(rOld.bNew)
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir }
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir /*--------------------------------------------------------------------
69*cdf0e10cSrcweir 	 Beschreibung:
70*cdf0e10cSrcweir  --------------------------------------------------------------------*/
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir SvxListBox::SvxListBox(Window* pParent, WinBits nBits) :
73*cdf0e10cSrcweir 	ListBox(pParent, nBits)
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir 	InitListBox();
76*cdf0e10cSrcweir }
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir SvxListBox::SvxListBox(Window* pParent, const ResId& rId):
80*cdf0e10cSrcweir 	ListBox(pParent, rId)
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 	InitListBox();
83*cdf0e10cSrcweir }
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir /*--------------------------------------------------------------------
86*cdf0e10cSrcweir 	 Beschreibung: Basisklasse Dtor
87*cdf0e10cSrcweir  --------------------------------------------------------------------*/
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir __EXPORT SvxListBox::~SvxListBox()
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir 	aEntryLst.DeleteAndDestroy(0,	aEntryLst.Count());
92*cdf0e10cSrcweir 	aDelEntryLst.DeleteAndDestroy(0, aDelEntryLst.Count());
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir /*--------------------------------------------------------------------
96*cdf0e10cSrcweir 	 Beschreibung: Evtl. Liste aus der Ressource beachten
97*cdf0e10cSrcweir  --------------------------------------------------------------------*/
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir void SvxListBox::InitListBox()
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir 	// Verwaltung fuer die Stringlist aus der Resource aufbauen
102*cdf0e10cSrcweir 	sal_uInt16 nSize = GetEntryCount();
103*cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
104*cdf0e10cSrcweir 	{	const SvxBoxEntry* pTmp = new SvxBoxEntry(ListBox::GetEntry(i), i);
105*cdf0e10cSrcweir 		const SvxBoxEntry* &rpTmp = pTmp;
106*cdf0e10cSrcweir 		aEntryLst.Insert(rpTmp, aEntryLst.Count());
107*cdf0e10cSrcweir 	}
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir /*--------------------------------------------------------------------
111*cdf0e10cSrcweir 	 Beschreibung: neue Eintraege verwalten
112*cdf0e10cSrcweir  --------------------------------------------------------------------*/
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir void SvxListBox::InsertNewEntry(const SvxBoxEntry& rEntry)
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir 	SvxBoxEntry* pNew = new SvxBoxEntry(rEntry);
117*cdf0e10cSrcweir 	pNew->bNew = sal_True;
118*cdf0e10cSrcweir 	InsertSorted(pNew);
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir /*--------------------------------------------------------------------
122*cdf0e10cSrcweir 	 Beschreibung: Eintrag in die ListBox aufnehmen
123*cdf0e10cSrcweir  --------------------------------------------------------------------*/
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir void SvxListBox::InsertEntry(const SvxBoxEntry& rEntry, sal_uInt16 nPos)
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir 	if(nPos != LISTBOX_ENTRY_NOTFOUND)
128*cdf0e10cSrcweir 	{
129*cdf0e10cSrcweir 		SvxBoxEntry* pEntry = new SvxBoxEntry(rEntry);
130*cdf0e10cSrcweir 		ListBox::InsertEntry(pEntry->aName, nPos);
131*cdf0e10cSrcweir 		//const SvxBoxEntry* &rpEntry = pEntry;
132*cdf0e10cSrcweir 		aEntryLst.C40_INSERT(SvxBoxEntry, pEntry, nPos);
133*cdf0e10cSrcweir 	}
134*cdf0e10cSrcweir 	else
135*cdf0e10cSrcweir 		InsertSorted(new SvxBoxEntry(rEntry));
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir /*--------------------------------------------------------------------
139*cdf0e10cSrcweir 	 Beschreibung: Eintrag aus der Liste loeschen
140*cdf0e10cSrcweir  --------------------------------------------------------------------*/
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir void SvxListBox::RemoveEntry(sal_uInt16 nPos)
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir 	if(nPos >= aEntryLst.Count())
145*cdf0e10cSrcweir 		return;
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 	// Altes Element austragen
148*cdf0e10cSrcweir 	SvxBoxEntry* pEntry = aEntryLst[nPos];
149*cdf0e10cSrcweir 	aEntryLst.Remove(nPos, 1);
150*cdf0e10cSrcweir 	ListBox::RemoveEntry(nPos);
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	// keine neuen Eintraege in die Liste mit aufnehmen
153*cdf0e10cSrcweir 	if(pEntry->bNew)
154*cdf0e10cSrcweir 		return;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	// in DeleteListe eintragen
157*cdf0e10cSrcweir 	aDelEntryLst.C40_INSERT(SvxBoxEntry, pEntry, aDelEntryLst.Count());
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir /*--------------------------------------------------------------------
161*cdf0e10cSrcweir 	 Beschreibung: Eintrag ueber konkretes Obkjekt loeschen
162*cdf0e10cSrcweir  --------------------------------------------------------------------*/
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir void SvxListBox::RemoveEntry(const SvxBoxEntry& rEntry)
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	sal_uInt16 nPos = ListBox::GetEntryPos(rEntry.aName);
167*cdf0e10cSrcweir 	RemoveEntry(nPos);
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir /*--------------------------------------------------------------------
171*cdf0e10cSrcweir 	 Beschreibung: Listen loeschen und Anzeige loeschen
172*cdf0e10cSrcweir  --------------------------------------------------------------------*/
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir void SvxListBox::Clear()
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir 	ListBox::Clear();
177*cdf0e10cSrcweir 	aEntryLst.DeleteAndDestroy(0, aEntryLst.Count());
178*cdf0e10cSrcweir 	aDelEntryLst.DeleteAndDestroy(0, aDelEntryLst.Count());
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir /*--------------------------------------------------------------------
182*cdf0e10cSrcweir 	 Beschreibung: Position by Name
183*cdf0e10cSrcweir  --------------------------------------------------------------------*/
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir sal_uInt16 SvxListBox::GetEntryPos(const SvxBoxEntry& rEntry) const
186*cdf0e10cSrcweir {
187*cdf0e10cSrcweir 	return ListBox::GetEntryPos(rEntry.aName);
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir /*--------------------------------------------------------------------
191*cdf0e10cSrcweir 	 Beschreibung: Rund um die Entries
192*cdf0e10cSrcweir  --------------------------------------------------------------------*/
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir const SvxBoxEntry& SvxListBox::GetSvxBoxEntry(sal_uInt16 nPos) const
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir 	if(nPos < aEntryLst.Count())
197*cdf0e10cSrcweir 		return *aEntryLst[nPos];
198*cdf0e10cSrcweir 	else
199*cdf0e10cSrcweir 		return aDefault;
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir /*--------------------------------------------------------------------
203*cdf0e10cSrcweir 	 Beschreibung: aktullen Eintrag zurueckgeben
204*cdf0e10cSrcweir  --------------------------------------------------------------------*/
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir const SvxBoxEntry& SvxListBox::GetSelectSvxBoxEntry(sal_uInt16 nSelId) const
207*cdf0e10cSrcweir {
208*cdf0e10cSrcweir 	String aName(ListBox::GetSelectEntry(nSelId));
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 	if(aName.Len() > 0)
211*cdf0e10cSrcweir 	{
212*cdf0e10cSrcweir 		for (sal_uInt16 i=0; i < aEntryLst.Count(); i++)
213*cdf0e10cSrcweir 		{
214*cdf0e10cSrcweir 			if(aEntryLst[i]->aName == aName )
215*cdf0e10cSrcweir 				return *aEntryLst[i];
216*cdf0e10cSrcweir 		}
217*cdf0e10cSrcweir 	}
218*cdf0e10cSrcweir 	return aDefault;
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir /*--------------------------------------------------------------------
222*cdf0e10cSrcweir 	 Beschreibung: modifizierte Eintraege
223*cdf0e10cSrcweir  --------------------------------------------------------------------*/
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir sal_uInt16 SvxListBox::GetModifiedCount() const
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir 	sal_uInt16 nMod  = 0;
228*cdf0e10cSrcweir 	sal_uInt16 nSize = aEntryLst.Count();
229*cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
230*cdf0e10cSrcweir 	{	if(aEntryLst[i]->bModified)
231*cdf0e10cSrcweir 			nMod++;
232*cdf0e10cSrcweir 	}
233*cdf0e10cSrcweir 	return nMod;
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir /*--------------------------------------------------------------------
237*cdf0e10cSrcweir 	 Beschreibung: Modifizierte Eintraege behandeln
238*cdf0e10cSrcweir  --------------------------------------------------------------------*/
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir void SvxListBox::ModifyEntry(sal_uInt16 nPos, const String& rName)
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir 	if(nPos >= aEntryLst.Count())
243*cdf0e10cSrcweir 		return;
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 	SvxBoxEntry* pEntry = aEntryLst[nPos];
246*cdf0e10cSrcweir 	aEntryLst.Remove(nPos, 1);
247*cdf0e10cSrcweir 	aEntryLst[nPos]->aName 		= rName;
248*cdf0e10cSrcweir 	aEntryLst[nPos]->bModified 	= sal_True;
249*cdf0e10cSrcweir 	ListBox::RemoveEntry(nPos);
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	InsertSorted(pEntry);
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir /*--------------------------------------------------------------------
255*cdf0e10cSrcweir 	 Beschreibung: alle modifizierten Eintraege bahandeln
256*cdf0e10cSrcweir  --------------------------------------------------------------------*/
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir const SvxBoxEntry& SvxListBox::GetModifiedEntry(sal_uInt16 nPos) const
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir 	sal_uInt16 nSize = aEntryLst.Count();
261*cdf0e10cSrcweir 	sal_uInt16 nMod  = 0;
262*cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
263*cdf0e10cSrcweir 	{	if(aEntryLst[i]->bModified)
264*cdf0e10cSrcweir 		{	if(nMod == nPos)
265*cdf0e10cSrcweir 				return *aEntryLst[i];
266*cdf0e10cSrcweir 			nMod++;
267*cdf0e10cSrcweir 		}
268*cdf0e10cSrcweir 	}
269*cdf0e10cSrcweir 	return aDefault;
270*cdf0e10cSrcweir }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir /*--------------------------------------------------------------------
273*cdf0e10cSrcweir 	 Beschreibung: geloeschte Eintraege
274*cdf0e10cSrcweir  --------------------------------------------------------------------*/
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir sal_uInt16 SvxListBox::GetRemovedCount() const
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir 	return aDelEntryLst.Count();
279*cdf0e10cSrcweir }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir const SvxBoxEntry& SvxListBox::GetRemovedEntry(sal_uInt16 nPos) const
283*cdf0e10cSrcweir {
284*cdf0e10cSrcweir 	if(nPos < aDelEntryLst.Count())
285*cdf0e10cSrcweir 		return *aDelEntryLst[nPos];
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 	return aDefault;
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir /*--------------------------------------------------------------------
291*cdf0e10cSrcweir 	 Beschreibung: Neue Entries begutachten
292*cdf0e10cSrcweir  --------------------------------------------------------------------*/
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir sal_uInt16 SvxListBox::GetNewCount() const
295*cdf0e10cSrcweir {
296*cdf0e10cSrcweir 	sal_uInt16 nNew = 0;
297*cdf0e10cSrcweir 	sal_uInt16 nSize = aEntryLst.Count();
298*cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
299*cdf0e10cSrcweir 	{	if(aEntryLst[i]->bNew)
300*cdf0e10cSrcweir 			nNew++;
301*cdf0e10cSrcweir 	}
302*cdf0e10cSrcweir 	return nNew;
303*cdf0e10cSrcweir }
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir /*--------------------------------------------------------------------
306*cdf0e10cSrcweir 	 Beschreibung:	Alle neuen Eintraege ueberpruefen
307*cdf0e10cSrcweir  --------------------------------------------------------------------*/
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir const SvxBoxEntry& SvxListBox::GetNewEntry(sal_uInt16 nPos) const
310*cdf0e10cSrcweir {
311*cdf0e10cSrcweir 	sal_uInt16 nSize = aEntryLst.Count();
312*cdf0e10cSrcweir 	sal_uInt16 nNew  = 0;
313*cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
314*cdf0e10cSrcweir 	{	if(aEntryLst[i]->bNew)
315*cdf0e10cSrcweir 		{	if(nNew == nPos)
316*cdf0e10cSrcweir 				return *aEntryLst[i];
317*cdf0e10cSrcweir 			nNew++;
318*cdf0e10cSrcweir 		}
319*cdf0e10cSrcweir 	}
320*cdf0e10cSrcweir 	return aDefault;
321*cdf0e10cSrcweir }
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir /*--------------------------------------------------------------------
324*cdf0e10cSrcweir 	 Beschreibung: Sortiert einfuegen
325*cdf0e10cSrcweir  --------------------------------------------------------------------*/
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir void SvxListBox::InsertSorted(SvxBoxEntry* pEntry)
328*cdf0e10cSrcweir {
329*cdf0e10cSrcweir 	ListBox::InsertEntry(pEntry->aName);
330*cdf0e10cSrcweir 	sal_uInt16 nPos = ListBox::GetEntryPos(pEntry->aName);
331*cdf0e10cSrcweir 	aEntryLst.C40_INSERT(SvxBoxEntry, pEntry, nPos);
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir /*--------------------------------------------------------------------
335*cdf0e10cSrcweir 	 Beschreibung: ComboBoxen mit Verwaltungseinheit
336*cdf0e10cSrcweir  --------------------------------------------------------------------*/
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir SvxComboBox::SvxComboBox(Window* pParent, WinBits nBits, sal_uInt16 nStyleBits) :
339*cdf0e10cSrcweir 	ComboBox(pParent, nBits),
340*cdf0e10cSrcweir 	nStyle(nStyleBits)
341*cdf0e10cSrcweir {
342*cdf0e10cSrcweir 	InitComboBox();
343*cdf0e10cSrcweir }
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir SvxComboBox::SvxComboBox(Window* pParent, const ResId& rId, sal_uInt16 nStyleBits ):
347*cdf0e10cSrcweir 	ComboBox(pParent, rId),
348*cdf0e10cSrcweir 	nStyle(nStyleBits)
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir 	InitComboBox();
351*cdf0e10cSrcweir }
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir /*--------------------------------------------------------------------
354*cdf0e10cSrcweir 	 Beschreibung: Basisklasse Dtor
355*cdf0e10cSrcweir  --------------------------------------------------------------------*/
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir __EXPORT SvxComboBox::~SvxComboBox()
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir 	aEntryLst.DeleteAndDestroy(0,	aEntryLst.Count());
360*cdf0e10cSrcweir 	aDelEntryLst.DeleteAndDestroy(0, aDelEntryLst.Count());
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir /*--------------------------------------------------------------------
364*cdf0e10cSrcweir 	 Beschreibung: Evtl. Liste aus der Ressource beachten
365*cdf0e10cSrcweir  --------------------------------------------------------------------*/
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir void SvxComboBox::InitComboBox()
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir 	// Verwaltung fuer die Stringlist aus der Resource aufbauen
370*cdf0e10cSrcweir 	sal_uInt16 nSize = GetEntryCount();
371*cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
372*cdf0e10cSrcweir 	{	const SvxBoxEntry* pTmp = new SvxBoxEntry(ComboBox::GetEntry(i), i);
373*cdf0e10cSrcweir 		const SvxBoxEntry* &rpTmp = pTmp;
374*cdf0e10cSrcweir 		aEntryLst.Insert(rpTmp, aEntryLst.Count());
375*cdf0e10cSrcweir 	}
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir /*--------------------------------------------------------------------
379*cdf0e10cSrcweir 	 Beschreibung: neue Eintraege verwalten
380*cdf0e10cSrcweir  --------------------------------------------------------------------*/
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir void SvxComboBox::InsertNewEntry(const SvxBoxEntry& rEntry)
383*cdf0e10cSrcweir {
384*cdf0e10cSrcweir 	SvxBoxEntry* pNew = new SvxBoxEntry(rEntry);
385*cdf0e10cSrcweir 	pNew->bNew = sal_True;
386*cdf0e10cSrcweir 	InsertSorted(pNew);
387*cdf0e10cSrcweir }
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir /*--------------------------------------------------------------------
390*cdf0e10cSrcweir 	 Beschreibung: Eintrag in die ComboBox aufnehmen
391*cdf0e10cSrcweir  --------------------------------------------------------------------*/
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir void SvxComboBox::InsertEntry(const SvxBoxEntry& rEntry)
394*cdf0e10cSrcweir {
395*cdf0e10cSrcweir 	InsertSorted(new SvxBoxEntry(rEntry));
396*cdf0e10cSrcweir }
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir /*--------------------------------------------------------------------
399*cdf0e10cSrcweir 	 Beschreibung: Eintrag aus der Liste loeschen
400*cdf0e10cSrcweir  --------------------------------------------------------------------*/
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir void SvxComboBox::RemoveEntry(sal_uInt16 nPos)
403*cdf0e10cSrcweir {
404*cdf0e10cSrcweir 	if(nPos >= aEntryLst.Count())
405*cdf0e10cSrcweir 		return;
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 	// Altes Element austragen
408*cdf0e10cSrcweir 	SvxBoxEntry* pEntry = aEntryLst[nPos];
409*cdf0e10cSrcweir 	aEntryLst.Remove(nPos, 1);
410*cdf0e10cSrcweir 	ComboBox::RemoveEntry(nPos);
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 	// keine neuen Eintraege in die Liste mit aufnehmen
413*cdf0e10cSrcweir 	if(pEntry->bNew)
414*cdf0e10cSrcweir 		return;
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir 	// in DeleteListe eintragen
417*cdf0e10cSrcweir 	aDelEntryLst.C40_INSERT(SvxBoxEntry, pEntry, aDelEntryLst.Count());
418*cdf0e10cSrcweir }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir /*--------------------------------------------------------------------
421*cdf0e10cSrcweir 	 Beschreibung: Eintrag ueber konkretes Obkjekt loeschen
422*cdf0e10cSrcweir  --------------------------------------------------------------------*/
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir void SvxComboBox::RemoveEntry(const SvxBoxEntry& rEntry)
425*cdf0e10cSrcweir {
426*cdf0e10cSrcweir 	sal_uInt16 nPos = ComboBox::GetEntryPos(rEntry.aName);
427*cdf0e10cSrcweir 	RemoveEntry(nPos);
428*cdf0e10cSrcweir }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir /*--------------------------------------------------------------------
431*cdf0e10cSrcweir 	 Beschreibung: Listen loeschen und Anzeige loeschen
432*cdf0e10cSrcweir  --------------------------------------------------------------------*/
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir void SvxComboBox::Clear()
435*cdf0e10cSrcweir {
436*cdf0e10cSrcweir 	ComboBox::Clear();
437*cdf0e10cSrcweir 	aEntryLst.DeleteAndDestroy(0, aEntryLst.Count());
438*cdf0e10cSrcweir 	aDelEntryLst.DeleteAndDestroy(0, aDelEntryLst.Count());
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir /*--------------------------------------------------------------------
443*cdf0e10cSrcweir 	 Beschreibung: Position by Name
444*cdf0e10cSrcweir  --------------------------------------------------------------------*/
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir sal_uInt16 SvxComboBox::GetEntryPos(const SvxBoxEntry& rEntry) const
447*cdf0e10cSrcweir {
448*cdf0e10cSrcweir 	return ComboBox::GetEntryPos(rEntry.aName);
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir /*--------------------------------------------------------------------
452*cdf0e10cSrcweir 	 Beschreibung: Rund um die Entries
453*cdf0e10cSrcweir  --------------------------------------------------------------------*/
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir const SvxBoxEntry& SvxComboBox::GetEntry(sal_uInt16 nPos) const
456*cdf0e10cSrcweir {
457*cdf0e10cSrcweir 	if(nPos < aEntryLst.Count())
458*cdf0e10cSrcweir 		return *aEntryLst[nPos];
459*cdf0e10cSrcweir 	else
460*cdf0e10cSrcweir 		return aDefault;
461*cdf0e10cSrcweir }
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir /*--------------------------------------------------------------------
464*cdf0e10cSrcweir 	 Beschreibung: modifizierte Eintraege
465*cdf0e10cSrcweir  --------------------------------------------------------------------*/
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir sal_uInt16 SvxComboBox::GetModifiedCount() const
468*cdf0e10cSrcweir {
469*cdf0e10cSrcweir 	sal_uInt16 nMod  = 0;
470*cdf0e10cSrcweir 	sal_uInt16 nSize = aEntryLst.Count();
471*cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
472*cdf0e10cSrcweir 	{	if(aEntryLst[i]->bModified)
473*cdf0e10cSrcweir 			nMod++;
474*cdf0e10cSrcweir 	}
475*cdf0e10cSrcweir 	return nMod;
476*cdf0e10cSrcweir }
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir /*--------------------------------------------------------------------
479*cdf0e10cSrcweir 	 Beschreibung: Modifizierte Eintraege behandeln
480*cdf0e10cSrcweir  --------------------------------------------------------------------*/
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir void SvxComboBox::ModifyEntry(sal_uInt16 nPos, const String& rName)
483*cdf0e10cSrcweir {
484*cdf0e10cSrcweir 	if(nPos >= aEntryLst.Count())
485*cdf0e10cSrcweir 		return;
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir 	SvxBoxEntry* pEntry = aEntryLst[nPos];
488*cdf0e10cSrcweir 	aEntryLst.Remove(nPos, 1);
489*cdf0e10cSrcweir 	aEntryLst[nPos]->aName 		= rName;
490*cdf0e10cSrcweir 	aEntryLst[nPos]->bModified 	= sal_True;
491*cdf0e10cSrcweir 	ComboBox::RemoveEntry(nPos);
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir 	InsertSorted(pEntry);
494*cdf0e10cSrcweir }
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir /*--------------------------------------------------------------------
497*cdf0e10cSrcweir 	 Beschreibung: alle modifizierten Eintraege bahandeln
498*cdf0e10cSrcweir  --------------------------------------------------------------------*/
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir const SvxBoxEntry& SvxComboBox::GetModifiedEntry(sal_uInt16 nPos) const
501*cdf0e10cSrcweir {
502*cdf0e10cSrcweir 	sal_uInt16 nSize = aEntryLst.Count();
503*cdf0e10cSrcweir 	sal_uInt16 nMod  = 0;
504*cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
505*cdf0e10cSrcweir 	{	if(aEntryLst[i]->bModified)
506*cdf0e10cSrcweir 		{	if(nMod == nPos)
507*cdf0e10cSrcweir 				return *aEntryLst[i];
508*cdf0e10cSrcweir 			nMod++;
509*cdf0e10cSrcweir 		}
510*cdf0e10cSrcweir 	}
511*cdf0e10cSrcweir 	return aDefault;
512*cdf0e10cSrcweir }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir /*--------------------------------------------------------------------
515*cdf0e10cSrcweir 	 Beschreibung: geloeschte Eintraege
516*cdf0e10cSrcweir  --------------------------------------------------------------------*/
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir sal_uInt16 SvxComboBox::GetRemovedCount() const
519*cdf0e10cSrcweir {
520*cdf0e10cSrcweir 	return aDelEntryLst.Count();
521*cdf0e10cSrcweir }
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir const SvxBoxEntry& SvxComboBox::GetRemovedEntry(sal_uInt16 nPos) const
525*cdf0e10cSrcweir {
526*cdf0e10cSrcweir 	if(nPos < aDelEntryLst.Count())
527*cdf0e10cSrcweir 		return *aDelEntryLst[nPos];
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir 	return aDefault;
530*cdf0e10cSrcweir }
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir /*--------------------------------------------------------------------
533*cdf0e10cSrcweir 	 Beschreibung: Neue Entries begutachten
534*cdf0e10cSrcweir  --------------------------------------------------------------------*/
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir sal_uInt16 SvxComboBox::GetNewCount() const
537*cdf0e10cSrcweir {
538*cdf0e10cSrcweir 	sal_uInt16 nNew = 0;
539*cdf0e10cSrcweir 	sal_uInt16 nSize = aEntryLst.Count();
540*cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
541*cdf0e10cSrcweir 	{	if(aEntryLst[i]->bNew)
542*cdf0e10cSrcweir 			nNew++;
543*cdf0e10cSrcweir 	}
544*cdf0e10cSrcweir 	return nNew;
545*cdf0e10cSrcweir }
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir /*--------------------------------------------------------------------
548*cdf0e10cSrcweir 	 Beschreibung:	Alle neuen Eintraege ueberpruefen
549*cdf0e10cSrcweir  --------------------------------------------------------------------*/
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir const SvxBoxEntry& SvxComboBox::GetNewEntry(sal_uInt16 nPos) const
552*cdf0e10cSrcweir {
553*cdf0e10cSrcweir 	sal_uInt16 nSize = aEntryLst.Count();
554*cdf0e10cSrcweir 	sal_uInt16 nNew  = 0;
555*cdf0e10cSrcweir 	for(sal_uInt16 i=0; i < nSize; ++i)
556*cdf0e10cSrcweir 	{	if(aEntryLst[i]->bNew)
557*cdf0e10cSrcweir 		{	if(nNew == nPos)
558*cdf0e10cSrcweir 				return *aEntryLst[i];
559*cdf0e10cSrcweir 			nNew++;
560*cdf0e10cSrcweir 		}
561*cdf0e10cSrcweir 	}
562*cdf0e10cSrcweir 	return aDefault;
563*cdf0e10cSrcweir }
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir /*--------------------------------------------------------------------
566*cdf0e10cSrcweir 	 Beschreibung: Sortiert einfuegen
567*cdf0e10cSrcweir  --------------------------------------------------------------------*/
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir void SvxComboBox::InsertSorted(SvxBoxEntry* pEntry)
570*cdf0e10cSrcweir {
571*cdf0e10cSrcweir 	ComboBox::InsertEntry(pEntry->aName);
572*cdf0e10cSrcweir 	sal_uInt16 nPos = ComboBox::GetEntryPos(pEntry->aName);
573*cdf0e10cSrcweir 	aEntryLst.C40_INSERT(SvxBoxEntry, pEntry, nPos);
574*cdf0e10cSrcweir }
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir /*--------------------------------------------------------------------
578*cdf0e10cSrcweir 	Beschreibung: Je nach Option bestimmte Zeichen ausblenden
579*cdf0e10cSrcweir  --------------------------------------------------------------------*/
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir void __EXPORT SvxComboBox::KeyInput( const KeyEvent& rKEvt )
582*cdf0e10cSrcweir {
583*cdf0e10cSrcweir 	sal_Unicode cChar = rKEvt.GetCharCode();
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir 	if(nStyle & SVX_CBS_FILENAME)
586*cdf0e10cSrcweir 	{
587*cdf0e10cSrcweir #if defined UNX
588*cdf0e10cSrcweir 		if( cChar == sal_Unicode( '/' ) || cChar == sal_Unicode( ' ' ) )
589*cdf0e10cSrcweir 			return;
590*cdf0e10cSrcweir #else
591*cdf0e10cSrcweir 		if( cChar == sal_Unicode( ':' ) || cChar == sal_Unicode( '\\' ) ||
592*cdf0e10cSrcweir 			cChar == sal_Unicode( '.' ) || cChar == sal_Unicode( ' ' ) )
593*cdf0e10cSrcweir 			return;
594*cdf0e10cSrcweir #endif
595*cdf0e10cSrcweir 	}
596*cdf0e10cSrcweir 	ComboBox::KeyInput(rKEvt);
597*cdf0e10cSrcweir }
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir /*--------------------------------------------------------------------
600*cdf0e10cSrcweir 	Beschreibung: Text nach Option konvertieren
601*cdf0e10cSrcweir  --------------------------------------------------------------------*/
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir String SvxComboBox::GetText() const
604*cdf0e10cSrcweir {
605*cdf0e10cSrcweir 	String aTxt(ComboBox::GetText());
606*cdf0e10cSrcweir 	CharClass aCharClass( Application::GetSettings().GetLocale() );
607*cdf0e10cSrcweir 
608*cdf0e10cSrcweir 	if(nStyle & SVX_CBS_LOWER)
609*cdf0e10cSrcweir 		return aCharClass.lower(aTxt);
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 	if(nStyle & SVX_CBS_UPPER)
612*cdf0e10cSrcweir 		return aCharClass.upper(aTxt);
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir 	return aTxt;
615*cdf0e10cSrcweir }
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir 
618