Re: [gtk-list] another silly question?




On Fri, 8 May 1998, jb wrote:

> Hi,
> 
> 	i have not the source at hand, so i might as well as here... it
> there a way to disable signals emission in Gtk? This would be useful in
> the following case: say i have a text widget with an associated callback
> for the "changed" signal, then if in the callback function i modify the
> contents of the text box, that callback function will be invoked again,
> and since it's not reentrant it'll crash...

This is mostly not a problem.  The text widget doesn't send the "changed"
signal when you call it directly.  It only sends the changed signal if the
widget changes in response to the user.

> 	Another question: does anyone use dynamic menus? I have one
> menu on which entries are added and deleted at runtime, and it looks
> like it's confusing Gtk..

I do.  I use a menufactory and I keep the factory around so the code is as
follows (This assumes that all entries in this menu at one time are
unique.  This is untested.  The menu is called "Window".):

void remove_from_menu( GtkMenuFactory menubar, gchar
*menuitemtitle )
{
  gchar *path = g_malloc0( strlen( menuitemtitle ) + 8 );

  sprintf( path, "%s%s", "Window/", menuitemtitle );
  gtk_menu_factory_remove_paths( menubar, &path, 1 );
  g_free( path );
}

void add_to_menu( GtkMenuFactory menubar, 
gchar *menuitemtitle, gchar *accelerator, GtkMenuCallback callback, 
gpointer callback_data)
{
  GtkMenuEntry *new_menu_entry = g_malloc0( sizeof( GtkMenuEntry ) );
  
  new_menu_entry->path = g_malloc0( strlen( menuitemtitle ) + 8 );
  sprintf( new_menu_entry->path, "%s%s", "Window/", menuitemtitle );

  new_menu_entry->accelerator = accelerator;
  new_menu_entry->callback = callback;
  new_menu_entry->callback_data = callback_data;
  new_menu_entry->widget = 0;

  gtk_menu_factory_add_entries( menubar, new_menu_entry, 1 );
}




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