author | Stefan Vogel <sv@exept.de> |
Thu, 16 Jan 2014 15:32:28 +0100 | |
changeset 4466 | 7b936f52873d |
parent 3956 | 32c277e2d606 |
child 4577 | 29d5e55a2f07 |
permissions | -rw-r--r-- |
0 | 1 |
" |
4 | 2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
26 | 3 |
All Rights Reserved |
0 | 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 |
" |
|
2088 | 12 |
"{ Package: 'stx:libwidg2' }" |
13 |
||
0 | 14 |
EnterBox subclass:#TextBox |
3956 | 15 |
instanceVariableNames:'textViewClass textView' |
1555 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Views-DialogBoxes' |
|
0 | 19 |
! |
20 |
||
13 | 21 |
!TextBox class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
26 | 26 |
All Rights Reserved |
13 | 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 |
! |
|
0 | 36 |
|
13 | 37 |
documentation |
38 |
" |
|
39 |
this class implements a pop-up box to enter some text with 2 buttons, |
|
40 |
one to cancel, another to start some action. |
|
41 |
It is basically an enterBox, but allows entering of more than one line |
|
42 |
of text. |
|
26 | 43 |
" |
44 |
! |
|
13 | 45 |
|
26 | 46 |
examples |
47 |
" |
|
1555 | 48 |
Example (using ok-action callBack): |
49 |
[exBegin] |
|
50 |
|textBox| |
|
13 | 51 |
|
1555 | 52 |
textBox := TextBox new. |
53 |
textBox title:'enter some text'. |
|
54 |
textBox action:[:text | Transcript showCR:('the entered text was:\' , text) withCRs]. |
|
55 |
textBox showAtPointer. |
|
56 |
[exEnd] |
|
57 |
||
58 |
||
59 |
Example (asking afterwards): |
|
60 |
[exBegin] |
|
61 |
|textBox| |
|
13 | 62 |
|
1555 | 63 |
textBox := TextBox new. |
64 |
textBox title:'enter some text'. |
|
65 |
textBox showAtPointer. |
|
66 |
textBox accepted ifTrue:[ |
|
67 |
Transcript showCR:'accepted text is:'. |
|
68 |
Transcript showCR:textBox contents |
|
69 |
]. |
|
70 |
[exEnd] |
|
71 |
||
72 |
Example - readonly text (useful for status display): |
|
73 |
[exBegin] |
|
74 |
|textBox| |
|
75 |
||
76 |
textBox := TextBox new. |
|
77 |
textBox initialText:('Makefile' asFilename contents). |
|
78 |
textBox title:'Makefile:'. |
|
79 |
textBox readOnly:true. |
|
80 |
textBox noCancel. |
|
81 |
textBox label:'Makefile'. |
|
82 |
textBox extent:(600@250); sizeFixed:true. |
|
83 |
textBox showAtPointer. |
|
84 |
[exEnd] |
|
13 | 85 |
" |
86 |
! ! |
|
0 | 87 |
|
1654 | 88 |
!TextBox class methodsFor:'common dialogs'! |
89 |
||
90 |
openOn:someText |
|
91 |
"open a textBox on some text, |
|
92 |
return (the possibly modified) text if accepted; nil otherwise." |
|
93 |
||
2088 | 94 |
^ self openOn:someText title:'Enter text' |
95 |
||
96 |
" |
|
97 |
TextBox openOn:'hello' |
|
98 |
" |
|
99 |
! |
|
100 |
||
101 |
openOn:someText title:titleString |
|
102 |
"open a textBox on some text, |
|
103 |
return (the possibly modified) text if accepted; nil otherwise." |
|
104 |
||
1654 | 105 |
|box returnValue| |
106 |
||
107 |
box := self new. |
|
2088 | 108 |
box title:titleString. |
1654 | 109 |
box initialText:someText. |
110 |
box action:[:text | returnValue := text]. |
|
111 |
box showAtPointer. |
|
112 |
^ returnValue. |
|
113 |
||
114 |
" |
|
2088 | 115 |
TextBox openOn:'hello' title:'hi there' |
1654 | 116 |
" |
3956 | 117 |
! |
118 |
||
119 |
openOn:someText title:titleString readOnly:readOnly |
|
120 |
"open a textBox on some text, |
|
121 |
return (the possibly modified) text if accepted; nil otherwise." |
|
122 |
||
123 |
|box returnValue| |
|
124 |
||
125 |
box := self basicNew. |
|
126 |
readOnly ifTrue:[ box textViewClass:TextView ]. |
|
127 |
box initialize. |
|
128 |
box title:titleString. |
|
129 |
box initialText:someText. |
|
130 |
box action:[:text | returnValue := text]. |
|
131 |
box readOnly:readOnly. |
|
132 |
box showAtPointer. |
|
133 |
^ returnValue. |
|
134 |
||
135 |
" |
|
136 |
TextBox openOn:'hello' title:'hi there' readOnly:true |
|
137 |
TextBox openOn:'hello' title:'hi there' readOnly:false |
|
138 |
" |
|
139 |
||
140 |
"Created: / 29-10-2010 / 17:10:04 / cg" |
|
1654 | 141 |
! ! |
142 |
||
0 | 143 |
!TextBox class methodsFor:'defaults'! |
144 |
||
145 |
defaultExtent |
|
4466
7b936f52873d
Replace references to Diplay with "Screen current" - where appropriate
Stefan Vogel <sv@exept.de>
parents:
3956
diff
changeset
|
146 |
^ (Screen current pixelPerMillimeter * (120 @ 90)) rounded |
0 | 147 |
! ! |
148 |
||
1555 | 149 |
!TextBox methodsFor:'accessing'! |
150 |
||
151 |
contents |
|
152 |
"return my contents" |
|
153 |
||
154 |
^ textView contents |
|
155 |
! |
|
156 |
||
157 |
initialText:aString |
|
158 |
"define the initial text in the enterfield" |
|
159 |
||
160 |
textView contents:aString |
|
161 |
! |
|
162 |
||
163 |
readOnly:aBoolean |
|
164 |
"make my text readOnly or readWrite" |
|
165 |
||
166 |
textView readOnly:aBoolean |
|
167 |
! |
|
168 |
||
169 |
textView |
|
170 |
^ textView |
|
3956 | 171 |
! |
172 |
||
173 |
textViewClass:something |
|
174 |
textViewClass := something. |
|
1555 | 175 |
! ! |
176 |
||
0 | 177 |
!TextBox methodsFor:'initialization'! |
178 |
||
179 |
initialize |
|
180 |
|space2 space3 innerWidth| |
|
181 |
||
182 |
super initialize. |
|
183 |
||
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
184 |
enterField destroy. |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
185 |
|
0 | 186 |
space2 := 2 * ViewSpacing. |
187 |
space3 := 3 * ViewSpacing. |
|
188 |
||
189 |
"kludge: preset extent to something useful since other subviews |
|
190 |
depend on it (extent blocks are not evaluated until view is realized) |
|
191 |
- avoid visible resizing when realized the first time" |
|
192 |
||
193 |
innerWidth := width - space2. |
|
194 |
||
3956 | 195 |
textView := HVScrollableView for:(textViewClass ? EditTextView) miniScrollerH:true in:self. |
0 | 196 |
textView origin:(ViewSpacing @ (space2 + labelField height)) |
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
197 |
extent:(innerWidth @ (height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
198 |
labelField height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
199 |
buttonPanel height - space3) ). |
0 | 200 |
textView origin:[ViewSpacing @ (space2 + labelField height)] |
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
201 |
extent:[(width - space2) @ (height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
202 |
labelField height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
203 |
buttonPanel height - space3) ]. |
0 | 204 |
|
54 | 205 |
self delegate:(KeyboardForwarder toView:textView scrolledView) |
0 | 206 |
|
207 |
"TextBox new showAtPointer" |
|
3956 | 208 |
|
209 |
"Modified: / 29-10-2010 / 17:14:49 / cg" |
|
0 | 210 |
! ! |
211 |
||
26 | 212 |
!TextBox methodsFor:'queries'! |
0 | 213 |
|
62 | 214 |
preferredExtent |
26 | 215 |
"return the extent needed to make everything visible" |
0 | 216 |
|
217 |
|wWanted hWanted wPanel| |
|
218 |
||
3571
15340c832dd7
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3418
diff
changeset
|
219 |
"/ If I have an explicit preferredExtent.. |
15340c832dd7
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3418
diff
changeset
|
220 |
explicitExtent notNil ifTrue:[ |
15340c832dd7
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3418
diff
changeset
|
221 |
^ explicitExtent |
15340c832dd7
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3418
diff
changeset
|
222 |
]. |
15340c832dd7
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3418
diff
changeset
|
223 |
|
15340c832dd7
changed #preferredExtent - use explicitExtent instvar
Stefan Vogel <sv@exept.de>
parents:
3418
diff
changeset
|
224 |
"/ If I have a cached preferredExtent value.. |
2618 | 225 |
preferredExtent notNil ifTrue:[ |
226 |
^ preferredExtent |
|
227 |
]. |
|
0 | 228 |
wWanted := labelField width + ViewSpacing + ViewSpacing. |
229 |
(wWanted > width) ifFalse:[ |
|
2618 | 230 |
wWanted := width |
0 | 231 |
]. |
232 |
wPanel := ViewSpacing * 3. |
|
233 |
buttonPanel subViews do:[:aView | |
|
2618 | 234 |
wPanel := wPanel + aView width + ViewSpacing |
0 | 235 |
]. |
236 |
wPanel > wWanted ifTrue:[ |
|
2618 | 237 |
wWanted := wPanel |
0 | 238 |
]. |
239 |
hWanted := ViewSpacing + labelField height + |
|
2618 | 240 |
ViewSpacing + textView height + |
3418
8243c6e537e0
added preferredWidth & preferredHeight
Claus Gittinger <cg@exept.de>
parents:
2618
diff
changeset
|
241 |
(ViewSpacing * 6) + buttonPanel preferredHeight + |
2618 | 242 |
ViewSpacing. |
26 | 243 |
^ (wWanted @ hWanted) |
0 | 244 |
! ! |
245 |
||
1555 | 246 |
!TextBox class methodsFor:'documentation'! |
0 | 247 |
|
1555 | 248 |
version |
4466
7b936f52873d
Replace references to Diplay with "Screen current" - where appropriate
Stefan Vogel <sv@exept.de>
parents:
3956
diff
changeset
|
249 |
^ '$Header: /cvs/stx/stx/libwidg2/TextBox.st,v 1.22 2014-01-16 14:32:28 stefan Exp $' |
3956 | 250 |
! |
251 |
||
252 |
version_CVS |
|
4466
7b936f52873d
Replace references to Diplay with "Screen current" - where appropriate
Stefan Vogel <sv@exept.de>
parents:
3956
diff
changeset
|
253 |
^ '$Header: /cvs/stx/stx/libwidg2/TextBox.st,v 1.22 2014-01-16 14:32:28 stefan Exp $' |
0 | 254 |
! ! |
4466
7b936f52873d
Replace references to Diplay with "Screen current" - where appropriate
Stefan Vogel <sv@exept.de>
parents:
3956
diff
changeset
|
255 |