summaryrefslogtreecommitdiff
path: root/qadevOOo/tests/basic/mod/dbaccess/SbaXGridControl/dbaccess_SbaXGridControl.xba
blob: 49cb01a19912e3f24a8c274baae936e91a13fa7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="dbaccess_SbaXGridControl" script:language="StarBasic">


'*************************************************************************
'
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
' 
' Copyright 2008 by Sun Microsystems, Inc.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' $RCSfile: dbaccess_SbaXGridControl.xba,v $
'
' $Revision: 1.3 $
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 License.
'
'*************************************************************************
'*************************************************************************



' Be sure that all variables are dimensioned:
option explicit


' REQUIRED VARIABLES for interface/service tests:

' Required for view.XSelectionSupplier
Global SelectableObj1 as Variant
Global SelectableObj2 as Variant
    
' Required for awt.XControl
Global oModel As Object
Global oContext As Object
Global oWinpeer As Object
Global oToolkit As Object

' Required for awt.XWindow
Global oXWindow As Object
Global oCtrlShape As Variant

' Required for awt.XView
Global oGraphics As Object

' Required for frame.XDispatch
Global dispatchURL As String

' Required for XContainer
Global oElementToInsert As Object
Global oContainer As Object ' in case if the 
 ' component tested doesn't support XNameContainer

' Required for XComponent
Global oComponentInstance As Object 'it will be disposed

' Required for form.XUpdateBroadcaster
Global bCustomUpdate As Boolean


Sub CreateObj()

'*************************************************************************
' COMPONENT: 
' dbaccess.SbaXGridControl
'*************************************************************************
    Dim cntrlShape as Object, grid as Object
    Dim size as new com.sun.star.awt.Size
    Dim pos as new com.sun.star.awt.Point
    Dim drawPage as Object, aForm as Object
    Dim aColumn1 as Object, aColumn2 as Object
    Dim theAccess as Object
    Dim sel1(0) as Long, sel2(0) as Long
    Dim device as Object
    
On Error Goto ErrHndl

    oDoc = utils.createDocument("swriter", cObjectName)
    
    ' creating ControlShape with GridControl inside it
    cntrlShape = oDoc.createInstance("com.sun.star.drawing.ControlShape")
    grid = oDoc.createInstance("com.sun.star.form.component.GridControl")
    grid.DefaultControl = "com.sun.star.form.control.InteractionGridControl"
    pos.X = 15000
    pos.Y = 10000
    size.Width = 4500
    size.Height = 3000
    cntrlShape.setPosition(pos)
    cntrlShape.setSize(size)
    cntrlShape.setControl(grid)
    
    ' adding the shape with grid into the document
    drawPage = oDoc.getDrawPage()
    drawPage.add(cntrlShape)
    
    ' binding the form which contains a grid model to
    ' the Bibliography database
    aForm = drawPage.getForms().getByName("Standard")
    aForm.DataSourceName = "Bibliography"
    aForm.Command = "biblio"
    aForm.CommandType = com.sun.star.sdb.CommandType.TABLE
    
    ' creating and inserting some columns
    aColumn1 = grid.createColumn("TextField")
    aColumn1.DataField = "Identifier"
    aColumn1.Label = "Identifier"
    grid.insertByName("First", aColumn1)
    aColumn2 = grid.createColumn("TextField")
    aColumn2.DataField = "Address"
    aColumn2.Label = "Address"
    grid.insertByName("Second", aColumn2)
    
    ' Getting the controller of the Grid
    theAccess = oDoc.getCurrentController()
    oObj = theAccess.getControl(grid)

    ' setting variable for XSelectionSupplier
    sel1(0) = 2
    sel2(0) = 5
    SelectableObj1 = sel1()
    SelectableObj2 = sel2()

    ' setting variable for XControl
    oContext = oDoc
    oModel = grid
    oWinpeer = oObj.getPeer()
    oToolkit = oWinpeer.getToolkit()

    ' setting variable for XWindow
    oXWindow = theAccess.getControl(cntrlShape.getControl())
    oCtrlShape = cntrlShape

    ' setting variable for XView
    device = oToolkit.createScreenCompatibleDevice(200, 200)
    oGraphics = device.createGraphics()

    'setting variable for XDispatch
    dispatchURL = ".uno:FormSlots/moveToNext"
    
    'setting variables for XContainer
    oElementToInsert = grid.createColumn("TextField")
    oElementToInsert.DataField = "Author"
    oElementToInsert.Label = "Author"
    oContainer = grid

    'setting variable for XComponent
    cntrlShape = oDoc.createInstance("com.sun.star.drawing.ControlShape")
    grid = oDoc.createInstance("com.sun.star.form.component.GridControl")
    grid.DefaultControl = "com.sun.star.form.control.InteractionGridControl"
    cntrlShape.setControl(grid)
    drawPage.add(cntrlShape)


   'setting variable for XUpdateBroadcaster
    bCustomUpdate = True

    oComponentInstance = theAccess.getControl(grid)

    ' Switching to non-design mode
    switchDesignMode(oDoc)
    
    wait(200)

Exit Sub
ErrHndl:
    Test.Exception()
End Sub

Sub UpdateComponent()
    oObj.commit
End Sub

Sub switchDesignMode(xDoc as Object)
On Error Goto ErrHndl

        Dim frame as Variant, disp as Variant, transf as Object
        Dim URL as new com.sun.star.util.URL
        Dim noProps()
        Dim res as Boolean
        
        frame = xDoc.getCurrentController().getFrame()
        URL.Complete = ".uno:SwitchControlDesignMode"
        transf = createUnoService("com.sun.star.util.URLTransformer")
        res = transf.parseStrict(URL)
        
        out.log("URL parsed :" + res)
        
        disp = frame.queryDispatch(URL, "", com.sun.star.frame.FrameSearchFlag.SELF _
                OR com.sun.star.frame.FrameSearchFlag.CHILDREN)

        out.log("disp get.")

        disp.dispatch(URL, noProps())
Exit Sub
ErrHndl:
    Test.Exception()
End Sub

' for XBoundComponent
Sub prepareCommit()
    Out.Log("prepareCommit() called")
    Out.Log("can be checked only interactively")
End Sub

' for XBoundComponent
Function checkCommit() As Boolean
    checkCommit() = True
End Function
</script:module>