1// -*- c++ -*- 2/* $Id: treesortable.ccg,v 1.7 2006/05/11 11:40:24 murrayc Exp $ */ 3 4/* Copyright 1998-2002 The gtkmm Development Team 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2.1 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the Free 18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21static int SignalProxy_Compare_gtk_callback(GtkTreeModel* model, GtkTreeIter* lhs, GtkTreeIter* rhs, void* data) 22{ 23 Gtk::TreeSortable::SlotCompare* the_slot = static_cast<Gtk::TreeSortable::SlotCompare*>(data); 24 25 try 26 { 27 // use Slot::operator() 28 return (*the_slot)(Gtk::TreeIter(model, lhs), Gtk::TreeIter(model, rhs)); 29 } 30 catch(...) 31 { 32 Glib::exception_handlers_invoke(); 33 } 34 35 return 0; 36} 37 38static void SignalProxy_Compare_gtk_callback_destroy(void* data) 39{ 40 delete static_cast<Gtk::TreeSortable::SlotCompare*>(data); 41} 42 43namespace Gtk 44{ 45 46void TreeSortable::set_sort_func(int sort_column_id, const SlotCompare& slot) 47{ 48 SlotCompare* slot_copy = new SlotCompare(slot); 49 50 gtk_tree_sortable_set_sort_func( 51 gobj(), sort_column_id, 52 &SignalProxy_Compare_gtk_callback, slot_copy, 53 &SignalProxy_Compare_gtk_callback_destroy); 54} 55 56void TreeSortable::set_sort_func(const Gtk::TreeModelColumnBase& sort_column, const SlotCompare& slot) 57{ 58 set_sort_func(sort_column.index(), slot); 59} 60 61void TreeSortable::set_default_sort_func(const SlotCompare& slot) 62{ 63 SlotCompare* slot_copy = new SlotCompare(slot); 64 65 gtk_tree_sortable_set_default_sort_func( 66 gobj(), 67 &SignalProxy_Compare_gtk_callback, slot_copy, 68 &SignalProxy_Compare_gtk_callback_destroy); 69} 70 71void TreeSortable::unset_default_sort_func() 72{ 73 gtk_tree_sortable_set_default_sort_func( 74 gobj(), 0, 0, 0); /* See GTK+ docs about the 0s. */ 75} 76 77_DEPRECATE_IFDEF_START 78void TreeSortable::set_sort_column_id(const TreeModelColumnBase& sort_column, SortType order) 79{ 80 set_sort_column(sort_column, order); 81} 82 83void TreeSortable::set_sort_column_id(int sort_column_id, SortType order) 84{ 85 set_sort_column(sort_column_id, order); 86} 87_DEPRECATE_IFDEF_END 88 89} // namespace Gtk 90 91