1*b1cdbd2cSJim Jagielski<?xml version="1.0" encoding="UTF-8"?>
2*b1cdbd2cSJim Jagielski<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*b1cdbd2cSJim Jagielski<script:module xmlns:script="http://openoffice.org/2000/script" script:name="dbaccess_SbaXGridControl" script:language="StarBasic">
4*b1cdbd2cSJim Jagielski
5*b1cdbd2cSJim Jagielski
6*b1cdbd2cSJim Jagielski'*************************************************************************
7*b1cdbd2cSJim Jagielski'
8*b1cdbd2cSJim Jagielski'  Licensed to the Apache Software Foundation (ASF) under one
9*b1cdbd2cSJim Jagielski'  or more contributor license agreements.  See the NOTICE file
10*b1cdbd2cSJim Jagielski'  distributed with this work for additional information
11*b1cdbd2cSJim Jagielski'  regarding copyright ownership.  The ASF licenses this file
12*b1cdbd2cSJim Jagielski'  to you under the Apache License, Version 2.0 (the
13*b1cdbd2cSJim Jagielski'  "License"); you may not use this file except in compliance
14*b1cdbd2cSJim Jagielski'  with the License.  You may obtain a copy of the License at
15*b1cdbd2cSJim Jagielski'
16*b1cdbd2cSJim Jagielski'    http://www.apache.org/licenses/LICENSE-2.0
17*b1cdbd2cSJim Jagielski'
18*b1cdbd2cSJim Jagielski'  Unless required by applicable law or agreed to in writing,
19*b1cdbd2cSJim Jagielski'  software distributed under the License is distributed on an
20*b1cdbd2cSJim Jagielski'  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21*b1cdbd2cSJim Jagielski'  KIND, either express or implied.  See the License for the
22*b1cdbd2cSJim Jagielski'  specific language governing permissions and limitations
23*b1cdbd2cSJim Jagielski'  under the License.
24*b1cdbd2cSJim Jagielski'
25*b1cdbd2cSJim Jagielski'*************************************************************************
26*b1cdbd2cSJim Jagielski
27*b1cdbd2cSJim Jagielski
28*b1cdbd2cSJim Jagielski
29*b1cdbd2cSJim Jagielski
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim Jagielski' Be sure that all variables are dimensioned:
32*b1cdbd2cSJim Jagielskioption explicit
33*b1cdbd2cSJim Jagielski
34*b1cdbd2cSJim Jagielski
35*b1cdbd2cSJim Jagielski' REQUIRED VARIABLES for interface/service tests:
36*b1cdbd2cSJim Jagielski
37*b1cdbd2cSJim Jagielski' Required for view.XSelectionSupplier
38*b1cdbd2cSJim JagielskiGlobal SelectableObj1 as Variant
39*b1cdbd2cSJim JagielskiGlobal SelectableObj2 as Variant
40*b1cdbd2cSJim Jagielski
41*b1cdbd2cSJim Jagielski' Required for awt.XControl
42*b1cdbd2cSJim JagielskiGlobal oModel As Object
43*b1cdbd2cSJim JagielskiGlobal oContext As Object
44*b1cdbd2cSJim JagielskiGlobal oWinpeer As Object
45*b1cdbd2cSJim JagielskiGlobal oToolkit As Object
46*b1cdbd2cSJim Jagielski
47*b1cdbd2cSJim Jagielski' Required for awt.XWindow
48*b1cdbd2cSJim JagielskiGlobal oXWindow As Object
49*b1cdbd2cSJim JagielskiGlobal oCtrlShape As Variant
50*b1cdbd2cSJim Jagielski
51*b1cdbd2cSJim Jagielski' Required for awt.XView
52*b1cdbd2cSJim JagielskiGlobal oGraphics As Object
53*b1cdbd2cSJim Jagielski
54*b1cdbd2cSJim Jagielski' Required for frame.XDispatch
55*b1cdbd2cSJim JagielskiGlobal dispatchURL As String
56*b1cdbd2cSJim Jagielski
57*b1cdbd2cSJim Jagielski' Required for XContainer
58*b1cdbd2cSJim JagielskiGlobal oElementToInsert As Object
59*b1cdbd2cSJim JagielskiGlobal oContainer As Object ' in case if the
60*b1cdbd2cSJim Jagielski ' component tested doesn't support XNameContainer
61*b1cdbd2cSJim Jagielski
62*b1cdbd2cSJim Jagielski' Required for XComponent
63*b1cdbd2cSJim JagielskiGlobal oComponentInstance As Object 'it will be disposed
64*b1cdbd2cSJim Jagielski
65*b1cdbd2cSJim Jagielski' Required for form.XUpdateBroadcaster
66*b1cdbd2cSJim JagielskiGlobal bCustomUpdate As Boolean
67*b1cdbd2cSJim Jagielski
68*b1cdbd2cSJim Jagielski
69*b1cdbd2cSJim JagielskiSub CreateObj()
70*b1cdbd2cSJim Jagielski
71*b1cdbd2cSJim Jagielski'*************************************************************************
72*b1cdbd2cSJim Jagielski' COMPONENT:
73*b1cdbd2cSJim Jagielski' dbaccess.SbaXGridControl
74*b1cdbd2cSJim Jagielski'*************************************************************************
75*b1cdbd2cSJim Jagielski    Dim cntrlShape as Object, grid as Object
76*b1cdbd2cSJim Jagielski    Dim size as new com.sun.star.awt.Size
77*b1cdbd2cSJim Jagielski    Dim pos as new com.sun.star.awt.Point
78*b1cdbd2cSJim Jagielski    Dim drawPage as Object, aForm as Object
79*b1cdbd2cSJim Jagielski    Dim aColumn1 as Object, aColumn2 as Object
80*b1cdbd2cSJim Jagielski    Dim theAccess as Object
81*b1cdbd2cSJim Jagielski    Dim sel1(0) as Long, sel2(0) as Long
82*b1cdbd2cSJim Jagielski    Dim device as Object
83*b1cdbd2cSJim Jagielski
84*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl
85*b1cdbd2cSJim Jagielski
86*b1cdbd2cSJim Jagielski    oDoc = utils.createDocument("swriter", cObjectName)
87*b1cdbd2cSJim Jagielski
88*b1cdbd2cSJim Jagielski    ' creating ControlShape with GridControl inside it
89*b1cdbd2cSJim Jagielski    cntrlShape = oDoc.createInstance("com.sun.star.drawing.ControlShape")
90*b1cdbd2cSJim Jagielski    grid = oDoc.createInstance("com.sun.star.form.component.GridControl")
91*b1cdbd2cSJim Jagielski    grid.DefaultControl = "com.sun.star.form.control.InteractionGridControl"
92*b1cdbd2cSJim Jagielski    pos.X = 15000
93*b1cdbd2cSJim Jagielski    pos.Y = 10000
94*b1cdbd2cSJim Jagielski    size.Width = 4500
95*b1cdbd2cSJim Jagielski    size.Height = 3000
96*b1cdbd2cSJim Jagielski    cntrlShape.setPosition(pos)
97*b1cdbd2cSJim Jagielski    cntrlShape.setSize(size)
98*b1cdbd2cSJim Jagielski    cntrlShape.setControl(grid)
99*b1cdbd2cSJim Jagielski
100*b1cdbd2cSJim Jagielski    ' adding the shape with grid into the document
101*b1cdbd2cSJim Jagielski    drawPage = oDoc.getDrawPage()
102*b1cdbd2cSJim Jagielski    drawPage.add(cntrlShape)
103*b1cdbd2cSJim Jagielski
104*b1cdbd2cSJim Jagielski    ' binding the form which contains a grid model to
105*b1cdbd2cSJim Jagielski    ' the Bibliography database
106*b1cdbd2cSJim Jagielski    aForm = drawPage.getForms().getByName("Standard")
107*b1cdbd2cSJim Jagielski    aForm.DataSourceName = "Bibliography"
108*b1cdbd2cSJim Jagielski    aForm.Command = "biblio"
109*b1cdbd2cSJim Jagielski    aForm.CommandType = com.sun.star.sdb.CommandType.TABLE
110*b1cdbd2cSJim Jagielski
111*b1cdbd2cSJim Jagielski    ' creating and inserting some columns
112*b1cdbd2cSJim Jagielski    aColumn1 = grid.createColumn("TextField")
113*b1cdbd2cSJim Jagielski    aColumn1.DataField = "Identifier"
114*b1cdbd2cSJim Jagielski    aColumn1.Label = "Identifier"
115*b1cdbd2cSJim Jagielski    grid.insertByName("First", aColumn1)
116*b1cdbd2cSJim Jagielski    aColumn2 = grid.createColumn("TextField")
117*b1cdbd2cSJim Jagielski    aColumn2.DataField = "Address"
118*b1cdbd2cSJim Jagielski    aColumn2.Label = "Address"
119*b1cdbd2cSJim Jagielski    grid.insertByName("Second", aColumn2)
120*b1cdbd2cSJim Jagielski
121*b1cdbd2cSJim Jagielski    ' Getting the controller of the Grid
122*b1cdbd2cSJim Jagielski    theAccess = oDoc.getCurrentController()
123*b1cdbd2cSJim Jagielski    oObj = theAccess.getControl(grid)
124*b1cdbd2cSJim Jagielski
125*b1cdbd2cSJim Jagielski    ' setting variable for XSelectionSupplier
126*b1cdbd2cSJim Jagielski    sel1(0) = 2
127*b1cdbd2cSJim Jagielski    sel2(0) = 5
128*b1cdbd2cSJim Jagielski    SelectableObj1 = sel1()
129*b1cdbd2cSJim Jagielski    SelectableObj2 = sel2()
130*b1cdbd2cSJim Jagielski
131*b1cdbd2cSJim Jagielski    ' setting variable for XControl
132*b1cdbd2cSJim Jagielski    oContext = oDoc
133*b1cdbd2cSJim Jagielski    oModel = grid
134*b1cdbd2cSJim Jagielski    oWinpeer = oObj.getPeer()
135*b1cdbd2cSJim Jagielski    oToolkit = oWinpeer.getToolkit()
136*b1cdbd2cSJim Jagielski
137*b1cdbd2cSJim Jagielski    ' setting variable for XWindow
138*b1cdbd2cSJim Jagielski    oXWindow = theAccess.getControl(cntrlShape.getControl())
139*b1cdbd2cSJim Jagielski    oCtrlShape = cntrlShape
140*b1cdbd2cSJim Jagielski
141*b1cdbd2cSJim Jagielski    ' setting variable for XView
142*b1cdbd2cSJim Jagielski    device = oToolkit.createScreenCompatibleDevice(200, 200)
143*b1cdbd2cSJim Jagielski    oGraphics = device.createGraphics()
144*b1cdbd2cSJim Jagielski
145*b1cdbd2cSJim Jagielski    'setting variable for XDispatch
146*b1cdbd2cSJim Jagielski    dispatchURL = ".uno:FormSlots/moveToNext"
147*b1cdbd2cSJim Jagielski
148*b1cdbd2cSJim Jagielski    'setting variables for XContainer
149*b1cdbd2cSJim Jagielski    oElementToInsert = grid.createColumn("TextField")
150*b1cdbd2cSJim Jagielski    oElementToInsert.DataField = "Author"
151*b1cdbd2cSJim Jagielski    oElementToInsert.Label = "Author"
152*b1cdbd2cSJim Jagielski    oContainer = grid
153*b1cdbd2cSJim Jagielski
154*b1cdbd2cSJim Jagielski    'setting variable for XComponent
155*b1cdbd2cSJim Jagielski    cntrlShape = oDoc.createInstance("com.sun.star.drawing.ControlShape")
156*b1cdbd2cSJim Jagielski    grid = oDoc.createInstance("com.sun.star.form.component.GridControl")
157*b1cdbd2cSJim Jagielski    grid.DefaultControl = "com.sun.star.form.control.InteractionGridControl"
158*b1cdbd2cSJim Jagielski    cntrlShape.setControl(grid)
159*b1cdbd2cSJim Jagielski    drawPage.add(cntrlShape)
160*b1cdbd2cSJim Jagielski
161*b1cdbd2cSJim Jagielski
162*b1cdbd2cSJim Jagielski   'setting variable for XUpdateBroadcaster
163*b1cdbd2cSJim Jagielski    bCustomUpdate = True
164*b1cdbd2cSJim Jagielski
165*b1cdbd2cSJim Jagielski    oComponentInstance = theAccess.getControl(grid)
166*b1cdbd2cSJim Jagielski
167*b1cdbd2cSJim Jagielski    ' Switching to non-design mode
168*b1cdbd2cSJim Jagielski    switchDesignMode(oDoc)
169*b1cdbd2cSJim Jagielski
170*b1cdbd2cSJim Jagielski    wait(200)
171*b1cdbd2cSJim Jagielski
172*b1cdbd2cSJim JagielskiExit Sub
173*b1cdbd2cSJim JagielskiErrHndl:
174*b1cdbd2cSJim Jagielski    Test.Exception()
175*b1cdbd2cSJim JagielskiEnd Sub
176*b1cdbd2cSJim Jagielski
177*b1cdbd2cSJim JagielskiSub UpdateComponent()
178*b1cdbd2cSJim Jagielski    oObj.commit
179*b1cdbd2cSJim JagielskiEnd Sub
180*b1cdbd2cSJim Jagielski
181*b1cdbd2cSJim JagielskiSub switchDesignMode(xDoc as Object)
182*b1cdbd2cSJim JagielskiOn Error Goto ErrHndl
183*b1cdbd2cSJim Jagielski
184*b1cdbd2cSJim Jagielski        Dim frame as Variant, disp as Variant, transf as Object
185*b1cdbd2cSJim Jagielski        Dim URL as new com.sun.star.util.URL
186*b1cdbd2cSJim Jagielski        Dim noProps()
187*b1cdbd2cSJim Jagielski        Dim res as Boolean
188*b1cdbd2cSJim Jagielski
189*b1cdbd2cSJim Jagielski        frame = xDoc.getCurrentController().getFrame()
190*b1cdbd2cSJim Jagielski        URL.Complete = ".uno:SwitchControlDesignMode"
191*b1cdbd2cSJim Jagielski        transf = createUnoService("com.sun.star.util.URLTransformer")
192*b1cdbd2cSJim Jagielski        res = transf.parseStrict(URL)
193*b1cdbd2cSJim Jagielski
194*b1cdbd2cSJim Jagielski        out.log("URL parsed :" + res)
195*b1cdbd2cSJim Jagielski
196*b1cdbd2cSJim Jagielski        disp = frame.queryDispatch(URL, "", com.sun.star.frame.FrameSearchFlag.SELF _
197*b1cdbd2cSJim Jagielski                OR com.sun.star.frame.FrameSearchFlag.CHILDREN)
198*b1cdbd2cSJim Jagielski
199*b1cdbd2cSJim Jagielski        out.log("disp get.")
200*b1cdbd2cSJim Jagielski
201*b1cdbd2cSJim Jagielski        disp.dispatch(URL, noProps())
202*b1cdbd2cSJim JagielskiExit Sub
203*b1cdbd2cSJim JagielskiErrHndl:
204*b1cdbd2cSJim Jagielski    Test.Exception()
205*b1cdbd2cSJim JagielskiEnd Sub
206*b1cdbd2cSJim Jagielski
207*b1cdbd2cSJim Jagielski' for XBoundComponent
208*b1cdbd2cSJim JagielskiSub prepareCommit()
209*b1cdbd2cSJim Jagielski    Out.Log("prepareCommit() called")
210*b1cdbd2cSJim Jagielski    Out.Log("can be checked only interactively")
211*b1cdbd2cSJim JagielskiEnd Sub
212*b1cdbd2cSJim Jagielski
213*b1cdbd2cSJim Jagielski' for XBoundComponent
214*b1cdbd2cSJim JagielskiFunction checkCommit() As Boolean
215*b1cdbd2cSJim Jagielski    checkCommit() = True
216*b1cdbd2cSJim JagielskiEnd Function
217*b1cdbd2cSJim Jagielski</script:module>
218