Adsense code (2021-10-05)

Monday, December 30, 2013

GTK+ example: LinkButton, button to open URL in browser

LinkButton
LinkButton

#include <gtk/gtk.h>

int main( int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *box;
    GtkWidget *linkbutton_linuxbuddy;
    GtkWidget *linkbutton_google;
    GtkWidget *linkbutton_youtube;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 250);
    gtk_window_set_title(GTK_WINDOW(window), "Linux-buddy.blogspot.com");

    linkbutton_linuxbuddy = gtk_link_button_new ("linux-buddy.blogspot.com");
    gtk_link_button_set_uri(GTK_LINK_BUTTON(linkbutton_linuxbuddy), "http://linux-buddy.blogspot.com/");
    linkbutton_google = gtk_link_button_new ("Google");
    gtk_link_button_set_uri(GTK_LINK_BUTTON(linkbutton_google), "http://google.com/");
    linkbutton_youtube = gtk_link_button_new ("Youtube");
    gtk_link_button_set_uri(GTK_LINK_BUTTON(linkbutton_youtube), "http://www.youtube.com");

    box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5);
    gtk_box_pack_start(GTK_BOX(box), linkbutton_linuxbuddy, FALSE, FALSE, 3);
    gtk_box_pack_start(GTK_BOX(box), linkbutton_google, FALSE, FALSE, 3);
    gtk_box_pack_start(GTK_BOX(box), linkbutton_youtube, FALSE, FALSE, 3);

    gtk_container_add(GTK_CONTAINER(window), box);

    //Connects GCallback function gtk_main_quit to "destroy" signal for "window"
    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}