From: Daniel Carl <danielcarl@gmx.de>
Date: Mon, 4 Mar 2013 16:21:56 +0000 (+0100)
Subject: Simplified the completion widgets style settings.
X-Git-Url: https://git.owens.tech/assets/112-editable-focus.html/assets/112-editable-focus.html/git?a=commitdiff_plain;h=12f4ea7f4d0961f1839df764276db760fbcf8e0a;p=vimb.git

Simplified the completion widgets style settings.

Don't overwrite the colors of the completion labels. Instead we set the style
for the normal and active state and switch this during cycling through the
list.
---

diff --git a/src/completion.c b/src/completion.c
index 4a90c08..ca805d4 100644
--- a/src/completion.c
+++ b/src/completion.c
@@ -32,7 +32,6 @@ static GList* completion_init_completion(GList* target, GList* source,
     Comp_Func func, const char* input, const char* prefix);
 static GList* completion_update(GList* completion, GList* active, gboolean back);
 static void completion_show(gboolean back);
-static void completion_set_color(Completion* completion, const VpColor* fg, const VpColor* bg, PangoFontDescription* font);
 static void completion_set_entry_text(Completion* c);
 static char* completion_get_text(Completion* c);
 static Completion* completion_get_new(const char* label, const char* prefix);
@@ -216,18 +215,10 @@ static GList* completion_update(GList* completion, GList* active, gboolean back)
         }
     }
 
-    completion_set_color(
-        old->data,
-        &core.style.comp_fg[VP_COMP_NORMAL],
-        &core.style.comp_bg[VP_COMP_NORMAL],
-        core.style.comp_font[VP_COMP_NORMAL]
-    );
-    completion_set_color(
-        new->data,
-        &core.style.comp_fg[VP_COMP_ACTIVE],
-        &core.style.comp_bg[VP_COMP_ACTIVE],
-        core.style.comp_font[VP_COMP_ACTIVE]
-    );
+    VP_WIDGET_SET_STATE(((Completion*)old->data)->label, VP_GTK_STATE_NORMAL);
+    VP_WIDGET_SET_STATE(((Completion*)old->data)->event, VP_GTK_STATE_NORMAL);
+    VP_WIDGET_SET_STATE(((Completion*)new->data)->label, VP_GTK_STATE_ACTIVE);
+    VP_WIDGET_SET_STATE(((Completion*)new->data)->event, VP_GTK_STATE_ACTIVE);
 
     active = new;
     completion_set_entry_text(active->data);
@@ -251,25 +242,15 @@ static void completion_show(gboolean back)
         }
     }
     if (vp.comps.active != NULL) {
-        completion_set_color(
-            vp.comps.active->data,
-            &core.style.comp_fg[VP_COMP_ACTIVE],
-            &core.style.comp_bg[VP_COMP_ACTIVE],
-            core.style.comp_font[VP_COMP_ACTIVE]
-        );
-        completion_set_entry_text(vp.comps.active->data);
+        Completion* active = (Completion*)vp.comps.active->data;
+        VP_WIDGET_SET_STATE(active->label, VP_GTK_STATE_ACTIVE);
+        VP_WIDGET_SET_STATE(active->event, VP_GTK_STATE_ACTIVE);
+
+        completion_set_entry_text(active);
         gtk_widget_show(vp.gui.compbox);
     }
 }
 
-static void completion_set_color(Completion* completion, const VpColor* fg, const VpColor* bg, PangoFontDescription* font)
-{
-    VP_WIDGET_OVERRIDE_COLOR(completion->label, GTK_STATE_NORMAL, fg);
-    VP_WIDGET_OVERRIDE_BACKGROUND(completion->event, GTK_STATE_NORMAL, bg);
-    /* TODO is it really necessary to set the font for each item */
-    VP_WIDGET_OVERRIDE_FONT(completion->label, font);
-}
-
 static void completion_set_entry_text(Completion* c)
 {
     char* text = completion_get_text(c);
@@ -315,12 +296,14 @@ static Completion* completion_get_new(const char* label, const char* prefix)
     gtk_label_set_ellipsize(GTK_LABEL(c->label), PANGO_ELLIPSIZE_MIDDLE);
     gtk_misc_set_alignment(GTK_MISC(c->label), 0.0, 0.5);
 
-    completion_set_color(
-        c,
-        &core.style.comp_fg[VP_COMP_NORMAL],
-        &core.style.comp_bg[VP_COMP_NORMAL],
-        core.style.comp_font[VP_COMP_NORMAL]
-    );
+    VP_WIDGET_SET_STATE(c->label, VP_GTK_STATE_NORMAL);
+    VP_WIDGET_SET_STATE(c->event, VP_GTK_STATE_NORMAL);
+
+    VP_WIDGET_OVERRIDE_COLOR(c->label, GTK_STATE_NORMAL, &core.style.comp_fg[VP_COMP_NORMAL]);
+    VP_WIDGET_OVERRIDE_COLOR(c->label, GTK_STATE_ACTIVE, &core.style.comp_fg[VP_COMP_ACTIVE]);
+    VP_WIDGET_OVERRIDE_BACKGROUND(c->event, GTK_STATE_NORMAL, &core.style.comp_bg[VP_COMP_NORMAL]);
+    VP_WIDGET_OVERRIDE_BACKGROUND(c->event, GTK_STATE_ACTIVE, &core.style.comp_bg[VP_COMP_ACTIVE]);
+    VP_WIDGET_OVERRIDE_FONT(c->label, core.style.comp_font);
 
     GtkWidget *alignment = gtk_alignment_new(0.5, 0.5, 1, 1);
     gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), padding, padding, padding, padding);
