ModuleAgenda.xba 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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="ModuleAgenda" script:language="StarBasic">&apos; All variables must be declared before use
  21. Option Explicit
  22. &apos; Used for &quot;disabling&quot; the cancel button of the dialog
  23. Public DialogExited As Boolean
  24. Dim DlgAgenda_gMyName as String
  25. Public TemplateDialog as Object
  26. Public DialogModel as Object
  27. Public sTrueContent as String
  28. Public Bookmarkname as String
  29. Sub Initialize()
  30. &apos; User sets the type of minutes
  31. BasicLibraries.LoadLibrary( &quot;Tools&quot; )
  32. TemplateDialog = LoadDialog(&quot;Template&quot;, &quot;TemplateDialog&quot;)
  33. DialogModel = TemplateDialog.Model
  34. DialogModel.Step = 1
  35. LoadLanguageAgenda()
  36. DialogModel.OptAgenda2.State = TRUE
  37. GetOptionValues()
  38. DialogExited = FALSE
  39. TemplateDialog.Execute
  40. End Sub
  41. Sub LoadLanguageAgenda()
  42. If InitResources(&quot;&apos;Template&apos;&quot;) Then
  43. DlgAgenda_gMyName = GetResText(&quot;AgendaDlgName&quot;)
  44. DialogModel.CmdCancel.Label = GetResText(&quot;STYLES_2&quot;)
  45. DialogModel.CmdAgdGoon.Label = GetResText(&quot;STYLES_3&quot;)
  46. &apos; DlgAgenda_gMsgNoCancel$ = GetResText(&quot;AgendaDlgNoCancel&quot;)
  47. DialogModel.FrmAgenda.Label = GetResText(&quot;AgendaDlgFrame&quot;)
  48. DialogModel.OptAgenda1.Label = GetResText(&quot;AgendaDlgButton1&quot;)
  49. DialogModel.OptAgenda2.Label = GetResText(&quot;AgendaDlgButton2&quot;)
  50. &apos; DialogModel.OptAgenda1.State = 1
  51. End If
  52. End Sub
  53. Sub ModifyTemplate()
  54. Dim oDocument, oBookmarks, oBookmark, oBookmarkCursor, oTextField as Object
  55. Dim i as Integer
  56. oDocument = ThisComponent
  57. oBookMarks = oDocument.Bookmarks
  58. On Local Error Goto NOBOOKMARK
  59. TemplateDialog.EndExecute
  60. DialogExited = TRUE
  61. oBookmarkCursor = CreateBookmarkCursor(oDocument, BookmarkName)
  62. oBookmarkCursor.Text.insertString(oBookmarkCursor,&quot;&quot;,True)
  63. &apos; Delete all the Bookmarks except for the one named &quot;NextTopic&quot;
  64. For i = oBookmarks.Count-1 To 0 Step -1
  65. oBookMark = oBookMarks.GetByIndex(i)
  66. If oBookMark.Name &lt;&gt; &quot;NextTopic&quot; Then
  67. oBookMark.Dispose()
  68. End If
  69. Next i
  70. oBookMarkCursor = CreateBookmarkCursor(oDocument, &quot;NextTopic&quot;)
  71. If Not IsNull(oBookMarkCursor) Then
  72. oTextField = oBookMarkCursor.TextField
  73. &apos; oTextField.TrueContent = sTrueContent
  74. oTextField.Content = sTrueContent
  75. End If
  76. NOBOOKMARK:
  77. If Err &lt;&gt; 0 Then
  78. RESUME NEXT
  79. End If
  80. End Sub
  81. Sub NewTopic
  82. &apos; Add a new topic to the agenda
  83. Dim oDocument, oBookmarks, oBookmark, oBookmarkCursor, oTextField as Object
  84. Dim oBaustein, oAutoText, oAutoGroup as Object
  85. Dim i as Integer
  86. oDocument = ThisComponent
  87. oBookMarkCursor = CreateBookMarkCursor(oDocument, &quot;NextTopic&quot;)
  88. oTextField = oBookMarkCursor.TextField
  89. oAutoText = CreateUnoService(&quot;com.sun.star.text.AutoTextContainer&quot;)
  90. If oAutoText.HasbyName(&quot;template&quot;) Then
  91. oAutoGroup = oAutoText.GetbyName(&quot;template&quot;)
  92. If oAutoGroup.HasbyName(oTextField.Content) Then
  93. oBaustein = oAutoGroup.GetbyName(oTextField.Content)
  94. oBaustein.ApplyTo(oBookMarkCursor)
  95. Else
  96. Msgbox(&quot;AutoText &apos;&quot; &amp; oTextField.Content &amp; &quot;&apos; is not existing. Cannot insert additional topic!&quot;)
  97. End If
  98. Else
  99. Msgbox(&quot;AutoGroupField template is not existing. Cannot insert additional topic!&quot;, 16, DlgAgenda_gMyName )
  100. End If
  101. End Sub
  102. &apos; Add initials, date and time at bottom of agenda, disable and hide command buttons
  103. Sub FinishAgenda
  104. Dim BtnAddAgendaTopic As Object
  105. Dim BtnFinishAgenda As Object
  106. Dim oUserField, oDateTimeField as Object
  107. Dim oBookmarkCursor as Object
  108. Dim oFormats, oLocale as Object
  109. Dim iDateTimeKey as Integer
  110. BasicLibraries.LoadLibrary( &quot;Tools&quot; )
  111. oDocument = ThisComponent
  112. oUserField = oDocument.CreateInstance(&quot;com.sun.star.text.TextField.ExtendedUser&quot;)
  113. oUserField.UserDatatype = com.sun.star.text.UserDataPart.SHORTCUT
  114. oDateTimeField = oDocument.CreateInstance(&quot;com.sun.star.text.TextField.DateTime&quot;)
  115. &apos; Assign Standardformat to Datetime-Textfield
  116. oFormats = oDocument.Numberformats
  117. oLocale = oDocument.CharLocale
  118. iDateTimeKey = oFormats.GetStandardFormat(com.sun.star.util.NumberFormat.DATETIME,oLocale)
  119. oDateTimeField.NumberFormat = iDateTimeKey
  120. oBookmarkCursor = CreateBookmarkCursor(oDocument, &quot;NextTopic&quot;)
  121. oBookmarkCursor.Text.InsertTextContent(oBookmarkCursor,oUserField,False)
  122. oBookmarkCursor.Text.InsertString(oBookmarkCursor,&quot; &quot;,False)
  123. oBookmarkCursor.Text.InsertTextContent(oBookmarkCursor,oDateTimeField,False)
  124. BtnAddAgendaTopic = getControlModel(oDocument, &quot;BtnAddAgendaTopic&quot;)
  125. BtnFinishAgenda = getControlModel(oDocument, &quot;BtnFinishAgenda&quot;)
  126. If Not IsNull(BtnAddAgendaTopic) Then BtnAddAgendaTopic.Enabled = FALSE
  127. If Not IsNull(BtnFinishAgenda) Then BtnFinishAgenda.Enabled = FALSE
  128. End Sub
  129. Function CreateBookMarkCursor(oDocument as Object,sBookmarkName as String)
  130. oBookMarks = oDocument.Bookmarks
  131. If oBookmarks.HasbyName(sBookmarkName) Then
  132. oBookMark = oBookMarks.GetbyName(sBookmarkName)
  133. CreateBookMarkCursor = oBookMark.Anchor.Text.CreateTextCursorByRange(oBookMark.Anchor)
  134. Else
  135. Msgbox &quot;Bookmark &quot; &amp; sBookmarkName &amp; &quot; is not defined!&quot;
  136. End If
  137. End Function
  138. Sub DeleteButtons
  139. Dim AgendaFinished As Boolean
  140. Dim BtnAddAgendaTopic As Object
  141. Dim BtnFinishAgenda As Object
  142. oDocument = ThisComponent
  143. BtnAddAgendaTopic = getControlModel(oDocument, &quot;BtnAddAgendaTopic&quot;)
  144. BtnFinishAgenda = getControlModel(oDocument, &quot;BtnFinishAgenda&quot;)
  145. &apos; If buttons could be accessed: If at least one button is disabled, then agenda is finished
  146. AgendaFinished = FALSE
  147. If Not IsNull(BtnAddAgendaTopic) Then
  148. AgendaFinished = (AgendaFinished Or (BtnAddAgendaTopic.Enabled = FALSE))
  149. End If
  150. If Not IsNull(BtnFinishAgenda) Then
  151. AgendaFinished = (AgendaFinished Or (BtnFinishAgenda.Enabled = FALSE))
  152. End If
  153. &apos; Delete Buttons, empty rows at end of document &amp; macro bindings if agenda is finished
  154. If AgendaFinished Then
  155. DisposeControl(oDocument, &quot;BtnAddAgendaTopic&quot;)
  156. DisposeControl(oDocument, &quot;BtnFinishAgenda&quot;)
  157. oBookmarkCursor = CreateBookMarkCursor(oDocument,&quot;NextTopic&quot;)
  158. oBookMarkCursor.GotoEnd(True)
  159. oBookmarkCursor.Text.insertString(oBookmarkCursor,&quot;&quot;,True)
  160. AttachBasicMacroToEvent(oDocument,&quot;OnNew&quot;, &quot;&quot;)
  161. AttachBasicMacroToEvent(oDocument,&quot;OnSave&quot;, &quot;&quot;)
  162. AttachBasicMacroToEvent(oDocument,&quot;OnSaveAs&quot;, &quot;&quot;)
  163. AttachBasicMacroToEvent(oDocument,&quot;OnPrint&quot;, &quot;&quot;)
  164. End If
  165. End Sub
  166. Sub GetOptionValues(Optional aEvent as Object)
  167. Dim CurTag as String
  168. Dim Taglist() as String
  169. If Not IsMissing(aEvent) Then
  170. CurTag = aEvent.Source.Model.Tag
  171. Else
  172. If DialogModel.OptAgenda1.State = TRUE Then
  173. CurTag = DialogModel.OptAgenda1.Tag
  174. Else
  175. CurTag = DialogModel.OptAgenda2.Tag
  176. End If
  177. End If
  178. Taglist() = ArrayoutOfString(CurTag, &quot;;&quot;)
  179. Bookmarkname = TagList(0)
  180. sTrueContent = TagList(1)
  181. End Sub
  182. </script:module>