From: Luca Padovani Date: Tue, 9 Sep 2003 20:17:50 +0000 (+0000) Subject: * advanced implementation of View interface X-Git-Tag: v0_0_1~8 X-Git-Url: http://matita.cs.unibo.it/gitweb/?p=helm.git;a=commitdiff_plain;h=e03554e83a734994353488594810b5c32bfc46af * advanced implementation of View interface --- diff --git a/helm/gtkmathview-bonobo/idl/GtkMathView.idl b/helm/gtkmathview-bonobo/idl/GtkMathView.idl index 8c850f788..9052449b0 100644 --- a/helm/gtkmathview-bonobo/idl/GtkMathView.idl +++ b/helm/gtkmathview-bonobo/idl/GtkMathView.idl @@ -48,7 +48,9 @@ module GNOME { void select (in element_id elem); void unselect (in element_id elem); boolean isSelected (in element_id elem); - + + boolean elementCoords (in element_id elem, + out short x, out short y); /** * elementRectangle: * @elem: ID of the element @@ -60,13 +62,9 @@ module GNOME { * Returns the position and the size of the rectangle includes @elem */ boolean elementBoundingBox (in element_id elem, - out short x, out short y, out short width, out short height, out short depth); - void getBoundingBox (out short width, out short height, out short depth); - - void getSize (out short width, out short height, - out short totalWidth, out short totalHeight); + void getSize (out short width, out short height); void getTop (out short x, out short y); void setTop (in short x, in short y); diff --git a/helm/gtkmathview-bonobo/src/aux.cc b/helm/gtkmathview-bonobo/src/aux.cc index 4eaef1074..6fe151bc1 100644 --- a/helm/gtkmathview-bonobo/src/aux.cc +++ b/helm/gtkmathview-bonobo/src/aux.cc @@ -21,7 +21,8 @@ // #include -#include + +#include #include @@ -30,10 +31,28 @@ #include +#include "aux.h" + #define MATHML_NS_URI "http://www.w3.org/1998/Math/MathML" namespace DOM = GdomeSmartDOM; +static DOM::Element +findElementById(const DOM::Element& el, + const DOM::GdomeString& ns, const DOM::GdomeString& name, + const DOM::GdomeString& id) +{ + assert(el); + if (el.getAttributeNS(ns, name) == id) + return el; + else + for (DOM::Node p = el.get_firstChild(); p; p = p.get_nextSibling()) + if (p.get_nodeType() == DOM::Node::ELEMENT_NODE) + if (DOM::Element res = findElementById(p, ns, name, id)) + return res; + return DOM::Element(); +} + static unsigned getDepth(const DOM::Element& elem) { @@ -260,20 +279,17 @@ find_xref_element(GdomeElement* elem) extern "C" GdomeDOMString* find_hyperlink(GdomeElement* elem) { - DOM::Element el = findElementWithAttribute(DOM::Element(elem),"href"); - if (el) return el.getAttribute("href").gdome_str(); - else return NULL; + DOM::Element el = findElementWithAttribute(DOM::Element(elem),"href"); + if (el) return el.getAttribute("href").gdome_str(); + else return NULL; } - -extern "C" void -delete_element(GdomeElement* elem) +extern "C" GdomeElement* +find_element_by_id(GdomeElement* root, GdomeDOMString* ns_uri, GdomeDOMString* name, + const char* id) { - DOM::Element p(elem); - - DOM::Element parent = p.get_parentNode(); - assert(parent); - - parent.removeChild(p); + DOM::Element el = findElementById(DOM::Element(root), + DOM::GdomeString(ns_uri), DOM::GdomeString(name), + DOM::GdomeString(id)); + return gdome_cast_el(el.gdome_object()); } - diff --git a/helm/gtkmathview-bonobo/src/control-data.c b/helm/gtkmathview-bonobo/src/control-data.c index 382ea8d1d..10f06491c 100644 --- a/helm/gtkmathview-bonobo/src/control-data.c +++ b/helm/gtkmathview-bonobo/src/control-data.c @@ -9,6 +9,8 @@ gtk_math_view_control_data_new(GtkMathView *math_view) cd->semantic_selection = FALSE; cd->first_selected = NULL; cd->root_selected = NULL; + cd->id_ns_uri = NULL; + cd->id_name = NULL; return cd; } @@ -30,6 +32,34 @@ gtk_math_view_control_data_destroy(GtkMathViewControlData* cd) g_assert(exc == 0); cd->root_selected = NULL; } + if (cd->id_ns_uri != NULL) + { + gdome_str_unref(cd->id_ns_uri); + cd->id_ns_uri = NULL; + } + if (cd->id_name != NULL) + { + gdome_str_unref(cd->id_name); + cd->id_name = NULL; + } g_free(cd); } +void +gtk_math_view_control_data_set_id_attribute(GtkMathViewControlData* cd, + const char* ns_uri, const char* name) +{ + g_return_if_fail(cd != NULL); + if (cd->id_ns_uri != NULL) + { + gdome_str_unref(cd->id_ns_uri); + cd->id_ns_uri = NULL; + } + if (cd->id_name != NULL) + { + gdome_str_unref(cd->id_name); + cd->id_name = NULL; + } + if (ns_uri) cd->id_ns_uri = gdome_str_mkref(ns_uri); + if (name) cd->id_name = gdome_str_mkref(name); +} diff --git a/helm/gtkmathview-bonobo/src/control-data.h b/helm/gtkmathview-bonobo/src/control-data.h index 0d90f6a4c..f7a95cfab 100644 --- a/helm/gtkmathview-bonobo/src/control-data.h +++ b/helm/gtkmathview-bonobo/src/control-data.h @@ -11,6 +11,13 @@ typedef struct _GtkMathViewControlData gboolean semantic_selection; GdomeElement* first_selected; GdomeElement* root_selected; + GdomeDOMString* id_ns_uri; + GdomeDOMString* id_name; } GtkMathViewControlData; +GtkMathViewControlData* gtk_math_view_control_data_new(GtkMathView*); +void gtk_math_view_control_data_destroy(GtkMathViewControlData*); +void gtk_math_view_control_data_set_id_attribute(GtkMathViewControlData*, + const char*, const char*); + #endif // __control_data_h__ diff --git a/helm/gtkmathview-bonobo/src/view.c b/helm/gtkmathview-bonobo/src/view.c index 9f7451f40..bc0c903ef 100644 --- a/helm/gtkmathview-bonobo/src/view.c +++ b/helm/gtkmathview-bonobo/src/view.c @@ -1,6 +1,9 @@ #include +#include + +#include "aux.h" #include "view.h" static GObjectClass* view_parent_class; @@ -32,14 +35,13 @@ impl_view_thaw(PortableServer_Servant servant, return; } -static void +static CORBA_boolean impl_view_load(PortableServer_Servant servant, const CORBA_char *uri, CORBA_Environment *ev) { View* view = VIEW (bonobo_object (servant)); - gtk_math_view_load_uri(view->control_data->math_view, uri); - return; + return gtk_math_view_load_uri(view->control_data->math_view, uri); } static void @@ -48,123 +50,226 @@ impl_view_unload(PortableServer_Servant servant, { View* view = VIEW (bonobo_object (servant)); gtk_math_view_unload(view->control_data->math_view); - return; } static void impl_view_setIdAttribute (PortableServer_Servant servant, - const CORBA_char *ns, - const CORBA_char *name, - CORBA_Environment *ev) + const CORBA_char *ns, + const CORBA_char *name, + CORBA_Environment *ev) { - return; + View* view = VIEW (bonobo_object (servant)); + gtk_math_view_control_data_set_id_attribute(view->control_data, ns, name); } - static void impl_view_getIdAttribute (PortableServer_Servant servant, - CORBA_char *ns, - CORBA_char *name, - CORBA_Environment *ev) + CORBA_string *ns, + CORBA_string *name, + CORBA_Environment *ev) { - return; + View* view = VIEW (bonobo_object (servant)); + if (view->control_data->id_ns_uri != NULL) + *ns = CORBA_string_dup(view->control_data->id_ns_uri->str); + else + *ns = NULL; + + if (view->control_data->id_name != NULL) + *name = CORBA_string_dup(view->control_data->id_name); + else + *name = NULL; } static void impl_view_select(PortableServer_Servant servant, - //in element_id elem, - CORBA_Environment *ev) + const CORBA_char *id, + CORBA_Environment *ev) { - return; + View* view = VIEW (bonobo_object (servant)); + GdomeElement* root = gtk_math_view_get_root_element(view->control_data->math_view); + if (root != NULL) + { + GdomeException exc = 0; + GdomeElement* el = find_element_by_id(root, + view->control_data->id_ns_uri, + view->control_data->id_name, + id); + if (el != NULL) + { + gtk_math_view_select(view->control_data->math_view, el); + gdome_el_unref(el, &exc); + g_assert(exc == 0); + } + gdome_el_unref(root, &exc); + g_assert(exc == 0); + } } static void impl_view_unselect(PortableServer_Servant servant, - //in element_id elem, - CORBA_Environment *ev) + const CORBA_char *id, + CORBA_Environment *ev) { - return; + View* view = VIEW (bonobo_object (servant)); + GdomeElement* root = gtk_math_view_get_root_element(view->control_data->math_view); + if (root != NULL) + { + GdomeException exc = 0; + GdomeElement* el = find_element_by_id(root, + view->control_data->id_ns_uri, + view->control_data->id_name, + id); + if (el != NULL) + { + gtk_math_view_unselect(view->control_data->math_view, el); + gdome_el_unref(el, &exc); + g_assert(exc == 0); + } + gdome_el_unref(root, &exc); + g_assert(exc == 0); + } } static CORBA_boolean impl_view_isSelected(PortableServer_Servant servant, - //in element_id elem, - CORBA_Environment *ev) + const CORBA_char *id, + CORBA_Environment *ev) { - return; + View* view = VIEW (bonobo_object (servant)); + GdomeElement* root = gtk_math_view_get_root_element(view->control_data->math_view); + CORBA_boolean res = CORBA_FALSE; + if (root != NULL) + { + GdomeException exc = 0; + GdomeElement* el = find_element_by_id(root, + view->control_data->id_ns_uri, + view->control_data->id_name, + id); + if (el != NULL) + { + res = gtk_math_view_is_selected(view->control_data->math_view, el) ? CORBA_TRUE : CORBA_FALSE; + gdome_el_unref(el, &exc); + g_assert(exc == 0); + } + gdome_el_unref(root, &exc); + g_assert(exc == 0); + } + return res; } -static CORBA_boolean -impl_view_elementBoundingBox(PortableServer_Servant servant, - //in element_id elem, - CORBA_short *x,CORBA_short *y, - CORBA_short *width,CORBA_short *height, - CORBA_short *depth, - CORBA_Environment *ev) +static CORBA_boolean +impl_view_elementCoords(PortableServer_Servant servant, + const CORBA_char *id, + CORBA_short *x, CORBA_short *y, + CORBA_Environment *ev) { - return; + View* view = VIEW (bonobo_object (servant)); + GdomeElement* root = gtk_math_view_get_root_element(view->control_data->math_view); + CORBA_boolean res = CORBA_FALSE; + if (root != NULL) + { + GdomeException exc = 0; + GdomeElement* el = find_element_by_id(root, + view->control_data->id_ns_uri, + view->control_data->id_name, + id); + if (el != NULL) + { + gint xx; + gint yy; + res = gtk_math_view_get_element_coords(view->control_data->math_view, el, &xx, &yy) ? CORBA_TRUE : CORBA_FALSE; + gdome_el_unref(el, &exc); + g_assert(exc == 0); + *x = xx; + *y = yy; + } + gdome_el_unref(root, &exc); + g_assert(exc == 0); + } + return res; } -static void -impl_view_getBoundingBox(PortableServer_Servant servant, - CORBA_short *width, - CORBA_short *height, - CORBA_short *depth, - CORBA_Environment *ev) +static CORBA_boolean +impl_view_elementBoundingBox(PortableServer_Servant servant, + const CORBA_char *id, + CORBA_short *width, CORBA_short *height, CORBA_short *depth, + CORBA_Environment *ev) { - return; + View* view = VIEW (bonobo_object (servant)); + GdomeElement* root = gtk_math_view_get_root_element(view->control_data->math_view); + CORBA_boolean res = CORBA_FALSE; + if (root != NULL) + { + GdomeException exc = 0; + GdomeElement* el = find_element_by_id(root, + view->control_data->id_ns_uri, + view->control_data->id_name, + id); + if (el != NULL) + { + gint w; + gint h; + gint d; + res = gtk_math_view_get_element_coords(view->control_data->math_view, el, &w, &h, &d) ? CORBA_TRUE : CORBA_FALSE; + gdome_el_unref(el, &exc); + g_assert(exc == 0); + *width = w; + *height = h; + *depth = d; + } + gdome_el_unref(root, &exc); + g_assert(exc == 0); + } + return res; } static void impl_view_getSize(PortableServer_Servant servant, - CORBA_short *width,CORBA_short *height, - CORBA_short *totalWidth,CORBA_short *totalHeight, + CORBA_short *width, CORBA_short *height, CORBA_Environment *ev) { - //View* view = VIEW (bonobo_object (servant)); - //gtk_math_view_get_top(view->control_data->math_view,x,y); - - return; + View* view = VIEW (bonobo_object (servant)); + *width = gtk_math_view_get_width(view->control_data->math_view); + *height = gtk_math_view_get_height(view->control_data->math_view); } static void impl_view_getTop(PortableServer_Servant servant, - CORBA_short *x,CORBA_short *y, + CORBA_short *x, CORBA_short *y, CORBA_Environment *ev) { - View* view = VIEW (bonobo_object (servant)); - gtk_math_view_get_top(view->control_data->math_view,x,y); - return; + View* view = VIEW (bonobo_object (servant)); + gint xx; + gint yy; + gtk_math_view_get_top(view->control_data->math_view, &xx, &yy); + *x = xx; + *y = yy; } static void impl_view_setTop (PortableServer_Servant servant, - const CORBA_short x,const CORBA_short y, + CORBA_short x, CORBA_short y, CORBA_Environment *ev) { - View* view = VIEW (bonobo_object (servant)); - gtk_math_view_set_top(view->control_data->math_view,x,y); - return; + View* view = VIEW (bonobo_object (servant)); + gtk_math_view_set_top(view->control_data->math_view, x, y); } static void impl_view_setDefaultFontSize(PortableServer_Servant servant, - const CORBA_short size, + CORBA_short size, CORBA_Environment *ev) { - View* view = VIEW (bonobo_object (servant)); - gtk_math_view_set_font_size(view->control_data->math_view,size); - return; + View* view = VIEW (bonobo_object (servant)); + gtk_math_view_set_font_size(view->control_data->math_view, size); } static short impl_view_getDefaultFontSize(PortableServer_Servant servant, CORBA_Environment *ev) { - short int ris; - View* view = VIEW (bonobo_object (servant)); - ris = gtk_math_view_get_font_size(view->control_data->math_view); - return ris; + View* view = VIEW (bonobo_object (servant)); + return gtk_math_view_get_font_size(view->control_data->math_view); } static void @@ -172,19 +277,16 @@ impl_view_setVerbosity(PortableServer_Servant servant, const CORBA_short level, CORBA_Environment *ev) { - View* view = VIEW (bonobo_object (servant)); - gtk_math_view_set_log_verbosity(view->control_data->math_view,level); - return; + View* view = VIEW (bonobo_object (servant)); + gtk_math_view_set_log_verbosity(view->control_data->math_view, level); } static short impl_view_getVerbosity(PortableServer_Servant servant, CORBA_Environment *ev) { - short int ris; - View* view = VIEW (bonobo_object (servant)); - ris = gtk_math_view_get_log_verbosity(view->control_data->math_view); - return ris; + View* view = VIEW (bonobo_object (servant)); + return gtk_math_view_get_log_verbosity(view->control_data->math_view); } static void @@ -205,8 +307,8 @@ view_class_init(ViewClass* klass) epv->select = impl_view_select; epv->unselect = impl_view_unselect; epv->isSelected = impl_view_isSelected; + epv->elementCoords = impl_view_elementCoords; epv->elementBoundingBox = impl_view_elementBoundingBox; - epv->getBoundingBox = impl_view_getBoundingBox; epv->getSize = impl_view_getSize; epv->getTop = impl_view_getTop; epv->setTop = impl_view_setTop; @@ -214,8 +316,6 @@ view_class_init(ViewClass* klass) epv->getDefaultFontSize = impl_view_getDefaultFontSize; epv->setVerbosity = impl_view_setVerbosity; epv->getVerbosity = impl_view_getVerbosity; - - return; } static void