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

📄 spinbutton.c

📁 安装DDD之前
💻 C
📖 第 1 页 / 共 5 页
字号:
/* * SpinButton.c, Interleaf, 16aug93 2:37pm Version 1.1. *//***********************************************************Copyright 1993 Interleaf, Inc.Permission to use, copy, modify, and distribute this softwareand its documentation for any purpose without fee is granted,provided that the above copyright notice appear in all copiesand that both copyright notice and this permission notice appearin supporting documentation, and that the name of Interleaf notbe used in advertising or publicly pertaining to distribution ofthe software without specific written prior permission.Interleaf makes no representation about the suitability of thissoftware for any purpose. It is provided "AS IS" without anyexpress or implied warranty. ******************************************************************//* * (C) Copyright 1991,1992, 1993 * Interleaf, Inc. * 9 Hillside Avenue,  * Waltham, MA  02154 * * SpinButton.c (DtSpinButtonWidget): * * I wanted a margin around the widget (outside the shadow, like buttons),  * so that the spin-button could be made the smae size as a  * push-button, etc.  The bulletin-board widget always puts the shadow at  * the outside edge of the widget, so spin-button is a sublcass of * manager, and we do everything ourselves. *  * One must be carefull when using Dimension (for core width and height). * Dimension is an unsigned short.  This causes problems when subtracting * and ending up with what should be a negative number (but it doesn't). * All child widget positioning is done by the spin_button.  We don't * use any heavy-weight forms, etc. to help us out. *  * There is no padding when editable.  If using a label, give it a * small margin, so it doesn't run up against the side of our * shadow or the arrow. * * Make some of the SpinButton functions common, so they can be shared * with ComboBox. * * Known bugs: *	    Changing margin_width or margin_height resources when the *	    spin_button has focus will probably result in display glitches. */#include <stdio.h>#include "SpinButtonP.h"static void	ClassInitialize AA(());static void	Initialize AA((DtSpinButtonWidget request, 			       DtSpinButtonWidget new, ArgList given_args, 			       Cardinal *num_args));static XmNavigability WidgetNavigable AA((DtSpinButtonWidget spin));static void	_SpinButtonFocusIn AA((DtSpinButtonWidget spin, XEvent *event, 				       char **params, Cardinal *num_params));static void	_SpinButtonFocusOut AA((DtSpinButtonWidget spin, XEvent *event,					char **params, Cardinal *num_params));static void	DrawHighlight AA((DtSpinButtonWidget spin, Boolean clear));static void	_SpinButtonUp AA((DtSpinButtonWidget spin, 				  XEvent *event, char **params, 				  Cardinal *num_params));static void	_SpinButtonDown AA((DtSpinButtonWidget spin, 				    XEvent *event, char **params, 				    Cardinal *num_params));static void	_SpinButtonLeft AA((DtSpinButtonWidget spin, 				    XEvent *event, char **params, 				    Cardinal *num_params));static void	_SpinButtonRight AA((DtSpinButtonWidget spin, 				     XEvent *event, char **params, 				     Cardinal *num_params));static void	_SpinButtonBeginLine AA((DtSpinButtonWidget spin, 					 XEvent *event, char **params, 					 Cardinal *num_params));static void	_SpinButtonEndLine AA((DtSpinButtonWidget spin, 				       XEvent *event, char **params, 				       Cardinal *num_params));static void	CheckResources AA((DtSpinButtonWidget spin));static void	Destroy AA((DtSpinButtonWidget spin));static void	Resize AA((DtSpinButtonWidget spin));static void	Redisplay AA((DtSpinButtonWidget w, XEvent *event, 			      Region region));static XtGeometryResult GeometryManager AA((Widget w, 					    XtWidgetGeometry *request, 					    XtWidgetGeometry *reply));static void	SetSpinButtonSize AA((DtSpinButtonWidget spin));static void	ForceChildSizes AA((DtSpinButtonWidget spin));static void	LayoutChildren AA((DtSpinButtonWidget spin));static Boolean	SetValues AA((DtSpinButtonWidget current, 			      DtSpinButtonWidget request, 			      DtSpinButtonWidget new));static void	ClearShadow AA((DtSpinButtonWidget w, Boolean all));static void	DrawShadow AA((DtSpinButtonWidget w));static void	StoreResourceInfo AA((DtSpinButtonPart *spin_p,				      DtSpinButtonPart *old_p,				      Boolean do_items));static char*	GetTextString AA((XmString xm_string));static void	SetTextFieldData AA((DtSpinButtonWidget spin));static void	SetMaximumLabelSize AA((DtSpinButtonPart *spin_p));static void	SetLabelData AA((DtSpinButtonWidget spin));static void	timer_dispatch AA((XtPointer client_data, XtIntervalId *id));static void	TextFieldActivate AA((DtSpinButtonPart *spin_p));static Boolean	SendCallback AA((DtSpinButtonWidget spin, XEvent *event,				 Boolean value_changed, int position,				 float current, Boolean crossed));static void	FinishUpDown AA((DtSpinButtonWidget spin, 				 XtPointer arrow_call_data, int new_position,				 float new_current, Boolean crossed));static void	up_cb AA((Widget w, XtPointer client_data, 			  XtPointer call_data));static void	down_cb AA((Widget w, XtPointer client_data, 			    XtPointer call_data));static void	disarm_cb AA((Widget w, XtPointer client_data, 			      XtPointer call_data));static void	grab_leave_cb AA((Widget w, XtPointer client_data, 				  Event *event, Boolean *dispatch));static void	text_losing_focus_cb AA((Widget w, XtPointer client_data,					 XtPointer call_data));static void	text_activate_cb AA((Widget w, XtPointer client_data,				     XtPointer call_data));static void	text_focus_cb AA((Widget w, XtPointer client_data,				  XtPointer call_data));static XmImportOperator _XmSetSyntheticResForChild AA((Widget widget,						       int offset, 						       XtArgVal * value));static XmString InitLabel = NULL;static XtTranslations child_trans;XtTranslations spin_trans;#define SPIN_SHADOW(w)	    w->manager.shadow_thickness#define SPIN_MARGIN_W(w)    w->spin_button.margin_width#define SPIN_MARGIN_H(w)    w->spin_button.margin_height#define MAXINT 2147483647  /* Taken from TextF.c *//* Only need one timer for all widget instances */static XtIntervalId timer;static char SpinButtonTranslationTable[] = "\	<FocusIn>:		SpinButtonFocusIn() \n\	<FocusOut>:		SpinButtonFocusOut() \n\        <Key>osfUp:		SpinButtonUp() \n\        <Key>osfDown:		SpinButtonDown() \n\        <Key>osfRight:		SpinButtonRight() \n\        <Key>osfLeft:		SpinButtonLeft() \n\        <Key>osfBeginLine:	SpinButtonBeginLine() \n\        <Key>osfEndLine:	SpinButtonEndLine() \n\";static char SpinButtonChildTranslationTable[] = "\        <Key>osfUp:		SpinButtonUp(child) \n\        <Key>osfDown:		SpinButtonDown(child) \n\        <Key>osfRight:		SpinButtonRight(child) \n\        <Key>osfLeft:		SpinButtonLeft(child) \n\        <Key>osfBeginLine:	SpinButtonBeginLine(child) \n\        <Key>osfEndLine:	SpinButtonEndLine(child) \n\";static XtActionsRec SpinButtonActionTable[] = {       {"SpinButtonFocusIn",	(XtActionProc)_SpinButtonFocusIn},       {"SpinButtonFocusOut",	(XtActionProc)_SpinButtonFocusOut},       {"SpinButtonUp",		(XtActionProc)_SpinButtonUp},       {"SpinButtonDown",	(XtActionProc)_SpinButtonDown},       {"SpinButtonRight",	(XtActionProc)_SpinButtonRight},       {"SpinButtonLeft",	(XtActionProc)_SpinButtonLeft},       {"SpinButtonBeginLine",	(XtActionProc)_SpinButtonBeginLine},       {"SpinButtonEndLine",	(XtActionProc)_SpinButtonEndLine},};/* DtSpinButtonWidget resources */#define offset(field) XtOffset(DtSpinButtonWidget, field)static XtResource resources[] = {    {XmNshadowThickness, XmCShadowThickness, XmRHorizontalDimension, 	 sizeof(Dimension), offset(manager.shadow_thickness),	 XmRImmediate, (XtPointer)TEXT_FIELD_SHADOW},    /* Common resources */    {XmNactivateCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),	 offset(spin_button.activate_callback), XmRCallback, 	 (XtPointer)NULL},    {XmNalignment, XmCAlignment, XmRAlignment, sizeof(unsigned char),	 offset(spin_button.alignment), XmRImmediate, 	 (XtPointer)XmALIGNMENT_BEGINNING},    {XmNarrowLayout, XmCArrowLayout, XmRArrowLayout, sizeof(unsigned char),	 offset(spin_button.arrow_layout), XmRImmediate, 	 (XtPointer)XmARROWS_BEGINNING},    {XmNarrowSensitivity, XmCArrowSensitivity, XmRArrowSensitivity,	 sizeof(unsigned char), offset(spin_button.arrow_sensitivity),	 XmRImmediate, (XtPointer)XmARROWS_SENSITIVE},    {XmNchildType, XmCChildType, XmRChildType, sizeof(unsigned char),	 offset(spin_button.child_type), XmRImmediate, (XtPointer)XmSTRING},    {XmNcolumns, XmCColumns, XmRShort, sizeof(short),	 offset(spin_button.text_columns), XmRImmediate, (XtPointer)20},    {XmNdecimalPoints, XmCDecimalPoints, XmRInt, sizeof(unsigned int),	 offset(spin_button.decimal_points), XmRImmediate, (XtPointer)0},    {XmNeditable, XmCEditable, XmRBoolean, sizeof(Boolean),	 offset(spin_button.editable), XmRImmediate, (XtPointer)TRUE},    {XmNfocusCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),	 offset(spin_button.focus_callback), XmRCallback, 	 (XtPointer)NULL},    {XmNincrement, XmCIncrement, XmRInt, sizeof(int),	 offset(spin_button.numeric_increment), XmRImmediate, (XtPointer)1},    {XmNinitialDelay, XmCInitialDelay, XmRInt, sizeof(unsigned int),	 offset(spin_button.initial_delay), XmRImmediate, (XtPointer)250},    {XmNitemCount, XmCItemCount, XmRInt, sizeof(unsigned int),	 offset(spin_button.item_count), XmRImmediate, (XtPointer)0},    {XmNitems, XmCItems, XmRXmStringTable, sizeof(XmStringTable),	 offset(spin_button.items), XmRImmediate, (XtPointer)NULL},    {XmNlosingFocusCallback, XmCCallback, XmRCallback, sizeof(XtCallbackList),	 offset(spin_button.losing_focus_callback), XmRCallback, 	 (XtPointer)NULL},    {XmNmarginHeight, XmCMarginHeight, XmRVerticalDimension, sizeof(Dimension),	 offset(spin_button.margin_height), XmRImmediate, (XtPointer)MARGIN},    {XmNmarginWidth, XmCMarginWidth, XmRHorizontalDimension, sizeof(Dimension),	 offset(spin_button.margin_width), XmRImmediate, (XtPointer)MARGIN},    {XmNmaximum, XmCMaximum, XmRInt, sizeof(int), 	 offset(spin_button.maximum), XmRImmediate, (XtPointer)1},    {XmNmaxLength, XmCMaxLength, XmRInt, sizeof(int),	 offset(spin_button.text_max_length), XmRImmediate, (XtPointer)MAXINT},    {XmNminimum, XmCMinimum, XmRInt, sizeof(int), 	 offset(spin_button.minimum), XmRImmediate, (XtPointer)0},    {XmNmodifyVerifyCallback, XmCCallback, XmRCallback, 	 sizeof(XtCallbackList), offset(spin_button.modify_verify_callback),	 XmRCallback, (XtPointer)NULL},    {XmNposition, XmCPosition, XmRInt, sizeof(unsigned int),	 offset(spin_button.position), XmRImmediate, (XtPointer)0},    {XmNrecomputeSize, XmCRecomputeSize, XmRBoolean, sizeof(Boolean),	 offset(spin_button.recompute_size), XmRImmediate, (XtPointer)TRUE},    {XmNrepeatDelay, XmCRepeatDelay, XmRInt, sizeof(unsigned int),	 offset(spin_button.repeat_delay), XmRImmediate, (XtPointer)200},    {XmNtextField, XmCTextField, XmRWidget, sizeof(Widget),	 offset(spin_button.text), XmRImmediate, (XtPointer)NULL},    {XmNvalueChangedCallback, XmCCallback, XmRCallback, 	 sizeof(XtCallbackList), offset(spin_button.value_changed_callback),	 XmRCallback, (XtPointer)NULL},    {XmNwrap, XmCWrap, XmRBoolean, sizeof(Boolean),	 offset(spin_button.wrap), XmRImmediate, (XtPointer)TRUE},};/* Synthetic resources.  Only used for Motif API arrowSize right now */static XmSyntheticResource syn_resources[] = {    {XmNarrowSize, sizeof(Dimension), offset(spin_button.arrow_size), 	 _DtSpinButtonGetArrowSize, _XmSetSyntheticResForChild},};#undef offset/* Need Class Extension for widget navigation */static XmBaseClassExtRec baseClassExtRec = {    NULL,    NULLQUARK,    XmBaseClassExtVersion,    sizeof(XmBaseClassExtRec),    (XtInitProc)NULL,			/* InitializePrehook	*/    (XtSetValuesFunc)NULL,		/* SetValuesPrehook	*/    (XtInitProc)NULL,			/* InitializePosthook	*/    (XtSetValuesFunc)NULL,		/* SetValuesPosthook	*/    NULL,				/* secondaryObjectClass	*/    (XtInitProc)NULL,			/* secondaryCreate	*/    (XmGetSecResDataFunc)NULL, 		/* getSecRes data	*/    { 0 },      			/* fastSubclass flags	*/    (XtArgsProc)NULL,			/* getValuesPrehook	*/    (XtArgsProc)NULL,			/* getValuesPosthook	*/    (XtWidgetClassProc)NULL,            /* classPartInitPrehook */    (XtWidgetClassProc)NULL,            /* classPartInitPosthook*/    NULL,                               /* ext_resources        */    NULL,                               /* compiled_ext_resources*/    0,                                  /* num_ext_resources    */    FALSE,                              /* use_sub_resources    */    WidgetNavigable,                    /* widgetNavigable      */    (XmFocusChangeProc)NULL,            /* focusChange          */    (XmWrapperData)NULL			/* wrapperData 		*/};/* * Define Class Record. */DtSpinButtonClassRec dtSpinButtonClassRec ={    {		/* core_class fields      */    (WidgetClass)&(xmManagerClassRec),		/* superclass         */        (String)"DtSpinButton",			/* class_name         */        (Cardinal)sizeof(DtSpinButtonRec),		/* widget_size        */        (XtProc)ClassInitialize,			/* class_initialize   */        (XtWidgetClassProc)NULL,			/* class_part_init    */        (XtEnum)FALSE,				/* class_inited       */        (XtInitProc)Initialize,			/* initialize         */        (XtArgsProc)NULL,				/* initialize_hook    */        (XtRealizeProc)XtInheritRealize,		/* realize            */        (XtActionList)SpinButtonActionTable,	/* actions	       */        (Cardinal)XtNumber(SpinButtonActionTable),	/* num_actions        */        (XtResourceList)resources,			/* resources          */        (Cardinal)XtNumber(resources),		/* num_resources      */        (XrmClass)NULLQUARK,			/* xrm_class          */        (Boolean)TRUE,				/* compress_motion    */        (XtEnum)XtExposeCompressMaximal,		/* compress_exposure  */        (Boolean)TRUE,				/* compress_enterleave*/        (Boolean)FALSE,				/* visible_interest   */        (XtWidgetProc)Destroy,			/* destroy            */        (XtWidgetProc)Resize,			/* resize             */        (XtExposeProc)Redisplay,			/* expose             */        (XtSetValuesFunc)SetValues,			/* set_values         */        (XtArgsFunc)NULL,				/* set values hook    */        (XtAlmostProc)XtInheritSetValuesAlmost,	/* set values almost  */        (XtArgsProc)NULL,				/* get values hook    */        (XtAcceptFocusProc)NULL,			/* accept_focus       */        (XtVersionType)XtVersion,			/* Version            */        (XtPointer)NULL,				/* PRIVATE cb list    */    (String)XtInheritTranslations,		/* tm_table           */    (XtGeometryHandler)XtInheritQueryGeometry,	/* query_geom         */    (XtStringProc)XtInheritDisplayAccelerator,	/* display_accelerator*/    (XtPointer)&baseClassExtRec			/* extension	      */    },    {		/* composite_class fields */    (XtGeometryHandler)GeometryManager,		/* geometry_manager   */         (XtWidgetProc)XtInheritChangeManaged,	/* change_managed     */         (XtWidgetProc)XtInheritInsertChild,		/* insert_child	      */         (XtWidgetProc)XtInheritDeleteChild,		/* delete_child	      */         (XtPointer)NULL				/* extension	      */         },    {		/* constraint_class fields */    (XtResourceList)NULL,			/* resources	      */         (Cardinal)0,				/* num_resources      */         (Cardinal)0,				/* constraint_size    */         (XtInitProc)NULL,				/* initialize	      */         (XtWidgetProc)NULL,				/* destroy	      */         (XtSetValuesFunc)NULL,			/* set_values	      */         (XtPointer)NULL				/* extension          */         },    {		/* manager class     */    (String)XtInheritTranslations,		/* translations       */         (XmSyntheticResource*)syn_resources,	/* syn resources      */         (int)XtNumber(syn_resources),		/* num syn_resources  */         (XmSyntheticResource*)NULL,			/* get_cont_resources */         (int)0,					/* num_get_cont_resources */     (XmParentProcessProc)XmInheritParentProcess,/* parent_process     */         (XtPointer)NULL				/* extension          */         },    {		/* spin_button_class fields */         (Boolean)0,    }};WidgetClass dtSpinButtonWidgetClass = (WidgetClass)&dtSpinButtonClassRec;/*  * Must set up the record type for the class extensions to work. */static voidClassInitialize(){    baseClassExtRec.record_type = XmQmotif;    child_trans = XtParseTranslationTable(SpinButtonChildTranslationTable);    spin_trans = XtParseTranslationTable(SpinButtonTranslationTable);}/* * SpinButton initialization function.  This builds the widgets inside * our widget, to get the correct layout.  If the editable resource * is TRUE, we create a textField; if FALSE, we create a label.  If the * user changes this resource later, we will create the other widget * (textField or Label).  We don't want to carry backage from both * widgets if the user never changes the editable resource. */static voidInitialize(request, new, given_args, num_args)DtSpinButtonWidget request;DtSpinButtonWidget new;ArgList given_args;Cardinal *num_args;{    DtSpinButtonPart *spin_p = (DtSpinButtonPart*)&(new->spin_button);    char *widget_name;    Arg args[20];    int n;    /* Overwrite the manager's focusIn and focusOut translations */    XtOverrideTranslations((Widget)new, spin_trans);

⌨️ 快捷键说明

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