1 /* $Id: celllayout.hg,v 1.12 2006/05/10 20:59:27 murrayc Exp $ */
3 /* Copyright (C) 2003 The gtkmm Development Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <glibmm/interface.h>
21 #include <gtkmm/cellrenderer.h>
22 #include <gtkmm/cellrenderer_generation.h>
23 #include <gtkmm/treemodel.h>
25 _PINCLUDE(glibmm/private/interface_p.h)
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 typedef struct _GtkCellLayoutIface GtkCellLayoutIface;
32 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
38 /** An interface for packing cells.
39 * CellLayout is an interface to be implemented by all objects which want to provide a TreeView::Column-like API
40 * for packing cells, setting attributes and data funcs.
42 class CellLayout : public Glib::Interface
44 _CLASS_INTERFACE(CellLayout, GtkCellLayout, GTK_CELL_LAYOUT, GtkCellLayoutIface)
48 template <class ColumnType> inline
49 void pack_start(const TreeModelColumn<ColumnType>& model_column, bool expand = true);
50 _IGNORE(gtk_cell_layout_add_attribute, gtk_cell_layout_set_attributes)
52 _WRAP_METHOD(void pack_start(CellRenderer& cell, bool expand = true), gtk_cell_layout_pack_start)
53 _WRAP_METHOD(void pack_end(CellRenderer& cell, bool expand = true), gtk_cell_layout_pack_end)
55 #m4 _CONVERSION(`GList*', `Glib::ListHandle<CellRenderer*>', `$2($3, Glib::OWNERSHIP_SHALLOW)')
56 #m4 _CONVERSION(`GList*', `Glib::ListHandle<const CellRenderer*>', `$2($3, Glib::OWNERSHIP_SHALLOW)')
57 _WRAP_METHOD(Glib::ListHandle<CellRenderer*> get_cells(), gtk_cell_layout_get_cells)
58 _WRAP_METHOD(Glib::ListHandle<const CellRenderer*> get_cells() const, gtk_cell_layout_get_cells)
60 _WRAP_METHOD(void clear(), gtk_cell_layout_clear)
62 _IGNORE(gtk_cell_layout_set_attributes) //I think this is just a convenience method, equivalent to clear() and multiple add_attribute()s. murrayc.
64 _WRAP_METHOD(void add_attribute(CellRenderer& cell, const Glib::ustring& attribute, int column), gtk_cell_layout_add_attribute)
66 #ifdef GLIBMM_PROPERTIES_ENABLED
67 void add_attribute(const Glib::PropertyProxy_Base& property, const TreeModelColumnBase& column);
70 void add_attribute(CellRenderer& cell, const Glib::ustring& attribute, const TreeModelColumnBase& column);
72 //For instance, void on_cell_data(const TreeModel::const_iterator& iter)
73 typedef sigc::slot<void, const TreeModel::const_iterator&> SlotCellData;
75 void set_cell_data_func(CellRenderer& cell, const SlotCellData& slot);
76 _IGNORE(gtk_cell_layout_set_cell_data_func)
78 _WRAP_METHOD(void clear_attributes(CellRenderer& cell), gtk_cell_layout_clear_attributes)
80 _WRAP_METHOD(void reorder(CellRenderer& cell, int position), gtk_cell_layout_reorder)
83 _WRAP_VFUNC(void pack_start(CellRenderer* cell, bool expand), pack_start)
84 _WRAP_VFUNC(void pack_end(CellRenderer* cell, bool expand), pack_end)
85 _WRAP_VFUNC(void clear(), clear)
86 _WRAP_VFUNC(void add_attribute(CellRenderer* cell, const Glib::ustring& attribute, int column), add_attribute)
87 //TODO (added in GTK+ 2.4): _WRAP_VFUNC(void set_cell_data_func(CellRenderer* cell, GtkCellLayoutDataFunc func, gpointer func_data, GDestroyNotify destroy), gtk_cell_layout_set_cell_data_func)
88 _WRAP_VFUNC(void clear_attributes(CellRenderer* cell), clear_attributes)
89 _WRAP_VFUNC(void reorder(CellRenderer* cell, int position), reorder)
93 template<class T_ModelColumnType>
94 void CellLayout::pack_start(const TreeModelColumn<T_ModelColumnType>& column, bool expand)
96 //Generate appropriate Renderer for the column:
97 CellRenderer* pCellRenderer = manage( CellRenderer_Generation::generate_cellrenderer<T_ModelColumnType>() );
100 pack_start(*pCellRenderer, expand);
102 //Make the renderer render the column:
103 #ifdef GLIBMM_PROPERTIES_ENABLED
104 add_attribute(pCellRenderer->_property_renderable(), column);
106 add_attribute(*pCellRenderer, pCellRenderer->_property_renderable(), column);