]> matita.cs.unibo.it Git - helm.git/blob - helm/gtkmathview-bonobo/src/handlers.c
* using the clipboard to communicate the id of the selected subtree
[helm.git] / helm / gtkmathview-bonobo / src / handlers.c
1
2 #include "handlers.h"
3
4 static void
5 set_clipboard(GdomeDOMString* data)
6 {
7   GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
8   gtk_clipboard_set_text(clipboard, data->str, gdome_str_length(data));
9 }
10
11 void
12 set_frame(BonoboControl *control, gpointer data)
13 {     
14 }
15
16 void
17 click_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
18          GtkMathViewControlData* control_data)
19 {
20   GdomeException exc = 0;
21   
22   g_return_if_fail(math_view != NULL);
23   g_return_if_fail(control_data != NULL);
24   
25   if (elem != NULL)
26     {
27       GdomeElement* action;
28       GdomeDOMString* href = find_hyperlink(elem);
29
30       if (href != NULL)
31         {
32           /*gtk_math_view_load_uri(math_view,href->str);*/
33           set_clipboard(href);
34           gdome_str_unref(href);
35           return;
36         }
37
38       action = find_self_or_ancestor(elem, MATHML_NS_URI, "maction");
39       if (action != NULL)
40         {
41           gtk_math_view_freeze(math_view);
42           action_toggle(action);
43           gtk_math_view_thaw(math_view);
44           gdome_el_unref(action, &exc);
45           g_assert(exc == 0);
46           return;
47         }
48     }
49     
50   if (control_data->root_selected != NULL)
51     {
52       gtk_math_view_freeze(math_view);
53       gtk_math_view_unselect(math_view, control_data->root_selected);
54       gtk_math_view_thaw(math_view);
55       gdome_el_unref(control_data->root_selected, &exc);
56       g_assert(exc == 0);
57       control_data->root_selected = NULL;
58     }
59 }
60
61 void
62 select_begin_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
63                 GtkMathViewControlData* control_data)
64 {
65   g_return_if_fail(math_view != NULL);
66   g_return_if_fail(control_data != NULL);
67
68   if (elem != NULL)
69     {
70       GdomeException exc = 0;
71       gtk_math_view_freeze(math_view);
72       if (control_data->root_selected != NULL)
73         {
74           gtk_math_view_unselect(math_view, control_data->root_selected);
75           gdome_el_unref(control_data->root_selected, &exc);
76           g_assert(exc == 0);
77           control_data->root_selected = NULL;
78         }
79       
80       if (control_data->id_ns_uri != NULL || control_data->id_name != NULL)
81         {
82           GdomeElement* new_elem = find_element_with_id(elem, control_data->id_ns_uri, control_data->id_name);
83           if (new_elem != NULL)
84             {
85               gdome_el_ref(new_elem, &exc);
86               g_assert(exc == 0);
87             }
88           control_data->first_selected = control_data->root_selected = new_elem;
89         }
90       else
91         {
92           gdome_el_ref(elem, &exc);
93           g_assert(exc == 0);
94           gdome_el_ref(elem, &exc);
95           g_assert(exc == 0);
96           control_data->first_selected = control_data->root_selected = elem;
97         }
98       
99       if (control_data->root_selected != NULL)
100         gtk_math_view_select(math_view, control_data->root_selected);
101       
102       gtk_math_view_thaw(math_view);
103     }
104 }
105
106 void
107 select_over_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
108                GtkMathViewControlData* control_data)
109 {
110   g_return_if_fail(math_view != NULL);
111   g_return_if_fail(control_data != NULL);
112
113   if (control_data->first_selected != NULL && elem != NULL)
114     {
115       GdomeException exc = 0;
116
117       gtk_math_view_freeze(math_view);
118       
119       if (control_data->root_selected != NULL)
120         {
121           gtk_math_view_unselect(math_view, control_data->root_selected);
122           gdome_el_unref(control_data->root_selected, &exc);
123           g_assert(exc == 0);
124           control_data->root_selected = NULL;
125         }
126       
127       if (control_data->id_ns_uri != NULL || control_data->id_name != NULL)
128         {
129           GdomeElement* new_root = find_common_ancestor(control_data->first_selected, elem);
130           if (new_root != NULL)
131             {
132               control_data->root_selected = find_element_with_id(new_root, control_data->id_ns_uri, control_data->id_name);
133               gdome_el_unref(new_root, &exc);
134               g_assert(exc == 0);
135             }
136           else
137             control_data->root_selected = NULL;
138         }
139       else
140         control_data->root_selected = find_common_ancestor(control_data->first_selected, elem);
141       
142       if (control_data->root_selected != NULL)
143         gtk_math_view_select(math_view, control_data->root_selected);
144       
145       gtk_math_view_thaw(math_view);
146     }
147 }
148
149 void
150 select_end_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
151               GtkMathViewControlData* control_data)
152 {
153   g_return_if_fail(math_view != NULL);
154   g_return_if_fail(control_data != NULL);
155   
156   if (control_data->first_selected != NULL)
157     {
158       GdomeException exc = 0;
159       gdome_el_unref(control_data->first_selected, &exc);
160       g_assert(exc == 0);
161       control_data->first_selected = NULL;
162
163       if (control_data->root_selected != NULL &&
164           (control_data->id_ns_uri != NULL || control_data->id_name != NULL))
165         {
166           GdomeException exc = 0;
167           GdomeDOMString* id = gdome_el_getAttributeNS(control_data->root_selected,
168                                                        control_data->id_ns_uri,
169                                                        control_data->id_name, &exc);
170           g_assert(exc == 0);
171           g_assert(id != NULL);
172           set_clipboard(id);
173           gdome_str_unref(id);
174         }
175     }
176 }
177
178 void
179 select_abort_cb(GtkMathView* math_view, GtkMathViewControlData* control_data)
180 {
181   GdomeException exc = 0;
182   
183   g_return_if_fail(math_view != NULL);
184   g_return_if_fail(control_data != NULL);
185   
186   if (control_data->first_selected != NULL)
187     {
188       gdome_el_unref(control_data->first_selected, &exc);
189       g_assert(exc == 0);
190       control_data->first_selected = NULL;
191     }
192   
193   if (control_data->root_selected != NULL)
194     {
195       gtk_math_view_freeze(math_view);
196       gtk_math_view_unselect(math_view, control_data->root_selected);
197       gtk_math_view_thaw(math_view);
198       gdome_el_unref(control_data->root_selected, &exc);
199       g_assert(exc == 0);
200       control_data->root_selected = NULL;
201     }
202 }
203