Commit ddc5bfd2 authored by Morten Welinder's avatar Morten Welinder
Browse files

Fix scrolling bug. Minor cleanup of new root finder.

Fix scrolling bug.
Minor cleanup of new root finder.
parent 596d0c11
1999-05-23 Morten Welinder <terra@diku.dk>
* src/gnumeric-sheet.c (gnumeric_sheet_cursor_set): Make the
scroll bar reflect the top-left corner's position. This feels
more natural.
(gnumeric_sheet_set_top_col): Compute visible ranges; do nothing
until things change.
(gnumeric_sheet_set_top_row): Ditto.
* src/dialog-goal-seek.c (gnumeric_goal_seek): Use
goal_seek_initialise.
(gnumeric_goal_seek): Trawl heavier and earlier in the middle.
(dialog_goal_seek): downcase a stray uppercase letter.
* src/goal-seek.c (goal_seek_initialise): New function.
1999-05-23 Morten Welinder <terra@diku.dk>
* src/dialog-goal-seek.c: redesign non-gui part.
......
1999-05-23 Morten Welinder <terra@diku.dk>
* src/gnumeric-sheet.c (gnumeric_sheet_cursor_set): Make the
scroll bar reflect the top-left corner's position. This feels
more natural.
(gnumeric_sheet_set_top_col): Compute visible ranges; do nothing
until things change.
(gnumeric_sheet_set_top_row): Ditto.
* src/dialog-goal-seek.c (gnumeric_goal_seek): Use
goal_seek_initialise.
(gnumeric_goal_seek): Trawl heavier and earlier in the middle.
(dialog_goal_seek): downcase a stray uppercase letter.
* src/goal-seek.c (goal_seek_initialise): New function.
1999-05-23 Morten Welinder <terra@diku.dk>
* src/dialog-goal-seek.c: redesign non-gui part.
......
1999-05-23 Morten Welinder <terra@diku.dk>
* src/gnumeric-sheet.c (gnumeric_sheet_cursor_set): Make the
scroll bar reflect the top-left corner's position. This feels
more natural.
(gnumeric_sheet_set_top_col): Compute visible ranges; do nothing
until things change.
(gnumeric_sheet_set_top_row): Ditto.
* src/dialog-goal-seek.c (gnumeric_goal_seek): Use
goal_seek_initialise.
(gnumeric_goal_seek): Trawl heavier and earlier in the middle.
(dialog_goal_seek): downcase a stray uppercase letter.
* src/goal-seek.c (goal_seek_initialise): New function.
1999-05-23 Morten Welinder <terra@diku.dk>
* src/dialog-goal-seek.c: redesign non-gui part.
......
1999-05-23 Morten Welinder <terra@diku.dk>
* src/gnumeric-sheet.c (gnumeric_sheet_cursor_set): Make the
scroll bar reflect the top-left corner's position. This feels
more natural.
(gnumeric_sheet_set_top_col): Compute visible ranges; do nothing
until things change.
(gnumeric_sheet_set_top_row): Ditto.
* src/dialog-goal-seek.c (gnumeric_goal_seek): Use
goal_seek_initialise.
(gnumeric_goal_seek): Trawl heavier and earlier in the middle.
(dialog_goal_seek): downcase a stray uppercase letter.
* src/goal-seek.c (goal_seek_initialise): New function.
1999-05-23 Morten Welinder <terra@diku.dk>
* src/dialog-goal-seek.c: redesign non-gui part.
......
......@@ -20,7 +20,7 @@
#include "utils.h"
#include "goal-seek.h"
#ifdef HAVE_IEEEFP_H
# include <ieeefp.h>
#include <ieeefp.h>
#endif
#define MAX_CELL_NAME_LEN 20
......@@ -70,10 +70,9 @@ gnumeric_goal_seek (Workbook *wb, Sheet *sheet,
GoalEvalData evaldata;
GoalSeekStatus status;
goal_seek_initialise (&seekdata);
seekdata.xmin = xmin;
seekdata.xmax = xmax;
seekdata.precision = 1e-10;
seekdata.havexpos = seekdata.havexneg = FALSE;
evaldata.xcell = change_cell;
evaldata.ycell = set_cell;
......@@ -105,31 +104,31 @@ gnumeric_goal_seek (Workbook *wb, Sheet *sheet,
goto DONE;
}
/* PLAN C: Trawl normally from left. */
/* PLAN C: Trawl normally from middle. */
{
float_t sigma, mu;
int i;
sigma = seekdata.xmax - seekdata.xmin;
mu = seekdata.xmin;
mu = (seekdata.xmax + seekdata.xmin) / 2;
for (i = 0; i < 5; i++) {
sigma /= 10;
status = goal_seek_trawl_normally (goal_seek_eval,
&seekdata, &evaldata,
mu, sigma, 20);
mu, sigma, 30);
if (status == GOAL_SEEK_OK)
goto DONE;
}
}
/* PLAN D: Trawl normally from right. */
/* PLAN D: Trawl normally from left. */
{
float_t sigma, mu;
int i;
sigma = seekdata.xmax - seekdata.xmin;
mu = seekdata.xmax;
mu = seekdata.xmin;
for (i = 0; i < 5; i++) {
sigma /= 10;
......@@ -141,13 +140,13 @@ gnumeric_goal_seek (Workbook *wb, Sheet *sheet,
}
}
/* PLAN E: Trawl normally from middle. */
/* PLAN E: Trawl normally from right. */
{
float_t sigma, mu;
int i;
sigma = seekdata.xmax - seekdata.xmin;
mu = (seekdata.xmax + seekdata.xmin) / 2;
mu = seekdata.xmax;
for (i = 0; i < 5; i++) {
sigma /= 10;
......@@ -279,17 +278,17 @@ dialog_goal_seek (Workbook *wb, Sheet *sheet)
xmin_entry = gtk_entry_new_with_max_length (MAX_CELL_NAME_LEN);
xmax_entry = gtk_entry_new_with_max_length (MAX_CELL_NAME_LEN);
set_label = gtk_label_new (_("Set Cell:"));
set_label = gtk_label_new (_("Set cell:"));
target_label = gtk_label_new (_("To value:"));
change_label = gtk_label_new (_("By changing cell:"));
xmin_label = gtk_label_new (_("To a value of at least [optional]:"));
xmax_label = gtk_label_new (_("But no bigger than [optional]:"));
gtk_misc_set_alignment (GTK_MISC(set_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC(target_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC(change_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC(xmin_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC(xmax_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC (set_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC (target_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC (change_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC (xmin_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC (xmax_label), 0, 0);
box = gtk_hbox_new (FALSE, 0);
entry_box = gtk_vbox_new (FALSE, 0);
......@@ -312,18 +311,12 @@ dialog_goal_seek (Workbook *wb, Sheet *sheet)
gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG
(dialog)->vbox), box);
gtk_entry_set_text(GTK_ENTRY (set_entry), set_entry_str);
gtk_entry_set_position(GTK_ENTRY (set_entry), 0);
gtk_entry_select_region(GTK_ENTRY (set_entry), 0,
GTK_ENTRY(set_entry)->text_length);
gtk_entry_set_text (GTK_ENTRY (set_entry), set_entry_str);
focus_on_entry (set_entry);
gtk_widget_show_all (box);
} else {
gtk_entry_set_text(GTK_ENTRY (set_entry), set_entry_str);
gtk_entry_set_position(GTK_ENTRY (set_entry), 0);
gtk_entry_select_region(GTK_ENTRY (set_entry), 0,
GTK_ENTRY(set_entry)->text_length);
gtk_entry_set_text (GTK_ENTRY (set_entry), set_entry_str);
focus_on_entry (set_entry);
gtk_widget_show (dialog);
}
......
......@@ -20,7 +20,7 @@
#include "utils.h"
#include "goal-seek.h"
#ifdef HAVE_IEEEFP_H
# include <ieeefp.h>
#include <ieeefp.h>
#endif
#define MAX_CELL_NAME_LEN 20
......@@ -70,10 +70,9 @@ gnumeric_goal_seek (Workbook *wb, Sheet *sheet,
GoalEvalData evaldata;
GoalSeekStatus status;
goal_seek_initialise (&seekdata);
seekdata.xmin = xmin;
seekdata.xmax = xmax;
seekdata.precision = 1e-10;
seekdata.havexpos = seekdata.havexneg = FALSE;
evaldata.xcell = change_cell;
evaldata.ycell = set_cell;
......@@ -105,31 +104,31 @@ gnumeric_goal_seek (Workbook *wb, Sheet *sheet,
goto DONE;
}
/* PLAN C: Trawl normally from left. */
/* PLAN C: Trawl normally from middle. */
{
float_t sigma, mu;
int i;
sigma = seekdata.xmax - seekdata.xmin;
mu = seekdata.xmin;
mu = (seekdata.xmax + seekdata.xmin) / 2;
for (i = 0; i < 5; i++) {
sigma /= 10;
status = goal_seek_trawl_normally (goal_seek_eval,
&seekdata, &evaldata,
mu, sigma, 20);
mu, sigma, 30);
if (status == GOAL_SEEK_OK)
goto DONE;
}
}
/* PLAN D: Trawl normally from right. */
/* PLAN D: Trawl normally from left. */
{
float_t sigma, mu;
int i;
sigma = seekdata.xmax - seekdata.xmin;
mu = seekdata.xmax;
mu = seekdata.xmin;
for (i = 0; i < 5; i++) {
sigma /= 10;
......@@ -141,13 +140,13 @@ gnumeric_goal_seek (Workbook *wb, Sheet *sheet,
}
}
/* PLAN E: Trawl normally from middle. */
/* PLAN E: Trawl normally from right. */
{
float_t sigma, mu;
int i;
sigma = seekdata.xmax - seekdata.xmin;
mu = (seekdata.xmax + seekdata.xmin) / 2;
mu = seekdata.xmax;
for (i = 0; i < 5; i++) {
sigma /= 10;
......@@ -279,17 +278,17 @@ dialog_goal_seek (Workbook *wb, Sheet *sheet)
xmin_entry = gtk_entry_new_with_max_length (MAX_CELL_NAME_LEN);
xmax_entry = gtk_entry_new_with_max_length (MAX_CELL_NAME_LEN);
set_label = gtk_label_new (_("Set Cell:"));
set_label = gtk_label_new (_("Set cell:"));
target_label = gtk_label_new (_("To value:"));
change_label = gtk_label_new (_("By changing cell:"));
xmin_label = gtk_label_new (_("To a value of at least [optional]:"));
xmax_label = gtk_label_new (_("But no bigger than [optional]:"));
gtk_misc_set_alignment (GTK_MISC(set_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC(target_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC(change_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC(xmin_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC(xmax_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC (set_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC (target_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC (change_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC (xmin_label), 0, 0);
gtk_misc_set_alignment (GTK_MISC (xmax_label), 0, 0);
box = gtk_hbox_new (FALSE, 0);
entry_box = gtk_vbox_new (FALSE, 0);
......@@ -312,18 +311,12 @@ dialog_goal_seek (Workbook *wb, Sheet *sheet)
gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG
(dialog)->vbox), box);
gtk_entry_set_text(GTK_ENTRY (set_entry), set_entry_str);
gtk_entry_set_position(GTK_ENTRY (set_entry), 0);
gtk_entry_select_region(GTK_ENTRY (set_entry), 0,
GTK_ENTRY(set_entry)->text_length);
gtk_entry_set_text (GTK_ENTRY (set_entry), set_entry_str);
focus_on_entry (set_entry);
gtk_widget_show_all (box);
} else {
gtk_entry_set_text(GTK_ENTRY (set_entry), set_entry_str);
gtk_entry_set_position(GTK_ENTRY (set_entry), 0);
gtk_entry_select_region(GTK_ENTRY (set_entry), 0,
GTK_ENTRY(set_entry)->text_length);
gtk_entry_set_text (GTK_ENTRY (set_entry), set_entry_str);
focus_on_entry (set_entry);
gtk_widget_show (dialog);
}
......
......@@ -17,6 +17,8 @@
#include "cursors.h"
#include "utils.h"
#undef DEBUG_POSITIONS
#define CURSOR_COL(gsheet) (gsheet)->sheet_view->sheet->cursor_col
#define CURSOR_ROW(gsheet) (gsheet)->sheet_view->sheet->cursor_row
......@@ -90,12 +92,23 @@ gnumeric_sheet_cursor_set (GnumericSheet *gsheet, int col, int row)
if (sheet_view->ha){
ha = GTK_ADJUSTMENT (sheet_view->ha);
va = GTK_ADJUSTMENT (sheet_view->va);
ha->value = col;
va->value = row;
ha->value = gsheet->top_col;
va->value = gsheet->top_row;
#ifdef DEBUG_POSITIONS
{
char *top_str = g_strdup (cell_name (gsheet->top_col, gsheet->top_row));
char *lv_str = g_strdup (cell_name (gsheet->last_visible_col, gsheet->last_visible_row));
printf ("top=%s lv=%s\n", top_str, lv_str);
g_free (top_str);
g_free (lv_str);
}
#endif
gtk_adjustment_value_changed (ha);
gtk_adjustment_value_changed (va);
}
}
/*
......@@ -1031,9 +1044,12 @@ gnumeric_sheet_set_top_row (GnumericSheet *gsheet, int new_top_row)
g_return_if_fail (gsheet != NULL);
g_return_if_fail (new_top_row >= 0 && new_top_row <= SHEET_MAX_ROWS-1);
if (gsheet->top_row != new_top_row) {
distance = gnumeric_sheet_bar_set_top_row (gsheet, new_top_row);
gnome_canvas_get_scroll_offsets (GNOME_CANVAS (gsheet), &x, NULL);
gnumeric_sheet_compute_visible_ranges (gsheet);
gnome_canvas_scroll_to (GNOME_CANVAS (gsheet), x, distance);
}
}
static int
......@@ -1067,9 +1083,12 @@ gnumeric_sheet_set_top_col (GnumericSheet *gsheet, int new_top_col)
g_return_if_fail (gsheet != NULL);
g_return_if_fail (new_top_col >= 0 && new_top_col <= SHEET_MAX_COLS-1);
if (gsheet->top_col != new_top_col) {
distance = gnumeric_sheet_bar_set_top_col (gsheet, new_top_col);
gnome_canvas_get_scroll_offsets (GNOME_CANVAS (gsheet), NULL, &y);
gnumeric_sheet_compute_visible_ranges (gsheet);
gnome_canvas_scroll_to (GNOME_CANVAS (gsheet), distance, y);
}
}
void
......
......@@ -17,6 +17,8 @@
#include "cursors.h"
#include "utils.h"
#undef DEBUG_POSITIONS
#define CURSOR_COL(gsheet) (gsheet)->sheet_view->sheet->cursor_col
#define CURSOR_ROW(gsheet) (gsheet)->sheet_view->sheet->cursor_row
......@@ -90,12 +92,23 @@ gnumeric_sheet_cursor_set (GnumericSheet *gsheet, int col, int row)
if (sheet_view->ha){
ha = GTK_ADJUSTMENT (sheet_view->ha);
va = GTK_ADJUSTMENT (sheet_view->va);
ha->value = col;
va->value = row;
ha->value = gsheet->top_col;
va->value = gsheet->top_row;
#ifdef DEBUG_POSITIONS
{
char *top_str = g_strdup (cell_name (gsheet->top_col, gsheet->top_row));
char *lv_str = g_strdup (cell_name (gsheet->last_visible_col, gsheet->last_visible_row));
printf ("top=%s lv=%s\n", top_str, lv_str);
g_free (top_str);
g_free (lv_str);
}
#endif
gtk_adjustment_value_changed (ha);
gtk_adjustment_value_changed (va);
}
}
/*
......@@ -1031,9 +1044,12 @@ gnumeric_sheet_set_top_row (GnumericSheet *gsheet, int new_top_row)
g_return_if_fail (gsheet != NULL);
g_return_if_fail (new_top_row >= 0 && new_top_row <= SHEET_MAX_ROWS-1);
if (gsheet->top_row != new_top_row) {
distance = gnumeric_sheet_bar_set_top_row (gsheet, new_top_row);
gnome_canvas_get_scroll_offsets (GNOME_CANVAS (gsheet), &x, NULL);
gnumeric_sheet_compute_visible_ranges (gsheet);
gnome_canvas_scroll_to (GNOME_CANVAS (gsheet), x, distance);
}
}
static int
......@@ -1067,9 +1083,12 @@ gnumeric_sheet_set_top_col (GnumericSheet *gsheet, int new_top_col)
g_return_if_fail (gsheet != NULL);
g_return_if_fail (new_top_col >= 0 && new_top_col <= SHEET_MAX_COLS-1);
if (gsheet->top_col != new_top_col) {
distance = gnumeric_sheet_bar_set_top_col (gsheet, new_top_col);
gnome_canvas_get_scroll_offsets (GNOME_CANVAS (gsheet), NULL, &y);
gnumeric_sheet_compute_visible_ranges (gsheet);
gnome_canvas_scroll_to (GNOME_CANVAS (gsheet), distance, y);
}
}
void
......
......@@ -162,6 +162,19 @@ fake_df (GoalSeekFunction f, float_t x, float_t *dfx, float_t xrelstep,
return GOAL_SEEK_OK;
}
/* ------------------------------------------------------------------------- */
void
goal_seek_initialise (GoalSeekData *data)
{
data->havexpos = data->havexneg = FALSE;
data->xmin = -1e10;
data->xmax = +1e10;
data->precision = 1e-10;
}
/* ------------------------------------------------------------------------- */
/*
* Seek a goal (root) using Newton's iterative method.
*
......@@ -407,10 +420,10 @@ int
main ()
{
GoalSeekData data;
goal_seek_initialise (&data);
data.xmin = -100;
data.xmax = 100;
data.precision = 1e-10;
data.havexpos = data.havexneg = FALSE;
goal_seek_newton (f, NULL, &data, NULL, 50.0);
......
......@@ -24,6 +24,8 @@ typedef enum { GOAL_SEEK_OK, GOAL_SEEK_ERROR } GoalSeekStatus;
typedef GoalSeekStatus (*GoalSeekFunction) (float_t x, float_t *y, void *user_data);
void goal_seek_initialise (GoalSeekData *data);
GoalSeekStatus goal_seek_newton (GoalSeekFunction f,
GoalSeekFunction df,
GoalSeekData *data,
......
......@@ -1509,7 +1509,7 @@ sheet_selection_is_cell_selected (Sheet *sheet, int col, int row)
}
/*
* walk_boundaries: implements the decitions for walking a region
* walk_boundaries: implements the decisions for walking a region
* returns TRUE if the cursor left the boundary region
*/
static int
......@@ -2014,8 +2014,8 @@ sheet_is_region_empty_or_selected (Sheet *sheet, int start_col, int start_row, i
static gint
CRowSort (gconstpointer a, gconstpointer b)
{
Cell *ca = (Cell *) a;
Cell *cb = (Cell *) b;
const Cell *ca = (const Cell *) a;
const Cell *cb = (const Cell *) b;
return ca->row->pos - cb->row->pos;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment