Example 2

Example 2 — From Gtk to MGtk

Description

Example 6. Example Gtk 2.20.1


#include <gtk/gtk.h>

static void hello( GtkWidget *widget,
                   gpointer   data )
{
    g_print ("Hello World\n");
}

static gboolean delete_event( GtkWidget *widget,
                              GdkEvent  *event,
                              gpointer   data )
{
    g_print ("delete event occurred\n");

    return TRUE;
}


static void destroy( GtkWidget *widget,
                     gpointer   data )
{
    gtk_main_quit ();
}

int main( int   argc,
          char *argv[] )
{

    GtkWidget *window;
    GtkWidget *button;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

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

    g_signal_connect (window, "destroy",
		      G_CALLBACK (destroy), NULL);

    gtk_container_set_border_width (GTK_CONTAINER (window), 10);

    button = gtk_button_new_with_label ("Hello World");

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

    g_signal_connect_swapped (button, "clicked",
			      G_CALLBACK (gtk_widget_destroy),
                              window);

    gtk_container_add (GTK_CONTAINER (window), button);

    gtk_widget_show (button);

    gtk_widget_show (window);

    gtk_main ();

    return 0;
}

  


Example 7. Example MGtk 0.0.1


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

    static
    void
    hello ( GtkWidget*      widget,
            mpointer        data )
{
    g_print ("Hello World\n");

    return;

    m_warning_disable_var ( widget );
    m_warning_disable_var ( data );
}

    static
    mboolean
    delete_event ( GtkWidget*    widget,
                   GdkEvent*     event,
                   mpointer      data )
{
    g_print ( "delete event occurred \n") ;

    return TRUE;

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

    static
    void
    destroy ( GtkWidget*    widget,
              mpointer      data )
{
    gtk_main_quit ();

    return;

    m_warning_disable_var ( widget );
    m_warning_disable_var ( data );
}



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

    MId window = MNOID;
    MId button = MNOID;


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

    button = mgtk_button_insert ( "Hello World" );


    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 ( "destroy",
                                        MGTK_WINDOW_(window),
                                        G_CALLBACK (destroy),
                                        NULL );

    m_signal_connect ( "clicked",
                                        MGTK_BUTTON_(button),
                                        G_CALLBACK (hello),
                                        NULL );

    m_signal_connect_swapped ( "clicked",
                                        MGTK_BUTTON_(button),
                                        G_CALLBACK (gtk_widget_destroy),
                                        MGTK_WINDOW_(window) );


    gtk_container_add ( GTK_CONTAINER ( MGTK_WINDOW_(window) ), MGTK_BUTTON_(button) );


    gtk_widget_show ( MGTK_BUTTON_(button) );

    gtk_widget_show ( MGTK_WINDOW_(window) );


    gtk_main ();

    return MCORRECT;
}