| 1 |
/* Copyright (C) 2003 The gtkmm Development Team |
| 2 |
* |
| 3 |
* This library is free software; you can redistribute it and/or |
| 4 |
* modify it under the terms of the GNU Lesser General Public |
| 5 |
* License as published by the Free Software Foundation; either |
| 6 |
* version 2.1 of the License, or (at your option) any later version. |
| 7 |
* |
| 8 |
* This library is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 |
* Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public |
| 14 |
* License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include <vector> |
| 18 |
|
| 19 |
#include <glibmm/interface.h> |
| 20 |
//#include <gtkmm/cellarea.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 |
class GTKMM_API CellArea; |
| 39 |
|
| 40 |
/** An interface for packing cells. |
| 41 |
* CellLayout is an interface to be implemented by all objects which want to provide a TreeView::Column-like API |
| 42 |
* for packing cells, setting attributes and data funcs. |
| 43 |
*/ |
| 44 |
class GTKMM_API CellLayout : public Glib::Interface |
| 45 |
{ |
| 46 |
_CLASS_INTERFACE(CellLayout, GtkCellLayout, GTK_CELL_LAYOUT, GtkCellLayoutIface, , , GTKMM_API) |
| 47 |
|
| 48 |
public: |
| 49 |
|
| 50 |
template <class ColumnType> inline |
| 51 |
void pack_start(const TreeModelColumn<ColumnType>& model_column, bool expand = true); |
| 52 |
_IGNORE(gtk_cell_layout_add_attribute, gtk_cell_layout_set_attributes) |
| 53 |
|
| 54 |
_WRAP_METHOD(void pack_start(CellRenderer& cell, bool expand = true), gtk_cell_layout_pack_start) |
| 55 |
_WRAP_METHOD(void pack_end(CellRenderer& cell, bool expand = true), gtk_cell_layout_pack_end) |
| 56 |
|
| 57 |
#m4 _CONVERSION(`GList*', `std::vector<CellRenderer*>', `Glib::ListHandler<CellRenderer*>::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)') |
| 58 |
#m4 _CONVERSION(`GList*', `std::vector<const CellRenderer*>', `Glib::ListHandler<const CellRenderer*>::list_to_vector($3, Glib::OWNERSHIP_SHALLOW)') |
| 59 |
_WRAP_METHOD(std::vector<CellRenderer*> get_cells(), gtk_cell_layout_get_cells) |
| 60 |
_WRAP_METHOD(std::vector<const CellRenderer*> get_cells() const, gtk_cell_layout_get_cells) |
| 61 |
|
| 62 |
/** Gets the CellRenderer for the first column if any has been added, or |
| 63 |
* nullptr otherwise. |
| 64 |
* You should dynamic_cast<> to the expected derived CellRenderer type. |
| 65 |
*/ |
| 66 |
CellRenderer* get_first_cell(); |
| 67 |
|
| 68 |
/** Gets the CellRenderer for the first column if any has been added, or |
| 69 |
* nullptr otherwise. |
| 70 |
* You should dynamic_cast<> to the expected derived CellRenderer type. |
| 71 |
*/ |
| 72 |
const CellRenderer* get_first_cell() const; |
| 73 |
|
| 74 |
_WRAP_METHOD(void clear(), gtk_cell_layout_clear) |
| 75 |
|
| 76 |
_IGNORE(gtk_cell_layout_set_attributes) //I think this is just a convenience method, equivalent to clear() and multiple add_attribute()s. murrayc. |
| 77 |
|
| 78 |
_WRAP_METHOD(void add_attribute(CellRenderer& cell, const Glib::ustring& attribute, int column), gtk_cell_layout_add_attribute) |
| 79 |
|
| 80 |
void add_attribute(const Glib::PropertyProxy_Base& property, const TreeModelColumnBase& column); |
| 81 |
|
| 82 |
void add_attribute(CellRenderer& cell, const Glib::ustring& attribute, const TreeModelColumnBase& column); |
| 83 |
|
| 84 |
//For instance, void on_cell_data(const TreeModel::const_iterator& iter) |
| 85 |
typedef sigc::slot<void, const TreeModel::const_iterator&> SlotCellData; |
| 86 |
|
| 87 |
void set_cell_data_func(CellRenderer& cell, const SlotCellData& slot); |
| 88 |
_IGNORE(gtk_cell_layout_set_cell_data_func) |
| 89 |
|
| 90 |
_WRAP_METHOD(void clear_attributes(CellRenderer& cell), gtk_cell_layout_clear_attributes) |
| 91 |
|
| 92 |
_WRAP_METHOD(void reorder(CellRenderer& cell, int position), gtk_cell_layout_reorder) |
| 93 |
|
| 94 |
_WRAP_METHOD(Glib::RefPtr<CellArea> get_area(), gtk_cell_layout_get_area, refreturn) |
| 95 |
_WRAP_METHOD(Glib::RefPtr<const CellArea> get_area() const, gtk_cell_layout_get_area, refreturn, constversion) |
| 96 |
|
| 97 |
protected: |
| 98 |
_WRAP_VFUNC(void pack_start(CellRenderer* cell, bool expand), pack_start) |
| 99 |
_WRAP_VFUNC(void pack_end(CellRenderer* cell, bool expand), pack_end) |
| 100 |
_WRAP_VFUNC(void clear(), clear) |
| 101 |
|
| 102 |
#m4 _CONVERSION(`const char*',`const Glib::ustring&',__GCHARP_TO_USTRING) |
| 103 |
_WRAP_VFUNC(void add_attribute(CellRenderer* cell, const Glib::ustring& attribute, int column), add_attribute) |
| 104 |
|
| 105 |
//TODO when we can break ABI(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) |
| 106 |
_WRAP_VFUNC(void clear_attributes(CellRenderer* cell), clear_attributes) |
| 107 |
_WRAP_VFUNC(void reorder(CellRenderer* cell, int position), reorder) |
| 108 |
|
| 109 |
}; |
| 110 |
|
| 111 |
template<class T_ModelColumnType> |
| 112 |
void CellLayout::pack_start(const TreeModelColumn<T_ModelColumnType>& column, bool expand) |
| 113 |
{ |
| 114 |
//Generate appropriate Renderer for the column: |
| 115 |
CellRenderer* pCellRenderer = manage( CellRenderer_Generation::generate_cellrenderer<T_ModelColumnType>() ); |
| 116 |
|
| 117 |
//Use the renderer: |
| 118 |
pack_start(*pCellRenderer, expand); |
| 119 |
|
| 120 |
//Make the renderer render the column: |
| 121 |
add_attribute(pCellRenderer->_property_renderable(), column); |
| 122 |
} |
| 123 |
|
| 124 |
} // namespace Gtk |