calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / wizards / source / scriptforge / SF_Utils.xba
blob23145cb991df1797fb69b9cc306304656b60903d
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="SF_Utils" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === Full documentation is available on https://help.libreoffice.org/ ===
6 REM =======================================================================================================================
8 Option Explicit
9 Option Private Module
11 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
12 &apos;&apos;&apos; SF_Utils
13 &apos;&apos;&apos; ========
14 &apos;&apos;&apos; FOR INTERNAL USE ONLY
15 &apos;&apos;&apos; Groups all private functions used by the official modules
16 &apos;&apos;&apos; Declares the Global variable _SF_
17 &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
19 REM ===================================================================== GLOBALS
21 Global _SF_ As Variant &apos; SF_Root (Basic) object)
23 &apos;&apos;&apos; ScriptForge version
24 Const SF_Version = &quot;7.5&quot;
26 &apos;&apos;&apos; Standard symbolic names for VarTypes
27 &apos; V_EMPTY = 0
28 &apos; V_NULL = 1
29 &apos; V_INTEGER = 2
30 &apos; V_LONG = 3
31 &apos; V_SINGLE = 4
32 &apos; V_DOUBLE = 5
33 &apos; V_CURRENCY = 6
34 &apos; V_DATE = 7
35 &apos; V_STRING = 8
36 &apos;&apos;&apos; Additional symbolic names for VarTypes
37 Global Const V_OBJECT = 9
38 Global Const V_BOOLEAN = 11
39 Global Const V_VARIANT = 12
40 Global Const V_BYTE = 17
41 Global Const V_USHORT = 18
42 Global Const V_ULONG = 19
43 Global Const V_BIGINT = 35
44 Global Const V_DECIMAL = 37
45 Global Const V_ARRAY = 8192
46 &apos;&apos;&apos; Fictive VarTypes
47 Global Const V_NUMERIC = 99 &apos; Synonym of any numeric value [returned by _VarTypeExt()]
48 Global Const V_NOTHING = 101 &apos; Object categories [returned by _VarTypeObj()] Null object
49 Global Const V_UNOOBJECT = 102 &apos; Uno object or Uno structure
50 Global Const V_SFOBJECT = 103 &apos; ScriptForge object: has ObjectType and ServiceName properties
51 Global Const V_BASICOBJECT = 104 &apos; User Basic object
53 Type _ObjectDescriptor &apos; Returned by the _VarTypeObj() method
54 iVarType As Integer &apos; One of the V_NOTHING, V_xxxOBJECT constants
55 sObjectType As String &apos; Either &quot;&quot; or &quot;com.sun.star...&quot; or a ScriptForge object type (ex. &quot;SF_SESSION&quot; or &quot;DICTIONARY&quot;)
56 sServiceName As String &apos; Either &quot;&quot; or the service name of a ScriptForge object type (ex. &quot;ScriptForge.Exception&quot;-
57 End Type
59 REM ================================================================== EXCEPTIONS
61 Const MISSINGARGERROR = &quot;MISSINGARGERROR&quot; &apos; A mandatory argument is missing
62 Const ARGUMENTERROR = &quot;ARGUMENTERROR&quot; &apos; An argument does not pass the _Validate() validation
63 Const ARRAYERROR = &quot;ARRAYERROR&quot; &apos; An argument does not pass the _ValidateArray() validation
64 Const FILEERROR = &quot;FILEERROR&quot; &apos; An argument does not pass the _ValidateFile() validation
66 REM =========================================pvA==================== PRIVATE METHODS
68 REM -----------------------------------------------------------------------------
69 Public Function _CDateToIso(pvDate As Variant) As Variant
70 &apos;&apos;&apos; Returns a string representation of the given Basic date
71 &apos;&apos;&apos; Dates as strings are essential in property values, where Basic dates are evil
73 Dim sIsoDate As Variant &apos; Return value
75 If VarType(pvDate) = V_DATE Then
76 If Year(pvDate) &lt; 1900 Then &apos; Time only
77 sIsoDate = Right(&quot;0&quot; &amp; Hour(pvDate), 2) &amp; &quot;:&quot; &amp; Right(&quot;0&quot; &amp; Minute(pvDate), 2) &amp; &quot;:&quot; &amp; Right(&quot;0&quot; &amp; Second(pvDate), 2)
78 ElseIf Hour(pvDate) + Minute(pvDate) + Second(pvDate) = 0 Then &apos; Date only
79 sIsoDate = Year(pvDate) &amp; &quot;-&quot; &amp; Right(&quot;0&quot; &amp; Month(pvDate), 2) &amp; &quot;-&quot; &amp; Right(&quot;0&quot; &amp; Day(pvDate), 2)
80 Else
81 sIsoDate = Year(pvDate) &amp; &quot;-&quot; &amp; Right(&quot;0&quot; &amp; Month(pvDate), 2) &amp; &quot;-&quot; &amp; Right(&quot;0&quot; &amp; Day(pvDate), 2) _
82 &amp; &quot; &quot; &amp; Right(&quot;0&quot; &amp; Hour(pvDate), 2) &amp; &quot;:&quot; &amp; Right(&quot;0&quot; &amp; Minute(pvDate), 2) _
83 &amp; &quot;:&quot; &amp; Right(&quot;0&quot; &amp; Second(pvDate), 2)
84 End If
85 Else
86 sIsoDate = pvDate
87 End If
89 _CDateToIso = sIsoDate
91 End Function &apos; ScriptForge.SF_Utils._CDateToIso
93 REM -----------------------------------------------------------------------------
94 Public Function _CDateToUnoDate(pvDate As Variant) As Variant
95 &apos;&apos;&apos; Returns a UNO com.sun.star.util.DateTime/Date/Time object depending on the given date
96 &apos;&apos;&apos; by using the appropriate CDateToUnoDateXxx builtin function
97 &apos;&apos;&apos; UNO dates are essential in property values, where Basic dates are evil
99 Dim vUnoDate As Variant &apos; Return value
101 If VarType(pvDate) = V_DATE Then
102 If Year(pvDate) &lt; 1900 Then
103 vUnoDate = CDateToUnoTime(pvDate)
104 ElseIf Hour(pvDate) + Minute(pvDate) + Second(pvDate) = 0 Then
105 vUnoDate = CDateToUnoDate(pvDate)
106 Else
107 vUnoDate = CDateToUnoDateTime(pvDate)
108 End If
109 Else
110 vUnoDate = pvDate
111 End If
113 _CDateToUnoDate = vUnoDate
115 End Function &apos; ScriptForge.SF_Utils._CDateToUnoDate
117 REM -----------------------------------------------------------------------------
118 Public Function _CPropertyValue(ByRef pvValue As Variant) As Variant
119 &apos;&apos;&apos; Set a value of a correct type in a com.sun.star.beans.PropertyValue
120 &apos;&apos;&apos; Date BASIC variables give error. Change them to UNO types
121 &apos;&apos;&apos; Empty arrays should be replaced by Null
123 Dim vValue As Variant &apos; Return value
125 If VarType(pvValue) = V_DATE Then
126 vValue = SF_Utils._CDateToUnoDate(pvValue)
127 ElseIf IsArray(pvValue) Then
128 If UBound(pvValue, 1) &lt; LBound(pvValue, 1) Then vValue = Null Else vValue = pvValue
129 Else
130 vValue = pvValue
131 End If
132 _CPropertyValue() = vValue
134 End Function &apos; ScriptForge.SF_Utils._CPropertyValue
136 REM -----------------------------------------------------------------------------
137 Public Function _CStrToDate(ByRef pvStr As String) As Date
138 &apos;&apos;&apos; Attempt to convert the input string to a Date variable with the CDate builtin function
139 &apos;&apos;&apos; If not successful, returns conventionally -1 (29/12/1899)
140 &apos;&apos;&apos; Date patterns: YYYY-MM-DD, HH:MM:DD and YYYY-MM-DD HH:MM:DD
142 Dim dDate As Date &apos; Return value
143 Const cstNoDate = -1
145 dDate = cstNoDate
146 Try:
147 On Local Error Resume Next
148 dDate = CDate(pvStr)
150 Finally:
151 _CStrToDate = dDate
152 Exit Function
153 End Function &apos; ScriptForge.SF_Utils._CStrToDate
155 REM -----------------------------------------------------------------------------
156 Public Function _EnterFunction(ByVal psSub As String, Optional ByVal psArgs As String)
157 &apos;&apos;&apos; Called on top of each public function
158 &apos;&apos;&apos; Used to trace routine in/outs (debug mode)
159 &apos;&apos;&apos; and to allow the explicit mention of the user call which caused an error
160 &apos;&apos;&apos; Args:
161 &apos;&apos;&apos; psSub = the called Sub/Function/Property, usually something like &quot;service.sub&quot;
162 &apos;&apos;&apos; Return: True when psSub is called from a user script
163 &apos;&apos;&apos; Used to bypass the validation of the arguments when unnecessary
165 If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() &apos; First use of ScriptForge during current LibO session
166 If IsMissing(psArgs) Then psArgs = &quot;&quot;
167 With _SF_
168 If .StackLevel = 0 Then
169 .MainFunction = psSub
170 .MainFunctionArgs = psArgs
171 _EnterFunction = True
172 Else
173 _EnterFunction = False
174 End If
175 .StackLevel = .StackLevel + 1
176 If .DebugMode Then ._AddToConsole(&quot;==&gt; &quot; &amp; psSub &amp; &quot;(&quot; &amp; .StackLevel &amp; &quot;)&quot;)
177 End With
179 End Function &apos; ScriptForge.SF_Utils._EnterFunction
181 REM -----------------------------------------------------------------------------
182 Public Function _ErrorHandling(Optional ByVal pbErrorHandler As Boolean) As Boolean
183 &apos;&apos;&apos; Error handling is normally ON and can be set OFF for debugging purposes
184 &apos;&apos;&apos; Each user visible routine starts with a call to this function to enable/disable
185 &apos;&apos;&apos; standard handling of internal errors
186 &apos;&apos;&apos; Args:
187 &apos;&apos;&apos; pbErrorHandler = if present, set its value
188 &apos;&apos;&apos; Return: the current value of the error handler
190 If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() &apos; First use of ScriptForge during current LibO session
191 If Not IsMissing(pbErrorHandler) Then _SF_.ErrorHandler = pbErrorHandler
192 _ErrorHandling = _SF_.ErrorHandler
194 End Function &apos; ScriptForge.SF_Utils._ErrorHandling
196 REM -----------------------------------------------------------------------------
197 Public Sub _ExitFunction(ByVal psSub As String)
198 &apos;&apos;&apos; Called in the Finally block of each public function
199 &apos;&apos;&apos; Manage ScriptForge internal aborts
200 &apos;&apos;&apos; Resets MainFunction (root) when exiting the method called by a user script
201 &apos;&apos;&apos; Used to trace routine in/outs (debug mode)
202 &apos;&apos;&apos; Args:
203 &apos;&apos;&apos; psSub = the called Sub/Function/Property, usually something like &quot;service.sub&quot;
205 If IsEmpty(_SF_) Or IsNull(_SF_) Then SF_Utils._InitializeRoot() &apos; Useful only when current module has been recompiled
206 With _SF_
207 If Err &gt; 0 Then
208 SF_Exception.RaiseAbort(psSub)
209 End If
210 If .StackLevel = 1 Then
211 .MainFunction = &quot;&quot;
212 .MainFunctionArgs = &quot;&quot;
213 End If
214 If .DebugMode Then ._AddToConsole(&quot;&lt;== &quot; &amp; psSub &amp; &quot;(&quot; &amp; .StackLevel &amp; &quot;)&quot;)
215 If .StackLevel &gt; 0 Then .StackLevel = .StackLevel - 1
216 End With
218 End Sub &apos; ScriptForge.SF_Utils._ExitFunction
220 REM -----------------------------------------------------------------------------
221 Public Sub _ExportScriptForgePOTFile(ByVal FileName As String)
222 &apos;&apos;&apos; Export the ScriptForge POT file related to its own user interface
223 &apos;&apos;&apos; Should be called only before issuing new ScriptForge releases only
224 &apos;&apos;&apos; Args:
225 &apos;&apos;&apos; FileName: the resulting file. If it exists, is overwritten without warning
227 Dim sHeader As String &apos; The specific header to insert
229 sHeader = &quot;&quot; _
230 &amp; &quot;*********************************************************************\n&quot; _
231 &amp; &quot;*** The ScriptForge library and its associated libraries ***\n&quot; _
232 &amp; &quot;*** are part of the LibreOffice project. ***\n&quot; _
233 &amp; &quot;*********************************************************************\n&quot; _
234 &amp; &quot;\n&quot; _
235 &amp; &quot;ScriptForge Release &quot; &amp; SF_Version &amp; &quot;\n&quot; _
236 &amp; &quot;-----------------------&quot;
238 Try:
239 With _SF_
240 If Not IsNull(.LocalizedInterface) Then .LocalizedInterface.Dispose()
241 ._LoadLocalizedInterface(psMode := &quot;ADDTEXT&quot;) &apos; Force reload of labels from the code
242 .LocalizedInterface.ExportToPOTFile(FileName, Header := sHeader)
243 End With
245 Finally:
246 Exit Sub
247 End Sub &apos; ScriptForge.SF_Utils._ExportScriptForgePOTFile
249 REM -----------------------------------------------------------------------------
250 Public Function _GetPropertyValue(ByRef pvArgs As Variant, ByVal psName As String) As Variant
251 &apos;&apos;&apos; Returns the Value corresponding to the given name
252 &apos;&apos;&apos; Args
253 &apos;&apos;&apos; pvArgs: a zero_based array of PropertyValues
254 &apos;&apos;&apos; psName: the comparison is not case-sensitive
255 &apos;&apos;&apos; Returns:
256 &apos;&apos;&apos; Zero-length string if not found
258 Dim vValue As Variant &apos; Return value
259 Dim i As Long
261 vValue = &quot;&quot;
262 If IsArray(pvArgs) Then
263 For i = LBound(pvArgs) To UBound(pvArgs)
264 If UCase(psName) = UCase(pvArgs(i).Name) Then
265 vValue = pvArgs(i).Value
266 Exit For
267 End If
268 Next i
269 End If
270 _GetPropertyValue = vValue
272 End Function &apos; ScriptForge.SF_Utils._GetPropertyValue
274 REM -----------------------------------------------------------------------------
275 Public Function _GetRegistryKeyContent(ByVal psKeyName as string _
276 , Optional pbForUpdate as Boolean _
277 ) As Variant
278 &apos;&apos;&apos; Implement a ConfigurationProvider service
279 &apos;&apos;&apos; Derived from the Tools library
280 &apos;&apos;&apos; Args:
281 &apos;&apos;&apos; psKeyName: the name of the node in the configuration tree
282 &apos;&apos;&apos; pbForUpdate: default = False
284 Dim oConfigProvider as Object &apos; com.sun.star.configuration.ConfigurationProvider
285 Dim vNodePath(0) as New com.sun.star.beans.PropertyValue
286 Dim sConfig As String &apos; One of next 2 constants
287 Const cstConfig = &quot;com.sun.star.configuration.ConfigurationAccess&quot;
288 Const cstConfigUpdate = &quot;com.sun.star.configuration.ConfigurationUpdateAccess&quot;
290 Set oConfigProvider = _GetUNOService(&quot;ConfigurationProvider&quot;)
291 vNodePath(0).Name = &quot;nodepath&quot;
292 vNodePath(0).Value = psKeyName
294 If IsMissing(pbForUpdate) Then pbForUpdate = False
295 If pbForUpdate Then sConfig = cstConfigUpdate Else sConfig = cstConfig
297 Set _GetRegistryKeyContent = oConfigProvider.createInstanceWithArguments(sConfig, vNodePath())
299 End Function &apos; ScriptForge.SF_Utils._GetRegistryKeyContent
301 REM -----------------------------------------------------------------------------
302 Private Function _GetSetting(ByVal psPreference As String, psProperty As String) As Variant
303 &apos;&apos;&apos; Find in the configuration a specific setting based on its location in the
304 &apos;&apos;&apos; settings registry
306 Dim oConfigProvider As Object &apos; com.sun.star.configuration.ConfigurationProvider
307 Dim vNodePath As Variant &apos; Array of com.sun.star.beans.PropertyValue
309 &apos; Derived from the Tools library
310 Set oConfigProvider = createUnoService(&quot;com.sun.star.configuration.ConfigurationProvider&quot;)
311 vNodePath = Array(SF_Utils._MakePropertyValue(&quot;nodepath&quot;, psPreference))
313 _GetSetting = oConfigProvider.createInstanceWithArguments( _
314 &quot;com.sun.star.configuration.ConfigurationAccess&quot;, vNodePath()).getByName(psProperty)
316 End Function &apos; ScriptForge.SF_Utils._GetSetting
318 REM -----------------------------------------------------------------------------
319 Public Function _GetUNOService(ByVal psService As String _
320 , Optional ByVal pvArg As Variant _
321 ) As Object
322 &apos;&apos;&apos; Create a UNO service
323 &apos;&apos;&apos; Each service is called only once
324 &apos;&apos;&apos; Args:
325 &apos;&apos;&apos; psService: shortcut to service
326 &apos;&apos;&apos; pvArg: some services might require an argument
328 Dim sLocale As String &apos; fr-BE f.i.
329 Dim oDefaultContext As Object
331 Set _GetUNOService = Nothing
332 With _SF_
333 Select Case psService
334 Case &quot;BrowseNodeFactory&quot;
335 Set oDefaultContext = GetDefaultContext()
336 If Not IsNull(oDefaultContext) Then Set _GetUNOService = oDefaultContext.getValueByName(&quot;/singletons/com.sun.star.script.browse.theBrowseNodeFactory&quot;)
337 Case &quot;CalendarImpl&quot;
338 If IsEmpty(.CalendarImpl) Or IsNull(.CalendarImpl) Then
339 Set .CalendarImpl = CreateUnoService(&quot;com.sun.star.i18n.CalendarImpl&quot;)
340 End If
341 Set _GetUNOService = .CalendarImpl
342 Case &quot;CharacterClass&quot;
343 If IsEmpty(.CharacterClass) Or IsNull(.CharacterClass) Then
344 Set .CharacterClass = CreateUnoService(&quot;com.sun.star.i18n.CharacterClassification&quot;)
345 End If
346 Set _GetUNOService = .CharacterClass
347 Case &quot;ConfigurationProvider&quot;
348 If IsEmpty(.ConfigurationProvider) Or IsNull(.ConfigurationProvider) Then
349 Set .ConfigurationProvider = CreateUnoService(&quot;com.sun.star.configuration.ConfigurationProvider&quot;)
350 End If
351 Set _GetUNOService = .ConfigurationProvider
352 Case &quot;CoreReflection&quot;
353 If IsEmpty(.CoreReflection) Or IsNull(.CoreReflection) Then
354 Set .CoreReflection = CreateUnoService(&quot;com.sun.star.reflection.CoreReflection&quot;)
355 End If
356 Set _GetUNOService = .CoreReflection
357 Case &quot;DatabaseContext&quot;
358 If IsEmpty(.DatabaseContext) Or IsNull(.DatabaseContext) Then
359 Set .DatabaseContext = CreateUnoService(&quot;com.sun.star.sdb.DatabaseContext&quot;)
360 End If
361 Set _GetUNOService = .DatabaseContext
362 Case &quot;DispatchHelper&quot;
363 If IsEmpty(.DispatchHelper) Or IsNull(.DispatchHelper) Then
364 Set .DispatchHelper = CreateUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
365 End If
366 Set _GetUNOService = .DispatchHelper
367 Case &quot;FileAccess&quot;
368 If IsEmpty(.FileAccess) Or IsNull(.FileAccess) Then
369 Set .FileAccess = CreateUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
370 End If
371 Set _GetUNOService = .FileAccess
372 Case &quot;FilePicker&quot;
373 Set .FilePicker = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;) &apos; Do not reuse an existing FilePicker: TDF#154462
374 Set _GetUNOService = .FilePicker
375 Case &quot;FilterFactory&quot;
376 If IsEmpty(.FilterFactory) Or IsNull(.FilterFactory) Then
377 Set .FilterFactory = CreateUnoService(&quot;com.sun.star.document.FilterFactory&quot;)
378 End If
379 Set _GetUNOService = .FilterFactory
380 Case &quot;FolderPicker&quot;
381 If IsEmpty(.FolderPicker) Or IsNull(.FolderPicker) Then
382 Set .FolderPicker = CreateUnoService(&quot;com.sun.star.ui.dialogs.FolderPicker&quot;)
383 End If
384 Set _GetUNOService = .FolderPicker
385 Case &quot;FormatLocale&quot;
386 If IsEmpty(.FormatLocale) Or IsNull(.FormatLocale) Then
387 .FormatLocale = CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
388 &apos; 1st and 2nd chance
389 sLocale = SF_Utils._GetSetting(&quot;org.openoffice.Setup/L10N&quot;, &quot;ooSetupSystemLocale&quot;)
390 If Len(sLocale) = 0 Then sLocale = SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, &quot;UILocale&quot;)
391 .FormatLocale.Language = Split(sLocale, &quot;-&quot;)(0) &apos; Language is most often 2 chars long, but not always
392 .FormatLocale.Country = Right(sLocale, 2)
393 End If
394 Set _GetUNOService = .FormatLocale
395 Case &quot;FunctionAccess&quot;
396 If IsEmpty(.FunctionAccess) Or IsNull(.FunctionAccess) Then
397 Set .FunctionAccess = CreateUnoService(&quot;com.sun.star.sheet.FunctionAccess&quot;)
398 End If
399 Set _GetUNOService = .FunctionAccess
400 Case &quot;GraphicExportFilter&quot;
401 If IsEmpty(.GraphicExportFilter) Or IsNull(.GraphicExportFilter) Then
402 Set .GraphicExportFilter = CreateUnoService(&quot;com.sun.star.drawing.GraphicExportFilter&quot;)
403 End If
404 Set _GetUNOService = .GraphicExportFilter
405 Case &quot;Introspection&quot;
406 If IsEmpty(.Introspection) Or IsNull(.Introspection) Then
407 Set .Introspection = CreateUnoService(&quot;com.sun.star.beans.Introspection&quot;)
408 End If
409 Set _GetUNOService = .Introspection
410 Case &quot;LocaleData&quot;
411 If IsEmpty(.LocaleData) Or IsNull(.LocaleData) Then
412 Set .LocaleData = CreateUnoService(&quot;com.sun.star.i18n.LocaleData&quot;)
413 End If
414 Set _GetUNOService = .LocaleData
415 Case &quot;MacroExpander&quot;
416 Set oDefaultContext = GetDefaultContext()
417 If Not IsNull(oDefaultContext) Then Set _GetUNOService = oDefaultContext.getValueByName(&quot;/singletons/com.sun.star.util.theMacroExpander&quot;)
418 Case &quot;MailService&quot;
419 If IsEmpty(.MailService) Or IsNull(.MailService) Then
420 If GetGuiType = 1 Then &apos; Windows
421 Set .MailService = CreateUnoService(&quot;com.sun.star.system.SimpleSystemMail&quot;)
422 Else
423 Set .MailService = CreateUnoService(&quot;com.sun.star.system.SimpleCommandMail&quot;)
424 End If
425 End If
426 Set _GetUNOService = .MailService
427 Case &quot;Number2Text&quot;
428 If IsEmpty(.Number2Text) Or IsNull(.Number2Text) Then
429 Set .Number2Text = CreateUnoService(&quot;com.sun.star.linguistic2.NumberText&quot;)
430 End If
431 Set _GetUNOService = .Number2Text
432 Case &quot;OfficeLocale&quot;
433 If IsEmpty(.OfficeLocale) Or IsNull(.OfficeLocale) Then
434 .OfficeLocale = CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
435 &apos; 1st and 2nd chance
436 sLocale = SF_Utils._GetSetting(&quot;org.openoffice.Setup/L10N&quot;, &quot;ooLocale&quot;)
437 If Len(sLocale) = 0 Then sLocale = SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, &quot;UILocale&quot;)
438 .OfficeLocale.Language = Split(sLocale, &quot;-&quot;)(0) &apos; Language is most often 2 chars long, but not always
439 .OfficeLocale.Country = Right(sLocale, 2)
440 End If
441 Set _GetUNOService = .OfficeLocale
442 Case &quot;PackageInformationProvider&quot;
443 If IsEmpty(.PackageProvider) Or IsNull(.PackageProvider) Then
444 Set .PackageProvider = GetDefaultContext.getByName(&quot;/singletons/com.sun.star.deployment.PackageInformationProvider&quot;)
445 End If
446 Set _GetUNOService = .PackageProvider
447 Case &quot;PathSettings&quot;
448 If IsEmpty(.PathSettings) Or IsNull(.PathSettings) Then
449 Set .PathSettings = CreateUnoService(&quot;com.sun.star.util.PathSettings&quot;)
450 End If
451 Set _GetUNOService = .PathSettings
452 Case &quot;PathSubstitution&quot;
453 If IsEmpty(.PathSubstitution) Or IsNull(.PathSubstitution) Then
454 Set .PathSubstitution = CreateUnoService(&quot;com.sun.star.util.PathSubstitution&quot;)
455 End If
456 Set _GetUNOService = .PathSubstitution
457 Case &quot;PrinterServer&quot;
458 If IsEmpty(.PrinterServer) Or IsNull(.PrinterServer) Then
459 Set .PrinterServer = CreateUnoService(&quot;com.sun.star.awt.PrinterServer&quot;)
460 End If
461 Set _GetUNOService = .PrinterServer
462 Case &quot;ScriptProvider&quot;
463 If IsMissing(pvArg) Then pvArg = SF_Session.SCRIPTISAPPLICATION
464 Select Case LCase(pvArg)
465 Case SF_Session.SCRIPTISEMBEDDED &apos; Document
466 If Not IsNull(ThisComponent) Then Set _GetUNOService = ThisComponent.getScriptProvider()
467 Case Else
468 If IsEmpty(.ScriptProvider) Or IsNull(.ScriptProvider) Then
469 Set .ScriptProvider = _
470 CreateUnoService(&quot;com.sun.star.script.provider.MasterScriptProviderFactory&quot;).createScriptProvider(&quot;&quot;)
471 End If
472 Set _GetUNOService = .ScriptProvider
473 End Select
474 Case &quot;SearchOptions&quot;
475 If IsEmpty(.SearchOptions) Or IsNull(.SearchOptions) Then
476 Set .SearchOptions = New com.sun.star.util.SearchOptions
477 With .SearchOptions
478 .algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
479 .searchFlag = 0
480 End With
481 End If
482 Set _GetUNOService = .SearchOptions
483 Case &quot;SystemLocale&quot;, &quot;Locale&quot;
484 If IsEmpty(.SystemLocale) Or IsNull(.SystemLocale) Then
485 .SystemLocale = CreateUnoStruct(&quot;com.sun.star.lang.Locale&quot;)
486 sLocale = SF_Utils._GetSetting(&quot;org.openoffice.System/L10N&quot;, &quot;SystemLocale&quot;)
487 .SystemLocale.Language = Split(sLocale, &quot;-&quot;)(0) &apos; Language is most often 2 chars long, but not always
488 .SystemLocale.Country = Right(sLocale, 2)
489 End If
490 Set _GetUNOService = .SystemLocale
491 Case &quot;SystemShellExecute&quot;
492 If IsEmpty(.SystemShellExecute) Or IsNull(.SystemShellExecute) Then
493 Set .SystemShellExecute = CreateUnoService(&quot;com.sun.star.system.SystemShellExecute&quot;)
494 End If
495 Set _GetUNOService = .SystemShellExecute
496 Case &quot;TextSearch&quot;
497 If IsEmpty(.TextSearch) Or IsNull(.TextSearch) Then
498 Set .TextSearch = CreateUnoService(&quot;com.sun.star.util.TextSearch&quot;)
499 End If
500 Set _GetUNOService = .TextSearch
501 Case &quot;Toolkit&quot;
502 If IsEmpty(.Toolkit) Or IsNull(.Toolkit) Then
503 Set .Toolkit = CreateUnoService(&quot;com.sun.star.awt.Toolkit&quot;)
504 End If
505 Set _GetUNOService = .Toolkit
506 Case &quot;URLTransformer&quot;
507 If IsEmpty(.URLTransformer) Or IsNull(.URLTransformer) Then
508 Set .URLTransformer = CreateUnoService(&quot;com.sun.star.util.URLTransformer&quot;)
509 End If
510 Set _GetUNOService = .URLTransformer
511 Case Else
512 End Select
513 End With
515 End Function &apos; ScriptForge.SF_Utils._GetUNOService
517 REM -----------------------------------------------------------------------------
518 Public Sub _InitializeRoot(Optional ByVal pbForce As Boolean)
519 &apos;&apos;&apos; Initialize _SF_ as SF_Root basic object
520 &apos;&apos;&apos; Args:
521 &apos;&apos;&apos; pbForce = True forces the reinit (default = False)
523 If IsMissing(pbForce) Then pbForce = False
524 If pbForce Then Set _SF_ = Nothing
525 If IsEmpty(_SF_) Or IsNull(_SF_) Then
526 Set _SF_ = New SF_Root
527 Set _SF_.[Me] = _SF_
528 End If
530 End Sub &apos; ScriptForge.SF_Utils._InitializeRoot
532 REM -----------------------------------------------------------------------------
533 Public Function _MakePropertyValue(ByVal psName As String _
534 , ByRef pvValue As Variant _
535 ) As com.sun.star.beans.PropertyValue
536 &apos;&apos;&apos; Create and return a new com.sun.star.beans.PropertyValue
538 Dim oPropertyValue As New com.sun.star.beans.PropertyValue
540 With oPropertyValue
541 .Name = psName
542 .Value = SF_Utils._CPropertyValue(pvValue)
543 End With
544 _MakePropertyValue() = oPropertyValue
546 End Function &apos; ScriptForge.SF_Utils._MakePropertyValue
548 REM -----------------------------------------------------------------------------
549 Public Function _Repr(ByVal pvArg As Variant, Optional ByVal plMax As Long) As String
550 &apos;&apos;&apos; Convert pvArg into a readable string (truncated if length &gt; plMax)
551 &apos;&apos;&apos; Args
552 &apos;&apos;&apos; pvArg: may be of any type
553 &apos;&apos;&apos; plMax: maximum length of the resulting string (default = 32K)
555 Dim sArg As String &apos; Return value
556 Dim oObject As Object &apos; Alias of argument to avoid &quot;Object variable not set&quot;
557 Dim oObjectDesc As Object &apos; Object descriptor
558 Dim sLength As String &apos; String length as a string
559 Dim i As Long
560 Const cstBasicObject = &quot;com.sun.star.script.NativeObjectWrapper&quot;
562 Const cstMaxLength = 2^15 - 1 &apos; 32767
563 Const cstByteLength = 25
564 Const cstEtc = &quot; … &quot;
566 If IsMissing(plMax) Then plMax = cstMaxLength
567 If plMax = 0 Then plMax = cstMaxLength
568 If IsArray(pvArg) Then
569 sArg = SF_Array._Repr(pvArg)
570 Else
571 Select Case VarType(pvArg)
572 Case V_EMPTY : sArg = &quot;[EMPTY]&quot;
573 Case V_NULL : sArg = &quot;[NULL]&quot;
574 Case V_OBJECT
575 Set oObjectDesc = SF_Utils._VarTypeObj(pvArg)
576 With oObjectDesc
577 Select Case .iVarType
578 Case V_NOTHING : sArg = &quot;[NOTHING]&quot;
579 Case V_OBJECT, V_BASICOBJECT
580 sArg = &quot;[OBJECT]&quot;
581 Case V_UNOOBJECT : sArg = &quot;[&quot; &amp; .sObjectType &amp; &quot;]&quot;
582 Case V_SFOBJECT
583 If Left(.sObjectType, 3) = &quot;SF_&quot; Then &apos; Standard module
584 sArg = &quot;[&quot; &amp; .sObjectType &amp; &quot;]&quot;
585 Else &apos; Class module must have a _Repr() method
586 Set oObject = pvArg
587 sArg = oObject._Repr()
588 End If
589 End Select
590 End With
591 Case V_VARIANT : sArg = &quot;[VARIANT]&quot;
592 Case V_STRING
593 sArg = SF_String._Repr(pvArg)
594 Case V_BOOLEAN : sArg = Iif(pvArg, &quot;[TRUE]&quot;, &quot;[FALSE]&quot;)
595 Case V_BYTE : sArg = Right(&quot;00&quot; &amp; Hex(pvArg), 2)
596 Case V_SINGLE, V_DOUBLE, V_CURRENCY
597 sArg = Format(pvArg)
598 If InStr(1, sArg, &quot;E&quot;, 1) = 0 Then sArg = Format(pvArg, &quot;##0.0##&quot;)
599 sArg = Replace(sArg, &quot;,&quot;, &quot;.&quot;) &apos;Force decimal point
600 Case V_BIGINT : sArg = CStr(CLng(pvArg))
601 Case V_DATE : sArg = _CDateToIso(pvArg)
602 Case Else : sArg = CStr(pvArg)
603 End Select
604 End If
605 If Len(sArg) &gt; plMax Then
606 sLength = &quot;(&quot; &amp; Len(sArg) &amp; &quot;)&quot;
607 sArg = Left(sArg, plMax - Len(cstEtc) - Len(slength)) &amp; cstEtc &amp; sLength
608 End If
609 _Repr = sArg
611 End Function &apos; ScriptForge.SF_Utils._Repr
613 REM -----------------------------------------------------------------------------
614 Private Function _ReprValues(Optional ByVal pvArgs As Variant _
615 , Optional ByVal plMax As Long _
616 ) As String
617 &apos;&apos;&apos; Convert an array of values to a comma-separated list of readable strings
619 Dim sValues As String &apos; Return value
620 Dim sValue As String &apos; A single value
621 Dim vValue As Variant &apos; A single item in the argument
622 Dim i As Long &apos; Items counter
623 Const cstMax = 20 &apos; Maximum length of single string
624 Const cstContinue = &quot;…&quot; &apos; Unicode continuation char U+2026
626 _ReprValues = &quot;&quot;
627 If IsMissing(pvArgs) Then Exit Function
628 If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
629 sValues = &quot;&quot;
630 For i = 0 To UBound(pvArgs)
631 vValue = pvArgs(i)
632 If i &lt; plMax Then
633 If VarType(vValue) = V_STRING Then sValue = &quot;&quot;&quot;&quot; &amp; vValue &amp; &quot;&quot;&quot;&quot; Else sValue = SF_Utils._Repr(vValue, cstMax)
634 If Len(sValues) = 0 Then sValues = sValue Else sValues = sValues &amp; &quot;, &quot; &amp; sValue
635 ElseIf i &lt; UBound(pvArgs) Then
636 sValues = sValues &amp; &quot;, &quot; &amp; cstContinue
637 Exit For
638 End If
639 Next i
640 _ReprValues = sValues
642 End Function &apos; ScriptForge.SF_Utils._ReprValues
644 REM -----------------------------------------------------------------------------
645 Public Function _SetPropertyValue(ByVal pvPropertyValue As Variant _
646 , ByVal psName As String _
647 , ByRef pvValue As Variant _
648 ) As Variant
649 &apos;&apos;&apos; Return the 1st argument (passed by reference), which is an array of property values
650 &apos;&apos;&apos; If the property psName exists, update it with pvValue, otherwise create it on top of the returned array
652 Dim oPropertyValue As New com.sun.star.beans.PropertyValue
653 Dim lIndex As Long &apos; Found entry
654 Dim vValue As Variant &apos; Alias of pvValue
655 Dim vProperties As Variant &apos; Alias of pvPropertyValue
656 Dim i As Long
658 lIndex = -1
659 vProperties = pvPropertyValue
660 For i = 0 To UBound(vProperties)
661 If vProperties(i).Name = psName Then
662 lIndex = i
663 Exit For
664 End If
665 Next i
666 If lIndex &lt; 0 Then &apos; Not found
667 lIndex = UBound(vProperties) + 1
668 ReDim Preserve vProperties(0 To lIndex)
669 Set oPropertyValue = SF_Utils._MakePropertyValue(psName, pvValue)
670 vProperties(lIndex) = oPropertyValue
671 vProperties = vProperties
672 Else &apos; psName exists already in array of property values
673 vProperties(lIndex).Value = SF_Utils._CPropertyValue(pvValue)
674 End If
676 _SetPropertyValue = vProperties
678 End Function &apos; ScriptForge.SF_Utils._SetPropertyValue
680 REM -----------------------------------------------------------------------------
681 Private Function _TypeNames(Optional ByVal pvArgs As Variant) As String
682 &apos;&apos;&apos; Converts the array of VarTypes to a comma-separated list of TypeNames
684 Dim sTypes As String &apos; Return value
685 Dim sType As String &apos; A single type
686 Dim iType As Integer &apos; A single item of the argument
688 _TypeNames = &quot;&quot;
689 If IsMissing(pvArgs) Then Exit Function
690 If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs)
691 sTypes = &quot;&quot;
692 For Each iType In pvArgs
693 Select Case iType
694 Case V_EMPTY : sType = &quot;Empty&quot;
695 Case V_NULL : sType = &quot;Null&quot;
696 Case V_INTEGER : sType = &quot;Integer&quot;
697 Case V_LONG : sType = &quot;Long&quot;
698 Case V_SINGLE : sType = &quot;Single&quot;
699 Case V_DOUBLE : sType = &quot;Double&quot;
700 Case V_CURRENCY : sType = &quot;Currency&quot;
701 Case V_DATE : sType = &quot;Date&quot;
702 Case V_STRING : sType = &quot;String&quot;
703 Case V_OBJECT : sType = &quot;Object&quot;
704 Case V_BOOLEAN : sType = &quot;Boolean&quot;
705 Case V_VARIANT : sType = &quot;Variant&quot;
706 Case V_DECIMAL : sType = &quot;Decimal&quot;
707 Case &gt;= V_ARRAY : sType = &quot;Array&quot;
708 Case V_NUMERIC : sType = &quot;Numeric&quot;
709 End Select
710 If Len(sTypes) = 0 Then sTypes = sType Else sTypes = sTypes &amp; &quot;, &quot; &amp; sType
711 Next iType
712 _TypeNames = sTypes
714 End Function &apos; ScriptForge.SF_Utils._TypeNames
716 REM -----------------------------------------------------------------------------
717 Public Function _Validate(Optional ByRef pvArgument As Variant _
718 , ByVal psName As String _
719 , Optional ByVal pvTypes As Variant _
720 , Optional ByVal pvValues As Variant _
721 , Optional ByVal pvRegex As Variant _
722 , Optional ByVal pvObjectType As Variant _
723 ) As Boolean
724 &apos;&apos;&apos; Validate the arguments set by user scripts
725 &apos;&apos;&apos; The arguments of the function define the validation rules
726 &apos;&apos;&apos; This function ignores arrays. Use _ValidateArray instead
727 &apos;&apos;&apos; Args:
728 &apos;&apos;&apos; pvArgument: the argument to (in)validate
729 &apos;&apos;&apos; psName: the documented name of the argument (can be inserted in an error message)
730 &apos;&apos;&apos; pvTypes: array of allowed VarTypes
731 &apos;&apos;&apos; pvValues: array of allowed values
732 &apos;&apos;&apos; pvRegex: regular expression to comply with
733 &apos;&apos;&apos; pvObjectType: mandatory Basic class
734 &apos;&apos;&apos; Return: True if validation OK
735 &apos;&apos;&apos; Otherwise an error is raised
736 &apos;&apos;&apos; Exceptions:
737 &apos;&apos;&apos; ARGUMENTERROR
739 Dim iVarType As Integer &apos; Extended VarType of argument
740 Dim bValid As Boolean &apos; Returned value
741 Dim oObjectDescriptor As Object &apos; _ObjectDescriptor type
742 Const cstMaxLength = 256 &apos; Maximum length of readable value
743 Const cstMaxValues = 10 &apos; Maximum number of allowed items to list in an error message
745 &apos; To avoid useless recursions, keep main function, only increase stack depth
746 _SF_.StackLevel = _SF_.StackLevel + 1
747 On Local Error GoTo Finally &apos; Do never interrupt
749 Try:
750 bValid = True
751 If IsMissing(pvArgument) Then GoTo CatchMissing
752 If IsMissing(pvRegex) Or IsEmpty(pvRegex) Then pvRegex = &quot;&quot;
753 If IsMissing(pvObjectType) Or IsEmpty(pvObjectType) Then pvObjectType = &quot;&quot;
754 iVarType = SF_Utils._VarTypeExt(pvArgument)
756 &apos; Arrays NEVER pass validation
757 If iVarType &gt;= V_ARRAY Then
758 bValid = False
759 Else
760 &apos; Check existence of argument
761 bValid = iVarType &lt;&gt; V_NULL And iVarType &lt;&gt; V_EMPTY
762 &apos; Check if argument&apos;s VarType is valid
763 If bValid And Not IsMissing(pvTypes) Then
764 If Not IsArray(pvTypes) Then bValid = ( pvTypes = iVarType ) Else bValid = SF_Array.Contains(pvTypes, iVarType)
765 End If
766 &apos; Check if argument&apos;s value is valid
767 If bValid And Not IsMissing(pvValues) Then
768 If Not IsArray(pvValues) Then pvValues = Array(pvValues)
769 bValid = SF_Array.Contains(pvValues, pvArgument, CaseSensitive := False)
770 End If
771 &apos; Check regular expression
772 If bValid And Len(pvRegex) &gt; 0 And iVarType = V_STRING Then
773 If Len(pvArgument) &gt; 0 Then bValid = SF_String.IsRegex(pvArgument, pvRegex, CaseSensitive := False)
774 End If
775 &apos; Check instance types
776 If bValid And Len(pvObjectType) &gt; 0 And iVarType = V_OBJECT Then
777 &apos;Set oArgument = pvArgument
778 Set oObjectDescriptor = SF_Utils._VarTypeObj(pvArgument)
779 bValid = ( oObjectDescriptor.iVarType = V_SFOBJECT )
780 If bValid Then bValid = ( oObjectDescriptor.sObjectType = pvObjectType )
781 End If
782 End If
784 If Not bValid Then
785 &apos;&apos;&apos; Library: ScriptForge
786 &apos;&apos;&apos; Service: Array
787 &apos;&apos;&apos; Method: Contains
788 &apos;&apos;&apos; Arguments: Array_1D, ToFind, [CaseSensitive=False], [SortOrder=&quot;&quot;]
789 &apos;&apos;&apos; A serious error has been detected on argument SortOrder
790 &apos;&apos;&apos; Rules: SortOrder is of type String
791 &apos;&apos;&apos; SortOrder must contain one of next values: &quot;ASC&quot;, &quot;DESC&quot;, &quot;&quot;
792 &apos;&apos;&apos; Actual value: &quot;Ascending&quot;
793 SF_Exception.RaiseFatal(ARGUMENTERROR _
794 , SF_Utils._Repr(pvArgument, cstMaxLength), psName, SF_Utils._TypeNames(pvTypes) _
795 , SF_Utils._ReprValues(pvValues, cstMaxValues), pvRegex, pvObjectType _
797 End If
799 Finally:
800 _Validate = bValid
801 _SF_.StackLevel = _SF_.StackLevel - 1
802 Exit Function
803 CatchMissing:
804 bValid = False
805 SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
806 GoTo Finally
807 End Function &apos; ScriptForge.SF_Utils._Validate
809 REM -----------------------------------------------------------------------------
810 Public Function _ValidateArray(Optional ByRef pvArray As Variant _
811 , ByVal psName As String _
812 , Optional ByVal piDimensions As Integer _
813 , Optional ByVal piType As Integer _
814 , Optional ByVal pbNotNull As Boolean _
815 ) As Boolean
816 &apos;&apos;&apos; Validate the (array) arguments set by user scripts
817 &apos;&apos;&apos; The arguments of the function define the validation rules
818 &apos;&apos;&apos; This function ignores non-arrays. Use _Validate instead
819 &apos;&apos;&apos; Args:
820 &apos;&apos;&apos; pvArray: the argument to (in)validate
821 &apos;&apos;&apos; psName: the documented name of the array (can be inserted in an error message)
822 &apos;&apos;&apos; piDimensions: the # of dimensions the array must have. 0 = Any (default)
823 &apos;&apos;&apos; piType: (default = -1, i.e. not applicable)
824 &apos;&apos;&apos; For 2D arrays, the 1st column is checked
825 &apos;&apos;&apos; 0 =&gt; all items must be any out of next types: string, date or numeric,
826 &apos;&apos;&apos; but homogeneously: all strings or all dates or all numeric
827 &apos;&apos;&apos; V_STRING or V_DATE or V_NUMERIC =&gt; that specific type is required
828 &apos;&apos;&apos; pbNotNull: piType must be &gt;=0, otherwise ignored
829 &apos;&apos;&apos; If True: Empty, Null items are rejected
830 &apos;&apos;&apos; Return: True if validation OK
831 &apos;&apos;&apos; Otherwise an error is raised
832 &apos;&apos;&apos; Exceptions:
833 &apos;&apos;&apos; ARRAYERROR
835 Dim iVarType As Integer &apos; VarType of argument
836 Dim vItem As Variant &apos; Array item
837 Dim iItemType As Integer &apos; VarType of individual items of argument
838 Dim iDims As Integer &apos; Number of dimensions of the argument
839 Dim bValid As Boolean &apos; Returned value
840 Dim iArrayType As Integer &apos; Static array type
841 Dim iFirstItemType As Integer &apos; Type of 1st non-null/empty item
842 Dim sType As String &apos; Allowed item types as a string
843 Dim i As Long
844 Const cstMaxLength = 256 &apos; Maximum length of readable value
846 &apos; To avoid useless recursions, keep main function, only increase stack depth
848 _SF_.StackLevel = _SF_.StackLevel + 1
849 On Local Error GoTo Finally &apos; Do never interrupt
851 Try:
852 bValid = True
853 If IsMissing(pvArray) Then GoTo CatchMissing
854 If IsMissing(piDimensions) Then piDimensions = 0
855 If IsMissing(piType) Then piType = -1
856 If IsMissing(pbNotNull) Then pbNotNull = False
857 iVarType = VarType(pvArray)
859 &apos; Scalars NEVER pass validation
860 If iVarType &lt; V_ARRAY Then
861 bValid = False
862 Else
863 &apos; Check dimensions
864 iDims = SF_Array.CountDims(pvArray)
865 If iDims &gt; 2 Then bValid = False &apos; Only 1D and 2D arrays
866 If bValid And piDimensions &gt; 0 Then
867 bValid = ( iDims = piDimensions Or (iDims = 0 And piDimensions = 1) ) &apos; Allow empty vectors
868 End If
869 &apos; Check VarType and Empty/Null status of the array items
870 If bValid And iDims = 1 And piType &gt;= 0 Then
871 iArrayType = SF_Array._StaticType(pvArray)
872 If (piType = 0 And iArrayType &gt; 0) Or (piType &gt; 0 And iArrayType = piType) Then
873 &apos; If static array of the right VarType ..., OK
874 Else
875 &apos; Go through array and check individual items
876 iFirstItemType = -1
877 For i = LBound(pvArray, 1) To UBound(pvArray, 1)
878 If iDims = 1 Then vItem = pvArray(i) Else vItem = pvArray(i, LBound(pvArray, 2))
879 iItemType = SF_Utils._VarTypeExt(vItem)
880 If iItemType &gt; V_NULL Then &apos; Exclude Empty and Null
881 &apos; Initialization at first non-null item
882 If iFirstItemType &lt; 0 Then
883 iFirstItemType = iItemType
884 If piType &gt; 0 Then bValid = ( iFirstItemType = piType ) Else bValid = SF_Array.Contains(Array(V_STRING, V_DATE, V_NUMERIC), iFirstItemType)
885 Else
886 bValid = (iItemType = iFirstItemType)
887 End If
888 Else
889 bValid = Not pbNotNull
890 End If
891 If Not bValid Then Exit For
892 Next i
893 End If
894 End If
895 End If
897 If Not bValid Then
898 &apos;&apos;&apos; Library: ScriptForge
899 &apos;&apos;&apos; Service: Array
900 &apos;&apos;&apos; Method: Contains
901 &apos;&apos;&apos; Arguments: Array_1D, ToFind, [CaseSensitive=False], [SortOrder=&quot;&quot;|&quot;ASC&quot;|&quot;DESC&quot;]
902 &apos;&apos;&apos; An error was detected on argument Array_1D
903 &apos;&apos;&apos; Rules: Array_1D is of type Array
904 &apos;&apos;&apos; Array_1D must have maximum 1 dimension
905 &apos;&apos;&apos; Array_1D must have all elements of the same type: either String, Date or Numeric
906 &apos;&apos;&apos; Actual value: (0:2, 0:3)
907 sType = &quot;&quot;
908 If piType = 0 Then
909 sType = &quot;String, Date, Numeric&quot;
910 ElseIf piType &gt; 0 Then
911 sType = SF_Utils._TypeNames(piType)
912 End If
913 SF_Exception.RaiseFatal(ARRAYERROR _
914 , SF_Utils._Repr(pvArray, cstMaxLength), psName, piDimensions, sType, pbNotNull)
915 End If
917 Finally:
918 _ValidateArray = bValid
919 _SF_.StackLevel = _SF_.StackLevel - 1
920 Exit Function
921 CatchMissing:
922 bValid = False
923 SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
924 GoTo Finally
925 End Function &apos; ScriptForge.SF_Utils._ValidateArray
927 REM -----------------------------------------------------------------------------
928 Public Function _ValidateFile(Optional ByRef pvArgument As Variant _
929 , ByVal psName As String _
930 , Optional ByVal pbWildCards As Boolean _
931 , Optional ByVal pbSpace As Boolean _
933 &apos;&apos;&apos; Validate the argument as a valid FileName
934 &apos;&apos;&apos; Args:
935 &apos;&apos;&apos; pvArgument: the argument to (in)validate
936 &apos;&apos;&apos; pbWildCards: if True, wildcard characters are accepted in the last component of the 1st argument
937 &apos;&apos;&apos; pbSpace: if True, the argument may be an empty string. Default = False
938 &apos;&apos;&apos; Return: True if validation OK
939 &apos;&apos;&apos; Otherwise an error is raised
940 &apos;&apos;&apos; Exceptions:
941 &apos;&apos;&apos; ARGUMENTERROR
943 Dim iVarType As Integer &apos; VarType of argument
944 Dim sFile As String &apos; Alias for argument
945 Dim bValid As Boolean &apos; Returned value
946 Dim sFileNaming As String &apos; Alias of SF_FileSystem.FileNaming
947 Dim oArgument As Variant &apos; Workaround &quot;Object variable not set&quot; error on 1st executable statement
948 Const cstMaxLength = 256 &apos; Maximum length of readable value
950 &apos; To avoid useless recursions, keep main function, only increase stack depth
952 _SF_.StackLevel = _SF_.StackLevel + 1
953 On Local Error GoTo Finally &apos; Do never interrupt
955 Try:
956 bValid = True
957 If IsMissing(pvArgument) Then GoTo CatchMissing
958 If IsMissing(pbWildCards) Then pbWildCards = False
959 If IsMissing(pbSpace) Then pbSpace = False
960 iVarType = VarType(pvArgument)
962 &apos; Arrays NEVER pass validation
963 If iVarType &gt;= V_ARRAY Then
964 bValid = False
965 Else
966 &apos; Argument must be a string containing a valid file name
967 bValid = ( iVarType = V_STRING )
968 If bValid Then
969 bValid = ( Len(pvArgument) &gt; 0 Or pbSpace )
970 If bValid And Len(pvArgument) &gt; 0 Then
971 &apos; Wildcards are replaced by arbitrary alpha characters
972 If pbWildCards Then
973 sFile = Replace(Replace(pvArgument, &quot;?&quot;, &quot;Z&quot;), &quot;*&quot;, &quot;A&quot;)
974 Else
975 sFile = pvArgument
976 bValid = ( InStr(sFile, &quot;?&quot;) + InStr(sFile, &quot;*&quot;) = 0 )
977 End If
978 &apos; Check file format without wildcards
979 If bValid Then
980 With SF_FileSystem
981 sFileNaming = .FileNaming
982 Select Case sFileNaming
983 Case &quot;ANY&quot; : bValid = SF_String.IsUrl(ConvertToUrl(sFile))
984 Case &quot;URL&quot; : bValid = SF_String.IsUrl(sFile)
985 Case &quot;SYS&quot; : bValid = SF_String.IsFileName(sFile)
986 End Select
987 End With
988 End If
989 &apos; Check that wildcards are only present in last component
990 If bValid And pbWildCards Then
991 sFile = SF_FileSystem.GetParentFolderName(pvArgument)
992 bValid = ( InStr(sFile, &quot;*&quot;) + InStr(sFile, &quot;?&quot;) + InStr(sFile,&quot;%3F&quot;) = 0 ) &apos; ConvertToUrl replaces ? by %3F
993 End If
994 End If
995 End If
996 End If
998 If Not bValid Then
999 &apos;&apos;&apos; Library: ScriptForge
1000 &apos;&apos;&apos; Service: FileSystem
1001 &apos;&apos;&apos; Method: CopyFile
1002 &apos;&apos;&apos; Arguments: Source, Destination
1003 &apos;&apos;&apos; A serious error has been detected on argument Source
1004 &apos;&apos;&apos; Rules: Source is of type String
1005 &apos;&apos;&apos; Source must be a valid file name expressed in operating system notation
1006 &apos;&apos;&apos; Source may contain one or more wildcard characters in its last component
1007 &apos;&apos;&apos; Actual value: /home/jean-*/SomeFile.odt
1008 SF_Exception.RaiseFatal(FILEERROR _
1009 , SF_Utils._Repr(pvArgument, cstMaxLength), psName, pbWildCards)
1010 End If
1012 Finally:
1013 _ValidateFile = bValid
1014 _SF_.StackLevel = _SF_.StackLevel - 1
1015 Exit Function
1016 CatchMissing:
1017 bValid = False
1018 SF_Exception.RaiseFatal(MISSINGARGERROR, psName)
1019 GoTo Finally
1020 End Function &apos; ScriptForge.SF_Utils._ValidateFile
1022 REM -----------------------------------------------------------------------------
1023 Public Function _VarTypeExt(ByRef pvValue As Variant) As Integer
1024 &apos;&apos;&apos; Return the VarType of the argument but all numeric types are aggregated into V_NUMERIC
1025 &apos;&apos;&apos; Args:
1026 &apos;&apos;&apos; pvValue: value to examine
1027 &apos;&apos;&apos; Return:
1028 &apos;&apos;&apos; The extended VarType
1030 Dim iType As Integer &apos; VarType of argument
1032 iType = VarType(pvValue)
1033 Select Case iType
1034 Case V_INTEGER, V_LONG, V_SINGLE, V_DOUBLE, V_CURRENCY, V_BIGINT, V_DECIMAL
1035 _VarTypeExt = V_NUMERIC
1036 Case Else : _VarTypeExt = iType
1037 End Select
1039 End Function &apos; ScriptForge.SF_Utils._VarTypeExt
1041 REM -----------------------------------------------------------------------------
1042 Public Function _VarTypeObj(ByRef pvValue As Variant) As Object
1043 &apos;&apos;&apos; Inspect the argument that is supposed to be an Object
1044 &apos;&apos;&apos; Return the internal type of object as one of the values
1045 &apos;&apos;&apos; V_NOTHING Null object
1046 &apos;&apos;&apos; V_UNOOBJECT Uno object or Uno structure
1047 &apos;&apos;&apos; V_SFOBJECT ScriptForge object: has ObjectType and ServiceName properties
1048 &apos;&apos;&apos; V_BASICOBJECT User Basic object
1049 &apos;&apos;&apos; coupled with object type as a string (&quot;com.sun.star...&quot; or &quot;SF_...&quot; or &quot;... ScriptForge class ...&quot;)
1050 &apos;&apos;&apos; When the argument is not an Object, return the usual VarType() of the argument
1052 Dim oObjDesc As _ObjectDescriptor &apos; Return value
1053 Dim oValue As Object &apos; Alias of pvValue used to avoid &quot;Object variable not set&quot; error
1054 Dim sObjType As String &apos; The type of object is first derived as a string
1055 Dim oReflection As Object &apos; com.sun.star.reflection.CoreReflection
1056 Dim vClass As Variant &apos; com.sun.star.reflection.XIdlClass
1057 Dim bUno As Boolean &apos; True when object recognized as UNO object
1059 Const cstBasicClass = &quot;com.sun.star.script.NativeObjectWrapper&quot; &apos; Way to recognize Basic objects
1061 On Local Error Resume Next &apos; Object type is established by trial and error
1063 Try:
1064 With oObjDesc
1065 .iVarType = VarType(pvValue)
1066 .sObjectType = &quot;&quot;
1067 .sServiceName = &quot;&quot;
1068 bUno = False
1069 If .iVarType = V_OBJECT Then
1070 If IsNull(pvValue) Then
1071 .iVarType = V_NOTHING
1072 Else
1073 Set oValue = pvValue
1074 &apos; Try UNO type with usual ImplementationName property
1075 .sObjectType = oValue.getImplementationName()
1076 If .sObjectType = &quot;&quot; Then
1077 &apos; Try UNO type with alternative CoreReflection trick
1078 Set oReflection = SF_Utils._GetUNOService(&quot;CoreReflection&quot;)
1079 vClass = oReflection.getType(oValue)
1080 If vClass.TypeClass &gt;= com.sun.star.uno.TypeClass.STRUCT Then
1081 .sObjectType = vClass.Name
1082 bUno = True
1083 End If
1084 Else
1085 bUno = True
1086 End If
1087 &apos; Identify Basic objects
1088 If .sObjectType = cstBasicClass Then
1089 bUno = False
1090 &apos; Try if the Basic object has an ObjectType property
1091 .sObjectType = oValue.ObjectType
1092 .sServiceName = oValue.ServiceName
1093 End If
1094 &apos; Derive the return value from the object type
1095 Select Case True
1096 Case Len(.sObjectType) = 0 &apos; Do nothing (return V_OBJECT)
1097 Case .sObjectType = cstBasicClass : .iVarType = V_BASICOBJECT
1098 Case bUno : .iVarType = V_UNOOBJECT
1099 Case Else : .iVarType = V_SFOBJECT
1100 End Select
1101 End If
1102 End If
1103 End With
1105 Finally:
1106 Set _VarTypeObj = oObjDesc
1107 Exit Function
1108 End Function &apos; ScriptForge.SF_Utils._VarTypeObj
1110 REM ================================================= END OF SCRIPTFORGE.SF_UTILS
1111 </script:module>