EditField.st
author Claus Gittinger <cg@exept.de>
Fri, 15 Dec 1995 14:04:06 +0100
changeset 258 ae4b8f1a6738
parent 231 014756a636e3
child 261 afcea54bd74e
permissions -rw-r--r--
interest is written with one 'r' (shame on me)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     1
"
5
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1990 by Claus Gittinger
59
450ce95a72a4 *** empty log message ***
claus
parents: 47
diff changeset
     3
	      All Rights Reserved
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     4
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    11
"
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    12
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    13
EditTextView subclass:#EditField
125
claus
parents: 122
diff changeset
    14
	 instanceVariableNames:'leaveAction enabled enableAction 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
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
    17
		cursorMovementWhenUpdating'
105
3d064ba4a0cc *** empty log message ***
claus
parents: 97
diff changeset
    18
	 classVariableNames:'DefaultForegroundColor DefaultBackgroundColor
209
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
    19
		DefaultSelectionForegroundColor DefaultSelectionBackgroundColor
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
    20
		DefaultFont'
105
3d064ba4a0cc *** empty log message ***
claus
parents: 97
diff changeset
    21
	 poolDictionaries:''
3d064ba4a0cc *** empty log message ***
claus
parents: 97
diff changeset
    22
	 category:'Views-Text'
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    23
!
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
    24
19
a696fb528758 *** empty log message ***
claus
parents: 7
diff changeset
    25
!EditField class methodsFor:'documentation'!
a696fb528758 *** empty log message ***
claus
parents: 7
diff changeset
    26
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    27
copyright
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    28
"
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    29
 COPYRIGHT (c) 1990 by Claus Gittinger
59
450ce95a72a4 *** empty log message ***
claus
parents: 47
diff changeset
    30
	      All Rights Reserved
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    31
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    32
 This software is furnished under a license and may be used
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    33
 only in accordance with the terms of that license and with the
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    35
 be provided or otherwise made available to, or used by, any
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    36
 other person.  No title to or ownership of the software is
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    37
 hereby transferred.
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    38
"
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    39
!
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    40
19
a696fb528758 *** empty log message ***
claus
parents: 7
diff changeset
    41
documentation
a696fb528758 *** empty log message ***
claus
parents: 7
diff changeset
    42
"
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    43
    an editable text-field. Realized by using an EditTextView,
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    44
    and forcing its size to 1 line - disabling cursor movement
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
    45
    in the vertical direction.
121
claus
parents: 120
diff changeset
    46
claus
parents: 120
diff changeset
    47
    Instance variables:
claus
parents: 120
diff changeset
    48
claus
parents: 120
diff changeset
    49
      leaveAction    <Block | nil>              if non-nil, this is evaluated with
