The R Project SVN R

Rev

Rev 9205 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9205 Rev 9212
Line 36... Line 36...
36
#include "rui.h"
36
#include "rui.h"
37
 
37
 
38
static dataeditor de;
38
static dataeditor de;
39
static ConsoleData p;
39
static ConsoleData p;
40
 
40
 
41
extern int R_de_up;
41
static int R_de_up;
42
 
42
 
43
#ifndef max
43
#ifndef max
44
#define max(a, b) (((a)>(b))?(a):(b))
44
#define max(a, b) (((a)>(b))?(a):(b))
45
#endif
45
#endif
46
#ifndef min
46
#ifndef min
Line 56... Line 56...
56
static void bell();
56
static void bell();
57
static void cleararea(int, int, int, int, rgb);
57
static void cleararea(int, int, int, int, rgb);
58
static void clearrect();
58
static void clearrect();
59
static void closerect();
59
static void closerect();
60
static void clearwindow();
60
static void clearwindow();
61
void de_closewin();
61
static void de_closewin();
62
static void copyarea(int, int, int, int);
62
static void copyarea(int, int, int, int);
63
static void copyH(int, int, int);
63
static void copyH(int, int, int);
64
static void deredraw();
64
static void deredraw();
65
static void eventloop();
65
static void eventloop();
66
static void downlightrect();
66
static void downlightrect();
Line 79... Line 79...
79
static void de_popupmenu(int, int, int);
79
static void de_popupmenu(int, int, int);
80
static void printlabs();
80
static void printlabs();
81
static void printrect(int, int);
81
static void printrect(int, int);
82
static void printstring(char*, int, int, int, int);
82
static void printstring(char*, int, int, int, int);
83
static void printelt(SEXP, int, int, int);
83
static void printelt(SEXP, int, int, int);
-
 
84
static void setcellwidths();
-
 
85
 
-
 
86
static dataeditor newdataeditor();
84
void de_copy(control c);
87
static void de_copy(control c);
85
void de_paste(control c);
88
static void de_paste(control c);
86
void de_delete(control c);
89
static void de_delete(control c);
87
extern menuitem de_mvw;
90
static menuitem de_mvw;
88
 
91
 
89
static SEXP inputlist;  /* each element is a vector for that row */
92
static SEXP inputlist;  /* each element is a vector for that row */
90
static SEXP ssNA_STRING;
93
static SEXP ssNA_STRING;
91
static double ssNA_REAL;
94
static double ssNA_REAL;
92
 
95
 
Line 133... Line 136...
133
static int xmaxused, ymaxused;
136
static int xmaxused, ymaxused;
134
static int oldWIDTH=0, oldHEIGHT=0;
137
static int oldWIDTH=0, oldHEIGHT=0;
135
static int nboxchars=0;
138
static int nboxchars=0;
136
 
139
 
137
 
140
 
138
char *demenuitems[20];
-
 
139
 
-
 
140
 
-
 
141
void R_ProcessEvents(); /* in system.c */
141
void R_ProcessEvents(); /* in system.c */
142
 
142
 
