Sample GTK app:
/////////////////////////////////////////////////////////
// run with
// flx `pkg-config --cflags --libs gtk+-2.0` ghel
#import <flx.flxh>
include "pthread";
open Pthread;
header '#include <gtk/gtk.h>';
header '#include <glib.h>';
header '#include <glib.h>';
// GLib
type GObject = "GObject*";
type GCallback = "GCallback";
type gpointer = "gpointer";
fun G_OBJECT[t]: t -> GObject = "G_OBJECT($1)";
fun G_CALLBACK[t]: t -> GCallback = "G_CALLBACK($1)";
proc g_print: string = "g_print($1.data());";
// GDK
type GdkEvent = "GdkEvent*";
const TRUE : bool = "TRUE";
// GTK
type GtkWidget = "GtkWidget *";
type GtkContainer = "GtkContainer*";
fun GTK_CONTAINER[t]: t -> GtkContainer = "GTK_CONTAINER($1)";
gen gtk_window_new: 1 -> GtkWidget ="gtk_window_new
(GTK_WINDOW_TOPLEVEL)";
proc gtk_init: 1 = 'gtk_init(NULL,NULL);';
proc gtk_widget_show : GtkWidget = 'gtk_widget_show($1);';
proc gtk_main: 1 = 'gtk_main();';
proc gtk_main_quit : 1 = 'gtk_main_quit ();';
proc g_signal_connect: GObject * charp * GCallback =
"g_signal_connect($1, $2, $3, NULL);"
;
proc g_signal_connect_swapped: GObject * charp * GCallback * GObject;
proc gtk_container_set_border_width : GtkContainer * int;
gen gtk_button_new_with_label: string -> GtkWidget=
"gtk_button_new_with_label($1.data())"
;
proc gtk_container_add: GtkContainer * GtkWidget;
const gtk_widget_destroy: GCallback;
//-------------------------------------------------------
cfun delete_event (
widget: GtkWidget,
event: GdkEvent,
data: gpointer
) : bool =
{
/* If you return FALSE in the "delete_event" signal handler,
* GTK will emit the "destroy" signal. Returning TRUE means
* you don't want the window to be destroyed.
* This is useful for popping up 'are you sure you want to quit?'
* type dialogs. */
g_print ("delete event occurred\n");
/* Change TRUE to FALSE and the main window will be destroyed with
* a "delete_event". */
return TRUE;
}
cproc destroy( widget : GtkWidget, data : gpointer )
{
gtk_main_quit ();
}
cproc hello( widget: GtkWidget, data : gpointer)
{
g_print ("Hello World\n");
}
gtk_init();
val window = gtk_window_new();
g_signal_connect (G_OBJECT(window), c"delete_event",G_CALLBACK(the
delete_event));
g_signal_connect (G_OBJECT(window), c"destroy",G_CALLBACK(the destroy));
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
var button = gtk_button_new_with_label ("Hello World");
g_signal_connect (G_OBJECT (button), c"clicked", G_CALLBACK (the
hello));
/* This will cause the window to be destroyed by calling
* gtk_widget_destroy(window) when "clicked". Again, the destroy
* signal could come from here, or the window manager. */
g_signal_connect_swapped (G_OBJECT (button), c"clicked", G_CALLBACK
(gtk_widget_destroy), G_OBJECT (window));
gtk_container_add(GTK_CONTAINER(window),button);
gtk_widget_show(button);
gtk_widget_show(window);
spawn_pthread { gtk_main(); };
print "GTK is running now!"; endl;
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language