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 private import std.algorithm; 40 41 42 /** 43 * The #GtkFileChooserButton is a widget that lets the user select a 44 * file. It implements the #GtkFileChooser interface. Visually, it is a 45 * file name with a button to bring up a #GtkFileChooserDialog. 46 * The user can then use that dialog to change the file associated with 47 * that button. This widget does not support setting the 48 * #GtkFileChooser:select-multiple property to %TRUE. 49 * 50 * ## Create a button to let the user select a file in /etc 51 * 52 * |[<!-- language="C" --> 53 * { 54 * GtkWidget *button; 55 * 56 * button = gtk_file_chooser_button_new (_("Select a file"), 57 * GTK_FILE_CHOOSER_ACTION_OPEN); 58 * gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button), 59 * "/etc"); 60 * } 61 * ]| 62 * 63 * The #GtkFileChooserButton supports the #GtkFileChooserActions 64 * %GTK_FILE_CHOOSER_ACTION_OPEN and %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER. 65 * 66 * > The #GtkFileChooserButton will ellipsize the label, and will thus 67 * > request little horizontal space. To give the button more space, 68 * > you should call gtk_widget_get_preferred_size(), 69 * > gtk_file_chooser_button_set_width_chars(), or pack the button in 70 * > such a way that other interface elements give space to the 71 * > widget. 72 */ 73 public class FileChooserButton : Box, FileChooserIF 74 { 75 /** the main Gtk struct */ 76 protected GtkFileChooserButton* gtkFileChooserButton; 77 78 /** Get the main Gtk struct */ 79 public GtkFileChooserButton* getFileChooserButtonStruct() 80 { 81 return gtkFileChooserButton; 82 } 83 84 /** the main Gtk struct as a void* */ 85 protected override void* getStruct() 86 { 87 return cast(void*)gtkFileChooserButton; 88 } 89 90 protected override void setStruct(GObject* obj) 91 { 92 gtkFileChooserButton = cast(GtkFileChooserButton*)obj; 93 super.setStruct(obj); 94 } 95 96 /** 97 * Sets our main struct and passes it to the parent class. 98 */ 99 public this (GtkFileChooserButton* gtkFileChooserButton, bool ownedRef = false) 100 { 101 this.gtkFileChooserButton = gtkFileChooserButton; 102 super(cast(GtkBox*)gtkFileChooserButton, ownedRef); 103 } 104 105 // add the FileChooser capabilities 106 mixin FileChooserT!(GtkFileChooserButton); 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 * Deprecated: Use gtk_widget_get_focus_on_click() instead 178 * 179 * Return: %TRUE if the button grabs focus when it is clicked with 180 * the mouse. 181 * 182 * Since: 2.10 183 */ 184 public override bool getFocusOnClick() 185 { 186 return gtk_file_chooser_button_get_focus_on_click(gtkFileChooserButton) != 0; 187 } 188 189 /** 190 * Retrieves the title of the browse dialog used by @button. The returned value 191 * should not be modified or freed. 192 * 193 * Return: a pointer to the browse dialog’s title. 194 * 195 * Since: 2.6 196 */ 197 public string getTitle() 198 { 199 return Str.toString(gtk_file_chooser_button_get_title(gtkFileChooserButton)); 200 } 201 202 /** 203 * Retrieves the width in characters of the @button widget’s entry and/or label. 204 * 205 * Return: an integer width (in characters) that the button will use to size itself. 206 * 207 * Since: 2.6 208 */ 209 public int getWidthChars() 210 { 211 return gtk_file_chooser_button_get_width_chars(gtkFileChooserButton); 212 } 213 214 /** 215 * Sets whether the button will grab focus when it is clicked with the mouse. 216 * Making mouse clicks not grab focus is useful in places like toolbars where 217 * you don’t want the keyboard focus removed from the main area of the 218 * application. 219 * 220 * Deprecated: Use gtk_widget_set_focus_on_click() instead 221 * 222 * Params: 223 * focusOnClick = whether the button grabs focus when clicked with the mouse 224 * 225 * Since: 2.10 226 */ 227 public override void setFocusOnClick(bool focusOnClick) 228 { 229 gtk_file_chooser_button_set_focus_on_click(gtkFileChooserButton, focusOnClick); 230 } 231 232 /** 233 * Modifies the @title of the browse dialog used by @button. 234 * 235 * Params: 236 * title = the new browse dialog title. 237 * 238 * Since: 2.6 239 */ 240 public void setTitle(string title) 241 { 242 gtk_file_chooser_button_set_title(gtkFileChooserButton, Str.toStringz(title)); 243 } 244 245 /** 246 * Sets the width (in characters) that @button will use to @n_chars. 247 * 248 * Params: 249 * nChars = the new width, in characters. 250 * 251 * Since: 2.6 252 */ 253 public void setWidthChars(int nChars) 254 { 255 gtk_file_chooser_button_set_width_chars(gtkFileChooserButton, nChars); 256 } 257 258 protected class OnFileSetDelegateWrapper 259 { 260 void delegate(FileChooserButton) dlg; 261 gulong handlerId; 262 ConnectFlags flags; 263 this(void delegate(FileChooserButton) dlg, gulong handlerId, ConnectFlags flags) 264 { 265 this.dlg = dlg; 266 this.handlerId = handlerId; 267 this.flags = flags; 268 } 269 } 270 protected OnFileSetDelegateWrapper[] onFileSetListeners; 271 272 /** 273 * The ::file-set signal is emitted when the user selects a file. 274 * 275 * Note that this signal is only emitted when the user 276 * changes the file. 277 * 278 * Since: 2.12 279 */ 280 gulong addOnFileSet(void delegate(FileChooserButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 281 { 282 onFileSetListeners ~= new OnFileSetDelegateWrapper(dlg, 0, connectFlags); 283 onFileSetListeners[onFileSetListeners.length - 1].handlerId = Signals.connectData( 284 this, 285 "file-set", 286 cast(GCallback)&callBackFileSet, 287 cast(void*)onFileSetListeners[onFileSetListeners.length - 1], 288 cast(GClosureNotify)&callBackFileSetDestroy, 289 connectFlags); 290 return onFileSetListeners[onFileSetListeners.length - 1].handlerId; 291 } 292 293 extern(C) static void callBackFileSet(GtkFileChooserButton* filechooserbuttonStruct,OnFileSetDelegateWrapper wrapper) 294 { 295 wrapper.dlg(wrapper.outer); 296 } 297 298 extern(C) static void callBackFileSetDestroy(OnFileSetDelegateWrapper wrapper, GClosure* closure) 299 { 300 wrapper.outer.internalRemoveOnFileSet(wrapper); 301 } 302 303 protected void internalRemoveOnFileSet(OnFileSetDelegateWrapper source) 304 { 305 foreach(index, wrapper; onFileSetListeners) 306 { 307 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 308 { 309 onFileSetListeners[index] = null; 310 onFileSetListeners = std.algorithm.remove(onFileSetListeners, index); 311 break; 312 } 313 } 314 } 315 316 }