diff -urN mgdiff-1.0/debian/changelog mgdiff-1.0-patch/debian/changelog --- mgdiff-1.0/debian/changelog Wed Jul 2 13:52:24 2003 +++ mgdiff-1.0-patch/debian/changelog Wed Jul 2 13:55:19 2003 @@ -1,3 +1,11 @@ +mgdiff (1.0-20-rgg-1) unstable; urgency=low + + * Apply my Xselection patch, forward ported to nw Select() + function. Diff 'hunks' selected n the X now go into + the X paste buffer. + + -- Roger Gammans Wed, 2 Jul 2003 13:53:44 +0100 + mgdiff (1.0-20) unstable; urgency=low * applied lots of patches from Erik de Castro Lopo selected; + } + XtVaGetValues (w, XmNwidth, &width, XmNheight, &height, NULL); XtAddExposureToRegion (cbs->event, region = XCreateRegion ()); @@ -761,7 +769,6 @@ dagcb = XtGetGC (children[1], GCForeground|GCBackground, &gc_values); been_here = 1; } - for (i = 0; i < 3; i++) { XtVaGetValues (children[i], XmNwidth, &width[i], @@ -1121,7 +1128,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); @@ -1217,6 +1223,7 @@ } newss.b = di->first; + newss.lastSelected= NULL; newss.topline = newss.sindex = newss.findex[LEFT] = newss.findex[RIGHT] = 0; mainw = XtVaCreateManagedWidget ("mainw", xmMainWindowWidgetClass, @@ -2180,6 +2187,7 @@ handle_diff_errors (di); } + static void refresh (void) { newss.b = di->first; @@ -2245,6 +2253,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) { @@ -2262,6 +2379,8 @@ Block *b; Dimension ypos, height; int itemp, rect_height, widget_side; + Side x_selection = NEITHER; + Block *curr_x_block = newss.lastSelected; if (event->xany.type != ButtonPress) return; @@ -2273,14 +2392,20 @@ else assert (False); + + 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 the current ypos is > height of window, we're done, so just return. */ - if (ypos > height) - return; + if (ypos > height) + return; if ((rect_height = font_height * (b->ssize - itemp)) > (int) height) rect_height = height; @@ -2363,7 +2488,27 @@ redraw_partial (textl, ypos, rect_height); redraw_partial (textr, ypos, rect_height); update_pixmaps (); - return; + + if ( b->selected == NEITHER ) { + if (b == newss.lastSelected) + newss.lastSelected=NULL; + } else { + newss.lastSelected=b; + } + + 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; } }