Code

ncmpc version 0.16.1
[ncmpc.git] / src / list_window.c
index 0b6031483e8854fc86bc410070fe9089bd45d540..d44fd29329b427965abedef04a113f3445187015 100644 (file)
@@ -1,5 +1,5 @@
 /* ncmpc (Ncurses MPD Client)
- * (c) 2004-2009 The Music Player Daemon Project
+ * (c) 2004-2010 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
 
  * This program is free software; you can redistribute it and/or modify
@@ -127,6 +127,9 @@ list_window_resize(struct list_window *lw, unsigned width, unsigned height)
 void
 list_window_set_length(struct list_window *lw, unsigned length)
 {
+       if (length == lw->length)
+               return;
+
        lw->length = length;
 
        list_window_check_selected(lw);
@@ -322,38 +325,11 @@ list_window_scroll_down(struct list_window *lw, unsigned n)
 }
 
 static void
-list_window_paint_row(WINDOW *w, unsigned y, unsigned width,
-                     bool selected, bool highlight,
-                     const char *text, const char *second_column)
+list_window_paint_row(WINDOW *w, unsigned width, bool selected,
+                     const char *text)
 {
-       unsigned second_column_width;
-
-#ifdef NCMPC_MINI
-       second_column = NULL;
-       highlight = false;
-#endif /* NCMPC_MINI */
-
-       if (second_column != NULL) {
-               second_column_width = utf8_width(second_column) + 1;
-               if (second_column_width < width)
-                       width -= second_column_width;
-               else
-                       second_column_width = 0;
-       } else
-               second_column_width = 0;
-
-       row_color(w, highlight ? COLOR_LIST_BOLD : COLOR_LIST, selected);
-
-       waddstr(w, text);
-
-       /* erase the unused space after the text */
-       row_clear_to_eol(w, width, selected);
-
-       if (second_column_width > 0) {
-               wmove(w, y, width);
-               waddch(w, ' ');
-               waddstr(w, second_column);
-       }
+       row_paint_text(w, width, COLOR_LIST,
+                      selected, text);
 }
 
 void
@@ -370,8 +346,6 @@ list_window_paint(const struct list_window *lw,
 
        for (unsigned i = 0; i < lw->rows; i++) {
                const char *label;
-               bool highlight = false;
-               char *second_column = NULL;
 
                wmove(lw->w, i, 0);
 
@@ -380,23 +354,14 @@ list_window_paint(const struct list_window *lw,
                        break;
                }
 
-               label = callback(lw->start + i, &highlight, &second_column, callback_data);
+               label = callback(lw->start + i, callback_data);
                assert(label != NULL);
 
-#ifdef NCMPC_MINI
-               highlight = false;
-               second_column = NULL;
-#endif /* NCMPC_MINI */
-
-               list_window_paint_row(lw->w, i, lw->cols,
+               list_window_paint_row(lw->w, lw->cols,
                                      show_cursor &&
                                      lw->start + i >= range.start &&
                                      lw->start + i < range.end,
-                                     highlight,
-                                     label, second_column);
-
-               if (second_column != NULL)
-                       g_free(second_column);
+                                     label);
        }
 
        row_color_end(lw->w);
@@ -408,6 +373,43 @@ list_window_paint(const struct list_window *lw,
        }
 }
 
+void
+list_window_paint2(const struct list_window *lw,
+                  list_window_paint_callback_t paint_callback,
+                  void *callback_data)
+{
+       bool show_cursor = !lw->hide_cursor &&
+               (!options.hardware_cursor || lw->range_selection);
+       struct list_window_range range;
+
+       if (show_cursor)
+               list_window_get_range(lw, &range);
+
+       for (unsigned i = 0; i < lw->rows; i++) {
+               bool selected;
+
+               wmove(lw->w, i, 0);
+
+               if (lw->start + i >= lw->length) {
+                       wclrtobot(lw->w);
+                       break;
+               }
+
+               selected = show_cursor &&
+                       lw->start + i >= range.start &&
+                       lw->start + i < range.end;
+
+               paint_callback(lw->w, lw->start + i, i, lw->cols,
+                              selected, callback_data);
+       }
+
+       if (options.hardware_cursor && lw->selected >= lw->start &&
+           lw->selected < lw->start + lw->rows) {
+               curs_set(1);
+               wmove(lw->w, lw->selected - lw->start, 0);
+       }
+}
+
 bool
 list_window_find(struct list_window *lw,
                 list_window_callback_fn_t callback,
@@ -416,7 +418,6 @@ list_window_find(struct list_window *lw,
                 bool wrap,
                 bool bell_on_wrap)
 {
-       bool h;
        unsigned i = lw->selected + 1;
        const char *label;
 
@@ -424,7 +425,7 @@ list_window_find(struct list_window *lw,
 
        do {
                while (i < lw->length) {
-                       label = callback(i, &h, NULL, callback_data);
+                       label = callback(i, callback_data);
                        assert(label != NULL);
 
                        if (match_line(label, str)) {
@@ -456,7 +457,6 @@ list_window_rfind(struct list_window *lw,
                  bool wrap,
                  bool bell_on_wrap)
 {
-       bool h;
        int i = lw->selected - 1;
        const char *label;
 
@@ -467,7 +467,7 @@ list_window_rfind(struct list_window *lw,
 
        do {
                while (i >= 0) {
-                       label = callback(i, &h, NULL, callback_data);
+                       label = callback(i, callback_data);
                        assert(label != NULL);
 
                        if (match_line(label, str)) {
@@ -512,18 +512,14 @@ list_window_jump(struct list_window *lw,
                 void *callback_data,
                 const char *str)
 {
-       bool h;
        const char *label;
 
        assert(str != NULL);
 
        for (unsigned i = 0; i < lw->length; ++i) {
-               label = callback(i, &h, NULL, callback_data);
+               label = callback(i, callback_data);
                assert(label != NULL);
 
-               if (label[0] == '[')
-                       label++;
-
                if (jump_match(label, str)) {
                        list_window_move_cursor(lw, i);
                        return true;