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 * Deprecated: Use gtk_widget_get_focus_on_click() instead 177 * 178 * Return: %TRUE if the button grabs focus when it is clicked with 179 * the mouse. 180 * 181 * Since: 2.10 182 */ 183 public override bool getFocusOnClick() 184 { 185 return gtk_file_chooser_button_get_focus_on_click(gtkFileChooserButton) != 0; 186 } 187 188 /** 189 * Retrieves the title of the browse dialog used by @button. The returned value 190 * should not be modified or freed. 191 * 192 * Return: a pointer to the browse dialog’s title. 193 * 194 * Since: 2.6 195 */ 196 public string getTitle() 197 { 198 return Str.toString(gtk_file_chooser_button_get_title(gtkFileChooserButton)); 199 } 200 201 /** 202 * Retrieves the width in characters of the @button widget’s entry and/or label. 203 * 204 * Return: an integer width (in characters) that the button will use to size itself. 205 * 206 * Since: 2.6 207 */ 208 public int getWidthChars() 209 { 210 return gtk_file_chooser_button_get_width_chars(gtkFileChooserButton); 211 } 212 213 /** 214 * Sets whether the button will grab focus when it is clicked with the mouse. 215 * Making mouse clicks not grab focus is useful in places like toolbars where 216 * you don’t want the keyboard focus removed from the main area of the 217 * application. 218 * 219 * Deprecated: Use gtk_widget_set_focus_on_click() instead 220 * 221 * Params: 222 * focusOnClick = whether the button grabs focus when clicked with the mouse 223 * 224 * Since: 2.10 225 */ 226 public override void setFocusOnClick(bool focusOnClick) 227 { 228 gtk_file_chooser_button_set_focus_on_click(gtkFileChooserButton, focusOnClick); 229 } 230 231 /** 232 * Modifies the @title of the browse dialog used by @button. 233 * 234 * Params: 235 * title = the new browse dialog title. 236 * 237 * Since: 2.6 238 */ 239 public void setTitle(string title) 240 { 241 gtk_file_chooser_button_set_title(gtkFileChooserButton, Str.toStringz(title)); 242 } 243 244 /** 245 * Sets the width (in characters) that @button will use to @n_chars. 246 * 247 * Params: 248 * nChars = the new width, in characters. 249 * 250 * Since: 2.6 251 */ 252 public void setWidthChars(int nChars) 253 { 254 gtk_file_chooser_button_set_width_chars(gtkFileChooserButton, nChars); 255 } 256 257 int[string] connectedSignals; 258 259 void delegate(FileChooserButton)[] onFileSetListeners; 260 /** 261 * The ::file-set signal is emitted when the user selects a file. 262 * 263 * Note that this signal is only emitted when the user 264 * changes the file. 265 * 266 * Since: 2.12 267 */ 268 void addOnFileSet(void delegate(FileChooserButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 269 { 270 if ( "file-set" !in connectedSignals ) 271 { 272 Signals.connectData( 273 this, 274 "file-set", 275 cast(GCallback)&callBackFileSet, 276 cast(void*)this, 277 null, 278 connectFlags); 279 connectedSignals["file-set"] = 1; 280 } 281 onFileSetListeners ~= dlg; 282 } 283 extern(C) static void callBackFileSet(GtkFileChooserButton* filechooserbuttonStruct, FileChooserButton _filechooserbutton) 284 { 285 foreach ( void delegate(FileChooserButton) dlg; _filechooserbutton.onFileSetListeners ) 286 { 287 dlg(_filechooserbutton); 288 } 289 } 290 }