[[view window] orderOut: NSApp];
[[view window] setFrame: t display: NO];
}
+
+ /* Processing input while Emacs is being minimized can cause a
+ crash, so block it for the duration. */
+ block_input();
[[view window] miniaturize: NSApp];
+ unblock_input();
}
/* Free X resources of frame F. */
[window setFrame: wr display: YES];
- /* This is a trick to compensate for Emacs' managing the scrollbar area
- as a fixed number of standard character columns. Instead of leaving
- blank space for the extra, we chopped it off above. Now for
- left-hand scrollbars, we shift all rendering to the left by the
- difference between the real width and Emacs' imagined one. For
- right-hand bars, don't worry about it since the extra is never used.
- (Obviously doesn't work for vertically split windows tho..) */
- {
- NSPoint origin = FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)
- ? NSMakePoint (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f)
- - NS_SCROLL_BAR_WIDTH (f), 0)
- : NSMakePoint (0, 0);
-
- [view setFrame: NSMakeRect (0, 0, pixelwidth, pixelheight)];
- [view setBoundsOrigin: origin];
- }
-
[view updateFrameSize: NO];
unblock_input ();
}
{
if (cursor_width < 1)
cursor_width = max (FRAME_CURSOR_WIDTH (f), 1);
- w->phys_cursor_width = cursor_width;
+
+ /* The bar cursor should never be wider than the glyph. */
+ if (cursor_width < w->phys_cursor_width)
+ w->phys_cursor_width = cursor_width;
}
/* If we have an HBAR, "cursor_width" MAY specify height. */
else if (cursor_type == HBAR_CURSOR)
r.size.height = h;
r.size.width = w->phys_cursor_width;
- /* TODO: only needed in rare cases with last-resort font in HELLO..
- should we do this more efficiently? */
- ns_clip_to_row (w, glyph_row, ANY_AREA, NO); /* do ns_focus(f, &r, 1); if remove */
+ /* Prevent the cursor from being drawn outside the text area. */
+ ns_clip_to_row (w, glyph_row, TEXT_AREA, NO); /* do ns_focus(f, &r, 1); if remove */
- face = FACE_FROM_ID (f, phys_cursor_glyph->face_id);
+ face = FACE_FROM_ID_OR_NULL (f, phys_cursor_glyph->face_id);
if (face && NS_FACE_BACKGROUND (face)
== ns_index_color (FRAME_CURSOR_COLOR (f), f))
{
NSTRACE ("ns_draw_vertical_window_border");
- face = FACE_FROM_ID (f, VERTICAL_BORDER_FACE_ID);
- if (face)
- [ns_lookup_indexed_color(face->foreground, f) set];
+ face = FACE_FROM_ID_OR_NULL (f, VERTICAL_BORDER_FACE_ID);
ns_focus (f, &r, 1);
+ if (face)
+ [ns_lookup_indexed_color(face->foreground, f) set];
+
NSRectFill(r);
ns_unfocus (f);
}
NSTRACE ("ns_draw_window_divider");
- face = FACE_FROM_ID (f, WINDOW_DIVIDER_FACE_ID);
- if (face)
- [ns_lookup_indexed_color(face->foreground, f) set];
+ face = FACE_FROM_ID_OR_NULL (f, WINDOW_DIVIDER_FACE_ID);
ns_focus (f, &r, 1);
+ if (face)
+ [ns_lookup_indexed_color(face->foreground, f) set];
+
NSRectFill(r);
ns_unfocus (f);
}
if (s->hl == DRAW_MOUSE_FACE)
{
- face = FACE_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id);
+ face = FACE_FROM_ID_OR_NULL (s->f,
+ MOUSE_HL_INFO (s->f)->mouse_face_face_id);
if (!face)
- face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
+ face = FACE_FROM_ID_OR_NULL (s->f, MOUSE_FACE_ID);
}
else
face = s->face;
struct face *face;
if (s->hl == DRAW_MOUSE_FACE)
{
- face = FACE_FROM_ID (s->f,
- MOUSE_HL_INFO (s->f)->mouse_face_face_id);
+ face
+ = FACE_FROM_ID_OR_NULL (s->f,
+ MOUSE_HL_INFO (s->f)->mouse_face_face_id);
if (!face)
face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
}
with its background color), we must clear just the image area. */
if (s->hl == DRAW_MOUSE_FACE)
{
- face = FACE_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id);
+ face = FACE_FROM_ID_OR_NULL (s->f,
+ MOUSE_HL_INFO (s->f)->mouse_face_face_id);
if (!face)
face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
}
if (s->hl == DRAW_MOUSE_FACE)
{
- face = FACE_FROM_ID (s->f, MOUSE_HL_INFO (s->f)->mouse_face_face_id);
+ face = FACE_FROM_ID_OR_NULL (s->f,
+ MOUSE_HL_INFO (s->f)->mouse_face_face_id);
if (!face)
face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
}
}
+static void
+ns_draw_glyph_string_foreground (struct glyph_string *s)
+{
+ int x, flags;
+ struct font *font = s->font;
+
+ /* If first glyph of S has a left box line, start drawing the text
+ of S to the right of that box line. */
+ if (s->face && s->face->box != FACE_NO_BOX
+ && s->first_glyph->left_box_line_p)
+ x = s->x + eabs (s->face->box_line_width);
+ else
+ x = s->x;
+
+ flags = s->hl == DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR :
+ (s->hl == DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE :
+ (s->for_overlaps ? NS_DUMPGLYPH_FOREGROUND :
+ NS_DUMPGLYPH_NORMAL));
+
+ font->driver->draw
+ (s, s->cmp_from, s->nchars, x, s->ybase,
+ (flags == NS_DUMPGLYPH_NORMAL && !s->background_filled_p)
+ || flags == NS_DUMPGLYPH_MOUSEFACE);
+}
+
+
static void
ns_draw_composite_glyph_string_foreground (struct glyph_string *s)
{
{
/* TODO (optimize): focus for box and contents draw */
NSRect r[2];
- int n, flags;
+ int n;
char box_drawn_p = 0;
struct font *font = s->face->font;
if (! font) font = FRAME_FONT (s->f);
ns_maybe_dumpglyphs_background
(s, s->first_glyph->type == COMPOSITE_GLYPH);
- flags = s->hl == DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR :
- (s->hl == DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE :
- (s->for_overlaps ? NS_DUMPGLYPH_FOREGROUND :
- NS_DUMPGLYPH_NORMAL));
-
if (s->hl == DRAW_CURSOR && s->w->phys_cursor_type == FILLED_BOX_CURSOR)
{
unsigned long tmp = NS_FACE_BACKGROUND (s->face);
if (isComposite)
ns_draw_composite_glyph_string_foreground (s);
else
- font->driver->draw
- (s, s->cmp_from, s->nchars, s->x, s->ybase,
- (flags == NS_DUMPGLYPH_NORMAL && !s->background_filled_p)
- || flags == NS_DUMPGLYPH_MOUSEFACE);
+ ns_draw_glyph_string_foreground (s);
}
{
NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_read_socket");
+ if (apploopnr > 0)
+ return -1; /* Already within event loop. */
+
#ifdef HAVE_NATIVE_FS
check_native_fs ();
#endif
NSTRACE_WHEN (NSTRACE_GROUP_EVENTS, "ns_select");
+ if (apploopnr > 0)
+ return -1; /* Already within event loop. */
+
#ifdef HAVE_NATIVE_FS
check_native_fs ();
#endif
window_box (window, ANY_AREA, 0, &window_y, 0, &window_height);
top = window_y;
height = window_height;
- width = WINDOW_CONFIG_SCROLL_BAR_COLS (window) * FRAME_COLUMN_WIDTH (f);
+ width = NS_SCROLL_BAR_WIDTH (f);
left = WINDOW_SCROLL_BAR_AREA_X (window);
r = NSMakeRect (left, top, width, height);
NSTRACE ("ns_set_horizontal_scroll_bar");
/* Get dimensions. */
- window_box (window, ANY_AREA, 0, &window_x, &window_width, 0);
+ window_box (window, ANY_AREA, &window_x, 0, &window_width, 0);
left = window_x;
width = window_width;
- height = WINDOW_CONFIG_SCROLL_BAR_LINES (window) * FRAME_LINE_HEIGHT (f);
+ height = NS_SCROLL_BAR_HEIGHT (f);
top = WINDOW_SCROLL_BAR_AREA_Y (window);
r = NSMakeRect (left, top, width, height);
/* the parent view is flipped, so we need to flip y value */
v = [view frame];
- /* ??????? PXW/scrollbars !!!!!!!!!!!!!!!!!!!! */
r.origin.y = (v.size.height - r.size.height - r.origin.y);
XSETWINDOW (win, window);
block_input ();
- if (WINDOW_TOTAL_COLS (window) < 5)
- {
- if (!NILP (window->horizontal_scroll_bar))
- {
- bar = XNS_SCROLL_BAR (window->horizontal_scroll_bar);
- [bar removeFromSuperview];
- wset_horizontal_scroll_bar (window, Qnil);
- }
- ns_clear_frame_area (f, left, top, width, height);
- unblock_input ();
- return;
- }
-
if (NILP (window->horizontal_scroll_bar))
{
if (width > 0 && height > 0)
NSRect oldRect;
bar = XNS_SCROLL_BAR (window->horizontal_scroll_bar);
oldRect = [bar frame];
- r.size.width = oldRect.size.width;
if (FRAME_LIVE_P (f) && !NSEqualRects (oldRect, r))
{
- if (oldRect.origin.x != r.origin.x)
- ns_clear_frame_area (f, left, top, width, height);
+ if (oldRect.origin.y != r.origin.y)
+ ns_clear_frame_area (f, left, top, width, height);
[bar setFrame: r];
update_p = YES;
}
}
+ /* If there are both horizontal and vertical scroll-bars they leave
+ a square that belongs to neither. We need to clear it otherwise
+ it fills with junk. */
+ if (!NILP (window->vertical_scroll_bar))
+ ns_clear_frame_area (f, WINDOW_SCROLL_BAR_AREA_X (window), top,
+ NS_SCROLL_BAR_HEIGHT (f), height);
+
if (update_p)
[bar setPosition: position portion: portion whole: whole];
unblock_input ();
{
id bar;
NSTRACE ("ns_redeem_scroll_bar");
- if (!NILP (window->vertical_scroll_bar))
+ if (!NILP (window->vertical_scroll_bar)
+ && WINDOW_HAS_VERTICAL_SCROLL_BAR (window))
{
bar = XNS_SCROLL_BAR (window->vertical_scroll_bar);
[bar reprieve];
}
- if (!NILP (window->horizontal_scroll_bar))
+ if (!NILP (window->horizontal_scroll_bar)
+ && WINDOW_HAS_HORIZONTAL_SCROLL_BAR (window))
{
bar = XNS_SCROLL_BAR (window->horizontal_scroll_bar);
[bar reprieve];
+FRAME_LINE_HEIGHT (emacsframe));
pt = [self convertPoint: pt toView: nil];
+#if !defined (NS_IMPL_COCOA) || \
+ MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
pt = [[self window] convertBaseToScreen: pt];
rect.origin = pt;
+#else
+ rect.origin = pt;
+ rect = [[self window] convertRectToScreen: rect];
+#endif
return rect;
}
return r;
}
-
- initFrame: (NSRect )r window: (Lisp_Object)nwin
{
NSTRACE ("[EmacsScroller initFrame: window:]");
- r.size.width = [EmacsScroller scrollerWidth];
+ if (r.size.width > r.size.height)
+ horizontal = YES;
+ else
+ horizontal = NO;
+
[super initWithFrame: r/*NSMakeRect (0, 0, 0, 0)*/];
[self setContinuous: YES];
[self setEnabled: YES];
window = XWINDOW (nwin);
condemned = NO;
- pixel_height = NSHeight (r);
- if (pixel_height == 0) pixel_height = 1;
- min_portion = 20 / pixel_height;
+ if (horizontal)
+ pixel_length = NSWidth (r);
+ else
+ pixel_length = NSHeight (r);
+ if (pixel_length == 0) pixel_length = 1;
+ min_portion = 20 / pixel_length;
frame = XFRAME (window->frame);
if (FRAME_LIVE_P (frame))
NSTRACE ("[EmacsScroller setFrame:]");
/* block_input (); */
- pixel_height = NSHeight (newRect);
- if (pixel_height == 0) pixel_height = 1;
- min_portion = 20 / pixel_height;
+ if (horizontal)
+ pixel_length = NSWidth (newRect);
+ else
+ pixel_length = NSHeight (newRect);
+ if (pixel_length == 0) pixel_length = 1;
+ min_portion = 20 / pixel_length;
[super setFrame: newRect];
/* unblock_input (); */
}
{
NSTRACE ("[EmacsScroller dealloc]");
if (window)
- wset_vertical_scroll_bar (window, Qnil);
+ {
+ if (horizontal)
+ wset_horizontal_scroll_bar (window, Qnil);
+ else
+ wset_vertical_scroll_bar (window, Qnil);
+ }
window = 0;
[super dealloc];
}
if (view != nil)
view->scrollbarsNeedingUpdate++;
if (window)
- wset_vertical_scroll_bar (window, Qnil);
+ {
+ if (horizontal)
+ wset_horizontal_scroll_bar (window, Qnil);
+ else
+ wset_vertical_scroll_bar (window, Qnil);
+ }
window = 0;
[self removeFromSuperview];
[self release];
{
float pos;
CGFloat por;
- portion = max ((float)whole*min_portion/pixel_height, portion);
+ portion = max ((float)whole*min_portion/pixel_length, portion);
pos = (float)position / (whole - portion);
por = (CGFloat)portion/whole;
#ifdef NS_IMPL_COCOA
XSETWINDOW (win, window);
emacs_event->frame_or_window = win;
emacs_event->timestamp = EV_TIMESTAMP (e);
- emacs_event->kind = SCROLL_BAR_CLICK_EVENT;
emacs_event->arg = Qnil;
- XSETINT (emacs_event->x, loc * pixel_height);
- XSETINT (emacs_event->y, pixel_height-20);
+
+ if (horizontal)
+ {
+ emacs_event->kind = HORIZONTAL_SCROLL_BAR_CLICK_EVENT;
+ XSETINT (emacs_event->x, em_whole * loc / pixel_length);
+ XSETINT (emacs_event->y, em_whole);
+ }
+ else
+ {
+ emacs_event->kind = SCROLL_BAR_CLICK_EVENT;
+ XSETINT (emacs_event->x, loc);
+ XSETINT (emacs_event->y, pixel_length-20);
+ }
if (q_event_ptr)
{
switch (part)
{
case NSScrollerDecrementPage:
- last_hit_part = scroll_bar_above_handle; inc = -1.0; break;
+ last_hit_part = horizontal ? scroll_bar_before_handle : scroll_bar_above_handle; break;
case NSScrollerIncrementPage:
- last_hit_part = scroll_bar_below_handle; inc = 1.0; break;
+ last_hit_part = horizontal ? scroll_bar_after_handle : scroll_bar_below_handle; break;
case NSScrollerDecrementLine:
- last_hit_part = scroll_bar_up_arrow; inc = -0.1; break;
+ last_hit_part = horizontal ? scroll_bar_left_arrow : scroll_bar_up_arrow; break;
case NSScrollerIncrementLine:
- last_hit_part = scroll_bar_down_arrow; inc = 0.1; break;
+ last_hit_part = horizontal ? scroll_bar_right_arrow : scroll_bar_down_arrow; break;
case NSScrollerKnob:
- last_hit_part = scroll_bar_handle; break;
+ last_hit_part = horizontal ? scroll_bar_horizontal_handle : scroll_bar_handle; break;
case NSScrollerKnobSlot: /* GNUstep-only */
last_hit_part = scroll_bar_move_ratio; break;
default: /* NSScrollerNoPart? */
return;
}
- if (inc != 0.0)
- {
- pos = 0; /* ignored */
-
- /* set a timer to repeat, as we can't let superclass do this modally */
- scroll_repeat_entry
- = [[NSTimer scheduledTimerWithTimeInterval: SCROLL_BAR_FIRST_DELAY
- target: self
- selector: @selector (repeatScroll:)
- userInfo: 0
- repeats: YES]
- retain];
- }
- else
+ if (part == NSScrollerKnob || part == NSScrollerKnobSlot)
{
/* handle, or on GNUstep possibly slot */
NSEvent *fake_event;
+ int length;
/* compute float loc in slot and mouse offset on knob */
sr = [self convertRect: [self rectForPart: NSScrollerKnobSlot]
toView: nil];
- loc = NSHeight (sr) - ([e locationInWindow].y - NSMinY (sr));
+ if (horizontal)
+ {
+ length = NSWidth (sr);
+ loc = ([e locationInWindow].x - NSMinX (sr));
+ }
+ else
+ {
+ length = NSHeight (sr);
+ loc = length - ([e locationInWindow].y - NSMinY (sr));
+ }
+
if (loc <= 0.0)
{
loc = 0.0;
edge = -1;
}
- else if (loc >= NSHeight (sr))
+ else if (loc >= length)
{
- loc = NSHeight (sr);
+ loc = length;
edge = 1;
}
{
kr = [self convertRect: [self rectForPart: NSScrollerKnob]
toView: nil];
- kloc = NSHeight (kr) - ([e locationInWindow].y - NSMinY (kr));
+ if (horizontal)
+ kloc = ([e locationInWindow].x - NSMinX (kr));
+ else
+ kloc = NSHeight (kr) - ([e locationInWindow].y - NSMinY (kr));
}
last_mouse_offset = kloc;
- /* if knob, tell emacs a location offset by knob pos
- (to indicate top of handle) */
- if (part == NSScrollerKnob)
- pos = (loc - last_mouse_offset) / NSHeight (sr);
- else
- /* else this is a slot click on GNUstep: go straight there */
- pos = loc / NSHeight (sr);
+ if (part != NSScrollerKnob)
+ /* this is a slot click on GNUstep: go straight there */
+ pos = loc;
/* send a fake mouse-up to super to preempt modal -trackKnob: mode */
fake_event = [NSEvent mouseEventWithType: NSLeftMouseUp
pressure: [e pressure]];
[super mouseUp: fake_event];
}
+ else
+ {
+ pos = 0; /* ignored */
+
+ /* set a timer to repeat, as we can't let superclass do this modally */
+ scroll_repeat_entry
+ = [[NSTimer scheduledTimerWithTimeInterval: SCROLL_BAR_FIRST_DELAY
+ target: self
+ selector: @selector (repeatScroll:)
+ userInfo: 0
+ repeats: YES]
+ retain];
+ }
if (part != NSScrollerKnob)
[self sendScrollEventAtLoc: pos fromEvent: e];
{
NSRect sr;
double loc, pos;
+ int length;
NSTRACE ("[EmacsScroller mouseDragged:]");
sr = [self convertRect: [self rectForPart: NSScrollerKnobSlot]
toView: nil];
- loc = NSHeight (sr) - ([e locationInWindow].y - NSMinY (sr));
+
+ if (horizontal)
+ {
+ length = NSWidth (sr);
+ loc = ([e locationInWindow].x - NSMinX (sr));
+ }
+ else
+ {
+ length = NSHeight (sr);
+ loc = length - ([e locationInWindow].y - NSMinY (sr));
+ }
if (loc <= 0.0)
{
loc = 0.0;
}
- else if (loc >= NSHeight (sr) + last_mouse_offset)
+ else if (loc >= length + last_mouse_offset)
{
- loc = NSHeight (sr) + last_mouse_offset;
+ loc = length + last_mouse_offset;
}
- pos = (loc - last_mouse_offset) / NSHeight (sr);
+ pos = (loc - last_mouse_offset);
[self sendScrollEventAtLoc: pos fromEvent: e];
}