summaryrefslogtreecommitdiff
path: root/wizards/source/webwizard/HtmlAutoPilotBasic.xba
blob: 00675bbf0c747b96036e2fd51717c9702f0a36d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="HtmlAutoPilotBasic" script:language="StarBasic">&apos; Variables must be declared
Option Explicit

Public CurDocIndex as Integer
Public CurWebPageIndex as Integer


Public bWithBackGraphic as Boolean
Public oStyle as Object
&apos; Maximum number of content templates, style templates and bullets
Const MaxLayouts = 50
Const MaxStyles = 100
Const MaxBullets = 10

&apos;Public NumberOfLayouts%, NumberOfStyles%

&apos; Filled with title, previous, next, home, top, bullet, background, file name
Public Style(MaxStyles, 8) as String

Public Layout$(MaxLayouts, 2)

Public TextureDir$, BulletDir$, GraphicsDir$, GalleryDir$, PhotosDir$
Public SOBitmapPath as String
Public CurrentBullet$, CurrentPrev$, CurrentNext$, CurrentHome$, CurrentTop$
Public FileStr as String

Public WebWiz_gWizardName$, WebWiz_gErrContentNotFound$, WebWiz_gErrStyleNotFound$
Public WebWiz_gErrMainTemplateError$, WebWiz_gErrWhileReloading$
Public WebWiz_gErrWhileLoadStyles$, WebWiz_gErrMsg$, WebWiz_gErrMainDocumentError$

Public ProgressBar as Object
Public ProgressValue As Long
Public oBaseDocument as Object
Public oViewCursor as Object
Public oViewSettings as Object
Public NoArgs() as New com.sun.star.beans.PropertyValue

Public oCursor as Object
Public oBookmarks as Object
Public oBookMark as Object

Public oUcb as Object
Public MainDialog as Object
Public DialogModel as Object


Sub Main
Dim RetValue
On Local Error Goto GlobalErrorHandler
	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
	oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
	oBaseDocument = StarDesktop.LoadComponentFromURL(&quot;private:factory/swriter/web&quot;, &quot;_default&quot;, 0, NoArgs())
	oViewSettings = oBaseDocument.CurrentController.ViewSettings
	oViewCursor = oBaseDocument.GetCurrentController.ViewCursor
	CurWebPageIndex = -1
	ProgressBar = oBaseDocument.GetCurrentController.GetFrame.CreateStatusIndicator
	ProgressBar.Start(&quot;&quot;, 100)
	SetProgressValue(2)
	oBaseDocument.LockControllers
	oViewSettings.ShowTableBoundaries = False
	If Not GetWebWizardPaths() Then
		Exit Sub
	End If
	LoadLanguage
	SetProgressValue(10)
	Layout() = getListBoxArrays(oUcb, &quot;/cnt&quot;)
	GetCurIndex(DialogModel, Layout(),2)
	SetProgressValue(30)
	oCursor = oBasedocument.Text.CreateTextCursor
	oCursor.InsertDocumentfromURL(FileStr, NoArgs())
	SetProgressValue(50)
	Style() = getListBoxArrays(oUcb, &quot;/stl&quot;)
	SetProgressValue(70)
	LoadWebPageStyles(oBaseDocument)
	SetProgressValue(90)
	oBaseDocument.UnlockControllers
	OpenWebDialog()
	SetProgressValue(98)
	SetProgressValue(0)
	MainDialog.Model.ImagePreview.BackGroundColor = RGB(0, 60,126)
	RetValue = MainDialog.Execute
	Select Case RetValue
		Case 0
			MainDialog.Dispose()
			DisposeDocument(oBaseDocument)
		Case 1
			EndDialog()
			MainDialog.Dispose()
	End Select
GLOBALERRORHANDLER:
	If Err &lt;&gt; 0 Then
		MsgBox (WebWiz_gErrMsg$, 16, WebWiz_gWizardName$)
		DisposeDocument(oBaseDocument)
		RESUME EXITWIZARD
EXITWIZARD:
	End If
End Sub


Function SetProgressValue(iValue as Integer)
	If iValue = 0 Then
		ProgressBar.End
	End If
	ProgressValue = iValue
	ProgressBar.Value = iValue
End Function


