Example 6

Example 6 — From Gtk to MGtk

Description

Example 17. Example Gtk 2.20.1


#include <stdlib.h>
#include <gtk/gtk.h>


static GtkWidget *xpm_label_box( gchar     *xpm_filename,
                                 gchar     *label_text )
{
    GtkWidget *box;
    GtkWidget *label;
    GtkWidget *image;

    box = gtk_hbox_new (FALSE, 0);
    gtk_container_set_border_width (GTK_CONTAINER (box), 2);

    image = gtk_image_new_from_file (xpm_filename);

    label = gtk_label_new (label_text);

    gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 3);
    gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 3);

    gtk_widget_show (image);
    gtk_widget_show (label);

    return box;
}


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

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

    gtk_init (&argc, &argv);


    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    gtk_window_set_title (GTK_WINDOW (window), "Pixmap'd Buttons!");

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

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

    gtk_container_set_border_width (GTK_CONTAINER (window), 10);

    button = gtk_button_new ();


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


    box = xpm_label_box ("info.xpm", "cool button");


    gtk_widget_show (box);

    gtk_container_add (GTK_CONTAINER (button), box);

    gtk_widget_show (button);

    gtk_container_add (GTK_CONTAINER (window), button);

    gtk_widget_show (window);


    gtk_main ();

    return 0;
}

  


Example 18. Example MGtk 0.0.1


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



    static
    MIdArchive*
    xpm_label_box ( mchar*  xpm_filename,
                    mchar*  label_text )
{
    GtkWidget *box;

    MId label = MNOID;
    MId image = MNOID;

    MIdArchive* archive = mgtk_idarchive_new ();


    box = gtk_hbox_new ( HOMOGENEOUS_OFF, SPACING_OFF );

    image = mgtk_image_insert ( xpm_filename );

    label = mgtk_label_insert ( label_text );

    MGTK_IMAGE_ARCHIVE_ID ( archive, image, "image" );
    MGTK_LABEL_ARCHIVE_ID ( archive, label, "label" );

    gtk_container_set_border_width ( GTK_CONTAINER ( box ), 2 );


    gtk_box_pack_start ( GTK_BOX ( box ),
                         MGTK_IMAGE_(image),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    3 );

    gtk_box_pack_start ( GTK_BOX ( box ),
                         MGTK_LABEL_(label),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    3 );


    gtk_widget_show ( MGTK_IMAGE_(image) );
    gtk_widget_show ( MGTK_LABEL_(label) );

    M_IDARCHIVE_data (archive) = (MPublic)box;

    return archive;
}


    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 );
}



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

    MId window  = MNOID;
    MId button  = MNOID;
    MId box     = MNOID;

    MIdArchive* archive = NULL;


    window = mgtk_window_insert ( GTK_WINDOW_TOPLEVEL, "Pixmap'd Buttons!" );

    button = mgtk_button_insert ( NULL );

    archive = xpm_label_box ( "info.xpm", "cool button" );

	box = mgtk_hbox_insert_attach ( GTK_HBOX ( archive->data ) );


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


    m_signal_connect ( "destroy",
                                        MGTK_WINDOW_(window),
                                        G_CALLBACK (gtk_main_quit),
                                        NULL );

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

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


    gtk_container_add ( GTK_CONTAINER ( MGTK_BUTTON_(button) ), MGTK_HBOX_(box) );

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


    gtk_widget_show ( MGTK_HBOX_(box) );

    gtk_widget_show ( MGTK_BUTTON_(button) );

    gtk_widget_show ( MGTK_WINDOW_(window) );


    gtk_main ();

    return 0;
}