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 WebWizardPath as String
26 Public WorkPath as String
27 Public TempPath as String
28 Public TexturePath as String
29 Public sQueryName as String
30 Public oDBConnection as Object
31 Public bWithBackGraphic as Boolean
32 Public bNeedFieldRefresh as Boolean
33 Public oDBForm as Object
34 Public oColumns() as Object
35 Public sDatabaseList() as String
36 Public TableNames() as String
37 Public QueryNames() as String
38 Public FieldNames() as String
39 Public ImgFieldNames() as String
40 Public oDBContext as Object
42 Public oDocInfo as Object
43 Public WidthList(
15,
3)
44 Public ImgWidthList(
3,
3)
45 Public sDBName as String
46 Public Tablename as String
47 Public Const SBSIZETEXT =
"The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
"
48 Public bDisposeDoc as Boolean
49 Public bDebug as Boolean
50 'Public bStartUp as Boolean
51 Public bConnectionIsovergiven as Boolean
52 Public FormName As String
53 Public sFormUrl as String
57 ' The macro can be called in
4 possible scenarios:
58 ' Scenario
1. No parameters at given
59 ' Scenario
2: Only Datasourcename is given, but no connection and no Content
60 ' Scenario
3: a data source and a connection are given
61 ' Scenario
4: all parameters (data source name, connection, object type and object) are given
64 Dim oLocDBContext as Object
65 Dim oLocConnection as Object
67 ' Scenario
1. No parameters at given
70 ' Scenario
2: Only Datasourcename is given, but no connection and no Content
71 ' MainWithDefault(
"Bibliography
")
73 ' Scenario
3: a data source and a connection are given
74 ' oLocDBContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
75 ' oLocConnection = oLocDBContext.GetByName(
"Bibliography
").GetConnection(
"",
"")
76 ' MainWithDefault(
"Bibliography
", oLocConnection)
78 ' Scenario
4: all parameters (data source name, connection, object type and object) are given
79 ' oLocDBContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
80 ' oLocConnection = oLocDBContext.GetByName(
"Bibliography
").GetConnection(
"",
"")
81 ' MainWithDefault(
"Bibliography
", oLocConnection, com.sun.star.sdb.CommandType.TABLE,
"biblio
")
85 Sub MainWithDefault(Optional DatasourceName as String, Optional oConnection as Object, Optional CommandType as Integer, Optional sContent as String)
87 Dim SelCount as Integer
88 Dim RetValue as Integer
89 Dim SelList(
0) as Integer
90 Dim LocList() as String
92 BasicLibraries.LoadLibrary(
"Tools
")
93 BasicLibraries.LoadLibrary(
"WebWizard
")
96 On Local Error GoTo WIZARDERROR
100 bControlsareCreated = False
101 bEnableBinaryOptionGroup = False
104 If Not InitResources(
"Formwizard
",
"dbw
") Then
107 oDBContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
108 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
109 If GetFormWizardPaths() = False Then
112 oDocument.GetCurrentController().Frame.ComponentWindow.Enable = False
113 oProgressBar.Value =
10
115 oProgressBar.Value =
20
116 InitializeWidthList()
117 oProgressBar.Value =
30
118 Styles() = getListBoxArrays(oUcb,
"/stl
")
119 CurIndex = GetCurIndex(DialogModel, Styles(),
2)
120 oProgressBar.Value =
40
122 oProgressBar.Value =
50
123 InitializeLabelValues()
124 bNeedFieldRefresh = True
126 ' bStartUp = true
128 .cmdBack.Enabled = False
129 .cmdGoOn.Enabled = False
130 .lblTables.Enabled = False
131 .lstSelFields.Tag = False
134 oProgressBar.Value =
60
135 bConnectionIsovergiven = Not IsMissing(oConnection)
136 If Not IsMissing(DataSourceName) Then
137 sDBName = DataSourceName
138 If Not IsMissing(oConnection) Then
139 ' Scenario
3: a data source and a connection are given
140 Set oDBConnection = oConnection
141 oDataSource = oDBContext.GetByName(DataSourceName)
142 DialogModel.lstTables.Enabled = True
143 DialogModel.lblTables.Enabled = True
144 If GetDBMetaData() Then
145 LocList() = AddListToList(TableNames(), QueryNames())
146 iCommandTypes = CreateCommandTypeList()
147 If Not IsMissing(sContent) Then
148 ' Scenario
4: all parameters (data source name, connection, object type and object) are given
149 DialogModel.lstTables.StringItemList() = LocList()
150 iCommandTypes() = CreateCommandTypeList()
151 SelCount = CountItemsInArray(DialogModel.lstTables.StringItemList(), sContent)
153 DlgFormDB.GetControl(
"lstTables
").SelectItem(sContent, True)
155 If CommandType = com.sun.star.sdb.CommandType.QUERY Then
156 SelIndex = IndexInArray(sContent, QueryNames()
157 DlgFormDB.GetControl(
"lstTables
").SelectItemPos(SelIndex, True)
158 ElseIf CommandType = com.sun.star.sdb.CommandType.TABLE Then
159 SelIndex = IndexInArray(sContent, TableNames()
160 DlgFormDB.GetControl(
"lstTables
").SelectItemPos(Ubound(QueryNames()+
1 + SelIndex, True)
163 CurCommandType = CommandType
164 FillUpFieldsListbox(False)
166 LocList() = AddListToList(Array(sSelectDBTable), LocList())
167 DialogModel.lstTables.StringItemList() = LocList()
168 ' bSelectContent = True
169 DialogModel.lstTables.SelectedItems() = Array(
0)
174 ' Scenario
2: Only Datasourcename is given, but no connection and no Content
175 GetSelectedDBMetaData(sDBName)
178 ' Scenario
1: No parameters are given
179 ToggleListboxControls(DialogModel, False)
181 oProgressBar.Value =
80
182 bWithBackGraphic = LoadNewStyles(oDocument, DialogModel, CurIndex, Styles(CurIndex,
8), Styles(), TexturePath)
183 DlgFormDB.Title = WizardTitle(
1)
184 DialogModel.lstStyles.StringItemList() = ArrayfromMultiArray(Styles,
1)
185 DialogModel.lstStyles.SelectedItems() = SelList()
186 ControlCaptionsToStandardLayout()
187 oDocument.GetCurrentController().Frame.ComponentWindow.Enable = True
188 oProgressBar.Value =
90
189 DialogModel.imgTheme.ImageURL = FormPath
& "FormWizard_1.bmp
"
190 DialogModel.imgTheme.BackGroundColor = RGB(
0,
60,
126)
191 ToggleDatabasePage(True)
192 oProgressBar.Value =
100
193 DlgFormDB.GetControl(
"lstTables
").SetFocus()
195 RetValue = DlgFormDB.Execute()
198 Dim aPropertyValues(
2) as new com.sun.star.beans.PropertyValue
199 oFormDocuments = oDataSource.getFormDocuments()
202 Dim bLinkExists as Boolean
204 Dim FormBaseName as String
205 FormBaseName = FormName
207 bLinkExists = oFormDocuments.HasbyHierarchicalName(FormName)
210 FormName = FormBaseName
& "_
" & i
212 Loop Until Not bLinkExists
213 aPropertyValues(
0).Name =
"Name
"
214 aPropertyValues(
0).Value = FormName
215 aPropertyValues(
1).Name =
"Parent
"
216 aPropertyValues(
1).Value = oFormDocuments()
217 aPropertyValues(
2).Name =
"URL
"
218 aPropertyValues(
2).Value = sFormUrl
220 oDBDocument = oFormDocuments.createInstanceWithArguments(
"com.sun.star.sdb.DocumentDefinition
", aPropertyValues())
221 oFormDocuments.insertbyName(FormName, oDBDocument)
222 ElseIf RetValue =
0 Then
223 RemoveNirwanaShapes()
225 If ((Not IsNull(oDBConnection)) And (Not bConnectionIsovergiven)) Then
226 oDBConnection.Dispose()
229 If Err
<> 0 Then
230 Msgbox(sMsgErrMsg,
16, GetProductName())
239 ' If bSelectContent Then
240 ' bSelectContent = False
243 DeleteFirstListBoxEntry(
"lstTables
", sSelectDBTable)
244 ToggleDatabasePage(False)
245 FillUpFieldsListbox(True)
246 ToggleDatabasePage(True)
250 Sub FillUpFieldsListbox(bGetCommandType as Boolean)
251 Dim SelIndex as Integer
252 Dim QueryIndex as Integer
254 On Local Error GoTo NOFIELDS
256 SelIndex = DlgFormDB.GetControl(
"lstTables
").getSelectedItemPos()
'.SelectedItems())
257 If SelIndex
> -
1 Then
258 If bGetCommandType Then
259 CurCommandType = iCommandTypes(SelIndex)
261 If CurCommandType = com.sun.star.sdb.CommandType.QUERY Then
262 QueryIndex = SelIndex - Ubound(Tablenames()) -
1
263 Tablename = QueryNames(QueryIndex)
264 oColumns = oDBConnection.Queries.GetByName(TableName).Columns
266 Tablename = Tablenames(SelIndex)
267 oColumns = oDBConnection.Tables.GetByName(Tablename).Columns
269 If GetSpecificFieldNames()
<> -
1 Then
270 ToggleListboxControls(DialogModel, True)
274 EmptyFieldsListboxes()
276 If Err
<> 0 Then
277 MsgBox sMsgErrCouldNotOpenObject,
16, sMsgWizardName
284 On Local Error GoTo WIZARDERROR
288 .cmdBack.Enabled = False
289 .cmdGoOn.Enabled = True
290 .lstSelFields.Tag = Not bControlsareCreated
291 .cmdGoOn.Label = sGoOn
292 .imgTheme.ImageUrl = FormPath
& "FormWizard_1.bmp
"
296 If Err
<> 0 Then
297 Msgbox(sMsgErrMsg,
16, GetProductName())
306 On Local Error GoTo WIZARDERROR
308 Select Case DialogModel.Step
310 bControlsAreCreated = Not (cBool(DialogModel.lstSelFields.Tag))
311 If Not bControlsAreCreated Then
315 InitializeLayoutSettings()
318 DialogModel.cmdGoOn.Label = sReady
319 DialogModel.cmdBack.Enabled = True
324 DlgFormDB.EndExecute()
327 DialogModel.imgTheme.ImageUrl = FormPath
& "FormWizard_
" & DialogModel.Step
& ".bmp
"
328 DlgFormDB.Title = WizardTitle(DialogModel.Step)
330 If Err
<> 0 Then
331 Msgbox(sMsgErrMsg,
16, GetProductName())
338 Sub InitializeLayoutSettings()
339 SwitchArrangementButtons(cTabled)
340 SwitchAlignMode(SBALIGNLEFT)
341 SwitchBorderMode(SB3DBORDER)
342 ToggleBorderGroup(bControlsAreCreated)
343 ToggleAlignGroup(bControlsAreCreated)
345 If OldAlignMode
<> 0 Then
346 DlgFormDB.GetControl(
"optAlign2
").Model.State =
0
351 Sub ToggleDatabasePage(bDoEnable as Boolean)
353 .cmdBack.Enabled = False
354 .cmdHelp.Enabled = bDoEnable
355 .cmdGoOn.Enabled = Ubound(DialogModel.lstSelFields.StringItemList())
<> -
1
356 .hlnBinaries.Enabled = ((bDoEnable = True) And (bEnableBinaryOptionGroup = True))
357 .optIgnoreBinaries.Enabled = ((bDoEnable = True) And (bEnableBinaryOptionGroup = True))
358 .optBinariesasGraphics.Enabled = ((bDoEnable = True) And (bEnableBinaryOptionGroup = True))
363 ' This Sub is called from the Procedure
"StoreDocument
" in the
"Tools
" Library
364 Sub CommitLastDocumentChanges(sTargetPath as String)
366 Dim sBookmarkName as String
367 Dim oDBBookmarks as Object
368 Dim bLinkExists as Boolean
369 Dim sBaseBookmarkName as String
370 sBookmarkName = GetFileNamewithoutExtension(FileNameoutofPath(sTargetPath))
371 sBaseBookmarkName = sBookmarkName
372 oDBBookmarks = oDataSource.GetBookmarks()
375 bLinkExists = oDBBookmarks.HasbyName(sBookmarkName)
378 sBookmarkName = sBaseBookmarkName
& "_
" & i
380 oDBBookmarks.insertByName(sBookmarkName, sTargetPath)
382 Loop Until Not bLinkExists
384 GroupShapesTogether()
385 ToggleDesignMode(oDocument)
390 Sub StoreFormInDatabase()
391 Dim NoArgs() as new com.sun.star.beans.PropertyValue
392 FormName =
"Form_
" & sDBName
& "_
" & TableName
& ".sxw
"
393 sFormUrl = TempPath
& "/
" & FormName
394 oDocument.StoreAsUrl(sFormUrl, NoArgs())
396 DlgFormDB.Endexecute()
402 Dim sTargetPath as String
403 Dim TypeNames(
0,
2) as String
404 Dim oMasterKey as Object
405 Dim oTypes() as Object
406 oMasterKey = GetRegistryKeyContent(
"org.openoffice.TypeDetection.Types/
")
407 oTypes() = oMasterKey.Types
408 TypeNames(
0,
0) = GetFilterName(
"StarOffice XML (Writer)
")
409 TypeNames(
0,
1) =
"*.sxw
"
410 TypeNames(
0,
2) =
""
411 StoreFormInDatabase()
412 ' sTargetPath = StoreDocument(oDocument, TypeNames(),
"Form_
" & sDBName
& "_
" & TableName
& ".sxw
", WorkPath,
1)
417 Sub EmptyFieldsListboxes()
418 Dim NullList() as String
419 ToggleListboxControls(DialogModel, False)
420 DialogModel.lstFields.StringItemList() = NullList()
421 DialogModel.lstSelFields.StringItemList() = NullList()
422 bEnableBinaryOptionGroup = False
426 Sub DeleteFirstTableListBoxEntry()
427 DeleteFirstListBoxEntry(
"lstTables
", sSelectDBTable)
430 Sub DeleteFirstListboxEntry(ListBoxName as String, DelEntryName as String)
431 Dim oListbox as Object
432 Dim sFirstItem as String
433 dim iSelPos as Integer
434 oListBox = DlgFormDB.getControl(ListBoxName)
435 sFirstItem = oListBox.getItem(
0)
436 If sFirstItem = DelEntryName Then
437 iSelPos = oListBox.getSelectedItemPos()
438 oListBox.removeItems(
0,
1)
439 If iSelPos
> 0 Then
440 oListBox.selectItemPos(iSelPos-
1, True)