How to redraw a widget completely?




How do I get a widget redrawn completely, including its background
(which might be a pixmap) and its children?
(I asked this question a while back but got no answer)

The problem is that in Glade you can select widgets and it draws
a black rectangle around them. So when the widget is deselected
I need to redraw the widget completely.

The best I can do at the moment is paint a filled rectangle in the
widget's parent's window in the widget's background colour, and then
draw the widget and its children explicitly. But this doesn't work
with background pixmaps, and I feel its a kludge anyway:


/*
 * Redraw the given widget completely, including all space allocated by its
 * parent (since this may be used for drawing the widget's selection).
 * If widget has no parent (i.e. its a toplevel window) just clear
 * it all and redraw.
 */
void
editor_refresh_widget (GtkWidget *widget)
{
  GdkGC *gc = widget->style->bg_gc[GTK_STATE_NORMAL];
  GdkWindow *window;
  gint x, y, w, h;

  if (widget->parent)
    {
      /* Some widgets have several child X windows and don't cover their
	 entire allocation, so we clear the allocated area in the parent's
	 window instead. */
      window = widget->parent->window;
      x = widget->allocation.x;
      y = widget->allocation.y;
      w = widget->allocation.width;
      h = widget->allocation.height;
    }
  else
    {
      window = widget->window;
      x = 0;
      y = 0;
      gdk_window_get_size (window, &w, &h);
    }

  /* If widget hasn't been layed out don't try to draw */
  if (x == -1 && y == -1)
    return;

  gdk_gc_set_subwindow (gc, GDK_INCLUDE_INFERIORS);
  gdk_draw_rectangle (window, gc, TRUE, x, y, w, h);
  gdk_gc_set_subwindow (gc, GDK_CLIP_BY_CHILDREN);

  gtk_widget_draw (widget, NULL);
  gtk_widget_draw_children (widget);
}

Damon




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