author | Claus Gittinger <cg@exept.de> |
Thu, 03 Mar 2011 19:17:42 +0100 | |
changeset 5719 | 014212ef8765 |
parent 5531 | 188f76d043b5 |
child 5952 | 5a8e9468117a |
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 |
||
5531 | 59 |
|aFileName prefs failed nm nmInStyles 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 |
]. |
5531 | 69 |
nm isAbsolute ifFalse:[ |
70 |
nmInStyles := 'styles' asFilename / nm |
|
71 |
]. |
|
72 |
||
3678 | 73 |
prefs := self new. |
4681
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
74 |
prefs at:#name put:baseName. |
153 | 75 |
|
5531 | 76 |
nmInStyles notNil ifTrue:[ |
77 |
path := Smalltalk getResourceFileName:nmInStyles forPackage:'stx:libview'. |
|
78 |
]. |
|
79 |
path isNil ifTrue:[ |
|
80 |
path := Smalltalk getResourceFileName:nm forPackage:'stx:libview'. |
|
81 |
]. |
|
3057
5d7383ca3aef
oops - local style file (in resources) must still be found
Claus Gittinger <cg@exept.de>
parents:
3053
diff
changeset
|
82 |
path notNil ifTrue:[ |
4681
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
83 |
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
|
84 |
]. |
4681
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
85 |
failed := (prefs readFromFile:nm directory:dir) isNil. |
153 | 86 |
prefs at:#fileReadFailed put:failed. |
53 | 87 |
^ prefs |
88 |
||
72 | 89 |
" |
4681
3cd2041ea16d
#fromFile: - use (only) #getResorceFileName:forPackage
Stefan Vogel <sv@exept.de>
parents:
4289
diff
changeset
|
90 |
ViewStyle fromFile:'motif' |
3112 | 91 |
ViewStyle fromFile:'motif.style' |
92 |
ViewStyle fromFile:'normal.style' |
|
72 | 93 |
ViewStyle fromFile:'iris.style' |
3678 | 94 |
ViewStyle fromFile:'iris.style' asFilename |
72 | 95 |
" |
3052 | 96 |
|
3112 | 97 |
"Modified: / 10.12.1999 / 16:05:30 / cg" |
53 | 98 |
! ! |
99 |
||
100 |
!ViewStyle methodsFor:'accessing'! |
|
101 |
||
243 | 102 |
at:aKey |
103 |
|sCls val| |
|
104 |
||
105 |
sCls := thisContext sender receiver. |
|
106 |
sCls isBehavior ifFalse:[sCls := sCls class]. |
|
107 |
(sCls isSubclassOf:SimpleView) ifTrue:[ |
|
108 |
val := self at:(sCls name , '.' , aKey) default:nil. |
|
109 |
val notNil ifTrue:[^ val]. |
|
110 |
]. |
|
111 |
^ self at:aKey default:nil |
|
112 |
||
113 |
"Modified: 10.9.1995 / 10:59:38 / claus" |
|
114 |
! |
|
115 |
||
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
116 |
at:aKey default:default |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
117 |
"translate a string; if not present, return default. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
118 |
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
|
119 |
'fooBar' is also tried. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
120 |
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
|
121 |
'classname.itemKey' in the stylesheets." |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
122 |
|
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
123 |
|v i k2| |
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 |
(self includesKey:aKey) ifTrue:[ |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
126 |
^ (super at:aKey ifAbsent:default) value |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
127 |
]. |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
128 |
(i := aKey indexOf:$.) ~~ 0 ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
129 |
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
|
130 |
(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
|
131 |
]. |
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
132 |
^ default value |
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
133 |
|
2347
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
134 |
"Created: / 14.10.1997 / 00:21:15 / cg" |
c276691fdd72
allow for blocks in styleSheets
Claus Gittinger <cg@exept.de>
parents:
2304
diff
changeset
|
135 |
"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
|
136 |
! |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
137 |
|
243 | 138 |
colorAt:aKey |
139 |
"retrieve a color resource - also aquire a device color |
|
140 |
to avoid repeated color allocations later" |
|
141 |
||
142 |
^ self deviceResourceAt:aKey default:nil |
|
143 |
! |
|
144 |
||
145 |
colorAt:aKey default:default |
|
146 |
"retrieve a color resource - also aquire a device color |
|
147 |
to avoid repeated color allocations later" |
|
148 |
||
149 |
^ self deviceResourceAt:aKey default:default |
|
150 |
! |
|
151 |
||
78 | 152 |
deviceResourceAt:aKey default:default |
153 |
"retrieve a resource - also aquire a device version |
|
1226 | 154 |
for the default display, to avoid repeated allocations later" |
78 | 155 |
|
228 | 156 |
|aResource deviceResource device| |
78 | 157 |
|
1226 | 158 |
device := Display. |
3678 | 159 |
|
78 | 160 |
aResource := self at:aKey default:default. |
3678 | 161 |
(aResource notNil and:[device notNil]) ifTrue:[ |
162 |
deviceResource := aResource onDevice:device. |
|
163 |
deviceResource notNil ifTrue:[^ deviceResource]. |
|
78 | 164 |
]. |
1006 | 165 |
^ aResource |
1226 | 166 |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
167 |
"Modified: / 5.9.1998 / 20:25:19 / cg" |
78 | 168 |
! |
169 |
||
243 | 170 |
doesNotUnderstand:aMessage |
171 |
^ self at:(aMessage selector) default:nil |
|
78 | 172 |
! |
173 |
||
243 | 174 |
fontAt:aKey |
175 |
"retrieve a font resource - also aquire a device font |
|
176 |
to avoid repeated font allocations later" |
|
78 | 177 |
|
178 |
^ self deviceResourceAt:aKey default:nil |
|
179 |
! |
|
180 |
||
181 |
fontAt:aKey default:default |
|
182 |
"retrieve a font resource - also aquire a device font |
|
183 |
to avoid repeated font allocations later" |
|
184 |
||
185 |
^ self deviceResourceAt:aKey default:default |
|
186 |
! |
|
187 |
||
72 | 188 |
is3D |
189 |
is3D isNil ifTrue:[ |
|
190 |
is3D := self at:#is3D default:false. |
|
53 | 191 |
]. |
72 | 192 |
^ is3D |
53 | 193 |
! |
194 |
||
72 | 195 |
name |
196 |
name isNil ifTrue:[ |
|
197 |
name := self at:#name default:'noname'. |
|
53 | 198 |
]. |
72 | 199 |
^ name |
2775 | 200 |
! |
201 |
||
202 |
viewGrey |
|
203 |
viewGrey isNil ifTrue:[ |
|
204 |
viewGrey := self at:#viewGrey default:nil. |
|
205 |
]. |
|
206 |
^ viewGrey |
|
243 | 207 |
! ! |
53 | 208 |
|
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
209 |
!ViewStyle methodsFor:'error handling'! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
210 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
211 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
212 |
"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
|
213 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
214 |
fileReadFailed := true. |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
215 |
^ self |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
216 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
217 |
"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
|
218 |
! ! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
219 |
|
3678 | 220 |
!ViewStyle methodsFor:'queries'! |
221 |
||
222 |
isWindowsStyle |
|
223 |
"answer true if this is a MS-Windows style. |
|
224 |
XXX Currently we simply check the name" |
|
225 |
||
5054 | 226 |
|nm| |
227 |
||
228 |
nm := name ? self name. |
|
3678 | 229 |
|
5054 | 230 |
^ nm == #win95 |
231 |
or:[nm == #win98 |
|
232 |
or:[nm == #winXP |
|
233 |
or:[nm == #winVista ]]] |
|
4730 | 234 |
! |
235 |
||
5052
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
236 |
isWindowsVistaStyle |
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
237 |
"answer true if this is a MS-Windows-Vista (or later) style. |
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
238 |
XXX Currently we simply check the name" |
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
239 |
|
5054 | 240 |
|nm| |
5052
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
241 |
|
5054 | 242 |
nm := name ? self name. |
243 |
||
244 |
^ nm == #winVista |
|
5052
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
245 |
! |
23a19186c25d
changed #isWindowsVistaStyle
Claus Gittinger <cg@exept.de>
parents:
4730
diff
changeset
|
246 |
|
4730 | 247 |
isWindowsXPStyle |
248 |
"answer true if this is a MS-Windows-XP (or later) style. |
|
249 |
XXX Currently we simply check the name" |
|
250 |
||
5054 | 251 |
|nm| |
4730 | 252 |
|
5054 | 253 |
nm := name ? self name. |
254 |
||
255 |
^ nm == #winXP |
|
256 |
or:[nm == #winVista] |
|
3678 | 257 |
! ! |
258 |
||
3069 | 259 |
!ViewStyle methodsFor:'special'! |
260 |
||
261 |
newDerivedStyle |
|
262 |
"create and return a new style, which inherits from |
|
263 |
the receiver, but possibly overrides individual entries. |
|
264 |
This may be useful to give a single button some different |
|
265 |
look (in the future - read the comment in SimpleView>>viewStyle:)" |
|
266 |
||
267 |
^ self class new |
|
268 |
superPack:self; |
|
269 |
at:#is3D put:(self is3D); |
|
270 |
at:viewGrey put:(self viewGrey); |
|
271 |
yourself |
|
272 |
||
273 |
" |
|
274 |
|panel b1 b2 newStyle| |
|
275 |
||
276 |
panel := HorizontalPanelView new. |
|
277 |
panel add:(b1 := Button label:'oldStyle'). |
|
278 |
panel add:(b2 := Button label:'newStyle'). |
|
279 |
newStyle := b1 styleSheet newDerivedStyle. |
|
280 |
newStyle at:'button.activeBackgroundColor' put:Color blue. |
|
281 |
b2 styleSheet:newStyle. |
|
282 |
||
283 |
panel open |
|
284 |
" |
|
285 |
! ! |
|
286 |
||
253 | 287 |
!ViewStyle class methodsFor:'documentation'! |
288 |
||
289 |
version |
|
5531 | 290 |
^ '$Header: /cvs/stx/stx/libview/ViewStyle.st,v 1.35 2009-11-17 10:01:40 cg Exp $' |
291 |
! |
|
292 |
||
293 |
version_CVS |
|
294 |
^ '$Header: /cvs/stx/stx/libview/ViewStyle.st,v 1.35 2009-11-17 10:01:40 cg Exp $' |
|
253 | 295 |
! ! |