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(bool transferOwnership = false) 79 { 80 if (transferOwnership) 81 ownedRef = false; 82 return gtkFileChooserButton; 83 } 84 85 /** the main Gtk struct as a void* */ 86 protected override void* getStruct() 87 { 88 return cast(void*)gtkFileChooserButton; 89 } 90 91 protected override void setStruct(GObject* obj) 92 { 93 gtkFileChooserButton = cast(GtkFileChooserButton*)obj; 94 super.setStruct(obj); 95 } 96 97 /** 98 * Sets our main struct and passes it to the parent class. 99 */ 100 public this (GtkFileChooserButton* gtkFileChooserButton, bool ownedRef = false) 101 { 102 this.gtkFileChooserButton = gtkFileChooserButton; 103 super(cast(GtkBox*)gtkFileChooserButton, ownedRef); 104 } 105 106 // add the FileChooser capabilities 107 mixin FileChooserT!(GtkFileChooserButton); 108 109 110 /** */ 111 public static GType getType() 112 { 113 return gtk_file_chooser_button_get_type(); 114 } 115 116 /** 117 * Creates a new file-selecting button widget. 118 * 119 * Params: 120 * title = the title of the browse dialog. 121 * action = the open mode for the widget. 122 * 123 * Returns: a new button widget. 124 * 125 * Since: 2.6 126 * 127 * Throws: ConstructionException GTK+ fails to create the object. 128 */ 129 public this(string title, GtkFileChooserAction action) 130 { 131 auto p = gtk_file_chooser_button_new(Str.toStringz(title), action); 132 133 if(p is null) 134 { 135 throw new ConstructionException("null returned by new"); 136 } 137 138 this(cast(GtkFileChooserButton*) p); 139 } 140 141 /** 142 * Creates a #GtkFileChooserButton widget which uses @dialog as its 143 * file-picking window. 144 * 145 * Note that @dialog must be a #GtkDialog (or subclass) which 146 * implements the #GtkFileChooser interface and must not have 147 * %GTK_DIALOG_DESTROY_WITH_PARENT set. 148 * 149 * Also note that the dialog needs to have its confirmative button 150 * added with response %GTK_RESPONSE_ACCEPT or %GTK_RESPONSE_OK in 151 * order for the button to take over the file selected in the dialog. 152 * 153 * Params: 154 * dialog = the widget to use as dialog 155 * 156 * Returns: a new button widget. 157 * 158 * Since: 2.6 159 * 160 * Throws: ConstructionException GTK+ fails to create the object. 161 */ 162 public this(Dialog dialog) 163 { 164 auto p = gtk_file_chooser_button_new_with_dialog((dialog is null) ? null : cast(GtkWidget*)dialog.getDialogStruct()); 165 166 if(p is null) 167 { 168 throw new ConstructionException("null returned by new_with_dialog"); 169 } 170 171 this(cast(GtkFileChooserButton*) p); 172 } 173 174 /** 175 * Returns whether the button grabs focus when it is clicked with the mouse. 176 * See gtk_file_chooser_button_set_focus_on_click(). 177 * 178 * Deprecated: Use gtk_widget_get_focus_on_click() instead 179 * 180 * Returns: %TRUE if the button grabs focus when it is clicked with 181 * the mouse. 182 * 183 * Since: 2.10 184 */ 185 public override bool getFocusOnClick() 186 { 187 return gtk_file_chooser_button_get_focus_on_click(gtkFileChooserButton) != 0; 188 } 189 190 /** 191 * Retrieves the title of the browse dialog used by @button. The returned value 192 * should not be modified or freed. 193 * 194 * Returns: a pointer to the browse dialog’s title. 195 * 196 * Since: 2.6 197 */ 198 public string getTitle() 199 { 200 return Str.toString(gtk_file_chooser_button_get_title(gtkFileChooserButton)); 201 } 202 203 /** 204 * Retrieves the width in characters of the @button widget’s entry and/or label. 205 * 206 * Returns: an integer width (in characters) that the button will use to size itself. 207 * 208 * Since: 2.6 209 */ 210 public int getWidthChars() 211 { 212 return gtk_file_chooser_button_get_width_chars(gtkFileChooserButton); 213 } 214 215 /** 216 * Sets whether the button will grab focus when it is clicked with the mouse. 217 * Making mouse clicks not grab focus is useful in places like toolbars where 218 * you don’t want the keyboard focus removed from the main area of the 219 * application. 220 * 221 * Deprecated: Use gtk_widget_set_focus_on_click() instead 222 * 223 * Params: 224 * focusOnClick = whether the button grabs focus when clicked with the mouse 225 * 226 * Since: 2.10 227 */ 228 public override void setFocusOnClick(bool focusOnClick) 229 { 230 gtk_file_chooser_button_set_focus_on_click(gtkFileChooserButton, focusOnClick); 231 } 232 233 /** 234 * Modifies the @title of the browse dialog used by @button. 235 * 236 * Params: 237 * title = the new browse dialog title. 238 * 239 * Since: 2.6 240 */ 241 public void setTitle(string title) 242 { 243 gtk_file_chooser_button_set_title(gtkFileChooserButton, Str.toStringz(title)); 244 } 245 246 /** 247 * Sets the width (in characters) that @button will use to @n_chars. 248 * 249 * Params: 250 * nChars = the new width, in characters. 251 * 252 * Since: 2.6 253 */ 254 public void setWidthChars(int nChars) 255 { 256 gtk_file_chooser_button_set_width_chars(gtkFileChooserButton, nChars); 257 } 258 259 protected class OnFileSetDelegateWrapper 260 { 261 void delegate(FileChooserButton) dlg; 262 gulong handlerId; 263 264 this(void delegate(FileChooserButton) dlg) 265 { 266 this.dlg = dlg; 267 onFileSetListeners ~= this; 268 } 269 270 void remove(OnFileSetDelegateWrapper source) 271 { 272 foreach(index, wrapper; onFileSetListeners) 273 { 274 if (wrapper.handlerId == source.handlerId) 275 { 276 onFileSetListeners[index] = null; 277 onFileSetListeners = std.algorithm.remove(onFileSetListeners, index); 278 break; 279 } 280 } 281 } 282 } 283 OnFileSetDelegateWrapper[] onFileSetListeners; 284 285 /** 286 * The ::file-set signal is emitted when the user selects a file. 287 * 288 * Note that this signal is only emitted when the user 289 * changes the file. 290 * 291 * Since: 2.12 292 */ 293 gulong addOnFileSet(void delegate(FileChooserButton) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 294 { 295 auto wrapper = new OnFileSetDelegateWrapper(dlg); 296 wrapper.handlerId = Signals.connectData( 297 this, 298 "file-set", 299 cast(GCallback)&callBackFileSet, 300 cast(void*)wrapper, 301 cast(GClosureNotify)&callBackFileSetDestroy, 302 connectFlags); 303 return wrapper.handlerId; 304 } 305 306 extern(C) static void callBackFileSet(GtkFileChooserButton* filechooserbuttonStruct, OnFileSetDelegateWrapper wrapper) 307 { 308 wrapper.dlg(wrapper.outer); 309 } 310 311 extern(C) static void callBackFileSetDestroy(OnFileSetDelegateWrapper wrapper, GClosure* closure) 312 { 313 wrapper.remove(wrapper); 314 } 315 }