void iterate_by_page(Parts db, size_t page_size, void (*record_op)(Part), int(*interval_op)(void)) { if (db->count == 0) return; int rc = 0; Node *n; size_t i; /* print first outside of loop to avoid a pause after the first; * otherwise we'd have to test for > 0 every iteration */ record_op(db->head->part); for (i = 1, n = db->head->next; n != NULL; n = n->next, i++) { if (i % page_size == 0) { if ((rc = interval_op()) == -2) { return; } else if (rc == -3) { continue; /* 'end' function will require doubly linked list */ } else if (rc > -1) { n = approximate_node(db, rc); } } record_op(n->part); } }
void code_editor_widget::on_slider_move(double value) { if(record_op("slider")) { save_undo_state(); } std::ostringstream s; value = (value - 0.5)*2.0; // normalize to [-1.0,1.0] range. const decimal new_value(value*slider_magnitude_); if(slider_decimal_) { s << new_value; } else { s << new_value.as_int(); } std::string new_string = s.str(); ASSERT_LOG(row_slider_ >= 0 && row_slider_ < get_data().size(), "Illegal row value for slider: " << row_slider_ << " / " << get_data().size()); std::string row = get_data()[row_slider_]; row.erase(row.begin() + begin_col_slider_, row.begin() + end_col_slider_); row.insert(row.begin() + begin_col_slider_, new_string.begin(), new_string.end()); const int old_end = end_col_slider_; end_col_slider_ = begin_col_slider_ + new_string.size(); if(cursor_row() == row_slider_ && cursor_col() == old_end) { set_cursor(cursor_row(), end_col_slider_); } set_row_contents(row_slider_, row); }