Example 5

Example 5 — From Gtk to MGtk

Description

Example 14. Example Gtk 2.20.1


#include <gtk/gtk.h>


static void callback( GtkWidget *widget,
                      gpointer   data )
{
    g_print ("Hello again - %s was pressed\n", (char *) data);
}


static gboolean delete_event( GtkWidget *widget,
                              GdkEvent  *event,
                              gpointer   data )
{
    gtk_main_quit ();
    return FALSE;
}

int main( int   argc,
          char *argv[] )
{
    GtkWidget *window;
    GtkWidget *button;
    GtkWidget *table;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    gtk_window_set_title (GTK_WINDOW (window), "Table");


    g_signal_connect (window, "delete-event",
                      G_CALLBACK (delete_event), NULL);

    gtk_container_set_border_width (GTK_CONTAINER (window), 20);

    table = gtk_table_new (2, 2, TRUE);

    gtk_container_add (GTK_CONTAINER (window), table);

    button = gtk_button_new_with_label ("button 1");


    g_signal_connect (button, "clicked",
	              G_CALLBACK (callback), (gpointer) "button 1");


    gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 0, 1);

    gtk_widget_show (button);

    button = gtk_button_new_with_label ("button 2");


    g_signal_connect (button, "clicked",
                      G_CALLBACK (callback), (gpointer) "button 2");

    gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 0, 1);

    gtk_widget_show (button);

    button = gtk_button_new_with_label ("Quit");


    g_signal_connect (button, "clicked",
                      G_CALLBACK (delete_event), NULL);


    gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 2, 1, 2);

    gtk_widget_show (button);

    gtk_widget_show (table);
    gtk_widget_show (window);

    gtk_main ();

    return 0;
}

  


Example 15. Example MGtk 0.0.1


#include <gtk/gtk.h>
#include <mlib.h>
#include <mgtk.h>



    static
    void callback ( GtkWidget*   widget,
                    mpointer     _data )
{
    mchars data = (mchars)_data;
    g_print ("Hello again - %s was pressed\n", data);

    return;

    m_warning_disable_var ( widget );
}


    static
    gboolean
    delete_event ( GtkWidget*   widget,
                   GdkEvent*    event,
                   mpointer     data )
{
    gtk_main_quit ();

    return FALSE;

    m_warning_disable_var ( widget );
    m_warning_disable_var ( event );
    m_warning_disable_var ( data );
}



    int
    mgtk_main ( argc, argv )
{
    mgtk_main_init ( argc, argv );

    MId window  = MNOID;
    MId button1 = MNOID;
    MId button2 = MNOID;
    MId button3 = MNOID;
    MId table   = MNOID;


    window = mgtk_window_insert ( GTK_WINDOW_TOPLEVEL, "Table" );

    button1 = mgtk_button_insert ( "button 1" );
    button2 = mgtk_button_insert ( "button 2" );
    button3 = mgtk_button_insert ( "Quit" );

    table = mgtk_table_insert ( 2, 2, HOMOGENEOUS_ON );


    gtk_container_set_border_width ( GTK_CONTAINER ( MGTK_WINDOW_(window) ), 20 );


    m_signal_connect ( "delete-event",
                                        MGTK_WINDOW_(window),
                                        G_CALLBACK (delete_event),
                                        NULL );

    m_signal_connect ( "clicked",
                                        MGTK_BUTTON_(button1),
                                        G_CALLBACK (callback),
                                        (gpointer) "button 1" );

    m_signal_connect ( "clicked",
                                        MGTK_BUTTON_(button2),
                                        G_CALLBACK (callback),
                                        (gpointer) "button 2" );

    m_signal_connect ( "clicked",
                                        MGTK_BUTTON_(button3),
                                        G_CALLBACK (delete_event),
                                        NULL );



    gtk_container_add ( GTK_CONTAINER ( MGTK_WINDOW_(window) ), MGTK_TABLE_(table) );

    gtk_table_attach_defaults ( GTK_TABLE ( MGTK_TABLE_(table) ),
                                MGTK_BUTTON_(button1),
                                                        0, 1, 0, 1 );

    gtk_table_attach_defaults ( GTK_TABLE ( MGTK_TABLE_(table) ),
                                MGTK_BUTTON_(button2),
                                                        1, 2, 0, 1 );

    gtk_table_attach_defaults ( GTK_TABLE ( MGTK_TABLE_(table) ),
                                MGTK_BUTTON_(button3),
                                                        0, 2, 1, 2 );


    gtk_widget_show ( MGTK_BUTTON_(button1) );
    gtk_widget_show ( MGTK_BUTTON_(button2) );
    gtk_widget_show ( MGTK_BUTTON_(button3) );
    gtk_widget_show ( MGTK_TABLE_(table) );
    gtk_widget_show ( MGTK_WINDOW_(window) );

    gtk_main ();

    return 0;
}