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.PadController; 26 27 private import gdk.Device; 28 private import gio.ActionGroupIF; 29 private import glib.ConstructionException; 30 private import glib.Str; 31 private import gobject.ObjectG; 32 private import gtk.EventController; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 36 37 /** 38 * `GtkPadController` is an event controller for the pads found in drawing 39 * tablets. 40 * 41 * Pads are the collection of buttons and tactile sensors often found around 42 * the stylus-sensitive area. 43 * 44 * These buttons and sensors have no implicit meaning, and by default they 45 * perform no action. `GtkPadController` is provided to map those to 46 * `GAction` objects, thus letting the application give them a more 47 * semantic meaning. 48 * 49 * Buttons and sensors are not constrained to triggering a single action, 50 * some %GDK_SOURCE_TABLET_PAD devices feature multiple "modes". All these 51 * input elements have one current mode, which may determine the final action 52 * being triggered. 53 * 54 * Pad devices often divide buttons and sensors into groups. All elements 55 * in a group share the same current mode, but different groups may have 56 * different modes. See [method@Gdk.DevicePad.get_n_groups] and 57 * [method@Gdk.DevicePad.get_group_n_modes]. 58 * 59 * Each of the actions that a given button/strip/ring performs for a given 60 * mode is defined by a [struct@Gtk.PadActionEntry]. It contains an action 61 * name that will be looked up in the given `GActionGroup` and activated 62 * whenever the specified input element and mode are triggered. 63 * 64 * A simple example of `GtkPadController` usage: Assigning button 1 in all 65 * modes and pad devices to an "invert-selection" action: 66 * 67 * ```c 68 * GtkPadActionEntry *pad_actions[] = { 69 * { GTK_PAD_ACTION_BUTTON, 1, -1, "Invert selection", "pad-actions.invert-selection" }, 70 * … 71 * }; 72 * 73 * … 74 * action_group = g_simple_action_group_new (); 75 * action = g_simple_action_new ("pad-actions.invert-selection", NULL); 76 * g_signal_connect (action, "activate", on_invert_selection_activated, NULL); 77 * g_action_map_add_action (G_ACTION_MAP (action_group), action); 78 * … 79 * pad_controller = gtk_pad_controller_new (action_group, NULL); 80 * ``` 81 * 82 * The actions belonging to rings/strips will be activated with a parameter 83 * of type %G_VARIANT_TYPE_DOUBLE bearing the value of the given axis, it 84 * is required that those are made stateful and accepting this `GVariantType`. 85 */ 86 public class PadController : EventController 87 { 88 /** the main Gtk struct */ 89 protected GtkPadController* gtkPadController; 90 91 /** Get the main Gtk struct */ 92 public GtkPadController* getPadControllerStruct(bool transferOwnership = false) 93 { 94 if (transferOwnership) 95 ownedRef = false; 96 return gtkPadController; 97 } 98 99 /** the main Gtk struct as a void* */ 100 protected override void* getStruct() 101 { 102 return cast(void*)gtkPadController; 103 } 104 105 /** 106 * Sets our main struct and passes it to the parent class. 107 */ 108 public this (GtkPadController* gtkPadController, bool ownedRef = false) 109 { 110 this.gtkPadController = gtkPadController; 111 super(cast(GtkEventController*)gtkPadController, ownedRef); 112 } 113 114 115 /** */ 116 public static GType getType() 117 { 118 return gtk_pad_controller_get_type(); 119 } 120 121 /** 122 * Creates a new `GtkPadController` that will associate events from @pad to 123 * actions. 124 * 125 * A %NULL pad may be provided so the controller manages all pad devices 126 * generically, it is discouraged to mix `GtkPadController` objects with 127 * %NULL and non-%NULL @pad argument on the same toplevel window, as execution 128 * order is not guaranteed. 129 * 130 * The `GtkPadController` is created with no mapped actions. In order to 131 * map pad events to actions, use [method@Gtk.PadController.set_action_entries] 132 * or [method@Gtk.PadController.set_action]. 133 * 134 * Be aware that pad events will only be delivered to `GtkWindow`s, so adding 135 * a pad controller to any other type of widget will not have an effect. 136 * 137 * Params: 138 * group = `GActionGroup` to trigger actions from 139 * pad = A %GDK_SOURCE_TABLET_PAD device, or %NULL to handle all pads 140 * 141 * Returns: A newly created `GtkPadController` 142 * 143 * Throws: ConstructionException GTK+ fails to create the object. 144 */ 145 public this(ActionGroupIF group, Device pad) 146 { 147 auto __p = gtk_pad_controller_new((group is null) ? null : group.getActionGroupStruct(), (pad is null) ? null : pad.getDeviceStruct()); 148 149 if(__p is null) 150 { 151 throw new ConstructionException("null returned by new"); 152 } 153 154 this(cast(GtkPadController*) __p, true); 155 } 156 157 /** 158 * Adds an individual action to @controller. 159 * 160 * This action will only be activated if the given button/ring/strip number 161 * in @index is interacted while the current mode is @mode. -1 may be used 162 * for simple cases, so the action is triggered on all modes. 163 * 164 * The given @label should be considered user-visible, so internationalization 165 * rules apply. Some windowing systems may be able to use those for user 166 * feedback. 167 * 168 * Params: 169 * type = the type of pad feature that will trigger this action 170 * index = the 0-indexed button/ring/strip number that will trigger this action 171 * mode = the mode that will trigger this action, or -1 for all modes. 172 * label = Human readable description of this action, this string should 173 * be deemed user-visible. 174 * actionName = action name that will be activated in the #GActionGroup 175 */ 176 public void setAction(GtkPadActionType type, int index, int mode, string label, string actionName) 177 { 178 gtk_pad_controller_set_action(gtkPadController, type, index, mode, Str.toStringz(label), Str.toStringz(actionName)); 179 } 180 181 /** 182 * A convenience function to add a group of action entries on 183 * @controller. 184 * 185 * See [struct@Gtk.PadActionEntry] and [method@Gtk.PadController.set_action]. 186 * 187 * Params: 188 * entries = the action entries to set on @controller 189 */ 190 public void setActionEntries(GtkPadActionEntry[] entries) 191 { 192 gtk_pad_controller_set_action_entries(gtkPadController, entries.ptr, cast(int)entries.length); 193 } 194 }