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