GtkButton – Part II

#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;

    /// ***
    button = gtk_button_new_with_label ( "_Click me"  );
    ///button = gtk_button_new_with_mnemonic ( "_Click me"  );
    g_signal_connect_swapped ( button, "clicked", G_CALLBACK ( clicked_clbk ), button );

    /// ***
    gtk_button_set_use_underline ( GTK_BUTTON ( button ), TRUE );

    /// ***
    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. Required fields are marked *