aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2016-01-30 11:27:34 -0800
committerPaul Eggert2016-01-30 11:27:34 -0800
commit82b089783e71b2aeef950eaecfe4cbc0735e64a2 (patch)
treea826c20768071bda95a69b2632718c1641c6d0cc /src
parentd27c8078ef766dae3587bc82b70128a70efaa223 (diff)
parentf7dc6d8b5bb318e02a4016d93f8b34de0716f4dc (diff)
downloademacs-82b089783e71b2aeef950eaecfe4cbc0735e64a2.tar.gz
emacs-82b089783e71b2aeef950eaecfe4cbc0735e64a2.zip
-
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.in9
-rw-r--r--src/buffer.c6
-rw-r--r--src/dispextern.h28
-rw-r--r--src/dispnew.c12
-rw-r--r--src/emacs.c6
-rw-r--r--src/emacsgtkfixed.c123
-rw-r--r--src/emacsgtkfixed.h20
-rw-r--r--src/keyboard.c18
-rw-r--r--src/lisp.h6
-rw-r--r--src/print.c16
-rw-r--r--src/termhooks.h5
-rw-r--r--src/window.c6
-rw-r--r--src/xdisp.c248
-rw-r--r--src/xterm.c14
-rw-r--r--src/xwidget.c1320
-rw-r--r--src/xwidget.h132
16 files changed, 1945 insertions, 24 deletions
diff --git a/src/Makefile.in b/src/Makefile.in
index defce62c529..b38e7d558b8 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -152,6 +152,9 @@ DBUS_LIBS = @DBUS_LIBS@
152## dbusbind.o if HAVE_DBUS, else empty. 152## dbusbind.o if HAVE_DBUS, else empty.
153DBUS_OBJ = @DBUS_OBJ@ 153DBUS_OBJ = @DBUS_OBJ@
154 154
155## xwidgets.o if HAVE_XWIDGETS, else empty.
156XWIDGETS_OBJ = @XWIDGETS_OBJ@
157
155LIB_EXECINFO=@LIB_EXECINFO@ 158LIB_EXECINFO=@LIB_EXECINFO@
156 159
157SETTINGS_CFLAGS = @SETTINGS_CFLAGS@ 160SETTINGS_CFLAGS = @SETTINGS_CFLAGS@
@@ -220,6 +223,9 @@ CFLAGS_SOUND= @CFLAGS_SOUND@
220RSVG_LIBS= @RSVG_LIBS@ 223RSVG_LIBS= @RSVG_LIBS@
221RSVG_CFLAGS= @RSVG_CFLAGS@ 224RSVG_CFLAGS= @RSVG_CFLAGS@
222 225
226WEBKIT_LIBS= @WEBKIT_LIBS@
227WEBKIT_CFLAGS= @WEBKIT_CFLAGS@
228
223CAIRO_LIBS= @CAIRO_LIBS@ 229CAIRO_LIBS= @CAIRO_LIBS@
224CAIRO_CFLAGS= @CAIRO_CFLAGS@ 230CAIRO_CFLAGS= @CAIRO_CFLAGS@
225 231
@@ -359,6 +365,7 @@ ALL_CFLAGS=-Demacs $(MYCPPFLAGS) -I. -I$(srcdir) \
359 $(GNUSTEP_CFLAGS) $(CFLAGS_SOUND) $(RSVG_CFLAGS) $(IMAGEMAGICK_CFLAGS) \ 365 $(GNUSTEP_CFLAGS) $(CFLAGS_SOUND) $(RSVG_CFLAGS) $(IMAGEMAGICK_CFLAGS) \
360 $(PNG_CFLAGS) $(LIBXML2_CFLAGS) $(DBUS_CFLAGS) \ 366 $(PNG_CFLAGS) $(LIBXML2_CFLAGS) $(DBUS_CFLAGS) \
361 $(XRANDR_CFLAGS) $(XINERAMA_CFLAGS) $(XFIXES_CFLAGS) \ 367 $(XRANDR_CFLAGS) $(XINERAMA_CFLAGS) $(XFIXES_CFLAGS) \
368 $(WEBKIT_CFLAGS) \
362 $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \ 369 $(SETTINGS_CFLAGS) $(FREETYPE_CFLAGS) $(FONTCONFIG_CFLAGS) \
363 $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) \ 370 $(LIBOTF_CFLAGS) $(M17N_FLT_CFLAGS) $(DEPFLAGS) \
364 $(LIBGNUTLS_CFLAGS) $(NOTIFY_CFLAGS) $(CAIRO_CFLAGS) \ 371 $(LIBGNUTLS_CFLAGS) $(NOTIFY_CFLAGS) $(CAIRO_CFLAGS) \
@@ -388,6 +395,7 @@ base_obj = dispnew.o frame.o scroll.o xdisp.o menu.o $(XMENU_OBJ) window.o \
388 process.o gnutls.o callproc.o \ 395 process.o gnutls.o callproc.o \
389 region-cache.o sound.o atimer.o \ 396 region-cache.o sound.o atimer.o \
390 doprnt.o intervals.o textprop.o composite.o xml.o $(NOTIFY_OBJ) \ 397 doprnt.o intervals.o textprop.o composite.o xml.o $(NOTIFY_OBJ) \
398 $(XWIDGETS_OBJ) \
391 profiler.o decompress.o \ 399 profiler.o decompress.o \
392 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \ 400 $(MSDOS_OBJ) $(MSDOS_X_OBJ) $(NS_OBJ) $(CYGWIN_OBJ) $(FONT_OBJ) \
393 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ) $(XGSELOBJ) 401 $(W32_OBJ) $(WINDOW_SYSTEM_OBJ) $(XGSELOBJ)
@@ -468,6 +476,7 @@ lisp = $(addprefix ${lispsource}/,${shortlisp})
468LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \ 476LIBES = $(LIBS) $(W32_LIBS) $(LIBS_GNUSTEP) $(LIBX_BASE) $(LIBIMAGE) \
469 $(LIBX_OTHER) $(LIBSOUND) \ 477 $(LIBX_OTHER) $(LIBSOUND) \
470 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_ACL) $(LIB_CLOCK_GETTIME) \ 478 $(RSVG_LIBS) $(IMAGEMAGICK_LIBS) $(LIB_ACL) $(LIB_CLOCK_GETTIME) \
479 $(WEBKIT_LIBS) \
471 $(LIB_EACCESS) $(LIB_FDATASYNC) $(LIB_TIMER_TIME) $(DBUS_LIBS) \ 480 $(LIB_EACCESS) $(LIB_FDATASYNC) $(LIB_TIMER_TIME) $(DBUS_LIBS) \
472 $(LIB_EXECINFO) $(XRANDR_LIBS) $(XINERAMA_LIBS) $(XFIXES_LIBS) \ 481 $(LIB_EXECINFO) $(XRANDR_LIBS) $(XINERAMA_LIBS) $(XFIXES_LIBS) \
473 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) $(CAIRO_LIBS) \ 482 $(LIBXML2_LIBS) $(LIBGPM) $(LIBRESOLV) $(LIBS_SYSTEM) $(CAIRO_LIBS) \
diff --git a/src/buffer.c b/src/buffer.c
index 4df77a181d6..51bbad78bbc 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -43,6 +43,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
43#include "keymap.h" 43#include "keymap.h"
44#include "frame.h" 44#include "frame.h"
45 45
46#ifdef HAVE_XWIDGETS
47# include "xwidget.h"
48#endif
46#ifdef WINDOWSNT 49#ifdef WINDOWSNT
47#include "w32heap.h" /* for mmap_* */ 50#include "w32heap.h" /* for mmap_* */
48#endif 51#endif
@@ -1747,6 +1750,9 @@ cleaning up all windows currently displaying the buffer to be killed. */)
1747 1750
1748 kill_buffer_processes (buffer); 1751 kill_buffer_processes (buffer);
1749 1752
1753#ifdef HAVE_XWIDGETS
1754 kill_buffer_xwidgets (buffer);
1755#endif
1750 /* Killing buffer processes may run sentinels which may have killed 1756 /* Killing buffer processes may run sentinels which may have killed
1751 our buffer. */ 1757 our buffer. */
1752 if (!BUFFER_LIVE_P (b)) 1758 if (!BUFFER_LIVE_P (b))
diff --git a/src/dispextern.h b/src/dispextern.h
index bb876f5af70..fad5bfd6f2f 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -348,6 +348,10 @@ enum glyph_type
348 348
349 /* Glyph is a space of fractional width and/or height. */ 349 /* Glyph is a space of fractional width and/or height. */
350 STRETCH_GLYPH 350 STRETCH_GLYPH
351#ifdef HAVE_XWIDGETS
352 /* Glyph is an external widget drawn by the GUI toolkit. */
353 ,XWIDGET_GLYPH
354#endif
351}; 355};
352 356
353 357
@@ -499,6 +503,9 @@ struct glyph
499 /* Image ID for image glyphs (type == IMAGE_GLYPH). */ 503 /* Image ID for image glyphs (type == IMAGE_GLYPH). */
500 int img_id; 504 int img_id;
501 505
506#ifdef HAVE_XWIDGETS
507 struct xwidget *xwidget;
508#endif
502 /* Sub-structure for type == STRETCH_GLYPH. */ 509 /* Sub-structure for type == STRETCH_GLYPH. */
503 struct 510 struct
504 { 511 {
@@ -1350,6 +1357,9 @@ struct glyph_string
1350 /* Image, if any. */ 1357 /* Image, if any. */
1351 struct image *img; 1358 struct image *img;
1352 1359
1360#ifdef HAVE_XWIDGETS
1361 struct xwidget *xwidget;
1362#endif
1353 /* Slice */ 1363 /* Slice */
1354 struct glyph_slice slice; 1364 struct glyph_slice slice;
1355 1365
@@ -2102,6 +2112,10 @@ enum display_element_type
2102 2112
2103 /* Continuation glyphs. See the comment for IT_TRUNCATION. */ 2113 /* Continuation glyphs. See the comment for IT_TRUNCATION. */
2104 IT_CONTINUATION 2114 IT_CONTINUATION
2115
2116#ifdef HAVE_XWIDGETS
2117 ,IT_XWIDGET
2118#endif
2105}; 2119};
2106 2120
2107 2121
@@ -2165,6 +2179,9 @@ enum it_method {
2165 GET_FROM_C_STRING, 2179 GET_FROM_C_STRING,
2166 GET_FROM_IMAGE, 2180 GET_FROM_IMAGE,
2167 GET_FROM_STRETCH, 2181 GET_FROM_STRETCH,
2182#ifdef HAVE_XWIDGETS
2183 GET_FROM_XWIDGET,
2184#endif
2168 NUM_IT_METHODS 2185 NUM_IT_METHODS
2169}; 2186};
2170 2187
@@ -2382,6 +2399,12 @@ struct it
2382 struct { 2399 struct {
2383 Lisp_Object object; 2400 Lisp_Object object;
2384 } stretch; 2401 } stretch;
2402#ifdef HAVE_XWIDGETS
2403 /* method == GET_FROM_XWIDGET */
2404 struct {
2405 Lisp_Object object;
2406 } xwidget;
2407#endif
2385 } u; 2408 } u;
2386 2409
2387 /* Current text and display positions. */ 2410 /* Current text and display positions. */
@@ -2506,6 +2529,11 @@ struct it
2506 /* If what == IT_IMAGE, the id of the image to display. */ 2529 /* If what == IT_IMAGE, the id of the image to display. */
2507 ptrdiff_t image_id; 2530 ptrdiff_t image_id;
2508 2531
2532#ifdef HAVE_XWIDGETS
2533 /* If what == IT_XWIDGET. */
2534 struct xwidget *xwidget;
2535#endif
2536
2509 /* Values from `slice' property. */ 2537 /* Values from `slice' property. */
2510 struct it_slice slice; 2538 struct it_slice slice;
2511 2539
diff --git a/src/dispnew.c b/src/dispnew.c
index 8d671f82e47..32c0dff9b92 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -44,6 +44,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
44#include TERM_HEADER 44#include TERM_HEADER
45#endif /* HAVE_WINDOW_SYSTEM */ 45#endif /* HAVE_WINDOW_SYSTEM */
46 46
47#ifdef HAVE_XWIDGETS
48# include "xwidget.h"
49#endif
50
47#include <errno.h> 51#include <errno.h>
48 52
49#include <fpending.h> 53#include <fpending.h>
@@ -3543,6 +3547,9 @@ update_window (struct window *w, bool force_p)
3543 add_window_display_history (w, w->current_matrix->method, paused_p); 3547 add_window_display_history (w, w->current_matrix->method, paused_p);
3544#endif 3548#endif
3545 3549
3550#ifdef HAVE_XWIDGETS
3551 xwidget_end_redisplay (w, w->current_matrix);
3552#endif
3546 clear_glyph_matrix (desired_matrix); 3553 clear_glyph_matrix (desired_matrix);
3547 3554
3548 return paused_p; 3555 return paused_p;
@@ -4116,6 +4123,11 @@ scrolling_window (struct window *w, bool header_line_p)
4116 break; 4123 break;
4117 } 4124 }
4118 4125
4126#ifdef HAVE_XWIDGETS
4127 /* Currently this seems needed to detect xwidget movement reliably. */
4128 return 0;
4129#endif
4130
4119 /* Give up if some rows in the desired matrix are not enabled. */ 4131 /* Give up if some rows in the desired matrix are not enabled. */
4120 if (! MATRIX_ROW_ENABLED_P (desired_matrix, i)) 4132 if (! MATRIX_ROW_ENABLED_P (desired_matrix, i))
4121 return -1; 4133 return -1;
diff --git a/src/emacs.c b/src/emacs.c
index aaf058e4a80..fcf048ca84b 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -66,6 +66,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
66#include "buffer.h" 66#include "buffer.h"
67#include "window.h" 67#include "window.h"
68 68
69#ifdef HAVE_XWIDGETS
70# include "xwidget.h"
71#endif
69#include "atimer.h" 72#include "atimer.h"
70#include "blockinput.h" 73#include "blockinput.h"
71#include "syssignal.h" 74#include "syssignal.h"
@@ -1492,6 +1495,9 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem
1492 syms_of_xfns (); 1495 syms_of_xfns ();
1493 syms_of_xmenu (); 1496 syms_of_xmenu ();
1494 syms_of_fontset (); 1497 syms_of_fontset ();
1498#ifdef HAVE_XWIDGETS
1499 syms_of_xwidget ();
1500#endif
1495 syms_of_xsettings (); 1501 syms_of_xsettings ();
1496#ifdef HAVE_X_SM 1502#ifdef HAVE_X_SM
1497 syms_of_xsmfns (); 1503 syms_of_xsmfns ();
diff --git a/src/emacsgtkfixed.c b/src/emacsgtkfixed.c
index cdcaf803ba5..08b840389c5 100644
--- a/src/emacsgtkfixed.c
+++ b/src/emacsgtkfixed.c
@@ -23,6 +23,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23#include "lisp.h" 23#include "lisp.h"
24#include "frame.h" 24#include "frame.h"
25#include "xterm.h" 25#include "xterm.h"
26#ifdef HAVE_XWIDGETS
27# include "xwidget.h"
28#endif
26#include "emacsgtkfixed.h" 29#include "emacsgtkfixed.h"
27 30
28/* Silence a bogus diagnostic; see GNOME bug 683906. */ 31/* Silence a bogus diagnostic; see GNOME bug 683906. */
@@ -31,27 +34,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31# pragma GCC diagnostic ignored "-Wunused-local-typedefs" 34# pragma GCC diagnostic ignored "-Wunused-local-typedefs"
32#endif 35#endif
33 36
34#define EMACS_TYPE_FIXED emacs_fixed_get_type ()
35#define EMACS_FIXED(obj) \
36 G_TYPE_CHECK_INSTANCE_CAST (obj, EMACS_TYPE_FIXED, EmacsFixed)
37
38typedef struct _EmacsFixed EmacsFixed; 37typedef struct _EmacsFixed EmacsFixed;
39typedef struct _EmacsFixedPrivate EmacsFixedPrivate; 38typedef struct _EmacsFixedPrivate EmacsFixedPrivate;
40typedef struct _EmacsFixedClass EmacsFixedClass; 39typedef struct _EmacsFixedClass EmacsFixedClass;
41 40
42struct _EmacsFixed
43{
44 GtkFixed container;
45
46 /*< private >*/
47 EmacsFixedPrivate *priv;
48};
49
50struct _EmacsFixedClass
51{
52 GtkFixedClass parent_class;
53};
54
55struct _EmacsFixedPrivate 41struct _EmacsFixedPrivate
56{ 42{
57 struct frame *f; 43 struct frame *f;
@@ -64,9 +50,103 @@ static void emacs_fixed_get_preferred_width (GtkWidget *widget,
64static void emacs_fixed_get_preferred_height (GtkWidget *widget, 50static void emacs_fixed_get_preferred_height (GtkWidget *widget,
65 gint *minimum, 51 gint *minimum,
66 gint *natural); 52 gint *natural);
53
67static GType emacs_fixed_get_type (void); 54static GType emacs_fixed_get_type (void);
68G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED) 55G_DEFINE_TYPE (EmacsFixed, emacs_fixed, GTK_TYPE_FIXED)
69 56
57static EmacsFixed *
58EMACS_FIXED (GtkWidget *widget)
59{
60 return G_TYPE_CHECK_INSTANCE_CAST (widget, emacs_fixed_get_type (),
61 EmacsFixed);
62}
63
64#ifdef HAVE_XWIDGETS
65
66static EmacsFixedClass *
67EMACS_FIXED_GET_CLASS (GtkWidget *widget)
68{
69 return G_TYPE_INSTANCE_GET_CLASS (widget, emacs_fixed_get_type (),
70 EmacsFixedClass);
71}
72
73struct GtkFixedPrivateL
74{
75 GList *children;
76};
77
78static void emacs_fixed_gtk_widget_size_allocate (GtkWidget *widget,
79 GtkAllocation *allocation)
80{
81 // For xwidgets.
82
83 // This basically re-implements the base class method and adds an
84 // additional case for an xwidget view.
85
86 // It would be nicer if the bse class method could be called first,
87 // and the the xview modification only would remain here. It wasn't
88 // possible to solve it that way yet.
89 EmacsFixedClass *klass;
90 GtkWidgetClass *parent_class;
91 struct GtkFixedPrivateL* priv;
92
93 klass = EMACS_FIXED_GET_CLASS (widget);
94 parent_class = g_type_class_peek_parent (klass);
95 parent_class->size_allocate (widget, allocation);
96
97 priv = G_TYPE_INSTANCE_GET_PRIVATE (widget,
98 GTK_TYPE_FIXED,
99 struct GtkFixedPrivateL);
100
101 gtk_widget_set_allocation (widget, allocation);
102
103 if (gtk_widget_get_has_window (widget))
104 {
105 if (gtk_widget_get_realized (widget))
106 gdk_window_move_resize (gtk_widget_get_window (widget),
107 allocation->x,
108 allocation->y,
109 allocation->width,
110 allocation->height);
111 }
112
113 for (GList *children = priv->children; children; children = children->next)
114 {
115 GtkFixedChild *child = children->data;
116
117 if (!gtk_widget_get_visible (child->widget))
118 continue;
119
120 GtkRequisition child_requisition;
121 gtk_widget_get_preferred_size (child->widget, &child_requisition, NULL);
122
123 GtkAllocation child_allocation;
124 child_allocation.x = child->x;
125 child_allocation.y = child->y;
126
127 if (!gtk_widget_get_has_window (widget))
128 {
129 child_allocation.x += allocation->x;
130 child_allocation.y += allocation->y;
131 }
132
133 child_allocation.width = child_requisition.width;
134 child_allocation.height = child_requisition.height;
135
136 struct xwidget_view *xv
137 = g_object_get_data (G_OBJECT (child->widget), XG_XWIDGET_VIEW);
138 if (xv)
139 {
140 child_allocation.width = xv->clip_right;
141 child_allocation.height = xv->clip_bottom - xv->clip_top;
142 }
143
144 gtk_widget_size_allocate (child->widget, &child_allocation);
145 }
146}
147
148#endif /* HAVE_XWIDGETS */
149
70static void 150static void
71emacs_fixed_class_init (EmacsFixedClass *klass) 151emacs_fixed_class_init (EmacsFixedClass *klass)
72{ 152{
@@ -74,15 +154,20 @@ emacs_fixed_class_init (EmacsFixedClass *klass)
74 154
75 widget_class = (GtkWidgetClass*) klass; 155 widget_class = (GtkWidgetClass*) klass;
76 156
157
77 widget_class->get_preferred_width = emacs_fixed_get_preferred_width; 158 widget_class->get_preferred_width = emacs_fixed_get_preferred_width;
78 widget_class->get_preferred_height = emacs_fixed_get_preferred_height; 159 widget_class->get_preferred_height = emacs_fixed_get_preferred_height;
160#ifdef HAVE_XWIDGETS
161 widget_class->size_allocate = emacs_fixed_gtk_widget_size_allocate;
162#endif
79 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate)); 163 g_type_class_add_private (klass, sizeof (EmacsFixedPrivate));
80} 164}
81 165
166
82static void 167static void
83emacs_fixed_init (EmacsFixed *fixed) 168emacs_fixed_init (EmacsFixed *fixed)
84{ 169{
85 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, EMACS_TYPE_FIXED, 170 fixed->priv = G_TYPE_INSTANCE_GET_PRIVATE (fixed, emacs_fixed_get_type (),
86 EmacsFixedPrivate); 171 EmacsFixedPrivate);
87 fixed->priv->f = 0; 172 fixed->priv->f = 0;
88} 173}
@@ -97,7 +182,7 @@ emacs_fixed_init (EmacsFixed *fixed)
97GtkWidget* 182GtkWidget*
98emacs_fixed_new (struct frame *f) 183emacs_fixed_new (struct frame *f)
99{ 184{
100 EmacsFixed *fixed = g_object_new (EMACS_TYPE_FIXED, NULL); 185 EmacsFixed *fixed = g_object_new (emacs_fixed_get_type (), NULL);
101 EmacsFixedPrivate *priv = fixed->priv; 186 EmacsFixedPrivate *priv = fixed->priv;
102 priv->f = f; 187 priv->f = f;
103 return GTK_WIDGET (fixed); 188 return GTK_WIDGET (fixed);
diff --git a/src/emacsgtkfixed.h b/src/emacsgtkfixed.h
index 73280b83e57..378bd2b828c 100644
--- a/src/emacsgtkfixed.h
+++ b/src/emacsgtkfixed.h
@@ -27,6 +27,26 @@ struct frame;
27 27
28G_BEGIN_DECLS 28G_BEGIN_DECLS
29 29
30struct frame;
31
32//typedef struct _EmacsFixed EmacsFixed;
33typedef struct _EmacsFixedPrivate EmacsFixedPrivate;
34typedef struct _EmacsFixedClass EmacsFixedClass;
35
36struct _EmacsFixed
37{
38 GtkFixed container;
39
40 /*< private >*/
41 EmacsFixedPrivate *priv;
42};
43
44
45struct _EmacsFixedClass
46{
47 GtkFixedClass parent_class;
48};
49
30extern GtkWidget *emacs_fixed_new (struct frame *f); 50extern GtkWidget *emacs_fixed_new (struct frame *f);
31 51
32G_END_DECLS 52G_END_DECLS
diff --git a/src/keyboard.c b/src/keyboard.c
index c8a9728e896..fe503b8ce56 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -4014,6 +4014,13 @@ kbd_buffer_get_event (KBOARD **kbp,
4014 kbd_fetch_ptr = event + 1; 4014 kbd_fetch_ptr = event + 1;
4015 } 4015 }
4016#endif 4016#endif
4017#ifdef HAVE_XWIDGETS
4018 else if (event->kind == XWIDGET_EVENT)
4019 {
4020 obj = make_lispy_event (&event->ie);
4021 kbd_fetch_ptr = event + 1;
4022 }
4023#endif
4017 else if (event->kind == CONFIG_CHANGED_EVENT) 4024 else if (event->kind == CONFIG_CHANGED_EVENT)
4018 { 4025 {
4019 obj = make_lispy_event (&event->ie); 4026 obj = make_lispy_event (&event->ie);
@@ -5950,6 +5957,13 @@ make_lispy_event (struct input_event *event)
5950 } 5957 }
5951#endif /* HAVE_DBUS */ 5958#endif /* HAVE_DBUS */
5952 5959
5960#ifdef HAVE_XWIDGETS
5961 case XWIDGET_EVENT:
5962 {
5963 return Fcons (Qxwidget_event,event->arg);
5964 }
5965#endif
5966
5953#if defined HAVE_INOTIFY || defined HAVE_KQUEUE || defined HAVE_GFILENOTIFY 5967#if defined HAVE_INOTIFY || defined HAVE_KQUEUE || defined HAVE_GFILENOTIFY
5954 case FILE_NOTIFY_EVENT: 5968 case FILE_NOTIFY_EVENT:
5955 { 5969 {
@@ -10956,6 +10970,10 @@ syms_of_keyboard (void)
10956 DEFSYM (Qdbus_event, "dbus-event"); 10970 DEFSYM (Qdbus_event, "dbus-event");
10957#endif 10971#endif
10958 10972
10973#ifdef HAVE_XWIDGETS
10974 DEFSYM (Qxwidget_event,"xwidget-event");
10975#endif
10976
10959#ifdef USE_FILE_NOTIFY 10977#ifdef USE_FILE_NOTIFY
10960 DEFSYM (Qfile_notify, "file-notify"); 10978 DEFSYM (Qfile_notify, "file-notify");
10961#endif /* USE_FILE_NOTIFY */ 10979#endif /* USE_FILE_NOTIFY */
diff --git a/src/lisp.h b/src/lisp.h
index 02b8078a9fd..8aa034e9e57 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -799,6 +799,12 @@ enum pvec_type
799 PVEC_WINDOW_CONFIGURATION, 799 PVEC_WINDOW_CONFIGURATION,
800 PVEC_SUBR, 800 PVEC_SUBR,
801 PVEC_OTHER, 801 PVEC_OTHER,
802
803#ifdef HAVE_XWIDGETS
804 PVEC_XWIDGET,
805 PVEC_XWIDGET_VIEW,
806#endif
807
802 /* These should be last, check internal_equal to see why. */ 808 /* These should be last, check internal_equal to see why. */
803 PVEC_COMPILED, 809 PVEC_COMPILED,
804 PVEC_CHAR_TABLE, 810 PVEC_CHAR_TABLE,
diff --git a/src/print.c b/src/print.c
index 269d8f250e2..4dd4e963093 100644
--- a/src/print.c
+++ b/src/print.c
@@ -33,6 +33,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
33#include "intervals.h" 33#include "intervals.h"
34#include "blockinput.h" 34#include "blockinput.h"
35 35
36#ifdef HAVE_XWIDGETS
37# include "xwidget.h"
38#endif
39
36#include <c-ctype.h> 40#include <c-ctype.h>
37#include <float.h> 41#include <float.h>
38#include <ftoastr.h> 42#include <ftoastr.h>
@@ -1736,6 +1740,18 @@ print_object (Lisp_Object obj, Lisp_Object printcharfun, bool escapeflag)
1736 print_c_string (XSUBR (obj)->symbol_name, printcharfun); 1740 print_c_string (XSUBR (obj)->symbol_name, printcharfun);
1737 printchar ('>', printcharfun); 1741 printchar ('>', printcharfun);
1738 } 1742 }
1743#ifdef HAVE_XWIDGETS
1744 else if (XWIDGETP (obj))
1745 {
1746 print_c_string ("#<xwidget ", printcharfun);
1747 printchar ('>', printcharfun);
1748 }
1749 else if (XWIDGET_VIEW_P (obj))
1750 {
1751 print_c_string ("#<xwidget ", printcharfun);
1752 printchar ('>', printcharfun);
1753 }
1754#endif
1739 else if (WINDOWP (obj)) 1755 else if (WINDOWP (obj))
1740 { 1756 {
1741 int len = sprintf (buf, "#<window %"pI"d", 1757 int len = sprintf (buf, "#<window %"pI"d",
diff --git a/src/termhooks.h b/src/termhooks.h
index 29223757621..c183528ee84 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -239,6 +239,11 @@ enum event_kind
239 , NS_NONKEY_EVENT 239 , NS_NONKEY_EVENT
240#endif 240#endif
241 241
242#ifdef HAVE_XWIDGETS
243 /* events generated by xwidgets*/
244 , XWIDGET_EVENT
245#endif
246
242#ifdef USE_FILE_NOTIFY 247#ifdef USE_FILE_NOTIFY
243 /* File or directory was changed. */ 248 /* File or directory was changed. */
244 , FILE_NOTIFY_EVENT 249 , FILE_NOTIFY_EVENT
diff --git a/src/window.c b/src/window.c
index 4aeb8b39a70..add2de38d18 100644
--- a/src/window.c
+++ b/src/window.c
@@ -41,6 +41,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
41#ifdef MSDOS 41#ifdef MSDOS
42#include "msdos.h" 42#include "msdos.h"
43#endif 43#endif
44#ifdef HAVE_XWIDGETS
45# include "xwidget.h"
46#endif
44 47
45static ptrdiff_t count_windows (struct window *); 48static ptrdiff_t count_windows (struct window *);
46static ptrdiff_t get_leaf_windows (struct window *, struct window **, 49static ptrdiff_t get_leaf_windows (struct window *, struct window **,
@@ -4368,6 +4371,9 @@ Signal an error when WINDOW is the only window on its frame. */)
4368 4371
4369 /* Block input. */ 4372 /* Block input. */
4370 block_input (); 4373 block_input ();
4374#ifdef HAVE_XWIDGETS
4375 xwidget_view_delete_all_in_window (w);
4376#endif
4371 window_resize_apply (p, horflag); 4377 window_resize_apply (p, horflag);
4372 /* If this window is referred to by the dpyinfo's mouse 4378 /* If this window is referred to by the dpyinfo's mouse
4373 highlight, invalidate that slot to be safe (Bug#9904). */ 4379 highlight, invalidate that slot to be safe (Bug#9904). */
diff --git a/src/xdisp.c b/src/xdisp.c
index d730a0bf1b6..89385c0e172 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -318,6 +318,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
318#include TERM_HEADER 318#include TERM_HEADER
319#endif /* HAVE_WINDOW_SYSTEM */ 319#endif /* HAVE_WINDOW_SYSTEM */
320 320
321#ifdef HAVE_XWIDGETS
322# include "xwidget.h"
323#endif
321#ifndef FRAME_X_OUTPUT 324#ifndef FRAME_X_OUTPUT
322#define FRAME_X_OUTPUT(f) ((f)->output_data.x) 325#define FRAME_X_OUTPUT(f) ((f)->output_data.x)
323#endif 326#endif
@@ -854,6 +857,9 @@ static bool next_element_from_buffer (struct it *);
854static bool next_element_from_composition (struct it *); 857static bool next_element_from_composition (struct it *);
855static bool next_element_from_image (struct it *); 858static bool next_element_from_image (struct it *);
856static bool next_element_from_stretch (struct it *); 859static bool next_element_from_stretch (struct it *);
860#ifdef HAVE_XWIDGETS
861static bool next_element_from_xwidget (struct it *);
862#endif
857static void load_overlay_strings (struct it *, ptrdiff_t); 863static void load_overlay_strings (struct it *, ptrdiff_t);
858static bool get_next_display_element (struct it *); 864static bool get_next_display_element (struct it *);
859static enum move_it_result 865static enum move_it_result
@@ -4690,6 +4696,9 @@ handle_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
4690 if (CONSP (spec) 4696 if (CONSP (spec)
4691 /* Simple specifications. */ 4697 /* Simple specifications. */
4692 && !EQ (XCAR (spec), Qimage) 4698 && !EQ (XCAR (spec), Qimage)
4699#ifdef HAVE_XWIDGETS
4700 && !EQ (XCAR (spec), Qxwidget)
4701#endif
4693 && !EQ (XCAR (spec), Qspace) 4702 && !EQ (XCAR (spec), Qspace)
4694 && !EQ (XCAR (spec), Qwhen) 4703 && !EQ (XCAR (spec), Qwhen)
4695 && !EQ (XCAR (spec), Qslice) 4704 && !EQ (XCAR (spec), Qslice)
@@ -5137,7 +5146,12 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
5137 || ((it ? FRAME_WINDOW_P (it->f) : frame_window_p) 5146 || ((it ? FRAME_WINDOW_P (it->f) : frame_window_p)
5138 && valid_image_p (value)) 5147 && valid_image_p (value))
5139#endif /* not HAVE_WINDOW_SYSTEM */ 5148#endif /* not HAVE_WINDOW_SYSTEM */
5140 || (CONSP (value) && EQ (XCAR (value), Qspace))); 5149 || (CONSP (value) && EQ (XCAR (value), Qspace))
5150#ifdef HAVE_XWIDGETS
5151 || ((it ? FRAME_WINDOW_P (it->f) : frame_window_p)
5152 && valid_xwidget_spec_p (value))
5153#endif
5154 );
5141 5155
5142 if (valid_p && display_replaced == 0) 5156 if (valid_p && display_replaced == 0)
5143 { 5157 {
@@ -5212,6 +5226,17 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
5212 *position = it->position = start_pos; 5226 *position = it->position = start_pos;
5213 retval = 1 + (it->area == TEXT_AREA); 5227 retval = 1 + (it->area == TEXT_AREA);
5214 } 5228 }
5229#ifdef HAVE_XWIDGETS
5230 else if (valid_xwidget_spec_p(value))
5231 {
5232 it->what = IT_XWIDGET;
5233 it->method = GET_FROM_XWIDGET;
5234 it->position = start_pos;
5235 it->object = NILP (object) ? it->w->contents : object;
5236 *position = start_pos;
5237 it->xwidget = lookup_xwidget(value);
5238 }
5239#endif
5215#ifdef HAVE_WINDOW_SYSTEM 5240#ifdef HAVE_WINDOW_SYSTEM
5216 else 5241 else
5217 { 5242 {
@@ -5964,6 +5989,11 @@ push_it (struct it *it, struct text_pos *position)
5964 case GET_FROM_STRETCH: 5989 case GET_FROM_STRETCH:
5965 p->u.stretch.object = it->object; 5990 p->u.stretch.object = it->object;
5966 break; 5991 break;
5992#ifdef HAVE_XWIDGETS
5993 case GET_FROM_XWIDGET:
5994 p->u.xwidget.object = it->object;
5995 break;
5996#endif
5967 case GET_FROM_BUFFER: 5997 case GET_FROM_BUFFER:
5968 case GET_FROM_DISPLAY_VECTOR: 5998 case GET_FROM_DISPLAY_VECTOR:
5969 case GET_FROM_STRING: 5999 case GET_FROM_STRING:
@@ -6065,6 +6095,11 @@ pop_it (struct it *it)
6065 it->object = p->u.image.object; 6095 it->object = p->u.image.object;
6066 it->slice = p->u.image.slice; 6096 it->slice = p->u.image.slice;
6067 break; 6097 break;
6098#ifdef HAVE_XWIDGETS
6099 case GET_FROM_XWIDGET:
6100 it->object = p->u.xwidget.object;
6101 break;
6102#endif
6068 case GET_FROM_STRETCH: 6103 case GET_FROM_STRETCH:
6069 it->object = p->u.stretch.object; 6104 it->object = p->u.stretch.object;
6070 break; 6105 break;
@@ -6739,7 +6774,10 @@ static next_element_function const get_next_element[NUM_IT_METHODS] =
6739 next_element_from_string, 6774 next_element_from_string,
6740 next_element_from_c_string, 6775 next_element_from_c_string,
6741 next_element_from_image, 6776 next_element_from_image,
6742 next_element_from_stretch 6777 next_element_from_stretch,
6778#ifdef HAVE_XWIDGETS
6779 next_element_from_xwidget,
6780#endif
6743}; 6781};
6744 6782
6745#define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it) 6783#define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
@@ -7600,6 +7638,10 @@ set_iterator_to_next (struct it *it, bool reseat_p)
7600 7638
7601 case GET_FROM_IMAGE: 7639 case GET_FROM_IMAGE:
7602 case GET_FROM_STRETCH: 7640 case GET_FROM_STRETCH:
7641#ifdef HAVE_XWIDGETS
7642 case GET_FROM_XWIDGET:
7643#endif
7644
7603 /* The position etc with which we have to proceed are on 7645 /* The position etc with which we have to proceed are on
7604 the stack. The position may be at the end of a string, 7646 the stack. The position may be at the end of a string,
7605 if the `display' property takes up the whole string. */ 7647 if the `display' property takes up the whole string. */
@@ -8061,6 +8103,15 @@ next_element_from_image (struct it *it)
8061 return true; 8103 return true;
8062} 8104}
8063 8105
8106#ifdef HAVE_XWIDGETS
8107static bool
8108next_element_from_xwidget (struct it *it)
8109{
8110 it->what = IT_XWIDGET;
8111 return true;
8112}
8113#endif
8114
8064 8115
8065/* Fill iterator IT with next display element from a stretch glyph 8116/* Fill iterator IT with next display element from a stretch glyph
8066 property. IT->object is the value of the text property. Value is 8117 property. IT->object is the value of the text property. Value is
@@ -18793,6 +18844,28 @@ dump_glyph (struct glyph_row *row, struct glyph *glyph, int area)
18793 glyph->left_box_line_p, 18844 glyph->left_box_line_p,
18794 glyph->right_box_line_p); 18845 glyph->right_box_line_p);
18795 } 18846 }
18847#ifdef HAVE_XWIDGETS
18848 else if (glyph->type == XWIDGET_GLYPH)
18849 {
18850 fprintf (stderr,
18851 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18852 glyph - row->glyphs[TEXT_AREA],
18853 'X',
18854 glyph->charpos,
18855 (BUFFERP (glyph->object)
18856 ? 'B'
18857 : (STRINGP (glyph->object)
18858 ? 'S'
18859 : '-')),
18860 glyph->pixel_width,
18861 glyph->u.xwidget,
18862 '.',
18863 glyph->face_id,
18864 glyph->left_box_line_p,
18865 glyph->right_box_line_p);
18866
18867 }
18868#endif
18796} 18869}
18797 18870
18798 18871
@@ -24291,6 +24364,13 @@ calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop,
24291 24364
24292 return OK_PIXELS (width_p ? img->width : img->height); 24365 return OK_PIXELS (width_p ? img->width : img->height);
24293 } 24366 }
24367# ifdef HAVE_XWIDGETS
24368 if (FRAME_WINDOW_P (it->f) && valid_xwidget_spec_p (prop))
24369 {
24370 // TODO: Don't return dummy size.
24371 return OK_PIXELS (100);
24372 }
24373# endif
24294#endif 24374#endif
24295 if (EQ (car, Qplus) || EQ (car, Qminus)) 24375 if (EQ (car, Qplus) || EQ (car, Qminus))
24296 { 24376 {
@@ -24796,6 +24876,18 @@ fill_image_glyph_string (struct glyph_string *s)
24796} 24876}
24797 24877
24798 24878
24879#ifdef HAVE_XWIDGETS
24880static void
24881fill_xwidget_glyph_string (struct glyph_string *s)
24882{
24883 eassert (s->first_glyph->type == XWIDGET_GLYPH);
24884 s->face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
24885 s->font = s->face->font;
24886 s->width = s->first_glyph->pixel_width;
24887 s->ybase += s->first_glyph->voffset;
24888 s->xwidget = s->first_glyph->u.xwidget;
24889}
24890#endif
24799/* Fill glyph string S from a sequence of stretch glyphs. 24891/* Fill glyph string S from a sequence of stretch glyphs.
24800 24892
24801 START is the index of the first glyph to consider, 24893 START is the index of the first glyph to consider,
@@ -25181,6 +25273,20 @@ compute_overhangs_and_x (struct glyph_string *s, int x, bool backward_p)
25181 } \ 25273 } \
25182 while (false) 25274 while (false)
25183 25275
25276#ifdef HAVE_XWIDGETS
25277#define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25278 do \
25279 { \
25280 s = alloca (sizeof *s); \
25281 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25282 fill_xwidget_glyph_string (s); \
25283 append_glyph_string (&(HEAD), &(TAIL), s); \
25284 ++(START); \
25285 s->x = (X); \
25286 } \
25287 while (false)
25288#endif
25289
25184 25290
25185/* Add a glyph string for a sequence of character glyphs to the list 25291/* Add a glyph string for a sequence of character glyphs to the list
25186 of strings between HEAD and TAIL. START is the index of the first 25292 of strings between HEAD and TAIL. START is the index of the first
@@ -25302,7 +25408,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, bool backward_p)
25302 to allocate glyph strings (because draw_glyphs can be called 25408 to allocate glyph strings (because draw_glyphs can be called
25303 asynchronously). */ 25409 asynchronously). */
25304 25410
25305#define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \ 25411#define BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25306 do \ 25412 do \
25307 { \ 25413 { \
25308 HEAD = TAIL = NULL; \ 25414 HEAD = TAIL = NULL; \
@@ -25333,8 +25439,17 @@ compute_overhangs_and_x (struct glyph_string *s, int x, bool backward_p)
25333 case IMAGE_GLYPH: \ 25439 case IMAGE_GLYPH: \
25334 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \ 25440 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
25335 HL, X, LAST_X); \ 25441 HL, X, LAST_X); \
25336 break; \ 25442 break;
25337 \ 25443
25444#ifdef HAVE_XWIDGETS
25445# define BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
25446 case XWIDGET_GLYPH: \
25447 BUILD_XWIDGET_GLYPH_STRING (START, END, HEAD, TAIL, \
25448 HL, X, LAST_X); \
25449 break;
25450#endif
25451
25452#define BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X) \
25338 case GLYPHLESS_GLYPH: \ 25453 case GLYPHLESS_GLYPH: \
25339 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \ 25454 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
25340 HL, X, LAST_X); \ 25455 HL, X, LAST_X); \
@@ -25353,6 +25468,18 @@ compute_overhangs_and_x (struct glyph_string *s, int x, bool backward_p)
25353 } while (false) 25468 } while (false)
25354 25469
25355 25470
25471#ifdef HAVE_XWIDGETS
25472# define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
25473 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25474 BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
25475 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
25476#else
25477# define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
25478 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25479 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
25480#endif
25481
25482
25356/* Draw glyphs between START and END in AREA of ROW on window W, 25483/* Draw glyphs between START and END in AREA of ROW on window W,
25357 starting at x-position X. X is relative to AREA in W. HL is a 25484 starting at x-position X. X is relative to AREA in W. HL is a
25358 face-override with the following meaning: 25485 face-override with the following meaning:
@@ -25991,6 +26118,109 @@ produce_image_glyph (struct it *it)
25991 } 26118 }
25992} 26119}
25993 26120
26121#ifdef HAVE_XWIDGETS
26122static void
26123produce_xwidget_glyph (struct it *it)
26124{
26125 struct xwidget *xw;
26126 int glyph_ascent, crop;
26127 eassert (it->what == IT_XWIDGET);
26128
26129 struct face *face = FACE_FROM_ID (it->f, it->face_id);
26130 eassert (face);
26131 /* Make sure X resources of the face is loaded. */
26132 prepare_face_for_display (it->f, face);
26133
26134 xw = it->xwidget;
26135 it->ascent = it->phys_ascent = glyph_ascent = xw->height/2;
26136 it->descent = xw->height/2;
26137 it->phys_descent = it->descent;
26138 it->pixel_width = xw->width;
26139 /* It's quite possible for images to have an ascent greater than
26140 their height, so don't get confused in that case. */
26141 if (it->descent < 0)
26142 it->descent = 0;
26143
26144 it->nglyphs = 1;
26145
26146 if (face->box != FACE_NO_BOX)
26147 {
26148 if (face->box_line_width > 0)
26149 {
26150 it->ascent += face->box_line_width;
26151 it->descent += face->box_line_width;
26152 }
26153
26154 if (it->start_of_box_run_p)
26155 it->pixel_width += eabs (face->box_line_width);
26156 it->pixel_width += eabs (face->box_line_width);
26157 }
26158
26159 take_vertical_position_into_account (it);
26160
26161 /* Automatically crop wide image glyphs at right edge so we can
26162 draw the cursor on same display row. */
26163 crop = it->pixel_width - (it->last_visible_x - it->current_x);
26164 if (crop > 0 && (it->hpos == 0 || it->pixel_width > it->last_visible_x / 4))
26165 it->pixel_width -= crop;
26166
26167 if (it->glyph_row)
26168 {
26169 enum glyph_row_area area = it->area;
26170 struct glyph *glyph
26171 = it->glyph_row->glyphs[area] + it->glyph_row->used[area];
26172
26173 if (it->glyph_row->reversed_p)
26174 {
26175 struct glyph *g;
26176
26177 /* Make room for the new glyph. */
26178 for (g = glyph - 1; g >= it->glyph_row->glyphs[it->area]; g--)
26179 g[1] = *g;
26180 glyph = it->glyph_row->glyphs[it->area];
26181 }
26182 if (glyph < it->glyph_row->glyphs[area + 1])
26183 {
26184 glyph->charpos = CHARPOS (it->position);
26185 glyph->object = it->object;
26186 glyph->pixel_width = it->pixel_width;
26187 glyph->ascent = glyph_ascent;
26188 glyph->descent = it->descent;
26189 glyph->voffset = it->voffset;
26190 glyph->type = XWIDGET_GLYPH;
26191 glyph->avoid_cursor_p = it->avoid_cursor_p;
26192 glyph->multibyte_p = it->multibyte_p;
26193 if (it->glyph_row->reversed_p && area == TEXT_AREA)
26194 {
26195 /* In R2L rows, the left and the right box edges need to be
26196 drawn in reverse direction. */
26197 glyph->right_box_line_p = it->start_of_box_run_p;
26198 glyph->left_box_line_p = it->end_of_box_run_p;
26199 }
26200 else
26201 {
26202 glyph->left_box_line_p = it->start_of_box_run_p;
26203 glyph->right_box_line_p = it->end_of_box_run_p;
26204 }
26205 glyph->overlaps_vertically_p = 0;
26206 glyph->padding_p = 0;
26207 glyph->glyph_not_available_p = 0;
26208 glyph->face_id = it->face_id;
26209 glyph->u.xwidget = it->xwidget;
26210 glyph->font_type = FONT_TYPE_UNKNOWN;
26211 if (it->bidi_p)
26212 {
26213 glyph->resolved_level = it->bidi_it.resolved_level;
26214 eassert ((it->bidi_it.type & 7) == it->bidi_it.type);
26215 glyph->bidi_type = it->bidi_it.type;
26216 }
26217 ++it->glyph_row->used[area];
26218 }
26219 else
26220 IT_EXPAND_MATRIX_WIDTH (it, area);
26221 }
26222}
26223#endif
25994 26224
25995/* Append a stretch glyph to IT->glyph_row. OBJECT is the source 26225/* Append a stretch glyph to IT->glyph_row. OBJECT is the source
25996 of the glyph, WIDTH and HEIGHT are the width and height of the 26226 of the glyph, WIDTH and HEIGHT are the width and height of the
@@ -27401,6 +27631,10 @@ x_produce_glyphs (struct it *it)
27401 produce_image_glyph (it); 27631 produce_image_glyph (it);
27402 else if (it->what == IT_STRETCH) 27632 else if (it->what == IT_STRETCH)
27403 produce_stretch_glyph (it); 27633 produce_stretch_glyph (it);
27634#ifdef HAVE_XWIDGETS
27635 else if (it->what == IT_XWIDGET)
27636 produce_xwidget_glyph (it);
27637#endif
27404 27638
27405 done: 27639 done:
27406 /* Accumulate dimensions. Note: can't assume that it->descent > 0 27640 /* Accumulate dimensions. Note: can't assume that it->descent > 0
@@ -27770,6 +28004,10 @@ get_window_cursor_type (struct window *w, struct glyph *glyph, int *width,
27770 /* Use normal cursor if not blinked off. */ 28004 /* Use normal cursor if not blinked off. */
27771 if (!w->cursor_off_p) 28005 if (!w->cursor_off_p)
27772 { 28006 {
28007#ifdef HAVE_XWIDGETS
28008 if (glyph != NULL && glyph->type == XWIDGET_GLYPH)
28009 return NO_CURSOR;
28010#endif
27773 if (glyph != NULL && glyph->type == IMAGE_GLYPH) 28011 if (glyph != NULL && glyph->type == IMAGE_GLYPH)
27774 { 28012 {
27775 if (cursor_type == FILLED_BOX_CURSOR) 28013 if (cursor_type == FILLED_BOX_CURSOR)
diff --git a/src/xterm.c b/src/xterm.c
index 5a6d643bad4..44eed22d2ec 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -62,6 +62,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
62#include "composite.h" 62#include "composite.h"
63#include "frame.h" 63#include "frame.h"
64#include "dispextern.h" 64#include "dispextern.h"
65#ifdef HAVE_XWIDGETS
66# include "xwidget.h"
67#endif
65#include "fontset.h" 68#include "fontset.h"
66#include "termhooks.h" 69#include "termhooks.h"
67#include "termopts.h" 70#include "termopts.h"
@@ -3511,6 +3514,12 @@ x_draw_glyph_string (struct glyph_string *s)
3511 x_draw_image_glyph_string (s); 3514 x_draw_image_glyph_string (s);
3512 break; 3515 break;
3513 3516
3517#ifdef HAVE_XWIDGETS
3518 case XWIDGET_GLYPH:
3519 x_draw_xwidget_glyph_string (s);
3520 break;
3521#endif
3522
3514 case STRETCH_GLYPH: 3523 case STRETCH_GLYPH:
3515 x_draw_stretch_glyph_string (s); 3524 x_draw_stretch_glyph_string (s);
3516 break; 3525 break;
@@ -8920,6 +8929,11 @@ x_draw_bar_cursor (struct window *w, struct glyph_row *row, int width, enum text
8920 if (cursor_glyph == NULL) 8929 if (cursor_glyph == NULL)
8921 return; 8930 return;
8922 8931
8932#ifdef HAVE_XWIDGETS
8933 if (cursor_glyph->type == XWIDGET_GLYPH)
8934 return; // Experimental avoidance of cursor on xwidget.
8935#endif
8936
8923 /* If on an image, draw like a normal cursor. That's usually better 8937 /* If on an image, draw like a normal cursor. That's usually better
8924 visible than drawing a bar, esp. if the image is large so that 8938 visible than drawing a bar, esp. if the image is large so that
8925 the bar might not be in the window. */ 8939 the bar might not be in the window. */
diff --git a/src/xwidget.c b/src/xwidget.c
new file mode 100644
index 00000000000..ea5dea0f9fe
--- /dev/null
+++ b/src/xwidget.c
@@ -0,0 +1,1320 @@
1/* Support for embedding graphical components in a buffer.
2
3Copyright (C) 2011-2016 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20#include <config.h>
21
22
23#include <signal.h>
24
25#include <stdio.h>
26#include <setjmp.h>
27#ifdef HAVE_X_WINDOWS
28
29#include "lisp.h"
30#include "blockinput.h"
31#include "syssignal.h"
32
33#include "xterm.h"
34#include <X11/cursorfont.h>
35
36#ifndef makedev
37# include <sys/types.h>
38#endif
39
40#ifdef BSD_SYSTEM
41# include <sys/ioctl.h>
42#endif
43
44#include "systime.h"
45
46#ifndef INCLUDED_FCNTL
47# include <fcntl.h>
48#endif
49#include <ctype.h>
50#include <errno.h>
51#include <setjmp.h>
52#include <sys/stat.h>
53
54#include "charset.h"
55#include "character.h"
56#include "coding.h"
57#include "ccl.h"
58#include "frame.h"
59#include "dispextern.h"
60#include "fontset.h"
61#include "termhooks.h"
62#include "termopts.h"
63#include "termchar.h"
64#include "disptab.h"
65#include "buffer.h"
66#include "window.h"
67#include "keyboard.h"
68#include "intervals.h"
69#include "process.h"
70#include "atimer.h"
71#include "keymap.h"
72
73
74#ifdef USE_X_TOOLKIT
75#include <X11/Shell.h>
76#endif
77#include <X11/extensions/Xcomposite.h>
78#include <X11/extensions/Xrender.h>
79#include <cairo.h>
80#ifdef HAVE_SYS_TIME_H
81#include <sys/time.h>
82#endif
83#ifdef HAVE_UNISTD_H
84#include <unistd.h>
85#endif
86
87#include "gtkutil.h"
88#include "font.h"
89#endif /* HAVE_X_WINDOWS */
90
91#include <gtk/gtk.h>
92#include <gdk/gdk.h>
93
94#include <gtk/gtkx.h>
95
96#include "emacsgtkfixed.h"
97
98#include <wchar.h>
99
100#include <webkit/webkitwebview.h>
101#include <webkit/webkitwebplugindatabase.h>
102#include <webkit/webkitwebplugin.h>
103#include <webkit/webkitglobals.h>
104#include <webkit/webkitwebnavigationaction.h>
105#include <webkit/webkitdownload.h>
106#include <webkit/webkitwebpolicydecision.h>
107
108#include "xwidget.h"
109
110static struct xwidget *
111allocate_xwidget (void)
112{
113 return ALLOCATE_PSEUDOVECTOR (struct xwidget, height, PVEC_XWIDGET);
114}
115
116static struct xwidget_view *
117allocate_xwidget_view (void)
118{
119 return ALLOCATE_PSEUDOVECTOR (struct xwidget_view, redisplayed,
120 PVEC_XWIDGET_VIEW);
121}
122
123#define XSETXWIDGET(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_XWIDGET))
124#define XSETXWIDGET_VIEW(a, b) (XSETPSEUDOVECTOR (a, b, PVEC_XWIDGET_VIEW))
125
126static struct xwidget_view *xwidget_view_lookup (struct xwidget *,
127 struct window *);
128static void webkit_document_load_finished_cb (WebKitWebView *, WebKitWebFrame *,
129 gpointer);
130static gboolean webkit_download_cb (WebKitWebView *, WebKitDownload *, gpointer);
131
132static gboolean
133webkit_mime_type_policy_typedecision_requested_cb (WebKitWebView *,
134 WebKitWebFrame *,
135 WebKitNetworkRequest *,
136 gchar *,
137 WebKitWebPolicyDecision *,
138 gpointer);
139
140static gboolean
141webkit_new_window_policy_decision_requested_cb (WebKitWebView *,
142 WebKitWebFrame *,
143 WebKitNetworkRequest *,
144 WebKitWebNavigationAction *,
145 WebKitWebPolicyDecision *,
146 gpointer);
147
148static gboolean
149webkit_navigation_policy_decision_requested_cb (WebKitWebView *,
150 WebKitWebFrame *,
151 WebKitNetworkRequest *,
152 WebKitWebNavigationAction *,
153 WebKitWebPolicyDecision *,
154 gpointer);
155
156
157
158DEFUN ("make-xwidget",
159 Fmake_xwidget, Smake_xwidget,
160 7, 8, 0,
161 doc: /* Make an xwidget from BEG to END of TYPE.
162If BUFFER is nil, use the current buffer.
163If BUFFER is a string and no such buffer exists, create it.
164TYPE is a symbol which can take one of the following values:
165
166- webkit_osr
167
168Returns the newly constructed xwidget, or nil if construction fails. */)
169 (Lisp_Object beg, Lisp_Object end,
170 Lisp_Object type,
171 Lisp_Object title,
172 Lisp_Object width, Lisp_Object height,
173 Lisp_Object arguments, Lisp_Object buffer)
174{
175 //should work a bit like "make-button"(make-button BEG END &rest PROPERTIES)
176 // arg "type" and fwd should be keyword args eventually
177 //(make-xwidget 3 3 'button "oei" 31 31 nil)
178 //(xwidget-info (car xwidget-list))
179 struct xwidget *xw = allocate_xwidget ();
180 Lisp_Object val;
181 xw->type = type;
182 xw->title = title;
183 if (NILP (buffer))
184 buffer = Fcurrent_buffer (); // no need to gcpro because
185 // Fcurrent_buffer doesn't
186 // call Feval/eval_sub.
187 else
188 buffer = Fget_buffer_create (buffer);
189 xw->buffer = buffer;
190
191 xw->height = XFASTINT (height);
192 xw->width = XFASTINT (width);
193 xw->kill_without_query = 0;
194 XSETXWIDGET (val, xw); // set the vectorlike_header of VAL
195 // with the correct value
196 Vxwidget_list = Fcons (val, Vxwidget_list);
197 xw->widgetwindow_osr = NULL;
198 xw->widget_osr = NULL;
199 xw->plist = Qnil;
200
201
202 if (EQ (xw->type, Qwebkit_osr))
203 {
204 block_input ();
205 xw->widgetwindow_osr = gtk_offscreen_window_new ();
206 gtk_window_resize (GTK_WINDOW (xw->widgetwindow_osr), xw->width,
207 xw->height);
208 xw->widgetscrolledwindow_osr = NULL; //webkit osr is the
209 //only scrolled
210 //component atm
211
212 if (EQ (xw->type, Qwebkit_osr))
213 {
214 xw->widgetscrolledwindow_osr = gtk_scrolled_window_new (NULL, NULL);
215 gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW
216 (xw->
217 widgetscrolledwindow_osr),
218 xw->height);
219 gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW
220 (xw->
221 widgetscrolledwindow_osr),
222 xw->width);
223 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
224 (xw->widgetscrolledwindow_osr),
225 GTK_POLICY_ALWAYS,
226 GTK_POLICY_ALWAYS);
227
228 xw->widget_osr = webkit_web_view_new ();
229 gtk_container_add (GTK_CONTAINER (xw->widgetscrolledwindow_osr),
230 GTK_WIDGET (WEBKIT_WEB_VIEW (xw->widget_osr)));
231 }
232
233 gtk_widget_set_size_request (GTK_WIDGET (xw->widget_osr), xw->width,
234 xw->height);
235
236 if (EQ (xw->type, Qwebkit_osr))
237 {
238 gtk_container_add (GTK_CONTAINER (xw->widgetwindow_osr),
239 xw->widgetscrolledwindow_osr);
240 }
241 else
242 {
243 gtk_container_add (GTK_CONTAINER (xw->widgetwindow_osr),
244 xw->widget_osr);
245 }
246
247 gtk_widget_show (xw->widget_osr);
248 gtk_widget_show (xw->widgetwindow_osr);
249 gtk_widget_show (xw->widgetscrolledwindow_osr);
250
251 /* store some xwidget data in the gtk widgets for convenient
252 retrieval in the event handlers. */
253 g_object_set_data (G_OBJECT (xw->widget_osr), XG_XWIDGET,
254 (gpointer) (xw));
255 g_object_set_data (G_OBJECT (xw->widgetwindow_osr), XG_XWIDGET,
256 (gpointer) (xw));
257
258 /* signals */
259 if (EQ (xw->type, Qwebkit_osr))
260 {
261 g_signal_connect (G_OBJECT (xw->widget_osr),
262 "document-load-finished",
263 G_CALLBACK (webkit_document_load_finished_cb), xw);
264
265 g_signal_connect (G_OBJECT (xw->widget_osr),
266 "download-requested",
267 G_CALLBACK (webkit_download_cb), xw);
268
269 g_signal_connect (G_OBJECT (xw->widget_osr),
270 "mime-type-policy-decision-requested",
271 G_CALLBACK
272 (webkit_mime_type_policy_typedecision_requested_cb),
273 xw);
274
275 g_signal_connect (G_OBJECT (xw->widget_osr),
276 "new-window-policy-decision-requested",
277 G_CALLBACK
278 (webkit_new_window_policy_decision_requested_cb),
279 xw);
280
281 g_signal_connect (G_OBJECT (xw->widget_osr),
282 "navigation-policy-decision-requested",
283 G_CALLBACK
284 (webkit_navigation_policy_decision_requested_cb),
285 xw);
286 }
287
288 unblock_input ();
289
290 }
291
292 return val;
293}
294
295DEFUN ("get-buffer-xwidgets", Fget_buffer_xwidgets, Sget_buffer_xwidgets,
296 1, 1, 0,
297 doc: /* Return a list of xwidgets associated with BUFFER.
298BUFFER may be a buffer or the name of one. */)
299 (Lisp_Object buffer)
300{
301 Lisp_Object xw, tail, xw_list;
302
303 if (NILP (buffer))
304 return Qnil;
305 buffer = Fget_buffer (buffer);
306 if (NILP (buffer))
307 return Qnil;
308
309 xw_list = Qnil;
310
311 for (tail = Vxwidget_list; CONSP (tail); tail = XCDR (tail))
312 {
313 xw = XCAR (tail);
314 if (XWIDGETP (xw) && EQ (Fxwidget_buffer (xw), buffer))
315 xw_list = Fcons (xw, xw_list);
316 }
317 return xw_list;
318}
319
320static int
321xwidget_hidden (struct xwidget_view *xv)
322{
323 return xv->hidden;
324}
325
326
327
328static void
329xwidget_show_view (struct xwidget_view *xv)
330{
331 xv->hidden = 0;
332 gtk_widget_show (xv->widgetwindow);
333 gtk_fixed_move (GTK_FIXED (xv->emacswindow),
334 xv->widgetwindow,
335 xv->x + xv->clip_left,
336 xv->y + xv->clip_top);
337}
338
339
340/* Hide an xvidget view. */
341static void
342xwidget_hide_view (struct xwidget_view *xv)
343{
344 xv->hidden = 1;
345 gtk_fixed_move (GTK_FIXED (xv->emacswindow), xv->widgetwindow,
346 10000, 10000);
347}
348
349
350
351/* When the off-screen webkit master view changes this signal is called.
352 It copies the bitmap from the off-screen instance. */
353static gboolean
354offscreen_damage_event (GtkWidget * widget, GdkEvent * event,
355 gpointer xv_widget)
356{
357 // Queue a redraw of onscreen widget.
358 // There is a guard against receiving an invalid widget,
359 // which should only happen if we failed to remove the
360 // specific signal handler for the damage event.
361 if (GTK_IS_WIDGET (xv_widget))
362 gtk_widget_queue_draw (GTK_WIDGET (xv_widget));
363 else
364 printf ("Warning, offscreen_damage_event received invalid xv pointer:%p\n",
365 (void *) xv_widget);
366
367 return FALSE;
368}
369
370static void
371store_xwidget_event_string (struct xwidget *xw, const char *eventname,
372 const char *eventstr)
373{
374 struct input_event event;
375 Lisp_Object xwl;
376 XSETXWIDGET (xwl, xw);
377 EVENT_INIT (event);
378 event.kind = XWIDGET_EVENT;
379 event.frame_or_window = Qnil;
380
381 event.arg = Qnil;
382 event.arg = Fcons (build_string (eventstr), event.arg);
383 event.arg = Fcons (xwl, event.arg);
384 event.arg = Fcons (intern (eventname), event.arg);
385 kbd_buffer_store_event (&event);
386
387}
388
389//TODO deprecated, use load-status
390void
391webkit_document_load_finished_cb (WebKitWebView * webkitwebview,
392 WebKitWebFrame * arg1,
393 gpointer data)
394{
395 struct xwidget *xw =
396 (struct xwidget *) g_object_get_data (G_OBJECT (webkitwebview),
397 XG_XWIDGET);
398
399 store_xwidget_event_string (xw, "document-load-finished", "");
400}
401
402gboolean
403webkit_download_cb (WebKitWebView * webkitwebview,
404 WebKitDownload * arg1,
405 gpointer data)
406{
407 struct xwidget *xw =
408 (struct xwidget *) g_object_get_data (G_OBJECT (webkitwebview),
409 XG_XWIDGET);
410 store_xwidget_event_string (xw, "download-requested",
411 webkit_download_get_uri (arg1));
412
413 return FALSE;
414}
415
416static gboolean
417webkit_mime_type_policy_typedecision_requested_cb (WebKitWebView *webView,
418 WebKitWebFrame *frame,
419 WebKitNetworkRequest * request,
420 gchar * mimetype,
421 WebKitWebPolicyDecision *policy_decision,
422 gpointer user_data)
423{
424 // This function makes webkit send a download signal for all unknown
425 // mime types. TODO Defer the decision to lisp, so that its possible
426 // to make Emacs handle teext mime for instance.xs
427 if (!webkit_web_view_can_show_mime_type (webView, mimetype))
428 {
429 webkit_web_policy_decision_download (policy_decision);
430 return TRUE;
431 }
432 else
433 {
434 return FALSE;
435 }
436}
437
438
439static gboolean
440webkit_new_window_policy_decision_requested_cb (WebKitWebView *webView,
441 WebKitWebFrame *frame,
442 WebKitNetworkRequest *request,
443 WebKitWebNavigationAction *navigation_action,
444 WebKitWebPolicyDecision *policy_decision,
445 gpointer user_data)
446{
447 struct xwidget *xw =
448 (struct xwidget *) g_object_get_data (G_OBJECT (webView), XG_XWIDGET);
449 webkit_web_navigation_action_get_original_uri (navigation_action);
450
451 store_xwidget_event_string (xw, "new-window-policy-decision-requested",
452 webkit_web_navigation_action_get_original_uri
453 (navigation_action));
454 return FALSE;
455}
456
457static gboolean
458webkit_navigation_policy_decision_requested_cb (WebKitWebView *webView,
459 WebKitWebFrame *frame,
460 WebKitNetworkRequest *request,
461 WebKitWebNavigationAction *navigation_action,
462 WebKitWebPolicyDecision * policy_decision,
463 gpointer user_data)
464{
465 struct xwidget *xw =
466 (struct xwidget *) g_object_get_data (G_OBJECT (webView), XG_XWIDGET);
467 store_xwidget_event_string (xw, "navigation-policy-decision-requested",
468 webkit_web_navigation_action_get_original_uri
469 (navigation_action));
470 return FALSE;
471}
472
473// For gtk3 offscreen rendered widgets.
474static gboolean
475xwidget_osr_draw_cb (GtkWidget * widget, cairo_t * cr, gpointer data)
476{
477 struct xwidget *xw =
478 (struct xwidget *) g_object_get_data (G_OBJECT (widget), XG_XWIDGET);
479 struct xwidget_view *xv =
480 (struct xwidget_view *) g_object_get_data (G_OBJECT (widget),
481 XG_XWIDGET_VIEW);
482
483 cairo_rectangle (cr, 0, 0, xv->clip_right, xv->clip_bottom);
484 cairo_clip (cr);
485
486 if (xw->widgetscrolledwindow_osr != NULL)
487 gtk_widget_draw (xw->widgetscrolledwindow_osr, cr);
488 else
489 gtk_widget_draw (xw->widget_osr, cr);
490 return FALSE;
491}
492
493static gboolean
494xwidget_osr_event_forward (GtkWidget * widget,
495 GdkEvent * event,
496 gpointer user_data)
497{
498 /* Copy events that arrive at the outer widget to the offscreen widget. */
499 struct xwidget *xw =
500 (struct xwidget *) g_object_get_data (G_OBJECT (widget), XG_XWIDGET);
501 GdkEvent *eventcopy = gdk_event_copy (event);
502 eventcopy->any.window = gtk_widget_get_window (xw->widget_osr);
503
504 //TODO This might leak events. They should be deallocated later,
505 //perhaps in xwgir_event_cb
506 gtk_main_do_event (eventcopy);
507 return TRUE; //dont propagate this event furter
508}
509
510
511static gboolean
512xwidget_osr_event_set_embedder (GtkWidget * widget,
513 GdkEvent * event, gpointer data)
514{
515 struct xwidget_view *xv = (struct xwidget_view *) data;
516 struct xwidget *xww = XXWIDGET (xv->model);
517 gdk_offscreen_window_set_embedder (gtk_widget_get_window
518 (xww->widgetwindow_osr),
519 gtk_widget_get_window (xv->widget));
520 return FALSE;
521}
522
523
524/* Initializes and does initial placement of an xwidget view on screen. */
525static struct xwidget_view *
526xwidget_init_view (struct xwidget *xww,
527 struct glyph_string *s,
528 int x, int y)
529{
530 struct xwidget_view *xv = allocate_xwidget_view ();
531 Lisp_Object val;
532
533 XSETXWIDGET_VIEW (val, xv);
534 Vxwidget_view_list = Fcons (val, Vxwidget_view_list);
535
536 XSETWINDOW (xv->w, s->w);
537 XSETXWIDGET (xv->model, xww);
538
539 if (EQ (xww->type, Qwebkit_osr))
540 {
541 xv->widget = gtk_drawing_area_new ();
542 // Expose event handling.
543 gtk_widget_set_app_paintable (xv->widget, TRUE);
544 gtk_widget_add_events (xv->widget, GDK_ALL_EVENTS_MASK);
545
546 /* Draw the view on damage-event */
547 g_signal_connect (G_OBJECT (xww->widgetwindow_osr), "damage-event",
548 G_CALLBACK (offscreen_damage_event), xv->widget);
549
550 if (EQ (xww->type, Qwebkit_osr))
551 {
552 g_signal_connect (G_OBJECT (xv->widget), "button-press-event",
553 G_CALLBACK (xwidget_osr_event_forward), NULL);
554 g_signal_connect (G_OBJECT (xv->widget), "button-release-event",
555 G_CALLBACK (xwidget_osr_event_forward), NULL);
556 g_signal_connect (G_OBJECT (xv->widget), "motion-notify-event",
557 G_CALLBACK (xwidget_osr_event_forward), NULL);
558 }
559 else
560 {
561 // xwgir debug , orthogonal to forwarding
562 g_signal_connect (G_OBJECT (xv->widget), "enter-notify-event",
563 G_CALLBACK (xwidget_osr_event_set_embedder), xv);
564 }
565 g_signal_connect (G_OBJECT (xv->widget), "draw",
566 G_CALLBACK (xwidget_osr_draw_cb), NULL);
567 }
568 // Widget realization.
569
570 // Make container widget 1st, and put the actual widget inside the
571 // container later. Drawing should crop container window if necessary
572 // to handle case where xwidget is partially obscured by other Emacs
573 // windows. Other containers than gtk_fixed where explored, but
574 // gtk_fixed had the most predictable behaviour so far.
575 xv->emacswindow = FRAME_GTK_WIDGET (s->f);
576 xv->widgetwindow = gtk_fixed_new ();
577 gtk_widget_set_has_window (xv->widgetwindow, TRUE);
578 gtk_container_add (GTK_CONTAINER (xv->widgetwindow), xv->widget);
579
580 // Store some xwidget data in the gtk widgets.
581 // The emacs frame.
582 g_object_set_data (G_OBJECT (xv->widget), XG_FRAME_DATA, (gpointer) (s->f));
583 // The xwidget.
584 g_object_set_data (G_OBJECT (xv->widget), XG_XWIDGET, (gpointer) (xww));
585 // The xwidget.
586 g_object_set_data (G_OBJECT (xv->widget), XG_XWIDGET_VIEW, (gpointer) (xv));
587 // The xwidget window.
588 g_object_set_data (G_OBJECT (xv->widgetwindow), XG_XWIDGET, (gpointer) (xww));
589 // the xwidget view.
590 g_object_set_data (G_OBJECT (xv->widgetwindow), XG_XWIDGET_VIEW,
591 (gpointer) (xv));
592
593
594 gtk_widget_set_size_request (GTK_WIDGET (xv->widget), xww->width,
595 xww->height);
596 gtk_widget_set_size_request (xv->widgetwindow, xww->width, xww->height);
597 gtk_fixed_put (GTK_FIXED (FRAME_GTK_WIDGET (s->f)), xv->widgetwindow, x, y);
598 xv->x = x;
599 xv->y = y;
600 gtk_widget_show_all (xv->widgetwindow);
601
602
603 return xv;
604}
605
606
607void
608x_draw_xwidget_glyph_string (struct glyph_string *s)
609{
610 /* This method is called by the redisplay engine and places the
611 xwidget on screen. Moving and clipping is done here. Also view
612 initialization.
613 */
614 struct xwidget *xww = s->xwidget;
615 struct xwidget_view *xv = xwidget_view_lookup (xww, s->w);
616 int clip_right;
617 int clip_bottom;
618 int clip_top;
619 int clip_left;
620
621 int x = s->x;
622 int y = s->y + (s->height / 2) - (xww->height / 2);
623 int moved = 0;
624
625 /* We do initialization here in the display loop because there is no
626 other time to know things like window placement etc.
627 */
628 xv = xwidget_init_view (xww, s, x, y);
629
630 // Calculate clipping, which is used for all manner of onscreen
631 // xwidget views. Each widget border can get clipped by other emacs
632 // objects so there are four clipping variables.
633 clip_right =
634 min (xww->width,
635 WINDOW_RIGHT_EDGE_X (s->w) - x -
636 WINDOW_RIGHT_SCROLL_BAR_AREA_WIDTH (s->w) -
637 WINDOW_RIGHT_FRINGE_WIDTH (s->w));
638 clip_left =
639 max (0,
640 WINDOW_LEFT_EDGE_X (s->w) - x +
641 WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (s->w) +
642 WINDOW_LEFT_FRINGE_WIDTH (s->w));
643
644 clip_bottom =
645 min (xww->height,
646 WINDOW_BOTTOM_EDGE_Y (s->w) - WINDOW_MODE_LINE_HEIGHT (s->w) - y);
647 clip_top = max (0, WINDOW_TOP_EDGE_Y (s->w) - y);
648
649 // We are conserned with movement of the onscreen area. The area
650 // might sit still when the widget actually moves. This happens
651 // when an Emacs window border moves across a widget window. So, if
652 // any corner of the outer widget clipping window moves, that counts
653 // as movement here, even if it looks like no movement happens
654 // because the widget sits still inside the clipping area. The
655 // widget can also move inside the clipping area, which happens
656 // later
657 moved = (xv->x + xv->clip_left != x + clip_left)
658 || ((xv->y + xv->clip_top) != (y + clip_top));
659 xv->x = x;
660 xv->y = y;
661 if (moved) // Has it moved?
662 {
663 gtk_fixed_move (GTK_FIXED (FRAME_GTK_WIDGET (s->f)),
664 xv->widgetwindow, x + clip_left, y + clip_top);
665 }
666 // Clip the widget window if some parts happen to be outside
667 // drawable area. An Emacs window is not a gtk window. A gtk window
668 // covers the entire frame. Clipping might have changed even if we
669 // havent actualy moved, we try figure out when we need to reclip
670 // for real.
671 if ((xv->clip_right != clip_right)
672 || (xv->clip_bottom != clip_bottom)
673 || (xv->clip_top != clip_top) || (xv->clip_left != clip_left))
674 {
675 gtk_widget_set_size_request (xv->widgetwindow, clip_right + clip_left,
676 clip_bottom + clip_top);
677 gtk_fixed_move (GTK_FIXED (xv->widgetwindow), xv->widget, -clip_left,
678 -clip_top);
679
680 xv->clip_right = clip_right;
681 xv->clip_bottom = clip_bottom;
682 xv->clip_top = clip_top;
683 xv->clip_left = clip_left;
684 }
685 // If emacs wants to repaint the area where the widget lives, queue
686 // a redraw. It seems its possible to get out of sync with emacs
687 // redraws so emacs background sometimes shows up instead of the
688 // xwidgets background. It's just a visual glitch though.
689 if (!xwidget_hidden (xv))
690 {
691 gtk_widget_queue_draw (xv->widgetwindow);
692 gtk_widget_queue_draw (xv->widget);
693 }
694}
695
696
697// Macro that checks WEBKIT_IS_WEB_VIEW(xw->widget_osr) first
698#define WEBKIT_FN_INIT() \
699 struct xwidget* xw; \
700 CHECK_XWIDGET (xwidget); \
701 if (NILP (xwidget)) {printf("ERROR xwidget nil\n"); return Qnil;}; \
702 xw = XXWIDGET (xwidget); \
703 if (NULL == xw) printf("ERROR xw is 0\n"); \
704 if ((NULL == xw->widget_osr) || !WEBKIT_IS_WEB_VIEW(xw->widget_osr)){ \
705 printf ("ERROR xw->widget_osr does not hold a webkit instance\n");\
706 return Qnil;\
707 };
708
709
710DEFUN ("xwidget-webkit-goto-uri",
711 Fxwidget_webkit_goto_uri, Sxwidget_webkit_goto_uri,
712 2, 2, 0,
713 doc: /* Make the xwidget webkit instance referenced by XWIDGET browse URI. */)
714 (Lisp_Object xwidget, Lisp_Object uri)
715{
716 WEBKIT_FN_INIT ();
717 CHECK_STRING (uri);
718 webkit_web_view_load_uri (WEBKIT_WEB_VIEW (xw->widget_osr), SSDATA (uri));
719 return Qnil;
720}
721
722
723DEFUN ("xwidget-webkit-execute-script",
724 Fxwidget_webkit_execute_script, Sxwidget_webkit_execute_script,
725 2, 2, 0,
726 doc: /* Make the Webkit XWIDGET execute javascript SCRIPT. */)
727 (Lisp_Object xwidget, Lisp_Object script)
728{
729 WEBKIT_FN_INIT ();
730 CHECK_STRING (script);
731 webkit_web_view_execute_script (WEBKIT_WEB_VIEW (xw->widget_osr),
732 SSDATA (script));
733 return Qnil;
734}
735
736DEFUN ("xwidget-webkit-get-title",
737 Fxwidget_webkit_get_title, Sxwidget_webkit_get_title,
738 1, 1, 0,
739 doc: /* Return the title from the Webkit instance in XWIDGET.
740This can be used to work around the lack of a return value from the
741exec method. */ )
742 (Lisp_Object xwidget)
743{
744 // TODO support multibyte strings
745 WEBKIT_FN_INIT ();
746 const gchar *str =
747 webkit_web_view_get_title (WEBKIT_WEB_VIEW (xw->widget_osr));
748 if (str == 0)
749 {
750 // TODO maybe return Qnil instead. I suppose webkit returns
751 // nullpointer when doc is not properly loaded or something
752 return build_string ("");
753 }
754 return build_string (str);
755}
756
757DEFUN ("xwidget-resize", Fxwidget_resize, Sxwidget_resize, 3, 3, 0,
758 doc: /* Resize XWIDGET. NEW_WIDTH, NEW_HEIGHT define the new size. */ )
759 (Lisp_Object xwidget, Lisp_Object new_width, Lisp_Object new_height)
760{
761 CHECK_XWIDGET (xwidget);
762 struct xwidget *xw = XXWIDGET (xwidget);
763 struct xwidget_view *xv;
764 int w, h;
765
766 CHECK_NUMBER (new_width);
767 CHECK_NUMBER (new_height);
768 w = XFASTINT (new_width);
769 h = XFASTINT (new_height);
770
771 xw->width = w;
772 xw->height = h;
773 // If there is a offscreen widget resize it 1st.
774 if (xw->widget_osr)
775 {
776 gtk_widget_set_size_request (GTK_WIDGET (xw->widget_osr),
777 xw->width, xw->height); //minimum size
778 gtk_window_resize (GTK_WINDOW (xw->widgetwindow_osr), xw->width,
779 xw->height);
780 gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW
781 (xw->
782 widgetscrolledwindow_osr),
783 xw->height);
784 gtk_scrolled_window_set_min_content_width (GTK_SCROLLED_WINDOW
785 (xw->
786 widgetscrolledwindow_osr),
787 xw->width);
788
789 gtk_container_resize_children (GTK_CONTAINER (xw->widgetwindow_osr));
790
791 }
792
793 for (Lisp_Object tail = Vxwidget_view_list; CONSP (tail); tail = XCDR (tail))
794 {
795 if (XWIDGET_VIEW_P (XCAR (tail)))
796 {
797 xv = XXWIDGET_VIEW (XCAR (tail));
798 if (XXWIDGET (xv->model) == xw)
799 gtk_widget_set_size_request (GTK_WIDGET (xv->widget), xw->width,
800 xw->height);
801 }
802 }
803
804 return Qnil;
805}
806
807
808
809DEFUN ("xwidget-set-adjustment",
810 Fxwidget_set_adjustment, Sxwidget_set_adjustment, 4, 4, 0,
811 doc: /* Set native scrolling for XWIDGET.
812AXIS can be 'vertical or 'horizontal.
813If RELATIVE is t, scroll relative, otherwise absolutely.
814VALUE is the amount to scroll, either relatively or absolutely. */)
815 (Lisp_Object xwidget, Lisp_Object axis, Lisp_Object relative,
816 Lisp_Object value)
817{
818 CHECK_XWIDGET (xwidget);
819 struct xwidget *xw = XXWIDGET (xwidget);
820 GtkAdjustment *adjustment;
821 float final_value = 0.0;
822
823 adjustment =
824 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW
825 (xw->widgetscrolledwindow_osr));
826 if (EQ (Qvertical, axis))
827 {
828 adjustment =
829 gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW
830 (xw->widgetscrolledwindow_osr));
831 }
832 if (EQ (Qhorizontal, axis))
833 {
834 adjustment =
835 gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW
836 (xw->widgetscrolledwindow_osr));
837 }
838
839 if (EQ (Qt, relative))
840 {
841 final_value = gtk_adjustment_get_value (adjustment) + XFASTINT (value);
842 }
843 else
844 {
845 final_value = 0.0 + XFASTINT (value);
846 }
847
848 gtk_adjustment_set_value (adjustment, final_value);
849
850 return Qnil;
851}
852
853
854DEFUN ("xwidget-size-request",
855 Fxwidget_size_request, Sxwidget_size_request,
856 1, 1, 0,
857 doc: /* Return the desired size of the XWIDGET.
858This can be used to read the xwidget desired size, and resizes the
859Emacs allocated area accordingly. */)
860 (Lisp_Object xwidget)
861{
862 CHECK_XWIDGET (xwidget);
863 GtkRequisition requisition;
864 Lisp_Object rv;
865 gtk_widget_size_request (XXWIDGET (xwidget)->widget_osr, &requisition);
866 rv = Qnil;
867 rv = Fcons (make_number (requisition.height), rv);
868 rv = Fcons (make_number (requisition.width), rv);
869 return rv;
870
871}
872
873DEFUN ("xwidgetp",
874 Fxwidgetp, Sxwidgetp,
875 1, 1, 0,
876 doc: /* Return t if OBJECT is an xwidget. */)
877 (Lisp_Object object)
878{
879 return XWIDGETP (object) ? Qt : Qnil;
880}
881
882DEFUN ("xwidget-view-p",
883 Fxwidget_view_p, Sxwidget_view_p,
884 1, 1, 0,
885 doc: /* Return t if OBJECT is an xwidget-view. */)
886 (Lisp_Object object)
887{
888 return XWIDGET_VIEW_P (object) ? Qt : Qnil;
889}
890
891DEFUN ("xwidget-info",
892 Fxwidget_info, Sxwidget_info,
893 1, 1, 0,
894 doc: /* Return XWIDGET properties in a vector.
895Currently [TYPE TITLE WIDTH HEIGHT]. */)
896 (Lisp_Object xwidget)
897{
898 CHECK_XWIDGET (xwidget);
899 Lisp_Object info, n;
900 struct xwidget *xw = XXWIDGET (xwidget);
901
902 info = Fmake_vector (make_number (4), Qnil);
903 ASET (info, 0, xw->type);
904 ASET (info, 1, xw->title);
905 XSETFASTINT (n, xw->width);
906 ASET (info, 2, n);
907 XSETFASTINT (n, xw->height);
908 ASET (info, 3, n);
909
910 return info;
911}
912
913DEFUN ("xwidget-view-info",
914 Fxwidget_view_info, Sxwidget_view_info,
915 1, 1, 0,
916 doc: /* Return properties of XWIDGET-VIEW in a vector.
917Currently [X Y CLIP_RIGHT CLIP_BOTTOM CLIP_TOP CLIP_LEFT]. */)
918 (Lisp_Object xwidget_view)
919{
920 CHECK_XWIDGET_VIEW (xwidget_view);
921 struct xwidget_view *xv = XXWIDGET_VIEW (xwidget_view);
922 Lisp_Object info;
923
924 info = Fmake_vector (make_number (6), Qnil);
925 ASET (info, 0, make_number (xv->x));
926 ASET (info, 1, make_number (xv->y));
927 ASET (info, 2, make_number (xv->clip_right));
928 ASET (info, 3, make_number (xv->clip_bottom));
929 ASET (info, 4, make_number (xv->clip_top));
930 ASET (info, 5, make_number (xv->clip_left));
931
932 return info;
933}
934
935DEFUN ("xwidget-view-model",
936 Fxwidget_view_model, Sxwidget_view_model,
937 1, 1, 0,
938 doc: /* Return the model associated with XWIDGET-VIEW. */)
939 (Lisp_Object xwidget_view)
940{
941 CHECK_XWIDGET_VIEW (xwidget_view);
942 return XXWIDGET_VIEW (xwidget_view)->model;
943}
944
945DEFUN ("xwidget-view-window",
946 Fxwidget_view_window, Sxwidget_view_window,
947 1, 1, 0,
948 doc: /* Return the window of XWIDGET-VIEW. */)
949 (Lisp_Object xwidget_view)
950{
951 CHECK_XWIDGET_VIEW (xwidget_view);
952 return XXWIDGET_VIEW (xwidget_view)->w;
953}
954
955
956DEFUN ("delete-xwidget-view",
957 Fdelete_xwidget_view, Sdelete_xwidget_view,
958 1, 1, 0,
959 doc: /* Delete the XWIDGET-VIEW. */)
960 (Lisp_Object xwidget_view)
961{
962 CHECK_XWIDGET_VIEW (xwidget_view);
963 struct xwidget_view *xv = XXWIDGET_VIEW (xwidget_view);
964 gtk_widget_destroy (xv->widgetwindow);
965 Vxwidget_view_list = Fdelq (xwidget_view, Vxwidget_view_list);
966 // xv->model still has signals pointing to the view. There can be
967 // several views. Find the matching signals and delete them all.
968 g_signal_handlers_disconnect_matched (XXWIDGET (xv->model)->widgetwindow_osr,
969 G_SIGNAL_MATCH_DATA,
970 0, 0, 0, 0,
971 xv->widget);
972 return Qnil;
973}
974
975DEFUN ("xwidget-view-lookup",
976 Fxwidget_view_lookup, Sxwidget_view_lookup,
977 1, 2, 0,
978 doc: /* Return the xwidget-view associated with XWIDGET in WINDOW.
979If WINDOW is unspecified or nil, use the selected window.
980Return nil if no association is found. */)
981 (Lisp_Object xwidget, Lisp_Object window)
982{
983 CHECK_XWIDGET (xwidget);
984
985 if (NILP (window))
986 window = Fselected_window ();
987 CHECK_WINDOW (window);
988
989 for (Lisp_Object tail = Vxwidget_view_list; CONSP (tail);
990 tail = XCDR (tail))
991 {
992 Lisp_Object xwidget_view = XCAR (tail);
993 if (EQ (Fxwidget_view_model (xwidget_view), xwidget)
994 && EQ (Fxwidget_view_window (xwidget_view), window))
995 return xwidget_view;
996 }
997
998 return Qnil;
999}
1000
1001DEFUN ("xwidget-plist",
1002 Fxwidget_plist, Sxwidget_plist,
1003 1, 1, 0,
1004 doc: /* Return the plist of XWIDGET. */)
1005 (register Lisp_Object xwidget)
1006{
1007 CHECK_XWIDGET (xwidget);
1008 return XXWIDGET (xwidget)->plist;
1009}
1010
1011DEFUN ("xwidget-buffer",
1012 Fxwidget_buffer, Sxwidget_buffer,
1013 1, 1, 0,
1014 doc: /* Return the buffer of XWIDGET. */)
1015 (register Lisp_Object xwidget)
1016{
1017 CHECK_XWIDGET (xwidget);
1018 return XXWIDGET (xwidget)->buffer;
1019}
1020
1021DEFUN ("set-xwidget-plist",
1022 Fset_xwidget_plist, Sset_xwidget_plist,
1023 2, 2, 0,
1024 doc: /* Replace the plist of XWIDGET with PLIST.
1025Returns PLIST. */)
1026 (register Lisp_Object xwidget, Lisp_Object plist)
1027{
1028 CHECK_XWIDGET (xwidget);
1029 CHECK_LIST (plist);
1030
1031 XXWIDGET (xwidget)->plist = plist;
1032 return plist;
1033}
1034
1035DEFUN ("set-xwidget-query-on-exit-flag",
1036 Fset_xwidget_query_on_exit_flag, Sset_xwidget_query_on_exit_flag,
1037 2, 2, 0,
1038 doc: /* Specify if query is needed for XWIDGET when Emacs is exited.
1039If the second argument FLAG is non-nil, Emacs will query the user before
1040exiting or killing a buffer if XWIDGET is running.
1041This function returns FLAG. */)
1042 (Lisp_Object xwidget, Lisp_Object flag)
1043{
1044 CHECK_XWIDGET (xwidget);
1045 XXWIDGET (xwidget)->kill_without_query = NILP (flag);
1046 return flag;
1047}
1048
1049DEFUN ("xwidget-query-on-exit-flag",
1050 Fxwidget_query_on_exit_flag, Sxwidget_query_on_exit_flag,
1051 1, 1, 0,
1052 doc: /* Return the current value of the query-on-exit flag for XWIDGET. */)
1053 (Lisp_Object xwidget)
1054{
1055 CHECK_XWIDGET (xwidget);
1056 return (XXWIDGET (xwidget)->kill_without_query ? Qnil : Qt);
1057}
1058
1059void
1060syms_of_xwidget (void)
1061{
1062
1063 defsubr (&Smake_xwidget);
1064 defsubr (&Sxwidgetp);
1065 DEFSYM (Qxwidgetp, "xwidgetp");
1066 defsubr (&Sxwidget_view_p);
1067 DEFSYM (Qxwidget_view_p, "xwidget-view-p");
1068 defsubr (&Sxwidget_info);
1069 defsubr (&Sxwidget_view_info);
1070 defsubr (&Sxwidget_resize);
1071 defsubr (&Sget_buffer_xwidgets);
1072 defsubr (&Sxwidget_view_model);
1073 defsubr (&Sxwidget_view_window);
1074 defsubr (&Sxwidget_view_lookup);
1075 defsubr (&Sxwidget_query_on_exit_flag);
1076 defsubr (&Sset_xwidget_query_on_exit_flag);
1077
1078 defsubr (&Sxwidget_webkit_goto_uri);
1079 defsubr (&Sxwidget_webkit_execute_script);
1080 defsubr (&Sxwidget_webkit_get_title);
1081 DEFSYM (Qwebkit_osr, "webkit-osr");
1082
1083 defsubr (&Sxwidget_size_request);
1084 defsubr (&Sdelete_xwidget_view);
1085
1086 defsubr (&Sxwidget_plist);
1087 defsubr (&Sxwidget_buffer);
1088 defsubr (&Sset_xwidget_plist);
1089
1090 defsubr (&Sxwidget_set_adjustment);
1091
1092 DEFSYM (Qxwidget, "xwidget");
1093
1094 DEFSYM (QCxwidget, ":xwidget");
1095 DEFSYM (QCtitle, ":title");
1096
1097 /* Do not forget to update the docstring of make-xwidget if you add
1098 new types. */
1099
1100 DEFSYM (Qvertical, "vertical");
1101 DEFSYM (Qhorizontal, "horizontal");
1102
1103 DEFSYM (QCplist, ":plist");
1104
1105 DEFVAR_LISP ("xwidget-list", Vxwidget_list,
1106 doc: /* xwidgets list. */);
1107 Vxwidget_list = Qnil;
1108
1109 DEFVAR_LISP ("xwidget-view-list", Vxwidget_view_list,
1110 doc: /* xwidget views list. */);
1111 Vxwidget_view_list = Qnil;
1112
1113 Fprovide (intern ("xwidget-internal"), Qnil);
1114
1115}
1116
1117
1118/* Value is non-zero if OBJECT is a valid Lisp xwidget specification. A
1119 valid xwidget specification is a list whose car is the symbol
1120 `xwidget', and whose rest is a property list. The property list must
1121 contain a value for key `:type'. That value must be the name of a
1122 supported xwidget type. The rest of the property list depends on the
1123 xwidget type. */
1124
1125bool
1126valid_xwidget_spec_p (Lisp_Object object)
1127{
1128 int valid_p = false;
1129
1130 if (CONSP (object) && EQ (XCAR (object), Qxwidget))
1131 valid_p = true;
1132
1133 return valid_p;
1134}
1135
1136
1137
1138/* Find a value associated with key in spec. */
1139static Lisp_Object
1140xwidget_spec_value (Lisp_Object spec, Lisp_Object key, int *found)
1141{
1142 Lisp_Object tail;
1143
1144 eassert (valid_xwidget_spec_p (spec));
1145
1146 for (tail = XCDR (spec);
1147 CONSP (tail) && CONSP (XCDR (tail)); tail = XCDR (XCDR (tail)))
1148 {
1149 if (EQ (XCAR (tail), key))
1150 {
1151 if (found)
1152 *found = 1;
1153 return XCAR (XCDR (tail));
1154 }
1155 }
1156
1157 if (found)
1158 *found = 0;
1159 return Qnil;
1160}
1161
1162
1163void
1164xwidget_view_delete_all_in_window (struct window *w)
1165{
1166 struct xwidget_view *xv = NULL;
1167 for (Lisp_Object tail = Vxwidget_view_list; CONSP (tail);
1168 tail = XCDR (tail))
1169 {
1170 if (XWIDGET_VIEW_P (XCAR (tail)))
1171 {
1172 xv = XXWIDGET_VIEW (XCAR (tail));
1173 if (XWINDOW (xv->w) == w)
1174 {
1175 Fdelete_xwidget_view (XCAR (tail));
1176 }
1177 }
1178 }
1179}
1180
1181static struct xwidget_view *
1182xwidget_view_lookup (struct xwidget *xw, struct window *w)
1183{
1184 Lisp_Object xwidget, window, ret;
1185 XSETXWIDGET (xwidget, xw);
1186 XSETWINDOW (window, w);
1187
1188 ret = Fxwidget_view_lookup (xwidget, window);
1189
1190 return EQ (ret, Qnil) ? NULL : XXWIDGET_VIEW (ret);
1191}
1192
1193struct xwidget *
1194lookup_xwidget (Lisp_Object spec)
1195{
1196 /* When a xwidget lisp spec is found initialize the C struct that is
1197 used in the C code. This is done by redisplay so values change
1198 if the spec changes. So, take special care of one-shot events.
1199 */
1200 int found = 0;
1201 Lisp_Object value;
1202 struct xwidget *xw;
1203
1204 value = xwidget_spec_value (spec, QCxwidget, &found);
1205 xw = XXWIDGET (value);
1206
1207 return xw;
1208}
1209
1210/* Set up detection of touched xwidget */
1211static void
1212xwidget_start_redisplay (void)
1213{
1214 for (Lisp_Object tail = Vxwidget_view_list; CONSP (tail);
1215 tail = XCDR (tail))
1216 {
1217 if (XWIDGET_VIEW_P (XCAR (tail)))
1218 XXWIDGET_VIEW (XCAR (tail))->redisplayed = 0;
1219 }
1220}
1221
1222/* The xwidget was touched during redisplay, so it isn't a candidate
1223 for hiding. */
1224static void
1225xwidget_touch (struct xwidget_view *xv)
1226{
1227 xv->redisplayed = 1;
1228}
1229
1230static int
1231xwidget_touched (struct xwidget_view *xv)
1232{
1233 return xv->redisplayed;
1234}
1235
1236/* Redisplay has ended, now we should hide untouched xwidgets
1237*/
1238void
1239xwidget_end_redisplay (struct window *w, struct glyph_matrix *matrix)
1240{
1241
1242 int i;
1243 int area;
1244
1245 xwidget_start_redisplay ();
1246 // Iterate desired glyph matrix of window here, hide gtk widgets
1247 // not in the desired matrix.
1248
1249 // This only takes care of xwidgets in active windows. If a window
1250 // goes away from screen xwidget views wust be deleted
1251
1252 // dump_glyph_matrix (matrix, 2);
1253 for (i = 0; i < matrix->nrows; ++i)
1254 {
1255 // dump_glyph_row (MATRIX_ROW (matrix, i), i, glyphs);
1256 struct glyph_row *row;
1257 row = MATRIX_ROW (matrix, i);
1258 if (row->enabled_p != 0)
1259 {
1260 for (area = LEFT_MARGIN_AREA; area < LAST_AREA; ++area)
1261 {
1262 struct glyph *glyph = row->glyphs[area];
1263 struct glyph *glyph_end = glyph + row->used[area];
1264 for (; glyph < glyph_end; ++glyph)
1265 {
1266 if (glyph->type == XWIDGET_GLYPH)
1267 {
1268 /*
1269 The only call to xwidget_end_redisplay is in dispnew
1270 xwidget_end_redisplay (w->current_matrix);
1271 */
1272 xwidget_touch (xwidget_view_lookup (glyph->u.xwidget,
1273 w));
1274 }
1275 }
1276 }
1277 }
1278 }
1279
1280 for (Lisp_Object tail = Vxwidget_view_list; CONSP (tail);
1281 tail = XCDR (tail))
1282 {
1283 if (XWIDGET_VIEW_P (XCAR (tail)))
1284 {
1285 struct xwidget_view *xv = XXWIDGET_VIEW (XCAR (tail));
1286
1287 // "touched" is only meaningful for the current window, so
1288 // disregard other views.
1289 if (XWINDOW (xv->w) == w)
1290 {
1291 if (xwidget_touched (xv))
1292 xwidget_show_view (xv);
1293 else
1294 xwidget_hide_view (xv);
1295 }
1296 }
1297 }
1298}
1299
1300/* Kill all xwidget in BUFFER. */
1301void
1302kill_buffer_xwidgets (Lisp_Object buffer)
1303{
1304 Lisp_Object tail, xwidget;
1305 for (tail = Fget_buffer_xwidgets (buffer); CONSP (tail); tail = XCDR (tail))
1306 {
1307 xwidget = XCAR (tail);
1308 Vxwidget_list = Fdelq (xwidget, Vxwidget_list);
1309 /* TODO free the GTK things in xw */
1310 {
1311 CHECK_XWIDGET (xwidget);
1312 struct xwidget *xw = XXWIDGET (xwidget);
1313 if (xw->widget_osr && xw->widgetwindow_osr)
1314 {
1315 gtk_widget_destroy (xw->widget_osr);
1316 gtk_widget_destroy (xw->widgetwindow_osr);
1317 }
1318 }
1319 }
1320}
diff --git a/src/xwidget.h b/src/xwidget.h
new file mode 100644
index 00000000000..fdcf40d8cbb
--- /dev/null
+++ b/src/xwidget.h
@@ -0,0 +1,132 @@
1/* Support for embedding graphical components in a buffer.
2
3Copyright (C) 2011-2016 Free Software Foundation, Inc.
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 3 of the License, or
10(at your option) any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20#ifndef XWIDGET_H_INCLUDED
21#define XWIDGET_H_INCLUDED
22
23void x_draw_xwidget_glyph_string (struct glyph_string *s);
24void syms_of_xwidget (void);
25
26//extern Lisp_Object Qxwidget;
27
28
29bool valid_xwidget_spec_p (Lisp_Object object);
30
31#include <gtk/gtk.h>
32
33
34/*
35each xwidget instance/model is described by this struct.
36
37lisp pseudovector.
38
39
40 */
41struct xwidget
42{
43 struct vectorlike_header header;
44 Lisp_Object plist; //auxilliary data
45 Lisp_Object type; //the widget type
46 Lisp_Object buffer; //buffer where xwidget lives
47 Lisp_Object title; //a title that is used for button labels for instance
48
49 //here ends the lisp part.
50 //"height" is the marker field
51 int height;
52 int width;
53
54 //for offscreen widgets, unused if not osr
55 GtkWidget *widget_osr;
56 GtkWidget *widgetwindow_osr;
57 //this is used if the widget (webkit) is to be wrapped in a scrolled window,
58 GtkWidget *widgetscrolledwindow_osr;
59 /* Non-nil means kill silently if Emacs is exited. */
60 unsigned int kill_without_query:1;
61
62};
63
64
65//struct for each xwidget view
66struct xwidget_view
67{
68 struct vectorlike_header header;
69 Lisp_Object model;
70 Lisp_Object w;
71
72 //here ends the lisp part.
73 //"redisplayed" is the marker field
74 int redisplayed; //if touched by redisplay
75
76 int hidden; //if the "live" instance isnt drawn
77
78 GtkWidget *widget;
79 GtkWidget *widgetwindow;
80 GtkWidget *emacswindow;
81 int x;
82 int y;
83 int clip_right;
84 int clip_bottom;
85 int clip_top;
86 int clip_left;
87
88
89 long handler_id;
90};
91
92/* Test for xwidget pseudovector*/
93#define XWIDGETP(x) PSEUDOVECTORP (x, PVEC_XWIDGET)
94#define XXWIDGET(a) (eassert (XWIDGETP(a)), \
95 (struct xwidget *) XUNTAG(a, Lisp_Vectorlike))
96
97#define CHECK_XWIDGET(x) \
98 CHECK_TYPE (XWIDGETP (x), Qxwidgetp, x)
99
100/* Test for xwidget_view pseudovector */
101#define XWIDGET_VIEW_P(x) PSEUDOVECTORP (x, PVEC_XWIDGET_VIEW)
102#define XXWIDGET_VIEW(a) (eassert (XWIDGET_VIEW_P(a)), \
103 (struct xwidget_view *) XUNTAG(a, Lisp_Vectorlike))
104
105#define CHECK_XWIDGET_VIEW(x) \
106 CHECK_TYPE (XWIDGET_VIEW_P (x), Qxwidget_view_p, x)
107
108struct xwidget_type
109{
110 /* A symbol uniquely identifying the xwidget type, */
111 Lisp_Object *type;
112
113 /* Check that SPEC is a valid image specification for the given
114 image type. Value is non-zero if SPEC is valid. */
115 int (*valid_p) (Lisp_Object spec);
116
117 /* Next in list of all supported image types. */
118 struct xwidget_type *next;
119};
120
121
122struct xwidget *xwidget_from_id (int id);
123
124void xwidget_end_redisplay (struct window *w, struct glyph_matrix *matrix);
125
126struct xwidget *lookup_xwidget (Lisp_Object spec);
127#define XG_XWIDGET "emacs_xwidget"
128#define XG_XWIDGET_VIEW "emacs_xwidget_view"
129void xwidget_view_delete_all_in_window (struct window *w);
130
131void kill_buffer_xwidgets (Lisp_Object buffer);
132#endif /* XWIDGET_H_INCLUDED */