X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/86633eab8a77697f6e15aae568868781a5a1023f..94f0aa3464955865f5abdac6b335a86aca3e180a:/src/nsterm.m diff --git a/src/nsterm.m b/src/nsterm.m index 827404a297..7cbaf99131 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1,6 +1,7 @@ /* NeXT/Open/GNUstep / MacOSX communication module. - Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2011 - Free Software Foundation, Inc. + +Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2012 + Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -64,6 +65,7 @@ int term_trace_num = 0; #define NSTRACE(x) #endif +extern NSString *NSMenuDidBeginTrackingNotification; /* ========================================================================== @@ -164,7 +166,7 @@ static Lisp_Object last_mouse_motion_frame; static EmacsScroller *last_mouse_scroll_bar = nil; static struct frame *ns_updating_frame; static NSView *focus_view = NULL; -static int ns_window_num =0; +static int ns_window_num = 0; static NSRect uRect; static BOOL gsaved = NO; BOOL ns_in_resize = NO; @@ -559,7 +561,7 @@ ns_constrain_all_frames (void) { NSView *view = FRAME_NS_VIEW (f); /* This no-op will trigger the default window placing - * constriant system. */ + * constraint system. */ f->output_data.ns->dont_constrain = 0; [[view window] setFrameOrigin:[[view window] frame].origin]; } @@ -1123,12 +1125,10 @@ x_iconify_frame (struct frame *f) [[view window] miniaturize: NSApp]; } +/* Free X resources of frame F. */ void -x_destroy_window (struct frame *f) -/* -------------------------------------------------------------------------- - External: Delete the window - -------------------------------------------------------------------------- */ +x_free_frame_resources (struct frame *f) { NSView *view = FRAME_NS_VIEW (f); struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (f); @@ -1160,13 +1160,27 @@ x_destroy_window (struct frame *f) xfree (f->output_data.ns); + if (f->output_data.ns->miniimage != nil) + [f->output_data.ns->miniimage release]; + [[view window] close]; [view release]; - ns_window_num--; UNBLOCK_INPUT; } +void +x_destroy_window (struct frame *f) +/* -------------------------------------------------------------------------- + External: Delete the window + -------------------------------------------------------------------------- */ +{ + NSTRACE (x_destroy_window); + check_ns (); + x_free_frame_resources (f); + ns_window_num--; +} + void x_set_offset (struct frame *f, int xoff, int yoff, int change_grav) @@ -1342,7 +1356,7 @@ ns_index_color (NSColor *color, struct frame *f) { struct ns_color_table *color_table = FRAME_NS_DISPLAY_INFO (f)->color_table; ptrdiff_t idx; - NSNumber *index; + ptrdiff_t i; if (!color_table->colors) { @@ -1355,21 +1369,13 @@ ns_index_color (NSColor *color, struct frame *f) } /* do we already have this color ? */ - { - ptrdiff_t i; - for (i = 1; i < color_table->avail; i++) - { - if (color_table->colors[i] && [color_table->colors[i] isEqual: color]) - { - [color_table->colors[i] retain]; - return i; - } - } - } + for (i = 1; i < color_table->avail; i++) + if (color_table->colors[i] && [color_table->colors[i] isEqual: color]) + return i; if ([color_table->empty_indices count] > 0) { - index = [color_table->empty_indices anyObject]; + NSNumber *index = [color_table->empty_indices anyObject]; [color_table->empty_indices removeObject: index]; idx = [index unsignedLongValue]; } @@ -1402,20 +1408,20 @@ ns_free_indexed_color (unsigned long idx, struct frame *f) color_table = FRAME_NS_DISPLAY_INFO (f)->color_table; if (idx <= 0 || idx >= color_table->size) { - message1("ns_free_indexed_color: Color index out of range.\n"); + message1 ("ns_free_indexed_color: Color index out of range.\n"); return; } index = [NSNumber numberWithUnsignedInt: idx]; if ([color_table->empty_indices containsObject: index]) { - message1("ns_free_indexed_color: attempt to free already freed color.\n"); + message1 ("ns_free_indexed_color: attempt to free already freed color.\n"); return; } color = color_table->colors[idx]; [color release]; color_table->colors[idx] = nil; - [color_table->empty_indices addObject: [NSNumber numberWithUnsignedInt: idx]]; + [color_table->empty_indices addObject: index]; /*fprintf(stderr, "color_table: FREED %d\n",idx);*/ } @@ -2099,7 +2105,7 @@ ns_scroll_run (struct window *w, struct run *run) } else { - /* Scolling down. Make sure we don't copy over the mode line. + /* Scrolling down. Make sure we don't copy over the mode line. at the bottom. */ if (to_y + run->height > bottom_y) height = bottom_y - to_y; @@ -3026,7 +3032,7 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r) /* Currently on NS img->mask is always 0. Since get_window_cursor_type specifies a hollow box cursor when on a non-masked image we never reach this clause. But we put it - in in antipication of better support for image masks on + in in anticipation of better support for image masks on NS. */ tdCol = ns_lookup_indexed_color (NS_FACE_FOREGROUND (face), s->f); } @@ -3066,7 +3072,7 @@ ns_dumpglyphs_image (struct glyph_string *s, NSRect r) /* If there is no mask, the background won't be seen, so draw a rectangle on the image for the cursor. - Do this for all images, getting trancparency right is not reliable. */ + Do this for all images, getting transparency right is not reliable. */ if (s->hl == DRAW_CURSOR) { int thickness = abs (s->img->relief); @@ -3815,11 +3821,9 @@ ns_default (const char *parameter, Lisp_Object *result, Check a parameter value in user's preferences -------------------------------------------------------------------------- */ { - const char *value; + const char *value = ns_get_defaults_value (parameter); - if ( (value =[[[NSUserDefaults standardUserDefaults] - stringForKey: [NSString stringWithUTF8String: parameter]] - UTF8String]) ) + if (value) { double f; char *pos; @@ -4196,6 +4200,15 @@ ns_term_init (Lisp_Object display_name) [NSApp setServicesMenu: svcsMenu]; /* Needed at least on Cocoa, to get dock menu to show windows */ [NSApp setWindowsMenu: [[NSMenu alloc] init]]; + + [[NSNotificationCenter defaultCenter] + addObserver: mainMenu + selector: @selector (trackingNotification:) + name: NSMenuDidBeginTrackingNotification object: mainMenu]; + [[NSNotificationCenter defaultCenter] + addObserver: mainMenu + selector: @selector (trackingNotification:) + name: NSMenuDidEndTrackingNotification object: mainMenu]; } #endif /* MAC OS X menu setup */ @@ -4494,7 +4507,7 @@ ns_term_shutdown (int sig) //ns_app_active=YES; ns_update_auto_hide_menu_bar (); - // No constrining takes place when the application is not active. + // No constraining takes place when the application is not active. ns_constrain_all_frames (); } - (void)applicationDidResignActive: (NSNotification *)notification @@ -5357,7 +5370,23 @@ ns_term_shutdown (int sig) a "windowDidResize" which calls x_set_window_size). */ #ifndef NS_IMPL_GNUSTEP if (cols > 0 && rows > 0) - x_set_window_size (emacsframe, 0, cols, rows); + { + if (ns_in_resize) + x_set_window_size (emacsframe, 0, cols, rows); + else + { + NSWindow *window = [self window]; + NSRect wr = [window frame]; + FRAME_PIXEL_WIDTH (emacsframe) = (int)wr.size.width + - emacsframe->border_width; + FRAME_PIXEL_HEIGHT (emacsframe) = (int)wr.size.height + - FRAME_NS_TITLEBAR_HEIGHT (emacsframe) + - FRAME_TOOLBAR_HEIGHT (emacsframe); + change_frame_size (emacsframe, rows, cols, 0, 0, 1); + SET_FRAME_GARBAGED (emacsframe); + cancel_mouse_face (emacsframe); + } + } #endif ns_send_appdefined (-1); @@ -6009,11 +6038,15 @@ ns_term_shutdown (int sig) restrict the height to just one monitor. So we override this. */ - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen { - /* When making the frame visible for the first time, we want to - constrain. Other times not. */ + /* When making the frame visible for the first time or if there is just + one screen, we want to constrain. Other times not. */ + NSUInteger nr_screens = [[NSScreen screens] count]; struct frame *f = ((EmacsView *)[self delegate])->emacsframe; NSTRACE (constrainFrameRect); + if (nr_screens == 1) + return [super constrainFrameRect:frameRect toScreen:screen]; + if (f->output_data.ns->dont_constrain || ns_menu_bar_should_be_hidden ()) return frameRect; @@ -6708,12 +6741,12 @@ Only works on OSX 10.6 or later. */); /* TODO: move to common code */ DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars, - doc: /* If not nil, Emacs uses toolkit scroll bars. */); -#ifdef USE_TOOLKIT_SCROLL_BARS + doc: /* Which toolkit scroll bars Emacs uses, if any. +A value of nil means Emacs doesn't use toolkit scroll bars. +With the X Window system, the value is a symbol describing the +X toolkit. Possible values are: gtk, motif, xaw, or xaw3d. +With MS Windows or Nextstep, the value is t. */); Vx_toolkit_scroll_bars = Qt; -#else - Vx_toolkit_scroll_bars = Qnil; -#endif DEFVAR_BOOL ("x-use-underline-position-properties", x_use_underline_position_properties,