]> matita.cs.unibo.it Git - helm.git/blob - helm/gtkmathview-bonobo/src/view.c
* completed implementation of View interface
[helm.git] / helm / gtkmathview-bonobo / src / view.c
1
2 #include <config.h>
3
4 #define HAVE_GMETADOM
5 #include <gtkmathview.h>
6
7 #include "aux.h"
8 #include "view.h"
9
10 static GObjectClass* view_parent_class;
11
12 static void
13 view_object_finalize(GObject* object)
14 {
15   View* view = VIEW(object);
16   /* free resources */
17   view_parent_class->finalize(object);
18   return;
19 }
20
21 static void
22 impl_view_freeze(PortableServer_Servant servant,
23                  CORBA_Environment *ev)
24 {
25   View* view = VIEW (bonobo_object (servant));
26   gtk_math_view_freeze(view->control_data->math_view);
27   return;
28 }
29
30 static void
31 impl_view_thaw(PortableServer_Servant servant,
32                CORBA_Environment *ev)
33 {
34   View* view = VIEW (bonobo_object (servant));
35   gtk_math_view_thaw(view->control_data->math_view);
36   return;
37 }
38
39 static CORBA_boolean
40 impl_view_load(PortableServer_Servant servant,
41                const CORBA_char *uri,
42                CORBA_Environment *ev)
43 {
44   View* view = VIEW (bonobo_object (servant));
45   return gtk_math_view_load_uri(view->control_data->math_view, uri);
46 }
47
48 static void
49 impl_view_unload(PortableServer_Servant servant,
50                  CORBA_Environment *ev)
51 {
52   View* view = VIEW (bonobo_object (servant));
53   gtk_math_view_unload(view->control_data->math_view);
54 }
55
56 static void
57 impl_view_setIdAttribute (PortableServer_Servant servant,
58                           const CORBA_char *ns,
59                           const CORBA_char *name,
60                           CORBA_Environment *ev)
61 {
62   View* view = VIEW (bonobo_object (servant));
63   gtk_math_view_control_data_set_id_attribute(view->control_data, ns, name);
64 }
65
66 static void
67 impl_view_getIdAttribute (PortableServer_Servant servant,
68                           CORBA_string *ns,
69                           CORBA_string *name,
70                           CORBA_Environment *ev)
71 {
72   View* view = VIEW (bonobo_object (servant));
73   if (view->control_data->id_ns_uri != NULL)
74     *ns = CORBA_string_dup(view->control_data->id_ns_uri->str);
75   else
76     *ns = NULL;
77
78   if (view->control_data->id_name != NULL)
79     *name = CORBA_string_dup(view->control_data->id_name);
80   else
81     *name = NULL;
82 }
83
84 static void 
85 impl_view_select(PortableServer_Servant servant,
86                  const CORBA_char *id,
87                  CORBA_Environment *ev)
88 {
89   View* view = VIEW (bonobo_object (servant));
90   GdomeElement* root = gtk_math_view_get_root_element(view->control_data->math_view);
91   if (root != NULL)
92     {
93       GdomeException exc = 0;
94       GdomeElement* el = find_element_by_id(root,
95                                             view->control_data->id_ns_uri,
96                                             view->control_data->id_name,
97                                             id);
98       if (el != NULL)
99         {
100           gtk_math_view_select(view->control_data->math_view, el);
101           gdome_el_unref(el, &exc);
102           g_assert(exc == 0);
103         }
104       gdome_el_unref(root, &exc);
105       g_assert(exc == 0);
106     }
107 }
108       
109 static void 
110 impl_view_unselect(PortableServer_Servant servant,
111                    const CORBA_char *id,
112                    CORBA_Environment *ev)
113 {
114   View* view = VIEW (bonobo_object (servant));
115   GdomeElement* root = gtk_math_view_get_root_element(view->control_data->math_view);
116   if (root != NULL)
117     {
118       GdomeException exc = 0;
119       GdomeElement* el = find_element_by_id(root,
120                                             view->control_data->id_ns_uri,
121                                             view->control_data->id_name,
122                                             id);
123       if (el != NULL)
124         {
125           gtk_math_view_unselect(view->control_data->math_view, el);
126           gdome_el_unref(el, &exc);
127           g_assert(exc == 0);
128         }
129       gdome_el_unref(root, &exc);
130       g_assert(exc == 0);
131     }
132 }
133       
134 static CORBA_boolean 
135 impl_view_isSelected(PortableServer_Servant servant,
136                      const CORBA_char *id,
137                      CORBA_Environment *ev)
138 {
139   View* view = VIEW (bonobo_object (servant));
140   GdomeElement* root = gtk_math_view_get_root_element(view->control_data->math_view);
141   CORBA_boolean res = CORBA_FALSE;
142   if (root != NULL)
143     {
144       GdomeException exc = 0;
145       GdomeElement* el = find_element_by_id(root,
146                                             view->control_data->id_ns_uri,
147                                             view->control_data->id_name,
148                                             id);
149       if (el != NULL)
150         {
151           res = gtk_math_view_is_selected(view->control_data->math_view, el) ? CORBA_TRUE : CORBA_FALSE;
152           gdome_el_unref(el, &exc);
153           g_assert(exc == 0);
154         }
155       gdome_el_unref(root, &exc);
156       g_assert(exc == 0);
157     }
158   return res;
159 }
160
161 static CORBA_boolean
162 impl_view_elementCoords(PortableServer_Servant servant,
163                         const CORBA_char *id,
164                         CORBA_short *x, CORBA_short *y,
165                         CORBA_Environment *ev)
166 {
167   View* view = VIEW (bonobo_object (servant));
168   GdomeElement* root = gtk_math_view_get_root_element(view->control_data->math_view);
169   CORBA_boolean res = CORBA_FALSE;
170   if (root != NULL)
171     {
172       GdomeException exc = 0;
173       GdomeElement* el = find_element_by_id(root,
174                                             view->control_data->id_ns_uri,
175                                             view->control_data->id_name,
176                                             id);
177       if (el != NULL)
178         {
179           gint xx;
180           gint yy;
181           res = gtk_math_view_get_element_coords(view->control_data->math_view, el, &xx, &yy) ? CORBA_TRUE : CORBA_FALSE;
182           gdome_el_unref(el, &exc);
183           g_assert(exc == 0);
184           *x = xx;
185           *y = yy;
186         }
187       gdome_el_unref(root, &exc);
188       g_assert(exc == 0);
189     }
190   return res;
191 }
192
193 static CORBA_boolean 
194 impl_view_elementBoundingBox(PortableServer_Servant servant,
195                              const CORBA_char *id,
196                              CORBA_short *width, CORBA_short *height, CORBA_short *depth,
197                              CORBA_Environment *ev)
198 {
199   View* view = VIEW (bonobo_object (servant));
200   GdomeElement* root = gtk_math_view_get_root_element(view->control_data->math_view);
201   CORBA_boolean res = CORBA_FALSE;
202   if (root != NULL)
203     {
204       GdomeException exc = 0;
205       GdomeElement* el = find_element_by_id(root,
206                                             view->control_data->id_ns_uri,
207                                             view->control_data->id_name,
208                                             id);
209       if (el != NULL)
210         {
211           gint w;
212           gint h;
213           gint d;
214           res = gtk_math_view_get_element_bounding_box(view->control_data->math_view, el, &w, &h, &d) ? CORBA_TRUE : CORBA_FALSE;
215           gdome_el_unref(el, &exc);
216           g_assert(exc == 0);
217           *width = w;
218           *height = h;
219           *depth = d;
220         }
221       gdome_el_unref(root, &exc);
222       g_assert(exc == 0);
223     }
224   return res;
225 }
226
227 static void 
228 impl_view_getSize(PortableServer_Servant servant,
229                   CORBA_short *width, CORBA_short *height,
230                   CORBA_Environment *ev)
231 {
232   View* view = VIEW (bonobo_object (servant));
233   *width = gtk_math_view_get_width(view->control_data->math_view);
234   *height = gtk_math_view_get_height(view->control_data->math_view);
235 }
236
237 static void 
238 impl_view_getTop(PortableServer_Servant servant,
239                  CORBA_short *x, CORBA_short *y,
240                  CORBA_Environment *ev)
241 {
242   View* view = VIEW (bonobo_object (servant));
243   gint xx;
244   gint yy;
245   gtk_math_view_get_top(view->control_data->math_view, &xx, &yy);
246   *x = xx;
247   *y = yy;
248 }
249
250 static void 
251 impl_view_setTop (PortableServer_Servant servant,
252                   CORBA_short x, CORBA_short y,
253                   CORBA_Environment *ev)
254 {
255   View* view = VIEW (bonobo_object (servant));
256   gtk_math_view_set_top(view->control_data->math_view, x, y);
257 }
258
259 static void 
260 impl_view_setDefaultFontSize(PortableServer_Servant servant,
261                              CORBA_short size,
262                              CORBA_Environment *ev)
263 {
264   View* view = VIEW (bonobo_object (servant));
265   gtk_math_view_set_font_size(view->control_data->math_view, size);
266 }
267
268 static short 
269 impl_view_getDefaultFontSize(PortableServer_Servant servant,
270                              CORBA_Environment *ev)
271 {
272   View* view = VIEW (bonobo_object (servant));
273   return gtk_math_view_get_font_size(view->control_data->math_view);
274 }
275
276 static void 
277 impl_view_setVerbosity(PortableServer_Servant servant,
278                        const CORBA_short level,
279                        CORBA_Environment *ev)
280 {
281   View* view = VIEW (bonobo_object (servant));
282   gtk_math_view_set_log_verbosity(view->control_data->math_view, level); 
283 }
284
285 static short 
286 impl_view_getVerbosity(PortableServer_Servant servant,
287                        CORBA_Environment *ev)
288 {
289   View* view = VIEW (bonobo_object (servant));
290   return gtk_math_view_get_log_verbosity(view->control_data->math_view);
291 }
292
293 static void
294 view_class_init(ViewClass* klass)
295 {
296   GObjectClass* object_class = (GObjectClass *) klass;
297   POA_GNOME_GtkMathView_View__epv* epv = &klass->epv;
298   
299   view_parent_class = g_type_class_peek_parent (klass);
300   object_class->finalize = view_object_finalize;
301   
302   epv->freeze = impl_view_freeze;
303   epv->thaw = impl_view_thaw;
304   epv->load = impl_view_load;
305   epv->unload = impl_view_unload;
306   epv->setIdAttribute = impl_view_setIdAttribute;
307   epv->getIdAttribute = impl_view_getIdAttribute;
308   epv->select = impl_view_select;
309   epv->unselect = impl_view_unselect;
310   epv->isSelected = impl_view_isSelected;
311   epv->elementCoords = impl_view_elementCoords;
312   epv->elementBoundingBox = impl_view_elementBoundingBox;
313   epv->getSize = impl_view_getSize;
314   epv->getTop = impl_view_getTop;
315   epv->setTop = impl_view_setTop;
316   epv->setDefaultFontSize = impl_view_setDefaultFontSize;
317   epv->getDefaultFontSize = impl_view_getDefaultFontSize;
318   epv->setVerbosity = impl_view_setVerbosity;
319   epv->getVerbosity = impl_view_getVerbosity;
320 }
321
322 static void
323 view_init(View* view)
324 {
325   /* do some initialization */
326 }
327
328 BONOBO_TYPE_FUNC_FULL (View, GNOME_GtkMathView_View, BONOBO_TYPE_OBJECT, view)
329
330 View*
331 view_new(GtkMathViewControlData* control_data)
332 {
333   View* view;
334   g_return_val_if_fail(control_data != NULL, NULL);
335   view = g_object_new(VIEW_TYPE, NULL);
336   view->control_data = control_data;
337   return view;
338 }