/* Implementation of GUI terminal on the Mac OS.
- Copyright (C) 2000, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+ 2008 Free Software Foundation, Inc.
This file is part of GNU Emacs.
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA. */
+along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
/* Contributed by Andrew Choi (akochoi@mac.com). */
#include "intervals.h"
#include "atimer.h"
#include "keymap.h"
+#include "character.h"
+#include "ccl.h"
\f
static int max_fringe_bmp = 0;
static CGImageRef *fringe_bmp = 0;
-static CGColorSpaceRef mac_cg_color_space_rgb;
+CGColorSpaceRef mac_cg_color_space_rgb;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
static CGColorRef mac_cg_color_black;
#endif
if (CGColorGetTypeID != NULL)
#endif
{
- float rgba[] = {0.0f, 0.0f, 0.0f, 1.0f};
+ CGFloat rgba[] = {0.0f, 0.0f, 0.0f, 1.0f};
mac_cg_color_black = CGColorCreate (mac_cg_color_space_rgb, rgba);
}
{
#if USE_CG_DRAWING
CGContextRef context;
- float gx1 = x1, gy1 = y1, gx2 = x2, gy2 = y2;
+ CGFloat gx1 = x1, gy1 = y1, gx2 = x2, gy2 = y2;
if (y1 != y2)
gx1 += 0.5f, gx2 += 0.5f;
GC gc;
int x1, y1, x2, y2;
{
+#if USE_MAC_IMAGE_IO
+ CGContextRef context;
+ XImagePtr ximg = p;
+ CGColorSpaceRef color_space;
+ CGImageAlphaInfo alpha_info;
+ CGFloat gx1 = x1, gy1 = y1, gx2 = x2, gy2 = y2;
+
+ if (y1 != y2)
+ gx1 += 0.5f, gx2 += 0.5f;
+ if (x1 != x2)
+ gy1 += 0.5f, gy2 += 0.5f;
+
+ if (ximg->bits_per_pixel == 32)
+ {
+ color_space = mac_cg_color_space_rgb;
+ alpha_info = (kCGImageAlphaNoneSkipFirst
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
+ | kCGBitmapByteOrder32Host
+#endif
+ );
+ }
+ else
+ {
+ color_space = NULL;
+ alpha_info = kCGImageAlphaOnly;
+ }
+ if (color_space == NULL)
+ return;
+ context = CGBitmapContextCreate (ximg->data, ximg->width,
+ ximg->height, 8,
+ ximg->bytes_per_line, color_space,
+ alpha_info);
+ if (ximg->bits_per_pixel == 32)
+ CG_SET_STROKE_COLOR_WITH_GC_FOREGROUND (context, gc);
+ else
+ CGContextSetGrayStrokeColor (context, gc->xgcv.foreground / 255.0f, 1.0);
+ CGContextMoveToPoint (context, gx1, gy1);
+ CGContextAddLineToPoint (context, gx2, gy2);
+ CGContextClosePath (context);
+ CGContextStrokePath (context);
+ CGContextRelease (context);
+#else
CGrafPtr old_port;
GDHandle old_gdh;
UnlockPixels (GetGWorldPixMap (p));
SetGWorld (old_port, old_gdh);
+#endif
}
context = mac_begin_cg_clip (f, gc);
CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc);
- CGContextFillRect (context, CGRectMake (x, y, width, height));
+ CGContextFillRect (context, mac_rect_make (f, x, y, width, height));
mac_end_cg_clip (f);
}
#else
int dest_x, dest_y, overlay_p;
{
CGContextRef context;
- float port_height = FRAME_PIXEL_HEIGHT (f);
- CGRect dest_rect = CGRectMake (dest_x, dest_y, width, height);
+ CGFloat port_height = FRAME_PIXEL_HEIGHT (f);
+ CGRect dest_rect = mac_rect_make (f, dest_x, dest_y, width, height);
context = mac_begin_cg_clip (f, gc);
if (!overlay_p)
if (CGImageIsMask (image))
CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context, gc);
CGContextDrawImage (context,
- CGRectMake (dest_x - src_x,
- port_height - (dest_y - src_y
- + CGImageGetHeight (image)),
- CGImageGetWidth (image),
- CGImageGetHeight (image)),
+ mac_rect_make (f, dest_x - src_x,
+ port_height - (dest_y - src_y
+ + CGImageGetHeight (image)),
+ CGImageGetWidth (image),
+ CGImageGetHeight (image)),
image);
mac_end_cg_clip (f);
}
Pixmap
XCreatePixmap (display, w, width, height, depth)
Display *display;
- WindowRef w;
+ Window w;
unsigned int width, height;
unsigned int depth;
{
+#if USE_MAC_IMAGE_IO
+ XImagePtr ximg;
+
+ ximg = xmalloc (sizeof (*ximg));
+ ximg->width = width;
+ ximg->height = height;
+ ximg->bits_per_pixel = depth == 1 ? 8 : 32;
+ ximg->bytes_per_line = width * (ximg->bits_per_pixel / 8);
+ ximg->data = xmalloc (ximg->bytes_per_line * height);
+ return ximg;
+#else
Pixmap pixmap;
Rect r;
QDErr err;
+#ifdef MAC_OS8
SetPortWindowPort (w);
-
+#endif
SetRect (&r, 0, 0, width, height);
#if !defined (WORDS_BIG_ENDIAN) && USE_CG_DRAWING
if (depth == 1)
if (err != noErr)
return NULL;
return pixmap;
+#endif
}
Pixmap
XCreatePixmapFromBitmapData (display, w, data, width, height, fg, bg, depth)
Display *display;
- WindowRef w;
+ Window w;
char *data;
unsigned int width, height;
unsigned long fg, bg;
{
Pixmap pixmap;
BitMap bitmap;
+#if USE_MAC_IMAGE_IO
+ CGDataProviderRef provider;
+ CGImageRef image_mask;
+ CGContextRef context;
+
+ pixmap = XCreatePixmap (display, w, width, height, depth);
+ if (pixmap == NULL)
+ return NULL;
+
+ mac_create_bitmap_from_bitmap_data (&bitmap, data, width, height);
+ provider = CGDataProviderCreateWithData (NULL, bitmap.baseAddr,
+ bitmap.rowBytes * height, NULL);
+ image_mask = CGImageMaskCreate (width, height, 1, 1, bitmap.rowBytes,
+ provider, NULL, 0);
+ CGDataProviderRelease (provider);
+
+ context = CGBitmapContextCreate (pixmap->data, width, height, 8,
+ pixmap->bytes_per_line,
+ mac_cg_color_space_rgb,
+ kCGImageAlphaNoneSkipFirst
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
+ | kCGBitmapByteOrder32Host
+#endif
+ );
+
+ CG_SET_FILL_COLOR (context, fg);
+ CGContextFillRect (context, CGRectMake (0, 0, width, height));
+ CG_SET_FILL_COLOR (context, bg);
+ CGContextDrawImage (context, CGRectMake (0, 0, width, height), image_mask);
+ CGContextRelease (context);
+ CGImageRelease (image_mask);
+#else
CGrafPtr old_port;
GDHandle old_gdh;
static GC gc = NULL;
#endif /* not TARGET_API_MAC_CARBON */
UnlockPixels (GetGWorldPixMap (pixmap));
SetGWorld (old_port, old_gdh);
+#endif
mac_free_bitmap (&bitmap);
return pixmap;
Display *display;
Pixmap pixmap;
{
+#if USE_MAC_IMAGE_IO
+ if (pixmap)
+ {
+ xfree (pixmap->data);
+ xfree (pixmap);
+ }
+#else
DisposeGWorld (pixmap);
+#endif
}
context = mac_begin_cg_clip (f, gc);
CG_SET_FILL_COLOR_WITH_GC_FOREGROUND (context, gc);
- CGContextFillRect (context, CGRectMake (x, y, width, height));
+ CGContextFillRect (context, mac_rect_make (f, x, y, width, height));
mac_end_cg_clip (f);
#else
Rect r;
int x, y;
unsigned int width, height;
{
- Rect r;
+#if USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1040
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 && MAC_OS_X_VERSION_MIN_REQUIRED >= 1020
+ if (CGContextSetBlendMode != NULL)
+#endif
+ {
+ CGContextRef context;
+
+ context = mac_begin_cg_clip (f, NULL);
+ CGContextSetRGBFillColor (context, 1.0f, 1.0f, 1.0f, 1.0f);
+ CGContextSetBlendMode (context, kCGBlendModeDifference);
+ CGContextFillRect (context, mac_rect_make (f, x, y, width, height));
+ mac_end_cg_clip (f);
+ }
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 && MAC_OS_X_VERSION_MIN_REQUIRED >= 1020
+ else /* CGContextSetBlendMode == NULL */
+#endif
+#endif /* USE_CG_DRAWING && MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 */
+#if !USE_CG_DRAWING || MAC_OS_X_VERSION_MAX_ALLOWED < 1040 || (MAC_OS_X_VERSION_MIN_REQUIRED < 1040 && MAC_OS_X_VERSION_MIN_REQUIRED >= 1020)
+ {
+ Rect r;
#if USE_CG_DRAWING
mac_prepare_for_quickdraw (f);
else
{
static CGContextRef context;
- float port_height = FRAME_PIXEL_HEIGHT (f);
+ CGFloat port_height = FRAME_PIXEL_HEIGHT (f);
static const ATSUAttributeTag tags[] = {kATSUCGContextTag};
static const ByteCount sizes[] = {sizeof (CGContextRef)};
static const ATSUAttributeValuePtr values[] = {&context};
{
CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc);
CGContextFillRect (context,
- CGRectMake (x, y - FONT_BASE (GC_FONT (gc)),
- bg_width,
- FONT_HEIGHT (GC_FONT (gc))));
+ mac_rect_make (f,
+ x, y - FONT_BASE (GC_FONT (gc)),
+ bg_width,
+ FONT_HEIGHT (GC_FONT (gc))));
}
CGContextScaleCTM (context, 1, -1);
CGContextTranslateCTM (context, 0, -port_height);
XChar2b *buf;
int nchars, bg_width, overstrike_p;
{
- float port_height, gx, gy;
+ CGFloat port_height, gx, gy;
int i;
CGContextRef context;
CGGlyph *glyphs;
CG_SET_FILL_COLOR_WITH_GC_BACKGROUND (context, gc);
CGContextFillRect
(context,
- CGRectMake (gx, y - FONT_BASE (GC_FONT (gc)),
- bg_width, FONT_HEIGHT (GC_FONT (gc))));
+ mac_rect_make (f, gx, y - FONT_BASE (GC_FONT (gc)),
+ bg_width, FONT_HEIGHT (GC_FONT (gc))));
}
CGContextScaleCTM (context, 1, -1);
CGContextTranslateCTM (context, 0, -port_height);
}
else
{
- float rgba[4];
+ CGFloat rgba[4];
rgba[0] = gc->fore_color.red / 65535.0f;
rgba[1] = gc->fore_color.green / 65535.0f;
}
else
{
- float rgba[4];
+ CGFloat rgba[4];
rgba[0] = gc->back_color.red / 65535.0f;
rgba[1] = gc->back_color.green / 65535.0f;
/* Mac replacement for XSetClipRectangles. */
static void
-mac_set_clip_rectangles (display, gc, rectangles, n)
- Display *display;
+mac_set_clip_rectangles (f, gc, rectangles, n)
+ struct frame *f;
GC gc;
Rect *rectangles;
int n;
{
Rect *rect = rectangles + i;
- gc->clip_rects[i] = CGRectMake (rect->left, rect->top,
- rect->right - rect->left,
- rect->bottom - rect->top);
+ gc->clip_rects[i] = mac_rect_make (f, rect->left, rect->top,
+ rect->right - rect->left,
+ rect->bottom - rect->top);
}
#endif
}
/* Mac replacement for XSetClipMask. */
static INLINE void
-mac_reset_clip_rectangles (display, gc)
- Display *display;
+mac_reset_clip_rectangles (f, gc)
+ struct frame *f;
GC gc;
{
gc->n_clip_rects = 0;
XSetForeground (display, face->gc, gcv.foreground);
}
- mac_reset_clip_rectangles (display, face->gc);
+ mac_reset_clip_rectangles (f, face->gc);
}
#if USE_CG_DRAWING
/* Function prototypes of this page. */
static XCharStruct *x_per_char_metric P_ ((XFontStruct *, XChar2b *));
-static int mac_encode_char P_ ((int, XChar2b *, struct font_info *, int *));
+static int mac_encode_char P_ ((int, XChar2b *, struct font_info *,
+ struct charset *, int *));
static void
the two-byte form of C. Encoding is returned in *CHAR2B. */
static int
-mac_encode_char (c, char2b, font_info, two_byte_p)
+mac_encode_char (c, char2b, font_info, charset, two_byte_p)
int c;
XChar2b *char2b;
struct font_info *font_info;
+ struct charset *charset;
int *two_byte_p;
{
- int charset = CHAR_CHARSET (c);
XFontStruct *font = font_info->font;
/* FONT_INFO may define a scheme by which to encode byte1 and byte2.
check_ccl_update (ccl);
if (CHARSET_DIMENSION (charset) == 1)
{
- ccl->reg[0] = charset;
- ccl->reg[1] = char2b->byte2;
+ ccl->reg[0] = CHARSET_ID (charset);
+ ccl->reg[1] = XCHAR2B_BYTE2 (char2b);
ccl->reg[2] = -1;
}
else
{
- ccl->reg[0] = charset;
- ccl->reg[1] = char2b->byte1;
- ccl->reg[2] = char2b->byte2;
+ ccl->reg[0] = CHARSET_ID (charset);
+ ccl->reg[1] = XCHAR2B_BYTE1 (char2b);
+ ccl->reg[2] = XCHAR2B_BYTE2 (char2b);
}
- ccl_driver (ccl, NULL, NULL, 0, 0, NULL);
+ ccl_driver (ccl, NULL, NULL, 0, 0, Qnil);
/* We assume that MSBs are appropriately set/reset by CCL
program. */
if (font->max_byte1 == 0) /* 1-byte font */
- char2b->byte1 = 0, char2b->byte2 = ccl->reg[1];
+ STORE_XCHAR2B (char2b, 0, ccl->reg[1]);
else
- char2b->byte1 = ccl->reg[1], char2b->byte2 = ccl->reg[2];
+ STORE_XCHAR2B (char2b, ccl->reg[1], ccl->reg[2]);
}
- else if (font_info->encoding[charset])
+ else if (font_info->encoding_type)
{
/* Fixed encoding scheme. See fontset.h for the meaning of the
encoding numbers. */
- int enc = font_info->encoding[charset];
+ unsigned char enc = font_info->encoding_type;
if ((enc == 1 || enc == 2)
&& CHARSET_DIMENSION (charset) == 2)
char2b->byte2 |= 0x80;
if (enc == 4)
- {
- int sjis1, sjis2;
+ {
+ int code = (char2b->byte1 << 8) | char2b->byte2;
- ENCODE_SJIS (char2b->byte1, char2b->byte2, sjis1, sjis2);
- char2b->byte1 = sjis1;
- char2b->byte2 = sjis2;
- }
+ JIS_TO_SJIS (code);
+ STORE_XCHAR2B (char2b, (code >> 8), (code & 0xFF));
+ }
}
if (two_byte_p)
face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
if (s->first_glyph->type == CHAR_GLYPH)
- face_id = FACE_FOR_CHAR (s->f, face, s->first_glyph->u.ch);
+ face_id = FACE_FOR_CHAR (s->f, face, s->first_glyph->u.ch, -1, Qnil);
else
- face_id = FACE_FOR_CHAR (s->f, face, 0);
+ face_id = FACE_FOR_CHAR (s->f, face, 0, -1, Qnil);
s->face = FACE_FROM_ID (s->f, face_id);
PREPARE_FACE_FOR_DISPLAY (s->f, s->face);
int n;
n = get_glyph_string_clip_rects (s, rects, MAX_CLIP_RECTS);
- mac_set_clip_rectangles (s->display, s->gc, rects, n);
+ mac_set_clip_rectangles (s->f, s->gc, rects, n);
}
/* Look for a frame with that top-level widget. Allocate the color
on that frame to get the right gamma correction value. */
- for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
- if (GC_FRAMEP (XCAR (tail))
+ for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
+ if (FRAMEP (XCAR (tail))
&& (f = XFRAME (XCAR (tail)),
(f->output_data.nothing != 1
&& FRAME_X_DISPLAY_INFO (f) == dpyinfo))
int top_p, bot_p, left_p, right_p, raised_p;
Rect *clip_rect;
{
- Display *dpy = FRAME_MAC_DISPLAY (f);
int i;
GC gc;
gc = f->output_data.mac->white_relief.gc;
else
gc = f->output_data.mac->black_relief.gc;
- mac_set_clip_rectangles (dpy, gc, clip_rect, 1);
+ mac_set_clip_rectangles (f, gc, clip_rect, 1);
/* Top. */
if (top_p)
mac_draw_line (f, gc,
left_x + i, top_y + i, left_x + i, bottom_y - i + 1);
- mac_reset_clip_rectangles (dpy, gc);
+ mac_reset_clip_rectangles (f, gc);
if (raised_p)
gc = f->output_data.mac->black_relief.gc;
else
gc = f->output_data.mac->white_relief.gc;
- mac_set_clip_rectangles (dpy, gc, clip_rect, 1);
+ mac_set_clip_rectangles (f, gc, clip_rect, 1);
/* Bottom. */
if (bot_p)
mac_draw_line (f, gc,
right_x - i, top_y + i + 1, right_x - i, bottom_y - i);
- mac_reset_clip_rectangles (dpy, gc);
+ mac_reset_clip_rectangles (f, gc);
}
XGetGCValues (s->display, s->gc, GCForeground, &xgcv);
XSetForeground (s->display, s->gc, s->face->box_color);
- mac_set_clip_rectangles (s->display, s->gc, clip_rect, 1);
+ mac_set_clip_rectangles (s->f, s->gc, clip_rect, 1);
/* Top. */
mac_fill_rectangle (s->f, s->gc, left_x, top_y,
top_y, width, bottom_y - top_y + 1);
XSetForeground (s->display, s->gc, xgcv.foreground);
- mac_reset_clip_rectangles (s->display, s->gc);
+ mac_reset_clip_rectangles (s->f, s->gc);
}
gc = s->face->gc;
get_glyph_string_clip_rect (s, &r);
- mac_set_clip_rectangles (s->display, gc, &r, 1);
+ mac_set_clip_rectangles (s->f, gc, &r, 1);
#if 0 /* MAC_TODO: stipple */
if (s->face->stipple)
if (s->face->font)
y = s->ybase + (s->face->font->max_bounds.descent + 1) / 2;
}
-
+ /* FIXME: Obey underline_minimum_offset. */
if (s->face->underline_defaulted_p)
mac_fill_rectangle (s->f, s->gc, s->x, y,
s->background_width, h);
}
/* Reset clipping. */
- mac_reset_clip_rectangles (s->display, s->gc);
+ mac_reset_clip_rectangles (s->f, s->gc);
}
/* Shift display to make room for inserted glyphs. */
/* Don't stop displaying the initial startup message
for a switch-frame event we don't need. */
- if (GC_NILP (Vterminal_frame)
- && GC_CONSP (Vframe_list)
- && !GC_NILP (XCDR (Vframe_list)))
+ if (NILP (Vterminal_frame)
+ && CONSP (Vframe_list)
+ && !NILP (XCDR (Vframe_list)))
{
bufp->kind = FOCUS_IN_EVENT;
XSETFRAME (bufp->frame_or_window, frame);
if (dpyinfo->x_focus_frame)
{
dpyinfo->x_highlight_frame
- = ((GC_FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame)))
+ = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame)))
? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame))
: dpyinfo->x_focus_frame);
if (! FRAME_LIVE_P (dpyinfo->x_highlight_frame))
{
int win_y, top_range;
- if (! GC_WINDOWP (bar->window))
+ if (! WINDOWP (bar->window))
abort ();
bufp->kind = SCROLL_BAR_CLICK_EVENT;
XSETVECTOR (last_mouse_scroll_bar, bar);
/* If we're dragging the bar, display it. */
- if (! GC_NILP (bar->dragging))
+ if (! NILP (bar->dragging))
{
/* Where should the handle be now? */
int new_start = y_pos - 24;
cursor_glyph->pixel_width,
width);
- mac_reset_clip_rectangles (dpy, gc);
+ mac_reset_clip_rectangles (f, gc);
}
}
register char *fontname;
{
struct font_info *fontp
- = FS_LOAD_FONT (f, 0, fontname, -1);
+ = FS_LOAD_FONT (f, fontname);
if (!fontp)
return Qnil;
+ if (FRAME_FONT (f) == (XFontStruct *) (fontp->font))
+ /* This font is already set in frame F. There's nothing more to
+ do. */
+ return build_string (fontp->full_name);
+
FRAME_FONT (f) = (XFontStruct *) (fontp->font);
FRAME_BASELINE_OFFSET (f) = fontp->baseline_offset;
FRAME_FONTSET (f) = -1;
return build_string (fontp->full_name);
}
+\f
+/* Give frame F the fontset named FONTSETNAME as its default fontset,
+ and return the full name of that fontset. FONTSETNAME may be a
+ wildcard pattern; in that case, we choose some fontset that fits
+ the pattern. FONTSETNAME may be a font name for ASCII characters;
+ in that case, we create a fontset from that font name.
-/* Give frame F the fontset named FONTSETNAME as its default font, and
- return the full name of that fontset. FONTSETNAME may be a wildcard
- pattern; in that case, we choose some fontset that fits the pattern.
- The return value shows which fontset we chose. */
+ The return value shows which fontset we chose.
+ If FONTSETNAME specifies the default fontset, return Qt.
+ If an ASCII font in the specified fontset can't be loaded, return
+ Qnil. */
Lisp_Object
x_new_fontset (f, fontsetname)
struct frame *f;
- char *fontsetname;
+ Lisp_Object fontsetname;
{
- int fontset = fs_query_fontset (build_string (fontsetname), 0);
+ int fontset = fs_query_fontset (fontsetname, 0);
Lisp_Object result;
- if (fontset < 0)
- return Qnil;
-
- if (FRAME_FONTSET (f) == fontset)
+ if (fontset > 0 && FRAME_FONTSET(f) == fontset)
/* This fontset is already set in frame F. There's nothing more
to do. */
return fontset_name (fontset);
+ else if (fontset == 0)
+ /* The default fontset can't be the default font. */
+ return Qt;
- result = x_new_font (f, (SDATA (fontset_ascii (fontset))));
+ if (fontset > 0)
+ result = x_new_font (f, (SDATA (fontset_ascii (fontset))));
+ else
+ result = x_new_font (f, SDATA (fontsetname));
if (!STRINGP (result))
/* Can't load ASCII font. */
return Qnil;
+ if (fontset < 0)
+ fontset = new_fontset_from_font_name (result);
+
/* Since x_new_font doesn't update any fontset information, do it now. */
FRAME_FONTSET (f) = fontset;
- return build_string (fontsetname);
+ return fontset_name (fontset);
}
\f
change_frame_size (f, rows, cols, 0, 1, 0);
FRAME_PIXEL_WIDTH (f) = pixelwidth;
FRAME_PIXEL_HEIGHT (f) = pixelheight;
- SET_FRAME_GARBAGED (f);
/* If cursor was outside the new size, mark it as off. */
mark_window_cursors_off (XWINDOW (f->root_window));
x_calc_absolute_position (f)
struct frame *f;
{
- int width_diff = 0, height_diff = 0;
int flags = f->size_hint_flags;
Rect inner, outer;
mac_get_window_bounds (f, &inner, &outer);
UNBLOCK_INPUT;
- width_diff = (outer.right - outer.left) - (inner.right - inner.left);
- height_diff = (outer.bottom - outer.top) - (inner.bottom - inner.top);
-
/* Treat negative positions as relative to the leftmost bottommost
position that fits on the screen. */
if (flags & XNegative)
- f->left_pos = (FRAME_MAC_DISPLAY_INFO (f)->width
- - width_diff
- - FRAME_PIXEL_WIDTH (f)
- + f->left_pos);
+ f->left_pos += (FRAME_MAC_DISPLAY_INFO (f)->width
+ - (outer.right - outer.left));
if (flags & YNegative)
- f->top_pos = (FRAME_MAC_DISPLAY_INFO (f)->height
- - height_diff
- - FRAME_PIXEL_HEIGHT (f)
- + f->top_pos);
+ f->top_pos += (FRAME_MAC_DISPLAY_INFO (f)->height
+ - (outer.bottom - outer.top));
/* The left_pos and top_pos
are now relative to the top and left screen edges,
x_free_gcs (f);
- if (FRAME_SIZE_HINTS (f))
- xfree (FRAME_SIZE_HINTS (f));
+ xfree (FRAME_SIZE_HINTS (f));
xfree (f->output_data.mac);
f->output_data.mac = NULL;
{
if (pat->buf)
{
- if (pat->blocks)
- xfree (pat->blocks);
+ xfree (pat->blocks);
xfree (pat->buf);
}
xfree (pat);
coding.src_multibyte = 0;
coding.dst_multibyte = 1;
coding.mode |= CODING_MODE_LAST_BLOCK;
- coding.composing = COMPOSITION_DISABLED;
- buf = (char *) alloca (size);
+ coding.dst_bytes = size;
+ coding.destination = (unsigned char *) alloca (coding.dst_bytes);
- decode_coding (&coding, name, buf, strlen (name), size - 1);
- bcopy (buf, name, coding.produced);
- name[coding.produced] = '\0';
+ decode_coding_c_string (&coding, name, strlen (name), Qnil);
+ bcopy (coding.destination, name, min (coding.produced, size));
+ name[min (coding.produced, size)] = '\0';
}
}
HASH_VALUE (h, j));
prev_family = family;
}
- if (font_ids)
- xfree (font_ids);
+ xfree (font_ids);
}
#endif
int i;
for (i = font->min_byte1; i <= font->max_byte1; i++)
- if (font->bounds.rows[i])
- xfree (font->bounds.rows[i]);
+ xfree (font->bounds.rows[i]);
xfree (font->bounds.rows);
ATSUDisposeStyle (font->mac_style);
}
else
#endif
- if (font->bounds.per_char)
- xfree (font->bounds.per_char);
+ xfree (font->bounds.per_char);
#if USE_CG_TEXT_DRAWING
if (font->cg_font)
CGFontRelease (font->cg_font);
- if (font->cg_glyphs)
- xfree (font->cg_glyphs);
+ xfree (font->cg_glyphs);
#endif
xfree (font);
}
bzero (fontp, sizeof (*fontp));
fontp->font = font;
fontp->font_idx = i;
+ fontp->charset = -1; /* fs_load_font sets it. */
fontp->name = (char *) xmalloc (strlen (fontname) + 1);
bcopy (fontname, fontp->name, strlen (fontname) + 1);
fontp->height = max_height;
}
+ /* MAC_TODO: The script encoding is irrelevant in unicode? */
/* The slot `encoding' specifies how to map a character
code-points (0x20..0x7F or 0x2020..0x7F7F) of each charset to
the font code-points (0:0x20..0x7F, 1:0xA0..0xFF), or
(0:0x2020..0x7F7F, 1:0xA0A0..0xFFFF, 3:0x20A0..0x7FFF,
2:0xA020..0xFF7F). For the moment, we don't know which charset
- uses this font. So, we set information in fontp->encoding[1]
+ uses this font. So, we set information in fontp->encoding_type
which is never used by any charset. If mapping can't be
decided, set FONT_ENCODING_NOT_DECIDED. */
if (font->mac_scriptcode == smJapanese)
- fontp->encoding[1] = 4;
+ fontp->encoding_type = 4;
else
{
- fontp->encoding[1]
+ fontp->encoding_type
= (font->max_byte1 == 0
/* 1-byte font */
? (font->min_char_or_byte2 < 0x80
for (i = 0; i < dpyinfo->n_fonts; i++)
if (dpyinfo->font_table[i].name
- && (!xstricmp (dpyinfo->font_table[i].name, fontname)
- || !xstricmp (dpyinfo->font_table[i].full_name, fontname)))
+ && (!xstrcasecmp (dpyinfo->font_table[i].name, fontname)
+ || !xstrcasecmp (dpyinfo->font_table[i].full_name, fontname)))
return (dpyinfo->font_table + i);
return NULL;
}
#endif
#if USE_MAC_TSM
static TSMDocumentID tsm_document_id;
-static Lisp_Object Qtext_input;
-static Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event;
-static Lisp_Object Vmac_ts_active_input_overlay;
+Lisp_Object Qtext_input;
+Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event;
+Lisp_Object Vmac_ts_active_input_overlay, Vmac_ts_active_input_buf;
extern Lisp_Object Qbefore_string;
static Lisp_Object Vmac_ts_script_language_on_focus;
static Lisp_Object saved_ts_script_language_on_focus;
#ifdef MAC_OSX
extern OSStatus install_service_handler ();
-static Lisp_Object Qservice, Qpaste, Qperform;
+Lisp_Object Qservice, Qpaste, Qperform;
+Lisp_Object Qmouse_drag_overlay;
#endif
#endif
return result;
}
+#ifdef MAC_OSX
+void
+mac_get_selected_range (w, range)
+ struct window *w;
+ CFRange *range;
+{
+ Lisp_Object overlay = find_symbol_value (Qmouse_drag_overlay);
+ struct buffer *b = XBUFFER (w->buffer);
+ int begv = BUF_BEGV (b), zv = BUF_ZV (b);
+ int start, end;
+
+ if (OVERLAYP (overlay)
+ && EQ (Foverlay_buffer (overlay), w->buffer)
+ && (start = XINT (Foverlay_start (overlay)),
+ end = XINT (Foverlay_end (overlay)),
+ start != end))
+ ;
+ else
+ {
+ if (w == XWINDOW (selected_window) && b == current_buffer)
+ start = PT;
+ else
+ start = marker_position (w->pointm);
+
+ if (NILP (Vtransient_mark_mode) || NILP (b->mark_active))
+ end = start;
+ else
+ {
+ int mark_pos = marker_position (b->mark);
+
+ if (start <= mark_pos)
+ end = mark_pos;
+ else
+ {
+ end = start;
+ start = mark_pos;
+ }
+ }
+ }
+
+ if (start != end)
+ {
+ if (start < begv)
+ start = begv;
+ else if (start > zv)
+ start = zv;
+
+ if (end < begv)
+ end = begv;
+ else if (end > zv)
+ end = zv;
+ }
+
+ range->location = start - begv;
+ range->length = end - start;
+}
+
+/* Store the text of the buffer BUF from START to END as Unicode
+ characters in CHARACTERS. Return non-zero if successful. */
+
+int
+mac_store_buffer_text_to_unicode_chars (buf, start, end, characters)
+ struct buffer *buf;
+ int start, end;
+ UniChar *characters;
+{
+ int start_byte, end_byte, char_count, byte_count;
+ struct coding_system coding;
+ unsigned char *dst = (unsigned char *) characters;
+
+ start_byte = buf_charpos_to_bytepos (buf, start);
+ end_byte = buf_charpos_to_bytepos (buf, end);
+ char_count = end - start;
+ byte_count = end_byte - start_byte;
+
+ if (setup_coding_system (
+#ifdef WORDS_BIG_ENDIAN
+ intern ("utf-16be")
+#else
+ intern ("utf-16le")
+#endif
+ , &coding) < 0)
+ return 0;
+
+ coding.src_multibyte = !NILP (buf->enable_multibyte_characters);
+ coding.dst_multibyte = 0;
+ coding.mode |= CODING_MODE_LAST_BLOCK;
+ coding.composing = COMPOSITION_DISABLED;
+
+ if (BUF_GPT_BYTE (buf) <= start_byte || end_byte <= BUF_GPT_BYTE (buf))
+ encode_coding (&coding, BUF_BYTE_ADDRESS (buf, start_byte), dst,
+ byte_count, char_count * sizeof (UniChar));
+ else
+ {
+ int first_byte_count = BUF_GPT_BYTE (buf) - start_byte;
+
+ encode_coding (&coding, BUF_BYTE_ADDRESS (buf, start_byte), dst,
+ first_byte_count, char_count * sizeof (UniChar));
+ if (coding.result == CODING_FINISH_NORMAL)
+ encode_coding (&coding,
+ BUF_BYTE_ADDRESS (buf, start_byte + first_byte_count),
+ dst + coding.produced,
+ byte_count - first_byte_count,
+ char_count * sizeof (UniChar) - coding.produced);
+ }
+
+ if (coding.result != CODING_FINISH_NORMAL)
+ return 0;
+
+ return 1;
+}
+
+void
+mac_ax_selected_text_range (f, range)
+ struct frame *f;
+ CFRange *range;
+{
+ mac_get_selected_range (XWINDOW (f->selected_window), range);
+}
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030
+unsigned int
+mac_ax_number_of_characters (f)
+ struct frame *f;
+{
+ struct buffer *b = XBUFFER (XWINDOW (f->selected_window)->buffer);
+
+ return BUF_ZV (b) - BUF_BEGV (b);
+}
+#endif
+#endif
+
+#if USE_MAC_TSM
+OSStatus
+mac_restore_keyboard_input_source ()
+{
+ OSStatus err = noErr;
+ ScriptLanguageRecord slrec, *slptr = NULL;
+
+ if (EQ (Vmac_ts_script_language_on_focus, Qt)
+ && EQ (saved_ts_script_language_on_focus, Qt))
+ slptr = &saved_ts_language;
+ else if (CONSP (Vmac_ts_script_language_on_focus)
+ && INTEGERP (XCAR (Vmac_ts_script_language_on_focus))
+ && INTEGERP (XCDR (Vmac_ts_script_language_on_focus))
+ && CONSP (saved_ts_script_language_on_focus)
+ && EQ (XCAR (saved_ts_script_language_on_focus),
+ XCAR (Vmac_ts_script_language_on_focus))
+ && EQ (XCDR (saved_ts_script_language_on_focus),
+ XCDR (Vmac_ts_script_language_on_focus)))
+ {
+ slrec.fScript = XINT (XCAR (Vmac_ts_script_language_on_focus));
+ slrec.fLanguage = XINT (XCDR (Vmac_ts_script_language_on_focus));
+ slptr = &slrec;
+ }
+
+ if (slptr)
+ {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
+ err = SetDefaultInputMethodOfClass (saved_ts_component, slptr,
+ kKeyboardInputMethodClass);
+#else
+ err = SetDefaultInputMethod (saved_ts_component, slptr);
+#endif
+ if (err == noErr)
+ err = SetTextServiceLanguage (slptr);
+
+ /* Seems to be needed on Mac OS X 10.2. */
+ if (err == noErr)
+ KeyScript (slptr->fScript | smKeyForceKeyScriptMask);
+ }
+
+ return err;
+}
+
+void
+mac_save_keyboard_input_source ()
+{
+ OSStatus err;
+ ScriptLanguageRecord slrec, *slptr = NULL;
+
+ saved_ts_script_language_on_focus = Vmac_ts_script_language_on_focus;
+
+ if (EQ (Vmac_ts_script_language_on_focus, Qt))
+ {
+ err = GetTextServiceLanguage (&saved_ts_language);
+ if (err == noErr)
+ slptr = &saved_ts_language;
+ }
+ else if (CONSP (Vmac_ts_script_language_on_focus)
+ && INTEGERP (XCAR (Vmac_ts_script_language_on_focus))
+ && INTEGERP (XCDR (Vmac_ts_script_language_on_focus)))
+ {
+ slrec.fScript = XINT (XCAR (Vmac_ts_script_language_on_focus));
+ slrec.fLanguage = XINT (XCDR (Vmac_ts_script_language_on_focus));
+ slptr = &slrec;
+ }
+
+ if (slptr)
+ {
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
+ GetDefaultInputMethodOfClass (&saved_ts_component, slptr,
+ kKeyboardInputMethodClass);
+#else
+ GetDefaultInputMethod (&saved_ts_component, slptr);
+#endif
+ }
+}
+#endif
+
#if TARGET_API_MAC_CARBON
/***** Code to handle C-g testing *****/
extern int quit_char;
dpyinfo->grabbed = 0;
dpyinfo->root_window = NULL;
- dpyinfo->image_cache = make_image_cache ();
+ dpyinfo->terminal->image_cache = make_image_cache ();
dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
if (dpyinfo->font_table)
{
- if (dpyinfo->font_table->font_encoder)
- xfree (dpyinfo->font_table->font_encoder);
+ xfree (dpyinfo->font_table->font_encoder);
xfree (dpyinfo->font_table);
}
- if (dpyinfo->mac_id_name)
- xfree (dpyinfo->mac_id_name);
+ xfree (dpyinfo->mac_id_name);
if (x_display_list == 0)
{
Qservice = intern ("service"); staticpro (&Qservice);
Qpaste = intern ("paste"); staticpro (&Qpaste);
Qperform = intern ("perform"); staticpro (&Qperform);
+
+ Qmouse_drag_overlay = intern ("mouse-drag-overlay");
+ staticpro (&Qmouse_drag_overlay);
#endif
#if USE_MAC_TSM
Qtext_input = intern ("text-input"); staticpro (&Qtext_input);
doc: /* Overlay used to display Mac TSM active input area. */);
Vmac_ts_active_input_overlay = Qnil;
+ DEFVAR_LISP ("mac-ts-active-input-buf", &Vmac_ts_active_input_buf,
+ doc: /* Byte sequence of the current Mac TSM active input area. */);
+ /* `empty_string' is not ready yet on Mac OS Classic. */
+ Vmac_ts_active_input_buf = build_string ("");
+
DEFVAR_LISP ("mac-ts-script-language-on-focus", &Vmac_ts_script_language_on_focus,
doc: /* *How to change Mac TSM script/language when a frame gets focus.
If the value is t, the input script and language are restored to those