Sub ReloadCurrentDocument()
Dim OldDocIndex as Integer
On Local Error Goto ErrorOcurred
	OldDocIndex = CurDocIndex
	CurDocIndex = GetCurIndex(DialogModel.lbTemplate, Layout(), 2)
	If OldDocIndex &lt;&gt; CurDocIndex Then
		oBaseDocument.LockControllers
		ToggleDialogControls(False)
		oCursor = oBaseDocument.Text.CreateTextCursor()
		oCursor.GotoStart(False)
		oCursor.GotoEnd(True)
		oCursor.SetAllPropertiesToDefault()
		oCursor.InsertDocumentfromURL(FileStr, NoArgs())
		SetBulletAndGraphics
		CheckControls(oBaseDocument.DrawPage)
	ErrorOcurred:
		If Err &lt;&gt; 0 Then
			MsgBox(WebWiz_gErrWhileReloading$, 16, WebWiz_gWizardName$)
		End If
		oBaseDocument.UnlockControllers
		oViewCursor.GotoStart(False)
		ToggleDialogControls(True, &quot;lbTemplate&quot;)
	End If
End Sub




Sub LoadWebPageStyles(aEvent as Object, Optional bStartUp as Boolean)
Dim OldWebPageIndex as Integer
	OldWebPageIndex = CurWebPageIndex
	If IsNull(DialogModel) Then
		CurWebPageIndex = GetCurIndex(DialogModel, Style(), 8)
	Else
		CurWebPageIndex = GetCurIndex(DialogModel.lbStyles, Style(), 8)
	End If
	If OldWebPageIndex &lt;&gt; CurWebPageIndex Then
		ToggleDialogControls(False)
		oBaseDocument.LockControllers
		bWithBackGraphic = LoadNewStyles(oBaseDocument, DialogModel, CurWebPageIndex, FileStr, Style(), TextureDir)
		CurrentBullet$ = BulletDir + Style(CurWebPageIndex, 6)
		CurrentPrev$ = GraphicsDir + Style(CurWebPageIndex, 2)
		CurrentNext$ = GraphicsDir + Style(CurWebPageIndex, 3)
		CurrentHome$ = GraphicsDir + Style(CurWebPageIndex, 4)
		CurrentTop$ = GraphicsDir + Style(CurWebPageIndex, 5)
		With oBaseDocument.DocumentProperties.UserDefinedProperties
            .AutoPilotName1 = ExtractGraphicNames(CurWebPageIndex,2)
            .AutoPilotName2 = ExtractGraphicNames(CurWebPageIndex, 4)
            .AutoPilotBullet = Style(CurWebPageIndex, 6)
            .AutoPilotBackground =  Style(CurWebPageIndex, 7)
		End With
		SetBulletAndGraphics()
		CheckControls(oBaseDocument.DrawPage)
		oViewCursor.GotoStart(False)
		oBaseDocument.UnlockControllers
		ToggleDialogControls(True, &quot;lbStyles&quot;)
	End If
End Sub


Function ExtractGraphicNames(CurIndex as Integer, i as Integer) as String
Dim FieldValue as String
	FieldValue = GetFileNameWithoutExtension(Style(CurIndex, i))
	FieldValue = FieldValue &amp; &quot; &quot; &amp;	GetFileNameWithoutExtension(Style(CurIndex, i+1))
	ExtractGraphicNames = FieldValue
End Function


Sub SetBulletAndGraphics
	SetGraphic(&quot;Prev&quot;, CurrentPrev)
	SetGraphic(&quot;Next&quot;, CurrentNext)
	SetGraphic(&quot;Home&quot;, CurrentHome)
	SetGraphic(&quot;Top&quot;, CurrentTop)
	SetBulletGraphics(CurrentBullet)
	SetGraphicsToOriginalSize()
End Sub


Sub SetGraphicsToOriginalSize()
Dim oGraphics as Object
Dim oGraphic as Object
Dim i as Integer
Dim aActSize as New com.sun.star.awt.Size
	oGraphics = oBaseDocument.GraphicObjects
	For i = 0 To oGraphics.Count-1
		oGraphic = oGraphics.GetByIndex(i)
		aActSize = oGraphic.ActualSize
		If aActSize.Height &gt; 0 And aActSize.Width &gt; 0 Then
			oGraphic.SetSize(aActSize)
		End If
	Next i
End Sub


Sub EndDialog()
	If DialogModel.chkSaveasTemplate.State = 1 Then
		&apos; Generating template? Set events later!
		AttachBasicMacroToEvent(oBaseDocument,&quot;OnNew&quot;, &quot;WebWizard.HtmlAutoPilotBasic.SetEvent()&quot;)
		&apos; Call the Store template dialog
		DispatchSlot(5538)
		AttachBasicMacroToEvent(oBaseDocument,&quot;OnNew&quot;, &quot;&quot;)
	End If
	SetEvent()
End Sub


