]> matita.cs.unibo.it Git - helm.git/commitdiff
* added popup menu, implemented some functions
authorLuca Padovani <luca.padovani@unito.it>
Sun, 5 Oct 2003 08:02:30 +0000 (08:02 +0000)
committerLuca Padovani <luca.padovani@unito.it>
Sun, 5 Oct 2003 08:02:30 +0000 (08:02 +0000)
helm/gtkmathview-bonobo/src/aux.cc
helm/gtkmathview-bonobo/src/control-data.c
helm/gtkmathview-bonobo/src/control-data.h
helm/gtkmathview-bonobo/src/control-factory.c
helm/gtkmathview-bonobo/src/handlers.c
helm/gtkmathview-bonobo/src/handlers.h
helm/gtkmathview-bonobo/test/testembedding.html

index b6d22c0992feaa1d8fd99c1e8b8b22a282d408b4..4ef5312399dc3b3356dc6923a5af6f8de0448300 100644 (file)
@@ -299,3 +299,4 @@ find_element_by_id(GdomeElement* root, GdomeDOMString* ns_uri, GdomeDOMString* n
                                    DOM::GdomeString(id));
   return gdome_cast_el(el.gdome_object());
 }
+
index 8668a3867b87f79aca1bf72557d94aa71c59457c..b4885bf2afdb68343415bfbd3cea3755603f6f55 100644 (file)
@@ -32,10 +32,14 @@ gtk_math_view_control_data_new(GtkMathView *math_view)
 {
   GtkMathViewControlData *cd = g_new(GtkMathViewControlData,1);
   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 = gdome_str_mkref("http://www.cs.unibo.it/helm");
   cd->id_name = gdome_str_mkref("xref");
+  cd->x = cd->y = 0;
   return cd;
 }
 
@@ -43,8 +47,13 @@ void
 gtk_math_view_control_data_destroy(GtkMathViewControlData* cd)
 {
   GdomeException exc = 0;
-  //gtk_object_unref(cd->math_view);
+  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);
@@ -99,3 +108,29 @@ gtk_math_view_control_data_set_id_name(GtkMathViewControlData* cd, const gchar*
   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)
+    {
+      gtk_math_view_unselect(cd->math_view, cd->root_selected);
+      gdome_el_unref(cd->root_selected, &exc);
+      g_assert(exc == 0);
+    }
+
+  cd->root_selected = elem;
+  if (cd->root_selected != NULL)
+    {
+      gdome_el_ref(cd->root_selected, &exc);
+      g_assert(exc == 0);
+      gtk_math_view_select(cd->math_view, cd->root_selected);
+    }
+
+  gtk_math_view_thaw(cd->math_view);
+}
index 8f81c12a8c5b22e5922178bdfef9cfc5317554c4..ecbaa1a7eca75690aeba77e207920d2c84838b6e 100644 (file)
 typedef struct _GtkMathViewControlData
 {
   GtkMathView* math_view;
+  GtkWidget* item_factory;
+  gboolean semantic_selection;
   GdomeElement* first_selected;
   GdomeElement* root_selected;
   GdomeDOMString* id_ns_uri;
   GdomeDOMString* id_name;
+  gint x;
+  gint y;
 } GtkMathViewControlData;
 
 GtkMathViewControlData* gtk_math_view_control_data_new(GtkMathView*);
@@ -42,5 +46,6 @@ gchar* gtk_math_view_control_data_get_id_ns_uri(GtkMathViewControlData*);
 void gtk_math_view_control_data_set_id_ns_uri(GtkMathViewControlData*, const gchar*);
 gchar* gtk_math_view_control_data_get_id_name(GtkMathViewControlData*);
 void gtk_math_view_control_data_set_id_name(GtkMathViewControlData*, const gchar*);
+void gtk_math_view_control_data_set_root_selected(GtkMathViewControlData*, GdomeElement*);
 
 #endif // __control_data_h__
index 847d9f4f6106358b2fa0848aba85fa3cef10f208..9f3edf1a8cdee29407cf0c731736c9e7f9888ac8 100644 (file)
@@ -46,6 +46,156 @@ enum
     MATH_VIEW_ID_NAME
   } math_args;
 
