diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2010-03-14 19:08:01 +0100 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2010-03-14 19:08:01 +0100 |
commit | 4ae4bb8c81bd722c656435231625ae4f9ef86e71 (patch) | |
tree | f7023034217fbd4d8ee8343b22d8e63dcd34539e | |
parent | 0ec1a0764355707a31d0cde65fdae37e600221f3 (diff) |
fixed tabstrip drag-n-drop
-rw-r--r-- | deadbeef.h | 1 | ||||
-rw-r--r-- | playlist.c | 57 | ||||
-rw-r--r-- | playlist.h | 3 | ||||
-rw-r--r-- | plugins.c | 1 | ||||
-rw-r--r-- | plugins/gtkui/ddbtabstrip.c | 33 |
5 files changed, 77 insertions, 18 deletions
@@ -289,6 +289,7 @@ typedef struct { int (*plt_get_curr) (void); int (*plt_get_title) (int plt, char *buffer, int bufsize); int (*plt_set_title) (int plt, const char *title); + void (*plt_move) (int from, int before); // playlist control void (*pl_lock) (void); void (*pl_unlock) (void); @@ -361,6 +361,59 @@ plt_free (void) { } void +plt_move (int from, int before) { + if (from == before) { + return; + } + int i; + PLT_LOCK; + playlist_t *p = playlists_head; + + playlist_t *pfrom = NULL; + playlist_t *prev = NULL; + playlist_t *ins = NULL; + + for (i = 0; p && i <= from; i++) { + if (i == from) { + pfrom = p; + if (prev) { + prev->next = p->next; + } + else { + playlists_head = p->next; + } + break; + } + prev = p; + p = p->next; + } +// if (before > from) { +// before--; +// } + + if (before == 0) { + pfrom->next = playlists_head; + playlists_head = pfrom; + } + else { + p = playlists_head; + for (i = 0; p && i < before; i++) { + if (i == before-1) { + playlist_t *next = p->next; + p->next = pfrom; + pfrom->next = next; + break; + } + prev = p; + p = p->next; + } + } + + PLT_UNLOCK; + plt_gen_conf (); +} + +void pl_clear (void) { LOCK; while (playlist->head[PL_MAIN]) { @@ -1426,10 +1479,10 @@ pl_delete_selected (void) { } } if (playlist->current_row[PL_MAIN] >= playlist->count[PL_MAIN]) { - playlist->current_row[PL_MAIN] == playlist->count[PL_MAIN] - 1; + playlist->current_row[PL_MAIN] = playlist->count[PL_MAIN] - 1; } if (playlist->current_row[PL_SEARCH] >= playlist->count[PL_SEARCH]) { - playlist->current_row[PL_SEARCH] == playlist->count[PL_SEARCH] - 1; + playlist->current_row[PL_SEARCH] = playlist->count[PL_SEARCH] - 1; } GLOBAL_UNLOCK; return ret; @@ -121,6 +121,9 @@ plt_get_title (int plt, char *buffer, int bufsize); int plt_set_title (int plt, const char *title); +void +plt_move (int from, int before); + // playlist access functions void pl_clear (void); @@ -112,6 +112,7 @@ static DB_functions_t deadbeef_api = { .plt_get_curr = plt_get_curr, .plt_get_title = plt_get_title, .plt_set_title = plt_set_title, + .plt_move = plt_move, // playlist access .pl_lock = pl_lock, .pl_unlock = pl_unlock, diff --git a/plugins/gtkui/ddbtabstrip.c b/plugins/gtkui/ddbtabstrip.c index ec279d1c..7be9b6f8 100644 --- a/plugins/gtkui/ddbtabstrip.c +++ b/plugins/gtkui/ddbtabstrip.c @@ -320,7 +320,7 @@ tabstrip_draw (GtkWidget *widget) { gtk_paint_box (widget->style, backbuf, GTK_STATE_ACTIVE, GTK_SHADOW_ETCHED_IN, NULL, widget, "button", x, 0, w, h); } #endif - x += ts->movepos; + x = ts->movepos; if (x >= widget->allocation.width) { break; } @@ -378,7 +378,14 @@ on_tabstrip_button_press_event (GtkWidget *widget, if (tab_clicked != -1) { deadbeef->plt_set_curr (tab_clicked); } - ts->dragpt[0] = event->x - ts->hscrollpos; + + int x = -ts->hscrollpos + tabs_left_margin; + int idx; + for (idx = 0; idx < tab_clicked; idx++) { + int width = ddb_tabstrip_get_tab_width (ts, idx); + x += width - tab_overlap_size; + } + ts->dragpt[0] = event->x - x; ts->dragpt[1] = event->y; ts->prepare = 1; ts->dragging = tab_clicked; @@ -425,7 +432,6 @@ on_tabstrip_expose_event (GtkWidget *widget, return FALSE; } - gboolean on_tabstrip_motion_notify_event (GtkWidget *widget, GdkEventMotion *event) @@ -445,28 +451,23 @@ on_tabstrip_motion_notify_event (GtkWidget *widget, if (!ts->prepare && ts->dragging >= 0) { // gdk_window_set_cursor (widget->window, cursor_drag); ts->movepos = ev_x - ts->dragpt[0]; - int drag_width = ddb_tabstrip_get_tab_width (ts, ts->dragging); // find closest tab to the left + int idx; + int x = -ts->hscrollpos + tabs_left_margin; int inspos = -1; - int x = 0; - int idx = 0; - int x1 = -1, x2 = -1; int cnt = deadbeef->plt_get_count (); - for (idx = 0; idx < ts->dragging; idx++) { + for (idx = 0; idx < cnt; idx++) { int width = ddb_tabstrip_get_tab_width (ts, idx); - if (x < ts->movepos && x + width > ts->movepos) { + if (idx != ts->dragging && x <= ts->movepos && x + width/2 - tab_overlap_size > ts->movepos) { inspos = idx; - x1 = x; - } - else if (idx == ts->dragging) { - x2 = x; + break; } - x += drag_width; + x += width - tab_overlap_size; } if (inspos >= 0 && inspos != ts->dragging) { - //ddb_tabstrip_tab_move (ps, c, inspos); - //ts->dragging = inspos; + deadbeef->plt_move (ts->dragging, inspos); + ts->dragging = inspos; } tabstrip_draw (widget); } |