]> matita.cs.unibo.it Git - helm.git/blob - helm/gtkmathview-bonobo/src/handlers.c
Bug fixed: when an axiom was asked, an exception was raised (since the
[helm.git] / helm / gtkmathview-bonobo / src / handlers.c
1 /* This file is part of GtkMathView-Bonobo, a Bonobo wrapper for GtkMathView.
2  * Copyright (C) 2003 Luca Padovani <lpadovan@cs.unibo.it>
3  *                    Pouria Masoudi <pmasoudi@cs.unibo.it>
4  * 
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * 
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  * 
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * For more information, please visit the project's home page
20  * http://helm.cs.unibo.it/gtkmathview-bonobo
21  * or send an email to <lpadovan@cs.unibo.it>
22  */
23
24 #include <config.h>
25
26 #include "aux.h"
27 #include "handlers.h"
28
29 static void
30 set_clipboard(GdomeDOMString* data)
31 {
32   GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
33   gtk_clipboard_set_text(clipboard, data->str, gdome_str_length(data));
34 }
35
36 void
37 set_frame(BonoboControl *control, gpointer data)
38 {     
39 }
40
41 void
42 click_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
43          GtkMathViewControlData* control_data)
44 {
45   GdomeException exc = 0;
46   
47   g_return_if_fail(math_view != NULL);
48   g_return_if_fail(control_data != NULL);
49   
50   if (elem != NULL)
51     {
52       GdomeElement* action;
53       GdomeDOMString* href = find_hyperlink(elem);
54
55       if (href != NULL)
56         {
57           /*gtk_math_view_load_uri(math_view,href->str);*/
58           set_clipboard(href);
59           gdome_str_unref(href);
60           return;
61         }
62
63       action = find_self_or_ancestor(elem, MATHML_NS_URI, "maction");
64       if (action != NULL)
65         {
66           gtk_math_view_freeze(math_view);
67           action_toggle(action);
68           gtk_math_view_thaw(math_view);
69           gdome_el_unref(action, &exc);
70           g_assert(exc == 0);
71           return;
72         }
73     }
74     
75   if (control_data->root_selected != NULL)
76     {
77       gtk_math_view_freeze(math_view);
78       gtk_math_view_unselect(math_view, control_data->root_selected);
79       gtk_math_view_thaw(math_view);
80       gdome_el_unref(control_data->root_selected, &exc);
81       g_assert(exc == 0);
82       control_data->root_selected = NULL;
83     }
84 }
85
86 void
87 select_begin_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
88                 GtkMathViewControlData* control_data)
89 {
90   g_return_if_fail(math_view != NULL);
91   g_return_if_fail(control_data != NULL);
92
93   if (elem != NULL)
94     {
95       GdomeException exc = 0;
96       gtk_math_view_freeze(math_view);
97       if (control_data->root_selected != NULL)
98         {
99           gtk_math_view_unselect(math_view, control_data->root_selected);
100           gdome_el_unref(control_data->root_selected, &exc);
101           g_assert(exc == 0);
102           control_data->root_selected = NULL;
103         }
104       
105       if (control_data->semantic_selection)
106         {
107           GdomeElement* new_elem = find_element_with_id(elem, control_data->id_ns_uri, control_data->id_name);
108           if (new_elem != NULL)
109             {
110               gdome_el_ref(new_elem, &exc);
111               g_assert(exc == 0);
112             }
113           control_data->first_selected = control_data->root_selected = new_elem;
114         }
115       else
116         {
117           gdome_el_ref(elem, &exc);
118           g_assert(exc == 0);
119           gdome_el_ref(elem, &exc);
120           g_assert(exc == 0);
121           control_data->first_selected = control_data->root_selected = elem;
122         }
123       
124       if (control_data->root_selected != NULL)
125         gtk_math_view_select(math_view, control_data->root_selected);
126       
127       gtk_math_view_thaw(math_view);
128     }
129 }
130
131 void
132 select_over_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
133                GtkMathViewControlData* control_data)
134 {
135   g_return_if_fail(math_view != NULL);
136   g_return_if_fail(control_data != NULL);
137
138   if (control_data->first_selected != NULL && elem != NULL)
139     {
140       GdomeException exc = 0;
141
142       gtk_math_view_freeze(math_view);
143       
144       if (control_data->root_selected != NULL)
145         {
146           gtk_math_view_unselect(math_view, control_data->root_selected);
147           gdome_el_unref(control_data->root_selected, &exc);
148           g_assert(exc == 0);
149           control_data->root_selected = NULL;
150         }
151       
152       if (control_data->semantic_selection)
153         {
154           GdomeElement* new_root = find_common_ancestor(control_data->first_selected, elem);
155           if (new_root != NULL)
156             {
157               control_data->root_selected = find_element_with_id(new_root, control_data->id_ns_uri, control_data->id_name);
158               gdome_el_unref(new_root, &exc);
159               g_assert(exc == 0);
160             }
161           else
162             control_data->root_selected = NULL;
163         }
164       else
165         control_data->root_selected = find_common_ancestor(control_data->first_selected, elem);
166       
167       if (control_data->root_selected != NULL)
168         gtk_math_view_select(math_view, control_data->root_selected);
169       
170       gtk_math_view_thaw(math_view);
171     }
172 }
173
174 void
175 select_end_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
176               GtkMathViewControlData* control_data)
177 {
178   g_return_if_fail(math_view != NULL);
179   g_return_if_fail(control_data != NULL);
180   
181   if (control_data->first_selected != NULL)
182     {
183       GdomeException exc = 0;
184       gdome_el_unref(control_data->first_selected, &exc);
185       g_assert(exc == 0);
186       control_data->first_selected = NULL;
187
188       if (control_data->root_selected != NULL && control_data->semantic_selection)
189         {
190           GdomeException exc = 0;
191           GdomeDOMString* id = gdome_el_getAttributeNS(control_data->root_selected,
192                                                        control_data->id_ns_uri,
193                                                        control_data->id_name, &exc);
194           g_assert(exc == 0);
195           g_assert(id != NULL);
196           set_clipboard(id);
197           gdome_str_unref(id);
198         }
199     }
200 }
201
202 void
203 select_abort_cb(GtkMathView* math_view, GtkMathViewControlData* control_data)
204 {
205   GdomeException exc = 0;
206   
207   g_return_if_fail(math_view != NULL);
208   g_return_if_fail(control_data != NULL);
209   
210   if (control_data->first_selected != NULL)
211     {
212       gdome_el_unref(control_data->first_selected, &exc);
213       g_assert(exc == 0);
214       control_data->first_selected = NULL;
215     }
216   
217   if (control_data->root_selected != NULL)
218     {
219       gtk_math_view_freeze(math_view);
220       gtk_math_view_unselect(math_view, control_data->root_selected);
221       gtk_math_view_thaw(math_view);
222       gdome_el_unref(control_data->root_selected, &exc);
223       g_assert(exc == 0);
224       control_data->root_selected = NULL;
225     }
226 }
227