void Set_Spotlight_Attributes(InstanceList objects, Boolean do_area) { InstanceList elmt; XawTextBlock text_block; int old_length; instances = objects; arealight_after = do_area; spotlight_after = FALSE; if ( ! spotlight_shell ) Create_Spotlight_Dialog(); for ( elmt = objects ; elmt->the_instance->o_parent->b_class != spotlight_obj ; elmt = elmt->next ); /* Set all the text strings. */ text_block.firstPos = 0; text_block.format = FMT8BIT; old_length = strlen(intensity_string); sprintf(intensity_string, "%0.2g %0.2g %0.2g", ((LightInfoPtr)elmt->the_instance->o_attribs)->red, ((LightInfoPtr)elmt->the_instance->o_attribs)->green, ((LightInfoPtr)elmt->the_instance->o_attribs)->blue); text_block.length = strlen(intensity_string); text_block.ptr = intensity_string; XawTextReplace(spotlight_intensity_text, 0, old_length + 1, &text_block); old_length = strlen(radius_string); sprintf(radius_string, "%0.2g", ((LightInfoPtr)elmt->the_instance->o_attribs)->val1); text_block.length = strlen(radius_string); text_block.ptr = radius_string; XawTextReplace(radius_text, 0, old_length + 1, &text_block); old_length = strlen(tightness_string); sprintf(tightness_string, "%0.2g", ((LightInfoPtr)elmt->the_instance->o_attribs)->val2); text_block.length = strlen(tightness_string); text_block.ptr = tightness_string; XawTextReplace(tightness_text, 0, old_length + 1, &text_block); /* Set the inverse toggle. */ XtVaSetValues(invert_toggle, XtNstate, ((LightInfoPtr)elmt->the_instance->o_attribs)->flag, NULL); SFpositionWidget(spotlight_shell); XtPopup(spotlight_shell, XtGrabExclusive); }
void Set_Arealight_Attributes(InstanceList objects) { InstanceList elmt; XawTextBlock text_block; int old_length; instances = objects; arealight_after = FALSE; if ( ! arealight_shell ) Create_Arealight_Dialog(); for ( elmt = objects ; elmt->the_instance->o_parent->b_class != arealight_obj ; elmt = elmt->next ); /* Set all the text strings. */ text_block.firstPos = 0; text_block.format = FMT8BIT; old_length = strlen(intensity_string); sprintf(intensity_string, "%0.2g %0.2g %0.2g", ((LightInfoPtr)elmt->the_instance->o_attribs)->red, ((LightInfoPtr)elmt->the_instance->o_attribs)->green, ((LightInfoPtr)elmt->the_instance->o_attribs)->blue); text_block.length = strlen(intensity_string); text_block.ptr = intensity_string; XawTextReplace(arealight_intensity_text, 0, old_length + 1, &text_block); old_length = strlen(xnum_string); sprintf(xnum_string, "%d", (int)(((LightInfoPtr)elmt->the_instance->o_attribs)->val1)); text_block.length = strlen(xnum_string); text_block.ptr = xnum_string; XawTextReplace(xnum_text, 0, old_length + 1, &text_block); old_length = strlen(ynum_string); sprintf(ynum_string, "%d", (int)(((LightInfoPtr)elmt->the_instance->o_attribs)->val2)); text_block.length = strlen(ynum_string); text_block.ptr = ynum_string; XawTextReplace(ynum_text, 0, old_length + 1, &text_block); /* Set the inverse toggle. */ XtVaSetValues(jitter_toggle, XtNstate, ((LightInfoPtr)elmt->the_instance->o_attribs)->flag, NULL); SFpositionWidget(arealight_shell); XtPopup(arealight_shell, XtGrabExclusive); }
// callback routine for ADDMETRICSRESOURCES int fd_input2(int dummy){ Arg args[1]; XawTextPosition pos; XawTextBlock tb; char buf[100]; int size; int noMetrics,noResources,noBins; int aggr; double value; fprintf(stderr,"@@@@ in callback for ADDMETRICSRESOURCES\n"); XtSetArg(args[0], XtNinsertPosition, &pos); XtGetValues(text, args, ONE); noMetrics = visi_NumMetrics(); noResources = visi_NumResources(); noBins = visi_NumBuckets(); value = visi_BucketWidth(); sprintf(&buf[0],"\n%s%d%s%d%s%d%s%f\n","noMetrics = ",noMetrics, ", no resources = ",noResources,", num Bins = ",noBins, "\nbinWidth = ",value); size = strlen(buf); tb.firstPos = 0; tb.length = size; tb.ptr = buf; tb.format = FMT8BIT; if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) { fprintf(stderr,"XawTextReplace returned error\n"); } pos += size; XtSetArg(args[0], XtNinsertPosition, pos); XtSetValues(text, args, ONE); return(0); }
static void NewCurrentClipContents(char *data, int len) { XawTextBlock textBlock; SaveClip (text, currentClip); /* append new clips at the end */ while (currentClip && currentClip->next) currentClip = currentClip->next; /* any trailing clips with no text get overwritten */ if (strlen (currentClip->clip) != 0) currentClip = NewClip (text, currentClip); textBlock.ptr = data; textBlock.firstPos = 0; textBlock.length = len; textBlock.format = FMT8BIT; if (XawTextReplace(text, 0, TextLength (text), &textBlock)) { #ifdef XKB XkbStdBell(XtDisplay(text), XtWindow(text), 0, XkbBI_Info); #else XBell( XtDisplay(text), 0); #endif } set_button_state (); }
// callback routine for NEWMETRICSRESOURCES, PHASENAME int fd_input3(int dummy){ Arg args[1]; XawTextPosition pos; XawTextBlock tb; char buf[100]; int size; XtSetArg(args[0], XtNinsertPosition, &pos); XtGetValues(text, args, ONE); sprintf(&buf[0],"\n%s\n", "This operation is not fully supported: only the call is implemented"); size = strlen(buf); tb.firstPos = 0; tb.length = size; tb.ptr = buf; tb.format = FMT8BIT; if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) { fprintf(stderr,"XawTextReplace returned error\n"); } pos += size; XtSetArg(args[0], XtNinsertPosition, pos); XtSetValues(text, args, ONE); return(0); }
static void show_search_result(char *format,...) { va_list ap; XawTextBlock block; static char tmpstr[300]; va_start(ap, format); vsprintf(tmpstr, format, ap ); va_end(ap); strcat(tmpstr,"\n"); /* append this message to the file message widget string */ block.firstPos = 0; block.ptr = tmpstr; block.length = strlen(tmpstr); block.format = FMT8BIT; /* make editable to add new message */ FirstArg(XtNeditType, XawtextEdit); SetValues(search_results_win); /* insert the new message after the end */ (void) XawTextReplace(search_results_win, msg_length, msg_length, &block); (void) XawTextSetInsertionPoint(search_results_win, msg_length); /* make read-only again */ FirstArg(XtNeditType, XawtextRead); SetValues(search_results_win); msg_length += block.length; }
static void DisplayPageNumber (void) { Arg arg[2]; int actual_number, last_page; XawTextBlock text; int length; char value[128]; char *cur; XtSetArg (arg[0], XtNpageNumber, &actual_number); XtSetArg (arg[1], XtNlastPageNumber, &last_page); XtGetValues (dvi, arg, 2); if (actual_number == 0) sprintf (value, "<none>"); else if (last_page > 0) sprintf (value, "%d of %d", actual_number, last_page); else sprintf (value, "%d", actual_number); text.firstPos = 0; text.length = strlen (value); text.ptr = value; text.format = FMT8BIT; XtSetArg (arg[0], XtNstring, &cur); XtGetValues (XawTextGetSource (pageNumber), arg, 1); length = strlen (cur); XawTextReplace (pageNumber, 0, length, &text); }
void SFsetText (char *path) { XawTextBlock text; text.firstPos = 0; text.length = strlen (path); text.ptr = path; text.format = FMT8BIT; XawTextReplace (selFileField, 0, strlen (SFtextBuffer), &text); XawTextSetInsertionPoint (selFileField, strlen (SFtextBuffer)); }
void text_empty(Widget w) { XawTextBlock b; b.firstPos = 0; b.ptr = CS &b; b.format = FMT8BIT; b.length = 0; XawTextReplace(w, 0, text_count, &b); text_count = 0; XawTextSetInsertionPoint(w, text_count); }
void text_show(Widget w, uschar *s) { XawTextBlock b; b.firstPos = 0; b.ptr = CS s; b.format = FMT8BIT; b.length = Ustrlen(s); XawTextReplace(w, text_count, text_count, &b); text_count += b.length; XawTextSetInsertionPoint(w, text_count); }
void add_log_text(char *str) { XawTextPosition pos = XawTextGetInsertionPoint (logText); XawTextBlock text; text.firstPos = 0; text.length = strlen (str); text.ptr = str; text.format = XawFmt8Bit; XawTextReplace (logText, pos, pos, &text); }
static void EraseTextWidget(void) { XawTextBlock block; block.ptr = ""; block.length = 0; block.firstPos = 0; block.format = FMT8BIT; XawTextReplace(text, 0, INFINITY, &block); /* If this fails, too bad. */ }
// callback routine for FOLD and DATAVALUES int fd_input(int dummy){ Arg args[1]; XawTextPosition pos; XawTextBlock tb; char buf[100]; int i,j,k; int noMetrics,noResources,noBins; int size; double value; XtSetArg(args[0], XtNinsertPosition, &pos); XtGetValues(text, args, ONE); fprintf(stderr,"@@@@ in callback for datavalues and fold\n"); noMetrics = visi_NumMetrics(); noResources = visi_NumResources(); noBins = visi_NumBuckets(); for(i=0;i < noMetrics; i++) for(j=0;j<noResources;j++){ k = dummy; if(visi_Valid(i,j)){ fprintf(stderr,"dataGrid[%d][%d][%d] = %f\n",i,j,k, visi_DataValue(i,j,k)); value = visi_DataValue(i,j,k); if(!(isnan(value))){ sprintf(&buf[0],"%s%d%s%d%s%d%s%f\n","dataGrid[",i,"][",j,"][",k, "] = ",value); } else{ sprintf(&buf[0],"%s%d%s%d%s%d%s\n","dataGrid[",i,"][",j,"][",k , "] = NaN"); } size = strlen(buf); tb.firstPos = 0; tb.length = size; tb.ptr = buf; tb.format = FMT8BIT; if (XawTextReplace(text,pos,pos+size-1,&tb) != XawEditDone) { fprintf(stderr,"XawTextReplace returned error\n"); } pos += size; XtSetArg(args[0], XtNinsertPosition, pos); XtSetValues(text, args, ONE); } } return 1; }
static void TextReplace(Widget w, int start, int end, XawTextBlock *block) { Arg arg; Widget source; XawTextEditType edit_mode; source = XawTextGetSource (w); XtSetArg (arg, XtNeditType, &edit_mode); XtGetValues (source, &arg, ONE); XtSetArg (arg, XtNeditType, XawtextEdit); XtSetValues (source, &arg, ONE); XawTextReplace (w, start, end, block); XtSetArg (arg, XtNeditType, edit_mode); XtSetValues (source, &arg, ONE); }
void XeditPrintf (char *str) { XawTextBlock text; static XawTextPosition pos = 0; text.length = strlen (str); text.ptr = str; text.firstPos = 0; text.format = FMT8BIT; XawTextReplace (messwidget, pos, pos, &text); pos += text.length; XawTextSetInsertionPoint (messwidget, pos); }
void InsertIntoMemo( int which, char * text, int where ) { XawTextBlock t; Widget edit; /* the backend adds \r\n, which is needed for winboard, * for xboard we delete them again over here */ if(t.ptr = strchr(text, '\r')) *t.ptr = ' '; t.ptr = text; t.firstPos = 0; t.length = strlen(text); t.format = XawFmt8Bit; edit = XtNameToWidget(engineOutputShell, which ? "*form2.text" : "*form.text"); XawTextReplace(edit, where, where, &t); if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting int len = strlen(text); highTextStart[which] += len; highTextEnd[which] += len; XawTextSetSelection( outputField[which][nMemo], highTextStart[which], highTextEnd[which] ); } }
/******************************************************************************* Name: printMatchForTextEdit Description: Simulates callbacks for dialog widget Arguments: w - Dialog widget client_data - Dialog widget call_data - Not Used Returns: None *******************************************************************************/ static void printMatchForTextEdit( Widget w, XtPointer client_data, XtPointer call_data) { XawTextBlock text; String aString = XawDialogGetValueString(XtParent(w)); Widget text_widget = (Widget)client_data; int length; length = strlen(completionString); text.firstPos = 0; text.length = strlen(&(aString[length])); text.ptr = &(aString[length]); XawTextReplace(text_widget, XawTextGetInsertionPoint(text_widget), XawTextGetInsertionPoint(text_widget),&text); XawTextSetInsertionPoint(text_widget, XawTextGetInsertionPoint(text_widget) + text.length); XtDestroyWidget(XtParent(XtParent(XtParent(w)))); }
/* * Function: * InsertFileNamed * * Parameters: * tw - text widget to insert this file into * str - name of the file to insert * * Description: * Inserts a file into the text widget. * * Returns: * True if the insert was sucessful, False otherwise. */ static Bool InsertFileNamed(Widget tw, char *str) { FILE *file; XawTextBlock text; XawTextPosition pos; if (str == NULL || strlen(str) == 0 || (file = fopen(str, "r")) == NULL) return (False); pos = XawTextGetInsertionPoint(tw); fseek(file, 0L, 2); text.firstPos = 0; text.length = ftell(file); text.ptr = XtMalloc(text.length + 1); text.format = XawFmt8Bit; fseek(file, 0L, 0); if (fread(text.ptr, 1, text.length, file) != text.length) XtErrorMsg("readError", "insertFileNamed", "XawError", "fread returned error", NULL, NULL); if (XawTextReplace(tw, pos, pos, &text) != XawEditDone) { XtFree(text.ptr); fclose(file); return (False); } pos += text.length; XtFree(text.ptr); fclose(file); XawTextSetInsertionPoint(tw, pos); _XawTextShowPosition((TextWidget)tw); return (True); }
LispObj * Lisp_XawTextReplace(LispBuiltin *builtin) /* xaw-text-replace widget left right text */ { Widget widget; XawTextPosition left, right; XawTextBlock block; LispObj *owidget, *oleft, *oright, *otext; otext = ARGUMENT(3); oright = ARGUMENT(2); oleft = ARGUMENT(1); owidget = ARGUMENT(0); if (!CHECKO(owidget, xawWidget_t)) LispDestroy("%s: cannot convert %s to Widget", STRFUN(builtin), STROBJ(owidget)); widget = (Widget)(owidget->data.opaque.data); CHECK_INDEX(oleft); left = (XawTextPosition)FIXNUM_VALUE(oleft); CHECK_INDEX(oright); right = (XawTextPosition)FIXNUM_VALUE(oright); CHECK_STRING(otext); block.firstPos = 0; block.ptr = THESTR(otext); block.length = strlen(block.ptr); block.format = FMT8BIT; return (FIXNUM(XawTextReplace(widget, left, right, &block))); }
static void show_log(char *s, ...) { int length, newtop; va_list ap; XawTextBlock b; uschar buffer[log_buffer_len + 24]; /* Do nothing if not tailing a log */ if (log_widget == NULL) return; /* Initialize the text block structure */ b.firstPos = 0; b.ptr = CS buffer; b.format = FMT8BIT; /* We want to know whether the window has been scrolled back or not, so that we can cease automatically scrolling with new text. This turns out to be tricky with the text widget. We can detect whether the scroll bar has been operated by checking on the "top" value, but it's harder to detect that it has been returned to the bottom. The following heuristic does its best. */ newtop = XawTextTopPosition(log_widget); if (newtop != top) { if (!scrolled) { visible = size - top; /* save size of window */ scrolled = newtop < top; } else if (newtop > size - visible) scrolled = FALSE; top = newtop; } /* Format the text that is to be written. */ va_start(ap, s); vsprintf(CS buffer, s, ap); va_end(ap); length = Ustrlen(buffer); /* If we are anonymizing for screen shots, flatten various things. */ #ifdef ANONYMIZE { uschar *p = buffer + 9; if (p[6] == '-' && p[13] == '-') p += 17; while (p < buffer + length) { int i; /* Check for strings to be left alone */ for (i = 0; i < oklist_size; i++) { int len = Ustrlen(oklist[i]); if (Ustrncmp(p, oklist[i], len) == 0) { p += len; break; } } if (i < oklist_size) continue; /* Leave driver names, size, protocol, alone */ if ((*p == 'D' || *p == 'P' || *p == 'T' || *p == 'S' || *p == 'R') && p[1] == '=') { p += 2; while (*p != ' ' && *p != 0) p++; continue; } /* Leave C= text alone */ if (Ustrncmp(p, "C=\"", 3) == 0) { p += 3; while (*p != 0 && *p != '"') p++; continue; } /* Flatten remaining chars */ if (isdigit(*p)) *p++ = 'x'; else if (isalpha(*p)) *p++ = 'x'; else *p++ = '$'; } } #endif /* If this would overflow the buffer, throw away 50% of the current stuff in the buffer. Code defensively against odd extreme cases that shouldn't actually arise. */ if (size + length > log_buffer_size) { if (size == 0) length = log_buffer_size/2; else { int cutcount = log_buffer_size/2; if (cutcount > size) cutcount = size; else { while (cutcount < size && log_display_buffer[cutcount] != '\n') cutcount++; cutcount++; } b.length = 0; XawTextReplace(log_widget, 0, cutcount, &b); size -= cutcount; top -= cutcount; if (top < 0) top = 0; if (top < cutcount) XawTextInvalidate(log_widget, 0, 999999); xs_SetValues(log_widget, 1, "displayPosition", top); } } /* Insert the new text at the end of the buffer. */ b.length = length; XawTextReplace(log_widget, 999999, 999999, &b); size += length; /* When not scrolled back, we want to keep the bottom line always visible. Put the insert point at the start of it because this stops left/right scrolling with some X libraries. */ if (!scrolled) { XawTextSetInsertionPoint(log_widget, size - length); top = XawTextTopPosition(log_widget); } }
/******************************************************************************* Name: CompletionEditCallback Description: Called when Completion is selected form File menu in the editor. Arguments: w - menu item that was selected client_data - dialog window or edit window call_data - not used Returns: None *******************************************************************************/ void CompletionEditCallback( Widget w, XtPointer client_data, XtPointer call_data) { int NumberOfMatches,i,length; Boolean tempFlag; struct symbolMatch *matches; extern char* GetCommandString(); XawTextBlock text; char *matchString = NULL; Widget source = XawTextGetSource((Widget)client_data); XawTextPosition CurrentPosition,EndPosition; /* ================================================== */ /* Free the memory of completionString before assign */ /* it to the new string. */ /* ================================================== */ if(completionString != NULL) { free(completionString); completionString = NULL; } /* =================================================== */ /* Get the beginning and ending positions of the */ /* selection. If there is no selection get the last */ /* word from the cursor. */ /* ====================================================*/ XawTextGetSelectionPos((Widget)client_data,&CurrentPosition,&EndPosition); if(CurrentPosition == EndPosition) /* No selection was made */ { matchString = GetBufferFromTextEdit((Widget)client_data); length = strlen(matchString); } else { XawTextSourceRead(source,CurrentPosition,&text,EndPosition - CurrentPosition); XawTextUnsetSelection((Widget)client_data); XawTextSetInsertionPoint((Widget)client_data,EndPosition); matchString = text.ptr; length = text.length; } /* ======================================= */ /* Determine if the word can be matched. */ /* ======================================= */ matchString = GetCommandCompletionString(matchString,length); if(matchString == NULL) { XBell(XtDisplay(toplevel),100); return; } completionString = (char*)malloc(strlen(matchString) + 1); strcpy(completionString,matchString); matches = FindSymbolMatches(completionString,&NumberOfMatches,NULL); if(NumberOfMatches == 0) { XBell(XtDisplay(toplevel),100); return; } else if (NumberOfMatches == 1) { length = strlen(completionString); text.firstPos = 0; text.length = strlen(&(matches->match->contents[length])); text.ptr = &(matches->match->contents[length]); XawTextReplace((Widget)client_data, XawTextGetInsertionPoint((Widget)client_data), XawTextGetInsertionPoint((Widget)client_data),&text); XawTextSetInsertionPoint((Widget)client_data, XawTextGetInsertionPoint((Widget)client_data) + text.length); } else { DisplayMatchedList((Widget)client_data,matches); } }
int GTsetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { PIXsize_t ps; XawTextBlock tb; int ai, li; XColor c; int color; RESETARGS; for (ai = 0; ai < attrn; ai++) { switch (attrp[ai].id) { case G_ATTRSIZE: GETSIZE (attrp[ai].u.s, ps, MINTWSIZE); ADD2ARGS (XtNwidth, ps.x); ADD2ARGS (XtNheight, ps.y); break; case G_ATTRBORDERWIDTH: ADD2ARGS (XtNborderWidth, attrp[ai].u.i); break; case G_ATTRTEXT: ADD2ARGS (XtNstring, attrp[ai].u.t); break; case G_ATTRAPPENDTEXT: XawTextSetInsertionPoint (widget->w, 327670000); li = XawTextGetInsertionPoint (widget->w); tb.firstPos = 0, tb.length = strlen (attrp[ai].u.t); tb.ptr = attrp[ai].u.t, tb.format = FMT8BIT; XawTextReplace (widget->w, li, li, &tb); li = XawTextGetInsertionPoint (widget->w); tb.firstPos = 0, tb.length = 1; tb.ptr = "\n", tb.format = FMT8BIT; XawTextReplace (widget->w, li, li, &tb); break; case G_ATTRMODE: if (strcmp ("oneline", attrp[ai].u.t) == 0) ADD2ARGS (XtNeditType, XawtextAppend); else if (strcmp ("input", attrp[ai].u.t) == 0) ADD2ARGS (XtNeditType, XawtextEdit); else if (strcmp ("output", attrp[ai].u.t) == 0) ADD2ARGS (XtNeditType, XawtextRead); else { Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t); return -1; } break; case G_ATTRCOLOR: color = attrp[ai].u.c.index; if (color != 0 && color != 1) { Gerr (POS, G_ERRBADCOLORINDEX, color); return -1; } c.red = attrp[ai].u.c.r * 257; c.green = attrp[ai].u.c.g * 257; c.blue = attrp[ai].u.c.b * 257; if (XAllocColor ( Gdisplay, DefaultColormap (Gdisplay, Gscreenn), &c )) if (color == 0) ADD2ARGS (XtNbackground, c.pixel); else ADD2ARGS (XtNforeground, c.pixel); break; case G_ATTRWINDOWID: Gerr (POS, G_ERRCANNOTSETATTR2, "windowid"); return -1; case G_ATTRNEWLINECB: WTU->func = (Gtwnewlinecb) attrp[ai].u.func; break; case G_ATTRUSERDATA: widget->udata = attrp[ai].u.u; break; default: Gerr (POS, G_ERRBADATTRID, attrp[ai].id); return -1; } } XtSetValues (widget->w, argp, argn); return 0; }