1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4 * dialog-so-list.c: A property dialog for lists and combos
6 * Copyright (C) 2006 Jody Goldberg (jody@gnome.org)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) version 3.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 #include <gnumeric-config.h>
29 #include <selection.h>
31 #include <sheet-view.h>
32 #include <sheet-object-widget.h>
34 #include <workbook-control.h>
37 #include <parse-util.h>
39 #include <widgets/gnumeric-expr-entry.h>
41 #include <glib/gi18n.h>
43 #define DIALOG_SO_LIST_KEY "so-list"
47 GtkWidget
*as_index_radio
;
48 GnmExprEntry
*content_entry
, *link_entry
;
55 init_entry (GnmDialogSOList
*state
, GtkBuilder
*gui
, int col
, int row
,
56 GnmExprTop
const *texpr
)
58 GnmExprEntry
*gee
= gnm_expr_entry_new (state
->wbcg
, TRUE
);
59 GtkWidget
*w
= GTK_WIDGET (gee
);
60 GtkGrid
*grid
= GTK_GRID (gtk_builder_get_object (gui
, "main-grid"));
61 Sheet
*sheet
= sheet_object_get_sheet (state
->so
);
64 g_return_val_if_fail (w
!= NULL
, NULL
);
66 gtk_grid_attach (grid
, w
, col
, row
, 1, 1);
67 gnm_expr_entry_set_flags (gee
, GNM_EE_FORCE_ABS_REF
|
68 GNM_EE_SHEET_OPTIONAL
|
69 GNM_EE_SINGLE_RANGE
, GNM_EE_MASK
);
71 parse_pos_init_sheet (&pp
, sheet
);
72 gnm_expr_entry_load_from_expr (gee
, texpr
, &pp
);
77 cb_so_list_response (GtkWidget
*dialog
, gint response_id
, GnmDialogSOList
*state
)
79 if (response_id
== GTK_RESPONSE_HELP
)
81 if (response_id
== GTK_RESPONSE_OK
) {
83 Sheet
*sheet
= sheet_object_get_sheet (state
->so
);
84 GnmExprTop
const *output
;
85 GnmExprTop
const *content
;
87 parse_pos_init (&pp
, sheet
->workbook
, sheet
, 0, 0);
88 output
= gnm_expr_entry_parse (state
->link_entry
,
89 &pp
, NULL
, FALSE
, GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES
);
90 content
= gnm_expr_entry_parse (state
->content_entry
,
91 &pp
, NULL
, FALSE
, GNM_EXPR_PARSE_FORCE_ABSOLUTE_REFERENCES
);
92 cmd_so_set_links (GNM_WBC (state
->wbcg
), state
->so
, output
, content
,
93 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
94 (state
->as_index_radio
)));
97 gtk_widget_destroy (dialog
);
101 so_list_init (GnmDialogSOList
*state
, WBCGtk
*wbcg
, SheetObject
*so
)
103 GnmExprTop
const *texpr
;
106 gui
= gnm_gtk_builder_load ("res:ui/so-list.ui", NULL
, GO_CMD_CONTEXT (wbcg
));
112 state
->dialog
= go_gtk_builder_get_widget (gui
, "SOList");
114 gnm_dialog_setup_destroy_handlers (GTK_DIALOG (state
->dialog
),
116 GNM_DIALOG_DESTROY_CURRENT_SHEET_REMOVED
);
118 texpr
= sheet_widget_list_base_get_content_link (so
);
119 state
->content_entry
= init_entry (state
, gui
, 1, 4, texpr
);
120 if (texpr
) gnm_expr_top_unref (texpr
);
122 texpr
= sheet_widget_list_base_get_result_link (so
);
123 state
->link_entry
= init_entry (state
, gui
, 1, 0, texpr
);
124 if (texpr
) gnm_expr_top_unref (texpr
);
126 state
->as_index_radio
= go_gtk_builder_get_widget (gui
, "as-index-radio");
127 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state
->as_index_radio
),
128 sheet_widget_list_base_result_type_is_index (so
));
130 g_signal_connect (G_OBJECT (state
->dialog
), "response",
131 G_CALLBACK (cb_so_list_response
), state
);
132 gnm_init_help_button (
133 go_gtk_builder_get_widget (gui
, "help"),
134 GNUMERIC_HELP_LINK_SO_LIST
);
136 /* a candidate for merging into attach guru */
137 gnm_keyed_dialog (state
->wbcg
, GTK_WINDOW (state
->dialog
),
139 g_object_set_data_full (G_OBJECT (state
->dialog
),
140 "state", state
, g_free
);
141 go_gtk_nonmodal_dialog (wbcg_toplevel (state
->wbcg
),
142 GTK_WINDOW (state
->dialog
));
143 wbc_gtk_attach_guru (state
->wbcg
, state
->dialog
);
144 gtk_widget_show_all (GTK_WIDGET (state
->dialog
));
145 g_object_unref (gui
);
151 dialog_so_list (WBCGtk
*wbcg
, GObject
*so
)
153 GnmDialogSOList
*state
;
155 g_return_if_fail (wbcg
!= NULL
);
157 if (wbc_gtk_get_guru (wbcg
) ||
158 gnm_dialog_raise_if_exists (wbcg
, DIALOG_SO_LIST_KEY
))
161 state
= g_new0 (GnmDialogSOList
, 1);
162 if (so_list_init (state
, wbcg
, GNM_SO (so
))) {
163 go_gtk_notice_dialog (wbcg_toplevel (wbcg
), GTK_MESSAGE_ERROR
,
164 _("Could not create the List Property dialog."));