Example 4_b

Example 4_b — From Gtk to MGtk

Description

Example 13. Example b 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
    MIdArchive*
    make_box ( gboolean     homogeneous,
               gint         spacing,
               gboolean     expand,
               gboolean     fill,
               guint        padding )
{
    GtkWidget* box = NULL;

    MId button[6] = { MNOID, MNOID, MNOID, MNOID, MNOID, MNOID };

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

    MIdArchive* archive = mgtk_idarchive_new ();


    box = gtk_hbox_new ( 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, "%u);", padding );

    button[5] = mgtk_button_insert ( padstr );


    muint index;

    fortooffset ( index, 6 )
    {
        gtk_box_pack_start ( GTK_BOX( box ),
                             MGTK_BUTTON_( button[index] ),
                                        expand,
                                        fill,
                                        padding );

        gtk_widget_show ( MGTK_BUTTON_( button[index] ) );

        sprintf ( padstr, "button[%u]", index );

        MGTK_BUTTON_ARCHIVE_ID ( archive, button[index], g_strdup (padstr) );
    }

    M_IDARCHIVE_data (archive) = (MPublic)box;

    return archive;
}



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

    MIdArchive* archive[5] = { NULL, NULL, NULL, NULL, NULL };

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

    archive[0] = make_box ( FALSE, 0, FALSE, FALSE, 0 );

	box2[0] = mgtk_hbox_insert_attach ( GTK_HBOX ( M_IDARCHIVE_data (archive[0]) ) );

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

    archive[1] = make_box ( FALSE, 0, TRUE, FALSE, 0 );

	box2[1] = mgtk_hbox_insert_attach ( GTK_HBOX ( M_IDARCHIVE_data (archive[1]) ) );

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

    archive[2] = make_box ( FALSE, 0, TRUE, TRUE, 0 );

	box2[2] = mgtk_hbox_insert_attach ( GTK_HBOX ( M_IDARCHIVE_data (archive[2]) ) );

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

    archive[3] = make_box ( TRUE, 0, TRUE, FALSE, 0 );

	box2[3] = mgtk_hbox_insert_attach ( GTK_HBOX ( M_IDARCHIVE_data (archive[3]) ) );

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

    archive[4] = make_box ( TRUE, 0, TRUE, TRUE, 0 );

	box2[4] = mgtk_hbox_insert_attach ( GTK_HBOX ( M_IDARCHIVE_data (archive[4]) ) );

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

    archive[0] = make_box ( FALSE, 10, TRUE, FALSE, 0 );

	box2[0] = mgtk_hbox_insert_attach ( GTK_HBOX ( M_IDARCHIVE_data (archive[0]) ) );

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

    archive[1] = make_box ( FALSE, 10, TRUE, TRUE, 0 );

	box2[1] = mgtk_hbox_insert_attach ( GTK_HBOX ( M_IDARCHIVE_data (archive[1]) ) );

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

    archive[2] = make_box ( FALSE, 0, TRUE, FALSE, 10 );

	box2[2] = mgtk_hbox_insert_attach ( GTK_HBOX ( M_IDARCHIVE_data (archive[2]) ) );

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

    archive[3] = make_box ( FALSE, 0, TRUE, TRUE, 10 );

	box2[3] = mgtk_hbox_insert_attach ( GTK_HBOX ( M_IDARCHIVE_data (archive[3]) ) );

	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:

    archive[0] = make_box ( FALSE, 0, FALSE, FALSE, 0 );

	box2[0] = mgtk_hbox_insert_attach ( GTK_HBOX ( M_IDARCHIVE_data (archive[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) );

    muint i, index;

    fortooffset ( i, 5 )
    {
      if ( archive[i] != NULL )
      {
        g_print ( "\n\n\n archive[%u] : %p \n", i, archive[i] );

        fortooffset ( index, 6 )
        {
            g_print ( "\n   index(%u) - label: %s \n",
                index,
                M_IDARCHIVE_GET_LABEL_FROM_IDELEMENT ( archive[i], index) );
        }
      }
    }

    gtk_main ();

    return 0;
}