X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-variable-sheet.c;h=b0fcbfca909b52375f0757711a2154dfba6bdbd3;hb=13ca98079f4cb3cd80deb10b173813548b1f3ddc;hp=149403743aa16fe5404a1212b5ee02271708a5d2;hpb=56e6166660c0f1388cad4cb4d3189e026bc84dd5;p=pspp diff --git a/src/ui/gui/psppire-variable-sheet.c b/src/ui/gui/psppire-variable-sheet.c index 149403743a..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 John Darrington + 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 @@ -266,6 +266,10 @@ create_var_row_header_popup_menu (PsppireVariableSheet *var_sheet) { GtkWidget *menu = gtk_menu_new (); + /* gtk_menu_shell_append does not sink/ref this object, + so we must do it ourselves (and remember to unref it). */ + g_object_ref_sink (menu); + GtkWidget *item = gtk_menu_item_new_with_mnemonic (_("_Insert Variable")); g_signal_connect_swapped (item, "activate", G_CALLBACK (insert_new_variable_var), @@ -432,6 +436,7 @@ psppire_variable_sheet_dispose (GObject *obj) g_object_unref (sheet->value_label_renderer); g_object_unref (sheet->missing_values_renderer); g_object_unref (sheet->var_type_renderer); + g_object_unref (sheet->row_popup); /* Chain up to the parent class */ G_OBJECT_CLASS (parent_class)->dispose (obj); @@ -450,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 @@ -593,7 +607,6 @@ psppire_variable_sheet_init (PsppireVariableSheet *sheet) sheet->row_popup = create_var_row_header_popup_menu (sheet); - g_signal_connect (sheet, "selection-changed", G_CALLBACK (set_var_popup_sensitivity), sheet); @@ -605,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); }