From 915ba5d5a94993feda88b7922b6e130ed2c671a3 Mon Sep 17 00:00:00 2001 From: Liang Chang Date: Sat, 20 Feb 2021 22:15:56 +0800 Subject: [PATCH 1/6] dtappbuilder: set limits on the resize rectangle to avoid rollover. --- .../dtappbuilder/src/ab/abobj_resize.c | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/cde/programs/dtappbuilder/src/ab/abobj_resize.c b/cde/programs/dtappbuilder/src/ab/abobj_resize.c index 680441f56..293581aa2 100644 --- a/cde/programs/dtappbuilder/src/ab/abobj_resize.c +++ b/cde/programs/dtappbuilder/src/ab/abobj_resize.c @@ -794,51 +794,51 @@ make_rect ( { case NORTH: new_r->x = r->x; - new_r->y = y; + new_r->y = min(y, rect_bottom(r)); new_r->width = r->width; - new_r->height = (r->y + r->height) - y; + new_r->height = max(0, r->y + r->height - y); break; case SOUTH: new_r->x = r->x; new_r->y = r->y; new_r->width = r->width; - new_r->height = y - r->y; + new_r->height = max(0, y - r->y); break; case EAST: new_r->x = r->x; new_r->y = r->y; - new_r->width = x - r->x; + new_r->width = max(0, x - r->x); new_r->height = r->height; break; case WEST: - new_r->x = x; + new_r->x = min(x, rect_right(r)); new_r->y = r->y; - new_r->width = (r->x + r->width) - x; + new_r->width = max(0, r->x + r->width - x); new_r->height = r->height; break; case NORTH_EAST: new_r->x = r->x; - new_r->y = y; - new_r->width = x - r->x; - new_r->height = (r->y + r->height) - y; + new_r->y = min(y, rect_bottom(r)); + new_r->width = max(0, x - r->x); + new_r->height = max(0, r->y + r->height - y); break; case NORTH_WEST: - new_r->x = x; - new_r->y = y; - new_r->width = (r->x + r->width) - x; - new_r->height = (r->y + r->height) - y; + new_r->x = min(x, rect_right(r)); + new_r->y = min(y, rect_bottom(r)); + new_r->width = max(0, r->x + r->width - x); + new_r->height = max(0, r->y + r->height - y); break; case SOUTH_EAST: new_r->x = r->x; new_r->y = r->y; - new_r->width = x - r->x; - new_r->height = y - r->y; + new_r->width = max(0, x - r->x); + new_r->height = max(0, y - r->y); break; case SOUTH_WEST: - new_r->x = x; + new_r->x = min(x, rect_right(r)); new_r->y = r->y; - new_r->width = (r->x + r->width) - x; - new_r->height = y - r->y; + new_r->width = max(0, r->x + r->width - x); + new_r->height = max(0, y - r->y); break; } } From 3a99e98d6a7482743d1409ef5798d691e42e033b Mon Sep 17 00:00:00 2001 From: Liang Chang Date: Sun, 21 Feb 2021 06:52:32 +0800 Subject: [PATCH 2/6] dtappbuilder: ensure the resize box always inside the main window to avoid the rendering glitch. --- .../dtappbuilder/src/ab/abobj_resize.c | 65 ++++++++++++++++--- 1 file changed, 57 insertions(+), 8 deletions(-) diff --git a/cde/programs/dtappbuilder/src/ab/abobj_resize.c b/cde/programs/dtappbuilder/src/ab/abobj_resize.c index 293581aa2..82a85ae47 100644 --- a/cde/programs/dtappbuilder/src/ab/abobj_resize.c +++ b/cde/programs/dtappbuilder/src/ab/abobj_resize.c @@ -72,6 +72,16 @@ static void make_rect( RESIZE_DIR dir ); +static void +make_rect_in_rect( + XRectangle *pr, + XRectangle *new_r, + XRectangle *r, + int x, + int y, + RESIZE_DIR dir +); + static void undo_resize( ABUndoRec undo_rec ); @@ -355,9 +365,9 @@ abobjP_resize_object_outline( static Widget parent; static Window rootwin; static Display *dpy; - static XRectangle orig_r, r; + static XRectangle orig_r, r, p_rect; static int last_x, last_y; - int x,y; + int x, y, x_tmp, y_tmp; char buf[80]; if (event->type == MotionNotify) @@ -399,6 +409,16 @@ abobjP_resize_object_outline( rootwin = RootWindowOfScreen(XtScreen(xy_widget)); x_get_widget_rect(xy_widget, &orig_r); + + x_get_widget_rect(parent, &p_rect); + + XTranslateCoordinates(dpy, XtWindow(parent), + rootwin, p_rect.x, p_rect.y, &x_tmp, &y_tmp, + &win); + + p_rect.x = x_tmp; + p_rect.y = y_tmp; + if (obj_has_border_frame(obj)) /* We have a border-frame to deal with */ { XRectangle pane_r; @@ -412,8 +432,8 @@ abobjP_resize_object_outline( else border_w = 0; - orig_r.width--; - orig_r.height--; + if (orig_r.width > 0) orig_r.width--; + if (orig_r.height > 0) orig_r.height--; r = orig_r; @@ -431,7 +451,7 @@ abobjP_resize_object_outline( } else /* erase previous outline */ { - make_rect(&resize_rect, &r, last_x, last_y, dir); + make_rect_in_rect(&p_rect, &resize_rect, &r, last_x, last_y, dir); x_fullscreen_box(xy_widget, rootwin, resize_rect.x, resize_rect.y, rect_right(&resize_rect), @@ -439,7 +459,7 @@ abobjP_resize_object_outline( } - make_rect(&resize_rect, &r, x, y, dir); + make_rect_in_rect(&p_rect, &resize_rect, &r, x, y, dir); x_fullscreen_box(xy_widget, rootwin, resize_rect.x, resize_rect.y, rect_right(&resize_rect), @@ -508,8 +528,8 @@ abobj_resize( XTranslateCoordinates(dpy, rootwin, XtWindow(parent), orig_x , orig_y, &trans_x, &trans_y, &win); - resize_rect.width++; - resize_rect.height++; + resize_rect.width++; if (!resize_rect.width) --resize_rect.width; + resize_rect.height++; if (!resize_rect.height) --resize_rect.height; /* Ensure new geometry fits within parent */ @@ -843,6 +863,35 @@ make_rect ( } } +/* + * calculate resize rect based on resize-direction & obj dimensions & a + * boundary. + */ +static void +make_rect_in_rect( + XRectangle *pr, + XRectangle *new_r, + XRectangle *r, + int x, + int y, + RESIZE_DIR dir +) +{ + int x_tmp, y_tmp; + int pr_right = rect_right(pr); + int pr_bottom = rect_bottom(pr); + + if (x < pr->x) x_tmp = pr->x; + else if (x > pr_right) x_tmp = pr_right; + else x_tmp = x; + + if (y < pr->y) y_tmp = pr->y; + else if (y > pr_bottom) y_tmp = pr_bottom; + else y_tmp = y; + + make_rect(new_r, r, x_tmp, y_tmp, dir); +} + /* * Function for undoing RESIZE */ From f70877daa246ab4252e63aed8b36366d93471ed8 Mon Sep 17 00:00:00 2001 From: Liang Chang Date: Mon, 22 Feb 2021 06:27:34 +0800 Subject: [PATCH 3/6] dtappbuilder: set the default size (in pixels) for terminal pane. --- cde/programs/dtappbuilder/src/ab/pal_termp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cde/programs/dtappbuilder/src/ab/pal_termp.c b/cde/programs/dtappbuilder/src/ab/pal_termp.c index ad65ccc05..1049d061f 100644 --- a/cde/programs/dtappbuilder/src/ab/pal_termp.c +++ b/cde/programs/dtappbuilder/src/ab/pal_termp.c @@ -174,6 +174,8 @@ termp_initialize( { obj_set_num_rows(obj, 6); obj_set_num_columns(obj, 12); + obj_set_width(obj, termp_init_width); + obj_set_height(obj, termp_init_width); } obj_set_process_string(obj, "/bin/csh"); From 2851d666eb9cca30422033842b97a44e43a0b2b7 Mon Sep 17 00:00:00 2001 From: Liang Chang Date: Mon, 22 Feb 2021 08:09:24 +0800 Subject: [PATCH 4/6] dtappbuilder: set the minimum limit for rows and columns to avoid rollover. --- cde/programs/dtappbuilder/src/ab/ui_util.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cde/programs/dtappbuilder/src/ab/ui_util.c b/cde/programs/dtappbuilder/src/ab/ui_util.c index 40e696749..1429f86c2 100644 --- a/cde/programs/dtappbuilder/src/ab/ui_util.c +++ b/cde/programs/dtappbuilder/src/ab/ui_util.c @@ -720,7 +720,7 @@ ui_size_to_row_col( XFontStruct *font; unsigned long charwidth; unsigned long lineheight; - Dimension pane_width, pane_height; + int pane_width, pane_height; if (XtIsSubclass(text, dtTermWidgetClass)) XtVaGetValues(text, @@ -776,8 +776,8 @@ ui_size_to_row_col( pane_width = width - (vsb_width + spacing) - (2*p_margin_w); pane_height = height - (hsb_height + spacing) - (2*p_margin_h); - *row_ptr = (int)((pane_height - (2*margin_h))/lineheight); - *col_ptr = (int)((pane_width - (2*margin_w))/charwidth); + *row_ptr = (int)(max(0, pane_height - 2 * margin_h) / lineheight); + *col_ptr = (int)(max(0, pane_width - 2 * margin_w) / charwidth); /* For some reason, above calculations result in rows being 1 too * large for a scrolled list widget; put in workaround until From 7287f262ad418ab2cc4d7d97c272dc3b0c56d696 Mon Sep 17 00:00:00 2001 From: Liang Chang Date: Sun, 4 Apr 2021 09:13:55 +0800 Subject: [PATCH 5/6] dtappbuilder: Fix a crash when resize a text pane. The crash is occurred when drag on the scrollbar to resize. --- cde/programs/dtappbuilder/src/ab/abobj_set.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cde/programs/dtappbuilder/src/ab/abobj_set.c b/cde/programs/dtappbuilder/src/ab/abobj_set.c index 868bb1a47..ff2d15a90 100644 --- a/cde/programs/dtappbuilder/src/ab/abobj_set.c +++ b/cde/programs/dtappbuilder/src/ab/abobj_set.c @@ -1063,9 +1063,7 @@ abobj_set_num_columns( (obj_is_text(obj) || obj_is_term_pane(obj))) { objxm_obj_set_ui_arg(subObj, AB_ARG_INT, XmNcolumns, num_cols); -/* - obj_clear_flag(obj, InstantiatedFlag); -*/ + if (obj_is_text(obj)) obj_clear_flag(obj, InstantiatedFlag); obj_clear_flag(subObj, InstantiatedFlag); } else if (obj_is_choice(obj)) From 5afe94ea3ebd26835ad7e80a76e7f4a46151d040 Mon Sep 17 00:00:00 2001 From: Liang Chang Date: Mon, 5 Apr 2021 07:11:24 +0800 Subject: [PATCH 6/6] dtappbuilder: Fix unsigned integer rollover. --- cde/programs/dtappbuilder/src/ab/abobj_resize.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cde/programs/dtappbuilder/src/ab/abobj_resize.c b/cde/programs/dtappbuilder/src/ab/abobj_resize.c index 82a85ae47..30a4e59d8 100644 --- a/cde/programs/dtappbuilder/src/ab/abobj_resize.c +++ b/cde/programs/dtappbuilder/src/ab/abobj_resize.c @@ -536,7 +536,7 @@ abobj_resize( if (trans_x < 0) { resize_rect.x = 0; - resize_rect.width += trans_x; + resize_rect.width = max(0, resize_rect.width + trans_x); if (obj_is_pane(obj) || obj_is_separator(obj)) /* If a pane, attach to parent's edge */ obj_set_attachment(xy_obj, AB_CP_WEST, AB_ATTACH_OBJ, obj_get_parent(xy_obj), 0); @@ -555,7 +555,7 @@ abobj_resize( if (trans_y < 0) { resize_rect.y = 0; - resize_rect.height += trans_y; + resize_rect.height = max(0, resize_rect.height + trans_y); if (obj_is_pane(obj) || obj_is_separator(obj)) /* If a pane, attach to parent's edge */ obj_set_attachment(xy_obj, AB_CP_NORTH, AB_ATTACH_OBJ, obj_get_parent(xy_obj), 0); @@ -573,7 +573,7 @@ abobj_resize( if (resize_rect.x + (short)resize_rect.width >= (short)p_rect.width) { - resize_rect.width = (short)p_rect.width - resize_rect.x - 1; + resize_rect.width = max(0, (short)p_rect.width - resize_rect.x - 1); if (obj_is_pane(obj) || obj_is_separator(obj)) /* If a pane, attach to parent's edge */ obj_set_attachment(xy_obj, AB_CP_EAST, AB_ATTACH_OBJ, obj_get_parent(xy_obj), 0); @@ -589,7 +589,7 @@ abobj_resize( if (resize_rect.y + (short)resize_rect.height > (short)p_rect.height) { - resize_rect.height = (short)p_rect.height - resize_rect.y - 1; + resize_rect.height = max(0, (short)p_rect.height - resize_rect.y - 1); if (obj_is_pane(obj) || obj_is_separator(obj)) /* If a pane, attach to parent's edge */ obj_set_attachment(xy_obj, AB_CP_SOUTH, AB_ATTACH_OBJ, obj_get_parent(xy_obj), 0);