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 =======================================================================================================================
14 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
15 ''' SF_Writer
16 ''' =========
18 ''' The SFDocuments library gathers a number of methods and properties making easy
19 ''' managing and manipulating LibreOffice documents
21 ''' Some methods are generic for all types of documents: they are combined in the SF_Document module.
22 ''' Specific properties and methods are implemented in the concerned subclass(es) SF_Calc, SF_Writer, SF_Base, ...
24 ''' To workaround the absence of class inheritance in LibreOffice Basic, some redundancy is necessary
25 ''' Each subclass MUST implement also the generic methods and properties, even if they only call
26 ''' the parent methods and properties.
27 ''' They should also duplicate some generic private members as a subset of their own set of members
29 ''' The SF_Writer module is focused on selecting, reading, inserting, modifying texts and values
30 ''' on well-identified and predefined places in the document.
31 ''' Usually such customization of the document starts from a predefined template.
32 ''' Multiple customizations are also known as mail merging.
34 ''' As a consequence, focus is not on text formatting, except by the application of styles
35 ''' onto the targeted text fragments.
37 ''' The positions in the text where customization can take place easily are:
38 ''' - the start and end positions of the text body
39 ''' - the start and end positions of text frames
40 ''' - bookmarks
41 ''' - text fields
42 ''' - the start and end positions of document sections
43 ''' - writer tables and table cells
44 ''' - the area currently selected by the user, i.e. the
"visible
" selection
46 ''' The current module is closely related to the
"UI
" service of the ScriptForge library
48 ''' Service invocation examples:
49 ''' 1) From the UI service
50 ''' Dim ui As Object, oDoc As Object
51 ''' Set ui = CreateScriptService(
"UI
")
52 ''' Set oDoc = ui.CreateDocument(
"Writer
", ...)
53 ''' ' or Set oDoc = ui.OpenDocument(
"C:\Me\MyFile.odt
")
54 ''' 2) Directly if the document is already opened
55 ''' Dim oDoc As Object
56 ''' Set oDoc = CreateScriptService(
"SFDocuments.Writer
", ThisComponent)
' Default = ActiveWindow
57 ''' ' or Set oDoc = CreateScriptService(
"SFDocuments.Writer
",
"Untitled
1")
' Untitled
1 is presumed a Writer document
58 ''' ' The substring
"SFDocuments.
" in the service name is optional
60 ''' Definitions:
61 ''' Many methods require a
"TextRange
" as argument.
62 ''' A textrange is a string describing the scope on which to apply the method.
63 ''' Such a textrange corresponds either with a single insertion point or with a (text) interval between
2 insertion points.
64 ''' Multiple textranges are not supported in this context.
66 ''' TextRange: a string containing one of next variants :
67 ''' (names may be surrounded with single or double quotes)
68 ''' "~
" or
"SELECTION
" or
"SEL
" = current selection (if multiple selections, its
1st component)
69 ''' "BODY
" = the main text of the actual document instance
70 ''' "FRAME!name
" = the text contained in a text frame
71 ''' "BOOKMARK!name
" = the given bookmark, may be zero or more characters long
72 ''' "FIELD!name
" = a user text field
73 ''' "SECTION!name
" = the text contained in a section
74 ''' "TABLE!name!
" = the whole cellrange of a table
75 ''' "TABLE!name!cellrange
" = a cell (cellrange =
"B3
") or a range of cells (
"A2:B3
")
76 ''' "WORD+
3" =
3 words after the current selection
77 ''' "SENTENCE-
1" = the sentence before the current selection
78 ''' "PARAGRAPH
" or
"ยง
" = the paragraph containing the current selection (
0 is the default)
79 ''' optionally combined with next control character:
80 ''' "|
": start or end of string
81 ''' "|~
" = the point immediately before the current visible selection (starting point)
82 ''' "~|
" = the point immediately after the current visible selection (ending point)
83 ''' "~
",
"|~|
" = the full visible selection
86 ''' Detailed user documentation:
87 ''' https://help.libreoffice.org/latest/en-US/text/sbasic/shared/
03/sf_writer.html?DbPAR=BASIC
89 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
91 REM ================================================================== EXCEPTIONS
93 Private Const WRITERFORMNOTFOUNDERROR =
"WRITERFORMNOTFOUNDERROR
"
94 Private Const WRITERRANGEERROR =
"WRITERRANGEERROR
"
96 REM ============================================================= PRIVATE MEMBERS
98 Private [Me] As Object
99 Private [_Parent] As Object
100 Private [_Super] As Object
' Document superclass, which the current instance is a subclass of
101 Private ObjectType As String
' Must be WRITER
102 Private ServiceName As String
104 ' Window component
105 Private _Component As Object
' com.sun.star.lang.XComponent
109 RangeString As String
' The input string
110 Target As String
' Selection or Body or Frame or ...
111 TargetName As String
' Name of Frame or Table or ...
112 TargetCell As String
' Cell
113 TargetObject As Object
' Field, TableCell, Section, ... object
114 Offset As Long
' Number of items to right (+) or to left (-)
115 StartPoint As Boolean
' When True, vertical bar before target
116 EndPoint As Boolean
' When True, vertical bar after target
117 Anchor As Object
' com.sun.star.text.XTextRange
118 Text As Object
' com.sun.star.text.XText
119 Cursor As Object
' com.sun.star.text.XTextCursor
120 Location As String
' BODY or FOOTNOTE or HEADER/FOOTER ...
123 REM ============================================================ MODULE CONSTANTS
125 Const ISDOCFORM =
1 ' Form is stored in a Writer document
127 REM ====================================================== CONSTRUCTOR/DESTRUCTOR
129 REM -----------------------------------------------------------------------------
130 Private Sub Class_Initialize()
132 Set [_Parent] = Nothing
133 Set [_Super] = Nothing
134 ObjectType =
"WRITER
"
135 ServiceName =
"SFDocuments.Writer
"
136 Set _Component = Nothing
137 End Sub
' SFDocuments.SF_Writer Constructor
139 REM -----------------------------------------------------------------------------
140 Private Sub Class_Terminate()
141 Call Class_Initialize()
142 End Sub
' 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
' SFDocuments.SF_Writer Explicit Destructor
151 REM ================================================================== PROPERTIES
153 REM -----------------------------------------------------------------------------
154 Property Get Bookmarks() As Variant
155 ''' Return the list of currently available bookmarks as a zero-based array
156 Bookmarks = _PropertyGet(
"Bookmarks
")
157 End Property
' SFDocuments.SF_Writer.Bookmarks (get)
159 REM -----------------------------------------------------------------------------
160 Property Get CurrentSelection() As Variant
161 ''' Return the list of currently available CurrentSelection as a zero-based array
162 CurrentSelection = _PropertyGet(
"CurrentSelection
")
163 End Property
' SFDocuments.SF_Writer.CurrentSelection (get)
165 REM -----------------------------------------------------------------------------
166 Property Let CurrentSelection(Optional ByVal pvSelection As Variant)
167 ''' Set the selection to a single or a multiple range
168 ''' The argument can be:
169 ''' - a string (a textrange)
170 ''' - a com.sun.star.text.XTextRange object
171 ''' - a collection of com.sun.star.text.XTextRange objects
173 Dim vSelection As Variant
' Alias of pvSelection
174 Dim oSelection As Object
' com.sun.star.text.XTextRange
175 Dim sType As String
' session.UnoObjectType()
176 Dim oSess As Object : Set oSess = ScriptForge.SF_Session
179 Const cstThisSub =
"SFDocuments.Writer.setCurrentSelection
"
180 Const cstSubArgs =
"Selection
"
182 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
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,
"Selection
", Array(V_STRING, ScriptForge.V_Object)) Then GoTo Finally
191 vSelection = pvSelection
' Necessary to avoid the
"Object variable not set
" 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)
197 sType = oSess.UnoObjectType(vSelection)
199 Case
"SwXTextRanges
" ' Argument is a multiple selection
200 For i =
0 To vSelection.Count -
1
201 If oSess.UnoObjectType(vSelection.getByIndex(i))
<> "SwXTextRange
" Then GoTo Catch
' Do nothing
204 Case
"SwXTextRange
",
"SwXTextCursor
",
"SwXTextTableCursor
" ' Argument is a simple selection (anchor/cursor)
212 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
216 End Property
' SFDocuments.SF_Writer.CurrentSelection (let)
218 REM -----------------------------------------------------------------------------
219 Property Get Fields() As Variant
220 ''' Return the list of currently available fields as a zero-based array
221 ''' Are considered only next field-types:
222 ''' - user fields: com.sun.star.text.textfield.User
223 ''' - variable fields: com.sun.star.text.textfield.SetExpression
224 Fields = _PropertyGet(
"Fields
")
225 End Property
' SFDocuments.SF_Writer.Fields (get)
227 REM -----------------------------------------------------------------------------
228 Property Get Frames() As Variant
229 ''' Return the list of currently available frames as a zero-based array
230 Frames = _PropertyGet(
"Frames
")
231 End Property
' SFDocuments.SF_Writer.Frames (get)
233 REM ===================================================================== METHODS
235 REM -----------------------------------------------------------------------------
236 Public Function Forms(Optional ByVal Form As Variant) As Variant
237 ''' Return either
238 ''' - the list of the Forms contained in the form document
239 ''' - a SFDocuments.Form object based on its name or its index
240 ''' Args:
241 ''' Form: a form stored in the document given by its name or its index
242 ''' When absent, the list of available forms is returned
243 ''' To get the first (unique ?) form stored in the form document, set Form =
0
244 ''' Exceptions:
245 ''' WRITERFORMNOTFOUNDERROR Form not found
246 ''' Returns:
247 ''' A zero-based array of strings if Form is absent
248 ''' An instance of the SF_Form class if Form exists
249 ''' Example:
250 ''' Dim myForm As Object, myList As Variant
251 ''' myList = oDoc.Forms()
252 ''' Set myForm = oDoc.Forms(
"myForm
")
254 Dim oForm As Object
' The new Form class instance
255 Dim oMainForm As Object
' com.sun.star.comp.sdb.Content
256 Dim oXForm As Object
' com.sun.star.form.XForm
257 Dim vFormNames As Variant
' Array of form names
258 Dim oForms As Object
' Forms collection
259 Const cstDrawPage =
0 ' Only
1 drawpage in a Writer document
261 Const cstThisSub =
"SFDocuments.Writer.Forms
"
262 Const cstSubArgs =
"[Form=
""""]
"
264 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
267 If IsMissing(Form) Or IsEmpty(Form) Then Form =
""
268 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
269 If Not _IsStillAlive() Then GoTo Finally
270 If Not ScriptForge.SF_Utils._Validate(Form,
"Form
", Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
274 ' 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
' Return the list of valid form names
281 If VarType(Form) = V_STRING Then
' 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
' Find the form by index
285 If Form
< 0 Or Form
>= oForms.Count Then GoTo CatchNotFound
286 Set oXForm = oForms.getByIndex(Form)
288 ' Create the new Form class instance
289 Set oForm = SF_Register._NewForm(oXForm)
291 Set .[_Parent] = [Me]
292 ._FormType = ISDOCFORM
293 Set ._Component = _Component
300 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
305 ScriptForge.SF_Exception.RaiseFatal(WRITERFORMNOTFOUNDERROR, Form, _FileIdent())
306 End Function
' SFDocuments.SF_Writer.Forms
308 REM -----------------------------------------------------------------------------
309 Public Function GetProperty(Optional ByVal PropertyName As Variant _
311 ''' Return the actual value of the given property
312 ''' Args:
313 ''' PropertyName: the name of the property as a string
314 ''' Returns:
315 ''' The actual value of the property
316 ''' Exceptions:
317 ''' ARGUMENTERROR The property does not exist
319 Const cstThisSub =
"SFDocuments.Writer.GetProperty
"
320 Const cstSubArgs =
""
322 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
326 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
327 If Not ScriptForge.SF_Utils._Validate(PropertyName,
"PropertyName
", V_STRING, Properties()) Then GoTo Catch
331 ' Superclass or subclass property ?
332 If ScriptForge.SF_Array.Contains([_Super].Properties(), PropertyName) Then
333 GetProperty = [_Super].GetProperty(PropertyName)
335 GetProperty = _PropertyGet(PropertyName)
339 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
343 End Function
' SFDocuments.SF_Writer.GetProperty
345 REM -----------------------------------------------------------------------------
346 Public Function Methods() As Variant
347 ''' Return the list of public methods of the Writer service as an array
351 ,
"PrintOut
" _
354 End Function
' 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 _
365 ''' Send the content of the document to the printer.
366 ''' The printer might be defined previously by default, by the user or by the SetPrinter() method
367 ''' Args:
368 ''' Pages: the pages to print as a string, like in the user interface. Example:
"1-
4;
10;
15-
18". Default = all pages
369 ''' Copies: the number of copies
370 ''' PrintBackground: print the background image when True (default)
371 ''' PrintBlankPages: when False (default), omit empty pages
372 ''' PrintEvenPages: print the left pages when True (default)
373 ''' PrintOddPages: print the right pages when True (default)
374 ''' PrintImages: print the graphic objects when True (default)
375 ''' Returns:
376 ''' True when successful
377 ''' Examples:
378 ''' oDoc.PrintOut(
"1-
4;
10;
15-
18", Copies :=
2, PrintImages := False)
380 Dim bPrint As Boolean
' Return value
381 Dim vPrintOptions As Variant
' com.sun.star.text.DocumentSettings
383 Const cstThisSub =
"SFDocuments.Writer.PrintOut
"
384 Const cstSubArgs =
"[Pages=
""""], [Copies=
1], [PrintBackground=True], [PrintBlankPages=False], [PrintEvenPages=True]
" _
385 & ", [PrintOddPages=True], [PrintImages=True]
"
387 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
391 If IsMissing(Pages) Or IsEmpty(Pages) Then Pages =
""
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,
"Pages
", V_STRING) Then GoTo Finally
402 If Not ScriptForge.SF_Utils._Validate(Copies,
"Copies
", ScriptForge.V_NUMERIC) Then GoTo Finally
403 If Not ScriptForge.SF_Utils._Validate(PrintBackground,
"PrintBackground
", ScriptForge.V_BOOLEAN) Then GoTo Finally
404 If Not ScriptForge.SF_Utils._Validate(PrintBlankPages,
"PrintBlankPages
", ScriptForge.V_BOOLEAN) Then GoTo Finally
405 If Not ScriptForge.SF_Utils._Validate(PrintEvenPages,
"PrintEvenPages
", ScriptForge.V_BOOLEAN) Then GoTo Finally
406 If Not ScriptForge.SF_Utils._Validate(PrintOddPages,
"PrintOddPages
", ScriptForge.V_BOOLEAN) Then GoTo Finally
407 If Not ScriptForge.SF_Utils._Validate(PrintImages,
"PrintImages
", ScriptForge.V_BOOLEAN) Then GoTo Finally
411 vPrintOptions = _Component.createInstance(
"com.sun.star.text.DocumentSettings
")
413 .PrintPageBackground = PrintBackground
414 .PrintEmptyPages = PrintBlankPages
415 .PrintLeftPages = PrintEvenPages
416 .PrintRightPages = PrintOddPages
417 .PrintGraphics = PrintImages
418 .PrintDrawings = PrintImages
421 bPrint = [_Super].PrintOut(Pages, Copies, _Component)
425 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
429 End Function
' SFDocuments.SF_Writer.PrintOut
431 REM -----------------------------------------------------------------------------
432 Public Function Properties() As Variant
433 ''' Return the list or properties of the Writer class as an array
435 Properties = Array( _
436 "Bookmarks
" _
437 ,
"CurrentSelection
" _
438 ,
"CustomProperties
" _
439 ,
"Description
" _
440 ,
"DocumentProperties
" _
441 ,
"DocumentType
" _
442 ,
"ExportFilters
" _
443 ,
"Fields
" _
444 ,
"FileSystem
" _
445 ,
"Frames
" _
446 ,
"ImportFilters
" _
447 ,
"IsAlive
" _
448 ,
"IsBase
" _
449 ,
"IsCalc
" _
450 ,
"IsDraw
" _
451 ,
"IsFormDocument
" _
452 ,
"IsImpress
" _
453 ,
"IsMath
" _
454 ,
"IsWriter
" _
455 ,
"Keywords
" _
456 ,
"Readonly
" _
457 ,
"StyleFamilies
" _
458 ,
"Subject
" _
459 ,
"Title
" _
460 ,
"XComponent
" _
461 ,
"XDocumentSettings
" _
464 End Function
' SFDocuments.SF_Writer.Properties
466 REM -----------------------------------------------------------------------------
467 Private Function SetProperty(Optional ByVal psProperty As String _
468 , Optional ByVal pvValue As Variant _
470 ''' Set the new value of the named property
471 ''' Args:
472 ''' psProperty: the name of the property
473 ''' pvValue: the new value of the given property
474 ''' Returns:
475 ''' True if successful
477 Dim bSet As Boolean
' Return value
478 Static oSession As Object
' Alias of SF_Session
479 Dim cstThisSub As String
480 Const cstSubArgs =
"Value
"
482 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
485 cstThisSub =
"SFDocuments.Writer.set
" & psProperty
486 If IsMissing(pvValue) Then pvValue = Empty
487 'ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
' Validation done in Property Lets
489 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(
"Session
")
491 Select Case UCase(psProperty)
492 Case UCase(
"CustomProperties
")
493 CustomProperties = pvValue
494 Case UCase(
"Description
")
495 Description = pvValue
496 Case UCase(
"Keywords
")
498 Case UCase(
"Subject
")
500 Case UCase(
"Title
")
508 'ScriptForge.SF_Utils._ExitFunction(cstThisSub)
512 End Function
' SFDocuments.SF_Writer.SetProperty
514 REM ======================================================= SUPERCLASS PROPERTIES
516 REM -----------------------------------------------------------------------------
517 Property Get CustomProperties() As Variant
518 CustomProperties = [_Super].GetProperty(
"CustomProperties
")
519 End Property
' SFDocuments.SF_Writer.CustomProperties
521 REM -----------------------------------------------------------------------------
522 Property Let CustomProperties(Optional ByVal pvCustomProperties As Variant)
523 [_Super].CustomProperties = pvCustomProperties
524 End Property
' SFDocuments.SF_Writer.CustomProperties
526 REM -----------------------------------------------------------------------------
527 Property Get Description() As Variant
528 Description = [_Super].GetProperty(
"Description
")
529 End Property
' SFDocuments.SF_Writer.Description
531 REM -----------------------------------------------------------------------------
532 Property Let Description(Optional ByVal pvDescription As Variant)
533 [_Super].Description = pvDescription
534 End Property
' SFDocuments.SF_Writer.Description
536 REM -----------------------------------------------------------------------------
537 Property Get DocumentProperties() As Variant
538 DocumentProperties = [_Super].GetProperty(
"DocumentProperties
")
539 End Property
' SFDocuments.SF_Writer.DocumentProperties
541 REM -----------------------------------------------------------------------------
542 Property Get DocumentType() As String
543 DocumentType = [_Super].GetProperty(
"DocumentType
")
544 End Property
' SFDocuments.SF_Writer.DocumentType
546 REM -----------------------------------------------------------------------------
547 Property Get ExportFilters() As Variant
548 ExportFilters = [_Super].GetProperty(
"ExportFilters
")
549 End Property
' SFDocuments.SF_Writer.ExportFilters
551 REM -----------------------------------------------------------------------------
552 Property Get FileSystem() As String
553 FileSystem = [_Super].GetProperty(
"FileSystem
")
554 End Property
' SFDocuments.SF_Writer.FileSystem
556 REM -----------------------------------------------------------------------------
557 Property Get ImportFilters() As Variant
558 ImportFilters = [_Super].GetProperty(
"ImportFilters
")
559 End Property
' SFDocuments.SF_Writer.ImportFilters
561 REM -----------------------------------------------------------------------------
562 Property Get IsAlive() As Boolean
563 IsAlive = [_Super].GetProperty(
"IsAlive
")
564 End Property
' SFDocuments.SF_Writer.IsAlive
566 REM -----------------------------------------------------------------------------
567 Property Get IsBase() As Boolean
568 IsBase = [_Super].GetProperty(
"IsBase
")
569 End Property
' SFDocuments.SF_Writer.IsBase
571 REM -----------------------------------------------------------------------------
572 Property Get IsCalc() As Boolean
573 IsCalc = [_Super].GetProperty(
"IsCalc
")
574 End Property
' SFDocuments.SF_Writer.IsCalc
576 REM -----------------------------------------------------------------------------
577 Property Get IsDraw() As Boolean
578 IsDraw = [_Super].GetProperty(
"IsDraw
")
579 End Property
' SFDocuments.SF_Writer.IsDraw
581 REM -----------------------------------------------------------------------------
582 Property Get IsFormDocument() As Boolean
583 IsFormDocument = [_Super].GetProperty(
"IsFormDocument
")
584 End Property
' SFDocuments.SF_Writer.IsFormDocument
586 REM -----------------------------------------------------------------------------
587 Property Get IsImpress() As Boolean
588 IsImpress = [_Super].GetProperty(
"IsImpress
")
589 End Property
' SFDocuments.SF_Writer.IsImpress
591 REM -----------------------------------------------------------------------------
592 Property Get IsMath() As Boolean
593 IsMath = [_Super].GetProperty(
"IsMath
")
594 End Property
' SFDocuments.SF_Writer.IsMath
596 REM -----------------------------------------------------------------------------
597 Property Get IsWriter() As Boolean
598 IsWriter = [_Super].GetProperty(
"IsWriter
")
599 End Property
' SFDocuments.SF_Writer.IsWriter
601 REM -----------------------------------------------------------------------------
602 Property Get Keywords() As Variant
603 Keywords = [_Super].GetProperty(
"Keywords
")
604 End Property
' SFDocuments.SF_Writer.Keywords
606 REM -----------------------------------------------------------------------------
607 Property Let Keywords(Optional ByVal pvKeywords As Variant)
608 [_Super].Keywords = pvKeywords
609 End Property
' SFDocuments.SF_Writer.Keywords
611 REM -----------------------------------------------------------------------------
612 Property Get Readonly() As Variant
613 Readonly = [_Super].GetProperty(
"Readonly
")
614 End Property
' SFDocuments.SF_Writer.Readonly
616 REM -----------------------------------------------------------------------------
617 Property Get StyleFamilies() As Variant
618 StyleFamilies = [_Super].GetProperty(
"StyleFamilies
")
619 End Property
' SFDocuments.SF_Writer.StyleFamilies
621 REM -----------------------------------------------------------------------------
622 Property Get Subject() As Variant
623 Subject = [_Super].GetProperty(
"Subject
")
624 End Property
' SFDocuments.SF_Writer.Subject
626 REM -----------------------------------------------------------------------------
627 Property Let Subject(Optional ByVal pvSubject As Variant)
628 [_Super].Subject = pvSubject
629 End Property
' SFDocuments.SF_Writer.Subject
631 REM -----------------------------------------------------------------------------
632 Property Get Title() As Variant
633 Title = [_Super].GetProperty(
"Title
")
634 End Property
' SFDocuments.SF_Writer.Title
636 REM -----------------------------------------------------------------------------
637 Property Let Title(Optional ByVal pvTitle As Variant)
638 [_Super].Title = pvTitle
639 End Property
' SFDocuments.SF_Writer.Title
641 REM -----------------------------------------------------------------------------
642 Property Get XComponent() As Variant
643 XComponent = [_Super].GetProperty(
"XComponent
")
644 End Property
' SFDocuments.SF_Writer.XComponent
646 REM -----------------------------------------------------------------------------
647 Property Get XDocumentSettings() As Variant
648 XDocumentSettings = [_Super].GetProperty(
"XDocumentSettings
")
649 End Property
' SFDocuments.SF_Writer.XDocumentSettings
651 REM ========================================================== SUPERCLASS METHODS
653 REM -----------------------------------------------------------------------------
654 Public Function Activate() As Boolean
655 Activate = [_Super].Activate()
656 End Function
' 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
' SFDocuments.SF_Writer.CloseDocument
663 REM -----------------------------------------------------------------------------
664 Public Function ContextMenus(Optional ByVal ContextMenuName As Variant _
665 , Optional ByVal SubmenuChar As Variant _
667 ContextMenus = [_Super].ContextMenus(ContextMenuName, SubmenuChar)
668 End Function
' 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 _
675 Set CreateMenu = [_Super].CreateMenu(MenuHeader, Before, SubmenuChar)
676 End Function
' 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
' 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
' 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 _
699 ExportAsPDF = [_Super].ExportAsPDF(FileName, Overwrite, Pages, Password, Watermark)
700 End Function
' 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 _
707 [_Super]._ImportStylesFromFile(FileName, Families, Overwrite)
708 End Sub
' 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
' 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
' SFDocuments.SF_Writer.RunCommand
722 REM -----------------------------------------------------------------------------
723 Public Function Save() As Boolean
724 Save = [_Super].Save()
725 End Function
' 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 _
734 SaveAs = [_Super].SaveAs(FileName, Overwrite, Password, FilterName, FilterOptions)
735 End Function
' 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 _
744 SaveCopyAs = [_Super].SaveCopyAs(FileName, Overwrite, Password, FilterName, FilterOptions)
745 End Function
' 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 _
752 SetPrinter = [_Super].SetPrinter(Printer, Orientation, PaperFormat)
753 End Function
' 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 _
763 Styles = [_Super].Styles(Family, NamePattern, Used, UserDefined, ParentStyle, Category)
764 End Function
' 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
' SFDocuments.SF_Writer.Toolbars
771 REM -----------------------------------------------------------------------------
772 Public Function XStyle(Optional ByVal Family As Variant _
773 , Optional ByVal StyleName As variant _
775 Set XStyle = [_Super].XStyle(Family, StyleName)
776 End Function
' SFDocuments.SF_Writer.XStyle
778 REM =========================================================== PRIVATE FUNCTIONS
780 REM -----------------------------------------------------------------------------
781 Private Function _FileIdent() As String
782 ''' Returns a file identification from the information that is currently available
783 ''' Useful e.g. for display in error messages
785 _FileIdent = [_Super]._FileIdent()
787 End Function
' SFDocuments.SF_Writer._FileIdent
789 REM -----------------------------------------------------------------------------
790 Private Function _IsStillAlive(Optional ByVal pbForUpdate As Boolean _
791 , Optional ByVal pbError As Boolean _
793 ''' Returns True if the document has not been closed manually or incidentally since the last use
794 ''' If dead the actual instance is disposed. The execution is cancelled when pbError = True (default)
795 ''' Args:
796 ''' pbForUpdate: if True (default = False), check additionally if document is open for editing
797 ''' pbError: if True (default), raise a fatal error
799 Dim bAlive As Boolean
' Return value
801 If IsMissing(pbForUpdate) Then pbForUpdate = False
802 If IsMissing(pbError) Then pbError = True
805 bAlive = [_Super]._IsStillAlive(pbForUpdate, pbError)
808 _IsStillAlive = bAlive
810 End Function
' SFDocuments.SF_Writer._IsStillAlive
812 REM -----------------------------------------------------------------------------
813 Private Function _ParseRange(psTextRange As String) As Object
814 ''' Parse and validate a text range passed as a string
815 ''' Syntax to parse:
816 ''' [|]~ or
"SELECTION
" or
"SEL
"[|]
817 ''' [|]BODY[|]
818 ''' [|]FRAME!name[|]
819 ''' BOOKMARK!name
820 ''' FIELD!name
821 ''' [|]SECTION!name[|]
822 ''' TABLE!name!cell
823 ''' [|]WORDยฑn[|]
824 ''' [|]SENTENCEยฑn[|]
825 ''' [|]PARAGRAPHยฑn or ยงยฑn[|]
826 ''' A name must be surrounded with single or double quotes when it contains a space or a not alphanumeric character
827 ''' Returns:
828 ''' An object of type _TextRange
829 ''' Exceptions:
830 ''' WRITERRANGEERROR
' Text range could not be parsed to a valid location
832 Dim oTextRange As Object
' Return value
833 Dim bParsing As Boolean
' When True, parsing could identify the target
834 Dim lSelects As Long
' Number of items in the current selection
835 Dim sTarget As String
' Alias of _TextRange.Target
836 Dim sString As String
' Work variable
837 Dim sLeft1 As String
' The
1st character of sString
838 Dim sSign As String
' + or -
839 Dim oColl As Object
' Collection of TargetObjects (bookmarks or frames or ...)
840 Dim oItem As Object
' An item in the oColl collection
841 Dim vNames As Variant
' Array of the available object names within a collection
842 Dim oStr As Object : Set oStr = ScriptForge.SF_String
843 Dim bMove As Boolean
' Return value of a cursor move
846 ' Reinitialize a new _TextRange object
847 Set oTextRange = New _TextRange
849 Set .TargetObject = Nothing
850 .RangeString =
"" : .Target =
"" : .TargetName =
"" : .TargetCell =
""
851 .Offset =
0 : .StartPoint = False : .EndPoint = False
852 Set .Anchor = Nothing : Set .Text = Nothing : Set .Cursor = Nothing
853 .Location =
""
856 ' Identify the type of range with adequate regular expressions
858 .RangeString = psTextRange
859 .StartPoint = ( Left(psTextRange,
1) =
"|
" )
860 .EndPoint = ( Right(psTextRange,
1) =
"|
" )
863 ' Parsing is done with regular expressions because names may really contain any character, including
"รง
"
866 Case oStr.IsRegex(psTextRange,
"\|?\s*(~|SEL|SELECTION)\s*\|?
")
867 .Target =
"Selection
"
868 If _Component.CurrentSelection.ImplementationName =
"SwXTextRanges
" Then
869 lSelects = _Component.CurrentSelection.Count
870 If lSelects
> 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
877 Set .Text = .Anchor.Text
878 Set .Cursor = .Text.createTextCursorByRange(.Anchor)
881 If IsNull(.Cursor) Then .Location = _Component.CurrentSelection.ImplementationName
883 ' WORD, SENTENCE, PARAGRAPH
884 Case oStr.IsRegex(psTextRange,
"\|?\s*(PARAGRAPH|ยง|SENTENCE|WORD)\s*([+-][
0-
9]+)?\s*\|?
")
885 If InStr(psTextRange,
"+
")
> 0 Then
886 sSign =
"+
"
887 ElseIf InStr(psTextRange,
"-
")
> 0 Then
890 If Len(sSign)
> 0 Then sTarget = Split(psTextRange, sSign)(
0) Else sTarget = psTextRange
891 If InStr(Iif(.StartPoint,
2,
1), sTarget,
"PARAGRAPH
",
1)
> 0 Or InStr(Iif(.StartPoint,
2,
1), sTarget,
"ยง
",
1)
> 0 Then
892 .Target =
"Paragraph
"
893 ElseIf InStr(Iif(.StartPoint,
2,
1), sTarget,
"SENTENCE
",
1)
> 0 Then
894 .Target =
"Sentence
"
895 ElseIf InStr(Iif(.StartPoint,
2,
1), sTarget,
"WORD
",
1)
> 0 Then
896 .Target =
"Word
"
899 ' Identify the offset
900 If Len(sSign) =
0 Then
903 sString = Split(psTextRange, sSign)(
1)
904 If .EndPoint Then sString = Left(sString, Len(sString) -
1)
905 .Offset = CLng(sString) * Iif(sSign =
"+
",
1, -
1)
908 ' Build the cursor pointing at the current selection
909 If _Component.CurrentSelection.ImplementationName =
"SwXTextRanges
" Then
910 lSelects = _Component.CurrentSelection.Count
911 If lSelects
> 0 Then
912 Set .Anchor = _Component.CurrentSelection.getByIndex(lSelects -
1)
913 Set .Text = .Anchor.Text
914 Set .Cursor = .Text.createTextCursorByRange(.Anchor)
917 If IsNull(.Cursor) Then
918 .Location = _Component.CurrentSelection.ImplementationName
920 ' Move the cursor to the requested area
922 Select Case oTextRange.Target
923 Case
"Word
"
924 bMove = .gotoStartOfWord(False)
926 For i =
1 To Abs(oTextRange.Offset)
927 If sSign =
"+
" Then bMove = .gotoNextWord(False) Else bMove = .gotoPreviousWord(False)
928 If sSign =
"+
" Then
929 If Not bMove Then Exit For
930 If .isEndOfSentence() Then i = i -
1 ' Loop to do once more
932 bMove = .goLeft(
1, False)
' Additional trial to bypass some locks (tabs, list items, ... ?)
933 If Not bMove Then Exit For
937 ' 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
943 Case
"Sentence
"
944 bMove = .gotoStartOfSentence(False)
946 For i =
1 To Abs(oTextRange.Offset)
947 If sSign =
"+
" Then bMove = .gotoNextSentence(False) Else bMove = .gotoPreviousSentence(False)
948 If sSign =
"+
" Then
949 If .isEndOfParagraph() Then bMove = .goRight(
1, False)
951 bMove = .goLeft(
1, False)
' Additional trial to bypass some locks (tabs, list items, ... ?)
952 If .isStartOfParagraph() Then bMove = .goLeft(
1, False)
954 If Not bMove Then Exit For
957 ' 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)
963 Case
"Paragraph
"
964 bMove = .gotoStartOfParagraph(False)
966 For i =
1 To Abs(oTextRange.Offset)
967 If sSign =
"+
" Then bMove = .gotoNextParagraph(False) Else bMove = .gotoPreviousParagraph(False)
968 If sSign =
"+
" Then
969 If .isEndOfParagraph() Then bMove = .goRight(
1, False)
971 bMove = .goLeft(
1, False)
' Additional trial to bypass some locks (tabs, list items, ... ?)
972 If .isStartOfParagraph() Then bMove = .goLeft(
1, False)
974 If Not bMove Then Exit For
977 ' 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)
987 ' Bookmarks, Fields, Frames, Sections
988 Case oStr.IsRegex(psTextRange,
"\|?\s*(BOOKMARK|FIELD|FRAME|SECTION)!([\w\s]+|
'[^
']+
'|
""[^
""]+
"")\|?
")
989 sTarget = Split(psTextRange,
"!
")(
0)
990 If InStr(Iif(.StartPoint,
2,
1), sTarget,
"BOOKMARK
",
1)
> 0 Then
991 .Target =
"Bookmark
"
992 ElseIf InStr(Iif(.StartPoint,
2,
1), sTarget,
"FIELD
",
1)
> 0 Then
993 .Target =
"Field
"
994 ElseIf InStr(Iif(.StartPoint,
2,
1), sTarget,
"FRAME
",
1)
> 0 Then
995 .Target =
"Frame
"
996 ElseIf InStr(Iif(.StartPoint,
2,
1), sTarget,
"SECTION
",
1)
> 0 Then
997 .Target =
"Section
"
1000 ' Identify section or frame or bookmark or field by its name
1001 sString = Split(psTextRange,
"!
")(
1)
1002 If .EndPoint Then sString = Left(sString, Len(sString) -
1)
1003 sLeft1 = Left(sString,
1)
1004 If (sLeft1 =
"""" Or sLeft1 =
"'") And Len(sString)
> 2 Then .TargetName = Trim(Mid(sString,
2, Len(sString) -
2)) Else .TargetName = Trim(sString)
1006 Case
"Bookmark
" : Set oColl = _Component.getBookmarks()
1007 Case
"Field
" : Set oColl = _Component.getTextFieldMasters()
1008 .TargetName =
"com.sun.star.text.fieldmaster.User.
" & .TargetName
1009 If Not oColl.hasByName(.TargetName) Then .TargetName = Replace(.TargetName,
".User.
",
".SetExpression.
")
1010 Case
"Frame
" : Set oColl = _Component.getTextFrames()
1011 Case
"Section
" : Set oColl = _Component.getTextSections()
1013 If .Target =
"Field
" 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 ' Set text, anchor and cursor: order varies depending on target
1019 Case
"Bookmark
",
"Field
",
"Section
"
1020 If .Target =
"Field
" 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
1026 Set .Text = .Anchor.Text
1027 Set .Cursor = .Text.createTextCursorByRange(.Anchor)
1028 Case
"Frame
"
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)
1037 .Cursor.gotoStart(False)
1038 .Cursor.gotoEnd(True)
1044 Case oStr.IsRegex(psTextRange,
"\|
0\s*?BODY\s*\|?
")
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)
1054 .Cursor.gotoStart(False)
1055 .Cursor.gotoEnd(True)
1059 Case oStr.IsRegex(psTextRange,
"\|?\s*TABLE!([\w\s]+|
'[^
']+
'|
""[^
""]+
"")![\s]*[A-Za-z]+[
1-
9][
0-
9]*\s*\|?
")
1060 .Target =
"TableCell
"
1061 ' Identify table by its name
1062 sString = Split(psTextRange,
"!
")(
1)
1063 sLeft1 = Left(sString,
1)
1064 If (sLeft1 =
"""" Or sLeft1 =
"'") And Len(sString)
> 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,
"!
")(
2)
1070 ' Set text, anchor and cursor
1071 Set .TargetObject = oItem.getCellByName(.TargetCell)
1072 If IsNull(.TargetObject) Then GoTo CatchRange
' 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)
1082 .Cursor.gotoStart(False)
1083 .Cursor.gotoEnd(True)
1090 ' Determine Location if not yet done
1091 If .Location =
"" And Not IsNull(.Text) Then
1092 Select Case .Text.ImplementationName
1093 Case
"SwXBodyText
" : .Location =
"Body
"
1094 Case
"SwXTextFrame
" : .Location =
"Frame
"
1095 Case
"SwXCell
" : .Location =
"Cell
"
1096 Case
"SwXHeadFootText
" : .Location =
"Header/Footer
"
1097 Case
"SwXFootnote
" : .Location =
"Footnote/Endnote
"
1098 Case
"SwXShape
" : .Location =
"Shape
"
1099 Case Else : .Location = .Text.ImplementationName
1106 Set _ParseRange = oTextRange
1109 ScriptForge.SF_Exception.Clear()
1111 ScriptForge.SF_Exception.RaiseFatal(WRITERRANGEERROR,
"TextRange
", psTextRange _
1112 ,
"Document
", [_Super]._FileIdent())
1114 End Function
' SFDocuments.SF_Writer._ParseRange
1116 REM -----------------------------------------------------------------------------
1117 Private Function _PropertyGet(Optional ByVal psProperty As String _
1118 , Optional ByVal pvArg As Variant _
1120 ''' Return the value of the named property
1121 ''' Args:
1122 ''' psProperty: the name of the property
1124 Dim oFieldMasters As Object
' SwXTextFieldMasters
1125 Dim vMasters As Variant
' Array of SwXTextFieldMasters
1126 Dim oMaster As Object
' A single SwXTextFieldMasters
1127 Dim sField As String
' A text field full name
1128 Dim vFieldNames As Variant
' Array of field names as strings
1129 Dim cstThisSub As String
1130 Const cstSubArgs =
""
1132 _PropertyGet = False
1134 cstThisSub =
"SFDocuments.Writer.get
" & psProperty
1135 ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
1136 If Not _IsStillAlive() Then GoTo Finally
1138 Select Case UCase(psProperty)
1139 Case UCase(
"Bookmarks
")
1140 _PropertyGet = _Component.getBookmarks().getElementNames()
1141 Case UCase(
"CurrentSelection
")
1142 _PropertyGet = _Component.CurrentSelection
1143 Case UCase(
"Fields
")
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,
"com.sun.star.text.fieldmaster.User
") 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,
"com.sun.star.text.fieldmaster.SetExpression
") 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)
1158 _PropertyGet = vFieldNames
1159 Case UCase(
"Frames
")
1160 _PropertyGet = _Component.getTextFrames().getElementNames()
1166 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
1168 End Function
' SFDocuments.SF_Writer._PropertyGet
1170 REM -----------------------------------------------------------------------------
1171 Private Function _Repr() As String
1172 ''' Convert the SF_Writer instance to a readable string, typically for debugging purposes (DebugPrint ...)
1173 ''' Args:
1174 ''' Return:
1175 ''' "[DOCUMENT]: Type/File
"
1177 _Repr =
"[Writer]:
" & [_Super]._FileIdent()
1179 End Function
' SFDocuments.SF_Writer._Repr
1181 REM ============================================ END OF SFDOCUMENTS.SF_WRITER