The R Project SVN R

Rev

Rev 46677 | Rev 46826 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 46677 Rev 46784
Line 291... Line 291...
291
}
291
}
292
 
292
 
293
 
293
 
294
/* console */
294
/* console */
295
 
295
 
-
 
296
rgb guiColors[numGuiColors] = { 
296
rgb consolebg = White, consolefg = Black, consoleuser = gaRed,
297
	White, Black, gaRed, /* consolebg, consolefg, consoleuser, */
297
    pagerhighlight = gaRed;
298
	White, Black, gaRed, /* pagerbg, pagerfg, pagerhighlight,  */
-
 
299
	White, Black, gaRed, /* dataeditbg, dataeditfg, dataedituser */
-
 
300
	White, Black         /* editorbg, editorfg                 */
-
 
301
};
298
 
302
 
299
extern int R_HistorySize;  /* from Defn.h */
303
extern int R_HistorySize;  /* from Defn.h */
300
 
304
 
301
ConsoleData
305
ConsoleData
302
newconsoledata(font f, int rows, int cols, int bufbytes, int buflines,
306
newconsoledata(font f, int rows, int cols, int bufbytes, int buflines,
303
	       rgb fg, rgb ufg, rgb bg, int kind, int buffered)
307
	       rgb *guiColors, int kind, int buffered)
304
{
308
{
305
    ConsoleData p;
309
    ConsoleData p;
306
 
310
 
307
    initapp(0, 0);
311
    initapp(0, 0);
308
    p = (ConsoleData) malloc(sizeof(struct structConsoleData));
312
    p = (ConsoleData) malloc(sizeof(struct structConsoleData));
Line 326... Line 330...
326
	p->kbuf = NULL;
330
	p->kbuf = NULL;
327
    }
331
    }
328
    p->bm = NULL;
332
    p->bm = NULL;
329
    p->rows = rows;
333
    p->rows = rows;
330
    p->cols = cols;
334
    p->cols = cols;
331
    p->fg = fg;
-
 
332
    p->bg = bg;
335
    for (int i=0; i<numGuiColors; i++)
333
    p->ufg = ufg;
336
    	p->guiColors[i] = guiColors[i];
334
    p->f = f;
337
    p->f = f;
335
    FH = fontheight(f);
338
    FH = fontheight(f);
336
    FW = fontwidth(f);
339
    FW = fontwidth(f);
337
    WIDTH = (COLS + 1) * FW;
340
    WIDTH = (COLS + 1) * FW;
338
    HEIGHT = (ROWS + 1) * FH + 1; /* +1 avoids size problems in MDI */
341
    HEIGHT = (ROWS + 1) * FH + 1; /* +1 avoids size problems in MDI */
Line 471... Line 474...
471
{
474
{
472
    wchar_t *s, *stmp, *p0;
475
    wchar_t *s, *stmp, *p0;
473
    int   insel, len, col1, d;
476
    int   insel, len, col1, d;
474
    int   c1, c2, c3, x0, y0, x1, y1;
477
    int   c1, c2, c3, x0, y0, x1, y1;
475
    rect r;
478
    rect r;
-
 
479
    int   bg, fg, highlight, base;
-
 
480
    
-
 
481
    if (p->kind == CONSOLE) base = consolebg;
-
 
482
    else if (p->kind == PAGER) base = pagerbg;
-
 
483
    else base = dataeditbg;
-
 
484
    
-
 
485
    bg = p->guiColors[base];
-
 
486
    fg = p->guiColors[base+1];
-
 
487
    highlight = p->guiColors[base+2];
476
 
488
 
477
    if ((i < 0) || (i >= NUMLINES)) return 0;
489
    if ((i < 0) || (i >= NUMLINES)) return 0;
478
    stmp = s = LINE(i);
490
    stmp = s = LINE(i);
479
    len = wcswidth(stmp);
491
    len = wcswidth(stmp);
480
    /* If there is a \r in the line, we need to preprocess it */
492
    /* If there is a \r in the line, we need to preprocess it */
Line 498... Line 510...
498
	len = l; /* for redraw that uses len */
510
	len = l; /* for redraw that uses len */
499
    }
511
    }
500
    col1 = COLS - 1;
512
    col1 = COLS - 1;
501
    insel = p->sel ? ((i - p->my0) * (i - p->my1)) : 1;
513
    insel = p->sel ? ((i - p->my0) * (i - p->my1)) : 1;
502
    if (insel < 0) {
514
    if (insel < 0) {
503
	WLHELPER(0, col1, White, DarkBlue);
515
	WLHELPER(0, col1, bg, fg);
504
	return len;
516
	return len;
505
    }
517
    }
506
    if ((USER(i) >= 0) && (USER(i) < FC + COLS)) {
518
    if ((USER(i) >= 0) && (USER(i) < FC + COLS)) {
507
	if (USER(i) <= FC)
519
	if (USER(i) <= FC)
508
	    WLHELPER(0, col1, p->ufg, p->bg);
520
	    WLHELPER(0, col1, highlight, bg);
509
	else {
521
	else {
510
	    d = USER(i) - FC;
522
	    d = USER(i) - FC;
511
	    WLHELPER(0, d - 1, p->fg, p->bg);
523
	    WLHELPER(0, d - 1, fg, bg);
512
	    WLHELPER(d, col1, p->ufg, p->bg);
524
	    WLHELPER(d, col1, highlight, bg);
513
	}
525
	}
514
    } else if (USER(i) == -2) {
526
    } else if (USER(i) == -2) {
515
	WLHELPER(0, col1, pagerhighlight, p->bg);
527
	WLHELPER(0, col1, highlight, bg);
516
    } else
528
    } else
517
	WLHELPER(0, col1, p->fg, p->bg);
529
	WLHELPER(0, col1, fg, bg);
518
    /* This is the cursor, and it may need to be variable-width */
530
    /* This is the cursor, and it may need to be variable-width */
519
    if ((p->r >= 0) && (CURCOL >= FC) && (CURCOL < FC + COLS) &&
531
    if ((p->r >= 0) && (CURCOL >= FC) && (CURCOL < FC + COLS) &&
520
	(i == NUMLINES - 1) && (p->sel == 0 || !intersect_input(p, 0))) {
532
	(i == NUMLINES - 1) && (p->sel == 0 || !intersect_input(p, 0))) {
521
	if (!p->overwrite) {
533
	if (!p->overwrite) {
522
	    r = rect(BORDERX + (CURCOL - FC) * FW, BORDERY + j * FH, FW/4, FH);
534
	    r = rect(BORDERX + (CURCOL - FC) * FW, BORDERY + j * FH, FW/4, FH);
523
	    gfillrect(p->bm, p->ufg, r);
535
	    gfillrect(p->bm, highlight, r);
524
	} else if(mbcslocale) { /* determine the width of the current char */
536
	} else if(mbcslocale) { /* determine the width of the current char */
525
	    int w0;
537
	    int w0;
526
	    wchar_t *P = s, wc = 0, nn[2] = L" ";
538
	    wchar_t *P = s, wc = 0, nn[2] = L" ";
527
	    for (w0 = 0; w0 <= CURCOL; P++) {
539
	    for (w0 = 0; w0 <= CURCOL; P++) {
528
		wc = *P;
540
		wc = *P;
Line 532... Line 544...
532
	    /* term string '\0' box width = 1 fix */
544
	    /* term string '\0' box width = 1 fix */
533
	    w0 = wc ? Ri18n_wcwidth(wc) : 1;
545
	    w0 = wc ? Ri18n_wcwidth(wc) : 1;
534
	    nn[0] = wc;
546
	    nn[0] = wc;
535
	    r = rect(BORDERX + (CURCOL - FC) * FW, BORDERY + j * FH,
547
	    r = rect(BORDERX + (CURCOL - FC) * FW, BORDERY + j * FH,
536
		     w0 * FW, FH);
548
		     w0 * FW, FH);
537
	    gfillrect(p->bm, p->ufg, r);
549
	    gfillrect(p->bm, highlight, r);
538
	    gdrawwcs(p->bm, p->f, p->bg, pt(r.x, r.y), nn);
550
	    gdrawwcs(p->bm, p->f, bg, pt(r.x, r.y), nn);
539
	} else
551
	} else
540
	    WLHELPER(CURCOL - FC, CURCOL - FC, p->bg, p->ufg);
552
	    WLHELPER(CURCOL - FC, CURCOL - FC, bg, highlight);
541
    }
553
    }
542
    if (insel != 0) return len;
554
    if (insel != 0) return len;
543
    c1 = (p->my0 < p->my1);
555
    c1 = (p->my0 < p->my1);
544
    c2 = (p->my0 == p->my1);
556
    c2 = (p->my0 == p->my1);
545
    c3 = (p->mx0 < p->mx1);
557
    c3 = (p->mx0 < p->mx1);
Line 577... Line 589...
577
	    x1 = w0 - 1;
589
	    x1 = w0 - 1;
578
	}
590
	}
