home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / plug-ins / common / uniteditor.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-01  |  19.3 KB  |  680 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * This is a plug-in for the GIMP.
  5.  *
  6.  * Copyright (C) 2000 Michael Natterer <mitch@gimp.org>
  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. #include "config.h"
  24. #include <string.h>
  25.  
  26. #include <gtk/gtk.h>
  27.  
  28. #include <libgimp/gimp.h>
  29. #include <libgimp/gimpui.h>
  30.  
  31. #include "libgimp/stdplugins-intl.h"
  32.  
  33. #include "pixmaps/new.xpm"
  34. #include "pixmaps/duplicate.xpm"
  35. #include "pixmaps/yes.xpm"
  36. #include "pixmaps/no.xpm"
  37.  
  38.  
  39. static void   query              (void);
  40. static void   run                (gchar   *name,
  41.                   gint     nparams,
  42.                   GimpParam  *param,
  43.                   gint    *nreturn_vals,
  44.                   GimpParam **return_vals);
  45.  
  46. static void   unit_editor_dialog (void);
  47.  
  48. GimpPlugInInfo PLUG_IN_INFO =
  49. {
  50.   NULL,  /* init_proc  */
  51.   NULL,  /* quit_proc  */
  52.   query, /* query_proc */
  53.   run,   /* run_proc   */
  54. };
  55.  
  56. MAIN ()
  57.  
  58. static void
  59. query (void)
  60. {
  61.   static GimpParamDef args[] =
  62.   {
  63.     { GIMP_PDB_INT32, "run_mode", "Interactive" }
  64.   };
  65.   static gint nargs = sizeof (args) / sizeof (args[0]);
  66.  
  67.   gimp_install_procedure ("extension_gimp_unit_editor",
  68.                           "The GIMP unit editor (runs in interactive mode only)",
  69.                           "The GIMP unit editor (runs in interactive mode only)",
  70.                           "Michael Natterer <mitch@gimp.org>",
  71.                           "Michael Natterer <mitch@gimp.org>",
  72.                           "2000",
  73.               N_("<Toolbox>/Xtns/Unit Editor..."),
  74.               "",
  75.                           GIMP_EXTENSION,
  76.               nargs, 0,
  77.                           args, NULL);
  78. }
  79.  
  80. static void
  81. run (gchar   *name,
  82.      gint     nparams,
  83.      GimpParam  *param,
  84.      gint    *nreturn_vals,
  85.      GimpParam **return_vals)
  86. {
  87.   static GimpParam  values[2];
  88.   GimpRunModeType   run_mode;
  89.  
  90.   run_mode = param[0].data.d_int32;
  91.  
  92.   *nreturn_vals = 1;
  93.   *return_vals  = values;
  94.   values[0].type          = GIMP_PDB_STATUS;
  95.   values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
  96.  
  97.   if (strcmp (name, "extension_gimp_unit_editor") == 0)
  98.     {
  99.       values[0].data.d_status = GIMP_PDB_SUCCESS;
  100.  
  101.       INIT_I18N_UI();
  102.  
  103.       unit_editor_dialog ();
  104.     }
  105. }
  106.  
  107. static GdkPixmap *yes_pixmap = NULL;
  108. static GdkBitmap *yes_mask   = NULL;
  109. static GdkPixmap *no_pixmap  = NULL;
  110. static GdkBitmap *no_mask    = NULL;
  111.  
  112. static GtkWidget *delete_button    = NULL;
  113. static GtkWidget *undelete_button  = NULL;
  114.  
  115. static GtkWidget *main_dialog = NULL;
  116. static GtkWidget *clist       = NULL;
  117. static GdkColor   color;
  118.  
  119. static GimpUnit   current_unit = GIMP_UNIT_INCH;
  120. static gint       current_row  = 0;
  121.  
  122. enum
  123. {
  124.   SAVE,
  125.   IDENTIFIER,
  126.   FACTOR,
  127.   DIGITS,
  128.   SYMBOL,
  129.   ABBREVIATION,
  130.   SINGULAR,
  131.   PLURAL,
  132.   NUM_FIELDS
  133. };
  134.  
  135. static gchar *help_strings[NUM_FIELDS];
  136.  
  137. static void
  138. new_unit_ok_callback (GtkWidget *widget,
  139.               gpointer   data)
  140. {
  141.   *((gboolean *) data) = TRUE;
  142.  
  143.   gtk_main_quit ();
  144. }
  145.  
  146. static GimpUnit
  147. new_unit (GimpUnit template)
  148. {
  149.   GtkWidget *dialog;
  150.   GtkWidget *table;
  151.   GtkWidget *entry;
  152.   GtkWidget *spinbutton;
  153.  
  154.   GtkWidget *identifier_entry;
  155.   GtkObject *factor_adj;
  156.   GtkObject *digits_adj;
  157.   GtkWidget *symbol_entry;
  158.   GtkWidget *abbreviation_entry;
  159.   GtkWidget *singular_entry;
  160.   GtkWidget *plural_entry;
  161.  
  162.   gchar    *str;
  163.   gboolean  ok   = FALSE;
  164.   GimpUnit  unit = GIMP_UNIT_PIXEL;
  165.  
  166.   gtk_widget_set_sensitive (main_dialog, FALSE);
  167.  
  168.   dialog = gimp_dialog_new (_("New Unit"), "uniteditor",
  169.                 gimp_standard_help_func, "filters/uniteditor.html",
  170.                 GTK_WIN_POS_MOUSE,
  171.                 FALSE, TRUE, FALSE,
  172.  
  173.                 _("OK"), new_unit_ok_callback,
  174.                 &ok, NULL, NULL, TRUE, FALSE,
  175.                 _("Cancel"), gtk_main_quit,
  176.                 NULL, 1, NULL, FALSE, TRUE,
  177.  
  178.                 NULL);
  179.  
  180.   table = gtk_table_new (7, 2, FALSE);
  181.   gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  182.   gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  183.   gtk_container_set_border_width (GTK_CONTAINER (table), 6);
  184.   gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), table,
  185.               FALSE, FALSE, 0);
  186.   gtk_widget_show (table);
  187.  
  188.   entry = identifier_entry = gtk_entry_new ();
  189.   if (template != GIMP_UNIT_PIXEL)
  190.     {
  191.       str = gimp_unit_get_identifier (template);
  192.       gtk_entry_set_text (GTK_ENTRY (entry), str);
  193.       g_free (str);
  194.     }
  195.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
  196.                  _("ID:"), 1.0, 0.5,
  197.                  entry, 1, FALSE);
  198.  
  199.   gimp_help_set_help_data (entry, help_strings[IDENTIFIER], NULL);
  200.  
  201.   spinbutton = gimp_spin_button_new (&factor_adj,
  202.                      (template != GIMP_UNIT_PIXEL) ?
  203.                      gimp_unit_get_factor (template) : 1.0,
  204.                      GIMP_MIN_RESOLUTION, GIMP_MAX_RESOLUTION,
  205.                      0.01, 0.1, 0.0, 0.01, 5);
  206.   gtk_widget_set_usize (spinbutton, 100, -1);
  207.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
  208.                  _("Factor:"), 1.0, 0.5,
  209.                  spinbutton, 1, TRUE);
  210.  
  211.   gimp_help_set_help_data (spinbutton, help_strings[FACTOR], NULL);
  212.  
  213.   spinbutton = gimp_spin_button_new (&digits_adj,
  214.                      (template != GIMP_UNIT_PIXEL) ?
  215.                      gimp_unit_get_digits (template) : 2.0,
  216.                      0, 5, 1, 1, 0, 1, 0);
  217.   gtk_widget_set_usize (spinbutton, 50, -1);
  218.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
  219.                  _("Digits:"), 1.0, 0.5,
  220.                  spinbutton, 1, TRUE);
  221.  
  222.   gimp_help_set_help_data (spinbutton, help_strings[DIGITS], NULL);
  223.  
  224.   entry = symbol_entry = gtk_entry_new ();
  225.   if (template != GIMP_UNIT_PIXEL)
  226.     {
  227.       str = gimp_unit_get_symbol (template);
  228.       gtk_entry_set_text (GTK_ENTRY (entry), str);
  229.       g_free (str);
  230.     }
  231.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
  232.                  _("Symbol:"), 1.0, 0.5,
  233.                  entry, 1, FALSE);
  234.  
  235.   gimp_help_set_help_data (entry, help_strings[SYMBOL], NULL);
  236.  
  237.   entry = abbreviation_entry = gtk_entry_new ();
  238.   if (template != GIMP_UNIT_PIXEL)
  239.     {
  240.       str = gimp_unit_get_abbreviation (template);
  241.       gtk_entry_set_text (GTK_ENTRY (entry), str);
  242.       g_free (str);
  243.     }
  244.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 4,
  245.                  _("Abbreviation:"), 1.0, 0.5,
  246.                  entry, 1, FALSE);
  247.  
  248.   gimp_help_set_help_data (entry, help_strings[ABBREVIATION], NULL);
  249.  
  250.   entry = singular_entry = gtk_entry_new ();
  251.   if (template != GIMP_UNIT_PIXEL)
  252.     {
  253.       str = gimp_unit_get_singular (template);
  254.       gtk_entry_set_text (GTK_ENTRY (entry), str);
  255.       g_free (str);
  256.     }
  257.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 5,
  258.                  _("Singular:"), 1.0, 0.5,
  259.                  entry, 1, FALSE);
  260.  
  261.   gimp_help_set_help_data (entry, help_strings[SINGULAR], NULL);
  262.  
  263.   entry = plural_entry = gtk_entry_new ();
  264.   if (template != GIMP_UNIT_PIXEL)
  265.     {
  266.       str = gimp_unit_get_plural (template);
  267.       gtk_entry_set_text (GTK_ENTRY (entry), str);
  268.       g_free (str);
  269.     }
  270.   gimp_table_attach_aligned (GTK_TABLE (table), 0, 6,
  271.                  _("Plural:"), 1.0, 0.5,
  272.                  entry, 1, FALSE);
  273.  
  274.   gimp_help_set_help_data (entry, help_strings[PLURAL], NULL);
  275.  
  276.   gtk_widget_show (dialog);
  277.  
  278.   while (1)
  279.     {
  280.       gtk_main ();
  281.  
  282.       if (ok)
  283.     {
  284.       gchar   *identifier;
  285.       gdouble  factor;
  286.       gint     digits;
  287.       gchar   *symbol;
  288.       gchar   *abbreviation;
  289.       gchar   *singular;
  290.       gchar   *plural;
  291.  
  292.       identifier   = gtk_entry_get_text (GTK_ENTRY (identifier_entry));
  293.       factor       = GTK_ADJUSTMENT (factor_adj)->value;
  294.       digits       = ROUND (GTK_ADJUSTMENT (digits_adj)->value);
  295.       symbol       = gtk_entry_get_text (GTK_ENTRY (symbol_entry));
  296.       abbreviation = gtk_entry_get_text (GTK_ENTRY (abbreviation_entry));
  297.       singular     = gtk_entry_get_text (GTK_ENTRY (singular_entry));
  298.       plural       = gtk_entry_get_text (GTK_ENTRY (plural_entry));
  299.  
  300.       identifier   = g_strstrip (g_strdup (identifier));
  301.       symbol       = g_strstrip (g_strdup (symbol));
  302.       abbreviation = g_strstrip (g_strdup (abbreviation));
  303.       singular     = g_strstrip (g_strdup (singular));
  304.       plural       = g_strstrip (g_strdup (plural));
  305.  
  306.       if (factor < GIMP_MIN_RESOLUTION)
  307.         {
  308.           g_message (_("Unit factor must not be 0."));
  309.           ok = FALSE;
  310.         }
  311.  
  312.       if (!strlen (identifier) |
  313.           !strlen (symbol) |
  314.           !strlen (abbreviation) |
  315.           !strlen (singular) |
  316.           !strlen (plural))
  317.         {
  318.           g_message (_("All text fields must contain a value."));
  319.           ok = FALSE;
  320.         }
  321.  
  322.       if (ok)
  323.         unit = gimp_unit_new (identifier, factor, digits,
  324.                   symbol, abbreviation,
  325.                   singular, plural);
  326.  
  327.       g_free (identifier);
  328.       g_free (symbol);
  329.       g_free (abbreviation);
  330.       g_free (singular);
  331.       g_free (plural);
  332.  
  333.       if (ok)
  334.         break;
  335.     }
  336.       else
  337.     {
  338.       break;
  339.     }
  340.     }
  341.  
  342.   gtk_widget_destroy (dialog);
  343.   gdk_flush ();
  344.  
  345.   gtk_widget_set_sensitive (main_dialog, TRUE);
  346.  
  347.   return unit;
  348. }
  349.  
  350. static void
  351. clist_init (void)
  352. {
  353.   gchar    *entries[8];
  354.   gint      num_units;
  355.   GimpUnit  unit;
  356.   gint      column_width;
  357.   gint      row;
  358.   gint      i;
  359.  
  360.   entries[0] = NULL;
  361.  
  362.   num_units = gimp_unit_get_number_of_units ();
  363.   for (unit = GIMP_UNIT_INCH; unit < num_units; unit++)
  364.     {
  365.       row = unit - GIMP_UNIT_INCH;
  366.  
  367.       entries[1] = gimp_unit_get_identifier (unit);
  368.       entries[2] = g_strdup_printf ("%.5f", gimp_unit_get_factor (unit));
  369.       entries[3] = g_strdup_printf ("%d", gimp_unit_get_digits (unit));
  370.       entries[4] = gimp_unit_get_symbol (unit);
  371.       entries[5] = gimp_unit_get_abbreviation (unit);
  372.       entries[6] = gimp_unit_get_singular (unit);
  373.       entries[7] = gimp_unit_get_plural (unit);
  374.  
  375.       gtk_clist_append (GTK_CLIST (clist), entries);
  376.       gtk_clist_set_row_data (GTK_CLIST (clist), row,
  377.                               (gpointer) unit);
  378.  
  379.       if (unit < gimp_unit_get_number_of_built_in_units ())
  380.     gtk_clist_set_background (GTK_CLIST (clist), row, &color);
  381.  
  382.       if (gimp_unit_get_deletion_flag (unit))
  383.     {
  384.       gtk_clist_set_pixmap (GTK_CLIST (clist), row, 0,
  385.                 no_pixmap, no_mask);
  386.     }
  387.       else
  388.     {
  389.       gtk_clist_set_pixmap (GTK_CLIST (clist), row, 0,
  390.                 yes_pixmap, yes_mask);
  391.     }
  392.  
  393.       for (i = 1; i < 8; i++)
  394.     g_free (entries[i]);
  395.     }
  396.  
  397.   for (i = 0; i < 8; i++)
  398.     {
  399.       column_width = gtk_clist_optimal_column_width (GTK_CLIST (clist), i);
  400.  
  401.       gtk_clist_set_column_width (GTK_CLIST (clist), i, column_width);
  402.     }
  403. }
  404.  
  405. static void
  406. select_row_callback (GtkWidget      *widget,
  407.              gint            row, 
  408.              gint            column, 
  409.              GdkEventButton *bevent,
  410.              gpointer        data)
  411. {
  412.   GimpUnit unit;
  413.   gboolean delete_sensitive   = TRUE;
  414.   gboolean undelete_sensitive = TRUE;
  415.  
  416.   current_row = row;
  417.  
  418.   unit = current_unit =
  419.     (GimpUnit) gtk_clist_get_row_data (GTK_CLIST (widget), row);
  420.  
  421.   if (unit < gimp_unit_get_number_of_built_in_units ())
  422.     {
  423.       delete_sensitive   = FALSE;
  424.       undelete_sensitive = FALSE;
  425.     }
  426.   else if (gimp_unit_get_deletion_flag (unit))
  427.     {
  428.       delete_sensitive = FALSE;
  429.       gtk_clist_set_pixmap (GTK_CLIST (clist), current_row, 0,
  430.                 no_pixmap, no_mask);
  431.     }
  432.   else
  433.     {
  434.       undelete_sensitive = FALSE;
  435.       gtk_clist_set_pixmap (GTK_CLIST (clist), current_row, 0,
  436.                 yes_pixmap, yes_mask);
  437.     }
  438.  
  439.   gtk_widget_set_sensitive (delete_button,    delete_sensitive);
  440.   gtk_widget_set_sensitive (undelete_button,  undelete_sensitive);
  441. }
  442.  
  443. static void
  444. refresh_callback (GtkWidget *widget,
  445.           gpointer   data)
  446. {
  447.   gtk_clist_clear (GTK_CLIST (clist));
  448.   clist_init ();
  449.   gtk_clist_select_row (GTK_CLIST (clist), 0, 0);
  450. }
  451.  
  452. static void
  453. new_callback (GtkWidget *widget,
  454.           gpointer   data)
  455. {
  456.   GimpUnit unit;
  457.  
  458.   unit = new_unit (GIMP_UNIT_PIXEL);
  459.  
  460.   if (unit != GIMP_UNIT_PIXEL)
  461.     {
  462.       refresh_callback (NULL, NULL);
  463.       gtk_clist_select_row (GTK_CLIST (clist), unit - GIMP_UNIT_INCH, 0);
  464.       gtk_clist_moveto (GTK_CLIST (clist), unit - GIMP_UNIT_INCH, -1, 0.5, 0.0);
  465.     }
  466. }
  467.  
  468. static void
  469. duplicate_callback (GtkWidget *widget,
  470.             gpointer   data)
  471. {
  472.   GimpUnit unit;
  473.  
  474.   unit = new_unit (current_unit);
  475.  
  476.   if (unit != GIMP_UNIT_PIXEL)
  477.     {
  478.       refresh_callback (NULL, NULL);
  479.       gtk_clist_select_row (GTK_CLIST (clist), unit - GIMP_UNIT_INCH, 0);
  480.       gtk_clist_moveto (GTK_CLIST (clist), unit - GIMP_UNIT_INCH, -1, 0.5, 0.0);
  481.     }
  482. }
  483.  
  484. static void
  485. delete_callback (GtkWidget *widget,
  486.          gpointer   data)
  487. {
  488.   gimp_unit_set_deletion_flag (current_unit, TRUE);
  489.   gtk_clist_set_pixmap (GTK_CLIST (clist), current_row, 0,
  490.             no_pixmap, no_mask);
  491.   gtk_clist_select_row (GTK_CLIST (clist), current_row, 0);
  492. }
  493.  
  494. static void
  495. undelete_callback (GtkWidget *widget,
  496.            gpointer   data)
  497. {
  498.   gimp_unit_set_deletion_flag (current_unit, FALSE);
  499.   gtk_clist_set_pixmap (GTK_CLIST (clist), current_row, 0,
  500.             yes_pixmap, yes_mask);
  501.   gtk_clist_select_row (GTK_CLIST (clist), current_row, 0);
  502. }
  503.  
  504. static void
  505. unit_editor_dialog (void)
  506. {
  507.   GtkWidget *main_vbox;
  508.   GtkWidget *scrolled_win;
  509.   GtkWidget *hbox;
  510.   GtkWidget *button;
  511.   GtkStyle  *style;
  512.  
  513.   gchar  *titles[NUM_FIELDS];
  514.   gint    i;
  515.  
  516.   gimp_ui_init ("uniteditor", FALSE);
  517.  
  518.   main_dialog =
  519.     gimp_dialog_new (_("Unit Editor"), "uniteditor",
  520.              gimp_standard_help_func, "filters/uniteditor.html",
  521.              GTK_WIN_POS_MOUSE,
  522.              FALSE, TRUE, TRUE,
  523.  
  524.              _("Refresh"), refresh_callback,
  525.              NULL, NULL, NULL, FALSE, FALSE,
  526.              _("Close"), gtk_widget_destroy,
  527.              NULL, 1, NULL, TRUE, TRUE,
  528.  
  529.              NULL);
  530.  
  531.   gtk_signal_connect (GTK_OBJECT (main_dialog), "destroy",
  532.                       GTK_SIGNAL_FUNC (gtk_main_quit),
  533.               NULL);
  534.  
  535.   gimp_help_init ();
  536.  
  537.   help_strings[SAVE]         = _("A unit definition will only be saved before "
  538.                  "GIMP exits if this column is checked.");
  539.   help_strings[IDENTIFIER]   = _("This string will be used to identify a "
  540.                  "unit in GIMP's configuration files.");
  541.   help_strings[FACTOR]       = _("How many units make up an inch.");
  542.   help_strings[DIGITS]       = _("This field is a hint for numerical input "
  543.                  "fields. It specifies how many decimal digits "
  544.                  "the input field should provide to get "
  545.                  "approximately the same accuracy as an "
  546.                  "\"inch\" input field with two decimal "
  547.                  "digits.");
  548.   help_strings[SYMBOL]       = _("The unit's symbol if it has one (e.g. \"'\" "
  549.                  "for inches). Use the unit's abbreviation if "
  550.                  "it doesn't have a symbol.");
  551.   help_strings[ABBREVIATION] = _("The unit's abbreviation (e.g. \"cm\" for "
  552.                  "centimeters).");
  553.   help_strings[SINGULAR]     = _("The unit's singular form.");
  554.   help_strings[PLURAL]       = _("The unit's plural form.");
  555.  
  556.   /*  the main vbox  */
  557.   main_vbox = gtk_vbox_new (FALSE, 4);
  558.   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 6);
  559.   gtk_container_add (GTK_CONTAINER (GTK_DIALOG (main_dialog)->vbox), main_vbox);
  560.   gtk_widget_show (main_vbox);
  561.  
  562.   /*  the selection list  */
  563.   scrolled_win = gtk_scrolled_window_new (NULL, NULL);
  564.   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
  565.                                   GTK_POLICY_NEVER,
  566.                                   GTK_POLICY_ALWAYS);
  567.   gtk_container_add (GTK_CONTAINER (main_vbox), scrolled_win);
  568.   gtk_widget_show (scrolled_win);
  569.  
  570.   titles[SAVE]         = _("Saved");
  571.   titles[IDENTIFIER]   = _("ID");
  572.   titles[FACTOR]       = _("Factor");
  573.   titles[DIGITS]       = _("Digits");
  574.   titles[SYMBOL]       = _("Symbol");
  575.   titles[ABBREVIATION] = _("Abbr.");
  576.   titles[SINGULAR]     = _("Singular");
  577.   titles[PLURAL]       = _("Plural");
  578.  
  579.   clist = gtk_clist_new_with_titles (NUM_FIELDS, titles);
  580.   gtk_clist_set_shadow_type (GTK_CLIST (clist), GTK_SHADOW_IN);
  581.   gtk_clist_set_selection_mode (GTK_CLIST (clist), GTK_SELECTION_BROWSE);
  582.   gtk_clist_column_titles_passive (GTK_CLIST (clist));
  583.  
  584.   /*  eek, passive column titles don't show a tooltip, so the next 3 lines
  585.    *  are useless...
  586.    */
  587.   for (i = 0; i < NUM_FIELDS; i++)
  588.     gimp_help_set_help_data (gtk_clist_get_column_widget (GTK_CLIST (clist), i),
  589.                  help_strings[i], NULL);
  590.  
  591.   gtk_widget_realize (main_dialog);
  592.   style = gtk_widget_get_style (main_dialog);
  593.  
  594.   yes_pixmap =  gdk_pixmap_create_from_xpm_d (main_dialog->window,
  595.                           &yes_mask,
  596.                           &style->bg[GTK_STATE_NORMAL],
  597.                           yes_xpm);
  598.  
  599.   no_pixmap =  gdk_pixmap_create_from_xpm_d (main_dialog->window,
  600.                          &no_mask,
  601.                          &style->bg[GTK_STATE_NORMAL],
  602.                          no_xpm);
  603.  
  604.   color.red   = 65535;
  605.   color.green = 50000;
  606.   color.blue  = 50000;
  607.  
  608.   gdk_color_alloc (gtk_widget_get_colormap (main_dialog), &color);
  609.  
  610.   clist_init ();
  611.  
  612.   gtk_widget_set_usize (clist, -1, 200);
  613.  
  614.   gtk_container_add (GTK_CONTAINER (scrolled_win), clist);
  615.   gtk_signal_connect (GTK_OBJECT (clist), "select_row",
  616.                       GTK_SIGNAL_FUNC (select_row_callback),
  617.                       NULL);
  618.   gtk_widget_show (clist);
  619.  
  620.   hbox = gtk_hbox_new (FALSE, 2);
  621.   gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
  622.   gtk_widget_show (hbox);
  623.  
  624.   button = gimp_pixmap_button_new (new_xpm, _("New Unit"));
  625.   gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  626.   gtk_signal_connect (GTK_OBJECT (button), "clicked",
  627.               GTK_SIGNAL_FUNC (new_callback),
  628.               NULL);
  629.   gtk_widget_show (button);
  630.  
  631.   gimp_help_set_help_data (button, _("Create a new unit from scratch."), NULL);
  632.  
  633.   button = gimp_pixmap_button_new (duplicate_xpm, _("Duplicate Unit"));
  634.   gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  635.   gtk_signal_connect (GTK_OBJECT (button), "clicked",
  636.               GTK_SIGNAL_FUNC (duplicate_callback),
  637.               NULL);
  638.   gtk_widget_show (button);
  639.  
  640.   gimp_help_set_help_data (button, _("Create a new unit with the currently "
  641.                      "seleted unit as template."), NULL);
  642.  
  643.   button = gimp_pixmap_button_new (no_xpm, _("Don't Save Unit"));
  644.   gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  645.   gtk_signal_connect (GTK_OBJECT (button), "clicked",
  646.               GTK_SIGNAL_FUNC (delete_callback),
  647.               NULL);
  648.   gtk_widget_show (button);
  649.  
  650.   gimp_help_set_help_data (button, _("Don't save the currently selected unit "
  651.                      "before GIMP exits."), NULL);
  652.  
  653.   delete_button = button;
  654.  
  655.   button = gimp_pixmap_button_new (yes_xpm, _("Save Unit"));
  656.   gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  657.   gtk_signal_connect (GTK_OBJECT (button), "clicked",
  658.               GTK_SIGNAL_FUNC (undelete_callback),
  659.               NULL);
  660.   gtk_widget_show (button);
  661.  
  662.   gimp_help_set_help_data (button, _("Save the currently selected unit "
  663.                      "before GIMP exits."), NULL);
  664.  
  665.   undelete_button = button;
  666.  
  667.   gtk_clist_select_row (GTK_CLIST (clist), 0, 0);
  668.  
  669.   gtk_widget_show (main_dialog);
  670.  
  671.   gtk_main ();
  672.   gimp_help_free ();
  673.   gdk_flush ();
  674.  
  675.   gdk_pixmap_unref (yes_pixmap);
  676.   gdk_bitmap_unref (yes_mask);
  677.   gdk_pixmap_unref (no_pixmap);
  678.   gdk_bitmap_unref (no_mask);
  679. }
  680.