Annotation of uae/src/gui-gtk/util.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * util.c
        !             3:  *
        !             4:  * Copyright 2003-2004 Richard Drummond
        !             5:  */
        !             6: 
        !             7: #include <sys/types.h>
        !             8: #include <sys/stat.h>
        !             9: #include <unistd.h>
        !            10: #include <string.h>
        !            11: 
        !            12: #include <gdk/gdkkeysyms.h>
        !            13: #include <gtk/gtk.h>
        !            14: 
        !            15: #include "util.h"
        !            16: 
        !            17: /*
        !            18:  * Some utility functions to make building a GTK+ GUI easier
        !            19:  * and more compact, to hide differences between GTK1.x and GTK2.x
        !            20:  * and to help maintain consistency
        !            21:  */
        !            22: 
        !            23: GtkWidget *make_chooser (int count, ...)
        !            24: {
        !            25:     GtkWidget *chooser;
        !            26:     va_list   choices;
        !            27:     int       i;
        !            28: 
        !            29:     chooser = gtk_combo_box_new_text ();
        !            30: 
        !            31:     va_start (choices, count);
        !            32:     for (i = 0; i < count; i++)
        !            33:        gtk_combo_box_append_text (GTK_COMBO_BOX (chooser), va_arg (choices, char *));
        !            34: 
        !            35:     gtk_widget_show (chooser);
        !            36:     return chooser;
        !            37: }
        !            38: 
        !            39: /*
        !            40:  * Add some padding to a vbox or hbox which will consume
        !            41:  * space when the box is resized to larger than default size
        !            42:  */
        !            43: void add_box_padding (GtkWidget *box)
        !            44: {
        !            45:     GtkWidget *vbox;
        !            46: 
        !            47:     vbox = gtk_vbox_new (FALSE, 0);
        !            48:     gtk_widget_show (vbox);
        !            49:     gtk_box_pack_start (GTK_BOX (box), vbox, TRUE, TRUE, 0);
        !            50: }
        !            51: 
        !            52: /*
        !            53:  * Add some padding to a table which will consime space when
        !            54:  * when the table is resized to larger than default size
        !            55:  */
        !            56: void add_table_padding (GtkWidget *table, int x, int y)
        !            57: {
        !            58:     GtkWidget *vbox;
        !            59:     vbox = gtk_vbox_new (FALSE, 0);
        !            60:     gtk_widget_show (vbox);
        !            61:     gtk_table_attach (GTK_TABLE (table), vbox, x, x+1, y, y+1,
        !            62:                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
        !            63:                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0);
        !            64: }
        !            65: 
        !            66: /*
        !            67:  * Add a widget to a table with some sensible defaults
        !            68:  *
        !            69:  * <x,y> is the table position to insert the widget
        !            70:  * <width> is the the number of columns the widget will take up
        !            71:  * <xflags> are the attachment flags that will apply horizontally
        !            72:  */
        !            73: void add_to_table(GtkWidget *table, GtkWidget *widget, int x, int y, int width, int xflags)
        !            74: {
        !            75:   gtk_table_attach (GTK_TABLE (table), widget, x, x+width, y, y+1,
        !            76:                   (GtkAttachOptions) (xflags),
        !            77:                   (GtkAttachOptions) (0), 0, 0);
        !            78: }
        !            79: 
        !            80: 
        !            81: /*
        !            82:  * Super-duper, handy table creation tool!
        !            83:  *
        !            84:  * Creates a table and add a list of widgets to it.
        !            85:  */
        !            86: GtkWidget *gtkutil_add_table (GtkWidget *container, ...)
        !            87: {
        !            88:     va_list contents;
        !            89:     GtkWidget *widget;
        !            90:     GtkWidget *table;
        !            91:     int row, max_col;
        !            92:     int col, width;
        !            93:     int flags;
        !            94: 
        !            95:     table = gtk_table_new (3, 3, FALSE);
        !            96:     gtk_container_set_border_width (GTK_CONTAINER (table), TABLE_BORDER_WIDTH);
        !            97:     gtk_table_set_row_spacings (GTK_TABLE (table), TABLE_ROW_SPACING);
        !            98:     gtk_table_set_col_spacings (GTK_TABLE (table), TABLE_COL_SPACING);
        !            99:     gtk_container_add (GTK_CONTAINER (container), table);
        !           100: 
        !           101:     va_start (contents, container);
        !           102:     widget = va_arg (contents, GtkWidget *);
        !           103:     row = 1;
        !           104:     max_col = 1;
        !           105: 
        !           106:     while (widget != GTKUTIL_TABLE_END) {
        !           107:        if (widget == GTKUTIL_ROW_END) {
        !           108:            row += 2;
        !           109:        } else {
        !           110:            col = va_arg (contents, gint);
        !           111:            if (col > max_col) max_col = col;
        !           112:            width = va_arg (contents, gint);
        !           113:            flags = va_arg (contents, gint);
        !           114: 
        !           115:            gtk_table_attach (GTK_TABLE (table), widget, col, col+width, row, row+1,
        !           116:                              (GtkAttachOptions) (flags), (GtkAttachOptions) (0), 0, 0);
        !           117:        }
        !           118:        widget = va_arg (contents, GtkWidget *);
        !           119:     }
        !           120: 
        !           121:     gtk_table_resize (GTK_TABLE (table), row, max_col + 2);
        !           122:     add_table_padding (table, 0, 0);
        !           123:     add_table_padding (table, max_col + 1, row - 1);
        !           124: 
        !           125:     gtk_widget_show_all (table);
        !           126: 
        !           127:     return table;
        !           128: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.