[anjuta] libanjuta/anjuta-entry: Don't use CSS for help text styles
- From: James Liggett <jrliggett src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] libanjuta/anjuta-entry: Don't use CSS for help text styles
- Date: Mon, 24 Jun 2013 07:49:03 +0000 (UTC)
commit 4668028ebba542b1ab3c93cd51168145236215a8
Author: James Liggett <jrliggett cox net>
Date: Mon Jun 24 00:48:15 2013 -0700
libanjuta/anjuta-entry: Don't use CSS for help text styles
Some themes, including Ubuntu's, don't define insensitive_fg_color, making the
help text render white when such themes are used with custom CSS styles. In
many cases, the entry background is also a light color, making the help text
unreadable.
libanjuta/anjuta-entry.c | 57 ++++++++++++++++-----------------------------
libanjuta/anjuta-entry.h | 7 +----
2 files changed, 22 insertions(+), 42 deletions(-)
---
diff --git a/libanjuta/anjuta-entry.c b/libanjuta/anjuta-entry.c
index 38d4a46..44f0331 100644
--- a/libanjuta/anjuta-entry.c
+++ b/libanjuta/anjuta-entry.c
@@ -45,26 +45,21 @@ typedef enum
ANJUTA_ENTRY_HELP
} AnjutaEntryMode;
-struct _AnjutaEntryClassPrivate
-{
- GtkCssProvider *css;
-};
-
-struct _AnjutaEntryPrivate
+struct _AnjutaEntryPriv
{
gboolean showing_help_text;
gchar *help_text;
};
-G_DEFINE_TYPE_WITH_CODE (AnjutaEntry, anjuta_entry, GTK_TYPE_ENTRY,
- g_type_add_class_private (g_define_type_id, sizeof (AnjutaEntryClassPrivate)))
+G_DEFINE_TYPE (AnjutaEntry, anjuta_entry, GTK_TYPE_ENTRY);
static void
anjuta_entry_set_mode (AnjutaEntry *self, AnjutaEntryMode mode)
{
- GtkStyleContext *context;
+ GtkStyleContext *style_context;
+ GdkRGBA insensitive_color;
- context = gtk_widget_get_style_context (GTK_WIDGET (self));
+ style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
switch (mode)
{
@@ -73,8 +68,8 @@ anjuta_entry_set_mode (AnjutaEntry *self, AnjutaEntryMode mode)
if (self->priv->showing_help_text)
gtk_entry_set_text (GTK_ENTRY (self), "");
- gtk_style_context_add_class (context, "anjuta-entry-mode-normal");
- gtk_style_context_remove_class (context, "anjuta-entry-mode-help");
+ gtk_widget_override_color (GTK_WIDGET (self), GTK_STATE_NORMAL,
+ NULL);
self->priv->showing_help_text = FALSE;
@@ -85,8 +80,17 @@ anjuta_entry_set_mode (AnjutaEntry *self, AnjutaEntryMode mode)
else
gtk_entry_set_text (GTK_ENTRY (self), "");
- gtk_style_context_add_class (context, "anjuta-entry-mode-help");
- gtk_style_context_remove_class (context, "anjuta-entry-mode-normal");
+ /* FIXME: Ideally we should be using CSS here, but some themes,
+ * like Ubuntu's, don't define insensitive_fg_color. The help text
+ * renders white on these themes, which is unreadable in many cases.
+ *
+ * This should make the help text readable on all themes, but the
+ * color won't change if the theme changes while Anjuta is running.
+ */
+ gtk_style_context_get_color (style_context, GTK_STATE_FLAG_INSENSITIVE,
+ &insensitive_color);
+ gtk_widget_override_color (GTK_WIDGET (self), GTK_STATE_NORMAL,
+ &insensitive_color);
self->priv->showing_help_text = TRUE;
@@ -110,17 +114,8 @@ anjuta_entry_icon_release (GtkEntry *entry, GtkEntryIconPosition icon_pos,
static void
anjuta_entry_init (AnjutaEntry *self)
{
- GtkStyleContext *context;
+ self->priv = g_new0 (AnjutaEntryPriv, 1);
- self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ANJUTA_TYPE_ENTRY,
- AnjutaEntryPrivate);
-
- /* Setup styling */
- context = gtk_widget_get_style_context (GTK_WIDGET (self));
- gtk_style_context_add_provider (context,
- GTK_STYLE_PROVIDER (ANJUTA_ENTRY_GET_CLASS (self)->priv->css),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-
gtk_entry_set_icon_from_stock (GTK_ENTRY (self), GTK_ENTRY_ICON_SECONDARY,
GTK_STOCK_CLEAR);
gtk_entry_set_icon_activatable (GTK_ENTRY (self), GTK_ENTRY_ICON_SECONDARY,
@@ -141,6 +136,7 @@ anjuta_entry_finalize (GObject *object)
self = ANJUTA_ENTRY (object);
g_free (self->priv->help_text);
+ g_free (self->priv);
G_OBJECT_CLASS (anjuta_entry_parent_class)->finalize (object);
}
@@ -233,19 +229,12 @@ anjuta_entry_class_init (AnjutaEntryClass *klass)
GObjectClass* object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- static const gchar entry_style[] =
- "AnjutaEntry.anjuta-entry-mode-help {\n"
- "color: @insensitive_fg_color;\n"
- "}";
-
object_class->finalize = anjuta_entry_finalize;
object_class->set_property = anjuta_entry_set_property;
object_class->get_property = anjuta_entry_get_property;
widget_class->focus_in_event = anjuta_entry_focus_in_event;
widget_class->focus_out_event = anjuta_entry_focus_out_event;
- g_type_class_add_private (klass, sizeof(AnjutaEntryPrivate));
-
/**
* AnjutaEntry::help-text:
*
@@ -259,12 +248,6 @@ anjuta_entry_class_init (AnjutaEntryClass *klass)
_("Text to show the user what to enter into the
entry"),
"",
G_PARAM_READABLE | G_PARAM_WRITABLE));
-
-
- klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, ANJUTA_TYPE_ENTRY, AnjutaEntryClassPrivate);
-
- klass->priv->css = gtk_css_provider_new ();
- gtk_css_provider_load_from_data (klass->priv->css, entry_style, -1, NULL);
}
/**
diff --git a/libanjuta/anjuta-entry.h b/libanjuta/anjuta-entry.h
index 2a722e2..199fc30 100644
--- a/libanjuta/anjuta-entry.h
+++ b/libanjuta/anjuta-entry.h
@@ -35,21 +35,18 @@ G_BEGIN_DECLS
typedef struct _AnjutaEntryClass AnjutaEntryClass;
typedef struct _AnjutaEntry AnjutaEntry;
-typedef struct _AnjutaEntryPrivate AnjutaEntryPrivate;
-typedef struct _AnjutaEntryClassPrivate AnjutaEntryClassPrivate;
+typedef struct _AnjutaEntryPriv AnjutaEntryPriv;
struct _AnjutaEntryClass
{
GtkEntryClass parent_class;
-
- AnjutaEntryClassPrivate *priv;
};
struct _AnjutaEntry
{
GtkEntry parent_instance;
- AnjutaEntryPrivate *priv;
+ AnjutaEntryPriv *priv;
};
GType anjuta_entry_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]