Functions.xba 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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="Functions" script:language="StarBasic">REM ***** BASIC *****
  21. Dim DialogVisible As Boolean
  22. Dim TutorStep As Integer
  23. Dim TutorLastStep As Integer
  24. Dim myDialog As Object
  25. Dim myTutorial As Object
  26. Public TutorText() As String
  27. Dim documentTitle As String
  28. Dim exampleUse As Object
  29. Dim properties() As Object
  30. Dim docTYP As String
  31. &apos;public myWidth As Long
  32. Dim myHeight As Long
  33. Dim oTextField As Object
  34. Dim stepTitle As String
  35. Dim oOpenDialogFlag
  36. Dim imageStatus As String
  37. Sub LoadTutorialDialog(exampleToUse, documentTYP)
  38. Init()
  39. exampleUse = exampleToUse
  40. TutorText() = exampleUse.LoadText()
  41. properties() = exampleUse.GetProperties()
  42. If properties(3).Value = &quot;True&quot; Then
  43. Dim localisation(0) As new com.sun.star.beans.NamedValue
  44. localisation(0).Name = &quot;Localisation&quot;
  45. localisation(0).Value = properties()
  46. myTutorial.execute(localisation())
  47. Else
  48. TutorStep = 0
  49. TutorLastStep = 0
  50. docTYP = documentTYP
  51. InitAction()
  52. ShowInfoMain()
  53. DialogVisible = True
  54. myDialog = LoadDialog(&quot;Tutorials&quot;,&quot;TutorialsDialog&quot;)
  55. SetTutorialDocumentPosSize()
  56. documentProps = ThisComponent.getDocumentProperties()
  57. myDialog.Title = &quot;Tutorials - &quot; &amp; documentProps.Title
  58. oTextField = myDialog.GetControl(&quot;myTextField&quot;)
  59. oTextField.setVisible(False)
  60. imageStatus = &quot;MIN&quot;
  61. setMaxMinImage(imageStatus)
  62. &apos;myWidth = myDialog.Size.Width
  63. myHeight = myDialog.Size.Height
  64. CheckForStepShowButtonStatus()
  65. CheckForStepNextButtonStatus()
  66. InitRoadMap()
  67. SetVisibleTrue()
  68. myDialog.model.myTextField.Label = stepTitle
  69. myDialog.model.myText.Label = GetStepText()&apos;TutorText(TutorStep)
  70. Do
  71. wait 1000
  72. Loop Until DialogVisible = False
  73. If( oOpenDialogFlag = True) Then
  74. Destroy()
  75. TutorialOpen.TutorialOpenMain()
  76. Else
  77. Destroy()
  78. End If
  79. End If
  80. End Sub
  81. Sub setMaxMinImage(param As String)
  82. On Local Error Goto NOIMAGE
  83. oCommandButton = myDialog.GetControl(&quot;CommandButton&quot;)
  84. templatePath = GetPathSettings(&quot;Template&quot;,false, 0)
  85. Dim bitmapPath As String
  86. iPos = InStr(templatePath,&quot;/&quot;)
  87. If(iPos &gt; 0) Then
  88. If(param = &quot;MAX&quot;) Then
  89. bitmapPath = templatePath &amp; &quot;../wizard/bitmap/maximize.png&quot;
  90. ElseIf(param = &quot;MIN&quot;) Then
  91. bitmapPath = templatePath &amp; &quot;../wizard/bitmap/minimize.png&quot;
  92. End If
  93. Else
  94. If(param = &quot;MAX&quot;) Then
  95. bitmapPath = templatePath &amp; &quot;..\wizard\bitmap\maximize.png&quot;
  96. ElseIf(param = &quot;MIN&quot;) Then
  97. bitmapPath = templatePath &amp; &quot;..\wizard\bitmap\minimize.png&quot;
  98. End If
  99. End If
  100. &apos;printdbgInfo oCommandButton.Model
  101. oCommandButton.Model.ImageUrl = bitmapPath
  102. Exit Sub
  103. NOIMAGE:
  104. End Sub
  105. Sub SetTutorialDocumentPosSize()
  106. activDesktopWindow = StarDesktop.activeFrame.ContainerWindow
  107. If(activDesktopWindow.posSize.Height &lt; 550) Then
  108. activDesktopWindow.setPosSize(0,0,0,550,8)
  109. End If
  110. If (activDesktopWindow.posSize.Width &lt; 750 ) Then
  111. activDesktopWindow.setPosSize(0,0,750,0,4)
  112. EndIf
  113. End Sub
  114. Sub InitRoadMap()
  115. RoadMapMain(Functions, myDialog)
  116. SetControlModelPosSize(0, 0, 85, 176)
  117. SetControlModelText(&quot;Steps&quot;)
  118. StepSize = Ubound(TutorText())
  119. Dim ItemsArray(StepSize) as String
  120. For i = 0 To StepSize
  121. stepcontent = TutorText(i)
  122. iPos = InStr(stepcontent,CHR(13))
  123. ItemName = Left(stepcontent, iPos)
  124. ItemsArray(i) = ItemName
  125. Next i
  126. InsertItemsLabels( ItemsArray())
  127. For i = 1 To StepSize
  128. SetItemEnabled( i, False)
  129. Next i
  130. SetItemEnabled( 0, True)
  131. End Sub
  132. Sub Destroy()
  133. &apos;myDialog.dispose
  134. wait 1000
  135. ShowInfoDialog.DisposeIDialog()
  136. &apos; THE DOCUMENT GETS CLOSED HERE!!!!!!!! GPF
  137. thisComponent.CurrentController.Frame.close(True)
  138. End Sub
  139. Sub Init
  140. GlobalScope.BasicLibraries.LoadLibrary(&quot;Tools&quot;)
  141. myTutorial = createUNOService(&quot;com.sun.star.wizards.tutorial.executer.CallTutorialFramework&quot;)
  142. documentTitle = ThisComponent.getCurrentController.getFrame.Title
  143. End Sub
  144. Sub InitStep
  145. udProps = ThisComponent.DocumentProperties.UserDefinedProperties
  146. If udProps.PropertySetInfo.hasPropertyByName(&quot;CurrentStep&quot;) Then
  147. TutorStep = udProps.CurrentStep
  148. Else
  149. udProps.addProperty(&quot;CurrentStep&quot;, 0, TutorStep)
  150. End If
  151. End Sub
  152. Sub setStep
  153. ThisComponent.DocumentProperties.UserDefinedProperties.CurrentStep = TutorStep
  154. End Sub
  155. Sub InitAction()
  156. SetStepTitle()
  157. Dim property(6) As new com.sun.star.beans.PropertyValue
  158. property(0).Name = &quot;DocumentTYP&quot;
  159. property(0).Value = docTYP
  160. property(1).Name = &quot;MethodName&quot;
  161. property(1).Value = &quot;setDelay&quot;
  162. property(2).Name = &quot;Param&quot;
  163. property(2).Value = 0 &apos;key insert speed (Millis)
  164. property(3).Name = &quot;Param&quot;
  165. property(3).Value = 4 &apos;mouse animate speed (Millis)
  166. property(4).Name = &quot;Param&quot;
  167. property(4).Value = 2000 &apos;after mouse animate sleep (Millis)
  168. property(5).Name = &quot;Param&quot;
  169. property(5).Value = 10 &apos;mouse scroll speed (Millis)
  170. property(6).Name = &quot;Param&quot;
  171. property(6).Value = -1 &apos;mouse speed (step)
  172. myTutorial.setPropertyValues(property())
  173. End Sub
  174. Sub EndDialog
  175. oOpenDialogFlag = False
  176. If (myDialog.model.done.Label = &quot;Close&quot;) Then
  177. TutorialCloseMain()
  178. Else
  179. DialogVisible = False
  180. End If
  181. End Sub
  182. Sub NextStep
  183. GotoStep(TutorStep + 1)
  184. End Sub
  185. Sub GotoStep(StepIndex)
  186. If(StepIndex &lt;= Ubound(TutorText())) Then
  187. TutorStep = StepIndex
  188. If TutorStep &gt; TutorLastStep Then
  189. TutorLastStep = TutorStep
  190. End If
  191. If(TutorStep = Ubound(TutorText())) Then
  192. myDialog.model.next.enabled = False
  193. myDialog.model.done.Label = &quot;Done&quot;
  194. myDialog.model.show.Label = &quot;Tutorials&quot;
  195. Else
  196. myDialog.model.next.enabled = True
  197. End If
  198. SetStepTitle()
  199. myDialog.model.myText.Label = GetStepText()
  200. CheckForStepShowButtonStatus()
  201. SetItemEnabled( TutorStep, True)
  202. &apos;setStep()
  203. End If
  204. End Sub
  205. Function GetStepText()
  206. Dim tempText As String
  207. tempText = TutorText(TutorStep)
  208. iPos = InStr(tempText,CHR(13))
  209. ResultString = Right(tempText, Len(tempText) - iPos - 1)
  210. GetStepText() = ResultString
  211. End Function
  212. Sub ItemChange(CurrentItemID, SelectitemID)
  213. GotoStep(SelectitemID)
  214. End Sub
  215. Sub SetDisableShowMeButton()
  216. myDialog.model.show.enabled = False
  217. TutorLastStep = TutorLastStep + 1
  218. End Sub
  219. Sub Minimize(aEvent)
  220. ActionItemsTextField = myDialog.GetControl(&quot;ActionItemsLabel&quot;)
  221. FixedLineVertikal = myDialog.GetControl(&quot;FixedLineVertikal&quot;)
  222. If myDialog.Size.Height = 35 Then
  223. myDialog.setPosSize(0,0,0,myHeight,8)
  224. oTextField.setVisible(False)
  225. ActionItemsTextField.setVisible(True)
  226. FixedLineVertikal.setVisible(True)
  227. RoadMap.SetVisibleRoadMap(True)
  228. Else
  229. myDialog.setPosSize(0,0,0,35,8)
  230. rmSelectedIndex = RoadMap.GetSelectedIndex() + 1
  231. gsTitle = GetStepTitle()
  232. oTextField.setText(rmSelectedIndex &amp; &quot;. &quot; &amp; gsTitle)
  233. oTextField.setVisible(True)
  234. ActionItemsTextField.setVisible(False)
  235. FixedLineVertikal.setVisible(False)
  236. RoadMap.SetVisibleRoadMap(False)
  237. End If
  238. If(imageStatus = &quot;MAX&quot;) Then
  239. imageStatus = &quot;MIN&quot;
  240. ElseIf(imageStatus = &quot;MIN&quot;) Then
  241. imageStatus = &quot;MAX&quot;
  242. End If
  243. setMaxMinImage(imageStatus)
  244. End Sub
  245. Sub SetStepTitle()
  246. stepcontent = TutorText(TutorStep)
  247. iPos = InStr(stepcontent,CHR(13))
  248. stepTitle = Left(stepcontent, iPos)
  249. SetStepTitle() = stepTitle
  250. End Sub
  251. Function GetStepTitle()
  252. GetStepTitle() = stepTitle
  253. End Function
  254. Sub CheckForStepShowButtonStatus()
  255. If ((exampleUse.ContainsStepAction() = True And TutorStep = TutorLastStep) Or myDialog.model.show.Label = &quot;Tutorials&quot;) Then
  256. myDialog.model.show.enabled = True
  257. Else
  258. myDialog.model.show.enabled = False
  259. End If
  260. End Sub
  261. Sub CheckForStepNextButtonStatus()
  262. If(TutorStep = Ubound(TutorText())) Then
  263. myDialog.model.next.enabled = False
  264. myDialog.model.done.Label = &quot;Done&quot;
  265. End If
  266. End Sub
  267. Sub Show(aEvent)
  268. &apos;ShowInfoMain()
  269. If( myDialog.model.show.Label = &quot;Tutorials&quot;) Then
  270. oOpenDialogFlag = True
  271. DialogVisible = False
  272. Else
  273. SetMousePosition(aEvent)
  274. exampleUse.Action()
  275. End If
  276. End Sub
  277. Sub SetMousePosition(aEvent)
  278. MyPoints() = MousePoints(aEvent)
  279. Dim mousePosition(3) as new com.sun.star.beans.PropertyValue
  280. mousePosition(0).Name = &quot;DocumentTYP&quot;
  281. mousePosition(0).Value = docTYP
  282. mousePosition(1).Name = &quot;MethodName&quot;
  283. mousePosition(1).Value = &quot;setMousePosition&quot;
  284. mousePosition(2).Name = &quot;Param&quot;
  285. mousePosition(2).Value = MyPoints(0)
  286. mousePosition(3).Name = &quot;Param&quot;
  287. mousePosition(3).Value = MyPoints(1)
  288. myTutorial.setPropertyValues(mousePosition())
  289. End Sub
  290. Function MousePoints(aEvent)
  291. Dim position(1) As Integer
  292. position(0) = myDialog.getControl(&quot;show&quot;).AccessibleContext.LocationOnScreen.X + aEvent.Source.Model.PositionX
  293. position(1) = myDialog.getControl(&quot;show&quot;).AccessibleContext.LocationOnScreen.Y + aEvent.Source.Model.PositionY
  294. MousePoints = position()
  295. End Function
  296. Function CheckPath(path() As String)
  297. &apos;documentTitle = ThisComponent.getCurrentController.getFrame.Title
  298. sTitle = path(0)
  299. ResultString = Right(sTitle, 3)
  300. iPos = InStr(ResultString,&quot;#&quot;)
  301. ResultString = Right(ResultString, Len(ResultString) - iPos)
  302. ResultFrameString = InStr (sTitle, &quot;{D}FRAME#&quot;)
  303. If ResultFrameString &lt;&gt; 0 Then
  304. If Not (sTitle = (&quot;{D}FRAME#&quot; &amp; documentTitle &amp; &quot;#&quot; &amp; ResultString)) Then
  305. &apos;path(0) = &quot;{D}FRAME#&quot; &amp; documentTitle &amp; &quot;#&quot; &amp; ResultString
  306. path(0) = &quot;FRAME#&quot; &amp; documentTitle &amp; &quot;#&quot; &amp; ResultString
  307. sTitle = path(1)
  308. ResultString = Right(sTitle, 3)
  309. iPos = InStr(ResultString,&quot;#&quot;)
  310. ResultString = Right(ResultString, Len(ResultString) - iPos)
  311. path(1) = &quot;ROOT_PANE#&quot; &amp; documentTitle &amp; &quot;#&quot; &amp; ResultString
  312. Else
  313. &apos;path(0) = &quot;{D}FRAME#&quot; &amp; documentTitle &amp; &quot;#&quot; &amp; ResultString
  314. path(0) = &quot;FRAME#&quot; &amp; documentTitle &amp; &quot;#&quot; &amp; ResultString
  315. End If
  316. End If
  317. End Function
  318. Sub SetVisibleTutorialsDialog(param)
  319. myDialog.setVisible(param)
  320. End Sub
  321. Sub SetVisibleTrue()
  322. myDialog.setVisible(True)
  323. End Sub
  324. Sub SetVisibleFalse()
  325. myDialog.setVisible(False)
  326. End Sub
  327. Sub ExitTutorial()
  328. Dim aUrl As new com.sun.star.util.URL
  329. oDoc = ThisComponent
  330. urlTransformer = createUNOService(&quot;com.sun.star.util.URLTransformer&quot;)
  331. aUrl.Complete = &quot;slot:5621&quot;
  332. urlTransformer.parseStrict(aUrl)
  333. xController = oDoc.getCurrentController()
  334. xDispatcher = xController.queryDispatch(aUrl, &quot;&quot;, 0)
  335. if NOT isNull(xDispatcher) then
  336. xDispatcher.dispatch(aUrl, DimArray())
  337. else
  338. msgBox &quot;Error! Cannot close document.&quot;
  339. End If
  340. End Sub
  341. </script:module>