update dev300-m58
[ooovba.git] / svx / source / dialog / svxbox.cxx
blobcb8c4c388f5824bcfc44cb640fefa722cd2d1404
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: svxbox.cxx,v $
10 * $Revision: 1.8 $
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_svx.hxx"
33 #include <tools/debug.hxx>
34 #ifndef _APP_HXX //autogen
35 #include <vcl/svapp.hxx>
36 #endif
38 #include <svx/svxbox.hxx>
39 #include <unotools/charclass.hxx>
41 // -----------------------------------------------------------------------
43 SV_IMPL_PTRARR(SvxEntryLst, SvxBoxEntry*)
45 /*--------------------------------------------------------------------
46 Beschreibung: Ein ListboxElement
47 --------------------------------------------------------------------*/
49 SvxBoxEntry::SvxBoxEntry() :
50 nId(LISTBOX_ENTRY_NOTFOUND),
51 bModified(FALSE),
52 bNew(FALSE)
57 SvxBoxEntry::SvxBoxEntry(const String& aNam, USHORT nIdx) :
58 aName(aNam),
59 nId(nIdx),
60 bModified(FALSE),
61 bNew(FALSE)
66 SvxBoxEntry::SvxBoxEntry(const SvxBoxEntry& rOld) :
67 aName(rOld.aName),
68 nId(rOld.nId),
69 bModified(rOld.bModified),
70 bNew(rOld.bNew)
74 /*--------------------------------------------------------------------
75 Beschreibung:
76 --------------------------------------------------------------------*/
78 SvxListBox::SvxListBox(Window* pParent, WinBits nBits) :
79 ListBox(pParent, nBits)
81 InitListBox();
85 SvxListBox::SvxListBox(Window* pParent, const ResId& rId):
86 ListBox(pParent, rId)
88 InitListBox();
91 /*--------------------------------------------------------------------
92 Beschreibung: Basisklasse Dtor
93 --------------------------------------------------------------------*/
95 __EXPORT SvxListBox::~SvxListBox()
97 aEntryLst.DeleteAndDestroy(0, aEntryLst.Count());
98 aDelEntryLst.DeleteAndDestroy(0, aDelEntryLst.Count());
101 /*--------------------------------------------------------------------
102 Beschreibung: Evtl. Liste aus der Ressource beachten
103 --------------------------------------------------------------------*/
105 void SvxListBox::InitListBox()
107 // Verwaltung fuer die Stringlist aus der Resource aufbauen
108 USHORT nSize = GetEntryCount();
109 for(USHORT i=0; i < nSize; ++i)
110 { const SvxBoxEntry* pTmp = new SvxBoxEntry(ListBox::GetEntry(i), i);
111 const SvxBoxEntry* &rpTmp = pTmp;
112 aEntryLst.Insert(rpTmp, aEntryLst.Count());
116 /*--------------------------------------------------------------------
117 Beschreibung: neue Eintraege verwalten
118 --------------------------------------------------------------------*/
120 void SvxListBox::InsertNewEntry(const SvxBoxEntry& rEntry)
122 SvxBoxEntry* pNew = new SvxBoxEntry(rEntry);
123 pNew->bNew = TRUE;
124 InsertSorted(pNew);
127 /*--------------------------------------------------------------------
128 Beschreibung: Eintrag in die ListBox aufnehmen
129 --------------------------------------------------------------------*/
131 void SvxListBox::InsertEntry(const SvxBoxEntry& rEntry, USHORT nPos)
133 if(nPos != LISTBOX_ENTRY_NOTFOUND)
135 SvxBoxEntry* pEntry = new SvxBoxEntry(rEntry);
136 ListBox::InsertEntry(pEntry->aName, nPos);
137 //const SvxBoxEntry* &rpEntry = pEntry;
138 aEntryLst.C40_INSERT(SvxBoxEntry, pEntry, nPos);
140 else
141 InsertSorted(new SvxBoxEntry(rEntry));
144 /*--------------------------------------------------------------------
145 Beschreibung: Eintrag aus der Liste loeschen
146 --------------------------------------------------------------------*/
148 void SvxListBox::RemoveEntry(USHORT nPos)
150 if(nPos >= aEntryLst.Count())
151 return;
153 // Altes Element austragen
154 SvxBoxEntry* pEntry = aEntryLst[nPos];
155 aEntryLst.Remove(nPos, 1);
156 ListBox::RemoveEntry(nPos);
158 // keine neuen Eintraege in die Liste mit aufnehmen
159 if(pEntry->bNew)
160 return;
162 // in DeleteListe eintragen
163 aDelEntryLst.C40_INSERT(SvxBoxEntry, pEntry, aDelEntryLst.Count());
166 /*--------------------------------------------------------------------
167 Beschreibung: Eintrag ueber konkretes Obkjekt loeschen
168 --------------------------------------------------------------------*/
170 void SvxListBox::RemoveEntry(const SvxBoxEntry& rEntry)
172 USHORT nPos = ListBox::GetEntryPos(rEntry.aName);
173 RemoveEntry(nPos);
176 /*--------------------------------------------------------------------
177 Beschreibung: Listen loeschen und Anzeige loeschen
178 --------------------------------------------------------------------*/
180 void SvxListBox::Clear()
182 ListBox::Clear();
183 aEntryLst.DeleteAndDestroy(0, aEntryLst.Count());
184 aDelEntryLst.DeleteAndDestroy(0, aDelEntryLst.Count());
187 /*--------------------------------------------------------------------
188 Beschreibung: Position by Name
189 --------------------------------------------------------------------*/
191 USHORT SvxListBox::GetEntryPos(const SvxBoxEntry& rEntry) const
193 return ListBox::GetEntryPos(rEntry.aName);
196 /*--------------------------------------------------------------------
197 Beschreibung: Rund um die Entries
198 --------------------------------------------------------------------*/
200 const SvxBoxEntry& SvxListBox::GetSvxBoxEntry(USHORT nPos) const
202 if(nPos < aEntryLst.Count())
203 return *aEntryLst[nPos];
204 else
205 return aDefault;
208 /*--------------------------------------------------------------------
209 Beschreibung: aktullen Eintrag zurueckgeben
210 --------------------------------------------------------------------*/
212 const SvxBoxEntry& SvxListBox::GetSelectSvxBoxEntry(USHORT nSelId) const
214 String aName(ListBox::GetSelectEntry(nSelId));
216 if(aName.Len() > 0)
218 for (USHORT i=0; i < aEntryLst.Count(); i++)
220 if(aEntryLst[i]->aName == aName )
221 return *aEntryLst[i];
224 return aDefault;
227 /*--------------------------------------------------------------------
228 Beschreibung: modifizierte Eintraege
229 --------------------------------------------------------------------*/
231 USHORT SvxListBox::GetModifiedCount() const
233 USHORT nMod = 0;
234 USHORT nSize = aEntryLst.Count();
235 for(USHORT i=0; i < nSize; ++i)
236 { if(aEntryLst[i]->bModified)
237 nMod++;
239 return nMod;
242 /*--------------------------------------------------------------------
243 Beschreibung: Modifizierte Eintraege behandeln
244 --------------------------------------------------------------------*/
246 void SvxListBox::ModifyEntry(USHORT nPos, const String& rName)
248 if(nPos >= aEntryLst.Count())
249 return;
251 SvxBoxEntry* pEntry = aEntryLst[nPos];
252 aEntryLst.Remove(nPos, 1);
253 aEntryLst[nPos]->aName = rName;
254 aEntryLst[nPos]->bModified = TRUE;
255 ListBox::RemoveEntry(nPos);
257 InsertSorted(pEntry);
260 /*--------------------------------------------------------------------
261 Beschreibung: alle modifizierten Eintraege bahandeln
262 --------------------------------------------------------------------*/
264 const SvxBoxEntry& SvxListBox::GetModifiedEntry(USHORT nPos) const
266 USHORT nSize = aEntryLst.Count();
267 USHORT nMod = 0;
268 for(USHORT i=0; i < nSize; ++i)
269 { if(aEntryLst[i]->bModified)
270 { if(nMod == nPos)
271 return *aEntryLst[i];
272 nMod++;
275 return aDefault;
278 /*--------------------------------------------------------------------
279 Beschreibung: geloeschte Eintraege
280 --------------------------------------------------------------------*/
282 USHORT SvxListBox::GetRemovedCount() const
284 return aDelEntryLst.Count();
288 const SvxBoxEntry& SvxListBox::GetRemovedEntry(USHORT nPos) const
290 if(nPos < aDelEntryLst.Count())
291 return *aDelEntryLst[nPos];
293 return aDefault;
296 /*--------------------------------------------------------------------
297 Beschreibung: Neue Entries begutachten
298 --------------------------------------------------------------------*/
300 USHORT SvxListBox::GetNewCount() const
302 USHORT nNew = 0;
303 USHORT nSize = aEntryLst.Count();
304 for(USHORT i=0; i < nSize; ++i)
305 { if(aEntryLst[i]->bNew)
306 nNew++;
308 return nNew;
311 /*--------------------------------------------------------------------
312 Beschreibung: Alle neuen Eintraege ueberpruefen
313 --------------------------------------------------------------------*/
315 const SvxBoxEntry& SvxListBox::GetNewEntry(USHORT nPos) const
317 USHORT nSize = aEntryLst.Count();
318 USHORT nNew = 0;
319 for(USHORT i=0; i < nSize; ++i)
320 { if(aEntryLst[i]->bNew)
321 { if(nNew == nPos)
322 return *aEntryLst[i];
323 nNew++;
326 return aDefault;
329 /*--------------------------------------------------------------------
330 Beschreibung: Sortiert einfuegen
331 --------------------------------------------------------------------*/
333 void SvxListBox::InsertSorted(SvxBoxEntry* pEntry)
335 ListBox::InsertEntry(pEntry->aName);
336 USHORT nPos = ListBox::GetEntryPos(pEntry->aName);
337 aEntryLst.C40_INSERT(SvxBoxEntry, pEntry, nPos);
340 /*--------------------------------------------------------------------
341 Beschreibung: ComboBoxen mit Verwaltungseinheit
342 --------------------------------------------------------------------*/
344 SvxComboBox::SvxComboBox(Window* pParent, WinBits nBits, USHORT nStyleBits) :
345 ComboBox(pParent, nBits),
346 nStyle(nStyleBits)
348 InitComboBox();
352 SvxComboBox::SvxComboBox(Window* pParent, const ResId& rId, USHORT nStyleBits ):
353 ComboBox(pParent, rId),
354 nStyle(nStyleBits)
356 InitComboBox();
359 /*--------------------------------------------------------------------
360 Beschreibung: Basisklasse Dtor
361 --------------------------------------------------------------------*/
363 __EXPORT SvxComboBox::~SvxComboBox()
365 aEntryLst.DeleteAndDestroy(0, aEntryLst.Count());
366 aDelEntryLst.DeleteAndDestroy(0, aDelEntryLst.Count());
369 /*--------------------------------------------------------------------
370 Beschreibung: Evtl. Liste aus der Ressource beachten
371 --------------------------------------------------------------------*/
373 void SvxComboBox::InitComboBox()
375 // Verwaltung fuer die Stringlist aus der Resource aufbauen
376 USHORT nSize = GetEntryCount();
377 for(USHORT i=0; i < nSize; ++i)
378 { const SvxBoxEntry* pTmp = new SvxBoxEntry(ComboBox::GetEntry(i), i);
379 const SvxBoxEntry* &rpTmp = pTmp;
380 aEntryLst.Insert(rpTmp, aEntryLst.Count());
384 /*--------------------------------------------------------------------
385 Beschreibung: neue Eintraege verwalten
386 --------------------------------------------------------------------*/
388 void SvxComboBox::InsertNewEntry(const SvxBoxEntry& rEntry)
390 SvxBoxEntry* pNew = new SvxBoxEntry(rEntry);
391 pNew->bNew = TRUE;
392 InsertSorted(pNew);
395 /*--------------------------------------------------------------------
396 Beschreibung: Eintrag in die ComboBox aufnehmen
397 --------------------------------------------------------------------*/
399 void SvxComboBox::InsertEntry(const SvxBoxEntry& rEntry)
401 InsertSorted(new SvxBoxEntry(rEntry));
404 /*--------------------------------------------------------------------
405 Beschreibung: Eintrag aus der Liste loeschen
406 --------------------------------------------------------------------*/
408 void SvxComboBox::RemoveEntry(USHORT nPos)
410 if(nPos >= aEntryLst.Count())
411 return;
413 // Altes Element austragen
414 SvxBoxEntry* pEntry = aEntryLst[nPos];
415 aEntryLst.Remove(nPos, 1);
416 ComboBox::RemoveEntry(nPos);
418 // keine neuen Eintraege in die Liste mit aufnehmen
419 if(pEntry->bNew)
420 return;
422 // in DeleteListe eintragen
423 aDelEntryLst.C40_INSERT(SvxBoxEntry, pEntry, aDelEntryLst.Count());
426 /*--------------------------------------------------------------------
427 Beschreibung: Eintrag ueber konkretes Obkjekt loeschen
428 --------------------------------------------------------------------*/
430 void SvxComboBox::RemoveEntry(const SvxBoxEntry& rEntry)
432 USHORT nPos = ComboBox::GetEntryPos(rEntry.aName);
433 RemoveEntry(nPos);
436 /*--------------------------------------------------------------------
437 Beschreibung: Listen loeschen und Anzeige loeschen
438 --------------------------------------------------------------------*/
440 void SvxComboBox::Clear()
442 ComboBox::Clear();
443 aEntryLst.DeleteAndDestroy(0, aEntryLst.Count());
444 aDelEntryLst.DeleteAndDestroy(0, aDelEntryLst.Count());
448 /*--------------------------------------------------------------------
449 Beschreibung: Position by Name
450 --------------------------------------------------------------------*/
452 USHORT SvxComboBox::GetEntryPos(const SvxBoxEntry& rEntry) const
454 return ComboBox::GetEntryPos(rEntry.aName);
457 /*--------------------------------------------------------------------
458 Beschreibung: Rund um die Entries
459 --------------------------------------------------------------------*/
461 const SvxBoxEntry& SvxComboBox::GetEntry(USHORT nPos) const
463 if(nPos < aEntryLst.Count())
464 return *aEntryLst[nPos];
465 else
466 return aDefault;
469 /*--------------------------------------------------------------------
470 Beschreibung: modifizierte Eintraege
471 --------------------------------------------------------------------*/
473 USHORT SvxComboBox::GetModifiedCount() const
475 USHORT nMod = 0;
476 USHORT nSize = aEntryLst.Count();
477 for(USHORT i=0; i < nSize; ++i)
478 { if(aEntryLst[i]->bModified)
479 nMod++;
481 return nMod;
484 /*--------------------------------------------------------------------
485 Beschreibung: Modifizierte Eintraege behandeln
486 --------------------------------------------------------------------*/
488 void SvxComboBox::ModifyEntry(USHORT nPos, const String& rName)
490 if(nPos >= aEntryLst.Count())
491 return;
493 SvxBoxEntry* pEntry = aEntryLst[nPos];
494 aEntryLst.Remove(nPos, 1);
495 aEntryLst[nPos]->aName = rName;
496 aEntryLst[nPos]->bModified = TRUE;
497 ComboBox::RemoveEntry(nPos);
499 InsertSorted(pEntry);
502 /*--------------------------------------------------------------------
503 Beschreibung: alle modifizierten Eintraege bahandeln
504 --------------------------------------------------------------------*/
506 const SvxBoxEntry& SvxComboBox::GetModifiedEntry(USHORT nPos) const
508 USHORT nSize = aEntryLst.Count();
509 USHORT nMod = 0;
510 for(USHORT i=0; i < nSize; ++i)
511 { if(aEntryLst[i]->bModified)
512 { if(nMod == nPos)
513 return *aEntryLst[i];
514 nMod++;
517 return aDefault;
520 /*--------------------------------------------------------------------
521 Beschreibung: geloeschte Eintraege
522 --------------------------------------------------------------------*/
524 USHORT SvxComboBox::GetRemovedCount() const
526 return aDelEntryLst.Count();
530 const SvxBoxEntry& SvxComboBox::GetRemovedEntry(USHORT nPos) const
532 if(nPos < aDelEntryLst.Count())
533 return *aDelEntryLst[nPos];
535 return aDefault;
538 /*--------------------------------------------------------------------
539 Beschreibung: Neue Entries begutachten
540 --------------------------------------------------------------------*/
542 USHORT SvxComboBox::GetNewCount() const
544 USHORT nNew = 0;
545 USHORT nSize = aEntryLst.Count();
546 for(USHORT i=0; i < nSize; ++i)
547 { if(aEntryLst[i]->bNew)
548 nNew++;
550 return nNew;
553 /*--------------------------------------------------------------------
554 Beschreibung: Alle neuen Eintraege ueberpruefen
555 --------------------------------------------------------------------*/
557 const SvxBoxEntry& SvxComboBox::GetNewEntry(USHORT nPos) const
559 USHORT nSize = aEntryLst.Count();
560 USHORT nNew = 0;
561 for(USHORT i=0; i < nSize; ++i)
562 { if(aEntryLst[i]->bNew)
563 { if(nNew == nPos)
564 return *aEntryLst[i];
565 nNew++;
568 return aDefault;
571 /*--------------------------------------------------------------------
572 Beschreibung: Sortiert einfuegen
573 --------------------------------------------------------------------*/
575 void SvxComboBox::InsertSorted(SvxBoxEntry* pEntry)
577 ComboBox::InsertEntry(pEntry->aName);
578 USHORT nPos = ComboBox::GetEntryPos(pEntry->aName);
579 aEntryLst.C40_INSERT(SvxBoxEntry, pEntry, nPos);
583 /*--------------------------------------------------------------------
584 Beschreibung: Je nach Option bestimmte Zeichen ausblenden
585 --------------------------------------------------------------------*/
587 void __EXPORT SvxComboBox::KeyInput( const KeyEvent& rKEvt )
589 sal_Unicode cChar = rKEvt.GetCharCode();
591 if(nStyle & SVX_CBS_FILENAME)
593 #if defined UNX
594 if( cChar == sal_Unicode( '/' ) || cChar == sal_Unicode( ' ' ) )
595 return;
596 #else
597 if( cChar == sal_Unicode( ':' ) || cChar == sal_Unicode( '\\' ) ||
598 cChar == sal_Unicode( '.' ) || cChar == sal_Unicode( ' ' ) )
599 return;
600 #endif
602 ComboBox::KeyInput(rKEvt);
605 /*--------------------------------------------------------------------
606 Beschreibung: Text nach Option konvertieren
607 --------------------------------------------------------------------*/
609 String SvxComboBox::GetText() const
611 String aTxt(ComboBox::GetText());
612 CharClass aCharClass( Application::GetSettings().GetLocale() );
614 if(nStyle & SVX_CBS_LOWER)
615 return aCharClass.lower(aTxt);
617 if(nStyle & SVX_CBS_UPPER)
618 return aCharClass.upper(aTxt);
620 return aTxt;