Commit c0e146e4 authored by Alexander Gramiak's avatar Alexander Gramiak

Introduce Emacs_Color struct and typedef

This avoids clashing with the XColor struct from X.

* src/dispextern [HAVE_X_WINDOWS]: Define Emacs_Color alias.
[!HAVE_X_WINDOWS]: Rename XColor compatibility struct to
Emacs_Color. Remove unused fields.

* src/gtkutil.c:
* src/gtkutil.h:
* src/image.c:
* src/nsterm.h:
* src/nsterm.m:
* src/termhooks.h:
* src/w32fns.c:
* src/w32term.c:
* src/w32term.h:
* src/xfaces.c:
* src/xfns.c:
* src/xterm.h: Use Emacs_Color over XColor outside of X-specific
sections.
parent 05b79539
......@@ -34,16 +34,17 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
#ifdef HAVE_XRENDER
# include <X11/extensions/Xrender.h>
#endif
typedef XColor Emacs_Color;
#else /* !HAVE_X_WINDOWS */
/* X-related stuff used by non-X gui code. */
/* XColor-like struct used by non-X code. */
typedef struct {
typedef struct
{
unsigned long pixel;
unsigned short red, green, blue;
char flags;
char pad;
} XColor;
} Emacs_Color;
#endif /* HAVE_X_WINDOWS */
......@@ -3410,8 +3411,8 @@ void x_free_colors (struct frame *, unsigned long *, int);
void update_face_from_frame_parameter (struct frame *, Lisp_Object,
Lisp_Object);
extern bool tty_defined_color (struct frame *f, const char *, XColor *, bool,
bool);
extern bool tty_defined_color (struct frame *, const char *, Emacs_Color *,
bool, bool);
Lisp_Object tty_color_name (struct frame *, int);
void clear_face_cache (bool);
......
......@@ -520,7 +520,7 @@ get_utf8_string (const char *str)
bool
xg_check_special_colors (struct frame *f,
const char *color_name,
XColor *color)
Emacs_Color *color)
{
bool success_p = 0;
bool get_bg = strcmp ("gtk_selection_bg_color", color_name) == 0;
......
......@@ -166,7 +166,7 @@ extern void xg_free_frame_widgets (struct frame *f);
extern void xg_set_background_color (struct frame *f, unsigned long bg);
extern bool xg_check_special_colors (struct frame *f,
const char *color_name,
XColor *color);
Emacs_Color *color);
extern void xg_set_frame_icon (struct frame *f,
Pixmap icon_pixmap,
......
......@@ -1076,10 +1076,10 @@ image_ascent (struct image *img, struct face *face, struct glyph_slice *slice)
#ifdef USE_CAIRO
static uint32_t
xcolor_to_argb32 (XColor xc)
emacs_color_to_argb32 (Emacs_Color *ec)
{
return ((0xffu << 24) | ((xc.red / 256) << 16)
| ((xc.green / 256) << 8) | (xc.blue / 256));
return ((0xffu << 24) | ((ec->red / 256) << 16)
| ((ec->green / 256) << 8) | (ec->blue / 256));
}
static uint32_t
......@@ -1087,11 +1087,11 @@ get_spec_bg_or_alpha_as_argb (struct image *img,
struct frame *f)
{
uint32_t bgcolor = 0;
XColor xbgcolor;
Emacs_Color xbgcolor;
Lisp_Object bg = image_spec_value (img->spec, QCbackground, NULL);
if (STRINGP (bg) && x_parse_color (f, SSDATA (bg), &xbgcolor))
bgcolor = xcolor_to_argb32 (xbgcolor);
bgcolor = emacs_color_to_argb32 (&xbgcolor);
return bgcolor;
}
......@@ -1321,7 +1321,7 @@ static unsigned long
image_alloc_image_color (struct frame *f, struct image *img,
Lisp_Object color_name, unsigned long dflt)
{
XColor color;
Emacs_Color color;
unsigned long result;
eassert (STRINGP (color_name));
......@@ -4286,7 +4286,7 @@ xpm_load_image (struct frame *f,
char *color, *max_color;
int key, next_key, max_key = 0;
Lisp_Object symbol_color = Qnil, color_val;
XColor cdef;
Emacs_Color cdef;
expect (XPM_TK_STRING);
if (len <= chars_per_pixel || len >= BUFSIZ + chars_per_pixel)
......@@ -4772,17 +4772,17 @@ static int laplace_matrix[9] = {
#define COLOR_INTENSITY(R, G, B) ((2 * (R) + 3 * (G) + (B)) / 6)
/* On frame F, return an array of XColor structures describing image
IMG->pixmap. Each XColor structure has its pixel color set. RGB_P
means also fill the red/green/blue members of the XColor
structures. Value is a pointer to the array of XColors structures,
/* On frame F, return an array of Emacs_Color structures describing image
IMG->pixmap. Each Emacs_Color structure has its pixel color set. RGB_P
means also fill the red/green/blue members of the Emacs_Color
structures. Value is a pointer to the array of Emacs_Color structures,
allocated with xmalloc; it must be freed by the caller. */
static XColor *
image_to_xcolors (struct frame *f, struct image *img, bool rgb_p)
static Emacs_Color *
image_to_emacs_colors (struct frame *f, struct image *img, bool rgb_p)
{
int x, y;
XColor *colors, *p;
Emacs_Color *colors, *p;
XImagePtr_or_DC ximg;
ptrdiff_t nbytes;
#ifdef HAVE_NTGUI
......@@ -4798,13 +4798,13 @@ image_to_xcolors (struct frame *f, struct image *img, bool rgb_p)
/* Get the X image or create a memory device context for IMG. */
ximg = image_get_x_image_or_dc (f, img, 0, &prev);
/* Fill the `pixel' members of the XColor array. I wished there
/* Fill the `pixel' members of the Emacs_Color array. I wished there
were an easy and portable way to circumvent XGetPixel. */
p = colors;
for (y = 0; y < img->height; ++y)
{
#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
XColor *row = p;
Emacs_Color *row = p;
for (x = 0; x < img->width; ++x, ++p)
p->pixel = GET_PIXEL (ximg, x, y);
if (rgb_p)
......@@ -4878,16 +4878,16 @@ XPutPixel (XImagePtr ximg, int x, int y, COLORREF color)
#endif /* HAVE_NTGUI */
/* Create IMG->pixmap from an array COLORS of XColor structures, whose
/* Create IMG->pixmap from an array COLORS of Emacs_Color structures, whose
RGB members are set. F is the frame on which this all happens.
COLORS will be freed; an existing IMG->pixmap will be freed, too. */
static void
image_from_xcolors (struct frame *f, struct image *img, XColor *colors)
image_from_emacs_colors (struct frame *f, struct image *img, Emacs_Color *colors)
{
int x, y;
XImagePtr oimg = NULL;
XColor *p;
Emacs_Color *p;
init_color_table ();
......@@ -4925,8 +4925,8 @@ static void
image_detect_edges (struct frame *f, struct image *img,
int *matrix, int color_adjust)
{
XColor *colors = image_to_xcolors (f, img, 1);
XColor *new, *p;
Emacs_Color *colors = image_to_emacs_colors (f, img, 1);
Emacs_Color *new, *p;
int x, y, i, sum;
ptrdiff_t nbytes;
......@@ -4969,7 +4969,7 @@ image_detect_edges (struct frame *f, struct image *img,
for (xx = x - 1; xx < x + 2; ++xx, ++i)
if (matrix[i])
{
XColor *t = COLOR (colors, xx, yy);
Emacs_Color *t = COLOR (colors, xx, yy);
r += matrix[i] * t->red;
g += matrix[i] * t->green;
b += matrix[i] * t->blue;
......@@ -4983,7 +4983,7 @@ image_detect_edges (struct frame *f, struct image *img,
}
xfree (colors);
image_from_xcolors (f, img, new);
image_from_emacs_colors (f, img, new);
#undef COLOR
}
......@@ -5066,8 +5066,8 @@ image_disable_image (struct frame *f, struct image *img)
/* Color (or grayscale). Convert to gray, and equalize. Just
drawing such images with a stipple can look very odd, so
we're using this method instead. */
XColor *colors = image_to_xcolors (f, img, 1);
XColor *p, *end;
Emacs_Color *colors = image_to_emacs_colors (f, img, 1);
Emacs_Color *p, *end;
const int h = 15000;
const int l = 30000;
......@@ -5080,7 +5080,7 @@ image_disable_image (struct frame *f, struct image *img)
p->red = p->green = p->blue = i2;
}
image_from_xcolors (f, img, colors);
image_from_emacs_colors (f, img, colors);
}
/* Draw a cross over the disabled image, if we must or if we
......@@ -5522,7 +5522,7 @@ pbm_load (struct frame *f, struct image *img)
unsigned long fg = FRAME_FOREGROUND_PIXEL (f);
unsigned long bg = FRAME_BACKGROUND_PIXEL (f);
#ifdef USE_CAIRO
XColor xfg, xbg;
Emacs_Color xfg, xbg;
int fga32, bga32;
#endif
/* Parse the image specification. */
......@@ -5542,7 +5542,7 @@ pbm_load (struct frame *f, struct image *img)
xfg.pixel = fg;
x_query_colors (f, &xfg, 1);
}
fga32 = xcolor_to_argb32 (xfg);
fga32 = emacs_color_to_argb32 (&xfg);
if (! fmt[PBM_BACKGROUND].count
|| ! STRINGP (fmt[PBM_BACKGROUND].value)
......@@ -5555,7 +5555,7 @@ pbm_load (struct frame *f, struct image *img)
xbg.pixel = bg;
x_query_colors (f, &xbg, 1);
}
bga32 = xcolor_to_argb32 (xbg);
bga32 = emacs_color_to_argb32 (&xbg);
#else
if (fmt[PBM_FOREGROUND].count
&& STRINGP (fmt[PBM_FOREGROUND].value))
......@@ -6180,7 +6180,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
/* png_color_16 *image_bg; */
Lisp_Object specified_bg
= image_spec_value (img->spec, QCbackground, NULL);
XColor color;
Emacs_Color color;
/* If the user specified a color, try to use it; if not, use the
current frame background, ignoring any default background
......@@ -7813,7 +7813,7 @@ gif_load (struct frame *f, struct image *img)
uint32_t *data32 = (uint32_t *) cairo_image_surface_get_data (surface);
if (STRINGP (specified_bg))
{
XColor color;
Emacs_Color color;
if (FRAME_TERMINAL (f)->defined_color_hook
(f, SSDATA (specified_bg), &color, false, false))
{
......@@ -8548,7 +8548,7 @@ imagemagick_load_image (struct frame *f, struct image *img,
/* Retrieve the frame's background color, for use later. */
{
XColor bgcolor;
Emacs_Color bgcolor;
Lisp_Object specified_bg;
specified_bg = image_spec_value (img->spec, QCbackground, NULL);
......@@ -9285,7 +9285,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
/* Handle alpha channel by combining the image with a background
color. */
XColor background;
Emacs_Color background;
Lisp_Object specified_bg = image_spec_value (img->spec, QCbackground, NULL);
if (!STRINGP (specified_bg)
|| !FRAME_TERMINAL (f)->defined_color_hook (f,
......
......@@ -109,11 +109,6 @@ typedef void *Cursor;
#define No_Cursor (0)
#ifdef __OBJC__
typedef NSColor * Color;
#else
typedef void * Color;
#endif
typedef int Window;
......
......@@ -1134,10 +1134,10 @@ extern void ns_set_doc_edited (void);
extern bool
ns_defined_color (struct frame *f,
const char *name,
XColor *color_def, bool alloc,
Emacs_Color *color_def, bool alloc,
bool makeIndex);
extern void
ns_query_color (void *col, XColor *color_def, bool setPixel);
ns_query_color (void *col, Emacs_Color *color_def, bool setPixel);
#ifdef __OBJC__
extern int ns_lisp_to_color (Lisp_Object color, NSColor **col);
......
......@@ -2327,7 +2327,7 @@ so some key presses (TAB) are swallowed by the system. */
}
void
ns_query_color(void *col, XColor *color_def, bool setPixel)
ns_query_color(void *col, Emacs_Color *color_def, bool setPixel)
/* --------------------------------------------------------------------------
Get ARGB values out of NSColor col and put them into color_def.
If setPixel, set the pixel to a concatenated version.
......@@ -2350,7 +2350,7 @@ so some key presses (TAB) are swallowed by the system. */
bool
ns_defined_color (struct frame *f,
const char *name,
XColor *color_def,
Emacs_Color *color_def,
bool alloc,
bool makeIndex)
/* --------------------------------------------------------------------------
......@@ -2378,7 +2378,7 @@ so some key presses (TAB) are swallowed by the system. */
}
static void
ns_query_frame_background_color (struct frame *f, XColor *bgcolor)
ns_query_frame_background_color (struct frame *f, Emacs_Color *bgcolor)
/* --------------------------------------------------------------------------
External (hook): Store F's background color into *BGCOLOR
-------------------------------------------------------------------------- */
......
......@@ -496,7 +496,7 @@ struct terminal
If MAKEINDEX (on NS), set COLOR_DEF pixel to ARGB. */
bool (*defined_color_hook) (struct frame *f, const char *color_name,
XColor *color_def,
Emacs_Color *color_def,
bool alloc,
bool makeIndex);
......@@ -515,13 +515,13 @@ struct terminal
/* This hook is called to store the frame's background color into
BGCOLOR. */
void (*query_frame_background_color) (struct frame *f, XColor *bgcolor);
void (*query_frame_background_color) (struct frame *f, Emacs_Color *bgcolor);
#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
/* On frame F, translate pixel colors to RGB values for the NCOLORS
colors in COLORS. Use cached information, if available. */
void (*query_colors) (struct frame *f, XColor *colors, int ncolors);
void (*query_colors) (struct frame *f, Emacs_Color *colors, int ncolors);
#endif
/* Return the current position of the mouse.
......
......@@ -1174,7 +1174,7 @@ gamma_correct (struct frame *f, COLORREF *color)
If ALLOC is nonzero, allocate a new colormap cell. */
bool
w32_defined_color (struct frame *f, const char *color, XColor *color_def,
w32_defined_color (struct frame *f, const char *color, Emacs_Color *color_def,
bool alloc_p, bool _makeIndex)
{
register Lisp_Object tem;
......@@ -1248,7 +1248,7 @@ w32_defined_color (struct frame *f, const char *color, XColor *color_def,
static int
w32_decode_color (struct frame *f, Lisp_Object arg, int def)
{
XColor cdef;
Emacs_Color cdef;
CHECK_STRING (arg);
......@@ -6100,7 +6100,7 @@ DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
doc: /* SKIP: real doc in xfns.c. */)
(Lisp_Object color, Lisp_Object frame)
{
XColor foo;
Emacs_Color foo;
struct frame *f = decode_window_system_frame (frame);
CHECK_STRING (color);
......@@ -6115,7 +6115,7 @@ DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
doc: /* SKIP: real doc in xfns.c. */)
(Lisp_Object color, Lisp_Object frame)
{
XColor foo;
Emacs_Color foo;
struct frame *f = decode_window_system_frame (frame);
CHECK_STRING (color);
......
......@@ -43,7 +43,6 @@ typedef HBITMAP Pixmap;
typedef HBITMAP Bitmap;
typedef XGCValues * GC;
typedef COLORREF Color;
typedef HWND Window;
typedef HDC Display; /* HDC so it doesn't conflict with xpm lib. */
typedef HCURSOR Cursor;
......
......@@ -1517,7 +1517,7 @@ w32_alloc_lighter_color (struct frame *f, COLORREF *color,
colors in COLORS. On W32, we no longer try to map colors to
a palette. */
static void
w32_query_colors (struct frame *f, XColor *colors, int ncolors)
w32_query_colors (struct frame *f, Emacs_Color *colors, int ncolors)
{
int i;
......@@ -1534,7 +1534,7 @@ w32_query_colors (struct frame *f, XColor *colors, int ncolors)
/* Store F's background color into *BGCOLOR. */
static void
w32_query_frame_background_color (struct frame *f, XColor *bgcolor)
w32_query_frame_background_color (struct frame *f, Emacs_Color *bgcolor)
{
bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
w32_query_colors (f, bgcolor, 1);
......@@ -7208,7 +7208,7 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
/* initialize palette with white and black */
{
XColor color;
Emacs_Color color;
w32_defined_color (0, "white", &color, true, false);
w32_defined_color (0, "black", &color, true, false);
}
......
......@@ -241,7 +241,7 @@ extern void w32_set_scroll_bar_default_height (struct frame *);
extern struct w32_display_info *w32_term_init (Lisp_Object,
char *, char *);
extern bool w32_defined_color (struct frame *, const char *, XColor *,
extern bool w32_defined_color (struct frame *, const char *, Emacs_Color *,
bool, bool);
extern int w32_display_pixel_height (struct w32_display_info *);
extern int w32_display_pixel_width (struct w32_display_info *);
......@@ -721,7 +721,7 @@ extern void complete_deferred_msg (HWND hwnd, UINT msg, LRESULT result);
extern BOOL parse_button (int, int, int *, int *);
extern void w32_sys_ring_bell (struct frame *f);
extern void w32_query_color (struct frame *, XColor *);
extern void w32_query_color (struct frame *, Emacs_Color *);
extern void w32_delete_display (struct w32_display_info *dpyinfo);
#define FILE_NOTIFICATIONS_SIZE 16384
......
......@@ -348,7 +348,7 @@ static void free_face_cache (struct face_cache *);
static bool merge_face_ref (struct window *w,
struct frame *, Lisp_Object, Lisp_Object *,
bool, struct named_merge_point *);
static int color_distance (XColor *x, XColor *y);
static int color_distance (Emacs_Color *x, Emacs_Color *y);
#ifdef HAVE_WINDOW_SYSTEM
static void set_font_frame_param (Lisp_Object, Lisp_Object);
......@@ -802,7 +802,7 @@ load_pixmap (struct frame *f, Lisp_Object name)
/***********************************************************************
X Colors
Color Handling
***********************************************************************/
/* Parse RGB_LIST, and fill in the RGB fields of COLOR.
......@@ -810,7 +810,7 @@ load_pixmap (struct frame *f, Lisp_Object name)
Return true iff RGB_LIST is OK. */
static bool
parse_rgb_list (Lisp_Object rgb_list, XColor *color)
parse_rgb_list (Lisp_Object rgb_list, Emacs_Color *color)
{
#define PARSE_RGB_LIST_FIELD(field) \
if (CONSP (rgb_list) && FIXNUMP (XCAR (rgb_list))) \
......@@ -835,8 +835,8 @@ parse_rgb_list (Lisp_Object rgb_list, XColor *color)
returned in it. */
static bool
tty_lookup_color (struct frame *f, Lisp_Object color, XColor *tty_color,
XColor *std_color)
tty_lookup_color (struct frame *f, Lisp_Object color, Emacs_Color *tty_color,
Emacs_Color *std_color)
{
Lisp_Object frame, color_desc;
......@@ -897,7 +897,7 @@ tty_lookup_color (struct frame *f, Lisp_Object color, XColor *tty_color,
bool
tty_defined_color (struct frame *f, const char *color_name,
XColor *color_def, bool alloc, bool _makeIndex)
Emacs_Color *color_def, bool alloc, bool _makeIndex)
{
bool status = true;
......@@ -965,7 +965,7 @@ tty_color_name (struct frame *f, int idx)
static bool
face_color_gray_p (struct frame *f, const char *color_name)
{
XColor color;
Emacs_Color color;
bool gray_p;
if (FRAME_TERMINAL (f)->defined_color_hook
......@@ -994,7 +994,7 @@ face_color_supported_p (struct frame *f, const char *color_name,
bool background_p)
{
Lisp_Object frame;
XColor not_used;
Emacs_Color not_used;
XSETFRAME (frame, f);
return
......@@ -1043,7 +1043,7 @@ COLOR must be a valid color name. */)
static unsigned long
load_color2 (struct frame *f, struct face *face, Lisp_Object name,
enum lface_attribute_index target_index, XColor *color)
enum lface_attribute_index target_index, Emacs_Color *color)
{
eassert (STRINGP (name));
eassert (target_index == LFACE_FOREGROUND_INDEX
......@@ -1117,7 +1117,7 @@ unsigned long
load_color (struct frame *f, struct face *face, Lisp_Object name,
enum lface_attribute_index target_index)
{
XColor color;
Emacs_Color color;
return load_color2 (f, face, name, target_index, &color);
}
......@@ -1134,7 +1134,7 @@ load_face_colors (struct frame *f, struct face *face,
Lisp_Object attrs[LFACE_VECTOR_SIZE])
{
Lisp_Object fg, bg, dfg;
XColor xfg, xbg;
Emacs_Color xfg, xbg;
bg = attrs[LFACE_BACKGROUND_INDEX];
fg = attrs[LFACE_FOREGROUND_INDEX];
......@@ -4170,7 +4170,7 @@ prepare_face_for_display (struct frame *f, struct face *face)
/* Returns the `distance' between the colors X and Y. */
static int
color_distance (XColor *x, XColor *y)
color_distance (Emacs_Color *x, Emacs_Color *y)
{
/* This formula is from a paper titled `Colour metric' by Thiadmer Riemersma.
Quoting from that paper:
......@@ -4205,7 +4205,7 @@ two lists of the form (RED GREEN BLUE) aforementioned. */)
Lisp_Object metric)
{
struct frame *f = decode_live_frame (frame);
XColor cdef1, cdef2;
Emacs_Color cdef1, cdef2;
if (!(CONSP (color1) && parse_rgb_list (color1, &cdef1))
&& !(STRINGP (color1)
......@@ -4885,8 +4885,8 @@ tty_supports_face_attributes_p (struct frame *f,
{
int weight, slant;
Lisp_Object val, fg, bg;
XColor fg_tty_color, fg_std_color;
XColor bg_tty_color, bg_std_color;
Emacs_Color fg_tty_color, fg_std_color;
Emacs_Color bg_tty_color, bg_std_color;
unsigned test_caps = 0;
Lisp_Object *def_attrs = def_face->lface;
......@@ -4988,7 +4988,7 @@ tty_supports_face_attributes_p (struct frame *f,
else
/* Make sure the color is really different than the default. */
{
XColor def_fg_color;
Emacs_Color def_fg_color;
if (tty_lookup_color (f, def_fg, &def_fg_color, 0)
&& (color_distance (&fg_tty_color, &def_fg_color)
<= TTY_SAME_COLOR_THRESHOLD))
......@@ -5012,7 +5012,7 @@ tty_supports_face_attributes_p (struct frame *f,
else
/* Make sure the color is really different than the default. */
{
XColor def_bg_color;
Emacs_Color def_bg_color;
if (tty_lookup_color (f, def_bg, &def_bg_color, 0)
&& (color_distance (&bg_tty_color, &def_bg_color)
<= TTY_SAME_COLOR_THRESHOLD))
......
......@@ -653,7 +653,7 @@ gamma_correct (struct frame *f, XColor *color)
bool
x_defined_color (struct frame *f, const char *color_name,
XColor *color, bool alloc_p, bool _makeIndex)
Emacs_Color *color, bool alloc_p, bool _makeIndex)
{
bool success_p = false;
Colormap cmap = FRAME_X_COLORMAP (f);
......
......@@ -1224,7 +1224,8 @@ extern void destroy_frame_xic (struct frame *);
extern void xic_set_preeditarea (struct window *, int, int);
extern void xic_set_statusarea (struct frame *);
extern void xic_set_xfontset (struct frame *, const char *);
extern bool x_defined_color (struct frame *, const char *, XColor *, bool, bool);
extern bool x_defined_color (struct frame *, const char *, Emacs_Color *,
bool, bool);
#ifdef HAVE_X_I18N
extern void free_frame_xic (struct frame *);
# if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment