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