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.Tab;
20 
21 private import dazzle.Bin;
22 private import dazzle.c.functions;
23 public  import dazzle.c.types;
24 private import gio.IconIF;
25 private import glib.Str;
26 private import gobject.ObjectG;
27 private import gobject.Signals;
28 private import gtk.ActionableIF;
29 private import gtk.ActionableT;
30 private import gtk.Widget;
31 private import std.algorithm;
32 
33 
34 /** */
35 public class Tab : Bin, ActionableIF
36 {
37 	/** the main Gtk struct */
38 	protected DzlTab* dzlTab;
39 
40 	/** Get the main Gtk struct */
41 	public DzlTab* getTabStruct(bool transferOwnership = false)
42 	{
43 		if (transferOwnership)
44 			ownedRef = false;
45 		return dzlTab;
46 	}
47 
48 	/** the main Gtk struct as a void* */
49 	protected override void* getStruct()
50 	{
51 		return cast(void*)dzlTab;
52 	}
53 
54 	/**
55 	 * Sets our main struct and passes it to the parent class.
56 	 */
57 	public this (DzlTab* dzlTab, bool ownedRef = false)
58 	{
59 		this.dzlTab = dzlTab;
60 		super(cast(DzlBin*)dzlTab, ownedRef);
61 	}
62 
63 	// add the Actionable capabilities
64 	mixin ActionableT!(DzlTab);
65 
66 	alias getStyle = Widget.getStyle;
67 
68 	/** */
69 	public DzlTabStyle getStyle()
70 	{
71 		return dzl_tab_get_style(dzlTab);
72 	}
73 
74 	/**
75 	 */
76 
77 	/** */
78 	public static GType getType()
79 	{
80 		return dzl_tab_get_type();
81 	}
82 
83 	/** */
84 	public bool getActive()
85 	{
86 		return dzl_tab_get_active(dzlTab) != 0;
87 	}
88 
89 	/** */
90 	public bool getCanClose()
91 	{
92 		return dzl_tab_get_can_close(dzlTab) != 0;
93 	}
94 
95 	/** */
96 	public GtkPositionType getEdge()
97 	{
98 		return dzl_tab_get_edge(dzlTab);
99 	}
100 
101 	/** */
102 	public string getIconName()
103 	{
104 		return Str.toString(dzl_tab_get_icon_name(dzlTab));
105 	}
106 
107 	/** */
108 	public string getTitle()
109 	{
110 		return Str.toString(dzl_tab_get_title(dzlTab));
111 	}
112 
113 	/**
114 	 * Returns: A #GtkWidget or %NULL.
115 	 */
116 	public Widget getWidget()
117 	{
118 		auto p = dzl_tab_get_widget(dzlTab);
119 
120 		if(p is null)
121 		{
122 			return null;
123 		}
124 
125 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
126 	}
127 
128 	/** */
129 	public void setActive(bool active)
130 	{
131 		dzl_tab_set_active(dzlTab, active);
132 	}
133 
134 	/** */
135 	public void setCanClose(bool canClose)
136 	{
137 		dzl_tab_set_can_close(dzlTab, canClose);
138 	}
139 
140 	/** */
141 	public void setEdge(GtkPositionType edge)
142 	{
143 		dzl_tab_set_edge(dzlTab, edge);
144 	}
145 
146 	/** */
147 	public void setGicon(IconIF gicon)
148 	{
149 		dzl_tab_set_gicon(dzlTab, (gicon is null) ? null : gicon.getIconStruct());
150 	}
151 
152 	/** */
153 	public void setIconName(string iconName)
154 	{
155 		dzl_tab_set_icon_name(dzlTab, Str.toStringz(iconName));
156 	}
157 
158 	/** */
159 	public void setStyle(DzlTabStyle style)
160 	{
161 		dzl_tab_set_style(dzlTab, style);
162 	}
163 
164 	/** */
165 	public void setTitle(string title)
166 	{
167 		dzl_tab_set_title(dzlTab, Str.toStringz(title));
168 	}
169 
170 	/** */
171 	public void setWidget(Widget widget)
172 	{
173 		dzl_tab_set_widget(dzlTab, (widget is null) ? null : widget.getWidgetStruct());
174 	}
175 
176 	/** */
177 	gulong addOnClicked(void delegate(Tab) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
178 	{
179 		return Signals.connect(this, "clicked", dlg, connectFlags ^ ConnectFlags.SWAPPED);
180 	}
181 }