Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libform * Fix cursor motion bugs referred to in pr 17480



details:   https://anonhg.NetBSD.org/src/rev/c18a8dfa2b28
branches:  trunk
changeset: 534543:c18a8dfa2b28
user:      blymn <blymn%NetBSD.org@localhost>
date:      Mon Jul 29 05:17:37 2002 +0000

description:
* Fix cursor motion bugs referred to in pr 17480
 * Handle cursor motion for justifications other than left justified.

diffstat:

 lib/libform/driver.c    |   13 +-
 lib/libform/field.c     |   10 +-
 lib/libform/internals.c |  286 +++++++++++++++++++++++++++++------------------
 lib/libform/internals.h |    4 +-
 4 files changed, 194 insertions(+), 119 deletions(-)

diffs (truncated from 554 to 300 lines):

diff -r 94ea264dadd6 -r c18a8dfa2b28 lib/libform/driver.c
--- a/lib/libform/driver.c      Mon Jul 29 04:24:47 2002 +0000
+++ b/lib/libform/driver.c      Mon Jul 29 05:17:37 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: driver.c,v 1.12 2002/05/20 15:00:11 blymn Exp $        */
+/*     $NetBSD: driver.c,v 1.13 2002/07/29 05:17:37 blymn Exp $        */
 
 /*-
  * Copyright (c) 1998-1999 Brett Lymn
@@ -321,7 +321,7 @@
                        if ((form->opts & O_BS_OVERLOAD) == O_BS_OVERLOAD) {
                                if ((fieldp->start_char == 0) &&
                                    (fieldp->start_line == 0) &&
-                                   (fieldp->cursor_xpos == 0)) {
+                                   (fieldp->row_xpos == 0)) {
                                        update_field =
                                                _formi_manipulate_field(form,
                                                        REQ_PREV_FIELD);
@@ -341,7 +341,7 @@
                        if ((form->opts & O_NL_OVERLOAD) == O_NL_OVERLOAD) {
                                if ((fieldp->start_char == 0) &&
                                    (fieldp->start_line == 0) &&
-                                   (fieldp->cursor_xpos == 0)) {
+                                   (fieldp->row_xpos == 0)) {
                                        update_field =
                                                _formi_manipulate_field(form,
                                                        REQ_NEXT_FIELD);
@@ -406,6 +406,11 @@
                case REQ_PREV_CHOICE:
                case REQ_NEXT_CHOICE:
                        update_field = _formi_field_choice(form, c);
+                         /* reinit the cursor pos just in case */
+                       if (update_field == 1) {
+                               _formi_init_field_xpos(fieldp);
+                               fieldp->row_xpos = 0;
+                       }
                        break;
 
                default: /* should not need to do this, but.... */
@@ -438,8 +443,8 @@
                fieldp->start_char = 0;
                fieldp->start_line = 0;
                fieldp->row_xpos = 0;
-               fieldp->cursor_xpos = 0;
                fieldp->cursor_ypos = 0;
+               _formi_init_field_xpos(fieldp);
        }
        
        if (update_field < 0)
diff -r 94ea264dadd6 -r c18a8dfa2b28 lib/libform/field.c
--- a/lib/libform/field.c       Mon Jul 29 04:24:47 2002 +0000
+++ b/lib/libform/field.c       Mon Jul 29 05:17:37 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: field.c,v 1.16 2002/07/04 10:51:02 blymn Exp $ */
+/*     $NetBSD: field.c,v 1.17 2002/07/29 05:17:37 blymn Exp $ */
 /*-
  * Copyright (c) 1998-1999 Brett Lymn
  *                         (blymn%baea.com.au@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -209,8 +209,16 @@
        if ((justification < MIN_JUST_STYLE) /* check justification valid */
            || (justification > MAX_JUST_STYLE))
                return E_BAD_ARGUMENT;
+
+         /* only allow justification on static, single row fields */
+       if (((fp->opts & O_STATIC) != O_STATIC) ||
+           ((fp->rows + fp->nrows) > 1))
+               return E_BAD_ARGUMENT;
        
        fp->justification = justification;
