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