summaryrefslogtreecommitdiffstats
path: root/contrib/ncurses/form/frm_driver.c
diff options
context:
space:
mode:
authorrafan <rafan@FreeBSD.org>2007-12-30 11:08:14 +0000
committerrafan <rafan@FreeBSD.org>2007-12-30 11:08:14 +0000
commit9f9e55f97a716ef0dd4082c4cef00a5a95b624a9 (patch)
tree319eb1471eaf8c0c9cfc606e7cb8987ca9167507 /contrib/ncurses/form/frm_driver.c
parent7ed1a8e865bedf5154163476c1224b868257ab1a (diff)
downloadFreeBSD-src-9f9e55f97a716ef0dd4082c4cef00a5a95b624a9.zip
FreeBSD-src-9f9e55f97a716ef0dd4082c4cef00a5a95b624a9.tar.gz
Import ncurses 5.6-20071222 snapshot onto the vender branch
Diffstat (limited to 'contrib/ncurses/form/frm_driver.c')
-rw-r--r--contrib/ncurses/form/frm_driver.c131
1 files changed, 123 insertions, 8 deletions
diff --git a/contrib/ncurses/form/frm_driver.c b/contrib/ncurses/form/frm_driver.c
index 354bace..25928c5 100644
--- a/contrib/ncurses/form/frm_driver.c
+++ b/contrib/ncurses/form/frm_driver.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -32,7 +32,7 @@
#include "form.priv.h"
-MODULE_ID("$Id: frm_driver.c,v 1.76 2006/11/04 18:45:35 tom Exp $")
+MODULE_ID("$Id: frm_driver.c,v 1.85 2007/11/24 21:32:53 tom Exp $")
/*----------------------------------------------------------------------------
This is the core module of the form library. It contains the majority
@@ -262,7 +262,19 @@ wins_wchnstr(WINDOW *w, cchar_t *s, int n)
static int
fix_wchnstr(WINDOW *w, cchar_t *s, int n)
{
+ int x;
+
win_wchnstr(w, s, n);
+ /*
+ * This function is used to extract the text only from the window.
+ * Strip attributes and color from the string so they will not be added
+ * back when copying the string to the window.
+ */
+ for (x = 0; x < n; ++x)
+ {
+ RemAttr(s[x], A_ATTRIBUTES);
+ SetPair(s[x], 0);
+ }
return n;
}
@@ -651,6 +663,7 @@ Field_Grown(FIELD *field, int amount)
result = TRUE; /* allow sharing of recovery on failure */
+ T((T_CREATE("fieldcell %p"), newbuf));
field->buf = newbuf;
for (i = 0; i <= field->nbuf; i++)
{
@@ -724,6 +737,34 @@ Field_Grown(FIELD *field, int amount)
return (result);
}
+#ifdef NCURSES_MOUSE_VERSION
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : int Field_encloses(FIELD *field, int ry, int rx)
+|
+| Description : Check if the given coordinates lie within the given field.
+|
+| Return Values : E_OK - success
+| E_BAD_ARGUMENT - invalid form pointer
+| E_SYSTEM_ERROR - form has no current field or
+| field-window
++--------------------------------------------------------------------------*/
+static int
+Field_encloses(FIELD *field, int ry, int rx)
+{
+ T((T_CALLED("Field_encloses(%p)"), field));
+ if (field != 0
+ && field->frow <= ry
+ && (field->frow + field->rows) > ry
+ && field->fcol <= rx
+ && (field->fcol + field->cols) > rx)
+ {
+ RETURN(E_OK);
+ }
+ RETURN(E_INVALID_FIELD);
+}
+#endif
+
/*---------------------------------------------------------------------------
| Facility : libnform
| Function : int _nc_Position_Form_Cursor(FORM * form)
@@ -4149,6 +4190,83 @@ form_driver(FORM *form, int c)
res = (BI->cmd) (form);
}
}
+#ifdef NCURSES_MOUSE_VERSION
+ else if (KEY_MOUSE == c)
+ {
+ MEVENT event;
+ WINDOW *win = form->win ? form->win : stdscr;
+ WINDOW *sub = form->sub ? form->sub : win;
+
+ getmouse(&event);
+ if ((event.bstate & (BUTTON1_CLICKED |
+ BUTTON1_DOUBLE_CLICKED |
+ BUTTON1_TRIPLE_CLICKED))
+ && wenclose(win, event.y, event.x))
+ { /* we react only if the click was in the userwin, that means
+ * inside the form display area or at the decoration window.
+ */
+ int ry = event.y, rx = event.x; /* screen coordinates */
+
+ res = E_REQUEST_DENIED;
+ if (mouse_trafo(&ry, &rx, FALSE))
+ { /* rx, ry are now "curses" coordinates */
+ if (ry < sub->_begy)
+ { /* we clicked above the display region; this is
+ * interpreted as "scroll up" request
+ */
+ if (event.bstate & BUTTON1_CLICKED)
+ res = form_driver(form, REQ_PREV_FIELD);
+ else if (event.bstate & BUTTON1_DOUBLE_CLICKED)
+ res = form_driver(form, REQ_PREV_PAGE);
+ else if (event.bstate & BUTTON1_TRIPLE_CLICKED)
+ res = form_driver(form, REQ_FIRST_FIELD);
+ }
+ else if (ry > sub->_begy + sub->_maxy)
+ { /* we clicked below the display region; this is
+ * interpreted as "scroll down" request
+ */
+ if (event.bstate & BUTTON1_CLICKED)
+ res = form_driver(form, REQ_NEXT_FIELD);
+ else if (event.bstate & BUTTON1_DOUBLE_CLICKED)
+ res = form_driver(form, REQ_NEXT_PAGE);
+ else if (event.bstate & BUTTON1_TRIPLE_CLICKED)
+ res = form_driver(form, REQ_LAST_FIELD);
+ }
+ else if (wenclose(sub, event.y, event.x))
+ { /* Inside the area we try to find the hit item */
+ int i;
+
+ ry = event.y;
+ rx = event.x;
+ if (wmouse_trafo(sub, &ry, &rx, FALSE))
+ {
+ int min_field = form->page[form->curpage].pmin;
+ int max_field = form->page[form->curpage].pmax;
+
+ for (i = min_field; i <= max_field; ++i)
+ {
+ FIELD *field = form->field[i];
+
+ if (Field_Is_Selectable(field)
+ && Field_encloses(field, ry, rx) == E_OK)
+ {
+ res = _nc_Set_Current_Field(form, field);
+ if (res == E_OK)
+ res = _nc_Position_Form_Cursor(form);
+ if (res == E_OK
+ && (event.bstate & BUTTON1_DOUBLE_CLICKED))
+ res = E_UNKNOWN_COMMAND;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ else
+ res = E_REQUEST_DENIED;
+ }
+#endif /* NCURSES_MOUSE_VERSION */
else if (!(c & (~(int)MAX_REGULAR_CHARACTER)))
{
/*
@@ -4261,7 +4379,7 @@ set_field_buffer(FIELD *field, int buffer, const char *value)
wclear(field->working);
mvwaddstr(field->working, 0, 0, value);
- if ((widevalue = (FIELD_CELL *)calloc(len, sizeof(FIELD_CELL))) == 0)
+ if ((widevalue = typeCalloc(FIELD_CELL, len + 1)) == 0)
{
RETURN(E_SYSTEM_ERROR);
}
@@ -4341,10 +4459,7 @@ field_buffer(const FIELD *field, int buffer)
init_mb(state);
next = _nc_wcrtomb(0, data[n].chars[0], &state);
if (!isEILSEQ(next))
- {
- if (next != 0)
- need += next;
- }
+ need += next;
}
}
@@ -4358,7 +4473,7 @@ field_buffer(const FIELD *field, int buffer)
{
wclear(field->working);
mvwadd_wchnstr(field->working, 0, 0, data, size);
- mvwinnstr(field->working, 0, 0, result, (int)need + 1);
+ mvwinnstr(field->working, 0, 0, result, (int)need);
}
#else
result = Address_Of_Nth_Buffer(field, buffer);
OpenPOWER on IntegriCloud