xref: /aoo42x/main/wizards/source/tools/Debug.xba (revision cdf0e10c)
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="Debug" script:language="StarBasic">REM  *****  BASIC  *****
4*cdf0e10cSrcweir
5*cdf0e10cSrcweirSub ActivateReadOnlyFlag()
6*cdf0e10cSrcweir	SetBasicReadOnlyFlag(True)
7*cdf0e10cSrcweirEnd Sub
8*cdf0e10cSrcweir
9*cdf0e10cSrcweir
10*cdf0e10cSrcweirSub DeactivateReadOnlyFlag()
11*cdf0e10cSrcweir	SetBasicReadOnlyFlag(False)
12*cdf0e10cSrcweirEnd Sub
13*cdf0e10cSrcweir
14*cdf0e10cSrcweir
15*cdf0e10cSrcweirSub SetBasicReadOnlyFlag(bReadOnly as Boolean)
16*cdf0e10cSrcweirDim i as Integer
17*cdf0e10cSrcweirDim LibName as String
18*cdf0e10cSrcweirDim BasicLibNames() as String
19*cdf0e10cSrcweir	BasicLibNames() = BasicLibraries.ElementNames()
20*cdf0e10cSrcweir	For i = 0 To Ubound(BasicLibNames())
21*cdf0e10cSrcweir		LibName = BasicLibNames(i)
22*cdf0e10cSrcweir		If LibName &lt;&gt; &quot;Standard&quot; Then
23*cdf0e10cSrcweir			BasicLibraries.SetLibraryReadOnly(LibName, bReadOnly)
24*cdf0e10cSrcweir		End If
25*cdf0e10cSrcweir	Next i
26*cdf0e10cSrcweirEnd Sub
27*cdf0e10cSrcweir
28*cdf0e10cSrcweir
29*cdf0e10cSrcweirSub WritedbgInfo(LocObject as Object)
30*cdf0e10cSrcweirDim locUrl as String
31*cdf0e10cSrcweirDim oLocDocument as Object
32*cdf0e10cSrcweirDim oLocText as Object
33*cdf0e10cSrcweirDim oLocCursor as Object
34*cdf0e10cSrcweirDim NoArgs()
35*cdf0e10cSrcweirDim sObjectStrings(2) as String
36*cdf0e10cSrcweirDim sProperties() as String
37*cdf0e10cSrcweirDim n as Integer
38*cdf0e10cSrcweirDim m as Integer
39*cdf0e10cSrcweirDim MaxIndex as Integer
40*cdf0e10cSrcweir	sObjectStrings(0) = LocObject.dbg_Properties
41*cdf0e10cSrcweir	sObjectStrings(1) = LocObject.dbg_Methods
42*cdf0e10cSrcweir	sObjectStrings(2) = LocObject.dbg_SupportedInterfaces
43*cdf0e10cSrcweir	LocUrl = &quot;private:factory/swriter&quot;
44*cdf0e10cSrcweir	oLocDocument = StarDesktop.LoadComponentFromURL(LocUrl,&quot;_default&quot;,0,NoArgs)
45*cdf0e10cSrcweir	oLocText = oLocDocument.text
46*cdf0e10cSrcweir	oLocCursor = oLocText.createTextCursor()
47*cdf0e10cSrcweir	oLocCursor.gotoStart(False)
48*cdf0e10cSrcweir	If Vartype(LocObject) = 9 then	&apos; an Object Variable
49*cdf0e10cSrcweir		For n = 0 To 2
50*cdf0e10cSrcweir			sProperties() = ArrayoutofString(sObjectStrings(n),&quot;;&quot;, MaxIndex)
51*cdf0e10cSrcweir			For m = 0 To MaxIndex
52*cdf0e10cSrcweir				oLocText.insertString(oLocCursor,sProperties(m),False)
53*cdf0e10cSrcweir				oLocText.insertControlCharacter(oLocCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
54*cdf0e10cSrcweir			Next m
55*cdf0e10cSrcweir		Next n
56*cdf0e10cSrcweir	Elseif Vartype(LocObject) = 8 Then	&apos; a String Variable
57*cdf0e10cSrcweir		oLocText.insertString(oLocCursor,LocObject,False)
58*cdf0e10cSrcweir	ElseIf Vartype(LocObject) = 1 Then
59*cdf0e10cSrcweir		Msgbox(&quot;Variable is Null!&quot;, 16, GetProductName())
60*cdf0e10cSrcweir	End If
61*cdf0e10cSrcweirEnd Sub
62*cdf0e10cSrcweir
63*cdf0e10cSrcweir
64*cdf0e10cSrcweirSub WriteDbgString(LocString as string)
65*cdf0e10cSrcweirDim oLocDesktop as object
66*cdf0e10cSrcweirDim LocUrl as String
67*cdf0e10cSrcweirDim oLocDocument as Object
68*cdf0e10cSrcweirDim oLocCursor as Object
69*cdf0e10cSrcweirDim oLocText as Object
70*cdf0e10cSrcweir
71*cdf0e10cSrcweir	LocUrl = &quot;private:factory/swriter&quot;
72*cdf0e10cSrcweir	oLocDocument = StarDesktop.LoadComponentFromURL(LocUrl,&quot;_default&quot;,0,NoArgs)
73*cdf0e10cSrcweir	oLocText = oLocDocument.text
74*cdf0e10cSrcweir	oLocCursor = oLocText.createTextCursor()
75*cdf0e10cSrcweir	oLocCursor.gotoStart(False)
76*cdf0e10cSrcweir	oLocText.insertString(oLocCursor,LocString,False)
77*cdf0e10cSrcweirEnd Sub
78*cdf0e10cSrcweir
79*cdf0e10cSrcweir
80*cdf0e10cSrcweirSub printdbgInfo(LocObject)
81*cdf0e10cSrcweir	If Vartype(LocObject) = 9 then
82*cdf0e10cSrcweir		Msgbox LocObject.dbg_properties
83*cdf0e10cSrcweir		Msgbox LocObject.dbg_methods
84*cdf0e10cSrcweir		Msgbox LocObject.dbg_supportedinterfaces
85*cdf0e10cSrcweir	Elseif Vartype(LocObject) = 8 Then	&apos; a String Variable
86*cdf0e10cSrcweir		Msgbox LocObject
87*cdf0e10cSrcweir	ElseIf Vartype(LocObject) = 0 Then
88*cdf0e10cSrcweir		Msgbox(&quot;Variable is Null!&quot;, 16, GetProductName())
89*cdf0e10cSrcweir	Else
90*cdf0e10cSrcweir		Msgbox(&quot;Type of Variable: &quot; &amp; Typename(LocObject), 48, GetProductName())
91*cdf0e10cSrcweir	End If
92*cdf0e10cSrcweirEnd Sub
93*cdf0e10cSrcweir
94*cdf0e10cSrcweir
95*cdf0e10cSrcweirSub ShowArray(LocArray())
96*cdf0e10cSrcweirDim i as integer
97*cdf0e10cSrcweirDim msgstring
98*cdf0e10cSrcweir	msgstring = &quot;&quot;
99*cdf0e10cSrcweir	For i = Lbound(LocArray()) to Ubound(LocArray())
100*cdf0e10cSrcweir		msgstring = msgstring + LocArray(i) + chr(13)
101*cdf0e10cSrcweir	Next
102*cdf0e10cSrcweir	Msgbox msgstring
103*cdf0e10cSrcweirEnd Sub
104*cdf0e10cSrcweir
105*cdf0e10cSrcweir
106*cdf0e10cSrcweirSub ShowPropertyValues(oLocObject as Object)
107*cdf0e10cSrcweirDim PropName as String
108*cdf0e10cSrcweirDim sValues as String
109*cdf0e10cSrcweir	On Local Error Goto NOPROPERTYSETINFO:
110*cdf0e10cSrcweir	sValues = &quot;&quot;
111*cdf0e10cSrcweir	For i = 0 To Ubound(oLocObject.PropertySetInfo.Properties)
112*cdf0e10cSrcweir		Propname = oLocObject.PropertySetInfo.Properties(i).Name
113*cdf0e10cSrcweir		sValues = sValues &amp; PropName &amp; chr(13) &amp; &quot; = &quot; &amp; oLocObject.GetPropertyValue(PropName) &amp; chr(13)
114*cdf0e10cSrcweir	Next i
115*cdf0e10cSrcweir	Msgbox(sValues , 64, GetProductName())
116*cdf0e10cSrcweir	Exit Sub
117*cdf0e10cSrcweir
118*cdf0e10cSrcweirNOPROPERTYSETINFO:
119*cdf0e10cSrcweir	Msgbox(&quot;Sorry, No PropertySetInfo attached to the object&quot;, 16, GetProductName())
120*cdf0e10cSrcweir	Resume LEAVEPROC
121*cdf0e10cSrcweir	LEAVEPROC:
122*cdf0e10cSrcweirEnd Sub
123*cdf0e10cSrcweir
124*cdf0e10cSrcweir
125*cdf0e10cSrcweirSub ShowNameValuePair(Pair())
126*cdf0e10cSrcweirDim i as Integer
127*cdf0e10cSrcweirDim ShowString as String
128*cdf0e10cSrcweir	ShowString = &quot;&quot;
129*cdf0e10cSrcweir	On Local Error Resume Next
130*cdf0e10cSrcweir	For i = 0 To Ubound(Pair())
131*cdf0e10cSrcweir		ShowString = ShowString &amp; Pair(i).Name &amp; &quot; = &quot;
132*cdf0e10cSrcweir		ShowString = ShowString &amp; Pair(i).Value &amp; chr(13)
133*cdf0e10cSrcweir	Next i
134*cdf0e10cSrcweir	Msgbox ShowString
135*cdf0e10cSrcweirEnd Sub
136*cdf0e10cSrcweir
137*cdf0e10cSrcweir
138*cdf0e10cSrcweir&apos; Retrieves all the Elements of aSequence of an object, with the
139*cdf0e10cSrcweir&apos; possibility to define a filter(sfilter &lt;&gt; &quot;&quot;)
140*cdf0e10cSrcweirSub ShowElementNames(oLocElements() as Object, Optional sFiltername as String)
141*cdf0e10cSrcweirDim i as Integer
142*cdf0e10cSrcweirDim NameString as String
143*cdf0e10cSrcweir	NameString = &quot;&quot;
144*cdf0e10cSrcweir	For i = 0 To Ubound(oLocElements())
145*cdf0e10cSrcweir		If Not IsMissIng(sFilterName) Then
146*cdf0e10cSrcweir			If Instr(1, oLocElements(i), sFilterName) Then
147*cdf0e10cSrcweir				NameString = NameString &amp; oLocElements(i) &amp; chr(13)
148*cdf0e10cSrcweir			End If
149*cdf0e10cSrcweir		Else
150*cdf0e10cSrcweir			NameString = NameString &amp; oLocElements(i) &amp; chr(13)
151*cdf0e10cSrcweir		End If
152*cdf0e10cSrcweir	Next i
153*cdf0e10cSrcweir	Msgbox(NameString, 64, GetProductName())
154*cdf0e10cSrcweirEnd Sub
155*cdf0e10cSrcweir
156*cdf0e10cSrcweir
157*cdf0e10cSrcweir&apos; Retrieves all the supported servicenames of an object, with the
158*cdf0e10cSrcweir&apos; possibility to define a filter(sfilter &lt;&gt; &quot;&quot;)
159*cdf0e10cSrcweirSub ShowSupportedServiceNames(oLocObject as Object, Optional sFilterName as String)
160*cdf0e10cSrcweir	On Local Error Goto NOSERVICENAMES
161*cdf0e10cSrcweir	If IsMissing(sFilterName) Then
162*cdf0e10cSrcweir		ShowElementNames(oLocobject.SupportedServiceNames())
163*cdf0e10cSrcweir	Else
164*cdf0e10cSrcweir		ShowElementNames(oLocobject.SupportedServiceNames(), sFilterName)
165*cdf0e10cSrcweir	End If
166*cdf0e10cSrcweir	Exit Sub
167*cdf0e10cSrcweir
168*cdf0e10cSrcweir	NOSERVICENAMES:
169*cdf0e10cSrcweir	Msgbox(&quot;Sorry, No &apos;SupportedServiceNames&apos; - Property attached to the object&quot;, 16, GetProductName())
170*cdf0e10cSrcweir	Resume LEAVEPROC
171*cdf0e10cSrcweir	LEAVEPROC:
172*cdf0e10cSrcweirEnd Sub
173*cdf0e10cSrcweir
174*cdf0e10cSrcweir
175*cdf0e10cSrcweir&apos; Retrieves all the available Servicenames of an object, with the
176*cdf0e10cSrcweir&apos; possibility to define a filter(sfilter &lt;&gt; &quot;&quot;)
177*cdf0e10cSrcweirSub ShowAvailableServiceNames(oLocObject as Object, Optional sFilterName as String)
178*cdf0e10cSrcweir	On Local Error Goto NOSERVICENAMES
179*cdf0e10cSrcweir	If IsMissing(sFilterName) Then
180*cdf0e10cSrcweir		ShowElementNames(oLocobject.AvailableServiceNames)
181*cdf0e10cSrcweir	Else
182*cdf0e10cSrcweir		ShowElementNames(oLocobject.AvailableServiceNames, sFilterName)
183*cdf0e10cSrcweir	End If
184*cdf0e10cSrcweir	Exit Sub
185*cdf0e10cSrcweir
186*cdf0e10cSrcweir	NOSERVICENAMES:
187*cdf0e10cSrcweir	Msgbox(&quot;Sorry, No &apos;AvailableServiceNames&apos; - Property attached to the object&quot;, 16, GetProductName())
188*cdf0e10cSrcweir	Resume LEAVEPROC
189*cdf0e10cSrcweir	LEAVEPROC:
190*cdf0e10cSrcweirEnd Sub
191*cdf0e10cSrcweir
192*cdf0e10cSrcweir
193*cdf0e10cSrcweirSub ShowCommands(oLocObject as Object)
194*cdf0e10cSrcweir	On Local Error Goto NOCOMMANDS
195*cdf0e10cSrcweir	ShowElementNames(oLocObject.QueryCommands)
196*cdf0e10cSrcweir	Exit Sub
197*cdf0e10cSrcweir	NOCOMMANDS:
198*cdf0e10cSrcweir	Msgbox(&quot;Sorry, No &apos;QueryCommands&apos; - Property attached to the object&quot;, 16, GetProductName())
199*cdf0e10cSrcweir	Resume LEAVEPROC
200*cdf0e10cSrcweir	LEAVEPROC:
201*cdf0e10cSrcweirEnd Sub
202*cdf0e10cSrcweir
203*cdf0e10cSrcweir
204*cdf0e10cSrcweirSub ProtectCurrentSheets()
205*cdf0e10cSrcweirDim oDocument as Object
206*cdf0e10cSrcweirDim sDocType as String
207*cdf0e10cSrcweirDim iResult as Integer
208*cdf0e10cSrcweirDim oSheets as Object
209*cdf0e10cSrcweirDim i as Integer
210*cdf0e10cSrcweirDim bDoProtect as Boolean
211*cdf0e10cSrcweir	oDocument = StarDesktop.ActiveFrame.Controller.Model
212*cdf0e10cSrcweir	sDocType = GetDocumentType(oDocument)
213*cdf0e10cSrcweir	If sDocType = &quot;scalc&quot; Then
214*cdf0e10cSrcweir		oSheets = oDocument.Sheets
215*cdf0e10cSrcweir		bDoProtect = False
216*cdf0e10cSrcweir		For i = 0 To oSheets.Count-1
217*cdf0e10cSrcweir			If Not oSheets(i).IsProtected Then
218*cdf0e10cSrcweir				bDoProtect = True
219*cdf0e10cSrcweir			End If
220*cdf0e10cSrcweir		Next i
221*cdf0e10cSrcweir		If bDoProtect Then
222*cdf0e10cSrcweir			iResult = Msgbox( &quot;Do you want to protect all sheets of this document?&quot;,35, GetProductName())
223*cdf0e10cSrcweir			If iResult = 6 Then
224*cdf0e10cSrcweir				ProtectSheets(oDocument.Sheets)
225*cdf0e10cSrcweir			End If
226*cdf0e10cSrcweir		End If
227*cdf0e10cSrcweir	End If
228*cdf0e10cSrcweirEnd Sub
229*cdf0e10cSrcweir
230*cdf0e10cSrcweir
231*cdf0e10cSrcweirSub FillDocument()
232*cdf0e10cSrcweir	oMyReport = createUNOService(&quot;com.sun.star.wizards.report.CallReportWizard&quot;)
233*cdf0e10cSrcweir	oMyReport.trigger(&quot;fill&quot;)
234*cdf0e10cSrcweirEnd Sub
235*cdf0e10cSrcweir
236*cdf0e10cSrcweir</script:module>