author | Claus Gittinger <cg@exept.de> |
Fri, 10 Dec 1999 16:03:50 +0100 | |
changeset 3112 | 94968bec00b0 |
parent 3084 | 0fa2dc926084 |
child 3118 | 5a03bfe77f91 |
permissions | -rw-r--r-- |
53 | 1 |
" |
243 | 2 |
COPYRIGHT (c) 1993 by Claus Gittinger |
72 | 3 |
All Rights Reserved |
53 | 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 |
||
243 | 13 |
ResourcePack subclass:#ViewStyle |
2775 | 14 |
instanceVariableNames:'name is3D viewGrey' |
617 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
17 |
category:'Views-Support' |
|
53 | 18 |
! |
19 |
||
20 |
!ViewStyle class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 25 |
All Rights Reserved |
53 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
instances of this class keep all view-style specific information. |
|
72 | 39 |
The current viewStyle is kept in Views-classvariable called 'StyleSheet' |
40 |
and is instantiated with 'View defaultStyle:aStyleSymbol', which reads |
|
41 |
a stylesheet from a file '<aStyleSymbol>.style' (usually in the 'resources' |
|
42 |
directory. |
|
617 | 43 |
|
44 |
[see also:] |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
45 |
View |
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
46 |
( Configuration & Customization :html: custom/TOP.html#VIEWSTYLE ) |
617 | 47 |
|
48 |
[author:] |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
49 |
Claus Gittinger |
53 | 50 |
" |
51 |
! ! |
|
52 |
||
53 |
!ViewStyle class methodsFor:'instance creation'! |
|
54 |
||
55 |
fromFile:aFileName |
|
56 |
"get the preferences definitions from a file" |
|
57 |
||
3112 | 58 |
|prefs failed nm dir d path| |
53 | 59 |
|
72 | 60 |
prefs := self new. |
61 |
(aFileName endsWith:'.style') ifTrue:[ |
|
3048
df43567e46cd
look for styles in the libview package-dir as well
Claus Gittinger <cg@exept.de>
parents:
2775
diff
changeset
|
62 |
nm := aFileName copyWithoutLast:6 |
72 | 63 |
] ifFalse:[ |
3048
df43567e46cd
look for styles in the libview package-dir as well
Claus Gittinger <cg@exept.de>
parents:
2775
diff
changeset
|
64 |
nm := aFileName |
72 | 65 |
]. |
153 | 66 |
prefs at:#name put:nm. |
67 |
||
3050
55940674bfa4
also search in libview package
Claus Gittinger <cg@exept.de>
parents:
3048
diff
changeset
|
68 |
"/ generic search first (allows for user to overwrite it) |
3084 | 69 |
path := Smalltalk getResourceFileName:aFileName forPackage:'stx:libview'. |
3112 | 70 |
path := Smalltalk getResourceFileName:aFileName forPackage:'stx:libview'. |
3057
5d7383ca3aef
oops - local style file (in resources) must still be found
Claus Gittinger <cg@exept.de>
parents:
3053
diff
changeset
|
71 |
path notNil ifTrue:[ |
5d7383ca3aef
oops - local style file (in resources) must still be found
Claus Gittinger <cg@exept.de>
parents:
3053
diff
changeset
|
72 |
dir := path asFilename directory name |
5d7383ca3aef
oops - local style file (in resources) must still be found
Claus Gittinger <cg@exept.de>
parents:
3053
diff
changeset
|
73 |
] ifFalse:[ |
3052 | 74 |
"/ then search in the classes package directory ... |
3053 | 75 |
dir := Smalltalk projectDirectoryForPackage:'stx:libview'. |
3052 | 76 |
dir notNil ifTrue:[ |
3112 | 77 |
d := dir asFilename construct:'resources'. |
78 |
(d exists and:[(d construct:aFileName) exists]) ifFalse:[ |
|
79 |
d := dir asFilename construct:'styles'. |
|
80 |
]. |
|
81 |
(d exists and:[(d construct:aFileName) exists]) ifTrue:[ |
|
82 |
dir := d pathName |
|
83 |
]. |
|
3052 | 84 |
]. |
3048
df43567e46cd
look for styles in the libview package-dir as well
Claus Gittinger <cg@exept.de>
parents:
2775
diff
changeset
|
85 |
]. |
3052 | 86 |
failed := (prefs readFromFile:aFileName directory:dir) isNil. |
153 | 87 |
prefs at:#fileReadFailed put:failed. |
53 | 88 |
^ prefs |
89 |
||
72 | 90 |
" |
3112 | 91 |
ViewStyle fromFile:'motif.style' |
92 |
ViewStyle fromFile:'normal.style' |
|
72 | 93 |
ViewStyle fromFile:'iris.style' |
94 |
" |
|
3052 | 95 |
|
3112 | 96 |
"Modified: / 10.12.1999 / 16:05:30 / cg" |
53 | 97 |
! ! |
98 |
||
99 |
!ViewStyle methodsFor:'accessing'! |
|
100 |
||
243 | 101 |
at:aKey |
102 |
|sCls val| |
|
103 |
||
104 |
sCls := thisContext sender receiver. |
|
105 |
sCls isBehavior ifFalse:[sCls := sCls class]. |
|
106 |
(sCls isSubclassOf:SimpleView) ifTrue:[ |
|
107 |
val := self at:(sCls name , '.' , aKey) default:nil. |
|
108 |
val notNil ifTrue:[^ val]. |
|
109 |
]. |
|
110 |
^ self at:aKey default:nil |
|
111 |
||
112 |
"Modified: 10.9.1995 / 10:59:38 / claus" |
|
113 |
! |
|
114 |
||
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
115 |
at:aKey default:default |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
116 |
"translate a string; if not present, return default. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
117 |
Here, two keys are tried, iff the key is of the form 'foo.bar', |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
118 |
'fooBar' is also tried. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
119 |
This has been added for a smooth migration towards names with a form of |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
120 |
'classname.itemKey' in the stylesheets." |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
121 |
|
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
122 |
|v i k2| |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
123 |
|
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
124 |
(self includesKey:aKey) ifTrue:[ |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
125 |
^ (super at:aKey ifAbsent:default) value |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
126 |
]. |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
127 |
(i := aKey indexOf:$.) ~~ 0 ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
128 |
k2 := (aKey copyTo:i-1) , (aKey copyFrom:i+1) asUppercaseFirst. |
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
129 |
(self includesKey:k2) ifTrue:[^ super at:k2 ifAbsent:default]. |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
130 |
]. |
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
131 |
^ default value |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
132 |
|
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
133 |
"Created: / 14.10.1997 / 00:21:15 / cg" |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
134 |
"Modified: / 15.9.1998 / 21:47:13 / cg" |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
135 |
! |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
136 |
|
243 | 137 |
colorAt:aKey |
138 |
"retrieve a color resource - also aquire a device color |
|
139 |
to avoid repeated color allocations later" |
|
140 |
||
141 |
^ self deviceResourceAt:aKey default:nil |
|
142 |
! |
|
143 |
||
144 |
colorAt:aKey default:default |
|
145 |
"retrieve a color resource - also aquire a device color |
|
146 |
to avoid repeated color allocations later" |
|
147 |
||
148 |
^ self deviceResourceAt:aKey default:default |
|
149 |
! |
|
150 |
||
78 | 151 |
deviceResourceAt:aKey default:default |
152 |
"retrieve a resource - also aquire a device version |
|
1226 | 153 |
for the default display, to avoid repeated allocations later" |
78 | 154 |
|
228 | 155 |
|aResource deviceResource device| |
78 | 156 |
|
1226 | 157 |
device := Display. |
78 | 158 |
aResource := self at:aKey default:default. |
228 | 159 |
aResource isNil ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
160 |
aResource := default |
228 | 161 |
]. |
78 | 162 |
aResource notNil ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
163 |
device notNil ifTrue:[ |
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
164 |
deviceResource := aResource onDevice:device. |
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
165 |
] |
228 | 166 |
]. |
167 |
deviceResource notNil ifTrue:[ |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
168 |
^ deviceResource |
78 | 169 |
]. |
1006 | 170 |
^ aResource |
1226 | 171 |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
172 |
"Modified: / 5.9.1998 / 20:25:19 / cg" |
78 | 173 |
! |
174 |
||
243 | 175 |
doesNotUnderstand:aMessage |
176 |
^ self at:(aMessage selector) default:nil |
|
78 | 177 |
! |
178 |
||
243 | 179 |
fontAt:aKey |
180 |
"retrieve a font resource - also aquire a device font |
|
181 |
to avoid repeated font allocations later" |
|
78 | 182 |
|
183 |
^ self deviceResourceAt:aKey default:nil |
|
184 |
! |
|
185 |
||
186 |
fontAt:aKey default:default |
|
187 |
"retrieve a font resource - also aquire a device font |
|
188 |
to avoid repeated font allocations later" |
|
189 |
||
190 |
^ self deviceResourceAt:aKey default:default |
|
191 |
! |
|
192 |
||
72 | 193 |
is3D |
194 |
is3D isNil ifTrue:[ |
|
195 |
is3D := self at:#is3D default:false. |
|
53 | 196 |
]. |
72 | 197 |
^ is3D |
53 | 198 |
! |
199 |
||
72 | 200 |
name |
201 |
name isNil ifTrue:[ |
|
202 |
name := self at:#name default:'noname'. |
|
53 | 203 |
]. |
72 | 204 |
^ name |
2775 | 205 |
! |
206 |
||
207 |
viewGrey |
|
208 |
viewGrey isNil ifTrue:[ |
|
209 |
viewGrey := self at:#viewGrey default:nil. |
|
210 |
]. |
|
211 |
^ viewGrey |
|
243 | 212 |
! ! |
53 | 213 |
|
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
214 |
!ViewStyle methodsFor:'error handling'! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
215 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
216 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
217 |
"here, a non-existing stylesheet is treated as an error" |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
218 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
219 |
fileReadFailed := true. |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
220 |
^ self |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
221 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
222 |
"Created: 6.9.1997 / 11:40:16 / cg" |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
223 |
! ! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
224 |
|
3069 | 225 |
!ViewStyle methodsFor:'special'! |
226 |
||
227 |
newDerivedStyle |
|
228 |
"create and return a new style, which inherits from |
|
229 |
the receiver, but possibly overrides individual entries. |
|
230 |
This may be useful to give a single button some different |
|
231 |
look (in the future - read the comment in SimpleView>>viewStyle:)" |
|
232 |
||
233 |
^ self class new |
|
234 |
superPack:self; |
|
235 |
at:#is3D put:(self is3D); |
|
236 |
at:viewGrey put:(self viewGrey); |
|
237 |
yourself |
|
238 |
||
239 |
" |
|
240 |
|panel b1 b2 newStyle| |
|
241 |
||
242 |
panel := HorizontalPanelView new. |
|
243 |
panel add:(b1 := Button label:'oldStyle'). |
|
244 |
panel add:(b2 := Button label:'newStyle'). |
|
245 |
newStyle := b1 styleSheet newDerivedStyle. |
|
246 |
newStyle at:'button.activeBackgroundColor' put:Color blue. |
|
247 |
b2 styleSheet:newStyle. |
|
248 |
||
249 |
panel open |
|
250 |
" |
|
251 |
! ! |
|
252 |
||
253 | 253 |
!ViewStyle class methodsFor:'documentation'! |
254 |
||
255 |
version |
|
3112 | 256 |
^ '$Header: /cvs/stx/stx/libview/ViewStyle.st,v 1.26 1999-12-10 15:03:50 cg Exp $' |
253 | 257 |
! ! |