]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/gtkmathview-bonobo/src/control-data.c
ocaml 3.09 transition
[helm.git] / helm / gtkmathview-bonobo / src / control-data.c
index 10f06491c338a197cd9e04ddd78b6e39c35561e6..d97d0fd2f77700338a039c1f33b8e4b2f12b2952 100644 (file)
@@ -1,16 +1,46 @@
+/* This file is part of GtkMathView-Bonobo, a Bonobo wrapper for GtkMathView.
+ * Copyright (C) 2003 Luca Padovani <lpadovan@cs.unibo.it>
+ *                    Pouria Masoudi <pmasoudi@cs.unibo.it>
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * For more information, please visit the project's home page
+ * http://helm.cs.unibo.it/gtkmathview-bonobo
+ * or send an email to <lpadovan@cs.unibo.it>
+ */
+
+#include <config.h>
+
+#include <gdome.h>
 
 #include "control-data.h"
 
 GtkMathViewControlData*
-gtk_math_view_control_data_new(GtkMathView *math_view)
+gtk_math_view_control_data_new(BonoboControl* control, GtkMathView *math_view)
 {
   GtkMathViewControlData *cd = g_new(GtkMathViewControlData,1);
+  cd->control = control; /* we don't ref the control this is a weak pointer */
   cd->math_view = math_view;
+  gtk_widget_ref(GTK_WIDGET(math_view));
+  cd->item_factory = NULL;
   cd->semantic_selection = FALSE;
   cd->first_selected = NULL;
   cd->root_selected = NULL;
-  cd->id_ns_uri = NULL;
-  cd->id_name = NULL;
+  cd->id_ns_uri = gdome_str_mkref("http://www.cs.unibo.it/helm");
+  cd->id_name = gdome_str_mkref("xref");
+  cd->x = cd->y = 0;
   return cd;
 }
 
@@ -18,8 +48,14 @@ void
 gtk_math_view_control_data_destroy(GtkMathViewControlData* cd)
 {
   GdomeException exc = 0;
-  //gtk_object_unref(cd->math_view);
+  cd->control = NULL; /* don't unref the control, see above */
+  gtk_widget_unref(GTK_WIDGET(cd->math_view));
   cd->math_view = NULL;
+  if (cd->item_factory != NULL)
+    {
+      gtk_object_unref(cd->item_factory);
+      cd->item_factory = NULL;
+    }
   if (cd->first_selected != NULL)
     {
       gdome_el_unref(cd->first_selected, &exc);
@@ -45,21 +81,58 @@ gtk_math_view_control_data_destroy(GtkMathViewControlData* cd)
   g_free(cd);
 }
 
+gchar*
+gtk_math_view_control_data_get_id_ns_uri(GtkMathViewControlData* cd)
+{
+  g_return_val_if_fail(cd != NULL, NULL);
+  return (cd->id_ns_uri != NULL) ? g_strdup(cd->id_ns_uri->str) : NULL;
+}
+                                        
 void
-gtk_math_view_control_data_set_id_attribute(GtkMathViewControlData* cd,
-                                           const char* ns_uri, const char* name)
+gtk_math_view_control_data_set_id_ns_uri(GtkMathViewControlData* cd, const gchar* ns_uri)
 {
   g_return_if_fail(cd != NULL);
-  if (cd->id_ns_uri != NULL)
+  if (cd->id_ns_uri != NULL) gdome_str_unref(cd->id_ns_uri);
+  cd->id_ns_uri = (ns_uri != NULL) ? gdome_str_mkref_dup(ns_uri) : NULL;
+}
+
+gchar*
+gtk_math_view_control_data_get_id_name(GtkMathViewControlData* cd)
+{
+  g_return_val_if_fail(cd != NULL, NULL);
+  return (cd->id_name != NULL) ? g_strdup(cd->id_name->str) : NULL;
+}
+                                        
+void
+gtk_math_view_control_data_set_id_name(GtkMathViewControlData* cd, const gchar* name)
+{
+  g_return_if_fail(cd != NULL);
+  if (cd->id_name != NULL) gdome_str_unref(cd->id_name);
+  cd->id_name = (name != NULL) ? gdome_str_mkref_dup(name) : NULL;
+}
+
+void
+gtk_math_view_control_data_set_root_selected(GtkMathViewControlData* cd, GdomeElement* elem)
+{
+  g_return_if_fail(cd != NULL);
+  GdomeException exc = 0;
+
+  gtk_math_view_freeze(cd->math_view);
+
+  if (cd->root_selected != NULL)
     {
-      gdome_str_unref(cd->id_ns_uri);
-      cd->id_ns_uri = NULL;
+      gtk_math_view_unselect(cd->math_view, cd->root_selected);
+      gdome_el_unref(cd->root_selected, &exc);
+      g_assert(exc == 0);
     }
-  if (cd->id_name != NULL)
+
+  cd->root_selected = elem;
+  if (cd->root_selected != NULL)
     {
-      gdome_str_unref(cd->id_name);
-      cd->id_name = NULL;
+      gdome_el_ref(cd->root_selected, &exc);
+      g_assert(exc == 0);
+      gtk_math_view_select(cd->math_view, cd->root_selected);
     }
-  if (ns_uri) cd->id_ns_uri = gdome_str_mkref(ns_uri);
-  if (name) cd->id_name = gdome_str_mkref(name);
+
+  gtk_math_view_thaw(cd->math_view);
 }