1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svxbox.cxx,v $
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>
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
),
57 SvxBoxEntry::SvxBoxEntry(const String
& aNam
, USHORT nIdx
) :
66 SvxBoxEntry::SvxBoxEntry(const SvxBoxEntry
& rOld
) :
69 bModified(rOld
.bModified
),
74 /*--------------------------------------------------------------------
76 --------------------------------------------------------------------*/
78 SvxListBox::SvxListBox(Window
* pParent
, WinBits nBits
) :
79 ListBox(pParent
, nBits
)
85 SvxListBox::SvxListBox(Window
* pParent
, const ResId
& rId
):
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
);
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
);
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())
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
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
);
176 /*--------------------------------------------------------------------
177 Beschreibung: Listen loeschen und Anzeige loeschen
178 --------------------------------------------------------------------*/
180 void SvxListBox::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
];
208 /*--------------------------------------------------------------------
209 Beschreibung: aktullen Eintrag zurueckgeben
210 --------------------------------------------------------------------*/
212 const SvxBoxEntry
& SvxListBox::GetSelectSvxBoxEntry(USHORT nSelId
) const
214 String
aName(ListBox::GetSelectEntry(nSelId
));
218 for (USHORT i
=0; i
< aEntryLst
.Count(); i
++)
220 if(aEntryLst
[i
]->aName
== aName
)
221 return *aEntryLst
[i
];
227 /*--------------------------------------------------------------------
228 Beschreibung: modifizierte Eintraege
229 --------------------------------------------------------------------*/
231 USHORT
SvxListBox::GetModifiedCount() const
234 USHORT nSize
= aEntryLst
.Count();
235 for(USHORT i
=0; i
< nSize
; ++i
)
236 { if(aEntryLst
[i
]->bModified
)
242 /*--------------------------------------------------------------------
243 Beschreibung: Modifizierte Eintraege behandeln
244 --------------------------------------------------------------------*/
246 void SvxListBox::ModifyEntry(USHORT nPos
, const String
& rName
)
248 if(nPos
>= aEntryLst
.Count())
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();
268 for(USHORT i
=0; i
< nSize
; ++i
)
269 { if(aEntryLst
[i
]->bModified
)
271 return *aEntryLst
[i
];
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
];
296 /*--------------------------------------------------------------------
297 Beschreibung: Neue Entries begutachten
298 --------------------------------------------------------------------*/
300 USHORT
SvxListBox::GetNewCount() const
303 USHORT nSize
= aEntryLst
.Count();
304 for(USHORT i
=0; i
< nSize
; ++i
)
305 { if(aEntryLst
[i
]->bNew
)
311 /*--------------------------------------------------------------------
312 Beschreibung: Alle neuen Eintraege ueberpruefen
313 --------------------------------------------------------------------*/
315 const SvxBoxEntry
& SvxListBox::GetNewEntry(USHORT nPos
) const
317 USHORT nSize
= aEntryLst
.Count();
319 for(USHORT i
=0; i
< nSize
; ++i
)
320 { if(aEntryLst
[i
]->bNew
)
322 return *aEntryLst
[i
];
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
),
352 SvxComboBox::SvxComboBox(Window
* pParent
, const ResId
& rId
, USHORT nStyleBits
):
353 ComboBox(pParent
, rId
),
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
);
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())
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
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
);
436 /*--------------------------------------------------------------------
437 Beschreibung: Listen loeschen und Anzeige loeschen
438 --------------------------------------------------------------------*/
440 void SvxComboBox::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
];
469 /*--------------------------------------------------------------------
470 Beschreibung: modifizierte Eintraege
471 --------------------------------------------------------------------*/
473 USHORT
SvxComboBox::GetModifiedCount() const
476 USHORT nSize
= aEntryLst
.Count();
477 for(USHORT i
=0; i
< nSize
; ++i
)
478 { if(aEntryLst
[i
]->bModified
)
484 /*--------------------------------------------------------------------
485 Beschreibung: Modifizierte Eintraege behandeln
486 --------------------------------------------------------------------*/
488 void SvxComboBox::ModifyEntry(USHORT nPos
, const String
& rName
)
490 if(nPos
>= aEntryLst
.Count())
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();
510 for(USHORT i
=0; i
< nSize
; ++i
)
511 { if(aEntryLst
[i
]->bModified
)
513 return *aEntryLst
[i
];
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
];
538 /*--------------------------------------------------------------------
539 Beschreibung: Neue Entries begutachten
540 --------------------------------------------------------------------*/
542 USHORT
SvxComboBox::GetNewCount() const
545 USHORT nSize
= aEntryLst
.Count();
546 for(USHORT i
=0; i
< nSize
; ++i
)
547 { if(aEntryLst
[i
]->bNew
)
553 /*--------------------------------------------------------------------
554 Beschreibung: Alle neuen Eintraege ueberpruefen
555 --------------------------------------------------------------------*/
557 const SvxBoxEntry
& SvxComboBox::GetNewEntry(USHORT nPos
) const
559 USHORT nSize
= aEntryLst
.Count();
561 for(USHORT i
=0; i
< nSize
; ++i
)
562 { if(aEntryLst
[i
]->bNew
)
564 return *aEntryLst
[i
];
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
)
594 if( cChar
== sal_Unicode( '/' ) || cChar
== sal_Unicode( ' ' ) )
597 if( cChar
== sal_Unicode( ':' ) || cChar
== sal_Unicode( '\\' ) ||
598 cChar
== sal_Unicode( '.' ) || cChar
== sal_Unicode( ' ' ) )
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
);