Example 4

Example 4 — From Gtk to MGtk

Description

Example 11. Example Gtk 2.20.1


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

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


static GtkWidget *make_box( gboolean homogeneous,
                            gint     spacing,
                            gboolean expand,
                            gboolean fill,
                            guint    padding )
{
    GtkWidget *box;
    GtkWidget *button;
    char padstr[80];


    box = gtk_hbox_new (homogeneous, spacing);


    button = gtk_button_new_with_label ("gtk_box_pack");
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("(box,");
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);

    button = gtk_button_new_with_label ("button,");
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);


    if (expand == TRUE)
	    button = gtk_button_new_with_label ("TRUE,");
    else
	    button = gtk_button_new_with_label ("FALSE,");

    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);


    button = gtk_button_new_with_label (fill ? "TRUE," : "FALSE,");
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);

    sprintf (padstr, "%d);", padding);

    button = gtk_button_new_with_label (padstr);
    gtk_box_pack_start (GTK_BOX (box), button, expand, fill, padding);
    gtk_widget_show (button);

    return box;
}

int main( int   argc,
          char *argv[])
{
    GtkWidget *window;
    GtkWidget *button;
    GtkWidget *box1;
    GtkWidget *box2;
    GtkWidget *separator;
    GtkWidget *label;
    GtkWidget *quitbox;
    int which;


    gtk_init (&argc, &argv);

    if (argc != 2) {
	fprintf (stderr, "usage: packbox num, where num is 1, 2, or 3.\n");

	exit (1);
    }

    which = atoi (argv[1]);


    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);


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


    box1 = gtk_vbox_new (FALSE, 0);


    switch (which) {
    case 1:

	label = gtk_label_new ("gtk_hbox_new (FALSE, 0);");


	gtk_misc_set_alignment (GTK_MISC (label), 0, 0);


	gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);


	gtk_widget_show (label);


	box2 = make_box (FALSE, 0, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
	gtk_widget_show (box2);


	box2 = make_box (FALSE, 0, TRUE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
	gtk_widget_show (box2);


	box2 = make_box (FALSE, 0, TRUE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
	gtk_widget_show (box2);


	separator = gtk_hseparator_new ();

	gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
	gtk_widget_show (separator);


	label = gtk_label_new ("gtk_hbox_new (TRUE, 0);");
	gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
	gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
	gtk_widget_show (label);


	box2 = make_box (TRUE, 0, TRUE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
	gtk_widget_show (box2);


	box2 = make_box (TRUE, 0, TRUE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
	gtk_widget_show (box2);


	separator = gtk_hseparator_new ();

	gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
	gtk_widget_show (separator);

	break;

    case 2:

	label = gtk_label_new ("gtk_hbox_new (FALSE, 10);");
	gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
	gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
	gtk_widget_show (label);


	box2 = make_box (FALSE, 10, TRUE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
	gtk_widget_show (box2);


	box2 = make_box (FALSE, 10, TRUE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
	gtk_widget_show (box2);

	separator = gtk_hseparator_new ();


	gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
	gtk_widget_show (separator);

	label = gtk_label_new ("gtk_hbox_new (FALSE, 0);");
	gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
	gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
	gtk_widget_show (label);


	box2 = make_box (FALSE, 0, TRUE, FALSE, 10);
	gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
	gtk_widget_show (box2);


	box2 = make_box (FALSE, 0, TRUE, TRUE, 10);
	gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
	gtk_widget_show (box2);

	separator = gtk_hseparator_new ();

	gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
	gtk_widget_show (separator);
	break;

    case 3:

	box2 = make_box (FALSE, 0, FALSE, FALSE, 0);

	label = gtk_label_new ("end");

	gtk_box_pack_end (GTK_BOX (box2), label, FALSE, FALSE, 0);

	gtk_widget_show (label);

	gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
	gtk_widget_show (box2);

	separator = gtk_hseparator_new ();

	gtk_widget_set_size_request (separator, 400, 5);

	gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5);
	gtk_widget_show (separator);
    }

    quitbox = gtk_hbox_new (FALSE, 0);

    button = gtk_button_new_with_label ("Quit");


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


    gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0);

    gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, FALSE, 0);

    gtk_container_add (GTK_CONTAINER (window), box1);


    gtk_widget_show (button);
    gtk_widget_show (quitbox);

    gtk_widget_show (box1);

    gtk_widget_show (window);


    gtk_main ();

    return 0;
}

  


Example 12. Example MGtk 0.0.1


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


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



    static
    GtkWidget*
    make_box ( gboolean     homogeneous,
               gint         spacing,
               gboolean     expand,
               gboolean     fill,
               guint        padding )
{
    MId box = MNOID;
    MId button[6] = { MNOID, MNOID, MNOID, MNOID, MNOID, MNOID };

    char padstr[80] = { '\0' };


    box = mgtk_hbox_insert ( homogeneous, spacing );


    button[0] = mgtk_button_insert ( "gtk_box_pack" );

    button[1] = mgtk_button_insert ( "(box," );

    button[2] = mgtk_button_insert ( "button," );

    if (expand == TRUE)
    {
	    button[3] = mgtk_button_insert ( "TRUE," );
    }
    else
    {
	    button[3] = mgtk_button_insert ( "FALSE," );
    }

    button[4] = mgtk_button_insert ( fill ? "TRUE," : "FALSE," );


    sprintf (padstr, "%d);", padding);

    button[5] = mgtk_button_insert ( padstr );


    muint index;

    for ( index = 0; index < 6; index++ )
    {
        gtk_box_pack_start ( GTK_BOX( MGTK_HBOX_(box) ),
                             MGTK_BUTTON_( button[index] ),
                                        expand,
                                        fill,
                                        padding );

        gtk_widget_show ( MGTK_BUTTON_( button[index] ) );
    }


    return MGTK_HBOX_(box);
}



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


    MId window       = MNOID;
    MId box1         = MNOID;
    MId quitbox      = MNOID;
    MId quitbutton   = MNOID;

    MId box2[5]      = { MNOID, MNOID, MNOID, MNOID, MNOID };
    MId label[2]     = { MNOID, MNOID };
    MId separator[2] = { MNOID, MNOID };


    int which;


    if (argc != 2) {
	fprintf (stderr, "usage: packbox num, where num is 1, 2, or 3.\n");

	exit (1);
    }

    which = atoi (argv[1]);


    window = mgtk_window_insert ( GTK_WINDOW_TOPLEVEL, NULL );

    box1 = mgtk_vbox_insert ( HOMOGENEOUS_OFF, SPACING_OFF );


    switch (which)
  {
  case 1:

	label[0] = mgtk_label_insert ( "gtk_hbox_new (FALSE, 0);" );

	gtk_misc_set_alignment ( GTK_MISC ( MGTK_LABEL_(label[0]) ), 0, 0 );

    gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_LABEL_(label[0]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );


	box2[0] = mgtk_hbox_insert_attach ( GTK_HBOX ( make_box ( FALSE, 0, FALSE, FALSE, 0 ) ) );

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HBOX_(box2[0]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );

	box2[1] = mgtk_hbox_insert_attach ( GTK_HBOX ( make_box (FALSE, 0, TRUE, FALSE, 0 ) ) );

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HBOX_(box2[1]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );

    box2[2] = mgtk_hbox_insert_attach ( GTK_HBOX ( make_box (FALSE, 0, TRUE, TRUE, 0 ) ) );

    gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HBOX_(box2[2]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );

    separator[0] = mgtk_hseparator_insert ();

    gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HSEPARATOR_(separator[0]),
                                    EXPAND_OFF,
                                    FILL_ON,
                                    5 );


	label[1] = mgtk_label_insert ( "gtk_hbox_new (TRUE, 0);" );

	gtk_misc_set_alignment ( GTK_MISC ( MGTK_LABEL_(label[1]) ), 0, 0 );

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_LABEL_(label[1]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );


	box2[3] = mgtk_hbox_insert_attach ( GTK_HBOX ( make_box (TRUE, 0, TRUE, FALSE, 0 ) ) );

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HBOX_(box2[3]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );

	box2[4] = mgtk_hbox_insert_attach ( GTK_HBOX ( make_box (TRUE, 0, TRUE, TRUE, 0 ) ) );

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HBOX_(box2[4]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );

	separator[1] = mgtk_hseparator_insert ();

    gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HSEPARATOR_(separator[1]),
                                    EXPAND_OFF,
                                    FILL_ON,
                                    5 );


	gtk_widget_show ( MGTK_HSEPARATOR_(separator[0]) );
    gtk_widget_show ( MGTK_HSEPARATOR_(separator[1]) );

    gtk_widget_show ( MGTK_LABEL_(label[0]) );
    gtk_widget_show ( MGTK_LABEL_(label[1]) );

	gtk_widget_show ( MGTK_HBOX_(box2[0]) );
	gtk_widget_show ( MGTK_HBOX_(box2[1]) );
	gtk_widget_show ( MGTK_HBOX_(box2[2]) );
	gtk_widget_show ( MGTK_HBOX_(box2[3]) );
	gtk_widget_show ( MGTK_HBOX_(box2[4]) );

	break;


  case 2:

	label[0] = mgtk_label_insert ( "gtk_hbox_new (FALSE, 10);" );

	gtk_misc_set_alignment ( GTK_MISC ( MGTK_LABEL_(label[0]) ), 0, 0);

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_LABEL_(label[0]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );

    box2[0] = mgtk_hbox_insert_attach ( GTK_HBOX ( make_box (FALSE, 10, TRUE, FALSE, 0 ) ) );

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HBOX_(box2[0]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );


	box2[1] = mgtk_hbox_insert_attach ( GTK_HBOX ( make_box (FALSE, 10, TRUE, TRUE, 0)  ) );

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HBOX_(box2[1]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );

	separator[0] = mgtk_hseparator_insert ();

    gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HSEPARATOR_(separator[0]),
                                    EXPAND_OFF,
                                    FILL_ON,
                                    5 );


	label[1] = mgtk_label_insert ( "gtk_hbox_new (FALSE, 0);" );

	gtk_misc_set_alignment ( GTK_MISC ( MGTK_LABEL_(label[1]) ), 0, 0);

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_LABEL_(label[1]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );


	box2[2] = mgtk_hbox_insert_attach ( GTK_HBOX ( make_box (FALSE, 0, TRUE, FALSE, 10 ) ) );

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HBOX_(box2[2]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );


	box2[3] = mgtk_hbox_insert_attach ( GTK_HBOX ( make_box (FALSE, 0, TRUE, TRUE, 10) ) );

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HBOX_(box2[3]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );

	separator[1] = mgtk_hseparator_insert ();

	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HSEPARATOR_(separator[1]),
                                    EXPAND_OFF,
                                    FILL_ON,
                                    5 );


    gtk_widget_show ( MGTK_HSEPARATOR_(separator[0]) );
	gtk_widget_show ( MGTK_HSEPARATOR_(separator[1]) );

	gtk_widget_show ( MGTK_LABEL_(label[0]) );
	gtk_widget_show ( MGTK_LABEL_(label[1]) );

	gtk_widget_show ( MGTK_HBOX_(box2[0]) );
	gtk_widget_show ( MGTK_HBOX_(box2[1]) );
	gtk_widget_show ( MGTK_HBOX_(box2[2]) );
	gtk_widget_show ( MGTK_HBOX_(box2[3]) );

	break;


  case 3:

	box2[0] = mgtk_hbox_insert_attach ( GTK_HBOX ( make_box ( FALSE, 0, FALSE, FALSE, 0) ) );


	label[0] = mgtk_label_insert ( "end" );

    gtk_box_pack_end ( GTK_BOX( MGTK_HBOX_(box2[0]) ),
                       MGTK_LABEL_(label[0]),
                                EXPAND_OFF,
                                FILL_OFF,
                                PADDING_OFF );


	gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HBOX_(box2[0]),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );


	separator[0] = mgtk_hseparator_insert ();


	gtk_widget_set_size_request ( MGTK_HSEPARATOR_(separator[0]), 400, 5 );

    gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HSEPARATOR_(separator[0]),
                                    EXPAND_OFF,
                                    FILL_ON,
                                    5 );

	gtk_widget_show ( MGTK_HSEPARATOR_(separator[0]) );

    gtk_widget_show ( MGTK_LABEL_(label[0]) );

	gtk_widget_show ( MGTK_HBOX_(box2[0]) );
  }


    quitbox = mgtk_hbox_insert ( HOMOGENEOUS_OFF, SPACING_OFF );


    quitbutton = mgtk_button_insert ( "Quit" );


    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_swapped ( "clicked",
                                        MGTK_BUTTON_(quitbutton),
                                        G_CALLBACK (gtk_main_quit),
                                        MGTK_WINDOW_(window) );


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

    gtk_box_pack_start ( GTK_BOX( MGTK_HBOX_(quitbox) ),
                         MGTK_BUTTON_(quitbutton),
                                    EXPAND_ON,
                                    FILL_OFF,
                                    PADDING_OFF );

    gtk_box_pack_start ( GTK_BOX( MGTK_VBOX_(box1) ),
                         MGTK_HBOX_(quitbox),
                                    EXPAND_OFF,
                                    FILL_OFF,
                                    PADDING_OFF );


    gtk_widget_show ( MGTK_BUTTON_(quitbutton) );
    gtk_widget_show ( MGTK_HBOX_(quitbox) );
    gtk_widget_show ( MGTK_VBOX_(box1) );
    gtk_widget_show ( MGTK_WINDOW_(window) );


    gtk_main ();

    return 0;
}