author | Claus Gittinger <cg@exept.de> |
Wed, 01 Dec 1999 22:05:41 +0100 | |
changeset 3057 | 5d7383ca3aef |
parent 3053 | 9fd0a77f7d38 |
child 3069 | 0dc010683048 |
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 |
||
3057
5d7383ca3aef
oops - local style file (in resources) must still be found
Claus Gittinger <cg@exept.de>
parents:
3053
diff
changeset
|
58 |
|prefs failed nm dir 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) |
3057
5d7383ca3aef
oops - local style file (in resources) must still be found
Claus Gittinger <cg@exept.de>
parents:
3053
diff
changeset
|
69 |
path := Smalltalk getResourceFileName:aFileName. |
5d7383ca3aef
oops - local style file (in resources) must still be found
Claus Gittinger <cg@exept.de>
parents:
3053
diff
changeset
|
70 |
path notNil ifTrue:[ |
5d7383ca3aef
oops - local style file (in resources) must still be found
Claus Gittinger <cg@exept.de>
parents:
3053
diff
changeset
|
71 |
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
|
72 |
] ifFalse:[ |
3052 | 73 |
"/ then search in the classes package directory ... |
3053 | 74 |
dir := Smalltalk projectDirectoryForPackage:'stx:libview'. |
3052 | 75 |
dir notNil ifTrue:[ |
76 |
dir := dir , '/resources' |
|
77 |
]. |
|
3048
df43567e46cd
look for styles in the libview package-dir as well
Claus Gittinger <cg@exept.de>
parents:
2775
diff
changeset
|
78 |
]. |
3052 | 79 |
failed := (prefs readFromFile:aFileName directory:dir) isNil. |
153 | 80 |
prefs at:#fileReadFailed put:failed. |
53 | 81 |
^ prefs |
82 |
||
72 | 83 |
" |
84 |
ViewStyle fromFile:'motif.style' |
|
85 |
ViewStyle fromFile:'normal.style' |
|
86 |
ViewStyle fromFile:'iris.style' |
|
87 |
" |
|
3052 | 88 |
|
53 | 89 |
! ! |
90 |
||
91 |
!ViewStyle methodsFor:'accessing'! |
|
92 |
||
243 | 93 |
at:aKey |
94 |
|sCls val| |
|
95 |
||
96 |
sCls := thisContext sender receiver. |
|
97 |
sCls isBehavior ifFalse:[sCls := sCls class]. |
|
98 |
(sCls isSubclassOf:SimpleView) ifTrue:[ |
|
99 |
val := self at:(sCls name , '.' , aKey) default:nil. |
|
100 |
val notNil ifTrue:[^ val]. |
|
101 |
]. |
|
102 |
^ self at:aKey default:nil |
|
103 |
||
104 |
"Modified: 10.9.1995 / 10:59:38 / claus" |
|
105 |
! |
|
106 |
||
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
107 |
at:aKey default:default |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
108 |
"translate a string; if not present, return default. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
109 |
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
|
110 |
'fooBar' is also tried. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
111 |
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
|
112 |
'classname.itemKey' in the stylesheets." |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
113 |
|
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
114 |
|v i k2| |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
115 |
|
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
116 |
(self includesKey:aKey) ifTrue:[ |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
117 |
^ (super at:aKey ifAbsent:default) value |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
118 |
]. |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
119 |
(i := aKey indexOf:$.) ~~ 0 ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
120 |
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
|
121 |
(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
|
122 |
]. |
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
123 |
^ default value |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
124 |
|
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
125 |
"Created: / 14.10.1997 / 00:21:15 / cg" |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
126 |
"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
|
127 |
! |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
128 |
|
243 | 129 |
colorAt:aKey |
130 |
"retrieve a color resource - also aquire a device color |
|
131 |
to avoid repeated color allocations later" |
|
132 |
||
133 |
^ self deviceResourceAt:aKey default:nil |
|
134 |
! |
|
135 |
||
136 |
colorAt:aKey default:default |
|
137 |
"retrieve a color resource - also aquire a device color |
|
138 |
to avoid repeated color allocations later" |
|
139 |
||
140 |
^ self deviceResourceAt:aKey default:default |
|
141 |
! |
|
142 |
||
78 | 143 |
deviceResourceAt:aKey default:default |
144 |
"retrieve a resource - also aquire a device version |
|
1226 | 145 |
for the default display, to avoid repeated allocations later" |
78 | 146 |
|
228 | 147 |
|aResource deviceResource device| |
78 | 148 |
|
1226 | 149 |
device := Display. |
78 | 150 |
aResource := self at:aKey default:default. |
228 | 151 |
aResource isNil ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
152 |
aResource := default |
228 | 153 |
]. |
78 | 154 |
aResource notNil ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
155 |
device notNil ifTrue:[ |
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
156 |
deviceResource := aResource onDevice:device. |
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
157 |
] |
228 | 158 |
]. |
159 |
deviceResource notNil ifTrue:[ |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
160 |
^ deviceResource |
78 | 161 |
]. |
1006 | 162 |
^ aResource |
1226 | 163 |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
164 |
"Modified: / 5.9.1998 / 20:25:19 / cg" |
78 | 165 |
! |
166 |
||
243 | 167 |
doesNotUnderstand:aMessage |
168 |
^ self at:(aMessage selector) default:nil |
|
78 | 169 |
! |
170 |
||
243 | 171 |
fontAt:aKey |
172 |
"retrieve a font resource - also aquire a device font |
|
173 |
to avoid repeated font allocations later" |
|
78 | 174 |
|
175 |
^ self deviceResourceAt:aKey default:nil |
|
176 |
! |
|
177 |
||
178 |
fontAt:aKey default:default |
|
179 |
"retrieve a font resource - also aquire a device font |
|
180 |
to avoid repeated font allocations later" |
|
181 |
||
182 |
^ self deviceResourceAt:aKey default:default |
|
183 |
! |
|
184 |
||
72 | 185 |
is3D |
186 |
is3D isNil ifTrue:[ |
|
187 |
is3D := self at:#is3D default:false. |
|
53 | 188 |
]. |
72 | 189 |
^ is3D |
53 | 190 |
! |
191 |
||
72 | 192 |
name |
193 |
name isNil ifTrue:[ |
|
194 |
name := self at:#name default:'noname'. |
|
53 | 195 |
]. |
72 | 196 |
^ name |
2775 | 197 |
! |
198 |
||
199 |
viewGrey |
|
200 |
viewGrey isNil ifTrue:[ |
|
201 |
viewGrey := self at:#viewGrey default:nil. |
|
202 |
]. |
|
203 |
^ viewGrey |
|
243 | 204 |
! ! |
53 | 205 |
|
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
206 |
!ViewStyle methodsFor:'error handling'! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
207 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
208 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
209 |
"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
|
210 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
211 |
fileReadFailed := true. |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
212 |
^ self |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
213 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
214 |
"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
|
215 |
! ! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
216 |
|
253 | 217 |
!ViewStyle class methodsFor:'documentation'! |
218 |
||
219 |
version |
|
3057
5d7383ca3aef
oops - local style file (in resources) must still be found
Claus Gittinger <cg@exept.de>
parents:
3053
diff
changeset
|
220 |
^ '$Header: /cvs/stx/stx/libview/ViewStyle.st,v 1.23 1999-12-01 21:05:41 cg Exp $' |
253 | 221 |
! ! |