author | Claus Gittinger <cg@exept.de> |
Tue, 22 Sep 2015 15:53:35 +0200 | |
changeset 6920 | cbe27edb6e72 |
parent 5952 | 5a8e9468117a |
child 6924 | 295e6d594ca0 |
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 |
" |
|
3678 | 12 |
"{ Package: 'stx:libview' }" |
13 |
||
6920 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
243 | 16 |
ResourcePack subclass:#ViewStyle |
2775 | 17 |
instanceVariableNames:'name is3D viewGrey' |
617 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
20 |
category:'Views-Support' |
|
53 | 21 |
! |
22 |
||
23 |
!ViewStyle class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 28 |
All Rights Reserved |
53 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
39 |
documentation |
|
40 |
" |
|
41 |
instances of this class keep all view-style specific information. |
|
72 | 42 |
The current viewStyle is kept in Views-classvariable called 'StyleSheet' |
43 |
and is instantiated with 'View defaultStyle:aStyleSymbol', which reads |
|
44 |
a stylesheet from a file '<aStyleSymbol>.style' (usually in the 'resources' |
|
45 |
directory. |
|
617 | 46 |
|
47 |
[see also:] |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
48 |
View |
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
49 |
( Configuration & Customization :html: custom/TOP.html#VIEWSTYLE ) |
617 | 50 |
|
51 |
[author:] |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
52 |
Claus Gittinger |
53 | 53 |
" |
54 |
! ! |
|
55 |
||
56 |
!ViewStyle class methodsFor:'instance creation'! |
|
57 |
||
3678 | 58 |
fromFile:aFileNameArg |
53 | 59 |
"get the preferences definitions from a file" |
60 |
||
5531 | 61 |
|aFileName prefs failed nm nmInStyles dir path baseName| |
53 | 62 |
|
3678 | 63 |
aFileName := aFileNameArg asFilename. |
64 |
(aFileName hasSuffix:'style') ifTrue:[ |
|
4681
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
65 |
baseName := aFileName withoutSuffix baseName. |
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
66 |
nm := aFileName. |
72 | 67 |
] ifFalse:[ |
4681
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
68 |
baseName := aFileName baseName. |
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
69 |
nm := aFileName withSuffix:'style'. |
72 | 70 |
]. |
5531 | 71 |
nm isAbsolute ifFalse:[ |
72 |
nmInStyles := 'styles' asFilename / nm |
|
73 |
]. |
|
74 |
||
3678 | 75 |
prefs := self new. |
4681
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
76 |
prefs at:#name put:baseName. |
153 | 77 |
|
5531 | 78 |
nmInStyles notNil ifTrue:[ |
79 |
path := Smalltalk getResourceFileName:nmInStyles forPackage:'stx:libview'. |
|
80 |
]. |
|
81 |
path isNil ifTrue:[ |
|
82 |
path := Smalltalk getResourceFileName:nm forPackage:'stx:libview'. |
|
83 |
]. |
|
3057
5d7383ca3aef
oops - local style file (in resources) must still be found
Claus Gittinger <cg@exept.de>
parents:
3053
diff
changeset
|
84 |
path notNil ifTrue:[ |
4681
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
85 |
dir := path asFilename directory pathName. |
3048
df43567e46cd
look for styles in the libview package-dir as well
Claus Gittinger <cg@exept.de>
parents:
2775
diff
changeset
|
86 |
]. |
4681
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
87 |
failed := (prefs readFromFile:nm directory:dir) isNil. |
153 | 88 |
prefs at:#fileReadFailed put:failed. |
53 | 89 |
^ prefs |
90 |
||
72 | 91 |
" |
4681
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
92 |
ViewStyle fromFile:'motif' |
3112 | 93 |
ViewStyle fromFile:'motif.style' |
94 |
ViewStyle fromFile:'normal.style' |
|
72 | 95 |
ViewStyle fromFile:'iris.style' |
3678 | 96 |
ViewStyle fromFile:'iris.style' asFilename |
72 | 97 |
" |
3052 | 98 |
|
3112 | 99 |
"Modified: / 10.12.1999 / 16:05:30 / cg" |
53 | 100 |
! ! |
101 |
||
5952 | 102 |
!ViewStyle class methodsFor:'constants'! |
103 |
||
104 |
msWindowsVista |
|
105 |
^ #mswindowsVista |
|
106 |
! |
|
107 |
||
108 |
msWindowsXP |
|
109 |
^ #mswindowsXP |
|
110 |
! |
|
111 |
||
112 |
normal |
|
113 |
^ #normal |
|
114 |
! ! |
|
115 |
||
53 | 116 |
!ViewStyle methodsFor:'accessing'! |
117 |
||
243 | 118 |
at:aKey |
119 |
|sCls val| |
|
120 |
||
121 |
sCls := thisContext sender receiver. |
|
122 |
sCls isBehavior ifFalse:[sCls := sCls class]. |
|
123 |
(sCls isSubclassOf:SimpleView) ifTrue:[ |
|
124 |
val := self at:(sCls name , '.' , aKey) default:nil. |
|
125 |
val notNil ifTrue:[^ val]. |
|
126 |
]. |
|
127 |
^ self at:aKey default:nil |
|
128 |
||
129 |
"Modified: 10.9.1995 / 10:59:38 / claus" |
|
130 |
! |
|
131 |
||
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
132 |
at:aKey default:default |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
133 |
"translate a string; if not present, return default. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
134 |
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
|
135 |
'fooBar' is also tried. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
136 |
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
|
137 |
'classname.itemKey' in the stylesheets." |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
138 |
|
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
139 |
|v i k2| |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
140 |
|
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
141 |
(self includesKey:aKey) ifTrue:[ |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
142 |
^ (super at:aKey ifAbsent:default) value |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
143 |
]. |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
144 |
(i := aKey indexOf:$.) ~~ 0 ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
145 |
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
|
146 |
(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
|
147 |
]. |
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
148 |
^ default value |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
149 |
|
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
150 |
"Created: / 14.10.1997 / 00:21:15 / cg" |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
151 |
"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
|
152 |
! |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
153 |
|
243 | 154 |
colorAt:aKey |
155 |
"retrieve a color resource - also aquire a device color |
|
156 |
to avoid repeated color allocations later" |
|
157 |
||
6920 | 158 |
|value device deviceColor| |
159 |
||
160 |
device := Display. |
|
161 |
||
162 |
value := self at:aKey default:nil. |
|
163 |
value isInteger ifTrue:[ |
|
164 |
value := Color rgbValue:value |
|
165 |
]. |
|
166 |
(value notNil and:[device notNil]) ifTrue:[ |
|
167 |
deviceColor := value onDevice:device. |
|
168 |
deviceColor notNil ifTrue:[^ deviceColor]. |
|
169 |
]. |
|
170 |
^ value |
|
243 | 171 |
! |
172 |
||
173 |
colorAt:aKey default:default |
|
174 |
"retrieve a color resource - also aquire a device color |
|
175 |
to avoid repeated color allocations later" |
|
176 |
||
177 |
^ self deviceResourceAt:aKey default:default |
|
178 |
! |
|
179 |
||
78 | 180 |
deviceResourceAt:aKey default:default |
181 |
"retrieve a resource - also aquire a device version |
|
1226 | 182 |
for the default display, to avoid repeated allocations later" |
78 | 183 |
|
228 | 184 |
|aResource deviceResource device| |
78 | 185 |
|
1226 | 186 |
device := Display. |
3678 | 187 |
|
78 | 188 |
aResource := self at:aKey default:default. |
3678 | 189 |
(aResource notNil and:[device notNil]) ifTrue:[ |
190 |
deviceResource := aResource onDevice:device. |
|
191 |
deviceResource notNil ifTrue:[^ deviceResource]. |
|
78 | 192 |
]. |
1006 | 193 |
^ aResource |
1226 | 194 |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
195 |
"Modified: / 5.9.1998 / 20:25:19 / cg" |
78 | 196 |
! |
197 |
||
243 | 198 |
doesNotUnderstand:aMessage |
199 |
^ self at:(aMessage selector) default:nil |
|
78 | 200 |
! |
201 |
||
243 | 202 |
fontAt:aKey |
203 |
"retrieve a font resource - also aquire a device font |
|
204 |
to avoid repeated font allocations later" |
|
78 | 205 |
|
206 |
^ self deviceResourceAt:aKey default:nil |
|
207 |
! |
|
208 |
||
209 |
fontAt:aKey default:default |
|
210 |
"retrieve a font resource - also aquire a device font |
|
211 |
to avoid repeated font allocations later" |
|
212 |
||
213 |
^ self deviceResourceAt:aKey default:default |
|
214 |
! |
|
215 |
||
72 | 216 |
is3D |
217 |
is3D isNil ifTrue:[ |
|
218 |
is3D := self at:#is3D default:false. |
|
53 | 219 |
]. |
72 | 220 |
^ is3D |
53 | 221 |
! |
222 |
||
72 | 223 |
name |
224 |
name isNil ifTrue:[ |
|
225 |
name := self at:#name default:'noname'. |
|
53 | 226 |
]. |
72 | 227 |
^ name |
2775 | 228 |
! |
229 |
||
230 |
viewGrey |
|
231 |
viewGrey isNil ifTrue:[ |
|
232 |
viewGrey := self at:#viewGrey default:nil. |
|
233 |
]. |
|
234 |
^ viewGrey |
|
243 | 235 |
! ! |
53 | 236 |
|
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
237 |
!ViewStyle methodsFor:'error handling'! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
238 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
239 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
240 |
"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
|
241 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
242 |
fileReadFailed := true. |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
243 |
^ self |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
244 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
245 |
"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
|
246 |
! ! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
247 |
|
3678 | 248 |
!ViewStyle methodsFor:'queries'! |
249 |
||
250 |
isWindowsStyle |
|
251 |
"answer true if this is a MS-Windows style. |
|
252 |
XXX Currently we simply check the name" |
|
253 |
||
5054 | 254 |
|nm| |
255 |
||
256 |
nm := name ? self name. |
|
3678 | 257 |
|
5054 | 258 |
^ nm == #win95 |
259 |
or:[nm == #win98 |
|
260 |
or:[nm == #winXP |
|
261 |
or:[nm == #winVista ]]] |
|
4730 | 262 |
! |
263 |
||
5052
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
264 |
isWindowsVistaStyle |
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
265 |
"answer true if this is a MS-Windows-Vista (or later) style. |
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
266 |
XXX Currently we simply check the name" |
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
267 |
|
5054 | 268 |
|nm| |
5052
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
269 |
|
5054 | 270 |
nm := name ? self name. |
271 |
||
272 |
^ nm == #winVista |
|
5052
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
273 |
! |
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
274 |
|
4730 | 275 |
isWindowsXPStyle |
276 |
"answer true if this is a MS-Windows-XP (or later) style. |
|
277 |
XXX Currently we simply check the name" |
|
278 |
||
5054 | 279 |
|nm| |
4730 | 280 |
|
5054 | 281 |
nm := name ? self name. |
282 |
||
283 |
^ nm == #winXP |
|
284 |
or:[nm == #winVista] |
|
3678 | 285 |
! ! |
286 |
||
3069 | 287 |
!ViewStyle methodsFor:'special'! |
288 |
||
289 |
newDerivedStyle |
|
290 |
"create and return a new style, which inherits from |
|
291 |
the receiver, but possibly overrides individual entries. |
|
292 |
This may be useful to give a single button some different |
|
293 |
look (in the future - read the comment in SimpleView>>viewStyle:)" |
|
294 |
||
295 |
^ self class new |
|
296 |
superPack:self; |
|
297 |
at:#is3D put:(self is3D); |
|
298 |
at:viewGrey put:(self viewGrey); |
|
299 |
yourself |
|
300 |
||
301 |
" |
|
302 |
|panel b1 b2 newStyle| |
|
303 |
||
304 |
panel := HorizontalPanelView new. |
|
305 |
panel add:(b1 := Button label:'oldStyle'). |
|
306 |
panel add:(b2 := Button label:'newStyle'). |
|
307 |
newStyle := b1 styleSheet newDerivedStyle. |
|
308 |
newStyle at:'button.activeBackgroundColor' put:Color blue. |
|
309 |
b2 styleSheet:newStyle. |
|
310 |
||
311 |
panel open |
|
312 |
" |
|
313 |
! ! |
|
314 |
||
253 | 315 |
!ViewStyle class methodsFor:'documentation'! |
316 |
||
317 |
version |
|
6920 | 318 |
^ '$Header$' |
5531 | 319 |
! |
320 |
||
321 |
version_CVS |
|
6920 | 322 |
^ '$Header$' |
253 | 323 |
! ! |
6920 | 324 |