import -ko -b 1.1.3 XEmacs XEmacs-21_2 r21-2-35
[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 INCLUDED_glyphs_h_
25 #define INCLUDED_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, color-pixmap
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   label                         widget
66   layout                        widget
67   native-layout                 widget
68 */
69
70 /* These are methods specific to a particular format of image instantiator
71    (e.g. xpm, string, etc.). */
72
73 typedef struct ii_keyword_entry ii_keyword_entry;
74 struct ii_keyword_entry
75 {
76   Lisp_Object keyword;
77   void (*validate) (Lisp_Object data);
78   int multiple_p;
79   int copy_p;
80 };
81
82 typedef struct
83 {
84   Dynarr_declare (ii_keyword_entry);
85 } ii_keyword_entry_dynarr;
86
87 extern const struct struct_description iim_description;
88
89 enum image_instance_geometry
90 {
91   IMAGE_GEOMETRY,
92   IMAGE_DESIRED_GEOMETRY,
93   IMAGE_MIN_GEOMETRY,
94   IMAGE_MAX_GEOMETRY
95 };
96
97 #define IMAGE_UNSPECIFIED_GEOMETRY -1
98
99 #define WIDGET_BORDER_HEIGHT 4
100 #define WIDGET_BORDER_WIDTH 4
101
102 enum governing_domain
103 {
104   GOVERNING_DOMAIN_WINDOW,
105   GOVERNING_DOMAIN_FRAME,
106   GOVERNING_DOMAIN_DEVICE
107 };
108
109 struct image_instantiator_methods
110 {
111   Lisp_Object symbol;
112
113   Lisp_Object device;           /* sometimes used */
114
115   ii_keyword_entry_dynarr *keywords;
116   /* consoles this ii is supported on */
117   console_type_entry_dynarr *consoles;
118   /* Implementation specific methods: */
119
120   /* Validate method: Given an instantiator vector, signal an error if
121      it's invalid for this image-instantiator format.  Note that this
122      validation only occurs after all the keyword-specific validation
123      has already been performed.  This is chiefly useful for making
124      sure that certain required keywords are present. */
125   void (*validate_method) (Lisp_Object instantiator);
126
127   /* Normalize method: Given an instantiator, convert it to the form
128      that should be used in a glyph, for devices of type CONSOLE_TYPE.
129      Signal an error if conversion fails. */
130   Lisp_Object (*normalize_method) (Lisp_Object instantiator,
131                                    Lisp_Object console_type);
132
133   /* Governing domain method: Return an int indicating what type of
134      domain an instance in this format is governed by. */
135   int (*governing_domain_method) (void);
136
137   /* Possible-dest-types method: Return a mask indicating what dest types
138      are compatible with this format. */
139   int (*possible_dest_types_method) (void);
140
141   /* Instantiate method: Given an instantiator and a partially
142      filled-in image instance, complete the filling-in.  Return
143      non-zero if the instantiation succeeds, 0 if it fails.
144      This must be present. */
145   void (*instantiate_method) (Lisp_Object image_instance,
146                               Lisp_Object instantiator,
147                               Lisp_Object pointer_fg,
148                               Lisp_Object pointer_bg,
149                               int dest_mask,
150                               Lisp_Object domain);
151   /* Post instantiate method: finish instantiation of the image
152      instance. */
153   void (*post_instantiate_method) (Lisp_Object image_instance,
154                                    Lisp_Object instantiator,
155                                    Lisp_Object domain);
156   /* Property method: Given an image instance, return device specific
157      properties. */
158   Lisp_Object (*property_method) (Lisp_Object image_instance,
159                                   Lisp_Object property);
160   /* Set-property method: Given an image instance, set device specific
161      properties. */
162   Lisp_Object (*set_property_method) (Lisp_Object image_instance,
163                                       Lisp_Object property,
164                                       Lisp_Object val);
165   /* Asynchronously update properties. */
166   void (*update_method) (Lisp_Object image_instance);
167
168   /* Find out the desired geometry, as given by disp, of this image
169    instance. Actual geometry is stored in the appropriate slots in the
170    image instance. */
171   void (*query_geometry_method) (Lisp_Object image_instance,
172                                  int* width, int* height,
173                                  enum image_instance_geometry disp,
174                                  Lisp_Object domain);
175
176   /* Layout the instance and its children bounded by the provided
177      dimensions. Returns success or failure. */
178   int (*layout_method) (Lisp_Object image_instance,
179                         int width, int height, Lisp_Object domain);
180 };
181
182 /***** Calling an image-instantiator method *****/
183
184 #define HAS_IIFORMAT_METH_P(mstruc, m) (((mstruc)->m##_method) != 0)
185 #define IIFORMAT_METH(mstruc, m, args) (((mstruc)->m##_method) args)
186
187 /* Call a void-returning specifier method, if it exists */
188 #define MAYBE_IIFORMAT_METH(mstruc, m, args)                    \
189 do {                                                            \
190   struct image_instantiator_methods *MIM_mstruc = (mstruc);     \
191   if (MIM_mstruc && HAS_IIFORMAT_METH_P (MIM_mstruc, m))        \
192     IIFORMAT_METH (MIM_mstruc, m, args);                        \
193 } while (0)
194
195 #define MAYBE_IIFORMAT_DEVMETH(device, mstruc, m, args) \
196 do {                                                    \
197   struct image_instantiator_methods *MID_mstruc =       \
198     decode_ii_device (device, mstruc);                  \
199   if (MID_mstruc)                                       \
200     MAYBE_IIFORMAT_METH(MID_mstruc, m, args);           \
201 } while (0)
202
203
204 /* Call a specifier method, if it exists; otherwise return
205    the specified value */
206
207 #define IIFORMAT_METH_OR_GIVEN(mstruc, m, args, given)  \
208   ((mstruc && HAS_IIFORMAT_METH_P (mstruc, m)) ?                \
209    IIFORMAT_METH (mstruc, m, args) : (given))
210
211 /***** Defining new image-instantiator types *****/
212
213 #define DECLARE_IMAGE_INSTANTIATOR_FORMAT(format)               \
214 extern struct image_instantiator_methods *format##_image_instantiator_methods
215
216 #define DEFINE_IMAGE_INSTANTIATOR_FORMAT(format)                \
217 struct image_instantiator_methods *format##_image_instantiator_methods
218
219 #define INITIALIZE_IMAGE_INSTANTIATOR_FORMAT_NO_SYM(format, obj_name)   \
220 do {                                                            \
221   format##_image_instantiator_methods =                         \
222     xnew_and_zero (struct image_instantiator_methods);          \
223   format##_image_instantiator_methods->symbol = Q##format;      \
224   format##_image_instantiator_methods->device = Qnil;           \
225   format##_image_instantiator_methods->keywords =               \
226     Dynarr_new (ii_keyword_entry);                              \
227   format##_image_instantiator_methods->consoles =               \
228     Dynarr_new (console_type_entry);                            \
229   add_entry_to_image_instantiator_format_list                   \
230     (Q##format, format##_image_instantiator_methods);           \
231   dumpstruct (&format##_image_instantiator_methods,             \
232               &iim_description);                                \
233 } while (0)
234
235 #define INITIALIZE_IMAGE_INSTANTIATOR_FORMAT(format, obj_name)  \
236 do {                                                            \
237   defsymbol (&Q##format, obj_name);                             \
238   INITIALIZE_IMAGE_INSTANTIATOR_FORMAT_NO_SYM(format, obj_name);\
239 } while (0)
240
241 /* Declare that image-instantiator format FORMAT has method M; used in
242    initialization routines */
243 #define IIFORMAT_HAS_METHOD(format, m) \
244   (format##_image_instantiator_methods->m##_method = format##_##m)
245
246 #define IIFORMAT_HAS_SHARED_METHOD(format, m, type) \
247   (format##_image_instantiator_methods->m##_method = type##_##m)
248
249 /* Declare that KEYW is a valid keyword for image-instantiator format
250    FORMAT.  VALIDATE_FUN if a function that returns whether the data
251    is valid.  The keyword may not appear more than once. */
252 #define IIFORMAT_VALID_GENERIC_KEYWORD(format, keyw, validate_fun, copy, multi) \
253   do {                                                          \
254     struct ii_keyword_entry entry;                              \
255                                                                 \
256     entry.keyword = keyw;                                       \
257     entry.validate = validate_fun;                              \
258     entry.multiple_p = multi;                                   \
259     entry.copy_p = copy;                                        \
260     Dynarr_add (format##_image_instantiator_methods->keywords,  \
261                 entry);                                         \
262   } while (0)
263
264 #define IIFORMAT_VALID_KEYWORD(format, keyw, validate_fun)      \
265 IIFORMAT_VALID_GENERIC_KEYWORD(format, keyw, validate_fun, 1, 0)
266
267 /* Same as IIFORMAT_VALID_KEYWORD except that the keyword may
268    appear multiple times. */
269 #define IIFORMAT_VALID_MULTI_KEYWORD(format, keyw, validate_fun)        \
270 IIFORMAT_VALID_GENERIC_KEYWORD(format, keyw, validate_fun, 1, 1)
271
272 /* Same as IIFORMAT_VALID_KEYWORD execpt that the argument is not
273    copied by the specifier functions. This is necessary for things
274    like callbacks etc. */
275 #define IIFORMAT_VALID_NONCOPY_KEYWORD(format, keyw, validate_fun)      \
276 IIFORMAT_VALID_GENERIC_KEYWORD(format, keyw, validate_fun, 0, 0)
277
278 /* Declare that image-instantiator format FORMAT is supported on
279    CONSOLE type. */
280 #define IIFORMAT_VALID_CONSOLE(console, format)                 \
281   do {                                                          \
282     struct console_type_entry entry;                            \
283                                                                 \
284     entry.symbol = Q##console;                                  \
285     entry.meths = console##_console_methods;                    \
286     Dynarr_add (format##_image_instantiator_methods->consoles,  \
287                 entry);                                         \
288   } while (0)
289
290 #define IIFORMAT_VALID_CONSOLE2(con1, con2, format)             \
291   IIFORMAT_VALID_CONSOLE (con1, format);                        \
292   IIFORMAT_VALID_CONSOLE (con2, format);
293
294 #define DEFINE_DEVICE_IIFORMAT(type, format)    \
295 DECLARE_IMAGE_INSTANTIATOR_FORMAT(format);      \
296 struct image_instantiator_methods *type##_##format##_image_instantiator_methods
297
298 #define INITIALIZE_DEVICE_IIFORMAT(type, format)                        \
299 do {                                                                    \
300   type##_##format##_image_instantiator_methods =                        \
301     xnew_and_zero (struct image_instantiator_methods);                  \
302   type##_##format##_image_instantiator_methods->symbol = Q##format;     \
303   type##_##format##_image_instantiator_methods->device = Q##type;       \
304   type##_##format##_image_instantiator_methods->keywords =              \
305     Dynarr_new (ii_keyword_entry);                                      \
306   add_entry_to_device_ii_format_list                                    \
307     (Q##type, Q##format, type##_##format##_image_instantiator_methods); \
308   IIFORMAT_VALID_CONSOLE(type,format);                                  \
309   dumpstruct (&type##_##format##_image_instantiator_methods,            \
310               &iim_description);                                        \
311 } while (0)
312
313 /* Declare that image-instantiator format FORMAT has method M; used in
314    initialization routines */
315 #define IIFORMAT_HAS_DEVMETHOD(type, format, m) \
316   (type##_##format##_image_instantiator_methods->m##_method = type##_##format##_##m)
317 #define IIFORMAT_HAS_SHARED_DEVMETHOD(type, format, m, fromformat) \
318   (type##_##format##_image_instantiator_methods->m##_method = type##_##fromformat##_##m)
319
320 #define IIFORMAT_INHERITS_DEVMETHOD(type, from, format, m) \
321   (type##_##format##_image_instantiator_methods->m##_method = from##_##format##_##m)
322 #define IIFORMAT_INHERITS_SHARED_DEVMETHOD(type, from, format, m, fromformat) \
323   (type##_##format##_image_instantiator_methods->m##_method = from##_##fromformat##_##m)
324
325 struct image_instantiator_methods *
326 decode_device_ii_format (Lisp_Object device, Lisp_Object format,
327                          Error_behavior errb);
328 struct image_instantiator_methods *
329 decode_image_instantiator_format (Lisp_Object format, Error_behavior errb);
330
331 void add_entry_to_image_instantiator_format_list (Lisp_Object symbol,
332                         struct image_instantiator_methods *meths);
333 void add_entry_to_device_ii_format_list (Lisp_Object device, Lisp_Object symbol,
334                         struct image_instantiator_methods *meths);
335 Lisp_Object find_keyword_in_vector (Lisp_Object vector,
336                                     Lisp_Object keyword);
337 Lisp_Object find_keyword_in_vector_or_given (Lisp_Object vector,
338                                              Lisp_Object keyword,
339                                              Lisp_Object default_);
340 Lisp_Object simple_image_type_normalize (Lisp_Object inst,
341                                          Lisp_Object console_type,
342                                          Lisp_Object image_type_tag);
343 Lisp_Object potential_pixmap_file_instantiator (Lisp_Object instantiator,
344                                                 Lisp_Object file_keyword,
345                                                 Lisp_Object data_keyword,
346                                                 Lisp_Object console_type);
347 void check_valid_string (Lisp_Object data);
348 void check_valid_int (Lisp_Object data);
349 void check_valid_face (Lisp_Object data);
350 void check_valid_vector (Lisp_Object data);
351 void check_valid_item_list_1 (Lisp_Object items);
352
353 void initialize_subwindow_image_instance (Lisp_Image_Instance*);
354 void subwindow_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
355                             Lisp_Object pointer_fg, Lisp_Object pointer_bg,
356                             int dest_mask, Lisp_Object domain);
357 int subwindow_governing_domain (void);
358 void widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
359                          Lisp_Object pointer_fg, Lisp_Object pointer_bg,
360                          int dest_mask, Lisp_Object domain);
361 void image_instance_query_geometry (Lisp_Object image_instance,
362                                     int* width, int* height,
363                                     enum image_instance_geometry disp,
364                                     Lisp_Object domain);
365 void image_instance_layout (Lisp_Object image_instance,
366                             int width, int height,
367                             Lisp_Object domain);
368 int layout_layout (Lisp_Object image_instance,
369                    int width, int height,
370                    Lisp_Object domain);
371 int invalidate_glyph_geometry_maybe (Lisp_Object glyph_or_ii, struct window* w);
372
373 DECLARE_DOESNT_RETURN (incompatible_image_types (Lisp_Object instantiator,
374                                                  int given_dest_mask,
375                                                  int desired_dest_mask));
376 DECLARE_DOESNT_RETURN (signal_image_error (const char *, Lisp_Object));
377 DECLARE_DOESNT_RETURN (signal_image_error_2 (const char *, Lisp_Object, Lisp_Object));
378
379 /************************************************************************/
380 /*                      Image Specifier Object                          */
381 /************************************************************************/
382
383 DECLARE_SPECIFIER_TYPE (image);
384 #define XIMAGE_SPECIFIER(x) XSPECIFIER_TYPE (x, image)
385 #define XSETIMAGE_SPECIFIER(x, p) XSETSPECIFIER_TYPE (x, p, image)
386 #define IMAGE_SPECIFIERP(x) SPECIFIER_TYPEP (x, image)
387 #define CHECK_IMAGE_SPECIFIER(x) CHECK_SPECIFIER_TYPE (x, image)
388 #define CONCHECK_IMAGE_SPECIFIER(x) CONCHECK_SPECIFIER_TYPE (x, image)
389
390 void set_image_attached_to (Lisp_Object obj, Lisp_Object face_or_glyph,
391                             Lisp_Object property);
392
393 struct image_specifier
394 {
395   int allowed;
396   Lisp_Object attachee;         /* face or glyph this is attached to, or nil */
397   Lisp_Object attachee_property;/* property of that face or glyph */
398 };
399
400 #define IMAGE_SPECIFIER_DATA(g) (SPECIFIER_TYPE_DATA (g, image))
401 #define IMAGE_SPECIFIER_ALLOWED(g) (IMAGE_SPECIFIER_DATA (g)->allowed)
402 #define IMAGE_SPECIFIER_ATTACHEE(g) (IMAGE_SPECIFIER_DATA (g)->attachee)
403 #define IMAGE_SPECIFIER_ATTACHEE_PROPERTY(g) \
404   (IMAGE_SPECIFIER_DATA (g)->attachee_property)
405
406 #define XIMAGE_SPECIFIER_ALLOWED(g) \
407   IMAGE_SPECIFIER_ALLOWED (XIMAGE_SPECIFIER (g))
408
409 /************************************************************************/
410 /*                      Image Instance Object                           */
411 /************************************************************************/
412
413 DECLARE_LRECORD (image_instance, Lisp_Image_Instance);
414 #define XIMAGE_INSTANCE(x) XRECORD (x, image_instance, Lisp_Image_Instance)
415 #define XSETIMAGE_INSTANCE(x, p) XSETRECORD (x, p, image_instance)
416 #define IMAGE_INSTANCEP(x) RECORDP (x, image_instance)
417 #define CHECK_IMAGE_INSTANCE(x) CHECK_RECORD (x, image_instance)
418 #define CONCHECK_IMAGE_INSTANCE(x) CONCHECK_RECORD (x, image_instance)
419
420 #ifdef ERROR_CHECK_GLYPHS
421 void check_image_instance_structure (Lisp_Object instance);
422 void check_window_subwindow_cache (struct window* w);
423 #define ERROR_CHECK_IMAGE_INSTANCE(ii) \
424   check_image_instance_structure (ii)
425 #define ERROR_CHECK_SUBWINDOW_CACHE(w) \
426   check_window_subwindow_cache (w)
427 #else
428 #define ERROR_CHECK_IMAGE_INSTANCE(ii)
429 #define ERROR_CHECK_SUBWINDOW_CACHE(w)
430 #endif
431
432 enum image_instance_type
433 {
434   IMAGE_UNKNOWN,
435   IMAGE_NOTHING,
436   IMAGE_TEXT,
437   IMAGE_MONO_PIXMAP,
438   IMAGE_COLOR_PIXMAP,
439   IMAGE_POINTER,
440   IMAGE_SUBWINDOW,
441   IMAGE_WIDGET
442 };
443
444 #define IMAGE_NOTHING_MASK (1 << 0)
445 #define IMAGE_TEXT_MASK (1 << 1)
446 #define IMAGE_MONO_PIXMAP_MASK (1 << 2)
447 #define IMAGE_COLOR_PIXMAP_MASK (1 << 3)
448 #define IMAGE_POINTER_MASK (1 << 4)
449 #define IMAGE_SUBWINDOW_MASK (1 << 5)
450 #define IMAGE_WIDGET_MASK (1 << 6)
451
452 /* This depends on the fact that enums are assigned consecutive
453    integers starting at 0. (Remember that IMAGE_UNKNOWN is the
454    first enum.) I'm fairly sure this behavior is ANSI-mandated,
455    so there should be no portability problems here. */
456 #define image_instance_type_to_mask(type) \
457   ((int) (1 << ((int) (type) - 1)))
458
459 #define IMAGE_INSTANCE_TYPE_P(ii, type) \
460 (IMAGE_INSTANCEP (ii) && XIMAGE_INSTANCE_TYPE (ii) == type)
461
462 #define NOTHING_IMAGE_INSTANCEP(ii) \
463      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_NOTHING)
464 #define TEXT_IMAGE_INSTANCEP(ii) \
465      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_TEXT)
466 #define MONO_PIXMAP_IMAGE_INSTANCEP(ii) \
467      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_MONO_PIXMAP)
468 #define COLOR_PIXMAP_IMAGE_INSTANCEP(ii) \
469      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_COLOR_PIXMAP)
470 #define POINTER_IMAGE_INSTANCEP(ii) \
471      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_POINTER)
472 #define SUBWINDOW_IMAGE_INSTANCEP(ii) \
473      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_SUBWINDOW)
474 #define WIDGET_IMAGE_INSTANCEP(ii) \
475      IMAGE_INSTANCE_TYPE_P (ii, IMAGE_WIDGET)
476
477 #define CHECK_NOTHING_IMAGE_INSTANCE(x) do {                    \
478   CHECK_IMAGE_INSTANCE (x);                                     \
479   if (!NOTHING_IMAGE_INSTANCEP (x))                             \
480     x = wrong_type_argument (Qnothing_image_instance_p, (x));   \
481 } while (0)
482
483 #define CHECK_TEXT_IMAGE_INSTANCE(x) do {                       \
484   CHECK_IMAGE_INSTANCE (x);                                     \
485   if (!TEXT_IMAGE_INSTANCEP (x))                                \
486     x = wrong_type_argument (Qtext_image_instance_p, (x));      \
487 } while (0)
488
489 #define CHECK_MONO_PIXMAP_IMAGE_INSTANCE(x) do {                        \
490   CHECK_IMAGE_INSTANCE (x);                                             \
491   if (!MONO_PIXMAP_IMAGE_INSTANCEP (x))                                 \
492     x = wrong_type_argument (Qmono_pixmap_image_instance_p, (x));       \
493 } while (0)
494
495 #define CHECK_COLOR_PIXMAP_IMAGE_INSTANCE(x) do {                       \
496   CHECK_IMAGE_INSTANCE (x);                                             \
497   if (!COLOR_PIXMAP_IMAGE_INSTANCEP (x))                                \
498     x = wrong_type_argument (Qcolor_pixmap_image_instance_p, (x));      \
499 } while (0)
500
501 #define CHECK_POINTER_IMAGE_INSTANCE(x) do {                    \
502   CHECK_IMAGE_INSTANCE (x);                                     \
503   if (!POINTER_IMAGE_INSTANCEP (x))                             \
504     x = wrong_type_argument (Qpointer_image_instance_p, (x));   \
505 } while (0)
506
507 #define CHECK_SUBWINDOW_IMAGE_INSTANCE(x) do {                  \
508   CHECK_IMAGE_INSTANCE (x);                                     \
509   if (!SUBWINDOW_IMAGE_INSTANCEP (x)                            \
510       && !WIDGET_IMAGE_INSTANCEP (x))                           \
511     x = wrong_type_argument (Qsubwindow_image_instance_p, (x)); \
512 } while (0)
513
514 #define CHECK_WIDGET_IMAGE_INSTANCE(x) do {                     \
515   CHECK_IMAGE_INSTANCE (x);                                     \
516   if (!WIDGET_IMAGE_INSTANCEP (x))                              \
517     x = wrong_type_argument (Qwidget_image_instance_p, (x));    \
518 } while (0)
519
520 struct Lisp_Image_Instance
521 {
522   struct lcrecord_header header;
523   Lisp_Object domain;           /* The domain in which we were cached. */
524   Lisp_Object device;           /* The device of the domain. Recorded
525                                    since the domain may get deleted
526                                    before us. */
527   Lisp_Object name;
528   /* The glyph from which we were instantiated. This is a weak
529      reference. */
530   Lisp_Object parent;
531   enum image_instance_type type;
532   unsigned int x_offset, y_offset;      /* for layout purposes */
533   int width, height, margin_width;
534   unsigned long display_hash; /* Hash value representing the structure
535                                  of the image_instance when it was
536                                  last displayed. */
537   unsigned int dirty : 1;
538   unsigned int size_changed : 1;
539   unsigned int text_changed : 1;
540   unsigned int layout_changed : 1; 
541   unsigned int optimize_output : 1; /* For outputting layouts. */
542   unsigned int initialized : 1; /* When we're fully done. */
543
544   union
545   {
546     struct
547     {
548       unsigned int descent;
549       Lisp_Object string;
550     } text;
551     struct
552     {
553       unsigned int depth;
554       unsigned int slice, maxslice, timeout;
555       Lisp_Object hotspot_x, hotspot_y; /* integer or Qnil */
556       Lisp_Object filename;      /* string or Qnil */
557       Lisp_Object mask_filename; /* string or Qnil */
558       Lisp_Object fg, bg; /* foreground and background colors,
559                              if this is a colorized mono-pixmap
560                              or a pointer */
561       Lisp_Object auxdata;    /* list or Qnil: any additional data
562                                  to be seen from lisp */
563       void* mask;               /* mask that can be seen from all windowing systems */
564     } pixmap; /* used for pointers as well */
565     struct
566     {
567       void* subwindow;          /* specific devices can use this as necessary */
568       struct 
569       {                         /* We need these so we can do without
570                                    subwindow_cachel */
571         unsigned int x, y;      
572         unsigned int width, height;
573       } display_data;
574       unsigned int being_displayed : 1; /* used to detect when needs
575                                            to be unmapped */
576       unsigned int v_resize : 1;        /* Whether the vsize is allowed to change. */
577       unsigned int h_resize : 1;        /* Whether the hsize is allowed to change. */
578       unsigned int orientation : 1; /* Vertical or horizontal. */
579       unsigned int justification : 2; /* Left, right or center. */
580       /* Face for colors and font. We specify this here because we
581          want people to be able to put :face in the instantiator
582          spec. Using gyph-face is more inconvenient, although more
583          general. */
584       Lisp_Object face;
585       Lisp_Object type;
586       Lisp_Object props;        /* properties or border*/
587       Lisp_Object items;        /* a list of displayed gui_items */
588       Lisp_Object pending_items; /* gui_items that should be displayed */
589       Lisp_Object children;     /* a list of children */
590       Lisp_Object width;        /* dynamic width spec. */
591       Lisp_Object height;       /* dynamic height spec. */
592       /* Change flags to augment dirty. */
593       unsigned int face_changed : 1;
594       unsigned int items_changed : 1;
595     } subwindow;
596   } u;
597
598   /* console-type- and image-type-specific data */
599   void *data;
600 };
601
602 /* Layout bit-fields. */
603 #define LAYOUT_HORIZONTAL       0
604 #define LAYOUT_VERTICAL 1
605
606 #define LAYOUT_JUSTIFY_LEFT 0
607 #define LAYOUT_JUSTIFY_RIGHT 1
608 #define LAYOUT_JUSTIFY_CENTER 2
609
610 #define IMAGE_INSTANCE_HASH_DEPTH 0
611
612 /* Accessor macros. */
613 #define IMAGE_INSTANCE_DOMAIN(i) ((i)->domain)
614 #define IMAGE_INSTANCE_DOMAIN_LIVE_P(i) (DOMAIN_LIVE_P ((i)->domain))
615 #define IMAGE_INSTANCE_DEVICE(i) ((i)->device)
616 #define IMAGE_INSTANCE_FRAME(i) (DOMAIN_FRAME ((i)->domain))
617 #define IMAGE_INSTANCE_NAME(i) ((i)->name)
618 #define IMAGE_INSTANCE_PARENT(i) ((i)->parent)
619 #define IMAGE_INSTANCE_GLYPH(i) (image_instance_parent_glyph(i))
620 #define IMAGE_INSTANCE_TYPE(i) ((i)->type)
621 #define IMAGE_INSTANCE_XOFFSET(i) ((i)->x_offset)
622 #define IMAGE_INSTANCE_YOFFSET(i) ((i)->y_offset)
623 #define IMAGE_INSTANCE_WIDTH(i) ((i)->width)
624 #define IMAGE_INSTANCE_MARGIN_WIDTH(i) ((i)->margin_width)
625 #define IMAGE_INSTANCE_HEIGHT(i) ((i)->height)
626 #define IMAGE_INSTANCE_INITIALIZED(i) ((i)->initialized)
627 #define IMAGE_INSTANCE_DISPLAY_HASH(i) ((i)->display_hash)
628 #define IMAGE_INSTANCE_PIXMAP_TYPE_P(i)                 \
629  ((IMAGE_INSTANCE_TYPE (i) == IMAGE_MONO_PIXMAP)        \
630   || (IMAGE_INSTANCE_TYPE (i) == IMAGE_COLOR_PIXMAP))
631 #define IMAGE_INSTANCE_DIRTYP(i) ((i)->dirty)
632 #define IMAGE_INSTANCE_NEEDS_LAYOUT(i) \
633   ((IMAGE_INSTANCE_DIRTYP (i) && IMAGE_INSTANCE_LAYOUT_CHANGED (i)) \
634    || (FRAMEP (IMAGE_INSTANCE_FRAME (i)) \
635        && XFRAME (IMAGE_INSTANCE_FRAME (i))->size_changed))
636 #define IMAGE_INSTANCE_FACE(i) \
637   (GLYPHP (IMAGE_INSTANCE_GLYPH (i)) ? \
638    XGLYPH_FACE (IMAGE_INSTANCE_GLYPH (i)) : Qnil)
639
640 /* Changed flags */
641 #define IMAGE_INSTANCE_TEXT_CHANGED(i) ((i)->text_changed)
642 #define IMAGE_INSTANCE_SIZE_CHANGED(i) ((i)->size_changed)
643 #define IMAGE_INSTANCE_WIDGET_FACE_CHANGED(i) \
644   ((i)->u.subwindow.face_changed)
645 #define IMAGE_INSTANCE_WIDGET_ITEMS_CHANGED(i) \
646   ((i)->u.subwindow.items_changed)
647 #define IMAGE_INSTANCE_LAYOUT_CHANGED(i) ((i)->layout_changed)
648 #define IMAGE_INSTANCE_OPTIMIZE_OUTPUT(i) ((i)->optimize_output)
649
650 /* Text properties */
651 #define IMAGE_INSTANCE_TEXT_STRING(i) ((i)->u.text.string)
652 #define IMAGE_INSTANCE_TEXT_WIDTH(i) \
653   IMAGE_INSTANCE_WIDTH(i)
654 #define IMAGE_INSTANCE_TEXT_HEIGHT(i) \
655   IMAGE_INSTANCE_HEIGHT(i)
656 #define IMAGE_INSTANCE_TEXT_DESCENT(i) ((i)->u.text.descent)
657 #define IMAGE_INSTANCE_TEXT_ASCENT(i) \
658   (IMAGE_INSTANCE_TEXT_HEIGHT(i) - IMAGE_INSTANCE_TEXT_DESCENT(i))
659
660 /* Pixmap properties */
661 #define IMAGE_INSTANCE_PIXMAP_WIDTH(i) \
662   IMAGE_INSTANCE_WIDTH(i)
663 #define IMAGE_INSTANCE_PIXMAP_HEIGHT(i) \
664   IMAGE_INSTANCE_HEIGHT(i)
665 #define IMAGE_INSTANCE_PIXMAP_DEPTH(i) ((i)->u.pixmap.depth)
666 #define IMAGE_INSTANCE_PIXMAP_FILENAME(i) ((i)->u.pixmap.filename)
667 #define IMAGE_INSTANCE_PIXMAP_MASK_FILENAME(i) ((i)->u.pixmap.mask_filename)
668 #define IMAGE_INSTANCE_PIXMAP_HOTSPOT_X(i) ((i)->u.pixmap.hotspot_x)
669 #define IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y(i) ((i)->u.pixmap.hotspot_y)
670 #define IMAGE_INSTANCE_PIXMAP_FG(i) ((i)->u.pixmap.fg)
671 #define IMAGE_INSTANCE_PIXMAP_BG(i) ((i)->u.pixmap.bg)
672 #define IMAGE_INSTANCE_PIXMAP_AUXDATA(i) ((i)->u.pixmap.auxdata)
673 #define IMAGE_INSTANCE_PIXMAP_MASK(i) ((i)->u.pixmap.mask)
674 #define IMAGE_INSTANCE_PIXMAP_SLICE(i) ((i)->u.pixmap.slice)
675 #define IMAGE_INSTANCE_PIXMAP_MAXSLICE(i) ((i)->u.pixmap.maxslice)
676 #define IMAGE_INSTANCE_PIXMAP_TIMEOUT(i) ((i)->u.pixmap.timeout)
677
678 /* Subwindow properties */
679 #define IMAGE_INSTANCE_SUBWINDOW_ID(i) ((i)->u.subwindow.subwindow)
680 /* Display data. */
681 #define IMAGE_INSTANCE_DISPLAY_X(i) ((i)->u.subwindow.display_data.x)
682 #define IMAGE_INSTANCE_DISPLAY_Y(i) ((i)->u.subwindow.display_data.y)
683 #define IMAGE_INSTANCE_DISPLAY_WIDTH(i) \
684   ((i)->u.subwindow.display_data.width)
685 #define IMAGE_INSTANCE_DISPLAY_HEIGHT(i) \
686   ((i)->u.subwindow.display_data.height)
687 #define IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP(i) \
688 ((i)->u.subwindow.being_displayed)
689 #define IMAGE_INSTANCE_SUBWINDOW_V_RESIZEP(i) \
690 ((i)->u.subwindow.v_resize)
691 #define IMAGE_INSTANCE_SUBWINDOW_H_RESIZEP(i) \
692 ((i)->u.subwindow.h_resize)
693 #define IMAGE_INSTANCE_SUBWINDOW_ORIENT(i) \
694 ((i)->u.subwindow.orientation)
695 #define IMAGE_INSTANCE_SUBWINDOW_JUSTIFY(i) \
696 ((i)->u.subwindow.justification)
697
698 /* Widget properties */
699 #define IMAGE_INSTANCE_WIDGET_WIDTH(i) \
700   IMAGE_INSTANCE_WIDTH(i)
701 #define IMAGE_INSTANCE_WIDGET_HEIGHT(i) \
702   IMAGE_INSTANCE_HEIGHT(i)
703 #define IMAGE_INSTANCE_WIDGET_WIDTH_SUBR(i) ((i)->u.subwindow.width)
704 #define IMAGE_INSTANCE_WIDGET_HEIGHT_SUBR(i) ((i)->u.subwindow.height)
705 #define IMAGE_INSTANCE_WIDGET_TYPE(i) ((i)->u.subwindow.type)
706 #define IMAGE_INSTANCE_WIDGET_PROPS(i) ((i)->u.subwindow.props)
707 #define SET_IMAGE_INSTANCE_WIDGET_FACE(i,f) \
708  ((i)->u.subwindow.face = f)
709 #define IMAGE_INSTANCE_WIDGET_FACE(i)                           \
710   (!NILP ((i)->u.subwindow.face) ? (i)->u.subwindow.face :      \
711   !NILP (IMAGE_INSTANCE_FACE (i)) ? IMAGE_INSTANCE_FACE (i) :   \
712   Vwidget_face)
713 #define IMAGE_INSTANCE_WIDGET_ITEMS(i) ((i)->u.subwindow.items)
714 #define IMAGE_INSTANCE_WIDGET_PENDING_ITEMS(i) \
715   ((i)->u.subwindow.pending_items)
716 #define IMAGE_INSTANCE_WIDGET_ITEM(i)           \
717 (CONSP (IMAGE_INSTANCE_WIDGET_ITEMS (i)) ?      \
718 XCAR (IMAGE_INSTANCE_WIDGET_ITEMS (i)) :        \
719   IMAGE_INSTANCE_WIDGET_ITEMS (i))
720 #define IMAGE_INSTANCE_WIDGET_TEXT(i) XGUI_ITEM (IMAGE_INSTANCE_WIDGET_ITEM (i))->name
721
722 /* Layout properties */
723 #define IMAGE_INSTANCE_LAYOUT_CHILDREN(i) ((i)->u.subwindow.children)
724 #define IMAGE_INSTANCE_LAYOUT_BORDER(i) ((i)->u.subwindow.props)
725
726 #define XIMAGE_INSTANCE_DOMAIN(i) \
727   IMAGE_INSTANCE_DOMAIN (XIMAGE_INSTANCE (i))
728 #define XIMAGE_INSTANCE_DOMAIN_LIVE_P(i) \
729   IMAGE_INSTANCE_DOMAIN_LIVE_P (XIMAGE_INSTANCE (i))
730 #define XIMAGE_INSTANCE_DEVICE(i) \
731   IMAGE_INSTANCE_DEVICE (XIMAGE_INSTANCE (i))
732 #define XIMAGE_INSTANCE_FRAME(i) \
733   IMAGE_INSTANCE_FRAME (XIMAGE_INSTANCE (i))
734 #define XIMAGE_INSTANCE_NAME(i) \
735   IMAGE_INSTANCE_NAME (XIMAGE_INSTANCE (i))
736 #define XIMAGE_INSTANCE_GLYPH(i) \
737   IMAGE_INSTANCE_GLYPH (XIMAGE_INSTANCE (i))
738 #define XIMAGE_INSTANCE_PARENT(i) \
739   IMAGE_INSTANCE_PARENT (XIMAGE_INSTANCE (i))
740 #define XIMAGE_INSTANCE_TYPE(i) \
741   IMAGE_INSTANCE_TYPE (XIMAGE_INSTANCE (i))
742 #define XIMAGE_INSTANCE_DISPLAY_HASH(i) \
743   IMAGE_INSTANCE_DISPLAY_HASH (XIMAGE_INSTANCE (i))
744 #define XIMAGE_INSTANCE_XOFFSET(i) \
745   IMAGE_INSTANCE_XOFFSET (XIMAGE_INSTANCE (i))
746 #define XIMAGE_INSTANCE_YOFFSET(i) \
747   IMAGE_INSTANCE_YOFFSET (XIMAGE_INSTANCE (i))
748 #define XIMAGE_INSTANCE_DIRTYP(i) \
749   IMAGE_INSTANCE_DIRTYP (XIMAGE_INSTANCE (i))
750 #define XIMAGE_INSTANCE_NEEDS_LAYOUT(i) \
751   IMAGE_INSTANCE_NEEDS_LAYOUT (XIMAGE_INSTANCE (i))
752 #define XIMAGE_INSTANCE_WIDTH(i) \
753   IMAGE_INSTANCE_WIDTH (XIMAGE_INSTANCE (i))
754 #define XIMAGE_INSTANCE_MARGIN_WIDTH(i) \
755   IMAGE_INSTANCE_MARGIN_WIDTH (XIMAGE_INSTANCE (i))
756 #define XIMAGE_INSTANCE_HEIGHT(i) \
757   IMAGE_INSTANCE_HEIGHT (XIMAGE_INSTANCE (i))
758 #define XIMAGE_INSTANCE_INITIALIZED(i) \
759   IMAGE_INSTANCE_INITIALIZED (XIMAGE_INSTANCE (i))
760 #define XIMAGE_INSTANCE_FACE(i) \
761   IMAGE_INSTANCE_FACE (XIMAGE_INSTANCE (i))
762
763 #define XIMAGE_INSTANCE_TEXT_STRING(i) \
764   IMAGE_INSTANCE_TEXT_STRING (XIMAGE_INSTANCE (i))
765 #define XIMAGE_INSTANCE_TEXT_WIDTH(i) \
766   IMAGE_INSTANCE_TEXT_WIDTH (XIMAGE_INSTANCE (i))
767 #define XIMAGE_INSTANCE_TEXT_HEIGHT(i) \
768   IMAGE_INSTANCE_TEXT_HEIGHT (XIMAGE_INSTANCE (i))
769 #define XIMAGE_INSTANCE_TEXT_ASCENT(i) \
770   IMAGE_INSTANCE_TEXT_ASCENT (XIMAGE_INSTANCE (i))
771 #define XIMAGE_INSTANCE_TEXT_DESCENT(i) \
772   IMAGE_INSTANCE_TEXT_DESCENT (XIMAGE_INSTANCE (i))
773
774 #define XIMAGE_INSTANCE_PIXMAP_WIDTH(i) \
775   IMAGE_INSTANCE_PIXMAP_WIDTH (XIMAGE_INSTANCE (i))
776 #define XIMAGE_INSTANCE_PIXMAP_HEIGHT(i) \
777   IMAGE_INSTANCE_PIXMAP_HEIGHT (XIMAGE_INSTANCE (i))
778 #define XIMAGE_INSTANCE_PIXMAP_DEPTH(i) \
779   IMAGE_INSTANCE_PIXMAP_DEPTH (XIMAGE_INSTANCE (i))
780 #define XIMAGE_INSTANCE_PIXMAP_FILENAME(i) \
781   IMAGE_INSTANCE_PIXMAP_FILENAME (XIMAGE_INSTANCE (i))
782 #define XIMAGE_INSTANCE_PIXMAP_MASK_FILENAME(i) \
783   IMAGE_INSTANCE_PIXMAP_MASK_FILENAME (XIMAGE_INSTANCE (i))
784 #define XIMAGE_INSTANCE_PIXMAP_HOTSPOT_X(i) \
785   IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (XIMAGE_INSTANCE (i))
786 #define XIMAGE_INSTANCE_PIXMAP_HOTSPOT_Y(i) \
787   IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (XIMAGE_INSTANCE (i))
788 #define XIMAGE_INSTANCE_PIXMAP_FG(i) \
789   IMAGE_INSTANCE_PIXMAP_FG (XIMAGE_INSTANCE (i))
790 #define XIMAGE_INSTANCE_PIXMAP_BG(i) \
791   IMAGE_INSTANCE_PIXMAP_BG (XIMAGE_INSTANCE (i))
792 #define XIMAGE_INSTANCE_PIXMAP_MASK(i) \
793   IMAGE_INSTANCE_PIXMAP_MASK (XIMAGE_INSTANCE (i))
794 #define XIMAGE_INSTANCE_PIXMAP_SLICE(i) \
795   IMAGE_INSTANCE_PIXMAP_SLICE (XIMAGE_INSTANCE (i))
796 #define XIMAGE_INSTANCE_PIXMAP_MAXSLICE(i) \
797   IMAGE_INSTANCE_PIXMAP_MAXSLICE (XIMAGE_INSTANCE (i))
798 #define XIMAGE_INSTANCE_PIXMAP_TIMEOUT(i) \
799   IMAGE_INSTANCE_PIXMAP_TIMEOUT (XIMAGE_INSTANCE (i))
800
801 #define XIMAGE_INSTANCE_WIDGET_WIDTH(i) \
802   IMAGE_INSTANCE_WIDGET_WIDTH (XIMAGE_INSTANCE (i))
803 #define XIMAGE_INSTANCE_WIDGET_HEIGHT(i) \
804   IMAGE_INSTANCE_WIDGET_HEIGHT (XIMAGE_INSTANCE (i))
805 #define XIMAGE_INSTANCE_WIDGET_WIDTH_SUBR(i) \
806   IMAGE_INSTANCE_WIDGET_WIDTH_SUBR (XIMAGE_INSTANCE (i))
807 #define XIMAGE_INSTANCE_WIDGET_HEIGHT_SUBR(i) \
808   IMAGE_INSTANCE_WIDGET_HEIGHT_SUBR (XIMAGE_INSTANCE (i))
809 #define XIMAGE_INSTANCE_WIDGET_TYPE(i) \
810   IMAGE_INSTANCE_WIDGET_TYPE (XIMAGE_INSTANCE (i))
811 #define XIMAGE_INSTANCE_WIDGET_PROPS(i) \
812   IMAGE_INSTANCE_WIDGET_PROPS (XIMAGE_INSTANCE (i))
813 #define XIMAGE_INSTANCE_WIDGET_FACE(i) \
814   IMAGE_INSTANCE_WIDGET_FACE (XIMAGE_INSTANCE (i))
815 #define XSET_IMAGE_INSTANCE_WIDGET_FACE(i) \
816   SET_IMAGE_INSTANCE_WIDGET_FACE (XIMAGE_INSTANCE (i))
817 #define XIMAGE_INSTANCE_WIDGET_ITEM(i) \
818   IMAGE_INSTANCE_WIDGET_ITEM (XIMAGE_INSTANCE (i))
819 #define XIMAGE_INSTANCE_WIDGET_ITEMS(i) \
820   IMAGE_INSTANCE_WIDGET_ITEMS (XIMAGE_INSTANCE (i))
821 #define XIMAGE_INSTANCE_WIDGET_PENDING_ITEMS(i) \
822   IMAGE_INSTANCE_WIDGET_PENDING_ITEMS (XIMAGE_INSTANCE (i))
823 #define XIMAGE_INSTANCE_WIDGET_TEXT(i) \
824   IMAGE_INSTANCE_WIDGET_TEXT (XIMAGE_INSTANCE (i))
825
826 #define XIMAGE_INSTANCE_LAYOUT_CHILDREN(i) \
827   IMAGE_INSTANCE_LAYOUT_CHILDREN (XIMAGE_INSTANCE (i))
828 #define XIMAGE_INSTANCE_LAYOUT_BORDER(i) \
829   IMAGE_INSTANCE_LAYOUT_BORDER (XIMAGE_INSTANCE (i))
830
831 #define XIMAGE_INSTANCE_SUBWINDOW_ID(i) \
832   IMAGE_INSTANCE_SUBWINDOW_ID (XIMAGE_INSTANCE (i))
833 #define XIMAGE_INSTANCE_DISPLAY_X(i) \
834   IMAGE_INSTANCE_DISPLAY_X (XIMAGE_INSTANCE (i))
835 #define XIMAGE_INSTANCE_DISPLAY_Y(i) \
836   IMAGE_INSTANCE_DISPLAY_Y (XIMAGE_INSTANCE (i))
837 #define XIMAGE_INSTANCE_DISPLAY_WIDTH(i) \
838   IMAGE_INSTANCE_DISPLAY_WIDTH (XIMAGE_INSTANCE (i))
839 #define XIMAGE_INSTANCE_DISPLAY_HEIGHT(i) \
840   IMAGE_INSTANCE_DISPLAY_HEIGHT (XIMAGE_INSTANCE (i))
841 #define XIMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP(i) \
842   IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (XIMAGE_INSTANCE (i))
843 #define XIMAGE_INSTANCE_SUBWINDOW_ORIENT(i) \
844   IMAGE_INSTANCE_SUBWINDOW_ORIENT (XIMAGE_INSTANCE (i))
845 #define XIMAGE_INSTANCE_SUBWINDOW_JUSTIFY(i) \
846   IMAGE_INSTANCE_SUBWINDOW_JUSTIFY (XIMAGE_INSTANCE (i))
847
848 #define MARK_IMAGE_INSTANCE_CHANGED(i) \
849   (IMAGE_INSTANCE_DIRTYP (i) = 1);
850
851 Lisp_Object image_instance_device (Lisp_Object instance);
852 Lisp_Object image_instance_frame (Lisp_Object instance);
853 Lisp_Object image_instance_window (Lisp_Object instance);
854 int image_instance_live_p (Lisp_Object instance);
855
856 #ifdef HAVE_XPM
857 Lisp_Object evaluate_xpm_color_symbols (void);
858 Lisp_Object pixmap_to_lisp_data (Lisp_Object name, int ok_if_data_invalid);
859 #endif /* HAVE_XPM */
860 #ifdef HAVE_WINDOW_SYSTEM
861 Lisp_Object bitmap_to_lisp_data (Lisp_Object name, int *xhot, int *yhot,
862                                  int ok_if_data_invalid);
863 int read_bitmap_data_from_file (const char *filename, unsigned int *width,
864                                 unsigned int *height, unsigned char **datap,
865                                 int *x_hot, int *y_hot);
866 Lisp_Object xbm_mask_file_munging (Lisp_Object alist, Lisp_Object file,
867                                    Lisp_Object mask_file,
868                                    Lisp_Object console_type);
869 #endif
870
871 /************************************************************************/
872 /*                              Glyph Object                            */
873 /************************************************************************/
874
875 enum glyph_type
876 {
877   GLYPH_UNKNOWN,
878   GLYPH_BUFFER,
879   GLYPH_POINTER,
880   GLYPH_ICON
881 };
882
883 struct Lisp_Glyph
884 {
885   struct lcrecord_header header;
886
887   enum glyph_type type;
888
889   /* specifiers: */
890   Lisp_Object image;            /* the actual image */
891   Lisp_Object contrib_p;        /* whether to figure into line height */
892   Lisp_Object baseline;         /* percent above baseline */
893
894   Lisp_Object face;             /* if non-nil, face to use when displaying */
895
896   Lisp_Object plist;
897   void (*after_change) (Lisp_Object glyph, Lisp_Object property,
898                         Lisp_Object locale);
899
900   unsigned int dirty : 1;       /* So that we can selectively
901                                    redisplay changed glyphs. */
902 };
903 typedef struct Lisp_Glyph Lisp_Glyph;
904
905 DECLARE_LRECORD (glyph, Lisp_Glyph);
906 #define XGLYPH(x) XRECORD (x, glyph, Lisp_Glyph)
907 #define XSETGLYPH(x, p) XSETRECORD (x, p, glyph)
908 #define GLYPHP(x) RECORDP (x, glyph)
909 #define CHECK_GLYPH(x) CHECK_RECORD (x, glyph)
910 #define CONCHECK_GLYPH(x) CONCHECK_RECORD (x, glyph)
911
912 #define CHECK_BUFFER_GLYPH(x) do {                      \
913   CHECK_GLYPH (x);                                      \
914   if (XGLYPH (x)->type != GLYPH_BUFFER)                 \
915     x = wrong_type_argument (Qbuffer_glyph_p, (x));     \
916 } while (0)
917
918 #define CHECK_POINTER_GLYPH(x) do {                     \
919   CHECK_GLYPH (x);                                      \
920   if (XGLYPH (x)->type != GLYPH_POINTER)                \
921     x = wrong_type_argument (Qpointer_glyph_p, (x));    \
922 } while (0)
923
924 #define CHECK_ICON_GLYPH(x) do {                        \
925   CHECK_GLYPH (x);                                      \
926   if (XGLYPH (x)->type != GLYPH_ICON)                   \
927     x = wrong_type_argument (Qicon_glyph_p, (x));       \
928 } while (0)
929
930 #define GLYPH_TYPE(g) ((g)->type)
931 #define GLYPH_IMAGE(g) ((g)->image)
932 #define GLYPH_CONTRIB_P(g) ((g)->contrib_p)
933 #define GLYPH_BASELINE(g) ((g)->baseline)
934 #define GLYPH_FACE(g) ((g)->face)
935 #define GLYPH_DIRTYP(g) ((g)->dirty)
936
937 #define XGLYPH_TYPE(g) GLYPH_TYPE (XGLYPH (g))
938 #define XGLYPH_IMAGE(g) GLYPH_IMAGE (XGLYPH (g))
939 #define XGLYPH_CONTRIB_P(g) GLYPH_CONTRIB_P (XGLYPH (g))
940 #define XGLYPH_BASELINE(g) GLYPH_BASELINE (XGLYPH (g))
941 #define XGLYPH_FACE(g) GLYPH_FACE (XGLYPH (g))
942 #define XGLYPH_DIRTYP(g) GLYPH_DIRTYP (XGLYPH (g))
943
944 #define MARK_GLYPH_CHANGED(g) (GLYPH_DIRTYP (g) = 1);
945
946 extern Lisp_Object Qxpm, Qxface, Qetched_in, Qetched_out, Qbevel_in, Qbevel_out;
947 extern Lisp_Object Q_data, Q_file, Q_color_symbols, Qconst_glyph_variable;
948 extern Lisp_Object Qxbm, Qedit_field, Qgroup, Qlabel, Qcombo_box, Qscrollbar;
949 extern Lisp_Object Qtree_view, Qtab_control, Qprogress_gauge, Q_border;
950 extern Lisp_Object Q_mask_file, Q_mask_data, Q_hotspot_x, Q_hotspot_y;
951 extern Lisp_Object Q_foreground, Q_background, Q_face, Q_descriptor, Q_group;
952 extern Lisp_Object Q_width, Q_height, Q_pixel_width, Q_pixel_height, Q_text;
953 extern Lisp_Object Q_items, Q_properties, Q_image, Qimage_conversion_error;
954 extern Lisp_Object Q_orientation, Q_margin_width;
955 extern Lisp_Object Vcontinuation_glyph, Vcontrol_arrow_glyph, Vhscroll_glyph;
956 extern Lisp_Object Vinvisible_text_glyph, Voctal_escape_glyph, Vtruncation_glyph;
957 extern Lisp_Object Vxemacs_logo;
958
959
960 unsigned short glyph_width (Lisp_Object glyph, Lisp_Object domain);
961 unsigned short glyph_ascent (Lisp_Object glyph, Lisp_Object domain);
962 unsigned short glyph_descent (Lisp_Object glyph, Lisp_Object domain);
963 unsigned short glyph_height (Lisp_Object glyph, Lisp_Object domain);
964 Lisp_Object glyph_baseline (Lisp_Object glyph, Lisp_Object domain);
965 Lisp_Object glyph_face (Lisp_Object glyph, Lisp_Object domain);
966 int glyph_contrib_p (Lisp_Object glyph, Lisp_Object domain);
967 Lisp_Object glyph_image_instance (Lisp_Object glyph,
968                                   Lisp_Object domain,
969                                   Error_behavior errb, int no_quit);
970 void file_or_data_must_be_present (Lisp_Object instantiator);
971 void data_must_be_present (Lisp_Object instantiator);
972 Lisp_Object make_string_from_file (Lisp_Object file);
973 Lisp_Object tagged_vector_to_alist (Lisp_Object vector);
974 Lisp_Object alist_to_tagged_vector (Lisp_Object tag, Lisp_Object alist);
975 void string_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
976                          Lisp_Object pointer_fg, Lisp_Object pointer_bg,
977                          int dest_mask, Lisp_Object domain);
978 Lisp_Object allocate_glyph (enum glyph_type type,
979                             void (*after_change) (Lisp_Object glyph,
980                                                   Lisp_Object property,
981                                                   Lisp_Object locale));
982 void query_string_geometry ( Lisp_Object string, Lisp_Object face,
983                              int* width, int* height, int* descent, 
984                              Lisp_Object domain);
985 Lisp_Object query_string_font (Lisp_Object string,
986                                Lisp_Object face, Lisp_Object domain);
987 Lisp_Object add_glyph_animated_timeout (EMACS_INT tickms, Lisp_Object device);
988 void disable_glyph_animated_timeout (int i);
989
990 /************************************************************************/
991 /*                              Glyph Cachels                           */
992 /************************************************************************/
993
994 typedef struct glyph_cachel glyph_cachel;
995 struct glyph_cachel
996 {
997   Lisp_Object glyph;
998
999   unsigned int dirty :1;        /* I'm copying faces here. I'm not
1000                                    sure why we need two dirty
1001                                    flags. Maybe because an image
1002                                    instance can be dirty and so we
1003                                    need to frob this in the same way
1004                                    as other image instance properties.  */
1005   unsigned int updated :1;
1006
1007   unsigned short width;
1008   unsigned short ascent;
1009   unsigned short descent;
1010 };
1011
1012 #define CONT_GLYPH_INDEX        (glyph_index) 0
1013 #define TRUN_GLYPH_INDEX        (glyph_index) 1
1014 #define HSCROLL_GLYPH_INDEX     (glyph_index) 2
1015 #define CONTROL_GLYPH_INDEX     (glyph_index) 3
1016 #define OCT_ESC_GLYPH_INDEX     (glyph_index) 4
1017 #define INVIS_GLYPH_INDEX       (glyph_index) 5
1018
1019 #ifdef ERROR_CHECK_GLYPHS
1020
1021 #include "window.h"
1022
1023 INLINE_HEADER int
1024 GLYPH_CACHEL_WIDTH (struct window *window, int ind);
1025 INLINE_HEADER int
1026 GLYPH_CACHEL_WIDTH (struct window *window, int ind)
1027 {
1028   int wid = Dynarr_atp (window->glyph_cachels, ind)->width;
1029   assert (wid >= 0 && wid < 10000);
1030   return wid;
1031 }
1032 INLINE_HEADER int
1033 GLYPH_CACHEL_ASCENT (struct window *window, int ind);
1034 INLINE_HEADER int
1035 GLYPH_CACHEL_ASCENT (struct window *window, int ind)
1036 {
1037   int wid = Dynarr_atp (window->glyph_cachels, ind)->ascent;
1038   assert (wid >= 0 && wid < 10000);
1039   return wid;
1040 }
1041 INLINE_HEADER int
1042 GLYPH_CACHEL_DESCENT (struct window *window, int ind);
1043 INLINE_HEADER int
1044 GLYPH_CACHEL_DESCENT (struct window *window, int ind)
1045 {
1046   int wid = Dynarr_atp (window->glyph_cachels, ind)->descent;
1047   assert (wid >= 0 && wid < 10000);
1048   return wid;
1049 }
1050
1051 #else /* not ERROR_CHECK_GLYPHS */
1052
1053 #define GLYPH_CACHEL_WIDTH(window, ind)         \
1054   Dynarr_atp (window->glyph_cachels, ind)->width
1055 #define GLYPH_CACHEL_ASCENT(window, ind)                \
1056   Dynarr_atp (window->glyph_cachels, ind)->ascent
1057 #define GLYPH_CACHEL_DESCENT(window, ind)               \
1058   Dynarr_atp (window->glyph_cachels, ind)->descent
1059
1060 #endif /* not ERROR_CHECK_GLYPHS */
1061
1062 #define GLYPH_CACHEL(window, ind)                       \
1063   Dynarr_atp (window->glyph_cachels, ind)
1064 #define GLYPH_CACHEL_GLYPH(window, ind)         \
1065   Dynarr_atp (window->glyph_cachels, ind)->glyph
1066 #define GLYPH_CACHEL_DIRTYP(window, ind)                \
1067   Dynarr_atp (window->glyph_cachels, ind)->dirty
1068
1069 void mark_glyph_cachels (glyph_cachel_dynarr *elements);
1070 void mark_glyph_cachels_as_not_updated (struct window *w);
1071 void mark_glyph_cachels_as_clean (struct window *w);
1072 void reset_glyph_cachels (struct window *w);
1073 glyph_index get_glyph_cachel_index (struct window *w, Lisp_Object glyph);
1074
1075 #ifdef MEMORY_USAGE_STATS
1076 int compute_glyph_cachel_usage (glyph_cachel_dynarr *glyph_cachels,
1077                                 struct overhead_stats *ovstats);
1078 #endif /* MEMORY_USAGE_STATS */
1079
1080 /************************************************************************/
1081 /*                              Display Tables                          */
1082 /************************************************************************/
1083
1084 Lisp_Object display_table_entry (Emchar, Lisp_Object, Lisp_Object);
1085 void get_display_tables (struct window *, face_index,
1086                          Lisp_Object *, Lisp_Object *);
1087
1088 /****************************************************************************
1089  *                            Subwindow Object                              *
1090  ****************************************************************************/
1091
1092 void unmap_subwindow (Lisp_Object subwindow);
1093 void map_subwindow (Lisp_Object subwindow, int x, int y,
1094                     struct display_glyph_area *dga);
1095 int find_matching_subwindow (struct frame* f, int x, int y, int width, int height);
1096 void update_widget (Lisp_Object widget);
1097 void update_widget_instances (Lisp_Object frame);
1098 void update_subwindow (Lisp_Object subwindow);
1099 Lisp_Object image_instance_parent_glyph (struct Lisp_Image_Instance*);
1100 int image_instance_changed (Lisp_Object image);
1101 void free_frame_subwindow_instance_cache (struct frame* f);
1102 void reset_frame_subwindow_instance_cache (struct frame* f);
1103
1104 struct expose_ignore
1105 {
1106   unsigned int  x, y;
1107   unsigned int  width, height;
1108   struct expose_ignore *next;
1109 };
1110
1111 int check_for_ignored_expose (struct frame* f, int x, int y, int width, int height);
1112 extern int hold_ignored_expose_registration;
1113
1114 #endif /* INCLUDED_glyphs_h_ */