]> matita.cs.unibo.it Git - helm.git/commitdiff
- new handling of links
authorLuca Padovani <luca.padovani@unito.it>
Sat, 10 Nov 2001 19:16:54 +0000 (19:16 +0000)
committerLuca Padovani <luca.padovani@unito.it>
Sat, 10 Nov 2001 19:16:54 +0000 (19:16 +0000)
- no more conflict between links and actions (links have precedence)
- cursors now handled by helmpot
- fixed problem with pot cursor

helm/helmpot/configure.in
helm/helmpot/guiGTK.c

index 58025f81624a30e8ac6433180d12e1959cc8a57d..b36ac29daf88c561ccb70377050ee5c8aad2738b 100644 (file)
@@ -3,7 +3,7 @@ AC_INIT(main.c)
 
 HELMPOT_MAJOR_VERSION=0
 HELMPOT_MINOR_VERSION=0
-HELMPOT_MICRO_VERSION=3
+HELMPOT_MICRO_VERSION=4
 HELMPOT_VERSION=$HELMPOT_MAJOR_VERSION.$HELMPOT_MINOR_VERSION.$HELMPOT_MICRO_VERSION
 VERSION=$HELMPOT_VERSION
 
@@ -62,6 +62,12 @@ AC_CHECK_LIB(minidom, mdom_node_get_type,
        `minidom-config --libs` `glib-config --libs`
 )
 
+vers=`minidom-config --version | awk -F. '{ printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
+minvers=`echo 0.1.3 | awk -F. '{ printf "%d", ($1 * 1000 + $2) * 1000 + $3;}'`
+if test "$vers" -lt "$minvers"; then
+        AC_MSG_ERROR(you need at least minidom 0.1.3)
+fi
+
 AC_CHECK_LIB(gtkmathview, gtk_math_view_new,
        [
                CFLAGS="$CFLAGS `gtkmathview-config --cflags`"
index 5ca382d91e6a57e70b49488b131cea482a0c9ec4..4384f3cef2c5d8cbc8b20d81034f7bf0db5fceee 100644 (file)
@@ -65,8 +65,11 @@ PRIVATE GtkMenuItem* anti_aliasing_item;
 PRIVATE GtkMenuItem* font_size_item;
 PRIVATE gchar* file_name = NULL;
 
-PRIVATE GdkCursor* pot;
+PRIVATE GdkCursor* normal_cursor;
+PRIVATE GdkCursor* link_cursor;  
+PRIVATE GdkCursor* pot_cursor;
 
+PRIVATE gboolean loading = FALSE;
 PRIVATE guint statusbar_context;
 
 PRIVATE void create_widget_set(void);
@@ -176,11 +179,14 @@ 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 = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 8, 8);
+  pot_cursor = gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, 8, 8);
   gdk_pixmap_unref (source);
   gdk_pixmap_unref (mask);  
 }
@@ -195,6 +201,7 @@ 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);
@@ -206,9 +213,13 @@ GUI_load_document(const gchar* name)
   klass = (GtkMathViewClass*) gtk_type_class(gtk_math_view_get_type());
   g_return_val_if_fail(klass != NULL, -1);
 
-  gdk_window_set_cursor (main_area->window, pot);  
+  gdk_window_set_cursor(main_area->window, pot_cursor);  
+  loading = TRUE;
+  res = gtk_math_view_load(math_view, name);
+  gdk_window_set_cursor(main_area->window, normal_cursor);
+  loading = FALSE;
 
-  if (!gtk_math_view_load(math_view, name)) {
+  if (!res) {
     load_error_msg(name);
     return -1;
   }
@@ -217,8 +228,6 @@ 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);
 
@@ -452,6 +461,25 @@ save_as(GtkWidget* widget)
   file_dialog("Save As...", save_filename);
 }
 
+PRIVATE void
+element_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) {
+    while (node != NULL && !mdom_node_has_attribute_ns(node, DOM_CONST_STRING("href"), XLINK_NS_URI))
+      node = mdom_node_get_parent(node);
+
+    if (node != NULL) {
+      gdk_window_set_cursor(main_area->window, link_cursor);
+    } else
+      gdk_window_set_cursor(main_area->window, normal_cursor);
+  }
+}
+
 PRIVATE void
 selection_changed(GtkMathView* math_view, mDOMNodeRef node)
 {
@@ -465,45 +493,45 @@ selection_changed(GtkMathView* math_view, mDOMNodeRef node)
 }
 
 PRIVATE void
-jump(GtkMathView* math_view, mDOMNodeRef node)
+jump(mDOMConstStringRef href)
 {
-  mDOMStringRef href;
-
-  g_return_if_fail(node != NULL);
-  href = mdom_node_get_attribute_ns(node, DOM_CONST_STRING("href"), XLINK_NS_URI);
-
-  if (href != NULL) {
-    pid_t pid;
-
-    g_assert(main_area != NULL);
-    gdk_window_set_cursor (main_area->window, pot);  
-
-    pid = fork();
-    if (pid == -1) exit(-1);
-    if (pid == 0) {
-      gchar* open_url = g_strdup_printf("openURL(%s,cic)", href);
-      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);
-    }
-    mdom_string_free(href);
+  pid_t pid;
+  g_return_if_fail(href != NULL);
+
+  pid = fork();
+  if (pid == -1) exit(-1);
+  if (pid == 0) {
+    gchar* open_url = g_strdup_printf("openURL(%s,cic)", href);
+    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);
   }
 }
 
 PRIVATE void
 clicked(GtkMathView* math_view, gpointer user_data)
 {
-  if (gtk_math_view_get_action(math_view) != NULL)
+  mDOMNodeRef p = gtk_math_view_get_element(math_view);
+  while (p != NULL && !mdom_node_has_attribute_ns(p, DOM_CONST_STRING("href"), XLINK_NS_URI))
+    p = mdom_node_get_parent(p);
+
+  if (p != NULL) {
+    mDOMStringRef href = mdom_node_get_attribute_ns(p, DOM_CONST_STRING("href"), XLINK_NS_URI);
+    g_assert(href != NULL);
+
+    jump(C_CONST_STRING(href));
+    mdom_string_free(href);
+  } else if (gtk_math_view_get_action(math_view) != NULL)
     gtk_math_view_action_toggle(math_view);
 }
 
@@ -526,11 +554,11 @@ create_widget_set()
   gtk_widget_show(main_area);
 
   gtk_signal_connect_object (GTK_OBJECT (main_area),
-                            "selection_changed", GTK_SIGNAL_FUNC (selection_changed),
+                            "element_changed", GTK_SIGNAL_FUNC (element_changed),
                             (gpointer) main_area);
 
   gtk_signal_connect_object (GTK_OBJECT (main_area),
-                            "jump", GTK_SIGNAL_FUNC(jump),
+                            "selection_changed", GTK_SIGNAL_FUNC (selection_changed),
                             (gpointer) main_area);
 
   gtk_signal_connect_object (GTK_OBJECT (main_area),