[gtk-list] Re: changing a widget's background



On Apr 26,  4:14pm, Ramiro Estrugo wrote:
} Subject: [gtk-list] changing a widget's background
} what is the correct way to do this ?
} 
} ive experimented with chaning the w->window and hacking the style with
} little success.
} 
} all i want to do is change the background.

Lots of people ask this.  It actually is a lot harder than it needs to
be.  We have hacked a function to simplify matters somewhat.  It takes
a color ID (foreground, etc.) and a widget state (normal, prelight,
etc.), as well as a 24-bit packed RGB color, where 0xff0000 would be
red and 0x0000ff would be blue.  Returns 1 on success, 0 on failure.
I suggest that this function be added to the GTK+ API if there is
nothing similar that I have overlooked.

---------------------------

int GtkSetColor (GtkObject* obj, int colorid, int widgetstate, long color)
{
    GtkStyle        *oldstyle, *style;
    int             retval = 0;
    GdkColor        *gdkcolor;

    if (colorid >= GTK_COLOR_FOREGROUND && colorid <=
        GTK_COLOR_BASE &&
        widgetstate >= GTK_STATE_NORMAL &&
        widgetstate <= GTK_STATE_INSENSITIVE)
    {
        oldstyle = gtk_widget_get_style (GTK_WIDGET(obj));
        style = gtk_style_copy (oldstyle);

        switch (colorid)
        {
          case GTK_COLOR_FOREGROUND:
            gdkcolor = &style->fg[widgetstate];
            break;
          case GTK_COLOR_BACKGROUND:
            gdkcolor = &style->bg[widgetstate];
            break;
          case GTK_COLOR_LIGHT:
            gdkcolor = &style->light[widgetstate];
            break;
          case GTK_COLOR_DARK:
            gdkcolor = &style->dark[widgetstate];
            break;
          case GTK_COLOR_MID:
            gdkcolor = &style->mid[widgetstate];
            break;
          case GTK_COLOR_TEXT:
            gdkcolor = &style->text[widgetstate];
            break;
          case GTK_COLOR_BASE:
            gdkcolor = &style->base[widgetstate];
            break;
        }
        gdkcolor->red = (color >> 8) & 0xff00;
        gdkcolor->green = color & 0xff00;
        gdkcolor->blue = (color << 8) & 0xff00;

        gtk_widget_set_style (GTK_WIDGET(obj), style);
        retval = 1;
    }
    return (retval);
}



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