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="HtmlAutoPilotBasic" script:language="StarBasic">&apos; Variables must be declared
4Option Explicit
5
6Public CurDocIndex as Integer
7Public CurWebPageIndex as Integer
8
9
10Public bWithBackGraphic as Boolean
11Public oStyle as Object
12&apos; Maximum number of content templates, style templates and bullets
13Const MaxLayouts = 50
14Const MaxStyles = 100
15Const MaxBullets = 10
16
17&apos;Public NumberOfLayouts%, NumberOfStyles%
18
19&apos; Filled with title, previous, next, home, top, bullet, background, file name
20Public Style(MaxStyles, 8) as String
21
22Public Layout$(MaxLayouts, 2)
23
24Public TextureDir$, BulletDir$, GraphicsDir$, GalleryDir$, PhotosDir$
25Public SOBitmapPath as String
26Public CurrentBullet$, CurrentPrev$, CurrentNext$, CurrentHome$, CurrentTop$
27Public FileStr as String
28
29Public WebWiz_gWizardName$, WebWiz_gErrContentNotFound$, WebWiz_gErrStyleNotFound$
30Public WebWiz_gErrMainTemplateError$, WebWiz_gErrWhileReloading$
31Public WebWiz_gErrWhileLoadStyles$, WebWiz_gErrMsg$, WebWiz_gErrMainDocumentError$
32
33Public ProgressBar as Object
34Public ProgressValue As Long
35Public oBaseDocument as Object
36Public oViewCursor as Object
37Public oViewSettings as Object
38Public NoArgs() as New com.sun.star.beans.PropertyValue
39
40Public oCursor as Object
41Public oBookmarks as Object
42Public oBookMark as Object
43
44Public oUcb as Object
45Public MainDialog as Object
46Public DialogModel as Object
47
48
49Sub Main
50Dim RetValue
51On Local Error Goto GlobalErrorHandler
52	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
53	oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
54	oBaseDocument = StarDesktop.LoadComponentFromURL(&quot;private:factory/swriter/web&quot;, &quot;_default&quot;, 0, NoArgs())
55	oViewSettings = oBaseDocument.CurrentController.ViewSettings
56	oViewCursor = oBaseDocument.GetCurrentController.ViewCursor
57	CurWebPageIndex = -1
58	ProgressBar = oBaseDocument.GetCurrentController.GetFrame.CreateStatusIndicator
59	ProgressBar.Start(&quot;&quot;, 100)
60	SetProgressValue(2)
61	oBaseDocument.LockControllers
62	oViewSettings.ShowTableBoundaries = False
63	If Not GetWebWizardPaths() Then
64		Exit Sub
65	End If
66	LoadLanguage
67	SetProgressValue(10)
68	Layout() = getListBoxArrays(oUcb, &quot;/cnt&quot;)
69	GetCurIndex(DialogModel, Layout(),2)
70	SetProgressValue(30)
71	oCursor = oBasedocument.Text.CreateTextCursor
72	oCursor.InsertDocumentfromURL(FileStr, NoArgs())
73	SetProgressValue(50)
74	Style() = getListBoxArrays(oUcb, &quot;/stl&quot;)
75	SetProgressValue(70)
76	LoadWebPageStyles(oBaseDocument)
77	SetProgressValue(90)
78	oBaseDocument.UnlockControllers
79	OpenWebDialog()
80	SetProgressValue(98)
81	SetProgressValue(0)
82	MainDialog.Model.ImagePreview.BackGroundColor = RGB(0, 60,126)
83	RetValue = MainDialog.Execute
84	Select Case RetValue
85		Case 0
86			MainDialog.Dispose()
87			DisposeDocument(oBaseDocument)
88		Case 1
89			EndDialog()
90			MainDialog.Dispose()
91	End Select
92GLOBALERRORHANDLER:
93	If Err &lt;&gt; 0 Then
94		MsgBox (WebWiz_gErrMsg$, 16, WebWiz_gWizardName$)
95		DisposeDocument(oBaseDocument)
96		RESUME EXITWIZARD
97EXITWIZARD:
98	End If
99End Sub
100
101
102Function SetProgressValue(iValue as Integer)
103	If iValue = 0 Then
104		ProgressBar.End
105	End If
106	ProgressValue = iValue
107	ProgressBar.Value = iValue
108End Function
109
110
111Sub ReloadCurrentDocument()
112Dim OldDocIndex as Integer
113On Local Error Goto ErrorOcurred
114	OldDocIndex = CurDocIndex
115	CurDocIndex = GetCurIndex(DialogModel.lbTemplate, Layout(), 2)
116	If OldDocIndex &lt;&gt; CurDocIndex Then
117		oBaseDocument.LockControllers
118		ToggleDialogControls(False)
119		oCursor = oBaseDocument.Text.CreateTextCursor()
120		oCursor.GotoStart(False)
121		oCursor.GotoEnd(True)
122		oCursor.SetAllPropertiesToDefault()
123		oCursor.InsertDocumentfromURL(FileStr, NoArgs())
124		SetBulletAndGraphics
125		CheckControls(oBaseDocument.DrawPage)
126	ErrorOcurred:
127		If Err &lt;&gt; 0 Then
128			MsgBox(WebWiz_gErrWhileReloading$, 16, WebWiz_gWizardName$)
129		End If
130		oBaseDocument.UnlockControllers
131		oViewCursor.GotoStart(False)
132		ToggleDialogControls(True, &quot;lbTemplate&quot;)
133	End If
134End Sub
135
136
137
138
139Sub LoadWebPageStyles(aEvent as Object, Optional bStartUp as Boolean)
140Dim OldWebPageIndex as Integer
141	OldWebPageIndex = CurWebPageIndex
142	If IsNull(DialogModel) Then
143		CurWebPageIndex = GetCurIndex(DialogModel, Style(), 8)
144	Else
145		CurWebPageIndex = GetCurIndex(DialogModel.lbStyles, Style(), 8)
146	End If
147	If OldWebPageIndex &lt;&gt; CurWebPageIndex Then
148		ToggleDialogControls(False)
149		oBaseDocument.LockControllers
150		bWithBackGraphic = LoadNewStyles(oBaseDocument, DialogModel, CurWebPageIndex, FileStr, Style(), TextureDir)
151		CurrentBullet$ = BulletDir + Style(CurWebPageIndex, 6)
152		CurrentPrev$ = GraphicsDir + Style(CurWebPageIndex, 2)
153		CurrentNext$ = GraphicsDir + Style(CurWebPageIndex, 3)
154		CurrentHome$ = GraphicsDir + Style(CurWebPageIndex, 4)
155		CurrentTop$ = GraphicsDir + Style(CurWebPageIndex, 5)
156		With oBaseDocument.DocumentProperties.UserDefinedProperties
157            .AutoPilotName1 = ExtractGraphicNames(CurWebPageIndex,2)
158            .AutoPilotName2 = ExtractGraphicNames(CurWebPageIndex, 4)
159            .AutoPilotBullet = Style(CurWebPageIndex, 6)
160            .AutoPilotBackground =  Style(CurWebPageIndex, 7)
161		End With
162		SetBulletAndGraphics()
163		CheckControls(oBaseDocument.DrawPage)
164		oViewCursor.GotoStart(False)
165		oBaseDocument.UnlockControllers
166		ToggleDialogControls(True, &quot;lbStyles&quot;)
167	End If
168End Sub
169
170
171Function ExtractGraphicNames(CurIndex as Integer, i as Integer) as String
172Dim FieldValue as String
173	FieldValue = GetFileNameWithoutExtension(Style(CurIndex, i))
174	FieldValue = FieldValue &amp; &quot; &quot; &amp;	GetFileNameWithoutExtension(Style(CurIndex, i+1))
175	ExtractGraphicNames = FieldValue
176End Function
177
178
179Sub SetBulletAndGraphics
180	SetGraphic(&quot;Prev&quot;, CurrentPrev)
181	SetGraphic(&quot;Next&quot;, CurrentNext)
182	SetGraphic(&quot;Home&quot;, CurrentHome)
183	SetGraphic(&quot;Top&quot;, CurrentTop)
184	SetBulletGraphics(CurrentBullet)
185	SetGraphicsToOriginalSize()
186End Sub
187
188
189Sub SetGraphicsToOriginalSize()
190Dim oGraphics as Object
191Dim oGraphic as Object
192Dim i as Integer
193Dim aActSize as New com.sun.star.awt.Size
194	oGraphics = oBaseDocument.GraphicObjects
195	For i = 0 To oGraphics.Count-1
196		oGraphic = oGraphics.GetByIndex(i)
197		aActSize = oGraphic.ActualSize
198		If aActSize.Height &gt; 0 And aActSize.Width &gt; 0 Then
199			oGraphic.SetSize(aActSize)
200		End If
201	Next i
202End Sub
203
204
205Sub EndDialog()
206	If DialogModel.chkSaveasTemplate.State = 1 Then
207		&apos; Generating template? Set events later!
208		AttachBasicMacroToEvent(oBaseDocument,&quot;OnNew&quot;, &quot;WebWizard.HtmlAutoPilotBasic.SetEvent()&quot;)
209		&apos; Call the Store template dialog
210		DispatchSlot(5538)
211		AttachBasicMacroToEvent(oBaseDocument,&quot;OnNew&quot;, &quot;&quot;)
212	End If
213	SetEvent()
214End Sub
215
216
217Sub SetEvent()
218Dim oDocument as Object
219&apos; This sub links the events OnSaveDone and OnSaveAsDone to the procedure
220&apos; CopyGraphics. It is invoked when a document is created, either directly
221&apos; from the AutoPilot or from a template. It is not possible to set these
222&apos; links for the template created by the AutoPilot because then it is not
223&apos; possible to modify the template.
224	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
225	oDocument = ThisComponent
226	AttachBasicMacroToEvent(oDocument,&quot;OnSaveDone&quot;, &quot;WebWizard.HtmlAutoPilotBasic.CopyGraphics()&quot;)
227	AttachBasicMacroToEvent(oDocument,&quot;OnSaveAsDone&quot;, &quot;WebWizard.HtmlAutoPilotBasic.CopyGraphics()&quot;)
228End Sub
229
230
231
232Sub CopyGraphics
233&apos; This sub copies all the graphics used in the document to the same directory the
234&apos; document has been copied into and changes the graphics links in the document.
235Dim oGraphicObjects as Object
236Dim oGraphic as Object
237Dim i as Integer
238Dim udProps as Object
239Dim SavePath as String
240    BasicLibraries.LoadLibrary(&quot;Tools&quot;)
241	oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
242	GetWebWizardPaths()
243	oBaseDocument = ThisComponent
244&apos;	oBaseDocument.LockControllers()
245
246	&apos; Note: The sub DirectoryNameoutofPath should be change, so that the last character is a slash
247	SavePath = DirectoryNameoutofPath(oBaseDocument.Url, &quot;/&quot;) &amp; &quot;/&quot;
248
249	oGraphicObjects = oBaseDocument.GraphicObjects
250	For i = 0 to oGraphicObjects.Count-1
251		oGraphic = oGraphicObjects.GetbyIndex(i)
252		oGraphic.GraphicUrl = CopyFile(oGraphic.GraphicURL, SavePath)
253	Next i
254
255	ChangeBackGraphicUrl(SavePath)
256
257	BulletUrlsToSavePath(SavePath)
258
259    udProps = oBaseDocument.DocumentProperties.UserDefinedProperties
260    udProps.addProperty(&quot;AutoPilotName1&quot;, 0, &quot;&quot;)
261    udProps.addProperty(&quot;AutoPilotName2&quot;, 0, &quot;&quot;)
262    udProps.addProperty(&quot;AutoPilotBullet&quot;, 0, &quot;&quot;)
263    udProps.addProperty(&quot;AutoPilotBackground&quot;, 0, &quot;&quot;)
264
265	AttachBasicMacroToEvent(oBaseDocument,&quot;OnSaveDone&quot;, &quot;&quot;)
266	AttachBasicMacroToEvent(oBaseDocument,&quot;OnSaveAsDone&quot;, &quot;&quot;)
267	AttachBasicMacroToEvent(oBaseDocument,&quot;OnNew&quot;, &quot;&quot;)
268	oBaseDocument.Store
269&apos;	oBaseDocument.UnlockControllers()
270End Sub
271
272
273Function CopyFile(ByVal SourceUrl as String, TargetDir as String)
274Dim sFileName as String
275Dim sNewFileUrl as String
276	If oUcb.Exists(TargetDir) Then
277		If Len(TargetDir) &gt; 2 Then
278			sFileName = FileNameoutofPath(SourceUrl)
279			sNewFileUrl = TargetDir &amp; sFileName
280			oUcb.Copy(SourceUrl, sNewFileUrl)
281			CopyFile() = sNewFileUrl
282		End If
283	End If
284End Function
285
286
287Function getListBoxArrays(oUcb as Object, sFileFilter as String)
288Dim oDocProps as Object
289Dim oListboxControl as Object
290Dim Description as String
291Dim sField as String
292Dim sFieldList() as String
293Dim bItemFound as Boolean
294Dim MaxIndex as Integer
295Dim DirContent() as String
296Dim FileName as String
297Dim TemplatePath as String
298Dim FilterLen as Integer
299Dim i as Integer
300Dim m as Integer
301Dim n as Integer
302Dim s as Integer
303Dim a as Integer
304Dim LocMaxIndex as Integer
305Dim Properties()
306Dim DimCount as Integer
307Dim sExtension as String
308	oDocProps = CreateUnoService(&quot;com.sun.star.document.DocumentProperties&quot;)
309	FilterLen = Len(sFileFilter)
310	bItemFound = False
311	&apos; It has to be made sure that the TemplatePath &lt;&gt; &quot;&quot;
312	TemplatePath = GetOfficeSubPath(&quot;Template&quot;, &quot;wizard/web/&quot;)
313	If TemplatePath = &quot;&quot; Then
314		Dim NullList()
315		getListBoxArrays() = NullList()
316		Exit Function
317	End If
318	DirContent() = oUcb.GetFolderContents(TemplatePath,True)
319	If sFileFilter = &quot;/cnt&quot; Then
320		DimCount = 2
321	Else
322		DimCount = 8
323	End If
324	LocMaxIndex = Ubound(DirContent())
325	Dim List(LocMaxIndex, DimCount) as String
326	Dim SortList(LocMaxIndex,1)
327	For i = 0 to LocMaxIndex
328		SortList(i,0) = DirContent(i)
329		SortList(i,1) = RetrieveDocTitle(oDocProps, DirContent(i))
330	Next i
331	SortList() = BubbleSortList(SortList(),True)
332	For i = 0 to LocMaxIndex
333		DirContent(i) = SortList(i,0)
334	Next i
335	a = 0
336	For i = 0 To LocMaxIndex
337		FileName = DirContent(i)
338		sExtension = Ucase(GetFileNameExtension(FileName))
339		If Instr(1,Filename, sFileFilter) And sExtension = &quot;STW&quot; Then
340			bItemFound = True
341			Description = RetrieveDocTitle(oDocProps, FileName)
342			Properties = oDocProps.UserDefinedProperties.PropertyValues
343			List(a,1) = Description
344			If sFileFilter = &quot;/cnt&quot; Then
345				List(a,2) = Filename
346			Else
347				m = 2
348				For n = 0 To 3
349					sField = Properties(n).Value
350					sFieldList() = ArrayoutofString(sField, &quot; &quot;, MaxIndex)
351					For s = 0 To MaxIndex
352						If m &lt; 6 Then
353					        List(a,m) = sFieldList(s) &amp; &quot;.gif&quot;
354						Else
355					        List(a,m) = sFieldList(s)
356						End If
357						m = m + 1
358					Next s
359				Next n
360				List(a,8) = FileName
361			End If
362			a = a + 1
363		End If
364	Next i
365	If sFileFilter = &quot;/cnt&quot; Then
366		ReDim Preserve List(a-1,2) as String
367	Else
368		ReDim Preserve List(a-1,8) as String
369	End If
370	If Not bItemfound Then
371		MsgBox(WebWiz_gErrContentNotFound$, 16, WebWiz_gWizardName$)
372		DisposeDocument(oBaseDocument)
373		Stop
374	End If
375	getListBoxArrays = List()
376End Function
377
378
379Sub SetGraphic(sWhich, sGraphicText as String)
380Dim oLocCursor as Object
381Dim oGraphic as Object
382Dim bGetGraphic as Boolean
383	oBookmarks = oBaseDocument.BookMarks
384	If oBookmarks.HasbyName(sWhich)Then
385		oBookMark = oBookmarks.GetbyName(sWhich)
386		oLocCursor = oBookMark.Anchor.Text.CreateTextCursorByRange(oBookMark.Anchor)
387		oGraphic = oBaseDocument.CreateInstance(&quot;com.sun.star.text.GraphicObject&quot;)
388		oLocCursor.GoRight(3,True)
389		oGraphic.AnchorType = 1
390		oGraphic.GraphicURL = ConverttoURL(sGraphicText)
391		oLocCursor.Text.InsertTextContent(oLocCursor, oGraphic, True)
392		oGraphic.Name = sWhich
393	ElseIf oBaseDocument.GraphicObjects.HasbyName(sWhich) Then
394		oGraphic = oBaseDocument.GraphicObjects.GetByName(sWhich)
395		oGraphic.GraphicUrl = sGraphicText
396	End If
397End Sub
398
399
400Sub CheckControls(oDrawPage as Object)
401Dim aForm as Object
402Dim m,n as integer
403Dim lColor as Long
404Dim oControl as Object
405	lColor = oBaseDocument.StyleFamilies.GetbyName(&quot;ParagraphStyles&quot;).GetByName(&quot;Standard&quot;).CharColor
406	&apos;SearchFor all possible Controls
407	For n = 0 to oDrawPage.Forms.Count - 1
408		aForm = oDrawPage.Forms(n)
409		For m = 0 to aForm.Count-1
410			oControl = aForm.GetbyIndex(m)
411			oControl.TextColor = lColor
412		Next
413	Next
414End Sub
415
416
417Sub RepaintHeaderPreview()
418Dim Bitmap As Object
419Dim sBitmapPath as String
420	sBitmapPath = SOBitmapPath &amp; &quot;webwizard.bmp&quot;
421	WebWzrd.ImagePreview.ImageURL = sBitmapPath
422End Sub
423
424
425Sub ToggleDialogControls(ByVal bDoEnable as Boolean, Optional FocusControlName as String)
426	If Not IsNull(DialogModel) Then
427		DialogModel.Enabled = bDoEnable
428		If bDoEnable Then
429			&apos; Enable Controls referring to Background graphic only when this Property is set
430			bDoEnable = bWithBackGraphic
431			ToggleOptionButtons(DialogModel, bDoEnable)
432			MainDialog.GetControl(FocusControlName).SetFocus()
433		End If
434	End If
435End Sub
436</script:module>
437