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