static void gnc_column_view_edit_size_cb(GtkButton * button, gpointer user_data) { gnc_column_view_edit * r = user_data; GtkWidget * rowspin; GtkWidget * colspin; GtkWidget * dlg; GladeXML *xml; SCM current; int length; int dlg_ret; xml = gnc_glade_xml_new ("report.glade", "Edit Report Size"); dlg = glade_xml_get_widget (xml, "Edit Report Size"); /* get the spinner widgets */ rowspin = glade_xml_get_widget (xml, "row_spin"); colspin = glade_xml_get_widget (xml, "col_spin"); length = scm_ilength(r->contents_list); if (length > r->contents_selected) { current = scm_list_ref(r->contents_list, scm_int2num(r->contents_selected)); gtk_spin_button_set_value(GTK_SPIN_BUTTON(colspin), (float)scm_num2int(SCM_CADR(current), SCM_ARG1, G_STRFUNC)); gtk_spin_button_set_value(GTK_SPIN_BUTTON(rowspin), (float)scm_num2int(SCM_CADDR(current), SCM_ARG1, G_STRFUNC)); dlg_ret = gtk_dialog_run(GTK_DIALOG(dlg)); gtk_widget_hide(dlg); if (dlg_ret == GTK_RESPONSE_OK) { current = SCM_LIST4(SCM_CAR(current), scm_int2num(gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(colspin))), scm_int2num(gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(rowspin))), SCM_BOOL_F); scm_gc_unprotect_object(r->contents_list); r->contents_list = scm_list_set_x(r->contents_list, scm_int2num(r->contents_selected), current); scm_gc_protect_object(r->contents_list); gnc_options_dialog_changed (r->optwin); update_display_lists(r); } gtk_widget_destroy(dlg); } }
static GncOwnerType get_owner_type_from_option (GNCOption *option) { SCM odata = gnc_option_get_option_data (option); /* The option data is enum-typed. It's just the enum value. */ return (GncOwnerType) scm_num2int(odata, SCM_ARG1, G_STRFUNC); }
gint gnc_report_add(SCM report) { SCM get_id = scm_c_eval_string("gnc:report-id"); SCM value; gint id, *key; gnc_report_init_table(); value = scm_call_1(get_id, report); if (scm_is_number(value)) { id = scm_num2int(value, SCM_ARG1, G_STRFUNC); if (!g_hash_table_lookup(reports, &id)) { key = g_new(gint, 1); *key = id; g_hash_table_insert(reports, key, (gpointer)report); scm_gc_protect_object(report); return id; } g_warning("Report specified id of %d is already is use. " "Using generated id.", id); } id = report_next_serial_id++; while (id < G_MAXINT) { if (!g_hash_table_lookup(reports, &id)) { key = g_new(gint, 1); *key = id; g_hash_table_insert(reports, key, (gpointer)report); scm_gc_protect_object(report); return id; } id = report_next_serial_id++; } g_warning("Unable to add report to table. %d reports in use.", G_MAXINT); report_next_serial_id = G_MAXINT; return G_MAXINT; }
static void gnc_column_view_edit_add_cb(GtkButton * button, gpointer user_data) { gnc_column_view_edit * r = user_data; SCM make_report = scm_c_eval_string("gnc:make-report"); SCM mark_report = scm_c_eval_string("gnc:report-set-needs-save?!"); SCM template_name; SCM new_report; SCM newlist = SCM_EOL; SCM oldlist = r->contents_list; int count; int oldlength, id; if (scm_is_list(r->available_list) && (scm_ilength(r->available_list) > r->available_selected)) { template_name = scm_list_ref(r->available_list, scm_int2num(r->available_selected)); new_report = scm_call_1(make_report, template_name); id = scm_num2int(new_report, SCM_ARG1, G_STRFUNC); scm_call_2(mark_report, gnc_report_find(id), SCM_BOOL_T); oldlength = scm_ilength(r->contents_list); if (oldlength > r->contents_selected) { for (count = 0; count < r->contents_selected; count++) { newlist = scm_cons(SCM_CAR(oldlist), newlist); oldlist = SCM_CDR(oldlist); } newlist = scm_append (scm_listify(scm_reverse(scm_cons(SCM_LIST4(new_report, scm_int2num(1), scm_int2num(1), SCM_BOOL_F), newlist)), oldlist, SCM_UNDEFINED)); } else { newlist = scm_append (scm_listify(oldlist, SCM_LIST1(SCM_LIST4(new_report, scm_int2num(1), scm_int2num(1), SCM_BOOL_F)), SCM_UNDEFINED)); r->contents_selected = oldlength; } scm_gc_unprotect_object(r->contents_list); r->contents_list = newlist; scm_gc_protect_object(r->contents_list); gnc_column_view_set_option(r->odb, "__general", "report-list", r->contents_list); gnc_options_dialog_changed (r->optwin); } update_display_lists(r); }
static void update_display_lists(gnc_column_view_edit * view) { SCM get_names = scm_c_eval_string("gnc:all-report-template-names"); SCM template_menu_name = scm_c_eval_string("gnc:report-template-menu-name/report-guid"); SCM report_menu_name = scm_c_eval_string("gnc:report-menu-name"); SCM names = scm_call_0(get_names); SCM contents = gnc_option_db_lookup_option(view->odb, "__general", "report-list", SCM_BOOL_F); SCM this_report; SCM selection; const gchar *name; int row, i, id; GtkListStore *store; GtkTreeIter iter; GtkTreePath *path; GtkTreeSelection *tree_selection; /* Update the list of available reports (left selection box). */ row = view->available_selected; if (scm_is_list(view->available_list) && !scm_is_null (view->available_list)) { row = MIN (row, scm_ilength (view->available_list) - 1); selection = scm_list_ref (view->available_list, scm_int2num (row)); } else { selection = SCM_UNDEFINED; } scm_gc_unprotect_object(view->available_list); view->available_list = names; scm_gc_protect_object(view->available_list); store = GTK_LIST_STORE(gtk_tree_view_get_model(view->available)); gtk_list_store_clear(store); if (scm_is_list(names)) { for (i = 0; !scm_is_null(names); names = SCM_CDR(names), i++) { char * str; if (scm_is_equal (SCM_CAR(names), selection)) row = i; scm_dynwind_begin (0); str = scm_to_locale_string (scm_call_2(template_menu_name, SCM_CAR(names), SCM_BOOL_F)); name = _(g_strdup (str)); scm_dynwind_free (str); scm_dynwind_end (); gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, AVAILABLE_COL_NAME, name, AVAILABLE_COL_ROW, i, -1); } } tree_selection = gtk_tree_view_get_selection(view->available); path = gtk_tree_path_new_from_indices(row, -1); gtk_tree_selection_select_path(tree_selection, path); gtk_tree_path_free(path); /* Update the list of selected reports (right selection box). */ row = view->contents_selected; if (scm_is_list(view->contents_list) && !scm_is_null (view->contents_list)) { row = MIN (row, scm_ilength (view->contents_list) - 1); selection = scm_list_ref (view->contents_list, scm_int2num (row)); } else { selection = SCM_UNDEFINED; } scm_gc_unprotect_object(view->contents_list); view->contents_list = contents; scm_gc_protect_object(view->contents_list); store = GTK_LIST_STORE(gtk_tree_view_get_model(view->contents)); gtk_list_store_clear(store); if (scm_is_list(contents)) { for (i = 0; !scm_is_null(contents); contents = SCM_CDR(contents), i++) { char * str; if (scm_is_equal (SCM_CAR(contents), selection)) row = i; id = scm_num2int(SCM_CAAR(contents), SCM_ARG1, G_STRFUNC); this_report = gnc_report_find(id); scm_dynwind_begin (0); str = scm_to_locale_string (scm_call_1(report_menu_name, this_report)); name = _(g_strdup (str)); scm_dynwind_free (str); scm_dynwind_end (); gtk_list_store_append(store, &iter); gtk_list_store_set (store, &iter, CONTENTS_COL_NAME, name, CONTENTS_COL_ROW, i, CONTENTS_COL_REPORT_COLS, scm_num2int(SCM_CADR(SCM_CAR(contents)), SCM_ARG1, G_STRFUNC), CONTENTS_COL_REPORT_ROWS, scm_num2int(SCM_CADDR(SCM_CAR(contents)), SCM_ARG1, G_STRFUNC), -1); } } tree_selection = gtk_tree_view_get_selection(view->contents); path = gtk_tree_path_new_from_indices(row, -1); gtk_tree_selection_select_path(tree_selection, path); // gtk_tree_view_scroll_to_cell(view->contents, path, NULL, TRUE, 0.5, 0.0); gtk_tree_path_free(path); }