SF_Writer.xba 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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 =======================================================================================================================
  8. Option Compatible
  9. Option ClassModule
  10. Option Explicit
  11. &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
  12. &apos;&apos;&apos; SF_Writer
  13. &apos;&apos;&apos; =========
  14. &apos;&apos;&apos;
  15. &apos;&apos;&apos; The SFDocuments library gathers a number of methods and properties making easy
  16. &apos;&apos;&apos; managing and manipulating LibreOffice documents
  17. &apos;&apos;&apos;
  18. &apos;&apos;&apos; Some methods are generic for all types of documents: they are combined in the SF_Document module.
  19. &apos;&apos;&apos; Specific properties and methods are implemented in the concerned subclass(es) SF_Calc, SF_Writer, SF_Base, ...
  20. &apos;&apos;&apos;
  21. &apos;&apos;&apos; To workaround the absence of class inheritance in LibreOffice Basic, some redundancy is necessary
  22. &apos;&apos;&apos; Each subclass MUST implement also the generic methods and properties, even if they only call
  23. &apos;&apos;&apos; the parent methods and properties.
  24. &apos;&apos;&apos; They should also duplicate some generic private members as a subset of their own set of members
  25. &apos;&apos;&apos;
  26. &apos;&apos;&apos; The SF_Writer module is focused on :
  27. &apos;&apos;&apos; TBD
  28. &apos;&apos;&apos;
  29. &apos;&apos;&apos; The current module is closely related to the &quot;UI&quot; service of the ScriptForge library
  30. &apos;&apos;&apos;
  31. &apos;&apos;&apos; Service invocation examples:
  32. &apos;&apos;&apos; 1) From the UI service
  33. &apos;&apos;&apos; Dim ui As Object, oDoc As Object
  34. &apos;&apos;&apos; Set ui = CreateScriptService(&quot;UI&quot;)
  35. &apos;&apos;&apos; Set oDoc = ui.CreateDocument(&quot;Writer&quot;, ...)
  36. &apos;&apos;&apos; &apos; or Set oDoc = ui.OpenDocument(&quot;C:\Me\MyFile.odt&quot;)
  37. &apos;&apos;&apos; 2) Directly if the document is already opened
  38. &apos;&apos;&apos; Dim oDoc As Object
  39. &apos;&apos;&apos; Set oDoc = CreateScriptService(&quot;SFDocuments.Writer&quot;, &quot;Untitled 1&quot;) &apos; Default = ActiveWindow
  40. &apos;&apos;&apos; &apos; or Set oDoc = CreateScriptService(&quot;SFDocuments.Writer&quot;, &quot;Untitled 1&quot;) &apos; Untitled 1 is presumed a Writer document
  41. &apos;&apos;&apos; &apos; The substring &quot;SFDocuments.&quot; in the service name is optional
  42. &apos;&apos;&apos;
  43. &apos;&apos;&apos; Definitions:
  44. &apos;&apos;&apos; TBD
  45. &apos;&apos;&apos;
  46. &apos;&apos;&apos; Detailed user documentation:
  47. &apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/SF_Writer.html?DbPAR=BASIC
  48. &apos;&apos;&apos;
  49. &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
  50. REM ================================================================== EXCEPTIONS
  51. Private Const WRITERFORMNOTFOUNDERROR = &quot;WRITERFORMNOTFOUNDERROR&quot;
  52. REM ============================================================= PRIVATE MEMBERS
  53. Private [Me] As Object
  54. Private [_Parent] As Object
  55. Private [_Super] As Object &apos; Document superclass, which the current instance is a subclass of
  56. Private ObjectType As String &apos; Must be WRITER
  57. Private ServiceName As String
  58. &apos; Window component
  59. Private _Component As Object &apos; com.sun.star.lang.XComponent
  60. REM ============================================================ MODULE CONSTANTS
  61. REM ====================================================== CONSTRUCTOR/DESTRUCTOR
  62. REM -----------------------------------------------------------------------------
  63. Private Sub Class_Initialize()
  64. Set [Me] = Nothing
  65. Set [_Parent] = Nothing
  66. Set [_Super] = Nothing
  67. ObjectType = &quot;WRITER&quot;
  68. ServiceName = &quot;SFDocuments.Writer&quot;
  69. Set _Component = Nothing
  70. End Sub &apos; SFDocuments.SF_Writer Constructor
  71. REM -----------------------------------------------------------------------------
  72. Private Sub Class_Terminate()
  73. Call Class_Initialize()
  74. End Sub &apos; SFDocuments.SF_Writer Destructor
  75. REM -----------------------------------------------------------------------------
  76. Public Function Dispose() As Variant
  77. If Not IsNull([_Super]) Then Set [_Super] = [_Super].Dispose()
  78. Call Class_Terminate()
  79. Set Dispose = Nothing
  80. End Function &apos; SFDocuments.SF_Writer Explicit Destructor
  81. REM ================================================================== PROPERTIES
  82. REM ===================================================================== METHODS
  83. REM -----------------------------------------------------------------------------
  84. Public Function Forms(Optional ByVal Form As Variant) As Variant
  85. &apos;&apos;&apos; Return either
  86. &apos;&apos;&apos; - the list of the Forms contained in the form document
  87. &apos;&apos;&apos; - a SFDocuments.Form object based on its name or its index
  88. &apos;&apos;&apos; Args:
  89. &apos;&apos;&apos; Form: a form stored in the document given by its name or its index
  90. &apos;&apos;&apos; When absent, the list of available forms is returned
  91. &apos;&apos;&apos; To get the first (unique ?) form stored in the form document, set Form = 0
  92. &apos;&apos;&apos; Exceptions:
  93. &apos;&apos;&apos; WRITERFORMNOTFOUNDERROR Form not found
  94. &apos;&apos;&apos; Returns:
  95. &apos;&apos;&apos; A zero-based array of strings if Form is absent
  96. &apos;&apos;&apos; An instance of the SF_Form class if Form exists
  97. &apos;&apos;&apos; Example:
  98. &apos;&apos;&apos; Dim myForm As Object, myList As Variant
  99. &apos;&apos;&apos; myList = oDoc.Forms()
  100. &apos;&apos;&apos; Set myForm = oDoc.Forms(&quot;myForm&quot;)
  101. Dim oForm As Object &apos; The new Form class instance
  102. Dim oMainForm As Object &apos; com.sun.star.comp.sdb.Content
  103. Dim oXForm As Object &apos; com.sun.star.form.XForm
  104. Dim vFormNames As Variant &apos; Array of form names
  105. Dim oForms As Object &apos; Forms collection
  106. Const cstDrawPage = 0 &apos; Only 1 drawpage in a Writer document
  107. Const cstThisSub = &quot;SFDocuments.Writer.Forms&quot;
  108. Const cstSubArgs = &quot;[Form=&quot;&quot;&quot;&quot;]&quot;
  109. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  110. Check:
  111. If IsMissing(Form) Or IsEmpty(Form) Then Form = &quot;&quot;
  112. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  113. If Not _IsStillAlive() Then GoTo Finally
  114. If Not ScriptForge.SF_Utils._Validate(Form, &quot;Form&quot;, Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
  115. End If
  116. Try:
  117. &apos; Start from the document component and go down to forms
  118. Set oForms = _Component.DrawPages(cstDrawPage).Forms
  119. vFormNames = oForms.getElementNames()
  120. If Len(Form) = 0 Then &apos; Return the list of valid form names
  121. Forms = vFormNames
  122. Else
  123. If VarType(Form) = V_STRING Then &apos; Find the form by name
  124. If Not ScriptForge.SF_Array.Contains(vFormNames, Form, CaseSensitive := True) Then GoTo CatchNotFound
  125. Set oXForm = oForms.getByName(Form)
  126. Else &apos; Find the form by index
  127. If Form &lt; 0 Or Form &gt;= oForms.Count Then GoTo CatchNotFound
  128. Set oXForm = oForms.getByIndex(Form)
  129. End If
  130. &apos; Create the new Form class instance
  131. Set oForm = SF_Register._NewForm(oXForm)
  132. With oForm
  133. Set .[_Parent] = [Me]
  134. ._FormType = ISDOCFORM
  135. Set ._Component = _Component
  136. ._Initialize()
  137. End With
  138. Set Forms = oForm
  139. End If
  140. Finally:
  141. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  142. Exit Function
  143. Catch:
  144. GoTo Finally
  145. CatchNotFound:
  146. ScriptForge.SF_Exception.RaiseFatal(WRITERFORMNOTFOUNDERROR, Form, _FileIdent())
  147. End Function &apos; SFDocuments.SF_Writer.Forms
  148. REM -----------------------------------------------------------------------------
  149. Public Function GetProperty(Optional ByVal PropertyName As Variant _
  150. , Optional ObjectName As Variant _
  151. ) As Variant
  152. &apos;&apos;&apos; Return the actual value of the given property
  153. &apos;&apos;&apos; Args:
  154. &apos;&apos;&apos; PropertyName: the name of the property as a string
  155. &apos;&apos;&apos; ObjectName: a sheet or range name
  156. &apos;&apos;&apos; Returns:
  157. &apos;&apos;&apos; The actual value of the property
  158. &apos;&apos;&apos; Exceptions:
  159. &apos;&apos;&apos; ARGUMENTERROR The property does not exist
  160. Const cstThisSub = &quot;SFDocuments.Writer.GetProperty&quot;
  161. Const cstSubArgs = &quot;&quot;
  162. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  163. GetProperty = Null
  164. Check:
  165. If IsMissing(ObjectName) Or IsEmpty(ObjectName) Then ObjectName = &quot;&quot;
  166. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  167. If Not ScriptForge.SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
  168. If Not ScriptForge.SF_Utils._Validate(ObjectName, &quot;ObjectName&quot;, V_STRING) Then GoTo Catch
  169. End If
  170. Try:
  171. &apos; Superclass or subclass property ?
  172. If ScriptForge.SF_Array.Contains([_Super].Properties(), PropertyName) Then
  173. GetProperty = [_Super].GetProperty(PropertyName)
  174. ElseIf Len(ObjectName) = 0 Then
  175. GetProperty = _PropertyGet(PropertyName)
  176. Else
  177. GetProperty = _PropertyGet(PropertyName, ObjectName)
  178. End If
  179. Finally:
  180. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  181. Exit Function
  182. Catch:
  183. GoTo Finally
  184. End Function &apos; SFDocuments.SF_Writer.GetProperty
  185. REM -----------------------------------------------------------------------------
  186. Public Function Methods() As Variant
  187. &apos;&apos;&apos; Return the list of public methods of the Writer service as an array
  188. Methods = Array( _
  189. &quot;Forms&quot; _
  190. , &quot;PrintOut&quot; _
  191. )
  192. End Function &apos; SFDocuments.SF_Writer.Methods
  193. REM -----------------------------------------------------------------------------
  194. Public Function PrintOut(Optional ByVal Pages As Variant _
  195. , Optional ByVal Copies As Variant _
  196. , Optional ByVal PrintBackground As Variant _
  197. , Optional ByVal PrintBlankPages As Variant _
  198. , Optional ByVal PrintEvenPages As Variant _
  199. , Optional ByVal PrintOddPages As Variant _
  200. , Optional ByVal PrintImages As Variant _
  201. ) As Boolean
  202. &apos;&apos;&apos; Send the content of the document to the printer.
  203. &apos;&apos;&apos; The printer might be defined previously by default, by the user or by the SetPrinter() method
  204. &apos;&apos;&apos; Args:
  205. &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
  206. &apos;&apos;&apos; Copies: the number of copies
  207. &apos;&apos;&apos; PrintBackground: print the background image when True (default)
  208. &apos;&apos;&apos; PrintBlankPages: when False (default), omit empty pages
  209. &apos;&apos;&apos; PrintEvenPages: print the left pages when True (default)
  210. &apos;&apos;&apos; PrintOddPages: print the right pages when True (default)
  211. &apos;&apos;&apos; PrintImages: print the graphic objects when True (default)
  212. &apos;&apos;&apos; Returns:
  213. &apos;&apos;&apos; True when successful
  214. &apos;&apos;&apos; Examples:
  215. &apos;&apos;&apos; oDoc.PrintOut(&quot;1-4;10;15-18&quot;, Copies := 2, PrintImages := False)
  216. Dim bPrint As Boolean &apos; Return value
  217. Dim vPrintOptions As Variant &apos; com.sun.star.text.DocumentSettings
  218. Const cstThisSub = &quot;SFDocuments.Writer.PrintOut&quot;
  219. Const cstSubArgs = &quot;[Pages=&quot;&quot;&quot;&quot;], [Copies=1], [PrintBackground=True], [PrintBlankPages=False], [PrintEvenPages=True]&quot; _
  220. &amp; &quot;, [PrintOddPages=True], [PrintImages=True]&quot;
  221. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  222. bPrint = False
  223. Check:
  224. If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
  225. If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
  226. If IsMissing(PrintBackground) Or IsEmpty(PrintBackground) Then PrintBackground = True
  227. If IsMissing(PrintBlankPages) Or IsEmpty(PrintBlankPages) Then PrintBlankPages = False
  228. If IsMissing(PrintEvenPages) Or IsEmpty(PrintEvenPages) Then PrintEvenPages = True
  229. If IsMissing(PrintOddPages) Or IsEmpty(PrintOddPages) Then PrintOddPages = True
  230. If IsMissing(PrintImages) Or IsEmpty(PrintImages) Then PrintImages = True
  231. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  232. If Not _IsStillAlive() Then GoTo Finally
  233. If Not ScriptForge.SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
  234. If Not ScriptForge.SF_Utils._Validate(Copies, &quot;Copies&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
  235. If Not ScriptForge.SF_Utils._Validate(PrintBackground, &quot;PrintBackground&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
  236. If Not ScriptForge.SF_Utils._Validate(PrintBlankPages, &quot;PrintBlankPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
  237. If Not ScriptForge.SF_Utils._Validate(PrintEvenPages, &quot;PrintEvenPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
  238. If Not ScriptForge.SF_Utils._Validate(PrintOddPages, &quot;PrintOddPages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
  239. If Not ScriptForge.SF_Utils._Validate(PrintImages, &quot;PrintImages&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
  240. End If
  241. Try:
  242. vPrintOptions = _Component.createInstance(&quot;com.sun.star.text.DocumentSettings&quot;)
  243. With vPrintOptions
  244. .PrintPageBackground = PrintBackground
  245. .PrintEmptyPages = PrintBlankPages
  246. .PrintLeftPages = PrintEvenPages
  247. .PrintRightPages = PrintOddPages
  248. .PrintGraphics = PrintImages
  249. .PrintDrawings = PrintImages
  250. End With
  251. bPrint = [_Super].PrintOut(Pages, Copies, _Component)
  252. Finally:
  253. PrintOut = bPrint
  254. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  255. Exit Function
  256. Catch:
  257. GoTo Finally
  258. End Function &apos; SFDocuments.SF_Writer.PrintOut
  259. REM -----------------------------------------------------------------------------
  260. Public Function Properties() As Variant
  261. &apos;&apos;&apos; Return the list or properties of the Writer class as an array
  262. Properties = Array( _
  263. &quot;CustomProperties&quot; _
  264. , &quot;Description&quot; _
  265. , &quot;DocumentProperties&quot; _
  266. , &quot;DocumentType&quot; _
  267. , &quot;ExportFilters&quot; _
  268. , &quot;ImportFilters&quot; _
  269. , &quot;IsBase&quot; _
  270. , &quot;IsCalc&quot; _
  271. , &quot;IsDraw&quot; _
  272. , &quot;IsImpress&quot; _
  273. , &quot;IsMath&quot; _
  274. , &quot;IsWriter&quot; _
  275. , &quot;Keywords&quot; _
  276. , &quot;Readonly&quot; _
  277. , &quot;Subject&quot; _
  278. , &quot;Title&quot; _
  279. , &quot;XComponent&quot; _
  280. )
  281. End Function &apos; SFDocuments.SF_Writer.Properties
  282. REM -----------------------------------------------------------------------------
  283. Private Function SetProperty(Optional ByVal psProperty As String _
  284. , Optional ByVal pvValue As Variant _
  285. ) As Boolean
  286. &apos;&apos;&apos; Set the new value of the named property
  287. &apos;&apos;&apos; Args:
  288. &apos;&apos;&apos; psProperty: the name of the property
  289. &apos;&apos;&apos; pvValue: the new value of the given property
  290. &apos;&apos;&apos; Returns:
  291. &apos;&apos;&apos; True if successful
  292. Dim bSet As Boolean &apos; Return value
  293. Static oSession As Object &apos; Alias of SF_Session
  294. Dim cstThisSub As String
  295. Const cstSubArgs = &quot;Value&quot;
  296. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  297. bSet = False
  298. cstThisSub = &quot;SFDocuments.Writer.set&quot; &amp; psProperty
  299. If IsMissing(pvValue) Then pvValue = Empty
  300. &apos;ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) &apos; Validation done in Property Lets
  301. If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(&quot;Session&quot;)
  302. bSet = True
  303. Select Case UCase(psProperty)
  304. Case UCase(&quot;CustomProperties&quot;)
  305. CustomProperties = pvValue
  306. Case UCase(&quot;Description&quot;)
  307. Description = pvValue
  308. Case UCase(&quot;Keywords&quot;)
  309. Keywords = pvValue
  310. Case UCase(&quot;Subject&quot;)
  311. Subject = pvValue
  312. Case UCase(&quot;Title&quot;)
  313. Title = pvValue
  314. Case Else
  315. bSet = False
  316. End Select
  317. Finally:
  318. SetProperty = bSet
  319. &apos;ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  320. Exit Function
  321. Catch:
  322. GoTo Finally
  323. End Function &apos; SFDocuments.SF_Writer.SetProperty
  324. REM ======================================================= SUPERCLASS PROPERTIES
  325. REM -----------------------------------------------------------------------------
  326. Property Get CustomProperties() As Variant
  327. CustomProperties = [_Super].GetProperty(&quot;CustomProperties&quot;)
  328. End Property &apos; SFDocuments.SF_Writer.CustomProperties
  329. REM -----------------------------------------------------------------------------
  330. Property Let CustomProperties(Optional ByVal pvCustomProperties As Variant)
  331. [_Super].CustomProperties = pvCustomProperties
  332. End Property &apos; SFDocuments.SF_Writer.CustomProperties
  333. REM -----------------------------------------------------------------------------
  334. Property Get Description() As Variant
  335. Description = [_Super].GetProperty(&quot;Description&quot;)
  336. End Property &apos; SFDocuments.SF_Writer.Description
  337. REM -----------------------------------------------------------------------------
  338. Property Let Description(Optional ByVal pvDescription As Variant)
  339. [_Super].Description = pvDescription
  340. End Property &apos; SFDocuments.SF_Writer.Description
  341. REM -----------------------------------------------------------------------------
  342. Property Get DocumentProperties() As Variant
  343. DocumentProperties = [_Super].GetProperty(&quot;DocumentProperties&quot;)
  344. End Property &apos; SFDocuments.SF_Writer.DocumentProperties
  345. REM -----------------------------------------------------------------------------
  346. Property Get DocumentType() As String
  347. DocumentType = [_Super].GetProperty(&quot;DocumentType&quot;)
  348. End Property &apos; SFDocuments.SF_Writer.DocumentType
  349. REM -----------------------------------------------------------------------------
  350. Property Get ExportFilters() As Variant
  351. ExportFilters = [_Super].GetProperty(&quot;ExportFilters&quot;)
  352. End Property &apos; SFDocuments.SF_Writer.ExportFilters
  353. REM -----------------------------------------------------------------------------
  354. Property Get ImportFilters() As Variant
  355. ImportFilters = [_Super].GetProperty(&quot;ImportFilters&quot;)
  356. End Property &apos; SFDocuments.SF_Writer.ImportFilters
  357. REM -----------------------------------------------------------------------------
  358. Property Get IsBase() As Boolean
  359. IsBase = [_Super].GetProperty(&quot;IsBase&quot;)
  360. End Property &apos; SFDocuments.SF_Writer.IsBase
  361. REM -----------------------------------------------------------------------------
  362. Property Get IsCalc() As Boolean
  363. IsCalc = [_Super].GetProperty(&quot;IsCalc&quot;)
  364. End Property &apos; SFDocuments.SF_Writer.IsCalc
  365. REM -----------------------------------------------------------------------------
  366. Property Get IsDraw() As Boolean
  367. IsDraw = [_Super].GetProperty(&quot;IsDraw&quot;)
  368. End Property &apos; SFDocuments.SF_Writer.IsDraw
  369. REM -----------------------------------------------------------------------------
  370. Property Get IsImpress() As Boolean
  371. IsImpress = [_Super].GetProperty(&quot;IsImpress&quot;)
  372. End Property &apos; SFDocuments.SF_Writer.IsImpress
  373. REM -----------------------------------------------------------------------------
  374. Property Get IsMath() As Boolean
  375. IsMath = [_Super].GetProperty(&quot;IsMath&quot;)
  376. End Property &apos; SFDocuments.SF_Writer.IsMath
  377. REM -----------------------------------------------------------------------------
  378. Property Get IsWriter() As Boolean
  379. IsWriter = [_Super].GetProperty(&quot;IsWriter&quot;)
  380. End Property &apos; SFDocuments.SF_Writer.IsWriter
  381. REM -----------------------------------------------------------------------------
  382. Property Get Keywords() As Variant
  383. Keywords = [_Super].GetProperty(&quot;Keywords&quot;)
  384. End Property &apos; SFDocuments.SF_Writer.Keywords
  385. REM -----------------------------------------------------------------------------
  386. Property Let Keywords(Optional ByVal pvKeywords As Variant)
  387. [_Super].Keywords = pvKeywords
  388. End Property &apos; SFDocuments.SF_Writer.Keywords
  389. REM -----------------------------------------------------------------------------
  390. Property Get Readonly() As Variant
  391. Readonly = [_Super].GetProperty(&quot;Readonly&quot;)
  392. End Property &apos; SFDocuments.SF_Writer.Readonly
  393. REM -----------------------------------------------------------------------------
  394. Property Get Subject() As Variant
  395. Subject = [_Super].GetProperty(&quot;Subject&quot;)
  396. End Property &apos; SFDocuments.SF_Writer.Subject
  397. REM -----------------------------------------------------------------------------
  398. Property Let Subject(Optional ByVal pvSubject As Variant)
  399. [_Super].Subject = pvSubject
  400. End Property &apos; SFDocuments.SF_Writer.Subject
  401. REM -----------------------------------------------------------------------------
  402. Property Get Title() As Variant
  403. Title = [_Super].GetProperty(&quot;Title&quot;)
  404. End Property &apos; SFDocuments.SF_Writer.Title
  405. REM -----------------------------------------------------------------------------
  406. Property Let Title(Optional ByVal pvTitle As Variant)
  407. [_Super].Title = pvTitle
  408. End Property &apos; SFDocuments.SF_Writer.Title
  409. REM -----------------------------------------------------------------------------
  410. Property Get XComponent() As Variant
  411. XComponent = [_Super].GetProperty(&quot;XComponent&quot;)
  412. End Property &apos; SFDocuments.SF_Writer.XComponent
  413. REM ========================================================== SUPERCLASS METHODS
  414. REM -----------------------------------------------------------------------------
  415. Public Function Activate() As Boolean
  416. Activate = [_Super].Activate()
  417. End Function &apos; SFDocuments.SF_Writer.Activate
  418. REM -----------------------------------------------------------------------------
  419. Public Function CloseDocument(Optional ByVal SaveAsk As Variant) As Boolean
  420. CloseDocument = [_Super].CloseDocument(SaveAsk)
  421. End Function &apos; SFDocuments.SF_Writer.CloseDocument
  422. REM -----------------------------------------------------------------------------
  423. Public Function CreateMenu(Optional ByVal MenuHeader As Variant _
  424. , Optional ByVal Before As Variant _
  425. , Optional ByVal SubmenuChar As Variant _
  426. ) As Object
  427. Set CreateMenu = [_Super].CreateMenu(MenuHeader, Before, SubmenuChar)
  428. End Function &apos; SFDocuments.SF_Writer.CreateMenu
  429. REM -----------------------------------------------------------------------------
  430. Public Function ExportAsPDF(Optional ByVal FileName As Variant _
  431. , Optional ByVal Overwrite As Variant _
  432. , Optional ByVal Pages As Variant _
  433. , Optional ByVal Password As Variant _
  434. , Optional ByVal Watermark As Variant _
  435. ) As Boolean
  436. ExportAsPDF = [_Super].ExportAsPDF(FileName, Overwrite, Pages, Password, Watermark)
  437. End Function &apos; SFDocuments.SF_Writer.ExportAsPDF
  438. REM -----------------------------------------------------------------------------
  439. Public Function RemoveMenu(Optional ByVal MenuHeader As Variant) As Boolean
  440. RemoveMenu = [_Super].RemoveMenu(MenuHeader)
  441. End Function &apos; SFDocuments.SF_Writer.RemoveMenu
  442. REM -----------------------------------------------------------------------------
  443. Public Sub RunCommand(Optional ByVal Command As Variant _
  444. , ParamArray Args As Variant _
  445. )
  446. [_Super].RunCommand(Command, Args)
  447. End Sub &apos; SFDocuments.SF_Writer.RunCommand
  448. REM -----------------------------------------------------------------------------
  449. Public Function Save() As Boolean
  450. Save = [_Super].Save()
  451. End Function &apos; SFDocuments.SF_Writer.Save
  452. REM -----------------------------------------------------------------------------
  453. Public Function SaveAs(Optional ByVal FileName As Variant _
  454. , Optional ByVal Overwrite As Variant _
  455. , Optional ByVal Password As Variant _
  456. , Optional ByVal FilterName As Variant _
  457. , Optional ByVal FilterOptions As Variant _
  458. ) As Boolean
  459. SaveAs = [_Super].SaveAs(FileName, Overwrite, Password, FilterName, FilterOptions)
  460. End Function &apos; SFDocuments.SF_Writer.SaveAs
  461. REM -----------------------------------------------------------------------------
  462. Public Function SaveCopyAs(Optional ByVal FileName As Variant _
  463. , Optional ByVal Overwrite As Variant _
  464. , Optional ByVal Password As Variant _
  465. , Optional ByVal FilterName As Variant _
  466. , Optional ByVal FilterOptions As Variant _
  467. ) As Boolean
  468. SaveCopyAs = [_Super].SaveCopyAs(FileName, Overwrite, Password, FilterName, FilterOptions)
  469. End Function &apos; SFDocuments.SF_Writer.SaveCopyAs
  470. REM -----------------------------------------------------------------------------
  471. Public Function SetPrinter(Optional ByVal Printer As Variant _
  472. , Optional ByVal Orientation As Variant _
  473. , Optional ByVal PaperFormat As Variant _
  474. ) As Boolean
  475. SetPrinter = [_Super].SetPrinter(Printer, Orientation, PaperFormat)
  476. End Function &apos; SFDocuments.SF_Writer.SetPrinter
  477. REM =========================================================== PRIVATE FUNCTIONS
  478. REM -----------------------------------------------------------------------------
  479. Private Function _FileIdent() As String
  480. &apos;&apos;&apos; Returns a file identification from the information that is currently available
  481. &apos;&apos;&apos; Useful e.g. for display in error messages
  482. _FileIdent = [_Super]._FileIdent()
  483. End Function &apos; SFDocuments.SF_Writer._FileIdent
  484. REM -----------------------------------------------------------------------------
  485. Private Function _IsStillAlive(Optional ByVal pbForUpdate As Boolean _
  486. , Optional ByVal pbError As Boolean _
  487. ) As Boolean
  488. &apos;&apos;&apos; Returns True if the document has not been closed manually or incidentally since the last use
  489. &apos;&apos;&apos; If dead the actual instance is disposed. The execution is cancelled when pbError = True (default)
  490. &apos;&apos;&apos; Args:
  491. &apos;&apos;&apos; pbForUpdate: if True (default = False), check additionally if document is open for editing
  492. &apos;&apos;&apos; pbError: if True (default), raise a fatal error
  493. Dim bAlive As Boolean &apos; Return value
  494. If IsMissing(pbForUpdate) Then pbForUpdate = False
  495. If IsMissing(pbError) Then pbError = True
  496. Try:
  497. bAlive = [_Super]._IsStillAlive(pbForUpdate, pbError)
  498. Finally:
  499. _IsStillAlive = bAlive
  500. Exit Function
  501. End Function &apos; SFDocuments.SF_Writer._IsStillAlive
  502. REM -----------------------------------------------------------------------------
  503. Private Function _PropertyGet(Optional ByVal psProperty As String _
  504. , Optional ByVal pvArg As Variant _
  505. ) As Variant
  506. &apos;&apos;&apos; Return the value of the named property
  507. &apos;&apos;&apos; Args:
  508. &apos;&apos;&apos; psProperty: the name of the property
  509. Dim cstThisSub As String
  510. Const cstSubArgs = &quot;&quot;
  511. _PropertyGet = False
  512. cstThisSub = &quot;SFDocuments.Writer.get&quot; &amp; psProperty
  513. ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
  514. If Not _IsStillAlive() Then GoTo Finally
  515. Select Case psProperty
  516. Case Else
  517. _PropertyGet = Null
  518. End Select
  519. Finally:
  520. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  521. Exit Function
  522. End Function &apos; SFDocuments.SF_Writer._PropertyGet
  523. REM -----------------------------------------------------------------------------
  524. Private Function _Repr() As String
  525. &apos;&apos;&apos; Convert the SF_Writer instance to a readable string, typically for debugging purposes (DebugPrint ...)
  526. &apos;&apos;&apos; Args:
  527. &apos;&apos;&apos; Return:
  528. &apos;&apos;&apos; &quot;[DOCUMENT]: Type/File&quot;
  529. _Repr = &quot;[Writer]: &quot; &amp; [_Super]._FileIdent()
  530. End Function &apos; SFDocuments.SF_Writer._Repr
  531. REM ============================================ END OF SFDOCUMENTS.SF_WRITER
  532. </script:module>