1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"Listbox" script:
language=
"StarBasic">Option Explicit
5 Dim oDialogModel as Object
8 Sub MergeList(SourceListBox() as Object, SecondList() as String)
10 Dim MaxIndex as Integer
11 MaxIndex = Ubound(SecondList())
12 OriginalList() = AddListToList(OriginalList(), SecondList())
14 SourceListbox = AddSingleItemToListbox(SourceListbox, SecondList(i))
16 Call FormSetMoveRights()
20 Sub RemoveListItems(SourceListbox as Object, TargetListbox as Object, RemoveList() as String)
23 Dim MaxIndex as Integer
25 MaxIndex = Ubound(RemoveList())
27 RemoveListboxItemByName(SourceListbox, RemoveList(i))
28 RemoveListboxItemByName(TargetListbox, RemoveList(i))
30 CopyList() = OriginalList()
32 MaxIndex = Ubound(CopyList())
34 If IndexInArray(CopyList(i),RemoveList())= -
1 Then
35 OriginalList(s) = CopyList(i)
39 ReDim Preserve OriginalList(s-
1)
40 Call FormSetMoveRights()
44 ' Note Boolean Parameter
45 Sub InitializeListboxProcedures(oModel as Object, SourceListbox as Object, TargetListbox as Object)
47 Set oDialogModel = oModel
48 OriginalList()= SourceListbox.StringItemList()
49 TargetListbox.StringItemList() = EmptyList()
53 Sub CopyListboxItems(SourceListbox as Object, TargetListbox As Object)
55 TargetListbox.StringItemList() = OriginalList()
56 SourceListbox.StringItemList() = NullArray()
60 Sub FormMoveSelected()
61 Call MoveSelectedListBox(oDialogModel.lstFields, oDialogModel.lstSelFields)
62 Call FormSetMoveRights()
63 oDialogModel.lstSelFields.Tag = True
68 Call CopyListboxItems(oDialogModel.lstFields, oDialogModel.lstSelFields)
69 Call FormSetMoveRights()
70 oDialogModel.lstSelFields.Tag = True
74 Sub FormRemoveSelected()
75 Call MoveOrderedSelectedListbox(oDialogModel.lstFields, oDialogModel.lstSelFields, False)
76 Call FormSetMoveRights()
77 oDialogModel.lstSelFields.Tag = True
82 Call MoveOrderedSelectedListbox(oDialogModel.lstFields, oDialogModel.lstSelFields, True)
83 Call FormSetMoveRights()
84 oDialogModel.lstSelFields.Tag =
1
88 Sub MoveSelectedListBox(SourceListbox as Object, TargetListbox as Object)
89 Dim MaxCurTarget as Integer
90 Dim MaxSourceSelected as Integer
94 Dim iOldTargetSelect as Integer
95 Dim iOldSourceSelect as Integer
96 MaxCurTarget = Ubound(TargetListbox.StringItemList())
97 MaxSourceSelected = Ubound(SourceListbox.SelectedItems())
98 Dim TargetList(MaxCurTarget+MaxSourceSelected+
1)
99 If MaxSourceSelected
> -
1 Then
100 iOldSourceSelect = SourceListbox.SelectedItems(
0)
101 If Ubound(TargetListbox.SelectedItems())
> -
1 Then
102 iOldTargetSelect = TargetListbox.SelectedItems(
0)
104 iOldTargetSelect = -
1
106 For n =
0 To MaxCurTarget
107 TargetList(n) = TargetListbox.StringItemList(n)
109 For m =
0 To MaxSourceSelected
110 CurIndex = SourceListbox.SelectedItems(m)
111 TargetList(n) = SourceListbox.StringItemList(CurIndex)
114 TargetListBox.StringItemList() = TargetList()
115 SourceListbox.StringItemList() = RemoveSelected (SourceListbox)
116 SetNewSelection(SourceListbox, iOldSourceSelect)
117 SetNewSelection(TargetListbox, iOldTargetSelect)
123 Sub MoveOrderedSelectedListbox(lstSource as Object, lstTarget as Object, bMoveAll as Boolean)
125 Dim MaxSelected as Integer
126 Dim MaxSourceIndex as Integer
127 Dim MaxOriginalIndex as Integer
128 Dim MaxNewIndex as Integer
131 Dim CurIndex as Integer
132 Dim SearchString as String
133 Dim SourceList() as String
134 Dim iOldTargetSelect as Integer
135 Dim iOldSourceSelect as Integer
137 lstSource.StringItemList() = OriginalList()
138 lstTarget.StringItemList() = NullArray()
140 MaxOriginalIndex = Ubound(OriginalList())
141 MaxSelected = Ubound(lstTarget.SelectedItems())
142 iOldTargetSelect = lstTarget.SelectedItems(
0)
143 If Ubound(lstSource.SelectedItems())
> -
1 Then
144 iOldSourceSelect = lstSource.SelectedItems(
0)
146 Dim SelList(MaxSelected)
147 For n =
0 To MaxSelected
148 CurIndex = lstTarget.SelectedItems(n)
149 SelList(n) = lstTarget.StringItemList(CurIndex)
151 SourceList() = lstSource.StringItemList()
152 MaxSourceIndex = Ubound(lstSource.StringItemList())
153 MaxNewIndex = MaxSelected + MaxSourceIndex +
1
154 Dim NewSourceList(MaxNewIndex)
156 For n =
0 To MaxOriginalIndex
157 SearchString = OriginalList(n)
158 If IndexinArray(SearchString, SelList())
<> -
1 Then
159 NewSourceList(m) = SearchString
161 ElseIf IndexinArray(SearchString, SourceList())
<> -
1 Then
162 NewSourceList(m) = SearchString
166 lstSource.StringItemList() = NewSourceList()
167 lstTarget.StringItemList() = RemoveSelected(lstTarget)
169 SetNewSelection(lstSource, iOldSourceSelect)
170 SetNewSelection(lstTarget, iOldTargetSelect)
175 Function RemoveSelected(oListbox as Object)
176 Dim MaxIndex as Integer
177 Dim MaxSelected as Integer
180 Dim CurIndex as Integer
181 Dim CurItem as String
183 MaxIndex = Ubound(oListbox.StringItemList())
184 MaxSelected = Ubound(oListbox.SelectedItems())
185 Dim LocItemList(MaxIndex)
186 LocItemList() = oListbox.StringItemList()
187 If MaxSelected
> -
1 Then
188 For n =
0 To MaxSelected
189 CurIndex = oListbox.SelectedItems(n)
190 LocItemList(CurIndex) =
""
192 If MaxIndex
> 0 Then
193 ReDim ResultArray(MaxIndex - MaxSelected -
1)
195 For n =
0 To MaxIndex
196 CurItem = LocItemList(n)
197 If CurItem
<> "" Then
198 ResultArray(m) = CurItem
203 RemoveSelected = ResultArray()
205 RemoveSelected = oListbox.StringItemList()
210 Sub SetNewSelection(oListBox as Object, iLastSelection as Integer)
211 Dim MaxIndex as Integer
212 Dim SelIndex as Integer
213 Dim SelList(
0) as Integer
214 MaxIndex = Ubound(oListBox.StringItemList())
215 If MaxIndex
> -
1 AND iLastSelection
> -
1 Then
216 If iLastSelection
> MaxIndex Then
219 SelIndex = iLastSelection
221 Sellist(
0) = SelIndex
222 oListBox.SelectedItems() = SelList()
227 Sub ToggleListboxControls(oDialogModel as Object, bDoEnable as Boolean)
229 .lblFields.Enabled = bDoEnable
230 .lblSelFields.Enabled = bDoEnable
231 ' .lstTables.Enabled = bDoEnable
232 .lstFields.Enabled = bDoEnable
233 .lstSelFields.Enabled = bDoEnable
234 .cmdRemoveAll.Enabled = bDoEnable
235 .cmdRemoveSelected.Enabled = bDoEnable
236 .cmdMoveAll.Enabled = bDoEnable
237 .cmdMoveSelected.Enabled = bDoEnable
245 ' Enable or disable the buttons used for moving the available
246 ' fields between the two list boxes.
247 Sub FormSetMoveRights()
248 Dim bIsFieldSelected as Boolean
249 Dim bSelectSelected as Boolean
250 Dim FieldCount as Integer
251 Dim SelectCount as Integer
252 bIsFieldSelected = Ubound(oDialogModel.lstFields.SelectedItems())
<> -
1
253 FieldCount = Ubound(oDialogModel.lstFields.StringItemList()) +
1
254 bSelectSelected = Ubound(oDialogModel.lstSelFields.SelectedItems())
> -
1
255 SelectCount = Ubound(oDialogModel.lstSelFields.StringItemList()) +
1
256 oDialogModel.cmdRemoveAll.Enabled = SelectCount
>=
1
257 oDialogModel.cmdRemoveSelected.Enabled = bSelectSelected
258 oDialogModel.cmdMoveAll.Enabled = FieldCount
>=
1
259 oDialogModel.cmdMoveSelected.Enabled = bIsFieldSelected
260 oDialogModel.cmdGoOn.Enabled = SelectCount
>=
1
261 ' This flag is set to
'1' when the lstSelFields has been modified
265 Function AddSingleItemToListbox(ByVal oListbox as Object, ListItem as String, Optional iSelIndex) as Object
266 Dim MaxIndex as Integer
269 MaxIndex = Ubound(oListbox.StringItemList())
270 Dim LocList(MaxIndex +
1)
271 ' Todo: This goes faster with the Redim LocList(MaxIndex +
1) Preserve function
272 For i =
0 To MaxIndex
273 LocList(i) = oListbox.StringItemList(i)
275 LocList(MaxIndex +
1) = ListItem
276 oListbox.StringItemList() = LocList()
277 If Not IsMissing(iSelIndex) Then
278 SelectListboxItem(oListbox, iSelIndex)
280 AddSingleItemToListbox() = oListbox
284 Sub EmptyListbox(oListbox as Object)
285 Dim NullList() as String
286 oListbox.StringItemList() = NullList()
290 Sub SelectListboxItem(oListbox as Object, iSelIndex as Integer)
291 Dim LocSelList(
0) as Integer
292 If iSelIndex
<> -
1 Then
293 LocSelList(
0) = iSelIndex
294 oListbox.SelectedItems() = LocSelList()
299 Function GetSelectedListboxItems(oListbox as Object)
300 Dim SelList(Ubound(oListBox.SelectedItems())) as String
302 Dim CurIndex as Integer
303 For i =
0 To Ubound(oListbox.SelectedItems())
304 CurIndex = oListbox.SelectedItems(i)
305 SelList(i) = oListbox.StringItemList(CurIndex)
307 GetSelectedListboxItems() = SelList()
311 ' Note: When using this Sub it must be ensured that the
312 ' 'RemoveItem
' appears only only once in the Listbox
313 Sub RemoveListboxItemByName(oListbox as Object, RemoveItem as String)
314 Dim OldList() as String
315 Dim NullList() as String
318 Dim MaxIndex as Integer
319 OldList = oListbox.StringItemList()
320 MaxIndex = Ubound(OldList())
321 If IndexInArray(RemoveItem, OldList())
<> -
1 Then
322 If MaxIndex
> 0 Then
324 Dim NewList(MaxIndex -
1)
325 For i =
0 To MaxIndex
326 If RemoveItem
<> OldList(i) Then
327 NewList(a) = OldList(i)
331 oListbox.StringItemList() = NewList()
333 oListBox.StringItemList() = NullList()
339 Function GetItemPos(oListBox as Object, sItem as String)
341 Dim MaxIndex as Integer
343 ItemList() = oListBox.StringItemList()
344 MaxIndex = Ubound(ItemList())
345 For i =
0 To MaxIndex
346 If sItem = ItemList(i) Then