gtknotebook issue




Hi,

I have a little test program with a notebook as the
main app contents, and each page I add is a Vbox
containing a ("sub") notebook.

  --Notebook----------------------------
 |  --Vbox----------    --Vbox----------
 | |  --Notebook--  |  |  --Notebook--  |
 | | |            | |  | |            | |


I found that when I do the following in a menu callback,

  w = gtk_vbox_new(TRUE, 0);
  setup(w);        /* Insert a notebook inside the vbox */
  gtk_widget_show(w);
  label = gtk_label_new (_("Untitled"));
  gtk_notebook_append_page(GTK_NOTEBOOK(notebook), w, label);
  gtk_notebook_set_page(GTK_NOTEBOOK(notebook), -1);

That last call triggers an assertion,

  Gtk-CRITICAL **: file gtkwidget.c: line 1584 (gtk_widget_map): assertion
  `GTK_WIDGET_VISIBLE (widget) == TRUE' failed.

for every page added after the first one.  The widget that Gtk
is complaining about is the label on the "inner" notebook page.

With GDB I tracked down the call to gtk_widget_map() to
gtknotebook.c,

 static void
 gtk_notebook_map (GtkWidget *widget)
     ...
	  if (page->tab_label && 
	      GTK_WIDGET_VISIBLE (page->child) && 
	      !GTK_WIDGET_MAPPED (page->tab_label))
	    gtk_widget_map (page->tab_label);

I don't pretend to understand all the logic going on, but can
anyone explain why it checks "GTK_WIDGET_VISIBLE (page->child)" 
when dealing with "page->tab_label"? 

Replacing it with "GTK_WIDGET_VISIBLE (page->tab_label)"
makes the assertion go away, but I don't know if this 
is a bad thing to do.

Any advice?

$ gtk-config --version
1.2.6

-Jamie
#include <gnome.h>

static GtkWidget *app;		/* GnomeApp */
static GtkWidget *notebook;
static GtkWidget *status;

static gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
  /* signal the main loop to quit */
  gtk_main_quit();
  /* return FALSE to continue closing the window */
  return FALSE;
}

static void setup(GtkWidget *widget)
{
  GtkWidget *sub_notebook;
  GtkWidget *frame;
  GtkWidget *label;

  sub_notebook =  gtk_notebook_new();
  gtk_notebook_set_tab_pos (GTK_NOTEBOOK (sub_notebook), GTK_POS_TOP);
  frame = gtk_frame_new("Test");
  label = gtk_label_new("Tab");
  gtk_notebook_append_page(GTK_NOTEBOOK(sub_notebook),
  			   GTK_WIDGET(frame),
  			   label);
  gtk_box_pack_start(GTK_BOX(widget), sub_notebook, TRUE, TRUE, 0);
  gtk_widget_show_all(sub_notebook);
  
}

static void new_cb(GtkWidget *widget, gpointer data)
{
  GtkWidget *w;
  GtkWidget *label;

  w = gtk_vbox_new(TRUE, 0);

  setup(w);

  gtk_widget_show(w);

  label = gtk_label_new (_("Untitled"));
  gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
  			   w,
  			   label);
  gtk_notebook_set_page(GTK_NOTEBOOK(notebook), -1);
}

static void open_cb(GtkWidget *widget, gpointer data)
{
}

static void save_cb(GtkWidget *widget, gpointer data)
{
}

static void save_as_cb(GtkWidget *widget, gpointer data)
{
}

static void close_cb(GtkWidget *widget, gpointer data)
{
}

static void exit_cb(GtkWidget *widget, gpointer data)
{
  gtk_main_quit();
}


static GnomeUIInfo file_menu[] = {
  GNOMEUIINFO_MENU_NEW_ITEM(N_("_New"),
			    N_("Create a new clock"),
			    new_cb, NULL),
  GNOMEUIINFO_MENU_OPEN_ITEM(open_cb, NULL),
  GNOMEUIINFO_MENU_SAVE_ITEM(save_cb, NULL),
  GNOMEUIINFO_MENU_SAVE_AS_ITEM(save_as_cb, NULL),
  GNOMEUIINFO_SEPARATOR,
  GNOMEUIINFO_MENU_CLOSE_ITEM(close_cb, NULL),
  GNOMEUIINFO_MENU_EXIT_ITEM(exit_cb, NULL),
  GNOMEUIINFO_END
};

static GnomeUIInfo main_menu[] = {
  GNOMEUIINFO_MENU_FILE_TREE(file_menu),
  GNOMEUIINFO_END
};


int main(int argc, char *argv[])
{
 
  /* Initialize GNOME, this is very similar to gtk_init */

  gnome_init ("nbtest2", "0.0", argc, argv); 
  
  app = gnome_app_new ("nbtest2",
		       "nbtest2");

  gtk_window_set_title(GTK_WINDOW(app), _("nbtest2"));
  gtk_window_set_policy(GTK_WINDOW(app), TRUE, TRUE, TRUE);
  gtk_window_set_wmclass(GTK_WINDOW(app), "nbtest2", "nbtest2");

  gtk_signal_connect (GTK_OBJECT (app), "delete_event",
		      GTK_SIGNAL_FUNC (delete_event),
		      NULL);
  status = gnome_appbar_new(FALSE, TRUE, GNOME_PREFERENCES_NEVER);
  gnome_app_set_statusbar(GNOME_APP(app), status);
  gnome_app_create_menus_with_data(GNOME_APP(app), main_menu, app);
  gnome_app_install_menu_hints(GNOME_APP(app), main_menu);


  notebook =  gtk_notebook_new();
  gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);

  gnome_app_set_contents(GNOME_APP(app), GTK_WIDGET(notebook));

  new_cb(app, NULL);
  gtk_widget_show_all(app);

  gtk_main();
  return 0;
}


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