143
static void eventloop()
143
static void eventloop()
144
{
144
{
145
    while (R_de_up) R_ProcessEvents();
145
    while (R_de_up) R_ProcessEvents();
Line 174... Line 174...
174
    ssNA_REAL = -NA_REAL;
174
    ssNA_REAL = -NA_REAL;
175
    tvec = allocVector(REALSXP, 1);
175
    tvec = allocVector(REALSXP, 1);
176
    REAL(tvec)[0] = ssNA_REAL;
176
    REAL(tvec)[0] = ssNA_REAL;
177
    PROTECT(ssNA_STRING = coerceVector(tvec, STRSXP)); nprotect++;
177
    PROTECT(ssNA_STRING = coerceVector(tvec, STRSXP)); nprotect++;
178
    bwidth = 0;
178
    bwidth = 0;
179
    hwidth = 0;
179
    hwidth = 5;
180
 
180
 
181
    /* setup inputlist  */
181
    /* setup inputlist  */
182
 
182
 
183
    if (indata != R_NilValue) {
183
    if (indata != R_NilValue) {
184
	xmaxused = 0; ymaxused = 0;
184
	xmaxused = 0; ymaxused = 0;
Line 277... Line 277...
277
 
277
 
278
/* Window Drawing Routines */
278
/* Window Drawing Routines */
279
 
279
 
280
static rgb bbg;
280
static rgb bbg;
281
 
281
 
282
 
-
 
283
void drawwindow()
282
static void setcellwidths()
284
{
283
{
285
    int i, w, dw;
284
    int i, w, dw;
286
 
285
 
287
    /* might have resized */
-
 
288
    windowWidth = w = 2*bwidth + boxw[0] + BOXW(colmin);
286
    windowWidth = w = 2*bwidth + boxw[0] + BOXW(colmin);
289
    nwide = 2;
287
    nwide = 2;
290
    for (i = 2; i < 100; i++) { /* 100 on-screen columns cannot occur */
288
    for (i = 2; i < 100; i++) { /* 100 on-screen columns cannot occur */
291
	dw = BOXW(i + colmin - 1);
289
	dw = BOXW(i + colmin - 1);
292
	if((w += dw) > WIDTH) {
290
	if((w += dw) > WIDTH) {
293
	    nwide = i;
291
	    nwide = i;
294
	    windowWidth = w - dw;
292
	    windowWidth = w - dw;
295
	    break;
293
	    break;
296
	}
294
	}
297
    }
295
    }
-
 
296
}
-
 
297
 
-
 
298
 
-
 
299
static void drawwindow()
-
 
300
{
-
 
301
    int i;
-
 
302
 
-
 
303
    /* might have resized */
-
 
304
    setcellwidths();
298
    nhigh = (HEIGHT - 2 * bwidth - hwidth) / box_h;
305
    nhigh = (HEIGHT - 2 * bwidth - hwidth) / box_h;
299
    windowHeight = nhigh * box_h + 2 * bwidth;
306
    windowHeight = nhigh * box_h + 2 * bwidth + hwidth;
300
    oldWIDTH = WIDTH;
307
    oldWIDTH = WIDTH;
301
    oldHEIGHT = HEIGHT;
308
    oldHEIGHT = HEIGHT;
302
    
309
    
303
    clearwindow();
310
    clearwindow();
304
 
311
 
Line 317... Line 324...
317
    gchangescrollbar(de, VWINSB, rowmin-1, ymaxused, nhigh, 0);
324
    gchangescrollbar(de, VWINSB, rowmin-1, ymaxused, nhigh, 0);
318
    gchangescrollbar(de, HWINSB, colmin-1, xmaxused, nwide, 0);
325
    gchangescrollbar(de, HWINSB, colmin-1, xmaxused, nwide, 0);
319
    highlightrect();
326
    highlightrect();
320
}
327
}
321
 
328
 
322
void doHscroll(int oldcol)
329
static void doHscroll(int oldcol)
323
{
330
{
324
    int i, w, dw;
331
    int i, dw;
325
    int oldnwide = nwide, oldwindowWidth = windowWidth;
332
    int oldnwide = nwide, oldwindowWidth = windowWidth;
326
 
333
 
327
    /* horizontal re-position */
334
    /* horizontal re-position */
328
    windowWidth = w = 2*bwidth + boxw[0] + BOXW(colmin);
-
 
329
    nwide = 2;
335
    setcellwidths();
330
    for (i = 2; i < 100; i++) {
-
 
331
	dw = BOXW(i + colmin - 1);
-
 
332
	if((w += dw) > WIDTH) {
-
 
333
	    nwide = i;
-
 
334
	    windowWidth = w - dw;
-
 
335
	    break;
-
 
336
	}
-
 
337
    }
-
 
338
    colmax = colmin + (nwide - 2);
336
    colmax = colmin + (nwide - 2);
339
    if (oldcol < colmin) { /* drop oldcol...colmin-1 */
337
    if (oldcol < colmin) { /* drop oldcol...colmin-1 */
340
	dw = boxw[0];
338
	dw = boxw[0];
341
	for (i = oldcol; i < colmin; i++) dw += BOXW(i);
339
	for (i = oldcol; i < colmin; i++) dw += BOXW(i);
342
	copyH(dw, boxw[0], oldwindowWidth - dw + 1);
340
	copyH(dw, boxw[0], oldwindowWidth - dw + 1);
Line 357... Line 355...
357
}
355
}
358
 
356
 
359
/* find_coords finds the coordinates of the upper left corner of the
357
/* find_coords finds the coordinates of the upper left corner of the
360
   given cell on the screen: row and col are on-screen coords */
358
   given cell on the screen: row and col are on-screen coords */
361
 
359
 
362
void find_coords(int row, int col, int *xcoord, int *ycoord)
360
static void find_coords(int row, int col, int *xcoord, int *ycoord)
363
{
361
{
364
    int i, w;
362
    int i, w;
365
    w = bwidth;
363
    w = bwidth;
366
    if (col > 0) w += boxw[0];
364
    if (col > 0) w += boxw[0];
367
    for(i = 1; i < col; i ++) w += BOXW(i + colmin - 1);
365
    for(i = 1; i < col; i ++) w += BOXW(i + colmin - 1);
Line 369... Line 367...
369
    *ycoord = bwidth + hwidth + box_h * row;
367
    *ycoord = bwidth + hwidth + box_h * row;
370
}
368
}
371
 
369
 
372
/* draw the window with the top left box at column wcol and row wrow */
370
/* draw the window with the top left box at column wcol and row wrow */
373
 
371
 
374
void jumpwin(int wcol, int wrow)
372
static void jumpwin(int wcol, int wrow)
375
{
373
{
376
    if (wcol < 0 || wrow < 0) {
374
    if (wcol < 0 || wrow < 0) {
377
	bell();
375
	bell();
378
	return;
376
	return;
379
    }
377
    }
Line 383... Line 381...
383
	rowmin = wrow;
381
	rowmin = wrow;
384
	deredraw();
382
	deredraw();
385
    } else highlightrect();
383
    } else highlightrect();
386
}
384
}
387
 
385
 
388
void advancerect(int which)
386
static void advancerect(int which)
389
{
387
{
390
 
388
 
391
    /* if we are in the header, changing a name then only down is
389
    /* if we are in the header, changing a name then only down is
392
       allowed */
390
       allowed */
393
    if (crow < 1 && which != DOWN) {
391
    if (crow < 1 && which != DOWN) {
Line 491... Line 489...
491
    return res;
489
    return res;
492
}
490
}
493
 
491
 
494
 
492
 
495
/* whichcol is absolute col no, col is position on screen */
493
/* whichcol is absolute col no, col is position on screen */
496
void drawcol(int whichcol)
494
static void drawcol(int whichcol)
497
{
495
{
498
    int i, src_x, src_y, len, col = whichcol - colmin + 1, bw = BOXW(whichcol);
496
    int i, src_x, src_y, len, col = whichcol - colmin + 1, bw = BOXW(whichcol);
499
    char *clab;
497
    char *clab;
500
    SEXP tmp;
498
    SEXP tmp;
501
 
499
 
Line 519... Line 517...
519
    }
517
    }
520
}
518
}
521
 
519
 
522
 
520
 
523
/* whichrow is absolute row no */
521
/* whichrow is absolute row no */
524
void drawrow(int whichrow)
522
static void drawrow(int whichrow)
525
{
523
{
526
    int i, src_x, src_y, lenip, row = whichrow - rowmin + 1, w;
524
    int i, src_x, src_y, lenip, row = whichrow - rowmin + 1, w;
527
    char rlab[15];
525
    char rlab[15];
528
    SEXP tvec;
526
    SEXP tvec;
529
 
527
 
Line 555... Line 553...
555
   spreadsheet in row ssrow and col sscol */
553
   spreadsheet in row ssrow and col sscol */
556
 
554
 
557
/* WARNING: This has no check that you're not beyond the end of the
555
/* WARNING: This has no check that you're not beyond the end of the
558
   vector. Caller must check. */
556
   vector. Caller must check. */
559
 
557
 
560
void printelt(SEXP invec, int vrow, int ssrow, int sscol)
558
static void printelt(SEXP invec, int vrow, int ssrow, int sscol)
561
{
559
{
562
    char *strp;
560
    char *strp;
563
    PrintDefaults(R_NilValue);
561
    PrintDefaults(R_NilValue);
564
    if (TYPEOF(invec) == REALSXP) {
562
    if (TYPEOF(invec) == REALSXP) {
565
	if (REAL(invec)[vrow] != ssNA_REAL) {
563
	if (REAL(invec)[vrow] != ssNA_REAL) {
Line 596... Line 594...
596
	} else
594
	} else
597
	printstring("", 0, whichrow,  whichcol, 0);
595
	printstring("", 0, whichrow,  whichcol, 0);
598
    }
596
    }
599
}
597
}
600
 
598
 
601
void jumppage(int dir)
599
static void jumppage(int dir)
602
{
600
{
603
    int i, w, oldcol, wcol;
601
    int i, w, oldcol, wcol;
604
 
602
 
605
    switch (dir) {
603
    switch (dir) {
606
    case UP:
604
    case UP:
Line 638... Line 636...
638
	break;
636
	break;
639
    }
637
    }
640
}
638
}
641
/* draw a rectangle, used to highlight/downlight the current box */
639
/* draw a rectangle, used to highlight/downlight the current box */
642
 
640
 
643
void printrect(int lwd, int fore)
641
static void printrect(int lwd, int fore)
644
{
642
{
645
    int x, y;
643
    int x, y;
646
    find_coords(crow, ccol, &x, &y);
644
    find_coords(crow, ccol, &x, &y);
647
    drawrectangle(x + lwd - 1, y + lwd -1,
645
    drawrectangle(x + lwd - 1, y + lwd -1,
648
		  BOXW(ccol+colmin-1) - lwd + 1,
646
		  BOXW(ccol+colmin-1) - lwd + 1,
649
		  box_h - lwd + 1, lwd, fore);
647
		  box_h - lwd + 1, lwd, fore);
650
}
648
}
651
 
649
 
652
void downlightrect()
650
static void downlightrect()
653
{
651
{
654
    printrect(2, 0);
652
    printrect(2, 0);
655
    printrect(1, 1);
653
    printrect(1, 1);
656
}
654
}
657
 
655
 
658
void highlightrect()
656
static void highlightrect()
659
{
657
{
660
    printrect(2, 1);
658
    printrect(2, 1);
661
}
659
}
662
 
660
 
663
 
661
 
Line 709... Line 707...
709
/* close up the entry to a cell, put the value that has been entered
707
/* close up the entry to a cell, put the value that has been entered
710
   into the correct place and as the correct type */
708
   into the correct place and as the correct type */
711
 
709
 
712
extern double R_strtod(char *c, char **end); /* in coerce.c */
710
extern double R_strtod(char *c, char **end); /* in coerce.c */
713
 
711
 
714
void closerect()
712
static void closerect()
715
{
713
{
716
    SEXP cvec, c0vec, tvec;
714
    SEXP cvec, c0vec, tvec;
717
    int wcol = ccol + colmin - 1, wrow = rowmin + crow - 1, wrow0;
715
    int wcol = ccol + colmin - 1, wrow = rowmin + crow - 1, wrow0;
718
 
716
 
719
    *bufp = '\0';
717
    *bufp = '\0';
Line 774... Line 772...
774
 
772
 
775
/* print a null terminated string, check to see if it is longer than
773
/* print a null terminated string, check to see if it is longer than
776
   the print area and print it, left adjusted if necessary; clear the
774
   the print area and print it, left adjusted if necessary; clear the
777
   area of previous text; */
775
   area of previous text; */
778
 
776
 
779
void printstring(char *ibuf, int buflen, int row, int col, int left)
777
static void printstring(char *ibuf, int buflen, int row, int col, int left)
780
{
778
{
781
    int x_pos, y_pos, bw, fw;
779
    int x_pos, y_pos, bw, fw;
782
    char buf[45], *pc = buf;
780
    char buf[45], *pc = buf;
783
 
781
 
784
    find_coords(row, col, &x_pos, &y_pos);
782
    find_coords(row, col, &x_pos, &y_pos);
785
    if (col == 0) bw = boxw[0]; else bw = BOXW(col+colmin-1);
783
    if (col == 0) bw = boxw[0]; else bw = BOXW(col+colmin-1);
786
    cleararea(x_pos + 2, y_pos + 2, bw - 3, box_h - 3,
784
    cleararea(x_pos + 1, y_pos + 1, bw - 1, box_h - 1,
787
	      (row==0 || col==0) ? bbg:p->bg);
785
	      (row==0 || col==0) ? bbg:p->bg);
788
    strncpy(buf, ibuf, buflen);
786
    strncpy(buf, ibuf, buflen);
789
    buf[buflen] = '\0';
787
    buf[buflen] = '\0';
790
    fw = (bw - 8)/FW;
788
    fw = (bw - 8)/FW;
791
    if (buflen > fw) {
789
    if (buflen > fw) {
Line 798... Line 796...
798
	}
796
	}
799
    }
797
    }
800
    de_drawtext(x_pos + text_xoffset, y_pos - text_yoffset, pc);
798
    de_drawtext(x_pos + text_xoffset, y_pos - text_yoffset, pc);
801
}
799
}
802
 
800
 
803
void clearrect()
801
static void clearrect()
804
{
802
{
805
    int x_pos, y_pos;
803
    int x_pos, y_pos;
806
    find_coords(crow, ccol, &x_pos, &y_pos);
804
    find_coords(crow, ccol, &x_pos, &y_pos);
807
    cleararea(x_pos, y_pos, BOXW(ccol+colmin-1), box_h, p->bg);
805
    cleararea(x_pos, y_pos, BOXW(ccol+colmin-1), box_h, p->bg);
808
}
806
}
Line 811... Line 809...
811
   depending on the current column type, only printing characters
809
   depending on the current column type, only printing characters
812
   should get this far */
810
   should get this far */
813
 
811
 
814
/* --- Not true! E.g. ESC ends up in here... */
812
/* --- Not true! E.g. ESC ends up in here... */
815
 
813
 
816
void handlechar(char *text)
814
static void handlechar(char *text)
817
{
815
{
818
    int c = text[0];
816
    int c = text[0];
819
 
817
 
820
    if ( c == '\033' ) {
818
    if ( c == '\033' ) {
821
	CellModified = 0;
819
	CellModified = 0;
Line 881... Line 879...
881
 
879
 
882
 donehc:
880
 donehc:
883
    bell();
881
    bell();
884
}
882
}
885
 
883
 
886
void printlabs()
884
static void printlabs()
887
{
885
{
888
    char clab[10], *p;
886
    char clab[10], *p;
889
    int i;
887
    int i;
890
 
888
 
891
    for (i = colmin; i <= colmax; i++) {
889
    for (i = colmin; i <= colmax; i++) {
Line 896... Line 894...
896
	sprintf(clab, "%4d", i);
894
	sprintf(clab, "%4d", i);
897
	printstring(clab, strlen(clab), i - rowmin + 1, 0, 0);
895
	printstring(clab, strlen(clab), i - rowmin + 1, 0, 0);
898
    }
896
    }
899
}
897
}
900
 
898
 
901
              /* ================ Windows-specific ================ */
899
              /* ================ GraphApp-specific ================ */
902
 
900
 
903
static void bell()
901
static void bell()
904
{
902
{
905
    gabeep();
903
    gabeep();
906
}
904
}
Line 934... Line 932...
934
    gdrawstr(de, p->f, p->fg, pt(xpos, ypos), text);
932
    gdrawstr(de, p->f, p->fg, pt(xpos, ypos), text);
935
}
933
}
936
 
934
 
937
/* Keypress callbacks */
935
/* Keypress callbacks */
938
 
936
 
939
void de_normalkeyin(control c, int k)
937
static void de_normalkeyin(control c, int k)
940
{
938
{
941
    int i, st;
939
    int i, st;
942
    char text[1];
940
    char text[1];
943
 
941
 
944
    st = ggetkeystate();
942
    st = ggetkeystate();
Line 1001... Line 999...
1001
	handlechar(text);
999
	handlechar(text);
1002
    }
1000
    }
1003
 
1001
 
1004
}
1002
}
1005
 
1003
 
1006
void de_ctrlkeyin(control c, int key)
1004
static void de_ctrlkeyin(control c, int key)
1007
{
1005
{
1008
    int st, i;
1006
    int st, i;
1009
 
1007
 
1010
    st = ggetkeystate();
1008
    st = ggetkeystate();
1011
    if ((p->chbrk) && (key == p->chbrk) &&
1009
    if ((p->chbrk) && (key == p->chbrk) &&
Line 1087... Line 1085...
1087
    return prev;
1085
    return prev;
1088
}
1086
}
1089
 
1087
 
1090
static int online, clickline;
1088
static int online, clickline;
1091
 
1089
 
1092
void de_mousedown(control c, int buttons, point xy)
1090
static void de_mousedown(control c, int buttons, point xy)
1093
{
1091
{
1094
    int xw, yw, wcol=0, wrow, i, w;
1092
    int xw, yw, wcol=0, wrow, i, w;
1095
 
1093
 
1096
    if (buttons & LeftButton) {
1094
    if (buttons & LeftButton) {
1097
	xw = xy.x;
1095
	xw = xy.x;
Line 1176... Line 1174...
1176
	highlightrect();
1174
	highlightrect();
1177
	return;
1175
	return;
1178
    }
1176
    }
1179
}
1177
}
1180
 
1178
 
1181
void de_mouseup(control c, int buttons, point xy)
1179
static void de_mouseup(control c, int buttons, point xy)
1182
{
1180
{
1183
    int xw, bw, i, w;
1181
    int xw, bw, i, w;
1184
 
1182
 
1185
    if (online) {
1183
    if (online) {
1186
	xw = xy.x;
1184
	xw = xy.x;
Line 1193... Line 1191...
1193
	gsetcursor(de, ArrowCursor);
1191
	gsetcursor(de, ArrowCursor);
1194
	deredraw();
1192
	deredraw();
1195
    }
1193
    }
1196
}
1194
}
1197
 
1195
 
1198
void de_redraw(control c, rect r)
1196
static void de_redraw(control c, rect r)
1199
{
1197
{
1200
    deredraw();
1198
    deredraw();
1201
}
1199
}
1202
 
1200
 
1203
static void deredraw()
1201
static void deredraw()
1204
{
1202
{
1205
    int i, w, dw;
1203
    int i;
1206
 
1204
 
1207
    if (WIDTH != oldWIDTH || HEIGHT != oldHEIGHT) {
1205
    if (WIDTH != oldWIDTH || HEIGHT != oldHEIGHT) {
1208
	drawwindow();
1206
	drawwindow();
1209
	return;
1207
	return;
1210
    }
1208
    }
1211
    windowWidth = w = 2*bwidth + boxw[0] + BOXW(colmin);
-
 
1212
    nwide = 2;
1209
    setcellwidths();
1213
    for (i = 2; i < 100; i++) { /* 100 on-screen columns cannot occur */
-
 
1214
	dw = BOXW(i + colmin - 1);
-
 
1215
	if((w += dw) > WIDTH) {
-
 
1216
	    nwide = i;
-
 
1217
	    windowWidth = w - dw;
-
 
1218
	    break;
-
 
1219
	}
-
 
1220
    }
-
 
1221
 
1210
 
1222
    gfillrect(de, bbg, rect(0, 0, windowWidth, box_h));
1211
    gfillrect(de, bbg, rect(0, 0, windowWidth, box_h));
1223
    gfillrect(de, bbg, rect(0, 0, boxw[0], windowHeight));
1212
    gfillrect(de, bbg, rect(0, 0, boxw[0], windowHeight));
1224
 
1213
 
1225
    for (i = 1; i < nhigh; i++)
1214
    for (i = 1; i < nhigh; i++)
Line 1231... Line 1220...
1231
	for (i = colmin; i <= colmax; i++) drawcol(i);
1220
	for (i = colmin; i <= colmax; i++) drawcol(i);
1232
    gfillrect(de, p->bg, rect(windowWidth+1, 0, WIDTH-windowWidth-1, HEIGHT));
1221
    gfillrect(de, p->bg, rect(windowWidth+1, 0, WIDTH-windowWidth-1, HEIGHT));
1233
    highlightrect();
1222
    highlightrect();
1234
}
1223
}
1235
 
1224
 
1236
void de_closewin()
1225
static void de_closewin()
1237
{
1226
{
1238
    closerect();
1227
    closerect();
1239
    hide(de);
1228
    hide(de);
1240
    del(de);
1229
    del(de);
1241
}
1230
}
1242
 
1231
 
1243
#include <windows.h>
-
 
1244
extern HDC get_context(dataeditor);
-
 
1245
 
-
 
1246
static void copyarea(int src_x, int src_y, int dest_x, int dest_y)
1232
static void copyarea(int src_x, int src_y, int dest_x, int dest_y)
1247
{
1233
{
1248
    int mx = max(src_x, dest_x), my = max(src_y, dest_y);
1234
    int mx = max(src_x, dest_x), my = max(src_y, dest_y);
1249
    HDC dc = get_context(de);
-
 
1250
    BitBlt(dc, dest_x, dest_y,
1235
    copyrect(de, pt(dest_x, dest_y),
1251
	   windowWidth - mx, windowHeight - my,
1236
	     rect(src_x, src_y, windowWidth - mx, windowHeight - my));
1252
	   dc, src_x, src_y, SRCCOPY);
-
 
1253
}
1237
}
1254
 
1238
 
1255
static void copyH(int src_x, int dest_x, int width)
1239
static void copyH(int src_x, int dest_x, int width)
1256
{
1240
{
1257
    HDC dc = get_context(de);
1241
    copyrect(de, pt(dest_x, hwidth), 
1258
    BitBlt(dc, dest_x, hwidth, width, windowHeight - hwidth,
1242
	     rect(src_x, hwidth, width, windowHeight - hwidth));
1259
	   dc, src_x, hwidth, SRCCOPY);
-
 
1260
}
1243
}
1261
 
1244
 
-
 
1245
#include <windows.h> /* for COLOR_BTNFACE */
-
 
1246
 
1262
static int  initwin()
1247
static int  initwin()
1263
{
1248
{
1264
    int i, w, dw;
1249
    int i;
1265
    rect r;
1250
    rect r;
1266
 
1251
 
1267
    demenuitems[0] = "";
-
 
1268
    de = newdataeditor();
1252
    de = newdataeditor();
1269
    if(!de) return 1;
1253
    if(!de) return 1;
1270
    p = getdata(de);
1254
    p = getdata(de);
1271
 
1255
 
1272
    nboxchars = asInteger(GetOption(install("de.cellwidth"), R_GlobalEnv));
1256
    nboxchars = asInteger(GetOption(install("de.cellwidth"), R_GlobalEnv));
Line 1276... Line 1260...
1276
    boxw[0] = 5*FW + 8;
1260
    boxw[0] = 5*FW + 8;
1277
    for(i = 1; i < 100; i++) boxw[i] = get_col_width(i)*FW + 8;
1261
    for(i = 1; i < 100; i++) boxw[i] = get_col_width(i)*FW + 8;
1278
    box_h = FH + 4;
1262
    box_h = FH + 4;
1279
    text_xoffset = 5;
1263
    text_xoffset = 5;
1280
    text_yoffset = -3;
1264
    text_yoffset = -3;
1281
    windowWidth = w = 2*bwidth + boxw[0] + boxw[1];
-
 
1282
    nwide = 2;
1265
    setcellwidths();
1283
    for (i = 2; i < 100; i++) {
-
 
1284
	if((w += boxw[i]) > WIDTH) {
-
 
1285
	    nwide = i;
-
 
1286
	    windowWidth = w - boxw[i];
-
 
1287
	    break;
-
 
1288
	}
-
 
1289
    }
-
 
1290
    nhigh = (HEIGHT - 2 * bwidth - hwidth) / box_h;
1266
    nhigh = (HEIGHT - 2 * bwidth - hwidth) / box_h;
1291
    windowHeight = nhigh * box_h + 2 * bwidth - hwidth;
1267
    windowHeight = nhigh * box_h + 2 * bwidth + hwidth;
1292
    r = getrect(de);
1268
    r = getrect(de);
1293
    r.width = windowWidth + 3;
1269
    r.width = windowWidth + 3;
1294
    r.height = windowHeight + 3;
1270
    r.height = windowHeight + 3;
1295
    resize(de, r);
1271
    resize(de, r);
1296
 
1272
 
Line 1301... Line 1277...
1301
    ccol = 1;
1277
    ccol = 1;
1302
    /* drawwindow(); done as repaint but
1278
    /* drawwindow(); done as repaint but
1303
       decide if we need scrollbars here to avoid flashing*/
1279
       decide if we need scrollbars here to avoid flashing*/
1304
    nhigh = (HEIGHT - 2 * bwidth - hwidth) / box_h;
1280
    nhigh = (HEIGHT - 2 * bwidth - hwidth) / box_h;
1305
    gchangescrollbar(de, VWINSB, 0, ymaxused, nhigh, 0);
1281
    gchangescrollbar(de, VWINSB, 0, ymaxused, nhigh, 0);
1306
    windowWidth = w = 2*bwidth + boxw[0] + BOXW(colmin);
-
 
1307
    nwide = 2;
1282
    setcellwidths();
1308
    for (i = 2; i < 100; i++) {
-
 
1309
	dw = BOXW(i + colmin - 1);
-
 
1310
	if((w += dw) > WIDTH) {
-
 
1311
	    nwide = i;
-
 
1312
	    windowWidth = w - dw;
-
 
1313
	    break;
-
 
1314
	}
-
 
1315
    }
-
 
1316
    gchangescrollbar(de, HWINSB, 0, xmaxused, nwide, 0);    
1283
    gchangescrollbar(de, HWINSB, 0, xmaxused, nwide, 0);    
1317
    show(de);
1284
    show(de);
1318
    R_de_up = 1;
1285
    R_de_up = 1;
1319
    return 0;
1286
    return 0;
1320
}
1287
}
Line 1357... Line 1324...
1357
	LEVELS(CAR(tvec)) = levs;
1324
	LEVELS(CAR(tvec)) = levs;
1358
    }
1325
    }
1359
    TAG(tvec) = install(buf);
1326
    TAG(tvec) = install(buf);
1360
    hide(wconf);
1327
    hide(wconf);
1361
    del(wconf);
1328
    del(wconf);
1362
//    addto(de);
-
 
1363
}
1329
}
1364
 
1330
 
1365
void getscreenrect(control, rect *);
1331
extern void getscreenrect(control, rect *);
1366
 
1332
 
1367
static void nm_hit_key(window w, int key)
1333
static void nm_hit_key(window w, int key)
1368
{
1334
{
1369
    if(key == '\n') popupclose(wconf);
1335
    if(key == '\n') popupclose(wconf);
1370
}
1336
}
Line 1379... Line 1345...
1379
    getscreenrect(de, &r);
1345
    getscreenrect(de, &r);
1380
    wconf = newwindow("Variable editor",
1346
    wconf = newwindow("Variable editor",
1381
		      rect(x_pos + r.x-150, y_pos + r.y-50, 300, 100),
1347
		      rect(x_pos + r.x-150, y_pos + r.y-50, 300, 100),
1382
		      Titlebar | Closebox);
1348
		      Titlebar | Closebox);
1383
    setclose(wconf, popupclose);
1349
    setclose(wconf, popupclose);
1384
    setbackground(wconf, LightGrey);
1350
    setbackground(wconf, bbg);
1385
    lwhat = newlabel("variable name", rect(10, 20, 90, 20), AlignLeft);
1351
    lwhat = newlabel("variable name", rect(10, 20, 90, 20), AlignLeft);
1386
    varname = newfield(blah, rect(100, 20, 120, 20));
1352
    varname = newfield(blah, rect(100, 20, 120, 20));
1387
    lrb = newlabel("type", rect(50, 60, 50, 20), AlignLeft);
1353
    lrb = newlabel("type", rect(50, 60, 50, 20), AlignLeft);
1388
    rb_num = newradiobutton("numeric", rect(100, 60 , 80, 20), NULL);
1354
    rb_num = newradiobutton("numeric", rect(100, 60 , 80, 20), NULL);
1389
    rb_char = newradiobutton("character", rect(180, 60 , 80, 20), NULL);
1355
    rb_char = newradiobutton("character", rect(180, 60 , 80, 20), NULL);
Line 1391... Line 1357...
1391
    if (isnumeric) check(rb_num); else check(rb_char);
1357
    if (isnumeric) check(rb_num); else check(rb_char);
1392
    setkeydown(wconf, nm_hit_key);
1358
    setkeydown(wconf, nm_hit_key);
1393
    show(wconf);
1359
    show(wconf);
1394
}
1360
}
1395
 
