1cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3*3e02b54dSAndrew Rist<!--***********************************************************
4*3e02b54dSAndrew Rist *
5*3e02b54dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
6*3e02b54dSAndrew Rist * or more contributor license agreements.  See the NOTICE file
7*3e02b54dSAndrew Rist * distributed with this work for additional information
8*3e02b54dSAndrew Rist * regarding copyright ownership.  The ASF licenses this file
9*3e02b54dSAndrew Rist * to you under the Apache License, Version 2.0 (the
10*3e02b54dSAndrew Rist * "License"); you may not use this file except in compliance
11*3e02b54dSAndrew Rist * with the License.  You may obtain a copy of the License at
12*3e02b54dSAndrew Rist *
13*3e02b54dSAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
14*3e02b54dSAndrew Rist *
15*3e02b54dSAndrew Rist * Unless required by applicable law or agreed to in writing,
16*3e02b54dSAndrew Rist * software distributed under the License is distributed on an
17*3e02b54dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18*3e02b54dSAndrew Rist * KIND, either express or implied.  See the License for the
19*3e02b54dSAndrew Rist * specific language governing permissions and limitations
20*3e02b54dSAndrew Rist * under the License.
21*3e02b54dSAndrew Rist *
22*3e02b54dSAndrew Rist ***********************************************************-->
23cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ModuleAgenda" script:language="StarBasic">&apos; All variables must be declared before use
24cdf0e10cSrcweirOption Explicit
25cdf0e10cSrcweir
26cdf0e10cSrcweir&apos; Used for &quot;disabling&quot; the cancel button of the dialog
27cdf0e10cSrcweirPublic DialogExited As Boolean
28cdf0e10cSrcweirDim DlgAgenda_gMyName as String
29cdf0e10cSrcweirPublic TemplateDialog as Object
30cdf0e10cSrcweirPublic DialogModel as Object
31cdf0e10cSrcweirPublic sTrueContent as String
32cdf0e10cSrcweirPublic Bookmarkname as String
33cdf0e10cSrcweir
34cdf0e10cSrcweir
35cdf0e10cSrcweir
36cdf0e10cSrcweirSub Initialize()
37cdf0e10cSrcweir&apos; User sets the type of minutes
38cdf0e10cSrcweir        BasicLibraries.LoadLibrary( &quot;Tools&quot; )
39cdf0e10cSrcweir	TemplateDialog = LoadDialog(&quot;Template&quot;, &quot;TemplateDialog&quot;)
40cdf0e10cSrcweir	DialogModel = TemplateDialog.Model
41cdf0e10cSrcweir	DialogModel.Step = 1
42cdf0e10cSrcweir	LoadLanguageAgenda()
43cdf0e10cSrcweir	DialogModel.OptAgenda2.State = TRUE
44cdf0e10cSrcweir	GetOptionValues()
45cdf0e10cSrcweir	DialogExited = FALSE
46cdf0e10cSrcweir	TemplateDialog.Execute
47cdf0e10cSrcweirEnd Sub
48cdf0e10cSrcweir
49cdf0e10cSrcweir
50cdf0e10cSrcweirSub LoadLanguageAgenda()
51cdf0e10cSrcweir	If InitResources(&quot;&apos;Template&apos;&quot;, &quot;tpl&quot;) Then
52cdf0e10cSrcweir		DlgAgenda_gMyName = GetResText(1200)
53cdf0e10cSrcweir		DialogModel.CmdCancel.Label = GetResText(1102)
54cdf0e10cSrcweir		DialogModel.CmdAgdGoon.Label = GetResText(1103)
55cdf0e10cSrcweir&apos;		DlgAgenda_gMsgNoCancel$ = GetResText(1201)
56cdf0e10cSrcweir		DialogModel.FrmAgenda.Label = GetResText(1202)
57cdf0e10cSrcweir		DialogModel.OptAgenda1.Label = GetResText(1203)
58cdf0e10cSrcweir		DialogModel.OptAgenda2.Label = GetResText(1204)
59cdf0e10cSrcweir&apos;		DialogModel.OptAgenda1.State = 1
60cdf0e10cSrcweir	End If
61cdf0e10cSrcweirEnd Sub
62cdf0e10cSrcweir
63cdf0e10cSrcweir
64cdf0e10cSrcweirSub ModifyTemplate()
65cdf0e10cSrcweirDim oDocument, oBookmarks, oBookmark, oBookmarkCursor, oTextField as Object
66cdf0e10cSrcweirDim i as Integer
67cdf0e10cSrcweir
68cdf0e10cSrcweir  oDocument = ThisComponent
69cdf0e10cSrcweir	oBookMarks = oDocument.Bookmarks
70cdf0e10cSrcweir
71cdf0e10cSrcweir	On Local Error Goto NOBOOKMARK
72cdf0e10cSrcweir	TemplateDialog.EndExecute
73cdf0e10cSrcweir	DialogExited = TRUE
74cdf0e10cSrcweir	oBookmarkCursor = CreateBookmarkCursor(oDocument, BookmarkName)
75cdf0e10cSrcweir	oBookmarkCursor.Text.insertString(oBookmarkCursor,&quot;&quot;,True)
76cdf0e10cSrcweir	&apos; Delete all the Bookmarks except for the one named &quot;NextTopic&quot;
77cdf0e10cSrcweir	For i = oBookmarks.Count-1 To 0 Step -1
78cdf0e10cSrcweir		oBookMark = oBookMarks.GetByIndex(i)
79cdf0e10cSrcweir		If oBookMark.Name &lt;&gt; &quot;NextTopic&quot; Then
80cdf0e10cSrcweir			oBookMark.Dispose()
81cdf0e10cSrcweir		End If
82cdf0e10cSrcweir	Next i
83cdf0e10cSrcweir	oBookMarkCursor = CreateBookmarkCursor(oDocument, &quot;NextTopic&quot;)
84cdf0e10cSrcweir	If Not IsNull(oBookMarkCursor) Then
85cdf0e10cSrcweir		oTextField = oBookMarkCursor.TextField
86cdf0e10cSrcweir&apos;		oTextField.TrueContent = 	sTrueContent
87cdf0e10cSrcweir		oTextField.Content = sTrueContent
88cdf0e10cSrcweir	End If
89cdf0e10cSrcweir
90cdf0e10cSrcweir	NOBOOKMARK:
91cdf0e10cSrcweir	If Err &lt;&gt; 0 Then
92cdf0e10cSrcweir		RESUME NEXT
93cdf0e10cSrcweir	End If
94cdf0e10cSrcweirEnd Sub
95cdf0e10cSrcweir
96cdf0e10cSrcweir
97cdf0e10cSrcweirSub NewTopic
98cdf0e10cSrcweir&apos; Add a new topic to the agenda
99cdf0e10cSrcweirDim oDocument, oBookmarks, oBookmark, oBookmarkCursor, oTextField as Object
100cdf0e10cSrcweirDim oBaustein, oAutoText, oAutoGroup as Object
101cdf0e10cSrcweirDim i as Integer
102cdf0e10cSrcweir
103cdf0e10cSrcweir  	oDocument = ThisComponent
104cdf0e10cSrcweir	oBookMarkCursor = CreateBookMarkCursor(oDocument, &quot;NextTopic&quot;)
105cdf0e10cSrcweir	oTextField = oBookMarkCursor.TextField
106cdf0e10cSrcweir	oAutoText = CreateUnoService(&quot;com.sun.star.text.AutoTextContainer&quot;)
107cdf0e10cSrcweir	If oAutoText.HasbyName(&quot;template&quot;) Then
108cdf0e10cSrcweir		oAutoGroup = oAutoText.GetbyName(&quot;template&quot;)
109cdf0e10cSrcweir		If oAutoGroup.HasbyName(oTextField.Content) Then
110cdf0e10cSrcweir			oBaustein = oAutoGroup.GetbyName(oTextField.Content)
111cdf0e10cSrcweir			oBaustein.ApplyTo(oBookMarkCursor)
112cdf0e10cSrcweir		Else
113cdf0e10cSrcweir			Msgbox(&quot;AutoText &apos;&quot; &amp; oTextField.Content &amp; &quot;&apos; is not existing. Cannot insert additional topic!&quot;)
114cdf0e10cSrcweir		End If
115cdf0e10cSrcweir	Else
116cdf0e10cSrcweir		Msgbox(&quot;AutoGroupField template is not existing. Cannot insert additional topic!&quot;, 16, DlgAgenda_gMyName )
117cdf0e10cSrcweir	End If
118cdf0e10cSrcweirEnd Sub
119cdf0e10cSrcweir
120cdf0e10cSrcweir
121cdf0e10cSrcweir
122cdf0e10cSrcweir&apos; Add initials, date and time at bottom of agenda, disable and hide command buttons
123cdf0e10cSrcweirSub FinishAgenda
124cdf0e10cSrcweirDim BtnAddAgendaTopic As Object
125cdf0e10cSrcweirDim BtnFinishAgenda As Object
126cdf0e10cSrcweirDim oUserField, oDateTimeField as Object
127cdf0e10cSrcweirDim oBookmarkCursor as Object
128cdf0e10cSrcweirDim oFormats, oLocale as Object
129cdf0e10cSrcweirDim iDateTimeKey as Integer
130cdf0e10cSrcweir
131cdf0e10cSrcweir        BasicLibraries.LoadLibrary( &quot;Tools&quot; )
132cdf0e10cSrcweir  oDocument = ThisComponent
133cdf0e10cSrcweir
134cdf0e10cSrcweir	oUserField = oDocument.CreateInstance(&quot;com.sun.star.text.TextField.ExtendedUser&quot;)
135cdf0e10cSrcweir	oUserField.UserDatatype = com.sun.star.text.UserDataPart.SHORTCUT
136cdf0e10cSrcweir
137cdf0e10cSrcweir	oDateTimeField = oDocument.CreateInstance(&quot;com.sun.star.text.TextField.DateTime&quot;)
138cdf0e10cSrcweir
139cdf0e10cSrcweir	&apos; Assign Standardformat to Datetime-Textfield
140cdf0e10cSrcweir	oFormats = oDocument.Numberformats
141cdf0e10cSrcweir	oLocale = oDocument.CharLocale
142cdf0e10cSrcweir	iDateTimeKey = oFormats.GetStandardFormat(com.sun.star.util.NumberFormat.DATETIME,oLocale)
143cdf0e10cSrcweir	oDateTimeField.NumberFormat = iDateTimeKey
144cdf0e10cSrcweir
145cdf0e10cSrcweir	oBookmarkCursor = CreateBookmarkCursor(oDocument, &quot;NextTopic&quot;)
146cdf0e10cSrcweir	oBookmarkCursor.Text.InsertTextContent(oBookmarkCursor,oUserField,False)
147cdf0e10cSrcweir	oBookmarkCursor.Text.InsertString(oBookmarkCursor,&quot; &quot;,False)
148cdf0e10cSrcweir	oBookmarkCursor.Text.InsertTextContent(oBookmarkCursor,oDateTimeField,False)
149cdf0e10cSrcweir	BtnAddAgendaTopic = getControlModel(oDocument, &quot;BtnAddAgendaTopic&quot;)
150cdf0e10cSrcweir	BtnFinishAgenda = getControlModel(oDocument, &quot;BtnFinishAgenda&quot;)
151cdf0e10cSrcweir	If Not IsNull(BtnAddAgendaTopic) Then BtnAddAgendaTopic.Enabled = FALSE
152cdf0e10cSrcweir	If Not IsNull(BtnFinishAgenda) Then BtnFinishAgenda.Enabled = FALSE
153cdf0e10cSrcweirEnd Sub
154cdf0e10cSrcweir
155cdf0e10cSrcweir
156cdf0e10cSrcweirFunction CreateBookMarkCursor(oDocument as Object,sBookmarkName as String)
157cdf0e10cSrcweir	oBookMarks = oDocument.Bookmarks
158cdf0e10cSrcweir	If oBookmarks.HasbyName(sBookmarkName) Then
159cdf0e10cSrcweir		oBookMark = oBookMarks.GetbyName(sBookmarkName)
160cdf0e10cSrcweir		CreateBookMarkCursor = oBookMark.Anchor.Text.CreateTextCursorByRange(oBookMark.Anchor)
161cdf0e10cSrcweir	Else
162cdf0e10cSrcweir		Msgbox &quot;Bookmark &quot; &amp; sBookmarkName &amp;  &quot; is not defined!&quot;
163cdf0e10cSrcweir	End If
164cdf0e10cSrcweirEnd Function
165cdf0e10cSrcweir
166cdf0e10cSrcweir
167cdf0e10cSrcweir
168cdf0e10cSrcweirSub DeleteButtons
169cdf0e10cSrcweirDim AgendaFinished As Boolean
170cdf0e10cSrcweirDim BtnAddAgendaTopic As Object
171cdf0e10cSrcweirDim BtnFinishAgenda As Object
172cdf0e10cSrcweir
173cdf0e10cSrcweir  oDocument = ThisComponent
174cdf0e10cSrcweir
175cdf0e10cSrcweir	BtnAddAgendaTopic = getControlModel(oDocument, &quot;BtnAddAgendaTopic&quot;)
176cdf0e10cSrcweir	BtnFinishAgenda = getControlModel(oDocument, &quot;BtnFinishAgenda&quot;)
177cdf0e10cSrcweir
178cdf0e10cSrcweir	&apos; If buttons could be accessed: If at least one button is disabled, then agenda is finished
179cdf0e10cSrcweir	AgendaFinished = FALSE
180cdf0e10cSrcweir	If Not IsNull(BtnAddAgendaTopic) Then
181cdf0e10cSrcweir		AgendaFinished = (AgendaFinished Or (BtnAddAgendaTopic.Enabled = FALSE))
182cdf0e10cSrcweir	End If
183cdf0e10cSrcweir
184cdf0e10cSrcweir	If Not IsNull(BtnFinishAgenda) Then
185cdf0e10cSrcweir		AgendaFinished = (AgendaFinished Or (BtnFinishAgenda.Enabled = FALSE))
186cdf0e10cSrcweir	End If
187cdf0e10cSrcweir
188cdf0e10cSrcweir	&apos; Delete Buttons, empty rows at end of document &amp; macro bindings if agenda is finished
189cdf0e10cSrcweir	If AgendaFinished Then
190cdf0e10cSrcweir		DisposeControl(oDocument, &quot;BtnAddAgendaTopic&quot;)
191cdf0e10cSrcweir		DisposeControl(oDocument, &quot;BtnFinishAgenda&quot;)
192cdf0e10cSrcweir
193cdf0e10cSrcweir		oBookmarkCursor = CreateBookMarkCursor(oDocument,&quot;NextTopic&quot;)
194cdf0e10cSrcweir		oBookMarkCursor.GotoEnd(True)
195cdf0e10cSrcweir		oBookmarkCursor.Text.insertString(oBookmarkCursor,&quot;&quot;,True)
196cdf0e10cSrcweir
197cdf0e10cSrcweir		AttachBasicMacroToEvent(oDocument,&quot;OnNew&quot;, &quot;&quot;)
198cdf0e10cSrcweir		AttachBasicMacroToEvent(oDocument,&quot;OnSave&quot;, &quot;&quot;)
199cdf0e10cSrcweir		AttachBasicMacroToEvent(oDocument,&quot;OnSaveAs&quot;, &quot;&quot;)
200cdf0e10cSrcweir		AttachBasicMacroToEvent(oDocument,&quot;OnPrint&quot;, &quot;&quot;)
201cdf0e10cSrcweir	End If
202cdf0e10cSrcweirEnd Sub
203cdf0e10cSrcweir
204cdf0e10cSrcweir
205cdf0e10cSrcweir
206cdf0e10cSrcweirSub GetOptionValues(Optional aEvent as Object)
207cdf0e10cSrcweirDim CurTag as String
208cdf0e10cSrcweirDim Taglist() as String
209cdf0e10cSrcweir	If Not IsMissing(aEvent) Then
210cdf0e10cSrcweir		CurTag = aEvent.Source.Model.Tag
211cdf0e10cSrcweir	Else
212cdf0e10cSrcweir		If DialogModel.OptAgenda1.State = TRUE Then
213cdf0e10cSrcweir			CurTag = DialogModel.OptAgenda1.Tag
214cdf0e10cSrcweir		Else
215cdf0e10cSrcweir			CurTag = DialogModel.OptAgenda2.Tag
216cdf0e10cSrcweir		End If
217cdf0e10cSrcweir	End If
218cdf0e10cSrcweir	Taglist() = ArrayoutOfString(CurTag, &quot;;&quot;)
219cdf0e10cSrcweir	Bookmarkname = TagList(0)
220cdf0e10cSrcweir	sTrueContent = TagList(1)
221cdf0e10cSrcweirEnd Sub
222cdf0e10cSrcweir
223*3e02b54dSAndrew Rist</script:module>
224