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_object_popup.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-22  |  3.8 KB  |  140 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 "imap_cmd_copy_object.h"
  25. #include "imap_cmd_cut_object.h"
  26. #include "imap_cmd_object_down.h"
  27. #include "imap_cmd_object_up.h"
  28. #include "imap_main.h"
  29. #include "imap_object_popup.h"
  30.  
  31. /* Current object with popup menu */
  32. static Object_t *_current_obj;
  33.  
  34. Object_t*
  35. get_popup_object(void)
  36. {
  37.    return _current_obj;
  38. }
  39.  
  40. static void
  41. popup_edit_area_info(GtkWidget *widget, gpointer data)
  42. {
  43.    object_edit(_current_obj, TRUE);
  44. }
  45.  
  46. static void
  47. popup_delete_area(GtkWidget *widget, gpointer data)
  48. {
  49.    if (_current_obj->locked) {
  50.       do_object_locked_dialog();
  51.    } else {
  52.       object_remove(_current_obj);
  53.       redraw_preview();
  54.    }
  55. }
  56.  
  57. static void
  58. popup_move_up(GtkWidget *widget, gpointer data)
  59. {
  60.    Command_t *command = object_up_command_new(_current_obj->list, 
  61.                           _current_obj);
  62.    command_execute(command);
  63. }
  64.  
  65. static void
  66. popup_move_down(GtkWidget *widget, gpointer data)
  67. {
  68.    Command_t *command = object_down_command_new(_current_obj->list,
  69.                         _current_obj);
  70.    command_execute(command);
  71. }
  72.  
  73. static void
  74. popup_cut(GtkWidget *widget, gpointer data)
  75. {
  76.    if (_current_obj->locked) {
  77.       do_object_locked_dialog();
  78.    } else {
  79.       Command_t *command = cut_object_command_new(_current_obj);
  80.       command_execute(command);
  81.    }
  82. }
  83.  
  84. static void
  85. popup_copy(GtkWidget *widget, gpointer data)
  86. {
  87.    Command_t *command = copy_object_command_new(_current_obj);
  88.    command_execute(command);
  89. }
  90.  
  91. ObjectPopup_t*
  92. make_object_popup(void)
  93. {
  94.    ObjectPopup_t *popup = g_new(ObjectPopup_t, 1);
  95.    GtkWidget *menu;
  96.  
  97.    popup->menu = menu = gtk_menu_new();
  98.    make_item_with_label(menu, "Edit Area Info...", popup_edit_area_info, NULL);
  99.    make_item_with_label(menu, "Delete Area", popup_delete_area, NULL);
  100.    popup->up = make_item_with_label(menu, "Move Up", popup_move_up, NULL);
  101.    popup->down = make_item_with_label(menu, "Move Down", popup_move_down, 
  102.                       NULL);
  103.    make_item_with_label(menu, "Cut", popup_cut, NULL);
  104.    make_item_with_label(menu, "Copy", popup_copy, NULL);
  105.  
  106.    return popup;
  107. }
  108.  
  109. GtkWidget*
  110. object_popup_prepend_menu(ObjectPopup_t *popup, gchar *label, 
  111.               MenuCallback activate, gpointer data)
  112. {
  113.    return prepend_item_with_label(popup->menu, label, activate, data);
  114. }
  115.  
  116. void
  117. object_handle_popup(ObjectPopup_t *popup, Object_t *obj, GdkEventButton *event)
  118. {
  119.    int position = object_get_position_in_list(obj) + 1;
  120.  
  121.    _current_obj = popup->obj = obj;
  122.    gtk_widget_set_sensitive(popup->up, (position > 1) ? TRUE : FALSE);
  123.    gtk_widget_set_sensitive(popup->down, 
  124.                 (position < g_list_length(obj->list->list)) 
  125.                 ? TRUE : FALSE);
  126.  
  127.    gtk_menu_popup(GTK_MENU(popup->menu), NULL, NULL, NULL, NULL,
  128.           event->button, event->time);
  129. }
  130.  
  131. void 
  132. object_do_popup(Object_t *obj, GdkEventButton *event)
  133. {
  134.    static ObjectPopup_t *popup;
  135.  
  136.    if (!popup)
  137.       popup = make_object_popup();
  138.    object_handle_popup(popup, obj, event);
  139. }
  140.