~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to plug-ins/imagemap/imap_object_popup.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

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