claus
parents: 120
diff changeset
    50
						the key (#Return, #CursorUp etc.) when
claus
parents: 120
diff changeset
    51
						the field is left via keyboard keys.
claus
parents: 120
diff changeset
    52
						(fieldGroups use this to decide which
claus
parents: 120
diff changeset
    53
						 field has to be enabled next)
claus
parents: 120
diff changeset
    54
claus
parents: 120
diff changeset
    55
      enabled        <Boolean>                  if false, input is ignored.
claus
parents: 120
diff changeset
    56
125
claus
parents: 122
diff changeset
    57
      enableAction   <Block | nil>              action performed if the field is
claus
parents: 122
diff changeset
    58
						enabled via an explicit click.
claus
parents: 122
diff changeset
    59
						(this is used by the group to
claus
parents: 122
diff changeset
    60
						 set the active field to the clicked upon field)
121
claus
parents: 120
diff changeset
    61
claus
parents: 120
diff changeset
    62
      crAction       <Block | nil>              if non-nil, keyboard input of a cr are not
claus
parents: 120
diff changeset
    63
						handled specially, instead this block is evaluated
claus
parents: 120
diff changeset
    64
						(however, this block can perform additional checks and send
claus
parents: 120
diff changeset
    65
						 a #accept then)
claus
parents: 120
diff changeset
    66
claus
parents: 120
diff changeset
    67
      tabAction      <Block | nil>              if non-nil, keyboard input of a tab character
claus
parents: 120
diff changeset
    68
						is not entered into the text, instead this block
claus
parents: 120
diff changeset
    69
						is evaluated.
claus
parents: 120
diff changeset
    70
claus
parents: 120
diff changeset
    71
      converter      <PrintConverter | nil>     if non-nil, this is supposed to convert between
claus
parents: 120
diff changeset
    72
						the object and its printed representation.
claus
parents: 120
diff changeset
    73
						Defaults to nil i.e. assume that strings are edited.
claus
parents: 120
diff changeset
    74
claus
parents: 120
diff changeset
    75
      leaveKeys      <Collection>               keys which are interpreted as 'leving the field'
122
claus
parents: 121
diff changeset
    76
125
claus
parents: 122
diff changeset
    77
      immediateAccept   <Boolean>               if true, every change of the text is immediately
claus
parents: 122
diff changeset
    78
						forwarded to the model/acceptBlock. If false,
claus
parents: 122
diff changeset
    79
						the changed value is only stored in the model
claus
parents: 122
diff changeset
    80
						if the field is left or accepted.
claus
parents: 122
diff changeset
    81
						Default is false.
122
claus
parents: 121
diff changeset
    82
claus
parents: 121
diff changeset
    83
      acceptOnLeave  <Boolean>                  if true, leaving the field (via cursor keys)
claus
parents: 121
diff changeset
    84
						automatically accepts the value into the model.
130
claus
parents: 128
diff changeset
    85
						Default is true.
122
claus
parents: 121
diff changeset
    86
claus
parents: 121
diff changeset
    87
      acceptOnReturn <Boolean>                  if true, leaving the field via return
claus
parents: 121
diff changeset
    88
						automatically accepts the value into the model.
130
claus
parents: 128
diff changeset
    89
						Default is true.
19
a696fb528758 *** empty log message ***
claus
parents: 7
diff changeset
    90
"
120
claus
parents: 118
diff changeset
    91
!
claus
parents: 118
diff changeset
    92
claus
parents: 118
diff changeset
    93
examples 
claus
parents: 118
diff changeset
    94
"
122
claus
parents: 121
diff changeset
    95
    see more examples in EnterFieldGroup>>examples.
claus
parents: 121
diff changeset
    96
claus
parents: 121
diff changeset
    97
claus
parents: 121
diff changeset
    98
    basic field in a view:
120
claus
parents: 118
diff changeset
    99
claus
parents: 118
diff changeset
   100
	|top field|
claus
parents: 118
diff changeset
   101
claus
parents: 118
diff changeset
   102
	top := StandardSystemView new.
claus
parents: 118
diff changeset
   103
	top extent:200@100.
claus
parents: 118
diff changeset
   104
claus
parents: 118
diff changeset
   105
	field := EditField origin:0.0@0.0 in:top.
claus
parents: 118
diff changeset
   106
	field width:1.0.        'let its height as-is'.
claus
parents: 118
diff changeset
   107
claus
parents: 118
diff changeset
   108
	top open
claus
parents: 118
diff changeset
   109
122
claus
parents: 121
diff changeset
   110
125
claus
parents: 122
diff changeset
   111
    forward input in topView to the field:
claus
parents: 122
diff changeset
   112
    (currently, the field does not know this - therefore,
claus
parents: 122
diff changeset
   113
     its been told here ... this may change)
122
claus
parents: 121
diff changeset
   114
claus
parents: 121
diff changeset
   115
	|top field|
claus
parents: 121
diff changeset
   116
claus
parents: 121
diff changeset
   117
	top := StandardSystemView new.
claus
parents: 121
diff changeset
   118
	top extent:200@100.
claus
parents: 121
diff changeset
   119
claus
parents: 121
diff changeset
   120
	field := EditField origin:0.0@0.0 in:top.
claus
parents: 121
diff changeset
   121
	field width:1.0.        'let its height as-is'.
claus
parents: 121
diff changeset
   122
claus
parents: 121
diff changeset
   123
	top delegate:(KeyboardForwarder toView:field).
125
claus
parents: 122
diff changeset
   124
	field hasKeyboardFocus:true.
122
claus
parents: 121
diff changeset
   125
	top open
claus
parents: 121
diff changeset
   126
claus
parents: 121
diff changeset
   127
125
claus
parents: 122
diff changeset
   128
    to make it look better: set some inset:
120
claus
parents: 118
diff changeset
   129
claus
parents: 118
diff changeset
   130
	|top field|
claus
parents: 118
diff changeset
   131
claus
parents: 118
diff changeset
   132
	top := StandardSystemView new.
claus
parents: 118
diff changeset
   133
	top extent:200@100.
claus
parents: 118
diff changeset
   134
claus
parents: 118
diff changeset
   135
	field := EditField origin:0.0@ViewSpacing in:top.
claus
parents: 118
diff changeset
   136
	field width:1.0.        'let its height as-is'.
claus
parents: 118
diff changeset
   137
	field leftInset:ViewSpacing;
claus
parents: 118
diff changeset
   138
	      rightInset:ViewSpacing.
claus
parents: 118
diff changeset
   139
claus
parents: 118
diff changeset
   140
	top open
claus
parents: 118
diff changeset
   141
122
claus
parents: 121
diff changeset
   142
120
claus
parents: 118
diff changeset
   143
    give it an initial contents:
claus
parents: 118
diff changeset
   144
claus
parents: 118
diff changeset
   145
	|top field|
claus
parents: 118
diff changeset
   146
claus
parents: 118
diff changeset
   147
	top := StandardSystemView new.
claus
parents: 118
diff changeset
   148
	top extent:200@100.
claus
parents: 118
diff changeset
   149
claus
parents: 118
diff changeset
   150
	field := EditField origin:0.0@ViewSpacing in:top.
claus
parents: 118
diff changeset
   151
	field width:1.0.       
claus
parents: 118
diff changeset
   152
	field leftInset:ViewSpacing;
claus
parents: 118
diff changeset
   153
	      rightInset:ViewSpacing.
121
claus
parents: 120
diff changeset
   154
	field editValue:'hello world'.
120
claus
parents: 118
diff changeset
   155
claus
parents: 118
diff changeset
   156
	top open
claus
parents: 118
diff changeset
   157
122
claus
parents: 121
diff changeset
   158
125
claus
parents: 122
diff changeset
   159
    have it preselected:
120
claus
parents: 118
diff changeset
   160
claus
parents: 118
diff changeset
   161
	|top field|
claus
parents: 118
diff changeset
   162
claus
parents: 118
diff changeset
   163
	top := StandardSystemView new.
claus
parents: 118
diff changeset
   164
	top extent:200@100.
claus
parents: 118
diff changeset
   165
claus
parents: 118
diff changeset
   166
	field := EditField origin:0.0@ViewSpacing in:top.
claus
parents: 118
diff changeset
   167
	field width:1.0.     
claus
parents: 118
diff changeset
   168
	field leftInset:ViewSpacing;
claus
parents: 118
diff changeset
   169
	      rightInset:ViewSpacing.
121
claus
parents: 120
diff changeset
   170
	field editValue:'hello world' selected:true.
120
claus
parents: 118
diff changeset
   171
claus
parents: 118
diff changeset
   172
	top open
claus
parents: 118
diff changeset
   173
122
claus
parents: 121
diff changeset
   174
120
claus
parents: 118
diff changeset
   175
    have part of it preselected:
claus
parents: 118
diff changeset
   176
claus
parents: 118
diff changeset
   177
	|top field|
claus
parents: 118
diff changeset
   178
claus
parents: 118
diff changeset
   179
	top := StandardSystemView new.
claus
parents: 118
diff changeset
   180
	top extent:200@100.
claus
parents: 118
diff changeset
   181
claus
parents: 118
diff changeset
   182
	field := EditField origin:0.0@ViewSpacing in:top.
claus
parents: 118
diff changeset
   183
	field width:1.0.     
claus
parents: 118
diff changeset
   184
	field leftInset:ViewSpacing;
claus
parents: 118
diff changeset
   185
	      rightInset:ViewSpacing.
121
claus
parents: 120
diff changeset
   186
	field editValue:'hello world';
120
claus
parents: 118
diff changeset
   187
	      selectFromCharacterPosition:1 to:5.
claus
parents: 118
diff changeset
   188
claus
parents: 118
diff changeset
   189
	top open
claus
parents: 118
diff changeset
   190
122
claus
parents: 121
diff changeset
   191
125
claus
parents: 122
diff changeset
   192
    set a size limit:
claus
parents: 122
diff changeset
   193
claus
parents: 122
diff changeset
   194
	|top field|
claus
parents: 122
diff changeset
   195
claus
parents: 122
diff changeset
   196
	top := StandardSystemView new.
claus
parents: 122
diff changeset
   197
	top extent:200@100.
claus
parents: 122
diff changeset
   198
claus
parents: 122
diff changeset
   199
	field := EditField origin:0.0@ViewSpacing in:top.
claus
parents: 122
diff changeset
   200
	field width:1.0.     
claus
parents: 122
diff changeset
   201
	field leftInset:ViewSpacing;
claus
parents: 122
diff changeset
   202
	      rightInset:ViewSpacing.
claus
parents: 122
diff changeset
   203
	field editValue:'hello';
claus
parents: 122
diff changeset
   204
	      maxChars:8.
claus
parents: 122
diff changeset
   205
claus
parents: 122
diff changeset
   206
	top open
claus
parents: 122
diff changeset
   207
claus
parents: 122
diff changeset
   208
121
claus
parents: 120
diff changeset
   209
    use a converter:
125
claus
parents: 122
diff changeset
   210
      - numbers (default to 0):
121
claus
parents: 120
diff changeset
   211
claus
parents: 120
diff changeset
   212
	|top field|
claus
parents: 120
diff changeset
   213
claus
parents: 120
diff changeset
   214
	top := StandardSystemView new.
claus
parents: 120
diff changeset
   215
	top extent:200@100.
claus
parents: 120
diff changeset
   216
claus
parents: 120
diff changeset
   217
	field := EditField origin:0.0@ViewSpacing in:top.
claus
parents: 120
diff changeset
   218
	field width:1.0.
claus
parents: 120
diff changeset
   219
	field leftInset:ViewSpacing;
claus
parents: 120
diff changeset
   220
	      rightInset:ViewSpacing.
claus
parents: 120
diff changeset
   221
claus
parents: 120
diff changeset
   222
	field converter:(PrintConverter new initForNumber).
claus
parents: 120
diff changeset
   223
	field editValue:1234.
claus
parents: 120
diff changeset
   224
	field acceptAction:[:value | Transcript showCr:value].
claus
parents: 120
diff changeset
   225
	field crAction:[field accept. top destroy].
claus
parents: 120
diff changeset
   226
	top open.
claus
parents: 120
diff changeset
   227
claus
parents: 120
diff changeset
   228
      - dates:
claus
parents: 120
diff changeset
   229
claus
parents: 120
diff changeset
   230
	|top field|
claus
parents: 120
diff changeset
   231
claus
parents: 120
diff changeset
   232
	top := StandardSystemView new.
claus
parents: 120
diff changeset
   233
	top extent:200@100.
claus
parents: 120
diff changeset
   234
claus
parents: 120
diff changeset
   235
	field := EditField origin:0.0@ViewSpacing in:top.
claus
parents: 120
diff changeset
   236
	field width:1.0.
claus
parents: 120
diff changeset
   237
	field leftInset:ViewSpacing;
claus
parents: 120
diff changeset
   238
	      rightInset:ViewSpacing.
claus
parents: 120
diff changeset
   239
claus
parents: 120
diff changeset
   240
	field converter:(PrintConverter new initForDate).
claus
parents: 120
diff changeset
   241
	field editValue:Date today.
125
claus
parents: 122
diff changeset
   242
	field acceptAction:[:value | Transcript showCr:value class name , ' ' , value printString].
121
claus
parents: 120
diff changeset
   243
	field crAction:[field accept. top destroy].
claus
parents: 120
diff changeset
   244
	top open.
claus
parents: 120
diff changeset
   245
122
claus
parents: 121
diff changeset
   246
125
claus
parents: 122
diff changeset
   247
    setting immediateAccept, makes the field update with every key:
claus
parents: 122
diff changeset
   248
claus
parents: 122
diff changeset
   249
      - immediate accept numbers, defaulting to nil:
121
claus
parents: 120
diff changeset
   250
claus
parents: 120
diff changeset
   251
	|top field|
claus
parents: 120
diff changeset
   252
claus
parents: 120
diff changeset
   253
	top := StandardSystemView new.
claus
parents: 120
diff changeset
   254
	top extent:200@100.
claus
parents: 120
diff changeset
   255
claus
parents: 120
diff changeset
   256
	field := EditField origin:0.0@ViewSpacing in:top.
claus
parents: 120
diff changeset
   257
	field width:1.0.
claus
parents: 120
diff changeset
   258
	field leftInset:ViewSpacing;
claus
parents: 120
diff changeset
   259
	      rightInset:ViewSpacing.
claus
parents: 120
diff changeset
   260
125
claus
parents: 122
diff changeset
   261
	field converter:(PrintConverter new initForNumberOrNil).
claus
parents: 122
diff changeset
   262
	field immediateAccept:true.
121
claus
parents: 120
diff changeset
   263
	field editValue:1234.
claus
parents: 120
diff changeset
   264
	field acceptAction:[:value | Transcript showCr:value].
claus
parents: 120
diff changeset
   265
	field crAction:[field accept. top destroy].
claus
parents: 120
diff changeset
   266
	top open.
claus
parents: 120
diff changeset
   267
122
claus
parents: 121
diff changeset
   268
127
claus
parents: 125
diff changeset
   269
claus
parents: 125
diff changeset
   270
120
claus
parents: 118
diff changeset
   271
    use a model:
claus
parents: 118
diff changeset
   272
    (see changing model value in inspector when return is pressed in the field)
claus
parents: 118
diff changeset
   273
claus
parents: 118
diff changeset
   274
	|top field model|
claus
parents: 118
diff changeset
   275
claus
parents: 118
diff changeset
   276
	model := 'hello world' asValue.
claus
parents: 118
diff changeset
   277
claus
parents: 118
diff changeset
   278
	top := StandardSystemView new.
claus
parents: 118
diff changeset
   279
	top extent:200@100.
claus
parents: 118
diff changeset
   280
claus
parents: 118
diff changeset
   281
	field := EditField origin:0.0@ViewSpacing in:top.
121
claus
parents: 120
diff changeset
   282
	field width:1.0.
120
claus
parents: 118
diff changeset
   283
	field leftInset:ViewSpacing;
claus
parents: 118
diff changeset
   284
	      rightInset:ViewSpacing.
claus
parents: 118
diff changeset
   285
	field model:model.
128
claus
parents: 127
diff changeset
   286
	field acceptOnReturn:true.
120
claus
parents: 118
diff changeset
   287
claus
parents: 118
diff changeset
   288
	top open.
121
claus
parents: 120
diff changeset
   289
	model inspect.
claus
parents: 120
diff changeset
   290
122
claus
parents: 121
diff changeset
   291
127
claus
parents: 125
diff changeset
   292
    two views on the same model (each accepts on return):
121
claus
parents: 120
diff changeset
   293
claus
parents: 120
diff changeset
   294
	|top1 top2 field1 field2 model|
claus
parents: 120
diff changeset
   295
claus
parents: 120
diff changeset
   296
	model := 'hello world' asValue.
claus
parents: 120
diff changeset
   297
claus
parents: 120
diff changeset
   298
	top1 := StandardSystemView new.
claus
parents: 120
diff changeset
   299
	top1 extent:200@100.
claus
parents: 120
diff changeset
   300
	field1 := EditField origin:0.0@ViewSpacing in:top1.
claus
parents: 120
diff changeset
   301
	field1 width:1.0.
claus
parents: 120
diff changeset
   302
	field1 leftInset:ViewSpacing;
claus
parents: 120
diff changeset
   303
	      rightInset:ViewSpacing.
claus
parents: 120
diff changeset
   304
	field1 model:model.
128
claus
parents: 127
diff changeset
   305
	field1 acceptOnReturn:true.
121
claus
parents: 120
diff changeset
   306
	top1 open.
claus
parents: 120
diff changeset
   307
claus
parents: 120
diff changeset
   308
	top2 := StandardSystemView new.
claus
parents: 120
diff changeset
   309
	top2 extent:200@100.
claus
parents: 120
diff changeset
   310
	field2 := EditField origin:0.0@ViewSpacing in:top2.
claus
parents: 120
diff changeset
   311
	field2 width:1.0.
claus
parents: 120
diff changeset
   312
	field2 leftInset:ViewSpacing;
claus
parents: 120
diff changeset
   313
	      rightInset:ViewSpacing.
claus
parents: 120
diff changeset
   314
	field2 model:model.
128
claus
parents: 127
diff changeset
   315
	field2 acceptOnReturn:true.
121
claus
parents: 120
diff changeset
   316
	top2 open.
claus
parents: 120
diff changeset
   317
127
claus
parents: 125
diff changeset
   318
    two views on the same model (no accept on return):
claus
parents: 125
diff changeset
   319
claus
parents: 125
diff changeset
   320
	|top1 top2 field1 field2 model|
claus
parents: 125
diff changeset
   321
claus
parents: 125
diff changeset
   322
	model := 'hello world' asValue.
claus
parents: 125
diff changeset
   323
claus
parents: 125
diff changeset
   324
	top1 := StandardSystemView new.
claus
parents: 125
diff changeset
   325
	top1 extent:200@100.
claus
parents: 125
diff changeset
   326
	field1 := EditField origin:0.0@ViewSpacing in:top1.
claus
parents: 125
diff changeset
   327
	field1 width:1.0.
claus
parents: 125
diff changeset
   328
	field1 leftInset:ViewSpacing;
claus
parents: 125
diff changeset
   329
	      rightInset:ViewSpacing.
claus
parents: 125
diff changeset
   330
	field1 model:model; acceptOnReturn:false.
claus
parents: 125
diff changeset
   331
	top1 open.
claus
parents: 125
diff changeset
   332
claus
parents: 125
diff changeset
   333
	top2 := StandardSystemView new.
claus
parents: 125
diff changeset
   334
	top2 extent:200@100.
claus
parents: 125
diff changeset
   335
	field2 := EditField origin:0.0@ViewSpacing in:top2.
claus
parents: 125
diff changeset
   336
	field2 width:1.0.
claus
parents: 125
diff changeset
   337
	field2 leftInset:ViewSpacing;
claus
parents: 125
diff changeset
   338
	      rightInset:ViewSpacing.
claus
parents: 125
diff changeset
   339
	field2 model:model; acceptOnReturn:false.
claus
parents: 125
diff changeset
   340
	top2 open.
claus
parents: 125
diff changeset
   341
125
claus
parents: 122
diff changeset
   342
    with immediate accept:
claus
parents: 122
diff changeset
   343
claus
parents: 122
diff changeset
   344
	|top1 top2 field1 field2 model|
claus
parents: 122
diff changeset
   345
claus
parents: 122
diff changeset
   346
	model := 'hello world' asValue.
claus
parents: 122
diff changeset
   347
claus
parents: 122
diff changeset
   348
	top1 := StandardSystemView new.
claus
parents: 122
diff changeset
   349
	top1 extent:200@100.
claus
parents: 122
diff changeset
   350
	field1 := EditField origin:0.0@ViewSpacing in:top1.
claus
parents: 122
diff changeset
   351
	field1 width:1.0.
claus
parents: 122
diff changeset
   352
	field1 leftInset:ViewSpacing; rightInset:ViewSpacing.
claus
parents: 122
diff changeset
   353
	field1 model:model; immediateAccept:true.
claus
parents: 122
diff changeset
   354
	top1 open.
claus
parents: 122
diff changeset
   355
claus
parents: 122
diff changeset
   356
	top2 := StandardSystemView new.
claus
parents: 122
diff changeset
   357
	top2 extent:200@100.
claus
parents: 122
diff changeset
   358
	field2 := EditField origin:0.0@ViewSpacing in:top2.
claus
parents: 122
diff changeset
   359
	field2 width:1.0.
claus
parents: 122
diff changeset
   360
	field2 leftInset:ViewSpacing; rightInset:ViewSpacing.
claus
parents: 122
diff changeset
   361
	field2 model:model; immediateAccept:true.
claus
parents: 122
diff changeset
   362
	top2 open.
122
claus
parents: 121
diff changeset
   363
121
claus
parents: 120
diff changeset
   364
    just an example; a checkBox and an editField on the same model:
claus
parents: 120
diff changeset
   365
claus
parents: 120
diff changeset
   366
	|top1 top2 field1 box model|
claus
parents: 120
diff changeset
   367
claus
parents: 120
diff changeset
   368
	model := false asValue.
claus
parents: 120
diff changeset
   369
claus
parents: 120
diff changeset
   370
	top1 := StandardSystemView new.
claus
parents: 120
diff changeset
   371
	top1 extent:200@100.
claus
parents: 120
diff changeset
   372
	field1 := EditField origin:0.0@ViewSpacing in:top1.
claus
parents: 120
diff changeset
   373
	field1 width:1.0.
claus
parents: 120
diff changeset
   374
	field1 leftInset:ViewSpacing;
claus
parents: 120
diff changeset
   375
	      rightInset:ViewSpacing.
claus
parents: 120
diff changeset
   376
	field1 converter:(PrintConverter new initForYesNo).
claus
parents: 120
diff changeset
   377
	field1 model:model.
claus
parents: 120
diff changeset
   378
	top1 open.
claus
parents: 120
diff changeset
   379
claus
parents: 120
diff changeset
   380
	top2 := StandardSystemView new.
claus
parents: 120
diff changeset
   381
	top2 extent:200@100.
claus
parents: 120
diff changeset
   382
	box := CheckBox on:model.
claus
parents: 120
diff changeset
   383
	box label:'on/off'.
claus
parents: 120
diff changeset
   384
	top2 add:box.
claus
parents: 120
diff changeset
   385
	top2 open.
claus
parents: 120
diff changeset
   386
120
claus
parents: 118
diff changeset
   387
	model inspect.
125
claus
parents: 122
diff changeset
   388
claus
parents: 122
diff changeset
   389
claus
parents: 122
diff changeset
   390
    connecting fields:
claus
parents: 122
diff changeset
   391
    update field2 wehenever field1 is changed.
claus
parents: 122
diff changeset
   392
    (normally, the processing below (xChanged) is done in your application
claus
parents: 122
diff changeset
   393
     class, or in a complex model. For the demonstration below, we use
claus
parents: 122
diff changeset
   394
     a Plug to simulate the protocol.)
claus
parents: 122
diff changeset
   395
claus
parents: 122
diff changeset
   396
	|application top field1 field2 value1 value2|
claus
parents: 122
diff changeset
   397
claus
parents: 122
diff changeset
   398
	application := Plug new.
claus
parents: 122
diff changeset
   399
	application respondTo:#value1Changed
claus
parents: 122
diff changeset
   400
			 with:[value2 value:(value1 value isNil ifTrue:[nil]
claus
parents: 122
diff changeset
   401
								ifFalse:[value1 value squared])].
claus
parents: 122
diff changeset
   402
claus
parents: 122
diff changeset
   403
	value1 := 1 asValue.
claus
parents: 122
diff changeset
   404
	value2 := 1 asValue.
claus
parents: 122
diff changeset
   405
claus
parents: 122
diff changeset
   406
	top := Dialog new.
claus
parents: 122
diff changeset
   407
	top extent:200@200.
claus
parents: 122
diff changeset
   408
claus
parents: 122
diff changeset
   409
	(top addTextLabel:'some number:') layout:#left.
claus
parents: 122
diff changeset
   410
	top addVerticalSpace.
claus
parents: 122
diff changeset
   411
claus
parents: 122
diff changeset
   412
	(top addInputFieldOn:value1 tabable:false) 
claus
parents: 122
diff changeset
   413
	    converter:(PrintConverter new initForNumberOrNil);
claus
parents: 122
diff changeset
   414
	    immediateAccept:true.
claus
parents: 122
diff changeset
   415
	top addVerticalSpace.
claus
parents: 122
diff changeset
   416
claus
parents: 122
diff changeset
   417
	(top addTextLabel:'squared:') layout:#left.
claus
parents: 122
diff changeset
   418
	top addVerticalSpace.
claus
parents: 122
diff changeset
   419
	(top addInputFieldOn:value2 tabable:false) 
claus
parents: 122
diff changeset
   420
	    converter:(PrintConverter new initForNumberOrNil).
claus
parents: 122
diff changeset
   421
claus
parents: 122
diff changeset
   422
	value1 onChangeSend:#value1Changed to:application.
claus
parents: 122
diff changeset
   423
claus
parents: 122
diff changeset
   424
	top openModeless.
claus
parents: 122
diff changeset
   425
claus
parents: 122
diff changeset
   426
claus
parents: 122
diff changeset
   427
    two-way connect:
claus
parents: 122
diff changeset
   428
    each field updates the other (notice, that we have to turn off
claus
parents: 122
diff changeset
   429
    onChange: notification, to avoid an endless notification cycle)
claus
parents: 122
diff changeset
   430
claus
parents: 122
diff changeset
   431
	|application top field1 field2 value1 value2|
claus
parents: 122
diff changeset
   432
claus
parents: 122
diff changeset
   433
	application := Plug new.
claus
parents: 122
diff changeset
   434
	application respondTo:#value1Changed
258
ae4b8f1a6738 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   435
			 with:[value2 retractInterestsFor:application.
125
claus
parents: 122
diff changeset
   436
			       value2 value:(value1 value isNil ifTrue:[nil]
claus
parents: 122
diff changeset
   437
								ifFalse:[value1 value squared]).
claus
parents: 122
diff changeset
   438
			       value2 onChangeSend:#value2Changed to:application.
claus
parents: 122
diff changeset
   439
			      ].
claus
parents: 122
diff changeset
   440
	application respondTo:#value2Changed
258
ae4b8f1a6738 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   441
			 with:[value1 retractInterestsFor:application.
125
claus
parents: 122
diff changeset
   442
			       value1 value:(value2 value isNil ifTrue:[nil]
claus
parents: 122
diff changeset
   443
								ifFalse:[value2 value sqrt]).
claus
parents: 122
diff changeset
   444
			       value1 onChangeSend:#value1Changed to:application.
claus
parents: 122
diff changeset
   445
			      ].
claus
parents: 122
diff changeset
   446
claus
parents: 122
diff changeset
   447
	value1 := 1 asValue.
claus
parents: 122
diff changeset
   448
	value2 := 1 asValue.
claus
parents: 122
diff changeset
   449
claus
parents: 122
diff changeset
   450
	top := Dialog new.
claus
parents: 122
diff changeset
   451
	top extent:200@200.
claus
parents: 122
diff changeset
   452
claus
parents: 122
diff changeset
   453
	(top addTextLabel:'some number:') layout:#left.
claus
parents: 122
diff changeset
   454
	top addVerticalSpace.
claus
parents: 122
diff changeset
   455
claus
parents: 122
diff changeset
   456
	(top addInputFieldOn:value1 tabable:false) 
claus
parents: 122
diff changeset
   457
	    converter:(PrintConverter new initForNumberOrNil);
claus
parents: 122
diff changeset
   458
	    immediateAccept:true.
claus
parents: 122
diff changeset
   459
	top addVerticalSpace.
claus
parents: 122
diff changeset
   460
claus
parents: 122
diff changeset
   461
	(top addTextLabel:'squared:') layout:#left.
claus
parents: 122
diff changeset
   462
	top addVerticalSpace.
claus
parents: 122
diff changeset
   463
	(top addInputFieldOn:value2 tabable:false) 
127
claus
parents: 125
diff changeset
   464
	    converter:(PrintConverter new initForNumberOrNil);
claus
parents: 125
diff changeset
   465
	    immediateAccept:true.
125
claus
parents: 122
diff changeset
   466
claus
parents: 122
diff changeset
   467
	value1 onChangeSend:#value1Changed to:application.
claus
parents: 122
diff changeset
   468
	value2 onChangeSend:#value2Changed to:application.
claus
parents: 122
diff changeset
   469
claus
parents: 122
diff changeset
   470
	top openModeless.
120
claus
parents: 118
diff changeset
   471
"
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   472
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   473
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   474
version
258
ae4b8f1a6738 interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents: 231
diff changeset
   475
    ^ '$Header: /cvs/stx/stx/libwidg/EditField.st,v 1.35 1995-12-15 13:04:02 cg Exp $'
19
a696fb528758 *** empty log message ***
claus
parents: 7
diff changeset
   476
! !
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   477
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   478
!EditField class methodsFor:'defaults'!
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   479
125
claus
parents: 122
diff changeset
   480
defaultLeaveKeys
128
claus
parents: 127
diff changeset
   481
    "return the set of keys which are taken as leave-keys.
claus
parents: 127
diff changeset
   482
     If the field is in an enterFieldGroup, all leave keys will be
claus
parents: 127
diff changeset
   483
     forwarded to the group and possible step to the next/previous field.
claus
parents: 127
diff changeset
   484
     Also, if acceptOnLeave is true, leave keys will store the current
claus
parents: 127
diff changeset
   485
     value into their model (if any)"
claus
parents: 127
diff changeset
   486
125
claus
parents: 122
diff changeset
   487
    ^ #(Return CursorUp CursorDown Next Previous Accept)
claus
parents: 122
diff changeset
   488
!
claus
parents: 122
diff changeset
   489
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   490
defaultNumberOfLines
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   491
    "the number of lines in the field"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   492
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   493
    ^ 1
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   494
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   495
59
450ce95a72a4 *** empty log message ***
claus
parents: 47
diff changeset
   496
updateStyleCache
60
f3c738c24ce6 mostly style
claus
parents: 59
diff changeset
   497
    DefaultForegroundColor := StyleSheet colorAt:'editFieldForegroundColor' default:Black.
f3c738c24ce6 mostly style
claus
parents: 59
diff changeset
   498
    DefaultBackgroundColor := StyleSheet colorAt:'editFieldBackgroundColor' default:White.
f3c738c24ce6 mostly style
claus
parents: 59
diff changeset
   499
    DefaultSelectionForegroundColor := StyleSheet colorAt:'editFieldSelectionForegroundColor' default:DefaultBackgroundColor.
f3c738c24ce6 mostly style
claus
parents: 59
diff changeset
   500
    DefaultSelectionBackgroundColor := StyleSheet colorAt:'editFieldSelectionBackgroundColor' default:DefaultForegroundColor.
f3c738c24ce6 mostly style
claus
parents: 59
diff changeset
   501
    DefaultFont := StyleSheet fontAt:'editFieldFont' default:nil.
59
450ce95a72a4 *** empty log message ***
claus
parents: 47
diff changeset
   502
450ce95a72a4 *** empty log message ***
claus
parents: 47
diff changeset
   503
    "
60
f3c738c24ce6 mostly style
claus
parents: 59
diff changeset
   504
     self updateStyleCache
59
450ce95a72a4 *** empty log message ***
claus
parents: 47
diff changeset
   505
    "
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   506
! !
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   507
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   508
!EditField methodsFor:'accessing-behavior'!
125
claus
parents: 122
diff changeset
   509
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   510
acceptOnLeave:aBoolean
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   511
    "set/clear the acceptOnLeave flag. The default is false."
125
claus
parents: 122
diff changeset
   512
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   513
     acceptOnLeave := aBoolean
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   514
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   515
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   516
acceptOnReturn:aBoolean
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   517
    "set/clear the acceptOnReturn flag. The default is false."
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   518
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   519
     acceptOnReturn := aBoolean
125
claus
parents: 122
diff changeset
   520
!
claus
parents: 122
diff changeset
   521
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   522
crAction:aBlock
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   523
    "define an action to be evaluated when the return key is pressed."
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   524
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   525
    crAction := aBlock
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   526
!
125
claus
parents: 122
diff changeset
   527
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   528
cursorMovementWhenUpdating:aSymbol
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   529
    "define what should be done with the cursor, when I update
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   530
     my contents from the model. Allowed argumetns are:
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   531
	#keep / nil     -> stay where it was
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   532
	#endOfLine      -> position cursor after the string
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   533
	#beginOfLine    -> position cursor to the beginning
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   534
     The default is #endOfLine"
125
claus
parents: 122
diff changeset
   535
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   536
    cursorMovementWhenUpdating := aSymbol
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   537
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   538
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   539
disable
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   540
    "disable the field; hide cursor and ignore input"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   541
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   542
    enabled ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   543
	enabled := false.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   544
	self hideCursor
125
claus
parents: 122
diff changeset
   545
    ]
claus
parents: 122
diff changeset
   546
!
claus
parents: 122
diff changeset
   547
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   548
enable
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   549
    "enable the field; show cursor and allow input"
127
claus
parents: 125
diff changeset
   550
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   551
    enabled ifFalse:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   552
"/        enableAction notNil ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   553
"/            enableAction value
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   554
"/        ].
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   555
	enabled := true.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   556
	super showCursor
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   557
    ]
