Exemple #1
0
static int fonttool_aac_cb(void *data)
{
    fonttool_ui *ui = (fonttool_ui *) data;
    if (ui->cstext_parent != NULL) {
        char *s = TextGetString(ui->cstext);
        int pos = TextGetCursorPos(ui->cstext);
        TextSetString(ui->cstext_parent, s);
        TextSetCursorPos(ui->cstext_parent, pos);
        xfree(s);
    }
    
    return RETURN_SUCCESS;
}
Exemple #2
0
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;
    }
}
Exemple #3
0
static int explorer_apply(ExplorerUI *ui, void *caller)
{
    TreeItemList items;
    int count, i, res = RETURN_SUCCESS;

    int gpcount = 0;
    GProject **gplist;
    
    if (caller && !ToggleButtonGetState(ui->instantupdate)) {
        return RETURN_FAILURE;
    }
    
    TreeGetHighlighted(ui->tree, &items);
    count = items.count;

    if (!count) {
        xfree(items.items);
        return RETURN_FAILURE;
    }

    gplist = xmalloc(gapp->gpcount*sizeof(GProject));
    if (!gplist) {
        return RETURN_FAILURE;
    }

    for (i = 0; i < count && res == RETURN_SUCCESS; i++) {
        Quark *q = TreeGetQuark(items.items[i]);

        add_to_list(gplist, &gpcount, gproject_from_quark(q));

        if (count == 1 && (!caller || caller == ui->idstr)) {
            char *s = TextGetString(ui->idstr);
            quark_idstr_set(q, s);
            xfree(s);
        }

        switch (quark_fid_get(q)) {
        case QFlavorProject:
            if (set_project_data(ui->project_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorSSD:
            if (set_ssd_data(ui->ssd_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorFrame:
            if (set_frame_data(ui->frame_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorGraph:
            if (graph_set_data(ui->graph_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorSet:
            if (set_set_data(ui->set_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorAGrid:
            if (set_axisgrid_data(ui->axisgrid_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorAxis:
            if (set_axis_data(ui->axis_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorDObject:
            if (set_object_data(ui->object_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorAText:
            if (set_atext_data(ui->atext_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        case QFlavorRegion:
            if (set_region_data(ui->region_ui, q, caller) != RETURN_SUCCESS) {
                res = RETURN_FAILURE;
            }
            break;
        default:
            res = RETURN_FAILURE;
            break;
        }
    }
    xfree(items.items);

    for (i = 0; i < gpcount; i++) {
        explorer_snapshot(gapp, gplist[i], FALSE);
    }
    xfree(gplist);

    return res;
}
Exemple #4
0
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;
}
Exemple #5
0
void create_fonttool(TextStructure *cstext_parent)
{
    static fonttool_ui *ui = NULL;
    
    if (ui == NULL) {
        ui = xmalloc(sizeof(fonttool_ui));
        memset(ui, 0, sizeof(fonttool_ui));
	
        ui->fonttool_panel = CreateDialog(app_shell, "Font tool");

        ui->font_select = CreateFontChoice(ui->fonttool_panel, "Font:");
        FormAddVChild(ui->fonttool_panel, ui->font_select->menu);
        
        ui->font_table = CreateTable("fontTable", ui->fonttool_panel,
                                     FONT_TOOL_ROWS, FONT_TOOL_COLS,
                                     8, 16);
        TableFontInit(ui->font_table);
        TableSetDefaultColWidth(ui->font_table, 2);
        TableSetDefaultColAlignment(ui->font_table, ALIGN_BEGINNING);
        TableUpdateVisibleRowsCols(ui->font_table);

        AddTableDrawCellCB(ui->font_table, DrawCB, ui);
        AddTableEnterCellCB(ui->font_table, EnterCB, ui);
        AddOptionChoiceCB(ui->font_select, update_fonttool_cb, ui);

        FormAddVChild(ui->fonttool_panel, ui->font_table);

        ui->cstext = CreateCSText(ui->fonttool_panel, "CString:");

        AddTextValidateCB(ui->cstext, EditStringCB, ui);
        
        ui->aac_buts = CreateAACDialog(ui->fonttool_panel,
            ui->cstext->form, fonttool_aac_cb, ui);

        FormFixateVChild(ui->cstext->form);
        
        update_fonttool_cb(NULL, 0, ui);
    }

    if (cstext_parent == ui->cstext) {
        /* avoid recursion */
        return;
    }
    
    ui->cstext_parent = cstext_parent;
    
    if (ui->cstext_parent == NULL) {
        TextSetString(ui->cstext, "");
        WidgetSetSensitive(ui->aac_buts[0], FALSE);
        WidgetSetSensitive(ui->aac_buts[1], FALSE);
    } else {
        char *s = TextGetString(ui->cstext_parent);
        int pos = TextGetCursorPos(ui->cstext_parent);
        TextSetString(ui->cstext, s);
        TextSetCursorPos(ui->cstext, pos);
        xfree(s);
        WidgetSetSensitive(ui->aac_buts[0], TRUE);
        WidgetSetSensitive(ui->aac_buts[1], TRUE);
    }
    
    DialogRaise(ui->fonttool_panel);
}