author | Claus Gittinger <cg@exept.de> |
Tue, 08 Sep 1998 12:02:57 +0200 | |
changeset 2304 | cbf9bb6fb83e |
parent 1925 | e4d67cc4f082 |
child 2347 | c276691fdd72 |
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 |
" |
|
12 |
||
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
13 |
'From Smalltalk/X, Version:3.2.1 on 14-oct-1997 at 11:22:01 pm' ! |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
14 |
|
243 | 15 |
ResourcePack subclass:#ViewStyle |
617 | 16 |
instanceVariableNames:'name is3D' |
17 |
classVariableNames:'' |
|
18 |
poolDictionaries:'' |
|
19 |
category:'Views-Support' |
|
53 | 20 |
! |
21 |
||
22 |
!ViewStyle class methodsFor:'documentation'! |
|
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1993 by Claus Gittinger |
|
72 | 27 |
All Rights Reserved |
53 | 28 |
|
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
instances of this class keep all view-style specific information. |
|
72 | 41 |
The current viewStyle is kept in Views-classvariable called 'StyleSheet' |
42 |
and is instantiated with 'View defaultStyle:aStyleSymbol', which reads |
|
43 |
a stylesheet from a file '<aStyleSymbol>.style' (usually in the 'resources' |
|
44 |
directory. |
|
617 | 45 |
|
46 |
[see also:] |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
47 |
View |
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
48 |
( Configuration & Customization :html: custom/TOP.html#VIEWSTYLE ) |
617 | 49 |
|
50 |
[author:] |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
51 |
Claus Gittinger |
53 | 52 |
" |
53 |
! ! |
|
54 |
||
55 |
!ViewStyle class methodsFor:'instance creation'! |
|
56 |
||
57 |
fromFile:aFileName |
|
58 |
"get the preferences definitions from a file" |
|
59 |
||
153 | 60 |
|prefs failed nm| |
53 | 61 |
|
72 | 62 |
prefs := self new. |
63 |
(aFileName endsWith:'.style') ifTrue:[ |
|
153 | 64 |
nm := aFileName copyWithoutLast:6 |
72 | 65 |
] ifFalse:[ |
153 | 66 |
nm := aFileName |
72 | 67 |
]. |
153 | 68 |
prefs at:#name put:nm. |
69 |
||
70 |
failed := (prefs readFromFile:aFileName directory:'resources') isNil. |
|
71 |
prefs at:#fileReadFailed put:failed. |
|
53 | 72 |
^ prefs |
73 |
||
72 | 74 |
" |
75 |
ViewStyle fromFile:'motif.style' |
|
76 |
ViewStyle fromFile:'normal.style' |
|
77 |
ViewStyle fromFile:'iris.style' |
|
78 |
" |
|
53 | 79 |
! ! |
80 |
||
81 |
!ViewStyle methodsFor:'accessing'! |
|
82 |
||
243 | 83 |
at:aKey |
84 |
|sCls val| |
|
85 |
||
86 |
sCls := thisContext sender receiver. |
|
87 |
sCls isBehavior ifFalse:[sCls := sCls class]. |
|
88 |
(sCls isSubclassOf:SimpleView) ifTrue:[ |
|
89 |
val := self at:(sCls name , '.' , aKey) default:nil. |
|
90 |
val notNil ifTrue:[^ val]. |
|
91 |
]. |
|
92 |
^ self at:aKey default:nil |
|
93 |
||
94 |
"Modified: 10.9.1995 / 10:59:38 / claus" |
|
95 |
! |
|
96 |
||
1925
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
97 |
at:aKey default:default |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
98 |
"translate a string; if not present, return default. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
99 |
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
|
100 |
'fooBar' is also tried. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
101 |
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
|
102 |
'classname.itemKey' in the stylesheets." |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
103 |
|
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
104 |
|v i k2| |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
105 |
|
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
106 |
(self includesKey:aKey) ifTrue:[^ super at:aKey ifAbsent:default]. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
107 |
(i := aKey indexOf:$.) ~~ 0 ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
108 |
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
|
109 |
(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
|
110 |
]. |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
111 |
^ default |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
112 |
|
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
113 |
"Created: 14.10.1997 / 00:21:15 / cg" |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
114 |
"Modified: 14.10.1997 / 00:26:48 / cg" |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
115 |
! |
e4d67cc4f082
support new viewStyle resource name format
Claus Gittinger <cg@exept.de>
parents:
1894
diff
changeset
|
116 |
|
243 | 117 |
colorAt:aKey |
118 |
"retrieve a color resource - also aquire a device color |
|
119 |
to avoid repeated color allocations later" |
|
120 |
||
121 |
^ self deviceResourceAt:aKey default:nil |
|
122 |
! |
|
123 |
||
124 |
colorAt:aKey default:default |
|
125 |
"retrieve a color resource - also aquire a device color |
|
126 |
to avoid repeated color allocations later" |
|
127 |
||
128 |
^ self deviceResourceAt:aKey default:default |
|
129 |
! |
|
130 |
||
78 | 131 |
deviceResourceAt:aKey default:default |
132 |
"retrieve a resource - also aquire a device version |
|
1226 | 133 |
for the default display, to avoid repeated allocations later" |
78 | 134 |
|
228 | 135 |
|aResource deviceResource device| |
78 | 136 |
|
1226 | 137 |
device := Display. |
78 | 138 |
aResource := self at:aKey default:default. |
228 | 139 |
aResource isNil ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
140 |
aResource := default |
228 | 141 |
]. |
78 | 142 |
aResource notNil ifTrue:[ |
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
143 |
device notNil ifTrue:[ |
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
144 |
deviceResource := aResource onDevice:device. |
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
145 |
] |
228 | 146 |
]. |
147 |
deviceResource notNil ifTrue:[ |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
148 |
^ deviceResource |
78 | 149 |
]. |
1006 | 150 |
^ aResource |
1226 | 151 |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
152 |
"Modified: / 5.9.1998 / 20:25:19 / cg" |
78 | 153 |
! |
154 |
||
243 | 155 |
doesNotUnderstand:aMessage |
156 |
^ self at:(aMessage selector) default:nil |
|
78 | 157 |
! |
158 |
||
243 | 159 |
fontAt:aKey |
160 |
"retrieve a font resource - also aquire a device font |
|
161 |
to avoid repeated font allocations later" |
|
78 | 162 |
|
163 |
^ self deviceResourceAt:aKey default:nil |
|
164 |
! |
|
165 |
||
166 |
fontAt:aKey default:default |
|
167 |
"retrieve a font resource - also aquire a device font |
|
168 |
to avoid repeated font allocations later" |
|
169 |
||
170 |
^ self deviceResourceAt:aKey default:default |
|
171 |
! |
|
172 |
||
72 | 173 |
is3D |
174 |
is3D isNil ifTrue:[ |
|
175 |
is3D := self at:#is3D default:false. |
|
53 | 176 |
]. |
72 | 177 |
^ is3D |
53 | 178 |
! |
179 |
||
72 | 180 |
name |
181 |
name isNil ifTrue:[ |
|
182 |
name := self at:#name default:'noname'. |
|
53 | 183 |
]. |
72 | 184 |
^ name |
243 | 185 |
! ! |
53 | 186 |
|
1894
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
187 |
!ViewStyle methodsFor:'error handling'! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
188 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
189 |
nonexistingFileRead |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
190 |
"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
|
191 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
192 |
fileReadFailed := true. |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
193 |
^ self |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
194 |
|
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
195 |
"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
|
196 |
! ! |
9982e96dff75
better behavior if no stylesheet is present.
Claus Gittinger <cg@exept.de>
parents:
1226
diff
changeset
|
197 |
|
253 | 198 |
!ViewStyle class methodsFor:'documentation'! |
199 |
||
200 |
version |
|
2304
cbf9bb6fb83e
use #onDevice: instead of #on:
Claus Gittinger <cg@exept.de>
parents:
1925
diff
changeset
|
201 |
^ '$Header: /cvs/stx/stx/libview/ViewStyle.st,v 1.15 1998-09-08 10:02:57 cg Exp $' |
253 | 202 |
! ! |