127
claus
parents: 125
diff changeset
   558
!
claus
parents: 125
diff changeset
   559
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   560
enableAction:aBlock
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   561
    "define an action to be evaluated when enabled by clicking upon"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   562
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   563
    enableAction := aBlock
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   564
!
125
claus
parents: 122
diff changeset
   565
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   566
entryCompletionBlock:aOneArgBlock
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   567
    "define an action to be evaluated when Tab (NameCompletion) is pressed.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   568
     The block gets the current contents as argument."
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   569
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   570
    entryCompletionBlock := aOneArgBlock
125
claus
parents: 122
diff changeset
   571
!
claus
parents: 122
diff changeset
   572
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   573
immediateAccept:aBoolean
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   574
    "set/clear the immediateAccept flag. The default is false."
155
claus
parents: 144
diff changeset
   575
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   576
     immediateAccept := aBoolean
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   577
!
155
claus
parents: 144
diff changeset
   578
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   579
leaveAction:aBlock
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   580
    "define an action to be evaluated when field is left by return key"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   581
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   582
    leaveAction := aBlock
155
claus
parents: 144
diff changeset
   583
!
claus
parents: 144
diff changeset
   584
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   585
leaveKeys:aCollectionOfKeySymbols 
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   586
    "define the set of keys which are interpreted as leaveKeys.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   587
     I.e. those that make the field inactive and accept (if acceptOnLeave is true).
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   588
     The default is a set of #CursorUp, #CursorDown, #Next, #Prior and #Return."
