summaryrefslogtreecommitdiff
path: root/odk/examples/DevelopersGuide/BasicAndDialogs/ToolkitControls/ToolkitControls/MultiPage.xba
blob: 3a95715819836b376bd157425025530b9d597b1b (plain)
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
<?xml version="1.0" encoding="UTF-8"?>
<!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 = &quot;ToolkitControls&quot;
	Const sDialogName = &quot;MultiPageDlg&quot;

	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(&quot;NextButton&quot;)
	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(&quot;ListBox1&quot;)
	sPizzas = Array(&quot;Margarita&quot;,&quot;Vegeterian&quot;,&quot;Ham &amp; Pineapple&quot;,&quot;Mexican&quot;,&quot;Seafood&quot;)		
	oListBox.addItems( sPizzas, 0 )
	oListBox.selectItem( sPizzas(0), True )

	REM extra toppings 
	sToppings = Array(&quot;Extra Cheese&quot;,&quot;Corn&quot;,&quot;Onions&quot;,&quot;Olives&quot;)	
	For i = 0 To 3
	    sName = &quot;CheckBox&quot; + 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 = &quot;€&quot;
	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(&quot;ComboBox1&quot;)
	sCreditCards = Array(&quot;Visa&quot;,&quot;Master/EuroCard&quot;,&quot;American Express&quot;)
	oComboBox.addItems( sCreditCards, 0 )
	oComboBoxModel = oDialogModel.ComboBox1	
	oComboBoxModel.Text = sCreditCards(0)	
	
	REM expiration month			
	oListBox = oDialog.getControl(&quot;ListBox2&quot;)
	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;)	
	oListBox.addItems( sMonths, 0 )
	oListBox.selectItemPos( Month(Date())-1, True )

	REM expiration year
	oListBox = oDialog.getControl(&quot;ListBox3&quot;)	
	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(&quot;ListBox1&quot;)
	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 = &quot;CheckBox&quot; + 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 &lt; 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 &gt; 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 = &quot;Next &gt;&gt;&quot;
	Const sLabelSubmit = &quot;Submit&quot;

	REM get dialog model
	oDialogModel = oDialog.getModel()

	REM get back button model
	oBackButtonModel = oDialogModel.getByName(&quot;BackButton&quot;)

	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(&quot;NextButton&quot;)

	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 &quot;Your pizza will be delivered in 45 minutes.&quot;

End Sub

</script:module>