diff --git a/src/main.h b/src/main.h
index e9fa516..bc72c41 100644
--- a/src/main.h
+++ b/src/main.h
@@ -80,7 +80,13 @@
 #define VP_WIDGET_OVERRIDE_COLOR        gtk_widget_override_color
 #define VP_WIDGET_OVERRIDE_TEXT         gtk_widget_override_color
 #define VP_WIDGET_OVERRIDE_FONT         gtk_widget_override_font
+
+#define VP_GTK_STATE_NORMAL             GTK_STATE_FLAG_NORMAL
+#define VP_GTK_STATE_ACTIVE             GTK_STATE_FLAG_ACTIVE
+#define VP_WIDGET_SET_STATE(w, s)       gtk_widget_set_state_flags(w, s, true)
+
 #else
+
 #define VpColor GdkColor
 #define VP_COLOR_PARSE(color, string)   (gdk_color_parse(string, color))
 #define VP_COLOR_TO_STRING(color)       (gdk_color_to_string(color))
@@ -89,6 +95,10 @@
 #define VP_WIDGET_OVERRIDE_COLOR        gtk_widget_modify_fg
 #define VP_WIDGET_OVERRIDE_TEXT         gtk_widget_modify_text
 #define VP_WIDGET_OVERRIDE_FONT         gtk_widget_modify_font
+
+#define VP_GTK_STATE_NORMAL             GTK_STATE_NORMAL
+#define VP_GTK_STATE_ACTIVE             GTK_STATE_ACTIVE
+#define VP_WIDGET_SET_STATE(w, s)       gtk_widget_set_state(w, s)
 #endif
 
 /* enums */
@@ -280,7 +290,7 @@ typedef struct {
     /* completion */
     VpColor               comp_fg[VP_COMP_LAST];
     VpColor               comp_bg[VP_COMP_LAST];
-    PangoFontDescription* comp_font[VP_COMP_LAST];
+    PangoFontDescription* comp_font;
     /* hint style */
     char*                 hint_bg;
     char*                 hint_bg_focus;
diff --git a/src/setting.c b/src/setting.c
index 16129e3..7f39dd0 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -104,8 +104,7 @@ static Setting default_settings[] = {
     {NULL, "input-fg-error", TYPE_COLOR, setting_input_style, {.s = "#000"}},
     {NULL, "input-font-normal", TYPE_FONT, setting_input_style, {.s = "monospace normal 8"}},
     {NULL, "input-font-error", TYPE_FONT, setting_input_style, {.s = "monospace bold 8"}},
-    {NULL, "completion-font-normal", TYPE_FONT, setting_completion_style, {.s = "monospace normal 8"}},
-    {NULL, "completion-font-active", TYPE_FONT, setting_completion_style, {.s = "monospace bold 8"}},
+    {NULL, "completion-font", TYPE_FONT, setting_completion_style, {.s = "monospace normal 8"}},
     {NULL, "completion-fg-normal", TYPE_COLOR, setting_completion_style, {.s = "#f6f3e8"}},
     {NULL, "completion-fg-active", TYPE_COLOR, setting_completion_style, {.s = "#fff"}},
     {NULL, "completion-bg-normal", TYPE_COLOR, setting_completion_style, {.s = "#656565"}},
@@ -495,12 +494,12 @@ static gboolean setting_completion_style(const Setting* s, const SettingType typ
         }
     } else if (s->type == TYPE_FONT) {
         if (type == SETTING_GET) {
-            setting_print_value(s, style->comp_font[ctype]);
+            setting_print_value(s, style->comp_font);
         } else {
-            if (style->comp_font[ctype]) {
-                pango_font_description_free(style->comp_font[ctype]);
+            if (style->comp_font) {
+                pango_font_description_free(style->comp_font);
             }
-            style->comp_font[ctype] = pango_font_description_from_string(s->arg.s);
+            style->comp_font = pango_font_description_from_string(s->arg.s);
         }
     } else {
         VpColor* color = NULL;