static void add_general_tag (char* tag_name, Preference text_pref, Preference background_pref, Preference font_pref) { GdkRGBA *fg_color, *bg_color; char *font; char *key; /* initialize tag preferences */ /* text color */ key = preferences_get_key (text_pref); fg_color = preferences_get_color (key); preferences_notify_add (key, changed_text, tag_name); g_free (key); /* base color */ key = preferences_get_key (background_pref); bg_color = preferences_get_color (key); preferences_notify_add (key, changed_background, tag_name); g_free (key); /* font */ key = preferences_get_key (font_pref); font = preferences_get_string (key); preferences_notify_add (key, changed_font, tag_name); g_free (key); highlight_add_tag (tag_name, fg_color, bg_color, font); }
static void init_color (char *name, Preference pref) { GtkWidget *widget; char *key; GdkColor *color; GtkWidget *box; box = glade_xml_get_widget (warlock_xml, name); widget = warlock_color_button_new (); gtk_box_pack_start (GTK_BOX (box), widget, FALSE, TRUE, 0); gtk_box_reorder_child (GTK_BOX (box), widget, 0); key = preferences_get_key (pref); color = preferences_get_color (key); warlock_color_button_set_color (WARLOCK_COLOR_BUTTON (widget), color); if (color != NULL) { g_free (color); } g_signal_connect (widget, "color-set", G_CALLBACK (on_color_button_color_set), GINT_TO_POINTER (pref)); g_free (key); gtk_widget_show (widget); }
static void change_text_color (const char *key, gpointer user_data) { GtkWidget *text_view; GdkRGBA *color; text_view = user_data; color = preferences_get_color (key); gtk_widget_override_color (text_view, GTK_STATE_NORMAL, color); }
static void changed_background (const char *key, gpointer user_data) { GtkTextTag *tag; GdkRGBA *color; char *name; name = user_data; tag = gtk_text_tag_table_lookup (highlight_tag_table, name); g_assert (tag != NULL); color = preferences_get_color (key); g_object_set (G_OBJECT (tag), "background-rgba", color, NULL); }
static void highlight_add_tags (guint id) { /* * don't call this function if you think there might be a tag by this * name already, call highlight_check_tags first if that's the case */ int i; for (i = 0; i < HIGHLIGHT_MATCHES; i++) { GdkRGBA *text, *background; char *font; text = preferences_get_color ( preferences_get_highlight_match_key (id, i, PREF_HIGHLIGHT_MATCH_TEXT_COLOR)); background = preferences_get_color ( preferences_get_highlight_match_key (id, i, PREF_HIGHLIGHT_MATCH_BASE_COLOR)); font = preferences_get_string ( preferences_get_highlight_match_key (id, i, PREF_HIGHLIGHT_MATCH_FONT)); highlight_add_tag (mangle_name (id, i), text, background, font); } }
static void warlock_view_create_text_view (WarlockView *warlock_view) { PangoFontDescription *font; GdkRGBA *color; GtkTextIter iter; GtkWidget *text_view; text_view = gtk_text_view_new (); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD_CHAR); gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE); warlock_view->text_buffer = gtk_text_buffer_new (highlight_tag_table); warlock_view->text_view = text_view; gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), warlock_view->text_buffer); gtk_text_buffer_get_end_iter (warlock_view->text_buffer, &iter); warlock_view->mark = gtk_text_buffer_create_mark (warlock_view->text_buffer, NULL, &iter, TRUE); /* set the text color */ color = preferences_get_color (preferences_get_key (PREF_DEFAULT_TEXT_COLOR)); if (color == NULL) { color = g_new (GdkRGBA, 1); gdk_rgba_parse (color, "white"); } gtk_widget_override_color (text_view, GTK_STATE_NORMAL, color); g_free (color); /* set the background color*/ color = preferences_get_color (preferences_get_key (PREF_DEFAULT_BASE_COLOR)); if (color == NULL) { color = g_new (GdkRGBA, 1); gdk_rgba_parse (color, "black"); } gtk_widget_override_background_color (text_view, GTK_STATE_NORMAL, color); g_free (color); /* set the font */ font = preferences_get_font (preferences_get_key (PREF_DEFAULT_FONT)); if (font == NULL) { font = pango_font_description_from_string ("sans"); } gtk_widget_override_font (text_view, font); /* listen to gconf and change the text color when the gconf * value changes */ preferences_notify_add (preferences_get_key (PREF_DEFAULT_TEXT_COLOR), change_text_color, text_view); /* listen for background change */ preferences_notify_add (preferences_get_key (PREF_DEFAULT_BASE_COLOR), change_base_color, text_view); /* listen for font change */ preferences_notify_add (preferences_get_key (PREF_DEFAULT_FONT), change_font, text_view); }