1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
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 .
20 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Listbox" script:
language=
"StarBasic">Option Explicit
22 Dim oDialogModel as Object
25 Sub MergeList(SourceListBox() as Object, SecondList() as String)
27 Dim MaxIndex as Integer
28 MaxIndex = Ubound(SecondList())
29 OriginalList() = AddListToList(OriginalList(), SecondList())
31 SourceListbox = AddSingleItemToListbox(SourceListbox, SecondList(i))
33 Call FormSetMoveRights()
37 Sub RemoveListItems(SourceListbox as Object, TargetListbox as Object, RemoveList() as String)
40 Dim MaxIndex as Integer
42 MaxIndex = Ubound(RemoveList())
44 RemoveListboxItemByName(SourceListbox, RemoveList(i))
45 RemoveListboxItemByName(TargetListbox, RemoveList(i))
47 CopyList() = OriginalList()
49 MaxIndex = Ubound(CopyList())
51 If IndexInArray(CopyList(i),RemoveList())= -
1 Then
52 OriginalList(s) = CopyList(i)
56 ReDim Preserve OriginalList(s-
1)
57 Call FormSetMoveRights()
61 ' Note Boolean Parameter
62 Sub InitializeListboxProcedures(oModel as Object, SourceListbox as Object, TargetListbox as Object)
64 Set oDialogModel = oModel
65 OriginalList()= SourceListbox.StringItemList()
66 TargetListbox.StringItemList() = EmptyList()
70 Sub CopyListboxItems(SourceListbox as Object, TargetListbox As Object)
72 TargetListbox.StringItemList() = OriginalList()
73 SourceListbox.StringItemList() = NullArray()
77 Sub FormMoveSelected()
78 Call MoveSelectedListBox(oDialogModel.lstFields, oDialogModel.lstSelFields)
79 Call FormSetMoveRights()
80 oDialogModel.lstSelFields.Tag = True
85 Call CopyListboxItems(oDialogModel.lstFields, oDialogModel.lstSelFields)
86 Call FormSetMoveRights()
87 oDialogModel.lstSelFields.Tag = True
91 Sub FormRemoveSelected()
92 Call MoveOrderedSelectedListbox(oDialogModel.lstFields, oDialogModel.lstSelFields, False)
93 Call FormSetMoveRights()
94 oDialogModel.lstSelFields.Tag = True
99 Call MoveOrderedSelectedListbox(oDialogModel.lstFields, oDialogModel.lstSelFields, True)
100 Call FormSetMoveRights()
101 oDialogModel.lstSelFields.Tag =
1
105 Sub MoveSelectedListBox(SourceListbox as Object, TargetListbox as Object)
106 Dim MaxCurTarget as Integer
107 Dim MaxSourceSelected as Integer
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
> -
1 Then
117 iOldSourceSelect = SourceListbox.SelectedItems(
0)
118 If Ubound(TargetListbox.SelectedItems())
> -
1 Then
119 iOldTargetSelect = TargetListbox.SelectedItems(
0)
121 iOldTargetSelect = -
1
123 For n =
0 To MaxCurTarget
124 TargetList(n) = TargetListbox.StringItemList(n)
126 For m =
0 To MaxSourceSelected
127 CurIndex = SourceListbox.SelectedItems(m)
128 TargetList(n) = SourceListbox.StringItemList(CurIndex)
131 TargetListBox.StringItemList() = TargetList()
132 SourceListbox.StringItemList() = RemoveSelected (SourceListbox)
133 SetNewSelection(SourceListbox, iOldSourceSelect)
134 SetNewSelection(TargetListbox, iOldTargetSelect)
140 Sub MoveOrderedSelectedListbox(lstSource as Object, lstTarget as Object, bMoveAll as Boolean)
142 Dim MaxSelected as Integer
143 Dim MaxSourceIndex as Integer
144 Dim MaxOriginalIndex as Integer
145 Dim MaxNewIndex 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
154 lstSource.StringItemList() = OriginalList()
155 lstTarget.StringItemList() = NullArray()
157 MaxOriginalIndex = Ubound(OriginalList())
158 MaxSelected = Ubound(lstTarget.SelectedItems())
159 iOldTargetSelect = lstTarget.SelectedItems(
0)
160 If Ubound(lstSource.SelectedItems())
> -
1 Then
161 iOldSourceSelect = lstSource.SelectedItems(
0)
163 Dim SelList(MaxSelected)
164 For n =
0 To MaxSelected
165 CurIndex = lstTarget.SelectedItems(n)
166 SelList(n) = lstTarget.StringItemList(CurIndex)
168 SourceList() = lstSource.StringItemList()
169 MaxSourceIndex = Ubound(lstSource.StringItemList())
170 MaxNewIndex = MaxSelected + MaxSourceIndex +
1
171 Dim NewSourceList(MaxNewIndex)
173 For n =
0 To MaxOriginalIndex
174 SearchString = OriginalList(n)
175 If IndexInArray(SearchString, SelList())
<> -
1 Then
176 NewSourceList(m) = SearchString
178 ElseIf IndexInArray(SearchString, SourceList())
<> -
1 Then
179 NewSourceList(m) = SearchString
183 lstSource.StringItemList() = NewSourceList()
184 lstTarget.StringItemList() = RemoveSelected(lstTarget)
186 SetNewSelection(lstSource, iOldSourceSelect)
187 SetNewSelection(lstTarget, iOldTargetSelect)
192 Function RemoveSelected(oListbox as Object)
193 Dim MaxIndex as Integer
194 Dim MaxSelected as Integer
197 Dim CurIndex as Integer
198 Dim CurItem as String
200 MaxIndex = Ubound(oListbox.StringItemList())
201 MaxSelected = Ubound(oListbox.SelectedItems())
202 Dim LocItemList(MaxIndex)
203 LocItemList() = oListbox.StringItemList()
204 If MaxSelected
> -
1 Then
205 For n =
0 To MaxSelected
206 CurIndex = oListbox.SelectedItems(n)
207 LocItemList(CurIndex) =
""
209 If MaxIndex
> 0 Then
210 ReDim ResultArray(MaxIndex - MaxSelected -
1)
212 For n =
0 To MaxIndex
213 CurItem = LocItemList(n)
214 If CurItem
<> "" Then
215 ResultArray(m) = CurItem
220 RemoveSelected = ResultArray()
222 RemoveSelected = oListbox.StringItemList()
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
> -
1 AND iLastSelection
> -
1 Then
233 If iLastSelection
> MaxIndex Then
236 SelIndex = iLastSelection
238 Sellist(
0) = SelIndex
239 oListBox.SelectedItems() = SelList()
244 Sub ToggleListboxControls(oDialogModel as Object, bDoEnable as Boolean)
246 .lblFields.Enabled = bDoEnable
247 .lblSelFields.Enabled = bDoEnable
248 ' .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
262 ' Enable or disable the buttons used for moving the available
263 ' 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())
<> -
1
270 FieldCount = Ubound(oDialogModel.lstFields.StringItemList()) +
1
271 bSelectSelected = Ubound(oDialogModel.lstSelFields.SelectedItems())
> -
1
272 SelectCount = Ubound(oDialogModel.lstSelFields.StringItemList()) +
1
273 oDialogModel.cmdRemoveAll.Enabled = SelectCount
>=
1
274 oDialogModel.cmdRemoveSelected.Enabled = bSelectSelected
275 oDialogModel.cmdMoveAll.Enabled = FieldCount
>=
1
276 oDialogModel.cmdMoveSelected.Enabled = bIsFieldSelected
277 oDialogModel.cmdGoOn.Enabled = SelectCount
>=
1
278 ' This flag is set to
'1' when the lstSelFields has been modified
282 Function AddSingleItemToListbox(ByVal oListbox as Object, ListItem as String, Optional iSelIndex) as Object
283 Dim MaxIndex as Integer
286 MaxIndex = Ubound(oListbox.StringItemList())
287 Dim LocList(MaxIndex +
1)
288 ' Todo: This goes faster with the Redim LocList(MaxIndex +
1) Preserve function
289 For i =
0 To MaxIndex
290 LocList(i) = oListbox.StringItemList(i)
292 LocList(MaxIndex +
1) = ListItem
293 oListbox.StringItemList() = LocList()
294 If Not IsMissing(iSelIndex) Then
295 SelectListboxItem(oListbox, iSelIndex)
297 AddSingleItemToListbox() = oListbox
301 Sub EmptyListbox(oListbox as Object)
302 Dim NullList() as String
303 oListbox.StringItemList() = NullList()
307 Sub SelectListboxItem(oListbox as Object, iSelIndex as Integer)
308 Dim LocSelList(
0) as Integer
309 If iSelIndex
<> -
1 Then
310 LocSelList(
0) = iSelIndex
311 oListbox.SelectedItems() = LocSelList()
316 Function GetSelectedListboxItems(oListbox as Object)
317 Dim SelList(Ubound(oListBox.SelectedItems())) as String
319 Dim CurIndex as Integer
320 For i =
0 To Ubound(oListbox.SelectedItems())
321 CurIndex = oListbox.SelectedItems(i)
322 SelList(i) = oListbox.StringItemList(CurIndex)
324 GetSelectedListboxItems() = SelList()
328 ' Note: When using this Sub it must be ensured that the
329 ' 'RemoveItem
' 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
335 Dim MaxIndex as Integer
336 OldList = oListbox.StringItemList()
337 MaxIndex = Ubound(OldList())
338 If IndexInArray(RemoveItem, OldList())
<> -
1 Then
339 If MaxIndex
> 0 Then
341 Dim NewList(MaxIndex -
1)
342 For i =
0 To MaxIndex
343 If RemoveItem
<> OldList(i) Then
344 NewList(a) = OldList(i)
348 oListbox.StringItemList() = NewList()
350 oListBox.StringItemList() = NullList()
356 Function GetItemPos(oListBox as Object, sItem as String)
358 Dim MaxIndex as Integer
360 ItemList() = oListBox.StringItemList()
361 MaxIndex = Ubound(ItemList())
362 For i =
0 To MaxIndex
363 If sItem = ItemList(i) Then