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.AppChooserButton;
26 
27 private import gio.IconIF;
28 private import glib.ConstructionException;
29 private import glib.Str;
30 private import gobject.ObjectG;
31 private import gobject.Signals;
32 private import gtk.AppChooserIF;
33 private import gtk.AppChooserT;
34 private import gtk.ComboBox;
35 private import gtk.Widget;
36 private import gtk.c.functions;
37 public  import gtk.c.types;
38 public  import gtkc.gtktypes;
39 private import std.algorithm;
40 
41 
42 /**
43  * The #GtkAppChooserButton is a widget that lets the user select
44  * an application. It implements the #GtkAppChooser interface.
45  * 
46  * Initially, a #GtkAppChooserButton selects the first application
47  * in its list, which will either be the most-recently used application
48  * or, if #GtkAppChooserButton:show-default-item is %TRUE, the
49  * default application.
50  * 
51  * The list of applications shown in a #GtkAppChooserButton includes
52  * the recommended applications for the given content type. When
53  * #GtkAppChooserButton:show-default-item is set, the default application
54  * is also included. To let the user chooser other applications,
55  * you can set the #GtkAppChooserButton:show-dialog-item property,
56  * which allows to open a full #GtkAppChooserDialog.
57  * 
58  * It is possible to add custom items to the list, using
59  * gtk_app_chooser_button_append_custom_item(). These items cause
60  * the #GtkAppChooserButton::custom-item-activated signal to be
61  * emitted when they are selected.
62  * 
63  * To track changes in the selected application, use the
64  * #GtkComboBox::changed signal.
65  */
66 public class AppChooserButton : ComboBox, AppChooserIF
67 {
68 	/** the main Gtk struct */
69 	protected GtkAppChooserButton* gtkAppChooserButton;
70 
71 	/** Get the main Gtk struct */
72 	public GtkAppChooserButton* getAppChooserButtonStruct(bool transferOwnership = false)
73 	{
74 		if (transferOwnership)
75 			ownedRef = false;
76 		return gtkAppChooserButton;
77 	}
78 
79 	/** the main Gtk struct as a void* */
80 	protected override void* getStruct()
81 	{
82 		return cast(void*)gtkAppChooserButton;
83 	}
84 
85 	/**
86 	 * Sets our main struct and passes it to the parent class.
87 	 */
88 	public this (GtkAppChooserButton* gtkAppChooserButton, bool ownedRef = false)
89 	{
90 		this.gtkAppChooserButton = gtkAppChooserButton;
91 		super(cast(GtkComboBox*)gtkAppChooserButton, ownedRef);
92 	}
93 
94 	// add the AppChooser capabilities
95 	mixin AppChooserT!(GtkAppChooserButton);
96 
97 
98 	/** */
99 	public static GType getType()
100 	{
101 		return gtk_app_chooser_button_get_type();
102 	}
103 
104 	/**
105 	 * Creates a new #GtkAppChooserButton for applications
106 	 * that can handle content of the given type.
107 	 *
108 	 * Params:
109 	 *     contentType = the content type to show applications for
110 	 *
111 	 * Returns: a newly created #GtkAppChooserButton
112 	 *
113 	 * Since: 3.0
114 	 *
115 	 * Throws: ConstructionException GTK+ fails to create the object.
116 	 */
117 	public this(string contentType)
118 	{
119 		auto p = gtk_app_chooser_button_new(Str.toStringz(contentType));
120 
121 		if(p is null)
122 		{
123 			throw new ConstructionException("null returned by new");
124 		}
125 
126 		this(cast(GtkAppChooserButton*) p);
127 	}
128 
129 	/**
130 	 * Appends a custom item to the list of applications that is shown
131 	 * in the popup; the item name must be unique per-widget.
132 	 * Clients can use the provided name as a detail for the
133 	 * #GtkAppChooserButton::custom-item-activated signal, to add a
134 	 * callback for the activation of a particular custom item in the list.
135 	 * See also gtk_app_chooser_button_append_separator().
136 	 *
137 	 * Params:
138 	 *     name = the name of the custom item
139 	 *     label = the label for the custom item
140 	 *     icon = the icon for the custom item
141 	 *
142 	 * Since: 3.0
143 	 */
144 	public void appendCustomItem(string name, string label, IconIF icon)
145 	{
146 		gtk_app_chooser_button_append_custom_item(gtkAppChooserButton, Str.toStringz(name), Str.toStringz(label), (icon is null) ? null : icon.getIconStruct());
147 	}
148 
149 	/**
150 	 * Appends a separator to the list of applications that is shown
151 	 * in the popup.
152 	 *
153 	 * Since: 3.0
154 	 */
155 	public void appendSeparator()
156 	{
157 		gtk_app_chooser_button_append_separator(gtkAppChooserButton);
158 	}
159 
160 	/**
161 	 * Returns the text to display at the top of the dialog.
162 	 *
163 	 * Returns: the text to display at the top of the dialog,
164 	 *     or %NULL, in which case a default text is displayed
165 	 */
166 	public string getHeading()
167 	{
168 		return Str.toString(gtk_app_chooser_button_get_heading(gtkAppChooserButton));
169 	}
170 
171 	/**
172 	 * Returns the current value of the #GtkAppChooserButton:show-default-item
173 	 * property.
174 	 *
175 	 * Returns: the value of #GtkAppChooserButton:show-default-item
176 	 *
177 	 * Since: 3.2
178 	 */
179 	public bool getShowDefaultItem()
180 	{
181 		return gtk_app_chooser_button_get_show_default_item(gtkAppChooserButton) != 0;
182 	}
183 
184 	/**
185 	 * Returns the current value of the #GtkAppChooserButton:show-dialog-item
186 	 * property.
187 	 *
188 	 * Returns: the value of #GtkAppChooserButton:show-dialog-item
189 	 *
190 	 * Since: 3.0
191 	 */
192 	public bool getShowDialogItem()
193 	{
194 		return gtk_app_chooser_button_get_show_dialog_item(gtkAppChooserButton) != 0;
195 	}
196 
197 	/**
198 	 * Selects a custom item previously added with
199 	 * gtk_app_chooser_button_append_custom_item().
200 	 *
201 	 * Use gtk_app_chooser_refresh() to bring the selection
202 	 * to its initial state.
203 	 *
204 	 * Params:
205 	 *     name = the name of the custom item
206 	 *
207 	 * Since: 3.0
208 	 */
209 	public void setActiveCustomItem(string name)
210 	{
211 		gtk_app_chooser_button_set_active_custom_item(gtkAppChooserButton, Str.toStringz(name));
212 	}
213 
214 	/**
215 	 * Sets the text to display at the top of the dialog.
216 	 * If the heading is not set, the dialog displays a default text.
217 	 *
218 	 * Params:
219 	 *     heading = a string containing Pango markup
220 	 */
221 	public void setHeading(string heading)
222 	{
223 		gtk_app_chooser_button_set_heading(gtkAppChooserButton, Str.toStringz(heading));
224 	}
225 
226 	/**
227 	 * Sets whether the dropdown menu of this button should show the
228 	 * default application for the given content type at top.
229 	 *
230 	 * Params:
231 	 *     setting = the new value for #GtkAppChooserButton:show-default-item
232 	 *
233 	 * Since: 3.2
234 	 */
235 	public void setShowDefaultItem(bool setting)
236 	{
237 		gtk_app_chooser_button_set_show_default_item(gtkAppChooserButton, setting);
238 	}
239 
240 	/**
241 	 * Sets whether the dropdown menu of this button should show an
242 	 * entry to trigger a #GtkAppChooserDialog.
243 	 *
244 	 * Params:
245 	 *     setting = the new value for #GtkAppChooserButton:show-dialog-item
246 	 *
247 	 * Since: 3.0
248 	 */
249 	public void setShowDialogItem(bool setting)
250 	{
251 		gtk_app_chooser_button_set_show_dialog_item(gtkAppChooserButton, setting);
252 	}
253 
254 	/**
255 	 * Emitted when a custom item, previously added with
256 	 * gtk_app_chooser_button_append_custom_item(), is activated from the
257 	 * dropdown menu.
258 	 *
259 	 * Params:
260 	 *     itemName = the name of the activated item
261 	 */
262 	gulong addOnCustomItemActivated(void delegate(string, AppChooserButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
263 	{
264 		return Signals.connect(this, "custom-item-activated", dlg, connectFlags ^ ConnectFlags.SWAPPED);
265 	}
266 }