Widget style property from RC file.



Could someone point out what I'm doing wrong in the attached test case?
It's meant to read a value from the rc file, to determine how a widget
would be drawn, making the widget themed.

I get this output:

example button gtype name=ExampleButton
example_button_class_init(): Registering example_thing style property.
example_button_init(): example_thing from rc file=0

-- 
Murray Cumming
murrayc murrayc com
www.murrayc.com
www.openismus.com
style "example-style"
{
  ExampleButton::example_thing = 10
}

class "ExampleButton" style "example-style"
#include <gtk/gtk.h>


typedef struct _ExampleButton            ExampleButton;
typedef struct _ExampleButtonClass       ExampleButtonClass;



struct _ExampleButton
{
  GtkButton parent;

  /* private */
};

struct _ExampleButtonClass
{
  GtkButtonClass parent_class;
};

static void
example_button_init (ExampleButton *object)
{
  int example_thing = 0;
  gtk_widget_style_get(GTK_WIDGET(object), "example_thing", &example_thing, NULL);
  printf("example_button_init(): example_thing from rc file=%d\n", example_thing);
}

static void
example_button_class_init (ExampleButtonClass *klass)
{
  GtkWidgetClass *widget_klass = 0;

  widget_klass = GTK_WIDGET_CLASS (klass);

  printf("example_button_class_init(): Registering example_thing style property.\n");

  gtk_widget_class_install_style_property(widget_klass, 
    g_param_spec_int("example_thing",
		      "Example Thing",
                      "This is just a silly example.",
                      G_MININT,
		      G_MAXINT,
		      0,
 		      G_PARAM_READABLE) );
 }

G_DEFINE_TYPE (ExampleButton, example_button, GTK_TYPE_BUTTON);


#define EXAMPLE_TYPE_BUTTON             (example_button_get_type ())
#define EXAMPLE_BUTTON(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), EXAMPLE_TYPE_BUTTON, ExampleButton))
#define EXAMPLE_BUTTON_CLASS(obj)       (G_TYPE_CHECK_CLASS_CAST ((obj), EXAMPLE_BUTTON,  ExampleButtonClass))
#define EXAMPLE_IS_BUTTON(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EXAMPLE_TYPE_BUTTON))
#define EXAMPLE_IS_BUTTON_CLASS(obj)    (G_TYPE_CHECK_CLASS_TYPE ((obj), EXAMPLE_TYPE_BUTTON))
#define EXAMPLE_BUTTON_GET_CLASS        (G_TYPE_INSTANCE_GET_CLASS ((obj), EXAMPLE_TYPE_BUTTON, ExampleButtonClass))



GtkWidget *
example_button_new (void)
{
	return g_object_new (EXAMPLE_TYPE_BUTTON, NULL);
}

int main( int   argc,
          char *argv[] )
{ 
    GtkWidget *window = 0;
    GtkWidget *button = 0;
    
    gtk_init (&argc, &argv);

    GType gtype = example_button_get_type(); //Make sure that it is initialized.
    printf("example button gtype name=%s\n", g_type_name(gtype));
    
    /* Without the gtk_window_new(), the RC file is never parsed. */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(window), 200, 200);
    button = example_button_new();
    gtk_widget_show(button);
    gtk_container_add(GTK_CONTAINER(window), button);
    gtk_widget_show(window);
    
    gtk_rc_parse("custom_gtkrc"); 

    gtk_main ();
    
    return 0;
}


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