add new sigc++2 directory
[ardour.git] / libs / gtkmm2 / gtk / src / celllayout.hg
1 /* $Id: celllayout.hg,v 1.12 2006/05/10 20:59:27 murrayc Exp $ */
2
3 /* Copyright (C) 2003 The gtkmm Development Team
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #include <glibmm/interface.h>
21 #include <gtkmm/cellrenderer.h>
22 #include <gtkmm/cellrenderer_generation.h>
23 #include <gtkmm/treemodel.h>
24 _DEFS(gtkmm,gtk)
25 _PINCLUDE(glibmm/private/interface_p.h)
26
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
28 extern "C"
29 {
30 typedef struct _GtkCellLayoutIface GtkCellLayoutIface;
31 }
32 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
33
34
35 namespace Gtk
36 {
37
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.
41  */
42 class CellLayout : public Glib::Interface
43 {
44   _CLASS_INTERFACE(CellLayout, GtkCellLayout, GTK_CELL_LAYOUT, GtkCellLayoutIface)
45
46 public:
47
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)
51
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)
54
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)
59
60   _WRAP_METHOD(void clear(), gtk_cell_layout_clear)
61
62   _IGNORE(gtk_cell_layout_set_attributes) //I think this is just a convenience method, equivalent to clear() and multiple add_attribute()s. murrayc.
63
64   _WRAP_METHOD(void add_attribute(CellRenderer& cell, const Glib::ustring& attribute, int column), gtk_cell_layout_add_attribute)
65
66 #ifdef GLIBMM_PROPERTIES_ENABLED
67   void add_attribute(const Glib::PropertyProxy_Base& property, const TreeModelColumnBase& column);
68 #endif
69
70   void add_attribute(CellRenderer& cell, const Glib::ustring& attribute, const TreeModelColumnBase& column);
71
72   //For instance, void on_cell_data(const TreeModel::const_iterator& iter)
73   typedef sigc::slot<void, const TreeModel::const_iterator&> SlotCellData;
74
75   void set_cell_data_func(CellRenderer& cell, const SlotCellData& slot);
76   _IGNORE(gtk_cell_layout_set_cell_data_func)
77
78   _WRAP_METHOD(void clear_attributes(CellRenderer& cell), gtk_cell_layout_clear_attributes)
79
80   _WRAP_METHOD(void reorder(CellRenderer& cell, int position), gtk_cell_layout_reorder)
81
82 protected:
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)
90
91 };
92
93 template<class T_ModelColumnType>
94 void CellLayout::pack_start(const TreeModelColumn<T_ModelColumnType>& column, bool expand)
95 {
96   //Generate appropriate Renderer for the column:
97   CellRenderer* pCellRenderer = manage( CellRenderer_Generation::generate_cellrenderer<T_ModelColumnType>() );
98
99   //Use the renderer:
100   pack_start(*pCellRenderer, expand);
101
102   //Make the renderer render the column:
103 #ifdef GLIBMM_PROPERTIES_ENABLED
104   add_attribute(pCellRenderer->_property_renderable(), column);
105 #else
106   add_attribute(*pCellRenderer, pCellRenderer->_property_renderable(), column);
107 #endif
108 }
109
110 } // namespace Gtk
111