lynx-dev
[Top][All Lists]
Advanced

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

lynx-dev [PATCH 2.8.3.dev4] User interface patches


From: Ilya Zakharevich
Subject: lynx-dev [PATCH 2.8.3.dev4] User interface patches
Date: Sun, 18 Jul 1999 01:11:52 -0400 (EDT)

This patch (in the order of chunks down below):

  a) Makes lynx ignore mouse events which are not clicks (filtering through
        ncurses does not work).

  b) Makes mouse-clicks "basin of attraction" of a link wider (the
        area where clicks make the link a current link).  It was 
        2 units vertically and horizontally, make it 2 units vertically,
        and 6 units horisontally.  This leads to "more intuitive selection".

  c) Make processing of .lynx-keymap write messages to trace buffer;

  d) LAC-keybindings were not working;

  e) Allow .lss files include one another via INCLUDE:/file/name

  g) Allow a change of default color in .lss files (not the color of
        attributeles text, but colors for a style if "default" is specified);
        This (together with "e") allows for a simple modification of a color
        scheme (see example below);

  h) Improve algorithm for allocation of color-pairs;

  i) Lynx was not recognizing HOME directory on EMX;

  j) UP_LINK and DOWN_LINK now actually move along a vertical line (as
        far as it is possible), including an arbitrary sequence of
        such keypresses.

Enjoy,
Ilya

P.S. Here is an example of a .lss file with a changed default
     foreground/background and a handful of other declarations
     fine-tuned for this change.  [It implements "Commander" style.]

     "Overriding" declarations should be put before INCLUDE:,
     and the default: declaration should be the last one.

     Note declaration
        normal:normal:default:default
     Should not it go into standard .lss - now when it makes some sense?

status:reverse:yellow:black
h1:bold:yellow:black
em.a:reverse:black:blue
em.b:reverse:white:black
font.letter:normal:default:black
link.blue:bold:white:brightblue
link.blue.prev:bold:yellow:brightblue
title:normal:magenta:black
i:bold:white
table:normal:white
blockquote:normal:white
li.blue:bold:blue:black
link.blue.next:bold:blue:black
normal:normal:default:default
INCLUDE:F:/emx.add/lib/lynx.lss
default:normal:brightcyan:blue

--- src/LYCurses.c~     Wed Jul 14 09:25:26 1999
+++ src/LYCurses.c      Sat Jul 17 16:16:18 1999
@@ -938,14 +938,18 @@ PUBLIC void lynx_enable_mouse ARGS1(int,
        /* Inform ncurses which mouse events we're interested in.
         * We shouldn't need to include BUTTONn_PRESSED and BUTTONn_RELEASED
         * events, since ncurses should translate them to click events. - kw
+        * However, if we do not include them, then ncurses effectively
+        * ignores mouseinterval(), thus translates *any* sequence of
+        * press/release to a click, which leads to unconviniences.
+        * We special-case these events in LYStrings.c.
         */
        mousemask(BUTTON_CTRL | BUTTON_ALT
-                 /* | BUTTON1_PRESSED | BUTTON1_RELEASED */
+                 | BUTTON1_PRESSED | BUTTON1_RELEASED
                  | BUTTON1_CLICKED
                  | BUTTON1_DOUBLE_CLICKED | BUTTON1_TRIPLE_CLICKED
-                 /* | BUTTON2_PRESSED | BUTTON2_RELEASED */
+                 | BUTTON2_PRESSED | BUTTON2_RELEASED
                  | BUTTON2_CLICKED
-                 /* | BUTTON3_PRESSED | BUTTON3_RELEASED */
+                 | BUTTON3_PRESSED | BUTTON3_RELEASED
                  | BUTTON3_CLICKED
                  | BUTTON3_DOUBLE_CLICKED | BUTTON3_TRIPLE_CLICKED,
                  NULL);
--- src/LYStrings.c~    Wed Jul 14 09:25:26 1999
+++ src/LYStrings.c     Sat Jul 17 19:35:14 1999
@@ -271,7 +271,9 @@ PRIVATE int XYdist ARGS5(
        xerr = 0;
     if (yerr < 0)
        yerr = -yerr;
-    return xerr + yerr;
+    if (xerr < 3 && yerr)      /* x-distance of 3 better than y-dist of 1 */
+       return yerr + 1;
+    return (xerr + 2)/3 + yerr;        /* Subjective factor of distance */
 }
 
 /* Given X and Y coordinates of a mouse event, set mouse_link to the
@@ -304,7 +306,7 @@ PRIVATE int set_clicked_link ARGS4(
        else if (x > right) c = '\b';
        else c = PGUP;
     } else {
-       int mouse_err = 3, /* must be closer than this for approx stuff */
+       int mouse_err = 4, /* subjctv-dist better than this for approx stuff */
            cur_err;
 
        /* Loop over the links and see if we can get a match */
@@ -975,20 +977,33 @@ PRIVATE int setkey_cmd (char *parse)
     int keysym;
     char buf[BUFSIZ];
 
+    CTRACE(tfp, "KEYMAP(PA): in=%s", parse);   /* \n-terminated */
     if ((s = skip_keysym(parse)) != 0) {
        if (isspace(*s)) {
            *s++ = '\0';
            s = LYSkipBlanks(s);
-           if ((t = skip_keysym(s)) == 0)
+           if ((t = skip_keysym(s)) == 0) {
+               CTRACE(tfp, "KEYMAP(SKIP) no key expansion found\n");
                return -1;
+           }
            if (t != s)
                *t = '\0';
            if (map_string_to_keysym (s, &keysym) >= 0
             && unescape_string(parse, buf)) {
+               CTRACE(tfp, "KEYMAP(DEF) keysym=%#x, seq='%s'\n", keysym, buf);
                return define_key(buf, keysym);
            }
+           else {
+               CTRACE(tfp, "KEYMAP(SKIP) could not map to keysym\n");
+           }
+       }
+       else {
+           CTRACE(tfp, "KEYMAP(SKIP) junk after key description: '%s'\n", s);
        }
     }
+    else {
+       CTRACE(tfp, "KEYMAP(SKIP) no key description\n");
+    }
     return -1;
 }
 
