1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD 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 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.CellRendererText; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import gobject.ObjectG; 30 private import gobject.Signals; 31 private import gtk.CellRenderer; 32 private import gtk.c.functions; 33 public import gtk.c.types; 34 public import gtkc.gtktypes; 35 private import std.algorithm; 36 37 38 /** 39 * A #GtkCellRendererText renders a given text in its cell, using the font, color and 40 * style information provided by its properties. The text will be ellipsized if it is 41 * too long and the #GtkCellRendererText:ellipsize property allows it. 42 * 43 * If the #GtkCellRenderer:mode is %GTK_CELL_RENDERER_MODE_EDITABLE, 44 * the #GtkCellRendererText allows to edit its text using an entry. 45 */ 46 public class CellRendererText : CellRenderer 47 { 48 /** the main Gtk struct */ 49 protected GtkCellRendererText* gtkCellRendererText; 50 51 /** Get the main Gtk struct */ 52 public GtkCellRendererText* getCellRendererTextStruct(bool transferOwnership = false) 53 { 54 if (transferOwnership) 55 ownedRef = false; 56 return gtkCellRendererText; 57 } 58 59 /** the main Gtk struct as a void* */ 60 protected override void* getStruct() 61 { 62 return cast(void*)gtkCellRendererText; 63 } 64 65 protected override void setStruct(GObject* obj) 66 { 67 gtkCellRendererText = cast(GtkCellRendererText*)obj; 68 super.setStruct(obj); 69 } 70 71 /** 72 * Sets our main struct and passes it to the parent class. 73 */ 74 public this (GtkCellRendererText* gtkCellRendererText, bool ownedRef = false) 75 { 76 this.gtkCellRendererText = gtkCellRendererText; 77 super(cast(GtkCellRenderer*)gtkCellRendererText, ownedRef); 78 } 79 80 81 /** */ 82 public static GType getType() 83 { 84 return gtk_cell_renderer_text_get_type(); 85 } 86 87 /** 88 * Creates a new #GtkCellRendererText. Adjust how text is drawn using 89 * object properties. Object properties can be 90 * set globally (with g_object_set()). Also, with #GtkTreeViewColumn, 91 * you can bind a property to a value in a #GtkTreeModel. For example, 92 * you can bind the “text” property on the cell renderer to a string 93 * value in the model, thus rendering a different string in each row 94 * of the #GtkTreeView 95 * 96 * Returns: the new cell renderer 97 * 98 * Throws: ConstructionException GTK+ fails to create the object. 99 */ 100 public this() 101 { 102 auto p = gtk_cell_renderer_text_new(); 103 104 if(p is null) 105 { 106 throw new ConstructionException("null returned by new"); 107 } 108 109 this(cast(GtkCellRendererText*) p); 110 } 111 112 /** 113 * Sets the height of a renderer to explicitly be determined by the “font” and 114 * “y_pad” property set on it. Further changes in these properties do not 115 * affect the height, so they must be accompanied by a subsequent call to this 116 * function. Using this function is unflexible, and should really only be used 117 * if calculating the size of a cell is too slow (ie, a massive number of cells 118 * displayed). If @number_of_rows is -1, then the fixed height is unset, and 119 * the height is determined by the properties again. 120 * 121 * Params: 122 * numberOfRows = Number of rows of text each cell renderer is allocated, or -1 123 */ 124 public void setFixedHeightFromFont(int numberOfRows) 125 { 126 gtk_cell_renderer_text_set_fixed_height_from_font(gtkCellRendererText, numberOfRows); 127 } 128 129 protected class OnEditedDelegateWrapper 130 { 131 void delegate(string, string, CellRendererText) dlg; 132 gulong handlerId; 133 134 this(void delegate(string, string, CellRendererText) dlg) 135 { 136 this.dlg = dlg; 137 onEditedListeners ~= this; 138 } 139 140 void remove(OnEditedDelegateWrapper source) 141 { 142 foreach(index, wrapper; onEditedListeners) 143 { 144 if (wrapper.handlerId == source.handlerId) 145 { 146 onEditedListeners[index] = null; 147 onEditedListeners = std.algorithm.remove(onEditedListeners, index); 148 break; 149 } 150 } 151 } 152 } 153 OnEditedDelegateWrapper[] onEditedListeners; 154 155 /** 156 * This signal is emitted after @renderer has been edited. 157 * 158 * It is the responsibility of the application to update the model 159 * and store @new_text at the position indicated by @path. 160 * 161 * Params: 162 * path = the path identifying the edited cell 163 * newText = the new text 164 */ 165 gulong addOnEdited(void delegate(string, string, CellRendererText) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 166 { 167 auto wrapper = new OnEditedDelegateWrapper(dlg); 168 wrapper.handlerId = Signals.connectData( 169 this, 170 "edited", 171 cast(GCallback)&callBackEdited, 172 cast(void*)wrapper, 173 cast(GClosureNotify)&callBackEditedDestroy, 174 connectFlags); 175 return wrapper.handlerId; 176 } 177 178 extern(C) static void callBackEdited(GtkCellRendererText* cellrenderertextStruct, char* path, char* newText, OnEditedDelegateWrapper wrapper) 179 { 180 wrapper.dlg(Str.toString(path), Str.toString(newText), wrapper.outer); 181 } 182 183 extern(C) static void callBackEditedDestroy(OnEditedDelegateWrapper wrapper, GClosure* closure) 184 { 185 wrapper.remove(wrapper); 186 } 187 }