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_sw.hxx" 26 27 28 #include <tools/debug.hxx> 29 #include <unotools/charclass.hxx> 30 #include <swtypes.hxx> 31 #include <swlbox.hxx> 32 33 using namespace nsSwComboBoxStyle; 34 35 36 SV_IMPL_PTRARR(SwEntryLst, SwBoxEntry*) 37 38 /*-------------------------------------------------------------------- 39 Beschreibung: Ein ListboxElement 40 --------------------------------------------------------------------*/ 41 42 43 SwBoxEntry::SwBoxEntry() : 44 bModified(sal_False), 45 bNew(sal_False), 46 nId(LISTBOX_APPEND) 47 { 48 } 49 50 51 SwBoxEntry::SwBoxEntry(const String& aNam, sal_uInt16 nIdx) : 52 bModified(sal_False), 53 bNew(sal_False), 54 aName(aNam), 55 nId(nIdx) 56 { 57 } 58 59 60 SwBoxEntry::SwBoxEntry(const SwBoxEntry& rOld) : 61 bModified(rOld.bModified), 62 bNew(rOld.bNew), 63 aName(rOld.aName), 64 nId(rOld.nId) 65 { 66 67 } 68 69 70 71 SwComboBox::SwComboBox(Window* pParent, const ResId& rId, sal_uInt16 nStyleBits ): 72 ComboBox(pParent, rId), 73 nStyle(nStyleBits) 74 { 75 // Verwaltung fuer die Stringlist aus der Resource aufbauen 76 sal_uInt16 nSize = GetEntryCount(); 77 for( sal_uInt16 i=0; i < nSize; ++i ) 78 { 79 const SwBoxEntry* pTmp = new SwBoxEntry(ComboBox::GetEntry(i), i); 80 aEntryLst.Insert(pTmp, aEntryLst.Count() ); 81 } 82 } 83 84 /*-------------------------------------------------------------------- 85 Beschreibung: Basisklasse Dtor 86 --------------------------------------------------------------------*/ 87 88 89 SwComboBox::~SwComboBox() 90 { 91 // das erledigen die Listen doch schon selbst im DTOR! 92 // aEntryLst.DeleteAndDestroy(0, aEntryLst.Count()); 93 // aDelEntryLst.DeleteAndDestroy(0, aDelEntryLst.Count()); 94 } 95 96 /*-------------------------------------------------------------------- 97 Beschreibung: Eintrag in die ComboBox aufnehmen 98 --------------------------------------------------------------------*/ 99 100 101 void SwComboBox::InsertEntry(const SwBoxEntry& rEntry) 102 { 103 InsertSorted(new SwBoxEntry(rEntry)); 104 } 105 106 /*-------------------------------------------------------------------- 107 Beschreibung: Eintrag aus der Liste loeschen 108 --------------------------------------------------------------------*/ 109 110 111 void SwComboBox::RemoveEntry(sal_uInt16 nPos) 112 { 113 if(nPos >= aEntryLst.Count()) 114 return; 115 116 // Altes Element austragen 117 SwBoxEntry* pEntry = aEntryLst[nPos]; 118 aEntryLst.Remove(nPos, 1); 119 ComboBox::RemoveEntry(nPos); 120 121 // keine neuen Eintraege in die Liste mit aufnehmen 122 if(pEntry->bNew) 123 return; 124 125 // in DeleteListe eintragen 126 aDelEntryLst.C40_INSERT(SwBoxEntry, pEntry, aDelEntryLst.Count()); 127 } 128 129 130 131 /*-------------------------------------------------------------------- 132 Beschreibung: Position by Name 133 --------------------------------------------------------------------*/ 134 135 sal_uInt16 SwComboBox::GetEntryPos(const SwBoxEntry& rEntry) const 136 { 137 return ComboBox::GetEntryPos(rEntry.aName); 138 } 139 140 /*-------------------------------------------------------------------- 141 Beschreibung: Rund um die Entries 142 --------------------------------------------------------------------*/ 143 144 145 const SwBoxEntry& SwComboBox::GetEntry(sal_uInt16 nPos) const 146 { 147 if(nPos < aEntryLst.Count()) 148 return *aEntryLst[nPos]; 149 150 return aDefault; 151 } 152 153 /*-------------------------------------------------------------------- 154 Beschreibung: geloeschte Eintraege 155 --------------------------------------------------------------------*/ 156 157 158 sal_uInt16 SwComboBox::GetRemovedCount() const 159 { 160 return aDelEntryLst.Count(); 161 } 162 163 164 const SwBoxEntry& SwComboBox::GetRemovedEntry(sal_uInt16 nPos) const 165 { 166 if(nPos < aDelEntryLst.Count()) 167 return *aDelEntryLst[nPos]; 168 169 return aDefault; 170 } 171 172 /*-------------------------------------------------------------------- 173 Beschreibung: Sortiert einfuegen 174 --------------------------------------------------------------------*/ 175 176 177 void SwComboBox::InsertSorted(SwBoxEntry* pEntry) 178 { 179 ComboBox::InsertEntry(pEntry->aName); 180 sal_uInt16 nPos = ComboBox::GetEntryPos(pEntry->aName); 181 aEntryLst.C40_INSERT(SwBoxEntry, pEntry, nPos); 182 } 183 184 185 /*-------------------------------------------------------------------- 186 Beschreibung: Je nach Option bestimmte Zeichen ausblenden 187 --------------------------------------------------------------------*/ 188 189 190 void SwComboBox::KeyInput( const KeyEvent& rKEvt ) 191 { 192 sal_uInt16 nChar = rKEvt.GetCharCode(); 193 194 if(nStyle & CBS_FILENAME) 195 { 196 #if defined UNX 197 if(nChar == '/' || nChar == ' ' ) 198 return; 199 #else 200 if(nChar == ':' || nChar == '\\' || nChar == '.' || nChar == ' ') 201 return; 202 #endif 203 } 204 ComboBox::KeyInput(rKEvt); 205 } 206 207 208 209 /*-------------------------------------------------------------------- 210 Beschreibung: Text nach Option konvertieren 211 --------------------------------------------------------------------*/ 212 213 214 String SwComboBox::GetText() const 215 { 216 String aTxt( ComboBox::GetText() ); 217 218 if(nStyle & CBS_LOWER) 219 GetAppCharClass().toLower( aTxt ); 220 else if( nStyle & CBS_UPPER ) 221 GetAppCharClass().toUpper( aTxt ); 222 223 return aTxt; 224 } 225 226 227 228