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