Debug.xba 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
  3. <!--***********************************************************
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. ***********************************************************-->
  23. <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Debug" script:language="StarBasic">REM ***** BASIC *****
  24. Sub ActivateReadOnlyFlag()
  25. SetBasicReadOnlyFlag(True)
  26. End Sub
  27. Sub DeactivateReadOnlyFlag()
  28. SetBasicReadOnlyFlag(False)
  29. End Sub
  30. Sub SetBasicReadOnlyFlag(bReadOnly as Boolean)
  31. Dim i as Integer
  32. Dim LibName as String
  33. Dim BasicLibNames() as String
  34. BasicLibNames() = BasicLibraries.ElementNames()
  35. For i = 0 To Ubound(BasicLibNames())
  36. LibName = BasicLibNames(i)
  37. If LibName &lt;&gt; &quot;Standard&quot; Then
  38. BasicLibraries.SetLibraryReadOnly(LibName, bReadOnly)
  39. End If
  40. Next i
  41. End Sub
  42. Sub WritedbgInfo(LocObject as Object)
  43. Dim locUrl as String
  44. Dim oLocDocument as Object
  45. Dim oLocText as Object
  46. Dim oLocCursor as Object
  47. Dim NoArgs()
  48. Dim sObjectStrings(2) as String
  49. Dim sProperties() as String
  50. Dim n as Integer
  51. Dim m as Integer
  52. Dim MaxIndex as Integer
  53. sObjectStrings(0) = LocObject.dbg_Properties
  54. sObjectStrings(1) = LocObject.dbg_Methods
  55. sObjectStrings(2) = LocObject.dbg_SupportedInterfaces
  56. LocUrl = &quot;private:factory/swriter&quot;
  57. oLocDocument = StarDesktop.LoadComponentFromURL(LocUrl,&quot;_default&quot;,0,NoArgs)
  58. oLocText = oLocDocument.text
  59. oLocCursor = oLocText.createTextCursor()
  60. oLocCursor.gotoStart(False)
  61. If Vartype(LocObject) = 9 then &apos; an Object Variable
  62. For n = 0 To 2
  63. sProperties() = ArrayoutofString(sObjectStrings(n),&quot;;&quot;, MaxIndex)
  64. For m = 0 To MaxIndex
  65. oLocText.insertString(oLocCursor,sProperties(m),False)
  66. oLocText.insertControlCharacter(oLocCursor,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,False)
  67. Next m
  68. Next n
  69. Elseif Vartype(LocObject) = 8 Then &apos; a String Variable
  70. oLocText.insertString(oLocCursor,LocObject,False)
  71. ElseIf Vartype(LocObject) = 1 Then
  72. Msgbox(&quot;Variable is Null!&quot;, 16, GetProductName())
  73. End If
  74. End Sub
  75. Sub WriteDbgString(LocString as string)
  76. Dim oLocDesktop as object
  77. Dim LocUrl as String
  78. Dim oLocDocument as Object
  79. Dim oLocCursor as Object
  80. Dim oLocText as Object
  81. LocUrl = &quot;private:factory/swriter&quot;
  82. oLocDocument = StarDesktop.LoadComponentFromURL(LocUrl,&quot;_default&quot;,0,NoArgs)
  83. oLocText = oLocDocument.text
  84. oLocCursor = oLocText.createTextCursor()
  85. oLocCursor.gotoStart(False)
  86. oLocText.insertString(oLocCursor,LocString,False)
  87. End Sub
  88. Sub printdbgInfo(LocObject)
  89. If Vartype(LocObject) = 9 then
  90. Msgbox LocObject.dbg_properties
  91. Msgbox LocObject.dbg_methods
  92. Msgbox LocObject.dbg_supportedinterfaces
  93. Elseif Vartype(LocObject) = 8 Then &apos; a String Variable
  94. Msgbox LocObject
  95. ElseIf Vartype(LocObject) = 0 Then
  96. Msgbox(&quot;Variable is Null!&quot;, 16, GetProductName())
  97. Else
  98. Msgbox(&quot;Type of Variable: &quot; &amp; Typename(LocObject), 48, GetProductName())
  99. End If
  100. End Sub
  101. Sub ShowArray(LocArray())
  102. Dim i as integer
  103. Dim msgstring
  104. msgstring = &quot;&quot;
  105. For i = Lbound(LocArray()) to Ubound(LocArray())
  106. msgstring = msgstring + LocArray(i) + chr(13)
  107. Next
  108. Msgbox msgstring
  109. End Sub
  110. Sub ShowPropertyValues(oLocObject as Object)
  111. Dim PropName as String
  112. Dim sValues as String
  113. On Local Error Goto NOPROPERTYSETINFO:
  114. sValues = &quot;&quot;
  115. For i = 0 To Ubound(oLocObject.PropertySetInfo.Properties)
  116. Propname = oLocObject.PropertySetInfo.Properties(i).Name
  117. sValues = sValues &amp; PropName &amp; chr(13) &amp; &quot; = &quot; &amp; oLocObject.GetPropertyValue(PropName) &amp; chr(13)
  118. Next i
  119. Msgbox(sValues , 64, GetProductName())
  120. Exit Sub
  121. NOPROPERTYSETINFO:
  122. Msgbox(&quot;Sorry, No PropertySetInfo attached to the object&quot;, 16, GetProductName())
  123. Resume LEAVEPROC
  124. LEAVEPROC:
  125. End Sub
  126. Sub ShowNameValuePair(Pair())
  127. Dim i as Integer
  128. Dim ShowString as String
  129. ShowString = &quot;&quot;
  130. On Local Error Resume Next
  131. For i = 0 To Ubound(Pair())
  132. ShowString = ShowString &amp; Pair(i).Name &amp; &quot; = &quot;
  133. ShowString = ShowString &amp; Pair(i).Value &amp; chr(13)
  134. Next i
  135. Msgbox ShowString
  136. End Sub
  137. &apos; Retrieves all the Elements of aSequence of an object, with the
  138. &apos; possibility to define a filter(sfilter &lt;&gt; &quot;&quot;)
  139. Sub ShowElementNames(oLocElements() as Object, Optional sFiltername as String)
  140. Dim i as Integer
  141. Dim NameString as String
  142. NameString = &quot;&quot;
  143. For i = 0 To Ubound(oLocElements())
  144. If Not IsMissIng(sFilterName) Then
  145. If Instr(1, oLocElements(i), sFilterName) Then
  146. NameString = NameString &amp; oLocElements(i) &amp; chr(13)
  147. End If
  148. Else
  149. NameString = NameString &amp; oLocElements(i) &amp; chr(13)
  150. End If
  151. Next i
  152. Msgbox(NameString, 64, GetProductName())
  153. End Sub
  154. &apos; Retrieves all the supported servicenames of an object, with the
  155. &apos; possibility to define a filter(sfilter &lt;&gt; &quot;&quot;)
  156. Sub ShowSupportedServiceNames(oLocObject as Object, Optional sFilterName as String)
  157. On Local Error Goto NOSERVICENAMES
  158. If IsMissing(sFilterName) Then
  159. ShowElementNames(oLocobject.SupportedServiceNames())
  160. Else
  161. ShowElementNames(oLocobject.SupportedServiceNames(), sFilterName)
  162. End If
  163. Exit Sub
  164. NOSERVICENAMES:
  165. Msgbox(&quot;Sorry, No &apos;SupportedServiceNames&apos; - Property attached to the object&quot;, 16, GetProductName())
  166. Resume LEAVEPROC
  167. LEAVEPROC:
  168. End Sub
  169. &apos; Retrieves all the available Servicenames of an object, with the
  170. &apos; possibility to define a filter(sfilter &lt;&gt; &quot;&quot;)
  171. Sub ShowAvailableServiceNames(oLocObject as Object, Optional sFilterName as String)
  172. On Local Error Goto NOSERVICENAMES
  173. If IsMissing(sFilterName) Then
  174. ShowElementNames(oLocobject.AvailableServiceNames)
  175. Else
  176. ShowElementNames(oLocobject.AvailableServiceNames, sFilterName)
  177. End If
  178. Exit Sub
  179. NOSERVICENAMES:
  180. Msgbox(&quot;Sorry, No &apos;AvailableServiceNames&apos; - Property attached to the object&quot;, 16, GetProductName())
  181. Resume LEAVEPROC
  182. LEAVEPROC:
  183. End Sub
  184. Sub ShowCommands(oLocObject as Object)
  185. On Local Error Goto NOCOMMANDS
  186. ShowElementNames(oLocObject.QueryCommands)
  187. Exit Sub
  188. NOCOMMANDS:
  189. Msgbox(&quot;Sorry, No &apos;QueryCommands&apos; - Property attached to the object&quot;, 16, GetProductName())
  190. Resume LEAVEPROC
  191. LEAVEPROC:
  192. End Sub
  193. Sub ProtectCurrentSheets()
  194. Dim oDocument as Object
  195. Dim sDocType as String
  196. Dim iResult as Integer
  197. Dim oSheets as Object
  198. Dim i as Integer
  199. Dim bDoProtect as Boolean
  200. oDocument = StarDesktop.ActiveFrame.Controller.Model
  201. sDocType = GetDocumentType(oDocument)
  202. If sDocType = &quot;scalc&quot; Then
  203. oSheets = oDocument.Sheets
  204. bDoProtect = False
  205. For i = 0 To oSheets.Count-1
  206. If Not oSheets(i).IsProtected Then
  207. bDoProtect = True
  208. End If
  209. Next i
  210. If bDoProtect Then
  211. iResult = Msgbox( &quot;Do you want to protect all sheets of this document?&quot;,35, GetProductName())
  212. If iResult = 6 Then
  213. ProtectSheets(oDocument.Sheets)
  214. End If
  215. End If
  216. End If
  217. End Sub
  218. Sub FillDocument()
  219. oMyReport = createUNOService(&quot;com.sun.star.wizards.report.CallReportWizard&quot;)
  220. oMyReport.trigger(&quot;fill&quot;)
  221. End Sub
  222. </script:module>