Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / wizards / source / template / ModuleAgenda.xba
bloba17fb68cd602e5ddd935b1eaf3529c1e2ec8ed58
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.
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/.
10 * This file incorporates work covered by the following license notice:
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
23 &apos; Used for &quot;disabling&quot; the cancel button of the dialog
24 Public DialogExited As Boolean
25 Dim DlgAgenda_gMyName as String
26 Public TemplateDialog as Object
27 Public DialogModel as Object
28 Public sTrueContent as String
29 Public Bookmarkname as String
33 Sub Initialize()
34 &apos; User sets the type of minutes
35 BasicLibraries.LoadLibrary( &quot;Tools&quot; )
36 TemplateDialog = LoadDialog(&quot;Template&quot;, &quot;TemplateDialog&quot;)
37 DialogModel = TemplateDialog.Model
38 DialogModel.Step = 1
39 LoadLanguageAgenda()
40 DialogModel.OptAgenda2.State = TRUE
41 GetOptionValues()
42 DialogExited = FALSE
43 TemplateDialog.Execute
44 End Sub
47 Sub LoadLanguageAgenda()
48 If InitResources(&quot;&apos;Template&apos;&quot;) Then
49 DlgAgenda_gMyName = GetResText(&quot;AgendaDlgName&quot;)
50 DialogModel.CmdCancel.Label = GetResText(&quot;STYLES_2&quot;)
51 DialogModel.CmdAgdGoon.Label = GetResText(&quot;STYLES_3&quot;)
52 &apos; DlgAgenda_gMsgNoCancel$ = GetResText(&quot;AgendaDlgNoCancel&quot;)
53 DialogModel.FrmAgenda.Label = GetResText(&quot;AgendaDlgFrame&quot;)
54 DialogModel.OptAgenda1.Label = GetResText(&quot;AgendaDlgButton1&quot;)
55 DialogModel.OptAgenda2.Label = GetResText(&quot;AgendaDlgButton2&quot;)
56 &apos; DialogModel.OptAgenda1.State = 1
57 End If
58 End Sub
61 Sub ModifyTemplate()
62 Dim oDocument, oBookmarks, oBookmark, oBookmarkCursor, oTextField as Object
63 Dim i as Integer
65 oDocument = ThisComponent
66 oBookMarks = oDocument.Bookmarks
68 On Local Error Goto NOBOOKMARK
69 TemplateDialog.EndExecute
70 DialogExited = TRUE
71 oBookmarkCursor = CreateBookmarkCursor(oDocument, BookmarkName)
72 oBookmarkCursor.Text.insertString(oBookmarkCursor,&quot;&quot;,True)
73 &apos; Delete all the Bookmarks except for the one named &quot;NextTopic&quot;
74 For i = oBookmarks.Count-1 To 0 Step -1
75 oBookMark = oBookMarks.GetByIndex(i)
76 If oBookMark.Name &lt;&gt; &quot;NextTopic&quot; Then
77 oBookMark.Dispose()
78 End If
79 Next i
80 oBookMarkCursor = CreateBookmarkCursor(oDocument, &quot;NextTopic&quot;)
81 If Not IsNull(oBookMarkCursor) Then
82 oTextField = oBookMarkCursor.TextField
83 &apos; oTextField.TrueContent = sTrueContent
84 oTextField.Content = sTrueContent
85 End If
87 NOBOOKMARK:
88 If Err &lt;&gt; 0 Then
89 RESUME NEXT
90 End If
91 End Sub
94 Sub NewTopic
95 &apos; Add a new topic to the agenda
96 Dim oDocument, oBookmarks, oBookmark, oBookmarkCursor, oTextField as Object
97 Dim oBaustein, oAutoText, oAutoGroup as Object
98 Dim i as Integer
100 oDocument = ThisComponent
101 oBookMarkCursor = CreateBookMarkCursor(oDocument, &quot;NextTopic&quot;)
102 oTextField = oBookMarkCursor.TextField
103 oAutoText = CreateUnoService(&quot;com.sun.star.text.AutoTextContainer&quot;)
104 If oAutoText.HasbyName(&quot;template&quot;) Then
105 oAutoGroup = oAutoText.GetbyName(&quot;template&quot;)
106 If oAutoGroup.HasbyName(oTextField.Content) Then
107 oBaustein = oAutoGroup.GetbyName(oTextField.Content)
108 oBaustein.ApplyTo(oBookMarkCursor)
109 Else
110 Msgbox(&quot;AutoText &apos;&quot; &amp; oTextField.Content &amp; &quot;&apos; is not existing. Cannot insert additional topic!&quot;)
111 End If
112 Else
113 Msgbox(&quot;AutoGroupField template is not existing. Cannot insert additional topic!&quot;, 16, DlgAgenda_gMyName )
114 End If
115 End Sub
119 &apos; Add initials, date and time at bottom of agenda, disable and hide command buttons
120 Sub FinishAgenda
121 Dim BtnAddAgendaTopic As Object
122 Dim BtnFinishAgenda As Object
123 Dim oUserField, oDateTimeField as Object
124 Dim oBookmarkCursor as Object
125 Dim oFormats, oLocale as Object
126 Dim iDateTimeKey as Integer
128 BasicLibraries.LoadLibrary( &quot;Tools&quot; )
129 oDocument = ThisComponent
131 oUserField = oDocument.CreateInstance(&quot;com.sun.star.text.TextField.ExtendedUser&quot;)
132 oUserField.UserDatatype = com.sun.star.text.UserDataPart.SHORTCUT
134 oDateTimeField = oDocument.CreateInstance(&quot;com.sun.star.text.TextField.DateTime&quot;)
136 &apos; Assign Standardformat to Datetime-Textfield
137 oFormats = oDocument.Numberformats
138 oLocale = oDocument.CharLocale
139 iDateTimeKey = oFormats.GetStandardFormat(com.sun.star.util.NumberFormat.DATETIME,oLocale)
140 oDateTimeField.NumberFormat = iDateTimeKey
142 oBookmarkCursor = CreateBookmarkCursor(oDocument, &quot;NextTopic&quot;)
143 oBookmarkCursor.Text.InsertTextContent(oBookmarkCursor,oUserField,False)
144 oBookmarkCursor.Text.InsertString(oBookmarkCursor,&quot; &quot;,False)
145 oBookmarkCursor.Text.InsertTextContent(oBookmarkCursor,oDateTimeField,False)
146 BtnAddAgendaTopic = getControlModel(oDocument, &quot;BtnAddAgendaTopic&quot;)
147 BtnFinishAgenda = getControlModel(oDocument, &quot;BtnFinishAgenda&quot;)
148 If Not IsNull(BtnAddAgendaTopic) Then BtnAddAgendaTopic.Enabled = FALSE
149 If Not IsNull(BtnFinishAgenda) Then BtnFinishAgenda.Enabled = FALSE
150 End Sub
153 Function CreateBookMarkCursor(oDocument as Object,sBookmarkName as String)
154 oBookMarks = oDocument.Bookmarks
155 If oBookmarks.HasbyName(sBookmarkName) Then
156 oBookMark = oBookMarks.GetbyName(sBookmarkName)
157 CreateBookMarkCursor = oBookMark.Anchor.Text.CreateTextCursorByRange(oBookMark.Anchor)
158 Else
159 Msgbox &quot;Bookmark &quot; &amp; sBookmarkName &amp; &quot; is not defined!&quot;
160 End If
161 End Function
165 Sub DeleteButtons
166 Dim AgendaFinished As Boolean
167 Dim BtnAddAgendaTopic As Object
168 Dim BtnFinishAgenda As Object
170 oDocument = ThisComponent
172 BtnAddAgendaTopic = getControlModel(oDocument, &quot;BtnAddAgendaTopic&quot;)
173 BtnFinishAgenda = getControlModel(oDocument, &quot;BtnFinishAgenda&quot;)
175 &apos; If buttons could be accessed: If at least one button is disabled, then agenda is finished
176 AgendaFinished = FALSE
177 If Not IsNull(BtnAddAgendaTopic) Then
178 AgendaFinished = (AgendaFinished Or (BtnAddAgendaTopic.Enabled = FALSE))
179 End If
181 If Not IsNull(BtnFinishAgenda) Then
182 AgendaFinished = (AgendaFinished Or (BtnFinishAgenda.Enabled = FALSE))
183 End If
185 &apos; Delete Buttons, empty rows at end of document &amp; macro bindings if agenda is finished
186 If AgendaFinished Then
187 DisposeControl(oDocument, &quot;BtnAddAgendaTopic&quot;)
188 DisposeControl(oDocument, &quot;BtnFinishAgenda&quot;)
190 oBookmarkCursor = CreateBookMarkCursor(oDocument,&quot;NextTopic&quot;)
191 oBookMarkCursor.GotoEnd(True)
192 oBookmarkCursor.Text.insertString(oBookmarkCursor,&quot;&quot;,True)
194 AttachBasicMacroToEvent(oDocument,&quot;OnNew&quot;, &quot;&quot;)
195 AttachBasicMacroToEvent(oDocument,&quot;OnSave&quot;, &quot;&quot;)
196 AttachBasicMacroToEvent(oDocument,&quot;OnSaveAs&quot;, &quot;&quot;)
197 AttachBasicMacroToEvent(oDocument,&quot;OnPrint&quot;, &quot;&quot;)
198 End If
199 End Sub
203 Sub GetOptionValues(Optional aEvent as Object)
204 Dim CurTag as String
205 Dim Taglist() as String
206 If Not IsMissing(aEvent) Then
207 CurTag = aEvent.Source.Model.Tag
208 Else
209 If DialogModel.OptAgenda1.State = TRUE Then
210 CurTag = DialogModel.OptAgenda1.Tag
211 Else
212 CurTag = DialogModel.OptAgenda2.Tag
213 End If
214 End If
215 Taglist() = ArrayoutOfString(CurTag, &quot;;&quot;)
216 Bookmarkname = TagList(0)
217 sTrueContent = TagList(1)
218 End Sub
220 </script:module>