+
+       _formi_init_field_xpos(fp);
+       
        return E_OK;
 }
 
diff -r 94ea264dadd6 -r c18a8dfa2b28 lib/libform/internals.c
--- a/lib/libform/internals.c   Mon Jul 29 04:24:47 2002 +0000
+++ b/lib/libform/internals.c   Mon Jul 29 05:17:37 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: internals.c,v 1.24 2002/07/08 10:43:37 blymn Exp $     */
+/*     $NetBSD: internals.c,v 1.25 2002/07/29 05:17:38 blymn Exp $     */
 
 /*-
  * Copyright (c) 1998-1999 Brett Lymn
@@ -93,6 +93,8 @@
 static void
 _formi_scroll_fwd(FIELD *field, unsigned int amt);
 static int
+_formi_set_cursor_xpos(FIELD *field);
+static int
 find_sow(char *str, unsigned int offset);
 static int
 find_cur_line(FIELD *cur, unsigned pos);
@@ -113,6 +115,38 @@
 
 
 /*
+ * Initialise the row offset for a field, depending on the type of
+ * field it is and the type of justification used.  The justification
+ * is only used on static single line fields, everything else will
+ * have the cursor_xpos set to 0.
+ */
+void
+_formi_init_field_xpos(FIELD *field)
+{
+         /* not static or is multi-line which are not justified, so 0 it is */
+       if (((field->opts & O_STATIC) != O_STATIC) ||
+           ((field->rows + field->nrows) != 1)) {
+               field->cursor_xpos = 0;
+               return;
+       }
+       
+       switch (field->justification) {
+       case JUSTIFY_RIGHT:
+               field->cursor_xpos = field->cols - 1;
+               break;
+
+       case JUSTIFY_CENTER:
+               field->cursor_xpos = (field->cols - 1) / 2;
+               break;
+
+       default: /* assume left justify */
+               field->cursor_xpos = 0;
+               break;
+       }
+}
+
+       
+/*
  * Open the debug file if it is not already open....
  */
 #ifdef DEBUG
@@ -1359,11 +1393,11 @@
                field->start_line = 0;
                field->row_count = 1;
                field->row_xpos = 0;
-               field->cursor_xpos = 0;
                field->cursor_ypos = 0;
                field->lines[0].start = 0;
                field->lines[0].end = 0;
                field->lines[0].length = 0;
+               _formi_init_field_xpos(field);
        }
 
 
