static status appendTable(Table tab, TableCell cell, Int x, Int y) { int cspan = valInt(cell->col_span); int rspan = valInt(cell->row_span); int dy; if ( isDefault(x) ) x = tab->current->x; if ( isDefault(y) ) y = tab->current->y; if ( notNil(tab->device) && notNil(cell->image) ) send(tab->device, NAME_display, cell->image, EAV); assign(cell, layout_manager, tab); assign(cell, column, x); assign(cell, row, y); for(dy=0; dy<rspan; dy++) { Int cy = toInt(valInt(y)+dy); TableRow row = getRowTable(tab, cy, ON); int dx; for(dx=0; dx<cspan; dx++) { Int cx = toInt(valInt(x)+dx); cellTableRow(row, cx, cell); } } advance_table(tab); requestComputeLayoutManager((LayoutManager)tab, DEFAULT); return changedTable(tab); }
static status dragResizeGesture(ResizeGesture g, EventObj ev) { Graphical gr = ev->receiver; int x, y, w, h; int sx, sy, sw, sh; int ex, ey; Int X, Y; Name hm = g->h_mode, vm = g->v_mode; x = valInt(gr->area->x); y = valInt(gr->area->y); w = valInt(gr->area->w); h = valInt(gr->area->h); get_xy_event(ev, gr, ON, &X, &Y); ex = valInt(X); ey = valInt(Y); if ( notNil(g->min_size) ) { if ( hm == NAME_left && ex > w - valInt(g->min_size->w) ) ex = w - valInt(g->min_size->w); if ( hm == NAME_right && ex < valInt(g->min_size->w) ) ex = valInt(g->min_size->w); if ( vm == NAME_top && ey > h - valInt(g->min_size->h) ) ey = h - valInt(g->min_size->h); if ( vm == NAME_bottom && ey < valInt(g->min_size->h) ) ey = valInt(g->min_size->h); } if ( notNil(g->max_size) ) { if ( hm == NAME_left && ex < w - valInt(g->max_size->w) ) ex = w - valInt(g->max_size->w); if ( hm == NAME_right && ex > valInt(g->max_size->w) ) ex = valInt(g->max_size->w); if ( vm == NAME_top && ey < h - valInt(g->max_size->h) ) ey = h - valInt(g->max_size->h); if ( vm == NAME_bottom && ey > valInt(g->max_size->h) ) ey = valInt(g->max_size->h); } if ( hm == NAME_left && vm == NAME_top ) sx = x+ex, sy = y+ey, sw = w-ex, sh = h-ey; else if ( hm == NAME_right && vm == NAME_top ) sx = x, sy = y+ey, sw = ex, sh = h-ey; else if ( hm == NAME_left && vm == NAME_bottom ) sx = x+ex, sy = y, sw = w-ex, sh = ey; else if ( hm == NAME_right && vm == NAME_bottom ) sx = x, sy = y, sw = ex, sh = ey; else if ( hm == NAME_keep && vm == NAME_top ) sx = x, sy = y+ey, sw = w, sh = h-ey; else if ( hm == NAME_keep && vm == NAME_bottom ) sx = x, sy = y, sw = w, sh = ey; else if ( hm == NAME_left && vm == NAME_keep ) sx = x+ex, sy = y, sw = w-ex, sh = h; else if ( hm == NAME_right && vm == NAME_keep ) sx = x, sy = y, sw = ex, sh = h; else { NOTREACHED; fail; } return send(gr, NAME_doSet, toInt(sx), toInt(sy), toInt(sw), toInt(sh), EAV); }
static status forwardCreateConstraint(Constraint c) { if ( notNil(c->from) && notNil(c->to) ) updateConstraintsObject(c->from); succeed; }
Any RedrawBoxFigure(Figure f, Area area) { Any rval = NIL; if ( f->pen != ZERO || notNil(f->background) || notNil(f->elevation) ) { int x, y, w, h; initialiseDeviceGraphical(f, &x, &y, &w, &h); if ( f->pen == ZERO && f->radius == ZERO && isNil(f->elevation) ) { r_fill(x, y, w, h, f->background); rval = f->background; } else { r_thickness(valInt(f->pen)); r_dash(f->texture); if ( notNil(f->elevation) ) { r_3d_box(x, y, w, h, valInt(f->radius), f->elevation, TRUE); rval = f->elevation->background; } else { r_box(x, y, w, h, valInt(f->radius), f->background); rval = f->background; } } } return rval; }
static status updatePopupGesture(PopupGesture g, EventObj ev) { PopupObj p; Any rec = getMasterEvent(ev); DEBUG(NAME_popup, Cprintf("updatePopupGesture(): rec=%s\n", pp(rec))); if ( notNil(g->popup) ) { if ( instanceOfObject(g->popup, ClassFunction) ) { TRY( p = getForwardReceiverFunction((Function) g->popup, rec, rec, ev, EAV) ); TRY( p = checkType(p, nameToType(NAME_popup), g)); } else p = g->popup; } else { if ( !(p = get(rec, NAME_popup, EAV)) || !instanceOfObject(p, ClassPopup) ) fail; } assign(g, current, p); if ( isNil(g->context) ) assign(g, context, notNil(p->context) ? p->context : rec); send(p, NAME_update, g->context, EAV); if ( p->active == OFF || emptyChain(p->members) ) { send(g, NAME_cancel, ev, EAV); fail; } succeed; }
static status computeFigure(Figure f) { if ( notNil(f->request_compute) ) { if ( f->pen != ZERO || notNil(f->background) ) { CHANGING_GRAPHICAL(f, { computeGraphicalsDevice((Device) f); computeLayoutDevice((Device) f); computeBoundingBoxFigure(f); }); } else
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; }
status RedrawAreaButton(Button b, Area a) { int x, y, w, h; int defb; int rm = 0; /* right-margin */ PceWindow sw; int kbf; /* Button has keyboard focus */ int obhf; /* Other button has focus */ int focus; int swapbg = FALSE; int up; int flags = 0; Elevation z; if ( b->look == NAME_winMenuBar || b->look == NAME_gtkMenuBar ) return RedrawMenuBarButton(b, a); if ( b->active == OFF ) flags |= LABEL_INACTIVE; up = (b->status == NAME_active || b->status == NAME_inactive); defb = (b->default_button == ON); initialiseDeviceGraphical(b, &x, &y, &w, &h); NormaliseArea(x, y, w, h); if ( (sw = getWindowGraphical((Graphical)b)) ) { kbf = (sw->keyboard_focus == (Graphical) b); obhf = (!kbf && instanceOfObject(sw->keyboard_focus, ClassButton)); focus = (sw->input_focus == ON); } else kbf = obhf = focus = FALSE; /* should not happen */ if ( !ws_draw_button_face((DialogItem)b, x, y, w, h, up, defb, kbf && focus) ) draw_generic_button_face(b, x, y, w, h, up, defb, kbf && focus); if ( b->look == NAME_openLook && b->status == NAME_preview && !((z = getClassVariableValueObject(b, NAME_elevation)) && notNil(z)) ) { swapbg = TRUE; r_swap_background_and_foreground(); } if ( notNil(b->popup) && !instanceOfObject(b->label, ClassImage) ) rm = draw_button_popup_indicator(b, x, y, w, h, up); RedrawLabelDialogItem(b, accelerator_code(b->accelerator), x, y, w-rm, h, NAME_center, NAME_center, flags); if ( swapbg ) r_swap_background_and_foreground(); return RedrawAreaGraphical(b, a); }
static status computeArc(Arc a) { if ( notNil(a->request_compute) ) { int minx, miny, maxx, maxy; int sx, sy, ex, ey; int px = valInt(a->position->x); int py = valInt(a->position->y); int sw = valInt(a->size->w); int sh = valInt(a->size->h); points_arc(a, &sx, &sy, &ex, &ey); minx = min(sx, ex); maxx = max(sx, ex); miny = min(sy, ey); maxy = max(sy, ey); if ( angleInArc(a, 0) ) maxx = max(maxx, px + sw); if ( angleInArc(a, 90) ) miny = min(miny, py - sh); if ( angleInArc(a, 180) ) minx = min(minx, px - sw); if ( angleInArc(a, 270) ) maxy = max(maxy, py + sh); if ( a->close == NAME_pieSlice || (a->close == NAME_none && notNil(a->fill_pattern)) ) { maxx = max(maxx, px); minx = min(minx, px); miny = min(miny, py); maxy = max(maxy, py); } minx--; miny--; maxy++; maxx++; if ( a->selected == ON ) /* account for selection blobs */ { minx -= 3; miny -= 3; maxx += 3; maxy += 3; } CHANGING_GRAPHICAL(a, { setArea(a->area, toInt(minx), toInt(miny), toInt(maxx-minx), toInt(maxy-miny)); includeArrowsInAreaArc(a); changedEntireImageGraphical(a); });
static Name getArrowsJoint(Joint jt) { if ( notNil(jt->first_arrow) ) { if ( notNil(jt->second_arrow) ) return NAME_both; else return NAME_first; } else { if ( notNil(jt->second_arrow) ) return NAME_second; else return NAME_none; } }
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); }
status cancelGesture(Gesture g, EventObj ev) { PceWindow sw = ev->window; EventObj fe = sw->focus_event; EventObj oev; addCodeReference(fe); assign(g, active, OFF); send(sw, NAME_focus, NIL, EAV); if ( notNil(fe) ) send(sw, NAME_event, fe, EAV); if ( ev != sw->focus_event ) { addCodeReference(ev); oev = sw->current_event; assign(sw, current_event, NIL); send(sw, NAME_postEvent, ev, EAV); assign(sw, current_event, oev); delCodeReference(ev); } assign(g, active, ON); delCodeReference(fe); freeableObj(fe); assign(g, status, NAME_inactive); succeed; }
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 terminatePopupGesture(PopupGesture g, EventObj ev) { Any context = g->context; PopupObj current = g->current; if ( notNil(current) ) { postEvent(ev, (Graphical) current, DEFAULT); if ( current->displayed == OFF ) /* for stayup */ { PceWindow sw; if ( !(sw = getWindowGraphical(ev->receiver)) ) sw = ev->window; assign(g, context, NIL); assign(g, current, NIL); grabPointerWindow(sw, OFF); send(current, NAME_execute, context, EAV); focusWindow(sw, NIL, NIL, NIL, NIL); } } succeed; }
static status attributeElevation(Elevation e, Name att, Any val) { if ( notNil(e->name) ) return errorPce(e, NAME_readOnly); return slotObject(e, att, val); }
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 int draw_button_popup_indicator(Button b, int x, int y, int w, int h, int up) { int rm; /* required right margin */ if ( notNil(b->popup_image) ) { int iw = valInt(b->popup_image->size->w); int ih = valInt(b->popup_image->size->h); rm = iw+8; r_image(b->popup_image, 0, 0, x+w-rm, y + (h-ih)/2, iw, ih, ON); } else { Elevation z = getClassVariableValueObject(b, NAME_elevation); if ( b->look == NAME_motif || b->look == NAME_gtk ) { int bw = 12; int bh = 8; rm = bw+8; r_3d_box(x+w-bw-8, y+(h-bh)/2, bw, bh, 0, z, TRUE); } else { int th = 8; int tw = 9; int tx, ty; rm = tw+8; tx = x+w-rm; ty = y + (h-th)/2; r_3d_triangle(tx+tw/2, ty+th, tx, ty, tx+tw, ty, z, up, 0x3); rm = tw; } } return rm; }
void table_column_range(Table tab, int *xmin, int *xmax) { Vector rows = tab->rows; int low=0, high=0; int y, ymin, ymax; int first = TRUE; table_row_range(tab, &ymin, &ymax); for(y=ymin; y<=ymax; y++) { TableRow row = getElementVector(rows, toInt(y)); if ( row && notNil(row) ) { int l = valInt(getLowIndexVector((Vector)row)); int h = valInt(getHighIndexVector((Vector)row)); if ( first ) { low = l; high = h; first = FALSE; } else { low = min(low, l); high = max(high, h); } } } *xmin = low; *xmax = high; }
static status unlinkDictItem(DictItem di) { if ( notNil(di->dict) ) return deleteDict(di->dict, di); succeed; }
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 eventHandler(Handler h, EventObj ev) { DEBUG(NAME_post, Cprintf("eventHandler(%s, %s)\n", pp(h), pp(ev))); if ( isAEvent(ev, h->event) ) { if (isDefault(h->region)) { if (isNil(h->message)) succeed; return forwardReceiverCodev(h->message, getMasterEvent(ev), 1, (Any *)&ev); } else { Graphical gr = ev->receiver; if ( insideRegion(h->region, gr->area, getAreaPositionEvent(ev, gr)) == SUCCEED ) { if ( notNil(h->message) ) return forwardReceiverCodev(h->message, getMasterEvent(ev), 1, (Any *)&ev); succeed; } } } fail; }
static status unlinkMenuItem(MenuItem mi) { if ( notNil(mi->menu) ) deleteMenu(mi->menu, mi); succeed; }
static status computeSlider(Slider s) { if ( notNil(s->request_compute) ) { int ny, vx, vy, lx, ly, sx, sy, hx, hy; int w, h; int sw, sh; obtainClassVariablesObject(s); compute_slider(s, &ny, &vx, &vy, &lx, &ly, &sx, &sy, &hx, &hy); h = SLIDER_HEIGHT; h = max(h, ly+valInt(getHeightFont(s->label_font))); h = max(h, vy+valInt(getHeightFont(s->value_font))); if ( s->show_value == ON ) { char buf[100]; string str; sprintf(buf, INTPTR_FORMAT, valInt(s->high)); str_set_ascii(&str, buf); str_size(&str, s->value_font, &sw, &sh); w = hx + sw; } else w = hx; CHANGING_GRAPHICAL(s, assign(s->area, w, toInt(w)); assign(s->area, h, toInt(h))); assign(s, request_compute, NIL); }
static status unlinkTileAdjuster(TileAdjuster adj) { if ( notNil(adj->client) ) assign(adj->client, adjuster, NIL); return unlinkWindow((PceWindow) adj); }
static status unlinkElevation(Elevation e) { if ( notNil(e->name) ) deleteHashTable(ElevationTable, e->name); succeed; }
static status eventTileAdjuster(TileAdjuster adj, EventObj ev) { Int offset; if ( postEventWindow((PceWindow) adj, ev) ) succeed; if ( isDownEvent(ev) && (offset = getEventOffsetTileAdjuster(adj, ev)) ) { send(adj, NAME_focus, adj, DEFAULT, adj->cursor, getButtonEvent(ev), EAV); assign(adj, down_offset, offset); succeed; } else if ( notNil(adj->offset) ) { if ( isDragEvent(ev) ) { DisplayObj d = getDisplayEvent(ev); if ( d && ws_events_queued_display(d) ) succeed; forwardTileAdjuster(adj, ev); } else if ( isUpEvent(ev) ) { forwardTileAdjuster(adj, ev); assign(adj, down_offset, NIL); } succeed; } 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 status computeBezier(Bezier b) { if ( notNil(b->request_compute) ) { CHANGING_GRAPHICAL(b, { computeBoundingBoxBezier(b); changedEntireImageGraphical(b); });
status fillVector(Vector v, Any obj, Int from, Int to) { int f, t; f = (isDefault(from) ? valInt(getLowIndexVector(v)) : valInt(from)); t = (isDefault(to) ? valInt(getHighIndexVector(v)) : valInt(to)); if ( t < f ) fail; if ( v->size == ZERO ) { int size = t-f+1; int n; assign(v, offset, toInt(f - 1)); assign(v, size, toInt(size)); assign(v, allocated, v->size); if ( v->elements ) unalloc(0, v->elements); v->elements = alloc(sizeof(Any) * size); for(n=0; n<size; n++) { v->elements[n] = NIL; if ( notNil(obj) ) assignVector(v, n, obj); } } else { elementVector(v, toInt(f), obj); elementVector(v, toInt(t), obj); while( ++f < t ) elementVector(v, toInt(f), obj); } succeed; }
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); }