579
	c2 = (x1 > FC + COLS) ? (COLS - 1) : (x1 - FC);
591
	c2 = (x1 > FC + COLS) ? (COLS - 1) : (x1 - FC);
580
    } else
592
    } else
581
	c2 = COLS - 1;
593
	c2 = COLS - 1;
582
    WLHELPER(c1, c2, White, DarkBlue);
594
    WLHELPER(c1, c2, bg, fg);
583
    return len;
595
    return len;
584
}
596
}
585
 
597
 
586
void drawconsole(control c, rect r) /* r is unused here */
598
void drawconsole(control c, rect r) /* r is unused here */
587
{
599
{
Line 590... Line 602...
590
    int i, ll, wd, maxwd = 0;
602
    int i, ll, wd, maxwd = 0;
591
 
603
 
592
    ll = min(NUMLINES, ROWS);
604
    ll = min(NUMLINES, ROWS);
593
    if(!BM) return;;     /* This is a workaround for PR#1711.
605
    if(!BM) return;;     /* This is a workaround for PR#1711.
594
			    BM should never be null here */
606
			    BM should never be null here */
-
 
607
    if (p->kind == PAGER)
595
    gfillrect(BM, p->bg, getrect(BM));
608
    	gfillrect(BM, p->guiColors[pagerbg], getrect(BM));
-
 
609
    else
-
 
610
    	gfillrect(BM, p->guiColors[consolebg], getrect(BM));
596
    if(!ll) return;;
611
    if(!ll) return;;
597
    for (i = 0; i < ll; i++) {
612
    for (i = 0; i < ll; i++) {
598
	wd = WRITELINE(NEWFV + i, i);
613
	wd = WRITELINE(NEWFV + i, i);
599
	if(wd > maxwd) maxwd = wd;
614
	if(wd > maxwd) maxwd = wd;
600
    }
615
    }
Line 635... Line 650...
635
	    return;;
650
	    return;;
636
	}
651
	}
637
    }
652
    }
638
    if (ds == 1) {
653
    if (ds == 1) {
639
	gscroll(BM, pt(0, -FH), RMLINES(0, ROWS - 1));
654
	gscroll(BM, pt(0, -FH), RMLINES(0, ROWS - 1));
-
 
655
	if (p->kind == PAGER)
640
	gfillrect(BM, p->bg, RLINE(ROWS - 1));
656
	    gfillrect(BM, p->guiColors[pagerbg], RLINE(ROWS - 1));
-
 
657
	else
-
 
658
	    gfillrect(BM, p->guiColors[consolebg], RLINE(ROWS - 1));
641
	WRITELINE(fv + ROWS - 1, ROWS - 1);
659
	WRITELINE(fv + ROWS - 1, ROWS - 1);
642
    }
660
    }
643
    else if (ds == -1) {
661
    else if (ds == -1) {
644
	gscroll(BM, pt(0, FH), RMLINES(0, ROWS - 1));
662
	gscroll(BM, pt(0, FH), RMLINES(0, ROWS - 1));
-
 
663
	if (p->kind == PAGER)
645
	gfillrect(BM, p->bg, RLINE(0));
664
	    gfillrect(BM, p->guiColors[pagerbg], RLINE(0));
-
 
665
	else	
-
 
666
	    gfillrect(BM, p->guiColors[consolebg], RLINE(0));
646
	WRITELINE(fv, 0);
667
	WRITELINE(fv, 0);
647
    }
668
    }
648
    RSHOW(getrect(c));
669
    RSHOW(getrect(c));
649
    FV = fv;
670
    FV = fv;
650
    NEWFV = fv;
671
    NEWFV = fv;
Line 1875... Line 1896...
1875
int consolebufb = DIMLBUF, consolebufl = MLBUF, consolebuffered = 1;
1896
int consolebufb = DIMLBUF, consolebufl = MLBUF, consolebuffered = 1;
1876
 
1897
 