@@ -1587,6 +1602,9 @@ re_read:
        current_modifier = LKC_MOD2;
        c &= LKC_MASK;
     }
+    if (c >= 0 && (c&LKC_ISLAC)) {
+       done_esc = TRUE; /* already a lynxactioncode, skip keypad switches - iz 
*/
+    }
 #endif
     if (done_esc) {
        /* don't do keypad() switches below, we already got it - kw */
@@ -1827,7 +1845,12 @@ re_read:
                        lac = LYK_SUBMIT;
                } else if (event.bstate & BUTTON3_CLICKED) {
                    c = LAC_TO_LKC0(LYK_PREV_DOC);
-               } else if (code == FOR_PROMPT) {
+               } else if (code == FOR_PROMPT
+                                /* Cannot ignore: see LYCurses.c */
+                          || (event.bstate &
+                               ( BUTTON1_PRESSED | BUTTON1_RELEASED
+                                 | BUTTON2_PRESSED | BUTTON2_RELEASED
+                                 | BUTTON3_PRESSED | BUTTON3_RELEASED))) {
                    /* Completely ignore - don't return anything, to
                       avoid canceling the prompt - kw */
                    goto re_read;
@@ -2067,6 +2090,8 @@ re_read:
     }
 #endif /* USE_SLANG && __DJGPP__ && !DJGPP_KEYHANDLER && !USE_KEYMAPS */
 
