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="forms_OListBoxModel" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8'  Licensed to the Apache Software Foundation (ASF) under one
9'  or more contributor license agreements.  See the NOTICE file
10'  distributed with this work for additional information
11'  regarding copyright ownership.  The ASF licenses this file
12'  to you under the Apache License, Version 2.0 (the
13'  "License"); you may not use this file except in compliance
14'  with the License.  You may obtain a copy of the License at
15'
16'    http://www.apache.org/licenses/LICENSE-2.0
17'
18'  Unless required by applicable law or agreed to in writing,
19'  software distributed under the License is distributed on an
20'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21'  KIND, either express or implied.  See the License for the
22'  specific language governing permissions and limitations
23'  under the License.
24'
25'*************************************************************************
26
27
28
29
30
31' Be sure that all variables are dimensioned:
32option explicit
33
34
35' REQUIRED VARIABLES for interface/service tests:
36
37' for XComponent
38Global oComponentInstance As Object
39
40' for XPersistObject
41Global oPersistInstance As Object
42
43' for XUpdateBroadcaster
44Global bCustomUpdate As Boolean
45
46Global oForm As Object
47Global aList(1) As Variant
48
49
50Sub CreateObj()
51
52'*************************************************************************
53' COMPONENT:
54' forms.OListBoxModel
55'*************************************************************************
56On Error Goto ErrHndl
57    Dim bOK As Boolean
58    Dim aSelection(0 to 0) As Variant
59    Dim oShape As Object, oDrawPage As Object
60
61    bOK = true
62
63    oDoc = utils.createDocument("swriter", cObjectName)
64
65    oShape = toolkittools.addControlToDefaultForm("ListBox", 1000, 1000, 2000, 1000)
66    oObj = oShape.getControl()
67    oShape = toolkittools.addControlToDefaultForm("ListBox", 1000, 3000, 2000, 1000)
68    oComponentInstance = oShape.getControl()
69    oShape = toolkittools.addControlToDefaultForm("ListBox", 1000, 5000, 2000, 1000)
70    oPersistInstance = oShape.getControl()
71
72    'for UnoControlListBoxModel::SelectedItems
73    aList(0) = "Hello"
74    aList(1) = "World"
75    aSelection(0) = 1
76    oObj.DefaultSelection = aSelection()
77    oObj.ListSource = aList()
78
79    'get control from document
80    oDrawPage = oDoc.DrawPage
81    oForm = oDrawPage.Forms.getByName("Standard")
82
83	oForm.DataSourceName = "Bibliography"
84	oForm.Command = "biblio"
85	oForm.CommandType = com.sun.star.sdb.CommandType.TABLE
86
87    oObj.DataField = "Author"
88
89    oForm.load()
90
91    ' for XUpdateBroadcaster
92    bCustomUpdate = true
93
94Exit Sub
95ErrHndl:
96    Test.Exception()
97End Sub
98
99Global sChangedText As String
100
101' for XBoundComponent
102Sub prepareCommit()
103On Error Goto ErrHndl
104    Dim items As Variant
105    Dim item As Variant
106
107    Out.Log("prepareCommit() called.")
108    items = oObj.SelectedItems
109    if ubound(items()) &lt; 0 then
110        item = 0
111    else
112        if items(0) = 0 then item = 1 else item = 0
113    endif
114
115    sChangedText = aList(item)
116    oObj.SelectedItems = Array(item)
117
118    exit sub
119ErrHndl:
120    Test.Exception()
121End Sub
122
123' for XBoundComponent
124Function checkCommit() As Boolean
125On Error Goto ErrHndl
126    Out.Log("checkCommit() called.")
127    Dim rowText As Variant
128
129    rowText = oForm.getString(oForm.findColumn("Author"))
130    checkCommit() = (rowText = sChangedText)
131
132    exit function
133ErrHndl:
134    Test.Exception()
135End Function
136
137' for XUpdateBroadcaster
138Sub UpdateComponent()
139    Out.Log("UpdateComponent() called.")
140
141    Dim items As Variant
142    Dim item As Variant
143    items = oObj.SelectedItems
144    if ubound(items()) &lt; 0 then
145        item = 0
146    else
147        if items(0) = 0 then item = 1 else item = 0
148    endif
149    oObj.SelectedItems = Array(item)
150
151    oObj.commit()
152End Sub
153</script:module>
154