author | Claus Gittinger <cg@exept.de> |
Thu, 16 Nov 1995 17:26:36 +0100 | |
changeset 88 | d591b16c8f46 |
parent 86 | 4d7dbb5f1719 |
child 93 | f3158d8e67d0 |
permissions | -rw-r--r-- |
58 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
'From Smalltalk/X, Version:2.10.5 on 15-may-1995 at 8:03:34 am'! |
|
14 |
||
15 |
ListEntry subclass:#ColoredListEntry |
|
88
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
16 |
instanceVariableNames:'color string bgColor' |
58 | 17 |
classVariableNames:'' |
18 |
poolDictionaries:'' |
|
19 |
category:'Views-Support' |
|
20 |
! |
|
21 |
||
22 |
!ColoredListEntry class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
version |
|
88
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
39 |
^ '$Header: /cvs/stx/stx/libwidg2/ColoredListEntry.st,v 1.5 1995-11-16 16:26:36 cg Exp $' |
58 | 40 |
! |
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
Instances of ColoredListEntry can be used in place of strings |
|
45 |
as entries of the list in a ListView or SelectionInListView. |
|
88
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
46 |
|
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
47 |
Notice: this is a temporary kludge class which will be made obsolete, |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
48 |
once full-attributed strings are available. |
58 | 49 |
" |
50 |
! |
|
51 |
||
52 |
examples |
|
53 |
" |
|
54 |
putting colored entries into a SelectionInListView |
|
55 |
(instead of strings)' |
|
56 |
||
57 |
|v e myList tabs| |
|
58 |
||
59 |
myList := OrderedCollection new. |
|
60 |
||
61 |
myList add:(ColoredListEntry string:'red' color:Color red). |
|
62 |
myList add:(ColoredListEntry string:'green' color:Color green). |
|
63 |
myList add:(ColoredListEntry string:'blue' color:Color blue). |
|
64 |
myList add:(ColoredListEntry string:'white' color:Color white). |
|
65 |
myList add:(ColoredListEntry string:'black' color:Color black). |
|
66 |
myList add:(ColoredListEntry string:'yellow' color:Color yellow). |
|
67 |
||
68 |
v := SelectionInListView new. |
|
69 |
v setList:myList expandTabs:false. |
|
70 |
v open |
|
71 |
||
72 |
||
60 | 73 |
in a popUpList (sorry, Labels do not (yet) know how to display |
74 |
non-strings. |
|
58 | 75 |
|
76 |
|v e myList selList tabs| |
|
77 |
||
78 |
myList := OrderedCollection new. |
|
79 |
||
80 |
myList add:(ColoredListEntry string:'red' color:Color red). |
|
81 |
myList add:(ColoredListEntry string:'green' color:Color green). |
|
82 |
myList add:(ColoredListEntry string:'blue' color:Color blue). |
|
83 |
myList add:(ColoredListEntry string:'white' color:Color white). |
|
84 |
myList add:(ColoredListEntry string:'black' color:Color black). |
|
85 |
myList add:(ColoredListEntry string:'yellow' color:Color yellow). |
|
86 |
||
87 |
selList := SelectionInList new list:myList. |
|
88 |
||
89 |
v := PopUpList on:selList. |
|
90 |
v open |
|
91 |
" |
|
92 |
! ! |
|
93 |
||
94 |
!ColoredListEntry class methodsFor:'instance creation'! |
|
95 |
||
96 |
string:aString color:aColor |
|
97 |
^ self new string:aString color:aColor |
|
88
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
98 |
! |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
99 |
|
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
100 |
string:aString foregroundColor:fgColor backgroundColor:bgColor |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
101 |
^ self new string:aString foregroundColor:fgColor backgroundColor:bgColor |
58 | 102 |
! ! |
103 |
||
104 |
!ColoredListEntry methodsFor:'drawing'! |
|
105 |
||
106 |
displayOn:aGC x:x y:y |
|
107 |
"display the receiver on a GC" |
|
108 |
||
88
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
109 |
|savedPaint savedBgPaint| |
73 | 110 |
|
111 |
savedPaint := aGC paint. |
|
88
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
112 |
bgColor notNil ifTrue:[ |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
113 |
savedBgPaint := aGC backgroundPaint. |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
114 |
aGC paint:color on:bgColor. |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
115 |
aGC displayOpaqueString:string x:x y:y. |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
116 |
aGC paint:savedPaint on:savedBgPaint |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
117 |
] ifFalse:[ |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
118 |
aGC paint:color. |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
119 |
aGC displayString:string x:x y:y. |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
120 |
aGC paint:savedPaint |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
121 |
] |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
122 |
|
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
123 |
"Created: 16.11.1995 / 16:54:40 / cg" |
58 | 124 |
! ! |
125 |
||
126 |
!ColoredListEntry methodsFor:'accessing'! |
|
127 |
||
128 |
string:aString color:aColor |
|
129 |
string := aString. |
|
130 |
color := aColor |
|
88
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
131 |
! |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
132 |
|
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
133 |
string:aString foregroundColor:fg backgroundColor:bg |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
134 |
string := aString. |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
135 |
color := fg. |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
136 |
bgColor := bg. |
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
137 |
|
d591b16c8f46
allow for background (i.e. opaque strings)
Claus Gittinger <cg@exept.de>
parents:
86
diff
changeset
|
138 |
"Created: 16.11.1995 / 16:53:17 / cg" |
58 | 139 |
! ! |
140 |
||
141 |
!ColoredListEntry methodsFor:'converting'! |
|
142 |
||
143 |
string |
|
144 |
^ string |
|
145 |
! |
|
146 |
||
147 |
asString |
|
148 |
^ string |
|
149 |
! ! |
|
150 |
||
151 |
!ColoredListEntry methodsFor:'queries'! |
|
152 |
||
153 |
widthIn:aGC |
|
154 |
"return the width of the receiver when displayed in aGC" |
|
155 |
||
156 |
^ aGC font widthOf:string |
|
157 |
! ! |