update dev300-m58
[ooovba.git] / wizards / source / template / ModuleAgenda.xba
blob73b0c6cfd8dc3399ea3b187d0ead7dac82833efb
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
4 Option Explicit
6 &apos; Used for &quot;disabling&quot; the cancel button of the dialog
7 Public DialogExited As Boolean
8 Dim DlgAgenda_gMyName as String
9 Public TemplateDialog as Object
10 Public DialogModel as Object
11 Public sTrueContent as String
12 Public Bookmarkname as String
16 Sub 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
27 End Sub
30 Sub 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
41 End Sub
44 Sub ModifyTemplate()
45 Dim oDocument, oBookmarks, oBookmark, oBookmarkCursor, oTextField as Object
46 Dim i as Integer
48 oDocument = ThisComponent
49 oBookMarks = oDocument.Bookmarks
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
70 NOBOOKMARK:
71 If Err &lt;&gt; 0 Then
72 RESUME NEXT
73 End If
74 End Sub
77 Sub NewTopic
78 &apos; Add a new topic to the agenda
79 Dim oDocument, oBookmarks, oBookmark, oBookmarkCursor, oTextField as Object
80 Dim oBaustein, oAutoText, oAutoGroup as Object
81 Dim i as Integer
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
98 End Sub
102 &apos; Add initials, date and time at bottom of agenda, disable and hide command buttons
103 Sub FinishAgenda
104 Dim BtnAddAgendaTopic As Object
105 Dim BtnFinishAgenda As Object
106 Dim oUserField, oDateTimeField as Object
107 Dim oBookmarkCursor as Object
108 Dim oFormats, oLocale as Object
109 Dim iDateTimeKey as Integer
111 BasicLibraries.LoadLibrary( &quot;Tools&quot; )
112 oDocument = ThisComponent
114 oUserField = oDocument.CreateInstance(&quot;com.sun.star.text.TextField.ExtendedUser&quot;)
115 oUserField.UserDatatype = com.sun.star.text.UserDataPart.SHORTCUT
117 oDateTimeField = oDocument.CreateInstance(&quot;com.sun.star.text.TextField.DateTime&quot;)
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
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
133 End Sub
136 Function 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
144 End Function
148 Sub DeleteButtons
149 Dim AgendaFinished As Boolean
150 Dim BtnAddAgendaTopic As Object
151 Dim BtnFinishAgenda As Object
153 oDocument = ThisComponent
155 BtnAddAgendaTopic = getControlModel(oDocument, &quot;BtnAddAgendaTopic&quot;)
156 BtnFinishAgenda = getControlModel(oDocument, &quot;BtnFinishAgenda&quot;)
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
164 If Not IsNull(BtnFinishAgenda) Then
165 AgendaFinished = (AgendaFinished Or (BtnFinishAgenda.Enabled = FALSE))
166 End If
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;)
173 oBookmarkCursor = CreateBookMarkCursor(oDocument,&quot;NextTopic&quot;)
174 oBookMarkCursor.GotoEnd(True)
175 oBookmarkCursor.Text.insertString(oBookmarkCursor,&quot;&quot;,True)
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
182 End Sub
186 Sub GetOptionValues(Optional aEvent as Object)
187 Dim CurTag as String
188 Dim 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)
201 End Sub
203 </script:module>