1 /* NeXT/Open/GNUstep / MacOSX communication module.
3 Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2012
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 Originally by Carl Edman
23 Updated by Christian Limpach (chris@nice.ch)
24 OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com)
25 MacOSX/Aqua port by Christophe de Dinechin (descubes@earthlink.net)
26 GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
29 /* This should be the first include, as it may set up #defines affecting
30 interpretation of even the system includes. */
34 #include
<sys
/types.h
>
40 #include
<c
-strcase.h
>
48 #include "blockinput.h"
49 #include "sysselect.h"
52 #include "character.h"
54 #include "composite.h"
57 #include "termhooks.h"
68 int term_trace_num
= 0;
69 #define NSTRACE
(x
) fprintf (stderr
, "
%s:%d: [%d] " #x "\n", \
70 __FILE__
, __LINE__
, ++term_trace_num
)
75 extern NSString
*NSMenuDidBeginTrackingNotification
;
77 /* ==========================================================================
81 ========================================================================== */
83 /* Convert a symbol indexed with an NSxxx value to a value as defined
84 in keyboard.c (lispy_function_key). I hope this is a correct way
86 static unsigned convert_ns_to_X_keysym
[] =
88 NSHomeFunctionKey
, 0x50,
89 NSLeftArrowFunctionKey
, 0x51,
90 NSUpArrowFunctionKey
, 0x52,
91 NSRightArrowFunctionKey
, 0x53,
92 NSDownArrowFunctionKey
, 0x54,
93 NSPageUpFunctionKey
, 0x55,
94 NSPageDownFunctionKey
, 0x56,
95 NSEndFunctionKey
, 0x57,
96 NSBeginFunctionKey
, 0x58,
97 NSSelectFunctionKey
, 0x60,
98 NSPrintFunctionKey
, 0x61,
99 NSExecuteFunctionKey
, 0x62,
100 NSInsertFunctionKey
, 0x63,
101 NSUndoFunctionKey
, 0x65,
102 NSRedoFunctionKey
, 0x66,
103 NSMenuFunctionKey
, 0x67,
104 NSFindFunctionKey
, 0x68,
105 NSHelpFunctionKey
, 0x6A,
106 NSBreakFunctionKey
, 0x6B,
108 NSF1FunctionKey
, 0xBE,
109 NSF2FunctionKey
, 0xBF,
110 NSF3FunctionKey
, 0xC0,
111 NSF4FunctionKey
, 0xC1,
112 NSF5FunctionKey
, 0xC2,
113 NSF6FunctionKey
, 0xC3,
114 NSF7FunctionKey
, 0xC4,
115 NSF8FunctionKey
, 0xC5,
116 NSF9FunctionKey
, 0xC6,
117 NSF10FunctionKey
, 0xC7,
118 NSF11FunctionKey
, 0xC8,
119 NSF12FunctionKey
, 0xC9,
120 NSF13FunctionKey
, 0xCA,
121 NSF14FunctionKey
, 0xCB,
122 NSF15FunctionKey
, 0xCC,
123 NSF16FunctionKey
, 0xCD,
124 NSF17FunctionKey
, 0xCE,
125 NSF18FunctionKey
, 0xCF,
126 NSF19FunctionKey
, 0xD0,
127 NSF20FunctionKey
, 0xD1,
128 NSF21FunctionKey
, 0xD2,
129 NSF22FunctionKey
, 0xD3,
130 NSF23FunctionKey
, 0xD4,
131 NSF24FunctionKey
, 0xD5,
133 NSBackspaceCharacter
, 0x08, /* 8: Not on some KBs. */
134 NSDeleteCharacter
, 0xFF, /* 127: Big 'delete' key upper right. */
135 NSDeleteFunctionKey
, 0x9F, /* 63272: Del forw key off main array. */
137 NSTabCharacter
, 0x09,
138 0x19, 0x09, /* left tab->regular since pass shift */
139 NSCarriageReturnCharacter
, 0x0D,
140 NSNewlineCharacter
, 0x0D,
141 NSEnterCharacter
, 0x8D,
143 0x1B, 0x1B /* escape */
146 static Lisp_Object Qmodifier_value
;
147 Lisp_Object Qalt
, Qcontrol
, Qhyper
, Qmeta
, Qsuper
;
148 extern Lisp_Object Qcursor_color
, Qcursor_type
, Qns
, Qleft
;
150 static Lisp_Object QUTF8_STRING
;
152 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
153 the maximum font size to NOT antialias. On GNUstep there is currently
154 no way to control this behavior. */
155 float ns_antialias_threshold
;
157 /* Used to pick up AppleHighlightColor on OS X */
158 NSString
*ns_selection_color
;
160 NSArray
*ns_send_types
=0, *ns_return_types
=0, *ns_drag_types
=0;
161 NSString
*ns_app_name
= @"Emacs"
; /* default changed later */
163 /* Display variables */
164 struct ns_display_info
*x_display_list
; /* Chain of existing displays */
165 Lisp_Object ns_display_name_list
;
166 long context_menu_value
= 0;
169 NSPoint last_mouse_motion_position
;
170 static NSRect last_mouse_glyph
;
171 static Time last_mouse_movement_time
= 0;
172 static Lisp_Object last_mouse_motion_frame
;
173 static EmacsScroller
*last_mouse_scroll_bar
= nil
;
174 static
struct frame
*ns_updating_frame
;
175 static NSView
*focus_view
= NULL;
176 static int ns_window_num
= 0;
177 #ifdef NS_IMPL_GNUSTEP
180 static BOOL gsaved
= NO
;
181 BOOL ns_in_resize
= NO
;
182 static BOOL ns_fake_keydown
= NO
;
183 int ns_tmp_flags
; /* FIXME */
184 struct nsfont_info
*ns_tmp_font
; /* FIXME */
185 static BOOL ns_menu_bar_is_hidden
= NO
;
186 /*static int debug_lock = 0; */
189 static BOOL send_appdefined
= YES
;
190 static NSEvent
*last_appdefined_event
= 0;
191 static NSTimer
*timed_entry
= 0;
192 static NSTimer
*scroll_repeat_entry
= nil
;
193 static fd_set select_readfds
, select_writefds
;
194 enum
{ SELECT_HAVE_READ
= 1, SELECT_HAVE_WRITE
= 2, SELECT_HAVE_TMO
= 4 };
195 static int select_nfds
= 0, select_valid
= 0;
196 static EMACS_TIME select_timeout
= { 0, 0 };
197 static int selfds
[2] = { -1, -1 };
198 static pthread_mutex_t select_mutex
;
199 static int apploopnr
= 0;
200 static NSAutoreleasePool
*outerpool
;
201 static
struct input_event
*emacs_event
= NULL;
202 static
struct input_event
*q_event_ptr
= NULL;
203 static int n_emacs_events_pending
= 0;
204 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
205 *ns_pending_service_args
;
206 static BOOL ns_do_open_file
= NO
;
208 /* Convert modifiers in a NeXTstep event to emacs style modifiers. */
209 #define NS_FUNCTION_KEY_MASK
0x800000
210 #define NSLeftControlKeyMask
(0x000001 | NSControlKeyMask
)
211 #define NSRightControlKeyMask
(0x002000 | NSControlKeyMask
)
212 #define NSLeftCommandKeyMask
(0x000008 | NSCommandKeyMask
)
213 #define NSRightCommandKeyMask
(0x000010 | NSCommandKeyMask
)
214 #define NSLeftAlternateKeyMask
(0x000020 | NSAlternateKeyMask
)
215 #define NSRightAlternateKeyMask
(0x000040 | NSAlternateKeyMask
)
216 #define EV_MODIFIERS
(e
) \
217 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
218 hyper_modifier
: 0) \
219 |
(!EQ
(ns_right_alternate_modifier
, Qleft
) && \
220 (([e modifierFlags
] & NSRightAlternateKeyMask
) \
221 == NSRightAlternateKeyMask
) ? \
222 parse_solitary_modifier
(ns_right_alternate_modifier
) : 0) \
223 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
224 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
225 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
226 shift_modifier
: 0) \
227 |
(!EQ
(ns_right_control_modifier
, Qleft
) && \
228 (([e modifierFlags
] & NSRightControlKeyMask
) \
229 == NSRightControlKeyMask
) ? \
230 parse_solitary_modifier
(ns_right_control_modifier
) : 0) \
231 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
232 parse_solitary_modifier
(ns_control_modifier
) : 0) \
233 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
234 parse_solitary_modifier
(ns_function_modifier
) : 0) \
235 |
(!EQ
(ns_right_command_modifier
, Qleft
) && \
236 (([e modifierFlags
] & NSRightCommandKeyMask
) \
237 == NSRightCommandKeyMask
) ? \
238 parse_solitary_modifier
(ns_right_command_modifier
) : 0) \
239 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
240 parse_solitary_modifier
(ns_command_modifier
):0))
242 #define EV_UDMODIFIERS
(e
) \
243 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
244 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
245 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
246 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
247 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
248 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
249 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
250 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
251 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
253 #define EV_BUTTON
(e
) \
254 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
255 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
256 [e buttonNumber
] - 1)
258 /* Convert the time field to a timestamp in milliseconds. */
259 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
261 /* This is a piece of code which is common to all the event handling
262 methods. Maybe it should even be a function. */
263 #define EV_TRAILER
(e
) \
265 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
266 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
269 n_emacs_events_pending
++; \
270 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
273 kbd_buffer_store_event
(emacs_event
); \
274 EVENT_INIT
(*emacs_event
); \
275 ns_send_appdefined
(-1); \
278 void x_set_cursor_type
(struct frame
*, Lisp_Object
, Lisp_Object
);
280 /* TODO: get rid of need for these forward declarations */
281 static void ns_condemn_scroll_bars
(struct frame
*f
);
282 static void ns_judge_scroll_bars
(struct frame
*f
);
283 void x_set_frame_alpha
(struct frame
*f
);
286 /* ==========================================================================
290 ========================================================================== */
294 append2
(Lisp_Object list
, Lisp_Object item
)
295 /* --------------------------------------------------------------------------
296 Utility to append to a list
297 -------------------------------------------------------------------------- */
299 Lisp_Object array
[2];
301 array
[1] = Fcons
(item
, Qnil
);
302 return Fnconc
(2, &array
[0]);
307 ns_etc_directory
(void
)
308 /* If running as a self-contained app bundle, return as a string the
309 filename of the etc directory, if present; else nil. */
311 NSBundle
*bundle
= [NSBundle mainBundle
];
312 NSString
*resourceDir
= [bundle resourcePath
];
313 NSString
*resourcePath
;
314 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
317 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
318 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
320 if (isDir
) return [resourcePath UTF8String
];
328 /* If running as a self-contained app bundle, return as a path string
329 the filenames of the libexec and bin directories, ie libexec:bin.
330 Otherwise, return nil.
331 Normally, Emacs does not add its own bin/ directory to the PATH.
332 However, a self-contained NS build has a different layout, with
333 bin/ and libexec/ subdirectories in the directory that contains
335 We put libexec first, because init_callproc_1 uses the first
336 element to initialize exec-directory. An alternative would be
337 for init_callproc to check for invocation-directory/libexec.
340 NSBundle
*bundle
= [NSBundle mainBundle
];
341 NSString
*resourceDir
= [bundle resourcePath
];
342 NSString
*binDir
= [bundle bundlePath
];
343 NSString
*resourcePath
, *resourcePaths
;
345 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
346 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
348 NSEnumerator
*pathEnum
;
351 range
= [resourceDir rangeOfString
: @"Contents"
];
352 if (range.location
!= NSNotFound
)
354 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
356 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
360 paths
= [binDir stringsByAppendingPaths
:
361 [NSArray arrayWithObjects
: @"libexec"
, @"bin"
, nil
]];
362 pathEnum
= [paths objectEnumerator
];
365 while ((resourcePath
= [pathEnum nextObject
]))
367 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
370 if ([resourcePaths
length] > 0)
372 = [resourcePaths stringByAppendingString
: pathSeparator
];
374 = [resourcePaths stringByAppendingString
: resourcePath
];
377 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
385 /* If running as a self-contained app bundle, return as a path string
386 the filenames of the site-lisp, lisp and leim directories.
387 Ie, site-lisp:lisp:leim. Otherwise, return nil. */
389 NSBundle
*bundle
= [NSBundle mainBundle
];
390 NSString
*resourceDir
= [bundle resourcePath
];
391 NSString
*resourcePath
, *resourcePaths
;
392 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
393 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
395 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
396 [NSArray arrayWithObjects
:
397 @"site
-lisp"
, @"lisp"
, @"leim"
, nil
]];
398 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
401 /* Hack to skip site-lisp. */
402 if (no_site_lisp
) resourcePath
= [pathEnum nextObject
];
404 while ((resourcePath
= [pathEnum nextObject
]))
406 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
409 if ([resourcePaths
length] > 0)
411 = [resourcePaths stringByAppendingString
: pathSeparator
];
413 = [resourcePaths stringByAppendingString
: resourcePath
];
416 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
422 ns_timeout
(int usecs
)
423 /* --------------------------------------------------------------------------
424 Blocking timer utility used by ns_ring_bell
425 -------------------------------------------------------------------------- */
427 EMACS_TIME wakeup
= add_emacs_time
(current_emacs_time
(),
428 make_emacs_time
(0, usecs
* 1000));
430 /* Keep waiting until past the time wakeup. */
433 EMACS_TIME timeout
, now
= current_emacs_time
();
434 if (EMACS_TIME_LE
(wakeup
, now
))
436 timeout
= sub_emacs_time
(wakeup
, now
);
438 /* Try to wait that long--but we might wake up sooner. */
439 pselect
(0, NULL, NULL, NULL, &timeout
, NULL);
445 ns_release_object
(void
*obj
)
446 /* --------------------------------------------------------------------------
447 Release an object (callable from C)
448 -------------------------------------------------------------------------- */
455 ns_retain_object
(void
*obj
)
456 /* --------------------------------------------------------------------------
457 Retain an object (callable from C)
458 -------------------------------------------------------------------------- */
465 ns_alloc_autorelease_pool
(void
)
466 /* --------------------------------------------------------------------------
467 Allocate a pool for temporary objects (callable from C)
468 -------------------------------------------------------------------------- */
470 return [[NSAutoreleasePool alloc
] init
];
475 ns_release_autorelease_pool
(void
*pool
)
476 /* --------------------------------------------------------------------------
477 Free a pool and temporary objects it refers to (callable from C)
478 -------------------------------------------------------------------------- */
480 ns_release_object
(pool
);
485 /* ==========================================================================
487 Focus (clipping) and screen update
489 ========================================================================== */
492 ns_resize_handle_rect
(NSWindow
*window
)
494 NSRect r
= [window frame
];
495 r.origin.x
= r.
size.width
- RESIZE_HANDLE_SIZE
;
497 r.
size.width
= r.
size.height
= RESIZE_HANDLE_SIZE
;
503 // Window constraining
504 // -------------------
506 // To ensure that the windows are not placed under the
menu bar, they
507 // are typically moved by the call
-back constrainFrameRect. However
,
508 // by overriding it
, it
's possible to inhibit this, leaving the window
509 // in it's original position.
511 // It
's possible to hide the menu bar. However, technically, it's only
512 // possible to hide it when the application is active. To ensure that
513 // this work properly
, the
menu bar and window constraining are
514 // deferred until the application becomes active.
516 // Even though it
's not possible to manually move a window above the
517 // top of the screen, it is allowed if it's done programmatically
,
518 // when the
menu is
hidden. This allows the editable area to cover the
519 // full screen height.
524 // Use the following extra files
:
527 // ;; Hide
menu and place frame slightly above the top of the screen.
528 // (setq ns
-auto
-hide
-menu-bar t
)
529 // (set-frame
-position
(selected
-frame
) 0 -20)
533 // emacs
-Q
-l init.el
535 // Result
: No
menu bar, and the
title bar should be above the screen.
541 // Result
: Menu bar visible
, frame placed immediately below the
menu.
545 ns_constrain_all_frames
(void
)
547 Lisp_Object tail
, frame
;
549 FOR_EACH_FRAME
(tail
, frame
)
551 struct frame
*f
= XFRAME
(frame
);
554 NSView
*view = FRAME_NS_VIEW
(f
);
555 /* This no-op will trigger the default window placing
556 * constraint system. */
557 f
->output_data.ns
->dont_constrain
= 0;
558 [[view window
] setFrameOrigin
:[[view window
] frame
].origin
];
564 /* True, if the menu bar should be hidden. */
567 ns_menu_bar_should_be_hidden
(void
)
569 return !NILP
(ns_auto_hide_menu_bar
)
570 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)];
574 /* Show or hide the menu bar, based on user setting. */
577 ns_update_auto_hide_menu_bar
(void
)
579 #ifndef MAC_OS_X_VERSION_10_6
580 #define MAC_OS_X_VERSION_10_6
1060
583 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
586 NSTRACE
(ns_update_auto_hide_menu_bar
);
590 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)])
592 // Note
, "setPresentationOptions" triggers an
error unless the
593 // application is active.
594 BOOL menu_bar_should_be_hidden
= ns_menu_bar_should_be_hidden
();
596 if (menu_bar_should_be_hidden
!= ns_menu_bar_is_hidden
)
598 NSApplicationPresentationOptions options
599 = NSApplicationPresentationAutoHideDock
;
601 if (menu_bar_should_be_hidden
)
602 options |
= NSApplicationPresentationAutoHideMenuBar
;
604 [NSApp setPresentationOptions
: options
];
606 ns_menu_bar_is_hidden
= menu_bar_should_be_hidden
;
608 if (!ns_menu_bar_is_hidden
)
610 ns_constrain_all_frames
();
622 ns_update_begin
(struct frame
*f
)
623 /* --------------------------------------------------------------------------
624 Prepare for a grouped sequence of drawing calls
625 external (RIF) call; whole frame, called before update_window_begin
626 -------------------------------------------------------------------------- */
628 NSView
*view = FRAME_NS_VIEW
(f
);
629 NSRect r
= [view frame
];
631 NSTRACE
(ns_update_begin
);
633 ns_update_auto_hide_menu_bar
();
635 ns_updating_frame
= f
;
638 /* drawRect may have been called for say the minibuffer, and then clip path
639 is for the minibuffer. But the display engine may draw more because
640 we have set the frame as garbaged. So reset clip path to the whole
642 bp
= [[NSBezierPath bezierPathWithRect
: r
] retain
];
646 #ifdef NS_IMPL_GNUSTEP
647 uRect
= NSMakeRect
(0, 0, 0, 0);
653 ns_update_window_begin
(struct window
*w
)
654 /* --------------------------------------------------------------------------
655 Prepare for a grouped sequence of drawing calls
656 external (RIF) call; for one window, called after update_begin
657 -------------------------------------------------------------------------- */
659 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
660 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
661 NSTRACE
(ns_update_window_begin
);
663 set_output_cursor
(&w
->cursor
);
667 if (f
== hlinfo
->mouse_face_mouse_frame
)
669 /* Don't do highlighting for mouse motion during the update. */
670 hlinfo
->mouse_face_defer
= 1;
672 /* If the frame needs to be redrawn,
673 simply forget about any prior mouse highlighting. */
674 if (FRAME_GARBAGED_P
(f
))
675 hlinfo
->mouse_face_window
= Qnil
;
677 /* (further code for mouse faces ifdef'd out in other terms elided) */
685 ns_update_window_end
(struct window
*w
, int cursor_on_p
,
686 int mouse_face_overwritten_p
)
687 /* --------------------------------------------------------------------------
688 Finished a grouped sequence of drawing calls
689 external (RIF) call; for one window called before update_end
690 -------------------------------------------------------------------------- */
692 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(XFRAME
(w
->frame
));
694 /* note: this fn is nearly identical in all terms */
695 if (!w
->pseudo_window_p
)
700 display_and_set_cursor
(w
, 1,
701 output_cursor.hpos
, output_cursor.vpos
,
702 output_cursor.x
, output_cursor.y
);
704 if (draw_window_fringes
(w
, 1))
705 x_draw_vertical_border
(w
);
710 /* If a row with mouse-face was overwritten, arrange for
711 frame_up_to_date to redisplay the mouse highlight. */
712 if (mouse_face_overwritten_p
)
714 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
715 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
716 hlinfo
->mouse_face_window
= Qnil
;
719 updated_window
= NULL;
720 NSTRACE
(update_window_end
);
725 ns_update_end
(struct frame
*f
)
726 /* --------------------------------------------------------------------------
727 Finished a grouped sequence of drawing calls
728 external (RIF) call; for whole frame, called after update_window_end
729 -------------------------------------------------------------------------- */
731 NSView
*view = FRAME_NS_VIEW
(f
);
733 /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
734 MOUSE_HL_INFO
(f
)->mouse_face_defer
= 0;
738 #ifdef NS_IMPL_GNUSTEP
739 /* trigger flush only in the rectangle we tracked as being drawn */
740 [view unlockFocusNeedsFlush
: NO
];
741 /*fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", uRect.origin.x, uRect.origin.y, uRect.size.width, uRect.size.height); */
742 [view lockFocusInRect
: uRect
];
746 [[view window
] flushWindow
];
749 ns_updating_frame
= NULL;
750 NSTRACE
(ns_update_end
);
755 ns_flush
(struct frame
*f
)
756 /* --------------------------------------------------------------------------
758 NS impl is no-op since currently we flush in ns_update_end and elsewhere
759 -------------------------------------------------------------------------- */
766 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
767 /* --------------------------------------------------------------------------
768 Internal: Focus on given frame. During small local updates this is used to
769 draw, however during large updates, ns_update_begin and ns_update_end are
770 called to wrap the whole thing, in which case these calls are stubbed out.
771 Except, on GNUstep, we accumulate the rectangle being drawn into, because
772 the back end won't do this automatically, and will just end up flushing
774 -------------------------------------------------------------------------- */
776 // NSTRACE
(ns_focus
);
777 #ifdef NS_IMPL_GNUSTEP
780 u
= NSUnionRect
(r
[0], r
[1]);
785 fprintf (stderr, "focus: %d", c++);
786 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
787 fprintf (stderr, "\n"); */
789 if (f
!= ns_updating_frame
)
791 NSView
*view = FRAME_NS_VIEW
(f
);
792 if (view != focus_view
)
794 if (focus_view
!= NULL)
796 [focus_view unlockFocus
];
797 [[focus_view window
] flushWindow
];
802 #ifdef NS_IMPL_GNUSTEP
803 r ?
[view lockFocusInRect
: u
] : [view lockFocus
];
808 /*if (view) debug_lock++; */
810 #ifdef NS_IMPL_GNUSTEP
813 /* more than one rect being drawn into */
816 [view unlockFocus
]; /* add prev rect to redraw list */
817 [view lockFocusInRect
: u
]; /* focus for draw in new rect */
822 #ifdef NS_IMPL_GNUSTEP
825 /* in batch mode, but in GNUstep must still track rectangles explicitly */
826 uRect
= (r ? NSUnionRect
(uRect
, u
) : [FRAME_NS_VIEW
(f
) visibleRect
]);
833 [[NSGraphicsContext currentContext
] saveGraphicsState
];
835 NSRectClipList
(r
, 2);
844 ns_unfocus
(struct frame
*f
)
845 /* --------------------------------------------------------------------------
846 Internal: Remove focus on given frame
847 -------------------------------------------------------------------------- */
849 // NSTRACE
(ns_unfocus
);
853 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
857 if (f
!= ns_updating_frame
)
859 if (focus_view
!= NULL)
861 [focus_view unlockFocus
];
862 [[focus_view window
] flushWindow
];
871 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
, int area
, BOOL gc
)
872 /* --------------------------------------------------------------------------
873 Internal (but parallels other terms): Focus drawing on given row
874 -------------------------------------------------------------------------- */
876 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
878 int window_x
, window_y
, window_width
;
880 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
882 clip_rect.origin.x
= window_x
;
883 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
884 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
885 clip_rect.
size.width
= window_width
;
886 clip_rect.
size.height
= row
->visible_height
;
888 ns_focus
(f
, &clip_rect
, 1);
893 ns_ring_bell
(struct frame
*f
)
894 /* --------------------------------------------------------------------------
896 -------------------------------------------------------------------------- */
898 NSTRACE
(ns_ring_bell
);
901 NSAutoreleasePool
*pool
;
902 struct frame
*frame
= SELECTED_FRAME
();
906 pool
= [[NSAutoreleasePool alloc
] init
];
908 view = FRAME_NS_VIEW
(frame
);
912 NSPoint dim
= NSMakePoint
(128, 128);
915 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
916 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
917 r.
size.width
= dim.x
;
918 r.
size.height
= dim.y
;
919 surr
= NSInsetRect
(r
, -2, -2);
920 ns_focus
(frame
, &surr
, 1);
921 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
922 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
923 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
925 [[view window
] flushWindow
];
927 [[view window
] restoreCachedImage
];
928 [[view window
] flushWindow
];
942 ns_reset_terminal_modes
(struct terminal *terminal)
943 /* Externally called as hook */
945 NSTRACE
(ns_reset_terminal_modes
);
950 ns_set_terminal_modes
(struct terminal *terminal)
951 /* Externally called as hook */
953 NSTRACE
(ns_set_terminal_modes
);
958 /* ==========================================================================
960 Frame / window manager related functions
962 ========================================================================== */
966 ns_raise_frame
(struct frame
*f
)
967 /* --------------------------------------------------------------------------
968 Bring window to foreground and make it active
969 -------------------------------------------------------------------------- */
971 NSView
*view = FRAME_NS_VIEW
(f
);
974 FRAME_SAMPLE_VISIBILITY
(f
);
975 if (FRAME_VISIBLE_P
(f
))
977 [[view window
] makeKeyAndOrderFront
: NSApp
];
984 ns_lower_frame
(struct frame
*f
)
985 /* --------------------------------------------------------------------------
987 -------------------------------------------------------------------------- */
989 NSView
*view = FRAME_NS_VIEW
(f
);
992 [[view window
] orderBack
: NSApp
];
998 ns_frame_raise_lower
(struct frame
*f
, int raise
)
999 /* --------------------------------------------------------------------------
1001 -------------------------------------------------------------------------- */
1003 NSTRACE
(ns_frame_raise_lower
);
1013 ns_frame_rehighlight
(struct frame
*frame
)
1014 /* --------------------------------------------------------------------------
1015 External (hook): called on things like window switching within frame
1016 -------------------------------------------------------------------------- */
1018 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(frame
);
1019 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1021 NSTRACE
(ns_frame_rehighlight
);
1022 if (dpyinfo
->x_focus_frame
)
1024 dpyinfo
->x_highlight_frame
1025 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1026 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1027 : dpyinfo
->x_focus_frame
);
1028 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
1030 fset_focus_frame
(dpyinfo
->x_focus_frame
, Qnil
);
1031 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1035 dpyinfo
->x_highlight_frame
= 0;
1037 if (dpyinfo
->x_highlight_frame
&&
1038 dpyinfo
->x_highlight_frame
!= old_highlight
)
1042 x_update_cursor
(old_highlight
, 1);
1043 x_set_frame_alpha
(old_highlight
);
1045 if (dpyinfo
->x_highlight_frame
)
1047 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
1048 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
1055 x_make_frame_visible
(struct frame
*f
)
1056 /* --------------------------------------------------------------------------
1057 External: Show the window (X11 semantics)
1058 -------------------------------------------------------------------------- */
1060 NSTRACE
(x_make_frame_visible
);
1061 /* XXX: at some points in past this was not needed, as the only place that
1062 called this (frame.c:Fraise_frame ()) also called raise_lower;
1063 if this ends up the case again, comment this out again. */
1064 if (!FRAME_VISIBLE_P
(f
))
1066 f
->async_visible
= 1;
1073 x_make_frame_invisible
(struct frame
*f
)
1074 /* --------------------------------------------------------------------------
1075 External: Hide the window (X11 semantics)
1076 -------------------------------------------------------------------------- */
1078 NSView
* view = FRAME_NS_VIEW
(f
);
1079 NSTRACE
(x_make_frame_invisible
);
1081 [[view window
] orderOut
: NSApp
];
1082 f
->async_visible
= 0;
1083 f
->async_iconified
= 0;
1088 x_iconify_frame
(struct frame
*f
)
1089 /* --------------------------------------------------------------------------
1090 External: Iconify window
1091 -------------------------------------------------------------------------- */
1093 NSView
* view = FRAME_NS_VIEW
(f
);
1094 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1095 NSTRACE
(x_iconify_frame
);
1098 if (dpyinfo
->x_highlight_frame
== f
)
1099 dpyinfo
->x_highlight_frame
= 0;
1101 if ([[view window
] windowNumber
] <= 0)
1103 /* the window is still deferred. Make it very small, bring it
1104 on screen and order it out. */
1105 NSRect s
= { { 100, 100}, {0, 0} };
1107 t
= [[view window
] frame
];
1108 [[view window
] setFrame
: s display
: NO
];
1109 [[view window
] orderBack
: NSApp
];
1110 [[view window
] orderOut
: NSApp
];
1111 [[view window
] setFrame
: t display
: NO
];
1113 [[view window
] miniaturize
: NSApp
];
1116 /* Free X resources of frame F. */
1119 x_free_frame_resources
(struct frame
*f
)
1121 NSView
*view = FRAME_NS_VIEW
(f
);
1122 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1123 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1124 NSTRACE
(x_free_frame_resources
);
1127 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1131 free_frame_menubar
(f
);
1133 if (FRAME_FACE_CACHE
(f
))
1134 free_frame_faces
(f
);
1136 if (f
== dpyinfo
->x_focus_frame
)
1137 dpyinfo
->x_focus_frame
= 0;
1138 if (f
== dpyinfo
->x_highlight_frame
)
1139 dpyinfo
->x_highlight_frame
= 0;
1140 if (f
== hlinfo
->mouse_face_mouse_frame
)
1142 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1143 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1144 hlinfo
->mouse_face_window
= Qnil
;
1145 hlinfo
->mouse_face_deferred_gc
= 0;
1146 hlinfo
->mouse_face_mouse_frame
= 0;
1149 if (f
->output_data.ns
->miniimage
!= nil
)
1150 [f
->output_data.ns
->miniimage release
];
1152 [[view window
] close];
1155 xfree
(f
->output_data.ns
);
1161 x_destroy_window
(struct frame
*f
)
1162 /* --------------------------------------------------------------------------
1163 External: Delete the window
1164 -------------------------------------------------------------------------- */
1166 NSTRACE
(x_destroy_window
);
1168 x_free_frame_resources
(f
);
1174 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1175 /* --------------------------------------------------------------------------
1176 External: Position the window
1177 -------------------------------------------------------------------------- */
1179 NSView
*view = FRAME_NS_VIEW
(f
);
1180 NSArray
*screens
= [NSScreen screens
];
1181 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1182 NSScreen
*screen
= [[view window
] screen
];
1184 NSTRACE
(x_set_offset
);
1191 if (view != nil
&& screen
&& fscreen
)
1193 f
->left_pos
= f
->size_hint_flags
& XNegative
1194 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1196 /* We use visibleFrame here to take menu bar into account.
1197 Ideally we should also adjust left/top with visibleFrame.origin. */
1199 f
->top_pos
= f
->size_hint_flags
& YNegative
1200 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1201 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1202 - FRAME_TOOLBAR_HEIGHT
(f
))
1204 #ifdef NS_IMPL_GNUSTEP
1205 if (f
->left_pos
< 100)
1206 f
->left_pos
= 100; /* don't overlap menu */
1208 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1210 f
->output_data.ns
->dont_constrain
= 0;
1211 [[view window
] setFrameTopLeftPoint
:
1212 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1213 SCREENMAXBOUND
([fscreen frame
].
size.height
1214 - NS_TOP_POS
(f
)))];
1215 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1223 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1224 /* --------------------------------------------------------------------------
1225 Adjust window pixel size based on given character grid size
1226 Impl is a bit more complex than other terms, need to do some
1228 -------------------------------------------------------------------------- */
1230 EmacsView
*view = FRAME_NS_VIEW
(f
);
1231 NSWindow
*window
= [view window
];
1232 NSRect wr
= [window frame
];
1233 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1234 int pixelwidth
, pixelheight
;
1236 NSTRACE
(x_set_window_size
);
1241 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1245 check_frame_size
(f
, &rows
, &cols
);
1247 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1248 compute_fringe_widths
(f
, 0);
1250 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1251 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1253 /* If we have a toolbar, take its height into account. */
1255 /* NOTE: previously this would generate wrong result if toolbar not
1256 yet displayed and fixing toolbar_height=32 helped, but
1257 now (200903) seems no longer needed */
1258 FRAME_TOOLBAR_HEIGHT
(f
) =
1259 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1260 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1262 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1264 wr.
size.width
= pixelwidth
+ f
->border_width
;
1265 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1266 + FRAME_TOOLBAR_HEIGHT
(f
);
1268 /* Do not try to constrain to this screen. We may have multiple
1269 screens, and want Emacs to span those. Constraining to screen
1270 prevents that, and that is not nice to the user. */
1271 if (f
->output_data.ns
->zooming
)
1272 f
->output_data.ns
->zooming
= 0;
1274 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1276 [view setRows
: rows andColumns
: cols
];
1277 [window setFrame
: wr display
: YES
];
1279 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1281 /* This is a trick to compensate for Emacs' managing the scrollbar area
1282 as a fixed number of standard character columns. Instead of leaving
1283 blank space for the extra, we chopped it off above. Now for
1284 left-hand scrollbars, we shift all rendering to the left by the
1285 difference between the real width and Emacs' imagined one. For
1286 right-hand bars, don't worry about it since the extra is never used.
1287 (Obviously doesn't work for vertically split windows tho..) */
1289 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1290 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1291 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1292 : NSMakePoint
(0, 0);
1293 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1294 [view setBoundsOrigin
: origin
];
1297 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1298 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1299 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1300 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1302 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1303 cancel_mouse_face
(f
);
1310 /* ==========================================================================
1314 ========================================================================== */
1318 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1320 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1321 if (idx
< 1 || idx
>= color_table
->avail
)
1323 return color_table
->colors
[idx
];
1328 ns_index_color
(NSColor
*color
, struct frame
*f
)
1330 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1334 if (!color_table
->colors
)
1336 color_table
->size = NS_COLOR_CAPACITY
;
1337 color_table
->avail
= 1; /* skip idx=0 as marker */
1338 color_table
->colors
= xmalloc
(color_table
->size * sizeof
(NSColor
*));
1339 color_table
->colors
[0] = nil
;
1340 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1343 /* do we already have this color ? */
1344 for (i
= 1; i
< color_table
->avail
; i
++)
1345 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1348 if ([color_table
->empty_indices count
] > 0)
1350 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1351 [color_table
->empty_indices removeObject
: index
];
1352 idx
= [index unsignedLongValue
];
1356 if (color_table
->avail
== color_table
->size)
1357 color_table
->colors
=
1358 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1359 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1360 idx
= color_table
->avail
++;
1363 color_table
->colors
[idx
] = color
;
1365 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1371 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1373 struct ns_color_table
*color_table
;
1380 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1382 if (idx
<= 0 || idx
>= color_table
->size) {
1383 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1387 index
= [NSNumber numberWithUnsignedInt
: idx
];
1388 if ([color_table
->empty_indices containsObject
: index
]) {
1389 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1393 color
= color_table
->colors
[idx
];
1395 color_table
->colors
[idx
] = nil
;
1396 [color_table
->empty_indices addObject
: index
];
1397 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1402 ns_get_color
(const
char *name
, NSColor
**col
)
1403 /* --------------------------------------------------------------------------
1405 -------------------------------------------------------------------------- */
1406 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1407 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1408 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1411 static
char hex
[20];
1413 float r
= -1.0, g
, b
;
1414 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1416 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1419 if ([nsname isEqualToString
: @"ns_selection_color"
])
1421 nsname
= ns_selection_color
;
1422 name
= [ns_selection_color UTF8String
];
1425 /* First, check for some sort of numeric specification. */
1428 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1430 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1431 [scanner scanFloat
: &r
];
1432 [scanner scanFloat
: &g
];
1433 [scanner scanFloat
: &b
];
1435 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1436 scaling
= (snprintf
(hex
, sizeof hex
, "
%s", name + 4) - 2) / 3;
1437 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1439 int len
= (strlen
(name
) - 1);
1440 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1442 scaling
= strlen
(name
+start
) / 3;
1443 for (i
= 0; i
< 3; i
++)
1444 sprintf (hex
+ i
* (scaling
+ 1), "
%.*s/", scaling,
1445 name
+ start
+ i
* scaling
);
1446 hex
[3 * (scaling
+ 1) - 1] = '\0';
1452 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1453 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1463 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1468 /* Otherwise, color is expected to be from a list */
1470 NSEnumerator
*lenum
, *cenum
;
1474 #ifdef NS_IMPL_GNUSTEP
1475 /* XXX: who is wrong, the requestor or the implementation? */
1476 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1478 nsname
= @"highlightColor"
;
1481 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1482 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1484 cenum
= [[clist allKeys
] objectEnumerator
];
1485 while ( (name
= [cenum nextObject
]) && new
== nil
)
1487 if ([name compare
: nsname
1488 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1489 new
= [clist colorWithKey
: name
];
1495 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1502 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1503 /* --------------------------------------------------------------------------
1504 Convert a Lisp string object to a NS color
1505 -------------------------------------------------------------------------- */
1507 NSTRACE
(ns_lisp_to_color
);
1508 if (STRINGP
(color
))
1509 return ns_get_color
(SSDATA
(color
), col
);
1510 else if (SYMBOLP
(color
))
1511 return ns_get_color
(SSDATA
(SYMBOL_NAME
(color
)), col
);
1517 ns_color_to_lisp
(NSColor
*col
)
1518 /* --------------------------------------------------------------------------
1519 Convert a color to a lisp string with the RGB equivalent
1520 -------------------------------------------------------------------------- */
1522 CGFloat red
, green
, blue
, alpha
, gray;
1525 NSTRACE
(ns_color_to_lisp
);
1528 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1530 if ((str
=[[col colorNameComponent
] UTF8String
]))
1533 return build_string
((char *)str
);
1536 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1537 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1538 if (red
==green
&& red
==blue
)
1540 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1541 getWhite
: &gray alpha
: &alpha
];
1542 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1543 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1545 return build_string
(buf
);
1548 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1549 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1552 return build_string
(buf
);
1557 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1558 /* --------------------------------------------------------------------------
1559 Get ARGB values out of NSColor col and put them into color_def.
1560 If setPixel, set the pixel to a concatenated version.
1561 and set color_def pixel to the resulting index.
1562 -------------------------------------------------------------------------- */
1566 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1567 color_def
->red
= r
* 65535;
1568 color_def
->green
= g
* 65535;
1569 color_def
->blue
= b
* 65535;
1571 if (setPixel
== YES
)
1573 = ARGB_TO_ULONG
((int
)(a
*255),
1574 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1579 ns_defined_color
(struct frame
*f
,
1584 /* --------------------------------------------------------------------------
1585 Return 1 if named color found, and set color_def rgb accordingly.
1586 If makeIndex and alloc are nonzero put the color in the color_table,
1587 and set color_def pixel to the resulting index.
1588 If makeIndex is zero, set color_def pixel to ARGB.
1589 Return 0 if not found
1590 -------------------------------------------------------------------------- */
1593 NSTRACE
(ns_defined_color
);
1596 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1601 if (makeIndex
&& alloc
)
1602 color_def
->pixel
= ns_index_color
(col
, f
);
1603 ns_query_color
(col
, color_def
, !makeIndex
);
1610 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1611 /* --------------------------------------------------------------------------
1612 return an autoreleased RGB color
1613 -------------------------------------------------------------------------- */
1615 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1616 if (r
< 0.0) r
= 0.0;
1617 else if (r
> 1.0) r
= 1.0;
1618 if (g
< 0.0) g
= 0.0;
1619 else if (g
> 1.0) g
= 1.0;
1620 if (b
< 0.0) b
= 0.0;
1621 else if (b
> 1.0) b
= 1.0;
1622 if (a
< 0.0) a
= 0.0;
1623 else if (a
> 1.0) a
= 1.0;
1624 return (unsigned
long) ns_index_color
(
1625 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1630 x_set_frame_alpha
(struct frame
*f
)
1631 /* --------------------------------------------------------------------------
1632 change the entire-frame transparency
1633 -------------------------------------------------------------------------- */
1635 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1636 EmacsView
*view = FRAME_NS_VIEW
(f
);
1638 double alpha_min
= 1.0;
1640 if (dpyinfo
->x_highlight_frame
== f
)
1641 alpha
= f
->alpha
[0];
1643 alpha
= f
->alpha
[1];
1645 if (FLOATP
(Vframe_alpha_lower_limit
))
1646 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1647 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1648 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1652 else if (1.0 < alpha
)
1654 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1657 #ifdef NS_IMPL_COCOA
1658 [[view window
] setAlphaValue
: alpha
];
1663 /* ==========================================================================
1667 ========================================================================== */
1671 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1672 /* --------------------------------------------------------------------------
1673 Programmatically reposition mouse pointer in pixel coordinates
1674 -------------------------------------------------------------------------- */
1676 NSTRACE
(x_set_mouse_pixel_position
);
1679 /* FIXME: this does not work, and what about GNUstep? */
1680 #ifdef NS_IMPL_COCOA
1681 [FRAME_NS_VIEW
(f
) lockFocus
];
1682 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1683 [FRAME_NS_VIEW
(f
) unlockFocus
];
1690 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1691 /* --------------------------------------------------------------------------
1692 Programmatically reposition mouse pointer in character coordinates
1693 -------------------------------------------------------------------------- */
1697 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1698 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1700 if (pix_x
< 0) pix_x
= 0;
1701 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1703 if (pix_y
< 0) pix_y
= 0;
1704 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1706 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1711 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1712 /* ------------------------------------------------------------------------
1713 Called by EmacsView on mouseMovement events. Passes on
1714 to emacs mainstream code if we moved off of a rect of interest
1715 known as last_mouse_glyph.
1716 ------------------------------------------------------------------------ */
1718 // NSTRACE
(note_mouse_movement
);
1720 XSETFRAME
(last_mouse_motion_frame
, frame
);
1722 /* Note, this doesn't get called for enter/leave, since we don't have a
1723 position. Those are taken care of in the corresponding NSView methods. */
1725 /* has movement gone beyond last rect we were tracking? */
1726 if (x
< last_mouse_glyph.origin.x ||
1727 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1728 y
< last_mouse_glyph.origin.y ||
1729 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1731 ns_update_begin
(frame
);
1732 frame
->mouse_moved
= 1;
1733 note_mouse_highlight
(frame
, x
, y
);
1734 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1735 ns_update_end
(frame
);
1744 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1745 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1747 /* --------------------------------------------------------------------------
1748 External (hook): inform emacs about mouse position and hit parts.
1749 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1750 x & y should be position in the scrollbar (the whole bar, not the handle)
1751 and length of scrollbar respectively
1752 -------------------------------------------------------------------------- */
1756 Lisp_Object frame
, tail
;
1758 struct ns_display_info
*dpyinfo
;
1760 NSTRACE
(ns_mouse_position
);
1764 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1768 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1772 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1774 /* TODO: we do not use this path at the moment because drag events will
1775 go directly to the EmacsScroller. Leaving code in for now. */
1776 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1778 if (time
) *time
= last_mouse_movement_time
;
1779 last_mouse_scroll_bar
= nil
;
1783 /* Clear the mouse-moved flag for every frame on this display. */
1784 FOR_EACH_FRAME
(tail
, frame
)
1785 if (FRAME_NS_P
(XFRAME
(frame
))
1786 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1787 XFRAME
(frame
)->mouse_moved
= 0;
1789 last_mouse_scroll_bar
= nil
;
1790 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1791 f
= last_mouse_frame
;
1793 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1794 : SELECTED_FRAME
();
1796 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1798 view = FRAME_NS_VIEW
(*fp
);
1800 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1801 position
= [view convertPoint
: position fromView
: nil
];
1802 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1803 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1805 if (bar_window
) *bar_window
= Qnil
;
1806 if (part
) *part
= 0; /*scroll_bar_handle; */
1808 if (x
) XSETINT
(*x
, lrint
(position.x
));
1809 if (y
) XSETINT
(*y
, lrint
(position.y
));
1810 if (time
) *time
= last_mouse_movement_time
;
1820 ns_frame_up_to_date
(struct frame
*f
)
1821 /* --------------------------------------------------------------------------
1822 External (hook): Fix up mouse highlighting right after a full update.
1823 Some highlighting was deferred if GC was happening during
1824 note_mouse_highlight (), while other highlighting was deferred for update.
1825 -------------------------------------------------------------------------- */
1827 NSTRACE
(ns_frame_up_to_date
);
1831 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1832 if ((hlinfo
->mouse_face_deferred_gc || f
==hlinfo
->mouse_face_mouse_frame
)
1833 /*&& hlinfo->mouse_face_mouse_frame*/)
1837 if (hlinfo
->mouse_face_mouse_frame
)
1838 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1839 hlinfo
->mouse_face_mouse_x
,
1840 hlinfo
->mouse_face_mouse_y
);
1841 hlinfo
->mouse_face_deferred_gc
= 0;
1850 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1851 /* --------------------------------------------------------------------------
1852 External (RIF): set frame mouse pointer type.
1853 -------------------------------------------------------------------------- */
1855 NSTRACE
(ns_define_frame_cursor
);
1856 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1858 EmacsView
*view = FRAME_NS_VIEW
(f
);
1859 FRAME_POINTER_TYPE
(f
) = cursor
;
1860 [[view window
] invalidateCursorRectsForView
: view];
1861 /* Redisplay assumes this function also draws the changed frame
1862 cursor, but this function doesn't, so do it explicitly. */
1863 x_update_cursor
(f
, 1);
1869 /* ==========================================================================
1873 ========================================================================== */
1877 ns_convert_key
(unsigned code
)
1878 /* --------------------------------------------------------------------------
1879 Internal call used by NSView-keyDown.
1880 -------------------------------------------------------------------------- */
1882 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1883 / sizeof
(convert_ns_to_X_keysym
[0]));
1885 /* An array would be faster, but less easy to read. */
1886 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1887 if (code
== convert_ns_to_X_keysym
[keysym
])
1888 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1890 /* if decide to use keyCode and Carbon table, use this line:
1891 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1896 x_get_keysym_name
(int keysym
)
1897 /* --------------------------------------------------------------------------
1898 Called by keyboard.c. Not sure if the return val is important, except
1900 -------------------------------------------------------------------------- */
1902 static
char value
[16];
1903 NSTRACE
(x_get_keysym_name
);
1904 sprintf (value
, "
%d", keysym);
1910 /* ==========================================================================
1912 Block drawing operations
1914 ========================================================================== */
1918 ns_redraw_scroll_bars
(struct frame
*f
)
1922 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1923 NSTRACE
(ns_redraw_scroll_bars
);
1924 for (i
=[subviews count
]-1; i
>= 0; i
--)
1926 view = [subviews objectAtIndex
: i
];
1927 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
1934 ns_clear_frame
(struct frame
*f
)
1935 /* --------------------------------------------------------------------------
1936 External (hook): Erase the entire frame
1937 -------------------------------------------------------------------------- */
1939 NSView
*view = FRAME_NS_VIEW
(f
);
1942 NSTRACE
(ns_clear_frame
);
1946 /* comes on initial frame because we have
1947 after-make-frame-functions = select-frame */
1948 if (!FRAME_DEFAULT_FACE
(f
))
1951 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
1953 output_cursor.hpos
= output_cursor.vpos
= 0;
1954 output_cursor.x
= -1;
1959 ns_focus
(f
, &r
, 1);
1960 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
1964 #ifdef NS_IMPL_COCOA
1965 [[view window
] display
]; /* redraw resize handle */
1968 /* as of 2006/11 or so this is now needed */
1969 ns_redraw_scroll_bars
(f
);
1975 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
1976 /* --------------------------------------------------------------------------
1977 External (RIF): Clear section of frame
1978 -------------------------------------------------------------------------- */
1980 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
1981 NSView
*view = FRAME_NS_VIEW
(f
);
1982 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
1987 NSTRACE
(ns_clear_frame_area
);
1989 r
= NSIntersectionRect
(r
, [view frame
]);
1990 ns_focus
(f
, &r
, 1);
1991 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
1993 #ifdef NS_IMPL_COCOA
1995 /* clip out the resize handle */
1996 NSWindow
*window
= [FRAME_NS_VIEW
(f
) window
];
1998 = [view convertRect
: ns_resize_handle_rect
(window
) fromView
: nil
];
2000 ir
= NSIntersectionRect
(r
, ir
);
2001 if (NSIsEmptyRect
(ir
))
2007 #ifdef NS_IMPL_COCOA
2011 NSRect r1
= r
, r2
= r
; /* upper and lower non-intersecting */
2012 r1.
size.height
-= ir.
size.height
;
2013 r2.origin.y
+= r1.
size.height
;
2014 r2.
size.width
-= ir.
size.width
;
2015 r2.
size.height
= ir.
size.height
;
2028 ns_scroll_run
(struct window
*w
, struct run
*run
)
2029 /* --------------------------------------------------------------------------
2030 External (RIF): Insert or delete n lines at line vpos
2031 -------------------------------------------------------------------------- */
2033 struct frame
*f
= XFRAME
(w
->frame
);
2034 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2036 NSTRACE
(ns_scroll_run
);
2038 /* begin copy from other terms */
2039 /* Get frame-relative bounding box of the text display area of W,
2040 without mode lines. Include in this box the left and right
2042 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2044 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2045 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2046 bottom_y
= y
+ height
;
2050 /* Scrolling up. Make sure we don't copy part of the mode
2051 line at the bottom. */
2052 if (from_y
+ run
->height
> bottom_y
)
2053 height
= bottom_y
- from_y
;
2055 height
= run
->height
;
2059 /* Scrolling down. Make sure we don't copy over the mode line.
2061 if (to_y
+ run
->height
> bottom_y
)
2062 height
= bottom_y
- to_y
;
2064 height
= run
->height
;
2066 /* end copy from other terms */
2077 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2078 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2079 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2081 ns_focus
(f
, &dstRect
, 1);
2082 NSCopyBits
(0, srcRect
, dstOrigin
);
2091 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2092 /* --------------------------------------------------------------------------
2093 External (RIF): preparatory to fringe update after text was updated
2094 -------------------------------------------------------------------------- */
2096 struct window
*w
= updated_window
;
2100 NSTRACE
(ns_after_update_window_line
);
2102 /* begin copy from other terms */
2105 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2106 desired_row
->redraw_fringe_bitmaps_p
= 1;
2108 /* When a window has disappeared, make sure that no rest of
2109 full-width rows stays visible in the internal border. */
2110 if (windows_or_buffers_changed
2111 && desired_row
->full_width_p
2112 && (f
= XFRAME
(w
->frame
),
2113 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2115 && (height
= desired_row
->visible_height
,
2118 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2121 ns_clear_frame_area
(f
, 0, y
, width
, height
);
2122 ns_clear_frame_area
(f
,
2123 FRAME_PIXEL_WIDTH
(f
) - width
,
2131 ns_shift_glyphs_for_insert
(struct frame
*f
,
2132 int x
, int y
, int width
, int height
,
2134 /* --------------------------------------------------------------------------
2135 External (RIF): copy an area horizontally, don't worry about clearing src
2136 -------------------------------------------------------------------------- */
2138 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2139 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2140 NSPoint dstOrigin
= dstRect.origin
;
2142 NSTRACE
(ns_shift_glyphs_for_insert
);
2144 ns_focus
(f
, &dstRect
, 1);
2145 NSCopyBits
(0, srcRect
, dstOrigin
);
2151 /* ==========================================================================
2153 Character encoding and metrics
2155 ========================================================================== */
2159 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2160 /* --------------------------------------------------------------------------
2161 External (RIF); compute left/right overhang of whole string and set in s
2162 -------------------------------------------------------------------------- */
2164 struct font
*font
= s
->font
;
2168 struct font_metrics metrics
;
2169 unsigned int codes
[2];
2170 codes
[0] = *(s
->char2b
);
2171 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2173 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2174 s
->left_overhang
= -metrics.lbearing
;
2176 = metrics.rbearing
> metrics.width
2177 ? metrics.rbearing
- metrics.width
: 0;
2181 s
->left_overhang
= 0;
2182 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2183 FONT_HEIGHT
(font
) * 0.2 : 0;
2189 /* ==========================================================================
2191 Fringe and cursor drawing
2193 ========================================================================== */
2196 extern int max_used_fringe_bitmap
;
2198 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2199 struct draw_fringe_bitmap_params
*p
)
2200 /* --------------------------------------------------------------------------
2201 External (RIF); fringe-related
2202 -------------------------------------------------------------------------- */
2204 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2205 struct face
*face
= p
->face
;
2207 static EmacsImage
**bimgs
= NULL;
2208 static int nBimgs
= 0;
2210 /* grow bimgs if needed */
2211 if (nBimgs
< max_used_fringe_bitmap
)
2213 bimgs
= xrealloc
(bimgs
, max_used_fringe_bitmap
* sizeof
*bimgs
);
2214 memset
(bimgs
+ nBimgs
, 0,
2215 (max_used_fringe_bitmap
- nBimgs
) * sizeof
*bimgs
);
2216 nBimgs
= max_used_fringe_bitmap
;
2219 /* Must clip because of partially visible lines. */
2220 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2221 ns_clip_to_row
(w
, row
, -1, YES
);
2225 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
2227 /* If the fringe is adjacent to the left (right) scroll bar of a
2228 leftmost (rightmost, respectively) window, then extend its
2229 background to the gap between the fringe and the bar. */
2230 if ((WINDOW_LEFTMOST_P
(w
)
2231 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(w
))
2232 ||
(WINDOW_RIGHTMOST_P
(w
)
2233 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT
(w
)))
2235 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH
(w
);
2239 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X
(w
);
2240 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS
(w
)
2241 * FRAME_COLUMN_WIDTH
(f
));
2245 /* Bitmap fills the fringe. */
2246 if (bar_area_x
+ bar_area_width
== p
->x
)
2247 bx
= bar_area_x
+ sb_width
;
2248 else if (p
->x
+ p
->wd
== bar_area_x
)
2252 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT
(w
);
2254 nx
= bar_area_width
- sb_width
;
2255 by
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (header_line_height
,
2257 ny
= row
->visible_height
;
2262 if (bar_area_x
+ bar_area_width
== bx
)
2264 bx
= bar_area_x
+ sb_width
;
2265 nx
+= bar_area_width
- sb_width
;
2267 else if (bx
+ nx
== bar_area_x
)
2268 nx
+= bar_area_width
- sb_width
;
2273 if (bx
>= 0 && nx
> 0)
2275 NSRect r
= NSMakeRect
(bx
, by
, nx
, ny
);
2277 [ns_lookup_indexed_color
(face
->background
, f
) set];
2284 NSRect r
= NSMakeRect
(p
->x
, p
->y
, p
->wd
, p
->h
);
2285 EmacsImage
*img
= bimgs
[p
->which - 1];
2289 unsigned short
*bits
= p
->bits
+ p
->dh
;
2292 unsigned
char *cbits
= xmalloc
(len
);
2294 for (i
= 0; i
< len
; i
++)
2295 cbits
[i
] = ~
(bits
[i
] & 0xff);
2296 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2298 bimgs
[p
->which - 1] = img
;
2303 /* Since we composite the bitmap instead of just blitting it, we need
2304 to erase the whole background. */
2305 [ns_lookup_indexed_color
(face
->background
, f
) set];
2307 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2308 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
2310 fromRect
: NSZeroRect
2311 operation
: NSCompositeSourceOver
2317 NSPoint pt
= r.origin
;
2319 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2328 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2329 int x
, int y
, int cursor_type
, int cursor_width
,
2330 int on_p
, int active_p
)
2331 /* --------------------------------------------------------------------------
2332 External call (RIF): draw cursor.
2333 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2334 -------------------------------------------------------------------------- */
2337 int fx
, fy
, h
, cursor_height
;
2338 struct frame
*f
= WINDOW_XFRAME
(w
);
2339 struct glyph
*phys_cursor_glyph
;
2341 struct glyph
*cursor_glyph
;
2343 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2345 /* If cursor is out of bounds, don't draw garbage. This can happen
2346 in mini-buffer windows when switching between echo area glyphs
2349 NSTRACE
(dumpcursor
);
2354 w
->phys_cursor_type
= cursor_type
;
2355 w
->phys_cursor_on_p
= on_p
;
2357 if (cursor_type
== NO_CURSOR
)
2359 w
->phys_cursor_width
= 0;
2363 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2365 if (glyph_row
->exact_window_width_line_p
2366 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2368 glyph_row
->cursor_in_fringe_p
= 1;
2369 draw_fringe_bitmap
(w
, glyph_row
, 0);
2374 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2375 (other terminals do it the other way round). We must set
2376 w->phys_cursor_width to the cursor width. For bar cursors, that
2377 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2378 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2380 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2381 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2382 if (cursor_type
== BAR_CURSOR
)
2384 if (cursor_width
< 1)
2385 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2386 w
->phys_cursor_width
= cursor_width
;
2388 /* If we have an HBAR, "cursor_width" MAY specify height. */
2389 else if (cursor_type
== HBAR_CURSOR
)
2391 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2392 fy
+= h
- cursor_height
;
2396 r.origin.x
= fx
, r.origin.y
= fy
;
2398 r.
size.width
= w
->phys_cursor_width
;
2400 /* TODO: only needed in rare cases with last-resort font in HELLO..
2401 should we do this more efficiently? */
2402 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2405 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2406 if (face
&& NS_FACE_BACKGROUND
(face
)
2407 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2409 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2410 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2413 [FRAME_CURSOR_COLOR
(f
) set];
2415 #ifdef NS_IMPL_COCOA
2416 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2417 atomic. Cleaner ways of doing this should be investigated.
2418 One way would be to set a global variable DRAWING_CURSOR
2419 when making the call to draw_phys..(), don't focus in that
2420 case, then move the ns_unfocus() here after that call. */
2421 NSDisableScreenUpdates
();
2424 switch (cursor_type
)
2428 case FILLED_BOX_CURSOR
:
2431 case HOLLOW_BOX_CURSOR
:
2434 NSRectFill
(NSInsetRect
(r
, 1, 1));
2435 [FRAME_CURSOR_COLOR
(f
) set];
2442 /* If the character under cursor is R2L, draw the bar cursor
2443 on the right of its glyph, rather than on the left. */
2444 cursor_glyph
= get_phys_cursor_glyph
(w
);
2445 if ((cursor_glyph
->resolved_level
& 1) != 0)
2446 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2453 /* draw the character under the cursor */
2454 if (cursor_type
!= NO_CURSOR
)
2455 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2457 #ifdef NS_IMPL_COCOA
2458 NSEnableScreenUpdates
();
2465 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2466 /* --------------------------------------------------------------------------
2467 External (RIF): Draw a vertical line.
2468 -------------------------------------------------------------------------- */
2470 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2472 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2474 NSTRACE
(ns_draw_vertical_window_border
);
2476 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2478 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2480 ns_focus
(f
, &r
, 1);
2487 show_hourglass
(struct atimer
*timer
)
2489 if (hourglass_shown_p
)
2494 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2496 hourglass_shown_p
= 1;
2502 hide_hourglass
(void
)
2504 if (!hourglass_shown_p
)
2509 /* TODO: remove NSProgressIndicator from all frames */
2511 hourglass_shown_p
= 0;
2517 /* ==========================================================================
2519 Glyph drawing operations
2521 ========================================================================== */
2524 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2525 /* --------------------------------------------------------------------------
2526 Wrapper utility to account for internal border width on full-width lines,
2527 and allow top full-width rows to hit the frame top. nr should be pointer
2528 to two successive NSRects. Number of rects actually used is returned.
2529 -------------------------------------------------------------------------- */
2531 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2535 /* --------------------------------------------------------------------
2536 Draw a wavy line under glyph string s. The wave fills wave_height
2543 wave_height = 3 | * * * *
2544 --------------------------------------------------------------------- */
2547 ns_draw_underwave
(struct glyph_string
*s
, CGFloat width
, CGFloat x
)
2549 int wave_height
= 3, wave_length
= 3;
2550 int y
, dx
, dy
, odd
, xmax
;
2555 dy
= wave_height
- 1;
2559 /* Find and set clipping rectangle */
2560 waveClip
= NSMakeRect
(x
, y
, width
, wave_height
);
2561 [[NSGraphicsContext currentContext
] saveGraphicsState
];
2562 NSRectClip
(waveClip
);
2564 /* Draw the waves */
2565 a.x
= x
- ((int
)(x
) % dx);
2567 odd
= (int
)(a.x
/dx
) % 2;
2577 [NSBezierPath strokeLineFromPoint
:a toPoint
:b
];
2578 a.x
= b.x
, a.y
= b.y
;
2579 b.x
+= dx
, b.y
= y
+ odd
*dy
;
2583 /* Restore previous clipping rectangle(s) */
2584 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
2590 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2591 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2592 /* --------------------------------------------------------------------------
2593 Draw underline, overline, and strike-through on glyph string s.
2594 -------------------------------------------------------------------------- */
2596 if (s
->for_overlaps
)
2600 if (face
->underline_p
)
2602 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2604 if (face
->underline_defaulted_p
)
2607 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2609 ns_draw_underwave
(s
, width
, x
);
2611 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2615 unsigned
long thickness
, position
;
2617 /* If the prev was underlined, match its appearance. */
2618 if (s
->prev
&& s
->prev
->face
->underline_p
2619 && s
->prev
->underline_thickness
> 0)
2621 thickness
= s
->prev
->underline_thickness
;
2622 position
= s
->prev
->underline_position
;
2627 unsigned
long descent
;
2630 descent
= s
->y
+ s
->height
- s
->ybase
;
2632 /* Use underline thickness of font, defaulting to 1. */
2633 thickness
= (font
&& font
->underline_thickness
> 0)
2634 ? font
->underline_thickness
: 1;
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
;
2643 position
= lround
(font
->descent
/ 2);
2645 position
= underline_minimum_offset
;
2647 position
= max (position
, underline_minimum_offset
);
2649 /* Ensure underlining is not cropped. */
2650 if (descent
<= position
)
2652 position
= descent
- 1;
2655 else if (descent
< position
+ thickness
)
2659 s
->underline_thickness
= thickness
;
2660 s
->underline_position
= position
;
2662 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2664 if (face
->underline_defaulted_p
)
2667 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2671 /* Do overline. We follow other terms in using a thickness of 1
2672 and ignoring overline_margin. */
2673 if (face
->overline_p
)
2676 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2678 if (face
->overline_color_defaulted_p
)
2681 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2685 /* Do strike-through. We follow other terms for thickness and
2686 vertical position.*/
2687 if (face
->strike_through_p
)
2692 dy
= lrint
((s
->height
- 1) / 2);
2693 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2695 if (face
->strike_through_color_defaulted_p
)
2698 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2704 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2705 /* --------------------------------------------------------------------------
2706 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2707 Note we can't just use an NSDrawRect command, because of the possibility
2708 of some sides not being drawn, and because the rect will be filled.
2709 -------------------------------------------------------------------------- */
2715 s.
size.height
= thickness
;
2717 s.origin.y
+= r.
size.height
- thickness
;
2720 s.
size.height
= r.
size.height
;
2721 s.origin.y
= r.origin.y
;
2723 /* left, right (optional) */
2724 s.
size.width
= thickness
;
2729 s.origin.x
+= r.
size.width
- thickness
;
2736 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2737 char top_p
, char bottom_p
, char left_p
, char right_p
,
2738 struct glyph_string
*s
)
2739 /* --------------------------------------------------------------------------
2740 Draw a relief rect inside r, optionally leaving some sides open.
2741 Note we can't just use an NSDrawBezel command, because of the possibility
2742 of some sides not being drawn, and because the rect will be filled.
2743 -------------------------------------------------------------------------- */
2745 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2746 NSColor
*newBaseCol
= nil
;
2749 NSTRACE
(ns_draw_relief
);
2753 if (s
->face
->use_box_color_for_shadows_p
)
2755 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2757 /* else if (s->first_glyph->type == IMAGE_GLYPH
2759 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2761 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2765 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2768 if (newBaseCol
== nil
)
2769 newBaseCol
= [NSColor grayColor
];
2771 if (newBaseCol
!= baseCol
) /* TODO: better check */
2774 baseCol
= [newBaseCol retain
];
2776 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2778 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2781 [(raised_p ? lightCol
: darkCol
) set];
2783 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2786 sr.
size.height
= thickness
;
2787 if (top_p
) NSRectFill
(sr
);
2790 sr.
size.height
= r.
size.height
;
2791 sr.
size.width
= thickness
;
2792 if (left_p
) NSRectFill
(sr
);
2794 [(raised_p ? darkCol
: lightCol
) set];
2797 sr.
size.width
= r.
size.width
;
2798 sr.
size.height
= thickness
;
2799 sr.origin.y
+= r.
size.height
- thickness
;
2800 if (bottom_p
) NSRectFill
(sr
);
2803 sr.
size.height
= r.
size.height
;
2804 sr.origin.y
= r.origin.y
;
2805 sr.
size.width
= thickness
;
2806 sr.origin.x
+= r.
size.width
- thickness
;
2807 if (right_p
) NSRectFill
(sr
);
2812 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2813 /* --------------------------------------------------------------------------
2814 Function modeled after x_draw_glyph_string_box ().
2815 Sets up parameters for drawing.
2816 -------------------------------------------------------------------------- */
2818 int right_x
, last_x
;
2819 char left_p
, right_p
;
2820 struct glyph
*last_glyph
;
2825 if (s
->hl
== DRAW_MOUSE_FACE
)
2827 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2829 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2834 thickness
= face
->box_line_width
;
2836 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2838 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2839 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2840 : window_box_right
(s
->w
, s
->area
));
2841 last_glyph
= (s
->cmp || s
->img
2842 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2844 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2845 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2847 left_p
= (s
->first_glyph
->left_box_line_p
2848 ||
(s
->hl
== DRAW_MOUSE_FACE
2849 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2850 right_p
= (last_glyph
->right_box_line_p
2851 ||
(s
->hl
== DRAW_MOUSE_FACE
2852 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2854 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2856 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2857 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2859 ns_draw_box
(r
, abs (thickness
),
2860 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2865 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2866 1, 1, left_p
, right_p
, s
);
2872 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2873 /* --------------------------------------------------------------------------
2874 Modeled after x_draw_glyph_string_background, which draws BG in
2875 certain cases. Others are left to the text rendering routine.
2876 -------------------------------------------------------------------------- */
2878 NSTRACE
(ns_maybe_dumpglyphs_background
);
2880 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2882 int box_line_width
= max (s
->face
->box_line_width
, 0);
2883 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2884 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2887 if (s
->hl
== DRAW_MOUSE_FACE
)
2889 face
= FACE_FROM_ID
(s
->f
,
2890 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2892 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2895 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2897 [(NS_FACE_BACKGROUND
(face
) != 0
2898 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2899 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2902 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2903 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2906 if (s
->hl
!= DRAW_CURSOR
)
2908 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2909 s
->background_width
,
2910 s
->height
-2*box_line_width
);
2914 s
->background_filled_p
= 1;
2921 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2922 /* --------------------------------------------------------------------------
2923 Renders an image and associated borders.
2924 -------------------------------------------------------------------------- */
2926 EmacsImage
*img
= s
->img
->pixmap
;
2927 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2928 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2929 int bg_x
, bg_y
, bg_height
;
2936 NSTRACE
(ns_dumpglyphs_image
);
2938 if (s
->face
->box
!= FACE_NO_BOX
2939 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
2940 x
+= abs (s
->face
->box_line_width
);
2943 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
2944 bg_height
= s
->height
;
2945 /* other terms have this, but was causing problems w/tabbar mode */
2946 /* - 2 * box_line_vwidth; */
2948 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
2949 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
2951 /* Draw BG: if we need larger area than image itself cleared, do that,
2952 otherwise, since we composite the image under NS (instead of mucking
2953 with its background color), we must clear just the image area. */
2954 if (s
->hl
== DRAW_MOUSE_FACE
)
2956 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2958 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2961 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2963 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
2965 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
2966 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
2968 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
2969 s
->background_filled_p
= 1;
2973 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
2978 /* Draw the image.. do we need to draw placeholder if img ==nil? */
2981 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
2983 fromRect
: NSZeroRect
2984 operation
: NSCompositeSourceOver
2989 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
2990 operation
: NSCompositeSourceOver
];
2994 if (s
->hl
== DRAW_CURSOR
)
2996 [FRAME_CURSOR_COLOR
(s
->f
) set];
2997 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
2998 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3000 /* Currently on NS img->mask is always 0. Since
3001 get_window_cursor_type specifies a hollow box cursor when on
3002 a non-masked image we never reach this clause. But we put it
3003 in in anticipation of better support for image masks on
3005 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3009 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3012 /* Draw underline, overline, strike-through. */
3013 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3015 /* Draw relief, if requested */
3016 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3018 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3020 th
= tool_bar_button_relief
>= 0 ?
3021 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3022 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3026 th
= abs (s
->img
->relief
);
3027 raised_p
= (s
->img
->relief
> 0);
3030 r.origin.x
= x
- th
;
3031 r.origin.y
= y
- th
;
3032 r.
size.width
= s
->slice.width
+ 2*th
-1;
3033 r.
size.height
= s
->slice.height
+ 2*th
-1;
3034 ns_draw_relief
(r
, th
, raised_p
,
3036 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3038 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3041 /* If there is no mask, the background won't be seen,
3042 so draw a rectangle on the image for the cursor.
3043 Do this for all images, getting transparency right is not reliable. */
3044 if (s
->hl
== DRAW_CURSOR
)
3046 int thickness
= abs (s
->img
->relief
);
3047 if (thickness
== 0) thickness
= 1;
3048 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3054 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3059 NSColor
*fgCol
, *bgCol
;
3061 if (!s
->background_filled_p
)
3063 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3064 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3066 ns_focus
(s
->f
, r
, n
);
3068 if (s
->hl
== DRAW_MOUSE_FACE
)
3070 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3072 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3075 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3077 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3078 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3080 for (i
= 0; i
< n
; ++i
)
3082 if (!s
->row
->full_width_p
)
3084 int overrun
, leftoverrun
;
3086 /* truncate to avoid overwriting fringe and/or scrollbar */
3087 overrun
= max (0, (s
->x
+ s
->background_width
)
3088 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3089 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3090 r
[i
].
size.width
-= overrun
;
3092 /* truncate to avoid overwriting to left of the window box */
3093 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3094 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3096 if (leftoverrun
> 0)
3098 r
[i
].origin.x
+= leftoverrun
;
3099 r
[i
].
size.width
-= leftoverrun
;
3102 /* XXX: Try to work between problem where a stretch glyph on
3103 a partially-visible bottom row will clear part of the
3104 modeline, and another where list-buffers headers and similar
3105 rows erroneously have visible_height set to 0. Not sure
3106 where this is coming from as other terms seem not to show. */
3107 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3112 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3113 overwriting cursor (usually when cursor on a tab) */
3114 if (s
->hl
== DRAW_CURSOR
)
3119 width
= s
->w
->phys_cursor_width
;
3120 r
[i
].
size.width
-= width
;
3121 r
[i
].origin.x
+= width
;
3125 /* Draw overlining, etc. on the cursor. */
3126 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3127 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3129 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3136 /* Draw overlining, etc. on the stretch glyph (or the part
3137 of the stretch glyph after the cursor). */
3138 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3142 s
->background_filled_p
= 1;
3148 ns_draw_glyph_string
(struct glyph_string
*s
)
3149 /* --------------------------------------------------------------------------
3150 External (RIF): Main draw-text call.
3151 -------------------------------------------------------------------------- */
3153 /* TODO (optimize): focus for box and contents draw */
3156 char box_drawn_p
= 0;
3158 NSTRACE
(ns_draw_glyph_string
);
3160 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3163 struct glyph_string
*next
;
3165 for (width
= 0, next
= s
->next
;
3166 next
&& width
< s
->right_overhang
;
3167 width
+= next
->width
, next
= next
->next
)
3168 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3170 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3172 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3173 ns_focus
(s
->f
, r
, n
);
3174 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3179 ns_dumpglyphs_stretch
(s
->next
);
3181 next
->num_clips
= 0;
3185 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3186 && (s
->first_glyph
->type == CHAR_GLYPH
3187 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3189 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3190 ns_focus
(s
->f
, r
, n
);
3191 ns_maybe_dumpglyphs_background
(s
, 1);
3192 ns_dumpglyphs_box_or_relief
(s
);
3197 switch (s
->first_glyph
->type)
3201 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3202 ns_focus
(s
->f
, r
, n
);
3203 ns_dumpglyphs_image
(s
, r
[0]);
3208 ns_dumpglyphs_stretch
(s
);
3212 case COMPOSITE_GLYPH
:
3213 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3214 ns_focus
(s
->f
, r
, n
);
3216 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3217 && ! s
->first_glyph
->u.cmp.automatic
))
3218 s
->background_filled_p
= 1;
3220 ns_maybe_dumpglyphs_background
3221 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3223 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3224 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3225 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3226 NS_DUMPGLYPH_NORMAL
));
3227 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3228 if (ns_tmp_font
== NULL)
3229 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3231 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3233 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3234 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3235 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3238 ns_tmp_font
->font.driver
->draw
3239 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3240 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3241 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
3243 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3245 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3246 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3247 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3253 case GLYPHLESS_GLYPH
:
3254 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3255 ns_focus
(s
->f
, r
, n
);
3257 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3258 && ! s
->first_glyph
->u.cmp.automatic
))
3259 s
->background_filled_p
= 1;
3261 ns_maybe_dumpglyphs_background
3262 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3264 /* Not yet implemented. */
3273 /* Draw box if not done already. */
3274 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3276 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3277 ns_focus
(s
->f
, r
, n
);
3278 ns_dumpglyphs_box_or_relief
(s
);
3287 /* ==========================================================================
3291 ========================================================================== */
3295 ns_send_appdefined
(int value
)
3296 /* --------------------------------------------------------------------------
3297 Internal: post an appdefined event which EmacsApp-sendEvent will
3298 recognize and take as a command to halt the event loop.
3299 -------------------------------------------------------------------------- */
3301 /*NSTRACE (ns_send_appdefined); */
3303 /* Only post this event if we haven't already posted one. This will end
3304 the [NXApp run] main loop after having processed all events queued at
3306 if (send_appdefined
)
3310 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3311 send_appdefined
= NO
;
3313 /* Don't need wakeup timer any more */
3316 [timed_entry invalidate
];
3317 [timed_entry release
];
3321 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3322 location
: NSMakePoint
(0, 0)
3325 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3326 context
: [NSApp context
]
3331 /* Post an application defined event on the event queue. When this is
3332 received the [NXApp run] will return, thus having processed all
3333 events which are currently queued. */
3334 [NSApp postEvent
: nxev atStart
: NO
];
3339 ns_read_socket
(struct terminal *terminal, struct input_event
*hold_quit
)
3340 /* --------------------------------------------------------------------------
3341 External (hook): Post an event to ourself and keep reading events until
3342 we read it back again. In effect process all events which were waiting.
3343 From 21+ we have to manage the event buffer ourselves.
3344 -------------------------------------------------------------------------- */
3346 struct input_event ev
;
3349 /* NSTRACE (ns_read_socket); */
3351 if ([NSApp modalWindow
] != nil
)
3354 if (interrupt_input_blocked
)
3356 interrupt_input_pending
= 1;
3357 pending_signals
= 1;
3361 interrupt_input_pending
= 0;
3362 pending_signals
= pending_atimers
;
3365 n_emacs_events_pending
= 0;
3368 q_event_ptr
= hold_quit
;
3370 /* we manage autorelease pools by allocate/reallocate each time around
3371 the loop; strict nesting is occasionally violated but seems not to
3372 matter.. earlier methods using full nesting caused major memory leaks */
3373 [outerpool release
];
3374 outerpool
= [[NSAutoreleasePool alloc
] init
];
3376 /* If have pending open-file requests, attend to the next one of those. */
3377 if (ns_pending_files
&& [ns_pending_files count
] != 0
3378 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3380 [ns_pending_files removeObjectAtIndex
: 0];
3382 /* Deal with pending service requests. */
3383 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3385 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3386 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3388 [ns_pending_service_names removeObjectAtIndex
: 0];
3389 [ns_pending_service_args removeObjectAtIndex
: 0];
3393 /* Run and wait for events. We must always send one NX_APPDEFINED event
3394 to ourself, otherwise [NXApp run] will never exit. */
3395 send_appdefined
= YES
;
3396 ns_send_appdefined
(-1);
3398 if (++apploopnr
!= 1)
3406 nevents
= n_emacs_events_pending
;
3407 n_emacs_events_pending
= 0;
3408 emacs_event
= q_event_ptr
= NULL;
3416 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3417 fd_set
*exceptfds
, EMACS_TIME
*timeout
, sigset_t
*sigmask
)
3418 /* --------------------------------------------------------------------------
3419 Replacement for select, checking for events
3420 -------------------------------------------------------------------------- */
3425 struct input_event event
;
3428 /* NSTRACE (ns_select); */
3430 for (k
= 0; readfds
&& k
< nfds
+1; k
++)
3431 if (FD_ISSET
(k
, readfds
)) ++nr
;
3434 ||
(timeout
&& timeout
->tv_sec
== 0 && timeout
->tv_nsec
== 0))
3435 return pselect
(nfds
, readfds
, writefds
, exceptfds
, timeout
, sigmask
);
3437 [outerpool release
];
3438 outerpool
= [[NSAutoreleasePool alloc
] init
];
3441 send_appdefined
= YES
;
3444 pthread_mutex_lock
(&select_mutex
);
3449 select_readfds
= *readfds
;
3450 select_valid
+= SELECT_HAVE_READ
;
3454 select_writefds
= *writefds
;
3455 select_valid
+= SELECT_HAVE_WRITE
;
3460 select_timeout
= *timeout
;
3461 select_valid
+= SELECT_HAVE_TMO
;
3464 pthread_mutex_unlock
(&select_mutex
);
3466 /* Inform fd_handler that select should be called */
3468 write
(selfds
[1], &c
, 1);
3470 else if (nr
== 0 && timeout
)
3472 /* No file descriptor, just a timeout, no need to wake fd_handler */
3473 double time
= EMACS_TIME_TO_DOUBLE
(*timeout
);
3474 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3477 @selector
(timeout_handler
:)
3482 else /* No timeout and no file descriptors, can this happen? */
3484 /* Send appdefined so we exit from the loop */
3485 ns_send_appdefined
(-1);
3490 emacs_event
= &event
;
3491 if (++apploopnr
!= 1)
3498 if (nr
> 0 && readfds
)
3501 write
(selfds
[1], &c
, 1);
3505 ev
= last_appdefined_event
;
3510 if ([ev
type] != NSApplicationDefined
)
3514 last_appdefined_event
= 0;
3518 /* The NX_APPDEFINED event we received was a timeout. */
3523 /* The NX_APPDEFINED event we received was the result of
3524 at least one real input event arriving. */
3530 /* Received back from select () in fd_handler; copy the results */
3531 pthread_mutex_lock
(&select_mutex
);
3532 if (readfds
) *readfds
= select_readfds
;
3533 if (writefds
) *writefds
= select_writefds
;
3534 if (timeout
) *timeout
= select_timeout
;
3535 pthread_mutex_unlock
(&select_mutex
);
3545 /* ==========================================================================
3549 ========================================================================== */
3553 ns_set_vertical_scroll_bar
(struct window
*window
,
3554 int portion
, int whole
, int position
)
3555 /* --------------------------------------------------------------------------
3556 External (hook): Update or add scrollbar
3557 -------------------------------------------------------------------------- */
3561 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3562 EmacsView
*view = FRAME_NS_VIEW
(f
);
3563 int window_y
, window_height
;
3564 int top
, left
, height
, width
, sb_width
, sb_left
;
3566 BOOL fringe_extended_p
;
3568 /* optimization; display engine sends WAY too many of these.. */
3569 if (!NILP
(window
->vertical_scroll_bar
))
3571 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3572 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3574 if (view->scrollbarsNeedingUpdate
== 0)
3576 if (!windows_or_buffers_changed
)
3580 view->scrollbarsNeedingUpdate
--;
3584 NSTRACE
(ns_set_vertical_scroll_bar
);
3586 /* Get dimensions. */
3587 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3589 height
= window_height
;
3590 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3591 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3593 /* allow for displaying a skinnier scrollbar than char area allotted */
3594 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3595 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3598 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3599 /* the parent view is flipped, so we need to flip y value */
3601 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3603 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(window
))
3604 fringe_extended_p
= (WINDOW_LEFTMOST_P
(window
)
3605 && WINDOW_LEFT_FRINGE_WIDTH
(window
)
3606 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3607 || WINDOW_LEFT_MARGIN_COLS
(window
) == 0));
3609 fringe_extended_p
= (WINDOW_RIGHTMOST_P
(window
)
3610 && WINDOW_RIGHT_FRINGE_WIDTH
(window
)
3611 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3612 || WINDOW_RIGHT_MARGIN_COLS
(window
) == 0));
3614 XSETWINDOW
(win
, window
);
3617 /* we want at least 5 lines to display a scrollbar */
3618 if (WINDOW_TOTAL_LINES
(window
) < 5)
3620 if (!NILP
(window
->vertical_scroll_bar
))
3622 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3623 [bar removeFromSuperview
];
3624 wset_vertical_scroll_bar
(window
, Qnil
);
3626 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3631 if (NILP
(window
->vertical_scroll_bar
))
3633 if (width
> 0 && height
> 0)
3635 if (fringe_extended_p
)
3636 ns_clear_frame_area
(f
, sb_left
, top
, sb_width
, height
);
3638 ns_clear_frame_area
(f
, left
, top
, width
, height
);
3641 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3642 wset_vertical_scroll_bar
(window
, make_save_value
(bar, 0));
3647 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3648 oldRect
= [bar frame
];
3649 r.
size.width
= oldRect.
size.width
;
3650 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3652 if (oldRect.origin.x
!= r.origin.x
)
3653 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3658 [bar setPosition
: position portion
: portion whole
: whole
];
3664 ns_condemn_scroll_bars
(struct frame
*f
)
3665 /* --------------------------------------------------------------------------
3666 External (hook): arrange for all frame's scrollbars to be removed
3667 at next call to judge_scroll_bars, except for those redeemed.
3668 -------------------------------------------------------------------------- */
3672 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3674 NSTRACE
(ns_condemn_scroll_bars
);
3676 for (i
=[subviews count
]-1; i
>= 0; i
--)
3678 view = [subviews objectAtIndex
: i
];
3679 if ([view isKindOfClass
: [EmacsScroller
class]])
3686 ns_redeem_scroll_bar
(struct window
*window
)
3687 /* --------------------------------------------------------------------------
3688 External (hook): arrange to spare this window's scrollbar
3689 at next call to judge_scroll_bars.
3690 -------------------------------------------------------------------------- */
3693 NSTRACE
(ns_redeem_scroll_bar
);
3694 if (!NILP
(window
->vertical_scroll_bar
))
3696 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3703 ns_judge_scroll_bars
(struct frame
*f
)
3704 /* --------------------------------------------------------------------------
3705 External (hook): destroy all scrollbars on frame that weren't
3706 redeemed after call to condemn_scroll_bars.
3707 -------------------------------------------------------------------------- */
3711 EmacsView
*eview
= FRAME_NS_VIEW
(f
);
3712 NSArray
*subviews
= [[eview superview
] subviews
];
3715 NSTRACE
(ns_judge_scroll_bars
);
3716 for (i
= [subviews count
]-1; i
>= 0; --i
)
3718 view = [subviews objectAtIndex
: i
];
3719 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3725 [eview updateFrameSize
: NO
];
3730 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3732 /* XXX irrelevant under NS */
3737 /* ==========================================================================
3741 ========================================================================== */
3744 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3746 NSScreen
*screen
= [NSScreen mainScreen
];
3747 return [screen frame
].
size.height
;
3751 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3753 NSScreen
*screen
= [NSScreen mainScreen
];
3754 return [screen frame
].
size.width
;
3758 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3759 /* --------------------------------------------------------------------------
3760 Convert modifier name to lisp symbol
3761 -------------------------------------------------------------------------- */
3763 if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3765 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3767 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3769 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3771 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3773 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3781 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3782 Lisp_Object yesval
, Lisp_Object noval
,
3783 BOOL is_float
, BOOL is_modstring
)
3784 /* --------------------------------------------------------------------------
3785 Check a parameter value in user's preferences
3786 -------------------------------------------------------------------------- */
3788 const
char *value
= ns_get_defaults_value
(parameter
);
3794 if (c_strcasecmp
(value
, "YES"
) == 0)
3796 else if (c_strcasecmp
(value
, "NO"
) == 0)
3798 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3799 *result
= make_float
(f
);
3800 else if (is_modstring
&& value
)
3801 *result
= ns_string_to_lispmod
(value
);
3802 else fprintf (stderr
,
3803 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3809 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3810 /* --------------------------------------------------------------------------
3811 Initialize global info and storage for display.
3812 -------------------------------------------------------------------------- */
3814 NSScreen
*screen
= [NSScreen mainScreen
];
3815 NSWindowDepth depth
= [screen depth
];
3816 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
3818 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3819 dpyinfo
->resy
= 72.27;
3820 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3821 NSColorSpaceFromDepth
(depth
)]
3822 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3823 NSColorSpaceFromDepth
(depth
)];
3824 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3825 dpyinfo
->image_cache
= make_image_cache
();
3826 dpyinfo
->color_table
= xmalloc
(sizeof
*dpyinfo
->color_table
);
3827 dpyinfo
->color_table
->colors
= NULL;
3828 dpyinfo
->root_window
= 42; /* a placeholder.. */
3830 hlinfo
->mouse_face_mouse_frame
= NULL;
3831 hlinfo
->mouse_face_deferred_gc
= 0;
3832 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
3833 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
3834 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3835 hlinfo
->mouse_face_window
= hlinfo
->mouse_face_overlay
= Qnil
;
3836 hlinfo
->mouse_face_hidden
= 0;
3838 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
3839 hlinfo
->mouse_face_defer
= 0;
3841 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3843 dpyinfo
->n_fonts
= 0;
3844 dpyinfo
->smallest_font_height
= 1;
3845 dpyinfo
->smallest_char_width
= 1;
3849 /* This and next define (many of the) public functions in this file. */
3850 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3851 with using despite presence in the "system dependent" redisplay
3852 interface. In addition, many of the ns_ methods have code that is
3853 shared with all terms, indicating need for further refactoring. */
3854 extern frame_parm_handler ns_frame_parm_handlers
[];
3855 static
struct redisplay_interface ns_redisplay_interface
=
3857 ns_frame_parm_handlers
,
3861 x_clear_end_of_line
,
3863 ns_after_update_window_line
,
3864 ns_update_window_begin
,
3865 ns_update_window_end
,
3868 0, /* flush_display_optional */
3869 x_clear_window_mouse_face
,
3870 x_get_glyph_overhangs
,
3871 x_fix_overlapping_area
,
3872 ns_draw_fringe_bitmap
,
3873 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3874 0, /* destroy_fringe_bitmap */
3875 ns_compute_glyph_string_overhangs
,
3876 ns_draw_glyph_string
, /* interface to nsfont.m */
3877 ns_define_frame_cursor
,
3878 ns_clear_frame_area
,
3879 ns_draw_window_cursor
,
3880 ns_draw_vertical_window_border
,
3881 ns_shift_glyphs_for_insert
3886 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3892 /* This function is called when the last frame on a display is deleted. */
3894 ns_delete_terminal
(struct terminal *terminal)
3896 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3898 /* Protect against recursive calls. delete_frame in
3899 delete_terminal calls us back when it deletes our last frame. */
3900 if (!terminal->name
)
3905 x_destroy_all_bitmaps
(dpyinfo
);
3906 ns_delete_display
(dpyinfo
);
3911 static
struct terminal *
3912 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3913 /* --------------------------------------------------------------------------
3914 Set up use of NS before we make the first connection.
3915 -------------------------------------------------------------------------- */
3917 struct terminal *terminal;
3919 NSTRACE
(ns_create_terminal
);
3921 terminal = create_terminal
();
3923 terminal->type = output_ns
;
3924 terminal->display_info.ns
= dpyinfo
;
3925 dpyinfo
->terminal = terminal;
3927 terminal->rif
= &ns_redisplay_interface
;
3929 terminal->clear_frame_hook
= ns_clear_frame
;
3930 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
3931 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
3932 terminal->ring_bell_hook
= ns_ring_bell
;
3933 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
3934 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
3935 terminal->update_begin_hook
= ns_update_begin
;
3936 terminal->update_end_hook
= ns_update_end
;
3937 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
3938 terminal->read_socket_hook
= ns_read_socket
;
3939 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
3940 terminal->mouse_position_hook
= ns_mouse_position
;
3941 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
3942 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
3944 terminal->fullscreen_hook
= 0; /* see XTfullscreen_hook */
3946 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
3947 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
3948 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
3949 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
3951 terminal->delete_frame_hook
= x_destroy_window
;
3952 terminal->delete_terminal_hook
= ns_delete_terminal
;
3954 terminal->scroll_region_ok
= 1;
3955 terminal->char_ins_del_ok
= 1;
3956 terminal->line_ins_del_ok
= 1;
3957 terminal->fast_clear_end_of_line
= 1;
3958 terminal->memory_below_frame
= 0;
3964 struct ns_display_info
*
3965 ns_term_init
(Lisp_Object display_name
)
3966 /* --------------------------------------------------------------------------
3967 Start the Application and get things rolling.
3968 -------------------------------------------------------------------------- */
3970 struct terminal *terminal;
3971 struct ns_display_info
*dpyinfo
;
3972 static int ns_initialized
= 0;
3975 if (ns_initialized
) return x_display_list
;
3978 NSTRACE
(ns_term_init
);
3980 [outerpool release
];
3981 outerpool
= [[NSAutoreleasePool alloc
] init
];
3983 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
3984 /*GSDebugAllocationActive (YES); */
3988 Fset_input_interrupt_mode
(Qnil
);
3990 if (selfds
[0] == -1)
3992 if (pipe
(selfds
) == -1)
3994 fprintf (stderr
, "Failed to create pipe
: %s\n",
3995 emacs_strerror
(errno
));
3999 fcntl
(selfds
[0], F_SETFL
, O_NONBLOCK|fcntl
(selfds
[0], F_GETFL
));
4000 FD_ZERO
(&select_readfds
);
4001 FD_ZERO
(&select_writefds
);
4002 pthread_mutex_init
(&select_mutex
, NULL);
4005 ns_pending_files
= [[NSMutableArray alloc
] init
];
4006 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
4007 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
4009 /* Start app and create the main menu, window, view.
4010 Needs to be here because ns_initialize_display_info () uses AppKit classes.
4011 The view will then ask the NSApp to stop and return to Emacs. */
4012 [EmacsApp sharedApplication
];
4015 [NSApp setDelegate
: NSApp
];
4017 /* Start the select thread. */
4018 [NSThread detachNewThreadSelector
:@selector
(fd_handler
:)
4022 /* debugging: log all notifications */
4023 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4024 selector: @selector (logNotification:)
4025 name: nil object: nil]; */
4027 dpyinfo
= xzalloc
(sizeof
*dpyinfo
);
4029 ns_initialize_display_info
(dpyinfo
);
4030 terminal = ns_create_terminal
(dpyinfo
);
4032 terminal->kboard
= xmalloc
(sizeof
*terminal->kboard
);
4033 init_kboard
(terminal->kboard
);
4034 kset_window_system
(terminal->kboard
, Qns
);
4035 terminal->kboard
->next_kboard
= all_kboards
;
4036 all_kboards
= terminal->kboard
;
4037 /* Don't let the initial kboard remain current longer than necessary.
4038 That would cause problems if a file loaded on startup tries to
4039 prompt in the mini-buffer. */
4040 if (current_kboard
== initial_kboard
)
4041 current_kboard
= terminal->kboard
;
4042 terminal->kboard
->reference_count
++;
4044 dpyinfo
->next
= x_display_list
;
4045 x_display_list
= dpyinfo
;
4047 /* Put it on ns_display_name_list */
4048 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
4049 ns_display_name_list
);
4050 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
4052 terminal->name
= xstrdup
(SSDATA
(display_name
));
4056 if (!inhibit_x_resources
)
4058 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4061 /* this is a standard variable */
4062 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4063 make_float
(10.0), make_float
(6.0), YES
, NO
);
4064 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4067 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
4068 stringForKey
: @"AppleHighlightColor"
];
4069 if (ns_selection_color
== nil
)
4070 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
4073 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4077 Lisp_Object color_file
, color_map
, color
;
4081 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4082 Fsymbol_value
(intern
("data
-directory"
)));
4083 if (NILP
(Ffile_readable_p
(color_file
)))
4084 fatal
("Could not
find %s.\n", SDATA (color_file));
4086 color_map
= Fx_load_color_file
(color_file
);
4087 if (NILP
(color_map
))
4088 fatal
("Could not read
%s.\n", SDATA (color_file));
4090 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4091 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4093 color
= XCAR
(color_map
);
4094 name
= SSDATA
(XCAR
(color
));
4095 c
= XINT
(XCDR
(color
));
4097 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4098 green
: GREEN_FROM_ULONG
(c
) / 255.0
4099 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4101 forKey
: [NSString stringWithUTF8String
: name
]];
4103 [cl writeToFile
: nil
];
4108 #ifdef NS_IMPL_GNUSTEP
4109 Vwindow_system_version
= build_string
(gnustep_base_version
);
4111 /*PSnextrelease (128, c); */
4112 char c
[DBL_BUFSIZE_BOUND
];
4113 int len
= dtoastr
(c
, sizeof c
, 0, 0, NSAppKitVersionNumber
);
4114 Vwindow_system_version
= make_unibyte_string
(c
, len
);
4118 delete_keyboard_wait_descriptor
(0);
4120 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4122 /* Set up OS X app menu */
4123 #ifdef NS_IMPL_COCOA
4127 /* set up the application menu */
4128 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4129 [svcsMenu setAutoenablesItems
: NO
];
4130 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4131 [appMenu setAutoenablesItems
: NO
];
4132 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4133 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4135 [appMenu insertItemWithTitle
: @"About Emacs"
4136 action
: @selector
(orderFrontStandardAboutPanel
:)
4139 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4140 [appMenu insertItemWithTitle
: @"Preferences..."
4141 action
: @selector
(showPreferencesWindow
:)
4144 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4145 item
= [appMenu insertItemWithTitle
: @"Services"
4146 action
: @selector
(menuDown
:)
4149 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4150 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4151 [appMenu insertItemWithTitle
: @"Hide Emacs"
4152 action
: @selector
(hide
:)
4155 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4156 action
: @selector
(hideOtherApplications
:)
4159 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4160 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4161 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4162 action
: @selector
(terminate
:)
4166 item
= [mainMenu insertItemWithTitle
: ns_app_name
4167 action
: @selector
(menuDown
:)
4170 [mainMenu setSubmenu
: appMenu forItem
: item
];
4171 [dockMenu insertItemWithTitle
: @"New Frame"
4172 action
: @selector
(newFrame
:)
4176 [NSApp setMainMenu
: mainMenu
];
4177 [NSApp setAppleMenu
: appMenu
];
4178 [NSApp setServicesMenu
: svcsMenu
];
4179 /* Needed at least on Cocoa, to get dock menu to show windows */
4180 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4182 [[NSNotificationCenter defaultCenter
]
4183 addObserver
: mainMenu
4184 selector
: @selector
(trackingNotification
:)
4185 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4186 [[NSNotificationCenter defaultCenter
]
4187 addObserver
: mainMenu
4188 selector
: @selector
(trackingNotification
:)
4189 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4191 #endif
/* MAC OS X menu setup */
4193 /* Register our external input/output types, used for determining
4194 applicable services and also drag/drop eligibility. */
4195 ns_send_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
] retain
];
4196 ns_return_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
]
4198 ns_drag_types
= [[NSArray arrayWithObjects
:
4200 NSTabularTextPboardType
,
4201 NSFilenamesPboardType
,
4204 NSFontPboardType
, nil
] retain
];
4208 ns_do_open_file
= YES
;
4214 ns_term_shutdown
(int sig
)
4216 [[NSUserDefaults standardUserDefaults
] synchronize
];
4218 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4219 if (STRINGP
(Vauto_save_list_file_name
))
4220 unlink
(SSDATA
(Vauto_save_list_file_name
));
4222 if (sig
== 0 || sig
== SIGTERM
)
4224 [NSApp terminate
: NSApp
];
4226 else // force a stack
trace to happen
4233 /* ==========================================================================
4235 EmacsApp implementation
4237 ========================================================================== */
4240 @implementation EmacsApp
4242 - (void
)logNotification
: (NSNotification
*)notification
4244 const
char *name
= [[notification name
] UTF8String
];
4245 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4246 && !strstr
(name
, "WindowNumber"
))
4247 NSLog
(@"notification
: '%@'"
, [notification name
]);
4251 - (void
)sendEvent
: (NSEvent
*)theEvent
4252 /* --------------------------------------------------------------------------
4253 Called when NSApp is running for each event received. Used to stop
4254 the loop when we choose, since there's no way to just run one iteration.
4255 -------------------------------------------------------------------------- */
4257 int
type = [theEvent
type];
4258 NSWindow
*window
= [theEvent window
];
4259 /* NSTRACE (sendEvent); */
4260 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4262 #ifdef NS_IMPL_COCOA
4263 if (type == NSApplicationDefined
4264 && [theEvent data2
] == NSAPP_DATA2_RUNASSCRIPT
)
4272 if (type == NSCursorUpdate
&& window
== nil
)
4274 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4278 #ifdef NS_IMPL_COCOA
4279 /* pass mouse down in resize handle and subsequent drags directly to
4280 EmacsWindow so we can generate continuous redisplays */
4283 if (type == NSLeftMouseDragged
)
4285 [window mouseDragged
: theEvent
];
4288 else if (type == NSLeftMouseUp
)
4290 [window mouseUp
: theEvent
];
4294 else if (type == NSLeftMouseDown
)
4296 NSRect r
= ns_resize_handle_rect
(window
);
4297 if (NSPointInRect
([theEvent locationInWindow
], r
))
4300 [window mouseDown
: theEvent
];
4306 if (type == NSApplicationDefined
)
4308 /* Events posted by ns_send_appdefined interrupt the run loop here.
4309 But, if a modal window is up, an appdefined can still come through,
4310 (e.g., from a makeKeyWindow event) but stopping self also stops the
4311 modal loop. Just defer it until later. */
4312 if ([NSApp modalWindow
] == nil
)
4314 last_appdefined_event
= theEvent
;
4319 send_appdefined
= YES
;
4323 [super sendEvent
: theEvent
];
4327 - (void
)showPreferencesWindow
: (id
)sender
4329 struct frame
*emacsframe
= SELECTED_FRAME
();
4330 NSEvent
*theEvent
= [NSApp currentEvent
];
4334 emacs_event
->kind
= NS_NONKEY_EVENT
;
4335 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4336 emacs_event
->modifiers
= 0;
4337 EV_TRAILER
(theEvent
);
4341 - (void
)newFrame
: (id
)sender
4343 struct frame
*emacsframe
= SELECTED_FRAME
();
4344 NSEvent
*theEvent
= [NSApp currentEvent
];
4348 emacs_event
->kind
= NS_NONKEY_EVENT
;
4349 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4350 emacs_event
->modifiers
= 0;
4351 EV_TRAILER
(theEvent
);
4355 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4356 - (BOOL
) openFile
: (NSString
*)fileName
4358 struct frame
*emacsframe
= SELECTED_FRAME
();
4359 NSEvent
*theEvent
= [NSApp currentEvent
];
4364 emacs_event
->kind
= NS_NONKEY_EVENT
;
4365 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4366 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4367 ns_input_line
= Qnil
; /* can be start or cons start,end */
4368 emacs_event
->modifiers
=0;
4369 EV_TRAILER
(theEvent
);
4375 /* **************************************************************************
4377 EmacsApp delegate implementation
4379 ************************************************************************** */
4381 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4382 /* --------------------------------------------------------------------------
4383 When application is loaded, terminate event loop in ns_term_init
4384 -------------------------------------------------------------------------- */
4386 NSTRACE
(applicationDidFinishLaunching
);
4387 [NSApp setServicesProvider
: NSApp
];
4388 ns_send_appdefined
(-2);
4392 /* Termination sequences:
4395 MenuBar | File | Exit:
4396 Select Quit from App menubar:
4398 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4401 Select Quit from Dock menu:
4404 Cancel -> Nothing else
4408 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4413 - (void
) terminate
: (id
)sender
4415 struct frame
*emacsframe
= SELECTED_FRAME
();
4420 emacs_event
->kind
= NS_NONKEY_EVENT
;
4421 emacs_event
->code
= KEY_NS_POWER_OFF
;
4422 emacs_event
->arg
= Qt
; /* mark as non-key event */
4423 EV_TRAILER
((id
)nil
);
4427 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4431 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4432 return NSTerminateNow
;
4434 ret
= NSRunAlertPanel
(ns_app_name
,
4435 @"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
,
4436 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4438 if (ret
== NSAlertDefaultReturn
)
4439 return NSTerminateNow
;
4440 else if (ret
== NSAlertAlternateReturn
)
4441 return NSTerminateCancel
;
4442 return NSTerminateNow
; /* just in case */
4446 not_in_argv
(NSString
*arg
)
4449 const
char *a
= [arg UTF8String
];
4450 for (k
= 1; k
< initial_argc
; ++k
)
4451 if (strcmp (a
, initial_argv
[k
]) == 0) return 0;
4455 /* Notification from the Workspace to open a file */
4456 - (BOOL
)application
: sender openFile
: (NSString
*)file
4458 if (ns_do_open_file || not_in_argv
(file
))
4459 [ns_pending_files addObject
: file
];
4464 /* Open a file as a temporary file */
4465 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4467 if (ns_do_open_file || not_in_argv
(file
))
4468 [ns_pending_files addObject
: file
];
4473 /* Notification from the Workspace to open a file noninteractively (?) */
4474 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4476 if (ns_do_open_file || not_in_argv
(file
))
4477 [ns_pending_files addObject
: file
];
4481 /* Notification from the Workspace to open multiple files */
4482 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4484 NSEnumerator
*files
= [fileList objectEnumerator
];
4486 /* Don't open files from the command line unconditionally,
4487 Cocoa parses the command line wrong, --option value tries to open value
4488 if --option is the last option. */
4489 while ((file
= [files nextObject
]) != nil
)
4490 if (ns_do_open_file || not_in_argv
(file
))
4491 [ns_pending_files addObject
: file
];
4493 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4498 /* Handle dock menu requests. */
4499 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4505 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4506 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4508 //ns_app_active
=YES
;
4510 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4512 NSTRACE
(applicationDidBecomeActive
);
4514 //ns_app_active
=YES
;
4516 ns_update_auto_hide_menu_bar
();
4517 // No constraining takes place when the application is not active.
4518 ns_constrain_all_frames
();
4520 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4523 ns_send_appdefined
(-1);
4528 /* ==========================================================================
4530 EmacsApp aux handlers for managing event loop
4532 ========================================================================== */
4535 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4536 /* --------------------------------------------------------------------------
4537 The timeout specified to ns_select has passed.
4538 -------------------------------------------------------------------------- */
4540 /*NSTRACE (timeout_handler); */
4541 ns_send_appdefined
(-2);
4544 - (void
)fd_handler
:(id
)unused
4545 /* --------------------------------------------------------------------------
4546 Check data waiting on file descriptors and terminate if so
4547 -------------------------------------------------------------------------- */
4550 int waiting
= 1, nfds
;
4553 SELECT_TYPE readfds
, writefds
, *wfds
;
4554 EMACS_TIME timeout
, *tmo
;
4555 NSAutoreleasePool
*pool
= nil
;
4557 /* NSTRACE (fd_handler); */
4562 pool
= [[NSAutoreleasePool alloc
] init
];
4568 FD_SET
(selfds
[0], &fds
);
4569 result
= select
(selfds
[0]+1, &fds
, NULL, NULL, NULL);
4572 read
(selfds
[0], &c
, 1);
4573 if (c
== 'g') waiting
= 0;
4578 pthread_mutex_lock
(&select_mutex
);
4581 if (select_valid
& SELECT_HAVE_READ
)
4582 readfds
= select_readfds
;
4586 if (select_valid
& SELECT_HAVE_WRITE
)
4588 writefds
= select_writefds
;
4593 if (select_valid
& SELECT_HAVE_TMO
)
4595 timeout
= select_timeout
;
4601 pthread_mutex_unlock
(&select_mutex
);
4603 FD_SET
(selfds
[0], &readfds
);
4604 if (selfds
[0] >= nfds
) nfds
= selfds
[0]+1;
4606 result
= pselect
(nfds
, &readfds
, wfds
, NULL, tmo
, NULL);
4609 ns_send_appdefined
(-2);
4610 else if (result
> 0)
4612 if (FD_ISSET
(selfds
[0], &readfds
))
4614 read
(selfds
[0], &c
, 1);
4615 if (c
== 's') waiting
= 1;
4619 pthread_mutex_lock
(&select_mutex
);
4620 if (select_valid
& SELECT_HAVE_READ
)
4621 select_readfds
= readfds
;
4622 if (select_valid
& SELECT_HAVE_WRITE
)
4623 select_writefds
= writefds
;
4624 if (select_valid
& SELECT_HAVE_TMO
)
4625 select_timeout
= timeout
;
4626 pthread_mutex_unlock
(&select_mutex
);
4628 ns_send_appdefined
(result
);
4638 /* ==========================================================================
4642 ========================================================================== */
4644 /* called from system: queue for next pass through event loop */
4645 - (void
)requestService
: (NSPasteboard
*)pboard
4646 userData
: (NSString
*)userData
4647 error: (NSString
**)error
4649 [ns_pending_service_names addObject
: userData
];
4650 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4651 SSDATA
(ns_string_from_pasteboard
(pboard
))]];
4655 /* called from ns_read_socket to clear queue */
4656 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4658 struct frame
*emacsframe
= SELECTED_FRAME
();
4659 NSEvent
*theEvent
= [NSApp currentEvent
];
4664 emacs_event
->kind
= NS_NONKEY_EVENT
;
4665 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4666 ns_input_spi_name
= build_string
([name UTF8String
]);
4667 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4668 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4669 EV_TRAILER
(theEvent
);
4679 /* ==========================================================================
4681 EmacsView implementation
4683 ========================================================================== */
4686 @implementation EmacsView
4688 /* needed to inform when window closed from LISP */
4689 - (void
) setWindowClosing
: (BOOL
)closing
4691 windowClosing
= closing
;
4697 NSTRACE
(EmacsView_dealloc
);
4703 /* called on font panel selection */
4704 - (void
)changeFont
: (id
)sender
4706 NSEvent
*e
=[[self window
] currentEvent
];
4707 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4711 NSTRACE
(changeFont
);
4715 if ((newFont
= [sender convertFont
:
4716 ((struct nsfont_info
*)face
->font
)->nsfont
]))
4718 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4720 emacs_event
->kind
= NS_NONKEY_EVENT
;
4721 emacs_event
->modifiers
= 0;
4722 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4724 size = [newFont pointSize
];
4725 ns_input_fontsize
= make_number
(lrint
(size));
4726 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4732 - (BOOL
)acceptsFirstResponder
4734 NSTRACE
(acceptsFirstResponder
);
4739 - (void
)resetCursorRects
4741 NSRect visible
= [self visibleRect
];
4742 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4743 NSTRACE
(resetCursorRects
);
4745 if (currentCursor
== nil
)
4746 currentCursor
= [NSCursor arrowCursor
];
4748 if (!NSIsEmptyRect
(visible
))
4749 [self addCursorRect
: visible cursor
: currentCursor
];
4750 [currentCursor setOnMouseEntered
: YES
];
4755 /*****************************************************************************/
4756 /* Keyboard handling. */
4759 - (void
)keyDown
: (NSEvent
*)theEvent
4761 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
4763 unsigned fnKeysym
= 0;
4765 static NSMutableArray
*nsEvArray
;
4766 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4767 static BOOL firstTime
= YES
;
4773 /* Rhapsody and OS X give up and down events for the arrow keys */
4774 if (ns_fake_keydown
== YES
)
4775 ns_fake_keydown
= NO
;
4776 else if ([theEvent
type] != NSKeyDown
)
4782 if (![[self window
] isKeyWindow
]
4783 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4784 /* we must avoid an infinite loop here. */
4785 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4787 /* XXX: There is an occasional condition in which, when Emacs display
4788 updates a different frame from the current one, and temporarily
4789 selects it, then processes some interrupt-driven input
4790 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4791 for some reason that window has its first responder set to the NSView
4792 most recently updated (I guess), which is not the correct one. */
4793 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4797 if (nsEvArray
== nil
)
4798 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4800 [NSCursor setHiddenUntilMouseMoves
: YES
];
4802 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4804 clear_mouse_face
(hlinfo
);
4805 hlinfo
->mouse_face_hidden
= 1;
4808 if (!processingCompose
)
4810 /* When using screen sharing, no left or right information is sent,
4811 so use Left key in those cases. */
4812 int is_left_key
, is_right_key
;
4814 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4815 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4817 /* (Carbon way: [theEvent keyCode]) */
4819 /* is it a "function key"? */
4820 fnKeysym
= ns_convert_key
(code
);
4823 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4824 because Emacs treats Delete and KP-Delete same (in simple.el). */
4825 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4826 code
= 0xFF08; /* backspace */
4831 /* are there modifiers? */
4832 emacs_event
->modifiers
= 0;
4833 flags
= [theEvent modifierFlags
];
4835 if (flags
& NSHelpKeyMask
)
4836 emacs_event
->modifiers |
= hyper_modifier
;
4838 if (flags
& NSShiftKeyMask
)
4839 emacs_event
->modifiers |
= shift_modifier
;
4841 is_right_key
= (flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
;
4842 is_left_key
= (flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
4843 ||
(! is_right_key
&& (flags
& NSCommandKeyMask
) == NSCommandKeyMask
);
4846 emacs_event
->modifiers |
= parse_solitary_modifier
4847 (EQ
(ns_right_command_modifier
, Qleft
)
4848 ? ns_command_modifier
4849 : ns_right_command_modifier
);
4853 emacs_event
->modifiers |
= parse_solitary_modifier
4854 (ns_command_modifier
);
4856 /* if super (default), take input manager's word so things like
4857 dvorak / qwerty layout work */
4858 if (EQ
(ns_command_modifier
, Qsuper
)
4860 && [[theEvent characters
] length] != 0)
4862 /* XXX: the code we get will be unshifted, so if we have
4863 a shift modifier, must convert ourselves */
4864 if (!(flags
& NSShiftKeyMask
))
4865 code
= [[theEvent characters
] characterAtIndex
: 0];
4867 /* this is ugly and also requires linking w/Carbon framework
4868 (for LMGetKbdType) so for now leave this rare (?) case
4869 undealt with.. in future look into CGEvent methods */
4872 long smv
= GetScriptManagerVariable
(smKeyScript
);
4873 Handle uchrHandle
= GetResource
4874 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4876 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4877 [[theEvent characters
] characterAtIndex
: 0],
4878 kUCKeyActionDisplay
,
4879 (flags
& ~NSCommandKeyMask
) >> 8,
4880 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4881 &dummy
, 1, &dummy
, &code
);
4888 is_right_key
= (flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
;
4889 is_left_key
= (flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
4890 ||
(! is_right_key
&& (flags
& NSControlKeyMask
) == NSControlKeyMask
);
4893 emacs_event
->modifiers |
= parse_solitary_modifier
4894 (EQ
(ns_right_control_modifier
, Qleft
)
4895 ? ns_control_modifier
4896 : ns_right_control_modifier
);
4899 emacs_event
->modifiers |
= parse_solitary_modifier
4900 (ns_control_modifier
);
4902 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4903 emacs_event
->modifiers |
=
4904 parse_solitary_modifier
(ns_function_modifier
);
4906 left_is_none
= NILP
(ns_alternate_modifier
)
4907 || EQ
(ns_alternate_modifier
, Qnone
);
4909 is_right_key
= (flags
& NSRightAlternateKeyMask
)
4910 == NSRightAlternateKeyMask
;
4911 is_left_key
= (flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
4913 && (flags
& NSAlternateKeyMask
) == NSAlternateKeyMask
);
4917 if ((NILP
(ns_right_alternate_modifier
)
4918 || EQ
(ns_right_alternate_modifier
, Qnone
)
4919 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
4921 { /* accept pre-interp alt comb */
4922 if ([[theEvent characters
] length] > 0)
4923 code
= [[theEvent characters
] characterAtIndex
: 0];
4924 /*HACK: clear lone shift modifier to stop next if from firing */
4925 if (emacs_event
->modifiers
== shift_modifier
)
4926 emacs_event
->modifiers
= 0;
4929 emacs_event
->modifiers |
= parse_solitary_modifier
4930 (EQ
(ns_right_alternate_modifier
, Qleft
)
4931 ? ns_alternate_modifier
4932 : ns_right_alternate_modifier
);
4935 if (is_left_key
) /* default = meta */
4937 if (left_is_none
&& !fnKeysym
)
4938 { /* accept pre-interp alt comb */
4939 if ([[theEvent characters
] length] > 0)
4940 code
= [[theEvent characters
] characterAtIndex
: 0];
4941 /*HACK: clear lone shift modifier to stop next if from firing */
4942 if (emacs_event
->modifiers
== shift_modifier
)
4943 emacs_event
->modifiers
= 0;
4946 emacs_event
->modifiers |
=
4947 parse_solitary_modifier
(ns_alternate_modifier
);
4951 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4952 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4954 /* if it was a function key or had modifiers, pass it directly to emacs */
4955 if (fnKeysym ||
(emacs_event
->modifiers
4956 && (emacs_event
->modifiers
!= shift_modifier
)
4957 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4958 /*[[theEvent characters] length] */
4960 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4962 code |
= (1<<28)|
(3<<16);
4963 else if (code
== 0x7f)
4964 code |
= (1<<28)|
(3<<16);
4966 emacs_event
->kind
= code
> 0xFF
4967 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4969 emacs_event
->code
= code
;
4970 EV_TRAILER
(theEvent
);
4976 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4977 /* if we get here we should send the key for input manager processing */
4978 if (firstTime
&& [[NSInputManager currentInputManager
]
4979 wantsToDelayTextChangeNotifications
] == NO
)
4981 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
4984 if (NS_KEYLOG
&& !processingCompose
)
4985 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
4987 processingCompose
= YES
;
4988 [nsEvArray addObject
: theEvent
];
4989 [self interpretKeyEvents
: nsEvArray
];
4990 [nsEvArray removeObject
: theEvent
];
4994 #ifdef NS_IMPL_COCOA
4995 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
4996 decided not to send key-down for.
4997 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
4998 This only applies on Tiger and earlier.
4999 If it matches one of these, send it on to keyDown. */
5000 -(void
)keyUp
: (NSEvent
*)theEvent
5002 int flags
= [theEvent modifierFlags
];
5003 int code
= [theEvent keyCode
];
5004 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
5005 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
5008 fprintf (stderr
, "keyUp
: passed test"
);
5009 ns_fake_keydown
= YES
;
5010 [self keyDown
: theEvent
];
5016 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
5019 /* <NSTextInput>: called when done composing;
5020 NOTE: also called when we delete over working text, followed immed.
5021 by doCommandBySelector: deleteBackward: */
5022 - (void
)insertText
: (id
)aString
5025 int len
= [(NSString
*)aString
length];
5029 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
5030 processingCompose
= NO
;
5035 /* first, clear any working text */
5036 if (workingText
!= nil
)
5037 [self deleteWorkingText
];
5039 /* now insert the string as keystrokes */
5040 for (i
=0; i
<len
; i
++)
5042 code
= [aString characterAtIndex
: i
];
5043 /* TODO: still need this? */
5045 code
= '~'; /* 0x7E */
5046 if (code
!= 32) /* Space */
5047 emacs_event
->modifiers
= 0;
5049 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
5050 emacs_event
->code
= code
;
5051 EV_TRAILER
((id
)nil
);
5056 /* <NSTextInput>: inserts display of composing characters */
5057 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
5059 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
5060 [aString string
] : aString
;
5062 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
5063 selRange.
length, selRange.location
);
5065 if (workingText
!= nil
)
5066 [self deleteWorkingText
];
5067 if ([str
length] == 0)
5073 processingCompose
= YES
;
5074 workingText
= [str copy
];
5075 ns_working_text
= build_string
([workingText UTF8String
]);
5077 emacs_event
->kind
= NS_TEXT_EVENT
;
5078 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
5079 EV_TRAILER
((id
)nil
);
5083 /* delete display of composing characters [not in <NSTextInput>] */
5084 - (void
)deleteWorkingText
5086 if (workingText
== nil
)
5089 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
5090 [workingText release
];
5092 processingCompose
= NO
;
5097 emacs_event
->kind
= NS_TEXT_EVENT
;
5098 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5099 EV_TRAILER
((id
)nil
);
5103 - (BOOL
)hasMarkedText
5105 return workingText
!= nil
;
5109 - (NSRange
)markedRange
5111 NSRange rng
= workingText
!= nil
5112 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5114 NSLog
(@"markedRange request"
);
5122 NSLog
(@"unmark
(accept
) text"
);
5123 [self deleteWorkingText
];
5124 processingCompose
= NO
;
5128 /* used to position char selection windows, etc. */
5129 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5133 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5135 NSLog
(@"firstRectForCharRange request"
);
5137 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5138 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5139 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5140 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5141 +FRAME_LINE_HEIGHT
(emacsframe
));
5143 pt
= [self convertPoint
: pt toView
: nil
];
5144 pt
= [[self window
] convertBaseToScreen
: pt
];
5150 - (NSInteger
)conversationIdentifier
5152 return (NSInteger
)self
;
5156 - (void
)doCommandBySelector
: (SEL
)aSelector
5159 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5161 if (aSelector
== @selector
(deleteBackward
:))
5163 /* happens when user backspaces over an ongoing composition:
5164 throw a 'delete' into the event queue */
5167 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5168 emacs_event
->code
= 0xFF08;
5169 EV_TRAILER
((id
)nil
);
5173 - (NSArray
*)validAttributesForMarkedText
5175 static NSArray
*arr
= nil
;
5176 if (arr
== nil
) arr
= [NSArray new
];
5177 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5181 - (NSRange
)selectedRange
5184 NSLog
(@"selectedRange request"
);
5185 return NSMakeRange
(NSNotFound
, 0);
5188 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5191 NSLog
(@"characterIndexForPoint request"
);
5195 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5197 static NSAttributedString
*str
= nil
;
5198 if (str
== nil
) str
= [NSAttributedString new
];
5200 NSLog
(@"attributedSubstringFromRange request"
);
5204 /* End <NSTextInput> impl. */
5205 /*****************************************************************************/
5208 /* This is what happens when the user presses a mouse button. */
5209 - (void
)mouseDown
: (NSEvent
*)theEvent
5211 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5213 NSTRACE
(mouseDown
);
5215 [self deleteWorkingText
];
5220 last_mouse_frame
= emacsframe
;
5221 /* appears to be needed to prevent spurious movement events generated on
5223 last_mouse_frame
->mouse_moved
= 0;
5225 if ([theEvent
type] == NSScrollWheel
)
5227 float delta
= [theEvent deltaY
];
5228 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5231 emacs_event
->kind
= WHEEL_EVENT
;
5232 emacs_event
->code
= 0;
5233 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5234 ((delta
> 0) ? up_modifier
: down_modifier
);
5238 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5239 emacs_event
->code
= EV_BUTTON
(theEvent
);
5240 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5241 | EV_UDMODIFIERS
(theEvent
);
5243 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5244 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5245 EV_TRAILER
(theEvent
);
5249 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5251 NSTRACE
(rightMouseDown
);
5252 [self mouseDown
: theEvent
];
5256 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5258 NSTRACE
(otherMouseDown
);
5259 [self mouseDown
: theEvent
];
5263 - (void
)mouseUp
: (NSEvent
*)theEvent
5266 [self mouseDown
: theEvent
];
5270 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5272 NSTRACE
(rightMouseUp
);
5273 [self mouseDown
: theEvent
];
5277 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5279 NSTRACE
(otherMouseUp
);
5280 [self mouseDown
: theEvent
];
5284 - (void
) scrollWheel
: (NSEvent
*)theEvent
5286 NSTRACE
(scrollWheel
);
5287 [self mouseDown
: theEvent
];
5291 /* Tell emacs the mouse has moved. */
5292 - (void
)mouseMoved
: (NSEvent
*)e
5294 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5297 // NSTRACE
(mouseMoved
);
5299 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5300 last_mouse_motion_position
5301 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5303 /* update any mouse face */
5304 if (hlinfo
->mouse_face_hidden
)
5306 hlinfo
->mouse_face_hidden
= 0;
5307 clear_mouse_face
(hlinfo
);
5310 /* tooltip handling */
5311 previous_help_echo_string
= help_echo_string
;
5312 help_echo_string
= Qnil
;
5314 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
5315 last_mouse_motion_position.y
))
5316 help_echo_string
= previous_help_echo_string
;
5318 XSETFRAME
(frame
, emacsframe
);
5319 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5321 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5322 (note_mouse_highlight), which is called through the
5323 note_mouse_movement () call above */
5324 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5325 help_echo_object
, help_echo_pos
);
5329 help_echo_string
= Qnil
;
5330 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5333 if (emacsframe
->mouse_moved
&& send_appdefined
)
5334 ns_send_appdefined
(-1);
5338 - (void
)mouseDragged
: (NSEvent
*)e
5340 NSTRACE
(mouseDragged
);
5341 [self mouseMoved
: e
];
5345 - (void
)rightMouseDragged
: (NSEvent
*)e
5347 NSTRACE
(rightMouseDragged
);
5348 [self mouseMoved
: e
];
5352 - (void
)otherMouseDragged
: (NSEvent
*)e
5354 NSTRACE
(otherMouseDragged
);
5355 [self mouseMoved
: e
];
5359 - (BOOL
)windowShouldClose
: (id
)sender
5361 NSEvent
*e
=[[self window
] currentEvent
];
5363 NSTRACE
(windowShouldClose
);
5364 windowClosing
= YES
;
5367 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5368 emacs_event
->modifiers
= 0;
5369 emacs_event
->code
= 0;
5371 /* Don't close this window, let this be done from lisp code. */
5375 - (void
) updateFrameSize
: (BOOL
) delay
;
5377 NSWindow
*window
= [self window
];
5378 NSRect wr
= [window frame
];
5379 #ifdef NS_IMPL_GNUSTEP
5385 int oldc
= cols
, oldr
= rows
;
5386 int oldw
= FRAME_PIXEL_WIDTH
(emacsframe
),
5387 oldh
= FRAME_PIXEL_HEIGHT
(emacsframe
);
5390 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
, wr.
size.width
+ extra
);
5392 if (cols
< MINWIDTH
)
5395 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
5396 (emacsframe
, wr.
size.height
5397 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + extra
5398 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5400 if (rows
< MINHEIGHT
)
5403 neww
= (int
)wr.
size.width
- emacsframe
->border_width
;
5404 newh
= ((int
)wr.
size.height
5405 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5406 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5408 if (oldr
!= rows || oldc
!= cols || neww
!= oldw || newh
!= oldh
)
5410 NSView
*view = FRAME_NS_VIEW
(emacsframe
);
5411 FRAME_PIXEL_WIDTH
(emacsframe
) = neww
;
5412 FRAME_PIXEL_HEIGHT
(emacsframe
) = newh
;
5413 change_frame_size
(emacsframe
, rows
, cols
, 0, delay
, 0);
5414 SET_FRAME_GARBAGED
(emacsframe
);
5415 cancel_mouse_face
(emacsframe
);
5416 [view setFrame
: NSMakeRect
(0, 0, neww
, newh
)];
5420 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5421 /* normalize frame to gridded text size */
5423 NSTRACE
(windowWillResize
);
5424 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5426 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5427 #ifdef NS_IMPL_GNUSTEP
5428 frameSize.width
+ 3);
5432 if (cols
< MINWIDTH
)
5435 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5436 #ifdef NS_IMPL_GNUSTEP
5437 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5438 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5440 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5441 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5443 if (rows
< MINHEIGHT
)
5445 #ifdef NS_IMPL_COCOA
5447 /* this sets window title to have size in it; the wm does this under GS */
5448 NSRect r
= [[self window
] frame
];
5449 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5460 NSWindow
*window
= [self window
];
5463 const
char *t
= [[[self window
] title] UTF8String
];
5464 char *pos
= strstr
(t
, " — "
);
5467 old_title
= xstrdup
(t
);
5469 size_title
= xmalloc
(strlen
(old_title
) + 40);
5470 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5471 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5476 #endif
/* NS_IMPL_COCOA */
5477 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5483 - (void
)windowDidResize
: (NSNotification
*)notification
5485 #ifdef NS_IMPL_GNUSTEP
5486 NSWindow
*theWindow
= [notification object
];
5488 /* in GNUstep, at least currently, it's possible to get a didResize
5489 without getting a willResize.. therefore we need to act as if we got
5490 the willResize now */
5491 NSSize sz
= [theWindow frame
].
size;
5492 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5493 #endif
/* NS_IMPL_GNUSTEP */
5495 NSTRACE
(windowDidResize
);
5496 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5498 #ifdef NS_IMPL_COCOA
5504 #endif
/* NS_IMPL_COCOA */
5506 /* Avoid loop under GNUstep due to call at beginning of this function.
5507 (x_set_window_size causes a resize which causes
5508 a "windowDidResize" which calls x_set_window_size). */
5509 #ifndef NS_IMPL_GNUSTEP
5510 if (cols
> 0 && rows
> 0)
5513 x_set_window_size
(emacsframe
, 0, cols
, rows
);
5516 [self updateFrameSize
: YES
];
5521 ns_send_appdefined
(-1);
5525 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5526 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5528 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5529 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5531 NSTRACE
(windowDidBecomeKey
);
5533 if (emacsframe
!= old_focus
)
5534 dpyinfo
->x_focus_frame
= emacsframe
;
5536 ns_frame_rehighlight
(emacsframe
);
5540 emacs_event
->kind
= FOCUS_IN_EVENT
;
5541 EV_TRAILER
((id
)nil
);
5546 - (void
)windowDidResignKey
: (NSNotification
*)notification
5547 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5549 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5550 NSTRACE
(windowDidResignKey
);
5552 if (dpyinfo
->x_focus_frame
== emacsframe
)
5553 dpyinfo
->x_focus_frame
= 0;
5555 ns_frame_rehighlight
(emacsframe
);
5557 /* FIXME: for some reason needed on second and subsequent clicks away
5558 from sole-frame Emacs to get hollow box to show */
5559 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5561 x_update_cursor
(emacsframe
, 1);
5562 x_set_frame_alpha
(emacsframe
);
5567 [self deleteWorkingText
];
5568 emacs_event
->kind
= FOCUS_IN_EVENT
;
5569 EV_TRAILER
((id
)nil
);
5574 - (void
)windowWillMiniaturize
: sender
5576 NSTRACE
(windowWillMiniaturize
);
5592 - initFrameFromEmacs
: (struct frame
*)f
5597 NSButton
*toggleButton
;
5602 NSTRACE
(initFrameFromEmacs
);
5605 processingCompose
= NO
;
5606 scrollbarsNeedingUpdate
= 0;
5608 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5610 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5611 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5612 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5613 [self initWithFrame
: r
];
5614 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5616 FRAME_NS_VIEW
(f
) = self
;
5620 win
= [[EmacsWindow alloc
]
5621 initWithContentRect
: r
5622 styleMask
: (NSResizableWindowMask |
5623 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5624 NSTitledWindowMask |
5626 NSMiniaturizableWindowMask |
5627 NSClosableWindowMask
)
5628 backing
: NSBackingStoreBuffered
5632 f
->border_width
= wr.
size.width
- r.
size.width
;
5633 FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
5635 [win setAcceptsMouseMovedEvents
: YES
];
5636 [win setDelegate
: self
];
5637 [win useOptimizedDrawing
: YES
];
5639 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5640 sz.height
= FRAME_LINE_HEIGHT
(f
);
5641 [win setResizeIncrements
: sz
];
5643 [[win contentView
] addSubview
: self
];
5646 [self registerForDraggedTypes
: ns_drag_types
];
5649 name
= [NSString stringWithUTF8String
:
5650 NILP
(tem
) ? "Emacs"
: SSDATA
(tem
)];
5651 [win setTitle
: name
];
5653 /* toolbar support */
5654 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
5655 [NSString stringWithFormat
: @"Emacs Frame
%d",
5657 [win setToolbar
: toolbar
];
5658 [toolbar setVisible
: NO
];
5659 #ifdef NS_IMPL_COCOA
5660 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
5661 [toggleButton setTarget
: self
];
5662 [toggleButton setAction
: @selector
(toggleToolbar
: )];
5664 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5668 [win setMiniwindowTitle
:
5669 [NSString stringWithUTF8String
: SSDATA
(tem
)]];
5672 NSScreen
*screen
= [win screen
];
5675 [win setFrameTopLeftPoint
: NSMakePoint
5676 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
5677 IN_BOUND
(-SCREENMAX
,
5678 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
5681 [win makeFirstResponder
: self
];
5683 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5684 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
5685 [win setBackgroundColor
: col
];
5686 if ([col alphaComponent
] != 1.0)
5687 [win setOpaque
: NO
];
5689 [self allocateGState
];
5691 [NSApp registerServicesMenuSendTypes
: ns_send_types
5699 - (void
)windowDidMove
: sender
5701 NSWindow
*win
= [self window
];
5702 NSRect r
= [win frame
];
5703 NSArray
*screens
= [NSScreen screens
];
5704 NSScreen
*screen
= [screens objectAtIndex
: 0];
5706 NSTRACE
(windowDidMove
);
5708 if (!emacsframe
->output_data.ns
)
5712 emacsframe
->left_pos
= r.origin.x
;
5713 emacsframe
->top_pos
=
5714 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
5719 /* Called AFTER method below, but before our windowWillResize call there leads
5720 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
5721 location so set_window_size moves the frame. */
5722 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5724 emacsframe
->output_data.ns
->zooming
= 1;
5729 /* Override to do something slightly nonstandard, but nice. First click on
5730 zoom button will zoom vertically. Second will zoom completely. Third
5731 returns to original. */
5732 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5733 defaultFrame
:(NSRect
)defaultFrame
5735 NSRect result
= [sender frame
];
5737 NSTRACE
(windowWillUseStandardFrame
);
5739 if (abs (defaultFrame.
size.height
- result.
size.height
)
5740 > FRAME_LINE_HEIGHT
(emacsframe
))
5743 ns_userRect
= result
;
5744 result.
size.height
= defaultFrame.
size.height
;
5745 result.origin.y
= defaultFrame.origin.y
;
5749 if (abs (defaultFrame.
size.width
- result.
size.width
)
5750 > FRAME_COLUMN_WIDTH
(emacsframe
))
5751 result
= defaultFrame
; /* second click */
5755 result
= ns_userRect.
size.height ? ns_userRect
: result
;
5756 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5760 [self windowWillResize
: sender toSize
: result.
size];
5765 - (void
)windowDidDeminiaturize
: sender
5767 NSTRACE
(windowDidDeminiaturize
);
5768 if (!emacsframe
->output_data.ns
)
5770 emacsframe
->async_iconified
= 0;
5771 emacsframe
->async_visible
= 1;
5772 windows_or_buffers_changed
++;
5776 emacs_event
->kind
= ICONIFY_EVENT
;
5777 EV_TRAILER
((id
)nil
);
5782 - (void
)windowDidExpose
: sender
5784 NSTRACE
(windowDidExpose
);
5785 if (!emacsframe
->output_data.ns
)
5787 emacsframe
->async_visible
= 1;
5788 SET_FRAME_GARBAGED
(emacsframe
);
5790 if (send_appdefined
)
5791 ns_send_appdefined
(-1);
5795 - (void
)windowDidMiniaturize
: sender
5797 NSTRACE
(windowDidMiniaturize
);
5798 if (!emacsframe
->output_data.ns
)
5801 emacsframe
->async_iconified
= 1;
5802 emacsframe
->async_visible
= 0;
5806 emacs_event
->kind
= ICONIFY_EVENT
;
5807 EV_TRAILER
((id
)nil
);
5812 - (void
)mouseEntered
: (NSEvent
*)theEvent
5814 NSTRACE
(mouseEntered
);
5815 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5819 - (void
)mouseExited
: (NSEvent
*)theEvent
5821 Mouse_HLInfo
*hlinfo
= emacsframe ? MOUSE_HL_INFO
(emacsframe
) : NULL;
5823 NSTRACE
(mouseExited
);
5828 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5830 if (emacsframe
== hlinfo
->mouse_face_mouse_frame
)
5832 clear_mouse_face
(hlinfo
);
5833 hlinfo
->mouse_face_mouse_frame
= 0;
5841 if (context_menu_value
== -1)
5842 context_menu_value
= [sender tag
];
5845 NSInteger tag
= [sender tag
];
5846 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
5847 emacsframe
->menu_bar_vector
,
5851 ns_send_appdefined
(-1);
5856 - (EmacsToolbar
*)toolbar
5862 /* this gets called on toolbar button click */
5863 - toolbarClicked
: (id
)item
5866 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
5868 NSTRACE
(toolbarClicked
);
5873 /* send first event (for some reason two needed) */
5874 theEvent
= [[self window
] currentEvent
];
5875 emacs_event
->kind
= TOOL_BAR_EVENT
;
5876 XSETFRAME
(emacs_event
->arg
, emacsframe
);
5877 EV_TRAILER
(theEvent
);
5879 emacs_event
->kind
= TOOL_BAR_EVENT
;
5880 /* XSETINT (emacs_event->code, 0); */
5881 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
5882 idx
+ TOOL_BAR_ITEM_KEY
);
5883 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5884 EV_TRAILER
(theEvent
);
5889 - toggleToolbar
: (id
)sender
5894 emacs_event
->kind
= NS_NONKEY_EVENT
;
5895 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
5896 EV_TRAILER
((id
)nil
);
5901 - (void
)drawRect
: (NSRect
)rect
5903 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
5904 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
5908 if (!emacsframe ||
!emacsframe
->output_data.ns || ns_in_resize
)
5911 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
5912 expose_frame
(emacsframe
, x
, y
, width
, height
);
5915 drawRect: may be called (at least in OS X 10.5) for invisible
5916 views as well for some reason. Thus, do not infer visibility
5919 emacsframe->async_visible = 1;
5920 emacsframe->async_iconified = 0;
5925 /* NSDraggingDestination protocol methods. Actually this is not really a
5926 protocol, but a category of Object. O well... */
5928 -(NSUInteger
) draggingEntered
: (id
<NSDraggingInfo
>) sender
5930 NSTRACE
(draggingEntered
);
5931 return NSDragOperationGeneric
;
5935 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
5941 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
5946 NSEvent
*theEvent
= [[self window
] currentEvent
];
5949 NSTRACE
(performDragOperation
);
5954 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
5955 x
= lrint
(position.x
); y
= lrint
(position.y
);
5957 pb
= [sender draggingPasteboard
];
5958 type = [pb availableTypeFromArray
: ns_drag_types
];
5963 else if ([type isEqualToString
: NSFilenamesPboardType
])
5966 NSEnumerator
*fenum
;
5969 if (!(files
= [pb propertyListForType
: type]))
5972 fenum
= [files objectEnumerator
];
5973 while ( (file
= [fenum nextObject
]) )
5975 emacs_event
->kind
= NS_NONKEY_EVENT
;
5976 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5977 XSETINT
(emacs_event
->x
, x
);
5978 XSETINT
(emacs_event
->y
, y
);
5979 ns_input_file
= append2
(ns_input_file
,
5980 build_string
([file UTF8String
]));
5981 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5982 EV_TRAILER
(theEvent
);
5986 else if ([type isEqualToString
: NSURLPboardType
])
5991 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
5992 [fileURL isFileURL
] == NO
)
5995 file
= [fileURL
path];
5996 emacs_event
->kind
= NS_NONKEY_EVENT
;
5997 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5998 XSETINT
(emacs_event
->x
, x
);
5999 XSETINT
(emacs_event
->y
, y
);
6000 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
6001 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6002 EV_TRAILER
(theEvent
);
6005 else if ([type isEqualToString
: NSStringPboardType
]
6006 ||
[type isEqualToString
: NSTabularTextPboardType
])
6010 if (! (data
= [pb stringForType
: type]))
6013 emacs_event
->kind
= NS_NONKEY_EVENT
;
6014 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
6015 XSETINT
(emacs_event
->x
, x
);
6016 XSETINT
(emacs_event
->y
, y
);
6017 ns_input_text
= build_string
([data UTF8String
]);
6018 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6019 EV_TRAILER
(theEvent
);
6022 else if ([type isEqualToString
: NSColorPboardType
])
6024 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
6025 emacs_event
->kind
= NS_NONKEY_EVENT
;
6026 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
6027 XSETINT
(emacs_event
->x
, x
);
6028 XSETINT
(emacs_event
->y
, y
);
6029 ns_input_color
= ns_color_to_lisp
(c
);
6030 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6031 EV_TRAILER
(theEvent
);
6034 else if ([type isEqualToString
: NSFontPboardType
])
6036 /* impl based on GNUstep NSTextView.m */
6037 NSData
*data
= [pb dataForType
: NSFontPboardType
];
6038 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
6039 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
6045 emacs_event
->kind
= NS_NONKEY_EVENT
;
6046 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
6047 XSETINT
(emacs_event
->x
, x
);
6048 XSETINT
(emacs_event
->y
, y
);
6049 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
6050 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
6051 ns_input_fontsize
= build_string
(fontSize
);
6052 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6053 EV_TRAILER
(theEvent
);
6058 error ("Invalid data
type in dragging pasteboard."
);
6064 - (id
) validRequestorForSendType
: (NSString
*)typeSent
6065 returnType
: (NSString
*)typeReturned
6067 NSTRACE
(validRequestorForSendType
);
6068 if (typeSent
!= nil
&& [ns_send_types indexOfObject
: typeSent
] != NSNotFound
6069 && typeReturned
== nil
)
6071 if (! NILP
(ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
)))
6075 return [super validRequestorForSendType
: typeSent
6076 returnType
: typeReturned
];
6080 /* The next two methods are part of NSServicesRequests informal protocol,
6081 supposedly called when a services menu item is chosen from this app.
6082 But this should not happen because we override the services menu with our
6083 own entries which call ns-perform-service.
6084 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
6085 So let's at least stub them out until further investigation can be done. */
6087 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
6089 /* we could call ns_string_from_pasteboard(pboard) here but then it should
6090 be written into the buffer in place of the existing selection..
6091 ordinary service calls go through functions defined in ns-win.el */
6095 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
6097 NSArray
*typesDeclared
;
6100 /* We only support NSStringPboardType */
6101 if ([types containsObject
:NSStringPboardType
] == NO
) {
6105 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6106 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
6109 if (CONSP
(val
) && NILP
(XCDR
(val
)))
6112 if (! STRINGP
(val
))
6115 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
6116 [pb declareTypes
:typesDeclared owner
:nil
];
6117 ns_string_to_pasteboard
(pb
, val
);
6122 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
6123 (gives a miniaturized version of the window); currently we use the latter for
6124 frames whose active buffer doesn't correspond to any file
6125 (e.g., '*scratch*') */
6126 - setMiniwindowImage
: (BOOL
) setMini
6128 id
image = [[self window
] miniwindowImage
];
6129 NSTRACE
(setMiniwindowImage
);
6131 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6132 about "AppleDockIconEnabled" notwithstanding, however the set message
6133 below has its effect nonetheless. */
6134 if (image != emacsframe
->output_data.ns
->miniimage
)
6136 if (image && [image isKindOfClass
: [EmacsImage
class]])
6138 [[self window
] setMiniwindowImage
:
6139 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6146 - (void
) setRows
: (int
) r andColumns
: (int
) c
6152 @
end /* EmacsView */
6156 /* ==========================================================================
6158 EmacsWindow implementation
6160 ========================================================================== */
6162 @implementation EmacsWindow
6164 #ifdef NS_IMPL_COCOA
6165 - (id
)accessibilityAttributeValue
:(NSString
*)attribute
6167 Lisp_Object str
= Qnil
;
6168 struct frame
*f
= SELECTED_FRAME
();
6169 struct buffer
*curbuf
= XBUFFER
(XWINDOW
(f
->selected_window
)->buffer
);
6171 if ([attribute isEqualToString
:NSAccessibilityRoleAttribute
])
6172 return NSAccessibilityTextFieldRole
;
6174 if ([attribute isEqualToString
:NSAccessibilitySelectedTextAttribute
]
6175 && curbuf
&& ! NILP
(BVAR
(curbuf
, mark_active
)))
6177 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6179 else if (curbuf
&& [attribute isEqualToString
:NSAccessibilityValueAttribute
])
6181 if (! NILP
(BVAR
(curbuf
, mark_active
)))
6182 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6186 ptrdiff_t start_byte
= BUF_BEGV_BYTE
(curbuf
);
6187 ptrdiff_t byte_range
= BUF_ZV_BYTE
(curbuf
) - start_byte
;
6188 ptrdiff_t range
= BUF_ZV
(curbuf
) - BUF_BEGV
(curbuf
);
6190 if (! NILP
(BVAR
(curbuf
, enable_multibyte_characters
)))
6191 str
= make_uninit_multibyte_string
(range
, byte_range
);
6193 str
= make_uninit_string
(range
);
6194 /* To check: This returns emacs-utf-8, which is a superset of utf-8.
6195 Is this a problem? */
6196 memcpy
(SDATA
(str
), BYTE_POS_ADDR
(start_byte
), byte_range
);
6203 if (CONSP
(str
) && SYMBOLP
(XCAR
(str
)))
6206 if (CONSP
(str
) && NILP
(XCDR
(str
)))
6211 const
char *utfStr
= SSDATA
(str
);
6212 NSString
*nsStr
= [NSString stringWithUTF8String
: utfStr
];
6217 return [super accessibilityAttributeValue
:attribute
];
6219 #endif
/* NS_IMPL_COCOA */
6221 /* If we have multiple monitors, one above the other, we don't want to
6222 restrict the height to just one monitor. So we override this. */
6223 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6225 /* When making the frame visible for the first time or if there is just
6226 one screen, we want to constrain. Other times not. */
6227 NSUInteger nr_screens
= [[NSScreen screens
] count
];
6228 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6229 NSTRACE
(constrainFrameRect
);
6231 if (nr_screens
== 1)
6233 NSRect r
= [super constrainFrameRect
:frameRect toScreen
:screen
];
6237 if (f
->output_data.ns
->dont_constrain
6238 || ns_menu_bar_should_be_hidden
())
6241 f
->output_data.ns
->dont_constrain
= 1;
6242 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6246 /* called only on resize clicks by special case in EmacsApp-sendEvent */
6247 - (void
)mouseDown
: (NSEvent
*)theEvent
6251 NSSize
size = [[theEvent window
] frame
].
size;
6252 grabOffset
= [theEvent locationInWindow
];
6253 grabOffset.x
= size.width
- grabOffset.x
;
6256 [super mouseDown
: theEvent
];
6261 - (void
)mouseUp
: (NSEvent
*)theEvent
6265 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6267 ns_set_name_as_filename
(f
);
6269 ns_send_appdefined
(-1);
6272 [super mouseUp
: theEvent
];
6276 /* send resize events */
6277 - (void
)mouseDragged
: (NSEvent
*)theEvent
6281 NSPoint p
= [theEvent locationInWindow
];
6282 NSSize
size, vettedSize
, origSize
= [self frame
].
size;
6284 size.width
= p.x
+ grabOffset.x
;
6285 size.height
= origSize.height
- p.y
+ grabOffset.y
;
6287 if (size.width
== origSize.width
&& size.height
== origSize.height
)
6290 vettedSize
= [[self delegate
] windowWillResize
: self toSize
: size];
6291 [[NSNotificationCenter defaultCenter
]
6292 postNotificationName
: NSWindowDidResizeNotification
6296 [super mouseDragged
: theEvent
];
6299 @
end /* EmacsWindow */
6302 /* ==========================================================================
6304 EmacsScroller implementation
6306 ========================================================================== */
6309 @implementation EmacsScroller
6311 /* for repeat button push */
6312 #define SCROLL_BAR_FIRST_DELAY
0.5
6313 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6315 + (CGFloat
) scrollerWidth
6317 /* TODO: if we want to allow variable widths, this is the place to do it,
6318 however neither GNUstep nor Cocoa support it very well */
6319 return [NSScroller scrollerWidth
];
6323 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
6325 NSTRACE
(EmacsScroller_initFrame
);
6327 r.
size.width
= [EmacsScroller scrollerWidth
];
6328 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
6329 [self setContinuous
: YES
];
6330 [self setEnabled
: YES
];
6332 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
6333 locked against the top and bottom edges, and right edge on OS X, where
6334 scrollers are on right. */
6335 #ifdef NS_IMPL_GNUSTEP
6336 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
6338 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
6343 pixel_height
= NSHeight
(r
);
6344 if (pixel_height
== 0) pixel_height
= 1;
6345 min_portion
= 20 / pixel_height
;
6347 frame
= XFRAME
(XWINDOW
(win
)->frame
);
6348 if (FRAME_LIVE_P
(frame
))
6351 EmacsView
*view = FRAME_NS_VIEW
(frame
);
6352 NSView
*sview
= [[view window
] contentView
];
6353 NSArray
*subs
= [sview subviews
];
6355 /* disable optimization stopping redraw of other scrollbars */
6356 view->scrollbarsNeedingUpdate
= 0;
6357 for (i
=[subs count
]-1; i
>= 0; i
--)
6358 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
6359 view->scrollbarsNeedingUpdate
++;
6360 [sview addSubview
: self
];
6363 /* [self setFrame: r]; */
6369 - (void
)setFrame
: (NSRect
)newRect
6371 NSTRACE
(EmacsScroller_setFrame
);
6373 pixel_height
= NSHeight
(newRect
);
6374 if (pixel_height
== 0) pixel_height
= 1;
6375 min_portion
= 20 / pixel_height
;
6376 [super setFrame
: newRect
];
6378 /* UNBLOCK_INPUT; */
6384 NSTRACE
(EmacsScroller_dealloc
);
6386 wset_vertical_scroll_bar
(XWINDOW
(win
), Qnil
);
6414 /* ensure other scrollbar updates after deletion */
6415 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6417 view->scrollbarsNeedingUpdate
++;
6418 [self removeFromSuperview
];
6426 - (void
)resetCursorRects
6428 NSRect visible
= [self visibleRect
];
6429 NSTRACE
(resetCursorRects
);
6431 if (!NSIsEmptyRect
(visible
))
6432 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
6433 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
6437 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
6440 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
6441 && portion
!= whole
; /* needed for resize empty buf */
6445 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
6447 NSTRACE
(setPosition
);
6449 em_position
= position
;
6450 em_portion
= portion
;
6453 if (portion
>= whole
)
6455 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6456 [self setKnobProportion
: 1.0];
6457 [self setDoubleValue
: 1.0];
6459 [self setFloatValue
: 0.0 knobProportion
: 1.0];
6465 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
6466 pos
= (float
)position
/ (whole
- portion
);
6467 por
= (float
)portion
/whole
;
6468 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6469 [self setKnobProportion
: por
];
6470 [self setDoubleValue
: pos
];
6472 [self setFloatValue
: pos knobProportion
: por
];
6478 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
6479 drag events will go directly to the EmacsScroller. Leaving in for now. */
6480 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
6481 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
6483 *part
= last_hit_part
;
6485 XSETINT
(*y
, pixel_height
);
6486 if ([self floatValue
] > 0.999)
6487 XSETINT
(*x
, pixel_height
);
6489 XSETINT
(*x
, pixel_height
* [self floatValue
]);
6493 /* set up emacs_event */
6494 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
6499 emacs_event
->part
= last_hit_part
;
6500 emacs_event
->code
= 0;
6501 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
6502 emacs_event
->frame_or_window
= win
;
6503 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
6504 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
6505 emacs_event
->arg
= Qnil
;
6506 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
6507 XSETINT
(emacs_event
->y
, pixel_height
-20);
6511 n_emacs_events_pending
++;
6512 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
6515 kbd_buffer_store_event
(emacs_event
);
6516 EVENT_INIT
(*emacs_event
);
6517 ns_send_appdefined
(-1);
6521 /* called manually thru timer to implement repeated button action w/hold-down */
6522 - repeatScroll
: (NSTimer
*)scrollEntry
6524 NSEvent
*e
= [[self window
] currentEvent
];
6525 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
6526 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
6528 /* clear timer if need be */
6529 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
6531 [scroll_repeat_entry invalidate
];
6532 [scroll_repeat_entry release
];
6533 scroll_repeat_entry
= nil
;
6539 = [[NSTimer scheduledTimerWithTimeInterval
:
6540 SCROLL_BAR_CONTINUOUS_DELAY
6542 selector
: @selector
(repeatScroll
:)
6548 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
6553 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
6554 mouseDragged events without going into a modal loop. */
6555 - (void
)mouseDown
: (NSEvent
*)e
6558 /* hitPart is only updated AFTER event is passed on */
6559 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6560 double inc
= 0.0, loc
, kloc
, pos
;
6563 NSTRACE
(EmacsScroller_mouseDown
);
6567 case NSScrollerDecrementPage
:
6568 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6569 case NSScrollerIncrementPage
:
6570 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6571 case NSScrollerDecrementLine
:
6572 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6573 case NSScrollerIncrementLine
:
6574 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6575 case NSScrollerKnob
:
6576 last_hit_part
= scroll_bar_handle
; break;
6577 case NSScrollerKnobSlot
: /* GNUstep-only */
6578 last_hit_part
= scroll_bar_move_ratio
; break;
6579 default
: /* NSScrollerNoPart? */
6580 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
6587 pos
= 0; /* ignored */
6589 /* set a timer to repeat, as we can't let superclass do this modally */
6591 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
6593 selector
: @selector
(repeatScroll
:)
6600 /* handle, or on GNUstep possibly slot */
6601 NSEvent
*fake_event
;
6603 /* compute float loc in slot and mouse offset on knob */
6604 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6606 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6612 else if (loc
>= NSHeight
(sr
))
6614 loc
= NSHeight
(sr
);
6622 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6624 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6626 last_mouse_offset
= kloc
;
6628 /* if knob, tell emacs a location offset by knob pos
6629 (to indicate top of handle) */
6630 if (part
== NSScrollerKnob
)
6631 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6633 /* else this is a slot click on GNUstep: go straight there */
6634 pos
= loc
/ NSHeight
(sr
);
6636 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6637 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6638 location
: [e locationInWindow
]
6639 modifierFlags
: [e modifierFlags
]
6640 timestamp
: [e timestamp
]
6641 windowNumber
: [e windowNumber
]
6642 context
: [e context
]
6643 eventNumber
: [e eventNumber
]
6644 clickCount
: [e clickCount
]
6645 pressure
: [e pressure
]];
6646 [super mouseUp
: fake_event
];
6649 if (part
!= NSScrollerKnob
)
6650 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6654 /* Called as we manually track scroller drags, rather than superclass. */
6655 - (void
)mouseDragged
: (NSEvent
*)e
6661 NSTRACE
(EmacsScroller_mouseDragged
);
6663 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6665 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6672 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6674 loc
= NSHeight
(sr
) + last_mouse_offset
;
6678 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6679 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6683 - (void
)mouseUp
: (NSEvent
*)e
6685 if (scroll_repeat_entry
)
6687 [scroll_repeat_entry invalidate
];
6688 [scroll_repeat_entry release
];
6689 scroll_repeat_entry
= nil
;
6695 /* treat scrollwheel events in the bar as though they were in the main window */
6696 - (void
) scrollWheel
: (NSEvent
*)theEvent
6698 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6699 [view mouseDown
: theEvent
];
6702 @
end /* EmacsScroller */
6707 /* ==========================================================================
6709 Font-related functions; these used to be in nsfaces.m
6711 ========================================================================== */
6715 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6717 struct font
*font
= XFONT_OBJECT
(font_object
);
6720 fontset
= fontset_from_font
(font_object
);
6721 FRAME_FONTSET
(f
) = fontset
;
6723 if (FRAME_FONT
(f
) == font
)
6724 /* This font is already set in frame F. There's nothing more to
6728 FRAME_FONT
(f
) = font
;
6730 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6731 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6732 FRAME_SPACE_WIDTH
(f
) = font
->space_width
;
6733 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6735 compute_fringe_widths
(f
, 1);
6737 /* Compute the scroll bar width in character columns. */
6738 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6740 int wid
= FRAME_COLUMN_WIDTH
(f
);
6741 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6742 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6746 int wid
= FRAME_COLUMN_WIDTH
(f
);
6747 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6750 /* Now make the frame display the given font. */
6751 if (FRAME_NS_WINDOW
(f
) != 0)
6752 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6758 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6759 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6763 ns_xlfd_to_fontname
(const
char *xlfd
)
6764 /* --------------------------------------------------------------------------
6765 Convert an X font name (XLFD) to an NS font name.
6766 Only family is used.
6767 The string returned is temporarily allocated.
6768 -------------------------------------------------------------------------- */
6770 char *name
= xmalloc
(180);
6774 if (!strncmp
(xlfd
, "
--"
, 2))
6775 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
6777 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
6779 /* stopgap for malformed XLFD input */
6780 if (strlen
(name
) == 0)
6781 strcpy
(name
, "Monaco"
);
6783 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
6784 also uppercase after '-' or ' ' */
6785 name
[0] = c_toupper
(name
[0]);
6786 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
6792 name
[i
+1] = c_toupper
(name
[i
+1]);
6794 else if (name
[i
] == '_')
6798 name
[i
+1] = c_toupper
(name
[i
+1]);
6801 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
6802 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
6809 syms_of_nsterm
(void
)
6811 NSTRACE
(syms_of_nsterm
);
6813 ns_antialias_threshold
= 10.0;
6815 /* from 23+ we need to tell emacs what modifiers there are.. */
6816 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
6817 DEFSYM
(Qalt
, "alt"
);
6818 DEFSYM
(Qhyper
, "hyper"
);
6819 DEFSYM
(Qmeta
, "
meta"
);
6820 DEFSYM
(Qsuper
, "super"
);
6821 DEFSYM
(Qcontrol
, "control"
);
6822 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
6824 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
6825 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
6826 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
6827 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
6828 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
6830 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
6831 "The file specified in the last NS event."
);
6832 ns_input_file
=Qnil
;
6834 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
6835 "The data received in the last NS
text drag event."
);
6836 ns_input_text
=Qnil
;
6838 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
6839 "String
for visualizing working composition sequence."
);
6840 ns_working_text
=Qnil
;
6842 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
6843 "The font specified in the last NS event."
);
6844 ns_input_font
=Qnil
;
6846 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
6847 "The fontsize specified in the last NS event."
);
6848 ns_input_fontsize
=Qnil
;
6850 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
6851 "The
line specified in the last NS event."
);
6852 ns_input_line
=Qnil
;
6854 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
6855 "The color specified in the last NS event."
);
6856 ns_input_color
=Qnil
;
6858 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
6859 "The service name specified in the last NS event."
);
6860 ns_input_spi_name
=Qnil
;
6862 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
6863 "The service argument specified in the last NS event."
);
6864 ns_input_spi_arg
=Qnil
;
6866 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
6867 "This variable describes the behavior of the alternate or option key.
\n\
6868 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6869 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
6870 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6871 ns_alternate_modifier
= Qmeta
;
6873 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
6874 "This variable describes the behavior of the right alternate or option key.
\n\
6875 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6876 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
6877 Set to none means that the alternate / option key is not interpreted by Emacs\n\
6878 at all, allowing it to be used at a lower level for accented character entry.");
6879 ns_right_alternate_modifier = Qleft;
6881 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
6882 "This variable describes the behavior of the command key.\n\
6883 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
6884 ns_command_modifier = Qsuper;
6886 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
6887 "This variable describes the behavior of the right command key.\n\
6888 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6889 Set to left means be the same key as `ns-command-modifier'.
\n\
6890 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
6891 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6892 ns_right_command_modifier
= Qleft
;
6894 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
6895 "This variable describes the behavior of the control key.
\n\
6896 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
6897 ns_control_modifier
= Qcontrol
;
6899 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
6900 "This variable describes the behavior of the right control key.
\n\
6901 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6902 Set to left means be the same key as `ns
-control
-modifier
'.\n\
6903 Set to none means that the control / option key is not interpreted by Emacs\n\
6904 at all, allowing it to be used at a lower level for accented character entry.");
6905 ns_right_control_modifier = Qleft;
6907 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
6908 "This variable describes the behavior of the function key (on laptops).\n\
6909 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6910 Set to none means that the function key is not interpreted by Emacs at all,\n\
6911 allowing it to be used at a lower level for accented character entry.");
6912 ns_function_modifier = Qnone;
6914 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
6915 "Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above.");
6916 ns_antialias_text = Qt;
6918 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
6919 "Whether to confirm application quit using dialog.");
6920 ns_confirm_quit = Qnil;
6922 staticpro (&ns_display_name_list);
6923 ns_display_name_list = Qnil;
6925 staticpro (&last_mouse_motion_frame);
6926 last_mouse_motion_frame = Qnil;
6928 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
6929 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
6930 Only works on OSX 10.6 or later. */);
6931 ns_auto_hide_menu_bar = Qnil;
6933 /* TODO: move to common code */
6934 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
6935 doc: /* Which toolkit scroll bars Emacs uses, if any.
6936 A value of nil means Emacs doesn't use toolkit scroll bars.
6937 With the X Window system
, the value is a symbol describing the
6938 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
6939 With MS Windows or Nextstep
, the value is t. */
);
6940 Vx_toolkit_scroll_bars
= Qt
;
6942 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
6943 x_use_underline_position_properties
,
6944 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
6945 A value of nil means ignore them. If you encounter fonts with bogus
6946 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
6947 to 4.1, set this to nil. */);
6948 x_use_underline_position_properties
= 0;
6950 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
6951 x_underline_at_descent_line
,
6952 doc: /* Non-nil means to draw the underline at the same place as the descent line.
6953 A value of nil means to draw the underline according to the value of the
6954 variable `x-use-underline-position-properties', which is usually at the
6955 baseline level. The default value is nil. */);
6956 x_underline_at_descent_line
= 0;
6958 /* Tell emacs about this window system. */
6959 Fprovide
(intern
("ns"
), Qnil
);