From: joncruz Date: Mon, 9 Mar 2009 07:39:42 +0000 (+0000) Subject: Made text entry handle standard web-hex values. Fixes bug #168121. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f11cf4b52d554fe0993dcb7b41607601c9978041;p=inkscape.git Made text entry handle standard web-hex values. Fixes bug #168121. --- diff --git a/src/widgets/sp-color-notebook.cpp b/src/widgets/sp-color-notebook.cpp index 9766a9498..779895de4 100644 --- a/src/widgets/sp-color-notebook.cpp +++ b/src/widgets/sp-color-notebook.cpp @@ -448,18 +448,36 @@ void ColorNotebook::_rgbaEntryChanged(GtkEntry* entry) const gchar *t = gtk_entry_get_text( entry ); if (t) { - gchar *e = 0; - guint rgba = strtoul (t, &e, 16); - if ( e != t ) { - ptrdiff_t len=e-t; + Glib::ustring text = t; + bool changed = false; + if (!text.empty() && text[0] == '#') { + changed = true; + text.erase(0,1); + if (text.size() == 6) { + // it was a standard RGB hex + unsigned int alph = SP_COLOR_F_TO_U(_alpha); + gchar* tmp = g_strdup_printf("%02x", alph); + text += tmp; + g_free(tmp); + } + } + gchar* str = g_strdup(text.c_str()); + gchar* end = 0; + guint64 rgba = g_ascii_strtoull( str, &end, 16 ); + if ( end != str ) { + ptrdiff_t len = end - str; if ( len < 8 ) { rgba = rgba << ( 4 * ( 8 - len ) ); } _updatingrgba = TRUE; + if ( changed ) { + gtk_entry_set_text( entry, str ); + } SPColor color( rgba ); setColorAlpha( color, SP_RGBA32_A_F(rgba), true ); _updatingrgba = FALSE; } + g_free(str); } }