📄 liteclue.c
字号:
/* LiteClue.c - LiteClue widget See LiteClue documentation Version 1.5Copyright 1996 COMPUTER GENERATION, INC.,The software is provided "as is", without warranty of any kind, expressor implied, including but not limited to the warranties ofmerchantability, fitness for a particular purpose and noninfringement.In no event shall Computer Generation, inc. nor the author be liable forany claim, damages or other liability, whether in an action of contract,tort or otherwise, arising from, out of or in connection with thesoftware or the use or other dealings in the software.Permission to use, copy, modify, and distribute this software and itsdocumentation for any purpose and without fee is hereby granted,provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear insupporting documentation.Author:Gary Aviv Computer Generation, Inc.,gary@compgen.comwww.compgen.com/widgetsThanks to Contributers:J SatchellEric MarttilaAddy Klos*//* Revision History:$Log: LiteClue.c,v $Revision 1.1 2001/02/20 20:29:59 daservisMakefiles and movement for configure scriptsRevision 1.1 2000/08/20 04:47:58 bforsbergAdd mixing class and made several fixesRevision 1.16 1998/09/07 14:06:19 garyAdded const to prototype of XcgLiteClueAddWidget at request from userRevision 1.15 1998/07/30 16:05:16 garyAdd NO_FONT_SET to usr FontStruct rather than FontSetRevision 1.14 1998/01/06 15:30:33 garyIf font specified by resource can not be converted, use fixedfont as fallback. If no font at all can be converted, preventcrash, just disable widget entirely.Revision 1.13 1997/07/07 14:55:04 garyCancel timeouts when XcgLiteClueDeleteWidget is called to preventerrant timeout event on deleted widget.Revision 1.12 1997/06/20 20:09:09 garyAdd XcgLiteClueDispatchEvent to enable clues for insensitive widgets.Revision 1.11 1997/06/15 14:10:24 garyAdd XcgLiteClueDispatchEvent to enable clues for insensitive widgets.Revision 1.10 1997/04/14 13:02:33 garyAttempt to fix problem when we get multiple enter events bu no leave event.Revision 1.9 1997/03/10 14:42:41 garyAttempt to fix problem when we get multiple enter events bu no leave event.Add C++ wrapper to allow linking with C++ programs. (In HView.h)Revision 1.8 1997/01/17 13:44:14 garySupport of cancelWaitPeriod resource: this is a period from the pointa help popdown occurs in which the normal waitPeriod is suspendedfor the next popupRevision 1.7 1996/12/16 22:35:38 garyFix double entry problemRevision 1.6 1996/11/18 14:52:21 garyremove some compile warnings pointed out by a userRevision 1.5 1996/11/12 20:56:43 garyremove some compile warningsRevision 1.4 1996/10/20 13:38:16 garyVersion 1.2 freezeRevision 1.3 1996/10/19 16:16:30 garyCompile warning removed with castRevision 1.2 1996/10/19 16:07:38 garya) R4 back compatibilityb) Delay before pop up of help, waitPeriod resource (def 500 ms). Thanks to J Satchell for this.c) Button press in watched widget pops down helpRevision 1.1 1996/10/18 23:14:58 garyInitial$logRemapping of clue added when clue is displayed off screen.$log*/#include <unistd.h>#include <signal.h>/* #include <Xm/XmP.h> */#include <X11/IntrinsicP.h> #include <X11/StringDefs.h>#include "LiteClueP.h"#include <stdio.h>#define CheckWidgetClass(routine) \ if (XtClass(w) != xcgLiteClueWidgetClass) \ wrong_widget(routine)static Boolean setValues( Widget _current, Widget _request, Widget _new, ArgList args, Cardinal * num_args);static void Initialize(Widget treq, Widget tnew, ArgList args, Cardinal *num_args);struct liteClue_context_str * alloc_liteClue_context(void);/* keep information about each widget we are keeping track of */struct liteClue_context_str{ ListThread next; /* next in list */ Widget watched_w; /* the widget we are watching */ XcgLiteClueWidget cw; /* pointer back to the liteClue widget */ Position abs_x, abs_y; Boolean sensitive; /* if False, liteClue is suppressed */ char * text; /* text to display */ short text_size; /* its size */};void free_widget_context(XcgLiteClueWidget cw, struct liteClue_context_str * obj);/*Widget resources: eg to set LiteClue box background: *XcgLiteClue.background: yellow */#define offset(field) XtOffsetOf(LiteClueRec, field)static XtResource LC_resources[] ={ {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), offset(liteClue.foreground), XtRString, "black"},#if XtSpecificationRelease < 5 || defined(NO_FONT_SET) {XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *), offset(liteClue.fontset), XtRString, "-adobe-new century schoolbook-bold-r-normal-*-14-*-*-*-*-*-*-*"},#else {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet), offset(liteClue.fontset), XtRString, "-adobe-new century schoolbook-bold-r-normal-*-12-*"},#endif {XgcNwaitPeriod, XgcCWaitPeriod, XtRInt , sizeof(int), offset(liteClue.waitPeriod),XtRString, "500" }, {XgcNcancelWaitPeriod, XgcCCancelWaitPeriod, XtRInt , sizeof(int), offset(liteClue.cancelWaitPeriod),XtRString, "2000" },};#undef offset#if 0static XtActionsRec actions[] = }; /* actions */#endifLiteClueClassRec xcgLiteClueClassRec ={ { (WidgetClass)&overrideShellClassRec, /* superclass */ "XcgLiteClue", /* class_name */ (Cardinal)sizeof(LiteClueRec), /* widget size */ NULL, /* class_init */ (XtWidgetClassProc)NULL, /* class_part_init */ (XtEnum)FALSE, /* class_inited */ (XtInitProc)Initialize, /* initialize */ (XtArgsProc)NULL, /* init_hook */ XtInheritRealize, /* realize */ (XtActionList)0, /* actions */ (Cardinal)0, /* num_actions */ (XtResourceList)LC_resources, /* resources */ (Cardinal)XtNumber(LC_resources), /* num_resources */ NULLQUARK, /* xrm_class */ TRUE, /* compress_motion */ (XtEnum)FALSE, /* compress_exposur */ TRUE, /* compress enterleave */ FALSE, /* visibility_interest */ (XtWidgetProc)NULL, /* destroy */ XtInheritResize, XtInheritExpose, /* expose, */ (XtSetValuesFunc)setValues, /* set_values */ (XtArgsFunc)NULL, /* set_values_hook */ XtInheritSetValuesAlmost, /* set_values_almost */ (XtArgsProc)NULL, /* get_values_hook */ XtInheritAcceptFocus, /* accept_focus */ XtVersion, /* version */ (XtPointer)NULL, /* callback_private */ XtInheritTranslations, XtInheritQueryGeometry, /* query_geometry */ XtInheritDisplayAccelerator, /* display_accelerator */ (XtPointer)0, /* extension */ }, { /*** composite-Class ***/ XtInheritGeometryManager, /* geometry_manager */ XtInheritChangeManaged, /* change_managed */ XtInheritInsertChild, /* insert_child */ XtInheritDeleteChild, /* delete_child */ NULL /* extension */ }, { /* Shell */ (XtPointer) NULL, /* pointer to extension record */ }, /* Override Shell */ { 0, }, /* LiteClue */ { 0, },};WidgetClass xcgLiteClueWidgetClass = (WidgetClass) & xcgLiteClueClassRec;/* doubly linked list processing *//* initialize header - both pointers point to it*/static void xcgListInit(ListThread *newbuf){ newbuf->back = newbuf; newbuf->forw = newbuf;}/* insert newbuf before posbuf*/static void xcgListInsertBefore(ListThread *newlist, ListThread *poslist){ ListThread *prevbuf; prevbuf = poslist->back; poslist->back = newlist; newlist->forw = poslist; newlist->back = prevbuf; prevbuf->forw = newlist;}/* remove rembuf from queue*/static ListThread * xcgListRemove(ListThread *rembuf){ ListThread *prevbuf, *nextbuf; prevbuf = rembuf->back; nextbuf = rembuf->forw; prevbuf->forw = nextbuf; nextbuf->back = prevbuf; rembuf->back = (ListThread *) NULL; /* for safety to cause trap if ..*/ rembuf->forw = (ListThread *) NULL; /* .. mistakenly refed */ return rembuf;}/*The font_information is derived */#if XtSpecificationRelease < 5 || defined(NO_FONT_SET)/* R4 and below code *//*Return XFontSet for passed font_string. return status*/static int string_to_FontSet (XcgLiteClueWidget cw, char * font_string, XFontStruct ** out) { Boolean sts; XrmValue from; XrmValue to; to.size = sizeof(out); to.addr = (void *) out; from.size = strlen(from.addr = font_string ); sts = XtConvertAndStore((Widget) cw, XtRString, &from, XtRFontStruct, &to); return sts;}static void compute_font_info(XcgLiteClueWidget cw){ int direction_return; int font_ascent_return, font_descent_return; XCharStruct oret; if (!cw->liteClue.fontset) string_to_FontSet(cw, "fixed", &cw->liteClue.fontset) ; if (!cw->liteClue.fontset) { fprintf(stderr,"LiteClue: can not find resource font nor fallback fixed font\n"); return; } XTextExtents( cw->liteClue.fontset, "1", 1, &direction_return, &font_ascent_return, &font_descent_return, &oret); cw->liteClue.font_baseline = oret.ascent; /* y offset from top to baseline, don't know why this is returned as negative */ cw->liteClue.font_width = oret.width; /* the width and height of the object */ cw->liteClue.font_height = oret.ascent+oret.descent;}#else/*Return XFontSet for passed font_string. return status*/static int string_to_FontSet (XcgLiteClueWidget cw, char * font_string, XFontSet * out) { Boolean sts; XrmValue from; XrmValue to; to.size = sizeof(out); to.addr = (void *) out; from.size = strlen(from.addr = font_string ); sts = XtConvertAndStore((Widget) cw, XtRString, &from, XtRFontSet, &to); return sts;}/* R5 and above code */static void compute_font_info(XcgLiteClueWidget cw){ XRectangle ink; XRectangle logical; if (!cw->liteClue.fontset) string_to_FontSet(cw, "fixed", &cw->liteClue.fontset) ; if (!cw->liteClue.fontset) { fprintf(stderr,"LiteClue: can not find resource font nor fallback fixed font\n"); return; } XmbTextExtents(cw->liteClue.fontset, "1", 1,&ink, &logical); cw->liteClue.font_baseline = -logical.y; /* y offset from top to baseline, don't know why this is returned as negative */ cw->liteClue.font_width = logical.width; /* the width and height of the object */ cw->liteClue.font_height = logical.height;}#endif/* Creates the various graphic contexts we will need */static void create_GC(XcgLiteClueWidget cw ){ XtGCMask valuemask; XGCValues myXGCV; valuemask = GCForeground | GCBackground | GCFillStyle ; myXGCV.foreground = cw->liteClue.foreground; myXGCV.background = cw->core.background_pixel; myXGCV.fill_style = FillSolid; #if XtSpecificationRelease < 5 || defined(NO_FONT_SET) valuemask |= GCFont ; myXGCV.font = cw->liteClue.fontset->fid; #endif /* end R4 hack */ if (cw->liteClue.text_GC ) XtReleaseGC((Widget) cw, cw->liteClue.text_GC ); cw->liteClue.text_GC = XtGetGC((Widget)cw, valuemask, &myXGCV);}/* a routine to halt execution and force a core dump for debugging analysis when a public routine is called with the wrong class of widget*/static void wrong_widget(char * routine){ int mypid = getpid(); fprintf(stderr, "Wrong class of widget passed to %s\n", routine); fflush(stderr); kill(mypid, SIGABRT); }/*Find the target in the widget list. Return context pointer if found,NULL if not*/static struct liteClue_context_str * find_watched_widget(XcgLiteClueWidget cw, Widget target){ struct liteClue_context_str * obj; for (obj = (struct liteClue_context_str *) cw->liteClue.widget_list.forw; obj != (struct liteClue_context_str *) & cw->liteClue.widget_list; obj = (struct liteClue_context_str *)obj->next.forw ) { if (target == obj->watched_w) return obj; } return NULL;}/* allocate and initialize a widget context*/struct liteClue_context_str * alloc_liteClue_context(void){ struct liteClue_context_str * out; out = (struct liteClue_context_str *) XtMalloc(sizeof(struct liteClue_context_str)); memset(out, 0, sizeof(struct liteClue_context_str)); xcgListInit(&out->next); return out ;}/* allocate, initialize and link a liteClue context to the list*/static struct liteClue_context_str * alloc_link_liteClue_context(XcgLiteClueWidget cw ){ struct liteClue_context_str * out = alloc_liteClue_context(); /* link as new last */ xcgListInsertBefore(&out->next, &cw->liteClue.widget_list); out->cw = cw; /* initialize this emeber - its always the same */ return out;}/* free a widget context*/void free_widget_context(XcgLiteClueWidget cw, struct liteClue_context_str * obj){ xcgListRemove((ListThread *)obj); /* free up all things object points to */ obj->sensitive = False; if (obj->text ) XtFree(obj->text); XtFree((char *) obj);}/* -------------------- Widget Methods ---------------------- *//* Initialize method */static void Initialize(Widget treq, Widget tnew, ArgList args, Cardinal *num_args){ XcgLiteClueWidget cw = (XcgLiteClueWidget) tnew; cw->liteClue.text_GC = NULL; cw->liteClue.HelpIsUp = False;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -