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