X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Flist_window.c;h=9d120c14e24eb97d2ce17994364cc830cfe78409;hb=502d803a2efc9f7de5560f86829e33bf78e47584;hp=9e67f9f87a61b1bd257271d98e327794ba2e3250;hpb=74c1180360f39199b76b72e7d266372a52ddbbb3;p=ncmpc.git diff --git a/src/list_window.c b/src/list_window.c index 9e67f9f..9d120c1 100644 --- a/src/list_window.c +++ b/src/list_window.c @@ -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 @@ -24,6 +24,7 @@ #include "match.h" #include "command.h" #include "colors.h" +#include "paint.h" #include "screen_message.h" #include "i18n.h" @@ -126,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); @@ -321,58 +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 text_width = utf8_width(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; - - if (highlight) - colors_use(w, COLOR_LIST_BOLD); - else - colors_use(w, COLOR_LIST); - - if (selected) - wattron(w, A_REVERSE); - - waddstr(w, text); - if (options.wide_cursor && text_width < width) - whline(w, ' ', width - text_width); - - if (second_column_width > 0) { - wmove(w, y, width); - waddch(w, ' '); - waddstr(w, second_column); - } - - if (selected) - wattroff(w, A_REVERSE); - - if (!options.wide_cursor && text_width < width) { - if (second_column_width == 0) - /* the cursor is at the end of the text; clear - the rest of this row */ - wclrtoeol(w); - else - /* there's a second column: clear the space - between the first and the second column */ - mvwhline(w, y, text_width, ' ', width - text_width); - } + row_paint_text(w, width, COLOR_LIST, + selected, text); } void @@ -380,18 +337,15 @@ list_window_paint(const struct list_window *lw, list_window_callback_fn_t callback, void *callback_data) { - bool show_cursor = !lw->hide_cursor; - struct list_window_range range; - - show_cursor = show_cursor && + bool show_cursor = !lw->hide_cursor && (!options.hardware_cursor || lw->range_selection); + struct list_window_range range; - list_window_get_range(lw, &range); + if (show_cursor) + list_window_get_range(lw, &range); for (unsigned i = 0; i < lw->rows; i++) { const char *label; - bool highlight = false; - char *second_column = NULL; wmove(lw->w, i, 0); @@ -400,23 +354,53 @@ 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); + label); + } - if (second_column != NULL) - g_free(second_column); + row_color_end(lw->w); + + 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); + } +} + +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 && @@ -434,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; @@ -442,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)) { @@ -474,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; @@ -485,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)) { @@ -507,48 +489,60 @@ list_window_rfind(struct list_window *lw, return false; } -static bool -jump_match(const char *haystack, const char *needle) -{ #ifdef NCMPC_MINI - bool jump_prefix_only = true; -#else - bool jump_prefix_only = options.jump_prefix_only; -#endif +bool +list_window_jump(struct list_window *lw, + list_window_callback_fn_t callback, + void *callback_data, + const char *str) +{ + unsigned i; + const char *label; - assert(haystack != NULL); - assert(needle != NULL); + assert(str != NULL); - return jump_prefix_only - ? g_ascii_strncasecmp(haystack, needle, strlen(needle)) == 0 - : match_line(haystack, needle); -} + for (i = 0; i < lw->length; i++) { + label = callback(i, callback_data); + assert(label != NULL); + if (g_ascii_strncasecmp(label, str, strlen(str)) == 0) { + list_window_move_cursor(lw, i); + return true; + } + } + return false; +} +#else bool list_window_jump(struct list_window *lw, list_window_callback_fn_t callback, void *callback_data, const char *str) { - bool h; + unsigned i; const char *label; + GRegex *regex; assert(str != NULL); - for (unsigned i = 0; i < lw->length; ++i) { - label = callback(i, &h, NULL, callback_data); - assert(label != NULL); + regex = compile_regex(str, options.jump_prefix_only); + if (regex == NULL) + return false; - if (label[0] == '[') - label++; + for (i = 0; i < lw->length; i++) { + label = callback(i, callback_data); + assert(label != NULL); - if (jump_match(label, str)) { + if (match_regex(regex, label)) { + g_regex_unref(regex); list_window_move_cursor(lw, i); return true; } } + g_regex_unref(regex); return false; } +#endif /* perform basic list window commands (movement) */ bool