(linenum→info "unix/slp.c:2238")

emacs/22.1/src/dispextern.h

    1: /* Interface definitions for display code.
    2:    Copyright (C) 1985, 1993, 1994, 1997, 1998, 1999, 2000, 2001, 2002,
    3:                  2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
    4: 
    5: This file is part of GNU Emacs.
    6: 
    7: GNU Emacs is free software; you can redistribute it and/or modify
    8: it under the terms of the GNU General Public License as published by
    9: the Free Software Foundation; either version 2, or (at your option)
   10: any later version.
   11: 
   12: GNU Emacs is distributed in the hope that it will be useful,
   13: but WITHOUT ANY WARRANTY; without even the implied warranty of
   14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15: GNU General Public License for more details.
   16: 
   17: You should have received a copy of the GNU General Public License
   18: along with GNU Emacs; see the file COPYING.  If not, write to
   19: the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   20: Boston, MA 02110-1301, USA.  */
   21: 
   22: /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.  */
   23: 
   24: #ifndef DISPEXTERN_H_INCLUDED
   25: #define DISPEXTERN_H_INCLUDED
   26: 
   27: #ifdef HAVE_X_WINDOWS
   28: 
   29: #include <X11/Xlib.h>
   30: #ifdef USE_X_TOOLKIT
   31: #include <X11/Intrinsic.h>
   32: #endif /* USE_X_TOOLKIT */
   33: 
   34: #else /* !HAVE_X_WINDOWS */
   35: 
   36: /* X-related stuff used by non-X gui code. */
   37: 
   38: typedef struct {
   39:   unsigned long pixel;
   40:   unsigned short red, green, blue;
   41:   char flags;
   42:   char pad;
   43: } XColor;
   44: 
   45: #endif /* HAVE_X_WINDOWS */
   46: 
   47: #ifdef MSDOS
   48: #include "msdos.h"
   49: #endif
   50: 
   51: #ifdef HAVE_X_WINDOWS
   52: typedef struct x_display_info Display_Info;
   53: typedef XImage * XImagePtr;
   54: typedef XImagePtr XImagePtr_or_DC;
   55: #define NativeRectangle XRectangle
   56: #endif
   57: 
   58: #ifdef HAVE_NTGUI
   59: #include "w32gui.h"
   60: typedef struct w32_display_info Display_Info;
   61: typedef XImage *XImagePtr;
   62: typedef HDC XImagePtr_or_DC;
   63: #endif
   64: 
   65: #ifdef MAC_OS
   66: #include "macgui.h"
   67: typedef struct mac_display_info Display_Info;
   68: /* Mac equivalent of XImage.  */
   69: typedef Pixmap XImagePtr;
   70: typedef XImagePtr XImagePtr_or_DC;
   71: #endif
   72: 
   73: #ifndef NativeRectangle
   74: #define NativeRectangle int
   75: #endif
   76: 
   77: /* Structure forward declarations.  Some are here because function
   78:    prototypes below reference structure types before their definition
   79:    in this file.  Some are here because not every file including
   80:    dispextern.h also includes frame.h and windows.h.  */
   81: 
   82: struct glyph;
   83: struct glyph_row;
   84: struct glyph_matrix;
   85: struct glyph_pool;
   86: struct frame;
   87: struct window;
   88: 
   89: 
   90: /* Values returned from coordinates_in_window.  */
   91: 
   92: enum window_part
   93: {
   94:   ON_NOTHING,
   95:   ON_TEXT,
   96:   ON_MODE_LINE,
   97:   ON_VERTICAL_BORDER,
   98:   ON_HEADER_LINE,
   99:   ON_LEFT_FRINGE,
  100:   ON_RIGHT_FRINGE,
  101:   ON_LEFT_MARGIN,
  102:   ON_RIGHT_MARGIN,
  103:   ON_SCROLL_BAR
  104: };
  105: 
  106: /* Number of bits allocated to store fringe bitmap numbers.  */
  107: #define FRINGE_ID_BITS  16
  108: 
  109: 
  110: ^L
  111: /***********************************************************************
  112:                               Debugging
  113:  ***********************************************************************/
  114: 
  115: /* If GLYPH_DEBUG is non-zero, additional checks are activated.  Turn
  116:    it off by defining the macro GLYPH_DEBUG to zero.  */
  117: 
  118: #ifndef GLYPH_DEBUG
  119: #define GLYPH_DEBUG 0
  120: #endif
  121: 
  122: /* If XASSERTS is non-zero, additional consistency checks are activated.
  123:    Turn it off by defining the macro XASSERTS to zero.  */
  124: 
  125: #ifndef XASSERTS
  126: #define XASSERTS 0
  127: #endif
  128: 
  129: /* Macros to include code only if GLYPH_DEBUG != 0.  */
  130: 
  131: #if GLYPH_DEBUG
  132: #define IF_DEBUG(X)     X
  133: #else
  134: #define IF_DEBUG(X)     (void) 0
  135: #endif
  136: 
  137: #if XASSERTS
  138: #define xassert(X)      do {if (!(X)) abort ();} while (0)
  139: #else
  140: #define xassert(X)      (void) 0
  141: #endif
  142: 
  143: /* Macro for displaying traces of redisplay.  If Emacs was compiled
  144:    with GLYPH_DEBUG != 0, the variable trace_redisplay_p can be set to
  145:    a non-zero value in debugging sessions to activate traces.  */
  146: 
  147: #if GLYPH_DEBUG
  148: 
  149: extern int trace_redisplay_p;
  150: #include <stdio.h>
  151: 
  152: #define TRACE(X)                                \
  153:      if (trace_redisplay_p)                     \
  154:        fprintf X;                               \
  155:      else                                       \
  156:        (void) 0
  157: 
  158: #else /* GLYPH_DEBUG == 0 */
  159: 
  160: #define TRACE(X)        (void) 0
  161: 
  162: #endif /* GLYPH_DEBUG == 0 */
  163: 
  164: 
  165: ^L
  166: /***********************************************************************
  167:                             Text positions
  168:  ***********************************************************************/
  169: 
  170: /* Starting with Emacs 20.3, characters from strings and buffers have
  171:    both a character and a byte position associated with them.  The
  172:    following structure holds such a pair of positions.  */
  173: 
  174: struct text_pos
  175: {
  176:   /* Character position.  */
  177:   int charpos;
  178: 
  179:   /* Corresponding byte position.  */
  180:   int bytepos;
  181: };
  182: 
  183: /* Access character and byte position of POS in a functional form.  */
  184: 
  185: #define BYTEPOS(POS)    (POS).bytepos
  186: #define CHARPOS(POS)    (POS).charpos
  187: 
  188: /* Set character position of POS to CHARPOS, byte position to BYTEPOS.  */
  189: 
  190: #define SET_TEXT_POS(POS, CHARPOS, BYTEPOS) \
  191:      ((POS).charpos = (CHARPOS), (POS).bytepos = BYTEPOS)
  192: 
  193: /* Increment text position POS.  */
  194: 
  195: #define INC_TEXT_POS(POS, MULTIBYTE_P)          \
  196:      do                                         \
  197:        {                                        \
  198:          ++(POS).charpos;                      \
  199:          if (MULTIBYTE_P)                       \
  200:            INC_POS ((POS).bytepos);            \
  201:          else                                  \
  202:            ++(POS).bytepos;                    \
  203:        }                                        \
  204:      while (0)
  205: 
  206: /* Decrement text position POS.  */
  207: 
  208: #define DEC_TEXT_POS(POS, MULTIBYTE_P)          \
  209:      do                                         \
  210:        {                                        \
  211:          --(POS).charpos;                      \
  212:          if (MULTIBYTE_P)                       \
  213:            DEC_POS ((POS).bytepos);            \
  214:          else                                  \
  215:            --(POS).bytepos;                    \
  216:        }                                        \
  217:      while (0)
  218: 
  219: /* Set text position POS from marker MARKER.  */
  220: 
  221: #define SET_TEXT_POS_FROM_MARKER(POS, MARKER)           \
  222:      (CHARPOS (POS) = marker_position ((MARKER)),       \
  223:       BYTEPOS (POS) = marker_byte_position ((MARKER)))
  224: 
  225: /* Set marker MARKER from text position POS.  */
  226: 
  227: #define SET_MARKER_FROM_TEXT_POS(MARKER, POS) \
  228:      set_marker_both ((MARKER), Qnil, CHARPOS ((POS)), BYTEPOS ((POS)))
  229: 
  230: /* Value is non-zero if character and byte positions of POS1 and POS2
  231:    are equal.  */
  232: 
  233: #define TEXT_POS_EQUAL_P(POS1, POS2)            \
  234:      ((POS1).charpos == (POS2).charpos          \
  235:       && (POS1).bytepos == (POS2).bytepos)
  236: 
  237: /* When rendering glyphs, redisplay scans string or buffer text,
  238:    overlay strings in that text, and does display table or control
  239:    character translations.  The following structure captures a
  240:    position taking all this into account.  */
  241: 
  242: struct display_pos
  243: {
  244:   /* Buffer or string position.  */
  245:   struct text_pos pos;
  246: 
  247:   /* If this is a position in an overlay string, overlay_string_index
  248:      is the index of that overlay string in the sequence of overlay
  249:      strings at `pos' in the order redisplay processes them.  A value
  250:      < 0 means that this is not a position in an overlay string.  */
  251:   int overlay_string_index;
  252: 
  253:   /* If this is a position in an overlay string, string_pos is the
  254:      position within that string.  */
  255:   struct text_pos string_pos;
  256: 
  257:   /* If the character at the position above is a control character or
  258:      has a display table entry, dpvec_index is an index in the display
  259:      table or control character translation of that character.  A
  260:      value < 0 means this is not a position in such a translation.  */
  261:   int dpvec_index;
  262: };
  263: 
  264: 
  265: ^L
  266: /***********************************************************************
  267:                                 Glyphs
  268:  ***********************************************************************/
  269: 
  270: /* Enumeration of glyph types.  Glyph structures contain a type field
  271:    containing one of the enumerators defined here.  */
  272: 
  273: enum glyph_type
  274: {
  275:   /* Glyph describes a character.  */
  276:   CHAR_GLYPH,
  277: 
  278:   /* Glyph describes a composition sequence.  */
  279:   COMPOSITE_GLYPH,
  280: 
  281:   /* Glyph describes an image.  */
  282:   IMAGE_GLYPH,
  283: 
  284:   /* Glyph is a space of fractional width and/or height.  */
  285:   STRETCH_GLYPH
  286: };
  287: 
  288: 
  289: /* Structure describing how to use partial glyphs (images slicing) */
  290: 
  291: struct glyph_slice
  292: {
  293:   unsigned x : 16;
  294:   unsigned y : 16;
  295:   unsigned width : 16;
  296:   unsigned height : 16;
  297: };
  298: 
  299: 
  300: /* Glyphs.
  301: 
  302:    Be extra careful when changing this structure!  Esp. make sure that
  303:    functions producing glyphs, like append_glyph, fill ALL of the
  304:    glyph structure, and that GLYPH_EQUAL_P compares all
  305:    display-relevant members of glyphs (not to imply that these are the
  306:    only things to check when you add a member).  */
  307: 
  308: struct glyph
  309: {
  310:   /* Position from which this glyph was drawn.  If `object' below is a
  311:      Lisp string, this is a position in that string.  If it is a
  312:      buffer, this is a position in that buffer.  A value of -1
  313:      together with a null object means glyph is a truncation glyph at
  314:      the start of a row.  */
  315:   int charpos;
  316: 
  317:   /* Lisp object source of this glyph.  Currently either a buffer or
  318:      a string, if the glyph was produced from characters which came from
  319:      a buffer or a string; or 0 if the glyph was inserted by redisplay
  320:      for its own purposes such as padding.  */
  321:   Lisp_Object object;
  322: 
  323:   /* Width in pixels.  */
  324:   short pixel_width;
  325: 
  326:   /* Ascent and descent in pixels.  */
  327:   short ascent, descent;
  328: 
  329:   /* Vertical offset.  If < 0, the glyph is displayed raised, if > 0
  330:      the glyph is displayed lowered.  */
  331:   short voffset;
  332: 
  333:   /* Which kind of glyph this is---character, image etc.  Value
  334:      should be an enumerator of type enum glyph_type.  */
  335:   unsigned type : 2;
  336: 
  337:   /* 1 means this glyph was produced from multibyte text.  Zero
  338:      means it was produced from unibyte text, i.e. charsets aren't
  339:      applicable, and encoding is not performed.  */
  340:   unsigned multibyte_p : 1;
  341: 
  342:   /* Non-zero means draw a box line at the left or right side of this
  343:      glyph.  This is part of the implementation of the face attribute
  344:      `:box'.  */
  345:   unsigned left_box_line_p : 1;
  346:   unsigned right_box_line_p : 1;
  347: 
  348:   /* Non-zero means this glyph's physical ascent or descent is greater
  349:      than its logical ascent/descent, i.e. it may potentially overlap
  350:      glyphs above or below it.  */
  351:   unsigned overlaps_vertically_p : 1;
  352: 
  353:   /* 1 means glyph is a padding glyph.  Padding glyphs are used for
  354:      characters whose visual shape consists of more than one glyph
  355:      (e.g. Asian characters).  All but the first glyph of such a glyph
  356:      sequence have the padding_p flag set.  Only used for terminal
  357:      frames, and there only to minimize code changes.  A better way
  358:      would probably be to use the width field of glyphs to express
  359:      padding. */
  360:   unsigned padding_p : 1;
  361: 
  362:   /* 1 means the actual glyph is not available, draw a box instead.
  363:      This can happen when a font couldn't be loaded, or a character
  364:      doesn't have a glyph in a font.  */
  365:   unsigned glyph_not_available_p : 1;
  366: 
  367: #define FACE_ID_BITS    21
  368: 
  369:   /* Face of the glyph.  This is a realized face ID,
  370:      an index in the face cache of the frame.  */
  371:   unsigned face_id : FACE_ID_BITS;
  372: 
  373:   /* Type of font used to display the character glyph.  May be used to
  374:      determine which set of functions to use to obtain font metrics
  375:      for the glyph.  On W32, value should be an enumerator of the type
  376:      w32_char_font_type.  Otherwise it equals FONT_TYPE_UNKNOWN.  */
  377:   unsigned font_type : 3;
  378: 
  379:   struct glyph_slice slice;
  380: 
  381:   /* A union of sub-structures for different glyph types.  */
  382:   union
  383:   {
  384:     /* Character code for character glyphs (type == CHAR_GLYPH).  */
  385:     unsigned ch;
  386: 
  387:     /* Composition ID for composition glyphs (type == COMPOSITION_GLYPH)  */
  388:     unsigned cmp_id;
  389: 
  390:     /* Image ID for image glyphs (type == IMAGE_GLYPH).  */
  391:     unsigned img_id;
  392: 
  393:     /* Sub-structure for type == STRETCH_GLYPH.  */
  394:     struct
  395:     {
  396:       /* The height of the glyph.  */
  397:       unsigned height  : 16;
  398: 
  399:       /* The ascent of the glyph.  */
  400:       unsigned ascent  : 16;
  401:     }
  402:     stretch;
  403: 
  404:     /* Used to compare all bit-fields above in one step.  */
  405:     unsigned val;
  406:   } u;
  407: };
  408: 
  409: 
  410: /* Default value of the glyph font_type field.  */
  411: 
  412: #define FONT_TYPE_UNKNOWN       0
  413: 
  414: /* Is GLYPH a space?  */
  415: 
  416: #define CHAR_GLYPH_SPACE_P(GLYPH) \
  417:      (GLYPH_FROM_CHAR_GLYPH ((GLYPH)) == SPACEGLYPH)
  418: 
  419: /* Are glyph slices of glyphs *X and *Y equal */
  420: 
  421: #define GLYPH_SLICE_EQUAL_P(X, Y)               \
  422:   ((X)->slice.x == (Y)->slice.x                 \
  423:    && (X)->slice.y == (Y)->slice.y              \
  424:    && (X)->slice.width == (Y)->slice.width      \
  425:    && (X)->slice.height == (Y)->slice.height)
  426: 
  427: /* Are glyphs *X and *Y displayed equal?  */
  428: 
  429: #define GLYPH_EQUAL_P(X, Y)                                     \
  430:      ((X)->type == (Y)->type                                    \
  431:       && (X)->u.val == (Y)->u.val                               \
  432:       && GLYPH_SLICE_EQUAL_P (X, Y)                             \
  433:       && (X)->face_id == (Y)->face_id                           \
  434:       && (X)->padding_p == (Y)->padding_p                       \
  435:       && (X)->left_box_line_p == (Y)->left_box_line_p           \
  436:       && (X)->right_box_line_p == (Y)->right_box_line_p         \
  437:       && (X)->voffset == (Y)->voffset                           \
  438:       && (X)->pixel_width == (Y)->pixel_width)
  439: 
  440: /* Are character codes, faces, padding_ps of glyphs *X and *Y equal?  */
  441: 
  442: #define GLYPH_CHAR_AND_FACE_EQUAL_P(X, Y)       \
  443:   ((X)->u.ch == (Y)->u.ch                       \
  444:    && (X)->face_id == (Y)->face_id              \
  445:    && (X)->padding_p == (Y)->padding_p)
  446: 
  447: /* Fill a character glyph GLYPH.  CODE, FACE_ID, PADDING_P correspond
  448:    to the bits defined for the typedef `GLYPH' in lisp.h.  */
  449: 
  450: #define SET_CHAR_GLYPH(GLYPH, CODE, FACE_ID, PADDING_P) \
  451:      do                                                 \
  452:        {                                                \
  453:          (GLYPH).u.ch = (CODE);                         \
  454:          (GLYPH).face_id = (FACE_ID);                   \
  455:          (GLYPH).padding_p = (PADDING_P);               \
  456:        }                                                \
  457:      while (0)
  458: 
  459: /* Fill a character type glyph GLYPH from a glyph typedef FROM as
  460:    defined in lisp.h.  */
  461: 
  462: #define SET_CHAR_GLYPH_FROM_GLYPH(GLYPH, FROM)                  \
  463:      SET_CHAR_GLYPH ((GLYPH),                                   \
  464:                     FAST_GLYPH_CHAR ((FROM)),                       \
  465:                      FAST_GLYPH_FACE ((FROM)),                        \
  466:                      0)
  467: 
  468: /* Construct a glyph code from a character glyph GLYPH.  If the
  469:    character is multibyte, return -1 as we can't use glyph table for a
  470:    multibyte character.  */
  471: 
  472: #define GLYPH_FROM_CHAR_GLYPH(GLYPH)                            \
  473:   ((GLYPH).u.ch < 256                                           \
  474:    ? ((GLYPH).u.ch | ((GLYPH).face_id << CHARACTERBITS))        \
  475:    : -1)
  476: 
  477: /* Is GLYPH a padding glyph?  */
  478: 
  479: #define CHAR_GLYPH_PADDING_P(GLYPH) (GLYPH).padding_p
  480: 
  481: 
  482: 
  483: ^L
  484: /***********************************************************************
  485:                              Glyph Pools
  486:  ***********************************************************************/
  487: 
  488: /* Glyph Pool.
  489: 
  490:    Glyph memory for frame-based redisplay is allocated from the heap
  491:    in one vector kept in a glyph pool structure which is stored with
  492:    the frame.  The size of the vector is made large enough to cover
  493:    all windows on the frame.
  494: 
  495:    Both frame and window glyph matrices reference memory from a glyph
  496:    pool in frame-based redisplay.
  497: 
  498:    In window-based redisplay, no glyphs pools exist; windows allocate
  499:    and free their glyph memory themselves.  */
  500: 
  501: struct glyph_pool
  502: {
  503:   /* Vector of glyphs allocated from the heap.  */
  504:   struct glyph *glyphs;
  505: 
  506:   /* Allocated size of `glyphs'.  */
  507:   int nglyphs;
  508: 
  509:   /* Number of rows and columns in a matrix.  */
  510:   int nrows, ncolumns;
  511: };
  512: 
  513: 
  514: ^L
  515: /***********************************************************************
  516:                              Glyph Matrix
  517:  ***********************************************************************/
  518: 
  519: /* Glyph Matrix.
  520: 
  521:    Three kinds of glyph matrices exist:
  522: 
  523:    1. Frame glyph matrices.  These are used for terminal frames whose
  524:    redisplay needs a view of the whole screen due to limited terminal
  525:    capabilities.  Frame matrices are used only in the update phase
  526:    of redisplay.  They are built in update_frame and not used after
  527:    the update has been performed.
  528: 
  529:    2. Window glyph matrices on frames having frame glyph matrices.
  530:    Such matrices are sub-matrices of their corresponding frame matrix,
  531:    i.e. frame glyph matrices and window glyph matrices share the same
  532:    glyph memory which is allocated in form of a glyph_pool structure.
  533:    Glyph rows in such a window matrix are slices of frame matrix rows.
  534: 
  535:    2. Free-standing window glyph matrices managing their own glyph
  536:    storage.  This form is used in window-based redisplay which
  537:    includes variable width and height fonts etc.
  538: 
  539:    The size of a window's row vector depends on the height of fonts
  540:    defined on its frame.  It is chosen so that the vector is large
  541:    enough to describe all lines in a window when it is displayed in
  542:    the smallest possible character size.  When new fonts are loaded,
  543:    or window sizes change, the row vector is adjusted accordingly.  */
  544: 
  545: struct glyph_matrix
  546: {
  547:   /* The pool from which glyph memory is allocated, if any.  This is
  548:      null for frame matrices and for window matrices managing their
  549:      own storage.  */
  550:   struct glyph_pool *pool;
  551: 
  552:   /* Vector of glyph row structures.  The row at nrows - 1 is reserved
  553:      for the mode line.  */
  554:   struct glyph_row *rows;
  555: 
  556:   /* Number of elements allocated for the vector rows above.  */
  557:   int rows_allocated;
  558: 
  559:   /* The number of rows used by the window if all lines were displayed
  560:      with the smallest possible character height.  */
  561:   int nrows;
  562: 
  563:   /* Origin within the frame matrix if this is a window matrix on a
  564:      frame having a frame matrix.  Both values are zero for
  565:      window-based redisplay.  */
  566:   int matrix_x, matrix_y;
  567: 
  568:   /* Width and height of the matrix in columns and rows.  */
  569:   int matrix_w, matrix_h;
  570: 
  571:   /* If this structure describes a window matrix of window W,
  572:      window_left_col is the value of W->left_col, window_top_line the
  573:      value of W->top_line, window_height and window_width are width and
  574:      height of W, as returned by window_box, and window_vscroll is the
  575:      value of W->vscroll at the time the matrix was last adjusted.
  576:      Only set for window-based redisplay.  */
  577:   int window_left_col, window_top_line;
  578:   int window_height, window_width;
  579:   int window_vscroll;
  580: 
  581:   /* Number of glyphs reserved for left and right marginal areas when
  582:      the matrix was last adjusted.  */
  583:   int left_margin_glyphs, right_margin_glyphs;
  584: 
  585:   /* Flag indicating that scrolling should not be tried in
  586:      update_window.  This flag is set by functions like try_window_id
  587:      which do their own scrolling.  */
  588:   unsigned no_scrolling_p : 1;
  589: 
  590:   /* Non-zero means window displayed in this matrix has a top mode
  591:      line.  */
  592:   unsigned header_line_p : 1;
  593: 
  594: #ifdef GLYPH_DEBUG
  595:   /* A string identifying the method used to display the matrix.  */
  596:   char method[512];
  597: #endif
  598: 
  599:   /* The buffer this matrix displays.  Set in
  600:      mark_window_display_accurate_1.  */
  601:   struct buffer *buffer;
  602: 
  603:   /* Values of BEGV and ZV as of last redisplay.  Set in
  604:      mark_window_display_accurate_1.  */
  605:   int begv, zv;
  606: };
  607: 
  608: 
  609: /* Check that glyph pointers stored in glyph rows of MATRIX are okay.
  610:    This aborts if any pointer is found twice.  */
  611: 
  612: #if GLYPH_DEBUG
  613: void check_matrix_pointer_lossage P_ ((struct glyph_matrix *));
  614: #define CHECK_MATRIX(MATRIX) check_matrix_pointer_lossage ((MATRIX))
  615: #else
  616: #define CHECK_MATRIX(MATRIX) (void) 0