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,
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));
1207 const struct variable *v =
1208 psppire_dict_get_variable (var_store->dict, row);
1210 if ( v && event->button == 3)
1212 psppire_sheet_select_row (sheet, row);
1214 gtk_menu_popup (menu,
1215 NULL, NULL, NULL, NULL,
1216 event->button, event->time);
1222 popup_cases_menu (PsppireSheet *sheet, gint row,
1223 GdkEventButton *event, gpointer data)
1225 GtkMenu *menu = GTK_MENU (data);
1227 PsppireDataStore *data_store =
1228 PSPPIRE_DATA_STORE (psppire_sheet_get_model (sheet));
1230 if ( row <= psppire_data_store_get_case_count (data_store) &&
1233 psppire_sheet_select_row (sheet, row);
1235 gtk_menu_popup (menu,
1236 NULL, NULL, NULL, NULL,
1237 event->button, event->time);
1246 do_sort (PsppireDataStore *ds, int var, gboolean descend)
1248 GString *string = g_string_new ("SORT CASES BY ");
1250 const struct variable *v =
1251 psppire_dict_get_variable (ds->dict, var);
1253 g_string_append_printf (string, "%s", var_get_name (v));
1256 g_string_append (string, " (D)");
1258 g_string_append (string, ".");
1260 execute_syntax (create_syntax_string_source (string->str));
1262 g_string_free (string, TRUE);
1266 /* Sort the data by the the variable which the editor has currently
1269 psppire_data_editor_sort_ascending (PsppireDataEditor *de)
1271 PsppireSheetRange range;
1272 psppire_sheet_get_selected_range (PSPPIRE_SHEET(de->data_sheet[0]), &range);
1274 do_sort (de->data_store, range.col0, FALSE);
1278 /* Sort the data by the the variable which the editor has currently
1281 psppire_data_editor_sort_descending (PsppireDataEditor *de)
1283 PsppireSheetRange range;
1284 psppire_sheet_get_selected_range (PSPPIRE_SHEET(de->data_sheet[0]), &range);
1286 do_sort (de->data_store, range.col0, TRUE);
1293 /* Insert a new variable before the currently selected position */
1295 psppire_data_editor_insert_variable (PsppireDataEditor *de)
1299 switch (gtk_notebook_get_current_page (GTK_NOTEBOOK (de)))
1301 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
1302 if ( PSPPIRE_SHEET (de->data_sheet[0])->select_status
1303 == PSPPIRE_SHEET_COLUMN_SELECTED )
1304 posn = PSPPIRE_SHEET (de->data_sheet[0])->range.col0;
1306 posn = PSPPIRE_SHEET (de->data_sheet[0])->active_cell.col;
1308 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
1309 if ( PSPPIRE_SHEET (de->var_sheet)->select_status
1310 == PSPPIRE_SHEET_ROW_SELECTED )
1311 posn = PSPPIRE_SHEET (de->var_sheet)->range.row0;
1313 posn = PSPPIRE_SHEET (de->var_sheet)->active_cell.row;
1316 g_assert_not_reached ();
1320 psppire_dict_insert_variable (de->data_store->dict, posn, NULL);
1323 /* Insert a new case before the currently selected position */
1325 psppire_data_editor_insert_case (PsppireDataEditor *de)
1329 if ( PSPPIRE_SHEET (de->data_sheet[0])->select_status == PSPPIRE_SHEET_ROW_SELECTED )
1331 posn = PSPPIRE_SHEET (de->data_sheet[0])->range.row0;
1335 posn = PSPPIRE_SHEET (de->data_sheet[0])->active_cell.row;
1338 if ( posn == -1 ) posn = 0;
1340 psppire_data_store_insert_new_case (de->data_store, posn);
1343 /* Delete the cases currently selected in the data sheet */
1345 psppire_data_editor_delete_cases (PsppireDataEditor *de)
1347 gint first = PSPPIRE_SHEET (de->data_sheet[0])->range.row0;
1348 gint n = PSPPIRE_SHEET (de->data_sheet[0])->range.rowi - first + 1;
1350 psppire_data_store_delete_cases (de->data_store, first, n);
1352 psppire_sheet_unselect_range (PSPPIRE_SHEET (de->data_sheet[0]));
1355 /* Delete the variables currently selected in the
1356 datasheet or variable sheet */
1358 psppire_data_editor_delete_variables (PsppireDataEditor *de)
1362 switch (gtk_notebook_get_current_page (GTK_NOTEBOOK (de)))
1364 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
1365 first = PSPPIRE_SHEET (de->data_sheet[0])->range.col0;
1366 n = PSPPIRE_SHEET (de->data_sheet[0])->range.coli - first + 1;
1368 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
1369 first = PSPPIRE_SHEET (de->var_sheet)->range.row0;
1370 n = PSPPIRE_SHEET (de->var_sheet)->range.rowi - first + 1;
1373 g_assert_not_reached ();
1377 psppire_dict_delete_variables (de->var_store->dict, first, n);
1379 psppire_sheet_unselect_range (PSPPIRE_SHEET (de->data_sheet[0]));
1380 psppire_sheet_unselect_range (PSPPIRE_SHEET (de->var_sheet));
1385 psppire_data_editor_show_grid (PsppireDataEditor *de, gboolean grid_visible)
1387 psppire_sheet_show_grid (PSPPIRE_SHEET (de->var_sheet), grid_visible);
1388 psppire_sheet_show_grid (PSPPIRE_SHEET (de->data_sheet[0]), grid_visible);
1393 set_font (GtkWidget *w, gpointer data)
1395 PangoFontDescription *font_desc = data;
1396 GtkRcStyle *style = gtk_widget_get_modifier_style (w);
1398 pango_font_description_free (style->font_desc);
1399 style->font_desc = pango_font_description_copy (font_desc);
1401 gtk_widget_modify_style (w, style);
1403 if ( GTK_IS_CONTAINER (w))
1404 gtk_container_foreach (GTK_CONTAINER (w), set_font, font_desc);
1408 psppire_data_editor_set_font (PsppireDataEditor *de, PangoFontDescription *font_desc)
1410 set_font (GTK_WIDGET (de), font_desc);
1411 gtk_container_foreach (GTK_CONTAINER (de), set_font, font_desc);
1419 emit_selected_signal (PsppireDataEditor *de)
1421 gboolean data_selected = data_is_selected (de);
1423 g_signal_emit (de, data_editor_signals[DATA_SELECTION_CHANGED], 0, data_selected);
1428 on_activate (PsppireDataEditor *de)
1431 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &col);
1434 if ( row < psppire_data_store_get_case_count (de->data_store)
1436 col < psppire_var_store_get_var_cnt (de->var_store))
1438 emit_selected_signal (de);
1442 emit_selected_signal (de);
1447 on_select_range (PsppireDataEditor *de)
1449 PsppireSheetRange range;
1451 psppire_sheet_get_selected_range (PSPPIRE_SHEET (de->data_sheet[0]), &range);
1453 if ( range.rowi < psppire_data_store_get_case_count (de->data_store)
1455 range.coli < psppire_var_store_get_var_cnt (de->var_store))
1457 emit_selected_signal (de);
1461 emit_selected_signal (de);
1466 on_switch_page (PsppireDataEditor *de, GtkNotebookPage *p,
1467 gint pagenum, gpointer data)
1471 case PSPPIRE_DATA_EDITOR_DATA_VIEW:
1472 gtk_widget_grab_focus (de->data_vbox);
1473 on_select_range (de);
1475 case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW:
1476 gtk_widget_grab_focus (de->var_sheet);
1477 emit_selected_signal (de);
1489 data_is_selected (PsppireDataEditor *de)
1491 PsppireSheetRange range;
1494 if ( gtk_notebook_get_current_page (GTK_NOTEBOOK (de)) != PSPPIRE_DATA_EDITOR_DATA_VIEW)
1497 psppire_sheet_get_active_cell (PSPPIRE_SHEET (de->data_sheet[0]), &row, &col);
1499 if ( row >= psppire_data_store_get_case_count (de->data_store)
1501 col >= psppire_var_store_get_var_cnt (de->var_store))
1506 psppire_sheet_get_selected_range (PSPPIRE_SHEET (de->data_sheet[0]), &range);
1508 if ( range.rowi >= psppire_data_store_get_case_count (de->data_store)
1510 range.coli >= psppire_var_store_get_var_cnt (de->var_store))
1520 on_select_row (PsppireSheet *sheet, gint row, PsppireDataEditor *de)
1522 g_signal_emit (de, data_editor_signals[CASES_SELECTED], 0, row);
1527 on_select_variable (PsppireSheet *sheet, gint var, PsppireDataEditor *de)
1529 g_signal_emit (de, data_editor_signals[VARIABLES_SELECTED], 0, var);
1535 /* Clipboard stuff */
1538 #include <data/casereader.h>
1539 #include <data/case-map.h>
1540 #include <data/casewriter.h>
1542 #include <data/data-out.h>
1545 /* A casereader and dictionary holding the data currently in the clip */
1546 static struct casereader *clip_datasheet = NULL;
1547 static struct dictionary *clip_dict = NULL;
1550 static void data_sheet_update_clipboard (PsppireSheet *);
1552 /* Set the clip according to the currently
1553 selected range in the data sheet */
1555 data_sheet_set_clip (PsppireSheet *sheet)
1558 struct casewriter *writer ;
1559 PsppireSheetRange range;
1560 PsppireDataStore *ds;
1561 struct case_map *map = NULL;
1562 casenumber max_rows;
1565 ds = PSPPIRE_DATA_STORE (psppire_sheet_get_model (sheet));
1567 psppire_sheet_get_selected_range (sheet, &range);
1569 /* If nothing selected, then use active cell */
1570 if ( range.row0 < 0 || range.col0 < 0 )
1573 psppire_sheet_get_active_cell (sheet, &row, &col);
1575 range.row0 = range.rowi = row;
1576 range.col0 = range.coli = col;
1579 /* The sheet range can include cells that do not include data.
1580 Exclude them from the range. */
1581 max_rows = psppire_data_store_get_case_count (ds);
1582 if (range.rowi >= max_rows)
1586 range.rowi = max_rows - 1;
1588 max_columns = dict_get_var_cnt (ds->dict->dict);
1589 if (range.coli >= max_columns)
1591 if (max_columns == 0)
1593 range.coli = max_columns - 1;
1596 g_return_if_fail (range.rowi >= range.row0);
1597 g_return_if_fail (range.row0 >= 0);
1598 g_return_if_fail (range.coli >= range.col0);
1599 g_return_if_fail (range.col0 >= 0);
1601 /* Destroy any existing clip */
1602 if ( clip_datasheet )
1604 casereader_destroy (clip_datasheet);
1605 clip_datasheet = NULL;
1610 dict_destroy (clip_dict);
1614 /* Construct clip dictionary. */
1615 clip_dict = dict_create ();
1616 for (i = range.col0; i <= range.coli; i++)
1618 const struct variable *old = dict_get_var (ds->dict->dict, i);
1619 dict_clone_var_assert (clip_dict, old, var_get_name (old));
1622 /* Construct clip data. */
1623 map = case_map_by_name (ds->dict->dict, clip_dict);
1624 writer = autopaging_writer_create (dict_get_proto (clip_dict));
1625 for (i = range.row0; i <= range.rowi ; ++i )
1627 struct ccase *old = psppire_data_store_get_case (ds, i);
1629 casewriter_write (writer, case_map_execute (map, old));
1631 casewriter_force_error (writer);
1633 case_map_destroy (map);
1635 clip_datasheet = casewriter_make_reader (writer);
1637 data_sheet_update_clipboard (sheet);
1647 /* Perform data_out for case CC, variable V, appending to STRING */
1649 data_out_g_string (GString *string, const struct dictionary *dict, const struct variable *v,
1650 const struct ccase *cc)
1652 const struct fmt_spec *fs = var_get_print_format (v);
1653 const union value *val = case_data (cc, v);
1655 char *s = data_out (val, dict_get_encoding (dict), fs);
1657 g_string_append_len (string, s, fs->w);
1668 const size_t val_cnt = caseproto_get_n_widths (casereader_get_proto (clip_datasheet));
1669 const casenumber case_cnt = casereader_get_case_cnt (clip_datasheet);
1670 const size_t var_cnt = dict_get_var_cnt (clip_dict);
1672 string = g_string_sized_new (10 * val_cnt * case_cnt);
1674 for (r = 0 ; r < case_cnt ; ++r )
1679 cc = casereader_peek (clip_datasheet, r);
1682 g_warning ("Clipboard seems to have inexplicably shrunk");
1686 for (c = 0 ; c < var_cnt ; ++c)
1688 const struct variable *v = dict_get_var (clip_dict, c);
1689 data_out_g_string (string, clip_dict, v, cc);
1690 if ( c < val_cnt - 1 )
1691 g_string_append (string, "\t");
1695 g_string_append (string, "\n");
1710 const size_t val_cnt = caseproto_get_n_widths (casereader_get_proto (clip_datasheet));
1711 const casenumber case_cnt = casereader_get_case_cnt (clip_datasheet);
1712 const size_t var_cnt = dict_get_var_cnt (clip_dict);
1715 /* Guestimate the size needed */
1716 string = g_string_sized_new (20 * val_cnt * case_cnt);
1718 g_string_append (string, "<table>\n");
1719 for (r = 0 ; r < case_cnt ; ++r )
1722 struct ccase *cc = casereader_peek (clip_datasheet, r);
1725 g_warning ("Clipboard seems to have inexplicably shrunk");
1728 g_string_append (string, "<tr>\n");
1730 for (c = 0 ; c < var_cnt ; ++c)
1732 const struct variable *v = dict_get_var (clip_dict, c);
1733 g_string_append (string, "<td>");
1734 data_out_g_string (string, clip_dict, v, cc);
1735 g_string_append (string, "</td>\n");
1738 g_string_append (string, "</tr>\n");
1742 g_string_append (string, "</table>\n");
1750 clipboard_get_cb (GtkClipboard *clipboard,
1751 GtkSelectionData *selection_data,
1755 GString *string = NULL;
1759 case SELECT_FMT_TEXT:
1760 string = clip_to_text ();
1762 case SELECT_FMT_HTML:
1763 string = clip_to_html ();
1766 g_assert_not_reached ();
1769 gtk_selection_data_set (selection_data, selection_data->target,
1771 (const guchar *) string->str, string->len);
1773 g_string_free (string, TRUE);
1777 clipboard_clear_cb (GtkClipboard *clipboard,
1780 dict_destroy (clip_dict);
1783 casereader_destroy (clip_datasheet);
1784 clip_datasheet = NULL;
1788 static const GtkTargetEntry targets[] = {
1789 { "UTF8_STRING", 0, SELECT_FMT_TEXT },
1790 { "STRING", 0, SELECT_FMT_TEXT },
1791 { "TEXT", 0, SELECT_FMT_TEXT },
1792 { "COMPOUND_TEXT", 0, SELECT_FMT_TEXT },
1793 { "text/plain;charset=utf-8", 0, SELECT_FMT_TEXT },
1794 { "text/plain", 0, SELECT_FMT_TEXT },
1795 { "text/html", 0, SELECT_FMT_HTML }
1801 data_sheet_update_clipboard (PsppireSheet *sheet)
1803 GtkClipboard *clipboard =
1804 gtk_widget_get_clipboard (GTK_WIDGET (sheet),
1805 GDK_SELECTION_CLIPBOARD);
1807 if (!gtk_clipboard_set_with_owner (clipboard, targets,
1808 G_N_ELEMENTS (targets),
1809 clipboard_get_cb, clipboard_clear_cb,
1811 clipboard_clear_cb (clipboard, sheet);
1816 /* A callback for when the clipboard contents have been received */
1818 data_sheet_contents_received_callback (GtkClipboard *clipboard,
1819 GtkSelectionData *sd,
1824 gint next_row, next_column;
1827 PsppireDataEditor *data_editor = data;
1829 if ( sd->length < 0 )
1832 if ( sd->type != gdk_atom_intern ("UTF8_STRING", FALSE))
1835 c = (char *) sd->data;
1837 /* Paste text to selected position */
1838 psppire_sheet_get_active_cell (PSPPIRE_SHEET (data_editor->data_sheet[0]),
1841 g_return_if_fail (row >= 0);
1842 g_return_if_fail (column >= 0);
1844 first_column = column;
1846 next_column = column;
1847 while (count < sd->length)
1852 column = next_column;
1853 while (*c != '\t' && *c != '\n' && count < sd->length)
1861 next_column = column + 1;
1863 else if ( *c == '\n')
1866 next_column = first_column;
1872 /* Append some new cases if pasting beyond the last row */
1873 if ( row >= psppire_data_store_get_case_count (data_editor->data_store))
1874 psppire_data_store_insert_new_case (data_editor->data_store, row);
1876 psppire_data_store_set_string (data_editor->data_store, s, row, column);
1882 on_owner_change (GtkClipboard *clip, GdkEventOwnerChange *event, gpointer data)
1885 gboolean compatible_target = FALSE;
1886 PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
1888 for (i = 0 ; i < sizeof (targets) / sizeof(targets[0]) ; ++i )
1890 GdkAtom atom = gdk_atom_intern (targets[i].target, TRUE);
1891 if ( gtk_clipboard_wait_is_target_available (clip, atom))
1893 compatible_target = TRUE;
1898 g_signal_emit (de, data_editor_signals[DATA_AVAILABLE_CHANGED], 0,