aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsterm.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/nsterm.m')
-rw-r--r--src/nsterm.m351
1 files changed, 268 insertions, 83 deletions
diff --git a/src/nsterm.m b/src/nsterm.m
index 546247ab74a..a45792fd645 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1,6 +1,7 @@
1/* NeXT/Open/GNUstep / MacOSX communication module. 1/* NeXT/Open/GNUstep / MacOSX communication module.
2 Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2011 2
3 Free Software Foundation, Inc. 3Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2012
4 Free Software Foundation, Inc.
4 5
5This file is part of GNU Emacs. 6This file is part of GNU Emacs.
6 7
@@ -64,6 +65,7 @@ int term_trace_num = 0;
64#define NSTRACE(x) 65#define NSTRACE(x)
65#endif 66#endif
66 67
68extern NSString *NSMenuDidBeginTrackingNotification;
67 69
68/* ========================================================================== 70/* ==========================================================================
69 71
@@ -164,7 +166,7 @@ static Lisp_Object last_mouse_motion_frame;
164static EmacsScroller *last_mouse_scroll_bar = nil; 166static EmacsScroller *last_mouse_scroll_bar = nil;
165static struct frame *ns_updating_frame; 167static struct frame *ns_updating_frame;
166static NSView *focus_view = NULL; 168static NSView *focus_view = NULL;
167static int ns_window_num =0; 169static int ns_window_num = 0;
168static NSRect uRect; 170static NSRect uRect;
169static BOOL gsaved = NO; 171static BOOL gsaved = NO;
170BOOL ns_in_resize = NO; 172BOOL ns_in_resize = NO;
@@ -263,8 +265,6 @@ static void ns_condemn_scroll_bars (struct frame *f);
263static void ns_judge_scroll_bars (struct frame *f); 265static void ns_judge_scroll_bars (struct frame *f);
264void x_set_frame_alpha (struct frame *f); 266void x_set_frame_alpha (struct frame *f);
265 267
266/* FIXME: figure out what to do with underline_minimum_offset. */
267
268 268
269/* ========================================================================== 269/* ==========================================================================
270 270
@@ -561,7 +561,7 @@ ns_constrain_all_frames (void)
561 { 561 {
562 NSView *view = FRAME_NS_VIEW (f); 562 NSView *view = FRAME_NS_VIEW (f);
563 /* This no-op will trigger the default window placing 563 /* This no-op will trigger the default window placing
564 * constriant system. */ 564 * constraint system. */
565 f->output_data.ns->dont_constrain = 0; 565 f->output_data.ns->dont_constrain = 0;
566 [[view window] setFrameOrigin:[[view window] frame].origin]; 566 [[view window] setFrameOrigin:[[view window] frame].origin];
567 } 567 }
@@ -1125,12 +1125,10 @@ x_iconify_frame (struct frame *f)
1125 [[view window] miniaturize: NSApp]; 1125 [[view window] miniaturize: NSApp];
1126} 1126}
1127 1127
1128/* Free X resources of frame F. */
1128 1129
1129void 1130void
1130x_destroy_window (struct frame *f) 1131x_free_frame_resources (struct frame *f)
1131/* --------------------------------------------------------------------------
1132 External: Delete the window
1133 -------------------------------------------------------------------------- */
1134{ 1132{
1135 NSView *view = FRAME_NS_VIEW (f); 1133 NSView *view = FRAME_NS_VIEW (f);
1136 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f); 1134 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f);
@@ -1162,13 +1160,27 @@ x_destroy_window (struct frame *f)
1162 1160
1163 xfree (f->output_data.ns); 1161 xfree (f->output_data.ns);
1164 1162
1163 if (f->output_data.ns->miniimage != nil)
1164 [f->output_data.ns->miniimage release];
1165
1165 [[view window] close]; 1166 [[view window] close];
1166 [view release]; 1167 [view release];
1167 1168
1168 ns_window_num--;
1169 UNBLOCK_INPUT; 1169 UNBLOCK_INPUT;
1170} 1170}
1171 1171
1172void
1173x_destroy_window (struct frame *f)
1174/* --------------------------------------------------------------------------
1175 External: Delete the window
1176 -------------------------------------------------------------------------- */
1177{
1178 NSTRACE (x_destroy_window);
1179 check_ns ();
1180 x_free_frame_resources (f);
1181 ns_window_num--;
1182}
1183
1172 1184
1173void 1185void
1174x_set_offset (struct frame *f, int xoff, int yoff, int change_grav) 1186x_set_offset (struct frame *f, int xoff, int yoff, int change_grav)
@@ -1343,8 +1355,8 @@ unsigned long
1343ns_index_color (NSColor *color, struct frame *f) 1355ns_index_color (NSColor *color, struct frame *f)
1344{ 1356{
1345 struct ns_color_table *color_table = FRAME_NS_DISPLAY_INFO (f)->color_table; 1357 struct ns_color_table *color_table = FRAME_NS_DISPLAY_INFO (f)->color_table;
1346 int idx; 1358 ptrdiff_t idx;
1347 NSNumber *index; 1359 ptrdiff_t i;
1348 1360
1349 if (!color_table->colors) 1361 if (!color_table->colors)
1350 { 1362 {
@@ -1357,33 +1369,22 @@ ns_index_color (NSColor *color, struct frame *f)
1357 } 1369 }
1358 1370
1359 /* do we already have this color ? */ 1371 /* do we already have this color ? */
1360 { 1372 for (i = 1; i < color_table->avail; i++)
1361 int i; 1373 if (color_table->colors[i] && [color_table->colors[i] isEqual: color])
1362 for (i = 1; i < color_table->avail; i++) 1374 return i;
1363 {
1364 if (color_table->colors[i] && [color_table->colors[i] isEqual: color])
1365 {
1366 [color_table->colors[i] retain];
1367 return i;
1368 }
1369 }
1370 }
1371 1375
1372 if ([color_table->empty_indices count] > 0) 1376 if ([color_table->empty_indices count] > 0)
1373 { 1377 {
1374 index = [color_table->empty_indices anyObject]; 1378 NSNumber *index = [color_table->empty_indices anyObject];
1375 [color_table->empty_indices removeObject: index]; 1379 [color_table->empty_indices removeObject: index];
1376 idx = [index unsignedIntValue]; 1380 idx = [index unsignedLongValue];
1377 } 1381 }
1378 else 1382 else
1379 { 1383 {
1380 if (color_table->avail == color_table->size) 1384 if (color_table->avail == color_table->size)
1381 { 1385 color_table->colors =
1382 color_table->size += NS_COLOR_CAPACITY; 1386 xpalloc (color_table->colors, &color_table->size, 1,
1383 color_table->colors 1387 min (ULONG_MAX, PTRDIFF_MAX), sizeof *color_table->colors);
1384 = (NSColor **)xrealloc (color_table->colors,
1385 color_table->size * sizeof (NSColor *));
1386 }
1387 idx = color_table->avail++; 1388 idx = color_table->avail++;
1388 } 1389 }
1389 1390
@@ -1407,20 +1408,20 @@ ns_free_indexed_color (unsigned long idx, struct frame *f)
1407 color_table = FRAME_NS_DISPLAY_INFO (f)->color_table; 1408 color_table = FRAME_NS_DISPLAY_INFO (f)->color_table;
1408 1409
1409 if (idx <= 0 || idx >= color_table->size) { 1410 if (idx <= 0 || idx >= color_table->size) {
1410 message1("ns_free_indexed_color: Color index out of range.\n"); 1411 message1 ("ns_free_indexed_color: Color index out of range.\n");
1411 return; 1412 return;
1412 } 1413 }
1413 1414
1414 index = [NSNumber numberWithUnsignedInt: idx]; 1415 index = [NSNumber numberWithUnsignedInt: idx];
1415 if ([color_table->empty_indices containsObject: index]) { 1416 if ([color_table->empty_indices containsObject: index]) {
1416 message1("ns_free_indexed_color: attempt to free already freed color.\n"); 1417 message1 ("ns_free_indexed_color: attempt to free already freed color.\n");
1417 return; 1418 return;
1418 } 1419 }
1419 1420
1420 color = color_table->colors[idx]; 1421 color = color_table->colors[idx];
1421 [color release]; 1422 [color release];
1422 color_table->colors[idx] = nil; 1423 color_table->colors[idx] = nil;
1423 [color_table->empty_indices addObject: [NSNumber numberWithUnsignedInt: idx]]; 1424 [color_table->empty_indices addObject: index];
1424/*fprintf(stderr, "color_table: FREED %d\n",idx);*/ 1425/*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1425} 1426}
1426 1427
@@ -2104,7 +2105,7 @@ ns_scroll_run (struct window *w, struct run *run)
2104 } 2105 }
2105 else 2106 else
2106 { 2107 {
2107 /* Scolling down. Make sure we don't copy over the mode line. 2108 /* Scrolling down. Make sure we don't copy over the mode line.
2108 at the bottom. */ 2109 at the bottom. */
2109 if (to_y + run->height > bottom_y) 2110 if (to_y + run->height > bottom_y)
2110 height = bottom_y - to_y; 2111 height = bottom_y - to_y;
@@ -2323,7 +2324,7 @@ ns_draw_fringe_bitmap (struct window *w, struct glyph_row *row,
2323 if (!img) 2324 if (!img)
2324 { 2325 {
2325 unsigned short *bits = p->bits + p->dh; 2326 unsigned short *bits = p->bits + p->dh;
2326 int len = 8 * p->h/8; 2327 int len = p->h;
2327 int i; 2328 int i;
2328 unsigned char *cbits = xmalloc (len); 2329 unsigned char *cbits = xmalloc (len);
2329 2330
@@ -2597,6 +2598,107 @@ ns_get_glyph_string_clip_rect (struct glyph_string *s, NativeRectangle *nr)
2597 return n; 2598 return n;
2598} 2599}
2599 2600
2601void
2602ns_draw_text_decoration (struct glyph_string *s, struct face *face,
2603 NSColor *defaultCol, CGFloat width, CGFloat x)
2604/* --------------------------------------------------------------------------
2605 Draw underline, overline, and strike-through on glyph string s.
2606 -------------------------------------------------------------------------- */
2607{
2608 if (s->for_overlaps)
2609 return;
2610
2611 /* Do underline. */
2612 if (face->underline_p)
2613 {
2614 NSRect r;
2615 unsigned long thickness, position;
2616
2617 /* If the prev was underlined, match its appearance. */
2618 if (s->prev && s->prev->face->underline_p
2619 && s->prev->underline_thickness > 0)
2620 {
2621 thickness = s->prev->underline_thickness;
2622 position = s->prev->underline_position;
2623 }
2624 else
2625 {
2626 struct font *font;
2627 unsigned long descent;
2628
2629 font=s->font;
2630 descent = s->y + s->height - s->ybase;
2631
2632 /* Use underline thickness of font, defaulting to 1. */
2633 thickness = (font && font->underline_thickness > 0)
2634 ? font->underline_thickness : 1;
2635
2636 /* Determine the offset of underlining from the baseline. */
2637 if (x_underline_at_descent_line)
2638 position = descent - thickness;
2639 else if (x_use_underline_position_properties
2640 && font && font->underline_position >= 0)
2641 position = font->underline_position;
2642 else if (font)
2643 position = lround (font->descent / 2);
2644 else
2645 position = underline_minimum_offset;
2646
2647 position = max (position, underline_minimum_offset);
2648
2649 /* Ensure underlining is not cropped. */
2650 if (descent <= position)
2651 {
2652 position = descent - 1;
2653 thickness = 1;
2654 }
2655 else if (descent < position + thickness)
2656 thickness = 1;
2657 }
2658
2659 s->underline_thickness = thickness;
2660 s->underline_position = position;
2661
2662 r = NSMakeRect (x, s->ybase + position, width, thickness);
2663
2664 if (face->underline_defaulted_p)
2665 [defaultCol set];
2666 else
2667 [ns_lookup_indexed_color (face->underline_color, s->f) set];
2668 NSRectFill (r);
2669 }
2670
2671 /* Do overline. We follow other terms in using a thickness of 1
2672 and ignoring overline_margin. */
2673 if (face->overline_p)
2674 {
2675 NSRect r;
2676 r = NSMakeRect (x, s->y, width, 1);
2677
2678 if (face->overline_color_defaulted_p)
2679 [defaultCol set];
2680 else
2681 [ns_lookup_indexed_color (face->overline_color, s->f) set];
2682 NSRectFill (r);
2683 }
2684
2685 /* Do strike-through. We follow other terms for thickness and
2686 vertical position.*/
2687 if (face->strike_through_p)
2688 {
2689 NSRect r;
2690 unsigned long dy;
2691
2692 dy = lrint ((s->height - 1) / 2);
2693 r = NSMakeRect (x, s->y + dy, width, 1);
2694
2695 if (face->strike_through_color_defaulted_p)
2696 [defaultCol set];
2697 else
2698 [ns_lookup_indexed_color (face->strike_through_color, s->f) set];
2699 NSRectFill (r);
2700 }
2701}
2600 2702
2601static void 2703static void
2602ns_draw_box (NSRect r, float thickness, NSColor *col, char left_p, char right_p) 2704ns_draw_box (NSRect r, float thickness, NSColor *col, char left_p, char right_p)
@@ -2854,6 +2956,7 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r)
2854 char raised_p; 2956 char raised_p;
2855 NSRect br; 2957 NSRect br;
2856 struct face *face; 2958 struct face *face;
2959 NSColor *tdCol;
2857 2960
2858 NSTRACE (ns_dumpglyphs_image); 2961 NSTRACE (ns_dumpglyphs_image);
2859 2962
@@ -2882,10 +2985,7 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r)
2882 else 2985 else
2883 face = FACE_FROM_ID (s->f, s->first_glyph->face_id); 2986 face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
2884 2987
2885 if (s->hl == DRAW_CURSOR) 2988 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f) set];
2886 [FRAME_CURSOR_COLOR (s->f) set];
2887 else
2888 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f) set];
2889 2989
2890 if (bg_height > s->slice.height || s->img->hmargin || s->img->vmargin 2990 if (bg_height > s->slice.height || s->img->hmargin || s->img->vmargin
2891 || s->img->mask || s->img->pixmap == 0 || s->width != s->background_width) 2991 || s->img->mask || s->img->pixmap == 0 || s->width != s->background_width)
@@ -2923,6 +3023,27 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r)
2923 [img compositeToPoint: NSMakePoint (x, y + s->slice.height) 3023 [img compositeToPoint: NSMakePoint (x, y + s->slice.height)
2924 operation: NSCompositeSourceOver]; 3024 operation: NSCompositeSourceOver];
2925 3025
3026 if (s->hl == DRAW_CURSOR)
3027 {
3028 [FRAME_CURSOR_COLOR (s->f) set];
3029 if (s->w->phys_cursor_type == FILLED_BOX_CURSOR)
3030 tdCol = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f);
3031 else
3032 /* Currently on NS img->mask is always 0. Since
3033 get_window_cursor_type specifies a hollow box cursor when on
3034 a non-masked image we never reach this clause. But we put it
3035 in in anticipation of better support for image masks on
3036 NS. */
3037 tdCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f);
3038 }
3039 else
3040 {
3041 tdCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f);
3042 }
3043
3044 /* Draw underline, overline, strike-through. */
3045 ns_draw_text_decoration (s, face, tdCol, br.size.width, br.origin.x);
3046
2926 /* Draw relief, if requested */ 3047 /* Draw relief, if requested */
2927 if (s->img->relief || s->hl ==DRAW_IMAGE_RAISED || s->hl ==DRAW_IMAGE_SUNKEN) 3048 if (s->img->relief || s->hl ==DRAW_IMAGE_RAISED || s->hl ==DRAW_IMAGE_SUNKEN)
2928 { 3049 {
@@ -2951,7 +3072,7 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r)
2951 3072
2952 /* If there is no mask, the background won't be seen, 3073 /* If there is no mask, the background won't be seen,
2953 so draw a rectangle on the image for the cursor. 3074 so draw a rectangle on the image for the cursor.
2954 Do this for all images, getting trancparency right is not reliable. */ 3075 Do this for all images, getting transparency right is not reliable. */
2955 if (s->hl == DRAW_CURSOR) 3076 if (s->hl == DRAW_CURSOR)
2956 { 3077 {
2957 int thickness = abs (s->img->relief); 3078 int thickness = abs (s->img->relief);
@@ -2967,22 +3088,49 @@ ns_dumpglyphs_stretch (struct glyph_string *s)
2967 NSRect r[2]; 3088 NSRect r[2];
2968 int n, i; 3089 int n, i;
2969 struct face *face; 3090 struct face *face;
3091 NSColor *fgCol, *bgCol;
2970 3092
2971 if (!s->background_filled_p) 3093 if (!s->background_filled_p)
2972 { 3094 {
2973 n = ns_get_glyph_string_clip_rect (s, r); 3095 n = ns_get_glyph_string_clip_rect (s, r);
2974 *r = NSMakeRect (s->x, s->y, s->background_width, s->height); 3096 *r = NSMakeRect (s->x, s->y, s->background_width, s->height);
2975 3097
3098 ns_focus (s->f, r, n);
3099
3100 if (s->hl == DRAW_MOUSE_FACE)
3101 {
3102 face = FACE_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id);
3103 if (!face)
3104 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
3105 }
3106 else
3107 face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
3108
3109 bgCol = ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f);
3110 fgCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f);
3111
2976 for (i=0; i<n; i++) 3112 for (i=0; i<n; i++)
2977 { 3113 {
2978 if (!s->row->full_width_p) 3114 if (!s->row->full_width_p)
2979 { 3115 {
3116 int overrun, leftoverrun;
3117
2980 /* truncate to avoid overwriting fringe and/or scrollbar */ 3118 /* truncate to avoid overwriting fringe and/or scrollbar */
2981 int overrun = max (0, (s->x + s->background_width) 3119 overrun = max (0, (s->x + s->background_width)
2982 - (WINDOW_BOX_RIGHT_EDGE_X (s->w) 3120 - (WINDOW_BOX_RIGHT_EDGE_X (s->w)
2983 - WINDOW_RIGHT_FRINGE_WIDTH (s->w))); 3121 - WINDOW_RIGHT_FRINGE_WIDTH (s->w)));
2984 r[i].size.width -= overrun; 3122 r[i].size.width -= overrun;
2985 3123
3124 /* truncate to avoid overwriting to left of the window box */
3125 leftoverrun = (WINDOW_BOX_LEFT_EDGE_X (s->w)
3126 + WINDOW_LEFT_FRINGE_WIDTH (s->w)) - s->x;
3127
3128 if (leftoverrun > 0)
3129 {
3130 r[i].origin.x += leftoverrun;
3131 r[i].size.width -= leftoverrun;
3132 }
3133
2986 /* XXX: Try to work between problem where a stretch glyph on 3134 /* XXX: Try to work between problem where a stretch glyph on
2987 a partially-visible bottom row will clear part of the 3135 a partially-visible bottom row will clear part of the
2988 modeline, and another where list-buffers headers and similar 3136 modeline, and another where list-buffers headers and similar
@@ -2998,30 +3146,37 @@ ns_dumpglyphs_stretch (struct glyph_string *s)
2998 FRAME_PIXEL_WIDTH (s->f)); 3146 FRAME_PIXEL_WIDTH (s->f));
2999 } 3147 }
3000 3148
3149 [bgCol set];
3150
3001 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid 3151 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3002 overwriting cursor (usually when cursor on a tab) */ 3152 overwriting cursor (usually when cursor on a tab) */
3003 if (s->hl == DRAW_CURSOR) 3153 if (s->hl == DRAW_CURSOR)
3004 { 3154 {
3005 r[i].origin.x += s->width; 3155 CGFloat x, width;
3006 r[i].size.width -= s->width;
3007 }
3008 }
3009 3156
3010 ns_focus (s->f, r, n); 3157 x = r[i].origin.x;
3158 width = s->w->phys_cursor_width;
3159 r[i].size.width -= width;
3160 r[i].origin.x += width;
3011 3161
3012 if (s->hl == DRAW_MOUSE_FACE) 3162 NSRectFill (r[i]);
3013 {
3014 face = FACE_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id);
3015 if (!face)
3016 face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
3017 }
3018 else
3019 face = FACE_FROM_ID (s->f, s->first_glyph->face_id);
3020 3163
3021 [ns_lookup_indexed_color (NS_FACE_BACKGROUND (face), s->f) set]; 3164 /* Draw overlining, etc. on the cursor. */
3165 if (s->w->phys_cursor_type == FILLED_BOX_CURSOR)
3166 ns_draw_text_decoration (s, face, bgCol, width, x);
3167 else
3168 ns_draw_text_decoration (s, face, fgCol, width, x);
3169 }
3170 else
3171 {
3172 NSRectFill (r[i]);
3173 }
3022 3174
3023 NSRectFill (r[0]); 3175 /* Draw overlining, etc. on the stretch glyph (or the part
3024 NSRectFill (r[1]); 3176 of the stretch glyph after the cursor). */
3177 ns_draw_text_decoration (s, face, fgCol, r[i].size.width,
3178 r[i].origin.x);
3179 }
3025 ns_unfocus (s->f); 3180 ns_unfocus (s->f);
3026 s->background_filled_p = 1; 3181 s->background_filled_p = 1;
3027 } 3182 }
@@ -3666,11 +3821,9 @@ ns_default (const char *parameter, Lisp_Object *result,
3666 Check a parameter value in user's preferences 3821 Check a parameter value in user's preferences
3667 -------------------------------------------------------------------------- */ 3822 -------------------------------------------------------------------------- */
3668{ 3823{
3669 const char *value; 3824 const char *value = ns_get_defaults_value (parameter);
3670 3825
3671 if ( (value =[[[NSUserDefaults standardUserDefaults] 3826 if (value)
3672 stringForKey: [NSString stringWithUTF8String: parameter]]
3673 UTF8String]) )
3674 { 3827 {
3675 double f; 3828 double f;
3676 char *pos; 3829 char *pos;
@@ -4047,6 +4200,15 @@ ns_term_init (Lisp_Object display_name)
4047 [NSApp setServicesMenu: svcsMenu]; 4200 [NSApp setServicesMenu: svcsMenu];
4048 /* Needed at least on Cocoa, to get dock menu to show windows */ 4201 /* Needed at least on Cocoa, to get dock menu to show windows */
4049 [NSApp setWindowsMenu: [[NSMenu alloc] init]]; 4202 [NSApp setWindowsMenu: [[NSMenu alloc] init]];
4203
4204 [[NSNotificationCenter defaultCenter]
4205 addObserver: mainMenu
4206 selector: @selector (trackingNotification:)
4207 name: NSMenuDidBeginTrackingNotification object: mainMenu];
4208 [[NSNotificationCenter defaultCenter]
4209 addObserver: mainMenu
4210 selector: @selector (trackingNotification:)
4211 name: NSMenuDidEndTrackingNotification object: mainMenu];
4050 } 4212 }
4051#endif /* MAC OS X menu setup */ 4213#endif /* MAC OS X menu setup */
4052 4214
@@ -4105,6 +4267,16 @@ ns_term_shutdown (int sig)
4105/* NSTRACE (sendEvent); */ 4267/* NSTRACE (sendEvent); */
4106/*fprintf (stderr, "received event of type %d\t%d\n", type);*/ 4268/*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4107 4269
4270#ifdef NS_IMPL_COCOA
4271 if (type == NSApplicationDefined
4272 && [theEvent data2] == NSAPP_DATA2_RUNASSCRIPT)
4273 {
4274 ns_run_ascript ();
4275 [self stop: self];
4276 return;
4277 }
4278#endif
4279
4108 if (type == NSCursorUpdate && window == nil) 4280 if (type == NSCursorUpdate && window == nil)
4109 { 4281 {
4110 fprintf (stderr, "Dropping external cursor update event.\n"); 4282 fprintf (stderr, "Dropping external cursor update event.\n");
@@ -4335,7 +4507,7 @@ ns_term_shutdown (int sig)
4335 //ns_app_active=YES; 4507 //ns_app_active=YES;
4336 4508
4337 ns_update_auto_hide_menu_bar (); 4509 ns_update_auto_hide_menu_bar ();
4338 // No constrining takes place when the application is not active. 4510 // No constraining takes place when the application is not active.
4339 ns_constrain_all_frames (); 4511 ns_constrain_all_frames ();
4340} 4512}
4341- (void)applicationDidResignActive: (NSNotification *)notification 4513- (void)applicationDidResignActive: (NSNotification *)notification
@@ -4705,7 +4877,7 @@ ns_term_shutdown (int sig)
4705 } 4877 }
4706 } 4878 }
4707 4879
4708 4880
4709#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 4881#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
4710 /* if we get here we should send the key for input manager processing */ 4882 /* if we get here we should send the key for input manager processing */
4711 if (firstTime && [[NSInputManager currentInputManager] 4883 if (firstTime && [[NSInputManager currentInputManager]
@@ -5157,7 +5329,7 @@ ns_term_shutdown (int sig)
5157 strcpy (old_title, t); 5329 strcpy (old_title, t);
5158 } 5330 }
5159 size_title = xmalloc (strlen (old_title) + 40); 5331 size_title = xmalloc (strlen (old_title) + 40);
5160 sprintf (size_title, "%s — (%d x %d)", old_title, cols, rows); 5332 esprintf (size_title, "%s — (%d x %d)", old_title, cols, rows);
5161 [window setTitle: [NSString stringWithUTF8String: size_title]]; 5333 [window setTitle: [NSString stringWithUTF8String: size_title]];
5162 [window display]; 5334 [window display];
5163 xfree (size_title); 5335 xfree (size_title);
@@ -5198,7 +5370,23 @@ ns_term_shutdown (int sig)
5198 a "windowDidResize" which calls x_set_window_size). */ 5370 a "windowDidResize" which calls x_set_window_size). */
5199#ifndef NS_IMPL_GNUSTEP 5371#ifndef NS_IMPL_GNUSTEP
5200 if (cols > 0 && rows > 0) 5372 if (cols > 0 && rows > 0)
5201 x_set_window_size (emacsframe, 0, cols, rows); 5373 {
5374 if (ns_in_resize)
5375 x_set_window_size (emacsframe, 0, cols, rows);
5376 else
5377 {
5378 NSWindow *window = [self window];
5379 NSRect wr = [window frame];
5380 FRAME_PIXEL_WIDTH (emacsframe) = (int)wr.size.width
5381 - emacsframe->border_width;
5382 FRAME_PIXEL_HEIGHT (emacsframe) = (int)wr.size.height
5383 - FRAME_NS_TITLEBAR_HEIGHT (emacsframe)
5384 - FRAME_TOOLBAR_HEIGHT (emacsframe);
5385 change_frame_size (emacsframe, rows, cols, 0, 0, 1);
5386 SET_FRAME_GARBAGED (emacsframe);
5387 cancel_mouse_face (emacsframe);
5388 }
5389 }
5202#endif 5390#endif
5203 5391
5204 ns_send_appdefined (-1); 5392 ns_send_appdefined (-1);
@@ -5304,6 +5492,9 @@ ns_term_shutdown (int sig)
5304 win = [[EmacsWindow alloc] 5492 win = [[EmacsWindow alloc]
5305 initWithContentRect: r 5493 initWithContentRect: r
5306 styleMask: (NSResizableWindowMask | 5494 styleMask: (NSResizableWindowMask |
5495#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
5496 NSTitledWindowMask |
5497#endif
5307 NSMiniaturizableWindowMask | 5498 NSMiniaturizableWindowMask |
5308 NSClosableWindowMask) 5499 NSClosableWindowMask)
5309 backing: NSBackingStoreBuffered 5500 backing: NSBackingStoreBuffered
@@ -6546,30 +6737,24 @@ Only works on OSX 10.6 or later. */);
6546 6737
6547 /* TODO: move to common code */ 6738 /* TODO: move to common code */
6548 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars, 6739 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
6549 doc: /* If not nil, Emacs uses toolkit scroll bars. */); 6740 doc: /* Which toolkit scroll bars Emacs uses, if any.
6550#ifdef USE_TOOLKIT_SCROLL_BARS 6741A value of nil means Emacs doesn't use toolkit scroll bars.
6742With the X Window system, the value is a symbol describing the
6743X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
6744With MS Windows or Nextstep, the value is t. */);
6551 Vx_toolkit_scroll_bars = Qt; 6745 Vx_toolkit_scroll_bars = Qt;
6552#else
6553 Vx_toolkit_scroll_bars = Qnil;
6554#endif
6555 6746
6556 /* these are unsupported but we need the declarations to avoid whining
6557 messages from cus-start.el */
6558 DEFVAR_BOOL ("x-use-underline-position-properties", 6747 DEFVAR_BOOL ("x-use-underline-position-properties",
6559 x_use_underline_position_properties, 6748 x_use_underline_position_properties,
6560 doc: /* NOT SUPPORTED UNDER NS. 6749 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
6561*Non-nil means make use of UNDERLINE_POSITION font properties.
6562A value of nil means ignore them. If you encounter fonts with bogus 6750A value of nil means ignore them. If you encounter fonts with bogus
6563UNDERLINE_POSITION font properties, for example 7x13 on XFree prior 6751UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
6564to 4.1, set this to nil. 6752to 4.1, set this to nil. */);
6565
6566NOTE: Not supported on Mac yet. */);
6567 x_use_underline_position_properties = 0; 6753 x_use_underline_position_properties = 0;
6568 6754
6569 DEFVAR_BOOL ("x-underline-at-descent-line", 6755 DEFVAR_BOOL ("x-underline-at-descent-line",
6570 x_underline_at_descent_line, 6756 x_underline_at_descent_line,
6571 doc: /* NOT SUPPORTED UNDER NS. 6757 doc: /* Non-nil means to draw the underline at the same place as the descent line.
6572*Non-nil means to draw the underline at the same place as the descent line.
6573A value of nil means to draw the underline according to the value of the 6758A value of nil means to draw the underline according to the value of the
6574variable `x-use-underline-position-properties', which is usually at the 6759variable `x-use-underline-position-properties', which is usually at the
6575baseline level. The default value is nil. */); 6760baseline level. The default value is nil. */);