[gucharmap] chartable: Fix off-by-one in the calculation of the number of rows
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gucharmap] chartable: Fix off-by-one in the calculation of the number of rows
- Date: Wed, 24 Oct 2012 18:46:13 +0000 (UTC)
commit 1bea61e0947323e7f25c69ee79fa8b1a84414b28
Author: Christian Persch <chpe gnome org>
Date: Wed Oct 24 20:45:12 2012 +0200
chartable: Fix off-by-one in the calculation of the number of rows
https://bugzilla.gnome.org/show_bug.cgi?id=678311
https://bugzilla.gnome.org/show_bug.cgi?id=686612
gucharmap/gucharmap-chartable.c | 27 ++++++++++-----------------
1 files changed, 10 insertions(+), 17 deletions(-)
---
diff --git a/gucharmap/gucharmap-chartable.c b/gucharmap/gucharmap-chartable.c
index 2ae3a48..f3b6596 100644
--- a/gucharmap/gucharmap-chartable.c
+++ b/gucharmap/gucharmap-chartable.c
@@ -1052,11 +1052,11 @@ update_scrollbar_adjustment (GucharmapChartable *chartable)
return;
gtk_adjustment_configure (vadjustment,
- 1.0 * priv->page_first_cell / priv->cols,
- 0.0 /* lower */,
- 1.0 * ((priv->last_cell + priv->cols - 1) / priv->cols) /* upper */,
- 3.0 /* step increment */,
- 1.0 * priv->rows /* page increment */,
+ priv->page_first_cell / priv->cols,
+ 0 /* lower */,
+ priv->last_cell / priv->cols + 1 /* upper */,
+ 3 /* step increment */,
+ priv->rows /* page increment */,
priv->rows);
}
@@ -1085,20 +1085,13 @@ gucharmap_chartable_set_active_cell (GucharmapChartable *chartable,
{
int old_row = old_active_cell / priv->cols;
int new_row = cell / priv->cols;
- int row_delta = new_row - old_row;
- int delta = row_delta * priv->cols;
- int first_cell_on_last_page = priv->last_cell - (priv->last_cell % priv->cols) - priv->cols * (priv->rows - 1);
- int new_page_first_cell = old_page_first_cell + delta;
-
- if (new_page_first_cell < 0)
- priv->page_first_cell = 0;
- else if (new_page_first_cell > first_cell_on_last_page)
- priv->page_first_cell = first_cell_on_last_page;
- else
- priv->page_first_cell = new_page_first_cell;
+ int new_page_first_cell = old_page_first_cell + (new_row - old_row) * priv->cols;
+ int last_page_first_cell = (priv->last_cell / priv->cols - priv->rows + 1) * priv->cols;
+
+ priv->page_first_cell = CLAMP (new_page_first_cell, 0, last_page_first_cell);
if (priv->vadjustment)
- gtk_adjustment_set_value (priv->vadjustment, 1.0 * priv->page_first_cell / priv->cols);
+ gtk_adjustment_set_value (priv->vadjustment, priv->page_first_cell / priv->cols);
}
else if (gtk_widget_get_realized (widget)) {
expose_cell (chartable, old_active_cell);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]