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 private import gtkc.gtk; 37 public import gtkc.gtktypes; 38 private import std.algorithm; 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 * Returns: 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 * Returns: 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 * Returns: %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 * Returns: 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 * Returns: 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 protected class OnFileSetDelegateWrapper 258 { 259 static OnFileSetDelegateWrapper[] listeners; 260 void delegate(FileChooserButton) dlg; 261 gulong handlerId; 262 263 this(void delegate(FileChooserButton) dlg) 264 { 265 this.dlg = dlg; 266 this.listeners ~= this; 267 } 268 269 void remove(OnFileSetDelegateWrapper source) 270 { 271 foreach(index, wrapper; listeners) 272 { 273 if (wrapper.handlerId == source.handlerId) 274 { 275 listeners[index] = null; 276 listeners = std.algorithm.remove(listeners, index); 277 break; 278 } 279 } 280 } 281 } 282 283 /** 284 * The ::file-set signal is emitted when the user selects a file. 285 * 286 * Note that this signal is only emitted when the user 287 * changes the file. 288 * 289 * Since: 2.12 290 */ 291 gulong addOnFileSet(void delegate(FileChooserButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 292 { 293 auto wrapper = new OnFileSetDelegateWrapper(dlg); 294 wrapper.handlerId = Signals.connectData( 295 this, 296 "file-set", 297 cast(GCallback)&callBackFileSet, 298 cast(void*)wrapper, 299 cast(GClosureNotify)&callBackFileSetDestroy, 300 connectFlags); 301 return wrapper.handlerId; 302 } 303 304 extern(C) static void callBackFileSet(GtkFileChooserButton* filechooserbuttonStruct, OnFileSetDelegateWrapper wrapper) 305 { 306 wrapper.dlg(wrapper.outer); 307 } 308 309 extern(C) static void callBackFileSetDestroy(OnFileSetDelegateWrapper wrapper, GClosure* closure) 310 { 311 wrapper.remove(wrapper); 312 } 313 }