diff options
-rw-r--r-- | callbacks.c | 8 | ||||
-rw-r--r-- | gtkplaylist.c | 109 | ||||
-rw-r--r-- | gtkplaylist.h | 3 | ||||
-rw-r--r-- | search.c | 10 | ||||
-rw-r--r-- | search.h | 4 |
5 files changed, 78 insertions, 56 deletions
diff --git a/callbacks.c b/callbacks.c index aff07974..76cb1d3f 100644 --- a/callbacks.c +++ b/callbacks.c @@ -65,9 +65,8 @@ main_playlist_init (GtkWidget *widget) { main_playlist.scrollbar = lookup_widget (mainwin, "playscroll"); main_playlist.pcurr = &playlist_current_ptr; main_playlist.count = &ps_count; - main_playlist.update_statusbar = 1; - main_playlist.has_dragndrop = 1; - search_playlist.iterator = PS_MAIN; + main_playlist.iterator = PS_MAIN; + main_playlist.multisel = 1; main_playlist.scrollpos = 0; main_playlist.row = -1; main_playlist.clicktime = -1; @@ -96,8 +95,7 @@ search_playlist_init (GtkWidget *widget) { assert (search_playlist.scrollbar); // main_playlist.pcurr = &search_current; search_playlist.count = &search_count; - search_playlist.update_statusbar = 0; - search_playlist.has_dragndrop = 0; + search_playlist.multisel = 0; search_playlist.iterator = PS_SEARCH; search_playlist.scrollpos = 0; search_playlist.row = -1; diff --git a/gtkplaylist.c b/gtkplaylist.c index dac2e6aa..09ec386d 100644 --- a/gtkplaylist.c +++ b/gtkplaylist.c @@ -191,7 +191,7 @@ gtkps_draw_ps_row_back (gtkplaylist_t *ps, cairo_t *cr, int row, playItem_t *it) int width, height; gdk_drawable_get_size (ps->backbuf, &width, &height); w = width; - if (it && it->selected) { + if (it && ((it->selected && ps->multisel) || (row == ps->row && !ps->multisel))) { if (row % 2) { cairo_set_source_rgb (cr, 0xa7/255.f, 0x9f/255.f, 0x96/255.f); } @@ -228,12 +228,12 @@ gtkps_draw_ps_row (gtkplaylist_t *ps, cairo_t *cr, int row, playItem_t *it) { } int width, height; gdk_drawable_get_size (ps->backbuf, &width, &height); - if (it == playlist_current_ptr) { + if (it == playlist_current_ptr && ps->colwidths[0] > 0) { cairo_set_source_rgb (cr, 1, 1, 1); cairo_rectangle (cr, 3, row * rowheight - ps->scrollpos * rowheight + 3, rowheight-6, rowheight-6); cairo_fill (cr); } - if (it && it->selected) { + if (it && ((it->selected && ps->multisel) || (row == ps->row && !ps->multisel))) { cairo_set_source_rgb (cr, 0, 0, 0); } else { @@ -383,6 +383,9 @@ gtkps_expose (gtkplaylist_t *ps, int x, int y, int w, int h) { void gtkps_select_single (gtkplaylist_t *ps, int sel) { + if (!ps->multisel) { + return; + } int idx=0; GtkWidget *widget = ps->playlist; for (playItem_t *it = playlist_head[ps->iterator]; it; it = it->next[ps->iterator], idx++) { @@ -465,63 +468,70 @@ gtkps_mouse1_pressed (gtkplaylist_t *ps, int state, int ex, int ey, double time) int prev = ps->row; ps->row = y; shift_sel_anchor = ps->row; - // handle selection - if (!(state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK))) - { - playItem_t *it = gtkps_get_for_idx (ps, sel); - if (!it || !it->selected) { - // reset selection, and set it to single item - gtkps_select_single (ps, sel); - areaselect = 1; - areaselect_x = ex; - areaselect_y = ey; - areaselect_dx = -1; - areaselect_dy = -1; - shift_sel_anchor = ps->row; - } - else { - dragwait = 1; - gtkps_redraw_ps_row (ps, prev); - gtkps_redraw_ps_row (ps, ps->row); - } - } - else if (state & GDK_CONTROL_MASK) { - // toggle selection - if (y != -1) { - playItem_t *it = gtkps_get_for_idx (ps, y); - if (it) { - it->selected = 1 - it->selected; - gtkps_redraw_ps_row (ps, y); + // handle multiple selection + if (ps->multisel) { + if (!(state & (GDK_CONTROL_MASK|GDK_SHIFT_MASK))) + { + playItem_t *it = gtkps_get_for_idx (ps, sel); + if (!it || !it->selected) { + // reset selection, and set it to single item + gtkps_select_single (ps, sel); + areaselect = 1; + areaselect_x = ex; + areaselect_y = ey; + areaselect_dx = -1; + areaselect_dy = -1; + shift_sel_anchor = ps->row; + } + else { + dragwait = 1; + gtkps_redraw_ps_row (ps, prev); + gtkps_redraw_ps_row (ps, ps->row); } } - } - else if (state & GDK_SHIFT_MASK) { - // select range - int start = min (prev, ps->row); - int end = max (prev, ps->row); - int idx = 0; - for (playItem_t *it = playlist_head[ps->iterator]; it; it = it->next[ps->iterator], idx++) { - if (idx >= start && idx <= end) { - if (!it->selected) { - it->selected = 1; - gtkps_redraw_ps_row (ps, idx); + else if (state & GDK_CONTROL_MASK) { + // toggle selection + if (y != -1) { + playItem_t *it = gtkps_get_for_idx (ps, y); + if (it) { + it->selected = 1 - it->selected; + gtkps_redraw_ps_row (ps, y); } } - else { - if (it->selected) { - it->selected = 0; - gtkps_redraw_ps_row (ps, idx); + } + else if (state & GDK_SHIFT_MASK) { + // select range + int start = min (prev, ps->row); + int end = max (prev, ps->row); + int idx = 0; + for (playItem_t *it = playlist_head[ps->iterator]; it; it = it->next[ps->iterator], idx++) { + if (idx >= start && idx <= end) { + if (!it->selected) { + it->selected = 1; + gtkps_redraw_ps_row (ps, idx); + } + } + else { + if (it->selected) { + it->selected = 0; + gtkps_redraw_ps_row (ps, idx); + } } } } + if (ps->row != -1 && sel == -1) { + gtkps_redraw_ps_row (ps, ps->row); + } + } + else { + if (ps->row != -1) { + gtkps_redraw_ps_row (ps, ps->row); + } } - if (prev != -1 && prev != ps->row) { gtkps_redraw_ps_row (ps, prev); } - if (ps->row != -1 && sel == -1) { - gtkps_redraw_ps_row (ps, ps->row); - } + } void @@ -773,6 +783,7 @@ gtkps_keypress (gtkplaylist_t *ps, int keyval, int state) { gtkps_setup_scrollbar (ps); gtkps_draw_playlist (ps, 0, 0, widget->allocation.width, widget->allocation.height); gtkps_expose (ps, 0, 0, widget->allocation.width, widget->allocation.height); + search_refresh (); return; } else if (keyval == GDK_Down && ps->row < (*ps->count) - 1) { diff --git a/gtkplaylist.h b/gtkplaylist.h index 1b12e165..25333c7f 100644 --- a/gtkplaylist.h +++ b/gtkplaylist.h @@ -43,10 +43,9 @@ typedef struct { // parameters playItem_t **pcurr; // pointer to current item int *count; // pointer to count of items in list - int update_statusbar; // whether it needs to update status bar in certain cases - int has_dragndrop; // whether it has drag and drop capability int iterator; // index into next array of playItem_t struct int lastpos[2]; // last mouse position (for playlist widget) + int multisel; // if it uses multiple selection // current state int scrollpos; int row; @@ -86,11 +86,21 @@ on_searchentry_changed (GtkEditable *editable, extern gtkplaylist_t search_playlist; gtkplaylist_t *ps = &search_playlist; gtkps_setup_scrollbar (ps); + if (ps->row >= search_count) { + ps->row = search_count-1; + } memset (ps->fmtcache, 0, sizeof (int16_t) * 3 * ps_ncolumns * ps->nvisiblerows); gtkps_draw_playlist (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height); gtkps_expose (ps, 0, 0, ps->playlist->allocation.width, ps->playlist->allocation.height); } +void +search_refresh (void) { + if (searchwin) { + on_searchentry_changed (GTK_EDITABLE (lookup_widget (searchwin, "searchentry")), NULL); + } +} + ///////// searchwin header handlers gboolean @@ -24,4 +24,8 @@ extern int search_count; void search_start (void); +// should be called whenever playlist was changed +void +search_refresh (void); + #endif // __SEARCH_H |