155
claus
parents: 144
diff changeset
   589
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   590
    leaveKeys := aCollectionOfKeySymbols
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   591
!
155
claus
parents: 144
diff changeset
   592
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   593
tabAction:aBlock
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   594
    "define an action to be evaluated when the tabulator key is pressed."
155
claus
parents: 144
diff changeset
   595
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   596
    tabAction := aBlock
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   597
! !
125
claus
parents: 122
diff changeset
   598
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   599
!EditField methodsFor:'accessing-contents'!
125
claus
parents: 122
diff changeset
   600
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   601
contents
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   602
    "return contents as a string
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   603
     - redefined since EditFields hold only one line of text.
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   604
    In your application, please use #editValue; 
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   605
    it uses a converter (if any) and is compatible to ST-80."
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   606
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   607
    list isNil ifTrue:[^ ''].
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   608
    (list size == 0) ifTrue:[^ ''].
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   609
    ^ list at:1
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   610
!
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   611
125
claus
parents: 122
diff changeset
   612
contents:someText
claus
parents: 122
diff changeset
   613
    "set the contents from a string
claus
parents: 122
diff changeset
   614
     - redefined to place the cursor to the end.
claus
parents: 122
diff changeset
   615
    In your application, please use #editValue:; 
claus
parents: 122
diff changeset
   616
    it uses a converter (if any) and is compatible to ST-80."
