GUI: Move .ui files from goffice resources to glib resources
[gnumeric.git] / src / dialogs / dialog-col-row.c
blob687de319b5c10f0e0e8bd2e651a90eee792a625f
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /**
3 * dialog-col-row.c: group/ungroup dialog
5 * Author:
6 * Andreas J. Guelzow <aguelzow@taliesin.ca>
8 * (c) Copyright 2002-2006 Andreas J. Guelzow <aguelzow@taliesin.ca>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <https://www.gnu.org/licenses/>.
23 #include <gnumeric-config.h>
24 #include <gnumeric.h>
25 #include "dialogs.h"
26 #include "help.h"
28 #include <gui-util.h>
29 #include <commands.h>
30 #include <workbook-control.h>
31 #include <workbook.h>
32 #include <wbc-gtk.h>
34 #include <gtk/gtk.h>
36 #define COL_ROW_DIALOG_KEY "col-row-dialog"
38 typedef struct {
39 GtkBuilder *gui;
40 GtkWidget *dialog;
41 GtkWidget *ok_button;
42 GtkWidget *cancel_button;
43 WBCGtk *wbcg;
45 gpointer data;
46 ColRowCallback_t callback;
47 } ColRowState;
49 static void
50 cb_dialog_col_row_destroy (ColRowState *state)
52 if (state->gui != NULL)
53 g_object_unref (state->gui);
54 g_free (state);
57 static void
58 cb_dialog_col_row_cancel_clicked (G_GNUC_UNUSED GtkWidget *button,
59 ColRowState *state)
61 gtk_widget_destroy (state->dialog);
65 static void
66 cb_dialog_col_row_ok_clicked (G_GNUC_UNUSED GtkWidget *button,
67 ColRowState *state)
69 state->callback (state->wbcg,
70 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
71 (go_gtk_builder_get_widget (state->gui,
72 "cols"))),
73 state->data);
74 gtk_widget_destroy (state->dialog);
77 void
78 dialog_col_row (WBCGtk *wbcg, char const *operation,
79 ColRowCallback_t callback,
80 gpointer data)
82 GtkBuilder *gui;
83 ColRowState *state;
85 g_return_if_fail (wbcg != NULL);
87 if (gnm_dialog_raise_if_exists (wbcg, COL_ROW_DIALOG_KEY))
88 return;
89 gui = gnm_gtk_builder_load ("res:ui/colrow.ui", NULL, GO_CMD_CONTEXT (wbcg));
90 if (gui == NULL)
91 return;
93 state = g_new (ColRowState, 1);
94 state->wbcg = wbcg;
95 state->callback = callback;
96 state->data = data;
97 state->gui = gui;
99 state->dialog = go_gtk_builder_get_widget (state->gui, "dialog");
101 state->ok_button = go_gtk_builder_get_widget (state->gui, "ok_button");
102 g_signal_connect (G_OBJECT (state->ok_button),
103 "clicked",
104 G_CALLBACK (cb_dialog_col_row_ok_clicked), state);
106 state->cancel_button = go_gtk_builder_get_widget (state->gui, "cancel_button");
107 g_signal_connect (G_OBJECT (state->cancel_button),
108 "clicked",
109 G_CALLBACK (cb_dialog_col_row_cancel_clicked), state);
111 gnm_init_help_button (
112 go_gtk_builder_get_widget (state->gui, "help_button"),
113 GNUMERIC_HELP_LINK_GROUP_UNGROUP);
115 gtk_window_set_title (GTK_WINDOW (state->dialog), operation);
117 wbc_gtk_attach_guru (state->wbcg, state->dialog);
118 g_object_set_data_full (G_OBJECT (state->dialog),
119 "state", state, (GDestroyNotify) cb_dialog_col_row_destroy);
121 gnm_keyed_dialog (wbcg, GTK_WINDOW (state->dialog),
122 COL_ROW_DIALOG_KEY);
123 gtk_widget_show (state->dialog);