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.StackList;
20 
21 private import dazzle.c.functions;
22 public  import dazzle.c.types;
23 private import gio.ListModelIF;
24 private import glib.ConstructionException;
25 private import gobject.ObjectG;
26 private import gobject.Signals;
27 private import gtk.Bin;
28 private import gtk.BuildableIF;
29 private import gtk.BuildableT;
30 private import gtk.ListBoxRow;
31 private import gtk.Widget;
32 private import std.algorithm;
33 
34 
35 /** */
36 public class StackList : Bin
37 {
38 	/** the main Gtk struct */
39 	protected DzlStackList* dzlStackList;
40 
41 	/** Get the main Gtk struct */
42 	public DzlStackList* getStackListStruct(bool transferOwnership = false)
43 	{
44 		if (transferOwnership)
45 			ownedRef = false;
46 		return dzlStackList;
47 	}
48 
49 	/** the main Gtk struct as a void* */
50 	protected override void* getStruct()
51 	{
52 		return cast(void*)dzlStackList;
53 	}
54 
55 	/**
56 	 * Sets our main struct and passes it to the parent class.
57 	 */
58 	public this (DzlStackList* dzlStackList, bool ownedRef = false)
59 	{
60 		this.dzlStackList = dzlStackList;
61 		super(cast(GtkBin*)dzlStackList, ownedRef);
62 	}
63 
64 
65 	/** */
66 	public static GType getType()
67 	{
68 		return dzl_stack_list_get_type();
69 	}
70 
71 	/** */
72 	public this()
73 	{
74 		auto p = dzl_stack_list_new();
75 
76 		if(p is null)
77 		{
78 			throw new ConstructionException("null returned by new");
79 		}
80 
81 		this(cast(DzlStackList*) p);
82 	}
83 
84 	/** */
85 	public void clear()
86 	{
87 		dzl_stack_list_clear(dzlStackList);
88 	}
89 
90 	/** */
91 	public uint getDepth()
92 	{
93 		return dzl_stack_list_get_depth(dzlStackList);
94 	}
95 
96 	/**
97 	 * Returns: An #DzlStackList.
98 	 */
99 	public ListModelIF getModel()
100 	{
101 		auto p = dzl_stack_list_get_model(dzlStackList);
102 
103 		if(p is null)
104 		{
105 			return null;
106 		}
107 
108 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) p);
109 	}
110 
111 	/** */
112 	public void pop()
113 	{
114 		dzl_stack_list_pop(dzlStackList);
115 	}
116 
117 	/** */
118 	public void push(Widget header, ListModelIF model, DzlStackListCreateWidgetFunc createWidgetFunc, void* userData, GDestroyNotify userDataFreeFunc)
119 	{
120 		dzl_stack_list_push(dzlStackList, (header is null) ? null : header.getWidgetStruct(), (model is null) ? null : model.getListModelStruct(), createWidgetFunc, userData, userDataFreeFunc);
121 	}
122 
123 	/** */
124 	gulong addOnHeaderActivated(void delegate(ListBoxRow, StackList) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
125 	{
126 		return Signals.connect(this, "header-activated", dlg, connectFlags ^ ConnectFlags.SWAPPED);
127 	}
128 
129 	/** */
130 	gulong addOnRowActivated(void delegate(ListBoxRow, StackList) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
131 	{
132 		return Signals.connect(this, "row-activated", dlg, connectFlags ^ ConnectFlags.SWAPPED);
133 	}
134 }