]> matita.cs.unibo.it Git - helm.git/blob - helm/gtkmathview-bonobo/src/handlers.c
ocaml 3.09 transition
[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 static void
42 notify_browser(GtkMathViewControlData* control_data, const char* url)
43 {
44   BonoboObject* evs = bonobo_object_query_local_interface(BONOBO_OBJECT(control_data->control),
45                                                           "IDL:Bonobo/EventSource:1.0");
46   if (evs != NULL)
47     {
48       BonoboArg* arg = bonobo_arg_new(BONOBO_ARG_STRING);
49       BONOBO_ARG_SET_STRING(arg, url);
50       bonobo_event_source_notify_listeners (evs, "URL", arg, NULL);
51       /* bonobo_arg_release(arg); */
52       bonobo_object_unref(BONOBO_OBJECT(evs));
53     }
54 }
55
56 void
57 click_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
58          GtkMathViewControlData* control_data)
59 {
60   GdomeException exc = 0;
61   
62   g_return_if_fail(math_view != NULL);
63   g_return_if_fail(control_data != NULL);
64
65   if (elem != NULL)
66     {
67       GdomeElement* action;
68       GdomeDOMString* href = find_hyperlink(elem);
69
70       if (href != NULL)
71         {
72           /*gtk_math_view_load_uri(math_view,href->str);*/
73
74           notify_browser(control_data, href->str);
75
76           //set_clipboard(href);
77           gdome_str_unref(href);
78           return;
79         }
80
81       action = find_self_or_ancestor(elem, MATHML_NS_URI, "maction");
82       if (action != NULL)
83         {
84           gtk_math_view_freeze(math_view);
85           action_toggle(action);
86           gtk_math_view_thaw(math_view);
87           gdome_el_unref(action, &exc);
88           g_assert(exc == 0);
89           return;
90         }
91     }
92     
93   if (control_data->root_selected != NULL)
94     {
95       gtk_math_view_freeze(math_view);
96       gtk_math_view_unselect(math_view, control_data->root_selected);
97       gtk_math_view_thaw(math_view);
98       gdome_el_unref(control_data->root_selected, &exc);
99       g_assert(exc == 0);
100       control_data->root_selected = NULL;
101     }
102 }
103
104 void
105 select_begin_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
106                 GtkMathViewControlData* control_data)
107 {
108   g_return_if_fail(math_view != NULL);
109   g_return_if_fail(control_data != NULL);
110
111   if (elem != NULL)
112     {
113       GdomeException exc = 0;
114       gtk_math_view_freeze(math_view);
115       if (control_data->root_selected != NULL)
116         {
117           gtk_math_view_unselect(math_view, control_data->root_selected);
118           gdome_el_unref(control_data->root_selected, &exc);
119           g_assert(exc == 0);
120           control_data->root_selected = NULL;
121         }
122       
123       if (control_data->semantic_selection)
124         {
125           GdomeElement* new_elem = find_element_with_id(elem, control_data->id_ns_uri, control_data->id_name);
126           if (new_elem != NULL)
127             {
128               gdome_el_ref(new_elem, &exc);
129               g_assert(exc == 0);
130             }
131           control_data->first_selected = control_data->root_selected = new_elem;
132         }
133       else
134         {
135           gdome_el_ref(elem, &exc);
136           g_assert(exc == 0);
137           gdome_el_ref(elem, &exc);
138           g_assert(exc == 0);
139           control_data->first_selected = control_data->root_selected = elem;
140         }
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_over_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 && elem != NULL)
157     {
158       GdomeException exc = 0;
159
160       gtk_math_view_freeze(math_view);
161       
162       if (control_data->root_selected != NULL)
163         {
164           gtk_math_view_unselect(math_view, control_data->root_selected);
165           gdome_el_unref(control_data->root_selected, &exc);
166           g_assert(exc == 0);
167           control_data->root_selected = NULL;
168         }
169       
170       if (control_data->semantic_selection)
171         {
172           GdomeElement* new_root = find_common_ancestor(control_data->first_selected, elem);
173           if (new_root != NULL)
174             {
175               control_data->root_selected = find_element_with_id(new_root, control_data->id_ns_uri, control_data->id_name);
176               gdome_el_unref(new_root, &exc);
177               g_assert(exc == 0);
178             }
179           else
180             control_data->root_selected = NULL;
181         }
182       else
183         control_data->root_selected = find_common_ancestor(control_data->first_selected, elem);
184       
185       if (control_data->root_selected != NULL)
186         gtk_math_view_select(math_view, control_data->root_selected);
187       
188       gtk_math_view_thaw(math_view);
189     }
190 }
191
192 void
193 select_end_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
194               GtkMathViewControlData* control_data)
195 {
196   g_return_if_fail(math_view != NULL);
197   g_return_if_fail(control_data != NULL);
198   
199   if (control_data->first_selected != NULL)
200     {
201       GdomeException exc = 0;
202       gdome_el_unref(control_data->first_selected, &exc);
203       g_assert(exc == 0);
204       control_data->first_selected = NULL;
205
206       if (control_data->root_selected != NULL && control_data->semantic_selection)
207         {
208           GdomeException exc = 0;
209           GdomeDOMString* id = gdome_el_getAttributeNS(control_data->root_selected,
210                                                        control_data->id_ns_uri,
211                                                        control_data->id_name, &exc);
212           g_assert(exc == 0);
213           g_assert(id != NULL);
214           set_clipboard(id);
215           gdome_str_unref(id);
216         }
217     }
218 }
219
220 void
221 select_abort_cb(GtkMathView* math_view, GtkMathViewControlData* control_data)
222 {
223   GdomeException exc = 0;
224   
225   g_return_if_fail(math_view != NULL);
226   g_return_if_fail(control_data != NULL);
227   
228   if (control_data->first_selected != NULL)
229     {
230       gdome_el_unref(control_data->first_selected, &exc);
231       g_assert(exc == 0);
232       control_data->first_selected = NULL;
233     }
234   
235   if (control_data->root_selected != NULL)
236     {
237       gtk_math_view_freeze(math_view);
238       gtk_math_view_unselect(math_view, control_data->root_selected);
239       gtk_math_view_thaw(math_view);
240       gdome_el_unref(control_data->root_selected, &exc);
241       g_assert(exc == 0);
242       control_data->root_selected = NULL;
243     }
244 }
245