static int hook(Quark *q, void *udata, QTraverseClosure *closure) { frame *f; view v; DObject *o; AText *at; ext_xy_t *ext_xy = (ext_xy_t *) udata; switch (quark_fid_get(q)) { case QFlavorFrame: f = frame_get_data(q); frame_get_view(q, &v); v.xv1 *= ext_xy->x; v.xv2 *= ext_xy->x; v.yv1 *= ext_xy->y; v.yv2 *= ext_xy->y; frame_set_view(q, &v); f->l.offset.x *= ext_xy->x; f->l.offset.y *= ext_xy->y; /* TODO: tickmark offsets */ quark_dirtystate_set(q, TRUE); break; case QFlavorDObject: o = object_get_data(q); if (object_get_loctype(q) == COORD_VIEW) { o->ap.x *= ext_xy->x; o->ap.y *= ext_xy->y; o->offset.x *= ext_xy->x; o->offset.y *= ext_xy->y; quark_dirtystate_set(q, TRUE); } break; case QFlavorAText: at = atext_get_data(q); if (object_get_loctype(q) == COORD_VIEW) { at->ap.x *= ext_xy->x; at->ap.y *= ext_xy->y; at->offset.x *= ext_xy->x; at->offset.y *= ext_xy->y; quark_dirtystate_set(q, TRUE); } break; } return TRUE; }
int ssd_reverse(Quark *q) { ss_data *ssd = ssd_get_data(q); int nrows, ncols, i, j, k; if (!ssd) { return RETURN_FAILURE; } nrows = ssd_get_nrows(q); ncols = ssd_get_ncols(q); for (k = 0; k < ncols; k++) { ss_column *col = &ssd->cols[k]; if (col->format == FFORMAT_STRING) { char **s = col->data; for (i = 0; i < nrows/2; i++) { j = (nrows - 1) - i; sswap(&s[i], &s[j]); } } else { double *x = col->data; for (i = 0; i < nrows/2; i++) { j = (nrows - 1) - i; fswap(&x[i], &x[j]); } } } quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; }
void move_legend(Quark *fr, const VVector *shift) { legend *l = frame_get_legend(fr); if (l) { l->offset.x += shift->x; l->offset.y += shift->y; quark_dirtystate_set(fr, TRUE); } }
int project_set_description(Quark *q, char *descr) { Project *pr = project_get_data(q); if (pr) { pr->description = amem_strcpy(q->amem, pr->description, descr); quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int project_set_fontsize_scale(Quark *q, double fscale) { Project *pr = project_get_data(q); if (pr) { pr->fscale = fscale; quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int project_set_linewidth_scale(Quark *q, double lscale) { Project *pr = project_get_data(q); if (pr) { pr->lscale = lscale; quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int project_set_version_id(Quark *q, int version_id) { Project *pr = project_get_data(q); if (pr) { pr->version_id = version_id; quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int set_object_data(ObjectUI *ui, Quark *q, void *caller) { DObject *o = object_get_data(q); if (o && ui) { if (!caller || caller == ui->x) { xv_evalexpr(ui->x, &o->ap.x); } if (!caller || caller == ui->y) { xv_evalexpr(ui->y, &o->ap.y); } if (!caller || caller == ui->offsetx) { o->offset.x = SpinChoiceGetValue(ui->offsetx); } if (!caller || caller == ui->offsety) { o->offset.y = SpinChoiceGetValue(ui->offsety); } if (!caller || caller == ui->angle) { o->angle = GetAngleChoice(ui->angle); } if (!caller || caller == ui->linew) { o->line.width = SpinChoiceGetValue(ui->linew); } if (!caller || caller == ui->lines) { o->line.style = GetOptionChoice(ui->lines); } if (!caller || caller == ui->linepen) { GetPenChoice(ui->linepen, &o->line.pen); } if (!caller || caller == ui->fillpen) { GetPenChoice(ui->fillpen, &o->fillpen); } switch (o->type) { case DO_LINE: set_line_odata(ui->line_ui, (DOLineData *) o->odata, caller); break; case DO_BOX: set_box_odata(ui->box_ui, (DOBoxData *) o->odata, caller); break; case DO_ARC: set_arc_odata(ui->arc_ui, (DOArcData *) o->odata, caller); break; default: break; } quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int project_set_prec(Quark *q, unsigned int prec) { Project *pr = project_get_data(q); if (pr && prec >= DATA_PREC_MIN && prec <= DATA_PREC_MAX) { pr->prec = prec; quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int project_set_ref_date(Quark *q, double ref) { Project *pr = project_get_data(q); if (pr) { pr->ref_date = ref; quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int project_allow_two_digits_years(Quark *q, int flag) { Project *pr = project_get_data(q); if (pr) { pr->two_digits_years = flag; quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int project_set_page_dimensions(Quark *q, int wpp, int hpp) { Project *pr = project_get_data(q); if (pr) { pr->page_wpp = wpp; pr->page_hpp = hpp; quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int set_point(Quark *pset, int seti, const WPoint *wp) { if (!pset) { return RETURN_FAILURE; } if (seti >= set_get_length(pset) || seti < 0) { return RETURN_FAILURE; } (set_get_col(pset, DATA_X))[seti] = wp->x; (set_get_col(pset, DATA_Y))[seti] = wp->y; quark_dirtystate_set(pset, TRUE); return RETURN_SUCCESS; }
/* * store the wrap year */ int project_set_wrap_year(Quark *q, int year) { Project *pr = project_get_data(q); if (pr) { pr->wrap_year = year; quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int ssd_transpose(Quark *q) { ss_data *ssd_new, *ssd_old; unsigned int ncols, nrows, i, j; if (!ssd_is_numeric(q)) { return RETURN_FAILURE; } ncols = ssd_get_ncols(q); nrows = ssd_get_nrows(q); if (!ncols || !nrows) { return RETURN_FAILURE; } ssd_new = ssd_data_new(q->amem); if (!ssd_new) { return RETURN_FAILURE; } /* swap the data */ ssd_old = q->data; q->data = ssd_new; if (ssd_set_ncols(q, nrows, NULL) != RETURN_SUCCESS || ssd_set_nrows(q, ncols) != RETURN_SUCCESS) { ssd_data_free(q->amem, ssd_new); q->data = ssd_old; return RETURN_FAILURE; } for (i = 0; i < ncols; i++) { for (j = 0; j < nrows; j++) { ssd_set_value(q, i, j, ((double *)ssd_old->cols[i].data)[j]); } } quark_dirtystate_set(q, TRUE); ssd_data_free(q->amem, ssd_old); return RETURN_SUCCESS; }
/* * drop rows */ int ssd_delete_rows(Quark *q, unsigned int startno, unsigned int endno) { ss_data *ssd = ssd_get_data(q); unsigned int i, j, dist; if (!ssd || startno >= ssd->nrows || endno >= ssd->nrows) { return RETURN_FAILURE; } if (endno < startno) { uswap(&endno, &startno); } if (endno == ssd->nrows - 1) { /* trivial case */ return ssd_set_nrows(q, startno); } dist = endno - startno + 1; for (j = 0; j < ssd->ncols; j++) { ss_column *col = &ssd->cols[j]; if (col->format == FFORMAT_STRING) { char **s = col->data; for (i = startno; i <= endno; i++) { amem_free(q->amem, s[i]); } memmove(s + startno, s + endno + 1, (ssd->nrows - endno - 1)*SIZEOF_VOID_P); } else { double *x = col->data; memmove(x + startno, x + endno + 1, (ssd->nrows - endno - 1)*SIZEOF_DOUBLE); } } ssd->nrows -= dist; quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; }
int set_set_colors(Quark *pset, unsigned int color) { set *p = set_get_data(pset); GraceApp *gapp = gapp_from_quark(pset); if (!p || !gapp) { return RETURN_FAILURE; } if (color < number_of_colors(grace_get_canvas(gapp->grace))) { p->line.line.pen.color = color; p->sym.line.pen.color = color; p->sym.fillpen.color = color; p->errbar.pen.color = color; quark_dirtystate_set(pset, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
void sortset(Quark *pset, int sorton, int stype) { int i, j, nc, len, *ind; double *x, *xtmp; char **s, **stmp; /* get the vector to sort on */ vptr = set_get_col(pset, sorton); if (vptr == NULL) { errmsg("NULL vector in sort, operation cancelled, check set type"); return; } len = set_get_length(pset); if (len <= 1) { return; } /* allocate memory for permuted indices */ ind = xmalloc(len*SIZEOF_INT); if (ind == NULL) { return; } /* allocate memory for temporary array */ xtmp = xmalloc(len*SIZEOF_DOUBLE); if (xtmp == NULL) { xfree(ind); return; } s = set_get_strings(pset); if (s != NULL) { stmp = xmalloc(len*sizeof(char *)); if (stmp == NULL) { xfree(xtmp); xfree(ind); } } else { stmp = NULL; } /* initialize indices */ for (i = 0; i < len; i++) { ind[i] = i; } /* sort */ qsort(ind, len, SIZEOF_INT, stype ? compare_points2 : compare_points1); /* straighten things out - done one vector at a time for storage */ nc = set_get_ncols(pset); /* loop over the number of columns */ for (j = 0; j < nc; j++) { /* get this vector and put into the temporary vector in the right order */ x = set_get_col(pset, j); for (i = 0; i < len; i++) { xtmp[i] = x[ind[i]]; } /* load it back to the set */ for (i = 0; i < len; i++) { x[i] = xtmp[i]; } } /* same with strings, if any */ if (s != NULL) { for (i = 0; i < len; i++) { stmp[i] = s[ind[i]]; } for (i = 0; i < len; i++) { s[i] = stmp[i]; } } /* free allocated temporary arrays */ xfree(stmp); xfree(xtmp); xfree(ind); quark_dirtystate_set(pset, TRUE); }
int set_axisgrid_data(AGridUI *ui, Quark *q, void *caller) { tickmarks *t = axisgrid_get_data(q); if (t && ui) { AMem *amem = quark_get_amem(q); int i; if (!caller || caller == ui->type) { t->type = GetOptionChoice(ui->type); } if (!caller || caller == ui->tmajor) { if (xv_evalexpr(ui->tmajor, &t->tmajor) != RETURN_SUCCESS) { errmsg("Specify major tick spacing"); return RETURN_FAILURE; } } if (!caller || caller == ui->nminor) { t->nminor = (int) SpinChoiceGetValue(ui->nminor); } if (!caller || caller == ui->tlform) { Format *format = GetFormatChoice(ui->tlform); AMem *amem = quark_get_amem(q); amem_free(amem, t->tl_format.fstring); t->tl_format = *format; t->tl_format.fstring = amem_strdup(amem, format->fstring); format_free(format); } if (!caller || caller == ui->tlfont) { t->tl_tprops.font = GetOptionChoice(ui->tlfont); } if (!caller || caller == ui->tlcolor) { t->tl_tprops.color = GetOptionChoice(ui->tlcolor); } if (!caller || caller == ui->barpen) { GetPenChoice(ui->barpen, &t->bar.pen); } if (!caller || caller == ui->barlinew) { t->bar.width = SpinChoiceGetValue(ui->barlinew); } if (!caller || caller == ui->barlines) { t->bar.style = GetOptionChoice(ui->barlines); } if (!caller || caller == ui->tlcharsize) { t->tl_tprops.charsize = SpinChoiceGetValue(ui->tlcharsize); } if (!caller || caller == ui->tlangle) { t->tl_tprops.angle = GetAngleChoice(ui->tlangle); } if (!caller || caller == ui->tlstagger) { t->tl_staggered = GetOptionChoice(ui->tlstagger); } if (!caller || caller == ui->tlstarttype) { t->tl_starttype = GetOptionChoice(ui->tlstarttype) == 0 ? TYPE_AUTO : TYPE_SPEC; } if (!caller || caller == ui->tlstart) { if (t->tl_starttype == TYPE_SPEC) { if (xv_evalexpr(ui->tlstart, &t->tl_start) != RETURN_SUCCESS) { errmsg("Specify tick label start"); return RETURN_FAILURE; } } } if (!caller || caller == ui->tlstoptype) { t->tl_stoptype = GetOptionChoice(ui->tlstoptype) == 0 ? TYPE_AUTO : TYPE_SPEC; } if (!caller || caller == ui->tlstop) { if (t->tl_stoptype == TYPE_SPEC) { if (xv_evalexpr(ui->tlstop, &t->tl_stop) != RETURN_SUCCESS) { errmsg("Specify tick label stop"); return RETURN_FAILURE; } } } if (!caller || caller == ui->tlskip) { t->tl_skip = GetOptionChoice(ui->tlskip); } if (!caller || caller == ui->tlformula) { char *s = TextGetString(ui->tlformula); t->tl_formula = amem_strcpy(amem, t->tl_formula, s); xfree(s); } if (!caller || caller == ui->tlprestr) { char *s = TextGetString(ui->tlprestr); t->tl_prestr = amem_strcpy(amem, t->tl_prestr, s); xfree(s); } if (!caller || caller == ui->tlappstr) { char *s = TextGetString(ui->tlappstr); t->tl_appstr = amem_strcpy(amem, t->tl_appstr, s); xfree(s); } if (!caller || caller == ui->tlgap_para) { xv_evalexpr(ui->tlgap_para, &t->tl_gap.x); } if (!caller || caller == ui->tlgap_perp) { xv_evalexpr(ui->tlgap_perp, &t->tl_gap.y); } if (!caller || caller == ui->tround) { t->t_round = ToggleButtonGetState(ui->tround); } if (!caller || caller == ui->autonum) { t->t_autonum = GetOptionChoice(ui->autonum) + 2; } if (!caller || caller == ui->tgrid) { t->gprops.onoff = ToggleButtonGetState(ui->tgrid); } if (!caller || caller == ui->tgridpen) { GetPenChoice(ui->tgridpen, &t->gprops.line.pen); } if (!caller || caller == ui->tgridlinew) { t->gprops.line.width = SpinChoiceGetValue(ui->tgridlinew); } if (!caller || caller == ui->tgridlines) { t->gprops.line.style = GetOptionChoice(ui->tgridlines); } if (!caller || caller == ui->tmgrid) { t->mgprops.onoff = ToggleButtonGetState(ui->tmgrid); } if (!caller || caller == ui->tmgridpen) { GetPenChoice(ui->tmgridpen, &t->mgprops.line.pen); } if (!caller || caller == ui->tmgridlinew) { t->mgprops.line.width = SpinChoiceGetValue(ui->tmgridlinew); } if (!caller || caller == ui->tmgridlines) { t->mgprops.line.style = GetOptionChoice(ui->tmgridlines); } if (!caller || caller == ui->tinout) { t->props.inout = GetOptionChoice(ui->tinout); } if (!caller || caller == ui->tlen) { t->props.size = SpinChoiceGetValue(ui->tlen); } if (!caller || caller == ui->tpen) { GetPenChoice(ui->tpen, &t->props.line.pen); } if (!caller || caller == ui->tgridlinew) { t->props.line.width = SpinChoiceGetValue(ui->tlinew); } if (!caller || caller == ui->tgridlines) { t->props.line.style = GetOptionChoice(ui->tlines); } if (!caller || caller == ui->tminout) { t->mprops.inout = GetOptionChoice(ui->tminout); } if (!caller || caller == ui->tmlen) { t->mprops.size = SpinChoiceGetValue(ui->tmlen); } if (!caller || caller == ui->tmpen) { GetPenChoice(ui->tmpen, &t->mprops.line.pen); } if (!caller || caller == ui->tmgridlinew) { t->mprops.line.width = SpinChoiceGetValue(ui->tmlinew); } if (!caller || caller == ui->tmgridlines) { t->mprops.line.style = GetOptionChoice(ui->tmlines); } if (!caller || caller == ui->specticks || caller == ui->nspec || caller == ui->specloc) { t->t_spec = GetOptionChoice(ui->specticks); /* only read special info if special ticks used */ if (t->t_spec != TICKS_SPEC_NONE) { t->nticks = (int) SpinChoiceGetValue(ui->nspec); /* ensure that enough tick positions have been specified */ for (i = 0; i < t->nticks; i++) { if (xv_evalexpr(ui->specloc[i], &t->tloc[i].wtpos) == RETURN_SUCCESS) { char *cp, *s; cp = TextGetString(ui->speclabel[i]); if (cp[0] == '\0') { t->tloc[i].type = TICK_TYPE_MINOR; } else { t->tloc[i].type = TICK_TYPE_MAJOR; } if (t->t_spec == TICKS_SPEC_BOTH) { s = cp; } else { s = NULL; } t->tloc[i].label = amem_strcpy(amem, t->tloc[i].label, s); xfree(cp); } } } } quark_dirtystate_set(q, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int graph_set_data(GraphUI *ui, Quark *q, void *caller) { if (quark_fid_get(q) == QFlavorGraph) { double axislim, znorm; world w; GLocator *locator; graph_get_world(q, &w); locator = graph_get_locator(q); if (!caller || caller == ui->graph_type) { graph_set_type(q, GetOptionChoice(ui->graph_type)); } if (!caller || caller == ui->stacked) { graph_set_stacked(q, GetToggleButtonState(ui->stacked)); } if (!caller || caller == ui->flip_xy) { graph_set_xyflip(q, GetToggleButtonState(ui->flip_xy)); } if (!caller || caller == ui->start_x) { if (xv_evalexpr(ui->start_x, &axislim) != RETURN_SUCCESS) { errmsg("Axis start/stop values undefined"); return RETURN_FAILURE; } w.xg1 = axislim; } if (!caller || caller == ui->stop_x) { if (xv_evalexpr(ui->stop_x, &axislim) != RETURN_SUCCESS) { errmsg("Axis start/stop values undefined"); return RETURN_FAILURE; } w.xg2 = axislim; } if (!caller || caller == ui->start_y) { if (xv_evalexpr(ui->start_y, &axislim) != RETURN_SUCCESS) { errmsg("Axis start/stop values undefined"); return RETURN_FAILURE; } w.yg1 = axislim; } if (!caller || caller == ui->stop_y) { if (xv_evalexpr(ui->stop_y, &axislim) != RETURN_SUCCESS) { errmsg("Axis start/stop values undefined"); return RETURN_FAILURE; } w.yg2 = axislim; } if (!caller || caller == ui->start_x || caller == ui->stop_x || caller == ui->start_y || caller == ui->stop_y) { graph_set_world(q, &w); } if (!caller || caller == ui->scale_x) { graph_set_xscale(q, GetOptionChoice(ui->scale_x)); } if (!caller || caller == ui->invert_x) { graph_set_xinvert(q, GetToggleButtonState(ui->invert_x)); } if (!caller || caller == ui->scale_y) { graph_set_yscale(q, GetOptionChoice(ui->scale_y)); } if (!caller || caller == ui->invert_y) { graph_set_yinvert(q, GetToggleButtonState(ui->invert_y)); } if (!caller || caller == ui->bargap) { graph_set_bargap(q, GetSpinChoice(ui->bargap)); } if (!caller || caller == ui->znorm) { xv_evalexpr(ui->znorm, &znorm); graph_set_znorm(q, znorm); } if (!caller || caller == ui->loc_type) { locator->type = GetOptionChoice(ui->loc_type); quark_dirtystate_set(q, TRUE); } if (!caller || caller == ui->loc_fx) { Format *format = GetFormatChoice(ui->loc_fx); AMem *amem = quark_get_amem(q); amem_free(amem, locator->fx.fstring); locator->fx = *format; locator->fx.fstring = amem_strdup(amem, format->fstring); format_free(format); quark_dirtystate_set(q, TRUE); } if (!caller || caller == ui->loc_fy) { Format *format = GetFormatChoice(ui->loc_fy); AMem *amem = quark_get_amem(q); amem_free(amem, locator->fy.fstring); locator->fy = *format; locator->fy.fstring = amem_strdup(amem, format->fstring); format_free(format); quark_dirtystate_set(q, TRUE); } if (!caller || caller == ui->fixedp) { locator->pointset = GetToggleButtonState(ui->fixedp); quark_dirtystate_set(q, TRUE); } if (!caller || caller == ui->locx) { xv_evalexpr(ui->locx, &locator->origin.x); quark_dirtystate_set(q, TRUE); } if (!caller || caller == ui->locy) { xv_evalexpr(ui->locy, &locator->origin.y); quark_dirtystate_set(q, TRUE); } return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int set_project_data(ProjectUI *ui, Quark *q, void *caller) { Project *pr = project_get_data(q); int retval = RETURN_SUCCESS; if (ui && pr) { GraceApp *gapp = gapp_from_quark(q); double jul; if (!caller || caller == ui->prec) { project_set_prec(q, GetSpinChoice(ui->prec)); } if (!caller || caller == ui->description) { char *s = TextGetString(ui->description); project_set_description(q, s); xfree(s); } if (caller == ui->page_orient) { int wpp, hpp; int orientation = GetOptionChoice(ui->page_orient); project_get_page_dimensions(q, &wpp, &hpp); if ((orientation == PAGE_ORIENT_LANDSCAPE && wpp < hpp) || (orientation == PAGE_ORIENT_PORTRAIT && wpp > hpp)) { set_page_dimensions(gapp, hpp, wpp, TRUE); } } if (caller == ui->page_format) { int wpp, hpp; int orientation = GetOptionChoice(ui->page_orient); int format = GetOptionChoice(ui->page_format); GraceApp *gapp = gapp_from_quark(q); switch (format) { case PAGE_FORMAT_USLETTER: wpp = 792.0; hpp = 612.0; break; case PAGE_FORMAT_A4: wpp = 842.0; hpp = 595.0; break; default: return RETURN_SUCCESS; } if (orientation == PAGE_ORIENT_PORTRAIT) { iswap(&wpp, &hpp); } set_page_dimensions(gapp, wpp, hpp, TRUE); } if (!caller || caller == ui->page_x || caller == ui->page_y) { int page_units = GetOptionChoice(ui->page_size_unit); double factor, page_x, page_y; GraceApp *gapp = gapp_from_quark(q); if (xv_evalexpr(ui->page_x, &page_x) != RETURN_SUCCESS || xv_evalexpr(ui->page_y, &page_y) != RETURN_SUCCESS) { errmsg("Invalid page dimension(s)"); return RETURN_FAILURE; } switch (page_units) { case PAGE_UNITS_IN: factor = 72.0; break; case PAGE_UNITS_CM: factor = 72.0/CM_PER_INCH; break; default: factor = 1.0; break; } page_x *= factor; page_y *= factor; set_page_dimensions(gapp, (int) rint(page_x), (int) rint(page_y), TRUE); } if (!caller || caller == ui->bg_color) { pr->bgcolor = GetOptionChoice(ui->bg_color); } if (!caller || caller == ui->bg_fill) { pr->bgfill = GetToggleButtonState(ui->bg_fill); } if (!caller || caller == ui->fsize_scale) { pr->fscale = GetSpinChoice(ui->fsize_scale); } if (!caller || caller == ui->lwidth_scale) { pr->lscale = GetSpinChoice(ui->lwidth_scale); } if (!caller || caller == ui->refdate) { char *s = TextGetString(ui->refdate); if (parse_date_or_number(q, s, TRUE, get_date_hint(gapp), &jul) == RETURN_SUCCESS) { pr->ref_date = jul; } else { errmsg("Invalid date"); retval = RETURN_FAILURE; } xfree(s); } if (!caller || caller == ui->two_digits_years) { pr->two_digits_years = GetToggleButtonState(ui->two_digits_years); } if (!caller || caller == ui->wrap_year) { char *s = TextGetString(ui->wrap_year); pr->wrap_year = atoi(s); xfree(s); } quark_dirtystate_set(q, TRUE); } return retval; }
static int leaveCB(TableEvent *event) { SSDataUI *ui = (SSDataUI *) event->anydata; int nrows = ssd_get_nrows(ui->q); int ncols = ssd_get_ncols(ui->q); int format; double value; int changed = FALSE; GraceApp *gapp = gapp_from_quark(ui->q); if (event->row < 0 || event->col < 0 || event->col > ncols) { return TRUE; } if (event->row >= nrows && !string_is_empty(event->value)) { if (ssd_set_nrows(ui->q, event->row + 1) == RETURN_SUCCESS) { changed = TRUE; } } if (event->col == ncols && !string_is_empty(event->value)) { if (parse_date_or_number(get_parent_project(ui->q), event->value, FALSE, get_date_hint(gapp), &value) == RETURN_SUCCESS) { format = FFORMAT_NUMBER; } else { format = FFORMAT_STRING; } if (ssd_add_col(ui->q, format)) { ncols++; changed = TRUE; } } if (event->col < ncols) { char *old_value = get_cell_content(ui, event->row, event->col, &format); if (!strings_are_equal(old_value, event->value)) { switch (format) { case FFORMAT_STRING: if (ssd_set_string(ui->q, event->row, event->col, event->value) == RETURN_SUCCESS) { quark_dirtystate_set(ui->q, TRUE); changed = TRUE; } break; default: if (graal_eval_expr(grace_get_graal(gapp->grace), event->value, &value, gproject_get_top(gapp->gp)) == RETURN_SUCCESS) { unsigned int prec; char buf[32]; double val; prec = project_get_prec(get_parent_project(ui->q)); sprintf(buf, "%.*g", prec, value); if (parse_date_or_number(get_parent_project(ui->q), buf, FALSE, get_date_hint(gapp), &val) == RETURN_SUCCESS) { if (ssd_set_value(ui->q, event->row, event->col, val) == RETURN_SUCCESS) { quark_dirtystate_set(ui->q, TRUE); changed = TRUE; } } } else { errmsg("Can't parse input value"); return FALSE; } break; } } } if (changed) { snapshot_and_update(gapp->gp, FALSE); } return TRUE; }