claus
parents: 122
diff changeset
   617
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   618
    |newCol|
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   619
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   620
    newCol := cursorCol.
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   621
125
claus
parents: 122
diff changeset
   622
    super contents:someText.
claus
parents: 122
diff changeset
   623
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   624
    cursorMovementWhenUpdating == #endOfLine ifTrue:[
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   625
	 newCol := (someText size + 1).
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   626
    ] ifFalse:[
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   627
	cursorMovementWhenUpdating == #beginOfLine ifTrue:[
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   628
	    newCol := 1
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   629
	] ifFalse:[
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   630
	    "/ default: stay where it was
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   631
	]
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   632
    ].
125
claus
parents: 122
diff changeset
   633
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   634
    self cursorCol:newCol.
125
claus
parents: 122
diff changeset
   635
!
claus
parents: 122
diff changeset
   636
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   637
converter
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   638
    "return the converter (if any)."
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   639
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   640
    ^ converter
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   641
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   642
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   643
converter:aConverter
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   644
    "set the converter. If non-nil,
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   645
     the converter is applied to the text to convert from the string
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   646
     representation to the actual object value and vice versa.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   647
     The default converter is nil, meaning no-conversion
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   648
     (i.e. the edited object is the string itself."
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   649
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   650
    converter := aConverter
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   651
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   652
125
claus
parents: 122
diff changeset
   653
editValue
claus
parents: 122
diff changeset
   654
    "if the field edits a string, this is a name alias for #contents.
claus
parents: 122
diff changeset
   655
     Otherwise, if there is a converter, return the edited string
claus
parents: 122
diff changeset
   656
     converted to an appropriate object."
claus
parents: 122
diff changeset
   657
claus
parents: 122
diff changeset
   658
    |string|
claus
parents: 122
diff changeset
   659
claus
parents: 122
diff changeset
   660
    string := self contents.
claus
parents: 122
diff changeset
   661
    converter isNil ifTrue:[^ string].
claus
parents: 122
diff changeset
   662
    string isNil ifTrue:[string := ''].
claus
parents: 122
diff changeset
   663
    ^ converter readValueFrom:string 
claus
parents: 122
diff changeset
   664
!
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   665
125
claus
parents: 122
diff changeset
   666
editValue:aStringOrObject
claus
parents: 122
diff changeset
   667
    "set the contents. If there is a converter, use it to convert
claus
parents: 122
diff changeset
   668
     the object into a printed representation.
claus
parents: 122
diff changeset
   669
     Otherwise, the argument is supposed to be a string like object,
claus
parents: 122
diff changeset
   670
     and used directly (i.e. this is equivalent to sending #contents:)."
claus
parents: 122
diff changeset
   671
claus
parents: 122
diff changeset
   672
    self editValue:aStringOrObject selected:false
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   673
!
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   674
125
claus
parents: 122
diff changeset
   675
editValue:aStringOrObject selected:aBoolean
claus
parents: 122
diff changeset
   676
    "set the contents. If there is a converter, use it to convert
claus
parents: 122
diff changeset
   677
     the object into a printed representation.
claus
parents: 122
diff changeset
   678
     Otherwise, the argument is supposed to be a string like object,
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   679
     and used directly (i.e. this is equivalent to sending #initialText:selected:)."
125
claus
parents: 122
diff changeset
   680
claus
parents: 122
diff changeset
   681
    |string|
claus
parents: 122
diff changeset
   682
claus
parents: 122
diff changeset
   683
    converter notNil ifTrue:[
claus
parents: 122
diff changeset
   684
	string := converter printStringFor:aStringOrObject
claus
parents: 122
diff changeset
   685
    ] ifFalse:[
claus
parents: 122
diff changeset
   686
	string :=  aStringOrObject.
claus
parents: 122
diff changeset
   687
    ].
claus
parents: 122
diff changeset
   688
    self contents:string.
claus
parents: 122
diff changeset
   689
    aBoolean ifTrue:[
claus
parents: 122
diff changeset
   690
	self selectFromLine:1 col:1 toLine:1 col:string size
claus
parents: 122
diff changeset
   691
    ]
claus
parents: 122
diff changeset
   692
!
claus
parents: 122
diff changeset
   693
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   694
initialText:aString
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   695
    "set the initialText and select it"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   696
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   697
    self initialText:aString selected:true
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   698
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   699
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   700
initialText:aString selected:aBoolean
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   701
    "set the initialText and select it if aBoolean is true"
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   702
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   703
    |len s|
125
claus
parents: 122
diff changeset
   704
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   705
    leftOffset := 0.
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   706
    (s := aString) notNil ifTrue:[
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   707
	s := s asString
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   708
    ].
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   709
    self contents:s.
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   710
    aBoolean ifTrue:[
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   711
	(len := s size) ~~ 0 ifTrue:[
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   712
	    self selectFromLine:1 col:1 toLine:1 col:len
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   713
	]
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   714
    ]
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   715
!
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   716
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   717
list:someText
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   718
    "low level access to the underlying contents' list.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   719
     Redefined to force text to 1 line, and notify dependents
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   720
     of any changed extent-wishes (for automatic box resizing)."
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   721
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   722
    |l oldWidth|
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   723
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   724
    l := someText.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   725
    l size > 1 ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   726
	l := OrderedCollection with:(l at:1)
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   727
    ].
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   728
    oldWidth := self widthOfContents.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   729
    super list:l.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   730
    self widthOfContents ~~ oldWidth ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   731
	self changed:#preferredExtent
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   732
    ]
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   733
!
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   734
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   735
stringValue
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   736
    "alias for #contents - for compatibility with ST-80's InputField"
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   737
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   738
    ^ self contents
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   739
! !
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   740
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   741
!EditField methodsFor:'accessing-look'!
125
claus
parents: 122
diff changeset
   742
155
claus
parents: 144
diff changeset
   743
maxChars
claus
parents: 144
diff changeset
   744
    "return the maximum number of characters that are allowed in
claus
parents: 144
diff changeset
   745
     the field. 
claus
parents: 144
diff changeset
   746
     A limit of nil means: unlimited. This is the default."
claus
parents: 144
diff changeset
   747
claus
parents: 144
diff changeset
   748
    ^ lengthLimit
claus
parents: 144
diff changeset
   749
claus
parents: 144
diff changeset
   750
    "Modified: 6.9.1995 / 13:43:33 / claus"
claus
parents: 144
diff changeset
   751
!
claus
parents: 144
diff changeset
   752
125
claus
parents: 122
diff changeset
   753
maxChars:aNumberOrNil
claus
parents: 122
diff changeset
   754
    "set the maximum number of characters that are allowed in
claus
parents: 122
diff changeset
   755
     the field. Additional input will be ignored by the field.
claus
parents: 122
diff changeset
   756
     A limit of nil means: unlimited. This is the default.
claus
parents: 122
diff changeset
   757
     This method has been renamed from #lengthLimit: for ST-80
claus
parents: 122
diff changeset
   758
     compatibility."
claus
parents: 122
diff changeset
   759
claus
parents: 122
diff changeset
   760
    lengthLimit := aNumberOrNil
187
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   761
!
1a429506fad6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   762
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   763
passwordCharacter
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   764
    ^ passwordCharacter
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   765
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   766
    "Modified: 6.9.1995 / 12:25:39 / claus"
125
claus
parents: 122
diff changeset
   767
!
claus
parents: 122
diff changeset
   768
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   769
passwordCharacter:aCharacter
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   770
    passwordCharacter := aCharacter
97
cbf495fe3b64 *** empty log message ***
claus
parents: 77
diff changeset
   771
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   772
    "Modified: 6.9.1995 / 12:25:33 / claus"
38
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
   773
! !
4b9b70b2cc87 2.10.3 pre-final version
claus
parents: 19
diff changeset
   774
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   775
!EditField methodsFor:'cursor drawing'!
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   776
155
claus
parents: 144
diff changeset
   777
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg
claus
parents: 144
diff changeset
   778
    startVisLineNr to:endVisLineNr do:[:visLine |
claus
parents: 144
diff changeset
   779
	self drawVisibleLine:visLine with:fg and:bg
claus
parents: 144
diff changeset
   780
    ]
claus
parents: 144
diff changeset
   781
claus
parents: 144
diff changeset
   782
    "Modified: 6.9.1995 / 12:24:29 / claus"
claus
parents: 144
diff changeset
   783
!
claus
parents: 144
diff changeset
   784
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   785
showCursor
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   786
    "make cursor visible if currently invisible - but only if this
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   787
     EditField is enabled"
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   788
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   789
    enabled ifTrue:[super showCursor]
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   790
! !
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   791
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   792
!EditField methodsFor:'cursor movement'!
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   793
125
claus
parents: 122
diff changeset
   794
cursorCol:col
claus
parents: 122
diff changeset
   795
    "redefined to lock the cursor at the end, if I have a lngthLimit"
claus
parents: 122
diff changeset
   796
claus
parents: 122
diff changeset
   797
    |c sz|
claus
parents: 122
diff changeset
   798
claus
parents: 122
diff changeset
   799
    c := col.
claus
parents: 122
diff changeset
   800
    lengthLimit notNil ifTrue:[
claus
parents: 122
diff changeset
   801
	sz := lengthLimit.
claus
parents: 122
diff changeset
   802
	c > sz ifTrue:[
claus
parents: 122
diff changeset
   803
	    c := sz+1.
claus
parents: 122
diff changeset
   804
	]
claus
parents: 122
diff changeset
   805
    ].
claus
parents: 122
diff changeset
   806
    super cursorCol:c
claus
parents: 122
diff changeset
   807
!
claus
parents: 122
diff changeset
   808
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   809
cursorDown
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   810
    "catch cursor movement"
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   811
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   812
    (cursorVisibleLine == nLinesShown) ifFalse:[
59
450ce95a72a4 *** empty log message ***
claus
parents: 47
diff changeset
   813
	super cursorDown
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   814
    ]
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   815
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   816
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   817
cursorLine:line col:col
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   818
    "catch cursor movement"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   819
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   820
    super cursorLine:1 col:col
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   821
! !
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   822
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   823
!EditField methodsFor:'editing'!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   824
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   825
paste:someText
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   826
    "redefined to force text to 1 line"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   827
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   828
    super paste:someText.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   829
    list size > 1 ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   830
	self deleteFromLine:2 toLine:(list size)
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   831
    ]
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   832
! !
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
   833
