Example 3

Example 3 — From Gtk to MGtk

Description

Example 9. Example Gtk 2.20.1


#include <gtk/gtk.h>


static void callback( GtkWidget *widget,
                      gpointer   data )
{
    g_print ("Hello again - %s was pressed\n", (gchar *) 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 *box1;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    gtk_window_set_title (GTK_WINDOW (window), "Hello Buttons!");

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

    gtk_container_set_border_width (GTK_CONTAINER (window), 10);

    box1 = gtk_hbox_new (FALSE, 0);

    gtk_container_add (GTK_CONTAINER (window), box1);

    button = gtk_button_new_with_label ("Button 1");

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

    gtk_box_pack_start (GTK_BOX(box1), button, TRUE, TRUE, 0);

    gtk_widget_show (button);

    button = gtk_button_new_with_label ("Button 2");

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

    gtk_box_pack_start(GTK_BOX (box1), button, TRUE, TRUE, 0);


    gtk_widget_show (button);

    gtk_widget_show (box1);

    gtk_widget_show (window);


    gtk_main ();

    return 0;
}

  


Example 10. Example MGtk 0.0.1


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


    static
    void
    callback ( GtkWidget*       widget,
               gpointer         _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,
                   gpointer         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 box1    = MNOID;

    MId button1 = MNOID;
    MId button2 = MNOID;


    window = mgtk_window_insert ( GTK_WINDOW_TOPLEVEL, "Hello Buttons!" );

    box1 = mgtk_hbox_insert ( HOMOGENEOUS_OFF, SPACING_OFF );

    button1 = mgtk_button_insert ( "Button 1" );

    button2 = mgtk_button_insert ( "Button 2" );


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


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


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


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


    gtk_container_add ( GTK_CONTAINER ( MGTK_WINDOW_(window) ), MGTK_HBOX_(box1) );

    gtk_box_pack_start ( GTK_BOX( MGTK_HBOX_(box1) ),
                         MGTK_BUTTON_(button1),
                                    EXPAND_ON,
                                    FILL_ON,
                                    PADDING_OFF );

    gtk_box_pack_start ( GTK_BOX( MGTK_HBOX_(box1) ),
                         MGTK_BUTTON_(button2),
                                    EXPAND_ON,
                                    FILL_ON,
                                    PADDING_OFF );


    gtk_widget_show ( MGTK_BUTTON_(button1) );

    gtk_widget_show ( MGTK_BUTTON_(button2) );

    gtk_widget_show ( MGTK_HBOX_(box1) );

    gtk_widget_show ( MGTK_WINDOW_(window) );


    gtk_main ();

    return 0;
}