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">' Variables must be declared
6 Public CurDocIndex as Integer
7 Public CurWebPageIndex as Integer
10 Public bWithBackGraphic as Boolean
11 Public oStyle as Object
12 ' Maximum number of content templates, style templates and bullets
17 'Public NumberOfLayouts%, NumberOfStyles%
19 ' Filled with title, previous, next, home, top, bullet, background, file name
20 Public Style(MaxStyles,
8) as String
22 Public Layout$(MaxLayouts,
2)
24 Public TextureDir$, BulletDir$, GraphicsDir$, GalleryDir$, PhotosDir$
25 Public SOBitmapPath as String
26 Public CurrentBullet$, CurrentPrev$, CurrentNext$, CurrentHome$, CurrentTop$
27 Public FileStr as String
29 Public WebWiz_gWizardName$, WebWiz_gErrContentNotFound$, WebWiz_gErrStyleNotFound$
30 Public WebWiz_gErrMainTemplateError$, WebWiz_gErrWhileReloading$
31 Public WebWiz_gErrWhileLoadStyles$, WebWiz_gErrMsg$, WebWiz_gErrMainDocumentError$
33 Public ProgressBar as Object
34 Public ProgressValue As Long
35 Public oBaseDocument as Object
36 Public oViewCursor as Object
37 Public oViewSettings as Object
38 Public NoArgs() as New com.sun.star.beans.PropertyValue
40 Public oCursor as Object
41 Public oBookmarks as Object
42 Public oBookMark as Object
45 Public MainDialog as Object
46 Public DialogModel as Object
51 On Local Error Goto GlobalErrorHandler
52 BasicLibraries.LoadLibrary(
"Tools
")
53 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
54 oBaseDocument = StarDesktop.LoadComponentFromURL(
"private:factory/swriter/web
",
"_default
",
0, NoArgs())
55 oViewSettings = oBaseDocument.CurrentController.ViewSettings
56 oViewCursor = oBaseDocument.GetCurrentController.ViewCursor
58 ProgressBar = oBaseDocument.GetCurrentController.GetFrame.CreateStatusIndicator
59 ProgressBar.Start(
"",
100)
61 oBaseDocument.LockControllers
62 oViewSettings.ShowTableBoundaries = False
63 If Not GetWebWizardPaths() Then
68 Layout() = getListBoxArrays(oUcb,
"/cnt
")
69 GetCurIndex(DialogModel, Layout(),
2)
71 oCursor = oBasedocument.Text.CreateTextCursor
72 oCursor.InsertDocumentfromURL(FileStr, NoArgs())
74 Style() = getListBoxArrays(oUcb,
"/stl
")
76 LoadWebPageStyles(oBaseDocument)
78 oBaseDocument.UnlockControllers
82 MainDialog.Model.ImagePreview.BackGroundColor = RGB(
0,
60,
126)
83 RetValue = MainDialog.Execute
87 DisposeDocument(oBaseDocument)
93 If Err
<> 0 Then
94 MsgBox (WebWiz_gErrMsg$,
16, WebWiz_gWizardName$)
95 DisposeDocument(oBaseDocument)
102 Function SetProgressValue(iValue as Integer)
106 ProgressValue = iValue
107 ProgressBar.Value = iValue
111 Sub ReloadCurrentDocument()
112 Dim OldDocIndex as Integer
113 On Local Error Goto ErrorOcurred
114 OldDocIndex = CurDocIndex
115 CurDocIndex = GetCurIndex(DialogModel.lbTemplate, Layout(),
2)
116 If OldDocIndex
<> 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())
125 CheckControls(oBaseDocument.DrawPage)
127 If Err
<> 0 Then
128 MsgBox(WebWiz_gErrWhileReloading$,
16, WebWiz_gWizardName$)
130 oBaseDocument.UnlockControllers
131 oViewCursor.GotoStart(False)
132 ToggleDialogControls(True,
"lbTemplate
")
139 Sub LoadWebPageStyles(aEvent as Object, Optional bStartUp as Boolean)
140 Dim OldWebPageIndex as Integer
141 OldWebPageIndex = CurWebPageIndex
142 If IsNull(DialogModel) Then
143 CurWebPageIndex = GetCurIndex(DialogModel, Style(),
8)
145 CurWebPageIndex = GetCurIndex(DialogModel.lbStyles, Style(),
8)
147 If OldWebPageIndex
<> 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)
162 SetBulletAndGraphics()
163 CheckControls(oBaseDocument.DrawPage)
164 oViewCursor.GotoStart(False)
165 oBaseDocument.UnlockControllers
166 ToggleDialogControls(True,
"lbStyles
")
171 Function ExtractGraphicNames(CurIndex as Integer, i as Integer) as String
172 Dim FieldValue as String
173 FieldValue = GetFileNameWithoutExtension(Style(CurIndex, i))
174 FieldValue = FieldValue
& " " & GetFileNameWithoutExtension(Style(CurIndex, i+
1))
175 ExtractGraphicNames = FieldValue
179 Sub SetBulletAndGraphics
180 SetGraphic(
"Prev
", CurrentPrev)
181 SetGraphic(
"Next
", CurrentNext)
182 SetGraphic(
"Home
", CurrentHome)
183 SetGraphic(
"Top
", CurrentTop)
184 SetBulletGraphics(CurrentBullet)
185 SetGraphicsToOriginalSize()
189 Sub SetGraphicsToOriginalSize()
190 Dim oGraphics as Object
191 Dim oGraphic as Object
193 Dim 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
> 0 And aActSize.Width
> 0 Then
199 oGraphic.SetSize(aActSize)
206 If DialogModel.chkSaveasTemplate.State =
1 Then
207 ' Generating template? Set events later!
208 AttachBasicMacroToEvent(oBaseDocument,
"OnNew
",
"WebWizard.HtmlAutoPilotBasic.SetEvent()
")
209 ' Call the Store template dialog
211 AttachBasicMacroToEvent(oBaseDocument,
"OnNew
",
"")
218 Dim oDocument as Object
219 ' This sub links the events OnSaveDone and OnSaveAsDone to the procedure
220 ' CopyGraphics. It is invoked when a document is created, either directly
221 ' from the AutoPilot or from a template. It is not possible to set these
222 ' links for the template created by the AutoPilot because then it is not
223 ' possible to modify the template.
224 BasicLibraries.LoadLibrary(
"Tools
")
225 oDocument = ThisComponent
226 AttachBasicMacroToEvent(oDocument,
"OnSaveDone
",
"WebWizard.HtmlAutoPilotBasic.CopyGraphics()
")
227 AttachBasicMacroToEvent(oDocument,
"OnSaveAsDone
",
"WebWizard.HtmlAutoPilotBasic.CopyGraphics()
")
233 ' This sub copies all the graphics used in the document to the same directory the
234 ' document has been copied into and changes the graphics links in the document.
235 Dim oGraphicObjects as Object
236 Dim oGraphic as Object
238 Dim udProps as Object
239 Dim SavePath as String
240 BasicLibraries.LoadLibrary(
"Tools
")
241 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
243 oBaseDocument = ThisComponent
244 ' oBaseDocument.LockControllers()
246 ' Note: The sub DirectoryNameoutofPath should be change, so that the last character is a slash
247 SavePath = DirectoryNameoutofPath(oBaseDocument.Url,
"/
")
& "/
"
249 oGraphicObjects = oBaseDocument.GraphicObjects
250 For i =
0 to oGraphicObjects.Count-
1
251 oGraphic = oGraphicObjects.GetbyIndex(i)
252 oGraphic.GraphicUrl = CopyFile(oGraphic.GraphicURL, SavePath)
255 ChangeBackGraphicUrl(SavePath)
257 BulletUrlsToSavePath(SavePath)
259 udProps = oBaseDocument.DocumentProperties.UserDefinedProperties
260 udProps.addProperty(
"AutoPilotName1
",
0,
"")
261 udProps.addProperty(
"AutoPilotName2
",
0,
"")
262 udProps.addProperty(
"AutoPilotBullet
",
0,
"")
263 udProps.addProperty(
"AutoPilotBackground
",
0,
"")
265 AttachBasicMacroToEvent(oBaseDocument,
"OnSaveDone
",
"")
266 AttachBasicMacroToEvent(oBaseDocument,
"OnSaveAsDone
",
"")
267 AttachBasicMacroToEvent(oBaseDocument,
"OnNew
",
"")
269 ' oBaseDocument.UnlockControllers()
273 Function CopyFile(ByVal SourceUrl as String, TargetDir as String)
274 Dim sFileName as String
275 Dim sNewFileUrl as String
276 If oUcb.Exists(TargetDir) Then
277 If Len(TargetDir)
> 2 Then
278 sFileName = FileNameoutofPath(SourceUrl)
279 sNewFileUrl = TargetDir
& sFileName
280 oUcb.Copy(SourceUrl, sNewFileUrl)
281 CopyFile() = sNewFileUrl
287 Function getListBoxArrays(oUcb as Object, sFileFilter as String)
288 Dim oDocProps as Object
289 Dim oListboxControl as Object
290 Dim Description as String
292 Dim sFieldList() as String
293 Dim bItemFound as Boolean
294 Dim MaxIndex as Integer
295 Dim DirContent() as String
296 Dim FileName as String
297 Dim TemplatePath as String
298 Dim FilterLen as Integer
304 Dim LocMaxIndex as Integer
306 Dim DimCount as Integer
307 Dim sExtension as String
308 oDocProps = CreateUnoService(
"com.sun.star.document.DocumentProperties
")
309 FilterLen = Len(sFileFilter)
311 ' It has to be made sure that the TemplatePath
<> ""
312 TemplatePath = GetOfficeSubPath(
"Template
",
"wizard/web/
")
313 If TemplatePath =
"" Then
315 getListBoxArrays() = NullList()
318 DirContent() = oUcb.GetFolderContents(TemplatePath,True)
319 If sFileFilter =
"/cnt
" Then
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))
331 SortList() = BubbleSortList(SortList(),True)
332 For i =
0 to LocMaxIndex
333 DirContent(i) = SortList(i,
0)
336 For i =
0 To LocMaxIndex
337 FileName = DirContent(i)
338 sExtension = Ucase(GetFileNameExtension(FileName))
339 If Instr(
1,Filename, sFileFilter) And sExtension =
"STW
" Then
341 Description = RetrieveDocTitle(oDocProps, FileName)
342 Properties = oDocProps.UserDefinedProperties.PropertyValues
343 List(a,
1) = Description
344 If sFileFilter =
"/cnt
" Then
349 sField = Properties(n).Value
350 sFieldList() = ArrayoutofString(sField,
" ", MaxIndex)
351 For s =
0 To MaxIndex
353 List(a,m) = sFieldList(s)
& ".gif
"
355 List(a,m) = sFieldList(s)
365 If sFileFilter =
"/cnt
" Then
366 ReDim Preserve List(a-
1,
2) as String
368 ReDim Preserve List(a-
1,
8) as String
370 If Not bItemfound Then
371 MsgBox(WebWiz_gErrContentNotFound$,
16, WebWiz_gWizardName$)
372 DisposeDocument(oBaseDocument)
375 getListBoxArrays = List()
379 Sub SetGraphic(sWhich, sGraphicText as String)
380 Dim oLocCursor as Object
381 Dim oGraphic as Object
382 Dim 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(
"com.sun.star.text.GraphicObject
")
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
400 Sub CheckControls(oDrawPage as Object)
404 Dim oControl as Object
405 lColor = oBaseDocument.StyleFamilies.GetbyName(
"ParagraphStyles
").GetByName(
"Standard
").CharColor
406 '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
417 Sub RepaintHeaderPreview()
419 Dim sBitmapPath as String
420 sBitmapPath = SOBitmapPath
& "webwizard.bmp
"
421 WebWzrd.ImagePreview.ImageURL = sBitmapPath
425 Sub ToggleDialogControls(ByVal bDoEnable as Boolean, Optional FocusControlName as String)
426 If Not IsNull(DialogModel) Then
427 DialogModel.Enabled = bDoEnable
429 ' Enable Controls referring to Background graphic only when this Property is set
430 bDoEnable = bWithBackGraphic
431 ToggleOptionButtons(DialogModel, bDoEnable)
432 MainDialog.GetControl(FocusControlName).SetFocus()