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