+    if (c&LKC_ISLAC)
+       return(c);
     if ((c+1) >= KEYMAP_SIZE) {
        /*
         *  Don't return raw values for KEYPAD symbols which we may have
--- src/LYStyle.c.pre   Wed Jul 14 09:25:26 1999
+++ src/LYStyle.c       Sat Jul 17 17:46:54 1999
@@ -68,7 +68,7 @@ PUBLIC int    s_alink  = NOSTYLE, s_a     =
 
 /* start somewhere safe */
 PRIVATE int colorPairs = 0;
-PRIVATE int last_fA = COLOR_WHITE, last_bA = COLOR_BLACK;
+PRIVATE unsigned char our_pairs[2][8][8];
 
 /* icky parsing of the style options */
 PRIVATE void parse_attributes 
ARGS5(char*,mono,char*,fg,char*,bg,int,style,char*,element)
@@ -118,6 +118,13 @@ PRIVATE void parse_attributes ARGS5(char
 
     fA = check_color(fg, default_fg);
     bA = check_color(bg, default_bg);
+
+    if (style == -1) {                 /* default */
+       CTRACE(tfp, "CSS(DEF):default_fg=%d, default_bg=%d\n", fA, bA);
+        default_fg = fA;
+        default_bg = bA;
+       return;
+    }
     if (fA == NO_COLOR) {
        bA = NO_COLOR;
     } else if (COLORS) {
@@ -139,18 +146,26 @@ PRIVATE void parse_attributes ARGS5(char
      */
     if (lynx_has_color && colorPairs < COLOR_PAIRS-1 && fA != NO_COLOR)
     {
-       if (colorPairs <= 0 || fA != last_fA || bA != last_bA) {
-           colorPairs++;
-           init_pair(colorPairs, fA, bA);
-           last_fA = fA;
-           last_bA = bA;
+       int curPair;
+
+       if (fA < 8 && bA < 8 && our_pairs[cA == A_BOLD][fA][bA])
+           curPair = our_pairs[cA == A_BOLD][fA][bA] - 1;
+       else {
+           curPair = ++colorPairs;
+           init_pair(curPair, fA, bA);
+           if (fA < 8 && bA < 8 && curPair < 255)
+               our_pairs[cA == A_BOLD][fA][bA] = curPair + 1;
        }
+       CTRACE(tfp, "CSS(CURPAIR):%d\n", colorPairs);
        if (style < DSTYLE_ELEMENTS)
-           setStyle(style, COLOR_PAIR(colorPairs)|cA, cA, mA);
-       setHashStyle(newstyle, COLOR_PAIR(colorPairs)|cA, cA, mA, element);
+           setStyle(style, COLOR_PAIR(curPair)|cA, cA, mA);
+       setHashStyle(newstyle, COLOR_PAIR(curPair)|cA, cA, mA, element);
     }
     else
     {
+       if (lynx_has_color && fA != NO_COLOR) {
+           CTRACE(tfp, "CSS(NC): maximum of %d colorpairs exhausted\n", 
COLOR_PAIR - 1);
+       }
     /* only mono is set */
        if (style < DSTYLE_ELEMENTS)
            setStyle(style, -1, -1, mA);
@@ -218,7 +233,11 @@ where OBJECT is one of EM,STRONG,B,I,U,B
     /*
     * We use some pseudo-elements, so catch these first
     */
-    if (!strncasecomp(element, "alink", 5)) /* active link */
+    if (!strncasecomp(element, "default", 7)) /* default fg/bg */
+    {
+       parse_attributes(mono,fg,bg,-1,"default");
+    }
+    else if (!strncasecomp(element, "alink", 5)) /* active link */
     {
        parse_attributes(mono,fg,bg,DSTYLE_ALINK,"alink");
     }
@@ -396,7 +415,7 @@ PUBLIC void style_defaultStyleSheet NOAR
                HStyle_addStyle(default_stylesheet[i]);
 }
 
-PUBLIC int style_readFromFile ARGS1(char*, file)
+PRIVATE int style_readFromFileREC ARGS2(char*, file, int, toplevel)
 {
     FILE *fh;
     char *buffer = NULL;
@@ -413,15 +432,19 @@ PUBLIC int style_readFromFile ARGS1(char
        return -1;
     }
 
-    style_initialiseHashTable();
-    style_deleteStyleList();
+    if (toplevel) {
+      style_initialiseHashTable();
+      style_deleteStyleList();
+    }
 
     while (LYSafeGets(&buffer, fh) != NULL)
     {
        LYTrimTrailing(buffer);
        LYTrimTail(buffer);
        LYTrimHead(buffer);
-       if (buffer[0] != '#' && (len = strlen(buffer)) > 0)
+       if (!strncasecomp(buffer,"include:",8))
+           style_readFromFileREC(buffer+8, 0);
+       else if (buffer[0] != '#' && (len = strlen(buffer)) > 0)
            HStyle_addStyle(buffer);
     }
     /* the default styles are added after the user styles in order
@@ -430,9 +453,14 @@ PUBLIC int style_readFromFile ARGS1(char
     /* style_defaultStyleSheet(); */
 
     fclose (fh);
-    if (LYCursesON)
+    if (toplevel && LYCursesON)
        parse_userstyles();
     return 0;
+}
+
+PUBLIC int style_readFromFile ARGS1(char*, file)
+{
+    return style_readFromFileREC(file, 1);
 }
 
 /* Used in HTStructured methods: - kw */
--- src/LYUtils.c~      Wed Jul 14 09:25:26 1999
+++ src/LYUtils.c       Sat Jul 17 16:37:56 1999
@@ -5298,7 +5298,12 @@ PUBLIC CONST char * Home_Dir NOARGS
     if (homedir == NULL) {
        if ((cp = getenv("HOME")) == NULL || *cp == '\0'
 #ifdef UNIX
-           || *cp != '/'
+           || !(*cp == '/'
+#  ifdef __EMX__
+                || *cp == '\\' 
+                || (*cp && cp[1] == ':' && (cp[2] == '/' || cp[2] == '\\'))
+#  endif
+               )
 #endif /* UNIX */
            ) {
 #if defined (DOSPATH) || defined (__EMX__) /* BAD!     WSB */
--- src/LYMainLoop.c.orig       Wed Jul 14 09:25:26 1999
+++ src/LYMainLoop.c    Sat Jul 17 21:29:14 1999
@@ -358,6 +358,33 @@ PRIVATE int do_change_link ARGS1(
     return(0);                 /* indicates OK */
 }
 
+PRIVATE int find_link_near_col ARGS2( int, col, int, delta)
+{
+    int i;
+
+    for (i = curdoc.link; delta > 0 ? (i < nlinks) : (i >= 0); i += delta)
+       if ( (links[i].ly - links[curdoc.link].ly)*delta > 0 ) {
+            int cy = links[i].ly, best = -1, dist = 1000000;
+
+            while ((delta > 0 ? (i < nlinks) : (i >= 0)) && cy == links[i].ly) 
{
+                int cx = links[i].lx;
+                           
+                if (links[i].hightext) 
+                    cx += strlen(links[i].hightext)/2;
+                cx -= col;
+                if (cx < 0)
+                    cx = -cx;
+                if (cx < dist) {
+                    dist = cx;
+                    best = i;
+                }
+                i += delta;
+            }
+            return(best);
+       }
+    return(-1);
+}
+
 /*
  *  Here's where we do all the work.
  *  mainloop is basically just a big switch dependent on the users input.
@@ -412,6 +439,7 @@ int mainloop NOARGS
     unsigned int len;
     int i;
     int n;
+    int follow_col = -1;
 
 #ifdef DIRED_SUPPORT
     char *tp = NULL;
@@ -1949,6 +1977,9 @@ new_cmd:  /*
        force_old_UCLYhndl_on_reload = FALSE;
        CTRACE_FLUSH(tfp);
 
+       if (cmd != LYK_UP_LINK && cmd != LYK_DOWN_LINK)
+           follow_col = -1;
+
        switch(cmd) {
        case 0: /* unmapped character */
        default:
@@ -2966,13 +2997,16 @@ new_cmd:  /*
                 !HText_LinksInLines(HTMainText, 1, Newline - 1))) {
                /* more links before this on screen, and first of them on
                   a different line or no previous links before this screen? */
-               int newlink = -1;
-               for (i = curdoc.link; i >= 0; i--) {
-                   if (links[i].ly < links[curdoc.link].ly) {
-                       newlink = i;
-                       break;
-                   }
+               int newlink;
+
+               if (follow_col == -1) {
+                   follow_col = links[curdoc.link].lx;
+
+                   if (links[curdoc.link].hightext) 
+                       follow_col += strlen(links[curdoc.link].hightext)/2;
                }
+
+               newlink = find_link_near_col(follow_col, -1);
                if (newlink > -1) {
                    highlight(OFF, curdoc.link, prev_target);
                    curdoc.link = newlink;
@@ -3021,13 +3055,16 @@ new_cmd:  /*
 
        case LYK_DOWN_LINK:
            if (curdoc.link < (nlinks-1)) {     /* more links? */
-               int newlink = -1;
-               for (i = curdoc.link; i < nlinks; i++)
-                  if (links[i].ly > links[curdoc.link].ly) {
-                       newlink = i;
-                       break;
-                  }
+               int newlink;
+
+               if (follow_col == -1) {
+                   follow_col = links[curdoc.link].lx;
+
+                   if (links[curdoc.link].hightext) 
+                       follow_col += strlen(links[curdoc.link].hightext)/2;
+               }
 
+               newlink = find_link_near_col(follow_col, 1);
                if (newlink > -1) {
                    highlight(OFF, curdoc.link, prev_target);
                    curdoc.link = newlink;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]