From: Luca Padovani Date: Sun, 5 Oct 2003 08:02:30 +0000 (+0000) Subject: * added popup menu, implemented some functions X-Git-Tag: v0_0_2~1 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=4faf0e37e7019de16dd6862bb34d84f799a2a230;p=helm.git * added popup menu, implemented some functions --- diff --git a/helm/gtkmathview-bonobo/src/aux.cc b/helm/gtkmathview-bonobo/src/aux.cc index b6d22c099..4ef531239 100644 --- a/helm/gtkmathview-bonobo/src/aux.cc +++ b/helm/gtkmathview-bonobo/src/aux.cc @@ -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()); } + diff --git a/helm/gtkmathview-bonobo/src/control-data.c b/helm/gtkmathview-bonobo/src/control-data.c index 8668a3867..b4885bf2a 100644 --- a/helm/gtkmathview-bonobo/src/control-data.c +++ b/helm/gtkmathview-bonobo/src/control-data.c @@ -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); +} diff --git a/helm/gtkmathview-bonobo/src/control-data.h b/helm/gtkmathview-bonobo/src/control-data.h index 8f81c12a8..ecbaa1a7e 100644 --- a/helm/gtkmathview-bonobo/src/control-data.h +++ b/helm/gtkmathview-bonobo/src/control-data.h @@ -30,10 +30,14 @@ 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__ diff --git a/helm/gtkmathview-bonobo/src/control-factory.c b/helm/gtkmathview-bonobo/src/control-factory.c index 847d9f4f6..9f3edf1a8 100644 --- a/helm/gtkmathview-bonobo/src/control-factory.c +++ b/helm/gtkmathview-bonobo/src/control-factory.c @@ -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 ", NULL, activate_maction, 0, "", GTK_STOCK_EXECUTE }, + { "/Copy Link Address", NULL, copy_link_address, 0, "", GTK_STOCK_COPY }, + /* { "/Jump To", NULL, NULL, 0, "", GTK_STOCK_JUMP_TO }, */ + { "/sep1", NULL, NULL, 0, "" }, + /* { "/Semantic Selection", NULL, switch_semantic_selection, 0, "" }, */ + /* { "/Copy Selected Markup", NULL, copy_selected_markup, 0, "" }, */ + /* { "/Copy Id", NULL, copy_selected_id, 0, "" }, */ + /* { "/Show Selected", NULL, NULL, 0, "" }, */ + { "/Select Parent", NULL, select_parent, 0, "" }, + { "/De-Select", NULL, deselect, 0, "", GTK_STOCK_CLEAR }, + { "/sep2", NULL, NULL, 0, "" }, + { "/Smaller", NULL, zoom_out, 0, "", GTK_STOCK_ZOOM_OUT }, + { "/Bigger", NULL, zoom_in, 0, "", GTK_STOCK_ZOOM_IN }, + /* { "/Properties...", NULL, NULL, 0, "", 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, "
", 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, "
"); */ + /* 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), diff --git a/helm/gtkmathview-bonobo/src/handlers.c b/helm/gtkmathview-bonobo/src/handlers.c index 85479ed1b..78dc7ee66 100644 --- a/helm/gtkmathview-bonobo/src/handlers.c +++ b/helm/gtkmathview-bonobo/src/handlers.c @@ -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, diff --git a/helm/gtkmathview-bonobo/src/handlers.h b/helm/gtkmathview-bonobo/src/handlers.h index 529a13d7b..47eda64b3 100644 --- a/helm/gtkmathview-bonobo/src/handlers.h +++ b/helm/gtkmathview-bonobo/src/handlers.h @@ -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*); diff --git a/helm/gtkmathview-bonobo/test/testembedding.html b/helm/gtkmathview-bonobo/test/testembedding.html index 77a42e452..529360057 100644 --- a/helm/gtkmathview-bonobo/test/testembedding.html +++ b/helm/gtkmathview-bonobo/test/testembedding.html @@ -4,16 +4,14 @@ -
-


-Embedded Document using the <object> HTML tag -
- +

GtkMathView-Bonobo test page

+ +The embedded object should display a mathematical formula. +
+
+ No viewer capable of displaying the test document installed. -
- -