tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / wizards / source / tools / Listbox.xba
blob21f8f44c6175d6c5b225a4d4c23adaed58677790
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <!--
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 -->
20 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Listbox" script:language="StarBasic">Option Explicit
21 Dim OriginalList()
22 Dim oDialogModel as Object
25 Sub MergeList(SourceListBox() as Object, SecondList() as String)
26 Dim i as Integer
27 Dim MaxIndex as Integer
28 MaxIndex = Ubound(SecondList())
29 OriginalList() = AddListToList(OriginalList(), SecondList())
30 For i = 0 To MaxIndex
31 SourceListbox = AddSingleItemToListbox(SourceListbox, SecondList(i))
32 Next i
33 Call FormSetMoveRights()
34 End Sub
37 Sub RemoveListItems(SourceListbox as Object, TargetListbox as Object, RemoveList() as String)
38 Dim i as Integer
39 Dim s as Integer
40 Dim MaxIndex as Integer
41 Dim CopyList()
42 MaxIndex = Ubound(RemoveList())
43 For i = 0 To MaxIndex
44 RemoveListboxItemByName(SourceListbox, RemoveList(i))
45 RemoveListboxItemByName(TargetListbox, RemoveList(i))
46 Next i
47 CopyList() = OriginalList()
48 s = 0
49 MaxIndex = Ubound(CopyList())
50 For i = 0 To MaxIndex
51 If IndexInArray(CopyList(i),RemoveList())= -1 Then
52 OriginalList(s) = CopyList(i)
53 s = s + 1
54 End If
55 Next i
56 ReDim Preserve OriginalList(s-1)
57 Call FormSetMoveRights()
58 End Sub
61 &apos; Note Boolean Parameter
62 Sub InitializeListboxProcedures(oModel as Object, SourceListbox as Object, TargetListbox as Object)
63 Dim EmptyList()
64 Set oDialogModel = oModel
65 OriginalList()= SourceListbox.StringItemList()
66 TargetListbox.StringItemList() = EmptyList()
67 End Sub
70 Sub CopyListboxItems(SourceListbox as Object, TargetListbox As Object)
71 Dim NullArray()
72 TargetListbox.StringItemList() = OriginalList()
73 SourceListbox.StringItemList() = NullArray()
74 End Sub
77 Sub FormMoveSelected()
78 Call MoveSelectedListBox(oDialogModel.lstFields, oDialogModel.lstSelFields)
79 Call FormSetMoveRights()
80 oDialogModel.lstSelFields.Tag = True
81 End Sub
84 Sub FormMoveAll()
85 Call CopyListboxItems(oDialogModel.lstFields, oDialogModel.lstSelFields)
86 Call FormSetMoveRights()
87 oDialogModel.lstSelFields.Tag = True
88 End Sub
91 Sub FormRemoveSelected()
92 Call MoveOrderedSelectedListbox(oDialogModel.lstFields, oDialogModel.lstSelFields, False)
93 Call FormSetMoveRights()
94 oDialogModel.lstSelFields.Tag = True
95 End Sub
98 Sub FormRemoveAll()
99 Call MoveOrderedSelectedListbox(oDialogModel.lstFields, oDialogModel.lstSelFields, True)
100 Call FormSetMoveRights()
101 oDialogModel.lstSelFields.Tag = 1
102 End Sub
105 Sub MoveSelectedListBox(SourceListbox as Object, TargetListbox as Object)
106 Dim MaxCurTarget as Integer
107 Dim MaxSourceSelected as Integer
108 Dim n as Integer
109 Dim m as Integer
110 Dim CurIndex
111 Dim iOldTargetSelect as Integer
112 Dim iOldSourceSelect as Integer
113 MaxCurTarget = Ubound(TargetListbox.StringItemList())
114 MaxSourceSelected = Ubound(SourceListbox.SelectedItems())
115 Dim TargetList(MaxCurTarget+MaxSourceSelected+1)
116 If MaxSourceSelected &gt; -1 Then
117 iOldSourceSelect = SourceListbox.SelectedItems(0)
118 If Ubound(TargetListbox.SelectedItems()) &gt; -1 Then
119 iOldTargetSelect = TargetListbox.SelectedItems(0)
120 Else
121 iOldTargetSelect = -1
122 End If
123 For n = 0 To MaxCurTarget
124 TargetList(n) = TargetListbox.StringItemList(n)
125 Next n
126 For m = 0 To MaxSourceSelected
127 CurIndex = SourceListbox.SelectedItems(m)
128 TargetList(n) = SourceListbox.StringItemList(CurIndex)
129 n = n + 1
130 Next m
131 TargetListBox.StringItemList() = TargetList()
132 SourceListbox.StringItemList() = RemoveSelected (SourceListbox)
133 SetNewSelection(SourceListbox, iOldSourceSelect)
134 SetNewSelection(TargetListbox, iOldTargetSelect)
135 End If
136 End Sub
140 Sub MoveOrderedSelectedListbox(lstSource as Object, lstTarget as Object, bMoveAll as Boolean)
141 Dim NullArray()
142 Dim MaxSelected as Integer
143 Dim MaxSourceIndex as Integer
144 Dim MaxOriginalIndex as Integer
145 Dim MaxNewIndex as Integer
146 Dim n as Integer
147 Dim m as Integer
148 Dim CurIndex as Integer
149 Dim SearchString as String
150 Dim SourceList() as String
151 Dim iOldTargetSelect as Integer
152 Dim iOldSourceSelect as Integer
153 If bMoveAll Then
154 lstSource.StringItemList() = OriginalList()
155 lstTarget.StringItemList() = NullArray()
156 Else
157 MaxOriginalIndex = Ubound(OriginalList())
158 MaxSelected = Ubound(lstTarget.SelectedItems())
159 iOldTargetSelect = lstTarget.SelectedItems(0)
160 If Ubound(lstSource.SelectedItems()) &gt; -1 Then
161 iOldSourceSelect = lstSource.SelectedItems(0)
162 End If
163 Dim SelList(MaxSelected)
164 For n = 0 To MaxSelected
165 CurIndex = lstTarget.SelectedItems(n)
166 SelList(n) = lstTarget.StringItemList(CurIndex)
167 Next n
168 SourceList() = lstSource.StringItemList()
169 MaxSourceIndex = Ubound(lstSource.StringItemList())
170 MaxNewIndex = MaxSelected + MaxSourceIndex + 1
171 Dim NewSourceList(MaxNewIndex)
172 m = 0
173 For n = 0 To MaxOriginalIndex
174 SearchString = OriginalList(n)
175 If IndexInArray(SearchString, SelList()) &lt;&gt; -1 Then
176 NewSourceList(m) = SearchString
177 m = m + 1
178 ElseIf IndexInArray(SearchString, SourceList()) &lt;&gt; -1 Then
179 NewSourceList(m) = SearchString
180 m = m + 1
181 End If
182 Next n
183 lstSource.StringItemList() = NewSourceList()
184 lstTarget.StringItemList() = RemoveSelected(lstTarget)
185 End If
186 SetNewSelection(lstSource, iOldSourceSelect)
187 SetNewSelection(lstTarget, iOldTargetSelect)
189 End Sub
192 Function RemoveSelected(oListbox as Object)
193 Dim MaxIndex as Integer
194 Dim MaxSelected as Integer
195 Dim n as Integer
196 Dim m as Integer
197 Dim CurIndex as Integer
198 Dim CurItem as String
199 Dim ResultArray()
200 MaxIndex = Ubound(oListbox.StringItemList())
201 MaxSelected = Ubound(oListbox.SelectedItems())
202 Dim LocItemList(MaxIndex)
203 LocItemList() = oListbox.StringItemList()
204 If MaxSelected &gt; -1 Then
205 For n = 0 To MaxSelected
206 CurIndex = oListbox.SelectedItems(n)
207 LocItemList(CurIndex) = &quot;&quot;
208 Next n
209 If MaxIndex &gt; 0 Then
210 ReDim ResultArray(MaxIndex - MaxSelected - 1)
211 m = 0
212 For n = 0 To MaxIndex
213 CurItem = LocItemList(n)
214 If CurItem &lt;&gt; &quot;&quot; Then
215 ResultArray(m) = CurItem
216 m = m + 1
217 End If
218 Next n
219 End If
220 RemoveSelected = ResultArray()
221 Else
222 RemoveSelected = oListbox.StringItemList()
223 End If
224 End Function
227 Sub SetNewSelection(oListBox as Object, iLastSelection as Integer)
228 Dim MaxIndex as Integer
229 Dim SelIndex as Integer
230 Dim SelList(0) as Integer
231 MaxIndex = Ubound(oListBox.StringItemList())
232 If MaxIndex &gt; -1 AND iLastSelection &gt; -1 Then
233 If iLastSelection &gt; MaxIndex Then
234 Selindex = MaxIndex
235 Else
236 SelIndex = iLastSelection
237 End If
238 Sellist(0) = SelIndex
239 oListBox.SelectedItems() = SelList()
240 End If
241 End Sub
244 Sub ToggleListboxControls(oDialogModel as Object, bDoEnable as Boolean)
245 With oDialogModel
246 .lblFields.Enabled = bDoEnable
247 .lblSelFields.Enabled = bDoEnable
248 &apos; .lstTables.Enabled = bDoEnable
249 .lstFields.Enabled = bDoEnable
250 .lstSelFields.Enabled = bDoEnable
251 .cmdRemoveAll.Enabled = bDoEnable
252 .cmdRemoveSelected.Enabled = bDoEnable
253 .cmdMoveAll.Enabled = bDoEnable
254 .cmdMoveSelected.Enabled = bDoEnable
255 End With
256 If bDoEnable Then
257 FormSetMoveRights()
258 End If
259 End Sub
262 &apos; Enable or disable the buttons used for moving the available
263 &apos; fields between the two list boxes.
264 Sub FormSetMoveRights()
265 Dim bIsFieldSelected as Boolean
266 Dim bSelectSelected as Boolean
267 Dim FieldCount as Integer
268 Dim SelectCount as Integer
269 bIsFieldSelected = Ubound(oDialogModel.lstFields.SelectedItems()) &lt;&gt; -1
270 FieldCount = Ubound(oDialogModel.lstFields.StringItemList()) + 1
271 bSelectSelected = Ubound(oDialogModel.lstSelFields.SelectedItems()) &gt; -1
272 SelectCount = Ubound(oDialogModel.lstSelFields.StringItemList()) + 1
273 oDialogModel.cmdRemoveAll.Enabled = SelectCount&gt;=1
274 oDialogModel.cmdRemoveSelected.Enabled = bSelectSelected
275 oDialogModel.cmdMoveAll.Enabled = FieldCount &gt;=1
276 oDialogModel.cmdMoveSelected.Enabled = bIsFieldSelected
277 oDialogModel.cmdGoOn.Enabled = SelectCount&gt;=1
278 &apos; This flag is set to &apos;1&apos; when the lstSelFields has been modified
279 End Sub
282 Function AddSingleItemToListbox(ByVal oListbox as Object, ListItem as String, Optional iSelIndex) as Object
283 Dim MaxIndex as Integer
284 Dim i as Integer
286 MaxIndex = Ubound(oListbox.StringItemList())
287 Dim LocList(MaxIndex + 1)
288 &apos; Todo: This goes faster with the Redim LocList(MaxIndex + 1) Preserve function
289 For i = 0 To MaxIndex
290 LocList(i) = oListbox.StringItemList(i)
291 Next i
292 LocList(MaxIndex + 1) = ListItem
293 oListbox.StringItemList() = LocList()
294 If Not IsMissing(iSelIndex) Then
295 SelectListboxItem(oListbox, iSelIndex)
296 End If
297 AddSingleItemToListbox() = oListbox
298 End Function
301 Sub EmptyListbox(oListbox as Object)
302 Dim NullList() as String
303 oListbox.StringItemList() = NullList()
304 End Sub
307 Sub SelectListboxItem(oListbox as Object, iSelIndex as Integer)
308 Dim LocSelList(0) as Integer
309 If iSelIndex &lt;&gt; -1 Then
310 LocSelList(0) = iSelIndex
311 oListbox.SelectedItems() = LocSelList()
312 End If
313 End Sub
316 Function GetSelectedListboxItems(oListbox as Object)
317 Dim SelList(Ubound(oListBox.SelectedItems())) as String
318 Dim i as Integer
319 Dim CurIndex as Integer
320 For i = 0 To Ubound(oListbox.SelectedItems())
321 CurIndex = oListbox.SelectedItems(i)
322 SelList(i) = oListbox.StringItemList(CurIndex)
323 Next i
324 GetSelectedListboxItems() = SelList()
325 End Function
328 &apos; Note: When using this Sub it must be ensured that the
329 &apos; &apos;RemoveItem&apos; appears only once in the Listbox
330 Sub RemoveListboxItemByName(oListbox as Object, RemoveItem as String)
331 Dim OldList() as String
332 Dim NullList() as String
333 Dim i as Integer
334 Dim a as Integer
335 Dim MaxIndex as Integer
336 OldList = oListbox.StringItemList()
337 MaxIndex = Ubound(OldList())
338 If IndexInArray(RemoveItem, OldList()) &lt;&gt; -1 Then
339 If MaxIndex &gt; 0 Then
340 a = 0
341 Dim NewList(MaxIndex -1)
342 For i = 0 To MaxIndex
343 If RemoveItem &lt;&gt; OldList(i) Then
344 NewList(a) = OldList(i)
345 a = a + 1
346 End If
347 Next i
348 oListbox.StringItemList() = NewList()
349 Else
350 oListBox.StringItemList() = NullList()
351 End If
352 End If
353 End Sub
356 Function GetItemPos(oListBox as Object, sItem as String)
357 Dim ItemList()
358 Dim MaxIndex as Integer
359 Dim i as Integer
360 ItemList() = oListBox.StringItemList()
361 MaxIndex = Ubound(ItemList())
362 For i = 0 To MaxIndex
363 If sItem = ItemList(i) Then
364 GetItemPos() = i
365 Exit Function
366 End If
367 Next i
368 GetItemPos() = -1
369 End Function
370 </script:module>