]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/helmpot/guiGTK.c
This commit was manufactured by cvs2svn to create tag 'v0_0_2'.
[helm.git] / helm / helmpot / guiGTK.c
index 906daf2b60f55253333fbc75cf3d75e092210aef..fc268ae8a1b34b157fdb4353ce766481946c9ed4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2000-2002, Luca Padovani <luca.padovani@cs.unibo.it>.
+ * Copyright (C) 2000, Luca Padovani <luca.padovani@cs.unibo.it>.
  * 
  * This file is part of HelmPot, a minimal browser for HELM.
  * 
@@ -65,11 +65,8 @@ PRIVATE GtkMenuItem* anti_aliasing_item;
 PRIVATE GtkMenuItem* font_size_item;
 PRIVATE gchar* file_name = NULL;
 
-PRIVATE GdkCursor* normal_cursor;
-PRIVATE GdkCursor* link_cursor;  
-PRIVATE GdkCursor* pot_cursor;
+PRIVATE GdkCursor* pot;
 
-PRIVATE gboolean loading = FALSE;
 PRIVATE guint statusbar_context;
 
 PRIVATE void create_widget_set(void);
@@ -179,14 +176,11 @@ GUI_init(gint* argc, gchar*** argv, gchar* title, guint width, guint height, Gtk
 
   gtk_timeout_add(timeout, f, NULL);
 
-  normal_cursor = gdk_cursor_new(GDK_TOP_LEFT_ARROW);
-  link_cursor = gdk_cursor_new(GDK_HAND2);
-  
   source = gdk_bitmap_create_from_data (NULL, pot_bits,
                                        pot_width, pot_height);
   mask = gdk_bitmap_create_from_data (NULL, pot_mask_bits,
                                      pot_mask_width, pot_mask_height);
-  pot_cursor = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 8, 8);
+  pot = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 8, 8);
   gdk_pixmap_unref (source);
   gdk_pixmap_unref (mask);  
 }
