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.FileChooserButton;
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.Box;
32 private import gtk.Dialog;
33 private import gtk.FileChooserIF;
34 private import gtk.FileChooserT;
35 private import gtk.Widget;
36 public  import gtkc.gdktypes;
37 private import gtkc.gtk;
38 public  import gtkc.gtktypes;
39 
40 
41 /**
42  * The #GtkFileChooserButton is a widget that lets the user select a
43  * file.  It implements the #GtkFileChooser interface.  Visually, it is a
44  * file name with a button to bring up a #GtkFileChooserDialog.
45  * The user can then use that dialog to change the file associated with
46  * that button.  This widget does not support setting the
47  * #GtkFileChooser:select-multiple property to %TRUE.
48  * 
49  * ## Create a button to let the user select a file in /etc
50  * 
51  * |[<!-- language="C" -->
52  * {
53  * GtkWidget *button;
54  * 
55  * button = gtk_file_chooser_button_new (_("Select a file"),
56  * GTK_FILE_CHOOSER_ACTION_OPEN);
57  * gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button),
58  * "/etc");
59  * }
60  * ]|
61  * 
62  * The #GtkFileChooserButton supports the #GtkFileChooserActions
63  * %GTK_FILE_CHOOSER_ACTION_OPEN and %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
64  * 
65  * > The #GtkFileChooserButton will ellipsize the label, and will thus
66  * > request little horizontal space.  To give the button more space,
67  * > you should call gtk_widget_get_preferred_size(),
68  * > gtk_file_chooser_button_set_width_chars(), or pack the button in
69  * > such a way that other interface elements give space to the
70  * > widget.
71  */
72 public class FileChooserButton : Box, FileChooserIF
73 {
74 	/** the main Gtk struct */
75 	protected GtkFileChooserButton* gtkFileChooserButton;
76 
77 	/** Get the main Gtk struct */
78 	public GtkFileChooserButton* getFileChooserButtonStruct()
79 	{
80 		return gtkFileChooserButton;
81 	}
82 
83 	/** the main Gtk struct as a void* */
84 	protected override void* getStruct()
85 	{
86 		return cast(void*)gtkFileChooserButton;
87 	}
88 
89 	protected override void setStruct(GObject* obj)
90 	{
91 		gtkFileChooserButton = cast(GtkFileChooserButton*)obj;
92 		super.setStruct(obj);
93 	}
94 
95 	/**
96 	 * Sets our main struct and passes it to the parent class.
97 	 */
98 	public this (GtkFileChooserButton* gtkFileChooserButton, bool ownedRef = false)
99 	{
100 		this.gtkFileChooserButton = gtkFileChooserButton;
101 		super(cast(GtkBox*)gtkFileChooserButton, ownedRef);
102 	}
103 
104 	// add the FileChooser capabilities
105 	mixin FileChooserT!(GtkFileChooserButton);
106 
107 	/**
108 	 */
109 
110 	public static GType getType()
111 	{
112 		return gtk_file_chooser_button_get_type();
113 	}
114 
115 	/**
116 	 * Creates a new file-selecting button widget.
117 	 *
118 	 * Params:
119 	 *     title = the title of the browse dialog.
120 	 *     action = the open mode for the widget.
121 	 *
122 	 * Return: a new button widget.
123 	 *
124 	 * Since: 2.6
125 	 *
126 	 * Throws: ConstructionException GTK+ fails to create the object.
127 	 */
128 	public this(string title, GtkFileChooserAction action)
129 	{
130 		auto p = gtk_file_chooser_button_new(Str.toStringz(title), action);
131 		
132 		if(p is null)
133 		{
134 			throw new ConstructionException("null returned by new");
135 		}
136 		
137 		this(cast(GtkFileChooserButton*) p);
138 	}
139 
140 	/**
141 	 * Creates a #GtkFileChooserButton widget which uses @dialog as its
142 	 * file-picking window.
143 	 *
144 	 * Note that @dialog must be a #GtkDialog (or subclass) which
145 	 * implements the #GtkFileChooser interface and must not have
146 	 * %GTK_DIALOG_DESTROY_WITH_PARENT set.
147 	 *
148 	 * Also note that the dialog needs to have its confirmative button
149 	 * added with response %GTK_RESPONSE_ACCEPT or %GTK_RESPONSE_OK in
150 	 * order for the button to take over the file selected in the dialog.
151 	 *
152 	 * Params:
153 	 *     dialog = the widget to use as dialog
154 	 *
155 	 * Return: a new button widget.
156 	 *
157 	 * Since: 2.6
158 	 *
159 	 * Throws: ConstructionException GTK+ fails to create the object.
160 	 */
161 	public this(Dialog dialog)
162 	{
163 		auto p = gtk_file_chooser_button_new_with_dialog((dialog is null) ? null : cast(GtkWidget*)dialog.getDialogStruct());
164 		
165 		if(p is null)
166 		{
167 			throw new ConstructionException("null returned by new_with_dialog");
168 		}
169 		
170 		this(cast(GtkFileChooserButton*) p);
171 	}
172 
173 	/**
174 	 * Returns whether the button grabs focus when it is clicked with the mouse.
175 	 * See gtk_file_chooser_button_set_focus_on_click().
176 	 *
177 	 * Return: %TRUE if the button grabs focus when it is clicked with
178 	 *     the mouse.
179 	 *
180 	 * Since: 2.10
181 	 */
182 	public bool getFocusOnClick()
183 	{
184 		return gtk_file_chooser_button_get_focus_on_click(gtkFileChooserButton) != 0;
185 	}
186 
187 	/**
188 	 * Retrieves the title of the browse dialog used by @button. The returned value
189 	 * should not be modified or freed.
190 	 *
191 	 * Return: a pointer to the browse dialog’s title.
192 	 *
193 	 * Since: 2.6
194 	 */
195 	public string getTitle()
196 	{
197 		return Str.toString(gtk_file_chooser_button_get_title(gtkFileChooserButton));
198 	}
199 
200 	/**
201 	 * Retrieves the width in characters of the @button widget’s entry and/or label.
202 	 *
203 	 * Return: an integer width (in characters) that the button will use to size itself.
204 	 *
205 	 * Since: 2.6
206 	 */
207 	public int getWidthChars()
208 	{
209 		return gtk_file_chooser_button_get_width_chars(gtkFileChooserButton);
210 	}
211 
212 	/**
213 	 * Sets whether the button will grab focus when it is clicked with the mouse.
214 	 * Making mouse clicks not grab focus is useful in places like toolbars where
215 	 * you don’t want the keyboard focus removed from the main area of the
216 	 * application.
217 	 *
218 	 * Params:
219 	 *     focusOnClick = whether the button grabs focus when clicked with the mouse
220 	 *
221 	 * Since: 2.10
222 	 */
223 	public void setFocusOnClick(bool focusOnClick)
224 	{
225 		gtk_file_chooser_button_set_focus_on_click(gtkFileChooserButton, focusOnClick);
226 	}
227 
228 	/**
229 	 * Modifies the @title of the browse dialog used by @button.
230 	 *
231 	 * Params:
232 	 *     title = the new browse dialog title.
233 	 *
234 	 * Since: 2.6
235 	 */
236 	public void setTitle(string title)
237 	{
238 		gtk_file_chooser_button_set_title(gtkFileChooserButton, Str.toStringz(title));
239 	}
240 
241 	/**
242 	 * Sets the width (in characters) that @button will use to @n_chars.
243 	 *
244 	 * Params:
245 	 *     nChars = the new width, in characters.
246 	 *
247 	 * Since: 2.6
248 	 */
249 	public void setWidthChars(int nChars)
250 	{
251 		gtk_file_chooser_button_set_width_chars(gtkFileChooserButton, nChars);
252 	}
253 
254 	int[string] connectedSignals;
255 
256 	void delegate(FileChooserButton)[] onFileSetListeners;
257 	/**
258 	 * The ::file-set signal is emitted when the user selects a file.
259 	 *
260 	 * Note that this signal is only emitted when the user
261 	 * changes the file.
262 	 *
263 	 * Since: 2.12
264 	 */
265 	void addOnFileSet(void delegate(FileChooserButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
266 	{
267 		if ( "file-set" !in connectedSignals )
268 		{
269 			Signals.connectData(
270 				this,
271 				"file-set",
272 				cast(GCallback)&callBackFileSet,
273 				cast(void*)this,
274 				null,
275 				connectFlags);
276 			connectedSignals["file-set"] = 1;
277 		}
278 		onFileSetListeners ~= dlg;
279 	}
280 	extern(C) static void callBackFileSet(GtkFileChooserButton* filechooserbuttonStruct, FileChooserButton _filechooserbutton)
281 	{
282 		foreach ( void delegate(FileChooserButton) dlg; _filechooserbutton.onFileSetListeners )
283 		{
284 			dlg(_filechooserbutton);
285 		}
286 	}
287 }