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

📄 spinbutton.c

📁 安装DDD之前
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (InitLabel == NULL)	InitLabel = XmStringCreateSimple("SpinButton");    widget_name = XtMalloc(strlen(XtName(new)) + 10);    spin_p->text = (Widget)NULL;    spin_p->label = (Widget)NULL;    spin_p->old_width = 0;    spin_p->old_height = 0;    spin_p->init_cb = TRUE;    spin_p->grabbed = FALSE;    CheckResources(new);    /*     * Create the text or label depending on editable resource.     */    if (spin_p->editable) {	sprintf(widget_name, "%s_TF", XtName(new));	n = 0;	XtSetArg(args[n], XmNcolumns, spin_p->text_columns); n++;	XtSetArg(args[n], XmNmaxLength, spin_p->text_max_length); n++;	XtSetArg(args[n], XmNmarginWidth, 2); n++;	XtSetArg(args[n], XmNmarginHeight, 2); n++;	spin_p->text = XtCreateManagedWidget(widget_name,					     xmTextFieldWidgetClass,					     (Widget)new, args, n);	XtAddCallback(spin_p->text, XmNlosingFocusCallback, 		      text_losing_focus_cb, (XtPointer)new);	XtAddCallback(spin_p->text, XmNactivateCallback, 		      text_activate_cb, (XtPointer)new);	XtAddCallback(spin_p->text, XmNfocusCallback, 		      text_focus_cb, (XtPointer)new);    }    else {	sprintf(widget_name, "%s_Label", XtName(new));	SPIN_SHADOW(new) = LABEL_SHADOW;	n = 0;	XtSetArg(args[n], XmNalignment, spin_p->alignment); n++;	XtSetArg(args[n], XmNrecomputeSize, FALSE); n++;	XtSetArg(args[n], XmNlabelString, InitLabel); n++;	XtSetArg(args[n], XmNmarginLeft, LABEL_PADDING); n++;	XtSetArg(args[n], XmNmarginRight, LABEL_PADDING); n++;	XtSetArg(args[n], XmNmarginWidth, 0); n++;	XtSetArg(args[n], XmNmarginHeight, 0); n++;	spin_p->label = XtCreateManagedWidget(widget_name, xmLabelWidgetClass,					      (Widget)new, args, n);	XtOverrideTranslations((Widget)spin_p->label, child_trans);    }    /*     * Create the 2 ArrowWidgets.     */    sprintf(widget_name, "%s_Up", XtName(new));    n = 0;    if (spin_p->arrow_layout == XmARROWS_SPLIT) {	XtSetArg(args[n], XmNarrowDirection, XmARROW_RIGHT); n++;    }    XtSetArg(args[n], XmNhighlightThickness, 0); n++;    XtSetArg(args[n], XmNshadowThickness, 0); n++;    XtSetArg(args[n], XmNtraversalOn, FALSE); n++;    XtSetArg(args[n], XmNforeground, new->core.background_pixel); n++;    spin_p->up_arrow = XtCreateManagedWidget(widget_name, 					     xmArrowButtonWidgetClass,					     (Widget)new, args, n);    XtOverrideTranslations((Widget)spin_p->up_arrow, child_trans);    sprintf(widget_name, "%s_Down", XtName(new));    if (spin_p->arrow_layout == XmARROWS_SPLIT) {	XtSetArg(args[n], XmNarrowDirection, XmARROW_LEFT); n++;    }    else {	XtSetArg(args[n], XmNarrowDirection, XmARROW_DOWN); n++;    }    spin_p->down_arrow = XtCreateManagedWidget(widget_name, 					       xmArrowButtonWidgetClass,					       (Widget)new, args, n);    XtOverrideTranslations((Widget)spin_p->down_arrow, child_trans);    /* Set sensitivity of arrows (up arrow is right arrow) */    if ((spin_p->arrow_sensitivity == XmARROWS_INSENSITIVE) ||	(spin_p->arrow_sensitivity == XmARROWS_LEFT_SENSITIVE)) 	XtSetSensitive(spin_p->up_arrow, FALSE);    if ((spin_p->arrow_sensitivity == XmARROWS_INSENSITIVE) ||	(spin_p->arrow_sensitivity == XmARROWS_RIGHT_SENSITIVE)) 	XtSetSensitive(spin_p->down_arrow, FALSE);    /*      * Arm causes the value to change and the timer to start.     * Disarm (leaveNotify from grab) causes the timer to stop.     */    XtAddCallback(spin_p->up_arrow, XmNarmCallback, up_cb, (XtPointer)new);    XtAddCallback(spin_p->up_arrow, XmNdisarmCallback, disarm_cb, 		  (XtPointer)new);    XtAddEventHandler(spin_p->up_arrow, LeaveWindowMask, FALSE, grab_leave_cb, 		      (XtPointer)new);    XtAddCallback(spin_p->down_arrow, XmNarmCallback, down_cb, (XtPointer)new);    XtAddCallback(spin_p->down_arrow, XmNdisarmCallback, disarm_cb, 		  (XtPointer)new);    XtAddEventHandler(spin_p->down_arrow, LeaveWindowMask, FALSE, 		      grab_leave_cb, (XtPointer)new);    /* Initialize everything based on what the resource values are */    StoreResourceInfo(spin_p, NULL, TRUE);    /*     * Set initial value in text or label if items was specified     */    if (spin_p->editable == FALSE) {	SetLabelData(new);	SetMaximumLabelSize(spin_p);    }    else	SetTextFieldData(new);    SetSpinButtonSize(new);    LayoutChildren(new);    XtFree(widget_name);}/* * Allow the manager to gain focus if not editable.  If editable (using * text-field), then let the toolkit give focus to the text-field. */static XmNavigabilityWidgetNavigable(spin)DtSpinButtonWidget spin;{       XmNavigationType nav_type = ((XmManagerWidget)spin)->manager.navigation_type;    if (spin->core.sensitive &&  spin->core.ancestor_sensitive &&	((XmManagerWidget)spin)->manager.traversal_on) {	if ((nav_type == XmSTICKY_TAB_GROUP) ||	    (nav_type == XmEXCLUSIVE_TAB_GROUP) ||	    ((nav_type == XmTAB_GROUP) &&	     !_XmShellIsExclusive((Widget)spin))) {	    if (spin->spin_button.editable)		return(XmDESCENDANTS_TAB_NAVIGABLE);	    else		return(XmTAB_NAVIGABLE);	}	return(XmDESCENDANTS_NAVIGABLE);    }    return(XmNOT_NAVIGABLE);}/*  * The spin-button gets focus. */static void _SpinButtonFocusIn(spin, event, params, num_params)DtSpinButtonWidget spin;XEvent *event;char **params;Cardinal *num_params;{    DrawHighlight(spin, FALSE);}/*  * The spin-button loses focus. */static void _SpinButtonFocusOut(spin, event, params, num_params)DtSpinButtonWidget spin;XEvent *event;char **params;Cardinal *num_params;{    DrawHighlight(spin, TRUE);}/* * This function gets called whenever we draw or clear the shadow (to * redraw highlight during resize, etc), as well as during focus_in * and focus_out events. */static voidDrawHighlight(spin, clear)DtSpinButtonWidget spin;Boolean clear;{    XRectangle rect[4] ;    if (XtIsRealized(spin)) {	if (clear) {	    rect[0].x = rect[1].x = rect[2].x = 0;	    rect[3].x = spin->spin_button.old_width - SPIN_MARGIN_W(spin);	    rect[0].y = rect[2].y = rect[3].y = 0 ;	    rect[1].y = spin->spin_button.old_height - SPIN_MARGIN_H(spin);	    rect[0].width = rect[1].width = spin->spin_button.old_width;	    rect[2].width = rect[3].width = SPIN_MARGIN_W(spin);	    rect[0].height = rect[1].height = SPIN_MARGIN_H(spin);	    rect[2].height = rect[3].height = spin->spin_button.old_height;	    XFillRectangles(XtDisplayOfObject((Widget)spin),			    XtWindowOfObject((Widget)spin), 			    spin->manager.background_GC, rect, 4);	}	else if (XmGetFocusWidget((Widget)spin) == (Widget)spin) {	    rect[0].x = rect[1].x = rect[2].x = 0;	    rect[3].x = XtWidth(spin) - SPIN_MARGIN_W(spin);	    rect[0].y = rect[2].y = rect[3].y = 0 ;	    rect[1].y = XtHeight(spin) - SPIN_MARGIN_H(spin);	    rect[0].width = rect[1].width = XtWidth(spin);	    rect[2].width = rect[3].width = SPIN_MARGIN_W(spin);	    rect[0].height = rect[1].height = SPIN_MARGIN_H(spin);	    rect[2].height = rect[3].height = XtHeight(spin);	    XFillRectangles(XtDisplayOfObject((Widget)spin),			    XtWindowOfObject((Widget)spin), 			    spin->manager.highlight_GC, rect, 4);	}    }}/* * osfUp virtual key hit.  Simulate hitting the up arrow. */static void _SpinButtonUp(spin, event, params, num_params)DtSpinButtonWidget spin;XEvent *event;char **params;Cardinal *num_params;{    if (*num_params != 0) /* params means label or arrows */	spin = (DtSpinButtonWidget)XtParent(spin);    if (spin->spin_button.arrow_layout != XmARROWS_SPLIT) {	up_cb((Widget)spin->spin_button.up_arrow, (XtPointer)spin, NULL);	disarm_cb((Widget)spin->spin_button.up_arrow, (XtPointer)spin, NULL);    }}/* * osfDown virtual key hit.  Simulate hitting the down arrow. */static void _SpinButtonDown(spin, event, params, num_params)DtSpinButtonWidget spin;XEvent *event;char **params;Cardinal *num_params;{    if (*num_params != 0) /* params means label or arrows */	spin = (DtSpinButtonWidget)XtParent(spin);    if (spin->spin_button.arrow_layout != XmARROWS_SPLIT) {	down_cb((Widget)spin->spin_button.down_arrow, (XtPointer)spin, NULL);	disarm_cb((Widget)spin->spin_button.down_arrow, (XtPointer)spin, NULL);    }}/* * osfRight virtual key hit.  Simulate hitting the up arrow. */static void _SpinButtonRight(spin, event, params, num_params)DtSpinButtonWidget spin;XEvent *event;char **params;Cardinal *num_params;{    if (*num_params != 0) /* params means label or arrows */	spin = (DtSpinButtonWidget)XtParent(spin);    if (spin->spin_button.arrow_layout == XmARROWS_SPLIT) {	up_cb((Widget)spin->spin_button.up_arrow, (XtPointer)spin, NULL);	disarm_cb((Widget)spin->spin_button.up_arrow, (XtPointer)spin, NULL);    }}/* * osfLeft virtual key hit.  Simulate hitting the down arrow. */static void _SpinButtonLeft(spin, event, params, num_params)DtSpinButtonWidget spin;XEvent *event;char **params;Cardinal *num_params;{    if (*num_params != 0) /* params means label or arrows */	spin = (DtSpinButtonWidget)XtParent(spin);    if (spin->spin_button.arrow_layout == XmARROWS_SPLIT) {	down_cb((Widget)spin->spin_button.down_arrow, (XtPointer)spin, NULL);	disarm_cb((Widget)spin->spin_button.down_arrow, (XtPointer)spin, NULL);    }}/* * osfBeginLine virtual key hit.  Go to first item. */static void _SpinButtonBeginLine(spin, event, params, num_params)DtSpinButtonWidget spin;XEvent *event;char **params;Cardinal *num_params;{    DtSpinButtonPart *spin_p;    int new_position;    float new_current = 0;        if (*num_params != 0) /* params means label or arrows */	spin = (DtSpinButtonWidget)XtParent(spin);    spin_p = (DtSpinButtonPart*)&(spin->spin_button);    if (spin_p->child_type == XmNUMERIC) {	new_position = spin_p->minimum;	new_current = spin_p->min;    }    else {	new_position = 0;    }    if (SendCallback(spin, event, FALSE, new_position,		     new_current, FALSE) == TRUE) {	/* User said yes, so set widget values */	spin_p->position = new_position;	spin_p->current = new_current;	if (spin_p->editable)	    SetTextFieldData(spin);	else	    SetLabelData(spin);		/* send value_changed callback */	(void)SendCallback(spin, event, TRUE, spin_p->position,			   spin_p->current, FALSE);    }}/* * osfEndLine virtual key hit.  Go to last item. */static void _SpinButtonEndLine(spin, event, params, num_params)DtSpinButtonWidget spin;XEvent *event;char **params;Cardinal *num_params;{    DtSpinButtonPart *spin_p;    int new_position;    float new_current = 0;        if (*num_params != 0) /* params means label or arrows */	spin = (DtSpinButtonWidget)XtParent(spin);    spin_p = (DtSpinButtonPart*)&(spin->spin_button);    if (spin_p->child_type == XmNUMERIC) {	new_position = spin_p->maximum;	new_current = spin_p->max;    }    else {	new_position = spin_p->item_count - 1;    }    if (SendCallback(spin, event, FALSE, new_position,		     new_current, FALSE) == TRUE) {	/* User said yes, so set widget values */	spin_p->position = new_position;	spin_p->current = new_current;	if (spin_p->editable)	    SetTextFieldData(spin);	else	    SetLabelData(spin);		/* send value_changed callback */	(void)SendCallback(spin, event, TRUE, spin_p->position,			   spin_p->current, FALSE);    }}/* * This function goes through most of the resources and makes sure  * they have legal values. */static voidCheckResources(spin)DtSpinButtonWidget spin;{    DtSpinButtonPart *spin_p = (DtSpinButtonPart*)&(spin->spin_button);    if ((spin_p->arrow_sensitivity != XmARROWS_SENSITIVE) &&	(spin_p->arrow_sensitivity != XmARROWS_LEFT_SENSITIVE) &&

⌨️ 快捷键说明

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