1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2008, 2009, 2010 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,
748 gtk_entry_set_text (GTK_ENTRY (de->cell_ref_entry), text);
758 psppire_data_store_get_string (data_store, row,
759 var_get_dict_index(var));
766 gtk_entry_set_text (GTK_ENTRY (de->datum_entry), text);
778 gtk_entry_set_text (GTK_ENTRY (de->datum_entry), "");
785 datum_entry_activate (GtkEntry *entry, gpointer data)
788 PsppireDataEditor *de = data;
790 const gchar *text = gtk_entry_get_text (entry);
792 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &column);
794 if ( row == -1 || column == -1)
797 psppire_data_store_set_string (de->data_store, text, row, column);
800 static void on_activate (PsppireDataEditor *de);
801 static gboolean on_switch_page (PsppireDataEditor *de, GtkNotebookPage *p, gint pagenum, gpointer data);
802 static void on_select_range (PsppireDataEditor *de);
804 static void on_select_row (PsppireSheet *, gint, PsppireDataEditor *);
805 static void on_select_variable (PsppireSheet *, gint, PsppireDataEditor *);
808 static void on_owner_change (GtkClipboard *,
809 GdkEventOwnerChange *, gpointer);
812 on_map (GtkWidget *w)
814 GtkClipboard *clip = gtk_widget_get_clipboard (w, GDK_SELECTION_CLIPBOARD);
816 g_signal_connect (clip, "owner-change", G_CALLBACK (on_owner_change), w);
821 init_sheet (PsppireDataEditor *de, int i,
822 GtkAdjustment *hadj, GtkAdjustment *vadj,
827 de->sheet_bin[i] = gtk_scrolled_window_new (hadj, vadj);
829 de->data_sheet[i] = psppire_sheet_new (NULL);
831 g_object_set (de->sheet_bin[i],
833 "shadow-type", GTK_SHADOW_ETCHED_IN,
836 g_object_set (haxis, "default-size", 75, NULL);
837 g_object_set (vaxis, "default-size", 25, NULL);
839 g_object_set (de->data_sheet[i],
840 "horizontal-axis", haxis,
841 "vertical-axis", vaxis,
844 gtk_container_add (GTK_CONTAINER (de->sheet_bin[i]), de->data_sheet[i]);
846 g_signal_connect (de->data_sheet[i], "traverse",
847 G_CALLBACK (traverse_cell_callback), de);
849 gtk_widget_show (de->sheet_bin[i]);
854 init_data_sheet (PsppireDataEditor *de)
856 GtkAdjustment *vadj0, *hadj0;
857 GtkAdjustment *vadj1, *hadj1;
860 de->vaxis[0] = psppire_axis_new ();
861 de->vaxis[1] = psppire_axis_new ();
863 /* There's only one horizontal axis, since the
864 column widths are parameters of the variables */
865 de->haxis = psppire_axis_new ();
868 de->paned = gtk_xpaned_new ();
870 init_sheet (de, 0, NULL, NULL, de->vaxis[0], de->haxis);
871 gtk_widget_show (de->sheet_bin[0]);
872 vadj0 = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[0]));
873 hadj0 = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[0]));
875 g_object_set (de->sheet_bin[0], "vscrollbar-policy", GTK_POLICY_NEVER, NULL);
876 g_object_set (de->sheet_bin[0], "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
878 init_sheet (de, 1, NULL, vadj0, de->vaxis[0], de->haxis);
879 gtk_widget_show (de->sheet_bin[1]);
880 sheet = gtk_bin_get_child (GTK_BIN (de->sheet_bin[1]));
881 psppire_sheet_hide_row_titles (PSPPIRE_SHEET (sheet));
882 hadj1 = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[1]));
883 g_object_set (de->sheet_bin[1], "vscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
884 g_object_set (de->sheet_bin[1], "hscrollbar-policy", GTK_POLICY_NEVER, NULL);
886 init_sheet (de, 2, hadj0, NULL, de->vaxis[1], de->haxis);
887 gtk_widget_show (de->sheet_bin[2]);
888 sheet = gtk_bin_get_child (GTK_BIN (de->sheet_bin[2]));
889 psppire_sheet_hide_column_titles (PSPPIRE_SHEET (sheet));
890 g_object_set (de->sheet_bin[2], "vscrollbar-policy", GTK_POLICY_NEVER, NULL);
891 g_object_set (de->sheet_bin[2], "hscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
892 vadj1 = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (de->sheet_bin[2]));
894 init_sheet (de, 3, hadj1, vadj1, de->vaxis[1], de->haxis);
895 gtk_widget_show (de->sheet_bin[3]);
896 sheet = gtk_bin_get_child (GTK_BIN (de->sheet_bin[3]));
897 psppire_sheet_hide_column_titles (PSPPIRE_SHEET (sheet));
898 psppire_sheet_hide_row_titles (PSPPIRE_SHEET (sheet));
899 g_object_set (de->sheet_bin[3], "vscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
900 g_object_set (de->sheet_bin[3], "hscrollbar-policy", GTK_POLICY_ALWAYS, NULL);
902 gtk_xpaned_pack_top_left (GTK_XPANED (de->paned), de->sheet_bin[0], TRUE, TRUE);
903 gtk_xpaned_pack_top_right (GTK_XPANED (de->paned), de->sheet_bin[1], TRUE, TRUE);
904 gtk_xpaned_pack_bottom_left (GTK_XPANED (de->paned), de->sheet_bin[2], TRUE, TRUE);
905 gtk_xpaned_pack_bottom_right (GTK_XPANED (de->paned), de->sheet_bin[3], TRUE, TRUE);
907 gtk_xpaned_set_position_y (GTK_XPANED (de->paned), 150);
908 gtk_xpaned_set_position_x (GTK_XPANED (de->paned), 350);
913 psppire_data_editor_init (PsppireDataEditor *de)
915 GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
916 GtkWidget *sw_vs = gtk_scrolled_window_new (NULL, NULL);
918 init_data_sheet (de);
920 de->data_vbox = gtk_vbox_new (FALSE, 0);
921 de->var_sheet = psppire_var_sheet_new ();
923 g_object_set (de, "tab-pos", GTK_POS_BOTTOM, NULL);
925 de->datum_entry = gtk_entry_new ();
926 de->cell_ref_entry = gtk_entry_new ();
928 g_object_set (de->cell_ref_entry,
934 gtk_box_pack_start (GTK_BOX (hbox), de->cell_ref_entry, FALSE, FALSE, 0);
935 gtk_box_pack_start (GTK_BOX (hbox), de->datum_entry, TRUE, TRUE, 0);
938 gtk_container_add (GTK_CONTAINER (sw_vs), de->var_sheet);
939 gtk_widget_show_all (sw_vs);
942 gtk_box_pack_start (GTK_BOX (de->data_vbox), hbox, FALSE, FALSE, 0);
943 gtk_box_pack_start (GTK_BOX (de->data_vbox), de->paned, TRUE, TRUE, 0);
946 psppire_data_editor_remove_split (de);
948 gtk_widget_show_all (de->data_vbox);
950 gtk_notebook_append_page (GTK_NOTEBOOK (de), de->data_vbox,
951 gtk_label_new_with_mnemonic (_("Data View")));
953 gtk_notebook_append_page (GTK_NOTEBOOK (de), sw_vs,
954 gtk_label_new_with_mnemonic (_("Variable View")));
956 g_signal_connect (de->data_sheet[0], "activate",
957 G_CALLBACK (update_data_ref_entry),
960 g_signal_connect (de->datum_entry, "activate",
961 G_CALLBACK (datum_entry_activate),
965 g_signal_connect_swapped (de->data_sheet[0],
966 "double-click-column",
967 G_CALLBACK (on_data_column_clicked),
970 g_signal_connect_swapped (de->var_sheet,
972 G_CALLBACK (on_var_row_clicked),
975 g_signal_connect_swapped (de->data_sheet[0], "activate",
976 G_CALLBACK (on_activate),
979 g_signal_connect_swapped (de->data_sheet[0], "select-range",
980 G_CALLBACK (on_select_range),
983 g_signal_connect (de->data_sheet[0], "select-row",
984 G_CALLBACK (on_select_row), de);
986 g_signal_connect (de->data_sheet[0], "select-column",
987 G_CALLBACK (on_select_variable), de);
990 g_signal_connect (de->var_sheet, "select-row",
991 G_CALLBACK (on_select_variable), de);
994 g_signal_connect_after (de, "switch-page",
995 G_CALLBACK (on_switch_page),
998 g_object_set (de, "can-focus", FALSE, NULL);
1000 g_signal_connect (de, "map", G_CALLBACK (on_map), NULL);
1003 // psppire_sheet_hide_column_titles (de->var_sheet);
1004 // psppire_sheet_hide_row_titles (de->data_sheet);
1007 de->dispose_has_run = FALSE;
1012 psppire_data_editor_new (PsppireVarStore *var_store,
1013 PsppireDataStore *data_store)
1015 return g_object_new (PSPPIRE_DATA_EDITOR_TYPE,
1016 "var-store", var_store,
1017 "data-store", data_store,
1023 psppire_data_editor_remove_split (PsppireDataEditor *de)
1025 if ( !de->split ) return;
1028 g_object_ref (de->sheet_bin[0]);
1029 gtk_container_remove (GTK_CONTAINER (de->paned), de->sheet_bin[0]);
1031 g_object_ref (de->paned);
1032 gtk_container_remove (GTK_CONTAINER (de->data_vbox), de->paned);
1034 gtk_box_pack_start (GTK_BOX (de->data_vbox), de->sheet_bin[0],
1037 g_object_unref (de->sheet_bin[0]);
1039 g_object_set (de->sheet_bin[0], "vscrollbar-policy",
1040 GTK_POLICY_ALWAYS, NULL);
1042 g_object_set (de->sheet_bin[0], "hscrollbar-policy",
1043 GTK_POLICY_ALWAYS, NULL);
1048 psppire_data_editor_set_split (PsppireDataEditor *de)
1050 if ( de->split ) return;
1053 g_object_ref (de->sheet_bin[0]);
1054 gtk_container_remove (GTK_CONTAINER (de->data_vbox), de->sheet_bin[0]);
1056 gtk_xpaned_pack_top_left (GTK_XPANED (de->paned), de->sheet_bin [0],
1059 gtk_box_pack_start (GTK_BOX (de->data_vbox), de->paned,
1062 g_object_unref (de->paned);
1064 g_object_set (de->sheet_bin[0], "vscrollbar-policy",
1065 GTK_POLICY_NEVER, NULL);
1067 g_object_set (de->sheet_bin[0], "hscrollbar-policy",
1068 GTK_POLICY_NEVER, NULL);
1072 psppire_data_editor_split_window (PsppireDataEditor *de, gboolean split)
1075 psppire_data_editor_set_split (de);
1077 psppire_data_editor_remove_split (de);
1079 gtk_widget_show_all (de->data_vbox);
1082 static void data_sheet_set_clip (PsppireSheet *sheet);
1083 static void data_sheet_contents_received_callback (GtkClipboard *clipboard,
1084 GtkSelectionData *sd,
1089 psppire_data_editor_clip_copy (PsppireDataEditor *de)
1091 data_sheet_set_clip (PSPPIRE_SHEET (de->data_sheet[0]));
1095 psppire_data_editor_clip_paste (PsppireDataEditor *de)
1097 GdkDisplay *display = gtk_widget_get_display ( GTK_WIDGET (de));
1098 GtkClipboard *clipboard =
1099 gtk_clipboard_get_for_display (display, GDK_SELECTION_CLIPBOARD);
1101 gtk_clipboard_request_contents (clipboard,
1102 gdk_atom_intern ("UTF8_STRING", TRUE),
1103 data_sheet_contents_received_callback,
1110 psppire_data_editor_clip_cut (PsppireDataEditor *de)
1112 gint max_rows, max_columns;
1114 PsppireSheetRange range;
1115 PsppireDataStore *ds = de->data_store;
1117 data_sheet_set_clip (PSPPIRE_SHEET (de->data_sheet[0]));
1119 /* Now blank all the cells */
1120 psppire_sheet_get_selected_range (PSPPIRE_SHEET (de->data_sheet[0]), &range);
1122 /* If nothing selected, then use active cell */
1123 if ( range.row0 < 0 || range.col0 < 0 )
1126 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &col);
1128 range.row0 = range.rowi = row;
1129 range.col0 = range.coli = col;
1132 /* The sheet range can include cells that do not include data.
1133 Exclude them from the range. */
1134 max_rows = psppire_data_store_get_case_count (ds);
1135 if (range.rowi >= max_rows)
1139 range.rowi = max_rows - 1;
1142 max_columns = dict_get_var_cnt (ds->dict->dict);
1143 if (range.coli >= max_columns)
1145 if (max_columns == 0)
1147 range.coli = max_columns - 1;
1150 g_return_if_fail (range.rowi >= range.row0);
1151 g_return_if_fail (range.row0 >= 0);
1152 g_return_if_fail (range.coli >= range.col0);
1153 g_return_if_fail (range.col0 >= 0);
1156 for (r = range.row0; r <= range.rowi ; ++r )
1160 for (c = range.col0 ; c <= range.coli; ++c)
1162 psppire_data_store_set_string (ds, "", r, c);
1166 /* and remove the selection */
1167 psppire_sheet_unselect_range (PSPPIRE_SHEET (de->data_sheet[0]));
1173 /* Popup menu related stuff */
1176 popup_variable_column_menu (PsppireSheet *sheet, gint column,
1177 GdkEventButton *event, gpointer data)
1179 GtkMenu *menu = GTK_MENU (data);
1181 PsppireDataStore *data_store =
1182 PSPPIRE_DATA_STORE (psppire_sheet_get_model (sheet));
1184 const struct variable *v =
1185 psppire_dict_get_variable (data_store->dict, column);
1187 if ( v && event->button == 3)
1189 psppire_sheet_select_column (sheet, column);
1191 gtk_menu_popup (menu,
1192 NULL, NULL, NULL, NULL,
1193 event->button, event->time);
1199 popup_variable_row_menu (PsppireSheet *sheet, gint row,
1200 GdkEventButton *event, gpointer data)
1202 GtkMenu *menu = GTK_MENU (data);
1204 PsppireVarStore *var_store =
1205 PSPPIRE_VAR_STORE (psppire_sheet_get_model (sheet));
1208 const struct variable *v ;
1210 g_object_get (var_store, "dictionary", &dict, NULL);
1212 v = psppire_dict_get_variable (dict, row);
1214 if ( v && event->button == 3)
1216 psppire_sheet_select_row (sheet, row);
1218 gtk_menu_popup (menu,
1219 NULL, NULL, NULL, NULL,
1220 event->button, event->time);
1226 popup_cases_menu (PsppireSheet *sheet, gint row,
1227 GdkEventButton *event, gpointer data)
1229 GtkMenu *menu = GTK_MENU (data);
1231 PsppireDataStore *data_store =
1232 PSPPIRE_DATA_STORE (psppire_sheet_get_model (sheet));
1234 if ( row <= psppire_data_store_get_case_count (data_store) &&
1237 psppire_sheet_select_row (sheet, row);
1239 gtk_menu_popup (menu,
1240 NULL, NULL, NULL, NULL,
1241 event->button, event->time);
1250 do_sort (PsppireDataStore *ds, int var, gboolean descend)
1252 GString *string = g_string_new ("SORT CASES BY ");
1254 const struct variable *v =
1255 psppire_dict_get_variable (ds->dict, var);
1257 g_string_append_printf (string, "%s", var_get_name (v));
1260 g_string_append (string, " (D)");
1262 g_string_append (string, ".");
1264 execute_syntax (create_syntax_string_source (string->str));
1266 g_string_free (string, TRUE);
1270 /* Sort the data by the the variable which the editor has currently
1273 psppire_data_editor_sort_ascending (PsppireDataEditor *de)
1275 PsppireSheetRange range;
1276 psppire_sheet_get_selected_range (PSPPIRE_SHEET(de->data_sheet[0]), &range);
1278 do_sort (de->data_store, range.col0, FALSE);
1282 /* Sort the data by the the variable which the editor has currently
1285 psppire_data_editor_sort_descending (PsppireDataEditor *de)
1287 PsppireSheetRange range;
1288 psppire_sheet_get_selected_range (PSPPIRE_SHEET(de->data_sheet[0]), &range);
1290 do_sort (de->data_store, range.col0, TRUE);
1297 /* Insert a new variable before the currently selected position */
1299 psppire_data_editor_insert_variable (PsppireDataEditor *de)
1303 switch (gtk_notebook_get_current_page (GTK_NOTEBOOK (de)))
1305 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
1306 if ( PSPPIRE_SHEET (de->data_sheet[0])->select_status
1307 == PSPPIRE_SHEET_COLUMN_SELECTED )
1308 posn = PSPPIRE_SHEET (de->data_sheet[0])->range.col0;
1310 posn = PSPPIRE_SHEET (de->data_sheet[0])->active_cell.col;
1312 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
1313 if ( PSPPIRE_SHEET (de->var_sheet)->select_status
1314 == PSPPIRE_SHEET_ROW_SELECTED )
1315 posn = PSPPIRE_SHEET (de->var_sheet)->range.row0;
1317 posn = PSPPIRE_SHEET (de->var_sheet)->active_cell.row;
1320 g_assert_not_reached ();
1324 psppire_dict_insert_variable (de->data_store->dict, posn, NULL);
1327 /* Insert a new case before the currently selected position */
1329 psppire_data_editor_insert_case (PsppireDataEditor *de)
1333 if ( PSPPIRE_SHEET (de->data_sheet[0])->select_status == PSPPIRE_SHEET_ROW_SELECTED )
1335 posn = PSPPIRE_SHEET (de->data_sheet[0])->range.row0;
1339 posn = PSPPIRE_SHEET (de->data_sheet[0])->active_cell.row;
1342 if ( posn == -1 ) posn = 0;
1344 psppire_data_store_insert_new_case (de->data_store, posn);
1347 /* Delete the cases currently selected in the data sheet */
1349 psppire_data_editor_delete_cases (PsppireDataEditor *de)
1351 gint first = PSPPIRE_SHEET (de->data_sheet[0])->range.row0;
1352 gint n = PSPPIRE_SHEET (de->data_sheet[0])->range.rowi - first + 1;
1354 psppire_data_store_delete_cases (de->data_store, first, n);
1356 psppire_sheet_unselect_range (PSPPIRE_SHEET (de->data_sheet[0]));
1359 /* Delete the variables currently selected in the
1360 datasheet or variable sheet */
1362 psppire_data_editor_delete_variables (PsppireDataEditor *de)
1364 PsppireDict *dict = NULL;
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 g_object_get (de->var_store, "dictionary", &dict, NULL);
1384 psppire_dict_delete_variables (dict, first, n);
1386 psppire_sheet_unselect_range (PSPPIRE_SHEET (de->data_sheet[0]));
1387 psppire_sheet_unselect_range (PSPPIRE_SHEET (de->var_sheet));
1392 psppire_data_editor_show_grid (PsppireDataEditor *de, gboolean grid_visible)
1394 psppire_sheet_show_grid (PSPPIRE_SHEET (de->var_sheet), grid_visible);
1395 psppire_sheet_show_grid (PSPPIRE_SHEET (de->data_sheet[0]), grid_visible);
1400 set_font (GtkWidget *w, gpointer data)
1402 PangoFontDescription *font_desc = data;
1403 GtkRcStyle *style = gtk_widget_get_modifier_style (w);
1405 pango_font_description_free (style->font_desc);
1406 style->font_desc = pango_font_description_copy (font_desc);
1408 gtk_widget_modify_style (w, style);
1410 if ( GTK_IS_CONTAINER (w))
1411 gtk_container_foreach (GTK_CONTAINER (w), set_font, font_desc);
1415 psppire_data_editor_set_font (PsppireDataEditor *de, PangoFontDescription *font_desc)
1417 set_font (GTK_WIDGET (de), font_desc);
1418 gtk_container_foreach (GTK_CONTAINER (de), set_font, font_desc);
1426 emit_selected_signal (PsppireDataEditor *de)
1428 gboolean data_selected = data_is_selected (de);
1430 g_signal_emit (de, data_editor_signals[DATA_SELECTION_CHANGED], 0, data_selected);
1435 on_activate (PsppireDataEditor *de)
1438 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &col);
1441 if ( row < psppire_data_store_get_case_count (de->data_store)
1443 col < psppire_var_store_get_var_cnt (de->var_store))
1445 emit_selected_signal (de);
1449 emit_selected_signal (de);
1454 on_select_range (PsppireDataEditor *de)
1456 PsppireSheetRange range;
1458 psppire_sheet_get_selected_range (PSPPIRE_SHEET (de->data_sheet[0]), &range);
1460 if ( range.rowi < psppire_data_store_get_case_count (de->data_store)
1462 range.coli < psppire_var_store_get_var_cnt (de->var_store))
1464 emit_selected_signal (de);
1468 emit_selected_signal (de);
1473 on_switch_page (PsppireDataEditor *de, GtkNotebookPage *p,
1474 gint pagenum, gpointer data)
1478 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
1479 gtk_widget_grab_focus (de->data_vbox);
1480 on_select_range (de);
1482 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
1483 gtk_widget_grab_focus (de->var_sheet);
1484 emit_selected_signal (de);
1496 data_is_selected (PsppireDataEditor *de)
1498 PsppireSheetRange range;
1501 if ( gtk_notebook_get_current_page (GTK_NOTEBOOK (de)) != PSPPIRE_DATA_EDITOR_DATA_VIEW)
1504 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &col);
1506 if ( row >= psppire_data_store_get_case_count (de->data_store)
1508 col >= psppire_var_store_get_var_cnt (de->var_store))
1513 psppire_sheet_get_selected_range (PSPPIRE_SHEET (de->data_sheet[0]), &range);
1515 if ( range.rowi >= psppire_data_store_get_case_count (de->data_store)
1517 range.coli >= psppire_var_store_get_var_cnt (de->var_store))
1527 on_select_row (PsppireSheet *sheet, gint row, PsppireDataEditor *de)
1529 g_signal_emit (de, data_editor_signals[CASES_SELECTED], 0, row);
1534 on_select_variable (PsppireSheet *sheet, gint var, PsppireDataEditor *de)
1536 g_signal_emit (de, data_editor_signals[VARIABLES_SELECTED], 0, var);
1542 /* Clipboard stuff */
1545 #include <data/casereader.h>
1546 #include <data/case-map.h>
1547 #include <data/casewriter.h>
1549 #include <data/data-out.h>
1552 /* A casereader and dictionary holding the data currently in the clip */
1553 static struct casereader *clip_datasheet = NULL;
1554 static struct dictionary *clip_dict = NULL;
1557 static void data_sheet_update_clipboard (PsppireSheet *);
1559 /* Set the clip according to the currently
1560 selected range in the data sheet */
1562 data_sheet_set_clip (PsppireSheet *sheet)
1565 struct casewriter *writer ;
1566 PsppireSheetRange range;
1567 PsppireDataStore *ds;
1568 struct case_map *map = NULL;
1569 casenumber max_rows;
1574 ds = PSPPIRE_DATA_STORE (psppire_sheet_get_model (sheet));
1576 psppire_sheet_get_selected_range (sheet, &range);
1578 col0 = MIN (range.col0, range.coli);
1579 coli = MAX (range.col0, range.coli);
1580 row0 = MIN (range.row0, range.rowi);
1581 rowi = MAX (range.row0, range.rowi);
1583 /* If nothing selected, then use active cell */
1584 if ( row0 < 0 || col0 < 0 )
1587 psppire_sheet_get_active_cell (sheet, &row, &col);
1593 /* The sheet range can include cells that do not include data.
1594 Exclude them from the range. */
1595 max_rows = psppire_data_store_get_case_count (ds);
1596 if (rowi >= max_rows)
1600 rowi = max_rows - 1;
1602 max_columns = dict_get_var_cnt (ds->dict->dict);
1603 if (coli >= max_columns)
1605 if (max_columns == 0)
1607 coli = max_columns - 1;
1610 /* Destroy any existing clip */
1611 if ( clip_datasheet )
1613 casereader_destroy (clip_datasheet);
1614 clip_datasheet = NULL;
1619 dict_destroy (clip_dict);
1623 /* Construct clip dictionary. */
1624 clip_dict = dict_create ();
1625 dict_set_encoding (clip_dict, dict_get_encoding (ds->dict->dict));
1626 for (i = col0; i <= coli; i++)
1627 dict_clone_var_assert (clip_dict, dict_get_var (ds->dict->dict, i));
1629 /* Construct clip data. */
1630 map = case_map_by_name (ds->dict->dict, clip_dict);
1631 writer = autopaging_writer_create (dict_get_proto (clip_dict));
1632 for (i = row0; i <= rowi ; ++i )
1634 struct ccase *old = psppire_data_store_get_case (ds, i);
1636 casewriter_write (writer, case_map_execute (map, old));
1638 casewriter_force_error (writer);
1640 case_map_destroy (map);
1642 clip_datasheet = casewriter_make_reader (writer);
1644 data_sheet_update_clipboard (sheet);
1654 /* Perform data_out for case CC, variable V, appending to STRING */
1656 data_out_g_string (GString *string, const struct variable *v,
1657 const struct ccase *cc)
1659 const struct fmt_spec *fs = var_get_print_format (v);
1660 const union value *val = case_data (cc, v);
1662 char *s = data_out (val, var_get_encoding (v), fs);
1664 g_string_append (string, s);
1675 const size_t val_cnt = caseproto_get_n_widths (casereader_get_proto (clip_datasheet));
1676 const casenumber case_cnt = casereader_get_case_cnt (clip_datasheet);
1677 const size_t var_cnt = dict_get_var_cnt (clip_dict);
1679 string = g_string_sized_new (10 * val_cnt * case_cnt);
1681 for (r = 0 ; r < case_cnt ; ++r )
1686 cc = casereader_peek (clip_datasheet, r);
1689 g_warning ("Clipboard seems to have inexplicably shrunk");
1693 for (c = 0 ; c < var_cnt ; ++c)
1695 const struct variable *v = dict_get_var (clip_dict, c);
1696 data_out_g_string (string, v, cc);
1697 if ( c < val_cnt - 1 )
1698 g_string_append (string, "\t");
1702 g_string_append (string, "\n");
1717 const size_t val_cnt = caseproto_get_n_widths (casereader_get_proto (clip_datasheet));
1718 const casenumber case_cnt = casereader_get_case_cnt (clip_datasheet);
1719 const size_t var_cnt = dict_get_var_cnt (clip_dict);
1721 /* Guestimate the size needed */
1722 string = g_string_sized_new (80 + 20 * val_cnt * case_cnt);
1724 g_string_append (string,
1725 "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n");
1727 g_string_append (string, "<table>\n");
1728 for (r = 0 ; r < case_cnt ; ++r )
1731 struct ccase *cc = casereader_peek (clip_datasheet, r);
1734 g_warning ("Clipboard seems to have inexplicably shrunk");
1737 g_string_append (string, "<tr>\n");
1739 for (c = 0 ; c < var_cnt ; ++c)
1741 const struct variable *v = dict_get_var (clip_dict, c);
1742 g_string_append (string, "<td>");
1743 data_out_g_string (string, v, cc);
1744 g_string_append (string, "</td>\n");
1747 g_string_append (string, "</tr>\n");
1751 g_string_append (string, "</table>\n");
1759 clipboard_get_cb (GtkClipboard *clipboard,
1760 GtkSelectionData *selection_data,
1764 GString *string = NULL;
1768 case SELECT_FMT_TEXT:
1769 string = clip_to_text ();
1771 case SELECT_FMT_HTML:
1772 string = clip_to_html ();
1775 g_assert_not_reached ();
1778 gtk_selection_data_set (selection_data, selection_data->target,
1780 (const guchar *) string->str, string->len);
1782 g_string_free (string, TRUE);
1786 clipboard_clear_cb (GtkClipboard *clipboard,
1789 dict_destroy (clip_dict);
1792 casereader_destroy (clip_datasheet);
1793 clip_datasheet = NULL;
1797 static const GtkTargetEntry targets[] = {
1798 { "UTF8_STRING", 0, SELECT_FMT_TEXT },
1799 { "STRING", 0, SELECT_FMT_TEXT },
1800 { "TEXT", 0, SELECT_FMT_TEXT },
1801 { "COMPOUND_TEXT", 0, SELECT_FMT_TEXT },
1802 { "text/plain;charset=utf-8", 0, SELECT_FMT_TEXT },
1803 { "text/plain", 0, SELECT_FMT_TEXT },
1804 { "text/html", 0, SELECT_FMT_HTML }
1810 data_sheet_update_clipboard (PsppireSheet *sheet)
1812 GtkClipboard *clipboard =
1813 gtk_widget_get_clipboard (GTK_WIDGET (sheet),
1814 GDK_SELECTION_CLIPBOARD);
1816 if (!gtk_clipboard_set_with_owner (clipboard, targets,
1817 G_N_ELEMENTS (targets),
1818 clipboard_get_cb, clipboard_clear_cb,
1820 clipboard_clear_cb (clipboard, sheet);
1825 /* A callback for when the clipboard contents have been received */
1827 data_sheet_contents_received_callback (GtkClipboard *clipboard,
1828 GtkSelectionData *sd,
1833 gint next_row, next_column;
1836 PsppireDataEditor *data_editor = data;
1838 if ( sd->length < 0 )
1841 if ( sd->type != gdk_atom_intern ("UTF8_STRING", FALSE))
1844 c = (char *) sd->data;
1846 /* Paste text to selected position */
1847 psppire_sheet_get_active_cell (PSPPIRE_SHEET (data_editor->data_sheet[0]),
1850 g_return_if_fail (row >= 0);
1851 g_return_if_fail (column >= 0);
1853 first_column = column;
1855 next_column = column;
1856 while (count < sd->length)
1861 column = next_column;
1862 while (*c != '\t' && *c != '\n' && count < sd->length)
1870 next_column = column + 1;
1872 else if ( *c == '\n')
1875 next_column = first_column;
1881 /* Append some new cases if pasting beyond the last row */
1882 if ( row >= psppire_data_store_get_case_count (data_editor->data_store))
1883 psppire_data_store_insert_new_case (data_editor->data_store, row);
1885 psppire_data_store_set_string (data_editor->data_store, s, row, column);
1891 on_owner_change (GtkClipboard *clip, GdkEventOwnerChange *event, gpointer data)
1894 gboolean compatible_target = FALSE;
1895 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
1897 for (i = 0 ; i < sizeof (targets) / sizeof(targets[0]) ; ++i )
1899 GdkAtom atom = gdk_atom_intern (targets[i].target, TRUE);
1900 if ( gtk_clipboard_wait_is_target_available (clip, atom))
1902 compatible_target = TRUE;
1907 g_signal_emit (de, data_editor_signals[DATA_AVAILABLE_CHANGED], 0,