static void PrintDocStr(char str[]) { if( (**gDocTE).teLength > 10000) /* clear first half*/ { TESetSelect(0, 5000, gDocTE); TEDelete(gDocTE); } TESetSelect((**gDocTE).teLength, (**gDocTE).teLength, gDocTE); /* move to end*/ TEInsert(str, strlen(str), gDocTE); TESelView(gDocTE); }
/* initialize a premade window as a TextEdit window with options */ void NATEinit(na_win *winp, long flags, short docwidth, Ptr data, long len) { Rect rtemp, vtemp; winp->flags = (winp->flags & ~NATE_FLAGS) | flags; if (!docwidth) docwidth = DOCWIDTH; teinfo->docwidth = docwidth; rtemp = winp->pwin->portRect; rtemp.top += teinfo->topoff; vtemp = rtemp; if (!(flags & NATE_NOHSCROLL)) { vtemp.right = vtemp.left + docwidth; } if (!(flags & NATE_READONLY)) { winp->keyp = NATEkeyp; } if (!(flags & NATE_NOMOUSE)) { winp->mousep = NATEmousep; winp->idlep = NATEidlep; } winp->menup = NATEmenup; winp->activep = NATEactivep; winp->updatep = NATEupdatep; winp->ctrlp = NATEctrlp; winp->closep = NATEclosep; winp->cursorRgn = NewRgn(); teinfo->vctrl = teinfo->hctrl = NULL; TEAutoView(true, teinfo->hTE = TENew(&vtemp, &rtemp)); if (len > 0 && data != (Ptr) NULL) { TESetText(data, len, teinfo->hTE); TESetSelect(0, 0, teinfo->hTE); } teinfo->lheight = (*teinfo->hTE)->lineHeight; }
/* append text at the end of a TextEdit window */ void NATEappend(na_win *winp, char *data, long len) { TEHandle hTE = ((nate_win*) winp)->hTE; TESetSelect(32767, 32767, hTE); TEInsert(data, len, hTE); TESelView(hTE); NATEsetscroll(winp, false, (Rect*) NULL, (Rect*) NULL); }
/****pkintextreplace()******************************************************/ void pkintextreplace(char string[256]) { long newend; if (Lquiet == 0) { newend = (*textText)->selEnd; TESetSelect(mactextselect,newend,textText); TEDelete(textText); TEInsert(string,strlen(string), textText); } }
static void PrintLogStr(char str[]) { int len=strlen(str); if( !mac_LogWindow.show ) return; if( (**gLogTE).teLength > 10000) /* clear first half*/ { TEFeatureFlag(teFAutoScroll, teBitClear, gLogTE); TESetSelect(0, 5000, gLogTE); TEDelete(gLogTE); } TESetSelect((**gLogTE).teLength, (**gLogTE).teLength, gLogTE); /* move to end*/ if( len>=1 && str[len-1]=='\n' ){ str[len-1]=0; len--; //convert dos return code to mac's } TEInsert(str, len, gLogTE); TESelView(gLogTE); TEFeatureFlag(teFAutoScroll, teBitSet, gLogTE); }
static PyObject *TEObj_TESetSelect(TEObject *_self, PyObject *_args) { PyObject *_res = NULL; long selStart; long selEnd; #ifndef TESetSelect PyMac_PRECHECK(TESetSelect); #endif if (!PyArg_ParseTuple(_args, "ll", &selStart, &selEnd)) return NULL; TESetSelect(selStart, selEnd, _self->ob_itself); Py_INCREF(Py_None); _res = Py_None; return _res; }
static int message_LogWin(int message, long /*param*/) { Rect rect; switch(message){ case MW_GROW: rect=win.ref->portRect; //rect.right-=15; rect.bottom-=15; rect = win.ref->portRect; rect.right -= 15; //rect.bottom -= 15; (**gLogTE).viewRect= (**gLogTE).destRect= rect; (**gLogTE).destRect.right = (**gLogTE).destRect.right - 14; TECalText(gLogTE); TESetSelect((**gLogTE).teLength, (**gLogTE).teLength, gLogTE); return 0; } return -1; //not supported }
static int message_DocWin(int message, long param) { switch(message){ case MW_GROW: { Rect rect; rect=win.ref->portRect; //rect.right-=15; rect.bottom-=15; rect = win.ref->portRect; rect.right -= 16; //rect.bottom -= 15; (**gDocTE).viewRect= (**gDocTE).destRect= rect; //(**gDocTE).destRect.right = (**gDocTE).destRect.right - 14; TECalText(gDocTE); TESetSelect((**gDocTE).teLength, (**gDocTE).teLength, gDocTE); return 0; } case MW_DOC_SET: { const char *midiname=(char*)param; char *p, docname[256]; //midiname= (char*)param; strncpy(docname, midiname, sizeof docname - 1); docname[sizeof docname - 1] = '\0'; if((p = strrchr(docname, '.')) == NULL){ return 0; } else if(p - docname >= sizeof docname - 4) { return 0; /* cannot strcpy: that cause buffer overrun */ } if('A' <= p[1] && p[1] <= 'Z') strcpy(p + 1, "DOC"); else strcpy(p + 1, "doc"); TEReadFile( docname, gDocTE ); break; } } return -1; //not supported }
/* an edit menu handler for TextEdit */ short NATEmenup(na_win *winp, WORD menuid, WORD itemno) { MenuHandle mh = NAmenuh(mEdit); TEHandle hTE = teinfo->hTE; TEPtr pte; short status = NA_NOTPROCESSED; switch (menuid) { case 0: pte = *hTE; if (pte->selStart != pte->selEnd) { EnableItem(mh, iCopy); if (!(winp->flags & NATE_READONLY)) { EnableItem(mh, iCut); EnableItem(mh, iClear); } } else { DisableItem(mh, iCopy); if (!(winp->flags & NATE_READONLY)) { DisableItem(mh, iCut); DisableItem(mh, iClear); } } EnableItem(mh, iSelAll); if (!(winp->flags & NATE_READONLY)) { EnableItem(mh, iPaste); } break; case mEdit: switch (itemno) { case iCut: TECut(hTE); goto DOSCRAP; case iCopy: TECopy(hTE); DOSCRAP: ZeroScrap(); TEToScrap(); goto EDITDONE; case iPaste: TEFromScrap(); TEPaste(hTE); goto EDITDONE; case iClear: TEDelete(hTE); goto EDITDONE; case iSelAll: TESetSelect(0, 32767, hTE); TESelView(hTE); EDITDONE: status = NA_PROCESSED; NATEsetscroll(winp, false, (Rect*) NULL, (Rect*) NULL); break; } default: DisableItem(mh, iSelAll); break; } return (status); }