[Xfce4-commits] <xfce4-weather-plugin:master> Implement scrollbox text color support.
Harald Judt
noreply at xfce.org
Tue Nov 27 16:46:29 CET 2012
Updating branch refs/heads/master
to 2dc70062a2148e6adcfb7a4048723d2c36be6780 (commit)
from dd04f1961900fb7e348b30b748765fe08da001a3 (commit)
commit 2dc70062a2148e6adcfb7a4048723d2c36be6780
Author: Harald Judt <h.judt at gmx.at>
Date: Sun Nov 25 21:38:58 2012 +0100
Implement scrollbox text color support.
panel-plugin/weather-config.c | 21 ++++++++++++++++-----
panel-plugin/weather-debug.c | 2 ++
panel-plugin/weather-scrollbox.c | 25 +++++++++++++++++++++++--
panel-plugin/weather-scrollbox.h | 4 ++++
panel-plugin/weather.c | 12 +++++++++++-
panel-plugin/weather.h | 1 +
6 files changed, 57 insertions(+), 8 deletions(-)
diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 03a1554..0ab5c1a 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -821,6 +821,19 @@ button_scrollbox_font_clicked(GtkWidget *button,
}
+static void
+button_scrollbox_color_set(GtkWidget *button,
+ gpointer user_data)
+{
+ xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
+
+ gtk_color_button_get_color(GTK_COLOR_BUTTON(button),
+ &(dialog->wd->scrollbox_color));
+ gtk_scrollbox_set_color(GTK_SCROLLBOX(dialog->wd->scrollbox),
+ dialog->wd->scrollbox_color);
+}
+
+
static GtkWidget *
make_label(void)
{
@@ -995,7 +1008,6 @@ create_scrollbox_page(xfceweather_dialog *dialog)
GtkWidget *button_add, *button_del, *button_up, *button_down;
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
- GdkColor color;
data_types type;
guint i;
gint n;
@@ -1041,15 +1053,14 @@ create_scrollbox_page(xfceweather_dialog *dialog)
dialog->wd->scrollbox_font);
g_signal_connect(dialog->button_scrollbox_font, "clicked",
G_CALLBACK(button_scrollbox_font_clicked), dialog);
- gdk_color_parse("#000000", &color);
dialog->button_scrollbox_color =
- gtk_color_button_new_with_color(&color);
+ gtk_color_button_new_with_color(&(dialog->wd->scrollbox_color));
gtk_size_group_add_widget(sg_misc, dialog->button_scrollbox_color);
gtk_box_pack_start(GTK_BOX(hbox), dialog->button_scrollbox_color,
FALSE, FALSE, 0 );
gtk_box_pack_start(GTK_BOX(page), hbox, FALSE, FALSE, 0);
-
- //g_signal_connect(dialog->button_scrollbox_color, "color-set", cb, base);
+ g_signal_connect(dialog->button_scrollbox_color, "color-set",
+ G_CALLBACK(button_scrollbox_color_set), dialog);
/* labels and buttons */
diff --git a/panel-plugin/weather-debug.c b/panel-plugin/weather-debug.c
index b601647..ea0d4d3 100644
--- a/panel-plugin/weather-debug.c
+++ b/panel-plugin/weather-debug.c
@@ -412,6 +412,7 @@ weather_dump_plugindata(const xfceweather_data *data)
" show scrollbox: %s\n"
" scrollbox lines: %d\n"
" scrollbox font: %s\n"
+ " scrollbox color: %s\n"
" animate scrollbox: %s\n"
" --------------------------------------------",
data->panel_size,
@@ -429,6 +430,7 @@ weather_dump_plugindata(const xfceweather_data *data)
YESNO(data->show_scrollbox),
data->scrollbox_lines,
data->scrollbox_font,
+ gdk_color_to_string(&(data->scrollbox_color)),
YESNO(data->scrollbox_animate));
g_free(last_astro_update);
g_free(last_data_update);
diff --git a/panel-plugin/weather-scrollbox.c b/panel-plugin/weather-scrollbox.c
index b9decae..7317a68 100644
--- a/panel-plugin/weather-scrollbox.c
+++ b/panel-plugin/weather-scrollbox.c
@@ -70,6 +70,7 @@ gtk_scrollbox_init(GtkScrollbox *self)
self->active = NULL;
self->orientation = GTK_ORIENTATION_HORIZONTAL;
self->fontname = NULL;
+ self->pattr_list = pango_attr_list_new();
}
@@ -88,6 +89,7 @@ gtk_scrollbox_finalize(GObject *object)
/* free everything else */
g_free(self->fontname);
+ pango_attr_list_unref(self->pattr_list);
G_OBJECT_CLASS(gtk_scrollbox_parent_class)->finalize(object);
}
@@ -103,12 +105,14 @@ gtk_scrollbox_set_font(GtkScrollbox *self,
if (self->fontname)
desc = pango_font_description_from_string(self->fontname);
- if (layout)
+ if (layout) {
pango_layout_set_font_description(layout, desc);
- else
+ pango_layout_set_attributes(layout, self->pattr_list);
+ } else
for (li = self->labels; li != NULL; li = li->next) {
layout = PANGO_LAYOUT(li->data);
pango_layout_set_font_description(layout, desc);
+ pango_layout_set_attributes(layout, self->pattr_list);
}
pango_font_description_free(desc);
}
@@ -371,3 +375,20 @@ gtk_scrollbox_set_fontname(GtkScrollbox *self,
gtk_scrollbox_set_font(self, NULL);
gtk_widget_queue_resize(GTK_WIDGET(self));
}
+
+
+void
+gtk_scrollbox_set_color(GtkScrollbox *self,
+ const GdkColor color)
+{
+ PangoAttribute *pattr = NULL;
+
+ g_return_if_fail(GTK_IS_SCROLLBOX(self));
+
+ pattr = pango_attr_foreground_new(color.red,
+ color.green,
+ color.blue);
+ pango_attr_list_change(self->pattr_list, pattr);
+ gtk_scrollbox_set_font(self, NULL);
+ gtk_widget_queue_resize(GTK_WIDGET(self));
+}
diff --git a/panel-plugin/weather-scrollbox.h b/panel-plugin/weather-scrollbox.h
index 245ea0a..7a1c320 100644
--- a/panel-plugin/weather-scrollbox.h
+++ b/panel-plugin/weather-scrollbox.h
@@ -50,6 +50,7 @@ struct _GtkScrollbox {
gboolean animate;
GtkOrientation orientation;
gchar *fontname;
+ PangoAttrList *pattr_list;
};
struct _GtkScrollboxClass {
@@ -76,6 +77,9 @@ void gtk_scrollbox_next_label(GtkScrollbox *self);
void gtk_scrollbox_set_fontname(GtkScrollbox *self,
const gchar *fontname);
+void gtk_scrollbox_set_color(GtkScrollbox *self,
+ const GdkColor color);
+
G_END_DECLS
#endif
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index cdab60c..31f0fbe 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -568,6 +568,10 @@ xfceweather_read_config(XfcePanelPlugin *plugin,
data->scrollbox_font = g_strdup(value);
}
+ value = xfce_rc_read_entry(rc, "scrollbox_color", NULL);
+ if (value)
+ gdk_color_parse("#rrrrggggbbbb", &(data->scrollbox_color));
+
data->scrollbox_animate =
xfce_rc_read_bool_entry(rc, "scrollbox_animate", TRUE);
gtk_scrollbox_set_animate(GTK_SCROLLBOX(data->scrollbox),
@@ -595,7 +599,7 @@ xfceweather_write_config(XfcePanelPlugin *plugin,
gchar label[10];
guint i;
XfceRc *rc;
- gchar *file;
+ gchar *file, *value;
if (!(file = xfce_panel_plugin_save_location(plugin, TRUE)))
return;
@@ -646,6 +650,10 @@ xfceweather_write_config(XfcePanelPlugin *plugin,
if (data->scrollbox_font)
xfce_rc_write_entry(rc, "scrollbox_font", data->scrollbox_font);
+ value = gdk_color_to_string(&(data->scrollbox_color));
+ xfce_rc_write_entry(rc, "scrollbox_color", value);
+ g_free(value);
+
for (i = 0; i < data->labels->len; i++) {
g_snprintf(label, 10, "label%d", i);
xfce_rc_write_int_entry(rc, label,
@@ -1274,6 +1282,8 @@ weather_construct(XfcePanelPlugin *plugin)
scrollbox_set_visible(data);
gtk_scrollbox_set_fontname(GTK_SCROLLBOX(data->scrollbox),
data->scrollbox_font);
+ gtk_scrollbox_set_color(GTK_SCROLLBOX(data->scrollbox),
+ data->scrollbox_color);
#if LIBXFCE4PANEL_CHECK_VERSION(4,9,0)
xfceweather_set_mode(plugin, xfce_panel_plugin_get_mode(plugin), data);
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 3f9fc52..34122ec 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -57,6 +57,7 @@ typedef struct {
gboolean show_scrollbox;
guint scrollbox_lines;
gchar *scrollbox_font;
+ GdkColor scrollbox_color;
gboolean scrollbox_animate;
GArray *labels;
More information about the Xfce4-commits
mailing list