⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mac.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 4 页
字号:
EventRecord *event;WindowPtr window;{#define track() TrackControl(whichControl,p,(ProcPtr)NULL)	ControlHandle whichControl;	Window *jwind, *cwind;	int notcurwind;	int cpart;	/* control part */	int oldval,newval,thumb = 0;	p = event->where;	intext = 0;	notcurwind = 0;	GlobalToLocal(&p);	if (event->what == mouseDown) {		if ((cpart = FindControl(p,window,&whichControl)) == 0)			return;		if ((jwind = (Window *) (*whichControl)->contrlRfCon) !=  curwind) {			notcurwind++;			cwind = curwind;			SetWind(jwind);		}		switch (cpart) {		case inUpButton:			TrackControl(whichControl,p,(ProcPtr) DScroll);			break;		case inDownButton:			TrackControl(whichControl,p,(ProcPtr) UScroll);			break;		case inPageUp:			TrackControl(whichControl,p,(ProcPtr) PPage);			break;		case inPageDown:			TrackControl(whichControl,p,(ProcPtr) NPage);			break;		case inThumb:			if (track()) {				newval = GetCtlValue(whichControl);				if (newval == MAXC)					Eof();				else if (newval == MINC)					Bof();				else					SetLine(ctol(newval));			}			break;		}		if (notcurwind) {			SetWind(cwind);			redisplay();		}		redisplay();	/* again, to set the cursor */	}	else {		if (findtext())			redisplay();	}}#define std_state(w) (*((WStateData **)((WindowPeek)((w)))->dataHandle))->stdState#define user_state(w) (*((WStateData **)((WindowPeek)((w)))->dataHandle))->userStateprivate voiddoDrag(event,window)EventRecord *event;WindowPtr window;{	Rect old_std;	old_std = std_state(window);	DragWindow(window, event->where, &LimitRect);	if (wc == &wc_std) {		wc_user = wc_std;		user_state(theScreen) = std_state(theScreen);		ZoomWindow(window,7,1);		wc = &wc_user;		Reset_std();	}}private voiddoGrow(event,window)EventRecord *event;WindowPtr window;{	long size;	/* zero means user didn't change anything */	if (size = GrowWindow(window, event->where, &LimitRect)) {		if (wc == &wc_std) {			wc_user = wc_std;			user_state(theScreen) = std_state(theScreen);			ZoomWindow(window,7,1);			wc = &wc_user;			Reset_std();		}		if (wc_adjust(LoWord(size),HiWord(size),wc,0)) {			EraseRect(&window->portRect);			SizeWindow(window,wc->w_width,wc->w_height,TRUE);			win_reshape();	/* no signals here... */		}	}}private voiddoZoomIn(event,window)EventRecord *event;WindowPtr window;{	if (TrackBox(window, event->where, 7)) {			EraseRect(&window->portRect);			ZoomWindow(window,7,1);			wc = &wc_user;			win_reshape();	/* we do our own toggle, not ZoomWindow() */		}}private voiddoZoomOut(event,window)EventRecord *event;WindowPtr window;{	if (TrackBox(window, event->where, 8)) {			EraseRect(&window->portRect);			ZoomWindow(window,8,1);			wc = &wc_std;			win_reshape();	/* we do our own toggle, not ZoomWindow() */		}}private voiddoGoAway(event,window)EventRecord *event;WindowPtr window;{	if (TrackGoAway(window, event->where))		Leave();}private Window *rtowind(row)	/* return jove window row is in */int row;{	Window *w = fwind;	do {		if ((w->w_topline <= row) && ((w->w_height + w->w_topline) > row))			return w;		w = w->w_next;	} while (w != fwind);	return NULL;}private Line *windtol(w,row)		/* return line for row in window */Window *w;int row;{	Line *l = w->w_top;	while (row--)		if ((l = l->l_next) == NULL)			return NULL;	return l;}private boolfindtext()		/* locate and move the point to match the mouse */{	int row,col;	long ticks;	EventRecord event;	Window *w;	Line *l;	ticks = Ticks;	ptoxy(p,&row,&col);	if ((w = rtowind(row)) == NULL)		return NO;	if (w != curwind)		SetWind(w);	row -= w->w_topline;		/* now have row number in window */	if (row >= w->w_height -1)		return NO;	if ((l = windtol(w,row)) == NULL)		return NO;	if (l->l_dline == NULL_DADDR)		return NO;	this_cmd = LINECMD;	SetLine(l);		/* Curline is in linebuf now */	if (w->w_flags & W_NUMLINES)		col -= 8;	/* adjust for line numbers */	if (col < 0)		col = 0;	curchar = how_far(curline, col);	do {		if (GetNextEvent(mUpMask,&event) && (event.when < ticks + DoubleTime)) {			set_mark();			break;		}	} while ((Ticks - ticks) < DoubleTime);	return YES;}private intptoxy(p,row,col)	/* convert Point to terminal x,y coordinate */Point p;int *row,*col;{	*row = (p.v / HEIGHT);	*col = (p.h / WIDTH );	if ((*row > MAXROW) || (*col > MAXCOL))		return ERROR;	return 0;}/* Event-related routines. The Event loop is CheckEvents(), and is called whenever   a console read occurs or a call to charp(). During certain activities, such as ask(),   etc. non-keyboard events are ignored. This is set by the variable Keyonly.   As an update or activate event generates a call to redisplay(), it is important   that redisplay() and related routines NOT check for keyboard characters. *//* (ORIGINALLY IN) tevent.c	event handler for Jove. K Mitchum 12/86 */#define SYS_ID 100#define NOFUNC ((void (*)())NULL)#define NEVENTS 16extern void doMouse(),dokeyDown(),doUpdate(),doActivate();private void p_refresh proto((void));private MenuHandle SysMenu;private void (*eventlist[])() ={	NOFUNC, /* nullEvent */	doMouse,/* mouseDown */	doMouse, /* mouseUp */	dokeyDown, /* keyDown */	NOFUNC, /* keyUp */	dokeyDown, /* autoKey */	doUpdate, /* updateEvt */	NOFUNC, /* diskEvt */	doActivate, /* activateEvt */	NOFUNC, /* not  used */	NOFUNC, /* networkEvt = 10 */	NOFUNC, /* driverEvt */	NOFUNC, /* app1Evt */	NOFUNC, /* app2Evt */	NOFUNC,	/* app3Evt */	NOFUNC	/* app4Ev */};private voidCheckEvents(){	void SetBufMenu(),		MarkModes();	static EventRecord theEvent;	static Point Mousep;	static long time = 0;	static void (*fptr)();	if (FrontWindow() == window) {		GetMouse(&Mousep);		if (PtInRect(Mousep,&r))			SetCursor(*cross);		else			SetCursor(&arrow);	}	SystemTask();	if (EventCmd && !Keyonly)		return;	if (Bufchange)		SetBufMenu();	if (Modechange)		MarkModes();	while (GetNextEvent(everyEvent,&theEvent)) {		if ((theEvent.what < NEVENTS) && (fptr = eventlist[theEvent.what])) {			(*fptr)(&theEvent);		}		SystemTask();	}	if ((Ticks - time) > 3600) {		time = Ticks;		UpdModLine = YES;		redisplay();	}}private voidInitSysMenu(){	void InitLocalMenus();	SysMenu = NewMenu(SYS_ID,"\p\24");	AppendMenu(SysMenu,"\pAbout Jove");	AddResMenu(SysMenu,'DRVR');	InsertMenu(SysMenu,0);	InitLocalMenus();	DrawMenuBar();}extern void doWind(),doGoAway(),doSysMenu(),doSysClick(),	 doDrag(), doGrow(), doZoomIn(), doZoomOut();#define NMEVENTS 9private void (*mouselist[])() ={	NOFUNC, /* inDesk */	doSysMenu, /* inMenuBar */	doSysClick, /* inSysWindow */	doWind, /* inContent */	doDrag, /* inDrag */	doGrow, /* inGrow */	doGoAway, /* inGoAway */	doZoomIn,	/* inZoomIn */	doZoomOut	/* inZoomOut */};private voiddoMouse(event)EventRecord *event;{	WindowPtr theWindow;	int wpart;	void (*fptr)();	if (Keyonly) {		if (event->what == mouseDown)			SysBeep(2);		return;	}	wpart = FindWindow(event->where,&theWindow);	if ((wpart < NMEVENTS) && (fptr = mouselist[wpart])) {		(*fptr)(event,theWindow);	}}private voiddoSysMenu(event,window)EventRecord *event;WindowPtr window;{	void ProcMenu();	int Menu,Item;	long result = MenuSelect(event->where);	Menu = (result >> 16) & 0xffff;	Item = result & 0xffff;	if (Item == 0)		return;	/* no choice made */	if (Menu == SYS_ID) {			/* apple menu */		Str255 Name;		GrafPtr Port;		if (Item == 1)			about_j();		else {			GetItem(SysMenu,Item,Name);			GetPort(&Port);			OpenDeskAcc(Name);			SetPort(Port);		}	}	else		ProcMenu(Menu,Item);	HiliteMenu(0);	EventCmd = YES;	menus_on();}private voiddoSysClick(event,window)EventRecord *event;WindowPtr window;{	SystemClick(event,window);}private voiddoUpdate(event)EventRecord *event;{	WindowPtr theWindow, oldPort;	theWindow = (WindowPtr) event->message;	GetPort(&oldPort);	SetPort(theWindow);	BeginUpdate(theWindow);	p_refresh();	drawfluff();	EndUpdate(theWindow);	SetPort(oldPort);}private voiddoActivate(event)EventRecord *event;{	WindowPtr theWindow;	ControlHandle control;	int hilite;	theWindow = (WindowPtr) event->message;	SetPort(theWindow);	hilite = (event->modifiers & activeFlag)? 0 : 255;	for (control = (ControlHandle) (((WindowPeek) theWindow)->controlList)	; (control != 0); control = (*control)->nextControl) {			HiliteControl(control,hilite);	}}/* Keyboard routines. The Option key was formerly used as a meta key.   However, to take advantage of the full (non-ASCII) character set,   this was removed. The corresponding code is ifdeffed O_META. *//* (ORIGINALLY IN) tkey.c   keyboard routines for Macintosh. K Mitchum 12/86 */extern jmp_buf auxjmp;private nchars = 0;private char charbuf[MCHARS];/* The following kludges a meta key out of the option key by   sending an escape sequence back to the dispatch routines. this is   not elegant but it works, and doesn't alter escape sequences for   those that prefer them. to remap the control or meta keys,   see mackeys.h. */private voiddokeyDown(event)EventRecord *event;{	unsigned mods;	register c;	static int cptr = 0;	if (MCHARS - nchars < 2)		return;	c  = (char)((event->message)&(charCodeMask));	mods = event->modifiers;#ifdef	O_META	if (mods & (optionKey | cmdKey | controlKey)) {#else	if (mods & (cmdKey | controlKey)) {#endif#ifdef	NEVER		if (mods & shiftKey)			c  = sh_keycodes[(((event->message)&(keyCodeMask))>>8)];		else			c  = nsh_keycodes[(((event->message)&(keyCodeMask))>>8)];#endif#ifdef	O_META		if (mods & optionKey) {		/* make escape sequence */			if (mods & cmdKey)				c &= 0x1f;			charbuf[cptr++] = '\033';			cptr &= NMASK;		/* zero if necessary */			nchars++;		}		else#endif		{	/* command key (control key) */			if ((c == '2') || (c == '\\') || (c == ' '))				c = '\0';	/* so we have a null char */			if (c != '`')				c &= 0x1f;		/* make a control char */		}	}	else {		if (c == '`')			c = '\033';	/* for those used to escapes */	}	charbuf[cptr++] = c;	cptr &= NMASK;	nchars++;}private intrawgetc(){	static int cptr = 0;	register int c;	if (EventCmd)		longjmp(auxjmp,1);	while (nchars <= 0) {		nchars = 0;		if (EventCmd)			longjmp(auxjmp,1);		CheckEvents();	/* ugh! WAIT for a character */	}	nchars--;	c = charbuf[cptr++];	cptr &= NMASK;		/* zero if necessary */	return c;}boolrawchkc(){	if (EventCmd)		longjmp(auxjmp,1);	if (nchars == 0)		CheckEvents();	/* this should NOT be necessary! */	return nchars > 0;}/* Routines for calling the standard file dialogs, when macify is ON. If the user   changes the directory using the file dialogs, Jove's notion of the current directory   is updated. *//* (ORIGINALLY IN) tmacf.c. K. Mitchum 12/86.   Macify routines for jove. */int CurrentVol;			/* see tfile.c */#define TYPES  (-1)private Point px = {100,100};private char pmess[] = "\pSave file as: ";private pascal BooleanFfilter(p)FileParam *p;{	if (p->ioFlFndrInfo.fdType == 'APPL')		return TRUE;	PtoCstr((char *) p->ioNamePtr);	if (strcmp(p->ioNamePtr,d_tempfile) == 0) {		CtoPstr((char *) p->ioNamePtr);		return TRUE;	}	CtoPstr((char *) p->ioNamePtr);	return FALSE;}private voidcheck_dir(){	if (cur_vol != 0 - SFSaveDisk || cur_dir != CurDirStore) {		setdir(0 - SFSaveDisk, CurDirStore);		UpdModLine = YES;	/* make sure jove knows the change */		Modechange = YES;		setCWD(getwd());	}}char *gfile(namebuf)	/* return a filename to get */char *namebuf;{	SFReply frec;	char ans[FILESIZE];	SFSaveDisk = 0 - cur_vol;	/* in case a Desk Accessory changed them */	CurDirStore = cur_dir;	SFGetFile(px,0L,Ffilter,TYPES,0L,0L,&frec);	check_dir();	/* see if any change, set if so */	if (frec.good) {		EventRecord theEvent;		do; while (GetNextEvent(updateMask,&theEvent) == 0);		doUpdate(&theEvent);		PtoCstr((char *)frec.fName);		strcpy(ans,frec.fName);		CtoPstr((char *)frec.fName);		PathParse(ans,namebuf);		return namebuf;	}	return (char *)NULL;}char *pfile(namebuf)char *namebuf;{	SFReply frec;	char *t, *nm;	SFSaveDisk = 0 - cur_vol;	/* in case a Desk Accessory changed them */	CurDirStore = cur_dir;	strncpy(namebuf,filename(curbuf),63);	nm = cvt_fnm(namebuf);	CtoPstr(nm);	SFPutFile(px,pmess,nm,0L,&frec);	check_dir();	/* see if any change, set if so */	if (frec.good) {		EventRecord theEvent;		do; while (GetNextEvent(updateMask,&theEvent) == 0);		doUpdate(&theEvent);		t = (char *)frec.fName;		PtoCstr((char *)frec.fName);		while (*t == ':')			t++;	/* convert to unix style */		nm = t;		while (*nm) {			if (*nm == ':')				*nm = '/';			nm++;		}		PathParse(t,namebuf);		return namebuf;	}	return (char *)NULL;}/* getArgs() returns an argument list based on documents clicked on by the user. */intgetArgs(avp)char ***avp;{	int argc, nargs, type, old_vol;	long old_dir;	char **argv;	char *pathname;	AppFile p;	WDPBRec d;	old_vol = cur_vol;	old_dir = cur_dir;	CountAppFiles(&type,&nargs);	if (nargs > 0) {	/* files to open... */		argv = (char **) emalloc((nargs + 2) * sizeof(char *));		for (argc = 1; argc <= nargs; argc++) {			GetAppFiles(argc,&p);			if (type == 0) {				PtoCstr((char *)p.fName);				d.ioCompletion = 0;				d.ioNamePtr = NULL;				d.ioVRefNum = p.vRefNum;				d.ioWDIndex = 0;				PBGetWDInfo(&d,0);				cur_vol = d.ioWDVRefNum;				cur_dir = d.ioWDDirID;				pathname = getwd();				argv[argc] = emalloc(strlen((char *)p.fName) + strlen(pathname) + 2);				strcpy(argv[argc],pathname);				strcat(argv[argc],"/");				strcat(argv[argc],(char *)p.fName);			}			ClrAppFiles(argc);		}		if (type != 0)			argc = 1;	}	else {		argv = (char **) emalloc(2 * sizeof(char*));		argc = 1;	}	argv[0] = "jove";	argv[argc] = NULL;	*avp = argv;	cur_dir = old_dir;	cur_vol = old_vol;	return argc;}/* Limited version of getenv() */char *getenv(item)char *item;{	char *ret = NULL, *str = NULL;	if (strcmp(item,"CWD") == 0)		str = getwd();	if (strcmp(item,"HOME") == 0)		str = gethome();	if (str) {		ret = emalloc(strlen(str) + 1);		strcpy(ret,str);	}	return ret;}char *mktemp(name)char *name;{	return name;}/* Menu routines. The menus items are set up in a similar manner as keys, and   are bound prior to runtime. See menumaps.txt, which must be run through setmaps.   Unlike keys, menu items may be bound to variables, and to buffers. Buffer binding   is only done at runtime. */private voidInitLocalMenus(){	void InitMenu(),		make_edits();	int i;	for (i = 0; i < NMENUS; i++) {		InitMenu(&Menus[i]);		if (i == 0)			make_edits(Menus[i].menu_id + 1);	}}private voidInitMenu(M)struct menu *M;{	int i;	data_obj *d;	char *name;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -