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=
"FormWizard" script:
language=
"StarBasic">Option Explicit
5 Public DocumentName as String
6 Public FormPath as String
7 Public WizardPath as String
8 Public WebWizardPath as String
9 Public WorkPath as String
10 Public TempPath as String
11 Public TexturePath as String
12 Public sQueryName as String
13 Public oDBConnection as Object
14 Public bWithBackGraphic as Boolean
15 Public bNeedFieldRefresh as Boolean
16 Public oDBForm as Object
17 Public oColumns() as Object
18 Public sDatabaseList() as String
19 Public TableNames() as String
20 Public QueryNames() as String
21 Public FieldNames() as String
22 Public ImgFieldNames() as String
23 Public oDBContext as Object
25 Public oDocInfo as Object
26 Public WidthList(
15,
3)
27 Public ImgWidthList(
3,
3)
28 Public sDBName as String
29 Public Tablename as String
30 Public Const SBSIZETEXT =
"The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.
"
31 Public bDisposeDoc as Boolean
32 Public bDebug as Boolean
33 'Public bStartUp as Boolean
34 Public bConnectionIsovergiven as Boolean
35 Public FormName As String
36 Public sFormUrl as String
40 ' The macro can be called in
4 possible scenarios:
41 ' Scenario
1. No parameters at given
42 ' Scenario
2: Only Datasourcename is given, but no connection and no Content
43 ' Scenario
3: a data source and a connection are given
44 ' Scenario
4: all parameters (data source name, connection, object type and object) are given
47 Dim oLocDBContext as Object
48 Dim oLocConnection as Object
50 ' Scenario
1. No parameters at given
53 ' Scenario
2: Only Datasourcename is given, but no connection and no Content
54 ' MainWithDefault(
"Bibliography
")
56 ' Scenario
3: a data source and a connection are given
57 ' oLocDBContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
58 ' oLocConnection = oLocDBContext.GetByName(
"Bibliography
").GetConnection(
"",
"")
59 ' MainWithDefault(
"Bibliography
", oLocConnection)
61 ' Scenario
4: all parameters (data source name, connection, object type and object) are given
62 ' oLocDBContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
63 ' oLocConnection = oLocDBContext.GetByName(
"Bibliography
").GetConnection(
"",
"")
64 ' MainWithDefault(
"Bibliography
", oLocConnection, com.sun.star.sdb.CommandType.TABLE,
"biblio
")
68 Sub MainWithDefault(Optional DatasourceName as String, Optional oConnection as Object, Optional CommandType as Integer, Optional sContent as String)
70 Dim SelCount as Integer
71 Dim RetValue as Integer
72 Dim SelList(
0) as Integer
73 Dim LocList() as String
75 BasicLibraries.LoadLibrary(
"Tools
")
76 BasicLibraries.LoadLibrary(
"WebWizard
")
79 On Local Error GoTo WIZARDERROR
83 bControlsareCreated = False
84 bEnableBinaryOptionGroup = False
87 If Not InitResources(
"Formwizard
",
"dbw
") Then
90 oDBContext = CreateUnoService(
"com.sun.star.sdb.DatabaseContext
")
91 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
92 If GetFormWizardPaths() = False Then
95 oDocument.GetCurrentController().Frame.ComponentWindow.Enable = False
96 oProgressBar.Value =
10
98 oProgressBar.Value =
20
100 oProgressBar.Value =
30
101 Styles() = getListBoxArrays(oUcb,
"/stl
")
102 CurIndex = GetCurIndex(DialogModel, Styles(),
2)
103 oProgressBar.Value =
40
105 oProgressBar.Value =
50
106 InitializeLabelValues()
107 bNeedFieldRefresh = True
109 ' bStartUp = true
111 .cmdBack.Enabled = False
112 .cmdGoOn.Enabled = False
113 .lblTables.Enabled = False
114 .lstSelFields.Tag = False
117 oProgressBar.Value =
60
118 bConnectionIsovergiven = Not IsMissing(oConnection)
119 If Not IsMissing(DataSourceName) Then
120 sDBName = DataSourceName
121 If Not IsMissing(oConnection) Then
122 ' Scenario
3: a data source and a connection are given
123 Set oDBConnection = oConnection
124 oDataSource = oDBContext.GetByName(DataSourceName)
125 DialogModel.lstTables.Enabled = True
126 DialogModel.lblTables.Enabled = True
127 If GetDBMetaData() Then
128 LocList() = AddListToList(TableNames(), QueryNames())
129 iCommandTypes = CreateCommandTypeList()
130 If Not IsMissing(sContent) Then
131 ' Scenario
4: all parameters (data source name, connection, object type and object) are given
132 DialogModel.lstTables.StringItemList() = LocList()
133 iCommandTypes() = CreateCommandTypeList()
134 SelCount = CountItemsInArray(DialogModel.lstTables.StringItemList(), sContent)
136 DlgFormDB.GetControl(
"lstTables
").SelectItem(sContent, True)
138 If CommandType = com.sun.star.sdb.CommandType.QUERY Then
139 SelIndex = IndexInArray(sContent, QueryNames()
140 DlgFormDB.GetControl(
"lstTables
").SelectItemPos(SelIndex, True)
141 ElseIf CommandType = com.sun.star.sdb.CommandType.TABLE Then
142 SelIndex = IndexInArray(sContent, TableNames()
143 DlgFormDB.GetControl(
"lstTables
").SelectItemPos(Ubound(QueryNames()+
1 + SelIndex, True)
146 CurCommandType = CommandType
147 FillUpFieldsListbox(False)
149 LocList() = AddListToList(Array(sSelectDBTable), LocList())
150 DialogModel.lstTables.StringItemList() = LocList()
151 ' bSelectContent = True
152 DialogModel.lstTables.SelectedItems() = Array(
0)
157 ' Scenario
2: Only Datasourcename is given, but no connection and no Content
158 GetSelectedDBMetaData(sDBName)
161 ' Scenario
1: No parameters are given
162 ToggleListboxControls(DialogModel, False)
164 oProgressBar.Value =
80
165 bWithBackGraphic = LoadNewStyles(oDocument, DialogModel, CurIndex, Styles(CurIndex,
8), Styles(), TexturePath)
166 DlgFormDB.Title = WizardTitle(
1)
167 DialogModel.lstStyles.StringItemList() = ArrayfromMultiArray(Styles,
1)
168 DialogModel.lstStyles.SelectedItems() = SelList()
169 ControlCaptionsToStandardLayout()
170 oDocument.GetCurrentController().Frame.ComponentWindow.Enable = True
171 oProgressBar.Value =
90
172 DialogModel.imgTheme.ImageURL = FormPath
& "FormWizard_1.bmp
"
173 DialogModel.imgTheme.BackGroundColor = RGB(
0,
60,
126)
174 ToggleDatabasePage(True)
175 oProgressBar.Value =
100
176 DlgFormDB.GetControl(
"lstTables
").SetFocus()
178 RetValue = DlgFormDB.Execute()
181 Dim aPropertyValues(
2) as new com.sun.star.beans.PropertyValue
182 oFormDocuments = oDataSource.getFormDocuments()
185 Dim bLinkExists as Boolean
187 Dim FormBaseName as String
188 FormBaseName = FormName
190 bLinkExists = oFormDocuments.HasbyHierarchicalName(FormName)
193 FormName = FormBaseName
& "_
" & i
195 Loop Until Not bLinkExists
196 aPropertyValues(
0).Name =
"Name
"
197 aPropertyValues(
0).Value = FormName
198 aPropertyValues(
1).Name =
"Parent
"
199 aPropertyValues(
1).Value = oFormDocuments()
200 aPropertyValues(
2).Name =
"URL
"
201 aPropertyValues(
2).Value = sFormUrl
203 oDBDocument = oFormDocuments.createInstanceWithArguments(
"com.sun.star.sdb.DocumentDefinition
", aPropertyValues())
204 oFormDocuments.insertbyName(FormName, oDBDocument)
205 ElseIf RetValue =
0 Then
206 RemoveNirwanaShapes()
208 If ((Not IsNull(oDBConnection)) And (Not bConnectionIsovergiven)) Then
209 oDBConnection.Dispose()
212 If Err
<> 0 Then
213 Msgbox(sMsgErrMsg,
16, GetProductName())
222 ' If bSelectContent Then
223 ' bSelectContent = False
226 DeleteFirstListBoxEntry(
"lstTables
", sSelectDBTable)
227 ToggleDatabasePage(False)
228 FillUpFieldsListbox(True)
229 ToggleDatabasePage(True)
233 Sub FillUpFieldsListbox(bGetCommandType as Boolean)
234 Dim SelIndex as Integer
235 Dim QueryIndex as Integer
237 On Local Error GoTo NOFIELDS
239 SelIndex = DlgFormDB.GetControl(
"lstTables
").getSelectedItemPos()
'.SelectedItems())
240 If SelIndex
> -
1 Then
241 If bGetCommandType Then
242 CurCommandType = iCommandTypes(SelIndex)
244 If CurCommandType = com.sun.star.sdb.CommandType.QUERY Then
245 QueryIndex = SelIndex - Ubound(Tablenames()) -
1
246 Tablename = QueryNames(QueryIndex)
247 oColumns = oDBConnection.Queries.GetByName(TableName).Columns
249 Tablename = Tablenames(SelIndex)
250 oColumns = oDBConnection.Tables.GetByName(Tablename).Columns
252 If GetSpecificFieldNames()
<> -
1 Then
253 ToggleListboxControls(DialogModel, True)
257 EmptyFieldsListboxes()
259 If Err
<> 0 Then
260 MsgBox sMsgErrCouldNotOpenObject,
16, sMsgWizardName
267 On Local Error GoTo WIZARDERROR
271 .cmdBack.Enabled = False
272 .cmdGoOn.Enabled = True
273 .lstSelFields.Tag = Not bControlsareCreated
274 .cmdGoOn.Label = sGoOn
275 .imgTheme.ImageUrl = FormPath
& "FormWizard_1.bmp
"
279 If Err
<> 0 Then
280 Msgbox(sMsgErrMsg,
16, GetProductName())
289 On Local Error GoTo WIZARDERROR
291 Select Case DialogModel.Step
293 bControlsAreCreated = Not (cBool(DialogModel.lstSelFields.Tag))
294 If Not bControlsAreCreated Then
298 InitializeLayoutSettings()
301 DialogModel.cmdGoOn.Label = sReady
302 DialogModel.cmdBack.Enabled = True
307 DlgFormDB.EndExecute()
310 DialogModel.imgTheme.ImageUrl = FormPath
& "FormWizard_
" & DialogModel.Step
& ".bmp
"
311 DlgFormDB.Title = WizardTitle(DialogModel.Step)
313 If Err
<> 0 Then
314 Msgbox(sMsgErrMsg,
16, GetProductName())
321 Sub InitializeLayoutSettings()
322 SwitchArrangementButtons(cTabled)
323 SwitchAlignMode(SBALIGNLEFT)
324 SwitchBorderMode(SB3DBORDER)
325 ToggleBorderGroup(bControlsAreCreated)
326 ToggleAlignGroup(bControlsAreCreated)
328 If OldAlignMode
<> 0 Then
329 DlgFormDB.GetControl(
"optAlign2
").Model.State =
0
334 Sub ToggleDatabasePage(bDoEnable as Boolean)
336 .cmdBack.Enabled = False
337 .cmdHelp.Enabled = bDoEnable
338 .cmdGoOn.Enabled = Ubound(DialogModel.lstSelFields.StringItemList())
<> -
1
339 .hlnBinaries.Enabled = ((bDoEnable = True) And (bEnableBinaryOptionGroup = True))
340 .optIgnoreBinaries.Enabled = ((bDoEnable = True) And (bEnableBinaryOptionGroup = True))
341 .optBinariesasGraphics.Enabled = ((bDoEnable = True) And (bEnableBinaryOptionGroup = True))
346 ' This Sub is called from the Procedure
"StoreDocument
" in the
"Tools
" Library
347 Sub CommitLastDocumentChanges(sTargetPath as String)
349 Dim sBookmarkName as String
350 Dim oDBBookmarks as Object
351 Dim bLinkExists as Boolean
352 Dim sBaseBookmarkName as String
353 sBookmarkName = GetFileNamewithoutExtension(FileNameoutofPath(sTargetPath))
354 sBaseBookmarkName = sBookmarkName
355 oDBBookmarks = oDataSource.GetBookmarks()
358 bLinkExists = oDBBookmarks.HasbyName(sBookmarkName)
361 sBookmarkName = sBaseBookmarkName
& "_
" & i
363 oDBBookmarks.insertByName(sBookmarkName, sTargetPath)
365 Loop Until Not bLinkExists
367 GroupShapesTogether()
368 ToggleDesignMode(oDocument)
373 Sub StoreFormInDatabase()
374 Dim NoArgs() as new com.sun.star.beans.PropertyValue
375 FormName =
"Form_
" & sDBName
& "_
" & TableName
& ".sxw
"
376 sFormUrl = TempPath
& "/
" & FormName
377 oDocument.StoreAsUrl(sFormUrl, NoArgs())
379 DlgFormDB.Endexecute()
385 Dim sTargetPath as String
386 Dim TypeNames(
0,
2) as String
387 Dim oMasterKey as Object
388 Dim oTypes() as Object
389 oMasterKey = GetRegistryKeyContent(
"org.openoffice.TypeDetection.Types/
")
390 oTypes() = oMasterKey.Types
391 TypeNames(
0,
0) = GetFilterName(
"StarOffice XML (Writer)
")
392 TypeNames(
0,
1) =
"*.sxw
"
393 TypeNames(
0,
2) =
""
394 StoreFormInDatabase()
395 ' sTargetPath = StoreDocument(oDocument, TypeNames(),
"Form_
" & sDBName
& "_
" & TableName
& ".sxw
", WorkPath,
1)
400 Sub EmptyFieldsListboxes()
401 Dim NullList() as String
402 ToggleListboxControls(DialogModel, False)
403 DialogModel.lstFields.StringItemList() = NullList()
404 DialogModel.lstSelFields.StringItemList() = NullList()
405 bEnableBinaryOptionGroup = False
409 Sub DeleteFirstTableListBoxEntry()
410 DeleteFirstListBoxEntry(
"lstTables
", sSelectDBTable)
413 Sub DeleteFirstListboxEntry(ListBoxName as String, DelEntryName as String)
414 Dim oListbox as Object
415 Dim sFirstItem as String
416 dim iSelPos as Integer
417 oListBox = DlgFormDB.getControl(ListBoxName)
418 sFirstItem = oListBox.getItem(
0)
419 If sFirstItem = DelEntryName Then
420 iSelPos = oListBox.getSelectedItemPos()
421 oListBox.removeItems(
0,
1)
422 If iSelPos
> 0 Then
423 oListBox.selectItemPos(iSelPos-
1, True)