xref: /trunk/main/odk/examples/DevelopersGuide/BasicAndDialogs/ToolkitControls/ToolkitControls/MultiPage.xba (revision ffd38472365e95f6a578737bc9a5eb0fac624a86)
1<?xml version="1.0" encoding="UTF-8"?>
2<!--***********************************************************
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements.  See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership.  The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License.  You may obtain a copy of the License at
11 *
12 *   http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied.  See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 *
21 ***********************************************************-->
22<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="MultiPage" script:language="StarBasic">REM  *****  BASIC  *****
24
25Dim oDialog As Object
26
27Sub Main()
28
29    Dim oLibContainer As Object, oLib As Object
30    Dim oInputStreamProvider As Object
31    Dim oDialogModel As Object
32
33    Const sLibName = &quot;ToolkitControls&quot;
34    Const sDialogName = &quot;MultiPageDlg&quot;
35
36    REM load/get library and input stream provider
37    oLibContainer = DialogLibraries
38    oLibContainer.loadLibrary( sLibName )
39    oLib = oLibContainer.getByName( sLibName )
40    oInputStreamProvider = oLib.getByName( sDialogName )
41
42    REM create dialog control
43    oDialog = CreateUnoDialog( oInputStreamProvider )
44
45    REM initialize dialog and controls
46    Initialize()
47
48    REM show the dialog
49    oDialog.execute()
50
51End Sub
52
53
54Sub Initialize()
55
56    Dim oDialogModel As Object
57    Dim oNextButton As Object, oNextButtonModel As Object
58    Dim oListBox As Object
59    Dim oCheckBoxModel As Object
60    Dim oOptionButtonModel As Object
61    Dim oCurrencyFieldModel As Object
62    Dim oNumericFieldModel As Object
63    Dim oComboBox As Object, oComboBoxModel As Object
64    Dim i As Integer
65    Dim sName As String
66    Dim sPizzas As Variant, sToppings As Variant
67    Dim sCreditCards As Variant
68    Dim sMonths As Variant
69    Dim iCount As Integer
70
71    REM dialog properties
72    oDialogModel = oDialog.Model
73    oDialogModel.Step = 1
74
75    REM next button properties
76    oNextButtonModel = oDialogModel.NextButton
77    oNextButtonModel.DefaultButton = True
78    oNextButton = oDialog.getControl(&quot;NextButton&quot;)
79    oNextButton.setFocus()
80
81    REM enable/disable back button, set label of next button
82    PageChanged()
83
84    REM set control properties on dialog page 1
85
86    REM pizzas in list box
87    oListBox = oDialog.getControl(&quot;ListBox1&quot;)
88    sPizzas = Array(&quot;Margarita&quot;,&quot;Vegeterian&quot;,&quot;Ham &amp; Pineapple&quot;,&quot;Mexican&quot;,&quot;Seafood&quot;)
89    oListBox.addItems( sPizzas, 0 )
90    oListBox.selectItem( sPizzas(0), True )
91
92    REM extra toppings
93    sToppings = Array(&quot;Extra Cheese&quot;,&quot;Corn&quot;,&quot;Onions&quot;,&quot;Olives&quot;)
94    For i = 0 To 3
95        sName = &quot;CheckBox&quot; + i
96        oCheckBoxModel = oDialogModel.getByName( sName )
97        oCheckBoxModel.Label = sToppings( i )
98    Next i
99
100    REM default pizza size
101    oOptionButtonModel = oDialogModel.OptionButton2
102    oOptionButtonModel.State = True
103
104    REM currency field properties
105    oCurrencyFieldModel = oDialogModel.CurrencyField1
106    oCurrencyFieldModel.ReadOnly = True
107    oCurrencyFieldModel.DecimalAccuracy = 2
108    oCurrencyFieldModel.CurrencySymbol = &quot;€&quot;
109    oCurrencyFieldModel.PrependCurrencySymbol = True
110
111    REM calculate prize for default settings
112    CalculatePrize()
113
114    REM set control properties on dialog page 2
115
116    REM numeric field properties
117    oNumericFieldModel = oDialogModel.NumericField1
118    oNumericFieldModel.DecimalAccuracy = 0
119
120    REM set control properties on dialog page 3
121
122    REM default payment method
123    oOptionButtonModel = oDialogModel.OptionButton4
124    oOptionButtonModel.State = True
125
126    REM credit cards in combo box
127    oComboBox = oDialog.getControl(&quot;ComboBox1&quot;)
128    sCreditCards = Array(&quot;Visa&quot;,&quot;Master/EuroCard&quot;,&quot;American Express&quot;)
129    oComboBox.addItems( sCreditCards, 0 )
130    oComboBoxModel = oDialogModel.ComboBox1
131    oComboBoxModel.Text = sCreditCards(0)
132
133    REM expiration month
134    oListBox = oDialog.getControl(&quot;ListBox2&quot;)
135    sMonths = Array(&quot;01&quot;,&quot;02&quot;,&quot;03&quot;,&quot;04&quot;,&quot;05&quot;,&quot;06&quot;,&quot;07&quot;,&quot;08&quot;,&quot;09&quot;,&quot;10&quot;,&quot;11&quot;,&quot;12&quot;)
136    oListBox.addItems( sMonths, 0 )
137    oListBox.selectItemPos( Month(Date())-1, True )
138
139    REM expiration year
140    oListBox = oDialog.getControl(&quot;ListBox3&quot;)
141    For i = Year(Date()) To Year(Date()) + 4
142        iCount = oListBox.getItemCount()
143        oListBox.addItem( Str( i ), iCount )
144    Next i
145    oListBox.selectItemPos( 0, True )
146
147End Sub
148
149
150Sub CalculatePrize()
151
152    Dim oDialogModel As Object
153    Dim oListBox As Object
154    Dim oCheckBoxModel As Object
155    Dim oCurrencyFieldModel As Object
156    Dim Position As Integer
157    Dim sName As String
158    Dim i As Integer, nChecked As Integer
159    Dim Prizes As Variant
160    Dim Prize As Double
161
162    REM prizes for medium size pizzas
163    Prizes = Array( 4, 5, 6, 6, 7 )
164
165    REM get the position of the currently selected pizza
166    oListBox = oDialog.getControl(&quot;ListBox1&quot;)
167    Position = oListBox.getSelectedItemPos()
168    Prize = Prizes( Position )
169
170    REM small pizzas are 1€ cheaper, large pizzas are 1€ more expensive
171    oDialogModel = oDialog.Model
172    If oDialogModel.OptionButton1.State = 1 Then
173        Prize = Prize - 1
174    ElseIf oDialogModel.OptionButton3.State = 1 Then
175        Prize = Prize + 1
176    End If
177
178    REM get the number of extra toppings (0.5€ per extra topping)
179    For i = 0 To 3
180        sName = &quot;CheckBox&quot; + i
181        oCheckBoxModel = oDialogModel.getByName( sName )
182        If oCheckBoxModel.State = 1 Then
183            nChecked = nChecked + 1
184        End If
185    Next i
186    Prize = Prize + nChecked * 0.5
187
188    REM set the value of the currency field
189    oCurrencyFieldModel = oDialogModel.CurrencyField1
190    oCurrencyFieldModel.Value = Prize
191
192End Sub
193
194
195Sub PaymentMethodChanged()
196
197    Dim oDialogModel As Object
198    Dim bEnabled As Boolean
199
200    REM get dialog model
201    oDialogModel = oDialog.getModel()
202
203    If oDialogModel.OptionButton4.State = 1 Then
204        REM enable controls for payment by credit card
205        bEnabled = True
206    ElseIf oDialogModel.OptionButton5.State = 1 Then
207        REM disable controls for payment by check
208        bEnabled = False
209    End If
210
211    REM enable/disable controls
212    With oDialogModel
213        .Label11.Enabled = bEnabled
214        .Label12.Enabled = bEnabled
215        .Label13.Enabled = bEnabled
216        .ComboBox1.Enabled = bEnabled
217        .TextField6.Enabled = bEnabled
218        .ListBox2.Enabled = bEnabled
219        .ListBox3.Enabled = bEnabled
220        .TextField7.Enabled = bEnabled
221    End With
222
223End Sub
224
225
226Sub NextPage()
227
228    Dim oDialogModel As Object
229
230    REM get dialog model
231    oDialogModel = oDialog.getModel()
232
233    If oDialogModel.Step &lt; 3 Then
234        REM next page
235        oDialogModel.Step = oDialogModel.Step + 1
236        REM enable/disable back button, set label of next button
237        PageChanged()
238    ElseIf oDialogModel.Step = 3 Then
239        REM submit order
240        SubmitOrder()
241        REM hide dialog
242        oDialog.endExecute()
243    End If
244
245End Sub
246
247
248Sub PreviousPage()
249
250    Dim oDialogModel As Object
251
252    REM get dialog model
253    oDialogModel = oDialog.getModel()
254
255    If oDialogModel.Step &gt; 1 Then
256        REM previous page
257        oDialogModel.Step = oDialogModel.Step - 1
258        REM enable/disable back button, set label of next button
259        PageChanged()
260    End If
261
262End Sub
263
264
265Sub PageChanged()
266
267    Dim oDialogModel As Object
268    Dim oBackButtonModel As Object
269    Dim oNextButtonModel As Object
270
271    Const sLabelNext = &quot;Next &gt;&gt;&quot;
272    Const sLabelSubmit = &quot;Submit&quot;
273
274    REM get dialog model
275    oDialogModel = oDialog.getModel()
276
277    REM get back button model
278    oBackButtonModel = oDialogModel.getByName(&quot;BackButton&quot;)
279
280    REM enable/disable back button
281    If oDialogModel.Step = 1 Then
282        oBackButtonModel.Enabled = False
283    Else
284        oBackButtonModel.Enabled = True
285    End If
286
287    REM get next button model
288    oNextButtonModel = oDialogModel.getByName(&quot;NextButton&quot;)
289
290    REM set label of next button
291    If oDialogModel.Step = 3 Then
292        oNextButtonModel.Label = sLabelSubmit
293    Else
294        oNextButtonModel.Label = sLabelNext
295    End If
296
297End Sub
298
299
300Sub SubmitOrder()
301
302    MsgBox &quot;Your pizza will be delivered in 45 minutes.&quot;
303
304End Sub
305
306</script:module>
307