author | Claus Gittinger <cg@exept.de> |
Fri, 09 Feb 1996 21:31:29 +0100 | |
changeset 343 | a7b6fbfdc453 |
parent 333 | f1c500f177d8 |
child 392 | 81343306d796 |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1990 by Claus Gittinger |
59 | 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 |
" |
|
12 |
||
13 |
EditTextView subclass:#EditField |
|
316
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
14 |
instanceVariableNames:'leaveAction enabled clickAction crAction tabAction converter |
209
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
192
diff
changeset
|
15 |
leaveKeys immediateAccept acceptOnLeave acceptOnReturn |
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
192
diff
changeset
|
16 |
lengthLimit entryCompletionBlock passwordCharacter |
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
17 |
cursorMovementWhenUpdating enableChannel autoScrollHorizontally |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
18 |
acceptOnTab' |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
19 |
classVariableNames:'DefaultForegroundColor DefaultBackgroundColor |
209
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
192
diff
changeset
|
20 |
DefaultSelectionForegroundColor DefaultSelectionBackgroundColor |
7a6db7fac566
dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents:
192
diff
changeset
|
21 |
DefaultFont' |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
22 |
poolDictionaries:'' |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
23 |
category:'Views-Text' |
0 | 24 |
! |
25 |
||
19 | 26 |
!EditField class methodsFor:'documentation'! |
27 |
||
38 | 28 |
copyright |
29 |
" |
|
30 |
COPYRIGHT (c) 1990 by Claus Gittinger |
|
59 | 31 |
All Rights Reserved |
38 | 32 |
|
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
! |
|
41 |
||
19 | 42 |
documentation |
43 |
" |
|
38 | 44 |
an editable text-field. Realized by using an EditTextView, |
45 |
and forcing its size to 1 line - disabling cursor movement |
|
46 |
in the vertical direction. |
|
121 | 47 |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
48 |
Basically, an editField is an editor for a single line text, |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
49 |
and provides the usual access protocol as defined in its superClasses |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
50 |
(especially: #contents / #contents:). |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
51 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
52 |
The above underlying internal mechanism can be used for fields which |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
53 |
are passive; i.e. into which text can be entered and the value (string) |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
54 |
is extracted actively by someone else. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
55 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
56 |
accepting: |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
57 |
The opposite way to use editFields is to connect them to a model |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
58 |
and let the field notify changes to it. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
59 |
This notification is called ``accepting''. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
60 |
Unless accepted, the models value is not updated from the editFields contents |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
61 |
this default is the normal operation and way things should work, since most |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
62 |
uses of editFields are not interrested in every individual change |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
63 |
(i.e. getting each keyStroke when a long number is entered). |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
64 |
The default behavior is to ``accept'' when either return or a cursorUp/Down |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
65 |
key is pressed in a field. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
66 |
However, the field can setup to accept/not accept on leave, on return |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
67 |
or on each individual key input. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
68 |
See the methods #acceptOnLeave: / #acceptOnReturn: / #immediateAccept. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
69 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
70 |
In addition, the set of keys which are considered ``leaveKeys'' can be |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
71 |
specified by #leaveKeys: (in case you need keys other than Return, CursorUp/Down). |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
72 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
73 |
models value vs. field contents: |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
74 |
Although the field internally keeps its contents as some string object, |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
75 |
the application may prefer to think of numbers, floats, yes/no values etc. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
76 |
To support this, a converter may defined, which is responsible for conversion of |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
77 |
strings to/from the models domain value. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
78 |
If present (i.e. nonNil), the converter is asked to convert a string to the models |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
79 |
domain with #readValueFrom:aString and vice versa, a value to a string by #printStringFor:. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
80 |
The PrintConverter class already provides a number of standard conversions, see the examples. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
81 |
To access a converted value directly (i.e. not via the model), use #editValue. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
82 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
83 |
grouping: |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
84 |
Individual fields do not know about being included in a group. This must be arranged on the |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
85 |
outside, by placing multiple fields into an EnterFieldGroup. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
86 |
This groupObject keeps a reference to one active field, and forwards input from any other |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
87 |
field to the active one. Also have a look at the examples for this. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
88 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
89 |
input completion: |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
90 |
To support input completion (i.e. filename completion, classname completion etc.), |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
91 |
a completionBlock can be defined which (if non-nil) is evaluated when the completion-key |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
92 |
is pressed and its value is taken as the new field-contents. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
93 |
The physical completion-key is the Tab key (this one cannot be defined by |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
94 |
the keyboardTranslation mechanism, since that would disable the Tab-key on regular text views. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
95 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
96 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
97 |
|
121 | 98 |
Instance variables: |
99 |
||
100 |
leaveAction <Block | nil> if non-nil, this is evaluated with |
|
101 |
the key (#Return, #CursorUp etc.) when |
|
102 |
the field is left via keyboard keys. |
|
103 |
(fieldGroups use this to decide which |
|
104 |
field has to be enabled next) |
|
105 |
||
106 |
enabled <Boolean> if false, input is ignored. |
|
107 |
||
316
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
108 |
clickAction <Block | nil> action performed if the field is |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
109 |
clicked upon. |
125 | 110 |
(this is used by the group to |
111 |
set the active field to the clicked upon field) |
|
121 | 112 |
|
113 |
crAction <Block | nil> if non-nil, keyboard input of a cr are not |
|
114 |
handled specially, instead this block is evaluated |
|
115 |
(however, this block can perform additional checks and send |
|
116 |
a #accept then) |
|
117 |
||
118 |
tabAction <Block | nil> if non-nil, keyboard input of a tab character |
|
119 |
is not entered into the text, instead this block |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
120 |
is evaluated. Also, no input completion is performed if |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
121 |
tabAction is nonNil. |
121 | 122 |
|
123 |
converter <PrintConverter | nil> if non-nil, this is supposed to convert between |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
124 |
the object and its printed representation and vice versa. |
121 | 125 |
Defaults to nil i.e. assume that strings are edited. |
126 |
||
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
127 |
leaveKeys <Collection> keys which are interpreted as 'leaving the field' |
122 | 128 |
|
125 | 129 |
immediateAccept <Boolean> if true, every change of the text is immediately |
130 |
forwarded to the model/acceptBlock. If false, |
|
131 |
the changed value is only stored in the model |
|
132 |
if the field is left or accepted. |
|
133 |
Default is false. |
|
122 | 134 |
|
135 |
acceptOnLeave <Boolean> if true, leaving the field (via cursor keys) |
|
136 |
automatically accepts the value into the model. |
|
130 | 137 |
Default is true. |
122 | 138 |
|
139 |
acceptOnReturn <Boolean> if true, leaving the field via return |
|
140 |
automatically accepts the value into the model. |
|
130 | 141 |
Default is true. |
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
142 |
|
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
143 |
acceptOnTab <Boolean> if true, the Tab key accepts and leaves the field. |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
144 |
If false, Tabs are entered into the contents field like |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
145 |
ordinary non-control keys. |
301 | 146 |
AcceptOnTab is ignored if the entryCompletion block is nonNil. |
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
147 |
Default is true. |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
148 |
|
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
149 |
lengthLimit <Number> the max. number of allowed characters |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
150 |
|
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
151 |
entryCompletionBlock <BlockOrNil> if non-nil, this is evaluated to complete the entry |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
152 |
when Tab is pressed. |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
153 |
Entry completion is used with Filenamefields or in the |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
154 |
browser for classname/selector completion. |
301 | 155 |
Setting a nonNil entryCompletion disables acceptOnTab. |
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
156 |
|
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
157 |
passwordCharacter <CharacterOrNil> if non-nil, typed input is replaced by this character |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
158 |
for display. Used for secret-input fields (such as password entry). |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
159 |
Default is nil. |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
160 |
|
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
161 |
|
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
162 |
cursorMovementWhenUpdating <Symbol> defines where the cursor is to be positioned if the |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
163 |
model changes its value by some outside activity |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
164 |
(i.e. not by user input into the field). |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
165 |
Can be one of: |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
166 |
#keep / nil -> stay where it was |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
167 |
#endOfLine -> position cursor after the string |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
168 |
#beginOfLine -> position cursor to the beginning |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
169 |
The default is nil (i.e. stay where it was before). |
19 | 170 |
" |
120 | 171 |
! |
172 |
||
173 |
examples |
|
174 |
" |
|
122 | 175 |
see more examples in EnterFieldGroup>>examples. |
176 |
||
177 |
||
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
178 |
Step-by-step introduction: |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
179 |
|
120 | 180 |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
181 |
basic field in some view: |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
182 |
|
333 | 183 |
|top field| |
120 | 184 |
|
333 | 185 |
top := StandardSystemView new. |
186 |
top extent:200@100. |
|
120 | 187 |
|
333 | 188 |
field := EditField origin:0.0@0.0 in:top. |
189 |
field width:1.0. 'let its height as-is'. |
|
120 | 190 |
|
333 | 191 |
top open |
120 | 192 |
|
122 | 193 |
|
125 | 194 |
forward input in topView to the field: |
195 |
(currently, the field does not know this - therefore, |
|
196 |
its been told here ... this may change) |
|
122 | 197 |
|
333 | 198 |
|top field| |
122 | 199 |
|
333 | 200 |
top := StandardSystemView new. |
201 |
top extent:200@100. |
|
122 | 202 |
|
333 | 203 |
field := EditField origin:0.0@0.0 in:top. |
204 |
field width:1.0. 'let its height as-is'. |
|
122 | 205 |
|
333 | 206 |
top delegate:(KeyboardForwarder toView:field). |
207 |
field hasKeyboardFocus:true. |
|
208 |
top open |
|
122 | 209 |
|
210 |
||
125 | 211 |
to make it look better: set some inset: |
120 | 212 |
|
333 | 213 |
|top field spacing| |
120 | 214 |
|
333 | 215 |
top := StandardSystemView new. |
216 |
top extent:200@100. |
|
120 | 217 |
|
333 | 218 |
spacing := View viewSpacing. |
219 |
field := EditField origin:(0.0 @ spacing) in:top. |
|
220 |
field width:1.0. 'let its height as-is'. |
|
221 |
field leftInset:spacing; rightInset:spacing. |
|
120 | 222 |
|
333 | 223 |
top open |
120 | 224 |
|
122 | 225 |
|
120 | 226 |
give it an initial contents: |
227 |
||
333 | 228 |
|top field| |
120 | 229 |
|
333 | 230 |
top := StandardSystemView new. |
231 |
top extent:200@100. |
|
120 | 232 |
|
333 | 233 |
field := EditField origin:(0.0 @ 0@0) in:top. |
234 |
field width:1.0. |
|
120 | 235 |
|
333 | 236 |
field editValue:'hello world'. |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
237 |
|
333 | 238 |
top open |
120 | 239 |
|
122 | 240 |
|
125 | 241 |
have it preselected: |
120 | 242 |
|
333 | 243 |
|top field| |
120 | 244 |
|
333 | 245 |
top := StandardSystemView new. |
246 |
top extent:200@100. |
|
120 | 247 |
|
333 | 248 |
field := EditField origin:(0.0 @ 0.0) in:top. |
249 |
field width:1.0. |
|
250 |
field editValue:'hello world' selected:true. |
|
120 | 251 |
|
333 | 252 |
top open |
120 | 253 |
|
122 | 254 |
|
120 | 255 |
have part of it preselected: |
256 |
||
333 | 257 |
|top field| |
120 | 258 |
|
333 | 259 |
top := StandardSystemView new. |
260 |
top extent:200@100. |
|
120 | 261 |
|
333 | 262 |
field := EditField origin:(0.0 @ 0.0) in:top. |
263 |
field width:1.0. |
|
120 | 264 |
|
333 | 265 |
field editValue:'hello world'. |
266 |
field selectFromCharacterPosition:1 to:5. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
267 |
|
333 | 268 |
top open |
120 | 269 |
|
122 | 270 |
|
125 | 271 |
set a size limit: |
272 |
||
333 | 273 |
|top field| |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
274 |
|
333 | 275 |
top := StandardSystemView new. |
276 |
top extent:200@100. |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
277 |
|
333 | 278 |
field := EditField origin:(0.0 @ 0.0) in:top. |
279 |
field width:1.0. |
|
280 |
field editValue:'hello'. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
281 |
|
333 | 282 |
field maxChars:8. |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
283 |
|
333 | 284 |
top open |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
285 |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
286 |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
287 |
set a size limit, initial width and stop it from scrolling |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
288 |
notice: you may prefer a constant-pitch font (such as courier): |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
289 |
|
333 | 290 |
|top field| |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
291 |
|
333 | 292 |
top := StandardSystemView new. |
293 |
top extent:200@100. |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
294 |
|
333 | 295 |
field := EditField origin:(0.0 @ 0.0) in:top. |
296 |
field innerWidth:(field font widthOf:'00000000'). |
|
297 |
field editValue:'12345678'. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
298 |
|
333 | 299 |
field maxChars:8. |
300 |
field autoScroll:false. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
301 |
|
333 | 302 |
top open |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
303 |
|
125 | 304 |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
305 |
enable / disable: |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
306 |
|
333 | 307 |
|top panel check field ena| |
308 |
||
309 |
top := StandardSystemView new. |
|
310 |
top extent:200@100. |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
311 |
|
333 | 312 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
313 |
panel borderWidth:0. |
|
314 |
panel horizontalLayout:#left. |
|
315 |
panel horizontalInset:View viewSpacing. |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
316 |
|
333 | 317 |
check := CheckBox label:'enable' in:panel. |
318 |
check turnOn. |
|
319 |
check action:[:onOff | onOff ifTrue:[field enable] ifFalse:[field disable]]. |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
320 |
|
333 | 321 |
panel add:(View new height:30; borderWidth:0). |
125 | 322 |
|
333 | 323 |
field := EditField in:panel. |
324 |
field width:1.0. |
|
325 |
field editValue:'hello'. |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
326 |
|
333 | 327 |
top open |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
328 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
329 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
330 |
enable / disable using a channel: |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
331 |
|
333 | 332 |
|top panel check field ena| |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
333 |
|
333 | 334 |
top := StandardSystemView new. |
335 |
top extent:200@100. |
|
125 | 336 |
|
333 | 337 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
338 |
panel borderWidth:0. |
|
339 |
panel horizontalLayout:#left. |
|
340 |
panel horizontalInset:View viewSpacing. |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
341 |
|
333 | 342 |
ena := true asValue. |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
343 |
|
333 | 344 |
check := CheckBox label:'enable' in:panel. |
345 |
check model:ena. |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
346 |
|
333 | 347 |
panel add:(View new height:30; borderWidth:0). |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
348 |
|
333 | 349 |
field := EditField in:panel. |
350 |
field enableChannel:ena. |
|
351 |
field width:1.0. |
|
352 |
field editValue:'hello'. |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
353 |
|
333 | 354 |
top open |
125 | 355 |
|
356 |
||
121 | 357 |
use a converter: |
125 | 358 |
- numbers (default to 0): |
121 | 359 |
|
333 | 360 |
|top field| |
121 | 361 |
|
333 | 362 |
top := StandardSystemView new. |
363 |
top extent:200@100. |
|
121 | 364 |
|
333 | 365 |
field := EditField origin:0.0@ViewSpacing in:top. |
366 |
field width:1.0. |
|
367 |
field leftInset:ViewSpacing; |
|
368 |
rightInset:ViewSpacing. |
|
121 | 369 |
|
333 | 370 |
field converter:(PrintConverter new initForNumber). |
371 |
field editValue:1234. |
|
372 |
field acceptAction:[:value | Transcript showCr:value]. |
|
373 |
field crAction:[field accept. top destroy]. |
|
374 |
top open. |
|
121 | 375 |
|
376 |
- dates: |
|
377 |
||
333 | 378 |
|top field| |
121 | 379 |
|
333 | 380 |
top := StandardSystemView new. |
381 |
top extent:200@100. |
|
121 | 382 |
|
333 | 383 |
field := EditField origin:0.0@ViewSpacing in:top. |
384 |
field width:1.0. |
|
385 |
field leftInset:ViewSpacing; |
|
386 |
rightInset:ViewSpacing. |
|
121 | 387 |
|
333 | 388 |
field converter:(PrintConverter new initForDate). |
389 |
field editValue:Date today. |
|
390 |
field acceptAction:[:value | Transcript showCr:value class name , ' ' , value printString]. |
|
391 |
field crAction:[field accept. top destroy]. |
|
392 |
top open. |
|
121 | 393 |
|
122 | 394 |
|
125 | 395 |
setting immediateAccept, makes the field update with every key: |
396 |
||
397 |
- immediate accept numbers, defaulting to nil: |
|
121 | 398 |
|
333 | 399 |
|top field| |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
400 |
|
333 | 401 |
top := StandardSystemView new. |
402 |
top extent:200@100. |
|
121 | 403 |
|
333 | 404 |
field := EditField origin:0.0@ViewSpacing in:top. |
405 |
field width:1.0. |
|
406 |
field leftInset:ViewSpacing; |
|
407 |
rightInset:ViewSpacing. |
|
121 | 408 |
|
333 | 409 |
field converter:(PrintConverter new initForNumberOrNil). |
410 |
field immediateAccept:true. |
|
411 |
field editValue:1234. |
|
412 |
field acceptAction:[:value | Transcript showCr:value]. |
|
413 |
field crAction:[field accept. top destroy]. |
|
414 |
top open. |
|
121 | 415 |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
416 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
417 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
418 |
grouping multiple fields, and forward keyPres from the outer view to the active field |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
419 |
(i.e. actually: to the group): |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
420 |
|
333 | 421 |
|top field1 field2 field3 group| |
121 | 422 |
|
122 | 423 |
|
333 | 424 |
top := StandardSystemView new. |
425 |
top extent:200@100. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
426 |
|
333 | 427 |
field1 := EditField origin:(0.0 @ 0.0) in:top. |
428 |
field1 width:1.0. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
429 |
|
333 | 430 |
field2 := EditField origin:(0.0 @ 0.0) in:top. |
431 |
field2 width:0.5. |
|
432 |
field2 topInset:(field1 height); bottomInset:(field1 height negated). |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
433 |
|
333 | 434 |
field3 := EditField origin:(0.5 @ 0.0) in:top. |
435 |
field3 width:0.5. |
|
436 |
field3 topInset:(field1 height); bottomInset:(field1 height negated). |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
437 |
|
333 | 438 |
group := EnterFieldGroup new. |
439 |
group add:field1; add:field2; add:field3. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
440 |
|
333 | 441 |
top delegate:(KeyboardForwarder to:group). |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
442 |
|
333 | 443 |
top open. |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
444 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
445 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
446 |
in addition: tell the group to close when the last field is left: |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
447 |
|
333 | 448 |
|top field1 field2 field3 group| |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
449 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
450 |
|
333 | 451 |
top := StandardSystemView new. |
452 |
top extent:200@100. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
453 |
|
333 | 454 |
field1 := EditField origin:(0.0 @ 0.0) in:top. |
455 |
field1 width:1.0. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
456 |
|
333 | 457 |
field2 := EditField origin:(0.0 @ 0.0) in:top. |
458 |
field2 width:0.5. |
|
459 |
field2 topInset:(field1 height); bottomInset:(field1 height negated). |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
460 |
|
333 | 461 |
field3 := EditField origin:(0.5 @ 0.0) in:top. |
462 |
field3 width:0.5. |
|
463 |
field3 topInset:(field1 height); bottomInset:(field1 height negated). |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
464 |
|
333 | 465 |
group := EnterFieldGroup new. |
466 |
group add:field1; add:field2; add:field3. |
|
467 |
group leaveAction:[top destroy]. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
468 |
|
333 | 469 |
top delegate:(KeyboardForwarder to:group). |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
470 |
|
333 | 471 |
top open. |
127 | 472 |
|
473 |
||
120 | 474 |
use a model: |
475 |
(see changing model value in inspector when return is pressed in the field) |
|
476 |
||
333 | 477 |
|top field model| |
120 | 478 |
|
333 | 479 |
model := 'hello world' asValue. |
120 | 480 |
|
333 | 481 |
top := StandardSystemView new. |
482 |
top extent:200@100. |
|
120 | 483 |
|
333 | 484 |
field := EditField origin:(0.0 @ 0.0) in:top. |
485 |
field width:1.0. |
|
486 |
field model:model. |
|
487 |
field acceptOnReturn:true. |
|
120 | 488 |
|
333 | 489 |
top open. |
490 |
model inspect. |
|
121 | 491 |
|
122 | 492 |
|
127 | 493 |
two views on the same model (each accepts on return): |
121 | 494 |
|
333 | 495 |
|top1 top2 field1 field2 model| |
121 | 496 |
|
333 | 497 |
model := 'hello world' asValue. |
121 | 498 |
|
333 | 499 |
top1 := StandardSystemView new. |
500 |
top1 extent:200@100. |
|
501 |
field1 := EditField origin:(0.0 @ 0.0) in:top1. |
|
502 |
field1 width:1.0. |
|
503 |
field1 model:model. |
|
504 |
field1 acceptOnReturn:true. |
|
505 |
top1 open. |
|
121 | 506 |
|
333 | 507 |
top2 := StandardSystemView new. |
508 |
top2 extent:200@100. |
|
509 |
field2 := EditField origin:(0.0 @ 0.0) in:top2. |
|
510 |
field2 width:1.0. |
|
511 |
field2 model:model. |
|
512 |
field2 acceptOnReturn:true. |
|
513 |
top2 open. |
|
121 | 514 |
|
127 | 515 |
two views on the same model (no accept on return): |
516 |
||
333 | 517 |
|top1 top2 field1 field2 model| |
127 | 518 |
|
333 | 519 |
model := 'hello world' asValue. |
127 | 520 |
|
333 | 521 |
top1 := StandardSystemView new. |
522 |
top1 extent:200@100. |
|
523 |
field1 := EditField origin:(0.0 @ 0.0) in:top1. |
|
524 |
field1 width:1.0. |
|
525 |
field1 model:model; acceptOnReturn:false. |
|
526 |
top1 open. |
|
127 | 527 |
|
333 | 528 |
top2 := StandardSystemView new. |
529 |
top2 extent:200@100. |
|
530 |
field2 := EditField origin:(0.0 @ 0.0) in:top2. |
|
531 |
field2 width:1.0. |
|
532 |
field2 model:model; acceptOnReturn:false. |
|
533 |
top2 open. |
|
127 | 534 |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
535 |
with immediate accept (every key updates the model): |
125 | 536 |
|
333 | 537 |
|top1 top2 field1 field2 model| |
125 | 538 |
|
333 | 539 |
model := 'hello world' asValue. |
125 | 540 |
|
333 | 541 |
top1 := StandardSystemView new. |
542 |
top1 extent:200@100. |
|
543 |
field1 := EditField origin:(0.0 @ 0.0) in:top1. |
|
544 |
field1 width:1.0. |
|
545 |
field1 model:model; immediateAccept:true. |
|
546 |
top1 open. |
|
125 | 547 |
|
333 | 548 |
top2 := StandardSystemView new. |
549 |
top2 extent:200@100. |
|
550 |
field2 := EditField origin:(0.0 @ 0.0) in:top2. |
|
551 |
field2 width:1.0. |
|
552 |
field2 model:model; immediateAccept:true. |
|
553 |
top2 open. |
|
122 | 554 |
|
121 | 555 |
just an example; a checkBox and an editField on the same model: |
556 |
||
333 | 557 |
|top1 top2 field1 box model| |
121 | 558 |
|
333 | 559 |
model := false asValue. |
121 | 560 |
|
333 | 561 |
top1 := StandardSystemView new. |
562 |
top1 extent:200@100. |
|
563 |
field1 := EditField origin:(0.0 @ 0.0) in:top1. |
|
564 |
field1 width:1.0. |
|
565 |
field1 converter:(PrintConverter new initForYesNo). |
|
566 |
field1 model:model. |
|
567 |
top1 open. |
|
121 | 568 |
|
333 | 569 |
top2 := StandardSystemView new. |
570 |
top2 extent:200@100. |
|
571 |
box := CheckBox on:model. |
|
572 |
box label:'on/off'. |
|
573 |
top2 add:box. |
|
574 |
top2 open. |
|
121 | 575 |
|
333 | 576 |
model inspect. |
125 | 577 |
|
578 |
||
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
579 |
multiple editFields on multiple models (value holders): |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
580 |
(the fields are connected by a group to allow tabbing) |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
581 |
|
333 | 582 |
|top panel group field1 field2 field3 box v1 v2 v3| |
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
583 |
|
333 | 584 |
v1 := true asValue. |
585 |
v2 := 'some string' asValue. |
|
586 |
v3 := 1.2 asValue. |
|
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
587 |
|
333 | 588 |
top := StandardSystemView new. |
589 |
top extent:200@100. |
|
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
590 |
|
333 | 591 |
panel := VerticalPanelView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top. |
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
592 |
|
333 | 593 |
field1 := EditField new. |
594 |
field1 width:1.0. |
|
595 |
field1 horizontalInset:ViewSpacing. |
|
596 |
field1 converter:(PrintConverter new initForYesNo). |
|
597 |
field1 model:v1. |
|
598 |
panel add:field1. |
|
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
599 |
|
333 | 600 |
field2 := EditField new. |
601 |
field2 width:1.0. |
|
602 |
field2 horizontalInset:ViewSpacing. |
|
603 |
field2 model:v2. |
|
604 |
panel add:field2. |
|
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
605 |
|
333 | 606 |
field3 := EditField new. |
607 |
field3 width:1.0. |
|
608 |
field3 horizontalInset:ViewSpacing. |
|
609 |
field3 converter:(PrintConverter new initForNumber). |
|
610 |
field3 model:v3. |
|
611 |
panel add:field3. |
|
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
612 |
|
333 | 613 |
group := EnterFieldGroup new. |
614 |
group add:field1; add:field2; add:field3. |
|
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
615 |
|
333 | 616 |
top openModal. |
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
617 |
|
333 | 618 |
Transcript showCr:v1 value. |
619 |
Transcript showCr:v2 value. |
|
620 |
Transcript showCr:v3 value. |
|
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
621 |
|
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
622 |
|
125 | 623 |
connecting fields: |
624 |
update field2 wehenever field1 is changed. |
|
625 |
(normally, the processing below (xChanged) is done in your application |
|
626 |
class, or in a complex model. For the demonstration below, we use |
|
627 |
a Plug to simulate the protocol.) |
|
628 |
||
333 | 629 |
|application top field1 field2 value1 value2| |
125 | 630 |
|
333 | 631 |
application := Plug new. |
632 |
application respondTo:#value1Changed |
|
633 |
with:[value2 value:(value1 value isNil ifTrue:[nil] |
|
634 |
ifFalse:[value1 value squared])]. |
|
125 | 635 |
|
333 | 636 |
value1 := 1 asValue. |
637 |
value2 := 1 asValue. |
|
125 | 638 |
|
333 | 639 |
top := Dialog new. |
640 |
top extent:200@200. |
|
125 | 641 |
|
333 | 642 |
(top addTextLabel:'some number:') layout:#left. |
643 |
top addVerticalSpace. |
|
125 | 644 |
|
333 | 645 |
(top addInputFieldOn:value1 tabable:false) |
646 |
converter:(PrintConverter new initForNumberOrNil); |
|
647 |
immediateAccept:true. |
|
648 |
top addVerticalSpace. |
|
125 | 649 |
|
333 | 650 |
(top addTextLabel:'squared:') layout:#left. |
651 |
top addVerticalSpace. |
|
652 |
(top addInputFieldOn:value2 tabable:false) |
|
653 |
converter:(PrintConverter new initForNumberOrNil). |
|
125 | 654 |
|
333 | 655 |
value1 onChangeSend:#value1Changed to:application. |
125 | 656 |
|
333 | 657 |
top openModeless. |
125 | 658 |
|
659 |
||
660 |
two-way connect: |
|
661 |
each field updates the other (notice, that we have to turn off |
|
662 |
onChange: notification, to avoid an endless notification cycle) |
|
663 |
||
333 | 664 |
|application top field1 field2 value1 value2| |
125 | 665 |
|
333 | 666 |
application := Plug new. |
667 |
application respondTo:#value1Changed |
|
668 |
with:[value2 retractInterestsFor:application. |
|
669 |
value2 value:(value1 value isNil ifTrue:[nil] |
|
670 |
ifFalse:[value1 value squared]). |
|
671 |
value2 onChangeSend:#value2Changed to:application. |
|
672 |
]. |
|
673 |
application respondTo:#value2Changed |
|
674 |
with:[value1 retractInterestsFor:application. |
|
675 |
value1 value:(value2 value isNil ifTrue:[nil] |
|
676 |
ifFalse:[value2 value sqrt]). |
|
677 |
value1 onChangeSend:#value1Changed to:application. |
|
678 |
]. |
|
125 | 679 |
|
333 | 680 |
value1 := 1 asValue. |
681 |
value2 := 1 asValue. |
|
125 | 682 |
|
333 | 683 |
top := Dialog new. |
684 |
top extent:200@200. |
|
125 | 685 |
|
333 | 686 |
(top addTextLabel:'some number:') layout:#left. |
687 |
top addVerticalSpace. |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
688 |
|
333 | 689 |
(top addInputFieldOn:value1 tabable:false) |
690 |
converter:(PrintConverter new initForNumberOrNil); |
|
691 |
immediateAccept:true. |
|
692 |
top addVerticalSpace. |
|
125 | 693 |
|
333 | 694 |
(top addTextLabel:'squared:') layout:#left. |
695 |
top addVerticalSpace. |
|
696 |
(top addInputFieldOn:value2 tabable:false) |
|
697 |
converter:(PrintConverter new initForNumberOrNil); |
|
698 |
immediateAccept:true. |
|
125 | 699 |
|
333 | 700 |
value1 onChangeSend:#value1Changed to:application. |
701 |
value2 onChangeSend:#value2Changed to:application. |
|
125 | 702 |
|
333 | 703 |
top openModeless. |
120 | 704 |
" |
19 | 705 |
! ! |
0 | 706 |
|
707 |
!EditField class methodsFor:'defaults'! |
|
708 |
||
125 | 709 |
defaultLeaveKeys |
128 | 710 |
"return the set of keys which are taken as leave-keys. |
711 |
If the field is in an enterFieldGroup, all leave keys will be |
|
712 |
forwarded to the group and possible step to the next/previous field. |
|
713 |
Also, if acceptOnLeave is true, leave keys will store the current |
|
714 |
value into their model (if any)" |
|
715 |
||
125 | 716 |
^ #(Return CursorUp CursorDown Next Previous Accept) |
717 |
! |
|
718 |
||
192 | 719 |
defaultNumberOfLines |
720 |
"the number of lines in the field" |
|
721 |
||
722 |
^ 1 |
|
723 |
! |
|
724 |
||
59 | 725 |
updateStyleCache |
60 | 726 |
DefaultForegroundColor := StyleSheet colorAt:'editFieldForegroundColor' default:Black. |
727 |
DefaultBackgroundColor := StyleSheet colorAt:'editFieldBackgroundColor' default:White. |
|
728 |
DefaultSelectionForegroundColor := StyleSheet colorAt:'editFieldSelectionForegroundColor' default:DefaultBackgroundColor. |
|
729 |
DefaultSelectionBackgroundColor := StyleSheet colorAt:'editFieldSelectionBackgroundColor' default:DefaultForegroundColor. |
|
730 |
DefaultFont := StyleSheet fontAt:'editFieldFont' default:nil. |
|
59 | 731 |
|
732 |
" |
|
60 | 733 |
self updateStyleCache |
59 | 734 |
" |
0 | 735 |
! ! |
736 |
||
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
737 |
!EditField methodsFor:'accepting'! |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
738 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
739 |
accept |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
740 |
"" |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
741 |
|val string| |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
742 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
743 |
super accept. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
744 |
converter notNil ifTrue:[ |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
745 |
val := self editValue. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
746 |
string := converter printStringFor:val. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
747 |
string ~= self contents ifTrue:[ |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
748 |
self contents:string. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
749 |
self flash |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
750 |
] |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
751 |
]. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
752 |
! ! |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
753 |
|
192 | 754 |
!EditField methodsFor:'accessing-behavior'! |
125 | 755 |
|
192 | 756 |
acceptOnLeave:aBoolean |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
757 |
"set/clear the acceptOnLeave flag. The default is false. |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
758 |
If true, leaving the box (via return, cursor etc) accepts my |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
759 |
string into the valueHolder (if any). |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
760 |
(actually, the set of keys can be specified with #leaveKeys:)" |
125 | 761 |
|
192 | 762 |
acceptOnLeave := aBoolean |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
763 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
764 |
"Modified: 16.12.1995 / 16:26:45 / cg" |
192 | 765 |
! |
766 |
||
767 |
acceptOnReturn:aBoolean |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
768 |
"set/clear the acceptOnReturn flag. The default is false. |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
769 |
If true, leaving the box via return accepts my |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
770 |
string into the valueHolder (if any)." |
192 | 771 |
|
772 |
acceptOnReturn := aBoolean |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
773 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
774 |
"Modified: 16.12.1995 / 16:25:34 / cg" |
125 | 775 |
! |
776 |
||
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
777 |
acceptOnTab:aBoolean |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
778 |
"set/clear the acceptOnTab flag. The default is true. |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
779 |
If true, a pressed Tab key accepts and leaves the box. |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
780 |
If false, the Tab key is treated like any normal input character |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
781 |
(i.e. inserted into the contents)." |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
782 |
|
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
783 |
acceptOnTab := aBoolean |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
784 |
|
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
785 |
"Created: 24.1.1996 / 13:13:37 / cg" |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
786 |
! |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
787 |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
788 |
autoScroll:aBoolean |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
789 |
"turn on/off automatic scrolling upon keyboard entry |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
790 |
to make the cursor visible." |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
791 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
792 |
autoScrollHorizontally := aBoolean |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
793 |
! |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
794 |
|
325 | 795 |
clickAction:aBlock |
796 |
"define an action to be evaluated when being clicked upon" |
|
797 |
||
798 |
clickAction := aBlock |
|
799 |
! |
|
800 |
||
192 | 801 |
crAction:aBlock |
802 |
"define an action to be evaluated when the return key is pressed." |
|
803 |
||
804 |
crAction := aBlock |
|
805 |
! |
|
125 | 806 |
|
192 | 807 |
cursorMovementWhenUpdating:aSymbol |
808 |
"define what should be done with the cursor, when I update |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
809 |
my contents from the model. Allowed arguments are: |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
810 |
#keep / nil -> stay where it was |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
811 |
#endOfLine -> position cursor after the string |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
812 |
#beginOfLine -> position cursor to the beginning |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
813 |
The default is #endOfLine. |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
814 |
This may be useful for fields which get new values assigned from |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
815 |
the program (i.e. not from the user)" |
125 | 816 |
|
192 | 817 |
cursorMovementWhenUpdating := aSymbol |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
818 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
819 |
"Modified: 16.12.1995 / 16:27:55 / cg" |
192 | 820 |
! |
821 |
||
822 |
disable |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
823 |
"disable the field; hide the cursor and ignore input" |
192 | 824 |
|
825 |
enabled ifTrue:[ |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
826 |
enabled := false. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
827 |
self hideCursor |
125 | 828 |
] |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
829 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
830 |
"Modified: 16.12.1995 / 16:28:05 / cg" |
125 | 831 |
! |
832 |
||
192 | 833 |
enable |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
834 |
"enable the field; show the cursor and allow input" |
127 | 835 |
|
192 | 836 |
enabled ifFalse:[ |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
837 |
enabled := true. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
838 |
super showCursor |
192 | 839 |
] |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
840 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
841 |
"Modified: 16.12.1995 / 16:28:09 / cg" |
127 | 842 |
! |
843 |
||
192 | 844 |
entryCompletionBlock:aOneArgBlock |
845 |
"define an action to be evaluated when Tab (NameCompletion) is pressed. |
|
846 |
The block gets the current contents as argument." |
|
847 |
||
848 |
entryCompletionBlock := aOneArgBlock |
|
125 | 849 |
! |
850 |
||
192 | 851 |
immediateAccept:aBoolean |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
852 |
"set/clear the immediateAccept flag. The default is false. |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
853 |
If true, every pressed key immediately accepts my |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
854 |
string into the valueHolder (if any)." |
155 | 855 |
|
192 | 856 |
immediateAccept := aBoolean |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
857 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
858 |
"Modified: 16.12.1995 / 16:25:57 / cg" |
192 | 859 |
! |
155 | 860 |
|
192 | 861 |
leaveAction:aBlock |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
862 |
"define an action to be evaluated when field is left by return or cursor keys. |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
863 |
(actually, the set of keys can be specified with #leaveKeys:)" |
192 | 864 |
|
865 |
leaveAction := aBlock |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
866 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
867 |
"Modified: 16.12.1995 / 16:26:36 / cg" |
155 | 868 |
! |
869 |
||
192 | 870 |
leaveKeys:aCollectionOfKeySymbols |
871 |
"define the set of keys which are interpreted as leaveKeys. |
|
872 |
I.e. those that make the field inactive and accept (if acceptOnLeave is true). |
|
873 |
The default is a set of #CursorUp, #CursorDown, #Next, #Prior and #Return." |
|
155 | 874 |
|
192 | 875 |
leaveKeys := aCollectionOfKeySymbols |
876 |
! |
|
155 | 877 |
|
192 | 878 |
tabAction:aBlock |
879 |
"define an action to be evaluated when the tabulator key is pressed." |
|
155 | 880 |
|
192 | 881 |
tabAction := aBlock |
187 | 882 |
! ! |
125 | 883 |
|
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
884 |
!EditField methodsFor:'accessing-channels'! |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
885 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
886 |
enableChannel |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
887 |
^ enableChannel |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
888 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
889 |
"Modified: 6.9.1995 / 13:43:33 / claus" |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
890 |
"Created: 16.12.1995 / 16:29:05 / cg" |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
891 |
"Modified: 16.12.1995 / 16:48:47 / cg" |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
892 |
! |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
893 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
894 |
enableChannel:aValueHolder |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
895 |
|wasEnabled| |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
896 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
897 |
enableChannel notNil ifTrue:[ |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
898 |
wasEnabled := enableChannel value. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
899 |
enableChannel retractInterestsFor:self. |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
900 |
] ifFalse:[ |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
901 |
wasEnabled := enabled |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
902 |
]. |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
903 |
enableChannel := aValueHolder. |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
904 |
aValueHolder onChangeSend:#enableStateChange to:self. |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
905 |
enableChannel value ~~ wasEnabled ifTrue:[ |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
906 |
self enableStateChange |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
907 |
] |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
908 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
909 |
"Created: 16.12.1995 / 16:35:32 / cg" |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
910 |
! ! |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
911 |
|
187 | 912 |
!EditField methodsFor:'accessing-contents'! |
125 | 913 |
|
187 | 914 |
contents |
915 |
"return contents as a string |
|
916 |
- redefined since EditFields hold only one line of text. |
|
917 |
In your application, please use #editValue; |
|
918 |
it uses a converter (if any) and is compatible to ST-80." |
|
919 |
||
920 |
list isNil ifTrue:[^ '']. |
|
921 |
(list size == 0) ifTrue:[^ '']. |
|
922 |
^ list at:1 |
|
923 |
! |
|
924 |
||
125 | 925 |
contents:someText |
926 |
"set the contents from a string |
|
927 |
- redefined to place the cursor to the end. |
|
928 |
In your application, please use #editValue:; |
|
929 |
it uses a converter (if any) and is compatible to ST-80." |
|
930 |
||
187 | 931 |
|newCol| |
932 |
||
933 |
newCol := cursorCol. |
|
934 |
||
125 | 935 |
super contents:someText. |
936 |
||
187 | 937 |
cursorMovementWhenUpdating == #endOfLine ifTrue:[ |
938 |
newCol := (someText size + 1). |
|
939 |
] ifFalse:[ |
|
940 |
cursorMovementWhenUpdating == #beginOfLine ifTrue:[ |
|
941 |
newCol := 1 |
|
942 |
] ifFalse:[ |
|
943 |
"/ default: stay where it was |
|
944 |
] |
|
945 |
]. |
|
125 | 946 |
|
187 | 947 |
self cursorCol:newCol. |
125 | 948 |
! |
949 |
||
192 | 950 |
converter |
951 |
"return the converter (if any)." |
|
952 |
||
953 |
^ converter |
|
954 |
! |
|
955 |
||
956 |
converter:aConverter |
|
957 |
"set the converter. If non-nil, |
|
958 |
the converter is applied to the text to convert from the string |
|
959 |
representation to the actual object value and vice versa. |
|
960 |
The default converter is nil, meaning no-conversion |
|
961 |
(i.e. the edited object is the string itself." |
|
962 |
||
963 |
converter := aConverter |
|
964 |
! |
|
965 |
||
125 | 966 |
editValue |
967 |
"if the field edits a string, this is a name alias for #contents. |
|
968 |
Otherwise, if there is a converter, return the edited string |
|
969 |
converted to an appropriate object." |
|
970 |
||
971 |
|string| |
|
972 |
||
973 |
string := self contents. |
|
279 | 974 |
string isNil ifTrue:[string := '']. |
125 | 975 |
converter isNil ifTrue:[^ string]. |
976 |
^ converter readValueFrom:string |
|
977 |
! |
|
0 | 978 |
|
125 | 979 |
editValue:aStringOrObject |
980 |
"set the contents. If there is a converter, use it to convert |
|
981 |
the object into a printed representation. |
|
982 |
Otherwise, the argument is supposed to be a string like object, |
|
983 |
and used directly (i.e. this is equivalent to sending #contents:)." |
|
984 |
||
985 |
self editValue:aStringOrObject selected:false |
|
0 | 986 |
! |
987 |
||
125 | 988 |
editValue:aStringOrObject selected:aBoolean |
989 |
"set the contents. If there is a converter, use it to convert |
|
990 |
the object into a printed representation. |
|
991 |
Otherwise, the argument is supposed to be a string like object, |
|
187 | 992 |
and used directly (i.e. this is equivalent to sending #initialText:selected:)." |
125 | 993 |
|
994 |
|string| |
|
995 |
||
996 |
converter notNil ifTrue:[ |
|
997 |
string := converter printStringFor:aStringOrObject |
|
998 |
] ifFalse:[ |
|
999 |
string := aStringOrObject. |
|
1000 |
]. |
|
1001 |
self contents:string. |
|
1002 |
aBoolean ifTrue:[ |
|
1003 |
self selectFromLine:1 col:1 toLine:1 col:string size |
|
1004 |
] |
|
1005 |
! |
|
1006 |
||
192 | 1007 |
initialText:aString |
1008 |
"set the initialText and select it" |
|
1009 |
||
1010 |
self initialText:aString selected:true |
|
1011 |
! |
|
1012 |
||
187 | 1013 |
initialText:aString selected:aBoolean |
1014 |
"set the initialText and select it if aBoolean is true" |
|
1015 |
||
1016 |
|len s| |
|
125 | 1017 |
|
187 | 1018 |
leftOffset := 0. |
1019 |
(s := aString) notNil ifTrue:[ |
|
1020 |
s := s asString |
|
1021 |
]. |
|
1022 |
self contents:s. |
|
1023 |
aBoolean ifTrue:[ |
|
1024 |
(len := s size) ~~ 0 ifTrue:[ |
|
1025 |
self selectFromLine:1 col:1 toLine:1 col:len |
|
1026 |
] |
|
1027 |
] |
|
1028 |
! |
|
1029 |
||
192 | 1030 |
list:someText |
1031 |
"low level access to the underlying contents' list. |
|
1032 |
Redefined to force text to 1 line, and notify dependents |
|
1033 |
of any changed extent-wishes (for automatic box resizing)." |
|
1034 |
||
1035 |
|l oldWidth| |
|
187 | 1036 |
|
192 | 1037 |
l := someText. |
1038 |
l size > 1 ifTrue:[ |
|
1039 |
l := OrderedCollection with:(l at:1) |
|
1040 |
]. |
|
1041 |
oldWidth := self widthOfContents. |
|
1042 |
super list:l. |
|
1043 |
self widthOfContents ~~ oldWidth ifTrue:[ |
|
1044 |
self changed:#preferredExtent |
|
1045 |
] |
|
187 | 1046 |
! |
1047 |
||
1048 |
stringValue |
|
1049 |
"alias for #contents - for compatibility with ST-80's InputField" |
|
1050 |
||
1051 |
^ self contents |
|
1052 |
! ! |
|
1053 |
||
1054 |
!EditField methodsFor:'accessing-look'! |
|
125 | 1055 |
|
155 | 1056 |
maxChars |
1057 |
"return the maximum number of characters that are allowed in |
|
1058 |
the field. |
|
1059 |
A limit of nil means: unlimited. This is the default." |
|
1060 |
||
1061 |
^ lengthLimit |
|
1062 |
||
1063 |
"Modified: 6.9.1995 / 13:43:33 / claus" |
|
1064 |
! |
|
1065 |
||
125 | 1066 |
maxChars:aNumberOrNil |
1067 |
"set the maximum number of characters that are allowed in |
|
1068 |
the field. Additional input will be ignored by the field. |
|
1069 |
A limit of nil means: unlimited. This is the default. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1070 |
If set, a lengthLimit must be defined before any contents is placed |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1071 |
into the field, because the contents is not cut when the max is |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1072 |
changed later. I.e. it should be set early after creation of the field. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1073 |
|
125 | 1074 |
This method has been renamed from #lengthLimit: for ST-80 |
1075 |
compatibility." |
|
1076 |
||
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1077 |
lengthLimit := aNumberOrNil. |
187 | 1078 |
! |
1079 |
||
192 | 1080 |
passwordCharacter |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1081 |
"return the passwordCharacter; |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1082 |
If nonNil, that one is replacing typed input |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1083 |
(for secret input)" |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1084 |
|
192 | 1085 |
^ passwordCharacter |
0 | 1086 |
|
192 | 1087 |
"Modified: 6.9.1995 / 12:25:39 / claus" |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1088 |
"Modified: 16.12.1995 / 16:24:25 / cg" |
125 | 1089 |
! |
1090 |
||
192 | 1091 |
passwordCharacter:aCharacter |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1092 |
"set the passwordCharacter; |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1093 |
If nonNil, that one is replacing typed input |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1094 |
(for secret input)" |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1095 |
|
192 | 1096 |
passwordCharacter := aCharacter |
97 | 1097 |
|
192 | 1098 |
"Modified: 6.9.1995 / 12:25:33 / claus" |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1099 |
"Modified: 16.12.1995 / 16:24:33 / cg" |
38 | 1100 |
! ! |
1101 |
||
0 | 1102 |
!EditField methodsFor:'cursor drawing'! |
1103 |
||
155 | 1104 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
1105 |
startVisLineNr to:endVisLineNr do:[:visLine | |
|
1106 |
self drawVisibleLine:visLine with:fg and:bg |
|
1107 |
] |
|
1108 |
||
1109 |
"Modified: 6.9.1995 / 12:24:29 / claus" |
|
1110 |
! |
|
1111 |
||
0 | 1112 |
showCursor |
1113 |
"make cursor visible if currently invisible - but only if this |
|
1114 |
EditField is enabled" |
|
1115 |
||
1116 |
enabled ifTrue:[super showCursor] |
|
1117 |
! ! |
|
1118 |
||
1119 |
!EditField methodsFor:'cursor movement'! |
|
1120 |
||
125 | 1121 |
cursorCol:col |
1122 |
"redefined to lock the cursor at the end, if I have a lngthLimit" |
|
1123 |
||
1124 |
|c sz| |
|
1125 |
||
1126 |
c := col. |
|
1127 |
lengthLimit notNil ifTrue:[ |
|
1128 |
sz := lengthLimit. |
|
1129 |
c > sz ifTrue:[ |
|
1130 |
c := sz+1. |
|
1131 |
] |
|
1132 |
]. |
|
1133 |
super cursorCol:c |
|
1134 |
! |
|
1135 |
||
0 | 1136 |
cursorDown |
1137 |
"catch cursor movement" |
|
1138 |
||
1139 |
(cursorVisibleLine == nLinesShown) ifFalse:[ |
|
59 | 1140 |
super cursorDown |
0 | 1141 |
] |
192 | 1142 |
! |
1143 |
||
1144 |
cursorLine:line col:col |
|
1145 |
"catch cursor movement" |
|
1146 |
||
1147 |
super cursorLine:1 col:col |
|
1148 |
! ! |
|
1149 |
||
1150 |
!EditField methodsFor:'editing'! |
|
1151 |
||
1152 |
paste:someText |
|
1153 |
"redefined to force text to 1 line" |
|
1154 |
||
1155 |
super paste:someText. |
|
1156 |
list size > 1 ifTrue:[ |
|
1157 |
self deleteFromLine:2 toLine:(list size) |
|
1158 |
] |
|
0 | 1159 |
! ! |
1160 |
||
70 | 1161 |
!EditField methodsFor:'event handling'! |
19 | 1162 |
|
192 | 1163 |
buttonPress:button x:x y:y |
1164 |
"enable myself on mouse click" |
|
1165 |
||
333 | 1166 |
enabled ifFalse:[ |
1167 |
^ self |
|
1168 |
]. |
|
1169 |
||
316
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1170 |
clickAction notNil ifTrue:[ |
333 | 1171 |
clickAction value:self |
316
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1172 |
]. |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1173 |
super buttonPress:button x:x y:y |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1174 |
|
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1175 |
"/ enabled ifFalse:[ |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1176 |
"/ enabled := true. |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1177 |
"/ super buttonPress:button x:x y:y. |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1178 |
"/ enableAction notNil ifTrue:[ |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1179 |
"/ enableAction value |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1180 |
"/ ] |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1181 |
"/ ] ifTrue:[ |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1182 |
"/ super buttonPress:button x:x y:y |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1183 |
"/ ] |
333 | 1184 |
|
1185 |
"Modified: 9.2.1996 / 01:51:20 / cg" |
|
192 | 1186 |
! |
1187 |
||
1188 |
canHandle:aKey |
|
1189 |
"return true, if the receiver would like to handle aKey |
|
1190 |
(usually from another view, when the receiver is part of |
|
1191 |
a more complex dialog box). |
|
1192 |
We do return true here, since the editfield will handle |
|
1193 |
all keys. |
|
1194 |
OBSOLETE: dont use this anymore - its a leftover for the tableWidget" |
|
1195 |
||
1196 |
^ true |
|
1197 |
! |
|
1198 |
||
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1199 |
enableStateChange |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1200 |
enableChannel value ifTrue:[ |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1201 |
self enable |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1202 |
] ifFalse:[ |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1203 |
self disable |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1204 |
]. |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1205 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1206 |
"Created: 16.12.1995 / 16:35:39 / cg" |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1207 |
"Modified: 16.12.1995 / 16:36:13 / cg" |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1208 |
! |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1209 |
|
192 | 1210 |
focusIn |
1211 |
"got the explicit focus" |
|
1212 |
||
316
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1213 |
"/ enabled ifFalse:[ |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1214 |
"/ enabled := true. |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1215 |
"/ super focusIn. |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1216 |
"/ enableAction notNil ifTrue:[ |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1217 |
"/ enableAction value |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1218 |
"/ ] |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1219 |
"/ ] ifTrue:[ |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1220 |
"/ super focusIn |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1221 |
"/ ]. |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1222 |
^ super focusIn |
192 | 1223 |
! |
1224 |
||
125 | 1225 |
keyPress:key x:x y:y |
1226 |
"if keyHandler is defined, pass input; otherwise check for leave |
|
1227 |
keys" |
|
1228 |
||
132 | 1229 |
<resource: #keyboard (#DeleteLine #EndOfText)> |
1230 |
||
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1231 |
|leave xCol newOffset newWidth s| |
125 | 1232 |
|
1233 |
enabled ifFalse:[ |
|
325 | 1234 |
^ self |
125 | 1235 |
]. |
1236 |
||
1237 |
(key == #DeleteLine) ifTrue:[ |
|
325 | 1238 |
Smalltalk at:#CopyBuffer put:(self contents). |
1239 |
self contents:''. ^ self |
|
125 | 1240 |
]. |
19 | 1241 |
|
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
1242 |
leave := leaveKeys includes:key. |
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
1243 |
|
125 | 1244 |
(key == #Tab) ifTrue:[ |
325 | 1245 |
tabAction notNil ifTrue:[tabAction value. ^ self]. |
1246 |
entryCompletionBlock notNil ifTrue:[ |
|
1247 |
s := self contents. |
|
1248 |
s isNil ifTrue:[ |
|
1249 |
s := '' |
|
1250 |
] ifFalse:[ |
|
1251 |
s := s asString |
|
1252 |
]. |
|
1253 |
entryCompletionBlock value:s. ^ self |
|
1254 |
] ifFalse:[ |
|
1255 |
acceptOnTab ifTrue:[ |
|
1256 |
leave := true |
|
1257 |
] |
|
1258 |
]. |
|
1259 |
^ super keyPress:key x:x y:y |
|
125 | 1260 |
]. |
1261 |
(key == #Return) ifTrue:[ |
|
325 | 1262 |
crAction notNil ifTrue:[crAction value. ^ self]. |
125 | 1263 |
]. |
1264 |
leave ifTrue:[ |
|
325 | 1265 |
((key == #Return and:[acceptOnReturn]) |
1266 |
or:[(key == #Tab and:[acceptOnTab]) |
|
1267 |
or:[key ~~ #Return and:[acceptOnLeave]]]) ifTrue:[ |
|
1268 |
self accept. |
|
1269 |
]. |
|
279 | 1270 |
|
325 | 1271 |
leaveAction notNil ifTrue:[ |
1272 |
^ leaveAction value:key |
|
1273 |
]. |
|
125 | 1274 |
|
325 | 1275 |
x >= 0 ifTrue:[ |
1276 |
" |
|
1277 |
let superview know about the leave ... |
|
1278 |
This is a temporary kludge for the tableWidget - |
|
1279 |
it is no clean coding style. Should make the tableWidget |
|
1280 |
a proper model and handle it via the changed mechanism .... |
|
1281 |
" |
|
1282 |
(superView notNil and:[superView canHandle:key from:self]) ifTrue:[ |
|
1283 |
superView keyPress:key x:x y:y. |
|
1284 |
]. |
|
1285 |
]. |
|
1286 |
^ self |
|
19 | 1287 |
]. |
121 | 1288 |
|
125 | 1289 |
" |
1290 |
ignore some keys (if not a leaveKey) ... |
|
1291 |
" |
|
1292 |
(key == #Find) ifTrue:[^self]. |
|
1293 |
(key == #FindNext) ifTrue:[^self]. |
|
1294 |
(key == #FindPrev) ifTrue:[^self]. |
|
1295 |
(key == #GotoLine) ifTrue:[^self]. |
|
1296 |
||
1297 |
" |
|
1298 |
a normal key - let superclass's method insert it |
|
1299 |
" |
|
1300 |
super keyPress:key x:x y:y. |
|
1301 |
||
1302 |
" |
|
1303 |
for end-of-text, also move to end-of-line |
|
1304 |
" |
|
1305 |
key == #EndOfText ifTrue:[ |
|
325 | 1306 |
super keyPress:#EndOfLine x:x y:y. |
125 | 1307 |
]. |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1308 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1309 |
self resizeOrScroll. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1310 |
|
325 | 1311 |
"Modified: 1.2.1996 / 22:46:28 / cg" |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1312 |
! |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1313 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1314 |
resizeOrScroll |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1315 |
"helper for keyPress. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1316 |
Extracted for easier subclass redefinition." |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1317 |
|
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1318 |
|xCol newOffset newWidth| |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1319 |
|
125 | 1320 |
newWidth := self widthOfContents. |
1321 |
||
1322 |
" |
|
1323 |
should (& can) we resize ? |
|
1324 |
" |
|
1325 |
xCol := (self xOfCol:cursorCol inVisibleLine:cursorLine) - leftOffset. |
|
1326 |
(xCol > (width * (5/6))) ifTrue:[ |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1327 |
self changed:#preferredExtent |
125 | 1328 |
] ifFalse:[ |
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1329 |
newWidth < (width * (1/6)) ifTrue:[ |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1330 |
self changed:#preferredExtent |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1331 |
] |
125 | 1332 |
]. |
1333 |
||
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1334 |
autoScrollHorizontally ifTrue:[ |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1335 |
" |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1336 |
did someone react (i.e. has my extent changed) ? |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1337 |
(if not, we scroll horizontally) |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1338 |
" |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1339 |
xCol := (self xOfCol:cursorCol inVisibleLine:cursorLine) - leftOffset. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1340 |
(xCol > (width * (5/6))) ifTrue:[ |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1341 |
newOffset := leftOffset + (width // 2). |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1342 |
] ifFalse:[ |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1343 |
(xCol < (width * (1/6))) ifTrue:[ |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1344 |
newOffset := 0 max: leftOffset - (width // 2). |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1345 |
] ifFalse:[ |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1346 |
newOffset := leftOffset |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1347 |
] |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1348 |
]. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1349 |
newOffset ~~ leftOffset ifTrue:[ |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1350 |
self scrollHorizontalTo:newOffset. |
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1351 |
] |
125 | 1352 |
]. |
316
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1353 |
! |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1354 |
|
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1355 |
showFocus:explicit |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1356 |
"/ giving me the focus is loke clicking on me |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1357 |
"/ (tell my enterFieldGroup .... |
1e27aa926710
fixed Tab handling in enterFieldGroups;
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1358 |
|
343
a7b6fbfdc453
oops - explicit focusChange was broken
Claus Gittinger <cg@exept.de>
parents:
333
diff
changeset
|
1359 |
(enabled or:[explicit]) ifTrue:[ |
333 | 1360 |
clickAction notNil ifTrue:[clickAction value:self]. |
1361 |
self showCursor. |
|
1362 |
super showFocus:explicit |
|
1363 |
] |
|
1364 |
||
343
a7b6fbfdc453
oops - explicit focusChange was broken
Claus Gittinger <cg@exept.de>
parents:
333
diff
changeset
|
1365 |
"Modified: 9.2.1996 / 20:49:48 / cg" |
192 | 1366 |
! ! |
1367 |
||
1368 |
!EditField methodsFor:'initialization'! |
|
1369 |
||
1370 |
editMenu |
|
1371 |
|labels selectors m| |
|
1372 |
||
1373 |
labels := #( |
|
333 | 1374 |
'copy' |
1375 |
'cut' |
|
1376 |
'paste' |
|
192 | 1377 |
" |
333 | 1378 |
'replace' |
192 | 1379 |
" |
333 | 1380 |
'-' |
1381 |
'accept' |
|
1382 |
). |
|
192 | 1383 |
|
1384 |
selectors := #( |
|
333 | 1385 |
copySelection |
1386 |
cut |
|
1387 |
paste |
|
192 | 1388 |
" |
333 | 1389 |
replace |
192 | 1390 |
" |
333 | 1391 |
nil |
1392 |
accept |
|
1393 |
). |
|
192 | 1394 |
|
1395 |
m := PopUpMenu |
|
333 | 1396 |
labels:(resources array:labels) |
1397 |
selectors:selectors. |
|
192 | 1398 |
|
1399 |
self hasSelection ifFalse:[ |
|
333 | 1400 |
m disableAll:#(copySelection cut) |
1401 |
]. |
|
1402 |
enabled ifFalse:[ |
|
1403 |
m disableAll:#(cut paste accept) |
|
192 | 1404 |
]. |
1405 |
||
1406 |
^ m |
|
333 | 1407 |
|
1408 |
"Modified: 9.2.1996 / 01:50:10 / cg" |
|
19 | 1409 |
! |
0 | 1410 |
|
192 | 1411 |
initStyle |
1412 |
super initStyle. |
|
1413 |
||
1414 |
DefaultBackgroundColor notNil ifTrue:[ |
|
1415 |
bgColor := DefaultBackgroundColor on:device. |
|
1416 |
self viewBackground:bgColor. |
|
1417 |
]. |
|
1418 |
fgColor := DefaultForegroundColor. |
|
1419 |
selectionFgColor := DefaultSelectionForegroundColor. |
|
1420 |
selectionBgColor := DefaultSelectionBackgroundColor. |
|
1421 |
||
1422 |
DefaultFont notNil ifTrue:[ |
|
1423 |
font := DefaultFont on:device |
|
1424 |
] |
|
1425 |
! |
|
0 | 1426 |
|
192 | 1427 |
initialize |
1428 |
super initialize. |
|
1429 |
self height:(font height + font descent + (topMargin * 2)). |
|
1430 |
enabled := true. |
|
1431 |
fixedSize := true. |
|
290
f539121393b1
innerWidth:/innerHeight support; much more docu in editField
Claus Gittinger <cg@exept.de>
parents:
279
diff
changeset
|
1432 |
autoScrollHorizontally := true. |
192 | 1433 |
nFullLinesShown := 1. |
1434 |
nLinesShown := 1. |
|
1435 |
immediateAccept := false. |
|
298
932fa5ca44f8
added more control over tab-key behavior (acceptOnTab:); added more examples & docu
ah
parents:
290
diff
changeset
|
1436 |
acceptOnLeave := acceptOnReturn := acceptOnTab := true. |
192 | 1437 |
cursorShown := true. |
1438 |
leaveKeys := self class defaultLeaveKeys. |
|
1439 |
cursorMovementWhenUpdating := #endOfLine |
|
1440 |
! ! |
|
1441 |
||
1442 |
!EditField methodsFor:'private'! |
|
1443 |
||
1444 |
argForChangeMessage |
|
1445 |
"redefined to send use converted value (if I have one)" |
|
1446 |
||
1447 |
^ self editValue |
|
1448 |
! |
|
1449 |
||
1450 |
getListFromModel |
|
1451 |
"redefined to aquire the text via the aspectMsg - not the listMsg, |
|
1452 |
and to ignore updates resulting from my own change." |
|
1453 |
||
1454 |
" |
|
1455 |
ignore updates from my own change |
|
1456 |
" |
|
1457 |
lockUpdates ifTrue:[ |
|
1458 |
lockUpdates := false. |
|
1459 |
^ self |
|
1460 |
]. |
|
1461 |
||
1462 |
(model notNil and:[aspectMsg notNil]) ifTrue:[ |
|
1463 |
self editValue:(model perform:aspectMsg). |
|
0 | 1464 |
] |
1465 |
! |
|
1466 |
||
192 | 1467 |
startAutoScrollDown:y |
1468 |
"no vertical scrolling in editfields" |
|
1469 |
||
1470 |
^ self |
|
1471 |
! |
|
1472 |
||
1473 |
startAutoScrollUp:y |
|
1474 |
"no vertical scrolling in editfields" |
|
1475 |
||
1476 |
^ self |
|
1477 |
! |
|
0 | 1478 |
|
192 | 1479 |
textChanged |
1480 |
"this is sent by mySelf (somewhere in a superclass) whenever |
|
1481 |
my contents has changed. |
|
1482 |
A good place to add immediateAccept functionality and check for the |
|
1483 |
lengthLimit." |
|
1484 |
||
1485 |
|string c| |
|
1486 |
||
1487 |
super textChanged. |
|
1488 |
string := self contents. |
|
1489 |
lengthLimit notNil ifTrue:[ |
|
1490 |
string size > lengthLimit ifTrue:[ |
|
1491 |
c := cursorCol. |
|
1492 |
self contents:(string copyTo:lengthLimit). |
|
1493 |
self flash. |
|
1494 |
self cursorCol:c. |
|
125 | 1495 |
] |
0 | 1496 |
]. |
192 | 1497 |
immediateAccept ifTrue:[ |
1498 |
self accept |
|
1499 |
] |
|
105 | 1500 |
! |
1501 |
||
192 | 1502 |
visibleAt:visLineNr |
1503 |
"return the string at lineNr for display. |
|
1504 |
If there is a password character, return a string consisting of those only." |
|
1505 |
||
1506 |
|s| |
|
105 | 1507 |
|
192 | 1508 |
s := super visibleAt:visLineNr. |
1509 |
passwordCharacter notNil ifTrue:[ |
|
1510 |
^ String new:(s size) withAll:passwordCharacter |
|
1511 |
]. |
|
1512 |
^ s |
|
1513 |
||
1514 |
"Modified: 6.9.1995 / 12:25:06 / claus" |
|
0 | 1515 |
! ! |
125 | 1516 |
|
192 | 1517 |
!EditField methodsFor:'queries'! |
1518 |
||
1519 |
preferredExtent |
|
1520 |
"return the preferred extent of this view. |
|
1521 |
That is the width of the string plus some extra, |
|
1522 |
but not wider than half of the screen" |
|
1523 |
||
1524 |
|string w f| |
|
125 | 1525 |
|
192 | 1526 |
string := self contents. |
1527 |
(string isNil or:[string isBlank]) ifTrue:[ |
|
1528 |
string := ' ' "/ just any string is ok ^ super preferredExtent |
|
1529 |
]. |
|
1530 |
f := font on:device. |
|
1531 |
w := ((f widthOf:string) * 1.5) rounded. |
|
1532 |
w := w min:(device width // 2). |
|
231 | 1533 |
"/ ^ w @ (f height * 1.5) rounded |
1534 |
^ w @ (f height + f descent + (margin * 2)"* 1.5") rounded |
|
192 | 1535 |
|
1536 |
"Modified: 6.9.1995 / 19:24:06 / claus" |
|
1537 |
! |
|
1538 |
||
1539 |
specClass |
|
1540 |
self class == EditField ifTrue:[^ InputFieldSpec]. |
|
1541 |
^ nil |
|
125 | 1542 |
|
192 | 1543 |
"Modified: 5.9.1995 / 17:28:27 / claus" |
325 | 1544 |
! |
1545 |
||
1546 |
tabMeansNextField |
|
1547 |
"return true, if Tab character should shift focus to the next field" |
|
1548 |
||
1549 |
"if I have a completionBlock, I want my Tabs ..." |
|
1550 |
||
1551 |
^ entryCompletionBlock isNil |
|
1552 |
||
1553 |
"Created: 7.2.1996 / 19:16:38 / cg" |
|
192 | 1554 |
! ! |
1555 |
||
1556 |
!EditField methodsFor:'realization'! |
|
1557 |
||
1558 |
realize |
|
1559 |
"scroll back to beginning when realized" |
|
1560 |
leftOffset := 0. |
|
1561 |
super realize |
|
125 | 1562 |
! ! |
192 | 1563 |
|
1564 |
!EditField methodsFor:'scrolling'! |
|
1565 |
||
1566 |
makeColVisible:col inLine:line |
|
1567 |
"dont scroll for the cursor, if its behond the text and a lengthLimit |
|
1568 |
is present." |
|
1569 |
||
1570 |
lengthLimit notNil ifTrue:[ |
|
1571 |
(col == cursorCol and:[col > lengthLimit]) ifTrue:[ |
|
1572 |
^ super makeColVisible:lengthLimit inLine:line |
|
1573 |
] |
|
1574 |
]. |
|
1575 |
^ super makeColVisible:col inLine:line |
|
1576 |
||
1577 |
"Modified: 6.9.1995 / 13:57:53 / claus" |
|
1578 |
! ! |
|
1579 |
||
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1580 |
!EditField methodsFor:'selections'! |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1581 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1582 |
validateNewSelection |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1583 |
"make certain that only one line is ever selected" |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1584 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1585 |
selectionEndLine > 1 ifTrue:[ |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1586 |
selectionEndLine := 2. selectionEndCol := 0 |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1587 |
]. |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1588 |
! ! |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1589 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1590 |
!EditField class methodsFor:'documentation'! |
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1591 |
|
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1592 |
version |
343
a7b6fbfdc453
oops - explicit focusChange was broken
Claus Gittinger <cg@exept.de>
parents:
333
diff
changeset
|
1593 |
^ '$Header: /cvs/stx/stx/libwidg/EditField.st,v 1.46 1996-02-09 20:31:29 cg Exp $' |
261
afcea54bd74e
added channel-enable (needs overall cleanup)
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
1594 |
! ! |