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