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.ShortcutsWindow;
26 
27 private import gobject.Signals;
28 private import gtk.Window;
29 public  import gtkc.gdktypes;
30 private import gtkc.gtk;
31 public  import gtkc.gtktypes;
32 private import std.algorithm;
33 
34 
35 /**
36  * A GtkShortcutsWindow shows brief information about the keyboard shortcuts
37  * and gestures of an application. The shortcuts can be grouped, and you can
38  * have multiple sections in this window, corresponding to the major modes of
39  * your application.
40  * 
41  * Additionally, the shortcuts can be filtered by the current view, to avoid
42  * showing information that is not relevant in the current application context.
43  * 
44  * The recommended way to construct a GtkShortcutsWindow is with GtkBuilder,
45  * by populating a #GtkShortcutsWindow with one or more #GtkShortcutsSection
46  * objects, which contain #GtkShortcutsGroups that in turn contain objects of
47  * class #GtkShortcutsShortcut.
48  * 
49  * # A simple example:
50  * 
51  * ![](gedit-shortcuts.png)
52  * 
53  * This example has as single section. As you can see, the shortcut groups
54  * are arranged in columns, and spread across several pages if there are too
55  * many to find on a single page.
56  * 
57  * The .ui file for this example can be found [here](https://git.gnome.org/browse/gtk+/tree/demos/gtk-demo/shortcuts-gedit.ui).
58  * 
59  * # An example with multiple views:
60  * 
61  * ![](clocks-shortcuts.png)
62  * 
63  * This example shows a #GtkShortcutsWindow that has been configured to show only
64  * the shortcuts relevant to the "stopwatch" view.
65  * 
66  * The .ui file for this example can be found [here](https://git.gnome.org/browse/gtk+/tree/demos/gtk-demo/shortcuts-clocks.ui).
67  * 
68  * # An example with multiple sections:
69  * 
70  * ![](builder-shortcuts.png)
71  * 
72  * This example shows a #GtkShortcutsWindow with two sections, "Editor Shortcuts"
73  * and "Terminal Shortcuts".
74  * 
75  * The .ui file for this example can be found [here](https://git.gnome.org/browse/gtk+/tree/demos/gtk-demo/shortcuts-builder.ui).
76  */
77 public class ShortcutsWindow : Window
78 {
79 	/** the main Gtk struct */
80 	protected GtkShortcutsWindow* gtkShortcutsWindow;
81 
82 	/** Get the main Gtk struct */
83 	public GtkShortcutsWindow* getShortcutsWindowStruct()
84 	{
85 		return gtkShortcutsWindow;
86 	}
87 
88 	/** the main Gtk struct as a void* */
89 	protected override void* getStruct()
90 	{
91 		return cast(void*)gtkShortcutsWindow;
92 	}
93 
94 	protected override void setStruct(GObject* obj)
95 	{
96 		gtkShortcutsWindow = cast(GtkShortcutsWindow*)obj;
97 		super.setStruct(obj);
98 	}
99 
100 	/**
101 	 * Sets our main struct and passes it to the parent class.
102 	 */
103 	public this (GtkShortcutsWindow* gtkShortcutsWindow, bool ownedRef = false)
104 	{
105 		this.gtkShortcutsWindow = gtkShortcutsWindow;
106 		super(cast(GtkWindow*)gtkShortcutsWindow, ownedRef);
107 	}
108 
109 
110 	/** */
111 	public static GType getType()
112 	{
113 		return gtk_shortcuts_window_get_type();
114 	}
115 
116 	protected class OnCloseDelegateWrapper
117 	{
118 		void delegate(ShortcutsWindow) dlg;
119 		gulong handlerId;
120 		ConnectFlags flags;
121 		this(void delegate(ShortcutsWindow) dlg, gulong handlerId, ConnectFlags flags)
122 		{
123 			this.dlg = dlg;
124 			this.handlerId = handlerId;
125 			this.flags = flags;
126 		}
127 	}
128 	protected OnCloseDelegateWrapper[] onCloseListeners;
129 
130 	/**
131 	 * The ::close signal is a
132 	 * [keybinding signal][GtkBindingSignal]
133 	 * which gets emitted when the user uses a keybinding to close
134 	 * the window.
135 	 *
136 	 * The default binding for this signal is the Escape key.
137 	 */
138 	gulong addOnClose(void delegate(ShortcutsWindow) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
139 	{
140 		onCloseListeners ~= new OnCloseDelegateWrapper(dlg, 0, connectFlags);
141 		onCloseListeners[onCloseListeners.length - 1].handlerId = Signals.connectData(
142 			this,
143 			"close",
144 			cast(GCallback)&callBackClose,
145 			cast(void*)onCloseListeners[onCloseListeners.length - 1],
146 			cast(GClosureNotify)&callBackCloseDestroy,
147 			connectFlags);
148 		return onCloseListeners[onCloseListeners.length - 1].handlerId;
149 	}
150 	
151 	extern(C) static void callBackClose(GtkShortcutsWindow* shortcutswindowStruct,OnCloseDelegateWrapper wrapper)
152 	{
153 		wrapper.dlg(wrapper.outer);
154 	}
155 	
156 	extern(C) static void callBackCloseDestroy(OnCloseDelegateWrapper wrapper, GClosure* closure)
157 	{
158 		wrapper.outer.internalRemoveOnClose(wrapper);
159 	}
160 
161 	protected void internalRemoveOnClose(OnCloseDelegateWrapper source)
162 	{
163 		foreach(index, wrapper; onCloseListeners)
164 		{
165 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
166 			{
167 				onCloseListeners[index] = null;
168 				onCloseListeners = std.algorithm.remove(onCloseListeners, index);
169 				break;
170 			}
171 		}
172 	}
173 	
174 
175 	protected class OnSearchDelegateWrapper
176 	{
177 		void delegate(ShortcutsWindow) dlg;
178 		gulong handlerId;
179 		ConnectFlags flags;
180 		this(void delegate(ShortcutsWindow) dlg, gulong handlerId, ConnectFlags flags)
181 		{
182 			this.dlg = dlg;
183 			this.handlerId = handlerId;
184 			this.flags = flags;
185 		}
186 	}
187 	protected OnSearchDelegateWrapper[] onSearchListeners;
188 
189 	/**
190 	 * The ::search signal is a
191 	 * [keybinding signal][GtkBindingSignal]
192 	 * which gets emitted when the user uses a keybinding to start a search.
193 	 *
194 	 * The default binding for this signal is Control-F.
195 	 */
196 	gulong addOnSearch(void delegate(ShortcutsWindow) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
197 	{
198 		onSearchListeners ~= new OnSearchDelegateWrapper(dlg, 0, connectFlags);
199 		onSearchListeners[onSearchListeners.length - 1].handlerId = Signals.connectData(
200 			this,
201 			"search",
202 			cast(GCallback)&callBackSearch,
203 			cast(void*)onSearchListeners[onSearchListeners.length - 1],
204 			cast(GClosureNotify)&callBackSearchDestroy,
205 			connectFlags);
206 		return onSearchListeners[onSearchListeners.length - 1].handlerId;
207 	}
208 	
209 	extern(C) static void callBackSearch(GtkShortcutsWindow* shortcutswindowStruct,OnSearchDelegateWrapper wrapper)
210 	{
211 		wrapper.dlg(wrapper.outer);
212 	}
213 	
214 	extern(C) static void callBackSearchDestroy(OnSearchDelegateWrapper wrapper, GClosure* closure)
215 	{
216 		wrapper.outer.internalRemoveOnSearch(wrapper);
217 	}
218 
219 	protected void internalRemoveOnSearch(OnSearchDelegateWrapper source)
220 	{
221 		foreach(index, wrapper; onSearchListeners)
222 		{
223 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
224 			{
225 				onSearchListeners[index] = null;
226 				onSearchListeners = std.algorithm.remove(onSearchListeners, index);
227 				break;
228 			}
229 		}
230 	}
231 	
232 }