Subversion

HaExcel

?curdirlinks? - Rev 236

?prevdifflink? - Blame


<?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="Properties" script:language="StarBasic">REM  *****  BASIC  *****

Option Explicit

&apos;
&apos; TODO
&apos;  - check if the added expansion is valid
&apos;

&apos; *****************************************************************************

REM Gets document object properties
Function GetUserProperties (oDoc As Object) As Object
  GetUserProperties = oDoc.DocumentProperties.UserDefinedProperties
End Function


&apos; *****************************************************************************
&apos; *** CLASSES *****************************************************************
&apos; *****************************************************************************

&apos; *** Property name: ClassSheet
&apos; *** Format:
&apos; *** - List = ClassSheet
&apos; *** -      | ClassSheet &apos;;&apos; List
&apos; *** - ClassSheet = name &apos;,&apos; range &apos;,&apos; depth &apos;,&apos; color
&apos; *** note: the order of the items consists of a depth-first traversal

&apos; FIXME remove Global
Global Const PropertyClasses = &quot;ClassSheet&quot;

&apos; *****************************************************************************
&apos; *** EXPANSIONS **************************************************************
&apos; *****************************************************************************

&apos; *** Property name: ClassSheetExp
&apos; *** Format:
&apos; *** - List = Expansion
&apos; *** -      | Expansion &apos;;&apos; List
&apos; *** - Expansion = classname &apos;,&apos; range &apos;,&apos; Type
&apos; *** - Type = 0   // expand columns
&apos; *** -      | n   // expand rows, where n &gt;= 1, and is unique for each class
&apos; *** note: the list is ordered by classname and then by expansion type

Const PropertyExpansions = &quot;ClassSheetExp&quot;

REM Adds an expansion to the list
Function AddExpansion (oDoc As Object, class As String, oRange As Object, expType As Integer) As String
  Dim exp As String
  Dim expansions As Object
  Dim newList(0) As String
  Dim pos As Integer
  Dim newExp As String : newExp = &quot;&quot;
  
  expansions = Split( GetUserProperties( oDoc ), &quot;;&quot; )
  
  If LBound( expansions ) &lt;= UBound( expansions ) Then
    ReDim newList(UBound(expansions) + 1) As String
  End If
  
  &apos; try to insert the expansion in the list
  For i = LBound( expansions ) To UBound( expansions )
        exp = expansions(i)
        
        If class = GetExpansionName( exp ) And expType = GetExpansionType( expType ) Then
          AddExpansion = &quot;&quot;
          Exit Function
        End If
        
    If class &lt; GetExpansionName( exp ) Then
          &apos; insert here
          newExp = class &amp; &quot;,&quot; &amp; HaExcel.RangeToString( oDoc, oRange ) &amp; &quot;,&quot; &amp; expType
          newList(i) = newExp
          pos = i
          Exit For
    End If
        
    newList(i) = expansions(i)
  Next i
  
  &apos; add to the end of the list if it was not inserted
  If newExp = &quot;&quot; Then
    newExp
    newList( pos ) = class &amp; &quot;,&quot; &amp; HaExcel.RangeToString( oDoc, oRange ) &amp; &quot;,&quot; &amp; expType
    pos = pos + 1
  Else
    &apos; copy the rest to the list
    For i = pos To UBound( expansions )
      newList(i+1) = expansions(i)
    Next i
  End If
  
  AddExpansion = join(newList, &quot;;&quot;)
End Function

&apos; *****************************************************************************

REM Gets the expansions from the list
Function GetExpansions (oDoc As Object) As Object
  Dim oUserProperties, exps As Object
  Dim strExps As String
  
  oUserProperties = GetUserProperties( oDoc )
  
  strExps = oUserProperties.getPropertyValue( PropertyExpansions )
  
  exps = Split( strExps, &quot;;&quot; )
  
  GetExpansions = exps
End Function

&apos; *****************************************************************************

REM Gets data of expansion from the list
Function GetExpansion (class As String, expType As Integer) As String
  Dim expansions As Object
  
  expansions = Split( GetUserProperties( oDoc ), &quot;;&quot; )
  
  For i = LBound( expansions ) To UBound( expansions )
    c = GetExpansionName( expansions(i) )
    t = GetExpansionType( expansions(i) )
    If c = class And t = expType Then
      GetExpansion = expansions(i)
      Exit Function
    End If
  Next i
  
  GetExpansion = &quot;&quot;
End Function

&apos; *****************************************************************************

REM Gets the name of the given expansion
Function GetExpansionName (expansion As String) As String
  Dim values As Object
  values = Split( expansion, &quot;,&quot; )
  GetExpansionName = values(0)
End Function

&apos; *****************************************************************************

REM Gets the range (as string) of the given expansion
Function GetExpansionRangeName (expansion As String) As String
  Dim values As Object
  values = Split( expansion, &quot;,&quot; )
  GetExpansionRangeName = values(1)
End Function

&apos; *****************************************************************************

REM Gets the type of the given expansion
Function GetExpansionType (expansion As String) As Integer
  Dim values As Object
  values = Split( expansion, &quot;,&quot; )
  GetExpansionType = CInt( values(2) )
End Function

</script:module>

Generated by GNU Enscript 1.6.5.90.

Theme by Vikram Singh | Powered by WebSVN v2.3.3