'
' GTK sample code snippet - October 2010, PvE - GPL
'
' Conversion of the StatusIcon demonstration program at http://live.gnome.org/GtkStatusIconTutorial
'
'---------------------------------------------------------------------------------------------------------

SETENVIRON "LANG", "C"

IMPORT "gtk_status_icon_set_tooltip(long,char*)" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "gtk_status_icon_set_visible(long,int)" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "gtk_status_icon_position_menu(long,int*,int*,int*,long)" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "g_signal_connect_data(long,char*,long,long,long,int)" FROM "libgobject-2.0.so" TYPE void
IMPORT "gtk_main" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "gtk_init(int*,void*)" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "gtk_menu_new" FROM "libgtk-x11-2.0.so" TYPE long
IMPORT "gtk_menu_popup(long,long,long,void*,long,int,int)" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "gtk_menu_item_new_with_label(char*)" FROM "libgtk-x11-2.0.so" TYPE long
IMPORT "gtk_widget_show_all(long)" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "gtk_main_quit" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "gtk_status_icon_set_blinking(long,int)" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "gtk_menu_shell_append(long,long)" FROM "libgtk-x11-2.0.so" TYPE void
IMPORT "gtk_status_icon_new_from_stock(char*)" FROM "libgtk-x11-2.0.so" TYPE long

DECLARE my_menu, status_icon

SUB destroy(NUMBER widget, void* data)

    gtk_main_quit

END SUB

SUB on_blink_change(NUMBER widget, void* data)

    LOCAL blink

    blink = (long)data
    gtk_status_icon_set_blinking(status_icon, blink)

END SUB

SUB activate (NUMBER status_icon, void* user_data)

    PRINT "'activate' signal triggered"

END SUB

SUB popup(NUMBER status_icon, int button, int activate_time, void* user_data)

    LOCAL item

    PRINT "'popup-menu' signal triggered"

    IF NOT(my_menu) THEN

        my_menu = gtk_menu_new()

        item = gtk_menu_item_new_with_label("Let's blink!")
        gtk_menu_shell_append(my_menu, item)
        g_signal_connect_data(item, "activate", ADDRESS(on_blink_change), TRUE, 0, 0)

        item = gtk_menu_item_new_with_label("Let's stop blinking!")
        gtk_menu_shell_append(my_menu, item)
        g_signal_connect_data(item, "activate", ADDRESS(on_blink_change), FALSE, 0, 0)
                
        item = gtk_menu_item_new_with_label("Quit")
        gtk_menu_shell_append(my_menu, item)
        g_signal_connect_data(item, "activate", ADDRESS(destroy), 0, 0, 0)
    END IF
        
    gtk_widget_show_all(my_menu)

    gtk_menu_popup(my_menu, 0, 0, gtk_status_icon_position_menu, status_icon, button, activate_time)

END SUB

gtk_init(0, 0)

status_icon = gtk_status_icon_new_from_stock("gtk-quit")
gtk_status_icon_set_visible(status_icon, TRUE)
gtk_status_icon_set_tooltip(status_icon, "This is a test")

' Connect signals
g_signal_connect_data(status_icon, "popup-menu", ADDRESS(popup), 0, 0, 0)
g_signal_connect_data(status_icon, "activate", ADDRESS(activate), 0, 0, 0)
gtk_main