]> git.neil.brown.name Git - edlib.git/commitdiff
lib-messageline: use new text-display interface
authorNeilBrown <neil@brown.name>
Tue, 5 Jan 2016 01:54:05 +0000 (12:54 +1100)
committerNeilBrown <neil@brown.name>
Tue, 5 Jan 2016 01:54:05 +0000 (12:54 +1100)
Also some fixes and hacks...

Signed-off-by: NeilBrown <neil@brown.name>
core.h
display-ncurses.c
lib-messageline.c
python/display-pygtk.py

diff --git a/core.h b/core.h
index d40da1c5119e25400ac29b5f27cf104c68ade8c1..9a3d5f16aaa06cec05eff22fba67429eef6c0c46 100644 (file)
--- 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)
 {
index 42fdd0231e2d9689231993c85e2de67042cacd56..42c422846f2cfedfbffc22855777c20171ff3818 100644 (file)
@@ -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);
index b381dd54f96f348d55e09a4f21e080915c7054fe..665da051d85a2f72d4899898a134b17081de5d41 100644 (file)
 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);
index 6e63e376149f5302cfe13e2ee5c66aaff64a029c..8f0e3f4762553be0137beb8f28d05609bc022565 100644 (file)
@@ -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)