configure
config.log
config.cache
+config.status
config.h
+.depend
Makefile
test
testgrid
whiptail
libnewt*
-snack.pcy
+snack.pyc
+0.30 -> 0.40
+ - GPM mouse support added
+
0.30 -> 0.31:
- pgdn could core dump on short textboxes
SLsmg_set_color(NEWT_COLORSET_BUTTON);
if (bu->compact) {
- if (active)
+ if (active)
SLsmg_set_color(NEWT_COLORSET_COMPACTBUTTON);
else
SLsmg_set_color(NEWT_COLORSET_BUTTON);
}
er.result = ER_EXITFORM;
- } else
+ } else
er.result = ER_IGNORED;
break;
+ case EV_MOUSE:
+ if (!bu->compact) {
+ buttonDrawIt(co, 1, 1);
+ newtRefresh();
+ newtDelay(150000);
+ buttonDrawIt(co, 1, 0);
+ newtRefresh();
+ newtDelay(150000);
+ }
+ er.result = ER_EXITFORM;
+ break;
}
- } else
+ } else
er.result = ER_IGNORED;
return er;
newtComponent newtRadioGetCurrent(newtComponent setMember) {
struct checkbox * rb = setMember->data;
-
+
setMember = rb->lastButton;
rb = setMember->data;
SLsmg_write_string(cb->text);
- if (cb->hasFocus)
+ if (cb->hasFocus)
SLsmg_set_color(cb->active);
newtGotorc(c->top, c->left + 1);
*cb->result = *cb->seq;
else {
cur++;
- if (! *cur)
+ if (! *cur)
*cb->result = *cb->seq;
else
*cb->result = *cur;
er.result = ER_IGNORED;
}
break;
+ case EV_MOUSE:
+ if (ev.u.mouse.type == MOUSE_BUTTON_DOWN) {
+ if (cb->type == RADIO) {
+ makeActive(co);
+ } else if (cb->type == CHECK) {
+ cur = strchr(cb->seq, *cb->result);
+ if (!cur)
+ *cb->result = *cb->seq;
+ else {
+ cur++;
+ if (! *cur)
+ *cb->result = *cb->seq;
+ else
+ *cb->result = *cur;
+ }
+ cbDraw(co);
+ er.result = ER_SWALLOWED;
+
+ if (co->callback)
+ co->callback(co, co->callbackData);
+ }
+ }
}
- } else
+ } else
er.result = ER_IGNORED;
return er;
if (curr) {
rb->value = rb->seq[0];
cbDraw(curr);
- }
+ }
cb->value = cb->seq[1];
cbDraw(co);
static void entryDraw(newtComponent co);
static void entryDestroy(newtComponent co);
-static struct eventResult entryEvent(newtComponent co,
+static struct eventResult entryEvent(newtComponent co,
struct event ev);
static struct eventResult entryHandleKey(newtComponent co, int key);
en->buf = malloc(en->bufAlloced);
en->resultPtr = resultPtr;
if (en->resultPtr) *en->resultPtr = en->buf;
-
+
memset(en->buf, 0, en->bufAlloced);
if (initialValue) {
strcpy(en->buf, initialValue);
if (!co->isMapped) return;
- if (en->flags & NEWT_FLAG_DISABLED)
+ if (en->flags & NEWT_FLAG_DISABLED)
SLsmg_set_color(NEWT_COLORSET_DISENTRY);
else
SLsmg_set_color(NEWT_COLORSET_ENTRY);
-
+
if (en->flags & NEWT_FLAG_HIDDEN) {
newtGotorc(co->top, co->left);
for (i = 0; i < co->width; i++)
chptr = en->buf + en->firstChar;
len = strlen(chptr);
-
+
if (len <= co->width) {
i = len;
SLsmg_write_string(chptr);
free(co);
}
-static struct eventResult entryEvent(newtComponent co,
+static struct eventResult entryEvent(newtComponent co,
struct event ev) {
struct entry * en = co->data;
struct eventResult er;
if (ev.when == EV_NORMAL) {
switch (ev.event) {
- case EV_FOCUS:
+ case EV_FOCUS:
/*SLtt_set_cursor_visibility(0);*/
if (en->flags & NEWT_FLAG_HIDDEN)
newtGotorc(co->top, co->left);
else
- newtGotorc(co->top, co->left +
- (en->cursorPosition - en->firstChar));
+ newtGotorc(co->top, co->left +
+ (en->cursorPosition - en->firstChar));
er.result = ER_SWALLOWED;
break;
- case EV_UNFOCUS:
+ case EV_UNFOCUS:
/*SLtt_set_cursor_visibility(1);*/
newtGotorc(0, 0);
er.result = ER_SWALLOWED;
if (co->callback) co->callback(co, co->callbackData);
break;
- case EV_KEYPRESS:
+ case EV_KEYPRESS:
ch = ev.u.key;
if (en->filter)
ch = en->filter(co, en->filterData, ch, en->cursorPosition);
if (ch) er = entryHandleKey(co, ch);
break;
+
+ case EV_MOUSE:
+ if ((ev.u.mouse.type == MOUSE_BUTTON_DOWN) &&
+ (en->flags ^ NEWT_FLAG_HIDDEN)) {
+ if (strlen(en->buf) >= ev.u.mouse.x - co->left) {
+ en->cursorPosition = ev.u.mouse.x - co->left;
+ newtGotorc(co->top,
+ co->left +(en->cursorPosition - en->firstChar));
+ } else {
+ en->cursorPosition = strlen(en->buf);
+ newtGotorc(co->top,
+ co->left +(en->cursorPosition - en->firstChar));
+ }
+ }
+ break;
}
} else
er.result = ER_IGNORED;
if (!(en->flags & NEWT_FLAG_SCROLL) && en->bufUsed == co->width) {
SLtt_beep();
break;
- }
-
+ }
+
if ((en->bufUsed + 1) == en->bufAlloced) {
en->bufAlloced += 20;
en->buf = realloc(en->buf, en->bufAlloced);
if ((en->bufUsed + 1) == en->bufAlloced) {
/* this string fills the buffer, so clip it */
chptr--;
- } else
+ } else
en->bufUsed++;
insPoint = en->buf + en->cursorPosition;
}
}
-
+
en->buf[en->cursorPosition++] = key;
} else {
er.result = ER_IGNORED;
}
- }
+ }
entryDraw(co);
+#include "config.h"
+
#include <slang.h>
#include <stdarg.h>
#include <stdlib.h>
#include <sys/select.h>
+#ifdef HAVE_LIBGPM
+#include <gpm.h>
+#endif
+
#include "newt.h"
#include "newt_pr.h"
/****************************************************************************
- These forms handle vertical scrolling of components with a height of 1
-
+ These forms handle vertical scrolling of components with a height of 1
+
Horizontal scrolling won't work, and scrolling large widgets will fail
miserably. It shouldn't be too hard to fix either of those if anyone
cares to. I only use scrolling for listboxes and text boxes though so
if (vertBar)
form->vertBar = vertBar;
else
- form->vertBar = NULL;
+ form->vertBar = NULL;
return co;
}
if (form->numCompsAlloced == form->numComps) {
form->numCompsAlloced += 5;
- form->elements = realloc(form->elements,
+ form->elements = realloc(form->elements,
sizeof(*(form->elements)) * form->numCompsAlloced);
}
while ((subco = va_arg(ap, newtComponent)))
newtFormAddComponent(co, subco);
-
+
va_end(ap);
}
}
if (form->vertBar)
- newtScrollbarSet(form->vertBar, form->vertOffset,
+ newtScrollbarSet(form->vertBar, form->vertOffset,
form->numRows - co->height);
}
int new, wrap = 0;
struct eventResult er;
int dir = 0, page = 0;
- int i, num;
+ int i, num, found;
+ struct element * el;
er.result = ER_IGNORED;
if (!form->numComps) return er;
switch (ev.when) {
case EV_EARLY:
- if (ev.event == EV_KEYPRESS) {
+ if (ev.event == EV_KEYPRESS) {
if (ev.u.key == NEWT_KEY_TAB) {
er.result = ER_SWALLOWED;
dir = 1;
}
break;
-
+
case EV_NORMAL:
+ if (ev.event == EV_MOUSE) {
+ found = 0;
+ for (i = 0, el = form->elements; i < form->numComps; i++, el++) {
+ if ((el->co->top <= ev.u.mouse.y) &&
+ (el->co->top + el->co->height > ev.u.mouse.y) &&
+ (el->co->left <= ev.u.mouse.x) &&
+ (el->co->left + el->co->width > ev.u.mouse.x)) {
+ found = 1;
+ if (el->co->takesFocus) {
+ gotoComponent(form, i);
+ subco = form->elements[form->currComp].co;
+ }
+ }
+ /* If we did not find a co to send this event to, we
+ should just swallow the event here. */
+ }
+ if (!found) {
+ er.result = ER_SWALLOWED;
+
+ return er;
+ }
+ }
er = subco->ops->event(subco, ev);
switch (er.result) {
case ER_NEXTCOMP:
case EV_LATE:
er = subco->ops->event(subco, ev);
-
+
if (er.result == ER_IGNORED) {
switch (ev.u.key) {
case NEWT_KEY_UP:
dir = -1;
page = 1;
break;
-
+
case NEWT_KEY_PGDN:
er.result = ER_SWALLOWED;
dir = 1;
new = form->numComps - 1;
else if (new >= form->numComps)
new = 0;
- } else if (new < 0 || new >= form->numComps)
+ } else if (new < 0 || new >= form->numComps)
return er;
} while (!form->elements[new].co->takesFocus);
}
form->vertOffset = form->elements[new].top - co->top;
} else {
/* make the new component the last one */
- form->vertOffset = (form->elements[new].top +
+ form->vertOffset = (form->elements[new].top +
form->elements[new].co->height) -
(co->top + co->height);
}
} else {
if (subco->data) free(subco->data);
free(subco);
- }
+ }
}
free(form->elements);
co->height += delta;
}
- if ((co->left + co->width) < (el->co->left + el->co->width))
+ if ((co->left + co->width) < (el->co->left + el->co->width))
co->width = (el->co->left + el->co->width) - co->left;
if (!form->fixedHeight) {
- if ((co->top + co->height) < (el->co->top + el->co->height))
+ if ((co->top + co->height) < (el->co->top + el->co->height))
co->height = (el->co->top + el->co->height) - co->top;
}
}
}
+
void newtFormRun(newtComponent co, struct newtExitStruct * es) {
struct form * form = co->data;
struct event ev;
struct eventResult er;
- int key, i;
+ int key, i, max;
int done = 0;
fd_set readSet, writeSet;
+#ifdef HAVE_LIBGPM
+ int x, y;
+ Gpm_Connect conn;
+ Gpm_Event event;
+
+ /* Set up GPM interface */
+ conn.eventMask = ~GPM_MOVE;
+ conn.defaultMask = GPM_MOVE;
+ conn.minMod = 0;
+ conn.maxMod = 0;
+
+ Gpm_Open(&conn, 0);
+#endif
newtFormSetSize(co);
/* draw all of the components */
gotoComponent(form, 0);
} else
gotoComponent(form, form->currComp);
-
+
while (!done) {
newtRefresh();
FD_ZERO(&readSet);
FD_ZERO(&writeSet);
FD_SET(0, &readSet);
+#ifdef HAVE_LIBGPM
+ if (gpm_visiblepointer) GPM_DRAWPOINTER(&event);
+
+ if (gpm_fd > 0) {
+ FD_SET(gpm_fd, &readSet);
+ }
+ max = form->maxFd > gpm_fd ? form->maxFd : gpm_fd;
+#else
+ max = form->maxFd;
+#endif
+
for (i = 0; i < form->numFds; i++) {
if (form->fds[i].flags & NEWT_FD_READ)
FD_SET(form->fds[i].fd, &readSet);
FD_SET(form->fds[i].fd, &writeSet);
}
- i = select(form->maxFd + 1, &readSet, &writeSet, NULL, NULL);
+ i = select(max + 1, &readSet, &writeSet, NULL, NULL);
if (i < 0) continue; /* ?? What should we do here? */
- if (FD_ISSET(0, &readSet)) {
- key = newtGetKey();
+#ifdef HAVE_LIBGPM
+ if (gpm_fd > 0 && FD_ISSET(gpm_fd, &readSet)) {
+ Gpm_GetEvent(&event);
- if (key == NEWT_KEY_RESIZE) {
- /* newtResizeScreen(1); */
- continue;
- }
+ if (event.type & GPM_DOWN) {
+ /* Transform coordinates to current window */
+ newtGetWindowPos(&x, &y);
- for (i = 0; i < form->numHotKeys; i++) {
- if (form->hotKeys[i] == key) {
- es->reason = NEWT_EXIT_HOTKEY;
- es->u.key = key;
- done = 1;
- break;
- }
- }
-
- if (!done) {
- ev.event = EV_KEYPRESS;
- ev.u.key = key;
+ ev.event = EV_MOUSE;
+ ev.u.mouse.type = MOUSE_BUTTON_DOWN;
+ ev.u.mouse.x = event.x - x - 1;
+ ev.u.mouse.y = event.y - y - 1;
+ /* Send the form the event */
er = sendEvent(co, ev);
-
+
if (er.result == ER_EXITFORM) {
done = 1;
es->reason = NEWT_EXIT_COMPONENT;
es->u.co = form->exitComp;
- }
+ }
+
}
- } else {
- es->reason = NEWT_EXIT_FDREADY;
- done = 1;
- }
- }
+ } else
+#endif
+ {
+ if (FD_ISSET(0, &readSet)) {
+
+ key = newtGetKey();
+ if (key == NEWT_KEY_RESIZE) {
+ /* newtResizeScreen(1); */
+ continue;
+ }
+
+ for (i = 0; i < form->numHotKeys; i++) {
+ if (form->hotKeys[i] == key) {
+ es->reason = NEWT_EXIT_HOTKEY;
+ es->u.key = key;
+ done = 1;
+ break;
+ }
+ }
+
+ if (!done) {
+ ev.event = EV_KEYPRESS;
+ ev.u.key = key;
+
+ er = sendEvent(co, ev);
+
+ if (er.result == ER_EXITFORM) {
+ done = 1;
+ es->reason = NEWT_EXIT_COMPONENT;
+ es->u.co = form->exitComp;
+ }
+ }
+ } else {
+ es->reason = NEWT_EXIT_FDREADY;
+ done = 1;
+ }
+ }
+ }
newtRefresh();
+#ifdef HAVE_LIBGPM
+ Gpm_Close();
+#endif
}
static struct eventResult sendEvent(newtComponent co, struct event ev) {
}
form->currComp = newComp;
-
+
if (form->currComp != -1) {
ev.event = EV_FOCUS;
ev.when = EV_NORMAL;
int curHeight; /* size of text w/o border */
int sbAdjust;
int bdxAdjust, bdyAdjust;
- int numItems, numSelected;
+ int numItems, numSelected;
int userHasSetWidth;
int currItem, startShowItem; /* startShowItem is the first item displayed
on the screen */
static struct eventResult listboxEvent(newtComponent co, struct event ev);
static void newtListboxRealSetCurrent(newtComponent co);
static void listboxPlace(newtComponent co, int newLeft, int newTop);
-static inline void updateWidth(newtComponent co, struct listbox * li,
+static inline void updateWidth(newtComponent co, struct listbox * li,
int maxField);
static void listboxMapped(newtComponent co, int isMapped);
co->left = newLeft;
if (li->sb)
- li->sb->ops->place(li->sb, co->left + co->width - li->bdxAdjust - 1,
+ li->sb->ops->place(li->sb, co->left + co->width - li->bdxAdjust - 1,
co->top);
}
li->sbAdjust = 0;
li->bdxAdjust = 0;
li->bdyAdjust = 0;
- li->flags = flags & (NEWT_FLAG_RETURNEXIT | NEWT_FLAG_BORDER |
+ li->flags = flags & (NEWT_FLAG_RETURNEXIT | NEWT_FLAG_BORDER |
NEWT_FLAG_MULTIPLE);
if (li->flags & NEWT_FLAG_BORDER) {
if (height) {
li->grow = 0;
if (flags & NEWT_FLAG_SCROLL) {
- sb = newtVerticalScrollbar(left, top + li->bdyAdjust,
- li->curHeight,
+ sb = newtVerticalScrollbar(left, top + li->bdyAdjust,
+ li->curHeight,
COLORSET_LISTBOX, COLORSET_ACTLISTBOX);
li->sbAdjust = 3;
} else {
return co;
}
-static inline void updateWidth(newtComponent co, struct listbox * li,
+static inline void updateWidth(newtComponent co, struct listbox * li,
int maxField) {
li->curWidth = maxField;
co->width = li->curWidth + li->sbAdjust + 2 * li->bdxAdjust;
void newtListboxSetWidth(newtComponent co, int width) {
struct listbox * li = co->data;
-
+
co->width = width;
li->curWidth = co->width - li->sbAdjust - 2 * li->bdxAdjust;
li->userHasSetWidth = 1;
struct listbox * li = co->data;
int i;
struct items * item;
-
+
item = li->boxItems, i = 0;
while (item && item->data != key)
item = item->next, i++;
item->text = strdup(text); item->data = data; item->next = NULL;
item->isSelected = 0;
-
+
if (li->grow)
co->height++, li->curHeight++;
li->numItems++;
item->text = strdup(text?text:"(null)"); item->data = data;
item->isSelected = 0;
-
+
if (li->sb)
li->sb->left = co->left + co->width - li->bdxAdjust - 1;
li->numItems++;
}
li->numItems = li->numSelected = li->currItem = li->startShowItem = 0;
li->boxItems = NULL;
- if (!li->userHasSetWidth)
+ if (!li->userHasSetWidth)
updateWidth(co, li, 5);
}
}
i = 0;
- item = li->boxItems;
+ item = li->boxItems;
while (item && i < num) {
i++, item = item->next;
}
if (text)
*text = item->text;
if (data)
- *data = (void *)item->data;
+ *data = (void *)item->data;
}
}
li->sb->ops->draw(li->sb);
SLsmg_set_color(NEWT_COLORSET_LISTBOX);
-
+
for(i = 0, item = li->boxItems; item != NULL && i < li->startShowItem;
i++, item = item->next);
SLsmg_set_color(NEWT_COLORSET_SELLISTBOX);
else
SLsmg_set_color(NEWT_COLORSET_LISTBOX);
-
+
SLsmg_write_nstring(item->text, li->curWidth);
}
struct listbox * li = co->data;
er.result = ER_IGNORED;
-
+
if(ev.when == EV_EARLY || ev.when == EV_LATE) {
return er;
}
-
+
switch(ev.event) {
case EV_KEYPRESS:
if (!li->isActive) break;
switch(ev.u.key) {
case ' ':
if(!(li->flags & NEWT_FLAG_MULTIPLE)) break;
- newtListboxSelectItem(co, li->boxItems[li->currItem].data,
+ newtListboxSelectItem(co, li->boxItems[li->currItem].data,
NEWT_FLAGS_TOGGLE);
er.result = ER_SWALLOWED;
/* We don't break here, because it is cool to be able to
/* keeps gcc quiet */
}
break;
-
+
case EV_FOCUS:
li->isActive = 1;
listboxDraw(co);
listboxDraw(co);
er.result = ER_SWALLOWED;
break;
+
+ case EV_MOUSE:
+ /* if this mouse click was within the listbox, make the current
+ item the item clicked on. */
+ /* Up scroll arrow */
+ if (li->sb &&
+ ev.u.mouse.x == co->left + co->width - li->bdxAdjust - 1 &&
+ ev.u.mouse.y == co->top + li->bdyAdjust) {
+ if(li->numItems <= 0) break;
+ if(li->currItem > 0) {
+ li->currItem--;
+ if(li->currItem < li->startShowItem)
+ li->startShowItem = li->currItem;
+ if(li->sb)
+ newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
+ listboxDraw(co);
+ }
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ break;
+ }
+ /* Down scroll arrow */
+ if (li->sb &&
+ ev.u.mouse.x == co->left + co->width - li->bdxAdjust - 1 &&
+ ev.u.mouse.y == co->top + co->height - li->bdyAdjust - 1) {
+ if(li->numItems <= 0) break;
+ if(li->currItem < li->numItems - 1) {
+ li->currItem++;
+ if(li->currItem > (li->startShowItem + li->curHeight - 1)) {
+ li->startShowItem = li->currItem - li->curHeight + 1;
+ if(li->startShowItem + li->curHeight > li->numItems)
+ li->startShowItem = li->numItems - li->curHeight;
+ }
+ if(li->sb)
+ newtScrollbarSet(li->sb, li->currItem + 1, li->numItems);
+ listboxDraw(co);
+ }
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ break;
+ }
+ if ((ev.u.mouse.y >= co->top + li->bdyAdjust) &&
+ (ev.u.mouse.y <= co->top + co->height - (li->bdyAdjust * 2)) &&
+ (ev.u.mouse.x >= co->left + li->bdxAdjust) &&
+ (ev.u.mouse.x <= co->left + co->width + (li->bdxAdjust * 2))) {
+ li->currItem = li->startShowItem +
+ (ev.u.mouse.y - li->bdyAdjust - co->top);
+ newtListboxRealSetCurrent(co);
+ listboxDraw(co);
+ if(co->callback) co->callback(co, co->callbackData);
+ er.result = ER_SWALLOWED;
+ break;
+ }
}
return er;
free(li);
free(co);
}
-
static int cursorRow, cursorCol;
static int needResize;
-static const char * defaultHelpLine =
+static const char * defaultHelpLine =
" <Tab>/<Alt-Tab> between elements | <Space> selects | <F12> next screen"
;
const struct newtColors newtDefaultColorPalette = {
- "white", "blue", /* root fg, bg */
+ "white", "blue", /* root fg, bg */
"black", "lightgray", /* border fg, bg */
"black", "lightgray", /* window fg, bg */
"white", "black", /* shadow fg, bg */
SLsmg_init_smg();
SLang_init_tty(0, 0, 0);
-
+
newtSetColors(newtDefaultColorPalette);
/*initKeymap();*/
SLsignal_intr(SIGWINCH, handleSigwinch);
SLang_getkey_intr_hook = getkeyInterruptHook;
+
+
return 0;
}
SLtt_set_color(NEWT_COLORSET_SHADOW, "", colors.shadowFg, colors.shadowBg);
SLtt_set_color(NEWT_COLORSET_TITLE, "", colors.titleFg, colors.titleBg);
SLtt_set_color(NEWT_COLORSET_BUTTON, "", colors.buttonFg, colors.buttonBg);
- SLtt_set_color(NEWT_COLORSET_ACTBUTTON, "", colors.actButtonFg,
+ SLtt_set_color(NEWT_COLORSET_ACTBUTTON, "", colors.actButtonFg,
colors.actButtonBg);
- SLtt_set_color(NEWT_COLORSET_CHECKBOX, "", colors.checkboxFg,
+ SLtt_set_color(NEWT_COLORSET_CHECKBOX, "", colors.checkboxFg,
colors.checkboxBg);
- SLtt_set_color(NEWT_COLORSET_ACTCHECKBOX, "", colors.actCheckboxFg,
+ SLtt_set_color(NEWT_COLORSET_ACTCHECKBOX, "", colors.actCheckboxFg,
colors.actCheckboxBg);
SLtt_set_color(NEWT_COLORSET_ENTRY, "", colors.entryFg, colors.entryBg);
SLtt_set_color(NEWT_COLORSET_LABEL, "", colors.labelFg, colors.labelBg);
- SLtt_set_color(NEWT_COLORSET_LISTBOX, "", colors.listboxFg,
+ SLtt_set_color(NEWT_COLORSET_LISTBOX, "", colors.listboxFg,
colors.listboxBg);
- SLtt_set_color(NEWT_COLORSET_ACTLISTBOX, "", colors.actListboxFg,
+ SLtt_set_color(NEWT_COLORSET_ACTLISTBOX, "", colors.actListboxFg,
colors.actListboxBg);
- SLtt_set_color(NEWT_COLORSET_TEXTBOX, "", colors.textboxFg,
+ SLtt_set_color(NEWT_COLORSET_TEXTBOX, "", colors.textboxFg,
colors.textboxBg);
- SLtt_set_color(NEWT_COLORSET_ACTTEXTBOX, "", colors.actTextboxFg,
+ SLtt_set_color(NEWT_COLORSET_ACTTEXTBOX, "", colors.actTextboxFg,
colors.actTextboxBg);
- SLtt_set_color(NEWT_COLORSET_HELPLINE, "", colors.helpLineFg,
+ SLtt_set_color(NEWT_COLORSET_HELPLINE, "", colors.helpLineFg,
colors.helpLineBg);
- SLtt_set_color(NEWT_COLORSET_ROOTTEXT, "", colors.rootTextFg,
+ SLtt_set_color(NEWT_COLORSET_ROOTTEXT, "", colors.rootTextFg,
colors.rootTextBg);
SLtt_set_color(NEWT_COLORSET_EMPTYSCALE, "", "black",
SLtt_set_color(NEWT_COLORSET_COMPACTBUTTON, "", colors.compactButtonFg,
colors.compactButtonBg);
-
+
SLtt_set_color(NEWT_COLORSET_ACTSELLISTBOX, "", colors.actSelListboxFg,
colors.actSelListboxBg);
SLtt_set_color(NEWT_COLORSET_SELLISTBOX, "", colors.selListboxFg,
for later */
chptr--;
- while (chptr > buf)
+ while (chptr > buf)
SLang_ungetkey(*chptr--);
return *chptr;
}
}
-int newtOpenWindow(int left, int top, int width, int height,
+int newtOpenWindow(int left, int top, int width, int height,
const char * title) {
int j, row, col;
int n;
top = (SLtt_Screen_Rows - height) / 2;
- /* I don't know why, but this seems to look better */
+ /* I don't know why, but this seems to look better */
if ((SLtt_Screen_Rows % 2) && (top % 2)) top--;
left = (SLtt_Screen_Cols - width) / 2;
void newtPopWindow(void) {
int j, row, col;
- int n = 0;
+ int n = 0;
row = col = 0;
free(currentWindow->buffer);
free(currentWindow->title);
- if (currentWindow == windowStack)
+ if (currentWindow == windowStack)
currentWindow = NULL;
else
currentWindow--;
newtRefresh();
}
+void newtGetWindowPos(int * x, int * y) {
+ if (currentWindow) {
+ *x = currentWindow->left;
+ *y = currentWindow->top;
+ } else
+ *x = *y = 0;
+}
+
void newtGetrc(int * row, int * col) {
*row = cursorRow;
*col = cursorCol;
SLsmg_fill_region(top, left, height, width, ' ');
}
-#if 0
+#if 0
/* This doesn't seem to work quite right. I don't know why not, but when
I rsh from an rxvt into a box and run this code, the machine returns
console key's (\033[B) rather then xterm ones (\033OB). */
char * buf;
SLsmg_set_color(NEWT_COLORSET_HELPLINE);
-
+
buf = alloca(SLtt_Screen_Cols + 1);
memset(buf, ' ', SLtt_Screen_Cols);
buf[SLtt_Screen_Cols] = '\0';
void newtPushHelpLine(const char * text) {
if (!text)
text = defaultHelpLine;
-
+
if (currentHelpline)
(*(++currentHelpline)) = strdup(text);
else {
if (row < 0) {
row = SLtt_Screen_Rows + row;
}
-
+
SLsmg_gotorc(row, col);
SLsmg_write_string((char *)text);
}
return oldFlags | newFlags;
case NEWT_FLAGS_RESET:
- return oldFlags & (~newFlags);
+ return oldFlags & (~newFlags);
case NEWT_FLAGS_TOGGLE:
return oldFlags ^ newFlags;
%setup
%build
+./configure
make
make shared
#ifndef H_NEWT_PR
#define H_NEWT_PR
-#define COLORSET_ROOT NEWT_COLORSET_ROOT
-#define COLORSET_BORDER NEWT_COLORSET_BORDER
+#define COLORSET_ROOT NEWT_COLORSET_ROOT
+#define COLORSET_BORDER NEWT_COLORSET_BORDER
#define COLORSET_WINDOW NEWT_COLORSET_WINDOW
#define COLORSET_SHADOW NEWT_COLORSET_SHADOW
#define COLORSET_TITLE NEWT_COLORSET_TITLE
void newtGotorc(int row, int col);
void newtGetrc(int * row, int * col);
+void newtGetWindowPos(int * x, int * y);
void newtDrawBox(int left, int top, int width, int height, int shadow);
void newtClearBox(int left, int top, int width, int height);
struct newtComponent_struct {
/* common data */
- int height, width;
+ int height, width;
int top, left;
int takesFocus;
int isMapped;
union {
newtComponent focus;
} u;
-};
+};
-enum eventTypes { EV_FOCUS, EV_UNFOCUS, EV_KEYPRESS };
+enum eventTypes { EV_FOCUS, EV_UNFOCUS, EV_KEYPRESS, EV_MOUSE };
enum eventSequence { EV_EARLY, EV_NORMAL, EV_LATE };
struct event {
enum eventSequence when;
union {
int key;
+ struct {
+ enum { MOUSE_MOTION, MOUSE_BUTTON_DOWN, MOUSE_BUTTON_UP } type;
+ int x, y;
+ } mouse;
} u;
} ;
struct scrollbar {
int curr;
int cs, csThumb;
+ int arrows;
} ;
static void sbDraw(newtComponent co);
struct scrollbar * sb = co->data;
int new;
- new = (where * (co->height - 1)) / (total ? total : 1);
+ if (sb->arrows)
+ new = (where * (co->height - 3)) / (total ? total : 1) + 1;
+ else
+ new = (where * (co->height - 1)) / (total ? total : 1);
if (new != sb->curr) {
sbDrawThumb(co, 0);
sb->curr = new;
sb = malloc(sizeof(*sb));
co->data = sb;
- sb->curr = 0;
+ if (!strcmp(getenv("TERM"), "linux") && height >= 2) {
+ sb->arrows = 1;
+ sb->curr = 1;
+ } else {
+ sb->arrows = 0;
+ sb->curr = 0;
+ }
sb->cs = normalColorset;
sb->csThumb = thumbColorset;
SLsmg_set_color(sb->cs);
SLsmg_set_char_set(1);
- for (i = 0; i < co->height; i++) {
- newtGotorc(i + co->top, co->left);
- SLsmg_write_char('\x61');
+ if (sb->arrows) {
+ newtGotorc(co->top, co->left);
+ SLsmg_write_char('\x2d');
+ for (i = 1; i < co->height - 1; i++) {
+ newtGotorc(i + co->top, co->left);
+ SLsmg_write_char('\x61');
+ }
+ newtGotorc(co->top + co->height - 1, co->left);
+ SLsmg_write_char('\x2e');
+ } else {
+ for (i = 0; i < co->height; i++) {
+ newtGotorc(i + co->top, co->left);
+ SLsmg_write_char('\x61');
+ }
}
SLsmg_set_char_set(0);
newtFormAddComponents(f, b1, b2, l1, l2, l3, e1, e2, e3, chklist, NULL);
newtFormAddComponents(f, rsf, scale, NULL);
- lb = newtListbox(45, 1, 4, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER |
+ lb = newtListbox(45, 1, 6, NEWT_FLAG_MULTIPLE | NEWT_FLAG_BORDER |
NEWT_FLAG_SCROLL);
newtListboxAppendEntry(lb, "First", (void *) 1);
newtListboxAppendEntry(lb, "Second", (void *) 2);
do {
answer = newtRunForm(f);
-
+
if (answer == b2) {
newtScaleSet(scale, atoi(scaleVal));
newtRefresh();
answer = NULL;
}
} while (!answer);
-
+
scaleVal = strdup(scaleVal);
enr2 = strdup(enr2);
enr3 = strdup(enr3);
break;
}
}
-
+ if (ev.when == EV_EARLY && ev.event == EV_MOUSE && tb->sb) {
+ /* Top scroll arrow */
+ if (ev.u.mouse.x == co->width && ev.u.mouse.y == co->top) {
+ if (tb->topLine) tb->topLine--;
+ textboxDraw(co);
+
+ er.result = ER_SWALLOWED;
+ }
+ /* Bottom scroll arrow */
+ if (ev.u.mouse.x == co->width &&
+ ev.u.mouse.y == co->top + co->height - 1) {
+ if (tb->topLine < (tb->numLines - co->height)) tb->topLine++;
+ textboxDraw(co);
+
+ er.result = ER_SWALLOWED;
+ }
+ }
return er;
}