1361
 
1396
void de_copy(control c)
1362
static void de_copy(control c)
1397
{
1363
{
1398
    HGLOBAL hglb;
-
 
1399
    char *s, *cell;
-
 
1400
    int ll;
-
 
1401
 
-
 
1402
    cell = get_cell_text();
1364
    copystringtoclipboard(get_cell_text());
1403
    ll = strlen(cell) + 1;
-
 
1404
    if (!(hglb = GlobalAlloc(GHND, ll))){
-
 
1405
        R_ShowMessage("Insufficient memory: cell not copied to the clipboard");
-
 
1406
	return;
-
 
1407
    }
-
 
1408
    if (!(s = (char *)GlobalLock(hglb))){
-
 
1409
        R_ShowMessage("Insufficient memory: cell not copied to the clipboard");
-
 
1410
	return;
-
 
1411
    }
-
 
1412
    strcpy(s, cell);
-
 
1413
    GlobalUnlock(hglb);
-
 
1414
    if (!OpenClipboard(NULL) || !EmptyClipboard()) {
-
 
1415
        R_ShowMessage("Unable to open the clipboard");
-
 
1416
        GlobalFree(hglb);
-
 
1417
        return;
-
 
1418
    }
-
 
1419
    SetClipboardData(CF_TEXT, hglb);
-
 
1420
    CloseClipboard();
-
 
1421
}
1365
}
1422
 
1366
 
1423
void de_paste(control c)
1367
static void de_paste(control c)
1424
{
1368
{
1425
    HGLOBAL hglb;
-
 
1426
    char *p, *pc;
1369
    char *p;
1427
 
1370
 
1428
    closerect();
1371
    closerect();
1429
    if ( OpenClipboard(NULL) &&
1372
    if ( clipboardhastext() &&
1430
         (hglb = GetClipboardData(CF_TEXT)) &&
1373
	 !getstringfromclipboard(buf, 29) ) {
1431
         (pc = (char *)GlobalLock(hglb))) {
-
 
1432
	/* set current cell to first line of pc */
1374
	/* set current cell to first line of clipboard */
1433
	CellModified = 1;
1375
	CellModified = 1;
1434
	strncpy(buf, pc, 29);
-
 
1435
        GlobalUnlock(hglb);
-
 
1436
	CloseClipboard();
-
 
1437
	buf[30] = '\0';
-
 
1438
	if ((p = strchr(buf, '\n'))) *p = '\0';
1376
	if ((p = strchr(buf, '\n'))) *p = '\0';
1439
	clength = strlen(buf);
1377
	clength = strlen(buf);
1440
	bufp = buf + clength;
1378
	bufp = buf + clength;
1441
	closerect();
1379
	closerect();
1442
    }
1380
    }
1443
    highlightrect();
1381
    highlightrect();
1444
}
1382
}
1445
 
