home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
historic
/
v92.tgz
/
v92.tar
/
v92
/
src
/
runtime
/
rmac.ri
< prev
next >
Wrap
Text File
|
1996-03-22
|
19KB
|
1,048 lines
/*
* File: rmac.ri - Mac system-specific graphics interface code.
*/
#ifdef Graphics
#passthru #ifndef __QUICKDRAW__
struct RGBColor {
unsigned short red; /*magnitude of red component*/
unsigned short green; /*magnitude of green component*/
unsigned short blue; /*magnitude of blue component*/
};
typedef struct RGBColor RGBColor, *RGBColorPtr, **RGBColorHdl;
#passthru #endif
#passthru #include <sound.h>
/*
* Global variables specific to Mac
*/
extern PaletteHandle gPal;
extern long gNumColors;
/*
* Prototypes
*/
int CreateWindow Params((wbp wb));
int seticonicstate Params((wbp w, char *s));
novalue unsetclip Params((wbp w));
int seticonpos Params((wbp w, char *s));
int setdisplay Params((wbp w, char *s));
/*
* allocates a window binding, a context and a state, then calls
* CreateWindow to draw the window on screen
*/
FILE *wopen(name, lp, attr, n, err_index)
char *name;
struct b_list *lp;
dptr attr;
int n, *err_index;
{
wbp wb;
wsp ws;
wcp wc;
char dispchrs[256];
char answer[128];
char *display = NULL;
int i;
tended struct b_list *tlp;
tended struct descrip attrrslt;
tlp = lp;
for(i=0;i<n;i++)
{
if (is:string(attr[i]) &&
(StrLen(attr[i])>8) &&
!strncmp("display=",StrLoc(attr[i]),8))
{
mystrncpy(dispchrs,StrLoc(attr[i])+8,StrLen(attr[i])-8);
display = dispchrs;
}
}
/*
* Allocate a binding, a state and a context
*/
Protect(wb = alc_wbinding(), return NULL);
Protect(wb->window = alc_winstate(), { free_binding(wb); return NULL; });
Protect(wb->context = alc_context(wb), { free_binding(wb); return NULL; });
ws = wb->window;
ws->listp.dword = D_List;
BlkLoc(ws->listp) = (union block *)tlp;
wc = wb->context;
/*
* Defaults
*/
ws->height = 100;
ws->width = 100;
ws->posy = 60;
ws->posx = 20;
ws->visible = kVisible;
/*
* some window attributes
*/
/*
* Loop through any remaining arguments.
*/
for (i = 0; i < n; i++)
{
/*
* write the attribute,
* except "display=" attribute, which is done earlier
*/
if((StrLen(attr[i])<9)||strncmp(StrLoc(attr[i]),"display=",8))
{
switch (wattrib((wbp) wb, StrLoc(attr[i]), StrLen(attr[i]), &attrrslt, answer))
{
case Error:
*err_index = i;
return NULL;
case Failed:
free_binding((wbp)wb);
return NULL;
}
}
}
/* set window color according to context */
if (CreateWindow(wb) != 1) return NULL;
return (FILE *)wb;
}
/*
* Creates a window and shows it on screen
*/
int CreateWindow(wbp wb)
{
Rect winRect;
QDErr errGWorld;
STDLOCALS (wb);
/*
* create the window
*/
SetRect (&winRect,
ws->posx, ws->posy,
(ws->posx)+(ws->width),
(ws->posy)+(ws->height));
ws->theWindow = NewCWindow (nil,
&winRect,
"\pUntitled",
ws->visible,
documentProc,
kMoveToFront,
kHasGoAway,
kNilRefCon);
/*
* creating offscreen graphics world
*/
SetRect (&(ws->GWorldRect), 0, 0, kMaxDocSize, kMaxDocSize);
GetGWorld (&(ws->origPort), &(ws->origDev));
errGWorld = NewGWorld (&(ws->offScreenGWorld), 0, &(ws->GWorldRect), nil, nil, 0);
if (errGWorld != noErr)
printf ("Cannot create offscreen graphics world!\n");
SetGWorld (ws->offScreenGWorld, nil);
ws->offScreenPMHandle = GetGWorldPixMap (ws->offScreenGWorld);
ws->lockOK = LockPixels (ws->offScreenPMHandle);
EraseRect (&(ws->offScreenGWorld->portRect));
UnlockPixels (ws->offScreenPMHandle);
SetGWorld (ws->origPort, ws->origDev);
return 1;
}
/*
* Draw a bilevel image
*/
int blimage(w, x, y, width, height, ch, s, len)
wbp w;
int x, y, width, height, ch;
unsigned char *s;
word len;
{
}
/*
* copy an area
*/
int copyArea(wb1,wb2,x,y,width,height,x2,y2)
wbp wb1, wb2;
int x, y, width, height, x2, y2;
{
Rect sourceRect, destRect;
SetRect (&sourceRect, x, y, x+width, y+height);
SetRect (&destRect, x2, y2, x2+width, y2+width);
CopyBits (&(((GrafPtr)(wb1->window->theWindow))->portBits),
&(((GrafPtr)(wb2->window->theWindow))->portBits),
&sourceRect, &destRect, srcCopy, nil);
LockPixels (wb1->window->offScreenGWorld->portPixMap);
LockPixels (wb2->window->offScreenGWorld->portPixMap);
CopyBits (&(((GrafPtr)(wb1->window->offScreenGWorld))->portBits),
&(((GrafPtr)(wb2->window->offScreenGWorld))->portBits),
&sourceRect, &destRect, srcCopy, nil);
UnlockPixels (wb1->window->offScreenGWorld->portPixMap);
UnlockPixels (wb2->window->offScreenGWorld->portPixMap);
}
/*
* clear an area
*/
void clearArea(w,x,y,width,height)
wbp w;
int x, y, width, height;
{
}
/*
* erase an area
*/
void eraseArea(wb, x, y, width, height)
wbp wb;
int x, y, width, height;
{
Rect r;
STDLOCALS (wb);
SetPort (ws->theWindow);
COPYCONTEXT (wc->contextPtr);
SetRect (&r, x - 1,
y - 1,
(width == 0) ? (ws->posx + ws->width) : (x - 1 + width),
(height == 0) ? (ws->posy + ws->height) : (y - 1 + height) );
EraseRect (&r);
/* */
PREPAREGWORLD (ws);
COPYCONTEXT (wc->contextPtr);
EraseRect (&r);
UnlockPixels (ws->offScreenPMHandle);
SetGWorld (ws->origPort, ws->origDev);
/* */
}
/*
* dumpimage -- write an image to a disk file in an X format.
*
* Accepts only .xpm and .xbm file names, returning NoCvt for anything else.
*/
int dumpimage(w,filename,x,y,width,height)
wbp w;
char *filename;
unsigned int x, y, height, width;
{
}
int do_config(w, status)
wbp w;
int status;
{
}
novalue free_rgb(w, rgb)
wbp w;
RGBColor *rgb;
{
}
novalue freecolor(w, s)
wbp w;
char s;
{
}
novalue geticonic(w, answer)
wbp w;
char *answer;
{
}
novalue getpointername(w, answer)
wbp w;
char *answer;
{
}
novalue getlinestyle(w, answer)
wbp w;
char *answer;
{
}
novalue getfg(w, answer)
wbp w;
char *answer;
{
}
novalue getbg(w, answer)
wbp w;
char *answer;
{
}
/*
* Set the context's foreground color by color cell.
*/
int isetfg(wb,i)
wbp wb;
int i;
{
RGBColor c;
STDLOCALS (wb);
if (-i > gNumColors) return Failed;
GetEntryColor (gPal, -i-1, &c);
wc->contextPtr->fgColor = c;
SetPort (ws->theWindow);
PmForeColor (-i - 1);
/* */
GetGWorld (&(ws->origPort), &(ws->origDev));
SetGWorld (ws->offScreenGWorld, nil);
ws->lockOK = LockPixels (ws->offScreenPMHandle);
PmForeColor (-i - 1);
UnlockPixels (ws->offScreenPMHandle);
SetGWorld (ws->origPort, ws->origDev);
return Succeeded;
/* */
}
/*
* Set the context's background color by color cell.
*/
int isetbg(wb,i)
wbp wb;
int i;
{
RGBColor c;
STDLOCALS (wb);
if (-i > gNumColors) return Failed;
GetEntryColor (gPal, -i-1, &c);
wc->contextPtr->bgColor = c;
SetPort (ws->theWindow);
PmBackColor (-i - 1);
}
int setfg(wb,s)
wbp wb;
char *s;
{
long r, g, b;
RGBColor c;
STDLOCALS (wb);
if (parsecolor (NULL, s, &r, &g, &b) == Succeeded) {
RED (c) = r;
GREEN (c) = g;
BLUE (c) = b;
wc->contextPtr->fgColor = c;
SetPort (ws->theWindow);
RGBForeColor (&c);
GetGWorld (&(ws->origPort), &(ws->origDev));
SetGWorld (ws->offScreenGWorld, nil);
ws->lockOK = LockPixels (ws->offScreenPMHandle);
RGBForeColor (&c);
UnlockPixels (ws->offScreenPMHandle);
SetGWorld (ws->origPort, ws->origDev);
}
else
return Failed;
return Succeeded;
}
int setbg(wb,s)
wbp wb;
char *s;
{
long r, g, b;
RGBColor c;
STDLOCALS (wb);
if (parsecolor (NULL, s, &r, &g, &b) == Succeeded) {
RED (c) = r;
GREEN (c) = g;
BLUE (c) = b;
wc->contextPtr->bgColor = c;
SetPort (ws->theWindow);
RGBBackColor (&c);
}
else
return Failed;
return Succeeded;
}
int nativecolor(w, s, r, g, b)
wbp w;
char *s;
long *r;
long *g;
long *b;
{
return 0;
}
int getvisual(w, answer)
wbp w;
char *answer;
{
}
/*
* Initialize client for producing pixels from a window
*/
int getpixel_init(wb, x, y, width, height)
wbp wb;
int x, y, width, height;
{
}
/*
* Return pixel (x,y) from a window in long value (rv)
*/
int getpixel(wb, x, y, rv, s)
wbp wb;
int x, y;
long *rv;
char *s;
{
RGBColor c;
STDLOCALS (wb);
SetPort (ws->theWindow);
GetCPixel (x, y, &c);
*rv = ((c.red << 8) + c.green) << 8 + c.blue;
sprintf (s, "%d,%d,%d", c.red, c.green, c.blue);
return Succeeded;
}
novalue getdrawop(w, answer)
wbp w;
char *answer;
{
}
/*
* getimstr(w, x, y, width, height, paltbl, data) -- get image as a string.
*
* Stores the specified subimage in data, one pixel per byte, and sets
* entries in paltbl corresponding to the pixel values that were used.
*/
/*
* The getimstr() code assumes that a maximum of 256 colors can be onscreen
* at one time. If DMAXCOLORS maximum is raised, code must be added for the
* depth>8 case to reduce the local copy of the image to no more than the
* 256-color maximum allowed in a GIF file. This reduction operation is
* nontrivial; look up "color quantization" in computer graphics literature.
*/
#passthru #if (DMAXCOLORS > 256)
#passthru Deliberate Syntax error
#passthru #endif /* DMAXCOLORS */
int getimstr(w, x, y, width, height, paltbl, data)
wbp w;
int x, y, width, height;
struct palentry paltbl[DMAXCOLORS];
unsigned char *data;
{
}
int geticonpos(w, s)
wbp w;
char *s;
{
}
novalue getcanvas(wb, s)
wbp wb;
char *s;
{
STDLOCALS (wb);
if (ws->theWindow == (WindowPtr) (NULL))
sprintf (s, "absent");
else
switch (ws->visible) {
case kVisible:
sprintf (s, "normal");
break;
case kInvisible:
sprintf (s, "hidden");
break;
default:
sprintf (s, "unknown");
}
}
/*
* Set the canvas type, either during open (pixmap is null, set a flag)
* or change an existing canvas to a different type.
*/
int setcanvas(wb,s)
wbp wb;
char *s;
{
STDLOCALS(wb);
if (!strcmp(s, "iconic")) {
return Failed; /* not supported */
}
else if (!strcmp(s, "normal")) {
ws->visible = kVisible;
if (ws->theWindow != (WindowPtr) (NULL)) {
ShowHide (ws->theWindow, kVisible);
SelectWindow (ws->theWindow);
}
}
else if (!strcmp(s, "maximal")) {
return Failed; /* not supported */
}
else if (!strcmp(s, "hidden")) {
ws->visible = kInvisible;
if (ws->theWindow != (WindowPtr) (NULL)) {
ShowHide (ws->theWindow, kInvisible);
}
}
else return Error;
return Succeeded;
}
/*
* getpos() - update the window state's notion of its current position
*/
int getpos(w)
wbp w;
{
if (!w->window->theWindow) return Failed;
return Succeeded;
}
int getdefault(w, prog, opt, answer)
wbp w;
char *prog, *opt, *answer;
{
}
novalue getdisplay(wbp w, char *answer)
{
strcpy(answer, "local");
}
int setdisplay(wbp w, char *s)
{
return Failed;
}
int raiseWindow(w)
wbp w;
{
}
int lowerWindow(w)
wbp w;
{
}
/*
* rebind() - bind w's context to that of w2.
*/
int rebind(w, w2)
wbp w, w2;
{
}
int readimage(w, filename, x, y, status)
wbp w;
char *filename;
int x, y, *status;
{
}
int setimage(w, val)
wbp w;
char *val;
{
}
/*
* Set the context's line style by name.
*/
int setlinestyle(w, s)
wbp w;
char *s;
{
}
/*
* Set the context's fill style by name.
*/
int setfillstyle(w, s)
wbp w;
char *s;
{
}
int seticonimage(w, dp)
wbp w;
dptr dp;
{
}
int seticonicstate(w,s)
wbp w;
char *s;
{
}
/*
* Draw a character-per-pixel image
*/
int strimage(w, x, y, width, height, e, s, len)
wbp w;
int x, y, width, height;
struct palentry *e;
unsigned char *s;
word len;
{
}
char *get_mutable_name(wb, mute_index)
wbp wb;
int mute_index;
{
RGBColor c;
char *tmp = malloc (28);
STDLOCALS (wb);
if (-mute_index > gNumColors) return NULL;
GetEntryColor (gPal, -mute_index - 1, &c);
sprintf(tmp, "%d", mute_index);
sprintf(tmp + strlen (tmp) + 1, "%d,%d,%d", c.red, c.green, c.blue);
return tmp;
}
int set_mutable(wb, i, s)
wbp wb;
int i;
char *s;
{
long r, g, b;
RGBColor c;
STDLOCALS (wb);
if (parsecolor (NULL, s, &r, &g, &b) != Succeeded )
return Failed;
c.red = r;
c.green = g;
c.blue =b;
AnimateEntry (ws->theWindow, -i - 1, &c);
ActivatePalette (ws->theWindow);
/*
ws->lockOK = LockPixels (ws->offScreenPMHandle);
AnimateEntry ((WindowPtr)(ws->offScreenGWorld), -i-1, &c);
ActivatePalette ((WindowPtr)(ws->offScreenGWorld));
UnlockPixels (ws->offScreenPMHandle);
*/
return Succeeded;
}
novalue free_mutable(w, mute_index)
wbp w;
int mute_index;
{
}
/*
* Allocate a mutable color
*/
int mutable_color(wb, argv, argc, retval)
wbp wb;
dptr argv;
int argc;
int *retval;
{
long r, g, b;
tended char *str;
RGBColor c;
{
STDLOCALS(wb);
gNumColors++;
if (gNumColors == 1) {
gPal = NewPalette (gNumColors, nil, pmAnimated, kZeroTolerance);
}
else{
ResizePalette (gPal, gNumColors);
SetEntryUsage (gPal, gNumColors-1, pmAnimated, kZeroTolerance);
}
SetPalette (ws->theWindow, gPal, true);
/* */
ws->lockOK = LockPixels (ws->offScreenPMHandle);
SetPalette((WindowPtr)(ws->offScreenGWorld), gPal, true);
UnlockPixels (ws->offScreenPMHandle);
/* */
/* set the color */
if (argc > 0) {
if (argc != 1)
return Error;
else
if (argv[0].dword == D_Integer) {
if (IntVal (argv[0]) >= 0) return Failed; /* must be negative */
}
else {
if (!cnv:C_string(argv[0], str)) {
ReturnErrVal (103, argv[0], Error);
}
if (parsecolor (NULL, str, &r, &g, &b) != Succeeded) {
gNumColors--;
return Failed;
}
c.red = r;
c.green = g;
c.blue = b;
}
SetEntryColor (gPal, gNumColors-1, &c);
ActivatePalette (ws->theWindow);
/*
ws->lockOK = LockPixels (ws->offScreenPMHandle);
ActivatePalette ((WindowPtr)(ws->offScreenGWorld));
UnlockPixels (ws->offScreenPMHandle);
*/
}
*retval = -gNumColors;
return Succeeded;
}
}
int setleading(wb, i)
wbp wb;
int i;
{
STDLOCALS(wb);
if (i<0) return Failed;
wc->font->fInfo.leading = i;
return Succeeded;
}
/*
* Set the context's line width
*/
int setlinewidth(wb, linewid)
wbp wb;
LONG linewid;
{
STDLOCALS(wb);
if (linewid < 0) return Failed;
wc->contextPtr->pnSize.h = linewid;
wc->contextPtr->pnSize.v = linewid;
return Succeeded;
}
int setwidth(wb, new_width)
wbp wb;
SHORT new_width;
{
STDLOCALS(wb);
if (new_width < 0) return Failed;
ws->width = new_width;
return Succeeded;
}
int setheight(wb, new_height)
wbp wb;
short new_height;
{
STDLOCALS(wb);
if (new_height < 0) return Failed;
ws->height = new_height;
return Succeeded;
}
int query_pointer(wb, pp)
wbp wb;
XPoint *pp;
{
Point mousePt;
STDLOCALS (wb);
SetPort (ws->theWindow);
GetMouse (&mousePt);
pp->x = mousePt.h;
pp->y = mousePt.v;
return Succeeded;
}
int query_rootpointer(pp)
XPoint *pp;
{
}
void toggle_fgbg(w)
wbp w;
{
}
int setwindowlabel(wb, s)
wbp wb;
char *s;
{
wsp ws = wb->window;
if (ws->windowlabel != NULL) free(ws->windowlabel);
ws->windowlabel = salloc(s);
SetWTitle (ws->theWindow, "\pUntitled");
return Succeeded;
}
int seticonlabel(w, val)
wbp w;
char *val;
{
}
/*
* setdrawop() - set the drawing operation
*/
int setdrawop(w, val)
wbp w;
char *val;
{
}
void setclip(wb)
wbp wb;
{
Rect r;
STDLOCALS(wb);
SetRect (&r, wc->clipx, wc->clipy, wc->clipx+wc->clipw, wc->clipy+wc->cliph);
SetPort (ws->theWindow);
ClipRect (&r);
}
void unsetclip(w)
wbp w;
{
}
int allowresize(w, on)
wbp w;
int on;
{
return 0;
}
int setgamma(w, gamma)
wbp w;
double gamma;
{
return 0;
}
/*
* setpointer() - define a mouse pointer shape
*/
int setpointer(w, val)
wbp w;
char *val;
{
}
/*
* setcursor() -
*/
int setcursor(w, on)
wbp w;
int on;
{
if (on==1)
InitCursor ();
else {
InitCursor ();
HideCursor ();
}
return Succeeded;
}
int seticonpos(w,s)
wbp w;
char *s;
{
}
/*
* Set the window's font by name.
*/
int setfont(wb,s)
wbp wb;
char **s;
{
short theFontNum;
STDLOCALS(wb);
GetFNum (CtoPstr (*s), &theFontNum);
wc->contextPtr->txFont = theFontNum;
return Succeeded;
}
/*
* sync all the servers ???
*/
novalue wsync(w)
wbp w;
{
}
/*
* put a character out to a window using the current attributes
*/
int wputc(ci,w)
int ci;
wbp w;
{
}
int setgeometry(wb, geo)
wbp wb;
char *geo;
{
int width = 0, height = 0;
int x = 0, y = 0, status;
char *tmps;
STDLOCALS(wb);
if ((status = parsegeometry(geo, &x, &y, &width, &height)) == 0)
return Error;
if (status & 1) {
ws->width = width;
ws->height = height;
}
if (status & 2) {
ws->posx = x;
ws->posy = y;
}
/* insert assigns here:
* ws->posx = ((sign > 0) ? tmp :
* DisplayWidth(stddpy,wd->screen) - ws->width - tmp);
* ws->posy = ((sign > 0) ? tmp :
* DisplayHeight(stddpy,wd->screen) - ws->height - tmp);
*/
return Succeeded;
}
/*
* wclose - close a window. If is a real on-screen window,
* wait for a DestroyNotify event from the server before returning.
*/
int wclose(wb)
wbp wb;
{
STDLOCALS (wb);
DisposeWindow (ws->theWindow);
DisposeGWorld (ws->offScreenGWorld);
}
/*
* flush a window
*/
novalue wflush(w)
wbp w;
{
}
/*
* get a single item from w's pending queue
*/
int wgetq(wb,res)
wbp wb;
dptr res;
{
wsp ws;
if (!wb || !(ws = wb->window) || !(ws->theWindow)) return -1;
while (1) {
if (!EVQUEEMPTY (ws)) {
EVQUEGET (ws, *res);
return 1;
}
GetEvents ();
}
return -1;
}
void warpPointer(w, x, y)
wbp w;
int x, y;
{
/* can't change cursor location, Inside Mac, Imaging: 8-4 */
}
int walert(w, volume)
wbp w;
long volume;
{
long oldVol;
GetDefaultOutputVolume(&oldVol);
SetDefaultOutputVolume(volume);
SysBeep (30);
SetDefaultOutputVolume(oldVol);
}
/*
* write some text to both the window and the pixmap
*/
void xdis(w,s,n)
register wbp w;
char *s;
int n;
{
}
wsp GetActiveWindow(void)
{
}
#else /* Graphics */
static char junk; /* avoid empty module */
#endif /* Graphics */