1/* Copyright(C) 2002 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, write to the Free Software 15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 16 */ 17 18// This is for including the config header before any code (such as 19// the #ifndef GTKMM_DISABLE_DEPRECATED in deprecated classes) is generated: 20_CONFIGINCLUDE(gtkmmconfig.h) 21 22#include <gtkmm/treeiter.h> 23#include <gtkmm/button.h> 24#include <gdkmm/window.h> 25#include <gtkmm/treemodel.h> 26#include <gtkmm/celllayout.h> 27#include <gtkmm/cellrenderer_generation.h> 28_DEFS(gtkmm,gtk) 29_PINCLUDE(gtkmm/private/object_p.h) 30 31namespace Gtk 32{ 33 34_CC_INCLUDE(gtk/gtk.h) 35_WRAP_ENUM(TreeViewColumnSizing, GtkTreeViewColumnSizing) 36 37// We use GTKMM_API here because gcc needs the extra help on win32 , even 38// when using --export-all and auto-import. 39// See http://bugzilla.gnome.org/show_bug.cgi?id=309030. 40 41class TreeView; 42 43//TODO: Deal with the GtkObject->GObject change? 44/** Typedefed as Gtk::TreeView::Column. 45 * This is a visible column in a Gtk::TreeView widget. It determines the geometry, type. 46 * 47 * @ingroup TreeView 48*/ 49class GTKMM_API TreeViewColumn 50 : public Object, 51 public CellLayout 52{ 53 _CLASS_GTKOBJECT(TreeViewColumn, GtkTreeViewColumn, GTK_TREE_VIEW_COLUMN, Object, GObject) 54 _IMPLEMENTS_INTERFACE(CellLayout) 55 _IGNORE(gtk_tree_view_column_set_cell_data_func) 56public: 57 typedef TreeViewColumn Column; 58 59 _CTOR_DEFAULT() 60 61 explicit TreeViewColumn(const Glib::ustring& title); 62 TreeViewColumn(const Glib::ustring& title, CellRenderer& cell); 63 64 /** Create a default view column for the given model column type. 65 */ 66 template<class T_ModelColumnType> 67 TreeViewColumn(const Glib::ustring& title, const TreeModelColumn<T_ModelColumnType>& column); 68 69 _WRAP_METHOD(void pack_start(CellRenderer& cell, bool expand = true), gtk_tree_view_column_pack_start) 70 _WRAP_METHOD(void pack_end(CellRenderer& cell, bool expand = true), gtk_tree_view_column_pack_end) 71 72 /** Creates an appropriate CellRenderer for the @a column, and packs that cell into the beginning of the column. 73 * If @a expand is <tt>false</tt>, then 74 * the cell is allocated no more space than it needs. Any unused space is divided 75 * evenly between cells for which @a expand is <tt>true</tt>. 76 * 77 * You can use get_first_cell() or get_cells() to access the generated CellRenderer. 78 * 79 * @param column The model column that will be rendered by the view cell. 80 * @param expand <tt>true</tt> if the cell is to be given extra space allocated to the view column. 81 */ 82 template<class T_ModelColumnType> 83 void pack_start(const TreeModelColumn<T_ModelColumnType>& column, bool expand = true); 84 85 /** Creates an appropriate CellRenderer for the @a column, and packs that cell at the end of the column. 86 * If @a expand is <tt>false</tt>, then 87 * the cell is allocated no more space than it needs. Any unused space is divided 88 * evenly between cells for which @a expand is <tt>true</tt>. 89 * 90 * You can use get_first_cell() or get_cells() to access the generated CellRenderer. 91 * 92 * @param column The model column that will be rendered by the view cell. 93 * @param expand <tt>true</tt> if the cell is to be given extra space allocated to the view column. 94 */ 95 template<class T_ModelColumnType> 96 void pack_end(const TreeModelColumn<T_ModelColumnType>& column, bool expand = true); 97 98 _WRAP_METHOD(void clear(), gtk_tree_view_column_clear) 99 100 _WRAP_METHOD(void add_attribute(CellRenderer& cell_renderer, const Glib::ustring& attribute, int column), 101 gtk_tree_view_column_add_attribute) 102 103 void add_attribute(const Glib::PropertyProxy_Base& property, const TreeModelColumnBase& column); 104 105 void add_attribute(Gtk::CellRenderer& cell, const Glib::ustring& property_name, const TreeModelColumnBase& column); 106 _IGNORE(gtk_tree_view_column_set_attributes) 107 108 /** Associate a view CellRenderer with a model column, so that the CellRenderer renders the data in the model column. 109 * 110 * @param renderer The view cell renderer which will render the model column. 111 * @param column The model column to be renderered by this view. 112 */ 113 void set_renderer(Gtk::CellRenderer& renderer, const TreeModelColumnBase& column); 114 115 // _WRAP_METHOD(void set_attributes(CellRenderer& cell_renderer, ...), ) 116 117_DEPRECATE_IFDEF_START 118 /** For instance, 119 * void on_cell_data(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter); 120 * 121 * This function is used instead of the standard attributes mapping for setting the column value, and should set the 122 * value of the column's cell renderer as appropriate. 123 * 124 * @deprecated Use SlotTreeCellData instead. 125 */ 126 typedef sigc::slot<void, CellRenderer*, const Gtk::TreeModel::iterator&> SlotCellData; 127_DEPRECATE_IFDEF_END 128 129 /** For instance, 130 * void on_cell_data(Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& iter); 131 * 132 * This function is used instead of the standard attributes mapping for setting the column value, and should set the 133 * value of the column's cell renderer as appropriate. 134 */ 135 typedef sigc::slot<void, CellRenderer*, const Gtk::TreeModel::iterator&> SlotTreeCellData; 136 137 /** Sets the slot callback to use for the column. 138 * This callback function is used instead of the standard attributes mapping for setting the column value, and should set the 139 * value of the column's cell renderer as appropriate. 140 * 141 * See also unset_cell_data_func(). 142 * 143 * @param cell_renderer A Gtk::CellRenderer 144 * @param slot The callback slot to use. Create this with sigc::mem_fun(), or sigc::ptr_fun(). 145 */ 146 void set_cell_data_func(CellRenderer& cell_renderer, const SlotTreeCellData& slot); 147 148 /** Removes a previously set callback slot. See set_cell_data_func(). 149 */ 150 void unset_cell_data_func(CellRenderer& cell_renderer); 151 152 _WRAP_METHOD(void clear_attributes(CellRenderer& cell_renderer), gtk_tree_view_column_clear_attributes) 153 _WRAP_METHOD(void set_spacing(int spacing), gtk_tree_view_column_set_spacing) 154 _WRAP_METHOD(int get_spacing() const, gtk_tree_view_column_get_spacing) 155 _WRAP_METHOD(void set_visible(bool visible = true), gtk_tree_view_column_set_visible) 156 _WRAP_METHOD(bool get_visible() const, gtk_tree_view_column_get_visible) 157 _WRAP_METHOD(void set_resizable(bool resizable = true), gtk_tree_view_column_set_resizable) 158 _WRAP_METHOD(bool get_resizable() const, gtk_tree_view_column_get_resizable) 159 _WRAP_METHOD(void set_sizing(TreeViewColumnSizing type), gtk_tree_view_column_set_sizing) 160 _WRAP_METHOD(TreeViewColumnSizing get_sizing(), gtk_tree_view_column_get_sizing) 161 _WRAP_METHOD(int get_x_offset() const, gtk_tree_view_column_get_x_offset) 162 _WRAP_METHOD(int get_width() const, gtk_tree_view_column_get_width) 163 _WRAP_METHOD(int get_fixed_width() const, gtk_tree_view_column_get_fixed_width) 164 _WRAP_METHOD(void set_fixed_width(int fixed_width), gtk_tree_view_column_set_fixed_width) 165 _WRAP_METHOD(void set_min_width(int min_width), gtk_tree_view_column_set_min_width) 166 _WRAP_METHOD(int get_min_width() const, gtk_tree_view_column_get_min_width) 167 _WRAP_METHOD(void set_max_width(int max_width), gtk_tree_view_column_set_max_width) 168 _WRAP_METHOD(int get_max_width() const, gtk_tree_view_column_get_max_width) 169 _WRAP_METHOD(void clicked(), gtk_tree_view_column_clicked) 170 171 _WRAP_METHOD(void set_title(const Glib::ustring& title), gtk_tree_view_column_set_title) 172 _WRAP_METHOD(Glib::ustring get_title() const, gtk_tree_view_column_get_title) 173 174 _WRAP_METHOD(void set_expand(bool expand = true), gtk_tree_view_column_set_expand) 175 _WRAP_METHOD(bool get_expand() const, gtk_tree_view_column_get_expand) 176 177 _WRAP_METHOD(void set_clickable(bool clickable = true), gtk_tree_view_column_set_clickable) 178 _WRAP_METHOD(bool get_clickable() const, gtk_tree_view_column_get_clickable) 179 _WRAP_METHOD(void set_widget(Gtk::Widget& widget), gtk_tree_view_column_set_widget) 180 _WRAP_METHOD(Widget* get_widget(), gtk_tree_view_column_get_widget) 181 _WRAP_METHOD(const Widget* get_widget() const, gtk_tree_view_column_get_widget) 182 183 _WRAP_METHOD(void set_alignment(float xalign), gtk_tree_view_column_set_alignment) 184 _WRAP_METHOD(void set_alignment(Align xalign), gtk_tree_view_column_set_alignment) 185 186 _WRAP_METHOD(float get_alignment() const, gtk_tree_view_column_get_alignment) 187 _WRAP_METHOD(void set_reorderable(bool reorderable = true), gtk_tree_view_column_set_reorderable) 188 _WRAP_METHOD(bool get_reorderable() const, gtk_tree_view_column_get_reorderable) 189 190 _WRAP_METHOD(void set_sort_column(const TreeModelColumnBase& sort_column_id), gtk_tree_view_column_set_sort_column_id) 191 _WRAP_METHOD(void set_sort_column(int sort_column_id), gtk_tree_view_column_set_sort_column_id) 192 193 _WRAP_METHOD(int get_sort_column_id() const, gtk_tree_view_column_get_sort_column_id) 194 _WRAP_METHOD(void set_sort_indicator(bool setting), gtk_tree_view_column_set_sort_indicator) 195 _WRAP_METHOD(bool get_sort_indicator() const, gtk_tree_view_column_get_sort_indicator) 196 _WRAP_METHOD(void set_sort_order(SortType order), gtk_tree_view_column_set_sort_order) 197 _WRAP_METHOD(SortType get_sort_order() const, gtk_tree_view_column_get_sort_order) 198 199 200 _WRAP_METHOD(void cell_set_cell_data(const Glib::RefPtr<TreeModel>& tree_model, const TreeModel::iterator& iter, bool is_expander, bool is_expanded), gtk_tree_view_column_cell_set_cell_data) 201 202 //TODO: cell_area can be NULL. Add a method overload. 203 //But see http://bugzilla.gnome.org/show_bug.cgi?id=542329 about the lack of C documentation. 204 _WRAP_METHOD(void cell_get_size(const Gdk::Rectangle& cell_area, int& x_offset, int& y_offset, int& width, int& height) const, gtk_tree_view_column_cell_get_size) 205 206 _WRAP_METHOD(bool cell_is_visible() const, gtk_tree_view_column_cell_is_visible) 207 _WRAP_METHOD(void focus_cell(CellRenderer& cell), gtk_tree_view_column_focus_cell) 208 209 _WRAP_METHOD(bool get_cell_position(const CellRenderer& cell_renderer, int& start_pos, int& width) const, gtk_tree_view_column_cell_get_position) 210 _WRAP_METHOD(void queue_resize(), gtk_tree_view_column_queue_resize) 211 212 _WRAP_METHOD(TreeView* get_tree_view(), gtk_tree_view_column_get_tree_view, refreturn) 213 _WRAP_METHOD(const TreeView* get_tree_view() const, gtk_tree_view_column_get_tree_view, refreturn, constversion) 214 215 _WRAP_METHOD(Button* get_button(), gtk_tree_view_column_get_button, refreturn) 216 _WRAP_METHOD(const Button* get_button() const, gtk_tree_view_column_get_button, refreturn, constversion) 217 218 _WRAP_SIGNAL(void clicked(), "clicked") 219 220 _WRAP_PROPERTY("visible", bool) 221 _WRAP_PROPERTY("resizable", bool) 222 _WRAP_PROPERTY("x-offset", int) 223 _WRAP_PROPERTY("width", int) 224 _WRAP_PROPERTY("spacing", int) 225 _WRAP_PROPERTY("sizing", TreeViewColumnSizing) 226 _WRAP_PROPERTY("fixed-width", int) 227 _WRAP_PROPERTY("min-width", int) 228 _WRAP_PROPERTY("max-width", int) 229 _WRAP_PROPERTY("title", Glib::ustring) 230 _WRAP_PROPERTY("expand", bool) 231 _WRAP_PROPERTY("clickable", bool) 232 _WRAP_PROPERTY("widget", Widget*) 233 _WRAP_PROPERTY("alignment", float) 234 _WRAP_PROPERTY("reorderable", bool) 235 _WRAP_PROPERTY("sort-indicator", bool) 236 _WRAP_PROPERTY("sort-order", SortType) 237 _WRAP_PROPERTY("sort-column-id", int) 238 _WRAP_PROPERTY("cell-area", Glib::RefPtr<CellArea>) 239 240#ifndef DOXYGEN_SHOULD_SKIP_THIS 241private: 242 // Only necessary because of the templated ctor, see below. 243 static const Glib::Class& class_init_(); 244#endif //DOXYGEN_SHOULD_SKIP_THIS 245}; 246 247#ifndef DOXYGEN_SHOULD_SKIP_THIS 248 249template<class T_ModelColumnType> inline 250void TreeViewColumn::pack_start(const TreeModelColumn<T_ModelColumnType>& column, bool expand) 251{ 252 //Generate appropriate Renderer for the column: 253 CellRenderer* pCellRenderer = manage( CellRenderer_Generation::generate_cellrenderer<T_ModelColumnType>() ); 254 255 //Use the renderer: 256 pack_start(*pCellRenderer, expand); 257 set_renderer(*pCellRenderer, column); 258} 259 260template<class T_ModelColumnType> inline 261void TreeViewColumn::pack_end(const TreeModelColumn<T_ModelColumnType>& column, bool expand) 262{ 263 //Generate appropriate Renderer for the column: 264 CellRenderer* pCellRenderer= manage( CellRenderer_Generation::generate_cellrenderer<T_ModelColumnType>() ); 265 266 //Use the renderer: 267 pack_end(*pCellRenderer, expand); 268 set_renderer(*pCellRenderer, column); 269} 270 271template <class T_ModelColumnType> inline 272TreeViewColumn::TreeViewColumn(const Glib::ustring& title, 273 const TreeModelColumn<T_ModelColumnType>& column) 274: 275 Glib::ObjectBase(nullptr), // not (yet) a custom class 276 Gtk::Object(Glib::ConstructParams(class_init_(), "title", title.c_str(), nullptr)) 277{ 278 pack_start(column, true /* expand */); 279} 280 281#endif /* DOXYGEN_SHOULD_SKIP_THIS */ 282 283} // namespace Gtk 284