RE: GtkStyle in CList...
- From: "Dugas, Alan" <alan dugas analog com>
- To: gtk-app-devel-list gnome org, "James K. Wiggs" <wiggs novum-millennium org>
- Subject: RE: GtkStyle in CList...
- Date: Wed, 11 Oct 2000 16:06:07 -0400
Just a couple of thoughts from someone who is definately not an expert on
the subject...
I didn't notice any explict code to set the background or foreground color
in your posting. If this is not an oversight in your posting, then you
might want to try the following two functions;
gtk_clist_set_background(GtkCList *clist, gint row, GdkColor
*color);
gtk_clist_set_foreground(GtkCList *clist, gint row, GdkColor
*color);
Also, I noticed that you allocate the color black using
gdk_colormap_alloc_color( cmap, &black, FALSE, TRUE ). In your posting you
said that your getting dark blue instead of black. Could it be that
gdk_colormap_alloc_color() is performing a "best match"? It apprears that
your trying to allocate the color black which is probably already allocated,
and the argument that controls this is set to TRUE. You might want to try
changing;
(MMStyle[BLACK_WHITE_DISPLAY_STYLE])->bg[GTK_STATE_NORMAL] = black;
to
(MMStyle[BLACK_WHITE_DISPLAY_STYLE])->bg[GTK_STATE_NORMAL] =
(MMStyle[BLACK_WHITE_DISPLAY_STYLE])->black;
and see if this fixes your text coloring problem. Hope this helps.
-- Stupid Genius
----------
From: James K. Wiggs[SMTP:wiggs novum-millennium org]
Sent: Wednesday, October 11, 2000 2:20 PM
To: gtk-app-devel-list gnome org
Subject: Re: GtkStyle in CList...
Hello Again,
Once again, thunderous silence. If nobody can answer this question,
can somebody at least point me to a reasonably complete tutorial or set
of examples on how to use styles? The documentation I've found so far
on GtkStyles is, quite frankly, abysmal. Yet people are obviously using
them. How the hell did they figure 'em out? Is the source code the
*only* resource? I've been searching through the mailing list archives,
doing Google searches, sifting through the source code, etc., etc., and
I just can't figure out what's wrong with this. If I create a GtkStyle
object and set its background color to black, then attach that style to
a row in a CList with the appropriate function, why the *hell* is the
background color in the CList still white? According to all the stuff
I've read, that's all you need to do. Why doesn't it work? I've been
looking through gtk/gtkclist.? and trying to figure out from the
internal methods thereof if it maybe uses a different color entry than
the "bg" field for drawing the background, but the coding style used
is so convoluted with its casts to klasses and uses of internal methods
that I can't trace down where the code is that actually *draws* the
contents of the cells! Does *anybody* know where the actual lines of
C code are that *draw* the CList cells?
Color me *really* frustrated,
Jim Wiggs
wiggs wiggs net
PS Apologies if the above comes across badly; I'm running on little
sleep and really stuck on this problem; but I truly appreciate the
help I've received from the people on the mailing list.
On Tue, 10 Oct 2000, James K. Wiggs wrote:
Folks,
I'm trying to change the background colors in a CList widget, and
I don't seem to be having a lot of luck with it. I want to color the
text white by default, and alternating rows in the CList either black
or 25% grey. Certain cells may have the text colored bright green,
bright red, gold, or a light purple. I have the following code that
is called during the application's initialization phase to create a
global array of styles for this purpose:
gint Create_CList_Styles()
{
gint n;
GtkStyle *style;
GdkColormap *cmap;
GdkColor black,darkgrey,lightgrey,white;
GdkColor brightred,brightgreen;
GdkColor darkred,darkgreen;
GdkColor purple,gold;
cmap = gdk_colormap_get_system();
gdk_color_parse( "ffffff", &white);
gdk_colormap_alloc_color( cmap, &white, FALSE, TRUE );
gdk_color_parse( "000000", &black );
gdk_colormap_alloc_color( cmap, &black, FALSE, TRUE );
gdk_color_parse( "404040", &darkgrey );
gdk_colormap_alloc_color( cmap, &darkgrey, FALSE, TRUE );
...
/* The default (black) display style. */
MMStyle[BLACK_WHITE_DISPLAY_STYLE] =
gtk_style_copy( gtk_widget_get_default_style() );
(MMStyle[BLACK_WHITE_DISPLAY_STYLE])->bg[GTK_STATE_NORMAL] = black;
(MMStyle[BLACK_WHITE_DISPLAY_STYLE])->fg[GTK_STATE_NORMAL] = white;
(MMStyle[BLACK_WHITE_DISPLAY_STYLE])->text[GTK_STATE_NORMAL] =
white;
/* The default (grey) display style. */
MMStyle[GREY_WHITE_DISPLAY_STYLE] =
gtk_style_copy( gtk_widget_get_default_style() );
(MMStyle[GREY_WHITE_DISPLAY_STYLE])->bg[GTK_STATE_NORMAL] =
darkgrey;
(MMStyle[GREY_WHITE_DISPLAY_STYLE])->fg[GTK_STATE_NORMAL] = white;
(MMStyle[GREY_WHITE_DISPLAY_STYLE])->text[GTK_STATE_NORMAL] = white;
...
return(0);
}
So that's how I'm creating the styles. Then the styles get used
in this fashion (at this point in the code, the CList has already
been created and filled in):
for(i=0; i<MM->nsymbols; i++) {
if( i%2 ) {
gtk_clist_set_row_style( clist, i,
MMStyle[GREY_WHITE_DISPLAY_STYLE] );
}
else {
gtk_clist_set_row_style( clist, i,
MMStyle[BLACK_WHITE_DISPLAY_STYLE] );
}
for(j=0; j<MM->nfields; j++) {
/* Here is where we do the text coloring stuff. */
if( MM->field[j] == CHANGE_FIELD ) {
if( i%2 ) {
gtk_clist_set_cell_style( clist, i, j,
MMStyle[BLACK_GREEN_DISPLAY_STYLE] );
}
else {
gtk_clist_set_cell_style( clist, i, j,
MMStyle[GREY_GREEN_DISPLAY_STYLE] );
}
}
else if( MM->field[j] == SYMBOL_FIELD ) {
if( i%2 ) {
gtk_clist_set_cell_style( clist, i, j,
MMStyle[BLACK_PURPLE_DISPLAY_STYLE] );
}
else {
gtk_clist_set_cell_style( clist, i, j,
MMStyle[GREY_PURPLE_DISPLAY_STYLE] );
}
}
}
}
The code *does* have some effect. It appears to change the text
color, but not to the color it *should* be changed to. Instead of
black, it is a dark blue. The background remains white. So, any
suggestions as to what's wrong here?
thanks,
Jim Wiggs
wiggs wiggs net
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]