icons and labels in gtk_notebook?
- From: Jan Struyf <jeans ulyssis org>
- To: <gtk-app-devel-list gnome org>
- Subject: icons and labels in gtk_notebook?
- Date: Sun, 19 Jan 2003 22:00:00 +0100 (CET)
Hi,
I'd like to use a gtk_notebook with an icon and a label as label for each
tab. I have included an example in the code below (still 1.2 code).
The problem is that if I change the text in the label from a long string
to a short string the size of the tab does not change.
E.g.:
+---------------------------+
| [ICON] Long Label For Tab |
+---------------------------+---------------------------+
| ... |
Becomes (after changing label to "Test"):
+---------------------------+
| [ICON] Test |
+---------------------------+---------------------------+
| ... |
And not:
+-------------+
| [ICON] Test |
+---------------------------+---------------------------+
| ... |
What am I doing wrong?
The code I've used to test is below.
Best Regards,
Jan Struyf.
----------------------------------------------------------------
#include <gtk/gtk.h>
static const char * xpm_data[] = {
"16 16 3 1",
" c None",
". c #000000000000",
"X c #FFFFFFFFFFFF",
" ",
" ...... ",
" .XXX.X. ",
" .XXX.XX. ",
" .XXX.XXX. ",
" .XXX..... ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" .XXXXXXX. ",
" ......... ",
" ",
" "};
typedef struct {
GtkWidget* entry;
GtkWidget* label;
} MyTabData;
void setlabel(GtkWidget *widget, gpointer data) {
char* txt;
MyTabData *tab_data = (MyTabData *)data;
txt = gtk_entry_get_text(GTK_ENTRY(tab_data->entry));
gtk_label_set_text(GTK_LABEL(tab_data->label), txt);
}
int main(int argc, char *argv[]) {
GtkWidget *window, *button, *nb, *box, *tab_box, *tab_icon;
GdkPixmap *pixmap;
GdkBitmap *mask;
GtkStyle *style;
MyTabData data;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
gtk_widget_realize(window);
style = gtk_widget_get_style(window);
pixmap = gdk_pixmap_create_from_xpm_d(window->window, &mask,
&style->bg[GTK_STATE_NORMAL],
(gchar **)xpm_data);
data.label = gtk_label_new("Hello");
data.entry = gtk_entry_new();
tab_box = gtk_hbox_new(FALSE, 3);
tab_icon = gtk_pixmap_new(pixmap, mask);
gtk_box_pack_start(GTK_BOX(tab_box), tab_icon, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(tab_box), data.label, FALSE, FALSE, 0);
gtk_widget_show(tab_box);
gtk_widget_show(tab_icon);
gtk_widget_show(data.label);
gtk_widget_show(data.entry);
nb = gtk_notebook_new();
box = gtk_hbox_new(FALSE, 3);
button = gtk_button_new_with_label("Modify");
gtk_signal_connect(GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC(setlabel), &data);
gtk_box_pack_start(GTK_BOX(box), data.entry, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
gtk_notebook_append_page(GTK_NOTEBOOK(nb), box, tab_box);
gtk_widget_show(button);
gtk_widget_show(box);
gtk_widget_show(nb);
gtk_container_add(GTK_CONTAINER(window), nb);
gtk_widget_show(window);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]