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_toolbar.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-23  |  6.3 KB  |  185 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 "libgimp/stdplugins-intl.h"
  26. #include "imap_main.h"
  27. #include "imap_misc.h"
  28. #include "imap_toolbar.h"
  29.  
  30. #include "copy.xpm"
  31. #include "cut.xpm"
  32. #include "grid.xpm"
  33. #include "map_info.xpm"
  34. #include "open.xpm"
  35. #include "paste.xpm"
  36. #include "save.xpm"
  37. #include "preferences.xpm"
  38. #include "redo.xpm"
  39. #include "to_back.xpm"
  40. #include "to_front.xpm"
  41. #include "undo.xpm"
  42. #include "zoom_in.xpm"
  43. #include "zoom_out.xpm"
  44.  
  45. static gboolean _command_lock;
  46.  
  47. static void
  48. toolbar_command(GtkWidget *widget, gpointer data)
  49. {
  50.    if (_command_lock) {
  51.       _command_lock = FALSE;
  52.    } else {
  53.       CommandFactory_t *factory = (CommandFactory_t*) data;
  54.       Command_t *command = (*factory)();
  55.       command_execute(command);
  56.    }
  57. }
  58.  
  59. static void
  60. paste_buffer_added(Object_t *obj, gpointer data)
  61. {
  62.    gtk_widget_set_sensitive((GtkWidget*) data, TRUE);
  63. }
  64.  
  65. static void
  66. paste_buffer_removed(Object_t *obj, gpointer data)
  67. {
  68.    gtk_widget_set_sensitive((GtkWidget*) data, FALSE);
  69. }
  70.  
  71. static void
  72. command_list_changed(Command_t *command, gpointer data)
  73. {
  74.    ToolBar_t *toolbar = (ToolBar_t*) data;
  75.  
  76.    /* Set undo entry */
  77.    gtk_widget_set_sensitive(toolbar->undo, (command != NULL));
  78.  
  79.    /* Set redo entry */
  80.    command = command_list_get_redo_command();
  81.    gtk_widget_set_sensitive(toolbar->redo, (command != NULL));
  82. }
  83.  
  84. void
  85. toolbar_shapes_selected(ToolBar_t *toolbar, gint count)
  86. {
  87.    gint sensitive = (count > 0);
  88.    gtk_widget_set_sensitive(toolbar->cut, sensitive);
  89.    gtk_widget_set_sensitive(toolbar->copy, sensitive);
  90.    gtk_widget_set_sensitive(toolbar->to_front, sensitive);
  91.    gtk_widget_set_sensitive(toolbar->to_back, sensitive);
  92. }
  93.  
  94. ToolBar_t*
  95. make_toolbar(GtkWidget *main_vbox, GtkWidget *window)
  96. {
  97.    ToolBar_t     *data = g_new(ToolBar_t, 1);
  98.    GtkWidget     *handlebox, *toolbar, *paste;
  99.  
  100.    handlebox = gtk_handle_box_new();
  101.    gtk_box_pack_start(GTK_BOX(main_vbox), handlebox, FALSE, FALSE, 0);
  102.    data->toolbar = toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, 
  103.                          GTK_TOOLBAR_ICONS);
  104.  
  105.    gtk_container_set_border_width(GTK_CONTAINER(toolbar), 5);
  106.    gtk_toolbar_set_space_size(GTK_TOOLBAR(toolbar), 8);
  107.    gtk_container_add(GTK_CONTAINER(handlebox), toolbar);
  108.  
  109.    make_toolbar_icon(toolbar, window, open_xpm, "Open",
  110.              _("Open"), toolbar_command, &data->cmd_open);
  111.    make_toolbar_icon(toolbar, window, save_xpm, "Save",
  112.              _("Save"), toolbar_command, &data->cmd_save);
  113.    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  114.    make_toolbar_icon(toolbar, window, preferences_xpm, "Preferences",
  115.              _("Preferences"), toolbar_command, 
  116.              &data->cmd_preferences);
  117.  
  118.    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  119.    data->undo = make_toolbar_icon(toolbar, window, undo_xpm, "Undo", 
  120.                   _("Undo"), toolbar_command, &data->cmd_undo);
  121.    gtk_widget_set_sensitive(data->undo, FALSE);
  122.    data->redo = make_toolbar_icon(toolbar, window, redo_xpm, "Redo", 
  123.                  _("Redo"), toolbar_command, &data->cmd_redo);
  124.    gtk_widget_set_sensitive(data->redo, FALSE);
  125.    command_list_add_update_cb(command_list_changed, data);
  126.  
  127.    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  128.    data->cut = make_toolbar_icon(toolbar, window, cut_xpm, "Cut", 
  129.                  _("Cut"), toolbar_command, &data->cmd_cut);
  130.    gtk_widget_set_sensitive(data->cut, FALSE);
  131.    data->copy = make_toolbar_icon(toolbar, window, copy_xpm, "Copy", 
  132.                   _("Copy"), toolbar_command, &data->cmd_copy);
  133.    gtk_widget_set_sensitive(data->copy, FALSE);
  134.    paste = make_toolbar_icon(toolbar, window, paste_xpm, "Paste", 
  135.                  _("Paste"), toolbar_command, &data->cmd_paste);
  136.    gtk_widget_set_sensitive(paste, FALSE);
  137.    paste_buffer_add_add_cb(paste_buffer_added, (gpointer) paste);
  138.    paste_buffer_add_remove_cb(paste_buffer_removed, (gpointer) paste);
  139.  
  140.    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  141.    data->zoom_in = make_toolbar_icon(toolbar, window, zoom_in_xpm, "ZoomIn",
  142.                      _("Zoom in"), toolbar_command, 
  143.                      &data->cmd_zoom_in);
  144.    data->zoom_out = make_toolbar_icon(toolbar, window, zoom_out_xpm, "ZoomOut",
  145.                       _("Zoom out"), toolbar_command, 
  146.                       &data->cmd_zoom_out);
  147.    gtk_widget_set_sensitive(data->zoom_out, FALSE);
  148.    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  149.    make_toolbar_icon(toolbar, window, map_info_xpm, "EditMapInfo",
  150.              _("Edit Map Info"), toolbar_command, 
  151.              &data->cmd_edit_map_info);
  152.    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  153.    data->to_front = make_toolbar_icon(toolbar, window, to_front_xpm, "ToFront",
  154.                       _("Move To Front"), toolbar_command,
  155.                       &data->cmd_move_to_front);
  156.    gtk_widget_set_sensitive(data->to_front, FALSE);
  157.    data->to_back = make_toolbar_icon(toolbar, window, to_back_xpm, "ToBack",
  158.                      _("Send To Back"), toolbar_command, 
  159.                      &data->cmd_send_to_back);
  160.    gtk_widget_set_sensitive(data->to_back, FALSE);
  161.    gtk_toolbar_append_space(GTK_TOOLBAR(toolbar));
  162.    data->grid = make_toolbar_toggle_icon(toolbar, window, grid_xpm, "Grid",
  163.                      _("Grid"), toolbar_command, 
  164.                      &data->cmd_grid);
  165.  
  166.    gtk_widget_show(toolbar);
  167.    gtk_widget_show(handlebox);
  168.  
  169.    return data;
  170. }
  171.  
  172. void 
  173. toolbar_set_zoom_sensitivity(ToolBar_t *toolbar, gint factor)
  174. {
  175.    gtk_widget_set_sensitive(toolbar->zoom_in, factor < 8);
  176.    gtk_widget_set_sensitive(toolbar->zoom_out, factor > 1);
  177. }
  178.  
  179. void 
  180. toolbar_set_grid(ToolBar_t *toolbar, gboolean active)
  181. {
  182.    _command_lock = TRUE;
  183.    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toolbar->grid), active);
  184. }
  185.