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=
"ModuleControls" script:
language=
"StarBasic">Option Explicit
22 Public DlgOverwrite as Object
23 Public Const SBOVERWRITEUNDEFINED as Integer =
0
24 Public Const SBOVERWRITECANCEL as Integer =
2
25 Public Const SBOVERWRITEQUERY as Integer =
7
26 Public Const SBOVERWRITEALWAYS as Integer =
6
27 Public Const SBOVERWRITENEVER as Integer =
8
28 Public iGeneralOverwrite as Integer
32 ' Accepts the name of a control and returns the respective control model as object
33 ' The Container can either be a whole document or a specific sheet of a Calc-Document
34 ' 'CName
' is the name of the Control
35 Function getControlModel(oContainer as Object, CName as String)
36 Dim aForm, oForms as Object
38 oForms = oContainer.Drawpage.GetForms
39 For i =
0 To oForms.Count-
1
40 aForm = oForms.GetbyIndex(i)
41 If aForm.HasByName(CName) Then
42 GetControlModel = aForm.GetbyName(CName)
46 Msgbox(
"No Control with the name
'" & CName
& "' found
" ,
16, GetProductName())
51 ' Gets the Shape of a Control( e. g. to reset the size or Position of the control
53 ' The
'oContainer
' is the Document or a specific sheet of a Calc - Document
54 ' 'CName
' is the Name of the Control
55 Function GetControlShape(oContainer as Object,CName as String)
58 For i =
0 to oContainer.DrawPage.Count-
1
59 aShape = oContainer.DrawPage(i)
60 If HasUnoInterfaces(aShape,
"com.sun.star.drawing.XControlShape
") then
61 If ashape.Control.Name = CName then
62 GetControlShape = aShape
70 ' Returns the View of a Control
72 ' The
'oContainer
' is the Document or a specific sheet of a Calc - Document
73 ' The
'oController
' is always directly attached to the Document
74 ' 'CName
' is the Name of the Control
75 Function getControlView(oContainer , oController as Object, CName as String) as Object
76 Dim aForm, oForms, oControlModel as Object
78 oForms = oContainer.DrawPage.Forms
79 For i =
0 To oForms.Count-
1
80 aForm = oforms.GetbyIndex(i)
81 If aForm.HasByName(CName) Then
82 oControlModel = aForm.GetbyName(CName)
83 GetControlView = oController.GetControl(oControlModel)
87 Msgbox(
"No Control with the name
'" & CName
& "' found
" ,
16, GetProductName())
93 ' The
'oContainer
' is the Document or a specific sheet of a Calc - Document
94 ' 'CName
' is the Name of the Control
95 Function DisposeControl(oContainer as Object, CName as String) as Boolean
96 Dim aControl as Object
98 aControl = GetControlModel(oContainer,CName)
99 If not IsNull(aControl) Then
101 DisposeControl = True
103 DisposeControl = False
108 ' Returns a sequence of a group of controls like option buttons or checkboxes
109 ' The
'oContainer
' is the Document or a specific sheet of a Calc - Document
110 ' 'sGroupName
' is the Name of the Controlgroup
111 Function GetControlGroupModel(oContainer as Object, sGroupName as String )
112 Dim aForm, oForms As Object
113 Dim aControlModel() As Object
116 oForms = oContainer.DrawPage.Forms
117 For i =
0 To oForms.Count-
1
119 If aForm.HasbyName(sGroupName) Then
120 aForm.GetGroupbyName(sGroupName,aControlModel)
121 GetControlGroupModel = aControlModel
125 Msgbox(
"No Controlgroup with the name
'" & sGroupName
& "' found
" ,
16, GetProductName())
129 ' Returns the Referencevalue of a group of e.g. option buttons or check boxes
130 ' 'oControlGroup
' is a sequence of the Control objects
131 Function GetRefValue(oControlGroup() as Object)
133 For i =
0 To Ubound(oControlGroup())
134 ' oControlGroup(i).DefaultState = oControlGroup(i).State
135 If oControlGroup(i).State Then
136 GetRefValue = oControlGroup(i).RefValue
144 Function GetRefValueOfControlGroup(oContainer as Object, GroupName as String)
145 Dim oOptGroup() as Object
147 oOptGroup() = GetControlGroupModel(oContainer, GroupName)
148 iRef = GetRefValue(oOptGroup())
149 GetRefValueofControlGroup = iRef
153 Function GetOptionGroupValue(oContainer as Object, OptGroupName as String) as Boolean
154 Dim oRulesOptions() as Object
155 oRulesOptions() = GetControlGroupModel(oContainer, OptGroupName)
156 GetOptionGroupValue = oRulesOptions(
0).State
161 Function WriteOptValueToCell(oSheet as Object, OptGroupName as String, iCol as Integer, iRow as Integer) as Boolean
162 Dim bOptValue as Boolean
164 bOptValue = GetOptionGroupValue(oSheet, OptGroupName)
165 oCell = oSheet.GetCellByPosition(iCol, iRow)
166 oCell.SetValue(ABS(CInt(bOptValue)))
167 WriteOptValueToCell() = bOptValue
171 Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)
173 Dim oLibDialog as Object
174 Dim oRuntimeDialog as Object
175 If IsMissing(oLibContainer ) then
176 oLibContainer = DialogLibraries
178 oLibContainer.LoadLibrary(LibName)
179 oLib = oLibContainer.GetByName(Libname)
180 oLibDialog = oLib.GetByName(DialogName)
181 oRuntimeDialog = CreateUnoDialog(oLibDialog)
182 LoadDialog() = oRuntimeDialog
186 Sub GetFolderName(oRefModel as Object)
187 Dim oFolderDialog as Object
188 Dim iAccept as Integer
190 Dim InitPath as String
191 Dim RefControlName as String
193 'Note: The following services have to be called in the following order
194 ' because otherwise Basic does not remove the FileDialog Service
195 oFolderDialog = CreateUnoService(
"com.sun.star.ui.dialogs.FolderPicker
")
196 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
197 InitPath = ConvertToUrl(oRefModel.Text)
198 If InitPath =
"" Then
199 InitPath = GetPathSettings(
"Work
")
201 If oUcb.Exists(InitPath) Then
202 oFolderDialog.SetDisplayDirectory(InitPath)
204 iAccept = oFolderDialog.Execute()
206 sPath = oFolderDialog.GetDirectory()
207 If oUcb.Exists(sPath) Then
208 oRefModel.Text = ConvertFromUrl(sPath)
214 Sub GetFileName(oRefModel as Object, Filternames())
215 Dim oFileDialog as Object
216 Dim iAccept as Integer
218 Dim InitPath as String
219 Dim RefControlName as String
222 'Note: The following services have to be called in the following order
223 ' because otherwise Basic does not remove the FileDialog Service
224 oFileDialog = CreateUnoService(
"com.sun.star.ui.dialogs.FilePicker
")
225 oUcb = createUnoService(
"com.sun.star.ucb.SimpleFileAccess
")
226 'ListAny(
0) = com.sun.star.ui.dialogs.TemplateDescription.FILEOPEN_SIMPLE
227 'oFileDialog.initialize(ListAny())
228 AddFiltersToDialog(FilterNames(), oFileDialog)
229 InitPath = ConvertToUrl(oRefModel.Text)
230 If InitPath =
"" Then
231 InitPath = GetPathSettings(
"Work
")
233 If oUcb.Exists(InitPath) Then
234 oFileDialog.SetDisplayDirectory(InitPath)
236 iAccept = oFileDialog.Execute()
238 sPath = oFileDialog.Files(
0)
239 If oUcb.Exists(sPath) Then
240 oRefModel.Text = ConvertFromUrl(sPath)
243 oFileDialog.Dispose()
247 Function StoreDocument(oDocument as Object, FilterNames() as String, DefaultName as String, DisplayDirectory as String, Optional iAddProcedure as Integer) as String
248 Dim NoArgs() as New com.sun.star.beans.PropertyValue
249 Dim oStoreProperties(
0) as New com.sun.star.beans.PropertyValue
250 Dim oStoreDialog as Object
251 Dim iAccept as Integer
253 Dim ListAny(
0) as Long
254 Dim UIFilterName as String
255 Dim FilterName as String
256 Dim FilterIndex as Integer
257 ListAny(
0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION_PASSWORD
258 oStoreDialog = CreateUnoService(
"com.sun.star.ui.dialogs.FilePicker
")
259 oStoreDialog.Initialize(ListAny())
260 AddFiltersToDialog(FilterNames(), oStoreDialog)
261 oStoreDialog.SetDisplayDirectory(DisplayDirectory)
262 oStoreDialog.SetDefaultName(DefaultName)
263 oStoreDialog.setValue(com.sun.star.ui.dialogs.ExtendedFilePickerElementIds.CHECKBOX_AUTOEXTENSION,
0, true)
265 iAccept = oStoreDialog.Execute()
267 sPath = oStoreDialog.Files(
0)
268 UIFilterName = oStoreDialog.GetCurrentFilter()
269 FilterIndex = IndexInArray(UIFilterName, FilterNames())
270 FilterName = FilterNames(FilterIndex,
2)
271 If Not IsMissing(iAddProcedure) Then
272 Select Case iAddProcedure
274 CommitLastDocumentChanges(sPath)
277 On Local Error Goto NOSAVING
278 If FilterName =
"" Then
279 ' Todo: Catch the case that a document that has to be overwritten is writeprotected (e.g. it is open)
280 oDocument.StoreAsUrl(sPath, NoArgs())
282 oStoreProperties(
0).Name =
"FilterName
"
283 oStoreProperties(
0).Value = FilterName
284 oDocument.StoreAsUrl(sPath, oStoreProperties())
287 oStoreDialog.dispose()
288 StoreDocument() = sPath
291 If Err
<> 0 Then
292 ' Msgbox(
"Document cannot be saved under
'" & ConvertFromUrl(sPath)
& "'",
48, GetProductName())
294 oStoreDialog.dispose()
301 Sub AddFiltersToDialog(FilterNames() as String, oDialog as Object)
303 Dim MaxIndex as Integer
304 Dim ViewFiltername as String
305 Dim oProdNameAccess as Object
306 Dim sProdName as String
307 oProdNameAccess = GetRegistryKeyContent(
"org.openoffice.Setup/Product
")
308 sProdName = oProdNameAccess.getByName(
"ooName
")
309 MaxIndex = Ubound(FilterNames(),
1)
310 For i =
0 To MaxIndex
311 Filternames(i,
0) = ReplaceString(Filternames(i,
0), sProdName,
"%productname%
")
312 oDialog.AppendFilter(FilterNames(i,
0), FilterNames(i,
1))
314 oDialog.SetCurrentFilter(FilterNames(
0,
0))
318 Sub SwitchMousePointer(oWindowPeer as Object, bDoEnable as Boolean)
319 Dim oWindowPointer as Object
320 oWindowPointer = CreateUnoService(
"com.sun.star.awt.Pointer
")
322 oWindowPointer.SetType(com.sun.star.awt.SystemPointer.ARROW)
324 oWindowPointer.SetType(com.sun.star.awt.SystemPointer.WAIT)
326 oWindowPeer.SetPointer(oWindowPointer)
330 Sub ShowOverwriteAllDialog(FilePath as String, sTitle as String)
331 Dim QueryString as String
332 Dim LocRetValue as Integer
335 Dim lblYesToAll as String
336 Dim lblCancel as String
337 Dim OverwriteModel as Object
338 If InitResources(GetProductName()) Then
339 QueryString = GetResText(
"RID_COMMON_7
")
340 QueryString = ReplaceString(QueryString, ConvertFromUrl(FilePath),
"<PATH
>")
341 If Len(QueryString)
> 190 Then
342 QueryString = DeleteStr(QueryString,
".
<BR
>")
344 QueryString = ReplaceString(QueryString, chr(
13),
"<BR
>")
345 lblYes = GetResText(
"RID_COMMON_8
")
346 lblYesToAll = GetResText(
"RID_COMMON_9
")
347 lblNo = GetResText(
"RID_COMMON_10
")
348 lblCancel = GetResText(
"RID_COMMON_11
")
349 DlgOverwrite = LoadDialog(
"Tools
",
"DlgOverwriteAll
")
350 DlgOverwrite.Title = sTitle
351 OverwriteModel = DlgOverwrite.Model
352 OverwriteModel.cmdYes.Label = lblYes
353 OverwriteModel.cmdYesToAll.Label = lblYesToAll
354 OverwriteModel.cmdNo.Label = lblNo
355 OverwriteModel.cmdCancel.Label = lblCancel
356 OverwriteModel.lblQueryforSave.Label = QueryString
357 OverwriteModel.cmdNo.DefaultButton = True
358 DlgOverwrite.GetControl(
"cmdNo
").SetFocus()
359 iGeneralOverwrite =
999
360 LocRetValue = DlgOverwrite.execute()
361 If iGeneralOverwrite =
999 Then
362 iGeneralOverwrite = SBOVERWRITECANCEL
364 DlgOverwrite.dispose()
366 iGeneralOverwrite = SBOVERWRITECANCEL
371 Sub SetOVERWRITEToQuery()
372 iGeneralOverwrite = SBOVERWRITEQUERY
373 DlgOverwrite.EndExecute()
377 Sub SetOVERWRITEToAlways()
378 iGeneralOverwrite = SBOVERWRITEALWAYS
379 DlgOverwrite.EndExecute()
383 Sub SetOVERWRITEToNever()
384 iGeneralOverwrite = SBOVERWRITENEVER
385 DlgOverwrite.EndExecute()