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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
<?xml version="1.0" encoding="UTF-8"?>
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="MultiPage" script:language="StarBasic">REM ***** BASIC *****
Dim oDialog As Object
Sub Main()
Dim oLibContainer As Object, oLib As Object
Dim oInputStreamProvider As Object
Dim oDialogModel As Object
Const sLibName = "ToolkitControls"
Const sDialogName = "MultiPageDlg"
REM load/get library and input stream provider
oLibContainer = DialogLibraries
oLibContainer.loadLibrary( sLibName )
oLib = oLibContainer.getByName( sLibName )
oInputStreamProvider = oLib.getByName( sDialogName )
REM create dialog control
oDialog = CreateUnoDialog( oInputStreamProvider )
REM initialize dialog and controls
Initialize()
REM show the dialog
oDialog.execute()
End Sub
Sub Initialize()
Dim oDialogModel As Object
Dim oNextButton As Object, oNextButtonModel As Object
Dim oListBox As Object
Dim oCheckBoxModel As Object
Dim oOptionButtonModel As Object
Dim oCurrencyFieldModel As Object
Dim oNumericFieldModel As Object
Dim oComboBox As Object, oComboBoxModel As Object
Dim i As Integer
Dim sName As String
Dim sPizzas As Variant, sToppings As Variant
Dim sCreditCards As Variant
Dim sMonths As Variant
Dim iCount As Integer
REM dialog properties
oDialogModel = oDialog.Model
oDialogModel.Step = 1
REM next button properties
oNextButtonModel = oDialogModel.NextButton
oNextButtonModel.DefaultButton = True
oNextButton = oDialog.getControl("NextButton")
oNextButton.setFocus()
REM enable/disable back button, set label of next button
PageChanged()
REM set control properties on dialog page 1
REM pizzas in list box
oListBox = oDialog.getControl("ListBox1")
sPizzas = Array("Margarita","Vegeterian","Ham & Pineapple","Mexican","Seafood")
oListBox.addItems( sPizzas, 0 )
oListBox.selectItem( sPizzas(0), True )
REM extra toppings
sToppings = Array("Extra Cheese","Corn","Onions","Olives")
For i = 0 To 3
sName = "CheckBox" + i
oCheckBoxModel = oDialogModel.getByName( sName )
oCheckBoxModel.Label = sToppings( i )
Next i
REM default pizza size
oOptionButtonModel = oDialogModel.OptionButton2
oOptionButtonModel.State = True
REM currency field properties
oCurrencyFieldModel = oDialogModel.CurrencyField1
oCurrencyFieldModel.ReadOnly = True
oCurrencyFieldModel.DecimalAccuracy = 2
oCurrencyFieldModel.CurrencySymbol = "€"
oCurrencyFieldModel.PrependCurrencySymbol = True
REM calculate prize for default settings
CalculatePrize()
REM set control properties on dialog page 2
REM numeric field properties
oNumericFieldModel = oDialogModel.NumericField1
oNumericFieldModel.DecimalAccuracy = 0
REM set control properties on dialog page 3
REM default payment method
oOptionButtonModel = oDialogModel.OptionButton4
oOptionButtonModel.State = True
REM credit cards in combo box
oComboBox = oDialog.getControl("ComboBox1")
sCreditCards = Array("Visa","Master/EuroCard","American Express")
oComboBox.addItems( sCreditCards, 0 )
oComboBoxModel = oDialogModel.ComboBox1
oComboBoxModel.Text = sCreditCards(0)
REM expiration month
oListBox = oDialog.getControl("ListBox2")
sMonths = Array("01","02","03","04","05","06","07","08","09","10","11","12")
oListBox.addItems( sMonths, 0 )
oListBox.selectItemPos( Month(Date())-1, True )
REM expiration year
oListBox = oDialog.getControl("ListBox3")
For i = Year(Date()) To Year(Date()) + 4
iCount = oListBox.getItemCount()
oListBox.addItem( Str( i ), iCount )
Next i
oListBox.selectItemPos( 0, True )
End Sub
Sub CalculatePrize()
Dim oDialogModel As Object
Dim oListBox As Object
Dim oCheckBoxModel As Object
Dim oCurrencyFieldModel As Object
Dim Position As Integer
Dim sName As String
Dim i As Integer, nChecked As Integer
Dim Prizes As Variant
Dim Prize As Double
REM prizes for medium size pizzas
Prizes = Array( 4, 5, 6, 6, 7 )
REM get the position of the currently selected pizza
oListBox = oDialog.getControl("ListBox1")
Position = oListBox.getSelectedItemPos()
Prize = Prizes( Position )
REM small pizzas are 1€ cheaper, large pizzas are 1€ more expensive
oDialogModel = oDialog.Model
If oDialogModel.OptionButton1.State = 1 Then
Prize = Prize - 1
ElseIf oDialogModel.OptionButton3.State = 1 Then
Prize = Prize + 1
End If
REM get the number of extra toppings (0.5€ per extra topping)
For i = 0 To 3
sName = "CheckBox" + i
oCheckBoxModel = oDialogModel.getByName( sName )
If oCheckBoxModel.State = 1 Then
nChecked = nChecked + 1
End If
Next i
Prize = Prize + nChecked * 0.5
REM set the value of the currency field
oCurrencyFieldModel = oDialogModel.CurrencyField1
oCurrencyFieldModel.Value = Prize
End Sub
Sub PaymentMethodChanged()
Dim oDialogModel As Object
Dim bEnabled As Boolean
REM get dialog model
oDialogModel = oDialog.getModel()
If oDialogModel.OptionButton4.State = 1 Then
REM enable controls for payment by credit card
bEnabled = True
ElseIf oDialogModel.OptionButton5.State = 1 Then
REM disable controls for payment by check
bEnabled = False
End If
REM enable/disable controls
With oDialogModel
.Label11.Enabled = bEnabled
.Label12.Enabled = bEnabled
.Label13.Enabled = bEnabled
.ComboBox1.Enabled = bEnabled
.TextField6.Enabled = bEnabled
.ListBox2.Enabled = bEnabled
.ListBox3.Enabled = bEnabled
.TextField7.Enabled = bEnabled
End With
End Sub
Sub NextPage()
Dim oDialogModel As Object
REM get dialog model
oDialogModel = oDialog.getModel()
If oDialogModel.Step < 3 Then
REM next page
oDialogModel.Step = oDialogModel.Step + 1
REM enable/disable back button, set label of next button
PageChanged()
ElseIf oDialogModel.Step = 3 Then
REM submit order
SubmitOrder()
REM hide dialog
oDialog.endExecute()
End If
End Sub
Sub PreviousPage()
Dim oDialogModel As Object
REM get dialog model
oDialogModel = oDialog.getModel()
If oDialogModel.Step > 1 Then
REM previous page
oDialogModel.Step = oDialogModel.Step - 1
REM enable/disable back button, set label of next button
PageChanged()
End If
End Sub
Sub PageChanged()
Dim oDialogModel As Object
Dim oBackButtonModel As Object
Dim oNextButtonModel As Object
Const sLabelNext = "Next >>"
Const sLabelSubmit = "Submit"
REM get dialog model
oDialogModel = oDialog.getModel()
REM get back button model
oBackButtonModel = oDialogModel.getByName("BackButton")
REM enable/disable back button
If oDialogModel.Step = 1 Then
oBackButtonModel.Enabled = False
Else
oBackButtonModel.Enabled = True
End If
REM get next button model
oNextButtonModel = oDialogModel.getByName("NextButton")
REM set label of next button
If oDialogModel.Step = 3 Then
oNextButtonModel.Label = sLabelSubmit
Else
oNextButtonModel.Label = sLabelNext
End If
End Sub
Sub SubmitOrder()
MsgBox "Your pizza will be delivered in 45 minutes."
End Sub
</script:module>
|