Sub SetEvent()
Dim oDocument as Object
&apos; This sub links the events OnSaveDone and OnSaveAsDone to the procedure
&apos; CopyGraphics. It is invoked when a document is created, either directly
&apos; from the AutoPilot or from a template. It is not possible to set these
&apos; links for the template created by the AutoPilot because then it is not
&apos; possible to modify the template.
	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
	oDocument = ThisComponent
	AttachBasicMacroToEvent(oDocument,&quot;OnSaveDone&quot;, &quot;WebWizard.HtmlAutoPilotBasic.CopyGraphics()&quot;)
	AttachBasicMacroToEvent(oDocument,&quot;OnSaveAsDone&quot;, &quot;WebWizard.HtmlAutoPilotBasic.CopyGraphics()&quot;)
End Sub



Sub CopyGraphics
&apos; This sub copies all the graphics used in the document to the same directory the
&apos; document has been copied into and changes the graphics links in the document.
Dim oGraphicObjects as Object
Dim oGraphic as Object
Dim i as Integer
Dim udProps as Object
Dim SavePath as String
    BasicLibraries.LoadLibrary(&quot;Tools&quot;)
	oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
	GetWebWizardPaths()
	oBaseDocument = ThisComponent
&apos;	oBaseDocument.LockControllers()

	&apos; Note: The sub DirectoryNameoutofPath should be change, so that the last character is a slash
	SavePath = DirectoryNameoutofPath(oBaseDocument.Url, &quot;/&quot;) &amp; &quot;/&quot;

	oGraphicObjects = oBaseDocument.GraphicObjects
	For i = 0 to oGraphicObjects.Count-1
		oGraphic = oGraphicObjects.GetbyIndex(i)
		oGraphic.GraphicUrl = CopyFile(oGraphic.GraphicURL, SavePath)
	Next i

	ChangeBackGraphicUrl(SavePath)

	BulletUrlsToSavePath(SavePath)

    udProps = oBaseDocument.DocumentProperties.UserDefinedProperties
    udProps.addProperty(&quot;AutoPilotName1&quot;, 0, &quot;&quot;)
    udProps.addProperty(&quot;AutoPilotName2&quot;, 0, &quot;&quot;)
    udProps.addProperty(&quot;AutoPilotBullet&quot;, 0, &quot;&quot;)
    udProps.addProperty(&quot;AutoPilotBackground&quot;, 0, &quot;&quot;)

	AttachBasicMacroToEvent(oBaseDocument,&quot;OnSaveDone&quot;, &quot;&quot;)
	AttachBasicMacroToEvent(oBaseDocument,&quot;OnSaveAsDone&quot;, &quot;&quot;)
	AttachBasicMacroToEvent(oBaseDocument,&quot;OnNew&quot;, &quot;&quot;)
	oBaseDocument.Store
&apos;	oBaseDocument.UnlockControllers()
End Sub


Function CopyFile(ByVal SourceUrl as String, TargetDir as String)
Dim sFileName as String
Dim sNewFileUrl as String
	If oUcb.Exists(TargetDir) Then
		If Len(TargetDir) &gt; 2 Then
			sFileName = FileNameoutofPath(SourceUrl)
			sNewFileUrl = TargetDir &amp; sFileName
			oUcb.Copy(SourceUrl, sNewFileUrl)
			CopyFile() = sNewFileUrl
		End If
	End If
End Function


