From: Max Kellermann Date: Sun, 11 Oct 2009 12:53:28 +0000 (+0200) Subject: list_window: added callback function for row painting X-Git-Tag: release-0.16~118 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=965afb83b0d1e2b9a3df90a9c5010b9af1756af1;p=ncmpc.git list_window: added callback function for row painting With the function list_window_paint2(), callers can customize how a row is painted. The usual callback function is not used anymore. --- diff --git a/src/list_window.c b/src/list_window.c index 0b60314..f8ab8e9 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -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, diff --git a/src/list_window.h b/src/list_window.h index 98fcfbe..8ffe40f 100644 --- a/src/list_window.h +++ b/src/list_window.h @@ -22,6 +22,7 @@ #include "config.h" #include "command.h" +#include "colors.h" #include #include @@ -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); diff --git a/src/screen_artist.c b/src/screen_artist.c index 116f4b6..847bed0 100644 --- a/src/screen_artist.c +++ b/src/screen_artist.c @@ -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; diff --git a/src/screen_browser.c b/src/screen_browser.c index 994ea2d..3b0fc00 100644 --- a/src/screen_browser.c +++ b/src/screen_browser.c @@ -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 diff --git a/src/screen_find.c b/src/screen_find.c index 79115ed..531fe49 100644 --- a/src/screen_find.c +++ b/src/screen_find.c @@ -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); } diff --git a/src/screen_find.h b/src/screen_find.h index 7753e22..780aff1 100644 --- a/src/screen_find.h +++ b/src/screen_find.h @@ -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 diff --git a/src/screen_play.c b/src/screen_play.c index d1261c6..882dd7a 100644 --- a/src/screen_play.c +++ b/src/screen_play.c @@ -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;