Code

charset: renamed my_strlen() to utf8_width()
[ncmpc.git] / src / list_window.c
index 215a531dd4907a8bcba373c084db1c7706182f55..93bed86667db070332e3da3bb344dca1b28fa57e 100644 (file)
@@ -21,6 +21,7 @@
 #include "list_window.h"
 #include "config.h"
 #include "options.h"
+#include "charset.h"
 #include "support.h"
 #include "command.h"
 #include "colors.h"
@@ -41,7 +42,6 @@ list_window_init(WINDOW *w, unsigned width, unsigned height)
        lw->w = w;
        lw->cols = width;
        lw->rows = height;
-       lw->clear = 1;
        return lw;
 }
 
@@ -60,7 +60,6 @@ list_window_reset(struct list_window *lw)
        lw->selected = 0;
        lw->xoffset = 0;
        lw->start = 0;
-       lw->clear = 1;
 }
 
 void
@@ -94,8 +93,6 @@ list_window_center(struct list_window *lw, unsigned rows, unsigned n)
                else
                        lw->start = 0;
        }
-
-       lw->repaint = lw->clear = 1;
 }
 
 void
@@ -104,7 +101,7 @@ list_window_set_selected(struct list_window *lw, unsigned n)
        lw->selected = n;
 }
 
-void
+static void
 list_window_next(struct list_window *lw, unsigned length)
 {
        if (lw->selected + 1 < length)
@@ -113,7 +110,7 @@ list_window_next(struct list_window *lw, unsigned length)
                lw->selected = 0;
 }
 
-void
+static void
 list_window_previous(struct list_window *lw, unsigned length)
 {
        if (lw->selected > 0)
@@ -122,14 +119,14 @@ list_window_previous(struct list_window *lw, unsigned length)
                lw->selected = length - 1;
 }
 
-void
+static void
 list_window_first(struct list_window *lw)
 {
        lw->xoffset = 0;
        lw->selected = 0;
 }
 
-void
+static void
 list_window_last(struct list_window *lw, unsigned length)
 {
        lw->xoffset = 0;
@@ -139,7 +136,7 @@ list_window_last(struct list_window *lw, unsigned length)
                lw->selected = 0;
 }
 
-void
+static void
 list_window_next_page(struct list_window *lw, unsigned length)
 {
        if (lw->rows < 2)
@@ -150,7 +147,7 @@ list_window_next_page(struct list_window *lw, unsigned length)
                list_window_last(lw, length);
 }
 
-void
+static void
 list_window_previous_page(struct list_window *lw)
 {
        if (lw->rows < 2)
@@ -172,15 +169,11 @@ list_window_paint(struct list_window *lw,
        int show_cursor = !(lw->flags & LW_HIDE_CURSOR);
 
        if (show_cursor) {
-               if (lw->selected < lw->start) {
+               if (lw->selected < lw->start)
                        lw->start = lw->selected;
-                       lw->clear=1;
-               }
 
-               if (lw->selected >= lw->start + lw->rows) {
+               if (lw->selected >= lw->start + lw->rows)
                        lw->start = lw->selected - lw->rows + 1;
-                       lw->clear=1;
-               }
        }
 
        for (i = 0; i < lw->rows; i++) {
@@ -189,32 +182,32 @@ list_window_paint(struct list_window *lw,
 
                label = callback(lw->start + i, &highlight, callback_data);
                wmove(lw->w, i, 0);
-               if( lw->clear && (!fill || !label) )
-                       wclrtoeol(lw->w);
 
                if (label) {
                        int selected = lw->start + i == lw->selected;
-                       size_t len = my_strlen(label);
+                       unsigned len = utf8_width(label);
 
-                       if( highlight )
+                       if (highlight)
                                colors_use(lw->w, COLOR_LIST_BOLD);
                        else
                                colors_use(lw->w, COLOR_LIST);
 
-                       if( show_cursor && selected )
+                       if (show_cursor && selected)
                                wattron(lw->w, A_REVERSE);
 
                        //waddnstr(lw->w, label, lw->cols);
                        waddstr(lw->w, label);
-                       if( fill && len<lw->cols )
+                       if (fill && len < lw->cols)
                                whline(lw->w,  ' ', lw->cols-len);
 
-                       if( selected )
+                       if (selected)
                                wattroff(lw->w, A_REVERSE);
-               }
-       }
 
-       lw->clear=0;
+                       if (!fill && len < lw->cols)
+                               wclrtoeol(lw->w);
+               } else
+                       wclrtoeol(lw->w);
+       }
 }
 
 int
@@ -309,7 +302,6 @@ list_window_cmd(struct list_window *lw, unsigned rows, command_t cmd)
                return 0;
        }
 
-       lw->repaint  = 1;
        return 1;
 }
 
@@ -359,7 +351,6 @@ list_window_scroll_cmd(struct list_window *lw, unsigned rows, command_t cmd)
                return 0;
        }
 
-       lw->repaint = lw->clear = 1;
        return 1;
 }