[go: up one dir, main page]

Menu

[65d1b3]: / xp1input.pas  Maximize  Restore  History

Download this file

439 lines (400 with data), 12.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
{ $Id$
Copyright (C) 1991-2001 Peter Mandrella
Copyright (C) 2000-2002 OpenXP team (www.openxp.de)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
}
{ CrossPoint - Eingaberoutinen }
{$I xpdefine.inc }
unit xp1input;
interface
uses
xpglobal,
{$IFDEF NCRT }
xpcurses,
{$ENDIF }
sysutils,typeform,keys,maus2,inout,resource,winxp,maske, xp0;
function readbutton(x,y,abs:byte; buttons:string; default:shortint;
homeend:boolean; var retkey:taste):shortint;
function ReadJN(const txt:string; default:boolean):boolean;
function ReadJNesc(const txt:string; default:boolean; var brk:boolean):boolean;
function ReadIt(width:byte; txt,buttons:string; default:shortint;
var brk:boolean):shortint;
function MiniSel(x,y: Integer; txt,auswahl:string; startpos:shortint):shortint;
procedure EditDate(x,y: Integer; const txt: atext; var zdatestr: datetimest;
var getdate,brk: boolean);
implementation
uses xp1;
{ Button-Abfrage -----------------------------------------------------}
{ x,y : Position des linken Buttons }
{ abs : Leerabstand zwischen Buttons }
{ buttons : '^Butt1,^Butt2...' }
{ default : Startwert fr p }
{ homeend : die Tasten Home/End sind zugelassen }
{ retkey : '' -> Normale Abfrage. '*' -> bei jeder unbekannten Taste }
{ wird die Taste in 'retkey' und readbutton<0 zurckgegeben }
{ '!' -> nur Anzeige der Buttons, und direkt zurck }
{ RETURN: 0 oder p bei normaler Abfrage, -p bei retkey='*' und Esc }
function readbutton(x,y,abs:byte; buttons:string; default:shortint;
homeend:boolean; var retkey:taste):shortint;
const maxbutt = 9;
var p,n,p1,i : Integer;
butt : array[1..maxbutt] of string;
butthigh : array[1..maxbutt] of byte;
buttsp : array[1..maxbutt] of byte;
bpx : array[1..maxbutt] of integer;
hot : string[maxbutt];
t : taste;
stop : boolean;
spenter : boolean;
procedure display;
var
i,bx : Integer;
begin
bx := x;
attrtxt(col.colbutton);
moff;
for i:=1 to n do begin
if buttsp[i]>0 then
bx := bx+buttsp[i];
bpx[i]:= bx;
if i=p then begin
attrtxt(col.colbuttonarr);
FWrt(bx, y, #16);
end
else
FWrt(bx, y, ' ');
attrtxt(col.colbutton);
FWrt(bx+1, y, butt[i]);
attrtxt(col.colbuttonhigh);
FWrt(bx+ButtHigh[i], y, hot[i]);
bx := bx + 1 + Length(butt[i]);
if i=p then
begin
attrtxt(col.colbuttonarr);
FWrt(bx, y, #17);
attrtxt(col.colbutton);
end
else
FWrt(bx, y, ' ');
bx := bx+abs+1;
end;
mon;
end;
procedure maus_bearbeiten;
var xx,yy,i,_x : integer;
begin
maus_gettext(xx,yy);
if (yy=y) and (xx>=x) then begin
_x:=x;
i:=1;
while (i<=n) and (xx>=_x+length(butt[i])+2+buttsp[i]) do begin
inc(_x,length(butt[i])+buttsp[i]+abs+2);
inc(i);
end;
if (i<=n) and (xx>=_x+buttsp[i]) then
if (t=mausleft) or (t=mauslmoved) then begin
p:=i; t:=#0; end else
if t=mausunleft then t:=hot[i];
end;
end;
begin
spenter:=(firstchar(buttons)='*');
if spenter then DeleteFirstChar(buttons);
Buttons := Buttons + ',';
n:=0;
repeat
p:=cPos(',',buttons);
if p>0 then begin
inc(n);
if buttons[1]='ů' then begin
i:=2; while (buttons[i]>='0') and (buttons[i]<='9') do inc(i);
buttsp[n]:=ival(copy(buttons,2,i-2));
buttons:=Mid(buttons,i);
dec(p,i-1);
end
else
buttsp[n]:=0;
butt[n]:=LeftStr(buttons,p-1);
buttons:= Mid(buttons,p+1);
p:=cPos('^',butt[n]);
if p=0 then interr('Button: kein ShortKey!');
delete(butt[n],p,1);
butthigh[n]:=p;
hot[n]:=butt[n,p];
end;
until p=0;
if retkey='!' then begin
display;
readbutton:=0;
end
else begin
hot[0]:=chr(n);
p:=default;
repeat
mauszul:=(p>1); mauszur:=(p<n);
display;
if auswahlcursor and (rbx<>0) then begin
gotoxy(rbx,rby);
repeat get(t,curon) until t<>#0#0;
end
else
if auswahlcursor then begin
gotoxy(bpx[p],y);
repeat get(t,curon) until t<>#0#0;
end
else
repeat get(t,curoff) until t<>#0#0;
stop:=false;
if (t>=mausfirstkey) and (t<=mauslastkey) then
maus_bearbeiten;
if (t=keytab) or (not spenter and (t=' ')) or (t=keyrght) then
p:=p mod n + 1
else if (t=keystab) or (t=keyleft) then
if p=1 then p:=n else dec(p)
else if homeend and (t=keyhome) then p:=1
else if homeend and (t=keyend) then p:=n
else begin
p1:=pos(UpperCase(t),UpperCase(hot));
if p1>0 then begin
p:=p1; display;
t:=keycr; end
else
if (t<>keycr) and (t<>keyesc) and (t<>#0) and (retkey='*') then
stop:=true;
end;
if spenter and (t=' ') then t:=keycr;
until (t=keycr) or (t=keyesc) or stop;
mauszul:=true; mauszur:=true;
if stop then begin
readbutton:=-p;
retkey:=t;
end
else
if t=keyesc then readbutton:=0
else readbutton:=p;
end;
rbx:=0; rby:=0;
end;
{ Button-Abfrage; liefert FALSE bei Esc }
function ReadJN(const txt:string; default:boolean):boolean;
var x,y, width: Integer;
t : taste;
begin
readjn:=default;
width:=max(22,length(txt)+5);
diabox(width,5,'',x,y);
mwrt(x+2,y+1,txt+'?');
t:='';
case readbutton(x+2,y+3,2,getres(107),iif(default,1,2),true,t) of
0,2 : readJN:=false; { ' ^Ja , ^Nein ' }
1 : readJN:=true;
end;
closebox;
end;
{ Button-Abfrage; liefert brk bei Esc }
function ReadJNesc(const txt:string; default:boolean; var brk:boolean):boolean;
var x,y, Width: Integer;
t : taste;
begin
readjnesc := default;
width:=max(22,length(txt)+5);
diabox(width,5,'',x,y);
mwrt(x+2,y+1,txt+'?');
t:='';
brk:=false;
case readbutton(x+2,y+3,2,getres(107),iif(default,1,2),true,t) of
0 : begin
readJNesc:=false;
brk:=true;
end;
2 : readJNesc:=false;
1 : readJNesc:=true;
end;
closebox;
end;
function ReadIt(width:byte; txt,buttons:string; default:shortint;
var brk:boolean):shortint;
var x,y : Integer;
t : taste;
r : shortint;
begin
diabox(width,5,'',x,y);
mwrt(x+2,y+1,txt);
t:='';
brk:=false;
r:=readbutton(x+2,y+3,2,buttons,default,true,t);
brk:=(r=0);
ReadIt:=r;
closebox;
end;
{ Auswahl-Fenster ------------------ }
{ x,y=0 -> zentrieren }
{ auswahl = ^Punkt1,^Punkt2,... }
{ startpos = Default; < 0 -> Checker }
function MiniSel(x,y: Integer; txt,auswahl:string; startpos:shortint):shortint;
const maxsel = 20;
var width,height : Integer;
n,p,p1,ml : shortint;
sel : array[1..maxsel] of string;
selhigh : array[1..maxsel] of byte;
hot : string[maxsel];
t : taste;
checker : boolean;
poutside : boolean;
procedure display;
var i : integer;
ch : char;
begin
moff;
for i:=1 to n do begin
if checker and (i=startpos) then ch:='ű'
else ch:=' ';
if (hot[i]=#0) or (i=p) then begin
if i=p then attrtxt(col.colselbar)
else attrtxt(col.colselbox);
FWrt(x+1,y+i,ch+forms(sel[i],ml+1));
end
else begin
attrtxt(col.colselbox);
FWrt(x+1,y+i,forms(ch+sel[i], ml+2));
attrtxt(col.colselhigh);
FWrt(x+1+selhigh[i], y+i, sel[i][selhigh[i]]);
end;
end;
mon;
end;
procedure maus_bearbeiten;
var inside : boolean;
xx,yy : integer;
begin
maus_gettext(xx,yy);
inside:=(xx>x) and (xx<=x+ml+2) and (yy>y) and (yy<=y+n);
if inside then begin
if (t=mausleft) or (t=mauslmoved) then
p:=yy-y else
if t=mausunright then
poutside:=false else
if t=mausunleft then
t:=keycr;
end
else
if (t=mausleft) or (t=mausright) or (t=mauslmoved) or (t=mausrmoved) then
poutside:=true else
if (t=mausunleft) and poutside then t:=keycr else
if (t=mausunright) and poutside then t:=keyesc;
end;
begin
auswahl := auswahl + ',';
n:=0; ml:=0;
poutside:=false;
repeat
p:=cPos(',',auswahl);
if p>0 then begin
inc(n);
sel[n]:=LeftStr(auswahl,p-1);
auswahl:=Mid(auswahl,p+1);
p:=cPos('^',sel[n]);
if p=0 then begin
selhigh[n]:=0; hot[n]:=#0;
p:=1;
end
else begin
delete(sel[n],p,1);
selhigh[n]:=p;
hot[n]:=sel[n][p];
end;
ml:=max(max(ml,length(sel[n])),max(ml,length(txt))+1);
end;
until p=0;
hot[0]:=chr(n);
checker:=(startpos<0); startpos:=abs(startpos);
maus_noinside;
width:=ml+4; height:=n+2;
if x=0 then getpos(width,height,x,y);
blindon(true);
attrtxt(col.colselrahmen);
forcecolor:=true;
wpushs(x,x+width-1,y,y+height-1,'');
if txt<>'' then mwrt(x+2,y,' '+txt+' ');
forcecolor:=false;
p:=min(startpos,n);
repeat
mauszuo:=(p>1); mauszuu:=(p<n);
display;
if auswahlcursor then begin
gotoxy(x+1,y+p);
get(t,curon);
end
else
get(t,curoff);
if (t>=mausfirstkey) and (t<=mauslastkey) then
maus_bearbeiten;
if (t=keyup) or (t=keystab) then
if p=1 then p:=n else dec(p);
if (t=keydown) or (t=keytab) then p:=p mod n + 1;
if t=keyhome then p:=1;
if t=keyend then p:=n;
if checker and (t=' ') then startpos:=p;
p1:=pos(UpperCase(t),UpperCase(hot));
if p1>0 then begin
p:=p1; t:=keycr; end;
until (t=keycr) or (t=keyesc);
mauszuo:=true; mauszuu:=true;
if (t=keyesc) then MiniSel:=-p
else MiniSel:=p;
CloseBox;
maus_popinside;
end;
procedure EditDate(x,y: Integer; const txt: atext; var zdatestr: datetimest;
var getdate,brk: boolean);
var width,height,i : byte;
SDate,STime: String;
begin
SDate:=fdat(zdatestr);
STime:=ftime(zdatestr);
width:=length(txt)+17;
if getdate then
begin
// REALLY bad style. Should definitely be rewritten.
if (txt[1]='N') and (length(getres2(452,2))+13 > width) then
width:=length(getres2(452,2))+13
else if length(getres2(2720,5))+13 > width then
width:=length(getres2(2720,5))+13;
end;
height:=iif(Getdate,6,4);
if x=0 then getpos(width,height,x,y);
blindon(true);
attrtxt(col.coldiarahmen);
forcecolor:=true;
wpushs(x,x+width-1,y,y+height-1,'');
forcecolor:=false;
openmask(x+1,x+length(txt)+10,y+1,y+height-2,false);
maskrahmen(0,0,0,0,0);
madddate(3,1,txt,SDate,false,false);
maddtime(length(txt)-length(getres2(2720,4))+3,2,getres2(2720,4),STime,false);
if getdate then begin
getdate:=false;
maddbool(3,4,iifs(txt[1]='N',getres2(452,2),getres2(2720,5)),getdate);
end;
readmask(brk);
closemask;
wpop;
blindoff;
if not brk then begin
zdatestr:=copy(SDate,7,2)+copy(SDate,4,2)+copy(SDate,1,2)+
copy(STime,1,2)+copy(STime,4,2);
for i:=1 to length(zdatestr) do
if zdatestr[i]=' ' then zdatestr[i]:='0';
end;
end;
end.