aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoakim Verona2011-07-10 23:47:48 +0200
committerJoakim Verona2011-07-10 23:47:48 +0200
commite098c552ccd4be2c05898bb69df97ce35efa90b7 (patch)
tree11758196be04a6ec414100fd73419ffb582bde60 /src
parentd812bba65d7f22a624c8cc19e9ec21ffe3720228 (diff)
downloademacs-e098c552ccd4be2c05898bb69df97ce35efa90b7.tar.gz
emacs-e098c552ccd4be2c05898bb69df97ce35efa90b7.zip
minor cleanups and doc
Diffstat (limited to 'src')
-rw-r--r--src/xwidget-attic.c229
-rw-r--r--src/xwidget.c57
2 files changed, 266 insertions, 20 deletions
diff --git a/src/xwidget-attic.c b/src/xwidget-attic.c
new file mode 100644
index 00000000000..84844587051
--- /dev/null
+++ b/src/xwidget-attic.c
@@ -0,0 +1,229 @@
1static int once = 0;
2
3int
4xwidget_has_composition(void){ //unused
5int event_base, error_base;
6Display* dpy = GDK_DISPLAY ();
7int i;
8 if(xwidget_query_composition_called)
9 return hasNamePixmap;
10 xwidget_query_composition_called = 1;
11
12 //do this once in an emacs session
13
14 if(gdk_display_supports_composite(gdk_display_get_default ())){
15 hasNamePixmap = 1;
16 }else{
17 return 0;
18 }
19 return 1;
20}
21
22
23
24
25
26void
27xwidget_end_composition(struct xwidget* w){ //unused
28 //XCompositeUnredirectWindow(); stop redirecting, should be called when the socket is destroyed
29}
30
31
32static gboolean
33xwidget_composite_draw_phantom(struct xwidget* xw,
34 int x, int y,
35 int clipx, int clipy)
36{
37 FRAME_PTR f = (FRAME_PTR) g_object_get_data (G_OBJECT (xw->widget), XG_FRAME_DATA);
38 ////////////////////////////////////////////////////////////////
39 //Example 7. Composited windows
40 GdkRegion *region;
41 GtkWidget *child;
42 cairo_t *cr;
43 printf("xwidget_composite_draw_2 at:%d %d\n", x,y);
44 /* get our child (in this case, the event box) */
45 child = xw->widget; //gtk_bin_get_child (GTK_BIN (widget));
46 /* create a cairo context to draw to the emacs window */
47 // cr = gdk_cairo_create (gtk_widget_get_window (f->gwfixed));//GTK_WIDGET(xw->emacswindow));//xw->widgetwindow));//widget->window);
48 cr = gdk_cairo_create (gtk_widget_get_window (f->gwfixed));//GTK_WIDGET(xw->emacswindow));//));//widget->window);
49 /* the source data is the (composited) xwidget */
50 //cairo_move_to(cr, xw->x, xw->y);
51
52 cairo_rectangle(cr, x,y, clipx, clipy);
53 cairo_clip(cr);
54
55 cairo_set_source_rgb(cr,1.0,0,0);
56 cairo_rectangle(cr,x,y,xw->width,xw->height);
57 cairo_fill(cr);
58
59 gdk_cairo_set_source_pixmap (cr, child->window,
60 x,//child->allocation.x,
61 y//child->allocation.y
62 );
63 /* draw no more than our expose event intersects our child */
64 /* region = gdk_region_rectangle (&child->allocation);
65 gdk_region_intersect (region, event->region);
66 gdk_cairo_region (cr, region);
67 cairo_clip (cr); */
68 /* composite, with a 50% opacity */
69 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
70 //cairo_paint_with_alpha (cr, phantom ? 0.5 : 0);
71 cairo_paint_with_alpha (cr, 0.9);
72 //cairo_paint(cr);//transparency);
73 /* we're done */
74 cairo_destroy (cr);
75 return FALSE;
76}
77
78
79
80/*
81static gboolean
82xwidget_composite_draw(GtkWidget *widget,
83 GdkEventExpose *event,
84 gpointer data)
85{
86 struct xwidget* xw = (struct xwidget*) g_object_get_data (G_OBJECT (widget), XG_XWIDGET);
87 printf("xwidget_composite_draw %s\n", data);
88 xwidget_composite_draw_2(widget,
89 event,
90 data,
91 xw->x, xw->y, 0);
92 return FALSE;
93}
94*/
95
96
97static gboolean
98xwidget_composite_draw_widgetwindow(GtkWidget *widget,
99 GdkEventExpose *event,
100 gpointer data)
101{
102 struct xwidget* xw = (struct xwidget*) g_object_get_data (G_OBJECT (widget), XG_XWIDGET);
103 cairo_t *cr;
104 GdkPixmap *pixmap;
105 pixmap=xw->widget->window;
106 printf("xwidget_composite_draw_widgetwindow xw.id:%d xw.type:%d window:%d\n", xw->id,xw->type, gtk_widget_get_window (widget));
107 //if(xw->type!=3)//TODO this is just trial and terror to see if i can draw the live socket anywhere at all
108 cr = gdk_cairo_create (gtk_widget_get_window (widget));//GTK_LAYOUT (xw->widgetwindow)->bin_window);//
109 //else cr = gdk_cairo_create (gtk_widget_get_window (xw->emacswindow));
110 cairo_rectangle(cr, 0,0, xw->width, xw->height);
111 cairo_clip(cr);
112
113 cairo_set_source_rgb(cr,0,1.0,0);
114 cairo_rectangle(cr, 0,0, xw->width, xw->height);
115 cairo_fill(cr);
116 gdk_cairo_set_source_pixmap (cr, pixmap,
117 0,0);
118
119 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
120 cairo_paint_with_alpha (cr, 0.9);
121 //cairo_paint(cr);
122 cairo_destroy (cr);
123
124 return FALSE;
125}
126
127
128//type support nevermind for now
129
130/* /\* List of supported image types. Use define_image_type to add new */
131/* types. Use lookup_image_type to find a type for a given symbol. *\/ */
132
133/* static struct wxidget_type *wxidget_types; */
134
135/* /\* Look up xwidget type SYMBOL, and return a pointer to its xwidget_type */
136/* structure. Value is null if SYMBOL is not a known image type. *\/ */
137
138/* static INLINE struct xwidget_type *lookup_xwidget_type (Lisp_Object symbol) */
139/* { */
140/* struct xwidget_type *type; */
141
142/* for (type = xwidget_types; type; type = type->next) */
143/* if (EQ (symbol, *type->type)) */
144/* break; */
145
146/* return type; */
147/* } */
148
149
150////////////////////////////////////////////////////////////////
151
152/* delete the xwidget and its native widget peer(unused) */
153void xwidget_delete(struct xwidget* xw);
154
155
156void
157xwidget_delete (struct xwidget *xw)
158{
159 printf ("xwidget %d deleted\n", xw->id);
160 xw->initialized = 0;
161 gtk_widget_destroy (xw->widget);
162
163}
164
165
166/* redraw all xwidgets(unused) */
167void
168xwidget_invalidate (void)
169{
170 int i;
171 struct xwidget *xw;
172 printf ("invalidate ");
173 for (i = 0; i < MAX_XWIDGETS; i++)
174 {
175 xw = &xwidgets[i];
176 if (xw->initialized)
177 {
178 printf ("%d,", i);
179 gtk_widget_queue_draw_area (xw->widget, 0, 0, xw->width,
180 xw->height);
181 }
182 }
183 printf ("\n");
184}
185
186
187/* initializes the xwidget model */
188void
189xwidget_init_model (struct xwidget *xw,
190 struct glyph_string *s,
191 int x, int y)
192{
193 xw->id = s->xwidget_id;
194 xw->initialized = 1;
195}
196
197
198
199DEFUN ("xwidget-replug", Fxwidget_replug, Sxwidget_replug, 2, 2, 0,
200 doc: /* unplug from socket1 plug into socket2.*/
201 )
202 (Lisp_Object old_parent, Lisp_Object new_parent)
203{
204
205 struct xwidget *xw1;
206 struct xwidget *xw2;
207
208
209 GtkWidget* widget;
210 CHECK_NUMBER (old_parent);
211 CHECK_NUMBER (new_parent);
212
213 xw1 = &xwidgets[XFASTINT (old_parent)];
214 xw2 = &xwidgets[XFASTINT (new_parent)];
215
216
217 ///this wasnt thought through. we need the views rather than the model.
218 //so we need to map xw+w to xv
219
220 widget = xw1->widget->gtk_socket_get_plug_window ();
221
222 //the plug...
223 gtk_widget_ref(widget);//...gets an xtra ref to prevent garb, then it ...
224 gtk_container_remove(GTK_CONTAINER(xw1->widget), widget);//...is uplugged from old socket and...
225 gtk_container_add(GTK_CONTAINER(xw2->widget), widget);//...replugged in new socket...
226 gtk_widget_unref(widget);//...and lastly remove the ref
227
228 return Qnil;
229}
diff --git a/src/xwidget.c b/src/xwidget.c
index 57243832ce3..6c712d1d707 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -90,8 +90,11 @@
90#endif 90#endif
91 91
92 92
93#include <wchar.h>
94
93#ifdef HAVE_WEBKIT 95#ifdef HAVE_WEBKIT
94#include <webkitgtk.h> 96#include <webkitgtk.h>
97
95#endif 98#endif
96 99
97 100
@@ -412,15 +415,10 @@ xwidget_osr_button_callback ( GtkWidget *widget,
412 GdkEvent *event, 415 GdkEvent *event,
413 gpointer user_data) 416 gpointer user_data)
414{ 417{
415 gdouble x, y;
416 struct xwidget* xw = (struct xwidget*) g_object_get_data (G_OBJECT (widget), XG_XWIDGET); 418 struct xwidget* xw = (struct xwidget*) g_object_get_data (G_OBJECT (widget), XG_XWIDGET);
417 GdkEventButton* eventcopy = gdk_event_copy(event); 419 GdkEvent* eventcopy = gdk_event_copy(event);
418 x = ((GdkEventButton*)event)->x;
419 y = ((GdkEventButton*)event)->y;
420
421 printf ("button callback %d %d\n",x,y);
422 420
423 eventcopy->window = gtk_widget_get_window(xw->widget_osr); 421 ((GdkEventButton*)eventcopy)->window = gtk_widget_get_window(xw->widget_osr);
424 gtk_main_do_event(eventcopy); //TODO this will leak events. they should be deallocated later 422 gtk_main_do_event(eventcopy); //TODO this will leak events. they should be deallocated later
425} 423}
426 424
@@ -620,7 +618,7 @@ x_draw_xwidget_glyph_string (struct glyph_string *s)
620{ 618{
621 /* 619 /*
622 this method is called by the redisplay engine and places the xwidget on screen. 620 this method is called by the redisplay engine and places the xwidget on screen.
623 moving and clpping 621 moving and clipping is done here. also view init.
624 622
625 */ 623 */
626 int box_line_hwidth = eabs (s->face->box_line_width); 624 int box_line_hwidth = eabs (s->face->box_line_width);
@@ -676,7 +674,7 @@ x_draw_xwidget_glyph_string (struct glyph_string *s)
676 || (xv->clip_top != clip_top) 674 || (xv->clip_top != clip_top)
677 || (xv->clip_left != clip_left)){ 675 || (xv->clip_left != clip_left)){
678 gtk_widget_set_size_request (GTK_WIDGET (xv->widgetwindow), clip_right + clip_left, clip_bottom + clip_top); 676 gtk_widget_set_size_request (GTK_WIDGET (xv->widgetwindow), clip_right + clip_left, clip_bottom + clip_top);
679 gtk_fixed_put(GTK_FIXED(xv->widgetwindow), xv->widget, -clip_left, -clip_top); 677 gtk_fixed_move(GTK_FIXED(xv->widgetwindow), xv->widget, -clip_left, -clip_top);
680 printf("reclip %d %d -> %d %d clip_top:%d clip_left:%d\n",xv->clip_right, xv->clip_bottom, clip_right, clip_bottom, clip_top , clip_left); 678 printf("reclip %d %d -> %d %d clip_top:%d clip_left:%d\n",xv->clip_right, xv->clip_bottom, clip_right, clip_bottom, clip_top , clip_left);
681 679
682 680
@@ -684,7 +682,7 @@ x_draw_xwidget_glyph_string (struct glyph_string *s)
684 } 682 }
685 //if emacs wants to repaint the area where the widget lives, queue a redraw 683 //if emacs wants to repaint the area where the widget lives, queue a redraw
686 if (!xwidget_hidden(xv)){ 684 if (!xwidget_hidden(xv)){
687 gtk_widget_queue_draw (xv->widgetwindow); 685 gtk_widget_queue_draw (GTK_WIDGET(xv->widgetwindow));
688 gtk_widget_queue_draw (xv->widget); 686 gtk_widget_queue_draw (xv->widget);
689 } 687 }
690} 688}
@@ -730,7 +728,7 @@ DEFUN ("xwidget-webkit-get-title", Fxwidget_webkit_get_title, Sxwidget_webkit_g
730{ 728{
731 //TODO support multibyte strings 729 //TODO support multibyte strings
732 const gchar* str=webkit_web_view_get_title( WEBKIT_WEB_VIEW(xid2xw(xwidget_id)->widget_osr)); 730 const gchar* str=webkit_web_view_get_title( WEBKIT_WEB_VIEW(xid2xw(xwidget_id)->widget_osr));
733 return make_string_from_bytes(str, wcslen(str), strlen(str)); 731 return make_string_from_bytes(str, wcslen((const wchar_t *)str), strlen(str));
734} 732}
735 733
736 734
@@ -798,18 +796,37 @@ DEFUN("xwidget-info", Fxwidget_info , Sxwidget_info, 1,1,0, doc: /* get xwidget
798 struct xwidget *xw = xid2xw(xwidget_id); 796 struct xwidget *xw = xid2xw(xwidget_id);
799 Lisp_Object info; 797 Lisp_Object info;
800 798
801 info = Fmake_vector (make_number (7), Qnil); 799 info = Fmake_vector (make_number (4), Qnil);
802 XVECTOR (info)->contents[0] = make_number(xw->id); 800 XVECTOR (info)->contents[0] = make_number(xw->id);
803 XVECTOR (info)->contents[1] = make_number(xw->type); 801 XVECTOR (info)->contents[1] = xw->type;
804 XVECTOR (info)->contents[2] = Qnil; //make_number(xw->x); 802 XVECTOR (info)->contents[2] = make_number(xw->width);
805 XVECTOR (info)->contents[3] = Qnil;//make_number(xw->y); 803 XVECTOR (info)->contents[3] = make_number(xw->height);
806 XVECTOR (info)->contents[4] = make_number(xw->width); 804
807 XVECTOR (info)->contents[5] = make_number(xw->height); 805
808 XVECTOR (info)->contents[6] = Qnil;//make_number(xw->hidden); 806 return info;
807}
808
809DEFUN("xwidget-view-info", Fxwidget_view_info , Sxwidget_view_info, 2,2,0, doc: /* get xwidget view props */)
810 (Lisp_Object xwidget_id, Lisp_Object window)
811{
812 struct xwidget *xw = xid2xw(xwidget_id);
813 struct xwidget_view* xv = xwidget_view_lookup(xw, XWINDOW(window));
814
815 Lisp_Object info;
816
817 info = Fmake_vector (make_number (6), Qnil);
818 XVECTOR (info)->contents[0] = make_number(xv->x);
819 XVECTOR (info)->contents[1] = make_number(xv->y);
820 XVECTOR (info)->contents[2] = make_number(xv->clip_right);
821 XVECTOR (info)->contents[3] = make_number(xv->clip_bottom);
822 XVECTOR (info)->contents[4] = make_number(xv->clip_top);
823 XVECTOR (info)->contents[5] = make_number(xv->clip_left);
809 824
810 return info; 825 return info;
811} 826}
812 827
828
829
813//xterm.c listens to xwidget_owns_kbd and tries to not eat events when its set 830//xterm.c listens to xwidget_owns_kbd and tries to not eat events when its set
814int xwidget_owns_kbd = 0; 831int xwidget_owns_kbd = 0;
815DEFUN ("xwidget-set-keyboard-grab", Fxwidget_set_keyboard_grab, Sxwidget_set_keyboard_grab, 2, 2, 0, doc: /* set unset kbd grab for xwidget. */ 832DEFUN ("xwidget-set-keyboard-grab", Fxwidget_set_keyboard_grab, Sxwidget_set_keyboard_grab, 2, 2, 0, doc: /* set unset kbd grab for xwidget. */
@@ -938,6 +955,7 @@ syms_of_xwidget (void)
938 defsubr (&Sxwidget_send_keyboard_event); 955 defsubr (&Sxwidget_send_keyboard_event);
939 defsubr (&Sxwidget_embed_steal_window); 956 defsubr (&Sxwidget_embed_steal_window);
940 defsubr (&Sxwidget_info); 957 defsubr (&Sxwidget_info);
958 defsubr (&Sxwidget_view_info);
941 defsubr (&Sxwidget_resize_internal); 959 defsubr (&Sxwidget_resize_internal);
942 defsubr (&Sxwidget_embed_steal_window); 960 defsubr (&Sxwidget_embed_steal_window);
943 961
@@ -1050,12 +1068,11 @@ xwidget_from_id (int id)
1050 1068
1051void xwidget_view_delete_all_in_window( struct window *w ) 1069void xwidget_view_delete_all_in_window( struct window *w )
1052{ 1070{
1053 //xxx
1054 struct xwidget_view* xv = NULL; 1071 struct xwidget_view* xv = NULL;
1055 for (int i = 0; i < MAX_XWIDGETS; i++){ 1072 for (int i = 0; i < MAX_XWIDGETS; i++){
1056 xv = &xwidget_views[i]; 1073 xv = &xwidget_views[i];
1057 if(xv->w == w){ 1074 if(xv->w == w){
1058 gtk_widget_destroy(xv->widgetwindow); 1075 gtk_widget_destroy(GTK_WIDGET(xv->widgetwindow));
1059 } 1076 }
1060 } 1077 }
1061} 1078}