/* * Given two positions, find the distance between them. */ static void FindDistance( Widget w, XawTextPosition fromPos, /* First position. */ int fromx, /* Horizontal location of first position. */ XawTextPosition toPos, /* Second position. */ int *resWidth, /* Distance between fromPos and resPos. */ XawTextPosition * resPos, /* Actual second position used. */ int *resHeight) /* Height required. */ { MultiSinkObject sink = (MultiSinkObject) w; Widget source = XawTextGetSource(XtParent(w)); XawTextPosition inx, lastPos; wchar_t c; XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset); XawTextBlock blk; /* we may not need this */ lastPos = GETLASTPOS; XawTextSourceRead(source, fromPos, &blk, (int) (toPos - fromPos)); *resWidth = 0; for (inx = fromPos; inx != toPos && inx < lastPos; inx++) { if (inx - blk.firstPos >= blk.length) XawTextSourceRead(source, inx, &blk, (int) (toPos - fromPos)); c = ((wchar_t *) blk.ptr)[inx - blk.firstPos]; *resWidth += CharWidth(w, fromx + *resWidth, c); if (c == _Xaw_atowc(XawLF)) { inx++; break; } } *resPos = inx; *resHeight = ext->max_logical_extent.height; }
/*ARGSUSED*/ static void AcceptSaveFile(Widget w, XEvent *e, String *argv, Cardinal *argc) { char *filename; Boolean success; Arg args[1]; filename = XawDialogGetValueString (fileDialog); success = XawAsciiSaveAsFile (XawTextGetSource (text), filename); XtPopdown (fileDialogShell); if (!success) { char *failMessage; XtAsprintf (&failMessage, "Can't open file \"%s\"", filename); XtSetArg (args[0], XtNlabel, failMessage); XtSetValues (failDialog, args, 1); CenterWidgetOnEvent (failDialogShell, e); XtPopup (failDialogShell, XtGrabNone); XtFree (failMessage); } else { if (currentClip->filename) free (currentClip->filename); currentClip->filename = malloc (strlen (filename) + 1); if (currentClip->filename) strcpy (currentClip->filename, filename); } }
static void FindPosition( Widget w, XawTextPosition fromPos, /* Starting position. */ int fromx, /* Horizontal location of starting position. */ int width, /* Desired width. */ Boolean stopAtWordBreak, /* Whether the resulting position should be at a word break. */ XawTextPosition * resPos, /* Resulting position. */ int *resWidth, /* Actual width used. */ int *resHeight) /* Height required. */ { MultiSinkObject sink = (MultiSinkObject) w; Widget source = XawTextGetSource(XtParent(w)); XawTextPosition lastPos, inx, whiteSpacePosition = 0; int lastWidth = 0, whiteSpaceWidth = 0; Boolean whiteSpaceSeen; wchar_t c; XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset); XawTextBlock blk; lastPos = GETLASTPOS; XawTextSourceRead(source, fromPos, &blk, BUFSIZ); *resWidth = 0; whiteSpaceSeen = FALSE; c = 0; for (inx = fromPos; *resWidth <= width && inx < lastPos; inx++) { lastWidth = *resWidth; if (inx - blk.firstPos >= blk.length) XawTextSourceRead(source, inx, &blk, BUFSIZ); c = ((wchar_t *) blk.ptr)[inx - blk.firstPos]; *resWidth += CharWidth(w, fromx + *resWidth, c); if ((c == _Xaw_atowc(XawSP) || c == _Xaw_atowc(XawTAB)) && *resWidth <= width) { whiteSpaceSeen = TRUE; whiteSpacePosition = inx; whiteSpaceWidth = *resWidth; } if (c == _Xaw_atowc(XawLF)) { inx++; break; } } if (*resWidth > width && inx > fromPos) { *resWidth = lastWidth; inx--; if (stopAtWordBreak && whiteSpaceSeen) { inx = whiteSpacePosition + 1; *resWidth = whiteSpaceWidth; } } if (inx == lastPos && c != _Xaw_atowc(XawLF)) inx = lastPos + 1; *resPos = inx; *resHeight = ext->max_logical_extent.height; }
/* * Load textfile [sub] */ Boolean LoadFile(Widget w,String fname) { WidgetClass class; Widget w_old,w_new; char buf[BUFSIZ]; String str; FILE *fp; int len; /* * get text file */ if ((fp = fopen(fname,"r")) == NULL) return FALSE; str = XtNewString(""); while(!feof(fp)) { fgets(buf,BUFSIZ,fp); str = XtRealloc(str,strlen(str)+strlen(buf)+1); strcat(str,buf); } fclose(fp); /* * make new text-source */ w_old = XawTextGetSource(w); if (XtIsSubclass(w_old, multiSrcObjectClass)) class = multiSrcObjectClass; else
static long TextLength(Widget w) { return XawTextSourceScan (XawTextGetSource (w), (XawTextPosition) 0, XawstAll, XawsdRight, 1, TRUE); }
/*ARGSUSED*/ void DoQuit(Widget w, XtPointer client_data, XtPointer call_data) { unsigned i; Bool source_changed = False; if (!double_click || (dc_state && dc_state != DC_UNSAVED)) { for (i = 0; i < flist.num_itens; i++) if (flist.itens[i]->flags & CHANGED_BIT) { source_changed = True; break; } } if(!source_changed) { #ifndef __UNIXOS2__ XeditLispCleanUp(); #endif exit(0); } XeditPrintf("Unsaved changes. Save them, or Quit again.\n"); Feep(); double_click = TRUE; dc_state = DC_UNSAVED; AddDoubleClickCallback(XawTextGetSource(textwindow), True); }
/******************************************************************************* GetBufferFromTextEdit Description : This function will return the last word in the editor from the cursor *******************************************************************************/ static char * GetBufferFromTextEdit( Widget w) { XawTextBlock text_return; XawTextPosition length; char *buffer; Widget source = XawTextGetSource(w); XawTextPosition NewPos,EndPos = XawTextGetInsertionPoint(w); /* ================================================ */ /* If Cursor is at the begining return empty */ /* string,orther while move the cursor backward */ /* until it hits the space then read and return */ /* the last word. */ /* ================================================ */ if(EndPos == 0) return(""); NewPos = EndPos - 1; XawTextSourceRead(source,NewPos,&text_return,1); while((text_return.ptr[0] != ' ') && (NewPos != 0)) { NewPos--; XawTextSourceRead(source,NewPos,&text_return,1); } if(NewPos != 0) NewPos++; XawTextSourceRead(source,NewPos,&text_return,EndPos - NewPos); buffer = (char *)malloc(text_return.length + 1); strncpy(buffer,text_return.ptr,text_return.length); buffer[text_return.length] = 0; return(buffer); }
static Bool ExceededMaxLines(Widget w) { XawTextPosition end_of_last_line; Bool retval = False; if (app_resources.saveLines > 0) { /* * XawTextSourceScan() will return the end of the widget if it cannot * find what it is searching for. */ end_of_last_line = XawTextSourceScan (XawTextGetSource (w), (XawTextPosition) 0, XawstEOL, XawsdRight, app_resources.saveLines, TRUE); if (TextLength(w) > end_of_last_line) retval = True; else retval = False; } else retval = False; return retval; }
static void SaveClip(Widget w, ClipPtr clip) { Arg args[1]; char *data; int len; Widget source; source = XawTextGetSource (w); XtSetArg (args[0], XtNstring, &data); XtGetValues (source, args, 1); len = strlen (data); if (len >= clip->avail) { if (clip->clip) free (clip->clip); clip->clip = malloc (len + 1); if (!clip->clip) clip->avail = 0; else clip->avail = len + 1; } if (clip->avail) { strcpy (clip->clip, data); } }
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); }
/******************************************************************************* Name: PrintChangedFocus Description: Update the Focus window Arguments: None Returns: *******************************************************************************/ int PrintChangedFocus() { void *theEnv = GetCurrentEnvironment(); void *FocusPtr; int n; char *buffer; /* Clear the old contents */ n = 0; XtSetArg(TheArgs[n],XtNstring,"");n++; XtSetValues(focus_text,TheArgs,n); XawAsciiSourceFreeString(XawTextGetSource(focus_text)); /* Print the new focus list */ FocusPtr = EnvGetNextFocus(theEnv,NULL); while(FocusPtr != NULL) { buffer = EnvGetDefmoduleName(theEnv,((struct focus*)FocusPtr)->theModule); EnvPrintRouter(theEnv,"xfocus",buffer); EnvPrintRouter(theEnv,"xfocus","\n"); FocusPtr = EnvGetNextFocus(theEnv,FocusPtr); } return 0; }
/* * This is hacked up to try to emulate old functionality, it * may not work, as I have not old code to test it on. * * Chris D. Peterson 8/31/89. */ void XawTextSetLastPos(Widget w, XawTextPosition lastPos) { AsciiSrcObject src = (AsciiSrcObject)XawTextGetSource(w); src->ascii_src.piece_size = lastPos; }
/* used for one line text input widgets */ void Gtweolaction (Widget w, XEvent *evp, char **app, unsigned int *anp) { Gwidget_t *widget; Widget ww; XawTextBlock tb; int ret, fi, li, n, i; widget = findwidget ((unsigned long) w, G_TEXTWIDGET); li = XawTextGetInsertionPoint (w) - 1; ww = XawTextGetSource (w); tb.firstPos = 0, tb.ptr = "\n", tb.format = FMT8BIT, tb.length = 1; fi = XawTextSourceSearch (ww, li, XawsdLeft, &tb); if (fi == XawTextSearchError) fi = 0; else fi++; n = li - fi; Gbufp[(Gbufi = 0)] = '\000'; while (Gbufi != n) { ret = XawTextSourceRead (ww, fi, &tb, n - Gbufi) - fi; for (i = 0; i < ret; i++) Gbufp[Gbufi++] = tb.ptr[i]; } Gbufp[Gbufi] = '\000'; if (n >= 0 && WTU->func) (*WTU->func) (widget - &Gwidgets[0], Gbufp); }
static void UpdatePageNumber (Widget w, XEvent *xev, String *s, Cardinal *c) { char *string; Arg arg[1]; XtSetArg (arg[0], XtNstring, &string); XtGetValues (XawTextGetSource(pageNumber), arg, 1); SetPageNumber (atoi(string)); }
static void RestoreClip(Widget w, ClipPtr clip) { Arg args[1]; Widget source; source = XawTextGetSource (w); XtSetArg (args[0], XtNstring, clip->clip); XtSetValues (source, args, 1); }
static void Resolve(Widget w, XawTextPosition pos, int fromx, int width, XawTextPosition *pos_return) { int resWidth, resHeight; Widget source = XawTextGetSource(XtParent(w)); FindPosition(w, pos, fromx, width, False, pos_return, &resWidth, &resHeight); if (*pos_return > GETLASTPOS) *pos_return = GETLASTPOS; }
/******************************************************************************* Name: PrintChangedAgenda Description: Update the agenda window Arguments: None Returns: *******************************************************************************/ int PrintChangedAgenda() { void *theEnv = GetCurrentEnvironment(); void *rule_ptr; char buffer[MAX_CHAR_IN_BUF]; char *name, labelBuffer[MAX_CHAR_IN_BUF]; Window AgendaWin; Display *theDisplay; struct defmodule* theModule = (struct defmodule *) EnvGetCurrentModule(theEnv); /*======================================================*/ /* Change the name of the window to the current module. */ /*======================================================*/ AgendaWin = XtWindow(agenda); theDisplay = XtDisplay(agenda); if (theModule != NULL) { name = EnvGetDefmoduleName(theEnv,theModule); strcpy(labelBuffer,"Agenda Window("); strcat(labelBuffer,name); strcat(labelBuffer,")"); } else { strcpy(labelBuffer,"Agenda Window"); } XStoreName(theDisplay,AgendaWin,labelBuffer); /*============================*/ /* Wipe out the old contents. */ /*============================*/ XtSetArg(TheArgs[0], XtNstring, ""); XtSetValues(agenda_text, TheArgs, 1); XawAsciiSourceFreeString(XawTextGetSource(agenda_text)); /*============================*/ /* Print the new agenda list. */ /*============================*/ rule_ptr = EnvGetNextActivation(theEnv,NULL); while (rule_ptr != NULL) { EnvGetActivationPPForm(theEnv,buffer,MAX_CHAR_IN_BUF - 1,rule_ptr); EnvPrintRouter(theEnv,"xagenda",buffer); EnvPrintRouter(theEnv,"xagenda", "\n"); rule_ptr = EnvGetNextActivation(theEnv,rule_ptr); } return 0; }
/******************************************************************************* Name: PrintChangedGlobals Description: Update the global window Arguments: None Returns: *******************************************************************************/ int PrintChangedGlobals() { void *theEnv = GetCurrentEnvironment(); void *dgPtr; int n; char *buffer; char *name,labelBuffer[MAX_CHAR_IN_BUF]; Window GlobalWin; Display *theDisplay; struct defmodule* theModule = (struct defmodule *) EnvGetCurrentModule(theEnv); /* Change the name of the window to the current module */ GlobalWin = XtWindow(globals); theDisplay = XtDisplay(globals); if (theModule != NULL) { name = EnvGetDefmoduleName(theEnv,theModule); strcpy(labelBuffer,"Globals Window("); strcat(labelBuffer,name); strcat(labelBuffer,")"); } else { strcpy(labelBuffer,"Globals Window"); } XStoreName(theDisplay,GlobalWin,labelBuffer); /* Clear the old contents */ n = 0; XtSetArg(TheArgs[n],XtNstring,"");n++; XtSetValues(globals_text,TheArgs,n); XawAsciiSourceFreeString(XawTextGetSource(globals_text)); /* Print the new defglobal list */ dgPtr = EnvGetNextDefglobal(theEnv,NULL); while (dgPtr != NULL) { buffer = (char *) EnvGetDefglobalPPForm(theEnv,(struct constructHeader *) dgPtr); EnvPrintRouter(theEnv,"xglobals",buffer); EnvPrintRouter(theEnv,"xglobals","\n"); dgPtr = EnvGetNextDefglobal(theEnv,dgPtr); } return 0; }
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); }
/******************************************************************************* Name: PrintChangedFacts Description: Update the fact window Arguments: None Returns: *******************************************************************************/ int PrintChangedFacts() { void *theEnv = GetCurrentEnvironment(); void *fact_ptr; char buffer[MAX_CHAR_IN_BUF]; char *name,labelBuffer[MAX_CHAR_IN_BUF]; Window FactWin; Display *theDisplay; struct defmodule* theModule = (struct defmodule *) EnvGetCurrentModule(theEnv); /* Change the name of the window to the current module */ FactWin = XtWindow(facts); theDisplay = XtDisplay(facts); if(theModule != NULL) { name = EnvGetDefmoduleName(theEnv,theModule); strcpy(labelBuffer,"Fact Window("); strcat(labelBuffer,name); strcat(labelBuffer,")"); } else { strcpy(labelBuffer,"Fact Window"); } XStoreName(theDisplay,FactWin,labelBuffer); /* Clear the old contents */ XtSetArg(TheArgs[0], XtNstring, ""); XtSetValues(facts_text, TheArgs, 1); XawAsciiSourceFreeString(XawTextGetSource(facts_text)); /* Print the new fact list */ fact_ptr = EnvGetNextFact(theEnv,NULL); while (fact_ptr != NULL) { EnvGetFactPPForm(theEnv,buffer,MAX_CHAR_IN_BUF - 1,fact_ptr); EnvPrintRouter(theEnv,"xfacts",buffer); EnvPrintRouter(theEnv,"xfacts", "\n"); fact_ptr = EnvGetNextFact(theEnv,fact_ptr); } return 0; }
static void Resolve( Widget w, XawTextPosition pos, int fromx, int width, XawTextPosition * leftPos, XawTextPosition * rightPos) { int resWidth, resHeight; Widget source = XawTextGetSource(XtParent(w)); FindPosition(w, pos, fromx, width, FALSE, leftPos, &resWidth, &resHeight); if (*leftPos > GETLASTPOS) *leftPos = GETLASTPOS; *rightPos = *leftPos; }
/******************************************************************************* Name: PrintChangedInstances Description: Update the instances window Arguments: None Returns: *******************************************************************************/ int PrintChangedInstances() { void *theEnv = GetCurrentEnvironment(); int n = 0; void *instancePtr; char buffer[MAX_CHAR_IN_BUF]; char *name, labelBuffer[MAX_CHAR_IN_BUF]; Window InstanceWin; Display *theDisplay; struct defmodule* theModule = (struct defmodule *) EnvGetCurrentModule(theEnv); /* Change the name of the window to the current module */ InstanceWin = XtWindow(instances); theDisplay = XtDisplay(instances); if (theModule != NULL) { name = EnvGetDefmoduleName(theEnv,theModule); strcpy(labelBuffer,"Instances Window("); strcat(labelBuffer,name); strcat(labelBuffer,")"); } else { strcpy(labelBuffer,"Instances Window"); } XStoreName(theDisplay,InstanceWin,labelBuffer); /* Clear the old contents */ XtSetArg(TheArgs[n],XtNstring,"");n++; XtSetValues(instances_text,TheArgs,n); XawAsciiSourceFreeString(XawTextGetSource(instances_text)); /* Print the new instance list */ instancePtr = (void *) EnvGetNextInstance(theEnv,NULL); while (instancePtr != NULL) { EnvGetInstancePPForm(theEnv,buffer,MAX_CHAR_IN_BUF - 1,instancePtr); EnvPrintRouter(theEnv,"xinstances",buffer); EnvPrintRouter(theEnv,"xinstances","\n"); instancePtr = (void *) EnvGetNextInstance(theEnv,instancePtr); } return 0; }
LispObj * Lisp_XawTextGetSource(LispBuiltin *builtin) /* xaw-text-get-source widget */ { LispObj *owidget; owidget = ARGUMENT(0); if (!CHECKO(owidget, xawWidget_t)) LispDestroy("%s: cannot convert %s to Widget", STRFUN(builtin), STROBJ(owidget)); return (OPAQUE(XawTextGetSource((Widget)(owidget->data.opaque.data)), xawWidget_t)); }
/* * XUMFUpdateTextWidget * * Author: Christian Schafmeister (1991) * * Tell the Text Widget that it has new text. */ static void XUMFUpdateTextWidget() { if ( GwTextSource == NULL ) { GwTextSource = XawTextGetSource(GwText); } if ( GcPMessBuffer ) { XtVaSetValues( GwTextSource, XtNstring, (XtArgVal) GcPMessBuffer, NULL ); } else { XtVaSetValues( GwTextSource, XtNstring, (XtArgVal) "---nothing---", NULL ); } }
static void ScrollLine(Widget w) { XawTextPosition firstnewline; XawTextBlock block; /* * This is pretty inefficient but should work well enough unless the * console device is getting totally spammed. Generally, new lines * only come in one at a time anyway. */ firstnewline = XawTextSourceScan (XawTextGetSource (w), (XawTextPosition) 0, XawstEOL, XawsdRight, 1, TRUE); block.ptr = ""; block.firstPos = 0; block.length = 0; block.format = FMT8BIT; TextReplace (w, 0, firstnewline, &block); }
int main(int argc, char *argv[]) { Boolean exists; char *filename; FileAccess file_access; Widget source; XtAppContext appcon; Boolean show_dir; xedit_flist_item *first_item; unsigned int i, lineno; lineno = 0; show_dir = FALSE; first_item = NULL; topwindow = XtAppInitialize(&appcon, "Xedit", NULL, 0, &argc, argv, NULL, NULL, 0); XtAppAddActions(appcon, actions, XtNumber(actions)); XtOverrideTranslations(topwindow, XtParseTranslationTable("<Message>WM_PROTOCOLS: quit()")); XtGetApplicationResources(topwindow, (XtPointer) &app_resources, resources, XtNumber(resources), NULL, 0); CurDpy = XtDisplay(topwindow); XawSimpleMenuAddGlobalActions(appcon); XtRegisterGrabAction(PopupMenu, True, ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync); makeButtonsAndBoxes(topwindow); StartHints(); StartFormatPosition(); (void)StartHooks(appcon); if (position_format_mask == 0) { for (i = 0; i < 3; i++) XtRemoveCallback(texts[i], XtNpositionCallback, PositionChanged, NULL); } XtRealizeWidget(topwindow); #ifndef __UNIXOS2__ XeditLispInitialize(); #endif options_popup = XtCreatePopupShell("optionsMenu", simpleMenuWidgetClass, topwindow, NULL, 0); XtRealizeWidget(options_popup); XtAddCallback(XtCreateManagedWidget("ispell", smeBSBObjectClass, options_popup, NULL, 0), XtNcallback, IspellCallback, NULL); CreateEditPopup(); wm_delete_window = XInternAtom(XtDisplay(topwindow), "WM_DELETE_WINDOW", False); (void)XSetWMProtocols(XtDisplay(topwindow), XtWindow(topwindow), &wm_delete_window, 1); /* This first call is just to save the default font and colors */ UpdateTextProperties(0); if (argc > 1) { xedit_flist_item *item; Arg args[2]; unsigned int num_args; for (i = 1; i < argc; i++) { struct stat st; if (argv[i][0] == '+') { char *endptr; lineno = strtol(argv[i], &endptr, 10); /* Don't warn about incorrect input? */ if (*endptr) lineno = 0; continue; } filename = ResolveName(argv[i]); if (filename == NULL || FindTextSource(NULL, filename) != NULL) continue; num_args = 0; if (stat(filename, &st) == 0 && !S_ISREG(st.st_mode)) { if (S_ISDIR(st.st_mode)) { if (!first_item) { char path[BUFSIZ + 1]; strncpy(path, filename, sizeof(path) - 2); path[sizeof(path) - 2] = '\0'; if (*path) { if (path[strlen(path) - 1] != '/') strcat(path, "/"); } else strcpy(path, "./"); XtSetArg(args[0], XtNlabel, ""); XtSetValues(dirlabel, args, 1); SwitchDirWindow(True); DirWindowCB(dirwindow, path, NULL); show_dir = True; } continue; } } switch (file_access = CheckFilePermissions(filename, &exists)) { case NO_READ: if (exists) XeditPrintf("File %s exists, and could not be opened for " "reading.\n", argv[i]); else XeditPrintf("File %s does not exist, and the directory " "could not be opened for writing.\n", argv[i]); break; case READ_OK: XtSetArg(args[num_args], XtNeditType, XawtextRead); num_args++; XeditPrintf("File %s opened READ ONLY.\n", argv[i]); break; case WRITE_OK: XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++; XeditPrintf("File %s opened read - write.\n", argv[i]); break; } if (file_access != NO_READ) { int flags; if (exists) { flags = EXISTS_BIT; XtSetArg(args[num_args], XtNstring, filename);num_args++; } else { flags = 0; XtSetArg(args[num_args], XtNstring, NULL); num_args++; } source = XtVaCreateWidget("textSource", international ? multiSrcObjectClass : asciiSrcObjectClass, topwindow, XtNtype, XawAsciiFile, XtNeditType, XawtextEdit, NULL, NULL); XtSetValues(source, args, num_args); item = AddTextSource(source, argv[i], filename, flags, file_access); XtAddCallback(item->source, XtNcallback, SourceChanged, (XtPointer)item); if (exists && file_access == WRITE_OK) { item->mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); item->mtime = st.st_mtime; } if (!first_item && !show_dir) first_item = item; ResetSourceChanged(item); } } } if (!flist.pixmap && strlen(app_resources.changed_pixmap_name)) { XrmValue from, to; from.size = strlen(app_resources.changed_pixmap_name); from.addr = app_resources.changed_pixmap_name; to.size = sizeof(Pixmap); to.addr = (XtPointer)&(flist.pixmap); XtConvertAndStore(flist.popup, XtRString, &from, XtRBitmap, &to); } if (first_item == NULL) { XtSetKeyboardFocus(topwindow, filenamewindow); XtVaSetValues(textwindow, XtNwrap, XawtextWrapLine, NULL); } else { SwitchTextSource(first_item); XtSetKeyboardFocus(topwindow, textwindow); if (lineno) { XawTextPosition position; source = XawTextGetSource(textwindow); position = RSCAN(XawTextGetInsertionPoint(textwindow), lineno, False); position = LSCAN(position, 1, False); XawTextSetInsertionPoint(textwindow, position); } } XtAppMainLoop(appcon); return EXIT_SUCCESS; }
/* * This function does not know about drawing more than one line of text. */ static void DisplayText( Widget w, Position x, Position y, XawTextPosition pos1, XawTextPosition pos2, Boolean highlight) { MultiSinkObject sink = (MultiSinkObject) w; Widget source = XawTextGetSource(XtParent(w)); wchar_t buf[BUFSIZ]; XFontSetExtents *ext = XExtentsOfFontSet(sink->multi_sink.fontset); int j, k; XawTextBlock blk; GC gc = highlight ? sink->multi_sink.invgc : sink->multi_sink.normgc; GC invgc = highlight ? sink->multi_sink.normgc : sink->multi_sink.invgc; if (!sink->multi_sink.echo) return; y = (Position) (y + abs(ext->max_logical_extent.y)); for (j = 0; pos1 < pos2;) { pos1 = (int) XawTextSourceRead(source, pos1, &blk, (int) (pos2 - pos1)); for (k = 0; k < blk.length; k++) { if (j >= BUFSIZ) { /* buffer full, dump the text. */ x = (Position) (x + PaintText(w, gc, x, y, buf, j)); j = 0; } buf[j] = ((wchar_t *) blk.ptr)[k]; if (buf[j] == _Xaw_atowc(XawLF)) continue; else if (buf[j] == _Xaw_atowc(XawTAB)) { Position temp = 0; Dimension width; if ((j != 0) && ((temp = (Position) PaintText(w, gc, x, y, buf, j) ) == 0)) return; x = (Position) (x + temp); width = (Dimension) CharWidth(w, x, _Xaw_atowc(XawTAB)); XFillRectangle(XtDisplayOfObject(w), XtWindowOfObject(w), invgc, (int) x, (int) y - abs(ext->max_logical_extent.y), (unsigned int) width, (unsigned int) ext->max_logical_extent.height); x = (Position) (x + width); j = -1; } else if (XwcTextEscapement(sink->multi_sink.fontset, &buf[j], 1) == 0) { if (sink->multi_sink.display_nonprinting) buf[j] = _Xaw_atowc('@'); else buf[j] = _Xaw_atowc(' '); } j++; } } if (j > 0) (void) PaintText(w, gc, x, y, buf, j); }
/******************************************************************************* 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 GTgetwidgetattr (Gwidget_t *widget, int attrn, Gwattr_t *attrp) { Dimension width, height; XawTextEditType mode; XawTextBlock tb; Widget w; int rtn, ai; long fi, li; for (ai = 0; ai < attrn; ai++) { RESETARGS; switch (attrp[ai].id) { case G_ATTRSIZE: ADD2ARGS (XtNwidth, &width); ADD2ARGS (XtNheight, &height); XtGetValues (widget->w, argp, argn); attrp[ai].u.s.x = width, attrp[ai].u.s.y = height; break; case G_ATTRBORDERWIDTH: ADD2ARGS (XtNborderWidth, &width); XtGetValues (widget->w, argp, argn); attrp[ai].u.i = width; break; case G_ATTRTEXT: w = XawTextGetSource (widget->w); tb.firstPos = 0, tb.ptr = NULL, tb.format = FMT8BIT, tb.length = 0; rtn = XawTextSourceRead (w, 0, &tb, 30000); if (rtn > Gbufn + 1) { Gbufp = Marraygrow (Gbufp, (long) (rtn + 1) * BUFSIZE); Gbufn = rtn + 1; } for (Gbufi = 0; Gbufi < rtn; Gbufi++) Gbufp[Gbufi] = tb.ptr[Gbufi]; Gbufp[Gbufi++] = '\000'; attrp[ai].u.t = &Gbufp[0]; break; case G_ATTRAPPENDTEXT: Gerr (POS, G_ERRCANNOTGETATTR, "appendtext"); return -1; case G_ATTRSELECTION: w = XawTextGetSource (widget->w); XawTextGetSelectionPos (widget->w, &fi, &li); tb.firstPos = 0, tb.ptr = NULL, tb.format = FMT8BIT, tb.length = 0; rtn = XawTextSourceRead (w, fi, &tb, li - fi); if (li - fi > Gbufn + 1) { Gbufp = Marraygrow (Gbufp, (long) (rtn + 1) * BUFSIZE); Gbufn = rtn + 1; } for (Gbufi = 0; Gbufi < li - fi; Gbufi++) Gbufp[Gbufi] = tb.ptr[Gbufi]; Gbufp[Gbufi++] = '\000'; attrp[ai].u.t = &Gbufp[0]; break; case G_ATTRMODE: ADD2ARGS (XtNeditType, &mode); XtGetValues (widget->w, argp, argn); if (mode == XawtextAppend) attrp[ai].u.t = "oneline"; else if (mode == XawtextEdit) attrp[ai].u.t = "input"; else if (mode == XawtextRead) attrp[ai].u.t = "output"; else { panic (POS, "GTgetwidgetattr", "unexpected text mode"); return -1; } break; case G_ATTRWINDOWID: sprintf (&Gbufp[0], "0x%lx", XtWindow (widget->w)); attrp[ai].u.t = &Gbufp[0]; break; case G_ATTRNEWLINECB: attrp[ai].u.func = WTU->func; break; case G_ATTRUSERDATA: attrp[ai].u.u = widget->udata; break; default: Gerr (POS, G_ERRBADATTRID, attrp[ai].id); return -1; } } return 0; }
static Boolean ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type, XtPointer *value, unsigned long *length, int *format) { Display* d = XtDisplay(w); XSelectionRequestEvent* req = XtGetSelectionRequest(w, *selection, (XtRequestId)NULL); if (*target == XA_TARGETS(d)) { Atom* targetP; Atom* std_targets; unsigned long std_length; XmuConvertStandardSelection(w, req->time, selection, target, type, (XPointer*)&std_targets, &std_length, format); *value = XtMalloc(sizeof(Atom)*(std_length + 7)); targetP = *(Atom**)value; *targetP++ = XA_STRING; *targetP++ = XA_TEXT(d); *targetP++ = XA_UTF8_STRING(d); *targetP++ = XA_COMPOUND_TEXT(d); *targetP++ = XA_LENGTH(d); *targetP++ = XA_LIST_LENGTH(d); *targetP++ = XA_CHARACTER_POSITION(d); *length = std_length + (targetP - (*(Atom **) value)); memmove( (char*)targetP, (char*)std_targets, sizeof(Atom)*std_length); XtFree((char*)std_targets); *type = XA_ATOM; *format = 32; return True; } if (*target == XA_LIST_LENGTH(d) || *target == XA_LENGTH(d)) { long * temp; temp = (long *) XtMalloc(sizeof(long)); if (*target == XA_LIST_LENGTH(d)) *temp = 1L; else /* *target == XA_LENGTH(d) */ *temp = (long) TextLength (text); *value = (XPointer) temp; *type = XA_INTEGER; *length = 1L; *format = 32; return True; } if (*target == XA_CHARACTER_POSITION(d)) { long * temp; temp = (long *) XtMalloc(2 * sizeof(long)); temp[0] = (long) 0; temp[1] = TextLength (text); *value = (XPointer) temp; *type = XA_SPAN(d); *length = 2L; *format = 32; return True; } if (*target == XA_STRING || *target == XA_TEXT(d) || *target == XA_UTF8_STRING(d) || *target == XA_COMPOUND_TEXT(d)) { Arg args[1]; Widget source; XTextProperty prop; int ret, style = XStdICCTextStyle; /* a safe default for TEXT */ char *data; source = XawTextGetSource (text); XtSetArg (args[0], XtNstring, &data); XtGetValues (source, args, 1); if (*target == XA_UTF8_STRING(d)) style = XUTF8StringStyle; else if (*target == XA_COMPOUND_TEXT(d)) style = XCompoundTextStyle; else if (*target == XA_STRING) style = XStringStyle; ret = XmbTextListToTextProperty (d, &data, 1, style, &prop); if (ret >= Success) { *length = prop.nitems; *value = prop.value; *type = prop.encoding; *format = prop.format; return True; } else return False; } if (XmuConvertStandardSelection(w, req->time, selection, target, type, (XPointer *) value, length, format)) return True; return False; }