+static void
+activate_maction(GtkMathViewControlData* control_data, guint action, GtkWidget* widget)
+{
+  GdomeElement* elem;
+
+  g_return_if_fail(control_data != NULL);
+
+  elem = gtk_math_view_get_element_at(control_data->math_view, control_data->x, control_data->y);
+  if (elem != NULL)
+    {
+      GdomeException exc = 0;
+      GdomeElement* action = find_self_or_ancestor(elem, MATHML_NS_URI, "maction");
+      if (action != NULL)
+       {
+         gtk_math_view_freeze(control_data->math_view);
+         action_toggle(action);
+         gtk_math_view_thaw(control_data->math_view);
+         gdome_el_unref(action, &exc);
+         g_assert(exc == 0);
+       }
+      gdome_el_unref(elem, &exc);
+      g_assert(exc == 0);
+    }
+}
+
+static void
+copy_link_address(GtkMathViewControlData* control_data, guint action, GtkWidget* widget)
+{
+}
+
+static void
+zoom_in(GtkMathViewControlData* control_data, guint action, GtkWidget* widget)
+{
+  g_return_if_fail(control_data != NULL);
+  guint old_font_size = gtk_math_view_get_font_size(control_data->math_view);
+  gtk_math_view_set_font_size(control_data->math_view, old_font_size + 1);
+}
+
+static void
+zoom_out(GtkMathViewControlData* control_data, guint action, GtkWidget* widget)
+{
+  g_return_if_fail(control_data != NULL);
+  guint old_font_size = gtk_math_view_get_font_size(control_data->math_view);
+  gtk_math_view_set_font_size(control_data->math_view, old_font_size - 1);
+}
+
+static void
+switch_semantic_selection(GtkMathViewControlData* control_data, guint action, GtkWidget* widget)
+{
+  g_return_if_fail(control_data != NULL);
+  control_data->semantic_selection = !control_data->semantic_selection;
+  if (control_data->semantic_selection)
+    {
+      GdomeElement* elem = find_element_with_id(control_data->root_selected,
+                                               control_data->id_ns_uri,
+                                               control_data->id_name);
+    }
+}
+
+/*
+static void
+copy_selected_markup(GtkMathViewControlData* control_data, guint action, GtkWidget* widget)
+{
+  gchar* res = copy_markup(control_data->root_selected);
+  if (res != NULL)
+    {
+      set_clipboard(res);
+      g_free(res);
+    }
+}
+*/
+
+static void
+copy_selected_id(GtkMathViewControlData* control_data, guint action, GtkWidget* widget)
+{
+}
+
+static void
+select_parent(GtkMathViewControlData* control_data, guint action, GtkWidget* widget)
+{
+  g_return_if_fail(control_data != NULL);
+  if (control_data->root_selected != NULL)
+    {
+      GdomeException exc = 0;
+      GdomeNode* parent_node = gdome_el_parentNode(control_data->root_selected, &exc);
+      g_assert(parent_node != NULL);
+      g_assert(exc == 0);
+      GdomeElement* parent = gdome_cast_el(parent_node);
+      gtk_math_view_control_data_set_root_selected(control_data, parent);
+      gdome_n_unref(parent_node, &exc);
+      g_assert(exc == 0);
+    }
+}
+
+static void
+deselect(GtkMathViewControlData* control_data, guint action, GtkWidget* widget)
+{
+  g_return_if_fail(control_data != NULL);
+
+  if (control_data->root_selected != NULL)
+    {
+      gtk_math_view_unselect(control_data->math_view, control_data->root_selected);
+      control_data->root_selected = NULL;
+    }
+}
+
+/* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */
+static GtkItemFactoryEntry menu_items[] = {
+  { "/Activate <maction>", NULL,    activate_maction, 0, "<StockItem>", GTK_STOCK_EXECUTE },
+  { "/Copy Link Address",  NULL,    copy_link_address, 0, "<StockItem>", GTK_STOCK_COPY },
+  /*  { "/Jump To",       NULL,         NULL,           0, "<StockItem>", GTK_STOCK_JUMP_TO }, */
+  { "/sep1",          NULL,         NULL,           0, "<Separator>" },
+  /* { "/Semantic Selection", NULL,    switch_semantic_selection, 0, "<CheckItem>" }, */
+  /* { "/Copy Selected Markup", NULL,  copy_selected_markup, 0, "<Item>" }, */
+  /* { "/Copy Id",       NULL,         copy_selected_id, 0, "<Item>" }, */
+  /*  { "/Show Selected", NULL,         NULL,           0, "<Item>" }, */
+  { "/Select Parent", NULL,         select_parent,  0, "<Item>" },
+  { "/De-Select",     NULL,         deselect, 0, "<StockItem>", GTK_STOCK_CLEAR },
+  { "/sep2",          NULL,         NULL,           0, "<Separator>" },
+  { "/Smaller",       NULL,         zoom_out,       0, "<StockItem>", GTK_STOCK_ZOOM_OUT },
+  { "/Bigger",        NULL,         zoom_in,        0, "<StockItem>", GTK_STOCK_ZOOM_IN },
+  /* { "/Properties...", NULL,         NULL,           0, "<StockItem>", GTK_STOCK_PROPERTIES }, */
+};
+
+static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
+
+void
+button_pressed_cb(GtkMathView* math_view, GdkEventButton* event, GtkMathViewControlData* control_data)
+{
+  g_return_if_fail(math_view != NULL);
+  g_return_if_fail(event != NULL);
+  g_return_if_fail(control_data != NULL);
+
+  if (event->button == 3)
+    {
+#if 0
+      gtk_menu_popup (GTK_MENU(control_data->popup_menu), NULL, NULL,
+                     NULL, event, event->button, event->time);
+#endif
+      control_data->x = (gint) event->x;
+      control_data->y = (gint) event->y;
+      printf("data %d %d\n", control_data->x, control_data->y);
+      
+      gtk_item_factory_popup_with_data(control_data->item_factory,
+                                      NULL, NULL, event->x_root, event->y_root,
+                                      event->button, gtk_get_current_event_time());
+    }
+}
+
+
 static void
 get_prop(BonoboPropertyBag* bag,
         BonoboArg* arg,
@@ -159,6 +309,8 @@ gtk_math_view_control_init(BonoboControl *control, GtkWidget *scrolled_window)
 {
   GtkMathViewControlData *control_data;
   GtkWidget *math_view;
+  GtkItemFactory *item_factory;
+  
   Bonobo_UIContainer remote_ui_container;
   BonoboUIComponent *ui_component;
   
@@ -169,11 +321,17 @@ gtk_math_view_control_init(BonoboControl *control, GtkWidget *scrolled_window)
 
   math_view = gtk_math_view_new(NULL,NULL);
   gtk_widget_show(math_view);
-  
+
   control_data = gtk_math_view_control_data_new((GtkMathView*)math_view);
   
   g_signal_connect (control, "destroy", G_CALLBACK (control_destroy), control_data);
   
+  /* Same as before but don't bother with the accelerators */
+  control_data->item_factory = gtk_item_factory_new (GTK_TYPE_MENU, "<main>", NULL);
+  gtk_item_factory_create_items (control_data->item_factory, nmenu_items, menu_items, control_data);
+  /* control_data->popup_menu = gtk_item_factory_get_widget (control_data->item_factory, "<main>"); */
+  /* gtk_widget_ref(control_data->popup_menu); */
+
   gtk_container_add(GTK_CONTAINER (scrolled_window), GTK_WIDGET (control_data->math_view));
 
   view = view_new(control_data);
@@ -224,6 +382,8 @@ gtk_math_view_control_init(BonoboControl *control, GtkWidget *scrolled_window)
   bonobo_object_unref(BONOBO_OBJECT(prop_bag));
   
   g_signal_connect(control,"set_frame", G_CALLBACK(set_frame), control_data);
+  g_signal_connect(control_data->math_view, "button_press_event", G_CALLBACK (button_pressed_cb),
+                  control_data);
   g_signal_connect(control_data->math_view, "click", G_CALLBACK (click_cb),
                   control_data);
   g_signal_connect(control_data->math_view, "select_begin", G_CALLBACK(select_begin_cb),
index 85479ed1b61a129b5a4466fae9f7bdb2d2c0880d..78dc7ee66a4d51a47ba0212bc90db2c40b27c4bc 100644 (file)
@@ -102,7 +102,7 @@ select_begin_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
          control_data->root_selected = NULL;
        }
       
-      if (control_data->id_ns_uri != NULL || control_data->id_name != NULL)
+      if (control_data->semantic_selection)
        {
          GdomeElement* new_elem = find_element_with_id(elem, control_data->id_ns_uri, control_data->id_name);
          if (new_elem != NULL)
@@ -149,7 +149,7 @@ select_over_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
           control_data->root_selected = NULL;
        }
       
-      if (control_data->id_ns_uri != NULL || control_data->id_name != NULL)
+      if (control_data->semantic_selection)
        {
          GdomeElement* new_root = find_common_ancestor(control_data->first_selected, elem);
          if (new_root != NULL)
@@ -185,8 +185,7 @@ select_end_cb(GtkMathView* math_view, GdomeElement* elem, gint state,
       g_assert(exc == 0);
       control_data->first_selected = NULL;
 
-      if (control_data->root_selected != NULL &&
-         (control_data->id_ns_uri != NULL || control_data->id_name != NULL))
+      if (control_data->root_selected != NULL && control_data->semantic_selection)
        {
          GdomeException exc = 0;
          GdomeDOMString* id = gdome_el_getAttributeNS(control_data->root_selected,
index 529a13d7b7d9b9b4aacba227c9a458d55fd31033..47eda64b386a8422e6170b22cb08c80fd12e2039 100644 (file)
@@ -31,6 +31,7 @@
 #include "control-data.h"
 
 void set_frame(BonoboControl*, gpointer);
+void button_pressed_cb(GtkMathView*, GdkEventButton*, GtkMathViewControlData*);
 void click_cb(GtkMathView*, GdomeElement*, gint, GtkMathViewControlData*);
 void select_begin_cb(GtkMathView*,GdomeElement*, gint, GtkMathViewControlData*);
 void select_over_cb(GtkMathView*,GdomeElement*,gint, GtkMathViewControlData*);
index 77a42e452e0da9a009dbcc7f06432da5cbb1dcac..529360057a4af423f11db371abe414314a8b8db2 100644 (file)
@@ -4,16 +4,14 @@
 </head>
 <body>
 
-<div align="center">
-<br><br><br>
-Embedded Document using the &lt;object&gt; HTML tag
-<hr>
-<object data="test.mml" width="400" height="400" type="application/mathml+xml">
+<h1>GtkMathView-Bonobo test page</h1>
+
+The embedded object should display a mathematical formula.
+<br />
+<br />
+<object data="test.mml" width="400" height="100" type="application/mathml+xml">
 No viewer capable of displaying the test document installed.
 </object>
-<hr>
-
-</div>
 
 </body>
 </html>