Back to index

radiance  4R0+20100331
Classes | Defines | Functions
x11twind.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  TEXTWIND

Defines

#define LEFTMAR   2 /* left margin width */
#define TNOCURS   0
#define TBLKCURS   1

Functions

TEXTWINDxt_open (Display *dpy, Window parent, int x, int y, int width, int height, int bw, unsigned long fore, unsigned long back, char *fontname)
void xt_puts (char *s, TEXTWIND *t)
void xt_putc (int c, TEXTWIND *t)
void xt_delete (TEXTWIND *t, int r)
void xt_insert (TEXTWIND *t, int r)
void xt_redraw (TEXTWIND *t)
void xt_clear (TEXTWIND *t)
void xt_move (TEXTWIND *t, int r, int c)
int xt_cursor (TEXTWIND *t, int curs)
void xt_close (TEXTWIND *t)

Class Documentation

struct TEXTWIND

Definition at line 19 of file x11twind.h.

Class Members
short c
short cursor
Display * dpy
XFontStruct * f
GC gc
char ** lp
short nc
short nr
short r
Window w

Define Documentation

#define LEFTMAR   2 /* left margin width */

Definition at line 17 of file x11twind.h.

#define TBLKCURS   1

Definition at line 31 of file x11twind.h.

#define TNOCURS   0

Definition at line 30 of file x11twind.h.


Function Documentation

void xt_clear ( TEXTWIND t)

Definition at line 209 of file x11twind.c.

{
       register int  i;

       XClearWindow(t->dpy, t->w);
       for (i = 0; i < t->nr; i++)
              memset(t->lp[i], '\0', t->nc);
       t->r = t->c = 0;
       restorecurs(t);
}
void xt_close ( TEXTWIND t)

Definition at line 254 of file x11twind.c.

{
       register int  i;

       XFreeFont(t->dpy, t->f);
       XFreeGC(t->dpy,t->gc);
       XDestroyWindow(t->dpy, t->w);
       for (i = 0; i < t->nr; i++)
              free(t->lp[i]);
       free((void *)t->lp);
       free((void *)t);
}

Here is the caller graph for this function:

int xt_cursor ( TEXTWIND t,
int  curs 
)

Definition at line 237 of file x11twind.c.

