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 37' Be sure that all variables are dimensioned: 38option explicit 39 40 41' REQUIRED VARIABLES for interface/service tests: 42 43' for XComponent 44Global oComponentInstance As Object 45 46' for XPersistObject 47Global oPersistInstance As Object 48 49' for XUpdateBroadcaster 50Global bCustomUpdate As Boolean 51 52Global oForm As Object 53Global aList(1) As Variant 54 55 56Sub CreateObj() 57 58'************************************************************************* 59' COMPONENT: 60' forms.OListBoxModel 61'************************************************************************* 62On Error Goto ErrHndl 63 Dim bOK As Boolean 64 Dim aSelection(0 to 0) As Variant 65 Dim oShape As Object, oDrawPage As Object 66 67 bOK = true 68 69 oDoc = utils.createDocument("swriter", cObjectName) 70 71 oShape = toolkittools.addControlToDefaultForm("ListBox", 1000, 1000, 2000, 1000) 72 oObj = oShape.getControl() 73 oShape = toolkittools.addControlToDefaultForm("ListBox", 1000, 3000, 2000, 1000) 74 oComponentInstance = oShape.getControl() 75 oShape = toolkittools.addControlToDefaultForm("ListBox", 1000, 5000, 2000, 1000) 76 oPersistInstance = oShape.getControl() 77 78 'for UnoControlListBoxModel::SelectedItems 79 aList(0) = "Hello" 80 aList(1) = "World" 81 aSelection(0) = 1 82 oObj.DefaultSelection = aSelection() 83 oObj.ListSource = aList() 84 85 'get control from document 86 oDrawPage = oDoc.DrawPage 87 oForm = oDrawPage.Forms.getByName("Standard") 88 89 oForm.DataSourceName = "Bibliography" 90 oForm.Command = "biblio" 91 oForm.CommandType = com.sun.star.sdb.CommandType.TABLE 92 93 oObj.DataField = "Author" 94 95 oForm.load() 96 97 ' for XUpdateBroadcaster 98 bCustomUpdate = true 99 100Exit Sub 101ErrHndl: 102 Test.Exception() 103End Sub 104 105Global sChangedText As String 106 107' for XBoundComponent 108Sub prepareCommit() 109On Error Goto ErrHndl 110 Dim items As Variant 111 Dim item As Variant 112 113 Out.Log("prepareCommit() called.") 114 items = oObj.SelectedItems 115 if ubound(items()) < 0 then 116 item = 0 117 else 118 if items(0) = 0 then item = 1 else item = 0 119 endif 120 121 sChangedText = aList(item) 122 oObj.SelectedItems = Array(item) 123 124 exit sub 125ErrHndl: 126 Test.Exception() 127End Sub 128 129' for XBoundComponent 130Function checkCommit() As Boolean 131On Error Goto ErrHndl 132 Out.Log("checkCommit() called.") 133 Dim rowText As Variant 134 135 rowText = oForm.getString(oForm.findColumn("Author")) 136 checkCommit() = (rowText = sChangedText) 137 138 exit function 139ErrHndl: 140 Test.Exception() 141End Function 142 143' for XUpdateBroadcaster 144Sub UpdateComponent() 145 Out.Log("UpdateComponent() called.") 146 147 Dim items As Variant 148 Dim item As Variant 149 items = oObj.SelectedItems 150 if ubound(items()) < 0 then 151 item = 0 152 else 153 if items(0) = 0 then item = 1 else item = 0 154 endif 155 oObj.SelectedItems = Array(item) 156 157 oObj.commit() 158End Sub 159</script:module> 160