problem w/ composite notebook tabs



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

I have a notebook, and one of the tabs has some buttons on it.

This works just fine.

However, I have the situation where I want to desensitize on of the buttons
(depending upon application state, the button should be unavailable).

So I save off a pointer to the button, and desensitize/sensitize it as
appropriate. and THIS works just as expected as well.

BUT... One of the side effects of desensitizing a button in a label, is that it
seems that the remaining buttons to the right of the desensitized button will
ALSO become desensitized when the tab is selected. (Conversely, when the button
is re-sensitized, selecting the tab will propagate the sensitivity to the
buttons on the right as well).

I should hasten to add that if I use simple images, instead of buttons, then
this problem does not persist. In other words, with simple images, desensitizing
one, does not desensitize it's sibling to the right. (I'm using buttons because
I need the callback.  :)

I have modified the gtk2/examples/notebook example, and attached it for the
curious, as clarification.

I'm presently trying to understand this behavior by running this sample under
the debugger, and breakpointing inside of the gtk library, to catch it when the
library is desensitizing the button(s) to the right of the desensitized button.
I'm still working on tracing this thru the debugger.

In the meantime, I'm curious as to whether the behavior I'm seeing is to be
expected (well... I guess I didn't expect it  :)

Any thoughts, comments are appreciated,

- -Greg

- --
+---------------------------------------------------------------------+

Please also check the log file at "/dev/null" for additional information.
		(from /var/log/Xorg.setup.log)

| Greg Hosler					ghosler redhat com    |
+---------------------------------------------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQFHGv7V404fl/0CV/QRAvuIAJ0bNO+WJcZrHNocQoQcaO/ojHVfUwCfQ0NP
fl/wSGbx5U95ybJlQVhmElE=
=m67N
-----END PGP SIGNATURE-----
CC = gcc

CFLAGS = -g -Wall			\
	-DG_DISABLE_DEPRECATED 	 	\
	-DGDK_DISABLE_DEPRECATED 	\
	-DGDK_PIXBUF_DISABLE_DEPRECATED \
	-DGTK_DISABLE_DEPRECATED

notebook: notebook.c 
	$(CC) notebook.c -o notebook $(CFLAGS) `pkg-config gtk+-2.0 --cflags --libs`

clean: 
	rm -f *.o notebook
#include <stdio.h>
#include <gtk/gtk.h>

GtkWidget *window;
GtkWidget *table;
GtkWidget *notebook;

static gboolean delete( GtkWidget *widget,
                        GtkWidget *event,
                        gpointer   data )
{
    gtk_widget_destroy(notebook);
    gtk_widget_destroy(table);
    gtk_widget_destroy(window);
    gtk_main_quit ();
    return FALSE;
}

GtkWidget *icon2;
GtkWidget *icon3;

int icon_state = 0;
void on_toggle_clicked(GtkToggleButton *checkbutton,
			   gpointer user_data)
{
    gtk_widget_set_sensitive(icon2, icon_state);
    icon_state = !icon_state;
}


GtkWidget *get_stocki_button(const gchar *stock_id, GtkIconSize size) {
	GtkWidget *im_menu;

#define BUTTON
#ifdef BUTTON
	im_menu = gtk_button_new();
	gtk_container_add(GTK_CONTAINER(im_menu), GTK_WIDGET(gtk_image_new_from_stock(stock_id, size) ));
	gtk_button_set_relief(GTK_BUTTON(im_menu), GTK_RELIEF_NONE); 
#else
	im_menu = gtk_image_new_from_stock(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
#endif

	return im_menu;
}


GtkWidget *create_quick_access_bar() {
 	GtkWidget *mainy;
	GtkWidget *im_menu;

 	mainy = gtk_hbox_new (FALSE, 0);
	gtk_box_set_spacing (GTK_BOX (mainy), 1);

	im_menu = get_stocki_button(GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_MENU);
	gtk_box_pack_start(GTK_BOX(mainy), im_menu, FALSE, FALSE, 0);

	gtk_box_pack_start(GTK_BOX(mainy), gtk_vseparator_new(), FALSE, FALSE, 0);

	im_menu = get_stocki_button(GTK_STOCK_NEW, GTK_ICON_SIZE_MENU);
	gtk_box_pack_start(GTK_BOX(mainy), im_menu, FALSE, FALSE, 0);


	im_menu = get_stocki_button(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_MENU);
	gtk_box_pack_start(GTK_BOX(mainy), im_menu, FALSE, FALSE, 0);

	gtk_box_pack_start(GTK_BOX(mainy), gtk_vseparator_new(), FALSE, FALSE, 0);

	im_menu = get_stocki_button(GTK_STOCK_FIND_AND_REPLACE, GTK_ICON_SIZE_MENU);
	gtk_box_pack_start(GTK_BOX(mainy), im_menu, FALSE, FALSE, 0);

	im_menu = get_stocki_button(GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU);
	gtk_box_pack_start(GTK_BOX(mainy), im_menu, FALSE, FALSE, 0);

	im_menu = get_stocki_button(GTK_STOCK_CONVERT, GTK_ICON_SIZE_MENU);
	icon2=im_menu;
	gtk_box_pack_start(GTK_BOX(mainy), im_menu, FALSE, FALSE, 0);

	im_menu = get_stocki_button(GTK_STOCK_CLEAR, GTK_ICON_SIZE_MENU);
	gtk_box_pack_start(GTK_BOX(mainy), im_menu, FALSE, FALSE, 0);

	gtk_box_pack_start(GTK_BOX(mainy), gtk_vseparator_new(), FALSE, FALSE, 0);

	im_menu = get_stocki_button(GTK_STOCK_YES, GTK_ICON_SIZE_MENU);
	gtk_box_pack_start(GTK_BOX(mainy), im_menu, FALSE, FALSE, 0);
	icon3= im_menu;

	im_menu = get_stocki_button(GTK_STOCK_CDROM, GTK_ICON_SIZE_MENU);
	gtk_box_pack_start(GTK_BOX(mainy), im_menu, FALSE, FALSE, 0);

	gtk_widget_show_all(mainy);
	return mainy;
}


static gint on_notebook_before_switch_page_cb(GtkWidget *notebook, GtkWidget *page, int page_num, gpointer d)
{
    printf("on_notebook_before_switch_page_cb: page: %d\n", page_num);
    return 0;
}

static gint on_notebook_switch_page_cb(GtkWidget *n, GtkWidget *p, int page_num, gpointer d)
{
    printf("on_notebook_before_page_cb: page: %d\n", page_num);
    return 0;
}


int main( int argc,
          char *argv[] )
{
    GtkWidget *button;
    GtkWidget *frame;
    GtkWidget *label;
    GtkWidget *checkbutton;
    int i;
    char bufferf[32];
    char bufferl[32];
    
    gtk_init (&argc, &argv);
    
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    
    g_signal_connect (G_OBJECT (window), "delete_event",
	              G_CALLBACK (delete), NULL);
    
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);

    table = gtk_table_new (3, 6, FALSE);
    gtk_container_add (GTK_CONTAINER (window), table);
    
    /* Create a new notebook, place the position of the tabs */
    notebook = gtk_notebook_new ();
    gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
    gtk_table_attach_defaults (GTK_TABLE (table), notebook, 0, 6, 0, 1);
    gtk_widget_show (notebook);

    g_signal_connect(G_OBJECT(notebook), "switch_page",
			 G_CALLBACK(on_notebook_before_switch_page_cb), NULL);
    g_signal_connect_after(G_OBJECT(notebook), "switch_page",
			       G_CALLBACK(on_notebook_switch_page_cb), NULL);

    /* Let's append a bunch of pages to the notebook */
    for (i = 0; i < 3; i++) {
	sprintf(bufferf, "Append Frame %d", i + 1);
	sprintf(bufferl, "Page %d", i + 1);
	
	frame = gtk_frame_new (bufferf);
	gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
	gtk_widget_set_size_request (frame, 100, 75);
	gtk_widget_show (frame);
	
	label = gtk_label_new (bufferf);
	gtk_container_add (GTK_CONTAINER (frame), label);
	gtk_widget_show (label);
	
	label = gtk_label_new (bufferl);
	gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
    }
      
    /* Now let's add a page to a specific spot */
    checkbutton = gtk_check_button_new_with_label ("Check me please!");
    gtk_widget_set_size_request (checkbutton, 100, 75);
    gtk_widget_show (checkbutton);
   
    GtkWidget *lhbox1;
    GtkWidget *icon1;

    g_object_set(notebook,"homogeneous", FALSE, NULL);
    lhbox1 = gtk_hbox_new (FALSE, 0);
    gtk_box_pack_start(GTK_BOX(lhbox1), gtk_label_new("Add Page") , FALSE, FALSE, 0);
    icon1 = gtk_image_new_from_stock(GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_MENU);
    gtk_box_pack_start(GTK_BOX(lhbox1), icon1, FALSE, FALSE, 0);

    GtkWidget *widgy;
    GtkWidget *lhbox2;

    lhbox2 = create_quick_access_bar();

    widgy = gtk_hbox_new (FALSE, 0);
    gtk_box_set_spacing (GTK_BOX (widgy), 1);
    gtk_box_pack_start(GTK_BOX(widgy), lhbox1, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(widgy), gtk_label_new("    "), FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(widgy), lhbox2, FALSE, FALSE, 0);

    gtk_widget_show_all(widgy);
    gtk_notebook_insert_page (GTK_NOTEBOOK (notebook), checkbutton, widgy, 2);
    
    /* Set what page to start at (page 4) */
    gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), 1);

    /* Create a bunch of buttons */
    button = gtk_button_new_with_label ("close");
    g_signal_connect_swapped (G_OBJECT (button), "clicked",
			      G_CALLBACK (delete), NULL);
    gtk_table_attach_defaults (GTK_TABLE (table), button, 0, 1, 1, 2);
    gtk_widget_show (button);
    
    button = gtk_button_new_with_label ("next page");
    g_signal_connect_swapped (G_OBJECT (button), "clicked",
			      G_CALLBACK (gtk_notebook_next_page),
			      G_OBJECT (notebook));
    gtk_table_attach_defaults (GTK_TABLE (table), button, 1, 2, 1, 2);
    gtk_widget_show (button);
    
    button = gtk_button_new_with_label ("prev page");
    g_signal_connect_swapped (G_OBJECT (button), "clicked",
			      G_CALLBACK (gtk_notebook_prev_page),
			      G_OBJECT (notebook));
    gtk_table_attach_defaults (GTK_TABLE (table), button, 2, 3, 1, 2);
    gtk_widget_show (button);
    
    button = gtk_button_new_with_label ("toggle sensitivity");
    g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (on_toggle_clicked),
                      (gpointer) notebook);
    gtk_table_attach_defaults (GTK_TABLE (table), button, 3, 4, 1, 2);
    gtk_widget_show (button);
    
    gtk_widget_show (table);
    gtk_widget_show (window);
    
    gtk_main ();
    
    return 0;
}


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