static status initialiseElevation(Elevation e, Any name, Int height, Any colour, Any relief, Any shadow, Name kind, Any bg) { if ( isDefault(name) ) name = NIL; assign(e, name, name); assign(e, background, bg); if ( isDefault(height) && isInteger(name) ) height = name; if ( notDefault(colour) ) assign(e, colour, colour); if ( notDefault(relief) ) assign(e, relief, relief); if ( notDefault(shadow) ) assign(e, shadow, shadow); if ( notDefault(kind) ) assign(e, kind, kind); if ( notDefault(height) ) assign(e, height, height); obtainClassVariablesObject(e); if ( notNil(name) ) appendHashTable(ElevationTable, name, e); succeed; }
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 status initialiseText(TextObj t, CharArray string, Name format, FontObj font) { if ( isDefault(string) ) string = CtoCharArray(""); initialiseGraphical(t, ZERO, ZERO, ZERO, ZERO); if ( notDefault(format) ) assign(t, format, format); if ( notDefault(font) ) assign(t, font, font); assign(t, underline, OFF); assign(t, string, string); assign(t, margin, toInt(100)); assign(t, wrap, NAME_extend); assign(t, position, newObject(ClassPoint, EAV)); assign(t, caret, getSizeCharArray(string)); assign(t, show_caret, OFF); assign(t, background, NIL); assign(t, x_offset, ZERO); assign(t, x_caret, ZERO); assign(t, y_caret, ZERO); assign(t, selection, NIL); return recomputeText(t, NAME_position); }
status rangeVector(Vector v, Int low, Int high) { if ( notDefault(low) ) lowIndexVector(v, low); if ( notDefault(high) ) highIndexVector(v, high); succeed; }
status setArea(Area a, Int x, Int y, Int w, Int h) { if (notDefault(x)) assign(a, x, x); if (notDefault(y)) assign(a, y, y); if (notDefault(w)) assign(a, w, w); if (notDefault(h)) assign(a, h, h); succeed; }
static status requestGeometryView(View v, Int x, Int y, Int w, Int h) { Editor e = v->editor; if ( notDefault(w) ) w = mul(w, getExFont(e->font)); if ( notDefault(h) ) h = mul(h, getHeightFont(e->font)); return requestGeometryWindow((PceWindow) v, x, y, w, h); }
static Name defcolourname(Int r, Int g, Int b) { if ( notDefault(r) && notDefault(g) && notDefault(b) ) { char buf[50]; sprintf(buf, "#%02x%02x%02x", (unsigned int)valInt(r)>>8, (unsigned int)valInt(g)>>8, (unsigned int)valInt(b)>>8); return CtoName(buf); }
status initialiseGesture(Gesture g, Name button, Modifier modifier) { if ( notDefault(button) ) assign(g, button, button); if ( notDefault(modifier) ) assign(g, modifier, modifier); assign(g, active, ON); assign(g, status, NAME_inactive); assign(g, cursor, DEFAULT); return obtainClassVariablesObject(g); }
static status initialiseSyntaxTable(SyntaxTable t, Name name, SyntaxTable def) { unsigned short *flags; unsigned char *context; if ( isDefault(name) ) name = NIL; if ( notDefault(def) ) { flags = def->table; context = def->context; assign(t, sentence_end, def->paragraph_end); assign(t, paragraph_end, def->paragraph_end); } else { flags = char_flags; context = char_context; assign(t, sentence_end, newObject(ClassRegex, CtoName("[.?!]\\s"), EAV)); assign(t, paragraph_end, newObject(ClassRegex, CtoName("\\s*\n"), EAV)); } assign(t, name, name); assign(t, size, toInt(256)); t->table = alloc(FLAGS_SIZE(t)); t->context = alloc(CONTEXT_SIZE(t)); memcpy(t->table, flags, FLAGS_SIZE(t)); memcpy(t->context, context, CONTEXT_SIZE(t)); if ( notNil(name) ) appendHashTable(SyntaxTables, name, t); succeed; }
static status addSyntaxSyntaxTable(SyntaxTable t, Int chr, Name kind, Int context) { t->table[valInt(chr)] |= nameToCode(kind); if ( notDefault(context) ) { if ( kind == NAME_openBracket ) { t->table[valInt(context)] = CB; t->context[valInt(context)] = valInt(chr); t->context[valInt(chr)] = valInt(context); } else if ( kind == NAME_closeBracket ) { t->table[valInt(context)] = OB; t->context[valInt(context)] = valInt(chr); t->context[valInt(chr)] = valInt(context); } else if ( kind == NAME_commentStart ) { t->table[valInt(context)] |= CS; t->context[valInt(chr)] |= 1; t->context[valInt(context)] |= 2; } else if ( kind == NAME_commentEnd ) { t->table[valInt(context)] |= CE; t->context[valInt(chr)] |= 4; t->context[valInt(context)] |= 8; } else t->context[valInt(chr)] |= valInt(context); } succeed; }
static status initialiseMenuItem(MenuItem m, Any value, Message msg, Any label, BoolObj eg, Code cond, Name acc) { if ( isDefault(eg) ) eg = OFF; if ( isDefault(label) && !(label = get(m, NAME_defaultLabel, value, EAV)) ) return errorPce(m, NAME_noDefaultLabel, value); if ( isDefault(cond) ) cond = NIL; assign(m, value, value); assign(m, message, msg); assign(m, label, label); assign(m, font, DEFAULT); assign(m, colour, DEFAULT); assign(m, selected, OFF); assign(m, active, ON); assign(m, condition, cond); assign(m, end_group, eg); if ( notDefault(acc) ) assign(m, accelerator, acc); return labelMenuItem(m, label); }
status initialiseJoint(Joint jt, Int x, Int y, Int w, Int h, Name arrows) { initialiseGraphical(jt, x, y, w, h); if ( notDefault(arrows) ) arrowsJoint(jt, arrows); succeed; }
status ws_create_window(PceWindow sw, PceWindow parent) { Widget w; DisplayObj d = getDisplayGraphical((Graphical)sw); /* create the widget */ { Arg args[8]; Cardinal n = 0; int pen = valInt(sw->pen); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Actually, it appears Xt is ignoring the geometry parameters. Hence, ws_realise_frame() sends ->geometry to all windows. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ XtSetArg(args[n], XtNx, valInt(sw->area->x)); n++; XtSetArg(args[n], XtNy, valInt(sw->area->y)); n++; XtSetArg(args[n], XtNwidth, valInt(sw->area->w) - 2*pen); n++; XtSetArg(args[n], XtNheight, valInt(sw->area->h) - 2*pen); n++; XtSetArg(args[n], XtNborderWidth, pen); n++; XtSetArg(args[n], XtNinput, True); n++; if ( instanceOfObject(sw->background, ClassColour) ) { XtSetArg(args[n], XtNbackground, getPixelColour(sw->background, d)); n++; } else { Pixmap pm = (Pixmap) getXrefObject(sw->background, d); XtSetArg(args[n], XtNbackgroundPixmap, pm); n++; } DEBUG(NAME_create, Cprintf("Calling XtCreateWidget ...")); w = XtCreateWidget(strName(sw->name), canvasWidgetClass, isDefault(parent) ? widgetFrame(sw->frame) : widgetWindow(parent), args, n); DEBUG(NAME_create, Cprintf("Widget = %p\n", w)); } if ( !w ) return errorPce(w, NAME_createFailed); setWidgetWindow(sw, w); XtAddCallback(w, XtNeventCallback, event_window, sw); XtAddCallback(w, XtNexposeCallback, expose_window, sw); XtAddCallback(w, XtNresizeCallback, resize_window, sw); XtAddCallback(w, XtNdestroyCallback, destroy_window, sw); if ( notDefault(parent) ) /* make a sub-window */ { XtManageChild(w); send(sw, NAME_displayed, ON, EAV); } succeed; }
static status initialiseConstant(Constant c, Name name, StringObj summary) { protectObject(c); assign(c, name, name); if ( notDefault(summary) ) assign(c, summary, summary); succeed; }
status initialiseImage(Image image, SourceSink data, Int w, Int h, Name kind) { Name name = FAIL; if ( isDefault(data) ) data = (SourceSink) NIL; if ( notNil(data) && hasGetMethodObject(data, NAME_name) ) name = get(data, NAME_name, EAV); if ( !name ) name = NIL; assign(image, name, name); assign(image, background, DEFAULT); assign(image, foreground, DEFAULT); ws_init_image(image); if ( isNil(data) || notDefault(w) || notDefault(h) || notDefault(kind) ) { if ( isDefault(w) ) w = toInt(16); if ( isDefault(h) ) h = toInt(16); if ( isDefault(kind) ) kind = NAME_bitmap; assign(image, kind, kind); assign(image, file, NIL); assign(image, depth, kind == NAME_bitmap ? ONE : (Int) DEFAULT); assign(image, size, newObject(ClassSize, w, h, EAV)); assign(image, access, NAME_both); } else { assign(image, kind, NAME_bitmap); assign(image, file, data); assign(image, depth, ONE); assign(image, size, newObject(ClassSize, EAV)); TRY(loadImage(image, DEFAULT, DEFAULT)); assign(image, access, NAME_read); } if ( notNil(name) ) { protectObject(image); appendHashTable(ImageTable, name, image); } succeed; }
static status PlaceLBox(LBox lp, Graphical gr, Int x, Int y, Int w) { DEBUG(NAME_lbox, Cprintf("Placing %s on %s at %d,%d (width = %s)\n", pp(gr), pp(lp), valInt(x), valInt(y), pp(w))); ComputeGraphical(gr); if ( gr->area->x != x || gr->area->y != y || (notDefault(w) && gr->area->w != w) ) setGraphical(gr, x, y, w, DEFAULT); succeed; }
static status initialiseButton(Button b, Name name, Message msg, Name acc) { createDialogItem(b, name); assign(b, default_button, OFF); assign(b, show_focus_border, ON); assign(b, message, msg); if ( notDefault(acc) ) assign(b, accelerator, acc); return requestComputeGraphical(b, DEFAULT); }
static status executeLabel(Label lb) { if ( notNil(lb->message) && notDefault(lb->message) ) { statusLabel(lb, NAME_execute); flushGraphical(lb); forwardReceiverCode(lb->message, lb, EAV); if ( !isFreedObj(lb) ) { statusLabel(lb, NAME_inactive); flushGraphical(lb); } } 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; } }
static status initialiseStyle(Style s, Image icon, FontObj font, Colour colour, BoolObj highlight, BoolObj underline, BoolObj bold, BoolObj grey, Any background, BoolObj hidden, Int lm, Int rm) { if ( isDefault(icon) ) icon = NIL; if ( isDefault(lm) ) lm = ZERO; if ( isDefault(rm) ) rm = ZERO; assign(s, font, font); assign(s, icon, icon); assign(s, colour, colour); assign(s, background, background); assign(s, left_margin, lm); assign(s, right_margin, rm); s->attributes = 0; if ( notDefault(highlight) ) highlightStyle(s, highlight); if ( notDefault(underline) ) underlineStyle(s, underline); if ( notDefault(bold) ) boldStyle(s, bold); if ( notDefault(grey) ) greyStyle(s, grey); if ( notDefault(hidden) ) hiddenStyle(s, hidden); succeed; }
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); }
static status computeLabel(Label lb) { if ( notNil(lb->request_compute) ) { int w, h, b; TRY(obtainClassVariablesObject(lb)); b = valInt(lb->border); if ( notNil(lb->elevation) ) b += abs(valInt(lb->elevation->height)); if ( instanceOfObject(lb->selection, ClassCharArray) ) { String s = &((CharArray)lb->selection)->data; int minw; int ex = valInt(getExFont(lb->font)); if ( lb->wrap == NAME_clip ) { LocalString(buf, s->iswide, s->size+1); str_one_line(buf, s); s = buf; } str_size(s, lb->font, &w, &h); w += ex; if ( notDefault(lb->width) ) minw = valInt(lb->width) - 2*b; else minw = (valInt(lb->length)+1) * ex; w = max(w, minw); } else /*if ( instanceOfObject(lb->selection, ClassImage) )*/ { Image image = (Image) lb->selection; w = valInt(image->size->w); h = valInt(image->size->h); } w += 2*b; h += 2*b; CHANGING_GRAPHICAL(lb, assign(lb->area, w, toInt(w)); assign(lb->area, h, toInt(h)); changedEntireImageGraphical(lb)); assign(lb, request_compute, NIL); }
static status initialiseDate(Date d, Int s, Int m, Int h, Int D, Int M, Int Y) { d->unix_date = time(0); if ( notDefault(s) || notDefault(m) || notDefault(h) || notDefault(D) || notDefault(M) || notDefault(Y) ) return setDate(d, s, m, h, D, M, Y); succeed; }
Name getValignTableCell(TableCell cell) { Table tab; if ( notDefault(cell->valign) ) answer(cell->valign); if ( (tab=table_of_cell(cell)) && notNil(tab->rows) ) { TableRow row = getRowTable(tab, cell->row, OFF); if ( row ) answer(row->alignment); } answer(NAME_top); }
Name getHalignTableCell(TableCell cell) { Table tab; if ( notDefault(cell->halign) ) answer(cell->halign); if ( (tab=table_of_cell(cell)) && notNil(tab->columns) ) { TableColumn col = getColumnTable(tab, cell->column, OFF); if ( col ) answer(col->alignment); } answer(NAME_left); }
static status initialiseLabel(Label lb, Name name, Any selection, FontObj font) { if ( isDefault(name) ) name = NAME_reporter; if ( isDefault(selection) ) selection = NAME_; createDialogItem(lb, name); if ( notDefault(font) ) assign(lb, font, font); selectionLabel(lb, selection); assign(lb, width, DEFAULT); assign(lb, wrap, NAME_extend); return requestComputeGraphical(lb, DEFAULT); }
static Editor getCreateEditorView(View v, Size size) { Editor e; Int w, h; if ( notDefault(size) ) { w = size->w; h = size->h; } else w = h = DEFAULT; if ( (e = newObject(ClassEditor, DEFAULT, w, h, EAV)) ) { FontObj f; if ( (f = getClassVariableValueObject(v, NAME_font)) ) send(e, NAME_font, f, EAV); answer(e); } fail; }
int ws_read_stream_data(Stream s, void *data, int len, Real timeout) { if ( s->rdfd < 0 ) { errno = EINVAL; return -1; } if ( notDefault(timeout) ) { #ifdef HAVE_POLL double v = valReal(timeout); int to = (int)(v*1000.0); struct pollfd fds[1]; fds[0].fd = s->rdfd; fds[0].events = POLLIN; if ( poll(fds, 1, to) == 0 ) return -2; #else #ifndef __WINDOWS__ if ( s->rdfd < FD_SETSIZE ) #endif { fd_set readfds; struct timeval to; double v = valReal(timeout); to.tv_sec = (long)v; to.tv_usec = (long)(v * 1000000.0) % 1000000; FD_ZERO(&readfds); FD_SET(s->rdfd, &readfds); if ( select(s->rdfd+1, &readfds, NULL, NULL, &to) == 0 ) return -2; } #endif } return read(s->rdfd, data, len); }
int ws_read_stream_data(Stream s, void *data, int len, Real timeout) { if ( s->rdfd < 0 ) { errno = EINVAL; return -1; } if ( notDefault(timeout) ) { fd_set readfds; struct timeval to; double v = valReal(timeout); to.tv_sec = (long)v; to.tv_usec = (long)(v * 1000000.0) % 1000000; FD_ZERO(&readfds); FD_SET(s->rdfd, &readfds); if ( select(s->rdfd+1, &readfds, NULL, NULL, &to) == 0 ) return -2; } return read(s->rdfd, data, len); }
IOSTREAM * Sopen_object(Any obj, const char *mode) { if ( instanceOfObject(obj, ClassFile) ) { Name name = getOsNameFile(obj); IOSTREAM *s; if ( (s=Sopen_file(nameToFN(name), mode)) ) { if ( !strchr(mode, 'b') ) { FileObj f = obj; Name oldstat = f->status; IOSTREAM *ofd = f->fd; int rc; /* HACKS */ f->status = (mode[0] == 'r' ? NAME_read : NAME_write); f->fd = s; switch(mode[0]) { case 'r': { if ( (rc = doBOMFile(f)) ) setStreamEncodingSourceSink(obj, s); break; } case 'w': { setStreamEncodingSourceSink(obj, s); rc = doBOMFile(f); break; } default: { setStreamEncodingSourceSink(obj, s); rc = 0; } } s->newline = (f->newline_mode == NAME_posix ? SIO_NL_POSIX : f->newline_mode == NAME_dos ? SIO_NL_DOS : SIO_NL_DETECT); f->fd = ofd; f->status = oldstat; if ( !rc ) return NULL; } return s; } errorPce(obj, NAME_openFile, mode[0] == 'r' ? NAME_read : NAME_write, getOsErrorPce(PCE)); return s; } else if ( instanceOfObject(obj, ClassRC) && TheCallbackFunctions.rc_open ) { IOSTREAM *s; RC rc = obj; char *rc_class; if ( notDefault(rc->rc_class) ) rc_class = strName(rc->rc_class); else rc_class = NULL; if ( notNil(rc->context) && TheCallbackFunctions.setHostContext ) { Any savedcontext = (*TheCallbackFunctions.setHostContext)(rc->context); s = (*TheCallbackFunctions.rc_open)(strName(rc->name), rc_class, mode); (*TheCallbackFunctions.setHostContext)(savedcontext); } else s = (*TheCallbackFunctions.rc_open)(strName(rc->name), rc_class, mode); if ( !s ) errorPce(obj, NAME_openFile, mode[0] == 'r' ? NAME_read : NAME_write, getOsErrorPce(PCE)); return s; } else { int flags = SIO_TEXT|SIO_RECORDPOS; OpenObject h; IOSTREAM *stream; switch(mode[0]) { case 'r': flags |= SIO_INPUT; break; case 'w': flags |= SIO_OUTPUT; break; default: errno = EINVAL; return NULL; } for(mode++; *mode; mode++) { switch(*mode) { case 'b': /* binary */ flags &= ~SIO_TEXT; break; case 'r': /* no record */ flags &= ~SIO_RECORDPOS; break; default: errno = EINVAL; return NULL; } } h = alloc(sizeof(*h)); h->point = 0; h->object = obj; addCodeReference(obj); stream = Snew(h, flags, &Sobjectfunctions); if ( (flags&SIO_TEXT) ) stream->encoding = ENC_WCHAR; /* see comment above */ else stream->encoding = ENC_OCTET; h->encoding = stream->encoding; return stream; } }