1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008, 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #include <gtk/gtksignal.h>
20 #include <gtk-contrib/gtkextra-sheet.h>
21 #include "psppire-data-editor.h"
22 #include "psppire-var-sheet.h"
24 #include <language/syntax-string-source.h>
25 #include "psppire-data-store.h"
26 #include <libpspp/i18n.h>
27 #include <ui/gui/sheet/psppire-axis.h>
30 #include <gtk-contrib/gtkxpaned.h>
32 #define _(msgid) gettext (msgid)
33 #define N_(msgid) msgid
36 static void psppire_data_editor_remove_split (PsppireDataEditor *de);
37 static void psppire_data_editor_set_split (PsppireDataEditor *de);
40 DATA_SELECTION_CHANGED,
41 DATA_AVAILABLE_CHANGED,
48 static guint data_editor_signals [n_SIGNALS] = { 0 };
51 static gboolean data_is_selected (PsppireDataEditor *de);
53 static void psppire_data_editor_class_init (PsppireDataEditorClass *klass);
54 static void psppire_data_editor_init (PsppireDataEditor *de);
57 psppire_data_editor_get_type (void)
59 static GType de_type = 0;
63 static const GTypeInfo de_info =
65 sizeof (PsppireDataEditorClass),
67 NULL, /* base_finalize */
68 (GClassInitFunc) psppire_data_editor_class_init,
69 NULL, /* class_finalize */
70 NULL, /* class_data */
71 sizeof (PsppireDataEditor),
73 (GInstanceInitFunc) psppire_data_editor_init,
76 de_type = g_type_register_static (GTK_TYPE_NOTEBOOK, "PsppireDataEditor",
83 static GObjectClass * parent_class = NULL;
86 psppire_data_editor_dispose (GObject *obj)
88 PsppireDataEditor *de = (PsppireDataEditor *) obj;
90 if (de->dispose_has_run)
93 g_object_unref (de->data_store);
94 g_object_unref (de->var_store);
96 /* Make sure dispose does not run twice. */
97 de->dispose_has_run = TRUE;
99 /* Chain up to the parent class */
100 G_OBJECT_CLASS (parent_class)->dispose (obj);
104 psppire_data_editor_finalize (GObject *obj)
106 /* Chain up to the parent class */
107 G_OBJECT_CLASS (parent_class)->finalize (obj);
112 static void popup_variable_column_menu (PsppireSheet *sheet, gint column,
113 GdkEventButton *event, gpointer data);
115 static void popup_variable_row_menu (PsppireSheet *sheet, gint row,
116 GdkEventButton *event, gpointer data);
119 static void popup_cases_menu (PsppireSheet *sheet, gint row,
120 GdkEventButton *event, gpointer data);
126 /* Callback which occurs when the data sheet's column title
129 on_data_column_clicked (PsppireDataEditor *de, gint col, gpointer data)
131 PsppireSheetRange visible_range;
132 gint current_row, current_column;
134 gtk_notebook_set_current_page (GTK_NOTEBOOK (de),
135 PSPPIRE_DATA_EDITOR_VARIABLE_VIEW);
137 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->var_sheet),
138 ¤t_row, ¤t_column);
140 psppire_sheet_set_active_cell (PSPPIRE_SHEET (de->var_sheet), col, current_column);
143 psppire_sheet_get_visible_range (PSPPIRE_SHEET (de->var_sheet), &visible_range);
145 if ( col < visible_range.row0 || col > visible_range.rowi)
146 psppire_sheet_moveto (PSPPIRE_SHEET (de->var_sheet), col, current_column, 0.5, 0.5);
153 /* Callback which occurs when the var sheet's row title
154 button is double clicked */
156 on_var_row_clicked (PsppireDataEditor *de, gint row, gpointer data)
158 PsppireSheetRange visible_range;
160 gint current_row, current_column;
162 gtk_notebook_set_current_page (GTK_NOTEBOOK(de), PSPPIRE_DATA_EDITOR_DATA_VIEW);
164 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]),
165 ¤t_row, ¤t_column);
167 psppire_sheet_set_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), current_row, row);
169 psppire_sheet_get_visible_range (PSPPIRE_SHEET (de->data_sheet[0]), &visible_range);
171 if ( row < visible_range.col0 || row > visible_range.coli)
172 psppire_sheet_moveto (PSPPIRE_SHEET (de->data_sheet[0]), -1, row, 0.5, 0.5);
178 /* Moves the focus to a new cell.
179 Returns TRUE iff the move should be disallowed */
181 traverse_cell_callback (PsppireSheet *sheet,
182 PsppireSheetCell *existing_cell,
183 PsppireSheetCell *new_cell,
186 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
187 const PsppireDict *dict = de->data_store->dict;
189 if ( new_cell->col >= psppire_dict_get_var_cnt (dict))
212 #define DEFAULT_ROW_HEIGHT 25
215 new_data_callback (PsppireDataStore *ds, gpointer data)
218 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
220 casenumber n_cases = psppire_data_store_get_case_count (ds);
222 for (i = 0; i < 2; ++i)
224 psppire_axis_clear (de->vaxis[i]);
225 psppire_axis_append_n (de->vaxis[i], n_cases, DEFAULT_ROW_HEIGHT);
230 case_inserted_callback (PsppireDataStore *ds, gint before, gpointer data)
233 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
235 for (i = 0; i < 2; ++i)
236 psppire_axis_insert (de->vaxis[i], before, DEFAULT_ROW_HEIGHT);
241 cases_deleted_callback (PsppireDataStore *ds, gint first, gint n_cases, gpointer data)
244 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
246 for (i = 0; i < 2; ++i)
247 psppire_axis_delete (de->vaxis[0], first, n_cases);
252 /* Return the width (in pixels) of an upper case M when rendered in the
256 width_of_m (GtkWidget *w)
259 PangoLayout *layout = gtk_widget_create_pango_layout (w, "M");
261 pango_layout_get_pixel_extents (layout, NULL, &rect);
263 g_object_unref (layout);
268 /* Callback for the axis' resize signal.
269 Changes the variable's display width */
271 rewidth_variable (GtkWidget *w, gint unit, glong size)
273 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (w);
275 const PsppireDict *dict = de->data_store->dict;
276 struct variable *var = psppire_dict_get_variable (dict, unit);
281 var_set_display_width (var, size / (float) width_of_m (w));
286 new_variables_callback (PsppireDict *dict, gpointer data)
289 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
290 gint m_width = width_of_m (GTK_WIDGET (de));
293 g_object_get (de->var_sheet, "vertical-axis", &vaxis, NULL);
295 psppire_axis_clear (vaxis);
296 psppire_axis_append_n (vaxis, 1 + psppire_dict_get_var_cnt (dict), DEFAULT_ROW_HEIGHT);
298 g_signal_connect_swapped (de->haxis, "resize-unit",
299 G_CALLBACK (rewidth_variable), de);
301 psppire_axis_clear (de->haxis);
303 for (v = 0 ; v < psppire_dict_get_var_cnt (dict); ++v)
305 const struct variable *var = psppire_dict_get_variable (dict, v);
307 psppire_axis_append (de->haxis, m_width * var_get_display_width (var));
312 insert_variable_callback (PsppireDict *dict, gint x, gpointer data)
314 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
316 gint m_width = width_of_m (GTK_WIDGET (de));
318 PsppireAxis *var_vaxis;
320 const struct variable *var = psppire_dict_get_variable (dict, x);
322 g_object_get (de->var_sheet, "vertical-axis", &var_vaxis, NULL);
324 psppire_axis_insert (var_vaxis, x, DEFAULT_ROW_HEIGHT);
327 psppire_axis_insert (de->haxis, x, m_width * var_get_display_width (var));
332 delete_variable_callback (PsppireDict *dict, gint posn,
333 gint x UNUSED, gint y UNUSED, gpointer data)
335 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
337 PsppireAxis *var_vaxis;
338 g_object_get (de->var_sheet, "vertical-axis", &var_vaxis, NULL);
340 psppire_axis_delete (var_vaxis, posn, 1);
342 psppire_axis_delete (de->haxis, posn, 1);
347 rewidth_variable_callback (PsppireDict *dict, gint posn, gpointer data)
349 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
350 gint m_width = width_of_m (GTK_WIDGET (de));
352 const struct variable *var = psppire_dict_get_variable (dict, posn);
354 gint var_width = var_get_display_width (var);
356 /* Don't allow zero width */
360 psppire_axis_resize (de->haxis, posn, m_width * var_width);
365 psppire_data_editor_set_property (GObject *object,
371 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (object);
375 case PROP_SPLIT_WINDOW:
376 psppire_data_editor_split_window (de, g_value_get_boolean (value));
378 case PROP_DATA_STORE:
379 if ( de->data_store) g_object_unref (de->data_store);
380 de->data_store = g_value_get_pointer (value);
381 g_object_ref (de->data_store);
383 for (i = 0 ; i < 4 ; ++i )
385 g_object_set (de->data_sheet[i],
386 "model", de->data_store,
389 g_signal_connect_swapped (de->data_store->dict, "filter-changed",
390 G_CALLBACK (gtk_widget_queue_draw),
394 g_signal_connect (de->data_store->dict, "backend-changed",
395 G_CALLBACK (new_variables_callback), de);
397 g_signal_connect (de->data_store->dict, "variable-inserted",
398 G_CALLBACK (insert_variable_callback), de);
400 g_signal_connect (de->data_store->dict, "variable-deleted",
401 G_CALLBACK (delete_variable_callback), de);
403 g_signal_connect (de->data_store->dict, "variable-display-width-changed",
404 G_CALLBACK (rewidth_variable_callback), de);
406 g_signal_connect (de->data_store, "backend-changed",
407 G_CALLBACK (new_data_callback), de);
409 g_signal_connect (de->data_store, "case-inserted",
410 G_CALLBACK (case_inserted_callback), de);
412 g_signal_connect (de->data_store, "cases-deleted",
413 G_CALLBACK (cases_deleted_callback), de);
417 if ( de->var_store) g_object_unref (de->var_store);
418 de->var_store = g_value_get_pointer (value);
419 g_object_ref (de->var_store);
421 g_object_set (de->var_sheet,
422 "model", de->var_store,
425 case PROP_VS_ROW_MENU:
427 GObject *menu = g_value_get_object (value);
429 g_signal_connect (de->var_sheet, "button-event-row",
430 G_CALLBACK (popup_variable_row_menu), menu);
433 case PROP_DS_COLUMN_MENU:
435 GObject *menu = g_value_get_object (value);
437 g_signal_connect (de->data_sheet[0], "button-event-column",
438 G_CALLBACK (popup_variable_column_menu), menu);
441 case PROP_DS_ROW_MENU:
443 GObject *menu = g_value_get_object (value);
445 g_signal_connect (de->data_sheet[0], "button-event-row",
446 G_CALLBACK (popup_cases_menu), menu);
449 case PROP_CURRENT_VAR:
452 gint var = g_value_get_long (value);
453 switch (gtk_notebook_get_current_page (GTK_NOTEBOOK (object)))
455 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
456 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &col);
457 psppire_sheet_set_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), row, var);
458 psppire_sheet_moveto (PSPPIRE_SHEET (de->data_sheet[0]), -1, var, 0.5, 0.5);
460 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
461 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->var_sheet), &row, &col);
462 psppire_sheet_set_active_cell (PSPPIRE_SHEET (de->var_sheet), var, col);
463 psppire_sheet_moveto (PSPPIRE_SHEET (de->var_sheet), var, -1, 0.5, 0.5);
466 g_assert_not_reached ();
471 case PROP_CURRENT_CASE:
474 gint case_num = g_value_get_long (value);
475 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &col);
476 psppire_sheet_set_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), case_num, col);
477 psppire_sheet_moveto (PSPPIRE_SHEET (de->data_sheet[0]), case_num, -1, 0.5, 0.5);
480 case PROP_VALUE_LABELS:
482 psppire_data_store_show_labels (de->data_store,
483 g_value_get_boolean (value));
487 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
493 psppire_data_editor_get_property (GObject *object,
498 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (object);
502 case PROP_SPLIT_WINDOW:
503 g_value_set_boolean (value, de->split);
505 case PROP_DATA_STORE:
506 g_value_set_pointer (value, de->data_store);
509 g_value_set_pointer (value, de->var_store);
511 case PROP_CURRENT_CASE:
514 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &column);
515 g_value_set_long (value, row);
518 case PROP_CURRENT_VAR:
521 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &column);
522 g_value_set_long (value, column);
525 case PROP_DATA_SELECTED:
526 g_value_set_boolean (value, data_is_selected (de));
529 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
536 psppire_data_editor_class_init (PsppireDataEditorClass *klass)
538 GParamSpec *data_store_spec ;
539 GParamSpec *var_store_spec ;
540 GParamSpec *column_menu_spec;
541 GParamSpec *ds_row_menu_spec;
542 GParamSpec *vs_row_menu_spec;
543 GParamSpec *value_labels_spec;
544 GParamSpec *current_case_spec;
545 GParamSpec *current_var_spec;
546 GParamSpec *data_selected_spec;
547 GParamSpec *split_window_spec;
548 GObjectClass *object_class = G_OBJECT_CLASS (klass);
550 parent_class = g_type_class_peek_parent (klass);
552 object_class->dispose = psppire_data_editor_dispose;
553 object_class->finalize = psppire_data_editor_finalize;
555 object_class->set_property = psppire_data_editor_set_property;
556 object_class->get_property = psppire_data_editor_get_property;
561 g_param_spec_pointer ("data-store",
563 "A pointer to the data store associated with this editor",
564 G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE );
566 g_object_class_install_property (object_class,
571 g_param_spec_pointer ("var-store",
573 "A pointer to the variable store associated with this editor",
574 G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE );
576 g_object_class_install_property (object_class,
581 g_param_spec_object ("datasheet-column-menu",
582 "Data Sheet Column Menu",
583 "A menu to be displayed when button 3 is pressed in thedata sheet's column title buttons",
587 g_object_class_install_property (object_class,
593 g_param_spec_object ("datasheet-row-menu",
594 "Data Sheet Row Menu",
595 "A menu to be displayed when button 3 is pressed in the data sheet's row title buttons",
599 g_object_class_install_property (object_class,
605 g_param_spec_object ("varsheet-row-menu",
606 "Variable Sheet Row Menu",
607 "A menu to be displayed when button 3 is pressed in the variable sheet's row title buttons",
611 g_object_class_install_property (object_class,
617 g_param_spec_boolean ("value-labels",
619 "Whether or not the data sheet should display labels instead of values",
621 G_PARAM_WRITABLE | G_PARAM_READABLE);
623 g_object_class_install_property (object_class,
629 g_param_spec_long ("current-case",
631 "Zero based number of the selected case",
634 G_PARAM_WRITABLE | G_PARAM_READABLE);
636 g_object_class_install_property (object_class,
642 g_param_spec_long ("current-variable",
644 "Zero based number of the selected variable",
647 G_PARAM_WRITABLE | G_PARAM_READABLE);
649 g_object_class_install_property (object_class,
655 g_param_spec_boolean ("data-selected",
657 "True iff the data view is active and one or more cells of data have been selected.",
661 g_object_class_install_property (object_class,
668 g_param_spec_boolean ("split",
670 "True iff the data sheet is split",
672 G_PARAM_READABLE | G_PARAM_WRITABLE);
674 g_object_class_install_property (object_class,
678 data_editor_signals [DATA_SELECTION_CHANGED] =
679 g_signal_new ("data-selection-changed",
680 G_TYPE_FROM_CLASS (klass),
684 g_cclosure_marshal_VOID__BOOLEAN,
689 data_editor_signals [CASES_SELECTED] =
690 g_signal_new ("cases-selected",
691 G_TYPE_FROM_CLASS (klass),
695 g_cclosure_marshal_VOID__INT,
701 data_editor_signals [VARIABLES_SELECTED] =
702 g_signal_new ("variables-selected",
703 G_TYPE_FROM_CLASS (klass),
707 g_cclosure_marshal_VOID__INT,
713 data_editor_signals [DATA_AVAILABLE_CHANGED] =
714 g_signal_new ("data-available-changed",
715 G_TYPE_FROM_CLASS (klass),
719 g_cclosure_marshal_VOID__BOOLEAN,
725 /* Update the data_ref_entry with the reference of the active cell */
727 update_data_ref_entry (const PsppireSheet *sheet,
729 gint old_row, gint old_col,
732 PsppireDataEditor *de = data;
734 PsppireDataStore *data_store =
735 PSPPIRE_DATA_STORE (psppire_sheet_get_model (sheet));
739 const struct variable *var =
740 psppire_dict_get_variable (data_store->dict, col);
744 gchar *text = g_strdup_printf ("%d: %s", row + FIRST_CASE_NUMBER,
747 gchar *s = recode_string (UTF8,
748 psppire_dict_encoding (data_store->dict),
753 gtk_entry_set_text (GTK_ENTRY (de->cell_ref_entry), s);
763 psppire_data_store_get_string (data_store, row,
764 var_get_dict_index(var));
771 gtk_entry_set_text (GTK_ENTRY (de->datum_entry), text);
783 gtk_entry_set_text (GTK_ENTRY (de->datum_entry), "");
790 datum_entry_activate (GtkEntry *entry, gpointer data)
793 PsppireDataEditor *de = data;
795 const gchar *text = gtk_entry_get_text (entry);
797 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &column);
799 if ( row == -1 || column == -1)
802 psppire_data_store_set_string (de->data_store, text, row, column);
805 static void on_activate (PsppireDataEditor *de);
806 static gboolean on_switch_page (PsppireDataEditor *de, GtkNotebookPage *p, gint pagenum, gpointer data);
807 static void on_select_range (PsppireDataEditor *de);
809 static void on_select_row (PsppireSheet *, gint, PsppireDataEditor *);
810 static void on_select_variable (PsppireSheet *, gint, PsppireDataEditor *);
813 static void on_owner_change (GtkClipboard *,
814 GdkEventOwnerChange *, gpointer);
817 on_map (GtkWidget *w)
819 GtkClipboard *clip = gtk_widget_get_clipboard (w, GDK_SELECTION_CLIPBOARD);
821 g_signal_connect (clip, "owner-change", G_CALLBACK (on_owner_change), w);
826 init_sheet (PsppireDataEditor *de, int i,
827 GtkAdjustment *hadj, GtkAdjustment *vadj,
832 de->sheet_bin[i] = gtk_scrolled_window_new (hadj, vadj);
834 de->data_sheet[i] = psppire_sheet_new (NULL);
836 g_object_set (de->sheet_bin[i],
838 "shadow-type", GTK_SHADOW_ETCHED_IN,
841 g_object_set (haxis, "default-size", 75, NULL);
842 g_object_set (vaxis, "default-size", 25, NULL);
844 g_object_set (de->data_sheet[i],
845 "horizontal-axis", haxis,
846 "vertical-axis", vaxis,
849 gtk_container_add (GTK_CONTAINER (de->sheet_bin[i]), de->data_sheet[i]);
851 g_signal_connect (de->data_sheet[i], "traverse",
852 G_CALLBACK (traverse_cell_callback), de);
854 gtk_widget_show (de->sheet_bin[i]);
859 init_data_sheet (PsppireDataEditor *de)
861 GtkAdjustment *vadj0, *hadj0;
862 GtkAdjustment *vadj1, *hadj1;
865 de->vaxis[0] = psppire_axis_new ();
866 de->vaxis[1] = psppire_axis_new ();
868 /* There's only one horizontal axis, since the
869 column widths are parameters of the variables */
870 de->haxis = psppire_axis_new ();
873 de->paned = gtk_xpaned_new ();
875 init_sheet (de, 0, NULL, NULL, de->vaxis[0], de->haxis);
876 gtk_widget_show (de->sheet_bin[0]);
877 vadj0 = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[0]));
878 hadj0 = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[0]));
880 g_object_set (de->sheet_bin[0], "vscrollbar-policy", GTK_POLICY_NEVER, NULL);
881 g_object_set (de->sheet_bin[0], "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
883 init_sheet (de, 1, NULL, vadj0, de->vaxis[0], de->haxis);
884 gtk_widget_show (de->sheet_bin[1]);
885 sheet = gtk_bin_get_child (GTK_BIN (de->sheet_bin[1]));
886 psppire_sheet_hide_row_titles (PSPPIRE_SHEET (sheet));
887 hadj1 = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[1]));
888 g_object_set (de->sheet_bin[1], "vscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
889 g_object_set (de->sheet_bin[1], "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
891 init_sheet (de, 2, hadj0, NULL, de->vaxis[1], de->haxis);
892 gtk_widget_show (de->sheet_bin[2]);
893 sheet = gtk_bin_get_child (GTK_BIN (de->sheet_bin[2]));
894 psppire_sheet_hide_column_titles (PSPPIRE_SHEET (sheet));
895 g_object_set (de->sheet_bin[2], "vscrollbar-policy", GTK_POLICY_NEVER, NULL);
896 g_object_set (de->sheet_bin[2], "hscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
897 vadj1 = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[2]));
899 init_sheet (de, 3, hadj1, vadj1, de->vaxis[1], de->haxis);
900 gtk_widget_show (de->sheet_bin[3]);
901 sheet = gtk_bin_get_child (GTK_BIN (de->sheet_bin[3]));
902 psppire_sheet_hide_column_titles (PSPPIRE_SHEET (sheet));
903 psppire_sheet_hide_row_titles (PSPPIRE_SHEET (sheet));
904 g_object_set (de->sheet_bin[3], "vscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
905 g_object_set (de->sheet_bin[3], "hscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
907 gtk_xpaned_pack_top_left (GTK_XPANED (de->paned), de->sheet_bin[0], TRUE, TRUE);
908 gtk_xpaned_pack_top_right (GTK_XPANED (de->paned), de->sheet_bin[1], TRUE, TRUE);
909 gtk_xpaned_pack_bottom_left (GTK_XPANED (de->paned), de->sheet_bin[2], TRUE, TRUE);
910 gtk_xpaned_pack_bottom_right (GTK_XPANED (de->paned), de->sheet_bin[3], TRUE, TRUE);
912 gtk_xpaned_set_position_y (GTK_XPANED (de->paned), 150);
913 gtk_xpaned_set_position_x (GTK_XPANED (de->paned), 350);
918 psppire_data_editor_init (PsppireDataEditor *de)
920 GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
921 GtkWidget *sw_vs = gtk_scrolled_window_new (NULL, NULL);
923 init_data_sheet (de);
925 de->data_vbox = gtk_vbox_new (FALSE, 0);
926 de->var_sheet = psppire_var_sheet_new ();
928 g_object_set (de, "tab-pos", GTK_POS_BOTTOM, NULL);
930 de->datum_entry = gtk_entry_new ();
931 de->cell_ref_entry = gtk_entry_new ();
933 g_object_set (de->cell_ref_entry,
939 gtk_box_pack_start (GTK_BOX (hbox), de->cell_ref_entry, FALSE, FALSE, 0);
940 gtk_box_pack_start (GTK_BOX (hbox), de->datum_entry, TRUE, TRUE, 0);
943 gtk_container_add (GTK_CONTAINER (sw_vs), de->var_sheet);
944 gtk_widget_show_all (sw_vs);
947 gtk_box_pack_start (GTK_BOX (de->data_vbox), hbox, FALSE, FALSE, 0);
948 gtk_box_pack_start (GTK_BOX (de->data_vbox), de->paned, TRUE, TRUE, 0);
951 psppire_data_editor_remove_split (de);
953 gtk_widget_show_all (de->data_vbox);
955 gtk_notebook_append_page (GTK_NOTEBOOK (de), de->data_vbox,
956 gtk_label_new_with_mnemonic (_("Data View")));
958 gtk_notebook_append_page (GTK_NOTEBOOK (de), sw_vs,
959 gtk_label_new_with_mnemonic (_("Variable View")));
961 g_signal_connect (de->data_sheet[0], "activate",
962 G_CALLBACK (update_data_ref_entry),
965 g_signal_connect (de->datum_entry, "activate",
966 G_CALLBACK (datum_entry_activate),
970 g_signal_connect_swapped (de->data_sheet[0],
971 "double-click-column",
972 G_CALLBACK (on_data_column_clicked),
975 g_signal_connect_swapped (de->var_sheet,
977 G_CALLBACK (on_var_row_clicked),
980 g_signal_connect_swapped (de->data_sheet[0], "activate",
981 G_CALLBACK (on_activate),
984 g_signal_connect_swapped (de->data_sheet[0], "select-range",
985 G_CALLBACK (on_select_range),
988 g_signal_connect (de->data_sheet[0], "select-row",
989 G_CALLBACK (on_select_row), de);
991 g_signal_connect (de->data_sheet[0], "select-column",
992 G_CALLBACK (on_select_variable), de);
995 g_signal_connect (de->var_sheet, "select-row",
996 G_CALLBACK (on_select_variable), de);
999 g_signal_connect_after (de, "switch-page",
1000 G_CALLBACK (on_switch_page),
1003 g_object_set (de, "can-focus", FALSE, NULL);
1005 g_signal_connect (de, "map", G_CALLBACK (on_map), NULL);
1008 // psppire_sheet_hide_column_titles (de->var_sheet);
1009 // psppire_sheet_hide_row_titles (de->data_sheet);
1012 de->dispose_has_run = FALSE;
1017 psppire_data_editor_new (PsppireVarStore *var_store,
1018 PsppireDataStore *data_store)
1020 return g_object_new (PSPPIRE_DATA_EDITOR_TYPE,
1021 "var-store", var_store,
1022 "data-store", data_store,
1028 psppire_data_editor_remove_split (PsppireDataEditor *de)
1030 if ( !de->split ) return;
1033 g_object_ref (de->sheet_bin[0]);
1034 gtk_container_remove (GTK_CONTAINER (de->paned), de->sheet_bin[0]);
1036 g_object_ref (de->paned);
1037 gtk_container_remove (GTK_CONTAINER (de->data_vbox), de->paned);
1039 gtk_box_pack_start (GTK_BOX (de->data_vbox), de->sheet_bin[0],
1042 g_object_unref (de->sheet_bin[0]);
1044 g_object_set (de->sheet_bin[0], "vscrollbar-policy",
1045 GTK_POLICY_ALWAYS, NULL);
1047 g_object_set (de->sheet_bin[0], "hscrollbar-policy",
1048 GTK_POLICY_ALWAYS, NULL);
1053 psppire_data_editor_set_split (PsppireDataEditor *de)
1055 if ( de->split ) return;
1058 g_object_ref (de->sheet_bin[0]);
1059 gtk_container_remove (GTK_CONTAINER (de->data_vbox), de->sheet_bin[0]);
1061 gtk_xpaned_pack_top_left (GTK_XPANED (de->paned), de->sheet_bin [0],
1064 gtk_box_pack_start (GTK_BOX (de->data_vbox), de->paned,
1067 g_object_unref (de->paned);
1069 g_object_set (de->sheet_bin[0], "vscrollbar-policy",
1070 GTK_POLICY_NEVER, NULL);
1072 g_object_set (de->sheet_bin[0], "hscrollbar-policy",
1073 GTK_POLICY_NEVER, NULL);
1077 psppire_data_editor_split_window (PsppireDataEditor *de, gboolean split)
1080 psppire_data_editor_set_split (de);
1082 psppire_data_editor_remove_split (de);
1084 gtk_widget_show_all (de->data_vbox);
1087 static void data_sheet_set_clip (PsppireSheet *sheet);
1088 static void data_sheet_contents_received_callback (GtkClipboard *clipboard,
1089 GtkSelectionData *sd,
1094 psppire_data_editor_clip_copy (PsppireDataEditor *de)
1096 data_sheet_set_clip (PSPPIRE_SHEET (de->data_sheet[0]));
1100 psppire_data_editor_clip_paste (PsppireDataEditor *de)
1102 GdkDisplay *display = gtk_widget_get_display ( GTK_WIDGET (de));
1103 GtkClipboard *clipboard =
1104 gtk_clipboard_get_for_display (display, GDK_SELECTION_CLIPBOARD);
1106 gtk_clipboard_request_contents (clipboard,
1107 gdk_atom_intern ("UTF8_STRING", TRUE),
1108 data_sheet_contents_received_callback,
1115 psppire_data_editor_clip_cut (PsppireDataEditor *de)
1117 gint max_rows, max_columns;
1119 PsppireSheetRange range;
1120 PsppireDataStore *ds = de->data_store;
1122 data_sheet_set_clip (PSPPIRE_SHEET (de->data_sheet[0]));
1124 /* Now blank all the cells */
1125 psppire_sheet_get_selected_range (PSPPIRE_SHEET (de->data_sheet[0]), &range);
1127 /* If nothing selected, then use active cell */
1128 if ( range.row0 < 0 || range.col0 < 0 )
1131 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &col);
1133 range.row0 = range.rowi = row;
1134 range.col0 = range.coli = col;
1137 /* The sheet range can include cells that do not include data.
1138 Exclude them from the range. */
1139 max_rows = psppire_data_store_get_case_count (ds);
1140 if (range.rowi >= max_rows)
1144 range.rowi = max_rows - 1;
1147 max_columns = dict_get_var_cnt (ds->dict->dict);
1148 if (range.coli >= max_columns)
1150 if (max_columns == 0)
1152 range.coli = max_columns - 1;
1155 g_return_if_fail (range.rowi >= range.row0);
1156 g_return_if_fail (range.row0 >= 0);
1157 g_return_if_fail (range.coli >= range.col0);
1158 g_return_if_fail (range.col0 >= 0);
1161 for (r = range.row0; r <= range.rowi ; ++r )
1165 for (c = range.col0 ; c <= range.coli; ++c)
1167 psppire_data_store_set_string (ds, "", r, c);
1171 /* and remove the selection */
1172 psppire_sheet_unselect_range (PSPPIRE_SHEET (de->data_sheet[0]));
1178 /* Popup menu related stuff */
1181 popup_variable_column_menu (PsppireSheet *sheet, gint column,
1182 GdkEventButton *event, gpointer data)
1184 GtkMenu *menu = GTK_MENU (data);
1186 PsppireDataStore *data_store =
1187 PSPPIRE_DATA_STORE (psppire_sheet_get_model (sheet));
1189 const struct variable *v =
1190 psppire_dict_get_variable (data_store->dict, column);
1192 if ( v && event->button == 3)
1194 psppire_sheet_select_column (sheet, column);
1196 gtk_menu_popup (menu,
1197 NULL, NULL, NULL, NULL,
1198 event->button, event->time);
1204 popup_variable_row_menu (PsppireSheet *sheet, gint row,
1205 GdkEventButton *event, gpointer data)
1207 GtkMenu *menu = GTK_MENU (data);
1209 PsppireVarStore *var_store =
1210 PSPPIRE_VAR_STORE (psppire_sheet_get_model (sheet));
1212 const struct variable *v =
1213 psppire_dict_get_variable (var_store->dict, row);
1215 if ( v && event->button == 3)
1217 psppire_sheet_select_row (sheet, row);
1219 gtk_menu_popup (menu,
1220 NULL, NULL, NULL, NULL,
1221 event->button, event->time);
1227 popup_cases_menu (PsppireSheet *sheet, gint row,
1228 GdkEventButton *event, gpointer data)
1230 GtkMenu *menu = GTK_MENU (data);
1232 PsppireDataStore *data_store =
1233 PSPPIRE_DATA_STORE (psppire_sheet_get_model (sheet));
1235 if ( row <= psppire_data_store_get_case_count (data_store) &&
1238 psppire_sheet_select_row (sheet, row);
1240 gtk_menu_popup (menu,
1241 NULL, NULL, NULL, NULL,
1242 event->button, event->time);
1251 do_sort (PsppireDataStore *ds, int var, gboolean descend)
1253 GString *string = g_string_new ("SORT CASES BY ");
1255 const struct variable *v =
1256 psppire_dict_get_variable (ds->dict, var);
1258 g_string_append_printf (string, "%s", var_get_name (v));
1261 g_string_append (string, " (D)");
1263 g_string_append (string, ".");
1265 execute_syntax (create_syntax_string_source (string->str));
1267 g_string_free (string, TRUE);
1271 /* Sort the data by the the variable which the editor has currently
1274 psppire_data_editor_sort_ascending (PsppireDataEditor *de)
1276 PsppireSheetRange range;
1277 psppire_sheet_get_selected_range (PSPPIRE_SHEET(de->data_sheet[0]), &range);
1279 do_sort (de->data_store, range.col0, FALSE);
1283 /* Sort the data by the the variable which the editor has currently
1286 psppire_data_editor_sort_descending (PsppireDataEditor *de)
1288 PsppireSheetRange range;
1289 psppire_sheet_get_selected_range (PSPPIRE_SHEET(de->data_sheet[0]), &range);
1291 do_sort (de->data_store, range.col0, TRUE);
1298 /* Insert a new variable before the currently selected position */
1300 psppire_data_editor_insert_variable (PsppireDataEditor *de)
1304 switch (gtk_notebook_get_current_page (GTK_NOTEBOOK (de)))
1306 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
1307 if ( PSPPIRE_SHEET (de->data_sheet[0])->select_status
1308 == PSPPIRE_SHEET_COLUMN_SELECTED )
1309 posn = PSPPIRE_SHEET (de->data_sheet[0])->range.col0;
1311 posn = PSPPIRE_SHEET (de->data_sheet[0])->active_cell.col;
1313 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
1314 if ( PSPPIRE_SHEET (de->var_sheet)->select_status
1315 == PSPPIRE_SHEET_ROW_SELECTED )
1316 posn = PSPPIRE_SHEET (de->var_sheet)->range.row0;
1318 posn = PSPPIRE_SHEET (de->var_sheet)->active_cell.row;
1321 g_assert_not_reached ();
1325 psppire_dict_insert_variable (de->data_store->dict, posn, NULL);
1328 /* Insert a new case before the currently selected position */
1330 psppire_data_editor_insert_case (PsppireDataEditor *de)
1334 if ( PSPPIRE_SHEET (de->data_sheet[0])->select_status == PSPPIRE_SHEET_ROW_SELECTED )
1336 posn = PSPPIRE_SHEET (de->data_sheet[0])->range.row0;
1340 posn = PSPPIRE_SHEET (de->data_sheet[0])->active_cell.row;
1343 if ( posn == -1 ) posn = 0;
1345 psppire_data_store_insert_new_case (de->data_store, posn);
1348 /* Delete the cases currently selected in the data sheet */
1350 psppire_data_editor_delete_cases (PsppireDataEditor *de)
1352 gint first = PSPPIRE_SHEET (de->data_sheet[0])->range.row0;
1353 gint n = PSPPIRE_SHEET (de->data_sheet[0])->range.rowi - first + 1;
1355 psppire_data_store_delete_cases (de->data_store, first, n);
1357 psppire_sheet_unselect_range (PSPPIRE_SHEET (de->data_sheet[0]));
1360 /* Delete the variables currently selected in the
1361 datasheet or variable sheet */
1363 psppire_data_editor_delete_variables (PsppireDataEditor *de)
1367 switch (gtk_notebook_get_current_page (GTK_NOTEBOOK (de)))
1369 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
1370 first = PSPPIRE_SHEET (de->data_sheet[0])->range.col0;
1371 n = PSPPIRE_SHEET (de->data_sheet[0])->range.coli - first + 1;
1373 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
1374 first = PSPPIRE_SHEET (de->var_sheet)->range.row0;
1375 n = PSPPIRE_SHEET (de->var_sheet)->range.rowi - first + 1;
1378 g_assert_not_reached ();
1382 psppire_dict_delete_variables (de->var_store->dict, first, n);
1384 psppire_sheet_unselect_range (PSPPIRE_SHEET (de->data_sheet[0]));
1385 psppire_sheet_unselect_range (PSPPIRE_SHEET (de->var_sheet));
1390 psppire_data_editor_show_grid (PsppireDataEditor *de, gboolean grid_visible)
1392 psppire_sheet_show_grid (PSPPIRE_SHEET (de->var_sheet), grid_visible);
1393 psppire_sheet_show_grid (PSPPIRE_SHEET (de->data_sheet[0]), grid_visible);
1398 set_font (GtkWidget *w, gpointer data)
1400 PangoFontDescription *font_desc = data;
1401 GtkRcStyle *style = gtk_widget_get_modifier_style (w);
1403 pango_font_description_free (style->font_desc);
1404 style->font_desc = pango_font_description_copy (font_desc);
1406 gtk_widget_modify_style (w, style);
1408 if ( GTK_IS_CONTAINER (w))
1409 gtk_container_foreach (GTK_CONTAINER (w), set_font, font_desc);
1413 psppire_data_editor_set_font (PsppireDataEditor *de, PangoFontDescription *font_desc)
1415 set_font (GTK_WIDGET (de), font_desc);
1416 gtk_container_foreach (GTK_CONTAINER (de), set_font, font_desc);
1424 emit_selected_signal (PsppireDataEditor *de)
1426 gboolean data_selected = data_is_selected (de);
1428 g_signal_emit (de, data_editor_signals[DATA_SELECTION_CHANGED], 0, data_selected);
1433 on_activate (PsppireDataEditor *de)
1436 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &col);
1439 if ( row < psppire_data_store_get_case_count (de->data_store)
1441 col < psppire_var_store_get_var_cnt (de->var_store))
1443 emit_selected_signal (de);
1447 emit_selected_signal (de);
1452 on_select_range (PsppireDataEditor *de)
1454 PsppireSheetRange range;
1456 psppire_sheet_get_selected_range (PSPPIRE_SHEET (de->data_sheet[0]), &range);
1458 if ( range.rowi < psppire_data_store_get_case_count (de->data_store)
1460 range.coli < psppire_var_store_get_var_cnt (de->var_store))
1462 emit_selected_signal (de);
1466 emit_selected_signal (de);
1471 on_switch_page (PsppireDataEditor *de, GtkNotebookPage *p,
1472 gint pagenum, gpointer data)
1476 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
1477 gtk_widget_grab_focus (de->data_vbox);
1478 on_select_range (de);
1480 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
1481 gtk_widget_grab_focus (de->var_sheet);
1482 emit_selected_signal (de);
1494 data_is_selected (PsppireDataEditor *de)
1496 PsppireSheetRange range;
1499 if ( gtk_notebook_get_current_page (GTK_NOTEBOOK (de)) != PSPPIRE_DATA_EDITOR_DATA_VIEW)
1502 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &col);
1504 if ( row >= psppire_data_store_get_case_count (de->data_store)
1506 col >= psppire_var_store_get_var_cnt (de->var_store))
1511 psppire_sheet_get_selected_range (PSPPIRE_SHEET (de->data_sheet[0]), &range);
1513 if ( range.rowi >= psppire_data_store_get_case_count (de->data_store)
1515 range.coli >= psppire_var_store_get_var_cnt (de->var_store))
1525 on_select_row (PsppireSheet *sheet, gint row, PsppireDataEditor *de)
1527 g_signal_emit (de, data_editor_signals[CASES_SELECTED], 0, row);
1532 on_select_variable (PsppireSheet *sheet, gint var, PsppireDataEditor *de)
1534 g_signal_emit (de, data_editor_signals[VARIABLES_SELECTED], 0, var);
1540 /* Clipboard stuff */
1543 #include <data/casereader.h>
1544 #include <data/case-map.h>
1545 #include <data/casewriter.h>
1547 #include <data/data-out.h>
1550 /* A casereader and dictionary holding the data currently in the clip */
1551 static struct casereader *clip_datasheet = NULL;
1552 static struct dictionary *clip_dict = NULL;
1555 static void data_sheet_update_clipboard (PsppireSheet *);
1557 /* Set the clip according to the currently
1558 selected range in the data sheet */
1560 data_sheet_set_clip (PsppireSheet *sheet)
1563 struct casewriter *writer ;
1564 PsppireSheetRange range;
1565 PsppireDataStore *ds;
1566 struct case_map *map = NULL;
1567 casenumber max_rows;
1570 ds = PSPPIRE_DATA_STORE (psppire_sheet_get_model (sheet));
1572 psppire_sheet_get_selected_range (sheet, &range);
1574 /* If nothing selected, then use active cell */
1575 if ( range.row0 < 0 || range.col0 < 0 )
1578 psppire_sheet_get_active_cell (sheet, &row, &col);
1580 range.row0 = range.rowi = row;
1581 range.col0 = range.coli = col;
1584 /* The sheet range can include cells that do not include data.
1585 Exclude them from the range. */
1586 max_rows = psppire_data_store_get_case_count (ds);
1587 if (range.rowi >= max_rows)
1591 range.rowi = max_rows - 1;
1593 max_columns = dict_get_var_cnt (ds->dict->dict);
1594 if (range.coli >= max_columns)
1596 if (max_columns == 0)
1598 range.coli = max_columns - 1;
1601 g_return_if_fail (range.rowi >= range.row0);
1602 g_return_if_fail (range.row0 >= 0);
1603 g_return_if_fail (range.coli >= range.col0);
1604 g_return_if_fail (range.col0 >= 0);
1606 /* Destroy any existing clip */
1607 if ( clip_datasheet )
1609 casereader_destroy (clip_datasheet);
1610 clip_datasheet = NULL;
1615 dict_destroy (clip_dict);
1619 /* Construct clip dictionary. */
1620 clip_dict = dict_create ();
1621 for (i = range.col0; i <= range.coli; i++)
1623 const struct variable *old = dict_get_var (ds->dict->dict, i);
1624 dict_clone_var_assert (clip_dict, old, var_get_name (old));
1627 /* Construct clip data. */
1628 map = case_map_by_name (ds->dict->dict, clip_dict);
1629 writer = autopaging_writer_create (dict_get_proto (clip_dict));
1630 for (i = range.row0; i <= range.rowi ; ++i )
1632 struct ccase *old = psppire_data_store_get_case (ds, i);
1634 casewriter_write (writer, case_map_execute (map, old));
1636 casewriter_force_error (writer);
1638 case_map_destroy (map);
1640 clip_datasheet = casewriter_make_reader (writer);
1642 data_sheet_update_clipboard (sheet);
1652 /* Perform data_out for case CC, variable V, appending to STRING */
1654 data_out_g_string (GString *string, const struct variable *v,
1655 const struct ccase *cc)
1659 const struct fmt_spec *fs = var_get_print_format (v);
1660 const union value *val = case_data (cc, v);
1661 buf = xzalloc (fs->w);
1663 data_out (val, fs, buf);
1665 g_string_append_len (string, buf, fs->w);
1676 const size_t val_cnt = caseproto_get_n_widths (casereader_get_proto (clip_datasheet));
1677 const casenumber case_cnt = casereader_get_case_cnt (clip_datasheet);
1678 const size_t var_cnt = dict_get_var_cnt (clip_dict);
1680 string = g_string_sized_new (10 * val_cnt * case_cnt);
1682 for (r = 0 ; r < case_cnt ; ++r )
1687 cc = casereader_peek (clip_datasheet, r);
1690 g_warning ("Clipboard seems to have inexplicably shrunk");
1694 for (c = 0 ; c < var_cnt ; ++c)
1696 const struct variable *v = dict_get_var (clip_dict, c);
1697 data_out_g_string (string, v, cc);
1698 if ( c < val_cnt - 1 )
1699 g_string_append (string, "\t");
1703 g_string_append (string, "\n");
1718 const size_t val_cnt = caseproto_get_n_widths (casereader_get_proto (clip_datasheet));
1719 const casenumber case_cnt = casereader_get_case_cnt (clip_datasheet);
1720 const size_t var_cnt = dict_get_var_cnt (clip_dict);
1723 /* Guestimate the size needed */
1724 string = g_string_sized_new (20 * val_cnt * case_cnt);
1726 g_string_append (string, "<table>\n");
1727 for (r = 0 ; r < case_cnt ; ++r )
1730 struct ccase *cc = casereader_peek (clip_datasheet, r);
1733 g_warning ("Clipboard seems to have inexplicably shrunk");
1736 g_string_append (string, "<tr>\n");
1738 for (c = 0 ; c < var_cnt ; ++c)
1740 const struct variable *v = dict_get_var (clip_dict, c);
1741 g_string_append (string, "<td>");
1742 data_out_g_string (string, v, cc);
1743 g_string_append (string, "</td>\n");
1746 g_string_append (string, "</tr>\n");
1750 g_string_append (string, "</table>\n");
1758 clipboard_get_cb (GtkClipboard *clipboard,
1759 GtkSelectionData *selection_data,
1763 GString *string = NULL;
1767 case SELECT_FMT_TEXT:
1768 string = clip_to_text ();
1770 case SELECT_FMT_HTML:
1771 string = clip_to_html ();
1774 g_assert_not_reached ();
1777 gtk_selection_data_set (selection_data, selection_data->target,
1779 (const guchar *) string->str, string->len);
1781 g_string_free (string, TRUE);
1785 clipboard_clear_cb (GtkClipboard *clipboard,
1788 dict_destroy (clip_dict);
1791 casereader_destroy (clip_datasheet);
1792 clip_datasheet = NULL;
1796 static const GtkTargetEntry targets[] = {
1797 { "UTF8_STRING", 0, SELECT_FMT_TEXT },
1798 { "STRING", 0, SELECT_FMT_TEXT },
1799 { "TEXT", 0, SELECT_FMT_TEXT },
1800 { "COMPOUND_TEXT", 0, SELECT_FMT_TEXT },
1801 { "text/plain;charset=utf-8", 0, SELECT_FMT_TEXT },
1802 { "text/plain", 0, SELECT_FMT_TEXT },
1803 { "text/html", 0, SELECT_FMT_HTML }
1809 data_sheet_update_clipboard (PsppireSheet *sheet)
1811 GtkClipboard *clipboard =
1812 gtk_widget_get_clipboard (GTK_WIDGET (sheet),
1813 GDK_SELECTION_CLIPBOARD);
1815 if (!gtk_clipboard_set_with_owner (clipboard, targets,
1816 G_N_ELEMENTS (targets),
1817 clipboard_get_cb, clipboard_clear_cb,
1819 clipboard_clear_cb (clipboard, sheet);
1824 /* A callback for when the clipboard contents have been received */
1826 data_sheet_contents_received_callback (GtkClipboard *clipboard,
1827 GtkSelectionData *sd,
1832 gint next_row, next_column;
1835 PsppireDataEditor *data_editor = data;
1837 if ( sd->length < 0 )
1840 if ( sd->type != gdk_atom_intern ("UTF8_STRING", FALSE))
1843 c = (char *) sd->data;
1845 /* Paste text to selected position */
1846 psppire_sheet_get_active_cell (PSPPIRE_SHEET (data_editor->data_sheet[0]),
1849 g_return_if_fail (row >= 0);
1850 g_return_if_fail (column >= 0);
1852 first_column = column;
1854 next_column = column;
1855 while (count < sd->length)
1860 column = next_column;
1861 while (*c != '\t' && *c != '\n' && count < sd->length)
1869 next_column = column + 1;
1871 else if ( *c == '\n')
1874 next_column = first_column;
1880 /* Append some new cases if pasting beyond the last row */
1881 if ( row >= psppire_data_store_get_case_count (data_editor->data_store))
1882 psppire_data_store_insert_new_case (data_editor->data_store, row);
1884 psppire_data_store_set_string (data_editor->data_store, s, row, column);
1890 on_owner_change (GtkClipboard *clip, GdkEventOwnerChange *event, gpointer data)
1893 gboolean compatible_target = FALSE;
1894 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
1896 for (i = 0 ; i < sizeof (targets) / sizeof(targets[0]) ; ++i )
1898 GdkAtom atom = gdk_atom_intern (targets[i].target, TRUE);
1899 if ( gtk_clipboard_wait_is_target_available (clip, atom))
1901 compatible_target = TRUE;
1906 g_signal_emit (de, data_editor_signals[DATA_AVAILABLE_CHANGED], 0,