XEmacs 21.2.20 "Yoko".
[chise/xemacs-chise.git.1] / src / glyphs.h
1 /* Generic glyph data structures + display tables
2    Copyright (C) 1994 Board of Trustees, University of Illinois.
3    Copyright (C) 1995, 1996 Ben Wing
4
5 This file is part of XEmacs.
6
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
11
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING.  If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 /* Synched up with: Not in FSF. */
23
24 #ifndef _XEMACS_GLYPHS_H_
25 #define _XEMACS_GLYPHS_H_
26
27 #include "specifier.h"
28 #include "gui.h"
29
30 /************************************************************************/
31 /*                      Image Instantiators                             */
32 /************************************************************************/
33
34 struct image_instantiator_methods;
35
36 /* Remember the distinction between image instantiator formats and
37    image instance types.  Here's an approximate mapping:
38
39   image instantiator format     image instance type
40   -------------------------     -------------------
41   nothing                       nothing
42   string                        text
43   formatted-string              text
44   xbm                           mono-pixmap, color-pixmap, pointer
45   xpm                           color-pixmap, mono-pixmap, pointer
46   xface                         mono-pixmap, color-pixmap, pointer
47   gif                           color-pixmap
48   jpeg                          color-pixmap
49   png                           color-pixmap
50   tiff                          color-pixmap
51   bmp                           color-pixmap
52   cursor-font                   pointer
53   mswindows-resource            pointer
54   font                          pointer
55   subwindow                     subwindow
56   inherit                       mono-pixmap
57   autodetect                    mono-pixmap, color-pixmap, pointer, text
58   button                                widget
59   edit-field                    widget
60   combo -box                    widget
61   progress-gauge                widget
62   tab-control                   widget
63   tree-view                     widget
64   scrollbar                     widget
65   static                                widget
66 */
67
68 /* These are methods specific to a particular format of image instantiator
69    (e.g. xpm, string, etc.). */
70
71 typedef struct ii_keyword_entry ii_keyword_entry;
72 struct ii_keyword_entry
73 {
74   Lisp_Object keyword;
75   void (*validate) (Lisp_Object data);
76   int multiple_p;
77 };
78
79 typedef struct
80 {
81   Dynarr_declare (ii_keyword_entry);
82 } ii_keyword_entry_dynarr;
83
84 extern const struct struct_description iim_description;
85
86 struct image_instantiator_methods
87 {
88   Lisp_Object symbol;
89
90   Lisp_Object device;           /* sometimes used */
91
92   ii_keyword_entry_dynarr *keywords;
93   /* consoles this ii is supported on */
94   console_type_entry_dynarr *consoles;
95   /* Implementation specific methods: */
96
97   /* Validate method: Given an instantiator vector, signal an error if
98      it's invalid for this image-instantiator format.  Note that this
99      validation only occurs after all the keyword-specific validation
100      has already been performed.  This is chiefly useful for making
101      sure that certain required keywords are present. */
102   void (*validate_method) (Lisp_Object instantiator);
103
104   /* Normalize method: Given an instantiator, convert it to the form
105      that should be used in a glyph, for devices of type CONSOLE_TYPE.
106      Signal an error if conversion fails. */
107   Lisp_Object (*normalize_method) (Lisp_Object instantiator,
108                                    Lisp_Object console_type);
109
110   /* Possible-dest-types method: Return a mask indicating what dest types
111      are compatible with this format. */
112   int (*possible_dest_types_method) (void);
113
114   /* Instantiate method: Given an instantiator and a partially
115      filled-in image instance, complete the filling-in.  Return
116      non-zero if the instantiation succeeds, 0 if it fails.
117      This must be present. */
118   void (*instantiate_method) (Lisp_Object image_instance,
119                               Lisp_Object instantiator,
120                               Lisp_Object pointer_fg,
121                               Lisp_Object pointer_bg,
122                               int dest_mask,
123                               Lisp_Object domain);
124   /* Property method: Given an image instance, return device specific
125      properties. */
126   Lisp_Object (*property_method) (Lisp_Object image_instance,
127                                   Lisp_Object property);
128   /* Set-property method: Given an image instance, set device specific
129      properties. */
130   Lisp_Object (*set_property_method) (Lisp_Object image_instance,
131                                       Lisp_Object property,
132                                       Lisp_Object val);
133 };
134
135 /***** Calling an image-instantiator method *****/
136
137 #define HAS_IIFORMAT_METH_P(mstruc, m) (((mstruc)->m##_method) != 0)
138 #define IIFORMAT_METH(mstruc, m, args) (((mstruc)->m##_method) args)
139
140 /* Call a void-returning specifier method, if it exists */
141 #define MAYBE_IIFORMAT_METH(mstruc, m, args)                    \
142 do {                                                            \
143   struct image_instantiator_methods *MIM_mstruc = (mstruc);     \
144   if (MIM_mstruc && HAS_IIFORMAT_METH_P (MIM_mstruc, m))        \
145     IIFORMAT_METH (MIM_mstruc, m, args);                        \
146 } while (0)
147
148 #define MAYBE_IIFORMAT_DEVMETH(device, mstruc, m, args) \
149 do {                                                    \
150   struct image_instantiator_methods *MID_mstruc =       \
151     decode_ii_device (device, mstruc);                  \
152   if (MID_mstruc)                                       \
153     MAYBE_IIFORMAT_METH(MID_mstruc, m, args);           \
154 } while (0)
155
156
157 /* Call a specifier method, if it exists; otherwise return
158    the specified value */
159
160 #define IIFORMAT_METH_OR_GIVEN(mstruc, m, args, given)  \
161   (HAS_IIFORMAT_METH_P (mstruc, m) ?                    \
162    IIFORMAT_METH (mstruc, m, args) : (given))
163
164 /***** Defining new image-instantiator types *****/
165
166 #define DECLARE_IMAGE_INSTANTIATOR_FORMAT(format)               \
167 extern struct image_instantiator_methods *format##_image_instantiator_methods
168
169 #define DEFINE_IMAGE_INSTANTIATOR_FORMAT(format)                \
170 struct image_instantiator_methods *format##_image_instantiator_methods
171
172 #define INITIALIZE_IMAGE_INSTANTIATOR_FORMAT_NO_SYM(format, obj_name)   \
173 do {                                                            \
174   format##_image_instantiator_methods =                         \
175     xnew_and_zero (struct image_instantiator_methods);          \
176   format##_image_instantiator_methods->symbol = Q##format;      \
177   format##_image_instantiator_methods->device = Qnil;           \
178   format##_image_instantiator_methods->keywords =               \
179     Dynarr_new (ii_keyword_entry);                              \
180   format##_image_instantiator_methods->consoles =               \
181     Dynarr_new (console_type_entry);                            \
182   add_entry_to_image_instantiator_format_list                   \
183     (Q##format, format##_image_instantiator_methods);           \
184   dumpstruct (&format##_image_instantiator_methods,             \
185               &iim_description);                                \
186 } while (0)
187
188 #define INITIALIZE_IMAGE_INSTANTIATOR_FORMAT(format, obj_name)  \
189 do {                                                            \
190   defsymbol (&Q##format, obj_name);                             \
191   INITIALIZE_IMAGE_INSTANTIATOR_FORMAT_NO_SYM(format, obj_name);\
192 } while (0)
193
194 /* Declare that image-instantiator format FORMAT has method M; used in
195    initialization routines */
196 #define IIFORMAT_HAS_METHOD(format, m) \
197   (format##_image_instantiator_methods->m##_method = format##_##m)
198
199 #define IIFORMAT_HAS_SHARED_METHOD(format, m, type) \
200   (format##_image_instantiator_methods->m##_method = type##_##m)
201
202 /* Declare that KEYW is a valid keyword for image-instantiator format
203    FORMAT.  VALIDATE_FUN if a function that returns whether the data
204    is valid.  The keyword may not appear more than once. */
205 #define IIFORMAT_VALID_KEYWORD(format, keyw, validate_fun)      \
206   do {                                                          \
207     struct ii_keyword_entry entry;                              \
208                                                                 \
209     entry.keyword = keyw;                                       \
210     entry.validate = validate_fun;                              \
211     entry.multiple_p = 0;                                       \
212     Dynarr_add (format##_image_instantiator_methods->keywords,  \
213                 entry);                                         \
214   } while (0)
215
216 /* Same as IIFORMAT_VALID_KEYWORD except that the keyword may
217    appear multiple times. */
218 #define IIFORMAT_VALID_MULTI_KEYWORD(format, keyword, validate_fun)     \
219   do {                                                                  \
220     struct ii_keyword_entry entry;                                      \
221                                                                         \
222     entry.keyword = keyword;                                            \
223     entry.validate = validate_fun;                                      \
224     entry.multiple_p = 1;                                               \
225     Dynarr_add (format##_image_instantiator_methods->keywords,          \
226                 entry);                                                 \
227   } while (0)
228
229 /* Declare that image-instantiator format FORMAT is supported on 
230    CONSOLE type. */
231 #define IIFORMAT_VALID_CONSOLE(console, format)         \
232   do {                                                          \
233     struct console_type_entry entry;                            \
234                                                                 \
235     entry.symbol = Q##console;                                  \
236     entry.meths = console##_console_methods;                    \
237     Dynarr_add (format##_image_instantiator_methods->consoles,  \
238                 entry);                                         \
239   } while (0)
240
241 #define DEFINE_DEVICE_IIFORMAT(type, format)\
242 DECLARE_IMAGE_INSTANTIATOR_FORMAT(format);              \
243 struct image_instantiator_methods *type##_##format##_image_instantiator_methods
244
245 #define INITIALIZE_DEVICE_IIFORMAT(type, format)                        \
246 do {                                                                    \
247   type##_##format##_image_instantiator_methods =                        \
248     xnew_and_zero (struct image_instantiator_methods);                  \
249   type##_##format##_image_instantiator_methods->symbol = Q##format;     \
250   type##_##format##_image_instantiator_methods->device = Q##type;       \
251   type##_##format##_image_instantiator_methods->keywords =              \
252     Dynarr_new (ii_keyword_entry);                                      \
253   add_entry_to_device_ii_format_list                                    \
254     (Q##type, Q##format, type##_##format##_image_instantiator_methods); \
255   IIFORMAT_VALID_CONSOLE(type,format);                                  \
256   dumpstruct (&type##_##format##_image_instantiator_methods,            \
257               &iim_description);                                        \
258 } while (0)
259
260 /* Declare that image-instantiator format FORMAT has method M; used in
261    initialization routines */
262 #define IIFORMAT_HAS_DEVMETHOD(type, format, m) \
263   (type##_##format##_image_instantiator_methods->m##_method = type##_##format##_##m)
264 #define IIFORMAT_HAS_SHARED_DEVMETHOD(type, format, m, fromformat) \
265   (type##_##format##_image_instantiator_methods->m##_method = type##_##fromformat##_##m)
266
267 struct image_instantiator_methods *
268 decode_device_ii_format (Lisp_Object device, Lisp_Object format,
269                          Error_behavior errb);
270 struct image_instantiator_methods *
271 decode_image_instantiator_format (Lisp_Object format, Error_behavior errb);
272
273 void add_entry_to_image_instantiator_format_list (Lisp_Object symbol,
274                         struct image_instantiator_methods *meths);
275 void add_entry_to_device_ii_format_list (Lisp_Object device, Lisp_Object symbol,
276                         struct image_instantiator_methods *meths);
277 Lisp_Object find_keyword_in_vector (Lisp_Object vector,
278                                     Lisp_Object keyword);
279 Lisp_Object find_keyword_in_vector_or_given (Lisp_Object vector,
280                                              Lisp_Object keyword,
281                                              Lisp_Object default_);
282 Lisp_Object simple_image_type_normalize (Lisp_Object inst,
283                                          Lisp_Object console_type,
284                                          Lisp_Object image_type_tag);
285 Lisp_Object potential_pixmap_file_instantiator (Lisp_Object instantiator,
286                                                 Lisp_Object file_keyword,
287                                                 Lisp_Object data_keyword,
288                                                 Lisp_Object console_type);
289 void check_valid_string (Lisp_Object data);
290 void check_valid_int (Lisp_Object data);
291 void check_valid_face (Lisp_Object data);
292 void check_valid_vector (Lisp_Object data);
293 void check_valid_item_list_1 (Lisp_Object items);
294
295 void initialize_subwindow_image_instance (struct Lisp_Image_Instance*);
296 void subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
297                             Lisp_Object pointer_fg, Lisp_Object pointer_bg,
298                             int dest_mask, Lisp_Object domain);
299 void widget_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
300                            Lisp_Object pointer_fg, Lisp_Object pointer_bg,
301                            int dest_mask, Lisp_Object domain, int default_textheight,
302                            int default_pixheight, int default_textwidth);
303
304 DECLARE_DOESNT_RETURN (incompatible_image_types (Lisp_Object instantiator,
305                                                  int given_dest_mask,
306                                                  int desired_dest_mask));
307 DECLARE_DOESNT_RETURN (signal_image_error (CONST char *, Lisp_Object));
308 DECLARE_DOESNT_RETURN (signal_image_error_2 (CONST char *, Lisp_Object, Lisp_Object));
309
310 /************************************************************************/
311 /*                      Image Specifier Object                          */
312 /************************************************************************/
313
314 DECLARE_SPECIFIER_TYPE (image);
315 #define XIMAGE_SPECIFIER(x) XSPECIFIER_TYPE (x, image)
316 #define XSETIMAGE_SPECIFIER(x, p) XSETSPECIFIER_TYPE (x, p, image)
317 #define IMAGE_SPECIFIERP(x) SPECIFIER_TYPEP (x, image)
318 #define CHECK_IMAGE_SPECIFIER(x) CHECK_SPECIFIER_TYPE (x, image)
319 #define CONCHECK_IMAGE_SPECIFIER(x) CONCHECK_SPECIFIER_TYPE (x, image)
320
321 void set_image_attached_to (Lisp_Object obj, Lisp_Object face_or_glyph,
322                             Lisp_Object property);
323
324 struct image_specifier
325 {
326   int allowed;
327   Lisp_Object attachee;         /* face or glyph this is attached to, or nil */
328   Lisp_Object attachee_property;/* property of that face or glyph */
329 };
330
331 #define IMAGE_SPECIFIER_DATA(g) (SPECIFIER_TYPE_DATA (g, image))
332 #define IMAGE_SPECIFIER_ALLOWED(g) (IMAGE_SPECIFIER_DATA (g)->allowed)
333 #define IMAGE_SPECIFIER_ATTACHEE(g) (IMAGE_SPECIFIER_DATA (g)->attachee)
334 #define IMAGE_SPECIFIER_ATTACHEE_PROPERTY(g) \
335   (IMAGE_SPECIFIER_DATA (g)->attachee_property)
336
337 #define XIMAGE_SPECIFIER_ALLOWED(g) \
338   IMAGE_SPECIFIER_ALLOWED (XIMAGE_SPECIFIER (g))
339
340 /************************************************************************/
341 /*                      Image Instance Object                           */
342 /************************************************************************/
343
344 DECLARE_LRECORD (image_instance, struct Lisp_Image_Instance);
345 #define XIMAGE_INSTANCE(x) \
346   XRECORD (x, image_instance, struct Lisp_Image_Instance)
347 #define XSETIMAGE_INSTANCE(x, p) XSETRECORD (x, p, image_instance)
348 #define IMAGE_INSTANCEP(x) RECORDP (x, image_instance)
349 #define CHECK_IMAGE_INSTANCE(x) CHECK_RECORD (x, image_instance)
350 #define CONCHECK_IMAGE_INSTANCE(x) CONCHECK_RECORD (x, image_instance)
351
352 enum image_instance_type
353 {
354   IMAGE_UNKNOWN,
355   IMAGE_NOTHING,
356   IMAGE_TEXT,
357   IMAGE_MONO_PIXMAP,
358   IMAGE_COLOR_PIXMAP,
359   IMAGE_POINTER,
360   IMAGE_SUBWINDOW,
361   IMAGE_WIDGET,
362   IMAGE_LAYOUT
363 };
364
365 #define IMAGE_NOTHING_MASK (1 << 0)
366 #define IMAGE_TEXT_MASK (1 << 1)
367 #define IMAGE_MONO_PIXMAP_MASK (1 << 2)
368 #define IMAGE_COLOR_PIXMAP_MASK (1 << 3)
369 #define IMAGE_POINTER_MASK (1 << 4)
370 #define IMAGE_SUBWINDOW_MASK (1 << 5)
371 #define IMAGE_WIDGET_MASK (1 << 6)
372 #define IMAGE_LAYOUT_MASK (1 << 7)
373
374 #define IMAGE_INSTANCE_TYPE_P(ii, type) \
375 (IMAGE_INSTANCEP (ii) && XIMAGE_INSTANCE_TYPE (ii) == type)
376
377 #define NOTHING_IMAGE_INSTANCEP(ii) \
378      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_NOTHING)
379 #define TEXT_IMAGE_INSTANCEP(ii) \
380      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_TEXT)
381 #define MONO_PIXMAP_IMAGE_INSTANCEP(ii) \
382      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_MONO_PIXMAP)
383 #define COLOR_PIXMAP_IMAGE_INSTANCEP(ii) \
384      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_COLOR_PIXMAP)
385 #define POINTER_IMAGE_INSTANCEP(ii) \
386      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_POINTER)
387 #define SUBWINDOW_IMAGE_INSTANCEP(ii) \
388      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_SUBWINDOW)
389 #define WIDGET_IMAGE_INSTANCEP(ii) \
390      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_WIDGET)
391 #define LAYOUT_IMAGE_INSTANCEP(ii) \
392      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_LAYOUT)
393
394 #define CHECK_NOTHING_IMAGE_INSTANCE(x) do {            \
395   CHECK_IMAGE_INSTANCE (x);                             \
396   if (!NOTHING_IMAGE_INSTANCEP (x))                             \
397     x = wrong_type_argument (Qnothing_image_instance_p, (x));   \
398 } while (0)
399
400 #define CHECK_TEXT_IMAGE_INSTANCE(x) do {               \
401   CHECK_IMAGE_INSTANCE (x);                             \
402   if (!TEXT_IMAGE_INSTANCEP (x))                                \
403     x = wrong_type_argument (Qtext_image_instance_p, (x));      \
404 } while (0)
405
406 #define CHECK_MONO_PIXMAP_IMAGE_INSTANCE(x) do {                        \
407   CHECK_IMAGE_INSTANCE (x);                                             \
408   if (!MONO_PIXMAP_IMAGE_INSTANCEP (x))                                 \
409     x = wrong_type_argument (Qmono_pixmap_image_instance_p, (x));       \
410 } while (0)
411
412 #define CHECK_COLOR_PIXMAP_IMAGE_INSTANCE(x) do {               \
413   CHECK_IMAGE_INSTANCE (x);                                     \
414   if (!COLOR_PIXMAP_IMAGE_INSTANCEP (x))                                \
415     x = wrong_type_argument (Qcolor_pixmap_image_instance_p, (x));      \
416 } while (0)
417
418 #define CHECK_POINTER_IMAGE_INSTANCE(x) do {            \
419   CHECK_IMAGE_INSTANCE (x);                             \
420   if (!POINTER_IMAGE_INSTANCEP (x))                             \
421     x = wrong_type_argument (Qpointer_image_instance_p, (x));   \
422 } while (0)
423
424 #define CHECK_SUBWINDOW_IMAGE_INSTANCE(x) do {          \
425   CHECK_IMAGE_INSTANCE (x);                                     \
426   if (!SUBWINDOW_IMAGE_INSTANCEP (x)                            \
427       && !WIDGET_IMAGE_INSTANCEP (x))                           \
428     x = wrong_type_argument (Qsubwindow_image_instance_p, (x)); \
429 } while (0)
430
431 #define CHECK_WIDGET_IMAGE_INSTANCE(x) do {             \
432   CHECK_IMAGE_INSTANCE (x);                             \
433   if (!WIDGET_IMAGE_INSTANCEP (x))                              \
434     x = wrong_type_argument (Qwidget_image_instance_p, (x));    \
435 } while (0)
436
437 #define CHECK_LAYOUT_IMAGE_INSTANCE(x) do {             \
438   CHECK_IMAGE_INSTANCE (x);                             \
439   if (!LAYOUT_IMAGE_INSTANCEP (x))                              \
440     x = wrong_type_argument (Qlayout_image_instance_p, (x));    \
441 } while (0)
442
443 struct Lisp_Image_Instance
444 {
445   struct lcrecord_header header;
446   Lisp_Object device;
447   Lisp_Object name;
448   enum image_instance_type type;
449   int x_offset, y_offset;       /* for layout purposes */
450   unsigned int dirty : 1;
451   union
452   {
453     struct
454     {
455       Lisp_Object string;
456     } text;
457     struct
458     {
459       int width, height, depth;
460       int slice, maxslice, timeout;
461       Lisp_Object hotspot_x, hotspot_y; /* integer or Qnil */
462       Lisp_Object filename;      /* string or Qnil */
463       Lisp_Object mask_filename; /* string or Qnil */
464       Lisp_Object fg, bg; /* foreground and background colors,
465                              if this is a colorized mono-pixmap
466                              or a pointer */
467       Lisp_Object auxdata;    /* list or Qnil: any additional data
468                                  to be seen from lisp */
469       void* mask;               /* mask that can be seen from all windowing systems */
470     } pixmap; /* used for pointers as well */
471     struct
472     {
473       Lisp_Object frame;
474       unsigned int width, height;
475       void* subwindow;          /* specific devices can use this as necessary */
476       unsigned int being_displayed : 1; /* used to detect when needs to be unmapped */
477       union
478       {
479         struct
480         {
481           Lisp_Object face; /* foreground and background colors */
482           Lisp_Object type;
483           Lisp_Object props;    /* properties */
484           Lisp_Object gui_item; /* a list of gui_items */
485         } widget;               /* widgets are subwindows */
486         struct
487         {
488           Lisp_Object children; /* managed children */
489           Lisp_Object border;   /* Style of enclosing border or text. */
490         } layout;
491       } s;
492     } subwindow;
493   } u;
494
495   /* console-type- and image-type-specific data */
496   void *data;
497 };
498
499 #define IMAGE_INSTANCE_DEVICE(i) ((i)->device)
500 #define IMAGE_INSTANCE_NAME(i) ((i)->name)
501 #define IMAGE_INSTANCE_TYPE(i) ((i)->type)
502 #define IMAGE_INSTANCE_XOFFSET(i) ((i)->x_offset)
503 #define IMAGE_INSTANCE_YOFFSET(i) ((i)->y_offset)
504 #define IMAGE_INSTANCE_PIXMAP_TYPE_P(i)                                 \
505  ((IMAGE_INSTANCE_TYPE (i) == IMAGE_MONO_PIXMAP)                        \
506   || (IMAGE_INSTANCE_TYPE (i) == IMAGE_COLOR_PIXMAP))
507 #define IMAGE_INSTANCE_DIRTYP(i) ((i)->dirty)
508
509 #define IMAGE_INSTANCE_TEXT_STRING(i) ((i)->u.text.string)
510
511 #define IMAGE_INSTANCE_PIXMAP_WIDTH(i) ((i)->u.pixmap.width)
512 #define IMAGE_INSTANCE_PIXMAP_HEIGHT(i) ((i)->u.pixmap.height)
513 #define IMAGE_INSTANCE_PIXMAP_DEPTH(i) ((i)->u.pixmap.depth)
514 #define IMAGE_INSTANCE_PIXMAP_FILENAME(i) ((i)->u.pixmap.filename)
515 #define IMAGE_INSTANCE_PIXMAP_MASK_FILENAME(i) ((i)->u.pixmap.mask_filename)
516 #define IMAGE_INSTANCE_PIXMAP_HOTSPOT_X(i) ((i)->u.pixmap.hotspot_x)
517 #define IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y(i) ((i)->u.pixmap.hotspot_y)
518 #define IMAGE_INSTANCE_PIXMAP_FG(i) ((i)->u.pixmap.fg)
519 #define IMAGE_INSTANCE_PIXMAP_BG(i) ((i)->u.pixmap.bg)
520 #define IMAGE_INSTANCE_PIXMAP_AUXDATA(i) ((i)->u.pixmap.auxdata)
521 #define IMAGE_INSTANCE_PIXMAP_MASK(i) ((i)->u.pixmap.mask)
522 #define IMAGE_INSTANCE_PIXMAP_SLICE(i) ((i)->u.pixmap.slice)
523 #define IMAGE_INSTANCE_PIXMAP_MAXSLICE(i) ((i)->u.pixmap.maxslice)
524 #define IMAGE_INSTANCE_PIXMAP_TIMEOUT(i) ((i)->u.pixmap.timeout)
525
526 #define IMAGE_INSTANCE_SUBWINDOW_WIDTH(i) ((i)->u.subwindow.width)
527 #define IMAGE_INSTANCE_SUBWINDOW_HEIGHT(i) ((i)->u.subwindow.height)
528 #define IMAGE_INSTANCE_SUBWINDOW_ID(i) ((i)->u.subwindow.subwindow)
529 #define IMAGE_INSTANCE_SUBWINDOW_FRAME(i) ((i)->u.subwindow.frame)
530 #define IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP(i) \
531 ((i)->u.subwindow.being_displayed)
532
533 #define IMAGE_INSTANCE_WIDGET_WIDTH(i) \
534   IMAGE_INSTANCE_SUBWINDOW_WIDTH(i)
535 #define IMAGE_INSTANCE_WIDGET_HEIGHT(i) \
536   IMAGE_INSTANCE_SUBWINDOW_HEIGHT(i)
537 #define IMAGE_INSTANCE_WIDGET_TYPE(i) ((i)->u.subwindow.s.widget.type)
538 #define IMAGE_INSTANCE_WIDGET_PROPS(i) ((i)->u.subwindow.s.widget.props)
539 #define IMAGE_INSTANCE_WIDGET_FACE(i) ((i)->u.subwindow.s.widget.face)
540 #define IMAGE_INSTANCE_WIDGET_ITEMS(i) ((i)->u.subwindow.s.widget.gui_item)
541 #define IMAGE_INSTANCE_WIDGET_ITEM(i) \
542 (CONSP (IMAGE_INSTANCE_WIDGET_ITEMS (i)) ? \
543 XCAR (IMAGE_INSTANCE_WIDGET_ITEMS (i)) : \
544   IMAGE_INSTANCE_WIDGET_ITEMS (i))
545 #define IMAGE_INSTANCE_WIDGET_TEXT(i) XGUI_ITEM (IMAGE_INSTANCE_WIDGET_ITEM (i))->name
546
547 #define IMAGE_INSTANCE_LAYOUT_CHILDREN(i) ((i)->u.subwindow.s.layout.children)
548 #define IMAGE_INSTANCE_LAYOUT_BORDER(i) ((i)->u.subwindow.s.layout.border)
549
550 #define XIMAGE_INSTANCE_DEVICE(i) \
551   IMAGE_INSTANCE_DEVICE (XIMAGE_INSTANCE (i))
552 #define XIMAGE_INSTANCE_NAME(i) \
553   IMAGE_INSTANCE_NAME (XIMAGE_INSTANCE (i))
554 #define XIMAGE_INSTANCE_TYPE(i) \
555   IMAGE_INSTANCE_TYPE (XIMAGE_INSTANCE (i))
556 #define XIMAGE_INSTANCE_XOFFSET(i) \
557   IMAGE_INSTANCE_XOFFSET (XIMAGE_INSTANCE (i))
558 #define XIMAGE_INSTANCE_YOFFSET(i) \
559   IMAGE_INSTANCE_YOFFSET (XIMAGE_INSTANCE (i))
560 #define XIMAGE_INSTANCE_DIRTYP(i) \
561   IMAGE_INSTANCE_DIRTYP (XIMAGE_INSTANCE (i))
562
563 #define XIMAGE_INSTANCE_TEXT_STRING(i) \
564   IMAGE_INSTANCE_TEXT_STRING (XIMAGE_INSTANCE (i))
565
566 #define XIMAGE_INSTANCE_PIXMAP_WIDTH(i) \
567   IMAGE_INSTANCE_PIXMAP_WIDTH (XIMAGE_INSTANCE (i))
568 #define XIMAGE_INSTANCE_PIXMAP_HEIGHT(i) \
569   IMAGE_INSTANCE_PIXMAP_HEIGHT (XIMAGE_INSTANCE (i))
570 #define XIMAGE_INSTANCE_PIXMAP_DEPTH(i) \
571   IMAGE_INSTANCE_PIXMAP_DEPTH (XIMAGE_INSTANCE (i))
572 #define XIMAGE_INSTANCE_PIXMAP_FILENAME(i) \
573   IMAGE_INSTANCE_PIXMAP_FILENAME (XIMAGE_INSTANCE (i))
574 #define XIMAGE_INSTANCE_PIXMAP_MASK_FILENAME(i) \
575   IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (XIMAGE_INSTANCE (i))
576 #define XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X(i) \
577   IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (XIMAGE_INSTANCE (i))
578 #define XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y(i) \
579   IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (XIMAGE_INSTANCE (i))
580 #define XIMAGE_INSTANCE_PIXMAP_FG(i) \
581   IMAGE_INSTANCE_PIXMAP_FG (XIMAGE_INSTANCE (i))
582 #define XIMAGE_INSTANCE_PIXMAP_BG(i) \
583   IMAGE_INSTANCE_PIXMAP_BG (XIMAGE_INSTANCE (i))
584 #define XIMAGE_INSTANCE_PIXMAP_MASK(i) \
585   IMAGE_INSTANCE_PIXMAP_MASK (XIMAGE_INSTANCE (i))
586 #define XIMAGE_INSTANCE_PIXMAP_SLICE(i) \
587   IMAGE_INSTANCE_PIXMAP_SLICE (XIMAGE_INSTANCE (i))
588 #define XIMAGE_INSTANCE_PIXMAP_MAXSLICE(i) \
589   IMAGE_INSTANCE_PIXMAP_MAXSLICE (XIMAGE_INSTANCE (i))
590 #define XIMAGE_INSTANCE_PIXMAP_TIMEOUT(i) \
591   IMAGE_INSTANCE_PIXMAP_TIMEOUT (XIMAGE_INSTANCE (i))
592
593 #define XIMAGE_INSTANCE_WIDGET_WIDTH(i) \
594   IMAGE_INSTANCE_WIDGET_WIDTH (XIMAGE_INSTANCE (i))
595 #define XIMAGE_INSTANCE_WIDGET_HEIGHT(i) \
596   IMAGE_INSTANCE_WIDGET_HEIGHT (XIMAGE_INSTANCE (i))
597 #define XIMAGE_INSTANCE_WIDGET_TYPE(i) \
598   IMAGE_INSTANCE_WIDGET_TYPE (XIMAGE_INSTANCE (i))
599 #define XIMAGE_INSTANCE_WIDGET_PROPS(i) \
600   IMAGE_INSTANCE_WIDGET_PROPS (XIMAGE_INSTANCE (i))
601 #define XIMAGE_INSTANCE_WIDGET_FACE(i) \
602   IMAGE_INSTANCE_WIDGET_FACE (XIMAGE_INSTANCE (i))
603 #define XIMAGE_INSTANCE_WIDGET_ITEM(i) \
604   IMAGE_INSTANCE_WIDGET_ITEM (XIMAGE_INSTANCE (i))
605 #define XIMAGE_INSTANCE_WIDGET_ITEMS(i) \
606   IMAGE_INSTANCE_WIDGET_ITEMS (XIMAGE_INSTANCE (i))
607 #define XIMAGE_INSTANCE_WIDGET_TEXT(i) \
608   IMAGE_INSTANCE_WIDGET_TEXT (XIMAGE_INSTANCE (i))
609
610 #define XIMAGE_INSTANCE_LAYOUT_CHILDREN(i) \
611   IMAGE_INSTANCE_LAYOUT_CHILDREN (XIMAGE_INSTANCE (i))
612 #define XIMAGE_INSTANCE_LAYOUT_BORDER(i) \
613   IMAGE_INSTANCE_LAYOUT_BORDER (XIMAGE_INSTANCE (i))
614
615 #define XIMAGE_INSTANCE_SUBWINDOW_WIDTH(i) \
616   IMAGE_INSTANCE_SUBWINDOW_WIDTH (XIMAGE_INSTANCE (i))
617 #define XIMAGE_INSTANCE_SUBWINDOW_HEIGHT(i) \
618   IMAGE_INSTANCE_SUBWINDOW_HEIGHT (XIMAGE_INSTANCE (i))
619 #define XIMAGE_INSTANCE_SUBWINDOW_ID(i) \
620   IMAGE_INSTANCE_SUBWINDOW_ID (XIMAGE_INSTANCE (i))
621 #define XIMAGE_INSTANCE_SUBWINDOW_FRAME(i) \
622   IMAGE_INSTANCE_SUBWINDOW_FRAME (XIMAGE_INSTANCE (i))
623 #define XIMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP(i) \
624   IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (XIMAGE_INSTANCE (i))
625
626 #define MARK_IMAGE_INSTANCE_CHANGED(i) \
627   (IMAGE_INSTANCE_DIRTYP (i) = 1);
628
629 #ifdef HAVE_XPM
630 Lisp_Object evaluate_xpm_color_symbols (void);
631 Lisp_Object pixmap_to_lisp_data (Lisp_Object name, int ok_if_data_invalid);
632 #endif /* HAVE_XPM */
633 #ifdef HAVE_WINDOW_SYSTEM
634 Lisp_Object bitmap_to_lisp_data (Lisp_Object name, int *xhot, int *yhot,
635                                  int ok_if_data_invalid);
636 int read_bitmap_data_from_file (CONST char *filename, unsigned int *width,
637                                 unsigned int *height, unsigned char **datap,
638                                 int *x_hot, int *y_hot);
639 Lisp_Object xbm_mask_file_munging (Lisp_Object alist, Lisp_Object file,
640                                    Lisp_Object mask_file,
641                                    Lisp_Object console_type);
642 #endif
643
644 /************************************************************************/
645 /*                              Glyph Object                            */
646 /************************************************************************/
647
648 enum glyph_type
649 {
650   GLYPH_UNKNOWN,
651   GLYPH_BUFFER,
652   GLYPH_POINTER,
653   GLYPH_ICON
654 };
655
656 struct Lisp_Glyph
657 {
658   struct lcrecord_header header;
659
660   enum glyph_type type;
661
662   /* specifiers: */
663   Lisp_Object image;            /* the actual image */
664   Lisp_Object contrib_p;        /* whether to figure into line height */
665   Lisp_Object baseline;         /* percent above baseline */
666
667   Lisp_Object face;             /* if non-nil, face to use when displaying */
668   
669   Lisp_Object plist;
670   void (*after_change) (Lisp_Object glyph, Lisp_Object property,
671                         Lisp_Object locale);
672
673   unsigned int dirty : 1;       /* So that we can selectively
674                                    redisplay changed glyphs. */
675 };
676
677 DECLARE_LRECORD (glyph, struct Lisp_Glyph);
678 #define XGLYPH(x) XRECORD (x, glyph, struct Lisp_Glyph)
679 #define XSETGLYPH(x, p) XSETRECORD (x, p, glyph)
680 #define GLYPHP(x) RECORDP (x, glyph)
681 #define CHECK_GLYPH(x) CHECK_RECORD (x, glyph)
682 #define CONCHECK_GLYPH(x) CONCHECK_RECORD (x, glyph)
683
684 #define CHECK_BUFFER_GLYPH(x) do {                      \
685   CHECK_GLYPH (x);                                      \
686   if (XGLYPH (x)->type != GLYPH_BUFFER)                 \
687     x = wrong_type_argument (Qbuffer_glyph_p, (x));     \
688 } while (0)
689
690 #define CHECK_POINTER_GLYPH(x) do {                     \
691   CHECK_GLYPH (x);                                      \
692   if (XGLYPH (x)->type != GLYPH_POINTER)                \
693     x = wrong_type_argument (Qpointer_glyph_p, (x));    \
694 } while (0)
695
696 #define CHECK_ICON_GLYPH(x) do {                        \
697   CHECK_GLYPH (x);                                      \
698   if (XGLYPH (x)->type != GLYPH_ICON)                   \
699     x = wrong_type_argument (Qicon_glyph_p, (x));       \
700 } while (0)
701
702 #define GLYPH_TYPE(g) ((g)->type)
703 #define GLYPH_IMAGE(g) ((g)->image)
704 #define GLYPH_CONTRIB_P(g) ((g)->contrib_p)
705 #define GLYPH_BASELINE(g) ((g)->baseline)
706 #define GLYPH_FACE(g) ((g)->face)
707 #define GLYPH_DIRTYP(g) ((g)->dirty)
708
709 #define XGLYPH_TYPE(g) GLYPH_TYPE (XGLYPH (g))
710 #define XGLYPH_IMAGE(g) GLYPH_IMAGE (XGLYPH (g))
711 #define XGLYPH_CONTRIB_P(g) GLYPH_CONTRIB_P (XGLYPH (g))
712 #define XGLYPH_BASELINE(g) GLYPH_BASELINE (XGLYPH (g))
713 #define XGLYPH_FACE(g) GLYPH_FACE (XGLYPH (g))
714 #define XGLYPH_DIRTYP(g) GLYPH_DIRTYP (XGLYPH (g))
715
716 #define MARK_GLYPH_CHANGED(g) (GLYPH_DIRTYP (g) = 1);
717
718 extern Lisp_Object Qxpm, Qxface, Qetched_in, Qetched_out, Qbevel_in, Qbevel_out;
719 extern Lisp_Object Q_data, Q_file, Q_color_symbols, Qconst_glyph_variable;
720 extern Lisp_Object Qxbm, Qedit_field, Qgroup, Qlabel, Qcombo_box, Qscrollbar;
721 extern Lisp_Object Qtree_view, Qtab_control, Qprogress_gauge, Q_border;
722 extern Lisp_Object Q_mask_file, Q_mask_data, Q_hotspot_x, Q_hotspot_y;
723 extern Lisp_Object Q_foreground, Q_background, Q_face, Q_descriptor, Q_group;
724 extern Lisp_Object Q_width, Q_height, Q_pixel_width, Q_pixel_height, Q_text;
725 extern Lisp_Object Q_items, Q_properties, Q_image, Q_percent, Qimage_conversion_error;
726 extern Lisp_Object Q_orientation;
727 extern Lisp_Object Vcontinuation_glyph, Vcontrol_arrow_glyph, Vhscroll_glyph;
728 extern Lisp_Object Vinvisible_text_glyph, Voctal_escape_glyph, Vtruncation_glyph;
729 extern Lisp_Object Vxemacs_logo;
730
731 unsigned short glyph_width (Lisp_Object glyph, Lisp_Object frame_face,
732                             face_index window_findex,
733                             Lisp_Object window);
734 unsigned short glyph_ascent (Lisp_Object glyph,  Lisp_Object frame_face,
735                              face_index window_findex,
736                              Lisp_Object window);
737 unsigned short glyph_descent (Lisp_Object glyph,
738                               Lisp_Object frame_face,
739                               face_index window_findex,
740                               Lisp_Object window);
741 unsigned short glyph_height (Lisp_Object glyph,  Lisp_Object frame_face,
742                              face_index window_findex,
743                              Lisp_Object window);
744 Lisp_Object glyph_baseline (Lisp_Object glyph, Lisp_Object domain);
745 Lisp_Object glyph_face (Lisp_Object glyph, Lisp_Object domain);
746 int glyph_contrib_p (Lisp_Object glyph, Lisp_Object domain);
747 Lisp_Object glyph_image_instance (Lisp_Object glyph,
748                                   Lisp_Object domain,
749                                   Error_behavior errb, int no_quit);
750 void file_or_data_must_be_present (Lisp_Object instantiator);
751 void data_must_be_present (Lisp_Object instantiator);
752 Lisp_Object make_string_from_file (Lisp_Object file);
753 Lisp_Object tagged_vector_to_alist (Lisp_Object vector);
754 Lisp_Object alist_to_tagged_vector (Lisp_Object tag, Lisp_Object alist);
755 void string_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
756                          Lisp_Object pointer_fg, Lisp_Object pointer_bg,
757                          int dest_mask, Lisp_Object domain);
758 Lisp_Object allocate_glyph (enum glyph_type type,
759                             void (*after_change) (Lisp_Object glyph,
760                                                   Lisp_Object property,
761                                                   Lisp_Object locale));
762 Lisp_Object widget_face_font_info (Lisp_Object domain, Lisp_Object face,
763                                    int *height, int *width);
764 void widget_text_to_pixel_conversion (Lisp_Object domain, Lisp_Object face,
765                                       int th, int tw,
766                                       int* height, int* width);
767 Lisp_Object add_glyph_animated_timeout (EMACS_INT tickms, Lisp_Object device);
768 void disable_glyph_animated_timeout (int i);
769
770 /************************************************************************/
771 /*                              Glyph Cachels                           */
772 /************************************************************************/
773
774 typedef struct glyph_cachel glyph_cachel;
775 struct glyph_cachel
776 {
777   Lisp_Object glyph;
778
779   unsigned int dirty :1;        /* I'm copying faces here. I'm not
780                                    sure why we need two dirty
781                                    flags. Maybe because an image
782                                    instance can be dirty and so we
783                                    need to frob this in the same way
784                                    as other image instance properties.  */
785   unsigned int updated :1;
786
787   unsigned short width;
788   unsigned short ascent;
789   unsigned short descent;
790 };
791
792 #define CONT_GLYPH_INDEX        (glyph_index) 0
793 #define TRUN_GLYPH_INDEX        (glyph_index) 1
794 #define HSCROLL_GLYPH_INDEX     (glyph_index) 2
795 #define CONTROL_GLYPH_INDEX     (glyph_index) 3
796 #define OCT_ESC_GLYPH_INDEX     (glyph_index) 4
797 #define INVIS_GLYPH_INDEX       (glyph_index) 5
798
799 #define GLYPH_CACHEL(window, index)                     \
800   Dynarr_atp (window->glyph_cachels, index)
801 #define GLYPH_CACHEL_GLYPH(window, index)               \
802   Dynarr_atp (window->glyph_cachels, index)->glyph
803 #define GLYPH_CACHEL_WIDTH(window, index)               \
804   Dynarr_atp (window->glyph_cachels, index)->width
805 #define GLYPH_CACHEL_ASCENT(window, index)              \
806   Dynarr_atp (window->glyph_cachels, index)->ascent
807 #define GLYPH_CACHEL_DESCENT(window, index)             \
808   Dynarr_atp (window->glyph_cachels, index)->descent
809 #define GLYPH_CACHEL_DIRTYP(window, index)              \
810   Dynarr_atp (window->glyph_cachels, index)->dirty
811
812 void mark_glyph_cachels (glyph_cachel_dynarr *elements);
813 void mark_glyph_cachels_as_not_updated (struct window *w);
814 void mark_glyph_cachels_as_clean (struct window *w);
815 void reset_glyph_cachels (struct window *w);
816 glyph_index get_glyph_cachel_index (struct window *w, Lisp_Object glyph);
817
818 #ifdef MEMORY_USAGE_STATS
819 int compute_glyph_cachel_usage (glyph_cachel_dynarr *glyph_cachels,
820                                 struct overhead_stats *ovstats);
821 #endif /* MEMORY_USAGE_STATS */
822
823 /************************************************************************/
824 /*                              Display Tables                          */
825 /************************************************************************/
826
827 Lisp_Object display_table_entry (Emchar, Lisp_Object, Lisp_Object);
828 void get_display_tables (struct window *, face_index,
829                          Lisp_Object *, Lisp_Object *);
830
831 /****************************************************************************
832  *                            Subwindow Object                              *
833  ****************************************************************************/
834
835 /* redisplay needs a per-frame cache of subwindows being displayed so
836  * that we known when to unmap them */
837 typedef struct subwindow_cachel subwindow_cachel;
838 struct subwindow_cachel
839 {
840   Lisp_Object subwindow;
841   int x, y;
842   int width, height;
843   unsigned int being_displayed : 1;
844   unsigned int updated : 1;
845 };
846
847 typedef struct
848 {
849   Dynarr_declare (subwindow_cachel);
850 } subwindow_cachel_dynarr;
851
852 void mark_subwindow_cachels (subwindow_cachel_dynarr *elements);
853 void mark_subwindow_cachels_as_not_updated (struct frame *f);
854 void reset_subwindow_cachels (struct frame *f);
855 void unmap_subwindow (Lisp_Object subwindow);
856 void map_subwindow (Lisp_Object subwindow, int x, int y,
857                     struct display_glyph_area *dga);
858 void update_frame_subwindows (struct frame *f);
859 int find_matching_subwindow (struct frame* f, int x, int y, int width, int height);
860
861 struct expose_ignore
862 {
863   int   x;
864   int   y;
865   int   width;
866   int   height;
867   struct expose_ignore *next;
868 };
869
870 int check_for_ignored_expose (struct frame* f, int x, int y, int width, int height);
871 extern int hold_ignored_expose_registration;
872
873 #endif /* _XEMACS_GLYPHS_H_ */