summaryrefslogtreecommitdiff
path: root/parameter.c
diff options
context:
space:
mode:
Diffstat (limited to 'parameter.c')
-rw-r--r--parameter.c149
1 files changed, 106 insertions, 43 deletions
diff --git a/parameter.c b/parameter.c
index eb277cb..e26bd95 100644
--- a/parameter.c
+++ b/parameter.c
@@ -62,7 +62,7 @@ u_char param_select[] = {
POLYGON | SPLINE | LABEL | OBJINST | ARC, /* P_POSITION_X */
POLYGON | SPLINE | LABEL | OBJINST | ARC, /* P_POSITION_Y */
POLYGON | SPLINE | ARC | PATH, /* P_STYLE */
- LABEL, /* P_JUSTIFY */
+ LABEL, /* P_ANCHOR */
ARC, /* P_ANGLE1 */
ARC, /* P_ANGLE2 */
ARC, /* P_RADIUS */
@@ -90,7 +90,7 @@ Widget *param_buttons[] = {
&ParametersPositionButton, /* P_POSITION_X */
&ParametersPositionButton, /* P_POSITION_Y */
&ParametersStyleButton, /* P_STYLE */
- &ParametersJustificationButton, /* P_JUSTIFY */
+ &ParametersAnchoringButton, /* P_ANCHOR */
&ParametersStartAngleButton, /* P_ANGLE1 */
&ParametersEndAngleButton, /* P_ANGLE2 */
&ParametersRadiusButton, /* P_RADIUS */
@@ -820,11 +820,11 @@ int epsubstitute(genericptr thiselem, objectptr thisobj, objinstptr pinst,
break;
}
break;
- case P_JUSTIFY:
+ case P_ANCHOR:
retval = max(retval, 1);
switch(thiselem->type) {
case LABEL:
- TOLABEL(&thiselem)->justify = ival;
+ TOLABEL(&thiselem)->anchor = ival;
break;
}
break;
@@ -869,10 +869,10 @@ int epsubstitute(genericptr thiselem, objectptr thisobj, objinstptr pinst,
retval = max(retval, 1);
switch(thiselem->type) {
case LABEL:
- TOLABEL(&thiselem)->rotation = ival;
+ TOLABEL(&thiselem)->rotation = fval;
break;
case OBJINST:
- TOOBJINST(&thiselem)->rotation = ival;
+ TOOBJINST(&thiselem)->rotation = fval;
break;
}
break;
@@ -1004,7 +1004,7 @@ int psubstitute(objinstptr thisinst)
Boolean has_param(genericptr celem)
{
- if (IS_LABEL(celem) == LABEL) {
+ if (IS_LABEL(celem)) {
stringpart *cstr;
labelptr clab = (labelptr)celem;
for (cstr = clab->string; cstr != NULL; cstr = cstr->nextpart)
@@ -1151,10 +1151,10 @@ void pwriteback(objinstptr thisinst)
break;
}
break;
- case P_JUSTIFY:
+ case P_ANCHOR:
switch(thiselem->type) {
case LABEL:
- wtemp.ival = TOLABEL(eptr)->justify;
+ wtemp.ival = TOLABEL(eptr)->anchor;
break;
}
break;
@@ -1189,10 +1189,10 @@ void pwriteback(objinstptr thisinst)
case P_ROTATION:
switch(thiselem->type) {
case OBJINST:
- wtemp.ival = TOOBJINST(eptr)->rotation;
+ wtemp.fval = TOOBJINST(eptr)->rotation;
break;
case LABEL:
- wtemp.ival = TOLABEL(eptr)->rotation;
+ wtemp.fval = TOLABEL(eptr)->rotation;
break;
}
break;
@@ -1750,11 +1750,12 @@ void makenumericalp(genericptr *gelem, u_int mode, char *key, short cycle)
case P_POSITION_Y:
newops->parameter.ivalue = (int)TOLABEL(gelem)->position.y;
break;
- case P_JUSTIFY:
- newops->parameter.ivalue = (int)TOLABEL(gelem)->justify;
+ case P_ANCHOR:
+ newops->parameter.ivalue = (int)TOLABEL(gelem)->anchor;
break;
case P_ROTATION:
- newops->parameter.ivalue = (int)TOLABEL(gelem)->rotation;
+ newops->type = XC_FLOAT;
+ newops->parameter.fvalue = TOLABEL(gelem)->rotation;
break;
case P_SCALE:
newops->type = XC_FLOAT;
@@ -1802,7 +1803,8 @@ void makenumericalp(genericptr *gelem, u_int mode, char *key, short cycle)
newops->parameter.ivalue = (int)TOOBJINST(gelem)->position.y;
break;
case P_ROTATION:
- newops->parameter.ivalue = (int)TOOBJINST(gelem)->rotation;
+ newops->type = XC_FLOAT;
+ newops->parameter.fvalue = TOOBJINST(gelem)->rotation;
break;
case P_SCALE:
newops->type = XC_FLOAT;
@@ -2319,7 +2321,7 @@ void free_object_param(objectptr thisobj, oparamptr thisparam)
for (strptr = plab->string; strptr != NULL; strptr = strptr->nextpart) {
if (strptr->type == PARAM_START) {
if (!strcmp(strptr->data.string, key)) {
- unmakeparam(plab, strptr);
+ unmakeparam(plab, NULL, strptr);
pending = TRUE;
break;
}
@@ -2365,9 +2367,10 @@ stringpart *searchparam(stringpart *tstr)
/* Remove parameterization from a label string or substring. */
/*--------------------------------------------------------------*/
-void unmakeparam(labelptr thislabel, stringpart *thispart)
+void unmakeparam(labelptr thislabel, objinstptr thisinst, stringpart *thispart)
{
oparamptr ops;
+ oparamptr testop;
stringpart *strptr, *lastpart, *endpart, *newstr, *subs;
char *key;
@@ -2386,34 +2389,52 @@ void unmakeparam(labelptr thislabel, stringpart *thispart)
/* parameter. The parameter itself will be deleted by a different */
/* method, using free_object_param(). */
- ops = match_param(topobject, key);
- subs = ops->parameter.string;
+ ops = (thisinst != NULL) ? match_instance_param(thisinst, key) :
+ match_param(topobject, key);
- /* Copy the default parameter into the place we are unparameterizing */
+ if (ops == NULL) ops = match_param(topobject, key);
- newstr = NULL;
- newstr = stringcopy(subs);
+ if (ops == NULL) return; /* Report error? */
- /* Delete the "PARAM_END" off of the copied string and link it into */
- /* the existing string. */
- /* (NOTE: If parameter is an empty string, there may be nothing */
- /* before PARAM_END. . .) */
+ /* Copy the default parameter into the place we are unparameterizing */
+ /* Promote first to a string type if necessary */
+
+ if (ops->type == XC_STRING) {
+ subs = ops->parameter.string;
+ newstr = NULL;
+ newstr = stringcopy(subs);
+
+ /* Delete the "PARAM_END" off of the copied string and link it */
+ /* into the existing string. */
+ /* (NOTE: If parameter is an empty string, there may be nothing */
+ /* before PARAM_END. . .) */
+
+ if (newstr->type != PARAM_END) {
+ for (endpart = newstr; endpart->nextpart->type != PARAM_END;
+ endpart = endpart->nextpart);
+ free(endpart->nextpart);
+ endpart->nextpart = thispart->nextpart;
+ }
+ else {
+ endpart = newstr;
+ newstr = newstr->nextpart;
+ free(endpart);
+ endpart = NULL;
+ }
- if (newstr->type != PARAM_END) {
- for (endpart = newstr; endpart->nextpart->type != PARAM_END;
- endpart = endpart->nextpart);
- free(endpart->nextpart);
- endpart->nextpart = thispart->nextpart;
+ /* Remove dangling link from instance parameter */
+ /* (If this was a global parameter, it will have no effect) */
+ for (strptr = ops->parameter.string; strptr->type != PARAM_END;
+ strptr = strptr->nextpart);
+ strptr->nextpart = NULL;
}
else {
- endpart = newstr;
- newstr = newstr->nextpart;
- free(endpart);
- endpart = NULL;
+ /* This should not happen */
+ Fprintf(stderr, "Error: String contains non-string parameter!\n");
+ redrawtext(thislabel);
+ return;
}
- /* Find the stringpart before the parameter call (if any) */
-
lastpart = NULL;
for (strptr = thislabel->string; strptr != NULL && strptr != thispart;
strptr = strptr->nextpart) {
@@ -2456,7 +2477,36 @@ void unparameterize(int mode)
else
ptype = ALL_TYPES;
- if ((areawin->selects == 1) && (mode == P_SUBSTRING) && areawin->textend > 0
+ // NOTE: Need a different method for interactive edit; remove only the
+ // parameter under the cursor.
+
+ if (eventmode == ETEXT_MODE) {
+ /* ETEXT_MODE implies there is only one selected label */
+ settext = SELTOLABEL(areawin->selectlist);
+ strptr = findstringpart(areawin->textpos, &locpos, settext->string,
+ areawin->topinstance);
+
+ /* Assume the cursor is inside a parameter and find the end */
+ while (strptr != NULL && strptr->type != PARAM_START && strptr->type != PARAM_END)
+ strptr = strptr->nextpart;
+
+ if (strptr && (strptr->type == PARAM_END)) {
+ strptr = strptr->nextpart;
+ tmpptr = settext->string;
+ while (tmpptr != NULL) {
+ if (tmpptr->type == PARAM_START) {
+ if (tmpptr->nextpart == strptr) {
+ /* tmpptr now points to the parameter to be removed */
+ unmakeparam(settext, areawin->topinstance, tmpptr);
+ break;
+ }
+ }
+ tmpptr = tmpptr->nextpart;
+ }
+ }
+ lastptr = NULL;
+ }
+ else if ((areawin->selects == 1) && (mode == P_SUBSTRING) && areawin->textend > 0
&& areawin->textend < areawin->textpos) {
if (SELECTTYPE(areawin->selectlist) != LABEL) return; /* Not a label */
settext = SELTOLABEL(areawin->selectlist);
@@ -2477,17 +2527,30 @@ void unparameterize(int mode)
/* Finish search, unlinking any parameter we might be inside */
for (; tmpptr != NULL; tmpptr = nextstringpart(tmpptr, areawin->topinstance));
- if (lastptr != NULL) unmakeparam(settext, lastptr);
+ if (lastptr != NULL) unmakeparam(settext, areawin->topinstance, lastptr);
}
else {
for (fselect = areawin->selectlist; fselect < areawin->selectlist +
areawin->selects; fselect++) {
if ((mode == P_SUBSTRING) && SELECTTYPE(fselect) == LABEL) {
+ u_char found;
+
settext = SELTOLABEL(fselect);
- strptr = settext->string;
- while (strptr != NULL && strptr->type != PARAM_START)
- strptr = strptr->nextpart;
- if (strptr != NULL) unmakeparam(settext, strptr);
+
+ // Remove all parameters from the string.
+ found = 1;
+ while (found == (u_char)1) {
+ found = (u_char)0;
+ strptr = settext->string;
+ while (strptr != NULL) {
+ if (strptr->type == PARAM_START) {
+ unmakeparam(settext, areawin->topinstance, strptr);
+ found = (u_char)1;
+ break;
+ }
+ strptr = strptr->nextpart;
+ }
+ }
}
else if (mode == P_POSITION) {
removenumericalp(topobject->plist + (*fselect), P_POSITION_X);