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