[9651] in The GTK GIMP ToolKit mailing list archive

home help back first fref pref prev next nref lref last post

[gtk-list] Re: style usage + memory leak

daemon@ATHENA.MIT.EDU (Robert Roebling)
Thu Oct 29 17:51:57 1998

Date: Thu, 29 Oct 1998 21:36:57 +0100
From: Robert Roebling <roebling@sun2.ruf.uni-freiburg.de>
To: gtk-list@redhat.com
Resent-From: gtk-list@redhat.com
Reply-To: gtk-list@redhat.com

This is a multi-part message in MIME format.
--------------27126DBFE7DC7F8846317A8E
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Eric Harlow wrote:
> 
> Nope nope nope.  Ran a little test to see what the ref count was and
> when the style was created, the ref count was 1.  Adding it to a
> button makes the ref count be 3.   I suspect this is because it's
> adding the style to the button and the contained label, but I haven't
> verified this.

No, setting a style to the widget doesn't change the
label's color e.g. Proof atttached.

  Robert

-- 
------------------------------------------------------------------
Robert Roebling              "Write once, compile, run everywhere"

wxWindows/GTK       http://wesley.informatik.uni-freiburg.de/~wxxt
--------------27126DBFE7DC7F8846317A8E
Content-Type: text/plain; charset=us-ascii; name="buttons.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="buttons.c"


#include <gtk/gtk.h>

int main (int argc, char *argv[])
{
    GtkWidget     *window;
    GtkWidget     *menu;
    GtkWidget     *button;
    GdkColor       color;
    GdkColormap   *colormap;
    GtkStyle      *style;

    gtk_init (&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Style usage?");

    gtk_container_border_width (GTK_CONTAINER (window), 10);
    gtk_widget_realize(window);

    /*
       create simple button
     */
      
    button = gtk_button_new_with_label( "Hallo" );
    
    gtk_container_add (GTK_CONTAINER (window), button );
    
    gtk_widget_realize( button );
    gtk_widget_show( button );
    
    /*
      create style by copying an existing one
    */
    
    style = gtk_style_copy( gtk_widget_get_style( button ) );

    /*
      create color and assign it to style's background
    */
        
    color.red   = 40000;
    color.green = 40000;
    color.blue  = 40000;
    colormap = gdk_window_get_colormap( button->window );
    gdk_color_alloc( colormap, &color );
    style->fg[GTK_STATE_NORMAL] = color;
    
    /*
      assign style to button
      color will not affect label unless uncommented
    */
    
    gtk_widget_set_style( button, style );
//    gtk_widget_set_style( GTK_BUTTON(button)->child, style );
    
    gtk_style_unref( style );
    
    gtk_widget_show (window);
    
    gtk_main();
    
    return 0;
}

--------------27126DBFE7DC7F8846317A8E--


-- 
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null


home help back first fref pref prev next nref lref last post