1 /* 2 * This file is part of d-dazzle. 3 * 4 * d-dazzle 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 * d-dazzle 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 d-dazzle; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 module dazzle.PropertiesGroup; 20 21 private import dazzle.c.functions; 22 public import dazzle.c.types; 23 private import gio.ActionGroupIF; 24 private import gio.ActionGroupT; 25 private import glib.ConstructionException; 26 private import glib.Str; 27 private import gobject.ObjectG; 28 29 30 /** */ 31 public class PropertiesGroup : ObjectG, ActionGroupIF 32 { 33 /** the main Gtk struct */ 34 protected DzlPropertiesGroup* dzlPropertiesGroup; 35 36 /** Get the main Gtk struct */ 37 public DzlPropertiesGroup* getPropertiesGroupStruct(bool transferOwnership = false) 38 { 39 if (transferOwnership) 40 ownedRef = false; 41 return dzlPropertiesGroup; 42 } 43 44 /** the main Gtk struct as a void* */ 45 protected override void* getStruct() 46 { 47 return cast(void*)dzlPropertiesGroup; 48 } 49 50 /** 51 * Sets our main struct and passes it to the parent class. 52 */ 53 public this (DzlPropertiesGroup* dzlPropertiesGroup, bool ownedRef = false) 54 { 55 this.dzlPropertiesGroup = dzlPropertiesGroup; 56 super(cast(GObject*)dzlPropertiesGroup, ownedRef); 57 } 58 59 // add the ActionGroup capabilities 60 mixin ActionGroupT!(DzlPropertiesGroup); 61 62 63 /** */ 64 public static GType getType() 65 { 66 return dzl_properties_group_get_type(); 67 } 68 69 /** 70 * This creates a new #DzlPropertiesGroup to create stateful actions 71 * around properties in @object. 72 * 73 * Call dzl_properties_group_add_property() to add a property to 74 * action name mapping for this group. Until you've called this, 75 * no actions are mapped. 76 * 77 * Note that #DzlPropertiesGroup only holds a weak reference to 78 * @object and therefore you must keep @object alive elsewhere. 79 * 80 * Params: 81 * object = The object containing the properties 82 * 83 * Returns: A #DzlPropertiesGroup 84 * 85 * Since: 3.26 86 * 87 * Throws: ConstructionException GTK+ fails to create the object. 88 */ 89 public this(ObjectG object) 90 { 91 auto p = dzl_properties_group_new((object is null) ? null : object.getObjectGStruct()); 92 93 if(p is null) 94 { 95 throw new ConstructionException("null returned by new"); 96 } 97 98 this(cast(DzlPropertiesGroup*) p, true); 99 } 100 101 /** 102 * This creates a new #DzlPropertiesGroup for which the initial object is 103 * %NULL. 104 * 105 * Set @object_type to a type of a class which is a #GObject-based type. 106 * 107 * Params: 108 * objectType = A #GObjectClass based type 109 * 110 * Returns: A #DzlPropertiesGroup. 111 * 112 * Throws: ConstructionException GTK+ fails to create the object. 113 */ 114 public this(GType objectType) 115 { 116 auto p = dzl_properties_group_new_for_type(objectType); 117 118 if(p is null) 119 { 120 throw new ConstructionException("null returned by new_for_type"); 121 } 122 123 this(cast(DzlPropertiesGroup*) p); 124 } 125 126 /** 127 * This function will try to add all properties found on the target 128 * instance to the group. Only properties that are supported by the 129 * #DzlPropertiesGroup will be added. 130 * 131 * The action name of all added properties will be identical to their 132 * property name. 133 * 134 * Since: 3.26 135 */ 136 public void addAllProperties() 137 { 138 dzl_properties_group_add_all_properties(dzlPropertiesGroup); 139 } 140 141 /** 142 * Adds a new stateful action named @name which maps to the underlying 143 * property @property_name of #DzlPropertiesGroup:object. 144 * 145 * Params: 146 * name = the name of the action 147 * propertyName = the name of the property 148 * 149 * Since: 3.26 150 */ 151 public void addProperty(string name, string propertyName) 152 { 153 dzl_properties_group_add_property(dzlPropertiesGroup, Str.toStringz(name), Str.toStringz(propertyName)); 154 } 155 156 /** 157 * Adds a new stateful action named @name which maps to the underlying 158 * property @property_name of #DzlPropertiesGroup:object. 159 * 160 * Seting @flags allows you to tweak some settings about the action. 161 * 162 * Params: 163 * name = the name of the action 164 * propertyName = the name of the property 165 * flags = optional flags for the action 166 * 167 * Since: 3.26 168 */ 169 public void addPropertyFull(string name, string propertyName, DzlPropertiesFlags flags) 170 { 171 dzl_properties_group_add_property_full(dzlPropertiesGroup, Str.toStringz(name), Str.toStringz(propertyName), flags); 172 } 173 174 /** 175 * Removes an action from @self that was previously added with 176 * dzl_properties_group_add_property(). @name should match the 177 * name parameter to that function. 178 * 179 * Params: 180 * name = the name of the action 181 * 182 * Since: 3.26 183 */ 184 public void remove(string name) 185 { 186 dzl_properties_group_remove(dzlPropertiesGroup, Str.toStringz(name)); 187 } 188 }