tdf#150880: Add support for WRAPROWS function
[LibreOffice.git] / wizards / source / sfdocuments / SF_Document.xba
blob0ad019315a5f4012cd4fdf3a93eb4d10aa090013
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_Document" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === The SFDocuments library is one of the associated libraries. ===
6 REM === Full documentation is available on https://help.libreoffice.org/ ===
7 REM =======================================================================================================================
9 Option Compatible
10 Option ClassModule
12 Option Explicit
14 &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;
15 &apos;&apos;&apos; SF_Document
16 &apos;&apos;&apos; ===========
17 &apos;&apos;&apos;
18 &apos;&apos;&apos; The SFDocuments library gathers a number of methods and properties making easy
19 &apos;&apos;&apos; managing and manipulating LibreOffice documents
20 &apos;&apos;&apos;
21 &apos;&apos;&apos; Some methods are generic for all types of documents: they are combined in the
22 &apos;&apos;&apos; current SF_Document module
23 &apos;&apos;&apos; - saving, closing documents
24 &apos;&apos;&apos; - accessing their standard or custom properties
25 &apos;&apos;&apos; Specific properties and methods are implemented in the concerned subclass(es) SF_Calc, SF_Base, ...
26 &apos;&apos;&apos;
27 &apos;&apos;&apos; Documents might contain forms. The current service gives access to the &quot;SFDocuments.Form&quot; service
28 &apos;&apos;&apos;
29 &apos;&apos;&apos; To workaround the absence of class inheritance in LibreOffice Basic, some redundancy is necessary
30 &apos;&apos;&apos; Each subclass MUST implement also the generic methods and properties, even if they only call
31 &apos;&apos;&apos; the parent methods and properties implemented below
32 &apos;&apos;&apos; They should also duplicate some generic private members as a subset of their own set of members
33 &apos;&apos;&apos;
34 &apos;&apos;&apos; The current module is closely related to the &quot;UI&quot; and &quot;FileSystem&quot; services
35 &apos;&apos;&apos; of the ScriptForge library
36 &apos;&apos;&apos;
37 &apos;&apos;&apos; Service invocation examples:
38 &apos;&apos;&apos; 1) From the UI service
39 &apos;&apos;&apos; Dim ui As Object, oDoc As Object
40 &apos;&apos;&apos; Set ui = CreateScriptService(&quot;UI&quot;)
41 &apos;&apos;&apos; Set oDoc = ui.GetDocument(&quot;Untitled 1&quot;)
42 &apos;&apos;&apos; &apos; or Set oDoc = ui.CreateDocument(&quot;Calc&quot;, ...)
43 &apos;&apos;&apos; &apos; or Set oDoc = ui.OpenDocument(&quot;C:\Me\MyFile.odt&quot;)
44 &apos;&apos;&apos; 2) Directly if the document is already opened
45 &apos;&apos;&apos; Dim oDoc As Object
46 &apos;&apos;&apos; Set oDoc = CreateScriptService(&quot;SFDocuments.Document&quot;, &quot;Untitled 1&quot;) &apos; Default = ActiveWindow
47 &apos;&apos;&apos; &apos; The substring &quot;SFDocuments.&quot; in the service name is optional
48 &apos;&apos;&apos;
49 &apos;&apos;&apos; Detailed user documentation:
50 &apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_document.html?DbPAR=BASIC
51 &apos;&apos;&apos;
52 &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;
54 REM ================================================================== EXCEPTIONS
56 Private Const DOCUMENTDEADERROR = &quot;DOCUMENTDEADERROR&quot;
57 Private Const DOCUMENTSAVEERROR = &quot;DOCUMENTSAVEERROR&quot;
58 Private Const DOCUMENTSAVEASERROR = &quot;DOCUMENTSAVEASERROR&quot;
59 Private Const DOCUMENTREADONLYERROR = &quot;DOCUMENTREADONLYERROR&quot;
61 Private Const FORMDEADERROR = &quot;FORMDEADERROR&quot;
63 Private Const UNKNOWNFILEERROR = &quot;UNKNOWNFILEERROR&quot;
65 REM ============================================================= PRIVATE MEMBERS
67 Private [Me] As Object
68 Private [_Parent] As Object
69 Private [_SubClass] As Object &apos; Subclass instance
70 Private ObjectType As String &apos; Must be DOCUMENT
71 Private ServiceName As String
73 &apos; Window description
74 Private _Component As Object &apos; com.sun.star.lang.XComponent
75 Private _Frame As Object &apos; com.sun.star.comp.framework.Frame
76 Private _WindowName As String &apos; Object Name
77 Private _WindowTitle As String &apos; Only mean to identify new documents
78 Private _WindowFileName As String &apos; URL of file name
79 Private _DocumentType As String &apos; Writer, Calc, ...
80 Private _DocumentSettings As Object &apos; com.sun.star.XXX.DocumentSettings (XXX = sheet, text, drawing or presentation)
82 &apos; Properties (work variables - real properties could have been set manually by user)
83 Private _DocumentProperties As Object &apos; Dictionary of document properties
84 Private _CustomProperties As Object &apos; Dictionary of custom properties
86 &apos; Cache for static toolbar descriptions
87 Private _Toolbars As Object &apos; SF_Dictionary instance to hold toolbars stored in application or in document
89 &apos; List of standard context menus
90 Private _ContextMenus As Variant &apos; Array of ResourceURL strings
92 &apos; Style descriptor
93 Type StyleDescriptor
94 Family As Object
95 StyleName As String
96 DisplayName As String
97 IsUsed As Boolean
98 BuiltIn As Boolean
99 Category As String
100 ParentStyle As String
101 XStyle As Object
102 End Type
104 Private _StyleFamilies As Variant &apos; Array of available style families
106 REM ============================================================ MODULE CONSTANTS
108 Const ISDOCFORM = 1 &apos; Form is stored in a Writer document
110 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
112 REM -----------------------------------------------------------------------------
113 Private Sub Class_Initialize()
114 Set [Me] = Nothing
115 Set [_Parent] = Nothing
116 Set [_SubClass] = Nothing
117 ObjectType = &quot;DOCUMENT&quot;
118 ServiceName = &quot;SFDocuments.Document&quot;
119 Set _Component = Nothing
120 Set _Frame = Nothing
121 _WindowName = &quot;&quot;
122 _WindowTitle = &quot;&quot;
123 _WindowFileName = &quot;&quot;
124 _DocumentType = &quot;&quot;
125 Set _DocumentSettings = Nothing
126 Set _DocumentProperties = Nothing
127 Set _CustomProperties = Nothing
128 Set _Toolbars = Nothing
129 _ContextMenus = Array()
130 _StyleFamilies = Array()
131 End Sub &apos; SFDocuments.SF_Document Constructor
133 REM -----------------------------------------------------------------------------
134 Private Sub Class_Terminate()
135 Call Class_Initialize()
136 End Sub &apos; SFDocuments.SF_Document Destructor
138 REM -----------------------------------------------------------------------------
139 Public Function Dispose() As Variant
140 Call Class_Terminate()
141 Set Dispose = Nothing
142 End Function &apos; SFDocuments.SF_Document Explicit Destructor
144 REM ================================================================== PROPERTIES
146 REM -----------------------------------------------------------------------------
147 Property Get CustomProperties() As Variant
148 &apos;&apos;&apos; Returns a dictionary of all custom properties of the document
149 CustomProperties = _PropertyGet(&quot;CustomProperties&quot;)
150 End Property &apos; SFDocuments.SF_Document.CustomProperties
152 REM -----------------------------------------------------------------------------
153 Property Let CustomProperties(Optional ByVal pvCustomProperties As Variant)
154 &apos;&apos;&apos; Sets the updatable custom properties
155 &apos;&apos;&apos; The argument is a dictionary
157 Dim vPropertyValues As Variant &apos; Array of com.sun.star.beans.PropertyValue
158 Dim vCustomProperties As Variant &apos; Alias of argument
159 Dim oUserdefinedProperties As Object &apos; Custom properties object
160 Dim vOldPropertyValues As Variant &apos; Array of (to remove) existing user defined properties
161 Dim oProperty As Object &apos; Single com.sun.star.beans.PropertyValues
162 Dim sProperty As String &apos; Property name
163 Dim vKeys As Variant &apos; Array of dictionary keys
164 Dim vItems As Variant &apos; Array of dictionary items
165 Dim vValue As Variant &apos; Value to store in property
166 Dim iAttribute As Integer &apos; com.sun.star.beans.PropertyAttribute.REMOVEABLE
167 Dim i As Long
168 Const cstThisSub = &quot;SFDocuments.Document.setCustomProperties&quot;
169 Const cstSubArgs = &quot;CustomProperties&quot;
171 On Local Error GoTo Catch
173 Check:
174 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
175 If Not _IsStillAlive(True) Then GoTo Finally
176 If Not ScriptForge.SF_Utils._Validate(pvCustomProperties, &quot;CustomProperties&quot;, ScriptForge.V_OBJECT, , , &quot;DICTIONARY&quot;) Then GoTo Finally
177 End If
179 Try:
180 Set oUserDefinedProperties = _Component.getDocumentProperties().UserDefinedProperties
182 Set vCustomProperties = pvCustomProperties &apos; To avoid &quot;Object variable not set&quot; error
183 With vCustomProperties
185 &apos; All existing custom properties must first be removed to avoid type conflicts
186 vOldPropertyValues = oUserDefinedProperties.getPropertyValues
187 For Each oProperty In vOldPropertyValues
188 sProperty = oProperty.Name
189 oUserDefinedProperties.removeProperty(sProperty)
190 Next oProperty
192 &apos; Insert new properties one by one after type adjustment (dates, arrays, numbers)
193 vKeys = .Keys
194 vItems = .Items
195 iAttribute = com.sun.star.beans.PropertyAttribute.REMOVEABLE
196 For i = 0 To UBound(vKeys)
197 If VarType(vItems(i)) = V_DATE Then
198 vValue = ScriptForge.SF_Utils._CDateToUnoDate(vItems(i))
199 ElseIf IsArray(vItems(i)) Then
200 vValue = Null
201 ElseIf ScriptForge.SF_Utils._VarTypeExt(vItems(i)) = ScriptForge.V_NUMERIC Then
202 vValue = CreateUnoValue(&quot;double&quot;, vItems(i))
203 Else
204 vValue = vItems(i)
205 End If
206 oUserDefinedProperties.addProperty(vKeys(i), iAttribute, vValue)
207 Next i
209 &apos; Declare the document as changed
210 _Component.setModified(True)
211 End With
213 &apos; Reload custom properties in current object instance
214 _PropertyGet(&quot;CustomProperties&quot;)
216 Finally:
217 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
218 Exit Property
219 Catch:
220 GoTo Finally
221 End Property &apos; SFDocuments.SF_Document.CustomProperties
223 REM -----------------------------------------------------------------------------
224 Property Get Description() As Variant
225 &apos;&apos;&apos; Returns the updatable document property Description
226 Description = _PropertyGet(&quot;Description&quot;)
227 End Property &apos; SFDocuments.SF_Document.Description
229 REM -----------------------------------------------------------------------------
230 Property Let Description(Optional ByVal pvDescription As Variant)
231 &apos;&apos;&apos; Sets the updatable document property Description
232 &apos;&apos;&apos; If multilined, separate lines by &quot;\n&quot; escape sequence or by hard breaks
234 Dim sDescription As String &apos; Alias of pvDescription
235 Const cstThisSub = &quot;SFDocuments.Document.setDescription&quot;
236 Const cstSubArgs = &quot;Description&quot;
238 Check:
239 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
240 If Not _IsStillAlive(True) Then GoTo Finally
241 If Not ScriptForge.SF_Utils._Validate(pvDescription, &quot;Description&quot;, V_STRING) Then GoTo Finally
242 End If
244 Try:
245 &apos; Update in UNO component object and in current instance
246 sDescription = Replace(pvDescription, &quot;\n&quot;, ScriptForge.SF_String.sfNEWLINE)
247 _Component.DocumentProperties.Description = sDescription
248 If Not IsNull(_DocumentProperties) Then _DocumentProperties.ReplaceItem(&quot;Description&quot;, sdescription)
250 Finally:
251 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
252 Exit Property
253 End Property &apos; SFDocuments.SF_Document.Description
255 REM -----------------------------------------------------------------------------
256 Property Get DocumentProperties() As Variant
257 &apos;&apos;&apos; Returns a dictionary of all standard document properties, custom properties are excluded
258 DocumentProperties = _PropertyGet(&quot;DocumentProperties&quot;)
259 End Property &apos; SFDocuments.SF_Document.DocumentProperties
261 REM -----------------------------------------------------------------------------
262 Property Get DocumentType() As String
263 &apos;&apos;&apos; Returns &quot;Base&quot;, &quot;Calc&quot;, &quot;Draw&quot;, ... or &quot;Writer&quot;
264 DocumentType = _PropertyGet(&quot;DocumentType&quot;)
265 End Property &apos; SFDocuments.SF_Document.DocumentType
267 REM -----------------------------------------------------------------------------
268 Property Get ExportFilters() As Variant
269 &apos;&apos;&apos; Returns the list of the export filter names applicable to the current document
270 &apos;&apos;&apos; as a zero-based array of strings
271 &apos;&apos;&apos; Import/Export filters are included
272 ExportFilters = _PropertyGet(&quot;ExportFilters&quot;)
273 End Property &apos; SFDocuments.SF_Document.ExportFilters
275 REM -----------------------------------------------------------------------------
276 Property Get FileSystem() As String
277 &apos;&apos;&apos; Returns the root of the document&apos;s virtual file system
278 &apos;&apos;&apos; The &quot;FileSystem&quot; service may be used to explore it, as long as the document remains open
279 &apos;&apos;&apos; The property is not applicable to Base documents
280 &apos;&apos;&apos; Example:
281 &apos;&apos;&apos; Dim sRoot As String, FSO
282 &apos;&apos;&apos; sRoot = oDoc.FileSystem
283 &apos;&apos;&apos; Set FSO = CreateScriptService(&quot;FileSystem&quot;)
284 &apos;&apos;&apos; MsgBox FSO.FolderExists(FSO.BuildPath(sRoot, &quot;Pictures&quot;))
285 FileSystem = _PropertyGet(&quot;FileSystem&quot;)
286 End Property &apos; SFDocuments.SF_Document.FileSystem
288 REM -----------------------------------------------------------------------------
289 Property Get ImportFilters() As Variant
290 &apos;&apos;&apos; Returns the list of the import filter names applicable to the current document
291 &apos;&apos;&apos; as a zero-based array of strings
292 &apos;&apos;&apos; Import/Export filters are included
293 ImportFilters = _PropertyGet(&quot;ImportFilters&quot;)
294 End Property &apos; SFDocuments.SF_Document.ImportFilters
296 REM -----------------------------------------------------------------------------
297 Property Get IsAlive() As Boolean
298 IsAlive = _PropertyGet(&quot;IsAlive&quot;)
299 End Property &apos; SFDocuments.SF_Document.IsAlive
301 REM -----------------------------------------------------------------------------
302 Property Get IsBase() As Boolean
303 IsBase = _PropertyGet(&quot;IsBase&quot;)
304 End Property &apos; SFDocuments.SF_Document.IsBase
306 REM -----------------------------------------------------------------------------
307 Property Get IsCalc() As Boolean
308 IsCalc = _PropertyGet(&quot;IsCalc&quot;)
309 End Property &apos; SFDocuments.SF_Document.IsCalc
311 REM -----------------------------------------------------------------------------
312 Property Get IsDraw() As Boolean
313 IsDraw = _PropertyGet(&quot;IsDraw&quot;)
314 End Property &apos; SFDocuments.SF_Document.IsDraw
316 REM -----------------------------------------------------------------------------
317 Property Get IsFormDocument() As Boolean
318 IsFormDocument = _PropertyGet(&quot;IsFormDocument&quot;)
319 End Property &apos; SFDocuments.SF_Document.IsFormDocument
321 REM -----------------------------------------------------------------------------
322 Property Get IsImpress() As Boolean
323 IsImpress = _PropertyGet(&quot;IsImpress&quot;)
324 End Property &apos; SFDocuments.SF_Document.IsImpress
326 REM -----------------------------------------------------------------------------
327 Property Get IsMath() As Boolean
328 IsMath = _PropertyGet(&quot;IsMath&quot;)
329 End Property &apos; SFDocuments.SF_Document.IsMath
331 REM -----------------------------------------------------------------------------
332 Property Get IsWriter() As Boolean
333 IsWriter = _PropertyGet(&quot;IsWriter&quot;)
334 End Property &apos; SFDocuments.SF_Document.IsWriter
336 REM -----------------------------------------------------------------------------
337 Property Get Keywords() As Variant
338 &apos;&apos;&apos; Returns the updatable document property Keywords
339 Keywords = _PropertyGet(&quot;Keywords&quot;)
340 End Property &apos; SFDocuments.SF_Document.Keywords
342 REM -----------------------------------------------------------------------------
343 Property Let Keywords(Optional ByVal pvKeywords As Variant)
344 &apos;&apos;&apos; Sets the updatable document property Keywords
346 Dim vKeywords As Variant &apos; Alias of pvKeywords
347 Const cstThisSub = &quot;SFDocuments.Document.setKeywords&quot;
348 Const cstSubArgs = &quot;Keywords&quot;
350 Check:
351 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
352 If Not _IsStillAlive(True) Then GoTo Finally
353 If Not ScriptForge.SF_Utils._Validate(pvKeywords, &quot;Keywords&quot;, V_STRING) Then GoTo Finally
354 End If
356 Try:
357 &apos; Update in UNO component object and in current instance
358 vKeywords = ScriptForge.SF_Array.TrimArray(Split(pvKeywords, &quot;,&quot;))
359 _Component.DocumentProperties.Keywords = vKeywords
360 If Not IsNull(_DocumentProperties) Then _DocumentProperties.ReplaceItem(&quot;Keywords&quot;, Join(vKeywords, &quot;, &quot;))
362 Finally:
363 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
364 Exit Property
365 End Property &apos; SFDocuments.SF_Document.Keywords
367 REM -----------------------------------------------------------------------------
368 Property Get Readonly() As Boolean
369 &apos;&apos;&apos; Returns True if the document must not be modified
370 Readonly = _PropertyGet(&quot;Readonly&quot;)
371 End Property &apos; SFDocuments.SF_Document.Readonly
373 REM -----------------------------------------------------------------------------
374 Property Get StyleFamilies() As Variant
375 &apos;&apos;&apos; Returns the list of available style families, as an array of strings
376 StyleFamilies = _PropertyGet(&quot;StyleFamilies&quot;)
377 End Property &apos; SFDocuments.SF_Document.StyleFamilies
379 REM -----------------------------------------------------------------------------
380 Property Get Subject() As Variant
381 &apos;&apos;&apos; Returns the updatable document property Subject
382 Subject = _PropertyGet(&quot;Subject&quot;)
383 End Property &apos; SFDocuments.SF_Document.Subject
385 REM -----------------------------------------------------------------------------
386 Property Let Subject(Optional ByVal pvSubject As Variant)
387 &apos;&apos;&apos; Sets the updatable document property Subject
389 Const cstThisSub = &quot;SFDocuments.Document.setSubject&quot;
390 Const cstSubArgs = &quot;Subject&quot;
392 Check:
393 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
394 If Not _IsStillAlive(True) Then GoTo Finally
395 If Not ScriptForge.SF_Utils._Validate(pvSubject, &quot;Subject&quot;, V_STRING) Then GoTo Finally
396 End If
398 Try:
399 &apos; Update in UNO component object and in current instance
400 _Component.DocumentProperties.Subject = pvSubject
401 If Not IsNull(_DocumentProperties) Then _DocumentProperties.ReplaceItem(&quot;Subject&quot;, pvSubject)
403 Finally:
404 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
405 Exit Property
406 End Property &apos; SFDocuments.SF_Document.Subject
408 REM -----------------------------------------------------------------------------
409 Property Get Title() As Variant
410 &apos;&apos;&apos; Returns the updatable document property Title
411 Title = _PropertyGet(&quot;Title&quot;)
412 End Property &apos; SFDocuments.SF_Document.Title
414 REM -----------------------------------------------------------------------------
415 Property Let Title(Optional ByVal pvTitle As Variant)
416 &apos;&apos;&apos; Sets the updatable document property Title
418 Const cstThisSub = &quot;SFDocuments.Document.setTitle&quot;
419 Const cstSubArgs = &quot;Title&quot;
421 Check:
422 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
423 If Not _IsStillAlive(True) Then GoTo Finally
424 If Not ScriptForge.SF_Utils._Validate(pvTitle, &quot;Title&quot;, V_STRING) Then GoTo Finally
425 End If
427 Try:
428 &apos; Update in UNO component object and in current instance
429 _Component.DocumentProperties.Title = pvTitle
430 If Not IsNull(_DocumentProperties) Then _DocumentProperties.ReplaceItem(&quot;Title&quot;, pvTitle)
432 Finally:
433 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
434 Exit Property
435 End Property &apos; SFDocuments.SF_Document.Title
437 REM -----------------------------------------------------------------------------
438 Property Get XComponent() As Variant
439 &apos;&apos;&apos; Returns the com.sun.star.lang.XComponent UNO object representing the document
440 XComponent = _PropertyGet(&quot;XComponent&quot;)
441 End Property &apos; SFDocuments.SF_Document.XComponent
443 REM -----------------------------------------------------------------------------
444 Property Get XDocumentSettings() As Variant
445 &apos;&apos;&apos; Gives access to a bunch of additional properties, specific to the document&apos;s type, about the document
446 &apos;&apos;&apos; Returns Nothing or a com.sun.star.XXX.DocumentSettings, XXX = text, sheet, drawing or presentation.
447 XDocumentSettings = _PropertyGet(&quot;XDocumentSettings&quot;)
448 End Property &apos; SFDocuments.SF_Document.XDocumentSettings
450 REM ===================================================================== METHODS
452 REM -----------------------------------------------------------------------------
453 Public Function Activate() As Boolean
454 &apos;&apos;&apos; Make the current document active
455 &apos;&apos;&apos; Args:
456 &apos;&apos;&apos; Returns:
457 &apos;&apos;&apos; True if the document could be activated
458 &apos;&apos;&apos; Otherwise, there is no change in the actual user interface
459 &apos;&apos;&apos; Examples:
460 &apos;&apos;&apos; oDoc.Activate()
462 Dim bActivate As Boolean &apos; Return value
463 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
464 Const cstThisSub = &quot;SFDocuments.Document.Activate&quot;
465 Const cstSubArgs = &quot;&quot;
467 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
468 bActivate = False
470 Check:
471 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
472 If Not _IsStillAlive() Then GoTo Finally
474 Try:
475 Set oContainer = _Frame.ContainerWindow
476 With oContainer
477 If .isVisible() = False Then .setVisible(True)
478 If .IsMinimized Then .IsMinimized = False
479 .setFocus()
480 .toFront() &apos; Force window change in Linux
481 Wait 1 &apos; Bypass desynchro issue in Linux
482 End With
483 bActivate = True
485 Finally:
486 Activate = bActivate
487 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
488 Exit Function
489 Catch:
490 GoTo Finally
491 End Function &apos; SFDocuments.SF_Document.Activate
493 REM -----------------------------------------------------------------------------
494 Public Function CloseDocument(Optional ByVal SaveAsk As Variant) As Boolean
495 &apos;&apos;&apos; Close the document. Does nothing if the document is already closed
496 &apos;&apos;&apos; regardless of how the document was closed, manually or by program
497 &apos;&apos;&apos; Args:
498 &apos;&apos;&apos; SaveAsk: If True (default), the user is invited to confirm or not the writing of the changes on disk
499 &apos;&apos;&apos; No effect if the document was not modified
500 &apos;&apos;&apos; Returns:
501 &apos;&apos;&apos; False if the user declined to close
502 &apos;&apos;&apos; Examples:
503 &apos;&apos;&apos; If oDoc.CloseDocument() Then
504 &apos;&apos;&apos; &apos; ...
506 Dim bClosed As Boolean &apos; return value
507 Dim oDispatch &apos; com.sun.star.frame.DispatchHelper
508 Const cstThisSub = &quot;SFDocuments.Document.CloseDocument&quot;
509 Const cstSubArgs = &quot;[SaveAsk=True]&quot;
511 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
512 bClosed = False
514 Check:
515 If IsMissing(SaveAsk) Or IsEmpty(SaveAsk) Then SaveAsk = True
516 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
517 If Not _IsStillAlive() Then GoTo Finally
518 If Not ScriptForge.SF_Utils._Validate(SaveAsk, &quot;SaveAsk&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
519 End If
521 Try:
522 If SaveAsk And _Component.IsModified Then &apos; Execute closure with the File/Close menu command
523 Activate()
524 RunCommand(&quot;CloseDoc&quot;)
525 bClosed = Not _IsStillAlive(, False) &apos; Do not raise error
526 Else
527 _Frame.close(True)
528 _Frame.dispose()
529 bClosed = True
530 End If
532 Finally:
533 If bClosed Then Dispose()
534 CloseDocument = bClosed
535 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
536 Exit Function
537 Catch:
538 On Local Error GoTo 0
539 GoTo Finally
540 End Function &apos; SFDocuments.SF_Document.CloseDocument
542 REM -----------------------------------------------------------------------------
543 Public Function ContextMenus(Optional ByVal ContextMenuName As Variant _
544 , Optional ByVal SubmenuChar As Variant _
545 ) As Variant
546 &apos;&apos;&apos; Returns either a list of the available ContextMenu names in the actual document
547 &apos;&apos;&apos; or a SFWidgets.ContextMenu object instance.
548 &apos;&apos;&apos; Args:
549 &apos;&apos;&apos; ContextMenuName: the usual name of one of the available ContextMenus
550 &apos;&apos;&apos; SubmenuChar: Delimiter used in menu trees
551 &apos;&apos;&apos; Returns:
552 &apos;&apos;&apos; A zero-based array of ContextMenu names when there is no argument,
553 &apos;&apos;&apos; or a new ContextMenu object instance from the SFWidgets library.
555 Const cstThisSub = &quot;SFDocuments.Document.ContextMenus&quot;
556 Const cstSubArgs = &quot;[ContextMenuName=&quot;&quot;&quot;&quot;], [SubmenuChar=&quot;&quot;&gt;&quot;&quot;]&quot;
558 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
560 Check:
561 If IsMissing(ContextMenuName) Or IsEmpty(ContextMenuName) Then ContextMenuName = &quot;&quot;
562 If IsMissing(SubmenuChar) Or IsEmpty(SubmenuChar) Then SubmenuChar = &quot;&gt;&quot;
563 If UBound(_ContextMenus) &lt; 0 Then _ContextMenus = _ListContextMenus()
564 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
565 If Not _IsStillAlive() Then GoTo Finally
566 If VarType(ContextMenuName) = V_STRING Then
567 If Len(ContextMenuName) &gt; 0 Then
568 If Not ScriptForge.SF_Utils._Validate(ContextMenuName, &quot;ContextMenuName&quot;, V_STRING, _ContextMenus) Then GoTo Finally
569 End If
570 Else
571 If Not ScriptForge.SF_Utils._Validate(ContextMenuName, &quot;ContextMenuName&quot;, V_STRING) Then GoTo Finally &apos; Manage here the VarType error
572 End If
573 If Not ScriptForge.SF_Utils._Validate(SubmenuChar, &quot;SubmenuChar&quot;, V_STRING) Then GoTo Finally
574 End If
576 Try:
577 If Len(ContextMenuName) = 0 Then
578 ContextMenus = _ContextMenus
579 Else
580 ContextMenus = CreateScriptService(&quot;SFWidgets.ContextMenu&quot; _
581 , _Component _
582 , &quot;private:resource/popupmenu/&quot; &amp; LCase(ContextMenuName) _
583 , SubmenuChar)
584 End If
586 Finally:
587 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
588 Exit Function
589 Catch:
590 GoTo Finally
591 End Function &apos; SFDocuments.SF_Document.ContextMenus
593 REM -----------------------------------------------------------------------------
594 Public Function CreateMenu(Optional ByVal MenuHeader As Variant _
595 , Optional ByVal Before As Variant _
596 , Optional ByVal SubmenuChar As Variant _
597 , Optional ByRef _Document As Variant _
598 ) As Object
599 &apos;&apos;&apos; Create a new menu entry in the document&apos;s menubar
600 &apos;&apos;&apos; The menu is not intended to be saved neither in the LibreOffice global environment, nor in the document
601 &apos;&apos;&apos; The method returns a SFWidgets.Menu instance. Its methods let define the menu further.
602 &apos;&apos;&apos; Args:
603 &apos;&apos;&apos; MenuHeader: the name/header of the menu
604 &apos;&apos;&apos; Before: the place where to put the new menu on the menubar (string or number &gt;= 1)
605 &apos;&apos;&apos; When not found =&gt; last position
606 &apos;&apos;&apos; SubmenuChar: the delimiter used in menu trees. Default = &quot;&gt;&quot;
607 &apos;&apos;&apos; _Document: undocumented argument to designate the document where the menu will be located
608 &apos;&apos;&apos; Returns:
609 &apos;&apos;&apos; A SFWidgets.Menu instance or Nothing
610 &apos;&apos;&apos; Examples:
611 &apos;&apos;&apos; Dim oMenu As Object
612 &apos;&apos;&apos; Set oMenu = oDoc.CreateMenu(&quot;My menu&quot;, Before := &quot;Styles&quot;)
613 &apos;&apos;&apos; With oMenu
614 &apos;&apos;&apos; .AddItem(&quot;Item 1&quot;, Command := &quot;About&quot;)
615 &apos;&apos;&apos; &apos;...
616 &apos;&apos;&apos; .Dispose() &apos; When definition is complete, the menu instance may be disposed
617 &apos;&apos;&apos; End With
618 &apos;&apos;&apos; &apos; ...
620 Dim oMenu As Object &apos; return value
621 Const cstThisSub = &quot;SFDocuments.Document.CreateMenu&quot;
622 Const cstSubArgs = &quot;MenuHeader, [Before=&quot;&quot;&quot;&quot;], [SubmenuChar=&quot;&quot;&gt;&quot;&quot;]&quot;
624 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
625 Set oMenu = Nothing
627 Check:
628 If IsMissing(Before) Or IsEmpty(Before) Then Before = &quot;&quot;
629 If IsMissing(SubmenuChar) Or IsEmpty(SubmenuChar) Then SubmenuChar = &quot;&quot;
630 If IsMissing(_Document) Or IsEmpty(_Document) Or IsNull(_Document) Then Set _Document = _Component
632 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
633 If Not _IsStillAlive() Then GoTo Finally
634 If Not ScriptForge.SF_Utils._Validate(MenuHeader, &quot;MenuHeader&quot;, V_STRING) Then GoTo Finally
635 If Not ScriptForge.SF_Utils._Validate(Before, &quot;Before&quot;, Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
636 If Not ScriptForge.SF_Utils._Validate(SubmenuChar, &quot;SubmenuChar&quot;, V_STRING) Then GoTo Finally
637 End If
639 Try:
640 Set oMenu = ScriptForge.SF_Services.CreateScriptService(&quot;SFWidgets.Menu&quot;, _Document, MenuHeader, Before, SubmenuChar)
642 Finally:
643 Set CreateMenu = oMenu
644 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
645 Exit Function
646 Catch:
647 GoTo Finally
648 End Function &apos; SFDocuments.SF_Document.CreateMenu
650 REM -----------------------------------------------------------------------------
651 Public Sub DeleteStyles(Optional ByVal Family As Variant _
652 , Optional ByRef StylesList As Variant _
654 &apos;&apos;&apos; Delete a single style or an array of styles given by their name(s)
655 &apos;&apos;&apos; within a specific styles family.
656 &apos;&apos;&apos; Only user-defined styles may be deleted. Built-in styles are ignored.
657 &apos;&apos;&apos; Args:
658 &apos;&apos;&apos; Family: one of the style families present in the actual document, as a case-sensitive string
659 &apos;&apos;&apos; StylesList: a single style name as a string or an array of style names.
660 &apos;&apos;&apos; The style names may be localized or not.
661 &apos;&apos;&apos; The StylesList is typically the output of the execution of a Styles() method.
662 &apos;&apos;&apos; Returns:
663 &apos;&apos;&apos; Examples:
664 &apos;&apos;&apos; &apos; Remove all unused styles
665 &apos;&apos;&apos; Const family = &quot;ParagraphStyles&quot;
666 &apos;&apos;&apos; doc.DeleteStyles(family, doc.Styles(family, Used := False, UserDefined := True))
668 Dim oFamily As Object &apos; Style names container
669 Dim vStylesList As Variant &apos; Alias of StylesList
670 Dim sStyle As String &apos; A single style name
671 Const cstThisSub = &quot;SFDocuments.Document.DeleteStyles&quot;
672 Const cstSubArgs = &quot;Family, StylesList&quot;
674 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
676 Check:
677 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
678 If Not _IsStillAlive() Then GoTo Finally
679 If UBound(_StyleFamilies) &lt; 0 Then _StyleFamilies = _Component.getStyleFamilies().getElementNames()
680 If Not ScriptForge.SF_Utils._Validate(Family, &quot;Family&quot;, V_STRING, _StyleFamilies) Then GoTo Finally
681 If IsArray(StylesList) Then
682 If Not ScriptForge.SF_Utils._ValidateArray(StylesList, &quot;StylesList&quot;, 1, V_STRING, True) Then GoTo Finally
683 Else
684 If Not ScriptForge.SF_Utils._Validate(StylesList, &quot;StylesList&quot;, V_STRING) Then GoTo Finally
685 End If
686 End If
688 Try:
689 Set oFamily = _GetStyleFamily(Family)
690 If Not IsNull(oFamily) Then
691 With oFamily
692 If Not IsArray(StylesList) Then vStylesList = Array(StylesList) Else vStylesList = StylesList
693 For Each sStyle In vStylesList
694 If .hasByName(sStyle) Then .removeByName(sStyle)
695 Next sStyle
696 End With
697 End If
699 Finally:
700 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
701 Exit Sub
702 Catch:
703 GoTo Finally
704 End Sub &apos; SFDocuments.SF_Document.DeleteStyles
706 REM -----------------------------------------------------------------------------
707 Public Sub Echo(Optional ByVal EchoOn As Variant _
708 , Optional ByVal Hourglass As Variant _
710 &apos;&apos;&apos; While a script is executed any display update resulting from that execution
711 &apos;&apos;&apos; is done immediately.
712 &apos;&apos;&apos; For performance reasons it might be an advantage to differ the display updates
713 &apos;&apos;&apos; up to the end of the script.
714 &apos;&apos;&apos; This is where pairs of Echo() methods to set and reset the removal of the
715 &apos;&apos;&apos; immediate updates may be beneficial.
716 &apos;&apos;&apos; Optionally the actual mouse pointer can be modified to the image of an hourglass.
717 &apos;&apos;&apos; Args:
718 &apos;&apos;&apos; EchoOn: when False, the display updates are suspended. Default = True.
719 &apos;&apos;&apos; Multiple calls with EchoOn = False are harmless.
720 &apos;&apos;&apos; Hourglass: when True, the mouse pointer is changed to an hourglass. Default = False.
721 &apos;&apos;&apos; The mouse pointer needs to be inside the actual document&apos;s window.
722 &apos;&apos;&apos; Note that it is very likely that at the least manual movement of the mouse,
723 &apos;&apos;&apos; the operating system or the LibreOffice process will take back the control
724 &apos;&apos;&apos; of the mouse icon and its usual behaviour.
725 &apos;&apos;&apos; Returns:
726 &apos;&apos;&apos; Examples:
727 &apos;&apos;&apos; oDoc.Echo(False, Hourglass := True)
728 &apos;&apos;&apos; &apos; ... &quot;long-lasting&quot; script ...
729 &apos;&apos;&apos; oDoc.Echo() &apos; Reset to normal
731 Dim oContainer As Object &apos; com.sun.star.awt.XWindow
732 Dim lPointer As Long &apos; com.sun.star.awt.SystemPointer constant
733 Dim oPointer As Object &apos; com.sun.star.awt.Pointer
734 Const cstThisSub = &quot;SFDocuments.Document.Echo&quot;
735 Const cstSubArgs = &quot;[EchoOn=True], [Hourglass=False]&quot;
737 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
739 Check:
740 If IsMissing(EchoOn) Or IsEmpty(EchoOn) Then EchoOn = True
741 If IsMissing(Hourglass) Or IsEmpty(Hourglass) Then Hourglass = False
742 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
743 If Not _IsStillAlive() Then GoTo Finally
744 If Not SF_Utils._Validate(EchoOn, &quot;EchoOn&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
745 If Not SF_Utils._Validate(Hourglass, &quot;Hourglass&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
746 End If
748 Try:
749 With _Component
751 Set oContainer = .CurrentController.Frame.GetContainerWindow()
752 Set oPointer = CreateUnoService(&quot;com.sun.star.awt.Pointer&quot;)
753 With com.sun.star.awt.SystemPointer
754 If Hourglass Then lPointer = .WAIT Else lPointer = .ARROW
755 End With
756 oPointer.setType(lPointer)
758 &apos; Mouse icon is set when controller is unlocked
759 If Not EchoOn Then
760 oContainer.setPointer(oPointer)
761 .lockControllers()
762 Else &apos; EchoOn = True
763 Do While .hasControllersLocked()
764 .unlockControllers()
765 Loop
766 oContainer.setPointer(oPointer)
767 End If
769 End With
771 Finally:
772 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
773 Exit Sub
774 Catch:
775 GoTo Finally
776 End Sub &apos; SFDocuments.SF_Document.Echo
778 REM -----------------------------------------------------------------------------
779 Public Function ExportAsPDF(Optional ByVal FileName As Variant _
780 , Optional ByVal Overwrite As Variant _
781 , Optional ByVal Pages As Variant _
782 , Optional ByVal Password As Variant _
783 , Optional ByVal Watermark As Variant _
784 ) As Boolean
785 &apos;&apos;&apos; Store the document to the given file location in PDF format
786 &apos;&apos;&apos; Args:
787 &apos;&apos;&apos; FileName: Identifies the file where to save. It must follow the SF_FileSystem.FileNaming notation
788 &apos;&apos;&apos; Overwrite: True if the destination file may be overwritten (default = False)
789 &apos;&apos;&apos; Pages: the pages to print as a string, like in the user interface. Example: &quot;1-4;10;15-18&quot;. Default = all pages
790 &apos;&apos;&apos; Password: password to open the document
791 &apos;&apos;&apos; Watermark: the text for a watermark to be drawn on every page of the exported PDF file
792 &apos;&apos;&apos; Returns:
793 &apos;&apos;&apos; False if the document could not be saved
794 &apos;&apos;&apos; Exceptions:
795 &apos;&apos;&apos; DOCUMENTSAVEASERROR The destination has its readonly attribute set or overwriting rejected
796 &apos;&apos;&apos; Examples:
797 &apos;&apos;&apos; oDoc.ExportAsPDF(&quot;C:\Me\myDoc.pdf&quot;, Overwrite := True)
799 Dim bSaved As Boolean &apos; return value
800 Dim oSfa As Object &apos; com.sun.star.ucb.SimpleFileAccess
801 Dim sFile As String &apos; Alias of FileName
802 Dim sFilter As String &apos; One of the pdf filter names
803 Dim vFilterData As Variant &apos; Array of com.sun.star.beans.PropertyValue
804 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
805 Dim FSO As Object &apos; SF_FileSystem
806 Const cstThisSub = &quot;SFDocuments.Document.ExportAsPDF&quot;
807 Const cstSubArgs = &quot;FileName, [Overwrite=False], [Pages=&quot;&quot;&quot;&quot;], [Password=&quot;&quot;&quot;&quot;], [Watermark=&quot;&quot;&quot;&quot;]&quot;
809 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo CatchError
810 bSaved = False
812 Check:
813 If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False
814 If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
815 If IsMissing(Password) Or IsEmpty(Password) Then Password = &quot;&quot;
816 If IsMissing(Watermark) Or IsEmpty(Watermark) Then Watermark = &quot;&quot;
818 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
819 If Not _IsStillAlive() Then GoTo Finally
820 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
821 If Not SF_Utils._Validate(Overwrite, &quot;Overwrite&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
822 If Not SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
823 If Not SF_Utils._Validate(Password, &quot;Password&quot;, V_STRING) Then GoTo Finally
824 If Not SF_Utils._Validate(Watermark, &quot;Watermark&quot;, V_STRING) Then GoTo Finally
825 End If
827 &apos; Check destination file overwriting
828 Set FSO = CreateScriptService(&quot;FileSystem&quot;)
829 sFile = FSO._ConvertToUrl(FileName)
830 If FSO.FileExists(FileName) Then
831 If Overwrite = False Then GoTo CatchError
832 Set oSfa = ScriptForge.SF_Utils._GetUNOService(&quot;FileAccess&quot;)
833 If oSfa.isReadonly(sFile) Then GoTo CatchError
834 End If
836 Try:
837 &apos; Setup arguments
838 Select Case _DocumentType &apos; Disguise form documents as a Writer document
839 Case &quot;FormDocument&quot; : sFilter = &quot;Writer_pdf_Export&quot;
840 Case Else : sFilter = LCase(_DocumentType) &amp; &quot;_pdf_Export&quot;
841 End Select
842 &apos; FilterData parameters are added only if they are meaningful
843 vFilterData = Array()
844 If Len(Pages) &gt; 0 Then
845 vFilterData = ScriptForge.SF_Array.Append(vFilterData _
846 , ScriptForge.SF_Utils._MakePropertyValue(&quot;PageRange&quot;, Pages))
847 End If
848 If Len(Password) &gt; 0 Then
849 vFilterData = ScriptForge.SF_Array.Append(vFilterData _
850 , ScriptForge.SF_Utils._MakePropertyValue(&quot;EncryptFile&quot;, True) _
851 , ScriptForge.SF_Utils._MakePropertyValue(&quot;DocumentOpenPassword&quot;, Password))
852 End If
853 If Len(Watermark) &gt; 0 Then
854 vFilterData = ScriptForge.SF_Array.Append(vFilterData _
855 , ScriptForge.SF_Utils._MakePropertyValue(&quot;Watermark&quot;, Watermark))
856 End If
858 &apos; Finalize properties and export
859 vProperties = Array( _
860 ScriptForge.SF_Utils._MakePropertyValue(&quot;FilterName&quot;, sFilter) _
861 , ScriptForge.SF_Utils._MakePropertyValue(&quot;FilterData&quot;, vFilterData))
862 _Component.StoreToURL(sFile, vProperties)
863 bSaved = True
865 Finally:
866 ExportAsPDF = bSaved
867 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
868 Exit Function
869 Catch:
870 GoTo Finally
871 CatchError:
872 ScriptForge.SF_Exception.RaiseFatal(DOCUMENTSAVEASERROR, &quot;FileName&quot;, FileName, &quot;Overwrite&quot;, Overwrite _
873 , &quot;FilterName&quot;, &quot;PDF Export&quot;)
874 GoTo Finally
875 End Function &apos; SFDocuments.SF_Document.ExportAsPDF
877 REM -----------------------------------------------------------------------------
878 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
879 &apos;&apos;&apos; Return the actual value of the given property
880 &apos;&apos;&apos; Args:
881 &apos;&apos;&apos; PropertyName: the name of the property as a string
882 &apos;&apos;&apos; Returns:
883 &apos;&apos;&apos; The actual value of the property
884 &apos;&apos;&apos; If the property does not exist, returns Null
885 &apos;&apos;&apos; Exceptions:
886 &apos;&apos;&apos; see the exceptions of the individual properties
887 &apos;&apos;&apos; Examples:
888 &apos;&apos;&apos; myModel.GetProperty(&quot;MyProperty&quot;)
890 Const cstThisSub = &quot;SFDocuments.Document.GetProperty&quot;
891 Const cstSubArgs = &quot;&quot;
893 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
894 GetProperty = Null
896 Check:
897 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
898 If Not ScriptForge.SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
899 End If
901 Try:
902 GetProperty = _PropertyGet(PropertyName)
904 Finally:
905 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
906 Exit Function
907 Catch:
908 GoTo Finally
909 End Function &apos; SFDocuments.SF_Document.GetProperty
911 REM -----------------------------------------------------------------------------
912 Public Function Methods() As Variant
913 &apos;&apos;&apos; Return the list of public methods of the Document service as an array
915 Methods = Array( _
916 &quot;Activate&quot; _
917 , &quot;CloseDocument&quot; _
918 , &quot;ContextMenus&quot; _
919 , &quot;CreateMenu&quot; _
920 , &quot;Echo&quot; _
921 , &quot;DeleteStyles&quot; _
922 , &quot;ExportAsPDF&quot; _
923 , &quot;ImportStylesFromFile&quot; _
924 , &quot;PrintOut&quot; _
925 , &quot;RemoveMenu&quot; _
926 , &quot;RunCommand&quot; _
927 , &quot;Save&quot; _
928 , &quot;SaveAs&quot; _
929 , &quot;SaveCopyAs&quot; _
930 , &quot;SetPrinter&quot; _
931 , &quot;Styles&quot; _
932 , &quot;Toolbars&quot; _
933 , &quot;XStyle&quot; _
936 End Function &apos; SFDocuments.SF_Document.Methods
938 REM -----------------------------------------------------------------------------
939 Public Function PrintOut(Optional ByVal Pages As Variant _
940 , Optional ByVal Copies As Variant _
941 , Optional ByRef _Document As Variant _
942 ) As Boolean
943 &apos;&apos;&apos; Send the content of the document to the printer.
944 &apos;&apos;&apos; The printer might be defined previously by default, by the user or by the SetPrinter() method
945 &apos;&apos;&apos; Args:
946 &apos;&apos;&apos; Pages: the pages to print as a string, like in the user interface. Example: &quot;1-4;10;15-18&quot;. Default = all pages
947 &apos;&apos;&apos; Copies: the number of copies
948 &apos;&apos;&apos; _Document: undocumented argument to designate the document to print when called from a subclass
949 &apos;&apos;&apos; Returns:
950 &apos;&apos;&apos; True when successful
951 &apos;&apos;&apos; Examples:
952 &apos;&apos;&apos; oDoc.PrintOut(&quot;1-4;10;15-18&quot;, Copies := 2)
954 Dim bPrint As Boolean &apos; Return value
955 Dim vPrintGoal As Variant &apos; Array of property values
957 Const cstThisSub = &quot;SFDocuments.Document.PrintOut&quot;
958 Const cstSubArgs = &quot;[Pages=&quot;&quot;&quot;&quot;], [Copies=1]&quot;
960 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
961 bPrint = False
963 Check:
964 If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
965 If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
966 If IsMissing(_Document) Or IsEmpty(_Document) Or IsNull(_Document) Then Set _Document = _Component
968 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
969 If Not _IsStillAlive() Then GoTo Finally
970 If Not ScriptForge.SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
971 If Not ScriptForge.SF_Utils._Validate(Copies, &quot;Copies&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
972 End If
974 Try:
975 vPrintGoal = Array( _
976 ScriptForge.SF_Utils._MakePropertyValue(&quot;CopyCount&quot;, CInt(Copies)) _
977 , ScriptForge.SF_Utils._MakePropertyValue(&quot;Collate&quot;, True) _
978 , ScriptForge.SF_Utils._MakePropertyValue(&quot;Pages&quot;, Pages) _
979 , ScriptForge.SF_Utils._MakePropertyValue(&quot;Wait&quot;, False) _
982 _Document.Print(vPrintGoal)
983 bPrint = True
985 Finally:
986 PrintOut = bPrint
987 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
988 Exit Function
989 Catch:
990 GoTo Finally
991 End Function &apos; SFDocuments.SF_Document.PrintOut
993 REM -----------------------------------------------------------------------------
994 Public Function Properties() As Variant
995 &apos;&apos;&apos; Return the list or properties of the Document class as an array
997 Properties = Array( _
998 &quot;CustomProperties&quot; _
999 , &quot;Description&quot; _
1000 , &quot;DocumentProperties&quot; _
1001 , &quot;DocumentType&quot; _
1002 , &quot;ExportFilters&quot; _
1003 , &quot;FileSystem&quot; _
1004 , &quot;ImportFilters&quot; _
1005 , &quot;IsAlive&quot; _
1006 , &quot;IsBase&quot; _
1007 , &quot;IsCalc&quot; _
1008 , &quot;IsDraw&quot; _
1009 , &quot;IsFormDocument&quot; _
1010 , &quot;IsImpress&quot; _
1011 , &quot;IsMath&quot; _
1012 , &quot;IsWriter&quot; _
1013 , &quot;Keywords&quot; _
1014 , &quot;Readonly&quot; _
1015 , &quot;StyleFamilies&quot; _
1016 , &quot;Subject&quot; _
1017 , &quot;Title&quot; _
1018 , &quot;XComponent&quot; _
1019 , &quot;XDocumentSettings&quot; _
1022 End Function &apos; SFDocuments.SF_Document.Properties
1024 REM -----------------------------------------------------------------------------
1025 Public Function RemoveMenu(Optional ByVal MenuHeader As Variant _
1026 , Optional ByRef _Document As Variant _
1027 ) As Boolean
1028 &apos;&apos;&apos; Remove a menu entry in the document&apos;s menubar
1029 &apos;&apos;&apos; The removal is not intended to be saved neither in the LibreOffice global environment, nor in the document
1030 &apos;&apos;&apos; Args:
1031 &apos;&apos;&apos; MenuHeader: the name/header of the menu, without tilde &quot;~&quot;, as a case-sensitive string
1032 &apos;&apos;&apos; _Document: undocumented argument to designate the document where the menu is located
1033 &apos;&apos;&apos; Returns:
1034 &apos;&apos;&apos; True when successful
1035 &apos;&apos;&apos; Examples:
1036 &apos;&apos;&apos; oDoc.RemoveMenu(&quot;File&quot;)
1037 &apos;&apos;&apos; &apos; ...
1039 Dim bRemove As Boolean &apos; Return value
1040 Dim oLayout As Object &apos; com.sun.star.comp.framework.LayoutManager
1041 Dim oMenuBar As Object &apos; com.sun.star.awt.XMenuBar or stardiv.Toolkit.VCLXMenuBar
1042 Dim sName As String &apos; Menu name
1043 Dim iMenuId As Integer &apos; Menu identifier
1044 Dim iMenuPosition As Integer &apos; Menu position &gt;= 0
1045 Dim i As Integer
1046 Const cstTilde = &quot;~&quot;
1048 Const cstThisSub = &quot;SFDocuments.Document.RemoveMenu&quot;
1049 Const cstSubArgs = &quot;MenuHeader&quot;
1051 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1052 bRemove = False
1054 Check:
1055 If IsMissing(_Document) Or IsEmpty(_Document) Or IsNull(_Document) Then Set _Document = _Component
1056 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1057 If Not _IsStillAlive() Then GoTo Finally
1058 If Not ScriptForge.SF_Utils._Validate(MenuHeader, &quot;MenuHeader&quot;, V_STRING) Then GoTo Finally
1059 End If
1061 Try:
1062 Set oLayout = _Document.CurrentController.Frame.LayoutManager
1063 Set oMenuBar = oLayout.getElement(&quot;private:resource/menubar/menubar&quot;).XMenuBar
1065 &apos; Search the menu identifier to remove by its name, Mark its position
1066 With oMenuBar
1067 iMenuPosition = -1
1068 For i = 0 To .ItemCount - 1
1069 iMenuId = .getItemId(i)
1070 sName = Replace(.getItemText(iMenuId), cstTilde, &quot;&quot;)
1071 If MenuHeader= sName Then
1072 iMenuPosition = i
1073 Exit For
1074 End If
1075 Next i
1076 &apos; Remove the found menu item
1077 If iMenuPosition &gt;= 0 Then
1078 .removeItem(iMenuPosition, 1)
1079 bRemove = True
1080 End If
1081 End With
1083 Finally:
1084 RemoveMenu = bRemove
1085 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1086 Exit Function
1087 Catch:
1088 GoTo Finally
1089 End Function &apos; SFDocuments.SF_Document.RemoveMenu
1091 REM -----------------------------------------------------------------------------
1092 Public Sub RunCommand(Optional ByVal Command As Variant _
1093 , ParamArray Args As Variant _
1095 &apos;&apos;&apos; Run on the current document window the given menu command. The command is executed with or without arguments
1096 &apos;&apos;&apos; A few typical commands:
1097 &apos;&apos;&apos; Save, SaveAs, ExportToPDF, SetDocumentProperties, Undo, Copy, Paste, ...
1098 &apos;&apos;&apos; Dozens can be found on next page: https://wiki.documentfoundation.org/Development/DispatchCommands
1099 &apos;&apos;&apos; Args:
1100 &apos;&apos;&apos; Command: Case-sensitive. The command itself is not checked.
1101 &apos;&apos;&apos; If the command does not contain the &quot;.uno:&quot; prefix, it is added.
1102 &apos;&apos;&apos; If nothing happens, then the command is probably wrong
1103 &apos;&apos;&apos; Args: Pairs of arguments name (string), value (any)
1104 &apos;&apos;&apos; Returns:
1105 &apos;&apos;&apos; Examples:
1106 &apos;&apos;&apos; oDoc.RunCommand(&quot;EditDoc&quot;, &quot;Editable&quot;, False) &apos; Toggle edit mode
1108 Dim vArgs As Variant &apos; Alias of Args
1109 Dim oDispatch &apos; com.sun.star.frame.DispatchHelper
1110 Dim vProps As Variant &apos; Array of PropertyValues
1111 Dim vValue As Variant &apos; A single value argument
1112 Dim sCommand As String &apos; Alias of Command
1113 Dim i As Long
1114 Const cstPrefix = &quot;.uno:&quot;
1116 Const cstThisSub = &quot;SFDocuments.Document.RunCommand&quot;
1117 Const cstSubArgs = &quot;Command, [arg0Name, arg0Value], [arg1Name, arg1Value], ...&quot;
1119 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1121 Check:
1122 &apos; When called from a subclass (Calc, Writer, ..) the arguments are gathered into one single array item
1123 vArgs = Args
1124 If IsArray(Args) Then
1125 If UBound(Args) &gt;= 0 Then
1126 If IsArray(Args(0)) Then vArgs = Args(0)
1127 End If
1128 End If
1129 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1130 If Not _IsStillAlive() Then GoTo Finally
1131 If Not ScriptForge.SF_Utils._Validate(Command, &quot;Command&quot;, V_STRING) Then GoTo Finally
1132 If Not ScriptForge.SF_Utils._ValidateArray(vArgs, &quot;Args&quot;, 1) Then GoTo Finally
1133 For i = 0 To UBound(vArgs) - 1 Step 2
1134 If Not ScriptForge.SF_Utils._Validate(vArgs(i), &quot;Arg&quot; &amp; CStr(i/2) &amp; &quot;Name&quot;, V_STRING) Then GoTo Finally
1135 Next i
1136 End If
1138 Try:
1139 &apos; Build array of property values
1140 vProps = Array()
1141 For i = 0 To UBound(vArgs) - 1 Step 2
1142 If IsEmpty(vArgs(i + 1)) Then vValue = Null Else vValue = vArgs(i + 1)
1143 vProps = ScriptForge.SF_Array.Append(vProps, ScriptForge.SF_Utils._MakePropertyValue(vArgs(i), vValue))
1144 Next i
1145 Set oDispatch = ScriptForge.SF_Utils._GetUNOService(&quot;DispatchHelper&quot;)
1146 If ScriptForge.SF_String.StartsWith(Command, cstPrefix) Then sCommand = Command Else sCommand = cstPrefix &amp; Command
1147 oDispatch.executeDispatch(_Frame, sCommand, &quot;&quot;, 0, vProps)
1149 Finally:
1150 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1151 Exit Sub
1152 Catch:
1153 GoTo Finally
1154 End Sub &apos; SFDocuments.SF_Document.RunCommand
1156 REM -----------------------------------------------------------------------------
1157 Public Function Save() As Boolean
1158 &apos;&apos;&apos; Store the document to the file location from which it was loaded
1159 &apos;&apos;&apos; Ignored if the document was not modified
1160 &apos;&apos;&apos; Args:
1161 &apos;&apos;&apos; Returns:
1162 &apos;&apos;&apos; False if the document could not be saved
1163 &apos;&apos;&apos; Exceptions:
1164 &apos;&apos;&apos; DOCUMENTSAVEERROR The file has been opened readonly or was opened as new and was not yet saved
1165 &apos;&apos;&apos; Examples:
1166 &apos;&apos;&apos; If Not oDoc.Save() Then
1167 &apos;&apos;&apos; &apos; ...
1169 Dim bSaved As Boolean &apos; return value
1170 Const cstThisSub = &quot;SFDocuments.Document.Save&quot;
1171 Const cstSubArgs = &quot;&quot;
1173 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1174 bSaved = False
1176 Check:
1177 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1178 If Not _IsStillAlive() Then GoTo Finally
1179 bSaved = False
1181 Try:
1182 With _Component
1183 If .isReadonly() Or Not .hasLocation() Then GoTo CatchReadonly
1184 If .IsModified() Then
1185 .store()
1186 bSaved = True
1187 End If
1188 End With
1190 Finally:
1191 Save = bSaved
1192 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1193 Exit Function
1194 Catch:
1195 GoTo Finally
1196 CatchReadonly:
1197 ScriptForge.SF_Exception.RaiseFatal(DOCUMENTSAVEERROR, &quot;FileName&quot;, _FileIdent())
1198 GoTo Finally
1199 End Function &apos; SFDocuments.SF_Document.Save
1201 REM -----------------------------------------------------------------------------
1202 Public Function SaveAs(Optional ByVal FileName As Variant _
1203 , Optional ByVal Overwrite As Variant _
1204 , Optional ByVal Password As Variant _
1205 , Optional ByVal FilterName As Variant _
1206 , Optional ByVal FilterOptions As Variant _
1207 ) As Boolean
1208 &apos;&apos;&apos; Store the document to the given file location
1209 &apos;&apos;&apos; The new location becomes the new file name on which simple Save method calls will be applied
1210 &apos;&apos;&apos; Args:
1211 &apos;&apos;&apos; FileName: Identifies the file where to save. It must follow the SF_FileSystem.FileNaming notation
1212 &apos;&apos;&apos; Overwrite: True if the destination file may be overwritten (default = False)
1213 &apos;&apos;&apos; Password: Use to protect the document
1214 &apos;&apos;&apos; FilterName: the name of a filter that should be used for saving the document
1215 &apos;&apos;&apos; If present, the filter must exist
1216 &apos;&apos;&apos; FilterOptions: an optional string of options associated with the filter
1217 &apos;&apos;&apos; Returns:
1218 &apos;&apos;&apos; False if the document could not be saved
1219 &apos;&apos;&apos; Exceptions:
1220 &apos;&apos;&apos; DOCUMENTSAVEASERROR The destination has its readonly attribute set or overwriting rejected
1221 &apos;&apos;&apos; Examples:
1222 &apos;&apos;&apos; oDoc.SaveAs(&quot;C:\Me\Copy2.odt&quot;, Overwrite := True)
1224 Dim bSaved As Boolean &apos; return value
1225 Dim oFilterFactory As Object &apos; com.sun.star.document.FilterFactory
1226 Dim oSfa As Object &apos; com.sun.star.ucb.SimpleFileAccess
1227 Dim sFile As String &apos; Alias of FileName
1228 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
1229 Dim FSO As Object &apos; SF_FileSystem
1230 Const cstThisSub = &quot;SFDocuments.Document.SaveAs&quot;
1231 Const cstSubArgs = &quot;FileName, [Overwrite=False], [Password=&quot;&quot;&quot;&quot;], [FilterName=&quot;&quot;&quot;&quot;], [FilterOptions=&quot;&quot;&quot;&quot;]&quot;
1233 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo CatchError
1234 bSaved = False
1236 Check:
1237 If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False
1238 If IsMissing(Password) Or IsEmpty(Password) Then Password = &quot;&quot;
1239 If IsMissing(FilterName) Or IsEmpty(FilterName) Then FilterName = &quot;&quot;
1240 If IsMissing(FilterOptions) Or IsEmpty(FilterOptions) Then FilterOptions = &quot;&quot;
1242 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1243 If Not _IsStillAlive() Then GoTo Finally
1244 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
1245 If Not SF_Utils._Validate(Overwrite, &quot;Overwrite&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
1246 If Not SF_Utils._Validate(Password, &quot;Password&quot;, V_STRING) Then GoTo Finally
1247 If Not SF_Utils._Validate(FilterName, &quot;FilterName&quot;, V_STRING) Then GoTo Finally
1248 If Not SF_Utils._Validate(FilterOptions, &quot;FilterOptions&quot;, V_STRING) Then GoTo Finally
1249 End If
1251 &apos; Check that the filter exists
1252 If Len(FilterName) &gt; 0 Then
1253 Set oFilterFactory = ScriptForge.SF_Utils._GetUNOService(&quot;FilterFactory&quot;)
1254 If Not oFilterFactory.hasByName(FilterName) Then GoTo CatchError
1255 End If
1257 &apos; Check destination file overwriting
1258 Set FSO = CreateScriptService(&quot;FileSystem&quot;)
1259 sFile = FSO._ConvertToUrl(FileName)
1260 If FSO.FileExists(FileName) Then
1261 If Overwrite = False Then GoTo CatchError
1262 Set oSfa = ScriptForge.SF_Utils._GetUNOService(&quot;FileAccess&quot;)
1263 If oSfa.isReadonly(sFile) Then GoTo CatchError
1264 End If
1266 Try:
1267 &apos; Setup arguments
1268 If Len(Password) + Len(FilterName) = 0 Then
1269 vProperties = Array()
1270 Else
1271 vProperties = Array( _
1272 ScriptForge.SF_Utils._MakePropertyValue(&quot;FilterName&quot;, FilterName) _
1273 , ScriptForge.SF_Utils._MakePropertyValue(&quot;FilterOptions&quot;, FilterOptions) _
1275 If Len(Password) &gt; 0 Then &apos; Password is to add only if &lt;&gt; &quot;&quot; !?
1276 vProperties = ScriptForge.SF_Array.Append(vProperties _
1277 , ScriptForge.SF_Utils._MakePropertyValue(&quot;Password&quot;, Password))
1278 End If
1279 End If
1281 _Component.StoreAsURL(sFile, vProperties)
1283 &apos; Remind the new file name
1284 _WindowFileName = sFile
1285 _WindowName = FSO.GetName(FileName)
1286 bSaved = True
1288 Finally:
1289 SaveAs = bSaved
1290 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1291 Exit Function
1292 Catch:
1293 GoTo Finally
1294 CatchError:
1295 ScriptForge.SF_Exception.RaiseFatal(DOCUMENTSAVEASERROR, &quot;FileName&quot;, FileName, &quot;Overwrite&quot;, Overwrite _
1296 , &quot;FilterName&quot;, FilterName)
1297 GoTo Finally
1298 End Function &apos; SFDocuments.SF_Document.SaveAs
1300 REM -----------------------------------------------------------------------------
1301 Public Function SaveCopyAs(Optional ByVal FileName As Variant _
1302 , Optional ByVal Overwrite As Variant _
1303 , Optional ByVal Password As Variant _
1304 , Optional ByVal FilterName As Variant _
1305 , Optional ByVal FilterOptions As Variant _
1306 ) As Boolean
1307 &apos;&apos;&apos; Store a copy or export the document to the given file location
1308 &apos;&apos;&apos; The actual location is unchanged
1309 &apos;&apos;&apos; Args:
1310 &apos;&apos;&apos; FileName: Identifies the file where to save. It must follow the SF_FileSystem.FileNaming notation
1311 &apos;&apos;&apos; Overwrite: True if the destination file may be overwritten (default = False)
1312 &apos;&apos;&apos; Password: Use to protect the document
1313 &apos;&apos;&apos; FilterName: the name of a filter that should be used for saving the document
1314 &apos;&apos;&apos; If present, the filter must exist
1315 &apos;&apos;&apos; FilterOptions: an optional string of options associated with the filter
1316 &apos;&apos;&apos; Returns:
1317 &apos;&apos;&apos; False if the document could not be saved
1318 &apos;&apos;&apos; Exceptions:
1319 &apos;&apos;&apos; DOCUMENTSAVEASERROR The destination has its readonly attribute set or overwriting rejected
1320 &apos;&apos;&apos; Examples:
1321 &apos;&apos;&apos; oDoc.SaveCopyAs(&quot;C:\Me\Copy2.odt&quot;, Overwrite := True)
1323 Dim bSaved As Boolean &apos; return value
1324 Dim oFilterFactory As Object &apos; com.sun.star.document.FilterFactory
1325 Dim oSfa As Object &apos; com.sun.star.ucb.SimpleFileAccess
1326 Dim sFile As String &apos; Alias of FileName
1327 Dim vProperties As Variant &apos; Array of com.sun.star.beans.PropertyValue
1328 Dim FSO As Object &apos; SF_FileSystem
1329 Const cstThisSub = &quot;SFDocuments.Document.SaveCopyAs&quot;
1330 Const cstSubArgs = &quot;FileName, [Overwrite=False], [Password=&quot;&quot;&quot;&quot;], [FilterName=&quot;&quot;&quot;&quot;], [FilterOptions=&quot;&quot;&quot;&quot;]&quot;
1332 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo CatchError
1333 bSaved = False
1335 Check:
1336 If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False
1337 If IsMissing(Password) Or IsEmpty(Password) Then Password = &quot;&quot;
1338 If IsMissing(FilterName) Or IsEmpty(FilterName) Then FilterName = &quot;&quot;
1339 If IsMissing(FilterOptions) Or IsEmpty(FilterOptions) Then FilterOptions = &quot;&quot;
1341 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1342 If Not _IsStillAlive() Then GoTo Finally
1343 If Not SF_Utils._ValidateFile(FileName, &quot;FileName&quot;) Then GoTo Finally
1344 If Not SF_Utils._Validate(Overwrite, &quot;Overwrite&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
1345 If Not SF_Utils._Validate(Password, &quot;Password&quot;, V_STRING) Then GoTo Finally
1346 If Not SF_Utils._Validate(FilterName, &quot;FilterName&quot;, V_STRING) Then GoTo Finally
1347 If Not SF_Utils._Validate(FilterOptions, &quot;FilterOptions&quot;, V_STRING) Then GoTo Finally
1348 End If
1350 &apos; Check that the filter exists
1351 If Len(FilterName) &gt; 0 Then
1352 Set oFilterFactory = ScriptForge.SF_Utils._GetUNOService(&quot;FilterFactory&quot;)
1353 If Not oFilterFactory.hasByName(FilterName) Then GoTo CatchError
1354 End If
1356 &apos; Check destination file overwriting
1357 Set FSO = CreateScriptService(&quot;FileSystem&quot;)
1358 sFile = FSO._ConvertToUrl(FileName)
1359 If FSO.FileExists(FileName) Then
1360 If Overwrite = False Then GoTo CatchError
1361 Set oSfa = ScriptForge.SF_Utils._GetUNOService(&quot;FileAccess&quot;)
1362 If oSfa.isReadonly(sFile) Then GoTo CatchError
1363 End If
1365 Try:
1366 &apos; Setup arguments
1367 If Len(Password) + Len(FilterName) = 0 Then
1368 vProperties = Array()
1369 Else
1370 vProperties = Array( _
1371 ScriptForge.SF_Utils._MakePropertyValue(&quot;FilterName&quot;, FilterName) _
1372 , ScriptForge.SF_Utils._MakePropertyValue(&quot;FilterOptions&quot;, FilterOptions) _
1374 If Len(Password) &gt; 0 Then &apos; Password is to add only if &lt;&gt; &quot;&quot; !?
1375 vProperties = ScriptForge.SF_Array.Append(vProperties _
1376 , ScriptForge.SF_Utils._MakePropertyValue(&quot;Password&quot;, Password))
1377 End If
1378 End If
1380 _Component.StoreToURL(sFile, vProperties)
1381 bSaved = True
1383 Finally:
1384 SaveCopyAs = bSaved
1385 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1386 Exit Function
1387 Catch:
1388 GoTo Finally
1389 CatchError:
1390 ScriptForge.SF_Exception.RaiseFatal(DOCUMENTSAVEASERROR, &quot;FileName&quot;, FileName, &quot;Overwrite&quot;, Overwrite _
1391 , &quot;FilterName&quot;, FilterName)
1392 GoTo Finally
1393 End Function &apos; SFDocuments.SF_Document.SaveCopyAs
1395 REM -----------------------------------------------------------------------------
1396 Public Function SetPrinter(Optional ByVal Printer As Variant _
1397 , Optional ByVal Orientation As Variant _
1398 , Optional ByVal PaperFormat As Variant _
1399 , Optional ByRef _PrintComponent As Variant _
1400 ) As Boolean
1401 &apos;&apos;&apos; Define the printer options for the document
1402 &apos;&apos;&apos; Args:
1403 &apos;&apos;&apos; Printer: the name of the printer queue where to print to
1404 &apos;&apos;&apos; When absent or space, the default printer is set
1405 &apos;&apos;&apos; Orientation: either &quot;PORTRAIT&quot; or &quot;LANDSCAPE&quot;. Left unchanged when absent
1406 &apos;&apos;&apos; PaperFormat: one of next values
1407 &apos;&apos;&apos; &quot;A3&quot;, &quot;A4&quot;, &quot;A5&quot;, &quot;B4&quot;, &quot;B5&quot;, &quot;LETTER&quot;, &quot;LEGAL&quot;, &quot;TABLOID&quot;
1408 &apos;&apos;&apos; Left unchanged when absent
1409 &apos;&apos;&apos; _PrintComponent: undocumented argument to determine the component
1410 &apos;&apos;&apos; Useful typically to apply printer settings on a Base form document
1411 &apos;&apos;&apos; Returns:
1412 &apos;&apos;&apos; True when successful
1413 &apos;&apos;&apos; Examples:
1414 &apos;&apos;&apos; oDoc.SetPrinter(Orientation := &quot;PORTRAIT&quot;)
1416 Dim bPrinter As Boolean &apos; Return value
1417 Dim vPrinters As Variant &apos; Array of known printers
1418 Dim vOrientations As Variant &apos; Array of allowed paper orientations
1419 Dim vPaperFormats As Variant &apos; Array of allowed formats
1420 Dim vPrinterSettings As Variant &apos; Array of property values
1421 Dim oPropertyValue As New com.sun.star.beans.PropertyValue
1422 &apos; A single property value item
1423 Const cstThisSub = &quot;SFDocuments.Document.SetPrinter&quot;
1424 Const cstSubArgs = &quot;[Printer=&quot;&quot;&quot;&quot;], [Orientation=&quot;&quot;PORTRAIT&quot;&quot;|&quot;&quot;LANDSCAPE&quot;&quot;]&quot; _
1425 &amp; &quot;, [PaperFormat=&quot;&quot;A3&quot;&quot;|&quot;&quot;A4&quot;&quot;|&quot;&quot;A5&quot;&quot;|&quot;&quot;B4&quot;&quot;|&quot;&quot;B5&quot;&quot;|&quot;&quot;LETTER&quot;&quot;|&quot;&quot;LEGAL&quot;&quot;|&quot;&quot;TABLOID&quot;&quot;&quot;
1427 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1428 bPrinter = False
1430 Check:
1431 If IsMissing(Printer) Or IsEmpty(Printer) Then Printer = &quot;&quot;
1432 If IsMissing(Orientation) Or IsEmpty(Orientation) Then Orientation = &quot;&quot;
1433 If IsMissing(PaperFormat) Or IsEmpty(PaperFormat) Then PaperFormat = &quot;&quot;
1434 If IsMissing(_PrintComponent) Or IsEmpty(_PrintComponent) Then Set _PrintComponent = _Component
1436 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) &apos; Unconditional validation
1437 If Not _IsStillAlive() Then GoTo Finally
1438 If VarType(Printer) = V_STRING Then
1439 vPrinters = ScriptForge.SF_Platform.Printers
1440 If Len(Printer) &gt; 0 Then
1441 If Not ScriptForge.SF_Utils._Validate(Printer, &quot;Printer&quot;, V_STRING, vPrinters, True) Then GoTo Finally
1442 End If
1443 Else
1444 If Not ScriptForge.SF_Utils._Validate(Printer, &quot;Printer&quot;, V_STRING) Then GoTo Finally &apos; Manage here the VarType error
1445 End If
1446 If VarType(Orientation) = V_STRING Then
1447 vOrientations = Array(&quot;PORTRAIT&quot;, &quot;LANDSCAPE&quot;)
1448 If Len(Orientation) &gt; 0 Then
1449 If Not ScriptForge.SF_Utils._Validate(Orientation, &quot;Orientation&quot;, V_STRING, vOrientations) Then GoTo Finally
1450 End If
1451 Else
1452 If Not ScriptForge.SF_Utils._Validate(Orientation, &quot;Orientation&quot;, V_STRING) Then GoTo Finally
1453 End If
1454 If VarType(PaperFormat) = V_STRING Then
1455 vPaperFormats = Array(&quot;A3&quot;, &quot;A4&quot;, &quot;A5&quot;, &quot;B4&quot;, &quot;B5&quot;, &quot;LETTER&quot;, &quot;LEGAL&quot;, &quot;TABLOID&quot;)
1456 If Len(PaperFormat) &gt; 0 Then
1457 If Not ScriptForge.SF_Utils._Validate(PaperFormat, &quot;PaperFormat&quot;, V_STRING, vPaperFormats) Then GoTo Finally
1458 End If
1459 Else
1460 If Not ScriptForge.SF_Utils._Validate(PaperFormat, &quot;PaperFormat&quot;, V_STRING) Then GoTo Finally
1461 End If
1463 Try:
1464 With _PrintComponent
1465 Set oPropertyValue = ScriptForge.SF_Utils._MakePropertyValue(&quot;Name&quot;, Iif(Len(Printer) &gt; 0, Printer, vPrinters(0)))
1466 vPrinterSettings = Array(oPropertyValue)
1467 If Len(Orientation) &gt; 0 Then
1468 vPrinterSettings = ScriptForge.SF_Utils._SetPropertyValue(vPrinterSettings, &quot;PaperOrientation&quot; _
1469 , ScriptForge.SF_Array.IndexOf(vOrientations, Orientation, CaseSensitive := False))
1470 End If
1471 If Len(PaperFormat) &gt; 0 Then
1472 vPrinterSettings = ScriptForge.SF_Utils._SetPropertyValue(vPrinterSettings, &quot;PaperFormat&quot; _
1473 , ScriptForge.SF_Array.IndexOf(vPaperFormats, PaperFormat, CaseSensitive := False))
1474 End If
1475 .setPrinter(vPrinterSettings)
1476 End With
1477 bPrinter = True
1479 Finally:
1480 SetPrinter = bPrinter
1481 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1482 Exit Function
1483 Catch:
1484 GoTo Finally
1485 End Function &apos; SFDocuments.SF_Document.SetPrinter
1487 REM -----------------------------------------------------------------------------
1488 Private Function SetProperty(Optional ByVal psProperty As String _
1489 , Optional ByVal pvValue As Variant _
1490 ) As Boolean
1491 &apos;&apos;&apos; Set the new value of the named property
1492 &apos;&apos;&apos; Args:
1493 &apos;&apos;&apos; psProperty: the name of the property
1494 &apos;&apos;&apos; pvValue: the new value of the given property
1495 &apos;&apos;&apos; Returns:
1496 &apos;&apos;&apos; True if successful
1498 Dim bSet As Boolean &apos; Return value
1499 Static oSession As Object &apos; Alias of SF_Session
1500 Dim cstThisSub As String
1501 Const cstSubArgs = &quot;Value&quot;
1503 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1504 bSet = False
1506 cstThisSub = &quot;SFDocuments.Document.set&quot; &amp; psProperty
1507 If IsMissing(pvValue) Then pvValue = Empty
1508 &apos;ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) &apos; Validation done in Property Lets
1510 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
1511 bSet = True
1512 Select Case UCase(psProperty)
1513 Case UCase(&quot;CustomProperties&quot;)
1514 CustomProperties = pvValue
1515 Case UCase(&quot;Description&quot;)
1516 Description = pvValue
1517 Case UCase(&quot;Keywords&quot;)
1518 Keywords = pvValue
1519 Case UCase(&quot;Subject&quot;)
1520 Subject = pvValue
1521 Case UCase(&quot;Title&quot;)
1522 Title = pvValue
1523 Case Else
1524 bSet = False
1525 End Select
1527 Finally:
1528 SetProperty = bSet
1529 &apos;ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1530 Exit Function
1531 Catch:
1532 GoTo Finally
1533 End Function &apos; SFDocuments.SF_Document.SetProperty
1535 REM -----------------------------------------------------------------------------
1536 Public Function Styles(Optional ByVal Family As Variant _
1537 , Optional ByVal NamePattern As variant _
1538 , Optional ByVal Used As variant _
1539 , Optional ByVal UserDefined As Variant _
1540 , Optional ByVal ParentStyle As Variant _
1541 , Optional ByVal Category As Variant _
1542 ) As Variant
1543 &apos;&apos;&apos; Returns an array of style names matching the filters given in argument
1544 &apos;&apos;&apos; Args:
1545 &apos;&apos;&apos; Family: one of the style families present in the actual document, as a case-sensitive string
1546 &apos;&apos;&apos; NamePattern: a filter on the style names, as a case-sensitive string pattern
1547 &apos;&apos;&apos; Admitted wildcard are: the &quot;?&quot; represents any single character
1548 &apos;&apos;&apos; the &quot;*&quot; represents zero, one, or multiple characters
1549 &apos;&apos;&apos; The names include the internal and localized names.
1550 &apos;&apos;&apos; Used: when True, the style must be used in the document
1551 &apos;&apos;&apos; When absent, the argument is ignored.
1552 &apos;&apos;&apos; UserDefined: when True, the style must have been added by the user, either in the document or its template
1553 &apos;&apos;&apos; When absent, the argument is ignored.
1554 &apos;&apos;&apos; ParentStyle: when present, only the children of the given, localized or not, parent style name are retained
1555 &apos;&apos;&apos; Category: a case-insensitive string: TEXT, CHAPTER, LIST, INDEX, EXTRA, HTML
1556 &apos;&apos;&apos; For their respective meanings, read https://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1style_1_1ParagraphStyleCategory.html
1557 &apos;&apos;&apos; The argument is ignored when the Family is not = &quot;ParagraphStyles&quot;.
1558 &apos;&apos;&apos; Returns:
1559 &apos;&apos;&apos; An array of style localized names
1560 &apos;&apos;&apos; An error is raised when the Family does not exist.
1561 &apos;&apos;&apos; The returned array may be empty.
1562 &apos;&apos;&apos; Example:
1563 &apos;&apos;&apos; Dim vStyles As Variant
1564 &apos;&apos;&apos; vStyles = doc.Styles(&quot;ParagraphStyles&quot;) &apos; All styles in the family
1565 &apos;&apos;&apos; vStyles = doc.Styles(&quot;ParagraphStyles&quot;, &quot;H*&quot;) &apos; Heading, Heading 1, ...
1566 &apos;&apos;&apos; vStyles = doc.Styles(&quot;ParagraphStyles&quot;, Used := False, UserDefined := True)
1567 &apos;&apos;&apos; &apos; All user-defined styles that are not used
1568 &apos;&apos;&apos; vStyles = doc.Styles(&quot;ParagraphStyles&quot;, ParentStyle := &quot;Standard&quot;)
1569 &apos;&apos;&apos; &apos; All styles derived from the &quot;Default Paragraph Style&quot;
1571 Dim vStyles As Variant &apos; Return value
1572 Dim sStyle As String &apos; A single style name
1573 Dim oFamily As Object &apos; Style names container
1574 Dim oStyle As Object &apos; _StyleDescriptor
1575 Dim oParentStyle As Object &apos; _StyleDescriptor
1576 Dim bValid As Boolean &apos; When True, a given style passes the filter
1577 Dim i As Integer
1578 Const cstCategories = &quot;TEXT,CHAPTER,LIST,INDEX,EXTRA,HTML&quot;
1580 Const cstThisSub = &quot;SFDocuments.Document.Styles&quot;
1581 Const cstSubArgs = &quot;Family, [NamePattern=&quot;&quot;*&quot;&quot;], [Used=True|False], [UserDefined=True|False], ParentStyle = &quot;&quot;&quot;&quot;&quot; _
1582 &amp; &quot;, [Category=&quot;&quot;&quot;&quot;|&quot;&quot;TEXT&quot;&quot;|&quot;&quot;CHAPTER&quot;&quot;|&quot;&quot;LIST&quot;&quot;|&quot;&quot;INDEX&quot;&quot;|&quot;&quot;EXTRA&quot;&quot;|&quot;&quot;HTML&quot;&quot;]&quot;
1584 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1585 vStyles = Array()
1587 Check:
1588 If IsMissing(NamePattern) Or IsEmpty(NamePattern) Then NamePattern = &quot;&quot;
1589 If IsMissing(Used) Then Used = Empty
1590 If IsMissing(UserDefined) Then UserDefined = Empty
1591 If IsMissing(ParentStyle) Or IsEmpty(ParentStyle) Then ParentStyle = &quot;&quot;
1592 If IsMissing(Category) Or IsEmpty(Category) Then Category = &quot;&quot;
1593 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1594 If Not _IsStillAlive() Then GoTo Finally
1595 If UBound(_StyleFamilies) &lt; 0 Then _StyleFamilies = _Component.getStyleFamilies().getElementNames()
1596 If Not ScriptForge.SF_Utils._Validate(Family, &quot;Family&quot;, V_STRING, _StyleFamilies) Then GoTo Finally
1597 If Not ScriptForge.SF_Utils._Validate(NamePattern, &quot;NamePattern&quot;, V_STRING) Then GoTo Finally
1598 If Not IsEmpty(Used) Then
1599 If Not ScriptForge.SF_Utils._Validate(Used, &quot;Used&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
1600 End If
1601 If Not IsEmpty(UserDefined) Then
1602 If Not ScriptForge.SF_Utils._Validate(UserDefined, &quot;UserDefined&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
1603 End If
1604 If Not ScriptForge.SF_Utils._Validate(ParentStyle, &quot;ParentStyle&quot;, V_STRING) Then GoTo Finally
1605 If Not ScriptForge.SF_Utils._Validate(Category, &quot;Category&quot;, V_STRING, Split(&quot;,&quot; &amp; cstCategories, &quot;,&quot;)) Then GoTo Finally
1606 End If
1608 Try:
1609 Set oFamily = _GetStyleFamily(Family)
1610 If Not IsNull(oFamily) Then
1611 &apos; Load it with the complete list of styles in the family
1612 vStyles = oFamily.getElementNames()
1613 &apos; Scan the list and retain those passing the filter
1614 For i = 0 To UBound(vStyles)
1615 sStyle = vStyles(i)
1616 Set oStyle = _GetStyle(oFamily, sStyle)
1617 If Not IsNull(oStyle) Then
1618 With oStyle
1619 &apos; Pattern ?
1620 bValid = ( Len(NamePattern) = 0 )
1621 If Not bValid Then bValid = ScriptForge.SF_String.IsLike(.DisplayName, NamePattern, CaseSensitive := True)
1622 &apos; Used ?
1623 If bValid And Not IsEmpty(Used) Then bValid = ( Used = .IsUsed )
1624 &apos; User defined ?
1625 If bValid And Not IsEmpty(UserDefined) Then bValid = ( UserDefined = Not .BuiltIn )
1626 &apos; Parent style ?
1627 If bValid And Len(ParentStyle) &gt; 0 Then
1628 Set oParentStyle = _GetStyle(oFamily, .ParentStyle)
1629 bValid = Not IsNull(oParentStyle) &apos; The child has a parent
1630 If bValid Then bValid = ( ParentStyle = oParentStyle.DisplayName Or ParentStyle = oParentStyle.StyleName)
1631 End If
1632 &apos; Category ?
1633 If bValid And Len(Category) &gt; 0 Then bValid = ( UCase(Category) = .Category )
1634 If bValid Then vStyles(i) = .DisplayName Else vStyles(i) = &quot;&quot;
1635 End With
1636 Else
1637 vStyles(i) = &quot;&quot;
1638 End If
1639 Next i
1640 &apos; Reject when not valid
1641 vStyles = ScriptForge.SF_Array.TrimArray(vStyles)
1642 End If
1644 Finally:
1645 Styles = vStyles
1646 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1647 Exit Function
1648 Catch:
1649 GoTo Finally
1650 End Function &apos; SFDocuments.SF_Document.Styles
1652 REM -----------------------------------------------------------------------------
1653 Public Function Toolbars(Optional ByVal ToolbarName As Variant) As Variant
1654 &apos;&apos;&apos; Returns either a list of the available toolbar names in the actual document
1655 &apos;&apos;&apos; or a Toolbar object instance.
1656 &apos;&apos;&apos; Args:
1657 &apos;&apos;&apos; ToolbarName: the usual name of one of the available toolbars
1658 &apos;&apos;&apos; Returns:
1659 &apos;&apos;&apos; A zero-based array of toolbar names when the argument is absent,
1660 &apos;&apos;&apos; or a new Toolbar object instance from the SF_Widgets library.
1662 Const cstThisSub = &quot;SFDocuments.Document.Toolbars&quot;
1663 Const cstSubArgs = &quot;[ToolbarName=&quot;&quot;&quot;&quot;]&quot;
1665 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1667 Check:
1668 If IsMissing(ToolbarName) Or IsEmpty(ToolbarName) Then ToolbarName = &quot;&quot;
1669 If IsNull(_Toolbars) Then _Toolbars = ScriptForge.SF_UI._ListToolbars(_Component)
1670 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1671 If Not _IsStillAlive() Then GoTo Finally
1672 If VarType(ToolbarName) = V_STRING Then
1673 If Len(ToolbarName) &gt; 0 Then
1674 If Not ScriptForge.SF_Utils._Validate(ToolbarName, &quot;ToolbarName&quot;, V_STRING, _Toolbars.Keys()) Then GoTo Finally
1675 End If
1676 Else
1677 If Not ScriptForge.SF_Utils._Validate(ToolbarName, &quot;ToolbarName&quot;, V_STRING) Then GoTo Finally &apos; Manage here the VarType error
1678 End If
1679 End If
1681 Try:
1682 If Len(ToolbarName) = 0 Then
1683 Toolbars = _Toolbars.Keys()
1684 Else
1685 Toolbars = CreateScriptService(&quot;SFWidgets.Toolbar&quot;, _Toolbars.Item(ToolbarName))
1686 End If
1688 Finally:
1689 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1690 Exit Function
1691 Catch:
1692 GoTo Finally
1693 End Function &apos; SFDocuments.SF_Document.Toolbars
1695 REM -----------------------------------------------------------------------------
1696 Public Function XStyle(Optional ByVal Family As Variant _
1697 , Optional ByVal StyleName As variant _
1698 ) As Object
1699 &apos;&apos;&apos; Returns a com.sun.star.style.Style UNO object corresponding with the arguments
1700 &apos;&apos;&apos; Args:
1701 &apos;&apos;&apos; Family: one of the style families present in the actual document, as a not case-sensitive string
1702 &apos;&apos;&apos; StyleName: one of the styles present in the given family, as a case-sensitive string
1703 &apos;&apos;&apos; The StyleName may be localized or not.
1704 &apos;&apos;&apos; Returns:
1705 &apos;&apos;&apos; A com.sun.star.style.XStyle UNO object or one of its descendants,
1706 &apos;&apos;&apos; like com.sun.star.style.CellStyle or com.sun.star.style.ParagraphStyle etc.
1707 &apos;&apos;&apos; An error is raised when the Family does not exist.
1708 &apos;&apos;&apos; Nothing is returned when the StyleName does not exist in the given Family.
1709 &apos;&apos;&apos; Example:
1710 &apos;&apos;&apos; Dim oStyle As Object
1711 &apos;&apos;&apos; Set oStyle = doc.XStyle(&quot;ParagraphStyle&quot;, &quot;Heading 2&quot;)
1713 Dim oXStyle As Object &apos; Return value
1714 Dim oFamily As Object &apos; Style names container
1716 Const cstThisSub = &quot;SFDocuments.Document.XStyle&quot;
1717 Const cstSubArgs = &quot;Family, StyleName&quot;
1719 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1720 Set oXStyle = Nothing
1722 Check:
1723 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1724 If Not _IsStillAlive() Then GoTo Finally
1725 If UBound(_StyleFamilies) &lt; 0 Then _StyleFamilies = _Component.getStyleFamilies().getElementNames()
1726 If Not ScriptForge.SF_Utils._Validate(Family, &quot;Family&quot;, V_STRING, _StyleFamilies) Then GoTo Finally
1727 If Not ScriptForge.SF_Utils._Validate(StyleName, &quot;StyleName&quot;, V_STRING) Then GoTo Finally
1728 End If
1730 Try:
1731 Set oFamily = _GetStyleFamily(Family)
1732 If Not IsNull(oFamily) Then
1733 If oFamily.hasByName(StyleName) Then Set oXStyle = oFamily.getByName(StyleName)
1734 End If
1736 Finally:
1737 Set XStyle = oXStyle
1738 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1739 Exit Function
1740 Catch:
1741 GoTo Finally
1742 End Function &apos; SFDocuments.SF_Document.XStyle
1744 REM =========================================================== PRIVATE FUNCTIONS
1746 REM -----------------------------------------------------------------------------
1747 Private Function _FileIdent() As String
1748 &apos;&apos;&apos; Returns a file identification from the information that is currently available
1749 &apos;&apos;&apos; Useful e.g. for display in error messages
1751 &apos; OS notation is used to avoid presence of &quot;%nn&quot; in error messages and wrong parameter substitutions
1752 _FileIdent = Iif(Len(_WindowFileName) &gt; 0, ConvertFromUrl(_WindowFileName), _WindowTitle)
1754 End Function &apos; SFDocuments.SF_Document._FileIdent
1756 REM -----------------------------------------------------------------------------
1757 Private Function _GetFilterNames(ByVal pbExport As Boolean) As Variant
1758 &apos;&apos;&apos; Returns the list of export (pbExport = True) or import filters
1759 &apos;&apos;&apos; applicable to the current document
1760 &apos;&apos;&apos; Args:
1761 &apos;&apos;&apos; pbExport: True for export, False for import
1762 &apos;&apos;&apos; Returns:
1763 &apos;&apos;&apos; A zero-based array of strings
1765 Dim vFilters As Variant &apos; Return value
1766 Dim sIdentifier As String &apos; Document service, like com.sun.star.text.TextDocument
1767 Dim oFilterFactory As Object &apos; com.sun.star.document.FilterFactory
1768 Dim vAllFilters As Variant &apos; The full list of installed filters
1769 Dim sFilter As String &apos; A single filter name
1770 Dim iCount As Integer &apos; Filters counter
1771 Dim vFilter As Variant &apos; A filter descriptor as an array of Name/Value pairs
1772 Dim sType As String &apos; The filter type to be compared with the document service
1773 Dim lFlags As Long &apos; Read https://wiki.documentfoundation.org/Documentation/DevGuide/Office_Development#Properties_of_a_Filter
1774 Dim bExport As Boolean &apos; Filter valid for export when True
1775 Dim bImport As Boolean &apos; Filter valid for import when True
1776 Dim bImportExport As Boolean &apos; Filter valid both for import and export when True
1778 vFilters = Array()
1779 On Local Error GoTo Finally &apos; Return empty or partial list if error
1781 Try:
1782 sIdentifier = _Component.Identifier
1783 Set oFilterFactory = ScriptForge.SF_Utils._GetUNOService(&quot;FilterFactory&quot;)
1784 vAllFilters = oFilterFactory.getElementNames()
1785 ReDim vFilters(0 To UBound(vAllFilters))
1786 iCount = -1
1788 For Each sFilter In vAllFilters
1789 vFilter = oFilterFactory.getByName(sFilter)
1790 sType = ScriptForge.SF_Utils._GetPropertyValue(vFilter, &quot;DocumentService&quot;)
1791 If sType = sIdentifier Then
1792 lFlags = ScriptForge.SF_Utils._GetPropertyValue(vFilter, &quot;Flags&quot;)
1793 &apos; export: flag is even
1794 &apos; import: flag is odd and flag/2 is even
1795 &apos; import/export: flag is odd and flag/2 is odd
1796 bExport = ( lFlags Mod 2 = 0 )
1797 bImport = ( (lFlags Mod 2 = 1) And ((lFlags \ 2) Mod 2 = 0) )
1798 bImportExport = ( (lFlags Mod 2 = 1) And ((lFlags \ 2) Mod 2 = 1) )
1799 &apos; Select filter ?
1800 If bImportExport _
1801 Or (pbExport And bExport) _
1802 Or (Not pbExport And bImport) Then
1803 iCount = iCount + 1
1804 vFilters(iCount) = sFilter
1805 End If
1806 End If
1807 Next sFilter
1809 If iCount &gt; -1 Then
1810 ReDim Preserve vFilters(0 To iCount)
1811 End If
1813 Finally:
1814 _GetFilterNames = vFilters
1815 Exit Function
1816 End Function &apos; SFDocuments.SF_Document._GetFilterNames
1818 REM -----------------------------------------------------------------------------
1819 Private Function _GetStyle(ByRef poFamily As Object _
1820 , Optional ByVal pvDisplayName As Variant _
1821 , Optional ByVal pvStyleIndex As Variant _
1822 ) As Object
1823 &apos;&apos;&apos; Returns the style descriptor of the style passed as argument in the given family
1824 &apos;&apos;&apos; Args:
1825 &apos;&apos;&apos; poFamily: a com.sun.star.container.XNameContainer/XStyleFamily object
1826 &apos;&apos;&apos; pvDisplayName: case-sensitive string, localized style name as visible in the user interface
1827 &apos;&apos;&apos; pvStyleIndex: index of the style in the family, as an integer
1828 &apos;&apos;&apos; Exactly 1 out of the last 2 arguments must be supplied
1829 &apos;&apos;&apos; Returns:
1830 &apos;&apos;&apos; A StyleDescriptor object or Nothing
1832 Dim oStyleDescriptor &apos; Return value
1833 Dim oStyle As Object &apos; com.sun.star.style.XStyle and variants
1834 Dim bFound As Boolean &apos; When True, the style has been found in the family
1835 Dim vCategories As Variant &apos; Array of category constants
1836 Dim iCategory As Integer &apos; Index of vCategories
1837 Dim oSession As Object : Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
1838 Dim i As Integer
1840 Const cstCAT0 = &quot;TEXT&quot; &apos; is applied to styles that are used for common text
1841 Const cstCAT1 = &quot;CHAPTER&quot; &apos; is applied to styles that are used as headings
1842 Const cstCAT2 = &quot;LIST&quot; &apos; is applied to styles that are used in numberings and lists
1843 Const cstCAT3 = &quot;INDEX&quot; &apos; is applied to styles that are used in indexes
1844 Const cstCAT4 = &quot;EXTRA&quot; &apos; is applied to styles that are used in special regions like headers, footers, and footnote text
1845 Const cstCAT5 = &quot;HTML&quot; &apos; is applied to styles that are used to support HTML
1846 Const cstCAT = cstCAT0 &amp; &quot;,&quot; &amp; cstCAT1 &amp; &quot;,&quot; &amp; cstCAT2 &amp; &quot;,&quot; &amp; cstCAT3 &amp; &quot;,&quot; &amp; cstCAT4 &amp; &quot;,&quot; &amp; cstCAT5
1848 On Local Error GoTo Catch
1849 Set oStyleDescriptor = Nothing
1851 Check:
1852 If IsNull(poFamily) Then GoTo Catch
1853 If IsMissing(pvDisplayName) Or IsEmpty(pvDisplayName) Then pvDisplayName = &quot;&quot;
1854 If IsMissing(pvStyleIndex) Or IsEmpty(pvStyleIndex) Then pvStyleIndex = -1
1855 Try:
1856 &apos; Find style corresponding with the given display name
1857 With poFamily
1858 If Len(pvDisplayName) &gt; 0 Then
1859 bFound = .hasByName(pvDisplayName) &apos; hasByName searches both for Name and DisplayName attributes here
1860 If bFound Then Set oStyle = .getByName(pvDisplayName) Else GoTo Catch
1861 ElseIf pvStyleIndex &gt;= 0 And pvStyleIndex &lt; .Count Then
1862 Set oStyle = .getByIndex(pvStyleIndex)
1863 Else
1864 GoTo Catch &apos; Should not happen
1865 End If
1866 End With
1868 &apos; Setup the style descriptor
1869 Set oStyleDescriptor = New StyleDescriptor
1870 With oStyleDescriptor
1871 Set .Family = poFamily
1872 .StyleName = oStyle.Name
1873 .DisplayName = oStyle.DisplayName
1874 .IsUsed = oStyle.isInUse
1875 .BuiltIn = Not oStyle.isUserDefined()
1876 .Category = &quot;&quot;
1877 If oSession.HasUnoProperty(oStyle, &quot;Category&quot;) Then
1878 vCategories = Split(cstCAT, &quot;,&quot;)
1879 iCategory = oStyle.Category
1880 If iCategory &gt;= 0 And iCategory &lt;= UBound(vCategories) Then .Category = vCategories(iCategory)
1881 End If
1882 .ParentStyle = oStyle.ParentStyle
1883 Set .XStyle = oStyle
1884 End With
1886 Finally:
1887 Set _GetStyle = oStyleDescriptor
1888 Exit Function
1889 Catch:
1890 Set oStyleDescriptor = Nothing
1891 GoTo Finally
1892 End Function &apos; SFDocuments.SF_Document._GetStyle
1894 REM -----------------------------------------------------------------------------
1895 Private Function _GetStyleFamily(ByVal psFamilyName As String) As Object
1896 &apos;&apos;&apos; Returns the style names container corresponding with the argument
1897 &apos;&apos;&apos; Args:
1898 &apos;&apos;&apos; psFamilyName: CellStyles, CharacterStyles, FrameStyles, GraphicsStyles, ListStyles,
1899 &apos;&apos;&apos; NumberingStyles, PageStyles, ParagraphStyles, TableStyles
1900 &apos;&apos;&apos; Returns:
1901 &apos;&apos;&apos; A com.sun.star.container.XNameContainer/XStyleFamily object or Nothing
1903 Dim oFamily As Object &apos; Return value
1904 Dim oFamilies As Object &apos; com.sun.star.container.XNameAccess
1905 Dim iIndex As Integer &apos; Index in vFamilies of the given argument
1907 On Local Error GoTo Catch
1908 Set oFamily = Nothing
1910 Try:
1911 Set oFamilies = _Component.getStyleFamilies()
1912 If UBound(_StyleFamilies) &lt; 0 Then _StyleFamilies = oFamilies.getElementNames()
1913 &apos; oFamilies.hasByName()/getByName() not used here to admit not case-sensitive family names
1914 iIndex = ScriptForge.SF_Array.IndexOf(_StyleFamilies, psFamilyName, CaseSensitive := False)
1915 If iIndex &gt;= 0 Then Set oFamily = oFamilies.getByName(_StyleFamilies(iIndex))
1917 Finally:
1918 Set _GetStyleFamily = oFamily
1919 Exit Function
1920 Catch:
1921 Set oFamily = Nothing
1922 GoTo Finally
1923 End Function &apos; SFDocuments.SF_Document._GetStyleFamily
1925 REM -----------------------------------------------------------------------------
1926 Public Sub _ImportStylesFromFile(Optional FileName As Variant _
1927 , Optional ByRef Families As Variant _
1928 , Optional ByVal Overwrite As variant _
1929 ) As Variant
1930 &apos;&apos;&apos; Load all the styles belonging to one or more style families from a closed file
1931 &apos;&apos;&apos; into the actual document. The actual document must be a Calc or a Writer document.
1932 &apos;&apos;&apos; Are always imported together:
1933 &apos;&apos;&apos; ParagraphStyles and CharacterStyles
1934 &apos;&apos;&apos; NumberingStyles and ListStyles
1935 &apos;&apos;&apos; Args:
1936 &apos;&apos;&apos; FileName: the file from which to load the styles in the FileSystem notation.
1937 &apos;&apos;&apos; The file is presumed to be of the same document type as the actual document
1938 &apos;&apos;&apos; Families: one of the style families present in the actual document, as a case-sensitive string
1939 &apos;&apos;&apos; or an array of such strings. Default = all families
1940 &apos;&apos;&apos; Overwrite: when True, the actual styles may be overwritten. Default = False
1941 &apos;&apos;&apos; Returns:
1942 &apos;&apos;&apos; Exceptions:
1943 &apos;&apos;&apos; UNKNOWNFILEERROR The given file name does not exist
1944 &apos;&apos;&apos; Example:
1945 &apos;&apos;&apos; oDoc.ImportStylesFromFile(&quot;C:\...\abc.odt&quot;, Families := &quot;ParagraphStyles&quot;, Overwrite := True)
1947 Dim vFamilies As Variant &apos; Alias of Families
1948 Dim oFamilies As Object &apos; com.sun.star.container.XNameAccess
1949 Dim vOptions As Variant &apos; Array of property values
1950 Dim bAll As Boolean &apos; When True, ALL style families are considered
1951 Dim sName As String &apos; A single name in vOptions
1952 Dim FSO As Object : Set FSO = ScriptForge.SF_FileSystem
1953 Dim i As Integer
1954 Const cstThisSub = &quot;SFDocuments.Document.ImportStylesFromFile&quot;
1955 Const cstSubArgs = &quot;FileName, [Families], [Overwrite=False]&quot;
1957 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1959 Check:
1960 If IsMissing(Families) Or IsEmpty(Families) Then Families = &quot;&quot;
1961 If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False
1963 Set oFamilies = _Component.getStyleFamilies()
1964 If UBound(_StyleFamilies) &lt; 0 Then _StyleFamilies = oFamilies.getElementNames()
1966 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1967 If Not _IsStillAlive() Then GoTo Finally
1968 If Not ScriptForge.SF_Utils._ValidateFile(FileName, &quot;FileName&quot;, False) Then GoTo Finally
1969 If IsArray(Families) Then
1970 If Not ScriptForge.SF_Utils._ValidateArray(Families, &quot;Families&quot;, 1, V_STRING, True) Then GoTo Finally
1971 Else
1972 If Not ScriptForge.SF_Utils._Validate(Families, &quot;Families&quot;, V_STRING, ScriptForge.SF_Array.Append(_StyleFamilies, &quot;&quot;)) Then GoTo Finally
1973 End If
1974 If Not ScriptForge.SF_Utils._Validate(Overwrite, &quot;Overwrite&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
1975 End If
1977 If Not FSO.FileExists(FileName) Then GoTo CatchNotExists
1978 If IsArray(Families) Then
1979 vFamilies = Families
1980 Else
1981 bAll = ( Len(Families) = 0 ) &apos; When Families is absent (= &quot;&quot;), all families should be considered
1982 vFamilies = Array(Families)
1983 End If
1985 Try:
1986 With ScriptForge.SF_Utils
1987 Set vOptions = _Component.getStyleFamilies().getStyleLoaderOptions
1988 &apos; By default, all style families are imported (True)
1989 If Not bAll Then
1990 For i = 0 To UBound(vOptions)
1991 vOptions(i).Value = False
1992 Next i
1993 For i = LBound(vFamilies) To UBound(vFamilies)
1994 Select Case UCase(vFamilies(i))
1995 Case &quot;PARAGRAPHSTYLES&quot;, &quot;CHARACTERSTYLES&quot; : sName = &quot;TextStyles&quot;
1996 Case &quot;FRAMESTYLES&quot; : sName = &quot;FrameStyles&quot;
1997 Case &quot;PAGESTYLES&quot; : sName = &quot;PageStyles&quot;
1998 Case &quot;NUMBERINGSTYLES&quot;, &quot;LISTSTYLES&quot; : sName = &quot;NumberingStyles&quot;
1999 Case &quot;CELLSTYLES&quot; : sName = &quot;PageStyles&quot;
2000 Case Else : sName = &quot;&quot;
2001 End Select
2002 If Len(sName) &gt; 0 Then Set vOptions = ._SetPropertyValue(vOptions, &quot;Load&quot; &amp; sName, True)
2003 Next i
2004 End If
2005 vOptions = ._SetPropertyValue(vOptions, &quot;OverwriteStyles&quot;, Overwrite)
2006 End With
2008 &apos; Finally, import
2009 oFamilies.loadStylesFromURL(FSO._ConvertToUrl(FileName), vOptions)
2011 Finally:
2012 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
2013 Exit Sub
2014 Catch:
2015 GoTo Finally
2016 CatchNotExists:
2017 SF_Exception.RaiseFatal(UNKNOWNFILEERROR, &quot;FileName&quot;, FileName)
2018 GoTo Finally
2019 End Sub &apos; SFDocuments.SF_Document._ImportStylesFromFile
2021 REM -----------------------------------------------------------------------------
2022 Private Function _IsStillAlive(Optional ByVal pbForUpdate As Boolean _
2023 , Optional ByVal pbError As Boolean _
2024 ) As Boolean
2025 &apos;&apos;&apos; Returns True if the document has not been closed manually or incidentally since the last use
2026 &apos;&apos;&apos; If dead the actual instance is disposed. The execution is cancelled when pbError = True (default)
2027 &apos;&apos;&apos; Args:
2028 &apos;&apos;&apos; pbForUpdate: if True (default = False), check additionally if document is open for editing
2029 &apos;&apos;&apos; pbError: if True (default), raise a fatal error
2031 Dim bAlive As Boolean &apos; Return value
2032 Dim sFileName As String &apos; File identification used to display error message
2034 On Local Error GoTo Catch &apos; Anticipate DisposedException errors or alike
2035 If IsMissing(pbForUpdate) Then pbForUpdate = False
2036 If IsMissing(pbError) Then pbError = True
2038 Try:
2039 &apos; Check existence of document
2040 bAlive = Not IsNull(_Frame)
2041 If bAlive Then bAlive = Not IsNull(_Component)
2042 If bAlive Then bAlive = Not IsNull(_Component.CurrentController)
2044 &apos; Check document is not read only
2045 If bAlive And pbForUpdate Then
2046 If _Component.isreadonly() Then GoTo CatchReadonly
2047 End If
2049 Finally:
2050 _IsStillAlive = bAlive
2051 Exit Function
2052 Catch:
2053 bAlive = False
2054 On Error GoTo 0
2055 sFileName = _FileIdent()
2056 Dispose()
2057 If pbError Then ScriptForge.SF_Exception.RaiseFatal(DOCUMENTDEADERROR, sFileName)
2058 GoTo Finally
2059 CatchReadonly:
2060 bAlive = False
2061 If pbError Then ScriptForge.SF_Exception.RaiseFatal(DOCUMENTREADONLYERROR, &quot;Document&quot;, _FileIdent())
2062 GoTo Finally
2063 End Function &apos; SFDocuments.SF_Document._IsStillAlive
2065 REM -----------------------------------------------------------------------------
2066 Private Function _ListContextMenus() As Variant
2067 &apos;&apos;&apos; Returns an array of the usual names of the context menus available in the current document
2069 Dim vMenus As Variant &apos; Return value
2070 Dim vMenusObj As Variant &apos; Array of arrays of property values
2071 Dim oSupplier As Object &apos; /singletons/com.sun.star.ui.theModuleUIConfigurationManagerSupplier
2072 Dim sComponentType As String &apos; Argument to determine the system config manager, ex. &quot;com.sun.star.text.TextDocument&quot;
2073 Dim oUIConf As Object &apos; com.sun.star.ui.XUIConfigurationManager
2074 Dim i As Long
2076 On Local Error GoTo Catch
2077 vMenus = Array()
2079 Try:
2080 Set oSupplier = ScriptForge.SF_Utils._GetUNOService(&quot;ModuleUIConfigurationManagerSupplier&quot;)
2081 sComponentType = ScriptForge.SF_UI._GetConfigurationManager(_Component)
2082 Set oUIConf = oSupplier.getUIConfigurationManager(sComponentType)
2084 &apos; Discard menubar, statusbar, ...
2085 vMenusObj = oUIConf.getUIElementsInfo(com.sun.star.ui.UIElementType.POPUPMENU)
2087 &apos; Extract and sort the names
2088 ReDim vMenus(0 To UBound(vMenusObj))
2089 For i = 0 To UBound(vMenusObj)
2090 vMenus(i) = Mid(vMenusObj(i)(0).Value, Len(&quot;private:resource/popupmenu/&quot;) + 1)
2091 Next i
2092 vMenus = ScriptForge.SF_Array.Unique(vMenus, CaseSensitive := True)
2094 Finally:
2095 _ListContextMenus = vMenus
2096 Exit Function
2097 Catch:
2098 On Local Error GoTo 0
2099 GoTo Finally
2100 End Function &apos; SFDocuments.SF_Document._ListContextMenus
2102 REM -----------------------------------------------------------------------------
2103 Private Sub _LoadDocumentProperties()
2104 &apos;&apos;&apos; Create dictionary with document properties as entries / Custom properties are excluded
2105 &apos;&apos;&apos; Document is presumed still alive
2106 &apos;&apos;&apos; Special values:
2107 &apos;&apos;&apos; Only valid dates are taken
2108 &apos;&apos;&apos; Statistics are exploded in subitems. Subitems are specific to document type
2109 &apos;&apos;&apos; Keywords are joined
2110 &apos;&apos;&apos; Language is aligned on L10N convention la-CO
2112 Dim oProperties As Object &apos; Document properties
2113 Dim vNamedValue As Variant &apos; com.sun.star.beans.NamedValue
2115 If IsNull(_DocumentProperties) Then
2116 Set oProperties = _Component.getDocumentProperties
2117 Set _DocumentProperties = CreateScriptService(&quot;Dictionary&quot;)
2118 With _DocumentProperties
2119 .Add(&quot;Author&quot;, oProperties.Author)
2120 .Add(&quot;AutoloadSecs&quot;, oProperties.AutoloadSecs)
2121 .Add(&quot;AutoloadURL&quot;, oProperties.AutoloadURL)
2122 If oProperties.CreationDate.Year &gt; 0 Then .Add(&quot;CreationDate&quot;, CDateFromUnoDateTime(oProperties.CreationDate))
2123 .Add(&quot;DefaultTarget&quot;, oProperties.DefaultTarget)
2124 .Add(&quot;Description&quot;, oProperties.Description) &apos; The description can be multiline
2125 &apos; DocumentStatistics : number and names of statistics depend on document type
2126 For Each vNamedValue In oProperties.DocumentStatistics
2127 .Add(vNamedValue.Name, vNamedValue.Value)
2128 Next vNamedValue
2129 .Add(&quot;EditingDuration&quot;, oProperties.EditingDuration)
2130 .Add(&quot;Generator&quot;, oProperties.Generator)
2131 .Add(&quot;Keywords&quot;, Join(oProperties.Keywords, &quot;, &quot;))
2132 .Add(&quot;Language&quot;, oProperties.Language.Language &amp; Iif(Len(oProperties.Language.Country) &gt; 0, &quot;-&quot; &amp; oProperties.Language.Country, &quot;&quot;))
2133 If oProperties.ModificationDate.Year &gt; 0 Then .Add(&quot;ModificationDate&quot;, CDateFromUnoDateTime(oProperties.ModificationDate))
2134 If oProperties.PrintDate.Year &gt; 0 Then .Add(&quot;PrintDate&quot;, CDateFromUnoDateTime(oProperties.PrintDate))
2135 .Add(&quot;PrintedBy&quot;, oProperties.PrintedBy)
2136 .Add(&quot;Subject&quot;, oProperties.Subject)
2137 If oProperties.TemplateDate.Year &gt; 0 Then .Add(&quot;TemplateDate&quot;, CDateFromUnoDateTime(oProperties.TemplateDate))
2138 .Add(&quot;TemplateName&quot;, oProperties.TemplateName)
2139 .Add(&quot;TemplateURL&quot;, oProperties.TemplateURL)
2140 .Add(&quot;Title&quot;, oProperties.Title)
2141 End With
2142 End If
2144 End Sub &apos; SFDocuments.SF_Document._LoadDocumentProperties
2146 REM -----------------------------------------------------------------------------
2147 Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
2148 &apos;&apos;&apos; Return the value of the named property
2149 &apos;&apos;&apos; Args:
2150 &apos;&apos;&apos; psProperty: the name of the property
2152 Dim oProperties As Object &apos; Document or Custom properties
2153 Dim oTransient As Object &apos; com.sun.star.frame.TransientDocumentsDocumentContentFactory
2154 Dim oContent As Object &apos; com.sun.star.comp.ucb.TransientDocumentsContent
2155 Dim cstThisSub As String
2156 Const cstSubArgs = &quot;&quot;
2158 _PropertyGet = False
2160 Select Case _DocumentType
2161 Case &quot;Base&quot;, &quot;Calc&quot;, &quot;FormDocument&quot;, &quot;Writer&quot;
2162 cstThisSub = &quot;SFDocuments.SF_&quot; &amp; _DocumentType &amp; &quot;.get&quot; &amp; psProperty
2163 Case Else : cstThisSub = &quot;SFDocuments.SF_Document.get&quot; &amp; psProperty
2164 End Select
2165 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
2166 If psProperty &lt;&gt; &quot;IsAlive&quot; Then
2167 If Not _IsStillAlive() Then GoTo Finally
2168 End If
2170 Select Case psProperty
2171 Case &quot;CustomProperties&quot;
2172 _CustomProperties = CreateScriptService(&quot;Dictionary&quot;, True) &apos; Always reload as updates could have been done manually by user
2173 &apos; (with case-sensitive comparison of keys)
2174 _CustomProperties.ImportFromPropertyValues(_Component.getDocumentProperties().UserDefinedProperties.getPropertyValues)
2175 _PropertyGet = _CustomProperties
2176 Case &quot;Description&quot;
2177 _PropertyGet = _Component.DocumentProperties.Description
2178 Case &quot;DocumentProperties&quot;
2179 _LoadDocumentProperties() &apos; Always reload as updates could have been done manually by user
2180 Set _PropertyGet = _DocumentProperties
2181 Case &quot;DocumentType&quot;
2182 _PropertyGet = _DocumentType
2183 Case &quot;ExportFilters&quot;
2184 _PropertyGet = _GetFilterNames(True)
2185 Case &quot;FileSystem&quot;
2186 &apos; Natural choice would have been to use the component.RunTimeUID property
2187 &apos; However it is optional in the OfficeDocument service and not available for Base documents
2188 &apos; Below a more generic alternative derived from the get_document_uri() method found in apso.py
2189 Set oTransient = ScriptForge.SF_Utils._GetUnoService(&quot;TransientDocumentFactory&quot;)
2190 Set oContent = oTransient.createDocumentContent(_Component)
2191 _PropertyGet = oContent.getIdentifier().ContentIdentifier &amp; &quot;/&quot;
2192 Case &quot;ImportFilters&quot;
2193 _PropertyGet = _GetFilterNames(False)
2194 Case &quot;IsAlive&quot;
2195 _PropertyGet = _IsStillAlive(False, False)
2196 Case &quot;IsBase&quot;, &quot;IsCalc&quot;, &quot;IsDraw&quot;, &quot;IsFormDocument&quot;, &quot;IsImpress&quot;, &quot;IsMath&quot;, &quot;IsWriter&quot;
2197 _PropertyGet = ( Mid(psProperty, 3) = _DocumentType )
2198 Case &quot;Keywords&quot;
2199 _PropertyGet = Join(_Component.DocumentProperties.Keywords, &quot;, &quot;)
2200 Case &quot;Readonly&quot;
2201 _PropertyGet = _Component.isReadonly()
2202 Case &quot;StyleFamilies&quot;
2203 If UBound(_StyleFamilies) &lt; 0 Then _StyleFamilies = _Component.getStyleFamilies().getElementNames()
2204 _PropertyGet = _StyleFamilies
2205 Case &quot;Subject&quot;
2206 _PropertyGet = _Component.DocumentProperties.Subject
2207 Case &quot;Title&quot;
2208 _PropertyGet = _Component.DocumentProperties.Title
2209 Case &quot;XComponent&quot;
2210 Set _PropertyGet = _Component
2211 Case &quot;XDocumentSettings&quot;
2212 With _Component
2213 If IsNull(_DocumentSettings) Then
2214 Select Case _DocumentType
2215 Case &quot;Calc&quot; : Set _DocumentSettings = .createInstance(&quot;com.sun.star.sheet.DocumentSettings&quot;)
2216 Case &quot;Draw&quot; : Set _DocumentSettings = .createInstance(&quot;com.sun.star.drawing.DocumentSettings&quot;)
2217 Case &quot;FormDocument&quot;, &quot;Writer&quot;
2218 Set _DocumentSettings = .createInstance(&quot;com.sun.star.text.DocumentSettings&quot;)
2219 Case &quot;Impress&quot; : Set _DocumentSettings = .createInstance(&quot;com.sun.star.presentation.DocumentSettings&quot;)
2220 Case Else : Set _DocumentSettings = Nothing
2221 End Select
2222 End If
2223 Set _PropertyGet = _DocumentSettings
2224 End With
2225 Case Else
2226 _PropertyGet = Null
2227 End Select
2229 Finally:
2230 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
2231 Exit Function
2232 End Function &apos; SFDocuments.SF_Document._PropertyGet
2234 REM -----------------------------------------------------------------------------
2235 Private Function _Repr() As String
2236 &apos;&apos;&apos; Convert the SF_Document instance to a readable string, typically for debugging purposes (DebugPrint ...)
2237 &apos;&apos;&apos; Args:
2238 &apos;&apos;&apos; Return:
2239 &apos;&apos;&apos; &quot;[DOCUMENT]: Type - File&quot;
2241 _Repr = &quot;[Document]: &quot; &amp; _DocumentType &amp; &quot; - &quot; &amp; _FileIdent()
2243 End Function &apos; SFDocuments.SF_Document._Repr
2245 REM ============================================ END OF SFDOCUMENTS.SF_DOCUMENT
2246 </script:module>