#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>

static void
create_css_sample (void)
{
  GtkCssProvider *provider = gtk_css_provider_new ();
  gtk_css_provider_load_from_data
    (provider,
     "GdkDisplay { color : #ff0000; }\n\
      GdkDisplay:active { color : #00ff00; }",
     -1, NULL);
  gtk_style_context_add_provider_for_screen
    (gdk_screen_get_default (),
     GTK_STYLE_PROVIDER (provider),
     GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 12);
  g_signal_connect (window, "destroy",
		    G_CALLBACK (gtk_main_quit),
		    NULL);
  g_signal_connect (window, "delete-event",
		    G_CALLBACK (gtk_false),
		    NULL);

  GtkStyleContext *context = gtk_style_context_new ();
  GtkStyleContext *pcontext = gtk_widget_get_style_context (window);
  GtkWidgetPath *path = gtk_widget_path_copy (gtk_style_context_get_path (pcontext));
  gtk_widget_path_append_type (path, GDK_TYPE_DISPLAY);
  gtk_style_context_set_path (context, path);
  gtk_widget_path_free (path);
  gtk_style_context_set_parent (context, pcontext);

  GdkRGBA rgba;
  gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &rgba);
  g_printerr ("Color: %s\n", gdk_rgba_to_string (&rgba));
  gtk_style_context_get_color (context, GTK_STATE_FLAG_ACTIVE, &rgba);
  g_printerr ("Color: %s\n", gdk_rgba_to_string (&rgba));

  gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
  gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &rgba);
  g_printerr ("Color: %s\n", gdk_rgba_to_string (&rgba));
  gtk_style_context_get_color (context, GTK_STATE_FLAG_ACTIVE, &rgba);
  g_printerr ("Color: %s\n", gdk_rgba_to_string (&rgba));

  gtk_style_context_save (context);
  gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
  gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, &rgba);
  g_printerr ("Color: %s\n", gdk_rgba_to_string (&rgba));
  gtk_style_context_set_state (context, GTK_STATE_FLAG_ACTIVE);
  gtk_style_context_get_color (context, GTK_STATE_FLAG_ACTIVE, &rgba);
  g_printerr ("Color: %s\n", gdk_rgba_to_string (&rgba));
  gtk_style_context_restore (context);

  gtk_container_add (GTK_CONTAINER (window), gtk_label_new ("Hi!"));
  gtk_window_set_default_size (GTK_WINDOW (window), 600, 0);
  gtk_widget_show_all (window);
}


int main(int   argc,
         char *argv[] )
{
  gtk_init (&argc, &argv);

  if (g_getenv ("GTK_RTL"))
    gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);

  create_css_sample ();

  gtk_main();

  return(0);
}
/* example-end */
