lynx-dev
[Top][All Lists]
Advanced

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

Re: lynx-dev [PATCH 2.8.3.dev4] Scrollbar support


From: Ilya Zakharevich
Subject: Re: lynx-dev [PATCH 2.8.3.dev4] Scrollbar support
Date: Tue, 10 Aug 1999 05:50:06 -0400 (EDT)

>> a) This works if you want the mouse click to move you to line 7.
>>    However, I know no global variable which keeps the total amount of
>>    lines, thus setting Newline does not help if you want to go to 7%
>>    of the buffer.
>
>Try HText_getNumOfLines().
>
>Everything doesn't have to become a global variable, there are already
>too many.

Thanks.

The patch below also simplifies the logic of calculating scrollbar
position.  Now the position of the scrollbar after a double click
(=set position) on a scrollbar should be "as close of possible" to the
position of double-click.

Enjoy,
Ilya

--- ./src/GridText.c.pre        Fri Aug  6 22:22:58 1999
+++ ./src/GridText.c    Tue Aug 10 02:22:58 1999
@@ -1229,63 +1229,45 @@ PRIVATE void display_scrollbar ARGS1(
     int i;
     int h = display_lines - 2 * (LYsb_arrow!=0); /* Height of the scrollbar */
     int off = (LYsb_arrow != 0);                /* Start of the scrollbar */
-    int top_skip, bot_skip, last, sh;
+    int top_skip, bot_skip, last, sh, shown;
 
     LYsb_begin = LYsb_end = -1;
     if (!LYsb || !text || h <= 2
        || (text->Lines + 1) <= display_lines)
        return;
 
+    if (text->top_of_screen >= text->Lines + 1 - display_lines) {
+       /* Only part of the screen shows actual text */
+       shown = text->Lines + 1 - text->top_of_screen;
+
+       if (shown <= 0)
+           shown = 1;
+    } else
+       shown = display_lines;
     /* Each cell of scrollbar represents text->Lines/h lines of text. */
     /* Always smaller than h */
-    sh = (display_lines*h + text->Lines/2)/(text->Lines + 1);
+    sh = (shown*h + text->Lines/2)/(text->Lines + 1);
     if (sh <= 0)
        sh = 1;
-    if (sh >= h)
-       sh = h - 1;
+    if (sh >= h - 1)
+       sh = h - 2;             /* Position at ends indicates BEG and END */
 
-    /* Always non-zero if not top, which is text->top_of_screen != 0 . */
-    top_skip = (text->top_of_screen * h + text->Lines)/(text->Lines + 1);
-    if (top_skip >= h)
-       top_skip = h - 1;
-
-    /* End happens when 
-       (text->Lines + 1 - (text->top_of_screen + display_lines - 1))
-       is either 0 or 1. */
-    bot_skip =
-       (text->Lines + 1 - (text->top_of_screen + display_lines - 1) - 1);
-    if (bot_skip < 0)
-       bot_skip = 0;
-    bot_skip = (bot_skip * h + text->Lines)/(text->Lines + 1);
-
-    /* Now make sure the height is always sh unless top_skip==bot_skip==1  */
-    if (top_skip + bot_skip + sh != h && !(top_skip == 1 && bot_skip == 1)) {
-       /* One which is smaller takes precedence. */
-       if (top_skip < bot_skip) {
-           int t = h - top_skip - sh;
-
-           if (t < top_skip)
-               bot_skip = top_skip;
-           else
-               bot_skip = t;
-       } else {
-           int t = h - bot_skip - sh;
-
-           if (t < bot_skip)
-               top_skip = bot_skip;
-           else
-               top_skip = t;       
-       }
-    }
-    /* Ensure the bar is visible if h >= 3 */
-    if (top_skip + bot_skip >= h)
-       bot_skip = h - top_skip;
-    if (top_skip + bot_skip == h && h >= 3) {
-       if (bot_skip > 1)
-           bot_skip--;
-       else
-           top_skip--;
+    if (text->top_of_screen == 0)
+       top_skip = 0;
+    else if (text->Lines - (text->top_of_screen + display_lines - 1) <= 0)
+       top_skip = h - sh;
+    else {
+       /* text->top_of_screen between 1 and text->Lines - display_lines
+          corresponds to top_skip between 1 and h - sh - 1 */
+       /* Use rounding to get as many positions into top_skip==h - sh - 1
+          as into top_skip == 1:
+          1--->1, text->Lines - display_lines + 1--->h - sh. */
+       top_skip = 1 + 
+           1. * (h - sh - 1) * text->top_of_screen
+               /(text->Lines - display_lines + 1);
     }
+    bot_skip = h - sh - top_skip;
+
     LYsb_begin = top_skip;
     LYsb_end = h - bot_skip;
 
--- ./src/LYStrings.c.pre       Fri Aug  6 22:20:14 1999
+++ ./src/LYStrings.c   Tue Aug 10 01:45:14 1999
@@ -315,6 +315,17 @@ PRIVATE int set_clicked_link ARGS4(
            return INSERT_KEY;
        if (y >= h)
            return REMOVE_KEY;
+#ifdef DISP_PARTIAL                    /* Newline is not defined otherwise */
+       if (clicks >= 2) {
+           double frac = (1. * y)/(h - 1);
+           int l = HText_getNumOfLines() + 1;  /* NOL() off by one? */
+
+           l -= display_lines;
+           if (l > 0)
+               Newline = frac * l + 1 + 0.5;
+           return LYReverseKeymap(LYK_DO_NOTHING);
+       }
+#endif
        if (y < LYsb_begin)
            return PGUP;
        if (y >= LYsb_end)

reply via email to

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