Commit 0c48da68 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

new function.


2000-12-05  Jody Goldberg <jgoldberg@home.com>

	* src/sheet.c (sheet_region_adjacent_merge) : new function.

	* src/cellspan.c (cell_calc_span) : Use it here to pre bound the
	  potential span region.

2000-12-05  Jody Goldberg <jgoldberg@home.com>

	* src/item-grid.c (item_grid_draw_merged_range) : Draw borders too.
	  This can easily be optimized.

	* src/selection.c (sheet_selection_add_range) : Use
	  sheet_selection_set.
parent 2b8ffd4a
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (sheet_region_adjacent_merge) : new function.
* src/cellspan.c (cell_calc_span) : Use it here to pre bound the
potential span region.
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* src/item-grid.c (item_grid_draw_merged_range) : Draw borders too.
......
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (sheet_region_adjacent_merge) : new function.
* src/cellspan.c (cell_calc_span) : Use it here to pre bound the
potential span region.
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* src/item-grid.c (item_grid_draw_merged_range) : Draw borders too.
......
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (sheet_region_adjacent_merge) : new function.
* src/cellspan.c (cell_calc_span) : Use it here to pre bound the
potential span region.
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* src/item-grid.c (item_grid_draw_merged_range) : Draw borders too.
......
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (sheet_region_adjacent_merge) : new function.
* src/cellspan.c (cell_calc_span) : Use it here to pre bound the
potential span region.
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* src/item-grid.c (item_grid_draw_merged_range) : Draw borders too.
......
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* src/sheet.c (sheet_region_adjacent_merge) : new function.
* src/cellspan.c (cell_calc_span) : Use it here to pre bound the
potential span region.
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* src/item-grid.c (item_grid_draw_merged_range) : Draw borders too.
......
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* ms-excel-read.c (ms_excel_read_mergecells) : enable merged cells.
2000-12-05 Jody Goldberg <jgoldberg@home.com>
* ms-escher.c (ms_escher_read_Blip) : revert to using the old
......
......@@ -3463,13 +3463,7 @@ ms_excel_read_mergecells (BiffQuery *q, ExcelSheet *sheet)
r.end.row = MS_OLE_GET_GUINT16(ptr+2);
r.start.col = MS_OLE_GET_GUINT16(ptr+4);
r.end.col = MS_OLE_GET_GUINT16(ptr+6);
#if 0
/* FIXME : enable when the core support is better
* - draws borders
* - handles attempts to span from neighbouring cells.
*/
sheet_region_merge (NULL, sheet->gnum_sheet, &r);
#endif
#ifndef NO_DEBUG_EXCEL
if (ms_excel_read_debug > 1) {
range_dump (&r);
......
......@@ -154,6 +154,11 @@ cell_contents_fit_inside_column (const Cell *cell)
* - no merged regions
* - no content
*
* No need to check for merged cells here. We have already bounded the search region
* using adjacent merged cells.
*
* We could probably have done the same thing with the span regions too, but
* the current representation is not well suited to that type of search
* returns TRUE if the cell is empty.
*/
static inline gboolean
......@@ -162,14 +167,11 @@ cell_is_empty (Cell const * cell, int col, ColRowInfo const *ri)
CellSpanInfo const *span = row_span_get (ri, col);
if (span != NULL && span->cell != cell)
return FALSE;
return FALSE;
if (!cell_is_blank (sheet_cell_get (cell->base.sheet, col, ri->pos)))
return FALSE;
return FALSE;
/* FIXME : ensure that there are no merged cells checking for the upper
* left is inexpensive, checking for impinging on other areas is not.
*/
return TRUE;
}
......@@ -185,11 +187,13 @@ void
cell_calc_span (Cell const * const cell, int * const col1, int * const col2)
{
Sheet *sheet;
int align, left;
int align, left, max_col, min_col;
int row, pos, margin;
int cell_width_pixel;
MStyle *mstyle;
ColRowInfo const *ri;
Range const *merge_left;
Range const *merge_right;
g_return_if_fail (cell != NULL);
......@@ -231,6 +235,11 @@ cell_calc_span (Cell const * const cell, int * const col1, int * const col2)
cell_width_pixel = cell_rendered_width (cell);
sheet_region_adjacent_merge (sheet, &cell->pos,
&merge_left, &merge_right);
min_col = (merge_left != NULL) ? merge_left->end.col : 0;
max_col = (merge_right != NULL) ? merge_right->start.col : SHEET_MAX_COLS;
switch (align) {
case HALIGN_LEFT:
*col1 = *col2 = cell->pos.col;
......@@ -238,7 +247,7 @@ cell_calc_span (Cell const * const cell, int * const col1, int * const col2)
left = cell_width_pixel - COL_INTERNAL_WIDTH (cell->col_info);
margin = cell->col_info->margin_b;
for (; left > 0 && pos < SHEET_MAX_COLS-1; pos++){
for (; left > 0 && pos < max_col; pos++){
ColRowInfo *ci = sheet_col_get_info (sheet, pos);
if (ci->visible) {
......@@ -263,7 +272,7 @@ cell_calc_span (Cell const * const cell, int * const col1, int * const col2)
left = cell_width_pixel - COL_INTERNAL_WIDTH (cell->col_info);
margin = cell->col_info->margin_a;
for (; left > 0 && pos >= 0; pos--){
for (; left > 0 && pos >= min_col; pos--){
ColRowInfo *ci = sheet_col_get_info (sheet, pos);
if (ci->visible) {
......@@ -297,7 +306,7 @@ cell_calc_span (Cell const * const cell, int * const col1, int * const col2)
for (; remain_left > 0 || remain_right > 0;){
ColRowInfo *ci;
if (*col1 - 1 >= 0){
if (*col1 - 1 >= min_col){
ci = sheet_col_get_info (sheet, *col1 - 1);
if (ci->visible) {
......@@ -315,7 +324,7 @@ cell_calc_span (Cell const * const cell, int * const col1, int * const col2)
} else
remain_left = 0;
if (*col2 + 1 < SHEET_MAX_COLS-1){
if (*col2 + 1 < max_col){
ci = sheet_col_get_info (sheet, *col2 + 1);
if (ci->visible) {
......@@ -347,7 +356,7 @@ cell_calc_span (Cell const * const cell, int * const col1, int * const col2)
left_loop :
tmp = left - 1;
/* When scanning left make sure not to overrun other spans */
if (tmp >= 0) {
if (tmp >= min_col) {
ci = sheet_col_get_info (sheet, tmp);
if (ci->visible) {
if (cell_is_empty (cell, tmp, ri)) {
......@@ -369,7 +378,7 @@ cell_calc_span (Cell const * const cell, int * const col1, int * const col2)
}
right_loop :
tmp = right + 1;
if (tmp < SHEET_MAX_COLS) {
if (tmp < max_col) {
ci = sheet_col_get_info (sheet, tmp);
if (ci->visible) {
if (cell_is_empty (cell, tmp, ri)) {
......
......@@ -101,14 +101,6 @@ move_cursor (GnumericSheet *gsheet, int col, int row, gboolean clear_selection)
sheet_selection_add (sheet, col, row);
}
void
gnumeric_sheet_move_cursor (GnumericSheet *gsheet, int col, int row)
{
g_return_if_fail (GNUMERIC_IS_SHEET (gsheet));
move_cursor (gsheet, col, row, TRUE);
}
void
gnumeric_sheet_set_cursor_bounds (GnumericSheet *gsheet,
int start_col, int start_row,
......@@ -318,8 +310,9 @@ static void
start_cell_selection (GnumericSheet *gsheet)
{
Sheet *sheet = gsheet->scg->sheet;
start_cell_selection_at (gsheet, sheet->cursor.edit_pos.col, sheet->cursor.edit_pos.row);
start_cell_selection_at (gsheet,
sheet->cursor.edit_pos.col,
sheet->cursor.edit_pos.row);
}
void
......
......@@ -50,8 +50,6 @@ GtkType gnumeric_sheet_get_type (void);
GtkWidget *gnumeric_sheet_new (SheetControlGUI *sheet, ItemBar *colbar, ItemBar *rowbar);
void gnumeric_sheet_set_top_row (GnumericSheet *gsheet, int new_first_row);
void gnumeric_sheet_set_left_col (GnumericSheet *gsheet, int new_first_col);
void gnumeric_sheet_move_cursor (GnumericSheet *gsheet,
int col, int row);
gboolean gnumeric_sheet_can_select_expr_range (GnumericSheet *gsheet);
void gnumeric_sheet_set_cursor_bounds (GnumericSheet *gsheet,
int start_col, int start_row,
......
......@@ -101,14 +101,6 @@ move_cursor (GnumericSheet *gsheet, int col, int row, gboolean clear_selection)
sheet_selection_add (sheet, col, row);
}
void
gnumeric_sheet_move_cursor (GnumericSheet *gsheet, int col, int row)
{
g_return_if_fail (GNUMERIC_IS_SHEET (gsheet));
move_cursor (gsheet, col, row, TRUE);
}
void
gnumeric_sheet_set_cursor_bounds (GnumericSheet *gsheet,
int start_col, int start_row,
......@@ -318,8 +310,9 @@ static void
start_cell_selection (GnumericSheet *gsheet)
{
Sheet *sheet = gsheet->scg->sheet;
start_cell_selection_at (gsheet, sheet->cursor.edit_pos.col, sheet->cursor.edit_pos.row);
start_cell_selection_at (gsheet,
sheet->cursor.edit_pos.col,
sheet->cursor.edit_pos.row);
}
void
......
......@@ -50,8 +50,6 @@ GtkType gnumeric_sheet_get_type (void);
GtkWidget *gnumeric_sheet_new (SheetControlGUI *sheet, ItemBar *colbar, ItemBar *rowbar);
void gnumeric_sheet_set_top_row (GnumericSheet *gsheet, int new_first_row);
void gnumeric_sheet_set_left_col (GnumericSheet *gsheet, int new_first_col);
void gnumeric_sheet_move_cursor (GnumericSheet *gsheet,
int col, int row);
gboolean gnumeric_sheet_can_select_expr_range (GnumericSheet *gsheet);
void gnumeric_sheet_set_cursor_bounds (GnumericSheet *gsheet,
int start_col, int start_row,
......
......@@ -31,6 +31,9 @@
#include "clipboard.h"
#include "dialogs.h"
#ifdef ENABLE_BONOBO
#include <bonobo/bonobo-view-frame.h>
#endif
#include <gdk/gdkkeysyms.h>
#include <gdk/gdkx.h>
#include <string.h>
......
......@@ -41,16 +41,25 @@ sheet_object_bonobo_destroy (GtkObject *object)
{
SheetObjectBonobo *sob = SHEET_OBJECT_BONOBO (object);
/* Call parent's destroy method */
GTK_OBJECT_CLASS (sheet_object_bonobo_parent_class)->destroy (object);
if (sob->client_site)
if (sob->client_site != NULL) {
bonobo_object_unref (BONOBO_OBJECT (sob->client_site));
sob->client_site = NULL;
}
#if 0
if (sob->object_server != NULL) {
bonobo_object_unref (BONOBO_OBJECT (sob->object_server));
sob->object_server = NULL;
}
#endif
g_free (sob->object_id);
if (sob->object_id != NULL) {
g_free (sob->object_id);
sob->object_id = NULL;
}
sob->object_server = NULL;
sob->client_site = NULL;
/* Call parent's destroy method */
GTK_OBJECT_CLASS (sheet_object_bonobo_parent_class)->destroy (object);
}
static char *
......
......@@ -3941,6 +3941,43 @@ sheet_region_get_merged (Sheet *sheet, Range const *range)
return res;
}
/**
* sheet_region_adjacent_merge
* @sheet : The sheet to look in.
* @pos : the cell to test for adjacent regions.
* @left : the return for a region on the left
* @right : the return for a region on the right
*
* Returns the nearest regions to either side of @pos.
*/
void
sheet_region_adjacent_merge (Sheet const *sheet, CellPos const *pos,
Range const **left, Range const **right)
{
GSList *ptr;
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (pos != NULL);
*left = *right = NULL;
for (ptr = sheet->list_merged ; ptr != NULL ; ptr = ptr->next) {
Range const * const test = ptr->data;
if (test->start.row <= pos->row && pos->row <= test->end.row) {
int const diff = test->end.col - pos->col;
g_return_if_fail (diff != 0);
if (diff < 0) {
if (*left == NULL || (*left)->end.col < test->end.col)
*left = test;
} else {
if (*right == NULL || (*right)->start.col > test->start.col)
*right = test;
}
}
}
}
/**
* sheet_region_is_merge_cell :
*
......
......@@ -320,6 +320,8 @@ gboolean sheet_region_unmerge (CommandContext *cc,
Sheet *sheet, Range const *r);
GSList *sheet_region_get_merged (Sheet *sheet, Range const *r);
Range const *sheet_region_is_merge_cell (Sheet const *sheet, CellPos const *pos);
void sheet_region_adjacent_merge(Sheet const *sheet, CellPos const *pos,
Range const **left, Range const **right);
#define SHEET_FOREACH_CONTROL(sheet, control, code) \
do { \
......
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