home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume10
/
xt-examples
/
part04
/
GraphDispl.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-11-04
|
5KB
|
177 lines
/***********************************************************
Copyright 1990 by Digital Equipment Corporation, Maynard, Massachusetts.
All Rights Reserved
Permission to use, copy, modify, and distribute these examples for any
purpose and without fee is hereby granted, provided that the above
copyright notice appear in all copies and that both that copyright
notice and this permission notice appear in supporting documentation,
and that the name of Digital not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission.
DIGITAL AND THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT
OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
#include <X11/IntrinsicP.h> /* Intrinsics header file */
#include <X11/StringDefs.h> /* Resource string definitions */
#include "GraphDispP.h" /* Graph display object */
#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
/* Forward declarations */
static void ClassPartInitialize(), Initialize(), Destroy();
static Boolean SetValues();
/* Class record declaration */
GraphDisplayClassRec graphDisplayClassRec = {
/* Object class part */
{
/* 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 */ NULL,
/* obj9 */ NULL,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* obj10 */ NULL,
/* get_values_hook */ NULL,
/* obj11 */ NULL,
/* version */ XtVersion,
/* callback offsets */ NULL,
/* obj12 */ NULL,
/* obj13 */ NULL,
/* obj14 */ NULL,
/* extension */ NULL
},
/* GraphDisplay class part */
{
/* compute_size */ NULL,
/* expose */ NULL,
/* extension */ NULL
}
};
/* Class record pointer */
WidgetClass graphDisplayObjectClass =
(WidgetClass) &graphDisplayClassRec;
static void ClassPartInitialize(widgetClass)
WidgetClass widgetClass;
{
register 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(gd)
GraphDisplayObject gd;
{
XGCValues values;
/* Allocate a graphics context with the foreground and font */
values.foreground = gd->graphDisplay.foreground;
values.font = gd->graphDisplay.font->fid;
return XtGetGC(XtParent((Widget) gd),
GCForeground | GCFont, &values);
}
static void Initialize(request, new, args, num_args)
Widget request, new;
ArgList args;
Cardinal *num_args;
{
GraphDisplayObject gd = (GraphDisplayObject) new;
/* Get a graphics context */
gd->graphDisplay.gc = GetGC(gd);
}
static Boolean SetValues(old, request, new, args, num_args)
Widget old, request, new;
ArgList args;
Cardinal *num_args;
{
GraphDisplayObject oldgd = (GraphDisplayObject) old;
GraphDisplayObject newgd = (GraphDisplayObject) new;
#define NE(field) (oldgd->field != newgd->field)
/* If foreground or font has changed, update GC */
if (NE(graphDisplay.foreground) || NE(graphDisplay.font->fid)) {
XtReleaseGC(newgd, oldgd->graphDisplay.gc);
newgd->graphDisplay.gc = GetGC(newgd);
/* Kludge. There's no way to tell the Intrinsics to
automatically redisplay, so clear the parent, causing
expose events. Subclasses will do this too, but multiple
redisplays are avoided since the parent has
XtExposeCompressMultiple. */
if (XtIsRealized(XtParent((Widget) newgd))) {
XClearArea(XtDisplayOfObject(newgd),
XtWindowOfObject(newgd), 0, 0, 0, 0, TRUE);
}
}
return FALSE;
#undef NE
}
static void Destroy(w)
Widget w;
{
GraphDisplayObject gd = (GraphDisplayObject) w;
XtReleaseGC(XtParent(w), gd->graphDisplay.gc);
}