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
>
39 #include
<c
-strcase.h
>
42 #include "blockinput.h"
43 #include "sysselect.h"
46 #include "character.h"
48 #include "composite.h"
51 #include "termhooks.h"
62 int term_trace_num
= 0;
63 #define NSTRACE
(x
) fprintf (stderr
, "
%s:%d: [%d] " #x "\n", \
64 __FILE__
, __LINE__
, ++term_trace_num
)
69 extern NSString
*NSMenuDidBeginTrackingNotification
;
71 /* ==========================================================================
75 ========================================================================== */
77 /* Convert a symbol indexed with an NSxxx value to a value as defined
78 in keyboard.c (lispy_function_key). I hope this is a correct way
80 static unsigned convert_ns_to_X_keysym
[] =
82 NSHomeFunctionKey
, 0x50,
83 NSLeftArrowFunctionKey
, 0x51,
84 NSUpArrowFunctionKey
, 0x52,
85 NSRightArrowFunctionKey
, 0x53,
86 NSDownArrowFunctionKey
, 0x54,
87 NSPageUpFunctionKey
, 0x55,
88 NSPageDownFunctionKey
, 0x56,
89 NSEndFunctionKey
, 0x57,
90 NSBeginFunctionKey
, 0x58,
91 NSSelectFunctionKey
, 0x60,
92 NSPrintFunctionKey
, 0x61,
93 NSExecuteFunctionKey
, 0x62,
94 NSInsertFunctionKey
, 0x63,
95 NSUndoFunctionKey
, 0x65,
96 NSRedoFunctionKey
, 0x66,
97 NSMenuFunctionKey
, 0x67,
98 NSFindFunctionKey
, 0x68,
99 NSHelpFunctionKey
, 0x6A,
100 NSBreakFunctionKey
, 0x6B,
102 NSF1FunctionKey
, 0xBE,
103 NSF2FunctionKey
, 0xBF,
104 NSF3FunctionKey
, 0xC0,
105 NSF4FunctionKey
, 0xC1,
106 NSF5FunctionKey
, 0xC2,
107 NSF6FunctionKey
, 0xC3,
108 NSF7FunctionKey
, 0xC4,
109 NSF8FunctionKey
, 0xC5,
110 NSF9FunctionKey
, 0xC6,
111 NSF10FunctionKey
, 0xC7,
112 NSF11FunctionKey
, 0xC8,
113 NSF12FunctionKey
, 0xC9,
114 NSF13FunctionKey
, 0xCA,
115 NSF14FunctionKey
, 0xCB,
116 NSF15FunctionKey
, 0xCC,
117 NSF16FunctionKey
, 0xCD,
118 NSF17FunctionKey
, 0xCE,
119 NSF18FunctionKey
, 0xCF,
120 NSF19FunctionKey
, 0xD0,
121 NSF20FunctionKey
, 0xD1,
122 NSF21FunctionKey
, 0xD2,
123 NSF22FunctionKey
, 0xD3,
124 NSF23FunctionKey
, 0xD4,
125 NSF24FunctionKey
, 0xD5,
127 NSBackspaceCharacter
, 0x08, /* 8: Not on some KBs. */
128 NSDeleteCharacter
, 0xFF, /* 127: Big 'delete' key upper right. */
129 NSDeleteFunctionKey
, 0x9F, /* 63272: Del forw key off main array. */
131 NSTabCharacter
, 0x09,
132 0x19, 0x09, /* left tab->regular since pass shift */
133 NSCarriageReturnCharacter
, 0x0D,
134 NSNewlineCharacter
, 0x0D,
135 NSEnterCharacter
, 0x8D,
137 0x1B, 0x1B /* escape */
140 static Lisp_Object Qmodifier_value
;
141 Lisp_Object Qalt
, Qcontrol
, Qhyper
, Qmeta
, Qsuper
, Qnone
;
142 extern Lisp_Object Qcursor_color
, Qcursor_type
, Qns
, Qleft
;
144 static Lisp_Object QUTF8_STRING
;
146 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
147 the maximum font size to NOT antialias. On GNUstep there is currently
148 no way to control this behavior. */
149 float ns_antialias_threshold
;
151 /* Used to pick up AppleHighlightColor on OS X */
152 NSString
*ns_selection_color
;
154 NSArray
*ns_send_types
=0, *ns_return_types
=0, *ns_drag_types
=0;
155 NSString
*ns_app_name
= @"Emacs"
; /* default changed later */
157 /* Display variables */
158 struct ns_display_info
*x_display_list
; /* Chain of existing displays */
159 Lisp_Object ns_display_name_list
;
160 long context_menu_value
= 0;
163 NSPoint last_mouse_motion_position
;
164 static NSRect last_mouse_glyph
;
165 static Time last_mouse_movement_time
= 0;
166 static Lisp_Object last_mouse_motion_frame
;
167 static EmacsScroller
*last_mouse_scroll_bar
= nil
;
168 static
struct frame
*ns_updating_frame
;
169 static NSView
*focus_view
= NULL;
170 static int ns_window_num
= 0;
172 static BOOL gsaved
= NO
;
173 BOOL ns_in_resize
= NO
;
174 static BOOL ns_fake_keydown
= NO
;
175 int ns_tmp_flags
; /* FIXME */
176 struct nsfont_info
*ns_tmp_font
; /* FIXME */
177 static BOOL ns_menu_bar_is_hidden
= NO
;
178 /*static int debug_lock = 0; */
181 static BOOL send_appdefined
= YES
;
182 static NSEvent
*last_appdefined_event
= 0;
183 static NSTimer
*timed_entry
= 0;
184 static NSTimer
*fd_entry
= nil
;
185 static NSTimer
*scroll_repeat_entry
= nil
;
186 static fd_set select_readfds
, t_readfds
;
187 static int select_nfds
;
188 static NSAutoreleasePool
*outerpool
;
189 static
struct input_event
*emacs_event
= NULL;
190 static
struct input_event
*q_event_ptr
= NULL;
191 static int n_emacs_events_pending
= 0;
192 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
193 *ns_pending_service_args
;
194 static BOOL inNsSelect
= 0;
196 /* Convert modifiers in a NeXTstep event to emacs style modifiers. */
197 #define NS_FUNCTION_KEY_MASK
0x800000
198 #define NSLeftControlKeyMask
(0x000001 | NSControlKeyMask
)
199 #define NSRightControlKeyMask
(0x002000 | NSControlKeyMask
)
200 #define NSLeftCommandKeyMask
(0x000008 | NSCommandKeyMask
)
201 #define NSRightCommandKeyMask
(0x000010 | NSCommandKeyMask
)
202 #define NSLeftAlternateKeyMask
(0x000020 | NSAlternateKeyMask
)
203 #define NSRightAlternateKeyMask
(0x000040 | NSAlternateKeyMask
)
204 #define EV_MODIFIERS
(e
) \
205 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
206 hyper_modifier
: 0) \
207 |
(!EQ
(ns_right_alternate_modifier
, Qleft
) && \
208 (([e modifierFlags
] & NSRightAlternateKeyMask
) \
209 == NSRightAlternateKeyMask
) ? \
210 parse_solitary_modifier
(ns_right_alternate_modifier
) : 0) \
211 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
212 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
213 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
214 shift_modifier
: 0) \
215 |
(!EQ
(ns_right_control_modifier
, Qleft
) && \
216 (([e modifierFlags
] & NSRightControlKeyMask
) \
217 == NSRightControlKeyMask
) ? \
218 parse_solitary_modifier
(ns_right_control_modifier
) : 0) \
219 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
220 parse_solitary_modifier
(ns_control_modifier
) : 0) \
221 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
222 parse_solitary_modifier
(ns_function_modifier
) : 0) \
223 |
(!EQ
(ns_right_command_modifier
, Qleft
) && \
224 (([e modifierFlags
] & NSRightCommandKeyMask
) \
225 == NSRightCommandKeyMask
) ? \
226 parse_solitary_modifier
(ns_right_command_modifier
) : 0) \
227 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
228 parse_solitary_modifier
(ns_command_modifier
):0))
230 #define EV_UDMODIFIERS
(e
) \
231 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
232 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
233 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
234 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
235 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
236 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
237 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
238 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
239 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
241 #define EV_BUTTON
(e
) \
242 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
243 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
244 [e buttonNumber
] - 1)
246 /* Convert the time field to a timestamp in milliseconds. */
247 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
249 /* This is a piece of code which is common to all the event handling
250 methods. Maybe it should even be a function. */
251 #define EV_TRAILER
(e
) \
253 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
254 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
255 n_emacs_events_pending
++; \
256 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
257 EVENT_INIT
(*emacs_event
); \
258 ns_send_appdefined
(-1); \
261 void x_set_cursor_type
(struct frame
*, Lisp_Object
, Lisp_Object
);
263 /* TODO: get rid of need for these forward declarations */
264 static void ns_condemn_scroll_bars
(struct frame
*f
);
265 static void ns_judge_scroll_bars
(struct frame
*f
);
266 void x_set_frame_alpha
(struct frame
*f
);
269 /* ==========================================================================
273 ========================================================================== */
277 append2
(Lisp_Object list
, Lisp_Object item
)
278 /* --------------------------------------------------------------------------
279 Utility to append to a list
280 -------------------------------------------------------------------------- */
282 Lisp_Object array
[2];
284 array
[1] = Fcons
(item
, Qnil
);
285 return Fnconc
(2, &array
[0]);
290 ns_etc_directory
(void
)
291 /* If running as a self-contained app bundle, return as a string the
292 filename of the etc directory, if present; else nil. */
294 NSBundle
*bundle
= [NSBundle mainBundle
];
295 NSString
*resourceDir
= [bundle resourcePath
];
296 NSString
*resourcePath
;
297 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
300 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
301 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
303 if (isDir
) return [resourcePath UTF8String
];
311 /* If running as a self-contained app bundle, return as a path string
312 the filenames of the libexec and bin directories, ie libexec:bin.
313 Otherwise, return nil.
314 Normally, Emacs does not add its own bin/ directory to the PATH.
315 However, a self-contained NS build has a different layout, with
316 bin/ and libexec/ subdirectories in the directory that contains
318 We put libexec first, because init_callproc_1 uses the first
319 element to initialize exec-directory. An alternative would be
320 for init_callproc to check for invocation-directory/libexec.
323 NSBundle
*bundle
= [NSBundle mainBundle
];
324 NSString
*resourceDir
= [bundle resourcePath
];
325 NSString
*binDir
= [bundle bundlePath
];
326 NSString
*resourcePath
, *resourcePaths
;
328 BOOL onWindows
= NO
; /* FIXME determine this somehow */
329 NSString
*pathSeparator
= onWindows ? @"
;"
: @"
:"
;
330 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
332 NSEnumerator
*pathEnum
;
335 range
= [resourceDir rangeOfString
: @"Contents"
];
336 if (range.location
!= NSNotFound
)
338 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
340 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
344 paths
= [binDir stringsByAppendingPaths
:
345 [NSArray arrayWithObjects
: @"libexec"
, @"bin"
, nil
]];
346 pathEnum
= [paths objectEnumerator
];
349 while (resourcePath
= [pathEnum nextObject
])
351 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
354 if ([resourcePaths
length] > 0)
356 = [resourcePaths stringByAppendingString
: pathSeparator
];
358 = [resourcePaths stringByAppendingString
: resourcePath
];
361 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
369 /* If running as a self-contained app bundle, return as a path string
370 the filenames of the site-lisp, lisp and leim directories.
371 Ie, site-lisp:lisp:leim. Otherwise, return nil. */
373 NSBundle
*bundle
= [NSBundle mainBundle
];
374 NSString
*resourceDir
= [bundle resourcePath
];
375 NSString
*resourcePath
, *resourcePaths
;
376 BOOL onWindows
= NO
; /* FIXME determine this somehow */
377 NSString
*pathSeparator
= onWindows ? @"
;"
: @"
:"
;
378 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
380 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
381 [NSArray arrayWithObjects
:
382 @"site
-lisp"
, @"lisp"
, @"leim"
, nil
]];
383 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
386 /* Hack to skip site-lisp. */
387 if (no_site_lisp
) resourcePath
= [pathEnum nextObject
];
389 while (resourcePath
= [pathEnum nextObject
])
391 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
394 if ([resourcePaths
length] > 0)
396 = [resourcePaths stringByAppendingString
: pathSeparator
];
398 = [resourcePaths stringByAppendingString
: resourcePath
];
401 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
407 ns_timeout
(int usecs
)
408 /* --------------------------------------------------------------------------
409 Blocking timer utility used by ns_ring_bell
410 -------------------------------------------------------------------------- */
412 EMACS_TIME wakeup
, delay
;
414 EMACS_GET_TIME
(wakeup
);
415 EMACS_SET_SECS_USECS
(delay
, 0, usecs
);
416 EMACS_ADD_TIME
(wakeup
, wakeup
, delay
);
418 /* Keep waiting until past the time wakeup. */
423 EMACS_GET_TIME
(timeout
);
424 if (EMACS_TIME_LE
(wakeup
, timeout
))
426 EMACS_SUB_TIME
(timeout
, wakeup
, timeout
);
428 /* Try to wait that long--but we might wake up sooner. */
429 pselect
(0, NULL, NULL, NULL, &timeout
, NULL);
435 ns_release_object
(void
*obj
)
436 /* --------------------------------------------------------------------------
437 Release an object (callable from C)
438 -------------------------------------------------------------------------- */
445 ns_retain_object
(void
*obj
)
446 /* --------------------------------------------------------------------------
447 Retain an object (callable from C)
448 -------------------------------------------------------------------------- */
455 ns_alloc_autorelease_pool
(void
)
456 /* --------------------------------------------------------------------------
457 Allocate a pool for temporary objects (callable from C)
458 -------------------------------------------------------------------------- */
460 return [[NSAutoreleasePool alloc
] init
];
465 ns_release_autorelease_pool
(void
*pool
)
466 /* --------------------------------------------------------------------------
467 Free a pool and temporary objects it refers to (callable from C)
468 -------------------------------------------------------------------------- */
470 ns_release_object
(pool
);
475 /* ==========================================================================
477 Focus (clipping) and screen update
479 ========================================================================== */
482 ns_resize_handle_rect
(NSWindow
*window
)
484 NSRect r
= [window frame
];
485 r.origin.x
= r.
size.width
- RESIZE_HANDLE_SIZE
;
487 r.
size.width
= r.
size.height
= RESIZE_HANDLE_SIZE
;
493 // Window constraining
494 // -------------------
496 // To ensure that the windows are not placed under the
menu bar, they
497 // are typically moved by the call
-back constrainFrameRect. However
,
498 // by overriding it
, it
's possible to inhibit this, leaving the window
499 // in it's original position.
501 // It
's possible to hide the menu bar. However, technically, it's only
502 // possible to hide it when the application is active. To ensure that
503 // this work properly
, the
menu bar and window constraining are
504 // deferred until the application becomes active.
506 // Even though it
's not possible to manually move a window above the
507 // top of the screen, it is allowed if it's done programmatically
,
508 // when the
menu is
hidden. This allows the editable area to cover the
509 // full screen height.
514 // Use the following extra files
:
517 // ;; Hide
menu and place frame slightly above the top of the screen.
518 // (setq ns
-auto
-hide
-menu-bar t
)
519 // (set-frame
-position
(selected
-frame
) 0 -20)
523 // emacs
-Q
-l init.el
525 // Result
: No
menu bar, and the
title bar should be above the screen.
531 // Result
: Menu bar visible
, frame placed immediately below the
menu.
535 ns_constrain_all_frames
(void
)
537 Lisp_Object tail
, frame
;
539 FOR_EACH_FRAME
(tail
, frame
)
541 struct frame
*f
= XFRAME
(frame
);
544 NSView
*view = FRAME_NS_VIEW
(f
);
545 /* This no-op will trigger the default window placing
546 * constraint system. */
547 f
->output_data.ns
->dont_constrain
= 0;
548 [[view window
] setFrameOrigin
:[[view window
] frame
].origin
];
554 /* True, if the menu bar should be hidden. */
557 ns_menu_bar_should_be_hidden
(void
)
559 return !NILP
(ns_auto_hide_menu_bar
)
560 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)];
564 /* Show or hide the menu bar, based on user setting. */
567 ns_update_auto_hide_menu_bar
(void
)
569 #ifndef MAC_OS_X_VERSION_10_6
570 #define MAC_OS_X_VERSION_10_6
1060
573 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
576 NSTRACE
(ns_update_auto_hide_menu_bar
);
580 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)])
582 // Note
, "setPresentationOptions" triggers an
error unless the
583 // application is active.
584 BOOL menu_bar_should_be_hidden
= ns_menu_bar_should_be_hidden
();
586 if (menu_bar_should_be_hidden
!= ns_menu_bar_is_hidden
)
588 NSApplicationPresentationOptions options
589 = NSApplicationPresentationAutoHideDock
;
591 if (menu_bar_should_be_hidden
)
592 options |
= NSApplicationPresentationAutoHideMenuBar
;
594 [NSApp setPresentationOptions
: options
];
596 ns_menu_bar_is_hidden
= menu_bar_should_be_hidden
;
598 if (!ns_menu_bar_is_hidden
)
600 ns_constrain_all_frames
();
612 ns_update_begin
(struct frame
*f
)
613 /* --------------------------------------------------------------------------
614 Prepare for a grouped sequence of drawing calls
615 external (RIF) call; whole frame, called before update_window_begin
616 -------------------------------------------------------------------------- */
618 NSView
*view = FRAME_NS_VIEW
(f
);
619 NSTRACE
(ns_update_begin
);
621 ns_update_auto_hide_menu_bar
();
623 ns_updating_frame
= f
;
626 #ifdef NS_IMPL_GNUSTEP
627 uRect
= NSMakeRect
(0, 0, 0, 0);
633 ns_update_window_begin
(struct window
*w
)
634 /* --------------------------------------------------------------------------
635 Prepare for a grouped sequence of drawing calls
636 external (RIF) call; for one window, called after update_begin
637 -------------------------------------------------------------------------- */
639 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
640 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
641 NSTRACE
(ns_update_window_begin
);
644 set_output_cursor
(&w
->cursor
);
648 if (f
== hlinfo
->mouse_face_mouse_frame
)
650 /* Don't do highlighting for mouse motion during the update. */
651 hlinfo
->mouse_face_defer
= 1;
653 /* If the frame needs to be redrawn,
654 simply forget about any prior mouse highlighting. */
655 if (FRAME_GARBAGED_P
(f
))
656 hlinfo
->mouse_face_window
= Qnil
;
658 /* (further code for mouse faces ifdef'd out in other terms elided) */
666 ns_update_window_end
(struct window
*w
, int cursor_on_p
,
667 int mouse_face_overwritten_p
)
668 /* --------------------------------------------------------------------------
669 Finished a grouped sequence of drawing calls
670 external (RIF) call; for one window called before update_end
671 -------------------------------------------------------------------------- */
673 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(XFRAME
(w
->frame
));
675 /* note: this fn is nearly identical in all terms */
676 if (!w
->pseudo_window_p
)
681 display_and_set_cursor
(w
, 1,
682 output_cursor.hpos
, output_cursor.vpos
,
683 output_cursor.x
, output_cursor.y
);
685 if (draw_window_fringes
(w
, 1))
686 x_draw_vertical_border
(w
);
691 /* If a row with mouse-face was overwritten, arrange for
692 frame_up_to_date to redisplay the mouse highlight. */
693 if (mouse_face_overwritten_p
)
695 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
696 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
697 hlinfo
->mouse_face_window
= Qnil
;
700 updated_window
= NULL;
701 NSTRACE
(update_window_end
);
706 ns_update_end
(struct frame
*f
)
707 /* --------------------------------------------------------------------------
708 Finished a grouped sequence of drawing calls
709 external (RIF) call; for whole frame, called after update_window_end
710 -------------------------------------------------------------------------- */
712 NSView
*view = FRAME_NS_VIEW
(f
);
714 /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
715 MOUSE_HL_INFO
(f
)->mouse_face_defer
= 0;
719 #ifdef NS_IMPL_GNUSTEP
720 /* trigger flush only in the rectangle we tracked as being drawn */
721 [view unlockFocusNeedsFlush
: NO
];
722 /*fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", uRect.origin.x, uRect.origin.y, uRect.size.width, uRect.size.height); */
723 [view lockFocusInRect
: uRect
];
727 [[view window
] flushWindow
];
730 ns_updating_frame
= NULL;
731 NSTRACE
(ns_update_end
);
736 ns_flush
(struct frame
*f
)
737 /* --------------------------------------------------------------------------
739 NS impl is no-op since currently we flush in ns_update_end and elsewhere
740 -------------------------------------------------------------------------- */
747 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
748 /* --------------------------------------------------------------------------
749 Internal: Focus on given frame. During small local updates this is used to
750 draw, however during large updates, ns_update_begin and ns_update_end are
751 called to wrap the whole thing, in which case these calls are stubbed out.
752 Except, on GNUstep, we accumulate the rectangle being drawn into, because
753 the back end won't do this automatically, and will just end up flushing
755 -------------------------------------------------------------------------- */
757 // NSTRACE
(ns_focus
);
758 #ifdef NS_IMPL_GNUSTEP
761 u
= NSUnionRect
(r
[0], r
[1]);
766 fprintf (stderr, "focus: %d", c++);
767 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
768 fprintf (stderr, "\n"); */
770 if (f
!= ns_updating_frame
)
772 NSView
*view = FRAME_NS_VIEW
(f
);
773 if (view != focus_view
)
775 if (focus_view
!= NULL)
777 [focus_view unlockFocus
];
778 [[focus_view window
] flushWindow
];
783 #ifdef NS_IMPL_GNUSTEP
784 r ?
[view lockFocusInRect
: u
] : [view lockFocus
];
789 /*if (view) debug_lock++; */
791 #ifdef NS_IMPL_GNUSTEP
794 /* more than one rect being drawn into */
797 [view unlockFocus
]; /* add prev rect to redraw list */
798 [view lockFocusInRect
: u
]; /* focus for draw in new rect */
803 #ifdef NS_IMPL_GNUSTEP
806 /* in batch mode, but in GNUstep must still track rectangles explicitly */
807 uRect
= (r ? NSUnionRect
(uRect
, u
) : [FRAME_NS_VIEW
(f
) visibleRect
]);
814 [[NSGraphicsContext currentContext
] saveGraphicsState
];
816 NSRectClipList
(r
, 2);
825 ns_unfocus
(struct frame
*f
)
826 /* --------------------------------------------------------------------------
827 Internal: Remove focus on given frame
828 -------------------------------------------------------------------------- */
830 // NSTRACE
(ns_unfocus
);
834 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
838 if (f
!= ns_updating_frame
)
840 if (focus_view
!= NULL)
842 [focus_view unlockFocus
];
843 [[focus_view window
] flushWindow
];
852 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
, int area
, BOOL gc
)
853 /* --------------------------------------------------------------------------
854 Internal (but parallels other terms): Focus drawing on given row
855 -------------------------------------------------------------------------- */
857 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
859 int window_x
, window_y
, window_width
;
861 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
863 clip_rect.origin.x
= window_x
- FRAME_INTERNAL_BORDER_WIDTH
(f
);
864 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
865 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
866 clip_rect.
size.width
= window_width
+ 2 * FRAME_INTERNAL_BORDER_WIDTH
(f
);
867 clip_rect.
size.height
= row
->visible_height
;
869 /* allow a full-height row at the top when requested
870 (used to draw fringe all the way through internal border area) */
871 if (gc
&& clip_rect.origin.y
< 5)
873 clip_rect.origin.y
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
874 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
877 /* likewise at bottom */
879 FRAME_PIXEL_HEIGHT
(f
) - (clip_rect.origin.y
+ clip_rect.
size.height
) < 5)
880 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
882 ns_focus
(f
, &clip_rect
, 1);
887 ns_ring_bell
(struct frame
*f
)
888 /* --------------------------------------------------------------------------
890 -------------------------------------------------------------------------- */
892 NSTRACE
(ns_ring_bell
);
895 NSAutoreleasePool
*pool
;
896 struct frame
*frame
= SELECTED_FRAME
();
900 pool
= [[NSAutoreleasePool alloc
] init
];
902 view = FRAME_NS_VIEW
(frame
);
906 NSPoint dim
= NSMakePoint
(128, 128);
909 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
910 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
911 r.
size.width
= dim.x
;
912 r.
size.height
= dim.y
;
913 surr
= NSInsetRect
(r
, -2, -2);
914 ns_focus
(frame
, &surr
, 1);
915 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
916 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
917 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
919 [[view window
] flushWindow
];
921 [[view window
] restoreCachedImage
];
922 [[view window
] flushWindow
];
936 ns_reset_terminal_modes
(struct terminal *terminal)
937 /* Externally called as hook */
939 NSTRACE
(ns_reset_terminal_modes
);
944 ns_set_terminal_modes
(struct terminal *terminal)
945 /* Externally called as hook */
947 NSTRACE
(ns_set_terminal_modes
);
952 /* ==========================================================================
954 Frame / window manager related functions
956 ========================================================================== */
960 ns_raise_frame
(struct frame
*f
)
961 /* --------------------------------------------------------------------------
962 Bring window to foreground and make it active
963 -------------------------------------------------------------------------- */
965 NSView
*view = FRAME_NS_VIEW
(f
);
968 FRAME_SAMPLE_VISIBILITY
(f
);
969 if (FRAME_VISIBLE_P
(f
))
971 [[view window
] makeKeyAndOrderFront
: NSApp
];
978 ns_lower_frame
(struct frame
*f
)
979 /* --------------------------------------------------------------------------
981 -------------------------------------------------------------------------- */
983 NSView
*view = FRAME_NS_VIEW
(f
);
986 [[view window
] orderBack
: NSApp
];
992 ns_frame_raise_lower
(struct frame
*f
, int raise
)
993 /* --------------------------------------------------------------------------
995 -------------------------------------------------------------------------- */
997 NSTRACE
(ns_frame_raise_lower
);
1007 ns_frame_rehighlight
(struct frame
*frame
)
1008 /* --------------------------------------------------------------------------
1009 External (hook): called on things like window switching within frame
1010 -------------------------------------------------------------------------- */
1012 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(frame
);
1013 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1015 NSTRACE
(ns_frame_rehighlight
);
1016 if (dpyinfo
->x_focus_frame
)
1018 dpyinfo
->x_highlight_frame
1019 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1020 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1021 : dpyinfo
->x_focus_frame
);
1022 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
1024 FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
) = Qnil
;
1025 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1029 dpyinfo
->x_highlight_frame
= 0;
1031 if (dpyinfo
->x_highlight_frame
&&
1032 dpyinfo
->x_highlight_frame
!= old_highlight
)
1036 x_update_cursor
(old_highlight
, 1);
1037 x_set_frame_alpha
(old_highlight
);
1039 if (dpyinfo
->x_highlight_frame
)
1041 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
1042 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
1049 x_make_frame_visible
(struct frame
*f
)
1050 /* --------------------------------------------------------------------------
1051 External: Show the window (X11 semantics)
1052 -------------------------------------------------------------------------- */
1054 NSTRACE
(x_make_frame_visible
);
1055 /* XXX: at some points in past this was not needed, as the only place that
1056 called this (frame.c:Fraise_frame ()) also called raise_lower;
1057 if this ends up the case again, comment this out again. */
1058 if (!FRAME_VISIBLE_P
(f
))
1060 f
->async_visible
= 1;
1067 x_make_frame_invisible
(struct frame
*f
)
1068 /* --------------------------------------------------------------------------
1069 External: Hide the window (X11 semantics)
1070 -------------------------------------------------------------------------- */
1072 NSView
* view = FRAME_NS_VIEW
(f
);
1073 NSTRACE
(x_make_frame_invisible
);
1075 [[view window
] orderOut
: NSApp
];
1076 f
->async_visible
= 0;
1077 f
->async_iconified
= 0;
1082 x_iconify_frame
(struct frame
*f
)
1083 /* --------------------------------------------------------------------------
1084 External: Iconify window
1085 -------------------------------------------------------------------------- */
1087 NSView
* view = FRAME_NS_VIEW
(f
);
1088 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1089 NSTRACE
(x_iconify_frame
);
1092 if (dpyinfo
->x_highlight_frame
== f
)
1093 dpyinfo
->x_highlight_frame
= 0;
1095 if ([[view window
] windowNumber
] <= 0)
1097 /* the window is still deferred. Make it very small, bring it
1098 on screen and order it out. */
1099 NSRect s
= { { 100, 100}, {0, 0} };
1101 t
= [[view window
] frame
];
1102 [[view window
] setFrame
: s display
: NO
];
1103 [[view window
] orderBack
: NSApp
];
1104 [[view window
] orderOut
: NSApp
];
1105 [[view window
] setFrame
: t display
: NO
];
1107 [[view window
] miniaturize
: NSApp
];
1110 /* Free X resources of frame F. */
1113 x_free_frame_resources
(struct frame
*f
)
1115 NSView
*view = FRAME_NS_VIEW
(f
);
1116 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1117 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1118 NSTRACE
(x_destroy_window
);
1121 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1125 free_frame_menubar
(f
);
1127 if (FRAME_FACE_CACHE
(f
))
1128 free_frame_faces
(f
);
1130 if (f
== dpyinfo
->x_focus_frame
)
1131 dpyinfo
->x_focus_frame
= 0;
1132 if (f
== dpyinfo
->x_highlight_frame
)
1133 dpyinfo
->x_highlight_frame
= 0;
1134 if (f
== hlinfo
->mouse_face_mouse_frame
)
1136 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1137 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1138 hlinfo
->mouse_face_window
= Qnil
;
1139 hlinfo
->mouse_face_deferred_gc
= 0;
1140 hlinfo
->mouse_face_mouse_frame
= 0;
1143 if (f
->output_data.ns
->miniimage
!= nil
)
1144 [f
->output_data.ns
->miniimage release
];
1146 [[view window
] close];
1149 xfree
(f
->output_data.ns
);
1155 x_destroy_window
(struct frame
*f
)
1156 /* --------------------------------------------------------------------------
1157 External: Delete the window
1158 -------------------------------------------------------------------------- */
1160 NSTRACE
(x_destroy_window
);
1162 x_free_frame_resources
(f
);
1168 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1169 /* --------------------------------------------------------------------------
1170 External: Position the window
1171 -------------------------------------------------------------------------- */
1173 NSView
*view = FRAME_NS_VIEW
(f
);
1174 NSArray
*screens
= [NSScreen screens
];
1175 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1176 NSScreen
*screen
= [[view window
] screen
];
1178 NSTRACE
(x_set_offset
);
1185 if (view != nil
&& screen
&& fscreen
)
1187 f
->left_pos
= f
->size_hint_flags
& XNegative
1188 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1190 /* We use visibleFrame here to take menu bar into account.
1191 Ideally we should also adjust left/top with visibleFrame.origin. */
1193 f
->top_pos
= f
->size_hint_flags
& YNegative
1194 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1195 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1196 - FRAME_TOOLBAR_HEIGHT
(f
))
1198 #ifdef NS_IMPL_GNUSTEP
1199 if (f
->left_pos
< 100)
1200 f
->left_pos
= 100; /* don't overlap menu */
1202 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1204 f
->output_data.ns
->dont_constrain
= 0;
1205 [[view window
] setFrameTopLeftPoint
:
1206 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1207 SCREENMAXBOUND
([fscreen frame
].
size.height
1208 - NS_TOP_POS
(f
)))];
1209 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1217 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1218 /* --------------------------------------------------------------------------
1219 Adjust window pixel size based on given character grid size
1220 Impl is a bit more complex than other terms, need to do some
1222 -------------------------------------------------------------------------- */
1224 EmacsView
*view = FRAME_NS_VIEW
(f
);
1225 EmacsToolbar
*toolbar
= [view toolbar
];
1226 NSWindow
*window
= [view window
];
1227 NSRect wr
= [window frame
];
1228 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1229 int pixelwidth
, pixelheight
;
1230 static int oldRows
, oldCols
, oldFontWidth
, oldFontHeight
;
1232 static
struct frame
*oldF
;
1234 NSTRACE
(x_set_window_size
);
1238 && rows
== oldRows
&& cols
== oldCols
1239 && oldFontWidth
== FRAME_COLUMN_WIDTH
(f
)
1240 && oldFontHeight
== FRAME_LINE_HEIGHT
(f
)
1244 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1248 check_frame_size
(f
, &rows
, &cols
);
1252 oldFontWidth
= FRAME_COLUMN_WIDTH
(f
);
1253 oldFontHeight
= FRAME_LINE_HEIGHT
(f
);
1256 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1257 compute_fringe_widths
(f
, 0);
1259 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1260 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1262 /* If we have a toolbar, take its height into account. */
1264 /* NOTE: previously this would generate wrong result if toolbar not
1265 yet displayed and fixing toolbar_height=32 helped, but
1266 now (200903) seems no longer needed */
1267 FRAME_TOOLBAR_HEIGHT
(f
) =
1268 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1269 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1271 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1273 wr.
size.width
= pixelwidth
+ f
->border_width
;
1274 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1275 + FRAME_TOOLBAR_HEIGHT
(f
);
1277 /* Do not try to constrain to this screen. We may have multiple
1278 screens, and want Emacs to span those. Constraining to screen
1279 prevents that, and that is not nice to the user. */
1280 if (f
->output_data.ns
->zooming
)
1281 f
->output_data.ns
->zooming
= 0;
1283 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1285 [view setRows
: rows andColumns
: cols
];
1286 [window setFrame
: wr display
: YES
];
1288 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1290 /* This is a trick to compensate for Emacs' managing the scrollbar area
1291 as a fixed number of standard character columns. Instead of leaving
1292 blank space for the extra, we chopped it off above. Now for
1293 left-hand scrollbars, we shift all rendering to the left by the
1294 difference between the real width and Emacs' imagined one. For
1295 right-hand bars, don't worry about it since the extra is never used.
1296 (Obviously doesn't work for vertically split windows tho..) */
1298 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1299 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1300 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1301 : NSMakePoint
(0, 0);
1302 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1303 [view setBoundsOrigin
: origin
];
1306 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1307 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1308 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1309 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1311 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1312 cancel_mouse_face
(f
);
1319 /* ==========================================================================
1323 ========================================================================== */
1327 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1329 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1330 if (idx
< 1 || idx
>= color_table
->avail
)
1332 return color_table
->colors
[idx
];
1337 ns_index_color
(NSColor
*color
, struct frame
*f
)
1339 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1343 if (!color_table
->colors
)
1345 color_table
->size = NS_COLOR_CAPACITY
;
1346 color_table
->avail
= 1; /* skip idx=0 as marker */
1347 color_table
->colors
= xmalloc
(color_table
->size * sizeof
(NSColor
*));
1348 color_table
->colors
[0] = nil
;
1349 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1352 /* do we already have this color ? */
1353 for (i
= 1; i
< color_table
->avail
; i
++)
1354 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1357 if ([color_table
->empty_indices count
] > 0)
1359 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1360 [color_table
->empty_indices removeObject
: index
];
1361 idx
= [index unsignedLongValue
];
1365 if (color_table
->avail
== color_table
->size)
1366 color_table
->colors
=
1367 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1368 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1369 idx
= color_table
->avail
++;
1372 color_table
->colors
[idx
] = color
;
1374 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1380 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1382 struct ns_color_table
*color_table
;
1389 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1391 if (idx
<= 0 || idx
>= color_table
->size) {
1392 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1396 index
= [NSNumber numberWithUnsignedInt
: idx
];
1397 if ([color_table
->empty_indices containsObject
: index
]) {
1398 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1402 color
= color_table
->colors
[idx
];
1404 color_table
->colors
[idx
] = nil
;
1405 [color_table
->empty_indices addObject
: index
];
1406 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1411 ns_get_color
(const
char *name
, NSColor
**col
)
1412 /* --------------------------------------------------------------------------
1414 -------------------------------------------------------------------------- */
1415 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1416 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1417 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1420 static
char hex
[20];
1422 float r
= -1.0, g
, b
;
1423 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1425 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1428 if ([nsname isEqualToString
: @"ns_selection_color"
])
1430 nsname
= ns_selection_color
;
1431 name
= [ns_selection_color UTF8String
];
1434 /* First, check for some sort of numeric specification. */
1437 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1439 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1440 [scanner scanFloat
: &r
];
1441 [scanner scanFloat
: &g
];
1442 [scanner scanFloat
: &b
];
1444 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1446 strncpy
(hex
, name
+ 4, 19);
1448 scaling
= (strlen
(hex
) - 2) / 3;
1450 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1452 int len
= (strlen
(name
) - 1);
1453 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1455 scaling
= strlen
(name
+start
) / 3;
1456 for (i
=0; i
<3; i
++) {
1457 strncpy
(hex
+ i
* (scaling
+ 1), name
+ start
+ i
* scaling
, scaling
);
1458 hex
[(i
+1) * (scaling
+ 1) - 1] = '/';
1460 hex
[3 * (scaling
+ 1) - 1] = '\0';
1466 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1467 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1477 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1482 /* Otherwise, color is expected to be from a list */
1484 NSEnumerator
*lenum
, *cenum
;
1488 #ifdef NS_IMPL_GNUSTEP
1489 /* XXX: who is wrong, the requestor or the implementation? */
1490 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1492 nsname
= @"highlightColor"
;
1495 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1496 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1498 cenum
= [[clist allKeys
] objectEnumerator
];
1499 while ( (name
= [cenum nextObject
]) && new
== nil
)
1501 if ([name compare
: nsname
1502 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1503 new
= [clist colorWithKey
: name
];
1509 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1516 ns_get_color_default
(const
char *name
, NSColor
*dflt
)
1517 /* --------------------------------------------------------------------------
1518 Parse a color or use a default value
1519 -------------------------------------------------------------------------- */
1523 if (ns_get_color
(name
, &col
))
1531 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1532 /* --------------------------------------------------------------------------
1533 Convert a Lisp string object to a NS color
1534 -------------------------------------------------------------------------- */
1536 NSTRACE
(ns_lisp_to_color
);
1537 if (STRINGP
(color
))
1538 return ns_get_color
(SDATA
(color
), col
);
1539 else if (SYMBOLP
(color
))
1540 return ns_get_color
(SDATA
(SYMBOL_NAME
(color
)), col
);
1546 ns_color_to_lisp
(NSColor
*col
)
1547 /* --------------------------------------------------------------------------
1548 Convert a color to a lisp string with the RGB equivalent
1549 -------------------------------------------------------------------------- */
1551 CGFloat red
, green
, blue
, alpha
, gray;
1554 NSTRACE
(ns_color_to_lisp
);
1557 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1559 if ((str
=[[col colorNameComponent
] UTF8String
]))
1562 return build_string
((char *)str
);
1565 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1566 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1567 if (red
==green
&& red
==blue
)
1569 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1570 getWhite
: &gray alpha
: &alpha
];
1571 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1572 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1574 return build_string
(buf
);
1577 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1578 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1581 return build_string
(buf
);
1586 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1587 /* --------------------------------------------------------------------------
1588 Get ARGB values out of NSColor col and put them into color_def.
1589 If setPixel, set the pixel to a concatenated version.
1590 and set color_def pixel to the resulting index.
1591 -------------------------------------------------------------------------- */
1595 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1596 color_def
->red
= r
* 65535;
1597 color_def
->green
= g
* 65535;
1598 color_def
->blue
= b
* 65535;
1600 if (setPixel
== YES
)
1602 = ARGB_TO_ULONG
((int
)(a
*255),
1603 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1608 ns_defined_color
(struct frame
*f
,
1613 /* --------------------------------------------------------------------------
1614 Return 1 if named color found, and set color_def rgb accordingly.
1615 If makeIndex and alloc are nonzero put the color in the color_table,
1616 and set color_def pixel to the resulting index.
1617 If makeIndex is zero, set color_def pixel to ARGB.
1618 Return 0 if not found
1619 -------------------------------------------------------------------------- */
1622 NSTRACE
(ns_defined_color
);
1625 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1630 if (makeIndex
&& alloc
)
1631 color_def
->pixel
= ns_index_color
(col
, f
);
1632 ns_query_color
(col
, color_def
, !makeIndex
);
1639 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1640 /* --------------------------------------------------------------------------
1641 return an autoreleased RGB color
1642 -------------------------------------------------------------------------- */
1644 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1645 if (r
< 0.0) r
= 0.0;
1646 else if (r
> 1.0) r
= 1.0;
1647 if (g
< 0.0) g
= 0.0;
1648 else if (g
> 1.0) g
= 1.0;
1649 if (b
< 0.0) b
= 0.0;
1650 else if (b
> 1.0) b
= 1.0;
1651 if (a
< 0.0) a
= 0.0;
1652 else if (a
> 1.0) a
= 1.0;
1653 return (unsigned
long) ns_index_color
(
1654 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1659 x_set_frame_alpha
(struct frame
*f
)
1660 /* --------------------------------------------------------------------------
1661 change the entire-frame transparency
1662 -------------------------------------------------------------------------- */
1664 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1665 EmacsView
*view = FRAME_NS_VIEW
(f
);
1667 double alpha_min
= 1.0;
1669 if (dpyinfo
->x_highlight_frame
== f
)
1670 alpha
= f
->alpha
[0];
1672 alpha
= f
->alpha
[1];
1674 if (FLOATP
(Vframe_alpha_lower_limit
))
1675 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1676 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1677 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1681 else if (1.0 < alpha
)
1683 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1686 #ifdef NS_IMPL_COCOA
1687 [[view window
] setAlphaValue
: alpha
];
1692 /* ==========================================================================
1696 ========================================================================== */
1700 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1701 /* --------------------------------------------------------------------------
1702 Programmatically reposition mouse pointer in pixel coordinates
1703 -------------------------------------------------------------------------- */
1705 NSTRACE
(x_set_mouse_pixel_position
);
1708 /* FIXME: this does not work, and what about GNUstep? */
1709 #ifdef NS_IMPL_COCOA
1710 [FRAME_NS_VIEW
(f
) lockFocus
];
1711 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1712 [FRAME_NS_VIEW
(f
) unlockFocus
];
1719 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1720 /* --------------------------------------------------------------------------
1721 Programmatically reposition mouse pointer in character coordinates
1722 -------------------------------------------------------------------------- */
1726 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1727 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1729 if (pix_x
< 0) pix_x
= 0;
1730 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1732 if (pix_y
< 0) pix_y
= 0;
1733 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1735 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1740 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1741 /* ------------------------------------------------------------------------
1742 Called by EmacsView on mouseMovement events. Passes on
1743 to emacs mainstream code if we moved off of a rect of interest
1744 known as last_mouse_glyph.
1745 ------------------------------------------------------------------------ */
1747 // NSTRACE
(note_mouse_movement
);
1749 XSETFRAME
(last_mouse_motion_frame
, frame
);
1751 /* Note, this doesn't get called for enter/leave, since we don't have a
1752 position. Those are taken care of in the corresponding NSView methods. */
1754 /* has movement gone beyond last rect we were tracking? */
1755 if (x
< last_mouse_glyph.origin.x ||
1756 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1757 y
< last_mouse_glyph.origin.y ||
1758 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1760 ns_update_begin
(frame
);
1761 frame
->mouse_moved
= 1;
1762 note_mouse_highlight
(frame
, x
, y
);
1763 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1764 ns_update_end
(frame
);
1773 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1774 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1776 /* --------------------------------------------------------------------------
1777 External (hook): inform emacs about mouse position and hit parts.
1778 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1779 x & y should be position in the scrollbar (the whole bar, not the handle)
1780 and length of scrollbar respectively
1781 -------------------------------------------------------------------------- */
1786 Lisp_Object frame
, tail
;
1788 struct ns_display_info
*dpyinfo
;
1790 NSTRACE
(ns_mouse_position
);
1794 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1798 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1802 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1804 /* TODO: we do not use this path at the moment because drag events will
1805 go directly to the EmacsScroller. Leaving code in for now. */
1806 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1808 if (time
) *time
= last_mouse_movement_time
;
1809 last_mouse_scroll_bar
= nil
;
1813 /* Clear the mouse-moved flag for every frame on this display. */
1814 FOR_EACH_FRAME
(tail
, frame
)
1815 if (FRAME_NS_P
(XFRAME
(frame
))
1816 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1817 XFRAME
(frame
)->mouse_moved
= 0;
1819 last_mouse_scroll_bar
= nil
;
1820 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1821 f
= last_mouse_frame
;
1823 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1824 : SELECTED_FRAME
();
1826 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1828 view = FRAME_NS_VIEW
(*fp
);
1830 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1831 position
= [view convertPoint
: position fromView
: nil
];
1832 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1833 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1835 if (bar_window
) *bar_window
= Qnil
;
1836 if (part
) *part
= 0; /*scroll_bar_handle; */
1838 if (x
) XSETINT
(*x
, lrint
(position.x
));
1839 if (y
) XSETINT
(*y
, lrint
(position.y
));
1840 if (time
) *time
= last_mouse_movement_time
;
1850 ns_frame_up_to_date
(struct frame
*f
)
1851 /* --------------------------------------------------------------------------
1852 External (hook): Fix up mouse highlighting right after a full update.
1853 Some highlighting was deferred if GC was happening during
1854 note_mouse_highlight (), while other highlighting was deferred for update.
1855 -------------------------------------------------------------------------- */
1857 NSTRACE
(ns_frame_up_to_date
);
1861 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1862 if ((hlinfo
->mouse_face_deferred_gc || f
==hlinfo
->mouse_face_mouse_frame
)
1863 /*&& hlinfo->mouse_face_mouse_frame*/)
1867 if (hlinfo
->mouse_face_mouse_frame
)
1868 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1869 hlinfo
->mouse_face_mouse_x
,
1870 hlinfo
->mouse_face_mouse_y
);
1871 hlinfo
->mouse_face_deferred_gc
= 0;
1880 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1881 /* --------------------------------------------------------------------------
1882 External (RIF): set frame mouse pointer type.
1883 -------------------------------------------------------------------------- */
1885 NSTRACE
(ns_define_frame_cursor
);
1886 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1888 EmacsView
*view = FRAME_NS_VIEW
(f
);
1889 FRAME_POINTER_TYPE
(f
) = cursor
;
1890 [[view window
] invalidateCursorRectsForView
: view];
1891 /* Redisplay assumes this function also draws the changed frame
1892 cursor, but this function doesn't, so do it explicitly. */
1893 x_update_cursor
(f
, 1);
1899 /* ==========================================================================
1903 ========================================================================== */
1907 ns_convert_key
(unsigned code
)
1908 /* --------------------------------------------------------------------------
1909 Internal call used by NSView-keyDown.
1910 -------------------------------------------------------------------------- */
1912 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1913 / sizeof
(convert_ns_to_X_keysym
[0]));
1915 /* An array would be faster, but less easy to read. */
1916 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1917 if (code
== convert_ns_to_X_keysym
[keysym
])
1918 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1920 /* if decide to use keyCode and Carbon table, use this line:
1921 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1926 x_get_keysym_name
(int keysym
)
1927 /* --------------------------------------------------------------------------
1928 Called by keyboard.c. Not sure if the return val is important, except
1930 -------------------------------------------------------------------------- */
1932 static
char value
[16];
1933 NSTRACE
(x_get_keysym_name
);
1934 sprintf (value
, "
%d", keysym);
1940 /* ==========================================================================
1942 Block drawing operations
1944 ========================================================================== */
1948 ns_redraw_scroll_bars
(struct frame
*f
)
1952 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1953 NSTRACE
(ns_judge_scroll_bars
);
1954 for (i
=[subviews count
]-1; i
>= 0; i
--)
1956 view = [subviews objectAtIndex
: i
];
1957 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
1964 ns_clear_frame
(struct frame
*f
)
1965 /* --------------------------------------------------------------------------
1966 External (hook): Erase the entire frame
1967 -------------------------------------------------------------------------- */
1969 NSView
*view = FRAME_NS_VIEW
(f
);
1972 NSTRACE
(ns_clear_frame
);
1976 /* comes on initial frame because we have
1977 after-make-frame-functions = select-frame */
1978 if (!FRAME_DEFAULT_FACE
(f
))
1981 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
1983 output_cursor.hpos
= output_cursor.vpos
= 0;
1984 output_cursor.x
= -1;
1989 ns_focus
(f
, &r
, 1);
1990 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
1994 #ifdef NS_IMPL_COCOA
1995 [[view window
] display
]; /* redraw resize handle */
1998 /* as of 2006/11 or so this is now needed */
1999 ns_redraw_scroll_bars
(f
);
2005 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
2006 /* --------------------------------------------------------------------------
2007 External (RIF): Clear section of frame
2008 -------------------------------------------------------------------------- */
2010 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
2011 NSView
*view = FRAME_NS_VIEW
(f
);
2012 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
2017 NSTRACE
(ns_clear_frame_area
);
2019 r
= NSIntersectionRect
(r
, [view frame
]);
2020 ns_focus
(f
, &r
, 1);
2021 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
2023 #ifdef NS_IMPL_COCOA
2025 /* clip out the resize handle */
2026 NSWindow
*window
= [FRAME_NS_VIEW
(f
) window
];
2028 = [view convertRect
: ns_resize_handle_rect
(window
) fromView
: nil
];
2030 ir
= NSIntersectionRect
(r
, ir
);
2031 if (NSIsEmptyRect
(ir
))
2037 #ifdef NS_IMPL_COCOA
2041 NSRect r1
= r
, r2
= r
; /* upper and lower non-intersecting */
2042 r1.
size.height
-= ir.
size.height
;
2043 r2.origin.y
+= r1.
size.height
;
2044 r2.
size.width
-= ir.
size.width
;
2045 r2.
size.height
= ir.
size.height
;
2058 ns_scroll_run
(struct window
*w
, struct run
*run
)
2059 /* --------------------------------------------------------------------------
2060 External (RIF): Insert or delete n lines at line vpos
2061 -------------------------------------------------------------------------- */
2063 struct frame
*f
= XFRAME
(w
->frame
);
2064 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2066 NSTRACE
(ns_scroll_run
);
2068 /* begin copy from other terms */
2069 /* Get frame-relative bounding box of the text display area of W,
2070 without mode lines. Include in this box the left and right
2072 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2074 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2075 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2076 bottom_y
= y
+ height
;
2080 /* Scrolling up. Make sure we don't copy part of the mode
2081 line at the bottom. */
2082 if (from_y
+ run
->height
> bottom_y
)
2083 height
= bottom_y
- from_y
;
2085 height
= run
->height
;
2089 /* Scrolling down. Make sure we don't copy over the mode line.
2091 if (to_y
+ run
->height
> bottom_y
)
2092 height
= bottom_y
- to_y
;
2094 height
= run
->height
;
2096 /* end copy from other terms */
2107 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2108 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2109 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2111 ns_focus
(f
, &dstRect
, 1);
2112 NSCopyBits
(0, srcRect
, dstOrigin
);
2121 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2122 /* --------------------------------------------------------------------------
2123 External (RIF): preparatory to fringe update after text was updated
2124 -------------------------------------------------------------------------- */
2126 struct window
*w
= updated_window
;
2130 NSTRACE
(ns_after_update_window_line
);
2132 /* begin copy from other terms */
2135 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2136 desired_row
->redraw_fringe_bitmaps_p
= 1;
2138 /* When a window has disappeared, make sure that no rest of
2139 full-width rows stays visible in the internal border.
2140 Under NS this is drawn inside the fringes. */
2141 if (windows_or_buffers_changed
2142 && (f
= XFRAME
(w
->frame
),
2143 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2145 && (height
= desired_row
->visible_height
,
2148 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2150 /* Internal border is drawn below the tool bar. */
2151 if (WINDOWP
(f
->tool_bar_window
)
2152 && w
== XWINDOW
(f
->tool_bar_window
))
2154 /* end copy from other terms */
2157 if (!desired_row
->full_width_p
)
2159 int x1
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2160 + WINDOW_LEFT_FRINGE_WIDTH
(w
);
2161 int x2
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2162 + FRAME_PIXEL_WIDTH
(f
) - NS_SCROLL_BAR_WIDTH
(f
)
2163 - WINDOW_RIGHT_FRINGE_WIDTH
(w
)
2164 - FRAME_INTERNAL_BORDER_WIDTH
(f
);
2165 ns_clear_frame_area
(f
, x1
, y
, width
, height
);
2166 ns_clear_frame_area
(f
, x2
, y
, width
, height
);
2174 ns_shift_glyphs_for_insert
(struct frame
*f
,
2175 int x
, int y
, int width
, int height
,
2177 /* --------------------------------------------------------------------------
2178 External (RIF): copy an area horizontally, don't worry about clearing src
2179 -------------------------------------------------------------------------- */
2181 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2182 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2183 NSPoint dstOrigin
= dstRect.origin
;
2185 NSTRACE
(ns_shift_glyphs_for_insert
);
2187 ns_focus
(f
, &dstRect
, 1);
2188 NSCopyBits
(0, srcRect
, dstOrigin
);
2194 /* ==========================================================================
2196 Character encoding and metrics
2198 ========================================================================== */
2202 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2203 /* --------------------------------------------------------------------------
2204 External (RIF); compute left/right overhang of whole string and set in s
2205 -------------------------------------------------------------------------- */
2207 struct face
*face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2208 struct font
*font
= s
->font
; /*face->font; */
2212 struct font_metrics metrics
;
2213 unsigned int codes
[2];
2214 codes
[0] = *(s
->char2b
);
2215 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2217 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2218 s
->left_overhang
= -metrics.lbearing
;
2220 = metrics.rbearing
> metrics.width
2221 ? metrics.rbearing
- metrics.width
: 0;
2225 s
->left_overhang
= 0;
2226 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2227 FONT_HEIGHT
(font
) * 0.2 : 0;
2233 /* ==========================================================================
2235 Fringe and cursor drawing
2237 ========================================================================== */
2240 extern int max_used_fringe_bitmap
;
2242 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2243 struct draw_fringe_bitmap_params
*p
)
2244 /* --------------------------------------------------------------------------
2245 External (RIF); fringe-related
2246 -------------------------------------------------------------------------- */
2248 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2249 struct face
*face
= p
->face
;
2251 static EmacsImage
**bimgs
= NULL;
2252 static int nBimgs
= 0;
2253 /* NS-specific: move internal border inside fringe */
2254 int x
= p
->bx
< 0 ? p
->x
: p
->bx
;
2255 int wd
= p
->bx
< 0 ? p
->wd
: p
->nx
;
2256 BOOL fringeOnVeryLeft
2257 = x
- WINDOW_LEFT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
)
2258 - FRAME_INTERNAL_BORDER_WIDTH
(f
) < 10;
2259 BOOL fringeOnVeryRight
2260 = FRAME_PIXEL_WIDTH
(f
) - x
- wd
- FRAME_INTERNAL_BORDER_WIDTH
(f
)
2261 - WINDOW_RIGHT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
) < 10;
2262 int xAdjust
= FRAME_INTERNAL_BORDER_WIDTH
(f
) *
2263 (fringeOnVeryLeft ?
-1 : (fringeOnVeryRight ?
1 : 0));
2265 /* grow bimgs if needed */
2266 if (nBimgs
< max_used_fringe_bitmap
)
2268 bimgs
= xrealloc
(bimgs
, max_used_fringe_bitmap
* sizeof
*bimgs
);
2269 memset
(bimgs
+ nBimgs
, 0,
2270 (max_used_fringe_bitmap
- nBimgs
) * sizeof
*bimgs
);
2271 nBimgs
= max_used_fringe_bitmap
;
2274 /* Must clip because of partially visible lines. */
2275 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2276 ns_clip_to_row
(w
, row
, -1, YES
);
2278 if (p
->bx
>= 0 && !p
->overlay_p
)
2280 int yAdjust
= rowY
- FRAME_INTERNAL_BORDER_WIDTH
(f
) < 5 ?
2281 -FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0;
2282 int yIncr
= FRAME_PIXEL_HEIGHT
(f
) - (p
->by
+yAdjust
+ p
->ny
) < 5 ?
2283 FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0
2284 + (yAdjust ? FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0);
2285 NSRect r
= NSMakeRect
(p
->bx
+xAdjust
, p
->by
+yAdjust
, p
->nx
, p
->ny
+yIncr
);
2287 [ns_lookup_indexed_color
(face
->background
, f
) set];
2293 NSRect r
= NSMakeRect
(p
->x
+xAdjust
, p
->y
, p
->wd
, p
->h
);
2294 NSPoint pt
= r.origin
;
2295 EmacsImage
*img
= bimgs
[p
->which - 1];
2299 unsigned short
*bits
= p
->bits
+ p
->dh
;
2302 unsigned
char *cbits
= xmalloc
(len
);
2304 for (i
=0; i
<len
; i
++)
2305 cbits
[i
] = ~
(bits
[i
] & 0xff);
2306 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2308 bimgs
[p
->which - 1] = img
;
2313 /* Since we composite the bitmap instead of just blitting it, we need
2314 to erase the whole background. */
2315 [ns_lookup_indexed_color
(face
->background
, f
) set];
2318 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2319 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2326 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2327 int x
, int y
, int cursor_type
, int cursor_width
,
2328 int on_p
, int active_p
)
2329 /* --------------------------------------------------------------------------
2330 External call (RIF): draw cursor.
2331 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2332 -------------------------------------------------------------------------- */
2335 int fx
, fy
, h
, cursor_height
;
2336 struct frame
*f
= WINDOW_XFRAME
(w
);
2337 struct glyph
*phys_cursor_glyph
;
2339 struct glyph
*cursor_glyph
;
2341 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2343 /* If cursor is out of bounds, don't draw garbage. This can happen
2344 in mini-buffer windows when switching between echo area glyphs
2347 NSTRACE
(dumpcursor
);
2352 w
->phys_cursor_type
= cursor_type
;
2353 w
->phys_cursor_on_p
= on_p
;
2355 if (cursor_type
== NO_CURSOR
)
2357 w
->phys_cursor_width
= 0;
2361 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2363 if (glyph_row
->exact_window_width_line_p
2364 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2366 glyph_row
->cursor_in_fringe_p
= 1;
2367 draw_fringe_bitmap
(w
, glyph_row
, 0);
2372 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2373 (other terminals do it the other way round). We must set
2374 w->phys_cursor_width to the cursor width. For bar cursors, that
2375 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2376 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2378 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2379 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2380 if (cursor_type
== BAR_CURSOR
)
2382 if (cursor_width
< 1)
2383 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2384 w
->phys_cursor_width
= cursor_width
;
2386 /* If we have an HBAR, "cursor_width" MAY specify height. */
2387 else if (cursor_type
== HBAR_CURSOR
)
2389 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2390 fy
+= h
- cursor_height
;
2394 r.origin.x
= fx
, r.origin.y
= fy
;
2396 r.
size.width
= w
->phys_cursor_width
;
2398 /* FIXME: if we overwrite the internal border area, it does not get erased;
2399 fix by truncating cursor, but better would be to erase properly */
2400 overspill
= r.origin.x
+ r.
size.width
-
2401 WINDOW_TEXT_TO_FRAME_PIXEL_X
(w
, WINDOW_BOX_RIGHT_EDGE_X
(w
)
2402 - WINDOW_TOTAL_FRINGE_WIDTH
(w
) - FRAME_INTERNAL_BORDER_WIDTH
(f
));
2404 r.
size.width
-= overspill
;
2406 /* TODO: only needed in rare cases with last-resort font in HELLO..
2407 should we do this more efficiently? */
2408 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2411 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2412 if (face
&& NS_FACE_BACKGROUND
(face
)
2413 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2415 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2416 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2419 [FRAME_CURSOR_COLOR
(f
) set];
2421 #ifdef NS_IMPL_COCOA
2422 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2423 atomic. Cleaner ways of doing this should be investigated.
2424 One way would be to set a global variable DRAWING_CURSOR
2425 when making the call to draw_phys..(), don't focus in that
2426 case, then move the ns_unfocus() here after that call. */
2427 NSDisableScreenUpdates
();
2430 switch (cursor_type
)
2434 case FILLED_BOX_CURSOR
:
2437 case HOLLOW_BOX_CURSOR
:
2440 NSRectFill
(NSInsetRect
(r
, 1, 1));
2441 [FRAME_CURSOR_COLOR
(f
) set];
2448 /* If the character under cursor is R2L, draw the bar cursor
2449 on the right of its glyph, rather than on the left. */
2450 cursor_glyph
= get_phys_cursor_glyph
(w
);
2451 if ((cursor_glyph
->resolved_level
& 1) != 0)
2452 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2459 /* draw the character under the cursor */
2460 if (cursor_type
!= NO_CURSOR
)
2461 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2463 #ifdef NS_IMPL_COCOA
2464 NSEnableScreenUpdates
();
2471 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2472 /* --------------------------------------------------------------------------
2473 External (RIF): Draw a vertical line.
2474 -------------------------------------------------------------------------- */
2476 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2478 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2480 NSTRACE
(ns_draw_vertical_window_border
);
2482 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2484 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2486 ns_focus
(f
, &r
, 1);
2493 show_hourglass
(struct atimer
*timer
)
2495 if (hourglass_shown_p
)
2500 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2502 hourglass_shown_p
= 1;
2508 hide_hourglass
(void
)
2510 if (!hourglass_shown_p
)
2515 /* TODO: remove NSProgressIndicator from all frames */
2517 hourglass_shown_p
= 0;
2523 /* ==========================================================================
2525 Glyph drawing operations
2527 ========================================================================== */
2530 static inline NSRect
2531 ns_fix_rect_ibw
(NSRect r
, int fibw
, int frame_pixel_width
)
2532 /* --------------------------------------------------------------------------
2533 Under NS we draw internal borders inside fringes, and want full-width
2534 rendering to go all the way to edge. This function makes that correction.
2535 -------------------------------------------------------------------------- */
2537 if (r.origin.y
<= fibw
+1)
2539 r.
size.height
+= r.origin.y
;
2542 if (r.origin.x
<= fibw
+1)
2544 r.
size.width
+= r.origin.x
;
2547 if (frame_pixel_width
- (r.origin.x
+r.
size.width
) <= fibw
+1)
2548 r.
size.width
+= fibw
;
2555 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2556 /* --------------------------------------------------------------------------
2557 Wrapper utility to account for internal border width on full-width lines,
2558 and allow top full-width rows to hit the frame top. nr should be pointer
2559 to two successive NSRects. Number of rects actually used is returned.
2560 -------------------------------------------------------------------------- */
2562 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2563 if (s
->row
->full_width_p
)
2565 *nr
= ns_fix_rect_ibw
(*nr
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2566 FRAME_PIXEL_WIDTH
(s
->f
));
2568 *nr
= ns_fix_rect_ibw
(*(nr
+1), FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2569 FRAME_PIXEL_WIDTH
(s
->f
));
2574 /* --------------------------------------------------------------------
2575 Draw a wavy line under glyph string s. The wave fills wave_height
2582 wave_height = 3 | * * * *
2583 --------------------------------------------------------------------- */
2586 ns_draw_underwave
(struct glyph_string
*s
, CGFloat width
, CGFloat x
)
2588 int wave_height
= 3, wave_length
= 3;
2589 int y
, dx
, dy
, odd
, xmax
;
2594 dy
= wave_height
- 1;
2598 /* Find and set clipping rectangle */
2599 waveClip
= NSMakeRect
(x
, y
, width
, wave_height
);
2600 [[NSGraphicsContext currentContext
] saveGraphicsState
];
2601 NSRectClip
(waveClip
);
2603 /* Draw the waves */
2604 a.x
= x
- ((int
)(x
) % dx);
2606 odd
= (int
)(a.x
/dx
) % 2;
2616 [NSBezierPath strokeLineFromPoint
:a toPoint
:b
];
2617 a.x
= b.x
, a.y
= b.y
;
2618 b.x
+= dx
, b.y
= y
+ odd
*dy
;
2622 /* Restore previous clipping rectangle(s) */
2623 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
2629 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2630 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2631 /* --------------------------------------------------------------------------
2632 Draw underline, overline, and strike-through on glyph string s.
2633 -------------------------------------------------------------------------- */
2635 if (s
->for_overlaps
)
2639 if (face
->underline_p
)
2641 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2643 if (face
->underline_defaulted_p
)
2646 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2648 ns_draw_underwave
(s
, width
, x
);
2650 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2654 unsigned
long thickness
, position
;
2656 /* If the prev was underlined, match its appearance. */
2657 if (s
->prev
&& s
->prev
->face
->underline_p
2658 && s
->prev
->underline_thickness
> 0)
2660 thickness
= s
->prev
->underline_thickness
;
2661 position
= s
->prev
->underline_position
;
2666 unsigned
long descent
;
2669 descent
= s
->y
+ s
->height
- s
->ybase
;
2671 /* Use underline thickness of font, defaulting to 1. */
2672 thickness
= (font
&& font
->underline_thickness
> 0)
2673 ? font
->underline_thickness
: 1;
2675 /* Determine the offset of underlining from the baseline. */
2676 if (x_underline_at_descent_line
)
2677 position
= descent
- thickness
;
2678 else if (x_use_underline_position_properties
2679 && font
&& font
->underline_position
>= 0)
2680 position
= font
->underline_position
;
2682 position
= lround
(font
->descent
/ 2);
2684 position
= underline_minimum_offset
;
2686 position
= max (position
, underline_minimum_offset
);
2688 /* Ensure underlining is not cropped. */
2689 if (descent
<= position
)
2691 position
= descent
- 1;
2694 else if (descent
< position
+ thickness
)
2698 s
->underline_thickness
= thickness
;
2699 s
->underline_position
= position
;
2701 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2703 if (face
->underline_defaulted_p
)
2706 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2710 /* Do overline. We follow other terms in using a thickness of 1
2711 and ignoring overline_margin. */
2712 if (face
->overline_p
)
2715 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2717 if (face
->overline_color_defaulted_p
)
2720 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2724 /* Do strike-through. We follow other terms for thickness and
2725 vertical position.*/
2726 if (face
->strike_through_p
)
2731 dy
= lrint
((s
->height
- 1) / 2);
2732 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2734 if (face
->strike_through_color_defaulted_p
)
2737 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2743 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2744 /* --------------------------------------------------------------------------
2745 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2746 Note we can't just use an NSDrawRect command, because of the possibility
2747 of some sides not being drawn, and because the rect will be filled.
2748 -------------------------------------------------------------------------- */
2754 s.
size.height
= thickness
;
2756 s.origin.y
+= r.
size.height
- thickness
;
2759 s.
size.height
= r.
size.height
;
2760 s.origin.y
= r.origin.y
;
2762 /* left, right (optional) */
2763 s.
size.width
= thickness
;
2768 s.origin.x
+= r.
size.width
- thickness
;
2775 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2776 char top_p
, char bottom_p
, char left_p
, char right_p
,
2777 struct glyph_string
*s
)
2778 /* --------------------------------------------------------------------------
2779 Draw a relief rect inside r, optionally leaving some sides open.
2780 Note we can't just use an NSDrawBezel command, because of the possibility
2781 of some sides not being drawn, and because the rect will be filled.
2782 -------------------------------------------------------------------------- */
2784 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2785 NSColor
*newBaseCol
= nil
;
2788 NSTRACE
(ns_draw_relief
);
2792 if (s
->face
->use_box_color_for_shadows_p
)
2794 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2796 /* else if (s->first_glyph->type == IMAGE_GLYPH
2798 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2800 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2804 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2807 if (newBaseCol
== nil
)
2808 newBaseCol
= [NSColor grayColor
];
2810 if (newBaseCol
!= baseCol
) /* TODO: better check */
2813 baseCol
= [newBaseCol retain
];
2815 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2817 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2820 [(raised_p ? lightCol
: darkCol
) set];
2822 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2825 sr.
size.height
= thickness
;
2826 if (top_p
) NSRectFill
(sr
);
2829 sr.
size.height
= r.
size.height
;
2830 sr.
size.width
= thickness
;
2831 if (left_p
) NSRectFill
(sr
);
2833 [(raised_p ? darkCol
: lightCol
) set];
2836 sr.
size.width
= r.
size.width
;
2837 sr.
size.height
= thickness
;
2838 sr.origin.y
+= r.
size.height
- thickness
;
2839 if (bottom_p
) NSRectFill
(sr
);
2842 sr.
size.height
= r.
size.height
;
2843 sr.origin.y
= r.origin.y
;
2844 sr.
size.width
= thickness
;
2845 sr.origin.x
+= r.
size.width
- thickness
;
2846 if (right_p
) NSRectFill
(sr
);
2851 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2852 /* --------------------------------------------------------------------------
2853 Function modeled after x_draw_glyph_string_box ().
2854 Sets up parameters for drawing.
2855 -------------------------------------------------------------------------- */
2857 int right_x
, last_x
;
2858 char left_p
, right_p
;
2859 struct glyph
*last_glyph
;
2864 if (s
->hl
== DRAW_MOUSE_FACE
)
2866 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2868 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2873 thickness
= face
->box_line_width
;
2875 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2877 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2878 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2879 : window_box_right
(s
->w
, s
->area
));
2880 last_glyph
= (s
->cmp || s
->img
2881 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2883 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2884 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2886 left_p
= (s
->first_glyph
->left_box_line_p
2887 ||
(s
->hl
== DRAW_MOUSE_FACE
2888 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2889 right_p
= (last_glyph
->right_box_line_p
2890 ||
(s
->hl
== DRAW_MOUSE_FACE
2891 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2893 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2895 /* expand full-width row over internal borders */
2896 if (s
->row
->full_width_p
)
2897 r
= ns_fix_rect_ibw
(r
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2898 FRAME_PIXEL_WIDTH
(s
->f
));
2900 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2901 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2903 ns_draw_box
(r
, abs (thickness
),
2904 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2909 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2910 1, 1, left_p
, right_p
, s
);
2916 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2917 /* --------------------------------------------------------------------------
2918 Modeled after x_draw_glyph_string_background, which draws BG in
2919 certain cases. Others are left to the text rendering routine.
2920 -------------------------------------------------------------------------- */
2922 NSTRACE
(ns_maybe_dumpglyphs_background
);
2924 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2926 int box_line_width
= max (s
->face
->box_line_width
, 0);
2927 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2928 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2931 if (s
->hl
== DRAW_MOUSE_FACE
)
2933 face
= FACE_FROM_ID
(s
->f
,
2934 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2936 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2939 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2941 [(NS_FACE_BACKGROUND
(face
) != 0
2942 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2943 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2946 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2947 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2950 if (s
->hl
!= DRAW_CURSOR
)
2952 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2953 s
->background_width
,
2954 s
->height
-2*box_line_width
);
2956 /* expand full-width row over internal borders */
2957 if (s
->row
->full_width_p
)
2959 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
2960 if (r.origin.y
<= fibw
+1 + box_line_width
)
2962 r.
size.height
+= r.origin.y
;
2965 if (r.origin.x
<= fibw
+1)
2967 r.
size.width
+= 2*r.origin.x
;
2970 if (FRAME_PIXEL_WIDTH
(s
->f
) - (r.origin.x
+ r.
size.width
)
2972 r.
size.width
+= fibw
;
2978 s
->background_filled_p
= 1;
2985 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2986 /* --------------------------------------------------------------------------
2987 Renders an image and associated borders.
2988 -------------------------------------------------------------------------- */
2990 EmacsImage
*img
= s
->img
->pixmap
;
2991 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2992 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2993 int bg_x
, bg_y
, bg_height
;
3000 NSTRACE
(ns_dumpglyphs_image
);
3002 if (s
->face
->box
!= FACE_NO_BOX
3003 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
3004 x
+= abs (s
->face
->box_line_width
);
3007 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
3008 bg_height
= s
->height
;
3009 /* other terms have this, but was causing problems w/tabbar mode */
3010 /* - 2 * box_line_vwidth; */
3012 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
3013 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
3015 /* Draw BG: if we need larger area than image itself cleared, do that,
3016 otherwise, since we composite the image under NS (instead of mucking
3017 with its background color), we must clear just the image area. */
3018 if (s
->hl
== DRAW_MOUSE_FACE
)
3020 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3022 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3025 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3027 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
3029 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
3030 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
3032 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
3033 s
->background_filled_p
= 1;
3037 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3040 /* expand full-width row over internal borders */
3041 if (s
->row
->full_width_p
)
3043 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
3044 if (br.origin.y
<= fibw
+1 + box_line_vwidth
)
3046 br.
size.height
+= br.origin.y
;
3049 if (br.origin.x
<= fibw
+1 + box_line_vwidth
)
3051 br.
size.width
+= br.origin.x
;
3054 if (FRAME_PIXEL_WIDTH
(s
->f
) - (br.origin.x
+ br.
size.width
) <= fibw
+1)
3055 br.
size.width
+= fibw
;
3060 /* Draw the image.. do we need to draw placeholder if img ==nil? */
3062 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
3063 operation
: NSCompositeSourceOver
];
3065 if (s
->hl
== DRAW_CURSOR
)
3067 [FRAME_CURSOR_COLOR
(s
->f
) set];
3068 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3069 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3071 /* Currently on NS img->mask is always 0. Since
3072 get_window_cursor_type specifies a hollow box cursor when on
3073 a non-masked image we never reach this clause. But we put it
3074 in in anticipation of better support for image masks on
3076 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3080 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3083 /* Draw underline, overline, strike-through. */
3084 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3086 /* Draw relief, if requested */
3087 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3089 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3091 th
= tool_bar_button_relief
>= 0 ?
3092 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3093 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3097 th
= abs (s
->img
->relief
);
3098 raised_p
= (s
->img
->relief
> 0);
3101 r.origin.x
= x
- th
;
3102 r.origin.y
= y
- th
;
3103 r.
size.width
= s
->slice.width
+ 2*th
-1;
3104 r.
size.height
= s
->slice.height
+ 2*th
-1;
3105 ns_draw_relief
(r
, th
, raised_p
,
3107 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3109 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3112 /* If there is no mask, the background won't be seen,
3113 so draw a rectangle on the image for the cursor.
3114 Do this for all images, getting transparency right is not reliable. */
3115 if (s
->hl
== DRAW_CURSOR
)
3117 int thickness
= abs (s
->img
->relief
);
3118 if (thickness
== 0) thickness
= 1;
3119 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3125 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3130 NSColor
*fgCol
, *bgCol
;
3132 if (!s
->background_filled_p
)
3134 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3135 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3137 ns_focus
(s
->f
, r
, n
);
3139 if (s
->hl
== DRAW_MOUSE_FACE
)
3141 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3143 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3146 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3148 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3149 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3153 if (!s
->row
->full_width_p
)
3155 int overrun
, leftoverrun
;
3157 /* truncate to avoid overwriting fringe and/or scrollbar */
3158 overrun
= max (0, (s
->x
+ s
->background_width
)
3159 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3160 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3161 r
[i
].
size.width
-= overrun
;
3163 /* truncate to avoid overwriting to left of the window box */
3164 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3165 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3167 if (leftoverrun
> 0)
3169 r
[i
].origin.x
+= leftoverrun
;
3170 r
[i
].
size.width
-= leftoverrun
;
3173 /* XXX: Try to work between problem where a stretch glyph on
3174 a partially-visible bottom row will clear part of the
3175 modeline, and another where list-buffers headers and similar
3176 rows erroneously have visible_height set to 0. Not sure
3177 where this is coming from as other terms seem not to show. */
3178 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3181 /* expand full-width rows over internal borders */
3184 r
[i
] = ns_fix_rect_ibw
(r
[i
], FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
3185 FRAME_PIXEL_WIDTH
(s
->f
));
3190 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3191 overwriting cursor (usually when cursor on a tab) */
3192 if (s
->hl
== DRAW_CURSOR
)
3197 width
= s
->w
->phys_cursor_width
;
3198 r
[i
].
size.width
-= width
;
3199 r
[i
].origin.x
+= width
;
3203 /* Draw overlining, etc. on the cursor. */
3204 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3205 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3207 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3214 /* Draw overlining, etc. on the stretch glyph (or the part
3215 of the stretch glyph after the cursor). */
3216 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3220 s
->background_filled_p
= 1;
3226 ns_draw_glyph_string
(struct glyph_string
*s
)
3227 /* --------------------------------------------------------------------------
3228 External (RIF): Main draw-text call.
3229 -------------------------------------------------------------------------- */
3231 /* TODO (optimize): focus for box and contents draw */
3234 char box_drawn_p
= 0;
3236 NSTRACE
(ns_draw_glyph_string
);
3238 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3241 struct glyph_string
*next
;
3243 for (width
= 0, next
= s
->next
;
3244 next
&& width
< s
->right_overhang
;
3245 width
+= next
->width
, next
= next
->next
)
3246 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3248 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3250 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3251 ns_focus
(s
->f
, r
, n
);
3252 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3257 ns_dumpglyphs_stretch
(s
->next
);
3259 next
->num_clips
= 0;
3263 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3264 && (s
->first_glyph
->type == CHAR_GLYPH
3265 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3267 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3268 ns_focus
(s
->f
, r
, n
);
3269 ns_maybe_dumpglyphs_background
(s
, 1);
3270 ns_dumpglyphs_box_or_relief
(s
);
3275 switch (s
->first_glyph
->type)
3279 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3280 ns_focus
(s
->f
, r
, n
);
3281 ns_dumpglyphs_image
(s
, r
[0]);
3286 ns_dumpglyphs_stretch
(s
);
3290 case COMPOSITE_GLYPH
:
3291 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3292 ns_focus
(s
->f
, r
, n
);
3294 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3295 && ! s
->first_glyph
->u.cmp.automatic
))
3296 s
->background_filled_p
= 1;
3298 ns_maybe_dumpglyphs_background
3299 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3301 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3302 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3303 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3304 NS_DUMPGLYPH_NORMAL
));
3305 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3306 if (ns_tmp_font
== NULL)
3307 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3309 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3311 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3312 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3313 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3316 ns_tmp_font
->font.driver
->draw
3317 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3318 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3319 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
3321 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3323 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3324 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3325 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3331 case GLYPHLESS_GLYPH
:
3332 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3333 ns_focus
(s
->f
, r
, n
);
3335 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3336 && ! s
->first_glyph
->u.cmp.automatic
))
3337 s
->background_filled_p
= 1;
3339 ns_maybe_dumpglyphs_background
3340 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3342 /* Not yet implemented. */
3351 /* Draw box if not done already. */
3352 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3354 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3355 ns_focus
(s
->f
, r
, n
);
3356 ns_dumpglyphs_box_or_relief
(s
);
3365 /* ==========================================================================
3369 ========================================================================== */
3373 ns_send_appdefined
(int value
)
3374 /* --------------------------------------------------------------------------
3375 Internal: post an appdefined event which EmacsApp-sendEvent will
3376 recognize and take as a command to halt the event loop.
3377 -------------------------------------------------------------------------- */
3379 /*NSTRACE (ns_send_appdefined); */
3381 /* Only post this event if we haven't already posted one. This will end
3382 the [NXApp run] main loop after having processed all events queued at
3384 if (send_appdefined
)
3388 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3389 send_appdefined
= NO
;
3391 /* Don't need wakeup timer any more */
3394 [timed_entry invalidate
];
3395 [timed_entry release
];
3399 /* Ditto for file descriptor poller */
3402 [fd_entry invalidate
];
3407 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3408 location
: NSMakePoint
(0, 0)
3411 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3412 context
: [NSApp context
]
3417 /* Post an application defined event on the event queue. When this is
3418 received the [NXApp run] will return, thus having processed all
3419 events which are currently queued. */
3420 [NSApp postEvent
: nxev atStart
: NO
];
3426 ns_read_socket
(struct terminal *terminal, int expected
,
3427 struct input_event
*hold_quit
)
3428 /* --------------------------------------------------------------------------
3429 External (hook): Post an event to ourself and keep reading events until
3430 we read it back again. In effect process all events which were waiting.
3431 From 21+ we have to manage the event buffer ourselves.
3432 -------------------------------------------------------------------------- */
3434 struct input_event ev
;
3437 /* NSTRACE (ns_read_socket); */
3439 if (interrupt_input_blocked
)
3441 interrupt_input_pending
= 1;
3443 pending_signals
= 1;
3448 interrupt_input_pending
= 0;
3450 pending_signals
= pending_atimers
;
3454 n_emacs_events_pending
= 0;
3457 q_event_ptr
= hold_quit
;
3459 /* we manage autorelease pools by allocate/reallocate each time around
3460 the loop; strict nesting is occasionally violated but seems not to
3461 matter.. earlier methods using full nesting caused major memory leaks */
3462 [outerpool release
];
3463 outerpool
= [[NSAutoreleasePool alloc
] init
];
3465 /* If have pending open-file requests, attend to the next one of those. */
3466 if (ns_pending_files
&& [ns_pending_files count
] != 0
3467 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3469 [ns_pending_files removeObjectAtIndex
: 0];
3471 /* Deal with pending service requests. */
3472 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3474 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3475 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3477 [ns_pending_service_names removeObjectAtIndex
: 0];
3478 [ns_pending_service_args removeObjectAtIndex
: 0];
3482 /* Run and wait for events. We must always send one NX_APPDEFINED event
3483 to ourself, otherwise [NXApp run] will never exit. */
3484 send_appdefined
= YES
;
3486 /* If called via ns_select, this is called once with expected=1,
3487 because we expect either the timeout or file descriptor activity.
3488 In this case the first event through will either be real input or
3489 one of these. read_avail_input() then calls once more with expected=0
3490 and in that case we need to return quickly if there is nothing.
3491 If we're being called outside of that, it's also OK to return quickly
3492 after one iteration through the event loop, since other terms do
3493 this and emacs expects it. */
3494 if (!(inNsSelect
&& expected
))
3496 /* Post an application defined event on the event queue. When this is
3497 received the [NXApp run] will return, thus having processed all
3498 events which are currently queued, if any. */
3499 ns_send_appdefined
(-1);
3505 nevents
= n_emacs_events_pending
;
3506 n_emacs_events_pending
= 0;
3507 emacs_event
= q_event_ptr
= NULL;
3515 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3516 fd_set
*exceptfds
, EMACS_TIME
*timeout
, sigset_t
*sigmask
)
3517 /* --------------------------------------------------------------------------
3518 Replacement for select, checking for events
3519 -------------------------------------------------------------------------- */
3524 struct timespec select_timeout
;
3526 /* NSTRACE (ns_select); */
3528 if (NSApp
== nil || inNsSelect
== 1 /* || ([NSApp isActive] == NO &&
3529 [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil
3530 inMode:NSDefaultRunLoopMode dequeue:NO] == nil) */)
3531 return pselect
(nfds
, readfds
, writefds
, exceptfds
, timeout
, sigmask
);
3533 /* Save file descriptor set, which gets overwritten in calls to select ()
3534 Note, this is called from process.c, and only readfds is ever set */
3537 memcpy
(&select_readfds
, readfds
, sizeof
(fd_set
));
3543 /* Try an initial select for pending data on input files */
3544 select_timeout.tv_sec
= select_timeout.tv_nsec
= 0;
3545 result
= pselect
(nfds
, readfds
, writefds
, exceptfds
,
3546 &select_timeout
, sigmask
);
3550 /* if (!timeout || timed_entry || fd_entry)
3551 fprintf (stderr, "assertion failed: timeout null or timed_entry/fd_entry non-null in ns_select\n"); */
3553 /* set a timeout and run the main AppKit event loop while continuing
3554 to monitor the files */
3555 time
= EMACS_TIME_TO_DOUBLE
(*timeout
);
3556 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3558 selector
: @selector
(timeout_handler
:)
3560 repeats
: YES
] /* for safe removal */
3563 /* set a periodic task to try the pselect () again */
3564 fd_entry
= [[NSTimer scheduledTimerWithTimeInterval
: 0.1
3566 selector
: @selector
(fd_handler
:)
3571 /* Let Application dispatch events until it receives an event of the type
3572 NX_APPDEFINED, which should only be sent by timeout_handler.
3573 We tell read_avail_input() that input is "expected" because we do expect
3574 either the timeout or fd handler to fire, and if they don't, the original
3575 call from process.c that got us here expects us to wait until some input
3579 ev
= last_appdefined_event
;
3585 if ([ev
type] != NSApplicationDefined
)
3589 last_appdefined_event
= 0;
3593 /* The NX_APPDEFINED event we received was a timeout. */
3598 /* The NX_APPDEFINED event we received was the result of
3599 at least one real input event arriving. */
3605 /* Received back from pselect () in fd_handler; copy the results */
3607 memcpy
(readfds
, &select_readfds
, sizeof
(fd_set
));
3611 /* never reached, shut compiler up */
3617 /* ==========================================================================
3621 ========================================================================== */
3625 ns_set_vertical_scroll_bar
(struct window
*window
,
3626 int portion
, int whole
, int position
)
3627 /* --------------------------------------------------------------------------
3628 External (hook): Update or add scrollbar
3629 -------------------------------------------------------------------------- */
3633 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3634 EmacsView
*view = FRAME_NS_VIEW
(f
);
3635 int window_y
, window_height
;
3636 BOOL barOnVeryLeft
, barOnVeryRight
;
3637 int top
, left
, height
, width
, sb_width
, sb_left
;
3639 static int count
= 0;
3641 /* optimization; display engine sends WAY too many of these.. */
3642 if (!NILP
(window
->vertical_scroll_bar
))
3644 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3645 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3647 if (view->scrollbarsNeedingUpdate
== 0)
3649 if (!windows_or_buffers_changed
)
3653 view->scrollbarsNeedingUpdate
--;
3657 NSTRACE
(ns_set_vertical_scroll_bar
);
3659 /* Get dimensions. */
3660 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3662 height
= window_height
;
3663 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3664 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3666 if (top
< 5) /* top scrollbar adjustment */
3668 top
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3669 height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3672 /* allow for displaying a skinnier scrollbar than char area allotted */
3673 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3674 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3676 barOnVeryLeft
= left
< 5;
3677 barOnVeryRight
= FRAME_PIXEL_WIDTH
(f
) - left
- width
< 5;
3678 sb_left
= left
+ FRAME_INTERNAL_BORDER_WIDTH
(f
)
3679 * (barOnVeryLeft ?
-1 : (barOnVeryRight ?
1 : 0));
3681 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3682 /* the parent view is flipped, so we need to flip y value */
3684 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3686 XSETWINDOW
(win
, window
);
3689 /* we want at least 5 lines to display a scrollbar */
3690 if (WINDOW_TOTAL_LINES
(window
) < 5)
3692 if (!NILP
(window
->vertical_scroll_bar
))
3694 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3695 [bar removeFromSuperview
];
3696 window
->vertical_scroll_bar
= Qnil
;
3698 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3703 if (NILP
(window
->vertical_scroll_bar
))
3705 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3706 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3707 window
->vertical_scroll_bar
= make_save_value
(bar, 0);
3712 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3713 oldRect
= [bar frame
];
3714 r.
size.width
= oldRect.
size.width
;
3715 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3717 if (oldRect.origin.x
!= r.origin.x
)
3718 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3723 [bar setPosition
: position portion
: portion whole
: whole
];
3729 ns_condemn_scroll_bars
(struct frame
*f
)
3730 /* --------------------------------------------------------------------------
3731 External (hook): arrange for all frame's scrollbars to be removed
3732 at next call to judge_scroll_bars, except for those redeemed.
3733 -------------------------------------------------------------------------- */
3737 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3739 NSTRACE
(ns_condemn_scroll_bars
);
3741 for (i
=[subviews count
]-1; i
>= 0; i
--)
3743 view = [subviews objectAtIndex
: i
];
3744 if ([view isKindOfClass
: [EmacsScroller
class]])
3751 ns_redeem_scroll_bar
(struct window
*window
)
3752 /* --------------------------------------------------------------------------
3753 External (hook): arrange to spare this window's scrollbar
3754 at next call to judge_scroll_bars.
3755 -------------------------------------------------------------------------- */
3758 NSTRACE
(ns_redeem_scroll_bar
);
3759 if (!NILP
(window
->vertical_scroll_bar
))
3761 bar =XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3768 ns_judge_scroll_bars
(struct frame
*f
)
3769 /* --------------------------------------------------------------------------
3770 External (hook): destroy all scrollbars on frame that weren't
3771 redeemed after call to condemn_scroll_bars.
3772 -------------------------------------------------------------------------- */
3776 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3777 NSTRACE
(ns_judge_scroll_bars
);
3778 for (i
=[subviews count
]-1; i
>= 0; i
--)
3780 view = [subviews objectAtIndex
: i
];
3781 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3788 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3790 /* XXX irrelevant under NS */
3795 /* ==========================================================================
3799 ========================================================================== */
3802 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3804 NSScreen
*screen
= [NSScreen mainScreen
];
3805 return [screen frame
].
size.height
;
3809 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3811 NSScreen
*screen
= [NSScreen mainScreen
];
3812 return [screen frame
].
size.width
;
3816 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3817 /* --------------------------------------------------------------------------
3818 Convert modifier name to lisp symbol
3819 -------------------------------------------------------------------------- */
3821 if (!strncmp
(SDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3823 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3825 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3827 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3829 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3831 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3838 static Lisp_Object ns_mod_to_lisp
(int m
)
3839 /* --------------------------------------------------------------------------
3840 Convert modifier code (see lisp.h) to lisp symbol
3841 -------------------------------------------------------------------------- */
3845 else if (m
== CHAR_SUPER
)
3847 else if (m
== CHAR_CTL
)
3849 else if (m
== CHAR_ALT
)
3851 else if (m
== CHAR_HYPER
)
3853 else /* if (m == 0) */
3859 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3860 Lisp_Object yesval
, Lisp_Object noval
,
3861 BOOL is_float
, BOOL is_modstring
)
3862 /* --------------------------------------------------------------------------
3863 Check a parameter value in user's preferences
3864 -------------------------------------------------------------------------- */
3866 const
char *value
= ns_get_defaults_value
(parameter
);
3872 if (c_strcasecmp
(value
, "YES"
) == 0)
3874 else if (c_strcasecmp
(value
, "NO"
) == 0)
3876 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3877 *result
= make_float
(f
);
3878 else if (is_modstring
&& value
)
3879 *result
= ns_string_to_lispmod
(value
);
3880 else fprintf (stderr
,
3881 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3887 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3888 /* --------------------------------------------------------------------------
3889 Initialize global info and storage for display.
3890 -------------------------------------------------------------------------- */
3892 NSScreen
*screen
= [NSScreen mainScreen
];
3893 NSWindowDepth depth
= [screen depth
];
3894 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
3896 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3897 dpyinfo
->resy
= 72.27;
3898 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3899 NSColorSpaceFromDepth
(depth
)]
3900 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3901 NSColorSpaceFromDepth
(depth
)];
3902 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3903 dpyinfo
->image_cache
= make_image_cache
();
3904 dpyinfo
->color_table
= xmalloc
(sizeof
*dpyinfo
->color_table
);
3905 dpyinfo
->color_table
->colors
= NULL;
3906 dpyinfo
->root_window
= 42; /* a placeholder.. */
3908 hlinfo
->mouse_face_mouse_frame
= NULL;
3909 hlinfo
->mouse_face_deferred_gc
= 0;
3910 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
3911 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
3912 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3913 hlinfo
->mouse_face_window
= hlinfo
->mouse_face_overlay
= Qnil
;
3914 hlinfo
->mouse_face_hidden
= 0;
3916 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
3917 hlinfo
->mouse_face_defer
= 0;
3919 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3921 dpyinfo
->n_fonts
= 0;
3922 dpyinfo
->smallest_font_height
= 1;
3923 dpyinfo
->smallest_char_width
= 1;
3927 /* This and next define (many of the) public functions in this file. */
3928 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3929 with using despite presence in the "system dependent" redisplay
3930 interface. In addition, many of the ns_ methods have code that is
3931 shared with all terms, indicating need for further refactoring. */
3932 extern frame_parm_handler ns_frame_parm_handlers
[];
3933 static
struct redisplay_interface ns_redisplay_interface
=
3935 ns_frame_parm_handlers
,
3939 x_clear_end_of_line
,
3941 ns_after_update_window_line
,
3942 ns_update_window_begin
,
3943 ns_update_window_end
,
3946 0, /* flush_display_optional */
3947 x_clear_window_mouse_face
,
3948 x_get_glyph_overhangs
,
3949 x_fix_overlapping_area
,
3950 ns_draw_fringe_bitmap
,
3951 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3952 0, /* destroy_fringe_bitmap */
3953 ns_compute_glyph_string_overhangs
,
3954 ns_draw_glyph_string
, /* interface to nsfont.m */
3955 ns_define_frame_cursor
,
3956 ns_clear_frame_area
,
3957 ns_draw_window_cursor
,
3958 ns_draw_vertical_window_border
,
3959 ns_shift_glyphs_for_insert
3964 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3970 /* This function is called when the last frame on a display is deleted. */
3972 ns_delete_terminal
(struct terminal *terminal)
3974 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3977 /* Protect against recursive calls. delete_frame in
3978 delete_terminal calls us back when it deletes our last frame. */
3979 if (!terminal->name
)
3984 x_destroy_all_bitmaps
(dpyinfo
);
3985 ns_delete_display
(dpyinfo
);
3990 static
struct terminal *
3991 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3992 /* --------------------------------------------------------------------------
3993 Set up use of NS before we make the first connection.
3994 -------------------------------------------------------------------------- */
3996 struct terminal *terminal;
3998 NSTRACE
(ns_create_terminal
);
4000 terminal = create_terminal
();
4002 terminal->type = output_ns
;
4003 terminal->display_info.ns
= dpyinfo
;
4004 dpyinfo
->terminal = terminal;
4006 terminal->rif
= &ns_redisplay_interface
;
4008 terminal->clear_frame_hook
= ns_clear_frame
;
4009 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
4010 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
4011 terminal->ring_bell_hook
= ns_ring_bell
;
4012 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
4013 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
4014 terminal->update_begin_hook
= ns_update_begin
;
4015 terminal->update_end_hook
= ns_update_end
;
4016 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
4017 terminal->read_socket_hook
= ns_read_socket
;
4018 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
4019 terminal->mouse_position_hook
= ns_mouse_position
;
4020 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
4021 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
4023 terminal->fullscreen_hook
= 0; /* see XTfullscreen_hook */
4025 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
4026 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
4027 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
4028 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
4030 terminal->delete_frame_hook
= x_destroy_window
;
4031 terminal->delete_terminal_hook
= ns_delete_terminal
;
4033 terminal->scroll_region_ok
= 1;
4034 terminal->char_ins_del_ok
= 1;
4035 terminal->line_ins_del_ok
= 1;
4036 terminal->fast_clear_end_of_line
= 1;
4037 terminal->memory_below_frame
= 0;
4043 struct ns_display_info
*
4044 ns_term_init
(Lisp_Object display_name
)
4045 /* --------------------------------------------------------------------------
4046 Start the Application and get things rolling.
4047 -------------------------------------------------------------------------- */
4049 struct terminal *terminal;
4050 struct ns_display_info
*dpyinfo
;
4051 static int ns_initialized
= 0;
4054 NSTRACE
(ns_term_init
);
4056 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
4057 /*GSDebugAllocationActive (YES); */
4059 handling_signal
= 0;
4061 if (!ns_initialized
)
4064 Fset_input_interrupt_mode
(Qnil
);
4068 ns_pending_files
= [[NSMutableArray alloc
] init
];
4069 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
4070 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
4072 /* Start app and create the main menu, window, view.
4073 Needs to be here because ns_initialize_display_info () uses AppKit classes.
4074 The view will then ask the NSApp to stop and return to Emacs. */
4075 [EmacsApp sharedApplication
];
4078 [NSApp setDelegate
: NSApp
];
4080 /* debugging: log all notifications */
4081 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4082 selector: @selector (logNotification:)
4083 name: nil object: nil]; */
4085 dpyinfo
= xzalloc
(sizeof
*dpyinfo
);
4087 ns_initialize_display_info
(dpyinfo
);
4088 terminal = ns_create_terminal
(dpyinfo
);
4090 terminal->kboard
= xmalloc
(sizeof
*terminal->kboard
);
4091 init_kboard
(terminal->kboard
);
4092 KVAR
(terminal->kboard
, Vwindow_system
) = Qns
;
4093 terminal->kboard
->next_kboard
= all_kboards
;
4094 all_kboards
= terminal->kboard
;
4095 /* Don't let the initial kboard remain current longer than necessary.
4096 That would cause problems if a file loaded on startup tries to
4097 prompt in the mini-buffer. */
4098 if (current_kboard
== initial_kboard
)
4099 current_kboard
= terminal->kboard
;
4100 terminal->kboard
->reference_count
++;
4102 dpyinfo
->next
= x_display_list
;
4103 x_display_list
= dpyinfo
;
4105 /* Put it on ns_display_name_list */
4106 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
4107 ns_display_name_list
);
4108 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
4110 /* Set the name of the terminal. */
4111 terminal->name
= xmalloc
(SBYTES
(display_name
) + 1);
4112 strncpy
(terminal->name
, SDATA
(display_name
), SBYTES
(display_name
));
4113 terminal->name
[SBYTES
(display_name
)] = 0;
4117 if (!inhibit_x_resources
)
4119 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4122 /* this is a standard variable */
4123 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4124 make_float
(10.0), make_float
(6.0), YES
, NO
);
4125 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4128 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
4129 stringForKey
: @"AppleHighlightColor"
];
4130 if (ns_selection_color
== nil
)
4131 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
4134 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4138 Lisp_Object color_file
, color_map
, color
;
4143 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4144 Fsymbol_value
(intern
("data
-directory"
)));
4145 if (NILP
(Ffile_readable_p
(color_file
)))
4146 fatal
("Could not
find %s.\n", SDATA (color_file));
4148 color_map
= Fx_load_color_file
(color_file
);
4149 if (NILP
(color_map
))
4150 fatal
("Could not read
%s.\n", SDATA (color_file));
4152 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4153 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4155 color
= XCAR
(color_map
);
4156 name
= SDATA
(XCAR
(color
));
4157 c
= XINT
(XCDR
(color
));
4159 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4160 green
: GREEN_FROM_ULONG
(c
) / 255.0
4161 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4163 forKey
: [NSString stringWithUTF8String
: name
]];
4165 [cl writeToFile
: nil
];
4171 #ifdef NS_IMPL_GNUSTEP
4172 strncpy
(c
, gnustep_base_version
, sizeof
(c
));
4174 /*PSnextrelease (128, c); */
4175 snprintf
(c
, sizeof
(c
), "
%g", NSAppKitVersionNumber);
4177 Vwindow_system_version
= build_string
(c
);
4180 delete_keyboard_wait_descriptor
(0);
4182 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4184 /* Set up OS X app menu */
4185 #ifdef NS_IMPL_COCOA
4189 /* set up the application menu */
4190 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4191 [svcsMenu setAutoenablesItems
: NO
];
4192 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4193 [appMenu setAutoenablesItems
: NO
];
4194 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4195 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4197 [appMenu insertItemWithTitle
: @"About Emacs"
4198 action
: @selector
(orderFrontStandardAboutPanel
:)
4201 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4202 [appMenu insertItemWithTitle
: @"Preferences..."
4203 action
: @selector
(showPreferencesWindow
:)
4206 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4207 item
= [appMenu insertItemWithTitle
: @"Services"
4208 action
: @selector
(menuDown
:)
4211 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4212 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4213 [appMenu insertItemWithTitle
: @"Hide Emacs"
4214 action
: @selector
(hide
:)
4217 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4218 action
: @selector
(hideOtherApplications
:)
4221 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4222 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4223 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4224 action
: @selector
(terminate
:)
4228 item
= [mainMenu insertItemWithTitle
: ns_app_name
4229 action
: @selector
(menuDown
:)
4232 [mainMenu setSubmenu
: appMenu forItem
: item
];
4233 [dockMenu insertItemWithTitle
: @"New Frame"
4234 action
: @selector
(newFrame
:)
4238 [NSApp setMainMenu
: mainMenu
];
4239 [NSApp setAppleMenu
: appMenu
];
4240 [NSApp setServicesMenu
: svcsMenu
];
4241 /* Needed at least on Cocoa, to get dock menu to show windows */
4242 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4244 [[NSNotificationCenter defaultCenter
]
4245 addObserver
: mainMenu
4246 selector
: @selector
(trackingNotification
:)
4247 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4248 [[NSNotificationCenter defaultCenter
]
4249 addObserver
: mainMenu
4250 selector
: @selector
(trackingNotification
:)
4251 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4253 #endif
/* MAC OS X menu setup */
4262 ns_term_shutdown
(int sig
)
4264 [[NSUserDefaults standardUserDefaults
] synchronize
];
4266 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4267 if (STRINGP
(Vauto_save_list_file_name
))
4268 unlink
(SDATA
(Vauto_save_list_file_name
));
4270 if (sig
== 0 || sig
== SIGTERM
)
4272 [NSApp terminate
: NSApp
];
4274 else // force a stack
trace to happen
4281 /* ==========================================================================
4283 EmacsApp implementation
4285 ========================================================================== */
4288 @implementation EmacsApp
4290 - (void
)logNotification
: (NSNotification
*)notification
4292 const
char *name
= [[notification name
] UTF8String
];
4293 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4294 && !strstr
(name
, "WindowNumber"
))
4295 NSLog
(@"notification
: '%@'"
, [notification name
]);
4299 - (void
)sendEvent
: (NSEvent
*)theEvent
4300 /* --------------------------------------------------------------------------
4301 Called when NSApp is running for each event received. Used to stop
4302 the loop when we choose, since there's no way to just run one iteration.
4303 -------------------------------------------------------------------------- */
4305 int
type = [theEvent
type];
4306 NSWindow
*window
= [theEvent window
];
4307 /* NSTRACE (sendEvent); */
4308 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4310 #ifdef NS_IMPL_COCOA
4311 if (type == NSApplicationDefined
4312 && [theEvent data2
] == NSAPP_DATA2_RUNASSCRIPT
)
4320 if (type == NSCursorUpdate
&& window
== nil
)
4322 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4326 #ifdef NS_IMPL_COCOA
4327 /* pass mouse down in resize handle and subsequent drags directly to
4328 EmacsWindow so we can generate continuous redisplays */
4331 if (type == NSLeftMouseDragged
)
4333 [window mouseDragged
: theEvent
];
4336 else if (type == NSLeftMouseUp
)
4338 [window mouseUp
: theEvent
];
4342 else if (type == NSLeftMouseDown
)
4344 NSRect r
= ns_resize_handle_rect
(window
);
4345 if (NSPointInRect
([theEvent locationInWindow
], r
))
4348 [window mouseDown
: theEvent
];
4354 if (type == NSApplicationDefined
)
4356 /* Events posted by ns_send_appdefined interrupt the run loop here.
4357 But, if a modal window is up, an appdefined can still come through,
4358 (e.g., from a makeKeyWindow event) but stopping self also stops the
4359 modal loop. Just defer it until later. */
4360 if ([NSApp modalWindow
] == nil
)
4362 last_appdefined_event
= theEvent
;
4367 send_appdefined
= YES
;
4371 [super sendEvent
: theEvent
];
4375 - (void
)showPreferencesWindow
: (id
)sender
4377 struct frame
*emacsframe
= SELECTED_FRAME
();
4378 NSEvent
*theEvent
= [NSApp currentEvent
];
4382 emacs_event
->kind
= NS_NONKEY_EVENT
;
4383 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4384 emacs_event
->modifiers
= 0;
4385 EV_TRAILER
(theEvent
);
4389 - (void
)newFrame
: (id
)sender
4391 struct frame
*emacsframe
= SELECTED_FRAME
();
4392 NSEvent
*theEvent
= [NSApp currentEvent
];
4396 emacs_event
->kind
= NS_NONKEY_EVENT
;
4397 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4398 emacs_event
->modifiers
= 0;
4399 EV_TRAILER
(theEvent
);
4403 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4404 - (BOOL
) openFile
: (NSString
*)fileName
4406 struct frame
*emacsframe
= SELECTED_FRAME
();
4407 NSEvent
*theEvent
= [NSApp currentEvent
];
4412 emacs_event
->kind
= NS_NONKEY_EVENT
;
4413 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4414 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4415 ns_input_line
= Qnil
; /* can be start or cons start,end */
4416 emacs_event
->modifiers
=0;
4417 EV_TRAILER
(theEvent
);
4423 /* **************************************************************************
4425 EmacsApp delegate implementation
4427 ************************************************************************** */
4429 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4430 /* --------------------------------------------------------------------------
4431 When application is loaded, terminate event loop in ns_term_init
4432 -------------------------------------------------------------------------- */
4434 NSTRACE
(applicationDidFinishLaunching
);
4435 [NSApp setServicesProvider
: NSApp
];
4436 ns_send_appdefined
(-2);
4440 /* Termination sequences:
4443 MenuBar | File | Exit:
4444 Select Quit from App menubar:
4446 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4449 Select Quit from Dock menu:
4452 Cancel -> Nothing else
4456 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4461 - (void
) terminate
: (id
)sender
4463 struct frame
*emacsframe
= SELECTED_FRAME
();
4468 emacs_event
->kind
= NS_NONKEY_EVENT
;
4469 emacs_event
->code
= KEY_NS_POWER_OFF
;
4470 emacs_event
->arg
= Qt
; /* mark as non-key event */
4471 EV_TRAILER
((id
)nil
);
4475 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4479 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4480 return NSTerminateNow
;
4482 ret
= NSRunAlertPanel
(ns_app_name
,
4483 [NSString stringWithUTF8String
:"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
],
4484 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4486 if (ret
== NSAlertDefaultReturn
)
4487 return NSTerminateNow
;
4488 else if (ret
== NSAlertAlternateReturn
)
4489 return NSTerminateCancel
;
4490 return NSTerminateNow
; /* just in case */
4494 /* Notification from the Workspace to open a file */
4495 - (BOOL
)application
: sender openFile
: (NSString
*)file
4497 [ns_pending_files addObject
: file
];
4502 /* Open a file as a temporary file */
4503 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4505 [ns_pending_files addObject
: file
];
4510 /* Notification from the Workspace to open a file noninteractively (?) */
4511 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4513 [ns_pending_files addObject
: file
];
4518 /* Notification from the Workspace to open multiple files */
4519 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4521 NSEnumerator
*files
= [fileList objectEnumerator
];
4523 while ((file
= [files nextObject
]) != nil
)
4524 [ns_pending_files addObject
: file
];
4526 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4531 /* Handle dock menu requests. */
4532 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4538 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4539 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4541 //ns_app_active
=YES
;
4543 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4545 NSTRACE
(applicationDidBecomeActive
);
4547 //ns_app_active
=YES
;
4549 ns_update_auto_hide_menu_bar
();
4550 // No constraining takes place when the application is not active.
4551 ns_constrain_all_frames
();
4553 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4556 ns_send_appdefined
(-1);
4561 /* ==========================================================================
4563 EmacsApp aux handlers for managing event loop
4565 ========================================================================== */
4568 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4569 /* --------------------------------------------------------------------------
4570 The timeout specified to ns_select has passed.
4571 -------------------------------------------------------------------------- */
4573 /*NSTRACE (timeout_handler); */
4574 ns_send_appdefined
(-2);
4577 - (void
)fd_handler
: (NSTimer
*) fdEntry
4578 /* --------------------------------------------------------------------------
4579 Check data waiting on file descriptors and terminate if so
4580 -------------------------------------------------------------------------- */
4583 struct timespec select_timeout
;
4584 /* NSTRACE (fd_handler); */
4586 if (select_nfds
== 0)
4589 memcpy
(&t_readfds
, &select_readfds
, sizeof
(fd_set
));
4591 select_timeout.tv_sec
= select_timeout.tv_nsec
= 0;
4592 result
= pselect
(select_nfds
, &t_readfds
, NULL, NULL, &select_timeout
, NULL);
4595 memcpy
(&select_readfds
, &t_readfds
, sizeof
(fd_set
));
4596 ns_send_appdefined
(result
);
4602 /* ==========================================================================
4606 ========================================================================== */
4608 /* called from system: queue for next pass through event loop */
4609 - (void
)requestService
: (NSPasteboard
*)pboard
4610 userData
: (NSString
*)userData
4611 error: (NSString
**)error
4613 [ns_pending_service_names addObject
: userData
];
4614 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4615 SDATA
(ns_string_from_pasteboard
(pboard
))]];
4619 /* called from ns_read_socket to clear queue */
4620 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4622 struct frame
*emacsframe
= SELECTED_FRAME
();
4623 NSEvent
*theEvent
= [NSApp currentEvent
];
4628 emacs_event
->kind
= NS_NONKEY_EVENT
;
4629 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4630 ns_input_spi_name
= build_string
([name UTF8String
]);
4631 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4632 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4633 EV_TRAILER
(theEvent
);
4643 /* ==========================================================================
4645 EmacsView implementation
4647 ========================================================================== */
4650 @implementation EmacsView
4652 /* needed to inform when window closed from LISP */
4653 - (void
) setWindowClosing
: (BOOL
)closing
4655 windowClosing
= closing
;
4661 NSTRACE
(EmacsView_dealloc
);
4667 /* called on font panel selection */
4668 - (void
)changeFont
: (id
)sender
4670 NSEvent
*e
=[[self window
] currentEvent
];
4671 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4675 NSTRACE
(changeFont
);
4679 if (newFont
= [sender convertFont
:
4680 ((struct nsfont_info
*)face
->font
)->nsfont
])
4682 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4684 emacs_event
->kind
= NS_NONKEY_EVENT
;
4685 emacs_event
->modifiers
= 0;
4686 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4688 size = [newFont pointSize
];
4689 ns_input_fontsize
= make_number
(lrint
(size));
4690 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4696 - (BOOL
)acceptsFirstResponder
4698 NSTRACE
(acceptsFirstResponder
);
4703 - (void
)resetCursorRects
4705 NSRect visible
= [self visibleRect
];
4706 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4707 NSTRACE
(resetCursorRects
);
4709 if (currentCursor
== nil
)
4710 currentCursor
= [NSCursor arrowCursor
];
4712 if (!NSIsEmptyRect
(visible
))
4713 [self addCursorRect
: visible cursor
: currentCursor
];
4714 [currentCursor setOnMouseEntered
: YES
];
4719 /*****************************************************************************/
4720 /* Keyboard handling. */
4723 - (void
)keyDown
: (NSEvent
*)theEvent
4725 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
4727 unsigned fnKeysym
= 0;
4729 static NSMutableArray
*nsEvArray
;
4730 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4731 static BOOL firstTime
= YES
;
4737 /* Rhapsody and OS X give up and down events for the arrow keys */
4738 if (ns_fake_keydown
== YES
)
4739 ns_fake_keydown
= NO
;
4740 else if ([theEvent
type] != NSKeyDown
)
4746 if (![[self window
] isKeyWindow
]
4747 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4748 /* we must avoid an infinite loop here. */
4749 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4751 /* XXX: There is an occasional condition in which, when Emacs display
4752 updates a different frame from the current one, and temporarily
4753 selects it, then processes some interrupt-driven input
4754 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4755 for some reason that window has its first responder set to the NSView
4756 most recently updated (I guess), which is not the correct one. */
4757 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4761 if (nsEvArray
== nil
)
4762 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4764 [NSCursor setHiddenUntilMouseMoves
: YES
];
4766 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4768 clear_mouse_face
(hlinfo
);
4769 hlinfo
->mouse_face_hidden
= 1;
4772 if (!processingCompose
)
4774 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4775 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4776 /* (Carbon way: [theEvent keyCode]) */
4778 /* is it a "function key"? */
4779 fnKeysym
= ns_convert_key
(code
);
4782 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4783 because Emacs treats Delete and KP-Delete same (in simple.el). */
4784 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4785 code
= 0xFF08; /* backspace */
4790 /* are there modifiers? */
4791 emacs_event
->modifiers
= 0;
4792 flags
= [theEvent modifierFlags
];
4794 if (flags
& NSHelpKeyMask
)
4795 emacs_event
->modifiers |
= hyper_modifier
;
4797 if (flags
& NSShiftKeyMask
)
4798 emacs_event
->modifiers |
= shift_modifier
;
4800 if ((flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
)
4801 emacs_event
->modifiers |
= parse_solitary_modifier
4802 (EQ
(ns_right_command_modifier
, Qleft
)
4803 ? ns_command_modifier
4804 : ns_right_command_modifier
);
4806 if ((flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
)
4808 emacs_event
->modifiers |
= parse_solitary_modifier
4809 (ns_command_modifier
);
4811 /* if super (default), take input manager's word so things like
4812 dvorak / qwerty layout work */
4813 if (EQ
(ns_command_modifier
, Qsuper
)
4815 && [[theEvent characters
] length] != 0)
4817 /* XXX: the code we get will be unshifted, so if we have
4818 a shift modifier, must convert ourselves */
4819 if (!(flags
& NSShiftKeyMask
))
4820 code
= [[theEvent characters
] characterAtIndex
: 0];
4822 /* this is ugly and also requires linking w/Carbon framework
4823 (for LMGetKbdType) so for now leave this rare (?) case
4824 undealt with.. in future look into CGEvent methods */
4827 long smv
= GetScriptManagerVariable
(smKeyScript
);
4828 Handle uchrHandle
= GetResource
4829 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4831 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4832 [[theEvent characters
] characterAtIndex
: 0],
4833 kUCKeyActionDisplay
,
4834 (flags
& ~NSCommandKeyMask
) >> 8,
4835 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4836 &dummy
, 1, &dummy
, &code
);
4843 if ((flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
)
4844 emacs_event
->modifiers |
= parse_solitary_modifier
4845 (EQ
(ns_right_control_modifier
, Qleft
)
4846 ? ns_control_modifier
4847 : ns_right_control_modifier
);
4849 if ((flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
)
4850 emacs_event
->modifiers |
= parse_solitary_modifier
4851 (ns_control_modifier
);
4853 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4854 emacs_event
->modifiers |
=
4855 parse_solitary_modifier
(ns_function_modifier
);
4857 left_is_none
= NILP
(ns_alternate_modifier
)
4858 || EQ
(ns_alternate_modifier
, Qnone
);
4860 if ((flags
& NSRightAlternateKeyMask
) == NSRightAlternateKeyMask
)
4862 if ((NILP
(ns_right_alternate_modifier
)
4863 || EQ
(ns_right_alternate_modifier
, Qnone
)
4864 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
4866 { /* accept pre-interp alt comb */
4867 if ([[theEvent characters
] length] > 0)
4868 code
= [[theEvent characters
] characterAtIndex
: 0];
4869 /*HACK: clear lone shift modifier to stop next if from firing */
4870 if (emacs_event
->modifiers
== shift_modifier
)
4871 emacs_event
->modifiers
= 0;
4874 emacs_event
->modifiers |
= parse_solitary_modifier
4875 (EQ
(ns_right_alternate_modifier
, Qleft
)
4876 ? ns_alternate_modifier
4877 : ns_right_alternate_modifier
);
4880 if ((flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
) /* default = meta */
4882 if (left_is_none
&& !fnKeysym
)
4883 { /* accept pre-interp alt comb */
4884 if ([[theEvent characters
] length] > 0)
4885 code
= [[theEvent characters
] characterAtIndex
: 0];
4886 /*HACK: clear lone shift modifier to stop next if from firing */
4887 if (emacs_event
->modifiers
== shift_modifier
)
4888 emacs_event
->modifiers
= 0;
4891 emacs_event
->modifiers |
=
4892 parse_solitary_modifier
(ns_alternate_modifier
);
4896 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4897 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4899 /* if it was a function key or had modifiers, pass it directly to emacs */
4900 if (fnKeysym ||
(emacs_event
->modifiers
4901 && (emacs_event
->modifiers
!= shift_modifier
)
4902 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4903 /*[[theEvent characters] length] */
4905 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4907 code |
= (1<<28)|
(3<<16);
4908 else if (code
== 0x7f)
4909 code |
= (1<<28)|
(3<<16);
4911 emacs_event
->kind
= code
> 0xFF
4912 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4914 emacs_event
->code
= code
;
4915 EV_TRAILER
(theEvent
);
4921 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4922 /* if we get here we should send the key for input manager processing */
4923 if (firstTime
&& [[NSInputManager currentInputManager
]
4924 wantsToDelayTextChangeNotifications
] == NO
)
4926 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
4929 if (NS_KEYLOG
&& !processingCompose
)
4930 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
4932 processingCompose
= YES
;
4933 [nsEvArray addObject
: theEvent
];
4934 [self interpretKeyEvents
: nsEvArray
];
4935 [nsEvArray removeObject
: theEvent
];
4939 #ifdef NS_IMPL_COCOA
4940 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
4941 decided not to send key-down for.
4942 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
4943 This only applies on Tiger and earlier.
4944 If it matches one of these, send it on to keyDown. */
4945 -(void
)keyUp
: (NSEvent
*)theEvent
4947 int flags
= [theEvent modifierFlags
];
4948 int code
= [theEvent keyCode
];
4949 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
4950 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
4953 fprintf (stderr
, "keyUp
: passed test"
);
4954 ns_fake_keydown
= YES
;
4955 [self keyDown
: theEvent
];
4961 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
4964 /* <NSTextInput>: called when done composing;
4965 NOTE: also called when we delete over working text, followed immed.
4966 by doCommandBySelector: deleteBackward: */
4967 - (void
)insertText
: (id
)aString
4970 int len
= [(NSString
*)aString
length];
4974 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
4975 processingCompose
= NO
;
4980 /* first, clear any working text */
4981 if (workingText
!= nil
)
4982 [self deleteWorkingText
];
4984 /* now insert the string as keystrokes */
4985 for (i
=0; i
<len
; i
++)
4987 code
= [aString characterAtIndex
: i
];
4988 /* TODO: still need this? */
4990 code
= '~'; /* 0x7E */
4991 emacs_event
->modifiers
= 0;
4993 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4994 emacs_event
->code
= code
;
4995 EV_TRAILER
((id
)nil
);
5000 /* <NSTextInput>: inserts display of composing characters */
5001 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
5003 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
5004 [aString string
] : aString
;
5006 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
5007 selRange.
length, selRange.location
);
5009 if (workingText
!= nil
)
5010 [self deleteWorkingText
];
5011 if ([str
length] == 0)
5017 processingCompose
= YES
;
5018 workingText
= [str copy
];
5019 ns_working_text
= build_string
([workingText UTF8String
]);
5021 emacs_event
->kind
= NS_TEXT_EVENT
;
5022 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
5023 EV_TRAILER
((id
)nil
);
5027 /* delete display of composing characters [not in <NSTextInput>] */
5028 - (void
)deleteWorkingText
5030 if (workingText
== nil
)
5033 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
5034 [workingText release
];
5036 processingCompose
= NO
;
5041 emacs_event
->kind
= NS_TEXT_EVENT
;
5042 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5043 EV_TRAILER
((id
)nil
);
5047 - (BOOL
)hasMarkedText
5049 return workingText
!= nil
;
5053 - (NSRange
)markedRange
5055 NSRange rng
= workingText
!= nil
5056 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5058 NSLog
(@"markedRange request"
);
5066 NSLog
(@"unmark
(accept
) text"
);
5067 [self deleteWorkingText
];
5068 processingCompose
= NO
;
5072 /* used to position char selection windows, etc. */
5073 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5077 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5079 NSLog
(@"firstRectForCharRange request"
);
5081 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5082 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5083 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5084 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5085 +FRAME_LINE_HEIGHT
(emacsframe
));
5087 pt
= [self convertPoint
: pt toView
: nil
];
5088 pt
= [[self window
] convertBaseToScreen
: pt
];
5094 - (long)conversationIdentifier
5100 - (void
)doCommandBySelector
: (SEL
)aSelector
5103 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5105 if (aSelector
== @selector
(deleteBackward
:))
5107 /* happens when user backspaces over an ongoing composition:
5108 throw a 'delete' into the event queue */
5111 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5112 emacs_event
->code
= 0xFF08;
5113 EV_TRAILER
((id
)nil
);
5117 - (NSArray
*)validAttributesForMarkedText
5119 static NSArray
*arr
= nil
;
5120 if (arr
== nil
) arr
= [NSArray new
];
5121 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5125 - (NSRange
)selectedRange
5128 NSLog
(@"selectedRange request"
);
5129 return NSMakeRange
(NSNotFound
, 0);
5132 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5135 NSLog
(@"characterIndexForPoint request"
);
5139 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5141 static NSAttributedString
*str
= nil
;
5142 if (str
== nil
) str
= [NSAttributedString new
];
5144 NSLog
(@"attributedSubstringFromRange request"
);
5148 /* End <NSTextInput> impl. */
5149 /*****************************************************************************/
5152 /* This is what happens when the user presses a mouse button. */
5153 - (void
)mouseDown
: (NSEvent
*)theEvent
5155 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5158 NSTRACE
(mouseDown
);
5160 [self deleteWorkingText
];
5165 last_mouse_frame
= emacsframe
;
5166 /* appears to be needed to prevent spurious movement events generated on
5168 last_mouse_frame
->mouse_moved
= 0;
5170 if ([theEvent
type] == NSScrollWheel
)
5172 float delta
= [theEvent deltaY
];
5173 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5176 emacs_event
->kind
= WHEEL_EVENT
;
5177 emacs_event
->code
= 0;
5178 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5179 ((delta
> 0) ? up_modifier
: down_modifier
);
5183 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5184 emacs_event
->code
= EV_BUTTON
(theEvent
);
5185 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5186 | EV_UDMODIFIERS
(theEvent
);
5188 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5189 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5190 EV_TRAILER
(theEvent
);
5194 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5196 NSTRACE
(rightMouseDown
);
5197 [self mouseDown
: theEvent
];
5201 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5203 NSTRACE
(otherMouseDown
);
5204 [self mouseDown
: theEvent
];
5208 - (void
)mouseUp
: (NSEvent
*)theEvent
5211 [self mouseDown
: theEvent
];
5215 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5217 NSTRACE
(rightMouseUp
);
5218 [self mouseDown
: theEvent
];
5222 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5224 NSTRACE
(otherMouseUp
);
5225 [self mouseDown
: theEvent
];
5229 - (void
) scrollWheel
: (NSEvent
*)theEvent
5231 NSTRACE
(scrollWheel
);
5232 [self mouseDown
: theEvent
];
5236 /* Tell emacs the mouse has moved. */
5237 - (void
)mouseMoved
: (NSEvent
*)e
5239 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5242 // NSTRACE
(mouseMoved
);
5244 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5245 last_mouse_motion_position
5246 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5248 /* update any mouse face */
5249 if (hlinfo
->mouse_face_hidden
)
5251 hlinfo
->mouse_face_hidden
= 0;
5252 clear_mouse_face
(hlinfo
);
5255 /* tooltip handling */
5256 previous_help_echo_string
= help_echo_string
;
5257 help_echo_string
= Qnil
;
5259 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
5260 last_mouse_motion_position.y
))
5261 help_echo_string
= previous_help_echo_string
;
5263 XSETFRAME
(frame
, emacsframe
);
5264 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5266 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5267 (note_mouse_highlight), which is called through the
5268 note_mouse_movement () call above */
5269 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5270 help_echo_object
, help_echo_pos
);
5274 help_echo_string
= Qnil
;
5275 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5278 if (emacsframe
->mouse_moved
&& send_appdefined
)
5279 ns_send_appdefined
(-1);
5283 - (void
)mouseDragged
: (NSEvent
*)e
5285 NSTRACE
(mouseDragged
);
5286 [self mouseMoved
: e
];
5290 - (void
)rightMouseDragged
: (NSEvent
*)e
5292 NSTRACE
(rightMouseDragged
);
5293 [self mouseMoved
: e
];
5297 - (void
)otherMouseDragged
: (NSEvent
*)e
5299 NSTRACE
(otherMouseDragged
);
5300 [self mouseMoved
: e
];
5304 - (BOOL
)windowShouldClose
: (id
)sender
5306 NSEvent
*e
=[[self window
] currentEvent
];
5308 NSTRACE
(windowShouldClose
);
5309 windowClosing
= YES
;
5312 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5313 emacs_event
->modifiers
= 0;
5314 emacs_event
->code
= 0;
5316 /* Don't close this window, let this be done from lisp code. */
5321 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5322 /* normalize frame to gridded text size */
5324 NSTRACE
(windowWillResize
);
5325 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5327 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5328 #ifdef NS_IMPL_GNUSTEP
5329 frameSize.width
+ 3);
5333 if (cols
< MINWIDTH
)
5336 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5337 #ifdef NS_IMPL_GNUSTEP
5338 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5339 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5341 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5342 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5344 if (rows
< MINHEIGHT
)
5346 #ifdef NS_IMPL_COCOA
5348 /* this sets window title to have size in it; the wm does this under GS */
5349 NSRect r
= [[self window
] frame
];
5350 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5361 NSWindow
*window
= [self window
];
5364 const
char *t
= [[[self window
] title] UTF8String
];
5365 char *pos
= strstr
(t
, " — "
);
5368 old_title
= xstrdup
(t
);
5370 size_title
= xmalloc
(strlen
(old_title
) + 40);
5371 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5372 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5377 #endif
/* NS_IMPL_COCOA */
5378 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5384 - (void
)windowDidResize
: (NSNotification
*)notification
5386 NSWindow
*theWindow
= [notification object
];
5388 #ifdef NS_IMPL_GNUSTEP
5389 /* in GNUstep, at least currently, it's possible to get a didResize
5390 without getting a willResize.. therefore we need to act as if we got
5391 the willResize now */
5392 NSSize sz
= [theWindow frame
].
size;
5393 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5394 #endif
/* NS_IMPL_GNUSTEP */
5396 NSTRACE
(windowDidResize
);
5397 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5399 #ifdef NS_IMPL_COCOA
5405 #endif
/* NS_IMPL_COCOA */
5407 /* Avoid loop under GNUstep due to call at beginning of this function.
5408 (x_set_window_size causes a resize which causes
5409 a "windowDidResize" which calls x_set_window_size). */
5410 #ifndef NS_IMPL_GNUSTEP
5411 if (cols
> 0 && rows
> 0)
5414 x_set_window_size
(emacsframe
, 0, cols
, rows
);
5417 NSWindow
*window
= [self window
];
5418 NSRect wr
= [window frame
];
5419 FRAME_PIXEL_WIDTH
(emacsframe
) = (int
)wr.
size.width
5420 - emacsframe
->border_width
;
5421 FRAME_PIXEL_HEIGHT
(emacsframe
) = (int
)wr.
size.height
5422 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5423 - FRAME_TOOLBAR_HEIGHT
(emacsframe
);
5424 change_frame_size
(emacsframe
, rows
, cols
, 0, 0, 1);
5425 SET_FRAME_GARBAGED
(emacsframe
);
5426 cancel_mouse_face
(emacsframe
);
5431 ns_send_appdefined
(-1);
5435 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5436 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5438 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5439 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5441 NSTRACE
(windowDidBecomeKey
);
5443 if (emacsframe
!= old_focus
)
5444 dpyinfo
->x_focus_frame
= emacsframe
;
5446 ns_frame_rehighlight
(emacsframe
);
5450 emacs_event
->kind
= FOCUS_IN_EVENT
;
5451 EV_TRAILER
((id
)nil
);
5456 - (void
)windowDidResignKey
: (NSNotification
*)notification
5457 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5459 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5460 NSTRACE
(windowDidResignKey
);
5462 if (dpyinfo
->x_focus_frame
== emacsframe
)
5463 dpyinfo
->x_focus_frame
= 0;
5465 ns_frame_rehighlight
(emacsframe
);
5467 /* FIXME: for some reason needed on second and subsequent clicks away
5468 from sole-frame Emacs to get hollow box to show */
5469 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5471 x_update_cursor
(emacsframe
, 1);
5472 x_set_frame_alpha
(emacsframe
);
5477 [self deleteWorkingText
];
5478 emacs_event
->kind
= FOCUS_IN_EVENT
;
5479 EV_TRAILER
((id
)nil
);
5484 - (void
)windowWillMiniaturize
: sender
5486 NSTRACE
(windowWillMiniaturize
);
5502 - initFrameFromEmacs
: (struct frame
*)f
5507 NSButton
*toggleButton
;
5508 int vbextra
= NS_SCROLL_BAR_WIDTH
(f
);
5513 NSTRACE
(initFrameFromEmacs
);
5516 processingCompose
= NO
;
5517 scrollbarsNeedingUpdate
= 0;
5519 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5521 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5522 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5523 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5524 [self initWithFrame
: r
];
5525 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5527 FRAME_NS_VIEW
(f
) = self
;
5531 win
= [[EmacsWindow alloc
]
5532 initWithContentRect
: r
5533 styleMask
: (NSResizableWindowMask |
5534 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5535 NSTitledWindowMask |
5537 NSMiniaturizableWindowMask |
5538 NSClosableWindowMask
)
5539 backing
: NSBackingStoreBuffered
5543 f
->border_width
= wr.
size.width
- r.
size.width
;
5544 FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
5546 [win setAcceptsMouseMovedEvents
: YES
];
5547 [win setDelegate
: self
];
5548 [win useOptimizedDrawing
: YES
];
5550 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5551 sz.height
= FRAME_LINE_HEIGHT
(f
);
5552 [win setResizeIncrements
: sz
];
5554 [[win contentView
] addSubview
: self
];
5557 [self registerForDraggedTypes
: ns_drag_types
];
5560 name
= [NSString stringWithUTF8String
:
5561 NILP
(tem
) ?
(unsigned
char *)"Emacs"
: SDATA
(tem
)];
5562 [win setTitle
: name
];
5564 /* toolbar support */
5565 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
5566 [NSString stringWithFormat
: @"Emacs Frame
%d",
5568 [win setToolbar
: toolbar
];
5569 [toolbar setVisible
: NO
];
5570 #ifdef NS_IMPL_COCOA
5571 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
5572 [toggleButton setTarget
: self
];
5573 [toggleButton setAction
: @selector
(toggleToolbar
: )];
5575 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5579 [win setMiniwindowTitle
:
5580 [NSString stringWithUTF8String
: SDATA
(tem
)]];
5583 NSScreen
*screen
= [win screen
];
5586 [win setFrameTopLeftPoint
: NSMakePoint
5587 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
5588 IN_BOUND
(-SCREENMAX
,
5589 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
5592 [win makeFirstResponder
: self
];
5594 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5595 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
5596 [win setBackgroundColor
: col
];
5597 if ([col alphaComponent
] != 1.0)
5598 [win setOpaque
: NO
];
5600 [self allocateGState
];
5602 [NSApp registerServicesMenuSendTypes
: ns_send_types
5610 - (void
)windowDidMove
: sender
5612 NSWindow
*win
= [self window
];
5613 NSRect r
= [win frame
];
5614 NSArray
*screens
= [NSScreen screens
];
5615 NSScreen
*screen
= [screens objectAtIndex
: 0];
5617 NSTRACE
(windowDidMove
);
5619 if (!emacsframe
->output_data.ns
)
5623 emacsframe
->left_pos
= r.origin.x
;
5624 emacsframe
->top_pos
=
5625 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
5630 /* Called AFTER method below, but before our windowWillResize call there leads
5631 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
5632 location so set_window_size moves the frame. */
5633 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5635 emacsframe
->output_data.ns
->zooming
= 1;
5640 /* Override to do something slightly nonstandard, but nice. First click on
5641 zoom button will zoom vertically. Second will zoom completely. Third
5642 returns to original. */
5643 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5644 defaultFrame
:(NSRect
)defaultFrame
5646 NSRect result
= [sender frame
];
5648 NSTRACE
(windowWillUseStandardFrame
);
5650 if (abs (defaultFrame.
size.height
- result.
size.height
)
5651 > FRAME_LINE_HEIGHT
(emacsframe
))
5654 ns_userRect
= result
;
5655 result.
size.height
= defaultFrame.
size.height
;
5656 result.origin.y
= defaultFrame.origin.y
;
5660 if (abs (defaultFrame.
size.width
- result.
size.width
)
5661 > FRAME_COLUMN_WIDTH
(emacsframe
))
5662 result
= defaultFrame
; /* second click */
5666 result
= ns_userRect.
size.height ? ns_userRect
: result
;
5667 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5671 [self windowWillResize
: sender toSize
: result.
size];
5676 - (void
)windowDidDeminiaturize
: sender
5678 NSTRACE
(windowDidDeminiaturize
);
5679 if (!emacsframe
->output_data.ns
)
5681 emacsframe
->async_iconified
= 0;
5682 emacsframe
->async_visible
= 1;
5683 windows_or_buffers_changed
++;
5687 emacs_event
->kind
= ICONIFY_EVENT
;
5688 EV_TRAILER
((id
)nil
);
5693 - (void
)windowDidExpose
: sender
5695 NSTRACE
(windowDidExpose
);
5696 if (!emacsframe
->output_data.ns
)
5698 emacsframe
->async_visible
= 1;
5699 SET_FRAME_GARBAGED
(emacsframe
);
5701 if (send_appdefined
)
5702 ns_send_appdefined
(-1);
5706 - (void
)windowDidMiniaturize
: sender
5708 NSTRACE
(windowDidMiniaturize
);
5709 if (!emacsframe
->output_data.ns
)
5712 emacsframe
->async_iconified
= 1;
5713 emacsframe
->async_visible
= 0;
5717 emacs_event
->kind
= ICONIFY_EVENT
;
5718 EV_TRAILER
((id
)nil
);
5723 - (void
)mouseEntered
: (NSEvent
*)theEvent
5725 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5726 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5727 NSTRACE
(mouseEntered
);
5729 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5733 - (void
)mouseExited
: (NSEvent
*)theEvent
5735 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5737 Mouse_HLInfo
*hlinfo
= emacsframe ? MOUSE_HL_INFO
(emacsframe
) : NULL;
5739 NSTRACE
(mouseExited
);
5744 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5746 if (emacsframe
== hlinfo
->mouse_face_mouse_frame
)
5748 clear_mouse_face
(hlinfo
);
5749 hlinfo
->mouse_face_mouse_frame
= 0;
5757 if (context_menu_value
== -1)
5758 context_menu_value
= [sender tag
];
5760 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
5761 emacsframe
->menu_bar_vector
,
5762 (void
*)[sender tag
]);
5763 ns_send_appdefined
(-1);
5768 - (EmacsToolbar
*)toolbar
5774 /* this gets called on toolbar button click */
5775 - toolbarClicked
: (id
)item
5778 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
5780 NSTRACE
(toolbarClicked
);
5785 /* send first event (for some reason two needed) */
5786 theEvent
= [[self window
] currentEvent
];
5787 emacs_event
->kind
= TOOL_BAR_EVENT
;
5788 XSETFRAME
(emacs_event
->arg
, emacsframe
);
5789 EV_TRAILER
(theEvent
);
5791 emacs_event
->kind
= TOOL_BAR_EVENT
;
5792 /* XSETINT (emacs_event->code, 0); */
5793 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
5794 idx
+ TOOL_BAR_ITEM_KEY
);
5795 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5796 EV_TRAILER
(theEvent
);
5801 - toggleToolbar
: (id
)sender
5806 emacs_event
->kind
= NS_NONKEY_EVENT
;
5807 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
5808 EV_TRAILER
((id
)nil
);
5813 - (void
)drawRect
: (NSRect
)rect
5815 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
5816 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
5820 if (!emacsframe ||
!emacsframe
->output_data.ns || ns_in_resize
)
5823 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
5824 expose_frame
(emacsframe
, x
, y
, width
, height
);
5827 drawRect: may be called (at least in OS X 10.5) for invisible
5828 views as well for some reason. Thus, do not infer visibility
5831 emacsframe->async_visible = 1;
5832 emacsframe->async_iconified = 0;
5837 /* NSDraggingDestination protocol methods. Actually this is not really a
5838 protocol, but a category of Object. O well... */
5840 -(NSUInteger
) draggingEntered
: (id
<NSDraggingInfo
>) sender
5842 NSTRACE
(draggingEntered
);
5843 return NSDragOperationGeneric
;
5847 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
5853 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
5858 NSEvent
*theEvent
= [[self window
] currentEvent
];
5861 NSTRACE
(performDragOperation
);
5866 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
5867 x
= lrint
(position.x
); y
= lrint
(position.y
);
5869 pb
= [sender draggingPasteboard
];
5870 type = [pb availableTypeFromArray
: ns_drag_types
];
5875 else if ([type isEqualToString
: NSFilenamesPboardType
])
5878 NSEnumerator
*fenum
;
5881 if (!(files
= [pb propertyListForType
: type]))
5884 fenum
= [files objectEnumerator
];
5885 while ( (file
= [fenum nextObject
]) )
5887 emacs_event
->kind
= NS_NONKEY_EVENT
;
5888 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5889 XSETINT
(emacs_event
->x
, x
);
5890 XSETINT
(emacs_event
->y
, y
);
5891 ns_input_file
= append2
(ns_input_file
,
5892 build_string
([file UTF8String
]));
5893 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5894 EV_TRAILER
(theEvent
);
5898 else if ([type isEqualToString
: NSURLPboardType
])
5903 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
5904 [fileURL isFileURL
] == NO
)
5907 file
= [fileURL
path];
5908 emacs_event
->kind
= NS_NONKEY_EVENT
;
5909 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5910 XSETINT
(emacs_event
->x
, x
);
5911 XSETINT
(emacs_event
->y
, y
);
5912 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
5913 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5914 EV_TRAILER
(theEvent
);
5917 else if ([type isEqualToString
: NSStringPboardType
]
5918 ||
[type isEqualToString
: NSTabularTextPboardType
])
5922 if (! (data
= [pb stringForType
: type]))
5925 emacs_event
->kind
= NS_NONKEY_EVENT
;
5926 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
5927 XSETINT
(emacs_event
->x
, x
);
5928 XSETINT
(emacs_event
->y
, y
);
5929 ns_input_text
= build_string
([data UTF8String
]);
5930 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5931 EV_TRAILER
(theEvent
);
5934 else if ([type isEqualToString
: NSColorPboardType
])
5936 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
5937 emacs_event
->kind
= NS_NONKEY_EVENT
;
5938 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
5939 XSETINT
(emacs_event
->x
, x
);
5940 XSETINT
(emacs_event
->y
, y
);
5941 ns_input_color
= ns_color_to_lisp
(c
);
5942 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5943 EV_TRAILER
(theEvent
);
5946 else if ([type isEqualToString
: NSFontPboardType
])
5948 /* impl based on GNUstep NSTextView.m */
5949 NSData
*data
= [pb dataForType
: NSFontPboardType
];
5950 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
5951 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
5957 emacs_event
->kind
= NS_NONKEY_EVENT
;
5958 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
5959 XSETINT
(emacs_event
->x
, x
);
5960 XSETINT
(emacs_event
->y
, y
);
5961 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
5962 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
5963 ns_input_fontsize
= build_string
(fontSize
);
5964 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5965 EV_TRAILER
(theEvent
);
5970 error ("Invalid data
type in dragging pasteboard."
);
5976 - (id
) validRequestorForSendType
: (NSString
*)typeSent
5977 returnType
: (NSString
*)typeReturned
5979 NSTRACE
(validRequestorForSendType
);
5980 if (typeSent
!= nil
&& [ns_send_types indexOfObject
: typeSent
] != NSNotFound
5981 && typeReturned
== nil
)
5983 if (! NILP
(ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
)))
5987 return [super validRequestorForSendType
: typeSent
5988 returnType
: typeReturned
];
5992 /* The next two methods are part of NSServicesRequests informal protocol,
5993 supposedly called when a services menu item is chosen from this app.
5994 But this should not happen because we override the services menu with our
5995 own entries which call ns-perform-service.
5996 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
5997 So let's at least stub them out until further investigation can be done. */
5999 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
6001 /* we could call ns_string_from_pasteboard(pboard) here but then it should
6002 be written into the buffer in place of the existing selection..
6003 ordinary service calls go through functions defined in ns-win.el */
6007 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
6009 NSArray
*typesDeclared
;
6012 /* We only support NSStringPboardType */
6013 if ([types containsObject
:NSStringPboardType
] == NO
) {
6017 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6018 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
6021 if (CONSP
(val
) && NILP
(XCDR
(val
)))
6024 if (! STRINGP
(val
))
6027 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
6028 [pb declareTypes
:typesDeclared owner
:nil
];
6029 ns_string_to_pasteboard
(pb
, val
);
6034 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
6035 (gives a miniaturized version of the window); currently we use the latter for
6036 frames whose active buffer doesn't correspond to any file
6037 (e.g., '*scratch*') */
6038 - setMiniwindowImage
: (BOOL
) setMini
6040 id
image = [[self window
] miniwindowImage
];
6041 NSTRACE
(setMiniwindowImage
);
6043 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6044 about "AppleDockIconEnabled" notwithstanding, however the set message
6045 below has its effect nonetheless. */
6046 if (image != emacsframe
->output_data.ns
->miniimage
)
6048 if (image && [image isKindOfClass
: [EmacsImage
class]])
6050 [[self window
] setMiniwindowImage
:
6051 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6058 - (void
) setRows
: (int
) r andColumns
: (int
) c
6064 @
end /* EmacsView */
6068 /* ==========================================================================
6070 EmacsWindow implementation
6072 ========================================================================== */
6074 @implementation EmacsWindow
6076 /* If we have multiple monitors, one above the other, we don't want to
6077 restrict the height to just one monitor. So we override this. */
6078 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6080 /* When making the frame visible for the first time or if there is just
6081 one screen, we want to constrain. Other times not. */
6082 NSUInteger nr_screens
= [[NSScreen screens
] count
];
6083 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6084 NSTRACE
(constrainFrameRect
);
6086 if (nr_screens
== 1)
6087 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6089 if (f
->output_data.ns
->dont_constrain
6090 || ns_menu_bar_should_be_hidden
())
6093 f
->output_data.ns
->dont_constrain
= 1;
6094 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6098 /* called only on resize clicks by special case in EmacsApp-sendEvent */
6099 - (void
)mouseDown
: (NSEvent
*)theEvent
6103 NSSize
size = [[theEvent window
] frame
].
size;
6104 grabOffset
= [theEvent locationInWindow
];
6105 grabOffset.x
= size.width
- grabOffset.x
;
6108 [super mouseDown
: theEvent
];
6113 - (void
)mouseUp
: (NSEvent
*)theEvent
6117 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6119 ns_set_name_as_filename
(f
);
6121 ns_send_appdefined
(-1);
6124 [super mouseUp
: theEvent
];
6128 /* send resize events */
6129 - (void
)mouseDragged
: (NSEvent
*)theEvent
6133 NSPoint p
= [theEvent locationInWindow
];
6134 NSSize
size, vettedSize
, origSize
= [self frame
].
size;
6136 size.width
= p.x
+ grabOffset.x
;
6137 size.height
= origSize.height
- p.y
+ grabOffset.y
;
6139 if (size.width
== origSize.width
&& size.height
== origSize.height
)
6142 vettedSize
= [[self delegate
] windowWillResize
: self toSize
: size];
6143 [[NSNotificationCenter defaultCenter
]
6144 postNotificationName
: NSWindowDidResizeNotification
6148 [super mouseDragged
: theEvent
];
6151 @
end /* EmacsWindow */
6154 /* ==========================================================================
6156 EmacsScroller implementation
6158 ========================================================================== */
6161 @implementation EmacsScroller
6163 /* for repeat button push */
6164 #define SCROLL_BAR_FIRST_DELAY
0.5
6165 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6167 + (CGFloat
) scrollerWidth
6169 /* TODO: if we want to allow variable widths, this is the place to do it,
6170 however neither GNUstep nor Cocoa support it very well */
6171 return [NSScroller scrollerWidth
];
6175 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
6177 NSTRACE
(EmacsScroller_initFrame
);
6179 r.
size.width
= [EmacsScroller scrollerWidth
];
6180 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
6181 [self setContinuous
: YES
];
6182 [self setEnabled
: YES
];
6184 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
6185 locked against the top and bottom edges, and right edge on OS X, where
6186 scrollers are on right. */
6187 #ifdef NS_IMPL_GNUSTEP
6188 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
6190 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
6195 pixel_height
= NSHeight
(r
);
6196 if (pixel_height
== 0) pixel_height
= 1;
6197 min_portion
= 20 / pixel_height
;
6199 frame
= XFRAME
(XWINDOW
(win
)->frame
);
6200 if (FRAME_LIVE_P
(frame
))
6203 EmacsView
*view = FRAME_NS_VIEW
(frame
);
6204 NSView
*sview
= [[view window
] contentView
];
6205 NSArray
*subs
= [sview subviews
];
6207 /* disable optimization stopping redraw of other scrollbars */
6208 view->scrollbarsNeedingUpdate
= 0;
6209 for (i
=[subs count
]-1; i
>= 0; i
--)
6210 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
6211 view->scrollbarsNeedingUpdate
++;
6212 [sview addSubview
: self
];
6215 /* [self setFrame: r]; */
6221 - (void
)setFrame
: (NSRect
)newRect
6223 NSTRACE
(EmacsScroller_setFrame
);
6225 pixel_height
= NSHeight
(newRect
);
6226 if (pixel_height
== 0) pixel_height
= 1;
6227 min_portion
= 20 / pixel_height
;
6228 [super setFrame
: newRect
];
6230 /* UNBLOCK_INPUT; */
6236 NSTRACE
(EmacsScroller_dealloc
);
6238 XWINDOW
(win
)->vertical_scroll_bar
= Qnil
;
6266 /* ensure other scrollbar updates after deletion */
6267 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6269 view->scrollbarsNeedingUpdate
++;
6270 [self removeFromSuperview
];
6278 - (void
)resetCursorRects
6280 NSRect visible
= [self visibleRect
];
6281 NSTRACE
(resetCursorRects
);
6283 if (!NSIsEmptyRect
(visible
))
6284 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
6285 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
6289 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
6292 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
6293 && portion
!= whole
; /* needed for resize empty buf */
6297 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
6299 NSTRACE
(setPosition
);
6301 em_position
= position
;
6302 em_portion
= portion
;
6305 if (portion
>= whole
)
6307 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6308 [self setKnobProportion
: 1.0];
6309 [self setDoubleValue
: 1.0];
6311 [self setFloatValue
: 0.0 knobProportion
: 1.0];
6317 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
6318 pos
= (float
)position
/ (whole
- portion
);
6319 por
= (float
)portion
/whole
;
6320 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6321 [self setKnobProportion
: por
];
6322 [self setDoubleValue
: pos
];
6324 [self setFloatValue
: pos knobProportion
: por
];
6330 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
6331 drag events will go directly to the EmacsScroller. Leaving in for now. */
6332 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
6333 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
6335 *part
= last_hit_part
;
6337 XSETINT
(*y
, pixel_height
);
6338 if ([self floatValue
] > 0.999)
6339 XSETINT
(*x
, pixel_height
);
6341 XSETINT
(*x
, pixel_height
* [self floatValue
]);
6345 /* set up emacs_event */
6346 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
6351 emacs_event
->part
= last_hit_part
;
6352 emacs_event
->code
= 0;
6353 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
6354 emacs_event
->frame_or_window
= win
;
6355 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
6356 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
6357 emacs_event
->arg
= Qnil
;
6358 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
6359 XSETINT
(emacs_event
->y
, pixel_height
-20);
6361 n_emacs_events_pending
++;
6362 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
6363 EVENT_INIT
(*emacs_event
);
6364 ns_send_appdefined
(-1);
6368 /* called manually thru timer to implement repeated button action w/hold-down */
6369 - repeatScroll
: (NSTimer
*)scrollEntry
6371 NSEvent
*e
= [[self window
] currentEvent
];
6372 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
6373 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
6375 /* clear timer if need be */
6376 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
6378 [scroll_repeat_entry invalidate
];
6379 [scroll_repeat_entry release
];
6380 scroll_repeat_entry
= nil
;
6386 = [[NSTimer scheduledTimerWithTimeInterval
:
6387 SCROLL_BAR_CONTINUOUS_DELAY
6389 selector
: @selector
(repeatScroll
:)
6395 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
6400 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
6401 mouseDragged events without going into a modal loop. */
6402 - (void
)mouseDown
: (NSEvent
*)e
6405 /* hitPart is only updated AFTER event is passed on */
6406 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6407 double inc
= 0.0, loc
, kloc
, pos
;
6410 NSTRACE
(EmacsScroller_mouseDown
);
6414 case NSScrollerDecrementPage
:
6415 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6416 case NSScrollerIncrementPage
:
6417 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6418 case NSScrollerDecrementLine
:
6419 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6420 case NSScrollerIncrementLine
:
6421 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6422 case NSScrollerKnob
:
6423 last_hit_part
= scroll_bar_handle
; break;
6424 case NSScrollerKnobSlot
: /* GNUstep-only */
6425 last_hit_part
= scroll_bar_move_ratio
; break;
6426 default
: /* NSScrollerNoPart? */
6427 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
6434 pos
= 0; /* ignored */
6436 /* set a timer to repeat, as we can't let superclass do this modally */
6438 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
6440 selector
: @selector
(repeatScroll
:)
6447 /* handle, or on GNUstep possibly slot */
6448 NSEvent
*fake_event
;
6450 /* compute float loc in slot and mouse offset on knob */
6451 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6453 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6459 else if (loc
>= NSHeight
(sr
))
6461 loc
= NSHeight
(sr
);
6469 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6471 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6473 last_mouse_offset
= kloc
;
6475 /* if knob, tell emacs a location offset by knob pos
6476 (to indicate top of handle) */
6477 if (part
== NSScrollerKnob
)
6478 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6480 /* else this is a slot click on GNUstep: go straight there */
6481 pos
= loc
/ NSHeight
(sr
);
6483 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6484 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6485 location
: [e locationInWindow
]
6486 modifierFlags
: [e modifierFlags
]
6487 timestamp
: [e timestamp
]
6488 windowNumber
: [e windowNumber
]
6489 context
: [e context
]
6490 eventNumber
: [e eventNumber
]
6491 clickCount
: [e clickCount
]
6492 pressure
: [e pressure
]];
6493 [super mouseUp
: fake_event
];
6496 if (part
!= NSScrollerKnob
)
6497 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6501 /* Called as we manually track scroller drags, rather than superclass. */
6502 - (void
)mouseDragged
: (NSEvent
*)e
6508 NSTRACE
(EmacsScroller_mouseDragged
);
6510 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6512 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6519 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6521 loc
= NSHeight
(sr
) + last_mouse_offset
;
6525 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6526 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6530 - (void
)mouseUp
: (NSEvent
*)e
6532 if (scroll_repeat_entry
)
6534 [scroll_repeat_entry invalidate
];
6535 [scroll_repeat_entry release
];
6536 scroll_repeat_entry
= nil
;
6542 /* treat scrollwheel events in the bar as though they were in the main window */
6543 - (void
) scrollWheel
: (NSEvent
*)theEvent
6545 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6546 [view mouseDown
: theEvent
];
6549 @
end /* EmacsScroller */
6554 /* ==========================================================================
6556 Font-related functions; these used to be in nsfaces.m
6558 ========================================================================== */
6562 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6564 struct font
*font
= XFONT_OBJECT
(font_object
);
6567 fontset
= fontset_from_font
(font_object
);
6568 FRAME_FONTSET
(f
) = fontset
;
6570 if (FRAME_FONT
(f
) == font
)
6571 /* This font is already set in frame F. There's nothing more to
6575 FRAME_FONT
(f
) = font
;
6577 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6578 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6579 FRAME_SPACE_WIDTH
(f
) = font
->space_width
;
6580 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6582 compute_fringe_widths
(f
, 1);
6584 /* Compute the scroll bar width in character columns. */
6585 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6587 int wid
= FRAME_COLUMN_WIDTH
(f
);
6588 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6589 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6593 int wid
= FRAME_COLUMN_WIDTH
(f
);
6594 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6597 /* Now make the frame display the given font. */
6598 if (FRAME_NS_WINDOW
(f
) != 0)
6599 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6605 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6606 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6610 ns_xlfd_to_fontname
(const
char *xlfd
)
6611 /* --------------------------------------------------------------------------
6612 Convert an X font name (XLFD) to an NS font name.
6613 Only family is used.
6614 The string returned is temporarily allocated.
6615 -------------------------------------------------------------------------- */
6617 char *name
= xmalloc
(180);
6621 if (!strncmp
(xlfd
, "
--"
, 2))
6622 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
6624 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
6626 /* stopgap for malformed XLFD input */
6627 if (strlen
(name
) == 0)
6628 strcpy
(name
, "Monaco"
);
6630 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
6631 also uppercase after '-' or ' ' */
6632 name
[0] = toupper
(name
[0]);
6633 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
6639 name
[i
+1] = toupper
(name
[i
+1]);
6641 else if (name
[i
] == '_')
6645 name
[i
+1] = toupper
(name
[i
+1]);
6648 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
6649 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
6656 syms_of_nsterm
(void
)
6658 NSTRACE
(syms_of_nsterm
);
6660 ns_antialias_threshold
= 10.0;
6662 /* from 23+ we need to tell emacs what modifiers there are.. */
6663 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
6664 DEFSYM
(Qalt
, "alt"
);
6665 DEFSYM
(Qhyper
, "hyper"
);
6666 DEFSYM
(Qmeta
, "
meta"
);
6667 DEFSYM
(Qsuper
, "super"
);
6668 DEFSYM
(Qcontrol
, "control"
);
6669 DEFSYM
(Qnone
, "none"
);
6670 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
6672 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
6673 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
6674 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
6675 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
6676 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
6678 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
6679 "The file specified in the last NS event."
);
6680 ns_input_file
=Qnil
;
6682 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
6683 "The data received in the last NS
text drag event."
);
6684 ns_input_text
=Qnil
;
6686 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
6687 "String
for visualizing working composition sequence."
);
6688 ns_working_text
=Qnil
;
6690 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
6691 "The font specified in the last NS event."
);
6692 ns_input_font
=Qnil
;
6694 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
6695 "The fontsize specified in the last NS event."
);
6696 ns_input_fontsize
=Qnil
;
6698 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
6699 "The
line specified in the last NS event."
);
6700 ns_input_line
=Qnil
;
6702 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
6703 "The color specified in the last NS event."
);
6704 ns_input_color
=Qnil
;
6706 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
6707 "The service name specified in the last NS event."
);
6708 ns_input_spi_name
=Qnil
;
6710 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
6711 "The service argument specified in the last NS event."
);
6712 ns_input_spi_arg
=Qnil
;
6714 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
6715 "This variable describes the behavior of the alternate or option key.
\n\
6716 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6717 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
6718 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6719 ns_alternate_modifier
= Qmeta
;
6721 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
6722 "This variable describes the behavior of the right alternate or option key.
\n\
6723 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6724 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
6725 Set to none means that the alternate / option key is not interpreted by Emacs\n\
6726 at all, allowing it to be used at a lower level for accented character entry.");
6727 ns_right_alternate_modifier = Qleft;
6729 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
6730 "This variable describes the behavior of the command key.\n\
6731 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
6732 ns_command_modifier = Qsuper;
6734 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
6735 "This variable describes the behavior of the right command key.\n\
6736 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6737 Set to left means be the same key as `ns-command-modifier'.
\n\
6738 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
6739 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6740 ns_right_command_modifier
= Qleft
;
6742 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
6743 "This variable describes the behavior of the control key.
\n\
6744 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
6745 ns_control_modifier
= Qcontrol
;
6747 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
6748 "This variable describes the behavior of the right control key.
\n\
6749 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6750 Set to left means be the same key as `ns
-control
-modifier
'.\n\
6751 Set to none means that the control / option key is not interpreted by Emacs\n\
6752 at all, allowing it to be used at a lower level for accented character entry.");
6753 ns_right_control_modifier = Qleft;
6755 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
6756 "This variable describes the behavior of the function key (on laptops).\n\
6757 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6758 Set to none means that the function key is not interpreted by Emacs at all,\n\
6759 allowing it to be used at a lower level for accented character entry.");
6760 ns_function_modifier = Qnone;
6762 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
6763 "Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above.");
6764 ns_antialias_text = Qt;
6766 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
6767 "Whether to confirm application quit using dialog.");
6768 ns_confirm_quit = Qnil;
6770 staticpro (&ns_display_name_list);
6771 ns_display_name_list = Qnil;
6773 staticpro (&last_mouse_motion_frame);
6774 last_mouse_motion_frame = Qnil;
6776 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
6777 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
6778 Only works on OSX 10.6 or later. */);
6779 ns_auto_hide_menu_bar = Qnil;
6781 /* TODO: move to common code */
6782 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
6783 doc: /* Which toolkit scroll bars Emacs uses, if any.
6784 A value of nil means Emacs doesn't use toolkit scroll bars.
6785 With the X Window system
, the value is a symbol describing the
6786 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
6787 With MS Windows or Nextstep
, the value is t. */
);
6788 Vx_toolkit_scroll_bars
= Qt
;
6790 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
6791 x_use_underline_position_properties
,
6792 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
6793 A value of nil means ignore them. If you encounter fonts with bogus
6794 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
6795 to 4.1, set this to nil. */);
6796 x_use_underline_position_properties
= 0;
6798 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
6799 x_underline_at_descent_line
,
6800 doc: /* Non-nil means to draw the underline at the same place as the descent line.
6801 A value of nil means to draw the underline according to the value of the
6802 variable `x-use-underline-position-properties', which is usually at the
6803 baseline level. The default value is nil. */);
6804 x_underline_at_descent_line
= 0;
6806 /* Tell emacs about this window system. */
6807 Fprovide
(intern
("ns"
), Qnil
);