@@ -1460,33 +1494,8 @@
        } else {
                field->buf0_status = TRUE;
                if ((field->rows + field->nrows) == 1) {
-                       if ((field->cursor_xpos < (field->cols - 1)) ||
-                           ((field->opts & O_STATIC) != O_STATIC)) {
-                               field->row_xpos++;
-                               field->cursor_xpos =
-                                       _formi_tab_expanded_length(
-                                               field->buffers[0].string,
-                                               field->start_char,
-                                               field->row_xpos
-                                               + field->start_char);
-                               if ((field->start_char + field->row_xpos)
-                                   < field->buffers[0].length)
-                                       field->cursor_xpos--;
-                       }
-                       
-                       if (field->cursor_xpos > (field->cols - 1)) {
-                               field->start_char =
-                                       tab_fit_window(field,
-                                                      field->start_char + field->row_xpos,
-                                                      field->cols);
-                               field->row_xpos = pos - field->start_char + 1;
-                               field->cursor_xpos =
-                                       _formi_tab_expanded_length(
-                                               field->buffers[0].string,
-                                               field->start_char,
-                                               field->row_xpos
-                                               + field->start_char - 1);
-                       }
+                       field->row_xpos++;
+                       status = _formi_set_cursor_xpos(field);
                } else {
                        if (new_size >= field->rows) {
                                field->cursor_ypos = field->rows - 1;
@@ -1544,6 +1553,112 @@
 }
 
 /*
+ * Set the position of the cursor on the screen in the row depending on
+ * where the current position in the string is and the justification
+ * that is to be applied to the field.  Justification is only applied
+ * to single row, static fields.
+ */
+static int
+_formi_set_cursor_xpos(FIELD *field)
+{
+       int just, pos;
+
+       just = field->justification;
+       pos = field->start_char + field->row_xpos
+          + field->lines[field->start_line + field->cursor_ypos].start;
+
+#ifdef DEBUG
+       fprintf(dbg,
+         "cursor_xpos enter: pos %d, start_char %d, row_xpos %d, xpos %d\n",
+               pos, field->start_char, field->row_xpos, field->cursor_xpos);
+#endif
+       
+         /*
+          * make sure we apply the correct justification to non-static
+          * fields.
+          */
+       if (((field->rows + field->nrows) != 1) ||
+           ((field->opts & O_STATIC) != O_STATIC))
+               just = JUSTIFY_LEFT;
+       
+       switch (just) {
+       case JUSTIFY_RIGHT:
+               field->cursor_xpos = field->cols - 1
+                       - _formi_tab_expanded_length(
+                               field->buffers[0].string, 0,
+                               field->buffers[0].length - 1)
+                       + _formi_tab_expanded_length(
+                               field->buffers[0].string, 0,
+                               field->row_xpos);
+               break;
+
+       case JUSTIFY_CENTER:
+               field->cursor_xpos = ((field->cols - 1) 
+                       - _formi_tab_expanded_length(
+                               field->buffers[0].string, 0,
+                               field->buffers[0].length - 1) + 1) / 2
+                       + _formi_tab_expanded_length(field->buffers[0].string,
+                                                    0, field->row_xpos);
+               
+               if (field->cursor_xpos > (field->cols - 1))
+                       field->cursor_xpos = (field->cols - 1);
+               break;
+
+       default:
+               field->cursor_xpos = _formi_tab_expanded_length(
+                       field->buffers[0].string,
+                       field->start_char,
+                       field->row_xpos + field->start_char);
+               if ((field->cursor_xpos <= (field->cols - 1)) &&
+                   ((field->start_char + field->row_xpos)
+                    < field->buffers[0].length))
+                       field->cursor_xpos--;
+
+               if (field->cursor_xpos > (field->cols - 1)) {
+                       if ((field->opts & O_STATIC) == O_STATIC) {
+                               field->start_char = 0;
+
+                               if (field->row_xpos
+                                   == (field->buffers[0].length - 1)) {
+                                       field->cursor_xpos = field->cols - 1;
+                               } else {
+                                       field->cursor_xpos =
+                                               _formi_tab_expanded_length(
+                                                 field->buffers[0].string,
+                                                 field->start_char,
+                                                 field->row_xpos
+                                                   + field->start_char
+                                                 - 1) - 1;
+                               }
+                       } else {
+                               field->start_char =
+                                       tab_fit_window(
+                                               field,
+                                               field->start_char
+                                                 + field->row_xpos,
+                                               field->cols);
+                               field->row_xpos = pos - field->start_char;
+                               field->cursor_xpos =
+                                       _formi_tab_expanded_length(
+                                               field->buffers[0].string,
+                                               field->start_char,
+                                               field->row_xpos
+                                               + field->start_char - 1);
+                       }
+                       
+               }
+               break;
+       }
+       
+#ifdef DEBUG
+       fprintf(dbg,
+         "cursor_xpos exit: pos %d, start_char %d, row_xpos %d, xpos %d\n",
+               pos, field->start_char, field->row_xpos, field->cursor_xpos);
+#endif
+       return E_OK;
+}
+
+/*
  * Manipulate the text in a field, this takes the given form and performs
  * the passed driver command on the current text field.  Returns 1 if the
  * text field was modified.
@@ -1553,7 +1668,7 @@
 {
        FIELD *cur;
        char *str, saved;
-       unsigned int i, start, end, pos, row, status, old_count, size;
+       unsigned int start, end, pos, row, status, old_count, size;



Home | Main Index | Thread Index | Old Index