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