X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fpsppire-data-editor.c;h=40a2c490b4460fcdb5a874dd28fb1d648ce3f55f;hb=e83d90847323b194bdb04267f9b0eb557fb139d4;hp=147ffcd4c3b50ec4f0ea479d27a2278cd69d241d;hpb=7293c1a383d325c371bd708401e5a1d7586a4d90;p=pspp diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 147ffcd4c3..40a2c490b4 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 2008, 2009, 2010, 2011, 2012, 2016 Free Software Foundation, Inc. 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 @@ -31,7 +31,11 @@ #include "ui/gui/psppire-conf.h" #include "ui/gui/psppire-var-sheet-header.h" +#include "value-variant.h" + + #include "ui/gui/efficient-sheet/jmd-sheet.h" +#include "ui/gui/efficient-sheet/jmd-sheet-body.h" #include #define _(msgid) gettext (msgid) @@ -242,13 +246,18 @@ 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; - value_init (&v, var_get_width (var)); - v.f = g_value_get_double (value); + + GVariant *vrnt = g_value_get_variant (value); + + value_variant_get (&v, vrnt); psppire_data_store_set_value (store, row, var, &v); - value_destroy (&v, var_get_width (var)); + value_destroy_from_variant (&v, vrnt); } static void @@ -449,7 +458,21 @@ on_data_sheet_var_double_clicked (JmdSheet *data_sheet, gint dict_index, static void refresh_entry (PsppireDataEditor *de) { - g_print ("%s\n", __FUNCTION__); + union value val; + gint row, col; + jmd_sheet_get_active_cell (JMD_SHEET (de->data_sheet), &col, &row); + + const struct variable *var = psppire_dict_get_variable (de->dict, col); + psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (de->datum_entry), var); + + int width = var_get_width (var); + if (! psppire_data_store_get_value (PSPPIRE_DATA_STORE (de->data_store), + row, var, &val)) + return; + + psppire_value_entry_set_value (PSPPIRE_VALUE_ENTRY (de->datum_entry), + &val, width); + value_destroy (&val, width); } static void @@ -476,9 +499,10 @@ on_data_selection_change (PsppireDataEditor *de, JmdRange *sel) { /* A single cell is selected */ const struct variable *var = psppire_dict_get_variable (de->dict, sel->start_x); - - ref_cell_text = g_strdup_printf (_("%d : %s"), - sel->start_y + 1, var_get_name (var)); + + if (var) + ref_cell_text = g_strdup_printf (_("%d : %s"), + sel->start_y + 1, var_get_name (var)); } else { @@ -508,12 +532,19 @@ on_data_selection_change (PsppireDataEditor *de, JmdRange *sel) static void set_font_recursively (GtkWidget *w, gpointer data); +gchar *myconvfunc (GtkTreeModel *m, gint col, gint row, const GValue *v); +void myreversefunc (GtkTreeModel *model, gint col, gint row, const gchar *in, GValue *out); + + static void psppire_data_editor_init (PsppireDataEditor *de) { GtkWidget *hbox; gchar *fontname = NULL; + GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (de)); + gtk_style_context_add_class (context, "psppire-data-editor"); + de->font = NULL; de->old_vbox_widget = NULL; @@ -532,7 +563,11 @@ 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 = g_object_new (JMD_TYPE_SHEET, NULL); + de->data_sheet = jmd_sheet_new (); + jmd_sheet_body_set_conversion_func + (JMD_SHEET_BODY (JMD_SHEET(de->data_sheet)->selected_body), + myconvfunc, myreversefunc); + GtkWidget *data_button = jmd_sheet_get_button (JMD_SHEET (de->data_sheet)); gtk_button_set_label (GTK_BUTTON (data_button), _("Case")); de->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); @@ -600,15 +635,8 @@ psppire_data_editor_new (PsppireDict *dict, void psppire_data_editor_show_grid (PsppireDataEditor *de, gboolean grid_visible) { -#if 0 - GtkTreeViewGridLines grid; - - grid = (grid_visible - ? GTK_TREE_VIEW_GRID_LINES_BOTH - : GTK_TREE_VIEW_GRID_LINES_NONE); - - pspp_sheet_view_set_grid_lines (PSPP_SHEET_VIEW (de->var_sheet), grid); -#endif + g_object_set (JMD_SHEET (de->var_sheet), "gridlines", grid_visible, NULL); + g_object_set (JMD_SHEET (de->data_sheet), "gridlines", grid_visible, NULL); } @@ -617,7 +645,28 @@ set_font_recursively (GtkWidget *w, gpointer data) { PangoFontDescription *font_desc = data; - gtk_widget_override_font (w, font_desc); + GtkStyleContext *style = gtk_widget_get_style_context (w); + GtkCssProvider *cssp = gtk_css_provider_new (); + + gchar *str = pango_font_description_to_string (font_desc); + gchar *css = + g_strdup_printf ("* {font: %s}", str); + g_free (str); + + GError *err = NULL; + gtk_css_provider_load_from_data (cssp, css, -1, &err); + if (err) + { + g_warning ("Failed to load font css \"%s\": %s", css, err->message); + g_error_free (err); + } + g_free (css); + + gtk_style_context_add_provider (style, + GTK_STYLE_PROVIDER (cssp), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_object_unref (cssp); + if ( GTK_IS_CONTAINER (w)) gtk_container_foreach (GTK_CONTAINER (w), set_font_recursively, font_desc); @@ -638,7 +687,7 @@ psppire_data_editor_set_font (PsppireDataEditor *de, PangoFontDescription *font_ psppire_conf_set_string (psppire_conf_new (), "Data Editor", "font", font_name); - + g_free (font_name); } /* If SPLIT is TRUE, splits DE's data sheet into four panes. @@ -668,41 +717,3 @@ void psppire_data_editor_goto_variable (PsppireDataEditor *de, gint dict_index) { } - -#if 0 -/* Returns the "active" data sheet in DE. If DE is in single-paned mode, this - is the only data sheet. If DE is in split mode (showing four data sheets), - this is the focused data sheet or, if none is focused, the data sheet with - selected cells or, if none has selected cells, the upper-left data sheet. */ -PsppireDataSheet * -psppire_data_editor_get_active_data_sheet (PsppireDataEditor *de) -{ - if (de->split) - { - PsppireDataSheet *data_sheet; - GtkWidget *scroller; - int i; - - /* If one of the datasheet's scrollers is focused, choose that one. */ - scroller = gtk_container_get_focus_child ( - GTK_CONTAINER (de->datasheet_vbox_widget)); - if (scroller != NULL) - return PSPPIRE_DATA_SHEET (gtk_bin_get_child (GTK_BIN (scroller))); - - /* Otherwise if there's a nonempty selection in some data sheet, choose - that one. */ - FOR_EACH_DATA_SHEET (data_sheet, i, de) - { - PsppSheetSelection *selection; - - selection = pspp_sheet_view_get_selection ( - PSPP_SHEET_VIEW (data_sheet)); - if (pspp_sheet_selection_count_selected_rows (selection) - && pspp_sheet_selection_count_selected_columns (selection)) - return data_sheet; - } - } - - return PSPPIRE_DATA_SHEET (de->data_sheets[0]); -} -#endif