home *** CD-ROM | disk | FTP | other *** search
- /*
- * clipboard.c
- * Routines to handle cut-copy-paste from microemacs, mainly for
- * interaction with desk accessories and such. Compiles into
- * nothing if not a Macintosh.
- */
- #include <stdio.h>
- #include "estruct.h"
- #include "edef.h"
- #if FINDER
- #if LSC
- #include <ScrapMgr.h>
- #include <TextEdit.h>
- #include <IntlPkg.h>
- #endif
-
- #if MPW
- #include <Scrap.h>
- #include <TextEdit.h>
- #include <Memory.h>
- #include <Packages.h>
- /* low-memory globals */
- #define TEScrpLength *((short *)0xAB0)
- #define TEScrpHandle *((Handle *)0xAB4)
-
- #ifdef MPU68000 /* Aztec */
- pascal void Pack6() = 0xA9ED;
- #endif
-
- #ifdef macintosh /* MPW C */
- pascal void Pack6(long time,short form,Ptr buf,short sel)
- extern 0xA9ED;
- #endif
-
- Handle NewHandle();
- #undef IUDateString
- #define IUDateString(a,b,c) Pack6((long)(a),((b)<<8),(c),(short)0)
- #endif
-
- /*
- * Look for 'TEXT' resource in the desk scrap and in the TextEdit
- * scrap. If found, then insert into the current buffer at dot.
- */
- emacs_paste()
- {
- Handle tHndl;
- char *tPtr;
- long tscraplen,toffset;
- long k;
- char ch;
- tHndl = NewHandle(0L);
- tscraplen = GetScrap(tHndl,(ResType)'TEXT',&toffset);
- if(tscraplen < 0){
- if(TEScrpLength > 0){
- ZeroScrap();
- TEToScrap();
- }
- }
- if(tscraplen > 0){
- HLock(tHndl);
- tPtr = (char *)(*tHndl);
- for (k=0;tscraplen-k;k++){
- ch = *tPtr++;
- switch(ch){
- case CR:
- if(lnewline()!=TRUE)
- return(FALSE);
- break;
- default:
- if(linsert(1,ch)!=TRUE)
- return(FALSE);
- break;
- }
- }
- }
- DisposHandle(tHndl);
- update(FALSE);
- }
- long bytes_to_copy;
- REGION region;
- /*
- * Copy the text in the region to the desk scrap and to the TextEdit
- * scrap. Do nothing with the kill buffer.
- */
- emacs_copy()
- {
- #ifdef macintosh
- #define lmalloc malloc
- #endif
- char *lmalloc();
- register LINE *linep;
- register int loffs;
- register int s;
- register char *ch;
- char *source;
-
- if ((s=getregion(®ion)) != TRUE)
- return (s);
- if((source = lmalloc(region.r_size))==NULL) {
- TTbeep();
- mlwrite("Can't get memory to copy to.");
- return (FALSE);
- }
- ch = source;
-
- ZeroScrap();
- linep = region.r_linep; /* Current line. */
- loffs = region.r_offset; /* Current offset. */
- bytes_to_copy = region.r_size;
- while (region.r_size--) {
- if (loffs == llength(linep)) { /* End of line. */
- *ch++ = CR;
- linep = lforw(linep);
- loffs = 0;
- } else { /* Middle of line. */
- *ch++ = lgetc(linep, loffs);
- ++loffs;
- }
- }
- PutScrap(bytes_to_copy,(ResType)'TEXT',source);
- TEFromScrap();
- free(source);
- return (TRUE);
- }
- /*
- * emacs_cut(). Copy, then delete. Note that this operation, like
- * emacs_copy(), does not use the kill buffer. The cut text can be
- * found in the clipboard, rather than by yanking it.
- * cut, then paste
- * kill, then yank
- * separate classes of operation.
- *
- * You can, of course, switch between the two by yanking something,
- * then cutting it, and so forth.
- */
- emacs_cut()
- {
- if (emacs_copy()==TRUE) {
- curwp->w_dotp = region.r_linep;
- curwp->w_doto = region.r_offset;
- ldelete(bytes_to_copy, FALSE);
- }
- update(FALSE);
- }
- ins_date(f,n)
- {
- {
- long curdate;
- char strbuf[256];
- int i;
- GetDateTime(&curdate);
- IUDateString(curdate,n,strbuf);
- for(i=0;i++ < strbuf[0];){
- linsert(1,strbuf[i]);
- }
- }
- return(TRUE);
- }
-
-
- #endif
-
-