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