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

Re: Quickie: changing label text colors



Thanks for the tip, Eric.
I looked in your book and at the example. Very helpful.

Now I have another question: I did what you suggested, but the only change
that shows up is setting the background. Am I doing something wrong? the
code is below.

/*-----------------------------------------------------------------------
**  MyStyleSetItemColor() - Helper function to change a style.
**-----------------------------------------------------------------------
*/
GtkStyle * MyStyleSetItemColor(
    GdkColor   color,      /* The allocated color to be added to the style
*/
    char             item,      /* the item to which the color is to be
applied */
                                       /* 'f' = foreground; 'b' =
background;    */
                                       /* 'l' = light;  'd' = dark;      */
                                       /* 'm' = mid;   't' = text;      */
                                       /* 's' = base.            */
    GtkStyle * oldstyle    /* The old style - changes made to a copy   */
)
{
    int i;
    GtkStyle * newstyle;

    if ( oldstyle == NULL )
        oldstyle = gtk_widget_get_default_style( );

    newstyle = gtk_style_copy( oldstyle );
    switch ( item )
    {
        case 'f':
        case 'F':
            for ( i = 0; i < 5; i++ )
                newstyle->fg[i] = color;
            break;
        case 'b':
        case 'B':
            for ( i = 0; i < 5; i++ )
                newstyle->bg[i] = color;
            break;
        case 'l':
        case 'L':
            for ( i = 0; i < 5; i++ )
                newstyle->light[i] = color;
            break;
        case 'd':
        case 'D':
            for ( i = 0; i < 5; i++ )
                newstyle->dark[i] = color;
            break;
        case 'm':
        case 'M':
            for ( i = 0; i < 5; i++ )
                newstyle->mid[i] = color;
            break;
        case 't':
        case 'T':
            for ( i = 0; i < 5; i++ )
                newstyle->text[i] = color;
            break;
        case 's':
        case 'S':
            for ( i = 0; i < 5; i++ )
                newstyle->base[i] = color;
            break;
        default:
            return oldstyle;
    }
    return newstyle;
}

 /* Stop button */
    Md.stop_button = gtk_button_new_with_label( "Stop" );
    gtk_signal_connect( GTK_OBJECT(Md.stop_button), "clicked",
GTK_SIGNAL_FUNC(m_stop_cb), NULL );
    style = MyStyleSetItemColor( CM.colors[CM_RED], 't', NULL );
    style = MyStyleSetItemColor( CM.colors[CM_RED], 'f', style );
    style = MyStyleSetItemColor( CM.colors[CM_RED], 'b', style );
    style = MyStyleSetItemColor( CM.colors[CM_RED], 'l', style );
    style = MyStyleSetItemColor( CM.colors[CM_RED], 'd', style );
    style = MyStyleSetItemColor( CM.colors[CM_RED], 'm', style );
    style = MyStyleSetItemColor( CM.colors[CM_RED], 's', style );
    gtk_widget_set_style( GTK_WIDGET(Md.stop_button), style );
    gtk_table_attach_defaults( GTK_TABLE(Md.table), Md.stop_button, 3, 4, 0,
2 );
    gtk_widget_show( Md.stop_button );

The way I understand it, the above calls to MyStyleSetItemColor should
result in everything about the button being red. However, the only red part
is the background. I also ran the program with only one line uncommented
out, with the same results.

Any suggestions?

Thanks, Miranda

/------------------------------------------------------------------------\
| Miranda Hawarden-Ogata             Email: hawarden@irtf.ifa.hawaii.edu |
| NASA IRTF, Institute of Astronomy  Phone: (808) 974-4206               |
| 1175 Manono St., Bldg 393            Fax: (808) 974-4207               |
| Hilo, HI 96720                                                         |
\------------------------------------------------------------------------/

-----Original Message-----
From: Eric Harlow <linuxgeek@yahoo.com>
To: gtk-app-devel-list@redhat.com <gtk-app-devel-list@redhat.com>
Date: Thursday, June 24, 1999 6:15 PM
Subject: Re: Quickie: changing label text colors


>
>You need to use styles.  There are some examples on
>
>http://www.bcpl.net/~eharlow/book
The above is a nice supplement to the book. Thanks.
>
>Chapter 11 has the examples for the styles.
>
> -Eric
>



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