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