--- mgdiff.c.orig Thu Apr 19 15:10:41 2001 +++ mgdiff.c Sat Apr 21 00:18:05 2001 @@ -137,6 +137,7 @@ static struct screenstate { Block *b; + Block *lastSelected; int topline; int leftcol; int sindex, findex[2]; @@ -724,7 +725,6 @@ dagcb = XtGetGC (children[1], GCForeground|GCBackground, &gc_values); been_here = 1; } - for (i = 0; i < 3; i++) { XtVaGetValues (children[i], XmNwidth, &width[i], @@ -1079,7 +1079,6 @@ }; werror_long (toplevel, "Wrong Application Defaults", array, sizeof (array) / sizeof (array[0])); } - if (debug_flag) { XSetErrorHandler (x_error_handler); XtAppSetErrorHandler (app, xt_error_handler); @@ -1174,6 +1173,7 @@ } newss.b = di->first; + newss.lastSelected= NULL; newss.topline = newss.sindex = newss.findex[LEFT] = newss.findex[RIGHT] = 0; mainw = XtVaCreateManagedWidget ("mainw", xmMainWindowWidgetClass, @@ -2133,6 +2133,7 @@ handle_diff_errors (di); } + static void refresh (void) { newss.b = di->first; @@ -2196,6 +2197,115 @@ exit ((di != NULL) ? di->status : 2); } +void lost_selection ( Widget widget, Atom* selection) { + + if (debug_flag) { + fprintf(stderr,"selection lost on widget %p\n",widget); + } +// newss.lastSelected=NULL; +} + +static Boolean do_selection(Widget widget, Atom* selection, Atom* target , + Atom* type, XtPointer* value, + unsigned long* length,int* format) { + + Atom targets = XInternAtom(XtDisplay(widget), "TARGETS", False); + Atom *array; + char* result; + char* line; + int i,j; + Block *b= newss.lastSelected; + Chunk *chunk =NULL; + + if (debug_flag) { + fprintf(stderr,"selection request on widget %p\n",widget); + } + + if (!b) return False; + + chunk = &(b->arr[b->selected]); + + if (*target == targets) + { + if (debug_flag) { + fprintf(stderr,"clipboards targets requested on widget %p\n",widget); + } + /* + * Handle request for data types + */ + + if ((array = (Atom *)XtMalloc((unsigned)(sizeof(Atom) * 1))) == NULL) + return False; + *value = (XtPointer)array; + array[0] = XA_STRING; + *type = XA_ATOM; + *format = sizeof(Atom) * 8; + *length = 5; + return True; + } + + if (*target == XA_STRING) { + /* + * request for string data !. + */ + if (debug_flag) { + fprintf(stderr,"string target requested on widget %p\n",widget); + } + + /* + * Iterate through the lines in the text block + * summing the lengths + */ + *length=0; + for (i = 0; i < chunk->fsize; i++) { + if ((chunk->wtext != NULL) && (chunk->wtext[i] != NULL)) { + *length += (strlen(chunk->wtext[i])+1); + } else { + *length += (strlen(chunk->text[i])+1); + } + } + *format = 8; /* 8 bits per char */ + *type = XA_STRING; + if (debug_flag) { + fprintf(stderr,"string length= %li\n",*length); + } + + *value = XtMalloc(*length); + result = (char*)(*value); + /* + * Iterate through the lines in the text block + * moving the data into the clipboard memblock + */ + for (i = 0; i < chunk->fsize; i++) { + if ((chunk->wtext != NULL) && (chunk->wtext[i] != NULL)) { + line = chunk->wtext[i] ; + } else { + line = chunk->text[i]; + } + j =strlen(line); + memcpy(result,line,j); + result+=j; + *(result++)= '\n'; + } + + + if (debug_flag) { + fprintf(stderr,"all done string at= %p\n",*value); + } + if (!(*value)) { + return False; + } + return True; + } + /* + * Haven't found data type we know about! + */ + return False; +} + + + + /* ARGSUSED2 */ static void Select (Widget widget, XEvent *event, String *params, Cardinal *num_params) { @@ -2203,11 +2313,19 @@ Block *b; Dimension ypos, height; int itemp, rect_height; - + + Side x_selection = NEITHER; + Block *curr_x_block = newss.lastSelected; + + if (curr_x_block) { + x_selection = curr_x_block->selected; + } + XtVaGetValues (widget, XmNheight, &height, NULL); itemp = newss.sindex; ypos = 0; + //Find selected chunk!. for (b = newss.b; b != NULL; b = b->next) { if ((rect_height = font_height * (b->ssize - itemp)) > (int) height) rect_height = height; @@ -2222,12 +2340,15 @@ redraw_partial (textl, ypos, rect_height); redraw_partial (textr, ypos, rect_height); update_pixmaps (); + if (b == newss.lastSelected) + newss.lastSelected=NULL; } else if (widget == textr) { b->selected = RIGHT; redraw_partial (textl, ypos, rect_height); redraw_partial (textr, ypos, rect_height); update_pixmaps (); + newss.lastSelected=b; } else assert (False); @@ -2238,12 +2359,15 @@ redraw_partial (textl, ypos, rect_height); redraw_partial (textr, ypos, rect_height); update_pixmaps (); + newss.lastSelected=b; } else if (widget == textr) { b->selected = NEITHER; redraw_partial (textl, ypos, rect_height); redraw_partial (textr, ypos, rect_height); update_pixmaps (); + if (b == newss.lastSelected) + newss.lastSelected=NULL; } else assert (False); @@ -2253,10 +2377,24 @@ redraw_partial (textl, ypos, rect_height); redraw_partial (textr, ypos, rect_height); update_pixmaps (); + newss.lastSelected=b; break; default: assert (False); break; + } + if ( + + !newss.lastSelected + || (x_selection != newss.lastSelected->selected) + // || (newss.lastSelected != curr_x_block ) + + ) { + XtDisownSelection(widget,XA_PRIMARY, CurrentTime); + } + if (newss.lastSelected) { + XtOwnSelection(widget,XA_PRIMARY, CurrentTime, + &do_selection,&lost_selection,NULL); } return; }