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