summaryrefslogtreecommitdiffstats
path: root/plug-ins/imagemap/imap_settings.c
blob: 10a4a33237819ca2fc3d5ffe5b3227fb03facf99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
 * This is a plug-in for GIMP.
 *
 * Generates clickable image maps.
 *
 * Copyright (C) 1998-2004 Maurits Rijk  m.rijk@chello.nl
 *
 * 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
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

#include "config.h"

#include "libgimp/gimp.h"
#include "libgimp/gimpui.h"

#include "imap_browse.h"
#include "imap_main.h"
#include "imap_settings.h"
#include "imap_string.h"
#include "imap_table.h"

#include "libgimp/stdplugins-intl.h"

typedef struct {
  DefaultDialog_t *dialog;
  BrowseWidget_t *imagename;
  GtkWidget     *filename;
  GtkWidget     *title;
  GtkWidget     *author;
  GtkWidget     *default_url;
  GtkWidget     *ncsa;
  GtkWidget     *cern;
  GtkWidget     *csim;
  GtkTextBuffer *description;
} SettingsDialog_t;

static MapFormat_t _map_format = CSIM;

static void
settings_ok_cb(gpointer data)
{
   SettingsDialog_t *param = (SettingsDialog_t*) data;
   MapInfo_t *info = get_map_info();
   gchar *description;
   GtkTextIter start, end;

   g_strreplace(&info->image_name, gtk_entry_get_text(
      GTK_ENTRY(param->imagename->file)));
   g_strreplace(&info->title, gtk_entry_get_text(GTK_ENTRY(param->title)));
   g_strreplace(&info->author, gtk_entry_get_text(GTK_ENTRY(param->author)));
   g_strreplace(&info->default_url,
                gtk_entry_get_text(GTK_ENTRY(param->default_url)));
   gtk_text_buffer_get_bounds(param->description, &start, &end);
   description = gtk_text_buffer_get_text(param->description, &start, &end,
                                          FALSE);
   g_strreplace(&info->description, description);
   g_free(description);

   info->map_format = _map_format;
}

static void
type_toggled_cb(GtkWidget *widget, gpointer data)
{
  if (gtk_widget_get_state (widget) & GTK_STATE_SELECTED)
    _map_format = (MapFormat_t) data;
}

static SettingsDialog_t*
create_settings_dialog(void)
{
   SettingsDialog_t *data = g_new(SettingsDialog_t, 1);
   GtkWidget *table, *view, *frame, *hbox, *label, *swin;
   DefaultDialog_t *dialog;

   dialog = data->dialog = make_default_dialog(_("Settings for this Mapfile"));
   default_dialog_set_ok_cb(dialog, settings_ok_cb, (gpointer) data);
   table = default_dialog_add_table(dialog, 9, 2);

   create_label_in_table(table, 0, 0, _("Filename:"));
   data->filename = create_label_in_table(table, 0, 1, "");

   create_label_in_table(table, 1, 0, _("Image name:"));
   data->imagename = browse_widget_new(_("Select Image File"));
   gtk_table_attach_defaults(GTK_TABLE(table), data->imagename->hbox, 1, 2,
                             1, 2);

   label = create_label_in_table(table, 2, 0, _("_Title:"));
   data->title = create_entry_in_table(table, label, 2, 1);
   label = create_label_in_table(table, 3, 0, _("Aut_hor:"));
   data->author = create_entry_in_table(table, label, 3, 1);
   label = create_label_in_table(table, 4, 0, _("Default _URL:"));
   data->default_url = create_entry_in_table(table, label, 4, 1);
   label = create_label_in_table(table, 5, 0, _("_Description:"));

   data->description = gtk_text_buffer_new(NULL);

   view = gtk_text_view_new_with_buffer(data->description);
   gtk_widget_set_size_request(view, -1, 128);
   gtk_widget_show(view);

   gtk_label_set_mnemonic_widget (GTK_LABEL (label), view);

   swin = gtk_scrolled_window_new(NULL, NULL);
   gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swin),
                                       GTK_SHADOW_IN);
   gtk_table_attach(GTK_TABLE(table), swin, 1, 2, 5, 8,
                    GTK_EXPAND | GTK_SHRINK | GTK_FILL,
                    GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
                                  GTK_POLICY_NEVER,
                                  GTK_POLICY_AUTOMATIC);
   gtk_widget_show(swin);
   gtk_container_add(GTK_CONTAINER(swin), view);

   frame = gimp_frame_new(_("Map File Format"));
   gtk_widget_show(frame);
   gtk_table_attach_defaults(GTK_TABLE(table), frame, 0, 2, 9, 10);
   hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
   gtk_container_add(GTK_CONTAINER(frame), hbox);
   gtk_widget_show(hbox);

   data->ncsa = gtk_radio_button_new_with_mnemonic_from_widget(NULL, "_NCSA");
   g_signal_connect(data->ncsa, "toggled",
                    G_CALLBACK(type_toggled_cb), (gpointer) NCSA);
   gtk_box_pack_start(GTK_BOX(hbox), data->ncsa, FALSE, FALSE, 0);
   gtk_widget_show(data->ncsa);

   data->cern = gtk_radio_button_new_with_mnemonic_from_widget(
      GTK_RADIO_BUTTON(data->ncsa), "C_ERN");
   g_signal_connect(data->cern, "toggled",
                    G_CALLBACK(type_toggled_cb), (gpointer) CERN);
   gtk_box_pack_start(GTK_BOX(hbox), data->cern, FALSE, FALSE, 0);
   gtk_widget_show(data->cern);

   data->csim = gtk_radio_button_new_with_mnemonic_from_widget(
      GTK_RADIO_BUTTON(data->cern), "C_SIM");
   g_signal_connect(data->csim, "toggled",
                    G_CALLBACK(type_toggled_cb), (gpointer) CSIM);
   gtk_box_pack_start(GTK_BOX(hbox), data->csim, FALSE, FALSE, 0);
   gtk_widget_show(data->csim);

   return data;
}

void
do_settings_dialog(void)
{
   static SettingsDialog_t *dialog;
   const char *filename = get_filename();
   MapInfo_t *info = get_map_info();

   if (!dialog)
      dialog = create_settings_dialog();

   if (!filename)
     filename = _("<Untitled>");

   gtk_label_set_text(GTK_LABEL(dialog->filename), filename);
   browse_widget_set_filename(dialog->imagename, info->image_name);
   gtk_entry_set_text(GTK_ENTRY(dialog->title), info->title);
   gtk_entry_set_text(GTK_ENTRY(dialog->author), info->author);
   gtk_entry_set_text(GTK_ENTRY(dialog->default_url), info->default_url);

   if (info->map_format == NCSA)
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->ncsa), TRUE);
   else if (info->map_format == CERN)
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->cern), TRUE);
   else
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->csim), TRUE);

   gtk_widget_grab_focus(dialog->imagename->file);
   default_dialog_show(dialog->dialog);

   gtk_text_buffer_set_text (dialog->description, info->description, -1);
}