self->highlight = FALSE;
self->highlight_col = -1;
self->highlight_row = -1;
-
+
// event handler
GtkGesture *drag = gtk_gesture_drag_new();
g_signal_connect(drag, "drag-begin", G_CALLBACK(drag_begin_cb), self);
#define MZ_GRID_VIEW_SELECTION_WIDTH 165
#define MZ_GRID_VIEW_SELECTION_HEIGHT 165
-static int point2item(MzFilesView *view, int x, int y, int *out_col, int *out_row) {
+static int point2item(MzFilesView *view, int x, int y, int *out_col, int *out_row, size_t *index) {
int width = view->current_width;
width -= MZ_GRID_VIEW_PADDING_LEFT + MZ_GRID_VIEW_PADDING_RIGHT;
-
+
int item_width = 180;
int item_height = 170;
+ int items_per_line = width / item_width;
+
int highlight_width = MZ_GRID_VIEW_SELECTION_WIDTH;
int highlight_height = MZ_GRID_VIEW_SELECTION_HEIGHT;
int highlight_rect_offset_x = (item_width - highlight_width) / 2;
if(col >= 0 && row >= 0) {
*out_col = col;
*out_row = row;
+ if(index) {
+ *index = row * items_per_line + col;
+ }
return 1;
}
return 0;
printf("drag_begin_cb: %f\n", start_x);
// update selection
- int item_selection_width = 160;
- int item_selection_height = 160;
- int selection_offset_x = 5;
- int selection_offset_y = 5;
int item_width = 180;
int item_height = 170;
int col;
+ int row;
+ size_t item_index;
+ if(point2item(view, start_x, start_y, &col, &row, &item_index)) {
+ if(view->numsections > 0 && item_index < cxListSize(view->sections[0].section.files)) {
+ FileInfo *file = cxListAt(view->sections[0].section.files, item_index);
+ printf("drag file: %s\n", file->name);
+ view->drag_file = file;
+ view->drag_item = TRUE;
+ return;
+ }
+ }
+
if(start_x <= MZ_GRID_VIEW_PADDING_LEFT) {
col = -1;
} else {
col = (start_x - MZ_GRID_VIEW_PADDING_LEFT) / item_width;
}
- int row = start_y / item_height;
+ row = start_y / item_height;
view->drag = TRUE;
view->drag_start_x = start_x;
{
MzFilesView *view = user_data;
view->drag = FALSE;
+ view->drag_item = FALSE;
+ view->drag_file = NULL;
view->update_selection = 1;
gtk_widget_queue_draw(GTK_WIDGET(view));
gpointer user_data)
{
MzFilesView *view = user_data;
+ if(view->drag_file) {
+ return;
+ }
view->drag_width = x;
view->drag_height = y;
+
// update selection
- int item_selection_width = 160;
- int item_selection_height = 160;
- int selection_offset_x = 5;
- int selection_offset_y = 5;
int item_width = 180;
int item_height = 170;
gpointer user_data)
{
MzFilesView *view = user_data;
+ if(view->drag_file) {
+
+ return;
+ }
int col, row;
int update = FALSE;
- if(point2item(view, x, y, &col, &row)) {
+ if(point2item(view, x, y, &col, &row, NULL)) {
if(view->highlight_col != col || view->highlight_row != row) {
update = TRUE;
view->highlight = TRUE;