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

📄 cmap.c

📁 安装DDD之前
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $Id: Cmap.c,v 1.1 2002/05/15 10:14:42 amai Exp $ *//* * Copyright 1992,1993,1994 John L. Cwikla *  * * Author: * 	John L. Cwikla *	Wolfram Research, Inc. *	cwikla@wri.com *  * Thanks to: * *	Pierre-Yves Bonnetain *	SILOGIC *	78, chemin des Sept Deniers *	31200 TOULOUSE *	FRANCE. *  *  who provided the improvement to use the shell's visual. *//*** Cmap Widget*/#define NeedFunctionProtoTypes	1#include <stdio.h>#include <X11/Xos.h>#include <X11/IntrinsicP.h>#include <X11/StringDefs.h>#include <X11/ShellP.h>#include <Xm/LabelP.h>#include <math.h>#ifdef __STDC__#include <stdarg.h>#else#include <varargs.h>#endif#include "CmapP.h"/* For actions */#if NeedFunctionProtoTypesstatic void left(Widget _cw, XEvent *_event, String *_argv, Cardinal *_argc);static void right(Widget _cw, XEvent *_event, String *_argv, Cardinal *_argc);static void up(Widget _cw, XEvent *_event, String *_argv, Cardinal *_argc);static void down(Widget _cw, XEvent *_event, String *_argv, Cardinal *_argc);static void cselect(Widget _cw, XEvent *_event, String *_argv, Cardinal *_argc);#elsestatic void left();static void right();static void up();static void down();static void cselect();#endif/* For widget internals */#if NeedFunctionProtoTypesstatic void initialize(Widget _request, Widget _new, ArgList args, Cardinal *num_args);static void realize(Widget _cw, XtValueMask *_xvm, XSetWindowAttributes *_xswa);static void resize(Widget _cw);static void destroy(Widget _cw);static void redisplay(Widget _cw, XEvent *_event, Region _region);static Boolean setValues(Widget _current, Widget _request, Widget _new, ArgList args, Cardinal *num_args);static void borderHighlight(Widget _cw);static void borderUnhighlight(Widget _cw);static void myXtWarning(char *_format, ...);#elsestatic void initialize();static void realize();static void resize();static void destroy();static void redisplay();static Boolean setValues();static void borderHighlight();static void borderUnhighlight();static void myXtWarning();#endif/* For Misc */#if NeedFunctionProtoTypesstatic int xYtoBox(Widget _cw, int _x, int _y);static void reString(Widget _cw);static void drawLabel(Widget _cw, GC _gc);static void drawSelected(Widget _cw, int _boxNumber);static void drawBox(Widget _cw, int _boxNumber);static void getFont(Widget _cw);#elsestatic int xYtoBox();static void reString();static void drawLabel();static void drawSelected();static void drawBox();static void getFont();#endifstatic char cmapTranslations[] =#if (XmREVISION == 2)"~s <Key>osfLeft: left()\n\~s <Key>osfRight: right()\n\~s <Key>osfUp: up() \n\~s <Key>osfDown: down() \n\<Btn1Down>: select()\n\<Btn1Motion>: select()\n\~s ~m ~a <Key>Return: PrimitiveParentActivate()\n\<Key>osfActivate: PrimitiveParentActivate()\n\<Key>osfCancel:PrimitiveParentCancel()\n\<Enter>:PrimitiveEnter()\n\<Leave>:PrimitiveLeave()\n\s ~m ~a <Key>Tab: PrimitivePrevTabGroup()\n\~m ~a <Key>Tab: PrimitiveNextTabGroup()\n\Shift<Key>osfUp:PrimitiveTraverseUp()\n\Shift<Key>osfDown:PrimitiveTraverseDown()\n\Shift<Key>osfLeft:PrimitiveTraverseLeft()\n\Shift<Key>osfRight:PrimitiveTraverseRight()\n\<FocusIn>:PrimitiveFocusIn()\n\<FocusOut>:PrimitiveFocusOut()\n\<Unmap>:PrimitiveUnmap()\n\<Key>osfHelp:PrimitiveHelp()";#else"~s <Key>osfLeft: left()\n\~s <Key>osfRight: right()\n\~s <Key>osfUp: up() \n\~s <Key>osfDown: down() \n\<Btn1Down>: select()\n\<Btn1Motion>: select()\n\s ~m ~a <Key>Tab: PrimitivePrevTabGroup()\n\~m ~a <Key>Tab: PrimitiveNextTabGroup()\n\Shift<Key>osfUp:PrimitiveTraverseUp()\n\Shift<Key>osfDown:PrimitiveTraverseDown()\n\Shift<Key>osfLeft:PrimitiveTraverseLeft()\n\Shift<Key>osfRight:PrimitiveTraverseRight()\n\<FocusIn>:PrimitiveFocusIn()\n\<FocusOut>:PrimitiveFocusOut()\n\<Unmap>:PrimitiveUnmap()\n\<Key>osfHelp:PrimitiveHelp()";#endif /* XmREVISION */static XtActionsRec cmapActions[] = {	{ "left", left },	{ "right", right },	{ "up", up },	{ "down", down },	{ "select", cselect}};#define RGB_STRING "R:%d G:%d B:%d (%d of %d)"#define BOXtoX(w, b) (((b) % ((CmapWidget)w)->cmap.numX) * ((CmapWidget)w)->cmap.realBoxWidth + ((CmapWidget)w)->cmap.drawPos.x)#define BOXtoY(w, b) (((b) / ((CmapWidget)w)->cmap.numX) * ((CmapWidget)w)->cmap.realBoxHeight + ((CmapWidget)w)->cmap.drawPos.y)#define ROW(w, a) ((a) / ((CmapWidget)w)->cmap.numX)#define COL(w, a) ((a) % ((CmapWidget)w)->cmap.numX)#ifndef MAX#define MAX(a,b) ((a) > (b) ? (a) : (b))#endif#ifndef MIN#define MIN(a,b) ((a) < (b) ? (a) : (b))#endif#define CORE(a) (((CmapWidget)(a))->core)#define PRIM(a) (((CmapWidget)(a))->primitive)#define CMAP(a) (((CmapWidget)(a))->cmap)#define FONT_LIST(a) (((CmapWidget)(a))->cmap.fontList)#define THE_FONT(a) (((CmapWidget)(a))->cmap.font)#define FG(a) (((CmapWidget)(a))->primitive.foreground)#define TX(a) (((CmapWidget)(a))->primitive.highlight_thickness)#define TY(a) (((CmapWidget)(a))->primitive.highlight_thickness)#define TWIDTH(a) (((CmapWidget)(a))->core.width - 2 * ((CmapWidget)(a))->primitive.highlight_thickness)#define THEIGHT(a) (((CmapWidget)(a))->core.height - 2 * ((CmapWidget)(a))->primitive.highlight_thickness)#define CMAP_MINBOXWIDTH(a) (10 + ((CmapWidget)(a))->primitive.shadow_thickness * 2 + ((CmapWidget)(a))->primitive.highlight_thickness * 2)#define CMAP_MINBOXHEIGHT(a) (10 + ((CmapWidget)(a))->primitive.shadow_thickness * 2 + ((CmapWidget)(a))->primitive.highlight_thickness * 2)#define ST(a) (((CmapWidget)(a))->primitive.shadow_thickness)#define HT(a) (((CmapWidget)(a))->primitive.highlight_thickness)#define HRECT(a) (((CmapWidget)(a))->cmap.hrects)#define ISHAD(a) (((CmapWidget)(a))->cmap.invertedShadows)#if (XmREVISION == 2)extern XmPrimitiveClassExtRec _XmPrimClassExtRec;#define LOCALPRIMITIVEEXTREC &_XmPrimClassExtRec#else#define LOCALPRIMITIVEEXTREC NULL#endif#define TheOffset(field) XtOffset(CmapWidget, cmap.field)static XtResource cmapResources[] = {	{XmNfontList, XmCFontList, XmRFontList, sizeof(XmFontList),		TheOffset(fontList), XmRImmediate, (XtPointer)NULL},	{XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension),		TheOffset(margin), XtRImmediate, (XtPointer)2},	{XtNchangeCallback, XtCCallback, XtRCallback, sizeof(XtPointer),		TheOffset(changeCallback), XtRCallback, (XtPointer)NULL},	{XtNselected, XtCSelected, XtRInt, sizeof(int),		TheOffset(selected), XtRImmediate, (XtPointer)0},	{XtNboxWidth, XtCBoxWidth, XtRInt, sizeof(int),		TheOffset(boxWidth), XtRImmediate, (XtPointer)0},	{XtNboxHeight, XtCBoxHeight, XtRInt, sizeof(int),		TheOffset(boxHeight), XtRImmediate, (XtPointer)0},	{XtNfirstIndex, XtCFirstIndex, XtRInt, sizeof(int),		TheOffset(firstIndex), XtRImmediate, (XtPointer)0},	{XtNlastIndex, XtCLastIndex, XtRInt, sizeof(int),		TheOffset(lastIndex), XtRImmediate, (XtPointer)LastIndexDefault},	{XtNmappingTable, XtCMappingTable, XtRPointer, sizeof(XtPointer),		TheOffset(mappingTable), XtRImmediate, (XtPointer)NULL},#if DEBUGGING	{XtNstandardColormap, XtCStandardColormap, XtRAtom, sizeof(Atom),		TheOffset(standardColormap), XtRImmediate, (XtPointer)0},#endif	{XtNshowUnselectedShadows, XtCShowShadows, XtRBoolean, sizeof(Boolean),		TheOffset(showUnselectedShadows), XtRImmediate, (XtPointer)FALSE},	{XtNinvertedShadows, XtCInvertedShadows, XtRBoolean, sizeof(Boolean),		TheOffset(invertedShadows), XtRImmediate, (XtPointer)FALSE},};#undef TheOffsetCmapClassRec cmapClassRec = {	{				/* CoreClassPart */	(WidgetClass)&xmPrimitiveClassRec, /* superclass */		"Cmap",												/* class_name */		sizeof(CmapRec),							 /* widget_size */		NULL,													/* class_initialize */		NULL,													/* class_part_initialize */		FALSE,												 /* class_init */		initialize,										/* initialize */		NULL,													/* initialize_hook */		realize,											 /* realize */		cmapActions,									 /* actions */		XtNumber(cmapActions),				 /* num_actions */		cmapResources,								 /* resources */		XtNumber(cmapResources),			 /* num_resources */		NULLQUARK,										 /* xrm_class */		TRUE,													/* compress_motion */		XtExposeCompressMultiple |		XtExposeGraphicsExposeMerged,													/* compress_exposure */		TRUE,													/* compress_enterleave */		TRUE,													/* visible_intress */		destroy,											 /* destroy */		resize,												/* resize */		redisplay,										 /* expose */		setValues,										 /* set_values */		NULL,													/* set_values_hook */		XtInheritSetValuesAlmost,			/* set_values_almost */		NULL,													/* get_values_hook */		NULL,													/* accept_focus */		XtVersion,										 /* version */		NULL,													/* callback_private */		cmapTranslations,							/* tm_translations */		NULL,		NULL,		NULL,	},{	borderHighlight,	borderUnhighlight,	NULL, /* XtInheritTranslations, */	(XtActionProc)NULL,	(XmSyntheticResource *)NULL,	0,	(XtPointer)LOCALPRIMITIVEEXTREC,},	{ 		0, /* empty */	}};WidgetClass cmapWidgetClass = (WidgetClass) &cmapClassRec;static void initialize(_request, _new, args, num_args)Widget _request;Widget _new;ArgList args;Cardinal *num_args;{	Display *display;	XColor color;	Widget parent;	display = XtDisplay(_new);	getFont(_new);	if (CMAP(_new).firstIndex < 0)	{		myXtWarning("CmapWidget: FirstIndex (%d) cannot be negative. FirstIndex set to 0.", CMAP(_new).firstIndex);		CMAP(_new).firstIndex = 0;	}	parent = XtParent(_new);	while(!XtIsShell(parent))		parent = XtParent(_new);	if (parent == (Widget)NULL)		CMAP(_new).availColors = XDisplayCells(display, DefaultScreen(display));	else	{		XVisualInfo *vout, vtemplate;		int numVis;		ShellWidget shellw;		shellw = (ShellWidget)parent;		if (shellw->shell.visual)		{			vtemplate.visualid = XVisualIDFromVisual(shellw->shell.visual);			vout = XGetVisualInfo (display, VisualIDMask, &vtemplate, &numVis);			if (vout != (XVisualInfo *)NULL)			{				CMAP(_new).availColors = vout[0].colormap_size;				XFree(vout);			}			else				CMAP(_new).availColors = XDisplayCells(display, DefaultScreen(display));		}		else			CMAP(_new).availColors = XDisplayCells(display, DefaultScreen(display));	}			if (CMAP(_new).lastIndex == LastIndexDefault)		CMAP(_new).lastIndex = CMAP(_new).availColors-1; 	if (CMAP(_new).firstIndex > CMAP(_new).availColors-1)	{		myXtWarning("CmapWidget: FirstIndex (%d) cannot be more than greatest index (%d).	FirstIndex set to %d.",			CMAP(_new).firstIndex, (CMAP(_new).availColors-1), (CMAP(_new).availColors-1));		CMAP(_new).firstIndex = CMAP(_new).availColors-1;	}	if (CMAP(_new).lastIndex < CMAP(_new).firstIndex)	{		myXtWarning("CmapWidget: LastIndex (%d) cannot be less than FirstIndex (%d).	LastIndex set to %d.", 			CMAP(_new).lastIndex, CMAP(_new).firstIndex, CMAP(_new).firstIndex+1);		CMAP(_new).lastIndex = CMAP(_new).firstIndex + 1;	}	if ((CMAP(_new).mappingTable == NULL) && (CMAP(_new).lastIndex > CMAP(_new).availColors-1))	{		myXtWarning("CmapWidget: LastIndex (%d) cannot be more than greatest index (%d).	LastIndex set to %d.",			CMAP(_new).lastIndex, CMAP(_new).availColors-1, CMAP(_new).availColors-1);		CMAP(_new).lastIndex = CMAP(_new).availColors-1;	}	if (CMAP(_new).mappingTable == NULL)		CMAP(_new).usedColors = MIN(CMAP(_new).lastIndex-CMAP(_new).firstIndex+1, CMAP(_new).availColors);	else		CMAP(_new).usedColors = CMAP(_new).lastIndex-CMAP(_new).firstIndex+1;	CMAP(_new).numX = (int)floor(sqrt((double)(CMAP(_new).usedColors)));	CMAP(_new).numY = CMAP(_new).usedColors/CMAP(_new).numX + (CMAP(_new).usedColors % CMAP(_new).numX ? 1 : 0);	if (CMAP(_new).selected > CMAP(_new).usedColors)	{		myXtWarning("CmapWidget: Selected pixel (%d) is greater than %d. Selected set to %d.",			CMAP(_new).selected, CMAP(_new).usedColors-1, CMAP(_new).usedColors-1);		CMAP(_new).selected = CMAP(_new).usedColors-1;	}	if (CMAP(_new).selected < 0)	{		myXtWarning("CmapWidget: Selected pixel cannot be negative! Selected set to 0.");		CMAP(_new).selected = 0;	}	if (CMAP(_new).mappingTable == (Pixel *)NULL)		color.pixel = CMAP(_new).selected+CMAP(_new).firstIndex;	else		color.pixel = ((Pixel *)CMAP(_new).mappingTable)[CMAP(_new).selected+CMAP(_new).firstIndex];	XQueryColor(display, CORE(_new).colormap, &color);	CMAP(_new).selectedColor = color;	sprintf(CMAP(_new).label, RGB_STRING, color.red, color.green,		color.blue, CMAP(_new).selected+1, CMAP(_new).usedColors);	CMAP(_new).labelHeight = CMAP(_new).font->ascent + CMAP(_new).font->descent;	CMAP(_new).labelWidth = XTextWidth(CMAP(_new).font, CMAP(_new).label, strlen(CMAP(_new).label)); 	if (_request->core.width == 0)	{		Dimension maxLabel;		int count;		count = strlen(RGB_STRING) + 19;

⌨️ 快捷键说明

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