static void project_popup_any_cb(ExplorerUI *eui, int type) { TreeItemList items; Quark *q; GraceApp *gapp; GProject *gp; TreeGetHighlighted(eui->tree, &items); if (!items.count || items.count > 1) { xfree(items.items); return; } q = TreeGetQuark(items.items[0]); gapp = gapp_from_quark(q); gp = gproject_from_quark(q); switch (type) { case PROJECT_SHOW_CB: gapp_set_active_gproject(gapp, gp); xdrawgraph(gp); update_all(); break; case PROJECT_SAVE_CB: project_save(gp); break; case PROJECT_SAVE_AS_CB: project_save_as(gp); break; case PROJECT_REVERT_TO_SAVED_CB: revert_project(gapp, gp); xdrawgraph(gapp->gp); update_all(); break; case PROJECT_CLOSE_CB: if (gapp->gpcount == 1) { errmsg("Can't close the last project"); return; } if (gp && gproject_get_top(gp) && quark_dirtystate_get(gproject_get_top(gp)) && !yesno("Abandon unsaved changes?", NULL, NULL, NULL)) { return; } gapp_delete_gproject(gapp, gp); if (gapp->gp == NULL) { gapp_set_active_gproject(gapp, gapp->gplist[0]); } xdrawgraph(gapp->gp); update_all(); break; } xfree(items.items); }
int gapp_set_active_gproject(GraceApp *gapp, GProject *gp) { if (!gapp || !gp) { return RETURN_FAILURE; } if (gapp->gp) { quark_set_active2(gproject_get_top(gapp->gp), FALSE); } quark_set_active2(gproject_get_top(gp), TRUE); gapp->gp = gp; /* reset graal ? */ /* Set dimensions of all devices */ grace_sync_canvas_devices(gp); /* Reset set autocolorization index */ gapp->rt->setcolor = 0; /* Request update of color selectors */ gapp->gui->need_colorsel_update = TRUE; /* Request update of font selectors */ gapp->gui->need_fontsel_update = TRUE; clean_graph_selectors(NULL, QUARK_ETYPE_DELETE, NULL); clean_frame_selectors(NULL, QUARK_ETYPE_DELETE, NULL); return RETURN_SUCCESS; }
static int load_project_file(GraceApp *gapp, const char *fn, int as_template) { GProject *gp; Quark *project, *gr, **graphs; int i, ngraphs; AMem *amem; if (gapp->gp && gproject_get_top(gapp->gp) && quark_dirtystate_get(gproject_get_top(gapp->gp)) && !yesno("Abandon unsaved changes?", NULL, NULL, NULL)) { return RETURN_FAILURE; } gproject_free(gapp->gp); gp = load_any_project(gapp, fn); if (!gp) { errmsg("Failed loading project file"); return RETURN_FAILURE; } project = gproject_get_top(gp); gapp->rt->print_file[0] = '\0'; gapp_set_project(gapp, gp); if (as_template) { grfile_free(gp->grf); gp->grf = NULL; } amem = quark_get_amem(project); /* Set undo limit of 16MB */ amem_set_undo_limit(amem, 0x1000000L); /* Get initial memory snapshot */ amem_snapshot(amem); /* try to switch to the first active graph */ ngraphs = project_get_graphs(project, &graphs); for (i = 0; i < ngraphs; i++) { gr = graphs[i]; if (select_graph(gr) == RETURN_SUCCESS) { break; } } xfree(graphs); #ifndef NONE_GUI select_quark_explorer(project); update_all(); #endif if (project) { return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
int set_page_dimensions(GraceApp *gapp, int wpp, int hpp, int rescale) { if (wpp <= 0 || hpp <= 0 || !gapp || !gapp->gp) { return RETURN_FAILURE; } else { int wpp_old, hpp_old; Project *pr = project_get_data(gproject_get_top(gapp->gp)); if (!pr) { return RETURN_FAILURE; } wpp_old = pr->page_wpp; hpp_old = pr->page_hpp; pr->page_wpp = wpp; pr->page_hpp = hpp; if (rescale) { if (hpp*wpp_old - wpp*hpp_old != 0) { /* aspect ratio changed */ double ext_x, ext_y; double old_aspectr, new_aspectr; old_aspectr = (double) wpp_old/hpp_old; new_aspectr = (double) wpp/hpp; if (old_aspectr >= 1.0 && new_aspectr >= 1.0) { ext_x = new_aspectr/old_aspectr; ext_y = 1.0; } else if (old_aspectr <= 1.0 && new_aspectr <= 1.0) { ext_x = 1.0; ext_y = old_aspectr/new_aspectr; } else if (old_aspectr >= 1.0 && new_aspectr <= 1.0) { ext_x = 1.0/old_aspectr; ext_y = 1.0/new_aspectr; } else { ext_x = new_aspectr; ext_y = old_aspectr; } rescale_viewport(gproject_get_top(gapp->gp), ext_x, ext_y); } } grace_sync_canvas_devices(gapp->gp); return RETURN_SUCCESS; } }
static void explorer_snapshot(GraceApp *gapp, GProject *gp, int all) { if (gp == gapp->gp) { snapshot_and_update(gp, all); } else { amem_snapshot(quark_get_amem(gproject_get_top(gp))); } }
/* * exit gapp */ void bailout(GraceApp *gapp) { int i; for (i = 0; i < gapp->gpcount; i++) { if (gapp->gplist[i] && quark_dirtystate_get(gproject_get_top(gapp->gplist[i]))) { if (yesno("Exit losing unsaved changes?", NULL, NULL, NULL)) { break; } else { return; } } } gapp_free(gapp); exit(0); }
GProject *load_any_project(GraceApp *gapp, const char *fn) { GProject *gp; /* FIXME: A temporary hack */ if (fn && strstr(fn, ".xgr")) { gp = load_xgr_project(gapp, fn); } else { gp = load_agr_project(gapp, fn); } if (gp) { quark_traverse(gproject_get_top(gp), project_hook, NULL); } return gp; }
static int EditStringCB(char **value, int *length, void *data) { fonttool_ui *ui = (fonttool_ui *) data; unsigned char c; static int column = 0, row = 0; char *text; int len = *length; text = *value; TableDeselectCell(ui->font_table, row, column); if (len == 1) { /* */ c = text[0]; row = c/16; column = c % 16; if (ui->valid_chars[c]) { TableSelectCell(ui->font_table, row, column); } else { return FALSE; } } if (ui->new_font) { char *buf; buf = copy_string(NULL, "\\f{"); buf = concat_strings(buf, project_get_font_name_by_id(gproject_get_top(gapp->gp), ui->font_id)); buf = concat_strings(buf, "}"); buf = concat_strings(buf, text); xfree(text); text = copy_string(NULL, buf); *value = text; *length = strlen(buf); xfree(buf); ui->new_font = FALSE; } return TRUE; }
int save_project(GProject *gp, char *fn) { GrFILE *grf; Quark *project = gproject_get_top(gp); GUI *gui = gui_from_quark(project); int noask_save; static int save_unsupported = FALSE; int retval; if (!project || !fn) { return RETURN_FAILURE; } if (fn && strstr(fn, ".agr")) { errmsg("Cowardly refusing to overwrite an agr file"); return RETURN_FAILURE; } if (!save_unsupported && !yesno("The current format may be unsupported by the final release. Continue?", "Yeah, I'm brave!", NULL, "doc/UsersGuide.html#unsupported_format")) { return RETURN_FAILURE; } save_unsupported = TRUE; noask_save = gui->noask; if (strings_are_equal(gproject_get_docname(gp), fn)) { /* If saving under the same name, don't warn about overwriting */ gui->noask = TRUE; } grf = grfile_openw(fn); if (!grf) { return RETURN_FAILURE; } gui->noask = noask_save; retval = gproject_save(gp, grf); grfile_free(grf); return retval; }
/* * Warn about a possible bug displaying the passed message, try to save * any unsaved work and abort */ void emergency_exit(GraceApp *gapp, int is_my_bug, char *msg) { /* * Since we got so far, memory is probably corrupted so it's better to use * a static storage */ static char buf[GR_MAXPATHLEN]; int i; if (gapp->rt->emergency_save != FALSE) { /* don't mind signals anymore: we're in emergency save mode already */ gapp->rt->interrupts++; if (gapp->rt->interrupts > 10) { fprintf(stderr, "oh, no luck :-(\n"); please_report_the_bug(); abort(); } return; } else { gapp->rt->emergency_save = TRUE; gapp->rt->interrupts = 0; fprintf(stderr, "\a\nOops! %s\n", msg); for (i = 0; i < gapp->gpcount; i++) { if (gapp->gplist[i] && quark_dirtystate_get(gproject_get_top(gapp->gplist[i]))) { strcpy(buf, gproject_get_docname(gapp->gplist[i])); strcat(buf, "$"); fprintf(stderr, "Trying to save your work into file \"%s\"... ", buf); fflush(stderr); gapp->gui->noask = TRUE; if (save_project(gapp->gplist[i], buf) == RETURN_SUCCESS) { fprintf(stderr, "ok!\n"); } else { fprintf(stderr, "oh, no luck :-(\n"); } } } if (is_my_bug) { please_report_the_bug(); } abort(); } }
GProject *gproject_from_quark(const Quark *q) { unsigned int i; GraceApp *gapp; GProject *gp; Quark *project = get_parent_project(q); if (!project) { return NULL; } gapp = gapp_from_quark(project); for (i = 0; i < gapp->gpcount; i++) { gp = gapp->gplist[i]; if (gproject_get_top(gp) == project) { return gp; } } return NULL; }
static int project_cb(Quark *pr, int etype, void *data) { if (etype == QUARK_ETYPE_DELETE) { GraceApp *gapp = gapp_from_quark(pr); if (pr == gproject_get_top(gapp->gp)) { gapp->gp = NULL; } } else if (etype == QUARK_ETYPE_MODIFY) { #if 0 /* TODO: */ if ((dirtystate > SOME_LIMIT) || (current_time - autosave_time > ANOTHER_LIMIT) ) { autosave(); } #endif } #ifndef NONE_GUI clean_graph_selectors(pr, etype, data); clean_frame_selectors(pr, etype, data); #endif return RETURN_SUCCESS; }
void raise_explorer(GUI *gui, Quark *q) { GraceApp *gapp = gui->P; set_wait_cursor(); if (!gui->eui) { ExplorerUI *eui; Widget menubar, menupane, panel, form, fr; eui = xmalloc(sizeof(ExplorerUI)); gui->eui = eui; eui->a_icon = XpmToPixmap(active_xpm); eui->h_icon = XpmToPixmap(hidden_xpm); eui->top = CreateDialog(app_shell, "Explorer"); menubar = CreateMenuBar(eui->top); WidgetManage(menubar); FormAddVChild(eui->top, menubar); menupane = CreateMenu(menubar, "File", 'F', FALSE); CreateMenuButtonA(menupane, "Close", 'C', "<Key>Escape", "Esc", destroy_dialog_cb, eui->top); menupane = CreateMenu(menubar, "Edit", 'E', FALSE); eui->edit_undo_bt = CreateMenuButtonA(menupane, "Undo", 'U', "Ctrl<Key>z", "Ctrl+Z", undo_cb, gapp); eui->edit_redo_bt = CreateMenuButtonA(menupane, "Redo", 'R', "Ctrl Shift<Key>z", "Ctrl+Shift+Z", redo_cb, gapp); menupane = CreateMenu(menubar, "Insert", 'I', FALSE); eui->insert_frame_bt = CreateMenuButton(menupane, "Frame", '\0', add_frame_cb, eui); WidgetSetSensitive(eui->insert_frame_bt, FALSE); eui->insert_graph_bt = CreateMenuButton(menupane, "Graph", '\0', add_graph_cb, eui); WidgetSetSensitive(eui->insert_graph_bt, FALSE); eui->insert_ssd_bt = CreateMenuButton(menupane, "SSData", '\0', add_ssd_cb, eui); WidgetSetSensitive(eui->insert_ssd_bt, FALSE); eui->insert_set_bt = CreateMenuButton(menupane, "Set", '\0', add_set_cb, eui); WidgetSetSensitive(eui->insert_set_bt, FALSE); eui->insert_axisgrid_bt = CreateMenuButton(menupane, "Axis grid", '\0', add_axisgrid_cb, eui); WidgetSetSensitive(eui->insert_axisgrid_bt, FALSE); eui->insert_axis_bt = CreateMenuButton(menupane, "Axis", '\0', add_axis_cb, eui); WidgetSetSensitive(eui->insert_axis_bt, FALSE); eui->insert_object_pane = CreateMenu(menupane, "Annotating objects", 'o', FALSE); WidgetSetSensitive(eui->insert_object_pane, FALSE); eui->insert_text_bt = CreateMenuButton(eui->insert_object_pane, "Text", '\0', add_object_cb, eui); eui->insert_line_bt = CreateMenuButton(eui->insert_object_pane, "Line", '\0', add_object_cb, eui); eui->insert_box_bt = CreateMenuButton(eui->insert_object_pane, "Box", '\0', add_object_cb, eui); eui->insert_arc_bt = CreateMenuButton(eui->insert_object_pane, "Arc", '\0', add_object_cb, eui); menupane = CreateMenu(menubar, "Options", 'O', FALSE); eui->instantupdate = CreateMenuToggle(menupane, "Instantaneous update", 'u', NULL, NULL); ToggleButtonSetState(eui->instantupdate, gui->instant_update); menupane = CreateMenu(menubar, "Help", 'H', TRUE); CreateMenuHelpButton(menupane, "On explorer", 'e', eui->top, "doc/UsersGuide.html#explorer"); panel = CreatePanedWindow(eui->top); form = CreateForm(panel); PlaceGridChild(panel, form, 0, 0); /* in case if CreatePanedWindow creates a grid */ eui->tree = CreateTree(form); AddTreeHighlightItemsCB(eui->tree, highlight_cb, eui); AddTreeContextMenuCB(eui->tree, menu_cb, eui); AddTreeDropItemsCB(eui->tree, drop_cb, eui); FormAddVChild(form, eui->tree); fr = CreateFrame(form, NULL); eui->idstr = CreateText(fr, "ID string:"); AddTextActivateCB(eui->idstr, text_explorer_cb, eui); FormAddVChild(form, fr); FormFixateVChild(fr); eui->scrolled_window = CreateScrolledWindow(panel); PlaceGridChild(panel, eui->scrolled_window, 1, 0); /* in case if CreatePanedWindow creates a grid */ PanedWindowSetMinWidth(form, 150); WidgetSetWidth(form, 250); WidgetManage(form); #ifdef HAVE_LESSTIF # if !defined(SF_BUG_993209_FIXED) && !defined(SF_BUG_993209_NOT_FIXED) # error "You should check whether SF bug #993209 is fixed in your version of LessTif." # error "Then define either SF_BUG_993209_FIXED or SF_BUG_993209_NOT_FIXED, accordingly." # error "See http://sourceforge.net/tracker/index.php?func=detail&aid=993209&group_id=8596&atid=108596." # endif # ifdef SF_BUG_993209_NOT_FIXED /* A dirty workaround */ eui->scrolled_window = CreateVContainer(eui->scrolled_window); # endif #endif eui->project_ui = create_project_ui(eui); WidgetUnmanage(eui->project_ui->top); eui->ssd_ui = create_ssd_ui(eui); WidgetUnmanage(eui->ssd_ui->top); eui->frame_ui = create_frame_ui(eui); WidgetUnmanage(eui->frame_ui->top); eui->graph_ui = create_graph_ui(eui); WidgetUnmanage(eui->graph_ui->top); eui->set_ui = create_set_ui(eui); WidgetUnmanage(eui->set_ui->top); eui->axisgrid_ui = create_axisgrid_ui(eui); WidgetUnmanage(eui->axisgrid_ui->top); eui->axis_ui = create_axis_ui(eui); WidgetUnmanage(eui->axis_ui->top); eui->object_ui = create_object_ui(eui); WidgetUnmanage(eui->object_ui->top); eui->atext_ui = create_atext_ui(eui); WidgetUnmanage(eui->atext_ui->top); eui->region_ui = create_region_ui(eui); WidgetUnmanage(eui->region_ui->top); eui->aacbuts = CreateAACDialog(eui->top, panel, explorer_aac, eui); WidgetManage(eui->tree); /* Menu popup */ eui->popup = CreatePopupMenu(eui->tree); eui->popup_hide_bt = CreateMenuButton(eui->popup, "Hide", '\0', hide_cb, eui); eui->popup_show_bt = CreateMenuButton(eui->popup, "Show", '\0', show_cb, eui); CreateMenuSeparator(eui->popup); eui->popup_delete_bt = CreateMenuButton(eui->popup, "Delete", '\0', delete_cb, eui); eui->popup_duplicate_bt = CreateMenuButton(eui->popup, "Duplicate", '\0', duplicate_cb, eui); /* Project menu popup */ eui->project_popup = CreatePopupMenu(eui->tree); eui->project_popup_show_bt = CreateMenuButton(eui->project_popup, "Show", '\0', project_show_cb, eui); CreateMenuSeparator(eui->project_popup); eui->project_popup_save_bt = CreateMenuButton(eui->project_popup, "Save", '\0', project_save_cb, eui); eui->project_popup_save_as_bt = CreateMenuButton(eui->project_popup, "Save as...", '\0', project_save_as_cb, eui); eui->project_popup_revert_to_saved_bt = CreateMenuButton(eui->project_popup, "Revert to saved", '\0', project_revert_to_saved_cb, eui); CreateMenuSeparator(eui->project_popup); eui->project_popup_close_bt = CreateMenuButton(eui->project_popup, "Close", '\0', project_close_cb, eui); init_quark_tree(eui); if (!q && gapp->gp) { select_quark_explorer(gproject_get_top(gapp->gp)); } } #ifdef QT_GUI /* TODO: use resources */ WidgetSetSize(gui->eui->top, 650, 600); #endif DialogRaise(gui->eui->top); if (q) { select_quark_explorer(q); } update_undo_buttons(gapp->gp); unset_wait_cursor(); }
/* * If writing to a file, check to see if it exists */ void do_hardcopy(const GProject *gp) { Quark *project = gproject_get_top(gp); GraceApp *gapp = gapp_from_quark(project); RunTime *rt; Canvas *canvas; char fname[GR_MAXPATHLEN]; view v; double vx, vy; int truncated_out, res; FILE *prstream; if (!gapp) { return; } rt = gapp->rt; canvas = grace_get_canvas(gapp->grace); if (get_ptofile(gapp)) { if (string_is_empty(rt->print_file)) { Device_entry *dev = get_device_props(canvas, rt->hdevice); sprintf(rt->print_file, "%s.%s", QIDSTR(project), dev->fext); } strcpy(fname, rt->print_file); prstream = gapp_openw(gapp, fname); } else { strcpy(fname, "gappXXXXXX"); prstream = gapp_tmpfile(fname); } if (prstream == NULL) { return; } canvas_set_prstream(canvas, prstream); select_device(canvas, rt->hdevice); res = gproject_render(gp); gapp_close(prstream); if (res != RETURN_SUCCESS) { return; } get_bbox(canvas, BBOX_TYPE_GLOB, &v); project_get_viewport(project, &vx, &vy); if (v.xv1 < 0.0 - VP_EPSILON || v.xv2 > vx + VP_EPSILON || v.yv1 < 0.0 - VP_EPSILON || v.yv2 > vy + VP_EPSILON) { truncated_out = TRUE; } else { truncated_out = FALSE; } if (get_ptofile(gapp) == FALSE) { if (truncated_out == FALSE || yesno("Printout is truncated. Continue?", NULL, NULL, NULL)) { gapp_print(gapp, fname); #ifndef PRINT_CMD_UNLINKS remove(fname); #endif } } else { if (truncated_out == TRUE) { errmsg("Output is truncated - tune device dimensions"); } } }
int gapp_get_gproject_id(GraceApp *gapp, GProject *gp) { Quark *q = gproject_get_top(gp); return quark_get_id(q); }
int gapp_set_gproject_id(GraceApp *gapp, GProject *gp, int id) { Quark *q = gproject_get_top(gp); return quark_move2(q, quark_parent_get(q), id); }
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; }
/* * process complete lines that have already been read */ static int process_complete_lines(GraceApp *gapp, Input_buffer *ib) { int line_corrupted; char *begin_of_line, *end_of_line; char buf[256]; if (ib->used <= 0) { return RETURN_SUCCESS; } end_of_line = NULL; do { /* loop over the embedded lines */ begin_of_line = (end_of_line == NULL) ? ib->buf : (end_of_line + 1); end_of_line = begin_of_line; line_corrupted = 0; while (end_of_line != NULL && *end_of_line != '\n') { /* trying to find a complete line */ if (end_of_line == ib->buf + ib->used) { end_of_line = NULL; } else { if (*end_of_line == '\0') { line_corrupted = 1; } ++end_of_line; } } if (end_of_line != NULL) { /* we have a whole line */ ++(ib->lineno); *end_of_line = '\0'; close_input = NULL; if (line_corrupted || graal_parse_line(grace_get_graal(gapp->grace), begin_of_line, gproject_get_top(gapp->gp)) != RETURN_SUCCESS) { sprintf(buf, "Error at line %d", ib->lineno); errmsg(buf); ++(ib->errors); if (ib->errors > MAXERR) { #ifndef NONE_GUI /* this prevents from being called recursively by the inner X loop of yesno */ xunregister_rti(ib); #endif if (yesno("Lots of errors, abort?", NULL, NULL, NULL)) { close_input = copy_string(close_input, ""); } #ifndef NONE_GUI xregister_rti(ib); #endif ib->errors = 0; } } if (close_input != NULL) { /* something should be closed */ if (close_input[0] == '\0') { unregister_real_time_input(ib->name); } else { unregister_real_time_input(close_input); } xfree(close_input); close_input = NULL; if (ib->fd < 0) { /* we have closed ourselves */ return RETURN_SUCCESS; } } } } while (end_of_line != NULL); if (end_of_line != NULL) { /* the line has just been processed */ begin_of_line = end_of_line + 1; } if (begin_of_line > ib->buf) { /* move the remaining data to the beginning */ ib->used -= begin_of_line - ib->buf; memmove(ib->buf, begin_of_line, ib->used); ib->buf[ib->used] = '\0'; } return RETURN_SUCCESS; }