author | Claus Gittinger <cg@exept.de> |
Fri, 28 Jun 2019 09:22:40 +0200 | |
changeset 6079 | c61b633da982 |
parent 6075 | 0c168e2e1937 |
child 6080 | a90e3bbb4c79 |
permissions | -rw-r--r-- |
5932 | 1 |
"{ Encoding: utf8 }" |
2 |
||
0 | 3 |
" |
4 | 4 |
COPYRIGHT (c) 1992 by Claus Gittinger |
26 | 5 |
All Rights Reserved |
0 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
2088 | 14 |
"{ Package: 'stx:libwidg2' }" |
15 |
||
4753 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
0 | 18 |
EnterBox subclass:#TextBox |
3956 | 19 |
instanceVariableNames:'textViewClass textView' |
1555 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'Views-DialogBoxes' |
|
0 | 23 |
! |
24 |
||
13 | 25 |
!TextBox class methodsFor:'documentation'! |
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
26 | 30 |
All Rights Reserved |
13 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
0 | 40 |
|
13 | 41 |
documentation |
42 |
" |
|
43 |
this class implements a pop-up box to enter some text with 2 buttons, |
|
44 |
one to cancel, another to start some action. |
|
45 |
It is basically an enterBox, but allows entering of more than one line |
|
46 |
of text. |
|
26 | 47 |
" |
48 |
! |
|
13 | 49 |
|
26 | 50 |
examples |
51 |
" |
|
1555 | 52 |
Example (using ok-action callBack): |
53 |
[exBegin] |
|
54 |
|textBox| |
|
13 | 55 |
|
1555 | 56 |
textBox := TextBox new. |
57 |
textBox title:'enter some text'. |
|
58 |
textBox action:[:text | Transcript showCR:('the entered text was:\' , text) withCRs]. |
|
59 |
textBox showAtPointer. |
|
60 |
[exEnd] |
|
61 |
||
62 |
||
63 |
Example (asking afterwards): |
|
64 |
[exBegin] |
|
65 |
|textBox| |
|
13 | 66 |
|
1555 | 67 |
textBox := TextBox new. |
68 |
textBox title:'enter some text'. |
|
69 |
textBox showAtPointer. |
|
70 |
textBox accepted ifTrue:[ |
|
71 |
Transcript showCR:'accepted text is:'. |
|
72 |
Transcript showCR:textBox contents |
|
73 |
]. |
|
74 |
[exEnd] |
|
75 |
||
76 |
Example - readonly text (useful for status display): |
|
77 |
[exBegin] |
|
78 |
|textBox| |
|
79 |
||
80 |
textBox := TextBox new. |
|
81 |
textBox initialText:('Makefile' asFilename contents). |
|
82 |
textBox title:'Makefile:'. |
|
83 |
textBox readOnly:true. |
|
84 |
textBox noCancel. |
|
85 |
textBox label:'Makefile'. |
|
86 |
textBox extent:(600@250); sizeFixed:true. |
|
87 |
textBox showAtPointer. |
|
88 |
[exEnd] |
|
13 | 89 |
" |
90 |
! ! |
|
0 | 91 |
|
1654 | 92 |
!TextBox class methodsFor:'common dialogs'! |
93 |
||
94 |
openOn:someText |
|
95 |
"open a textBox on some text, |
|
96 |
return (the possibly modified) text if accepted; nil otherwise." |
|
97 |
||
4753 | 98 |
^ self openOn:someText title:'Enter Text:' |
2088 | 99 |
|
100 |
" |
|
101 |
TextBox openOn:'hello' |
|
102 |
" |
|
103 |
! |
|
104 |
||
105 |
openOn:someText title:titleString |
|
4753 | 106 |
"open a textBox on some text, the titleString is shown above the text area as information |
2088 | 107 |
return (the possibly modified) text if accepted; nil otherwise." |
108 |
||
4753 | 109 |
^ self openOn:someText title:titleString readOnly:false |
1654 | 110 |
|
4753 | 111 |
"/ |box returnValue| |
112 |
"/ |
|
113 |
"/ box := self new. |
|
114 |
"/ box title:titleString. |
|
115 |
"/ box initialText:someText. |
|
116 |
"/ box action:[:text | returnValue := text]. |
|
117 |
"/ box showAtPointer. |
|
118 |
"/ ^ returnValue. |
|
1654 | 119 |
|
120 |
" |
|
2088 | 121 |
TextBox openOn:'hello' title:'hi there' |
4753 | 122 |
TextBox openOn:'hello' title:'hi there |
123 |
this is a very long title |
|
124 |
but only the first line is shown in the |
|
125 |
caption. |
|
126 |
' |
|
1654 | 127 |
" |
3956 | 128 |
! |
129 |
||
130 |
openOn:someText title:titleString readOnly:readOnly |
|
131 |
"open a textBox on some text, |
|
132 |
return (the possibly modified) text if accepted; nil otherwise." |
|
133 |
||
4753 | 134 |
^ self |
135 |
openOn:someText |
|
136 |
title:titleString |
|
137 |
windowTitle:nil |
|
138 |
readOnly:readOnly |
|
139 |
||
140 |
" |
|
141 |
TextBox openOn:'hello' title:'hi there' readOnly:true |
|
142 |
TextBox openOn:'hello' title:'hi there' readOnly:false |
|
143 |
" |
|
144 |
||
145 |
"Created: / 29-10-2010 / 17:10:04 / cg" |
|
146 |
! |
|
147 |
||
148 |
openOn:someText title:titleString windowTitle:windowTitle readOnly:readOnly |
|
149 |
"open a textBox on some text, the optional titleString is shown as label |
|
150 |
above the text areay. The optional windowTitle is used as title in the caption. |
|
151 |
return (the possibly modified) text if accepted; nil otherwise." |
|
152 |
||
6075 | 153 |
^ self new |
154 |
openOn:someText title:titleString windowTitle:windowTitle readOnly:readOnly |
|
3956 | 155 |
|
156 |
" |
|
4753 | 157 |
TextBox openOn:'hello' title:'hi there' windowTitle:'some Box' readOnly:true |
158 |
TextBox openOn:'hello' title:'hi there' windowTitle:'some Box' readOnly:false |
|
159 |
TextBox openOn:'hello' title:'hi there' windowTitle:nil readOnly:false |
|
160 |
TextBox openOn:'hello' title:nil windowTitle:'some Box' readOnly:false |
|
161 |
TextBox openOn:'hello' title:nil windowTitle:nil readOnly:false |
|
162 |
TextBox openOn:'hello' title:nil windowTitle:'foo' readOnly:false |
|
3956 | 163 |
" |
164 |
||
165 |
"Created: / 29-10-2010 / 17:10:04 / cg" |
|
6075 | 166 |
"Modified: / 26-06-2019 / 10:55:57 / Claus Gittinger" |
1654 | 167 |
! ! |
168 |
||
0 | 169 |
!TextBox class methodsFor:'defaults'! |
170 |
||
171 |
defaultExtent |
|
4466
7b936f52873d
Replace references to Diplay with "Screen current" - where appropriate
Stefan Vogel <sv@exept.de>
parents:
3956
diff
changeset
|
172 |
^ (Screen current pixelPerMillimeter * (120 @ 90)) rounded |
0 | 173 |
! ! |
174 |
||
1555 | 175 |
!TextBox methodsFor:'accessing'! |
176 |
||
177 |
contents |
|
5444 | 178 |
"return my contents (i.e. possibly modified text after accept)" |
1555 | 179 |
|
180 |
^ textView contents |
|
5444 | 181 |
|
182 |
"Modified (comment): / 04-02-2017 / 18:01:03 / cg" |
|
1555 | 183 |
! |
184 |
||
5932 | 185 |
contents:newText |
186 |
"set my contents" |
|
187 |
||
188 |
textView contents:newText |
|
189 |
||
190 |
"Created: / 04-11-2018 / 21:38:13 / Claus Gittinger" |
|
191 |
! |
|
192 |
||
1555 | 193 |
initialText:aString |
5444 | 194 |
"define the initial text in the texteditor" |
1555 | 195 |
|
196 |
textView contents:aString |
|
5444 | 197 |
|
198 |
"Modified (comment): / 04-02-2017 / 18:01:16 / cg" |
|
1555 | 199 |
! |
200 |
||
201 |
readOnly:aBoolean |
|
202 |
"make my text readOnly or readWrite" |
|
203 |
||
204 |
textView readOnly:aBoolean |
|
5444 | 205 |
! ! |
206 |
||
207 |
!TextBox methodsFor:'accessing-contents'! |
|
1555 | 208 |
|
209 |
textView |
|
210 |
^ textView |
|
3956 | 211 |
! |
212 |
||
213 |
textViewClass:something |
|
214 |
textViewClass := something. |
|
1555 | 215 |
! ! |
216 |
||
0 | 217 |
!TextBox methodsFor:'initialization'! |
218 |
||
219 |
initialize |
|
220 |
|space2 space3 innerWidth| |
|
221 |
||
222 |
super initialize. |
|
223 |
||
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
224 |
enterField destroy. |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
225 |
|
0 | 226 |
space2 := 2 * ViewSpacing. |
227 |
space3 := 3 * ViewSpacing. |
|
228 |
||
229 |
"kludge: preset extent to something useful since other subviews |
|
230 |
depend on it (extent blocks are not evaluated until view is realized) |
|
231 |
- avoid visible resizing when realized the first time" |
|
232 |
||
233 |
innerWidth := width - space2. |
|
234 |
||
3956 | 235 |
textView := HVScrollableView for:(textViewClass ? EditTextView) miniScrollerH:true in:self. |
0 | 236 |
textView origin:(ViewSpacing @ (space2 + labelField height)) |
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
237 |
extent:(innerWidth @ (height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
238 |
labelField height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
239 |
buttonPanel height - space3) ). |
0 | 240 |
textView origin:[ViewSpacing @ (space2 + labelField height)] |
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
241 |
extent:[(width - space2) @ (height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
242 |
labelField height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
243 |
buttonPanel height - space3) ]. |
0 | 244 |
|
54 | 245 |
self delegate:(KeyboardForwarder toView:textView scrolledView) |
0 | 246 |
|
247 |
"TextBox new showAtPointer" |
|
3956 | 248 |
|
249 |
"Modified: / 29-10-2010 / 17:14:49 / cg" |
|
6075 | 250 |
! |
251 |
||
252 |
openOn:someText title:titleString windowTitle:windowTitle readOnly:readOnly |
|
253 |
"open a textBox on some text, the optional titleString is shown as label |
|
254 |
above the text areay. The optional windowTitle is used as title in the caption. |
|
255 |
return (the possibly modified) text if accepted; nil otherwise." |
|
256 |
||
257 |
|returnValue usedWindowTitle| |
|
258 |
||
259 |
readOnly ifTrue:[ self textViewClass:TextView ]. |
|
260 |
self initialize. |
|
261 |
titleString notNil ifTrue:[ self title:titleString ]. |
|
262 |
self initialText:someText. |
|
263 |
self action:[:text | returnValue := text]. |
|
264 |
self readOnly:readOnly. |
|
265 |
readOnly ifTrue:[ self abortButton destroy ]. |
|
266 |
||
267 |
usedWindowTitle := windowTitle. |
|
268 |
usedWindowTitle isNil ifTrue:[ |
|
269 |
titleString notNil ifTrue:[ |
|
270 |
usedWindowTitle := titleString asString asStringCollection first |
|
271 |
] ifFalse:[ |
|
272 |
usedWindowTitle := readOnly ifTrue:'Value' ifFalse:'Input' |
|
273 |
]. |
|
274 |
]. |
|
275 |
self window label:usedWindowTitle. |
|
276 |
self showAtPointer. |
|
277 |
^ returnValue. |
|
278 |
||
279 |
" |
|
280 |
TextBox openOn:'hello' title:'hi there' windowTitle:'some Box' readOnly:true |
|
281 |
TextBox openOn:'hello' title:'hi there' windowTitle:'some Box' readOnly:false |
|
282 |
TextBox openOn:'hello' title:'hi there' windowTitle:nil readOnly:false |
|
283 |
TextBox openOn:'hello' title:nil windowTitle:'some Box' readOnly:false |
|
284 |
TextBox openOn:'hello' title:nil windowTitle:nil readOnly:false |
|
285 |
TextBox openOn:'hello' title:nil windowTitle:'foo' readOnly:false |
|
286 |
" |
|
287 |
||
288 |
"Created: / 26-06-2019 / 10:55:37 / Claus Gittinger" |
|
0 | 289 |
! ! |
290 |
||
26 | 291 |
!TextBox methodsFor:'queries'! |
0 | 292 |
|
5960 | 293 |
computePreferredExtent |
26 | 294 |
"return the extent needed to make everything visible" |
0 | 295 |
|
296 |
|wWanted hWanted wPanel| |
|
297 |
||
298 |
wWanted := labelField width + ViewSpacing + ViewSpacing. |
|
299 |
(wWanted > width) ifFalse:[ |
|
2618 | 300 |
wWanted := width |
0 | 301 |
]. |
302 |
wPanel := ViewSpacing * 3. |
|
303 |
buttonPanel subViews do:[:aView | |
|
2618 | 304 |
wPanel := wPanel + aView width + ViewSpacing |
0 | 305 |
]. |
306 |
wPanel > wWanted ifTrue:[ |
|
2618 | 307 |
wWanted := wPanel |
0 | 308 |
]. |
309 |
hWanted := ViewSpacing + labelField height + |
|
2618 | 310 |
ViewSpacing + textView height + |
3418
8243c6e537e0
added preferredWidth & preferredHeight
Claus Gittinger <cg@exept.de>
parents:
2618
diff
changeset
|
311 |
(ViewSpacing * 6) + buttonPanel preferredHeight + |
2618 | 312 |
ViewSpacing. |
26 | 313 |
^ (wWanted @ hWanted) |
5960 | 314 |
|
315 |
"Created: / 09-11-2018 / 20:02:29 / Claus Gittinger" |
|
0 | 316 |
! ! |
317 |
||
1555 | 318 |
!TextBox class methodsFor:'documentation'! |
0 | 319 |
|
1555 | 320 |
version |
5444 | 321 |
^ '$Header$' |
3956 | 322 |
! |
323 |
||
324 |
version_CVS |
|
5444 | 325 |
^ '$Header$' |
0 | 326 |
! ! |
4466
7b936f52873d
Replace references to Diplay with "Screen current" - where appropriate
Stefan Vogel <sv@exept.de>
parents:
3956
diff
changeset
|
327 |