1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<!--***********************************************************
4 *
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements.  See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership.  The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License.  You may obtain a copy of the License at
12 *
13 *   http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied.  See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 *
22 ***********************************************************-->
23<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Switch" script:language="StarBasic">REM  *****  BASIC  *****
24
25Dim oDialog AS Object
26Dim document AS Object
27
28Sub Main
29End Sub
30
31Sub InsertSwitch
32	InsertSwitchTag(FALSE)
33End Sub
34
35Sub InsertSwitchInline
36	InsertSwitchTag(TRUE)
37End Sub
38
39Sub InsertSwitchTag(bInline As Boolean)
40	document = StarDesktop.CurrentComponent
41	Dim oCur as Object
42
43	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
44
45	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgSwitch&quot;)
46	oDialogModel = oDialog.Model
47
48	oOptSys = oDialog.GetControl(&quot;opSwitchSystem&quot;)
49	oOptAppl = oDialog.GetControl(&quot;opSwitchAppl&quot;)
50	oOptDistrib = oDialog.GetControl(&quot;opSwitchDistrib&quot;)
51
52	If oDialog.Execute() = 1 Then
53		If oOptSys.State Then
54			sType = &quot;sys&quot;
55		ElseIf oOptAppl.State Then
56			sType = &quot;appl&quot;
57		ElseIf oOptDistrib.State Then
58			sType = &quot;distrib&quot;
59		End If
60	Else
61	End If
62	oDialog.Dispose
63
64	If bInline Then
65		oSel = thiscomponent.getcurrentcontroller.getselection
66		oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
67
68		oStart = oCur.getStart
69		oCurStart = oStart.getText.createTextCursorByRange(oStart)
70
71		oEnd = oCur.getEnd
72		oCurEnd = oEnd.getText.createTextCursorByRange(oEnd)
73
74		thiscomponent.getcurrentcontroller.select(oCurStart)
75		InsertTag(&quot;SWITCHINLINE_&quot;,&quot;&lt;SWITCHINLINE select=&quot;&quot;&quot; + sType + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_switch&quot;)
76		InsertCase(sType,TRUE,oCur)
77		thiscomponent.getcurrentcontroller.select(oCurEnd)
78		CloseSwitchInline
79		GoLeft(1)
80	Else
81		CR_before
82		GoUp(1)
83		SetParaStyle(&quot;hlp_aux_switch&quot;)
84		InsertTag(&quot;SWITCH_&quot;,&quot;&lt;SWITCH select=&quot;&quot;&quot; + sType + &quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_switch&quot;)
85		GoLeft(1)
86		GoDown(1)
87		SetCharStyle(&quot;Default&quot;)
88		CloseSwitch
89		GoUp(1)
90		InsertCase(sType,FALSE,oCur)
91	End If
92End Sub
93
94Sub InsertCaseElement
95	document = StarDesktop.CurrentComponent
96	Dim oCur as Object
97	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
98
99	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgSwitch&quot;)
100	oDialogModel = oDialog.Model
101
102	oOptSys = oDialog.GetControl(&quot;opSwitchSystem&quot;)
103	oOptAppl = oDialog.GetControl(&quot;opSwitchAppl&quot;)
104	oOptDistrib = oDialog.GetControl(&quot;opSwitchDistrib&quot;)
105
106	If oDialog.Execute() = 1 Then
107		If oOptSys.State Then
108			sType = &quot;sys&quot;
109		ElseIf oOptAppl.State Then
110			sType = &quot;appl&quot;
111		ElseIf oOptDistrib.State Then
112			sType = &quot;distrib&quot;
113		End If
114	Else
115	End If
116	oDialog.Dispose
117
118	InsertCase(sType,FALSE,oCur)
119
120End Sub
121
122Sub InsertDefaultElement
123	document = StarDesktop.CurrentComponent
124	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
125
126	InsertDefault
127End Sub
128
129Sub InsertCaseInlineElement
130	document = StarDesktop.CurrentComponent
131	Dim oCur as Object
132	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
133
134	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgSwitch&quot;)
135	oDialogModel = oDialog.Model
136
137	oOptSys = oDialog.GetControl(&quot;opSwitchSystem&quot;)
138	oOptAppl = oDialog.GetControl(&quot;opSwitchAppl&quot;)
139	oOptDistrib = oDialog.GetControl(&quot;opSwitchDistrib&quot;)
140
141	If oDialog.Execute() = 1 Then
142		If oOptSys.State Then
143			sType = &quot;sys&quot;
144		ElseIf oOptAppl.State Then
145			sType = &quot;appl&quot;
146		ElseIf oOptDistrib.State Then
147			sType = &quot;distrib&quot;
148		End If
149	Else
150	End If
151	oDialog.Dispose
152
153	oSel = thiscomponent.getcurrentcontroller.getselection
154	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
155
156	oStart = oCur.getStart
157	oCurStart = oStart.getText.createTextCursorByRange(oStart)
158
159	oEnd = oCur.getEnd
160	oCurEnd = oEnd.getText.createTextCursorByRange(oEnd)
161
162	InsertCase(sType,TRUE,oCur)
163	GoLeft(1)
164End Sub
165
166Sub InsertDefaultInlineElement
167	document = StarDesktop.CurrentComponent
168	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
169
170	oSel = thiscomponent.getcurrentcontroller.getselection
171	oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
172
173	oStart = oCur.getStart
174	oCurStart = oStart.getText.createTextCursorByRange(oStart)
175
176	oEnd = oCur.getEnd
177	oCurEnd = oEnd.getText.createTextCursorByRange(oEnd)
178
179	InsertDefaultInline(oCur)
180	GoLeft(1)
181End Sub
182
183
184Sub InsertCaseSys
185	InsertCase(&quot;sys&quot;,FALSE)
186End Sub
187
188Sub InsertCaseAppl
189	InsertCase(&quot;appl&quot;,FALSE)
190End Sub
191
192Sub InsertCaseDistrib
193	InsertCase(&quot;distrib&quot;,FALSE)
194End Sub
195
196Sub InsertCaseInlineSys
197	InsertCase(&quot;sys&quot;,TRUE)
198End Sub
199
200Sub InsertCaseInlineAppl
201	InsertCase(&quot;appl&quot;,TRUE)
202End Sub
203
204Sub InsertCaseInlineDistrib
205	InsertCase(&quot;distrib&quot;,TRUE)
206End Sub
207
208Sub InsertDefaultInline(oCur as Object)
209	oSel = thiscomponent.getcurrentcontroller.getselection
210	&apos;oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
211
212	oStart = oCur.getStart
213	oCurStart = oStart.getText.createTextCursorByRange(oStart)
214
215	oEnd = oCur.getEnd
216	oCurEnd = oEnd.getText.createTextCursorByRange(oEnd)
217
218	thiscomponent.getcurrentcontroller.select(oCurStart)
219	InsertTag(&quot;DEFAULTINLINE_&quot;,&quot;&lt;DEFAULTINLINE&gt;&quot;)
220
221	thiscomponent.getcurrentcontroller.select(oCurEnd)
222	InsertTag(&quot;_DEFAULTINLINE&quot;,&quot;&lt;/DEFAULTINLINE&gt;&quot;)
223End Sub
224
225Sub InsertCase(sType As String, bInline As Boolean,oCur As Object)
226	document = StarDesktop.CurrentComponent
227
228	BasicLibraries.LoadLibrary(&quot;HelpAuthoring&quot;)
229	oDialog = LoadDialog(&quot;HelpAuthoring&quot;, &quot;dlgCase&quot;)
230	oDialogModel = oDialog.Model
231
232	oOptPredefined = oDialog.GetControl(&quot;opPredefined&quot;)
233	oCbPredefined = oDialog.GetControl(&quot;cbPredefined&quot;)
234	oOptSpecify = oDialog.GetControl(&quot;opSpecify&quot;)
235	oTxtSpecify = oDialog.GetControl(&quot;txtSpecify&quot;)
236	oTxtSpecify.setVisible(FALSE)
237
238	If sType = &quot;sys&quot; Then
239		arItems = Array(&quot;WIN&quot;,&quot;UNIX&quot;,&quot;MAC&quot;)
240	ElseIf sType = &quot;appl&quot; Then
241		arItems = Array(&quot;CALC&quot;,&quot;CHART&quot;,&quot;DRAW&quot;,&quot;IMPRESS&quot;,&quot;MATH&quot;,&quot;WRITER&quot;,&quot;BASIC&quot;)
242	ElseIf sType = &quot;distrib&quot; Then
243		arItems = Array(&quot;OPENSOURCE&quot;,&quot;COMMERCIAL&quot;)
244	Else
245		msgbox &quot;Unknown Case. Go tell Frank about this&quot;,0,&quot;D&apos;oh!&quot;
246		Exit Sub
247	End If
248
249	oCbPredefined.AddItems(arItems,ubound(arItems))
250	oCbPredefined.SetText(arItems(0))
251
252	If oDialog.Execute() = 1 Then
253
254		If oOptPredefined.State Then
255			sSelect = oCbPredefined.GetText
256		Else
257			sSelect = oTxtSpecify.Text
258		End If
259
260		If bInline Then
261			oSel = thiscomponent.getcurrentcontroller.getselection
262			&apos;oCur = oSel(0).getText.createTextCursorByRange(oSel(0))
263
264			oStart = oCur.getStart
265			oCurStart = oStart.getText.createTextCursorByRange(oStart)
266
267			oEnd = oCur.getEnd
268			oCurEnd = oEnd.getText.createTextCursorByRange(oEnd)
269
270			thiscomponent.getcurrentcontroller.select(oCurStart)
271			InsertTag(&quot;CASEINLINE_&quot;,&quot;&lt;CASEINLINE select=&quot;&quot;&quot;+sSelect+&quot;&quot;&quot;&gt;&quot;)
272
273			thiscomponent.getcurrentcontroller.select(oCurEnd)
274			InsertTag(&quot;_CASEINLINE&quot;,&quot;&lt;/CASEINLINE&gt;&quot;)
275		Else
276			CR_before
277			GoUp(1)
278			SetParaStyle(&quot;hlp_aux_switch&quot;)
279			InsertTag(&quot;CASE_&quot;,&quot;&lt;CASE select=&quot;&quot;&quot; + sSelect+&quot;&quot;&quot;&gt;&quot;,&quot;hlp_aux_switch&quot;)
280			GoLeft(1)
281			GoDown(1)
282			SetCharStyle(&quot;Default&quot;)
283			CloseCase
284			GoUp(1)
285		End If
286	End If
287	oDialog.dispose
288End Sub
289
290Sub StatusChange
291	oOptPredefined = oDialog.GetControl(&quot;opPredefined&quot;)
292	oCbPredefined = oDialog.GetControl(&quot;cbPredefined&quot;)
293	oOptSpecify = oDialog.GetControl(&quot;opSpecify&quot;)
294	oTxtSpecify = oDialog.GetControl(&quot;txtSpecify&quot;)
295
296	If oOptPredefined.State Then
297		oCbPredefined.setVisible(TRUE)
298		oTxtSpecify.setVisible(FALSE)
299	ElseIf oOptSpecify.State Then
300		oCbPredefined.setVisible(FALSE)
301		oTxtSpecify.setVisible(TRUE)
302	End If
303End Sub
304
305Sub CloseCase
306	CR
307	SetParaStyle(&quot;hlp_aux_switch&quot;)
308	InsertTag(&quot;_CASE&quot;,&quot;&lt;/CASE&gt;&quot;,&quot;hlp_aux_switch&quot;)
309End Sub
310
311Sub InsertDefault
312	CR_before
313	GoUp(1)
314	SetParaStyle(&quot;hlp_aux_switch&quot;)
315	InsertTag(&quot;DEFAULT_&quot;,&quot;&lt;DEFAULT&gt;&quot;,&quot;hlp_aux_switch&quot;)
316	GoLeft(1)
317	GoDown(1)
318	SetCharStyle(&quot;Default&quot;)
319	CloseDefault
320	GoUp(1)
321End Sub
322
323Sub CloseDefault
324	CR
325	SetParaStyle(&quot;hlp_aux_switch&quot;)
326	InsertTag(&quot;_DEFAULT&quot;,&quot;&lt;/DEFAULT&gt;&quot;,&quot;hlp_aux_switch&quot;)
327End Sub
328
329Sub CloseSwitch
330	CR
331	SetParaStyle(&quot;hlp_aux_switch&quot;)
332	InsertTag(&quot;_SWITCH&quot;,&quot;&lt;/SWITCH&gt;&quot;,&quot;hlp_aux_switch&quot;)
333End Sub
334
335Sub CloseSwitchInline
336	InsertTag(&quot;_SWITCHINLINE&quot;,&quot;&lt;/SWITCHINLINE&gt;&quot;)
337End Sub
338</script:module>
339