Function getListBoxArrays(oUcb as Object, sFileFilter as String)
Dim oDocProps as Object
Dim oListboxControl as Object
Dim Description as String
Dim sField as String
Dim sFieldList() as String
Dim bItemFound as Boolean
Dim MaxIndex as Integer
Dim DirContent() as String
Dim FileName as String
Dim TemplatePath as String
Dim FilterLen as Integer
Dim i as Integer
Dim m as Integer
Dim n as Integer
Dim s as Integer
Dim a as Integer
Dim LocMaxIndex as Integer
Dim Properties()
Dim DimCount as Integer
Dim sExtension as String
	oDocProps = CreateUnoService(&quot;com.sun.star.document.DocumentProperties&quot;)
	FilterLen = Len(sFileFilter)
	bItemFound = False
	&apos; It has to be made sure that the TemplatePath &lt;&gt; &quot;&quot;
	TemplatePath = GetOfficeSubPath(&quot;Template&quot;, &quot;wizard/web/&quot;)
	If TemplatePath = &quot;&quot; Then
		Dim NullList()
		getListBoxArrays() = NullList()
		Exit Function
	End If
	DirContent() = oUcb.GetFolderContents(TemplatePath,True)
	If sFileFilter = &quot;/cnt&quot; Then
		DimCount = 2
	Else
		DimCount = 8
	End If
	LocMaxIndex = Ubound(DirContent())
	Dim List(LocMaxIndex, DimCount) as String
	Dim SortList(LocMaxIndex,1)
	For i = 0 to LocMaxIndex
		SortList(i,0) = DirContent(i)
		SortList(i,1) = RetrieveDocTitle(oDocProps, DirContent(i))
	Next i
	SortList() = BubbleSortList(SortList(),True)
	For i = 0 to LocMaxIndex
		DirContent(i) = SortList(i,0)
	Next i
	a = 0
	For i = 0 To LocMaxIndex
		FileName = DirContent(i)
		sExtension = Ucase(GetFileNameExtension(FileName))
		If Instr(1,Filename, sFileFilter) And sExtension = &quot;STW&quot; Then
			bItemFound = True
			Description = RetrieveDocTitle(oDocProps, FileName)
			Properties = oDocProps.UserDefinedProperties.PropertyValues
			List(a,1) = Description
			If sFileFilter = &quot;/cnt&quot; Then
				List(a,2) = Filename
			Else
				m = 2
				For n = 0 To 3
					sField = Properties(n).Value
					sFieldList() = ArrayoutofString(sField, &quot; &quot;, MaxIndex)
					For s = 0 To MaxIndex
						If m &lt; 6 Then
					        List(a,m) = sFieldList(s) &amp; &quot;.gif&quot;
						Else
					        List(a,m) = sFieldList(s)
						End If
						m = m + 1
					Next s
				Next n
				List(a,8) = FileName
			End If
			a = a + 1
		End If
	Next i
	If sFileFilter = &quot;/cnt&quot; Then
		ReDim Preserve List(a-1,2) as String
	Else
		ReDim Preserve List(a-1,8) as String
	End If
	If Not bItemfound Then
		MsgBox(WebWiz_gErrContentNotFound$, 16, WebWiz_gWizardName$)
		DisposeDocument(oBaseDocument)
		Stop
	End If
	getListBoxArrays = List()
End Function


Sub SetGraphic(sWhich, sGraphicText as String)
Dim oLocCursor as Object
Dim oGraphic as Object
Dim bGetGraphic as Boolean
	oBookmarks = oBaseDocument.BookMarks
	If oBookmarks.HasbyName(sWhich)Then
		oBookMark = oBookmarks.GetbyName(sWhich)
		oLocCursor = oBookMark.Anchor.Text.CreateTextCursorByRange(oBookMark.Anchor)
		oGraphic = oBaseDocument.CreateInstance(&quot;com.sun.star.text.GraphicObject&quot;)
		oLocCursor.GoRight(3,True)
		oGraphic.AnchorType = 1
		oGraphic.GraphicURL = ConverttoURL(sGraphicText)
		oLocCursor.Text.InsertTextContent(oLocCursor, oGraphic, True)
		oGraphic.Name = sWhich
	ElseIf oBaseDocument.GraphicObjects.HasbyName(sWhich) Then
		oGraphic = oBaseDocument.GraphicObjects.GetByName(sWhich)
		oGraphic.GraphicUrl = sGraphicText
	End If
End Sub


Sub CheckControls(oDrawPage as Object)
Dim aForm as Object
Dim m,n as integer
Dim lColor as Long
Dim oControl as Object
	lColor = oBaseDocument.StyleFamilies.GetbyName(&quot;ParagraphStyles&quot;).GetByName(&quot;Standard&quot;).CharColor
	&apos;SearchFor all possible Controls
	For n = 0 to oDrawPage.Forms.Count - 1
		aForm = oDrawPage.Forms(n)
		For m = 0 to aForm.Count-1
			oControl = aForm.GetbyIndex(m)
			oControl.TextColor = lColor
		Next
	Next
End Sub


Sub RepaintHeaderPreview()
Dim Bitmap As Object
Dim sBitmapPath as String
	sBitmapPath = SOBitmapPath &amp; &quot;webwizard.bmp&quot;
	WebWzrd.ImagePreview.ImageURL = sBitmapPath
End Sub


Sub ToggleDialogControls(ByVal bDoEnable as Boolean, Optional FocusControlName as String)
	If Not IsNull(DialogModel) Then
		DialogModel.Enabled = bDoEnable
		If bDoEnable Then
			&apos; Enable Controls referring to Background graphic only when this Property is set
			bDoEnable = bWithBackGraphic
			ToggleOptionButtons(DialogModel, bDoEnable)
			MainDialog.GetControl(FocusControlName).SetFocus()
		End If
	End If
End Sub
</script:module>