update
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,814 @@
|
||||
<?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_Chart" 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_Chart
|
||||
''' ========
|
||||
'''
|
||||
''' The SF_Chart module is focused on the description of chart documents
|
||||
''' stored in Calc sheets.
|
||||
''' With this service, many chart types and chart characteristics available
|
||||
''' in the user interface can be read or modified.
|
||||
'''
|
||||
''' Definitions
|
||||
''' Charts have 2 distinct names:
|
||||
''' - an internal name, given by the LibreOffice application
|
||||
''' - an optional user-defined name
|
||||
''' In the scope of the ScriptForge libraries, the chart name is the name given by the user.
|
||||
''' Only when there is no user name, the internal name may be used instead.
|
||||
'''
|
||||
''' Service invocation from the "Calc" service
|
||||
''' Either make a new chart
|
||||
''' calc.CreateChart(ChartName, SheetName, "SheetX.A1:C8")
|
||||
''' or select an existing one
|
||||
''' calc.Charts(SheetName, ChartName)
|
||||
'''
|
||||
''' Detailed user documentation:
|
||||
''' https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/sf_chart.html?DbPAR=BASIC
|
||||
'''
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
Private Const CHARTEXPORTERROR = "CHARTEXPORTERROR"
|
||||
|
||||
REM ============================================================= PRIVATE MEMBERS
|
||||
|
||||
Private [Me] As Object
|
||||
Private [_Parent] As Object ' Parent Calc document
|
||||
Private ObjectType As String ' Must be CHART
|
||||
Private ServiceName As String
|
||||
|
||||
' Chart description
|
||||
Private _SheetName As String ' Name of the Calc sheet containing the chart
|
||||
Private _DrawIndex As Long ' Index of the chart in the sheet's draw page
|
||||
Private _ChartName As String ' User name
|
||||
Private _PersistentName As String ' Internal name
|
||||
Private _Shape As Object ' com.sun.star.drawing.XShape
|
||||
Private _Chart As Object ' com.sun.star.table.XTableChart
|
||||
Private _ChartObject As Object ' com.sun.star.lang.XComponent - ScChartObj
|
||||
Private _Diagram As Object ' com.sun.star.chart.XDiagram
|
||||
|
||||
REM ============================================================ MODULE CONSTANTS
|
||||
|
||||
|
||||
REM ====================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Initialize()
|
||||
Set [Me] = Nothing
|
||||
Set [_Parent] = Nothing
|
||||
ObjectType = "CHART"
|
||||
ServiceName = "SFDocuments.Chart"
|
||||
_SheetName = ""
|
||||
_DrawIndex = -1
|
||||
_ChartName = ""
|
||||
_PersistentName = ""
|
||||
Set _Shape = Nothing
|
||||
Set _Chart = Nothing
|
||||
Set _ChartObject = Nothing
|
||||
Set _Diagram = Nothing
|
||||
End Sub ' SFDocuments.SF_Chart Constructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Terminate()
|
||||
Call Class_Initialize()
|
||||
End Sub ' SFDocuments.SF_Chart Destructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Dispose() As Variant
|
||||
Call Class_Terminate()
|
||||
Set Dispose = Nothing
|
||||
End Function ' SFDocuments.SF_Chart Explicit Destructor
|
||||
|
||||
REM ================================================================== PROPERTIES
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get ChartType() As Variant
|
||||
''' The ChartType property specifies the type of chart as a string among next values:
|
||||
''' Pie, Bar, Donut, Column, Area, Line, XY, Bubble, Net
|
||||
ChartType = _PropertyGet("ChartType")
|
||||
End Property ' SFDocuments.SF_Chart.ChartType (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let ChartType(Optional ByVal pvChartType As Variant)
|
||||
''' Set the updatable property ChartType
|
||||
_PropertySet("ChartType", pvChartType)
|
||||
End Property ' SFDocuments.SF_Chart.ChartType (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Deep() As Variant
|
||||
''' If True, determines that in a three-dimensional bar chart the bars of each series are arranged behind each other in the z-direction.
|
||||
''' If False the arrangement of bars is like in two-dimensional bar charts.
|
||||
''' Bar and Column chart types only
|
||||
Deep = _PropertyGet("Deep")
|
||||
End Property ' SFDocuments.SF_Chart.Deep (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Deep(Optional ByVal pvDeep As Variant)
|
||||
''' Set the updatable property Deep
|
||||
_PropertySet("Deep", pvDeep)
|
||||
End Property ' SFDocuments.SF_Chart.Deep (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Dim3D() As Variant
|
||||
''' The Dim3D property specifies if the chart is displayed with 3D elements
|
||||
''' String or Boolean
|
||||
''' When String, must be 1 of next values: Bar, Cylinder, Cone or Pyramid
|
||||
''' When Boolean True, Bar is assumed; when False, no 3D to be applied
|
||||
Dim3D = _PropertyGet("Dim3D")
|
||||
End Property ' SFDocuments.SF_Chart.Dim3D (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Dim3D(Optional ByVal pvDim3D As Variant)
|
||||
''' Set the updatable property Dim3D
|
||||
_PropertySet("Dim3D", pvDim3D)
|
||||
End Property ' SFDocuments.SF_Chart.Dim3D (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Exploded() As Variant
|
||||
''' the offset by which pie segments in a PieDiagram (pie or donut) are dragged outside from the center.
|
||||
''' This value is given in percent of the radius.
|
||||
Exploded = _PropertyGet("Exploded")
|
||||
End Property ' SFDocuments.SF_Chart.Exploded (get)_ChartObject
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Exploded(Optional ByVal pvExploded As Variant)
|
||||
''' Set the updatable property Exploded
|
||||
_PropertySet("Exploded", pvExploded)
|
||||
End Property ' SFDocuments.SF_Chart.Exploded (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Filled() As Variant
|
||||
''' When True, the Net diagram is said of FilledNet type
|
||||
''' Net chart type only
|
||||
Filled = _PropertyGet("Filled")
|
||||
End Property ' SFDocuments.SF_Chart.Filled (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Filled(Optional ByVal pvFilled As Variant)
|
||||
''' Set the updatable property Filled
|
||||
_PropertySet("Filled", pvFilled)
|
||||
End Property ' SFDocuments.SF_Chart.Filled (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Legend() As Variant
|
||||
''' Specifies if the chart has a legend
|
||||
Legend = _PropertyGet("Legend")
|
||||
End Property ' SFDocuments.SF_Chart.Legend (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Legend(Optional ByVal pvLegend As Variant)
|
||||
''' Set the updatable property Legend
|
||||
_PropertySet("Legend", pvLegend)
|
||||
End Property ' SFDocuments.SF_Chart.Legend (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Percent() As Variant
|
||||
''' When True, the series of the diagram are stacked and each category sums up to 100%.
|
||||
''' Area, Bar, Bubble, Column and Net chart types only_ChartObject
|
||||
Percent = _PropertyGet("Percent")
|
||||
End Property ' SFDocuments.SF_Chart.Percent (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Percent(Optional ByVal pvPercent As Variant)
|
||||
''' Set the updatable property Percent
|
||||
_PropertySet("Percent", pvPercent)
|
||||
End Property ' SFDocuments.SF_Chart.Percent (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Stacked() As Variant
|
||||
''' When True, the series of the diagram are stacked.
|
||||
''' Area, Bar, Bubble, Column and Net chart types only
|
||||
Stacked = _PropertyGet("Stacked")
|
||||
End Property ' SFDocuments.SF_Chart.Stacked (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Stacked(Optional ByVal pvStacked As Variant)
|
||||
''' Set the updatable property Stacked
|
||||
_PropertySet("Stacked", pvStacked)
|
||||
End Property ' SFDocuments.SF_Chart.Stacked (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Title() As Variant
|
||||
''' Specifies the main title of the chart
|
||||
Title = _PropertyGet("Title")
|
||||
End Property ' SFDocuments.SF_Chart.Title (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Title(Optional ByVal pvTitle As Variant)
|
||||
''' Set the updatable property Title
|
||||
_PropertySet("Title", pvTitle)
|
||||
End Property ' SFDocuments.SF_Chart.Title (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get XTitle() As Variant
|
||||
''' Specifies the main XTitle of the chart
|
||||
XTitle = _PropertyGet("XTitle")
|
||||
End Property ' SFDocuments.SF_Chart.XTitle (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let XTitle(Optional ByVal pvXTitle As Variant)
|
||||
''' Set the updatable property XTitle
|
||||
_PropertySet("XTitle", pvXTitle)
|
||||
End Property ' SFDocuments.SF_Chart.XTitle (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get YTitle() As Variant
|
||||
''' Specifies the main YTitle of the chart
|
||||
YTitle = _PropertyGet("YTitle")
|
||||
End Property ' SFDocuments.SF_Chart.YTitle (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let YTitle(Optional ByVal pvYTitle As Variant)
|
||||
''' Set the updatable property YTitle
|
||||
_PropertySet("YTitle", pvYTitle)
|
||||
End Property ' SFDocuments.SF_Chart.YTitle (let)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get XChartObj() As Variant
|
||||
''' com.sun.star.lang.XComponent - ScChartObj
|
||||
ChartType = _PropertyGet("XChartObj")
|
||||
End Property ' SFDocuments.SF_Chart.XChartObj (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get XDiagram() As Variant
|
||||
''' com.sun.star.chart.XDiagram
|
||||
ChartType = _PropertyGet("XDiagram")
|
||||
End Property ' SFDocuments.SF_Chart.XDiagram (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get XShape() As Variant
|
||||
''' com.sun.star.drawing.XShape
|
||||
ChartType = _PropertyGet("XShape")
|
||||
End Property ' SFDocuments.SF_Chart.XShape (get)
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get XTableChart() As Variant
|
||||
''' com.sun.star.table.XTableChart
|
||||
ChartType = _PropertyGet("XTableChart")
|
||||
End Property ' SFDocuments.SF_Chart.XTableChart (get)
|
||||
|
||||
REM ===================================================================== METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ExportToFile(Optional ByVal FileName As Variant _
|
||||
, Optional ByVal ImageType As Variant _
|
||||
, Optional ByVal Overwrite As Variant _
|
||||
) As Boolean
|
||||
''' Store the chart as an image to the given file location
|
||||
''' Args:
|
||||
''' FileName: Identifies the file where to save. It must follow the SF_FileSystem.FileNaming notation
|
||||
''' ImageType: the name of the targeted image type
|
||||
''' Allowed values: gif, jpeg, png (default), svg and tiff
|
||||
''' Overwrite: True if the destination file may be overwritten (default = False)
|
||||
''' Returns:
|
||||
''' False if the document could not be saved
|
||||
''' Exceptions:
|
||||
''' CHARTEXPORTERROR The destination has its readonly attribute set or overwriting rejected
|
||||
''' Examples:
|
||||
''' oChart.ExportToFile("C:\Me\Chart2.gif", ImageType := "gif", Overwrite := True)
|
||||
|
||||
Dim bSaved As Boolean ' return value
|
||||
Dim oSfa As Object ' com.sun.star.ucb.SimpleFileAccess
|
||||
Dim sFile As String ' Alias of FileName
|
||||
Dim vStoreArguments As Variant ' Array of com.sun.star.beans.PropertyValue
|
||||
Dim FSO As Object ' SF_FileSystem
|
||||
Dim oExport As Object ' com.sun.star.drawing.GraphicExportFilter
|
||||
Dim vImageTypes As Variant ' Array of permitted image types
|
||||
Dim vMimeTypes As Variant ' Array of corresponding mime types in the same order as vImageTypes
|
||||
|
||||
Const cstImageTypes = "gif,jpeg,png,svg,tiff"
|
||||
Const cstMimeTypes = "image/gif,image/jpeg,image/png,image/svg+xml,image/tiff"
|
||||
|
||||
Const cstThisSub = "SFDocuments.Chart.ExportToFile"
|
||||
Const cstSubArgs = "FileName, [ImageType=""png""|""gif""|""jpeg""|""svg""|""tiff""], [Overwrite=False]"
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo CatchError
|
||||
bSaved = False
|
||||
|
||||
Check:
|
||||
If IsMissing(ImageType) Or IsEmpty(ImageType) Then ImageType = "png"
|
||||
If IsMissing(Overwrite) Or IsEmpty(Overwrite) Then Overwrite = False
|
||||
|
||||
vImageTypes = Split(cstImageTypes, ",")
|
||||
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not [_Parent]._IsStillAlive() Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._ValidateFile(FileName, "FileName") Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(ImageType, "ImageType", V_STRING, vImageTypes) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(Overwrite, "Overwrite", ScriptForge.V_BOOLEAN) Then GoTo Finally
|
||||
End If
|
||||
|
||||
' Check destination file overwriting
|
||||
Set FSO = CreateScriptService("FileSystem")
|
||||
sFile = FSO._ConvertToUrl(FileName)
|
||||
If FSO.FileExists(FileName) Then
|
||||
If Overwrite = False Then GoTo CatchError
|
||||
Set oSfa = ScriptForge.SF_Utils._GetUNOService("FileAccess")
|
||||
If oSfa.isReadonly(sFile) Then GoTo CatchError
|
||||
End If
|
||||
|
||||
Try:
|
||||
' Setup arguments
|
||||
vMimeTypes = Split(cstMimeTypes, ",")
|
||||
vStoreArguments = Array( _
|
||||
ScriptForge.SF_Utils._MakePropertyValue("URL", sFile) _
|
||||
, ScriptForge.SF_Utils._MakePropertyValue("MediaType" _
|
||||
, vMimeTypes(ScriptForge.SF_Array.IndexOf(vImageTypes, ImageType, CaseSensitive := False))) _
|
||||
)
|
||||
' Export with the com.sun.star.drawing.GraphicExportFilter UNO service
|
||||
Set oExport = ScriptForge.SF_Utils._GetUNOService("GraphicExportFilter")
|
||||
With oExport
|
||||
.setSourceDocument(_Shape)
|
||||
.filter(vStoreArguments)
|
||||
End With
|
||||
bSaved = True
|
||||
|
||||
Finally:
|
||||
ExportToFile = bSaved
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchError:
|
||||
ScriptForge.SF_Exception.RaiseFatal(CHARTEXPORTERROR, "FileName", FileName, "Overwrite", Overwrite)
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Chart.ExportToFile
|
||||
|
||||
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
|
||||
''' If the property does not exist, returns Null
|
||||
''' Exceptions:
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "SFDocuments.Chart.GetProperty"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
GetProperty = Null
|
||||
|
||||
Check:
|
||||
If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
GetProperty = _PropertyGet(PropertyName)
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Chart.GetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Methods() As Variant
|
||||
''' Return the list of public methods of the Chart service as an array
|
||||
|
||||
Methods = Array( _
|
||||
"ExportToFile" _
|
||||
, "Resize" _
|
||||
)
|
||||
|
||||
End Function ' SFDocuments.SF_Chart.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties of the Chart class as an array
|
||||
|
||||
Properties = Array( _
|
||||
"ChartType" _
|
||||
, "Deep" _
|
||||
, "Dim3D" _
|
||||
, "Exploded" _
|
||||
, "Filled" _
|
||||
, "Legend" _
|
||||
, "Percent" _
|
||||
, "Stacked" _
|
||||
, "Title" _
|
||||
, "XChartObj" _
|
||||
, "XDiagram" _
|
||||
, "XShape" _
|
||||
, "XTableChart" _
|
||||
, "XTitle" _
|
||||
, "YTitle" _
|
||||
)
|
||||
|
||||
End Function ' SFDocuments.SF_Chart.Properties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Resize(Optional ByVal XPos As Variant _
|
||||
, Optional ByVal YPos As Variant _
|
||||
, Optional ByVal Width As Variant _
|
||||
, Optional ByVal Height As Variant _
|
||||
) As Boolean
|
||||
''' Move the topleft corner of a chart to new coordinates and/or modify its dimensions
|
||||
''' All distances are expressed in 1/100th mm
|
||||
''' Args:
|
||||
''' XPos : the vertical distance from the topleft corner
|
||||
''' YPos : the horizontal distance from the topleft corner
|
||||
''' Width : the horizontal width of the shape containing the chart
|
||||
''' Height : the vertical height of the shape containing the chart
|
||||
''' Negative or missing arguments are left unchanged
|
||||
''' Returns:
|
||||
''' True when successful
|
||||
''' Examples:
|
||||
''' oChart.Resize(1000, 2000, Height := 6000) ' Width is not changed
|
||||
|
||||
Dim bResize As Boolean ' Return value
|
||||
Dim oPosition As Object ' com.sun.star.awt.Point
|
||||
Dim oSize As Object ' com.sun.star.awt.Size
|
||||
Const cstThisSub = "SFDocuments.Chart.Resize"
|
||||
Const cstSubArgs = "[XPos], [YPos], [Width], [Height]"
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bResize = False
|
||||
|
||||
Check:
|
||||
If IsMissing(XPos) Or IsEmpty(XPos) Then XPos = -1
|
||||
If IsMissing(YPos) Or IsEmpty(YPos) Then YPos = -1
|
||||
If IsMissing(Height) Or IsEmpty(Height) Then Height = -1
|
||||
If IsMissing(Width) Or IsEmpty(Width) Then Width = -1
|
||||
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not [_Parent]._IsStillAlive() Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(XPos, "XPos", ScriptForge.V_NUMERIC) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(YPos, "YPos", ScriptForge.V_NUMERIC) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(Width, "Width", ScriptForge.V_NUMERIC) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(Height, "Height", ScriptForge.V_NUMERIC) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
With _Shape
|
||||
' Get the current values
|
||||
Set oPosition = .Position
|
||||
Set oSize = .Size
|
||||
' Modify relevant elements
|
||||
If XPos >= 0 Then oPosition.X = CLng(XPos)
|
||||
If YPos >= 0 Then oPosition.Y = CLng(YPos)
|
||||
If Width > 0 Then oSize.Width = CLng(Width)
|
||||
If Height > 0 Then oSize.Height = CLng(Height)
|
||||
' Rewrite
|
||||
.setPosition(oPosition)
|
||||
.setSize(oSize)
|
||||
End With
|
||||
bResize = True
|
||||
|
||||
Finally:
|
||||
Resize = bResize
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SF_Documents.SF_Chart.Resize
|
||||
|
||||
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.Chart.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 ScriptForge.SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
SetProperty = _PropertySet(PropertyName, Value)
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Chart.SetProperty
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
|
||||
''' Return the value of the named property
|
||||
''' Args:
|
||||
''' psProperty: the name of the property
|
||||
|
||||
Static oSession As Object ' Alias of SF_Session
|
||||
Dim vData As Variant ' Data points array of values
|
||||
|
||||
Dim cstThisSub As String
|
||||
Const cstSubArgs = ""
|
||||
|
||||
cstThisSub = "SFDocuments.Chart.get" & psProperty
|
||||
SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
If Not [_Parent]._IsStillAlive() Then GoTo Finally
|
||||
|
||||
If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService("Session")
|
||||
Select Case UCase(psProperty)
|
||||
Case UCase("ChartType")
|
||||
With _Diagram
|
||||
Select Case .DiagramType
|
||||
Case "com.sun.star.chart.BarDiagram"
|
||||
If .Vertical Then _PropertyGet = "Bar" Else _PropertyGet = "Column"
|
||||
Case "com.sun.star.chart.PieDiagram"
|
||||
_PropertyGet = "Pie"
|
||||
Case "com.sun.star.chart.DonutDiagram"
|
||||
_PropertyGet = "Donut"
|
||||
Case "com.sun.star.chart.AreaDiagram"
|
||||
_PropertyGet = "Area"
|
||||
Case "com.sun.star.chart.LineDiagram"
|
||||
_PropertyGet = "Line"
|
||||
Case "com.sun.star.chart.XYDiagram"
|
||||
_PropertyGet = "XY"
|
||||
Case "com.sun.star.chart.BubbleDiagram"
|
||||
_PropertyGet = "Bubble"
|
||||
Case "com.sun.star.chart.NetDiagram", "com.sun.star.chart.FilledNetDiagram"
|
||||
_PropertyGet = "Net"
|
||||
Case Else
|
||||
_PropertyGet = ""
|
||||
End Select
|
||||
End With
|
||||
Case UCase("Deep")
|
||||
If oSession.HasUnoProperty(_Diagram, "Deep") Then _PropertyGet = _Diagram.Deep Else _PropertyGet = False
|
||||
Case UCase("Dim3D")
|
||||
If oSession.HasUnoProperty(_Diagram, "Dim3D") Then
|
||||
If _Diagram.Dim3D Then
|
||||
If oSession.HasUnoProperty(_Diagram, "SolidType") Then
|
||||
Select Case _Diagram.SolidType
|
||||
Case com.sun.star.chart.ChartSolidType.RECTANGULAR_SOLID : _PropertyGet = "Bar"
|
||||
Case com.sun.star.chart.ChartSolidType.CYLINDER : _PropertyGet = "Cylinder"
|
||||
Case com.sun.star.chart.ChartSolidType.CONE : _PropertyGet = "Cone"
|
||||
Case com.sun.star.chart.ChartSolidType.PYRAMID : _PropertyGet = "Pyramid"
|
||||
End Select
|
||||
Else
|
||||
_PropertyGet = _Diagram.Dim3D
|
||||
End If
|
||||
Else
|
||||
_PropertyGet = False
|
||||
End If
|
||||
Else
|
||||
_PropertyGet = False
|
||||
End If
|
||||
Case UCase("Exploded")
|
||||
If oSession.HasUnoProperty(_ChartObject, "Data") Then
|
||||
' All data points are presumed exploded with the same coefficient. Determine the (0, 0)th
|
||||
With _ChartObject
|
||||
vData = .Data.Data
|
||||
_PropertyGet = 0
|
||||
If IsArray(vData) Then
|
||||
If UBound(vData) >= 0 Then
|
||||
If IsArray(vData(0)) Then
|
||||
If UBound(vData(0)) >= 0 Then _PropertyGet = _Diagram.getDataPointProperties(0, 0).SegmentOffset
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End With
|
||||
End If
|
||||
Case UCase("Filled")
|
||||
_PropertyGet = ( _Diagram.DiagramType = "com.sun.star.chart.FilledNetDiagram" )
|
||||
Case UCase("Legend")
|
||||
If oSession.HasUnoProperty(_ChartObject, "HasLegend") Then _PropertyGet = _ChartObject.HasLegend Else _PropertyGet = False
|
||||
Case UCase("Percent")
|
||||
If oSession.HasUnoProperty(_Diagram, "Percent") Then _PropertyGet = _Diagram.Percent Else _PropertyGet = False
|
||||
Case UCase("Stacked")
|
||||
If oSession.HasUnoProperty(_Diagram, "Stacked") Then _PropertyGet = _Diagram.Stacked Else _PropertyGet = False
|
||||
Case UCase("Title")
|
||||
If oSession.HasUnoProperty(_ChartObject, "HasMainTitle") Then
|
||||
If _ChartObject.HasMainTitle Then _PropertyGet = _ChartObject.Title.String Else _PropertyGet = ""
|
||||
End If
|
||||
Case UCase("XTitle")
|
||||
If oSession.HasUnoProperty(_Diagram, "HasXAxisTitle") Then
|
||||
If _Diagram.HasXAxisTitle Then _PropertyGet = _Diagram.XAxisTitle.String Else _PropertyGet = ""
|
||||
End If
|
||||
Case UCase("YTitle")
|
||||
If oSession.HasUnoProperty(_Diagram, "HasYAxisTitle") Then
|
||||
If _Diagram.HasYAxisTitle Then _PropertyGet = _Diagram.YAxisTitle.String Else _PropertyGet = ""
|
||||
End If
|
||||
Case UCase("XChartObj")
|
||||
Set _PropertyGet = _ChartObject
|
||||
Case UCase("XDiagram")
|
||||
Set _PropertyGet = _Diagram
|
||||
Case UCase("XShape")
|
||||
Set _PropertyGet = _Shape
|
||||
Case UCase("XTableChart")
|
||||
Set _PropertyGet = _Chart
|
||||
Case Else
|
||||
_PropertyGet = Null
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
End Function ' SFDocuments.SF_Chart._PropertyGet
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _PropertySet(Optional ByVal psProperty As String _
|
||||
, Optional ByVal pvValue As Variant _
|
||||
) As Boolean
|
||||
''' Set the new value of the named property
|
||||
''' Args:
|
||||
''' psProperty: the name of the property
|
||||
''' pvValue: the new value of the given property
|
||||
|
||||
Dim bSet As Boolean ' Return value
|
||||
Static oSession As Object ' Alias of SF_Session
|
||||
Dim sChartType As String ' Diagram type
|
||||
Dim bDim3D As Boolean ' Alias of Dim3D property of diagram
|
||||
Dim bVertical As Boolean ' When True, chart type is a bar, not a column
|
||||
Dim vData As Variant ' Data points array of values
|
||||
Dim i As Long, j As Long
|
||||
Const cstChart = "com.sun.star.chart."
|
||||
|
||||
Dim cstThisSub As String
|
||||
Const cstSubArgs = "Value"
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bSet = False
|
||||
|
||||
cstThisSub = "SFDocuments.Chart.set" & psProperty
|
||||
ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
If Not [_Parent]._IsStillAlive() Then GoTo Catch
|
||||
|
||||
bSet = True
|
||||
If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService("Session")
|
||||
Select Case UCase(psProperty)
|
||||
Case UCase("ChartType")
|
||||
If Not ScriptForge.SF_Utils._Validate(pvValue, "ChartType", V_STRING _
|
||||
, Array("Bar", "Column", "Pie", "Donut", "Area", "Line", "XY", "Bubble", "Net") _
|
||||
) Then GoTo Finally
|
||||
With _Diagram
|
||||
' Specify the targeted chart type
|
||||
Select Case UCase(pvValue)
|
||||
Case "BAR", "COLUMN" : sChartType = cstChart & "BarDiagram"
|
||||
Case "PIE" : sChartType = cstChart & "PieDiagram"
|
||||
Case "DONUT" : sChartType = cstChart & "DonutDiagram"
|
||||
Case "AREA" : sChartType = cstChart & "AreaDiagram"
|
||||
Case "LINE" : sChartType = cstChart & "LineDiagram"
|
||||
Case "XY" : sChartType = cstChart & "XYDiagram"
|
||||
Case "BUBBLE" : sChartType = cstChart & "BubbleDiagram"
|
||||
Case "NET" : sChartType = cstChart & "NetDiagram"
|
||||
End Select
|
||||
' If there is no change, do nothing
|
||||
If sChartType <> .DiagramType Then
|
||||
' Some combinations old type => new type require the cancellation of 3D graphs
|
||||
bDim3D = .Dim3D
|
||||
.Dim3D = False
|
||||
_ChartObject.createInstance(sChartType)
|
||||
Set _Diagram = _ChartObject.Diagram
|
||||
.Dim3D = bDim3D
|
||||
End If
|
||||
If UCase(pvValue) = "BAR" Or UCase(pvValue) = "COLUMN" Then .Vertical = ( UCase(pvValue) = "BAR" )
|
||||
End With
|
||||
Case UCase("Deep")
|
||||
If Not ScriptForge.SF_Utils._Validate(pvValue, "Deep", ScriptForge.V_BOOLEAN) Then GoTo Finally
|
||||
If oSession.HasUnoProperty(_Diagram, "Deep") Then _Diagram.Deep = pvValue
|
||||
Case UCase("Dim3D")
|
||||
If Not ScriptForge.SF_Utils._Validate(pvValue, "Dim3D", Array(ScriptForge.V_Boolean, V_STRING) _
|
||||
, Array(False, True, "Bar", "Cylinder", "Cone", "Pyramid") _
|
||||
) Then GoTo Finally
|
||||
With _Diagram
|
||||
If oSession.HasUnoProperty(_Diagram, "Dim3D") Then
|
||||
If _Diagram.DiagramType = "com.sun.star.chart.BubbleDiagram" Then
|
||||
.Dim3D = False ' Force False value to avoid empty graph
|
||||
ElseIf VarType(pvValue) = V_STRING Then
|
||||
bVertical = .Vertical
|
||||
.Dim3D = True
|
||||
.Vertical = bVertical
|
||||
If oSession.HasUnoProperty(_Diagram, "SolidType") Then
|
||||
If .DiagramType = cstChart & "BarDiagram" Then
|
||||
Select Case UCase(pvValue)
|
||||
Case "BAR" : .SolidType = com.sun.star.chart.ChartSolidType.RECTANGULAR_SOLID
|
||||
Case "CYLINDER" : .SolidType = com.sun.star.chart.ChartSolidType.CYLINDER
|
||||
Case "CONE" : .SolidType = com.sun.star.chart.ChartSolidType.CONE
|
||||
Case "PYRAMID" : .SolidType = com.sun.star.chart.ChartSolidType.PYRAMID
|
||||
End Select
|
||||
Else
|
||||
.SolidType = 0
|
||||
End If
|
||||
End If
|
||||
Else ' Boolean
|
||||
If oSession.HasUnoProperty(_Diagram, "SolidType") Then .SolidType = 0
|
||||
.Dim3D = pvValue
|
||||
End If
|
||||
End If
|
||||
End With
|
||||
Case UCase("Exploded")
|
||||
If oSession.HasUnoProperty(_ChartObject, "Data") And _Diagram.DiagramType <> "com.sun.star.chart.BubbleDiagram" Then
|
||||
' All data points are presumed exploded with the same coefficient
|
||||
If Not ScriptForge.SF_Utils._Validate(pvValue, "Exploded", ScriptForge.V_NUMERIC) Then GoTo Finally
|
||||
With _ChartObject
|
||||
vData = .Data.Data
|
||||
If IsArray(vData) Then
|
||||
For i = 0 To UBound(vData)
|
||||
If IsArray(vData(i)) Then
|
||||
For j = 0 To UBound(vData(i))
|
||||
_Diagram.getDataPointProperties(i, j).SegmentOffset = CLng(pvValue)
|
||||
Next j
|
||||
End If
|
||||
Next i
|
||||
End If
|
||||
End With
|
||||
End If
|
||||
Case UCase("Filled")
|
||||
' Flipflop between NetDiagram and FilledNetDiagram
|
||||
If Not ScriptForge.SF_Utils._Validate(pvValue, "Filled", ScriptForge.V_BOOLEAN) Then GoTo Finally
|
||||
With _Diagram
|
||||
' Specify the targeted chart type
|
||||
sChartType = cstChart & Iif(pvValue, "Filled", "") & "NetDiagram"
|
||||
' If there is no change, do nothing
|
||||
If sChartType <> .DiagramType then
|
||||
' Do not apply if the chart type not = "Net"
|
||||
If (pvValue And .DiagramType = cstChart & "NetDiagram") _
|
||||
Or (Not pvValue And .DiagramType = cstChart & "FilledNetDiagram") Then
|
||||
' Some combinations old type => new type require the cancellation of 3D graphs
|
||||
bDim3D = .Dim3D
|
||||
.Dim3D = False
|
||||
_ChartObject.createInstance(sChartType)
|
||||
Set _Diagram = _ChartObject.Diagram
|
||||
.Dim3D = bDim3D
|
||||
End If
|
||||
End If
|
||||
End With
|
||||
Case UCase("Legend")
|
||||
If Not ScriptForge.SF_Utils._Validate(pvValue, "Legend", ScriptForge.V_BOOLEAN) Then GoTo Finally
|
||||
If oSession.HasUnoProperty(_ChartObject, "HasLegend") Then _ChartObject.HasLegend = pvValue
|
||||
Case UCase("Percent")
|
||||
If Not ScriptForge.SF_Utils._Validate(pvValue, "Percent", ScriptForge.V_BOOLEAN) Then GoTo Finally
|
||||
If oSession.HasUnoProperty(_Diagram, "Percent") Then
|
||||
_Diagram.Stacked = pvValue
|
||||
_Diagram.Percent = pvValue
|
||||
End If
|
||||
Case UCase("Stacked")
|
||||
If Not ScriptForge.SF_Utils._Validate(pvValue, "Stacked", ScriptForge.V_BOOLEAN) Then GoTo Finally
|
||||
If oSession.HasUnoProperty(_Diagram, "Stacked") Then
|
||||
_Diagram.Stacked = pvValue
|
||||
If Not pvValue Then _Diagram.Percent = False
|
||||
End If
|
||||
Case UCase("Title")
|
||||
If Not ScriptForge.SF_Utils._Validate(pvValue, "Title", V_STRING) Then GoTo Finally
|
||||
If oSession.HasUnoProperty(_ChartObject, "HasMainTitle") Then
|
||||
_ChartObject.HasMainTitle = ( Len(pvValue) > 0 )
|
||||
If Len(pvValue) > 0 Then _ChartObject.Title.String = pvValue
|
||||
End If
|
||||
Case UCase("XTitle")
|
||||
If Not ScriptForge.SF_Utils._Validate(pvValue, "XTitle", V_STRING) Then GoTo Finally
|
||||
If oSession.HasUnoProperty(_Diagram, "HasXAxisTitle") Then
|
||||
_Diagram.HasXAxisTitle = ( Len(pvValue) > 0 )
|
||||
If Len(pvValue) > 0 Then _Diagram.XAxisTitle.String = pvValue
|
||||
End If
|
||||
Case UCase("YTitle")
|
||||
If Not ScriptForge.SF_Utils._Validate(pvValue, "YTitle", V_STRING) Then GoTo Finally
|
||||
If oSession.HasUnoProperty(_Diagram, "HasYAxisTitle") Then
|
||||
_Diagram.HasYAxisTitle = ( Len(pvValue) > 0 )
|
||||
If Len(pvValue) > 0 Then _Diagram.YAxisTitle.String = pvValue
|
||||
End If
|
||||
Case Else
|
||||
bSet = False
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
_PropertySet = bSet
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
bSet = False
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_FormControl._PropertySet
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _Repr() As String
|
||||
''' Convert the Chart instance to a readable string, typically for debugging purposes (DebugPrint ...)
|
||||
''' Args:
|
||||
''' Return:
|
||||
''' "[Chart]: Name - Type
|
||||
|
||||
_Repr = "[Chart]: " & ChartName & " - " & ChartType
|
||||
|
||||
End Function ' SFDocuments.SF_Chart._Repr
|
||||
|
||||
REM ============================================ END OF SFDOCUMENTS.SF_CHART
|
||||
</script:module>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,114 @@
|
||||
<?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_DocumentListener" 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_DocumentListener
|
||||
''' ===================
|
||||
''' The current module is dedicated to the management of document events + listeners, triggered by user actions,
|
||||
''' which cannot be defined with the Basic IDE
|
||||
'''
|
||||
''' Concerned listeners:
|
||||
''' com.sun.star.sheet.XRangeSelectionListener
|
||||
''' allowing a user to select a cell range at any moment
|
||||
'''
|
||||
''' The described events/listeners are processed by UNO listeners
|
||||
'''
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================= DEFINITIONS
|
||||
|
||||
REM ============================================================= PRIVATE MEMBERS
|
||||
|
||||
Private _SelectedRange As String ' The selected range is returned by a "done" event
|
||||
Private _RangeSelectionFinished As Boolean ' Flag indicating that the interaction with the user has stopped
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
REM ============================================================== PUBLIC METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function RunRangeSelector(ByRef poComponent As Object _
|
||||
, ByRef pvPropertyValues As Variant _
|
||||
) As String
|
||||
''' Called from the SF_Calc.OpenRangeSelector() method
|
||||
''' Opens a non-modal dialog with a text box,
|
||||
''' let the user make a selection in the current or another sheet and
|
||||
''' returns the selected area as a string.
|
||||
|
||||
Dim oController As Object ' com.sun.star.frame.Controller
|
||||
Dim oListener As Object ' com.sun.star.sheet.XRangeSelectionListener
|
||||
Dim lCountLoops As Long ' Sleep cycles counter
|
||||
|
||||
Const cstListenerPrefix = "_SFRGSEL_" ' Prefix used for naming events Subs
|
||||
Const cstSleep = 50 ' Sleep steps in ms while waiting for the end of the interaction
|
||||
Const cstMaxSleep = (60 * 5 * 1000) / cstSleep ' Never sleep more than 5 minutes. Afterwards, processing continues
|
||||
|
||||
On Local Error GoTo Catch ' Avoid stopping event scripts
|
||||
|
||||
Try:
|
||||
' Create the listener
|
||||
Set oController = poComponent.CurrentController
|
||||
Set oListener = CreateUnoListener(cstListenerPrefix, "com.sun.star.sheet.XRangeSelectionListener")
|
||||
oController.addRangeSelectionListener(oListener)
|
||||
|
||||
' Open the selector
|
||||
_SelectedRange = ""
|
||||
_RangeSelectionFinished = False
|
||||
oController.startRangeSelection(pvPropertyValues)
|
||||
|
||||
' Dummy thread synchronization
|
||||
lCountLoops = 0
|
||||
Do While Not _RangeSelectionFinished And lCountLoops < cstMaxSleep
|
||||
Wait(cstSleep)
|
||||
lCountLoops = lCountLoops + 1
|
||||
Loop
|
||||
|
||||
Finally:
|
||||
If Not IsNull(oListener) Then oController.removeRangeSelectionListener(oListener)
|
||||
RunRangeSelector = _SelectedRange
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_DocumentListener.RunRangeSelector
|
||||
|
||||
REM ============================================================= PRIVATE METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Sub _SFRGSEL_done(Optional poEvent As Object) ' com.sun.star.sheet.RangeSelectionEvent
|
||||
|
||||
On Local Error GoTo Catch ' Avoid stopping event scripts
|
||||
|
||||
Try:
|
||||
_SelectedRange = poEvent.RangeDescriptor
|
||||
_RangeSelectionFinished = True
|
||||
|
||||
Finally:
|
||||
Exit Sub
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Sub
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Sub _SFRGSEL_aborted(Optional poEvent As Object) ' com.sun.star.sheet.RangeSelectionEvent
|
||||
|
||||
On Local Error GoTo Catch ' Avoid stopping event scripts
|
||||
|
||||
Try:
|
||||
_RangeSelectionFinished = True
|
||||
|
||||
Finally:
|
||||
Exit Sub
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Sub
|
||||
|
||||
REM ============================================ END OF SFDIALOGS.SF_DIALOGLISTENER
|
||||
</script:module>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,546 @@
|
||||
<?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 ================================================================= DEFINITIONS
|
||||
|
||||
''' Strategy for management of Form and FormControl events:
|
||||
''' ------------------------------------------------------
|
||||
''' At the contrary of Dialogs and DialogControls, which are always started from some code,
|
||||
''' Forms and FormControls will be initiated most often by the user, even if the SFDocuments library
|
||||
''' allows to start forms programmatically
|
||||
'''
|
||||
''' For Forms started programmatically, the corresponding objects are built top-down
|
||||
''' Event management of forms and their controls requires to being able to rebuild Form
|
||||
''' and FormControl objects bottom-up
|
||||
'''
|
||||
''' To avoid multiple rebuilds requested by multiple events,
|
||||
''' 1. The active form objects are cached in a global array of _FormCache types
|
||||
''' 2. FormControl objects are cached in Form objects
|
||||
''' 3. The bottom-up rebuild is executed only once, at instance creation
|
||||
|
||||
Type _FormCache
|
||||
Terminated As Boolean
|
||||
XUnoForm As Object
|
||||
BasicForm As Object
|
||||
End Type
|
||||
|
||||
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("Base", "SFDocuments.SF_Register._NewDocument") ' Same reference, distinction is made inside the function
|
||||
.RegisterService("Calc", "SFDocuments.SF_Register._NewDocument") ' Same reference, distinction is made inside the function
|
||||
.RegisterService("Writer", "SFDocuments.SF_Register._NewDocument") ' Same reference, distinction is made inside the function
|
||||
.RegisterEventManager("DocumentEvent", "SFDocuments.SF_Register._EventManager") ' Reference to the events manager
|
||||
.RegisterEventManager("FormEvent", "SFDocuments.SF_Register._FormEventManager")' Reference to the form and controls events manager
|
||||
End With
|
||||
|
||||
End Sub ' SFDocuments.SF_Register.RegisterScriptServices
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _AddFormToCache(ByRef pvUnoForm As Object _
|
||||
, ByRef pvBasicForm As Object _
|
||||
) As Long
|
||||
''' Add a new entry in the cache array with the references of the actual Form
|
||||
''' If relevant, the last entry of the cache is reused.
|
||||
''' The cache is located in the global _SF_ variable
|
||||
''' Args:
|
||||
''' pvUnoForm: com.sun.star.form.XForm or com.sun.star.comp.forms.ODatabaseForm
|
||||
''' pvBasicForm: its corresponding Basic object
|
||||
''' Returns:
|
||||
''' The index of the new or modified entry
|
||||
|
||||
Dim vCache As New _FormCache ' Entry to be added
|
||||
Dim lIndex As Long ' UBound of _SF_.SFForms
|
||||
Dim vCacheArray As Variant ' Alias of _SF_.SFForms
|
||||
|
||||
Try:
|
||||
vCacheArray = _SF_.SFForms
|
||||
|
||||
If IsEmpty(vCacheArray) Then vCacheArray = Array()
|
||||
lIndex = UBound(vCacheArray)
|
||||
If lIndex < LBound(vCacheArray) Then
|
||||
ReDim vCacheArray(0 To 0)
|
||||
lIndex = 0
|
||||
ElseIf Not vCacheArray(lIndex).Terminated Then ' Often last entry can be reused
|
||||
lIndex = lIndex + 1
|
||||
ReDim Preserve vCacheArray(0 To lIndex)
|
||||
End If
|
||||
|
||||
With vCache
|
||||
.Terminated = False
|
||||
Set .XUnoForm = pvUnoForm
|
||||
Set .BasicForm = pvBasicForm
|
||||
End With
|
||||
Set vCacheArray(lIndex) = vCache
|
||||
|
||||
_SF_.SFForms = vCacheArray
|
||||
|
||||
Finally:
|
||||
_AddFormToCache = lIndex
|
||||
Exit Function
|
||||
End Function ' SFDocuments.SF_Register._AddFormToCache
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub _CleanCacheEntry(ByVal plIndex As Long)
|
||||
''' Clean the plIndex-th entry in the Forms cache
|
||||
''' Args:
|
||||
''' plIndex: must fit within the actual boundaries of the cache, otherwise the request is ignored
|
||||
|
||||
Dim vCache As New _FormCache ' Cleaned entry
|
||||
|
||||
With _SF_
|
||||
If Not IsArray(.SFForms) Then Exit Sub
|
||||
If plIndex < LBound(.SFForms) Or plIndex > UBound(.SFForms) Then Exit Sub
|
||||
|
||||
With vCache
|
||||
.Terminated = True
|
||||
Set .XUnoForm = Nothing
|
||||
Set .BasicForm = Nothing
|
||||
End With
|
||||
.SFForms(plIndex) = vCache
|
||||
End With
|
||||
|
||||
Finally:
|
||||
Exit Sub
|
||||
End Sub ' SFDocuments.SF_Register._CleanCacheEntry
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _EventManager(Optional ByRef pvArgs As Variant) As Object
|
||||
''' Returns a Document, Calc or Base 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
|
||||
Set oSource = SF_Register._NewDocument(vEvent.Source)
|
||||
End If
|
||||
|
||||
Finally:
|
||||
Set _EventManager = oSource
|
||||
Exit Function
|
||||
End Function ' SFDocuments.SF_Register._EventManager
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _FindFormInCache(ByRef poForm As Object) As Object
|
||||
''' Find the Form based on its XUnoForm
|
||||
''' The Form must not be terminated
|
||||
''' Returns:
|
||||
''' The corresponding Basic Form part or Nothing
|
||||
|
||||
Dim oBasicForm As Object ' Return value
|
||||
Dim oCache As _FormCache ' Entry in the cache
|
||||
|
||||
Set oBasicForm = Nothing
|
||||
|
||||
Try:
|
||||
With _SF_
|
||||
If Not IsEmpty(.SFForms) Then
|
||||
For Each oCache In .SFForms
|
||||
If EqualUnoObjects(poForm, oCache.XUnoForm) And Not oCache.Terminated Then
|
||||
Set oBasicForm = oCache.BasicForm
|
||||
Exit For
|
||||
End If
|
||||
Next oCache
|
||||
End If
|
||||
End With
|
||||
|
||||
Finally:
|
||||
Set _FindFormInCache = oBasicForm
|
||||
Exit Function
|
||||
End Function ' SFDocuments.SF_Register._FindFormInCache
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _FormEventManager(Optional ByRef pvArgs As Variant) As Object
|
||||
''' Returns a Form or FormControl object corresponding with the form or control
|
||||
''' which triggered the event in argument
|
||||
''' This method should be triggered only thru the invocation of CreateScriptService
|
||||
''' Args:
|
||||
''' pvEvent: com.sun.star.lang.EventObject
|
||||
''' Returns:
|
||||
''' the output of a Form, FormControl service or Nothing
|
||||
''' Example:
|
||||
''' Sub TriggeredByEvent(ByRef poEvent As Object)
|
||||
''' Dim oForm As Object
|
||||
''' Set oForm = CreateScriptService("SFDocuments.FormEvent", poEvent)
|
||||
''' If Not IsNull(oForm) Then
|
||||
''' ' ... (a valid form or subform has been identified)
|
||||
''' End Sub
|
||||
|
||||
Dim oSource As Object ' Return value
|
||||
Dim vEvent As Variant ' Alias of pvArgs(0)
|
||||
Dim oControlModel As Object ' com.sun.star.awt.XControlModel
|
||||
Dim oParent As Object ' com.sun.star.form.OGridControlModel or com.sun.star.comp.forms.ODatabaseForm
|
||||
Dim sParentType As String ' "com.sun.star.form.OGridControlModel" or "com.sun.star.comp.forms.ODatabaseForm"
|
||||
Dim oSFParent As Object ' The parent as a ScriptForge instance: SF_Form or SF_FormControl
|
||||
Dim oSFForm As Object ' The grand-parent SF_Form instance
|
||||
Dim oSession As Object : Set oSession = ScriptForge.SF_Session
|
||||
|
||||
' 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 oSession.HasUnoProperty(vEvent, "Source") Then
|
||||
|
||||
' FORM EVENT
|
||||
If oSession.UnoObjectType(vEvent.Source) = "com.sun.star.comp.forms.ODatabaseForm" Then
|
||||
Set oSource = SF_Register._NewForm(vEvent.Source, pbForceInit := True)
|
||||
|
||||
' CONTROL EVENT
|
||||
Else
|
||||
' A SF_FormControl instance is always created from its parent, either a form, a subform or a table control
|
||||
Set oControlModel = vEvent.Source.Model ' The event source is a control view com.sun.star.awt.XControl
|
||||
Set oParent = oControlModel.Parent
|
||||
sParentType = oSession.UnoObjectType(oParent)
|
||||
Select Case sParentType
|
||||
Case "com.sun.star.form.OGridControlModel"
|
||||
Set oSFForm = SF_Register._NewForm(oParent.Parent, pbForceInit := True)
|
||||
Set oSFParent = oSFForm.Controls(oParent.Name)
|
||||
Case "com.sun.star.comp.forms.ODatabaseForm"
|
||||
Set oSFParent = SF_Register._NewForm(oParent, pbForceInit := True)
|
||||
End Select
|
||||
' The final instance is derived from its parent instance
|
||||
Set oSource = oSFParent.Controls(oControlModel.Name)
|
||||
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
Finally:
|
||||
Set _FormEventManager = oSource
|
||||
Exit Function
|
||||
End Function ' SFDocuments.SF_Register._FormEventManager
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _GetEventScriptCode(poObject As Object _
|
||||
, ByVal psEvent As String _
|
||||
, ByVal psName As String _
|
||||
) As String
|
||||
''' Extract from the parent of poObject the Basic script linked to psEvent.
|
||||
''' Helper function common to forms and form controls
|
||||
''' Args:
|
||||
''' poObject: a com.sun.star.form.XForm or XControl object
|
||||
''' psEvent: the "On..." name of the event
|
||||
''' psName: the name of the object to be identified from the parent object
|
||||
''' Returns:
|
||||
''' The script to trigger when psEvent occurs
|
||||
''' See Scripting Framework URI Specification : https://wiki.documentfoundation.org/Documentation/DevGuide/Scripting_Framework#Scripting_Framework_URI_Specification
|
||||
|
||||
Dim vEvents As Variant ' List of available events in the parent object
|
||||
' Array of com.sun.star.script.ScriptEventDescriptor
|
||||
Dim sEvent As String ' The targeted event name
|
||||
Dim oParent As Object ' The parent object
|
||||
Dim lIndex As Long ' The index of the targeted event in the events list of the parent object
|
||||
Dim sName As String ' The corrected UNO event name
|
||||
Dim i As Long
|
||||
|
||||
_GetEventScriptCode = ""
|
||||
On Local Error GoTo Catch
|
||||
If Not ScriptForge.SF_Session.HasUnoMethod(poObject, "getParent") Then GoTo Finally
|
||||
|
||||
Try:
|
||||
' Find form index i.e. find control via getByIndex()
|
||||
' The name is known (= psName) but getByIndex() is not in the same sequence as getElementNames()
|
||||
Set oParent = poObject.getParent()
|
||||
lIndex = -1
|
||||
For i = 0 To oParent.getCount() - 1
|
||||
sName = oParent.getByIndex(i).Name
|
||||
If (sName = psName) Then
|
||||
lIndex = i
|
||||
Exit For
|
||||
End If
|
||||
Next i
|
||||
If lIndex < 0 Then GoTo Finally ' Not found, should not happen
|
||||
|
||||
' Find script triggered by event
|
||||
vEvents = oParent.getScriptEvents(lIndex) ' Returns an array
|
||||
' Fix historical typo error
|
||||
sEvent = Replace(LCase(Mid(psEvent, 3, 1)) & Mid(psEvent, 4), "errorOccurred", "errorOccured")
|
||||
For i = 0 To UBound(vEvents)
|
||||
If vEvents(i).EventMethod = sEvent Then
|
||||
_GetEventScriptCode = vEvents(i).ScriptCode
|
||||
Exit For
|
||||
End If
|
||||
Next i
|
||||
|
||||
Finally:
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Register._GetEventScriptCode
|
||||
|
||||
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_Services.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
|
||||
Set oSuperDocument.[_SubClass] = oDocument
|
||||
Case "Calc"
|
||||
Set oDocument = New SF_Calc
|
||||
Set oSuperDocument = New SF_Document
|
||||
Set oDocument.[_Super] = oSuperDocument ' Now both super and subclass are twinned
|
||||
Set oSuperDocument.[_SubClass] = oDocument
|
||||
Case "Writer"
|
||||
Set oDocument = New SF_Writer
|
||||
Set oSuperDocument = New SF_Document
|
||||
Set oDocument.[_Super] = oSuperDocument ' Now both super and subclass are twinned
|
||||
Set oSuperDocument.[_SubClass] = oDocument
|
||||
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 -----------------------------------------------------------------------------
|
||||
Public Function _NewForm(ByRef poForm As Object _
|
||||
, Optional pbForceInit As Boolean _
|
||||
) As Object
|
||||
''' Returns an existing or a new SF_Form instance based on the argument
|
||||
''' If the instance is new (not found in cache), the minimal members are initialized
|
||||
''' Args:
|
||||
''' poForm: com.sun.star.form.XForm or com.sun.star.comp.forms.ODatabaseForm
|
||||
''' pbForceInit: when True, initialize the form instance. Default = False
|
||||
''' Returns:
|
||||
''' A SF_Form instance
|
||||
|
||||
Dim oForm As Object ' Return value
|
||||
|
||||
Try:
|
||||
Set oForm = SF_Register._FindFormInCache(poForm)
|
||||
If IsNull(oForm) Then ' Not found
|
||||
If IsMissing(pbForceInit) Or IsEmpty(pbForceInit) Then pbForceInit = False
|
||||
Set oForm = New SF_Form
|
||||
With oForm
|
||||
._Name = poForm.Name
|
||||
Set .[Me] = oForm
|
||||
Set ._Form = poForm
|
||||
If pbForceInit Then ._Initialize()
|
||||
End With
|
||||
End If
|
||||
|
||||
Finally:
|
||||
Set _NewForm = oForm
|
||||
Exit Function
|
||||
End Function ' SFDocuments.SF_Register._NewForm
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function _RegisterEventScript(poObject As Object _
|
||||
, ByVal psEvent As String _
|
||||
, ByVal psListener As String _
|
||||
, ByVal psScriptCode As String _
|
||||
, ByVal psName As String _
|
||||
) As Boolean
|
||||
''' Register a script event (psEvent) to poObject (Form, SubForm or Control)
|
||||
''' Args:
|
||||
''' poObject: a com.sun.star.form.XForm or XControl object
|
||||
''' psEvent: the "On..." name of the event
|
||||
''' psListener: the listener name corresponding with the event
|
||||
''' psScriptCode: The script to trigger when psEvent occurs
|
||||
''' See Scripting Framework URI Specification : https://wiki.documentfoundation.org/Documentation/DevGuide/Scripting_Framework#Scripting_Framework_URI_Specification
|
||||
''' psName: the name of the object to associate with the event
|
||||
''' Returns:
|
||||
''' True when successful
|
||||
|
||||
Dim oEvent As Object ' com.sun.star.script.ScriptEventDescriptor
|
||||
Dim sEvent As String ' The targeted event name
|
||||
Dim oParent As Object ' The parent object
|
||||
Dim lIndex As Long ' The index of the targeted event in the events list of the parent object
|
||||
Dim sName As String ' The corrected UNO event name
|
||||
Dim i As Long
|
||||
|
||||
_RegisterEventScript = False
|
||||
On Local Error GoTo Catch
|
||||
If Not ScriptForge.SF_Session.HasUnoMethod(poObject, "getParent") Then GoTo Finally
|
||||
|
||||
Try:
|
||||
' Find object's internal index i.e. how to reach it via getByIndex()
|
||||
Set oParent = poObject.getParent()
|
||||
lIndex = -1
|
||||
For i = 0 To oParent.getCount() - 1
|
||||
sName = oParent.getByIndex(i).Name
|
||||
If (sName = psName) Then
|
||||
lIndex = i
|
||||
Exit For
|
||||
End If
|
||||
Next i
|
||||
If lIndex < 0 Then GoTo Finally ' Not found, should not happen
|
||||
|
||||
' Fix historical typo error
|
||||
sEvent = Replace(LCase(Mid(psEvent, 3, 1)) & Mid(psEvent, 4), "errorOccurred", "errorOccured")
|
||||
' Apply new script code. Erasing it is done with a specific UNO method
|
||||
If psScriptCode = "" Then
|
||||
oParent.revokeScriptEvent(lIndex, psListener, sEvent, "")
|
||||
Else
|
||||
Set oEvent = CreateUnoStruct("com.sun.star.script.ScriptEventDescriptor")
|
||||
With oEvent
|
||||
.ListenerType = psListener
|
||||
.EventMethod = sEvent
|
||||
.ScriptType = "Script" ' Better than "Basic"
|
||||
.ScriptCode = psScriptCode
|
||||
End With
|
||||
oParent.registerScriptEvent(lIndex, oEvent)
|
||||
End If
|
||||
_RegisterEventScript = True
|
||||
|
||||
Finally:
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Register._RegisterEventScript
|
||||
|
||||
REM ============================================== END OF SFDOCUMENTS.SF_REGISTER
|
||||
</script:module>
|
||||
@@ -0,0 +1,635 @@
|
||||
<?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_Writer" 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_Writer
|
||||
''' =========
|
||||
'''
|
||||
''' The SFDocuments library gathers a number of methods and properties making easy
|
||||
''' managing and manipulating 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, SF_Base, ...
|
||||
'''
|
||||
''' 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_Writer module is focused on :
|
||||
''' TBD
|
||||
'''
|
||||
''' 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.CreateDocument("Writer", ...)
|
||||
''' ' or Set oDoc = ui.OpenDocument("C:\Me\MyFile.odt")
|
||||
''' 2) Directly if the document is already opened
|
||||
''' Dim oDoc As Object
|
||||
''' Set oDoc = CreateScriptService("SFDocuments.Writer", "Untitled 1") ' Default = ActiveWindow
|
||||
''' ' or Set oDoc = CreateScriptService("SFDocuments.Writer", "Untitled 1") ' Untitled 1 is presumed a Writer document
|
||||
''' ' The substring "SFDocuments." in the service name is optional
|
||||
'''
|
||||
''' Definitions:
|
||||
''' TBD
|
||||
'''
|
||||
''' Detailed user documentation:
|
||||
''' https://help.libreoffice.org/latest/en-US/text/sbasic/shared/03/SF_Writer.html?DbPAR=BASIC
|
||||
'''
|
||||
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
REM ================================================================== EXCEPTIONS
|
||||
|
||||
Private Const WRITERFORMNOTFOUNDERROR = "WRITERFORMNOTFOUNDERROR"
|
||||
|
||||
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 WRITER
|
||||
Private ServiceName As String
|
||||
|
||||
' Window component
|
||||
Private _Component As Object ' com.sun.star.lang.XComponent
|
||||
|
||||
REM ============================================================ MODULE CONSTANTS
|
||||
|
||||
REM ====================================================== CONSTRUCTOR/DESTRUCTOR
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Initialize()
|
||||
Set [Me] = Nothing
|
||||
Set [_Parent] = Nothing
|
||||
Set [_Super] = Nothing
|
||||
ObjectType = "WRITER"
|
||||
ServiceName = "SFDocuments.Writer"
|
||||
Set _Component = Nothing
|
||||
End Sub ' SFDocuments.SF_Writer Constructor
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Sub Class_Terminate()
|
||||
Call Class_Initialize()
|
||||
End Sub ' SFDocuments.SF_Writer 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_Writer Explicit Destructor
|
||||
|
||||
REM ================================================================== PROPERTIES
|
||||
|
||||
REM ===================================================================== METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Forms(Optional ByVal Form As Variant) As Variant
|
||||
''' Return either
|
||||
''' - the list of the Forms contained in the form document
|
||||
''' - a SFDocuments.Form object based on its name or its index
|
||||
''' Args:
|
||||
''' Form: a form stored in the document given by its name or its index
|
||||
''' When absent, the list of available forms is returned
|
||||
''' To get the first (unique ?) form stored in the form document, set Form = 0
|
||||
''' Exceptions:
|
||||
''' WRITERFORMNOTFOUNDERROR Form not found
|
||||
''' Returns:
|
||||
''' A zero-based array of strings if Form is absent
|
||||
''' An instance of the SF_Form class if Form exists
|
||||
''' Example:
|
||||
''' Dim myForm As Object, myList As Variant
|
||||
''' myList = oDoc.Forms()
|
||||
''' Set myForm = oDoc.Forms("myForm")
|
||||
|
||||
Dim oForm As Object ' The new Form class instance
|
||||
Dim oMainForm As Object ' com.sun.star.comp.sdb.Content
|
||||
Dim oXForm As Object ' com.sun.star.form.XForm
|
||||
Dim vFormNames As Variant ' Array of form names
|
||||
Dim oForms As Object ' Forms collection
|
||||
Const cstDrawPage = 0 ' Only 1 drawpage in a Writer document
|
||||
|
||||
Const cstThisSub = "SFDocuments.Writer.Forms"
|
||||
Const cstSubArgs = "[Form=""""]"
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
|
||||
Check:
|
||||
If IsMissing(Form) Or IsEmpty(Form) Then Form = ""
|
||||
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not _IsStillAlive() Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(Form, "Form", Array(V_STRING, ScriptForge.V_NUMERIC)) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
' Start from the document component and go down to forms
|
||||
Set oForms = _Component.DrawPages(cstDrawPage).Forms
|
||||
vFormNames = oForms.getElementNames()
|
||||
|
||||
If Len(Form) = 0 Then ' Return the list of valid form names
|
||||
Forms = vFormNames
|
||||
Else
|
||||
If VarType(Form) = V_STRING Then ' Find the form by name
|
||||
If Not ScriptForge.SF_Array.Contains(vFormNames, Form, CaseSensitive := True) Then GoTo CatchNotFound
|
||||
Set oXForm = oForms.getByName(Form)
|
||||
Else ' Find the form by index
|
||||
If Form < 0 Or Form >= oForms.Count Then GoTo CatchNotFound
|
||||
Set oXForm = oForms.getByIndex(Form)
|
||||
End If
|
||||
' Create the new Form class instance
|
||||
Set oForm = SF_Register._NewForm(oXForm)
|
||||
With oForm
|
||||
Set .[_Parent] = [Me]
|
||||
._FormType = ISDOCFORM
|
||||
Set ._Component = _Component
|
||||
._Initialize()
|
||||
End With
|
||||
Set Forms = oForm
|
||||
End If
|
||||
|
||||
Finally:
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
CatchNotFound:
|
||||
ScriptForge.SF_Exception.RaiseFatal(WRITERFORMNOTFOUNDERROR, Form, _FileIdent())
|
||||
End Function ' SFDocuments.SF_Writer.Forms
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function GetProperty(Optional ByVal PropertyName As Variant _
|
||||
, Optional ObjectName As Variant _
|
||||
) As Variant
|
||||
''' Return the actual value of the given property
|
||||
''' Args:
|
||||
''' PropertyName: the name of the property as a string
|
||||
''' ObjectName: a sheet or range name
|
||||
''' Returns:
|
||||
''' The actual value of the property
|
||||
''' Exceptions:
|
||||
''' ARGUMENTERROR The property does not exist
|
||||
|
||||
Const cstThisSub = "SFDocuments.Writer.GetProperty"
|
||||
Const cstSubArgs = ""
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
GetProperty = Null
|
||||
|
||||
Check:
|
||||
If IsMissing(ObjectName) Or IsEmpty(ObjectName) Then ObjectName = ""
|
||||
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not ScriptForge.SF_Utils._Validate(PropertyName, "PropertyName", V_STRING, Properties()) Then GoTo Catch
|
||||
If Not ScriptForge.SF_Utils._Validate(ObjectName, "ObjectName", V_STRING) Then GoTo Catch
|
||||
End If
|
||||
|
||||
Try:
|
||||
' Superclass or subclass property ?
|
||||
If ScriptForge.SF_Array.Contains([_Super].Properties(), PropertyName) Then
|
||||
GetProperty = [_Super].GetProperty(PropertyName)
|
||||
ElseIf Len(ObjectName) = 0 Then
|
||||
GetProperty = _PropertyGet(PropertyName)
|
||||
Else
|
||||
GetProperty = _PropertyGet(PropertyName, ObjectName)
|
||||
End If
|
||||
|
||||
Finally:
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Writer.GetProperty
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Methods() As Variant
|
||||
''' Return the list of public methods of the Writer service as an array
|
||||
|
||||
Methods = Array( _
|
||||
"Forms" _
|
||||
, "PrintOut" _
|
||||
)
|
||||
|
||||
End Function ' SFDocuments.SF_Writer.Methods
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function PrintOut(Optional ByVal Pages As Variant _
|
||||
, Optional ByVal Copies As Variant _
|
||||
, Optional ByVal PrintBackground As Variant _
|
||||
, Optional ByVal PrintBlankPages As Variant _
|
||||
, Optional ByVal PrintEvenPages As Variant _
|
||||
, Optional ByVal PrintOddPages As Variant _
|
||||
, Optional ByVal PrintImages As Variant _
|
||||
) As Boolean
|
||||
''' Send the content of the document to the printer.
|
||||
''' The printer might be defined previously by default, by the user or by the SetPrinter() method
|
||||
''' Args:
|
||||
''' Pages: the pages to print as a string, like in the user interface. Example: "1-4;10;15-18". Default = all pages
|
||||
''' Copies: the number of copies
|
||||
''' PrintBackground: print the background image when True (default)
|
||||
''' PrintBlankPages: when False (default), omit empty pages
|
||||
''' PrintEvenPages: print the left pages when True (default)
|
||||
''' PrintOddPages: print the right pages when True (default)
|
||||
''' PrintImages: print the graphic objects when True (default)
|
||||
''' Returns:
|
||||
''' True when successful
|
||||
''' Examples:
|
||||
''' oDoc.PrintOut("1-4;10;15-18", Copies := 2, PrintImages := False)
|
||||
|
||||
Dim bPrint As Boolean ' Return value
|
||||
Dim vPrintOptions As Variant ' com.sun.star.text.DocumentSettings
|
||||
|
||||
Const cstThisSub = "SFDocuments.Writer.PrintOut"
|
||||
Const cstSubArgs = "[Pages=""""], [Copies=1], [PrintBackground=True], [PrintBlankPages=False], [PrintEvenPages=True]" _
|
||||
& ", [PrintOddPages=True], [PrintImages=True]"
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bPrint = False
|
||||
|
||||
Check:
|
||||
If IsMissing(Pages) Or IsEmpty(Pages) Then Pages = ""
|
||||
If IsMissing(Copies) Or IsEmpty(Copies) Then Copies = 1
|
||||
If IsMissing(PrintBackground) Or IsEmpty(PrintBackground) Then PrintBackground = True
|
||||
If IsMissing(PrintBlankPages) Or IsEmpty(PrintBlankPages) Then PrintBlankPages = False
|
||||
If IsMissing(PrintEvenPages) Or IsEmpty(PrintEvenPages) Then PrintEvenPages = True
|
||||
If IsMissing(PrintOddPages) Or IsEmpty(PrintOddPages) Then PrintOddPages = True
|
||||
If IsMissing(PrintImages) Or IsEmpty(PrintImages) Then PrintImages = True
|
||||
|
||||
If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
|
||||
If Not _IsStillAlive() Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(Pages, "Pages", V_STRING) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(Copies, "Copies", ScriptForge.V_NUMERIC) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(PrintBackground, "PrintBackground", ScriptForge.V_BOOLEAN) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(PrintBlankPages, "PrintBlankPages", ScriptForge.V_BOOLEAN) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(PrintEvenPages, "PrintEvenPages", ScriptForge.V_BOOLEAN) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(PrintOddPages, "PrintOddPages", ScriptForge.V_BOOLEAN) Then GoTo Finally
|
||||
If Not ScriptForge.SF_Utils._Validate(PrintImages, "PrintImages", ScriptForge.V_BOOLEAN) Then GoTo Finally
|
||||
End If
|
||||
|
||||
Try:
|
||||
vPrintOptions = _Component.createInstance("com.sun.star.text.DocumentSettings")
|
||||
With vPrintOptions
|
||||
.PrintPageBackground = PrintBackground
|
||||
.PrintEmptyPages = PrintBlankPages
|
||||
.PrintLeftPages = PrintEvenPages
|
||||
.PrintRightPages = PrintOddPages
|
||||
.PrintGraphics = PrintImages
|
||||
.PrintDrawings = PrintImages
|
||||
End With
|
||||
|
||||
bPrint = [_Super].PrintOut(Pages, Copies, _Component)
|
||||
|
||||
Finally:
|
||||
PrintOut = bPrint
|
||||
ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Writer.PrintOut
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Properties() As Variant
|
||||
''' Return the list or properties of the Writer class as an array
|
||||
|
||||
Properties = Array( _
|
||||
"CustomProperties" _
|
||||
, "Description" _
|
||||
, "DocumentProperties" _
|
||||
, "DocumentType" _
|
||||
, "ExportFilters" _
|
||||
, "ImportFilters" _
|
||||
, "IsBase" _
|
||||
, "IsCalc" _
|
||||
, "IsDraw" _
|
||||
, "IsImpress" _
|
||||
, "IsMath" _
|
||||
, "IsWriter" _
|
||||
, "Keywords" _
|
||||
, "Readonly" _
|
||||
, "Subject" _
|
||||
, "Title" _
|
||||
, "XComponent" _
|
||||
)
|
||||
|
||||
End Function ' SFDocuments.SF_Writer.Properties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function SetProperty(Optional ByVal psProperty As String _
|
||||
, Optional ByVal pvValue As Variant _
|
||||
) As Boolean
|
||||
''' Set the new value of the named property
|
||||
''' Args:
|
||||
''' psProperty: the name of the property
|
||||
''' pvValue: the new value of the given property
|
||||
''' Returns:
|
||||
''' True if successful
|
||||
|
||||
Dim bSet As Boolean ' Return value
|
||||
Static oSession As Object ' Alias of SF_Session
|
||||
Dim cstThisSub As String
|
||||
Const cstSubArgs = "Value"
|
||||
|
||||
If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
|
||||
bSet = False
|
||||
|
||||
cstThisSub = "SFDocuments.Writer.set" & psProperty
|
||||
If IsMissing(pvValue) Then pvValue = Empty
|
||||
'ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) ' Validation done in Property Lets
|
||||
|
||||
If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService("Session")
|
||||
bSet = True
|
||||
Select Case UCase(psProperty)
|
||||
Case UCase("CustomProperties")
|
||||
CustomProperties = pvValue
|
||||
Case UCase("Description")
|
||||
Description = pvValue
|
||||
Case UCase("Keywords")
|
||||
Keywords = pvValue
|
||||
Case UCase("Subject")
|
||||
Subject = pvValue
|
||||
Case UCase("Title")
|
||||
Title = pvValue
|
||||
Case Else
|
||||
bSet = False
|
||||
End Select
|
||||
|
||||
Finally:
|
||||
SetProperty = bSet
|
||||
'ScriptForge.SF_Utils._ExitFunction(cstThisSub)
|
||||
Exit Function
|
||||
Catch:
|
||||
GoTo Finally
|
||||
End Function ' SFDocuments.SF_Writer.SetProperty
|
||||
|
||||
REM ======================================================= SUPERCLASS PROPERTIES
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get CustomProperties() As Variant
|
||||
CustomProperties = [_Super].GetProperty("CustomProperties")
|
||||
End Property ' SFDocuments.SF_Writer.CustomProperties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let CustomProperties(Optional ByVal pvCustomProperties As Variant)
|
||||
[_Super].CustomProperties = pvCustomProperties
|
||||
End Property ' SFDocuments.SF_Writer.CustomProperties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Description() As Variant
|
||||
Description = [_Super].GetProperty("Description")
|
||||
End Property ' SFDocuments.SF_Writer.Description
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Description(Optional ByVal pvDescription As Variant)
|
||||
[_Super].Description = pvDescription
|
||||
End Property ' SFDocuments.SF_Writer.Description
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get DocumentProperties() As Variant
|
||||
DocumentProperties = [_Super].GetProperty("DocumentProperties")
|
||||
End Property ' SFDocuments.SF_Writer.DocumentProperties
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get DocumentType() As String
|
||||
DocumentType = [_Super].GetProperty("DocumentType")
|
||||
End Property ' SFDocuments.SF_Writer.DocumentType
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get ExportFilters() As Variant
|
||||
ExportFilters = [_Super].GetProperty("ExportFilters")
|
||||
End Property ' SFDocuments.SF_Writer.ExportFilters
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get ImportFilters() As Variant
|
||||
ImportFilters = [_Super].GetProperty("ImportFilters")
|
||||
End Property ' SFDocuments.SF_Writer.ImportFilters
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsBase() As Boolean
|
||||
IsBase = [_Super].GetProperty("IsBase")
|
||||
End Property ' SFDocuments.SF_Writer.IsBase
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsCalc() As Boolean
|
||||
IsCalc = [_Super].GetProperty("IsCalc")
|
||||
End Property ' SFDocuments.SF_Writer.IsCalc
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsDraw() As Boolean
|
||||
IsDraw = [_Super].GetProperty("IsDraw")
|
||||
End Property ' SFDocuments.SF_Writer.IsDraw
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsImpress() As Boolean
|
||||
IsImpress = [_Super].GetProperty("IsImpress")
|
||||
End Property ' SFDocuments.SF_Writer.IsImpress
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsMath() As Boolean
|
||||
IsMath = [_Super].GetProperty("IsMath")
|
||||
End Property ' SFDocuments.SF_Writer.IsMath
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get IsWriter() As Boolean
|
||||
IsWriter = [_Super].GetProperty("IsWriter")
|
||||
End Property ' SFDocuments.SF_Writer.IsWriter
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Keywords() As Variant
|
||||
Keywords = [_Super].GetProperty("Keywords")
|
||||
End Property ' SFDocuments.SF_Writer.Keywords
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Keywords(Optional ByVal pvKeywords As Variant)
|
||||
[_Super].Keywords = pvKeywords
|
||||
End Property ' SFDocuments.SF_Writer.Keywords
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Readonly() As Variant
|
||||
Readonly = [_Super].GetProperty("Readonly")
|
||||
End Property ' SFDocuments.SF_Writer.Readonly
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Subject() As Variant
|
||||
Subject = [_Super].GetProperty("Subject")
|
||||
End Property ' SFDocuments.SF_Writer.Subject
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Subject(Optional ByVal pvSubject As Variant)
|
||||
[_Super].Subject = pvSubject
|
||||
End Property ' SFDocuments.SF_Writer.Subject
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get Title() As Variant
|
||||
Title = [_Super].GetProperty("Title")
|
||||
End Property ' SFDocuments.SF_Writer.Title
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Let Title(Optional ByVal pvTitle As Variant)
|
||||
[_Super].Title = pvTitle
|
||||
End Property ' SFDocuments.SF_Writer.Title
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Property Get XComponent() As Variant
|
||||
XComponent = [_Super].GetProperty("XComponent")
|
||||
End Property ' SFDocuments.SF_Writer.XComponent
|
||||
|
||||
REM ========================================================== SUPERCLASS METHODS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Activate() As Boolean
|
||||
Activate = [_Super].Activate()
|
||||
End Function ' SFDocuments.SF_Writer.Activate
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function CloseDocument(Optional ByVal SaveAsk As Variant) As Boolean
|
||||
CloseDocument = [_Super].CloseDocument(SaveAsk)
|
||||
End Function ' SFDocuments.SF_Writer.CloseDocument
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function CreateMenu(Optional ByVal MenuHeader As Variant _
|
||||
, Optional ByVal Before As Variant _
|
||||
, Optional ByVal SubmenuChar As Variant _
|
||||
) As Object
|
||||
Set CreateMenu = [_Super].CreateMenu(MenuHeader, Before, SubmenuChar)
|
||||
End Function ' SFDocuments.SF_Writer.CreateMenu
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function ExportAsPDF(Optional ByVal FileName As Variant _
|
||||
, Optional ByVal Overwrite As Variant _
|
||||
, Optional ByVal Pages As Variant _
|
||||
, Optional ByVal Password As Variant _
|
||||
, Optional ByVal Watermark As Variant _
|
||||
) As Boolean
|
||||
ExportAsPDF = [_Super].ExportAsPDF(FileName, Overwrite, Pages, Password, Watermark)
|
||||
End Function ' SFDocuments.SF_Writer.ExportAsPDF
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function RemoveMenu(Optional ByVal MenuHeader As Variant) As Boolean
|
||||
RemoveMenu = [_Super].RemoveMenu(MenuHeader)
|
||||
End Function ' SFDocuments.SF_Writer.RemoveMenu
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Sub RunCommand(Optional ByVal Command As Variant _
|
||||
, ParamArray Args As Variant _
|
||||
)
|
||||
[_Super].RunCommand(Command, Args)
|
||||
End Sub ' SFDocuments.SF_Writer.RunCommand
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function Save() As Boolean
|
||||
Save = [_Super].Save()
|
||||
End Function ' SFDocuments.SF_Writer.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_Writer.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_Writer.SaveCopyAs
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Public Function SetPrinter(Optional ByVal Printer As Variant _
|
||||
, Optional ByVal Orientation As Variant _
|
||||
, Optional ByVal PaperFormat As Variant _
|
||||
) As Boolean
|
||||
SetPrinter = [_Super].SetPrinter(Printer, Orientation, PaperFormat)
|
||||
End Function ' SFDocuments.SF_Writer.SetPrinter
|
||||
|
||||
REM =========================================================== PRIVATE FUNCTIONS
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _FileIdent() As String
|
||||
''' Returns a file identification from the information that is currently available
|
||||
''' Useful e.g. for display in error messages
|
||||
|
||||
_FileIdent = [_Super]._FileIdent()
|
||||
|
||||
End Function ' SFDocuments.SF_Writer._FileIdent
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _IsStillAlive(Optional ByVal pbForUpdate As Boolean _
|
||||
, Optional ByVal pbError As Boolean _
|
||||
) As Boolean
|
||||
''' Returns True if the document has not been closed manually or incidentally since the last use
|
||||
''' If dead the actual instance is disposed. The execution is cancelled when pbError = True (default)
|
||||
''' Args:
|
||||
''' pbForUpdate: if True (default = False), check additionally if document is open for editing
|
||||
''' pbError: if True (default), raise a fatal error
|
||||
|
||||
Dim bAlive As Boolean ' Return value
|
||||
|
||||
If IsMissing(pbForUpdate) Then pbForUpdate = False
|
||||
If IsMissing(pbError) Then pbError = True
|
||||
|
||||
Try:
|
||||
bAlive = [_Super]._IsStillAlive(pbForUpdate, pbError)
|
||||
|
||||
Finally:
|
||||
_IsStillAlive = bAlive
|
||||
Exit Function
|
||||
End Function ' SFDocuments.SF_Writer._IsStillAlive
|
||||
|
||||
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 cstThisSub As String
|
||||
Const cstSubArgs = ""
|
||||
|
||||
_PropertyGet = False
|
||||
|
||||
cstThisSub = "SFDocuments.Writer.get" & psProperty
|
||||
ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
|
||||
If Not _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_Writer._PropertyGet
|
||||
|
||||
REM -----------------------------------------------------------------------------
|
||||
Private Function _Repr() As String
|
||||
''' Convert the SF_Writer instance to a readable string, typically for debugging purposes (DebugPrint ...)
|
||||
''' Args:
|
||||
''' Return:
|
||||
''' "[DOCUMENT]: Type/File"
|
||||
|
||||
_Repr = "[Writer]: " & [_Super]._FileIdent()
|
||||
|
||||
End Function ' SFDocuments.SF_Writer._Repr
|
||||
|
||||
REM ============================================ END OF SFDOCUMENTS.SF_WRITER
|
||||
</script:module>
|
||||
@@ -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-2022 Jean-Pierre LEDURE, Rafael LIMA, 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>
|
||||
@@ -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"/>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?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:element library:name="SF_Form"/>
|
||||
<library:element library:name="SF_FormControl"/>
|
||||
<library:element library:name="SF_Writer"/>
|
||||
<library:element library:name="SF_Chart"/>
|
||||
<library:element library:name="SF_DocumentListener"/>
|
||||
</library:library>
|
||||
Reference in New Issue
Block a user