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
struct timeval select_timeout
;
187 static int select_nfds
;
188 static NSAutoreleasePool
*outerpool
;
189 static
struct input_event
*emacs_event
= NULL;
190 static
struct input_event
*q_event_ptr
= NULL;
191 static int n_emacs_events_pending
= 0;
192 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
193 *ns_pending_service_args
;
194 static BOOL inNsSelect
= 0;
196 /* Convert modifiers in a NeXTstep event to emacs style modifiers. */
197 #define NS_FUNCTION_KEY_MASK
0x800000
198 #define NSLeftControlKeyMask
(0x000001 | NSControlKeyMask
)
199 #define NSRightControlKeyMask
(0x002000 | NSControlKeyMask
)
200 #define NSLeftCommandKeyMask
(0x000008 | NSCommandKeyMask
)
201 #define NSRightCommandKeyMask
(0x000010 | NSCommandKeyMask
)
202 #define NSLeftAlternateKeyMask
(0x000020 | NSAlternateKeyMask
)
203 #define NSRightAlternateKeyMask
(0x000040 | NSAlternateKeyMask
)
204 #define EV_MODIFIERS
(e
) \
205 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
206 hyper_modifier
: 0) \
207 |
(!EQ
(ns_right_alternate_modifier
, Qleft
) && \
208 (([e modifierFlags
] & NSRightAlternateKeyMask
) \
209 == NSRightAlternateKeyMask
) ? \
210 parse_solitary_modifier
(ns_right_alternate_modifier
) : 0) \
211 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
212 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
213 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
214 shift_modifier
: 0) \
215 |
(!EQ
(ns_right_control_modifier
, Qleft
) && \
216 (([e modifierFlags
] & NSRightControlKeyMask
) \
217 == NSRightControlKeyMask
) ? \
218 parse_solitary_modifier
(ns_right_control_modifier
) : 0) \
219 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
220 parse_solitary_modifier
(ns_control_modifier
) : 0) \
221 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
222 parse_solitary_modifier
(ns_function_modifier
) : 0) \
223 |
(!EQ
(ns_right_command_modifier
, Qleft
) && \
224 (([e modifierFlags
] & NSRightCommandKeyMask
) \
225 == NSRightCommandKeyMask
) ? \
226 parse_solitary_modifier
(ns_right_command_modifier
) : 0) \
227 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
228 parse_solitary_modifier
(ns_command_modifier
):0))
230 #define EV_UDMODIFIERS
(e
) \
231 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
232 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
233 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
234 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
235 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
236 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
237 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
238 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
239 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
241 #define EV_BUTTON
(e
) \
242 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
243 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
244 [e buttonNumber
] - 1)
246 /* Convert the time field to a timestamp in milliseconds. */
247 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
249 /* This is a piece of code which is common to all the event handling
250 methods. Maybe it should even be a function. */
251 #define EV_TRAILER
(e
) \
253 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
254 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
255 n_emacs_events_pending
++; \
256 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
257 EVENT_INIT
(*emacs_event
); \
258 ns_send_appdefined
(-1); \
261 void x_set_cursor_type
(struct frame
*, Lisp_Object
, Lisp_Object
);
263 /* TODO: get rid of need for these forward declarations */
264 static void ns_condemn_scroll_bars
(struct frame
*f
);
265 static void ns_judge_scroll_bars
(struct frame
*f
);
266 void x_set_frame_alpha
(struct frame
*f
);
269 /* ==========================================================================
273 ========================================================================== */
277 append2
(Lisp_Object list
, Lisp_Object item
)
278 /* --------------------------------------------------------------------------
279 Utility to append to a list
280 -------------------------------------------------------------------------- */
282 Lisp_Object array
[2];
284 array
[1] = Fcons
(item
, Qnil
);
285 return Fnconc
(2, &array
[0]);
291 /* --------------------------------------------------------------------------
292 Used to allow emacs to find its resources under Emacs.app
293 Called from emacs.c at startup.
294 -------------------------------------------------------------------------- */
296 NSBundle
*bundle
= [NSBundle mainBundle
];
297 NSString
*binDir
= [bundle bundlePath
], *resourceDir
= [bundle resourcePath
];
298 NSString
*resourcePath
, *resourcePaths
;
300 BOOL onWindows
= NO
; /* how do I determine this? */
301 NSString
*pathSeparator
= onWindows ? @"
;"
: @"
:"
;
302 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
304 /*NSLog (@"ns_init_paths: '%@'\n%@\n", [[NSBundle mainBundle] bundlePath], [[NSBundle mainBundle] resourcePath]); */
306 /* get bindir from base */
307 range
= [resourceDir rangeOfString
: @"Contents"
];
308 if (range.location
!= NSNotFound
)
310 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
312 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
316 /* the following based on Andrew Choi's init_mac_osx_environment () */
317 if (!getenv ("EMACSLOADPATH"
))
319 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
320 [NSArray arrayWithObjects
:
321 @"site
-lisp"
, @"lisp"
, @"leim"
, nil
]];
322 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
324 while (resourcePath
= [pathEnum nextObject
])
326 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
329 if ([resourcePaths
length] > 0)
331 = [resourcePaths stringByAppendingString
: pathSeparator
];
333 = [resourcePaths stringByAppendingString
: resourcePath
];
336 if ([resourcePaths
length] > 0)
337 setenv
("EMACSLOADPATH"
, [resourcePaths UTF8String
], 1);
338 /*NSLog (@"loadPath: '%@'\n", resourcePaths); */
341 if (!getenv ("EMACSPATH"
))
343 NSArray
*paths
= [binDir stringsByAppendingPaths
:
344 [NSArray arrayWithObjects
: @"bin"
,
346 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
348 while (resourcePath
= [pathEnum nextObject
])
350 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
353 if ([resourcePaths
length] > 0)
355 = [resourcePaths stringByAppendingString
: pathSeparator
];
357 = [resourcePaths stringByAppendingString
: resourcePath
];
360 if ([resourcePaths
length] > 0)
361 setenv
("EMACSPATH"
, [resourcePaths UTF8String
], 1);
364 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
365 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
369 if (!getenv ("EMACSDATA"
))
370 setenv
("EMACSDATA"
, [resourcePath UTF8String
], 1);
371 if (!getenv ("EMACSDOC"
))
372 setenv
("EMACSDOC"
, [resourcePath UTF8String
], 1);
376 if (!getenv ("INFOPATH"
))
378 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"
info"
];
379 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
381 setenv
("INFOPATH"
, [[resourcePath stringByAppendingString
: @"
:"
]
383 /* Note, extra colon needed to cause merge w/later user additions. */
389 timeval_subtract
(struct timeval
*result
, struct timeval x
, struct timeval y
)
390 /* --------------------------------------------------------------------------
391 Subtract the `struct timeval' values X and Y, storing the result in RESULT.
392 Return 1 if the difference is negative, otherwise 0.
393 -------------------------------------------------------------------------- */
395 /* Perform the carry for the later subtraction by updating y.
396 This is safer because on some systems
397 the tv_sec member is unsigned. */
398 if (x.tv_usec
< y.tv_usec
)
400 int nsec
= (y.tv_usec
- x.tv_usec
) / 1000000 + 1;
401 y.tv_usec
-= 1000000 * nsec
;
404 if (x.tv_usec
- y.tv_usec
> 1000000)
406 int nsec
= (y.tv_usec
- x.tv_usec
) / 1000000;
407 y.tv_usec
+= 1000000 * nsec
;
411 /* Compute the time remaining to wait. tv_usec is certainly positive. */
412 result
->tv_sec
= x.tv_sec
- y.tv_sec
;
413 result
->tv_usec
= x.tv_usec
- y.tv_usec
;
415 /* Return indication of whether the result should be considered negative. */
416 return x.tv_sec
< y.tv_sec
;
420 ns_timeout
(int usecs
)
421 /* --------------------------------------------------------------------------
422 Blocking timer utility used by ns_ring_bell
423 -------------------------------------------------------------------------- */
425 struct timeval wakeup
;
427 EMACS_GET_TIME
(wakeup
);
429 /* Compute time to wait until, propagating carry from usecs. */
430 wakeup.tv_usec
+= usecs
;
431 wakeup.tv_sec
+= (wakeup.tv_usec
/ 1000000);
432 wakeup.tv_usec
%= 1000000;
434 /* Keep waiting until past the time wakeup. */
437 struct timeval timeout
;
439 EMACS_GET_TIME
(timeout
);
441 /* In effect, timeout = wakeup - timeout.
442 Break if result would be negative. */
443 if (timeval_subtract
(&timeout
, wakeup
, timeout
))
446 /* Try to wait that long--but we might wake up sooner. */
447 select
(0, NULL, NULL, NULL, &timeout
);
453 ns_release_object
(void
*obj
)
454 /* --------------------------------------------------------------------------
455 Release an object (callable from C)
456 -------------------------------------------------------------------------- */
463 ns_retain_object
(void
*obj
)
464 /* --------------------------------------------------------------------------
465 Retain an object (callable from C)
466 -------------------------------------------------------------------------- */
473 ns_alloc_autorelease_pool
(void
)
474 /* --------------------------------------------------------------------------
475 Allocate a pool for temporary objects (callable from C)
476 -------------------------------------------------------------------------- */
478 return [[NSAutoreleasePool alloc
] init
];
483 ns_release_autorelease_pool
(void
*pool
)
484 /* --------------------------------------------------------------------------
485 Free a pool and temporary objects it refers to (callable from C)
486 -------------------------------------------------------------------------- */
488 ns_release_object
(pool
);
493 /* ==========================================================================
495 Focus (clipping) and screen update
497 ========================================================================== */
500 ns_resize_handle_rect
(NSWindow
*window
)
502 NSRect r
= [window frame
];
503 r.origin.x
= r.
size.width
- RESIZE_HANDLE_SIZE
;
505 r.
size.width
= r.
size.height
= RESIZE_HANDLE_SIZE
;
511 // Window constraining
512 // -------------------
514 // To ensure that the windows are not placed under the
menu bar, they
515 // are typically moved by the call
-back constrainFrameRect. However
,
516 // by overriding it
, it
's possible to inhibit this, leaving the window
517 // in it's original position.
519 // It
's possible to hide the menu bar. However, technically, it's only
520 // possible to hide it when the application is active. To ensure that
521 // this work properly
, the
menu bar and window constraining are
522 // deferred until the application becomes active.
524 // Even though it
's not possible to manually move a window above the
525 // top of the screen, it is allowed if it's done programmatically
,
526 // when the
menu is
hidden. This allows the editable area to cover the
527 // full screen height.
532 // Use the following extra files
:
535 // ;; Hide
menu and place frame slightly above the top of the screen.
536 // (setq ns
-auto
-hide
-menu-bar t
)
537 // (set-frame
-position
(selected
-frame
) 0 -20)
541 // emacs
-Q
-l init.el
543 // Result
: No
menu bar, and the
title bar should be above the screen.
549 // Result
: Menu bar visible
, frame placed immediately below the
menu.
553 ns_constrain_all_frames
(void
)
555 Lisp_Object tail
, frame
;
557 FOR_EACH_FRAME
(tail
, frame
)
559 struct frame
*f
= XFRAME
(frame
);
562 NSView
*view = FRAME_NS_VIEW
(f
);
563 /* This no-op will trigger the default window placing
564 * constraint system. */
565 f
->output_data.ns
->dont_constrain
= 0;
566 [[view window
] setFrameOrigin
:[[view window
] frame
].origin
];
572 /* True, if the menu bar should be hidden. */
575 ns_menu_bar_should_be_hidden
(void
)
577 return !NILP
(ns_auto_hide_menu_bar
)
578 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)];
582 /* Show or hide the menu bar, based on user setting. */
585 ns_update_auto_hide_menu_bar
(void
)
587 #ifndef MAC_OS_X_VERSION_10_6
588 #define MAC_OS_X_VERSION_10_6
1060
591 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
594 NSTRACE
(ns_update_auto_hide_menu_bar
);
598 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)])
600 // Note
, "setPresentationOptions" triggers an
error unless the
601 // application is active.
602 BOOL menu_bar_should_be_hidden
= ns_menu_bar_should_be_hidden
();
604 if (menu_bar_should_be_hidden
!= ns_menu_bar_is_hidden
)
606 NSApplicationPresentationOptions options
607 = NSApplicationPresentationAutoHideDock
;
609 if (menu_bar_should_be_hidden
)
610 options |
= NSApplicationPresentationAutoHideMenuBar
;
612 [NSApp setPresentationOptions
: options
];
614 ns_menu_bar_is_hidden
= menu_bar_should_be_hidden
;
616 if (!ns_menu_bar_is_hidden
)
618 ns_constrain_all_frames
();
630 ns_update_begin
(struct frame
*f
)
631 /* --------------------------------------------------------------------------
632 Prepare for a grouped sequence of drawing calls
633 external (RIF) call; whole frame, called before update_window_begin
634 -------------------------------------------------------------------------- */
636 NSView
*view = FRAME_NS_VIEW
(f
);
637 NSTRACE
(ns_update_begin
);
639 ns_update_auto_hide_menu_bar
();
641 ns_updating_frame
= f
;
644 #ifdef NS_IMPL_GNUSTEP
645 uRect
= NSMakeRect
(0, 0, 0, 0);
651 ns_update_window_begin
(struct window
*w
)
652 /* --------------------------------------------------------------------------
653 Prepare for a grouped sequence of drawing calls
654 external (RIF) call; for one window, called after update_begin
655 -------------------------------------------------------------------------- */
657 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
658 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
659 NSTRACE
(ns_update_window_begin
);
662 set_output_cursor
(&w
->cursor
);
666 if (f
== hlinfo
->mouse_face_mouse_frame
)
668 /* Don't do highlighting for mouse motion during the update. */
669 hlinfo
->mouse_face_defer
= 1;
671 /* If the frame needs to be redrawn,
672 simply forget about any prior mouse highlighting. */
673 if (FRAME_GARBAGED_P
(f
))
674 hlinfo
->mouse_face_window
= Qnil
;
676 /* (further code for mouse faces ifdef'd out in other terms elided) */
684 ns_update_window_end
(struct window
*w
, int cursor_on_p
,
685 int mouse_face_overwritten_p
)
686 /* --------------------------------------------------------------------------
687 Finished a grouped sequence of drawing calls
688 external (RIF) call; for one window called before update_end
689 -------------------------------------------------------------------------- */
691 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(XFRAME
(w
->frame
));
693 /* note: this fn is nearly identical in all terms */
694 if (!w
->pseudo_window_p
)
699 display_and_set_cursor
(w
, 1,
700 output_cursor.hpos
, output_cursor.vpos
,
701 output_cursor.x
, output_cursor.y
);
703 if (draw_window_fringes
(w
, 1))
704 x_draw_vertical_border
(w
);
709 /* If a row with mouse-face was overwritten, arrange for
710 frame_up_to_date to redisplay the mouse highlight. */
711 if (mouse_face_overwritten_p
)
713 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
714 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
715 hlinfo
->mouse_face_window
= Qnil
;
718 updated_window
= NULL;
719 NSTRACE
(update_window_end
);
724 ns_update_end
(struct frame
*f
)
725 /* --------------------------------------------------------------------------
726 Finished a grouped sequence of drawing calls
727 external (RIF) call; for whole frame, called after update_window_end
728 -------------------------------------------------------------------------- */
730 NSView
*view = FRAME_NS_VIEW
(f
);
732 /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
733 MOUSE_HL_INFO
(f
)->mouse_face_defer
= 0;
737 #ifdef NS_IMPL_GNUSTEP
738 /* trigger flush only in the rectangle we tracked as being drawn */
739 [view unlockFocusNeedsFlush
: NO
];
740 /*fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", uRect.origin.x, uRect.origin.y, uRect.size.width, uRect.size.height); */
741 [view lockFocusInRect
: uRect
];
745 [[view window
] flushWindow
];
748 ns_updating_frame
= NULL;
749 NSTRACE
(ns_update_end
);
754 ns_flush
(struct frame
*f
)
755 /* --------------------------------------------------------------------------
757 NS impl is no-op since currently we flush in ns_update_end and elsewhere
758 -------------------------------------------------------------------------- */
765 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
766 /* --------------------------------------------------------------------------
767 Internal: Focus on given frame. During small local updates this is used to
768 draw, however during large updates, ns_update_begin and ns_update_end are
769 called to wrap the whole thing, in which case these calls are stubbed out.
770 Except, on GNUstep, we accumulate the rectangle being drawn into, because
771 the back end won't do this automatically, and will just end up flushing
773 -------------------------------------------------------------------------- */
775 // NSTRACE
(ns_focus
);
776 #ifdef NS_IMPL_GNUSTEP
779 u
= NSUnionRect
(r
[0], r
[1]);
784 fprintf (stderr, "focus: %d", c++);
785 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
786 fprintf (stderr, "\n"); */
788 if (f
!= ns_updating_frame
)
790 NSView
*view = FRAME_NS_VIEW
(f
);
791 if (view != focus_view
)
793 if (focus_view
!= NULL)
795 [focus_view unlockFocus
];
796 [[focus_view window
] flushWindow
];
801 #ifdef NS_IMPL_GNUSTEP
802 r ?
[view lockFocusInRect
: u
] : [view lockFocus
];
807 /*if (view) debug_lock++; */
809 #ifdef NS_IMPL_GNUSTEP
812 /* more than one rect being drawn into */
815 [view unlockFocus
]; /* add prev rect to redraw list */
816 [view lockFocusInRect
: u
]; /* focus for draw in new rect */
821 #ifdef NS_IMPL_GNUSTEP
824 /* in batch mode, but in GNUstep must still track rectangles explicitly */
825 uRect
= (r ? NSUnionRect
(uRect
, u
) : [FRAME_NS_VIEW
(f
) visibleRect
]);
832 [[NSGraphicsContext currentContext
] saveGraphicsState
];
834 NSRectClipList
(r
, 2);
843 ns_unfocus
(struct frame
*f
)
844 /* --------------------------------------------------------------------------
845 Internal: Remove focus on given frame
846 -------------------------------------------------------------------------- */
848 // NSTRACE
(ns_unfocus
);
852 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
856 if (f
!= ns_updating_frame
)
858 if (focus_view
!= NULL)
860 [focus_view unlockFocus
];
861 [[focus_view window
] flushWindow
];
870 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
, int area
, BOOL gc
)
871 /* --------------------------------------------------------------------------
872 Internal (but parallels other terms): Focus drawing on given row
873 -------------------------------------------------------------------------- */
875 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
877 int window_x
, window_y
, window_width
;
879 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
881 clip_rect.origin.x
= window_x
- FRAME_INTERNAL_BORDER_WIDTH
(f
);
882 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
883 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
884 clip_rect.
size.width
= window_width
+ 2 * FRAME_INTERNAL_BORDER_WIDTH
(f
);
885 clip_rect.
size.height
= row
->visible_height
;
887 /* allow a full-height row at the top when requested
888 (used to draw fringe all the way through internal border area) */
889 if (gc
&& clip_rect.origin.y
< 5)
891 clip_rect.origin.y
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
892 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
895 /* likewise at bottom */
897 FRAME_PIXEL_HEIGHT
(f
) - (clip_rect.origin.y
+ clip_rect.
size.height
) < 5)
898 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
900 ns_focus
(f
, &clip_rect
, 1);
905 ns_ring_bell
(struct frame
*f
)
906 /* --------------------------------------------------------------------------
908 -------------------------------------------------------------------------- */
910 NSTRACE
(ns_ring_bell
);
913 NSAutoreleasePool
*pool
;
914 struct frame
*frame
= SELECTED_FRAME
();
918 pool
= [[NSAutoreleasePool alloc
] init
];
920 view = FRAME_NS_VIEW
(frame
);
924 NSPoint dim
= NSMakePoint
(128, 128);
927 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
928 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
929 r.
size.width
= dim.x
;
930 r.
size.height
= dim.y
;
931 surr
= NSInsetRect
(r
, -2, -2);
932 ns_focus
(frame
, &surr
, 1);
933 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
934 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
935 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
937 [[view window
] flushWindow
];
939 [[view window
] restoreCachedImage
];
940 [[view window
] flushWindow
];
954 ns_reset_terminal_modes
(struct terminal *terminal)
955 /* Externally called as hook */
957 NSTRACE
(ns_reset_terminal_modes
);
962 ns_set_terminal_modes
(struct terminal *terminal)
963 /* Externally called as hook */
965 NSTRACE
(ns_set_terminal_modes
);
970 /* ==========================================================================
972 Frame / window manager related functions
974 ========================================================================== */
978 ns_raise_frame
(struct frame
*f
)
979 /* --------------------------------------------------------------------------
980 Bring window to foreground and make it active
981 -------------------------------------------------------------------------- */
983 NSView
*view = FRAME_NS_VIEW
(f
);
986 FRAME_SAMPLE_VISIBILITY
(f
);
987 if (FRAME_VISIBLE_P
(f
))
989 [[view window
] makeKeyAndOrderFront
: NSApp
];
996 ns_lower_frame
(struct frame
*f
)
997 /* --------------------------------------------------------------------------
999 -------------------------------------------------------------------------- */
1001 NSView
*view = FRAME_NS_VIEW
(f
);
1004 [[view window
] orderBack
: NSApp
];
1010 ns_frame_raise_lower
(struct frame
*f
, int raise
)
1011 /* --------------------------------------------------------------------------
1013 -------------------------------------------------------------------------- */
1015 NSTRACE
(ns_frame_raise_lower
);
1025 ns_frame_rehighlight
(struct frame
*frame
)
1026 /* --------------------------------------------------------------------------
1027 External (hook): called on things like window switching within frame
1028 -------------------------------------------------------------------------- */
1030 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(frame
);
1031 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1033 NSTRACE
(ns_frame_rehighlight
);
1034 if (dpyinfo
->x_focus_frame
)
1036 dpyinfo
->x_highlight_frame
1037 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1038 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1039 : dpyinfo
->x_focus_frame
);
1040 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
1042 FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
) = Qnil
;
1043 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1047 dpyinfo
->x_highlight_frame
= 0;
1049 if (dpyinfo
->x_highlight_frame
&&
1050 dpyinfo
->x_highlight_frame
!= old_highlight
)
1054 x_update_cursor
(old_highlight
, 1);
1055 x_set_frame_alpha
(old_highlight
);
1057 if (dpyinfo
->x_highlight_frame
)
1059 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
1060 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
1067 x_make_frame_visible
(struct frame
*f
)
1068 /* --------------------------------------------------------------------------
1069 External: Show the window (X11 semantics)
1070 -------------------------------------------------------------------------- */
1072 NSTRACE
(x_make_frame_visible
);
1073 /* XXX: at some points in past this was not needed, as the only place that
1074 called this (frame.c:Fraise_frame ()) also called raise_lower;
1075 if this ends up the case again, comment this out again. */
1076 if (!FRAME_VISIBLE_P
(f
))
1078 f
->async_visible
= 1;
1085 x_make_frame_invisible
(struct frame
*f
)
1086 /* --------------------------------------------------------------------------
1087 External: Hide the window (X11 semantics)
1088 -------------------------------------------------------------------------- */
1090 NSView
* view = FRAME_NS_VIEW
(f
);
1091 NSTRACE
(x_make_frame_invisible
);
1093 [[view window
] orderOut
: NSApp
];
1094 f
->async_visible
= 0;
1095 f
->async_iconified
= 0;
1100 x_iconify_frame
(struct frame
*f
)
1101 /* --------------------------------------------------------------------------
1102 External: Iconify window
1103 -------------------------------------------------------------------------- */
1105 NSView
* view = FRAME_NS_VIEW
(f
);
1106 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1107 NSTRACE
(x_iconify_frame
);
1110 if (dpyinfo
->x_highlight_frame
== f
)
1111 dpyinfo
->x_highlight_frame
= 0;
1113 if ([[view window
] windowNumber
] <= 0)
1115 /* the window is still deferred. Make it very small, bring it
1116 on screen and order it out. */
1117 NSRect s
= { { 100, 100}, {0, 0} };
1119 t
= [[view window
] frame
];
1120 [[view window
] setFrame
: s display
: NO
];
1121 [[view window
] orderBack
: NSApp
];
1122 [[view window
] orderOut
: NSApp
];
1123 [[view window
] setFrame
: t display
: NO
];
1125 [[view window
] miniaturize
: NSApp
];
1128 /* Free X resources of frame F. */
1131 x_free_frame_resources
(struct frame
*f
)
1133 NSView
*view = FRAME_NS_VIEW
(f
);
1134 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1135 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1136 NSTRACE
(x_destroy_window
);
1139 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1143 free_frame_menubar
(f
);
1145 if (FRAME_FACE_CACHE
(f
))
1146 free_frame_faces
(f
);
1148 if (f
== dpyinfo
->x_focus_frame
)
1149 dpyinfo
->x_focus_frame
= 0;
1150 if (f
== dpyinfo
->x_highlight_frame
)
1151 dpyinfo
->x_highlight_frame
= 0;
1152 if (f
== hlinfo
->mouse_face_mouse_frame
)
1154 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1155 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1156 hlinfo
->mouse_face_window
= Qnil
;
1157 hlinfo
->mouse_face_deferred_gc
= 0;
1158 hlinfo
->mouse_face_mouse_frame
= 0;
1161 if (f
->output_data.ns
->miniimage
!= nil
)
1162 [f
->output_data.ns
->miniimage release
];
1164 [[view window
] close];
1167 xfree
(f
->output_data.ns
);
1173 x_destroy_window
(struct frame
*f
)
1174 /* --------------------------------------------------------------------------
1175 External: Delete the window
1176 -------------------------------------------------------------------------- */
1178 NSTRACE
(x_destroy_window
);
1180 x_free_frame_resources
(f
);
1186 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1187 /* --------------------------------------------------------------------------
1188 External: Position the window
1189 -------------------------------------------------------------------------- */
1191 NSView
*view = FRAME_NS_VIEW
(f
);
1192 NSArray
*screens
= [NSScreen screens
];
1193 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1194 NSScreen
*screen
= [[view window
] screen
];
1196 NSTRACE
(x_set_offset
);
1203 if (view != nil
&& screen
&& fscreen
)
1205 f
->left_pos
= f
->size_hint_flags
& XNegative
1206 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1208 /* We use visibleFrame here to take menu bar into account.
1209 Ideally we should also adjust left/top with visibleFrame.origin. */
1211 f
->top_pos
= f
->size_hint_flags
& YNegative
1212 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1213 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1214 - FRAME_TOOLBAR_HEIGHT
(f
))
1216 #ifdef NS_IMPL_GNUSTEP
1217 if (f
->left_pos
< 100)
1218 f
->left_pos
= 100; /* don't overlap menu */
1220 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1222 f
->output_data.ns
->dont_constrain
= 0;
1223 [[view window
] setFrameTopLeftPoint
:
1224 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1225 SCREENMAXBOUND
([fscreen frame
].
size.height
1226 - NS_TOP_POS
(f
)))];
1227 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1235 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1236 /* --------------------------------------------------------------------------
1237 Adjust window pixel size based on given character grid size
1238 Impl is a bit more complex than other terms, need to do some
1240 -------------------------------------------------------------------------- */
1242 EmacsView
*view = FRAME_NS_VIEW
(f
);
1243 EmacsToolbar
*toolbar
= [view toolbar
];
1244 NSWindow
*window
= [view window
];
1245 NSRect wr
= [window frame
];
1246 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1247 int pixelwidth
, pixelheight
;
1248 static int oldRows
, oldCols
, oldFontWidth
, oldFontHeight
;
1250 static
struct frame
*oldF
;
1252 NSTRACE
(x_set_window_size
);
1256 && rows
== oldRows
&& cols
== oldCols
1257 && oldFontWidth
== FRAME_COLUMN_WIDTH
(f
)
1258 && oldFontHeight
== FRAME_LINE_HEIGHT
(f
)
1262 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1266 check_frame_size
(f
, &rows
, &cols
);
1270 oldFontWidth
= FRAME_COLUMN_WIDTH
(f
);
1271 oldFontHeight
= FRAME_LINE_HEIGHT
(f
);
1274 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1275 compute_fringe_widths
(f
, 0);
1277 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1278 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1280 /* If we have a toolbar, take its height into account. */
1282 /* NOTE: previously this would generate wrong result if toolbar not
1283 yet displayed and fixing toolbar_height=32 helped, but
1284 now (200903) seems no longer needed */
1285 FRAME_TOOLBAR_HEIGHT
(f
) =
1286 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1287 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1289 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1291 wr.
size.width
= pixelwidth
+ f
->border_width
;
1292 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1293 + FRAME_TOOLBAR_HEIGHT
(f
);
1295 /* Do not try to constrain to this screen. We may have multiple
1296 screens, and want Emacs to span those. Constraining to screen
1297 prevents that, and that is not nice to the user. */
1298 if (f
->output_data.ns
->zooming
)
1299 f
->output_data.ns
->zooming
= 0;
1301 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1303 [view setRows
: rows andColumns
: cols
];
1304 [window setFrame
: wr display
: YES
];
1306 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1308 /* This is a trick to compensate for Emacs' managing the scrollbar area
1309 as a fixed number of standard character columns. Instead of leaving
1310 blank space for the extra, we chopped it off above. Now for
1311 left-hand scrollbars, we shift all rendering to the left by the
1312 difference between the real width and Emacs' imagined one. For
1313 right-hand bars, don't worry about it since the extra is never used.
1314 (Obviously doesn't work for vertically split windows tho..) */
1316 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1317 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1318 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1319 : NSMakePoint
(0, 0);
1320 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1321 [view setBoundsOrigin
: origin
];
1324 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1325 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1326 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1327 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1329 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1330 cancel_mouse_face
(f
);
1337 /* ==========================================================================
1341 ========================================================================== */
1345 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1347 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1348 if (idx
< 1 || idx
>= color_table
->avail
)
1350 return color_table
->colors
[idx
];
1355 ns_index_color
(NSColor
*color
, struct frame
*f
)
1357 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1361 if (!color_table
->colors
)
1363 color_table
->size = NS_COLOR_CAPACITY
;
1364 color_table
->avail
= 1; /* skip idx=0 as marker */
1366 = (NSColor
**)xmalloc
(color_table
->size * sizeof
(NSColor
*));
1367 color_table
->colors
[0] = nil
;
1368 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1371 /* do we already have this color ? */
1372 for (i
= 1; i
< color_table
->avail
; i
++)
1373 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1376 if ([color_table
->empty_indices count
] > 0)
1378 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1379 [color_table
->empty_indices removeObject
: index
];
1380 idx
= [index unsignedLongValue
];
1384 if (color_table
->avail
== color_table
->size)
1385 color_table
->colors
=
1386 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1387 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1388 idx
= color_table
->avail
++;
1391 color_table
->colors
[idx
] = color
;
1393 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1399 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1401 struct ns_color_table
*color_table
;
1408 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1410 if (idx
<= 0 || idx
>= color_table
->size) {
1411 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1415 index
= [NSNumber numberWithUnsignedInt
: idx
];
1416 if ([color_table
->empty_indices containsObject
: index
]) {
1417 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1421 color
= color_table
->colors
[idx
];
1423 color_table
->colors
[idx
] = nil
;
1424 [color_table
->empty_indices addObject
: index
];
1425 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1430 ns_get_color
(const
char *name
, NSColor
**col
)
1431 /* --------------------------------------------------------------------------
1433 -------------------------------------------------------------------------- */
1434 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1435 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1436 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1439 static
char hex
[20];
1441 float r
= -1.0, g
, b
;
1442 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1444 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1447 if ([nsname isEqualToString
: @"ns_selection_color"
])
1449 nsname
= ns_selection_color
;
1450 name
= [ns_selection_color UTF8String
];
1453 /* First, check for some sort of numeric specification. */
1456 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1458 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1459 [scanner scanFloat
: &r
];
1460 [scanner scanFloat
: &g
];
1461 [scanner scanFloat
: &b
];
1463 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1465 strncpy
(hex
, name
+ 4, 19);
1467 scaling
= (strlen
(hex
) - 2) / 3;
1469 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1471 int len
= (strlen
(name
) - 1);
1472 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1474 scaling
= strlen
(name
+start
) / 3;
1475 for (i
=0; i
<3; i
++) {
1476 strncpy
(hex
+ i
* (scaling
+ 1), name
+ start
+ i
* scaling
, scaling
);
1477 hex
[(i
+1) * (scaling
+ 1) - 1] = '/';
1479 hex
[3 * (scaling
+ 1) - 1] = '\0';
1485 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1486 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1496 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1501 /* Otherwise, color is expected to be from a list */
1503 NSEnumerator
*lenum
, *cenum
;
1507 #ifdef NS_IMPL_GNUSTEP
1508 /* XXX: who is wrong, the requestor or the implementation? */
1509 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1511 nsname
= @"highlightColor"
;
1514 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1515 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1517 cenum
= [[clist allKeys
] objectEnumerator
];
1518 while ( (name
= [cenum nextObject
]) && new
== nil
)
1520 if ([name compare
: nsname
1521 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1522 new
= [clist colorWithKey
: name
];
1528 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1535 ns_get_color_default
(const
char *name
, NSColor
*dflt
)
1536 /* --------------------------------------------------------------------------
1537 Parse a color or use a default value
1538 -------------------------------------------------------------------------- */
1542 if (ns_get_color
(name
, &col
))
1550 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1551 /* --------------------------------------------------------------------------
1552 Convert a Lisp string object to a NS color
1553 -------------------------------------------------------------------------- */
1555 NSTRACE
(ns_lisp_to_color
);
1556 if (STRINGP
(color
))
1557 return ns_get_color
(SDATA
(color
), col
);
1558 else if (SYMBOLP
(color
))
1559 return ns_get_color
(SDATA
(SYMBOL_NAME
(color
)), col
);
1565 ns_color_to_lisp
(NSColor
*col
)
1566 /* --------------------------------------------------------------------------
1567 Convert a color to a lisp string with the RGB equivalent
1568 -------------------------------------------------------------------------- */
1570 CGFloat red
, green
, blue
, alpha
, gray;
1573 NSTRACE
(ns_color_to_lisp
);
1576 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1578 if ((str
=[[col colorNameComponent
] UTF8String
]))
1581 return build_string
((char *)str
);
1584 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1585 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1586 if (red
==green
&& red
==blue
)
1588 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1589 getWhite
: &gray alpha
: &alpha
];
1590 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1591 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1593 return build_string
(buf
);
1596 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1597 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1600 return build_string
(buf
);
1605 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1606 /* --------------------------------------------------------------------------
1607 Get ARGB values out of NSColor col and put them into color_def.
1608 If setPixel, set the pixel to a concatenated version.
1609 and set color_def pixel to the resulting index.
1610 -------------------------------------------------------------------------- */
1614 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1615 color_def
->red
= r
* 65535;
1616 color_def
->green
= g
* 65535;
1617 color_def
->blue
= b
* 65535;
1619 if (setPixel
== YES
)
1621 = ARGB_TO_ULONG
((int
)(a
*255),
1622 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1627 ns_defined_color
(struct frame
*f
,
1632 /* --------------------------------------------------------------------------
1633 Return 1 if named color found, and set color_def rgb accordingly.
1634 If makeIndex and alloc are nonzero put the color in the color_table,
1635 and set color_def pixel to the resulting index.
1636 If makeIndex is zero, set color_def pixel to ARGB.
1637 Return 0 if not found
1638 -------------------------------------------------------------------------- */
1641 NSTRACE
(ns_defined_color
);
1644 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1649 if (makeIndex
&& alloc
)
1650 color_def
->pixel
= ns_index_color
(col
, f
);
1651 ns_query_color
(col
, color_def
, !makeIndex
);
1658 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1659 /* --------------------------------------------------------------------------
1660 return an autoreleased RGB color
1661 -------------------------------------------------------------------------- */
1663 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1664 if (r
< 0.0) r
= 0.0;
1665 else if (r
> 1.0) r
= 1.0;
1666 if (g
< 0.0) g
= 0.0;
1667 else if (g
> 1.0) g
= 1.0;
1668 if (b
< 0.0) b
= 0.0;
1669 else if (b
> 1.0) b
= 1.0;
1670 if (a
< 0.0) a
= 0.0;
1671 else if (a
> 1.0) a
= 1.0;
1672 return (unsigned
long) ns_index_color
(
1673 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1678 x_set_frame_alpha
(struct frame
*f
)
1679 /* --------------------------------------------------------------------------
1680 change the entire-frame transparency
1681 -------------------------------------------------------------------------- */
1683 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1684 EmacsView
*view = FRAME_NS_VIEW
(f
);
1686 double alpha_min
= 1.0;
1688 if (dpyinfo
->x_highlight_frame
== f
)
1689 alpha
= f
->alpha
[0];
1691 alpha
= f
->alpha
[1];
1693 if (FLOATP
(Vframe_alpha_lower_limit
))
1694 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1695 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1696 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1700 else if (1.0 < alpha
)
1702 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1705 #ifdef NS_IMPL_COCOA
1706 [[view window
] setAlphaValue
: alpha
];
1711 /* ==========================================================================
1715 ========================================================================== */
1719 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1720 /* --------------------------------------------------------------------------
1721 Programmatically reposition mouse pointer in pixel coordinates
1722 -------------------------------------------------------------------------- */
1724 NSTRACE
(x_set_mouse_pixel_position
);
1727 /* FIXME: this does not work, and what about GNUstep? */
1728 #ifdef NS_IMPL_COCOA
1729 [FRAME_NS_VIEW
(f
) lockFocus
];
1730 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1731 [FRAME_NS_VIEW
(f
) unlockFocus
];
1738 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1739 /* --------------------------------------------------------------------------
1740 Programmatically reposition mouse pointer in character coordinates
1741 -------------------------------------------------------------------------- */
1745 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1746 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1748 if (pix_x
< 0) pix_x
= 0;
1749 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1751 if (pix_y
< 0) pix_y
= 0;
1752 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1754 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1759 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1760 /* ------------------------------------------------------------------------
1761 Called by EmacsView on mouseMovement events. Passes on
1762 to emacs mainstream code if we moved off of a rect of interest
1763 known as last_mouse_glyph.
1764 ------------------------------------------------------------------------ */
1766 // NSTRACE
(note_mouse_movement
);
1768 XSETFRAME
(last_mouse_motion_frame
, frame
);
1770 /* Note, this doesn't get called for enter/leave, since we don't have a
1771 position. Those are taken care of in the corresponding NSView methods. */
1773 /* has movement gone beyond last rect we were tracking? */
1774 if (x
< last_mouse_glyph.origin.x ||
1775 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1776 y
< last_mouse_glyph.origin.y ||
1777 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1779 ns_update_begin
(frame
);
1780 frame
->mouse_moved
= 1;
1781 note_mouse_highlight
(frame
, x
, y
);
1782 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1783 ns_update_end
(frame
);
1792 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1793 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1795 /* --------------------------------------------------------------------------
1796 External (hook): inform emacs about mouse position and hit parts.
1797 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1798 x & y should be position in the scrollbar (the whole bar, not the handle)
1799 and length of scrollbar respectively
1800 -------------------------------------------------------------------------- */
1805 Lisp_Object frame
, tail
;
1807 struct ns_display_info
*dpyinfo
;
1809 NSTRACE
(ns_mouse_position
);
1813 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1817 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1821 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1823 /* TODO: we do not use this path at the moment because drag events will
1824 go directly to the EmacsScroller. Leaving code in for now. */
1825 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1827 if (time
) *time
= last_mouse_movement_time
;
1828 last_mouse_scroll_bar
= nil
;
1832 /* Clear the mouse-moved flag for every frame on this display. */
1833 FOR_EACH_FRAME
(tail
, frame
)
1834 if (FRAME_NS_P
(XFRAME
(frame
))
1835 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1836 XFRAME
(frame
)->mouse_moved
= 0;
1838 last_mouse_scroll_bar
= nil
;
1839 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1840 f
= last_mouse_frame
;
1842 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1843 : SELECTED_FRAME
();
1845 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1847 view = FRAME_NS_VIEW
(*fp
);
1849 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1850 position
= [view convertPoint
: position fromView
: nil
];
1851 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1852 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1854 if (bar_window
) *bar_window
= Qnil
;
1855 if (part
) *part
= 0; /*scroll_bar_handle; */
1857 if (x
) XSETINT
(*x
, lrint
(position.x
));
1858 if (y
) XSETINT
(*y
, lrint
(position.y
));
1859 if (time
) *time
= last_mouse_movement_time
;
1869 ns_frame_up_to_date
(struct frame
*f
)
1870 /* --------------------------------------------------------------------------
1871 External (hook): Fix up mouse highlighting right after a full update.
1872 Some highlighting was deferred if GC was happening during
1873 note_mouse_highlight (), while other highlighting was deferred for update.
1874 -------------------------------------------------------------------------- */
1876 NSTRACE
(ns_frame_up_to_date
);
1880 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1881 if ((hlinfo
->mouse_face_deferred_gc || f
==hlinfo
->mouse_face_mouse_frame
)
1882 /*&& hlinfo->mouse_face_mouse_frame*/)
1886 if (hlinfo
->mouse_face_mouse_frame
)
1887 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1888 hlinfo
->mouse_face_mouse_x
,
1889 hlinfo
->mouse_face_mouse_y
);
1890 hlinfo
->mouse_face_deferred_gc
= 0;
1899 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1900 /* --------------------------------------------------------------------------
1901 External (RIF): set frame mouse pointer type.
1902 -------------------------------------------------------------------------- */
1904 NSTRACE
(ns_define_frame_cursor
);
1905 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1907 EmacsView
*view = FRAME_NS_VIEW
(f
);
1908 FRAME_POINTER_TYPE
(f
) = cursor
;
1909 [[view window
] invalidateCursorRectsForView
: view];
1910 /* Redisplay assumes this function also draws the changed frame
1911 cursor, but this function doesn't, so do it explicitly. */
1912 x_update_cursor
(f
, 1);
1918 /* ==========================================================================
1922 ========================================================================== */
1926 ns_convert_key
(unsigned code
)
1927 /* --------------------------------------------------------------------------
1928 Internal call used by NSView-keyDown.
1929 -------------------------------------------------------------------------- */
1931 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1932 / sizeof
(convert_ns_to_X_keysym
[0]));
1934 /* An array would be faster, but less easy to read. */
1935 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1936 if (code
== convert_ns_to_X_keysym
[keysym
])
1937 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1939 /* if decide to use keyCode and Carbon table, use this line:
1940 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1945 x_get_keysym_name
(int keysym
)
1946 /* --------------------------------------------------------------------------
1947 Called by keyboard.c. Not sure if the return val is important, except
1949 -------------------------------------------------------------------------- */
1951 static
char value
[16];
1952 NSTRACE
(x_get_keysym_name
);
1953 sprintf (value
, "
%d", keysym);
1959 /* ==========================================================================
1961 Block drawing operations
1963 ========================================================================== */
1967 ns_redraw_scroll_bars
(struct frame
*f
)
1971 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1972 NSTRACE
(ns_judge_scroll_bars
);
1973 for (i
=[subviews count
]-1; i
>= 0; i
--)
1975 view = [subviews objectAtIndex
: i
];
1976 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
1983 ns_clear_frame
(struct frame
*f
)
1984 /* --------------------------------------------------------------------------
1985 External (hook): Erase the entire frame
1986 -------------------------------------------------------------------------- */
1988 NSView
*view = FRAME_NS_VIEW
(f
);
1991 NSTRACE
(ns_clear_frame
);
1995 /* comes on initial frame because we have
1996 after-make-frame-functions = select-frame */
1997 if (!FRAME_DEFAULT_FACE
(f
))
2000 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
2002 output_cursor.hpos
= output_cursor.vpos
= 0;
2003 output_cursor.x
= -1;
2008 ns_focus
(f
, &r
, 1);
2009 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
2013 #ifdef NS_IMPL_COCOA
2014 [[view window
] display
]; /* redraw resize handle */
2017 /* as of 2006/11 or so this is now needed */
2018 ns_redraw_scroll_bars
(f
);
2024 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
2025 /* --------------------------------------------------------------------------
2026 External (RIF): Clear section of frame
2027 -------------------------------------------------------------------------- */
2029 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
2030 NSView
*view = FRAME_NS_VIEW
(f
);
2031 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
2036 NSTRACE
(ns_clear_frame_area
);
2038 r
= NSIntersectionRect
(r
, [view frame
]);
2039 ns_focus
(f
, &r
, 1);
2040 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
2042 #ifdef NS_IMPL_COCOA
2044 /* clip out the resize handle */
2045 NSWindow
*window
= [FRAME_NS_VIEW
(f
) window
];
2047 = [view convertRect
: ns_resize_handle_rect
(window
) fromView
: nil
];
2049 ir
= NSIntersectionRect
(r
, ir
);
2050 if (NSIsEmptyRect
(ir
))
2056 #ifdef NS_IMPL_COCOA
2060 NSRect r1
= r
, r2
= r
; /* upper and lower non-intersecting */
2061 r1.
size.height
-= ir.
size.height
;
2062 r2.origin.y
+= r1.
size.height
;
2063 r2.
size.width
-= ir.
size.width
;
2064 r2.
size.height
= ir.
size.height
;
2077 ns_scroll_run
(struct window
*w
, struct run
*run
)
2078 /* --------------------------------------------------------------------------
2079 External (RIF): Insert or delete n lines at line vpos
2080 -------------------------------------------------------------------------- */
2082 struct frame
*f
= XFRAME
(w
->frame
);
2083 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2085 NSTRACE
(ns_scroll_run
);
2087 /* begin copy from other terms */
2088 /* Get frame-relative bounding box of the text display area of W,
2089 without mode lines. Include in this box the left and right
2091 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2093 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2094 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2095 bottom_y
= y
+ height
;
2099 /* Scrolling up. Make sure we don't copy part of the mode
2100 line at the bottom. */
2101 if (from_y
+ run
->height
> bottom_y
)
2102 height
= bottom_y
- from_y
;
2104 height
= run
->height
;
2108 /* Scrolling down. Make sure we don't copy over the mode line.
2110 if (to_y
+ run
->height
> bottom_y
)
2111 height
= bottom_y
- to_y
;
2113 height
= run
->height
;
2115 /* end copy from other terms */
2126 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2127 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2128 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2130 ns_focus
(f
, &dstRect
, 1);
2131 NSCopyBits
(0, srcRect
, dstOrigin
);
2140 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2141 /* --------------------------------------------------------------------------
2142 External (RIF): preparatory to fringe update after text was updated
2143 -------------------------------------------------------------------------- */
2145 struct window
*w
= updated_window
;
2149 NSTRACE
(ns_after_update_window_line
);
2151 /* begin copy from other terms */
2154 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2155 desired_row
->redraw_fringe_bitmaps_p
= 1;
2157 /* When a window has disappeared, make sure that no rest of
2158 full-width rows stays visible in the internal border.
2159 Under NS this is drawn inside the fringes. */
2160 if (windows_or_buffers_changed
2161 && (f
= XFRAME
(w
->frame
),
2162 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2164 && (height
= desired_row
->visible_height
,
2167 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2169 /* Internal border is drawn below the tool bar. */
2170 if (WINDOWP
(f
->tool_bar_window
)
2171 && w
== XWINDOW
(f
->tool_bar_window
))
2173 /* end copy from other terms */
2176 if (!desired_row
->full_width_p
)
2178 int x1
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2179 + WINDOW_LEFT_FRINGE_WIDTH
(w
);
2180 int x2
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2181 + FRAME_PIXEL_WIDTH
(f
) - NS_SCROLL_BAR_WIDTH
(f
)
2182 - WINDOW_RIGHT_FRINGE_WIDTH
(w
)
2183 - FRAME_INTERNAL_BORDER_WIDTH
(f
);
2184 ns_clear_frame_area
(f
, x1
, y
, width
, height
);
2185 ns_clear_frame_area
(f
, x2
, y
, width
, height
);
2193 ns_shift_glyphs_for_insert
(struct frame
*f
,
2194 int x
, int y
, int width
, int height
,
2196 /* --------------------------------------------------------------------------
2197 External (RIF): copy an area horizontally, don't worry about clearing src
2198 -------------------------------------------------------------------------- */
2200 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2201 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2202 NSPoint dstOrigin
= dstRect.origin
;
2204 NSTRACE
(ns_shift_glyphs_for_insert
);
2206 ns_focus
(f
, &dstRect
, 1);
2207 NSCopyBits
(0, srcRect
, dstOrigin
);
2213 /* ==========================================================================
2215 Character encoding and metrics
2217 ========================================================================== */
2221 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2222 /* --------------------------------------------------------------------------
2223 External (RIF); compute left/right overhang of whole string and set in s
2224 -------------------------------------------------------------------------- */
2226 struct face
*face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2227 struct font
*font
= s
->font
; /*face->font; */
2231 struct font_metrics metrics
;
2232 unsigned int codes
[2];
2233 codes
[0] = *(s
->char2b
);
2234 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2236 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2237 s
->left_overhang
= -metrics.lbearing
;
2239 = metrics.rbearing
> metrics.width
2240 ? metrics.rbearing
- metrics.width
: 0;
2244 s
->left_overhang
= 0;
2245 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2246 FONT_HEIGHT
(font
) * 0.2 : 0;
2252 /* ==========================================================================
2254 Fringe and cursor drawing
2256 ========================================================================== */
2259 extern int max_used_fringe_bitmap
;
2261 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2262 struct draw_fringe_bitmap_params
*p
)
2263 /* --------------------------------------------------------------------------
2264 External (RIF); fringe-related
2265 -------------------------------------------------------------------------- */
2267 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2268 struct face
*face
= p
->face
;
2270 static EmacsImage
**bimgs
= NULL;
2271 static int nBimgs
= 0;
2272 /* NS-specific: move internal border inside fringe */
2273 int x
= p
->bx
< 0 ? p
->x
: p
->bx
;
2274 int wd
= p
->bx
< 0 ? p
->wd
: p
->nx
;
2275 BOOL fringeOnVeryLeft
2276 = x
- WINDOW_LEFT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
)
2277 - FRAME_INTERNAL_BORDER_WIDTH
(f
) < 10;
2278 BOOL fringeOnVeryRight
2279 = FRAME_PIXEL_WIDTH
(f
) - x
- wd
- FRAME_INTERNAL_BORDER_WIDTH
(f
)
2280 - WINDOW_RIGHT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
) < 10;
2281 int xAdjust
= FRAME_INTERNAL_BORDER_WIDTH
(f
) *
2282 (fringeOnVeryLeft ?
-1 : (fringeOnVeryRight ?
1 : 0));
2284 /* grow bimgs if needed */
2285 if (nBimgs
< max_used_fringe_bitmap
)
2287 EmacsImage
**newBimgs
2288 = xmalloc
(max_used_fringe_bitmap
* sizeof
(EmacsImage
*));
2289 memset
(newBimgs
, 0, max_used_fringe_bitmap
* sizeof
(EmacsImage
*));
2293 memcpy
(newBimgs
, bimgs
, nBimgs
* sizeof
(EmacsImage
*));
2298 nBimgs
= max_used_fringe_bitmap
;
2301 /* Must clip because of partially visible lines. */
2302 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2303 ns_clip_to_row
(w
, row
, -1, YES
);
2305 if (p
->bx
>= 0 && !p
->overlay_p
)
2307 int yAdjust
= rowY
- FRAME_INTERNAL_BORDER_WIDTH
(f
) < 5 ?
2308 -FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0;
2309 int yIncr
= FRAME_PIXEL_HEIGHT
(f
) - (p
->by
+yAdjust
+ p
->ny
) < 5 ?
2310 FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0
2311 + (yAdjust ? FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0);
2312 NSRect r
= NSMakeRect
(p
->bx
+xAdjust
, p
->by
+yAdjust
, p
->nx
, p
->ny
+yIncr
);
2314 [ns_lookup_indexed_color
(face
->background
, f
) set];
2320 NSRect r
= NSMakeRect
(p
->x
+xAdjust
, p
->y
, p
->wd
, p
->h
);
2321 NSPoint pt
= r.origin
;
2322 EmacsImage
*img
= bimgs
[p
->which - 1];
2326 unsigned short
*bits
= p
->bits
+ p
->dh
;
2329 unsigned
char *cbits
= xmalloc
(len
);
2331 for (i
=0; i
<len
; i
++)
2332 cbits
[i
] = ~
(bits
[i
] & 0xff);
2333 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2335 bimgs
[p
->which - 1] = img
;
2340 /* Since we composite the bitmap instead of just blitting it, we need
2341 to erase the whole background. */
2342 [ns_lookup_indexed_color
(face
->background
, f
) set];
2345 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2346 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2353 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2354 int x
, int y
, int cursor_type
, int cursor_width
,
2355 int on_p
, int active_p
)
2356 /* --------------------------------------------------------------------------
2357 External call (RIF): draw cursor.
2358 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2359 -------------------------------------------------------------------------- */
2362 int fx
, fy
, h
, cursor_height
;
2363 struct frame
*f
= WINDOW_XFRAME
(w
);
2364 struct glyph
*phys_cursor_glyph
;
2366 struct glyph
*cursor_glyph
;
2368 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2370 /* If cursor is out of bounds, don't draw garbage. This can happen
2371 in mini-buffer windows when switching between echo area glyphs
2374 NSTRACE
(dumpcursor
);
2379 w
->phys_cursor_type
= cursor_type
;
2380 w
->phys_cursor_on_p
= on_p
;
2382 if (cursor_type
== NO_CURSOR
)
2384 w
->phys_cursor_width
= 0;
2388 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2390 if (glyph_row
->exact_window_width_line_p
2391 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2393 glyph_row
->cursor_in_fringe_p
= 1;
2394 draw_fringe_bitmap
(w
, glyph_row
, 0);
2399 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2400 (other terminals do it the other way round). We must set
2401 w->phys_cursor_width to the cursor width. For bar cursors, that
2402 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2403 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2405 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2406 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2407 if (cursor_type
== BAR_CURSOR
)
2409 if (cursor_width
< 1)
2410 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2411 w
->phys_cursor_width
= cursor_width
;
2413 /* If we have an HBAR, "cursor_width" MAY specify height. */
2414 else if (cursor_type
== HBAR_CURSOR
)
2416 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2417 fy
+= h
- cursor_height
;
2421 r.origin.x
= fx
, r.origin.y
= fy
;
2423 r.
size.width
= w
->phys_cursor_width
;
2425 /* FIXME: if we overwrite the internal border area, it does not get erased;
2426 fix by truncating cursor, but better would be to erase properly */
2427 overspill
= r.origin.x
+ r.
size.width
-
2428 WINDOW_TEXT_TO_FRAME_PIXEL_X
(w
, WINDOW_BOX_RIGHT_EDGE_X
(w
)
2429 - WINDOW_TOTAL_FRINGE_WIDTH
(w
) - FRAME_INTERNAL_BORDER_WIDTH
(f
));
2431 r.
size.width
-= overspill
;
2433 /* TODO: only needed in rare cases with last-resort font in HELLO..
2434 should we do this more efficiently? */
2435 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2438 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2439 if (face
&& NS_FACE_BACKGROUND
(face
)
2440 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2442 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2443 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2446 [FRAME_CURSOR_COLOR
(f
) set];
2448 #ifdef NS_IMPL_COCOA
2449 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2450 atomic. Cleaner ways of doing this should be investigated.
2451 One way would be to set a global variable DRAWING_CURSOR
2452 when making the call to draw_phys..(), don't focus in that
2453 case, then move the ns_unfocus() here after that call. */
2454 NSDisableScreenUpdates
();
2457 switch (cursor_type
)
2461 case FILLED_BOX_CURSOR
:
2464 case HOLLOW_BOX_CURSOR
:
2467 NSRectFill
(NSInsetRect
(r
, 1, 1));
2468 [FRAME_CURSOR_COLOR
(f
) set];
2475 /* If the character under cursor is R2L, draw the bar cursor
2476 on the right of its glyph, rather than on the left. */
2477 cursor_glyph
= get_phys_cursor_glyph
(w
);
2478 if ((cursor_glyph
->resolved_level
& 1) != 0)
2479 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2486 /* draw the character under the cursor */
2487 if (cursor_type
!= NO_CURSOR
)
2488 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2490 #ifdef NS_IMPL_COCOA
2491 NSEnableScreenUpdates
();
2498 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2499 /* --------------------------------------------------------------------------
2500 External (RIF): Draw a vertical line.
2501 -------------------------------------------------------------------------- */
2503 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2505 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2507 NSTRACE
(ns_draw_vertical_window_border
);
2509 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2511 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2513 ns_focus
(f
, &r
, 1);
2520 show_hourglass
(struct atimer
*timer
)
2522 if (hourglass_shown_p
)
2527 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2529 hourglass_shown_p
= 1;
2535 hide_hourglass
(void
)
2537 if (!hourglass_shown_p
)
2542 /* TODO: remove NSProgressIndicator from all frames */
2544 hourglass_shown_p
= 0;
2550 /* ==========================================================================
2552 Glyph drawing operations
2554 ========================================================================== */
2557 static inline NSRect
2558 ns_fix_rect_ibw
(NSRect r
, int fibw
, int frame_pixel_width
)
2559 /* --------------------------------------------------------------------------
2560 Under NS we draw internal borders inside fringes, and want full-width
2561 rendering to go all the way to edge. This function makes that correction.
2562 -------------------------------------------------------------------------- */
2564 if (r.origin.y
<= fibw
+1)
2566 r.
size.height
+= r.origin.y
;
2569 if (r.origin.x
<= fibw
+1)
2571 r.
size.width
+= r.origin.x
;
2574 if (frame_pixel_width
- (r.origin.x
+r.
size.width
) <= fibw
+1)
2575 r.
size.width
+= fibw
;
2582 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2583 /* --------------------------------------------------------------------------
2584 Wrapper utility to account for internal border width on full-width lines,
2585 and allow top full-width rows to hit the frame top. nr should be pointer
2586 to two successive NSRects. Number of rects actually used is returned.
2587 -------------------------------------------------------------------------- */
2589 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2590 if (s
->row
->full_width_p
)
2592 *nr
= ns_fix_rect_ibw
(*nr
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2593 FRAME_PIXEL_WIDTH
(s
->f
));
2595 *nr
= ns_fix_rect_ibw
(*(nr
+1), FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2596 FRAME_PIXEL_WIDTH
(s
->f
));
2602 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2603 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2604 /* --------------------------------------------------------------------------
2605 Draw underline, overline, and strike-through on glyph string s.
2606 -------------------------------------------------------------------------- */
2608 if (s
->for_overlaps
)
2612 if (face
->underline_p
)
2615 unsigned
long thickness
, position
;
2617 /* If the prev was underlined, match its appearance. */
2618 if (s
->prev
&& s
->prev
->face
->underline_p
2619 && s
->prev
->underline_thickness
> 0)
2621 thickness
= s
->prev
->underline_thickness
;
2622 position
= s
->prev
->underline_position
;
2627 unsigned
long descent
;
2630 descent
= s
->y
+ s
->height
- s
->ybase
;
2632 /* Use underline thickness of font, defaulting to 1. */
2633 thickness
= (font
&& font
->underline_thickness
> 0)
2634 ? font
->underline_thickness
: 1;
2636 /* Determine the offset of underlining from the baseline. */
2637 if (x_underline_at_descent_line
)
2638 position
= descent
- thickness
;
2639 else if (x_use_underline_position_properties
2640 && font
&& font
->underline_position
>= 0)
2641 position
= font
->underline_position
;
2643 position
= lround
(font
->descent
/ 2);
2645 position
= underline_minimum_offset
;
2647 position
= max (position
, underline_minimum_offset
);
2649 /* Ensure underlining is not cropped. */
2650 if (descent
<= position
)
2652 position
= descent
- 1;
2655 else if (descent
< position
+ thickness
)
2659 s
->underline_thickness
= thickness
;
2660 s
->underline_position
= position
;
2662 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2664 if (face
->underline_defaulted_p
)
2667 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2671 /* Do overline. We follow other terms in using a thickness of 1
2672 and ignoring overline_margin. */
2673 if (face
->overline_p
)
2676 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2678 if (face
->overline_color_defaulted_p
)
2681 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2685 /* Do strike-through. We follow other terms for thickness and
2686 vertical position.*/
2687 if (face
->strike_through_p
)
2692 dy
= lrint
((s
->height
- 1) / 2);
2693 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2695 if (face
->strike_through_color_defaulted_p
)
2698 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2704 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2705 /* --------------------------------------------------------------------------
2706 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2707 Note we can't just use an NSDrawRect command, because of the possibility
2708 of some sides not being drawn, and because the rect will be filled.
2709 -------------------------------------------------------------------------- */
2715 s.
size.height
= thickness
;
2717 s.origin.y
+= r.
size.height
- thickness
;
2720 s.
size.height
= r.
size.height
;
2721 s.origin.y
= r.origin.y
;
2723 /* left, right (optional) */
2724 s.
size.width
= thickness
;
2729 s.origin.x
+= r.
size.width
- thickness
;
2736 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2737 char top_p
, char bottom_p
, char left_p
, char right_p
,
2738 struct glyph_string
*s
)
2739 /* --------------------------------------------------------------------------
2740 Draw a relief rect inside r, optionally leaving some sides open.
2741 Note we can't just use an NSDrawBezel command, because of the possibility
2742 of some sides not being drawn, and because the rect will be filled.
2743 -------------------------------------------------------------------------- */
2745 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2746 NSColor
*newBaseCol
= nil
;
2749 NSTRACE
(ns_draw_relief
);
2753 if (s
->face
->use_box_color_for_shadows_p
)
2755 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2757 /* else if (s->first_glyph->type == IMAGE_GLYPH
2759 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2761 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2765 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2768 if (newBaseCol
== nil
)
2769 newBaseCol
= [NSColor grayColor
];
2771 if (newBaseCol
!= baseCol
) /* TODO: better check */
2774 baseCol
= [newBaseCol retain
];
2776 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2778 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2781 [(raised_p ? lightCol
: darkCol
) set];
2783 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2786 sr.
size.height
= thickness
;
2787 if (top_p
) NSRectFill
(sr
);
2790 sr.
size.height
= r.
size.height
;
2791 sr.
size.width
= thickness
;
2792 if (left_p
) NSRectFill
(sr
);
2794 [(raised_p ? darkCol
: lightCol
) set];
2797 sr.
size.width
= r.
size.width
;
2798 sr.
size.height
= thickness
;
2799 sr.origin.y
+= r.
size.height
- thickness
;
2800 if (bottom_p
) NSRectFill
(sr
);
2803 sr.
size.height
= r.
size.height
;
2804 sr.origin.y
= r.origin.y
;
2805 sr.
size.width
= thickness
;
2806 sr.origin.x
+= r.
size.width
- thickness
;
2807 if (right_p
) NSRectFill
(sr
);
2812 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2813 /* --------------------------------------------------------------------------
2814 Function modeled after x_draw_glyph_string_box ().
2815 Sets up parameters for drawing.
2816 -------------------------------------------------------------------------- */
2818 int right_x
, last_x
;
2819 char left_p
, right_p
;
2820 struct glyph
*last_glyph
;
2825 if (s
->hl
== DRAW_MOUSE_FACE
)
2827 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2829 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2834 thickness
= face
->box_line_width
;
2836 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2838 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2839 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2840 : window_box_right
(s
->w
, s
->area
));
2841 last_glyph
= (s
->cmp || s
->img
2842 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2844 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2845 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2847 left_p
= (s
->first_glyph
->left_box_line_p
2848 ||
(s
->hl
== DRAW_MOUSE_FACE
2849 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2850 right_p
= (last_glyph
->right_box_line_p
2851 ||
(s
->hl
== DRAW_MOUSE_FACE
2852 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2854 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2856 /* expand full-width row over internal borders */
2857 if (s
->row
->full_width_p
)
2858 r
= ns_fix_rect_ibw
(r
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2859 FRAME_PIXEL_WIDTH
(s
->f
));
2861 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2862 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2864 ns_draw_box
(r
, abs (thickness
),
2865 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2870 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2871 1, 1, left_p
, right_p
, s
);
2877 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2878 /* --------------------------------------------------------------------------
2879 Modeled after x_draw_glyph_string_background, which draws BG in
2880 certain cases. Others are left to the text rendering routine.
2881 -------------------------------------------------------------------------- */
2883 NSTRACE
(ns_maybe_dumpglyphs_background
);
2885 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2887 int box_line_width
= max (s
->face
->box_line_width
, 0);
2888 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2889 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2892 if (s
->hl
== DRAW_MOUSE_FACE
)
2894 face
= FACE_FROM_ID
(s
->f
,
2895 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2897 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2900 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2902 [(NS_FACE_BACKGROUND
(face
) != 0
2903 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2904 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2907 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2908 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2911 if (s
->hl
!= DRAW_CURSOR
)
2913 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2914 s
->background_width
,
2915 s
->height
-2*box_line_width
);
2917 /* expand full-width row over internal borders */
2918 if (s
->row
->full_width_p
)
2920 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
2921 if (r.origin.y
<= fibw
+1 + box_line_width
)
2923 r.
size.height
+= r.origin.y
;
2926 if (r.origin.x
<= fibw
+1)
2928 r.
size.width
+= 2*r.origin.x
;
2931 if (FRAME_PIXEL_WIDTH
(s
->f
) - (r.origin.x
+ r.
size.width
)
2933 r.
size.width
+= fibw
;
2939 s
->background_filled_p
= 1;
2946 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2947 /* --------------------------------------------------------------------------
2948 Renders an image and associated borders.
2949 -------------------------------------------------------------------------- */
2951 EmacsImage
*img
= s
->img
->pixmap
;
2952 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2953 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2954 int bg_x
, bg_y
, bg_height
;
2961 NSTRACE
(ns_dumpglyphs_image
);
2963 if (s
->face
->box
!= FACE_NO_BOX
2964 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
2965 x
+= abs (s
->face
->box_line_width
);
2968 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
2969 bg_height
= s
->height
;
2970 /* other terms have this, but was causing problems w/tabbar mode */
2971 /* - 2 * box_line_vwidth; */
2973 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
2974 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
2976 /* Draw BG: if we need larger area than image itself cleared, do that,
2977 otherwise, since we composite the image under NS (instead of mucking
2978 with its background color), we must clear just the image area. */
2979 if (s
->hl
== DRAW_MOUSE_FACE
)
2981 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2983 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2986 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2988 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
2990 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
2991 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
2993 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
2994 s
->background_filled_p
= 1;
2998 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3001 /* expand full-width row over internal borders */
3002 if (s
->row
->full_width_p
)
3004 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
3005 if (br.origin.y
<= fibw
+1 + box_line_vwidth
)
3007 br.
size.height
+= br.origin.y
;
3010 if (br.origin.x
<= fibw
+1 + box_line_vwidth
)
3012 br.
size.width
+= br.origin.x
;
3015 if (FRAME_PIXEL_WIDTH
(s
->f
) - (br.origin.x
+ br.
size.width
) <= fibw
+1)
3016 br.
size.width
+= fibw
;
3021 /* Draw the image.. do we need to draw placeholder if img ==nil? */
3023 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
3024 operation
: NSCompositeSourceOver
];
3026 if (s
->hl
== DRAW_CURSOR
)
3028 [FRAME_CURSOR_COLOR
(s
->f
) set];
3029 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3030 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3032 /* Currently on NS img->mask is always 0. Since
3033 get_window_cursor_type specifies a hollow box cursor when on
3034 a non-masked image we never reach this clause. But we put it
3035 in in anticipation of better support for image masks on
3037 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3041 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3044 /* Draw underline, overline, strike-through. */
3045 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3047 /* Draw relief, if requested */
3048 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3050 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3052 th
= tool_bar_button_relief
>= 0 ?
3053 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3054 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3058 th
= abs (s
->img
->relief
);
3059 raised_p
= (s
->img
->relief
> 0);
3062 r.origin.x
= x
- th
;
3063 r.origin.y
= y
- th
;
3064 r.
size.width
= s
->slice.width
+ 2*th
-1;
3065 r.
size.height
= s
->slice.height
+ 2*th
-1;
3066 ns_draw_relief
(r
, th
, raised_p
,
3068 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3070 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3073 /* If there is no mask, the background won't be seen,
3074 so draw a rectangle on the image for the cursor.
3075 Do this for all images, getting transparency right is not reliable. */
3076 if (s
->hl
== DRAW_CURSOR
)
3078 int thickness
= abs (s
->img
->relief
);
3079 if (thickness
== 0) thickness
= 1;
3080 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3086 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3091 NSColor
*fgCol
, *bgCol
;
3093 if (!s
->background_filled_p
)
3095 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3096 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3098 ns_focus
(s
->f
, r
, n
);
3100 if (s
->hl
== DRAW_MOUSE_FACE
)
3102 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3104 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3107 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3109 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3110 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3114 if (!s
->row
->full_width_p
)
3116 int overrun
, leftoverrun
;
3118 /* truncate to avoid overwriting fringe and/or scrollbar */
3119 overrun
= max (0, (s
->x
+ s
->background_width
)
3120 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3121 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3122 r
[i
].
size.width
-= overrun
;
3124 /* truncate to avoid overwriting to left of the window box */
3125 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3126 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3128 if (leftoverrun
> 0)
3130 r
[i
].origin.x
+= leftoverrun
;
3131 r
[i
].
size.width
-= leftoverrun
;
3134 /* XXX: Try to work between problem where a stretch glyph on
3135 a partially-visible bottom row will clear part of the
3136 modeline, and another where list-buffers headers and similar
3137 rows erroneously have visible_height set to 0. Not sure
3138 where this is coming from as other terms seem not to show. */
3139 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3142 /* expand full-width rows over internal borders */
3145 r
[i
] = ns_fix_rect_ibw
(r
[i
], FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
3146 FRAME_PIXEL_WIDTH
(s
->f
));
3151 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3152 overwriting cursor (usually when cursor on a tab) */
3153 if (s
->hl
== DRAW_CURSOR
)
3158 width
= s
->w
->phys_cursor_width
;
3159 r
[i
].
size.width
-= width
;
3160 r
[i
].origin.x
+= width
;
3164 /* Draw overlining, etc. on the cursor. */
3165 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3166 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3168 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3175 /* Draw overlining, etc. on the stretch glyph (or the part
3176 of the stretch glyph after the cursor). */
3177 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3181 s
->background_filled_p
= 1;
3187 ns_draw_glyph_string
(struct glyph_string
*s
)
3188 /* --------------------------------------------------------------------------
3189 External (RIF): Main draw-text call.
3190 -------------------------------------------------------------------------- */
3192 /* TODO (optimize): focus for box and contents draw */
3195 char box_drawn_p
= 0;
3197 NSTRACE
(ns_draw_glyph_string
);
3199 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3202 struct glyph_string
*next
;
3204 for (width
= 0, next
= s
->next
;
3205 next
&& width
< s
->right_overhang
;
3206 width
+= next
->width
, next
= next
->next
)
3207 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3209 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3211 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3212 ns_focus
(s
->f
, r
, n
);
3213 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3218 ns_dumpglyphs_stretch
(s
->next
);
3220 next
->num_clips
= 0;
3224 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3225 && (s
->first_glyph
->type == CHAR_GLYPH
3226 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3228 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3229 ns_focus
(s
->f
, r
, n
);
3230 ns_maybe_dumpglyphs_background
(s
, 1);
3231 ns_dumpglyphs_box_or_relief
(s
);
3236 switch (s
->first_glyph
->type)
3240 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3241 ns_focus
(s
->f
, r
, n
);
3242 ns_dumpglyphs_image
(s
, r
[0]);
3247 ns_dumpglyphs_stretch
(s
);
3251 case COMPOSITE_GLYPH
:
3252 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3253 ns_focus
(s
->f
, r
, n
);
3255 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3256 && ! s
->first_glyph
->u.cmp.automatic
))
3257 s
->background_filled_p
= 1;
3259 ns_maybe_dumpglyphs_background
3260 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3262 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3263 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3264 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3265 NS_DUMPGLYPH_NORMAL
));
3266 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3267 if (ns_tmp_font
== NULL)
3268 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3270 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3272 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3273 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3274 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3277 ns_tmp_font
->font.driver
->draw
3278 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3279 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3280 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
3282 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3284 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3285 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3286 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3292 case GLYPHLESS_GLYPH
:
3293 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3294 ns_focus
(s
->f
, r
, n
);
3296 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3297 && ! s
->first_glyph
->u.cmp.automatic
))
3298 s
->background_filled_p
= 1;
3300 ns_maybe_dumpglyphs_background
3301 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3303 /* Not yet implemented. */
3312 /* Draw box if not done already. */
3313 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3315 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3316 ns_focus
(s
->f
, r
, n
);
3317 ns_dumpglyphs_box_or_relief
(s
);
3326 /* ==========================================================================
3330 ========================================================================== */
3334 ns_send_appdefined
(int value
)
3335 /* --------------------------------------------------------------------------
3336 Internal: post an appdefined event which EmacsApp-sendEvent will
3337 recognize and take as a command to halt the event loop.
3338 -------------------------------------------------------------------------- */
3340 /*NSTRACE (ns_send_appdefined); */
3342 /* Only post this event if we haven't already posted one. This will end
3343 the [NXApp run] main loop after having processed all events queued at
3345 if (send_appdefined
)
3349 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3350 send_appdefined
= NO
;
3352 /* Don't need wakeup timer any more */
3355 [timed_entry invalidate
];
3356 [timed_entry release
];
3360 /* Ditto for file descriptor poller */
3363 [fd_entry invalidate
];
3368 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3369 location
: NSMakePoint
(0, 0)
3372 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3373 context
: [NSApp context
]
3378 /* Post an application defined event on the event queue. When this is
3379 received the [NXApp run] will return, thus having processed all
3380 events which are currently queued. */
3381 [NSApp postEvent
: nxev atStart
: NO
];
3387 ns_read_socket
(struct terminal *terminal, int expected
,
3388 struct input_event
*hold_quit
)
3389 /* --------------------------------------------------------------------------
3390 External (hook): Post an event to ourself and keep reading events until
3391 we read it back again. In effect process all events which were waiting.
3392 From 21+ we have to manage the event buffer ourselves.
3393 -------------------------------------------------------------------------- */
3395 struct input_event ev
;
3398 /* NSTRACE (ns_read_socket); */
3400 if ([NSApp modalWindow
] != nil
)
3403 if (interrupt_input_blocked
)
3405 interrupt_input_pending
= 1;
3407 pending_signals
= 1;
3412 interrupt_input_pending
= 0;
3414 pending_signals
= pending_atimers
;
3418 n_emacs_events_pending
= 0;
3421 q_event_ptr
= hold_quit
;
3423 /* we manage autorelease pools by allocate/reallocate each time around
3424 the loop; strict nesting is occasionally violated but seems not to
3425 matter.. earlier methods using full nesting caused major memory leaks */
3426 [outerpool release
];
3427 outerpool
= [[NSAutoreleasePool alloc
] init
];
3429 /* If have pending open-file requests, attend to the next one of those. */
3430 if (ns_pending_files
&& [ns_pending_files count
] != 0
3431 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3433 [ns_pending_files removeObjectAtIndex
: 0];
3435 /* Deal with pending service requests. */
3436 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3438 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3439 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3441 [ns_pending_service_names removeObjectAtIndex
: 0];
3442 [ns_pending_service_args removeObjectAtIndex
: 0];
3446 /* Run and wait for events. We must always send one NX_APPDEFINED event
3447 to ourself, otherwise [NXApp run] will never exit. */
3448 send_appdefined
= YES
;
3450 /* If called via ns_select, this is called once with expected=1,
3451 because we expect either the timeout or file descriptor activity.
3452 In this case the first event through will either be real input or
3453 one of these. read_avail_input() then calls once more with expected=0
3454 and in that case we need to return quickly if there is nothing.
3455 If we're being called outside of that, it's also OK to return quickly
3456 after one iteration through the event loop, since other terms do
3457 this and emacs expects it. */
3458 if (!(inNsSelect
&& expected
))
3460 /* Post an application defined event on the event queue. When this is
3461 received the [NXApp run] will return, thus having processed all
3462 events which are currently queued, if any. */
3463 ns_send_appdefined
(-1);
3469 nevents
= n_emacs_events_pending
;
3470 n_emacs_events_pending
= 0;
3471 emacs_event
= q_event_ptr
= NULL;
3479 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3480 fd_set
*exceptfds
, struct timeval
*timeout
)
3481 /* --------------------------------------------------------------------------
3482 Replacement for select, checking for events
3483 -------------------------------------------------------------------------- */
3488 /* NSTRACE (ns_select); */
3490 if (NSApp
== nil || inNsSelect
== 1 /* || ([NSApp isActive] == NO &&
3491 [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil
3492 inMode:NSDefaultRunLoopMode dequeue:NO] == nil) */)
3493 return select
(nfds
, readfds
, writefds
, exceptfds
, timeout
);
3495 /* Save file descriptor set, which gets overwritten in calls to select ()
3496 Note, this is called from process.c, and only readfds is ever set */
3499 memcpy
(&select_readfds
, readfds
, sizeof
(fd_set
));
3505 /* Try an initial select for pending data on input files */
3506 select_timeout.tv_sec
= select_timeout.tv_usec
= 0;
3507 result
= select
(nfds
, readfds
, writefds
, exceptfds
, &select_timeout
);
3511 /* if (!timeout || timed_entry || fd_entry)
3512 fprintf (stderr, "assertion failed: timeout null or timed_entry/fd_entry non-null in ns_select\n"); */
3514 /* set a timeout and run the main AppKit event loop while continuing
3515 to monitor the files */
3516 time
= ((double) timeout
->tv_sec
) + ((double) timeout
->tv_usec
)/1000000.0;
3517 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3519 selector
: @selector
(timeout_handler
:)
3521 repeats
: YES
] /* for safe removal */
3524 /* set a periodic task to try the select () again */
3525 fd_entry
= [[NSTimer scheduledTimerWithTimeInterval
: 0.1
3527 selector
: @selector
(fd_handler
:)
3532 /* Let Application dispatch events until it receives an event of the type
3533 NX_APPDEFINED, which should only be sent by timeout_handler.
3534 We tell read_avail_input() that input is "expected" because we do expect
3535 either the timeout or fd handler to fire, and if they don't, the original
3536 call from process.c that got us here expects us to wait until some input
3540 ev
= last_appdefined_event
;
3546 if ([ev
type] != NSApplicationDefined
)
3550 last_appdefined_event
= 0;
3554 /* The NX_APPDEFINED event we received was a timeout. */
3559 /* The NX_APPDEFINED event we received was the result of
3560 at least one real input event arriving. */
3566 /* Received back from select () in fd_handler; copy the results */
3568 memcpy
(readfds
, &select_readfds
, sizeof
(fd_set
));
3572 /* never reached, shut compiler up */
3578 /* ==========================================================================
3582 ========================================================================== */
3586 ns_set_vertical_scroll_bar
(struct window
*window
,
3587 int portion
, int whole
, int position
)
3588 /* --------------------------------------------------------------------------
3589 External (hook): Update or add scrollbar
3590 -------------------------------------------------------------------------- */
3594 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3595 EmacsView
*view = FRAME_NS_VIEW
(f
);
3596 int window_y
, window_height
;
3597 BOOL barOnVeryLeft
, barOnVeryRight
;
3598 int top
, left
, height
, width
, sb_width
, sb_left
;
3600 static int count
= 0;
3602 /* optimization; display engine sends WAY too many of these.. */
3603 if (!NILP
(window
->vertical_scroll_bar
))
3605 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3606 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3608 if (view->scrollbarsNeedingUpdate
== 0)
3610 if (!windows_or_buffers_changed
)
3614 view->scrollbarsNeedingUpdate
--;
3618 NSTRACE
(ns_set_vertical_scroll_bar
);
3620 /* Get dimensions. */
3621 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3623 height
= window_height
;
3624 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3625 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3627 if (top
< 5) /* top scrollbar adjustment */
3629 top
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3630 height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3633 /* allow for displaying a skinnier scrollbar than char area allotted */
3634 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3635 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3637 barOnVeryLeft
= left
< 5;
3638 barOnVeryRight
= FRAME_PIXEL_WIDTH
(f
) - left
- width
< 5;
3639 sb_left
= left
+ FRAME_INTERNAL_BORDER_WIDTH
(f
)
3640 * (barOnVeryLeft ?
-1 : (barOnVeryRight ?
1 : 0));
3642 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3643 /* the parent view is flipped, so we need to flip y value */
3645 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3647 XSETWINDOW
(win
, window
);
3650 /* we want at least 5 lines to display a scrollbar */
3651 if (WINDOW_TOTAL_LINES
(window
) < 5)
3653 if (!NILP
(window
->vertical_scroll_bar
))
3655 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3656 [bar removeFromSuperview
];
3657 window
->vertical_scroll_bar
= Qnil
;
3659 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3664 if (NILP
(window
->vertical_scroll_bar
))
3666 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3667 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3668 window
->vertical_scroll_bar
= make_save_value
(bar, 0);
3673 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3674 oldRect
= [bar frame
];
3675 r.
size.width
= oldRect.
size.width
;
3676 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3678 if (oldRect.origin.x
!= r.origin.x
)
3679 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3684 [bar setPosition
: position portion
: portion whole
: whole
];
3690 ns_condemn_scroll_bars
(struct frame
*f
)
3691 /* --------------------------------------------------------------------------
3692 External (hook): arrange for all frame's scrollbars to be removed
3693 at next call to judge_scroll_bars, except for those redeemed.
3694 -------------------------------------------------------------------------- */
3698 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3700 NSTRACE
(ns_condemn_scroll_bars
);
3702 for (i
=[subviews count
]-1; i
>= 0; i
--)
3704 view = [subviews objectAtIndex
: i
];
3705 if ([view isKindOfClass
: [EmacsScroller
class]])
3712 ns_redeem_scroll_bar
(struct window
*window
)
3713 /* --------------------------------------------------------------------------
3714 External (hook): arrange to spare this window's scrollbar
3715 at next call to judge_scroll_bars.
3716 -------------------------------------------------------------------------- */
3719 NSTRACE
(ns_redeem_scroll_bar
);
3720 if (!NILP
(window
->vertical_scroll_bar
))
3722 bar =XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3729 ns_judge_scroll_bars
(struct frame
*f
)
3730 /* --------------------------------------------------------------------------
3731 External (hook): destroy all scrollbars on frame that weren't
3732 redeemed after call to condemn_scroll_bars.
3733 -------------------------------------------------------------------------- */
3737 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3738 NSTRACE
(ns_judge_scroll_bars
);
3739 for (i
=[subviews count
]-1; i
>= 0; i
--)
3741 view = [subviews objectAtIndex
: i
];
3742 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3749 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3751 /* XXX irrelevant under NS */
3756 /* ==========================================================================
3760 ========================================================================== */
3763 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3765 NSScreen
*screen
= [NSScreen mainScreen
];
3766 return [screen frame
].
size.height
;
3770 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3772 NSScreen
*screen
= [NSScreen mainScreen
];
3773 return [screen frame
].
size.width
;
3777 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3778 /* --------------------------------------------------------------------------
3779 Convert modifier name to lisp symbol
3780 -------------------------------------------------------------------------- */
3782 if (!strncmp
(SDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3784 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3786 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3788 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3790 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3792 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3799 static Lisp_Object ns_mod_to_lisp
(int m
)
3800 /* --------------------------------------------------------------------------
3801 Convert modifier code (see lisp.h) to lisp symbol
3802 -------------------------------------------------------------------------- */
3806 else if (m
== CHAR_SUPER
)
3808 else if (m
== CHAR_CTL
)
3810 else if (m
== CHAR_ALT
)
3812 else if (m
== CHAR_HYPER
)
3814 else /* if (m == 0) */
3820 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3821 Lisp_Object yesval
, Lisp_Object noval
,
3822 BOOL is_float
, BOOL is_modstring
)
3823 /* --------------------------------------------------------------------------
3824 Check a parameter value in user's preferences
3825 -------------------------------------------------------------------------- */
3827 const
char *value
= ns_get_defaults_value
(parameter
);
3833 if (strcasecmp
(value
, "YES"
) == 0)
3835 else if (strcasecmp
(value
, "NO"
) == 0)
3837 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3838 *result
= make_float
(f
);
3839 else if (is_modstring
&& value
)
3840 *result
= ns_string_to_lispmod
(value
);
3841 else fprintf (stderr
,
3842 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3848 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3849 /* --------------------------------------------------------------------------
3850 Initialize global info and storage for display.
3851 -------------------------------------------------------------------------- */
3853 NSScreen
*screen
= [NSScreen mainScreen
];
3854 NSWindowDepth depth
= [screen depth
];
3855 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
3857 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3858 dpyinfo
->resy
= 72.27;
3859 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3860 NSColorSpaceFromDepth
(depth
)]
3861 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3862 NSColorSpaceFromDepth
(depth
)];
3863 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3864 dpyinfo
->image_cache
= make_image_cache
();
3865 dpyinfo
->color_table
3866 = (struct ns_color_table
*)xmalloc
(sizeof
(struct ns_color_table
));
3867 dpyinfo
->color_table
->colors
= NULL;
3868 dpyinfo
->root_window
= 42; /* a placeholder.. */
3870 hlinfo
->mouse_face_mouse_frame
= NULL;
3871 hlinfo
->mouse_face_deferred_gc
= 0;
3872 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
3873 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
3874 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3875 hlinfo
->mouse_face_window
= hlinfo
->mouse_face_overlay
= Qnil
;
3876 hlinfo
->mouse_face_hidden
= 0;
3878 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
3879 hlinfo
->mouse_face_defer
= 0;
3881 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3883 dpyinfo
->n_fonts
= 0;
3884 dpyinfo
->smallest_font_height
= 1;
3885 dpyinfo
->smallest_char_width
= 1;
3889 /* This and next define (many of the) public functions in this file. */
3890 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3891 with using despite presence in the "system dependent" redisplay
3892 interface. In addition, many of the ns_ methods have code that is
3893 shared with all terms, indicating need for further refactoring. */
3894 extern frame_parm_handler ns_frame_parm_handlers
[];
3895 static
struct redisplay_interface ns_redisplay_interface
=
3897 ns_frame_parm_handlers
,
3901 x_clear_end_of_line
,
3903 ns_after_update_window_line
,
3904 ns_update_window_begin
,
3905 ns_update_window_end
,
3908 0, /* flush_display_optional */
3909 x_clear_window_mouse_face
,
3910 x_get_glyph_overhangs
,
3911 x_fix_overlapping_area
,
3912 ns_draw_fringe_bitmap
,
3913 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3914 0, /* destroy_fringe_bitmap */
3915 ns_compute_glyph_string_overhangs
,
3916 ns_draw_glyph_string
, /* interface to nsfont.m */
3917 ns_define_frame_cursor
,
3918 ns_clear_frame_area
,
3919 ns_draw_window_cursor
,
3920 ns_draw_vertical_window_border
,
3921 ns_shift_glyphs_for_insert
3926 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3932 /* This function is called when the last frame on a display is deleted. */
3934 ns_delete_terminal
(struct terminal *terminal)
3936 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3939 /* Protect against recursive calls. delete_frame in
3940 delete_terminal calls us back when it deletes our last frame. */
3941 if (!terminal->name
)
3946 x_destroy_all_bitmaps
(dpyinfo
);
3947 ns_delete_display
(dpyinfo
);
3952 static
struct terminal *
3953 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3954 /* --------------------------------------------------------------------------
3955 Set up use of NS before we make the first connection.
3956 -------------------------------------------------------------------------- */
3958 struct terminal *terminal;
3960 NSTRACE
(ns_create_terminal
);
3962 terminal = create_terminal
();
3964 terminal->type = output_ns
;
3965 terminal->display_info.ns
= dpyinfo
;
3966 dpyinfo
->terminal = terminal;
3968 terminal->rif
= &ns_redisplay_interface
;
3970 terminal->clear_frame_hook
= ns_clear_frame
;
3971 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
3972 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
3973 terminal->ring_bell_hook
= ns_ring_bell
;
3974 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
3975 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
3976 terminal->update_begin_hook
= ns_update_begin
;
3977 terminal->update_end_hook
= ns_update_end
;
3978 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
3979 terminal->read_socket_hook
= ns_read_socket
;
3980 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
3981 terminal->mouse_position_hook
= ns_mouse_position
;
3982 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
3983 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
3985 terminal->fullscreen_hook
= 0; /* see XTfullscreen_hook */
3987 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
3988 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
3989 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
3990 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
3992 terminal->delete_frame_hook
= x_destroy_window
;
3993 terminal->delete_terminal_hook
= ns_delete_terminal
;
3995 terminal->scroll_region_ok
= 1;
3996 terminal->char_ins_del_ok
= 1;
3997 terminal->line_ins_del_ok
= 1;
3998 terminal->fast_clear_end_of_line
= 1;
3999 terminal->memory_below_frame
= 0;
4005 struct ns_display_info
*
4006 ns_term_init
(Lisp_Object display_name
)
4007 /* --------------------------------------------------------------------------
4008 Start the Application and get things rolling.
4009 -------------------------------------------------------------------------- */
4011 struct terminal *terminal;
4012 struct ns_display_info
*dpyinfo
;
4013 static int ns_initialized
= 0;
4016 NSTRACE
(ns_term_init
);
4018 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
4019 /*GSDebugAllocationActive (YES); */
4021 handling_signal
= 0;
4023 if (!ns_initialized
)
4026 Fset_input_interrupt_mode
(Qnil
);
4030 ns_pending_files
= [[NSMutableArray alloc
] init
];
4031 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
4032 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
4034 /* Start app and create the main menu, window, view.
4035 Needs to be here because ns_initialize_display_info () uses AppKit classes.
4036 The view will then ask the NSApp to stop and return to Emacs. */
4037 [EmacsApp sharedApplication
];
4040 [NSApp setDelegate
: NSApp
];
4042 /* debugging: log all notifications */
4043 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4044 selector: @selector (logNotification:)
4045 name: nil object: nil]; */
4047 dpyinfo
= (struct ns_display_info
*)xmalloc
(sizeof
(struct ns_display_info
));
4048 memset
(dpyinfo
, 0, sizeof
(struct ns_display_info
));
4050 ns_initialize_display_info
(dpyinfo
);
4051 terminal = ns_create_terminal
(dpyinfo
);
4053 terminal->kboard
= (KBOARD
*) xmalloc
(sizeof
(KBOARD
));
4054 init_kboard
(terminal->kboard
);
4055 KVAR
(terminal->kboard
, Vwindow_system
) = Qns
;
4056 terminal->kboard
->next_kboard
= all_kboards
;
4057 all_kboards
= terminal->kboard
;
4058 /* Don't let the initial kboard remain current longer than necessary.
4059 That would cause problems if a file loaded on startup tries to
4060 prompt in the mini-buffer. */
4061 if (current_kboard
== initial_kboard
)
4062 current_kboard
= terminal->kboard
;
4063 terminal->kboard
->reference_count
++;
4065 dpyinfo
->next
= x_display_list
;
4066 x_display_list
= dpyinfo
;
4068 /* Put it on ns_display_name_list */
4069 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
4070 ns_display_name_list
);
4071 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
4073 /* Set the name of the terminal. */
4074 terminal->name
= (char *) xmalloc
(SBYTES
(display_name
) + 1);
4075 strncpy
(terminal->name
, SDATA
(display_name
), SBYTES
(display_name
));
4076 terminal->name
[SBYTES
(display_name
)] = 0;
4080 if (!inhibit_x_resources
)
4082 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4085 /* this is a standard variable */
4086 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4087 make_float
(10.0), make_float
(6.0), YES
, NO
);
4088 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4091 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
4092 stringForKey
: @"AppleHighlightColor"
];
4093 if (ns_selection_color
== nil
)
4094 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
4097 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4101 Lisp_Object color_file
, color_map
, color
;
4106 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4107 Fsymbol_value
(intern
("data
-directory"
)));
4108 if (NILP
(Ffile_readable_p
(color_file
)))
4109 fatal
("Could not
find %s.\n", SDATA (color_file));
4111 color_map
= Fx_load_color_file
(color_file
);
4112 if (NILP
(color_map
))
4113 fatal
("Could not read
%s.\n", SDATA (color_file));
4115 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4116 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4118 color
= XCAR
(color_map
);
4119 name
= SDATA
(XCAR
(color
));
4120 c
= XINT
(XCDR
(color
));
4122 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4123 green
: GREEN_FROM_ULONG
(c
) / 255.0
4124 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4126 forKey
: [NSString stringWithUTF8String
: name
]];
4128 [cl writeToFile
: nil
];
4134 #ifdef NS_IMPL_GNUSTEP
4135 strncpy
(c
, gnustep_base_version
, sizeof
(c
));
4137 /*PSnextrelease (128, c); */
4138 snprintf
(c
, sizeof
(c
), "
%g", NSAppKitVersionNumber);
4140 Vwindow_system_version
= build_string
(c
);
4143 delete_keyboard_wait_descriptor
(0);
4145 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4147 /* Set up OS X app menu */
4148 #ifdef NS_IMPL_COCOA
4152 /* set up the application menu */
4153 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4154 [svcsMenu setAutoenablesItems
: NO
];
4155 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4156 [appMenu setAutoenablesItems
: NO
];
4157 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4158 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4160 [appMenu insertItemWithTitle
: @"About Emacs"
4161 action
: @selector
(orderFrontStandardAboutPanel
:)
4164 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4165 [appMenu insertItemWithTitle
: @"Preferences..."
4166 action
: @selector
(showPreferencesWindow
:)
4169 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4170 item
= [appMenu insertItemWithTitle
: @"Services"
4171 action
: @selector
(menuDown
:)
4174 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4175 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4176 [appMenu insertItemWithTitle
: @"Hide Emacs"
4177 action
: @selector
(hide
:)
4180 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4181 action
: @selector
(hideOtherApplications
:)
4184 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4185 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4186 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4187 action
: @selector
(terminate
:)
4191 item
= [mainMenu insertItemWithTitle
: ns_app_name
4192 action
: @selector
(menuDown
:)
4195 [mainMenu setSubmenu
: appMenu forItem
: item
];
4196 [dockMenu insertItemWithTitle
: @"New Frame"
4197 action
: @selector
(newFrame
:)
4201 [NSApp setMainMenu
: mainMenu
];
4202 [NSApp setAppleMenu
: appMenu
];
4203 [NSApp setServicesMenu
: svcsMenu
];
4204 /* Needed at least on Cocoa, to get dock menu to show windows */
4205 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4207 [[NSNotificationCenter defaultCenter
]
4208 addObserver
: mainMenu
4209 selector
: @selector
(trackingNotification
:)
4210 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4211 [[NSNotificationCenter defaultCenter
]
4212 addObserver
: mainMenu
4213 selector
: @selector
(trackingNotification
:)
4214 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4216 #endif
/* MAC OS X menu setup */
4225 ns_term_shutdown
(int sig
)
4227 [[NSUserDefaults standardUserDefaults
] synchronize
];
4229 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4230 if (STRINGP
(Vauto_save_list_file_name
))
4231 unlink
(SDATA
(Vauto_save_list_file_name
));
4233 if (sig
== 0 || sig
== SIGTERM
)
4235 [NSApp terminate
: NSApp
];
4237 else // force a stack
trace to happen
4244 /* ==========================================================================
4246 EmacsApp implementation
4248 ========================================================================== */
4251 @implementation EmacsApp
4253 - (void
)logNotification
: (NSNotification
*)notification
4255 const
char *name
= [[notification name
] UTF8String
];
4256 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4257 && !strstr
(name
, "WindowNumber"
))
4258 NSLog
(@"notification
: '%@'"
, [notification name
]);
4262 - (void
)sendEvent
: (NSEvent
*)theEvent
4263 /* --------------------------------------------------------------------------
4264 Called when NSApp is running for each event received. Used to stop
4265 the loop when we choose, since there's no way to just run one iteration.
4266 -------------------------------------------------------------------------- */
4268 int
type = [theEvent
type];
4269 NSWindow
*window
= [theEvent window
];
4270 /* NSTRACE (sendEvent); */
4271 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4273 #ifdef NS_IMPL_COCOA
4274 if (type == NSApplicationDefined
4275 && [theEvent data2
] == NSAPP_DATA2_RUNASSCRIPT
)
4283 if (type == NSCursorUpdate
&& window
== nil
)
4285 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4289 #ifdef NS_IMPL_COCOA
4290 /* pass mouse down in resize handle and subsequent drags directly to
4291 EmacsWindow so we can generate continuous redisplays */
4294 if (type == NSLeftMouseDragged
)
4296 [window mouseDragged
: theEvent
];
4299 else if (type == NSLeftMouseUp
)
4301 [window mouseUp
: theEvent
];
4305 else if (type == NSLeftMouseDown
)
4307 NSRect r
= ns_resize_handle_rect
(window
);
4308 if (NSPointInRect
([theEvent locationInWindow
], r
))
4311 [window mouseDown
: theEvent
];
4317 if (type == NSApplicationDefined
)
4319 /* Events posted by ns_send_appdefined interrupt the run loop here.
4320 But, if a modal window is up, an appdefined can still come through,
4321 (e.g., from a makeKeyWindow event) but stopping self also stops the
4322 modal loop. Just defer it until later. */
4323 if ([NSApp modalWindow
] == nil
)
4325 last_appdefined_event
= theEvent
;
4330 send_appdefined
= YES
;
4334 [super sendEvent
: theEvent
];
4338 - (void
)showPreferencesWindow
: (id
)sender
4340 struct frame
*emacsframe
= SELECTED_FRAME
();
4341 NSEvent
*theEvent
= [NSApp currentEvent
];
4345 emacs_event
->kind
= NS_NONKEY_EVENT
;
4346 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4347 emacs_event
->modifiers
= 0;
4348 EV_TRAILER
(theEvent
);
4352 - (void
)newFrame
: (id
)sender
4354 struct frame
*emacsframe
= SELECTED_FRAME
();
4355 NSEvent
*theEvent
= [NSApp currentEvent
];
4359 emacs_event
->kind
= NS_NONKEY_EVENT
;
4360 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4361 emacs_event
->modifiers
= 0;
4362 EV_TRAILER
(theEvent
);
4366 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4367 - (BOOL
) openFile
: (NSString
*)fileName
4369 struct frame
*emacsframe
= SELECTED_FRAME
();
4370 NSEvent
*theEvent
= [NSApp currentEvent
];
4375 emacs_event
->kind
= NS_NONKEY_EVENT
;
4376 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4377 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4378 ns_input_line
= Qnil
; /* can be start or cons start,end */
4379 emacs_event
->modifiers
=0;
4380 EV_TRAILER
(theEvent
);
4386 /* **************************************************************************
4388 EmacsApp delegate implementation
4390 ************************************************************************** */
4392 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4393 /* --------------------------------------------------------------------------
4394 When application is loaded, terminate event loop in ns_term_init
4395 -------------------------------------------------------------------------- */
4397 NSTRACE
(applicationDidFinishLaunching
);
4398 [NSApp setServicesProvider
: NSApp
];
4399 ns_send_appdefined
(-2);
4403 /* Termination sequences:
4406 MenuBar | File | Exit:
4407 Select Quit from App menubar:
4409 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4412 Select Quit from Dock menu:
4415 Cancel -> Nothing else
4419 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4424 - (void
) terminate
: (id
)sender
4426 struct frame
*emacsframe
= SELECTED_FRAME
();
4431 emacs_event
->kind
= NS_NONKEY_EVENT
;
4432 emacs_event
->code
= KEY_NS_POWER_OFF
;
4433 emacs_event
->arg
= Qt
; /* mark as non-key event */
4434 EV_TRAILER
((id
)nil
);
4438 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4442 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4443 return NSTerminateNow
;
4445 ret
= NSRunAlertPanel
(ns_app_name
,
4446 [NSString stringWithUTF8String
:"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
],
4447 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4449 if (ret
== NSAlertDefaultReturn
)
4450 return NSTerminateNow
;
4451 else if (ret
== NSAlertAlternateReturn
)
4452 return NSTerminateCancel
;
4453 return NSTerminateNow
; /* just in case */
4457 /* Notification from the Workspace to open a file */
4458 - (BOOL
)application
: sender openFile
: (NSString
*)file
4460 [ns_pending_files addObject
: file
];
4465 /* Open a file as a temporary file */
4466 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4468 [ns_pending_files addObject
: file
];
4473 /* Notification from the Workspace to open a file noninteractively (?) */
4474 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4476 [ns_pending_files addObject
: file
];
4481 /* Notification from the Workspace to open multiple files */
4482 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4484 NSEnumerator
*files
= [fileList objectEnumerator
];
4486 while ((file
= [files nextObject
]) != nil
)
4487 [ns_pending_files addObject
: file
];
4489 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4494 /* Handle dock menu requests. */
4495 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4501 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4502 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4504 //ns_app_active
=YES
;
4506 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4508 NSTRACE
(applicationDidBecomeActive
);
4510 //ns_app_active
=YES
;
4512 ns_update_auto_hide_menu_bar
();
4513 // No constraining takes place when the application is not active.
4514 ns_constrain_all_frames
();
4516 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4519 ns_send_appdefined
(-1);
4524 /* ==========================================================================
4526 EmacsApp aux handlers for managing event loop
4528 ========================================================================== */
4531 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4532 /* --------------------------------------------------------------------------
4533 The timeout specified to ns_select has passed.
4534 -------------------------------------------------------------------------- */
4536 /*NSTRACE (timeout_handler); */
4537 ns_send_appdefined
(-2);
4540 - (void
)fd_handler
: (NSTimer
*) fdEntry
4541 /* --------------------------------------------------------------------------
4542 Check data waiting on file descriptors and terminate if so
4543 -------------------------------------------------------------------------- */
4546 /* NSTRACE (fd_handler); */
4548 if (select_nfds
== 0)
4551 memcpy
(&t_readfds
, &select_readfds
, sizeof
(fd_set
));
4553 select_timeout.tv_sec
= select_timeout.tv_usec
= 0;
4554 result
= select
(select_nfds
, &t_readfds
, (SELECT_TYPE
*)0, (SELECT_TYPE
*)0,
4558 memcpy
(&select_readfds
, &t_readfds
, sizeof
(fd_set
));
4559 ns_send_appdefined
(result
);
4565 /* ==========================================================================
4569 ========================================================================== */
4571 /* called from system: queue for next pass through event loop */
4572 - (void
)requestService
: (NSPasteboard
*)pboard
4573 userData
: (NSString
*)userData
4574 error: (NSString
**)error
4576 [ns_pending_service_names addObject
: userData
];
4577 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4578 SDATA
(ns_string_from_pasteboard
(pboard
))]];
4582 /* called from ns_read_socket to clear queue */
4583 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4585 struct frame
*emacsframe
= SELECTED_FRAME
();
4586 NSEvent
*theEvent
= [NSApp currentEvent
];
4591 emacs_event
->kind
= NS_NONKEY_EVENT
;
4592 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4593 ns_input_spi_name
= build_string
([name UTF8String
]);
4594 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4595 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4596 EV_TRAILER
(theEvent
);
4606 /* ==========================================================================
4608 EmacsView implementation
4610 ========================================================================== */
4613 @implementation EmacsView
4615 /* needed to inform when window closed from LISP */
4616 - (void
) setWindowClosing
: (BOOL
)closing
4618 windowClosing
= closing
;
4624 NSTRACE
(EmacsView_dealloc
);
4630 /* called on font panel selection */
4631 - (void
)changeFont
: (id
)sender
4633 NSEvent
*e
=[[self window
] currentEvent
];
4634 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4638 NSTRACE
(changeFont
);
4642 if (newFont
= [sender convertFont
:
4643 ((struct nsfont_info
*)face
->font
)->nsfont
])
4645 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4647 emacs_event
->kind
= NS_NONKEY_EVENT
;
4648 emacs_event
->modifiers
= 0;
4649 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4651 size = [newFont pointSize
];
4652 ns_input_fontsize
= make_number
(lrint
(size));
4653 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4659 - (BOOL
)acceptsFirstResponder
4661 NSTRACE
(acceptsFirstResponder
);
4666 - (void
)resetCursorRects
4668 NSRect visible
= [self visibleRect
];
4669 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4670 NSTRACE
(resetCursorRects
);
4672 if (currentCursor
== nil
)
4673 currentCursor
= [NSCursor arrowCursor
];
4675 if (!NSIsEmptyRect
(visible
))
4676 [self addCursorRect
: visible cursor
: currentCursor
];
4677 [currentCursor setOnMouseEntered
: YES
];
4682 /*****************************************************************************/
4683 /* Keyboard handling. */
4686 - (void
)keyDown
: (NSEvent
*)theEvent
4688 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
4690 unsigned fnKeysym
= 0;
4692 static NSMutableArray
*nsEvArray
;
4693 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4694 static BOOL firstTime
= YES
;
4700 /* Rhapsody and OS X give up and down events for the arrow keys */
4701 if (ns_fake_keydown
== YES
)
4702 ns_fake_keydown
= NO
;
4703 else if ([theEvent
type] != NSKeyDown
)
4709 if (![[self window
] isKeyWindow
]
4710 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4711 /* we must avoid an infinite loop here. */
4712 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4714 /* XXX: There is an occasional condition in which, when Emacs display
4715 updates a different frame from the current one, and temporarily
4716 selects it, then processes some interrupt-driven input
4717 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4718 for some reason that window has its first responder set to the NSView
4719 most recently updated (I guess), which is not the correct one. */
4720 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4724 if (nsEvArray
== nil
)
4725 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4727 [NSCursor setHiddenUntilMouseMoves
: YES
];
4729 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4731 clear_mouse_face
(hlinfo
);
4732 hlinfo
->mouse_face_hidden
= 1;
4735 if (!processingCompose
)
4737 int is_left_key
, is_right_key
;
4739 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4740 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4741 /* (Carbon way: [theEvent keyCode]) */
4743 /* is it a "function key"? */
4744 fnKeysym
= ns_convert_key
(code
);
4747 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4748 because Emacs treats Delete and KP-Delete same (in simple.el). */
4749 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4750 code
= 0xFF08; /* backspace */
4755 /* are there modifiers? */
4756 emacs_event
->modifiers
= 0;
4757 flags
= [theEvent modifierFlags
];
4759 if (flags
& NSHelpKeyMask
)
4760 emacs_event
->modifiers |
= hyper_modifier
;
4762 if (flags
& NSShiftKeyMask
)
4763 emacs_event
->modifiers |
= shift_modifier
;
4765 is_right_key
= (flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
;
4766 is_left_key
= (flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
4767 ||
(! is_right_key
&& (flags
& NSCommandKeyMask
) == NSCommandKeyMask
);
4770 emacs_event
->modifiers |
= parse_solitary_modifier
4771 (EQ
(ns_right_command_modifier
, Qleft
)
4772 ? ns_command_modifier
4773 : ns_right_command_modifier
);
4777 emacs_event
->modifiers |
= parse_solitary_modifier
4778 (ns_command_modifier
);
4780 /* if super (default), take input manager's word so things like
4781 dvorak / qwerty layout work */
4782 if (EQ
(ns_command_modifier
, Qsuper
)
4784 && [[theEvent characters
] length] != 0)
4786 /* XXX: the code we get will be unshifted, so if we have
4787 a shift modifier, must convert ourselves */
4788 if (!(flags
& NSShiftKeyMask
))
4789 code
= [[theEvent characters
] characterAtIndex
: 0];
4791 /* this is ugly and also requires linking w/Carbon framework
4792 (for LMGetKbdType) so for now leave this rare (?) case
4793 undealt with.. in future look into CGEvent methods */
4796 long smv
= GetScriptManagerVariable
(smKeyScript
);
4797 Handle uchrHandle
= GetResource
4798 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4800 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4801 [[theEvent characters
] characterAtIndex
: 0],
4802 kUCKeyActionDisplay
,
4803 (flags
& ~NSCommandKeyMask
) >> 8,
4804 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4805 &dummy
, 1, &dummy
, &code
);
4812 is_right_key
= (flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
;
4813 is_left_key
= (flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
4814 ||
(! is_right_key
&& (flags
& NSControlKeyMask
) == NSControlKeyMask
);
4817 emacs_event
->modifiers |
= parse_solitary_modifier
4818 (EQ
(ns_right_control_modifier
, Qleft
)
4819 ? ns_control_modifier
4820 : ns_right_control_modifier
);
4823 emacs_event
->modifiers |
= parse_solitary_modifier
4824 (ns_control_modifier
);
4826 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4827 emacs_event
->modifiers |
=
4828 parse_solitary_modifier
(ns_function_modifier
);
4830 left_is_none
= NILP
(ns_alternate_modifier
)
4831 || EQ
(ns_alternate_modifier
, Qnone
);
4833 is_right_key
= (flags
& NSRightAlternateKeyMask
)
4834 == NSRightAlternateKeyMask
;
4835 is_left_key
= (flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
4837 && (flags
& NSAlternateKeyMask
) == NSAlternateKeyMask
);
4841 if ((NILP
(ns_right_alternate_modifier
)
4842 || EQ
(ns_right_alternate_modifier
, Qnone
)
4843 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
4845 { /* accept pre-interp alt comb */
4846 if ([[theEvent characters
] length] > 0)
4847 code
= [[theEvent characters
] characterAtIndex
: 0];
4848 /*HACK: clear lone shift modifier to stop next if from firing */
4849 if (emacs_event
->modifiers
== shift_modifier
)
4850 emacs_event
->modifiers
= 0;
4853 emacs_event
->modifiers |
= parse_solitary_modifier
4854 (EQ
(ns_right_alternate_modifier
, Qleft
)
4855 ? ns_alternate_modifier
4856 : ns_right_alternate_modifier
);
4859 if (is_left_key
) /* default = meta */
4861 if (left_is_none
&& !fnKeysym
)
4862 { /* accept pre-interp alt comb */
4863 if ([[theEvent characters
] length] > 0)
4864 code
= [[theEvent characters
] characterAtIndex
: 0];
4865 /*HACK: clear lone shift modifier to stop next if from firing */
4866 if (emacs_event
->modifiers
== shift_modifier
)
4867 emacs_event
->modifiers
= 0;
4870 emacs_event
->modifiers |
=
4871 parse_solitary_modifier
(ns_alternate_modifier
);
4875 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4876 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4878 /* if it was a function key or had modifiers, pass it directly to emacs */
4879 if (fnKeysym ||
(emacs_event
->modifiers
4880 && (emacs_event
->modifiers
!= shift_modifier
)
4881 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4882 /*[[theEvent characters] length] */
4884 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4886 code |
= (1<<28)|
(3<<16);
4887 else if (code
== 0x7f)
4888 code |
= (1<<28)|
(3<<16);
4890 emacs_event
->kind
= code
> 0xFF
4891 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4893 emacs_event
->code
= code
;
4894 EV_TRAILER
(theEvent
);
4900 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4901 /* if we get here we should send the key for input manager processing */
4902 if (firstTime
&& [[NSInputManager currentInputManager
]
4903 wantsToDelayTextChangeNotifications
] == NO
)
4905 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
4908 if (NS_KEYLOG
&& !processingCompose
)
4909 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
4911 processingCompose
= YES
;
4912 [nsEvArray addObject
: theEvent
];
4913 [self interpretKeyEvents
: nsEvArray
];
4914 [nsEvArray removeObject
: theEvent
];
4918 #ifdef NS_IMPL_COCOA
4919 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
4920 decided not to send key-down for.
4921 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
4922 This only applies on Tiger and earlier.
4923 If it matches one of these, send it on to keyDown. */
4924 -(void
)keyUp
: (NSEvent
*)theEvent
4926 int flags
= [theEvent modifierFlags
];
4927 int code
= [theEvent keyCode
];
4928 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
4929 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
4932 fprintf (stderr
, "keyUp
: passed test"
);
4933 ns_fake_keydown
= YES
;
4934 [self keyDown
: theEvent
];
4940 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
4943 /* <NSTextInput>: called when done composing;
4944 NOTE: also called when we delete over working text, followed immed.
4945 by doCommandBySelector: deleteBackward: */
4946 - (void
)insertText
: (id
)aString
4949 int len
= [(NSString
*)aString
length];
4953 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
4954 processingCompose
= NO
;
4959 /* first, clear any working text */
4960 if (workingText
!= nil
)
4961 [self deleteWorkingText
];
4963 /* now insert the string as keystrokes */
4964 for (i
=0; i
<len
; i
++)
4966 code
= [aString characterAtIndex
: i
];
4967 /* TODO: still need this? */
4969 code
= '~'; /* 0x7E */
4970 emacs_event
->modifiers
= 0;
4972 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4973 emacs_event
->code
= code
;
4974 EV_TRAILER
((id
)nil
);
4979 /* <NSTextInput>: inserts display of composing characters */
4980 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
4982 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
4983 [aString string
] : aString
;
4985 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
4986 selRange.
length, selRange.location
);
4988 if (workingText
!= nil
)
4989 [self deleteWorkingText
];
4990 if ([str
length] == 0)
4996 processingCompose
= YES
;
4997 workingText
= [str copy
];
4998 ns_working_text
= build_string
([workingText UTF8String
]);
5000 emacs_event
->kind
= NS_TEXT_EVENT
;
5001 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
5002 EV_TRAILER
((id
)nil
);
5006 /* delete display of composing characters [not in <NSTextInput>] */
5007 - (void
)deleteWorkingText
5009 if (workingText
== nil
)
5012 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
5013 [workingText release
];
5015 processingCompose
= NO
;
5020 emacs_event
->kind
= NS_TEXT_EVENT
;
5021 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5022 EV_TRAILER
((id
)nil
);
5026 - (BOOL
)hasMarkedText
5028 return workingText
!= nil
;
5032 - (NSRange
)markedRange
5034 NSRange rng
= workingText
!= nil
5035 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5037 NSLog
(@"markedRange request"
);
5045 NSLog
(@"unmark
(accept
) text"
);
5046 [self deleteWorkingText
];
5047 processingCompose
= NO
;
5051 /* used to position char selection windows, etc. */
5052 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5056 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5058 NSLog
(@"firstRectForCharRange request"
);
5060 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5061 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5062 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5063 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5064 +FRAME_LINE_HEIGHT
(emacsframe
));
5066 pt
= [self convertPoint
: pt toView
: nil
];
5067 pt
= [[self window
] convertBaseToScreen
: pt
];
5073 - (long)conversationIdentifier
5079 - (void
)doCommandBySelector
: (SEL
)aSelector
5082 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5084 if (aSelector
== @selector
(deleteBackward
:))
5086 /* happens when user backspaces over an ongoing composition:
5087 throw a 'delete' into the event queue */
5090 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5091 emacs_event
->code
= 0xFF08;
5092 EV_TRAILER
((id
)nil
);
5096 - (NSArray
*)validAttributesForMarkedText
5098 static NSArray
*arr
= nil
;
5099 if (arr
== nil
) arr
= [NSArray new
];
5100 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5104 - (NSRange
)selectedRange
5107 NSLog
(@"selectedRange request"
);
5108 return NSMakeRange
(NSNotFound
, 0);
5111 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5114 NSLog
(@"characterIndexForPoint request"
);
5118 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5120 static NSAttributedString
*str
= nil
;
5121 if (str
== nil
) str
= [NSAttributedString new
];
5123 NSLog
(@"attributedSubstringFromRange request"
);
5127 /* End <NSTextInput> impl. */
5128 /*****************************************************************************/
5131 /* This is what happens when the user presses a mouse button. */
5132 - (void
)mouseDown
: (NSEvent
*)theEvent
5134 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5137 NSTRACE
(mouseDown
);
5139 [self deleteWorkingText
];
5144 last_mouse_frame
= emacsframe
;
5145 /* appears to be needed to prevent spurious movement events generated on
5147 last_mouse_frame
->mouse_moved
= 0;
5149 if ([theEvent
type] == NSScrollWheel
)
5151 float delta
= [theEvent deltaY
];
5152 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5155 emacs_event
->kind
= WHEEL_EVENT
;
5156 emacs_event
->code
= 0;
5157 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5158 ((delta
> 0) ? up_modifier
: down_modifier
);
5162 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5163 emacs_event
->code
= EV_BUTTON
(theEvent
);
5164 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5165 | EV_UDMODIFIERS
(theEvent
);
5167 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5168 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5169 EV_TRAILER
(theEvent
);
5173 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5175 NSTRACE
(rightMouseDown
);
5176 [self mouseDown
: theEvent
];
5180 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5182 NSTRACE
(otherMouseDown
);
5183 [self mouseDown
: theEvent
];
5187 - (void
)mouseUp
: (NSEvent
*)theEvent
5190 [self mouseDown
: theEvent
];
5194 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5196 NSTRACE
(rightMouseUp
);
5197 [self mouseDown
: theEvent
];
5201 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5203 NSTRACE
(otherMouseUp
);
5204 [self mouseDown
: theEvent
];
5208 - (void
) scrollWheel
: (NSEvent
*)theEvent
5210 NSTRACE
(scrollWheel
);
5211 [self mouseDown
: theEvent
];
5215 /* Tell emacs the mouse has moved. */
5216 - (void
)mouseMoved
: (NSEvent
*)e
5218 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5221 // NSTRACE
(mouseMoved
);
5223 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5224 last_mouse_motion_position
5225 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5227 /* update any mouse face */
5228 if (hlinfo
->mouse_face_hidden
)
5230 hlinfo
->mouse_face_hidden
= 0;
5231 clear_mouse_face
(hlinfo
);
5234 /* tooltip handling */
5235 previous_help_echo_string
= help_echo_string
;
5236 help_echo_string
= Qnil
;
5238 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
5239 last_mouse_motion_position.y
))
5240 help_echo_string
= previous_help_echo_string
;
5242 XSETFRAME
(frame
, emacsframe
);
5243 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5245 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5246 (note_mouse_highlight), which is called through the
5247 note_mouse_movement () call above */
5248 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5249 help_echo_object
, help_echo_pos
);
5253 help_echo_string
= Qnil
;
5254 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5257 if (emacsframe
->mouse_moved
&& send_appdefined
)
5258 ns_send_appdefined
(-1);
5262 - (void
)mouseDragged
: (NSEvent
*)e
5264 NSTRACE
(mouseDragged
);
5265 [self mouseMoved
: e
];
5269 - (void
)rightMouseDragged
: (NSEvent
*)e
5271 NSTRACE
(rightMouseDragged
);
5272 [self mouseMoved
: e
];
5276 - (void
)otherMouseDragged
: (NSEvent
*)e
5278 NSTRACE
(otherMouseDragged
);
5279 [self mouseMoved
: e
];
5283 - (BOOL
)windowShouldClose
: (id
)sender
5285 NSEvent
*e
=[[self window
] currentEvent
];
5287 NSTRACE
(windowShouldClose
);
5288 windowClosing
= YES
;
5291 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5292 emacs_event
->modifiers
= 0;
5293 emacs_event
->code
= 0;
5295 /* Don't close this window, let this be done from lisp code. */
5300 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5301 /* normalize frame to gridded text size */
5303 NSTRACE
(windowWillResize
);
5304 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5306 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5307 #ifdef NS_IMPL_GNUSTEP
5308 frameSize.width
+ 3);
5312 if (cols
< MINWIDTH
)
5315 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5316 #ifdef NS_IMPL_GNUSTEP
5317 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5318 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5320 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5321 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5323 if (rows
< MINHEIGHT
)
5325 #ifdef NS_IMPL_COCOA
5327 /* this sets window title to have size in it; the wm does this under GS */
5328 NSRect r
= [[self window
] frame
];
5329 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5340 NSWindow
*window
= [self window
];
5343 const
char *t
= [[[self window
] title] UTF8String
];
5344 char *pos
= strstr
(t
, " — "
);
5347 old_title
= (char *) xmalloc
(strlen
(t
) + 1);
5348 strcpy
(old_title
, t
);
5350 size_title
= xmalloc
(strlen
(old_title
) + 40);
5351 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5352 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5357 #endif
/* NS_IMPL_COCOA */
5358 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5364 - (void
)windowDidResize
: (NSNotification
*)notification
5366 NSWindow
*theWindow
= [notification object
];
5368 #ifdef NS_IMPL_GNUSTEP
5369 /* in GNUstep, at least currently, it's possible to get a didResize
5370 without getting a willResize.. therefore we need to act as if we got
5371 the willResize now */
5372 NSSize sz
= [theWindow frame
].
size;
5373 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5374 #endif
/* NS_IMPL_GNUSTEP */
5376 NSTRACE
(windowDidResize
);
5377 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5379 #ifdef NS_IMPL_COCOA
5385 #endif
/* NS_IMPL_COCOA */
5387 /* Avoid loop under GNUstep due to call at beginning of this function.
5388 (x_set_window_size causes a resize which causes
5389 a "windowDidResize" which calls x_set_window_size). */
5390 #ifndef NS_IMPL_GNUSTEP
5391 if (cols
> 0 && rows
> 0)
5394 x_set_window_size
(emacsframe
, 0, cols
, rows
);
5397 NSWindow
*window
= [self window
];
5398 NSRect wr
= [window frame
];
5399 FRAME_PIXEL_WIDTH
(emacsframe
) = (int
)wr.
size.width
5400 - emacsframe
->border_width
;
5401 FRAME_PIXEL_HEIGHT
(emacsframe
) = (int
)wr.
size.height
5402 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5403 - FRAME_TOOLBAR_HEIGHT
(emacsframe
);
5404 change_frame_size
(emacsframe
, rows
, cols
, 0, 0, 1);
5405 SET_FRAME_GARBAGED
(emacsframe
);
5406 cancel_mouse_face
(emacsframe
);
5411 ns_send_appdefined
(-1);
5415 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5416 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5418 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5419 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5421 NSTRACE
(windowDidBecomeKey
);
5423 if (emacsframe
!= old_focus
)
5424 dpyinfo
->x_focus_frame
= emacsframe
;
5426 ns_frame_rehighlight
(emacsframe
);
5430 emacs_event
->kind
= FOCUS_IN_EVENT
;
5431 EV_TRAILER
((id
)nil
);
5436 - (void
)windowDidResignKey
: (NSNotification
*)notification
5437 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5439 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5440 NSTRACE
(windowDidResignKey
);
5442 if (dpyinfo
->x_focus_frame
== emacsframe
)
5443 dpyinfo
->x_focus_frame
= 0;
5445 ns_frame_rehighlight
(emacsframe
);
5447 /* FIXME: for some reason needed on second and subsequent clicks away
5448 from sole-frame Emacs to get hollow box to show */
5449 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5451 x_update_cursor
(emacsframe
, 1);
5452 x_set_frame_alpha
(emacsframe
);
5457 [self deleteWorkingText
];
5458 emacs_event
->kind
= FOCUS_IN_EVENT
;
5459 EV_TRAILER
((id
)nil
);
5464 - (void
)windowWillMiniaturize
: sender
5466 NSTRACE
(windowWillMiniaturize
);
5482 - initFrameFromEmacs
: (struct frame
*)f
5487 NSButton
*toggleButton
;
5488 int vbextra
= NS_SCROLL_BAR_WIDTH
(f
);
5493 NSTRACE
(initFrameFromEmacs
);
5496 processingCompose
= NO
;
5497 scrollbarsNeedingUpdate
= 0;
5499 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5501 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5502 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5503 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5504 [self initWithFrame
: r
];
5505 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5507 FRAME_NS_VIEW
(f
) = self
;
5511 win
= [[EmacsWindow alloc
]
5512 initWithContentRect
: r
5513 styleMask
: (NSResizableWindowMask |
5514 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5515 NSTitledWindowMask |
5517 NSMiniaturizableWindowMask |
5518 NSClosableWindowMask
)
5519 backing
: NSBackingStoreBuffered
5523 f
->border_width
= wr.
size.width
- r.
size.width
;
5524 FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
5526 [win setAcceptsMouseMovedEvents
: YES
];
5527 [win setDelegate
: self
];
5528 [win useOptimizedDrawing
: YES
];
5530 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5531 sz.height
= FRAME_LINE_HEIGHT
(f
);
5532 [win setResizeIncrements
: sz
];
5534 [[win contentView
] addSubview
: self
];
5537 [self registerForDraggedTypes
: ns_drag_types
];
5540 name
= [NSString stringWithUTF8String
:
5541 NILP
(tem
) ?
(unsigned
char *)"Emacs"
: SDATA
(tem
)];
5542 [win setTitle
: name
];
5544 /* toolbar support */
5545 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
5546 [NSString stringWithFormat
: @"Emacs Frame
%d",
5548 [win setToolbar
: toolbar
];
5549 [toolbar setVisible
: NO
];
5550 #ifdef NS_IMPL_COCOA
5551 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
5552 [toggleButton setTarget
: self
];
5553 [toggleButton setAction
: @selector
(toggleToolbar
: )];
5555 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5559 [win setMiniwindowTitle
:
5560 [NSString stringWithUTF8String
: SDATA
(tem
)]];
5563 NSScreen
*screen
= [win screen
];
5566 [win setFrameTopLeftPoint
: NSMakePoint
5567 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
5568 IN_BOUND
(-SCREENMAX
,
5569 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
5572 [win makeFirstResponder
: self
];
5574 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5575 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
5576 [win setBackgroundColor
: col
];
5577 if ([col alphaComponent
] != 1.0)
5578 [win setOpaque
: NO
];
5580 [self allocateGState
];
5582 [NSApp registerServicesMenuSendTypes
: ns_send_types
5590 - (void
)windowDidMove
: sender
5592 NSWindow
*win
= [self window
];
5593 NSRect r
= [win frame
];
5594 NSArray
*screens
= [NSScreen screens
];
5595 NSScreen
*screen
= [screens objectAtIndex
: 0];
5597 NSTRACE
(windowDidMove
);
5599 if (!emacsframe
->output_data.ns
)
5603 emacsframe
->left_pos
= r.origin.x
;
5604 emacsframe
->top_pos
=
5605 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
5610 /* Called AFTER method below, but before our windowWillResize call there leads
5611 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
5612 location so set_window_size moves the frame. */
5613 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5615 emacsframe
->output_data.ns
->zooming
= 1;
5620 /* Override to do something slightly nonstandard, but nice. First click on
5621 zoom button will zoom vertically. Second will zoom completely. Third
5622 returns to original. */
5623 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5624 defaultFrame
:(NSRect
)defaultFrame
5626 NSRect result
= [sender frame
];
5628 NSTRACE
(windowWillUseStandardFrame
);
5630 if (abs (defaultFrame.
size.height
- result.
size.height
)
5631 > FRAME_LINE_HEIGHT
(emacsframe
))
5634 ns_userRect
= result
;
5635 result.
size.height
= defaultFrame.
size.height
;
5636 result.origin.y
= defaultFrame.origin.y
;
5640 if (abs (defaultFrame.
size.width
- result.
size.width
)
5641 > FRAME_COLUMN_WIDTH
(emacsframe
))
5642 result
= defaultFrame
; /* second click */
5646 result
= ns_userRect.
size.height ? ns_userRect
: result
;
5647 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5651 [self windowWillResize
: sender toSize
: result.
size];
5656 - (void
)windowDidDeminiaturize
: sender
5658 NSTRACE
(windowDidDeminiaturize
);
5659 if (!emacsframe
->output_data.ns
)
5661 emacsframe
->async_iconified
= 0;
5662 emacsframe
->async_visible
= 1;
5663 windows_or_buffers_changed
++;
5667 emacs_event
->kind
= ICONIFY_EVENT
;
5668 EV_TRAILER
((id
)nil
);
5673 - (void
)windowDidExpose
: sender
5675 NSTRACE
(windowDidExpose
);
5676 if (!emacsframe
->output_data.ns
)
5678 emacsframe
->async_visible
= 1;
5679 SET_FRAME_GARBAGED
(emacsframe
);
5681 if (send_appdefined
)
5682 ns_send_appdefined
(-1);
5686 - (void
)windowDidMiniaturize
: sender
5688 NSTRACE
(windowDidMiniaturize
);
5689 if (!emacsframe
->output_data.ns
)
5692 emacsframe
->async_iconified
= 1;
5693 emacsframe
->async_visible
= 0;
5697 emacs_event
->kind
= ICONIFY_EVENT
;
5698 EV_TRAILER
((id
)nil
);
5703 - (void
)mouseEntered
: (NSEvent
*)theEvent
5705 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5706 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5707 NSTRACE
(mouseEntered
);
5709 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5713 - (void
)mouseExited
: (NSEvent
*)theEvent
5715 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5717 Mouse_HLInfo
*hlinfo
= emacsframe ? MOUSE_HL_INFO
(emacsframe
) : NULL;
5719 NSTRACE
(mouseExited
);
5724 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5726 if (emacsframe
== hlinfo
->mouse_face_mouse_frame
)
5728 clear_mouse_face
(hlinfo
);
5729 hlinfo
->mouse_face_mouse_frame
= 0;
5737 if (context_menu_value
== -1)
5738 context_menu_value
= [sender tag
];
5740 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
5741 emacsframe
->menu_bar_vector
,
5742 (void
*)[sender tag
]);
5743 ns_send_appdefined
(-1);
5748 - (EmacsToolbar
*)toolbar
5754 /* this gets called on toolbar button click */
5755 - toolbarClicked
: (id
)item
5758 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
5760 NSTRACE
(toolbarClicked
);
5765 /* send first event (for some reason two needed) */
5766 theEvent
= [[self window
] currentEvent
];
5767 emacs_event
->kind
= TOOL_BAR_EVENT
;
5768 XSETFRAME
(emacs_event
->arg
, emacsframe
);
5769 EV_TRAILER
(theEvent
);
5771 emacs_event
->kind
= TOOL_BAR_EVENT
;
5772 /* XSETINT (emacs_event->code, 0); */
5773 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
5774 idx
+ TOOL_BAR_ITEM_KEY
);
5775 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5776 EV_TRAILER
(theEvent
);
5781 - toggleToolbar
: (id
)sender
5786 emacs_event
->kind
= NS_NONKEY_EVENT
;
5787 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
5788 EV_TRAILER
((id
)nil
);
5793 - (void
)drawRect
: (NSRect
)rect
5795 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
5796 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
5800 if (!emacsframe ||
!emacsframe
->output_data.ns || ns_in_resize
)
5803 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
5804 expose_frame
(emacsframe
, x
, y
, width
, height
);
5807 drawRect: may be called (at least in OS X 10.5) for invisible
5808 views as well for some reason. Thus, do not infer visibility
5811 emacsframe->async_visible = 1;
5812 emacsframe->async_iconified = 0;
5817 /* NSDraggingDestination protocol methods. Actually this is not really a
5818 protocol, but a category of Object. O well... */
5820 -(NSUInteger
) draggingEntered
: (id
<NSDraggingInfo
>) sender
5822 NSTRACE
(draggingEntered
);
5823 return NSDragOperationGeneric
;
5827 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
5833 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
5838 NSEvent
*theEvent
= [[self window
] currentEvent
];
5841 NSTRACE
(performDragOperation
);
5846 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
5847 x
= lrint
(position.x
); y
= lrint
(position.y
);
5849 pb
= [sender draggingPasteboard
];
5850 type = [pb availableTypeFromArray
: ns_drag_types
];
5855 else if ([type isEqualToString
: NSFilenamesPboardType
])
5858 NSEnumerator
*fenum
;
5861 if (!(files
= [pb propertyListForType
: type]))
5864 fenum
= [files objectEnumerator
];
5865 while ( (file
= [fenum nextObject
]) )
5867 emacs_event
->kind
= NS_NONKEY_EVENT
;
5868 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5869 XSETINT
(emacs_event
->x
, x
);
5870 XSETINT
(emacs_event
->y
, y
);
5871 ns_input_file
= append2
(ns_input_file
,
5872 build_string
([file UTF8String
]));
5873 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5874 EV_TRAILER
(theEvent
);
5878 else if ([type isEqualToString
: NSURLPboardType
])
5883 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
5884 [fileURL isFileURL
] == NO
)
5887 file
= [fileURL
path];
5888 emacs_event
->kind
= NS_NONKEY_EVENT
;
5889 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5890 XSETINT
(emacs_event
->x
, x
);
5891 XSETINT
(emacs_event
->y
, y
);
5892 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
5893 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5894 EV_TRAILER
(theEvent
);
5897 else if ([type isEqualToString
: NSStringPboardType
]
5898 ||
[type isEqualToString
: NSTabularTextPboardType
])
5902 if (! (data
= [pb stringForType
: type]))
5905 emacs_event
->kind
= NS_NONKEY_EVENT
;
5906 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
5907 XSETINT
(emacs_event
->x
, x
);
5908 XSETINT
(emacs_event
->y
, y
);
5909 ns_input_text
= build_string
([data UTF8String
]);
5910 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5911 EV_TRAILER
(theEvent
);
5914 else if ([type isEqualToString
: NSColorPboardType
])
5916 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
5917 emacs_event
->kind
= NS_NONKEY_EVENT
;
5918 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
5919 XSETINT
(emacs_event
->x
, x
);
5920 XSETINT
(emacs_event
->y
, y
);
5921 ns_input_color
= ns_color_to_lisp
(c
);
5922 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5923 EV_TRAILER
(theEvent
);
5926 else if ([type isEqualToString
: NSFontPboardType
])
5928 /* impl based on GNUstep NSTextView.m */
5929 NSData
*data
= [pb dataForType
: NSFontPboardType
];
5930 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
5931 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
5937 emacs_event
->kind
= NS_NONKEY_EVENT
;
5938 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
5939 XSETINT
(emacs_event
->x
, x
);
5940 XSETINT
(emacs_event
->y
, y
);
5941 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
5942 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
5943 ns_input_fontsize
= build_string
(fontSize
);
5944 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5945 EV_TRAILER
(theEvent
);
5950 error ("Invalid data
type in dragging pasteboard."
);
5956 - (id
) validRequestorForSendType
: (NSString
*)typeSent
5957 returnType
: (NSString
*)typeReturned
5959 NSTRACE
(validRequestorForSendType
);
5960 if (typeSent
!= nil
&& [ns_send_types indexOfObject
: typeSent
] != NSNotFound
5961 && typeReturned
== nil
)
5963 if (! NILP
(ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
)))
5967 return [super validRequestorForSendType
: typeSent
5968 returnType
: typeReturned
];
5972 /* The next two methods are part of NSServicesRequests informal protocol,
5973 supposedly called when a services menu item is chosen from this app.
5974 But this should not happen because we override the services menu with our
5975 own entries which call ns-perform-service.
5976 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
5977 So let's at least stub them out until further investigation can be done. */
5979 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
5981 /* we could call ns_string_from_pasteboard(pboard) here but then it should
5982 be written into the buffer in place of the existing selection..
5983 ordinary service calls go through functions defined in ns-win.el */
5987 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
5989 NSArray
*typesDeclared
;
5992 /* We only support NSStringPboardType */
5993 if ([types containsObject
:NSStringPboardType
] == NO
) {
5997 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
5998 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
6001 if (CONSP
(val
) && NILP
(XCDR
(val
)))
6004 if (! STRINGP
(val
))
6007 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
6008 [pb declareTypes
:typesDeclared owner
:nil
];
6009 ns_string_to_pasteboard
(pb
, val
);
6014 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
6015 (gives a miniaturized version of the window); currently we use the latter for
6016 frames whose active buffer doesn't correspond to any file
6017 (e.g., '*scratch*') */
6018 - setMiniwindowImage
: (BOOL
) setMini
6020 id
image = [[self window
] miniwindowImage
];
6021 NSTRACE
(setMiniwindowImage
);
6023 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6024 about "AppleDockIconEnabled" notwithstanding, however the set message
6025 below has its effect nonetheless. */
6026 if (image != emacsframe
->output_data.ns
->miniimage
)
6028 if (image && [image isKindOfClass
: [EmacsImage
class]])
6030 [[self window
] setMiniwindowImage
:
6031 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6038 - (void
) setRows
: (int
) r andColumns
: (int
) c
6044 @
end /* EmacsView */
6048 /* ==========================================================================
6050 EmacsWindow implementation
6052 ========================================================================== */
6054 @implementation EmacsWindow
6056 /* If we have multiple monitors, one above the other, we don't want to
6057 restrict the height to just one monitor. So we override this. */
6058 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6060 /* When making the frame visible for the first time or if there is just
6061 one screen, we want to constrain. Other times not. */
6062 NSUInteger nr_screens
= [[NSScreen screens
] count
];
6063 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6064 NSTRACE
(constrainFrameRect
);
6066 if (nr_screens
== 1)
6067 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6069 if (f
->output_data.ns
->dont_constrain
6070 || ns_menu_bar_should_be_hidden
())
6073 f
->output_data.ns
->dont_constrain
= 1;
6074 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6078 /* called only on resize clicks by special case in EmacsApp-sendEvent */
6079 - (void
)mouseDown
: (NSEvent
*)theEvent
6083 NSSize
size = [[theEvent window
] frame
].
size;
6084 grabOffset
= [theEvent locationInWindow
];
6085 grabOffset.x
= size.width
- grabOffset.x
;
6088 [super mouseDown
: theEvent
];
6093 - (void
)mouseUp
: (NSEvent
*)theEvent
6097 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6099 ns_set_name_as_filename
(f
);
6101 ns_send_appdefined
(-1);
6104 [super mouseUp
: theEvent
];
6108 /* send resize events */
6109 - (void
)mouseDragged
: (NSEvent
*)theEvent
6113 NSPoint p
= [theEvent locationInWindow
];
6114 NSSize
size, vettedSize
, origSize
= [self frame
].
size;
6116 size.width
= p.x
+ grabOffset.x
;
6117 size.height
= origSize.height
- p.y
+ grabOffset.y
;
6119 if (size.width
== origSize.width
&& size.height
== origSize.height
)
6122 vettedSize
= [[self delegate
] windowWillResize
: self toSize
: size];
6123 [[NSNotificationCenter defaultCenter
]
6124 postNotificationName
: NSWindowDidResizeNotification
6128 [super mouseDragged
: theEvent
];
6131 @
end /* EmacsWindow */
6134 /* ==========================================================================
6136 EmacsScroller implementation
6138 ========================================================================== */
6141 @implementation EmacsScroller
6143 /* for repeat button push */
6144 #define SCROLL_BAR_FIRST_DELAY
0.5
6145 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6147 + (CGFloat
) scrollerWidth
6149 /* TODO: if we want to allow variable widths, this is the place to do it,
6150 however neither GNUstep nor Cocoa support it very well */
6151 return [NSScroller scrollerWidth
];
6155 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
6157 NSTRACE
(EmacsScroller_initFrame
);
6159 r.
size.width
= [EmacsScroller scrollerWidth
];
6160 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
6161 [self setContinuous
: YES
];
6162 [self setEnabled
: YES
];
6164 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
6165 locked against the top and bottom edges, and right edge on OS X, where
6166 scrollers are on right. */
6167 #ifdef NS_IMPL_GNUSTEP
6168 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
6170 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
6175 pixel_height
= NSHeight
(r
);
6176 if (pixel_height
== 0) pixel_height
= 1;
6177 min_portion
= 20 / pixel_height
;
6179 frame
= XFRAME
(XWINDOW
(win
)->frame
);
6180 if (FRAME_LIVE_P
(frame
))
6183 EmacsView
*view = FRAME_NS_VIEW
(frame
);
6184 NSView
*sview
= [[view window
] contentView
];
6185 NSArray
*subs
= [sview subviews
];
6187 /* disable optimization stopping redraw of other scrollbars */
6188 view->scrollbarsNeedingUpdate
= 0;
6189 for (i
=[subs count
]-1; i
>= 0; i
--)
6190 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
6191 view->scrollbarsNeedingUpdate
++;
6192 [sview addSubview
: self
];
6195 /* [self setFrame: r]; */
6201 - (void
)setFrame
: (NSRect
)newRect
6203 NSTRACE
(EmacsScroller_setFrame
);
6205 pixel_height
= NSHeight
(newRect
);
6206 if (pixel_height
== 0) pixel_height
= 1;
6207 min_portion
= 20 / pixel_height
;
6208 [super setFrame
: newRect
];
6210 /* UNBLOCK_INPUT; */
6216 NSTRACE
(EmacsScroller_dealloc
);
6218 XWINDOW
(win
)->vertical_scroll_bar
= Qnil
;
6246 /* ensure other scrollbar updates after deletion */
6247 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6249 view->scrollbarsNeedingUpdate
++;
6250 [self removeFromSuperview
];
6258 - (void
)resetCursorRects
6260 NSRect visible
= [self visibleRect
];
6261 NSTRACE
(resetCursorRects
);
6263 if (!NSIsEmptyRect
(visible
))
6264 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
6265 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
6269 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
6272 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
6273 && portion
!= whole
; /* needed for resize empty buf */
6277 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
6279 NSTRACE
(setPosition
);
6281 em_position
= position
;
6282 em_portion
= portion
;
6285 if (portion
>= whole
)
6287 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6288 [self setKnobProportion
: 1.0];
6289 [self setDoubleValue
: 1.0];
6291 [self setFloatValue
: 0.0 knobProportion
: 1.0];
6297 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
6298 pos
= (float
)position
/ (whole
- portion
);
6299 por
= (float
)portion
/whole
;
6300 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6301 [self setKnobProportion
: por
];
6302 [self setDoubleValue
: pos
];
6304 [self setFloatValue
: pos knobProportion
: por
];
6310 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
6311 drag events will go directly to the EmacsScroller. Leaving in for now. */
6312 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
6313 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
6315 *part
= last_hit_part
;
6317 XSETINT
(*y
, pixel_height
);
6318 if ([self floatValue
] > 0.999)
6319 XSETINT
(*x
, pixel_height
);
6321 XSETINT
(*x
, pixel_height
* [self floatValue
]);
6325 /* set up emacs_event */
6326 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
6331 emacs_event
->part
= last_hit_part
;
6332 emacs_event
->code
= 0;
6333 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
6334 emacs_event
->frame_or_window
= win
;
6335 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
6336 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
6337 emacs_event
->arg
= Qnil
;
6338 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
6339 XSETINT
(emacs_event
->y
, pixel_height
-20);
6341 n_emacs_events_pending
++;
6342 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
6343 EVENT_INIT
(*emacs_event
);
6344 ns_send_appdefined
(-1);
6348 /* called manually thru timer to implement repeated button action w/hold-down */
6349 - repeatScroll
: (NSTimer
*)scrollEntry
6351 NSEvent
*e
= [[self window
] currentEvent
];
6352 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
6353 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
6355 /* clear timer if need be */
6356 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
6358 [scroll_repeat_entry invalidate
];
6359 [scroll_repeat_entry release
];
6360 scroll_repeat_entry
= nil
;
6366 = [[NSTimer scheduledTimerWithTimeInterval
:
6367 SCROLL_BAR_CONTINUOUS_DELAY
6369 selector
: @selector
(repeatScroll
:)
6375 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
6380 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
6381 mouseDragged events without going into a modal loop. */
6382 - (void
)mouseDown
: (NSEvent
*)e
6385 /* hitPart is only updated AFTER event is passed on */
6386 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6387 double inc
= 0.0, loc
, kloc
, pos
;
6390 NSTRACE
(EmacsScroller_mouseDown
);
6394 case NSScrollerDecrementPage
:
6395 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6396 case NSScrollerIncrementPage
:
6397 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6398 case NSScrollerDecrementLine
:
6399 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6400 case NSScrollerIncrementLine
:
6401 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6402 case NSScrollerKnob
:
6403 last_hit_part
= scroll_bar_handle
; break;
6404 case NSScrollerKnobSlot
: /* GNUstep-only */
6405 last_hit_part
= scroll_bar_move_ratio
; break;
6406 default
: /* NSScrollerNoPart? */
6407 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
6414 pos
= 0; /* ignored */
6416 /* set a timer to repeat, as we can't let superclass do this modally */
6418 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
6420 selector
: @selector
(repeatScroll
:)
6427 /* handle, or on GNUstep possibly slot */
6428 NSEvent
*fake_event
;
6430 /* compute float loc in slot and mouse offset on knob */
6431 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6433 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6439 else if (loc
>= NSHeight
(sr
))
6441 loc
= NSHeight
(sr
);
6449 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6451 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6453 last_mouse_offset
= kloc
;
6455 /* if knob, tell emacs a location offset by knob pos
6456 (to indicate top of handle) */
6457 if (part
== NSScrollerKnob
)
6458 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6460 /* else this is a slot click on GNUstep: go straight there */
6461 pos
= loc
/ NSHeight
(sr
);
6463 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6464 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6465 location
: [e locationInWindow
]
6466 modifierFlags
: [e modifierFlags
]
6467 timestamp
: [e timestamp
]
6468 windowNumber
: [e windowNumber
]
6469 context
: [e context
]
6470 eventNumber
: [e eventNumber
]
6471 clickCount
: [e clickCount
]
6472 pressure
: [e pressure
]];
6473 [super mouseUp
: fake_event
];
6476 if (part
!= NSScrollerKnob
)
6477 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6481 /* Called as we manually track scroller drags, rather than superclass. */
6482 - (void
)mouseDragged
: (NSEvent
*)e
6488 NSTRACE
(EmacsScroller_mouseDragged
);
6490 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6492 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6499 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6501 loc
= NSHeight
(sr
) + last_mouse_offset
;
6505 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6506 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6510 - (void
)mouseUp
: (NSEvent
*)e
6512 if (scroll_repeat_entry
)
6514 [scroll_repeat_entry invalidate
];
6515 [scroll_repeat_entry release
];
6516 scroll_repeat_entry
= nil
;
6522 /* treat scrollwheel events in the bar as though they were in the main window */
6523 - (void
) scrollWheel
: (NSEvent
*)theEvent
6525 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6526 [view mouseDown
: theEvent
];
6529 @
end /* EmacsScroller */
6534 /* ==========================================================================
6536 Font-related functions; these used to be in nsfaces.m
6538 ========================================================================== */
6542 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6544 struct font
*font
= XFONT_OBJECT
(font_object
);
6547 fontset
= fontset_from_font
(font_object
);
6548 FRAME_FONTSET
(f
) = fontset
;
6550 if (FRAME_FONT
(f
) == font
)
6551 /* This font is already set in frame F. There's nothing more to
6555 FRAME_FONT
(f
) = font
;
6557 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6558 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6559 FRAME_SPACE_WIDTH
(f
) = font
->space_width
;
6560 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6562 compute_fringe_widths
(f
, 1);
6564 /* Compute the scroll bar width in character columns. */
6565 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6567 int wid
= FRAME_COLUMN_WIDTH
(f
);
6568 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6569 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6573 int wid
= FRAME_COLUMN_WIDTH
(f
);
6574 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6577 /* Now make the frame display the given font. */
6578 if (FRAME_NS_WINDOW
(f
) != 0)
6579 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6585 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6586 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6590 ns_xlfd_to_fontname
(const
char *xlfd
)
6591 /* --------------------------------------------------------------------------
6592 Convert an X font name (XLFD) to an NS font name.
6593 Only family is used.
6594 The string returned is temporarily allocated.
6595 -------------------------------------------------------------------------- */
6597 char *name
= xmalloc
(180);
6601 if (!strncmp
(xlfd
, "
--"
, 2))
6602 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
6604 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
6606 /* stopgap for malformed XLFD input */
6607 if (strlen
(name
) == 0)
6608 strcpy
(name
, "Monaco"
);
6610 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
6611 also uppercase after '-' or ' ' */
6612 name
[0] = toupper
(name
[0]);
6613 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
6619 name
[i
+1] = toupper
(name
[i
+1]);
6621 else if (name
[i
] == '_')
6625 name
[i
+1] = toupper
(name
[i
+1]);
6628 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
6629 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
6636 syms_of_nsterm
(void
)
6638 NSTRACE
(syms_of_nsterm
);
6640 ns_antialias_threshold
= 10.0;
6642 /* from 23+ we need to tell emacs what modifiers there are.. */
6643 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
6644 DEFSYM
(Qalt
, "alt"
);
6645 DEFSYM
(Qhyper
, "hyper"
);
6646 DEFSYM
(Qmeta
, "
meta"
);
6647 DEFSYM
(Qsuper
, "super"
);
6648 DEFSYM
(Qcontrol
, "control"
);
6649 DEFSYM
(Qnone
, "none"
);
6650 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
6652 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
6653 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
6654 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
6655 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
6656 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
6658 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
6659 "The file specified in the last NS event."
);
6660 ns_input_file
=Qnil
;
6662 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
6663 "The data received in the last NS
text drag event."
);
6664 ns_input_text
=Qnil
;
6666 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
6667 "String
for visualizing working composition sequence."
);
6668 ns_working_text
=Qnil
;
6670 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
6671 "The font specified in the last NS event."
);
6672 ns_input_font
=Qnil
;
6674 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
6675 "The fontsize specified in the last NS event."
);
6676 ns_input_fontsize
=Qnil
;
6678 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
6679 "The
line specified in the last NS event."
);
6680 ns_input_line
=Qnil
;
6682 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
6683 "The color specified in the last NS event."
);
6684 ns_input_color
=Qnil
;
6686 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
6687 "The service name specified in the last NS event."
);
6688 ns_input_spi_name
=Qnil
;
6690 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
6691 "The service argument specified in the last NS event."
);
6692 ns_input_spi_arg
=Qnil
;
6694 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
6695 "This variable describes the behavior of the alternate or option key.
\n\
6696 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6697 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
6698 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6699 ns_alternate_modifier
= Qmeta
;
6701 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
6702 "This variable describes the behavior of the right alternate or option key.
\n\
6703 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6704 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
6705 Set to none means that the alternate / option key is not interpreted by Emacs\n\
6706 at all, allowing it to be used at a lower level for accented character entry.");
6707 ns_right_alternate_modifier = Qleft;
6709 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
6710 "This variable describes the behavior of the command key.\n\
6711 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
6712 ns_command_modifier = Qsuper;
6714 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
6715 "This variable describes the behavior of the right command key.\n\
6716 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6717 Set to left means be the same key as `ns-command-modifier'.
\n\
6718 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
6719 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6720 ns_right_command_modifier
= Qleft
;
6722 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
6723 "This variable describes the behavior of the control key.
\n\
6724 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
6725 ns_control_modifier
= Qcontrol
;
6727 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
6728 "This variable describes the behavior of the right control key.
\n\
6729 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6730 Set to left means be the same key as `ns
-control
-modifier
'.\n\
6731 Set to none means that the control / option key is not interpreted by Emacs\n\
6732 at all, allowing it to be used at a lower level for accented character entry.");
6733 ns_right_control_modifier = Qleft;
6735 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
6736 "This variable describes the behavior of the function key (on laptops).\n\
6737 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6738 Set to none means that the function key is not interpreted by Emacs at all,\n\
6739 allowing it to be used at a lower level for accented character entry.");
6740 ns_function_modifier = Qnone;
6742 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
6743 "Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above.");
6744 ns_antialias_text = Qt;
6746 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
6747 "Whether to confirm application quit using dialog.");
6748 ns_confirm_quit = Qnil;
6750 staticpro (&ns_display_name_list);
6751 ns_display_name_list = Qnil;
6753 staticpro (&last_mouse_motion_frame);
6754 last_mouse_motion_frame = Qnil;
6756 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
6757 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
6758 Only works on OSX 10.6 or later. */);
6759 ns_auto_hide_menu_bar = Qnil;
6761 /* TODO: move to common code */
6762 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
6763 doc: /* Which toolkit scroll bars Emacs uses, if any.
6764 A value of nil means Emacs doesn't use toolkit scroll bars.
6765 With the X Window system
, the value is a symbol describing the
6766 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
6767 With MS Windows or Nextstep
, the value is t. */
);
6768 Vx_toolkit_scroll_bars
= Qt
;
6770 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
6771 x_use_underline_position_properties
,
6772 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
6773 A value of nil means ignore them. If you encounter fonts with bogus
6774 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
6775 to 4.1, set this to nil. */);
6776 x_use_underline_position_properties
= 0;
6778 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
6779 x_underline_at_descent_line
,
6780 doc: /* Non-nil means to draw the underline at the same place as the descent line.
6781 A value of nil means to draw the underline according to the value of the
6782 variable `x-use-underline-position-properties', which is usually at the
6783 baseline level. The default value is nil. */);
6784 x_underline_at_descent_line
= 0;
6786 /* Tell emacs about this window system. */
6787 Fprovide
(intern
("ns"
), Qnil
);