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="forms_OFormattedFieldWrapper" 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' Requiered for  com.sun.star.lang.XComponent
38 Global oComponentInstance As Object ' it will be disposed
39
40' Requiered for  com.sun.star.io.XPersistObject
41 Global oPersistInstance As Object
42
43' for XUpdateBroadcaster
44Global bCustomUpdate As Boolean
45
46Global oForm As Object
47
48
49Sub CreateObj()
50
51'*************************************************************************
52' COMPONENT:
53' forms.OFormattedFieldWrapper
54'*************************************************************************
55On Error Goto ErrHndl
56    Dim bOK As Boolean
57    Dim oShape As Object, oDrawPage As Object
58
59    bOK = true
60
61    oDoc = utils.createDocument("swriter", cObjectName)
62
63    oShape = toolkittools.addControlToDefaultForm("DatabaseFormattedField", 1000, 1000, 2000, 1000)
64    oObj = oShape.getControl()
65    oShape = toolkittools.addControlToDefaultForm("DatabaseFormattedField", 1000, 3000, 2000, 1000)
66    oComponentInstance = oShape.getControl()
67    oShape = toolkittools.addControlToDefaultForm("DatabaseFormattedField", 1000, 5000, 2000, 1000)
68    oPersistInstance = oShape.getControl()
69
70    'get control from document
71    oDrawPage = oDoc.DrawPage
72    oForm = oDrawPage.Forms.getByName("Standard")
73
74    oForm.DataSourceName = "Bibliography"
75    oForm.Command = "biblio"
76    oForm.CommandType = com.sun.star.sdb.CommandType.TABLE
77
78    oObj.DataField = "Custom2"
79
80    oForm.load()
81
82    ' for XUpdateBroadcaster
83    bCustomUpdate = true
84
85    ' Switching to non-design mode
86    switchDesignMode(oDoc)
87
88Exit Sub
89ErrHndl:
90    Test.Exception()
91End Sub
92
93Sub switchDesignMode(xDoc as Object)
94On Error Goto ErrHndl
95
96        Dim frame as Variant, disp as Variant, transf as Object
97        Dim URL as new com.sun.star.util.URL
98        Dim noProps()
99        Dim res as Boolean
100
101        frame = xDoc.getCurrentController().getFrame()
102        URL.Complete = ".uno:SwitchControlDesignMode"
103        transf = createUnoService("com.sun.star.util.URLTransformer")
104        res = transf.parseStrict(URL)
105
106        out.log("URL parsed :" + res)
107
108        disp = frame.queryDispatch(URL, "", com.sun.star.frame.FrameSearchFlag.SELF _
109                OR com.sun.star.frame.FrameSearchFlag.CHILDREN)
110
111        out.log("disp get.")
112
113        disp.dispatch(URL, noProps())
114Exit Sub
115ErrHndl:
116    Test.Exception()
117End Sub
118
119Global sChangedText As String
120
121' for XBoundComponent
122Sub prepareCommit()
123On Error Goto ErrHndl
124    Out.Log("prepareCommit() called.")
125
126    if isNull(oObj.EffectiveValue) OR isEmpty(oObj.EffectiveValue) then
127        oObj.EffectiveValue = "12"
128    endif
129    sChangedText = "9" + oObj.EffectiveValue
130
131    Out.Log("Text was: '" + oObj.EffectiveValue + "', set to '" + sChangedText + "'")
132
133    oObj.EffectiveValue = sChangedText
134
135    exit sub
136ErrHndl:
137    Test.Exception()
138End Sub
139
140' for XBoundComponent
141Function checkCommit() As Boolean
142On Error Goto ErrHndl
143    Out.Log("checkCommit() called.")
144    Dim rowText As Variant
145
146    rowText = oForm.getString(oForm.findColumn("Custom2"))
147
148    Out.Log("Result test: '" + rowText + "'")
149    checkCommit() = (rowText = sChangedText)
150
151    exit function
152ErrHndl:
153    Test.Exception()
154End Function
155
156' for XUpdateBroadcaster
157Sub UpdateComponent()
158    oObj.EffectiveValue = "_" + oObj.EffectiveValue
159    oObj.commit()
160End Sub
161</script:module>
162