/* sheet flags */
enum
{
- GTK_SHEET_REDRAW_PENDING = 1 << 0,
GTK_SHEET_IN_XDRAG = 1 << 1,
GTK_SHEET_IN_YDRAG = 1 << 2,
GTK_SHEET_IN_DRAG = 1 << 3,
#define GTK_SHEET_IN_DRAG(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_DRAG)
#define GTK_SHEET_IN_SELECTION(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_SELECTION)
#define GTK_SHEET_IN_RESIZE(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_IN_RESIZE)
-#define GTK_SHEET_REDRAW_PENDING(sheet) (GTK_SHEET_FLAGS (sheet) & GTK_SHEET_REDRAW_PENDING)
#define CELL_SPACING 1
static void gtk_sheet_entry_changed (GtkWidget *widget,
gpointer data);
-static void deactivate_cell (GtkSheet *sheet);
static void gtk_sheet_hide_active_cell (GtkSheet *sheet);
static void activate_cell (GtkSheet *sheet,
gint row, gint col);
RESIZE_RANGE,
MOVE_RANGE,
TRAVERSE,
- DEACTIVATE,
ACTIVATE,
CHANGED,
LAST_SIGNAL
G_TYPE_POINTER, G_TYPE_POINTER);
- sheet_signals[DEACTIVATE] =
- g_signal_new ("deactivate",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- offsetof (GtkSheetClass, deactivate),
- NULL, NULL,
- gtkextra_VOID__INT_INT,
- G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
-
sheet_signals[ACTIVATE] =
g_signal_new ("activate",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
offsetof (GtkSheetClass, activate),
NULL, NULL,
- gtkextra_VOID__INT_INT,
- G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT);
+ gtkextra_VOID__INT_INT_INT_INT,
+ G_TYPE_NONE, 4,
+ G_TYPE_INT, G_TYPE_INT,
+ G_TYPE_INT, G_TYPE_INT);
sheet_signals[CHANGED] =
g_signal_new ("changed",
klass->resize_range = NULL;
klass->move_range = NULL;
klass->traverse = NULL;
- klass->deactivate = NULL;
klass->activate = NULL;
klass->changed = NULL;
}
if (text_width > g_sheet_column_get_width (sheet->column_geometry, column) )
{
gtk_sheet_set_column_width (sheet, column, text_width);
- GTK_SHEET_SET_FLAGS (sheet, GTK_SHEET_REDRAW_PENDING);
}
}
if (sheet->state != GTK_SHEET_NORMAL)
gtk_sheet_real_unselect_range (sheet, NULL);
- else
- deactivate_cell (sheet);
sheet->state = GTK_SHEET_ROW_SELECTED;
sheet->range.row0 = row;
if (sheet->state != GTK_SHEET_NORMAL)
gtk_sheet_real_unselect_range (sheet, NULL);
- else
- deactivate_cell (sheet);
-
sheet->state = GTK_SHEET_COLUMN_SELECTED;
sheet->range.row0 = 0;
if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
return;
- deactivate_cell (sheet);
-
if ( row == -1 || col == -1)
{
gtk_sheet_hide_active_cell (sheet);
}
-static void
-deactivate_cell (GtkSheet *sheet)
-{
- g_return_if_fail (sheet != NULL);
- g_return_if_fail (GTK_IS_SHEET (sheet));
-
- if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return ;
- if (sheet->state != GTK_SHEET_NORMAL) return ;
-
-
- if ( sheet->active_cell.row == -1 || sheet->active_cell.col == -1 )
- return ;
-
- /*
- g_print ("%s\n", __FUNCTION__);
-
-
- GtkSheetRange r;
- r.col0 = r.coli = sheet->active_cell.col;
- r.row0 = r.rowi = sheet->active_cell.row;
- gtk_sheet_range_draw (sheet, &r);
- */
-
-
- g_signal_emit (sheet, sheet_signals[DEACTIVATE], 0,
- sheet->active_cell.row,
- sheet->active_cell.col);
-
-
- g_signal_handlers_disconnect_by_func (gtk_sheet_get_entry (sheet),
- G_CALLBACK (gtk_sheet_entry_changed),
- sheet);
-
- gtk_sheet_hide_active_cell (sheet);
- sheet->active_cell.row = -1;
- sheet->active_cell.col = -1;
-
-#if 0
- if (GTK_SHEET_REDRAW_PENDING (sheet))
- {
- GTK_SHEET_UNSET_FLAGS (sheet, GTK_SHEET_REDRAW_PENDING);
- gtk_sheet_range_draw (sheet, NULL);
- }
-#endif
-}
-
-
-
static void
gtk_sheet_hide_active_cell (GtkSheet *sheet)
{
static void
activate_cell (GtkSheet *sheet, gint row, gint col)
{
+ gint old_row, old_col;
g_return_if_fail (sheet != NULL);
g_return_if_fail (GTK_IS_SHEET (sheet));
gtk_sheet_real_unselect_range (sheet, NULL);
}
+ old_row = sheet->active_cell.row;
+ old_col = sheet->active_cell.col;
+
sheet->range.row0 = row;
sheet->range.col0 = col;
sheet->range.rowi = row;
G_CALLBACK (gtk_sheet_entry_changed),
sheet);
- g_signal_emit (sheet, sheet_signals [ACTIVATE], 0, row, col);
+ g_signal_emit (sheet, sheet_signals [ACTIVATE], 0,
+ row, col, old_row, old_col);
}
static void
if (sheet->state != GTK_SHEET_NORMAL)
gtk_sheet_real_unselect_range (sheet, NULL);
- else
- deactivate_cell (sheet);
sheet->range.row0 = range->row0;
sheet->range.rowi = range->rowi;
{
row = sheet->active_cell.row;
column = sheet->active_cell.col;
- deactivate_cell (sheet);
sheet->active_cell.row = row;
sheet->active_cell.col = column;
sheet->drag_range = sheet->range;
{
row = sheet->active_cell.row;
column = sheet->active_cell.col;
- deactivate_cell (sheet);
sheet->active_cell.row = row;
sheet->active_cell.col = column;
sheet->drag_range = sheet->range;
}
else
{
- deactivate_cell (sheet);
activate_cell (sheet, row, column);
}
static void
-step_horizontal (GtkSheet *sheet, GtkScrollType dir)
+step_sheet (GtkSheet *sheet, GtkScrollType dir)
{
+ gint current_row = sheet->active_cell.row;
+ gint current_col = sheet->active_cell.col;
+ gint new_row = current_row;
+ gint new_col = current_col;
+ gboolean forbidden = FALSE;
+
switch ( dir)
{
+ case GTK_SCROLL_STEP_DOWN:
+ new_row++;
+ break;
+ case GTK_SCROLL_STEP_UP:
+ new_row--;
+ break;
case GTK_SCROLL_STEP_RIGHT:
-
- activate_cell (sheet,
- sheet->active_cell.row,
- sheet->active_cell.col + 1);
+ new_col++;
break;
case GTK_SCROLL_STEP_LEFT:
-
- activate_cell (sheet,
- sheet->active_cell.row,
- sheet->active_cell.col - 1);
+ new_col--;
break;
-
default:
g_assert_not_reached ();
break;
}
+ g_signal_emit (sheet, sheet_signals[TRAVERSE], 0,
+ current_row, current_col,
+ &new_row, &new_col, &forbidden);
+
+ if (forbidden)
+ return;
+
+ activate_cell (sheet, new_row, new_col);
+
if ( sheet->active_cell.col >= max_visible_column (sheet))
{
glong hpos =
}
}
+
static gboolean
gtk_sheet_key_press (GtkWidget *widget,
GdkEventKey *key)
{
case GDK_Tab:
case GDK_Right:
- step_horizontal (sheet, GTK_SCROLL_STEP_RIGHT);
+ step_sheet (sheet, GTK_SCROLL_STEP_RIGHT);
break;
case GDK_ISO_Left_Tab:
case GDK_Left:
- step_horizontal (sheet, GTK_SCROLL_STEP_LEFT);
+ step_sheet (sheet, GTK_SCROLL_STEP_LEFT);
break;
-
case GDK_Return:
case GDK_Down:
- activate_cell (sheet,
- sheet->active_cell.row + ROWS_PER_STEP,
- sheet->active_cell.col);
-
- if ( sheet->active_cell.row >= max_visible_row (sheet))
- gtk_adjustment_set_value (sheet->vadjustment,
- sheet->vadjustment->value +
- sheet->vadjustment->step_increment);
+ step_sheet (sheet, GTK_SCROLL_STEP_DOWN);
break;
case GDK_Up:
- activate_cell (sheet,
- sheet->active_cell.row - ROWS_PER_STEP,
- sheet->active_cell.col);
-
- if ( sheet->active_cell.row < min_visible_row (sheet))
- gtk_adjustment_set_value (sheet->vadjustment,
- sheet->vadjustment->value -
- sheet->vadjustment->step_increment);
+ step_sheet (sheet, GTK_SCROLL_STEP_UP);
break;
case GDK_Page_Down:
-
/* PSPPIRE - a graphical user interface for PSPP.
Copyright (C) 2008 Free Software Foundation, Inc.
static void psppire_var_sheet_class_init (PsppireVarSheetClass *klass);
static void psppire_var_sheet_init (PsppireVarSheet *vs);
-enum
+enum
{
PSPPIRE_VAR_SHEET_MAY_CREATE_VARS = 1
};
if (*new_row >= n_vars && !var_sheet->may_create_vars)
return TRUE;
+
if ( row == n_vars && *new_row >= n_vars)
{
GtkEntry *entry = GTK_ENTRY (gtk_sheet_get_entry (sheet));
return FALSE;
}
+
/* If the destination cell is outside the current variables, then
automatically create variables for the new rows.
*/
psppire_dict_insert_variable (var_store->dict, i, NULL);
}
+
+
return FALSE;
}
-/*
- Callback whenever the pointer leaves a cell on the var sheet.
-*/
-static gboolean
-var_sheet_cell_entry_leave (GtkSheet * sheet, gint row, gint column,
- gpointer data)
-{
- gtk_sheet_change_entry (sheet, GTK_TYPE_ENTRY);
- return TRUE;
-}
-
/*
- Callback whenever the pointer enters a cell on the var sheet.
+ Callback whenever the active cell changes on the var sheet.
*/
-static gboolean
-var_sheet_cell_entry_enter (PsppireVarSheet *vs, gint row, gint column,
- gpointer data)
+static void
+var_sheet_change_active_cell (PsppireVarSheet *vs,
+ gint row, gint column,
+ gint oldrow, gint oldcolumn,
+ gpointer data)
{
GtkSheetCellAttr attributes;
- PsppireVarStore *var_store ;
+ PsppireVarStore *var_store;
PsppireVarSheetClass *vs_class =
PSPPIRE_VAR_SHEET_CLASS(G_OBJECT_GET_CLASS (vs));
struct variable *var ;
GtkSheet *sheet = GTK_SHEET (vs);
- g_return_val_if_fail (sheet != NULL, FALSE);
+ g_return_if_fail (sheet != NULL);
var_store = PSPPIRE_VAR_STORE (gtk_sheet_get_model (sheet));
g_assert (var_store);
- if ( row >= psppire_var_store_get_var_cnt (var_store))
- return TRUE;
+ g_return_if_fail (oldcolumn == PSPPIRE_VAR_STORE_COL_NAME ||
+ row < psppire_var_store_get_var_cnt (var_store));
gtk_sheet_get_attributes (sheet, row, column, &attributes);
-
var = psppire_var_store_get_var (var_store, row);
switch (column)
gtk_sheet_change_entry (sheet, GTK_TYPE_ENTRY);
break;
}
-
-
- return TRUE;
}
g_object_set (vs, "column-geometry", geo, NULL);
-
g_signal_connect (vs, "activate",
- G_CALLBACK (var_sheet_cell_entry_enter),
- NULL);
-
- g_signal_connect (vs, "deactivate",
- G_CALLBACK (var_sheet_cell_entry_leave),
+ G_CALLBACK (var_sheet_change_active_cell),
NULL);
g_signal_connect (vs, "traverse",