summaryrefslogtreecommitdiffstats
path: root/wizards/source/template/ModuleAgenda.xba
blob: a17fb68cd602e5ddd935b1eaf3529c1e2ec8ed58 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<!--
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="ModuleAgenda" script:language="StarBasic">&apos; All variables must be declared before use
Option Explicit

&apos; Used for &quot;disabling&quot; the cancel button of the dialog
Public DialogExited As Boolean
Dim DlgAgenda_gMyName as String
Public TemplateDialog as Object
Public DialogModel as Object
Public sTrueContent as String
Public Bookmarkname as String



Sub Initialize()
&apos; User sets the type of minutes
        BasicLibraries.LoadLibrary( &quot;Tools&quot; )
	TemplateDialog = LoadDialog(&quot;Template&quot;, &quot;TemplateDialog&quot;)
	DialogModel = TemplateDialog.Model
	DialogModel.Step = 1
	LoadLanguageAgenda()
	DialogModel.OptAgenda2.State = TRUE
	GetOptionValues()
	DialogExited = FALSE
	TemplateDialog.Execute
End Sub


Sub LoadLanguageAgenda()
	If InitResources(&quot;&apos;Template&apos;&quot;) Then
		DlgAgenda_gMyName = GetResText(&quot;AgendaDlgName&quot;)
		DialogModel.CmdCancel.Label = GetResText(&quot;STYLES_2&quot;)
		DialogModel.CmdAgdGoon.Label = GetResText(&quot;STYLES_3&quot;)
&apos;		DlgAgenda_gMsgNoCancel$ = GetResText(&quot;AgendaDlgNoCancel&quot;)
		DialogModel.FrmAgenda.Label = GetResText(&quot;AgendaDlgFrame&quot;)
		DialogModel.OptAgenda1.Label = GetResText(&quot;AgendaDlgButton1&quot;)
		DialogModel.OptAgenda2.Label = GetResText(&quot;AgendaDlgButton2&quot;)
&apos;		DialogModel.OptAgenda1.State = 1
	End If
End Sub


Sub ModifyTemplate()
Dim oDocument, oBookmarks, oBookmark, oBookmarkCursor, oTextField as Object
Dim i as Integer

  oDocument = ThisComponent
	oBookMarks = oDocument.Bookmarks

	On Local Error Goto NOBOOKMARK
	TemplateDialog.EndExecute
	DialogExited = TRUE
	oBookmarkCursor = CreateBookmarkCursor(oDocument, BookmarkName)
	oBookmarkCursor.Text.insertString(oBookmarkCursor,&quot;&quot;,True)
	&apos; Delete all the Bookmarks except for the one named &quot;NextTopic&quot;
	For i = oBookmarks.Count-1 To 0 Step -1
		oBookMark = oBookMarks.GetByIndex(i)
		If oBookMark.Name &lt;&gt; &quot;NextTopic&quot; Then
			oBookMark.Dispose()
		End If
	Next i
	oBookMarkCursor = CreateBookmarkCursor(oDocument, &quot;NextTopic&quot;)
	If Not IsNull(oBookMarkCursor) Then
		oTextField = oBookMarkCursor.TextField
&apos;		oTextField.TrueContent = 	sTrueContent
		oTextField.Content = sTrueContent
	End If

	NOBOOKMARK:
	If Err &lt;&gt; 0 Then
		RESUME NEXT
	End If
End Sub


Sub NewTopic
&apos; Add a new topic to the agenda
Dim oDocument, oBookmarks, oBookmark, oBookmarkCursor, oTextField as Object
Dim oBaustein, oAutoText, oAutoGroup as Object
Dim i as Integer

  	oDocument = ThisComponent
	oBookMarkCursor = CreateBookMarkCursor(oDocument, &quot;NextTopic&quot;)
	oTextField = oBookMarkCursor.TextField
	oAutoText = CreateUnoService(&quot;com.sun.star.text.AutoTextContainer&quot;)
	If oAutoText.HasbyName(&quot;template&quot;) Then
		oAutoGroup = oAutoText.GetbyName(&quot;template&quot;)
		If oAutoGroup.HasbyName(oTextField.Content) Then
			oBaustein = oAutoGroup.GetbyName(oTextField.Content)
			oBaustein.ApplyTo(oBookMarkCursor)
		Else
			Msgbox(&quot;AutoText &apos;&quot; &amp; oTextField.Content &amp; &quot;&apos; is not existing. Cannot insert additional topic!&quot;)
		End If
	Else
		Msgbox(&quot;AutoGroupField template is not existing. Cannot insert additional topic!&quot;, 16, DlgAgenda_gMyName )
	End If
End Sub



