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