giftcurs-devel
[Top][All Lists]
Advanced

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

[giFTcurs-devel] Re: [PATCH] Standard scrolling behavior for lists


From: Charles Levert
Subject: [giFTcurs-devel] Re: [PATCH] Standard scrolling behavior for lists
Date: Sat, 1 Jan 2005 15:38:13 -0500
User-agent: Mutt/1.4.1i

* On Friday 2004-12-31 at 21:59:18 -0500, Charles Levert wrote:
> Changes:

I am replying to my own message here.  Sorry for that.  Since I was
not subscribed to the mailing list, that original message is pending
moderator approval and may never make it now, which is just as well.

This message obsoletes the original one.  Mouse support was added and
a couple minor quirks were fixed.



Changes:

        * Content (list selector) positioning commands should only
          scroll minimally when necessary.  Likewise, scroll commands
          should only minimally modify the content position when
          necessary.  The ui_list_handler() function and the help text
          have been updated to reflect this; the scrolling behavior is
          now similar to that of GNU Emacs or Vim, including a 2-line
          overlap between successive screens.

        * Use of the mouse scroll wheel now primarily performs scrolling,
          not content positioning.  The code for this now reuses the
          logic from ui_list_handler() instead of implementing its own.
          Support for the mouse scroll wheel has been added to the help
          and console windows.



[ Edited with ude,
    the unified-format diff-output ("unidiff") editor,
    version 0.1 of 2004-11-03.  ]
--- src/ui.h.orig-0.6.2 2003-11-16 11:15:36 -0500
+++ src/ui.h    2004-12-31 20:58:35 -0500
@@ -57,7 +57,7 @@
 #endif
 void ui_handler(int key);
 
-int ui_list_handler(list *foo, int key, int page_len);
+int ui_list_handler(list *foo, int key, int page_len, int h);
 
 void ui_draw(void);
 
--- src/ui.c.orig-0.6.2 2003-11-16 11:15:36 -0500
+++ src/ui.c    2004-12-31 21:28:23 -0500
@@ -313,40 +313,65 @@ void ui_draw(void)
        move(curs_y, curs_x);
 }
 
-/* This changes position in a list. */
-/* returns true if position changes */
+/* This changes position in a list, or scrolls, or both.  */
+/* Returns true if display or position change.  */
-int ui_list_handler(list *foo, int key, int page_len)
+int ui_list_handler(list *foo, int key, int page_len, int h)
 {
-       int old_sel = foo->sel;
+       int tmp;
+
+       if (!page_len)
+               page_len = h - 2;       /* Use default.  */
+       if (page_len < 1)
+               page_len = 1;
 
        switch (key) {
        case KEY_DOWN:
+               if (foo->sel >= foo->num - 1)
+                       return 0;
                foo->sel++;
                break;
        case KEY_UP:
+               if (foo->sel <= 0)
+                       return 0;
                foo->sel--;
                break;
        case KEY_NPAGE:
-               foo->sel += page_len;
-               break;
+               tmp = foo->num - foo->start - h;
+               if (tmp <= 0)
+                       return 0;
+               if (page_len >= tmp)
+                       page_len = tmp;
+               foo->start += page_len;
+               if (foo->sel < foo->start)
+                       foo->sel = foo->start;
+               return 1;
        case KEY_PPAGE:
-               foo->sel -= page_len;
-               break;
+               if (page_len >= foo->start)
+                       page_len = foo->start;
+               if (!page_len)
+                       return 0;
+               foo->start -= page_len;
+               tmp = foo->start + h;
+               if (foo->sel >= tmp)
+                       foo->sel = tmp - 1;
+               return 1;
        case KEY_HOME:
+               if (foo->sel <= 0)
+                       return 0;
                foo->sel = 0;
                break;
        case KEY_END:
-               foo->sel = foo->num - 1;
+               tmp = foo->num - 1;
+               if (foo->sel >= tmp)
+                       return 0;
+               foo->sel = tmp;
                break;
        default:
-               break;
+               return 0;
        }
-       if (foo->sel < 0)
-               foo->sel = 0;
-       if (foo->sel >= foo->num)
-               foo->sel = foo->num - 1;
+       list_check_values(foo, h);
 
-       return foo->sel != old_sel;
+       return 1;
 }
 
 void ui_cursor_move(gint x, gint y)
