tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / wizards / source / formwizard / FormWizard.xba
blob68a80ff88effaa1dc5d43f6072c4091e0f6ec3a3
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <!--
4 * This file is part of the LibreOffice project.
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 * This file incorporates work covered by the following license notice:
12 * Licensed to the Apache Software Foundation (ASF) under one or more
13 * contributor license agreements. See the NOTICE file distributed
14 * with this work for additional information regarding copyright
15 * ownership. The ASF licenses this file to you under the Apache
16 * License, Version 2.0 (the "License"); you may not use this file
17 * except in compliance with the License. You may obtain a copy of
18 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 -->
20 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="FormWizard" script:language="StarBasic">Option Explicit
22 Public DocumentName as String
23 Public FormPath as String
24 Public WizardPath as String
25 Public WorkPath as String
26 Public TempPath as String
27 Public TexturePath as String
28 Public sQueryName as String
29 Public oDBConnection as Object
30 Public bWithBackGraphic as Boolean
31 Public bNeedFieldRefresh as Boolean
32 Public oDBForm as Object
33 Public oColumns() as Object
34 Public sDatabaseList() as String
35 Public TableNames() as String
36 Public QueryNames() as String
37 Public FieldNames() as String
38 Public ImgFieldNames() as String
39 Public oDBContext as Object
40 Public oUcb as Object
41 Public oDocInfo as Object
42 Public WidthList(15,3)
43 Public ImgWidthList(3,3)
44 Public sDBName as String
45 Public Tablename as String
46 Public Const SBSIZETEXT = &quot;The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.&quot;
47 Public bDisposeDoc as Boolean
48 Public bDebug as Boolean
49 &apos;Public bStartUp as Boolean
50 Public bConnectionIsovergiven as Boolean
51 Public FormName As String
52 Public sFormUrl as String
53 Public oFormDocuments
56 &apos; The macro can be called in 4 possible scenarios:
57 &apos; Scenario 1. No parameters at given
58 &apos; Scenario 2: Only Datasourcename is given, but no connection and no Content
59 &apos; Scenario 3: a data source and a connection are given
60 &apos; Scenario 4: all parameters (data source name, connection, object type and object) are given
62 Sub Main()
63 Dim oLocDBContext as Object
64 Dim oLocConnection as Object
66 &apos; Scenario 1. No parameters at given
67 MainWithDefault()
69 &apos; Scenario 2: Only Datasourcename is given, but no connection and no Content
70 &apos; MainWithDefault(&quot;Bibliography&quot;)
72 &apos; Scenario 3: a data source and a connection are given
73 &apos; oLocDBContext = CreateUnoService(&quot;com.sun.star.sdb.DatabaseContext&quot;)
74 &apos; oLocConnection = oLocDBContext.GetByName(&quot;Bibliography&quot;).GetConnection(&quot;&quot;,&quot;&quot;)
75 &apos; MainWithDefault(&quot;Bibliography&quot;, oLocConnection)
77 &apos; Scenario 4: all parameters (data source name, connection, object type and object) are given
78 &apos; oLocDBContext = CreateUnoService(&quot;com.sun.star.sdb.DatabaseContext&quot;)
79 &apos; oLocConnection = oLocDBContext.GetByName(&quot;Bibliography&quot;).GetConnection(&quot;&quot;,&quot;&quot;)
80 &apos; MainWithDefault(&quot;Bibliography&quot;, oLocConnection, com.sun.star.sdb.CommandType.TABLE, &quot;biblio&quot;)
81 End Sub
84 Sub MainWithDefault(Optional DatasourceName as String, Optional oConnection as Object, Optional CommandType as Integer, Optional sContent as String)
85 Dim i as Integer
86 Dim SelCount as Integer
87 Dim RetValue as Integer
88 Dim SelList(0) as Integer
89 Dim LocList() as String
90 SelList(0) = 0
91 BasicLibraries.LoadLibrary(&quot;Tools&quot;)
92 bDebug = False
93 If Not bDebug Then
94 On Local Error GoTo WIZARDERROR
95 End If
96 OpenFormDocument()
97 CurArrangement = 0
98 bControlsareCreated = False
99 bEnableBinaryOptionGroup = False
100 bDisposeDoc = True
101 MaxIndex = -1
102 If Not InitResources(&quot;Formwizard&quot;) Then
103 Exit Sub
104 End If
105 oDBContext = CreateUnoService(&quot;com.sun.star.sdb.DatabaseContext&quot;)
106 oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
107 If GetFormWizardPaths() = False Then
108 Exit Sub
109 End If
110 oDocument.GetCurrentController().Frame.ComponentWindow.Enable = False
111 oProgressBar.Value = 10
112 LoadLanguage()
113 oProgressBar.Value = 20
114 InitializeWidthList()
115 oProgressBar.Value = 30
116 Styles() = getListBoxArrays(oUcb, &quot;/stl&quot;)
117 CurIndex = GetCurIndex(DialogModel, Styles(), 2)
118 oProgressBar.Value = 40
119 ConfigurePageStyle()
120 oProgressBar.Value = 50
121 InitializeLabelValues()
122 bNeedFieldRefresh = True
123 SetDialogLanguage()
124 &apos; bStartUp = true
125 With DialogModel
126 .cmdBack.Enabled = False
127 .cmdGoOn.Enabled = False
128 .lblTables.Enabled = False
129 .lstSelFields.Tag = False
130 .Step = 1
131 End With
132 oProgressBar.Value = 60
133 bConnectionIsovergiven = Not IsMissing(oConnection)
134 If Not IsMissing(DataSourceName) Then
135 sDBName = DataSourceName
136 If Not IsMissing(oConnection) Then
137 &apos; Scenario 3: a data source and a connection are given
138 Set oDBConnection = oConnection
139 oDataSource = oDBContext.GetByName(DataSourceName)
140 DialogModel.lstTables.Enabled = True
141 DialogModel.lblTables.Enabled = True
142 If GetDBMetaData() Then
143 LocList() = AddListToList(TableNames(), QueryNames())
144 iCommandTypes = CreateCommandTypeList()
145 If Not IsMissing(sContent) Then
146 &apos; Scenario 4: all parameters (data source name, connection, object type and object) are given
147 DialogModel.lstTables.StringItemList() = LocList()
148 iCommandTypes() = CreateCommandTypeList()
149 SelCount = CountItemsInArray(DialogModel.lstTables.StringItemList(), sContent)
150 If SelCount = 1 Then
151 DlgFormDB.GetControl(&quot;lstTables&quot;).SelectItem(sContent, True)
152 Else
153 If CommandType = com.sun.star.sdb.CommandType.QUERY Then
154 SelIndex = IndexInArray(sContent, QueryNames())
155 DlgFormDB.GetControl(&quot;lstTables&quot;).SelectItemPos(SelIndex, True)
156 ElseIf CommandType = com.sun.star.sdb.CommandType.TABLE Then
157 SelIndex = IndexInArray(sContent, TableNames())
158 DlgFormDB.GetControl(&quot;lstTables&quot;).SelectItemPos(Ubound(QueryNames()+1 + SelIndex, True))
159 End If
160 End If
161 CurCommandType = CommandType
162 FillUpFieldsListbox(False)
163 Else
164 LocList() = AddListToList(Array(sSelectDBTable), LocList())
165 DialogModel.lstTables.StringItemList() = LocList()
166 &apos; bSelectContent = True
167 DialogModel.lstTables.SelectedItems() = Array(0)
169 End If
170 End If
171 Else
172 &apos; Scenario 2: Only Datasourcename is given, but no connection and no Content
173 GetSelectedDBMetaData(sDBName)
174 End If
175 Else
176 &apos; Scenario 1: No parameters are given
177 ToggleListboxControls(DialogModel, False)
178 End If
179 oProgressBar.Value = 80
180 bWithBackGraphic = LoadNewStyles(oDocument, DialogModel, CurIndex, Styles(CurIndex, 8), Styles(), TexturePath)
181 DlgFormDB.Title = WizardTitle(1)
182 DialogModel.lstStyles.StringItemList() = ArrayfromMultiArray(Styles, 1)
183 DialogModel.lstStyles.SelectedItems() = SelList()
184 ControlCaptionsToStandardLayout()
185 oDocument.GetCurrentController().Frame.ComponentWindow.Enable = True
186 oProgressBar.Value = 90
187 DialogModel.imgTheme.ImageURL = FormPath &amp; &quot;FormWizard_1.png&quot;
188 DialogModel.imgTheme.BackGroundColor = RGB(0,60,126)
189 ToggleDatabasePage(True)
190 oProgressBar.Value = 100
191 DlgFormDB.GetControl(&quot;lstTables&quot;).SetFocus()
192 oProgressbar.End
193 RetValue = DlgFormDB.Execute()
194 DlgFormDB.Dispose()
195 If bDisposeDoc Then
196 Dim aPropertyValues(2) as new com.sun.star.beans.PropertyValue
197 oFormDocuments = oDataSource.getFormDocuments()
198 DlgFormDB.Dispose()
199 oDocument.dispose()
200 Dim bLinkExists as Boolean
201 i = 1
202 Dim FormBaseName as String
203 FormBaseName = FormName
205 bLinkExists = oFormDocuments.HasbyHierarchicalName(FormName)
206 If bLinkExists Then
207 i = i + 1
208 FormName = FormBaseName &amp; &quot;_&quot; &amp; i
209 End If
210 Loop Until Not bLinkExists
211 aPropertyValues(0).Name = &quot;Name&quot;
212 aPropertyValues(0).Value = FormName
213 aPropertyValues(1).Name = &quot;Parent&quot;
214 aPropertyValues(1).Value = oFormDocuments()
215 aPropertyValues(2).Name = &quot;URL&quot;
216 aPropertyValues(2).Value = sFormUrl
217 Dim oDBDocument
218 oDBDocument = oFormDocuments.createInstanceWithArguments(&quot;com.sun.star.sdb.DocumentDefinition&quot;, aPropertyValues())
219 oFormDocuments.insertbyName(FormName, oDBDocument)
220 ElseIf RetValue = 0 Then
221 RemoveNirwanaShapes()
222 End If
223 If ((Not IsNull(oDBConnection)) And (Not bConnectionIsovergiven)) Then
224 oDBConnection.Dispose()
225 End If
226 WIZARDERROR:
227 If Err &lt;&gt; 0 Then
228 Msgbox(sMsgErrMsg, 16, GetProductName())
229 Resume LOCERROR
230 LOCERROR:
231 End If
232 End Sub
235 Sub FormGetFields()
236 Dim i as Integer
237 &apos; If bSelectContent Then
238 &apos; bSelectContent = False
239 &apos; Exit Sub
240 &apos; End If
241 DeleteFirstListBoxEntry(&quot;lstTables&quot;, sSelectDBTable)
242 ToggleDatabasePage(False)
243 FillUpFieldsListbox(True)
244 ToggleDatabasePage(True)
245 End Sub
248 Sub FillUpFieldsListbox(bGetCommandType as Boolean)
249 Dim SelIndex as Integer
250 Dim QueryIndex as Integer
251 If Not bDebug Then
252 On Local Error GoTo NOFIELDS
253 End If
254 SelIndex = DlgFormDB.GetControl(&quot;lstTables&quot;).getSelectedItemPos() &apos;.SelectedItems())
255 If SelIndex &gt; -1 Then
256 If bGetCommandType Then
257 CurCommandType = iCommandTypes(SelIndex)
258 End If
259 If CurCommandType = com.sun.star.sdb.CommandType.QUERY Then
260 QueryIndex = SelIndex - Ubound(Tablenames()) - 1
261 Tablename = QueryNames(QueryIndex)
262 oColumns = oDBConnection.Queries.GetByName(TableName).Columns
263 Else
264 Tablename = Tablenames(SelIndex)
265 oColumns = oDBConnection.Tables.GetByName(Tablename).Columns
266 End If
267 If GetSpecificFieldNames() &lt;&gt; -1 Then
268 ToggleListboxControls(DialogModel, True)
269 Exit Sub
270 End If
271 End If
272 EmptyFieldsListboxes()
273 NOFIELDS:
274 If Err &lt;&gt; 0 Then
275 MsgBox sMsgErrCouldNotOpenObject, 16, sMsgWizardName
276 End If
277 End Sub
280 Sub PreviousStep()
281 If Not bDebug Then
282 On Local Error GoTo WIZARDERROR
283 End If
284 With DialogModel
285 .Step = 1
286 .cmdBack.Enabled = False
287 .cmdGoOn.Enabled = True
288 .lstSelFields.Tag = Not bControlsareCreated
289 .cmdGoOn.Label = sGoOn
290 .imgTheme.ImageUrl = FormPath &amp; &quot;FormWizard_1.png&quot;
291 End With
292 FormSetMoveRights()
293 WIZARDERROR:
294 If Err &lt;&gt; 0 Then
295 Msgbox(sMsgErrMsg, 16, GetProductName())
296 Resume LOCERROR
297 LOCERROR:
298 End If
299 End Sub
302 Sub NextStep()
303 If Not bDebug Then
304 On Local Error GoTo WIZARDERROR
305 End If
306 Select Case DialogModel.Step
307 Case 1
308 bControlsAreCreated = Not (cBool(DialogModel.lstSelFields.Tag))
309 If Not bControlsAreCreated Then
310 GetTableMetaData()
311 CreateDBForm()
312 RemoveShapes()
313 InitializeLayoutSettings()
314 oDBForm.Load
315 End If
316 DialogModel.cmdGoOn.Label = sReady
317 DialogModel.cmdBack.Enabled = True
318 DialogModel.Step = 2
319 bDisposeDoc = False
320 Case 2
321 StoreForm()
322 DlgFormDB.EndExecute()
323 exit Sub
324 End Select
325 DialogModel.imgTheme.ImageUrl = FormPath &amp; &quot;FormWizard_&quot; &amp; DialogModel.Step &amp; &quot;.png&quot;
326 DlgFormDB.Title = WizardTitle(DialogModel.Step)
327 WIZARDERROR:
328 If Err &lt;&gt; 0 Then
329 Msgbox(sMsgErrMsg, 16, GetProductName())
330 Resume LOCERROR
331 LOCERROR:
332 End If
333 End Sub
336 Sub InitializeLayoutSettings()
337 SwitchArrangementButtons(cTabled)
338 SwitchAlignMode(SBALIGNLEFT)
339 SwitchBorderMode(SB3DBORDER)
340 ToggleBorderGroup(bControlsAreCreated)
341 ToggleAlignGroup(bControlsAreCreated)
342 ArrangeControls()
343 If OldAlignMode &lt;&gt; 0 Then
344 DlgFormDB.GetControl(&quot;optAlign2&quot;).Model.State = 0
345 End If
346 End Sub
349 Sub ToggleDatabasePage(bDoEnable as Boolean)
350 With DialogModel
351 .cmdBack.Enabled = False
352 .cmdHelp.Enabled = bDoEnable
353 .cmdGoOn.Enabled = Ubound(DialogModel.lstSelFields.StringItemList()) &lt;&gt; -1
354 .hlnBinaries.Enabled = ((bDoEnable = True) And (bEnableBinaryOptionGroup = True))
355 .optIgnoreBinaries.Enabled = ((bDoEnable = True) And (bEnableBinaryOptionGroup = True))
356 .optBinariesasGraphics.Enabled = ((bDoEnable = True) And (bEnableBinaryOptionGroup = True))
357 End With
358 End Sub
361 &apos; This Sub is called from the Procedure &quot;StoreDocument&quot; in the &quot;Tools&quot; Library
362 Sub CommitLastDocumentChanges(sTargetPath as String)
363 Dim i as Integer
364 Dim sBookmarkName as String
365 Dim oDBBookmarks as Object
366 Dim bLinkExists as Boolean
367 Dim sBaseBookmarkName as String
368 sBookmarkName = GetFileNamewithoutExtension(FileNameoutofPath(sTargetPath))
369 sBaseBookmarkName = sBookmarkName
370 oDBBookmarks = oDataSource.GetBookmarks()
371 i = 1
373 bLinkExists = oDBBookmarks.HasbyName(sBookmarkName)
374 If bLinkExists Then
375 i = i + 1
376 sBookmarkName = sBaseBookmarkName &amp; &quot;_&quot; &amp; i
377 Else
378 oDBBookmarks.insertByName(sBookmarkName, sTargetPath)
379 End If
380 Loop Until Not bLinkExists
381 bDisposeDoc = False
382 GroupShapesTogether()
383 ToggleDesignMode(oDocument)
384 oDBForm.Reload()
385 End Sub
388 Sub StoreFormInDatabase()
389 Dim NoArgs() as new com.sun.star.beans.PropertyValue
390 FormName = &quot;Form_&quot; &amp; sDBName &amp; &quot;_&quot; &amp; TableName &amp; &quot;.sxw&quot;
391 sFormUrl = TempPath &amp; &quot;/&quot; &amp; FormName
392 oDocument.StoreAsUrl(sFormUrl, NoArgs())
393 bdisposeDoc = true
394 DlgFormDB.Endexecute()
395 End Sub
398 Sub StoreForm()
399 Dim sTargetPath as String
400 Dim TypeNames(0,2) as String
401 Dim oMasterKey as Object
402 Dim oTypes() as Object
403 oMasterKey = GetRegistryKeyContent(&quot;org.openoffice.TypeDetection.Types/&quot;)
404 oTypes() = oMasterKey.Types
405 TypeNames(0,0) = GetFilterName(&quot;StarOffice XML (Writer)&quot;)
406 TypeNames(0,1) = &quot;*.sxw&quot;
407 TypeNames(0,2) = &quot;&quot;
408 StoreFormInDatabase()
409 &apos; sTargetPath = StoreDocument(oDocument, TypeNames(), &quot;Form_&quot; &amp; sDBName &amp; &quot;_&quot; &amp; TableName &amp; &quot;.sxw&quot;, WorkPath, 1)
410 End Sub
413 Sub EmptyFieldsListboxes()
414 Dim NullList() as String
415 ToggleListboxControls(DialogModel, False)
416 DialogModel.lstFields.StringItemList() = NullList()
417 DialogModel.lstSelFields.StringItemList() = NullList()
418 bEnableBinaryOptionGroup = False
419 End Sub
422 Sub DeleteFirstTableListBoxEntry()
423 DeleteFirstListBoxEntry(&quot;lstTables&quot;, sSelectDBTable)
424 End Sub
426 Sub DeleteFirstListboxEntry(ListBoxName as String, DelEntryName as String)
427 Dim oListbox as Object
428 Dim sFirstItem as String
429 dim iSelPos as Integer
430 oListBox = DlgFormDB.getControl(ListBoxName)
431 sFirstItem = oListBox.getItem(0)
432 If sFirstItem = DelEntryName Then
433 iSelPos = oListBox.getSelectedItemPos()
434 oListBox.removeItems(0, 1)
435 If iSelPos &gt; 0 Then
436 oListBox.selectItemPos(iSelPos-1, True)
437 End If
438 End If
439 End Sub
440 </script:module>