0
|
1 /* toolbar implementation -- X interface.
|
|
2 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
4 Copyright (C) 1995, 1996 Ben Wing.
|
|
5 Copyright (C) 1996 Chuck Thompson.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
|
26 #include <config.h>
|
|
27 #include "lisp.h"
|
|
28
|
|
29 #include "console-x.h"
|
|
30 #include "glyphs-x.h"
|
|
31 #include "objects-x.h"
|
|
32 #include "xgccache.h"
|
|
33 #include "EmacsFrame.h"
|
|
34 #include "EmacsFrameP.h"
|
|
35 #include "EmacsManager.h"
|
|
36
|
|
37 #include "faces.h"
|
|
38 #include "frame.h"
|
|
39 #include "toolbar.h"
|
|
40 #include "window.h"
|
|
41
|
|
42 static void
|
|
43 x_draw_blank_toolbar_button (struct frame *f, int x, int y, int width,
|
|
44 int height, int threed)
|
|
45 {
|
|
46 struct device *d = XDEVICE (f->device);
|
|
47 EmacsFrame ef = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
48 int shadow_thickness = ef->emacs_frame.toolbar_shadow_thickness;
|
|
49
|
|
50 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
51 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
52 GC top_shadow_gc, bottom_shadow_gc, background_gc;
|
|
53
|
|
54 background_gc = FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f);
|
|
55
|
|
56 if (threed)
|
|
57 {
|
|
58 top_shadow_gc = FRAME_X_TOOLBAR_TOP_SHADOW_GC (f);
|
|
59 bottom_shadow_gc = FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f);
|
|
60 }
|
|
61 else
|
|
62 {
|
|
63 top_shadow_gc = background_gc;
|
|
64 bottom_shadow_gc = background_gc;
|
|
65 }
|
|
66
|
|
67 /* Draw the outline. */
|
|
68 x_output_shadows (f, x, y, width, height, top_shadow_gc,
|
|
69 bottom_shadow_gc, background_gc, shadow_thickness);
|
|
70
|
|
71 /* Blank the middle. */
|
|
72 XFillRectangle (dpy, x_win, background_gc, x + shadow_thickness,
|
|
73 y + shadow_thickness, width - shadow_thickness * 2,
|
|
74 height - shadow_thickness * 2);
|
|
75 }
|
|
76
|
|
77 static void
|
|
78 x_output_toolbar_button (struct frame *f, Lisp_Object button)
|
|
79 {
|
|
80 struct device *d = XDEVICE (f->device);
|
|
81 EmacsFrame ef = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
82 int shadow_thickness = ef->emacs_frame.toolbar_shadow_thickness;
|
|
83
|
|
84 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
85 Window x_win = XtWindow (FRAME_X_TEXT_WIDGET (f));
|
|
86 GC top_shadow_gc, bottom_shadow_gc, background_gc;
|
|
87 Lisp_Object instance, frame, window, glyph;
|
|
88 struct toolbar_button *tb = XTOOLBAR_BUTTON (button);
|
|
89 struct Lisp_Image_Instance *p;
|
|
90 struct window *w;
|
|
91
|
|
92 XSETFRAME (frame, f);
|
|
93 window = FRAME_LAST_NONMINIBUF_WINDOW (f);
|
|
94 w = XWINDOW (window);
|
|
95
|
|
96 glyph = get_toolbar_button_glyph (w, tb);
|
|
97
|
|
98 if (tb->enabled)
|
|
99 {
|
|
100 if (tb->down)
|
|
101 {
|
|
102 top_shadow_gc = FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f);
|
|
103 bottom_shadow_gc = FRAME_X_TOOLBAR_TOP_SHADOW_GC (f);
|
|
104 }
|
|
105 else
|
|
106 {
|
|
107 top_shadow_gc = FRAME_X_TOOLBAR_TOP_SHADOW_GC (f);
|
|
108 bottom_shadow_gc = FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f);
|
|
109 }
|
|
110 }
|
|
111 else
|
|
112 {
|
|
113 top_shadow_gc = FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f);
|
|
114 bottom_shadow_gc = FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f);
|
|
115 }
|
|
116 background_gc = FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f);
|
|
117
|
|
118 /* Draw the outline. */
|
|
119 x_output_shadows (f, tb->x, tb->y, tb->width, tb->height, top_shadow_gc,
|
|
120 bottom_shadow_gc, background_gc, shadow_thickness);
|
|
121
|
|
122 /* Clear the pixmap area. */
|
|
123 XFillRectangle (dpy, x_win, background_gc, tb->x + shadow_thickness,
|
|
124 tb->y + shadow_thickness, tb->width - shadow_thickness * 2,
|
|
125 tb->height - shadow_thickness * 2);
|
|
126
|
|
127 background_gc = FRAME_X_TOOLBAR_PIXMAP_BACKGROUND_GC (f);
|
|
128
|
|
129 /* #### It is currently possible for users to trash us by directly
|
|
130 changing the toolbar glyphs. Avoid crashing in that case. */
|
|
131 if (GLYPHP (glyph))
|
|
132 instance = glyph_image_instance (glyph, window, ERROR_ME_NOT, 1);
|
|
133 else
|
|
134 instance = Qnil;
|
|
135
|
|
136 if (IMAGE_INSTANCEP (instance))
|
|
137 {
|
|
138 int width = tb->width - shadow_thickness * 2;
|
|
139 int height = tb->height - shadow_thickness * 2;
|
|
140 int x_offset = shadow_thickness;
|
|
141 int y_offset = shadow_thickness;
|
|
142
|
|
143 p = XIMAGE_INSTANCE (instance);
|
|
144
|
|
145 if (IMAGE_INSTANCE_PIXMAP_TYPE_P (p))
|
|
146 {
|
|
147 if (width > (int) IMAGE_INSTANCE_PIXMAP_WIDTH (p))
|
|
148 {
|
|
149 x_offset += ((int) (width - IMAGE_INSTANCE_PIXMAP_WIDTH (p))
|
|
150 / 2);
|
|
151 width = IMAGE_INSTANCE_PIXMAP_WIDTH (p);
|
|
152 }
|
|
153 if (height > (int) IMAGE_INSTANCE_PIXMAP_HEIGHT (p))
|
|
154 {
|
|
155 y_offset += ((int) (height - IMAGE_INSTANCE_PIXMAP_HEIGHT (p))
|
|
156 / 2);
|
|
157 height = IMAGE_INSTANCE_PIXMAP_HEIGHT (p);
|
|
158 }
|
|
159
|
|
160 x_output_x_pixmap (f, XIMAGE_INSTANCE (instance), tb->x + x_offset,
|
|
161 tb->y + y_offset, 0, 0, 0, 0, width, height,
|
|
162 0, 0, 0, background_gc);
|
|
163 }
|
|
164 else if (IMAGE_INSTANCE_TYPE (p) == IMAGE_TEXT)
|
|
165 {
|
|
166 /* #### We need to make the face used configurable. */
|
|
167 struct face_cachel *cachel =
|
|
168 WINDOW_FACE_CACHEL (w, DEFAULT_INDEX);
|
|
169 struct display_line dl;
|
|
170 Lisp_Object string = IMAGE_INSTANCE_TEXT_STRING (p);
|
|
171 unsigned char charsets[NUM_LEADING_BYTES];
|
|
172 emchar_dynarr *buf;
|
|
173 struct font_metric_info fm;
|
|
174
|
|
175 /* This could be true if we were called via the Expose event
|
|
176 handler. Mark the button as dirty and return
|
|
177 immediately. */
|
|
178 if (f->window_face_cache_reset)
|
|
179 {
|
|
180 tb->dirty = 1;
|
|
181 MARK_TOOLBAR_CHANGED;
|
|
182 return;
|
|
183 }
|
|
184 buf = Dynarr_new (Emchar);
|
|
185 convert_bufbyte_string_into_emchar_dynarr
|
16
|
186 (XSTRING_DATA (string), XSTRING_LENGTH (string), buf);
|
0
|
187 find_charsets_in_emchar_string (charsets, Dynarr_atp (buf, 0),
|
|
188 Dynarr_length (buf));
|
|
189 ensure_face_cachel_complete (cachel, window, charsets);
|
|
190 face_cachel_charset_font_metric_info (cachel, charsets, &fm);
|
|
191
|
|
192 dl.ascent = fm.ascent;
|
|
193 dl.descent = fm.descent;
|
|
194 dl.ypos = tb->y + y_offset + fm.ascent;
|
|
195
|
|
196 if (fm.ascent + fm.descent <= height)
|
|
197 {
|
|
198 dl.ypos += (height - fm.ascent - fm.descent) / 2;
|
|
199 dl.clip = 0;
|
|
200 }
|
|
201 else
|
|
202 {
|
|
203 dl.clip = fm.ascent + fm.descent - height;
|
|
204 }
|
|
205
|
|
206 x_output_string (w, &dl, buf, tb->x + x_offset, 0, 0, width,
|
|
207 DEFAULT_INDEX, 0, 0, 0, 0);
|
|
208 Dynarr_free (buf);
|
|
209 }
|
|
210
|
|
211 /* We silently ignore the image if it isn't a pixmap or text. */
|
|
212 }
|
|
213
|
|
214 tb->dirty = 0;
|
|
215 }
|
|
216
|
|
217 static int
|
|
218 x_get_button_size (struct frame *f, Lisp_Object window,
|
|
219 struct toolbar_button *tb, int vert, int pos)
|
|
220 {
|
|
221 EmacsFrame ef = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
222 int shadow_thickness = ef->emacs_frame.toolbar_shadow_thickness;
|
|
223 int size;
|
|
224
|
|
225 if (tb->blank)
|
|
226 {
|
|
227 if (!NILP (tb->down_glyph))
|
|
228 size = XINT (tb->down_glyph);
|
|
229 else
|
|
230 size = DEFAULT_TOOLBAR_BLANK_SIZE;
|
|
231 }
|
|
232 else
|
|
233 {
|
|
234 struct window *w = XWINDOW (window);
|
|
235 Lisp_Object glyph = get_toolbar_button_glyph (w, tb);
|
|
236
|
|
237 /* Unless, of course, the user has done something stupid like
|
|
238 change the glyph out from under us. Use a blank placeholder
|
|
239 in that case. */
|
|
240 if (NILP (glyph))
|
|
241 return XINT (f->toolbar_size[pos]);
|
|
242
|
|
243 if (vert)
|
|
244 size = glyph_height (glyph, Vdefault_face, 0, window);
|
|
245 else
|
|
246 size = glyph_width (glyph, Vdefault_face, 0, window);
|
|
247 }
|
|
248
|
|
249 if (!size)
|
|
250 {
|
|
251 /* If the glyph doesn't have a size we'll insert a blank
|
|
252 placeholder instead. */
|
|
253 return XINT (f->toolbar_size[pos]);
|
|
254 }
|
|
255
|
|
256 size += shadow_thickness * 2;
|
|
257
|
|
258 return (size);
|
|
259 }
|
|
260
|
|
261 #define X_OUTPUT_BUTTONS_LOOP(left) \
|
|
262 do { \
|
|
263 while (!NILP (button)) \
|
|
264 { \
|
|
265 struct toolbar_button *tb = XTOOLBAR_BUTTON (button); \
|
|
266 int size, height, width; \
|
|
267 \
|
|
268 if (left && tb->pushright) \
|
|
269 break; \
|
|
270 \
|
|
271 size = x_get_button_size (f, window, tb, vert, pos); \
|
|
272 \
|
|
273 if (vert) \
|
|
274 { \
|
|
275 width = bar_width; \
|
|
276 if (y + size > max_pixpos) \
|
|
277 height = max_pixpos - y; \
|
|
278 else \
|
|
279 height = size; \
|
|
280 } \
|
|
281 else \
|
|
282 { \
|
|
283 if (x + size > max_pixpos) \
|
|
284 width = max_pixpos - x; \
|
|
285 else \
|
|
286 width = size; \
|
|
287 height = bar_height; \
|
|
288 } \
|
|
289 \
|
|
290 if (tb->x != x \
|
|
291 || tb->y != y \
|
|
292 || tb->width != width \
|
|
293 || tb->height != height \
|
|
294 || tb->dirty) \
|
|
295 { \
|
|
296 if (width && height) \
|
|
297 { \
|
|
298 tb->x = x; \
|
|
299 tb->y = y; \
|
|
300 tb->width = width; \
|
|
301 tb->height = height; \
|
|
302 \
|
|
303 if (tb->blank || NILP (tb->up_glyph)) \
|
|
304 { \
|
|
305 int threed = (EQ (Qt, tb->up_glyph) ? 1 : 0); \
|
|
306 x_draw_blank_toolbar_button (f, x, y, width, \
|
|
307 height, threed); \
|
|
308 } \
|
|
309 else \
|
|
310 x_output_toolbar_button (f, button); \
|
|
311 } \
|
|
312 } \
|
|
313 \
|
|
314 if (vert) \
|
|
315 y += height; \
|
|
316 else \
|
|
317 x += width; \
|
|
318 \
|
|
319 if ((vert && y == max_pixpos) || (!vert && x == max_pixpos)) \
|
|
320 button = Qnil; \
|
|
321 else \
|
|
322 button = tb->next; \
|
|
323 } \
|
|
324 } while (0)
|
|
325
|
|
326 #define SET_TOOLBAR_WAS_VISIBLE_FLAG(frame, pos, flag) \
|
|
327 do { \
|
|
328 switch (pos) \
|
|
329 { \
|
|
330 case TOP_TOOLBAR: \
|
|
331 (frame)->top_toolbar_was_visible = flag; \
|
|
332 break; \
|
|
333 case BOTTOM_TOOLBAR: \
|
|
334 (frame)->bottom_toolbar_was_visible = flag; \
|
|
335 break; \
|
|
336 case LEFT_TOOLBAR: \
|
|
337 (frame)->left_toolbar_was_visible = flag; \
|
|
338 break; \
|
|
339 case RIGHT_TOOLBAR: \
|
|
340 (frame)->right_toolbar_was_visible = flag; \
|
|
341 break; \
|
|
342 default: \
|
|
343 abort (); \
|
|
344 } \
|
|
345 } while (0)
|
|
346
|
|
347 static void
|
|
348 x_output_toolbar (struct frame *f, enum toolbar_pos pos)
|
|
349 {
|
|
350 struct device *d = XDEVICE (f->device);
|
|
351 int x, y, bar_width, bar_height, vert;
|
|
352 int max_pixpos, right_size, right_start, blank_size;
|
|
353 Lisp_Object button, window;
|
|
354
|
|
355 get_toolbar_coords (f, pos, &x, &y, &bar_width, &bar_height, &vert, 1);
|
|
356 window = FRAME_LAST_NONMINIBUF_WINDOW (f);
|
|
357
|
|
358 if (vert)
|
|
359 max_pixpos = y + bar_height;
|
|
360 else
|
|
361 max_pixpos = x + bar_width;
|
|
362
|
|
363 button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons;
|
|
364 right_size = 0;
|
|
365
|
|
366 /* First loop over all of the buttons to determine how much room we
|
|
367 need for left hand and right hand buttons. This loop will also
|
|
368 make sure that all instances are instantiated so when we actually
|
|
369 output them they will come up immediately. */
|
|
370 while (!NILP (button))
|
|
371 {
|
|
372 struct toolbar_button *tb = XTOOLBAR_BUTTON (button);
|
|
373 int size = x_get_button_size (f, window, tb, vert, pos);
|
|
374
|
|
375 if (tb->pushright)
|
|
376 right_size += size;
|
|
377
|
|
378 button = tb->next;
|
|
379 }
|
|
380
|
|
381 button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons;
|
|
382
|
|
383 /* Loop over the left buttons, updating and outputting them. */
|
|
384 X_OUTPUT_BUTTONS_LOOP (1);
|
|
385
|
|
386 /* Now determine where the right buttons start. */
|
|
387 right_start = max_pixpos - right_size;
|
|
388 if (right_start < (vert ? y : x))
|
|
389 right_start = (vert ? y : x);
|
|
390
|
|
391 /* Output the blank which goes from the end of the left buttons to
|
|
392 the start of the right. */
|
|
393 blank_size = right_start - (vert ? y : x);
|
|
394 if (blank_size)
|
|
395 {
|
|
396 int height, width;
|
|
397
|
|
398 if (vert)
|
|
399 {
|
|
400 width = bar_width;
|
|
401 height = blank_size;
|
|
402 }
|
|
403 else
|
|
404 {
|
|
405 width = blank_size;
|
|
406 height = bar_height;
|
|
407 }
|
|
408
|
|
409 x_draw_blank_toolbar_button (f, x, y, width, height, 1);
|
|
410
|
|
411 if (vert)
|
|
412 y += height;
|
|
413 else
|
|
414 x += width;
|
|
415 }
|
|
416
|
|
417 /* Loop over the right buttons, updating and outputting them. */
|
|
418 X_OUTPUT_BUTTONS_LOOP (0);
|
|
419
|
|
420 if (!vert)
|
|
421 {
|
|
422 Lisp_Object frame;
|
|
423
|
|
424 XSETFRAME (frame, f);
|
|
425 DEVMETH (d, clear_region, (frame,
|
|
426 DEFAULT_INDEX, FRAME_PIXWIDTH (f) - 1, y, 1,
|
|
427 bar_height));
|
|
428 }
|
|
429
|
|
430 SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 1);
|
|
431
|
|
432 XFlush (DEVICE_X_DISPLAY (d));
|
|
433 }
|
|
434
|
|
435 static void
|
|
436 x_clear_toolbar (struct frame *f, enum toolbar_pos pos, int thickness_change)
|
|
437 {
|
|
438 Lisp_Object frame = Qnil;
|
|
439 struct device *d = XDEVICE (f->device);
|
|
440 int x, y, width, height, vert;
|
|
441
|
|
442 get_toolbar_coords (f, pos, &x, &y, &width, &height, &vert, 1);
|
|
443 XSETFRAME (frame, f);
|
|
444
|
|
445 /* The thickness_change parameter is used by the toolbar resize routines
|
|
446 to clear any excess toolbar if the size shrinks. */
|
|
447 if (thickness_change < 0)
|
|
448 {
|
|
449 if (pos == LEFT_TOOLBAR || pos == RIGHT_TOOLBAR)
|
|
450 {
|
|
451 x = x + width + thickness_change;
|
|
452 width = -thickness_change;
|
|
453 }
|
|
454 else
|
|
455 {
|
|
456 y = y + height + thickness_change;
|
|
457 height = -thickness_change;
|
|
458 }
|
|
459 }
|
|
460
|
|
461 SET_TOOLBAR_WAS_VISIBLE_FLAG (f, pos, 0);
|
|
462
|
|
463 DEVMETH (d, clear_region, (frame, DEFAULT_INDEX, x, y, width, height));
|
|
464 XFlush (DEVICE_X_DISPLAY (d));
|
|
465 }
|
|
466
|
|
467 static void
|
|
468 x_output_frame_toolbars (struct frame *f)
|
|
469 {
|
|
470 assert (FRAME_X_P (f));
|
|
471
|
|
472 if (FRAME_REAL_TOP_TOOLBAR_VISIBLE (f))
|
|
473 x_output_toolbar (f, TOP_TOOLBAR);
|
|
474 else if (f->top_toolbar_was_visible)
|
|
475 x_clear_toolbar (f, TOP_TOOLBAR, 0);
|
|
476
|
|
477 if (FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f))
|
|
478 x_output_toolbar (f, BOTTOM_TOOLBAR);
|
|
479 else if (f->bottom_toolbar_was_visible)
|
|
480 x_clear_toolbar (f, BOTTOM_TOOLBAR, 0);
|
|
481
|
|
482 if (FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f))
|
|
483 x_output_toolbar (f, LEFT_TOOLBAR);
|
|
484 else if (f->left_toolbar_was_visible)
|
|
485 x_clear_toolbar (f, LEFT_TOOLBAR, 0);
|
|
486
|
|
487 if (FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f))
|
|
488 x_output_toolbar (f, RIGHT_TOOLBAR);
|
|
489 else if (f->right_toolbar_was_visible)
|
|
490 x_clear_toolbar (f, RIGHT_TOOLBAR, 0);
|
|
491 }
|
|
492
|
|
493 static void
|
|
494 x_redraw_exposed_toolbar (struct frame *f, enum toolbar_pos pos, int x, int y,
|
|
495 int width, int height)
|
|
496 {
|
|
497 int bar_x, bar_y, bar_width, bar_height, vert;
|
|
498 Lisp_Object button = FRAME_TOOLBAR_DATA (f, pos)->toolbar_buttons;
|
|
499
|
|
500 get_toolbar_coords (f, pos, &bar_x, &bar_y, &bar_width, &bar_height,
|
|
501 &vert, 1);
|
|
502
|
|
503 if (((y + height) < bar_y) || (y > (bar_y + bar_height)))
|
|
504 return;
|
|
505 if (((x + width) < bar_x) || (x > (bar_x + bar_width)))
|
|
506 return;
|
|
507
|
|
508 while (!NILP (button))
|
|
509 {
|
|
510 struct toolbar_button *tb = XTOOLBAR_BUTTON (button);
|
|
511
|
|
512 if (vert)
|
|
513 {
|
|
514 if (((tb->y + tb->height) > y) && (tb->y < (y + height)))
|
|
515 tb->dirty = 1;
|
|
516
|
|
517 /* If this is true we have gone past the exposed region. */
|
|
518 if (tb->y > (y + height))
|
|
519 break;
|
|
520 }
|
|
521 else
|
|
522 {
|
|
523 if (((tb->x + tb->width) > x) && (tb->x < (x + width)))
|
|
524 tb->dirty = 1;
|
|
525
|
|
526 /* If this is true we have gone past the exposed region. */
|
|
527 if (tb->x > (x + width))
|
|
528 break;
|
|
529 }
|
|
530
|
|
531 button = tb->next;
|
|
532 }
|
|
533
|
|
534 /* Even if none of the buttons is in the area, the blank region at
|
|
535 the very least must be because the first thing we did is verify
|
|
536 that some portion of the toolbar is in the exposed region. */
|
|
537 x_output_toolbar (f, pos);
|
|
538 }
|
|
539
|
|
540 static void
|
|
541 x_redraw_exposed_toolbars (struct frame *f, int x, int y, int width,
|
|
542 int height)
|
|
543 {
|
|
544 assert (FRAME_X_P (f));
|
|
545
|
|
546 if (FRAME_REAL_TOP_TOOLBAR_VISIBLE (f))
|
|
547 x_redraw_exposed_toolbar (f, TOP_TOOLBAR, x, y, width, height);
|
|
548
|
|
549 if (FRAME_REAL_BOTTOM_TOOLBAR_VISIBLE (f))
|
|
550 x_redraw_exposed_toolbar (f, BOTTOM_TOOLBAR, x, y, width, height);
|
|
551
|
|
552 if (FRAME_REAL_LEFT_TOOLBAR_VISIBLE (f))
|
|
553 x_redraw_exposed_toolbar (f, LEFT_TOOLBAR, x, y, width, height);
|
|
554
|
|
555 if (FRAME_REAL_RIGHT_TOOLBAR_VISIBLE (f))
|
|
556 x_redraw_exposed_toolbar (f, RIGHT_TOOLBAR, x, y, width, height);
|
|
557 }
|
|
558
|
|
559 static void
|
|
560 x_redraw_frame_toolbars (struct frame *f)
|
|
561 {
|
|
562 /* There are certain startup paths that lead to update_EmacsFrame in
|
|
563 faces.c being called before a new frame is fully initialized. In
|
|
564 particular before we have actually mapped it. That routine can
|
|
565 call this one. So, we need to make sure that the frame is
|
|
566 actually ready before we try and draw all over it. */
|
|
567
|
|
568 if (XtIsRealized (FRAME_X_SHELL_WIDGET (f)))
|
|
569 x_redraw_exposed_toolbars (f, 0, 0, FRAME_PIXWIDTH (f),
|
|
570 FRAME_PIXHEIGHT (f));
|
|
571 }
|
|
572
|
|
573
|
|
574 static void
|
|
575 x_toolbar_size_changed_in_frame_1 (struct frame *f, enum toolbar_pos pos,
|
|
576 Lisp_Object old_visibility)
|
|
577 {
|
|
578 XtWidgetGeometry req, repl;
|
|
579 int newval;
|
|
580 int oldval = FRAME_X_OLD_TOOLBAR_SIZE (f, pos);
|
|
581
|
|
582 if (NILP (f->toolbar_visible_p[pos]))
|
|
583 newval = 0;
|
|
584 else if (!f->init_finished && !INTP (f->toolbar_size[pos]))
|
|
585 /* the size might not be set at all if we're in the process of
|
|
586 creating the frame. Otherwise it better be, and we'll crash
|
|
587 out if not. */
|
|
588 newval = 0;
|
|
589 else
|
|
590 {
|
|
591 Lisp_Object frame;
|
|
592
|
|
593 XSETFRAME (frame, f);
|
|
594 newval = XINT (Fspecifier_instance (Vtoolbar_size[pos], frame, Qzero,
|
|
595 Qnil));
|
|
596 }
|
|
597
|
|
598 if (oldval == newval)
|
|
599 return;
|
|
600
|
|
601 /* We want the text area to stay the same size. So, we query the
|
|
602 current size and then adjust it for the change in the toolbar
|
|
603 size. */
|
|
604
|
|
605 in_specifier_change_function++;
|
|
606 if (!in_resource_setting)
|
|
607 /* mirror the value in the frame resources, unless it was already
|
|
608 done. */
|
|
609 XtVaSetValues (FRAME_X_TEXT_WIDGET (f),
|
|
610 pos == TOP_TOOLBAR ? XtNtopToolBarHeight :
|
|
611 pos == BOTTOM_TOOLBAR ? XtNbottomToolBarHeight :
|
|
612 pos == LEFT_TOOLBAR ? XtNleftToolBarWidth :
|
|
613 XtNrightToolBarWidth,
|
|
614 newval, 0);
|
|
615 if (XtIsRealized (FRAME_X_CONTAINER_WIDGET (f)))
|
|
616 {
|
|
617 int change = newval - oldval;
|
|
618 Lisp_Object new_visibility = f->toolbar_visible_p[pos];
|
|
619
|
|
620 req.request_mode = 0;
|
|
621 /* the query-geometry method looks at the current value of
|
|
622 f->toolbar_size[pos], so temporarily set it back to the old
|
|
623 one. If we were called because of a visibility change we
|
|
624 also have to temporarily restore its old status as well. */
|
|
625 f->toolbar_size[pos] = make_int (oldval);
|
|
626 if (!EQ (old_visibility, Qzero))
|
|
627 f->toolbar_visible_p[pos] = old_visibility;
|
|
628 XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl);
|
|
629 f->toolbar_size[pos] = make_int (newval);
|
|
630 if (!EQ (old_visibility, Qzero))
|
|
631 f->toolbar_visible_p[pos] = new_visibility;
|
|
632
|
|
633 if (change < 0)
|
|
634 x_clear_toolbar (f, pos, change);
|
|
635 if (pos == LEFT_TOOLBAR || pos == RIGHT_TOOLBAR)
|
|
636 repl.width += change;
|
|
637 else
|
|
638 repl.height += change;
|
|
639
|
|
640 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
641 EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width,
|
|
642 repl.height);
|
|
643 }
|
|
644 /* #### should this go within XtIsRealized()? probably not ... */
|
|
645 FRAME_X_OLD_TOOLBAR_SIZE (f, pos) = newval;
|
|
646 in_specifier_change_function--;
|
|
647 }
|
|
648
|
|
649 static void
|
|
650 x_toolbar_size_changed_in_frame (struct frame *f, enum toolbar_pos pos,
|
|
651 Lisp_Object oldval)
|
|
652 {
|
|
653 x_toolbar_size_changed_in_frame_1 (f, pos, Qzero);
|
|
654 }
|
|
655
|
|
656 static void
|
|
657 x_toolbar_visible_p_changed_in_frame (struct frame *f, enum toolbar_pos pos,
|
|
658 Lisp_Object oldval)
|
|
659 {
|
|
660 x_toolbar_size_changed_in_frame_1 (f, pos, oldval);
|
|
661 }
|
|
662
|
|
663 static void
|
|
664 x_initialize_frame_toolbar_gcs (struct frame *f)
|
|
665 {
|
|
666 EmacsFrame ef = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
667 XGCValues gcv;
|
|
668 unsigned long flags = (GCForeground | GCBackground | GCGraphicsExposures);
|
|
669
|
|
670 gcv.foreground = ef->emacs_frame.background_toolbar_pixel;
|
|
671 gcv.background = ef->core.background_pixel;
|
|
672 gcv.graphics_exposures = False;
|
|
673 FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f) =
|
|
674 XtGetGC ((Widget) ef, flags, &gcv);
|
|
675
|
110
|
676 if (ef->emacs_frame.top_toolbar_shadow_pixel ==
|
|
677 ef->emacs_frame.bottom_toolbar_shadow_pixel)
|
0
|
678 {
|
|
679 ef->emacs_frame.top_toolbar_shadow_pixel =
|
|
680 ef->emacs_frame.background_toolbar_pixel;
|
|
681 ef->emacs_frame.bottom_toolbar_shadow_pixel =
|
|
682 ef->emacs_frame.background_toolbar_pixel;
|
|
683 }
|
|
684
|
|
685 x_generate_shadow_pixels (f, &ef->emacs_frame.top_toolbar_shadow_pixel,
|
|
686 &ef->emacs_frame.bottom_toolbar_shadow_pixel,
|
|
687 ef->emacs_frame.background_toolbar_pixel,
|
|
688 ef->core.background_pixel);
|
|
689
|
|
690 gcv.foreground = ef->emacs_frame.top_toolbar_shadow_pixel;
|
|
691 gcv.background = ef->core.background_pixel;
|
|
692 gcv.graphics_exposures = False;
|
|
693 flags = GCForeground | GCBackground | GCGraphicsExposures;
|
|
694 if (ef->emacs_frame.top_toolbar_shadow_pixmap)
|
|
695 {
|
|
696 gcv.fill_style = FillOpaqueStippled;
|
|
697 gcv.stipple = ef->emacs_frame.top_toolbar_shadow_pixmap;
|
|
698 flags |= GCStipple | GCFillStyle;
|
|
699 }
|
|
700 FRAME_X_TOOLBAR_TOP_SHADOW_GC (f) = XtGetGC ((Widget) ef, flags, &gcv);
|
|
701
|
|
702 gcv.foreground = ef->emacs_frame.bottom_toolbar_shadow_pixel;
|
|
703 gcv.background = ef->core.background_pixel;
|
|
704 gcv.graphics_exposures = False;
|
|
705 flags = GCForeground | GCBackground | GCGraphicsExposures;
|
|
706 if (ef->emacs_frame.bottom_toolbar_shadow_pixmap)
|
|
707 {
|
|
708 gcv.fill_style = FillOpaqueStippled;
|
|
709 gcv.stipple = ef->emacs_frame.bottom_toolbar_shadow_pixmap;
|
|
710 flags |= GCStipple | GCFillStyle;
|
|
711 }
|
|
712 FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f) = XtGetGC ((Widget) ef, flags, &gcv);
|
|
713
|
|
714 #ifdef HAVE_XPM
|
|
715 FRAME_X_TOOLBAR_PIXMAP_BACKGROUND_GC (f) =
|
|
716 FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f);
|
|
717 #else
|
|
718 {
|
|
719 struct device *d = XDEVICE (f->device);
|
|
720 Display *dpy = DEVICE_X_DISPLAY (d);
|
|
721
|
|
722 gcv.background = WhitePixelOfScreen (DefaultScreenOfDisplay (dpy));
|
|
723 gcv.foreground = BlackPixelOfScreen (DefaultScreenOfDisplay (dpy));
|
|
724 gcv.graphics_exposures = False;
|
|
725 flags = GCForeground | GCBackground | GCGraphicsExposures;
|
|
726 FRAME_X_TOOLBAR_PIXMAP_BACKGROUND_GC (f) =
|
|
727 XtGetGC ((Widget) ef, flags, &gcv);
|
|
728 }
|
|
729 #endif
|
|
730 }
|
|
731
|
|
732 static void
|
|
733 x_release_frame_toolbar_gcs (struct frame *f)
|
|
734 {
|
|
735 Widget ew = (Widget) FRAME_X_TEXT_WIDGET (f);
|
|
736 XtReleaseGC (ew, FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f));
|
|
737 /* If compiled with XPM support, this is a pointer to the same GC as
|
|
738 FRAME_X_BLANK_BACKGROUND_GC so we need to make sure we don't
|
|
739 release it twice. */
|
|
740 #ifndef HAVE_XPM
|
|
741 XtReleaseGC (ew, FRAME_X_TOOLBAR_PIXMAP_BACKGROUND_GC (f));
|
|
742 #endif
|
|
743 XtReleaseGC (ew, FRAME_X_TOOLBAR_TOP_SHADOW_GC (f));
|
|
744 XtReleaseGC (ew, FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f));
|
|
745
|
|
746 /* Seg fault if we try and use these again. */
|
|
747 FRAME_X_TOOLBAR_BLANK_BACKGROUND_GC (f) = (GC) -1;
|
|
748 FRAME_X_TOOLBAR_PIXMAP_BACKGROUND_GC (f) = (GC) -1;
|
|
749 FRAME_X_TOOLBAR_TOP_SHADOW_GC (f) = (GC) -1;
|
|
750 FRAME_X_TOOLBAR_BOTTOM_SHADOW_GC (f) = (GC) -1;
|
|
751 }
|
|
752
|
|
753 static void
|
|
754 x_initialize_frame_toolbars (struct frame *f)
|
|
755 {
|
|
756 EmacsFrame ef = (EmacsFrame) FRAME_X_TEXT_WIDGET (f);
|
|
757
|
|
758 if (ef->emacs_frame.toolbar_shadow_thickness < MINIMUM_SHADOW_THICKNESS)
|
|
759 {
|
|
760 XtVaSetValues (FRAME_X_TEXT_WIDGET (f), XtNtoolBarShadowThickness,
|
|
761 MINIMUM_SHADOW_THICKNESS, 0);
|
|
762 }
|
|
763
|
|
764 x_initialize_frame_toolbar_gcs (f);
|
|
765 }
|
|
766
|
|
767 /* This only calls one function but we go ahead and create this in
|
|
768 case we ever do decide that we need to do more work. */
|
|
769 static void
|
|
770 x_free_frame_toolbars (struct frame *f)
|
|
771 {
|
|
772 x_release_frame_toolbar_gcs (f);
|
|
773 }
|
|
774
|
|
775
|
|
776 /************************************************************************/
|
|
777 /* initialization */
|
|
778 /************************************************************************/
|
|
779
|
|
780 void
|
|
781 console_type_create_toolbar_x (void)
|
|
782 {
|
|
783 CONSOLE_HAS_METHOD (x, output_frame_toolbars);
|
|
784 CONSOLE_HAS_METHOD (x, initialize_frame_toolbars);
|
|
785 CONSOLE_HAS_METHOD (x, free_frame_toolbars);
|
|
786 CONSOLE_HAS_METHOD (x, output_toolbar_button);
|
|
787 CONSOLE_HAS_METHOD (x, redraw_exposed_toolbars);
|
|
788 CONSOLE_HAS_METHOD (x, redraw_frame_toolbars);
|
|
789 CONSOLE_HAS_METHOD (x, toolbar_size_changed_in_frame);
|
|
790 CONSOLE_HAS_METHOD (x, toolbar_visible_p_changed_in_frame);
|
|
791 }
|