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