home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / imagemap / imap_settings.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-22  |  6.3 KB  |  169 lines

  1. /*
  2.  * This is a plug-in for the GIMP.
  3.  *
  4.  * Generates clickable image maps.
  5.  *
  6.  * Copyright (C) 1998-1999 Maurits Rijk  lpeek.mrijk@consunet.nl
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  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.
  17.  *
  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21.  *
  22.  */
  23.  
  24. #include "config.h"
  25. #include "imap_browse.h"
  26. #include "libgimp/stdplugins-intl.h"
  27. #include "imap_main.h"
  28. #include "imap_settings.h"
  29. #include "imap_string.h"
  30. #include "imap_table.h"
  31.  
  32.  
  33. static MapFormat_t _map_format = CSIM;
  34.  
  35. static void
  36. settings_ok_cb(gpointer data)
  37. {
  38.    SettingsDialog_t *param = (SettingsDialog_t*) data;
  39.    MapInfo_t *info = get_map_info();
  40.  
  41.    g_strreplace(&info->image_name, gtk_entry_get_text(
  42.       GTK_ENTRY(param->imagename->file)));
  43.    g_strreplace(&info->title, gtk_entry_get_text(GTK_ENTRY(param->title)));
  44.    g_strreplace(&info->author, gtk_entry_get_text(GTK_ENTRY(param->author)));
  45.    g_strreplace(&info->default_url, 
  46.         gtk_entry_get_text(GTK_ENTRY(param->default_url)));
  47.    g_strreplace(&info->description, 
  48.         gtk_editable_get_chars(GTK_EDITABLE(param->description), 
  49.                        0, -1));
  50.    info->map_format = _map_format;
  51. }
  52.  
  53. static void
  54. type_toggled_cb(GtkWidget *widget, gpointer data)
  55. {
  56.    if (GTK_WIDGET_STATE(widget) & GTK_STATE_SELECTED)
  57.       _map_format = (MapFormat_t) data;
  58. }
  59.  
  60. static SettingsDialog_t*
  61. make_settings_dialog()
  62. {
  63.    SettingsDialog_t *data = g_new(SettingsDialog_t, 1);
  64.    GtkWidget *table, *vscrollbar, *frame, *hbox;
  65.    DefaultDialog_t *dialog;
  66.    GSList    *group;
  67.  
  68.    dialog = data->dialog = make_default_dialog(_("Settings for this Mapfile"));
  69.    default_dialog_set_ok_cb(dialog, settings_ok_cb, (gpointer) data);
  70.  
  71.    table = gtk_table_new(9, 3, FALSE);
  72.    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog->dialog)->vbox), 
  73.              table);
  74.    gtk_table_set_row_spacings(GTK_TABLE(table), 10);
  75.    gtk_table_set_col_spacings(GTK_TABLE(table), 10);
  76.    gtk_container_set_border_width(GTK_CONTAINER(table), 10);
  77.    gtk_widget_show(table);
  78.  
  79.    create_label_in_table(table, 0, 0, _("Filename:"));
  80.    data->filename = create_label_in_table(table, 0, 1, "");
  81.  
  82.    create_label_in_table(table, 1, 0, _("Image name:"));
  83.    data->imagename = browse_widget_new(_("Select Image File"));
  84.    gtk_table_attach_defaults(GTK_TABLE(table), data->imagename->hbox, 1, 2, 
  85.                  1, 2);
  86.  
  87.    create_label_in_table(table, 2, 0, _("Title:"));
  88.    data->title = create_entry_in_table(table, 2, 1);
  89.    create_label_in_table(table, 3, 0, _("Author:"));
  90.    data->author = create_entry_in_table(table, 3, 1);
  91.    create_label_in_table(table, 4, 0, _("Default URL:"));
  92.    data->default_url = create_entry_in_table(table, 4, 1);
  93.    create_label_in_table(table, 5, 0, _("Description:"));
  94.  
  95.    data->description = gtk_text_new(NULL, NULL);
  96.    gtk_text_set_editable(GTK_TEXT(data->description), TRUE);
  97.    gtk_table_attach(GTK_TABLE(table), data->description, 1, 2, 5, 8,
  98.             GTK_EXPAND | GTK_SHRINK | GTK_FILL,
  99.             GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
  100.    gtk_widget_show(data->description);
  101.  
  102.    /* Add a vertical scrollbar to the GtkText widget */
  103.    vscrollbar = gtk_vscrollbar_new(GTK_TEXT(data->description)->vadj);
  104.    gtk_table_attach(GTK_TABLE(table), vscrollbar, 2, 3, 5, 8,
  105.             GTK_FILL, GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
  106.    gtk_widget_show(vscrollbar);
  107.  
  108.    frame = gtk_frame_new(_("Map file format"));
  109.    gtk_widget_show(frame);
  110.    gtk_table_attach_defaults(GTK_TABLE(table), frame, 1, 2, 9, 10);
  111.    hbox = gtk_hbox_new(FALSE, 1);
  112.    gtk_container_add(GTK_CONTAINER(frame), hbox);
  113.    gtk_widget_show(hbox);
  114.  
  115.    data->ncsa = gtk_radio_button_new_with_label(NULL, "NCSA");
  116.    gtk_signal_connect(GTK_OBJECT(data->ncsa), "toggled", 
  117.               (GtkSignalFunc) type_toggled_cb, (gpointer) NCSA);
  118.    gtk_box_pack_start(GTK_BOX(hbox), data->ncsa, TRUE, TRUE, 10);
  119.    gtk_widget_show(data->ncsa);
  120.  
  121.    group = gtk_radio_button_group(GTK_RADIO_BUTTON(data->ncsa));
  122.    data->cern = gtk_radio_button_new_with_label(group, "CERN");
  123.    gtk_signal_connect(GTK_OBJECT(data->cern), "toggled", 
  124.               (GtkSignalFunc) type_toggled_cb, (gpointer) CERN);
  125.    gtk_box_pack_start(GTK_BOX(hbox), data->cern, TRUE, TRUE, 10);
  126.    gtk_widget_show(data->cern);
  127.  
  128.    group = gtk_radio_button_group(GTK_RADIO_BUTTON(data->cern));
  129.    data->csim = gtk_radio_button_new_with_label(group, "CSIM");
  130.    gtk_signal_connect(GTK_OBJECT(data->csim), "toggled", 
  131.               (GtkSignalFunc) type_toggled_cb, (gpointer) CSIM);
  132.    gtk_box_pack_start(GTK_BOX(hbox), data->csim, TRUE, TRUE, 10);
  133.    gtk_widget_show(data->csim);
  134.  
  135.    return data;
  136. }
  137.  
  138. void
  139. do_settings_dialog(void)
  140. {
  141.    static SettingsDialog_t *dialog;
  142.    const char *filename = get_filename();
  143.    MapInfo_t *info = get_map_info();
  144.  
  145.    if (!dialog)
  146.       dialog = make_settings_dialog();
  147.  
  148.    gtk_label_set_text(GTK_LABEL(dialog->filename), 
  149.               (filename) ? filename : _("<Untitled>"));
  150.    browse_widget_set_filename(dialog->imagename, info->image_name);
  151.    gtk_entry_set_text(GTK_ENTRY(dialog->title), info->title);
  152.    gtk_entry_set_text(GTK_ENTRY(dialog->author), info->author);
  153.    gtk_entry_set_text(GTK_ENTRY(dialog->default_url), info->default_url);
  154.  
  155.    if (info->map_format == NCSA)
  156.       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->ncsa), TRUE);
  157.    else if (info->map_format == CERN)
  158.       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->cern), TRUE);
  159.    else
  160.       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dialog->csim), TRUE);
  161.  
  162.    gtk_widget_grab_focus(dialog->imagename->file);
  163.    default_dialog_show(dialog->dialog);
  164.  
  165.    gtk_editable_delete_text(GTK_EDITABLE(dialog->description), 0, -1);
  166.    gtk_text_insert(GTK_TEXT(dialog->description), NULL, NULL, NULL,
  167.            info->description, -1);
  168. }
  169.