Real CtoReal(double f) { Real r = answerObject(ClassReal, ZERO, EAV); setReal(r, f); return r; }
static Area getNormalisedArea(Area a) { InitAreaA; NormaliseArea(ax, ay, aw, ah); answer(answerObject(ClassArea, toInt(ax), toInt(ay), toInt(aw), toInt(ah), EAV)); }
static Point getPositionHandle(Handle h, Graphical gr, Device dev) { Int x, y; TRY(getXYHandle(h, gr, dev, &x, &y)); answer(answerObject(ClassPoint, x, y, EAV)); }
StringObj CtoString(const char *s) { CharArray c = CtoScratchCharArray(s); StringObj str = answerObject(ClassString, name_procent_s, c, EAV); doneScratchCharArray(c); return str; }
static Area getUnionArea(Area a, Area b) { Area c; c = answerObject(ClassArea, a->x, a->y, a->w, a->h, EAV); unionArea(c, b); answer(c); }
static Tuple getRowRangeTable(Table tab) { int rmin, rmax; table_row_range(tab, &rmin, &rmax); answer(answerObject(ClassTuple, toInt(rmin), toInt(rmax), EAV)); }
static Tuple getColumnRangeTable(Table tab) { int cmin, cmax; table_column_range(tab, &cmin, &cmax); answer(answerObject(ClassTuple, toInt(cmin), toInt(cmax), EAV)); }
static SyntaxTable getConvertSyntaxTable(Any ctx, Name name) { SyntaxTable t; if ( (t = getLookupSyntaxTable(ctx, name)) ) answer(t); answer(answerObject(ClassSyntaxTable, name, EAV)); }
static Area getIntersectionArea(Area a, Area b) { Area c; c = answerObject(ClassArea, a->x, a->y, a->w, a->h, EAV); if ( intersectionArea(c, b) ) answer(c); freeObject(c); fail; }
StringObj staticCtoString(const char *s) { CharArray c = CtoScratchCharArray(s); StringObj str; c->data.s_readonly = TRUE; str = answerObject(ClassString, name_procent_s, c, EAV); doneScratchCharArray(c); return str; }
static Chain getConvertChain(Any ctx, Vector v) { Chain ch = answerObject(ClassChain, EAV); int n = valInt(v->size); Any *e = v->elements; for( ; --n >= 0; e++ ) { appendChain(ch, *e); } answer(ch); }
static Elevation getConvertElevation(Any receiver, Any val) { Int i; Elevation e; if ( (e= getLookupElevation(receiver, val, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT)) ) return e; if ( (i = toInteger(val)) ) answer(answerObject(ClassElevation, i, i, EAV)); fail; }
static Area getAreaTableCell(TableCell c) { Table tab = table_of_cell(c); Device dev; if ( tab && notNil(dev=tab->device) ) { table_cell_dimensions d; ComputeGraphical(dev); /* make sure area is up-to-date */ dims_table_cell(c, &d); answer(answerObject(ClassArea, toInt(d.x), toInt(d.y), toInt(d.w), toInt(d.h), EAV)); } fail; }
static HashTable LoadColourNames() { if ( !ColourNames ) { FileObj f = answerObject(ClassFile, CtoName("$PCEHOME/lib/rgb.txt"), EAV); ColourNames = globalObject(NAME_colourNames, ClassHashTable, EAV); if ( send(f, NAME_open, NAME_read, EAV) ) { char line[256]; int r, g, b; char name[80]; while( fgets(line, sizeof(line), f->fd) ) { switch( sscanf(line, "%d%d%d%[^\n]", &r, &g, &b, name) ) { case 4: { char *s; char *e; COLORREF rgb; Name cname; for(s=name; *s && *s <= ' '; s++) ; for(e = s + strlen(s); e > s && e[-1] <= ' '; e--) ; *e = EOS; for(e=s; *e; e++) { if ( isupper(*e) ) *e = tolower(*e); else if ( *e == ' ' ) *e = '_'; } cname = CtoKeyword(s); rgb = RGB(r, g, b); appendHashTable(ColourNames, cname, toInt(rgb)); DEBUG(NAME_colour, Cprintf("%s --> 0x%lx\n", pp(cname), (long) rgb)); break; } } } send(f, NAME_close, EAV); } } return ColourNames; }
StringObj create_string_from_str(String s, int tmp) { string s2; CharArray c; StringObj str; charA *do_free = NULL; if ( s->s_iswide ) { const charW *txt = s->s_textW; const charW *end = &txt[s->s_size]; charA *p; for( ; txt < end; txt++ ) { if ( *txt > 0xff ) goto canonical; } str_inithdr(&s2, FALSE); s2.s_size = s->s_size; if ( !(s2.s_textA = alloca(s->s_size)) ) { s2.s_textA = pceMalloc(s->s_size); do_free = s2.s_textA; } for(txt = s->s_textW, p = s2.s_textA; txt < end; ) *p++ = *txt++; s = &s2; } canonical: c = StringToScratchCharArray(s); if ( tmp ) str = tempObject(ClassString, name_procent_s, c, EAV); else str = answerObject(ClassString, name_procent_s, c, EAV); doneScratchCharArray(c); if ( do_free ) pceFree(do_free); return str; }
static Chain getFindAllVector(Vector v, Code code, Int from, Int to) { Chain result = answerObject(ClassChain, EAV); int f, t; if ( get_range(v, from, to, &f, &t) ) { int step = (t >= f ? 1 : -1); int offset = valInt(v->offset); for(; f != t+step ; f += step) { Any av[2]; av[0] = v->elements[f-offset-1]; av[1] = toInt(f); if ( forwardCodev(code, 2, av) ) appendChain(result, av[0]); } } answer(result); }
Image ws_grab_image_display(DisplayObj d, int x, int y, int width, int height) { HDC hdc = GetDC(NULL); RECT rect; Image image; int w, h; HBITMAP obm, bm; HDC hdcimg; Size size = getSizeDisplay(d); rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height; if ( rect.left < 0 ) rect.left = 0; if ( rect.top < 0 ) rect.top = 0; if ( rect.bottom > valInt(size->h) ) rect.bottom = valInt(size->h); if ( rect.right > valInt(size->w) ) rect.right = valInt(size->w); w = rect.right - rect.left; h = rect.bottom - rect.top; image = answerObject(ClassImage, NIL, toInt(w), toInt(h), NAME_pixmap, EAV); assign(image, display, d); bm = ZCreateCompatibleBitmap(hdc, w, h); hdcimg = CreateCompatibleDC(hdc); obm = SelectObject(hdcimg, bm); BitBlt(hdcimg, 0, 0, w, h, hdc, rect.left, rect.top, SRCCOPY); SelectObject(hdcimg, obm); ZDeleteObject(hdcimg); ReleaseDC(NULL, hdc); registerXrefObject(image, image->display, (void *) bm); return image; }
static HashTable LoadX11ColourNames() { if ( !X11ColourNames ) { FileObj f = answerObject(ClassFile, CtoName("$PCEHOME/lib/rgb.txt"), EAV); X11ColourNames = globalObject(CtoName("_x11_colour_names"), ClassHashTable, EAV); if ( send(f, NAME_open, NAME_read, EAV) ) { char line[256]; int r, g, b; char name[80]; while( fgets(line, sizeof(line), f->fd) ) { switch( sscanf(line, "%d%d%d%[^\n]", &r, &g, &b, name) ) { case 4: { char *s; char *e; COLORREF rgb; for(s=name; *s && *s <= ' '; s++) ; for(e = s + strlen(s); e > s && e[-1] <= ' '; e--) ; *e = EOS; rgb = RGB(r, g, b); appendHashTable(X11ColourNames, toInt(rgb), CtoName(s)); break; } } } send(f, NAME_close, EAV); } } return X11ColourNames; }
Elevation getModifyElevation(Elevation e, Name att, Any val) { if ( notNil(e->name) ) { Int height = e->height; Any colour = e->colour; Any relief = e->relief; Any shadow = e->shadow; Any bg = e->background; Name kind = e->kind; if ( att == NAME_height ) height = val; else if ( att == NAME_colour ) colour = val; else if ( att == NAME_relief ) relief = val; else if ( att == NAME_shadow ) shadow = val; else if ( att == NAME_kind ) kind = val; else if ( att == NAME_background ) bg = val; answer(answerObject(ClassElevation, NIL, height, colour, relief, shadow, kind, bg, EAV)); } else { attributeElevation(e, att, val); answer(e); } }
static Point getCornerArea(Area a) { answer(answerObject(ClassPoint, add(a->x,a->w), add(a->y,a->h), EAV)); }
static StringObj getCopyString(StringObj s) { answer(answerObject(classOfObject(s), name_procent_s, s, EAV)); }
static StringObj getModifyString(StringObj str, CharArray value) { answer(answerObject(classOfObject(str), name_procent_s, value, EAV)); }
Size getSizeArea(Area a) { answer(answerObject(ClassSize, a->w, a->h, EAV)); }
Point getPositionArea(Area a) { answer(answerObject(ClassPoint, a->x, a->y, EAV)); }
static LayoutInterface getConvertTableCell(Any context, Graphical image) { answer(answerObject(ClassTableCell, image, EAV)); }
Area getCopyArea(Area a) { answer(answerObject(classOfObject(a), a->x, a->y, a->w, a->h, EAV)); }
static Point getCenterArea(Area a) { answer(answerObject(ClassPoint, mid(a->x,a->w), mid(a->y,a->h), EAV)); }