1877
void
1898
void
1878
setconsoleoptions(const char *fnname,int fnsty, int fnpoints,
1899
setconsoleoptions(const char *fnname,int fnsty, int fnpoints,
1879
		  int rows, int cols, int consx, int consy,
1900
		  int rows, int cols, int consx, int consy,
1880
		  rgb nfg, rgb nufg, rgb nbg, rgb high,
1901
		  rgb *nguiColors,
1881
		  int pgr, int pgc, int multiplewindows, int widthonresize,
1902
		  int pgr, int pgc, int multiplewindows, int widthonresize,
1882
		  int bufbytes, int buflines, int buffered)
1903
		  int bufbytes, int buflines, int buffered)
1883
{
1904
{
1884
    char msg[LF_FACESIZE + 128];
1905
    char msg[LF_FACESIZE + 128];
1885
    strncpy(fontname, fnname, LF_FACESIZE);
1906
    strncpy(fontname, fnname, LF_FACESIZE);
Line 1908... Line 1929...
1908
       } */
1929
       } */
1909
    consoler = rows;
1930
    consoler = rows;
1910
    consolec = cols;
1931
    consolec = cols;
1911
    consolex = consx;
1932
    consolex = consx;
1912
    consoley = consy;
1933
    consoley = consy;
1913
    consolefg = nfg;
1934
    for (int i=0; i<numGuiColors; i++)
1914
    consoleuser = nufg;
1935
    	guiColors[i] = nguiColors[i];
1915
    consolebg = nbg;
-
 
1916
    pagerhighlight = high;
-
 
1917
    pagerrow = pgr;
1936
    pagerrow = pgr;
1918
    pagercol = pgc;
1937
    pagercol = pgc;
1919
    pagerMultiple = multiplewindows;
1938
    pagerMultiple = multiplewindows;
1920
    setWidthOnResize = widthonresize;
1939
    setWidthOnResize = widthonresize;
1921
    consolebufb = bufbytes;
1940
    consolebufb = bufbytes;
Line 2110... Line 2129...
2110
    console c;
2129
    console c;
2111
    ConsoleData p;
2130
    ConsoleData p;
2112
 
2131
 
2113
    p = newconsoledata((consolefn) ? consolefn : FixedFont,
2132
    p = newconsoledata((consolefn) ? consolefn : FixedFont,
2114
		       consoler, consolec, consolebufb, consolebufl,
2133
		       consoler, consolec, consolebufb, consolebufl,
2115
		       consolefg, consoleuser, consolebg,
2134
		       guiColors,
2116
		       CONSOLE, consolebuffered);
2135
		       CONSOLE, consolebuffered);
2117
    if (!p) return NULL;
2136
    if (!p) return NULL;
2118
    c = (console) newwindow(name, rect(consolex, consoley, WIDTH, HEIGHT),
2137
    c = (console) newwindow(name, rect(consolex, consoley, WIDTH, HEIGHT),
2119
			    flags | TrackMouse | VScrollbar | HScrollbar);
2138
			    flags | TrackMouse | VScrollbar | HScrollbar);
2120
    HEIGHT = getheight(c);
2139
    HEIGHT = getheight(c);
Line 2124... Line 2143...
2124
    gsetcursor(c, ArrowCursor);
2143
    gsetcursor(c, ArrowCursor);
2125
    gchangescrollbar(c, VWINSB, 0, 0, ROWS, 1);
2144
    gchangescrollbar(c, VWINSB, 0, 0, ROWS, 1);
2126
    gchangescrollbar(c, HWINSB, 0, COLS-1, COLS, 1);
2145
    gchangescrollbar(c, HWINSB, 0, COLS-1, COLS, 1);
2127
    BORDERX = (WIDTH - COLS*FW) / 2;
2146
    BORDERX = (WIDTH - COLS*FW) / 2;
2128
    BORDERY = (HEIGHT - ROWS*FH) / 2;
2147
    BORDERY = (HEIGHT - ROWS*FH) / 2;
2129
    setbackground(c, consolebg);
2148
    setbackground(c, guiColors[consolebg]);
2130
    BM = newbitmap(WIDTH, HEIGHT, 2);
2149
    BM = newbitmap(WIDTH, HEIGHT, 2);
2131
    if (!c || !BM ) {
2150
    if (!c || !BM ) {
2132
	freeConsoleData(p);
2151
	freeConsoleData(p);
2133
	del(c);
2152
	del(c);
2134
	return NULL;
2153
	return NULL;