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