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