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