70
14443a9ea4ec *** empty log message ***
claus
parents: 62
diff changeset
   834
!EditField methodsFor:'event handling'!
19
a696fb528758 *** empty log message ***
claus
parents: 7
diff changeset
   835
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   836
buttonPress:button x:x y:y
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   837
    "enable myself on mouse click"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   838
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   839
    enabled ifFalse:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   840
	enabled := true.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   841
	super buttonPress:button x:x y:y.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   842
	enableAction notNil ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   843
	    enableAction value
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   844
	]
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   845
    ] ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   846
	super buttonPress:button x:x y:y
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   847
    ]
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   848
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   849
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   850
canHandle:aKey
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   851
    "return true, if the receiver would like to handle aKey
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   852
     (usually from another view, when the receiver is part of
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   853
      a more complex dialog box).
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   854
     We do return true here, since the editfield will handle
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   855
     all keys.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   856
     OBSOLETE: dont use this anymore - its a leftover for the tableWidget"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   857
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   858
    ^ true
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   859
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   860
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   861
focusIn
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   862
    "got the explicit focus"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   863
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   864
    enabled ifFalse:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   865
	enabled := true.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   866
	super focusIn.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   867
	enableAction notNil ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   868
	    enableAction value
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   869
	]
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   870
    ] ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   871
	super focusIn
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   872
    ].
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   873
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   874
125
claus
parents: 122
diff changeset
   875
