tdf#164434 Correct SvgSymbolNode SVG import
[LibreOffice.git] / wizards / source / sfdocuments / SF_Writer.xba
blob38767666300eeb4d5ecc0a1f8fe4e8a774d5da3d
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_Writer" 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_Writer
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 SF_Document module.
22 &apos;&apos;&apos; Specific properties and methods are implemented in the concerned subclass(es) SF_Calc, SF_Writer, SF_Base, ...
23 &apos;&apos;&apos;
24 &apos;&apos;&apos; To workaround the absence of class inheritance in LibreOffice Basic, some redundancy is necessary
25 &apos;&apos;&apos; Each subclass MUST implement also the generic methods and properties, even if they only call
26 &apos;&apos;&apos; the parent methods and properties.
27 &apos;&apos;&apos; They should also duplicate some generic private members as a subset of their own set of members
28 &apos;&apos;&apos;
29 &apos;&apos;&apos; The SF_Writer module is focused on selecting, reading, inserting, modifying texts and values
30 &apos;&apos;&apos; on well-identified and predefined places in the document.
31 &apos;&apos;&apos; Usually such customization of the document starts from a predefined template.
32 &apos;&apos;&apos; Multiple customizations are also known as mail merging.
33 &apos;&apos;&apos;
34 &apos;&apos;&apos; As a consequence, focus is not on text formatting, except by the application of styles
35 &apos;&apos;&apos; onto the targeted text fragments.
36 &apos;&apos;&apos;
37 &apos;&apos;&apos; The positions in the text where customization can take place easily are:
38 &apos;&apos;&apos; - the start and end positions of the text body
39 &apos;&apos;&apos; - the start and end positions of text frames
40 &apos;&apos;&apos; - bookmarks
41 &apos;&apos;&apos; - text fields
42 &apos;&apos;&apos; - the start and end positions of document sections
43 &apos;&apos;&apos; - writer tables and table cells
44 &apos;&apos;&apos; - the area currently selected by the user, i.e. the &quot;visible&quot; selection
45 &apos;&apos;&apos;
46 &apos;&apos;&apos; The current module is closely related to the &quot;UI&quot; service of the ScriptForge library
47 &apos;&apos;&apos;
48 &apos;&apos;&apos; Service invocation examples:
49 &apos;&apos;&apos; 1) From the UI service
50 &apos;&apos;&apos; Dim ui As Object, oDoc As Object
51 &apos;&apos;&apos; Set ui = CreateScriptService(&quot;UI&quot;)
52 &apos;&apos;&apos; Set oDoc = ui.CreateDocument(&quot;Writer&quot;, ...)
53 &apos;&apos;&apos; &apos; or Set oDoc = ui.OpenDocument(&quot;C:\Me\MyFile.odt&quot;)
54 &apos;&apos;&apos; 2) Directly if the document is already opened
55 &apos;&apos;&apos; Dim oDoc As Object
56 &apos;&apos;&apos; Set oDoc = CreateScriptService(&quot;SFDocuments.Writer&quot;, ThisComponent) &apos; Default = ActiveWindow
57 &apos;&apos;&apos; &apos; or Set oDoc = CreateScriptService(&quot;SFDocuments.Writer&quot;, &quot;Untitled 1&quot;) &apos; Untitled 1 is presumed a Writer document
58 &apos;&apos;&apos; &apos; The substring &quot;SFDocuments.&quot; in the service name is optional
59 &apos;&apos;&apos;
60 &apos;&apos;&apos; Definitions:
61 &apos;&apos;&apos; Many methods require a &quot;TextRange&quot; as argument.
62 &apos;&apos;&apos; A textrange is a string describing the scope on which to apply the method.
63 &apos;&apos;&apos; Such a textrange corresponds either with a single insertion point or with a (text) interval between 2 insertion points.
64 &apos;&apos;&apos; Multiple textranges are not supported in this context.
65 &apos;&apos;&apos;
66 &apos;&apos;&apos; TextRange: a string containing one of next variants :
67 &apos;&apos;&apos; (names may be surrounded with single or double quotes)
68 &apos;&apos;&apos; &quot;~&quot; or &quot;SELECTION&quot; or &quot;SEL&quot; = current selection (if multiple selections, its 1st component)
69 &apos;&apos;&apos; &quot;BODY&quot; = the main text of the actual document instance
70 &apos;&apos;&apos; &quot;FRAME!name&quot; = the text contained in a text frame
71 &apos;&apos;&apos; &quot;BOOKMARK!name&quot; = the given bookmark, may be zero or more characters long
72 &apos;&apos;&apos; &quot;FIELD!name&quot; = a user text field
73 &apos;&apos;&apos; &quot;SECTION!name&quot; = the text contained in a section
74 &apos;&apos;&apos; &quot;TABLE!name!&quot; = the whole cellrange of a table
75 &apos;&apos;&apos; &quot;TABLE!name!cellrange&quot; = a cell (cellrange = &quot;B3&quot;) or a range of cells (&quot;A2:B3&quot;)
76 &apos;&apos;&apos; &quot;WORD+3&quot; = 3 words after the current selection
77 &apos;&apos;&apos; &quot;SENTENCE-1&quot; = the sentence before the current selection
78 &apos;&apos;&apos; &quot;PARAGRAPH&quot; or &quot;ยง&quot; = the paragraph containing the current selection (0 is the default)
79 &apos;&apos;&apos; optionally combined with next control character:
80 &apos;&apos;&apos; &quot;|&quot;: start or end of string
81 &apos;&apos;&apos; &quot;|~&quot; = the point immediately before the current visible selection (starting point)
82 &apos;&apos;&apos; &quot;~|&quot; = the point immediately after the current visible selection (ending point)
83 &apos;&apos;&apos; &quot;~&quot;, &quot;|~|&quot; = the full visible selection
84 &apos;&apos;&apos;
85 &apos;&apos;&apos;
86 &apos;&apos;&apos; Detailed user documentation:
87 &apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_writer.html?DbPAR=BASIC
88 &apos;&apos;&apos;
89 &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;
91 REM ================================================================== EXCEPTIONS
93 Private Const WRITERFORMNOTFOUNDERROR = &quot;WRITERFORMNOTFOUNDERROR&quot;
94 Private Const WRITERRANGEERROR = &quot;WRITERRANGEERROR&quot;
96 REM ============================================================= PRIVATE MEMBERS
98 Private [Me] As Object
99 Private [_Parent] As Object
100 Private [_Super] As Object &apos; Document superclass, which the current instance is a subclass of
101 Private ObjectType As String &apos; Must be WRITER
102 Private ServiceName As String
104 &apos; Window component
105 Private _Component As Object &apos; com.sun.star.lang.XComponent
107 &apos; Text Range
108 Type _TextRange
109 RangeString As String &apos; The input string
110 Target As String &apos; Selection or Body or Frame or ...
111 TargetName As String &apos; Name of Frame or Table or ...
112 TargetCell As String &apos; Cell
113 TargetObject As Object &apos; Field, TableCell, Section, ... object
114 Offset As Long &apos; Number of items to right (+) or to left (-)
115 StartPoint As Boolean &apos; When True, vertical bar before target
116 EndPoint As Boolean &apos; When True, vertical bar after target
117 Anchor As Object &apos; com.sun.star.text.XTextRange
118 Text As Object &apos; com.sun.star.text.XText
119 Cursor As Object &apos; com.sun.star.text.XTextCursor
120 Location As String &apos; BODY or FOOTNOTE or HEADER/FOOTER ...
121 End Type
123 REM ============================================================ MODULE CONSTANTS
125 Const ISDOCFORM = 1 &apos; Form is stored in a Writer document
127 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
129 REM -----------------------------------------------------------------------------
130 Private Sub Class_Initialize()
131 Set [Me] = Nothing
132 Set [_Parent] = Nothing
133 Set [_Super] = Nothing
134 ObjectType = &quot;WRITER&quot;
135 ServiceName = &quot;SFDocuments.Writer&quot;
136 Set _Component = Nothing
137 End Sub &apos; SFDocuments.SF_Writer Constructor
139 REM -----------------------------------------------------------------------------
140 Private Sub Class_Terminate()
141 Call Class_Initialize()
142 End Sub &apos; SFDocuments.SF_Writer Destructor
144 REM -----------------------------------------------------------------------------
145 Public Function Dispose() As Variant
146 If Not IsNull([_Super]) Then Set [_Super] = [_Super].Dispose()
147 Call Class_Terminate()
148 Set Dispose = Nothing
149 End Function &apos; SFDocuments.SF_Writer Explicit Destructor
151 REM ================================================================== PROPERTIES
153 REM -----------------------------------------------------------------------------
154 Property Get Bookmarks() As Variant
155 &apos;&apos;&apos; Return the list of currently available bookmarks as a zero-based array
156 Bookmarks = _PropertyGet(&quot;Bookmarks&quot;)
157 End Property &apos; SFDocuments.SF_Writer.Bookmarks (get)
159 REM -----------------------------------------------------------------------------
160 Property Get CurrentSelection() As Variant
161 &apos;&apos;&apos; Return the list of currently available CurrentSelection as a zero-based array
162 CurrentSelection = _PropertyGet(&quot;CurrentSelection&quot;)
163 End Property &apos; SFDocuments.SF_Writer.CurrentSelection (get)
165 REM -----------------------------------------------------------------------------
166 Property Let CurrentSelection(Optional ByVal pvSelection As Variant)
167 &apos;&apos;&apos; Set the selection to a single or a multiple range
168 &apos;&apos;&apos; The argument can be:
169 &apos;&apos;&apos; - a string (a textrange)
170 &apos;&apos;&apos; - a com.sun.star.text.XTextRange object
171 &apos;&apos;&apos; - a collection of com.sun.star.text.XTextRange objects
173 Dim vSelection As Variant &apos; Alias of pvSelection
174 Dim oSelection As Object &apos; com.sun.star.text.XTextRange
175 Dim sType As String &apos; session.UnoObjectType()
176 Dim oSess As Object : Set oSess = ScriptForge.SF_Session
177 Dim i As Long
179 Const cstThisSub = &quot;SFDocuments.Writer.setCurrentSelection&quot;
180 Const cstSubArgs = &quot;Selection&quot;
182 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
184 Check:
185 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
186 If Not _IsStillAlive(True) Then GoTo Finally
187 If Not ScriptForge.SF_Utils._Validate(pvSelection, &quot;Selection&quot;, Array(V_STRING, ScriptForge.V_Object)) Then GoTo Finally
188 End If
190 Try:
191 vSelection = pvSelection &apos; Necessary to avoid the &quot;Object variable not set&quot; error
192 With _Component.CurrentController
193 If VarType(vSelection) = V_STRING Then
194 Set oSelection = _ParseRange(vSelection).Cursor
195 If Not IsNull(oSelection) Then .select(oSelection)
196 Else
197 sType = oSess.UnoObjectType(vSelection)
198 Select Case sType
199 Case &quot;SwXTextRanges&quot; &apos; Argument is a multiple selection
200 For i = 0 To vSelection.Count - 1
201 If oSess.UnoObjectType(vSelection.getByIndex(i)) &lt;&gt; &quot;SwXTextRange&quot; Then GoTo Catch &apos; Do nothing
202 Next i
203 .select(vSelection)
204 Case &quot;SwXTextRange&quot;, &quot;SwXTextCursor&quot;, &quot;SwXTextTableCursor&quot; &apos; Argument is a simple selection (anchor/cursor)
205 .select(vSelection)
206 Case Else
207 End Select
208 End If
209 End With
211 Finally:
212 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
213 Exit Property
214 Catch:
215 GoTo Finally
216 End Property &apos; SFDocuments.SF_Writer.CurrentSelection (let)
218 REM -----------------------------------------------------------------------------
219 Property Get Fields() As Variant
220 &apos;&apos;&apos; Return the list of currently available fields as a zero-based array
221 &apos;&apos;&apos; Are considered only next field-types:
222 &apos;&apos;&apos; - user fields: com.sun.star.text.textfield.User
223 &apos;&apos;&apos; - variable fields: com.sun.star.text.textfield.SetExpression
224 Fields = _PropertyGet(&quot;Fields&quot;)
225 End Property &apos; SFDocuments.SF_Writer.Fields (get)
227 REM -----------------------------------------------------------------------------
228 Property Get Frames() As Variant
229 &apos;&apos;&apos; Return the list of currently available frames as a zero-based array
230 Frames = _PropertyGet(&quot;Frames&quot;)
231 End Property &apos; SFDocuments.SF_Writer.Frames (get)
233 REM ===================================================================== METHODS
235 REM -----------------------------------------------------------------------------
236 Public Function Forms(Optional ByVal Form As Variant) As Variant
237 &apos;&apos;&apos; Return either
238 &apos;&apos;&apos; - the list of the Forms contained in the form document
239 &apos;&apos;&apos; - a SFDocuments.Form object based on its name or its index
240 &apos;&apos;&apos; Args:
241 &apos;&apos;&apos; Form: a form stored in the document given by its name or its index
242 &apos;&apos;&apos; When absent, the list of available forms is returned
243 &apos;&apos;&apos; To get the first (unique ?) form stored in the form document, set Form = 0
244 &apos;&apos;&apos; Exceptions:
245 &apos;&apos;&apos; WRITERFORMNOTFOUNDERROR Form not found
246 &apos;&apos;&apos; Returns:
247 &apos;&apos;&apos; A zero-based array of strings if Form is absent
248 &apos;&apos;&apos; An instance of the SF_Form class if Form exists
249 &apos;&apos;&apos; Example:
250 &apos;&apos;&apos; Dim myForm As Object, myList As Variant
251 &apos;&apos;&apos; myList = oDoc.Forms()
252 &apos;&apos;&apos; Set myForm = oDoc.Forms(&quot;myForm&quot;)
254 Dim oForm As Object &apos; The new Form class instance
255 Dim oMainForm As Object &apos; com.sun.star.comp.sdb.Content
256 Dim oXForm As Object &apos; com.sun.star.form.XForm
257 Dim vFormNames As Variant &apos; Array of form names
258 Dim oForms As Object &apos; Forms collection
259 Const cstDrawPage = 0 &apos; Only 1 drawpage in a Writer document
261 Const cstThisSub = &quot;SFDocuments.Writer.Forms&quot;
262 Const cstSubArgs = &quot;[Form=&quot;&quot;&quot;&quot;]&quot;
264 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
266 Check:
267 If IsMissing(Form) Or IsEmpty(Form) Then Form = &quot;&quot;
268 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
269 If Not _IsStillAlive() Then GoTo Finally
270 If Not ScriptForge.SF_Utils._Validate(Form, &quot;Form&quot;, Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
271 End If
273 Try:
274 &apos; Start from the document component and go down to forms
275 Set oForms = _Component.DrawPages(cstDrawPage).Forms
276 vFormNames = oForms.getElementNames()
278 If Len(Form) = 0 Then &apos; Return the list of valid form names
279 Forms = vFormNames
280 Else
281 If VarType(Form) = V_STRING Then &apos; Find the form by name
282 If Not ScriptForge.SF_Array.Contains(vFormNames, Form, CaseSensitive := True) Then GoTo CatchNotFound
283 Set oXForm = oForms.getByName(Form)
284 Else &apos; Find the form by index
285 If Form &lt; 0 Or Form &gt;= oForms.Count Then GoTo CatchNotFound
286 Set oXForm = oForms.getByIndex(Form)
287 End If
288 &apos; Create the new Form class instance
289 Set oForm = SF_Register._NewForm(oXForm)
290 With oForm
291 Set .[_Parent] = [Me]
292 ._FormType = ISDOCFORM
293 Set ._Component = _Component
294 ._Initialize()
295 End With
296 Set Forms = oForm
297 End If
299 Finally:
300 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
301 Exit Function
302 Catch:
303 GoTo Finally
304 CatchNotFound:
305 ScriptForge.SF_Exception.RaiseFatal(WRITERFORMNOTFOUNDERROR, Form, _FileIdent())
306 End Function &apos; SFDocuments.SF_Writer.Forms
308 REM -----------------------------------------------------------------------------
309 Public Function GetProperty(Optional ByVal PropertyName As Variant _
310 ) As Variant
311 &apos;&apos;&apos; Return the actual value of the given property
312 &apos;&apos;&apos; Args:
313 &apos;&apos;&apos; PropertyName: the name of the property as a string
314 &apos;&apos;&apos; Returns:
315 &apos;&apos;&apos; The actual value of the property
316 &apos;&apos;&apos; Exceptions:
317 &apos;&apos;&apos; ARGUMENTERROR The property does not exist
319 Const cstThisSub = &quot;SFDocuments.Writer.GetProperty&quot;
320 Const cstSubArgs = &quot;&quot;
322 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
323 GetProperty = Null
325 Check:
326 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
327 If Not ScriptForge.SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
328 End If
330 Try:
331 &apos; Superclass or subclass property ?
332 If ScriptForge.SF_Array.Contains([_Super].Properties(), PropertyName) Then
333 GetProperty = [_Super].GetProperty(PropertyName)
334 Else
335 GetProperty = _PropertyGet(PropertyName)
336 End If
338 Finally:
339 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
340 Exit Function
341 Catch:
342 GoTo Finally
343 End Function &apos; SFDocuments.SF_Writer.GetProperty
345 REM -----------------------------------------------------------------------------
346 Public Function Methods() As Variant
347 &apos;&apos;&apos; Return the list of public methods of the Writer service as an array
349 Methods = Array( _
350 &quot;Forms&quot; _
351 , &quot;PrintOut&quot; _
354 End Function &apos; SFDocuments.SF_Writer.Methods
356 REM -----------------------------------------------------------------------------
357 Public Function PrintOut(Optional ByVal Pages As Variant _
358 , Optional ByVal Copies As Variant _
359 , Optional ByVal PrintBackground As Variant _
360 , Optional ByVal PrintBlankPages As Variant _
361 , Optional ByVal PrintEvenPages As Variant _
362 , Optional ByVal PrintOddPages As Variant _
363 , Optional ByVal PrintImages As Variant _
364 ) As Boolean
365 &apos;&apos;&apos; Send the content of the document to the printer.
366 &apos;&apos;&apos; The printer might be defined previously by default, by the user or by the SetPrinter() method
367 &apos;&apos;&apos; Args:
368 &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
369 &apos;&apos;&apos; Copies: the number of copies
370 &apos;&apos;&apos; PrintBackground: print the background image when True (default)
371 &apos;&apos;&apos; PrintBlankPages: when False (default), omit empty pages
372 &apos;&apos;&apos; PrintEvenPages: print the left pages when True (default)
373 &apos;&apos;&apos; PrintOddPages: print the right pages when True (default)
374 &apos;&apos;&apos; PrintImages: print the graphic objects when True (default)
375 &apos;&apos;&apos; Returns:
376 &apos;&apos;&apos; True when successful
377 &apos;&apos;&apos; Examples:
378 &apos;&apos;&apos; oDoc.PrintOut(&quot;1-4;10;15-18&quot;, Copies := 2, PrintImages := False)
380 Dim bPrint As Boolean &apos; Return value
381 Dim vPrintOptions As Variant &apos; com.sun.star.text.DocumentSettings
383 Const cstThisSub = &quot;SFDocuments.Writer.PrintOut&quot;
384 Const cstSubArgs = &quot;[Pages=&quot;&quot;&quot;&quot;], [Copies=1], [PrintBackground=True], [PrintBlankPages=False], [PrintEvenPages=True]&quot; _
385 &amp; &quot;, [PrintOddPages=True], [PrintImages=True]&quot;
387 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
388 bPrint = False
390 Check:
391 If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
392 If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
393 If IsMissing(PrintBackground) Or IsEmpty(PrintBackground) Then PrintBackground = True
394 If IsMissing(PrintBlankPages) Or IsEmpty(PrintBlankPages) Then PrintBlankPages = False
395 If IsMissing(PrintEvenPages) Or IsEmpty(PrintEvenPages) Then PrintEvenPages = True
396 If IsMissing(PrintOddPages) Or IsEmpty(PrintOddPages) Then PrintOddPages = True
397 If IsMissing(PrintImages) Or IsEmpty(PrintImages) Then PrintImages = True
399 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
400 If Not _IsStillAlive() Then GoTo Finally
401 If Not ScriptForge.SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
402 If Not ScriptForge.SF_Utils._Validate(Copies, &quot;Copies&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
403 If Not ScriptForge.SF_Utils._Validate(PrintBackground, &quot;PrintBackground&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
404 If Not ScriptForge.SF_Utils._Validate(PrintBlankPages, &quot;PrintBlankPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
405 If Not ScriptForge.SF_Utils._Validate(PrintEvenPages, &quot;PrintEvenPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
406 If Not ScriptForge.SF_Utils._Validate(PrintOddPages, &quot;PrintOddPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
407 If Not ScriptForge.SF_Utils._Validate(PrintImages, &quot;PrintImages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
408 End If
410 Try:
411 vPrintOptions = _Component.createInstance(&quot;com.sun.star.text.DocumentSettings&quot;)
412 With vPrintOptions
413 .PrintPageBackground = PrintBackground
414 .PrintEmptyPages = PrintBlankPages
415 .PrintLeftPages = PrintEvenPages
416 .PrintRightPages = PrintOddPages
417 .PrintGraphics = PrintImages
418 .PrintDrawings = PrintImages
419 End With
421 bPrint = [_Super].PrintOut(Pages, Copies, _Component)
423 Finally:
424 PrintOut = bPrint
425 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
426 Exit Function
427 Catch:
428 GoTo Finally
429 End Function &apos; SFDocuments.SF_Writer.PrintOut
431 REM -----------------------------------------------------------------------------
432 Public Function Properties() As Variant
433 &apos;&apos;&apos; Return the list or properties of the Writer class as an array
435 Properties = Array( _
436 &quot;Bookmarks&quot; _
437 , &quot;CurrentSelection&quot; _
438 , &quot;CustomProperties&quot; _
439 , &quot;Description&quot; _
440 , &quot;DocumentProperties&quot; _
441 , &quot;DocumentType&quot; _
442 , &quot;ExportFilters&quot; _
443 , &quot;Fields&quot; _
444 , &quot;FileSystem&quot; _
445 , &quot;Frames&quot; _
446 , &quot;ImportFilters&quot; _
447 , &quot;IsAlive&quot; _
448 , &quot;IsBase&quot; _
449 , &quot;IsCalc&quot; _
450 , &quot;IsDraw&quot; _
451 , &quot;IsFormDocument&quot; _
452 , &quot;IsImpress&quot; _
453 , &quot;IsMath&quot; _
454 , &quot;IsWriter&quot; _
455 , &quot;Keywords&quot; _
456 , &quot;Readonly&quot; _
457 , &quot;StyleFamilies&quot; _
458 , &quot;Subject&quot; _
459 , &quot;Title&quot; _
460 , &quot;XComponent&quot; _
461 , &quot;XDocumentSettings&quot; _
464 End Function &apos; SFDocuments.SF_Writer.Properties
466 REM -----------------------------------------------------------------------------
467 Private Function SetProperty(Optional ByVal psProperty As String _
468 , Optional ByVal pvValue As Variant _
469 ) As Boolean
470 &apos;&apos;&apos; Set the new value of the named property
471 &apos;&apos;&apos; Args:
472 &apos;&apos;&apos; psProperty: the name of the property
473 &apos;&apos;&apos; pvValue: the new value of the given property
474 &apos;&apos;&apos; Returns:
475 &apos;&apos;&apos; True if successful
477 Dim bSet As Boolean &apos; Return value
478 Static oSession As Object &apos; Alias of SF_Session
479 Dim cstThisSub As String
480 Const cstSubArgs = &quot;Value&quot;
482 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
483 bSet = False
485 cstThisSub = &quot;SFDocuments.Writer.set&quot; &amp; psProperty
486 If IsMissing(pvValue) Then pvValue = Empty
487 &apos;ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) &apos; Validation done in Property Lets
489 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
490 bSet = True
491 Select Case UCase(psProperty)
492 Case UCase(&quot;CustomProperties&quot;)
493 CustomProperties = pvValue
494 Case UCase(&quot;Description&quot;)
495 Description = pvValue
496 Case UCase(&quot;Keywords&quot;)
497 Keywords = pvValue
498 Case UCase(&quot;Subject&quot;)
499 Subject = pvValue
500 Case UCase(&quot;Title&quot;)
501 Title = pvValue
502 Case Else
503 bSet = False
504 End Select
506 Finally:
507 SetProperty = bSet
508 &apos;ScriptForge.SF_Utils._ExitFunction(cstThisSub)
509 Exit Function
510 Catch:
511 GoTo Finally
512 End Function &apos; SFDocuments.SF_Writer.SetProperty
514 REM ======================================================= SUPERCLASS PROPERTIES
516 REM -----------------------------------------------------------------------------
517 Property Get CustomProperties() As Variant
518 CustomProperties = [_Super].GetProperty(&quot;CustomProperties&quot;)
519 End Property &apos; SFDocuments.SF_Writer.CustomProperties
521 REM -----------------------------------------------------------------------------
522 Property Let CustomProperties(Optional ByVal pvCustomProperties As Variant)
523 [_Super].CustomProperties = pvCustomProperties
524 End Property &apos; SFDocuments.SF_Writer.CustomProperties
526 REM -----------------------------------------------------------------------------
527 Property Get Description() As Variant
528 Description = [_Super].GetProperty(&quot;Description&quot;)
529 End Property &apos; SFDocuments.SF_Writer.Description
531 REM -----------------------------------------------------------------------------
532 Property Let Description(Optional ByVal pvDescription As Variant)
533 [_Super].Description = pvDescription
534 End Property &apos; SFDocuments.SF_Writer.Description
536 REM -----------------------------------------------------------------------------
537 Property Get DocumentProperties() As Variant
538 DocumentProperties = [_Super].GetProperty(&quot;DocumentProperties&quot;)
539 End Property &apos; SFDocuments.SF_Writer.DocumentProperties
541 REM -----------------------------------------------------------------------------
542 Property Get DocumentType() As String
543 DocumentType = [_Super].GetProperty(&quot;DocumentType&quot;)
544 End Property &apos; SFDocuments.SF_Writer.DocumentType
546 REM -----------------------------------------------------------------------------
547 Property Get ExportFilters() As Variant
548 ExportFilters = [_Super].GetProperty(&quot;ExportFilters&quot;)
549 End Property &apos; SFDocuments.SF_Writer.ExportFilters
551 REM -----------------------------------------------------------------------------
552 Property Get FileSystem() As String
553 FileSystem = [_Super].GetProperty(&quot;FileSystem&quot;)
554 End Property &apos; SFDocuments.SF_Writer.FileSystem
556 REM -----------------------------------------------------------------------------
557 Property Get ImportFilters() As Variant
558 ImportFilters = [_Super].GetProperty(&quot;ImportFilters&quot;)
559 End Property &apos; SFDocuments.SF_Writer.ImportFilters
561 REM -----------------------------------------------------------------------------
562 Property Get IsAlive() As Boolean
563 IsAlive = [_Super].GetProperty(&quot;IsAlive&quot;)
564 End Property &apos; SFDocuments.SF_Writer.IsAlive
566 REM -----------------------------------------------------------------------------
567 Property Get IsBase() As Boolean
568 IsBase = [_Super].GetProperty(&quot;IsBase&quot;)
569 End Property &apos; SFDocuments.SF_Writer.IsBase
571 REM -----------------------------------------------------------------------------
572 Property Get IsCalc() As Boolean
573 IsCalc = [_Super].GetProperty(&quot;IsCalc&quot;)
574 End Property &apos; SFDocuments.SF_Writer.IsCalc
576 REM -----------------------------------------------------------------------------
577 Property Get IsDraw() As Boolean
578 IsDraw = [_Super].GetProperty(&quot;IsDraw&quot;)
579 End Property &apos; SFDocuments.SF_Writer.IsDraw
581 REM -----------------------------------------------------------------------------
582 Property Get IsFormDocument() As Boolean
583 IsFormDocument = [_Super].GetProperty(&quot;IsFormDocument&quot;)
584 End Property &apos; SFDocuments.SF_Writer.IsFormDocument
586 REM -----------------------------------------------------------------------------
587 Property Get IsImpress() As Boolean
588 IsImpress = [_Super].GetProperty(&quot;IsImpress&quot;)
589 End Property &apos; SFDocuments.SF_Writer.IsImpress
591 REM -----------------------------------------------------------------------------
592 Property Get IsMath() As Boolean
593 IsMath = [_Super].GetProperty(&quot;IsMath&quot;)
594 End Property &apos; SFDocuments.SF_Writer.IsMath
596 REM -----------------------------------------------------------------------------
597 Property Get IsWriter() As Boolean
598 IsWriter = [_Super].GetProperty(&quot;IsWriter&quot;)
599 End Property &apos; SFDocuments.SF_Writer.IsWriter
601 REM -----------------------------------------------------------------------------
602 Property Get Keywords() As Variant
603 Keywords = [_Super].GetProperty(&quot;Keywords&quot;)
604 End Property &apos; SFDocuments.SF_Writer.Keywords
606 REM -----------------------------------------------------------------------------
607 Property Let Keywords(Optional ByVal pvKeywords As Variant)
608 [_Super].Keywords = pvKeywords
609 End Property &apos; SFDocuments.SF_Writer.Keywords
611 REM -----------------------------------------------------------------------------
612 Property Get Readonly() As Variant
613 Readonly = [_Super].GetProperty(&quot;Readonly&quot;)
614 End Property &apos; SFDocuments.SF_Writer.Readonly
616 REM -----------------------------------------------------------------------------
617 Property Get StyleFamilies() As Variant
618 StyleFamilies = [_Super].GetProperty(&quot;StyleFamilies&quot;)
619 End Property &apos; SFDocuments.SF_Writer.StyleFamilies
621 REM -----------------------------------------------------------------------------
622 Property Get Subject() As Variant
623 Subject = [_Super].GetProperty(&quot;Subject&quot;)
624 End Property &apos; SFDocuments.SF_Writer.Subject
626 REM -----------------------------------------------------------------------------
627 Property Let Subject(Optional ByVal pvSubject As Variant)
628 [_Super].Subject = pvSubject
629 End Property &apos; SFDocuments.SF_Writer.Subject
631 REM -----------------------------------------------------------------------------
632 Property Get Title() As Variant
633 Title = [_Super].GetProperty(&quot;Title&quot;)
634 End Property &apos; SFDocuments.SF_Writer.Title
636 REM -----------------------------------------------------------------------------
637 Property Let Title(Optional ByVal pvTitle As Variant)
638 [_Super].Title = pvTitle
639 End Property &apos; SFDocuments.SF_Writer.Title
641 REM -----------------------------------------------------------------------------
642 Property Get XComponent() As Variant
643 XComponent = [_Super].GetProperty(&quot;XComponent&quot;)
644 End Property &apos; SFDocuments.SF_Writer.XComponent
646 REM -----------------------------------------------------------------------------
647 Property Get XDocumentSettings() As Variant
648 XDocumentSettings = [_Super].GetProperty(&quot;XDocumentSettings&quot;)
649 End Property &apos; SFDocuments.SF_Writer.XDocumentSettings
651 REM ========================================================== SUPERCLASS METHODS
653 REM -----------------------------------------------------------------------------
654 Public Function Activate() As Boolean
655 Activate = [_Super].Activate()
656 End Function &apos; SFDocuments.SF_Writer.Activate
658 REM -----------------------------------------------------------------------------
659 Public Function CloseDocument(Optional ByVal SaveAsk As Variant) As Boolean
660 CloseDocument = [_Super].CloseDocument(SaveAsk)
661 End Function &apos; SFDocuments.SF_Writer.CloseDocument
663 REM -----------------------------------------------------------------------------
664 Public Function ContextMenus(Optional ByVal ContextMenuName As Variant _
665 , Optional ByVal SubmenuChar As Variant _
666 ) As Variant
667 ContextMenus = [_Super].ContextMenus(ContextMenuName, SubmenuChar)
668 End Function &apos; SFDocuments.SF_Writer.ContextMenus
670 REM -----------------------------------------------------------------------------
671 Public Function CreateMenu(Optional ByVal MenuHeader As Variant _
672 , Optional ByVal Before As Variant _
673 , Optional ByVal SubmenuChar As Variant _
674 ) As Object
675 Set CreateMenu = [_Super].CreateMenu(MenuHeader, Before, SubmenuChar)
676 End Function &apos; SFDocuments.SF_Writer.CreateMenu
678 REM -----------------------------------------------------------------------------
679 Public Sub DeleteStyles(Optional ByVal Family As Variant _
680 , Optional ByRef StylesList As Variant _
682 [_Super].DeleteStyles(Family, StylesList)
683 End Sub &apos; SFDocuments.SF_Writer.DeleteStyles
685 REM -----------------------------------------------------------------------------
686 Public Sub Echo(Optional ByVal EchoOn As Variant _
687 , Optional ByVal Hourglass As Variant _
689 [_Super].Echo(EchoOn, Hourglass)
690 End Sub &apos; SFDocuments.SF_Writer.Echo
692 REM -----------------------------------------------------------------------------
693 Public Function ExportAsPDF(Optional ByVal FileName As Variant _
694 , Optional ByVal Overwrite As Variant _
695 , Optional ByVal Pages As Variant _
696 , Optional ByVal Password As Variant _
697 , Optional ByVal Watermark As Variant _
698 ) As Boolean
699 ExportAsPDF = [_Super].ExportAsPDF(FileName, Overwrite, Pages, Password, Watermark)
700 End Function &apos; SFDocuments.SF_Writer.ExportAsPDF
702 REM -----------------------------------------------------------------------------
703 Public Sub ImportStylesFromFile(Optional FileName As Variant _
704 , Optional ByRef Families As Variant _
705 , Optional ByVal Overwrite As variant _
706 ) As Variant
707 [_Super]._ImportStylesFromFile(FileName, Families, Overwrite)
708 End Sub &apos; SFDocuments.SF_Writer.ImportStylesFromFile
710 REM -----------------------------------------------------------------------------
711 Public Function RemoveMenu(Optional ByVal MenuHeader As Variant) As Boolean
712 RemoveMenu = [_Super].RemoveMenu(MenuHeader)
713 End Function &apos; SFDocuments.SF_Writer.RemoveMenu
715 REM -----------------------------------------------------------------------------
716 Public Sub RunCommand(Optional ByVal Command As Variant _
717 , ParamArray Args As Variant _
719 [_Super].RunCommand(Command, Args)
720 End Sub &apos; SFDocuments.SF_Writer.RunCommand
722 REM -----------------------------------------------------------------------------
723 Public Function Save() As Boolean
724 Save = [_Super].Save()
725 End Function &apos; SFDocuments.SF_Writer.Save
727 REM -----------------------------------------------------------------------------
728 Public Function SaveAs(Optional ByVal FileName As Variant _
729 , Optional ByVal Overwrite As Variant _
730 , Optional ByVal Password As Variant _
731 , Optional ByVal FilterName As Variant _
732 , Optional ByVal FilterOptions As Variant _
733 ) As Boolean
734 SaveAs = [_Super].SaveAs(FileName, Overwrite, Password, FilterName, FilterOptions)
735 End Function &apos; SFDocuments.SF_Writer.SaveAs
737 REM -----------------------------------------------------------------------------
738 Public Function SaveCopyAs(Optional ByVal FileName As Variant _
739 , Optional ByVal Overwrite As Variant _
740 , Optional ByVal Password As Variant _
741 , Optional ByVal FilterName As Variant _
742 , Optional ByVal FilterOptions As Variant _
743 ) As Boolean
744 SaveCopyAs = [_Super].SaveCopyAs(FileName, Overwrite, Password, FilterName, FilterOptions)
745 End Function &apos; SFDocuments.SF_Writer.SaveCopyAs
747 REM -----------------------------------------------------------------------------
748 Public Function SetPrinter(Optional ByVal Printer As Variant _
749 , Optional ByVal Orientation As Variant _
750 , Optional ByVal PaperFormat As Variant _
751 ) As Boolean
752 SetPrinter = [_Super].SetPrinter(Printer, Orientation, PaperFormat)
753 End Function &apos; SFDocuments.SF_Writer.SetPrinter
755 REM -----------------------------------------------------------------------------
756 Public Function Styles(Optional ByVal Family As Variant _
757 , Optional ByVal NamePattern As variant _
758 , Optional ByVal Used As variant _
759 , Optional ByVal UserDefined As Variant _
760 , Optional ByVal ParentStyle As Variant _
761 , Optional ByVal Category As Variant _
762 ) As Variant
763 Styles = [_Super].Styles(Family, NamePattern, Used, UserDefined, ParentStyle, Category)
764 End Function &apos; SFDocuments.SF_Writer.Styles
766 REM -----------------------------------------------------------------------------
767 Public Function Toolbars(Optional ByVal ToolbarName As Variant) As Variant
768 Toolbars = [_Super].Toolbars(ToolbarName)
769 End Function &apos; SFDocuments.SF_Writer.Toolbars
771 REM -----------------------------------------------------------------------------
772 Public Function XStyle(Optional ByVal Family As Variant _
773 , Optional ByVal StyleName As variant _
774 ) As Object
775 Set XStyle = [_Super].XStyle(Family, StyleName)
776 End Function &apos; SFDocuments.SF_Writer.XStyle
778 REM =========================================================== PRIVATE FUNCTIONS
780 REM -----------------------------------------------------------------------------
781 Private Function _FileIdent() As String
782 &apos;&apos;&apos; Returns a file identification from the information that is currently available
783 &apos;&apos;&apos; Useful e.g. for display in error messages
785 _FileIdent = [_Super]._FileIdent()
787 End Function &apos; SFDocuments.SF_Writer._FileIdent
789 REM -----------------------------------------------------------------------------
790 Private Function _IsStillAlive(Optional ByVal pbForUpdate As Boolean _
791 , Optional ByVal pbError As Boolean _
792 ) As Boolean
793 &apos;&apos;&apos; Returns True if the document has not been closed manually or incidentally since the last use
794 &apos;&apos;&apos; If dead the actual instance is disposed. The execution is cancelled when pbError = True (default)
795 &apos;&apos;&apos; Args:
796 &apos;&apos;&apos; pbForUpdate: if True (default = False), check additionally if document is open for editing
797 &apos;&apos;&apos; pbError: if True (default), raise a fatal error
799 Dim bAlive As Boolean &apos; Return value
801 If IsMissing(pbForUpdate) Then pbForUpdate = False
802 If IsMissing(pbError) Then pbError = True
804 Try:
805 bAlive = [_Super]._IsStillAlive(pbForUpdate, pbError)
807 Finally:
808 _IsStillAlive = bAlive
809 Exit Function
810 End Function &apos; SFDocuments.SF_Writer._IsStillAlive
812 REM -----------------------------------------------------------------------------
813 Private Function _ParseRange(psTextRange As String) As Object
814 &apos;&apos;&apos; Parse and validate a text range passed as a string
815 &apos;&apos;&apos; Syntax to parse:
816 &apos;&apos;&apos; [|]~ or &quot;SELECTION&quot; or &quot;SEL&quot;[|]
817 &apos;&apos;&apos; [|]BODY[|]
818 &apos;&apos;&apos; [|]FRAME!name[|]
819 &apos;&apos;&apos; BOOKMARK!name
820 &apos;&apos;&apos; FIELD!name
821 &apos;&apos;&apos; [|]SECTION!name[|]
822 &apos;&apos;&apos; TABLE!name!cell
823 &apos;&apos;&apos; [|]WORDยฑn[|]
824 &apos;&apos;&apos; [|]SENTENCEยฑn[|]
825 &apos;&apos;&apos; [|]PARAGRAPHยฑn or ยงยฑn[|]
826 &apos;&apos;&apos; A name must be surrounded with single or double quotes when it contains a space or a not alphanumeric character
827 &apos;&apos;&apos; Returns:
828 &apos;&apos;&apos; An object of type _TextRange
829 &apos;&apos;&apos; Exceptions:
830 &apos;&apos;&apos; WRITERRANGEERROR &apos; Text range could not be parsed to a valid location
832 Dim oTextRange As Object &apos; Return value
833 Dim bParsing As Boolean &apos; When True, parsing could identify the target
834 Dim lSelects As Long &apos; Number of items in the current selection
835 Dim sTarget As String &apos; Alias of _TextRange.Target
836 Dim sString As String &apos; Work variable
837 Dim sLeft1 As String &apos; The 1st character of sString
838 Dim sSign As String &apos; + or -
839 Dim oColl As Object &apos; Collection of TargetObjects (bookmarks or frames or ...)
840 Dim oItem As Object &apos; An item in the oColl collection
841 Dim vNames As Variant &apos; Array of the available object names within a collection
842 Dim oStr As Object : Set oStr = ScriptForge.SF_String
843 Dim bMove As Boolean &apos; Return value of a cursor move
844 Dim i As Long
846 &apos; Reinitialize a new _TextRange object
847 Set oTextRange = New _TextRange
848 With oTextRange
849 Set .TargetObject = Nothing
850 .RangeString = &quot;&quot; : .Target = &quot;&quot; : .TargetName = &quot;&quot; : .TargetCell = &quot;&quot;
851 .Offset = 0 : .StartPoint = False : .EndPoint = False
852 Set .Anchor = Nothing : Set .Text = Nothing : Set .Cursor = Nothing
853 .Location = &quot;&quot;
854 End With
856 &apos; Identify the type of range with adequate regular expressions
857 With oTextRange
858 .RangeString = psTextRange
859 .StartPoint = ( Left(psTextRange, 1) = &quot;|&quot; )
860 .EndPoint = ( Right(psTextRange, 1) = &quot;|&quot; )
862 Select Case True
863 &apos; Parsing is done with regular expressions because names may really contain any character, including &quot;รง&quot;
865 &apos; Selection
866 Case oStr.IsRegex(psTextRange, &quot;\|?\s*(~|SEL|SELECTION)\s*\|?&quot;)
867 .Target = &quot;Selection&quot;
868 If _Component.CurrentSelection.ImplementationName = &quot;SwXTextRanges&quot; Then
869 lSelects = _Component.CurrentSelection.Count
870 If lSelects &gt; 0 Then
871 Set .Anchor = _Component.CurrentSelection.getByIndex(lSelects - 1)
872 If .StartPoint And Not .EndPoint Then
873 Set .Anchor = .Anchor.Start
874 ElseIf Not .StartPoint And .EndPoint Then
875 Set .Anchor = .Anchor.End
876 End If
877 Set .Text = .Anchor.Text
878 Set .Cursor = .Text.createTextCursorByRange(.Anchor)
879 End If
880 End If
881 If IsNull(.Cursor) Then .Location = _Component.CurrentSelection.ImplementationName
883 &apos; WORD, SENTENCE, PARAGRAPH
884 Case oStr.IsRegex(psTextRange, &quot;\|?\s*(PARAGRAPH|ยง|SENTENCE|WORD)\s*([+-][0-9]+)?\s*\|?&quot;)
885 If InStr(psTextRange, &quot;+&quot;) &gt; 0 Then
886 sSign = &quot;+&quot;
887 ElseIf InStr(psTextRange, &quot;-&quot;) &gt; 0 Then
888 sSign= &quot;-&quot;
889 End If
890 If Len(sSign) &gt; 0 Then sTarget = Split(psTextRange, sSign)(0) Else sTarget = psTextRange
891 If InStr(Iif(.StartPoint, 2, 1), sTarget, &quot;PARAGRAPH&quot;, 1) &gt; 0 Or InStr(Iif(.StartPoint, 2, 1), sTarget, &quot;ยง&quot;, 1) &gt; 0 Then
892 .Target = &quot;Paragraph&quot;
893 ElseIf InStr(Iif(.StartPoint, 2, 1), sTarget, &quot;SENTENCE&quot;, 1) &gt; 0 Then
894 .Target = &quot;Sentence&quot;
895 ElseIf InStr(Iif(.StartPoint, 2, 1), sTarget, &quot;WORD&quot;, 1) &gt; 0 Then
896 .Target = &quot;Word&quot;
897 End If
899 &apos; Identify the offset
900 If Len(sSign) = 0 Then
901 .Offset = 0
902 Else
903 sString = Split(psTextRange, sSign)(1)
904 If .EndPoint Then sString = Left(sString, Len(sString) - 1)
905 .Offset = CLng(sString) * Iif(sSign = &quot;+&quot;, 1, -1)
906 End If
908 &apos; Build the cursor pointing at the current selection
909 If _Component.CurrentSelection.ImplementationName = &quot;SwXTextRanges&quot; Then
910 lSelects = _Component.CurrentSelection.Count
911 If lSelects &gt; 0 Then
912 Set .Anchor = _Component.CurrentSelection.getByIndex(lSelects - 1)
913 Set .Text = .Anchor.Text
914 Set .Cursor = .Text.createTextCursorByRange(.Anchor)
915 End If
916 End If
917 If IsNull(.Cursor) Then
918 .Location = _Component.CurrentSelection.ImplementationName
919 Else
920 &apos; Move the cursor to the requested area
921 With .Cursor
922 Select Case oTextRange.Target
923 Case &quot;Word&quot;
924 bMove = .gotoStartOfWord(False)
925 If bMove Then
926 For i = 1 To Abs(oTextRange.Offset)
927 If sSign = &quot;+&quot; Then bMove = .gotoNextWord(False) Else bMove = .gotoPreviousWord(False)
928 If sSign = &quot;+&quot; Then
929 If Not bMove Then Exit For
930 If .isEndOfSentence() Then i = i - 1 &apos; Loop to do once more
931 Else
932 bMove = .goLeft(1, False) &apos; Additional trial to bypass some locks (tabs, list items, ... ?)
933 If Not bMove Then Exit For
934 End If
935 Next i
936 End If
937 &apos; Cursor is always at the start of a word, move it when necessary
938 If Not oTextRange.StartPoint And oTextRange.EndPoint Then
939 .gotoEndOfWord(False)
940 ElseIf oTextRange.StartPoint = oTextRange.EndPoint Then
941 .gotoEndOfWord(True)
942 End If
943 Case &quot;Sentence&quot;
944 bMove = .gotoStartOfSentence(False)
945 If bMove Then
946 For i = 1 To Abs(oTextRange.Offset)
947 If sSign = &quot;+&quot; Then bMove = .gotoNextSentence(False) Else bMove = .gotoPreviousSentence(False)
948 If sSign = &quot;+&quot; Then
949 If .isEndOfParagraph() Then bMove = .goRight(1, False)
950 Else
951 bMove = .goLeft(1, False) &apos; Additional trial to bypass some locks (tabs, list items, ... ?)
952 If .isStartOfParagraph() Then bMove = .goLeft(1, False)
953 End If
954 If Not bMove Then Exit For
955 Next i
956 End If
957 &apos; Cursor is always at the start of a sentence, move it when necessary
958 If Not oTextRange.StartPoint And oTextRange.EndPoint Then
959 .gotoEndOfSentence(False)
960 ElseIf oTextRange.StartPoint = oTextRange.EndPoint Then
961 .gotoEndOfSentence(True)
962 End If
963 Case &quot;Paragraph&quot;
964 bMove = .gotoStartOfParagraph(False)
965 If bMove Then
966 For i = 1 To Abs(oTextRange.Offset)
967 If sSign = &quot;+&quot; Then bMove = .gotoNextParagraph(False) Else bMove = .gotoPreviousParagraph(False)
968 If sSign = &quot;+&quot; Then
969 If .isEndOfParagraph() Then bMove = .goRight(1, False)
970 Else
971 bMove = .goLeft(1, False) &apos; Additional trial to bypass some locks (tabs, list items, ... ?)
972 If .isStartOfParagraph() Then bMove = .goLeft(1, False)
973 End If
974 If Not bMove Then Exit For
975 Next i
976 End If
977 &apos; Cursor is always at the start of a Paragraph, move it when necessary
978 If Not oTextRange.StartPoint And oTextRange.EndPoint Then
979 .gotoEndOfParagraph(False)
980 ElseIf oTextRange.StartPoint = oTextRange.EndPoint Then
981 .gotoEndOfParagraph(True)
982 End If
983 End Select
984 End With
985 End If
987 &apos; Bookmarks, Fields, Frames, Sections
988 Case oStr.IsRegex(psTextRange, &quot;\|?\s*(BOOKMARK|FIELD|FRAME|SECTION)!([\w\s]+|&apos;[^&apos;]+&apos;|&quot;&quot;[^&quot;&quot;]+&quot;&quot;)\|?&quot;)
989 sTarget = Split(psTextRange, &quot;!&quot;)(0)
990 If InStr(Iif(.StartPoint, 2, 1), sTarget, &quot;BOOKMARK&quot;, 1) &gt; 0 Then
991 .Target = &quot;Bookmark&quot;
992 ElseIf InStr(Iif(.StartPoint, 2, 1), sTarget, &quot;FIELD&quot;, 1) &gt; 0 Then
993 .Target = &quot;Field&quot;
994 ElseIf InStr(Iif(.StartPoint, 2, 1), sTarget, &quot;FRAME&quot;, 1) &gt; 0 Then
995 .Target = &quot;Frame&quot;
996 ElseIf InStr(Iif(.StartPoint, 2, 1), sTarget, &quot;SECTION&quot;, 1) &gt; 0 Then
997 .Target = &quot;Section&quot;
998 End If
1000 &apos; Identify section or frame or bookmark or field by its name
1001 sString = Split(psTextRange, &quot;!&quot;)(1)
1002 If .EndPoint Then sString = Left(sString, Len(sString) - 1)
1003 sLeft1 = Left(sString, 1)
1004 If (sLeft1 = &quot;&quot;&quot;&quot; Or sLeft1 = &quot;&apos;&quot;) And Len(sString) &gt; 2 Then .TargetName = Trim(Mid(sString, 2, Len(sString) - 2)) Else .TargetName = Trim(sString)
1005 Select Case .Target
1006 Case &quot;Bookmark&quot; : Set oColl = _Component.getBookmarks()
1007 Case &quot;Field&quot; : Set oColl = _Component.getTextFieldMasters()
1008 .TargetName = &quot;com.sun.star.text.fieldmaster.User.&quot; &amp; .TargetName
1009 If Not oColl.hasByName(.TargetName) Then .TargetName = Replace(.TargetName, &quot;.User.&quot;, &quot;.SetExpression.&quot;)
1010 Case &quot;Frame&quot; : Set oColl = _Component.getTextFrames()
1011 Case &quot;Section&quot; : Set oColl = _Component.getTextSections()
1012 End Select
1013 If .Target = &quot;Field&quot; Then vNames = Fields() Else vNames = oColl.getElementNames()
1014 If Not ScriptForge.SF_Utils._Validate(.TargetName, .Target, V_STRING, vNames, True) Then GoTo Finally
1015 Set .TargetObject = oColl.getByName(.TargetName)
1017 &apos; Set text, anchor and cursor: order varies depending on target
1018 Select Case .Target
1019 Case &quot;Bookmark&quot;, &quot;Field&quot;, &quot;Section&quot;
1020 If .Target = &quot;Field&quot; Then Set .Anchor = .TargetObject.DependentTextFields(0).Anchor Else Set .Anchor = .TargetObject.Anchor
1021 If .StartPoint And Not .EndPoint Then
1022 Set .Anchor = .Anchor.Start
1023 ElseIf Not .StartPoint And .EndPoint Then
1024 Set .Anchor = .Anchor.End
1025 End If
1026 Set .Text = .Anchor.Text
1027 Set .Cursor = .Text.createTextCursorByRange(.Anchor)
1028 Case &quot;Frame&quot;
1029 Set .Text = .TargetObject.Start.Text
1030 Set .Anchor = .Text.Anchor
1031 Set .Cursor = .Text.createTextCursor()
1032 If .StartPoint And Not .EndPoint Then
1033 .Cursor.gotoStart(False)
1034 ElseIf Not .StartPoint And .EndPoint Then
1035 .Cursor.gotoEnd(False)
1036 Else
1037 .Cursor.gotoStart(False)
1038 .Cursor.gotoEnd(True)
1039 End If
1040 Case Else
1041 End Select
1043 &apos; Body
1044 Case oStr.IsRegex(psTextRange, &quot;\|0\s*?BODY\s*\|?&quot;)
1045 Set .Text = _Component.Text
1046 Set .Anchor = .Text.Start
1047 Set .Cursor = .Text.createTextCursor()
1048 If .StartPoint And Not .EndPoint Then
1049 .Cursor.gotoStart(False)
1050 ElseIf Not .StartPoint And .EndPoint Then
1051 Set .Anchor = .Text.End
1052 .Cursor.gotoEnd(False)
1053 Else
1054 .Cursor.gotoStart(False)
1055 .Cursor.gotoEnd(True)
1056 End If
1058 &apos; Table cell
1059 Case oStr.IsRegex(psTextRange, &quot;\|?\s*TABLE!([\w\s]+|&apos;[^&apos;]+&apos;|&quot;&quot;[^&quot;&quot;]+&quot;&quot;)![\s]*[A-Za-z]+[1-9][0-9]*\s*\|?&quot;)
1060 .Target = &quot;TableCell&quot;
1061 &apos; Identify table by its name
1062 sString = Split(psTextRange, &quot;!&quot;)(1)
1063 sLeft1 = Left(sString, 1)
1064 If (sLeft1 = &quot;&quot;&quot;&quot; Or sLeft1 = &quot;&apos;&quot;) And Len(sString) &gt; 2 Then .TargetName = Trim(Mid(sString, 2, Len(sString) - 2)) Else .TargetName = Trim(sString)
1065 Set oColl = _Component.getTextTables()
1066 vNames = oColl.getElementNames()
1067 If Not ScriptForge.SF_Utils._Validate(.TargetName, .Target, V_STRING, vNames, True) Then GoTo Finally
1068 Set oItem = oColl.getByName(.TargetName)
1069 .TargetCell = Split(psTextRange, &quot;!&quot;)(2)
1070 &apos; Set text, anchor and cursor
1071 Set .TargetObject = oItem.getCellByName(.TargetCell)
1072 If IsNull(.TargetObject) Then GoTo CatchRange &apos; The given range is out of the scope of the table
1073 Set .Text = .TargetObject.Text
1074 Set .Anchor = .Text.Start
1075 Set .Cursor = .Text.createTextCursor()
1076 If .StartPoint And Not .EndPoint Then
1077 .Cursor.gotoStart(False)
1078 ElseIf Not .StartPoint And .EndPoint Then
1079 Set .Anchor = .Text.End
1080 .Cursor.gotoEnd(False)
1081 Else
1082 .Cursor.gotoStart(False)
1083 .Cursor.gotoEnd(True)
1084 End If
1086 Case Else
1087 GoTo CatchRange
1088 End Select
1090 &apos; Determine Location if not yet done
1091 If .Location = &quot;&quot; And Not IsNull(.Text) Then
1092 Select Case .Text.ImplementationName
1093 Case &quot;SwXBodyText&quot; : .Location = &quot;Body&quot;
1094 Case &quot;SwXTextFrame&quot; : .Location = &quot;Frame&quot;
1095 Case &quot;SwXCell&quot; : .Location = &quot;Cell&quot;
1096 Case &quot;SwXHeadFootText&quot; : .Location = &quot;Header/Footer&quot;
1097 Case &quot;SwXFootnote&quot; : .Location = &quot;Footnote/Endnote&quot;
1098 Case &quot;SwXShape&quot; : .Location = &quot;Shape&quot;
1099 Case Else : .Location = .Text.ImplementationName
1100 End Select
1101 End If
1103 End With
1105 Finally:
1106 Set _ParseRange = oTextRange
1107 Exit Function
1108 CatchError:
1109 ScriptForge.SF_Exception.Clear()
1110 CatchRange:
1111 ScriptForge.SF_Exception.RaiseFatal(WRITERRANGEERROR, &quot;TextRange&quot;, psTextRange _
1112 , &quot;Document&quot;, [_Super]._FileIdent())
1113 GoTo Finally
1114 End Function &apos; SFDocuments.SF_Writer._ParseRange
1116 REM -----------------------------------------------------------------------------
1117 Private Function _PropertyGet(Optional ByVal psProperty As String _
1118 , Optional ByVal pvArg As Variant _
1119 ) As Variant
1120 &apos;&apos;&apos; Return the value of the named property
1121 &apos;&apos;&apos; Args:
1122 &apos;&apos;&apos; psProperty: the name of the property
1124 Dim oFieldMasters As Object &apos; SwXTextFieldMasters
1125 Dim vMasters As Variant &apos; Array of SwXTextFieldMasters
1126 Dim oMaster As Object &apos; A single SwXTextFieldMasters
1127 Dim sField As String &apos; A text field full name
1128 Dim vFieldNames As Variant &apos; Array of field names as strings
1129 Dim cstThisSub As String
1130 Const cstSubArgs = &quot;&quot;
1132 _PropertyGet = False
1134 cstThisSub = &quot;SFDocuments.Writer.get&quot; &amp; psProperty
1135 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1136 If Not _IsStillAlive() Then GoTo Finally
1138 Select Case UCase(psProperty)
1139 Case UCase(&quot;Bookmarks&quot;)
1140 _PropertyGet = _Component.getBookmarks().getElementNames()
1141 Case UCase(&quot;CurrentSelection&quot;)
1142 _PropertyGet = _Component.CurrentSelection
1143 Case UCase(&quot;Fields&quot;)
1144 vFieldNames = Array()
1145 Set oFieldMasters = _Component.getTextFieldMasters()
1146 vMasters = oFieldMasters.getElementNames()
1147 For Each sField In vMasters
1148 If ScriptForge.SF_String.StartsWith(sField, &quot;com.sun.star.text.fieldmaster.User&quot;) Then
1149 Set oMaster = oFieldMasters.getByName(sField)
1150 vFieldNames = ScriptForge.SF_Array.InsertSorted(vFieldNames, oMaster.Name, CaseSensitive := True)
1151 ElseIf ScriptForge.SF_String.StartsWith(sField, &quot;com.sun.star.text.fieldmaster.SetExpression&quot;) Then
1152 Set oMaster = oFieldMasters.getByName(sField)
1153 If oMaster.SubType = com.sun.star.text.SetVariableType.VAR Then
1154 vFieldNames = ScriptForge.SF_Array.InsertSorted(vFieldNames, oMaster.Name, CaseSensitive := True)
1155 End If
1156 End If
1157 Next sField
1158 _PropertyGet = vFieldNames
1159 Case UCase(&quot;Frames&quot;)
1160 _PropertyGet = _Component.getTextFrames().getElementNames()
1161 Case Else
1162 _PropertyGet = Null
1163 End Select
1165 Finally:
1166 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1167 Exit Function
1168 End Function &apos; SFDocuments.SF_Writer._PropertyGet
1170 REM -----------------------------------------------------------------------------
1171 Private Function _Repr() As String
1172 &apos;&apos;&apos; Convert the SF_Writer instance to a readable string, typically for debugging purposes (DebugPrint ...)
1173 &apos;&apos;&apos; Args:
1174 &apos;&apos;&apos; Return:
1175 &apos;&apos;&apos; &quot;[DOCUMENT]: Type/File&quot;
1177 _Repr = &quot;[Writer]: &quot; &amp; [_Super]._FileIdent()
1179 End Function &apos; SFDocuments.SF_Writer._Repr
1181 REM ============================================ END OF SFDOCUMENTS.SF_WRITER
1182 </script:module>