/* NeXT/Open/GNUstep / MacOSX communication module. -*- coding: utf-8 -*-
-Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2015 Free Software
+Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2016 Free Software
Foundation, Inc.
This file is part of GNU Emacs.
}
+void
+ns_init_locale (void)
+/* OS X doesn't set any environment variables for the locale when run
+ from the GUI. Get the locale from the OS and set LANG. */
+{
+ NSLocale *locale = [NSLocale currentLocale];
+
+ NSTRACE ("ns_init_locale");
+
+ @try
+ {
+ /* Set LANG to locale, but not if LANG is already set. */
+ setenv("LANG", [[locale localeIdentifier] UTF8String], 0);
+ }
+ @catch (NSException *e)
+ {
+ NSLog (@"Locale detection failed: %@: %@", [e name], [e reason]);
+ }
+}
+
+
void
ns_release_object (void *obj)
/* --------------------------------------------------------------------------
static CGFloat
ns_menu_bar_height (NSScreen *screen)
-/* The height of the menu bar, if visible. */
-{
- // NSTRACE ("ns_menu_bar_height");
+/* The height of the menu bar, if visible.
+ Note: Don't use this when fullscreen is enabled -- the screen
+ sometimes includes, sometimes excludes the menu bar area. */
+{
CGFloat res;
if (ns_menu_bar_should_be_hidden())
}
- // NSTRACE_MSG (NSTRACE_FMT_RETURN "%.0f", res);
+ NSTRACE ("ns_menu_bar_height " NSTRACE_FMT_RETURN " %.0f", res);
return res;
}
// Result: Menu bar visible, frame placed immediately below the menu.
//
-static NSRect constrain_frame_rect(NSRect frameRect)
+static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
{
NSTRACE ("constrain_frame_rect(" NSTRACE_FMT_RECT ")",
NSTRACE_ARG_RECT (frameRect));
{
multiscreenRect = NSUnionRect (multiscreenRect, scrRect);
- menu_bar_height = max(menu_bar_height, ns_menu_bar_height (s));
+ if (!isFullscreen)
+ {
+ CGFloat screen_menu_bar_height = ns_menu_bar_height (s);
+ menu_bar_height = max(menu_bar_height, screen_menu_bar_height);
+ }
}
}
if (![view isFullscreen])
{
[[view window]
- setFrame:constrain_frame_rect([[view window] frame])
+ setFrame:constrain_frame_rect([[view window] frame], false)
display:NO];
}
}
{
// Number of currently active bell:s.
unsigned int nestCount;
+ bool isAttached;
}
- (void)show:(NSView *)view;
- (void)hide;
+- (void)remove;
@end
@implementation EmacsBell
- (id)init;
{
+ NSTRACE ("[EmacsBell init]");
if ((self = [super init]))
{
nestCount = 0;
+ isAttached = false;
+#ifdef NS_IMPL_GNUSTEP
+ // GNUstep doesn't provide named images. This was reported in
+ // 2011, see https://savannah.gnu.org/bugs/?33396
+ //
+ // As a drop in replacement, a semitransparent gray square is used.
+ self.image = [[NSImage alloc] initWithSize:NSMakeSize(32, 32)];
+ [self.image lockFocus];
+ [[NSColor colorForEmacsRed:0.5 green:0.5 blue:0.5 alpha:0.5] set];
+ NSRectFill(NSMakeRect(0, 0, 32, 32));
+ [self.image unlockFocus];
+#else
self.image = [NSImage imageNamed:NSImageNameCaution];
+#endif
}
return self;
}
[self setFrameOrigin:pos];
[self setFrameSize:self.image.size];
+ isAttached = true;
[[[view window] contentView] addSubview:self
positioned:NSWindowAbove
relativeTo:nil];
// Note: Trace output from this method isn't shown, reason unknown.
// NSTRACE ("[EmacsBell hide]");
- --nestCount;
+ if (nestCount > 0)
+ --nestCount;
// Remove the image once the last bell became inactive.
if (nestCount == 0)
+ {
+ [self remove];
+ }
+}
+
+
+-(void)remove
+{
+ if (isAttached)
{
[self removeFromSuperview];
+ isAttached = false;
}
}
@end
+
+static EmacsBell * bell_view = nil;
+
static void
ns_ring_bell (struct frame *f)
/* --------------------------------------------------------------------------
struct frame *frame = SELECTED_FRAME ();
NSView *view;
- static EmacsBell * bell_view = nil;
if (bell_view == nil)
{
bell_view = [[EmacsBell alloc] init];
}
+static void hide_bell ()
+/* --------------------------------------------------------------------------
+ Ensure the bell is hidden.
+ -------------------------------------------------------------------------- */
+{
+ if (bell_view != nil)
+ {
+ [bell_view remove];
+ }
+}
+
+
/* ==========================================================================
Frame / window manager related functions
NSRect wr = [window frame];
int tb = FRAME_EXTERNAL_TOOL_BAR (f);
int pixelwidth, pixelheight;
- int rows, cols;
int orig_height = wr.size.height;
NSTRACE ("x_set_window_size");
{
pixelwidth = FRAME_TEXT_TO_PIXEL_WIDTH (f, width);
pixelheight = FRAME_TEXT_TO_PIXEL_HEIGHT (f, height);
- cols = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pixelwidth);
- rows = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, pixelheight);
}
else
{
pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
pixelheight = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
- cols = width;
- rows = height;
}
/* If we have a toolbar, take its height into account. */
{
if (FRAME_NS_VIEW (f))
{
+ hide_bell(); // Ensure the bell image isn't scrolled.
+
ns_focus (f, &dest, 1);
[FRAME_NS_VIEW (f) scrollRect: src
by: NSMakeSize (dest.origin.x - src.origin.x,
[img setXBMColor: bm_color];
}
+#ifdef NS_IMPL_COCOA
// Note: For periodic images, the full image height is "h + hd".
// By using the height h, a suitable part of the image is used.
NSRect fromRect = NSMakeRect(0, 0, p->wd, p->h);
NSTRACE_RECT ("fromRect", fromRect);
-#ifdef NS_IMPL_COCOA
[img drawInRect: r
fromRect: fromRect
operation: NSCompositeSourceOver
if (oldr != rows || oldc != cols || neww != oldw || newh != oldh)
{
NSView *view = FRAME_NS_VIEW (emacsframe);
- NSWindow *win = [view window];
change_frame_size (emacsframe,
FRAME_PIXEL_TO_TEXT_WIDTH (emacsframe, neww),
NSString *name;
NSTRACE ("[EmacsView initFrameFromEmacs:]");
- NSTRACE_MSG ("cols:%d lines:%d\n", f->text_cols, f->text_lines);
+ NSTRACE_MSG ("cols:%d lines:%d", f->text_cols, f->text_lines);
windowClosing = NO;
processingCompose = NO;
- (BOOL)isFullscreen
{
- NSTRACE ("[EmacsView isFullscreen]");
+ BOOL res;
- if (! fs_is_native) return nonfs_window != nil;
+ if (! fs_is_native)
+ {
+ res = (nonfs_window != nil);
+ }
+ else
+ {
#ifdef HAVE_NATIVE_FS
- return ([[self window] styleMask] & NSFullScreenWindowMask) != 0;
+ res = (([[self window] styleMask] & NSFullScreenWindowMask) != 0);
#else
- return NO;
+ res = NO;
#endif
+ }
+
+ NSTRACE ("[EmacsView isFullscreen] " NSTRACE_FMT_RETURN " %d",
+ (int) res);
+
+ return res;
}
#ifdef HAVE_NATIVE_FS
#endif
#endif
- return constrain_frame_rect(frameRect);
+ return constrain_frame_rect(frameRect,
+ [(EmacsView *)[self delegate] isFullscreen]);
}
- (void)zoom:(id)sender
{
- struct frame * f = SELECTED_FRAME ();
-
NSTRACE ("[EmacsWindow zoom:]");
ns_update_auto_hide_menu_bar();