From d16ca829aae999e6f02230956dbf2371a78a3091 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 8 Jan 2011 13:55:36 +0100 Subject: [PATCH] textbox: Verify a text when it is set This makes the textbox pass the markup/text it is given to oopango immediately. If it is invalid, a lua error will be thrown and the old text will still be shown. This fixes a bug where the whole wibox isn't redrawn when a textbox complains about broken UTF8. Signed-off-by: Uli Schlachter --- lib/wibox/widget/textbox.lua.in | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/wibox/widget/textbox.lua.in b/lib/wibox/widget/textbox.lua.in index 19f972d7..58de6de9 100644 --- a/lib/wibox/widget/textbox.lua.in +++ b/lib/wibox/widget/textbox.lua.in @@ -108,16 +108,23 @@ function fit(box, width, height) return res.width, res.height end ---- Test if a textbox' text is valid. If it isn't, a lua error will be thrown. -function check(box) - -- This creates a pango layout for the string and so forces pango to verify - -- whether we have some sane input for it - get_size(box, nil, -1, -1) +-- Test if a text is valid for a textbox. If it isn't, a lua error will be thrown. +local function check_text(text, markup) + local surface = oocairo.image_surface_create("argb32", 1, 1) + local cr = oocairo.context_create(surface) + local layout = layout_create(cr) + + if markup then + layout:set_markup(text) + else + layout:set_text(text) + end end --- Set a textbox' text. -- @param text The text to set. This can contain pango markup (e.g. bold) function set_markup(box, text) + check_text(text, true) box._text = text box._markup = true box:emit_signal("widget::updated") @@ -126,6 +133,7 @@ end --- Set a textbox' text. -- @param text The text to display. Pango markup is ignored and shown as-is. function set_text(box, text) + check_text(text, false) box._text = text box._markup = false box:emit_signal("widget::updated") -- 2.11.4.GIT