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