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