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 = gtk-General.html
56 * - GdkEvent* -> Event
57 * - GtkObject* -> ObjectGtk
58 * - GtkWidget* -> Widget
70 import tango
.io
.Stdout
; // use the tango loging?
74 private import gtkc
.gtktypes
;
76 private import gtkc
.gtk
;
79 private import gdk
.Event
;
80 private import gtk
.Widget
;
81 private import gtk
.ObjectGtk
;
82 private import glib
.Str
;
83 private import gtkc
.gtk
;
84 private import gthread
.Thread
;
85 private import gdk
.Threads
;
88 public alias GtkD Gtk
;
92 * Before using GTK+, you need to initialize it; initialization connects
93 * to the window system display, and parses some standard command line
94 * arguments. The gtk_init() function initializes GTK+. gtk_init() exits
95 * the application if errors occur; to avoid this, use gtk_init_check().
96 * gtk_init_check() allows you to recover from a failed GTK+
97 * initialization - you might start up your application in text mode instead.
98 * Like all GUI toolkits, GTK+ uses an event-driven programming
99 * model. When the user is doing nothing, GTK+ sits in the
100 * main loop and waits for input. If the user
101 * performs some action - say, a mouse click - then the main loop "wakes
102 * up" and delivers an event to GTK+. GTK+ forwards the event to one or
104 * When widgets receive an event, they frequently emit one or more
105 * signals. Signals notify your program that
106 * "something interesting happened" by invoking functions you've
107 * connected to the signal with g_signal_connect(). Functions connected
108 * to a signal are often termed callbacks.
109 * When your callbacks are invoked, you would typically take some action
110 * - for example, when an Open button is clicked you might display a
111 * GtkFileSelectionDialog. After a callback finishes, GTK+ will return
112 * to the main loop and await more user input.
113 * Example1.Typical main function for a GTK+ application
115 * main (int argc, char **argv)
117 * /+* Initialize i18n support +/
119 * /+* Initialize the widget set +/
120 * gtk_init (argc, argv);
121 * /+* Create the main window +/
122 * mainwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
123 * /+* Set up our GUI elements +/
125 * /+* Show the application window +/
126 * gtk_widget_show_all (mainwin);
127 * /+* Enter the main event loop, and wait for user interaction +/
129 * /+* The user lost interest +/
132 * It's OK to use the GLib main loop directly instead of gtk_main(),
133 * though it involves slightly more typing. See GMainLoop in the GLib
140 * Call this function before using any other GTK+ functions in your GUI applications.
142 public static void init(char[][] args
)
144 char** argv
= (new char*[args
.length
]).ptr
;
146 foreach (char[] p
; args
)
148 argv
[argc
++] = cast(char*)p
;
155 * This initiates GtkD to supports multi threaded programs.
156 * read full documantation at http://gtk.org/faq/#AEN482
158 * "There is a single global lock that you must acquire with
159 * gdk_threads_enter() before making any GDK calls,
160 * and release with gdk_threads_leave() afterwards throughout your code."
161 * This is to be used on any call to GDK not executed from the main thread.
163 public static void initMultiThread(char[][] args
)
175 * Initializes internationalization support for GTK+. gtk_init()
176 * automatically does this, so there is typically no point
177 * in calling this function.
178 * If you are calling this function because you changed the locale
179 * after GTK+ is was initialized, then calling this function
180 * may help a bit. (Note, however, that changing the locale
181 * after GTK+ is initialized may produce inconsistent results and
182 * is not really supported.)
183 * In detail - sets the current locale according to the
184 * program environment. This is the same as calling the C library function
185 * setlocale (LC_ALL, "") but also takes care of the
186 * locale specific setup of the windowing system used by GDK.
188 * a string corresponding to the locale set, typically in the
189 * form lang_COUNTRY, where lang is an ISO-639 language code, and
190 * COUNTRY is an ISO-3166 country code. On Unix, this form matches the
191 * result of the setlocale(); it is also used on other machines, such as
192 * Windows, where the C library returns a different result. The string is
193 * owned by GTK+ and should not be modified or freed.
195 public static char[] setLocale()
197 // gchar* gtk_set_locale (void);
198 return Str
.toString(gtk_set_locale() );
202 * Prevents gtk_init(), gtk_init_check(), gtk_init_with_args() and
203 * gtk_parse_args() from automatically
204 * calling setlocale (LC_ALL, ""). You would
205 * want to use this function if you wanted to set the locale for
206 * your program to something other than the user's locale, or if
207 * you wanted to set different values for different locale categories.
208 * Most programs should not need to call this function.
210 public static void disableSetlocale()
212 // void gtk_disable_setlocale (void);
213 gtk_disable_setlocale();
217 * Returns the PangoLanguage for the default language currently in
218 * effect. (Note that this can change over the life of an
219 * application.) The default language is derived from the current
220 * locale. It determines, for example, whether GTK+ uses the
221 * right-to-left or left-to-right text direction.
222 * This function is equivalent to pango_language_get_default(). See
223 * that function for details.
225 * the default language as a PangoLanguage, must not be
228 public static PangoLanguage
* getDefaultLanguage()
230 // PangoLanguage* gtk_get_default_language (void);
231 return gtk_get_default_language();
235 * Parses command line arguments, and initializes global
236 * attributes of GTK+, but does not actually open a connection
237 * to a display. (See gdk_display_open(), gdk_get_display_arg_name())
238 * Any arguments used by GTK+ or GDK are removed from the array and
239 * argc and argv are updated accordingly.
240 * You shouldn't call this function explicitely if you are using
241 * gtk_init(), or gtk_init_check().
243 * a pointer to the number of command line arguments.
245 * a pointer to the array of command line arguments.
247 * TRUE if initialization succeeded, otherwise FALSE.
249 public static int parseArgs(int* argc
, char*** argv
)
251 // gboolean gtk_parse_args (int *argc, char ***argv);
252 return gtk_parse_args(argc
, argv
);
256 * Call this function before using any other GTK+ functions in your GUI
257 * applications. It will initialize everything needed to operate the
258 * toolkit and parses some standard command line options. argc and
259 * argv are adjusted accordingly so your own code will
260 * never see those standard arguments.
261 * Note that there are some alternative ways to initialize GTK+:
262 * if you are calling gtk_parse_args(), gtk_init_check(),
263 * gtk_init_with_args() or g_option_context_parse() with
264 * the option group returned by gtk_get_option_group(), you
265 * don't have to call gtk_init().
267 * This function will terminate your program if it was unable to initialize
268 * the GUI for some reason. If you want your program to fall back to a
269 * textual interface you want to call gtk_init_check() instead.
272 * Address of the argc parameter of your
273 * main() function. Changed if any arguments were handled.
275 * Address of the argv parameter of main().
276 * Any parameters understood by gtk_init() are stripped before return.
278 public static void init(int* argc
, char*** argv
)
280 // void gtk_init (int *argc, char ***argv);
281 gtk_init(argc
, argv
);
285 * This function does the same work as gtk_init() with only
286 * a single change: It does not terminate the program if the GUI can't be
287 * initialized. Instead it returns FALSE on failure.
288 * This way the application can fall back to some other means of communication
289 * with the user - for example a curses or command line interface.
291 * Address of the argc parameter of your
292 * main() function. Changed if any arguments were handled.
294 * Address of the argv parameter of main().
295 * Any parameters understood by gtk_init() are stripped before return.
297 * TRUE if the GUI has been successfully initialized,
300 public static int initCheck(int* argc
, char*** argv
)
302 // gboolean gtk_init_check (int *argc, char ***argv);
303 return gtk_init_check(argc
, argv
);
307 * This function does the same work as gtk_init_check().
308 * Additionally, it allows you to add your own commandline options,
309 * and it automatically generates nicely formatted
310 * --help output. Note that your program will
311 * be terminated after writing out the help output.
313 * a pointer to the number of command line arguments.
315 * a pointer to the array of command line arguments.
317 * a string which is displayed in
318 * the first line of --help output, after
319 * programname [OPTION...]
321 * a NULL-terminated array of GOptionEntrys
322 * describing the options of your program
323 * translation_domain:
324 * a translation domain to use for translating
325 * the --help output for the options in entries
326 * with gettext(), or NULL
328 * a return location for errors
330 * TRUE if the GUI has been successfully initialized,
334 public static int initWithArgs(int* argc
, char*** argv
, char[] parameterString
, GOptionEntry
* entries
, char[] translationDomain
, GError
** error
)
336 // gboolean gtk_init_with_args (int *argc, char ***argv, char *parameter_string, GOptionEntry *entries, char *translation_domain, GError **error);
337 return gtk_init_with_args(argc
, argv
, Str
.toStringz(parameterString
), entries
, Str
.toStringz(translationDomain
), error
);
341 * Returns a GOptionGroup for the commandline arguments recognized
342 * by GTK+ and GDK. You should add this group to your GOptionContext
343 * with g_option_context_add_group(), if you are using
344 * g_option_context_parse() to parse your commandline arguments.
345 * open_default_display:
346 * whether to open the default display
347 * when parsing the commandline arguments
349 * a GOptionGroup for the commandline arguments recognized
353 public static GOptionGroup
* getOptionGroup(int openDefaultDisplay
)
355 // GOptionGroup* gtk_get_option_group (gboolean open_default_display);
356 return gtk_get_option_group(openDefaultDisplay
);
361 * gtk_exit is deprecated and should not be used in newly-written code. Use the standard exit() function instead.
362 * Terminates the program and returns the given exit code to the caller.
363 * This function will shut down the GUI and free all resources allocated
366 * Return value to pass to the caller. This is dependent on the
367 * target system but at least on Unix systems 0 means success.
369 public static void exit(int errorCode
)
371 // void gtk_exit (gint error_code);
376 * Checks if any events are pending. This can be used to update the GUI
377 * and invoke timeouts etc. while doing some time intensive computation.
378 * Example2.Updating the GUI during a long computation.
379 * /+* computation going on +/
381 * while (gtk_events_pending ())
382 * gtk_main_iteration ();
384 * /+* computation continued +/
386 * TRUE if any events are pending, FALSE otherwise.
388 public static int eventsPending()
390 // gboolean gtk_events_pending (void);
391 return gtk_events_pending();
395 * Runs the main loop until gtk_main_quit() is called. You can nest calls to
396 * gtk_main(). In that case gtk_main_quit() will make the innermost invocation
397 * of the main loop return.
399 public static void main()
401 // void gtk_main (void);
406 * Asks for the current nesting level of the main loop. This can be useful
407 * when calling gtk_quit_add().
409 * the nesting level of the current invocation of the main loop.
411 public static uint mainLevel()
413 // guint gtk_main_level (void);
414 return gtk_main_level();
418 * Makes the innermost invocation of the main loop return when it regains
421 public static void mainQuit()
423 // void gtk_main_quit (void);
428 * Runs a single iteration of the mainloop. If no events are waiting to be
429 * processed GTK+ will block until the next event is noticed. If you don't
430 * want to block look at gtk_main_iteration_do() or check if any events are
431 * pending with gtk_events_pending() first.
433 * TRUE if gtk_main_quit() has been called for the innermost mainloop.
435 public static int mainIteration()
437 // gboolean gtk_main_iteration (void);
438 return gtk_main_iteration();
442 * Runs a single iteration of the mainloop. If no events are available either
443 * return or block dependent on the value of blocking.
445 * TRUE if you want GTK+ to block if no events are pending.
447 * TRUE if gtk_main_quit() has been called for the innermost mainloop.
449 public static int mainIterationDo(int blocking
)
451 // gboolean gtk_main_iteration_do (gboolean blocking);
452 return gtk_main_iteration_do(blocking
);
456 * Processes a single GDK event. This is public only to allow filtering of events
457 * between GDK and GTK+. You will not usually need to call this function directly.
458 * While you should not call this function directly, you might want to know
459 * how exactly events are handled. So here is what this function does with
461 * Compress enter/leave notify events. If the event passed build an
462 * enter/leave pair together with the next event (peeked from GDK)
463 * both events are thrown away. This is to avoid a backlog of (de-)highlighting
464 * widgets crossed by the pointer.
465 * Find the widget which got the event. If the widget can't be determined
466 * the event is thrown away unless it belongs to a INCR transaction. In that
467 * case it is passed to gtk_selection_incr_event().
468 * Then the event is passed on a stack so you can query the currently handled
469 * event with gtk_get_current_event().
470 * The event is sent to a widget. If a grab is active all events for
471 * widgets that are not in the contained in the grab widget are sent to the
472 * latter with a few exceptions:
473 * Deletion and destruction events are still sent to the event widget for
475 * Events which directly relate to the visual representation of the event
477 * Leave events are delivered to the event widget if there was an enter
478 * event delivered to it before without the paired leave event.
479 * Drag events are not redirected because it is unclear what the semantics
481 * Another point of interest might be that all key events are first passed
482 * through the key snooper functions if there are any. Read the description
483 * of gtk_key_snooper_install() if you need this feature.
484 * After finishing the delivery the event is popped from the event stack.
486 * An event to process (normally) passed by GDK.
488 public static void mainDoEvent(Event event
)
490 // void gtk_main_do_event (GdkEvent *event);
491 gtk_main_do_event((event
is null) ?
null : event
.getEventStruct());
499 * Makes widget the current grabbed widget. This means that interaction with
500 * other widgets in the same application is blocked and mouse as well as
501 * keyboard events are delivered to this widget.
503 * The widget that grabs keyboard and pointer events.
505 public static void grabAdd(Widget widget
)
507 // void gtk_grab_add (GtkWidget *widget);
508 gtk_grab_add((widget
is null) ?
null : widget
.getWidgetStruct());
512 * Queries the current grab of the default window group.
514 * The widget which currently has the grab or NULL if no grab is active.
516 public static Widget
grabGetCurrent()
518 // GtkWidget* gtk_grab_get_current (void);
519 return new Widget( gtk_grab_get_current() );
523 * Removes the grab from the given widget. You have to pair calls to gtk_grab_add()
524 * and gtk_grab_remove().
526 * The widget which gives up the grab.
528 public static void grabRemove(Widget widget
)
530 // void gtk_grab_remove (GtkWidget *widget);
531 gtk_grab_remove((widget
is null) ?
null : widget
.getWidgetStruct());
535 * Registers a function to be called when the mainloop is started.
537 * Function to invoke when gtk_main() is called next.
539 * Data to pass to that function.
541 public static void initAdd(GtkFunction funct
, void* data
)
543 // void gtk_init_add (GtkFunction function, gpointer data);
544 gtk_init_add(funct
, data
);
548 * Trigger destruction of object in case the mainloop at level main_level
551 * Level of the mainloop which shall trigger the destruction.
553 * Object to be destroyed.
555 public static void quitAddDestroy(uint mainLevel
, ObjectGtk object
)
557 // void gtk_quit_add_destroy (guint main_level, GtkObject *object);
558 gtk_quit_add_destroy(mainLevel
, (object
is null) ?
null : object
.getObjectGtkStruct());
562 * Registers a function to be called when an instance of the mainloop is left.
564 * Level at which termination the function shall be called. You
565 * can pass 0 here to have the function run at the termination of the current
568 * The function to call. This should return 0 to be removed from the
569 * list of quit handlers. Otherwise the function might be called again.
571 * Pointer to pass when calling function.
573 * A handle for this quit handler (you need this for gtk_quit_remove())
574 * or 0 if you passed a NULL pointer in function.
576 public static uint quitAdd(uint mainLevel
, GtkFunction funct
, void* data
)
578 // guint gtk_quit_add (guint main_level, GtkFunction function, gpointer data);
579 return gtk_quit_add(mainLevel
, funct
, data
);
583 * Registers a function to be called when an instance of the mainloop is left.
584 * In comparison to gtk_quit_add() this function adds the possibility to
585 * pass a marshaller and a function to be called when the quit handler is freed.
586 * The former can be used to run interpreted code instead of a compiled function
587 * while the latter can be used to free the information stored in data (while
588 * you can do this in function as well)... So this function will mostly be
589 * used by GTK+ wrappers for languages other than C.
591 * Level at which termination the function shall be called. You
592 * can pass 0 here to have the function run at the termination of the current
595 * The function to call. This should return 0 to be removed from the
596 * list of quit handlers. Otherwise the function might be called again.
598 * The marshaller to be used. If this is non-NULL, function is
601 * Pointer to pass when calling function.
603 * Function to call to destruct data. Gets data as argument.
605 * A handle for this quit handler (you need this for gtk_quit_remove())
606 * or 0 if you passed a NULL pointer in function.
608 public static uint quitAddFull(uint mainLevel
, GtkFunction funct
, GtkCallbackMarshal marshal
, void* data
, GtkDestroyNotify destroy
)
610 // guint gtk_quit_add_full (guint main_level, GtkFunction function, GtkCallbackMarshal marshal, gpointer data, GtkDestroyNotify destroy);
611 return gtk_quit_add_full(mainLevel
, funct
, marshal
, data
, destroy
);
615 * Removes a quit handler by its identifier.
617 * Identifier for the handler returned when installing it.
619 public static void quitRemove(uint quitHandlerId
)
621 // void gtk_quit_remove (guint quit_handler_id);
622 gtk_quit_remove(quitHandlerId
);
626 * Removes a quit handler identified by its data field.
628 * The pointer passed as data to gtk_quit_add() or gtk_quit_add_full().
630 public static void quitRemoveByData(void* data
)
632 // void gtk_quit_remove_by_data (gpointer data);
633 gtk_quit_remove_by_data(data
);
646 * gtk_input_add_full has been deprecated since version 2.4 and should not be used in newly-written code. Use g_io_add_watch_full() instead.
647 * Registers a function to be called when a condition becomes true
648 * on a file descriptor.
654 * The function to call.
656 * The marshaller to use instead of the function (if non-NULL).
658 * callback data passed to function.
660 * callback function to call with data when the input
661 * handler is removed, or NULL.
663 * A unique id for the event source; to be used with gtk_input_remove().
665 public static uint inputAddFull(int source
, GdkInputCondition condition
, GdkInputFunction funct
, GtkCallbackMarshal marshal
, void* data
, GtkDestroyNotify destroy
)
667 // guint gtk_input_add_full (gint source, GdkInputCondition condition, GdkInputFunction function, GtkCallbackMarshal marshal, gpointer data, GtkDestroyNotify destroy);
668 return gtk_input_add_full(source
, condition
, funct
, marshal
, data
, destroy
);
673 * gtk_input_remove has been deprecated since version 2.4 and should not be used in newly-written code. Use g_source_remove() instead.
674 * Removes the function with the given id.
676 * Identifies the function to remove.
678 public static void inputRemove(uint inputHandlerId
)
680 // void gtk_input_remove (guint input_handler_id);
681 gtk_input_remove(inputHandlerId
);
691 * Installs a key snooper function, which will get called on all key events
692 * before delivering them normally.
696 * data to pass to snooper.
698 * a unique id for this key snooper for use with gtk_key_snooper_remove().
700 public static uint keySnooperInstall(GtkKeySnoopFunc snooper
, void* funcData
)
702 // guint gtk_key_snooper_install (GtkKeySnoopFunc snooper, gpointer func_data);
703 return gtk_key_snooper_install(snooper
, funcData
);
708 * Removes the key snooper function with the given id.
709 * snooper_handler_id:
710 * Identifies the key snooper to remove.
712 public static void keySnooperRemove(uint snooperHandlerId
)
714 // void gtk_key_snooper_remove (guint snooper_handler_id);
715 gtk_key_snooper_remove(snooperHandlerId
);
719 * Obtains a copy of the event currently being processed by GTK+. For
720 * example, if you get a "clicked" signal from GtkButton, the current
721 * event will be the GdkEventButton that triggered the "clicked"
722 * signal. The returned event must be freed with gdk_event_free().
723 * If there is no current event, the function returns NULL.
725 * a copy of the current event, or NULL if no current event.
727 public static Event
getCurrentEvent()
729 // GdkEvent* gtk_get_current_event (void);
730 return new Event( gtk_get_current_event() );
734 * If there is a current event and it has a timestamp, return that
735 * timestamp, otherwise return GDK_CURRENT_TIME.
737 * the timestamp from the current event, or GDK_CURRENT_TIME.
739 public static uint getCurrentEventTime()
741 // guint32 gtk_get_current_event_time (void);
742 return gtk_get_current_event_time();
746 * If there is a current event and it has a state field, place
747 * that state field in state and return TRUE, otherwise return
750 * a location to store the state of the current event
752 * TRUE if there was a current event and it had a state field
754 public static int getCurrentEventState(GdkModifierType
* state
)
756 // gboolean gtk_get_current_event_state (GdkModifierType *state);
757 return gtk_get_current_event_state(state
);
761 * If event is NULL or the event was not associated with any widget,
762 * returns NULL, otherwise returns the widget that received the event
767 * the widget that originally received event, or NULL
769 public static Widget
getEventWidget(Event event
)
771 // GtkWidget* gtk_get_event_widget (GdkEvent *event);
772 return new Widget( gtk_get_event_widget((event
is null) ?
null : event
.getEventStruct()) );
776 * Sends an event to a widget, propagating the event to parent widgets
777 * if the event remains unhandled. Events received by GTK+ from GDK
778 * normally begin in gtk_main_do_event(). Depending on the type of
779 * event, existence of modal dialogs, grabs, etc., the event may be
780 * propagated; if so, this function is used. gtk_propagate_event()
781 * calls gtk_widget_event() on each widget it decides to send the
782 * event to. So gtk_widget_event() is the lowest-level function; it
783 * simply emits the "event" and possibly an event-specific signal on a
784 * widget. gtk_propagate_event() is a bit higher-level, and
785 * gtk_main_do_event() is the highest level.
786 * All that said, you most likely don't want to use any of these
787 * functions; synthesizing events is rarely needed. Consider asking on
788 * the mailing list for better ways to achieve your goals. For
789 * example, use gdk_window_invalidate_rect() or
790 * gtk_widget_queue_draw() instead of making up expose events.
796 * See the GLib manual, especially GMainLoop and signal-related
797 * functions such as g_signal_connect().
799 public static void propagateEvent(Widget widget
, Event event
)
801 // void gtk_propagate_event (GtkWidget *widget, GdkEvent *event);
802 gtk_propagate_event((widget
is null) ?
null : widget
.getWidgetStruct(), (event
is null) ?
null : event
.getEventStruct());