Debug.xba 7.7 KB

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