From 16c9b320ee7d2d5e57ad15bae865ba603005ef9f Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 3 Oct 2020 07:18:47 +0200 Subject: [PATCH] Ensure that data sheet and variable sheets can be constructed via GtkBuilder. This change removes the reliance of the _new functions on setting necessary properties. Otherwise these objects do not get set when constructed by GtkBuilder. --- src/ui/gui/psppire-data-sheet.c | 32 ++++++++++++++------- src/ui/gui/psppire-variable-sheet.c | 44 ++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 24 deletions(-) diff --git a/src/ui/gui/psppire-data-sheet.c b/src/ui/gui/psppire-data-sheet.c index feb64b1aab..728604d513 100644 --- a/src/ui/gui/psppire-data-sheet.c +++ b/src/ui/gui/psppire-data-sheet.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2017, 2019 Free Software Foundation + Copyright (C) 2017, 2019, 2020 Free Software Foundation 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 @@ -372,10 +372,28 @@ psppire_data_sheet_dispose (GObject *obj) G_OBJECT_CLASS (parent_class)->dispose (obj); } + +static void +psppire_data_sheet_realize (GtkWidget *widget) +{ + g_object_set (widget, + "forward-conversion", psppire_data_store_value_to_string, + "reverse-conversion", psppire_data_store_string_to_value, + "editable", TRUE, + "horizontal-draggable", TRUE, + NULL); + + /* Chain up to the parent class */ + GTK_WIDGET_CLASS (parent_class)->realize (widget); +} + static void psppire_data_sheet_class_init (PsppireDataSheetClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + + widget_class->realize = psppire_data_sheet_realize; object_class->dispose = psppire_data_sheet_dispose; object_class->finalize = psppire_data_sheet_finalize; @@ -385,15 +403,7 @@ psppire_data_sheet_class_init (PsppireDataSheetClass *class) GtkWidget* psppire_data_sheet_new (void) { - GObject *obj = - g_object_new (PSPPIRE_TYPE_DATA_SHEET, - "forward-conversion", psppire_data_store_value_to_string, - "reverse-conversion", psppire_data_store_string_to_value, - "editable", TRUE, - "horizontal-draggable", TRUE, - NULL); - - return GTK_WIDGET (obj); + return g_object_new (PSPPIRE_TYPE_DATA_SHEET, NULL); } @@ -457,6 +467,8 @@ set_dictionary (PsppireDataSheet *sheet) GtkTreeModel *data_model = NULL; g_object_get (sheet, "data-model", &data_model, NULL); + g_return_if_fail (data_model); + PsppireDataStore *store = PSPPIRE_DATA_STORE (data_model); g_object_set (sheet, "hmodel", store->dict, NULL); diff --git a/src/ui/gui/psppire-variable-sheet.c b/src/ui/gui/psppire-variable-sheet.c index d877c80dc9..b0fcbfca90 100644 --- a/src/ui/gui/psppire-variable-sheet.c +++ b/src/ui/gui/psppire-variable-sheet.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2017 Free Software Foundation + Copyright (C) 2017, 2020 Free Software Foundation 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 @@ -455,33 +455,42 @@ psppire_variable_sheet_finalize (GObject *object) (*G_OBJECT_CLASS (parent_class)->finalize) (object); } +static void +psppire_variable_sheet_realize (GtkWidget *widget) +{ + /* This is a kludge. These are properties from the parent class. + They should really be set immediately after initialisation, but there is no + simple way to do that. */ + g_object_set (widget, + "editable", TRUE, + "select-renderer-func", select_renderer_func, + "vertical-draggable", TRUE, + "forward-conversion", var_sheet_data_to_string, + NULL); + + if (GTK_WIDGET_CLASS (parent_class)->realize) + (*GTK_WIDGET_CLASS (parent_class)->realize) (widget); +} + + static void psppire_variable_sheet_class_init (PsppireVariableSheetClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + object_class->dispose = psppire_variable_sheet_dispose; parent_class = g_type_class_peek_parent (class); + widget_class->realize = psppire_variable_sheet_realize; object_class->finalize = psppire_variable_sheet_finalize; } GtkWidget* psppire_variable_sheet_new (void) { - PsppireVarSheetHeader *vsh = - g_object_new (PSPPIRE_TYPE_VAR_SHEET_HEADER, NULL); - - GObject *obj = - g_object_new (PSPPIRE_TYPE_VARIABLE_SHEET, - "select-renderer-func", select_renderer_func, - "hmodel", vsh, - "forward-conversion", var_sheet_data_to_string, - "editable", TRUE, - "vertical-draggable", TRUE, - NULL); - - return GTK_WIDGET (obj); + return g_object_new (PSPPIRE_TYPE_VARIABLE_SHEET, NULL); } static void @@ -609,4 +618,11 @@ psppire_variable_sheet_init (PsppireVariableSheet *sheet) g_signal_connect (sheet, "row-moved", G_CALLBACK (move_variable), NULL); + + PsppireVarSheetHeader *vsh = + g_object_new (PSPPIRE_TYPE_VAR_SHEET_HEADER, NULL); + + g_object_set (sheet, + "hmodel", vsh, + NULL); } -- 2.30.2