author | Claus Gittinger <cg@exept.de> |
Thu, 18 Jan 2018 17:02:13 +0100 | |
changeset 8258 | b80bc4ef7fd3 |
parent 7711 | 11ee38c0349c |
child 7723 | 620e91f9b082 |
child 8518 | f7fd6d8ee737 |
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 |
||
7711 | 104 |
adwaita |
105 |
^ #Adwaita |
|
106 |
||
107 |
"Created: / 24-11-2016 / 17:54:58 / cg" |
|
108 |
! |
|
109 |
||
110 |
macosx_yosemite |
|
111 |
^ #'macosx_yosemite' |
|
112 |
||
113 |
"Created: / 24-11-2016 / 17:55:46 / cg" |
|
114 |
! |
|
115 |
||
7179 | 116 |
msWindows8 |
117 |
^ #mswindows8 |
|
118 |
! |
|
119 |
||
5952 | 120 |
msWindowsVista |
121 |
^ #mswindowsVista |
|
122 |
! |
|
123 |
||
124 |
msWindowsXP |
|
125 |
^ #mswindowsXP |
|
126 |
! |
|
127 |
||
128 |
normal |
|
129 |
^ #normal |
|
130 |
! ! |
|
131 |
||
53 | 132 |
!ViewStyle methodsFor:'accessing'! |
133 |
||
243 | 134 |
at:aKey |
135 |
|sCls val| |
|
136 |
||
137 |
sCls := thisContext sender receiver. |
|
138 |
sCls isBehavior ifFalse:[sCls := sCls class]. |
|
139 |
(sCls isSubclassOf:SimpleView) ifTrue:[ |
|
140 |
val := self at:(sCls name , '.' , aKey) default:nil. |
|
141 |
val notNil ifTrue:[^ val]. |
|
142 |
]. |
|
143 |
^ self at:aKey default:nil |
|
144 |
||
145 |
"Modified: 10.9.1995 / 10:59:38 / claus" |
|
146 |
! |
|
147 |
||
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
148 |
at:aKey default:default |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
149 |
"translate a string; if not present, return default. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
150 |
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
|
151 |
'fooBar' is also tried. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
152 |
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
|
153 |
'classname.itemKey' in the stylesheets." |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
154 |
|
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
155 |
|v i k2| |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
156 |
|
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
157 |
(self includesKey:aKey) ifTrue:[ |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
158 |
^ (super at:aKey ifAbsent:default) value |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
159 |
]. |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
160 |
(i := aKey indexOf:$.) ~~ 0 ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
161 |
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
|
162 |
(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
|
163 |
]. |
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
164 |
^ default value |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
165 |
|
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
166 |
"Created: / 14.10.1997 / 00:21:15 / cg" |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
167 |
"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
|
168 |
! |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
169 |
|
243 | 170 |
colorAt:aKey |
7402 | 171 |
"retrieve a color resource - also acquire a device color |
243 | 172 |
to avoid repeated color allocations later" |
173 |
||
6920 | 174 |
|value device deviceColor| |
175 |
||
176 |
device := Display. |
|
177 |
||
178 |
value := self at:aKey default:nil. |
|
179 |
value isInteger ifTrue:[ |
|
180 |
value := Color rgbValue:value |
|
181 |
]. |
|
182 |
(value notNil and:[device notNil]) ifTrue:[ |
|
183 |
deviceColor := value onDevice:device. |
|
184 |
deviceColor notNil ifTrue:[^ deviceColor]. |
|
185 |
]. |
|
186 |
^ value |
|
243 | 187 |
! |
188 |
||
189 |
colorAt:aKey default:default |
|
7402 | 190 |
"retrieve a color resource - also acquire a device color |
243 | 191 |
to avoid repeated color allocations later" |
192 |
||
6924 | 193 |
|value device deviceColor| |
194 |
||
195 |
device := Display. |
|
196 |
||
197 |
value := self at:aKey default:default. |
|
198 |
value isInteger ifTrue:[ |
|
199 |
value := Color rgbValue:value |
|
200 |
]. |
|
201 |
(value notNil and:[device notNil]) ifTrue:[ |
|
202 |
deviceColor := value onDevice:device. |
|
203 |
deviceColor notNil ifTrue:[^ deviceColor]. |
|
204 |
]. |
|
205 |
^ value |
|
243 | 206 |
! |
207 |
||
78 | 208 |
deviceResourceAt:aKey default:default |
7402 | 209 |
"retrieve a resource - also acquire a device version |
1226 | 210 |
for the default display, to avoid repeated allocations later" |
78 | 211 |
|
228 | 212 |
|aResource deviceResource device| |
78 | 213 |
|
1226 | 214 |
device := Display. |
3678 | 215 |
|
78 | 216 |
aResource := self at:aKey default:default. |
3678 | 217 |
(aResource notNil and:[device notNil]) ifTrue:[ |
218 |
deviceResource := aResource onDevice:device. |
|
219 |
deviceResource notNil ifTrue:[^ deviceResource]. |
|
78 | 220 |
]. |
1006 | 221 |
^ aResource |
1226 | 222 |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
223 |
"Modified: / 5.9.1998 / 20:25:19 / cg" |
78 | 224 |
! |
225 |
||
243 | 226 |
doesNotUnderstand:aMessage |
227 |
^ self at:(aMessage selector) default:nil |
|
78 | 228 |
! |
229 |
||
243 | 230 |
fontAt:aKey |
7402 | 231 |
"retrieve a font resource - also acquire a device font |
243 | 232 |
to avoid repeated font allocations later" |
78 | 233 |
|
234 |
^ self deviceResourceAt:aKey default:nil |
|
235 |
! |
|
236 |
||
237 |
fontAt:aKey default:default |
|
7402 | 238 |
"retrieve a font resource - also acquire a device font |
78 | 239 |
to avoid repeated font allocations later" |
240 |
||
241 |
^ self deviceResourceAt:aKey default:default |
|
242 |
! |
|
243 |
||
72 | 244 |
is3D |
245 |
is3D isNil ifTrue:[ |
|
246 |
is3D := self at:#is3D default:false. |
|
53 | 247 |
]. |
72 | 248 |
^ is3D |
53 | 249 |
! |
250 |
||
72 | 251 |
name |
252 |
name isNil ifTrue:[ |
|
253 |
name := self at:#name default:'noname'. |
|
53 | 254 |
]. |
72 | 255 |
^ name |
2775 | 256 |
! |
257 |
||
258 |
viewGrey |
|
259 |
viewGrey isNil ifTrue:[ |
|
260 |
viewGrey := self at:#viewGrey default:nil. |
|
261 |
]. |
|
262 |
^ viewGrey |
|
243 | 263 |
! ! |
53 | 264 |
|
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
265 |
!ViewStyle methodsFor:'error handling'! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
266 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
267 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
268 |
"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
|
269 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
270 |
fileReadFailed := true. |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
271 |
^ self |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
272 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
273 |
"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
|
274 |
! ! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
275 |
|
3678 | 276 |
!ViewStyle methodsFor:'queries'! |
277 |
||
278 |
isWindowsStyle |
|
279 |
"answer true if this is a MS-Windows style. |
|
280 |
XXX Currently we simply check the name" |
|
281 |
||
5054 | 282 |
|nm| |
283 |
||
284 |
nm := name ? self name. |
|
3678 | 285 |
|
5054 | 286 |
^ nm == #win95 |
287 |
or:[nm == #win98 |
|
288 |
or:[nm == #winXP |
|
289 |
or:[nm == #winVista ]]] |
|
4730 | 290 |
! |
291 |
||
5052
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
292 |
isWindowsVistaStyle |
7686 | 293 |
^ (name ? self name) == #winVista |
5052
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
294 |
|
7686 | 295 |
"Modified (format): / 19-11-2016 / 15:49:48 / cg" |
5052
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
296 |
! |
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
297 |
|
4730 | 298 |
isWindowsXPStyle |
299 |
"answer true if this is a MS-Windows-XP (or later) style. |
|
300 |
XXX Currently we simply check the name" |
|
301 |
||
5054 | 302 |
|nm| |
4730 | 303 |
|
5054 | 304 |
nm := name ? self name. |
305 |
||
306 |
^ nm == #winXP |
|
307 |
or:[nm == #winVista] |
|
3678 | 308 |
! ! |
309 |
||
3069 | 310 |
!ViewStyle methodsFor:'special'! |
311 |
||
312 |
newDerivedStyle |
|
313 |
"create and return a new style, which inherits from |
|
314 |
the receiver, but possibly overrides individual entries. |
|
315 |
This may be useful to give a single button some different |
|
316 |
look (in the future - read the comment in SimpleView>>viewStyle:)" |
|
317 |
||
318 |
^ self class new |
|
319 |
superPack:self; |
|
320 |
at:#is3D put:(self is3D); |
|
321 |
at:viewGrey put:(self viewGrey); |
|
322 |
yourself |
|
323 |
||
324 |
" |
|
325 |
|panel b1 b2 newStyle| |
|
326 |
||
327 |
panel := HorizontalPanelView new. |
|
328 |
panel add:(b1 := Button label:'oldStyle'). |
|
329 |
panel add:(b2 := Button label:'newStyle'). |
|
330 |
newStyle := b1 styleSheet newDerivedStyle. |
|
331 |
newStyle at:'button.activeBackgroundColor' put:Color blue. |
|
332 |
b2 styleSheet:newStyle. |
|
333 |
||
334 |
panel open |
|
335 |
" |
|
336 |
! ! |
|
337 |
||
253 | 338 |
!ViewStyle class methodsFor:'documentation'! |
339 |
||
340 |
version |
|
6920 | 341 |
^ '$Header$' |
5531 | 342 |
! |
343 |
||
344 |
version_CVS |
|
6920 | 345 |
^ '$Header$' |
253 | 346 |
! ! |
6920 | 347 |