{
       register int  oldcurs;

       if (curs != TNOCURS && curs != TBLKCURS)
              return(-1);
       oldcurs = t->cursor;
       if (curs != oldcurs)
              togglecurs(t);
       t->cursor = curs;
       return(oldcurs);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xt_delete ( TEXTWIND t,
int  r 
)

Definition at line 138 of file x11twind.c.

{
       char  *cp;
       register int  i;

       if (r < 0 || r >= t->nr)
              return;
       checkcurs(t);
                                   /* move lines */
       XCopyArea(t->dpy, t->w, t->w, t->gc, LEFTMAR, (r+1)*Height(t->f),
                     t->nc*Width(t->f), (t->nr-1-r)*Height(t->f),
                     LEFTMAR, r*Height(t->f));
       cp = t->lp[r];
       for (i = r; i < t->nr-1; i++)
              t->lp[i] = t->lp[i+1];
       t->lp[t->nr-1] = cp;
                                   /* clear bottom */
       XClearArea(t->dpy, t->w, LEFTMAR, (t->nr-1)*Height(t->f),
                     t->nc*Width(t->f), Height(t->f),(Bool) 0);

       memset(cp, '\0', t->nc);
       restorecurs(t);                    /* should we reposition cursor? */
}

Here is the caller graph for this function:

void xt_insert ( TEXTWIND t,
int  r 
)

Definition at line 166 of file x11twind.c.

{
       char  *cp;
       register int  i;

       if (r < 0 || r >= t->nr)
              return;
       checkcurs(t);
                                   /* move lines */
       XCopyArea(t->dpy, t->w, t->w, t->gc, LEFTMAR, r*Height(t->f), LEFTMAR,
                     (r+1)*Height(t->f), t->nc*Width(t->f),
                     (t->nr-1-r)*Height(t->f));
       cp = t->lp[t->nr-1];
       for (i = t->nr-1; i > r; i--)
              t->lp[i] = t->lp[i-1];
       t->lp[r] = cp;
                                   /* clear new line */
       XClearArea(t->dpy, t->w, LEFTMAR, r*Height(t->f),
                     t->nc*Width(t->f), Height(t->f), (Bool) 0);
       memset(cp, '\0', t->nc);
       restorecurs(t);                    /* should we reposition cursor? */
}
void xt_move ( TEXTWIND t,
int  r,
int  c 
)

Definition at line 223 of file x11twind.c.

{
       if (r < 0 || c < 0 || r >= t->nr || c >= t->nc)
              return;
       checkcurs(t);
       t->r = r;
       t->c = c;
       restorecurs(t);
}
TEXTWIND* xt_open ( Display *  dpy,
Window  parent,
int  x,
int  y,
int  width,
int  height,
int  bw,
unsigned long  fore,
unsigned long  back,
char *  fontname 
)

Definition at line 36 of file x11twind.c.

{
       register int  i;
       register TEXTWIND  *t;

       if ((t = (TEXTWIND *)malloc(sizeof(TEXTWIND))) == NULL)
              return(NULL);

       t->dpy = dpy;
       t->w = XCreateSimpleWindow(dpy, parent, x, y, width, height,
                                   bw, fore, back);
       if (t->w == 0)
              return(NULL);
       XMapWindow(dpy, t->w);

       if ((t->f = XLoadQueryFont(dpy, fontname)) == 0)
              return(NULL);

       /* if (!t->f.fixedwidth)   check for fixedwidth later 
              return(NULL); */

       t->gc = XCreateGC(dpy,t->w,0,NULL);
       XSetState(dpy, t->gc, fore, back, GXcopy, AllPlanes);
       XSetFont(dpy, t->gc, t->f->fid);

       t->nc = (width - LEFTMAR) / 
              Width(t->f);         /* number of columns */
       t->nr = height /
              Height(t->f);        /* number of rows */
       if (t->nc < 1 || t->nr < 1)
              return(NULL);
       if ((t->lp = (char **)calloc(t->nr, sizeof(char *))) == NULL)
              return(NULL);
       for (i = 0; i < t->nr; i++)
              if ((t->lp[i] = calloc(t->nc+1, 1)) == NULL)
                     return(NULL);
       t->r = t->c = 0;
       t->cursor = TNOCURS;
       return(t);

}

Here is the caller graph for this function:

void xt_putc ( int  c,
TEXTWIND t 
)

Definition at line 87 of file x11twind.c.

{
       char   ch[2];

       checkcurs(t);
       switch (c) {
       case '\n':
              if (t->r >= t->nr - 1)
                     xt_delete(t, 0);     /* scroll up 1 line */
              else if (t->r < t->nr - 1)
                     t->r++;
       /* fall through */
       case '\r':
              t->c = 0;
              break;
       case '\b':
              while (t->c < 1 && t->r > 0)
                     t->c = strlen(t->lp[--t->r]);
              if (t->c > 0)
                     t->c--;
              break;
       default:
              if (t->c >= t->nc)
                     xt_putc('\n', t);
              ch[0] = c; ch[1] = '\0';
              XDrawImageString(t->dpy, t->w, t->gc, LEFTMAR+t->c*Width(t->f), 
                     YStart(t->f)+t->r*Height(t->f), ch, 1);
              t->lp[t->r][t->c++] = c;
              break;
       }
       restorecurs(t);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xt_puts ( char *  s,
TEXTWIND t 
)

Definition at line 124 of file x11twind.c.

{
       int    oldcurs;

       oldcurs = xt_cursor(t, TNOCURS);   /* for efficiency */
       while (*s)
              xt_putc(*s++, t);
       xt_cursor(t, oldcurs);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xt_redraw ( TEXTWIND t)

Definition at line 193 of file x11twind.c.

{
       register int  i;

       XClearWindow(t->dpy, t->w);
       for (i = 0; i < t->nr; i++)
           if (strlen(t->lp[i]) > 0)
              XDrawImageString(t->dpy, t->w, t->gc, LEFTMAR, 
                            YStart(t->f)+i*Height(t->f),
                            t->lp[i], strlen(t->lp[i]));
       restorecurs(t);
}

Here is the caller graph for this function: