home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************\
- **
- ** samplextlite.c
- **
- ** Sample XTLite bulb.
- **
- **
- ** Copyright © 1993,1994 Quark Incorporated
- ** All Rights Reserved
- **
- \**************************************************************************/
-
- #include "XTLite.h"
-
- #define DOIMPORTFILTER 1
- #define DOEXPORTFILTER 1
- #define DOMENUITEM 1
- #define DOIDLELOOP 1
-
- /* function prototypes */
- uchar readchar(int16);
-
- #define STRINGRESID 20000
- #define IMPORTSTRID 1
- #define EXPORTSTRID 2
- #define SUFFIXSTRID 3
- #define MENUSTRID 4
-
- #if DOIMPORTFILTER || DOEXPORTFILTER
- #define OURTEXTCREATOR 'ABCX' /* creator of our text file */
- #define OURTEXTTYPE 'MYTX' /* ResType of our text file */
- #define BOLDCHAR '\\'
- #define BUFSIZE 1000L /* size of temp buffer for reading in text file */
-
- bool8 boldflag; /* flag telling if we're currently handling bold text */
- uchar boldchar = BOLDCHAR;
- int32 remaining; /* num of chars remaining in file buffer */
- int32 doffset; /* offset of char in buffer */
- uchar *filebuffer; /* holds characters */
- filtertxtattrib *mytextattr; /* text attributes */
- filterparaattrib *myparaattr; /* paragraph attributes */
- RGBColor thetextcolor; /* RGB value for text coloring */
- static int16 maxtabs;
-
- /**************************************************************************\
- **
- ** setupfilter
- **
- ** Setup the filter information.
- **
- ** Entry: variables to recieve information.
- **
- ** Exit: variables filled.
- **
- \**************************************************************************/
- void setupfilter(OSType *fcreator,OSType *ftype,bool8 *importok,bool8 *exportok,
- Str255 getstr,Str255 savestr,Str255 suffixstr)
- {
- *fcreator = OURTEXTCREATOR; /* set up file creator information */
- *ftype = OURTEXTTYPE; /* set up file type information */
- *importok = *exportok = TRUE; /* we can import and export this format */
- GetIndString(getstr,STRINGRESID,IMPORTSTRID); /* get "Get Text" String */
- GetIndString(savestr,STRINGRESID,EXPORTSTRID); /* get "Save Text" String */
- GetIndString(suffixstr,STRINGRESID,SUFFIXSTRID); /* get ".suffix" String (Optional) */
-
- maxtabs = maxnumoftabs(); /* get maximum number of tabs */
- }
- #else /* DOIMPORTFILTER || DOEXPORTFILTER */
- void setupfilter(OSType *fcreator,OSType *ftype,bool8 *importok,bool8 *exportok,
- Str255 getstr,Str255 savestr,Str255 suffixstr)
- {
- *importok = *exportok = FALSE;
- }
- #endif /* DOIMPORTFILTER || DOEXPORTFILTER */
-
-
-
- #if DOIMPORTFILTER
- /**************************************************************************\
- **
- ** readchar
- **
- ** Read a character from the file buffer.
- **
- ** Entry: fnum - the file reference number.
- **
- ** Exit: character.
- **
- \**************************************************************************/
- uchar readchar(int16 fnum)
- {
- int16 err;
-
- if (remaining == 0) { /* if buffer is empty then read a buffer full */
- remaining = BUFSIZE;
- err = FSRead(fnum,&remaining,filebuffer);
- if (err && !remaining) {
- if (err != eofErr) return (err);
- return (0xFF);
- }
- doffset = 0;
- }
- remaining--;
- return(filebuffer[doffset++]);
- }
-
- /**************************************************************************\
- **
- ** startread
- **
- ** Initialize variables for start of text import.
- **
- ** Entry: fnum - the file reference number.
- **
- ** Exit: None.
- **
- \**************************************************************************/
- void startread(int16 fnum)
- {
- int16 i;
-
- mytextattr = (filtertxtattribptr)NewPtr(sizeof(filtertxtattrib));
- myparaattr = (filterparaattribptr)NewPtr(sizeof(filterparaattrib)+maxtabs*sizeof(filtertabspec));
-
- mytextattr->font = helvetica; /* set text to 12 point helvetica */
- mytextattr->size = 12L<<16; /* point size is in fixed notation, so we << 16 */
- mytextattr->kern = 0L; /* auto kerning */
- mytextattr->shade = 0x00010000; /* 100% shade color */
- mytextattr->hscale = 0x00010000; /* 100% horizontal scaled text */
- mytextattr->track = 0L;
-
- myparaattr->relative = FALSE; /* not relative leading */
- myparaattr->just = LEFT; /* left justified text */
- myparaattr->leftindent = 0L; /* no left indent */
- myparaattr->firstindent = 0L; /* no first line of paragraph indent */
- myparaattr->rightindent = 0L; /* no right indent */
- myparaattr->leading = 0L; /* 0 means auto leading */
- myparaattr->spcbefore = 0L; /* no space before or after paragraphs */
- myparaattr->spcafter = 0L;
-
- for (i = 0; i < maxtabs; i++) /* tabs every .5 inches (all -1L means default) */
- myparaattr->tabs[i].tabindent = -1L;
-
- thetextcolor.red = 0; /* text color is black */
- thetextcolor.green = 0;
- thetextcolor.blue = 0;
-
- filebuffer = (uchar *)NewPtr(BUFSIZE);
- remaining = doffset = 0;
- boldflag = FALSE;
- }
-
- /**************************************************************************\
- **
- ** readtext
- **
- ** Read a section of text for text import.
- **
- ** Entry: variables to recieve information.
- **
- ** Exit: variables filled.
- **
- \**************************************************************************/
- void readtext(int16 fnum,Str255 textbuffer,int32 *count,filtertxtattrib *textattribs,
- filterparaattrib *paraattribs,RGBColor *textcolor)
- {
- char ch;
- int16 i;
-
- i = 0;
- mytextattr->face = boldflag ? bold : 0;
- while (TRUE) {
- ch = readchar(fnum);
- if (ch == BOLDCHAR) {
- /* handle change of text attributes */
- boldflag = !boldflag;
- /* break at the end of a run of characters */
- if (i) break;
- mytextattr->face = boldflag ? bold : 0;
- }
- if (ch >= ' ' || ch == '\t' || ch == '\r')
- textbuffer[i++] = ch;
- if (ch == '\r' || i == 256) break;
- else if (ch == -1) break;
- }
- /* set the text attributes before returning */
- textattribs->font = mytextattr->font;
- textattribs->face = mytextattr->face;
- textattribs->size = mytextattr->size;
- textattribs->hscale = mytextattr->hscale;
- textattribs->shade = mytextattr->shade;
- textattribs->kern = mytextattr->kern;
- textattribs->track = mytextattr->track;
-
- paraattribs->relative = myparaattr->relative;
- paraattribs->just = myparaattr->just;
- paraattribs->leftindent = myparaattr->leftindent;
- paraattribs->firstindent = myparaattr->firstindent;
- paraattribs->rightindent = myparaattr->rightindent;
- paraattribs->leading = myparaattr->leading;
- paraattribs->spcbefore = myparaattr->spcbefore;
- paraattribs->spcafter = myparaattr->spcafter;
- BlockMove(paraattribs->tabs,myparaattr->tabs,maxtabs*sizeof(filtertabspec));
-
- textcolor->red = thetextcolor.red;
- textcolor->green = thetextcolor.green;
- textcolor->blue = thetextcolor.blue;
-
- *count = i; /* tell QuarkXPress how many characters are in the text buffer */
- }
-
- /**************************************************************************\
- **
- ** endread
- **
- ** De-initialize variables for end of text import.
- **
- ** Entry: fnum - the file reference number.
- **
- ** Exit: None.
- **
- \**************************************************************************/
- void endread(int16 fnum)
- {
- if (filebuffer) DisposPtr((Ptr)filebuffer);
- DisposePtr((Ptr)mytextattr);
- DisposePtr((Ptr)myparaattr);
- }
- #else /* DOIMPORTFILTER */
- uchar readchar(int16 fnum) {}
- void startread(int16 fnum) {}
- void readtext(int16 fnum,Str255 textbuffer,int32 *count,filtertxtattrib *textattribs,
- filterparaattrib *paraattribs,RGBColor *textcolor) {}
- void endread(int16 fnum) {}
- #endif /* DOIMPORTFILTER */
-
-
-
- #if DOEXPORTFILTER
- /**************************************************************************\
- **
- ** startwrite
- **
- ** Initialize variables for start of text export.
- **
- ** Entry: fnum - the file reference number.
- **
- ** Exit: None.
- **
- \**************************************************************************/
- void startwrite(int16 fnum)
- {
- boldflag = FALSE;
- }
-
- /**************************************************************************\
- **
- ** writetext
- **
- ** Write a section of text for text export.
- **
- ** Entry: variables to recieve information.
- **
- ** Exit: variables filled.
- **
- \**************************************************************************/
- void writetext(int16 fnum,Str255 textbuffer,int32 count,filtertxtattrib *textattribs,
- filterparaattrib *paraattribs,RGBColor *textcolor)
- {
- char ch;
- int16 i,j;
- int32 size;
- int16 fserr;
- Str255 tempbuffer;
-
- if (boldflag != ((textattribs->face&bold) != 0)) {
- boldflag = !boldflag;
- size = 1;
- fserr = FSWrite(fnum,&size,&boldchar);
- }
- for (j = i = 0; i < count; i++) {
- ch = textbuffer[i];
- if (ch >= ' ' || ch == TABCHAR || ISSPECIAL(ch)) tempbuffer[j++] = ch;
- else if (ISLINECHAR(ch)) tempbuffer[j++] = RETURNCHAR;
- }
- size = j;
- fserr = FSWrite(fnum,&size,tempbuffer);
- }
-
- /**************************************************************************\
- **
- ** endwrite
- **
- ** De-initialize variables for end of text export.
- **
- ** Entry: fnum - the file reference number.
- **
- ** Exit: None.
- **
- \**************************************************************************/
- void endwrite(int16 fnum)
- {
- int32 size;
- int16 fserr;
-
- if (boldflag) {
- size = 1;
- fserr = FSWrite(fnum,&size,&boldchar);
- }
- }
- #else /* DOEXPORTFILTER */
- void startwrite(int16 fnum) {}
- void writetext(int16 fnum,Str255 textbuffer,int32 count,filtertxtattrib *textattribs,
- filterparaattrib *paraattribs,RGBColor *textcolor) {}
- void endwrite(int16 fnum) {}
- #endif /* DOEXPORTFILTER */
-
-
-
- #if DOMENUITEM
- /**************************************************************************\
- **
- ** setupmenu
- **
- ** Setup for adding a menu item to the Utilities menu.
- **
- ** Entry: Storage for the text of the menu item.
- **
- ** Exit: TRUE if you want to add your own menu item; FALSE if not.
- **
- \**************************************************************************/
- bool8 setupmenu(Str255 menustr)
- {
- GetIndString(menustr,STRINGRESID,MENUSTRID); /* get "Menu" String */
- return (TRUE);
- }
-
- void menucall(void)
- {
- /* Put you own code here! */
- SysBeep(1);
- }
- #else /* DOMENUITEM */
- bool8 setupmenu(Str255 menustr)
- {
- return (FALSE);
- }
- void menucall(void) {}
- #endif /* DOMENUITEM */
-
-
-
- #if DOIDLELOOP
- /**************************************************************************\
- **
- ** setupidle
- **
- ** Setup for handling Idle calls.
- **
- ** Entry: None.
- **
- ** Exit: TRUE if you want to handle Idle calls; FALSE if not.
- **
- \**************************************************************************/
- bool8 setupidle(void)
- {
- return (TRUE);
- }
-
- void idlecall(EventRecord *myevent)
- {
- register int32 c;
- int32 start,end,amount,textlen;
- Fixed kern;
- int16 character;
- uchar ch;
- bool8 plus;
-
- #define PLUSTRACKCHAR (30<<8) /* the + track value character "}" */
- #define MINUSTRACKCHAR (33<<8) /* the - track value character "{" */
-
- /* Put you own code here! */
- character = (*myevent).message&keyCodeMask;
- if (((*myevent).what == keyDown || (*myevent).what == autoKey)
- && ((*myevent).modifiers&(controlKey+shiftKey+cmdKey)) == controlKey+shiftKey+cmdKey
- && (character == PLUSTRACKCHAR || character == MINUSTRACKCHAR)) {
- if (istextboxcurrent()) {
- gettextinfo(&start,&end,&textlen);
- if (start != end) {
- plus = character == PLUSTRACKCHAR;
- amount = ((*myevent).modifiers&optionKey) ? 1L<<16: 10L<<16;
- turnofftextselection();
- for (c = start; c < end; c++) {
- gettext(c,1L,&ch);
- if (ch == ' ' && c != textlen) {
- gettextattribute(T_KERN,&kern,c,c+1);
- if (plus) {
- kern += amount;
- if (!settextattribute(T_KERN,kern,c,c+1,FALSE)) {
- SysBeep(1);
- break;
- }
- }
- else {
- kern -= amount;
- if (!settextattribute(T_KERN,kern,c,c+1,FALSE)) {
- SysBeep(1);
- break;
- }
- }
- }
- }
- settextselection(start,end);
- }
- else SysBeep(1);
- (*myevent).what = nullEvent;
- }
- }
- }
- #else /* DOIDLELOOP */
- bool8 setupidle(void)
- {
- return (FALSE);
- }
- void idlecall(EventRecord *myevent) {}
- #endif /* DOIDLELOOP */
-