/* * Move the object to the location of the last drag rect */ int abobj_move( ABObj obj, XEvent *event ) { short x_delta = 0; short y_delta = 0; if (!first_move) { first_move = True; /* erase last box */ x_box_r(parent, &move_rect); x_delta = move_rect.x - orig_rect.x; y_delta = move_rect.y - orig_rect.y; /* * Before the move is performed, record undo information */ (void)abobj_set_undo(sel.list, sel.count, undo_move, AB_UNDO_MOVE); abobj_nudge_selected(sel.list, sel.count, x_delta, y_delta, True); util_free(sel.list); return OK; } return ERROR; }
/* * rubberband_draw() * Draws the rubber band box seen when the mouse is dragged */ static void rubberband_draw( Widget widget, XEvent *event, XtPointer client_data ) { short x,y; if (event->type == ButtonPress) { x = (short)((XButtonEvent*)event)->x; y = (short)((XButtonEvent*)event)->y; } else if (event->type == MotionNotify) { x = (short)((XMotionEvent*)event)->x; y = (short)((XMotionEvent*)event)->y; } else return; if (rb_first_time) { rb_widget = widget; rb_rect.x = x; rb_rect.y = y; rb_first_time = FALSE; } else x_box_r(rb_widget, &rb_rect); rb_rect.width = x - rb_rect.x; rb_rect.height = y - rb_rect.y; x_box_r(rb_widget, &rb_rect); }
/* * Rubberbanding has just finished. * Finish up rubber banding: * - erase last box drawn * - call rubber band func * - reset some state variables */ static void rubberband_finish( Widget widget, XEvent *event, XtPointer client_data ) { if (!rb_first_time) { /* erase last box */ x_box_r(rb_widget, &rb_rect); /* * If a rubber band func was supplied, call it */ if (rubberband_func) rubberband_func(widget, event, &rb_rect, client_data); rubberband_func = NULL; rb_first_time = TRUE; } }
/************************************************************************* ** ** ** Function Definitions ** ** ** **************************************************************************/ int abobjP_move_object_outline( ABObj obj, XMotionEvent *mevent ) { static XRectangle parent_rect; static XRectangle last_rect; static int x_offset, y_offset; static Dimension border_w; static Display *dpy; XRectangle widget_rect; int trans_x, trans_y; /* First time: set up initial move variables */ if (first_move) { if (obj_is_item(obj)) obj = obj_get_parent(obj); obj = obj_get_root(obj); /* Multiple objects might be selected...*/ if (obj_is_control(obj) || obj_is_group(obj) || obj_is_pane(obj)) { abobj_get_selected(obj_get_root(obj_get_parent(obj)), False, False, &sel); } else { sel.count = 1; sel.list = (ABObj*)util_malloc(sizeof(ABObj)); sel.list[0] = obj; } xy_obj = objxm_comp_get_subobj(obj, AB_CFG_POSITION_OBJ); xy_widget = (Widget)xy_obj->ui_handle; if (xy_widget == NULL) { if (util_get_verbosity() > 2) fprintf(stderr,"abobjP_move_object_outline: %s :no POSITION widget\n", util_strsafe(obj_get_name(obj))); return ERROR; } dpy = XtDisplay(xy_widget); parent = XtParent(xy_widget); x_get_widget_rect(xy_widget, &widget_rect); x_get_widget_rect(parent, &parent_rect); if (sel.count > 1) { abobj_get_rect_for_objects(sel.list, sel.count, &orig_rect); } else { orig_rect = widget_rect; XtVaGetValues(xy_widget, XtNborderWidth, &border_w, NULL); orig_rect.width += (2*border_w); orig_rect.height += (2*border_w); orig_rect.width--; orig_rect.height--; } move_rect = orig_rect; drag_init_rect.x = mevent->x - AB_drag_threshold; drag_init_rect.y = mevent->y - AB_drag_threshold; drag_init_rect.width = drag_init_rect.height = 2 * AB_drag_threshold; x_offset = widget_rect.x - orig_rect.x + mevent->x; y_offset = widget_rect.y - orig_rect.y + mevent->y; first_move = False; rect_zero_out(&last_rect); } /* Don't begin rendering move outline until pointer is out of * the drag_init bounding box */ else if (!rect_includespoint(&drag_init_rect, mevent->x, mevent->y)) { Window win; /* event coords are relative to widget-must translate to parent */ XTranslateCoordinates(dpy, XtWindow(xy_widget), XtWindow(parent), mevent->x, mevent->y, &trans_x, &trans_y, &win); move_rect.x = trans_x - x_offset; move_rect.y = trans_y - y_offset; /* Ensure move outline is within the parent's rect */ if (move_rect.x < 0) move_rect.x = 0; else if ((move_rect.x + (short)move_rect.width + 1) >= (short)parent_rect.width) move_rect.x = parent_rect.width - (move_rect.width + 1); if (move_rect.y < 0) move_rect.y = 0; else if ((move_rect.y + (short)move_rect.height + 1) >= (short)parent_rect.height) move_rect.y = parent_rect.height - (move_rect.height + 1); /* If cursor has moved since last event, erase previous outline * and render new one (using XOR function) */ if (!rect_equal(&move_rect, &last_rect)) { if (!rect_isnull(&last_rect)) x_box_r(parent, &last_rect); x_box_r(parent, &move_rect); last_rect = move_rect; } } return OK; }