author | Claus Gittinger <cg@exept.de> |
Mon, 09 Mar 2020 14:19:10 +0100 | |
changeset 6238 | 1f70ed3090a4 |
parent 6086 | 00b0df472506 |
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 |
||
6086 | 213 |
textViewClass:aClassToUseForTheTextView |
214 |
textViewClass := aClassToUseForTheTextView. |
|
215 |
||
216 |
"Modified (format): / 15-07-2019 / 16:38:11 / Claus Gittinger" |
|
1555 | 217 |
! ! |
218 |
||
0 | 219 |
!TextBox methodsFor:'initialization'! |
220 |
||
221 |
initialize |
|
222 |
super initialize. |
|
223 |
||
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
224 |
enterField destroy. |
6086 | 225 |
textView := HVScrollableView for:(textViewClass ? EditTextView) miniScrollerH:true in:self. |
226 |
"kludge: preset extent to something useful since other subviews |
|
227 |
depend on it (extent blocks are not evaluated until view is realized) |
|
228 |
- avoid visible resizing when realized the first time" |
|
229 |
self initializeTextViewLayout. |
|
230 |
||
231 |
self delegate:(KeyboardForwarder toView:textView scrolledView) |
|
232 |
||
233 |
" |
|
234 |
TextBox new showAtPointer |
|
235 |
(TextBox title:'hello') showAtPointer |
|
236 |
" |
|
237 |
||
238 |
"Modified: / 29-10-2010 / 17:14:49 / cg" |
|
239 |
"Modified (comment): / 15-07-2019 / 16:37:40 / Claus Gittinger" |
|
240 |
! |
|
241 |
||
242 |
initializeTextViewLayout |
|
243 |
|space2 space3 innerWidth labelHeight| |
|
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
244 |
|
0 | 245 |
space2 := 2 * ViewSpacing. |
246 |
space3 := 3 * ViewSpacing. |
|
247 |
||
248 |
"kludge: preset extent to something useful since other subviews |
|
249 |
depend on it (extent blocks are not evaluated until view is realized) |
|
250 |
- avoid visible resizing when realized the first time" |
|
251 |
||
252 |
innerWidth := width - space2. |
|
6086 | 253 |
labelHeight := labelField height. |
254 |
||
255 |
"/ textView origin:(ViewSpacing @ (space2 + labelField height)) |
|
256 |
"/ extent:(innerWidth @ (height - ViewSpacing - |
|
257 |
"/ labelField height - ViewSpacing - |
|
258 |
"/ buttonPanel height - space3) ). |
|
259 |
textView origin:[ViewSpacing @ (space2 + labelHeight)] |
|
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
260 |
extent:[(width - space2) @ (height - ViewSpacing - |
6086 | 261 |
labelHeight - ViewSpacing - |
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
262 |
buttonPanel height - space3) ]. |
0 | 263 |
|
6086 | 264 |
"Created: / 15-07-2019 / 16:36:41 / Claus Gittinger" |
6075 | 265 |
! |
266 |
||
267 |
openOn:someText title:titleString windowTitle:windowTitle readOnly:readOnly |
|
268 |
"open a textBox on some text, the optional titleString is shown as label |
|
269 |
above the text areay. The optional windowTitle is used as title in the caption. |
|
270 |
return (the possibly modified) text if accepted; nil otherwise." |
|
271 |
||
272 |
|returnValue usedWindowTitle| |
|
273 |
||
274 |
readOnly ifTrue:[ self textViewClass:TextView ]. |
|
275 |
self initialize. |
|
276 |
titleString notNil ifTrue:[ self title:titleString ]. |
|
277 |
self initialText:someText. |
|
278 |
self action:[:text | returnValue := text]. |
|
279 |
self readOnly:readOnly. |
|
280 |
readOnly ifTrue:[ self abortButton destroy ]. |
|
281 |
||
282 |
usedWindowTitle := windowTitle. |
|
283 |
usedWindowTitle isNil ifTrue:[ |
|
284 |
titleString notNil ifTrue:[ |
|
285 |
usedWindowTitle := titleString asString asStringCollection first |
|
286 |
] ifFalse:[ |
|
287 |
usedWindowTitle := readOnly ifTrue:'Value' ifFalse:'Input' |
|
288 |
]. |
|
289 |
]. |
|
290 |
self window label:usedWindowTitle. |
|
291 |
self showAtPointer. |
|
292 |
^ returnValue. |
|
293 |
||
294 |
" |
|
295 |
TextBox openOn:'hello' title:'hi there' windowTitle:'some Box' readOnly:true |
|
296 |
TextBox openOn:'hello' title:'hi there' windowTitle:'some Box' readOnly:false |
|
297 |
TextBox openOn:'hello' title:'hi there' windowTitle:nil readOnly:false |
|
298 |
TextBox openOn:'hello' title:nil windowTitle:'some Box' readOnly:false |
|
299 |
TextBox openOn:'hello' title:nil windowTitle:nil readOnly:false |
|
300 |
TextBox openOn:'hello' title:nil windowTitle:'foo' readOnly:false |
|
301 |
" |
|
302 |
||
303 |
"Created: / 26-06-2019 / 10:55:37 / Claus Gittinger" |
|
0 | 304 |
! ! |
305 |
||
26 | 306 |
!TextBox methodsFor:'queries'! |
0 | 307 |
|
5960 | 308 |
computePreferredExtent |
26 | 309 |
"return the extent needed to make everything visible" |
0 | 310 |
|
6080 | 311 |
|wWanted hWanted wLabel wPanel wText hText| |
0 | 312 |
|
6080 | 313 |
wLabel := labelField width + ViewSpacing + ViewSpacing. |
314 |
||
0 | 315 |
wPanel := ViewSpacing * 3. |
316 |
buttonPanel subViews do:[:aView | |
|
2618 | 317 |
wPanel := wPanel + aView width + ViewSpacing |
0 | 318 |
]. |
6080 | 319 |
|
320 |
wWanted := (width max:wPanel) max:wLabel. |
|
321 |
||
322 |
textView notNil ifTrue:[ |
|
323 |
wText := (textView scrolledView widthOfContents + 30) min:1024. |
|
324 |
hText := (textView scrolledView heightOfContents + 20) min:400. |
|
325 |
wWanted := wWanted max:wText. |
|
0 | 326 |
]. |
6080 | 327 |
|
0 | 328 |
hWanted := ViewSpacing + labelField height + |
6080 | 329 |
ViewSpacing + hText + |
3418
8243c6e537e0
added preferredWidth & preferredHeight
Claus Gittinger <cg@exept.de>
parents:
2618
diff
changeset
|
330 |
(ViewSpacing * 6) + buttonPanel preferredHeight + |
2618 | 331 |
ViewSpacing. |
26 | 332 |
^ (wWanted @ hWanted) |
5960 | 333 |
|
334 |
"Created: / 09-11-2018 / 20:02:29 / Claus Gittinger" |
|
6080 | 335 |
"Modified: / 28-06-2019 / 11:06:25 / Claus Gittinger" |
0 | 336 |
! ! |
337 |
||
1555 | 338 |
!TextBox class methodsFor:'documentation'! |
0 | 339 |
|
1555 | 340 |
version |
5444 | 341 |
^ '$Header$' |
3956 | 342 |
! |
343 |
||
344 |
version_CVS |
|
5444 | 345 |
^ '$Header$' |
0 | 346 |
! ! |
4466
7b936f52873d
Replace references to Diplay with "Screen current" - where appropriate
Stefan Vogel <sv@exept.de>
parents:
3956
diff
changeset
|
347 |