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.SuggestionPopover;
20 
21 private import dazzle.Suggestion;
22 private import dazzle.c.functions;
23 public  import dazzle.c.types;
24 private import gio.ListModelIF;
25 private import glib.ConstructionException;
26 private import gobject.ObjectG;
27 private import gobject.Signals;
28 private import gtk.BuildableIF;
29 private import gtk.BuildableT;
30 private import gtk.Widget;
31 private import gtk.Window;
32 private import std.algorithm;
33 
34 
35 /** */
36 public class SuggestionPopover : Window
37 {
38 	/** the main Gtk struct */
39 	protected DzlSuggestionPopover* dzlSuggestionPopover;
40 
41 	/** Get the main Gtk struct */
42 	public DzlSuggestionPopover* getSuggestionPopoverStruct(bool transferOwnership = false)
43 	{
44 		if (transferOwnership)
45 			ownedRef = false;
46 		return dzlSuggestionPopover;
47 	}
48 
49 	/** the main Gtk struct as a void* */
50 	protected override void* getStruct()
51 	{
52 		return cast(void*)dzlSuggestionPopover;
53 	}
54 
55 	/**
56 	 * Sets our main struct and passes it to the parent class.
57 	 */
58 	public this (DzlSuggestionPopover* dzlSuggestionPopover, bool ownedRef = false)
59 	{
60 		this.dzlSuggestionPopover = dzlSuggestionPopover;
61 		super(cast(GtkWindow*)dzlSuggestionPopover, ownedRef);
62 	}
63 
64 
65 	/** */
66 	public static GType getType()
67 	{
68 		return dzl_suggestion_popover_get_type();
69 	}
70 
71 	/** */
72 	public this()
73 	{
74 		auto p = dzl_suggestion_popover_new();
75 
76 		if(p is null)
77 		{
78 			throw new ConstructionException("null returned by new");
79 		}
80 
81 		this(cast(DzlSuggestionPopover*) p);
82 	}
83 
84 	/** */
85 	public void activateSelected()
86 	{
87 		dzl_suggestion_popover_activate_selected(dzlSuggestionPopover);
88 	}
89 
90 	/**
91 	 * Gets the model being visualized.
92 	 *
93 	 * Returns: A #GListModel or %NULL.
94 	 */
95 	public ListModelIF getModel()
96 	{
97 		auto p = dzl_suggestion_popover_get_model(dzlSuggestionPopover);
98 
99 		if(p is null)
100 		{
101 			return null;
102 		}
103 
104 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) p);
105 	}
106 
107 	/**
108 	 * Returns: A #GtkWidget or %NULL.
109 	 */
110 	public Widget getRelativeTo()
111 	{
112 		auto p = dzl_suggestion_popover_get_relative_to(dzlSuggestionPopover);
113 
114 		if(p is null)
115 		{
116 			return null;
117 		}
118 
119 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
120 	}
121 
122 	/**
123 	 * Gets the currently selected suggestion.
124 	 *
125 	 * Returns: An #DzlSuggestion or %NULL.
126 	 */
127 	public Suggestion getSelected()
128 	{
129 		auto p = dzl_suggestion_popover_get_selected(dzlSuggestionPopover);
130 
131 		if(p is null)
132 		{
133 			return null;
134 		}
135 
136 		return ObjectG.getDObject!(Suggestion)(cast(DzlSuggestion*) p);
137 	}
138 
139 	/** */
140 	public void moveBy(int amount)
141 	{
142 		dzl_suggestion_popover_move_by(dzlSuggestionPopover, amount);
143 	}
144 
145 	/** */
146 	public void popdown()
147 	{
148 		dzl_suggestion_popover_popdown(dzlSuggestionPopover);
149 	}
150 
151 	/** */
152 	public void popup()
153 	{
154 		dzl_suggestion_popover_popup(dzlSuggestionPopover);
155 	}
156 
157 	/** */
158 	public void setModel(ListModelIF model)
159 	{
160 		dzl_suggestion_popover_set_model(dzlSuggestionPopover, (model is null) ? null : model.getListModelStruct());
161 	}
162 
163 	/** */
164 	public void setRelativeTo(Widget widget)
165 	{
166 		dzl_suggestion_popover_set_relative_to(dzlSuggestionPopover, (widget is null) ? null : widget.getWidgetStruct());
167 	}
168 
169 	/** */
170 	public void setSelected(Suggestion suggestion)
171 	{
172 		dzl_suggestion_popover_set_selected(dzlSuggestionPopover, (suggestion is null) ? null : suggestion.getSuggestionStruct());
173 	}
174 
175 	/** */
176 	gulong addOnSuggestionActivated(void delegate(Suggestion, SuggestionPopover) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
177 	{
178 		return Signals.connect(this, "suggestion-activated", dlg, connectFlags ^ ConnectFlags.SWAPPED);
179 	}
180 }