ModuleAgenda.xba 7.9 KB

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