1383
 
1446
void de_delete(control c)
1384
static void de_delete(control c)
1447
{
1385
{
1448
    CellModified = 1;
1386
    CellModified = 1;
1449
    buf[0] = '\0';
1387
    buf[0] = '\0';
1450
    clength = -1;
1388
    clength = -1;
1451
    bufp = buf + clength;
1389
    bufp = buf + clength;
1452
    closerect();
1390
    closerect();
1453
    highlightrect();
1391
    highlightrect();
1454
}
1392
}
1455
 
1393
 
1456
void de_autosize(control c)
1394
static void de_autosize(control c)
1457
{
1395
{
1458
    int col = ccol + colmin - 1;
1396
    int col = ccol + colmin - 1;
1459
    if(col < 100) {
1397
    if(col < 100) {
1460
	boxw[col] = get_col_width(col)*FW + 8;
1398
	boxw[col] = get_col_width(col)*FW + 8;
1461
	deredraw();
1399
	deredraw();
1462
    }
1400
    }
1463
}
1401
}
1464
 
1402
 
1465
void de_sbf(control c, int pos)
1403
static void de_sbf(control c, int pos)
1466
{
1404
{
1467
    if (pos < 0) { /* horizontal */
1405
    if (pos < 0) { /* horizontal */
1468
	colmin = 1 + (-pos - 1);
1406
	colmin = 1 + (-pos - 1);
1469
    } else {
1407
    } else {
1470
	rowmin = 1 + pos;
1408
	rowmin = 1 + pos;
1471
	if(rowmin > ymaxused - nhigh + 2) rowmin = ymaxused - nhigh + 2;
1409
	if(rowmin > ymaxused - nhigh + 2) rowmin = ymaxused - nhigh + 2;
1472
    }
1410
    }
1473
    drawwindow();
1411
    drawwindow();
1474
}
1412
}
1475
 
