462
|
1 /* gtk-xemacs.c
|
|
2 **
|
|
3 ** Description: A widget to encapsulate a XEmacs 'text widget'
|
|
4 **
|
|
5 ** Created by: William M. Perry
|
|
6 ** Copyright (c) 2000 William M. Perry <wmperry@gnu.org>
|
|
7 **
|
|
8 */
|
|
9
|
|
10 #include <config.h>
|
|
11
|
|
12 #include "lisp.h"
|
|
13 #include "console-gtk.h"
|
|
14 #include "objects-gtk.h"
|
|
15 #include "gtk-xemacs.h"
|
809
|
16 #include "device.h"
|
|
17 #include "glyphs.h"
|
462
|
18 #include "window.h"
|
|
19 #include "faces.h"
|
778
|
20 #include "event-gtk.h"
|
462
|
21
|
|
22 extern Lisp_Object Vmodeline_face;
|
|
23 extern Lisp_Object Vscrollbar_on_left_p;
|
|
24
|
|
25 EXFUN (Fmake_image_instance, 4);
|
|
26
|
|
27 static void gtk_xemacs_class_init (GtkXEmacsClass *klass);
|
|
28 static void gtk_xemacs_init (GtkXEmacs *xemacs);
|
|
29 static void gtk_xemacs_size_allocate (GtkWidget *widget, GtkAllocation *allocaction);
|
|
30 static void gtk_xemacs_draw (GtkWidget *widget, GdkRectangle *area);
|
|
31 static void gtk_xemacs_paint (GtkWidget *widget, GdkRectangle *area);
|
|
32 static void gtk_xemacs_size_request (GtkWidget *widget, GtkRequisition *requisition);
|
|
33 static void gtk_xemacs_realize (GtkWidget *widget);
|
|
34 static void gtk_xemacs_style_set (GtkWidget *widget, GtkStyle *previous_style);
|
|
35 static gint gtk_xemacs_expose (GtkWidget *widget, GdkEventExpose *event);
|
|
36
|
|
37 guint
|
|
38 gtk_xemacs_get_type (void)
|
|
39 {
|
|
40 static guint xemacs_type = 0;
|
|
41
|
|
42 if (!xemacs_type)
|
|
43 {
|
|
44 static const GtkTypeInfo xemacs_info =
|
|
45 {
|
|
46 "GtkXEmacs",
|
|
47 sizeof (GtkXEmacs),
|
|
48 sizeof (GtkXEmacsClass),
|
|
49 (GtkClassInitFunc) gtk_xemacs_class_init,
|
|
50 (GtkObjectInitFunc) gtk_xemacs_init,
|
|
51 /* reserved_1 */ NULL,
|
|
52 /* reserved_2 */ NULL,
|
|
53 (GtkClassInitFunc) NULL,
|
|
54 };
|
|
55
|
|
56 xemacs_type = gtk_type_unique (gtk_fixed_get_type (), &xemacs_info);
|
|
57 }
|
|
58
|
|
59 return xemacs_type;
|
|
60 }
|
|
61
|
|
62 static GtkWidgetClass *parent_class;
|
|
63
|
|
64 static void
|
|
65 gtk_xemacs_class_init (GtkXEmacsClass *class)
|
|
66 {
|
|
67 GtkWidgetClass *widget_class;
|
|
68
|
|
69 widget_class = (GtkWidgetClass*) class;
|
|
70 parent_class = (GtkWidgetClass *) gtk_type_class (gtk_fixed_get_type ());
|
|
71
|
|
72 widget_class->size_allocate = gtk_xemacs_size_allocate;
|
|
73 widget_class->size_request = gtk_xemacs_size_request;
|
|
74 widget_class->draw = gtk_xemacs_draw;
|
|
75 widget_class->expose_event = gtk_xemacs_expose;
|
|
76 widget_class->realize = gtk_xemacs_realize;
|
|
77 widget_class->button_press_event = emacs_gtk_button_event_handler;
|
|
78 widget_class->button_release_event = emacs_gtk_button_event_handler;
|
|
79 widget_class->key_press_event = emacs_gtk_key_event_handler;
|
|
80 widget_class->key_release_event = emacs_gtk_key_event_handler;
|
|
81 widget_class->motion_notify_event = emacs_gtk_motion_event_handler;
|
|
82 widget_class->style_set = gtk_xemacs_style_set;
|
|
83 }
|
|
84
|
|
85 static void
|
|
86 gtk_xemacs_init (GtkXEmacs *xemacs)
|
|
87 {
|
|
88 GTK_WIDGET_SET_FLAGS (xemacs, GTK_CAN_FOCUS);
|
|
89 }
|
|
90
|
|
91 GtkWidget*
|
|
92 gtk_xemacs_new (struct frame *f)
|
|
93 {
|
|
94 GtkXEmacs *xemacs;
|
|
95
|
|
96 xemacs = gtk_type_new (gtk_xemacs_get_type ());
|
|
97 xemacs->f = f;
|
|
98
|
|
99 return GTK_WIDGET (xemacs);
|
|
100 }
|
|
101
|
|
102 static void
|
|
103 __nuke_background_items (GtkWidget *widget)
|
|
104 {
|
|
105 /* This bit of voodoo is here to get around the annoying flicker
|
|
106 when GDK tries to futz with our background pixmap as well as
|
|
107 XEmacs doing it
|
|
108
|
|
109 We do NOT set the background of this widget window, that way
|
|
110 there is NO flickering, etc. The downside is the XEmacs frame
|
|
111 appears as 'seethru' when XEmacs is too busy to redraw the
|
|
112 frame.
|
|
113
|
|
114 Well, wait, we do... otherwise there sre weird 'seethru' areas
|
|
115 even when XEmacs does a full redisplay. Most noticable in some
|
|
116 areas of the modeline, or in the right-hand-side of the window
|
|
117 between the scrollbar ad n the edge of the window.
|
|
118 */
|
|
119 if (widget->window)
|
|
120 {
|
|
121 gdk_window_set_back_pixmap (widget->window, NULL, 0);
|
|
122 gdk_window_set_back_pixmap (widget->parent->window, NULL, 0);
|
|
123 gdk_window_set_background (widget->parent->window,
|
|
124 &widget->style->bg[GTK_STATE_NORMAL]);
|
|
125 gdk_window_set_background (widget->window,
|
|
126 &widget->style->bg[GTK_STATE_NORMAL]);
|
|
127 }
|
|
128 }
|
|
129
|
|
130 extern Lisp_Object xemacs_gtk_convert_color(GdkColor *c, GtkWidget *w);
|
|
131
|
|
132 /* From objects-gtk.c */
|
|
133 extern Lisp_Object __get_gtk_font_truename (GdkFont *gdk_font, int expandp);
|
|
134
|
|
135 #define convert_font(f) __get_gtk_font_truename (f, 0)
|
|
136
|
778
|
137 #ifdef SMASH_FACE_FALLBACKS
|
462
|
138 static void
|
|
139 smash_face_fallbacks (struct frame *f, GtkStyle *style)
|
|
140 {
|
|
141 #define FROB(face,prop,slot) do { \
|
|
142 Lisp_Object fallback = Qnil; \
|
|
143 Lisp_Object specifier = Fget (face, prop, Qnil); \
|
|
144 struct Lisp_Specifier *sp = NULL; \
|
|
145 if (NILP (specifier)) continue; \
|
|
146 sp = XSPECIFIER (specifier); \
|
|
147 fallback = sp->fallback; \
|
|
148 if (EQ (Fcar (Fcar (Fcar (fallback))), Qgtk)) \
|
|
149 fallback = XCDR (fallback); \
|
|
150 if (! NILP (slot)) \
|
|
151 fallback = acons (list1 (Qgtk), \
|
|
152 slot, \
|
|
153 fallback); \
|
|
154 set_specifier_fallback (specifier, fallback); \
|
|
155 } while (0);
|
|
156 #define FROB_FACE(face,fg_slot,bg_slot) \
|
|
157 do { \
|
|
158 FROB (face, Qforeground, xemacs_gtk_convert_color (&style->fg_slot[GTK_STATE_NORMAL], FRAME_GTK_SHELL_WIDGET (f))); \
|
|
159 FROB (face, Qbackground, xemacs_gtk_convert_color (&style->bg_slot[GTK_STATE_NORMAL], FRAME_GTK_SHELL_WIDGET (f))); \
|
|
160 if (style->rc_style && style->rc_style->bg_pixmap_name[GTK_STATE_NORMAL]) \
|
|
161 { \
|
|
162 FROB (Vdefault_face, Qbackground_pixmap, \
|
|
163 Fmake_image_instance (build_string (style->rc_style->bg_pixmap_name[GTK_STATE_NORMAL]), \
|
|
164 f->device, Qnil, make_int (5))); \
|
|
165 } \
|
|
166 else \
|
|
167 { \
|
|
168 FROB (Vdefault_face, Qbackground_pixmap, Qnil); \
|
|
169 } \
|
|
170 } while (0)
|
|
171
|
|
172 FROB (Vdefault_face, Qfont, convert_font (style->font));
|
|
173 FROB_FACE (Vdefault_face, fg, bg);
|
|
174 FROB_FACE (Vgui_element_face, text, mid);
|
|
175
|
|
176 #undef FROB
|
|
177 #undef FROB_FACE
|
|
178 }
|
778
|
179 #endif /* SMASH_FACE_FALLBACKS */
|
462
|
180
|
|
181 #ifdef HAVE_SCROLLBARS
|
|
182 static void
|
|
183 smash_scrollbar_specifiers (struct frame *f, GtkStyle *style)
|
|
184 {
|
|
185 Lisp_Object frame;
|
|
186 int slider_size = 0;
|
|
187 int hsize, vsize;
|
|
188 GtkRangeClass *klass;
|
|
189
|
793
|
190 frame = wrap_frame (f);
|
462
|
191
|
|
192 klass = (GtkRangeClass *) gtk_type_class (GTK_TYPE_SCROLLBAR);
|
|
193 slider_size = klass->slider_width;
|
|
194 hsize = slider_size + (style->klass->ythickness * 2);
|
|
195 vsize = slider_size + (style->klass->xthickness * 2);
|
|
196
|
|
197 style = gtk_style_attach (style,
|
|
198 GTK_WIDGET (DEVICE_GTK_APP_SHELL (XDEVICE (FRAME_DEVICE (f))))->window);
|
|
199
|
|
200 Fadd_spec_to_specifier (Vscrollbar_width, make_int (vsize), frame, Qnil, Qnil);
|
|
201 Fadd_spec_to_specifier (Vscrollbar_height, make_int (hsize), frame, Qnil, Qnil);
|
|
202 }
|
|
203 #endif /* HAVE_SCROLLBARS */
|
|
204
|
744
|
205 #ifdef HAVE_TOOLBARS
|
|
206 extern Lisp_Object Vtoolbar_shadow_thickness;
|
|
207
|
|
208 static void
|
|
209 smash_toolbar_specifiers(struct frame *f, GtkStyle *style)
|
|
210 {
|
|
211 Lisp_Object frame;
|
|
212 GtkStyleClass *klass = (GtkStyleClass *) style->klass;
|
|
213
|
793
|
214 frame = wrap_frame (f);
|
744
|
215
|
|
216 Fadd_spec_to_specifier (Vtoolbar_shadow_thickness, make_int (klass->xthickness),
|
|
217 Qnil, list2 (Qgtk, Qdefault), Qprepend);
|
|
218 }
|
|
219 #endif /* HAVE_TOOLBARS */
|
|
220
|
462
|
221 static void
|
|
222 gtk_xemacs_realize (GtkWidget *widget)
|
|
223 {
|
|
224 parent_class->realize (widget);
|
|
225 gtk_xemacs_style_set (widget, gtk_widget_get_style (widget));
|
|
226 }
|
|
227
|
|
228 static void
|
|
229 gtk_xemacs_style_set (GtkWidget *widget, GtkStyle *previous_style)
|
|
230 {
|
|
231 GtkStyle *new_style = gtk_widget_get_style (widget);
|
|
232 GtkXEmacs *x = GTK_XEMACS (widget);
|
|
233
|
|
234 parent_class->style_set (widget, previous_style);
|
|
235
|
|
236 if (x->f)
|
|
237 {
|
|
238 __nuke_background_items (widget);
|
778
|
239 #ifdef SMASH_FACE_FALLBACKS
|
462
|
240 smash_face_fallbacks (x->f, new_style);
|
|
241 #endif
|
744
|
242 #ifdef HAVE_SCROLLBARS
|
462
|
243 smash_scrollbar_specifiers (x->f, new_style);
|
744
|
244 #endif
|
|
245 #ifdef HAVE_TOOLBARS
|
|
246 smash_toolbar_specifiers (x->f, new_style);
|
|
247 #endif
|
462
|
248 }
|
|
249 }
|
|
250
|
|
251 static void
|
|
252 gtk_xemacs_size_request (GtkWidget *widget, GtkRequisition *requisition)
|
|
253 {
|
|
254 GtkXEmacs *x = GTK_XEMACS (widget);
|
|
255 struct frame *f = GTK_XEMACS_FRAME (x);
|
|
256 int width, height;
|
|
257
|
|
258 if (f)
|
|
259 {
|
|
260 char_to_pixel_size (f, FRAME_WIDTH (f), FRAME_HEIGHT (f),
|
|
261 &width, &height);
|
|
262 requisition->width = width;
|
|
263 requisition->height = height;
|
|
264 }
|
|
265 else
|
|
266 {
|
|
267 parent_class->size_request (widget, requisition);
|
|
268 }
|
|
269 }
|
|
270
|
|
271 static void
|
|
272 gtk_xemacs_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
|
|
273 {
|
|
274 GtkXEmacs *x = GTK_XEMACS (widget);
|
|
275 struct frame *f = GTK_XEMACS_FRAME (x);
|
|
276 int columns, rows;
|
|
277
|
|
278 parent_class->size_allocate(widget, allocation);
|
|
279
|
|
280 if (f)
|
|
281 {
|
|
282 f->pixwidth = allocation->width;
|
|
283 f->pixheight = allocation->height;
|
|
284
|
|
285 pixel_to_char_size (f,
|
|
286 allocation->width,
|
|
287 allocation->height, &columns, &rows);
|
|
288
|
|
289 change_frame_size (f, rows, columns, 1);
|
|
290 }
|
|
291 }
|
|
292
|
|
293 static void
|
|
294 gtk_xemacs_paint (GtkWidget *widget, GdkRectangle *area)
|
|
295 {
|
|
296 GtkXEmacs *x = GTK_XEMACS (widget);
|
|
297 struct frame *f = GTK_XEMACS_FRAME (x);
|
|
298 gtk_redraw_exposed_area (f, area->x, area->y, area->width, area->height);
|
|
299 }
|
|
300
|
|
301 static void
|
|
302 gtk_xemacs_draw (GtkWidget *widget, GdkRectangle *area)
|
|
303 {
|
|
304 GtkFixed *fixed = GTK_FIXED (widget);
|
|
305 GtkFixedChild *child;
|
|
306 GdkRectangle child_area;
|
|
307 GList *children;
|
|
308
|
|
309 /* I need to manually iterate over the children instead of just
|
|
310 chaining to parent_class->draw() because it calls
|
|
311 gtk_fixed_paint() directly, which clears the background window,
|
|
312 which causes A LOT of flashing. */
|
|
313
|
|
314 gtk_xemacs_paint (widget, area);
|
|
315
|
|
316 children = fixed->children;
|
|
317
|
|
318 while (children)
|
|
319 {
|
|
320 child = children->data;
|
|
321 children = children->next;
|
|
322 /* #### This is what causes the scrollbar flickering!
|
|
323 Evidently the scrollbars pretty much take care of drawing
|
|
324 themselves in most cases. Then we come along and tell them
|
|
325 to redraw again!
|
|
326
|
|
327 But if we just leave it out, then they do not get drawn
|
|
328 correctly the first time!
|
|
329
|
|
330 Scrollbar flickering has been greatly helped by the
|
|
331 optimizations in scrollbar-gtk.c /
|
|
332 gtk_update_scrollbar_instance_status (), so this is not that
|
|
333 big a deal anymore.
|
|
334 */
|
|
335 if (gtk_widget_intersect (child->widget, area, &child_area))
|
|
336 {
|
|
337 gtk_widget_draw (child->widget, &child_area);
|
|
338 }
|
|
339 }
|
|
340 }
|
|
341
|
|
342 static gint
|
|
343 gtk_xemacs_expose (GtkWidget *widget, GdkEventExpose *event)
|
|
344 {
|
|
345 GtkXEmacs *x = GTK_XEMACS (widget);
|
|
346 struct frame *f = GTK_XEMACS_FRAME (x);
|
|
347 GdkRectangle *a = &event->area;
|
|
348
|
|
349 /* This takes care of drawing the scrollbars, etc */
|
|
350 parent_class->expose_event (widget, event);
|
|
351
|
|
352 /* Now draw the actual frame data */
|
|
353 if (!check_for_ignored_expose (f, a->x, a->y, a->width, a->height) &&
|
|
354 !find_matching_subwindow (f, a->x, a->y, a->width, a->height))
|
|
355 gtk_redraw_exposed_area (f, a->x, a->y, a->width, a->height);
|
|
356 return (TRUE);
|
|
357 }
|
|
358
|
|
359 Lisp_Object
|
|
360 xemacs_gtk_convert_color(GdkColor *c, GtkWidget *w)
|
|
361 {
|
|
362 char color_buf[255];
|
|
363
|
|
364 sprintf (color_buf, "#%04x%04x%04x", c->red, c->green, c->blue);
|
|
365
|
|
366 return (build_string (color_buf));
|
|
367 }
|