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