From a05af1426075050d5d0cf155b54163799a9efb6c Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 5 Jan 2016 12:54:05 +1100 Subject: [PATCH] lib-messageline: use new text-display interface Also some fixes and hacks... Signed-off-by: NeilBrown --- core.h | 32 ++++++++++++++++++++++++++++++++ display-ncurses.c | 2 +- lib-messageline.c | 39 ++++++++++++++++++++++++++------------- python/display-pygtk.py | 22 +++++++++++----------- 4 files changed, 70 insertions(+), 25 deletions(-) diff --git a/core.h b/core.h index d40da1c5..9a3d5f16 100644 --- a/core.h +++ b/core.h @@ -527,6 +527,21 @@ static inline int call5(char *key, struct pane *focus, int numeric, struct mark return key_handle(&ci); } +static inline int call_xy(char *key, struct pane *focus, int numeric, + char *str, char *str2, int x, int y) +{ + struct cmd_info ci = {0}; + + ci.key = key; + ci.focus = focus; + ci.numeric = numeric; + ci.str = str; + ci.str2 = str2; + ci.x = x; + ci.y = y; + return key_handle(&ci); +} + static inline int call7(char *key, struct pane *focus, int numeric, struct mark *m, char *str, int extra, char *str2, struct mark *m2) { @@ -549,6 +564,7 @@ struct call_return { char *s; struct pane *p; int i; + int x,y; }; static inline int call_comm(char *key, struct pane *focus, int numeric, struct mark *m, @@ -566,6 +582,22 @@ static inline int call_comm(char *key, struct pane *focus, int numeric, struct m return key_handle(&ci); } +static inline int call_comm7(char *key, struct pane *focus, int numeric, struct mark *m, + char *str, int extra, char *str2, struct command *comm) +{ + struct cmd_info ci = {0}; + + ci.key = key; + ci.focus = focus; + ci.numeric = numeric; + ci.mark = m; + ci.str = str; + ci.str2 = str2; + ci.extra = extra; + ci.comm2 = comm; + return key_handle(&ci); +} + static inline int comm_call(struct command *comm, char *key, struct pane *focus, int numeric, struct mark *m, char *str, int extra) { diff --git a/display-ncurses.c b/display-ncurses.c index 42fdd023..42c42284 100644 --- a/display-ncurses.c +++ b/display-ncurses.c @@ -166,7 +166,7 @@ DEF_CMD(ncurses_handle) max_bytes = offset; } return comm_call_xy(ci->comm2, "callback:size", ci->focus, - max_bytes, 1, size, 1); + max_bytes, 0, size, 1); } if (strcmp(ci->key, "text-display") == 0) { int attr = cvt_attrs(ci->str2); diff --git a/lib-messageline.c b/lib-messageline.c index b381dd54..665da051 100644 --- a/lib-messageline.c +++ b/lib-messageline.c @@ -17,19 +17,22 @@ struct mlinfo { char *message; struct pane *line; + int height; /* height of line */ + int ascent; /* how for down to baseline */ }; static void pane_str(struct pane *p, char *s, char *attr, int x, int y) { - mbstate_t ps = {0}; - int err; - wchar_t ch; + call_xy("text-display", p, -1, s, attr, x, y); +} - while ((err = mbrtowc(&ch, s, 5, &ps)) > 0) { - pane_text(p, ch, attr, x, y); - s += err; - x += 1; - } +DEF_CMD(text_size_callback) +{ + struct call_return *cr = container_of(ci->comm, struct call_return, c); + cr->x = ci->x; + cr->y = ci->y; + cr->i = ci->extra; + return 1; } DEF_CMD(messageline_handle) @@ -51,15 +54,24 @@ DEF_CMD(messageline_handle) return 0; } if (strcmp(ci->key, "Refresh") == 0) { + if (mli->height == 0) { + struct call_return cr; + cr.c = text_size_callback; + call_comm7("text-size", ci->home, 0, NULL, + "M", 0, "bold", &cr.c); + mli->height = cr.y; + mli->ascent = cr.i; + } if (ci->home == mli->line) { - pane_resize(ci->home, 0, ci->home->parent->h - 1, - ci->home->parent->w, 1); - pane_clear(mli->line, ""); + pane_resize(ci->home, 0, ci->home->parent->h - mli->height, + ci->home->parent->w, mli->height); + pane_clear(mli->line, "bg:cyan"); if (mli->message) - pane_str(mli->line, mli->message, "bold", 0, 0); + pane_str(mli->line, mli->message, "bold,fg:red,bg:cyan", + 0, 0 + mli->ascent); } else { pane_resize(ci->home, 0, 0, ci->home->parent->w, - ci->home->parent->h - 1); + ci->home->parent->h - mli->height); } return 1; } @@ -79,6 +91,7 @@ DEF_CMD(messageline_attach) struct pane *ret; mli->message = NULL; + mli->height = 0; ret = pane_register(p, 0, &messageline_handle, mli, NULL); mli->line = pane_register(p, 1, &messageline_handle, mli, NULL); pane_focus(ci->focus); diff --git a/python/display-pygtk.py b/python/display-pygtk.py index 6e63e376..8f0e3f47 100644 --- a/python/display-pygtk.py +++ b/python/display-pygtk.py @@ -51,7 +51,7 @@ class EdDisplay(gtk.Window): if key == "text-size": fd = self.extract_font(a["str2"]) - ctx = self.text.pango_get_context() + ctx = self.text.get_pango_context() metric = ctx.get_metrics(fd) self.text.modify_font(fd) layout = self.text.create_pango_layout(a["str"]) @@ -59,21 +59,21 @@ class EdDisplay(gtk.Window): ascent = metric.get_ascent() / pango.SCALE cb = a["comm2"] max_bytes,something = layout.xy_to_index(a["numeric"], 0) - return cb.call("callback:size", f, max_bytes, ascent, (width, height)) + f = a["focus"] + return cb("callback:size", f, max_bytes, ascent, (width, height)) if key == "text-display": (x,y) = a["xy"] + f = a["focus"] fd = self.extract_font(a["str2"]) - ctx = self.text.pango_get_context() - self.text_modify_font(fd) + ctx = self.text.get_pango_context() + self.text.modify_font(fd) layout = self.text.create_pango_layout(a["str"]) - #ink,(xo,yo,width,height) = layout.get_pixel_extents() fg, bg = self.get_colours(a["str2"]) pm = self.get_pixmap(f) metric = ctx.get_metrics(fd) ascent = metric.get_ascent() / pango.SCALE - #pm.draw_rectangle(bg, True, x+xo-ascent, y+yo, width, height) - pm.draw_layout(fg, x-ascent, y, layout, fg, bg) + pm.draw_layout(self.gc, x, y-ascent, layout, fg, bg) if key == "Notify:Close": f = a["focus"] @@ -90,8 +90,8 @@ class EdDisplay(gtk.Window): family="mono" style="" size=10 - for word in attrs.split(): - if word in styles: + for word in attrs.split(','): + if word in self.styles: style += " " + word elif word == "large": size = 14 @@ -103,7 +103,7 @@ class EdDisplay(gtk.Window): "Return a foreground and a background colour" fg = "black" bg = "white" - for word in attrs.split(): + for word in attrs.split(','): if word[0:3] == "fg:": fg = word[3:] if word[0:3] == "bg:": @@ -247,7 +247,7 @@ class EdDisplay(gtk.Window): def do_clear(self, pm, colour): t = self.text - if not self.bg: + if not self.bg or True: self.bg = t.window.new_gc() cmap = t.get_colormap() self.bg.set_foreground(colour) -- 2.39.5