-/* This version of GtkSheet has been heavily modified, for the specific
+/* This version of GtkSheet has been *heavily* modified, for the specific
requirements of PSPPIRE. */
/* GtkSheet widget for Gtk+.
#define DEFAULT_COLUMN_WIDTH 80
+static gboolean gtk_sheet_cell_empty (const GtkSheet *sheet, gint row, gint col);
+static inline
+void dispose_string (const GtkSheet *sheet, gchar *text)
+{
+ GSheetModel *model = gtk_sheet_get_model(sheet);
+
+ if ( ! model )
+ return;
+ if (g_sheet_model_free_strings(model))
+ g_free(text);
+}
static inline
guint DEFAULT_ROW_HEIGHT(GtkWidget *widget)
g_return_if_fail (GTK_IS_SHEET (sheet));
if (column >= xxx_column_count(sheet) || column < 0) return;
- for (row = 0; row < yyy_row_count(sheet); row++){
- const gchar *text = gtk_sheet_cell_get_text(sheet, row, column);
- if (text && strlen(text) > 0){
- GtkSheetCellAttr attributes;
-
- gtk_sheet_get_attributes(sheet, row, column, &attributes);
- if(attributes.is_visible){
- gint width = STRING_WIDTH(GTK_WIDGET(sheet),
- attributes.font_desc,
- text)
- + 2*CELLOFFSET + attributes.border.width;
- text_width = MAX (text_width, width);
+ for (row = 0; row < yyy_row_count(sheet); row++)
+ {
+ gchar *text = gtk_sheet_cell_get_text(sheet, row, column);
+ if (text && strlen(text) > 0){
+ GtkSheetCellAttr attributes;
+
+ gtk_sheet_get_attributes(sheet, row, column, &attributes);
+ if(attributes.is_visible){
+ gint width = STRING_WIDTH(GTK_WIDGET(sheet),
+ attributes.font_desc,
+ text)
+ + 2*CELLOFFSET + attributes.border.width;
+ text_width = MAX (text_width, width);
+ }
}
+ dispose_string(sheet, text);
}
- }
if(text_width > xxx_column_width(sheet, column) )
{
PangoContext *context = gtk_widget_get_pango_context(GTK_WIDGET(sheet));
gint ascent, descent, y_pos;
- const gchar *label;
+ gchar *label;
g_return_if_fail (sheet != NULL);
clip_area = area;
layout = gtk_widget_create_pango_layout (GTK_WIDGET(sheet), label);
+ dispose_string(sheet, label);
pango_layout_set_font_description (layout, attributes.font_desc);
pango_layout_get_pixel_extents (layout, NULL, &rect);
area.x+=area.width;
if(!gtk_sheet_clip_text(sheet)){
for(i=col-1; i>=MIN_VISIBLE_COLUMN(sheet); i--){
- if(gtk_sheet_cell_get_text(sheet, row, i)) break;
+ if( !gtk_sheet_cell_empty(sheet, row, i)) break;
if(size>=text_width+CELLOFFSET) break;
size+=xxx_column_width(sheet, i);
xxx_column_set_right_column(sheet, i,
area.x+=area.width/2;
if(!gtk_sheet_clip_text(sheet)){
for(i=col+1; i<=MAX_VISIBLE_COLUMN(sheet); i++){
- if(gtk_sheet_cell_get_text(sheet, row, i)) break;
+ if( ! gtk_sheet_cell_empty(sheet, row, i)) break;
if(sizer>=text_width/2) break;
sizer+= xxx_column_width(sheet, i);
xxx_column_set_left_column(sheet, i,
xxx_column_left_column(sheet, i)));
}
for(i=col-1; i>=MIN_VISIBLE_COLUMN(sheet); i--){
- if(gtk_sheet_cell_get_text(sheet, row, i)) break;
+ if( ! gtk_sheet_cell_empty(sheet, row, i)) break;
if(sizel>=text_width/2) break;
sizel+=xxx_column_width(sheet, i);
xxx_column_set_right_column(sheet, i,
size=area.width;
if(!gtk_sheet_clip_text(sheet)){
for(i=col+1; i<=MAX_VISIBLE_COLUMN(sheet); i++){
- if(gtk_sheet_cell_get_text(sheet, row, i)) break;
+ if(! gtk_sheet_cell_empty(sheet, row, i)) break;
if(size>=text_width+CELLOFFSET) break;
size+=xxx_column_width(sheet, i);
xxx_column_set_left_column(sheet, i,
{
GSheetModel *model ;
gboolean changed ;
- const gchar *old_text ;
+ gchar *old_text ;
GtkSheetRange range;
gint text_width;
if (0 != safe_strcmp(old_text, text))
changed = g_sheet_model_set_string(model, text, row, col);
+ if ( g_sheet_model_free_strings(model))
+ g_free(old_text);
+
+
if(changed && attributes.is_visible)
{
- const gchar *s = gtk_sheet_cell_get_text(sheet, row, col);
+ gchar *s = gtk_sheet_cell_get_text(sheet, row, col);
text_width = 0;
if(s && strlen(s) > 0) {
text_width = STRING_WIDTH(GTK_WIDGET(sheet),
attributes.font_desc, text);
}
+ dispose_string(sheet, s);
range.row0 = row;
range.rowi = row;
{
GSheetModel *model = gtk_sheet_get_model(sheet);
- const gchar *old_text = gtk_sheet_cell_get_text(sheet, row, column);
+ gchar *old_text = gtk_sheet_cell_get_text(sheet, row, column);
if (old_text && strlen(old_text) > 0 )
{
row, column);
}
+ dispose_string (sheet, old_text);
}
void
}
-const gchar *
-gtk_sheet_cell_get_text (GtkSheet *sheet, gint row, gint col)
+static gboolean
+gtk_sheet_cell_empty (const GtkSheet *sheet, gint row, gint col)
+{
+ gboolean empty;
+ char *text = gtk_sheet_cell_get_text(sheet, row, col);
+ empty = (text == NULL );
+
+ dispose_string(sheet, text);
+
+ return empty;
+}
+
+
+gchar *
+gtk_sheet_cell_get_text (const GtkSheet *sheet, gint row, gint col)
{
GSheetModel *model;
g_return_val_if_fail (sheet != NULL, NULL);
if(gtk_sheet_justify_entry(sheet))
justification = attributes.justification;
- text = g_strdup(gtk_sheet_cell_get_text(sheet, row, col));
-
- if(!text) text = g_strdup("");
+ text = gtk_sheet_cell_get_text(sheet, row, col);
+ if ( ! text )
+ text = g_strdup("");
gtk_entry_set_visibility(GTK_ENTRY(sheet_entry), attributes.is_visible);
gtk_widget_grab_focus(GTK_WIDGET(sheet_entry));
- g_free(text);
+ dispose_string(sheet, text);
}
static void
shadow_type = GTK_SHADOW_OUT;
if(state != GTK_STATE_NORMAL && state != GTK_STATE_INSENSITIVE)
- gtk_paint_box (sheet->button->style, window,
- button->state, shadow_type,
- &allocation, GTK_WIDGET(sheet->button),
- "button", x, y, width, height);
+ gtk_paint_box (sheet->button->style, window,
+ button->state, shadow_type,
+ &allocation, GTK_WIDGET(sheet->button),
+ "button", x, y, width, height);
if(button->label_visible){