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' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9' 10' Copyright 2000, 2010 Oracle and/or its affiliates. 11' 12' OpenOffice.org - a multi-platform office productivity suite 13' 14' This file is part of OpenOffice.org. 15' 16' OpenOffice.org is free software: you can redistribute it and/or modify 17' it under the terms of the GNU Lesser General Public License version 3 18' only, as published by the Free Software Foundation. 19' 20' OpenOffice.org is distributed in the hope that it will be useful, 21' but WITHOUT ANY WARRANTY; without even the implied warranty of 22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23' GNU Lesser General Public License version 3 for more details 24' (a copy is included in the LICENSE file that accompanied this code). 25' 26' You should have received a copy of the GNU Lesser General Public License 27' version 3 along with OpenOffice.org. If not, see 28' <http://www.openoffice.org/license.html> 29' for a copy of the LGPLv3 License. 30' 31'************************************************************************* 32'************************************************************************* 33 34 35 36' Be sure that all variables are dimensioned: 37option explicit 38 39 40' REQUIRED VARIABLES for interface/service tests: 41 42' for XComponent 43Global oComponentInstance As Object 44 45' for XPersistObject 46Global oPersistInstance As Object 47 48' for XUpdateBroadcaster 49Global bCustomUpdate As Boolean 50 51Global oForm As Object 52Global aList(1) As Variant 53 54 55Sub CreateObj() 56 57'************************************************************************* 58' COMPONENT: 59' forms.OListBoxModel 60'************************************************************************* 61On Error Goto ErrHndl 62 Dim bOK As Boolean 63 Dim aSelection(0 to 0) As Variant 64 Dim oShape As Object, oDrawPage As Object 65 66 bOK = true 67 68 oDoc = utils.createDocument("swriter", cObjectName) 69 70 oShape = toolkittools.addControlToDefaultForm("ListBox", 1000, 1000, 2000, 1000) 71 oObj = oShape.getControl() 72 oShape = toolkittools.addControlToDefaultForm("ListBox", 1000, 3000, 2000, 1000) 73 oComponentInstance = oShape.getControl() 74 oShape = toolkittools.addControlToDefaultForm("ListBox", 1000, 5000, 2000, 1000) 75 oPersistInstance = oShape.getControl() 76 77 'for UnoControlListBoxModel::SelectedItems 78 aList(0) = "Hello" 79 aList(1) = "World" 80 aSelection(0) = 1 81 oObj.DefaultSelection = aSelection() 82 oObj.ListSource = aList() 83 84 'get control from document 85 oDrawPage = oDoc.DrawPage 86 oForm = oDrawPage.Forms.getByName("Standard") 87 88 oForm.DataSourceName = "Bibliography" 89 oForm.Command = "biblio" 90 oForm.CommandType = com.sun.star.sdb.CommandType.TABLE 91 92 oObj.DataField = "Author" 93 94 oForm.load() 95 96 ' for XUpdateBroadcaster 97 bCustomUpdate = true 98 99Exit Sub 100ErrHndl: 101 Test.Exception() 102End Sub 103 104Global sChangedText As String 105 106' for XBoundComponent 107Sub prepareCommit() 108On Error Goto ErrHndl 109 Dim items As Variant 110 Dim item As Variant 111 112 Out.Log("prepareCommit() called.") 113 items = oObj.SelectedItems 114 if ubound(items()) < 0 then 115 item = 0 116 else 117 if items(0) = 0 then item = 1 else item = 0 118 endif 119 120 sChangedText = aList(item) 121 oObj.SelectedItems = Array(item) 122 123 exit sub 124ErrHndl: 125 Test.Exception() 126End Sub 127 128' for XBoundComponent 129Function checkCommit() As Boolean 130On Error Goto ErrHndl 131 Out.Log("checkCommit() called.") 132 Dim rowText As Variant 133 134 rowText = oForm.getString(oForm.findColumn("Author")) 135 checkCommit() = (rowText = sChangedText) 136 137 exit function 138ErrHndl: 139 Test.Exception() 140End Function 141 142' for XUpdateBroadcaster 143Sub UpdateComponent() 144 Out.Log("UpdateComponent() called.") 145 146 Dim items As Variant 147 Dim item As Variant 148 items = oObj.SelectedItems 149 if ubound(items()) < 0 then 150 item = 0 151 else 152 if items(0) = 0 then item = 1 else item = 0 153 endif 154 oObj.SelectedItems = Array(item) 155 156 oObj.commit() 157End Sub 158</script:module> 159