mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-03-28 03:53:59 +08:00
更新windows内置office目录名, 适配jodconverter
This commit is contained in:
464
server/libreoffice/share/basic/SFDocuments/SF_Base.xba
Normal file
464
server/libreoffice/share/basic/SFDocuments/SF_Base.xba
Normal file
@@ -0,0 +1,464 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Base" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === The SFDocuments library is one of the associated libraries. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option ClassModule
|
||||
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' SF_Base
|
||||
''' =======
|
||||
'''
|
||||
''' The SFDocuments library gathers a number of methods and properties making easy
|
||||
''' the management and several manipulations of LibreOffice documents
|
||||
'''
|
||||
''' Some methods are generic for all types of documents: they are combined in the SF_Document module.
|
||||
''' Specific properties and methods are implemented in the concerned subclass(es) SF_Calc, SF_Writer, ...
|
||||
'''
|
||||
''' To workaround the absence of class inheritance in LibreOffice Basic, some redundancy is necessary
|
||||
''' Each subclass MUST implement also the generic methods and properties, even if they only call
|
||||
''' the parent methods and properties.
|
||||
''' They should also duplicate some generic private members as a subset of their own set of members
|
||||
'''
|
||||
''' The SF_Base module is provided only to block parent properties that are NOT applicable to Base documents
|
||||
'''
|
||||
''' The current module is closely related to the "UI" service of the ScriptForge library
|
||||
'''
|
||||
''' Service invocation examples:
|
||||
''' 1) From the UI service
|
||||
''' Dim ui As Object, oDoc As Object
|
||||
''' Set ui = CreateScriptService("UI")
|
||||
''' Set oDoc = ui.CreateBaseDocument("C:\Me\MyFile.odb", ...)
|
||||
''' ' or Set oDoc = ui.OpenDocument("C:\Me\MyFile.odb")
|
||||
''' 2) Directly if the document is already opened
|
||||
''' Dim oDoc As Object
|
||||
''' Set oDoc = CreateScriptService("SFDocuments.Base", "MyFile.odb")
|
||||
''' ' The substring "SFDocuments." in the service name is optional
|
||||
'''
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
Private Const DBCONNECTERROR = "DBCONNECTERROR"
|
||||
|
||||
REM ============================================================= PRIVATE MEMBERS
|
||||
|
||||
Private [Me] As Object
|
||||
Private [_Parent] As Object
|
||||
Private [_Super] As Object ' Document superclass, which the current instance is a subclass of
|
||||
Private ObjectType As String ' Must be BASE
|
||||
Private ServiceName As String
|
||||
|
||||
' Window component
|
||||
Private _Component As Object ' com.sun.star.comp.dba.ODatabaseDocument
|
||||
Private _DataSource As Object ' com.sun.star.comp.dba.ODatabaseSource
|
||||
Private _Database As Object ' SFDatabases.Database service instance
|
||||
|
||||
REM ============================================================ MODULE CONSTANTS
|
||||
|
||||
REM ===================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Initialize()
|
||||
Set [Me] = Nothing
|
||||
Set [_Parent] = Nothing
|
||||
Set [_Super] = Nothing
|
||||
ObjectType = "BASE"
|
||||
ServiceName = "SFDocuments.Base"
|
||||
Set _Component = Nothing
|
||||
Set _DataSource = Nothing
|
||||
Set _Database = Nothing
|
||||
End Sub ' SFDocuments.SF_Base Constructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Terminate()
|
||||
Call Class_Initialize()
|
||||
End Sub ' SFDocuments.SF_Base Destructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Dispose() As Variant
|
||||
If Not IsNull([_Super]) Then Set [_Super] = [_Super].Dispose()
|
||||
Call Class_Terminate()
|
||||
Set Dispose = Nothing
|
||||
End Function ' SFDocuments.SF_Base Explicit Destructor
|
||||
|
||||
REM ================================================================== PROPERTIES
|
||||
|
||||
REM ===================================================================== METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function CloseDocument(Optional ByVal SaveAsk As Variant) As Boolean
|
||||
''' The closure of a Base document requires the closures of
|
||||
''' 1) the connection => done in the CloseDatabase() method
|
||||
''' 2) the data source
|
||||
''' 3) the document itself => done in the superclass
|
||||
|
||||
Const cstThisSub = "SFDocuments.Base.CloseDocument"
|
||||
Const cstSubArgs = "[SaveAsk=True]"
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If IsMissing(SaveAsk) Or IsEmpty(SaveAsk) Then SaveAsk = True
|
||||
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not [_Super]._IsStillAlive(True) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(SaveAsk, "SaveAsk", V_BOOLEAN) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
If Not IsNull(_Database) Then _Database.CloseDatabase()
|
||||
If Not IsNull(_DataSource) Then _DataSource.dispose()
|
||||
CloseDocument = [_Super].CloseDocument(SaveAsk)
|
||||
|
||||
Finally:
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Base.CloseDocument
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetDatabase(Optional ByVal User As Variant _
|
||||
, Optional ByVal Password As Variant _
|
||||
) As Object
|
||||
''' Returns a Database instance (service = SFDatabases.Database) giving access
|
||||
''' to the execution of SQL commands on the database defined and/or stored in
|
||||
''' the actual Base document
|
||||
''' Args:
|
||||
''' User, Password: the login parameters as strings. Defaults = ""
|
||||
''' Returns:
|
||||
''' A SFDatabases.Database instance or Nothing
|
||||
''' Example:
|
||||
''' Dim myDb As Object
|
||||
''' Set myDb = oDoc.GetDatabase()
|
||||
|
||||
Const cstThisSub = "SFDocuments.Base.GetDatabase"
|
||||
Const cstSubArgs = "[User=""""], [Password=""""]"
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
Set GetDatabase = Nothing
|
||||
|
||||
Check:
|
||||
If IsMissing(User) Or IsEmpty(User) Then User = ""
|
||||
If IsMissing(Password) Or IsEmpty(Password) Then Password = ""
|
||||
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not [_Super]._IsStillAlive(True) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(User, "User", V_STRING) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(Password, "Password", V_STRING) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
If IsNull(_Database) Then ' 1st connection from the current document instance
|
||||
If IsNull(_DataSource) Then GoTo CatchConnect
|
||||
Set _Database = ScriptForge.SF_Services.CreateScriptService("SFDatabases.DatabaseFromDocument" _
|
||||
, _DataSource, User, Password)
|
||||
If IsNull(_Database) Then GoTo CatchConnect
|
||||
_Database._Location = [_Super]._WindowFileName
|
||||
EndIf
|
||||
|
||||
Finally:
|
||||
Set GetDatabase = _Database
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchConnect:
|
||||
ScriptForge.SF_Exception.RaiseFatal(DBCONNECTERROR, "User", User, "Password", Password, [_Super]._FileIdent())
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Base.GetDatabase
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
|
||||
''' Return the actual value of the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Returns:
|
||||
''' The actual value of the property
|
||||
''' Exceptions:
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "SFDocuments.Base.GetProperty"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
GetProperty = Null
|
||||
|
||||
Check:
|
||||
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not ScriptForge.SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
' Superclass or subclass property ?
|
||||
If ScriptForge.SF_Array.Contains([_Super].Properties(), PropertyName) Then
|
||||
GetProperty = [_Super].GetProperty(PropertyName)
|
||||
Else
|
||||
GetProperty = _PropertyGet(PropertyName)
|
||||
End If
|
||||
|
||||
Finally:
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Base.GetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Methods() As Variant
|
||||
''' Return the list of public methods of the Model service as an array
|
||||
|
||||
Methods = Array( _
|
||||
"Activate" _
|
||||
, "CloseDocument" _
|
||||
, "GetDatabase" _
|
||||
, "RunCommand" _
|
||||
, "Save" _
|
||||
, "SaveAs" _
|
||||
, "SaveCopyAs" _
|
||||
)
|
||||
|
||||
End Function ' SFDocuments.SF_Base.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties of the Timer class as an array
|
||||
|
||||
Properties = Array( _
|
||||
"DocumentType" _
|
||||
, "IsBase" _
|
||||
, "IsCalc" _
|
||||
, "IsDraw " _
|
||||
, "IsImpress" _
|
||||
, "IsMath" _
|
||||
, "IsWriter" _
|
||||
, "XComponent" _
|
||||
)
|
||||
|
||||
End Function ' SFDocuments.SF_Base.Properties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SetProperty(Optional ByVal PropertyName As Variant _
|
||||
, Optional ByRef Value As Variant _
|
||||
) As Boolean
|
||||
''' Set a new value to the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' Value: its new value
|
||||
''' Exceptions
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "SFDocuments.Base.SetProperty"
|
||||
Const cstSubArgs = "PropertyName, Value"
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
SetProperty = False
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
Select Case UCase(PropertyName)
|
||||
Case Else
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Documents.SetProperty
|
||||
|
||||
REM ======================================================= SUPERCLASS PROPERTIES
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get CustomProperties() As Variant
|
||||
' CustomProperties = [_Super].GetProperty("CustomProperties")
|
||||
'End Property ' SFDocuments.SF_Base.CustomProperties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Let CustomProperties(Optional ByVal pvCustomProperties As Variant)
|
||||
' [_Super].CustomProperties = pvCustomProperties
|
||||
'End Property ' SFDocuments.SF_Base.CustomProperties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get Description() As Variant
|
||||
' Description = [_Super].GetProperty("Description")
|
||||
'End Property ' SFDocuments.SF_Base.Description
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Let Description(Optional ByVal pvDescription As Variant)
|
||||
' [_Super].Description = pvDescription
|
||||
'End Property ' SFDocuments.SF_Base.Description
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get DocumentProperties() As Variant
|
||||
' DocumentProperties = [_Super].GetProperty("DocumentProperties")
|
||||
'End Property ' SFDocuments.SF_Base.DocumentProperties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get DocumentType() As String
|
||||
DocumentType = [_Super].GetProperty("DocumentType")
|
||||
End Property ' SFDocuments.SF_Base.DocumentType
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsBase() As Boolean
|
||||
IsBase = [_Super].GetProperty("IsBase")
|
||||
End Property ' SFDocuments.SF_Base.IsBase
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsCalc() As Boolean
|
||||
IsCalc = [_Super].GetProperty("IsCalc")
|
||||
End Property ' SFDocuments.SF_Base.IsCalc
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsDraw() As Boolean
|
||||
IsDraw = [_Super].GetProperty("IsDraw")
|
||||
End Property ' SFDocuments.SF_Base.IsDraw
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsImpress() As Boolean
|
||||
IsImpress = [_Super].GetProperty("IsImpress")
|
||||
End Property ' SFDocuments.SF_Base.IsImpress
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsMath() As Boolean
|
||||
IsMath = [_Super].GetProperty("IsMath")
|
||||
End Property ' SFDocuments.SF_Base.IsMath
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsWriter() As Boolean
|
||||
IsWriter = [_Super].GetProperty("IsWriter")
|
||||
End Property ' SFDocuments.SF_Base.IsWriter
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get Keywords() As Variant
|
||||
' Keywords = [_Super].GetProperty("Keywords")
|
||||
'End Property ' SFDocuments.SF_Base.Keywords
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Let Keywords(Optional ByVal pvKeywords As Variant)
|
||||
' [_Super].Keywords = pvKeywords
|
||||
'End Property ' SFDocuments.SF_Base.Keywords
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get Readonly() As Variant
|
||||
' Readonly = [_Super].GetProperty("Readonly")
|
||||
'End Property ' SFDocuments.SF_Base.Readonly
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get Subject() As Variant
|
||||
' Subject = [_Super].GetProperty("Subject")
|
||||
'End Property ' SFDocuments.SF_Base.Subject
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Let Subject(Optional ByVal pvSubject As Variant)
|
||||
' [_Super].Subject = pvSubject
|
||||
'End Property ' SFDocuments.SF_Base.Subject
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Get Title() As Variant
|
||||
' Title = [_Super].GetProperty("Title")
|
||||
'End Property ' SFDocuments.SF_Base.Title
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
'Property Let Title(Optional ByVal pvTitle As Variant)
|
||||
' [_Super].Title = pvTitle
|
||||
'End Property ' SFDocuments.SF_Base.Title
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get XComponent() As Variant
|
||||
XComponent = [_Super].GetProperty("XComponent")
|
||||
End Property ' SFDocuments.SF_Base.XComponent
|
||||
|
||||
REM ========================================================== SUPERCLASS METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Activate() As Boolean
|
||||
Activate = [_Super].Activate()
|
||||
End Function ' SFDocuments.SF_Base.Activate
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub RunCommand(Optional ByVal Command As Variant)
|
||||
[_Super].RunCommand(Command)
|
||||
End Sub ' SFDocuments.SF_Base.RunCommand
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Save() As Boolean
|
||||
Save = [_Super].Save()
|
||||
End Function ' SFDocuments.SF_Base.Save
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SaveAs(Optional ByVal FileName As Variant _
|
||||
, Optional ByVal Overwrite As Variant _
|
||||
, Optional ByVal Password As Variant _
|
||||
, Optional ByVal FilterName As Variant _
|
||||
, Optional ByVal FilterOptions As Variant _
|
||||
) As Boolean
|
||||
SaveAs = [_Super].SaveAs(FileName, Overwrite, Password, FilterName, FilterOptions)
|
||||
End Function ' SFDocuments.SF_Base.SaveAs
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SaveCopyAs(Optional ByVal FileName As Variant _
|
||||
, Optional ByVal Overwrite As Variant _
|
||||
, Optional ByVal Password As Variant _
|
||||
, Optional ByVal FilterName As Variant _
|
||||
, Optional ByVal FilterOptions As Variant _
|
||||
) As Boolean
|
||||
SaveCopyAs = [_Super].SaveCopyAs(FileName, Overwrite, Password, FilterName, FilterOptions)
|
||||
End Function ' SFDocuments.SF_Base.SaveCopyAs
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _PropertyGet(Optional ByVal psProperty As String _
|
||||
, Optional ByVal pvArg As Variant _
|
||||
) As Variant
|
||||
''' Return the value of the named property
|
||||
''' Args:
|
||||
''' psProperty: the name of the property
|
||||
|
||||
Dim oProperties As Object ' Document or Custom properties
|
||||
Dim vLastCell As Variant ' Coordinates of last used cell in a sheet
|
||||
Dim oSelect As Object ' Current selection
|
||||
Dim vRanges As Variant ' List of selected ranges
|
||||
Dim i As Long
|
||||
Dim cstThisSub As String
|
||||
Const cstSubArgs = ""
|
||||
|
||||
_PropertyGet = False
|
||||
|
||||
cstThisSub = "SFDocuments.SF_Base.get" & psProperty
|
||||
ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
If Not [_Super]._IsStillAlive() Then GoTo Finally
|
||||
|
||||
Select Case psProperty
|
||||
Case Else
|
||||
_PropertyGet = Null
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' SFDocuments.SF_Base._PropertyGet
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _Repr() As String
|
||||
''' Convert the SF_Base instance to a readable string, typically for debugging purposes (DebugPrint ...)
|
||||
''' Args:
|
||||
''' Return:
|
||||
''' "[Base]: Type/File"
|
||||
|
||||
_Repr = "[Base]: " & [_Super]._FileIdent()
|
||||
|
||||
End Function ' SFDocuments.SF_Base._Repr
|
||||
|
||||
REM ============================================ END OF SFDOCUMENTS.SF_BASE
|
||||
</script:module>
|
||||
2843
server/libreoffice/share/basic/SFDocuments/SF_Calc.xba
Normal file
2843
server/libreoffice/share/basic/SFDocuments/SF_Calc.xba
Normal file
File diff suppressed because it is too large
Load Diff
1010
server/libreoffice/share/basic/SFDocuments/SF_Document.xba
Normal file
1010
server/libreoffice/share/basic/SFDocuments/SF_Document.xba
Normal file
File diff suppressed because it is too large
Load Diff
198
server/libreoffice/share/basic/SFDocuments/SF_Register.xba
Normal file
198
server/libreoffice/share/basic/SFDocuments/SF_Register.xba
Normal file
@@ -0,0 +1,198 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="SF_Register" script:language="StarBasic" script:moduleType="normal">REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === The SFDocuments library is one of the associated libraries. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
Option Compatible
|
||||
Option Explicit
|
||||
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
''' SF_Register
|
||||
''' ===========
|
||||
''' The ScriptForge framework includes
|
||||
''' the master ScriptForge library
|
||||
''' a number of "associated" libraries SF*
|
||||
''' any user/contributor extension wanting to fit into the framework
|
||||
'''
|
||||
''' The main methods in this module allow the current library to cling to ScriptForge
|
||||
''' - RegisterScriptServices
|
||||
''' Register the list of services implemented by the current library
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
REM ============================================================== PUBLIC METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub RegisterScriptServices() As Variant
|
||||
''' Register into ScriptForge the list of the services implemented by the current library
|
||||
''' Each library pertaining to the framework must implement its own version of this method
|
||||
'''
|
||||
''' It consists in successive calls to the RegisterService() and RegisterEventManager() methods
|
||||
''' with 2 arguments:
|
||||
''' ServiceName: the name of the service as a case-insensitive string
|
||||
''' ServiceReference: the reference as an object
|
||||
''' If the reference refers to a module, then return the module as an object:
|
||||
''' GlobalScope.Library.Module
|
||||
''' If the reference is a class instance, then return a string referring to the method
|
||||
''' containing the New statement creating the instance
|
||||
''' "libraryname.modulename.function"
|
||||
|
||||
With GlobalScope.ScriptForge.SF_Services
|
||||
.RegisterService("Document", "SFDocuments.SF_Register._NewDocument") ' Reference to the function initializing the service
|
||||
.RegisterService("Calc", "SFDocuments.SF_Register._NewDocument") ' Same references, distinction is made inside the function
|
||||
.RegisterService("Base", "SFDocuments.SF_Register._NewDocument") ' Same references, distinction is made inside the function
|
||||
.RegisterEventManager("DocumentEvent", "SFDocuments.SF_Register._EventManager") ' Reference to the events manager
|
||||
'TODO
|
||||
End With
|
||||
|
||||
End Sub ' SFDocuments.SF_Register.RegisterScriptServices
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _EventManager(Optional ByRef pvArgs As Variant) As Object
|
||||
''' Returns a Document or Calc object corresponding with the active component
|
||||
''' which triggered the event in argument
|
||||
''' This method should be triggered only thru the invocation of CreateScriptService
|
||||
''' Args:
|
||||
''' pvEvent: com.sun.star.document.DocumentEvent
|
||||
''' Returns:
|
||||
''' the output of a Document, Calc, ... service or Nothing
|
||||
''' Example:
|
||||
''' Sub TriggeredByEvent(ByRef poEvent As Object)
|
||||
''' Dim oDoc As Object
|
||||
''' Set oDoc = CreateScriptService("SFDocuments.DocumentEvent", poEvent)
|
||||
''' If Not IsNull(oDoc) Then
|
||||
''' ' ... (a valid document has been identified)
|
||||
''' End Sub
|
||||
|
||||
Dim oSource As Object ' Return value
|
||||
Dim vEvent As Variant ' Alias of pvArgs(0)
|
||||
|
||||
' Never abort while an event is processed
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Finally
|
||||
Set oSource = Nothing
|
||||
|
||||
Check:
|
||||
If IsMissing(pvArgs) Or IsEmpty(pvArgs) Then pvArgs = Array()
|
||||
If UBound(pvArgs) >= 0 Then vEvent = pvArgs(0) Else Set vEvent = Empty
|
||||
If VarType(vEvent) <> ScriptForge.V_OBJECT Then GoTo Finally
|
||||
|
||||
Try:
|
||||
If ScriptForge.SF_Session.UnoObjectType(vEvent) = "com.sun.star.document.DocumentEvent" Then
|
||||
If ScriptForge.SF_Session.UnoObjectType(vEvent.Source) = "SwXTextDocument" Then
|
||||
Set oSource = SF_Register._NewDocument(vEvent.Source)
|
||||
End If
|
||||
End If
|
||||
|
||||
Finally:
|
||||
Set _EventManager = oSource
|
||||
Exit Function
|
||||
End Function ' SFDocuments.SF_Documents._EventManager
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _NewDocument(Optional ByVal pvArgs As Variant) As Object
|
||||
''' Create a new instance of the (super) SF_Document class or of one of its subclasses (SF_Calc, ...)
|
||||
' Args:
|
||||
''' WindowName: see the definition of WindowName in the description of the UI service
|
||||
''' If absent, the document is presumed to be in the active window
|
||||
''' If WindowName is an object, it must be a component
|
||||
''' (com.sun.star.lang.XComponent or com.sun.star.comp.dba.ODatabaseDocument)
|
||||
''' Returns: the instance or Nothing
|
||||
|
||||
Dim oDocument As Object ' Return value
|
||||
Dim oSuperDocument As Object ' Companion superclass document
|
||||
Dim vWindowName As Variant ' Alias of pvArgs(0)
|
||||
Dim oEnum As Object ' com.sun.star.container.XEnumeration
|
||||
Dim oComp As Object ' com.sun.star.lang.XComponent
|
||||
Dim vWindow As Window ' A single component
|
||||
Dim oUi As Object ' "UI" service
|
||||
Dim bFound As Boolean ' True if the document is found on the desktop
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If IsMissing(pvArgs) Or IsEmpty(pvArgs) Then pvArgs = Array()
|
||||
If Not IsArray(pvArgs) Then pvArgs = Array(pvArgs) ' Needed when _NewDocument called from _EventManager
|
||||
If UBound(pvArgs) >= 0 Then vWindowName = pvArgs(0) Else vWindowName = ""
|
||||
If Not ScriptForge.SF_Utils._Validate(vWindowName, "WindowName", Array(V_STRING, ScriptForge.V_OBJECT)) Then GoTo Finally
|
||||
Set oDocument = Nothing
|
||||
|
||||
Try:
|
||||
Set oUi = ScriptForge.SF_Register.CreateScriptService("UI")
|
||||
Select Case VarType(vWindowName)
|
||||
Case V_STRING
|
||||
If Len(vWindowName) > 0 Then
|
||||
bFound = False
|
||||
Set oEnum = StarDesktop.Components().createEnumeration
|
||||
Do While oEnum.hasMoreElements
|
||||
Set oComp = oEnum.nextElement
|
||||
vWindow = oUi._IdentifyWindow(oComp)
|
||||
With vWindow
|
||||
' Does the current window match the argument ?
|
||||
If (Len(.WindowFileName) > 0 And .WindowFileName = ScriptForge.SF_FileSystem._ConvertToUrl(vWindowName)) _
|
||||
Or (Len(.WindowName) > 0 And .WindowName = vWindowName) _
|
||||
Or (Len(.WindowTitle) > 0 And .WindowTitle = vWindowName) Then
|
||||
bFound = True
|
||||
Exit Do
|
||||
End If
|
||||
End With
|
||||
Loop
|
||||
Else
|
||||
bFound = True
|
||||
vWindow = oUi._IdentifyWindow(StarDesktop.CurrentComponent)
|
||||
End If
|
||||
Case ScriptForge.V_OBJECT ' com.sun.star.lang.XComponent
|
||||
bFound = True
|
||||
vWindow = oUi._IdentifyWindow(vWindowName)
|
||||
End Select
|
||||
|
||||
If bFound And Not IsNull(vWindow.Frame) And Len(vWindow.DocumentType) > 0 Then
|
||||
' Create the right subclass and associate to it a new instance of the superclass
|
||||
Select Case vWindow.DocumentType
|
||||
Case "Base"
|
||||
Set oDocument = New SF_Base
|
||||
Set oSuperDocument = New SF_Document
|
||||
Set oDocument.[_Super] = oSuperDocument ' Now both super and subclass are twinned
|
||||
Case "Calc"
|
||||
Set oDocument = New SF_Calc
|
||||
Set oSuperDocument = New SF_Document
|
||||
Set oDocument.[_Super] = oSuperDocument ' Now both super and subclass are twinned
|
||||
Case Else ' Only superclass
|
||||
Set oDocument = New SF_Document
|
||||
Set oSuperDocument = oDocument
|
||||
End Select
|
||||
With oDocument ' Initialize attributes of subclass
|
||||
Set .[Me] = oDocument
|
||||
Set ._Component = vWindow.Component
|
||||
' Initialize specific attributes
|
||||
Select Case vWindow.DocumentType
|
||||
Case "Base"
|
||||
Set ._DataSource = ._Component.DataSource
|
||||
Case Else
|
||||
End Select
|
||||
End With
|
||||
With oSuperDocument ' Initialize attributes of superclass
|
||||
Set .[Me] = oSuperDocument
|
||||
Set ._Component = vWindow.Component
|
||||
Set ._Frame = vWindow.Frame
|
||||
._WindowName = vWindow.WindowName
|
||||
._WindowTitle = vWindow.WindowTitle
|
||||
._WindowFileName = vWindow.WindowFileName
|
||||
._DocumentType = vWindow.DocumentType
|
||||
End With
|
||||
End If
|
||||
|
||||
Finally:
|
||||
Set _NewDocument = oDocument
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Register._NewDocument
|
||||
|
||||
REM ============================================== END OF SFDOCUMENTS.SF_REGISTER
|
||||
</script:module>
|
||||
26
server/libreoffice/share/basic/SFDocuments/__License.xba
Normal file
26
server/libreoffice/share/basic/SFDocuments/__License.xba
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
||||
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="__License" script:language="StarBasic" script:moduleType="normal">
|
||||
''' Copyright 2019-2020 Jean-Pierre LEDURE, Jean-François NIFENECKER, Alain ROMEDENNE
|
||||
|
||||
REM =======================================================================================================================
|
||||
REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
|
||||
REM === The SFDocuments library is one of the associated libraries. ===
|
||||
REM === Full documentation is available on https://help.libreoffice.org/ ===
|
||||
REM =======================================================================================================================
|
||||
|
||||
''' ScriptForge is distributed in the hope that it will be useful,
|
||||
''' but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
''' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
''' ScriptForge is free software; you can redistribute it and/or modify it under the terms of either (at your option):
|
||||
|
||||
''' 1) The Mozilla Public License, v. 2.0. If a copy of the MPL was not
|
||||
''' distributed with this file, you can obtain one at http://mozilla.org/MPL/2.0/ .
|
||||
|
||||
''' 2) The GNU Lesser General Public License as published by
|
||||
''' the Free Software Foundation, either version 3 of the License, or
|
||||
''' (at your option) any later version. If a copy of the LGPL was not
|
||||
''' distributed with this file, see http://www.gnu.org/licenses/ .
|
||||
|
||||
</script:module>
|
||||
3
server/libreoffice/share/basic/SFDocuments/dialog.xlb
Normal file
3
server/libreoffice/share/basic/SFDocuments/dialog.xlb
Normal file
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
|
||||
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="SFDocuments" library:readonly="false" library:passwordprotected="false"/>
|
||||
9
server/libreoffice/share/basic/SFDocuments/script.xlb
Normal file
9
server/libreoffice/share/basic/SFDocuments/script.xlb
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE library:library PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "library.dtd">
|
||||
<library:library xmlns:library="http://openoffice.org/2000/library" library:name="SFDocuments" library:readonly="false" library:passwordprotected="false">
|
||||
<library:element library:name="__License"/>
|
||||
<library:element library:name="SF_Document"/>
|
||||
<library:element library:name="SF_Calc"/>
|
||||
<library:element library:name="SF_Register"/>
|
||||
<library:element library:name="SF_Base"/>
|
||||
</library:library>
|
||||
Reference in New Issue
Block a user