1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
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 .
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
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 =
"The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
"
47 Public bDisposeDoc as Boolean
48 Public bDebug as Boolean
49 'Public bStartUp as Boolean
50 Public bConnectionIsovergiven as Boolean
51 Public FormName As String
52 Public sFormUrl as String
56 ' The macro can be called in
4 possible scenarios:
57 ' Scenario
1. No parameters at given
58 ' Scenario
2: Only Datasourcename is given, but no connection and no Content
59 ' Scenario
3: a data source and a connection are given
60 ' Scenario
4: all parameters (data source name, connection, object type and object) are given
63 Dim oLocDBContext as Object
64 Dim oLocConnection as Object
66 ' Scenario
1. No parameters at given
69 ' Scenario
2: Only Datasourcename is given, but no connection and no Content
70 ' MainWithDefault(
"Bibliography
")
72 ' Scenario
3: a data source and a connection are given
73 ' oLocDBContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
74 ' oLocConnection = oLocDBContext.GetByName(
"Bibliography
").GetConnection(
"",
"")
75 ' MainWithDefault(
"Bibliography
", oLocConnection)
77 ' Scenario
4: all parameters (data source name, connection, object type and object) are given
78 ' oLocDBContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
79 ' oLocConnection = oLocDBContext.GetByName(
"Bibliography
").GetConnection(
"",
"")
80 ' MainWithDefault(
"Bibliography
", oLocConnection, com.sun.star.sdb.CommandType.TABLE,
"biblio
")
84 Sub MainWithDefault(Optional DatasourceName as String, Optional oConnection as Object, Optional CommandType as Integer, Optional sContent as String)
86 Dim SelCount as Integer
87 Dim RetValue as Integer
88 Dim SelList(
0) as Integer
89 Dim LocList() as String
91 BasicLibraries.LoadLibrary(
"Tools
")
94 On Local Error GoTo WIZARDERROR
98 bControlsareCreated = False
99 bEnableBinaryOptionGroup = False
102 If Not InitResources(
"Formwizard
") Then
105 oDBContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
106 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
107 If GetFormWizardPaths() = False Then
110 oDocument.GetCurrentController().Frame.ComponentWindow.Enable = False
111 oProgressBar.Value =
10
113 oProgressBar.Value =
20
114 InitializeWidthList()
115 oProgressBar.Value =
30
116 Styles() = getListBoxArrays(oUcb,
"/stl
")
117 CurIndex = GetCurIndex(DialogModel, Styles(),
2)
118 oProgressBar.Value =
40
120 oProgressBar.Value =
50
121 InitializeLabelValues()
122 bNeedFieldRefresh = True
124 ' bStartUp = true
126 .cmdBack.Enabled = False
127 .cmdGoOn.Enabled = False
128 .lblTables.Enabled = False
129 .lstSelFields.Tag = False
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 ' 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 ' 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)
151 DlgFormDB.GetControl(
"lstTables
").SelectItem(sContent, True)
153 If CommandType = com.sun.star.sdb.CommandType.QUERY Then
154 SelIndex = IndexInArray(sContent, QueryNames())
155 DlgFormDB.GetControl(
"lstTables
").SelectItemPos(SelIndex, True)
156 ElseIf CommandType = com.sun.star.sdb.CommandType.TABLE Then
157 SelIndex = IndexInArray(sContent, TableNames())
158 DlgFormDB.GetControl(
"lstTables
").SelectItemPos(Ubound(QueryNames()+
1 + SelIndex, True))
161 CurCommandType = CommandType
162 FillUpFieldsListbox(False)
164 LocList() = AddListToList(Array(sSelectDBTable), LocList())
165 DialogModel.lstTables.StringItemList() = LocList()
166 ' bSelectContent = True
167 DialogModel.lstTables.SelectedItems() = Array(
0)
172 ' Scenario
2: Only Datasourcename is given, but no connection and no Content
173 GetSelectedDBMetaData(sDBName)
176 ' Scenario
1: No parameters are given
177 ToggleListboxControls(DialogModel, False)
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
& "FormWizard_1.png
"
188 DialogModel.imgTheme.BackGroundColor = RGB(
0,
60,
126)
189 ToggleDatabasePage(True)
190 oProgressBar.Value =
100
191 DlgFormDB.GetControl(
"lstTables
").SetFocus()
193 RetValue = DlgFormDB.Execute()
196 Dim aPropertyValues(
2) as new com.sun.star.beans.PropertyValue
197 oFormDocuments = oDataSource.getFormDocuments()
200 Dim bLinkExists as Boolean
202 Dim FormBaseName as String
203 FormBaseName = FormName
205 bLinkExists = oFormDocuments.HasbyHierarchicalName(FormName)
208 FormName = FormBaseName
& "_
" & i
210 Loop Until Not bLinkExists
211 aPropertyValues(
0).Name =
"Name
"
212 aPropertyValues(
0).Value = FormName
213 aPropertyValues(
1).Name =
"Parent
"
214 aPropertyValues(
1).Value = oFormDocuments()
215 aPropertyValues(
2).Name =
"URL
"
216 aPropertyValues(
2).Value = sFormUrl
218 oDBDocument = oFormDocuments.createInstanceWithArguments(
"com.sun.star.sdb.DocumentDefinition
", aPropertyValues())
219 oFormDocuments.insertbyName(FormName, oDBDocument)
220 ElseIf RetValue =
0 Then
221 RemoveNirwanaShapes()
223 If ((Not IsNull(oDBConnection)) And (Not bConnectionIsovergiven)) Then
224 oDBConnection.Dispose()
227 If Err
<> 0 Then
228 Msgbox(sMsgErrMsg,
16, GetProductName())
237 ' If bSelectContent Then
238 ' bSelectContent = False
241 DeleteFirstListBoxEntry(
"lstTables
", sSelectDBTable)
242 ToggleDatabasePage(False)
243 FillUpFieldsListbox(True)
244 ToggleDatabasePage(True)
248 Sub FillUpFieldsListbox(bGetCommandType as Boolean)
249 Dim SelIndex as Integer
250 Dim QueryIndex as Integer
252 On Local Error GoTo NOFIELDS
254 SelIndex = DlgFormDB.GetControl(
"lstTables
").getSelectedItemPos()
'.SelectedItems())
255 If SelIndex
> -
1 Then
256 If bGetCommandType Then
257 CurCommandType = iCommandTypes(SelIndex)
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
264 Tablename = Tablenames(SelIndex)
265 oColumns = oDBConnection.Tables.GetByName(Tablename).Columns
267 If GetSpecificFieldNames()
<> -
1 Then
268 ToggleListboxControls(DialogModel, True)
272 EmptyFieldsListboxes()
274 If Err
<> 0 Then
275 MsgBox sMsgErrCouldNotOpenObject,
16, sMsgWizardName
282 On Local Error GoTo WIZARDERROR
286 .cmdBack.Enabled = False
287 .cmdGoOn.Enabled = True
288 .lstSelFields.Tag = Not bControlsareCreated
289 .cmdGoOn.Label = sGoOn
290 .imgTheme.ImageUrl = FormPath
& "FormWizard_1.png
"
294 If Err
<> 0 Then
295 Msgbox(sMsgErrMsg,
16, GetProductName())
304 On Local Error GoTo WIZARDERROR
306 Select Case DialogModel.Step
308 bControlsAreCreated = Not (cBool(DialogModel.lstSelFields.Tag))
309 If Not bControlsAreCreated Then
313 InitializeLayoutSettings()
316 DialogModel.cmdGoOn.Label = sReady
317 DialogModel.cmdBack.Enabled = True
322 DlgFormDB.EndExecute()
325 DialogModel.imgTheme.ImageUrl = FormPath
& "FormWizard_
" & DialogModel.Step
& ".png
"
326 DlgFormDB.Title = WizardTitle(DialogModel.Step)
328 If Err
<> 0 Then
329 Msgbox(sMsgErrMsg,
16, GetProductName())
336 Sub InitializeLayoutSettings()
337 SwitchArrangementButtons(cTabled)
338 SwitchAlignMode(SBALIGNLEFT)
339 SwitchBorderMode(SB3DBORDER)
340 ToggleBorderGroup(bControlsAreCreated)
341 ToggleAlignGroup(bControlsAreCreated)
343 If OldAlignMode
<> 0 Then
344 DlgFormDB.GetControl(
"optAlign2
").Model.State =
0
349 Sub ToggleDatabasePage(bDoEnable as Boolean)
351 .cmdBack.Enabled = False
352 .cmdHelp.Enabled = bDoEnable
353 .cmdGoOn.Enabled = Ubound(DialogModel.lstSelFields.StringItemList())
<> -
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))
361 ' This Sub is called from the Procedure
"StoreDocument
" in the
"Tools
" Library
362 Sub CommitLastDocumentChanges(sTargetPath as String)
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()
373 bLinkExists = oDBBookmarks.HasbyName(sBookmarkName)
376 sBookmarkName = sBaseBookmarkName
& "_
" & i
378 oDBBookmarks.insertByName(sBookmarkName, sTargetPath)
380 Loop Until Not bLinkExists
382 GroupShapesTogether()
383 ToggleDesignMode(oDocument)
388 Sub StoreFormInDatabase()
389 Dim NoArgs() as new com.sun.star.beans.PropertyValue
390 FormName =
"Form_
" & sDBName
& "_
" & TableName
& ".sxw
"
391 sFormUrl = TempPath
& "/
" & FormName
392 oDocument.StoreAsUrl(sFormUrl, NoArgs())
394 DlgFormDB.Endexecute()
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(
"org.openoffice.TypeDetection.Types/
")
404 oTypes() = oMasterKey.Types
405 TypeNames(
0,
0) = GetFilterName(
"StarOffice XML (Writer)
")
406 TypeNames(
0,
1) =
"*.sxw
"
407 TypeNames(
0,
2) =
""
408 StoreFormInDatabase()
409 ' sTargetPath = StoreDocument(oDocument, TypeNames(),
"Form_
" & sDBName
& "_
" & TableName
& ".sxw
", WorkPath,
1)
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
422 Sub DeleteFirstTableListBoxEntry()
423 DeleteFirstListBoxEntry(
"lstTables
", sSelectDBTable)
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
> 0 Then
436 oListBox.selectItemPos(iSelPos-
1, True)