aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoakim Verona2012-07-23 00:42:42 +0200
committerJoakim Verona2012-07-23 00:42:42 +0200
commit9b022dc31cc92c0890eb142f8c9f120aab479f5e (patch)
tree3a3d862fb7fae55ccae8bb2404cebb314977e14f /src
parent178a8604317dc1e86b30dda5a4415af1555521d1 (diff)
downloademacs-9b022dc31cc92c0890eb142f8c9f120aab479f5e.tar.gz
emacs-9b022dc31cc92c0890eb142f8c9f120aab479f5e.zip
its now possible to use xwgir to call for instance the zoom method on webkit!
Diffstat (limited to 'src')
-rw-r--r--src/xwidget.c87
1 files changed, 46 insertions, 41 deletions
diff --git a/src/xwidget.c b/src/xwidget.c
index cfaf6d686bd..caa0f0e1a31 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -139,7 +139,7 @@ Lisp_Object Qxwidget_embed_steal_window;
139Lisp_Object Qxwidget_info; 139Lisp_Object Qxwidget_info;
140Lisp_Object Qxwidget_resize; 140Lisp_Object Qxwidget_resize;
141Lisp_Object Qxwidget_send_keyboard_event; 141Lisp_Object Qxwidget_send_keyboard_event;
142 142Lisp_Object Qcxwgir_class;
143Lisp_Object Qbutton, Qtoggle, Qslider, Qsocket, Qsocket_osr, Qcairo, Qxwgir, 143Lisp_Object Qbutton, Qtoggle, Qslider, Qsocket, Qsocket_osr, Qcairo, Qxwgir,
144 Qwebkit_osr, QCplist; 144 Qwebkit_osr, QCplist;
145 145
@@ -605,32 +605,35 @@ xwidget_osr_button_callback (GtkWidget *widget,
605} 605}
606 606
607 607
608GtkWidget* xwgir_create(char* class){ 608GIRepository *girepository ;
609DEFUN( "xwgir-require-namespace",Fxwgir_require_namespace, Sxwgir_require_namespace, 2,2,0,
610 doc: /*require a namespace. must be done for all namespaces we want to use, before using other xwgir functions.*/)
611 (Lisp_Object lnamespace, Lisp_Object lnamespace_version)
612{
613 char* namespace = SDATA(lnamespace);
614 char* namespace_version = SDATA(lnamespace_version);
615 GError *error = NULL;
616
617 girepository = g_irepository_get_default();
618 g_irepository_require(girepository, namespace, namespace_version, 0, &error);
619 if (error) {
620 g_error("ERROR: %s\n", error->message);
621 return Qnil;
622 }
623 return Qt;
624}
625
626GtkWidget* xwgir_create(char* class, char* namespace){
627 //TODO this is more or less the same as xwgir-call-method, so should be refactored
609 //create a gtk widget, given its name 628 //create a gtk widget, given its name
610 //find the constructor 629 //find the constructor
611 //call it 630 //call it
612 //also figure out how to pass args 631 //also figure out how to pass args
613 /* gboolean g_function_info_invoke (GIFunctionInfo *info, */ 632
614 /* const GIArgument *in_args, */
615 /* int n_in_args, */
616 /* const GIArgument *out_args, */
617 /* int n_out_args, */
618 /* GIArgument *return_value, */
619 /* GError **error); */
620 char* namespace = "Gtk";
621 char* namespace_version = "3.0";
622 GError *error = NULL; 633 GError *error = NULL;
623 GIRepository *repository;
624 GIArgument return_value; 634 GIArgument return_value;
625 /* GtkWidget* rv; */
626 repository = g_irepository_get_default();
627 g_irepository_require(repository, namespace, namespace_version, 0, &error);
628 if (error) {
629 g_error("ERROR: %s\n", error->message);
630 return NULL;
631 }
632 635
633 GIObjectInfo* obj_info = g_irepository_find_by_name(repository, namespace, class); 636 GIObjectInfo* obj_info = g_irepository_find_by_name(girepository, namespace, class);
634 GIFunctionInfo* f_info = g_object_info_find_method (obj_info, "new"); 637 GIFunctionInfo* f_info = g_object_info_find_method (obj_info, "new");
635 g_function_info_invoke(f_info, 638 g_function_info_invoke(f_info,
636 NULL, 0, 639 NULL, 0,
@@ -719,35 +722,34 @@ DEFUN ("xwgir-call-method", Fxwgir_call_method, Sxwgir_call_method, 3, 3,
719 doc: /* call xwidget object method.*/) 722 doc: /* call xwidget object method.*/)
720 (Lisp_Object xwidget, Lisp_Object method, Lisp_Object arguments) 723 (Lisp_Object xwidget, Lisp_Object method, Lisp_Object arguments)
721{ 724{
722 char* namespace = "Gtk";
723 char* namespace_version = "3.0";
724 GError *error = NULL; 725 GError *error = NULL;
725 GIRepository *repository;
726 GIArgument return_value; 726 GIArgument return_value;
727 GIArgument in_args[20]; 727 GIArgument in_args[20];
728 /* GtkWidget* rv; */ 728
729 repository = g_irepository_get_default(); 729
730 g_irepository_require(repository, namespace, namespace_version, 0, &error);
731 if (error) {
732 printf("repo init error\n");
733 //for some reason the error struct is mysteriously corrupt TODO figure out
734 //g_error("ERROR: %s\n", error->message);
735 return Qnil;
736 }
737 struct xwidget* xw; 730 struct xwidget* xw;
738 if(!XXWIDGETP(xwidget)) {printf("ERROR not an xwidget\n"); return Qnil;}; 731 if(!XXWIDGETP(xwidget)) {printf("ERROR not an xwidget\n"); return Qnil;};
739 if(Qnil == xwidget) {printf("ERROR xwidget nil\n"); return Qnil;}; 732 if(Qnil == xwidget) {printf("ERROR xwidget nil\n"); return Qnil;};
740 xw = XXWIDGET(xwidget); 733 xw = XXWIDGET(xwidget);
741 if(NULL == xw) printf("ERROR xw is 0\n"); 734 if(NULL == xw) printf("ERROR xw is 0\n");
742 735 char* namespace = SDATA(Fcar(Fget(xw->type, Qcxwgir_class)));
743 //we need the concrete widget, which happens in 2 ways depending on OSR or not TODO 736 //we need the concrete widget, which happens in 2 ways depending on OSR or not TODO
744 GtkWidget* widget = (xwidget_view_lookup (xw, XWINDOW(FRAME_SELECTED_WINDOW (SELECTED_FRAME ()))) -> widget); //non osr case 737 GtkWidget* widget = NULL;
745 738 if(NULL == xw->widget_osr) {
739 widget = xwidget_view_lookup (xw, XWINDOW(FRAME_SELECTED_WINDOW (SELECTED_FRAME ()))) -> widget;
740 } else {
741 widget = xw->widget_osr;
742 }
743
746 //char* class = SDATA(SYMBOL_NAME(xw->type)); //this works but is unflexible 744 //char* class = SDATA(SYMBOL_NAME(xw->type)); //this works but is unflexible
747 //figure out the class from the widget instead 745 //figure out the class from the widget instead
748 char* class = G_OBJECT_TYPE_NAME(widget); //gives "GtkButton"(I want "Button") 746 /* printf("type class: %s %s\n", G_OBJECT_TYPE_NAME(widget), G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(widget))); */
749 class += strlen(namespace); //TODO check for corresponding api method 747 /* char* class = G_OBJECT_TYPE_NAME(widget); //gives "GtkButton"(I want "Button") */
750 GIObjectInfo* obj_info = g_irepository_find_by_name(repository, namespace, class); 748 /* class += strlen(namespace); //TODO check for corresponding api method. but this seems to work. */
749
750 char* class = SDATA(Fcar(Fcdr(Fget(xw->type, Qcxwgir_class))));
751
752 GIObjectInfo* obj_info = g_irepository_find_by_name(girepository, namespace, class);
751 GIFunctionInfo* f_info = g_object_info_find_method (obj_info, SDATA(method)); 753 GIFunctionInfo* f_info = g_object_info_find_method (obj_info, SDATA(method));
752 754
753 //loop over args, convert from lisp to primitive type, given arg introspection data 755 //loop over args, convert from lisp to primitive type, given arg introspection data
@@ -907,9 +909,11 @@ xwidget_init_view (struct xwidget *xww,
907 // - support constructor args 909 // - support constructor args
908 // - support signals 910 // - support signals
909 // - check that the argument widget type actually exists 911 // - check that the argument widget type actually exists
910 printf("xwgir symbol %s:\n",SDATA(SYMBOL_NAME(xww->type))); 912 printf("xwgir symbol %s %s %s:\n",SDATA(SYMBOL_NAME(xww->type)), SDATA(Fcar(Fcdr(Fget(xww->type, Qcxwgir_class)))), SDATA(Fcar(Fget(xww->type, Qcxwgir_class))));
911 //xv->widget = xwgir_create ("Button"); 913 //xv->widget = xwgir_create ("Button");
912 xv->widget = xwgir_create(SDATA(SYMBOL_NAME(xww->type))); 914 Fcar(Fget(xww->type, Qcxwgir_class));
915 xv->widget = xwgir_create( SDATA(Fcar(Fcdr(Fget(xww->type, Qcxwgir_class)))),
916 SDATA(Fcar(Fget(xww->type, Qcxwgir_class))));
913 917
914 } 918 }
915 919
@@ -1416,7 +1420,7 @@ syms_of_xwidget (void)
1416#endif 1420#endif
1417 1421
1418 defsubr (&Sxwgir_call_method ); 1422 defsubr (&Sxwgir_call_method );
1419 1423 defsubr (&Sxwgir_require_namespace);
1420 defsubr (&Sxwidget_size_request ); 1424 defsubr (&Sxwidget_size_request );
1421 defsubr (&Sxwidget_delete_zombies); 1425 defsubr (&Sxwidget_delete_zombies);
1422 defsubr (&Sxwidget_disable_plugin_for_mime); 1426 defsubr (&Sxwidget_disable_plugin_for_mime);
@@ -1430,6 +1434,7 @@ syms_of_xwidget (void)
1430 DEFSYM (Qxwidget ,"xwidget"); 1434 DEFSYM (Qxwidget ,"xwidget");
1431 1435
1432 DEFSYM (Qcxwidget ,":xwidget"); 1436 DEFSYM (Qcxwidget ,":xwidget");
1437 DEFSYM (Qcxwgir_class ,":xwgir-class");
1433 DEFSYM (Qtitle ,":title"); 1438 DEFSYM (Qtitle ,":title");
1434 1439
1435 DEFSYM (Qbutton, "Button"); //changed to match the gtk class because xwgir(experimental and not really needed) 1440 DEFSYM (Qbutton, "Button"); //changed to match the gtk class because xwgir(experimental and not really needed)