/*
- * This file is part of DisOrder
* Copyright (C) 2009 Richard Kettlewell
*
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * Note that this license ONLY applies to multidrag.c and multidrag.h, not to
+ * the rest of DisOrder.
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
+ * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/** @file disobedience/multidrag.c
* @brief Drag multiple rows of a GtkTreeView
int *where = g_object_get_data(G_OBJECT(w), "multidrag-where");
if(!where) {
where = g_malloc(2 * sizeof (int));
- g_object_set_data(G_OBJECT(w), "multidrag-where", where);
+ g_object_set_data_full(G_OBJECT(w), "multidrag-where", where,
+ g_free);
}
where[0] = x;
where[1] = y;
- // TODO release 'where' when object is destroyed
}
static gboolean multidrag_button_press_event(GtkWidget *w,
/* We are only interested in left-button behavior */
if(event->button != 1)
return FALSE;
- /* We are only interested in unmodified clicks (not SHIFT etc) */
- if(event->state & GDK_MODIFIER_MASK)
+ /* We are only uninterested in clicks without CTRL or SHIFT. GTK ignores the
+ * other possible modifiers, so we do too. */
+ if(event->state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK))
return FALSE;
/* We are only interested if a well-defined path is clicked */
- GtkTreePath *path;
+ GtkTreePath *path = NULL;
if(!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(w),
event->x, event->y,
&path,
NULL,
NULL, NULL))
return FALSE;
- //gtk_widget_grab_focus(w); // TODO why??
/* We are only interested if a selected row is clicked */
GtkTreeSelection *s = gtk_tree_view_get_selection(GTK_TREE_VIEW(w));
- if(!gtk_tree_selection_path_is_selected(s, path))
- return FALSE;
- /* We block subsequent selection changes and remember where the
- * click was */
- block_selection(w, FALSE, event->x, event->y);
+ if(gtk_tree_selection_path_is_selected(s, path)) {
+ /* We block subsequent selection changes and remember where the
+ * click was */
+ block_selection(w, FALSE, event->x, event->y);
+ }
+ if(path)
+ gtk_tree_path_free(path);
return FALSE; /* propagate */
}
if(x == event->x && y == event->y) {
// If the up-click is at the same location as the down-click,
// it's not a drag.
- GtkTreePath *path;
+ GtkTreePath *path = NULL;
GtkTreeViewColumn *col;
if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(w),
event->x, event->y,
NULL, NULL)) {
gtk_tree_view_set_cursor(GTK_TREE_VIEW(w), path, col, FALSE);
}
+ if(path)
+ gtk_tree_path_free(path);
}
}
return FALSE; /* propagate */