Commit 2264af5a authored by Jody Goldberg's avatar Jody Goldberg

Wed Sep 8 14:11:52 EDT 1999

    1st stab at scrollbars adjusting to visible region.
    Move selection code into a new file, no changes.
    Minor const fixups.
parent 0f10b264
1999-09-08 Jody Goldberg <jgoldberg@home.com>
* src/cell.c (cell_get_span) : Support VALUE_EMPTY.
1999-09-08 Michael Meeks <michael@nuclecu.unam.mx>
* src/sheet-view.c (filenames_dropped, sheet_view_construct): Move
......@@ -29,6 +33,11 @@
* src/workbook.c: changed "_Comments" to "Co_mments" as there is
already "_Content" in the same menu
1999-09-07 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-function-select.c (function_definition_update,
function_categories_fill) : Const.
1999-09-07 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/workbook.c: Remove sample button from the toolbar.
......@@ -85,6 +94,15 @@
* src/cursors.c (create_bitmap_and_mask_from_xpm): Fix bitmap
loading. This code isn't exactly elegant.
1999-09-06 Jody Goldberg <jgoldberg@home.com>
* src/sheet-view.[ch] (sheet_view_scrollbar_config) : Adjust scrollbar
increment. Split out from sheet_view_size_allocate.
* src/gnumeric-sheet.c (gnumeric_sheet_compute_visible_ranges) :
call sheet_view_scrollbar_config, to adjust scrollbar when region
changes.
1999-09-05 Miguel de Icaza <miguel@gnu.org>
* src/print-preview.c (preview_canvas_event): Add an event handler
......
1999-09-08 Jody Goldberg <jgoldberg@home.com>
* src/cell.c (cell_get_span) : Support VALUE_EMPTY.
1999-09-08 Michael Meeks <michael@nuclecu.unam.mx>
* src/sheet-view.c (filenames_dropped, sheet_view_construct): Move
......@@ -29,6 +33,11 @@
* src/workbook.c: changed "_Comments" to "Co_mments" as there is
already "_Content" in the same menu
1999-09-07 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-function-select.c (function_definition_update,
function_categories_fill) : Const.
1999-09-07 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/workbook.c: Remove sample button from the toolbar.
......@@ -85,6 +94,15 @@
* src/cursors.c (create_bitmap_and_mask_from_xpm): Fix bitmap
loading. This code isn't exactly elegant.
1999-09-06 Jody Goldberg <jgoldberg@home.com>
* src/sheet-view.[ch] (sheet_view_scrollbar_config) : Adjust scrollbar
increment. Split out from sheet_view_size_allocate.
* src/gnumeric-sheet.c (gnumeric_sheet_compute_visible_ranges) :
call sheet_view_scrollbar_config, to adjust scrollbar when region
changes.
1999-09-05 Miguel de Icaza <miguel@gnu.org>
* src/print-preview.c (preview_canvas_event): Add an event handler
......
......@@ -119,6 +119,8 @@ GNUMERIC_BASE_SOURCES = \
regression.h \
render-ascii.c \
render-ascii.h \
selection.c \
selection.h \
sheet.c \
sheet.h \
sheet-autofill.c \
......
......@@ -1212,7 +1212,7 @@ cell_get_span (Cell *cell, int *col1, int *col2)
sibling = sheet_cell_get (sheet, pos, row);
if (sibling)
if (!cell_is_blank(sibling))
return;
ci = sheet_col_get_info (sheet, pos);
......@@ -1240,7 +1240,7 @@ cell_get_span (Cell *cell, int *col1, int *col2)
sibling = sheet_cell_get (sheet, pos, row);
if (sibling)
if (!cell_is_blank(sibling))
return;
ci = sheet_col_get_info (sheet, pos);
......@@ -1275,7 +1275,7 @@ cell_get_span (Cell *cell, int *col1, int *col2)
if (*col1 - 1 >= 0){
left_sibling = sheet_cell_get (sheet, *col1 - 1, row);
if (left_sibling)
if (!cell_is_blank(left_sibling))
left_left = 0;
else {
ci = sheet_col_get_info (sheet, *col1 - 1);
......@@ -1291,7 +1291,7 @@ cell_get_span (Cell *cell, int *col1, int *col2)
if (*col2 + 1 < SHEET_MAX_COLS-1){
right_sibling = sheet_cell_get (sheet, *col2 + 1, row);
if (right_sibling)
if (!cell_is_blank(right_sibling))
left_right = 0;
else {
ci = sheet_col_get_info (sheet, *col2 + 1);
......
......@@ -14,6 +14,7 @@
#include "dialogs.h"
#include "format.h"
#include "formats.h"
#include "selection.h"
#include "pattern-selector.h"
#include "widgets/widget-font-selector.h"
......
......@@ -13,6 +13,7 @@
#include "dialogs.h"
#include "cell.h"
#include "expr.h"
#include "selection.h"
#include "utils.h"
typedef struct {
......
......@@ -9,6 +9,7 @@
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "selection.h"
#include "dialogs.h"
void
......
......@@ -41,7 +41,7 @@ function_categories_fill (SelectorState *selector_state)
gchar *cols [1];
fc = g_list_nth_data (selector_state->cats, i);
cols[0] = fc->name;
cols[0] = (gchar *)fc->name; /* Const cast */
gtk_clist_append (cl, cols);
if (i == selector_state->selected_cat)
......@@ -72,7 +72,7 @@ function_definition_update (SelectorState *selector_state)
gchar *cols [1];
FunctionDefinition *fn = p->data;
cols [0] = fn->name;
cols[0] = (gchar *)fn->name; /* Const cast */
gtk_clist_append (cl, cols);
if (i == selector_state->selected_func)
......
......@@ -9,6 +9,7 @@
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "selection.h"
#include "dialogs.h"
void
......
......@@ -15,6 +15,7 @@
#include "sheet-object.h"
#include "color.h"
#include "cursors.h"
#include "selection.h"
#include "utils.h"
#undef DEBUG_POSITIONS
......@@ -1115,6 +1116,9 @@ gnumeric_sheet_compute_visible_ranges (GnumericSheet *gsheet)
pixels = cb;
row++;
} while (pixels < height);
/* Update the scrollbar sizes */
sheet_view_scrollbar_config (gsheet->sheet_view);
}
static int
......
......@@ -15,6 +15,7 @@
#include "sheet-object.h"
#include "color.h"
#include "cursors.h"
#include "selection.h"
#include "utils.h"
#undef DEBUG_POSITIONS
......@@ -1115,6 +1116,9 @@ gnumeric_sheet_compute_visible_ranges (GnumericSheet *gsheet)
pixels = cb;
row++;
} while (pixels < height);
/* Update the scrollbar sizes */
sheet_view_scrollbar_config (gsheet->sheet_view);
}
static int
......
......@@ -17,6 +17,7 @@
#include "cursors.h"
#include "sheet-autofill.h"
#include "clipboard.h"
#include "selection.h"
static GnomeCanvasItem *item_cursor_parent_class;
......
......@@ -16,6 +16,7 @@
#include "cursors.h"
#include "gnumeric-util.h"
#include "clipboard.h"
#include "selection.h"
#include "main.h"
static GnomeCanvasItem *item_grid_parent_class;
......
/*
* selection.c: Manage selection regions.
*
* Author:
* Miguel de Icaza (miguel@gnu.org)
*
*/
#include "selection.h"
#include "gnumeric-sheet.h"
#include "utils.h"
#include "clipboard.h"
#include "gnumeric-util.h"
/* FIXME : why do we need this ? split things better so that we can avoid it */
#define GNUMERIC_SHEET_VIEW(p) GNUMERIC_SHEET (SHEET_VIEW(p)->sheet_view);
#if 0
/*
This is some of the new code to break regions into non-intesecting areas.
I will enable it after the code transfer.
*/
/* Quick utility routine to test intersect of line segments.
* Returns : 4 --sA--sb--eb--eA-- a contains b
* 3 --sA--sb--eA--eb-- overlap left
* 2 --sb--sA--eA--eb-- b contains a
* 1 --sb--sA--eb--eA-- overlap right
* 0 if there is no intersection.
*/
static int
segments_intersect (int const s_a, int const e_a,
int const s_b, int const e_b)
{
/* Assume s_a <= e_a and s_b <= e_b */
if (e_a < s_b || e_b < s_a)
return 0;
if (s_a < s_b)
return (e_a >= e_b) ? 4 : 3;
/* We already know that s_a <= e_b */
return (e_a <= e_b) ? 2 : 1;
}
static SheetSelection *
SheetSelection_copy (SheetSelection const * src)
{
SheetSelection * res;
res = g_new (SheetSelection, 1);
res->start_col = src->start_col;
res->end_col = src->end_col;
res->start_row = src->start_row;
res->end_row = src->end_row;
return res;
}
static void
SheetSelection_dump (SheetSelection const * src)
{
/* keep these as 2 print statements, because
* col_name uses a static buffer */
fprintf (stderr, "%s%d",
col_name(src->start_col),
src->start_row + 1);
fprintf (stderr, ":%s%d\n",
col_name(src->end_col),
src->end_row + 1);
}
void
selection_append_range (Sheet *sheet,
int start_col, int start_row,
int end_col, int end_row)
{
SheetSelection *ss, *tmp, orig;
GList *l, *next, *proposed;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
ss = g_new0 (SheetSelection, 1);
ss->start_col = start_col;
ss->end_col = end_col;
ss->start_row = start_row;
ss->end_row = end_row;
orig = *ss; /* NOTE : copy struct */
fprintf (stderr, "\n%d %d %d %d\n",
start_col, start_row, end_col, end_row);
SheetSelection_dump (ss);
fprintf(stderr, "=========================================\n ");
/*
* Run through all the selection regions to see if any of
* the proposed regions overlap
*/
proposed = g_list_prepend (NULL, ss);
for (l = sheet->selections; l != NULL; l = next) {
/* The set of regions that do not interset with b or
* its predecessors */
GList *clear = NULL;
int i = 0;
SheetSelection *b = l->data;
fprintf(stderr, "\nTest %d = ", ++i);
SheetSelection_dump (b);
/* prefetch in case the element gets removed */
next = l->next;
/* run through the proposed regions and handle any that
* overlap with the current selection region
*/
while (proposed != NULL) {
int row_intersect, col_intersect;
/* pop the 1st element off the list */
SheetSelection *a = proposed->data;
fprintf(stderr, "proposed = ");
SheetSelection_dump (a);
proposed = g_list_remove (proposed, a);
col_intersect =
segments_intersect (a->start_col, a->end_col,
b->start_col, b->end_col);
fprintf (stderr, "Col intersect = %d\n", col_intersect);
/* No intersection */
if (col_intersect == 0) {
clear = g_list_prepend (clear, a);
continue;
}
row_intersect =
segments_intersect (a->start_row, a->end_row,
b->start_row, b->end_row);
fprintf (stderr, "Row intersect = %d\n", row_intersect);
/* No intersection */
if (row_intersect == 0) {
clear = g_list_prepend (clear, a);
continue;
}
/* Cross product of intersection cases */
switch (col_intersect) {
case 4 : /* a contains b */
switch (row_intersect) {
case 4 : /* a contains b */
/* Old region contained by new region */
/* remove old region from selection */
sheet->selections = g_list_remove(sheet->selections, b);
break;
case 3 : /* overlap top */
/* Shrink existing range */
b->end_row = a->start_row - 1;
break;
case 2 : /* b contains a */
/* Split existing range */
if (b->start_col > 0) {
tmp = SheetSelection_copy (a);
tmp->end_col = b->start_col - 1;
clear = g_list_prepend (clear, tmp);
}
/* Fall through to do bottom segment */
case 1 : /* overlap bottom */
/* Shrink existing range */
a->start_col = b->end_col + 1;
break;
default :
g_assert_not_reached();
};
break;
case 3 : /* overlap left */
switch (row_intersect) {
case 4 : /* a contains b */
/* Shrink old region */
b->start_col = a->end_col + 1;
break;
case 3 : /* overlap top */
/* Split region */
if (b->start_row > 0) {
tmp = SheetSelection_copy (a);
tmp->start_col = b->start_col;
tmp->end_row = b->start_row - 1;
clear = g_list_prepend (clear, tmp);
}
/* fall through */
case 2 : /* b contains a */
/* shrink the left segment */
a->end_col = b->start_col - 1;
break;
case 1 : /* overlap bottom */
/* Split region */
if (b->end_row < (SHEET_MAX_ROWS-1)) {
tmp = SheetSelection_copy (a);
tmp->start_col = b->start_col;
tmp->start_row = b->end_row + 1;
clear = g_list_prepend (clear, tmp);
}
/* shrink the left segment */
if (b->start_col == 0) {
g_free(a);
continue;
}
a->end_col = b->start_col - 1;
break;
default :
g_assert_not_reached();
};
break;
case 2 : /* b contains a */
switch (row_intersect) {
case 4 : /* a contains b */
/* Split region */
tmp = SheetSelection_copy (a);
tmp->start_row = b->end_row + 1;
clear = g_list_prepend (clear, tmp);
/* fall through */
case 3 : /* overlap top */
/* shrink the top segment */
a->end_row = b->start_row - 1;
break;
case 2 : /* b contains a */
/* remove the selection */
g_free (a);
continue;
case 1 : /* overlap bottom */
/* shrink the top segment */
a->start_row = b->end_row + 1;
break;
default :
g_assert_not_reached();
};
break;
case 1 : /* overlap right */
switch (row_intersect) {
case 4 : /* a contains b */
/* Shrink old region */
b->end_col = a->start_col - 1;
break;
case 3 : /* overlap top */
/* Split region */
tmp = SheetSelection_copy (a);
tmp->end_col = b->end_col;
tmp->end_row = b->start_row - 1;
/* fall through */
case 2 : /* b contains a */
/* shrink the right segment */
a->start_col = b->end_col + 1;
break;
case 1 : /* overlap bottom */
/* Split region */
tmp = SheetSelection_copy (a);
tmp->end_col = b->end_col;
tmp->start_row = b->end_row + 1;
/* shrink the right segment */
a->start_col = b->end_col + 1;
break;
default :
g_assert_not_reached();
};
break;
};
/* Be careful putting code here one of the cases skips this */
/* continue checking the new region for intersections */
clear = g_list_prepend (clear, a);
}
proposed = clear;
}
/* Catch attempts to select something twice */
if (proposed == NULL)
return;
sheet->selections = g_list_concat (sheet->selections, proposed);
sheet_accept_pending_input (sheet);
for (l = sheet->sheet_views; l; l = l->next){
GnumericSheet *gsheet = GNUMERIC_SHEET_VIEW (l->data);
gnumeric_sheet_set_selection (gsheet, &orig);
}
sheet_redraw_selection (sheet, &orig);
sheet_redraw_cols (sheet);
sheet_redraw_rows (sheet);
sheet_selection_changed_hook (sheet);
}
#endif
int
sheet_selection_equal (SheetSelection *a, SheetSelection *b)
{
if (a->start_col != b->start_col)
return 0;
if (a->start_row != b->start_row)
return 0;
if (a->end_col != b->end_col)
return 0;
if (a->end_row != b->end_row)
return 0;
return 1;
}
static const char *
sheet_get_selection_name (Sheet *sheet)
{
SheetSelection *ss = sheet->selections->data;
static char buffer [10 + 2 * 4 * sizeof (int)];
if (ss->start_col == ss->end_col && ss->start_row == ss->end_row){
return cell_name (ss->start_col, ss->start_row);
} else {
snprintf (buffer, sizeof (buffer), "%dLx%dC",
ss->end_row - ss->start_row + 1,
ss->end_col - ss->start_col + 1);
return buffer;
}
}
static void
sheet_selection_changed_hook (Sheet *sheet)
{
sheet_update_auto_expr (sheet);
sheet_update_controls (sheet);
workbook_set_region_status (sheet->workbook, sheet_get_selection_name (sheet));
}
void
sheet_selection_append_range (Sheet *sheet,
int base_col, int base_row,
int start_col, int start_row,
int end_col, int end_row)
{
SheetSelection *ss;
GList *l;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
ss = g_new0 (SheetSelection, 1);
ss->base_col = base_col;
ss->base_row = base_row;
ss->start_col = start_col;
ss->end_col = end_col;
ss->start_row = start_row;
ss->end_row = end_row;
sheet->selections = g_list_prepend (sheet->selections, ss);
sheet_accept_pending_input (sheet);
sheet_load_cell_val (sheet);
for (l = sheet->sheet_views; l; l = l->next){
GnumericSheet *gsheet = GNUMERIC_SHEET_VIEW (l->data);
gnumeric_sheet_set_selection (gsheet, ss);
}
sheet_redraw_selection (sheet, ss);
sheet_redraw_cols (sheet);
sheet_redraw_rows (sheet);
sheet_selection_changed_hook (sheet);
}
/**
* If returns true selection is just one range.
* If returns false, range data: indeterminate
**/
int
sheet_selection_first_range (Sheet *sheet,
int *base_col, int *base_row,
int *start_col, int *start_row,
int *end_col, int *end_row)
{
SheetSelection *ss;
GList *l;
g_return_val_if_fail (sheet != NULL, 0);
g_return_val_if_fail (IS_SHEET (sheet), 0);
if (!sheet->selections)
return 0;
l = g_list_first (sheet->selections);
if (!l || !l->data)
return 0;
ss = l->data;
*base_col = ss->base_col;
*base_row = ss->base_row;
*start_col = ss->start_col;
*start_row = ss->start_row;
*end_col = ss->end_col;
*end_row = ss->end_row;
if ((l = g_list_next (l)))
return 0;
return 1;
}
void
sheet_selection_append (Sheet *sheet, int col, int row)
{
sheet_selection_append_range (sheet, col, row, col, row, col, row);
}
/**
* sheet_selection_extend_to:
* @sheet: the sheet