I've no idea here...
[gtkD.git] / src / gtk / Idle.d
blob88d3a9a894bc262d02568deb2b1e5561e11753e7
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile =
26 * outPack = gtk
27 * outFile = Idle
28 * strct =
29 * realStrct=
30 * ctorStrct=
31 * clss = Idle
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_idle_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * structWrap:
45 * local aliases:
48 module gtk.Idle;
50 private import gtk.gtktypes;
52 private import lib.gtk;
55 /**
56 * Description
57 * Before using GTK+, you need to initialize it; initialization connects
58 * to the window system display, and parses some standard command line
59 * arguments. The gtk_init() function initializes GTK+. gtk_init() exits
60 * the application if errors occur; to avoid this, use gtk_init_check().
61 * gtk_init_check() allows you to recover from a failed GTK+
62 * initialization - you might start up your application in text mode instead.
63 * Like all GUI toolkits, GTK+ uses an event-driven programming
64 * model. When the user is doing nothing, GTK+ sits in the
65 * main loop and waits for input. If the user
66 * performs some action - say, a mouse click - then the main loop "wakes
67 * up" and delivers an event to GTK+. GTK+ forwards the event to one or
68 * more widgets.
69 * When widgets receive an event, they frequently emit one or more
70 * signals. Signals notify your program that
71 * "something interesting happened" by invoking functions you've
72 * connected to the signal with g_signal_connect(). Functions connected
73 * to a signal are often termed callbacks.
74 * When your callbacks are invoked, you would typically take some action
75 * - for example, when an Open button is clicked you might display a
76 * GtkFileSelectionDialog. After a callback finishes, GTK+ will return
77 * to the main loop and await more user input.
78 * Example1.Typical main function for a GTK+ application
79 * int
80 * main (int argc, char **argv)
81 * {
82 * /+* Initialize i18n support +/
83 * gtk_set_locale ();
84 * /+* Initialize the widget set +/
85 * gtk_init (argc, argv);
86 * /+* Create the main window +/
87 * mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
88 * /+* Set up our GUI elements +/
89 * ...
90 * /+* Show the application window +/
91 * gtk_widget_show_all (mainwin);
92 * /+* Enter the main event loop, and wait for user interaction +/
93 * gtk_main ();
94 * /+* The user lost interest +/
95 * return 0;
96 * }
97 * It's OK to use the GLib main loop directly instead of gtk_main(),
98 * though it involves slightly more typing. See GMainLoop in the GLib
99 * documentation.
101 public class Idle
104 /** Holds all idle delegates */
105 bit delegate()[] idleListeners;
106 /** our gtk idle ID */
107 uint idleID;
110 * Creates a new idle cycle.
111 * Params:
112 * interval = the idle in milieconds
113 * delegate() = the delegate to be executed
114 * fireNow = When true the delegate will be executed emmidiatly
115 * Returns:
117 this(bit delegate() dlg, bit fireNow=false)
119 idleListeners ~= dlg;
120 idleID = gtk_idle_add(cast(GtkFunction)&idleCallback, this);
121 if ( fireNow )
123 if ( !dlg() )
125 idleListeners.length = 0;
130 public void stop()
132 if ( idleID > 0 )
134 gtk_idle_remove(idleID);
136 idleListeners.length = 0;
140 * Removes the idle from gtk
141 * Returns:
143 ~this()
145 stop();
149 * Adds a new delegate to this idle cycle
150 * Params:
151 * delegate() =
152 * fireNow =
154 public void addListener(bit delegate() dlg, bit fireNow=false)
156 idleListeners ~= dlg;
157 if ( fireNow )
159 if ( !dlg() )
161 idleListeners.length = idleListeners.length - 1;
167 * The callback execution from glib
168 * Params:
169 * idle =
170 * Returns:
172 extern(C) static bit idleCallback(Idle idle)
174 return idle.callAllListeners();
178 * Executes all delegates on the execution list
179 * Returns:
181 private bit callAllListeners()
183 bit runAgain = false;
185 int i = 0;
187 while ( i<idleListeners.length )
189 if ( !idleListeners[i]() )
191 idleListeners = idleListeners[0..i] ~ idleListeners[i+1..idleListeners.length];
193 else
195 runAgain = true;
196 ++i;
199 return runAgain;
238 * Warning
239 * gtk_idle_add has been deprecated since version 2.4 and should not be used in newly-written code. Use g_idle_add() instead.
240 * Causes the mainloop to call the given function whenever no events with
241 * higher priority are to be processed. The default priority is
242 * GTK_PRIORITY_DEFAULT, which is rather low.
243 * function:
244 * The function to call.
245 * data:
246 * The information to pass to the function.
247 * Returns:
248 * a unique handle for this registration.
250 public static uint add(GtkFunction funct, void* data)
252 // guint gtk_idle_add (GtkFunction function, gpointer data);
253 return gtk_idle_add(funct, data);
257 * Warning
258 * gtk_idle_add_priority has been deprecated since version 2.4 and should not be used in newly-written code. Use g_idle_add_full() instead.
259 * Like gtk_idle_add() this function allows you to have a function called
260 * when the event loop is idle. The difference is that you can give a
261 * priority different from GTK_PRIORITY_DEFAULT to the idle function.
262 * priority:
263 * The priority which should not be above G_PRIORITY_HIGH_IDLE.
264 * Note that you will interfere with GTK+ if you use a priority above
265 * GTK_PRIORITY_RESIZE.
266 * function:
267 * The function to call.
268 * data:
269 * Data to pass to that function.
270 * Returns:
271 * A unique id for the event source.
273 public static uint addPriority(int priority, GtkFunction funct, void* data)
275 // guint gtk_idle_add_priority (gint priority, GtkFunction function, gpointer data);
276 return gtk_idle_add_priority(priority, funct, data);
280 * Warning
281 * gtk_idle_add_full has been deprecated since version 2.4 and should not be used in newly-written code. Use g_idle_add_full() instead.
282 * Like gtk_idle_add() this function allows you to have a function called
283 * when the event loop is idle. The difference is that you can give a
284 * priority different from GTK_PRIORITY_DEFAULT to the idle function.
285 * priority:
286 * The priority which should not be above G_PRIORITY_HIGH_IDLE.
287 * Note that you will interfere with GTK+ if you use a priority above
288 * GTK_PRIORITY_RESIZE.
289 * function:
290 * The function to call.
291 * marshal:
292 * The marshaller to use instead of the function (if non-NULL).
293 * data:
294 * Data to pass to that function.
295 * destroy:
296 * Function to call when the timeout is destroyed or NULL.
297 * Returns:
298 * A unique id for the event source.
300 public static uint addFull(int priority, GtkFunction funct, GtkCallbackMarshal marshal, void* data, GtkDestroyNotify destroy)
302 // guint gtk_idle_add_full (gint priority, GtkFunction function, GtkCallbackMarshal marshal, gpointer data, GtkDestroyNotify destroy);
303 return gtk_idle_add_full(priority, funct, marshal, data, destroy);
307 * Warning
308 * gtk_idle_remove has been deprecated since version 2.4 and should not be used in newly-written code. Use g_source_remove() instead.
309 * Removes the idle function with the given id.
310 * idle_handler_id:
311 * Identifies the idle function to remove.
313 public static void remove(uint idleHandlerId)
315 // void gtk_idle_remove (guint idle_handler_id);
316 gtk_idle_remove(idleHandlerId);
320 * Warning
321 * gtk_idle_remove_by_data has been deprecated since version 2.4 and should not be used in newly-written code. Use g_idle_remove_by_data() instead.
322 * Removes the idle function identified by the user data.
323 * data:
324 * remove the idle function which was registered with this user data.
326 public static void removeByData(void* data)
328 // void gtk_idle_remove_by_data (gpointer data);
329 gtk_idle_remove_by_data(data);