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
>
41 #include "blockinput.h"
42 #include "sysselect.h"
45 #include "character.h"
47 #include "composite.h"
50 #include "termhooks.h"
61 int term_trace_num
= 0;
62 #define NSTRACE
(x
) fprintf (stderr
, "
%s:%d: [%d] " #x "\n", \
63 __FILE__
, __LINE__
, ++term_trace_num
)
68 extern NSString
*NSMenuDidBeginTrackingNotification
;
70 /* ==========================================================================
74 ========================================================================== */
76 /* Convert a symbol indexed with an NSxxx value to a value as defined
77 in keyboard.c (lispy_function_key). I hope this is a correct way
79 static unsigned convert_ns_to_X_keysym
[] =
81 NSHomeFunctionKey
, 0x50,
82 NSLeftArrowFunctionKey
, 0x51,
83 NSUpArrowFunctionKey
, 0x52,
84 NSRightArrowFunctionKey
, 0x53,
85 NSDownArrowFunctionKey
, 0x54,
86 NSPageUpFunctionKey
, 0x55,
87 NSPageDownFunctionKey
, 0x56,
88 NSEndFunctionKey
, 0x57,
89 NSBeginFunctionKey
, 0x58,
90 NSSelectFunctionKey
, 0x60,
91 NSPrintFunctionKey
, 0x61,
92 NSExecuteFunctionKey
, 0x62,
93 NSInsertFunctionKey
, 0x63,
94 NSUndoFunctionKey
, 0x65,
95 NSRedoFunctionKey
, 0x66,
96 NSMenuFunctionKey
, 0x67,
97 NSFindFunctionKey
, 0x68,
98 NSHelpFunctionKey
, 0x6A,
99 NSBreakFunctionKey
, 0x6B,
101 NSF1FunctionKey
, 0xBE,
102 NSF2FunctionKey
, 0xBF,
103 NSF3FunctionKey
, 0xC0,
104 NSF4FunctionKey
, 0xC1,
105 NSF5FunctionKey
, 0xC2,
106 NSF6FunctionKey
, 0xC3,
107 NSF7FunctionKey
, 0xC4,
108 NSF8FunctionKey
, 0xC5,
109 NSF9FunctionKey
, 0xC6,
110 NSF10FunctionKey
, 0xC7,
111 NSF11FunctionKey
, 0xC8,
112 NSF12FunctionKey
, 0xC9,
113 NSF13FunctionKey
, 0xCA,
114 NSF14FunctionKey
, 0xCB,
115 NSF15FunctionKey
, 0xCC,
116 NSF16FunctionKey
, 0xCD,
117 NSF17FunctionKey
, 0xCE,
118 NSF18FunctionKey
, 0xCF,
119 NSF19FunctionKey
, 0xD0,
120 NSF20FunctionKey
, 0xD1,
121 NSF21FunctionKey
, 0xD2,
122 NSF22FunctionKey
, 0xD3,
123 NSF23FunctionKey
, 0xD4,
124 NSF24FunctionKey
, 0xD5,
126 NSBackspaceCharacter
, 0x08, /* 8: Not on some KBs. */
127 NSDeleteCharacter
, 0xFF, /* 127: Big 'delete' key upper right. */
128 NSDeleteFunctionKey
, 0x9F, /* 63272: Del forw key off main array. */
130 NSTabCharacter
, 0x09,
131 0x19, 0x09, /* left tab->regular since pass shift */
132 NSCarriageReturnCharacter
, 0x0D,
133 NSNewlineCharacter
, 0x0D,
134 NSEnterCharacter
, 0x8D,
136 0x1B, 0x1B /* escape */
139 static Lisp_Object Qmodifier_value
;
140 Lisp_Object Qalt
, Qcontrol
, Qhyper
, Qmeta
, Qsuper
, Qnone
;
141 extern Lisp_Object Qcursor_color
, Qcursor_type
, Qns
, Qleft
;
143 static Lisp_Object QUTF8_STRING
;
145 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
146 the maximum font size to NOT antialias. On GNUstep there is currently
147 no way to control this behavior. */
148 float ns_antialias_threshold
;
150 /* Used to pick up AppleHighlightColor on OS X */
151 NSString
*ns_selection_color
;
153 NSArray
*ns_send_types
=0, *ns_return_types
=0, *ns_drag_types
=0;
154 NSString
*ns_app_name
= @"Emacs"
; /* default changed later */
156 /* Display variables */
157 struct ns_display_info
*x_display_list
; /* Chain of existing displays */
158 Lisp_Object ns_display_name_list
;
159 long context_menu_value
= 0;
162 NSPoint last_mouse_motion_position
;
163 static NSRect last_mouse_glyph
;
164 static Time last_mouse_movement_time
= 0;
165 static Lisp_Object last_mouse_motion_frame
;
166 static EmacsScroller
*last_mouse_scroll_bar
= nil
;
167 static
struct frame
*ns_updating_frame
;
168 static NSView
*focus_view
= NULL;
169 static int ns_window_num
= 0;
171 static BOOL gsaved
= NO
;
172 BOOL ns_in_resize
= NO
;
173 static BOOL ns_fake_keydown
= NO
;
174 int ns_tmp_flags
; /* FIXME */
175 struct nsfont_info
*ns_tmp_font
; /* FIXME */
176 static BOOL ns_menu_bar_is_hidden
= NO
;
177 /*static int debug_lock = 0; */
180 static BOOL send_appdefined
= YES
;
181 static NSEvent
*last_appdefined_event
= 0;
182 static NSTimer
*timed_entry
= 0;
183 static NSTimer
*fd_entry
= nil
;
184 static NSTimer
*scroll_repeat_entry
= nil
;
185 static fd_set select_readfds
, t_readfds
;
186 static int select_nfds
;
187 static NSAutoreleasePool
*outerpool
;
188 static
struct input_event
*emacs_event
= NULL;
189 static
struct input_event
*q_event_ptr
= NULL;
190 static int n_emacs_events_pending
= 0;
191 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
192 *ns_pending_service_args
;
193 static BOOL inNsSelect
= 0;
195 /* Convert modifiers in a NeXTstep event to emacs style modifiers. */
196 #define NS_FUNCTION_KEY_MASK
0x800000
197 #define NSLeftControlKeyMask
(0x000001 | NSControlKeyMask
)
198 #define NSRightControlKeyMask
(0x002000 | NSControlKeyMask
)
199 #define NSLeftCommandKeyMask
(0x000008 | NSCommandKeyMask
)
200 #define NSRightCommandKeyMask
(0x000010 | NSCommandKeyMask
)
201 #define NSLeftAlternateKeyMask
(0x000020 | NSAlternateKeyMask
)
202 #define NSRightAlternateKeyMask
(0x000040 | NSAlternateKeyMask
)
203 #define EV_MODIFIERS
(e
) \
204 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
205 hyper_modifier
: 0) \
206 |
(!EQ
(ns_right_alternate_modifier
, Qleft
) && \
207 (([e modifierFlags
] & NSRightAlternateKeyMask
) \
208 == NSRightAlternateKeyMask
) ? \
209 parse_solitary_modifier
(ns_right_alternate_modifier
) : 0) \
210 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
211 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
212 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
213 shift_modifier
: 0) \
214 |
(!EQ
(ns_right_control_modifier
, Qleft
) && \
215 (([e modifierFlags
] & NSRightControlKeyMask
) \
216 == NSRightControlKeyMask
) ? \
217 parse_solitary_modifier
(ns_right_control_modifier
) : 0) \
218 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
219 parse_solitary_modifier
(ns_control_modifier
) : 0) \
220 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
221 parse_solitary_modifier
(ns_function_modifier
) : 0) \
222 |
(!EQ
(ns_right_command_modifier
, Qleft
) && \
223 (([e modifierFlags
] & NSRightCommandKeyMask
) \
224 == NSRightCommandKeyMask
) ? \
225 parse_solitary_modifier
(ns_right_command_modifier
) : 0) \
226 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
227 parse_solitary_modifier
(ns_command_modifier
):0))
229 #define EV_UDMODIFIERS
(e
) \
230 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
231 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
232 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
233 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
234 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
235 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
236 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
237 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
238 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
240 #define EV_BUTTON
(e
) \
241 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
242 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
243 [e buttonNumber
] - 1)
245 /* Convert the time field to a timestamp in milliseconds. */
246 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
248 /* This is a piece of code which is common to all the event handling
249 methods. Maybe it should even be a function. */
250 #define EV_TRAILER
(e
) \
252 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
253 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
254 n_emacs_events_pending
++; \
255 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
256 EVENT_INIT
(*emacs_event
); \
257 ns_send_appdefined
(-1); \
260 void x_set_cursor_type
(struct frame
*, Lisp_Object
, Lisp_Object
);
262 /* TODO: get rid of need for these forward declarations */
263 static void ns_condemn_scroll_bars
(struct frame
*f
);
264 static void ns_judge_scroll_bars
(struct frame
*f
);
265 void x_set_frame_alpha
(struct frame
*f
);
268 /* ==========================================================================
272 ========================================================================== */
276 append2
(Lisp_Object list
, Lisp_Object item
)
277 /* --------------------------------------------------------------------------
278 Utility to append to a list
279 -------------------------------------------------------------------------- */
281 Lisp_Object array
[2];
283 array
[1] = Fcons
(item
, Qnil
);
284 return Fnconc
(2, &array
[0]);
290 /* --------------------------------------------------------------------------
291 Used to allow emacs to find its resources under Emacs.app
292 Called from emacs.c at startup.
293 -------------------------------------------------------------------------- */
295 NSBundle
*bundle
= [NSBundle mainBundle
];
296 NSString
*binDir
= [bundle bundlePath
], *resourceDir
= [bundle resourcePath
];
297 NSString
*resourcePath
, *resourcePaths
;
299 BOOL onWindows
= NO
; /* how do I determine this? */
300 NSString
*pathSeparator
= onWindows ? @"
;"
: @"
:"
;
301 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
303 /*NSLog (@"ns_init_paths: '%@'\n%@\n", [[NSBundle mainBundle] bundlePath], [[NSBundle mainBundle] resourcePath]); */
305 /* get bindir from base */
306 range
= [resourceDir rangeOfString
: @"Contents"
];
307 if (range.location
!= NSNotFound
)
309 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
311 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
315 /* the following based on Andrew Choi's init_mac_osx_environment () */
316 if (!getenv ("EMACSLOADPATH"
))
318 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
319 [NSArray arrayWithObjects
:
320 @"site
-lisp"
, @"lisp"
, @"leim"
, nil
]];
321 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
323 /* Hack to skip site-lisp. */
324 if (no_site_lisp
) resourcePath
= [pathEnum nextObject
];
325 while (resourcePath
= [pathEnum nextObject
])
327 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
330 if ([resourcePaths
length] > 0)
332 = [resourcePaths stringByAppendingString
: pathSeparator
];
334 = [resourcePaths stringByAppendingString
: resourcePath
];
337 if ([resourcePaths
length] > 0)
338 setenv
("EMACSLOADPATH"
, [resourcePaths UTF8String
], 1);
339 /*NSLog (@"loadPath: '%@'\n", resourcePaths); */
342 /* Normally, Emacs does not add its own bin/ directory to the PATH.
343 However, a self-contained NS build has a different layout, with
344 bin/ and libexec/ subdirectories in the directory that contains
346 We put libexec first, because init_callproc_1 uses the first
347 element to initialize exec-directory. An alternative would be
348 for init_callproc to check for invocation-directory/libexec. */
349 if (!getenv ("EMACSPATH"
))
351 NSArray
*paths
= [binDir stringsByAppendingPaths
:
352 [NSArray arrayWithObjects
: @"libexec"
,
354 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
356 while (resourcePath
= [pathEnum nextObject
])
358 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
361 if ([resourcePaths
length] > 0)
363 = [resourcePaths stringByAppendingString
: pathSeparator
];
365 = [resourcePaths stringByAppendingString
: resourcePath
];
368 if ([resourcePaths
length] > 0)
369 setenv
("EMACSPATH"
, [resourcePaths UTF8String
], 1);
372 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
373 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
377 if (!getenv ("EMACSDATA"
))
378 setenv
("EMACSDATA"
, [resourcePath UTF8String
], 1);
379 if (!getenv ("EMACSDOC"
))
380 setenv
("EMACSDOC"
, [resourcePath UTF8String
], 1);
386 ns_timeout
(int usecs
)
387 /* --------------------------------------------------------------------------
388 Blocking timer utility used by ns_ring_bell
389 -------------------------------------------------------------------------- */
391 EMACS_TIME wakeup
, delay
;
393 EMACS_GET_TIME
(wakeup
);
394 EMACS_SET_SECS_USECS
(delay
, 0, usecs
);
395 EMACS_ADD_TIME
(wakeup
, wakeup
, delay
);
397 /* Keep waiting until past the time wakeup. */
402 EMACS_GET_TIME
(timeout
);
403 if (EMACS_TIME_LE
(wakeup
, timeout
))
405 EMACS_SUB_TIME
(timeout
, wakeup
, timeout
);
407 /* Try to wait that long--but we might wake up sooner. */
408 pselect
(0, NULL, NULL, NULL, &timeout
, NULL);
414 ns_release_object
(void
*obj
)
415 /* --------------------------------------------------------------------------
416 Release an object (callable from C)
417 -------------------------------------------------------------------------- */
424 ns_retain_object
(void
*obj
)
425 /* --------------------------------------------------------------------------
426 Retain an object (callable from C)
427 -------------------------------------------------------------------------- */
434 ns_alloc_autorelease_pool
(void
)
435 /* --------------------------------------------------------------------------
436 Allocate a pool for temporary objects (callable from C)
437 -------------------------------------------------------------------------- */
439 return [[NSAutoreleasePool alloc
] init
];
444 ns_release_autorelease_pool
(void
*pool
)
445 /* --------------------------------------------------------------------------
446 Free a pool and temporary objects it refers to (callable from C)
447 -------------------------------------------------------------------------- */
449 ns_release_object
(pool
);
454 /* ==========================================================================
456 Focus (clipping) and screen update
458 ========================================================================== */
461 ns_resize_handle_rect
(NSWindow
*window
)
463 NSRect r
= [window frame
];
464 r.origin.x
= r.
size.width
- RESIZE_HANDLE_SIZE
;
466 r.
size.width
= r.
size.height
= RESIZE_HANDLE_SIZE
;
472 // Window constraining
473 // -------------------
475 // To ensure that the windows are not placed under the
menu bar, they
476 // are typically moved by the call
-back constrainFrameRect. However
,
477 // by overriding it
, it
's possible to inhibit this, leaving the window
478 // in it's original position.
480 // It
's possible to hide the menu bar. However, technically, it's only
481 // possible to hide it when the application is active. To ensure that
482 // this work properly
, the
menu bar and window constraining are
483 // deferred until the application becomes active.
485 // Even though it
's not possible to manually move a window above the
486 // top of the screen, it is allowed if it's done programmatically
,
487 // when the
menu is
hidden. This allows the editable area to cover the
488 // full screen height.
493 // Use the following extra files
:
496 // ;; Hide
menu and place frame slightly above the top of the screen.
497 // (setq ns
-auto
-hide
-menu-bar t
)
498 // (set-frame
-position
(selected
-frame
) 0 -20)
502 // emacs
-Q
-l init.el
504 // Result
: No
menu bar, and the
title bar should be above the screen.
510 // Result
: Menu bar visible
, frame placed immediately below the
menu.
514 ns_constrain_all_frames
(void
)
516 Lisp_Object tail
, frame
;
518 FOR_EACH_FRAME
(tail
, frame
)
520 struct frame
*f
= XFRAME
(frame
);
523 NSView
*view = FRAME_NS_VIEW
(f
);
524 /* This no-op will trigger the default window placing
525 * constraint system. */
526 f
->output_data.ns
->dont_constrain
= 0;
527 [[view window
] setFrameOrigin
:[[view window
] frame
].origin
];
533 /* True, if the menu bar should be hidden. */
536 ns_menu_bar_should_be_hidden
(void
)
538 return !NILP
(ns_auto_hide_menu_bar
)
539 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)];
543 /* Show or hide the menu bar, based on user setting. */
546 ns_update_auto_hide_menu_bar
(void
)
548 #ifndef MAC_OS_X_VERSION_10_6
549 #define MAC_OS_X_VERSION_10_6
1060
552 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
555 NSTRACE
(ns_update_auto_hide_menu_bar
);
559 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)])
561 // Note
, "setPresentationOptions" triggers an
error unless the
562 // application is active.
563 BOOL menu_bar_should_be_hidden
= ns_menu_bar_should_be_hidden
();
565 if (menu_bar_should_be_hidden
!= ns_menu_bar_is_hidden
)
567 NSApplicationPresentationOptions options
568 = NSApplicationPresentationAutoHideDock
;
570 if (menu_bar_should_be_hidden
)
571 options |
= NSApplicationPresentationAutoHideMenuBar
;
573 [NSApp setPresentationOptions
: options
];
575 ns_menu_bar_is_hidden
= menu_bar_should_be_hidden
;
577 if (!ns_menu_bar_is_hidden
)
579 ns_constrain_all_frames
();
591 ns_update_begin
(struct frame
*f
)
592 /* --------------------------------------------------------------------------
593 Prepare for a grouped sequence of drawing calls
594 external (RIF) call; whole frame, called before update_window_begin
595 -------------------------------------------------------------------------- */
597 NSView
*view = FRAME_NS_VIEW
(f
);
598 NSTRACE
(ns_update_begin
);
600 ns_update_auto_hide_menu_bar
();
602 ns_updating_frame
= f
;
605 #ifdef NS_IMPL_GNUSTEP
606 uRect
= NSMakeRect
(0, 0, 0, 0);
612 ns_update_window_begin
(struct window
*w
)
613 /* --------------------------------------------------------------------------
614 Prepare for a grouped sequence of drawing calls
615 external (RIF) call; for one window, called after update_begin
616 -------------------------------------------------------------------------- */
618 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
619 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
620 NSTRACE
(ns_update_window_begin
);
623 set_output_cursor
(&w
->cursor
);
627 if (f
== hlinfo
->mouse_face_mouse_frame
)
629 /* Don't do highlighting for mouse motion during the update. */
630 hlinfo
->mouse_face_defer
= 1;
632 /* If the frame needs to be redrawn,
633 simply forget about any prior mouse highlighting. */
634 if (FRAME_GARBAGED_P
(f
))
635 hlinfo
->mouse_face_window
= Qnil
;
637 /* (further code for mouse faces ifdef'd out in other terms elided) */
645 ns_update_window_end
(struct window
*w
, int cursor_on_p
,
646 int mouse_face_overwritten_p
)
647 /* --------------------------------------------------------------------------
648 Finished a grouped sequence of drawing calls
649 external (RIF) call; for one window called before update_end
650 -------------------------------------------------------------------------- */
652 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(XFRAME
(w
->frame
));
654 /* note: this fn is nearly identical in all terms */
655 if (!w
->pseudo_window_p
)
660 display_and_set_cursor
(w
, 1,
661 output_cursor.hpos
, output_cursor.vpos
,
662 output_cursor.x
, output_cursor.y
);
664 if (draw_window_fringes
(w
, 1))
665 x_draw_vertical_border
(w
);
670 /* If a row with mouse-face was overwritten, arrange for
671 frame_up_to_date to redisplay the mouse highlight. */
672 if (mouse_face_overwritten_p
)
674 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
675 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
676 hlinfo
->mouse_face_window
= Qnil
;
679 updated_window
= NULL;
680 NSTRACE
(update_window_end
);
685 ns_update_end
(struct frame
*f
)
686 /* --------------------------------------------------------------------------
687 Finished a grouped sequence of drawing calls
688 external (RIF) call; for whole frame, called after update_window_end
689 -------------------------------------------------------------------------- */
691 NSView
*view = FRAME_NS_VIEW
(f
);
693 /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
694 MOUSE_HL_INFO
(f
)->mouse_face_defer
= 0;
698 #ifdef NS_IMPL_GNUSTEP
699 /* trigger flush only in the rectangle we tracked as being drawn */
700 [view unlockFocusNeedsFlush
: NO
];
701 /*fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", uRect.origin.x, uRect.origin.y, uRect.size.width, uRect.size.height); */
702 [view lockFocusInRect
: uRect
];
706 [[view window
] flushWindow
];
709 ns_updating_frame
= NULL;
710 NSTRACE
(ns_update_end
);
715 ns_flush
(struct frame
*f
)
716 /* --------------------------------------------------------------------------
718 NS impl is no-op since currently we flush in ns_update_end and elsewhere
719 -------------------------------------------------------------------------- */
726 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
727 /* --------------------------------------------------------------------------
728 Internal: Focus on given frame. During small local updates this is used to
729 draw, however during large updates, ns_update_begin and ns_update_end are
730 called to wrap the whole thing, in which case these calls are stubbed out.
731 Except, on GNUstep, we accumulate the rectangle being drawn into, because
732 the back end won't do this automatically, and will just end up flushing
734 -------------------------------------------------------------------------- */
736 // NSTRACE
(ns_focus
);
737 #ifdef NS_IMPL_GNUSTEP
740 u
= NSUnionRect
(r
[0], r
[1]);
745 fprintf (stderr, "focus: %d", c++);
746 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
747 fprintf (stderr, "\n"); */
749 if (f
!= ns_updating_frame
)
751 NSView
*view = FRAME_NS_VIEW
(f
);
752 if (view != focus_view
)
754 if (focus_view
!= NULL)
756 [focus_view unlockFocus
];
757 [[focus_view window
] flushWindow
];
762 #ifdef NS_IMPL_GNUSTEP
763 r ?
[view lockFocusInRect
: u
] : [view lockFocus
];
768 /*if (view) debug_lock++; */
770 #ifdef NS_IMPL_GNUSTEP
773 /* more than one rect being drawn into */
776 [view unlockFocus
]; /* add prev rect to redraw list */
777 [view lockFocusInRect
: u
]; /* focus for draw in new rect */
782 #ifdef NS_IMPL_GNUSTEP
785 /* in batch mode, but in GNUstep must still track rectangles explicitly */
786 uRect
= (r ? NSUnionRect
(uRect
, u
) : [FRAME_NS_VIEW
(f
) visibleRect
]);
793 [[NSGraphicsContext currentContext
] saveGraphicsState
];
795 NSRectClipList
(r
, 2);
804 ns_unfocus
(struct frame
*f
)
805 /* --------------------------------------------------------------------------
806 Internal: Remove focus on given frame
807 -------------------------------------------------------------------------- */
809 // NSTRACE
(ns_unfocus
);
813 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
817 if (f
!= ns_updating_frame
)
819 if (focus_view
!= NULL)
821 [focus_view unlockFocus
];
822 [[focus_view window
] flushWindow
];
831 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
, int area
, BOOL gc
)
832 /* --------------------------------------------------------------------------
833 Internal (but parallels other terms): Focus drawing on given row
834 -------------------------------------------------------------------------- */
836 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
838 int window_x
, window_y
, window_width
;
840 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
842 clip_rect.origin.x
= window_x
- FRAME_INTERNAL_BORDER_WIDTH
(f
);
843 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
844 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
845 clip_rect.
size.width
= window_width
+ 2 * FRAME_INTERNAL_BORDER_WIDTH
(f
);
846 clip_rect.
size.height
= row
->visible_height
;
848 /* allow a full-height row at the top when requested
849 (used to draw fringe all the way through internal border area) */
850 if (gc
&& clip_rect.origin.y
< 5)
852 clip_rect.origin.y
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
853 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
856 /* likewise at bottom */
858 FRAME_PIXEL_HEIGHT
(f
) - (clip_rect.origin.y
+ clip_rect.
size.height
) < 5)
859 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
861 ns_focus
(f
, &clip_rect
, 1);
866 ns_ring_bell
(struct frame
*f
)
867 /* --------------------------------------------------------------------------
869 -------------------------------------------------------------------------- */
871 NSTRACE
(ns_ring_bell
);
874 NSAutoreleasePool
*pool
;
875 struct frame
*frame
= SELECTED_FRAME
();
879 pool
= [[NSAutoreleasePool alloc
] init
];
881 view = FRAME_NS_VIEW
(frame
);
885 NSPoint dim
= NSMakePoint
(128, 128);
888 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
889 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
890 r.
size.width
= dim.x
;
891 r.
size.height
= dim.y
;
892 surr
= NSInsetRect
(r
, -2, -2);
893 ns_focus
(frame
, &surr
, 1);
894 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
895 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
896 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
898 [[view window
] flushWindow
];
900 [[view window
] restoreCachedImage
];
901 [[view window
] flushWindow
];
915 ns_reset_terminal_modes
(struct terminal *terminal)
916 /* Externally called as hook */
918 NSTRACE
(ns_reset_terminal_modes
);
923 ns_set_terminal_modes
(struct terminal *terminal)
924 /* Externally called as hook */
926 NSTRACE
(ns_set_terminal_modes
);
931 /* ==========================================================================
933 Frame / window manager related functions
935 ========================================================================== */
939 ns_raise_frame
(struct frame
*f
)
940 /* --------------------------------------------------------------------------
941 Bring window to foreground and make it active
942 -------------------------------------------------------------------------- */
944 NSView
*view = FRAME_NS_VIEW
(f
);
947 FRAME_SAMPLE_VISIBILITY
(f
);
948 if (FRAME_VISIBLE_P
(f
))
950 [[view window
] makeKeyAndOrderFront
: NSApp
];
957 ns_lower_frame
(struct frame
*f
)
958 /* --------------------------------------------------------------------------
960 -------------------------------------------------------------------------- */
962 NSView
*view = FRAME_NS_VIEW
(f
);
965 [[view window
] orderBack
: NSApp
];
971 ns_frame_raise_lower
(struct frame
*f
, int raise
)
972 /* --------------------------------------------------------------------------
974 -------------------------------------------------------------------------- */
976 NSTRACE
(ns_frame_raise_lower
);
986 ns_frame_rehighlight
(struct frame
*frame
)
987 /* --------------------------------------------------------------------------
988 External (hook): called on things like window switching within frame
989 -------------------------------------------------------------------------- */
991 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(frame
);
992 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
994 NSTRACE
(ns_frame_rehighlight
);
995 if (dpyinfo
->x_focus_frame
)
997 dpyinfo
->x_highlight_frame
998 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
999 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1000 : dpyinfo
->x_focus_frame
);
1001 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
1003 FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
) = Qnil
;
1004 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1008 dpyinfo
->x_highlight_frame
= 0;
1010 if (dpyinfo
->x_highlight_frame
&&
1011 dpyinfo
->x_highlight_frame
!= old_highlight
)
1015 x_update_cursor
(old_highlight
, 1);
1016 x_set_frame_alpha
(old_highlight
);
1018 if (dpyinfo
->x_highlight_frame
)
1020 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
1021 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
1028 x_make_frame_visible
(struct frame
*f
)
1029 /* --------------------------------------------------------------------------
1030 External: Show the window (X11 semantics)
1031 -------------------------------------------------------------------------- */
1033 NSTRACE
(x_make_frame_visible
);
1034 /* XXX: at some points in past this was not needed, as the only place that
1035 called this (frame.c:Fraise_frame ()) also called raise_lower;
1036 if this ends up the case again, comment this out again. */
1037 if (!FRAME_VISIBLE_P
(f
))
1039 f
->async_visible
= 1;
1046 x_make_frame_invisible
(struct frame
*f
)
1047 /* --------------------------------------------------------------------------
1048 External: Hide the window (X11 semantics)
1049 -------------------------------------------------------------------------- */
1051 NSView
* view = FRAME_NS_VIEW
(f
);
1052 NSTRACE
(x_make_frame_invisible
);
1054 [[view window
] orderOut
: NSApp
];
1055 f
->async_visible
= 0;
1056 f
->async_iconified
= 0;
1061 x_iconify_frame
(struct frame
*f
)
1062 /* --------------------------------------------------------------------------
1063 External: Iconify window
1064 -------------------------------------------------------------------------- */
1066 NSView
* view = FRAME_NS_VIEW
(f
);
1067 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1068 NSTRACE
(x_iconify_frame
);
1071 if (dpyinfo
->x_highlight_frame
== f
)
1072 dpyinfo
->x_highlight_frame
= 0;
1074 if ([[view window
] windowNumber
] <= 0)
1076 /* the window is still deferred. Make it very small, bring it
1077 on screen and order it out. */
1078 NSRect s
= { { 100, 100}, {0, 0} };
1080 t
= [[view window
] frame
];
1081 [[view window
] setFrame
: s display
: NO
];
1082 [[view window
] orderBack
: NSApp
];
1083 [[view window
] orderOut
: NSApp
];
1084 [[view window
] setFrame
: t display
: NO
];
1086 [[view window
] miniaturize
: NSApp
];
1089 /* Free X resources of frame F. */
1092 x_free_frame_resources
(struct frame
*f
)
1094 NSView
*view = FRAME_NS_VIEW
(f
);
1095 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1096 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1097 NSTRACE
(x_destroy_window
);
1100 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1104 free_frame_menubar
(f
);
1106 if (FRAME_FACE_CACHE
(f
))
1107 free_frame_faces
(f
);
1109 if (f
== dpyinfo
->x_focus_frame
)
1110 dpyinfo
->x_focus_frame
= 0;
1111 if (f
== dpyinfo
->x_highlight_frame
)
1112 dpyinfo
->x_highlight_frame
= 0;
1113 if (f
== hlinfo
->mouse_face_mouse_frame
)
1115 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1116 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1117 hlinfo
->mouse_face_window
= Qnil
;
1118 hlinfo
->mouse_face_deferred_gc
= 0;
1119 hlinfo
->mouse_face_mouse_frame
= 0;
1122 if (f
->output_data.ns
->miniimage
!= nil
)
1123 [f
->output_data.ns
->miniimage release
];
1125 [[view window
] close];
1128 xfree
(f
->output_data.ns
);
1134 x_destroy_window
(struct frame
*f
)
1135 /* --------------------------------------------------------------------------
1136 External: Delete the window
1137 -------------------------------------------------------------------------- */
1139 NSTRACE
(x_destroy_window
);
1141 x_free_frame_resources
(f
);
1147 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1148 /* --------------------------------------------------------------------------
1149 External: Position the window
1150 -------------------------------------------------------------------------- */
1152 NSView
*view = FRAME_NS_VIEW
(f
);
1153 NSArray
*screens
= [NSScreen screens
];
1154 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1155 NSScreen
*screen
= [[view window
] screen
];
1157 NSTRACE
(x_set_offset
);
1164 if (view != nil
&& screen
&& fscreen
)
1166 f
->left_pos
= f
->size_hint_flags
& XNegative
1167 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1169 /* We use visibleFrame here to take menu bar into account.
1170 Ideally we should also adjust left/top with visibleFrame.origin. */
1172 f
->top_pos
= f
->size_hint_flags
& YNegative
1173 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1174 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1175 - FRAME_TOOLBAR_HEIGHT
(f
))
1177 #ifdef NS_IMPL_GNUSTEP
1178 if (f
->left_pos
< 100)
1179 f
->left_pos
= 100; /* don't overlap menu */
1181 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1183 f
->output_data.ns
->dont_constrain
= 0;
1184 [[view window
] setFrameTopLeftPoint
:
1185 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1186 SCREENMAXBOUND
([fscreen frame
].
size.height
1187 - NS_TOP_POS
(f
)))];
1188 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1196 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1197 /* --------------------------------------------------------------------------
1198 Adjust window pixel size based on given character grid size
1199 Impl is a bit more complex than other terms, need to do some
1201 -------------------------------------------------------------------------- */
1203 EmacsView
*view = FRAME_NS_VIEW
(f
);
1204 EmacsToolbar
*toolbar
= [view toolbar
];
1205 NSWindow
*window
= [view window
];
1206 NSRect wr
= [window frame
];
1207 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1208 int pixelwidth
, pixelheight
;
1209 static int oldRows
, oldCols
, oldFontWidth
, oldFontHeight
;
1211 static
struct frame
*oldF
;
1213 NSTRACE
(x_set_window_size
);
1217 && rows
== oldRows
&& cols
== oldCols
1218 && oldFontWidth
== FRAME_COLUMN_WIDTH
(f
)
1219 && oldFontHeight
== FRAME_LINE_HEIGHT
(f
)
1223 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1227 check_frame_size
(f
, &rows
, &cols
);
1231 oldFontWidth
= FRAME_COLUMN_WIDTH
(f
);
1232 oldFontHeight
= FRAME_LINE_HEIGHT
(f
);
1235 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1236 compute_fringe_widths
(f
, 0);
1238 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1239 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1241 /* If we have a toolbar, take its height into account. */
1243 /* NOTE: previously this would generate wrong result if toolbar not
1244 yet displayed and fixing toolbar_height=32 helped, but
1245 now (200903) seems no longer needed */
1246 FRAME_TOOLBAR_HEIGHT
(f
) =
1247 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1248 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1250 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1252 wr.
size.width
= pixelwidth
+ f
->border_width
;
1253 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1254 + FRAME_TOOLBAR_HEIGHT
(f
);
1256 /* Do not try to constrain to this screen. We may have multiple
1257 screens, and want Emacs to span those. Constraining to screen
1258 prevents that, and that is not nice to the user. */
1259 if (f
->output_data.ns
->zooming
)
1260 f
->output_data.ns
->zooming
= 0;
1262 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1264 [view setRows
: rows andColumns
: cols
];
1265 [window setFrame
: wr display
: YES
];
1267 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1269 /* This is a trick to compensate for Emacs' managing the scrollbar area
1270 as a fixed number of standard character columns. Instead of leaving
1271 blank space for the extra, we chopped it off above. Now for
1272 left-hand scrollbars, we shift all rendering to the left by the
1273 difference between the real width and Emacs' imagined one. For
1274 right-hand bars, don't worry about it since the extra is never used.
1275 (Obviously doesn't work for vertically split windows tho..) */
1277 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1278 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1279 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1280 : NSMakePoint
(0, 0);
1281 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1282 [view setBoundsOrigin
: origin
];
1285 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1286 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1287 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1288 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1290 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1291 cancel_mouse_face
(f
);
1298 /* ==========================================================================
1302 ========================================================================== */
1306 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1308 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1309 if (idx
< 1 || idx
>= color_table
->avail
)
1311 return color_table
->colors
[idx
];
1316 ns_index_color
(NSColor
*color
, struct frame
*f
)
1318 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1322 if (!color_table
->colors
)
1324 color_table
->size = NS_COLOR_CAPACITY
;
1325 color_table
->avail
= 1; /* skip idx=0 as marker */
1327 = (NSColor
**)xmalloc
(color_table
->size * sizeof
(NSColor
*));
1328 color_table
->colors
[0] = nil
;
1329 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1332 /* do we already have this color ? */
1333 for (i
= 1; i
< color_table
->avail
; i
++)
1334 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1337 if ([color_table
->empty_indices count
] > 0)
1339 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1340 [color_table
->empty_indices removeObject
: index
];
1341 idx
= [index unsignedLongValue
];
1345 if (color_table
->avail
== color_table
->size)
1346 color_table
->colors
=
1347 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1348 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1349 idx
= color_table
->avail
++;
1352 color_table
->colors
[idx
] = color
;
1354 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1360 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1362 struct ns_color_table
*color_table
;
1369 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1371 if (idx
<= 0 || idx
>= color_table
->size) {
1372 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1376 index
= [NSNumber numberWithUnsignedInt
: idx
];
1377 if ([color_table
->empty_indices containsObject
: index
]) {
1378 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1382 color
= color_table
->colors
[idx
];
1384 color_table
->colors
[idx
] = nil
;
1385 [color_table
->empty_indices addObject
: index
];
1386 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1391 ns_get_color
(const
char *name
, NSColor
**col
)
1392 /* --------------------------------------------------------------------------
1394 -------------------------------------------------------------------------- */
1395 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1396 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1397 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1400 static
char hex
[20];
1402 float r
= -1.0, g
, b
;
1403 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1405 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1408 if ([nsname isEqualToString
: @"ns_selection_color"
])
1410 nsname
= ns_selection_color
;
1411 name
= [ns_selection_color UTF8String
];
1414 /* First, check for some sort of numeric specification. */
1417 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1419 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1420 [scanner scanFloat
: &r
];
1421 [scanner scanFloat
: &g
];
1422 [scanner scanFloat
: &b
];
1424 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1426 strncpy
(hex
, name
+ 4, 19);
1428 scaling
= (strlen
(hex
) - 2) / 3;
1430 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1432 int len
= (strlen
(name
) - 1);
1433 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1435 scaling
= strlen
(name
+start
) / 3;
1436 for (i
=0; i
<3; i
++) {
1437 strncpy
(hex
+ i
* (scaling
+ 1), name
+ start
+ i
* scaling
, scaling
);
1438 hex
[(i
+1) * (scaling
+ 1) - 1] = '/';
1440 hex
[3 * (scaling
+ 1) - 1] = '\0';
1446 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1447 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1457 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1462 /* Otherwise, color is expected to be from a list */
1464 NSEnumerator
*lenum
, *cenum
;
1468 #ifdef NS_IMPL_GNUSTEP
1469 /* XXX: who is wrong, the requestor or the implementation? */
1470 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1472 nsname
= @"highlightColor"
;
1475 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1476 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1478 cenum
= [[clist allKeys
] objectEnumerator
];
1479 while ( (name
= [cenum nextObject
]) && new
== nil
)
1481 if ([name compare
: nsname
1482 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1483 new
= [clist colorWithKey
: name
];
1489 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1496 ns_get_color_default
(const
char *name
, NSColor
*dflt
)
1497 /* --------------------------------------------------------------------------
1498 Parse a color or use a default value
1499 -------------------------------------------------------------------------- */
1503 if (ns_get_color
(name
, &col
))
1511 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1512 /* --------------------------------------------------------------------------
1513 Convert a Lisp string object to a NS color
1514 -------------------------------------------------------------------------- */
1516 NSTRACE
(ns_lisp_to_color
);
1517 if (STRINGP
(color
))
1518 return ns_get_color
(SDATA
(color
), col
);
1519 else if (SYMBOLP
(color
))
1520 return ns_get_color
(SDATA
(SYMBOL_NAME
(color
)), col
);
1526 ns_color_to_lisp
(NSColor
*col
)
1527 /* --------------------------------------------------------------------------
1528 Convert a color to a lisp string with the RGB equivalent
1529 -------------------------------------------------------------------------- */
1531 CGFloat red
, green
, blue
, alpha
, gray;
1534 NSTRACE
(ns_color_to_lisp
);
1537 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1539 if ((str
=[[col colorNameComponent
] UTF8String
]))
1542 return build_string
((char *)str
);
1545 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1546 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1547 if (red
==green
&& red
==blue
)
1549 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1550 getWhite
: &gray alpha
: &alpha
];
1551 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1552 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1554 return build_string
(buf
);
1557 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1558 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1561 return build_string
(buf
);
1566 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1567 /* --------------------------------------------------------------------------
1568 Get ARGB values out of NSColor col and put them into color_def.
1569 If setPixel, set the pixel to a concatenated version.
1570 and set color_def pixel to the resulting index.
1571 -------------------------------------------------------------------------- */
1575 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1576 color_def
->red
= r
* 65535;
1577 color_def
->green
= g
* 65535;
1578 color_def
->blue
= b
* 65535;
1580 if (setPixel
== YES
)
1582 = ARGB_TO_ULONG
((int
)(a
*255),
1583 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1588 ns_defined_color
(struct frame
*f
,
1593 /* --------------------------------------------------------------------------
1594 Return 1 if named color found, and set color_def rgb accordingly.
1595 If makeIndex and alloc are nonzero put the color in the color_table,
1596 and set color_def pixel to the resulting index.
1597 If makeIndex is zero, set color_def pixel to ARGB.
1598 Return 0 if not found
1599 -------------------------------------------------------------------------- */
1602 NSTRACE
(ns_defined_color
);
1605 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1610 if (makeIndex
&& alloc
)
1611 color_def
->pixel
= ns_index_color
(col
, f
);
1612 ns_query_color
(col
, color_def
, !makeIndex
);
1619 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1620 /* --------------------------------------------------------------------------
1621 return an autoreleased RGB color
1622 -------------------------------------------------------------------------- */
1624 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1625 if (r
< 0.0) r
= 0.0;
1626 else if (r
> 1.0) r
= 1.0;
1627 if (g
< 0.0) g
= 0.0;
1628 else if (g
> 1.0) g
= 1.0;
1629 if (b
< 0.0) b
= 0.0;
1630 else if (b
> 1.0) b
= 1.0;
1631 if (a
< 0.0) a
= 0.0;
1632 else if (a
> 1.0) a
= 1.0;
1633 return (unsigned
long) ns_index_color
(
1634 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1639 x_set_frame_alpha
(struct frame
*f
)
1640 /* --------------------------------------------------------------------------
1641 change the entire-frame transparency
1642 -------------------------------------------------------------------------- */
1644 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1645 EmacsView
*view = FRAME_NS_VIEW
(f
);
1647 double alpha_min
= 1.0;
1649 if (dpyinfo
->x_highlight_frame
== f
)
1650 alpha
= f
->alpha
[0];
1652 alpha
= f
->alpha
[1];
1654 if (FLOATP
(Vframe_alpha_lower_limit
))
1655 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1656 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1657 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1661 else if (1.0 < alpha
)
1663 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1666 #ifdef NS_IMPL_COCOA
1667 [[view window
] setAlphaValue
: alpha
];
1672 /* ==========================================================================
1676 ========================================================================== */
1680 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1681 /* --------------------------------------------------------------------------
1682 Programmatically reposition mouse pointer in pixel coordinates
1683 -------------------------------------------------------------------------- */
1685 NSTRACE
(x_set_mouse_pixel_position
);
1688 /* FIXME: this does not work, and what about GNUstep? */
1689 #ifdef NS_IMPL_COCOA
1690 [FRAME_NS_VIEW
(f
) lockFocus
];
1691 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1692 [FRAME_NS_VIEW
(f
) unlockFocus
];
1699 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1700 /* --------------------------------------------------------------------------
1701 Programmatically reposition mouse pointer in character coordinates
1702 -------------------------------------------------------------------------- */
1706 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1707 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1709 if (pix_x
< 0) pix_x
= 0;
1710 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1712 if (pix_y
< 0) pix_y
= 0;
1713 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1715 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1720 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1721 /* ------------------------------------------------------------------------
1722 Called by EmacsView on mouseMovement events. Passes on
1723 to emacs mainstream code if we moved off of a rect of interest
1724 known as last_mouse_glyph.
1725 ------------------------------------------------------------------------ */
1727 // NSTRACE
(note_mouse_movement
);
1729 XSETFRAME
(last_mouse_motion_frame
, frame
);
1731 /* Note, this doesn't get called for enter/leave, since we don't have a
1732 position. Those are taken care of in the corresponding NSView methods. */
1734 /* has movement gone beyond last rect we were tracking? */
1735 if (x
< last_mouse_glyph.origin.x ||
1736 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1737 y
< last_mouse_glyph.origin.y ||
1738 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1740 ns_update_begin
(frame
);
1741 frame
->mouse_moved
= 1;
1742 note_mouse_highlight
(frame
, x
, y
);
1743 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1744 ns_update_end
(frame
);
1753 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1754 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1756 /* --------------------------------------------------------------------------
1757 External (hook): inform emacs about mouse position and hit parts.
1758 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1759 x & y should be position in the scrollbar (the whole bar, not the handle)
1760 and length of scrollbar respectively
1761 -------------------------------------------------------------------------- */
1766 Lisp_Object frame
, tail
;
1768 struct ns_display_info
*dpyinfo
;
1770 NSTRACE
(ns_mouse_position
);
1774 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1778 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1782 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1784 /* TODO: we do not use this path at the moment because drag events will
1785 go directly to the EmacsScroller. Leaving code in for now. */
1786 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1788 if (time
) *time
= last_mouse_movement_time
;
1789 last_mouse_scroll_bar
= nil
;
1793 /* Clear the mouse-moved flag for every frame on this display. */
1794 FOR_EACH_FRAME
(tail
, frame
)
1795 if (FRAME_NS_P
(XFRAME
(frame
))
1796 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1797 XFRAME
(frame
)->mouse_moved
= 0;
1799 last_mouse_scroll_bar
= nil
;
1800 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1801 f
= last_mouse_frame
;
1803 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1804 : SELECTED_FRAME
();
1806 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1808 view = FRAME_NS_VIEW
(*fp
);
1810 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1811 position
= [view convertPoint
: position fromView
: nil
];
1812 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1813 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1815 if (bar_window
) *bar_window
= Qnil
;
1816 if (part
) *part
= 0; /*scroll_bar_handle; */
1818 if (x
) XSETINT
(*x
, lrint
(position.x
));
1819 if (y
) XSETINT
(*y
, lrint
(position.y
));
1820 if (time
) *time
= last_mouse_movement_time
;
1830 ns_frame_up_to_date
(struct frame
*f
)
1831 /* --------------------------------------------------------------------------
1832 External (hook): Fix up mouse highlighting right after a full update.
1833 Some highlighting was deferred if GC was happening during
1834 note_mouse_highlight (), while other highlighting was deferred for update.
1835 -------------------------------------------------------------------------- */
1837 NSTRACE
(ns_frame_up_to_date
);
1841 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1842 if ((hlinfo
->mouse_face_deferred_gc || f
==hlinfo
->mouse_face_mouse_frame
)
1843 /*&& hlinfo->mouse_face_mouse_frame*/)
1847 if (hlinfo
->mouse_face_mouse_frame
)
1848 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1849 hlinfo
->mouse_face_mouse_x
,
1850 hlinfo
->mouse_face_mouse_y
);
1851 hlinfo
->mouse_face_deferred_gc
= 0;
1860 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1861 /* --------------------------------------------------------------------------
1862 External (RIF): set frame mouse pointer type.
1863 -------------------------------------------------------------------------- */
1865 NSTRACE
(ns_define_frame_cursor
);
1866 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1868 EmacsView
*view = FRAME_NS_VIEW
(f
);
1869 FRAME_POINTER_TYPE
(f
) = cursor
;
1870 [[view window
] invalidateCursorRectsForView
: view];
1871 /* Redisplay assumes this function also draws the changed frame
1872 cursor, but this function doesn't, so do it explicitly. */
1873 x_update_cursor
(f
, 1);
1879 /* ==========================================================================
1883 ========================================================================== */
1887 ns_convert_key
(unsigned code
)
1888 /* --------------------------------------------------------------------------
1889 Internal call used by NSView-keyDown.
1890 -------------------------------------------------------------------------- */
1892 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1893 / sizeof
(convert_ns_to_X_keysym
[0]));
1895 /* An array would be faster, but less easy to read. */
1896 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1897 if (code
== convert_ns_to_X_keysym
[keysym
])
1898 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1900 /* if decide to use keyCode and Carbon table, use this line:
1901 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1906 x_get_keysym_name
(int keysym
)
1907 /* --------------------------------------------------------------------------
1908 Called by keyboard.c. Not sure if the return val is important, except
1910 -------------------------------------------------------------------------- */
1912 static
char value
[16];
1913 NSTRACE
(x_get_keysym_name
);
1914 sprintf (value
, "
%d", keysym);
1920 /* ==========================================================================
1922 Block drawing operations
1924 ========================================================================== */
1928 ns_redraw_scroll_bars
(struct frame
*f
)
1932 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1933 NSTRACE
(ns_judge_scroll_bars
);
1934 for (i
=[subviews count
]-1; i
>= 0; i
--)
1936 view = [subviews objectAtIndex
: i
];
1937 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
1944 ns_clear_frame
(struct frame
*f
)
1945 /* --------------------------------------------------------------------------
1946 External (hook): Erase the entire frame
1947 -------------------------------------------------------------------------- */
1949 NSView
*view = FRAME_NS_VIEW
(f
);
1952 NSTRACE
(ns_clear_frame
);
1956 /* comes on initial frame because we have
1957 after-make-frame-functions = select-frame */
1958 if (!FRAME_DEFAULT_FACE
(f
))
1961 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
1963 output_cursor.hpos
= output_cursor.vpos
= 0;
1964 output_cursor.x
= -1;
1969 ns_focus
(f
, &r
, 1);
1970 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
1974 #ifdef NS_IMPL_COCOA
1975 [[view window
] display
]; /* redraw resize handle */
1978 /* as of 2006/11 or so this is now needed */
1979 ns_redraw_scroll_bars
(f
);
1985 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
1986 /* --------------------------------------------------------------------------
1987 External (RIF): Clear section of frame
1988 -------------------------------------------------------------------------- */
1990 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
1991 NSView
*view = FRAME_NS_VIEW
(f
);
1992 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
1997 NSTRACE
(ns_clear_frame_area
);
1999 r
= NSIntersectionRect
(r
, [view frame
]);
2000 ns_focus
(f
, &r
, 1);
2001 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
2003 #ifdef NS_IMPL_COCOA
2005 /* clip out the resize handle */
2006 NSWindow
*window
= [FRAME_NS_VIEW
(f
) window
];
2008 = [view convertRect
: ns_resize_handle_rect
(window
) fromView
: nil
];
2010 ir
= NSIntersectionRect
(r
, ir
);
2011 if (NSIsEmptyRect
(ir
))
2017 #ifdef NS_IMPL_COCOA
2021 NSRect r1
= r
, r2
= r
; /* upper and lower non-intersecting */
2022 r1.
size.height
-= ir.
size.height
;
2023 r2.origin.y
+= r1.
size.height
;
2024 r2.
size.width
-= ir.
size.width
;
2025 r2.
size.height
= ir.
size.height
;
2038 ns_scroll_run
(struct window
*w
, struct run
*run
)
2039 /* --------------------------------------------------------------------------
2040 External (RIF): Insert or delete n lines at line vpos
2041 -------------------------------------------------------------------------- */
2043 struct frame
*f
= XFRAME
(w
->frame
);
2044 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2046 NSTRACE
(ns_scroll_run
);
2048 /* begin copy from other terms */
2049 /* Get frame-relative bounding box of the text display area of W,
2050 without mode lines. Include in this box the left and right
2052 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2054 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2055 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2056 bottom_y
= y
+ height
;
2060 /* Scrolling up. Make sure we don't copy part of the mode
2061 line at the bottom. */
2062 if (from_y
+ run
->height
> bottom_y
)
2063 height
= bottom_y
- from_y
;
2065 height
= run
->height
;
2069 /* Scrolling down. Make sure we don't copy over the mode line.
2071 if (to_y
+ run
->height
> bottom_y
)
2072 height
= bottom_y
- to_y
;
2074 height
= run
->height
;
2076 /* end copy from other terms */
2087 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2088 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2089 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2091 ns_focus
(f
, &dstRect
, 1);
2092 NSCopyBits
(0, srcRect
, dstOrigin
);
2101 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2102 /* --------------------------------------------------------------------------
2103 External (RIF): preparatory to fringe update after text was updated
2104 -------------------------------------------------------------------------- */
2106 struct window
*w
= updated_window
;
2110 NSTRACE
(ns_after_update_window_line
);
2112 /* begin copy from other terms */
2115 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2116 desired_row
->redraw_fringe_bitmaps_p
= 1;
2118 /* When a window has disappeared, make sure that no rest of
2119 full-width rows stays visible in the internal border.
2120 Under NS this is drawn inside the fringes. */
2121 if (windows_or_buffers_changed
2122 && (f
= XFRAME
(w
->frame
),
2123 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2125 && (height
= desired_row
->visible_height
,
2128 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2130 /* Internal border is drawn below the tool bar. */
2131 if (WINDOWP
(f
->tool_bar_window
)
2132 && w
== XWINDOW
(f
->tool_bar_window
))
2134 /* end copy from other terms */
2137 if (!desired_row
->full_width_p
)
2139 int x1
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2140 + WINDOW_LEFT_FRINGE_WIDTH
(w
);
2141 int x2
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2142 + FRAME_PIXEL_WIDTH
(f
) - NS_SCROLL_BAR_WIDTH
(f
)
2143 - WINDOW_RIGHT_FRINGE_WIDTH
(w
)
2144 - FRAME_INTERNAL_BORDER_WIDTH
(f
);
2145 ns_clear_frame_area
(f
, x1
, y
, width
, height
);
2146 ns_clear_frame_area
(f
, x2
, y
, width
, height
);
2154 ns_shift_glyphs_for_insert
(struct frame
*f
,
2155 int x
, int y
, int width
, int height
,
2157 /* --------------------------------------------------------------------------
2158 External (RIF): copy an area horizontally, don't worry about clearing src
2159 -------------------------------------------------------------------------- */
2161 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2162 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2163 NSPoint dstOrigin
= dstRect.origin
;
2165 NSTRACE
(ns_shift_glyphs_for_insert
);
2167 ns_focus
(f
, &dstRect
, 1);
2168 NSCopyBits
(0, srcRect
, dstOrigin
);
2174 /* ==========================================================================
2176 Character encoding and metrics
2178 ========================================================================== */
2182 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2183 /* --------------------------------------------------------------------------
2184 External (RIF); compute left/right overhang of whole string and set in s
2185 -------------------------------------------------------------------------- */
2187 struct face
*face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2188 struct font
*font
= s
->font
; /*face->font; */
2192 struct font_metrics metrics
;
2193 unsigned int codes
[2];
2194 codes
[0] = *(s
->char2b
);
2195 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2197 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2198 s
->left_overhang
= -metrics.lbearing
;
2200 = metrics.rbearing
> metrics.width
2201 ? metrics.rbearing
- metrics.width
: 0;
2205 s
->left_overhang
= 0;
2206 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2207 FONT_HEIGHT
(font
) * 0.2 : 0;
2213 /* ==========================================================================
2215 Fringe and cursor drawing
2217 ========================================================================== */
2220 extern int max_used_fringe_bitmap
;
2222 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2223 struct draw_fringe_bitmap_params
*p
)
2224 /* --------------------------------------------------------------------------
2225 External (RIF); fringe-related
2226 -------------------------------------------------------------------------- */
2228 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2229 struct face
*face
= p
->face
;
2231 static EmacsImage
**bimgs
= NULL;
2232 static int nBimgs
= 0;
2233 /* NS-specific: move internal border inside fringe */
2234 int x
= p
->bx
< 0 ? p
->x
: p
->bx
;
2235 int wd
= p
->bx
< 0 ? p
->wd
: p
->nx
;
2236 BOOL fringeOnVeryLeft
2237 = x
- WINDOW_LEFT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
)
2238 - FRAME_INTERNAL_BORDER_WIDTH
(f
) < 10;
2239 BOOL fringeOnVeryRight
2240 = FRAME_PIXEL_WIDTH
(f
) - x
- wd
- FRAME_INTERNAL_BORDER_WIDTH
(f
)
2241 - WINDOW_RIGHT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
) < 10;
2242 int xAdjust
= FRAME_INTERNAL_BORDER_WIDTH
(f
) *
2243 (fringeOnVeryLeft ?
-1 : (fringeOnVeryRight ?
1 : 0));
2245 /* grow bimgs if needed */
2246 if (nBimgs
< max_used_fringe_bitmap
)
2248 EmacsImage
**newBimgs
2249 = xmalloc
(max_used_fringe_bitmap
* sizeof
(EmacsImage
*));
2250 memset
(newBimgs
, 0, max_used_fringe_bitmap
* sizeof
(EmacsImage
*));
2254 memcpy
(newBimgs
, bimgs
, nBimgs
* sizeof
(EmacsImage
*));
2259 nBimgs
= max_used_fringe_bitmap
;
2262 /* Must clip because of partially visible lines. */
2263 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2264 ns_clip_to_row
(w
, row
, -1, YES
);
2266 if (p
->bx
>= 0 && !p
->overlay_p
)
2268 int yAdjust
= rowY
- FRAME_INTERNAL_BORDER_WIDTH
(f
) < 5 ?
2269 -FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0;
2270 int yIncr
= FRAME_PIXEL_HEIGHT
(f
) - (p
->by
+yAdjust
+ p
->ny
) < 5 ?
2271 FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0
2272 + (yAdjust ? FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0);
2273 NSRect r
= NSMakeRect
(p
->bx
+xAdjust
, p
->by
+yAdjust
, p
->nx
, p
->ny
+yIncr
);
2275 [ns_lookup_indexed_color
(face
->background
, f
) set];
2281 NSRect r
= NSMakeRect
(p
->x
+xAdjust
, p
->y
, p
->wd
, p
->h
);
2282 NSPoint pt
= r.origin
;
2283 EmacsImage
*img
= bimgs
[p
->which - 1];
2287 unsigned short
*bits
= p
->bits
+ p
->dh
;
2290 unsigned
char *cbits
= xmalloc
(len
);
2292 for (i
=0; i
<len
; i
++)
2293 cbits
[i
] = ~
(bits
[i
] & 0xff);
2294 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2296 bimgs
[p
->which - 1] = img
;
2301 /* Since we composite the bitmap instead of just blitting it, we need
2302 to erase the whole background. */
2303 [ns_lookup_indexed_color
(face
->background
, f
) set];
2306 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2307 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2314 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2315 int x
, int y
, int cursor_type
, int cursor_width
,
2316 int on_p
, int active_p
)
2317 /* --------------------------------------------------------------------------
2318 External call (RIF): draw cursor.
2319 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2320 -------------------------------------------------------------------------- */
2323 int fx
, fy
, h
, cursor_height
;
2324 struct frame
*f
= WINDOW_XFRAME
(w
);
2325 struct glyph
*phys_cursor_glyph
;
2327 struct glyph
*cursor_glyph
;
2329 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2331 /* If cursor is out of bounds, don't draw garbage. This can happen
2332 in mini-buffer windows when switching between echo area glyphs
2335 NSTRACE
(dumpcursor
);
2340 w
->phys_cursor_type
= cursor_type
;
2341 w
->phys_cursor_on_p
= on_p
;
2343 if (cursor_type
== NO_CURSOR
)
2345 w
->phys_cursor_width
= 0;
2349 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2351 if (glyph_row
->exact_window_width_line_p
2352 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2354 glyph_row
->cursor_in_fringe_p
= 1;
2355 draw_fringe_bitmap
(w
, glyph_row
, 0);
2360 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2361 (other terminals do it the other way round). We must set
2362 w->phys_cursor_width to the cursor width. For bar cursors, that
2363 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2364 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2366 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2367 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2368 if (cursor_type
== BAR_CURSOR
)
2370 if (cursor_width
< 1)
2371 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2372 w
->phys_cursor_width
= cursor_width
;
2374 /* If we have an HBAR, "cursor_width" MAY specify height. */
2375 else if (cursor_type
== HBAR_CURSOR
)
2377 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2378 fy
+= h
- cursor_height
;
2382 r.origin.x
= fx
, r.origin.y
= fy
;
2384 r.
size.width
= w
->phys_cursor_width
;
2386 /* FIXME: if we overwrite the internal border area, it does not get erased;
2387 fix by truncating cursor, but better would be to erase properly */
2388 overspill
= r.origin.x
+ r.
size.width
-
2389 WINDOW_TEXT_TO_FRAME_PIXEL_X
(w
, WINDOW_BOX_RIGHT_EDGE_X
(w
)
2390 - WINDOW_TOTAL_FRINGE_WIDTH
(w
) - FRAME_INTERNAL_BORDER_WIDTH
(f
));
2392 r.
size.width
-= overspill
;
2394 /* TODO: only needed in rare cases with last-resort font in HELLO..
2395 should we do this more efficiently? */
2396 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2399 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2400 if (face
&& NS_FACE_BACKGROUND
(face
)
2401 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2403 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2404 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2407 [FRAME_CURSOR_COLOR
(f
) set];
2409 #ifdef NS_IMPL_COCOA
2410 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2411 atomic. Cleaner ways of doing this should be investigated.
2412 One way would be to set a global variable DRAWING_CURSOR
2413 when making the call to draw_phys..(), don't focus in that
2414 case, then move the ns_unfocus() here after that call. */
2415 NSDisableScreenUpdates
();
2418 switch (cursor_type
)
2422 case FILLED_BOX_CURSOR
:
2425 case HOLLOW_BOX_CURSOR
:
2428 NSRectFill
(NSInsetRect
(r
, 1, 1));
2429 [FRAME_CURSOR_COLOR
(f
) set];
2436 /* If the character under cursor is R2L, draw the bar cursor
2437 on the right of its glyph, rather than on the left. */
2438 cursor_glyph
= get_phys_cursor_glyph
(w
);
2439 if ((cursor_glyph
->resolved_level
& 1) != 0)
2440 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2447 /* draw the character under the cursor */
2448 if (cursor_type
!= NO_CURSOR
)
2449 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2451 #ifdef NS_IMPL_COCOA
2452 NSEnableScreenUpdates
();
2459 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2460 /* --------------------------------------------------------------------------
2461 External (RIF): Draw a vertical line.
2462 -------------------------------------------------------------------------- */
2464 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2466 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2468 NSTRACE
(ns_draw_vertical_window_border
);
2470 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2472 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2474 ns_focus
(f
, &r
, 1);
2481 show_hourglass
(struct atimer
*timer
)
2483 if (hourglass_shown_p
)
2488 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2490 hourglass_shown_p
= 1;
2496 hide_hourglass
(void
)
2498 if (!hourglass_shown_p
)
2503 /* TODO: remove NSProgressIndicator from all frames */
2505 hourglass_shown_p
= 0;
2511 /* ==========================================================================
2513 Glyph drawing operations
2515 ========================================================================== */
2518 static inline NSRect
2519 ns_fix_rect_ibw
(NSRect r
, int fibw
, int frame_pixel_width
)
2520 /* --------------------------------------------------------------------------
2521 Under NS we draw internal borders inside fringes, and want full-width
2522 rendering to go all the way to edge. This function makes that correction.
2523 -------------------------------------------------------------------------- */
2525 if (r.origin.y
<= fibw
+1)
2527 r.
size.height
+= r.origin.y
;
2530 if (r.origin.x
<= fibw
+1)
2532 r.
size.width
+= r.origin.x
;
2535 if (frame_pixel_width
- (r.origin.x
+r.
size.width
) <= fibw
+1)
2536 r.
size.width
+= fibw
;
2543 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2544 /* --------------------------------------------------------------------------
2545 Wrapper utility to account for internal border width on full-width lines,
2546 and allow top full-width rows to hit the frame top. nr should be pointer
2547 to two successive NSRects. Number of rects actually used is returned.
2548 -------------------------------------------------------------------------- */
2550 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2551 if (s
->row
->full_width_p
)
2553 *nr
= ns_fix_rect_ibw
(*nr
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2554 FRAME_PIXEL_WIDTH
(s
->f
));
2556 *nr
= ns_fix_rect_ibw
(*(nr
+1), FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2557 FRAME_PIXEL_WIDTH
(s
->f
));
2562 /* --------------------------------------------------------------------
2563 Draw a wavy line under glyph string s. The wave fills wave_height
2570 wave_height = 3 | * * * *
2571 --------------------------------------------------------------------- */
2574 ns_draw_underwave
(struct glyph_string
*s
, CGFloat width
, CGFloat x
)
2576 int wave_height
= 3, wave_length
= 3;
2577 int y
, dx
, dy
, odd
, xmax
;
2582 dy
= wave_height
- 1;
2586 /* Find and set clipping rectangle */
2587 waveClip
= NSMakeRect
(x
, y
, width
, wave_height
);
2588 [[NSGraphicsContext currentContext
] saveGraphicsState
];
2589 NSRectClip
(waveClip
);
2591 /* Draw the waves */
2592 a.x
= x
- ((int
)(x
) % dx);
2594 odd
= (int
)(a.x
/dx
) % 2;
2604 [NSBezierPath strokeLineFromPoint
:a toPoint
:b
];
2605 a.x
= b.x
, a.y
= b.y
;
2606 b.x
+= dx
, b.y
= y
+ odd
*dy
;
2610 /* Restore previous clipping rectangle(s) */
2611 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
2617 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2618 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2619 /* --------------------------------------------------------------------------
2620 Draw underline, overline, and strike-through on glyph string s.
2621 -------------------------------------------------------------------------- */
2623 if (s
->for_overlaps
)
2627 if (face
->underline_p
)
2629 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2631 if (face
->underline_defaulted_p
)
2634 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2636 ns_draw_underwave
(s
, width
, x
);
2638 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2642 unsigned
long thickness
, position
;
2644 /* If the prev was underlined, match its appearance. */
2645 if (s
->prev
&& s
->prev
->face
->underline_p
2646 && s
->prev
->underline_thickness
> 0)
2648 thickness
= s
->prev
->underline_thickness
;
2649 position
= s
->prev
->underline_position
;
2654 unsigned
long descent
;
2657 descent
= s
->y
+ s
->height
- s
->ybase
;
2659 /* Use underline thickness of font, defaulting to 1. */
2660 thickness
= (font
&& font
->underline_thickness
> 0)
2661 ? font
->underline_thickness
: 1;
2663 /* Determine the offset of underlining from the baseline. */
2664 if (x_underline_at_descent_line
)
2665 position
= descent
- thickness
;
2666 else if (x_use_underline_position_properties
2667 && font
&& font
->underline_position
>= 0)
2668 position
= font
->underline_position
;
2670 position
= lround
(font
->descent
/ 2);
2672 position
= underline_minimum_offset
;
2674 position
= max (position
, underline_minimum_offset
);
2676 /* Ensure underlining is not cropped. */
2677 if (descent
<= position
)
2679 position
= descent
- 1;
2682 else if (descent
< position
+ thickness
)
2686 s
->underline_thickness
= thickness
;
2687 s
->underline_position
= position
;
2689 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2691 if (face
->underline_defaulted_p
)
2694 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2698 /* Do overline. We follow other terms in using a thickness of 1
2699 and ignoring overline_margin. */
2700 if (face
->overline_p
)
2703 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2705 if (face
->overline_color_defaulted_p
)
2708 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2712 /* Do strike-through. We follow other terms for thickness and
2713 vertical position.*/
2714 if (face
->strike_through_p
)
2719 dy
= lrint
((s
->height
- 1) / 2);
2720 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2722 if (face
->strike_through_color_defaulted_p
)
2725 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2731 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2732 /* --------------------------------------------------------------------------
2733 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2734 Note we can't just use an NSDrawRect command, because of the possibility
2735 of some sides not being drawn, and because the rect will be filled.
2736 -------------------------------------------------------------------------- */
2742 s.
size.height
= thickness
;
2744 s.origin.y
+= r.
size.height
- thickness
;
2747 s.
size.height
= r.
size.height
;
2748 s.origin.y
= r.origin.y
;
2750 /* left, right (optional) */
2751 s.
size.width
= thickness
;
2756 s.origin.x
+= r.
size.width
- thickness
;
2763 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2764 char top_p
, char bottom_p
, char left_p
, char right_p
,
2765 struct glyph_string
*s
)
2766 /* --------------------------------------------------------------------------
2767 Draw a relief rect inside r, optionally leaving some sides open.
2768 Note we can't just use an NSDrawBezel command, because of the possibility
2769 of some sides not being drawn, and because the rect will be filled.
2770 -------------------------------------------------------------------------- */
2772 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2773 NSColor
*newBaseCol
= nil
;
2776 NSTRACE
(ns_draw_relief
);
2780 if (s
->face
->use_box_color_for_shadows_p
)
2782 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2784 /* else if (s->first_glyph->type == IMAGE_GLYPH
2786 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2788 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2792 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2795 if (newBaseCol
== nil
)
2796 newBaseCol
= [NSColor grayColor
];
2798 if (newBaseCol
!= baseCol
) /* TODO: better check */
2801 baseCol
= [newBaseCol retain
];
2803 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2805 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2808 [(raised_p ? lightCol
: darkCol
) set];
2810 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2813 sr.
size.height
= thickness
;
2814 if (top_p
) NSRectFill
(sr
);
2817 sr.
size.height
= r.
size.height
;
2818 sr.
size.width
= thickness
;
2819 if (left_p
) NSRectFill
(sr
);
2821 [(raised_p ? darkCol
: lightCol
) set];
2824 sr.
size.width
= r.
size.width
;
2825 sr.
size.height
= thickness
;
2826 sr.origin.y
+= r.
size.height
- thickness
;
2827 if (bottom_p
) NSRectFill
(sr
);
2830 sr.
size.height
= r.
size.height
;
2831 sr.origin.y
= r.origin.y
;
2832 sr.
size.width
= thickness
;
2833 sr.origin.x
+= r.
size.width
- thickness
;
2834 if (right_p
) NSRectFill
(sr
);
2839 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2840 /* --------------------------------------------------------------------------
2841 Function modeled after x_draw_glyph_string_box ().
2842 Sets up parameters for drawing.
2843 -------------------------------------------------------------------------- */
2845 int right_x
, last_x
;
2846 char left_p
, right_p
;
2847 struct glyph
*last_glyph
;
2852 if (s
->hl
== DRAW_MOUSE_FACE
)
2854 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2856 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2861 thickness
= face
->box_line_width
;
2863 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2865 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2866 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2867 : window_box_right
(s
->w
, s
->area
));
2868 last_glyph
= (s
->cmp || s
->img
2869 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2871 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2872 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2874 left_p
= (s
->first_glyph
->left_box_line_p
2875 ||
(s
->hl
== DRAW_MOUSE_FACE
2876 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2877 right_p
= (last_glyph
->right_box_line_p
2878 ||
(s
->hl
== DRAW_MOUSE_FACE
2879 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2881 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2883 /* expand full-width row over internal borders */
2884 if (s
->row
->full_width_p
)
2885 r
= ns_fix_rect_ibw
(r
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2886 FRAME_PIXEL_WIDTH
(s
->f
));
2888 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2889 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2891 ns_draw_box
(r
, abs (thickness
),
2892 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2897 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2898 1, 1, left_p
, right_p
, s
);
2904 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2905 /* --------------------------------------------------------------------------
2906 Modeled after x_draw_glyph_string_background, which draws BG in
2907 certain cases. Others are left to the text rendering routine.
2908 -------------------------------------------------------------------------- */
2910 NSTRACE
(ns_maybe_dumpglyphs_background
);
2912 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2914 int box_line_width
= max (s
->face
->box_line_width
, 0);
2915 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2916 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2919 if (s
->hl
== DRAW_MOUSE_FACE
)
2921 face
= FACE_FROM_ID
(s
->f
,
2922 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2924 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2927 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2929 [(NS_FACE_BACKGROUND
(face
) != 0
2930 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2931 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2934 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2935 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2938 if (s
->hl
!= DRAW_CURSOR
)
2940 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2941 s
->background_width
,
2942 s
->height
-2*box_line_width
);
2944 /* expand full-width row over internal borders */
2945 if (s
->row
->full_width_p
)
2947 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
2948 if (r.origin.y
<= fibw
+1 + box_line_width
)
2950 r.
size.height
+= r.origin.y
;
2953 if (r.origin.x
<= fibw
+1)
2955 r.
size.width
+= 2*r.origin.x
;
2958 if (FRAME_PIXEL_WIDTH
(s
->f
) - (r.origin.x
+ r.
size.width
)
2960 r.
size.width
+= fibw
;
2966 s
->background_filled_p
= 1;
2973 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2974 /* --------------------------------------------------------------------------
2975 Renders an image and associated borders.
2976 -------------------------------------------------------------------------- */
2978 EmacsImage
*img
= s
->img
->pixmap
;
2979 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2980 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2981 int bg_x
, bg_y
, bg_height
;
2988 NSTRACE
(ns_dumpglyphs_image
);
2990 if (s
->face
->box
!= FACE_NO_BOX
2991 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
2992 x
+= abs (s
->face
->box_line_width
);
2995 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
2996 bg_height
= s
->height
;
2997 /* other terms have this, but was causing problems w/tabbar mode */
2998 /* - 2 * box_line_vwidth; */
3000 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
3001 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
3003 /* Draw BG: if we need larger area than image itself cleared, do that,
3004 otherwise, since we composite the image under NS (instead of mucking
3005 with its background color), we must clear just the image area. */
3006 if (s
->hl
== DRAW_MOUSE_FACE
)
3008 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3010 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3013 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3015 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
3017 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
3018 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
3020 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
3021 s
->background_filled_p
= 1;
3025 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3028 /* expand full-width row over internal borders */
3029 if (s
->row
->full_width_p
)
3031 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
3032 if (br.origin.y
<= fibw
+1 + box_line_vwidth
)
3034 br.
size.height
+= br.origin.y
;
3037 if (br.origin.x
<= fibw
+1 + box_line_vwidth
)
3039 br.
size.width
+= br.origin.x
;
3042 if (FRAME_PIXEL_WIDTH
(s
->f
) - (br.origin.x
+ br.
size.width
) <= fibw
+1)
3043 br.
size.width
+= fibw
;
3048 /* Draw the image.. do we need to draw placeholder if img ==nil? */
3050 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
3051 operation
: NSCompositeSourceOver
];
3053 if (s
->hl
== DRAW_CURSOR
)
3055 [FRAME_CURSOR_COLOR
(s
->f
) set];
3056 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3057 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3059 /* Currently on NS img->mask is always 0. Since
3060 get_window_cursor_type specifies a hollow box cursor when on
3061 a non-masked image we never reach this clause. But we put it
3062 in in anticipation of better support for image masks on
3064 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3068 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3071 /* Draw underline, overline, strike-through. */
3072 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3074 /* Draw relief, if requested */
3075 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3077 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3079 th
= tool_bar_button_relief
>= 0 ?
3080 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3081 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3085 th
= abs (s
->img
->relief
);
3086 raised_p
= (s
->img
->relief
> 0);
3089 r.origin.x
= x
- th
;
3090 r.origin.y
= y
- th
;
3091 r.
size.width
= s
->slice.width
+ 2*th
-1;
3092 r.
size.height
= s
->slice.height
+ 2*th
-1;
3093 ns_draw_relief
(r
, th
, raised_p
,
3095 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3097 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3100 /* If there is no mask, the background won't be seen,
3101 so draw a rectangle on the image for the cursor.
3102 Do this for all images, getting transparency right is not reliable. */
3103 if (s
->hl
== DRAW_CURSOR
)
3105 int thickness
= abs (s
->img
->relief
);
3106 if (thickness
== 0) thickness
= 1;
3107 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3113 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3118 NSColor
*fgCol
, *bgCol
;
3120 if (!s
->background_filled_p
)
3122 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3123 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3125 ns_focus
(s
->f
, r
, n
);
3127 if (s
->hl
== DRAW_MOUSE_FACE
)
3129 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3131 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3134 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3136 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3137 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3141 if (!s
->row
->full_width_p
)
3143 int overrun
, leftoverrun
;
3145 /* truncate to avoid overwriting fringe and/or scrollbar */
3146 overrun
= max (0, (s
->x
+ s
->background_width
)
3147 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3148 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3149 r
[i
].
size.width
-= overrun
;
3151 /* truncate to avoid overwriting to left of the window box */
3152 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3153 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3155 if (leftoverrun
> 0)
3157 r
[i
].origin.x
+= leftoverrun
;
3158 r
[i
].
size.width
-= leftoverrun
;
3161 /* XXX: Try to work between problem where a stretch glyph on
3162 a partially-visible bottom row will clear part of the
3163 modeline, and another where list-buffers headers and similar
3164 rows erroneously have visible_height set to 0. Not sure
3165 where this is coming from as other terms seem not to show. */
3166 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3169 /* expand full-width rows over internal borders */
3172 r
[i
] = ns_fix_rect_ibw
(r
[i
], FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
3173 FRAME_PIXEL_WIDTH
(s
->f
));
3178 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3179 overwriting cursor (usually when cursor on a tab) */
3180 if (s
->hl
== DRAW_CURSOR
)
3185 width
= s
->w
->phys_cursor_width
;
3186 r
[i
].
size.width
-= width
;
3187 r
[i
].origin.x
+= width
;
3191 /* Draw overlining, etc. on the cursor. */
3192 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3193 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3195 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3202 /* Draw overlining, etc. on the stretch glyph (or the part
3203 of the stretch glyph after the cursor). */
3204 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3208 s
->background_filled_p
= 1;
3214 ns_draw_glyph_string
(struct glyph_string
*s
)
3215 /* --------------------------------------------------------------------------
3216 External (RIF): Main draw-text call.
3217 -------------------------------------------------------------------------- */
3219 /* TODO (optimize): focus for box and contents draw */
3222 char box_drawn_p
= 0;
3224 NSTRACE
(ns_draw_glyph_string
);
3226 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3229 struct glyph_string
*next
;
3231 for (width
= 0, next
= s
->next
;
3232 next
&& width
< s
->right_overhang
;
3233 width
+= next
->width
, next
= next
->next
)
3234 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3236 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3238 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3239 ns_focus
(s
->f
, r
, n
);
3240 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3245 ns_dumpglyphs_stretch
(s
->next
);
3247 next
->num_clips
= 0;
3251 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3252 && (s
->first_glyph
->type == CHAR_GLYPH
3253 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3255 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3256 ns_focus
(s
->f
, r
, n
);
3257 ns_maybe_dumpglyphs_background
(s
, 1);
3258 ns_dumpglyphs_box_or_relief
(s
);
3263 switch (s
->first_glyph
->type)
3267 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3268 ns_focus
(s
->f
, r
, n
);
3269 ns_dumpglyphs_image
(s
, r
[0]);
3274 ns_dumpglyphs_stretch
(s
);
3278 case COMPOSITE_GLYPH
:
3279 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3280 ns_focus
(s
->f
, r
, n
);
3282 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3283 && ! s
->first_glyph
->u.cmp.automatic
))
3284 s
->background_filled_p
= 1;
3286 ns_maybe_dumpglyphs_background
3287 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3289 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3290 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3291 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3292 NS_DUMPGLYPH_NORMAL
));
3293 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3294 if (ns_tmp_font
== NULL)
3295 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3297 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3299 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3300 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3301 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3304 ns_tmp_font
->font.driver
->draw
3305 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3306 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3307 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
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
;
3319 case GLYPHLESS_GLYPH
:
3320 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3321 ns_focus
(s
->f
, r
, n
);
3323 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3324 && ! s
->first_glyph
->u.cmp.automatic
))
3325 s
->background_filled_p
= 1;
3327 ns_maybe_dumpglyphs_background
3328 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3330 /* Not yet implemented. */
3339 /* Draw box if not done already. */
3340 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3342 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3343 ns_focus
(s
->f
, r
, n
);
3344 ns_dumpglyphs_box_or_relief
(s
);
3353 /* ==========================================================================
3357 ========================================================================== */
3361 ns_send_appdefined
(int value
)
3362 /* --------------------------------------------------------------------------
3363 Internal: post an appdefined event which EmacsApp-sendEvent will
3364 recognize and take as a command to halt the event loop.
3365 -------------------------------------------------------------------------- */
3367 /*NSTRACE (ns_send_appdefined); */
3369 /* Only post this event if we haven't already posted one. This will end
3370 the [NXApp run] main loop after having processed all events queued at
3372 if (send_appdefined
)
3376 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3377 send_appdefined
= NO
;
3379 /* Don't need wakeup timer any more */
3382 [timed_entry invalidate
];
3383 [timed_entry release
];
3387 /* Ditto for file descriptor poller */
3390 [fd_entry invalidate
];
3395 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3396 location
: NSMakePoint
(0, 0)
3399 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3400 context
: [NSApp context
]
3405 /* Post an application defined event on the event queue. When this is
3406 received the [NXApp run] will return, thus having processed all
3407 events which are currently queued. */
3408 [NSApp postEvent
: nxev atStart
: NO
];
3414 ns_read_socket
(struct terminal *terminal, int expected
,
3415 struct input_event
*hold_quit
)
3416 /* --------------------------------------------------------------------------
3417 External (hook): Post an event to ourself and keep reading events until
3418 we read it back again. In effect process all events which were waiting.
3419 From 21+ we have to manage the event buffer ourselves.
3420 -------------------------------------------------------------------------- */
3422 struct input_event ev
;
3425 /* NSTRACE (ns_read_socket); */
3427 if (interrupt_input_blocked
)
3429 interrupt_input_pending
= 1;
3431 pending_signals
= 1;
3436 interrupt_input_pending
= 0;
3438 pending_signals
= pending_atimers
;
3442 n_emacs_events_pending
= 0;
3445 q_event_ptr
= hold_quit
;
3447 /* we manage autorelease pools by allocate/reallocate each time around
3448 the loop; strict nesting is occasionally violated but seems not to
3449 matter.. earlier methods using full nesting caused major memory leaks */
3450 [outerpool release
];
3451 outerpool
= [[NSAutoreleasePool alloc
] init
];
3453 /* If have pending open-file requests, attend to the next one of those. */
3454 if (ns_pending_files
&& [ns_pending_files count
] != 0
3455 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3457 [ns_pending_files removeObjectAtIndex
: 0];
3459 /* Deal with pending service requests. */
3460 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3462 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3463 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3465 [ns_pending_service_names removeObjectAtIndex
: 0];
3466 [ns_pending_service_args removeObjectAtIndex
: 0];
3470 /* Run and wait for events. We must always send one NX_APPDEFINED event
3471 to ourself, otherwise [NXApp run] will never exit. */
3472 send_appdefined
= YES
;
3474 /* If called via ns_select, this is called once with expected=1,
3475 because we expect either the timeout or file descriptor activity.
3476 In this case the first event through will either be real input or
3477 one of these. read_avail_input() then calls once more with expected=0
3478 and in that case we need to return quickly if there is nothing.
3479 If we're being called outside of that, it's also OK to return quickly
3480 after one iteration through the event loop, since other terms do
3481 this and emacs expects it. */
3482 if (!(inNsSelect
&& expected
))
3484 /* Post an application defined event on the event queue. When this is
3485 received the [NXApp run] will return, thus having processed all
3486 events which are currently queued, if any. */
3487 ns_send_appdefined
(-1);
3493 nevents
= n_emacs_events_pending
;
3494 n_emacs_events_pending
= 0;
3495 emacs_event
= q_event_ptr
= NULL;
3503 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3504 fd_set
*exceptfds
, EMACS_TIME
*timeout
, sigset_t
*sigmask
)
3505 /* --------------------------------------------------------------------------
3506 Replacement for select, checking for events
3507 -------------------------------------------------------------------------- */
3512 struct timespec select_timeout
;
3514 /* NSTRACE (ns_select); */
3516 if (NSApp
== nil || inNsSelect
== 1 /* || ([NSApp isActive] == NO &&
3517 [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil
3518 inMode:NSDefaultRunLoopMode dequeue:NO] == nil) */)
3519 return pselect
(nfds
, readfds
, writefds
, exceptfds
, timeout
, sigmask
);
3521 /* Save file descriptor set, which gets overwritten in calls to select ()
3522 Note, this is called from process.c, and only readfds is ever set */
3525 memcpy
(&select_readfds
, readfds
, sizeof
(fd_set
));
3531 /* Try an initial select for pending data on input files */
3532 select_timeout.tv_sec
= select_timeout.tv_nsec
= 0;
3533 result
= pselect
(nfds
, readfds
, writefds
, exceptfds
,
3534 &select_timeout
, sigmask
);
3538 /* if (!timeout || timed_entry || fd_entry)
3539 fprintf (stderr, "assertion failed: timeout null or timed_entry/fd_entry non-null in ns_select\n"); */
3541 /* set a timeout and run the main AppKit event loop while continuing
3542 to monitor the files */
3543 time
= EMACS_TIME_TO_DOUBLE
(*timeout
);
3544 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3546 selector
: @selector
(timeout_handler
:)
3548 repeats
: YES
] /* for safe removal */
3551 /* set a periodic task to try the pselect () again */
3552 fd_entry
= [[NSTimer scheduledTimerWithTimeInterval
: 0.1
3554 selector
: @selector
(fd_handler
:)
3559 /* Let Application dispatch events until it receives an event of the type
3560 NX_APPDEFINED, which should only be sent by timeout_handler.
3561 We tell read_avail_input() that input is "expected" because we do expect
3562 either the timeout or fd handler to fire, and if they don't, the original
3563 call from process.c that got us here expects us to wait until some input
3567 ev
= last_appdefined_event
;
3573 if ([ev
type] != NSApplicationDefined
)
3577 last_appdefined_event
= 0;
3581 /* The NX_APPDEFINED event we received was a timeout. */
3586 /* The NX_APPDEFINED event we received was the result of
3587 at least one real input event arriving. */
3593 /* Received back from pselect () in fd_handler; copy the results */
3595 memcpy
(readfds
, &select_readfds
, sizeof
(fd_set
));
3599 /* never reached, shut compiler up */
3605 /* ==========================================================================
3609 ========================================================================== */
3613 ns_set_vertical_scroll_bar
(struct window
*window
,
3614 int portion
, int whole
, int position
)
3615 /* --------------------------------------------------------------------------
3616 External (hook): Update or add scrollbar
3617 -------------------------------------------------------------------------- */
3621 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3622 EmacsView
*view = FRAME_NS_VIEW
(f
);
3623 int window_y
, window_height
;
3624 BOOL barOnVeryLeft
, barOnVeryRight
;
3625 int top
, left
, height
, width
, sb_width
, sb_left
;
3627 static int count
= 0;
3629 /* optimization; display engine sends WAY too many of these.. */
3630 if (!NILP
(window
->vertical_scroll_bar
))
3632 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3633 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3635 if (view->scrollbarsNeedingUpdate
== 0)
3637 if (!windows_or_buffers_changed
)
3641 view->scrollbarsNeedingUpdate
--;
3645 NSTRACE
(ns_set_vertical_scroll_bar
);
3647 /* Get dimensions. */
3648 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3650 height
= window_height
;
3651 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3652 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3654 if (top
< 5) /* top scrollbar adjustment */
3656 top
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3657 height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3660 /* allow for displaying a skinnier scrollbar than char area allotted */
3661 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3662 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3664 barOnVeryLeft
= left
< 5;
3665 barOnVeryRight
= FRAME_PIXEL_WIDTH
(f
) - left
- width
< 5;
3666 sb_left
= left
+ FRAME_INTERNAL_BORDER_WIDTH
(f
)
3667 * (barOnVeryLeft ?
-1 : (barOnVeryRight ?
1 : 0));
3669 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3670 /* the parent view is flipped, so we need to flip y value */
3672 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3674 XSETWINDOW
(win
, window
);
3677 /* we want at least 5 lines to display a scrollbar */
3678 if (WINDOW_TOTAL_LINES
(window
) < 5)
3680 if (!NILP
(window
->vertical_scroll_bar
))
3682 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3683 [bar removeFromSuperview
];
3684 window
->vertical_scroll_bar
= Qnil
;
3686 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3691 if (NILP
(window
->vertical_scroll_bar
))
3693 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3694 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3695 window
->vertical_scroll_bar
= make_save_value
(bar, 0);
3700 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3701 oldRect
= [bar frame
];
3702 r.
size.width
= oldRect.
size.width
;
3703 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3705 if (oldRect.origin.x
!= r.origin.x
)
3706 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3711 [bar setPosition
: position portion
: portion whole
: whole
];
3717 ns_condemn_scroll_bars
(struct frame
*f
)
3718 /* --------------------------------------------------------------------------
3719 External (hook): arrange for all frame's scrollbars to be removed
3720 at next call to judge_scroll_bars, except for those redeemed.
3721 -------------------------------------------------------------------------- */
3725 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3727 NSTRACE
(ns_condemn_scroll_bars
);
3729 for (i
=[subviews count
]-1; i
>= 0; i
--)
3731 view = [subviews objectAtIndex
: i
];
3732 if ([view isKindOfClass
: [EmacsScroller
class]])
3739 ns_redeem_scroll_bar
(struct window
*window
)
3740 /* --------------------------------------------------------------------------
3741 External (hook): arrange to spare this window's scrollbar
3742 at next call to judge_scroll_bars.
3743 -------------------------------------------------------------------------- */
3746 NSTRACE
(ns_redeem_scroll_bar
);
3747 if (!NILP
(window
->vertical_scroll_bar
))
3749 bar =XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3756 ns_judge_scroll_bars
(struct frame
*f
)
3757 /* --------------------------------------------------------------------------
3758 External (hook): destroy all scrollbars on frame that weren't
3759 redeemed after call to condemn_scroll_bars.
3760 -------------------------------------------------------------------------- */
3764 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3765 NSTRACE
(ns_judge_scroll_bars
);
3766 for (i
=[subviews count
]-1; i
>= 0; i
--)
3768 view = [subviews objectAtIndex
: i
];
3769 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3776 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3778 /* XXX irrelevant under NS */
3783 /* ==========================================================================
3787 ========================================================================== */
3790 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3792 NSScreen
*screen
= [NSScreen mainScreen
];
3793 return [screen frame
].
size.height
;
3797 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3799 NSScreen
*screen
= [NSScreen mainScreen
];
3800 return [screen frame
].
size.width
;
3804 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3805 /* --------------------------------------------------------------------------
3806 Convert modifier name to lisp symbol
3807 -------------------------------------------------------------------------- */
3809 if (!strncmp
(SDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3811 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3813 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3815 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3817 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3819 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3826 static Lisp_Object ns_mod_to_lisp
(int m
)
3827 /* --------------------------------------------------------------------------
3828 Convert modifier code (see lisp.h) to lisp symbol
3829 -------------------------------------------------------------------------- */
3833 else if (m
== CHAR_SUPER
)
3835 else if (m
== CHAR_CTL
)
3837 else if (m
== CHAR_ALT
)
3839 else if (m
== CHAR_HYPER
)
3841 else /* if (m == 0) */
3847 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3848 Lisp_Object yesval
, Lisp_Object noval
,
3849 BOOL is_float
, BOOL is_modstring
)
3850 /* --------------------------------------------------------------------------
3851 Check a parameter value in user's preferences
3852 -------------------------------------------------------------------------- */
3854 const
char *value
= ns_get_defaults_value
(parameter
);
3860 if (strcasecmp
(value
, "YES"
) == 0)
3862 else if (strcasecmp
(value
, "NO"
) == 0)
3864 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3865 *result
= make_float
(f
);
3866 else if (is_modstring
&& value
)
3867 *result
= ns_string_to_lispmod
(value
);
3868 else fprintf (stderr
,
3869 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3875 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3876 /* --------------------------------------------------------------------------
3877 Initialize global info and storage for display.
3878 -------------------------------------------------------------------------- */
3880 NSScreen
*screen
= [NSScreen mainScreen
];
3881 NSWindowDepth depth
= [screen depth
];
3882 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
3884 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3885 dpyinfo
->resy
= 72.27;
3886 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3887 NSColorSpaceFromDepth
(depth
)]
3888 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3889 NSColorSpaceFromDepth
(depth
)];
3890 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3891 dpyinfo
->image_cache
= make_image_cache
();
3892 dpyinfo
->color_table
3893 = (struct ns_color_table
*)xmalloc
(sizeof
(struct ns_color_table
));
3894 dpyinfo
->color_table
->colors
= NULL;
3895 dpyinfo
->root_window
= 42; /* a placeholder.. */
3897 hlinfo
->mouse_face_mouse_frame
= NULL;
3898 hlinfo
->mouse_face_deferred_gc
= 0;
3899 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
3900 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
3901 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3902 hlinfo
->mouse_face_window
= hlinfo
->mouse_face_overlay
= Qnil
;
3903 hlinfo
->mouse_face_hidden
= 0;
3905 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
3906 hlinfo
->mouse_face_defer
= 0;
3908 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3910 dpyinfo
->n_fonts
= 0;
3911 dpyinfo
->smallest_font_height
= 1;
3912 dpyinfo
->smallest_char_width
= 1;
3916 /* This and next define (many of the) public functions in this file. */
3917 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3918 with using despite presence in the "system dependent" redisplay
3919 interface. In addition, many of the ns_ methods have code that is
3920 shared with all terms, indicating need for further refactoring. */
3921 extern frame_parm_handler ns_frame_parm_handlers
[];
3922 static
struct redisplay_interface ns_redisplay_interface
=
3924 ns_frame_parm_handlers
,
3928 x_clear_end_of_line
,
3930 ns_after_update_window_line
,
3931 ns_update_window_begin
,
3932 ns_update_window_end
,
3935 0, /* flush_display_optional */
3936 x_clear_window_mouse_face
,
3937 x_get_glyph_overhangs
,
3938 x_fix_overlapping_area
,
3939 ns_draw_fringe_bitmap
,
3940 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3941 0, /* destroy_fringe_bitmap */
3942 ns_compute_glyph_string_overhangs
,
3943 ns_draw_glyph_string
, /* interface to nsfont.m */
3944 ns_define_frame_cursor
,
3945 ns_clear_frame_area
,
3946 ns_draw_window_cursor
,
3947 ns_draw_vertical_window_border
,
3948 ns_shift_glyphs_for_insert
3953 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3959 /* This function is called when the last frame on a display is deleted. */
3961 ns_delete_terminal
(struct terminal *terminal)
3963 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3966 /* Protect against recursive calls. delete_frame in
3967 delete_terminal calls us back when it deletes our last frame. */
3968 if (!terminal->name
)
3973 x_destroy_all_bitmaps
(dpyinfo
);
3974 ns_delete_display
(dpyinfo
);
3979 static
struct terminal *
3980 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3981 /* --------------------------------------------------------------------------
3982 Set up use of NS before we make the first connection.
3983 -------------------------------------------------------------------------- */
3985 struct terminal *terminal;
3987 NSTRACE
(ns_create_terminal
);
3989 terminal = create_terminal
();
3991 terminal->type = output_ns
;
3992 terminal->display_info.ns
= dpyinfo
;
3993 dpyinfo
->terminal = terminal;
3995 terminal->rif
= &ns_redisplay_interface
;
3997 terminal->clear_frame_hook
= ns_clear_frame
;
3998 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
3999 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
4000 terminal->ring_bell_hook
= ns_ring_bell
;
4001 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
4002 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
4003 terminal->update_begin_hook
= ns_update_begin
;
4004 terminal->update_end_hook
= ns_update_end
;
4005 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
4006 terminal->read_socket_hook
= ns_read_socket
;
4007 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
4008 terminal->mouse_position_hook
= ns_mouse_position
;
4009 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
4010 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
4012 terminal->fullscreen_hook
= 0; /* see XTfullscreen_hook */
4014 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
4015 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
4016 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
4017 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
4019 terminal->delete_frame_hook
= x_destroy_window
;
4020 terminal->delete_terminal_hook
= ns_delete_terminal
;
4022 terminal->scroll_region_ok
= 1;
4023 terminal->char_ins_del_ok
= 1;
4024 terminal->line_ins_del_ok
= 1;
4025 terminal->fast_clear_end_of_line
= 1;
4026 terminal->memory_below_frame
= 0;
4032 struct ns_display_info
*
4033 ns_term_init
(Lisp_Object display_name
)
4034 /* --------------------------------------------------------------------------
4035 Start the Application and get things rolling.
4036 -------------------------------------------------------------------------- */
4038 struct terminal *terminal;
4039 struct ns_display_info
*dpyinfo
;
4040 static int ns_initialized
= 0;
4043 NSTRACE
(ns_term_init
);
4045 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
4046 /*GSDebugAllocationActive (YES); */
4048 handling_signal
= 0;
4050 if (!ns_initialized
)
4053 Fset_input_interrupt_mode
(Qnil
);
4057 ns_pending_files
= [[NSMutableArray alloc
] init
];
4058 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
4059 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
4061 /* Start app and create the main menu, window, view.
4062 Needs to be here because ns_initialize_display_info () uses AppKit classes.
4063 The view will then ask the NSApp to stop and return to Emacs. */
4064 [EmacsApp sharedApplication
];
4067 [NSApp setDelegate
: NSApp
];
4069 /* debugging: log all notifications */
4070 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4071 selector: @selector (logNotification:)
4072 name: nil object: nil]; */
4074 dpyinfo
= (struct ns_display_info
*)xmalloc
(sizeof
(struct ns_display_info
));
4075 memset
(dpyinfo
, 0, sizeof
(struct ns_display_info
));
4077 ns_initialize_display_info
(dpyinfo
);
4078 terminal = ns_create_terminal
(dpyinfo
);
4080 terminal->kboard
= (KBOARD
*) xmalloc
(sizeof
(KBOARD
));
4081 init_kboard
(terminal->kboard
);
4082 KVAR
(terminal->kboard
, Vwindow_system
) = Qns
;
4083 terminal->kboard
->next_kboard
= all_kboards
;
4084 all_kboards
= terminal->kboard
;
4085 /* Don't let the initial kboard remain current longer than necessary.
4086 That would cause problems if a file loaded on startup tries to
4087 prompt in the mini-buffer. */
4088 if (current_kboard
== initial_kboard
)
4089 current_kboard
= terminal->kboard
;
4090 terminal->kboard
->reference_count
++;
4092 dpyinfo
->next
= x_display_list
;
4093 x_display_list
= dpyinfo
;
4095 /* Put it on ns_display_name_list */
4096 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
4097 ns_display_name_list
);
4098 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
4100 /* Set the name of the terminal. */
4101 terminal->name
= (char *) xmalloc
(SBYTES
(display_name
) + 1);
4102 strncpy
(terminal->name
, SDATA
(display_name
), SBYTES
(display_name
));
4103 terminal->name
[SBYTES
(display_name
)] = 0;
4107 if (!inhibit_x_resources
)
4109 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4112 /* this is a standard variable */
4113 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4114 make_float
(10.0), make_float
(6.0), YES
, NO
);
4115 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4118 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
4119 stringForKey
: @"AppleHighlightColor"
];
4120 if (ns_selection_color
== nil
)
4121 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
4124 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4128 Lisp_Object color_file
, color_map
, color
;
4133 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4134 Fsymbol_value
(intern
("data
-directory"
)));
4135 if (NILP
(Ffile_readable_p
(color_file
)))
4136 fatal
("Could not
find %s.\n", SDATA (color_file));
4138 color_map
= Fx_load_color_file
(color_file
);
4139 if (NILP
(color_map
))
4140 fatal
("Could not read
%s.\n", SDATA (color_file));
4142 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4143 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4145 color
= XCAR
(color_map
);
4146 name
= SDATA
(XCAR
(color
));
4147 c
= XINT
(XCDR
(color
));
4149 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4150 green
: GREEN_FROM_ULONG
(c
) / 255.0
4151 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4153 forKey
: [NSString stringWithUTF8String
: name
]];
4155 [cl writeToFile
: nil
];
4161 #ifdef NS_IMPL_GNUSTEP
4162 strncpy
(c
, gnustep_base_version
, sizeof
(c
));
4164 /*PSnextrelease (128, c); */
4165 snprintf
(c
, sizeof
(c
), "
%g", NSAppKitVersionNumber);
4167 Vwindow_system_version
= build_string
(c
);
4170 delete_keyboard_wait_descriptor
(0);
4172 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4174 /* Set up OS X app menu */
4175 #ifdef NS_IMPL_COCOA
4179 /* set up the application menu */
4180 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4181 [svcsMenu setAutoenablesItems
: NO
];
4182 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4183 [appMenu setAutoenablesItems
: NO
];
4184 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4185 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4187 [appMenu insertItemWithTitle
: @"About Emacs"
4188 action
: @selector
(orderFrontStandardAboutPanel
:)
4191 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4192 [appMenu insertItemWithTitle
: @"Preferences..."
4193 action
: @selector
(showPreferencesWindow
:)
4196 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4197 item
= [appMenu insertItemWithTitle
: @"Services"
4198 action
: @selector
(menuDown
:)
4201 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4202 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4203 [appMenu insertItemWithTitle
: @"Hide Emacs"
4204 action
: @selector
(hide
:)
4207 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4208 action
: @selector
(hideOtherApplications
:)
4211 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4212 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4213 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4214 action
: @selector
(terminate
:)
4218 item
= [mainMenu insertItemWithTitle
: ns_app_name
4219 action
: @selector
(menuDown
:)
4222 [mainMenu setSubmenu
: appMenu forItem
: item
];
4223 [dockMenu insertItemWithTitle
: @"New Frame"
4224 action
: @selector
(newFrame
:)
4228 [NSApp setMainMenu
: mainMenu
];
4229 [NSApp setAppleMenu
: appMenu
];
4230 [NSApp setServicesMenu
: svcsMenu
];
4231 /* Needed at least on Cocoa, to get dock menu to show windows */
4232 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4234 [[NSNotificationCenter defaultCenter
]
4235 addObserver
: mainMenu
4236 selector
: @selector
(trackingNotification
:)
4237 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4238 [[NSNotificationCenter defaultCenter
]
4239 addObserver
: mainMenu
4240 selector
: @selector
(trackingNotification
:)
4241 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4243 #endif
/* MAC OS X menu setup */
4252 ns_term_shutdown
(int sig
)
4254 [[NSUserDefaults standardUserDefaults
] synchronize
];
4256 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4257 if (STRINGP
(Vauto_save_list_file_name
))
4258 unlink
(SDATA
(Vauto_save_list_file_name
));
4260 if (sig
== 0 || sig
== SIGTERM
)
4262 [NSApp terminate
: NSApp
];
4264 else // force a stack
trace to happen
4271 /* ==========================================================================
4273 EmacsApp implementation
4275 ========================================================================== */
4278 @implementation EmacsApp
4280 - (void
)logNotification
: (NSNotification
*)notification
4282 const
char *name
= [[notification name
] UTF8String
];
4283 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4284 && !strstr
(name
, "WindowNumber"
))
4285 NSLog
(@"notification
: '%@'"
, [notification name
]);
4289 - (void
)sendEvent
: (NSEvent
*)theEvent
4290 /* --------------------------------------------------------------------------
4291 Called when NSApp is running for each event received. Used to stop
4292 the loop when we choose, since there's no way to just run one iteration.
4293 -------------------------------------------------------------------------- */
4295 int
type = [theEvent
type];
4296 NSWindow
*window
= [theEvent window
];
4297 /* NSTRACE (sendEvent); */
4298 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4300 #ifdef NS_IMPL_COCOA
4301 if (type == NSApplicationDefined
4302 && [theEvent data2
] == NSAPP_DATA2_RUNASSCRIPT
)
4310 if (type == NSCursorUpdate
&& window
== nil
)
4312 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4316 #ifdef NS_IMPL_COCOA
4317 /* pass mouse down in resize handle and subsequent drags directly to
4318 EmacsWindow so we can generate continuous redisplays */
4321 if (type == NSLeftMouseDragged
)
4323 [window mouseDragged
: theEvent
];
4326 else if (type == NSLeftMouseUp
)
4328 [window mouseUp
: theEvent
];
4332 else if (type == NSLeftMouseDown
)
4334 NSRect r
= ns_resize_handle_rect
(window
);
4335 if (NSPointInRect
([theEvent locationInWindow
], r
))
4338 [window mouseDown
: theEvent
];
4344 if (type == NSApplicationDefined
)
4346 /* Events posted by ns_send_appdefined interrupt the run loop here.
4347 But, if a modal window is up, an appdefined can still come through,
4348 (e.g., from a makeKeyWindow event) but stopping self also stops the
4349 modal loop. Just defer it until later. */
4350 if ([NSApp modalWindow
] == nil
)
4352 last_appdefined_event
= theEvent
;
4357 send_appdefined
= YES
;
4361 [super sendEvent
: theEvent
];
4365 - (void
)showPreferencesWindow
: (id
)sender
4367 struct frame
*emacsframe
= SELECTED_FRAME
();
4368 NSEvent
*theEvent
= [NSApp currentEvent
];
4372 emacs_event
->kind
= NS_NONKEY_EVENT
;
4373 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4374 emacs_event
->modifiers
= 0;
4375 EV_TRAILER
(theEvent
);
4379 - (void
)newFrame
: (id
)sender
4381 struct frame
*emacsframe
= SELECTED_FRAME
();
4382 NSEvent
*theEvent
= [NSApp currentEvent
];
4386 emacs_event
->kind
= NS_NONKEY_EVENT
;
4387 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4388 emacs_event
->modifiers
= 0;
4389 EV_TRAILER
(theEvent
);
4393 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4394 - (BOOL
) openFile
: (NSString
*)fileName
4396 struct frame
*emacsframe
= SELECTED_FRAME
();
4397 NSEvent
*theEvent
= [NSApp currentEvent
];
4402 emacs_event
->kind
= NS_NONKEY_EVENT
;
4403 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4404 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4405 ns_input_line
= Qnil
; /* can be start or cons start,end */
4406 emacs_event
->modifiers
=0;
4407 EV_TRAILER
(theEvent
);
4413 /* **************************************************************************
4415 EmacsApp delegate implementation
4417 ************************************************************************** */
4419 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4420 /* --------------------------------------------------------------------------
4421 When application is loaded, terminate event loop in ns_term_init
4422 -------------------------------------------------------------------------- */
4424 NSTRACE
(applicationDidFinishLaunching
);
4425 [NSApp setServicesProvider
: NSApp
];
4426 ns_send_appdefined
(-2);
4430 /* Termination sequences:
4433 MenuBar | File | Exit:
4434 Select Quit from App menubar:
4436 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4439 Select Quit from Dock menu:
4442 Cancel -> Nothing else
4446 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4451 - (void
) terminate
: (id
)sender
4453 struct frame
*emacsframe
= SELECTED_FRAME
();
4458 emacs_event
->kind
= NS_NONKEY_EVENT
;
4459 emacs_event
->code
= KEY_NS_POWER_OFF
;
4460 emacs_event
->arg
= Qt
; /* mark as non-key event */
4461 EV_TRAILER
((id
)nil
);
4465 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4469 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4470 return NSTerminateNow
;
4472 ret
= NSRunAlertPanel
(ns_app_name
,
4473 [NSString stringWithUTF8String
:"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
],
4474 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4476 if (ret
== NSAlertDefaultReturn
)
4477 return NSTerminateNow
;
4478 else if (ret
== NSAlertAlternateReturn
)
4479 return NSTerminateCancel
;
4480 return NSTerminateNow
; /* just in case */
4484 /* Notification from the Workspace to open a file */
4485 - (BOOL
)application
: sender openFile
: (NSString
*)file
4487 [ns_pending_files addObject
: file
];
4492 /* Open a file as a temporary file */
4493 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4495 [ns_pending_files addObject
: file
];
4500 /* Notification from the Workspace to open a file noninteractively (?) */
4501 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4503 [ns_pending_files addObject
: file
];
4508 /* Notification from the Workspace to open multiple files */
4509 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4511 NSEnumerator
*files
= [fileList objectEnumerator
];
4513 while ((file
= [files nextObject
]) != nil
)
4514 [ns_pending_files addObject
: file
];
4516 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4521 /* Handle dock menu requests. */
4522 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4528 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4529 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4531 //ns_app_active
=YES
;
4533 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4535 NSTRACE
(applicationDidBecomeActive
);
4537 //ns_app_active
=YES
;
4539 ns_update_auto_hide_menu_bar
();
4540 // No constraining takes place when the application is not active.
4541 ns_constrain_all_frames
();
4543 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4546 ns_send_appdefined
(-1);
4551 /* ==========================================================================
4553 EmacsApp aux handlers for managing event loop
4555 ========================================================================== */
4558 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4559 /* --------------------------------------------------------------------------
4560 The timeout specified to ns_select has passed.
4561 -------------------------------------------------------------------------- */
4563 /*NSTRACE (timeout_handler); */
4564 ns_send_appdefined
(-2);
4567 - (void
)fd_handler
: (NSTimer
*) fdEntry
4568 /* --------------------------------------------------------------------------
4569 Check data waiting on file descriptors and terminate if so
4570 -------------------------------------------------------------------------- */
4573 struct timespec select_timeout
;
4574 /* NSTRACE (fd_handler); */
4576 if (select_nfds
== 0)
4579 memcpy
(&t_readfds
, &select_readfds
, sizeof
(fd_set
));
4581 select_timeout.tv_sec
= select_timeout.tv_nsec
= 0;
4582 result
= pselect
(select_nfds
, &t_readfds
, NULL, NULL, &select_timeout
, NULL);
4585 memcpy
(&select_readfds
, &t_readfds
, sizeof
(fd_set
));
4586 ns_send_appdefined
(result
);
4592 /* ==========================================================================
4596 ========================================================================== */
4598 /* called from system: queue for next pass through event loop */
4599 - (void
)requestService
: (NSPasteboard
*)pboard
4600 userData
: (NSString
*)userData
4601 error: (NSString
**)error
4603 [ns_pending_service_names addObject
: userData
];
4604 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4605 SDATA
(ns_string_from_pasteboard
(pboard
))]];
4609 /* called from ns_read_socket to clear queue */
4610 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4612 struct frame
*emacsframe
= SELECTED_FRAME
();
4613 NSEvent
*theEvent
= [NSApp currentEvent
];
4618 emacs_event
->kind
= NS_NONKEY_EVENT
;
4619 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4620 ns_input_spi_name
= build_string
([name UTF8String
]);
4621 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4622 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4623 EV_TRAILER
(theEvent
);
4633 /* ==========================================================================
4635 EmacsView implementation
4637 ========================================================================== */
4640 @implementation EmacsView
4642 /* needed to inform when window closed from LISP */
4643 - (void
) setWindowClosing
: (BOOL
)closing
4645 windowClosing
= closing
;
4651 NSTRACE
(EmacsView_dealloc
);
4657 /* called on font panel selection */
4658 - (void
)changeFont
: (id
)sender
4660 NSEvent
*e
=[[self window
] currentEvent
];
4661 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4665 NSTRACE
(changeFont
);
4669 if (newFont
= [sender convertFont
:
4670 ((struct nsfont_info
*)face
->font
)->nsfont
])
4672 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4674 emacs_event
->kind
= NS_NONKEY_EVENT
;
4675 emacs_event
->modifiers
= 0;
4676 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4678 size = [newFont pointSize
];
4679 ns_input_fontsize
= make_number
(lrint
(size));
4680 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4686 - (BOOL
)acceptsFirstResponder
4688 NSTRACE
(acceptsFirstResponder
);
4693 - (void
)resetCursorRects
4695 NSRect visible
= [self visibleRect
];
4696 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4697 NSTRACE
(resetCursorRects
);
4699 if (currentCursor
== nil
)
4700 currentCursor
= [NSCursor arrowCursor
];
4702 if (!NSIsEmptyRect
(visible
))
4703 [self addCursorRect
: visible cursor
: currentCursor
];
4704 [currentCursor setOnMouseEntered
: YES
];
4709 /*****************************************************************************/
4710 /* Keyboard handling. */
4713 - (void
)keyDown
: (NSEvent
*)theEvent
4715 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
4717 unsigned fnKeysym
= 0;
4719 static NSMutableArray
*nsEvArray
;
4720 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4721 static BOOL firstTime
= YES
;
4727 /* Rhapsody and OS X give up and down events for the arrow keys */
4728 if (ns_fake_keydown
== YES
)
4729 ns_fake_keydown
= NO
;
4730 else if ([theEvent
type] != NSKeyDown
)
4736 if (![[self window
] isKeyWindow
]
4737 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4738 /* we must avoid an infinite loop here. */
4739 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4741 /* XXX: There is an occasional condition in which, when Emacs display
4742 updates a different frame from the current one, and temporarily
4743 selects it, then processes some interrupt-driven input
4744 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4745 for some reason that window has its first responder set to the NSView
4746 most recently updated (I guess), which is not the correct one. */
4747 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4751 if (nsEvArray
== nil
)
4752 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4754 [NSCursor setHiddenUntilMouseMoves
: YES
];
4756 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4758 clear_mouse_face
(hlinfo
);
4759 hlinfo
->mouse_face_hidden
= 1;
4762 if (!processingCompose
)
4764 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4765 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4766 /* (Carbon way: [theEvent keyCode]) */
4768 /* is it a "function key"? */
4769 fnKeysym
= ns_convert_key
(code
);
4772 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4773 because Emacs treats Delete and KP-Delete same (in simple.el). */
4774 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4775 code
= 0xFF08; /* backspace */
4780 /* are there modifiers? */
4781 emacs_event
->modifiers
= 0;
4782 flags
= [theEvent modifierFlags
];
4784 if (flags
& NSHelpKeyMask
)
4785 emacs_event
->modifiers |
= hyper_modifier
;
4787 if (flags
& NSShiftKeyMask
)
4788 emacs_event
->modifiers |
= shift_modifier
;
4790 if ((flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
)
4791 emacs_event
->modifiers |
= parse_solitary_modifier
4792 (EQ
(ns_right_command_modifier
, Qleft
)
4793 ? ns_command_modifier
4794 : ns_right_command_modifier
);
4796 if ((flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
)
4798 emacs_event
->modifiers |
= parse_solitary_modifier
4799 (ns_command_modifier
);
4801 /* if super (default), take input manager's word so things like
4802 dvorak / qwerty layout work */
4803 if (EQ
(ns_command_modifier
, Qsuper
)
4805 && [[theEvent characters
] length] != 0)
4807 /* XXX: the code we get will be unshifted, so if we have
4808 a shift modifier, must convert ourselves */
4809 if (!(flags
& NSShiftKeyMask
))
4810 code
= [[theEvent characters
] characterAtIndex
: 0];
4812 /* this is ugly and also requires linking w/Carbon framework
4813 (for LMGetKbdType) so for now leave this rare (?) case
4814 undealt with.. in future look into CGEvent methods */
4817 long smv
= GetScriptManagerVariable
(smKeyScript
);
4818 Handle uchrHandle
= GetResource
4819 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4821 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4822 [[theEvent characters
] characterAtIndex
: 0],
4823 kUCKeyActionDisplay
,
4824 (flags
& ~NSCommandKeyMask
) >> 8,
4825 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4826 &dummy
, 1, &dummy
, &code
);
4833 if ((flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
)
4834 emacs_event
->modifiers |
= parse_solitary_modifier
4835 (EQ
(ns_right_control_modifier
, Qleft
)
4836 ? ns_control_modifier
4837 : ns_right_control_modifier
);
4839 if ((flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
)
4840 emacs_event
->modifiers |
= parse_solitary_modifier
4841 (ns_control_modifier
);
4843 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4844 emacs_event
->modifiers |
=
4845 parse_solitary_modifier
(ns_function_modifier
);
4847 left_is_none
= NILP
(ns_alternate_modifier
)
4848 || EQ
(ns_alternate_modifier
, Qnone
);
4850 if ((flags
& NSRightAlternateKeyMask
) == NSRightAlternateKeyMask
)
4852 if ((NILP
(ns_right_alternate_modifier
)
4853 || EQ
(ns_right_alternate_modifier
, Qnone
)
4854 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
4856 { /* accept pre-interp alt comb */
4857 if ([[theEvent characters
] length] > 0)
4858 code
= [[theEvent characters
] characterAtIndex
: 0];
4859 /*HACK: clear lone shift modifier to stop next if from firing */
4860 if (emacs_event
->modifiers
== shift_modifier
)
4861 emacs_event
->modifiers
= 0;
4864 emacs_event
->modifiers |
= parse_solitary_modifier
4865 (EQ
(ns_right_alternate_modifier
, Qleft
)
4866 ? ns_alternate_modifier
4867 : ns_right_alternate_modifier
);
4870 if ((flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
) /* default = meta */
4872 if (left_is_none
&& !fnKeysym
)
4873 { /* accept pre-interp alt comb */
4874 if ([[theEvent characters
] length] > 0)
4875 code
= [[theEvent characters
] characterAtIndex
: 0];
4876 /*HACK: clear lone shift modifier to stop next if from firing */
4877 if (emacs_event
->modifiers
== shift_modifier
)
4878 emacs_event
->modifiers
= 0;
4881 emacs_event
->modifiers |
=
4882 parse_solitary_modifier
(ns_alternate_modifier
);
4886 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4887 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4889 /* if it was a function key or had modifiers, pass it directly to emacs */
4890 if (fnKeysym ||
(emacs_event
->modifiers
4891 && (emacs_event
->modifiers
!= shift_modifier
)
4892 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4893 /*[[theEvent characters] length] */
4895 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4897 code |
= (1<<28)|
(3<<16);
4898 else if (code
== 0x7f)
4899 code |
= (1<<28)|
(3<<16);
4901 emacs_event
->kind
= code
> 0xFF
4902 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4904 emacs_event
->code
= code
;
4905 EV_TRAILER
(theEvent
);
4911 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4912 /* if we get here we should send the key for input manager processing */
4913 if (firstTime
&& [[NSInputManager currentInputManager
]
4914 wantsToDelayTextChangeNotifications
] == NO
)
4916 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
4919 if (NS_KEYLOG
&& !processingCompose
)
4920 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
4922 processingCompose
= YES
;
4923 [nsEvArray addObject
: theEvent
];
4924 [self interpretKeyEvents
: nsEvArray
];
4925 [nsEvArray removeObject
: theEvent
];
4929 #ifdef NS_IMPL_COCOA
4930 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
4931 decided not to send key-down for.
4932 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
4933 This only applies on Tiger and earlier.
4934 If it matches one of these, send it on to keyDown. */
4935 -(void
)keyUp
: (NSEvent
*)theEvent
4937 int flags
= [theEvent modifierFlags
];
4938 int code
= [theEvent keyCode
];
4939 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
4940 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
4943 fprintf (stderr
, "keyUp
: passed test"
);
4944 ns_fake_keydown
= YES
;
4945 [self keyDown
: theEvent
];
4951 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
4954 /* <NSTextInput>: called when done composing;
4955 NOTE: also called when we delete over working text, followed immed.
4956 by doCommandBySelector: deleteBackward: */
4957 - (void
)insertText
: (id
)aString
4960 int len
= [(NSString
*)aString
length];
4964 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
4965 processingCompose
= NO
;
4970 /* first, clear any working text */
4971 if (workingText
!= nil
)
4972 [self deleteWorkingText
];
4974 /* now insert the string as keystrokes */
4975 for (i
=0; i
<len
; i
++)
4977 code
= [aString characterAtIndex
: i
];
4978 /* TODO: still need this? */
4980 code
= '~'; /* 0x7E */
4981 emacs_event
->modifiers
= 0;
4983 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4984 emacs_event
->code
= code
;
4985 EV_TRAILER
((id
)nil
);
4990 /* <NSTextInput>: inserts display of composing characters */
4991 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
4993 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
4994 [aString string
] : aString
;
4996 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
4997 selRange.
length, selRange.location
);
4999 if (workingText
!= nil
)
5000 [self deleteWorkingText
];
5001 if ([str
length] == 0)
5007 processingCompose
= YES
;
5008 workingText
= [str copy
];
5009 ns_working_text
= build_string
([workingText UTF8String
]);
5011 emacs_event
->kind
= NS_TEXT_EVENT
;
5012 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
5013 EV_TRAILER
((id
)nil
);
5017 /* delete display of composing characters [not in <NSTextInput>] */
5018 - (void
)deleteWorkingText
5020 if (workingText
== nil
)
5023 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
5024 [workingText release
];
5026 processingCompose
= NO
;
5031 emacs_event
->kind
= NS_TEXT_EVENT
;
5032 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5033 EV_TRAILER
((id
)nil
);
5037 - (BOOL
)hasMarkedText
5039 return workingText
!= nil
;
5043 - (NSRange
)markedRange
5045 NSRange rng
= workingText
!= nil
5046 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5048 NSLog
(@"markedRange request"
);
5056 NSLog
(@"unmark
(accept
) text"
);
5057 [self deleteWorkingText
];
5058 processingCompose
= NO
;
5062 /* used to position char selection windows, etc. */
5063 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5067 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5069 NSLog
(@"firstRectForCharRange request"
);
5071 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5072 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5073 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5074 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5075 +FRAME_LINE_HEIGHT
(emacsframe
));
5077 pt
= [self convertPoint
: pt toView
: nil
];
5078 pt
= [[self window
] convertBaseToScreen
: pt
];
5084 - (long)conversationIdentifier
5090 - (void
)doCommandBySelector
: (SEL
)aSelector
5093 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5095 if (aSelector
== @selector
(deleteBackward
:))
5097 /* happens when user backspaces over an ongoing composition:
5098 throw a 'delete' into the event queue */
5101 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5102 emacs_event
->code
= 0xFF08;
5103 EV_TRAILER
((id
)nil
);
5107 - (NSArray
*)validAttributesForMarkedText
5109 static NSArray
*arr
= nil
;
5110 if (arr
== nil
) arr
= [NSArray new
];
5111 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5115 - (NSRange
)selectedRange
5118 NSLog
(@"selectedRange request"
);
5119 return NSMakeRange
(NSNotFound
, 0);
5122 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5125 NSLog
(@"characterIndexForPoint request"
);
5129 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5131 static NSAttributedString
*str
= nil
;
5132 if (str
== nil
) str
= [NSAttributedString new
];
5134 NSLog
(@"attributedSubstringFromRange request"
);
5138 /* End <NSTextInput> impl. */
5139 /*****************************************************************************/
5142 /* This is what happens when the user presses a mouse button. */
5143 - (void
)mouseDown
: (NSEvent
*)theEvent
5145 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5148 NSTRACE
(mouseDown
);
5150 [self deleteWorkingText
];
5155 last_mouse_frame
= emacsframe
;
5156 /* appears to be needed to prevent spurious movement events generated on
5158 last_mouse_frame
->mouse_moved
= 0;
5160 if ([theEvent
type] == NSScrollWheel
)
5162 float delta
= [theEvent deltaY
];
5163 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5166 emacs_event
->kind
= WHEEL_EVENT
;
5167 emacs_event
->code
= 0;
5168 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5169 ((delta
> 0) ? up_modifier
: down_modifier
);
5173 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5174 emacs_event
->code
= EV_BUTTON
(theEvent
);
5175 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5176 | EV_UDMODIFIERS
(theEvent
);
5178 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5179 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5180 EV_TRAILER
(theEvent
);
5184 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5186 NSTRACE
(rightMouseDown
);
5187 [self mouseDown
: theEvent
];
5191 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5193 NSTRACE
(otherMouseDown
);
5194 [self mouseDown
: theEvent
];
5198 - (void
)mouseUp
: (NSEvent
*)theEvent
5201 [self mouseDown
: theEvent
];
5205 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5207 NSTRACE
(rightMouseUp
);
5208 [self mouseDown
: theEvent
];
5212 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5214 NSTRACE
(otherMouseUp
);
5215 [self mouseDown
: theEvent
];
5219 - (void
) scrollWheel
: (NSEvent
*)theEvent
5221 NSTRACE
(scrollWheel
);
5222 [self mouseDown
: theEvent
];
5226 /* Tell emacs the mouse has moved. */
5227 - (void
)mouseMoved
: (NSEvent
*)e
5229 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5232 // NSTRACE
(mouseMoved
);
5234 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5235 last_mouse_motion_position
5236 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5238 /* update any mouse face */
5239 if (hlinfo
->mouse_face_hidden
)
5241 hlinfo
->mouse_face_hidden
= 0;
5242 clear_mouse_face
(hlinfo
);
5245 /* tooltip handling */
5246 previous_help_echo_string
= help_echo_string
;
5247 help_echo_string
= Qnil
;
5249 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
5250 last_mouse_motion_position.y
))
5251 help_echo_string
= previous_help_echo_string
;
5253 XSETFRAME
(frame
, emacsframe
);
5254 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5256 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5257 (note_mouse_highlight), which is called through the
5258 note_mouse_movement () call above */
5259 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5260 help_echo_object
, help_echo_pos
);
5264 help_echo_string
= Qnil
;
5265 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5268 if (emacsframe
->mouse_moved
&& send_appdefined
)
5269 ns_send_appdefined
(-1);
5273 - (void
)mouseDragged
: (NSEvent
*)e
5275 NSTRACE
(mouseDragged
);
5276 [self mouseMoved
: e
];
5280 - (void
)rightMouseDragged
: (NSEvent
*)e
5282 NSTRACE
(rightMouseDragged
);
5283 [self mouseMoved
: e
];
5287 - (void
)otherMouseDragged
: (NSEvent
*)e
5289 NSTRACE
(otherMouseDragged
);
5290 [self mouseMoved
: e
];
5294 - (BOOL
)windowShouldClose
: (id
)sender
5296 NSEvent
*e
=[[self window
] currentEvent
];
5298 NSTRACE
(windowShouldClose
);
5299 windowClosing
= YES
;
5302 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5303 emacs_event
->modifiers
= 0;
5304 emacs_event
->code
= 0;
5306 /* Don't close this window, let this be done from lisp code. */
5311 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5312 /* normalize frame to gridded text size */
5314 NSTRACE
(windowWillResize
);
5315 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5317 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5318 #ifdef NS_IMPL_GNUSTEP
5319 frameSize.width
+ 3);
5323 if (cols
< MINWIDTH
)
5326 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5327 #ifdef NS_IMPL_GNUSTEP
5328 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5329 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5331 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5332 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5334 if (rows
< MINHEIGHT
)
5336 #ifdef NS_IMPL_COCOA
5338 /* this sets window title to have size in it; the wm does this under GS */
5339 NSRect r
= [[self window
] frame
];
5340 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5351 NSWindow
*window
= [self window
];
5354 const
char *t
= [[[self window
] title] UTF8String
];
5355 char *pos
= strstr
(t
, " — "
);
5358 old_title
= (char *) xmalloc
(strlen
(t
) + 1);
5359 strcpy
(old_title
, t
);
5361 size_title
= xmalloc
(strlen
(old_title
) + 40);
5362 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5363 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5368 #endif
/* NS_IMPL_COCOA */
5369 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5375 - (void
)windowDidResize
: (NSNotification
*)notification
5377 NSWindow
*theWindow
= [notification object
];
5379 #ifdef NS_IMPL_GNUSTEP
5380 /* in GNUstep, at least currently, it's possible to get a didResize
5381 without getting a willResize.. therefore we need to act as if we got
5382 the willResize now */
5383 NSSize sz
= [theWindow frame
].
size;
5384 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5385 #endif
/* NS_IMPL_GNUSTEP */
5387 NSTRACE
(windowDidResize
);
5388 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5390 #ifdef NS_IMPL_COCOA
5396 #endif
/* NS_IMPL_COCOA */
5398 /* Avoid loop under GNUstep due to call at beginning of this function.
5399 (x_set_window_size causes a resize which causes
5400 a "windowDidResize" which calls x_set_window_size). */
5401 #ifndef NS_IMPL_GNUSTEP
5402 if (cols
> 0 && rows
> 0)
5405 x_set_window_size
(emacsframe
, 0, cols
, rows
);
5408 NSWindow
*window
= [self window
];
5409 NSRect wr
= [window frame
];
5410 FRAME_PIXEL_WIDTH
(emacsframe
) = (int
)wr.
size.width
5411 - emacsframe
->border_width
;
5412 FRAME_PIXEL_HEIGHT
(emacsframe
) = (int
)wr.
size.height
5413 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5414 - FRAME_TOOLBAR_HEIGHT
(emacsframe
);
5415 change_frame_size
(emacsframe
, rows
, cols
, 0, 0, 1);
5416 SET_FRAME_GARBAGED
(emacsframe
);
5417 cancel_mouse_face
(emacsframe
);
5422 ns_send_appdefined
(-1);
5426 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5427 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5429 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5430 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5432 NSTRACE
(windowDidBecomeKey
);
5434 if (emacsframe
!= old_focus
)
5435 dpyinfo
->x_focus_frame
= emacsframe
;
5437 ns_frame_rehighlight
(emacsframe
);
5441 emacs_event
->kind
= FOCUS_IN_EVENT
;
5442 EV_TRAILER
((id
)nil
);
5447 - (void
)windowDidResignKey
: (NSNotification
*)notification
5448 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5450 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5451 NSTRACE
(windowDidResignKey
);
5453 if (dpyinfo
->x_focus_frame
== emacsframe
)
5454 dpyinfo
->x_focus_frame
= 0;
5456 ns_frame_rehighlight
(emacsframe
);
5458 /* FIXME: for some reason needed on second and subsequent clicks away
5459 from sole-frame Emacs to get hollow box to show */
5460 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5462 x_update_cursor
(emacsframe
, 1);
5463 x_set_frame_alpha
(emacsframe
);
5468 [self deleteWorkingText
];
5469 emacs_event
->kind
= FOCUS_IN_EVENT
;
5470 EV_TRAILER
((id
)nil
);
5475 - (void
)windowWillMiniaturize
: sender
5477 NSTRACE
(windowWillMiniaturize
);
5493 - initFrameFromEmacs
: (struct frame
*)f
5498 NSButton
*toggleButton
;
5499 int vbextra
= NS_SCROLL_BAR_WIDTH
(f
);
5504 NSTRACE
(initFrameFromEmacs
);
5507 processingCompose
= NO
;
5508 scrollbarsNeedingUpdate
= 0;
5510 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5512 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5513 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5514 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5515 [self initWithFrame
: r
];
5516 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5518 FRAME_NS_VIEW
(f
) = self
;
5522 win
= [[EmacsWindow alloc
]
5523 initWithContentRect
: r
5524 styleMask
: (NSResizableWindowMask |
5525 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5526 NSTitledWindowMask |
5528 NSMiniaturizableWindowMask |
5529 NSClosableWindowMask
)
5530 backing
: NSBackingStoreBuffered
5534 f
->border_width
= wr.
size.width
- r.
size.width
;
5535 FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
5537 [win setAcceptsMouseMovedEvents
: YES
];
5538 [win setDelegate
: self
];
5539 [win useOptimizedDrawing
: YES
];
5541 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5542 sz.height
= FRAME_LINE_HEIGHT
(f
);
5543 [win setResizeIncrements
: sz
];
5545 [[win contentView
] addSubview
: self
];
5548 [self registerForDraggedTypes
: ns_drag_types
];
5551 name
= [NSString stringWithUTF8String
:
5552 NILP
(tem
) ?
(unsigned
char *)"Emacs"
: SDATA
(tem
)];
5553 [win setTitle
: name
];
5555 /* toolbar support */
5556 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
5557 [NSString stringWithFormat
: @"Emacs Frame
%d",
5559 [win setToolbar
: toolbar
];
5560 [toolbar setVisible
: NO
];
5561 #ifdef NS_IMPL_COCOA
5562 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
5563 [toggleButton setTarget
: self
];
5564 [toggleButton setAction
: @selector
(toggleToolbar
: )];
5566 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5570 [win setMiniwindowTitle
:
5571 [NSString stringWithUTF8String
: SDATA
(tem
)]];
5574 NSScreen
*screen
= [win screen
];
5577 [win setFrameTopLeftPoint
: NSMakePoint
5578 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
5579 IN_BOUND
(-SCREENMAX
,
5580 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
5583 [win makeFirstResponder
: self
];
5585 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5586 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
5587 [win setBackgroundColor
: col
];
5588 if ([col alphaComponent
] != 1.0)
5589 [win setOpaque
: NO
];
5591 [self allocateGState
];
5593 [NSApp registerServicesMenuSendTypes
: ns_send_types
5601 - (void
)windowDidMove
: sender
5603 NSWindow
*win
= [self window
];
5604 NSRect r
= [win frame
];
5605 NSArray
*screens
= [NSScreen screens
];
5606 NSScreen
*screen
= [screens objectAtIndex
: 0];
5608 NSTRACE
(windowDidMove
);
5610 if (!emacsframe
->output_data.ns
)
5614 emacsframe
->left_pos
= r.origin.x
;
5615 emacsframe
->top_pos
=
5616 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
5621 /* Called AFTER method below, but before our windowWillResize call there leads
5622 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
5623 location so set_window_size moves the frame. */
5624 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5626 emacsframe
->output_data.ns
->zooming
= 1;
5631 /* Override to do something slightly nonstandard, but nice. First click on
5632 zoom button will zoom vertically. Second will zoom completely. Third
5633 returns to original. */
5634 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5635 defaultFrame
:(NSRect
)defaultFrame
5637 NSRect result
= [sender frame
];
5639 NSTRACE
(windowWillUseStandardFrame
);
5641 if (abs (defaultFrame.
size.height
- result.
size.height
)
5642 > FRAME_LINE_HEIGHT
(emacsframe
))
5645 ns_userRect
= result
;
5646 result.
size.height
= defaultFrame.
size.height
;
5647 result.origin.y
= defaultFrame.origin.y
;
5651 if (abs (defaultFrame.
size.width
- result.
size.width
)
5652 > FRAME_COLUMN_WIDTH
(emacsframe
))
5653 result
= defaultFrame
; /* second click */
5657 result
= ns_userRect.
size.height ? ns_userRect
: result
;
5658 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5662 [self windowWillResize
: sender toSize
: result.
size];
5667 - (void
)windowDidDeminiaturize
: sender
5669 NSTRACE
(windowDidDeminiaturize
);
5670 if (!emacsframe
->output_data.ns
)
5672 emacsframe
->async_iconified
= 0;
5673 emacsframe
->async_visible
= 1;
5674 windows_or_buffers_changed
++;
5678 emacs_event
->kind
= ICONIFY_EVENT
;
5679 EV_TRAILER
((id
)nil
);
5684 - (void
)windowDidExpose
: sender
5686 NSTRACE
(windowDidExpose
);
5687 if (!emacsframe
->output_data.ns
)
5689 emacsframe
->async_visible
= 1;
5690 SET_FRAME_GARBAGED
(emacsframe
);
5692 if (send_appdefined
)
5693 ns_send_appdefined
(-1);
5697 - (void
)windowDidMiniaturize
: sender
5699 NSTRACE
(windowDidMiniaturize
);
5700 if (!emacsframe
->output_data.ns
)
5703 emacsframe
->async_iconified
= 1;
5704 emacsframe
->async_visible
= 0;
5708 emacs_event
->kind
= ICONIFY_EVENT
;
5709 EV_TRAILER
((id
)nil
);
5714 - (void
)mouseEntered
: (NSEvent
*)theEvent
5716 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5717 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5718 NSTRACE
(mouseEntered
);
5720 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5724 - (void
)mouseExited
: (NSEvent
*)theEvent
5726 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5728 Mouse_HLInfo
*hlinfo
= emacsframe ? MOUSE_HL_INFO
(emacsframe
) : NULL;
5730 NSTRACE
(mouseExited
);
5735 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5737 if (emacsframe
== hlinfo
->mouse_face_mouse_frame
)
5739 clear_mouse_face
(hlinfo
);
5740 hlinfo
->mouse_face_mouse_frame
= 0;
5748 if (context_menu_value
== -1)
5749 context_menu_value
= [sender tag
];
5751 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
5752 emacsframe
->menu_bar_vector
,
5753 (void
*)[sender tag
]);
5754 ns_send_appdefined
(-1);
5759 - (EmacsToolbar
*)toolbar
5765 /* this gets called on toolbar button click */
5766 - toolbarClicked
: (id
)item
5769 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
5771 NSTRACE
(toolbarClicked
);
5776 /* send first event (for some reason two needed) */
5777 theEvent
= [[self window
] currentEvent
];
5778 emacs_event
->kind
= TOOL_BAR_EVENT
;
5779 XSETFRAME
(emacs_event
->arg
, emacsframe
);
5780 EV_TRAILER
(theEvent
);
5782 emacs_event
->kind
= TOOL_BAR_EVENT
;
5783 /* XSETINT (emacs_event->code, 0); */
5784 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
5785 idx
+ TOOL_BAR_ITEM_KEY
);
5786 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5787 EV_TRAILER
(theEvent
);
5792 - toggleToolbar
: (id
)sender
5797 emacs_event
->kind
= NS_NONKEY_EVENT
;
5798 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
5799 EV_TRAILER
((id
)nil
);
5804 - (void
)drawRect
: (NSRect
)rect
5806 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
5807 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
5811 if (!emacsframe ||
!emacsframe
->output_data.ns || ns_in_resize
)
5814 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
5815 expose_frame
(emacsframe
, x
, y
, width
, height
);
5818 drawRect: may be called (at least in OS X 10.5) for invisible
5819 views as well for some reason. Thus, do not infer visibility
5822 emacsframe->async_visible = 1;
5823 emacsframe->async_iconified = 0;
5828 /* NSDraggingDestination protocol methods. Actually this is not really a
5829 protocol, but a category of Object. O well... */
5831 -(NSUInteger
) draggingEntered
: (id
<NSDraggingInfo
>) sender
5833 NSTRACE
(draggingEntered
);
5834 return NSDragOperationGeneric
;
5838 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
5844 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
5849 NSEvent
*theEvent
= [[self window
] currentEvent
];
5852 NSTRACE
(performDragOperation
);
5857 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
5858 x
= lrint
(position.x
); y
= lrint
(position.y
);
5860 pb
= [sender draggingPasteboard
];
5861 type = [pb availableTypeFromArray
: ns_drag_types
];
5866 else if ([type isEqualToString
: NSFilenamesPboardType
])
5869 NSEnumerator
*fenum
;
5872 if (!(files
= [pb propertyListForType
: type]))
5875 fenum
= [files objectEnumerator
];
5876 while ( (file
= [fenum nextObject
]) )
5878 emacs_event
->kind
= NS_NONKEY_EVENT
;
5879 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5880 XSETINT
(emacs_event
->x
, x
);
5881 XSETINT
(emacs_event
->y
, y
);
5882 ns_input_file
= append2
(ns_input_file
,
5883 build_string
([file UTF8String
]));
5884 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5885 EV_TRAILER
(theEvent
);
5889 else if ([type isEqualToString
: NSURLPboardType
])
5894 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
5895 [fileURL isFileURL
] == NO
)
5898 file
= [fileURL
path];
5899 emacs_event
->kind
= NS_NONKEY_EVENT
;
5900 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5901 XSETINT
(emacs_event
->x
, x
);
5902 XSETINT
(emacs_event
->y
, y
);
5903 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
5904 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5905 EV_TRAILER
(theEvent
);
5908 else if ([type isEqualToString
: NSStringPboardType
]
5909 ||
[type isEqualToString
: NSTabularTextPboardType
])
5913 if (! (data
= [pb stringForType
: type]))
5916 emacs_event
->kind
= NS_NONKEY_EVENT
;
5917 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
5918 XSETINT
(emacs_event
->x
, x
);
5919 XSETINT
(emacs_event
->y
, y
);
5920 ns_input_text
= build_string
([data UTF8String
]);
5921 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5922 EV_TRAILER
(theEvent
);
5925 else if ([type isEqualToString
: NSColorPboardType
])
5927 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
5928 emacs_event
->kind
= NS_NONKEY_EVENT
;
5929 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
5930 XSETINT
(emacs_event
->x
, x
);
5931 XSETINT
(emacs_event
->y
, y
);
5932 ns_input_color
= ns_color_to_lisp
(c
);
5933 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5934 EV_TRAILER
(theEvent
);
5937 else if ([type isEqualToString
: NSFontPboardType
])
5939 /* impl based on GNUstep NSTextView.m */
5940 NSData
*data
= [pb dataForType
: NSFontPboardType
];
5941 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
5942 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
5948 emacs_event
->kind
= NS_NONKEY_EVENT
;
5949 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
5950 XSETINT
(emacs_event
->x
, x
);
5951 XSETINT
(emacs_event
->y
, y
);
5952 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
5953 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
5954 ns_input_fontsize
= build_string
(fontSize
);
5955 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5956 EV_TRAILER
(theEvent
);
5961 error ("Invalid data
type in dragging pasteboard."
);
5967 - (id
) validRequestorForSendType
: (NSString
*)typeSent
5968 returnType
: (NSString
*)typeReturned
5970 NSTRACE
(validRequestorForSendType
);
5971 if (typeSent
!= nil
&& [ns_send_types indexOfObject
: typeSent
] != NSNotFound
5972 && typeReturned
== nil
)
5974 if (! NILP
(ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
)))
5978 return [super validRequestorForSendType
: typeSent
5979 returnType
: typeReturned
];
5983 /* The next two methods are part of NSServicesRequests informal protocol,
5984 supposedly called when a services menu item is chosen from this app.
5985 But this should not happen because we override the services menu with our
5986 own entries which call ns-perform-service.
5987 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
5988 So let's at least stub them out until further investigation can be done. */
5990 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
5992 /* we could call ns_string_from_pasteboard(pboard) here but then it should
5993 be written into the buffer in place of the existing selection..
5994 ordinary service calls go through functions defined in ns-win.el */
5998 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
6000 NSArray
*typesDeclared
;
6003 /* We only support NSStringPboardType */
6004 if ([types containsObject
:NSStringPboardType
] == NO
) {
6008 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6009 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
6012 if (CONSP
(val
) && NILP
(XCDR
(val
)))
6015 if (! STRINGP
(val
))
6018 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
6019 [pb declareTypes
:typesDeclared owner
:nil
];
6020 ns_string_to_pasteboard
(pb
, val
);
6025 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
6026 (gives a miniaturized version of the window); currently we use the latter for
6027 frames whose active buffer doesn't correspond to any file
6028 (e.g., '*scratch*') */
6029 - setMiniwindowImage
: (BOOL
) setMini
6031 id
image = [[self window
] miniwindowImage
];
6032 NSTRACE
(setMiniwindowImage
);
6034 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6035 about "AppleDockIconEnabled" notwithstanding, however the set message
6036 below has its effect nonetheless. */
6037 if (image != emacsframe
->output_data.ns
->miniimage
)
6039 if (image && [image isKindOfClass
: [EmacsImage
class]])
6041 [[self window
] setMiniwindowImage
:
6042 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6049 - (void
) setRows
: (int
) r andColumns
: (int
) c
6055 @
end /* EmacsView */
6059 /* ==========================================================================
6061 EmacsWindow implementation
6063 ========================================================================== */
6065 @implementation EmacsWindow
6067 /* If we have multiple monitors, one above the other, we don't want to
6068 restrict the height to just one monitor. So we override this. */
6069 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6071 /* When making the frame visible for the first time or if there is just
6072 one screen, we want to constrain. Other times not. */
6073 NSUInteger nr_screens
= [[NSScreen screens
] count
];
6074 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6075 NSTRACE
(constrainFrameRect
);
6077 if (nr_screens
== 1)
6078 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6080 if (f
->output_data.ns
->dont_constrain
6081 || ns_menu_bar_should_be_hidden
())
6084 f
->output_data.ns
->dont_constrain
= 1;
6085 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6089 /* called only on resize clicks by special case in EmacsApp-sendEvent */
6090 - (void
)mouseDown
: (NSEvent
*)theEvent
6094 NSSize
size = [[theEvent window
] frame
].
size;
6095 grabOffset
= [theEvent locationInWindow
];
6096 grabOffset.x
= size.width
- grabOffset.x
;
6099 [super mouseDown
: theEvent
];
6104 - (void
)mouseUp
: (NSEvent
*)theEvent
6108 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6110 ns_set_name_as_filename
(f
);
6112 ns_send_appdefined
(-1);
6115 [super mouseUp
: theEvent
];
6119 /* send resize events */
6120 - (void
)mouseDragged
: (NSEvent
*)theEvent
6124 NSPoint p
= [theEvent locationInWindow
];
6125 NSSize
size, vettedSize
, origSize
= [self frame
].
size;
6127 size.width
= p.x
+ grabOffset.x
;
6128 size.height
= origSize.height
- p.y
+ grabOffset.y
;
6130 if (size.width
== origSize.width
&& size.height
== origSize.height
)
6133 vettedSize
= [[self delegate
] windowWillResize
: self toSize
: size];
6134 [[NSNotificationCenter defaultCenter
]
6135 postNotificationName
: NSWindowDidResizeNotification
6139 [super mouseDragged
: theEvent
];
6142 @
end /* EmacsWindow */
6145 /* ==========================================================================
6147 EmacsScroller implementation
6149 ========================================================================== */
6152 @implementation EmacsScroller
6154 /* for repeat button push */
6155 #define SCROLL_BAR_FIRST_DELAY
0.5
6156 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6158 + (CGFloat
) scrollerWidth
6160 /* TODO: if we want to allow variable widths, this is the place to do it,
6161 however neither GNUstep nor Cocoa support it very well */
6162 return [NSScroller scrollerWidth
];
6166 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
6168 NSTRACE
(EmacsScroller_initFrame
);
6170 r.
size.width
= [EmacsScroller scrollerWidth
];
6171 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
6172 [self setContinuous
: YES
];
6173 [self setEnabled
: YES
];
6175 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
6176 locked against the top and bottom edges, and right edge on OS X, where
6177 scrollers are on right. */
6178 #ifdef NS_IMPL_GNUSTEP
6179 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
6181 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
6186 pixel_height
= NSHeight
(r
);
6187 if (pixel_height
== 0) pixel_height
= 1;
6188 min_portion
= 20 / pixel_height
;
6190 frame
= XFRAME
(XWINDOW
(win
)->frame
);
6191 if (FRAME_LIVE_P
(frame
))
6194 EmacsView
*view = FRAME_NS_VIEW
(frame
);
6195 NSView
*sview
= [[view window
] contentView
];
6196 NSArray
*subs
= [sview subviews
];
6198 /* disable optimization stopping redraw of other scrollbars */
6199 view->scrollbarsNeedingUpdate
= 0;
6200 for (i
=[subs count
]-1; i
>= 0; i
--)
6201 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
6202 view->scrollbarsNeedingUpdate
++;
6203 [sview addSubview
: self
];
6206 /* [self setFrame: r]; */
6212 - (void
)setFrame
: (NSRect
)newRect
6214 NSTRACE
(EmacsScroller_setFrame
);
6216 pixel_height
= NSHeight
(newRect
);
6217 if (pixel_height
== 0) pixel_height
= 1;
6218 min_portion
= 20 / pixel_height
;
6219 [super setFrame
: newRect
];
6221 /* UNBLOCK_INPUT; */
6227 NSTRACE
(EmacsScroller_dealloc
);
6229 XWINDOW
(win
)->vertical_scroll_bar
= Qnil
;
6257 /* ensure other scrollbar updates after deletion */
6258 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6260 view->scrollbarsNeedingUpdate
++;
6261 [self removeFromSuperview
];
6269 - (void
)resetCursorRects
6271 NSRect visible
= [self visibleRect
];
6272 NSTRACE
(resetCursorRects
);
6274 if (!NSIsEmptyRect
(visible
))
6275 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
6276 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
6280 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
6283 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
6284 && portion
!= whole
; /* needed for resize empty buf */
6288 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
6290 NSTRACE
(setPosition
);
6292 em_position
= position
;
6293 em_portion
= portion
;
6296 if (portion
>= whole
)
6298 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6299 [self setKnobProportion
: 1.0];
6300 [self setDoubleValue
: 1.0];
6302 [self setFloatValue
: 0.0 knobProportion
: 1.0];
6308 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
6309 pos
= (float
)position
/ (whole
- portion
);
6310 por
= (float
)portion
/whole
;
6311 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6312 [self setKnobProportion
: por
];
6313 [self setDoubleValue
: pos
];
6315 [self setFloatValue
: pos knobProportion
: por
];
6321 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
6322 drag events will go directly to the EmacsScroller. Leaving in for now. */
6323 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
6324 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
6326 *part
= last_hit_part
;
6328 XSETINT
(*y
, pixel_height
);
6329 if ([self floatValue
] > 0.999)
6330 XSETINT
(*x
, pixel_height
);
6332 XSETINT
(*x
, pixel_height
* [self floatValue
]);
6336 /* set up emacs_event */
6337 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
6342 emacs_event
->part
= last_hit_part
;
6343 emacs_event
->code
= 0;
6344 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
6345 emacs_event
->frame_or_window
= win
;
6346 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
6347 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
6348 emacs_event
->arg
= Qnil
;
6349 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
6350 XSETINT
(emacs_event
->y
, pixel_height
-20);
6352 n_emacs_events_pending
++;
6353 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
6354 EVENT_INIT
(*emacs_event
);
6355 ns_send_appdefined
(-1);
6359 /* called manually thru timer to implement repeated button action w/hold-down */
6360 - repeatScroll
: (NSTimer
*)scrollEntry
6362 NSEvent
*e
= [[self window
] currentEvent
];
6363 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
6364 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
6366 /* clear timer if need be */
6367 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
6369 [scroll_repeat_entry invalidate
];
6370 [scroll_repeat_entry release
];
6371 scroll_repeat_entry
= nil
;
6377 = [[NSTimer scheduledTimerWithTimeInterval
:
6378 SCROLL_BAR_CONTINUOUS_DELAY
6380 selector
: @selector
(repeatScroll
:)
6386 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
6391 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
6392 mouseDragged events without going into a modal loop. */
6393 - (void
)mouseDown
: (NSEvent
*)e
6396 /* hitPart is only updated AFTER event is passed on */
6397 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6398 double inc
= 0.0, loc
, kloc
, pos
;
6401 NSTRACE
(EmacsScroller_mouseDown
);
6405 case NSScrollerDecrementPage
:
6406 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6407 case NSScrollerIncrementPage
:
6408 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6409 case NSScrollerDecrementLine
:
6410 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6411 case NSScrollerIncrementLine
:
6412 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6413 case NSScrollerKnob
:
6414 last_hit_part
= scroll_bar_handle
; break;
6415 case NSScrollerKnobSlot
: /* GNUstep-only */
6416 last_hit_part
= scroll_bar_move_ratio
; break;
6417 default
: /* NSScrollerNoPart? */
6418 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
6425 pos
= 0; /* ignored */
6427 /* set a timer to repeat, as we can't let superclass do this modally */
6429 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
6431 selector
: @selector
(repeatScroll
:)
6438 /* handle, or on GNUstep possibly slot */
6439 NSEvent
*fake_event
;
6441 /* compute float loc in slot and mouse offset on knob */
6442 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6444 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6450 else if (loc
>= NSHeight
(sr
))
6452 loc
= NSHeight
(sr
);
6460 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6462 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6464 last_mouse_offset
= kloc
;
6466 /* if knob, tell emacs a location offset by knob pos
6467 (to indicate top of handle) */
6468 if (part
== NSScrollerKnob
)
6469 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6471 /* else this is a slot click on GNUstep: go straight there */
6472 pos
= loc
/ NSHeight
(sr
);
6474 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6475 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6476 location
: [e locationInWindow
]
6477 modifierFlags
: [e modifierFlags
]
6478 timestamp
: [e timestamp
]
6479 windowNumber
: [e windowNumber
]
6480 context
: [e context
]
6481 eventNumber
: [e eventNumber
]
6482 clickCount
: [e clickCount
]
6483 pressure
: [e pressure
]];
6484 [super mouseUp
: fake_event
];
6487 if (part
!= NSScrollerKnob
)
6488 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6492 /* Called as we manually track scroller drags, rather than superclass. */
6493 - (void
)mouseDragged
: (NSEvent
*)e
6499 NSTRACE
(EmacsScroller_mouseDragged
);
6501 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6503 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6510 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6512 loc
= NSHeight
(sr
) + last_mouse_offset
;
6516 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6517 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6521 - (void
)mouseUp
: (NSEvent
*)e
6523 if (scroll_repeat_entry
)
6525 [scroll_repeat_entry invalidate
];
6526 [scroll_repeat_entry release
];
6527 scroll_repeat_entry
= nil
;
6533 /* treat scrollwheel events in the bar as though they were in the main window */
6534 - (void
) scrollWheel
: (NSEvent
*)theEvent
6536 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6537 [view mouseDown
: theEvent
];
6540 @
end /* EmacsScroller */
6545 /* ==========================================================================
6547 Font-related functions; these used to be in nsfaces.m
6549 ========================================================================== */
6553 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6555 struct font
*font
= XFONT_OBJECT
(font_object
);
6558 fontset
= fontset_from_font
(font_object
);
6559 FRAME_FONTSET
(f
) = fontset
;
6561 if (FRAME_FONT
(f
) == font
)
6562 /* This font is already set in frame F. There's nothing more to
6566 FRAME_FONT
(f
) = font
;
6568 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6569 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6570 FRAME_SPACE_WIDTH
(f
) = font
->space_width
;
6571 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6573 compute_fringe_widths
(f
, 1);
6575 /* Compute the scroll bar width in character columns. */
6576 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6578 int wid
= FRAME_COLUMN_WIDTH
(f
);
6579 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6580 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6584 int wid
= FRAME_COLUMN_WIDTH
(f
);
6585 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6588 /* Now make the frame display the given font. */
6589 if (FRAME_NS_WINDOW
(f
) != 0)
6590 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6596 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6597 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6601 ns_xlfd_to_fontname
(const
char *xlfd
)
6602 /* --------------------------------------------------------------------------
6603 Convert an X font name (XLFD) to an NS font name.
6604 Only family is used.
6605 The string returned is temporarily allocated.
6606 -------------------------------------------------------------------------- */
6608 char *name
= xmalloc
(180);
6612 if (!strncmp
(xlfd
, "
--"
, 2))
6613 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
6615 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
6617 /* stopgap for malformed XLFD input */
6618 if (strlen
(name
) == 0)
6619 strcpy
(name
, "Monaco"
);
6621 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
6622 also uppercase after '-' or ' ' */
6623 name
[0] = toupper
(name
[0]);
6624 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
6630 name
[i
+1] = toupper
(name
[i
+1]);
6632 else if (name
[i
] == '_')
6636 name
[i
+1] = toupper
(name
[i
+1]);
6639 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
6640 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
6647 syms_of_nsterm
(void
)
6649 NSTRACE
(syms_of_nsterm
);
6651 ns_antialias_threshold
= 10.0;
6653 /* from 23+ we need to tell emacs what modifiers there are.. */
6654 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
6655 DEFSYM
(Qalt
, "alt"
);
6656 DEFSYM
(Qhyper
, "hyper"
);
6657 DEFSYM
(Qmeta
, "
meta"
);
6658 DEFSYM
(Qsuper
, "super"
);
6659 DEFSYM
(Qcontrol
, "control"
);
6660 DEFSYM
(Qnone
, "none"
);
6661 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
6663 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
6664 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
6665 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
6666 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
6667 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
6669 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
6670 "The file specified in the last NS event."
);
6671 ns_input_file
=Qnil
;
6673 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
6674 "The data received in the last NS
text drag event."
);
6675 ns_input_text
=Qnil
;
6677 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
6678 "String
for visualizing working composition sequence."
);
6679 ns_working_text
=Qnil
;
6681 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
6682 "The font specified in the last NS event."
);
6683 ns_input_font
=Qnil
;
6685 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
6686 "The fontsize specified in the last NS event."
);
6687 ns_input_fontsize
=Qnil
;
6689 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
6690 "The
line specified in the last NS event."
);
6691 ns_input_line
=Qnil
;
6693 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
6694 "The color specified in the last NS event."
);
6695 ns_input_color
=Qnil
;
6697 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
6698 "The service name specified in the last NS event."
);
6699 ns_input_spi_name
=Qnil
;
6701 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
6702 "The service argument specified in the last NS event."
);
6703 ns_input_spi_arg
=Qnil
;
6705 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
6706 "This variable describes the behavior of the alternate or option key.
\n\
6707 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6708 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
6709 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6710 ns_alternate_modifier
= Qmeta
;
6712 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
6713 "This variable describes the behavior of the right alternate or option key.
\n\
6714 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6715 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
6716 Set to none means that the alternate / option key is not interpreted by Emacs\n\
6717 at all, allowing it to be used at a lower level for accented character entry.");
6718 ns_right_alternate_modifier = Qleft;
6720 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
6721 "This variable describes the behavior of the command key.\n\
6722 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
6723 ns_command_modifier = Qsuper;
6725 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
6726 "This variable describes the behavior of the right command key.\n\
6727 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6728 Set to left means be the same key as `ns-command-modifier'.
\n\
6729 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
6730 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6731 ns_right_command_modifier
= Qleft
;
6733 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
6734 "This variable describes the behavior of the control key.
\n\
6735 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
6736 ns_control_modifier
= Qcontrol
;
6738 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
6739 "This variable describes the behavior of the right control key.
\n\
6740 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6741 Set to left means be the same key as `ns
-control
-modifier
'.\n\
6742 Set to none means that the control / option key is not interpreted by Emacs\n\
6743 at all, allowing it to be used at a lower level for accented character entry.");
6744 ns_right_control_modifier = Qleft;
6746 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
6747 "This variable describes the behavior of the function key (on laptops).\n\
6748 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6749 Set to none means that the function key is not interpreted by Emacs at all,\n\
6750 allowing it to be used at a lower level for accented character entry.");
6751 ns_function_modifier = Qnone;
6753 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
6754 "Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above.");
6755 ns_antialias_text = Qt;
6757 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
6758 "Whether to confirm application quit using dialog.");
6759 ns_confirm_quit = Qnil;
6761 staticpro (&ns_display_name_list);
6762 ns_display_name_list = Qnil;
6764 staticpro (&last_mouse_motion_frame);
6765 last_mouse_motion_frame = Qnil;
6767 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
6768 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
6769 Only works on OSX 10.6 or later. */);
6770 ns_auto_hide_menu_bar = Qnil;
6772 /* TODO: move to common code */
6773 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
6774 doc: /* Which toolkit scroll bars Emacs uses, if any.
6775 A value of nil means Emacs doesn't use toolkit scroll bars.
6776 With the X Window system
, the value is a symbol describing the
6777 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
6778 With MS Windows or Nextstep
, the value is t. */
);
6779 Vx_toolkit_scroll_bars
= Qt
;
6781 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
6782 x_use_underline_position_properties
,
6783 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
6784 A value of nil means ignore them. If you encounter fonts with bogus
6785 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
6786 to 4.1, set this to nil. */);
6787 x_use_underline_position_properties
= 0;
6789 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
6790 x_underline_at_descent_line
,
6791 doc: /* Non-nil means to draw the underline at the same place as the descent line.
6792 A value of nil means to draw the underline according to the value of the
6793 variable `x-use-underline-position-properties', which is usually at the
6794 baseline level. The default value is nil. */);
6795 x_underline_at_descent_line
= 0;
6797 /* Tell emacs about this window system. */
6798 Fprovide
(intern
("ns"
), Qnil
);