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 	public static GType getType()
110 	{
111 		return gtk_file_chooser_button_get_type();
112 	}
113 
114 	/**
115 	 * Creates a new file-selecting button widget.
116 	 *
117 	 * Params:
118 	 *     title = the title of the browse dialog.
119 	 *     action = the open mode for the widget.
120 	 *
121 	 * Return: a new button widget.
122 	 *
123 	 * Since: 2.6
124 	 *
125 	 * Throws: ConstructionException GTK+ fails to create the object.
126 	 */
127 	public this(string title, GtkFileChooserAction action)
128 	{
129 		auto p = gtk_file_chooser_button_new(Str.toStringz(title), action);
130 		
131 		if(p is null)
132 		{
133 			throw new ConstructionException("null returned by new");
134 		}
135 		
136 		this(cast(GtkFileChooserButton*) p);
137 	}
138 
139 	/**
140 	 * Creates a #GtkFileChooserButton widget which uses @dialog as its
141 	 * file-picking window.
142 	 *
143 	 * Note that @dialog must be a #GtkDialog (or subclass) which
144 	 * implements the #GtkFileChooser interface and must not have
145 	 * %GTK_DIALOG_DESTROY_WITH_PARENT set.
146 	 *
147 	 * Also note that the dialog needs to have its confirmative button
148 	 * added with response %GTK_RESPONSE_ACCEPT or %GTK_RESPONSE_OK in
149 	 * order for the button to take over the file selected in the dialog.
150 	 *
151 	 * Params:
152 	 *     dialog = the widget to use as dialog
153 	 *
154 	 * Return: a new button widget.
155 	 *
156 	 * Since: 2.6
157 	 *
158 	 * Throws: ConstructionException GTK+ fails to create the object.
159 	 */
160 	public this(Dialog dialog)
161 	{
162 		auto p = gtk_file_chooser_button_new_with_dialog((dialog is null) ? null : cast(GtkWidget*)dialog.getDialogStruct());
163 		
164 		if(p is null)
165 		{
166 			throw new ConstructionException("null returned by new_with_dialog");
167 		}
168 		
169 		this(cast(GtkFileChooserButton*) p);
170 	}
171 
172 	/**
173 	 * Returns whether the button grabs focus when it is clicked with the mouse.
174 	 * See gtk_file_chooser_button_set_focus_on_click().
175 	 *
176 	 * Return: %TRUE if the button grabs focus when it is clicked with
177 	 *     the mouse.
178 	 *
179 	 * Since: 2.10
180 	 */
181 	public override bool getFocusOnClick()
182 	{
183 		return gtk_file_chooser_button_get_focus_on_click(gtkFileChooserButton) != 0;
184 	}
185 
186 	/**
187 	 * Retrieves the title of the browse dialog used by @button. The returned value
188 	 * should not be modified or freed.
189 	 *
190 	 * Return: a pointer to the browse dialog’s title.
191 	 *
192 	 * Since: 2.6
193 	 */
194 	public string getTitle()
195 	{
196 		return Str.toString(gtk_file_chooser_button_get_title(gtkFileChooserButton));
197 	}
198 
199 	/**
200 	 * Retrieves the width in characters of the @button widget’s entry and/or label.
201 	 *
202 	 * Return: an integer width (in characters) that the button will use to size itself.
203 	 *
204 	 * Since: 2.6
205 	 */
206 	public int getWidthChars()
207 	{
208 		return gtk_file_chooser_button_get_width_chars(gtkFileChooserButton);
209 	}
210 
211 	/**
212 	 * Sets whether the button will grab focus when it is clicked with the mouse.
213 	 * Making mouse clicks not grab focus is useful in places like toolbars where
214 	 * you don’t want the keyboard focus removed from the main area of the
215 	 * application.
216 	 *
217 	 * Params:
218 	 *     focusOnClick = whether the button grabs focus when clicked with the mouse
219 	 *
220 	 * Since: 2.10
221 	 */
222 	public override void setFocusOnClick(bool focusOnClick)
223 	{
224 		gtk_file_chooser_button_set_focus_on_click(gtkFileChooserButton, focusOnClick);
225 	}
226 
227 	/**
228 	 * Modifies the @title of the browse dialog used by @button.
229 	 *
230 	 * Params:
231 	 *     title = the new browse dialog title.
232 	 *
233 	 * Since: 2.6
234 	 */
235 	public void setTitle(string title)
236 	{
237 		gtk_file_chooser_button_set_title(gtkFileChooserButton, Str.toStringz(title));
238 	}
239 
240 	/**
241 	 * Sets the width (in characters) that @button will use to @n_chars.
242 	 *
243 	 * Params:
244 	 *     nChars = the new width, in characters.
245 	 *
246 	 * Since: 2.6
247 	 */
248 	public void setWidthChars(int nChars)
249 	{
250 		gtk_file_chooser_button_set_width_chars(gtkFileChooserButton, nChars);
251 	}
252 
253 	int[string] connectedSignals;
254 
255 	void delegate(FileChooserButton)[] onFileSetListeners;
256 	/**
257 	 * The ::file-set signal is emitted when the user selects a file.
258 	 *
259 	 * Note that this signal is only emitted when the user
260 	 * changes the file.
261 	 *
262 	 * Since: 2.12
263 	 */
264 	void addOnFileSet(void delegate(FileChooserButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
265 	{
266 		if ( "file-set" !in connectedSignals )
267 		{
268 			Signals.connectData(
269 				this,
270 				"file-set",
271 				cast(GCallback)&callBackFileSet,
272 				cast(void*)this,
273 				null,
274 				connectFlags);
275 			connectedSignals["file-set"] = 1;
276 		}
277 		onFileSetListeners ~= dlg;
278 	}
279 	extern(C) static void callBackFileSet(GtkFileChooserButton* filechooserbuttonStruct, FileChooserButton _filechooserbutton)
280 	{
281 		foreach ( void delegate(FileChooserButton) dlg; _filechooserbutton.onFileSetListeners )
282 		{
283 			dlg(_filechooserbutton);
284 		}
285 	}
286 }