-/* This version of GtkSheet has been *heavily* modified, for the specific
- requirements of PSPPIRE. */
+/*
+ * Copyright (C) 2006, 2008 Free Software Foundation
+ *
+ * This version of GtkSheet has been *heavily* modified, for the specific
+ * requirements of PSPPIRE. The changes are copyright by the
+ * Free Software Foundation. The copyright notice for the original work is
+ * below.
+ */
/* GtkSheet widget for Gtk+.
* Copyright (C) 1999-2001 Adrian E. Feiguin <adrian@ifir.ifir.edu.ar>
/* sheet flags */
enum
{
- GTK_SHEET_IS_LOCKED = 1 << 0,
GTK_SHEET_IS_FROZEN = 1 << 1,
GTK_SHEET_IN_XDRAG = 1 << 2,
GTK_SHEET_IN_YDRAG = 1 << 3,
#define GTK_SHEET_SET_FLAGS(sheet,flag) (GTK_SHEET_FLAGS (sheet) |= (flag))
#define GTK_SHEET_UNSET_FLAGS(sheet,flag) (GTK_SHEET_FLAGS (sheet) &= ~ (flag))
-#define GTK_SHEET_IS_LOCKED(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IS_LOCKED)
-
-
#define GTK_SHEET_IS_FROZEN(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IS_FROZEN)
#define GTK_SHEET_IN_XDRAG(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_XDRAG)
#define GTK_SHEET_IN_YDRAG(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_YDRAG)
static void gtk_sheet_update_primary_selection (GtkSheet *sheet);
-
-
static void gtk_sheet_column_title_button_draw (GtkSheet *sheet, gint column);
static void gtk_sheet_row_title_button_draw (GtkSheet *sheet, gint row);
static gboolean gtk_sheet_cell_empty (const GtkSheet *sheet, gint row, gint col);
-static inline
-void dispose_string (const GtkSheet *sheet, gchar *text)
+static inline void
+dispose_string (const GtkSheet *sheet, gchar *text)
{
GSheetModel *model = gtk_sheet_get_model (sheet);
pango_context_get_metrics (context,
widget->style->font_desc,
pango_context_get_language (context));
+
guint val = pango_font_metrics_get_descent (metrics) +
pango_font_metrics_get_ascent (metrics);
+
pango_font_metrics_unref (metrics);
- return PANGO_PIXELS (val)+2 * CELLOFFSET;
+
+ return PANGO_PIXELS (val) + 2 * CELLOFFSET;
}
}
pango_layout_get_extents (layout, NULL, &rect);
- g_object_unref (G_OBJECT (layout));
+ g_object_unref (layout);
return PANGO_PIXELS (rect.width);
}
static void gtk_sheet_class_init (GtkSheetClass * klass);
static void gtk_sheet_init (GtkSheet * sheet);
-static void gtk_sheet_destroy (GtkObject * object);
+static void gtk_sheet_dispose (GObject * object);
static void gtk_sheet_finalize (GObject * object);
static void gtk_sheet_style_set (GtkWidget *widget,
GtkStyle *previous_style);
static void gtk_sheet_entry_changed (GtkWidget *widget,
gpointer data);
-static gboolean gtk_sheet_deactivate_cell (GtkSheet *sheet);
+static void gtk_sheet_deactivate_cell (GtkSheet *sheet);
static void gtk_sheet_hide_active_cell (GtkSheet *sheet);
static gboolean gtk_sheet_activate_cell (GtkSheet *sheet,
gint row, gint col);
TRAVERSE,
DEACTIVATE,
ACTIVATE,
- SET_CELL,
- CLEAR_CELL,
CHANGED,
- NEW_COL_WIDTH,
- NEW_ROW_HEIGHT,
LAST_SIGNAL
};
return sheet_range_type;
}
+
+static void column_titles_changed (GtkWidget *w, gint first, gint n_columns, gpointer data);
+
+/* Properties */
+enum
+ {
+ PROP_0,
+ PROP_ROW_GEO,
+ PROP_COL_GEO,
+ PROP_MODEL
+ };
+
+static void
+gtk_sheet_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+
+{
+ GtkSheet *sheet = GTK_SHEET (object);
+
+ switch (prop_id)
+ {
+ case PROP_ROW_GEO:
+ sheet->row_geometry = g_value_get_pointer (value);
+ break;
+ case PROP_COL_GEO:
+ sheet->column_geometry = g_value_get_pointer (value);
+ if ( sheet->column_geometry)
+ g_signal_connect (sheet->column_geometry, "columns_changed",
+ G_CALLBACK (column_titles_changed), sheet);
+ break;
+ case PROP_MODEL:
+ gtk_sheet_set_model (sheet, g_value_get_pointer (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+static void
+gtk_sheet_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkSheet *sheet = GTK_SHEET (object);
+
+ switch (prop_id)
+ {
+ case PROP_ROW_GEO:
+ g_value_set_pointer (value, sheet->row_geometry);
+ break;
+ case PROP_COL_GEO:
+ g_value_set_pointer (value, sheet->column_geometry);
+ break;
+ case PROP_MODEL:
+ g_value_set_pointer (value, sheet->model);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ };
+}
+
+
static void
gtk_sheet_class_init (GtkSheetClass * klass)
{
- GtkObjectClass *object_class;
- GtkWidgetClass *widget_class;
- GtkContainerClass *container_class;
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class = (GtkObjectClass *) klass;
- widget_class = (GtkWidgetClass *) klass;
- container_class = (GtkContainerClass *) klass;
+ GParamSpec *row_geo_spec ;
+ GParamSpec *col_geo_spec ;
+ GParamSpec *model_spec ;
+
+ GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
+ GtkContainerClass *container_class = (GtkContainerClass *) klass;
parent_class = g_type_class_peek_parent (klass);
G_SIGNAL_RUN_LAST,
offsetof (GtkSheetClass, select_row),
NULL, NULL,
- gtkextra_VOID__INT,
+ g_cclosure_marshal_VOID__INT,
G_TYPE_NONE,
1,
G_TYPE_INT);
G_SIGNAL_RUN_LAST,
offsetof (GtkSheetClass, select_column),
NULL, NULL,
- gtkextra_VOID__INT,
+ g_cclosure_marshal_VOID__INT,
G_TYPE_NONE,
1,
G_TYPE_INT);
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- gtkextra_VOID__INT,
+ g_cclosure_marshal_VOID__INT,
G_TYPE_NONE,
1,
G_TYPE_INT);
G_SIGNAL_RUN_LAST,
0,
NULL, NULL,
- gtkextra_VOID__INT,
+ g_cclosure_marshal_VOID__INT,
G_TYPE_NONE,
1,
G_TYPE_INT);
G_SIGNAL_RUN_LAST,
offsetof (GtkSheetClass, select_range),
NULL, NULL,
- gtkextra_VOID__BOXED,
+ g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE,
1,
GTK_TYPE_SHEET_RANGE);
G_SIGNAL_RUN_LAST,
offsetof (GtkSheetClass, deactivate),
NULL, NULL,
- gtkextra_BOOLEAN__INT_INT,
- G_TYPE_BOOLEAN, 2, G_TYPE_INT, G_TYPE_INT);
+ gtkextra_VOID__INT_INT,
+ G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
sheet_signals[ACTIVATE] =
g_signal_new ("activate",
gtkextra_BOOLEAN__INT_INT,
G_TYPE_BOOLEAN, 2, G_TYPE_INT, G_TYPE_INT);
- sheet_signals[SET_CELL] =
- g_signal_new ("set-cell",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- offsetof (GtkSheetClass, set_cell),
- NULL, NULL,
- gtkextra_VOID__INT_INT,
- G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
-
-
- sheet_signals[CLEAR_CELL] =
- g_signal_new ("clear-cell",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- offsetof (GtkSheetClass, clear_cell),
- NULL, NULL,
- gtkextra_VOID__INT_INT,
- G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
-
sheet_signals[CHANGED] =
g_signal_new ("changed",
G_TYPE_FROM_CLASS (object_class),
gtkextra_VOID__INT_INT,
G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
- sheet_signals[NEW_COL_WIDTH] =
- g_signal_new ("new-column-width",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- offsetof (GtkSheetClass, new_column_width), /*!!!! */
- NULL, NULL,
- gtkextra_VOID__INT_INT,
- G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
-
- sheet_signals[NEW_ROW_HEIGHT] =
- g_signal_new ("new-row-height",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- offsetof (GtkSheetClass, new_row_height), /*!!!! */
- NULL, NULL,
- gtkextra_VOID__INT_INT,
- G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
-
widget_class->set_scroll_adjustments_signal =
g_signal_new ("set-scroll-adjustments",
G_TYPE_FROM_CLASS (object_class),
container_class->remove = gtk_sheet_remove;
container_class->forall = gtk_sheet_forall;
- object_class->destroy = gtk_sheet_destroy;
- gobject_class->finalize = gtk_sheet_finalize;
+ object_class->dispose = gtk_sheet_dispose;
+ object_class->finalize = gtk_sheet_finalize;
+
+
+ row_geo_spec =
+ g_param_spec_pointer ("row-geometry",
+ "Row Geometry",
+ "A pointer to the model of the row geometry",
+ G_PARAM_READABLE | G_PARAM_WRITABLE );
+
+ col_geo_spec =
+ g_param_spec_pointer ("column-geometry",
+ "Column Geometry",
+ "A pointer to the model of the column geometry",
+ G_PARAM_READABLE | G_PARAM_WRITABLE );
+
+ model_spec =
+ g_param_spec_pointer ("model",
+ "Model",
+ "A pointer to the data model",
+ G_PARAM_READABLE | G_PARAM_WRITABLE );
+
+
+ object_class->set_property = gtk_sheet_set_property;
+ object_class->get_property = gtk_sheet_get_property;
+
+ g_object_class_install_property (object_class,
+ PROP_ROW_GEO,
+ row_geo_spec);
+
+ g_object_class_install_property (object_class,
+ PROP_COL_GEO,
+ col_geo_spec);
+
+ g_object_class_install_property (object_class,
+ PROP_MODEL,
+ model_spec);
+
widget_class->realize = gtk_sheet_realize;
widget_class->unrealize = gtk_sheet_unrealize;
klass->traverse = NULL;
klass->deactivate = NULL;
klass->activate = NULL;
- klass->set_cell = NULL;
- klass->clear_cell = NULL;
klass->changed = NULL;
}
sheet->selection_cell.row = 0;
sheet->selection_cell.col = 0;
- sheet->sheet_entry = NULL;
sheet->pixmap = NULL;
sheet->range.row0 = 0;
sheet->sheet_window = NULL;
sheet->sheet_window_width = 0;
sheet->sheet_window_height = 0;
- sheet->sheet_entry = NULL;
+ sheet->entry_widget = NULL;
+ sheet->entry_container = NULL;
sheet->button = NULL;
sheet->hoffset = 0;
sheet->show_grid = TRUE;
sheet->motion_timer = 0;
+
+ sheet->columns_resizable = TRUE;
+ sheet->rows_resizable = TRUE;
+
+ sheet->row_titles_visible = TRUE;
+ sheet->row_title_area.width = DEFAULT_COLUMN_WIDTH;
+
+ sheet->column_titles_visible = TRUE;
+ sheet->autoscroll = TRUE;
+ sheet->justify_entry = TRUE;
+
+
+ /* create sheet entry */
+ sheet->entry_type = 0;
+ create_sheet_entry (sheet);
+
+ /* create global selection button */
+ create_global_button (sheet);
}
}
-static void gtk_sheet_construct (GtkSheet *sheet,
- GSheetRow *vgeo,
- GSheetColumn *hgeo,
- const gchar *title);
-
-
/**
* gtk_sheet_new:
* @rows: initial number of rows
* Returns: the new sheet widget
*/
GtkWidget *
-gtk_sheet_new (GSheetRow *vgeo, GSheetColumn *hgeo, const gchar *title,
- GSheetModel *model)
+gtk_sheet_new (GSheetRow *vgeo, GSheetColumn *hgeo, GSheetModel *model)
{
- GtkWidget *widget = g_object_new (GTK_TYPE_SHEET, NULL);
-
- gtk_sheet_construct (GTK_SHEET (widget), vgeo, hgeo, title);
-
- if (model)
- gtk_sheet_set_model (GTK_SHEET (widget), model);
-
-
+ GtkWidget *widget = g_object_new (GTK_TYPE_SHEET,
+ "row-geometry", vgeo,
+ "column-geometry", hgeo,
+ "model", model,
+ NULL);
return widget;
}
gtk_sheet_set_model (GtkSheet *sheet, GSheetModel *model)
{
g_return_if_fail (GTK_IS_SHEET (sheet));
- g_return_if_fail (G_IS_SHEET_MODEL (model));
- sheet->model = model;
+ if (sheet->model ) g_object_unref (sheet->model);
- g_signal_connect (model, "range_changed",
- G_CALLBACK (range_update_callback), sheet);
+ sheet->model = model;
- g_signal_connect (model, "rows_inserted",
- G_CALLBACK (rows_inserted_deleted_callback), sheet);
+ if ( model)
+ {
+ g_signal_connect (model, "range_changed",
+ G_CALLBACK (range_update_callback), sheet);
- g_signal_connect (model, "rows_deleted",
- G_CALLBACK (rows_inserted_deleted_callback), sheet);
+ g_signal_connect (model, "rows_inserted",
+ G_CALLBACK (rows_inserted_deleted_callback), sheet);
- g_signal_connect (model, "columns_inserted",
- G_CALLBACK (columns_inserted_deleted_callback), sheet);
+ g_signal_connect (model, "rows_deleted",
+ G_CALLBACK (rows_inserted_deleted_callback), sheet);
- g_signal_connect (model, "columns_deleted",
- G_CALLBACK (columns_inserted_deleted_callback), sheet);
+ g_signal_connect (model, "columns_inserted",
+ G_CALLBACK (columns_inserted_deleted_callback), sheet);
+ g_signal_connect (model, "columns_deleted",
+ G_CALLBACK (columns_inserted_deleted_callback), sheet);
+ }
}
for ( i = first ; i <= first + n_columns ; ++i )
{
gtk_sheet_column_title_button_draw (sheet, i);
- g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, -1, i);
+ g_signal_emit (sheet, sheet_signals[CHANGED], 0, -1, i);
}
}
}
-static void
-gtk_sheet_construct (GtkSheet *sheet,
- GSheetRow *vgeo,
- GSheetColumn *hgeo,
- const gchar *title)
-{
- g_return_if_fail (G_IS_SHEET_COLUMN (hgeo));
- g_return_if_fail (G_IS_SHEET_ROW (vgeo));
-
- sheet->column_geometry = hgeo;
- sheet->row_geometry = vgeo;
-
-
- sheet->columns_resizable = TRUE;
- sheet->rows_resizable = TRUE;
-
- sheet->row_titles_visible = TRUE;
- sheet->row_title_area.width = DEFAULT_COLUMN_WIDTH;
-
- sheet->column_titles_visible = TRUE;
- sheet->autoscroll = TRUE;
- sheet->justify_entry = TRUE;
-
-
- /* create sheet entry */
- sheet->entry_type = 0;
- create_sheet_entry (sheet);
-
- /* create global selection button */
- create_global_button (sheet);
-
- if (title)
- sheet->name = g_strdup (title);
-
- g_signal_connect (sheet->column_geometry, "columns_changed",
- G_CALLBACK (column_titles_changed), sheet);
-
-}
-
-
-GtkWidget *
-gtk_sheet_new_with_custom_entry (GSheetRow *rows, GSheetColumn *columns,
- const gchar *title, GtkType entry_type)
-{
- GtkWidget *widget = g_object_new (GTK_TYPE_SHEET, NULL);
-
- gtk_sheet_construct_with_custom_entry (GTK_SHEET (widget),
- rows, columns, title, entry_type);
-
- return widget;
-}
-
-void
-gtk_sheet_construct_with_custom_entry (GtkSheet *sheet,
- GSheetRow *vgeo,
- GSheetColumn *hgeo,
- const gchar *title,
- GtkType entry_type)
-{
- gtk_sheet_construct (sheet, vgeo, hgeo, title);
-
- sheet->entry_type = entry_type;
- create_sheet_entry (sheet);
-}
-
-
-
void
gtk_sheet_change_entry (GtkSheet *sheet, GtkType entry_type)
{
if (state == GTK_SHEET_NORMAL)
{
gtk_sheet_show_active_cell (sheet);
- g_signal_connect (G_OBJECT (gtk_sheet_get_entry (sheet)),
+ g_signal_connect (gtk_sheet_get_entry (sheet),
"changed",
G_CALLBACK (gtk_sheet_entry_changed),
sheet);
return sheet->justify_entry;
}
-void
-gtk_sheet_set_locked (GtkSheet *sheet, gboolean locked)
-{
- g_return_if_fail (sheet != NULL);
- g_return_if_fail (GTK_IS_SHEET (sheet));
-
- if ( locked )
- {
- GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_IS_LOCKED);
- gtk_widget_hide (sheet->sheet_entry);
- gtk_widget_unmap (sheet->sheet_entry);
- }
- else
- {
- GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_IS_LOCKED);
- if (GTK_WIDGET_MAPPED (GTK_WIDGET (sheet)))
- {
- gtk_widget_show (sheet->sheet_entry);
- gtk_widget_map (sheet->sheet_entry);
- }
- }
-
- gtk_editable_set_editable (GTK_EDITABLE (sheet->sheet_entry), locked);
-
-}
-
-gboolean
-gtk_sheet_locked (const GtkSheet *sheet)
-{
- g_return_val_if_fail (sheet != NULL, FALSE);
- g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
-
- return GTK_SHEET_IS_LOCKED (sheet);
-}
-
-/* This routine has problems with gtk+- 1.2 related with the
- label / button drawing - I think it's a bug in gtk+- 1.2 */
-void
-gtk_sheet_set_title (GtkSheet *sheet, const gchar *title)
-{
- GtkWidget *label;
-
- g_return_if_fail (sheet != NULL);
- g_return_if_fail (title != NULL);
- g_return_if_fail (GTK_IS_SHEET (sheet));
-
- if (sheet->name)
- g_free (sheet->name);
-
- sheet->name = g_strdup (title);
- if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)) || !title) return;
-
- if (GTK_BIN (sheet->button)->child)
- label = GTK_BIN (sheet->button)->child;
-
- size_allocate_global_button (sheet);
-}
void
gtk_sheet_freeze (GtkSheet *sheet)
sheet->old_hadjustment = -1.;
if (sheet->hadjustment)
- g_signal_emit_by_name (G_OBJECT (sheet->hadjustment),
+ g_signal_emit_by_name (sheet->hadjustment,
"value_changed");
if (sheet->vadjustment)
- g_signal_emit_by_name (G_OBJECT (sheet->vadjustment),
+ g_signal_emit_by_name (sheet->vadjustment,
"value_changed");
if (sheet->state == GTK_STATE_NORMAL)
- if (sheet->sheet_entry && GTK_WIDGET_MAPPED (sheet->sheet_entry))
+ if (sheet->entry_widget && GTK_WIDGET_MAPPED (sheet->entry_widget))
{
gtk_sheet_activate_cell (sheet, sheet->active_cell.row,
sheet->active_cell.col);
sheet->old_hadjustment = -1.;
if (sheet->hadjustment)
- g_signal_emit_by_name (G_OBJECT (sheet->hadjustment),
+ g_signal_emit_by_name (sheet->hadjustment,
"value_changed");
size_allocate_global_button (sheet);
}
sheet->old_vadjustment = -1.;
if (sheet->vadjustment)
- g_signal_emit_by_name (G_OBJECT (sheet->vadjustment),
+ g_signal_emit_by_name (sheet->vadjustment,
"value_changed");
size_allocate_global_button (sheet);
}
sheet->old_vadjustment = -1.;
if (sheet->vadjustment)
- g_signal_emit_by_name (G_OBJECT (sheet->vadjustment),
+ g_signal_emit_by_name (sheet->vadjustment,
"value_changed");
size_allocate_global_button (sheet);
}
sheet->old_hadjustment = -1.;
if (sheet->hadjustment)
- g_signal_emit_by_name (G_OBJECT (sheet->hadjustment),
+ g_signal_emit_by_name (sheet->hadjustment,
"value_changed");
size_allocate_global_button (sheet);
}
sheet->old_vadjustment = -1.;
if (sheet->vadjustment)
- g_signal_emit_by_name (G_OBJECT (sheet->vadjustment),
+ g_signal_emit_by_name (sheet->vadjustment,
"value_changed");
}
sheet->old_hadjustment = -1.;
if (sheet->hadjustment)
- g_signal_emit_by_name (G_OBJECT (sheet->hadjustment),
+ g_signal_emit_by_name (sheet->hadjustment,
"value_changed");
}
width = sheet->sheet_window_width;
/* adjust vertical scrollbar */
- if (row >= 0 && row_align >= 0.)
+ if (row >= 0 && row_align >= 0.0)
{
y = ROW_TOP_YPIXEL (sheet, row) - sheet->voffset
- - (gint) ( row_align*height + (1. - row_align)
+ - (gint) ( row_align * height + (1.0 - row_align)
* yyy_row_height (sheet, row));
/* This forces the sheet to scroll when you don't see the entire cell */
min_row = row;
adjust = 0;
- if (row_align == 1.)
+ if (row_align >= 1.0)
{
while (min_row >= 0 && min_row > MIN_VISIBLE_ROW (sheet))
{
if (yyy_row_is_visible (sheet, min_row))
adjust += yyy_row_height (sheet, min_row);
+
if (adjust >= height)
{
break;
min_row--;
}
min_row = MAX (min_row, 0);
+
+ min_row ++;
+
y = ROW_TOP_YPIXEL (sheet, min_row) - sheet->voffset +
yyy_row_height (sheet, min_row) - 1;
}
sheet->vadjustment->value = y;
sheet->old_vadjustment = -1.;
- g_signal_emit_by_name (G_OBJECT (sheet->vadjustment),
+ g_signal_emit_by_name (sheet->vadjustment,
"value_changed");
}
/* adjust horizontal scrollbar */
- if (column >= 0 && col_align >= 0.)
+ if (column >= 0 && col_align >= 0.0)
{
x = COLUMN_LEFT_XPIXEL (sheet, column) - sheet->hoffset
- - (gint) ( col_align*width + (1.- col_align)*
+ - (gint) ( col_align*width + (1.0 - col_align)*
xxx_column_width (sheet, column));
-
/* This forces the sheet to scroll when you don't see the entire cell */
min_col = column;
adjust = 0;
- if (col_align == 1.)
+ if (col_align == 1.0)
{
while (min_col >= 0 && min_col > MIN_VISIBLE_COLUMN (sheet))
{
sheet->hadjustment->value = x;
sheet->old_vadjustment = -1.;
- g_signal_emit_by_name (G_OBJECT (sheet->hadjustment),
+ g_signal_emit_by_name (sheet->hadjustment,
"value_changed");
-
}
}
if (sheet->state != GTK_SHEET_NORMAL)
gtk_sheet_real_unselect_range (sheet, NULL);
else
- {
- gboolean veto = TRUE;
- veto = gtk_sheet_deactivate_cell (sheet);
- if (!veto) return;
- }
+ gtk_sheet_deactivate_cell (sheet);
sheet->state = GTK_SHEET_ROW_SELECTED;
sheet->range.row0 = row;
sheet->active_cell.row = row;
sheet->active_cell.col = 0;
- g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_ROW], 0, row);
+ g_signal_emit (sheet, sheet_signals[SELECT_ROW], 0, row);
gtk_sheet_real_select_range (sheet, NULL);
}
if (sheet->state != GTK_SHEET_NORMAL)
gtk_sheet_real_unselect_range (sheet, NULL);
else
- {
- gboolean veto = TRUE;
- veto = gtk_sheet_deactivate_cell (sheet);
- if (!veto) return;
- }
+ gtk_sheet_deactivate_cell (sheet);
+
sheet->state = GTK_SHEET_COLUMN_SELECTED;
sheet->range.row0 = 0;
sheet->active_cell.row = 0;
sheet->active_cell.col = column;
- g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_COLUMN], 0, column);
+ g_signal_emit (sheet, sheet_signals[SELECT_COLUMN], 0, column);
gtk_sheet_real_select_range (sheet, NULL);
}
if (sheet->vadjustment)
{
- g_signal_handlers_disconnect_matched (G_OBJECT (sheet->vadjustment),
+ g_signal_handlers_disconnect_matched (sheet->vadjustment,
G_SIGNAL_MATCH_DATA,
0, 0, 0, 0,
sheet);
- g_object_unref (G_OBJECT (sheet->vadjustment));
+ g_object_unref (sheet->vadjustment);
}
sheet->vadjustment = adjustment;
if (sheet->vadjustment)
{
- g_object_ref (G_OBJECT (sheet->vadjustment));
- g_object_ref_sink (G_OBJECT (sheet->vadjustment));
+ g_object_ref (sheet->vadjustment);
+ g_object_ref_sink (sheet->vadjustment);
- g_signal_connect (G_OBJECT (sheet->vadjustment), "value_changed",
+ g_signal_connect (sheet->vadjustment, "value_changed",
G_CALLBACK (vadjustment_value_changed),
sheet);
}
if (sheet->hadjustment)
{
- g_signal_handlers_disconnect_matched (G_OBJECT (sheet->hadjustment),
+ g_signal_handlers_disconnect_matched (sheet->hadjustment,
G_SIGNAL_MATCH_DATA,
0, 0, 0, 0,
sheet);
- g_object_unref (G_OBJECT (sheet->hadjustment));
+ g_object_unref (sheet->hadjustment);
}
sheet->hadjustment = adjustment;
if (sheet->hadjustment)
{
- g_object_ref (G_OBJECT (sheet->hadjustment));
- g_object_ref_sink (G_OBJECT (sheet->hadjustment));
+ g_object_ref (sheet->hadjustment);
+ g_object_ref_sink (sheet->hadjustment);
- g_signal_connect (G_OBJECT (sheet->hadjustment), "value_changed",
+ g_signal_connect (sheet->hadjustment, "value_changed",
G_CALLBACK (hadjustment_value_changed),
sheet);
}
sheet = GTK_SHEET (object);
- if (sheet->name)
- {
- g_free (sheet->name);
- sheet->name = NULL;
- }
-
if (G_OBJECT_CLASS (parent_class)->finalize)
(*G_OBJECT_CLASS (parent_class)->finalize) (object);
}
static void
-gtk_sheet_destroy (GtkObject * object)
+gtk_sheet_dispose (GObject * object)
{
- GtkSheet *sheet;
+ GtkSheet *sheet = GTK_SHEET (object);
GList *children;
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_SHEET (object));
- sheet = GTK_SHEET (object);
+ if ( sheet->dispose_has_run )
+ return ;
- /* destroy the entry */
- if (sheet->sheet_entry && GTK_IS_WIDGET (sheet->sheet_entry))
- {
- gtk_widget_destroy (sheet->sheet_entry);
- sheet->sheet_entry = NULL;
- }
+ if (sheet->model) g_object_unref (sheet->model);
+ sheet->dispose_has_run = TRUE;
- /* destroy the global selection button */
- if (sheet->button && GTK_IS_WIDGET (sheet->button))
- {
- gtk_widget_destroy (sheet->button);
- sheet->button = NULL;
- }
+ g_object_unref (sheet->entry_container);
+ g_object_unref (sheet->button);
/* unref adjustments */
if (sheet->hadjustment)
{
- g_signal_handlers_disconnect_matched (G_OBJECT (sheet->hadjustment),
+ g_signal_handlers_disconnect_matched (sheet->hadjustment,
G_SIGNAL_MATCH_DATA,
0, 0, 0, 0,
sheet);
- g_object_unref (G_OBJECT (sheet->hadjustment));
+ g_object_unref (sheet->hadjustment);
sheet->hadjustment = NULL;
}
if (sheet->vadjustment)
{
- g_signal_handlers_disconnect_matched (G_OBJECT (sheet->vadjustment),
+ g_signal_handlers_disconnect_matched (sheet->vadjustment,
G_SIGNAL_MATCH_DATA,
0, 0, 0, 0,
sheet);
- g_object_unref (G_OBJECT (sheet->vadjustment));
+ g_object_unref (sheet->vadjustment);
sheet->vadjustment = NULL;
}
}
sheet->children = NULL;
- if (GTK_OBJECT_CLASS (parent_class)->destroy)
- (*GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+ if (G_OBJECT_CLASS (parent_class)->dispose)
+ (*G_OBJECT_CLASS (parent_class)->dispose) (object);
}
static void
gint attributes_mask;
GdkGCValues values, auxvalues;
GdkColormap *colormap;
- gchar *name;
GtkSheetChild *child;
GList *children;
GDK_GC_FUNCTION |
GDK_GC_SUBWINDOW);
- if (sheet->sheet_entry->parent)
- {
- gtk_widget_ref (sheet->sheet_entry);
- gtk_widget_unparent (sheet->sheet_entry);
- }
- gtk_widget_set_parent_window (sheet->sheet_entry, sheet->sheet_window);
- gtk_widget_set_parent (sheet->sheet_entry, GTK_WIDGET (sheet));
+ gtk_widget_set_parent_window (sheet->entry_widget, sheet->sheet_window);
+ gtk_widget_set_parent (sheet->entry_widget, GTK_WIDGET (sheet));
- if (sheet->button && sheet->button->parent)
- {
- gtk_widget_ref (sheet->button);
- gtk_widget_unparent (sheet->button);
- }
gtk_widget_set_parent_window (sheet->button, sheet->sheet_window);
gtk_widget_set_parent (sheet->button, GTK_WIDGET (sheet));
size_allocate_row_title_buttons (sheet);
size_allocate_column_title_buttons (sheet);
- name = g_strdup (sheet->name);
- gtk_sheet_set_title (sheet, name);
-
- g_free (name);
-
children = sheet->children;
while (children)
{
{
sheet->button = gtk_button_new_with_label (" ");
- g_signal_connect (G_OBJECT (sheet->button),
+ g_object_ref_sink (sheet->button);
+
+ g_signal_connect (sheet->button,
"pressed",
G_CALLBACK (global_button_clicked),
sheet);
static void
gtk_sheet_map (GtkWidget * widget)
{
- GtkSheet *sheet;
+ GtkSheet *sheet = GTK_SHEET (widget);
GtkSheetChild *child;
GList *children;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_SHEET (widget));
- sheet = GTK_SHEET (widget);
-
if (!GTK_WIDGET_MAPPED (widget))
{
GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
gdk_window_show (sheet->row_title_window);
}
- if (!GTK_WIDGET_MAPPED (sheet->sheet_entry)
- && ! gtk_sheet_locked (sheet)
+ if (!GTK_WIDGET_MAPPED (sheet->entry_widget)
&& sheet->active_cell.row >= 0
&& sheet->active_cell.col >= 0 )
{
- gtk_widget_show (sheet->sheet_entry);
- gtk_widget_map (sheet->sheet_entry);
+ gtk_widget_show (sheet->entry_widget);
+ gtk_widget_map (sheet->entry_widget);
}
if (GTK_WIDGET_VISIBLE (sheet->button) &&
gdk_window_hide (sheet->row_title_window);
gdk_window_hide (widget->window);
- if (GTK_WIDGET_MAPPED (sheet->sheet_entry))
- gtk_widget_unmap (sheet->sheet_entry);
+ if (GTK_WIDGET_MAPPED (sheet->entry_widget))
+ gtk_widget_unmap (sheet->entry_widget);
if (GTK_WIDGET_MAPPED (sheet->button))
gtk_widget_unmap (sheet->button);
case GTK_JUSTIFY_RIGHT:
size = area.width;
area.x +=area.width;
- {
- for (i = col - 1; i >= MIN_VISIBLE_COLUMN (sheet); i--)
- {
- 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,
- MAX (col,
- xxx_column_right_column (sheet, i)));
- }
- area.width = size;
- }
+ {
+ for (i = col - 1; i >= MIN_VISIBLE_COLUMN (sheet); i--)
+ {
+ 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,
+ MAX (col,
+ xxx_column_right_column (sheet, i)));
+ }
+ area.width = size;
+ }
area.x -= size;
xoffset += area.width - text_width - 2 * CELLOFFSET -
attributes.border.width / 2;
sizel = area.width / 2;
sizer = area.width / 2;
area.x += area.width / 2;
- {
- for (i = col + 1; i <= MAX_VISIBLE_COLUMN (sheet); i++)
- {
- 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,
- MIN (
- col,
- xxx_column_left_column (sheet, i)));
- }
- for (i = col - 1; i >= MIN_VISIBLE_COLUMN (sheet); i--)
- {
- 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,
- MAX (col,
- xxx_column_right_column (sheet, i)));
- }
- size = MIN (sizel, sizer);
- }
+ {
+ for (i = col + 1; i <= MAX_VISIBLE_COLUMN (sheet); i++)
+ {
+ 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,
+ MIN (
+ col,
+ xxx_column_left_column (sheet, i)));
+ }
+ for (i = col - 1; i >= MIN_VISIBLE_COLUMN (sheet); i--)
+ {
+ 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,
+ MAX (col,
+ xxx_column_right_column (sheet, i)));
+ }
+ size = MIN (sizel, sizer);
+ }
area.x -= sizel;
xoffset += sizel - text_width / 2 - CELLOFFSET;
area.width = sizel + sizer;
case GTK_JUSTIFY_LEFT:
default:
size = area.width;
- {
- for (i = col + 1; i <= MAX_VISIBLE_COLUMN (sheet); i++)
- {
- 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,
- MIN (
- col,
- xxx_column_left_column (sheet, i)));
-
- }
- area.width = size;
- }
+ {
+ for (i = col + 1; i <= MAX_VISIBLE_COLUMN (sheet); i++)
+ {
+ 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,
+ MIN (
+ col,
+ xxx_column_left_column (sheet, i)));
+
+ }
+ area.width = size;
+ }
xoffset += attributes.border.width / 2;
break;
}
layout);
gdk_gc_set_clip_rectangle (fg_gc, NULL);
- g_object_unref (G_OBJECT (layout));
+ g_object_unref (layout);
gdk_draw_pixmap (sheet->sheet_window,
GTK_WIDGET (sheet)->style->fg_gc[GTK_STATE_NORMAL],
}
if ( changed )
- g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, row, col);
+ g_signal_emit (sheet, sheet_signals[CHANGED], 0, row, col);
}
if (old_text && strlen (old_text) > 0 )
{
g_sheet_model_datum_clear (model, row, column);
-
- if (GTK_IS_OBJECT (sheet) && G_OBJECT (sheet)->ref_count > 0)
- g_signal_emit (G_OBJECT (sheet), sheet_signals[CLEAR_CELL], 0,
- row, column);
}
dispose_string (sheet, old_text);
return FALSE;
if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
- {
- if (!gtk_sheet_deactivate_cell (sheet)) return FALSE;
- }
+ gtk_sheet_deactivate_cell (sheet);
sheet->active_cell.row = row;
sheet->active_cell.col = column;
if (row < 0 || col < 0) return;
- sheet->active_cell.row =- 1;
- sheet->active_cell.col =- 1;
+ sheet->active_cell.row = -1;
+ sheet->active_cell.col = -1;
text = gtk_entry_get_text (GTK_ENTRY (gtk_sheet_get_entry (sheet)));
}
-static gboolean
+static void
gtk_sheet_deactivate_cell (GtkSheet *sheet)
{
- gboolean veto = TRUE;
+ g_return_if_fail (sheet != NULL);
+ g_return_if_fail (GTK_IS_SHEET (sheet));
- g_return_val_if_fail (sheet != NULL, FALSE);
- g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
+ if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return ;
+ if (sheet->state != GTK_SHEET_NORMAL) return ;
- if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return FALSE;
- if (sheet->state != GTK_SHEET_NORMAL) return FALSE;
+ if ( sheet->active_cell.row == -1 || sheet->active_cell.col == -1 )
+ return ;
- _gtkextra_signal_emit (GTK_OBJECT (sheet), sheet_signals[DEACTIVATE],
- sheet->active_cell.row,
- sheet->active_cell.col, &veto);
+ g_signal_emit (sheet, sheet_signals[DEACTIVATE], 0,
+ sheet->active_cell.row,
+ sheet->active_cell.col);
- if (!veto) return FALSE;
- if ( sheet->active_cell.row == -1 || sheet->active_cell.col == -1 )
- return TRUE;
-
- g_signal_handlers_disconnect_by_func (G_OBJECT (gtk_sheet_get_entry (sheet)),
+ g_signal_handlers_disconnect_by_func (gtk_sheet_get_entry (sheet),
G_CALLBACK (gtk_sheet_entry_changed),
sheet);
GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_REDRAW_PENDING);
gtk_sheet_range_draw (sheet, NULL);
}
-
- return TRUE;
}
static void
gtk_sheet_get_attributes (sheet, row, col, &attributes);
justification = attributes.justification;
- if (text && strlen (text) != 0)
- {
- gtk_sheet_set_cell (sheet, row, col, justification, text);
- g_signal_emit (G_OBJECT (sheet), sheet_signals[SET_CELL], 0, row, col);
- }
- else
- {
- gtk_sheet_cell_clear (sheet, row, col);
- }
-
row = sheet->active_cell.row;
col = sheet->active_cell.col;
- gtk_widget_hide (sheet->sheet_entry);
- gtk_widget_unmap (sheet->sheet_entry);
+ gtk_widget_hide (sheet->entry_widget);
+ gtk_widget_unmap (sheet->entry_widget);
if (row != -1 && col != -1)
gdk_draw_pixmap (sheet->sheet_window,
gtk_widget_grab_focus (GTK_WIDGET (sheet));
- GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (sheet->sheet_entry), GTK_VISIBLE);
+ GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (sheet->entry_widget), GTK_VISIBLE);
}
g_return_val_if_fail (GTK_IS_SHEET (sheet), FALSE);
if (row < 0 || col < 0) return FALSE;
- if (row >= yyy_row_count (sheet) || col >= xxx_column_count (sheet))
+
+ if ( row > yyy_row_count (sheet) || col > xxx_column_count (sheet))
return FALSE;
if (!veto) return FALSE;
gtk_sheet_show_active_cell (sheet);
-
- g_signal_connect (G_OBJECT (gtk_sheet_get_entry (sheet)),
+ g_signal_connect (gtk_sheet_get_entry (sheet),
"changed",
G_CALLBACK (gtk_sheet_entry_changed),
sheet);
if (sheet->state != GTK_SHEET_NORMAL) return;
if (GTK_SHEET_IN_SELECTION (sheet)) return;
- GTK_WIDGET_SET_FLAGS (GTK_WIDGET (sheet->sheet_entry), GTK_VISIBLE);
+ GTK_WIDGET_SET_FLAGS (GTK_WIDGET (sheet->entry_widget), GTK_VISIBLE);
sheet_entry = GTK_ENTRY (gtk_sheet_get_entry (sheet));
gtk_entry_set_visibility (GTK_ENTRY (sheet_entry), attributes.is_visible);
- if (gtk_sheet_locked (sheet) || !attributes.is_editable)
- gtk_editable_set_editable (GTK_EDITABLE (sheet_entry), FALSE);
- else
- gtk_editable_set_editable (GTK_EDITABLE (sheet_entry), TRUE);
/*** Added by John Gotts. Mar 25, 2005 *********/
old_text = gtk_entry_get_text (GTK_ENTRY (sheet_entry));
gtk_sheet_entry_set_max_size (sheet);
gtk_sheet_size_allocate_entry (sheet);
- gtk_widget_map (sheet->sheet_entry);
+ gtk_widget_map (sheet->entry_widget);
gtk_widget_grab_focus (GTK_WIDGET (sheet_entry));
gdk_gc_set_clip_rectangle (sheet->xor_gc, &area);
- for (i =- 1; i <= 1; ++i)
+ for (i = -1; i <= 1; ++i)
gdk_draw_rectangle (sheet->sheet_window,
sheet->xor_gc,
FALSE,
gtk_sheet_update_primary_selection (sheet);
- g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_RANGE], 0, &sheet->range);
+ g_signal_emit (sheet, sheet_signals[SELECT_RANGE], 0, &sheet->range);
}
if (range->col0 < 0 || range->coli < 0) return;
- if ( gtk_sheet_locked (sheet)) return ;
-
if (sheet->state != GTK_SHEET_NORMAL)
gtk_sheet_real_unselect_range (sheet, NULL);
else
- {
- gboolean veto = TRUE;
- veto = gtk_sheet_deactivate_cell (sheet);
- if (!veto) return;
- }
+ gtk_sheet_deactivate_cell (sheet);
sheet->range.row0 = range->row0;
sheet->range.rowi = range->rowi;
void
gtk_sheet_unselect_range (GtkSheet * sheet)
{
+ if (! GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
+ return;
+
gtk_sheet_real_unselect_range (sheet, NULL);
sheet->state = GTK_STATE_NORMAL;
if (range->row0 < 0 || range->rowi < 0) return;
if (range->col0 < 0 || range->coli < 0) return;
- g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_COLUMN], 0, -1);
- g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_ROW], 0, -1);
+ g_signal_emit (sheet, sheet_signals[SELECT_COLUMN], 0, -1);
+ g_signal_emit (sheet, sheet_signals[SELECT_ROW], 0, -1);
if (gtk_sheet_range_isvisible (sheet, *range))
gtk_sheet_draw_backing_pixmap (sheet, *range);
if ((!GTK_SHEET_IN_XDRAG (sheet)) && (!GTK_SHEET_IN_YDRAG (sheet)))
{
if (sheet->state == GTK_SHEET_NORMAL)
- {
- gtk_sheet_draw_active_cell (sheet);
- if (!GTK_SHEET_IN_SELECTION (sheet))
- gtk_widget_queue_draw (sheet->sheet_entry);
- }
+ gtk_sheet_draw_active_cell (sheet);
}
}
}
if (event->window == sheet->column_title_window)
{
- g_signal_emit (G_OBJECT (sheet),
+ g_signal_emit (sheet,
sheet_signals[BUTTON_EVENT_COLUMN], 0,
column, event);
if ( event->type == GDK_2BUTTON_PRESS && event->button == 1)
- g_signal_emit (G_OBJECT (sheet),
+ g_signal_emit (sheet,
sheet_signals[DOUBLE_CLICK_COLUMN], 0, column);
}
else if (event->window == sheet->row_title_window)
{
- g_signal_emit (G_OBJECT (sheet),
+ g_signal_emit (sheet,
sheet_signals[BUTTON_EVENT_ROW], 0,
row, event);
if ( event->type == GDK_2BUTTON_PRESS && event->button == 1)
- g_signal_emit (G_OBJECT (sheet),
+ g_signal_emit (sheet,
sheet_signals[DOUBLE_CLICK_ROW], 0, row);
}
{
row = sheet->active_cell.row;
column = sheet->active_cell.col;
- if (!gtk_sheet_deactivate_cell (sheet)) return FALSE;
+ gtk_sheet_deactivate_cell (sheet);
sheet->active_cell.row = row;
sheet->active_cell.col = column;
sheet->drag_range = sheet->range;
else if (sheet->cursor_drag->type == GDK_TOP_LEFT_ARROW &&
!GTK_SHEET_IN_SELECTION (sheet)
&& ! GTK_SHEET_IN_DRAG (sheet)
- && ! gtk_sheet_locked (sheet)
&& sheet->active_cell.row >= 0
&& sheet->active_cell.col >= 0
)
{
row = sheet->active_cell.row;
column = sheet->active_cell.col;
- if (!gtk_sheet_deactivate_cell (sheet)) return FALSE;
+ gtk_sheet_deactivate_cell (sheet);
sheet->active_cell.row = row;
sheet->active_cell.col = column;
sheet->drag_range = sheet->range;
return TRUE;
}
-#if 0
-static gint
-gtk_sheet_scroll (gpointer data)
-{
- GtkSheet *sheet;
- gint x, y, row, column;
- gint move;
-
- sheet = GTK_SHEET (data);
-
- GDK_THREADS_ENTER ();
-
- gtk_widget_get_pointer (GTK_WIDGET (sheet), &x, &y);
- gtk_sheet_get_pixel_info (sheet, x, y, &row, &column);
-
- move = TRUE;
-
- if (GTK_SHEET_IN_SELECTION (sheet))
- gtk_sheet_extend_selection (sheet, row, column);
-
- if (GTK_SHEET_IN_DRAG (sheet) || GTK_SHEET_IN_RESIZE (sheet))
- {
- move = gtk_sheet_move_query (sheet, row, column);
- if (move) draw_xor_rectangle (sheet, sheet->drag_range);
- }
-
- GDK_THREADS_LEAVE ();
-
- return TRUE;
-}
-#endif
-
static void
gtk_sheet_click_cell (GtkSheet *sheet, gint row, gint column, gboolean *veto)
{
}
else
{
- if (!gtk_sheet_deactivate_cell (sheet))
- {
- *veto = FALSE;
- return;
- }
+ gtk_sheet_deactivate_cell (sheet);
gtk_sheet_activate_cell (sheet, row, column);
}
gtk_sheet_set_column_width (sheet, sheet->drag_cell.col,
new_column_width (sheet, sheet->drag_cell.col, &x));
sheet->old_hadjustment = -1.;
- g_signal_emit_by_name (G_OBJECT (sheet->hadjustment), "value_changed");
+ g_signal_emit_by_name (sheet->hadjustment, "value_changed");
return TRUE;
}
gtk_sheet_set_row_height (sheet, sheet->drag_cell.row, new_row_height (sheet, sheet->drag_cell.row, &y));
sheet->old_vadjustment = -1.;
- g_signal_emit_by_name (G_OBJECT (sheet->vadjustment), "value_changed");
+ g_signal_emit_by_name (sheet->vadjustment, "value_changed");
return TRUE;
}
old_range = sheet->range;
sheet->range = sheet->drag_range;
sheet->drag_range = old_range;
- g_signal_emit (G_OBJECT (sheet), sheet_signals[MOVE_RANGE], 0,
+ g_signal_emit (sheet, sheet_signals[MOVE_RANGE], 0,
&sheet->drag_range, &sheet->range);
gtk_sheet_select_range (sheet, &sheet->range);
}
sheet->drag_range = old_range;
if (sheet->state == GTK_STATE_NORMAL) sheet->state = GTK_SHEET_RANGE_SELECTED;
- g_signal_emit (G_OBJECT (sheet), sheet_signals[RESIZE_RANGE], 0,
+ g_signal_emit (sheet, sheet_signals[RESIZE_RANGE], 0,
&sheet->drag_range, &sheet->range);
gtk_sheet_select_range (sheet, &sheet->range);
}
row_move = FALSE;
column_move = FALSE;
- row_align =- 1.;
- col_align =- 1.;
+ row_align = -1.;
+ col_align = -1.;
height = sheet->sheet_window_height;
width = sheet->sheet_window_width;
if (row >= MAX_VISIBLE_ROW (sheet) && sheet->state != GTK_SHEET_COLUMN_SELECTED)
{
row_align = 1.;
- new_row = MIN (yyy_row_count (sheet), row + 1);
+ new_row = MIN (yyy_row_count (sheet) - 1, row + 1);
row_move = TRUE;
if (MAX_VISIBLE_ROW (sheet) == yyy_row_count (sheet) - 1 &&
ROW_TOP_YPIXEL (sheet, yyy_row_count (sheet)- 1) +
GdkEventKey *key)
{
gboolean focus;
- g_signal_emit_by_name (G_OBJECT (widget), "key_press_event", key, &focus);
+ g_signal_emit_by_name (widget, "key_press_event", key, &focus);
return focus;
}
if (sheet->state == GTK_SHEET_NORMAL &&
!GTK_SHEET_IN_SELECTION (sheet))
g_signal_stop_emission_by_name (gtk_sheet_get_entry (sheet),
- "key-press-event");
+ "key-press-event");
row = sheet->active_cell.row;
col = sheet->active_cell.col;
if (sheet->state == GTK_SHEET_COLUMN_SELECTED)
break;
case GDK_Home:
row = 0;
- while (!yyy_row_is_visible (sheet, row) && row < yyy_row_count (sheet)- 1) row++;
+ while (!yyy_row_is_visible (sheet, row) && row < yyy_row_count (sheet) - 1) row++;
gtk_sheet_click_cell (sheet, row, sheet->active_cell.col, &veto);
extend_selection = FALSE;
break;
case GDK_End:
- row = yyy_row_count (sheet)- 1;
+ row = yyy_row_count (sheet) - 1;
while (!yyy_row_is_visible (sheet, row) && row > 0) row--;
gtk_sheet_click_cell (sheet, row, sheet->active_cell.col, &veto);
extend_selection = FALSE;
if (!GTK_WIDGET_DRAWABLE (sheet)) return;
+ size_allocate_global_button (sheet);
+
for (i = MIN_VISIBLE_COLUMN (sheet); i <= MAX_VISIBLE_COLUMN (sheet); i++)
gtk_sheet_column_title_button_draw (sheet, i);
}
if (!GTK_WIDGET_DRAWABLE (sheet)) return;
+ size_allocate_global_button (sheet);
+
for (i = MIN_VISIBLE_ROW (sheet); i <= MAX_VISIBLE_ROW (sheet); i++)
{
if ( i >= yyy_row_count (sheet))
&attributes) )
return ;
- if ( GTK_WIDGET_REALIZED (sheet->sheet_entry) )
+ if ( GTK_WIDGET_REALIZED (sheet->entry_widget) )
{
if (!GTK_WIDGET (sheet_entry)->style)
gtk_widget_ensure_style (GTK_WIDGET (sheet_entry));
style->font_desc = pango_font_description_copy (attributes.font_desc);
GTK_WIDGET (sheet_entry)->style = style;
- gtk_widget_size_request (sheet->sheet_entry, NULL);
+ gtk_widget_size_request (sheet->entry_widget, NULL);
GTK_WIDGET (sheet_entry)->style = previous_style;
if (style != previous_style)
{
- if (!GTK_IS_ITEM_ENTRY (sheet->sheet_entry))
+ if (!GTK_IS_ITEM_ENTRY (sheet->entry_widget))
{
style->bg[GTK_STATE_NORMAL] = previous_style->bg[GTK_STATE_NORMAL];
style->fg[GTK_STATE_NORMAL] = previous_style->fg[GTK_STATE_NORMAL];
shentry_allocation.width = column_width;
shentry_allocation.height = yyy_row_height (sheet, sheet->active_cell.row);
- if (GTK_IS_ITEM_ENTRY (sheet->sheet_entry))
+ if (GTK_IS_ITEM_ENTRY (sheet->entry_widget))
{
shentry_allocation.height -= 2 * CELLOFFSET;
shentry_allocation.y += CELLOFFSET;
}
}
- if (!GTK_IS_ITEM_ENTRY (sheet->sheet_entry))
+ if (!GTK_IS_ITEM_ENTRY (sheet->entry_widget))
{
shentry_allocation.x += 2;
shentry_allocation.y += 2;
shentry_allocation.height -= MIN (shentry_allocation.height, 3);
}
- gtk_widget_size_allocate (sheet->sheet_entry, &shentry_allocation);
+ gtk_widget_size_allocate (sheet->entry_widget, &shentry_allocation);
if (previous_style == style) g_object_unref (previous_style);
}
row = sheet->active_cell.row;
col = sheet->active_cell.col;
- if ( ! GTK_IS_ITEM_ENTRY (sheet->sheet_entry) )
+ if ( ! GTK_IS_ITEM_ENTRY (sheet->entry_widget) )
return;
- justification = GTK_ITEM_ENTRY (sheet->sheet_entry)->justification;
+ justification = GTK_ITEM_ENTRY (sheet->entry_widget)->justification;
switch (justification)
{
if (size != 0)
size += xxx_column_width (sheet, col);
- GTK_ITEM_ENTRY (sheet->sheet_entry)->text_max_size = size;
+ GTK_ITEM_ENTRY (sheet->entry_widget)->text_max_size = size;
}
static void
create_sheet_entry (GtkSheet *sheet)
{
- GtkWidget *widget;
- GtkWidget *parent;
- GtkWidget *entry;
- gint found_entry = FALSE;
-
- widget = GTK_WIDGET (sheet);
-
- if (sheet->sheet_entry)
+ if (sheet->entry_widget)
{
- /* avoids warnings */
- gtk_widget_ref (sheet->sheet_entry);
- gtk_widget_unparent (sheet->sheet_entry);
- gtk_widget_destroy (sheet->sheet_entry);
+ gtk_widget_unparent (sheet->entry_widget);
}
if (sheet->entry_type)
{
- if (!g_type_is_a (sheet->entry_type, GTK_TYPE_ENTRY))
- {
- parent = g_object_new (sheet->entry_type, NULL);
+ sheet->entry_container = g_object_new (sheet->entry_type, NULL);
+ g_object_ref_sink (sheet->entry_container);
+ sheet->entry_widget = gtk_sheet_get_entry (sheet);
- sheet->sheet_entry = parent;
-
- entry = gtk_sheet_get_entry (sheet);
- if (GTK_IS_ENTRY (entry))
- found_entry = TRUE;
- }
- else
+ if ( NULL == sheet->entry_widget)
{
- parent = g_object_new (sheet->entry_type, NULL);
- entry = parent;
- found_entry = TRUE;
+ g_warning ("Entry type is %s. It must be GtkEntry subclass, or a widget containing one. "
+ "Using default", g_type_name (sheet->entry_type));
+ g_object_unref (sheet->entry_container);
+ sheet->entry_widget = sheet->entry_container = gtk_item_entry_new ();
}
-
- if (!found_entry)
+ else
{
- g_warning ("Entry type must be GtkEntry subclass, using default");
- entry = gtk_item_entry_new ();
- sheet->sheet_entry = entry;
+ sheet->entry_widget = sheet->entry_container ;
}
- else
- sheet->sheet_entry = parent;
}
else
{
- entry = gtk_item_entry_new ();
- sheet->sheet_entry = entry;
+ sheet->entry_widget = sheet->entry_container = gtk_item_entry_new ();
+ g_object_ref_sink (sheet->entry_container);
}
- gtk_widget_size_request (sheet->sheet_entry, NULL);
+ gtk_widget_size_request (sheet->entry_widget, NULL);
if (GTK_WIDGET_REALIZED (sheet))
{
- gtk_widget_set_parent_window (sheet->sheet_entry, sheet->sheet_window);
- gtk_widget_set_parent (sheet->sheet_entry, GTK_WIDGET (sheet));
- gtk_widget_realize (sheet->sheet_entry);
+ gtk_widget_set_parent_window (sheet->entry_widget, sheet->sheet_window);
+ gtk_widget_set_parent (sheet->entry_widget, GTK_WIDGET (sheet));
+ gtk_widget_realize (sheet->entry_widget);
}
- g_signal_connect_swapped (G_OBJECT (entry), "key_press_event",
+ g_signal_connect_swapped (sheet->entry_widget, "key_press_event",
G_CALLBACK (gtk_sheet_entry_key_press),
sheet);
- gtk_widget_show (sheet->sheet_entry);
+ gtk_widget_show (sheet->entry_widget);
}
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
- g_return_val_if_fail (sheet->sheet_entry != NULL, NULL);
+ g_return_val_if_fail (sheet->entry_widget != NULL, NULL);
- if (GTK_IS_ENTRY (sheet->sheet_entry)) return (sheet->sheet_entry);
+ if (GTK_IS_ENTRY (sheet->entry_container))
+ return (sheet->entry_container);
- parent = GTK_WIDGET (sheet->sheet_entry);
+ //parent = GTK_WIDGET (sheet->entry_widget);
+ parent = sheet->entry_container;
if (GTK_IS_TABLE (parent)) children = GTK_TABLE (parent)->children;
if (GTK_IS_BOX (parent)) children = GTK_BOX (parent)->children;
{
g_return_val_if_fail (sheet != NULL, NULL);
g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
- g_return_val_if_fail (sheet->sheet_entry != NULL, NULL);
+ g_return_val_if_fail (sheet->entry_widget != NULL, NULL);
- return (sheet->sheet_entry);
+ return (sheet->entry_widget);
}
"label",
real_x, real_y,
layout);
- g_object_unref (G_OBJECT (layout));
+ g_object_unref (layout);
real_y += text_height + 2;
{
GdkWindow *window = NULL;
GdkRectangle allocation;
- GtkSheetButton *button = NULL;
+
gboolean is_sensitive = FALSE;
if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
}
else
{
- button = xxx_column_button (sheet, column);
+ GtkSheetButton *button = xxx_column_button (sheet, column);
allocation.x = COLUMN_LEFT_XPIXEL (sheet, column) + CELL_SPACING;
if (sheet->row_titles_visible)
allocation.x -= sheet->row_title_area.width;
is_sensitive = xxx_column_is_sensitive (sheet, column);
gtk_sheet_button_draw (sheet, window, button,
is_sensitive, allocation);
+
+ /* FIXME: Not freeing this button is correct (sort of),
+ because in PSPP the model always returns a static copy */
+
+ /* gtk_sheet_button_free (button); */
+
}
}
sheet->vadjustment->step_increment = DEFAULT_ROW_HEIGHT (GTK_WIDGET (sheet));
sheet->vadjustment->lower = 0;
sheet->vadjustment->upper = SHEET_HEIGHT (sheet) + 80;
- g_signal_emit_by_name (G_OBJECT (sheet->vadjustment), "changed");
+ g_signal_emit_by_name (sheet->vadjustment, "changed");
}
sheet->hadjustment->step_increment = DEFAULT_COLUMN_WIDTH;
sheet->hadjustment->lower = 0;
sheet->hadjustment->upper = SHEET_WIDTH (sheet)+ 80;
- g_signal_emit_by_name (G_OBJECT (sheet->hadjustment), "changed");
+ g_signal_emit_by_name (sheet->hadjustment, "changed");
}
}
sheet->voffset = - value;
- if (GTK_WIDGET_REALIZED (sheet->sheet_entry) &&
+ if (GTK_WIDGET_REALIZED (sheet->entry_widget) &&
sheet->state == GTK_SHEET_NORMAL &&
sheet->active_cell.row >= 0 && sheet->active_cell.col >= 0 &&
!gtk_sheet_cell_isvisible (sheet, sheet->active_cell.row,
gtk_sheet_cell_clear (sheet,
sheet->active_cell.row,
sheet->active_cell.col);
- gtk_widget_unmap (sheet->sheet_entry);
+ gtk_widget_unmap (sheet->entry_widget);
}
gtk_sheet_position_children (sheet);
}
sheet->hoffset = - value;
- if (GTK_WIDGET_REALIZED (sheet->sheet_entry) &&
+ if (GTK_WIDGET_REALIZED (sheet->entry_widget) &&
sheet->state == GTK_SHEET_NORMAL &&
sheet->active_cell.row >= 0 && sheet->active_cell.col >= 0 &&
!gtk_sheet_cell_isvisible (sheet, sheet->active_cell.row,
sheet->active_cell.row,
sheet->active_cell.col);
- gtk_widget_unmap (sheet->sheet_entry);
+ gtk_widget_unmap (sheet->entry_widget);
}
gtk_sheet_position_children (sheet);
gdk_gc_set_clip_rectangle (sheet->xor_gc, &clip_area);
- for (i =- 1; i <= 1; ++i)
+ for (i = -1; i <= 1; ++i)
gdk_draw_rectangle (sheet->sheet_window,
sheet->xor_gc,
FALSE,
gtk_sheet_range_draw (sheet, NULL);
}
- g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, -1, column);
- g_signal_emit (G_OBJECT (sheet), sheet_signals[NEW_COL_WIDTH], 0,
- column, width);
+ g_signal_emit (sheet, sheet_signals[CHANGED], 0, -1, column);
}
gtk_sheet_range_draw (sheet, NULL);
}
- g_signal_emit (G_OBJECT (sheet), sheet_signals[CHANGED], 0, row, - 1);
- g_signal_emit (G_OBJECT (sheet), sheet_signals[NEW_ROW_HEIGHT], 0,
- row, height);
-
+ g_signal_emit (sheet, sheet_signals[CHANGED], 0, row, - 1);
}
-
-
gboolean
gtk_sheet_get_attributes (const GtkSheet *sheet, gint row, gint col,
GtkSheetCellAttr *attributes)
{
GtkRequisition button_requisition;
GList *children;
+ GtkSheetButton *button = xxx_column_button (sheet, col);
gtk_sheet_button_size_request (sheet,
- xxx_column_button (sheet, col),
+ button,
&button_requisition);
+ gtk_sheet_button_free (button);
+
*requisition = button_requisition.width;
children = sheet->children;
(* callback) (child->widget, callback_data);
}
- if (sheet->button)
+
+ if (sheet->button && sheet->button->parent)
(* callback) (sheet->button, callback_data);
- if (sheet->sheet_entry)
- (* callback) (sheet->sheet_entry, callback_data);
+
+ if (sheet->entry_container && GTK_IS_CONTAINER (sheet->entry_container))
+ (* callback) (sheet->entry_container, callback_data);
}
g_free (child);
}
+ gtk_widget_unparent (sheet->button);
}
static void
g_string_append (string, "<html>\n");
g_string_append (string, "<body>\n");
g_string_append (string, "<table>\n");
- for (r = sheet->range.row0; r <= sheet->range.rowi; ++r)
+ for (r = sheet->range.row0; r <= sheet->range.rowi; ++r)
{
g_string_append (string, "<tr>\n");
for (c = sheet->range.col0; c <= sheet->range.coli; ++c)
GString *string = NULL;
switch (info)
- {
- case SELECT_FMT_TEXT:
- string = range_to_text (sheet);
- break;
- case SELECT_FMT_HTML:
- string = range_to_html (sheet);
- break;
- default:
- g_assert_not_reached ();
- }
+ {
+ case SELECT_FMT_TEXT:
+ string = range_to_text (sheet);
+ break;
+ case SELECT_FMT_HTML:
+ string = range_to_html (sheet);
+ break;
+ default:
+ g_assert_not_reached ();
+ }
gtk_selection_data_set (selection_data, selection_data->target,
8,
static const GtkTargetEntry targets[] = {
{ "UTF8_STRING", 0, SELECT_FMT_TEXT },
{ "STRING", 0, SELECT_FMT_TEXT },
- { "TEXT", 0, SELECT_FMT_TEXT },
+ { "TEXT", 0, SELECT_FMT_TEXT },
{ "COMPOUND_TEXT", 0, SELECT_FMT_TEXT },
- { "text/plain;charset=utf-8", 0, SELECT_FMT_TEXT },
+ { "text/plain;charset=utf-8", 0, SELECT_FMT_TEXT },
{ "text/plain", 0, SELECT_FMT_TEXT },
{ "text/html", 0, SELECT_FMT_HTML }
};
-
+
GtkClipboard *clipboard;
if (!GTK_WIDGET_REALIZED (sheet))
return;
- clipboard = gtk_widget_get_clipboard (GTK_WIDGET (sheet),
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (sheet),
GDK_SELECTION_PRIMARY);
-
+
if (gtk_sheet_range_isvisible (sheet, sheet->range))
{
- if (!gtk_clipboard_set_with_owner (clipboard, targets,
+ if (!gtk_clipboard_set_with_owner (clipboard, targets,
G_N_ELEMENTS (targets),
primary_get_cb, primary_clear_cb,
G_OBJECT (sheet)))