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.FileChooserNative;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gtk.FileChooserIF;
31 private import gtk.FileChooserT;
32 private import gtk.NativeDialog;
33 private import gtk.Window;
34 private import gtkc.gtk;
35 public  import gtkc.gtktypes;
36 
37 
38 /**
39  * #GtkFileChooserNative is an abstraction of a dialog box suitable
40  * for use with “File/Open” or “File/Save as” commands. By default, this
41  * just uses a #GtkFileChooserDialog to implement the actual dialog.
42  * However, on certain platforms, such as Windows, the native platform
43  * file chooser is uses instead.
44  * 
45  * While the API of #GtkFileChooserNative closely mirrors #GtkFileChooserDialog, the main
46  * difference is that there is no access to any #GtkWindow or #GtkWidget for the dialog.
47  * This is required, as there may not be one in the case of a platform native dialog.
48  * Showing, hiding and running the dialog is handled by the #GtkNativeDialog functions.
49  * 
50  * ## Typical usage ## {#gtkfilechoosernative-typical-usage}
51  * 
52  * In the simplest of cases, you can the following code to use
53  * #GtkFileChooserDialog to select a file for opening:
54  * 
55  * |[
56  * GtkFileChooserNative *native;
57  * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
58  * gint res;
59  * 
60  * native = gtk_file_chooser_native_new ("Open File",
61  * parent_window,
62  * action,
63  * "_Open",
64  * "_Cancel");
65  * 
66  * res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
67  * if (res == GTK_RESPONSE_ACCEPT)
68  * {
69  * char *filename;
70  * GtkFileChooser *chooser = GTK_FILE_CHOOSER (native);
71  * filename = gtk_file_chooser_get_filename (chooser);
72  * open_file (filename);
73  * g_free (filename);
74  * }
75  * 
76  * g_object_unref (native);
77  * ]|
78  * 
79  * To use a dialog for saving, you can use this:
80  * 
81  * |[
82  * GtkFileChooserNative *native;
83  * GtkFileChooser *chooser;
84  * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
85  * gint res;
86  * 
87  * native = gtk_file_chooser_native_new ("Save File",
88  * parent_window,
89  * action,
90  * "_Save",
91  * "_Cancel");
92  * chooser = GTK_FILE_CHOOSER (native);
93  * 
94  * gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
95  * 
96  * if (user_edited_a_new_document)
97  * gtk_file_chooser_set_current_name (chooser,
98  * _("Untitled document"));
99  * else
100  * gtk_file_chooser_set_filename (chooser,
101  * existing_filename);
102  * 
103  * res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
104  * if (res == GTK_RESPONSE_ACCEPT)
105  * {
106  * char *filename;
107  * 
108  * filename = gtk_file_chooser_get_filename (chooser);
109  * save_to_file (filename);
110  * g_free (filename);
111  * }
112  * 
113  * g_object_unref (native);
114  * ]|
115  * 
116  * For more information on how to best set up a file dialog, see #GtkFileChooserDialog.
117  * 
118  * ## Response Codes ## {#gtkfilechooserdialognative-responses}
119  * 
120  * #GtkFileChooserNative inherits from #GtkNativeDialog, which means it
121  * will return #GTK_RESPONSE_ACCEPT if the user accepted, and
122  * #GTK_RESPONSE_CANCEL if he pressed cancel. It can also return
123  * #GTK_RESPONSE_DELETE_EVENT if the window was unexpectedly closed.
124  * 
125  * ## Differences from #GtkFileChooserDialog ##  {#gtkfilechooserdialognative-differences}
126  * 
127  * There are a few things in the GtkFileChooser API that are not
128  * possible to use with #GtkFileChooserNative, as such use would
129  * prohibit the use of a native dialog.
130  * 
131  * There is no support for the signals that are emitted when the user
132  * navigates in the dialog, including:
133  * * #GtkFileChooser::current-folder-changed
134  * * #GtkFileChooser::selection-changed
135  * * #GtkFileChooser::file-activated
136  * * #GtkFileChooser::confirm-overwrite
137  * 
138  * You can also not use the methods that directly control user navigation:
139  * * gtk_file_chooser_unselect_filename()
140  * * gtk_file_chooser_select_all()
141  * * gtk_file_chooser_unselect_all()
142  * 
143  * If you need any of the above you will have to use #GtkFileChooserDialog directly.
144  * 
145  * No operations that change the the dialog work while the dialog is
146  * visible. Set all the properties that are required before showing the dialog.
147  * 
148  * ## Win32 details ## {#gtkfilechooserdialognative-win32}
149  * 
150  * On windows the IFileDialog implementation (added in Windows Vista) is
151  * used. It supports many of the features that #GtkFileChooserDialog
152  * does, but there are some things it does not handle:
153  * 
154  * * Extra widgets added with gtk_file_chooser_set_extra_widget().
155  * 
156  * * Use of custom previews by connecting to #GtkFileChooser::update-preview.
157  * 
158  * * Any #GtkFileFilter added using a mimetype or custom filter.
159  * 
160  * If any of these features are used the regular #GtkFileChooserDialog
161  * will be used in place of the native one.
162  */
163 public class FileChooserNative : NativeDialog, FileChooserIF
164 {
165 	/** the main Gtk struct */
166 	protected GtkFileChooserNative* gtkFileChooserNative;
167 
168 	/** Get the main Gtk struct */
169 	public GtkFileChooserNative* getFileChooserNativeStruct()
170 	{
171 		return gtkFileChooserNative;
172 	}
173 
174 	/** the main Gtk struct as a void* */
175 	protected override void* getStruct()
176 	{
177 		return cast(void*)gtkFileChooserNative;
178 	}
179 
180 	protected override void setStruct(GObject* obj)
181 	{
182 		gtkFileChooserNative = cast(GtkFileChooserNative*)obj;
183 		super.setStruct(obj);
184 	}
185 
186 	/**
187 	 * Sets our main struct and passes it to the parent class.
188 	 */
189 	public this (GtkFileChooserNative* gtkFileChooserNative, bool ownedRef = false)
190 	{
191 		this.gtkFileChooserNative = gtkFileChooserNative;
192 		super(cast(GtkNativeDialog*)gtkFileChooserNative, ownedRef);
193 	}
194 
195 	// add the FileChooser capabilities
196 	mixin FileChooserT!(GtkFileChooserNative);
197 
198 
199 	/** */
200 	public static GType getType()
201 	{
202 		return gtk_file_chooser_native_get_type();
203 	}
204 
205 	/**
206 	 * Creates a new #GtkFileChooserNative.
207 	 *
208 	 * Params:
209 	 *     title = Title of the native, or %NULL
210 	 *     parent = Transient parent of the native, or %NULL
211 	 *     action = Open or save mode for the dialog
212 	 *     acceptLabel = text to go in the accept button, or %NULL for the default
213 	 *     cancelLabel = text to go in the cancel button, or %NULL for the default
214 	 *
215 	 * Return: a new #GtkFileChooserNative
216 	 *
217 	 * Since: 3.20
218 	 *
219 	 * Throws: ConstructionException GTK+ fails to create the object.
220 	 */
221 	public this(string title, Window parent, GtkFileChooserAction action, string acceptLabel, string cancelLabel)
222 	{
223 		auto p = gtk_file_chooser_native_new(Str.toStringz(title), (parent is null) ? null : parent.getWindowStruct(), action, Str.toStringz(acceptLabel), Str.toStringz(cancelLabel));
224 		
225 		if(p is null)
226 		{
227 			throw new ConstructionException("null returned by new");
228 		}
229 		
230 		this(cast(GtkFileChooserNative*) p, true);
231 	}
232 
233 	/**
234 	 * Retrieves the custom label text for the accept button.
235 	 *
236 	 * Return: The custom label, or %NULL for the default. This string
237 	 *     is owned by GTK+ and should not be modified or freed
238 	 *
239 	 * Since: 3.20
240 	 */
241 	public string getAcceptLabel()
242 	{
243 		return Str.toString(gtk_file_chooser_native_get_accept_label(gtkFileChooserNative));
244 	}
245 
246 	/**
247 	 * Retrieves the custom label text for the cancel button.
248 	 *
249 	 * Return: The custom label, or %NULL for the default. This string
250 	 *     is owned by GTK+ and should not be modified or freed
251 	 *
252 	 * Since: 3.20
253 	 */
254 	public string getCancelLabel()
255 	{
256 		return Str.toString(gtk_file_chooser_native_get_cancel_label(gtkFileChooserNative));
257 	}
258 
259 	/**
260 	 * Sets the custom label text for the accept button.
261 	 *
262 	 * If characters in @label are preceded by an underscore, they are underlined.
263 	 * If you need a literal underscore character in a label, use “__” (two
264 	 * underscores). The first underlined character represents a keyboard
265 	 * accelerator called a mnemonic.
266 	 * Pressing Alt and that key activates the button.
267 	 *
268 	 * Params:
269 	 *     acceptLabel = custom label or %NULL for the default
270 	 *
271 	 * Since: 3.20
272 	 */
273 	public void setAcceptLabel(string acceptLabel)
274 	{
275 		gtk_file_chooser_native_set_accept_label(gtkFileChooserNative, Str.toStringz(acceptLabel));
276 	}
277 
278 	/**
279 	 * Sets the custom label text for the cancel button.
280 	 *
281 	 * If characters in @label are preceded by an underscore, they are underlined.
282 	 * If you need a literal underscore character in a label, use “__” (two
283 	 * underscores). The first underlined character represents a keyboard
284 	 * accelerator called a mnemonic.
285 	 * Pressing Alt and that key activates the button.
286 	 *
287 	 * Params:
288 	 *     cancelLabel = custom label or %NULL for the default
289 	 *
290 	 * Since: 3.20
291 	 */
292 	public void setCancelLabel(string cancelLabel)
293 	{
294 		gtk_file_chooser_native_set_cancel_label(gtkFileChooserNative, Str.toStringz(cancelLabel));
295 	}
296 }