Also some fixes and hacks...
Signed-off-by: NeilBrown <neil@brown.name>
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)
{
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,
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)
{
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);
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)
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;
}
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);
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"])
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"]
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
"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:":
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)