1413
 
1476
extern menuitem de_mvw;
-
 
1477
static checkbox varwidths;
1414
static checkbox varwidths;
1478
 
1415
 
1479
static void vw_close(control c)
1416
static void vw_close(control c)
1480
{
1417
{
1481
    int x;
1418
    int x;
Line 1508... Line 1445...
1508
 
1445
 
1509
    devw = newwindow("Cell width(s)",
1446
    devw = newwindow("Cell width(s)",
1510
		      rect(0, 0, 250, 60),
1447
		      rect(0, 0, 250, 60),
1511
		      Titlebar | Centered | Closebox);
1448
		      Titlebar | Centered | Closebox);
1512
    setclose(devw, vw_close);
1449
    setclose(devw, vw_close);
1513
    setbackground(devw, LightGrey);
1450
    setbackground(devw, bbg);
1514
    lwhat = newlabel("Cell width", rect(10, 20, 70, 20), AlignLeft);
1451
    lwhat = newlabel("Cell width", rect(10, 20, 70, 20), AlignLeft);
1515
    sprintf(blah, "%d", nboxchars);
1452
    sprintf(blah, "%d", nboxchars);
1516
    varname = newfield(blah, rect(80, 20, 40, 20));
1453
    varname = newfield(blah, rect(80, 20, 40, 20));
1517
    varwidths = newcheckbox("variable", rect(150, 20, 80, 20), vw_callback);
1454
    varwidths = newcheckbox("variable", rect(150, 20, 80, 20), vw_callback);
1518
    if (nboxchars == 0) {
1455
    if (nboxchars == 0) {
Line 1521... Line 1458...
1521
    }
1458
    }
1522
    setkeydown(devw, vw_hit_key);
1459
    setkeydown(devw, vw_hit_key);
1523
    show(devw);
1460
    show(devw);
1524
}
1461
}
1525
 
