Re: [gtk-list] Re: GtkToolbar



On Sun, Mar 28, 1999 at 11:53:22PM -0500, Owen Taylor wrote:
...
> 
> Hmmm, it looks like you've found a hole in the GtkToolbar API -
> there is no way to remove or hide spaces.
> 
> Right now, it looks like the cleanest way would be to destroy
> the toolbar and recreate it.
> 
> There probably should be a gtk_toolbar_remove_item() call.
> (Patches solicited...)
> 

and i happen to have such a patch.  it's probably not 100% perfect (or
rather, not 100% GTK conforming), but i think the idea is correct.
please take a look and include, modify, et al., as you see fit.

regards,
--andy

*** gtktoolbar.c.ORIG	Wed Feb 24 05:15:13 1999
--- gtktoolbar.c	Mon Mar 29 17:37:08 1999
***************
*** 1107,1109 ****
--- 1107,1180 ----
        gtk_widget_queue_resize (GTK_WIDGET (toolbar));
      }
  }
+ 
+ 
+ /*
+  * gtk_toolbar_remove_item - remove a toolbar item, either by the toolbar text,
+  * a pointer to the widget item itself, or a zero-based index.
+  *
+  * 'type' is the toolbar data type
+  * 'data' can be one of the following and is governed by the data type:
+  *	- the toolbar label text
+  *	- a pointer to a widget, representing the toolbar item to remove
+  *	- an integer representing the index (zero-based) of the item to remove
+  */
+ void
+ gtk_toolbar_remove_item(GtkToolbar *tb, GtkToolbarDataType type, gpointer data)
+ {
+ 	GtkContainer *container;
+ 	GList *children;
+ 	GtkToolbarChild *child;
+ 	gboolean found;
+ 	int idx;
+ 
+ 	g_return_if_fail(tb != NULL);
+ 	g_return_if_fail(GTK_IS_TOOLBAR(tb));
+ 	container = GTK_CONTAINER(&tb->container);
+ 
+ 	for (found = FALSE, idx = 0, children = tb->children;
+ 	     children;
+ 	     idx++, children = children->next) {
+ 
+ 		child = (GtkToolbarChild *)children->data;
+ 
+ 		switch (type) {
+ 		case GTK_TOOLBAR_DATA_TEXT:
+ 			if (child->label && GTK_LABEL(child->label)->label &&
+ 			    strcmp(GTK_LABEL(child->label)->label,
+ 			    	   (const char *)data) == 0)
+ 				found = TRUE;
+ 			break;
+ 		case GTK_TOOLBAR_DATA_WIDGET:
+ 			if (child->type != GTK_TOOLBAR_CHILD_SPACE &&
+ 			    child->widget == GTK_WIDGET(data))
+ 				found = TRUE;
+ 			break;
+ 		case GTK_TOOLBAR_DATA_INDEX:
+ 			if (idx == (int)data)
+ 				found = TRUE;
+ 			break;
+ 		default:
+ 			g_warning("gtk_toolbar_remove_item: Unknown data type "
+ 				  "(%d)", type);
+ 		}
+ 
+ 		if (found) {
+ 			gboolean was_visible;
+ 
+ 			was_visible = GTK_WIDGET_VISIBLE(child->widget);
+ 			gtk_widget_unparent(child->widget);
+ 
+ 			tb->children = g_list_remove_link(tb->children,
+ 							  children);
+ 			g_free(child);
+ 			g_list_free(children);
+ 			tb->num_children--;
+ 
+ 			if (was_visible && GTK_WIDGET_VISIBLE(container))
+ 				gtk_widget_queue_resize(GTK_WIDGET(container));
+ 
+ 			break;
+ 		}
+ 	}
+ } /* gtk_toolbar_remove_item */
*** gtktoolbar.h.ORIG	Wed Feb 24 05:15:13 1999
--- gtktoolbar.h	Mon Mar 29 17:30:30 1999
***************
*** 55,60 ****
--- 55,70 ----
    GTK_TOOLBAR_CHILD_WIDGET
  } GtkToolbarChildType;
  
+ /*
+  * when removing an item from the toolbar, these represent what type of item to
+  * look for when removing.
+  */
+ typedef enum {
+ 	GTK_TOOLBAR_DATA_TEXT,
+ 	GTK_TOOLBAR_DATA_WIDGET,
+ 	GTK_TOOLBAR_DATA_INDEX
+ } GtkToolbarDataType;
+ 
  typedef enum
  {
    GTK_TOOLBAR_SPACE_EMPTY,
***************
*** 129,134 ****
--- 139,148 ----
  					GtkSignalFunc    callback,
  					gpointer         user_data,
  					gint             position);
+ 
+ void       gtk_toolbar_remove_item     (GtkToolbar	*tb,
+ 					GtkToolbarDataType type,
+ 					gpointer	data);
  
  /* Space Items */
  void       gtk_toolbar_append_space    (GtkToolbar      *toolbar);


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