Problem with button sizing.



Hi all,

I'm having problems getting the mode window for my gcalctool calculator to
have the correct size buttons in it. 

Here's a screenshot of what I'm trying to achieve (old version using XView):

  http://calctool.sourceforge.net/Screenshots/calctool_ss.gif

You will notice the Scientific Mode window has two rows of eight buttons
but there are only seven buttons on the top row and six on the bottom. The
buttons are a consistent size with the buttons in the main calculator window.

Here's a screen shot of what it currently looks like with Gtk2:

  http://calctool.sourceforge.net/Screenshots/gcalctool_ss.gif

You will notice that the seven buttons on the top row have expanded to
fill up the available space.

I've written a small app to try to reproduce this problem (included below). 
I've tried various combinations of TRUE and FALSE for the arguments to 
gtk_window_set_policy(). I've also tried using GtkSizeGroup with no success.

I'd really appreciate somebody showing me how to achieve what I want here.
In other words, how can you get a button that isn't visible, to take up
space.

Thanks.

--

/* Built with:
 gcc -o sample -g `pkg-config --cflags gtk+-2.0` sample.c `pkg-config --libs 
gtk+-2.0`
 */

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

#define MCOLS 8
#define MROWS 2

char *mode_buttons[MCOLS * MROWS] = {
    "Trig", "Hyp ", "Inv ", "e^x ", "10^x", "y^x ", "x!  ", "    ",
    "Cos ", "Sin ", "Tan ", "Ln  ", "Log ", "Rand", "    ", "    ", 
};

GtkWidget *buttons[MROWS * MCOLS];
GtkWidget *kframe;  

static void make_mtable(GtkWidget *frame, GtkWidget *vbox)
{
    int i, j, n;
    GtkWidget *table = gtk_table_new(MROWS, MCOLS, FALSE);

    gtk_widget_ref(table);
    gtk_widget_show(table);
    gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);

    for (i = 0; i < MCOLS; i++) {
        for (j = 0; j < MROWS; j++) {
            n = j*MCOLS + i;
            buttons[n] = gtk_button_new_with_label(mode_buttons[n]);
            gtk_widget_ref(buttons[n]);

            if (strcmp(mode_buttons[n], "    ")) {
                gtk_widget_show(buttons[n]);
            }
            gtk_table_attach(GTK_TABLE(table), buttons[n],
                             i, i+1, j, j+1,
                             (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
                             (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 4, 4);
            gtk_widget_set_size_request(buttons[n], 60, 28);
        }
    }
}

void create_kframe()
{
    int i, k;
    GtkWidget *hbox, *vbox;

    kframe = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_policy(GTK_WINDOW(kframe), TRUE, TRUE, TRUE);
    vbox = gtk_vbox_new(FALSE, 0);
    gtk_widget_ref(vbox);
    gtk_widget_show(vbox);
    gtk_container_add(GTK_CONTAINER(kframe), vbox);
    make_mtable(kframe, vbox);
}

int main(int argc, char **argv)
{
    bindtextdomain("sample", "/usr/local/lib/locale");
    textdomain("sample");
    gtk_set_locale();
    gtk_init(&argc, &argv);
    create_kframe();
    gtk_widget_show(kframe);
    gtk_main();
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]