GtkButton – Part I

#include <gtk/gtk.h>

static void clicked_clbk ( GtkButton *button )
{
    g_return_if_fail ( GTK_IS_BUTTON ( button ) );

    g_print ( "You clicked the Button\n" );
}

static void create_button ( GtkWidget *window )
{
    GtkWidget *button;
    GtkWidget *label;

    /// ***
    button = gtk_button_new ();
    g_signal_connect_swapped ( button, "clicked", G_CALLBACK ( clicked_clbk ), button );

    /// ***
    ///gtk_button_set_label ( GTK_BUTTON( button ), "Click me" );
    label = gtk_label_new ( "Click me"  );

    /// ***
    gtk_button_set_child ( GTK_BUTTON ( button ), label );

    /// ***
    gtk_window_set_child ( GTK_WINDOW ( window ), button );
}

static void activate ( GtkApplication *application, G_GNUC_UNUSED gpointer data )
{
    GtkWidget *window;

    /// ***
    window = gtk_application_window_new   ( application );

    /// ***
    gtk_window_set_default_size ( GTK_WINDOW ( window ), 200, 200 );

    /// ***
    create_button ( window );

    /// ***
    gtk_window_present ( GTK_WINDOW ( window ) );
}

int main ( void )
{
    /// ***
    GtkApplication *application;
    gint status;

    /// ***
    application = gtk_application_new ( "this.is.my.nice.app", G_APPLICATION_FLAGS_NONE );

    /// ***
    g_signal_connect ( application, "activate", G_CALLBACK ( activate ), NULL );

    /// ***
    status = g_application_run ( G_APPLICATION ( application ), FALSE, NULL );

    /// ***
    g_object_unref ( application );

    /// ***
    return status;
}
Author: MichaelB

Leave a Reply

Your email address will not be published.