TabulatorSpecification.st
author claus
Wed, 24 Aug 1994 01:44:22 +0200
changeset 19 79ab6bc98651
child 25 e07adf47d209
permissions -rw-r--r--
Initial revision

'From Smalltalk/X, Version:2.10.3 on 12-aug-1994 at 10:44:09 pm'!

Object subclass:#TabulatorSpecification
	 instanceVariableNames:'tabUnit tabPositions tabTypes'
	 classVariableNames:''
	 poolDictionaries:''
	 category:'Views-Support'
!

!TabulatorSpecification methodsFor:'queries'!

pixelsPerUnitOn:aGC
    "
     return the number of device pixels one unit of my tabs
     takes on aGC
    "
    tabUnit isNil ifTrue:[
        tabUnit := #col
    ].
    tabUnit == #col ifTrue:[
        ^ aGC font width
    ].
    tabUnit == #inch ifTrue:[
        ^ aGC device horizontalPixelPerInch
    ].
    tabUnit == #mm ifTrue:[
        ^ aGC device horizontalPixelPerMillimeter
    ].
    tabUnit == #cm ifTrue:[
        ^ aGC device horizontalPixelPerMillimeter * 10
    ].
    "
     assume pixels
    "
    ^ 1.
!

positionOfTab:index on:aGC
    |unit pos|

    tabPositions isNil ifTrue:[^ nil].

    unit := self pixelsPerUnitOn:aGC.
    pos := ((tabPositions at:index) * unit).
    ^ pos
!

positionOfTab:index forString:aString on:aGC
    |pos type idx left|

    pos := self positionOfTab:index on:aGC.
    pos isNil ifTrue:[^ nil].

    tabTypes notNil ifTrue:[
        (tabTypes isMemberOf:Symbol) ifTrue:[
            type := tabTypes
        ] ifFalse:[
            type := tabTypes at:(index).
        ].
    ] ifFalse:[
        type := #left
    ].

    type == #right ifTrue:[
        ^ pos - (aGC font widthOf:aString).
    ].
    type == #center ifTrue:[
        ^ pos - ((aGC font widthOf:aString) // 2).
    ].
    type == #decimal ifTrue:[
        idx := aString indexOf:$..
        idx == 0 ifTrue:[
             ^ pos - (aGC font widthOf:aString).
        ].
        left := aString copyTo:(idx-1).
        ^ pos - (aGC font widthOf:left).
    ].
    "default is left"
    ^ pos

! !

!TabulatorSpecification methodsFor:'accessing'!

unit:aSymbol
    "allowed are: #inch, #mm, #cm, #pixel and #col"

    tabUnit := aSymbol
!

unit
    ^ tabUnit
!

align:types
    "
     an array of tab-types; each one is
        #left
        #right
        #center
        #decimal
     or a symbol which gives align of all tabs

    "
    tabTypes := types
!

align
    ^ tabTypes
!

positions:tabs
    tabPositions := tabs
!

positions
    ^ tabPositions
! !