/* NeXT/Open/GNUstep / MacOSX communication module.
-Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2014 Free Software
+Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2015 Free Software
Foundation, Inc.
This file is part of GNU Emacs.
#endif
#ifdef NS_IMPL_COCOA
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
#include "macfont.h"
#endif
-#endif
/* call tracing */
#if 0
0x1B, 0x1B /* escape */
};
-static Lisp_Object Qmodifier_value;
-Lisp_Object Qalt, Qcontrol, Qhyper, Qmeta, Qsuper;
-extern Lisp_Object Qcursor_color, Qcursor_type, Qns;
-
-static Lisp_Object QUTF8_STRING;
-static Lisp_Object Qcocoa, Qgnustep;
-static Lisp_Object Qfile, Qurl;
-
/* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
the maximum font size to NOT antialias. On GNUstep there is currently
no way to control this behavior. */
NULL, 0, 0
};
+static NSString *represented_filename = nil;
+static struct frame *represented_frame = 0;
+
#ifdef NS_IMPL_COCOA
/*
* State for pending menu activation:
if (e) emacs_event->timestamp = EV_TIMESTAMP (e); \
if (q_event_ptr) \
{ \
+ Lisp_Object tem = Vinhibit_quit; \
+ Vinhibit_quit = Qt; \
n_emacs_events_pending++; \
kbd_buffer_store_event_hold (emacs_event, q_event_ptr); \
+ Vinhibit_quit = tem; \
} \
else \
hold_event (emacs_event); \
========================================================================== */
+void
+ns_set_represented_filename (NSString* fstr, struct frame *f)
+{
+ represented_filename = [fstr retain];
+ represented_frame = f;
+}
+
void
ns_init_events (struct input_event* ev)
{
ns_update_auto_hide_menu_bar (void)
{
#ifdef NS_IMPL_COCOA
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
block_input ();
NSTRACE (ns_update_auto_hide_menu_bar);
unblock_input ();
#endif
-#endif
}
static void
-ns_frame_raise_lower (struct frame *f, int raise)
+ns_frame_raise_lower (struct frame *f, bool raise)
/* --------------------------------------------------------------------------
External (hook)
-------------------------------------------------------------------------- */
void
x_set_window_size (struct frame *f,
- int change_grav,
+ bool change_gravity,
int width,
int height,
bool pixelwise)
[view setBoundsOrigin: origin];
}
- change_frame_size (f, width, height, 0, 1, 0, pixelwise);
-/* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
-
- mark_window_cursors_off (XWINDOW (f->root_window));
- cancel_mouse_face (f);
-
+ [view updateFrameSize: NO];
unblock_input ();
-
- do_pending_window_change (0);
}
block_input ();
- if (dpyinfo->last_mouse_scroll_bar != nil && insist == 0)
- {
- /* TODO: we do not use this path at the moment because drag events will
- go directly to the EmacsScroller. Leaving code in for now. */
- [dpyinfo->last_mouse_scroll_bar
- getMouseMotionPart: (int *)part window: bar_window x: x y: y];
- if (time)
- *time = dpyinfo->last_mouse_movement_time;
- dpyinfo->last_mouse_scroll_bar = nil;
- }
+ /* Clear the mouse-moved flag for every frame on this display. */
+ FOR_EACH_FRAME (tail, frame)
+ if (FRAME_NS_P (XFRAME (frame))
+ && FRAME_NS_DISPLAY (XFRAME (frame)) == FRAME_NS_DISPLAY (*fp))
+ XFRAME (frame)->mouse_moved = 0;
+
+ dpyinfo->last_mouse_scroll_bar = nil;
+ if (dpyinfo->last_mouse_frame
+ && FRAME_LIVE_P (dpyinfo->last_mouse_frame))
+ f = dpyinfo->last_mouse_frame;
else
- {
- /* Clear the mouse-moved flag for every frame on this display. */
- FOR_EACH_FRAME (tail, frame)
- if (FRAME_NS_P (XFRAME (frame))
- && FRAME_NS_DISPLAY (XFRAME (frame)) == FRAME_NS_DISPLAY (*fp))
- XFRAME (frame)->mouse_moved = 0;
-
- dpyinfo->last_mouse_scroll_bar = nil;
- if (dpyinfo->last_mouse_frame
- && FRAME_LIVE_P (dpyinfo->last_mouse_frame))
- f = dpyinfo->last_mouse_frame;
- else
- f = dpyinfo->x_focus_frame ? dpyinfo->x_focus_frame
- : SELECTED_FRAME ();
+ f = dpyinfo->x_focus_frame ? dpyinfo->x_focus_frame : SELECTED_FRAME ();
- if (f && FRAME_NS_P (f))
- {
- view = FRAME_NS_VIEW (*fp);
+ if (f && FRAME_NS_P (f))
+ {
+ view = FRAME_NS_VIEW (*fp);
- position = [[view window] mouseLocationOutsideOfEventStream];
- position = [view convertPoint: position fromView: nil];
- remember_mouse_glyph (f, position.x, position.y,
- &dpyinfo->last_mouse_glyph);
+ position = [[view window] mouseLocationOutsideOfEventStream];
+ position = [view convertPoint: position fromView: nil];
+ remember_mouse_glyph (f, position.x, position.y,
+ &dpyinfo->last_mouse_glyph);
+/*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
- if (bar_window) *bar_window = Qnil;
- if (part) *part = scroll_bar_above_handle;
+ if (bar_window) *bar_window = Qnil;
+ if (part) *part = scroll_bar_above_handle;
- if (x) XSETINT (*x, lrint (position.x));
- if (y) XSETINT (*y, lrint (position.y));
- if (time)
- *time = dpyinfo->last_mouse_movement_time;
- *fp = f;
- }
+ if (x) XSETINT (*x, lrint (position.x));
+ if (y) XSETINT (*y, lrint (position.y));
+ if (time)
+ *time = dpyinfo->last_mouse_movement_time;
+ *fp = f;
}
unblock_input ();
[img setXBMColor: bm_color];
}
-#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+#ifdef NS_IMPL_COCOA
[img drawInRect: r
fromRect: NSZeroRect
operation: NSCompositeSourceOver
/* Draw the image.. do we need to draw placeholder if img ==nil? */
if (img != nil)
{
-#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+#ifdef NS_IMPL_COCOA
NSRect dr = NSMakeRect (x, y, s->slice.width, s->slice.height);
NSRect ir = NSMakeRect (s->slice.x, s->slice.y,
s->slice.width, s->slice.height);
/* Only post this event if we haven't already posted one. This will end
the [NXApp run] main loop after having processed all events queued at
this moment. */
+
+#ifdef NS_IMPL_COCOA
+ if (! send_appdefined)
+ {
+ /* OSX 10.10.1 swallows the AppDefined event we are sending ourselves
+ in certain situations (rapid incoming events).
+ So check if we have one, if not add one. */
+ NSEvent *appev = [NSApp nextEventMatchingMask:NSApplicationDefinedMask
+ untilDate:[NSDate distantPast]
+ inMode:NSDefaultRunLoopMode
+ dequeue:NO];
+ if (! appev) send_appdefined = YES;
+ }
+#endif
+
if (send_appdefined)
{
NSEvent *nxev;
}
#endif
-/* GNUstep and OSX <= 10.4 does not have cancelTracking. */
-#if defined (NS_IMPL_COCOA) && \
- MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
+/* GNUstep does not have cancelTracking. */
+#ifdef NS_IMPL_COCOA
/* Check if menu open should be canceled or continued as normal. */
void
ns_check_menu_open (NSMenu *menu)
menu_will_open_state = MENU_OPENING;
}
}
-#endif /* NS_IMPL_COCOA) && >= MAC_OS_X_VERSION_10_5 */
+#endif /* NS_IMPL_COCOA */
static void
unwind_apploopnr (Lisp_Object not_used)
EmacsScroller *bar;
int window_y, window_height;
int top, left, height, width;
+ BOOL update_p = YES;
/* optimization; display engine sends WAY too many of these.. */
if (!NILP (window->vertical_scroll_bar))
}
else
view->scrollbarsNeedingUpdate--;
+ update_p = NO;
}
}
bar = XNS_SCROLL_BAR (window->vertical_scroll_bar);
[bar removeFromSuperview];
wset_vertical_scroll_bar (window, Qnil);
+ [bar release];
}
ns_clear_frame_area (f, left, top, width, height);
unblock_input ();
bar = [[EmacsScroller alloc] initFrame: r window: win];
wset_vertical_scroll_bar (window, make_save_ptr (bar));
+ update_p = YES;
}
else
{
}
}
- [bar setPosition: position portion: portion whole: whole];
+ if (update_p)
+ [bar setPosition: position portion: portion whole: whole];
unblock_input ();
}
int top, height, left, width;
int window_x, window_width;
int pixel_width = WINDOW_PIXEL_WIDTH (window);
+ BOOL update_p = YES;
/* optimization; display engine sends WAY too many of these.. */
if (!NILP (window->horizontal_scroll_bar))
}
else
view->scrollbarsNeedingUpdate--;
+ update_p = NO;
}
}
bar = [[EmacsScroller alloc] initFrame: r window: win];
wset_horizontal_scroll_bar (window, make_save_ptr (bar));
+ update_p = YES;
}
else
{
if (oldRect.origin.x != r.origin.x)
ns_clear_frame_area (f, left, top, width, height);
[bar setFrame: r];
+ update_p = YES;
}
}
- [bar setPosition: position portion: portion whole: whole];
+ if (update_p)
+ [bar setPosition: position portion: portion whole: whole];
unblock_input ();
}
{
view = [subviews objectAtIndex: i];
if (![view isKindOfClass: [EmacsScroller class]]) continue;
- [view judge];
- removed = YES;
+ if ([view judge])
+ removed = YES;
}
if (removed)
dpyinfo->name_list_element = Fcons (display_name, Qnil);
- terminal->name = xstrdup (SSDATA (display_name));
+ terminal->name = xlispstrdup (display_name);
unblock_input ();
#ifdef NS_IMPL_COCOA
- (void)run
{
-#ifndef NSAppKitVersionNumber10_8
-#define NSAppKitVersionNumber10_8 1187
+#ifndef NSAppKitVersionNumber10_9
+#define NSAppKitVersionNumber10_9 1265
#endif
- if (NSAppKitVersionNumber <= NSAppKitVersionNumber10_8)
- {
- [super run];
- return;
- }
+ if ((int)NSAppKitVersionNumber != NSAppKitVersionNumber10_9)
+ {
+ [super run];
+ return;
+ }
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
untilDate:[NSDate distantFuture]
inMode:NSDefaultRunLoopMode
dequeue:YES];
+
[self sendEvent:event];
[self updateWindows];
} while (shouldKeepRunning);
}
#endif
+ if (represented_filename != nil && represented_frame)
+ {
+ NSString *fstr = represented_filename;
+ NSView *view = FRAME_NS_VIEW (represented_frame);
+#ifdef NS_IMPL_COCOA
+ /* work around a bug observed on 10.3 and later where
+ setTitleWithRepresentedFilename does not clear out previous state
+ if given filename does not exist */
+ if (! [[NSFileManager defaultManager] fileExistsAtPath: fstr])
+ [[view window] setRepresentedFilename: @""];
+#endif
+ [[view window] setRepresentedFilename: fstr];
+ [represented_filename release];
+ represented_filename = nil;
+ represented_frame = NULL;
+ }
+
if (type == NSApplicationDefined)
{
switch ([theEvent data2])
[self antialiasThresholdDidChange:nil];
#ifdef NS_IMPL_COCOA
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(antialiasThresholdDidChange:)
name:NSAntialiasThresholdChangedNotification
object:nil];
-#endif
#endif
ns_send_appdefined (-2);
- (void)antialiasThresholdDidChange:(NSNotification *)notification
{
#ifdef NS_IMPL_COCOA
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
macfont_update_antialias_threshold ();
#endif
-#endif
}
if (!emacs_event)
return;
- if (EQ (font->driver->type, Qns))
- nsfont = ((struct nsfont_info *)font)->nsfont;
-#ifdef NS_IMPL_COCOA
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
- else
- nsfont = (NSFont *) macfont_get_nsctfont (font);
+#ifdef NS_IMPL_GNUSTEP
+ nsfont = ((struct nsfont_info *)font)->nsfont;
#endif
+#ifdef NS_IMPL_COCOA
+ nsfont = (NSFont *) macfont_get_nsctfont (font);
#endif
if ((newFont = [sender convertFont: nsfont]))
int code;
unsigned fnKeysym = 0;
static NSMutableArray *nsEvArray;
-#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
+#ifdef NS_IMPL_GNUSTEP
static BOOL firstTime = YES;
#endif
int left_is_none;
}
-#if !defined (NS_IMPL_COCOA) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6
+#ifdef NS_IMPL_GNUSTEP
/* if we get here we should send the key for input manager processing */
/* Disable warning, there is nothing a user can do about it anyway, and
it does not seem to matter. */
/* Hide dock and menubar if we are on the primary screen. */
if (onFirstScreen)
{
-#if defined (NS_IMPL_COCOA) && \
- MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+#ifdef NS_IMPL_COCOA
NSApplicationPresentationOptions options
= NSApplicationPresentationAutoHideDock
| NSApplicationPresentationAutoHideMenuBar;
if (onFirstScreen)
{
-#if defined (NS_IMPL_COCOA) && \
- MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+#ifdef NS_IMPL_COCOA
[NSApp setPresentationOptions: NSApplicationPresentationDefault];
#else
[NSMenu setMenuBarVisible:YES];
return;
ns_clear_frame_area (emacsframe, x, y, width, height);
+ block_input ();
expose_frame (emacsframe, x, y, width, height);
+ unblock_input ();
/*
drawRect: may be called (at least in OS X 10.5) for invisible
#endif
#endif
- for (i = 0; i < nr_screens; ++i)
+ for (i = 0; i < nr_screens; ++i)
{
NSScreen *s = [screens objectAtIndex: i];
NSRect scrrect = [s frame];
[self setAutoresizingMask: NSViewMinXMargin | NSViewHeightSizable];
#endif
- win = nwin;
+ window = XWINDOW (nwin);
condemned = NO;
pixel_height = NSHeight (r);
if (pixel_height == 0) pixel_height = 1;
min_portion = 20 / pixel_height;
- frame = XFRAME (XWINDOW (win)->frame);
+ frame = XFRAME (window->frame);
if (FRAME_LIVE_P (frame))
{
int i;
if (pixel_height == 0) pixel_height = 1;
min_portion = 20 / pixel_height;
[super setFrame: newRect];
- [self display];
/* unblock_input (); */
}
+- (void)dealloc
+{
+ NSTRACE (EmacsScroller_dealloc);
+ if (window)
+ wset_vertical_scroll_bar (window, Qnil);
+ window = 0;
+ [super dealloc];
+}
+
+
- condemn
{
NSTRACE (condemn);
}
-- judge
+-(bool)judge
{
NSTRACE (judge);
+ bool ret = condemned;
if (condemned)
{
EmacsView *view;
view = (EmacsView *)FRAME_NS_VIEW (frame);
if (view != nil)
view->scrollbarsNeedingUpdate++;
- if (!NILP (win))
- wset_vertical_scroll_bar (XWINDOW (win), Qnil);
- win = Qnil;
+ if (window)
+ wset_vertical_scroll_bar (window, Qnil);
+ window = 0;
[self removeFromSuperview];
[self release];
unblock_input ();
}
- return self;
+ return ret;
}
if (portion >= whole)
{
-#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
+#ifdef NS_IMPL_COCOA
[self setKnobProportion: 1.0];
[self setDoubleValue: 1.0];
#else
portion = max ((float)whole*min_portion/pixel_height, portion);
pos = (float)position / (whole - portion);
por = (CGFloat)portion/whole;
-#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
+#ifdef NS_IMPL_COCOA
[self setKnobProportion: por];
[self setDoubleValue: pos];
#else
#endif
}
- /* Events may come here even if the event loop is not running.
- If we don't enter the event loop, the scroll bar will not update.
- So send SIGIO to ourselves. */
- if (apploopnr == 0) raise (SIGIO);
-
return self;
}
-/* FIXME: unused at moment (see ns_mouse_position) at the moment because
- drag events will go directly to the EmacsScroller. Leaving in for now. */
--(void)getMouseMotionPart: (int *)part window: (Lisp_Object *)window
- x: (Lisp_Object *)x y: ( Lisp_Object *)y
-{
- *part = last_hit_part;
- *window = win;
- XSETINT (*y, pixel_height);
- if ([self floatValue] > 0.999F)
- XSETINT (*x, pixel_height);
- else
- XSETINT (*x, pixel_height * [self floatValue]);
-}
-
-
/* set up emacs_event */
- (void) sendScrollEventAtLoc: (float)loc fromEvent: (NSEvent *)e
{
+ Lisp_Object win;
if (!emacs_event)
return;
emacs_event->part = last_hit_part;
emacs_event->code = 0;
emacs_event->modifiers = EV_MODIFIERS (e) | down_modifier;
+ XSETWINDOW (win, window);
emacs_event->frame_or_window = win;
emacs_event->timestamp = EV_TIMESTAMP (e);
emacs_event->kind = SCROLL_BAR_CLICK_EVENT;
/* Now make the frame display the given font. */
if (FRAME_NS_WINDOW (f) != 0 && ! [view isFullscreen])
- x_set_window_size (f, 0, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f),
- FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), 1);
+ x_set_window_size (f, false, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f),
+ FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), true);
return font_object;
}
DEFSYM (Qcocoa, "cocoa");
DEFSYM (Qgnustep, "gnustep");
- syms_of_nsfont ();
#ifdef NS_IMPL_COCOA
Fprovide (Qcocoa, Qnil);
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
syms_of_macfont ();
-#endif
#else
Fprovide (Qgnustep, Qnil);
+ syms_of_nsfont ();
#endif
}