&apos; Add initials, date and time at bottom of agenda, disable and hide command buttons
Sub FinishAgenda
Dim BtnAddAgendaTopic As Object
Dim BtnFinishAgenda As Object
Dim oUserField, oDateTimeField as Object
Dim oBookmarkCursor as Object
Dim oFormats, oLocale as Object
Dim iDateTimeKey as Integer

        BasicLibraries.LoadLibrary( &quot;Tools&quot; )
  oDocument = ThisComponent

	oUserField = oDocument.CreateInstance(&quot;com.sun.star.text.TextField.ExtendedUser&quot;)
	oUserField.UserDatatype = com.sun.star.text.UserDataPart.SHORTCUT

	oDateTimeField = oDocument.CreateInstance(&quot;com.sun.star.text.TextField.DateTime&quot;)

	&apos; Assign Standardformat to Datetime-Textfield
	oFormats = oDocument.Numberformats
	oLocale = oDocument.CharLocale
	iDateTimeKey = oFormats.GetStandardFormat(com.sun.star.util.NumberFormat.DATETIME,oLocale)
	oDateTimeField.NumberFormat = iDateTimeKey

	oBookmarkCursor = CreateBookmarkCursor(oDocument, &quot;NextTopic&quot;)
	oBookmarkCursor.Text.InsertTextContent(oBookmarkCursor,oUserField,False)
	oBookmarkCursor.Text.InsertString(oBookmarkCursor,&quot; &quot;,False)
	oBookmarkCursor.Text.InsertTextContent(oBookmarkCursor,oDateTimeField,False)
	BtnAddAgendaTopic = getControlModel(oDocument, &quot;BtnAddAgendaTopic&quot;)
	BtnFinishAgenda = getControlModel(oDocument, &quot;BtnFinishAgenda&quot;)
	If Not IsNull(BtnAddAgendaTopic) Then BtnAddAgendaTopic.Enabled = FALSE
	If Not IsNull(BtnFinishAgenda) Then BtnFinishAgenda.Enabled = FALSE
End Sub


Function CreateBookMarkCursor(oDocument as Object,sBookmarkName as String)
	oBookMarks = oDocument.Bookmarks
	If oBookmarks.HasbyName(sBookmarkName) Then
		oBookMark = oBookMarks.GetbyName(sBookmarkName)
		CreateBookMarkCursor = oBookMark.Anchor.Text.CreateTextCursorByRange(oBookMark.Anchor)
	Else
		Msgbox &quot;Bookmark &quot; &amp; sBookmarkName &amp;  &quot; is not defined!&quot;
	End If
End Function



Sub DeleteButtons
Dim AgendaFinished As Boolean
Dim BtnAddAgendaTopic As Object
Dim BtnFinishAgenda As Object

  oDocument = ThisComponent

	BtnAddAgendaTopic = getControlModel(oDocument, &quot;BtnAddAgendaTopic&quot;)
	BtnFinishAgenda = getControlModel(oDocument, &quot;BtnFinishAgenda&quot;)

	&apos; If buttons could be accessed: If at least one button is disabled, then agenda is finished
	AgendaFinished = FALSE
	If Not IsNull(BtnAddAgendaTopic) Then
		AgendaFinished = (AgendaFinished Or (BtnAddAgendaTopic.Enabled = FALSE))
	End If

	If Not IsNull(BtnFinishAgenda) Then
		AgendaFinished = (AgendaFinished Or (BtnFinishAgenda.Enabled = FALSE))
	End If

	&apos; Delete Buttons, empty rows at end of document &amp; macro bindings if agenda is finished
	If AgendaFinished Then
		DisposeControl(oDocument, &quot;BtnAddAgendaTopic&quot;)
		DisposeControl(oDocument, &quot;BtnFinishAgenda&quot;)

		oBookmarkCursor = CreateBookMarkCursor(oDocument,&quot;NextTopic&quot;)
		oBookMarkCursor.GotoEnd(True)
		oBookmarkCursor.Text.insertString(oBookmarkCursor,&quot;&quot;,True)

		AttachBasicMacroToEvent(oDocument,&quot;OnNew&quot;, &quot;&quot;)
		AttachBasicMacroToEvent(oDocument,&quot;OnSave&quot;, &quot;&quot;)
		AttachBasicMacroToEvent(oDocument,&quot;OnSaveAs&quot;, &quot;&quot;)
		AttachBasicMacroToEvent(oDocument,&quot;OnPrint&quot;, &quot;&quot;)
	End If
End Sub



Sub GetOptionValues(Optional aEvent as Object)
Dim CurTag as String
Dim Taglist() as String
	If Not IsMissing(aEvent) Then
		CurTag = aEvent.Source.Model.Tag
	Else
		If DialogModel.OptAgenda1.State = TRUE Then
			CurTag = DialogModel.OptAgenda1.Tag
		Else
			CurTag = DialogModel.OptAgenda2.Tag
		End If		
	End If
	Taglist() = ArrayoutOfString(CurTag, &quot;;&quot;)
	Bookmarkname = TagList(0)
	sTrueContent = TagList(1)
End Sub

</script:module>