author | Claus Gittinger <cg@exept.de> |
Tue, 07 May 2019 13:13:22 +0200 | |
changeset 6047 | 80dad68e23a2 |
parent 5960 | d150862d8ea3 |
child 6075 | 0c168e2e1937 |
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 |
||
153 |
|box returnValue usedWindowTitle| |
|
3956 | 154 |
|
4582 | 155 |
box := self new. |
3956 | 156 |
readOnly ifTrue:[ box textViewClass:TextView ]. |
157 |
box initialize. |
|
4753 | 158 |
titleString notNil ifTrue:[ box title:titleString ]. |
3956 | 159 |
box initialText:someText. |
160 |
box action:[:text | returnValue := text]. |
|
161 |
box readOnly:readOnly. |
|
4577 | 162 |
readOnly ifTrue:[ box abortButton destroy ]. |
4753 | 163 |
|
164 |
usedWindowTitle := windowTitle. |
|
165 |
usedWindowTitle isNil ifTrue:[ |
|
166 |
titleString notNil ifTrue:[ |
|
167 |
usedWindowTitle := titleString asString asStringCollection first |
|
168 |
] ifFalse:[ |
|
169 |
usedWindowTitle := readOnly ifTrue:'Value' ifFalse:'Input' |
|
170 |
]. |
|
171 |
]. |
|
172 |
box window label:usedWindowTitle. |
|
3956 | 173 |
box showAtPointer. |
174 |
^ returnValue. |
|
175 |
||
176 |
" |
|
4753 | 177 |
TextBox openOn:'hello' title:'hi there' windowTitle:'some Box' readOnly:true |
178 |
TextBox openOn:'hello' title:'hi there' windowTitle:'some Box' readOnly:false |
|
179 |
TextBox openOn:'hello' title:'hi there' windowTitle:nil readOnly:false |
|
180 |
TextBox openOn:'hello' title:nil windowTitle:'some Box' readOnly:false |
|
181 |
TextBox openOn:'hello' title:nil windowTitle:nil readOnly:false |
|
182 |
TextBox openOn:'hello' title:nil windowTitle:'foo' readOnly:false |
|
3956 | 183 |
" |
184 |
||
185 |
"Created: / 29-10-2010 / 17:10:04 / cg" |
|
1654 | 186 |
! ! |
187 |
||
0 | 188 |
!TextBox class methodsFor:'defaults'! |
189 |
||
190 |
defaultExtent |
|
4466
7b936f52873d
Replace references to Diplay with "Screen current" - where appropriate
Stefan Vogel <sv@exept.de>
parents:
3956
diff
changeset
|
191 |
^ (Screen current pixelPerMillimeter * (120 @ 90)) rounded |
0 | 192 |
! ! |
193 |
||
1555 | 194 |
!TextBox methodsFor:'accessing'! |
195 |
||
196 |
contents |
|
5444 | 197 |
"return my contents (i.e. possibly modified text after accept)" |
1555 | 198 |
|
199 |
^ textView contents |
|
5444 | 200 |
|
201 |
"Modified (comment): / 04-02-2017 / 18:01:03 / cg" |
|
1555 | 202 |
! |
203 |
||
5932 | 204 |
contents:newText |
205 |
"set my contents" |
|
206 |
||
207 |
textView contents:newText |
|
208 |
||
209 |
"Created: / 04-11-2018 / 21:38:13 / Claus Gittinger" |
|
210 |
! |
|
211 |
||
1555 | 212 |
initialText:aString |
5444 | 213 |
"define the initial text in the texteditor" |
1555 | 214 |
|
215 |
textView contents:aString |
|
5444 | 216 |
|
217 |
"Modified (comment): / 04-02-2017 / 18:01:16 / cg" |
|
1555 | 218 |
! |
219 |
||
220 |
readOnly:aBoolean |
|
221 |
"make my text readOnly or readWrite" |
|
222 |
||
223 |
textView readOnly:aBoolean |
|
5444 | 224 |
! ! |
225 |
||
226 |
!TextBox methodsFor:'accessing-contents'! |
|
1555 | 227 |
|
228 |
textView |
|
229 |
^ textView |
|
3956 | 230 |
! |
231 |
||
232 |
textViewClass:something |
|
233 |
textViewClass := something. |
|
1555 | 234 |
! ! |
235 |
||
0 | 236 |
!TextBox methodsFor:'initialization'! |
237 |
||
238 |
initialize |
|
239 |
|space2 space3 innerWidth| |
|
240 |
||
241 |
super initialize. |
|
242 |
||
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
243 |
enterField destroy. |
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. |
|
253 |
||
3956 | 254 |
textView := HVScrollableView for:(textViewClass ? EditTextView) miniScrollerH:true in:self. |
0 | 255 |
textView origin:(ViewSpacing @ (space2 + labelField height)) |
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
256 |
extent:(innerWidth @ (height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
257 |
labelField height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
258 |
buttonPanel height - space3) ). |
0 | 259 |
textView origin:[ViewSpacing @ (space2 + labelField height)] |
2437
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
260 |
extent:[(width - space2) @ (height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
261 |
labelField height - ViewSpacing - |
c9ba20e3367a
destroy the unused enterField
Claus Gittinger <cg@exept.de>
parents:
2088
diff
changeset
|
262 |
buttonPanel height - space3) ]. |
0 | 263 |
|
54 | 264 |
self delegate:(KeyboardForwarder toView:textView scrolledView) |
0 | 265 |
|
266 |
"TextBox new showAtPointer" |
|
3956 | 267 |
|
268 |
"Modified: / 29-10-2010 / 17:14:49 / cg" |
|
0 | 269 |
! ! |
270 |
||
26 | 271 |
!TextBox methodsFor:'queries'! |
0 | 272 |
|
5960 | 273 |
computePreferredExtent |
26 | 274 |
"return the extent needed to make everything visible" |
0 | 275 |
|
276 |
|wWanted hWanted wPanel| |
|
277 |
||
278 |
wWanted := labelField width + ViewSpacing + ViewSpacing. |
|
279 |
(wWanted > width) ifFalse:[ |
|
2618 | 280 |
wWanted := width |
0 | 281 |
]. |
282 |
wPanel := ViewSpacing * 3. |
|
283 |
buttonPanel subViews do:[:aView | |
|
2618 | 284 |
wPanel := wPanel + aView width + ViewSpacing |
0 | 285 |
]. |
286 |
wPanel > wWanted ifTrue:[ |
|
2618 | 287 |
wWanted := wPanel |
0 | 288 |
]. |
289 |
hWanted := ViewSpacing + labelField height + |
|
2618 | 290 |
ViewSpacing + textView height + |
3418
8243c6e537e0
added preferredWidth & preferredHeight
Claus Gittinger <cg@exept.de>
parents:
2618
diff
changeset
|
291 |
(ViewSpacing * 6) + buttonPanel preferredHeight + |
2618 | 292 |
ViewSpacing. |
26 | 293 |
^ (wWanted @ hWanted) |
5960 | 294 |
|
295 |
"Created: / 09-11-2018 / 20:02:29 / Claus Gittinger" |
|
0 | 296 |
! ! |
297 |
||
1555 | 298 |
!TextBox class methodsFor:'documentation'! |
0 | 299 |
|
1555 | 300 |
version |
5444 | 301 |
^ '$Header$' |
3956 | 302 |
! |
303 |
||
304 |
version_CVS |
|
5444 | 305 |
^ '$Header$' |
0 | 306 |
! ! |
4466
7b936f52873d
Replace references to Diplay with "Screen current" - where appropriate
Stefan Vogel <sv@exept.de>
parents:
3956
diff
changeset
|
307 |