1462
 
1526
void menudecellwidth(control m)
1463
static void menudecellwidth(control m)
1527
{
1464
{
1528
    de_popup_vw();
1465
    de_popup_vw();
1529
}
1466
}
-
 
1467
 
-
 
1468
static void deldataeditor(control m)
-
 
1469
{
-
 
1470
    freeConsoleData(getdata(m));
-
 
1471
}
-
 
1472
 
-
 
1473
static void declose(control m)
-
 
1474
{
-
 
1475
    de_closewin();
-
 
1476
    show(RConsole);
-
 
1477
    R_de_up =0;
-
 
1478
}
-
 
1479
 
-
 
1480
static void deresize(console c, rect r)
-
 
1481
FBEGIN
-
 
1482
    if (((WIDTH  == r.width) &&
-
 
1483
	 (HEIGHT == r.height)) ||
-
 
1484
	(r.width == 0) || (r.height == 0) ) /* minimize */
-
 
1485
        FVOIDRETURN;
-
 
1486
    WIDTH = r.width;
-
 
1487
    HEIGHT = r.height;
-
 
1488
FVOIDEND
-
 
1489
 
-
 
1490
static void menudehelp(control m)
-
 
1491
{
-
 
1492
    char s[] = "Navigation.\n  Keyboard: cursor keys move selection\n\tTab move right, Shift+Tab moves left\n\tPgDn or Ctrl+F: move down one screenful\n\tPgUp or Ctrl+B: move up one screenful\n\tHome: move to (1,1) cell\n\tEnd: show last rows of last column.\n   Mouse: left-click in a cell, use the scrollbar(s).\n\nEditing.\n  Type in the currently hightlighted cell\n  Double-click in a cell for an editable field\n\nMisc.\n  Ctrl-L redraws the screen, auto-resizing the columns\n  Ctrl-C copies selected cell\n  Ctrl-V pastes to selected cell\n  Right-click menu for copy, paste, autosize currently selected column\n\n";
-
 
1493
    askok(s);
-
 
1494
}
-
 
