// -*- c++ -*- /* $Id: treeviewcolumn.ccg,v 1.6 2006/05/10 20:59:28 murrayc Exp $ */ /* Copyright 2002 The gtkmm Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include namespace Gtk { // Only necessary because of the templated ctor, see .hg file. const Glib::Class& TreeViewColumn::class_init_() { return treeviewcolumn_class_.init(); } TreeViewColumn::TreeViewColumn(const Glib::ustring& title) : _CONSTRUCT("title", title.c_str()) {} TreeViewColumn::TreeViewColumn(const Glib::ustring& title, Gtk::CellRenderer& cell) : _CONSTRUCT("title", title.c_str()) { //This is equivalent to _gtk_tree_view_column_new_with_attributes(). //You will also need to call add_atrribute(), or set_renderer() a few times. pack_start(cell, true); } void TreeViewColumn::add_attribute(Gtk::CellRenderer& cell, const Glib::ustring& property_name, const TreeModelColumnBase& column) { gtk_tree_view_column_add_attribute(gobj(), (GtkCellRenderer*) cell.gobj(), property_name.c_str(), column.index()); } #ifdef GLIBMM_PROPERTIES_ENABLED void TreeViewColumn::add_attribute(const Glib::PropertyProxy_Base& property, const TreeModelColumnBase& column) { gtk_tree_view_column_add_attribute(gobj(), (GtkCellRenderer*) property.get_object()->gobj(), property.get_name(), column.index()); } #endif //GLIBMM_PROPERTIES_ENABLED void TreeViewColumn::set_renderer(Gtk::CellRenderer& renderer, const TreeModelColumnBase& column) { #ifdef GLIBMM_PROPERTIES_ENABLED add_attribute(renderer._property_renderable(), column); #else add_attribute(renderer, renderer._property_renderable(), column); #endif } void TreeViewColumn::set_cell_data_func(CellRenderer& cell_renderer, const SlotCellData& slot) { //Create a copy of the slot. A pointer to this will be passed through the callback's data parameter. //It will be deleted when TreeView_Private::SignalProxy_CellData_gtk_callback_destroy() is called. SlotCellData* slot_copy = new SlotCellData(slot); gtk_tree_view_column_set_cell_data_func( gobj(), cell_renderer.gobj(), &TreeView_Private::SignalProxy_CellData_gtk_callback, slot_copy, &TreeView_Private::SignalProxy_CellData_gtk_callback_destroy); } void TreeViewColumn::unset_cell_data_func(CellRenderer& cell_renderer) { gtk_tree_view_column_set_cell_data_func(gobj(), cell_renderer.gobj(), 0, 0, 0); } CellRenderer* TreeViewColumn::get_first_cell_renderer() { typedef std::vector type_vecCellRenderers; type_vecCellRenderers vecCellRenderers = get_cell_renderers(); if(!vecCellRenderers.empty()) return vecCellRenderers[0]; else return 0; } const CellRenderer* TreeViewColumn::get_first_cell_renderer() const { //Do some const_cast-ing to avoid repetition of code: return const_cast(this)->get_first_cell_renderer(); } _DEPRECATE_IFDEF_START void TreeViewColumn::set_sort_column_id(const TreeModelColumnBase& sort_column) { set_sort_column(sort_column); } void TreeViewColumn::set_sort_column_id(int sort_column_id) { set_sort_column(sort_column_id); } _DEPRECATE_IFDEF_END } // namespace Gtk