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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
|
<?xml version="1.0" encoding="UTF-8"?>
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="HtmlAutoPilotBasic" script:language="StarBasic">' Variables must be declared
Option Explicit
' Maximum number of content templates, style templates and bullets
Const MaxLayouts = 50
Const MaxStyles = 100
Const MaxBullets = 10
Public NumberOfLayouts%, NumberOfStyles%
' Filled with title, previous, next, home, top, bullet, background, file name
Public Style(8, MaxStyles) as String
' Filled with title, file name
Public Layout$(2, MaxLayouts%)
Public TextureDir$, BulletDir$, GraphicsDir$, GalleryDir$, PhotosDir$
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
'On Local Error Goto GlobalErrorHandler
BasicLibraries.LoadLibrary("Tools")
oUcb = createUnoService("com.sun.star.ucb.SimpleFileAccess")
oBaseDocument = StarDesktop.LoadComponentFromURL("private:factory/swriter/web", "_blank", 0, NoArgs())
oViewSettings = oBaseDocument.CurrentController.ViewSettings
oViewCursor = oBaseDocument.GetCurrentController.ViewCursor
ProgressBar = oBaseDocument.GetCurrentController.GetFrame.CreateStatusIndicator
ProgressBar.Start("", 100)
SetProgressValue(2)
oBaseDocument.LockControllers
oViewSettings.ShowTableBoundaries = False
oViewSettings.ShowTextBoundaries = False
MainDialog = LoadDialog("WebWizard","WebWzrd")
DialogModel = MainDialog.Model
LoadLanguage
SetProgressValue(10)
GetPaths()
NumberofLayouts = FillupWebListbox(oUcb, "/cnt", MainDialog, "lbTemplate", Layout$())
SetProgressValue(30)
GetCurIndex(DialogModel.lbTemplate, Layout(),NumberofLayouts,2)
oCursor = oBasedocument.Text.CreateTextCursor
oCursor.InsertDocumentfromURL(FileStr, NoArgs())
SetProgressValue(40)
DialogModel.optTiled.State = 1
NumberofStyles = FillupWebListbox(oUcb, "/stl", MainDialog, "lbStyles", Style())
SetProgressValue(50)
LoadWebPageStyles(oBaseDocument)
SetProgressValue(98)
SetProgressValue(0)
oBaseDocument.UnlockControllers
MainDialog.Execute
GLOBALERRORHANDLER:
If Err <> 0 Then
MsgBox (WebWiz_gErrMsg$, 16, WebWiz_gWizardName$)
CancelHTMLWizard()
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 CurInd as Integer
'On Local Error Goto ErrorOcurred
' Todo:Check if the pointer is really disabled, when set to Hourglass
ToggleWindow(False)
oBaseDocument.LockControllers
' Get selected list entry and corresponding file name
CurInd = GetCurIndex(DialogModel.lbTemplate, Layout$(), NumberofLayouts%, 2)
oCursor = oBaseDocument.Text.CreateTextCursor
oCursor.GotoStart(False)
oCursor.GotoEnd(True)
oCursor.InsertDocumentfromURL(FileStr, NoArgs())
SetBulletAndGraphics
CheckControls(oBaseDocument.DrawPage)
ErrorOcurred:
If Err <> 0 Then
MsgBox(WebWiz_gErrWhileReloading$, 16, WebWiz_gWizardName$)
End If
oBaseDocument.UnlockControllers
oViewCursor.GotoStart(False)
ToggleWindow(True)
End Sub
Sub LoadWebPageStyles()
Dim CurIndex as Integer
ToggleWindow(False)
oBaseDocument.LockControllers
CurIndex = GetCurIndex(DialogModel.lbStyles, Style(), NumberofStyles%,8)
LoadNewStyles(oBaseDocument, DialogModel, CurIndex, FileStr, Style(), TextureDir)
CurrentBullet$ = BulletDir + Style(6, CurIndex)
CurrentPrev$ = GraphicsDir + Style(2, CurIndex)
CurrentNext$ = GraphicsDir + Style(3, CurIndex)
CurrentHome$ = GraphicsDir + Style(4, CurIndex)
CurrentTop$ = GraphicsDir + Style(5, CurIndex)
With oBaseDocument.DocumentInfo
.GetUserFieldValue(0) = ExtractGraphicNames(CurIndex,2)
.GetUserFieldValue(1) = ExtractGraphicNames(CurIndex, 4)
.GetUserFieldValue(2) = Style(6, CurIndex) ' Bullet
.GetUserFieldValue(3) = Style(7, CurIndex) ' Background
End With
SetBulletAndGraphics()
CheckControls(oBaseDocument.DrawPage)
oViewCursor.GotoStart(False)
oBaseDocument.UnlockControllers
ToggleWindow(True)
End Sub
Function ExtractGraphicNames(CurIndex as Integer, i as Integer) as String
Dim FieldValue as String
FieldValue = GetFileNameWithoutExtension(Style(i,CurIndex))
FieldValue = FieldValue & " " & GetFileNameWithoutExtension(Style(i+1,CurIndex))
ExtractGraphicNames = FieldValue
End Function
Function GetCurIndex(oListbox as Object, sList() as String, MaxIndex as Integer, FileIndex as Integer)
Dim i, n as Integer
Dim SelValue as String
' Get selected list entry
n = oListbox.SelectedItems(0)
SelValue = oListbox.StringItemList(n)
' Find field index for chosen list entry
For i = 0 To MaxIndex
If sList(1, i) = SelValue Then
FileStr = sList(FileIndex, i)
Exit For
End If
Next
GetCurIndex = i
End Function
Sub SetBulletAndGraphics
SetGraphic("Prev", CurrentPrev)
SetGraphic("Next", CurrentNext)
SetGraphic("Home", CurrentHome)
SetGraphic("Top", 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 > 0 And aActSize.Width > 0 Then
oGraphic.SetSize(aActSize)
End If
Next i
End Sub
Sub EndDialog()
If DialogModel.chkSaveasTemplate.State = 1 Then
' Generating template? Set events later!
AttachBasicMacroToEvent(oBaseDocument,"OnNew", "WebWizard.HtmlAutoPilotBasic.SetEvent()")
' Call the Store template dialog
DispatchSlot(5538)
Else
SetEvent
End If
MainDialog.EndExecute()
MainDialog.Dispose()
End Sub
Sub CancelHTMLWizard()
MainDialog.EndExecute()
MainDialog.Dispose()
oBaseDocument.Dispose()
End Sub
Sub SetEvent()
Dim oDocument as Object
' This sub links the events OnSaveDone and OnSaveAsDone to the procedure
' CopyGraphics. It is invoked when a document is created, either directly
' from the AutoPilot or from a template. It is not possible to set these
' links for the template created by the AutoPilot because then it is not
' possible to modify the template.
BasicLibraries.LoadLibrary("Tools")
oDocument = StarDesktop.ActiveFrame.Controller.Model
AttachBasicMacroToEvent(oDocument,"OnSaveDone", "WebWizard.HtmlAutoPilotBasic.CopyGraphics()")
AttachBasicMacroToEvent(oDocument,"OnSaveAsDone", "WebWizard.HtmlAutoPilotBasic.CopyGraphics()")
End Sub
Sub CopyGraphics
' This sub copies all the graphics used in the document to the same directory the
' document has been copied into and changes the graphics links in the document.
Dim oGraphicObjects, oGraphic as Object
Dim i as Integer
Dim GraphicFilePath as String
Dim SavePath$
Dim GraphicFileName as String
BasicLibraries.LoadLibrary("Tools")
GetPaths()
oBaseDocument = StarDesktop.ActiveFrame.Controller.Model
Msgbox oBaseDocument.Url
SavePath = oBaseDocument.Url
oGraphicObjects = oBaseDocument.GraphicObjects
For i = 0 to oGraphicObjects.Count-1
oGraphic = oGraphicObjects.GetbyIndex(i)
GraphicFilePath = oGraphic.GraphicURL
GraphicFileName = FileNameoutofPath(GraphicFilePath)
FileCopy GraphicFilePath, Savepath & GraphicFileName
oGraphic.GraphicURL = Savepath & GraphicFileName
Next i
GraphicFileName = FileNameoutofPath(CurrentBullet)
FileCopy BulletDir & GraphicFileName, SavePath & GraphicFileName
SetBulletGraphics(GraphicFileName)
' ' Copy background graphic
' If ActiveWindow.Page.GrfFilename<>"" Then
' ' Set new background graphic
' ActiveWindow.Page.GrfFilename = SavePath$+GraphicFileName$
' ActiveWindow.Page.GrfPosition = 11
' End If
With oBaseDocument.DocumentInfo
.GetUserFieldValue(0) = ""
.GetUserFieldValue(1) = ""
.GetUserFieldValue(2) = ""
.GetUserFieldValue(3) = ""
End With
' ' Reset events
AttachBasicMacroToEvent(oBaseDocument,"OnSaveDone", "")
AttachBasicMacroToEvent(oBaseDocument,"OnSaveAsDone", "")
AttachBasicMacroToEvent(oBaseDocument,"OnCreate", "")
oBaseDocument.Store
End Sub
Function FillupWebListbox(oUcb as Object, sFileFilter as String, oDialog as Object, ListboxName as String, List() as String)
Dim oDocInfo 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 SelList(0) as Integer
Dim LocMaxIndex as Integer
oListboxControl = oDialog.GetControl(ListboxName)
oDocInfo = createUnoService("com.sun.star.document.StandaloneDocumentInfo")
FilterLen = Len(sFileFilter)
bItemFound = False
TemplatePath = GetOfficeSubPath("Template", "wizard/web/")
DirContent() = oUcb.GetFolderContents(TemplatePath,True)
LocMaxIndex = Ubound(DirContent())
a = 0
For i = 0 To LocMaxIndex
FileName = DirContent(i)
If Instr(1,Filename, sFileFilter) Then
bItemFound = True
Description = RetrieveDocTitle(oDocInfo, FileName)
oListboxControl.AddItem(Description,a)
a = a + 1
List(1,i) = Description
If sFileFilter = "/cnt" Then
List(2,i) = Filename
Else
m = 2
For n = 0 To 3
sField = oDocInfo.GetUserFieldValue(n)
sFieldList() = ArrayoutofString(sField, " ", MaxIndex)
For s = 0 To MaxIndex
If m < 6 Then
List(m,i) = sFieldList(s) & ".gif"
Else
List(m,i) = sFieldList(s)
End If
m = m + 1
Next s
Next n
List(8,i) = FileName
End If
End If
Next i
' No content template? Error message, close new empty document, stop execution
If Not bItemfound Then
MsgBox(WebWiz_gErrContentNotFound$ , 16, WebWiz_gWizardName$)
oBaseDocument.Dispose()
Stop
End If
SelList(0) = 0
oListboxControl.Model.SelectedItems() = SelList()
FillupWebListbox = i
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("com.sun.star.text.GraphicObject")
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 ChangeBulletURL(sBulletUrl as String, oBookMarkCursor as Object)
Dim n, m as Integer
Dim oLevel()
Dim oRules
Dim bDoReplace as Boolean
Dim oSize as New com.sun.star.awt.Size
Dim oNumberingBuffer(0) as New com.sun.star.beans.PropertyValue
Dim oNewBuffer(1) as New com.sun.star.beans.PropertyValue
oRules = oBookMarkCursor.NumberingRules
If Vartype(oRules()) = 9 Then
oNumberingBuffer(0).Name = "NumberingType"
oNumberingBuffer(0).Value = com.sun.star.style.NumberingType.BITMAP
For n = 0 To oRules.Count - 1
oLevel() = oRules.GetByIndex(n)
bDoReplace = ModifyPropertyValue(oLevel(), oNumberingBuffer())
If bDoReplace Then
oRules.ReplaceByIndex(n, oNumberingBuffer())
End If
Next n
oBookmarkCursor.NumberingRules = oRules
oNewBuffer(0).Name = "GraphicURL"
oNewBuffer(0).Value = sBulletUrl
oNewBuffer(1).Name = "GraphicSize"
oSize.Height = 300
oSize.Width = 300
oNewBuffer(1).Value = oSize
For n = 0 To oRules.Count - 1
oLevel() = oRules.GetByIndex(0)
bDoReplace = ModifyPropertyValue(oLevel(), oNewBuffer())
If bDoReplace Then
oRules.ReplaceByIndex(n, oNewBuffer())
End If
Next n
oBookmarkCursor.NumberingRules = oRules
End If
End Sub
Sub SetBulletGraphics(sBulletUrl as String)
Dim i as Integer
Dim oBookMarkCursor as Object
oBookmarks = oBaseDocument.BookMarks
For i = 0 To oBookmarks.Count - 1
oBookMark = oBookmarks.GetbyIndex(i)
oBookMarkCursor = oBookMark.Anchor.Text.CreateTextCursorByRange(oBookMark.Anchor)
If oBookMarkCursor.PropertySetInfo.HasPropertybyName("NumberingRules") Then
ChangeBulletURL(sBulletUrl, oBookMarkCursor)
End If
Next i
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("ParagraphStyles").GetByName("Standard").CharColor
'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
REM ***** BASIC *****
Sub LoadNewStyles(oDocument as Object, oDialogModel as Object, CurIndex as Integer, SourceFile as String, Styles() as String, TextureDir as String)
Dim BackGroundURL as String
Dim oBackGraph as Object
Dim i, BackColor as Long
Dim oFamilies as Object, oFamily as Object, oStyle as Object
Dim StylesOptions(0) as New com.sun.star.beans.PropertyValue
If SourceFile <> "" Then
StylesOptions(0).Name = "OverwriteStyles"
StylesOptions(0).Value = true
oDocument.StyleFamilies.LoadStylesFromURL(SourceFile, StylesOptions())
End If
' Read array fields for background, bullet & graphics
BackgroundURL = Styles(7, CurIndex)
If Left(BackgroundURL, 1) <> "#" Then
BackgroundURL = TextureDir + BackgroundURL
ToggleOptionButtons(oDialogModel, 1)
Else
BackColor = clng("&H" & Right(BackgroundURL, Len(BackgroundURL)-1))
ToggleOptionButtons(oDialogModel, 0)
End If
oFamilies = oDocument.StyleFamilies
oFamily = oFamilies.GetbyName("PageStyles")
' oStyle = oDocument.StyleFamilies.GetByName("PageStyles").GetByName("Standard")
For i = 0 To oFamily.Count - 1
If oFamily.GetByIndex(i).IsInUse Then
oStyle = oFamily.GetbyIndex(i)
If oStyle.PropertySetInfo.HasPropertybyName("BackGraphicURL") Then
If Left(BackgroundURL, 1) = "#" Then
oStyle.BackGraphicURL = ""
oStyle.BackColor = BackColor
oStyle.BackTransparent = False
Else
oStyle.BackGraphicUrl = BackGroundURL
SetTileBackgroundorNot(oDialogModel, oStyle)
End If
End If
End If
Next i
ErrorOcurred:
If Err <> 0 Then
MsgBox(WebWiz_gErrWhileLoadStyles$, 16, WebWiz_gWizardName$)
CancelHTMLWizard()
End If
End Sub
Sub ToggleOptionButtons(DialogModel as Object, bDoEnable as Integer)
DialogModel.optTiled.Enabled = bDoEnable
DialogModel.optArea.Enabled = bDoEnable
DialogModel.frmBackground.Enabled = bDoEnable
End Sub
Sub SetBackGraphicStyle(oEvent as Object)
Dim oFamilies as Object
Dim oFamily as Object
Dim i as Integer
Dim oStyle as Object
Dim oOptModel as Object
Dim iBackgroundValue as Integer
Dim oLocDocument as Object
ooptModel = oEvent.Source.Model
iBackgroundValue = Val(ooptModel.Tag)
oLocDocument = StarDesktop.ActiveFrame.Controller.Model
oLocDocument.LockControllers
oFamilies = oLocDocument.StyleFamilies
oFamily = oFamilies.GetbyName("PageStyles")
For i = 0 To oFamily.Count - 1
If oFamily.GetByIndex(i).IsInUse Then
oStyle = oFamily.GetbyIndex(i)
If oStyle.PropertySetInfo.HasPropertybyName("BackGraphicURL") Then
oStyle.BackGraphicLocation = iBackgroundValue
End If
End If
Next i
oLocDocument.UnlockControllers
End Sub
Sub SetTileBackgroundorNot(DialogModel as Object, oStyle as Object)
If DialogModel.optTiled.State = 1 Then
oStyle.BackGraphicLocation = com.sun.star.style.GraphicLocation.TILED
Else
oStyle.BackGraphicLocation = com.sun.star.style.GraphicLocation.AREA
End If
End Sub
</script:module>
|