keyPress:key x:x y:y
claus
parents: 122
diff changeset
   876
    "if keyHandler is defined, pass input; otherwise check for leave
claus
parents: 122
diff changeset
   877
     keys"
claus
parents: 122
diff changeset
   878
132
claus
parents: 131
diff changeset
   879
    <resource: #keyboard (#DeleteLine #EndOfText)>
claus
parents: 131
diff changeset
   880
163
claus
parents: 155
diff changeset
   881
    |leave xCol newOffset oldWidth newWidth s|
125
claus
parents: 122
diff changeset
   882
claus
parents: 122
diff changeset
   883
    enabled ifFalse:[
127
claus
parents: 125
diff changeset
   884
	^ self
125
claus
parents: 122
diff changeset
   885
    ].
claus
parents: 122
diff changeset
   886
claus
parents: 122
diff changeset
   887
    (key == #DeleteLine) ifTrue:[
127
claus
parents: 125
diff changeset
   888
	Smalltalk at:#CopyBuffer put:(self contents).
claus
parents: 125
diff changeset
   889
	self contents:''. ^ self
125
claus
parents: 122
diff changeset
   890
    ].
19
a696fb528758 *** empty log message ***
claus
parents: 7
diff changeset
   891
125
claus
parents: 122
diff changeset
   892
    (key == #Tab) ifTrue:[
127
claus
parents: 125
diff changeset
   893
	tabAction notNil ifTrue:[tabAction value. ^ self].
144
claus
parents: 132
diff changeset
   894
	entryCompletionBlock notNil ifTrue:[
163
claus
parents: 155
diff changeset
   895
	    s := self contents.
claus
parents: 155
diff changeset
   896
	    s isNil ifTrue:[
claus
parents: 155
diff changeset
   897
		s := ''
claus
parents: 155
diff changeset
   898
	    ] ifFalse:[
claus
parents: 155
diff changeset
   899
		s := s asString
claus
parents: 155
diff changeset
   900
	    ].
claus
parents: 155
diff changeset
   901
	    entryCompletionBlock value:s. ^ self
144
claus
parents: 132
diff changeset
   902
	]
125
claus
parents: 122
diff changeset
   903
    ].
claus
parents: 122
diff changeset
   904
    (key == #Return) ifTrue:[
127
claus
parents: 125
diff changeset
   905
	crAction notNil ifTrue:[crAction value. ^ self].
125
claus
parents: 122
diff changeset
   906
    ].
claus
parents: 122
diff changeset
   907
    leave := leaveKeys includes:key.
claus
parents: 122
diff changeset
   908
    leave ifTrue:[
127
claus
parents: 125
diff changeset
   909
	leaveAction notNil ifTrue:[
claus
parents: 125
diff changeset
   910
	    leaveAction value:key
claus
parents: 125
diff changeset
   911
	].
121
claus
parents: 120
diff changeset
   912
127
claus
parents: 125
diff changeset
   913
	((key == #Return and:[acceptOnReturn])
claus
parents: 125
diff changeset
   914
	or:[key ~~ #Return and:[acceptOnLeave]]) ifTrue:[
claus
parents: 125
diff changeset
   915
	    self accept.
claus
parents: 125
diff changeset
   916
	].
125
claus
parents: 122
diff changeset
   917
127
claus
parents: 125
diff changeset
   918
	x >= 0 ifTrue:[
claus
parents: 125
diff changeset
   919
	    "
claus
parents: 125
diff changeset
   920
	     let superview know about the leave ...
claus
parents: 125
diff changeset
   921
	     This is a temporary kludge for the tableWidget -
claus
parents: 125
diff changeset
   922
	     it is no clean coding style. Should make the tableWidget
claus
parents: 125
diff changeset
   923
	     a proper model and handle it via the changed mechanism ....
claus
parents: 125
diff changeset
   924
	    "
claus
parents: 125
diff changeset
   925
	    (superView notNil and:[superView canHandle:key from:self]) ifTrue:[
claus
parents: 125
diff changeset
   926
		superView keyPress:key x:x y:y.
claus
parents: 125
diff changeset
   927
	    ].
claus
parents: 125
diff changeset
   928
	].
claus
parents: 125
diff changeset
   929
	^ self
19
a696fb528758 *** empty log message ***
claus
parents: 7
diff changeset
   930
    ].
121
claus
parents: 120
diff changeset
   931
125
claus
parents: 122
diff changeset
   932
    "
claus
parents: 122
diff changeset
   933
     ignore some keys (if not a leaveKey) ...
claus
parents: 122
diff changeset
   934
    "
claus
parents: 122
diff changeset
   935
    (key == #Find) ifTrue:[^self].
claus
parents: 122
diff changeset
   936
    (key == #FindNext) ifTrue:[^self].
claus
parents: 122
diff changeset
   937
    (key == #FindPrev) ifTrue:[^self].
claus
parents: 122
diff changeset
   938
    (key == #GotoLine) ifTrue:[^self].
claus
parents: 122
diff changeset
   939
claus
parents: 122
diff changeset
   940
    "
claus
parents: 122
diff changeset
   941
     a normal key - let superclass's method insert it
claus
parents: 122
diff changeset
   942
    "
claus
parents: 122
diff changeset
   943
    oldWidth := self widthOfContents.
claus
parents: 122
diff changeset
   944
    super keyPress:key x:x y:y.
claus
parents: 122
diff changeset
   945
claus
parents: 122
diff changeset
   946
    "
claus
parents: 122
diff changeset
   947
     for end-of-text, also move to end-of-line
claus
parents: 122
diff changeset
   948
    "
claus
parents: 122
diff changeset
   949
    key == #EndOfText ifTrue:[
127
claus
parents: 125
diff changeset
   950
	super keyPress:#EndOfLine x:x y:y.
125
claus
parents: 122
diff changeset
   951
    ].
claus
parents: 122
diff changeset
   952
    newWidth := self widthOfContents.
claus
parents: 122
diff changeset
   953
claus
parents: 122
diff changeset
   954
    "
claus
parents: 122
diff changeset
   955
     should (& can) we resize ?
claus
parents: 122
diff changeset
   956
    "
claus
parents: 122
diff changeset
   957
    xCol := (self xOfCol:cursorCol inVisibleLine:cursorLine) - leftOffset.
claus
parents: 122
diff changeset
   958
    (xCol > (width * (5/6))) ifTrue:[
130
claus
parents: 128
diff changeset
   959
	self changed:#preferredExtent
125
claus
parents: 122
diff changeset
   960
    ] ifFalse:[
127
claus
parents: 125
diff changeset
   961
	newWidth < (width * (1/6)) ifTrue:[
130
claus
parents: 128
diff changeset
   962
	    self changed:#preferredExtent
127
claus
parents: 125
diff changeset
   963
	]
125
claus
parents: 122
diff changeset
   964
    ].
claus
parents: 122
diff changeset
   965
claus
parents: 122
diff changeset
   966
    "
155
claus
parents: 144
diff changeset
   967
     did someone react (i.e. has my extent changed) ?
125
claus
parents: 122
diff changeset
   968
     (if not, we scroll horizontally)
claus
parents: 122
diff changeset
   969
    "
claus
parents: 122
diff changeset
   970
    xCol := (self xOfCol:cursorCol inVisibleLine:cursorLine) - leftOffset.
claus
parents: 122
diff changeset
   971
    (xCol > (width * (5/6))) ifTrue:[
127
claus
parents: 125
diff changeset
   972
	newOffset := leftOffset + (width // 2).
125
claus
parents: 122
diff changeset
   973
    ] ifFalse:[
127
claus
parents: 125
diff changeset
   974
	(xCol < (width * (1/6))) ifTrue:[
claus
parents: 125
diff changeset
   975
	    newOffset := 0 max: leftOffset - (width // 2).
claus
parents: 125
diff changeset
   976
	] ifFalse:[
claus
parents: 125
diff changeset
   977
	    newOffset := leftOffset
claus
parents: 125
diff changeset
   978
	]
125
claus
parents: 122
diff changeset
   979
    ].
claus
parents: 122
diff changeset
   980
    newOffset ~~ leftOffset ifTrue:[
155
claus
parents: 144
diff changeset
   981
	self scrollHorizontalTo:newOffset.
claus
parents: 144
diff changeset
   982
"/        leftOffset := newOffset.
claus
parents: 144
diff changeset
   983
"/        self clear.
claus
parents: 144
diff changeset
   984
"/        self redraw
125
claus
parents: 122
diff changeset
   985
    ]
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   986
! !
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   987
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   988
!EditField methodsFor:'initialization'!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   989
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   990
editMenu
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   991
    |labels selectors m|
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   992
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   993
    labels := #(
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   994
		'copy'
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   995
		'cut'
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   996
		'paste'
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   997
"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   998
		'replace'
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
   999
"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1000
		'-'
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1001
		'accept'
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1002
	       ).
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1003
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1004
     selectors := #(
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1005
		 copySelection
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1006
		 cut
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1007
		 paste
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1008
"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1009
		 replace
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1010
"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1011
		 nil
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1012
		 accept
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1013
		).
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1014
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1015
    m := PopUpMenu 
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1016
	  labels:(resources array:labels)
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1017
	  selectors:selectors.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1018
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1019
    self hasSelection ifFalse:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1020
	m disableAll:#(copySelection cut)
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1021
    ].
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1022
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1023
    ^ m
19
a696fb528758 *** empty log message ***
claus
parents: 7
diff changeset
  1024
!
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
  1025
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1026
initStyle
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1027
    super initStyle.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1028
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1029
    DefaultBackgroundColor notNil ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1030
	bgColor := DefaultBackgroundColor on:device.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1031
	self viewBackground:bgColor.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1032
    ].
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1033
    fgColor := DefaultForegroundColor.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1034
    selectionFgColor := DefaultSelectionForegroundColor.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1035
    selectionBgColor := DefaultSelectionBackgroundColor.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1036
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1037
    DefaultFont notNil ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1038
	font := DefaultFont on:device
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1039
    ]
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1040
!
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
  1041
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1042
initialize
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1043
    super initialize.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1044
    self height:(font height + font descent + (topMargin * 2)).
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1045
    enabled := true.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1046
    fixedSize := true.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1047
    nFullLinesShown := 1.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1048
    nLinesShown := 1.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1049
    immediateAccept := false.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1050
"/    acceptOnLeave := false.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1051
"/    acceptOnReturn := false.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1052
    acceptOnLeave := acceptOnReturn := true.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1053
    cursorShown := true.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1054
    leaveKeys := self class defaultLeaveKeys.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1055
    cursorMovementWhenUpdating := #endOfLine
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1056
! !
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1057
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1058
!EditField methodsFor:'private'!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1059
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1060
argForChangeMessage
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1061
    "redefined to send use converted value (if I have one)"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1062
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1063
    ^ self editValue
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1064
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1065
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1066
getListFromModel
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1067
    "redefined to aquire the text via the aspectMsg - not the listMsg,
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1068
     and to ignore updates resulting from my own change."
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1069
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1070
    "
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1071
     ignore updates from my own change
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1072
    "
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1073
    lockUpdates ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1074
	lockUpdates := false.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1075
	^ self
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1076
    ].
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1077
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1078
    (model notNil and:[aspectMsg notNil]) ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1079
	self editValue:(model perform:aspectMsg).
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
  1080
    ]
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
  1081
!
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
  1082
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1083
startAutoScrollDown:y
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1084
    "no vertical scrolling in editfields"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1085
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1086
    ^ self
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1087
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1088
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1089
startAutoScrollUp:y
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1090
    "no vertical scrolling in editfields"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1091
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1092
    ^ self
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1093
!
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
  1094
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1095
textChanged
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1096
    "this is sent by mySelf (somewhere in a superclass) whenever
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1097
     my contents has changed. 
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1098
     A good place to add immediateAccept functionality and check for the
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1099
     lengthLimit."
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1100
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1101
    |string c|
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1102
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1103
    super textChanged.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1104
    string := self contents.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1105
    lengthLimit notNil ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1106
	string size > lengthLimit ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1107
	    c := cursorCol.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1108
	    self contents:(string copyTo:lengthLimit).
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1109
	    self flash.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1110
	    self cursorCol:c.
125
claus
parents: 122
diff changeset
  1111
	]
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
  1112
    ].
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1113
    immediateAccept ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1114
	self accept
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1115
    ]
105
3d064ba4a0cc *** empty log message ***
claus
parents: 97
diff changeset
  1116
!
3d064ba4a0cc *** empty log message ***
claus
parents: 97
diff changeset
  1117
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1118
visibleAt:visLineNr
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1119
    "return the string at lineNr for display.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1120
     If there is a password character, return a string consisting of those only."
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1121
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1122
    |s|
105
3d064ba4a0cc *** empty log message ***
claus
parents: 97
diff changeset
  1123
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1124
    s := super visibleAt:visLineNr.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1125
    passwordCharacter notNil ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1126
	^ String new:(s size) withAll:passwordCharacter
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1127
    ].
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1128
    ^ s
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1129
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1130
    "Modified: 6.9.1995 / 12:25:06 / claus"
0
e6a541c1c0eb Initial revision
claus
parents:
diff changeset
  1131
! !
125
claus
parents: 122
diff changeset
  1132
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1133
!EditField methodsFor:'queries'!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1134
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1135
preferredExtent
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1136
    "return the preferred extent of this view.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1137
     That is the width of the string plus some extra, 
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1138
     but not wider than half of the screen"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1139
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1140
    |string w f|
125
claus
parents: 122
diff changeset
  1141
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1142
    string := self contents.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1143
    (string isNil or:[string isBlank]) ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1144
	string := '          ' "/ just any string is ok ^ super preferredExtent
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1145
    ].
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1146
    f := font on:device.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1147
    w := ((f widthOf:string) * 1.5) rounded.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1148
    w := w min:(device width // 2).
231
014756a636e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1149
"/    ^ w @ (f height * 1.5) rounded
014756a636e3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 209
diff changeset
  1150
    ^ w @ (f height + f descent + (margin * 2)"* 1.5") rounded
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1151
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1152
    "Modified: 6.9.1995 / 19:24:06 / claus"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1153
!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1154
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1155
specClass
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1156
    self class == EditField ifTrue:[^ InputFieldSpec].
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1157
    ^ nil
125
claus
parents: 122
diff changeset
  1158
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1159
    "Modified: 5.9.1995 / 17:28:27 / claus"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1160
! !
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1161
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1162
!EditField methodsFor:'realization'!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1163
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1164
realize
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1165
    "scroll back to beginning when realized"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1166
    leftOffset := 0.
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1167
    super realize
125
claus
parents: 122
diff changeset
  1168
! !
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1169
209
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
  1170
!EditField methodsFor:'selections'!
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
  1171
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
  1172
validateNewSelection
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
  1173
     "make certain that only one line is ever selected"
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
  1174
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
  1175
     selectionEndLine > 1 ifTrue:[
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
  1176
	selectionEndLine := 2. selectionEndCol := 0
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
  1177
     ].
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
  1178
! !
7a6db7fac566 dont allow multiline selections in EditField
Claus Gittinger <cg@exept.de>
parents: 192
diff changeset
  1179
192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1180
!EditField methodsFor:'scrolling'!
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1181
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1182
makeColVisible:col inLine:line
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1183
    "dont scroll for the cursor, if its behond the text and a lengthLimit
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1184
     is present."
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1185
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1186
    lengthLimit notNil ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1187
	(col == cursorCol and:[col > lengthLimit]) ifTrue:[
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1188
	    ^ super makeColVisible:lengthLimit inLine:line
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1189
	]
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1190
    ].
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1191
    ^ super makeColVisible:col inLine:line
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1192
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1193
    "Modified: 6.9.1995 / 13:57:53 / claus"
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1194
! !
fc2fc4347d5d checkin from Browser
Claus Gittinger <cg@exept.de>
parents: 187
diff changeset
  1195