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