static status initialiseConstraint(Constraint c, Any from, Any to, Relation relation, Name only) { Name lock; if ( from == to ) return errorPce(c, NAME_cannotConstraintSelf); assign(c, from, from); assign(c, to, to); assign(c, relation, relation); if ( isDefault(only) ) lock = NAME_none; else if ( equalName(only, NAME_forwards) ) lock = NAME_backwards; else lock = NAME_forwards; assign(c, locked, lock); constraintObject(from, c); constraintObject(to, c); forwardCreateConstraint(c); succeed; }
status executeConstraint(Constraint c, Any obj) { if ( isNil(c->from) || isNil(c->to) ) fail; if ( obj == c->from && (equalName(c->locked, NAME_forwards) || equalName(c->locked, NAME_front)) ) fail; if ( obj == c->to && (equalName(c->locked, NAME_backwards) || equalName(c->locked, NAME_back)) ) fail; return send(c->relation, obj == c->from ? NAME_forwards : NAME_backwards, c->from, c->to, EAV); }
static status arrowsJoint(Joint jt, Name arrows) { Graphical first, second; if ( equalName(arrows, NAME_none) ) { first = NIL; second = NIL; } else if ( arrows == NAME_first ) { first = (notNil(jt->first_arrow) ? jt->first_arrow : initArrowJoint(jt)); second = NIL; } else if ( arrows == NAME_second ) { first = NIL; second = (notNil(jt->second_arrow) ? jt->second_arrow : initArrowJoint(jt)); } else if ( arrows == NAME_both ) { first = (notNil(jt->first_arrow) ? jt->first_arrow : initArrowJoint(jt)); second = (notNil(jt->second_arrow) ? jt->second_arrow : initArrowJoint(jt)); } else fail; return setArrowsJoint(jt, first, second); }
static Fragment scan_fragment_icons(TextMargin m, SendFunc func, Name how, Any ctx) { Editor e = m->editor; TextBuffer tb = e->text_buffer; TextImage ti = e->image; Fragment fragment = tb->first_fragment; int x = X_MARGIN, y = -1000, h; int mw = valInt(m->area->w); int line = 0, lines = ti->map->length; int gw = valInt(m->gap->w); int gh = valInt(m->gap->h); Style s; int skip = ti->map->skip; for( h=0; notNil(fragment) && line < lines; line++ ) { TextLine tl = &ti->map->lines[line + skip]; DEBUG(NAME_fragment, Cprintf("Scanning line from %ld\n", tl->start)); while( notNil(fragment) && fragment->start < tl->start ) fragment = fragment->next; if ( y + h + gh < tl->y ) /* open the icon-line */ { y = tl->y; x = X_MARGIN; h = 0; } DEBUG(NAME_fragment, Cprintf("tl->y = %d\n", tl->y)); for( ; notNil(fragment) && fragment->start < tl->end ; fragment = fragment->next ) { Image icon; if ( notNil(s = fragment_style(m, fragment)) && notNil(icon = s->icon) ) { int aw = valInt(icon->size->w); if ( (x + aw) > mw - X_MARGIN && aw <= mw -X_MARGIN) { y += h + gh; /* does not fit: next line */ x = X_MARGIN; h = 0; } if ( equalName(how, NAME_forAll) ) { if ( (*func)(m, x, y, fragment, ctx) == FAIL ) fail; } else if ( equalName(how, NAME_forSome) ) { (*func)(m, x, y, fragment, ctx); } else if ( equalName(how, NAME_find) ) { if ( (*func)(m, x, y, fragment, ctx) == SUCCEED ) return fragment; } x += valInt(icon->size->w) + gw; if ( valInt(icon->size->h) > h ) h = valInt(icon->size->h); } } } if ( equalName(how, NAME_find) ) fail; return (Fragment) SUCCEED; }