3 * dialog-so-list.c: A property dialog for lists and combos
5 * Copyright (C) 2006 Jody Goldberg (jody@gnome.org)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) version 3.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 #include <gnumeric-config.h>
24 #include <dialogs/dialogs.h>
25 #include <dialogs/help.h>
28 #include <selection.h>
30 #include <sheet-view.h>
31 #include <sheet-object-widget.h>
33 #include <workbook-control.h>
36 #include <parse-util.h>
38 #include <widgets/gnm-expr-entry.h>
39 #include <glib/gi18n.h>
41 #define DIALOG_SO_LIST_KEY "so-list"
45 GtkWidget
*as_index_radio
;
46 GnmExprEntry
*content_entry
, *link_entry
;
53 init_entry (GnmDialogSOList
*state
, GtkBuilder
*gui
, int col
, int row
,
54 GnmExprTop
const *texpr
)
56 GnmExprEntry
*gee
= gnm_expr_entry_new (state
->wbcg
, TRUE
);
57 GtkWidget
*w
= GTK_WIDGET (gee
);
58 GtkGrid
*grid
= GTK_GRID (gtk_builder_get_object (gui
, "main-grid"));
59 Sheet
*sheet
= sheet_object_get_sheet (state
->so
);
62 g_return_val_if_fail (w
!= NULL
, NULL
);
64 gtk_grid_attach (grid
, w
, col
, row
, 1, 1);
65 gnm_expr_entry_set_flags (gee
, GNM_EE_FORCE_ABS_REF
|
66 GNM_EE_SHEET_OPTIONAL
|
67 GNM_EE_SINGLE_RANGE
, GNM_EE_MASK
);
69 parse_pos_init_sheet (&pp
, sheet
);
70 gnm_expr_entry_load_from_expr (gee
, texpr
, &pp
);
75 cb_so_list_response (GtkWidget
*dialog
, gint response_id
, GnmDialogSOList
*state
)
77 if (response_id
== GTK_RESPONSE_HELP
)
79 if (response_id
== GTK_RESPONSE_OK
) {
81 Sheet
*sheet
= sheet_object_get_sheet (state
->so
);
82 GnmExprTop
const *output
;
83 GnmExprTop
const *content
;
85 parse_pos_init (&pp
, sheet
->workbook
, sheet
, 0, 0);
86 output
= gnm_expr_entry_parse (state
->link_entry
,
87 &pp
, NULL
, FALSE
, GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES
);
88 content
= gnm_expr_entry_parse (state
->content_entry
,
89 &pp
, NULL
, FALSE
, GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES
);
90 cmd_so_set_links (GNM_WBC (state
->wbcg
), state
->so
, output
, content
,
91 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
92 (state
->as_index_radio
)));
95 gtk_widget_destroy (dialog
);
99 so_list_init (GnmDialogSOList
*state
, WBCGtk
*wbcg
, SheetObject
*so
)
101 GnmExprTop
const *texpr
;
104 gui
= gnm_gtk_builder_load ("res:ui/so-list.ui", NULL
, GO_CMD_CONTEXT (wbcg
));
110 state
->dialog
= go_gtk_builder_get_widget (gui
, "SOList");
112 gnm_dialog_setup_destroy_handlers (GTK_DIALOG (state
->dialog
),
114 GNM_DIALOG_DESTROY_CURRENT_SHEET_REMOVED
);
116 texpr
= sheet_widget_list_base_get_content_link (so
);
117 state
->content_entry
= init_entry (state
, gui
, 1, 4, texpr
);
118 if (texpr
) gnm_expr_top_unref (texpr
);
120 texpr
= sheet_widget_list_base_get_result_link (so
);
121 state
->link_entry
= init_entry (state
, gui
, 1, 0, texpr
);
122 if (texpr
) gnm_expr_top_unref (texpr
);
124 state
->as_index_radio
= go_gtk_builder_get_widget (gui
, "as-index-radio");
125 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state
->as_index_radio
),
126 sheet_widget_list_base_result_type_is_index (so
));
128 g_signal_connect (G_OBJECT (state
->dialog
), "response",
129 G_CALLBACK (cb_so_list_response
), state
);
130 gnm_init_help_button (
131 go_gtk_builder_get_widget (gui
, "help"),
132 GNUMERIC_HELP_LINK_SO_LIST
);
134 /* a candidate for merging into attach guru */
135 gnm_keyed_dialog (state
->wbcg
, GTK_WINDOW (state
->dialog
),
137 g_object_set_data_full (G_OBJECT (state
->dialog
),
138 "state", state
, g_free
);
139 go_gtk_nonmodal_dialog (wbcg_toplevel (state
->wbcg
),
140 GTK_WINDOW (state
->dialog
));
141 wbc_gtk_attach_guru (state
->wbcg
, state
->dialog
);
142 gtk_widget_show_all (GTK_WIDGET (state
->dialog
));
143 g_object_unref (gui
);
149 dialog_so_list (WBCGtk
*wbcg
, GObject
*so
)
151 GnmDialogSOList
*state
;
153 g_return_if_fail (wbcg
!= NULL
);
155 if (wbc_gtk_get_guru (wbcg
) ||
156 gnm_dialog_raise_if_exists (wbcg
, DIALOG_SO_LIST_KEY
))
159 state
= g_new0 (GnmDialogSOList
, 1);
160 if (so_list_init (state
, wbcg
, GNM_SO (so
))) {
161 go_gtk_notice_dialog (wbcg_toplevel (wbcg
), GTK_MESSAGE_ERROR
,
162 _("Could not create the List Property dialog."));