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.Filter;
26 
27 private import gobject.ObjectG;
28 private import gobject.Signals;
29 private import gtk.c.functions;
30 public  import gtk.c.types;
31 private import std.algorithm;
32 
33 
34 /**
35  * A `GtkFilter` object describes the filtering to be performed by a
36  * `GtkFilterListModel`.
37  * 
38  * The model will use the filter to determine if it should include items
39  * or not by calling [method@Gtk.Filter.match] for each item and only
40  * keeping the ones that the function returns %TRUE for.
41  * 
42  * Filters may change what items they match through their lifetime. In that
43  * case, they will emit the [signal@Gtk.Filter::changed] signal to notify
44  * that previous filter results are no longer valid and that items should
45  * be checked again via [method@Gtk.Filter.match].
46  * 
47  * GTK provides various pre-made filter implementations for common filtering
48  * operations. These filters often include properties that can be linked to
49  * various widgets to easily allow searches.
50  * 
51  * However, in particular for large lists or complex search methods, it is
52  * also possible to subclass #GtkFilter and provide one's own filter.
53  */
54 public class Filter : ObjectG
55 {
56 	/** the main Gtk struct */
57 	protected GtkFilter* gtkFilter;
58 
59 	/** Get the main Gtk struct */
60 	public GtkFilter* getFilterStruct(bool transferOwnership = false)
61 	{
62 		if (transferOwnership)
63 			ownedRef = false;
64 		return gtkFilter;
65 	}
66 
67 	/** the main Gtk struct as a void* */
68 	protected override void* getStruct()
69 	{
70 		return cast(void*)gtkFilter;
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (GtkFilter* gtkFilter, bool ownedRef = false)
77 	{
78 		this.gtkFilter = gtkFilter;
79 		super(cast(GObject*)gtkFilter, ownedRef);
80 	}
81 
82 
83 	/** */
84 	public static GType getType()
85 	{
86 		return gtk_filter_get_type();
87 	}
88 
89 	/**
90 	 * Emits the #GtkFilter::changed signal to notify all users of the filter that
91 	 * the filter changed. Users of the filter should then check items again via
92 	 * gtk_filter_match().
93 	 *
94 	 * Depending on the @change parameter, not all items need to be changed, but
95 	 * only some. Refer to the #GtkFilterChange documentation for details.
96 	 *
97 	 * This function is intended for implementors of #GtkFilter subclasses and
98 	 * should not be called from other functions.
99 	 *
100 	 * Params:
101 	 *     change = How the filter changed
102 	 */
103 	public void changed(GtkFilterChange change)
104 	{
105 		gtk_filter_changed(gtkFilter, change);
106 	}
107 
108 	/**
109 	 * Gets the known strictness of @filters. If the strictness is not known,
110 	 * %GTK_FILTER_MATCH_SOME is returned.
111 	 *
112 	 * This value may change after emission of the #GtkFilter::changed signal.
113 	 *
114 	 * This function is meant purely for optimization purposes, filters can
115 	 * choose to omit implementing it, but #GtkFilterListModel uses it.
116 	 *
117 	 * Returns: the strictness of @self
118 	 */
119 	public GtkFilterMatch getStrictness()
120 	{
121 		return gtk_filter_get_strictness(gtkFilter);
122 	}
123 
124 	/**
125 	 * Checks if the given @item is matched by the filter or not.
126 	 *
127 	 * Params:
128 	 *     item = The item to check
129 	 *
130 	 * Returns: %TRUE if the filter matches the item and a filter model should
131 	 *     keep it, %FALSE if not.
132 	 */
133 	public bool match(ObjectG item)
134 	{
135 		return gtk_filter_match(gtkFilter, (item is null) ? null : item.getObjectGStruct()) != 0;
136 	}
137 
138 	/**
139 	 * Emitted whenever the filter changed.
140 	 *
141 	 * Users of the filter should then check items again via
142 	 * [method@Gtk.Filter.match].
143 	 *
144 	 * `GtkFilterListModel` handles this signal automatically.
145 	 *
146 	 * Depending on the @change parameter, not all items need
147 	 * to be checked, but only some. Refer to the [enum@Gtk.FilterChange]
148 	 * documentation for details.
149 	 *
150 	 * Params:
151 	 *     change = how the filter changed
152 	 */
153 	gulong addOnChanged(void delegate(GtkFilterChange, Filter) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
154 	{
155 		return Signals.connect(this, "changed", dlg, connectFlags ^ ConnectFlags.SWAPPED);
156 	}
157 }