home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume13
/
xfbrowse
/
part02
/
list.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-04
|
3KB
|
157 lines
#include "xfbrows.h"
#include "bitmaps.h"
#define DBLCLKTIME 500
#define LISTW 330
#define INACTIVE(lptr, item) ((lptr)->filetypes && (lptr)->dirsonly && \
(item) >= 0 && (item) < (lptr)->nstr && \
(lptr)->str[(item)][0] != C_DIR && \
(lptr)->str[(item)][0] != C_LNK)
void LSCreate (lp, win, x, y, w, h, nlines, strlist, nstr, fg, bg, fptr,
typ, donly)
LIST *lp;
Window win;
int x, y, w, h, nlines, nstr, typ, donly;
unsigned long fg, bg;
char **strlist;
void (*fptr) ();
{
lp->win = XCreateSimpleWindow (theDisp, win, x, y, w, h, 1, infofg, infobg);
if (!lp->win) FatalError ("can't create list window!");
lp->x = x;
lp->y = y;
lp->w = w;
lp->h = h;
lp->fg = fg;
lp->bg = bg;
lp->str = strlist;
lp->nstr = nstr;
lp->selected = 0;
lp->nlines = nlines;
lp->filetypes= typ;
lp->dirsonly = donly;
XSelectInput (theDisp, lp->win, ExposureMask | ButtonPressMask
| ButtonReleaseMask | Button1MotionMask | EnterWindowMask
| LeaveWindowMask);
SCCreate (&lp->scrl, win, x+w, y, 1, h, 0, nstr-nlines, curname, nlines-1,
fg, bg, fptr);
}
void LSNewData (lp, strlist, nstr)
LIST *lp;
char **strlist;
int nstr;
{
lp->str = strlist;
lp->nstr = nstr;
lp->selected = 0;
SCSetRange (&lp->scrl, 0, nstr - lp->nlines, 0, lp->nlines-1);
}
static void drawSel (lp, j)
LIST *lp;
int j;
{
int i, k, inactive;
unsigned long fg, bg;
char s[2];
inactive = INACTIVE (lp, j);
i = j - lp->scrl.val;
if (i<0 || i>=lp->nlines) return;
if (j == lp->selected && !inactive && j<lp->nstr && !isfont)
{
fg = lp->bg;
bg = lp->fg;
}
else
{
fg = lp->fg;
bg = lp->bg;
}
XSetForeground (theDisp, theGC, bg);
XFillRectangle (theDisp, lp->win, theGC, 0, i*LINEHIGH, lp->w, LINEHIGH);
if (j>=0 && j<lp->nstr)
{
XSetForeground (theDisp, theGC, fg);
XSetBackground (theDisp, theGC, bg);
if (!lp->filetypes)
XDrawString (theDisp, lp->win, theGC, 3, i*LINEHIGH + ASCENT + 1,
lp->str [j], strlen (lp->str [j]));
else
{
if (isfont)
for (k=0; k<16; k++)
{
s[0] = lp->str [j][k];
s[1] = '\0';
XDrawString (theDisp, lp->win, theGC, 3+k*WIDTH,
i*LINEHIGH + ASCENT + 1,
s, strlen (s));
}
else
XDrawString (theDisp, lp->win, theGC, 6,
i*LINEHIGH + ASCENT + 1,
lp->str [j], strlen (lp->str [j]));
}
}
}
void LSRedraw (lp)
LIST *lp;
{
int i;
for (i = lp->scrl.val;i < lp->scrl.val + lp->nlines;i++) drawSel (lp, i);
}
int LSClick (lp, ev)
LIST *lp;
XButtonEvent *ev;
{
Window rW, cW;
int rx, ry, x, y, sel, oldsel;
unsigned int mask;
static Time lasttime=0;
static int lastsel = -1;
x = ev->x;
y = ev->y;
sel = lp->scrl.val + y/LINEHIGH;
if (sel >= lp->nstr) sel = lp->selected;
if (ev->time - lasttime < DBLCLKTIME && sel==lastsel
&& (lp->scrl.val + y/LINEHIGH) < lp->nstr
&& !INACTIVE (lp, sel)) return (sel);
lasttime = ev->time;lastsel = sel;
if (sel != lp->selected)
{
oldsel = lp->selected;
lp->selected = sel;
drawSel (lp, sel);
drawSel (lp, oldsel);
XFlush (theDisp);
}
while (XQueryPointer (theDisp, lp->win, &rW, &cW, &rx, &ry, &x, &y, &mask))
{
if (! (mask & Button1Mask)) break;
}
return (sel);
}