Updated Spanish translation
[anjuta-git-plugin.git] / plugins / class-inheritance / class-callbacks.c
blobf63799fdf1c26546c9a96535dbc845b4db7dc294
1 /*
2 * Copyright (C) Massimo Cora' 2005 <maxcvs@email.it>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include <glib.h>
20 #include <libanjuta/anjuta-debug.h>
21 #include <libanjuta/interfaces/ianjuta-document-manager.h>
22 #include <libanjuta/interfaces/ianjuta-symbol-manager.h>
24 #include "plugin.h"
25 #include "class-callbacks.h"
26 #include "class-inherit.h"
30 gint
31 on_canvas_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
33 AnjutaClassInheritance *plugin;
34 plugin = ANJUTA_PLUGIN_CLASS_INHERITANCE (data);
36 switch (event->type)
38 case GDK_BUTTON_PRESS:
39 if (event->button.button == 3)
41 g_return_val_if_fail (plugin->menu != NULL, FALSE);
43 gtk_menu_popup (GTK_MENU (plugin->menu), NULL, NULL, NULL, NULL,
44 event->button.button, event->button.time);
46 break;
48 default:
49 break;
52 return FALSE;
55 void
56 on_toggled_menuitem_clicked (GtkCheckMenuItem *checkmenuitem,
57 gpointer data)
59 NodeData *node;
60 node = (NodeData*)data;
62 if (node->name == NULL || g_str_equal (node->name, ""))
63 return;
65 if (node->anchored) {
66 node->anchored = FALSE;
68 /* remove the key from the hash table, if present */
69 if (g_hash_table_lookup (node->plugin->expansion_node_list, node->name)) {
70 g_hash_table_remove (node->plugin->expansion_node_list, node->name);
73 else {
74 NodeExpansionStatus *node_status;
75 node->anchored = TRUE;
77 node_status = g_new0 (NodeExpansionStatus, 1);
78 node_status->name = g_strdup (node->name);
79 /* set to half. This will display at least NODE_HALF_DISPLAY_ELEM_NUM.
80 * User will decide whether to show all elements or not. */
81 node_status->expansion_status = NODE_HALF_EXPANDED;
83 /* insert the class name to the hash_table */
84 g_hash_table_insert (node->plugin->expansion_node_list,
85 g_strdup (node->name),
86 node_status);
89 class_inheritance_update_graph (node->plugin);
92 void
93 on_member_menuitem_clicked (GtkMenuItem *menuitem, gpointer data)
95 NodeData *node;
96 const gchar *file;
97 gint line;
99 node = (NodeData*)data;
100 file = g_object_get_data (G_OBJECT (menuitem), "__file");
101 line = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menuitem), "__line"));
102 if (file)
104 /* Goto file line */
105 IAnjutaDocumentManager *dm;
106 dm = anjuta_shell_get_interface (ANJUTA_PLUGIN (node->plugin)->shell,
107 IAnjutaDocumentManager, NULL);
108 if (dm)
110 ianjuta_document_manager_goto_file_line (dm, file, line, NULL);
115 gint
116 on_nodedata_expanded_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
118 AnjutaClassInheritance *plugin;
119 NodeData *nodedata;
120 nodedata = (NodeData*)data;
121 plugin = nodedata->plugin;
123 switch (event->type)
125 case GDK_2BUTTON_PRESS: /* double click */
126 break;
128 case GDK_BUTTON_PRESS: /* single click */
129 if (event->button.button == 1) {
130 NodeExpansionStatus *node_status;
131 if ( (node_status = (NodeExpansionStatus*)g_hash_table_lookup (plugin->expansion_node_list,
132 nodedata->name)) == NULL) {
133 break;
135 else
136 if (strcmp (nodedata->sub_item, NODE_SHOW_ALL_MEMBERS_STR) == 0) {
137 node_status->expansion_status = NODE_FULL_EXPANDED;
138 class_inheritance_update_graph (plugin);
140 else
141 if (strcmp (nodedata->sub_item, NODE_SHOW_NORMAL_VIEW_STR) == 0) {
142 g_hash_table_remove (plugin->expansion_node_list, nodedata->name);
143 class_inheritance_update_graph (plugin);
145 else { /* it's a class member. Take line && file of definition
146 * and reach them */
147 const gchar* file;
148 gint line;
150 file = g_object_get_data (G_OBJECT (item), "__file");
151 line = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "__line"));
152 if (file) {
153 /* Goto file line */
154 IAnjutaDocumentManager *dm;
155 dm = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
156 IAnjutaDocumentManager, NULL);
157 if (dm) {
158 ianjuta_document_manager_goto_file_line (dm, file, line, NULL);
163 break;
165 case GDK_ENTER_NOTIFY: /* mouse entered in item's area */
166 gnome_canvas_item_set (nodedata->canvas_item,
167 "fill_color_gdk",
168 &plugin->canvas->style->base[GTK_STATE_PRELIGHT],
169 NULL);
170 return TRUE;
172 case GDK_LEAVE_NOTIFY: /* mouse exited item's area */
173 gnome_canvas_item_set (nodedata->canvas_item,
174 "fill_color_gdk",
175 &plugin->canvas->style->base[GTK_STATE_ACTIVE],
176 NULL);
177 return TRUE;
178 default:
179 break;
182 return FALSE;
187 gint
188 on_nodedata_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
190 AnjutaClassInheritance *plugin;
191 NodeData *nodedata;
193 nodedata = (NodeData*)data;
194 plugin = nodedata->plugin;
196 switch (event->type)
198 case GDK_2BUTTON_PRESS: /* double click */
199 break;
201 case GDK_BUTTON_PRESS: /* single click */
202 if (event->button.button == 1 && !nodedata->anchored)
204 class_inheritance_show_dynamic_class_popup_menu (event, data);
206 break;
208 case GDK_ENTER_NOTIFY: /* mouse entered in item's area */
209 /* Make the outline wide */
210 gnome_canvas_item_set (nodedata->canvas_item,
211 "width_units", 2.5,
212 "fill_color_gdk",
213 &plugin->canvas->style->base[GTK_STATE_PRELIGHT],
214 "outline_color_gdk",
215 &plugin->canvas->style->text[GTK_STATE_PRELIGHT],
216 NULL);
217 return TRUE;
219 case GDK_LEAVE_NOTIFY: /* mouse exited item's area */
220 /* Make the outline thin */
221 gnome_canvas_item_set (nodedata->canvas_item,
222 "width_units", 1.0,
223 "fill_color_gdk",
224 &plugin->canvas->style->base[GTK_STATE_NORMAL],
225 "outline_color_gdk",
226 &plugin->canvas->style->text[GTK_STATE_NORMAL],
227 NULL);
228 return TRUE;
229 default:
230 break;
233 return FALSE;
237 /*----------------------------------------------------------------------------
238 * callback for the canvas' right-click menu - update button.
240 void
241 on_update_menu_item_selected (GtkMenuItem *item,
242 AnjutaClassInheritance *plugin)
244 class_inheritance_update_graph (plugin);
247 /*----------------------------------------------------------------------------
248 * callback for theme/colors changes
250 void
251 on_style_set (GtkWidget *widget, GtkStyle *previous_style,
252 AnjutaClassInheritance *plugin)
254 class_inheritance_update_graph (plugin);