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="dbaccess_SbaXGridControl" 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' Required for view.XSelectionSupplier
43Global SelectableObj1 as Variant
44Global SelectableObj2 as Variant
45
46' Required for awt.XControl
47Global oModel As Object
48Global oContext As Object
49Global oWinpeer As Object
50Global oToolkit As Object
51
52' Required for awt.XWindow
53Global oXWindow As Object
54Global oCtrlShape As Variant
55
56' Required for awt.XView
57Global oGraphics As Object
58
59' Required for frame.XDispatch
60Global dispatchURL As String
61
62' Required for XContainer
63Global oElementToInsert As Object
64Global oContainer As Object ' in case if the
65 ' component tested doesn't support XNameContainer
66
67' Required for XComponent
68Global oComponentInstance As Object 'it will be disposed
69
70' Required for form.XUpdateBroadcaster
71Global bCustomUpdate As Boolean
72
73
74Sub CreateObj()
75
76'*************************************************************************
77' COMPONENT:
78' dbaccess.SbaXGridControl
79'*************************************************************************
80    Dim cntrlShape as Object, grid as Object
81    Dim size as new com.sun.star.awt.Size
82    Dim pos as new com.sun.star.awt.Point
83    Dim drawPage as Object, aForm as Object
84    Dim aColumn1 as Object, aColumn2 as Object
85    Dim theAccess as Object
86    Dim sel1(0) as Long, sel2(0) as Long
87    Dim device as Object
88
89On Error Goto ErrHndl
90
91    oDoc = utils.createDocument("swriter", cObjectName)
92
93    ' creating ControlShape with GridControl inside it
94    cntrlShape = oDoc.createInstance("com.sun.star.drawing.ControlShape")
95    grid = oDoc.createInstance("com.sun.star.form.component.GridControl")
96    grid.DefaultControl = "com.sun.star.form.control.InteractionGridControl"
97    pos.X = 15000
98    pos.Y = 10000
99    size.Width = 4500
100    size.Height = 3000
101    cntrlShape.setPosition(pos)
102    cntrlShape.setSize(size)
103    cntrlShape.setControl(grid)
104
105    ' adding the shape with grid into the document
106    drawPage = oDoc.getDrawPage()
107    drawPage.add(cntrlShape)
108
109    ' binding the form which contains a grid model to
110    ' the Bibliography database
111    aForm = drawPage.getForms().getByName("Standard")
112    aForm.DataSourceName = "Bibliography"
113    aForm.Command = "biblio"
114    aForm.CommandType = com.sun.star.sdb.CommandType.TABLE
115
116    ' creating and inserting some columns
117    aColumn1 = grid.createColumn("TextField")
118    aColumn1.DataField = "Identifier"
119    aColumn1.Label = "Identifier"
120    grid.insertByName("First", aColumn1)
121    aColumn2 = grid.createColumn("TextField")
122    aColumn2.DataField = "Address"
123    aColumn2.Label = "Address"
124    grid.insertByName("Second", aColumn2)
125
126    ' Getting the controller of the Grid
127    theAccess = oDoc.getCurrentController()
128    oObj = theAccess.getControl(grid)
129
130    ' setting variable for XSelectionSupplier
131    sel1(0) = 2
132    sel2(0) = 5
133    SelectableObj1 = sel1()
134    SelectableObj2 = sel2()
135
136    ' setting variable for XControl
137    oContext = oDoc
138    oModel = grid
139    oWinpeer = oObj.getPeer()
140    oToolkit = oWinpeer.getToolkit()
141
142    ' setting variable for XWindow
143    oXWindow = theAccess.getControl(cntrlShape.getControl())
144    oCtrlShape = cntrlShape
145
146    ' setting variable for XView
147    device = oToolkit.createScreenCompatibleDevice(200, 200)
148    oGraphics = device.createGraphics()
149
150    'setting variable for XDispatch
151    dispatchURL = ".uno:FormSlots/moveToNext"
152
153    'setting variables for XContainer
154    oElementToInsert = grid.createColumn("TextField")
155    oElementToInsert.DataField = "Author"
156    oElementToInsert.Label = "Author"
157    oContainer = grid
158
159    'setting variable for XComponent
160    cntrlShape = oDoc.createInstance("com.sun.star.drawing.ControlShape")
161    grid = oDoc.createInstance("com.sun.star.form.component.GridControl")
162    grid.DefaultControl = "com.sun.star.form.control.InteractionGridControl"
163    cntrlShape.setControl(grid)
164    drawPage.add(cntrlShape)
165
166
167   'setting variable for XUpdateBroadcaster
168    bCustomUpdate = True
169
170    oComponentInstance = theAccess.getControl(grid)
171
172    ' Switching to non-design mode
173    switchDesignMode(oDoc)
174
175    wait(200)
176
177Exit Sub
178ErrHndl:
179    Test.Exception()
180End Sub
181
182Sub UpdateComponent()
183    oObj.commit
184End Sub
185
186Sub switchDesignMode(xDoc as Object)
187On Error Goto ErrHndl
188
189        Dim frame as Variant, disp as Variant, transf as Object
190        Dim URL as new com.sun.star.util.URL
191        Dim noProps()
192        Dim res as Boolean
193
194        frame = xDoc.getCurrentController().getFrame()
195        URL.Complete = ".uno:SwitchControlDesignMode"
196        transf = createUnoService("com.sun.star.util.URLTransformer")
197        res = transf.parseStrict(URL)
198
199        out.log("URL parsed :" + res)
200
201        disp = frame.queryDispatch(URL, "", com.sun.star.frame.FrameSearchFlag.SELF _
202                OR com.sun.star.frame.FrameSearchFlag.CHILDREN)
203
204        out.log("disp get.")
205
206        disp.dispatch(URL, noProps())
207Exit Sub
208ErrHndl:
209    Test.Exception()
210End Sub
211
212' for XBoundComponent
213Sub prepareCommit()
214    Out.Log("prepareCommit() called")
215    Out.Log("can be checked only interactively")
216End Sub
217
218' for XBoundComponent
219Function checkCommit() As Boolean
220    checkCommit() = True
221End Function
222</script:module>
223