path edit_select_rep::selection_get_subtable ( int& row1, int& col1, int& row2, int& col2) { if (selection_active_table ()) { path fp= ::table_search_format (et, common (start_p, end_p)); if (is_nil (fp)) return fp; tree st= subtree (et, fp); table_search_coordinates (st, tail (start_p, N(fp)), row1, col1); table_search_coordinates (st, tail (end_p, N(fp)), row2, col2); if (row1>row2) { int tmp= row1; row1= row2; row2= tmp; } if (col1>col2) { int tmp= col1; col1= col2; col2= tmp; } table_bound (fp, row1, col1, row2, col2); return fp; } else if (selection_active_table (false)) { path fp= ::table_search_format (et, common (start_p, end_p) * 0); if (is_nil (fp)) return fp; path p= fp; tree st; while (true) { st= subtree (et, p); if (is_func (st, TABLE) && N(st) > 0 && is_func (st[0], ROW)) break; if (!is_func (st, TFORMAT)) return path (); p= p * (N(st) - 1); } row1= 0; col1= 0; row2= N(st)-1; col2= N(st[0])-1; return fp; } else return path (); }
path find_subtable_selection (tree et, path p1, path p2, int& row1, int& col1, int& row2, int& col2) { if (is_table_selection (et, p1, p2, true)) { path fp= table_search_format (et, common (p1, p2)); if (is_nil (fp)) return fp; tree st= subtree (et, fp); table_search_coordinates (st, tail (p1, N(fp)), row1, col1); table_search_coordinates (st, tail (p2, N(fp)), row2, col2); if (row1>row2) { int tmp= row1; row1= row2; row2= tmp; } if (col1>col2) { int tmp= col1; col1= col2; col2= tmp; } // table_bound (fp, row1, col1, row2, col2); // FIXME: table editing routines should be moved to src/Data/Tree return fp; } else if (is_table_selection (et, p1, p2, false)) { path fp= table_search_format (et, common (p1, p2) * 0); if (is_nil (fp)) return fp; path p= fp; tree st; while (true) { st= subtree (et, p); if (is_func (st, TABLE) && N(st) > 0 && is_func (st[0], ROW)) break; if (!is_func (st, TFORMAT)) return path (); p= p * (N(st) - 1); } row1= 0; col1= 0; row2= N(st)-1; col2= N(st[0])-1; return fp; } else return path (); }
void edit_select_rep::raw_cut (path p1, path p2) { if (p2 == p1) return; path p = common (p1, p2); tree t = subtree (et, p); int n = N(p); int i1= p1[n]; int i2= p2[n]; if (is_document (t) || is_concat (t)) { path q1= copy (p); q1 << path (i1, end (t[i1])); path q2= copy (p); q2 << path (i2, start (t[i2])); raw_cut (q2, p2); if (i2>i1+1) remove (p * (i1+1), i2-i1-1); raw_cut (p1, q1); if (is_concat (t)) correct_concat (p); else remove_return (p * i1); return; } if (is_func (t, TFORMAT) || is_func (t, TABLE) || is_func (t, ROW)) { path fp= ::table_search_format (et, p); tree st= subtree (et, fp); int row1, col1, row2, col2; table_search_coordinates (st, tail (p1, N(fp)), row1, col1); table_search_coordinates (st, tail (p2, N(fp)), row2, col2); if (row1>row2) { int tmp= row1; row1= row2; row2= tmp; } if (col1>col2) { int tmp= col1; col1= col2; col2= tmp; } int i, j; for (i=row1; i<=row2; i++) for (j=col1; j<=col2; j++) { path cp= fp * ::table_search_cell (st, i, j); if (is_func (subtree (et, cp), CELL, 1)) cp= cp * 0; assign (cp, ""); } path cp= fp * ::table_search_cell (st, row1, col1); go_to (cp * path (0, 0)); if (is_func (st, TFORMAT)) table_del_format (fp, row1+1, col1+1, row2+1, col2+1, ""); return; } if (is_compound (t) && (!is_format (t))) { assign (p, ""); return; } if ((N(p1) != (N(p)+1)) || (N(p2) != (N(p)+1))) { cerr << "t = " << t << "\n"; cerr << "p = " << p << "\n"; cerr << "p1= " << p1 << "\n"; cerr << "p2= " << p2 << "\n"; FAILED ("invalid cut"); } if (is_atomic (t)) { int pos= last_item (p1); int nr = last_item (p2)-pos; if (nr>0) remove (p1, nr); } else { if ((last_item (p1) != 0) || (last_item (p2) != 1)) { cerr << "t = " << t << "\n"; cerr << "p = " << p << "\n"; cerr << "p1= " << p1 << "\n"; cerr << "p2= " << p2 << "\n"; FAILED ("invalid object cut"); } assign (p, ""); } }