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=
"ModuleControls" script:
language=
"StarBasic">Option Explicit
5 Public DlgOverwrite as Object
6 Public Const SBOVERWRITEUNDEFINED as Integer =
0
7 Public Const SBOVERWRITECANCEL as Integer =
2
8 Public Const SBOVERWRITEQUERY as Integer =
7
9 Public Const SBOVERWRITEALWAYS as Integer =
6
10 Public Const SBOVERWRITENEVER as Integer =
8
11 Public iGeneralOverwrite as Integer
15 ' Accepts the name of a control and returns the respective control model as object
16 ' The Container can either be a whole document or a specific sheet of a Calc-Document
17 ' 'CName
' is the name of the Control
18 Function getControlModel(oContainer as Object, CName as String)
19 Dim aForm, oForms as Object
21 oForms = oContainer.Drawpage.GetForms
22 For i =
0 To oForms.Count-
1
23 aForm = oForms.GetbyIndex(i)
24 If aForm.HasByName(CName) Then
25 GetControlModel = aForm.GetbyName(CName)
29 Msgbox(
"No Control with the name
'" & CName
& "' found
" ,
16, GetProductName())
34 ' Gets the Shape of a Control( e. g. to reset the size or Position of the control
36 ' The
'oContainer
' is the Document or a specific sheet of a Calc - Document
37 ' 'CName
' is the Name of the Control
38 Function GetControlShape(oContainer as Object,CName as String)
41 For i =
0 to oContainer.DrawPage.Count-
1
42 aShape = oContainer.DrawPage(i)
43 If HasUnoInterfaces(aShape,
"com.sun.star.drawing.XControlShape
") then
44 If ashape.Control.Name = CName then
45 GetControlShape = aShape
53 ' Returns the View of a Control
55 ' The
'oContainer
' is the Document or a specific sheet of a Calc - Document
56 ' The
'oController
' is always directly attached to the Document
57 ' 'CName
' is the Name of the Control
58 Function getControlView(oContainer , oController as Object, CName as String) as Object
59 Dim aForm, oForms, oControlModel as Object
61 oForms = oContainer.DrawPage.Forms
62 For i =
0 To oForms.Count-
1
63 aForm = oforms.GetbyIndex(i)
64 If aForm.HasByName(CName) Then
65 oControlModel = aForm.GetbyName(CName)
66 GetControlView = oController.GetControl(oControlModel)
70 Msgbox(
"No Control with the name
'" & CName
& "' found
" ,
16, GetProductName())
76 ' The
'oContainer
' is the Document or a specific sheet of a Calc - Document
77 ' 'CName
' is the Name of the Control
78 Function DisposeControl(oContainer as Object, CName as String) as Boolean
79 Dim aControl as Object
81 aControl = GetControlModel(oContainer,CName)
82 If not IsNull(aControl) Then
86 DisposeControl = False
91 ' Returns a sequence of a group of controls like option buttons or checkboxes
92 ' The
'oContainer
' is the Document or a specific sheet of a Calc - Document
93 ' 'sGroupName
' is the Name of the Controlgroup
94 Function GetControlGroupModel(oContainer as Object, sGroupName as String )
95 Dim aForm, oForms As Object
96 Dim aControlModel() As Object
99 oForms = oContainer.DrawPage.Forms
100 For i =
0 To oForms.Count-
1
102 If aForm.HasbyName(sGroupName) Then
103 aForm.GetGroupbyName(sGroupName,aControlModel)
104 GetControlGroupModel = aControlModel
108 Msgbox(
"No Controlgroup with the name
'" & sGroupName
& "' found
" ,
16, GetProductName())
112 ' Returns the Referencevalue of a group of e.g. option buttons or check boxes
113 ' 'oControlGroup
' is a sequence of the Control objects
114 Function GetRefValue(oControlGroup() as Object)
116 For i =
0 To Ubound(oControlGroup())
117 ' oControlGroup(i).DefaultState = oControlGroup(i).State
118 If oControlGroup(i).State Then
119 GetRefValue = oControlGroup(i).RefValue
127 Function GetRefValueOfControlGroup(oContainer as Object, GroupName as String)
128 Dim oOptGroup() as Object
130 oOptGroup() = GetControlGroupModel(oContainer, GroupName)
131 iRef = GetRefValue(oOptGroup())
132 GetRefValueofControlGroup = iRef
136 Function GetOptionGroupValue(oContainer as Object, OptGroupName as String) as Boolean
137 Dim oRulesOptions() as Object
138 oRulesOptions() = GetControlGroupModel(oContainer, OptGroupName)
139 GetOptionGroupValue = oRulesOptions(
0).State
144 Function WriteOptValueToCell(oSheet as Object, OptGroupName as String, iCol as Integer, iRow as Integer) as Boolean
145 Dim bOptValue as Boolean
147 bOptValue = GetOptionGroupValue(oSheet, OptGroupName)
148 oCell = oSheet.GetCellByPosition(iCol, iRow)
149 oCell.SetValue(ABS(CInt(bOptValue)))
150 WriteOptValueToCell() = bOptValue
154 Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)
156 Dim oLibDialog as Object
157 Dim oRuntimeDialog as Object
158 If IsMissing(oLibContainer ) then
159 oLibContainer = DialogLibraries
161 oLibContainer.LoadLibrary(LibName)
162 oLib = oLibContainer.GetByName(Libname)
163 oLibDialog = oLib.GetByName(DialogName)
164 oRuntimeDialog = CreateUnoDialog(oLibDialog)
165 LoadDialog() = oRuntimeDialog
169 Sub GetFolderName(oRefModel as Object)
170 Dim oFolderDialog as Object
171 Dim iAccept as Integer
173 Dim InitPath as String
174 Dim RefControlName as String
176 'Note: The following services have to be called in the following order
177 ' because otherwise Basic does not remove the FileDialog Service
178 oFolderDialog = CreateUnoService(
"com.sun.star.ui.dialogs.FolderPicker
")
179 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
180 InitPath = ConvertToUrl(oRefModel.Text)
181 If InitPath =
"" Then
182 InitPath = GetPathSettings(
"Work
")
184 If oUcb.Exists(InitPath) Then
185 oFolderDialog.SetDisplayDirectory(InitPath)
187 iAccept = oFolderDialog.Execute()
189 sPath = oFolderDialog.GetDirectory()
190 If oUcb.Exists(sPath) Then
191 oRefModel.Text = ConvertFromUrl(sPath)
197 Sub GetFileName(oRefModel as Object, Filternames())
198 Dim oFileDialog as Object
199 Dim iAccept as Integer
201 Dim InitPath as String
202 Dim RefControlName as String
205 'Note: The following services have to be called in the following order
206 ' because otherwise Basic does not remove the FileDialog Service
207 oFileDialog = CreateUnoService(
"com.sun.star.ui.dialogs.FilePicker
")
208 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
209 'ListAny(
0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE
210 'oFileDialog.initialize(ListAny())
211 AddFiltersToDialog(FilterNames(), oFileDialog)
212 InitPath = ConvertToUrl(oRefModel.Text)
213 If InitPath =
"" Then
214 InitPath = GetPathSettings(
"Work
")
216 If oUcb.Exists(InitPath) Then
217 oFileDialog.SetDisplayDirectory(InitPath)
219 iAccept = oFileDialog.Execute()
221 sPath = oFileDialog.Files(
0)
222 If oUcb.Exists(sPath) Then
223 oRefModel.Text = ConvertFromUrl(sPath)
226 oFileDialog.Dispose()
230 Function StoreDocument(oDocument as Object, FilterNames() as String, DefaultName as String, DisplayDirectory as String, Optional iAddProcedure as Integer) as String
231 Dim NoArgs() as New com.sun.star.beans.PropertyValue
232 Dim oStoreProperties(
0) as New com.sun.star.beans.PropertyValue
233 Dim oStoreDialog as Object
234 Dim iAccept as Integer
236 Dim ListAny(
0) as Long
237 Dim UIFilterName as String
238 Dim FilterName as String
239 Dim FilterIndex as Integer
240 ListAny(
0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD
241 oStoreDialog = CreateUnoService(
"com.sun.star.ui.dialogs.FilePicker
")
242 oStoreDialog.Initialize(ListAny())
243 AddFiltersToDialog(FilterNames(), oStoreDialog)
244 oStoreDialog.SetDisplayDirectory(DisplayDirectory)
245 oStoreDialog.SetDefaultName(DefaultName)
246 oStoreDialog.setValue(com.sun.star.ui.dialogs.ExtendedFilePickerElementIds.CHECKBOX_AUTOEXTENSION,
0, true)
248 iAccept = oStoreDialog.Execute()
250 sPath = oStoreDialog.Files(
0)
251 UIFilterName = oStoreDialog.GetCurrentFilter()
252 FilterIndex = IndexInArray(UIFilterName, FilterNames())
253 FilterName = FilterNames(FilterIndex,
2)
254 If Not IsMissing(iAddProcedure) Then
255 Select Case iAddProcedure
257 CommitLastDocumentChanges(sPath)
260 On Local Error Goto NOSAVING
261 If FilterName =
"" Then
262 ' Todo: Catch the case that a document that has to be overwritten is writeportected (e.g. it is open)
263 oDocument.StoreAsUrl(sPath, NoArgs())
265 oStoreProperties(
0).Name =
"FilterName
"
266 oStoreProperties(
0).Value = FilterName
267 oDocument.StoreAsUrl(sPath, oStoreProperties())
270 oStoreDialog.dispose()
271 StoreDocument() = sPath
274 If Err
<> 0 Then
275 ' Msgbox(
"Document cannot be saved under
'" & ConvertFromUrl(sPath)
& "'",
48, GetProductName())
277 oStoreDialog.dispose()
284 Sub AddFiltersToDialog(FilterNames() as String, oDialog as Object)
286 Dim MaxIndex as Integer
287 Dim ViewFiltername as String
288 Dim oProdNameAccess as Object
289 Dim sProdName as String
290 oProdNameAccess = GetRegistryKeyContent(
"org.openoffice.Setup/Product
")
291 sProdName = oProdNameAccess.getByName(
"ooName
")
292 MaxIndex = Ubound(FilterNames(),
1)
293 For i =
0 To MaxIndex
294 Filternames(i,
0) = ReplaceString(Filternames(i,
0), sProdName,
"%productname%
")
295 oDialog.AppendFilter(FilterNames(i,
0), FilterNames(i,
1))
297 oDialog.SetCurrentFilter(FilterNames(
0,
0)
301 Sub SwitchMousePointer(oWindowPeer as Object, bDoEnable as Boolean)
302 Dim oWindowPointer as Object
303 oWindowPointer = CreateUnoService(
"com.sun.star.awt.Pointer
")
305 oWindowPointer.SetType(com.sun.star.awt.SystemPointer.ARROW)
307 oWindowPointer.SetType(com.sun.star.awt.SystemPointer.WAIT)
309 oWindowPeer.SetPointer(oWindowPointer)
313 Sub ShowOverwriteAllDialog(FilePath as String, sTitle as String)
314 Dim QueryString as String
315 Dim LocRetValue as Integer
318 Dim lblYesToAll as String
319 Dim lblCancel as String
320 Dim OverwriteModel as Object
321 If InitResources(GetProductName(),
"dbw
") Then
322 QueryString = GetResText(
507)
323 QueryString = ReplaceString(QueryString, ConvertFromUrl(FilePath),
"<PATH
>")
324 If Len(QueryString)
> 190 Then
325 QueryString = DeleteStr(QueryString,
".
<BR
>")
327 QueryString = ReplaceString(QueryString, chr(
13),
"<BR
>")
328 lblYes = GetResText(
508)
329 lblYesToAll = GetResText(
509)
330 lblNo = GetResText(
510)
331 lblCancel = GetResText(
511)
332 DlgOverwrite = LoadDialog(
"Tools
",
"DlgOverwriteAll
")
333 DlgOverwrite.Title = sTitle
334 OverwriteModel = DlgOverwrite.Model
335 OverwriteModel.cmdYes.Label = lblYes
336 OverwriteModel.cmdYesToAll.Label = lblYesToAll
337 OverwriteModel.cmdNo.Label = lblNo
338 OverwriteModel.cmdCancel.Label = lblCancel
339 OverwriteModel.lblQueryforSave.Label = QueryString
340 OverwriteModel.cmdNo.DefaultButton = True
341 DlgOverwrite.GetControl(
"cmdNo
").SetFocus()
342 iGeneralOverwrite =
999
343 LocRetValue = DlgOverwrite.execute()
344 If iGeneralOverwrite =
999 Then
345 iGeneralOverwrite = SBOVERWRITECANCEL
347 DlgOverwrite.dispose()
349 iGeneralOverwrite = SBOVERWRITECANCEL
354 Sub SetOVERWRITEToQuery()
355 iGeneralOverwrite = SBOVERWRITEQUERY
356 DlgOverwrite.EndExecute()
360 Sub SetOVERWRITEToAlways()
361 iGeneralOverwrite = SBOVERWRITEALWAYS
362 DlgOverwrite.EndExecute()
366 Sub SetOVERWRITEToNever()
367 iGeneralOverwrite = SBOVERWRITENEVER
368 DlgOverwrite.EndExecute()