--- src/ui_help.c.orig-0.6.2    2003-09-15 17:51:40 -0400
+++ src/ui_help.c       2005-01-01 13:51:57 -0500
@@ -45,7 +45,7 @@ const char helptext[] = N_("\
 Welcome to giFTcurs!\n\
 \n\
 Key list:\n\
-{%header:B}up{%prev}/{%header:B}down{%prev}        select item or scroll in a 
list\n\
+{%header:B}up{%prev}/{%header:B}down{%prev}        select item or traverse a 
list\n\
 {%header:B}PgUp{%prev}/{%header:B}PgDown{%prev}    scroll lists one screen at 
a time\n\
 {%header:B}tab{%prev}            move to the next input field\n\
 {%header:B}F1{%prev}             this help screen\n\
@@ -96,6 +96,8 @@ const char copyright[] = N_("\
 static void help_screen_resize(void);
 static void help_screen_update(void);
 
+#define HELP_HEIGHT (max_y - 3 - show_buttonbar)
+
 #ifdef MOUSE
 /* Mouse callback */
 static void mouse_helpclick(int rx, int ry, void *data);
@@ -137,14 +139,18 @@ static void help_screen_draw(void)
        draw_box(0, 0, max_x, max_y - 1 - show_buttonbar, _("Help"),
                         COLOR_PAIR(COLOR_HELP_BOX) | A_BOLD);
        mouse_clear(0);
-       mouse_register(0, 0, max_x, max_y - 1 - show_buttonbar, 
BUTTON1_PRESSED, mouse_helpclick, NULL,
-                                  0);
+       mouse_register(0, 0, max_x, max_y - 1 - show_buttonbar, BUTTON1_PRESSED,
+                      mouse_helpclick, GINT_TO_POINTER(2), 0);
+       mouse_register(0, 0, max_x, max_y, BUTTON_UP,
+                      mouse_helpclick, GINT_TO_POINTER(0), 0);
+       mouse_register(0, 0, max_x, max_y, BUTTON_DOWN,
+                      mouse_helpclick, GINT_TO_POINTER(1), 0);
        help_screen_update();
 }
 
 static void help_screen_update(void)
 {
-       int height = max_y - 3 - show_buttonbar;
+       int height = HELP_HEIGHT;
 
        if (max_x != build_width)
                help_screen_resize();
@@ -161,8 +167,10 @@ static int help_screen_handler(int key)
        int ret;
 
        help.sel = help.start;
-       ret = ui_list_handler(&help, key, max_y - 3 - show_buttonbar);
+       ret = ui_list_handler(&help, key, 0, HELP_HEIGHT);
-       help.start = help.sel;
+       /* ScrollLock-like behavior hack; not for real scroll keys.  */
+       if (key != KEY_PPAGE && key != KEY_NPAGE)
+               help.start = help.sel;
        help_screen_update();
 
        return ret;
@@ -171,13 +179,17 @@ static int help_screen_handler(int key)
 #ifdef MOUSE
 static void mouse_helpclick(int rx, int ry, void *data)
 {
+       int dir = GPOINTER_TO_INT(data);
+
        g_assert(active_screen == my_screen_number);
 
-       if (ry < max_y / 2)
-               help.start -= 3;
-       else
-               help.start += 3;
-       help_screen_update();
+       if (dir & 2)    /* BUTTON1_PRESSED */
+               dir = (ry >= max_y / 2);
+
+       if (ui_list_handler(&help,
+                           dir ? KEY_NPAGE : KEY_PPAGE,
+                           HELP_HEIGHT / 2, HELP_HEIGHT))
+               help_screen_update();
 }
 #endif
 
--- src/ui_main.c.orig-0.6.2    2003-11-22 07:21:15 -0500
+++ src/ui_main.c       2005-01-01 13:08:10 -0500
@@ -398,7 +398,7 @@ static int main_screen_handler(int key)
 
        case FIELD_SEARCH_TERM:
                if (!ui_input_handler(&search_input, key))
-                       if (ui_list_handler(&queries, key, 5)) {
+                       if (ui_list_handler(&queries, key, 5, 1)) {
                                q = list_selected(&queries);
 
                                ui_input_assign(&search_input, q->search_term);
@@ -418,8 +418,7 @@ static int main_screen_handler(int key)
                refresh();
                return 1;
        case FIELD_SEARCH_REALM:
-               if (ui_list_handler(&search_realm, key, 1)) {
-                       list_check_values(&search_realm, 1);
+               if (ui_list_handler(&search_realm, key, 1, 1)) {
                        ui_input_assign(&realm_input, 
list_selected(&search_realm));
                } else if (key == KEY_ENTER && search_input.str->len) {
                        active_field = FIELD_SEARCH_BUTTON;
@@ -483,7 +482,7 @@ static int main_screen_handler(int key)
 
                        incoming_search_item();
                        g_message(_("Sorting order changed to %s."), method);
-               } else if (ui_list_handler(tree_flat(q), key, RESULT_H)) {
+               } else if (ui_list_handler(tree_flat(q), key, 0, RESULT_H)) {
                        main_screen_update_results();
                } else if (key == 'j' || key == 'J' || key == 'k' || key == 
'K') {
                        if (key == 'j' || key == 'J')
@@ -937,15 +936,13 @@ static void mouse_wheel(int rx, int ry, 
        if (active_field != FIELD_RESULT_LIST)
                return;
 
-       if (dir)
-               tree_flat(q)->sel += (RESULT_H / 2);
-       else
-               tree_flat(q)->sel -= (RESULT_H / 2);
-
-       list_check_values(tree_flat(q), RESULT_H);
-       main_screen_update_results();
-       main_screen_update_info();
-       refresh();
+       if (ui_list_handler(tree_flat(q),
+                           dir ? KEY_NPAGE : KEY_PPAGE,
+                           (RESULT_H / 2), RESULT_H)) {
+               main_screen_update_results();
+               main_screen_update_info();
+               refresh();
+       }
 }
 #endif
 
--- src/ui_transfer.c.orig-0.6.2        2003-11-16 11:39:40 -0500
+++ src/ui_transfer.c   2005-01-01 13:01:31 -0500
@@ -349,7 +349,7 @@ static int transfer_screen_handler(int k
                        g_message(_("Transfer sorting order changed to %s."), 
method);
                return 1;
        default:
-               if (ui_list_handler(tree_flat(active_tree), key, height - 2)) {
+               if (ui_list_handler(tree_flat(active_tree), key, 0, height - 
3)) {
                        update_func();
                        refresh();
                        return 1;
@@ -535,14 +535,12 @@ static void mouse_wheel(int rx, int ry, 
                active_field = FIELD_UPLOADS;
        }
 
-       if (dir & ~2)
-               tree_flat(foo)->sel += (h / 2) - 1;
-       else
-               tree_flat(foo)->sel -= (h / 2) - 1;
-
-       list_check_values(tree_flat(foo), h - 1);
-       transfer_screen_draw();
-       refresh();
+       if (ui_list_handler(tree_flat(foo),
+                           (dir & ~2) ? KEY_NPAGE : KEY_PPAGE,
+                           (h / 2) - 1, h - 3)) {
+               transfer_screen_draw();
+               refresh();
+       }
 }
 #endif
 
--- src/ui_console.c.orig-0.6.2 2003-11-04 18:40:44 -0500
+++ src/ui_console.c    2005-01-01 13:31:39 -0500
@@ -103,7 +103,11 @@ static void console_screen_draw(void)
                         COLOR_PAIR(COLOR_CONSOLE_BOX) | A_BOLD);
        mouse_clear(0);
        mouse_register(0, 0, max_x, max_y - 1 - show_buttonbar, BUTTON1_PRESSED,
-                                  mouse_consoleclick, NULL, 0);
+                                  mouse_consoleclick, GINT_TO_POINTER(2), 0);
+       mouse_register(0, 0, max_x, max_y, BUTTON_UP,
+                                  mouse_consoleclick, GINT_TO_POINTER(0), 0);
+       mouse_register(0, 0, max_x, max_y, BUTTON_DOWN,
+                                  mouse_consoleclick, GINT_TO_POINTER(1), 0);
        console_screen_update();
 }
 
@@ -137,8 +141,10 @@ static void console_screen_update(void)
                break;
        default:
                messages.sel = messages.start;
-               ret = ui_list_handler(&messages, key, max_y - 3 - 
show_buttonbar);
-               messages.start = messages.sel;
+               ret = ui_list_handler(&messages, key, 0, max_y - 3 - 
show_buttonbar);
+               /* ScrollLock-like behavior hack; not for real scroll keys.  */
+               if (key != KEY_PPAGE && key != KEY_NPAGE)
+                       messages.start = messages.sel;
                console_screen_update();
                break;
        }
@@ -192,13 +198,17 @@ static void console_screen_loghook(GLogL
 #ifdef MOUSE
 static void mouse_consoleclick(int rx, int ry, void *data)
 {
+       int dir = GPOINTER_TO_INT(data);
+
        g_assert(active_screen == my_screen_nr);
 
-       if (ry < max_y / 2)
-               messages.start -= CONSOLE_HEIGHT / 2;
-       else
-               messages.start += CONSOLE_HEIGHT / 2;
-       console_screen_update();
+       if (dir & 2)    /* BUTTON1_PRESSED */
+               dir = (ry >= max_y / 2);
+
+       if (ui_list_handler(&messages,
+                           dir ? KEY_NPAGE : KEY_PPAGE,
+                           CONSOLE_HEIGHT / 2, CONSOLE_HEIGHT))
+               console_screen_update();
 }
 #endif
 
--- src/ui_settings.c.orig-0.6.2        2003-06-30 04:10:57 -0400
+++ src/ui_settings.c   2004-12-31 21:02:37 -0500
@@ -121,14 +121,14 @@ static int settings_screen_handler(int k
 
        switch (active_field) {
        case FIELD_COLOR_ITEM:
-               if (ui_list_handler(&items, key, LIST_H)) {
+               if (ui_list_handler(&items, key, 0, LIST_H)) {
                        settings_screen_update();
                        refresh();
                        return 1;
                }
                break;
        case FIELD_COLOR_FG:
-               if (ui_list_handler(&fgcolors, key, LIST_H)) {
+               if (ui_list_handler(&fgcolors, key, 0, LIST_H)) {
                        init_pair(items.sel + 1, fgcolors.sel, bgcolors.sel);
                        ui_draw();
                        refresh();
@@ -136,7 +136,7 @@ static int settings_screen_handler(int k
                }
                break;
        case FIELD_COLOR_BG:
-               if (ui_list_handler(&bgcolors, key, LIST_H)) {
+               if (ui_list_handler(&bgcolors, key, 0, LIST_H)) {
                        init_pair(items.sel + 1, fgcolors.sel, bgcolors.sel);
                        ui_draw();
                        refresh();




reply via email to

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