]> git.deb.at Git - pkg/abook.git/blobdiff - list.c
Upload 0.6.1-2 to unstable
[pkg/abook.git] / list.c
diff --git a/list.c b/list.c
index 9b39b7e9f03b1bc4d8ff9033c9e8e5ebbac32852..1f0af7942c8fa4515c57ebaeacaec3a37cbed883 100644 (file)
--- a/list.c
+++ b/list.c
 #include "misc.h"
 #include "options.h"
 #include "xmalloc.h"
+#include "color.h"
 
 
 int curitem = -1;
 int first_list_item = -1;
+int scroll_speed = 2;
 char *selected = NULL;
 
 extern abook_field_list *fields_list;
@@ -129,6 +131,7 @@ init_list()
 {
        list = newwin(LIST_LINES, LIST_COLS, LIST_TOP, 0);
        scrollok(list, TRUE);
+       scroll_speed = abs(opt_get_int(INT_SCROLL_SPEED));
 }
 
 void
@@ -180,7 +183,7 @@ print_list_field(int item, int line, int *x_pos, struct index_elem *e)
        width = len ? bytes2width(s, len) : strwidth(s);
        x_start = *x_pos + ((e->d.field.len < 0) ? len - width : 0);
        if(width + x_start >= COLS)
-               width = COLS - x_start;
+               width = bytes2width(s, COLS - x_start);
 
        if(width)
                mvwaddnstr(list, line, x_start, s, width);
@@ -191,12 +194,46 @@ print_list_field(int item, int line, int *x_pos, struct index_elem *e)
        *x_pos += len ? len : width;
 }
 
+static void
+highlight_line(WINDOW *win, int line)
+{
+       wattrset(win, COLOR_PAIR(CP_LIST_HIGHLIGHT));
+       if(!opt_get_bool(BOOL_USE_COLORS)) {
+               wstandout(win);
+       }
+
+       /*
+        * this is a tricky one
+        */
+#if 0
+/*#ifdef mvwchgat*/
+       mvwchgat(win, line, 0, -1,  A_STANDOUT, 0, NULL);
+#else
+       /*
+        * buggy function: FIXME
+        */
+       scrollok(win, FALSE);
+       {
+               int i;
+               wmove(win, line, 0);
+               for(i = 0; i < COLS; i++)
+                       waddch(win, ' ');
+       /*wattrset(win, 0);*/
+       }
+       scrollok(win, TRUE);
+#endif
+}
+
 static void
 print_list_line(int item, int line, int highlight)
 {
        struct index_elem *cur;
        int x_pos = 1;
 
+       if(item % 2 == 0)
+               wattrset(list, COLOR_PAIR(CP_LIST_EVEN));
+       else
+               wattrset(list, COLOR_PAIR(CP_LIST_ODD));
        scrollok(list, FALSE);
        if(highlight)
                highlight_line(list, line);
@@ -273,13 +310,18 @@ list_headerline()
 #if defined(A_BOLD) && defined(A_NORMAL)
        attrset(A_BOLD);
 #endif
+       attrset(COLOR_PAIR(CP_LIST_HEADER));
+       mvhline(2, 0, ' ', COLS);
 
        for(e = index_elements; e; e = e->next)
                if(e->type == INDEX_TEXT)
                        x_pos += strwidth(e->d.text);
                else if(e->type == INDEX_FIELD) {
                        get_field_info(e->d.field.id, NULL, &str, NULL);
-                       width = e->d.field.len ? abs(e->d.field.len) : strwidth(str);
+                       width = e->d.field.len ?
+                               abs(e->d.field.len) : strwidth(str);
+                       if(width + x_pos > COLS)
+                               width = bytes2width(str, COLS - x_pos);
                        mvaddnstr(2, x_pos, str, width);
                        x_pos += width;
                } else
@@ -312,6 +354,49 @@ scroll_down()
        refresh_list();
 }
 
+void
+scroll_list_up()
+{
+       if(first_list_item <= 0) {
+               if(curitem != 0) {
+                       curitem--;
+                       refresh_list();
+               }
+               return;
+       }
+
+       first_list_item -= scroll_speed;
+       if(first_list_item < 0) {
+               first_list_item = 0;
+       }
+       if(curitem > LAST_LIST_ITEM) {
+               curitem = LAST_LIST_ITEM;
+       }
+
+       refresh_list();
+}
+
+void
+scroll_list_down()
+{
+       if(LAST_LIST_ITEM > db_n_items() - 2) {
+               if(curitem < LAST_LIST_ITEM) {
+                       curitem++;
+                       refresh_list();
+               }
+               return;
+       }
+
+       first_list_item += scroll_speed;
+       if(LAST_LIST_ITEM > db_n_items() - 1) {
+               first_list_item = db_n_items() - LIST_LINES;
+       }
+       if(curitem < first_list_item) {
+               curitem = first_list_item;
+       }
+
+       refresh_list();
+}
 
 void
 page_up()
@@ -422,33 +507,6 @@ goto_end()
        refresh_list();
 }
 
-static void
-highlight_line(WINDOW *win, int line)
-{
-       wstandout(win);
-
-       /*
-        * this is a tricky one
-        */
-#if 0
-/*#ifdef mvwchgat*/
-       mvwchgat(win, line, 0, -1,  A_STANDOUT, 0, NULL);
-#else
-       /*
-        * buggy function: FIXME
-        */
-       scrollok(win, FALSE);
-       {
-               int i;
-               wmove(win, line, 0);
-               for(i = 0; i < COLS; i++)
-                       waddch(win, ' ');
-       /*wattrset(win, 0);*/
-       }
-       scrollok(win, TRUE);
-#endif
-}
-
 int
 selected_items()
 {
@@ -485,6 +543,12 @@ list_get_curitem()
        return curitem;
 }
 
+int
+list_get_firstitem()
+{
+       return first_list_item;
+}
+
 void
 list_set_curitem(int i)
 {