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.WidgetClass; 26 27 private import glib.Bytes; 28 private import glib.Str; 29 private import glib.VariantType; 30 private import glib.c.functions; 31 private import gtk.BuilderScopeIF; 32 private import gtk.Shortcut; 33 private import gtk.c.functions; 34 public import gtk.c.types; 35 36 37 /** */ 38 public class WidgetClass 39 { 40 /** the main Gtk struct */ 41 protected GtkWidgetClass* gtkWidgetClass; 42 protected bool ownedRef; 43 44 /** Get the main Gtk struct */ 45 public GtkWidgetClass* getWidgetClassStruct(bool transferOwnership = false) 46 { 47 if (transferOwnership) 48 ownedRef = false; 49 return gtkWidgetClass; 50 } 51 52 /** the main Gtk struct as a void* */ 53 protected void* getStruct() 54 { 55 return cast(void*)gtkWidgetClass; 56 } 57 58 /** 59 * Sets our main struct and passes it to the parent class. 60 */ 61 public this (GtkWidgetClass* gtkWidgetClass, bool ownedRef = false) 62 { 63 this.gtkWidgetClass = gtkWidgetClass; 64 this.ownedRef = ownedRef; 65 } 66 67 68 /** 69 * Installs a shortcut in @widget_class. 70 * 71 * Every instance created for @widget_class or its subclasses will 72 * inherit this shortcut and trigger it. 73 * 74 * Shortcuts added this way will be triggered in the %GTK_PHASE_BUBBLE 75 * phase, which means they may also trigger if child widgets have focus. 76 * 77 * This function must only be used in class initialization functions 78 * otherwise it is not guaranteed that the shortcut will be installed. 79 * 80 * Params: 81 * shortcut = the #GtkShortcut to add 82 */ 83 public void addShortcut(Shortcut shortcut) 84 { 85 gtk_widget_class_add_shortcut(gtkWidgetClass, (shortcut is null) ? null : shortcut.getShortcutStruct()); 86 } 87 88 /** 89 * Declares a @callback_symbol to handle @callback_name from 90 * the template XML defined for @widget_type. 91 * 92 * This function is not supported after [method@Gtk.WidgetClass.set_template_scope] 93 * has been used on @widget_class. See [method@Gtk.BuilderCScope.add_callback_symbol]. 94 * 95 * Note that this must be called from a composite widget classes 96 * class initializer after calling [method@Gtk.WidgetClass.set_template]. 97 * 98 * Params: 99 * callbackName = The name of the callback as expected in the template XML 100 * callbackSymbol = The callback symbol 101 */ 102 public void bindTemplateCallbackFull(string callbackName, GCallback callbackSymbol) 103 { 104 gtk_widget_class_bind_template_callback_full(gtkWidgetClass, Str.toStringz(callbackName), callbackSymbol); 105 } 106 107 /** 108 * Automatically assign an object declared in the class template XML to be 109 * set to a location on a freshly built instance’s private data, or 110 * alternatively accessible via [method@Gtk.Widget.get_template_child]. 111 * 112 * The struct can point either into the public instance, then you should 113 * use `G_STRUCT_OFFSET(WidgetType, member)` for @struct_offset, or in the 114 * private struct, then you should use `G_PRIVATE_OFFSET(WidgetType, member)`. 115 * 116 * An explicit strong reference will be held automatically for the duration 117 * of your instance’s life cycle, it will be released automatically when 118 * `GObjectClass.dispose()` runs on your instance and if a @struct_offset 119 * that is `!= 0` is specified, then the automatic location in your instance 120 * public or private data will be set to %NULL. You can however access an 121 * automated child pointer the first time your classes `GObjectClass.dispose()` 122 * runs, or alternatively in [signal@Gtk.Widget::destroy]. 123 * 124 * If @internal_child is specified, [vfunc@Gtk.Buildable.get_internal_child] 125 * will be automatically implemented by the `GtkWidget` class so there is no 126 * need to implement it manually. 127 * 128 * The wrapper macros [func@Gtk.widget_class_bind_template_child], 129 * [func@Gtk.widget_class_bind_template_child_internal], 130 * [func@Gtk.widget_class_bind_template_child_private] and 131 * [func@Gtk.widget_class_bind_template_child_internal_private] 132 * might be more convenient to use. 133 * 134 * Note that this must be called from a composite widget classes class 135 * initializer after calling [method@Gtk.WidgetClass.set_template]. 136 * 137 * Params: 138 * name = The “id” of the child defined in the template XML 139 * internalChild = Whether the child should be accessible as an “internal-child” 140 * when this class is used in GtkBuilder XML 141 * structOffset = The structure offset into the composite widget’s instance public or private structure 142 * where the automated child pointer should be set, or 0 to not assign the pointer. 143 */ 144 public void bindTemplateChildFull(string name, bool internalChild, ptrdiff_t structOffset) 145 { 146 gtk_widget_class_bind_template_child_full(gtkWidgetClass, Str.toStringz(name), internalChild, structOffset); 147 } 148 149 /** 150 * Retrieves the accessible role used by the given `GtkWidget` class. 151 * 152 * Different accessible roles have different states, and are rendered 153 * differently by assistive technologies. 154 * 155 * See also: [method@Gtk.Accessible.get_accessible_role]. 156 * 157 * Returns: the accessible role for the widget class 158 */ 159 public GtkAccessibleRole getAccessibleRole() 160 { 161 return gtk_widget_class_get_accessible_role(gtkWidgetClass); 162 } 163 164 /** 165 * Retrieves the signal id for the activation signal set using 166 * gtk_widget_class_set_activate_signal(). 167 * 168 * Returns: a signal id, or 0 if the widget class does not 169 * specify an activation signal 170 */ 171 public uint getActivateSignal() 172 { 173 return gtk_widget_class_get_activate_signal(gtkWidgetClass); 174 } 175 176 /** 177 * Gets the name used by this class for matching in CSS code. 178 * 179 * See gtk_widget_class_set_css_name() for details. 180 * 181 * Returns: the CSS name of the given class 182 */ 183 public string getCssName() 184 { 185 return Str.toString(gtk_widget_class_get_css_name(gtkWidgetClass)); 186 } 187 188 /** 189 * Retrieves the type of the [class@Gtk.LayoutManager] 190 * used by the `GtkWidget` class. 191 * 192 * See also: gtk_widget_class_set_layout_manager_type() 193 * 194 * Returns: type of a `GtkLayoutManager` subclass, or %G_TYPE_INVALID 195 */ 196 public GType getLayoutManagerType() 197 { 198 return gtk_widget_class_get_layout_manager_type(gtkWidgetClass); 199 } 200 201 /** 202 * This should be called at class initialization time to specify 203 * actions to be added for all instances of this class. 204 * 205 * Actions installed by this function are stateless. The only state 206 * they have is whether they are enabled or not. 207 * 208 * Params: 209 * actionName = a prefixed action name, such as "clipboard.paste" 210 * parameterType = the parameter type, or %NULL 211 * activate = callback to use when the action is activated 212 */ 213 public void installAction(string actionName, string parameterType, GtkWidgetActionActivateFunc activate) 214 { 215 gtk_widget_class_install_action(gtkWidgetClass, Str.toStringz(actionName), Str.toStringz(parameterType), activate); 216 } 217 218 /** 219 * Installs an action called @action_name on @widget_class and 220 * binds its state to the value of the @property_name property. 221 * 222 * This function will perform a few santity checks on the property selected 223 * via @property_name. Namely, the property must exist, must be readable, 224 * writable and must not be construct-only. There are also restrictions 225 * on the type of the given property, it must be boolean, int, unsigned int, 226 * double or string. If any of these conditions are not met, a critical 227 * warning will be printed and no action will be added. 228 * 229 * The state type of the action matches the property type. 230 * 231 * If the property is boolean, the action will have no parameter and 232 * toggle the property value. Otherwise, the action will have a parameter 233 * of the same type as the property. 234 * 235 * Params: 236 * actionName = name of the action 237 * propertyName = name of the property in instances of @widget_class 238 * or any parent class. 239 */ 240 public void installPropertyAction(string actionName, string propertyName) 241 { 242 gtk_widget_class_install_property_action(gtkWidgetClass, Str.toStringz(actionName), Str.toStringz(propertyName)); 243 } 244 245 /** 246 * Queries the actions that have been installed for 247 * a widget class using [method@Gtk.WidgetClass.install_action] 248 * during class initialization. 249 * 250 * Note that this function will also return actions defined 251 * by parent classes. You can identify those by looking 252 * at @owner. 253 * 254 * Params: 255 * index = position of the action to query 256 * owner = return location for the type where the action was defined 257 * actionName = return location for the action name 258 * parameterType = return location for the parameter type 259 * propertyName = return location for the property name 260 * 261 * Returns: %TRUE if the action was found, 262 * %FALSE if @index_ is out of range 263 */ 264 public bool queryAction(uint index, out GType owner, out string actionName, out VariantType parameterType, out string propertyName) 265 { 266 char* outactionName = null; 267 GVariantType* outparameterType = null; 268 char* outpropertyName = null; 269 270 auto __p = gtk_widget_class_query_action(gtkWidgetClass, index, &owner, &outactionName, &outparameterType, &outpropertyName) != 0; 271 272 actionName = Str.toString(outactionName); 273 parameterType = new VariantType(outparameterType); 274 propertyName = Str.toString(outpropertyName); 275 276 return __p; 277 } 278 279 /** 280 * Sets the accessible role used by the given `GtkWidget` class. 281 * 282 * Different accessible roles have different states, and are 283 * rendered differently by assistive technologies. 284 * 285 * Params: 286 * accessibleRole = the `GtkAccessibleRole` used by the @widget_class 287 */ 288 public void setAccessibleRole(GtkAccessibleRole accessibleRole) 289 { 290 gtk_widget_class_set_accessible_role(gtkWidgetClass, accessibleRole); 291 } 292 293 /** 294 * Sets the GtkWidgetClass.activate_signal field with the 295 * given @signal_id; the signal will be emitted when calling 296 * gtk_widget_activate(). 297 * 298 * The @signal_id must have been registered with g_signal_new() 299 * or g_signal_newv() before calling this function. 300 * 301 * Params: 302 * signalId = the id for the activate signal 303 */ 304 public void setActivateSignal(uint signalId) 305 { 306 gtk_widget_class_set_activate_signal(gtkWidgetClass, signalId); 307 } 308 309 /** 310 * Sets the GtkWidgetClass.activate_signal field with the signal id for 311 * the given @signal_name; the signal will be emitted when calling 312 * gtk_widget_activate(). 313 * 314 * The @signal_name of @widget_type must have been registered with 315 * g_signal_new() or g_signal_newv() before calling this function. 316 * 317 * Params: 318 * signalName = the name of the activate signal of @widget_type 319 */ 320 public void setActivateSignalFromName(string signalName) 321 { 322 gtk_widget_class_set_activate_signal_from_name(gtkWidgetClass, Str.toStringz(signalName)); 323 } 324 325 /** 326 * Sets the name to be used for CSS matching of widgets. 327 * 328 * If this function is not called for a given class, the name 329 * set on the parent class is used. By default, `GtkWidget` 330 * uses the name "widget". 331 * 332 * Params: 333 * name = name to use 334 */ 335 public void setCssName(string name) 336 { 337 gtk_widget_class_set_css_name(gtkWidgetClass, Str.toStringz(name)); 338 } 339 340 /** 341 * Sets the type to be used for creating layout managers for widgets of 342 * @widget_class. 343 * 344 * The given @type must be a subtype of [class@Gtk.LayoutManager]. 345 * 346 * This function should only be called from class init functions 347 * of widgets. 348 * 349 * Params: 350 * type = The object type that implements the `GtkLayoutManager` 351 * for @widget_class 352 */ 353 public void setLayoutManagerType(GType type) 354 { 355 gtk_widget_class_set_layout_manager_type(gtkWidgetClass, type); 356 } 357 358 /** 359 * This should be called at class initialization time to specify 360 * the `GtkBuilder` XML to be used to extend a widget. 361 * 362 * For convenience, [method@Gtk.WidgetClass.set_template_from_resource] 363 * is also provided. 364 * 365 * Note that any class that installs templates must call 366 * [method@Gtk.Widget.init_template] in the widget’s instance initializer. 367 * 368 * Params: 369 * templateBytes = A #GBytes holding the #GtkBuilder XML 370 */ 371 public void setTemplate(Bytes templateBytes) 372 { 373 gtk_widget_class_set_template(gtkWidgetClass, (templateBytes is null) ? null : templateBytes.getBytesStruct()); 374 } 375 376 /** 377 * A convenience function that calls [method@Gtk.WidgetClass.set_template] 378 * with the contents of a `GResource`. 379 * 380 * Note that any class that installs templates must call 381 * [method@Gtk.Widget.init_template] in the widget’s instance 382 * initializer. 383 * 384 * Params: 385 * resourceName = The name of the resource to load the template from 386 */ 387 public void setTemplateFromResource(string resourceName) 388 { 389 gtk_widget_class_set_template_from_resource(gtkWidgetClass, Str.toStringz(resourceName)); 390 } 391 392 /** 393 * For use in language bindings, this will override the default 394 * `GtkBuilderScope` to be used when parsing GtkBuilder XML from 395 * this class’s template data. 396 * 397 * Note that this must be called from a composite widget classes class 398 * initializer after calling gtk_widget_class_set_template(). 399 * 400 * Params: 401 * scope_ = The `GtkBuilderScope` to use when loading 402 * the class template 403 */ 404 public void setTemplateScope(BuilderScopeIF scope_) 405 { 406 gtk_widget_class_set_template_scope(gtkWidgetClass, (scope_ is null) ? null : scope_.getBuilderScopeStruct()); 407 } 408 }