From e4651d75ff6d19fdf867dd508efb5fb9b656f3aa Mon Sep 17 00:00:00 2001 From: Romain Francoise Date: Fri, 18 Apr 2008 18:27:25 +0000 Subject: [PATCH 1/6] 2008-04-18 Steve Grubb (tiny change) * vcdiff: Use mktemp (CVE-2008-1694). --- lib-src/ChangeLog | 4 ++++ lib-src/vcdiff | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog index 2ed5830d550..63cc416cad7 100644 --- a/lib-src/ChangeLog +++ b/lib-src/ChangeLog @@ -1,3 +1,7 @@ +2008-04-18 Steve Grubb (tiny change) + + * vcdiff: Use mktemp (CVE-2008-1694). + 2008-04-10 Jason Rumney * makefile.w32-in (CLIENTRES): New variable and target. diff --git a/lib-src/vcdiff b/lib-src/vcdiff index 86b80bcdacd..cb977709db0 100755 --- a/lib-src/vcdiff +++ b/lib-src/vcdiff @@ -84,14 +84,14 @@ do case $f in s.* | */s.*) if - rev1=/tmp/geta$$ + rev1=`mktemp /tmp/geta.XXXXXXXX` get -s -p -k $sid1 "$f" > $rev1 && case $sid2 in '') workfile=`expr " /$f" : '.*/s.\(.*\)'` ;; *) - rev2=/tmp/getb$$ + rev2=`mktemp /tmp/getb.XXXXXXXX` get -s -p -k $sid2 "$f" > $rev2 workfile=$rev2 esac From d421d4d8fccc7f49bceae903014413c15ce6b097 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Sat, 19 Apr 2008 01:24:47 +0000 Subject: [PATCH 2/6] (create_apple_event) [TARGET_API_MAC_CARBON]: Make function non-static. (create_apple_event_from_event_ref) [TARGET_API_MAC_CARBON]: Remove function. (create_apple_event_from_drag_ref) [TARGET_API_MAC_CARBON]: Move to mactoolbox.c. (mac_event_parameters_to_lisp) [TARGET_API_MAC_CARBON]: New function. --- src/mac.c | 151 ++++++++++++++++++------------------------------------ 1 file changed, 49 insertions(+), 102 deletions(-) diff --git a/src/mac.c b/src/mac.c index 0ae233f048e..22f34747ea8 100644 --- a/src/mac.c +++ b/src/mac.c @@ -817,7 +817,7 @@ init_coercion_handler () } #if TARGET_API_MAC_CARBON -static OSErr +OSErr create_apple_event (class, id, result) AEEventClass class; AEEventID id; @@ -842,129 +842,76 @@ create_apple_event (class, id, result) return err; } -OSStatus -create_apple_event_from_event_ref (event, num_params, names, types, result) +Lisp_Object +mac_event_parameters_to_lisp (event, num_params, names, types) EventRef event; UInt32 num_params; const EventParamName *names; const EventParamType *types; - AppleEvent *result; { OSStatus err; - UInt32 i, size; + Lisp_Object result = Qnil; + UInt32 i; + ByteCount size; +#ifdef MAC_OSX CFStringRef string; CFDataRef data; +#endif char *buf = NULL; - err = create_apple_event (0, 0, result); /* Dummy class and ID. */ - if (err != noErr) - return err; - for (i = 0; i < num_params; i++) - switch (types[i]) - { + { + EventParamName name = names[i]; + EventParamType type = types[i]; + + switch (type) + { #ifdef MAC_OSX - case typeCFStringRef: - err = GetEventParameter (event, names[i], typeCFStringRef, NULL, - sizeof (CFStringRef), NULL, &string); - if (err != noErr) + case typeCFStringRef: + err = GetEventParameter (event, name, typeCFStringRef, NULL, + sizeof (CFStringRef), NULL, &string); + if (err != noErr) + break; + data = CFStringCreateExternalRepresentation (NULL, string, + kCFStringEncodingUTF8, + '?'); + if (data == NULL) + break; + name = EndianU32_NtoB (name); + type = EndianU32_NtoB (typeUTF8Text); + result = + Fcons (Fcons (make_unibyte_string ((char *) &name, 4), + Fcons (make_unibyte_string ((char *) &type, 4), + make_unibyte_string (CFDataGetBytePtr (data), + CFDataGetLength (data)))), + result); + CFRelease (data); break; - data = CFStringCreateExternalRepresentation (NULL, string, - kCFStringEncodingUTF8, - '?'); - if (data == NULL) - break; - AEPutParamPtr (result, names[i], typeUTF8Text, - CFDataGetBytePtr (data), CFDataGetLength (data)); - CFRelease (data); - break; #endif - default: - err = GetEventParameter (event, names[i], types[i], NULL, - 0, &size, NULL); - if (err != noErr) - break; - buf = xrealloc (buf, size); - err = GetEventParameter (event, names[i], types[i], NULL, - size, NULL, buf); - if (err == noErr) - AEPutParamPtr (result, names[i], types[i], buf, size); - break; - } - if (buf) - xfree (buf); - - return noErr; -} - -OSErr -create_apple_event_from_drag_ref (drag, num_types, types, result) - DragRef drag; - UInt32 num_types; - const FlavorType *types; - AppleEvent *result; -{ - OSErr err; - UInt16 num_items; - AppleEvent items; - long index; - char *buf = NULL; - - err = CountDragItems (drag, &num_items); - if (err != noErr) - return err; - err = AECreateList (NULL, 0, false, &items); - if (err != noErr) - return err; - - for (index = 1; index <= num_items; index++) - { - ItemReference item; - DescType desc_type = typeNull; - Size size; - - err = GetDragItemReferenceNumber (drag, index, &item); - if (err == noErr) - { - int i; - - for (i = 0; i < num_types; i++) + default: + err = GetEventParameter (event, name, type, NULL, 0, &size, NULL); + if (err != noErr) + break; + buf = xrealloc (buf, size); + err = GetEventParameter (event, name, type, NULL, size, NULL, buf); + if (err == noErr) { - err = GetFlavorDataSize (drag, item, types[i], &size); - if (err == noErr) - { - buf = xrealloc (buf, size); - err = GetFlavorData (drag, item, types[i], buf, &size, 0); - } - if (err == noErr) - { - desc_type = types[i]; - break; - } + name = EndianU32_NtoB (name); + type = EndianU32_NtoB (type); + result = + Fcons (Fcons (make_unibyte_string ((char *) &name, 4), + Fcons (make_unibyte_string ((char *) &type, 4), + make_unibyte_string (buf, size))), + result); } + break; } - err = AEPutPtr (&items, index, desc_type, - desc_type != typeNull ? buf : NULL, - desc_type != typeNull ? size : 0); - if (err != noErr) - break; } if (buf) xfree (buf); - if (err == noErr) - { - err = create_apple_event (0, 0, result); /* Dummy class and ID. */ - if (err == noErr) - err = AEPutParamDesc (result, keyDirectObject, &items); - if (err != noErr) - AEDisposeDesc (result); - } - - AEDisposeDesc (&items); - - return err; + return result; } #endif /* TARGET_API_MAC_CARBON */ From 15364c8fb7286984e2b18e927f8957a63107129e Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Sat, 19 Apr 2008 01:24:57 +0000 Subject: [PATCH 3/6] (CGFloat) [!CGFLOAT_DEFINED]: New typedef. (mac_rect_make): New macro. --- src/macgui.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/macgui.h b/src/macgui.h index 1f4e454c714..c1558e98bfe 100644 --- a/src/macgui.h +++ b/src/macgui.h @@ -124,6 +124,10 @@ typedef unsigned long Time; #endif #endif +#ifndef CGFLOAT_DEFINED +typedef float CGFloat; +#endif + typedef WindowRef Window; #if TARGET_API_MAC_CARBON typedef ScrapRef Selection; @@ -147,6 +151,7 @@ typedef int Selection; #define mac_size_window SizeWindow #define mac_get_global_mouse GetGlobalMouse #define mac_is_window_toolbar_visible IsWindowToolbarVisible +#define mac_rect_make(f, x, y, w, h) CGRectMake (x, y, w, h) typedef GWorldPtr Pixmap; #define Cursor ThemeCursor From 834263b66b4c0c45c7af133391fb905ff41fdf0a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Sat, 19 Apr 2008 01:25:06 +0000 Subject: [PATCH 4/6] (mac_draw_image_string_atsui) [MAC_OSX]: Use CGFloat instead of float. (mac_draw_image_string_cg) [USE_CG_TEXT_DRAWING]: Likewise. (init_cg_color, mac_draw_line, mac_draw_cg_image, XSetForeground) (XSetBackground) [USE_CG_DRAWING]: Likewise. (mac_draw_image_string_atsui) [MAC_OSX]: Use mac_rect_make instead of CGRectMake. (mac_draw_image_string_cg) [USE_CG_TEXT_DRAWING]: Likewise. (mac_erase_rectangle, mac_draw_cg_image, mac_fill_rectangle) (mac_set_clip_rectangles) [USE_CG_DRAWING]: Likewise. (XCreatePixmap, XCreatePixmapFromBitmapData): Use Window instead of WindowRef in argument type. (XCreatePixmap) [!MAC_OS8]: Don't call SetPortWindowPort. (mac_invert_rectangle): Use CGContextSetBlendMode if available. (mac_set_clip_rectangles, mac_reset_clip_rectangles): Take argument F instead of DISPLAY. All uses changed. (mac_handle_size_change): Don't call SET_FRAME_GARBAGED. (x_calc_absolute_position): Simplify so as not to use FRAME_PIXEL_WIDTH/FRAME_PIXEL_HEIGHT. (Vmac_ts_script_language_on_focus, saved_ts_script_language_on_focus) [USE_MAC_TSM]: Make variables static. (mac_store_event_ref_as_apple_event) [TARGET_API_MAC_CARBON]: Don't use create_apple_event_from_event_ref. Use mac_event_parameters_to_lisp. --- src/macterm.c | 167 ++++++++++++++++++++++++++++---------------------- 1 file changed, 94 insertions(+), 73 deletions(-) diff --git a/src/macterm.c b/src/macterm.c index a043e5a4860..2a8142938a9 100644 --- a/src/macterm.c +++ b/src/macterm.c @@ -332,7 +332,7 @@ init_cg_color () 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); } @@ -352,7 +352,7 @@ mac_draw_line (f, gc, x1, y1, x2, y2) { #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; @@ -445,7 +445,7 @@ mac_erase_rectangle (f, gc, x, y, width, height) 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 @@ -523,8 +523,8 @@ mac_draw_cg_image (image, f, gc, src_x, src_y, width, height, 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) @@ -538,11 +538,11 @@ mac_draw_cg_image (image, f, gc, src_x, src_y, width, height, 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); } @@ -635,7 +635,7 @@ mac_free_bitmap (bitmap) Pixmap XCreatePixmap (display, w, width, height, depth) Display *display; - WindowRef w; + Window w; unsigned int width, height; unsigned int depth; { @@ -643,8 +643,9 @@ XCreatePixmap (display, w, width, height, depth) 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) @@ -664,7 +665,7 @@ XCreatePixmap (display, w, width, height, depth) 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; @@ -729,7 +730,7 @@ mac_fill_rectangle (f, gc, x, y, width, height) 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; @@ -778,12 +779,33 @@ mac_invert_rectangle (f, x, y, width, height) 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; - mac_begin_clip (f, NULL); - SetRect (&r, x, y, x + width, y + height); - InvertRect (&r); - mac_end_clip (f, NULL); + 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; + + mac_begin_clip (f, NULL); + SetRect (&r, x, y, x + width, y + height); + InvertRect (&r); + mac_end_clip (f, NULL); + } +#endif } @@ -905,7 +927,7 @@ mac_draw_image_string_atsui (f, gc, x, y, buf, nchars, bg_width, 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}; @@ -929,9 +951,10 @@ mac_draw_image_string_atsui (f, gc, x, y, buf, nchars, bg_width, { 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); @@ -1275,7 +1298,7 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) XChar2b *buf; int nchars, bg_width, overstrike_p; { - float port_height, gx, gy; + CGFloat port_height, gx, gy; int i; CGContextRef context; CGGlyph *glyphs; @@ -1317,8 +1340,8 @@ mac_draw_image_string_cg (f, gc, x, y, buf, nchars, bg_width, overstrike_p) 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); @@ -1613,7 +1636,7 @@ XSetForeground (display, gc, color) } else { - float rgba[4]; + CGFloat rgba[4]; rgba[0] = gc->fore_color.red / 65535.0f; rgba[1] = gc->fore_color.green / 65535.0f; @@ -1654,7 +1677,7 @@ XSetBackground (display, gc, color) } else { - float rgba[4]; + CGFloat rgba[4]; rgba[0] = gc->back_color.red / 65535.0f; rgba[1] = gc->back_color.green / 65535.0f; @@ -1683,8 +1706,8 @@ XSetFont (display, gc, font) /* 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; @@ -1716,9 +1739,9 @@ mac_set_clip_rectangles (display, gc, rectangles, 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 } @@ -1727,8 +1750,8 @@ mac_set_clip_rectangles (display, gc, rectangles, n) /* 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; @@ -2136,7 +2159,7 @@ x_draw_fringe_bitmap (w, row, p) XSetForeground (display, face->gc, gcv.foreground); } - mac_reset_clip_rectangles (display, face->gc); + mac_reset_clip_rectangles (f, face->gc); } #if USE_CG_DRAWING @@ -2650,7 +2673,7 @@ x_set_glyph_string_clipping (s) 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); } @@ -3239,7 +3262,7 @@ x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, 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) @@ -3254,12 +3277,12 @@ x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, 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) @@ -3274,7 +3297,7 @@ x_draw_relief_rect (f, left_x, top_y, right_x, bottom_y, width, 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); } @@ -3296,7 +3319,7 @@ x_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, 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, @@ -3317,7 +3340,7 @@ x_draw_box_rect (s, left_x, top_y, right_x, bottom_y, width, 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); } @@ -3626,7 +3649,7 @@ x_draw_stretch_glyph_string (s) 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) @@ -3826,7 +3849,7 @@ x_draw_glyph_string (s) } /* 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. */ @@ -5008,7 +5031,7 @@ x_clip_to_row (w, row, area, gc) clip_rect.right = clip_rect.left + window_width; clip_rect.bottom = clip_rect.top + row->visible_height; - mac_set_clip_rectangles (FRAME_MAC_DISPLAY (f), gc, &clip_rect, 1); + mac_set_clip_rectangles (f, gc, &clip_rect, 1); } @@ -5050,7 +5073,7 @@ x_draw_hollow_cursor (w, row) /* Set clipping, draw the rectangle, and reset clipping again. */ x_clip_to_row (w, row, TEXT_AREA, gc); mac_draw_rectangle (f, gc, x, y, wd, h - 1); - mac_reset_clip_rectangles (dpy, gc); + mac_reset_clip_rectangles (f, gc); } @@ -5134,7 +5157,7 @@ x_draw_bar_cursor (w, row, width, kind) cursor_glyph->pixel_width, width); - mac_reset_clip_rectangles (dpy, gc); + mac_reset_clip_rectangles (f, gc); } } @@ -5428,7 +5451,6 @@ mac_handle_size_change (f, pixelwidth, pixelheight) 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)); @@ -5454,7 +5476,6 @@ void x_calc_absolute_position (f) struct frame *f; { - int width_diff = 0, height_diff = 0; int flags = f->size_hint_flags; Rect inner, outer; @@ -5469,22 +5490,15 @@ x_calc_absolute_position (f) 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, @@ -8141,8 +8155,8 @@ Lisp_Object Qtoolbar_switch_mode; Lisp_Object Qtext_input; Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event; Lisp_Object Vmac_ts_active_input_overlay; -Lisp_Object Vmac_ts_script_language_on_focus; -Lisp_Object saved_ts_script_language_on_focus; +static Lisp_Object Vmac_ts_script_language_on_focus; +static Lisp_Object saved_ts_script_language_on_focus; static ScriptLanguageRecord saved_ts_language; static Component saved_ts_component; #endif @@ -8673,16 +8687,23 @@ mac_store_event_ref_as_apple_event (class, id, class_key, id_key, err = XINT (binding); else { - AppleEvent apple_event; - err = create_apple_event_from_event_ref (event, num_params, - names, types, - &apple_event); - if (err == noErr) - { - mac_store_apple_event (class_key, id_key, &apple_event); - AEDisposeDesc (&apple_event); - mac_wakeup_from_rne (); - } + struct input_event buf; + + EVENT_INIT (buf); + + buf.kind = MAC_APPLE_EVENT; + buf.x = class_key; + buf.y = id_key; + XSETFRAME (buf.frame_or_window, + mac_focus_frame (&one_mac_display_info)); + /* Now that Lisp object allocations are protected by + BLOCK_INPUT, it is safe to use them during + read_socket_hook. */ + buf.arg = Fcons (build_string ("aevt"), + mac_event_parameters_to_lisp (event, num_params, + names, types)); + kbd_buffer_store_event (&buf); + mac_wakeup_from_rne (); } } From e4aae3c83758bef69969b9d1cb6379fe2f1143ec Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Sat, 19 Apr 2008 01:25:15 +0000 Subject: [PATCH 5/6] (XCreatePixmap, XCreatePixmapFromBitmapData): Use Window instead of WindowRef in argument type. (create_apple_event_from_event_ref, create_apple_event_from_drag_ref) [TARGET_API_MAC_CARBON]: Remove externs. (create_apple_event, mac_event_parameters_to_lisp) [TARGET_API_MAC_CARBON]: Add externs. --- src/macterm.h | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/macterm.h b/src/macterm.h index 8b9eda7a3bb..56d6081c829 100644 --- a/src/macterm.h +++ b/src/macterm.h @@ -636,9 +636,9 @@ extern void x_destroy_window P_ ((struct frame *)); extern void x_wm_set_size_hint P_ ((struct frame *, long, int)); extern void x_delete_display P_ ((struct x_display_info *)); extern void mac_initialize P_ ((void)); -extern Pixmap XCreatePixmap P_ ((Display *, WindowRef, unsigned int, +extern Pixmap XCreatePixmap P_ ((Display *, Window, unsigned int, unsigned int, unsigned int)); -extern Pixmap XCreatePixmapFromBitmapData P_ ((Display *, WindowRef, char *, +extern Pixmap XCreatePixmapFromBitmapData P_ ((Display *, Window, char *, unsigned int, unsigned int, unsigned long, unsigned long, unsigned int)); @@ -683,13 +683,10 @@ extern void mac_clear_font_name_table P_ ((void)); extern Lisp_Object mac_aedesc_to_lisp P_ ((const AEDesc *)); extern OSErr mac_ae_put_lisp P_ ((AEDescList *, UInt32, Lisp_Object)); #if TARGET_API_MAC_CARBON -extern OSStatus create_apple_event_from_event_ref P_ ((EventRef, UInt32, - const EventParamName *, - const EventParamType *, - AppleEvent *)); -extern OSErr create_apple_event_from_drag_ref P_ ((DragRef, UInt32, - const FlavorType *, - AppleEvent *)); +extern OSErr create_apple_event P_ ((AEEventClass, AEEventID, AppleEvent *)); +extern Lisp_Object mac_event_parameters_to_lisp P_ ((EventRef, UInt32, + const EventParamName *, + const EventParamType *)); extern CFStringRef cfstring_create_with_utf8_cstring P_ ((const char *)); extern CFStringRef cfstring_create_with_string P_ ((Lisp_Object)); extern Lisp_Object cfdata_to_lisp P_ ((CFDataRef)); From 81fe843b5a3cc7708e0800aeb5bc0dbe448e800a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Sat, 19 Apr 2008 01:25:50 +0000 Subject: [PATCH 6/6] (Vmac_ts_script_language_on_focus) (saved_ts_script_language_on_focus) [USE_MAC_TSM]: Remove externs. (XTread_socket) [USE_MAC_TOOLBAR]: Select window if its structure part is clicked. (x_activate_menubar): Remove extern for saved_menu_event_location. (create_apple_event_from_drag_ref) [TARGET_API_MAC_CARBON]: Move from mac.c. --- src/ChangeLog | 53 ++++++++++++++++++++++++++++++ src/mactoolbox.c | 85 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 130 insertions(+), 8 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 56676ea95d6..aaa49be146d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,56 @@ +2008-04-19 YAMAMOTO Mitsuharu + + * mac.c (create_apple_event) [TARGET_API_MAC_CARBON]: + Make function non-static. + (create_apple_event_from_event_ref) [TARGET_API_MAC_CARBON]: + Remove function. + (create_apple_event_from_drag_ref) [TARGET_API_MAC_CARBON]: + Move to mactoolbox.c. + (mac_event_parameters_to_lisp) [TARGET_API_MAC_CARBON]: New function. + + * macgui.h (CGFloat) [!CGFLOAT_DEFINED]: New typedef. + (mac_rect_make): New macro. + + * macterm.c (mac_draw_image_string_atsui) [MAC_OSX]: Use CGFloat + instead of float. + (mac_draw_image_string_cg) [USE_CG_TEXT_DRAWING]: Likewise. + (init_cg_color, mac_draw_line, mac_draw_cg_image, XSetForeground) + (XSetBackground) [USE_CG_DRAWING]: Likewise. + (mac_draw_image_string_atsui) [MAC_OSX]: Use mac_rect_make instead of + CGRectMake. + (mac_draw_image_string_cg) [USE_CG_TEXT_DRAWING]: Likewise. + (mac_erase_rectangle, mac_draw_cg_image, mac_fill_rectangle) + (mac_set_clip_rectangles) [USE_CG_DRAWING]: Likewise. + (XCreatePixmap, XCreatePixmapFromBitmapData): Use Window + instead of WindowRef in argument type. + (XCreatePixmap) [!MAC_OS8]: Don't call SetPortWindowPort. + (mac_invert_rectangle): Use CGContextSetBlendMode if available. + (mac_set_clip_rectangles, mac_reset_clip_rectangles): Take argument F + instead of DISPLAY. All uses changed. + (mac_handle_size_change): Don't call SET_FRAME_GARBAGED. + (x_calc_absolute_position): Simplify so as not to use + FRAME_PIXEL_WIDTH/FRAME_PIXEL_HEIGHT. + (Vmac_ts_script_language_on_focus, saved_ts_script_language_on_focus) + [USE_MAC_TSM]: Make variables static. + (mac_store_event_ref_as_apple_event) [TARGET_API_MAC_CARBON]: + Don't use create_apple_event_from_event_ref. + Use mac_event_parameters_to_lisp. + + * macterm.h (XCreatePixmap, XCreatePixmapFromBitmapData): Use Window + instead of WindowRef in argument type. + (create_apple_event_from_event_ref, create_apple_event_from_drag_ref) + [TARGET_API_MAC_CARBON]: Remove externs. + (create_apple_event, mac_event_parameters_to_lisp) + [TARGET_API_MAC_CARBON]: Add externs. + + * mactoolbox.c: (Vmac_ts_script_language_on_focus) + (saved_ts_script_language_on_focus) [USE_MAC_TSM]: Remove externs. + (XTread_socket) [USE_MAC_TOOLBAR]: Select window if its structure part + is clicked. + (x_activate_menubar): Remove extern for saved_menu_event_location. + (create_apple_event_from_drag_ref) [TARGET_API_MAC_CARBON]: + Move from mac.c. + 2008-04-12 YAMAMOTO Mitsuharu * alloc.c [!SYSTEM_MALLOC && !SYNC_INPUT] (uninterrupt_malloc) diff --git a/src/mactoolbox.c b/src/mactoolbox.c index 6b4d22049a9..71abce23fe0 100644 --- a/src/mactoolbox.c +++ b/src/mactoolbox.c @@ -120,8 +120,6 @@ extern Lisp_Object Qtext_input; extern Lisp_Object Qupdate_active_input_area, Qunicode_for_key_event; extern Lisp_Object Vmac_ts_active_input_overlay; extern Lisp_Object Qbefore_string; -extern Lisp_Object Vmac_ts_script_language_on_focus; -extern Lisp_Object saved_ts_script_language_on_focus; #endif static int mac_event_to_emacs_modifiers P_ ((EventRef)); @@ -606,15 +604,15 @@ install_application_handler () #if USE_MAC_TSM if (err == noErr) { - static const EventTypeSpec spec[] = + static const EventTypeSpec specs[] = {{kEventClassTextInput, kEventTextInputUpdateActiveInputArea}, {kEventClassTextInput, kEventTextInputUnicodeForKeyEvent}, {kEventClassTextInput, kEventTextInputOffsetToPos}}; err = InstallApplicationEventHandler (NewEventHandlerUPP (mac_handle_text_input_event), - GetEventTypeCount (spec), - spec, NULL, NULL); + GetEventTypeCount (specs), + specs, NULL, NULL); } #endif @@ -3009,8 +3007,8 @@ mac_event_to_emacs_modifiers (EventRef eventRef) GetEventParameter (eventRef, kEventParamKeyModifiers, typeUInt32, NULL, sizeof (UInt32), NULL, &mods); class = GetEventClass (eventRef); - if (!NILP (Vmac_emulate_three_button_mouse) && - (class == kEventClassMouse || class == kEventClassCommand)) + if (!NILP (Vmac_emulate_three_button_mouse) + && (class == kEventClassMouse || class == kEventClassCommand)) { mods &= ~(optionKey | cmdKey); } @@ -3560,6 +3558,9 @@ XTread_socket (sd, expected, hold_quit) OSStatus err; HIViewRef ch; + if (FrontNonFloatingWindow () != window_ptr) + SelectWindow (window_ptr); + err = HIViewGetViewForMouseEvent (HIViewGetRoot (window_ptr), eventRef, &ch); /* This doesn't work on Mac OS X 10.2. */ @@ -4248,7 +4249,6 @@ x_activate_menubar (f) { SInt32 menu_choice; SInt16 menu_id, menu_item; - extern Point saved_menu_event_location; set_frame_menubar (f, 0, 1); BLOCK_INPUT; @@ -5704,6 +5704,75 @@ static pascal OSErr mac_do_receive_drag P_ ((WindowRef, void *, DragRef)); static DragTrackingHandlerUPP mac_do_track_dragUPP = NULL; static DragReceiveHandlerUPP mac_do_receive_dragUPP = NULL; +static OSErr +create_apple_event_from_drag_ref (drag, num_types, types, result) + DragRef drag; + UInt32 num_types; + const FlavorType *types; + AppleEvent *result; +{ + OSErr err; + UInt16 num_items; + AppleEvent items; + long index; + char *buf = NULL; + + err = CountDragItems (drag, &num_items); + if (err != noErr) + return err; + err = AECreateList (NULL, 0, false, &items); + if (err != noErr) + return err; + + for (index = 1; index <= num_items; index++) + { + ItemReference item; + DescType desc_type = typeNull; + Size size; + + err = GetDragItemReferenceNumber (drag, index, &item); + if (err == noErr) + { + int i; + + for (i = 0; i < num_types; i++) + { + err = GetFlavorDataSize (drag, item, types[i], &size); + if (err == noErr) + { + buf = xrealloc (buf, size); + err = GetFlavorData (drag, item, types[i], buf, &size, 0); + } + if (err == noErr) + { + desc_type = types[i]; + break; + } + } + } + err = AEPutPtr (&items, index, desc_type, + desc_type != typeNull ? buf : NULL, + desc_type != typeNull ? size : 0); + if (err != noErr) + break; + } + if (buf) + xfree (buf); + + if (err == noErr) + { + err = create_apple_event (0, 0, result); /* Dummy class and ID. */ + if (err == noErr) + err = AEPutParamDesc (result, keyDirectObject, &items); + if (err != noErr) + AEDisposeDesc (result); + } + + AEDisposeDesc (&items); + + return err; +} + static void mac_store_drag_event (window, mouse_pos, modifiers, desc) WindowRef window;