xref: /aoo41x/main/sw/source/ui/cctrl/swlbox.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <tools/debug.hxx>
33 #include <unotools/charclass.hxx>
34 #include <swtypes.hxx>
35 #include <swlbox.hxx>
36 
37 using namespace nsSwComboBoxStyle;
38 
39 
40 SV_IMPL_PTRARR(SwEntryLst, SwBoxEntry*)
41 
42 /*--------------------------------------------------------------------
43 	 Beschreibung: Ein ListboxElement
44  --------------------------------------------------------------------*/
45 
46 
47 SwBoxEntry::SwBoxEntry() :
48 	bModified(sal_False),
49 	bNew(sal_False),
50 	nId(LISTBOX_APPEND)
51 {
52 }
53 
54 
55 SwBoxEntry::SwBoxEntry(const String& aNam, sal_uInt16 nIdx) :
56 	bModified(sal_False),
57 	bNew(sal_False),
58 	aName(aNam),
59 	nId(nIdx)
60 {
61 }
62 
63 
64 SwBoxEntry::SwBoxEntry(const SwBoxEntry& rOld) :
65     bModified(rOld.bModified),
66     bNew(rOld.bNew),
67     aName(rOld.aName),
68     nId(rOld.nId)
69 {
70 
71 }
72 
73 
74 
75 SwComboBox::SwComboBox(Window* pParent, const ResId& rId, sal_uInt16 nStyleBits ):
76 	ComboBox(pParent, rId),
77 	nStyle(nStyleBits)
78 {
79 	// Verwaltung fuer die Stringlist aus der Resource aufbauen
80 	sal_uInt16 nSize = GetEntryCount();
81 	for( sal_uInt16 i=0; i < nSize; ++i )
82 	{
83 		const SwBoxEntry* pTmp = new SwBoxEntry(ComboBox::GetEntry(i), i);
84 		aEntryLst.Insert(pTmp, aEntryLst.Count() );
85 	}
86 }
87 
88 /*--------------------------------------------------------------------
89 	 Beschreibung: Basisklasse Dtor
90  --------------------------------------------------------------------*/
91 
92 
93 SwComboBox::~SwComboBox()
94 {
95 // das erledigen die Listen doch schon selbst im DTOR!
96 //	aEntryLst.DeleteAndDestroy(0, 	aEntryLst.Count());
97 //	aDelEntryLst.DeleteAndDestroy(0, aDelEntryLst.Count());
98 }
99 
100 /*--------------------------------------------------------------------
101 	 Beschreibung: Eintrag in die ComboBox aufnehmen
102  --------------------------------------------------------------------*/
103 
104 
105 void SwComboBox::InsertEntry(const SwBoxEntry& rEntry)
106 {
107 	InsertSorted(new SwBoxEntry(rEntry));
108 }
109 
110 /*--------------------------------------------------------------------
111 	 Beschreibung: Eintrag aus der Liste loeschen
112  --------------------------------------------------------------------*/
113 
114 
115 void SwComboBox::RemoveEntry(sal_uInt16 nPos)
116 {
117 	if(nPos >= aEntryLst.Count())
118 		return;
119 
120 	// Altes Element austragen
121 	SwBoxEntry* pEntry = aEntryLst[nPos];
122 	aEntryLst.Remove(nPos, 1);
123 	ComboBox::RemoveEntry(nPos);
124 
125 	// keine neuen Eintraege in die Liste mit aufnehmen
126 	if(pEntry->bNew)
127 		return;
128 
129 	// in DeleteListe eintragen
130 	aDelEntryLst.C40_INSERT(SwBoxEntry, pEntry, aDelEntryLst.Count());
131 }
132 
133 
134 
135 /*--------------------------------------------------------------------
136 	 Beschreibung: Position by Name
137  --------------------------------------------------------------------*/
138 
139 sal_uInt16 SwComboBox::GetEntryPos(const SwBoxEntry& rEntry) const
140 {
141 	return ComboBox::GetEntryPos(rEntry.aName);
142 }
143 
144 /*--------------------------------------------------------------------
145 	 Beschreibung: Rund um die Entries
146  --------------------------------------------------------------------*/
147 
148 
149 const SwBoxEntry& SwComboBox::GetEntry(sal_uInt16 nPos) const
150 {
151 	if(nPos < aEntryLst.Count())
152 		return *aEntryLst[nPos];
153 
154 	return aDefault;
155 }
156 
157 /*--------------------------------------------------------------------
158 	 Beschreibung: geloeschte Eintraege
159  --------------------------------------------------------------------*/
160 
161 
162 sal_uInt16 SwComboBox::GetRemovedCount() const
163 {
164 	return aDelEntryLst.Count();
165 }
166 
167 
168 const SwBoxEntry& SwComboBox::GetRemovedEntry(sal_uInt16 nPos) const
169 {
170 	if(nPos < aDelEntryLst.Count())
171 		return *aDelEntryLst[nPos];
172 
173 	return aDefault;
174 }
175 
176 /*--------------------------------------------------------------------
177 	 Beschreibung: Sortiert einfuegen
178  --------------------------------------------------------------------*/
179 
180 
181 void SwComboBox::InsertSorted(SwBoxEntry* pEntry)
182 {
183 	ComboBox::InsertEntry(pEntry->aName);
184 	sal_uInt16 nPos = ComboBox::GetEntryPos(pEntry->aName);
185 	aEntryLst.C40_INSERT(SwBoxEntry, pEntry, nPos);
186 }
187 
188 
189 /*--------------------------------------------------------------------
190 	Beschreibung: Je nach Option bestimmte Zeichen ausblenden
191  --------------------------------------------------------------------*/
192 
193 
194 void SwComboBox::KeyInput( const KeyEvent& rKEvt )
195 {
196 	sal_uInt16 nChar = rKEvt.GetCharCode();
197 
198 	if(nStyle & CBS_FILENAME)
199 	{
200 #if defined UNX
201 		if(nChar == '/' || nChar == ' ' )
202 			return;
203 #else
204 		if(nChar == ':' || nChar == '\\' || nChar == '.' || nChar == ' ')
205 			return;
206 #endif
207 	}
208 	ComboBox::KeyInput(rKEvt);
209 }
210 
211 
212 
213 /*--------------------------------------------------------------------
214 	Beschreibung: Text nach Option konvertieren
215  --------------------------------------------------------------------*/
216 
217 
218 String SwComboBox::GetText() const
219 {
220 	String aTxt( ComboBox::GetText() );
221 
222 	if(nStyle & CBS_LOWER)
223 		GetAppCharClass().toLower( aTxt );
224 	else if( nStyle & CBS_UPPER )
225 		GetAppCharClass().toUpper( aTxt );
226 
227 	return aTxt;
228 }
229 
230 
231 
232