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