Read a textbox' text correctly

Previously, querying a textbox' .text property would return the text with all
pango markup stripped.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-07-16 18:54:57 +02:00
parent 64855b41cd
commit 0655f13615
1 changed files with 25 additions and 4 deletions

View File

@ -40,6 +40,10 @@ typedef struct
/** The textbox private data structure */ /** The textbox private data structure */
typedef struct typedef struct
{ {
/** The actual text the textbox is set to */
char *text;
/** The length of text */
size_t text_len;
draw_text_context_t data; draw_text_context_t data;
/** Textbox width and height */ /** Textbox width and height */
int width, height; int width, height;
@ -208,6 +212,7 @@ textbox_destructor(widget_t *w)
{ {
textbox_data_t *d = w->data; textbox_data_t *d = w->data;
draw_text_context_wipe(&d->data); draw_text_context_wipe(&d->data);
p_delete(&d->text);
p_delete(&d); p_delete(&d);
} }
@ -278,9 +283,9 @@ luaA_textbox_index(lua_State *L, awesome_token_t token)
luaA_pushcolor(L, &d->border.color); luaA_pushcolor(L, &d->border.color);
return 1; return 1;
case A_TK_TEXT: case A_TK_TEXT:
if(d->data.len > 0) if(d->text_len > 0)
{ {
lua_pushlstring(L, d->data.text, d->data.len); lua_pushlstring(L, d->text, d->text_len);
return 1; return 1;
} }
return 0; return 0;
@ -377,20 +382,36 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token)
{ {
/* delete */ /* delete */
draw_text_context_wipe(&d->data); draw_text_context_wipe(&d->data);
p_delete(&d->text);
d->text_len = 0;
p_clear(&d->data, 1); p_clear(&d->data, 1);
if(buf) if(buf)
{ {
char *text; char *text;
ssize_t tlen; ssize_t tlen;
bool success;
/* if text has been converted to UTF-8 */ /* if text has been converted to UTF-8 */
if(draw_iso2utf8(buf, len, &text, &tlen)) if(draw_iso2utf8(buf, len, &text, &tlen))
{ {
draw_text_context_init(&d->data, text, tlen); success = draw_text_context_init(&d->data, text, tlen);
if(success)
{
d->text = p_dup(text, tlen);
d->text_len = tlen;
}
p_delete(&text); p_delete(&text);
} }
else else
draw_text_context_init(&d->data, buf, len); {
success = draw_text_context_init(&d->data, buf, len);
if(success)
{
d->text = p_dup(buf, len);
d->text_len = len;
}
}
d->extents = draw_text_extents(&d->data); d->extents = draw_text_extents(&d->data);
} }