Code

list_window: added callback function for row painting
authorMax Kellermann <max@duempel.org>
Sun, 11 Oct 2009 12:53:28 +0000 (14:53 +0200)
committerMax Kellermann <max@duempel.org>
Sun, 11 Oct 2009 12:53:28 +0000 (14:53 +0200)
With the function list_window_paint2(), callers can customize how a
row is painted.  The usual callback function is not used anymore.

src/list_window.c
src/list_window.h
src/screen_artist.c
src/screen_browser.c
src/screen_find.c
src/screen_find.h
src/screen_play.c

index 0b6031483e8854fc86bc410070fe9089bd45d540..f8ab8e9a708ccd0d996c26443d7a7f126f64ecdc 100644 (file)
@@ -408,6 +408,46 @@ 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 (selected)
+                       wattroff(lw->w, A_REVERSE);
+       }
+
+       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,
index 98fcfbef7fc44327cd7ab07f704f51154b2b5d06..8ffe40f9bd5ca0cf79d11b3a82c11b16e51f0744 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "config.h"
 #include "command.h"
+#include "colors.h"
 
 #include <glib.h>
 #include <stdbool.h>
@@ -37,6 +38,12 @@ typedef const char *(*list_window_callback_fn_t)(unsigned index,
                                                 char **second_column,
                                                 void *data);
 
+typedef void
+(*list_window_paint_callback_t)(WINDOW *w, unsigned i,
+                               unsigned y, unsigned width,
+                               bool selected,
+                               void *data);
+
 struct list_window {
        WINDOW *w;
        unsigned rows, cols;
@@ -91,6 +98,11 @@ void list_window_paint(const struct list_window *lw,
                       list_window_callback_fn_t callback,
                       void *callback_data);
 
+void
+list_window_paint2(const struct list_window *lw,
+                  list_window_paint_callback_t paint_callback,
+                  void *callback_data);
+
 /* perform basic list window commands (movement) */
 bool
 list_window_cmd(struct list_window *lw, command_t cmd);
index 116f4b64cf8fd164f6f788e40948c1b77227576d..847bed045286f3a73c3dc3d0d193ded91751a6f5 100644 (file)
@@ -674,13 +674,13 @@ screen_artist_cmd(struct mpdclient *c, command_t cmd)
                switch (mode) {
                case LIST_ARTISTS:
                        screen_jump(browser.lw, screen_artist_lw_callback,
-                                   artist_list);
+                                   NULL, artist_list);
                        artist_repaint();
                        return true;
 
                case LIST_ALBUMS:
                        screen_jump(browser.lw, screen_artist_lw_callback,
-                                   album_list);
+                                   NULL, album_list);
                        artist_repaint();
                        return true;
 
index 994ea2dd5f61150ec95bcd758785897fc86d14e7..3b0fc00ccf2a5610880c06cde0ece8e8e93f4649 100644 (file)
@@ -405,7 +405,8 @@ browser_cmd(struct screen_browser *browser,
                            browser->filelist);
                return true;
        case CMD_LIST_JUMP:
-               screen_jump(browser->lw, browser_lw_callback, browser->filelist);
+               screen_jump(browser->lw, browser_lw_callback,
+                           NULL, browser->filelist);
                return true;
 
 #ifdef HAVE_GETMOUSE
index 79115edfa07f92573bc03b3eec6aa05b70612b0e..531fe499d62072df4297f757ac8e32d8c7b1ef38 100644 (file)
@@ -93,6 +93,7 @@ screen_find(struct list_window *lw, command_t findcmd,
 void
 screen_jump(struct list_window *lw,
                list_window_callback_fn_t callback_fn,
+           list_window_paint_callback_t paint_callback,
                void *callback_data)
 {
        char *search_str, *iter;
@@ -130,8 +131,12 @@ screen_jump(struct list_window *lw,
                                ++iter;
                }
                list_window_jump(lw, callback_fn, callback_data, search_str);
+
                /* repaint the list_window */
-               list_window_paint(lw, callback_fn, callback_data);
+               if (paint_callback != NULL)
+                       list_window_paint2(lw, paint_callback, callback_data);
+               else
+                       list_window_paint(lw, callback_fn, callback_data);
                wrefresh(lw->w);
        }
 
index 7753e228b87ffbe6dfbc85bec1dd9f831584f666..780aff1e631f80f881454b207dddaac792362d4d 100644 (file)
@@ -33,6 +33,7 @@ int screen_find(struct list_window *lw,
  * which begins with this string while the users types */
 void screen_jump(struct list_window *lw,
                list_window_callback_fn_t callback_fn,
+                list_window_paint_callback_t paint_callback,
                void *callback_data);
 
 #endif
index d1261c66ee418d7210c76c06cdead50b9dafe50c..882dd7a9e46b5f87df4e00624bfbd25f4f716d63 100644 (file)
@@ -662,7 +662,7 @@ screen_playlist_cmd(struct mpdclient *c, command_t cmd)
                playlist_repaint();
                return true;
        case CMD_LIST_JUMP:
-               screen_jump(lw, list_callback, NULL);
+               screen_jump(lw, list_callback, NULL, NULL);
                playlist_save_selection();
                playlist_repaint();
                return true;