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