static status forwardsSpatial(Spatial s, Any from, Any to) { Int xref, yref; Int tX, tY, tW, tH; Area f, t; TRY(f = get(from, NAME_area, EAV)); TRY(t = get(to, NAME_area, EAV)); CALC(xref,s->xFrom,getVar(s->xFrom,VarXref,VarX,f->x,VarW,f->w, EAV),f->x); CALC(yref,s->yFrom,getVar(s->yFrom,VarYref,VarY,f->y,VarH,f->h, EAV),f->y); CALC(tW, s->wTo, getVar(s->wTo, VarW2, VarW, f->w, EAV), t->w); CALC(tH, s->hTo, getVar(s->hTo, VarH2, VarH, f->h, EAV), t->h); CALC(tX, s->xTo,getVar(s->xTo, VarX, VarXref, xref, VarW, tW, EAV), t->x); CALC(tY, s->yTo,getVar(s->yTo, VarY, VarYref, yref, VarH, tH, EAV), t->y); DEBUG(NAME_spatial, Cprintf("%s->f: (%s,%s) -- %ld,%ld,%ld,%ld ==> (%ld, %ld, %ld, %ld)\n", pp(s), pp(from), pp(to), valInt(f->x), valInt(f->y), valInt(f->w), valInt(f->h), valInt(tX), valInt(tY), valInt(tW), valInt(tH))); if (t->x != tX || t->y != tY || t->w != tW || t->h != tH) return send(to, NAME_set, tX, tY, tW, tH, EAV); succeed; }
static status backwardsSpatial(Spatial s, Any from, Any to) { Int xref, yref; Int fW, fH, fX, fY; Area f, t; TRY(f = get(from, NAME_area, EAV)); TRY(t = get(to, NAME_area, EAV)); CALC(xref, s->xTo, getVar(s->xTo,VarXref,VarX,t->x,VarW,t->w,EAV), t->x); CALC(yref, s->yTo, getVar(s->yTo,VarYref,VarY,t->y,VarH,t->h,EAV), t->y); CALC(fW, s->wTo, getVar(s->wTo,VarW,VarW2,t->w,EAV), f->w); CALC(fH, s->hTo, getVar(s->hTo,VarH,VarH2,t->h,EAV), f->h); CALC(fX, s->xTo, getVar(s->xFrom,VarX,VarXref,xref,VarW,f->w,EAV), f->x); CALC(fY, s->yTo, getVar(s->yFrom,VarY,VarYref,yref,VarH,f->h,EAV), f->y); DEBUG(NAME_spatial, Cprintf("%s->b: (%s,%s) -- %ld,%ld,%ld,%ld ==> (%ld, %ld, %ld, %ld)\n", pp(s), pp(from), pp(to), valInt(t->x), valInt(t->y), valInt(t->w), valInt(t->h), valInt(fX), valInt(fY), valInt(fW), valInt(fH))); if (f->x != fX || f->y != fY || f->w != fW || f->h != fH) return send(from, NAME_set, fX, fY, fW, fH, EAV); succeed; }
static status cornerArea(Area a, Point pos) { int w, h; w = valInt(pos->x) - valInt(a->x); w += (w>=0 ? 1 : -1); h = valInt(pos->y) - valInt(a->y); h += (h>=0 ? 1 : -1); assign(a, w, toInt(w)); assign(a, h, toInt(h)); succeed; }
static void compute_label_slider(Slider s, int *lw, int *lh) { if ( s->show_label == ON ) { if ( isDefault(s->label_font) ) obtainClassVariablesObject(s); dia_label_size(s, lw, lh, NULL); *lw += valInt(getExFont(s->label_font)); if ( notDefault(s->label_width) ) *lw = max(valInt(s->label_width), *lw); } else { *lw = *lh = 0; } }
void table_cell_padding(TableCell cell, int *pxptr, int* pyptr) { Size size; Table tab; if ( notDefault(cell->cell_padding) ) size = cell->cell_padding; else if ( (tab=table_of_cell(cell)) ) size = tab->cell_padding; else return; /* should not happen */ *pxptr = valInt(size->w); *pyptr = valInt(size->h); }
int xpmGetRGBfromName(char *inname, int *r, int *g, int *b) { char name[256]; char *q = name, *s = inname; Name cname; Int pcergb; for( ;*s; s++, q++) { if ( isupper(*s) ) *q = tolower(*s); else if ( *s == ' ' ) *q = '_'; else *q = *s; } *q = EOS; cname = CtoKeyword(name); if ( (pcergb = getMemberHashTable(LoadColourNames(), cname)) ) { COLORREF rgb = valInt(pcergb); *r = GetRValue(rgb); *g = GetGValue(rgb); *b = GetBValue(rgb); } else { *r = 255; /* nothing there, return red */ *g = *b = 0; } return 1; /* we have it */ }
void NumValidatorTestCase::TransferInt() { int value = 0; wxIntegerValidator<int> valInt(&value); valInt.SetWindow(m_text); CPPUNIT_ASSERT( valInt.TransferToWindow() ); CPPUNIT_ASSERT_EQUAL( "0", m_text->GetValue() ); value = 17; CPPUNIT_ASSERT( valInt.TransferToWindow() ); CPPUNIT_ASSERT_EQUAL( "17", m_text->GetValue() ); m_text->ChangeValue("foobar"); CPPUNIT_ASSERT( !valInt.TransferFromWindow() ); m_text->ChangeValue("-234"); CPPUNIT_ASSERT( valInt.TransferFromWindow() ); CPPUNIT_ASSERT_EQUAL( -234, value ); m_text->ChangeValue("9223372036854775808"); // == LLONG_MAX + 1 CPPUNIT_ASSERT( !valInt.TransferFromWindow() ); m_text->Clear(); CPPUNIT_ASSERT( !valInt.TransferFromWindow() ); }
static status hasSyntaxSyntaxTable(SyntaxTable t, Int chr, Name name) { if ( tischtype(t, valInt(chr), nameToCode(name)) ) succeed; fail; }
static Int getBottomSideArea(Area a) { if ( valInt(a->h) >= 0 ) answer(add(a->y, a->h)); else answer(a->y); }
static Int getRightSideArea(Area a) { if ( valInt(a->w) >= 0 ) answer(add(a->x, a->w)); else answer(a->x); }
Any getTailVector(Vector v) { if ( v->size != ZERO ) answer(v->elements[valInt(v->size)-1]); fail; }
static status RedrawAreaTextMargin(TextMargin m, Area a) { int x, y, w, h; Elevation z = getClassVariableValueObject(m, NAME_elevation); Any obg; initialiseDeviceGraphical(m, &x, &y, &w, &h); margin_x = x; margin_y = y; obg = r_background(m->background); r_clear(x, y, w, h); if ( z && notNil(z) ) r_3d_box(x, y, w, h, 0, z, FALSE); else { r_thickness(valInt(m->pen)); r_dash(m->texture); r_box(x, y, w, h, 0, NIL); } scan_fragment_icons(m, paint_fragment, NAME_forSome, NIL); RedrawAreaGraphical(m, a); r_background(obg); succeed; }
static void ws_open_colourmap(ColourMap cm) { if ( !getExistingPaletteColourMap(cm) && notNil(cm->colours) ) { int size = valInt(cm->colours->size); LOGPALETTE *lp = pceMalloc(offset(LOGPALETTE, palPalEntry[size])); PALETTEENTRY *pe = &lp->palPalEntry[0]; HPALETTE hpal; int n, nc = 0; DisplayObj d = CurrentDisplay(NIL); for(n=0; n<size; n++) { Colour c = cm->colours->elements[n]; if ( isName(c) && (c = checkType(c, TypeColour, NIL)) ) elementVector(cm->colours, toInt(n+1), c); if ( instanceOfObject(c, ClassColour) ) { if ( c->kind == NAME_named ) ws_create_colour(c, d); pe->peRed = valInt(c->red) >> 8; pe->peGreen = valInt(c->green) >> 8; pe->peBlue = valInt(c->blue) >> 8; pe->peFlags = 0; pe++; nc++; } else Cprintf("%s is not a colour\n", pp(c)); }
static Any getSyntaxSyntaxTable(SyntaxTable t, Int chr) { Any argv[20]; int argc = 0; int code = t->table[valInt(chr)]; if ( code & UC ) argv[argc++] = NAME_uppercaseLetter; if ( code & LC ) argv[argc++] = NAME_lowercaseLetter; if ( code & DI ) argv[argc++] = NAME_digit; if ( code & WS ) argv[argc++] = NAME_wordSeparator; if ( code & SY ) argv[argc++] = NAME_symbol; if ( code & OB ) argv[argc++] = NAME_openBracket; if ( code & CB ) argv[argc++] = NAME_closeBracket; if ( code & EL ) argv[argc++] = NAME_endOfLine; if ( code & BL ) argv[argc++] = NAME_whiteSpace; if ( code & QT ) argv[argc++] = NAME_stringQuote; if ( code & PU ) argv[argc++] = NAME_punctuation; if ( code & EB ) argv[argc++] = NAME_endOfString; if ( code & CS ) argv[argc++] = NAME_commentStart; if ( code & CE ) argv[argc++] = NAME_commentEnd; switch(argc) { case 0: fail; case 1: answer(argv[0]); default: answer(answerObjectv(ClassChain, argc, argv)); } }
status computeAscentDescentGrBox(GrBox grb) { Graphical gr = grb->graphical; int h, ascent, descent; ComputeGraphical(gr); h = valInt(gr->area->h); if ( grb->alignment == NAME_top ) ascent = 0; else if ( grb->alignment == NAME_bottom ) ascent = h; else ascent = h/2; descent = h-ascent; if ( grb->ascent != toInt(ascent) || grb->descent != toInt(descent) ) { assign(grb, ascent, toInt(ascent)); assign(grb, descent, toInt(descent)); succeed; /* changed */ } else fail; /* no change */ }
static status computeButton(Button b) { if ( notNil(b->request_compute) ) { int w, h, isimage; TRY(obtainClassVariablesObject(b)); dia_label_size(b, &w, &h, &isimage); if ( b->look == NAME_winMenuBar || b->look == NAME_gtkMenuBar ) { if ( !isimage ) { w += valInt(getExFont(b->label_font)) * 2; if ( b->look == NAME_gtkMenuBar ) h += 4; } else { w += 4; h += 4; } } else { if ( isimage ) { w += 4; h += 4; } else { Size size = getClassVariableValueObject(b, NAME_size); h += 6; w += 10 + valInt(b->radius); if ( notNil(b->popup) ) { if ( notNil(b->popup->popup_image) ) w += valInt(b->popup->popup_image->size->w) + 5; else if ( b->look == NAME_motif || b->look == NAME_gtk ) w += 12 + 5; else w += 9 + 5; } w = max(valInt(size->w), w); h = max(valInt(size->h), h); } } CHANGING_GRAPHICAL(b, assign(b->area, w, toInt(w)); assign(b->area, h, toInt(h))); assign(b, request_compute, NIL); }
static status RedrawAreaLabel(Label lb, Area a) { int x, y, w, h; Elevation z = lb->elevation; int preview = (lb->status == NAME_preview && notNil(lb->message)); initialiseDeviceGraphical(lb, &x, &y, &w, &h); if ( notNil(z) ) r_3d_box(x, y, w, h, 0, z, !preview); x += valInt(lb->border); y += valInt(lb->border); w -= 2*valInt(lb->border); h -= 2*valInt(lb->border); if ( lb->wrap == NAME_clip ) d_clip(x, y, w, h); if ( instanceOfObject(lb->selection, ClassCharArray) ) { String s = &((CharArray)lb->selection)->data; if ( notNil(z) ) x += valInt(getExFont(lb->font))/2; if ( lb->wrap == NAME_clip ) { LocalString(buf, s->iswide, s->size+1); str_one_line(buf, s); s = buf; } str_label(s, 0, lb->font, x, y, w, h, NAME_left, NAME_top, lb->active == ON ? 0 : LABEL_INACTIVE); } else /*if ( instanceOfObject(lb->selection, ClassImage) )*/ { Image image = (Image) lb->selection; r_image(image, 0, 0, x, y, w, h, ON); } if ( lb->wrap == NAME_clip ) d_clip_done(); if ( preview && isNil(z) ) r_complement(x, y, w, h); return RedrawAreaGraphical(lb, a); }
static void includeArrowsInAreaArc(Arc a) { if ( notNil(a->first_arrow) || notNil(a->second_arrow) ) { int sx, sy, ex, ey; int cx, cy; Any av[4]; points_arc(a, &sx, &sy, &ex, &ey); cx = valInt(a->position->x); cy = valInt(a->position->y); if ( notNil(a->first_arrow) ) { av[0] = toInt(sx); av[1] = toInt(sy); if ( valReal(a->size_angle) >= 0.0 ) { av[2] = toInt(sx+(sy-cy)); av[3] = toInt(sy-(sx-cx)); } else { av[2] = toInt(sx-(sy-cy)); av[3] = toInt(sy+(sx-cx)); } if ( qadSendv(a->first_arrow, NAME_points, 4, av) ) { ComputeGraphical(a->first_arrow); unionNormalisedArea(a->area, a->first_arrow->area); } } if ( notNil(a->second_arrow) ) { av[0] = toInt(ex); av[1] = toInt(ey); if ( valReal(a->size_angle) >= 0.0 ) { av[2] = toInt(ex-(ey-cy)); av[3] = toInt(ey+(ex-cx)); } else { av[2] = toInt(ex+(ey-cy)); av[3] = toInt(ey-(ex-cx)); } if ( qadSendv(a->second_arrow, NAME_points, 4, av) ) { ComputeGraphical(a->second_arrow); unionNormalisedArea(a->area, a->second_arrow->area); } } } }
Vector getCopyVector(Vector v) { Vector v2 = answerObjectv(classOfObject(v), valInt(v->size), v->elements); assign(v2, offset, v->offset); answer(v2); }
static status find_fragment(TextMargin m, int x, int y, Fragment fragment, position *pos) { Style s; Size sz; int ex, ey; if ( isNil(s = fragment_style(m, fragment)) || isNil(s->icon) ) fail; ex = pos->x; ey = pos->y; sz = s->icon->size; if ( ex >= x && ey >= y && ex <= x + valInt(sz->w) && ey <= y + valInt(sz->h) ) succeed; fail; }
Any getArgVector(Vector v, Int arg) { int n = valInt(arg) - 1; validIndex(v, n); answer(v->elements[n]); }
int put_int64(Word at, int64_t l, int flags ARG_LD) { Word p; word r, m; int req; r = consInt(l); if ( valInt(r) == l ) { *at = r; return TRUE; } #if SIZEOF_VOIDP == 8 req = 3; #elif SIZEOF_VOIDP == 4 req = 4; #else #error "FIXME: Unsupported sizeof word" #endif if ( !hasGlobalSpace(req) ) { int rc = ensureGlobalSpace(req, flags); if ( rc != TRUE ) return rc; } p = gTop; gTop += req; #if SIZEOF_VOIDP == 8 r = consPtr(p, TAG_INTEGER|STG_GLOBAL); m = mkIndHdr(1, TAG_INTEGER); *p++ = m; *p++ = l; *p = m; #else #if SIZEOF_VOIDP == 4 r = consPtr(p, TAG_INTEGER|STG_GLOBAL); m = mkIndHdr(2, TAG_INTEGER); *p++ = m; #ifdef WORDS_BIGENDIAN *p++ = (word)(l>>32); *p++ = (word)l; #else *p++ = (word)l; *p++ = (word)(l>>32); #endif *p = m; #else #error "FIXME: Unsupported sizeof intptr_t." #endif #endif *at = r; return TRUE; }
static status sortVector(Vector v, Code code, Int from, Int to) { int f, t, n; f = valInt(v->offset) + 1; t = f + valInt(v->size) - 1; if ( notDefault(from) && valInt(from) > f ) f = valInt(from); if ( notDefault(to) && valInt(to) > t ) t = valInt(to); if ( t <= f ) succeed; n = t-f+1; f -= valInt(v->offset) + 1; { Code old = qsortCompareCode; /* make reentrant */ qsortCompareCode = code; qsort(&v->elements[f], n, sizeof(Any), qsortCompareObjects); qsortCompareCode = old; } succeed; }
static int width_text(FontObj f, const char *s) { CharArray ctmp = CtoScratchCharArray(s); Int w = getWidthFont(f, ctmp); doneScratchCharArray(ctmp); return(valInt(w)); }
static void format_value(Slider s, char *buf, Any val) { int deffmt = isDefault(s->format); if ( isInteger(val) ) sprintf(buf, deffmt ? INTPTR_FORMAT : strName(s->format), valInt(val)); else sprintf(buf, deffmt ? "%g" : strName(s->format), valReal(val)); }
static status dragPopupGesture(PopupGesture g, EventObj ev) { if ( notNil(g->current) && g->current->displayed == ON ) { DEBUG(NAME_popup, Cprintf("Posting drag to %s\n", pp(g->current))); return postEvent(ev, (Graphical) g->current, DEFAULT); } else { if ( notNil(g->max_drag_distance) ) { PceWindow sw; if ( instanceOfObject((sw=ev->window), ClassWindow) && valInt(getDistanceEvent(sw->focus_event, ev)) > valInt(g->max_drag_distance) ) send(g, NAME_cancel, ev, EAV); } } fail; }
static status eventPopupGesture(PopupGesture g, EventObj ev) { if ( g->status == NAME_active && isUpEvent(ev) ) { PceWindow sw; if ( !(sw = getWindowGraphical(ev->receiver)) ) sw = ev->window; if ( notNil(g->current) && g->current->displayed == OFF ) { send(g->current, NAME_open, ev->receiver, getAreaPositionEvent(ev, DEFAULT), EAV); attributeObject(g, NAME_Stayup, ON); grabPointerWindow(sw, ON); focusWindow(sw, ev->receiver, (Recogniser) g, g->cursor, NIL); } else if ( valInt(getClickTimeEvent(ev)) < 400 && getAttributeObject(g, NAME_Stayup) != ON ) { attributeObject(g, NAME_Stayup, ON); grabPointerWindow(sw, ON); focusWindow(sw, ev->receiver, (Recogniser) g, g->cursor, NIL); } else { send(g, NAME_terminate, EAV); if ( isNil(g->current) ) { grabPointerWindow(sw, OFF); focusWindow(sw, NIL, NIL, NIL, NIL); deleteAttributeObject(g, NAME_Stayup); assign(g, status, NAME_inactive); } } succeed; } else if ( notNil(g->current) && g->current->displayed == ON ) return postEvent(ev, (Graphical) g->current, DEFAULT); if ( eventGesture(g, ev) ) succeed; if ( g->status == NAME_active && isAEvent(ev, NAME_keyboard) ) { Name key; TRY(updatePopupGesture(g, ev)); key = characterName(getIdEvent(ev)); if ( send(g->current, NAME_key, key, EAV) ) { Any context = g->context; PopupObj current = g->current; assign(g, context, NIL); assign(g, current, NIL); send(current, NAME_execute, context, EAV); succeed; } else send(g, NAME_cancel, ev, EAV); } fail; }
static status paint_fragment(TextMargin m, int x, int y, Fragment fragment) { Image icon; Style s; int w, h; if ( notNil(s = fragment_style(m, fragment)) && notNil(icon = s->icon) ) { x += margin_x; y += margin_y; w = valInt(icon->size->w); h = valInt(icon->size->h); r_image(icon, 0, 0, x, y, w, h, ON); if ( m->editor->selected_fragment == fragment ) r_complement(x, y, w, h); } succeed; }
static status storeVector(Vector v, FileObj file) { int n; TRY(storeSlotsObject(v, file)); for(n = 0; n < valInt(v->size); n++) TRY(storeObject(v->elements[n], file)); succeed; }
Any cToPceInteger(intptr_t i) { Int n = toInt(i); if ( valInt(n) != i ) { errorPce(PCE, NAME_intRange); fail; } return n; }