1495
 
-
 
1496
 
-
 
1497
static MenuItem DePopup[28] = {
-
 
1498
    {"Help", menudehelp, 0},
-
 
1499
    {"-", 0, 0},
-
 
1500
    {"Copy selected cell", de_copy, 0},
-
 
1501
    {"Paste selected cell", de_paste, 0},
-
 
1502
    {"Autosize column", de_autosize, 0},
-
 
1503
    {"-", 0, 0},
-
 
1504
    {"Close", declose, 0},
-
 
1505
    LASTMENUITEM
-
 
1506
};
-
 
1507
 
-
 
1508
static void demenuact(control m)
-
 
1509
{
-
 
1510
    /* use this to customize the menu */
-
 
1511
}
-
 
1512
 
-
 
1513
static void depopupact(control m)
-
 
1514
{
-
 
1515
    /* use this to customize the menu */
-
 
1516
}
-
 
1517
 
-
 
1518
 
-
 
1519
#define MCHECK(a) if (!(a)) {del(c);return NULL;}
-
 
1520
 
-
 
1521
static dataeditor newdataeditor()
-
 
1522
{
-
 
1523
    ConsoleData p;
-
 
1524
    int w, h, x, y;
-
 
1525
    dataeditor c;
-
 
1526
    menuitem m;
-
 
1527
    
-
 
1528
    p = newconsoledata((consolefn) ? consolefn : FixedFont,
-
 
1529
		       pagerrow, pagercol,
-
 
1530
		       consolefg, consoleuser, consolebg,
-
 
1531
		       DATAEDITOR);
-
 
1532
    if (!p) return NULL;
-
 
1533
 
-
 
1534
    w = WIDTH ;
-
 
1535
    h = HEIGHT;
-
 
1536
#ifdef USE_MDI
-
 
1537
    if (ismdi()) {
-
 
1538
	RECT *pR = RgetMDIsize();
-
 
1539
	x = (pR->right - w) / 3; x = x > 20 ? x:20;
-
 
1540
	y = (pR->bottom - h) / 3; y = y > 20 ? y:20;
-
 
1541
    } else {
-
 
1542
#endif
-
 
1543
	x = (devicewidth(NULL) - w) / 3;
-
 
1544
	y = (deviceheight(NULL) - h) / 3 ;
-
 
1545
#ifdef USE_MDI
-
 
1546
    }
-
 
1547
#endif
-
 
1548
    c = (dataeditor) newwindow(" Data Editor", rect(x, y, w, h),
-
 
1549
			       Document | StandardWindow | TrackMouse |
-
 
1550
			       VScrollbar | HScrollbar | Modal);
-
 
1551
    if (!c) {
-
 
1552
         freeConsoleData(p);
-
 
1553
         return NULL;
-
 
1554
    }
-
 
1555
    setdata(c, p);
-
 
1556
    if(h == 0) HEIGHT = getheight(c);
-
 
1557
    if(w == 0) WIDTH  = getwidth(c);
-
 
1558
    COLS = WIDTH / FW - 1;
-
 
1559
    ROWS = HEIGHT / FH - 1;
-
 
1560
    BORDERX = (WIDTH - COLS*FW) / 2;
-
 
1561
    BORDERY = (HEIGHT - ROWS*FH) / 2;
-
 
1562
    gsetcursor(c, ArrowCursor);
-
 
1563
    setbackground(c, consolebg);
-
 
1564
    if (ismdi() && (RguiMDI & RW_TOOLBAR)) {
-
 
1565
	/* blank toolbar to stop windows jumping around */
-
 
1566
        int btsize = 24;
-
 
1567
        control tb;
-
 
1568
        addto(c);
-
 
1569
        MCHECK(tb = newtoolbar(btsize + 4));
-
 
1570
	gsetcursor(tb, ArrowCursor);
-
 
1571
    }
-
 
1572
    MCHECK(gpopup(depopupact, DePopup));
-
 
1573
    MCHECK(m = newmenubar(demenuact));
-
 
1574
    MCHECK(newmenu("File"));
-
 
1575
/*    MCHECK(m = newmenuitem("-", 0, NULL));*/
-
 
1576
    MCHECK(m = newmenuitem("Close", 0, declose));
-
 
1577
#ifdef USE_MDI
-
 
1578
    newmdimenu();
-
 
1579
#endif
-
 
1580
    MCHECK(newmenu("Edit"));
-
 
1581
    MCHECK(m = newmenuitem("Copy  \tCTRL+C", 0, de_copy));
-
 
1582
    MCHECK(m = newmenuitem("Paste \tCTRL+V", 0, de_paste));
-
 
1583
    MCHECK(m = newmenuitem("Delete\tDEL", 0, de_delete));
-
 
1584
    MCHECK(m = newmenuitem("-", 0, NULL));
-
 
1585
    MCHECK(de_mvw = newmenuitem("Cell widths ...", 0, menudecellwidth));
-
 
1586
    MCHECK(m = newmenu("Help"));
-
 
1587
    MCHECK(newmenuitem("Data editor", 0, menudehelp));
-
 
1588
 
-
 
1589
    setdata(c, p);
-
 
1590
    setresize(c, deresize);
-
 
1591
    setredraw(c, de_redraw);
-
 
1592
    setdel(c, deldataeditor);
-
 
1593
    setclose(c, declose);
-
 
1594
    sethit(c, de_sbf);
-
 
1595
    setkeyaction(c, de_ctrlkeyin);
-
 
1596
    setkeydown(c, de_normalkeyin);
-
 
1597
    setmousedown(c, de_mousedown);
-
 
1598
    setmouseup(c, de_mouseup);
-
 
1599
    return(c);
-
 
1600
}