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>
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.
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.
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
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>
30 set_clipboard(GdomeDOMString* data)
32 GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
33 gtk_clipboard_set_text(clipboard, data->str, gdome_str_length(data));
37 set_frame(BonoboControl *control, gpointer data)
42 notify_browser(GtkMathViewControlData* control_data, const char* url)
44 BonoboObject* evs = bonobo_object_query_local_interface(BONOBO_OBJECT(control_data->control),
45 "IDL:Bonobo/EventSource:1.0");
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));
57 click_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
58 GtkMathViewControlData* control_data)
60 GdomeException exc = 0;
62 g_return_if_fail(math_view != NULL);
63 g_return_if_fail(control_data != NULL);
68 GdomeDOMString* href = find_hyperlink(elem);
72 /*gtk_math_view_load_uri(math_view,href->str);*/
74 notify_browser(control_data, href->str);
76 //set_clipboard(href);
77 gdome_str_unref(href);
81 action = find_self_or_ancestor(elem, MATHML_NS_URI, "maction");
84 gtk_math_view_freeze(math_view);
85 action_toggle(action);
86 gtk_math_view_thaw(math_view);
87 gdome_el_unref(action, &exc);
93 if (control_data->root_selected != NULL)
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);
100 control_data->root_selected = NULL;
105 select_begin_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
106 GtkMathViewControlData* control_data)
108 g_return_if_fail(math_view != NULL);
109 g_return_if_fail(control_data != NULL);
113 GdomeException exc = 0;
114 gtk_math_view_freeze(math_view);
115 if (control_data->root_selected != NULL)
117 gtk_math_view_unselect(math_view, control_data->root_selected);
118 gdome_el_unref(control_data->root_selected, &exc);
120 control_data->root_selected = NULL;
123 if (control_data->semantic_selection)
125 GdomeElement* new_elem = find_element_with_id(elem, control_data->id_ns_uri, control_data->id_name);
126 if (new_elem != NULL)
128 gdome_el_ref(new_elem, &exc);
131 control_data->first_selected = control_data->root_selected = new_elem;
135 gdome_el_ref(elem, &exc);
137 gdome_el_ref(elem, &exc);
139 control_data->first_selected = control_data->root_selected = elem;
142 if (control_data->root_selected != NULL)
143 gtk_math_view_select(math_view, control_data->root_selected);
145 gtk_math_view_thaw(math_view);
150 select_over_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
151 GtkMathViewControlData* control_data)
153 g_return_if_fail(math_view != NULL);
154 g_return_if_fail(control_data != NULL);
156 if (control_data->first_selected != NULL && elem != NULL)
158 GdomeException exc = 0;
160 gtk_math_view_freeze(math_view);
162 if (control_data->root_selected != NULL)
164 gtk_math_view_unselect(math_view, control_data->root_selected);
165 gdome_el_unref(control_data->root_selected, &exc);
167 control_data->root_selected = NULL;
170 if (control_data->semantic_selection)
172 GdomeElement* new_root = find_common_ancestor(control_data->first_selected, elem);
173 if (new_root != NULL)
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);
180 control_data->root_selected = NULL;
183 control_data->root_selected = find_common_ancestor(control_data->first_selected, elem);
185 if (control_data->root_selected != NULL)
186 gtk_math_view_select(math_view, control_data->root_selected);
188 gtk_math_view_thaw(math_view);
193 select_end_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
194 GtkMathViewControlData* control_data)
196 g_return_if_fail(math_view != NULL);
197 g_return_if_fail(control_data != NULL);
199 if (control_data->first_selected != NULL)
201 GdomeException exc = 0;
202 gdome_el_unref(control_data->first_selected, &exc);
204 control_data->first_selected = NULL;
206 if (control_data->root_selected != NULL && control_data->semantic_selection)
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);
213 g_assert(id != NULL);
221 select_abort_cb(GtkMathView* math_view, GtkMathViewControlData* control_data)
223 GdomeException exc = 0;
225 g_return_if_fail(math_view != NULL);
226 g_return_if_fail(control_data != NULL);
228 if (control_data->first_selected != NULL)
230 gdome_el_unref(control_data->first_selected, &exc);
232 control_data->first_selected = NULL;
235 if (control_data->root_selected != NULL)
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);
242 control_data->root_selected = NULL;