📄 list_16_17.c
字号:
/************************************************************************* **** listing_16_17.c **** **** String-to-UnitType converter. This program shows an example of **** quarks in use. **** *************************************************************************/#include <Xm/Label.h>void CvtStringToUnitType(); /* FORWARD Definition */Widget appshell, /* Application Shell */ a_label, /* Dummy label */ the_label; /* The only true label */void main( argc, argv ) int argc; char *argv[];{ appshell = XtInitialize( argv[0], "Listing_16_17", NULL, 0, &argc, argv ); a_label = XmCreateLabel( appshell, "ALabel", NULL, 0 ); XtDestroyWidget( a_label ); XtAddConverter( XmRString, XmRUnitType, CvtStringToUnitType, NULL, 0 ); the_label = XmCreateLabel( appshell, "TheLabel", NULL, 0 ); XtManageChild( the_label ); XtRealizeWidget( appshell ); XtMainLoop();}/***** CvtStringToUnitType( args, num_args, from, to )****** Converts "String" data (NUL-terminated ASCII strings) to *** UnitType data. Recognizes five unit-type specifications:*** PIXELS, 100TH_MILLIMETERS, 1000TH_INCHES, 100TH_POINTS,*** and 100TH_FONT_UNITS. *** Does not recognize any spellings other than those listed.**/void CvtStringToUnitType( args, num_args, from, to ) XrmValue *args; Cardinal *num_args; XrmValue *from; XrmValue *to;{ static unsigned char val; static Boolean inited = FALSE; static XrmQuark q_pixel, q_mm, q_inch, q_pt, q_font; XrmQuark the_val; if (!inited) { inited = TRUE; q_pixel = XrmStringToQuark( "PIXELS" ); q_mm = XrmStringToQuark( "100TH_MILLIMETERS" ); q_inch = XrmStringToQuark( "1000TH_INCHES" ); q_pt = XrmStringToQuark( "100TH_POINTS" ); q_font = XrmStringToQuark( "100TH_FONT_UNITS" ); } the_val = XrmStringToQuark( (char*)from->addr ); if (the_val == q_pixel) val = XmPIXELS; else if (the_val == q_mm) val = Xm100TH_MILLIMETERS; else if (the_val == q_inch) val = Xm1000TH_INCHES; else if (the_val == q_pt) val = Xm100TH_POINTS; else if (the_val == q_font) val = Xm100TH_FONT_UNITS; else { val = XmPIXELS; XtStringConversionWarning( (char*)from->addr, "UnitType" ); } to->addr = (caddr_t)&val; to->size = sizeof(unsigned char);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -