alternative to assert
[gtkD.git] / gtkD / src / gtk / Idle.d
blobca7b3e5a2b6d706fb99a21b02062521e80aed9ba
1 /*
2 * This file is part of gtkD.
4 * gtkD 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 * gtkD 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 gtkD; 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 * module aliases:
46 * local aliases:
49 module gtk.Idle;
51 version(noAssert)
53 version(Tango)
55 import tango.io.Stdout; // use the tango loging?
59 private import gtkc.gtktypes;
61 private import gtkc.gtk;
68 /**
69 * Description
70 * Before using GTK+, you need to initialize it; initialization connects
71 * to the window system display, and parses some standard command line
72 * arguments. The gtk_init() function initializes GTK+. gtk_init() exits
73 * the application if errors occur; to avoid this, use gtk_init_check().
74 * gtk_init_check() allows you to recover from a failed GTK+
75 * initialization - you might start up your application in text mode instead.
76 * Like all GUI toolkits, GTK+ uses an event-driven programming
77 * model. When the user is doing nothing, GTK+ sits in the
78 * main loop and waits for input. If the user
79 * performs some action - say, a mouse click - then the main loop "wakes
80 * up" and delivers an event to GTK+. GTK+ forwards the event to one or
81 * more widgets.
82 * When widgets receive an event, they frequently emit one or more
83 * signals. Signals notify your program that
84 * "something interesting happened" by invoking functions you've
85 * connected to the signal with g_signal_connect(). Functions connected
86 * to a signal are often termed callbacks.
87 * When your callbacks are invoked, you would typically take some action
88 * - for example, when an Open button is clicked you might display a
89 * GtkFileSelectionDialog. After a callback finishes, GTK+ will return
90 * to the main loop and await more user input.
91 * Example1.Typical main function for a GTK+ application
92 * int
93 * main (int argc, char **argv)
94 * {
95 * /+* Initialize i18n support +/
96 * gtk_set_locale ();
97 * /+* Initialize the widget set +/
98 * gtk_init (argc, argv);
99 * /+* Create the main window +/
100 * mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
101 * /+* Set up our GUI elements +/
102 * ...
103 * /+* Show the application window +/
104 * gtk_widget_show_all (mainwin);
105 * /+* Enter the main event loop, and wait for user interaction +/
106 * gtk_main ();
107 * /+* The user lost interest +/
108 * return 0;
110 * It's OK to use the GLib main loop directly instead of gtk_main(),
111 * though it involves slightly more typing. See GMainLoop in the GLib
112 * documentation.
114 public class Idle
117 /** Holds all idle delegates */
118 bool delegate()[] idleListeners;
119 /** our gtk idle ID */
120 uint idleID;
123 * Creates a new idle cycle.
124 * Params:
125 * interval = the idle in milieconds
126 * delegate() = the delegate to be executed
127 * fireNow = When true the delegate will be executed emmidiatly
128 * Returns:
130 this(bool delegate() dlg, bool fireNow=false)
132 idleListeners ~= dlg;
133 idleID = gtk_idle_add(cast(GtkFunction)&idleCallback, cast(void*)this);
134 if ( fireNow )
136 if ( !dlg() )
138 idleListeners.length = 0;
143 public void stop()
145 if ( idleID > 0 )
147 gtk_idle_remove(idleID);
149 idleListeners.length = 0;
153 * Removes the idle from gtk
154 * Returns:
156 ~this()
158 stop();
162 * Adds a new delegate to this idle cycle
163 * Params:
164 * delegate() =
165 * fireNow =
167 public void addListener(bool delegate() dlg, bool fireNow=false)
169 idleListeners ~= dlg;
170 if ( fireNow )
172 if ( !dlg() )
174 idleListeners.length = idleListeners.length - 1;
180 * The callback execution from glib
181 * Params:
182 * idle =
183 * Returns:
185 extern(C) static bool idleCallback(Idle idle)
187 return idle.callAllListeners();
191 * Executes all delegates on the execution list
192 * Returns:
194 private bool callAllListeners()
196 bool runAgain = false;
198 int i = 0;
200 while ( i<idleListeners.length )
202 if ( !idleListeners[i]() )
204 idleListeners = idleListeners[0..i] ~ idleListeners[i+1..idleListeners.length];
206 else
208 runAgain = true;
209 ++i;
212 return runAgain;
251 * Warning
252 * gtk_idle_add has been deprecated since version 2.4 and should not be used in newly-written code. Use g_idle_add() instead.
253 * Causes the mainloop to call the given function whenever no events with
254 * higher priority are to be processed. The default priority is
255 * GTK_PRIORITY_DEFAULT, which is rather low.
256 * function:
257 * The function to call.
258 * data:
259 * The information to pass to the function.
260 * Returns:
261 * a unique handle for this registration.
263 public static uint add(GtkFunction funct, void* data)
265 // guint gtk_idle_add (GtkFunction function, gpointer data);
266 return gtk_idle_add(funct, data);
270 * Warning
271 * 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.
272 * Like gtk_idle_add() this function allows you to have a function called
273 * when the event loop is idle. The difference is that you can give a
274 * priority different from GTK_PRIORITY_DEFAULT to the idle function.
275 * priority:
276 * The priority which should not be above G_PRIORITY_HIGH_IDLE.
277 * Note that you will interfere with GTK+ if you use a priority above
278 * GTK_PRIORITY_RESIZE.
279 * function:
280 * The function to call.
281 * data:
282 * Data to pass to that function.
283 * Returns:
284 * A unique id for the event source.
286 public static uint addPriority(int priority, GtkFunction funct, void* data)
288 // guint gtk_idle_add_priority (gint priority, GtkFunction function, gpointer data);
289 return gtk_idle_add_priority(priority, funct, data);
293 * Warning
294 * 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.
295 * Like gtk_idle_add() this function allows you to have a function called
296 * when the event loop is idle. The difference is that you can give a
297 * priority different from GTK_PRIORITY_DEFAULT to the idle function.
298 * priority:
299 * The priority which should not be above G_PRIORITY_HIGH_IDLE.
300 * Note that you will interfere with GTK+ if you use a priority above
301 * GTK_PRIORITY_RESIZE.
302 * function:
303 * The function to call.
304 * marshal:
305 * The marshaller to use instead of the function (if non-NULL).
306 * data:
307 * Data to pass to that function.
308 * destroy:
309 * Function to call when the timeout is destroyed or NULL.
310 * Returns:
311 * A unique id for the event source.
313 public static uint addFull(int priority, GtkFunction funct, GtkCallbackMarshal marshal, void* data, GtkDestroyNotify destroy)
315 // guint gtk_idle_add_full (gint priority, GtkFunction function, GtkCallbackMarshal marshal, gpointer data, GtkDestroyNotify destroy);
316 return gtk_idle_add_full(priority, funct, marshal, data, destroy);
320 * Warning
321 * gtk_idle_remove has been deprecated since version 2.4 and should not be used in newly-written code. Use g_source_remove() instead.
322 * Removes the idle function with the given id.
323 * idle_handler_id:
324 * Identifies the idle function to remove.
326 public static void remove(uint idleHandlerId)
328 // void gtk_idle_remove (guint idle_handler_id);
329 gtk_idle_remove(idleHandlerId);
333 * Warning
334 * 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.
335 * Removes the idle function identified by the user data.
336 * data:
337 * remove the idle function which was registered with this user data.
339 public static void removeByData(void* data)
341 // void gtk_idle_remove_by_data (gpointer data);
342 gtk_idle_remove_by_data(data);