aboutsummaryrefslogtreecommitdiff
path: root/GraphDisplay.c
blob: 3b0d5827f24a31171588d5828b70da43cbb7b661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* $Id$ */

#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "GraphDisplayP.h"

#define Offset(field) XtOffsetOf(GraphDisplayRec, graphDisplay.field)
static XtResource resources[] = {
	{ XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
		Offset(font), XtRString, (XtPointer)XtDefaultFont },
	{ XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
		Offset(foreground), XtRString, (XtPointer)XtDefaultForeground },
};
#undef Offset

static void ClassPartInitialize();
static void Initialize();
static void Destroy();
static Boolean SetValues();

GraphDisplayClassRec graphDisplayClassRec = {
	.object_class = {
		.superclass		= (WidgetClass)&objectClassRec,
		.class_name		= "GraphDisplay",
		.widget_size		= sizeof(GraphDisplayRec),
		.class_initialize	= NULL,
		.class_part_initialize	= ClassPartInitialize,
		.class_inited		= False,
		.initialize		= Initialize,
		.initialize_hook	= NULL,
		.obj1			= NULL,
		.obj2			= NULL,
		.obj3			= 0,
		.resources		= resources,
		.num_resources		= XtNumber(resources),
		.xrm_class		= NULLQUARK,
		.obj4			= 0,
		.obj5			= 0,
		.obj6			= 0,
		.obj7			= 0,
		.destroy		= Destroy,
		.obj8			= 0,
		.obj9			= 0,
		.set_values		= SetValues,
		.set_values_hook	= NULL,
		.obj10			= NULL,
		.get_values_hook	= NULL,
		.obj11			= NULL,
		.version		= XtVersion,
		.callback_private	= NULL,
		.obj12			= NULL,
		.obj13			= NULL,
		.obj14			= NULL,
		.extension		= NULL,
	},
	.graphDisplay_class = {
		.compute_size		= NULL,
		.expose			= NULL,
		.extension		= NULL,
	},
};

WidgetClass graphDisplayObjectClass = (WidgetClass) &graphDisplayClassRec;

static void
ClassPartInitialize(WidgetClass widgetClass)
{
	GraphDisplayObjectClass wc = (GraphDisplayObjectClass) widgetClass;
	GraphDisplayObjectClass super =
		(GraphDisplayObjectClass) wc->object_class.superclass;

	if (wc->graphDisplay_class.compute_size == InheritComputeSize)
		wc->graphDisplay_class.compute_size =
			super->graphDisplay_class.compute_size;
	if (wc->graphDisplay_class.expose == XtInheritExpose)
		wc->graphDisplay_class.expose =
			super->graphDisplay_class.expose;
}

static GC
GetGC(GraphDisplayObject gd)
{
	XGCValues values;

	values.foreground = gd->graphDisplay.foreground;
	values.font = gd->graphDisplay.font->fid;

	return XtGetGC(XtParent((Widget)gd), GCForeground|GCFont, &values);
}

static void
Initialize(Widget request,
	Widget new,
	ArgList args,
	Cardinal * num_args)
{
	GraphDisplayObject gd = (GraphDisplayObject) new;

	gd->graphDisplay.gc = GetGC(gd);
}

static Boolean
SetValues(Widget old,
	Widget req,
	Widget new,
	ArgList args,
	Cardinal *num_args)
{
	GraphDisplayObject oldgd = (GraphDisplayObject) old;
	GraphDisplayObject newgd = (GraphDisplayObject) new;

#define NE(field)	(newgd->field != oldgd->field)
	if (NE(graphDisplay.foreground) || NE(graphDisplay.font->fid)) {
		XtReleaseGC(new, oldgd->graphDisplay.gc);
		newgd->graphDisplay.gc = GetGC(newgd);
	}
#undef NE

	if (XtIsRealized(XtParent((Widget)newgd)))
		XClearArea(XtDisplayOfObject(new),
			XtWindowOfObject(new), 0, 0, 0, 0, True);
	return False;
}

static void
Destroy(Widget w)
{
	GraphDisplayObject gd = (GraphDisplayObject) w;

	XtReleaseGC(XtParent(w), gd->graphDisplay.gc);
}