SF_Base.xba 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  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_Base" 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_Base
  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; the management and several manipulations of 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, ...
  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_Base module is provided mainly to block parent properties that are NOT applicable to Base documents
  27. &apos;&apos;&apos; In addition, it provides methods to identify form documents and access their internal forms
  28. &apos;&apos;&apos; (read more elsewhere (the &quot;SFDocuments.Form&quot; service) about this subject)
  29. &apos;&apos;&apos;
  30. &apos;&apos;&apos; The current module is closely related to the &quot;UI&quot; service of the ScriptForge library
  31. &apos;&apos;&apos;
  32. &apos;&apos;&apos; Service invocation examples:
  33. &apos;&apos;&apos; 1) From the UI service
  34. &apos;&apos;&apos; Dim ui As Object, oDoc As Object
  35. &apos;&apos;&apos; Set ui = CreateScriptService(&quot;UI&quot;)
  36. &apos;&apos;&apos; Set oDoc = ui.CreateBaseDocument(&quot;C:\Me\MyFile.odb&quot;, ...)
  37. &apos;&apos;&apos; &apos; or Set oDoc = ui.OpenDocument(&quot;C:\Me\MyFile.odb&quot;)
  38. &apos;&apos;&apos; 2) Directly if the document is already opened
  39. &apos;&apos;&apos; Dim oDoc As Object
  40. &apos;&apos;&apos; Set oDoc = CreateScriptService(&quot;SFDocuments.Base&quot;, &quot;MyFile.odb&quot;)
  41. &apos;&apos;&apos; &apos; The substring &quot;SFDocuments.&quot; in the service name is optional
  42. &apos;&apos;&apos;
  43. &apos;&apos;&apos; Detailed user documentation:
  44. &apos;&apos;&apos; https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_base.html?DbPAR=BASIC
  45. &apos;&apos;&apos;
  46. &apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;&apos;
  47. REM ================================================================== EXCEPTIONS
  48. Private Const DBCONNECTERROR = &quot;DBCONNECTERROR&quot;
  49. Private Const FORMDEADERROR = &quot;FORMDEADERROR&quot;
  50. Private Const BASEFORMNOTFOUNDERROR = &quot;BASEFORMNOTFOUNDERROR&quot;
  51. REM ============================================================= PRIVATE MEMBERS
  52. Private [Me] As Object
  53. Private [_Parent] As Object
  54. Private [_Super] As Object &apos; Document superclass, which the current instance is a subclass of
  55. Private ObjectType As String &apos; Must be BASE
  56. Private ServiceName As String
  57. &apos; UNO references
  58. Private _Component As Object &apos; com.sun.star.comp.dba.ODatabaseDocument
  59. Private _DataSource As Object &apos; com.sun.star.comp.dba.ODatabaseSource
  60. Private _Database As Object &apos; SFDatabases.Database service instance
  61. Private _FormDocuments As Object
  62. REM ============================================================ MODULE CONSTANTS
  63. Const ISBASEFORM = 3 &apos; Form is stored in a Base document
  64. Const cstToken = &quot;//&quot; &apos; Form names accept special characters but not slashes
  65. REM ====================================================== CONSTRUCTOR/DESTRUCTOR
  66. REM -----------------------------------------------------------------------------
  67. Private Sub Class_Initialize()
  68. Set [Me] = Nothing
  69. Set [_Parent] = Nothing
  70. Set [_Super] = Nothing
  71. ObjectType = &quot;BASE&quot;
  72. ServiceName = &quot;SFDocuments.Base&quot;
  73. Set _Component = Nothing
  74. Set _DataSource = Nothing
  75. Set _Database = Nothing
  76. Set _FormDocuments = Nothing
  77. End Sub &apos; SFDocuments.SF_Base Constructor
  78. REM -----------------------------------------------------------------------------
  79. Private Sub Class_Terminate()
  80. Call Class_Initialize()
  81. End Sub &apos; SFDocuments.SF_Base Destructor
  82. REM -----------------------------------------------------------------------------
  83. Public Function Dispose() As Variant
  84. If Not IsNull([_Super]) Then Set [_Super] = [_Super].Dispose()
  85. Call Class_Terminate()
  86. Set Dispose = Nothing
  87. End Function &apos; SFDocuments.SF_Base Explicit Destructor
  88. REM ================================================================== PROPERTIES
  89. REM ===================================================================== METHODS
  90. REM -----------------------------------------------------------------------------
  91. Public Function CloseDocument(Optional ByVal SaveAsk As Variant) As Boolean
  92. &apos;&apos;&apos; The closure of a Base document requires the closures of
  93. &apos;&apos;&apos; 1) the connection =&gt; done in the CloseDatabase() method
  94. &apos;&apos;&apos; 2) the data source
  95. &apos;&apos;&apos; 3) the document itself =&gt; done in the superclass
  96. Const cstThisSub = &quot;SFDocuments.Base.CloseDocument&quot;
  97. Const cstSubArgs = &quot;[SaveAsk=True]&quot;
  98. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  99. Check:
  100. If IsMissing(SaveAsk) Or IsEmpty(SaveAsk) Then SaveAsk = True
  101. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  102. If Not _IsStillAlive(True) Then GoTo Finally
  103. If Not ScriptForge.SF_Utils._Validate(SaveAsk, &quot;SaveAsk&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
  104. End If
  105. Try:
  106. If Not IsNull(_Database) Then _Database.CloseDatabase()
  107. If Not IsNull(_DataSource) Then _DataSource.dispose()
  108. CloseDocument = [_Super].CloseDocument(SaveAsk)
  109. Finally:
  110. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  111. Exit Function
  112. Catch:
  113. GoTo Finally
  114. End Function &apos; SFDocuments.SF_Base.CloseDocument
  115. REM -----------------------------------------------------------------------------
  116. Public Function CloseFormDocument(Optional ByVal FormDocument As Variant) As Boolean
  117. &apos;&apos;&apos; Close the given form document
  118. &apos;&apos;&apos; Nothing happens if the form document is not open
  119. &apos;&apos;&apos; Args:
  120. &apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
  121. &apos;&apos;&apos; Returns:
  122. &apos;&apos;&apos; True if closure is successful
  123. &apos;&apos;&apos; Example:
  124. &apos;&apos;&apos; oDoc.CloseFormDocument(&quot;Folder1/myFormDocument&quot;)
  125. Dim bClose As Boolean &apos; Return value
  126. Dim oMainForm As Object &apos; com.sun.star.comp.sdb.Content
  127. Dim vFormNames As Variant &apos; Array of all document form names present in the document
  128. Const cstThisSub = &quot;SFDocuments.Base.CloseFormDocument&quot;
  129. Const cstSubArgs = &quot;FormDocument&quot;
  130. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  131. bClose = False
  132. Check:
  133. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  134. If Not _IsStillAlive() Then GoTo Finally
  135. &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
  136. If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
  137. vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
  138. If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
  139. End If
  140. If Not IsLoaded(FormDocument) Then GoTo Finally
  141. Try:
  142. Set oMainForm = _FormDocuments.getByHierarchicalName(FormDocument)
  143. bClose = oMainForm.close()
  144. Finally:
  145. CloseFormDocument = bClose
  146. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  147. Exit Function
  148. Catch:
  149. GoTo Finally
  150. End Function &apos; SFDocuments.SF_Base.CloseFormDocument
  151. REM -----------------------------------------------------------------------------
  152. Public Function FormDocuments() As Variant
  153. &apos;&apos;&apos; Return the list of the FormDocuments contained in the Base document
  154. &apos;&apos;&apos; Args:
  155. &apos;&apos;&apos; Returns:
  156. &apos;&apos;&apos; A zero-base array of strings
  157. &apos;&apos;&apos; Each entry is the full path name of a form document. The path separator is the slash (&quot;/&quot;)
  158. &apos;&apos;&apos; Example:
  159. &apos;&apos;&apos; Dim myForm As Object, myList As Variant
  160. &apos;&apos;&apos; myList = oDoc.FormDocuments()
  161. Dim vFormNames As Variant &apos; Array of all form names present in the document
  162. Const cstThisSub = &quot;SFDocuments.Base.FormDocuments&quot;
  163. Const cstSubArgs = &quot;&quot;
  164. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  165. Check:
  166. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  167. If Not _IsStillAlive() Then GoTo Finally
  168. End If
  169. Try:
  170. &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
  171. If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
  172. vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
  173. Finally:
  174. FormDocuments = vFormNames
  175. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  176. Exit Function
  177. Catch:
  178. GoTo Finally
  179. End Function &apos; SFDocuments.SF_Base.FormDocuments
  180. REM -----------------------------------------------------------------------------
  181. Public Function Forms(Optional ByVal FormDocument As Variant _
  182. , Optional ByVal Form As Variant _
  183. ) As Variant
  184. &apos;&apos;&apos; Return either
  185. &apos;&apos;&apos; - the list of the Forms contained in the form document
  186. &apos;&apos;&apos; - a SFDocuments.Form object based on its name or its index
  187. &apos;&apos;&apos; Args:
  188. &apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
  189. &apos;&apos;&apos; Form: a form stored in the Base document given by its name or its index
  190. &apos;&apos;&apos; When absent, the list of available forms is returned
  191. &apos;&apos;&apos; To get the first (unique ?) form stored in the form document, set Form = 0
  192. &apos;&apos;&apos; Returns:
  193. &apos;&apos;&apos; A zero-based array of strings if Form is absent
  194. &apos;&apos;&apos; An instance of the SF_Form class if Form exists
  195. &apos;&apos;&apos; Exceptions:
  196. &apos;&apos;&apos; FORMDEADERROR The form is not open
  197. &apos;&apos;&apos; BASEFORMNOTFOUNDERROR FormDocument OK but Form not found
  198. &apos;&apos;&apos; Example:
  199. &apos;&apos;&apos; Dim myForm As Object, myList As Variant
  200. &apos;&apos;&apos; myList = oDoc.Forms(&quot;Folder1/myFormDocument&quot;)
  201. &apos;&apos;&apos; Set myForm = oDoc.Forms(&quot;Folder1/myFormDocument&quot;, 0)
  202. Dim oForm As Object &apos; The new Form class instance
  203. Dim oFormDocument As Object &apos; com.sun.star.comp.sdb.Content
  204. Dim oXForm As Object &apos; com.sun.star.form.XForm
  205. Dim vFormDocuments As Variant &apos; Array of form documents
  206. Dim vFormNames As Variant &apos; Array of form names
  207. Dim oForms As Object &apos; Forms collection
  208. Const cstDrawPage = 0 &apos; Only 1 drawpage in a Base document
  209. Const cstThisSub = &quot;SFDocuments.Base.Forms&quot;
  210. Const cstSubArgs = &quot;FormDocument, [Form=&quot;&quot;&quot;&quot;]&quot;
  211. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  212. Check:
  213. If IsMissing(Form) Or IsEmpty(Form) Then Form = &quot;&quot;
  214. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  215. If Not _IsStillAlive() Then GoTo Finally
  216. &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
  217. If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
  218. vFormDocuments = Split(_CollectFormDocuments(_FormDocuments), cstToken)
  219. If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormDocuments) Then GoTo Finally
  220. If Not ScriptForge.SF_Utils._Validate(Form, &quot;Form&quot;, Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
  221. End If
  222. If Not IsLoaded(FormDocument) Then GoTo CatchClosed
  223. Try:
  224. &apos; Start from the form document and go down to forms
  225. Set oFormDocument = _FormDocuments.getByHierarchicalName(FormDocument)
  226. Set oForms = oFormDocument.Component.DrawPages(cstDrawPage).Forms
  227. vFormNames = oForms.getElementNames()
  228. If Len(Form) = 0 Then &apos; Return the list of valid form names
  229. Forms = vFormNames
  230. Else
  231. If VarType(Form) = V_STRING Then &apos; Find the form by name
  232. If Not ScriptForge.SF_Utils._Validate(Form, &quot;Form&quot;, V_STRING, vFormNames) Then GoTo Finally
  233. Set oXForm = oForms.getByName(Form)
  234. Else &apos; Find the form by index
  235. If Form &lt; 0 Or Form &gt;= oForms.Count Then GoTo CatchNotFound
  236. Set oXForm = oForms.getByIndex(Form)
  237. End If
  238. &apos; Create the new Form class instance
  239. Set oForm = New SF_Form
  240. With oForm
  241. ._Name = oXForm.Name
  242. Set .[Me] = oForm
  243. Set .[_Parent] = [Me]
  244. Set ._Component = _Component
  245. ._FormDocumentName = FormDocument
  246. Set ._FormDocument = oFormDocument
  247. ._FormType = ISBASEFORM
  248. Set ._Form = oXForm
  249. ._Initialize()
  250. End With
  251. Set Forms = oForm
  252. End If
  253. Finally:
  254. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  255. Exit Function
  256. Catch:
  257. GoTo Finally
  258. CatchClosed:
  259. ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, FormDocument, _FileIdent())
  260. CatchNotFound:
  261. ScriptForge.SF_Exception.RaiseFatal(BASEFORMNOTFOUNDERROR, Form, FormDocument, _FileIdent())
  262. End Function &apos; SFDocuments.SF_Base.Forms
  263. REM -----------------------------------------------------------------------------
  264. Public Function GetDatabase(Optional ByVal User As Variant _
  265. , Optional ByVal Password As Variant _
  266. ) As Object
  267. &apos;&apos;&apos; Returns a Database instance (service = SFDatabases.Database) giving access
  268. &apos;&apos;&apos; to the execution of SQL commands on the database defined and/or stored in
  269. &apos;&apos;&apos; the actual Base document
  270. &apos;&apos;&apos; Args:
  271. &apos;&apos;&apos; User, Password: the login parameters as strings. Defaults = &quot;&quot;
  272. &apos;&apos;&apos; Returns:
  273. &apos;&apos;&apos; A SFDatabases.Database instance or Nothing
  274. &apos;&apos;&apos; Example:
  275. &apos;&apos;&apos; Dim myDb As Object
  276. &apos;&apos;&apos; Set myDb = oDoc.GetDatabase()
  277. Const cstThisSub = &quot;SFDocuments.Base.GetDatabase&quot;
  278. Const cstSubArgs = &quot;[User=&quot;&quot;&quot;&quot;], [Password=&quot;&quot;&quot;&quot;]&quot;
  279. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  280. Set GetDatabase = Nothing
  281. Check:
  282. If IsMissing(User) Or IsEmpty(User) Then User = &quot;&quot;
  283. If IsMissing(Password) Or IsEmpty(Password) Then Password = &quot;&quot;
  284. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  285. If Not _IsStillAlive(True) Then GoTo Finally
  286. If Not ScriptForge.SF_Utils._Validate(User, &quot;User&quot;, V_STRING) Then GoTo Finally
  287. If Not ScriptForge.SF_Utils._Validate(Password, &quot;Password&quot;, V_STRING) Then GoTo Finally
  288. End If
  289. Try:
  290. If IsNull(_Database) Then &apos; 1st connection from the current document instance
  291. If IsNull(_DataSource) Then GoTo CatchConnect
  292. Set _Database = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.DatabaseFromDocument&quot; _
  293. , _DataSource, User, Password)
  294. If IsNull(_Database) Then GoTo CatchConnect
  295. _Database._Location = [_Super]._WindowFileName
  296. EndIf
  297. Finally:
  298. Set GetDatabase = _Database
  299. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  300. Exit Function
  301. Catch:
  302. GoTo Finally
  303. CatchConnect:
  304. ScriptForge.SF_Exception.RaiseFatal(DBCONNECTERROR, &quot;User&quot;, User, &quot;Password&quot;, Password, [_Super]._FileIdent())
  305. GoTo Finally
  306. End Function &apos; SFDocuments.SF_Base.GetDatabase
  307. REM -----------------------------------------------------------------------------
  308. Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
  309. &apos;&apos;&apos; Return the actual value of the given property
  310. &apos;&apos;&apos; Args:
  311. &apos;&apos;&apos; PropertyName: the name of the property as a string
  312. &apos;&apos;&apos; Returns:
  313. &apos;&apos;&apos; The actual value of the property
  314. &apos;&apos;&apos; Exceptions:
  315. &apos;&apos;&apos; ARGUMENTERROR The property does not exist
  316. Const cstThisSub = &quot;SFDocuments.Base.GetProperty&quot;
  317. Const cstSubArgs = &quot;&quot;
  318. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  319. GetProperty = Null
  320. Check:
  321. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  322. If Not ScriptForge.SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
  323. End If
  324. Try:
  325. &apos; Superclass or subclass property ?
  326. If ScriptForge.SF_Array.Contains([_Super].Properties(), PropertyName) Then
  327. GetProperty = [_Super].GetProperty(PropertyName)
  328. Else
  329. GetProperty = _PropertyGet(PropertyName)
  330. End If
  331. Finally:
  332. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  333. Exit Function
  334. Catch:
  335. GoTo Finally
  336. End Function &apos; SFDocuments.SF_Base.GetProperty
  337. REM -----------------------------------------------------------------------------
  338. Public Function IsLoaded(Optional ByVal FormDocument As Variant) As Boolean
  339. &apos;&apos;&apos; Return True if the given FormDocument is open for the user
  340. &apos;&apos;&apos; Args:
  341. &apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
  342. &apos;&apos;&apos; Returns:
  343. &apos;&apos;&apos; True if the form document is currently open, otherwise False
  344. &apos;&apos;&apos; Exceptions:
  345. &apos;&apos;&apos; Form name is invalid
  346. &apos;&apos;&apos; Example:
  347. &apos;&apos;&apos; MsgBox oDoc.IsLoaded(&quot;Folder1/myFormDocument&quot;)
  348. Dim bLoaded As Boolean &apos; Return value
  349. Dim vFormNames As Variant &apos; Array of all document form names present in the document
  350. Dim oMainForm As Object &apos; com.sun.star.comp.sdb.Content
  351. Const cstThisSub = &quot;SFDocuments.Base.IsLoaded&quot;
  352. Const cstSubArgs = &quot;FormDocument&quot;
  353. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  354. bLoaded = False
  355. Check:
  356. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  357. If Not _IsStillAlive() Then GoTo Finally
  358. &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
  359. If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
  360. vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
  361. If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
  362. End If
  363. Try:
  364. Set oMainForm = _FormDocuments.getByHierarchicalName(FormDocument)
  365. &apos; A document form that has never been opened has no component
  366. &apos; If ever opened and closed afterwards, it keeps the Component but loses its Controller
  367. bLoaded = Not IsNull(oMainForm.Component)
  368. If bLoaded Then bLoaded = Not IsNull(oMainForm.Component.CurrentController)
  369. Finally:
  370. IsLoaded = bLoaded
  371. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  372. Exit Function
  373. Catch:
  374. GoTo Finally
  375. End Function &apos; SFDocuments.SF_Base.IsLoaded
  376. REM -----------------------------------------------------------------------------
  377. Public Function Methods() As Variant
  378. &apos;&apos;&apos; Return the list of public methods of the Base class as an array
  379. Methods = Array( _
  380. &quot;CloseFormDocument&quot; _
  381. , &quot;FormDocuments&quot; _
  382. , &quot;Forms&quot; _
  383. , &quot;GetDatabase&quot; _
  384. , &quot;IsLoaded&quot; _
  385. , &quot;OpenFormDocument&quot; _
  386. , &quot;PrintOut&quot; _
  387. , &quot;SetPrinter&quot; _
  388. )
  389. End Function &apos; SFDocuments.SF_Base.Methods
  390. REM -----------------------------------------------------------------------------
  391. Public Function OpenFormDocument(Optional ByVal FormDocument As Variant _
  392. , Optional ByVal DesignMode As Variant _
  393. ) As Boolean
  394. &apos;&apos;&apos; Open the FormDocument given by its hierarchical name either in normal or in design mode
  395. &apos;&apos;&apos; If the form document is already open, the form document is made active without changing its mode
  396. &apos;&apos;&apos; Args:
  397. &apos;&apos;&apos; FormDocument: a valid form document name as a case-sensitive string
  398. &apos;&apos;&apos; DesignMode: when True the form document is opened in design mode (Default = False)
  399. &apos;&apos;&apos; Returns:
  400. &apos;&apos;&apos; True if the form document could be opened, otherwise False
  401. &apos;&apos;&apos; Exceptions:
  402. &apos;&apos;&apos; Form name is invalid
  403. &apos;&apos;&apos; Example:
  404. &apos;&apos;&apos; oDoc.OpenFormDocument(&quot;Folder1/myFormDocument&quot;)
  405. Dim bOpen As Boolean &apos; Return value
  406. Dim vFormNames As Variant &apos; Array of all document form names present in the document
  407. Dim oContainer As Object &apos; com.sun.star.awt.XWindow
  408. Dim oNewForm As Object &apos; Output of loadComponent()
  409. Const cstThisSub = &quot;SFDocuments.Base.OpenFormDocument&quot;
  410. Const cstSubArgs = &quot;FormDocument, [DesignMode=False]&quot;
  411. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  412. bOpen = False
  413. Check:
  414. If IsMissing(DesignMode) Or IsEmpty(DesignMode) Then DesignMode = False
  415. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  416. If Not _IsStillAlive() Then GoTo Finally
  417. &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
  418. If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
  419. vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
  420. If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
  421. If Not ScriptForge.SF_Utils._Validate(DesignMode, &quot;DesignMode&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
  422. End If
  423. Try:
  424. With _Component.CurrentController
  425. If Not .IsConnected Then .connect()
  426. &apos; loadComponent activates the form when already loaded
  427. Set oNewForm = .loadComponent(com.sun.star.sdb.application.DatabaseObject.FORM, FormDocument, DesignMode)
  428. &apos; When user opened manually the form in design mode and closed it, the next execution in normal mode needs to be confirmed as below
  429. With oNewForm.CurrentController
  430. If .isFormDesignMode() &lt;&gt; DesignMode Then .setFormDesignMode(DesignMode)
  431. End With
  432. End With
  433. bOpen = True
  434. Finally:
  435. OpenFormDocument = bOpen
  436. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  437. Exit Function
  438. Catch:
  439. GoTo Finally
  440. End Function &apos; SFDocuments.SF_Base.OpenFormDocument
  441. REM -----------------------------------------------------------------------------
  442. Public Function OpenQuery(Optional ByVal QueryName As Variant _
  443. , Optional ByVal DesignMode As Variant _
  444. ) As Object
  445. &apos;&apos;&apos; Open the query given by its name either in normal or in design mode
  446. &apos;&apos;&apos; If the query is already open, the query datasheet is made active without changing its mode
  447. &apos;&apos;&apos; If still open, the datasheet will be closed together with the actual Base document.
  448. &apos;&apos;&apos; Args:
  449. &apos;&apos;&apos; QueryName: a valid Query name as a case-sensitive string
  450. &apos;&apos;&apos; DesignMode: when True the query is opened in design mode (Default = False)
  451. &apos;&apos;&apos; Returns:
  452. &apos;&apos;&apos; A Datasheet class instance if the query could be opened and DesignMode = False, otherwise False
  453. &apos;&apos;&apos; Exceptions:
  454. &apos;&apos;&apos; Query name is invalid
  455. &apos;&apos;&apos; Example:
  456. &apos;&apos;&apos; oDoc.OpenQuery(&quot;myQuery&quot;, DesignMode := False)
  457. Dim oOpen As Object &apos; Return value
  458. Dim vQueries As Variant &apos; Array of query names
  459. Dim oNewQuery As Object &apos; Output of loadComponent()
  460. Const cstThisSub = &quot;SFDocuments.Base.OpenQuery&quot;
  461. Const cstSubArgs = &quot;QueryName, [DesignMode=False]&quot;
  462. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  463. Set oOpen = Nothing
  464. Check:
  465. If IsMissing(DesignMode) Or IsEmpty(DesignMode) Then DesignMode = False
  466. vQueries = GetDatabase().Queries &apos; Includes _IsStillAlive()
  467. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  468. If Not ScriptForge.SF_Utils._Validate(QueryName, &quot;QueryName&quot;, V_STRING, vQueries) Then GoTo Finally
  469. If Not ScriptForge.SF_Utils._Validate(DesignMode, &quot;DesignMode&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
  470. End If
  471. Try:
  472. With _Component.CurrentController
  473. &apos; The connection may have been done previously by a user command. If not, do it now.
  474. If Not .IsConnected Then .connect()
  475. &apos; loadComponent activates the query component when already loaded
  476. Set oNewQuery = .loadComponent(com.sun.star.sdb.application.DatabaseObject.QUERY, QueryName, DesignMode)
  477. End With
  478. &apos; When design mode, the method returns Nothing
  479. If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, oNewQuery, [Me])
  480. Finally:
  481. Set OpenQuery = oOpen
  482. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  483. Exit Function
  484. Catch:
  485. GoTo Finally
  486. End Function &apos; SFDocuments.SF_Base.OpenQuery
  487. REM -----------------------------------------------------------------------------
  488. Public Function OpenTable(Optional ByVal TableName As Variant _
  489. , Optional ByVal DesignMode As Variant _
  490. ) As Object
  491. &apos;&apos;&apos; Open the table given by its name either in normal or in design mode
  492. &apos;&apos;&apos; If the table is already open, the table datasheet is made active without changing its mode
  493. &apos;&apos;&apos; If still open, the datasheet will be closed together with the actual Base document.
  494. &apos;&apos;&apos; Args:
  495. &apos;&apos;&apos; TableName: a valid table name as a case-sensitive string
  496. &apos;&apos;&apos; DesignMode: when True the table is opened in design mode (Default = False)
  497. &apos;&apos;&apos; Returns:
  498. &apos;&apos;&apos; A Datasheet class instance if the table could be opened or was already open, and DesignMode = False.
  499. &apos;&apos;&apos; Otherwise Nothing
  500. &apos;&apos;&apos; Exceptions:
  501. &apos;&apos;&apos; Table name is invalid
  502. &apos;&apos;&apos; Example:
  503. &apos;&apos;&apos; oDoc.OpenTable(&quot;myTable&quot;, DesignMode := False)
  504. Dim oOpen As Object &apos; Return value
  505. Dim vTables As Variant &apos; Array of table names
  506. Dim oNewTable As Object &apos; Output of loadComponent()
  507. Const cstThisSub = &quot;SFDocuments.Base.OpenTable&quot;
  508. Const cstSubArgs = &quot;TableName, [DesignMode=False]&quot;
  509. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  510. Set oOpen = Nothing
  511. Check:
  512. If IsMissing(DesignMode) Or IsEmpty(DesignMode) Then DesignMode = False
  513. vTables = GetDatabase().Tables
  514. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  515. If Not ScriptForge.SF_Utils._Validate(TableName, &quot;TableName&quot;, V_STRING, vTables) Then GoTo Finally
  516. If Not ScriptForge.SF_Utils._Validate(DesignMode, &quot;DesignMode&quot;, ScriptForge.V_BOOLEAN) Then GoTo Finally
  517. End If
  518. Try:
  519. With _Component.CurrentController
  520. &apos; The connection may have been done previously by a user command. If not, do it now.
  521. If Not .IsConnected Then .connect()
  522. &apos; loadComponent activates the table component when already loaded
  523. Set oNewTable = .loadComponent(com.sun.star.sdb.application.DatabaseObject.TABLE, TableName, DesignMode)
  524. End With
  525. &apos; When design mode, the method returns Nothing
  526. If Not DesignMode Then Set oOpen = ScriptForge.SF_Services.CreateScriptService(&quot;SFDatabases.Datasheet&quot;, oNewTable, [Me])
  527. Finally:
  528. Set OpenTable = oOpen
  529. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  530. Exit Function
  531. Catch:
  532. GoTo Finally
  533. End Function &apos; SFDocuments.SF_Base.OpenTable
  534. REM -----------------------------------------------------------------------------
  535. Public Function PrintOut(Optional ByVal FormDocument As Variant _
  536. , Optional ByVal Pages As Variant _
  537. , Optional ByVal Copies As Variant _
  538. ) As Boolean
  539. &apos;&apos;&apos; Send the content of the given form document to the printer.
  540. &apos;&apos;&apos; The printer might be defined previously by default, by the user or by the SetPrinter() method
  541. &apos;&apos;&apos; The given form document must be open. It is activated by the method.
  542. &apos;&apos;&apos; Args:
  543. &apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
  544. &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
  545. &apos;&apos;&apos; Copies: the number of copies
  546. &apos;&apos;&apos; Exceptions:
  547. &apos;&apos;&apos; FORMDEADERROR The form is not open
  548. &apos;&apos;&apos; Returns:
  549. &apos;&apos;&apos; True when successful
  550. &apos;&apos;&apos; Examples:
  551. &apos;&apos;&apos; oDoc.PrintOut(&quot;myForm&quot;, &quot;1-4;10;15-18&quot;, Copies := 2)
  552. Dim bPrint As Boolean &apos; Return value
  553. Dim vFormNames As Variant &apos; Array of all document form names present in the document
  554. Dim oFormDocument As Object &apos; com.sun.star.comp.sdb.Content
  555. Const cstThisSub = &quot;SFDocuments.Base.PrintOut&quot;
  556. Const cstSubArgs = &quot;FormDocument, [Pages=&quot;&quot;&quot;&quot;], [Copies=1]&quot;
  557. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  558. bPrint = False
  559. Check:
  560. If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = &quot;&quot;
  561. If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
  562. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  563. If Not _IsStillAlive() Then GoTo Finally
  564. &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
  565. If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
  566. vFormNames = Split(_CollectFormDocuments(_FormDocuments), cstToken)
  567. If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormNames) Then GoTo Finally
  568. If Not ScriptForge.SF_Utils._Validate(Pages, &quot;Pages&quot;, V_STRING) Then GoTo Finally
  569. If Not ScriptForge.SF_Utils._Validate(Copies, &quot;Copies&quot;, ScriptForge.V_NUMERIC) Then GoTo Finally
  570. End If
  571. If Not IsLoaded(FormDocument) Then GoTo CatchClosed
  572. Try:
  573. Set oFormDocument = _FormDocuments.getByHierarchicalName(FormDocument)
  574. bPrint = [_Super].PrintOut(Pages, Copies, oFormDocument.Component)
  575. Finally:
  576. PrintOut = bPrint
  577. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  578. Exit Function
  579. Catch:
  580. GoTo Finally
  581. CatchClosed:
  582. ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, FormDocument, _FileIdent())
  583. End Function &apos; SFDocuments.SF_Base.PrintOut
  584. REM -----------------------------------------------------------------------------
  585. Public Function Properties() As Variant
  586. &apos;&apos;&apos; Return the list or properties of the Base class as an array
  587. Properties = Array( _
  588. &quot;DocumentType&quot; _
  589. , &quot;IsBase&quot; _
  590. , &quot;IsCalc&quot; _
  591. , &quot;IsDraw &quot; _
  592. , &quot;IsImpress&quot; _
  593. , &quot;IsMath&quot; _
  594. , &quot;IsWriter&quot; _
  595. , &quot;XComponent&quot; _
  596. )
  597. End Function &apos; SFDocuments.SF_Base.Properties
  598. REM -----------------------------------------------------------------------------
  599. Public Function SetPrinter(Optional ByVal FormDocument As Variant _
  600. , Optional ByVal Printer As Variant _
  601. , Optional ByVal Orientation As Variant _
  602. , Optional ByVal PaperFormat As Variant _
  603. ) As Boolean
  604. &apos;&apos;&apos; Define the printer options for a form document. The form document must be open.
  605. &apos;&apos;&apos; Args:
  606. &apos;&apos;&apos; FormDocument: a valid document form name as a case-sensitive string
  607. &apos;&apos;&apos; Printer: the name of the printer queue where to print to
  608. &apos;&apos;&apos; When absent or space, the default printer is set
  609. &apos;&apos;&apos; Orientation: either &quot;PORTRAIT&quot; or &quot;LANDSCAPE&quot;. Left unchanged when absent
  610. &apos;&apos;&apos; PaperFormat: one of next values
  611. &apos;&apos;&apos; &quot;A3&quot;, &quot;A4&quot;, &quot;A5&quot;, &quot;B4&quot;, &quot;B5&quot;, &quot;LETTER&quot;, &quot;LEGAL&quot;, &quot;TABLOID&quot;
  612. &apos;&apos;&apos; Left unchanged when absent
  613. &apos;&apos;&apos; Returns:
  614. &apos;&apos;&apos; True when successful
  615. &apos;&apos;&apos; Examples:
  616. &apos;&apos;&apos; oDoc.SetPrinter(&quot;myForm&quot;, Orientation := &quot;PORTRAIT&quot;)
  617. Dim bPrinter As Boolean &apos; Return value
  618. Dim vFormDocuments As Variant &apos; Array of form documents
  619. Dim oFormDocument As Object &apos; com.sun.star.comp.sdb.Content
  620. Const cstThisSub = &quot;SFDocuments.Base.SetPrinter&quot;
  621. Const cstSubArgs = &quot;FormDocument, [Printer=&quot;&quot;&quot;&quot;], [Orientation=&quot;&quot;PORTRAIT&quot;&quot;|&quot;&quot;LANDSCAPE&quot;&quot;]&quot; _
  622. &amp; &quot;, [PaperFormat=&quot;&quot;A3&quot;&quot;|&quot;&quot;A4&quot;&quot;|&quot;&quot;A5&quot;&quot;|&quot;&quot;B4&quot;&quot;|&quot;&quot;B5&quot;&quot;|&quot;&quot;LETTER&quot;&quot;|&quot;&quot;LEGAL&quot;&quot;|&quot;&quot;TABLOID&quot;&quot;&quot;
  623. If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  624. bPrinter = False
  625. Check:
  626. If IsMissing(Printer) Or IsEmpty(Printer) Then Printer = &quot;&quot;
  627. If IsMissing(Orientation) Or IsEmpty(Orientation) Then Orientation = &quot;&quot;
  628. If IsMissing(PaperFormat) Or IsEmpty(PaperFormat) Then PaperFormat = &quot;&quot;
  629. If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  630. If Not _IsStillAlive() Then GoTo Finally
  631. &apos; Build list of available FormDocuments recursively with _CollectFormDocuments
  632. If IsNull(_FormDocuments) Then Set _FormDocuments = _Component.getFormDocuments()
  633. vFormDocuments = Split(_CollectFormDocuments(_FormDocuments), cstToken)
  634. If Not ScriptForge.SF_Utils._Validate(FormDocument, &quot;FormDocument&quot;, V_STRING, vFormDocuments) Then GoTo Finally
  635. End If
  636. If Not IsLoaded(FormDocument) Then GoTo CatchClosed
  637. Try:
  638. Set oFormDocument = _FormDocuments.getByHierarchicalName(FormDocument)
  639. bPrinter = [_Super].SetPrinter(Printer, Orientation, PaperFormat, oFormDocument.Component)
  640. Finally:
  641. SetPrinter = bPrinter
  642. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  643. Exit Function
  644. Catch:
  645. GoTo Finally
  646. CatchClosed:
  647. ScriptForge.SF_Exception.RaiseFatal(FORMDEADERROR, FormDocument, _FileIdent())
  648. End Function &apos; SFDocuments.SF_Base.SetPrinter
  649. REM -----------------------------------------------------------------------------
  650. Public Function SetProperty(Optional ByVal PropertyName As Variant _
  651. , Optional ByRef Value As Variant _
  652. ) As Boolean
  653. &apos;&apos;&apos; Set a new value to the given property
  654. &apos;&apos;&apos; Args:
  655. &apos;&apos;&apos; PropertyName: the name of the property as a string
  656. &apos;&apos;&apos; Value: its new value
  657. &apos;&apos;&apos; Exceptions
  658. &apos;&apos;&apos; ARGUMENTERROR The property does not exist
  659. Const cstThisSub = &quot;SFDocuments.Base.SetProperty&quot;
  660. Const cstSubArgs = &quot;PropertyName, Value&quot;
  661. If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
  662. SetProperty = False
  663. Check:
  664. If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
  665. If Not SF_Utils._Validate(PropertyName, &quot;PropertyName&quot;, V_STRING, Properties()) Then GoTo Catch
  666. End If
  667. Try:
  668. Select Case UCase(PropertyName)
  669. Case Else
  670. End Select
  671. Finally:
  672. SF_Utils._ExitFunction(cstThisSub)
  673. Exit Function
  674. Catch:
  675. GoTo Finally
  676. End Function &apos; SFDocuments.SF_Base.SetProperty
  677. REM ======================================================= SUPERCLASS PROPERTIES
  678. REM -----------------------------------------------------------------------------
  679. &apos;Property Get CustomProperties() As Variant
  680. &apos; CustomProperties = [_Super].GetProperty(&quot;CustomProperties&quot;)
  681. &apos;End Property &apos; SFDocuments.SF_Base.CustomProperties
  682. REM -----------------------------------------------------------------------------
  683. &apos;Property Let CustomProperties(Optional ByVal pvCustomProperties As Variant)
  684. &apos; [_Super].CustomProperties = pvCustomProperties
  685. &apos;End Property &apos; SFDocuments.SF_Base.CustomProperties
  686. REM -----------------------------------------------------------------------------
  687. &apos;Property Get Description() As Variant
  688. &apos; Description = [_Super].GetProperty(&quot;Description&quot;)
  689. &apos;End Property &apos; SFDocuments.SF_Base.Description
  690. REM -----------------------------------------------------------------------------
  691. &apos;Property Let Description(Optional ByVal pvDescription As Variant)
  692. &apos; [_Super].Description = pvDescription
  693. &apos;End Property &apos; SFDocuments.SF_Base.Description
  694. REM -----------------------------------------------------------------------------
  695. &apos;Property Get DocumentProperties() As Variant
  696. &apos; DocumentProperties = [_Super].GetProperty(&quot;DocumentProperties&quot;)
  697. &apos;End Property &apos; SFDocuments.SF_Base.DocumentProperties
  698. REM -----------------------------------------------------------------------------
  699. Property Get DocumentType() As String
  700. DocumentType = [_Super].GetProperty(&quot;DocumentType&quot;)
  701. End Property &apos; SFDocuments.SF_Base.DocumentType
  702. REM -----------------------------------------------------------------------------
  703. Property Get IsBase() As Boolean
  704. IsBase = [_Super].GetProperty(&quot;IsBase&quot;)
  705. End Property &apos; SFDocuments.SF_Base.IsBase
  706. REM -----------------------------------------------------------------------------
  707. Property Get IsCalc() As Boolean
  708. IsCalc = [_Super].GetProperty(&quot;IsCalc&quot;)
  709. End Property &apos; SFDocuments.SF_Base.IsCalc
  710. REM -----------------------------------------------------------------------------
  711. Property Get IsDraw() As Boolean
  712. IsDraw = [_Super].GetProperty(&quot;IsDraw&quot;)
  713. End Property &apos; SFDocuments.SF_Base.IsDraw
  714. REM -----------------------------------------------------------------------------
  715. Property Get IsImpress() As Boolean
  716. IsImpress = [_Super].GetProperty(&quot;IsImpress&quot;)
  717. End Property &apos; SFDocuments.SF_Base.IsImpress
  718. REM -----------------------------------------------------------------------------
  719. Property Get IsMath() As Boolean
  720. IsMath = [_Super].GetProperty(&quot;IsMath&quot;)
  721. End Property &apos; SFDocuments.SF_Base.IsMath
  722. REM -----------------------------------------------------------------------------
  723. Property Get IsWriter() As Boolean
  724. IsWriter = [_Super].GetProperty(&quot;IsWriter&quot;)
  725. End Property &apos; SFDocuments.SF_Base.IsWriter
  726. REM -----------------------------------------------------------------------------
  727. &apos;Property Get Keywords() As Variant
  728. &apos; Keywords = [_Super].GetProperty(&quot;Keywords&quot;)
  729. &apos;End Property &apos; SFDocuments.SF_Base.Keywords
  730. REM -----------------------------------------------------------------------------
  731. &apos;Property Let Keywords(Optional ByVal pvKeywords As Variant)
  732. &apos; [_Super].Keywords = pvKeywords
  733. &apos;End Property &apos; SFDocuments.SF_Base.Keywords
  734. REM -----------------------------------------------------------------------------
  735. &apos;Property Get Readonly() As Variant
  736. &apos; Readonly = [_Super].GetProperty(&quot;Readonly&quot;)
  737. &apos;End Property &apos; SFDocuments.SF_Base.Readonly
  738. REM -----------------------------------------------------------------------------
  739. &apos;Property Get Subject() As Variant
  740. &apos; Subject = [_Super].GetProperty(&quot;Subject&quot;)
  741. &apos;End Property &apos; SFDocuments.SF_Base.Subject
  742. REM -----------------------------------------------------------------------------
  743. &apos;Property Let Subject(Optional ByVal pvSubject As Variant)
  744. &apos; [_Super].Subject = pvSubject
  745. &apos;End Property &apos; SFDocuments.SF_Base.Subject
  746. REM -----------------------------------------------------------------------------
  747. &apos;Property Get Title() As Variant
  748. &apos; Title = [_Super].GetProperty(&quot;Title&quot;)
  749. &apos;End Property &apos; SFDocuments.SF_Base.Title
  750. REM -----------------------------------------------------------------------------
  751. &apos;Property Let Title(Optional ByVal pvTitle As Variant)
  752. &apos; [_Super].Title = pvTitle
  753. &apos;End Property &apos; SFDocuments.SF_Base.Title
  754. REM -----------------------------------------------------------------------------
  755. Property Get XComponent() As Variant
  756. XComponent = [_Super].GetProperty(&quot;XComponent&quot;)
  757. End Property &apos; SFDocuments.SF_Base.XComponent
  758. REM ========================================================== SUPERCLASS METHODS
  759. REM -----------------------------------------------------------------------------
  760. Public Function Activate() As Boolean
  761. Activate = [_Super].Activate()
  762. End Function &apos; SFDocuments.SF_Base.Activate
  763. REM -----------------------------------------------------------------------------
  764. Public Function CreateMenu(Optional ByVal MenuHeader As Variant _
  765. , Optional ByVal Before As Variant _
  766. , Optional ByVal SubmenuChar As Variant _
  767. ) As Object
  768. Set CreateMenu = [_Super].CreateMenu(MenuHeader, Before, SubmenuChar)
  769. End Function &apos; SFDocuments.SF_Base.CreateMenu
  770. REM -----------------------------------------------------------------------------
  771. Public Function RemoveMenu(Optional ByVal MenuHeader As Variant) As Boolean
  772. RemoveMenu = [_Super].RemoveMenu(MenuHeader)
  773. End Function &apos; SFDocuments.SF_Base.RemoveMenu
  774. REM -----------------------------------------------------------------------------
  775. Public Sub RunCommand(Optional ByVal Command As Variant _
  776. , ParamArray Args As Variant _
  777. )
  778. [_Super].RunCommand(Command, Args)
  779. End Sub &apos; SFDocuments.SF_Base.RunCommand
  780. REM -----------------------------------------------------------------------------
  781. Public Function Save() As Boolean
  782. Save = [_Super].Save()
  783. End Function &apos; SFDocuments.SF_Base.Save
  784. REM -----------------------------------------------------------------------------
  785. Public Function SaveAs(Optional ByVal FileName As Variant _
  786. , Optional ByVal Overwrite As Variant _
  787. , Optional ByVal Password As Variant _
  788. , Optional ByVal FilterName As Variant _
  789. , Optional ByVal FilterOptions As Variant _
  790. ) As Boolean
  791. SaveAs = [_Super].SaveAs(FileName, Overwrite, Password, FilterName, FilterOptions)
  792. End Function &apos; SFDocuments.SF_Base.SaveAs
  793. REM -----------------------------------------------------------------------------
  794. Public Function SaveCopyAs(Optional ByVal FileName As Variant _
  795. , Optional ByVal Overwrite As Variant _
  796. , Optional ByVal Password As Variant _
  797. , Optional ByVal FilterName As Variant _
  798. , Optional ByVal FilterOptions As Variant _
  799. ) As Boolean
  800. SaveCopyAs = [_Super].SaveCopyAs(FileName, Overwrite, Password, FilterName, FilterOptions)
  801. End Function &apos; SFDocuments.SF_Base.SaveCopyAs
  802. REM =========================================================== PRIVATE FUNCTIONS
  803. REM -----------------------------------------------------------------------------
  804. Private Function _CollectFormDocuments(ByRef poContainer As Object) As String
  805. &apos;&apos;&apos; Returns a token-separated string of all hierarchical formdocument names
  806. &apos;&apos;&apos; depending on the formdocuments container in argument
  807. &apos;&apos;&apos; The function traverses recursively the whole tree below the container
  808. &apos;&apos;&apos; The initial call starts from the container _Component.getFormDocuments
  809. &apos;&apos;&apos; The list contains closed and open forms
  810. Dim sCollectNames As String &apos; Return value
  811. Dim oSubItem As Object &apos; com.sun.star.container.XNameAccess (folder) or com.sun.star.ucb.XContent (form)
  812. Dim i As Long
  813. Const cstFormType = &quot;application/vnd.oasis.opendocument.text&quot;
  814. &apos; Identifies forms. Folders have a zero-length content type
  815. On Local Error GoTo Finally
  816. Try:
  817. sCollectNames = &quot;&quot;
  818. With poContainer
  819. For i = 0 To .Count - 1
  820. Set oSubItem = .getByIndex(i)
  821. If oSubItem.ContentType = cstFormType Then &apos; Add the form to the list
  822. sCollectNames = sCollectNames &amp; cstToken &amp; oSubItem.HierarchicalName
  823. Else
  824. sCollectNames = sCollectNames &amp; cstToken &amp; _CollectFormDocuments(oSubItem)
  825. End If
  826. Next i
  827. End With
  828. Finally:
  829. _CollectFormDocuments = Mid(sCollectNames, Len(cstToken) + 1) &apos; Skip the initial token
  830. Exit Function
  831. End Function &apos; SFDocuments.SF_Base._CollectFormDocuments
  832. REM -----------------------------------------------------------------------------
  833. Private Function _FileIdent() As String
  834. &apos;&apos;&apos; Returns a file identification from the information that is currently available
  835. &apos;&apos;&apos; Useful e.g. for display in error messages
  836. _FileIdent = [_Super]._FileIdent()
  837. End Function &apos; SFDocuments.SF_Base._FileIdent
  838. REM -----------------------------------------------------------------------------
  839. Private Function _FindByPersistentName(ByRef poContainer As Object _
  840. , psPersistent As String _
  841. ) As Object
  842. &apos;&apos;&apos; The FormDocuments property of a Base component has strangely
  843. &apos;&apos;&apos; a getByHierarchical() method but no access to the same com.sun.star.comp.sdb.Content
  844. &apos;&apos;&apos; object via its persistent/ODF name
  845. &apos;&apos;&apos; This method returns the object having the given persistent name
  846. &apos;&apos;&apos; The function traverses recursively the whole tree below the container until found
  847. &apos;&apos;&apos; The initial call starts from the container _Component.getFormDocuments
  848. &apos;&apos;&apos; The list contains closed and open forms
  849. &apos;&apos;&apos; Args:
  850. &apos;&apos;&apos; poContainer: the actual top of the free, initially _FormDocuments
  851. &apos;&apos;&apos; psPersistent: a name like &quot;Obj...&quot;
  852. &apos;&apos;&apos; Returns:
  853. &apos;&apos;&apos; A com.sun.star.comp.sdb.Content object (object found, the process stops)
  854. &apos;&apos;&apos; or Nothing (object not found, the process continues)
  855. Dim oMainForm As Object &apos; Return value
  856. Dim oSubItem As Object &apos; com.sun.star.container.XNameAccess (folder) or com.sun.star.ucb.XContent (form)
  857. Dim i As Long
  858. Const cstFormType = &quot;application/vnd.oasis.opendocument.text&quot;
  859. &apos; Identifies forms. Folders have a zero-length content type
  860. On Local Error GoTo Finally
  861. Try:
  862. Set oMainForm = Nothing
  863. With poContainer
  864. For i = 0 To .Count - 1
  865. Set oSubItem = .getByIndex(i)
  866. If oSubItem.ContentType = cstFormType Then &apos; Examine its persistent name
  867. If oSubItem.PersistentName = psPersistent Then
  868. Set oMainForm = oSubItem
  869. Exit For
  870. End If
  871. Else
  872. Set oMainForm = _FindByPersistentName(oSubItem, psPersistent)
  873. End If
  874. Next i
  875. End With
  876. Finally:
  877. Set _FindByPersistentName = oMainForm
  878. Exit Function
  879. End Function &apos; SFDocuments.SF_Base.FindByPersistentName
  880. REM -----------------------------------------------------------------------------
  881. Private Function _IsStillAlive(Optional ByVal pbForUpdate As Boolean _
  882. , Optional ByVal pbError As Boolean _
  883. ) As Boolean
  884. &apos;&apos;&apos; Returns True if the document has not been closed manually or incidentally since the last use
  885. &apos;&apos;&apos; If dead the actual instance is disposed. The execution is cancelled when pbError = True (default)
  886. &apos;&apos;&apos; Args:
  887. &apos;&apos;&apos; pbForUpdate: if True (default = False), check additionally if document is open for editing
  888. &apos;&apos;&apos; pbError: if True (default), raise a fatal error
  889. Dim bAlive As Boolean &apos; Return value
  890. If IsMissing(pbForUpdate) Then pbForUpdate = False
  891. If IsMissing(pbError) Then pbError = True
  892. Try:
  893. bAlive = [_Super]._IsStillAlive(pbForUpdate, pbError)
  894. Finally:
  895. _IsStillAlive = bAlive
  896. Exit Function
  897. End Function &apos; SFDocuments.SF_Base._IsStillAlive
  898. REM -----------------------------------------------------------------------------
  899. Private Function _PropertyGet(Optional ByVal psProperty As String _
  900. , Optional ByVal pvArg As Variant _
  901. ) As Variant
  902. &apos;&apos;&apos; Return the value of the named property
  903. &apos;&apos;&apos; Args:
  904. &apos;&apos;&apos; psProperty: the name of the property
  905. Dim oProperties As Object &apos; Document or Custom properties
  906. Dim vLastCell As Variant &apos; Coordinates of last used cell in a sheet
  907. Dim oSelect As Object &apos; Current selection
  908. Dim vRanges As Variant &apos; List of selected ranges
  909. Dim i As Long
  910. Dim cstThisSub As String
  911. Const cstSubArgs = &quot;&quot;
  912. _PropertyGet = False
  913. cstThisSub = &quot;SFDocuments.SF_Base.get&quot; &amp; psProperty
  914. ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
  915. If Not _IsStillAlive() Then GoTo Finally
  916. Select Case psProperty
  917. Case Else
  918. _PropertyGet = Null
  919. End Select
  920. Finally:
  921. ScriptForge.SF_Utils._ExitFunction(cstThisSub)
  922. Exit Function
  923. End Function &apos; SFDocuments.SF_Base._PropertyGet
  924. REM -----------------------------------------------------------------------------
  925. Private Function _Repr() As String
  926. &apos;&apos;&apos; Convert the SF_Base instance to a readable string, typically for debugging purposes (DebugPrint ...)
  927. &apos;&apos;&apos; Args:
  928. &apos;&apos;&apos; Return:
  929. &apos;&apos;&apos; &quot;[Base]: Type/File&quot;
  930. _Repr = &quot;[Base]: &quot; &amp; [_Super]._FileIdent()
  931. End Function &apos; SFDocuments.SF_Base._Repr
  932. REM ============================================ END OF SFDOCUMENTS.SF_BASE
  933. </script:module>