982 |
sheet->autoscroll = TRUE; |
sheet->autoscroll = TRUE; |
983 |
sheet->justify_entry = TRUE; |
sheet->justify_entry = TRUE; |
984 |
sheet->locked = FALSE; |
sheet->locked = FALSE; |
985 |
|
sheet->encode_func = NULL; |
986 |
|
sheet->decode_func = NULL; |
987 |
|
sheet->coding_data = NULL; |
988 |
|
|
989 |
/* set number of rows and columns */ |
/* set number of rows and columns */ |
990 |
GrowSheet(sheet, MINROWS, MINCOLS); |
GrowSheet(sheet, MINROWS, MINCOLS); |
3062 |
PangoContext *context = gtk_widget_get_pango_context(GTK_WIDGET(sheet)); |
PangoContext *context = gtk_widget_get_pango_context(GTK_WIDGET(sheet)); |
3063 |
gint ascent, descent, y_pos; |
gint ascent, descent, y_pos; |
3064 |
|
|
3065 |
char *label; |
|
3066 |
|
|
3067 |
g_return_if_fail (sheet != NULL); |
g_return_if_fail (sheet != NULL); |
3068 |
|
|
3074 |
if (col > sheet->maxalloccol) return; |
if (col > sheet->maxalloccol) return; |
3075 |
if (!sheet->data[row]) return; |
if (!sheet->data[row]) return; |
3076 |
if (!sheet->data[row][col]) return; |
if (!sheet->data[row][col]) return; |
3077 |
if (!sheet->data[row][col]->text || strlen(sheet->data[row][col]->text)==0) |
|
3078 |
|
const gchar *label = gtk_sheet_cell_get_text(sheet, row, col); |
3079 |
|
if (!label || strlen(label)==0) |
3080 |
return; |
return; |
3081 |
|
|
3082 |
if (row < 0 || row > sheet->maxrow) return; |
if (row < 0 || row > sheet->maxrow) return; |
3087 |
|
|
3088 |
widget = GTK_WIDGET(sheet); |
widget = GTK_WIDGET(sheet); |
3089 |
|
|
|
label = sheet->data[row][col]->text; |
|
|
|
|
3090 |
gtk_sheet_get_attributes(sheet, row, col, &attributes); |
gtk_sheet_get_attributes(sheet, row, col, &attributes); |
3091 |
|
|
3092 |
/* select GC for background rectangle */ |
/* select GC for background rectangle */ |
3471 |
gtk_sheet_cell_new() |
gtk_sheet_cell_new() |
3472 |
{ |
{ |
3473 |
GtkSheetCell *cell; |
GtkSheetCell *cell; |
3474 |
cell = g_new(GtkSheetCell, 1); |
cell = g_new0(GtkSheetCell, 1); |
|
cell->text = NULL; |
|
3475 |
cell->link = NULL; |
cell->link = NULL; |
3476 |
cell->attributes = NULL; |
cell->attributes = NULL; |
3477 |
return cell; |
return cell; |
3478 |
} |
} |
3479 |
|
|
3480 |
|
/* Return the GValue of the cell at ROW, COL into VALUE. |
3481 |
|
VALUE must be uninitialised (zero filled), and will be |
3482 |
|
initilized by this function. |
3483 |
|
It is the caller's responsibility to uninitialise it when |
3484 |
|
no longer required. |
3485 |
|
*/ |
3486 |
|
void |
3487 |
|
gtk_sheet_get_cell_value(GtkSheet *sheet, |
3488 |
|
gint row, gint col, GValue *value) |
3489 |
|
|
3490 |
|
{ |
3491 |
|
GtkSheetCell *cell; |
3492 |
|
GtkSheetCellAttr attributes; |
3493 |
|
|
3494 |
|
g_return_if_fail (sheet != NULL); |
3495 |
|
g_return_if_fail (GTK_IS_SHEET (sheet)); |
3496 |
|
if (col > sheet->maxcol || row > sheet->maxrow) return; |
3497 |
|
if (col < 0 || row < 0) return; |
3498 |
|
|
3499 |
|
CheckBounds(sheet, row, col); |
3500 |
|
|
3501 |
|
cell = sheet->data[row][col]; |
3502 |
|
|
3503 |
|
g_value_init(value, G_VALUE_TYPE(&cell->value)); |
3504 |
|
g_value_copy(&cell->value, value); |
3505 |
|
} |
3506 |
|
|
3507 |
|
/* Set the value of the cell at ROW, COL to be VALUE. |
3508 |
|
VALUE is copied by the function and will not be owned or modified */ |
3509 |
|
void |
3510 |
|
gtk_sheet_set_cell_value(GtkSheet *sheet, |
3511 |
|
gint row, gint col, const GValue *value) |
3512 |
|
{ |
3513 |
|
GtkSheetCell *cell; |
3514 |
|
GtkSheetCellAttr attributes; |
3515 |
|
GtkSheetRange range; |
3516 |
|
|
3517 |
|
g_return_if_fail (sheet != NULL); |
3518 |
|
g_return_if_fail (GTK_IS_SHEET (sheet)); |
3519 |
|
if (col > sheet->maxcol || row > sheet->maxrow) return; |
3520 |
|
if (col < 0 || row < 0) return; |
3521 |
|
|
3522 |
|
CheckBounds(sheet, row, col); |
3523 |
|
|
3524 |
|
cell = sheet->data[row][col]; |
3525 |
|
|
3526 |
|
if ( G_IS_VALUE(&cell->value)) |
3527 |
|
g_value_unset(&cell->value); |
3528 |
|
|
3529 |
|
g_value_init(&cell->value, G_VALUE_TYPE(value)); |
3530 |
|
g_value_copy(value, &cell->value); |
3531 |
|
|
3532 |
|
gtk_sheet_get_attributes(sheet, row, col, &attributes); |
3533 |
|
|
3534 |
|
if(attributes.is_visible){ |
3535 |
|
gint text_width; |
3536 |
|
const gchar *text = gtk_sheet_cell_get_text(sheet, row, col); |
3537 |
|
text_width = 0; |
3538 |
|
if(text && strlen(text) > 0) |
3539 |
|
{ |
3540 |
|
text_width = STRING_WIDTH(GTK_WIDGET(sheet), |
3541 |
|
attributes.font_desc, |
3542 |
|
text); |
3543 |
|
} |
3544 |
|
|
3545 |
|
range.row0 = row; |
3546 |
|
range.rowi = row; |
3547 |
|
range.col0 = sheet->view.col0; |
3548 |
|
range.coli = sheet->view.coli; |
3549 |
|
|
3550 |
|
if(gtk_sheet_autoresize(sheet) && |
3551 |
|
text_width > sheet->column[col].width-2*CELLOFFSET-attributes.border.width){ |
3552 |
|
gtk_sheet_set_column_width(sheet, col, text_width+2*CELLOFFSET+attributes.border.width); |
3553 |
|
GTK_SHEET_SET_FLAGS(sheet, GTK_SHEET_REDRAW_PENDING); |
3554 |
|
} |
3555 |
|
else |
3556 |
|
if(!GTK_SHEET_IS_FROZEN(sheet)) |
3557 |
|
gtk_sheet_range_draw(sheet, &range); |
3558 |
|
} |
3559 |
|
|
3560 |
|
|
3561 |
|
gtk_signal_emit(GTK_OBJECT(sheet),sheet_signals[CHANGED], row, col); |
3562 |
|
} |
3563 |
|
|
3564 |
|
|
3565 |
void |
void |
3566 |
gtk_sheet_set_cell_text(GtkSheet *sheet, gint row, gint col, const gchar *text) |
gtk_sheet_set_cell_text(GtkSheet *sheet, gint row, gint col, const gchar *text) |
3567 |
{ |
{ |
3576 |
gtk_sheet_set_cell(sheet, row, col, attributes.justification, text); |
gtk_sheet_set_cell(sheet, row, col, attributes.justification, text); |
3577 |
} |
} |
3578 |
|
|
3579 |
|
|
3580 |
void |
void |
3581 |
gtk_sheet_set_cell(GtkSheet *sheet, gint row, gint col, |
gtk_sheet_set_cell(GtkSheet *sheet, gint row, gint col, |
3582 |
GtkJustification justification, |
GtkJustification justification, |
3607 |
attributes.justification = justification; |
attributes.justification = justification; |
3608 |
gtk_sheet_set_cell_attributes(sheet, row, col, attributes); |
gtk_sheet_set_cell_attributes(sheet, row, col, attributes); |
3609 |
|
|
3610 |
if((*cell)->text){ |
if ( G_IS_VALUE( &(*cell)->value)) |
3611 |
g_free((*cell)->text); |
{ |
3612 |
(*cell)->text = NULL; |
GType the_type = G_VALUE_TYPE(&(*cell)->value); |
|
} |
|
3613 |
|
|
3614 |
if(text) |
g_value_unset( &(*cell)->value); |
3615 |
(*cell)->text=g_strdup(text); |
g_value_init(&(*cell)->value, the_type); |
3616 |
|
} |
3617 |
|
else |
3618 |
|
g_value_init(&(*cell)->value, G_TYPE_STRING); |
3619 |
|
|
3620 |
if(attributes.is_visible){ |
if ( sheet->encode_func) |
3621 |
|
{ |
3622 |
|
sheet->encode_func(row, col, text, &(*cell)->value); |
3623 |
|
} |
3624 |
|
else |
3625 |
|
{ |
3626 |
|
if ( G_TYPE_STRING == G_VALUE_TYPE(&(*cell)->value)) |
3627 |
|
g_value_set_string (&(*cell)->value, text); |
3628 |
|
else |
3629 |
|
{ |
3630 |
|
GValue value = {0}; |
3631 |
|
g_value_init(&value, G_TYPE_STRING); |
3632 |
|
g_value_set_string (&value, text); |
3633 |
|
|
3634 |
|
if (! g_value_type_transformable(G_TYPE_STRING, |
3635 |
|
G_VALUE_TYPE(&(*cell)->value))) |
3636 |
|
{ |
3637 |
|
g_warning ("Transformation from string to %s not possible." |
3638 |
|
" Hint: Use g_value_register_transform_func or set " |
3639 |
|
"a encode function using gtk_sheet_set_coding.", |
3640 |
|
G_VALUE_TYPE_NAME(&(*cell)->value)); |
3641 |
|
} |
3642 |
|
else |
3643 |
|
{ |
3644 |
|
g_assert (g_value_transform(&value, &(*cell)->value)); |
3645 |
|
} |
3646 |
|
g_value_unset(&value); |
3647 |
|
} |
3648 |
|
} |
3649 |
|
|
3650 |
|
if(attributes.is_visible){ |
3651 |
|
const gchar *text = gtk_sheet_cell_get_text(sheet, row, col); |
3652 |
text_width = 0; |
text_width = 0; |
3653 |
if((*cell)->text && strlen((*cell)->text) > 0) { |
if(text && strlen(text) > 0) |
3654 |
text_width = STRING_WIDTH(GTK_WIDGET(sheet), attributes.font_desc, (*cell)->text); |
{ |
3655 |
} |
text_width = STRING_WIDTH(GTK_WIDGET(sheet), |
3656 |
|
attributes.font_desc, |
3657 |
|
text); |
3658 |
|
} |
3659 |
|
|
3660 |
range.row0 = row; |
range.row0 = row; |
3661 |
range.rowi = row; |
range.rowi = row; |
3673 |
} |
} |
3674 |
gtk_signal_emit(GTK_OBJECT(sheet),sheet_signals[CHANGED], row, col); |
gtk_signal_emit(GTK_OBJECT(sheet),sheet_signals[CHANGED], row, col); |
3675 |
|
|
|
|
|
3676 |
} |
} |
3677 |
|
|
3678 |
void |
void |
3724 |
static void |
static void |
3725 |
gtk_sheet_real_cell_clear (GtkSheet *sheet, gint row, gint column, gboolean delete) |
gtk_sheet_real_cell_clear (GtkSheet *sheet, gint row, gint column, gboolean delete) |
3726 |
{ |
{ |
|
gchar *text; |
|
3727 |
gpointer link; |
gpointer link; |
3728 |
|
|
3729 |
if(row > sheet->maxallocrow || column > sheet->maxalloccol) return; |
if(row > sheet->maxallocrow || column > sheet->maxalloccol) return; |
3730 |
if(!sheet->data[row]) return; |
if(!sheet->data[row]) return; |
3731 |
if(!sheet->data[row][column]) return; |
if(!sheet->data[row][column]) return; |
3732 |
|
|
|
text = gtk_sheet_cell_get_text(sheet, row, column); |
|
3733 |
link = gtk_sheet_get_link(sheet, row, column); |
link = gtk_sheet_get_link(sheet, row, column); |
3734 |
|
|
3735 |
if(text){ |
if ( G_IS_VALUE(&sheet->data[row][column]->value)) |
3736 |
g_free(sheet->data[row][column]->text); |
{ |
3737 |
sheet->data[row][column]->text = NULL; |
g_value_reset(&sheet->data[row][column]->value); |
3738 |
|
|
3739 |
if(GTK_IS_OBJECT(sheet) && G_OBJECT(sheet)->ref_count > 0) |
if(GTK_IS_OBJECT(sheet) && G_OBJECT(sheet)->ref_count > 0) |
3740 |
gtk_signal_emit(GTK_OBJECT(sheet),sheet_signals[CLEAR_CELL], row, column); |
gtk_signal_emit(GTK_OBJECT(sheet),sheet_signals[CLEAR_CELL], row, column); |
3741 |
} |
} |
3742 |
|
|
3743 |
if(delete){ |
if(delete){ |
3744 |
if(sheet->data[row][column]->attributes){ |
if(sheet->data[row][column]->attributes){ |
3750 |
if(sheet->data[row][column]) g_free(sheet->data[row][column]); |
if(sheet->data[row][column]) g_free(sheet->data[row][column]); |
3751 |
|
|
3752 |
sheet->data[row][column] = NULL; |
sheet->data[row][column] = NULL; |
3753 |
|
|
3754 |
} |
} |
3755 |
|
|
3756 |
} |
} |
3802 |
} |
} |
3803 |
|
|
3804 |
|
|
3805 |
gchar * |
const gchar * |
3806 |
gtk_sheet_cell_get_text (GtkSheet *sheet, gint row, gint col) |
gtk_sheet_cell_get_text (GtkSheet *sheet, gint row, gint col) |
3807 |
{ |
{ |
3808 |
g_return_val_if_fail (sheet != NULL, NULL); |
g_return_val_if_fail (sheet != NULL, NULL); |
3812 |
if(col < 0 || row < 0) return NULL; |
if(col < 0 || row < 0) return NULL; |
3813 |
if(row > sheet->maxallocrow || col > sheet->maxalloccol) return NULL; |
if(row > sheet->maxallocrow || col > sheet->maxalloccol) return NULL; |
3814 |
if(!sheet->data[row]) return NULL; |
if(!sheet->data[row]) return NULL; |
|
if(!sheet->data[row][col]) return NULL; |
|
|
if(!sheet->data[row][col]->text) return NULL; |
|
|
if(strlen(sheet->data[row][col]->text) == 0) return NULL; |
|
3815 |
|
|
3816 |
return (sheet->data[row][col]->text); |
GtkSheetCell *cell = sheet->data[row][col]; |
3817 |
|
if(!cell) return NULL; |
3818 |
|
|
3819 |
|
if ( sheet->decode_func ) |
3820 |
|
{ |
3821 |
|
return sheet->decode_func(row, col, &cell->value); |
3822 |
|
} |
3823 |
|
else |
3824 |
|
{ |
3825 |
|
if (G_IS_VALUE(&cell->value)) |
3826 |
|
{ |
3827 |
|
const gchar *text; |
3828 |
|
if ( G_VALUE_HOLDS(&cell->value, G_TYPE_STRING)) |
3829 |
|
text = g_value_get_string(&cell->value); |
3830 |
|
else |
3831 |
|
{ |
3832 |
|
GValue new_value = {0}; |
3833 |
|
g_value_init(&new_value, G_TYPE_STRING); |
3834 |
|
g_value_transform(&cell->value, &new_value); |
3835 |
|
text = g_value_get_string(&new_value); |
3836 |
|
g_value_unset(&new_value); |
3837 |
|
} |
3838 |
|
return text; |
3839 |
|
} |
3840 |
|
} |
3841 |
|
|
3842 |
|
return NULL; |
3843 |
} |
} |
3844 |
|
|
3845 |
void |
void |
4060 |
} |
} |
4061 |
else |
else |
4062 |
{ |
{ |
4063 |
/* Added by Matias Mutchinick */ |
/* Added by Matias Mutchinick */ |
4064 |
if(row < sheet->maxallocrow && col < sheet->maxalloccol && sheet->data[row] && sheet->data[row][col] && sheet->data[row][col]->text) { |
if(row < sheet->maxallocrow && col < sheet->maxalloccol && |
4065 |
g_free(sheet->data[row][col]->text); |
sheet->data[row] && sheet->data[row][col] ) |
4066 |
sheet->data[row][col]->text = NULL; |
{ |
4067 |
} |
if ( G_IS_VALUE(&sheet->data[row][col]->value)) |
4068 |
|
g_value_reset(&sheet->data[row][col]->value); |
4069 |
|
} |
4070 |
} |
} |
4071 |
|
|
4072 |
if(sheet->freeze_count == 0) |
if(sheet->freeze_count == 0) |
4218 |
static void |
static void |
4219 |
gtk_sheet_show_active_cell(GtkSheet *sheet) |
gtk_sheet_show_active_cell(GtkSheet *sheet) |
4220 |
{ |
{ |
4221 |
GtkSheetCell *cell; |
|
4222 |
GtkEntry *sheet_entry; |
GtkEntry *sheet_entry; |
4223 |
GtkSheetCellAttr attributes; |
GtkSheetCellAttr attributes; |
4224 |
gchar *text = NULL; |
gchar *text = NULL; |
4252 |
justification = attributes.justification; |
justification = attributes.justification; |
4253 |
|
|
4254 |
if(row <= sheet->maxallocrow && col <= sheet->maxalloccol) { |
if(row <= sheet->maxallocrow && col <= sheet->maxalloccol) { |
4255 |
if(sheet->data[row]) { |
if(sheet->data[row] && sheet->data[row][col]) |
4256 |
if(sheet->data[row][col]) { |
{ |
4257 |
cell = sheet->data[row][col]; |
GtkSheetCell *cell = sheet->data[row][col]; |
4258 |
if(cell->text) |
const gchar *t = gtk_sheet_cell_get_text(sheet, row, col); |
4259 |
text = g_strdup(cell->text); |
if(t) |
4260 |
} |
text = g_strdup(t); |
4261 |
} |
} |
4262 |
} |
} |
4263 |
|
|
4264 |
if(!text) text = g_strdup(""); |
if(!text) text = g_strdup(""); |
7577 |
|
|
7578 |
} |
} |
7579 |
|
|
7580 |
|
|
7581 |
|
void |
7582 |
|
gtk_sheet_set_coding(GtkSheet *sheet, GtkSheetEncodeFunc encode, |
7583 |
|
GtkSheetDecodeFunc decode, |
7584 |
|
gpointer data) |
7585 |
|
{ |
7586 |
|
g_return_if_fail (sheet != NULL); |
7587 |
|
g_return_if_fail (GTK_IS_SHEET (sheet)); |
7588 |
|
|
7589 |
|
sheet->encode_func = encode; |
7590 |
|
sheet->decode_func = decode; |
7591 |
|
sheet->coding_data = data; |
7592 |
|
} |
7593 |
|
|
7594 |
|
|
7595 |
|
void |
7596 |
|
gtk_sheet_range_set_type(GtkSheet *sheet, const GtkSheetRange *urange, GType type) |
7597 |
|
{ |
7598 |
|
gint i, j; |
7599 |
|
GtkSheetRange range; |
7600 |
|
|
7601 |
|
g_return_if_fail (sheet != NULL); |
7602 |
|
g_return_if_fail (GTK_IS_SHEET (sheet)); |
7603 |
|
|
7604 |
|
if(!urange) |
7605 |
|
range = sheet->range; |
7606 |
|
else |
7607 |
|
range = *urange; |
7608 |
|
|
7609 |
|
for (i=range.row0; i<=range.rowi; i++) |
7610 |
|
{ |
7611 |
|
for (j=range.col0; j<=range.coli; j++) |
7612 |
|
{ |
7613 |
|
GtkSheetCell *cell; |
7614 |
|
|
7615 |
|
CheckBounds(sheet, i, j); |
7616 |
|
|
7617 |
|
cell = sheet->data[i][j]; |
7618 |
|
|
7619 |
|
if ( G_IS_VALUE(&cell->value)) |
7620 |
|
{ |
7621 |
|
if ( G_VALUE_TYPE(&cell->value) == type ) |
7622 |
|
continue; |
7623 |
|
g_value_unset(&cell->value); |
7624 |
|
} |
7625 |
|
|
7626 |
|
g_value_init(&cell->value, type); |
7627 |
|
} |
7628 |
|
} |
7629 |
|
} |
7630 |
|
|
7631 |
void |
void |
7632 |
gtk_sheet_range_set_background(GtkSheet *sheet, const GtkSheetRange *urange, const GdkColor *color) |
gtk_sheet_range_set_background(GtkSheet *sheet, const GtkSheetRange *urange, const GdkColor *color) |
7633 |
{ |
{ |