From: handa Date: Wed, 17 Mar 2004 07:41:46 +0000 (+0000) Subject: (update_selection): Fix for the case that the selected X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=41b3ec49a597bdc8b158dcc072f6a6043fd03ffd;p=m17n%2Fm17n-lib.git (update_selection): Fix for the case that the selected region is expanded to the opposite direction. (ButtonMoveProc): Likewise. (main): Use alloca instead of malloc for allocating menu names. Free several memory areas and GCs. --- diff --git a/example/medit.c b/example/medit.c index affd64c..c7736fb 100644 --- a/example/medit.c +++ b/example/medit.c @@ -498,28 +498,28 @@ update_selection () if (from < top.from) { - GLYPH_INFO (bol (from, 0), from, info); - sel_start.ascent = -info.this.y; - sel_start.from = info.line_from; - sel_start.to = info.line_to; - TEXT_EXTENTS (from, top.from, rect); - sel_start.y0 = - rect.height; - sel_start.y1 = sel_start.y0 + info.this.height; + int pos = bol (from, 0); + + TEXT_EXTENTS (pos, top.from, rect); + sel_start.y0 = top.y0 - rect.height; + sel_start.ascent = - rect.y; + GLYPH_INFO (pos, from, info); + if (pos < info.line_from) + sel_start.y0 += - rect.y + info.y + info.this.y; } else { GLYPH_INFO (top.from, from, info); sel_start.y0 = top.ascent + info.y + info.this.y; - sel_start.y1 = sel_start.y0 + info.this.height; - sel_start.ascent = -info.this.y; - sel_start.from = info.line_from; - sel_start.to = info.line_to; } + sel_start.ascent = -info.this.y; + sel_start.y1 = sel_start.y0 + info.this.height; + sel_start.from = info.line_from; + sel_start.to = info.line_to; if (to <= sel_start.to) { sel_end = sel_start; - to = bol (to - 1, 1) - 1; if (to >= sel_end.to) { GLYPH_INFO (sel_start.from, to, info); @@ -529,7 +529,6 @@ update_selection () } else { - to = bol (to - 1, 1) - 1; GLYPH_INFO (sel_start.from, to, info); sel_end.y0 = sel_start.y0 + sel_start.ascent + info.y + info.this.y; sel_end.y1 = sel_end.y0 + info.this.height; @@ -1143,25 +1142,61 @@ ButtonMoveProc (Widget w, XEvent *event, String *str, Cardinal *num) if (cursor.from == from) { - /* Start position of selection changed. */ - select_region (pos, to); - if (pos > from) - /* Shrunken. Previous selection face must be cleared. */ - redraw (start_y0, sel_start.y1, 1, 0); + /* Starting position changed. */ + if (pos <= from) + { + /* Enlarged. We can simply overdraw. */ + select_region (pos, to); + redraw (sel_start.y0, start_y1, 0, 0); + } + else if (pos < to) + { + /* Shrunken. Previous selection face must be cleared. */ + select_region (pos, to); + redraw (start_y0, sel_start.y1, 1, 0); + } + else if (pos == to) + { + /* Shrunken to zero. */ + XtDisownSelection (w, XA_PRIMARY, CurrentTime); + mtext_detach_property (selection); + redraw (start_y0, end_y1, 1, 0); + } else - /* Enlarged. We can simply overdraw. */ - redraw (sel_start.y0, start_y1, 0, 0); + { + /* Full update is necessary. */ + select_region (to, pos); + redraw (start_y0, sel_end.y1, 1, 0); + } } else { - /* End position of selection changed. */ - select_region (from, pos); - if (pos < to) - /* Shrunken. Previous selection face must be cleared. */ - redraw (sel_end.y0, end_y1, 1, 0); + /* Ending position changed. */ + if (pos < from) + { + /* Full update is necessary. */ + select_region (pos, from); + redraw (sel_start.y0, end_y1, 1, 0); + } + else if (pos == from) + { + /* Shrunken to zero. */ + XtDisownSelection (w, XA_PRIMARY, CurrentTime); + mtext_detach_property (selection); + redraw (start_y0, end_y1, 1, 0); + } + else if (pos < to) + { + /* Shrunken. Previous selection face must be cleared. */ + select_region (from, pos); + redraw (sel_end.y0, end_y1, 1, 0); + } else - /* Enlarged. We can simply overdraw. */ - redraw (end_y0, sel_end.y1, 0, 0); + { + /* Enlarged. We can simply overdraw. */ + select_region (from, pos); + redraw (end_y0, sel_end.y1, 0, 0); + } } } else