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 public import gtkc.gdktypes; 33 private import gtkc.gtk; 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() 53 { 54 return gtkCellRendererText; 55 } 56 57 /** the main Gtk struct as a void* */ 58 protected override void* getStruct() 59 { 60 return cast(void*)gtkCellRendererText; 61 } 62 63 protected override void setStruct(GObject* obj) 64 { 65 gtkCellRendererText = cast(GtkCellRendererText*)obj; 66 super.setStruct(obj); 67 } 68 69 /** 70 * Sets our main struct and passes it to the parent class. 71 */ 72 public this (GtkCellRendererText* gtkCellRendererText, bool ownedRef = false) 73 { 74 this.gtkCellRendererText = gtkCellRendererText; 75 super(cast(GtkCellRenderer*)gtkCellRendererText, ownedRef); 76 } 77 78 79 /** */ 80 public static GType getType() 81 { 82 return gtk_cell_renderer_text_get_type(); 83 } 84 85 /** 86 * Creates a new #GtkCellRendererText. Adjust how text is drawn using 87 * object properties. Object properties can be 88 * set globally (with g_object_set()). Also, with #GtkTreeViewColumn, 89 * you can bind a property to a value in a #GtkTreeModel. For example, 90 * you can bind the “text” property on the cell renderer to a string 91 * value in the model, thus rendering a different string in each row 92 * of the #GtkTreeView 93 * 94 * Return: the new cell renderer 95 * 96 * Throws: ConstructionException GTK+ fails to create the object. 97 */ 98 public this() 99 { 100 auto p = gtk_cell_renderer_text_new(); 101 102 if(p is null) 103 { 104 throw new ConstructionException("null returned by new"); 105 } 106 107 this(cast(GtkCellRendererText*) p); 108 } 109 110 /** 111 * Sets the height of a renderer to explicitly be determined by the “font” and 112 * “y_pad” property set on it. Further changes in these properties do not 113 * affect the height, so they must be accompanied by a subsequent call to this 114 * function. Using this function is unflexible, and should really only be used 115 * if calculating the size of a cell is too slow (ie, a massive number of cells 116 * displayed). If @number_of_rows is -1, then the fixed height is unset, and 117 * the height is determined by the properties again. 118 * 119 * Params: 120 * numberOfRows = Number of rows of text each cell renderer is allocated, or -1 121 */ 122 public void setFixedHeightFromFont(int numberOfRows) 123 { 124 gtk_cell_renderer_text_set_fixed_height_from_font(gtkCellRendererText, numberOfRows); 125 } 126 127 protected class OnEditedDelegateWrapper 128 { 129 void delegate(string, string, CellRendererText) dlg; 130 gulong handlerId; 131 ConnectFlags flags; 132 this(void delegate(string, string, CellRendererText) dlg, gulong handlerId, ConnectFlags flags) 133 { 134 this.dlg = dlg; 135 this.handlerId = handlerId; 136 this.flags = flags; 137 } 138 } 139 protected OnEditedDelegateWrapper[] onEditedListeners; 140 141 /** 142 * This signal is emitted after @renderer has been edited. 143 * 144 * It is the responsibility of the application to update the model 145 * and store @new_text at the position indicated by @path. 146 * 147 * Params: 148 * path = the path identifying the edited cell 149 * newText = the new text 150 */ 151 gulong addOnEdited(void delegate(string, string, CellRendererText) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 152 { 153 onEditedListeners ~= new OnEditedDelegateWrapper(dlg, 0, connectFlags); 154 onEditedListeners[onEditedListeners.length - 1].handlerId = Signals.connectData( 155 this, 156 "edited", 157 cast(GCallback)&callBackEdited, 158 cast(void*)onEditedListeners[onEditedListeners.length - 1], 159 cast(GClosureNotify)&callBackEditedDestroy, 160 connectFlags); 161 return onEditedListeners[onEditedListeners.length - 1].handlerId; 162 } 163 164 extern(C) static void callBackEdited(GtkCellRendererText* cellrenderertextStruct, char* path, char* newText,OnEditedDelegateWrapper wrapper) 165 { 166 wrapper.dlg(Str.toString(path), Str.toString(newText), wrapper.outer); 167 } 168 169 extern(C) static void callBackEditedDestroy(OnEditedDelegateWrapper wrapper, GClosure* closure) 170 { 171 wrapper.outer.internalRemoveOnEdited(wrapper); 172 } 173 174 protected void internalRemoveOnEdited(OnEditedDelegateWrapper source) 175 { 176 foreach(index, wrapper; onEditedListeners) 177 { 178 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 179 { 180 onEditedListeners[index] = null; 181 onEditedListeners = std.algorithm.remove(onEditedListeners, index); 182 break; 183 } 184 } 185 } 186 187 }