Esempio n. 1
0
void changeColor(GtkColorButton *cb, gpointer data)
{
	GtkStyleContext *context;
	GdkRGBA fg, bg;
	char *css;
	GError *err = NULL;

	context = gtk_widget_get_style_context(button);
	if (current != NULL) {
		gtk_style_context_remove_provider(context, GTK_STYLE_PROVIDER(current));
		g_object_unref(current);
	}
	gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(foreground), &fg);
	gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(background), &bg);
	css = g_strdup_printf(CSSFormat,
		(int) (fg.red * 255),
		(int) (fg.green * 255),
		(int) (fg.blue * 255),
		(int) (bg.red * 255),
		(int) (bg.green * 255),
		(int) (bg.blue * 255));
	current = gtk_css_provider_new();
	if (gtk_css_provider_load_from_data(current, css, -1, &err) == FALSE)
		g_error("error parsing CSS: %s", err->message);
	gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER(current), GTK_STYLE_PROVIDER_PRIORITY_USER);
	g_free(css);
}
Esempio n. 2
0
void gtk_widget_modify_bkg(GtkWidget *widget, GtkStateType state, GdkRGBA* color)
{
	GtkStyleContext *context = gtk_widget_get_style_context(widget);
	GtkCssProvider  *cssprv =  gtk_css_provider_new();
	char css[2048], strstate[256];
	
	strstate[0] = '\0';
	if (state == 0)
	{
		//GTK_STATE_FLAG_NORMAL
		strcat(strstate, "");
	}
	if ((state << 0) == 1)
	{
		//GTK_STATE_FLAG_ACTIVE
		strcat(strstate, ":active");
	}
	if ((state << 1) == 1)
	{
		//GTK_STATE_FLAG_PRELIGHT
		strcat(strstate, ":hoover");
	}
	if ((state << 2) == 1)
	{
		//GTK_STATE_FLAG_SELECTED
		strcat(strstate, ":focus");
	}
	if ((state << 3) == 1)
	{
		//GTK_STATE_FLAG_INSENSITIVE
		strcat(strstate, ":insensitive");
	}
	if ((state << 4) == 1)
	{
		//GTK_STATE_FLAG_INCONSISTENT
		strcat(strstate, "");
	}
	if ((state << 5) == 1)
	{
		//GTK_STATE_FLAG_FOCUSED
		strcat(strstate, "focus");
	}
	//sprintf(css, "%s%s {\n background-color: %s;\n background-image: none;\n }\n", G_OBJECT_TYPE_NAME(widget), strstate, gdk_rgba_to_string(color));
	sprintf(css, "%s%s {\n background-image: -gtk-gradient (linear, left top, left bottom, from (shade (%s, 1.1)), color-stop (0.5, shade (%s, 0.85)), to (shade (%s, 1.1)));\n }\n", G_OBJECT_TYPE_NAME(widget), strstate, gdk_rgba_to_string(color), gdk_rgba_to_string(color), gdk_rgba_to_string(color));
	gtk_style_context_remove_provider(context, GTK_STYLE_PROVIDER (cssprv));
	gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER (cssprv), GTK_STYLE_PROVIDER_PRIORITY_USER);
	gtk_css_provider_load_from_data(cssprv, css, -1, NULL);
	g_object_unref(cssprv);
}
Esempio n. 3
0
static void
gtk_font_button_label_use_font (GtkFontButton *font_button)
{
  GtkFontButtonPrivate *priv = font_button->priv;
  GtkStyleContext *context;

  context = gtk_widget_get_style_context (priv->font_label);

  if (!priv->use_font)
    {
      if (priv->provider)
        {
          gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (priv->provider));
          g_clear_object (&priv->provider);
        }
    }
  else
    {
      PangoFontDescription *desc;
      gchar *font, *data;

      if (!priv->provider)
        {
          priv->provider = gtk_css_provider_new ();
          gtk_style_context_add_provider (context,
                                          GTK_STYLE_PROVIDER (priv->provider),
                                          GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
        }

      desc = pango_font_description_copy (priv->font_desc);

      if (!priv->use_size)
        pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE);

      font = pango_font_description_to_string (desc);
      data = g_strconcat ("* { font: ",  font, "; }", NULL);
      
      gtk_css_provider_load_from_data (priv->provider, data, -1, NULL);

      g_free (data);
      g_free (font);

      pango_font_description_free (desc);
    }
}
Esempio n. 4
0
GtkWidget *gtk_paned_new_with_handle(GtkOrientation orientation)
{
	GtkWidget *pnd = gtk_paned_new(orientation);
	GtkStyleContext *context = gtk_widget_get_style_context(pnd);
	GtkCssProvider  *cssprv =  gtk_css_provider_new();
	GdkRGBA clrSel = {0.,0.,0.,0.};
	char css[2048];
	
	gtk_style_context_lookup_color(context, "bg_color", &clrSel);
	if (orientation == GTK_ORIENTATION_HORIZONTAL)
	{
		sprintf(css, "* {\n -GtkPaned-handle-size: 3; \n } \n .pane-separator.horizontal {\n background-image: -gtk-gradient (linear, left top, left bottom, from (%s), color-stop (0.5, shade (%s, 0.95)), to (%s)); \n -unico-centroid-texture: url(\"%s\");\n }\n", gdk_rgba_to_string(&clrSel), gdk_rgba_to_string(&clrSel), gdk_rgba_to_string(&clrSel), imgOrzHnd);
	}
	else
	{
		sprintf(css, "* {\n -GtkPaned-handle-size: 3; \n } \n \n .pane-separator.vertical {\n background-image: -gtk-gradient (linear, left top, right top, from (%s), color-stop (0.5, shade (%s, 0.95)), to (%s)); \n -unico-centroid-texture: url(\"%s\");\n }\n", gdk_rgba_to_string(&clrSel), gdk_rgba_to_string(&clrSel), gdk_rgba_to_string(&clrSel), imgVrtHnd);
	}
	gtk_style_context_remove_provider(context, GTK_STYLE_PROVIDER (cssprv));
	gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER (cssprv), GTK_STYLE_PROVIDER_PRIORITY_USER);
	gtk_css_provider_load_from_data(cssprv, css, -1, NULL);
	g_object_unref(cssprv);
	return pnd;
}
Esempio n. 5
0
int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *ebox;
  GtkStyleContext *context;
  GtkStyleProvider *provider;

  gtk_init (&argc, &argv);

  if (argc > 1)
    what = argv[1];
  else
    what = "check";

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_has_resize_grip (GTK_WINDOW (window), FALSE);
  ebox = gtk_event_box_new ();
  gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), TRUE);
  gtk_container_add (GTK_CONTAINER (window), ebox);
  gtk_widget_set_name (ebox, "ebox");

  context = gtk_widget_get_style_context (ebox);
  provider = (GtkStyleProvider *)gtk_css_provider_new ();
  gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider),
                                   ".frame1 {\n"
                                   "   border-image: url('gradient1.png') 10 10 10 10 stretch;\n"
                                   "}\n"
                                   ".frame2 {\n"
                                   "   border-style: solid;\n"
                                   "   border-color: rgb(255,0,0);\n"
                                   "   border-width: 10;\n"
                                   "   border-radius: 10;\n"
                                   "}\n"
                                   ".frame3 {\n"
                                   "   border-style: solid;\n"
                                   "   border-color: rgb(0,0,0);\n"
                                   "   border-width: 2;\n"
                                   "   border-radius: 10;\n"
                                   "}\n"
                                   ".background {\n"
                                   "   border-radius: 10;\n"
                                   "   border-width: 0;\n"
                                   "   background-image: -gtk-gradient (linear, left top, right bottom, from(#ff00ff), to(#aabbcc));\n"
                                   "}\n"
                                   ".frame {\n"
                                   "   border-style: solid;\n"
                                   "   border-width: 1;\n"
                                   "   border-radius: 0;\n"
                                   "}\n", -1, NULL);
  gtk_style_context_add_provider (context, provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

  g_signal_connect_after (ebox, "draw", G_CALLBACK (draw_cb), NULL);

  gtk_widget_show_all (window);

  gtk_main ();

  gtk_style_context_remove_provider (context, provider);

  return 0;
}