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=
"ReadDir" script:
language=
"StarBasic">Option Explicit
4 Public Const SBPAGEX =
800
5 Public Const SBPAGEY =
800
6 Public Const SBRELDIST =
1.3
8 ' Names of the second Dimension of the Array iLevelPos
9 Public Const SBBASEX =
0
10 Public Const SBBASEY =
1
12 Public Const SBOLDSTARTX =
2
13 Public Const SBOLDSTARTY =
3
15 Public Const SBOLDENDX =
4
16 Public Const SBOLDENDY =
5
18 Public Const SBNEWSTARTX =
6
19 Public Const SBNEWSTARTY =
7
21 Public Const SBNEWENDX =
8
22 Public Const SBNEWENDY =
9
24 Public ConnectLevel As Integer
25 Public iLevelPos(
1,
9) As Long
26 Public Source as String
27 Public iCurLevel as Integer
28 Public nConnectLevel as Integer
29 Public nOldWidth, nOldHeight As Long
30 Public nOldX, nOldY, nOldLevel As Integer
31 Public oOldLeavingLine As Object
32 Public oOldArrivingLine As Object
33 Public DlgReadDir as Object
34 Dim oProgressBar as Object
35 Dim oDocument As Object
40 Dim oStandardTemplate as Object
41 BasicLibraries.LoadLibrary(
"Tools
")
42 oDocument = CreateNewDocument(
"sdraw
")
43 If Not IsNull(oDocument) Then
44 oPage = oDocument.DrawPages(
0)
45 oStandardTemplate = oDocument.StyleFamilies.GetByName(
"graphics
").GetByName(
"standard
")
46 oStandardTemplate.CharHeight =
10
47 oStandardTemplate.TextLeftDistance =
100
48 oStandardTemplate.TextRightDistance =
100
49 oStandardTemplate.TextUpperDistance =
50
50 oStandardTemplate.TextLowerDistance =
50
51 DlgReadDir = LoadDialog(
"Gimmicks
",
"ReadFolderDlg
")
52 oProgressBar = DlgReadDir.Model.ProgressBar1
53 DlgReadDir.Model.TextField1.Text = ConvertFromUrl(GetPathSettings(
"Work
"))
54 DlgReadDir.Model.cmdGoOn.DefaultButton = True
55 DlgReadDir.GetControl(
"TextField1
").SetFocus()
62 Dim oCurTextShape As Object
64 Dim bStartUpRun As Boolean
65 Dim CurFilename as String
66 Dim BaseLevel as Integer
67 Dim oController as Object
68 Dim MaxFileIndex as Integer
69 Dim FileNames() as String
70 ToggleDialogControls(False)
71 oProgressBar.ProgressValueMin =
0
72 oProgressBar.ProgressValueMax =
100
78 oController = oDocument.GetCurrentController
79 Source = ConvertToURL(DlgReadDir.Model.TextField1.Text)
80 BaseLevel = CountCharsInString(Source,
"/
",
1)
81 oProgressBar.ProgressValue =
5
82 DlgReadDir.Model.Label3.Enabled = True
83 FileNames() = ReadSourceDirectory(Source)
84 DlgReadDir.Model.Label4.Enabled = True
85 DlgReadDir.Model.Label3.Enabled = False
86 oProgressBar.ProgressValue =
12
87 FileNames() = BubbleSortList(FileNames())
88 DlgReadDir.Model.Label5.Enabled = True
89 DlgReadDir.Model.Label4.Enabled = False
90 oProgressBar.ProgressValue =
20
91 MaxFileIndex = Ubound(FileNames(),
1)
92 For i =
0 To MaxFileIndex
93 oProgressBar.ProgressValue =
20 + (i/MaxFileIndex *
80)
94 CurFilename = FileNames(i,
1)
95 SetNewLevels(FileNames(i,
0), BaseLevel)
96 oCurTextShape = CreateTextShape(oPage, CurFilename)
97 CheckPageWidth(oCurTextShape.Size.Width)
98 iLevelPos(iCurLevel,SBBASEY) = oCurTextShape.Position.Y
100 AdjustPageHeight(oCurTextShape.Size.Height, MaxFileIndex +
1)
102 ' The Current TextShape has To be connected with a TextShape one Level higher
103 ' except for a TextShape In Level
0:
104 If Not bStartUpRun Then
105 ' A leaving Line Is only drawn when level is not
0
106 If iCurLevel
<> 0 Then
107 ' Determine the Coordinates of the arriving Line
108 iLevelPos(iCurLevel,SBOLDSTARTX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
109 iLevelPos(iCurLevel,SBOLDSTARTY) = oCurTextShape.Position.Y +
0.5 * oCurTextShape.Size.Height
111 iLevelPos(iCurLevel,SBOLDENDX) = iLevelPos(iCurLevel,SBBASEX)
112 iLevelPos(iCurLevel,SBOLDENDY) = oCurTextShape.Position.Y +
0.5 * oCurTextShape.Size.Height
114 oOldArrivingLine = DrawLine(iCurLevel, SBOLDSTARTX, SBOLDSTARTY, SBOLDENDX, SBOLDENDY, oPage)
116 ' Determine the End-Coordinates of the last leaving Line
117 iLevelPos(nConnectLevel,SBNEWENDX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
118 iLevelPos(nConnectLevel,SBNEWENDY) = oCurTextShape.Position.Y +
0.5 * oCurTextShape.Size.Height
120 ' On Level
0 the last Leaving Line
's Endpoint is the upper edge of the TextShape
121 iLevelPos(nConnectLevel,SBNEWENDY) = oCurTextShape.Position.Y
122 iLevelPos(nConnectLevel,SBNEWENDX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
124 ' Draw the Connectors To the previous TextShapes
125 oOldLeavingLine = DrawLine(nConnectLevel, SBNEWSTARTX, SBNEWSTARTY, SBNEWENDX, SBNEWENDY, oPage)
127 ' StartingPoint of the leaving Edge
131 ' Determine the beginning Coordinates of the leaving Line
132 iLevelPos(iCurLevel,SBNEWSTARTX) = iLevelPos(iCurLevel,SBBASEX) +
0.5 * oCurTextShape.Size.Width
133 iLevelPos(iCurLevel,SBNEWSTARTY) = iLevelPos(iCurLevel,SBBASEY) + oCurTextShape.Size.Height
135 ' Save the values For the Next run
136 nOldHeight = oCurTextShape.Size.Height
137 nOldX = oCurTextShape.Position.X
138 nOldWidth = oCurTextShape.Size.Width
139 nOldLevel = iCurLevel
141 ToggleDialogControls(True)
142 DlgReadDir.Model.cmdGoOn.Enabled = False
146 Function CreateTextShape(oPage as Object, Filename as String)
147 Dim oTextShape As Object
148 Dim aPoint As New com.sun.star.awt.Point
150 aPoint.X = CalculateXPoint()
151 aPoint.Y = nOldY + SBRELDIST * nOldHeight
154 oTextShape = oDocument.createInstance(
"com.sun.star.drawing.TextShape
")
155 oTextShape.LineStyle =
1
156 oTextShape.Position = aPoint
158 oPage.add(oTextShape)
159 oTextShape.TextAutoGrowWidth = TRUE
160 oTextShape.TextAutoGrowHeight = TRUE
161 oTextShape.String = FileName
163 ' Configure Size And Position of the TextShape according to its Scripting
164 aPoint.X = iLevelPos(iCurLevel,SBBASEX)
165 oTextShape.Position = aPoint
166 CreateTextShape() = oTextShape
170 Function CalculateXPoint()
171 ' The current level Is lower than the Old one
172 If (iCurLevel
< nOldLevel) And (iCurLevel
<> 0) Then
173 ' ClearArray(iLevelPos(),iCurLevel+
1)
174 Elseif iCurLevel=
0 Then
175 iLevelPos(iCurLevel,SBBASEX) = SBPAGEX
176 ' The current level Is higher than the old one
177 Elseif iCurLevel
> nOldLevel Then
178 iLevelPos(iCurLevel,SBBASEX) = iLevelPos(iCurLevel-
1,SBBASEX) + nOldWidth +
100
180 CalculateXPoint = iLevelPos(iCurLevel,SBBASEX)
184 Function DrawLine(nLevel, nStartX, nStartY, nEndX, nEndY As Integer, oPage as Object)
185 Dim oConnect As Object
186 Dim aPoint As New com.sun.star.awt.Point
187 Dim aSize As New com.sun.star.awt.Size
188 aPoint.X = iLevelPos(nLevel,nStartX)
189 aPoint.Y = iLevelPos(nLevel,nStartY)
190 aSize.Width = iLevelPos(nLevel,nEndX) - iLevelPos(nLevel,nStartX)
191 aSize.Height = iLevelPos(nLevel,nEndY) - iLevelPos(nLevel,nStartY)
192 oConnect = oDocument.createInstance(
"com.sun.star.drawing.LineShape
")
193 oConnect.Position = aPoint
194 oConnect.Size = aSize
196 DrawLine() = oConnect
200 Sub GetSourceDirectory()
201 GetFolderName(DlgReadDir.Model.TextField1)
205 Function ReadSourceDirectory(ByVal Source As String)
210 Dim FileName as string
211 Dim FileNameList(
100,
1) as String
212 Dim DirList(
0) as String
213 Dim oUCBobject as Object
214 Dim DirContent() as String
215 Dim SystemPath as String
216 Dim PathSeparator as String
217 Dim MaxFileIndex as Integer
218 PathSeparator = GetPathSeparator()
219 oUcbobject = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
223 FileNameList(n,
0) = Source
224 SystemPath = ConvertFromUrl(Source)
225 FileNameList(n,
1) = FileNameoutofPath(SystemPath, PathSeparator)
230 DirContent() = oUcbObject.GetFolderContents(Source,True)
231 If Ubound(DirContent())
<> -
1 Then
232 MaxFileIndex = Ubound(DirContent())
233 For i =
0 to MaxFileIndex
234 FileName = DirContent(i)
235 FileNameList(n,
0) = FileName
236 SystemPath = ConvertFromUrl(FileName)
237 FileNameList(n,
1) = FileNameOutofPath(SystemPath, PathSeparator)
239 If n
> Ubound(FileNameList(),
1) Then
240 ReDim Preserve FileNameList(n +
10,
1) as String
242 If oUcbObject.IsFolder(FileName) Then
244 ReDim Preserve DirList(s) as String
245 DirList(s) = FileName
249 Loop Until m
> Ubound(DirList()
250 ReDim Preserve FileNameList(n-
1,
1) as String
251 ReadSourceDirectory() = FileNameList()
256 DlgReadDir.EndExecute
260 Sub AdjustPageHeight(lShapeHeight, FileCount)
261 Dim lNecHeight as Long
263 oDocument.LockControllers
264 lBorders = oPage.BorderTop + oPage.BorderBottom
265 lNecHeight = SBPAGEY + (FileCount * SBRELDIST * lShapeHeight)
266 If lNecHeight
> (oPage.Height - lBorders) Then
267 oPage.Height = lNecHeight + lBorders +
500
269 oDocument.UnlockControllers
273 Sub SetNewLevels(FileName as String, BaseLevel as Integer)
274 iCurLevel= CountCharsInString(FileName,
"/
",
1) - BaseLevel
275 If iCurLevel
<> 0 Then
276 nConnectLevel = iCurLevel-
1
278 nConnectLevel = iCurLevel
280 If iCurLevel
> Ubound(iLevelPos(),
1) Then
281 ReDim Preserve iLevelPos(iCurLevel,
9) as Long
286 Sub CheckPageWidth(TextWidth as Long)
287 Dim PageWidth as Long
289 PageWidth = oPage.Width
290 BaseX = iLevelPos(iCurLevel,SBBASEX)
291 If BaseX + TextWidth
> PageWidth -
1000 Then
292 oPage.Width =
1000 + BaseX + TextWidth
297 Sub ToggleDialogControls(bDoEnable as Boolean)
298 With DlgReadDir.Model
299 .cmdGoOn.Enabled = bDoEnable
300 .cmdGetDir.Enabled = bDoEnable
301 .Label1.Enabled = bDoEnable
302 .Label2.Enabled = bDoEnable
303 .TextField1.Enabled = bDoEnable
305 End Sub
</script:module>