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.TreeBuilder; 20 21 private import dazzle.Tree; 22 private import dazzle.TreeNode; 23 private import dazzle.c.functions; 24 public import dazzle.c.types; 25 private import gio.Menu; 26 private import glib.ConstructionException; 27 private import gobject.ObjectG; 28 private import gobject.Signals; 29 private import gtk.SelectionData; 30 private import std.algorithm; 31 32 33 /** */ 34 public class TreeBuilder : ObjectG 35 { 36 /** the main Gtk struct */ 37 protected DzlTreeBuilder* dzlTreeBuilder; 38 39 /** Get the main Gtk struct */ 40 public DzlTreeBuilder* getTreeBuilderStruct(bool transferOwnership = false) 41 { 42 if (transferOwnership) 43 ownedRef = false; 44 return dzlTreeBuilder; 45 } 46 47 /** the main Gtk struct as a void* */ 48 protected override void* getStruct() 49 { 50 return cast(void*)dzlTreeBuilder; 51 } 52 53 /** 54 * Sets our main struct and passes it to the parent class. 55 */ 56 public this (DzlTreeBuilder* dzlTreeBuilder, bool ownedRef = false) 57 { 58 this.dzlTreeBuilder = dzlTreeBuilder; 59 super(cast(GObject*)dzlTreeBuilder, ownedRef); 60 } 61 62 63 /** */ 64 public static GType getType() 65 { 66 return dzl_tree_builder_get_type(); 67 } 68 69 /** */ 70 public this() 71 { 72 auto p = dzl_tree_builder_new(); 73 74 if(p is null) 75 { 76 throw new ConstructionException("null returned by new"); 77 } 78 79 this(cast(DzlTreeBuilder*) p); 80 } 81 82 /** 83 * Gets the tree that owns the builder. 84 * 85 * Returns: A #DzlTree or %NULL. 86 */ 87 public Tree getTree() 88 { 89 auto p = dzl_tree_builder_get_tree(dzlTreeBuilder); 90 91 if(p is null) 92 { 93 return null; 94 } 95 96 return ObjectG.getDObject!(Tree)(cast(DzlTree*) p); 97 } 98 99 /** */ 100 gulong addOnAdded(void delegate(Tree, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 101 { 102 return Signals.connect(this, "added", dlg, connectFlags ^ ConnectFlags.SWAPPED); 103 } 104 105 /** */ 106 gulong addOnBuildChildren(void delegate(TreeNode, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 107 { 108 return Signals.connect(this, "build-children", dlg, connectFlags ^ ConnectFlags.SWAPPED); 109 } 110 111 /** */ 112 gulong addOnBuildNode(void delegate(TreeNode, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 113 { 114 return Signals.connect(this, "build-node", dlg, connectFlags ^ ConnectFlags.SWAPPED); 115 } 116 117 /** */ 118 gulong addOnDragDataGet(bool delegate(TreeNode, SelectionData, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 119 { 120 return Signals.connect(this, "drag-data-get", dlg, connectFlags ^ ConnectFlags.SWAPPED); 121 } 122 123 /** */ 124 gulong addOnDragDataReceived(bool delegate(TreeNode, DzlTreeDropPosition, GdkDragAction, SelectionData, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 125 { 126 return Signals.connect(this, "drag-data-received", dlg, connectFlags ^ ConnectFlags.SWAPPED); 127 } 128 129 /** */ 130 gulong addOnDragNodeDelete(bool delegate(TreeNode, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 131 { 132 return Signals.connect(this, "drag-node-delete", dlg, connectFlags ^ ConnectFlags.SWAPPED); 133 } 134 135 /** */ 136 gulong addOnDragNodeReceived(bool delegate(TreeNode, TreeNode, DzlTreeDropPosition, GdkDragAction, SelectionData, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 137 { 138 return Signals.connect(this, "drag-node-received", dlg, connectFlags ^ ConnectFlags.SWAPPED); 139 } 140 141 /** */ 142 gulong addOnNodeActivated(bool delegate(TreeNode, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 143 { 144 return Signals.connect(this, "node-activated", dlg, connectFlags ^ ConnectFlags.SWAPPED); 145 } 146 147 /** */ 148 gulong addOnNodeCollapsed(void delegate(TreeNode, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 149 { 150 return Signals.connect(this, "node-collapsed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 151 } 152 153 /** */ 154 gulong addOnNodeDraggable(bool delegate(TreeNode, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 155 { 156 return Signals.connect(this, "node-draggable", dlg, connectFlags ^ ConnectFlags.SWAPPED); 157 } 158 159 /** */ 160 gulong addOnNodeDroppable(bool delegate(TreeNode, SelectionData, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 161 { 162 return Signals.connect(this, "node-droppable", dlg, connectFlags ^ ConnectFlags.SWAPPED); 163 } 164 165 /** */ 166 gulong addOnNodeExpanded(void delegate(TreeNode, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 167 { 168 return Signals.connect(this, "node-expanded", dlg, connectFlags ^ ConnectFlags.SWAPPED); 169 } 170 171 /** */ 172 gulong addOnNodePopup(void delegate(TreeNode, Menu, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 173 { 174 return Signals.connect(this, "node-popup", dlg, connectFlags ^ ConnectFlags.SWAPPED); 175 } 176 177 /** */ 178 gulong addOnNodeSelected(void delegate(TreeNode, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 179 { 180 return Signals.connect(this, "node-selected", dlg, connectFlags ^ ConnectFlags.SWAPPED); 181 } 182 183 /** */ 184 gulong addOnNodeUnselected(void delegate(TreeNode, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 185 { 186 return Signals.connect(this, "node-unselected", dlg, connectFlags ^ ConnectFlags.SWAPPED); 187 } 188 189 /** */ 190 gulong addOnRemoved(void delegate(Tree, TreeBuilder) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 191 { 192 return Signals.connect(this, "removed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 193 } 194 }