ListEntry.st
author Claus Gittinger <cg@exept.de>
Fri, 28 Jun 2019 09:21:50 +0200
changeset 6078 08c9e2a47dc5
parent 5927 f8763479f0c9
child 6119 68569809d6db
permissions -rw-r--r--
#OTHER by cg self class name -> self className

"{ Encoding: utf8 }"

"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libwidg2' }"

"{ NameSpace: Smalltalk }"

Object subclass:#ListEntry
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Views-Support'
!

ListEntry subclass:#SeparatingLineEntry
	instanceVariableNames:'width'
	classVariableNames:''
	poolDictionaries:''
	privateIn:ListEntry
!

!ListEntry class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1995 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    ListEntry is an abstract superclass for objects which can be used
    in place of strings in ListViews or SelectionInListViews.

    If you want to create new subclasses, implement (at least) the methods
    found in the 'required protocol' category.

    [author:]
        Claus Gittinger

    [see also:]
        ListView
"
! !

!ListEntry class methodsFor:'instance creation'!

separatingLineEntry
    ^ SeparatingLineEntry new

    "Created: / 01-10-2018 / 11:22:03 / Claus Gittinger"
! !

!ListEntry methodsFor:'comparing'!

< aString
    "behave like a string when comparing"

    ^ self asString < aString asString

    "Created: 8.2.1996 / 12:01:29 / cg"
!

= aString
    "behave like a string when comparing"

    self == aString ifTrue:[^ true].
    ^ self asString = aString asString
!

hash
    "return an integer useful for hashing"

    ^ self asString hash
! !

!ListEntry methodsFor:'printing & storing'!

printOn:aStream

    aStream nextPutAll:self asString.

    "Created: / 20.1.1998 / 14:11:02 / stefan"
!

printString
    ^ self asString

    "Created: 8.2.1996 / 11:56:14 / cg"
! !

!ListEntry methodsFor:'queries'!

hasChangeOfEmphasis
    "return true, if the receiver contains non-empty emphasis information
     i.e. any non-normal (=emphasized) characters"

    ^ false

    "Created: / 27-10-2018 / 09:51:45 / Claus Gittinger"
!

hasIcon
    ^ false
!

hasImage
    ^ false
!

includes:aCharacter 
    "behave like a string when testing"

    ^ self string includes:aCharacter

    "Modified: / 30.10.1997 / 15:42:32 / cg"
!

size
    "behave like a string when asked for the size"

    ^ self string size

    "Created: / 8.2.1996 / 12:54:45 / cg"
    "Modified: / 30.10.1997 / 15:42:19 / cg"
!

species
    ^ String

    "Created: 8.2.1996 / 12:52:38 / cg"
!

string
    ^ self asString
! !

!ListEntry methodsFor:'required protocol'!

asString
    "return the receiver as a string (for example, to store it in a file)"

    ^ self subclassResponsibility
!

displayOn:aGC x:x y:y opaque:opaque
    "display the receiver on a GC"

    ^ self subclassResponsibility
!

heightOn:aGC
    "return the height of the receiver when displayed in aGC.
     Assume the GC's font is taken. If that is not the case in a
     particular subclass, this method is to be redefined there."

    ^ aGC font heightOn:(aGC device) 

    "Created: 12.5.1996 / 20:37:06 / cg"
!

sameStringAndEmphasisAs:aStringOrText

    ^ self subclassResponsibility
!

widthOn:aGC
    "return the width (in device units) of the receiver when displayed in aGC"

    ^ self subclassResponsibility

    "Created: 12.5.1996 / 20:53:09 / cg"
! !

!ListEntry methodsFor:'string protocol'!

at:index
    "behave like a string when accessing characters"

    ^ self string at:index

    "Created: / 8.2.1996 / 12:53:06 / cg"
    "Modified: / 30.10.1997 / 15:41:47 / cg"
!

do:aBlock
    "behave like a string when enumerating characters"

    ^ self string do:aBlock

    "Created: / 8.2.1996 / 12:56:06 / cg"
    "Modified: / 30.10.1997 / 15:42:06 / cg"
!

withoutAnyColorEmphasis
    "/ to be redefined in subclasses
    ^ self.

    "Created: / 27-10-2018 / 10:09:14 / Claus Gittinger"
! !

!ListEntry::SeparatingLineEntry class methodsFor:'documentation'!

documentation
"
  an experiment (unfinished)
  
  in a listView:
                                                                        [exBegin]
    |top slv wrapper l|

    l := OrderedCollection new.
    l add:'one'.
    l add:'two'.
    l add:(ListEntry separatingLineEntry).
    l add:'three'.
    
    slv := SelectionInListView new.
    slv list:l.
    wrapper := HVScrollableView forView:slv miniScrollerH:true.

    top := StandardSystemView extent:150@200.
    top add:wrapper in:(0.0@0.0 corner:1.0@1.0).
    top open.
                                                                        [exEnd]
"
! !

!ListEntry::SeparatingLineEntry methodsFor:'required protocol'!

displayOn:aGC x:x y:y opaque:opaque
    |hFont aFont yMiddle|
    
    "/ hFont := aGC font height.
    aFont := aGC font ascent.
    yMiddle := y - (aFont // 2).
    ^ aGC displayLineFromX:0 y:yMiddle toX:(width-1) y:yMiddle

    "Created: / 01-10-2018 / 11:26:20 / Claus Gittinger"
!

widthOn:aGC
    width := aGC width.
    ^ width

    "Created: / 01-10-2018 / 11:25:33 / Claus Gittinger"
! !

!ListEntry class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !