From da6ac7ebe47553c89c7d06592770a49fa11b3a32 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 5 May 2017 15:21:00 +0200 Subject: [PATCH] New module: psppire_data_sheet.c --- src/ui/gui/automake.mk | 12 +- src/ui/gui/psppire-data-editor.c | 277 +--------------------- src/ui/gui/psppire-data-editor.h | 10 - src/ui/gui/psppire-data-sheet.c | 384 +++++++++++++++++++++++++++++++ src/ui/gui/psppire-data-sheet.h | 50 ++++ 5 files changed, 445 insertions(+), 288 deletions(-) create mode 100644 src/ui/gui/psppire-data-sheet.c create mode 100644 src/ui/gui/psppire-data-sheet.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 1b01c069ef..224ef749fb 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -71,11 +71,11 @@ EXTRA_DIST += \ src_ui_gui_psppire_CPPFLAGS= if HAVE_GUI -bin_PROGRAMS += src/ui/gui/psppire -noinst_PROGRAMS += src/ui/gui/spreadsheet-test +bin_PROGRAMS += src/ui/gui/psppire +noinst_PROGRAMS += src/ui/gui/spreadsheet-test -src_ui_gui_psppire_CFLAGS = $(GTK_CFLAGS) $(GTKSOURCEVIEW_CFLAGS) -Wall -DGDK_MULTIHEAD_SAFE=1 -src_ui_gui_spreadsheet_test_CFLAGS = $(GTK_CFLAGS) -Wall -DGDK_MULTIHEAD_SAFE=1 +src_ui_gui_psppire_CFLAGS = $(GTK_CFLAGS) $(GTKSOURCEVIEW_CFLAGS) -Wall -DGDK_MULTIHEAD_SAFE=1 +src_ui_gui_spreadsheet_test_CFLAGS = $(GTK_CFLAGS) -Wall -DGDK_MULTIHEAD_SAFE=1 src_ui_gui_psppire_LDFLAGS = \ @@ -293,6 +293,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-value-entry.h \ src/ui/gui/psppire-var-ptr.c \ src/ui/gui/psppire-var-ptr.h \ + src/ui/gui/psppire-data-sheet.c \ + src/ui/gui/psppire-data-sheet.h \ src/ui/gui/psppire-variable-sheet.c \ src/ui/gui/psppire-variable-sheet.h \ src/ui/gui/psppire-var-sheet-header.h \ @@ -385,7 +387,7 @@ dist_appdata_DATA = src/ui/gui/pspp.appdata.xml BUILT_SOURCES += src/ui/gui/psppire-marshal.c src/ui/gui/psppire-marshal.h src/ui/gui/resources.c CLEANFILES += src/ui/gui/psppire-marshal.c src/ui/gui/psppire-marshal.h \ - src/ui/gui/resources.c $(nodist_src_ui_gui_psppire_DATA) + src/ui/gui/resources.c $(nodist_src_ui_gui_psppire_DATA) include $(top_srcdir)/src/ui/gui/efficient-sheet.mk endif HAVE_GUI diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 2bdf3d6b78..13cd902de8 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -26,7 +26,7 @@ #include "data/value-labels.h" #include "libpspp/range-set.h" #include "libpspp/str.h" -#include "ui/gui/executor.h" + #include "ui/gui/helper.h" #include "ui/gui/var-display.h" #include "ui/gui/val-labs-dialog.h" @@ -38,8 +38,7 @@ #include "ui/gui/psppire-value-entry.h" #include "ui/gui/psppire-conf.h" #include "ui/gui/psppire-variable-sheet.h" - -#include "value-variant.h" +#include "ui/gui/psppire-data-sheet.h" #include "ui/gui/efficient-sheet/jmd-sheet.h" @@ -122,24 +121,6 @@ psppire_data_editor_refresh_model (PsppireDataEditor *de) { } -static void -change_data_value (PsppireDataStore *store, gint col, gint row, GValue *value) -{ - const struct variable *var = psppire_dict_get_variable (store->dict, col); - - if (NULL == var) - return; - - union value v; - - GVariant *vrnt = g_value_get_variant (value); - - value_variant_get (&v, vrnt); - - psppire_data_store_set_value (store, row, var, &v); - - value_destroy_from_variant (&v, vrnt); -} static void psppire_data_editor_set_property (GObject *object, @@ -175,9 +156,6 @@ psppire_data_editor_set_property (GObject *object, G_CALLBACK (refresh_entry), de); - g_signal_connect_swapped (de->data_sheet, "value-changed", - G_CALLBACK (change_data_value), de->data_store); - g_signal_connect_swapped (de->data_store, "case-changed", G_CALLBACK (refresh_entry), de); @@ -413,83 +391,7 @@ on_data_selection_change (PsppireDataEditor *de, JmdRange *sel) static void set_font_recursively (GtkWidget *w, gpointer data); -gboolean myreversefunc (GtkTreeModel *model, gint col, gint row, const gchar *in, - GValue *out); - - -enum sort_order - { - SORT_ASCEND, - SORT_DESCEND - }; - -static void -do_sort (PsppireDataEditor *de, enum sort_order order) -{ - JmdRange *range = JMD_SHEET(de->data_sheet)->selection; - - int n_vars = 0; - int i; - - PsppireDataWindow *pdw = - psppire_data_window_for_data_store (de->data_store); - - GString *syntax = g_string_new ("SORT CASES BY"); - for (i = range->start_x ; i <= range->end_x; ++i) - { - const struct variable *var = psppire_dict_get_variable (de->dict, i); - if (var != NULL) - { - g_string_append_printf (syntax, " %s", var_get_name (var)); - n_vars++; - } - } - if (n_vars > 0) - { - if (order == SORT_DESCEND) - g_string_append (syntax, " (DOWN)"); - g_string_append_c (syntax, '.'); - execute_const_syntax_string (pdw, syntax->str); - } - g_string_free (syntax, TRUE); -} - - -static void -sort_ascending (PsppireDataEditor *de) -{ - do_sort (de, SORT_ASCEND); - - gtk_widget_queue_draw (GTK_WIDGET (de)); -} - -static void -sort_descending (PsppireDataEditor *de) -{ - do_sort (de, SORT_DESCEND); - - gtk_widget_queue_draw (GTK_WIDGET (de)); -} - -static void -delete_cases (PsppireDataEditor *de) -{ - JmdRange *range = JMD_SHEET(de->data_sheet)->selection; - - psppire_data_store_delete_cases (de->data_store, range->start_y, - range->end_y - range->start_y + 1); - - gtk_widget_queue_draw (GTK_WIDGET (de)); -} - -static void -insert_new_case (PsppireDataEditor *de) -{ - gint posn = GPOINTER_TO_INT (g_object_get_data - (G_OBJECT (de->data_sheet_cases_row_popup), "item")); - - psppire_data_editor_insert_new_case_at_posn (de, posn); -} + void psppire_data_editor_data_delete_variables (PsppireDataEditor *de) @@ -531,160 +433,6 @@ psppire_data_editor_insert_new_variable_at_posn (PsppireDataEditor *de, gint pos gtk_widget_queue_draw (GTK_WIDGET (de)); } -static GtkWidget * -create_data_row_header_popup_menu (PsppireDataEditor *de) -{ - GtkWidget *menu = gtk_menu_new (); - - GtkWidget *item = - gtk_menu_item_new_with_mnemonic (_("_Insert Case")); - - g_signal_connect_swapped (item, "activate", G_CALLBACK (insert_new_case), de); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - item = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - de->data_clear_cases_menu_item = gtk_menu_item_new_with_mnemonic (_("Cl_ear Cases")); - gtk_widget_set_sensitive (de->data_clear_cases_menu_item, FALSE); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), de->data_clear_cases_menu_item); - g_signal_connect_swapped (de->data_clear_cases_menu_item, "activate", - G_CALLBACK (delete_cases), de); - - gtk_widget_show_all (menu); - return menu; -} - -static void -insert_new_variable_data (PsppireDataEditor *de) -{ - gint posn = GPOINTER_TO_INT (g_object_get_data - (G_OBJECT (de->data_sheet_cases_column_popup), - "item")); - - psppire_data_editor_insert_new_variable_at_posn (de, posn); -} - -static GtkWidget * -create_data_column_header_popup_menu (PsppireDataEditor *de) -{ - GtkWidget *menu = gtk_menu_new (); - - GtkWidget *item = - gtk_menu_item_new_with_mnemonic (_("_Insert Variable")); - g_signal_connect_swapped (item, "activate", G_CALLBACK (insert_new_variable_data), - de); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - item = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - de->data_clear_variables_menu_item = - gtk_menu_item_new_with_mnemonic (_("Cl_ear Variables")); - g_signal_connect_swapped (de->data_clear_variables_menu_item, "activate", - G_CALLBACK (psppire_data_editor_data_delete_variables), - de); - gtk_widget_set_sensitive (de->data_clear_variables_menu_item, FALSE); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), de->data_clear_variables_menu_item); - - item = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - de->data_sort_ascending_menu_item = - gtk_menu_item_new_with_mnemonic (_("Sort _Ascending")); - g_signal_connect_swapped (de->data_sort_ascending_menu_item, "activate", - G_CALLBACK (sort_ascending), de); - gtk_widget_set_sensitive (de->data_sort_ascending_menu_item, FALSE); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), de->data_sort_ascending_menu_item); - - de->data_sort_descending_menu_item = - gtk_menu_item_new_with_mnemonic (_("Sort _Descending")); - g_signal_connect_swapped (de->data_sort_descending_menu_item, "activate", - G_CALLBACK (sort_descending), de); - gtk_widget_set_sensitive (de->data_sort_descending_menu_item, FALSE); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), de->data_sort_descending_menu_item); - - gtk_widget_show_all (menu); - return menu; -} - -static void -set_menu_items_sensitivity (JmdSheet *sheet, gpointer selection, gpointer p) -{ - JmdRange *range = selection; - PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (p); - gint width = gtk_tree_model_get_n_columns (sheet->data_model); - gint length = psppire_data_store_get_case_count (de->data_store); - - - gboolean whole_row_selected = (range->start_x == 0 && range->end_x == width - 1); - gtk_widget_set_sensitive (de->data_clear_cases_menu_item, whole_row_selected); - - - gboolean whole_column_selected = - (range->start_y == 0 && range->end_y == length - 1); - gtk_widget_set_sensitive (de->data_clear_variables_menu_item, - whole_column_selected); - gtk_widget_set_sensitive (de->data_sort_ascending_menu_item, - whole_column_selected); - gtk_widget_set_sensitive (de->data_sort_descending_menu_item, - whole_column_selected); -} - -static void -show_cases_row_popup (JmdSheet *sheet, int row, uint button, uint state, gpointer p) -{ - PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (p); - GListModel *vmodel = NULL; - g_object_get (sheet, "vmodel", &vmodel, NULL); - if (vmodel == NULL) - return; - - guint n_items = g_list_model_get_n_items (vmodel); - - if (row >= n_items) - return; - - if (button != 3) - return; - - g_object_set_data (G_OBJECT (de->data_sheet_cases_row_popup), "item", - GINT_TO_POINTER (row)); - - gtk_menu_popup_at_pointer (GTK_MENU (de->data_sheet_cases_row_popup), NULL); -} - -static void -show_cases_column_popup (JmdSheet *sheet, int column, uint button, uint state, - gpointer p) -{ - PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (p); - GListModel *hmodel = NULL; - g_object_get (sheet, "hmodel", &hmodel, NULL); - if (hmodel == NULL) - return; - - guint n_items = g_list_model_get_n_items (hmodel); - - if (column >= n_items) - return; - - if (button != 3) - return; - - g_object_set_data (G_OBJECT (de->data_sheet_cases_column_popup), "item", - GINT_TO_POINTER (column)); - - gtk_menu_popup_at_pointer (GTK_MENU (de->data_sheet_cases_column_popup), NULL); -} - - -static gchar * -data_store_value_to_string (JmdSheet *data_sheet, PsppireDataStore *store, gint col, gint row, const GValue *v) -{ - return psppire_data_store_value_to_string (store, col, row, v); -} - static void psppire_data_editor_init (PsppireDataEditor *de) { @@ -711,24 +459,7 @@ psppire_data_editor_init (PsppireDataEditor *de) gtk_box_pack_start (GTK_BOX (hbox), de->datum_entry, TRUE, TRUE, 0); de->split = FALSE; - de->data_sheet = jmd_sheet_new (); - - de->data_sheet_cases_column_popup = create_data_column_header_popup_menu (de); - de->data_sheet_cases_row_popup = create_data_row_header_popup_menu (de); - - g_signal_connect (de->data_sheet, "row-header-pressed", - G_CALLBACK (show_cases_row_popup), de); - - g_signal_connect (de->data_sheet, "column-header-pressed", - G_CALLBACK (show_cases_column_popup), de); - - g_signal_connect (de->data_sheet, "selection-changed", - G_CALLBACK (set_menu_items_sensitivity), de); - - g_object_set (de->data_sheet, - "forward-conversion", data_store_value_to_string, - "reverse-conversion", myreversefunc, - NULL); + de->data_sheet = psppire_data_sheet_new (); GtkWidget *data_button = jmd_sheet_get_button (JMD_SHEET (de->data_sheet)); gtk_button_set_label (GTK_BUTTON (data_button), _("Case")); diff --git a/src/ui/gui/psppire-data-editor.h b/src/ui/gui/psppire-data-editor.h index 4eb2830637..497876a70e 100644 --- a/src/ui/gui/psppire-data-editor.h +++ b/src/ui/gui/psppire-data-editor.h @@ -62,16 +62,6 @@ struct _PsppireDataEditor GtkWidget *var_sheet; GtkWidget *data_sheet; - /* Data sheet popup menu */ - GtkWidget *data_sheet_cases_row_popup; - GtkWidget *data_clear_cases_menu_item; - - - GtkWidget *data_sheet_cases_column_popup; - GtkWidget *data_clear_variables_menu_item; - GtkWidget *data_sort_ascending_menu_item; - GtkWidget *data_sort_descending_menu_item; - /* Data sheet tab. */ GtkWidget *vbox; /* Top-level widget in tab. */ GtkWidget *cell_ref_label; /* GtkLabel that shows selected case and var. */ diff --git a/src/ui/gui/psppire-data-sheet.c b/src/ui/gui/psppire-data-sheet.c new file mode 100644 index 0000000000..1e6265a36e --- /dev/null +++ b/src/ui/gui/psppire-data-sheet.c @@ -0,0 +1,384 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2017 John Darrington + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include "psppire-data-sheet.h" + +#include +#define _(msgid) gettext (msgid) +#define P_(X) (X) + +#include "value-variant.h" + +#include "ui/gui/executor.h" +#include "psppire-data-window.h" + +static void +do_sort (PsppireDataSheet *sheet, GtkSortType order) +{ + JmdRange *range = JMD_SHEET(sheet)->selection; + + PsppireDataStore *data_store = NULL; + g_object_get (sheet, "data-model", &data_store, NULL); + + int n_vars = 0; + int i; + + PsppireDataWindow *pdw = + psppire_data_window_for_data_store (data_store); + + GString *syntax = g_string_new ("SORT CASES BY"); + for (i = range->start_x ; i <= range->end_x; ++i) + { + const struct variable *var = psppire_dict_get_variable (data_store->dict, i); + if (var != NULL) + { + g_string_append_printf (syntax, " %s", var_get_name (var)); + n_vars++; + } + } + if (n_vars > 0) + { + if (order == GTK_SORT_DESCENDING) + g_string_append (syntax, " (DOWN)"); + g_string_append_c (syntax, '.'); + execute_const_syntax_string (pdw, syntax->str); + } + g_string_free (syntax, TRUE); +} + + +static void +sort_ascending (PsppireDataSheet *sheet) +{ + do_sort (sheet, GTK_SORT_ASCENDING); + + gtk_widget_queue_draw (GTK_WIDGET (sheet)); +} + +static void +sort_descending (PsppireDataSheet *sheet) +{ + do_sort (sheet, GTK_SORT_DESCENDING); + + gtk_widget_queue_draw (GTK_WIDGET (sheet)); +} + + + +static void +change_data_value (PsppireDataSheet *sheet, gint col, gint row, GValue *value) +{ + PsppireDataStore *store = NULL; + g_object_get (sheet, "data-model", &store, NULL); + + const struct variable *var = psppire_dict_get_variable (store->dict, col); + + if (NULL == var) + return; + + union value v; + + GVariant *vrnt = g_value_get_variant (value); + + value_variant_get (&v, vrnt); + + psppire_data_store_set_value (store, row, var, &v); + + value_destroy_from_variant (&v, vrnt); +} + +static gchar * +data_store_value_to_string (JmdSheet *data_sheet, PsppireDataStore *store, gint col, gint row, const GValue *v) +{ + return psppire_data_store_value_to_string (store, col, row, v); +} + +gboolean myreversefunc (GtkTreeModel *model, gint col, gint row, const gchar *in, + GValue *out); + + + + +static void +show_cases_row_popup (PsppireDataSheet *sheet, int row, + uint button, uint state, gpointer p) +{ + GListModel *vmodel = NULL; + g_object_get (sheet, "vmodel", &vmodel, NULL); + if (vmodel == NULL) + return; + + guint n_items = g_list_model_get_n_items (vmodel); + + if (row >= n_items) + return; + + if (button != 3) + return; + + g_object_set_data (G_OBJECT (sheet->data_sheet_cases_row_popup), "item", + GINT_TO_POINTER (row)); + + gtk_menu_popup_at_pointer (GTK_MENU (sheet->data_sheet_cases_row_popup), NULL); +} + + +static void +insert_new_case (PsppireDataSheet *sheet) +{ + PsppireDataStore *data_store = NULL; + g_object_get (sheet, "data-model", &data_store, NULL); + + gint posn = GPOINTER_TO_INT (g_object_get_data + (G_OBJECT (sheet->data_sheet_cases_row_popup), "item")); + + psppire_data_store_insert_new_case (data_store, posn); + + gtk_widget_queue_draw (GTK_WIDGET (sheet)); +} + +static void +delete_cases (PsppireDataSheet *sheet) +{ + JmdRange *range = JMD_SHEET(sheet)->selection; + + PsppireDataStore *data_store = NULL; + g_object_get (sheet, "data-model", &data_store, NULL); + + psppire_data_store_delete_cases (data_store, range->start_y, + range->end_y - range->start_y + 1); + + gtk_widget_queue_draw (GTK_WIDGET (sheet)); +} + +static GtkWidget * +create_data_row_header_popup_menu (PsppireDataSheet *sheet) +{ + GtkWidget *menu = gtk_menu_new (); + + GtkWidget *item = + gtk_menu_item_new_with_mnemonic (_("_Insert Case")); + + g_signal_connect_swapped (item, "activate", G_CALLBACK (insert_new_case), sheet); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + item = gtk_separator_menu_item_new (); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + sheet->data_clear_cases_menu_item = gtk_menu_item_new_with_mnemonic (_("Cl_ear Cases")); + gtk_widget_set_sensitive (sheet->data_clear_cases_menu_item, FALSE); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), sheet->data_clear_cases_menu_item); + g_signal_connect_swapped (sheet->data_clear_cases_menu_item, "activate", + G_CALLBACK (delete_cases), sheet); + + gtk_widget_show_all (menu); + return menu; +} + + +static void +show_cases_column_popup (PsppireDataSheet *sheet, int column, uint button, uint state, + gpointer p) +{ + GListModel *hmodel = NULL; + g_object_get (sheet, "hmodel", &hmodel, NULL); + if (hmodel == NULL) + return; + + guint n_items = g_list_model_get_n_items (hmodel); + + if (column >= n_items) + return; + + if (button != 3) + return; + + g_object_set_data (G_OBJECT (sheet->data_sheet_cases_column_popup), "item", + GINT_TO_POINTER (column)); + + gtk_menu_popup_at_pointer (GTK_MENU (sheet->data_sheet_cases_column_popup), NULL); +} + +static void +insert_new_variable (PsppireDataSheet *sheet) +{ + PsppireDataStore *data_store = NULL; + g_object_get (sheet, "data-model", &data_store, NULL); + + gint posn = GPOINTER_TO_INT (g_object_get_data + (G_OBJECT (sheet->data_sheet_cases_column_popup), + "item")); + + const struct variable *v = psppire_dict_insert_variable (data_store->dict, + posn, NULL); + + psppire_data_store_insert_value (data_store, var_get_width(v), + var_get_case_index (v)); + + gtk_widget_queue_draw (GTK_WIDGET (sheet)); +} + +static void +set_menu_items_sensitivity (PsppireDataSheet *sheet, gpointer selection, gpointer p) +{ + JmdRange *range = selection; + + PsppireDataStore *data_store = NULL; + g_object_get (sheet, "data-model", &data_store, NULL); + + + gint width = gtk_tree_model_get_n_columns (GTK_TREE_MODEL (data_store)); + gint length = psppire_data_store_get_case_count (data_store); + + + gboolean whole_row_selected = (range->start_x == 0 && range->end_x == width - 1); + gtk_widget_set_sensitive (sheet->data_clear_cases_menu_item, whole_row_selected); + + gboolean whole_column_selected = + (range->start_y == 0 && range->end_y == length - 1); + gtk_widget_set_sensitive (sheet->data_clear_variables_menu_item, + whole_column_selected); + gtk_widget_set_sensitive (sheet->data_sort_ascending_menu_item, + whole_column_selected); + gtk_widget_set_sensitive (sheet->data_sort_descending_menu_item, + whole_column_selected); +} + +static void +delete_variables (PsppireDataSheet *sheet) +{ + JmdRange *range = JMD_SHEET(sheet)->selection; + + PsppireDataStore *data_store = NULL; + g_object_get (sheet, "data-model", &data_store, NULL); + + psppire_dict_delete_variables (data_store->dict, range->start_x, + (range->end_x - range->start_x + 1)); + + gtk_widget_queue_draw (GTK_WIDGET (sheet)); +} + + + +static GtkWidget * +create_data_column_header_popup_menu (PsppireDataSheet *sheet) +{ + GtkWidget *menu = gtk_menu_new (); + + GtkWidget *item = + gtk_menu_item_new_with_mnemonic (_("_Insert Variable")); + g_signal_connect_swapped (item, "activate", G_CALLBACK (insert_new_variable), + sheet); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + item = gtk_separator_menu_item_new (); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + sheet->data_clear_variables_menu_item = + gtk_menu_item_new_with_mnemonic (_("Cl_ear Variables")); + g_signal_connect_swapped (sheet->data_clear_variables_menu_item, "activate", + G_CALLBACK (delete_variables), + sheet); + gtk_widget_set_sensitive (sheet->data_clear_variables_menu_item, FALSE); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), sheet->data_clear_variables_menu_item); + + item = gtk_separator_menu_item_new (); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + + sheet->data_sort_ascending_menu_item = + gtk_menu_item_new_with_mnemonic (_("Sort _Ascending")); + g_signal_connect_swapped (sheet->data_sort_ascending_menu_item, "activate", + G_CALLBACK (sort_ascending), sheet); + gtk_widget_set_sensitive (sheet->data_sort_ascending_menu_item, FALSE); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), sheet->data_sort_ascending_menu_item); + + sheet->data_sort_descending_menu_item = + gtk_menu_item_new_with_mnemonic (_("Sort _Descending")); + g_signal_connect_swapped (sheet->data_sort_descending_menu_item, "activate", + G_CALLBACK (sort_descending), sheet); + gtk_widget_set_sensitive (sheet->data_sort_descending_menu_item, FALSE); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), sheet->data_sort_descending_menu_item); + + gtk_widget_show_all (menu); + return menu; +} + + + + +G_DEFINE_TYPE (PsppireDataSheet, psppire_data_sheet, JMD_TYPE_SHEET) + +static GObjectClass * parent_class = NULL; +static gboolean dispose_has_run = FALSE; + +static void +psppire_data_sheet_dispose (GObject *obj) +{ + PsppireDataSheet *sheet = PSPPIRE_DATA_SHEET (obj); + + if (dispose_has_run) + return; + + dispose_has_run = TRUE; + + /* Chain up to the parent class */ + G_OBJECT_CLASS (parent_class)->dispose (obj); +} + +static void +psppire_data_sheet_class_init (PsppireDataSheetClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + object_class->dispose = psppire_data_sheet_dispose; +} + +GtkWidget* +psppire_data_sheet_new (void) +{ + GObject *obj = + g_object_new (PSPPIRE_TYPE_DATA_SHEET, + "forward-conversion", data_store_value_to_string, + "reverse-conversion", myreversefunc, + NULL); + + return GTK_WIDGET (obj); +} + + +static void +psppire_data_sheet_init (PsppireDataSheet *sheet) +{ + sheet->data_sheet_cases_column_popup = + create_data_column_header_popup_menu (sheet); + + sheet->data_sheet_cases_row_popup = + create_data_row_header_popup_menu (sheet); + + g_signal_connect (sheet, "selection-changed", + G_CALLBACK (set_menu_items_sensitivity), sheet); + + g_signal_connect (sheet, "column-header-pressed", + G_CALLBACK (show_cases_column_popup), sheet); + + g_signal_connect (sheet, "row-header-pressed", + G_CALLBACK (show_cases_row_popup), sheet); + + g_signal_connect (sheet, "value-changed", + G_CALLBACK (change_data_value), NULL); +} diff --git a/src/ui/gui/psppire-data-sheet.h b/src/ui/gui/psppire-data-sheet.h new file mode 100644 index 0000000000..4622c067ca --- /dev/null +++ b/src/ui/gui/psppire-data-sheet.h @@ -0,0 +1,50 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2017 John Darrington + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef _PSPPIRE_DATA_SHEET_H +#define _PSPPIRE_DATA_SHEET_H + +#include +#include "ui/gui/efficient-sheet/jmd-sheet.h" + +struct _PsppireDataSheet +{ + JmdSheet parent_instance; + + GtkWidget *data_sheet_cases_column_popup; + + GtkWidget *data_clear_variables_menu_item; + GtkWidget *data_clear_cases_menu_item; + GtkWidget *data_sheet_cases_row_popup; + + /* Data sheet popup menu */ + GtkWidget *data_sort_ascending_menu_item; + GtkWidget *data_sort_descending_menu_item; +}; + +struct _PsppireDataSheetClass +{ + JmdSheetClass parent_class; +}; + +#define PSPPIRE_TYPE_DATA_SHEET psppire_data_sheet_get_type () + +G_DECLARE_FINAL_TYPE (PsppireDataSheet, psppire_data_sheet, PSPPIRE, DATA_SHEET, JmdSheet) + +GtkWidget *psppire_data_sheet_new (void); + +#endif -- 2.30.2