@@ -201,7 +195,6 @@ GUI_load_document(const gchar* name)
 {
   GtkMathView* math_view;
   GtkMathViewClass* klass;
-  gboolean res;
 
   g_return_val_if_fail(name != NULL, -1);
   g_return_val_if_fail(main_area != NULL, -1);
@@ -213,11 +206,9 @@ GUI_load_document(const gchar* name)
   klass = (GtkMathViewClass*) gtk_type_class(gtk_math_view_get_type());
   g_return_val_if_fail(klass != NULL, -1);
 
-  res = gtk_math_view_load(math_view, name);
-  gdk_window_set_cursor(main_area->window, normal_cursor);
-  loading = FALSE;
+  gdk_window_set_cursor (main_area->window, pot);  
 
-  if (!res) {
+  if (!gtk_math_view_load(math_view, name)) {
     load_error_msg(name);
     return -1;
   }
@@ -226,6 +217,8 @@ GUI_load_document(const gchar* name)
   if (strlen(name) > 40) name += strlen(name) - 40;
   gtk_statusbar_push(GTK_STATUSBAR(status_bar), statusbar_context, name);
 
+  /*gdk_window_set_cursor(gtk_widget_get_parent_window(main_area), klass->normal_cursor);*/
+
   if (file_name != NULL) g_free(file_name);
   file_name = g_strdup(name);
 
@@ -305,7 +298,7 @@ help_about(GtkWidget* widget, gpointer data)
   GtkWidget* ok;
 
   dialog = gtk_dialog_new();
-  label = gtk_label_new("\n    HELM PoT    \n    Copyright (C) 2001-2002 Luca Padovani    \n");
+  label = gtk_label_new("\n    HELM PoT    \n    Copyright (C) 2001 Luca Padovani    \n");
   ok = gtk_button_new_with_label("Close");
 
   gtk_signal_connect_object (GTK_OBJECT (ok), "clicked",
@@ -460,140 +453,54 @@ save_as(GtkWidget* widget)
 }
 
 PRIVATE void
-element_changed(GtkMathView* math_view, GdomeElement* elem)
+selection_changed(GtkMathView* math_view, mDOMNodeRef node)
 {
   g_return_if_fail(math_view != NULL);
-  g_return_if_fail(main_area != NULL);
   g_return_if_fail(GTK_IS_MATH_VIEW(math_view));
-  /* fprintf(stderr, "node changed: %p %s\n", node, (node != NULL) ? mdom_node_get_name(node) : "-"); */
-
-  if (!loading) {
-    GdomeException exc = 0;
-    GdomeDOMString* namespaceURI = gdome_str_mkref(XLINK_NS_URI);
-    GdomeDOMString* localName = gdome_str_mkref("href");
-    
-    if (elem != NULL) {
-      gdome_el_ref(elem, &exc);
-      g_assert(exc == 0);
-    }
-
-    while (elem != NULL && !gdome_el_hasAttributeNS(elem, namespaceURI, localName, &exc)) {
-      GdomeElement* parent = gdome_cast_el(gdome_el_parentNode(elem, &exc));
-      g_assert(exc == 0);
-      gdome_el_unref(elem, &exc);
-      g_assert(exc == 0);
-      elem = parent;
-    }
-    g_assert(exc == 0);
-
-    gdome_str_unref(namespaceURI);
-    gdome_str_unref(localName);
-
-    if (elem != NULL) {
-      gdome_el_unref(elem, &exc);
-      g_assert(exc == 0);
-      gdk_window_set_cursor(main_area->window, link_cursor);
-    } else
-      gdk_window_set_cursor(main_area->window, normal_cursor);
-  }
+  gtk_math_view_set_selection(math_view, node);
 }
 
 PRIVATE void
-selection_changed(GtkMathView* math_view, GdomeElement* elem)
+jump(GtkMathView* math_view, mDOMNodeRef node)
 {
-  GdomeException exc = 0;
-  GdomeDOMString* localName = gdome_str_mkref("xref");
+  mDOMStringRef href;
 
-  g_return_if_fail(math_view != NULL);
-  g_return_if_fail(GTK_IS_MATH_VIEW(math_view));
+  g_return_if_fail(node != NULL);
+  href = mdom_node_get_attribute_ns(node, DOM_CONST_STRING("href"), XLINK_NS_URI);
 
-  if (elem != NULL) {
-    gdome_el_ref(elem, &exc);
-    g_assert(exc == 0);
-  }
+  if (href != NULL) {
+    pid_t pid;
 
-  while (elem != NULL && !gdome_el_hasAttribute(elem, localName, &exc)) {
-    GdomeElement* parent = gdome_cast_el(gdome_el_parentNode(elem, &exc));
-    g_assert(exc == 0);
-    gdome_el_unref(elem, &exc);
-    g_assert(exc == 0);
-    elem = parent;
-  }
+    g_assert(main_area != NULL);
+    gdk_window_set_cursor (main_area->window, pot);  
 
-  gdome_str_unref(localName);
+    pid = fork();
+    if (pid == -1) exit(-1);
+    if (pid == 0) {
+      gchar* open_url = g_strdup_printf("openURL(%s,cic)", href);
+      gint fd;
 
-  gtk_math_view_set_selection(math_view, elem);
-  if (elem != NULL) {
-    gdome_el_unref(elem, &exc);
-    g_assert(exc == 0);
-  }
-}
+      close(0);
+      close(1);
+      close(2);
 
-PRIVATE void
-jump(GdomeDOMString* href)
-{
-  pid_t pid;
-  g_return_if_fail(href != NULL);
-
-  gdk_window_set_cursor(main_area->window, pot_cursor);  
-  loading = TRUE;
-  pid = fork();
-  if (pid == -1) exit(-1);
-  if (pid == 0) {
-    gchar* open_url = g_strdup_printf("openURL(%s,cic)", href->str);
-    gint fd;
-    
-    close(0);
-    close(1);
-    close(2);
-    
-    fd = open("/dev/null", O_RDWR);
-    dup(fd);
-    dup(fd);
-    
-    execlp("netscape", "netscape", "-noraise", "-remote", open_url, NULL);
-    perror("exec failed:");
-    exit(-1);
+      fd = open("/dev/null", O_RDWR);
+      dup(fd);
+      dup(fd);
+
+      execlp("netscape", "netscape", "-noraise", "-remote", open_url, NULL);
+      perror("exec failed:");
+      exit(-1);
+    }
+    mdom_string_free(href);
   }
 }
 
 PRIVATE void
 clicked(GtkMathView* math_view, gpointer user_data)
 {
-  GdomeException exc = 0;
-  GdomeDOMString* namespaceURI = gdome_str_mkref(XLINK_NS_URI);
-  GdomeDOMString* localName = gdome_str_mkref("href");
-
-  GdomeElement* p = gtk_math_view_get_element(math_view);
-  while (p != NULL && !gdome_el_hasAttributeNS(p, namespaceURI, localName, &exc)) {
-    GdomeElement* parent = gdome_cast_el(gdome_el_parentNode(p, &exc));
-    g_assert(exc == 0);
-    gdome_el_unref(p, &exc);
-    g_assert(exc == 0);
-    p = parent;
-  }
-  g_assert(exc == 0);
-
-  if (p != NULL) {
-    GdomeDOMString* href = gdome_el_getAttributeNS(p, namespaceURI, localName, &exc);
-    g_assert(exc == 0);
-    g_assert(href != NULL);
-
-    jump(href);
-    gdome_str_unref(href);
-    gdome_el_unref(p, &exc);
-    g_assert(exc == 0);
-  } else {
-    p = gtk_math_view_get_action(math_view);
-    if (p != NULL) {
-      gtk_math_view_action_toggle(math_view);
-      gdome_el_unref(p, &exc);
-      g_assert(exc == 0);
-    }
-  }
-
-  gdome_str_unref(namespaceURI);
-  gdome_str_unref(localName);
+  if (gtk_math_view_get_action(math_view) != NULL)
+    gtk_math_view_action_toggle(math_view);
 }
 
 PRIVATE void
@@ -615,11 +522,11 @@ create_widget_set()
   gtk_widget_show(main_area);
 
   gtk_signal_connect_object (GTK_OBJECT (main_area),
-                            "element_changed", GTK_SIGNAL_FUNC (element_changed),
+                            "selection_changed", GTK_SIGNAL_FUNC (selection_changed),
                             (gpointer) main_area);
 
   gtk_signal_connect_object (GTK_OBJECT (main_area),
-                            "selection_changed", GTK_SIGNAL_FUNC (selection_changed),
+                            "jump", GTK_SIGNAL_FUNC(jump),
                             (gpointer) main_area);
 
   gtk_signal_connect_object (GTK_OBJECT (main_area), 
@@ -681,4 +588,3 @@ get_main_menu()
 
   return gtk_item_factory_get_widget(item_factory, "<main>");
 }
-