From caf8c25c15a2405f7e12e2c6fd616b654d8fc044 Mon Sep 17 00:00:00 2001 From: Liang Chang Date: Sun, 21 Feb 2021 06:52:32 +0800 Subject: [PATCH] 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 c48b19354..ca698dfb9 100644 --- a/cde/programs/dtappbuilder/src/ab/abobj_resize.c +++ b/cde/programs/dtappbuilder/src/ab/abobj_resize.c @@ -73,6 +73,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 ); @@ -356,9 +366,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) @@ -400,6 +410,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; @@ -413,8 +433,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; @@ -432,7 +452,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), @@ -440,7 +460,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), @@ -509,8 +529,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 */ @@ -844,6 +864,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 */