1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ReadDir" script:language="StarBasic">Option Explicit
4*cdf0e10cSrcweirPublic Const SBPAGEX = 800
5*cdf0e10cSrcweirPublic Const SBPAGEY = 800
6*cdf0e10cSrcweirPublic Const SBRELDIST = 1.3
7*cdf0e10cSrcweir
8*cdf0e10cSrcweir&apos; Names of the second Dimension of the Array iLevelPos
9*cdf0e10cSrcweirPublic Const SBBASEX = 0
10*cdf0e10cSrcweirPublic Const SBBASEY = 1
11*cdf0e10cSrcweir
12*cdf0e10cSrcweirPublic Const SBOLDSTARTX = 2
13*cdf0e10cSrcweirPublic Const SBOLDSTARTY = 3
14*cdf0e10cSrcweir
15*cdf0e10cSrcweirPublic Const SBOLDENDX = 4
16*cdf0e10cSrcweirPublic Const SBOLDENDY = 5
17*cdf0e10cSrcweir
18*cdf0e10cSrcweirPublic Const SBNEWSTARTX = 6
19*cdf0e10cSrcweirPublic Const SBNEWSTARTY = 7
20*cdf0e10cSrcweir
21*cdf0e10cSrcweirPublic Const SBNEWENDX = 8
22*cdf0e10cSrcweirPublic Const SBNEWENDY = 9
23*cdf0e10cSrcweir
24*cdf0e10cSrcweirPublic ConnectLevel As Integer
25*cdf0e10cSrcweirPublic iLevelPos(1,9) As Long
26*cdf0e10cSrcweirPublic Source as String
27*cdf0e10cSrcweirPublic iCurLevel as Integer
28*cdf0e10cSrcweirPublic nConnectLevel as Integer
29*cdf0e10cSrcweirPublic nOldWidth, nOldHeight As Long
30*cdf0e10cSrcweirPublic nOldX, nOldY, nOldLevel As Integer
31*cdf0e10cSrcweirPublic oOldLeavingLine As Object
32*cdf0e10cSrcweirPublic oOldArrivingLine As Object
33*cdf0e10cSrcweirPublic DlgReadDir as Object
34*cdf0e10cSrcweirDim oProgressBar as Object
35*cdf0e10cSrcweirDim oDocument As Object
36*cdf0e10cSrcweirDim oPage As Object
37*cdf0e10cSrcweir
38*cdf0e10cSrcweir
39*cdf0e10cSrcweirSub Main()
40*cdf0e10cSrcweirDim oStandardTemplate as Object
41*cdf0e10cSrcweir	BasicLibraries.LoadLibrary(&quot;Tools&quot;)
42*cdf0e10cSrcweir	oDocument = CreateNewDocument(&quot;sdraw&quot;)
43*cdf0e10cSrcweir	If Not IsNull(oDocument) Then
44*cdf0e10cSrcweir		oPage = oDocument.DrawPages(0)
45*cdf0e10cSrcweir		oStandardTemplate = oDocument.StyleFamilies.GetByName(&quot;graphics&quot;).GetByName(&quot;standard&quot;)
46*cdf0e10cSrcweir		oStandardTemplate.CharHeight = 10
47*cdf0e10cSrcweir		oStandardTemplate.TextLeftDistance = 100
48*cdf0e10cSrcweir		oStandardTemplate.TextRightDistance = 100
49*cdf0e10cSrcweir		oStandardTemplate.TextUpperDistance = 50
50*cdf0e10cSrcweir		oStandardTemplate.TextLowerDistance = 50
51*cdf0e10cSrcweir		DlgReadDir = LoadDialog(&quot;Gimmicks&quot;,&quot;ReadFolderDlg&quot;)
52*cdf0e10cSrcweir		oProgressBar = DlgReadDir.Model.ProgressBar1
53*cdf0e10cSrcweir		DlgReadDir.Model.TextField1.Text = ConvertFromUrl(GetPathSettings(&quot;Work&quot;))
54*cdf0e10cSrcweir		DlgReadDir.Model.cmdGoOn.DefaultButton = True
55*cdf0e10cSrcweir		DlgReadDir.GetControl(&quot;TextField1&quot;).SetFocus()
56*cdf0e10cSrcweir		DlgReadDir.Execute
57*cdf0e10cSrcweir	End If
58*cdf0e10cSrcweirEnd Sub
59*cdf0e10cSrcweir
60*cdf0e10cSrcweir
61*cdf0e10cSrcweirSub TreeInfo()
62*cdf0e10cSrcweirDim oCurTextShape As Object
63*cdf0e10cSrcweirDim i as Integer
64*cdf0e10cSrcweirDim bStartUpRun As Boolean
65*cdf0e10cSrcweirDim CurFilename as String
66*cdf0e10cSrcweirDim BaseLevel as Integer
67*cdf0e10cSrcweirDim oController as Object
68*cdf0e10cSrcweirDim MaxFileIndex as Integer
69*cdf0e10cSrcweirDim FileNames() as String
70*cdf0e10cSrcweir	ToggleDialogControls(False)
71*cdf0e10cSrcweir	oProgressBar.ProgressValueMin = 0
72*cdf0e10cSrcweir	oProgressBar.ProgressValueMax = 100
73*cdf0e10cSrcweir	bStartUpRun  = True
74*cdf0e10cSrcweir	nOldHeight = 200
75*cdf0e10cSrcweir	nOldY = SBPAGEY
76*cdf0e10cSrcweir	nOldX = SBPAGEX
77*cdf0e10cSrcweir	nOldWidth = SBPAGEX
78*cdf0e10cSrcweir	oController = oDocument.GetCurrentController
79*cdf0e10cSrcweir	Source = ConvertToURL(DlgReadDir.Model.TextField1.Text)
80*cdf0e10cSrcweir	BaseLevel = CountCharsInString(Source, &quot;/&quot;, 1)
81*cdf0e10cSrcweir	oProgressBar.ProgressValue = 5
82*cdf0e10cSrcweir	DlgReadDir.Model.Label3.Enabled = True
83*cdf0e10cSrcweir	FileNames() = ReadSourceDirectory(Source)
84*cdf0e10cSrcweir	DlgReadDir.Model.Label4.Enabled = True
85*cdf0e10cSrcweir	DlgReadDir.Model.Label3.Enabled = False
86*cdf0e10cSrcweir	oProgressBar.ProgressValue = 12
87*cdf0e10cSrcweir	FileNames() = BubbleSortList(FileNames())
88*cdf0e10cSrcweir	DlgReadDir.Model.Label5.Enabled = True
89*cdf0e10cSrcweir	DlgReadDir.Model.Label4.Enabled = False
90*cdf0e10cSrcweir	oProgressBar.ProgressValue = 20
91*cdf0e10cSrcweir	MaxFileIndex = Ubound(FileNames(),1)
92*cdf0e10cSrcweir	For i = 0 To MaxFileIndex
93*cdf0e10cSrcweir		oProgressBar.ProgressValue = 20 + (i/MaxFileIndex * 80)
94*cdf0e10cSrcweir		CurFilename = FileNames(i,1)
95*cdf0e10cSrcweir		SetNewLevels(FileNames(i,0), BaseLevel)
96*cdf0e10cSrcweir		oCurTextShape = CreateTextShape(oPage, CurFilename)
97*cdf0e10cSrcweir		CheckPageWidth(oCurTextShape.Size.Width)
98*cdf0e10cSrcweir		iLevelPos(iCurLevel,SBBASEY) = oCurTextShape.Position.Y
99*cdf0e10cSrcweir		If i = 0 Then
100*cdf0e10cSrcweir			AdjustPageHeight(oCurTextShape.Size.Height, MaxFileIndex + 1)
101*cdf0e10cSrcweir		End If
102*cdf0e10cSrcweir		&apos; The Current TextShape has To be connected with a TextShape one Level higher
103*cdf0e10cSrcweir		&apos; except for a TextShape In Level 0:
104*cdf0e10cSrcweir		If Not bStartUpRun Then
105*cdf0e10cSrcweir			&apos; A leaving Line Is only drawn when level is not 0
106*cdf0e10cSrcweir			If iCurLevel&lt;&gt; 0 Then
107*cdf0e10cSrcweir				&apos; Determine the Coordinates of the arriving Line
108*cdf0e10cSrcweir				iLevelPos(iCurLevel,SBOLDSTARTX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
109*cdf0e10cSrcweir				iLevelPos(iCurLevel,SBOLDSTARTY) = oCurTextShape.Position.Y + 0.5 * oCurTextShape.Size.Height
110*cdf0e10cSrcweir
111*cdf0e10cSrcweir				iLevelPos(iCurLevel,SBOLDENDX) = iLevelPos(iCurLevel,SBBASEX)
112*cdf0e10cSrcweir				iLevelPos(iCurLevel,SBOLDENDY) = oCurTextShape.Position.Y + 0.5 * oCurTextShape.Size.Height
113*cdf0e10cSrcweir
114*cdf0e10cSrcweir				oOldArrivingLine = DrawLine(iCurLevel, SBOLDSTARTX, SBOLDSTARTY, SBOLDENDX, SBOLDENDY, oPage)
115*cdf0e10cSrcweir
116*cdf0e10cSrcweir				&apos; Determine the End-Coordinates of the last leaving Line
117*cdf0e10cSrcweir				iLevelPos(nConnectLevel,SBNEWENDX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
118*cdf0e10cSrcweir				iLevelPos(nConnectLevel,SBNEWENDY) = oCurTextShape.Position.Y + 0.5 * oCurTextShape.Size.Height
119*cdf0e10cSrcweir			Else
120*cdf0e10cSrcweir				&apos; On Level 0 the last Leaving Line&apos;s Endpoint is the upper edge of the TextShape
121*cdf0e10cSrcweir				iLevelPos(nConnectLevel,SBNEWENDY) = oCurTextShape.Position.Y
122*cdf0e10cSrcweir				iLevelPos(nConnectLevel,SBNEWENDX) = iLevelPos(nConnectLevel,SBNEWSTARTX)
123*cdf0e10cSrcweir			End If
124*cdf0e10cSrcweir			&apos; Draw the Connectors To the previous TextShapes
125*cdf0e10cSrcweir			oOldLeavingLine = DrawLine(nConnectLevel, SBNEWSTARTX, SBNEWSTARTY, SBNEWENDX, SBNEWENDY, oPage)
126*cdf0e10cSrcweir		Else
127*cdf0e10cSrcweir			&apos; StartingPoint of the leaving Edge
128*cdf0e10cSrcweir			bStartUpRun = FALSE
129*cdf0e10cSrcweir		End If
130*cdf0e10cSrcweir
131*cdf0e10cSrcweir		&apos; Determine the beginning Coordinates of the leaving Line
132*cdf0e10cSrcweir		iLevelPos(iCurLevel,SBNEWSTARTX) = iLevelPos(iCurLevel,SBBASEX) + 0.5 * oCurTextShape.Size.Width
133*cdf0e10cSrcweir		iLevelPos(iCurLevel,SBNEWSTARTY) = iLevelPos(iCurLevel,SBBASEY) + oCurTextShape.Size.Height
134*cdf0e10cSrcweir
135*cdf0e10cSrcweir		&apos; Save the values For the Next run
136*cdf0e10cSrcweir		nOldHeight = oCurTextShape.Size.Height
137*cdf0e10cSrcweir		nOldX = oCurTextShape.Position.X
138*cdf0e10cSrcweir		nOldWidth = oCurTextShape.Size.Width
139*cdf0e10cSrcweir		nOldLevel = iCurLevel
140*cdf0e10cSrcweir	Next i
141*cdf0e10cSrcweir	ToggleDialogControls(True)
142*cdf0e10cSrcweir	DlgReadDir.Model.cmdGoOn.Enabled = False
143*cdf0e10cSrcweirEnd Sub
144*cdf0e10cSrcweir
145*cdf0e10cSrcweir
146*cdf0e10cSrcweirFunction CreateTextShape(oPage as Object, Filename as String)
147*cdf0e10cSrcweirDim oTextShape As Object
148*cdf0e10cSrcweirDim aPoint As New com.sun.star.awt.Point
149*cdf0e10cSrcweir
150*cdf0e10cSrcweir	aPoint.X = CalculateXPoint()
151*cdf0e10cSrcweir	aPoint.Y = nOldY + SBRELDIST * nOldHeight
152*cdf0e10cSrcweir	nOldY  = aPoint.Y
153*cdf0e10cSrcweir
154*cdf0e10cSrcweir	oTextShape = oDocument.createInstance(&quot;com.sun.star.drawing.TextShape&quot;)
155*cdf0e10cSrcweir	oTextShape.LineStyle = 1
156*cdf0e10cSrcweir	oTextShape.Position = aPoint
157*cdf0e10cSrcweir
158*cdf0e10cSrcweir	oPage.add(oTextShape)
159*cdf0e10cSrcweir	oTextShape.TextAutoGrowWidth = TRUE
160*cdf0e10cSrcweir	oTextShape.TextAutoGrowHeight = TRUE
161*cdf0e10cSrcweir	oTextShape.String = FileName
162*cdf0e10cSrcweir
163*cdf0e10cSrcweir	&apos; Configure Size And Position of the TextShape  according to its Scripting
164*cdf0e10cSrcweir	aPoint.X = iLevelPos(iCurLevel,SBBASEX)
165*cdf0e10cSrcweir	oTextShape.Position = aPoint
166*cdf0e10cSrcweir	CreateTextShape() = oTextShape
167*cdf0e10cSrcweirEnd Function
168*cdf0e10cSrcweir
169*cdf0e10cSrcweir
170*cdf0e10cSrcweirFunction CalculateXPoint()
171*cdf0e10cSrcweir	&apos; The current level Is lower than the Old one
172*cdf0e10cSrcweir	If (iCurLevel&lt; nOldLevel) And (iCurLevel&lt;&gt; 0) Then
173*cdf0e10cSrcweir	&apos; ClearArray(iLevelPos(),iCurLevel+1)
174*cdf0e10cSrcweir	Elseif iCurLevel= 0 Then
175*cdf0e10cSrcweir		iLevelPos(iCurLevel,SBBASEX) = SBPAGEX
176*cdf0e10cSrcweir	&apos; The current level Is higher than the old one
177*cdf0e10cSrcweir	Elseif iCurLevel&gt; nOldLevel Then
178*cdf0e10cSrcweir		iLevelPos(iCurLevel,SBBASEX) = iLevelPos(iCurLevel-1,SBBASEX) + nOldWidth + 100
179*cdf0e10cSrcweir	End If
180*cdf0e10cSrcweir	CalculateXPoint = iLevelPos(iCurLevel,SBBASEX)
181*cdf0e10cSrcweirEnd Function
182*cdf0e10cSrcweir
183*cdf0e10cSrcweir
184*cdf0e10cSrcweirFunction DrawLine(nLevel, nStartX, nStartY, nEndX, nEndY As Integer, oPage as Object)
185*cdf0e10cSrcweirDim oConnect As Object
186*cdf0e10cSrcweirDim aPoint As New com.sun.star.awt.Point
187*cdf0e10cSrcweirDim aSize As New com.sun.star.awt.Size
188*cdf0e10cSrcweir	aPoint.X = iLevelPos(nLevel,nStartX)
189*cdf0e10cSrcweir	aPoint.Y = iLevelPos(nLevel,nStartY)
190*cdf0e10cSrcweir	aSize.Width = iLevelPos(nLevel,nEndX) - iLevelPos(nLevel,nStartX)
191*cdf0e10cSrcweir	aSize.Height = iLevelPos(nLevel,nEndY) - iLevelPos(nLevel,nStartY)
192*cdf0e10cSrcweir	oConnect = oDocument.createInstance(&quot;com.sun.star.drawing.LineShape&quot;)
193*cdf0e10cSrcweir	oConnect.Position = aPoint
194*cdf0e10cSrcweir	oConnect.Size = aSize
195*cdf0e10cSrcweir	oPage.Add(oConnect)
196*cdf0e10cSrcweir	DrawLine() = oConnect
197*cdf0e10cSrcweirEnd Function
198*cdf0e10cSrcweir
199*cdf0e10cSrcweir
200*cdf0e10cSrcweirSub GetSourceDirectory()
201*cdf0e10cSrcweir	GetFolderName(DlgReadDir.Model.TextField1)
202*cdf0e10cSrcweirEnd Sub
203*cdf0e10cSrcweir
204*cdf0e10cSrcweir
205*cdf0e10cSrcweirFunction ReadSourceDirectory(ByVal Source As String)
206*cdf0e10cSrcweirDim i as Integer
207*cdf0e10cSrcweirDim m as Integer
208*cdf0e10cSrcweirDim n as Integer
209*cdf0e10cSrcweirDim s as integer
210*cdf0e10cSrcweirDim FileName as string
211*cdf0e10cSrcweirDim FileNameList(100,1) as String
212*cdf0e10cSrcweirDim DirList(0) as String
213*cdf0e10cSrcweirDim oUCBobject as Object
214*cdf0e10cSrcweirDim DirContent() as String
215*cdf0e10cSrcweirDim SystemPath as String
216*cdf0e10cSrcweirDim PathSeparator as String
217*cdf0e10cSrcweirDim MaxFileIndex as Integer
218*cdf0e10cSrcweir	PathSeparator = GetPathSeparator()
219*cdf0e10cSrcweir	oUcbobject = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
220*cdf0e10cSrcweir	m = 0
221*cdf0e10cSrcweir	s = 0
222*cdf0e10cSrcweir	DirList(0) = Source
223*cdf0e10cSrcweir	FileNameList(n,0) = Source
224*cdf0e10cSrcweir	SystemPath = ConvertFromUrl(Source)
225*cdf0e10cSrcweir	FileNameList(n,1) = FileNameoutofPath(SystemPath, PathSeparator)
226*cdf0e10cSrcweir	n = 1
227*cdf0e10cSrcweir	Do
228*cdf0e10cSrcweir		Source = DirList(m)
229*cdf0e10cSrcweir		m = m + 1
230*cdf0e10cSrcweir		DirContent() = oUcbObject.GetFolderContents(Source,True)
231*cdf0e10cSrcweir		If Ubound(DirContent()) &lt;&gt; -1 Then
232*cdf0e10cSrcweir			MaxFileIndex  = Ubound(DirContent())
233*cdf0e10cSrcweir			For i = 0 to MaxFileIndex
234*cdf0e10cSrcweir				FileName = DirContent(i)
235*cdf0e10cSrcweir				FileNameList(n,0) = FileName
236*cdf0e10cSrcweir				SystemPath = ConvertFromUrl(FileName)
237*cdf0e10cSrcweir				FileNameList(n,1) = FileNameOutofPath(SystemPath, PathSeparator)
238*cdf0e10cSrcweir				n = n + 1
239*cdf0e10cSrcweir				If n &gt; Ubound(FileNameList(),1) Then
240*cdf0e10cSrcweir					ReDim Preserve FileNameList(n + 10,1) as String
241*cdf0e10cSrcweir				End If
242*cdf0e10cSrcweir				If oUcbObject.IsFolder(FileName) Then
243*cdf0e10cSrcweir					s = s + 1
244*cdf0e10cSrcweir					ReDim Preserve DirList(s) as String
245*cdf0e10cSrcweir					DirList(s) = FileName
246*cdf0e10cSrcweir				End If
247*cdf0e10cSrcweir			Next i
248*cdf0e10cSrcweir		End If
249*cdf0e10cSrcweir	Loop Until m &gt; Ubound(DirList()
250*cdf0e10cSrcweir	ReDim Preserve FileNameList(n-1,1) as String
251*cdf0e10cSrcweir	ReadSourceDirectory() = FileNameList()
252*cdf0e10cSrcweirEnd Function
253*cdf0e10cSrcweir
254*cdf0e10cSrcweir
255*cdf0e10cSrcweirSub CloseDialog
256*cdf0e10cSrcweir	DlgReadDir.EndExecute
257*cdf0e10cSrcweirEnd Sub
258*cdf0e10cSrcweir
259*cdf0e10cSrcweir
260*cdf0e10cSrcweirSub	AdjustPageHeight(lShapeHeight, FileCount)
261*cdf0e10cSrcweirDim lNecHeight as Long
262*cdf0e10cSrcweirDim lBorders as Long
263*cdf0e10cSrcweir	oDocument.LockControllers
264*cdf0e10cSrcweir	lBorders = oPage.BorderTop + oPage.BorderBottom
265*cdf0e10cSrcweir	lNecHeight = SBPAGEY + (FileCount * SBRELDIST * lShapeHeight)
266*cdf0e10cSrcweir	If lNecHeight &gt; (oPage.Height - lBorders) Then
267*cdf0e10cSrcweir		oPage.Height = lNecHeight + lBorders + 500
268*cdf0e10cSrcweir	End If
269*cdf0e10cSrcweir	oDocument.UnlockControllers
270*cdf0e10cSrcweirEnd Sub
271*cdf0e10cSrcweir
272*cdf0e10cSrcweir
273*cdf0e10cSrcweirSub SetNewLevels(FileName as String, BaseLevel as Integer)
274*cdf0e10cSrcweir	iCurLevel= CountCharsInString(FileName, &quot;/&quot;, 1) - BaseLevel
275*cdf0e10cSrcweir	If iCurLevel &lt;&gt; 0 Then
276*cdf0e10cSrcweir		nConnectLevel = iCurLevel- 1
277*cdf0e10cSrcweir	Else
278*cdf0e10cSrcweir		nConnectLevel = iCurLevel
279*cdf0e10cSrcweir	End If
280*cdf0e10cSrcweir	If iCurLevel &gt; Ubound(iLevelPos(),1) Then
281*cdf0e10cSrcweir		ReDim Preserve iLevelPos(iCurLevel,9) as Long
282*cdf0e10cSrcweir	End If
283*cdf0e10cSrcweirEnd Sub
284*cdf0e10cSrcweir
285*cdf0e10cSrcweir
286*cdf0e10cSrcweirSub CheckPageWidth(TextWidth as Long)
287*cdf0e10cSrcweirDim PageWidth as Long
288*cdf0e10cSrcweirDim BaseX as Long
289*cdf0e10cSrcweir	PageWidth = oPage.Width
290*cdf0e10cSrcweir	BaseX = iLevelPos(iCurLevel,SBBASEX)
291*cdf0e10cSrcweir	If BaseX + TextWidth &gt; PageWidth - 1000 Then
292*cdf0e10cSrcweir		oPage.Width = 1000 + BaseX + TextWidth
293*cdf0e10cSrcweir	End If
294*cdf0e10cSrcweirEnd Sub
295*cdf0e10cSrcweir
296*cdf0e10cSrcweir
297*cdf0e10cSrcweirSub ToggleDialogControls(bDoEnable as Boolean)
298*cdf0e10cSrcweir	With DlgReadDir.Model
299*cdf0e10cSrcweir		.cmdGoOn.Enabled = bDoEnable
300*cdf0e10cSrcweir		.cmdGetDir.Enabled = bDoEnable
301*cdf0e10cSrcweir		.Label1.Enabled = bDoEnable
302*cdf0e10cSrcweir		.Label2.Enabled = bDoEnable
303*cdf0e10cSrcweir		.TextField1.Enabled = bDoEnable
304*cdf0e10cSrcweir	End With
305*cdf0e10cSrcweirEnd Sub</script:module>