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

📄 cmap.c

📁 安装DDD之前
💻 C
📖 第 1 页 / 共 3 页
字号:
		maxLabel = count * THE_FONT(_new)->max_bounds.width; /* Max bounded guess. */		CORE(_new).width = MAX ((CMAP(_new).boxWidth ? CMAP(_new).boxWidth : CMAP_MINBOXWIDTH(_new)) * CMAP(_new).numX, maxLabel)			+ 2 * CMAP(_new).margin;		CORE(_new).width += PRIM(_new).highlight_thickness * 2;	}	if (_request->core.height == 0)	{		CORE(_new).height = (CMAP(_new).boxHeight ? CMAP(_new).boxHeight : CMAP_MINBOXHEIGHT(_new)) * CMAP(_new).numY + CMAP(_new).margin 			+ CMAP(_new).labelHeight + 2 * CMAP(_new).margin;		CORE(_new).height += PRIM(_new).highlight_thickness * 2;	}	CMAP(_new).halfMargin = CMAP(_new).margin/2;	CMAP(_new).wasHighlighted = FALSE;	if (HT(_new) > 0)		HRECT(_new) = (XRectangle *)XtMalloc(sizeof(XRectangle) * HT(_new));	resize(_new);}static void realize(_cw, _xvm, _xswa)Widget _cw; XtValueMask *_xvm;XSetWindowAttributes *_xswa;{	XGCValues gcValues;	XRectangle xrect;/* Call the Realize procedure (XtInheritRealize) */	(*cmapWidgetClass->core_class.superclass->core_class.realize)((Widget)_cw, _xvm, _xswa);/* Now we can create our GC's */	gcValues.foreground = CMAP(_cw).selected;	CMAP(_cw).gc = XCreateGC(XtDisplay(_cw), XtWindow(_cw), GCForeground, &gcValues);/* This one is read only */	gcValues.foreground = FG(_cw); 	gcValues.font = CMAP(_cw).font->fid;	CMAP(_cw).foregroundGC = XtGetGC((Widget)_cw, GCFont | GCForeground, &gcValues);/* This one is read only */	gcValues.foreground = _cw->core.background_pixel;	CMAP(_cw).eraseGC = XtGetGC((Widget)_cw, GCFont | GCForeground, &gcValues);	xrect.x = xrect.y = PRIM(_cw).highlight_thickness;	xrect.width = CORE(_cw).width - 2 * PRIM(_cw).highlight_thickness;	xrect.height = CORE(_cw).height - 2 * PRIM(_cw).highlight_thickness;	XSetClipRectangles(XtDisplay(_cw), CMAP(_cw).gc, 0, 0, &xrect, 1, Unsorted);	XSetClipRectangles(XtDisplay(_cw), CMAP(_cw).foregroundGC, 0, 0, &xrect, 1, Unsorted);	XSetClipRectangles(XtDisplay(_cw), CMAP(_cw).eraseGC, 0, 0, &xrect, 1, Unsorted);}static void resize(_cw)Widget _cw;{	int marginX, marginY;	XRectangle xrect;	marginX = 2 * CMAP(_cw).margin;	marginY = 2 * CMAP(_cw).margin;	CMAP(_cw).realBoxWidth = (TWIDTH(_cw) - marginX)/CMAP(_cw).numX;	CMAP(_cw).realBoxHeight = (THEIGHT(_cw) - marginY - (CMAP(_cw).labelHeight + CMAP(_cw).margin)) /		CMAP(_cw).numY;	if (CMAP(_cw).boxWidth)		if (CMAP(_cw).realBoxWidth > CMAP(_cw).boxWidth)			 CMAP(_cw).realBoxWidth = CMAP(_cw).boxWidth;	if (CMAP(_cw).boxHeight)		if (CMAP(_cw).realBoxHeight > CMAP(_cw).boxHeight)		 CMAP(_cw).realBoxHeight = CMAP(_cw).boxHeight; 	marginX += (TWIDTH(_cw) - marginX) - (CMAP(_cw).numX * CMAP(_cw).realBoxWidth);	marginY += (THEIGHT(_cw) - marginY) - (CMAP(_cw).numY * CMAP(_cw).realBoxHeight + CMAP(_cw).margin + CMAP(_cw).labelHeight);	CMAP(_cw).drawPos.y = marginY / 2 + TX(_cw);	CMAP(_cw).drawPos.x = marginX / 2 + TY(_cw);	CMAP(_cw).labelPos.x = (TWIDTH(_cw)/2) - (CMAP(_cw).labelWidth)/2 + TX(_cw);	CMAP(_cw).labelPos.y = CMAP(_cw).drawPos.y + (CMAP(_cw).numY * CMAP(_cw).realBoxHeight) + CMAP(_cw).font->ascent 		+ CMAP(_cw).margin;	if (XtIsRealized(_cw))	{		xrect.x = xrect.y = PRIM(_cw).highlight_thickness;		xrect.width = CORE(_cw).width - 2 * PRIM(_cw).highlight_thickness;		xrect.height = CORE(_cw).height - 2 * PRIM(_cw).highlight_thickness;		XSetClipRectangles(XtDisplay(_cw), CMAP(_cw).gc, 0, 0, &xrect, 1, Unsorted);		XSetClipRectangles(XtDisplay(_cw), CMAP(_cw).foregroundGC, 0, 0, &xrect, 1, Unsorted);		XSetClipRectangles(XtDisplay(_cw), CMAP(_cw).eraseGC, 0, 0, &xrect, 1, Unsorted);	}}static void destroy(_cw)Widget _cw;{	XFreeGC(XtDisplay(_cw), CMAP(_cw).gc);	XtReleaseGC((Widget)_cw, CMAP(_cw).foregroundGC);	XtReleaseGC((Widget)_cw, CMAP(_cw).eraseGC);	XFreeFont(XtDisplay(_cw),CMAP(_cw).font);	XtRemoveAllCallbacks((Widget)_cw, XtNchangeCallback);	if (HT(_cw) > 0)		XtFree((char *)HRECT(_cw));	XmFontListFree(FONT_LIST(_cw));}static void getFont(_cw)Widget _cw;{	if (FONT_LIST(_cw) == NULL)	{		XmFontList defaultFont;		defaultFont = _XmGetDefaultFontList((Widget)_cw, 0);		FONT_LIST(_cw) = XmFontListCopy(defaultFont);	}	else		FONT_LIST(_cw) = XmFontListCopy(FONT_LIST(_cw));	if (FONT_LIST(_cw) == (XmFontList)NULL)	{		THE_FONT(_cw) = XLoadQueryFont(XtDisplay(_cw), "fixed");		if (THE_FONT(_cw) == (XFontStruct *)NULL)			THE_FONT(_cw) = XLoadQueryFont(XtDisplay(_cw), "*");	 }	 else		 _XmFontListGetDefaultFont(FONT_LIST(_cw), &THE_FONT(_cw));}static void drawLabel(_cw, _gc)Widget _cw; GC _gc;{	XDrawString(XtDisplay(_cw), XtWindow(_cw), _gc,		CMAP(_cw).labelPos.x, CMAP(_cw).labelPos.y,		CMAP(_cw).label, strlen(CMAP(_cw).label));}static void drawSelectedHighlight(_cw, _on)Widget _cw;Boolean _on;{	int x, y;	GC gc;	Dimension hm;		hm = CMAP(_cw).halfMargin;	x = BOXtoX(_cw, CMAP(_cw).selected);	y = BOXtoY(_cw, CMAP(_cw).selected);	if (_on)		gc = PRIM(_cw).highlight_GC;	else		gc = CMAP(_cw).eraseGC;	if (HT(_cw) > 0)	{		int i;		x += hm;		y += hm;		for(i=0;i<HT(_cw);i++)		{			HRECT(_cw)[i].x = x;			HRECT(_cw)[i].y = y;			HRECT(_cw)[i].width = (unsigned short)MAX(0, CMAP(_cw).realBoxWidth - (2 * i + hm + 1));			HRECT(_cw)[i].height = (unsigned short)MAX(0, CMAP(_cw).realBoxHeight - (2 * i + hm + 1));			x++;			y++;		}		XDrawRectangles(XtDisplay(_cw), XtWindow(_cw), gc, HRECT(_cw), i);	}}static void drawSelected(_cw, _boxNumber)Widget _cw;int _boxNumber;{	int x, y;	x = BOXtoX(_cw, _boxNumber);	y = BOXtoY(_cw, _boxNumber);#if (XmREVISION == 2)	 _XmDrawShadows (XtDisplay(_cw), XtWindow(_cw),		PRIM(_cw).top_shadow_GC,		PRIM(_cw).bottom_shadow_GC,		x + HT(_cw), y + HT(_cw),		CMAP(_cw).realBoxWidth - (2 * HT(_cw)), CMAP(_cw).realBoxHeight - (2 * HT(_cw)),		ST(_cw), (CMAP(_cw).invertedShadows ? XmSHADOW_IN : XmSHADOW_OUT));#else	_XmDrawShadow (XtDisplay(_cw), XtWindow(_cw),		(CMAP(_cw).invertedShadows ? PRIM(_cw).bottom_shadow_GC : PRIM(_cw).top_shadow_GC),		(CMAP(_cw).invertedShadows ? PRIM(_cw).top_shadow_GC : PRIM(_cw).bottom_shadow_GC),		ST(_cw), 		x + HT(_cw), y + HT(_cw),		CMAP(_cw).realBoxWidth - (2 * ST(_cw)), CMAP(_cw).realBoxHeight - (2 * ST(_cw)));#endif /* XmREVISION */	drawSelectedHighlight(_cw, CMAP(_cw).wasHighlighted);}static void drawBox(_cw, _boxNumber)Widget _cw;int _boxNumber;{	int x, y;	if (CMAP(_cw).mappingTable == (Pixel *)NULL)		XSetForeground(XtDisplay(_cw), CMAP(_cw).gc, _boxNumber+CMAP(_cw).firstIndex);	else		XSetForeground(XtDisplay(_cw), CMAP(_cw).gc, ((Pixel *)CMAP(_cw).mappingTable)[_boxNumber+CMAP(_cw).firstIndex]);	x = BOXtoX(_cw, _boxNumber);	y = BOXtoY(_cw, _boxNumber);	XClearArea(XtDisplay(_cw), XtWindow(_cw), x, y, CMAP(_cw).realBoxWidth, CMAP(_cw).realBoxHeight, FALSE);	XFillRectangle(XtDisplay(_cw), XtWindow(_cw), CMAP(_cw).gc,		x + CMAP(_cw).halfMargin, y + CMAP(_cw).halfMargin,		CMAP(_cw).realBoxWidth - CMAP(_cw).halfMargin, CMAP(_cw).realBoxHeight - CMAP(_cw).halfMargin);	if (CMAP(_cw).showUnselectedShadows)#if (XmREVISION == 2 )	 	_XmDrawShadows (XtDisplay(_cw), XtWindow(_cw),				PRIM(_cw).top_shadow_GC,				PRIM(_cw).bottom_shadow_GC,				x + CMAP(_cw).halfMargin,				y + CMAP(_cw).halfMargin,				CMAP(_cw).realBoxWidth - CMAP(_cw).halfMargin,				CMAP(_cw).realBoxHeight - CMAP(_cw).halfMargin,				ST(_cw), (CMAP(_cw).invertedShadows ? XmSHADOW_OUT : XmSHADOW_IN));#else		_XmDrawShadow(XtDisplay(_cw), XtWindow(_cw),			(CMAP(_cw).invertedShadows ? PRIM(_cw).top_shadow_GC : PRIM(_cw).bottom_shadow_GC),			(CMAP(_cw).invertedShadows ? PRIM(_cw).bottom_shadow_GC: PRIM(_cw).top_shadow_GC),			ST(_cw),			x + CMAP(_cw).halfMargin,			y + CMAP(_cw).halfMargin,			CMAP(_cw).realBoxWidth - CMAP(_cw).halfMargin,			CMAP(_cw).realBoxHeight - CMAP(_cw).halfMargin);#endif /* XmREVISION */} static void redisplay(_cw, _event, _region)Widget _cw; XEvent *_event; Region _region;{	int i,j;	int scol, ecol;	int srow, erow;	XRectangle rect;	XClipBox(_region, &rect);	if (_cw->core.visible)	{		XFillRectangle(XtDisplay(_cw), XtWindow(_cw), CMAP(_cw).eraseGC, rect.x, rect.y,			rect.width, rect.height);		rect.x = MAX(rect.x, CMAP(_cw).drawPos.x);		rect.y = MAX(rect.y, CMAP(_cw).drawPos.y);		rect.width = MIN(rect.x+rect.width, CMAP(_cw).drawPos.x+CMAP(_cw).numX*CMAP(_cw).realBoxWidth-1);		rect.height = MIN(rect.y+rect.height, CMAP(_cw).drawPos.y+CMAP(_cw).numY*CMAP(_cw).realBoxHeight-1);		if(!( (rect.x >= rect.width) || (rect.y >= rect.height)))		{			scol = COL(_cw, xYtoBox(_cw, rect.x, rect.y));			ecol = COL(_cw, xYtoBox(_cw, rect.width, rect.y));			srow = ROW(_cw, xYtoBox(_cw, rect.x, rect.y));			erow = ROW(_cw, xYtoBox(_cw, rect.x, rect.height));			i = scol;			j = srow;			for(;i<=ecol; i++)			{				for(;(j<=erow) && ((i+CMAP(_cw).numX*j)<CMAP(_cw).usedColors);j++)					drawBox(_cw, i + j*CMAP(_cw).numX); 				j = srow;			}		}		drawLabel(_cw, CMAP(_cw).eraseGC);		drawLabel(_cw, CMAP(_cw).foregroundGC);		drawSelected(_cw, CMAP(_cw).selected);	}	XFlush(XtDisplay(_cw));	if (cmapWidgetClass->core_class.superclass->core_class.expose != NULL)		(*cmapWidgetClass->core_class.superclass->core_class.expose)((Widget)_cw, _event, _region);	if (CMAP(_cw).wasHighlighted)		borderHighlight(_cw);	else		borderUnhighlight(_cw);}static void borderHighlight(_cw)Widget _cw;{	drawSelectedHighlight(_cw, TRUE);	(*((XmPrimitiveWidgetClass)cmapWidgetClass->core_class.superclass)->primitive_class.border_highlight)((Widget)_cw);	CMAP(_cw).wasHighlighted = TRUE;}static void borderUnhighlight(_cw)Widget _cw;{	drawSelectedHighlight(_cw, FALSE);	(*((XmPrimitiveWidgetClass)cmapWidgetClass->core_class.superclass)->primitive_class.border_unhighlight)((Widget)_cw);	CMAP(_cw).wasHighlighted = FALSE;}static Boolean setValues(_current, _request, _new, args, num_args)Widget _current; Widget _request; Widget _new;ArgList args;Cardinal *num_args;{	Boolean redisplay = FALSE;	Boolean newErase = FALSE;	Boolean newSelected = FALSE;	Boolean needResize = FALSE;	Display *display = XtDisplay(_new);	XGCValues gcValues;	int gcMask = GCFont;	if (FONT_LIST(_new) != FONT_LIST(_current))	{		XmFontListFree(FONT_LIST(_current));		if (FONT_LIST(_new) == NULL)		{			XmFontList defaultFont;			defaultFont = _XmGetDefaultFontList((Widget)_new, 0);			FONT_LIST(_new) = XmFontListCopy(defaultFont);		}		else			FONT_LIST(_new) = XmFontListCopy(FONT_LIST(_new));		if (FONT_LIST(_new) == (XmFontList)NULL)		{			THE_FONT(_new) = XLoadQueryFont(XtDisplay(_new), "fixed");			if (THE_FONT(_new) == (XFontStruct *)NULL)				THE_FONT(_new) = XLoadQueryFont(XtDisplay(_new), "*");		}		else			_XmFontListGetDefaultFont(FONT_LIST(_new), &THE_FONT(_new));	}	if (THE_FONT(_new) != THE_FONT(_current))	{		XFreeFont(XtDisplay(_current), THE_FONT(_current));		if ((CMAP(_new).font = XLoadQueryFont(display, "fixed")) == NULL)			if ((CMAP(_new).font = XLoadQueryFont(display, "*")) == NULL)				myXtWarning("CmapWidget: Fonts %s and %s not found.", "fixed", "*");        XSetFont(display, CMAP(_new).foregroundGC, CMAP(_new).font->fid);        newSelected = TRUE;        newErase = TRUE;        redisplay = TRUE;	}	if (_new->core.background_pixel != _current->core.background_pixel)	{		gcValues.foreground = gcValues.background = _new->core.background_pixel;		gcMask |= (GCForeground | GCBackground);		newErase = TRUE;		redisplay = TRUE;	}	if (FG(_new) != FG(_current))		newSelected = TRUE;	if (CMAP(_new).firstIndex != CMAP(_current).firstIndex)	{		if (CMAP(_new).firstIndex < 0)		{			myXtWarning("CmapWidget: FirstIndex (%d) cannot be negative. FirstIndex set to 0.", 				CMAP(_new).firstIndex);			CMAP(_new).firstIndex = 0;		}		if (CMAP(_new).firstIndex > CMAP(_new).availColors-1)

⌨️ 快捷键说明

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