X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/ff18efce04ac61f70943dbdb6273c7663a1bb936..a59bf4da6cdf7b4c5f3ddf359cb69676554ee222:/disobedience/multidrag.c diff --git a/disobedience/multidrag.c b/disobedience/multidrag.c index 2f58ae1..8b28c94 100644 --- a/disobedience/multidrag.c +++ b/disobedience/multidrag.c @@ -1,19 +1,27 @@ /* - * 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 . + * 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 @@ -68,11 +76,11 @@ static void block_selection(GtkWidget *w, gboolean block, 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, @@ -88,21 +96,22 @@ static gboolean multidrag_button_press_event(GtkWidget *w, if(event->state & GDK_MODIFIER_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 */ } @@ -121,7 +130,7 @@ static gboolean multidrag_button_release_event(GtkWidget *w, 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, @@ -130,6 +139,8 @@ static gboolean multidrag_button_release_event(GtkWidget *w, NULL, NULL)) { gtk_tree_view_set_cursor(GTK_TREE_VIEW(w), path, col, FALSE); } + if(path) + gtk_tree_path_free(path); } } return FALSE; /* propagate */