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
)
69 /* ==========================================================================
73 ========================================================================== */
75 /* Convert a symbol indexed with an NSxxx value to a value as defined
76 in keyboard.c (lispy_function_key). I hope this is a correct way
78 static unsigned convert_ns_to_X_keysym
[] =
80 NSHomeFunctionKey
, 0x50,
81 NSLeftArrowFunctionKey
, 0x51,
82 NSUpArrowFunctionKey
, 0x52,
83 NSRightArrowFunctionKey
, 0x53,
84 NSDownArrowFunctionKey
, 0x54,
85 NSPageUpFunctionKey
, 0x55,
86 NSPageDownFunctionKey
, 0x56,
87 NSEndFunctionKey
, 0x57,
88 NSBeginFunctionKey
, 0x58,
89 NSSelectFunctionKey
, 0x60,
90 NSPrintFunctionKey
, 0x61,
91 NSExecuteFunctionKey
, 0x62,
92 NSInsertFunctionKey
, 0x63,
93 NSUndoFunctionKey
, 0x65,
94 NSRedoFunctionKey
, 0x66,
95 NSMenuFunctionKey
, 0x67,
96 NSFindFunctionKey
, 0x68,
97 NSHelpFunctionKey
, 0x6A,
98 NSBreakFunctionKey
, 0x6B,
100 NSF1FunctionKey
, 0xBE,
101 NSF2FunctionKey
, 0xBF,
102 NSF3FunctionKey
, 0xC0,
103 NSF4FunctionKey
, 0xC1,
104 NSF5FunctionKey
, 0xC2,
105 NSF6FunctionKey
, 0xC3,
106 NSF7FunctionKey
, 0xC4,
107 NSF8FunctionKey
, 0xC5,
108 NSF9FunctionKey
, 0xC6,
109 NSF10FunctionKey
, 0xC7,
110 NSF11FunctionKey
, 0xC8,
111 NSF12FunctionKey
, 0xC9,
112 NSF13FunctionKey
, 0xCA,
113 NSF14FunctionKey
, 0xCB,
114 NSF15FunctionKey
, 0xCC,
115 NSF16FunctionKey
, 0xCD,
116 NSF17FunctionKey
, 0xCE,
117 NSF18FunctionKey
, 0xCF,
118 NSF19FunctionKey
, 0xD0,
119 NSF20FunctionKey
, 0xD1,
120 NSF21FunctionKey
, 0xD2,
121 NSF22FunctionKey
, 0xD3,
122 NSF23FunctionKey
, 0xD4,
123 NSF24FunctionKey
, 0xD5,
125 NSBackspaceCharacter
, 0x08, /* 8: Not on some KBs. */
126 NSDeleteCharacter
, 0xFF, /* 127: Big 'delete' key upper right. */
127 NSDeleteFunctionKey
, 0x9F, /* 63272: Del forw key off main array. */
129 NSTabCharacter
, 0x09,
130 0x19, 0x09, /* left tab->regular since pass shift */
131 NSCarriageReturnCharacter
, 0x0D,
132 NSNewlineCharacter
, 0x0D,
133 NSEnterCharacter
, 0x8D,
135 0x1B, 0x1B /* escape */
138 static Lisp_Object Qmodifier_value
;
139 Lisp_Object Qalt
, Qcontrol
, Qhyper
, Qmeta
, Qsuper
, Qnone
;
140 extern Lisp_Object Qcursor_color
, Qcursor_type
, Qns
, Qleft
;
142 static Lisp_Object QUTF8_STRING
;
144 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
145 the maximum font size to NOT antialias. On GNUstep there is currently
146 no way to control this behavior. */
147 float ns_antialias_threshold
;
149 /* Used to pick up AppleHighlightColor on OS X */
150 NSString
*ns_selection_color
;
152 NSArray
*ns_send_types
=0, *ns_return_types
=0, *ns_drag_types
=0;
153 NSString
*ns_app_name
= @"Emacs"
; /* default changed later */
155 /* Display variables */
156 struct ns_display_info
*x_display_list
; /* Chain of existing displays */
157 Lisp_Object ns_display_name_list
;
158 long context_menu_value
= 0;
161 NSPoint last_mouse_motion_position
;
162 static NSRect last_mouse_glyph
;
163 static Time last_mouse_movement_time
= 0;
164 static Lisp_Object last_mouse_motion_frame
;
165 static EmacsScroller
*last_mouse_scroll_bar
= nil
;
166 static
struct frame
*ns_updating_frame
;
167 static NSView
*focus_view
= NULL;
168 static int ns_window_num
= 0;
170 static BOOL gsaved
= NO
;
171 BOOL ns_in_resize
= NO
;
172 static BOOL ns_fake_keydown
= NO
;
173 int ns_tmp_flags
; /* FIXME */
174 struct nsfont_info
*ns_tmp_font
; /* FIXME */
175 static BOOL ns_menu_bar_is_hidden
= NO
;
176 /*static int debug_lock = 0; */
179 static BOOL send_appdefined
= YES
;
180 static NSEvent
*last_appdefined_event
= 0;
181 static NSTimer
*timed_entry
= 0;
182 static NSTimer
*fd_entry
= nil
;
183 static NSTimer
*scroll_repeat_entry
= nil
;
184 static fd_set select_readfds
, t_readfds
;
185 static
struct timeval select_timeout
;
186 static int select_nfds
;
187 static NSAutoreleasePool
*outerpool
;
188 static
struct input_event
*emacs_event
= NULL;
189 static
struct input_event
*q_event_ptr
= NULL;
190 static int n_emacs_events_pending
= 0;
191 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
192 *ns_pending_service_args
;
193 static BOOL inNsSelect
= 0;
195 /* Convert modifiers in a NeXTstep event to emacs style modifiers. */
196 #define NS_FUNCTION_KEY_MASK
0x800000
197 #define NSLeftControlKeyMask
(0x000001 | NSControlKeyMask
)
198 #define NSRightControlKeyMask
(0x002000 | NSControlKeyMask
)
199 #define NSLeftCommandKeyMask
(0x000008 | NSCommandKeyMask
)
200 #define NSRightCommandKeyMask
(0x000010 | NSCommandKeyMask
)
201 #define NSLeftAlternateKeyMask
(0x000020 | NSAlternateKeyMask
)
202 #define NSRightAlternateKeyMask
(0x000040 | NSAlternateKeyMask
)
203 #define EV_MODIFIERS
(e
) \
204 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
205 hyper_modifier
: 0) \
206 |
(!EQ
(ns_right_alternate_modifier
, Qleft
) && \
207 (([e modifierFlags
] & NSRightAlternateKeyMask
) \
208 == NSRightAlternateKeyMask
) ? \
209 parse_solitary_modifier
(ns_right_alternate_modifier
) : 0) \
210 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
211 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
212 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
213 shift_modifier
: 0) \
214 |
(!EQ
(ns_right_control_modifier
, Qleft
) && \
215 (([e modifierFlags
] & NSRightControlKeyMask
) \
216 == NSRightControlKeyMask
) ? \
217 parse_solitary_modifier
(ns_right_control_modifier
) : 0) \
218 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
219 parse_solitary_modifier
(ns_control_modifier
) : 0) \
220 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
221 parse_solitary_modifier
(ns_function_modifier
) : 0) \
222 |
(!EQ
(ns_right_command_modifier
, Qleft
) && \
223 (([e modifierFlags
] & NSRightCommandKeyMask
) \
224 == NSRightCommandKeyMask
) ? \
225 parse_solitary_modifier
(ns_right_command_modifier
) : 0) \
226 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
227 parse_solitary_modifier
(ns_command_modifier
):0))
229 #define EV_UDMODIFIERS
(e
) \
230 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
231 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
232 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
233 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
234 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
235 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
236 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
237 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
238 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
240 #define EV_BUTTON
(e
) \
241 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
242 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
243 [e buttonNumber
] - 1)
245 /* Convert the time field to a timestamp in milliseconds. */
246 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
248 /* This is a piece of code which is common to all the event handling
249 methods. Maybe it should even be a function. */
250 #define EV_TRAILER
(e
) \
252 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
253 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
254 n_emacs_events_pending
++; \
255 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
256 EVENT_INIT
(*emacs_event
); \
257 ns_send_appdefined
(-1); \
260 void x_set_cursor_type
(struct frame
*, Lisp_Object
, Lisp_Object
);
262 /* TODO: get rid of need for these forward declarations */
263 static void ns_condemn_scroll_bars
(struct frame
*f
);
264 static void ns_judge_scroll_bars
(struct frame
*f
);
265 void x_set_frame_alpha
(struct frame
*f
);
268 /* ==========================================================================
272 ========================================================================== */
276 append2
(Lisp_Object list
, Lisp_Object item
)
277 /* --------------------------------------------------------------------------
278 Utility to append to a list
279 -------------------------------------------------------------------------- */
281 Lisp_Object array
[2];
283 array
[1] = Fcons
(item
, Qnil
);
284 return Fnconc
(2, &array
[0]);
290 /* --------------------------------------------------------------------------
291 Used to allow emacs to find its resources under Emacs.app
292 Called from emacs.c at startup.
293 -------------------------------------------------------------------------- */
295 NSBundle
*bundle
= [NSBundle mainBundle
];
296 NSString
*binDir
= [bundle bundlePath
], *resourceDir
= [bundle resourcePath
];
297 NSString
*resourcePath
, *resourcePaths
;
299 BOOL onWindows
= NO
; /* how do I determine this? */
300 NSString
*pathSeparator
= onWindows ? @"
;"
: @"
:"
;
301 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
303 /*NSLog (@"ns_init_paths: '%@'\n%@\n", [[NSBundle mainBundle] bundlePath], [[NSBundle mainBundle] resourcePath]); */
305 /* get bindir from base */
306 range
= [resourceDir rangeOfString
: @"Contents"
];
307 if (range.location
!= NSNotFound
)
309 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
311 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
315 /* the following based on Andrew Choi's init_mac_osx_environment () */
316 if (!getenv ("EMACSLOADPATH"
))
318 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
319 [NSArray arrayWithObjects
:
320 @"site
-lisp"
, @"lisp"
, @"leim"
, nil
]];
321 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
323 while (resourcePath
= [pathEnum nextObject
])
325 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
328 if ([resourcePaths
length] > 0)
330 = [resourcePaths stringByAppendingString
: pathSeparator
];
332 = [resourcePaths stringByAppendingString
: resourcePath
];
335 if ([resourcePaths
length] > 0)
336 setenv
("EMACSLOADPATH"
, [resourcePaths UTF8String
], 1);
337 /*NSLog (@"loadPath: '%@'\n", resourcePaths); */
340 if (!getenv ("EMACSPATH"
))
342 NSArray
*paths
= [binDir stringsByAppendingPaths
:
343 [NSArray arrayWithObjects
: @"bin"
,
345 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
347 while (resourcePath
= [pathEnum nextObject
])
349 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
352 if ([resourcePaths
length] > 0)
354 = [resourcePaths stringByAppendingString
: pathSeparator
];
356 = [resourcePaths stringByAppendingString
: resourcePath
];
359 if ([resourcePaths
length] > 0)
360 setenv
("EMACSPATH"
, [resourcePaths UTF8String
], 1);
363 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
364 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
368 if (!getenv ("EMACSDATA"
))
369 setenv
("EMACSDATA"
, [resourcePath UTF8String
], 1);
370 if (!getenv ("EMACSDOC"
))
371 setenv
("EMACSDOC"
, [resourcePath UTF8String
], 1);
375 if (!getenv ("INFOPATH"
))
377 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"
info"
];
378 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
380 setenv
("INFOPATH"
, [[resourcePath stringByAppendingString
: @"
:"
]
382 /* Note, extra colon needed to cause merge w/later user additions. */
388 timeval_subtract
(struct timeval
*result
, struct timeval x
, struct timeval y
)
389 /* --------------------------------------------------------------------------
390 Subtract the `struct timeval' values X and Y, storing the result in RESULT.
391 Return 1 if the difference is negative, otherwise 0.
392 -------------------------------------------------------------------------- */
394 /* Perform the carry for the later subtraction by updating y.
395 This is safer because on some systems
396 the tv_sec member is unsigned. */
397 if (x.tv_usec
< y.tv_usec
)
399 int nsec
= (y.tv_usec
- x.tv_usec
) / 1000000 + 1;
400 y.tv_usec
-= 1000000 * nsec
;
403 if (x.tv_usec
- y.tv_usec
> 1000000)
405 int nsec
= (y.tv_usec
- x.tv_usec
) / 1000000;
406 y.tv_usec
+= 1000000 * nsec
;
410 /* Compute the time remaining to wait. tv_usec is certainly positive. */
411 result
->tv_sec
= x.tv_sec
- y.tv_sec
;
412 result
->tv_usec
= x.tv_usec
- y.tv_usec
;
414 /* Return indication of whether the result should be considered negative. */
415 return x.tv_sec
< y.tv_sec
;
419 ns_timeout
(int usecs
)
420 /* --------------------------------------------------------------------------
421 Blocking timer utility used by ns_ring_bell
422 -------------------------------------------------------------------------- */
424 struct timeval wakeup
;
426 EMACS_GET_TIME
(wakeup
);
428 /* Compute time to wait until, propagating carry from usecs. */
429 wakeup.tv_usec
+= usecs
;
430 wakeup.tv_sec
+= (wakeup.tv_usec
/ 1000000);
431 wakeup.tv_usec
%= 1000000;
433 /* Keep waiting until past the time wakeup. */
436 struct timeval timeout
;
438 EMACS_GET_TIME
(timeout
);
440 /* In effect, timeout = wakeup - timeout.
441 Break if result would be negative. */
442 if (timeval_subtract
(&timeout
, wakeup
, timeout
))
445 /* Try to wait that long--but we might wake up sooner. */
446 select
(0, NULL, NULL, NULL, &timeout
);
452 ns_release_object
(void
*obj
)
453 /* --------------------------------------------------------------------------
454 Release an object (callable from C)
455 -------------------------------------------------------------------------- */
462 ns_retain_object
(void
*obj
)
463 /* --------------------------------------------------------------------------
464 Retain an object (callable from C)
465 -------------------------------------------------------------------------- */
472 ns_alloc_autorelease_pool
(void
)
473 /* --------------------------------------------------------------------------
474 Allocate a pool for temporary objects (callable from C)
475 -------------------------------------------------------------------------- */
477 return [[NSAutoreleasePool alloc
] init
];
482 ns_release_autorelease_pool
(void
*pool
)
483 /* --------------------------------------------------------------------------
484 Free a pool and temporary objects it refers to (callable from C)
485 -------------------------------------------------------------------------- */
487 ns_release_object
(pool
);
492 /* ==========================================================================
494 Focus (clipping) and screen update
496 ========================================================================== */
499 ns_resize_handle_rect
(NSWindow
*window
)
501 NSRect r
= [window frame
];
502 r.origin.x
= r.
size.width
- RESIZE_HANDLE_SIZE
;
504 r.
size.width
= r.
size.height
= RESIZE_HANDLE_SIZE
;
510 // Window constraining
511 // -------------------
513 // To ensure that the windows are not placed under the
menu bar, they
514 // are typically moved by the call
-back constrainFrameRect. However
,
515 // by overriding it
, it
's possible to inhibit this, leaving the window
516 // in it's original position.
518 // It
's possible to hide the menu bar. However, technically, it's only
519 // possible to hide it when the application is active. To ensure that
520 // this work properly
, the
menu bar and window constraining are
521 // deferred until the application becomes active.
523 // Even though it
's not possible to manually move a window above the
524 // top of the screen, it is allowed if it's done programmatically
,
525 // when the
menu is
hidden. This allows the editable area to cover the
526 // full screen height.
531 // Use the following extra files
:
534 // ;; Hide
menu and place frame slightly above the top of the screen.
535 // (setq ns
-auto
-hide
-menu-bar t
)
536 // (set-frame
-position
(selected
-frame
) 0 -20)
540 // emacs
-Q
-l init.el
542 // Result
: No
menu bar, and the
title bar should be above the screen.
548 // Result
: Menu bar visible
, frame placed immediately below the
menu.
552 ns_constrain_all_frames
(void
)
554 Lisp_Object tail
, frame
;
556 FOR_EACH_FRAME
(tail
, frame
)
558 struct frame
*f
= XFRAME
(frame
);
561 NSView
*view = FRAME_NS_VIEW
(f
);
562 /* This no-op will trigger the default window placing
563 * constraint system. */
564 f
->output_data.ns
->dont_constrain
= 0;
565 [[view window
] setFrameOrigin
:[[view window
] frame
].origin
];
571 /* True, if the menu bar should be hidden. */
574 ns_menu_bar_should_be_hidden
(void
)
576 return !NILP
(ns_auto_hide_menu_bar
)
577 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)];
581 /* Show or hide the menu bar, based on user setting. */
584 ns_update_auto_hide_menu_bar
(void
)
586 #ifndef MAC_OS_X_VERSION_10_6
587 #define MAC_OS_X_VERSION_10_6
1060
590 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
593 NSTRACE
(ns_update_auto_hide_menu_bar
);
597 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)])
599 // Note
, "setPresentationOptions" triggers an
error unless the
600 // application is active.
601 BOOL menu_bar_should_be_hidden
= ns_menu_bar_should_be_hidden
();
603 if (menu_bar_should_be_hidden
!= ns_menu_bar_is_hidden
)
605 NSApplicationPresentationOptions options
606 = NSApplicationPresentationAutoHideDock
;
608 if (menu_bar_should_be_hidden
)
609 options |
= NSApplicationPresentationAutoHideMenuBar
;
611 [NSApp setPresentationOptions
: options
];
613 ns_menu_bar_is_hidden
= menu_bar_should_be_hidden
;
615 if (!ns_menu_bar_is_hidden
)
617 ns_constrain_all_frames
();
629 ns_update_begin
(struct frame
*f
)
630 /* --------------------------------------------------------------------------
631 Prepare for a grouped sequence of drawing calls
632 external (RIF) call; whole frame, called before update_window_begin
633 -------------------------------------------------------------------------- */
635 NSView
*view = FRAME_NS_VIEW
(f
);
636 NSTRACE
(ns_update_begin
);
638 ns_update_auto_hide_menu_bar
();
640 ns_updating_frame
= f
;
643 #ifdef NS_IMPL_GNUSTEP
644 uRect
= NSMakeRect
(0, 0, 0, 0);
650 ns_update_window_begin
(struct window
*w
)
651 /* --------------------------------------------------------------------------
652 Prepare for a grouped sequence of drawing calls
653 external (RIF) call; for one window, called after update_begin
654 -------------------------------------------------------------------------- */
656 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
657 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
658 NSTRACE
(ns_update_window_begin
);
661 set_output_cursor
(&w
->cursor
);
665 if (f
== hlinfo
->mouse_face_mouse_frame
)
667 /* Don't do highlighting for mouse motion during the update. */
668 hlinfo
->mouse_face_defer
= 1;
670 /* If the frame needs to be redrawn,
671 simply forget about any prior mouse highlighting. */
672 if (FRAME_GARBAGED_P
(f
))
673 hlinfo
->mouse_face_window
= Qnil
;
675 /* (further code for mouse faces ifdef'd out in other terms elided) */
683 ns_update_window_end
(struct window
*w
, int cursor_on_p
,
684 int mouse_face_overwritten_p
)
685 /* --------------------------------------------------------------------------
686 Finished a grouped sequence of drawing calls
687 external (RIF) call; for one window called before update_end
688 -------------------------------------------------------------------------- */
690 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(XFRAME
(w
->frame
));
692 /* note: this fn is nearly identical in all terms */
693 if (!w
->pseudo_window_p
)
698 display_and_set_cursor
(w
, 1,
699 output_cursor.hpos
, output_cursor.vpos
,
700 output_cursor.x
, output_cursor.y
);
702 if (draw_window_fringes
(w
, 1))
703 x_draw_vertical_border
(w
);
708 /* If a row with mouse-face was overwritten, arrange for
709 frame_up_to_date to redisplay the mouse highlight. */
710 if (mouse_face_overwritten_p
)
712 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
713 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
714 hlinfo
->mouse_face_window
= Qnil
;
717 updated_window
= NULL;
718 NSTRACE
(update_window_end
);
723 ns_update_end
(struct frame
*f
)
724 /* --------------------------------------------------------------------------
725 Finished a grouped sequence of drawing calls
726 external (RIF) call; for whole frame, called after update_window_end
727 -------------------------------------------------------------------------- */
729 NSView
*view = FRAME_NS_VIEW
(f
);
731 /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
732 MOUSE_HL_INFO
(f
)->mouse_face_defer
= 0;
736 #ifdef NS_IMPL_GNUSTEP
737 /* trigger flush only in the rectangle we tracked as being drawn */
738 [view unlockFocusNeedsFlush
: NO
];
739 /*fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", uRect.origin.x, uRect.origin.y, uRect.size.width, uRect.size.height); */
740 [view lockFocusInRect
: uRect
];
744 [[view window
] flushWindow
];
747 ns_updating_frame
= NULL;
748 NSTRACE
(ns_update_end
);
753 ns_flush
(struct frame
*f
)
754 /* --------------------------------------------------------------------------
756 NS impl is no-op since currently we flush in ns_update_end and elsewhere
757 -------------------------------------------------------------------------- */
764 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
765 /* --------------------------------------------------------------------------
766 Internal: Focus on given frame. During small local updates this is used to
767 draw, however during large updates, ns_update_begin and ns_update_end are
768 called to wrap the whole thing, in which case these calls are stubbed out.
769 Except, on GNUstep, we accumulate the rectangle being drawn into, because
770 the back end won't do this automatically, and will just end up flushing
772 -------------------------------------------------------------------------- */
774 // NSTRACE
(ns_focus
);
775 #ifdef NS_IMPL_GNUSTEP
778 u
= NSUnionRect
(r
[0], r
[1]);
783 fprintf (stderr, "focus: %d", c++);
784 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
785 fprintf (stderr, "\n"); */
787 if (f
!= ns_updating_frame
)
789 NSView
*view = FRAME_NS_VIEW
(f
);
790 if (view != focus_view
)
792 if (focus_view
!= NULL)
794 [focus_view unlockFocus
];
795 [[focus_view window
] flushWindow
];
800 #ifdef NS_IMPL_GNUSTEP
801 r ?
[view lockFocusInRect
: u
] : [view lockFocus
];
806 /*if (view) debug_lock++; */
808 #ifdef NS_IMPL_GNUSTEP
811 /* more than one rect being drawn into */
814 [view unlockFocus
]; /* add prev rect to redraw list */
815 [view lockFocusInRect
: u
]; /* focus for draw in new rect */
820 #ifdef NS_IMPL_GNUSTEP
823 /* in batch mode, but in GNUstep must still track rectangles explicitly */
824 uRect
= (r ? NSUnionRect
(uRect
, u
) : [FRAME_NS_VIEW
(f
) visibleRect
]);
831 [[NSGraphicsContext currentContext
] saveGraphicsState
];
833 NSRectClipList
(r
, 2);
842 ns_unfocus
(struct frame
*f
)
843 /* --------------------------------------------------------------------------
844 Internal: Remove focus on given frame
845 -------------------------------------------------------------------------- */
847 // NSTRACE
(ns_unfocus
);
851 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
855 if (f
!= ns_updating_frame
)
857 if (focus_view
!= NULL)
859 [focus_view unlockFocus
];
860 [[focus_view window
] flushWindow
];
869 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
, int area
, BOOL gc
)
870 /* --------------------------------------------------------------------------
871 Internal (but parallels other terms): Focus drawing on given row
872 -------------------------------------------------------------------------- */
874 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
876 int window_x
, window_y
, window_width
;
878 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
880 clip_rect.origin.x
= window_x
- FRAME_INTERNAL_BORDER_WIDTH
(f
);
881 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
882 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
883 clip_rect.
size.width
= window_width
+ 2 * FRAME_INTERNAL_BORDER_WIDTH
(f
);
884 clip_rect.
size.height
= row
->visible_height
;
886 /* allow a full-height row at the top when requested
887 (used to draw fringe all the way through internal border area) */
888 if (gc
&& clip_rect.origin.y
< 5)
890 clip_rect.origin.y
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
891 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
894 /* likewise at bottom */
896 FRAME_PIXEL_HEIGHT
(f
) - (clip_rect.origin.y
+ clip_rect.
size.height
) < 5)
897 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
899 ns_focus
(f
, &clip_rect
, 1);
904 ns_ring_bell
(struct frame
*f
)
905 /* --------------------------------------------------------------------------
907 -------------------------------------------------------------------------- */
909 NSTRACE
(ns_ring_bell
);
912 NSAutoreleasePool
*pool
;
913 struct frame
*frame
= SELECTED_FRAME
();
917 pool
= [[NSAutoreleasePool alloc
] init
];
919 view = FRAME_NS_VIEW
(frame
);
923 NSPoint dim
= NSMakePoint
(128, 128);
926 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
927 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
928 r.
size.width
= dim.x
;
929 r.
size.height
= dim.y
;
930 surr
= NSInsetRect
(r
, -2, -2);
931 ns_focus
(frame
, &surr
, 1);
932 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
933 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
934 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
936 [[view window
] flushWindow
];
938 [[view window
] restoreCachedImage
];
939 [[view window
] flushWindow
];
953 ns_reset_terminal_modes
(struct terminal *terminal)
954 /* Externally called as hook */
956 NSTRACE
(ns_reset_terminal_modes
);
961 ns_set_terminal_modes
(struct terminal *terminal)
962 /* Externally called as hook */
964 NSTRACE
(ns_set_terminal_modes
);
969 /* ==========================================================================
971 Frame / window manager related functions
973 ========================================================================== */
977 ns_raise_frame
(struct frame
*f
)
978 /* --------------------------------------------------------------------------
979 Bring window to foreground and make it active
980 -------------------------------------------------------------------------- */
982 NSView
*view = FRAME_NS_VIEW
(f
);
985 FRAME_SAMPLE_VISIBILITY
(f
);
986 if (FRAME_VISIBLE_P
(f
))
988 [[view window
] makeKeyAndOrderFront
: NSApp
];
995 ns_lower_frame
(struct frame
*f
)
996 /* --------------------------------------------------------------------------
998 -------------------------------------------------------------------------- */
1000 NSView
*view = FRAME_NS_VIEW
(f
);
1003 [[view window
] orderBack
: NSApp
];
1009 ns_frame_raise_lower
(struct frame
*f
, int raise
)
1010 /* --------------------------------------------------------------------------
1012 -------------------------------------------------------------------------- */
1014 NSTRACE
(ns_frame_raise_lower
);
1024 ns_frame_rehighlight
(struct frame
*frame
)
1025 /* --------------------------------------------------------------------------
1026 External (hook): called on things like window switching within frame
1027 -------------------------------------------------------------------------- */
1029 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(frame
);
1030 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1032 NSTRACE
(ns_frame_rehighlight
);
1033 if (dpyinfo
->x_focus_frame
)
1035 dpyinfo
->x_highlight_frame
1036 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1037 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1038 : dpyinfo
->x_focus_frame
);
1039 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
1041 FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
) = Qnil
;
1042 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1046 dpyinfo
->x_highlight_frame
= 0;
1048 if (dpyinfo
->x_highlight_frame
&&
1049 dpyinfo
->x_highlight_frame
!= old_highlight
)
1053 x_update_cursor
(old_highlight
, 1);
1054 x_set_frame_alpha
(old_highlight
);
1056 if (dpyinfo
->x_highlight_frame
)
1058 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
1059 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
1066 x_make_frame_visible
(struct frame
*f
)
1067 /* --------------------------------------------------------------------------
1068 External: Show the window (X11 semantics)
1069 -------------------------------------------------------------------------- */
1071 NSTRACE
(x_make_frame_visible
);
1072 /* XXX: at some points in past this was not needed, as the only place that
1073 called this (frame.c:Fraise_frame ()) also called raise_lower;
1074 if this ends up the case again, comment this out again. */
1075 if (!FRAME_VISIBLE_P
(f
))
1077 f
->async_visible
= 1;
1084 x_make_frame_invisible
(struct frame
*f
)
1085 /* --------------------------------------------------------------------------
1086 External: Hide the window (X11 semantics)
1087 -------------------------------------------------------------------------- */
1089 NSView
* view = FRAME_NS_VIEW
(f
);
1090 NSTRACE
(x_make_frame_invisible
);
1092 [[view window
] orderOut
: NSApp
];
1093 f
->async_visible
= 0;
1094 f
->async_iconified
= 0;
1099 x_iconify_frame
(struct frame
*f
)
1100 /* --------------------------------------------------------------------------
1101 External: Iconify window
1102 -------------------------------------------------------------------------- */
1104 NSView
* view = FRAME_NS_VIEW
(f
);
1105 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1106 NSTRACE
(x_iconify_frame
);
1109 if (dpyinfo
->x_highlight_frame
== f
)
1110 dpyinfo
->x_highlight_frame
= 0;
1112 if ([[view window
] windowNumber
] <= 0)
1114 /* the window is still deferred. Make it very small, bring it
1115 on screen and order it out. */
1116 NSRect s
= { { 100, 100}, {0, 0} };
1118 t
= [[view window
] frame
];
1119 [[view window
] setFrame
: s display
: NO
];
1120 [[view window
] orderBack
: NSApp
];
1121 [[view window
] orderOut
: NSApp
];
1122 [[view window
] setFrame
: t display
: NO
];
1124 [[view window
] miniaturize
: NSApp
];
1127 /* Free X resources of frame F. */
1130 x_free_frame_resources
(struct frame
*f
)
1132 NSView
*view = FRAME_NS_VIEW
(f
);
1133 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1134 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1135 NSTRACE
(x_destroy_window
);
1138 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1142 free_frame_menubar
(f
);
1144 if (FRAME_FACE_CACHE
(f
))
1145 free_frame_faces
(f
);
1147 if (f
== dpyinfo
->x_focus_frame
)
1148 dpyinfo
->x_focus_frame
= 0;
1149 if (f
== dpyinfo
->x_highlight_frame
)
1150 dpyinfo
->x_highlight_frame
= 0;
1151 if (f
== hlinfo
->mouse_face_mouse_frame
)
1153 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1154 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1155 hlinfo
->mouse_face_window
= Qnil
;
1156 hlinfo
->mouse_face_deferred_gc
= 0;
1157 hlinfo
->mouse_face_mouse_frame
= 0;
1160 xfree
(f
->output_data.ns
);
1162 if (f
->output_data.ns
->miniimage
!= nil
)
1163 [f
->output_data.ns
->miniimage release
];
1165 [[view window
] close];
1172 x_destroy_window
(struct frame
*f
)
1173 /* --------------------------------------------------------------------------
1174 External: Delete the window
1175 -------------------------------------------------------------------------- */
1177 NSTRACE
(x_destroy_window
);
1179 x_free_frame_resources
(f
);
1185 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1186 /* --------------------------------------------------------------------------
1187 External: Position the window
1188 -------------------------------------------------------------------------- */
1190 NSView
*view = FRAME_NS_VIEW
(f
);
1191 NSArray
*screens
= [NSScreen screens
];
1192 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1193 NSScreen
*screen
= [[view window
] screen
];
1195 NSTRACE
(x_set_offset
);
1202 if (view != nil
&& screen
&& fscreen
)
1204 f
->left_pos
= f
->size_hint_flags
& XNegative
1205 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1207 /* We use visibleFrame here to take menu bar into account.
1208 Ideally we should also adjust left/top with visibleFrame.origin. */
1210 f
->top_pos
= f
->size_hint_flags
& YNegative
1211 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1212 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1213 - FRAME_TOOLBAR_HEIGHT
(f
))
1215 #ifdef NS_IMPL_GNUSTEP
1216 if (f
->left_pos
< 100)
1217 f
->left_pos
= 100; /* don't overlap menu */
1219 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1221 f
->output_data.ns
->dont_constrain
= 0;
1222 [[view window
] setFrameTopLeftPoint
:
1223 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1224 SCREENMAXBOUND
([fscreen frame
].
size.height
1225 - NS_TOP_POS
(f
)))];
1226 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1234 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1235 /* --------------------------------------------------------------------------
1236 Adjust window pixel size based on given character grid size
1237 Impl is a bit more complex than other terms, need to do some
1239 -------------------------------------------------------------------------- */
1241 EmacsView
*view = FRAME_NS_VIEW
(f
);
1242 EmacsToolbar
*toolbar
= [view toolbar
];
1243 NSWindow
*window
= [view window
];
1244 NSRect wr
= [window frame
];
1245 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1246 int pixelwidth
, pixelheight
;
1247 static int oldRows
, oldCols
, oldFontWidth
, oldFontHeight
;
1249 static
struct frame
*oldF
;
1251 NSTRACE
(x_set_window_size
);
1255 && rows
== oldRows
&& cols
== oldCols
1256 && oldFontWidth
== FRAME_COLUMN_WIDTH
(f
)
1257 && oldFontHeight
== FRAME_LINE_HEIGHT
(f
)
1261 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1265 check_frame_size
(f
, &rows
, &cols
);
1269 oldFontWidth
= FRAME_COLUMN_WIDTH
(f
);
1270 oldFontHeight
= FRAME_LINE_HEIGHT
(f
);
1273 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1274 compute_fringe_widths
(f
, 0);
1276 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1277 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1279 /* If we have a toolbar, take its height into account. */
1281 /* NOTE: previously this would generate wrong result if toolbar not
1282 yet displayed and fixing toolbar_height=32 helped, but
1283 now (200903) seems no longer needed */
1284 FRAME_TOOLBAR_HEIGHT
(f
) =
1285 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1286 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1288 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1290 wr.
size.width
= pixelwidth
+ f
->border_width
;
1291 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1292 + FRAME_TOOLBAR_HEIGHT
(f
);
1294 /* Do not try to constrain to this screen. We may have multiple
1295 screens, and want Emacs to span those. Constraining to screen
1296 prevents that, and that is not nice to the user. */
1297 if (f
->output_data.ns
->zooming
)
1298 f
->output_data.ns
->zooming
= 0;
1300 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1302 [view setRows
: rows andColumns
: cols
];
1303 [window setFrame
: wr display
: YES
];
1305 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1307 /* This is a trick to compensate for Emacs' managing the scrollbar area
1308 as a fixed number of standard character columns. Instead of leaving
1309 blank space for the extra, we chopped it off above. Now for
1310 left-hand scrollbars, we shift all rendering to the left by the
1311 difference between the real width and Emacs' imagined one. For
1312 right-hand bars, don't worry about it since the extra is never used.
1313 (Obviously doesn't work for vertically split windows tho..) */
1315 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1316 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1317 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1318 : NSMakePoint
(0, 0);
1319 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1320 [view setBoundsOrigin
: origin
];
1323 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1324 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1325 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1326 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1328 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1329 cancel_mouse_face
(f
);
1336 /* ==========================================================================
1340 ========================================================================== */
1344 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1346 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1347 if (idx
< 1 || idx
>= color_table
->avail
)
1349 return color_table
->colors
[idx
];
1354 ns_index_color
(NSColor
*color
, struct frame
*f
)
1356 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1360 if (!color_table
->colors
)
1362 color_table
->size = NS_COLOR_CAPACITY
;
1363 color_table
->avail
= 1; /* skip idx=0 as marker */
1365 = (NSColor
**)xmalloc
(color_table
->size * sizeof
(NSColor
*));
1366 color_table
->colors
[0] = nil
;
1367 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1370 /* do we already have this color ? */
1371 for (i
= 1; i
< color_table
->avail
; i
++)
1372 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1375 if ([color_table
->empty_indices count
] > 0)
1377 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1378 [color_table
->empty_indices removeObject
: index
];
1379 idx
= [index unsignedLongValue
];
1383 if (color_table
->avail
== color_table
->size)
1384 color_table
->colors
=
1385 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1386 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1387 idx
= color_table
->avail
++;
1390 color_table
->colors
[idx
] = color
;
1392 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1398 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1400 struct ns_color_table
*color_table
;
1407 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1409 if (idx
<= 0 || idx
>= color_table
->size) {
1410 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1414 index
= [NSNumber numberWithUnsignedInt
: idx
];
1415 if ([color_table
->empty_indices containsObject
: index
]) {
1416 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1420 color
= color_table
->colors
[idx
];
1422 color_table
->colors
[idx
] = nil
;
1423 [color_table
->empty_indices addObject
: index
];
1424 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1429 ns_get_color
(const
char *name
, NSColor
**col
)
1430 /* --------------------------------------------------------------------------
1432 -------------------------------------------------------------------------- */
1433 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1434 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1435 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1438 static
char hex
[20];
1440 float r
= -1.0, g
, b
;
1441 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1443 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1446 if ([nsname isEqualToString
: @"ns_selection_color"
])
1448 nsname
= ns_selection_color
;
1449 name
= [ns_selection_color UTF8String
];
1452 /* First, check for some sort of numeric specification. */
1455 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1457 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1458 [scanner scanFloat
: &r
];
1459 [scanner scanFloat
: &g
];
1460 [scanner scanFloat
: &b
];
1462 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1464 strncpy
(hex
, name
+ 4, 19);
1466 scaling
= (strlen
(hex
) - 2) / 3;
1468 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1470 int len
= (strlen
(name
) - 1);
1471 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1473 scaling
= strlen
(name
+start
) / 3;
1474 for (i
=0; i
<3; i
++) {
1475 strncpy
(hex
+ i
* (scaling
+ 1), name
+ start
+ i
* scaling
, scaling
);
1476 hex
[(i
+1) * (scaling
+ 1) - 1] = '/';
1478 hex
[3 * (scaling
+ 1) - 1] = '\0';
1484 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1485 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1495 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1500 /* Otherwise, color is expected to be from a list */
1502 NSEnumerator
*lenum
, *cenum
;
1506 #ifdef NS_IMPL_GNUSTEP
1507 /* XXX: who is wrong, the requestor or the implementation? */
1508 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1510 nsname
= @"highlightColor"
;
1513 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1514 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1516 cenum
= [[clist allKeys
] objectEnumerator
];
1517 while ( (name
= [cenum nextObject
]) && new
== nil
)
1519 if ([name compare
: nsname
1520 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1521 new
= [clist colorWithKey
: name
];
1527 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1534 ns_get_color_default
(const
char *name
, NSColor
*dflt
)
1535 /* --------------------------------------------------------------------------
1536 Parse a color or use a default value
1537 -------------------------------------------------------------------------- */
1541 if (ns_get_color
(name
, &col
))
1549 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1550 /* --------------------------------------------------------------------------
1551 Convert a Lisp string object to a NS color
1552 -------------------------------------------------------------------------- */
1554 NSTRACE
(ns_lisp_to_color
);
1555 if (STRINGP
(color
))
1556 return ns_get_color
(SDATA
(color
), col
);
1557 else if (SYMBOLP
(color
))
1558 return ns_get_color
(SDATA
(SYMBOL_NAME
(color
)), col
);
1564 ns_color_to_lisp
(NSColor
*col
)
1565 /* --------------------------------------------------------------------------
1566 Convert a color to a lisp string with the RGB equivalent
1567 -------------------------------------------------------------------------- */
1569 CGFloat red
, green
, blue
, alpha
, gray;
1572 NSTRACE
(ns_color_to_lisp
);
1575 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1577 if ((str
=[[col colorNameComponent
] UTF8String
]))
1580 return build_string
((char *)str
);
1583 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1584 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1585 if (red
==green
&& red
==blue
)
1587 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1588 getWhite
: &gray alpha
: &alpha
];
1589 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1590 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1592 return build_string
(buf
);
1595 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1596 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1599 return build_string
(buf
);
1604 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1605 /* --------------------------------------------------------------------------
1606 Get ARGB values out of NSColor col and put them into color_def.
1607 If setPixel, set the pixel to a concatenated version.
1608 and set color_def pixel to the resulting index.
1609 -------------------------------------------------------------------------- */
1613 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1614 color_def
->red
= r
* 65535;
1615 color_def
->green
= g
* 65535;
1616 color_def
->blue
= b
* 65535;
1618 if (setPixel
== YES
)
1620 = ARGB_TO_ULONG
((int
)(a
*255),
1621 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1626 ns_defined_color
(struct frame
*f
,
1631 /* --------------------------------------------------------------------------
1632 Return 1 if named color found, and set color_def rgb accordingly.
1633 If makeIndex and alloc are nonzero put the color in the color_table,
1634 and set color_def pixel to the resulting index.
1635 If makeIndex is zero, set color_def pixel to ARGB.
1636 Return 0 if not found
1637 -------------------------------------------------------------------------- */
1640 NSTRACE
(ns_defined_color
);
1643 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1648 if (makeIndex
&& alloc
)
1649 color_def
->pixel
= ns_index_color
(col
, f
);
1650 ns_query_color
(col
, color_def
, !makeIndex
);
1657 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1658 /* --------------------------------------------------------------------------
1659 return an autoreleased RGB color
1660 -------------------------------------------------------------------------- */
1662 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1663 if (r
< 0.0) r
= 0.0;
1664 else if (r
> 1.0) r
= 1.0;
1665 if (g
< 0.0) g
= 0.0;
1666 else if (g
> 1.0) g
= 1.0;
1667 if (b
< 0.0) b
= 0.0;
1668 else if (b
> 1.0) b
= 1.0;
1669 if (a
< 0.0) a
= 0.0;
1670 else if (a
> 1.0) a
= 1.0;
1671 return (unsigned
long) ns_index_color
(
1672 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1677 x_set_frame_alpha
(struct frame
*f
)
1678 /* --------------------------------------------------------------------------
1679 change the entire-frame transparency
1680 -------------------------------------------------------------------------- */
1682 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1683 EmacsView
*view = FRAME_NS_VIEW
(f
);
1685 double alpha_min
= 1.0;
1687 if (dpyinfo
->x_highlight_frame
== f
)
1688 alpha
= f
->alpha
[0];
1690 alpha
= f
->alpha
[1];
1692 if (FLOATP
(Vframe_alpha_lower_limit
))
1693 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1694 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1695 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1699 else if (1.0 < alpha
)
1701 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1704 #ifdef NS_IMPL_COCOA
1705 [[view window
] setAlphaValue
: alpha
];
1710 /* ==========================================================================
1714 ========================================================================== */
1718 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1719 /* --------------------------------------------------------------------------
1720 Programmatically reposition mouse pointer in pixel coordinates
1721 -------------------------------------------------------------------------- */
1723 NSTRACE
(x_set_mouse_pixel_position
);
1726 /* FIXME: this does not work, and what about GNUstep? */
1727 #ifdef NS_IMPL_COCOA
1728 [FRAME_NS_VIEW
(f
) lockFocus
];
1729 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1730 [FRAME_NS_VIEW
(f
) unlockFocus
];
1737 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1738 /* --------------------------------------------------------------------------
1739 Programmatically reposition mouse pointer in character coordinates
1740 -------------------------------------------------------------------------- */
1744 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1745 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1747 if (pix_x
< 0) pix_x
= 0;
1748 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1750 if (pix_y
< 0) pix_y
= 0;
1751 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1753 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1758 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1759 /* ------------------------------------------------------------------------
1760 Called by EmacsView on mouseMovement events. Passes on
1761 to emacs mainstream code if we moved off of a rect of interest
1762 known as last_mouse_glyph.
1763 ------------------------------------------------------------------------ */
1765 // NSTRACE
(note_mouse_movement
);
1767 XSETFRAME
(last_mouse_motion_frame
, frame
);
1769 /* Note, this doesn't get called for enter/leave, since we don't have a
1770 position. Those are taken care of in the corresponding NSView methods. */
1772 /* has movement gone beyond last rect we were tracking? */
1773 if (x
< last_mouse_glyph.origin.x ||
1774 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1775 y
< last_mouse_glyph.origin.y ||
1776 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1778 ns_update_begin
(frame
);
1779 frame
->mouse_moved
= 1;
1780 note_mouse_highlight
(frame
, x
, y
);
1781 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1782 ns_update_end
(frame
);
1791 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1792 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1794 /* --------------------------------------------------------------------------
1795 External (hook): inform emacs about mouse position and hit parts.
1796 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1797 x & y should be position in the scrollbar (the whole bar, not the handle)
1798 and length of scrollbar respectively
1799 -------------------------------------------------------------------------- */
1804 Lisp_Object frame
, tail
;
1806 struct ns_display_info
*dpyinfo
;
1808 NSTRACE
(ns_mouse_position
);
1812 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1816 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1820 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1822 /* TODO: we do not use this path at the moment because drag events will
1823 go directly to the EmacsScroller. Leaving code in for now. */
1824 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1826 if (time
) *time
= last_mouse_movement_time
;
1827 last_mouse_scroll_bar
= nil
;
1831 /* Clear the mouse-moved flag for every frame on this display. */
1832 FOR_EACH_FRAME
(tail
, frame
)
1833 if (FRAME_NS_P
(XFRAME
(frame
))
1834 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1835 XFRAME
(frame
)->mouse_moved
= 0;
1837 last_mouse_scroll_bar
= nil
;
1838 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1839 f
= last_mouse_frame
;
1841 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1842 : SELECTED_FRAME
();
1844 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1846 view = FRAME_NS_VIEW
(*fp
);
1848 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1849 position
= [view convertPoint
: position fromView
: nil
];
1850 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1851 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1853 if (bar_window
) *bar_window
= Qnil
;
1854 if (part
) *part
= 0; /*scroll_bar_handle; */
1856 if (x
) XSETINT
(*x
, lrint
(position.x
));
1857 if (y
) XSETINT
(*y
, lrint
(position.y
));
1858 if (time
) *time
= last_mouse_movement_time
;
1868 ns_frame_up_to_date
(struct frame
*f
)
1869 /* --------------------------------------------------------------------------
1870 External (hook): Fix up mouse highlighting right after a full update.
1871 Some highlighting was deferred if GC was happening during
1872 note_mouse_highlight (), while other highlighting was deferred for update.
1873 -------------------------------------------------------------------------- */
1875 NSTRACE
(ns_frame_up_to_date
);
1879 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1880 if ((hlinfo
->mouse_face_deferred_gc || f
==hlinfo
->mouse_face_mouse_frame
)
1881 /*&& hlinfo->mouse_face_mouse_frame*/)
1885 if (hlinfo
->mouse_face_mouse_frame
)
1886 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1887 hlinfo
->mouse_face_mouse_x
,
1888 hlinfo
->mouse_face_mouse_y
);
1889 hlinfo
->mouse_face_deferred_gc
= 0;
1898 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1899 /* --------------------------------------------------------------------------
1900 External (RIF): set frame mouse pointer type.
1901 -------------------------------------------------------------------------- */
1903 NSTRACE
(ns_define_frame_cursor
);
1904 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1906 EmacsView
*view = FRAME_NS_VIEW
(f
);
1907 FRAME_POINTER_TYPE
(f
) = cursor
;
1908 [[view window
] invalidateCursorRectsForView
: view];
1909 /* Redisplay assumes this function also draws the changed frame
1910 cursor, but this function doesn't, so do it explicitly. */
1911 x_update_cursor
(f
, 1);
1917 /* ==========================================================================
1921 ========================================================================== */
1925 ns_convert_key
(unsigned code
)
1926 /* --------------------------------------------------------------------------
1927 Internal call used by NSView-keyDown.
1928 -------------------------------------------------------------------------- */
1930 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1931 / sizeof
(convert_ns_to_X_keysym
[0]));
1933 /* An array would be faster, but less easy to read. */
1934 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1935 if (code
== convert_ns_to_X_keysym
[keysym
])
1936 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1938 /* if decide to use keyCode and Carbon table, use this line:
1939 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1944 x_get_keysym_name
(int keysym
)
1945 /* --------------------------------------------------------------------------
1946 Called by keyboard.c. Not sure if the return val is important, except
1948 -------------------------------------------------------------------------- */
1950 static
char value
[16];
1951 NSTRACE
(x_get_keysym_name
);
1952 sprintf (value
, "
%d", keysym);
1958 /* ==========================================================================
1960 Block drawing operations
1962 ========================================================================== */
1966 ns_redraw_scroll_bars
(struct frame
*f
)
1970 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1971 NSTRACE
(ns_judge_scroll_bars
);
1972 for (i
=[subviews count
]-1; i
>= 0; i
--)
1974 view = [subviews objectAtIndex
: i
];
1975 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
1982 ns_clear_frame
(struct frame
*f
)
1983 /* --------------------------------------------------------------------------
1984 External (hook): Erase the entire frame
1985 -------------------------------------------------------------------------- */
1987 NSView
*view = FRAME_NS_VIEW
(f
);
1990 NSTRACE
(ns_clear_frame
);
1994 /* comes on initial frame because we have
1995 after-make-frame-functions = select-frame */
1996 if (!FRAME_DEFAULT_FACE
(f
))
1999 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
2001 output_cursor.hpos
= output_cursor.vpos
= 0;
2002 output_cursor.x
= -1;
2007 ns_focus
(f
, &r
, 1);
2008 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
2012 #ifdef NS_IMPL_COCOA
2013 [[view window
] display
]; /* redraw resize handle */
2016 /* as of 2006/11 or so this is now needed */
2017 ns_redraw_scroll_bars
(f
);
2023 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
2024 /* --------------------------------------------------------------------------
2025 External (RIF): Clear section of frame
2026 -------------------------------------------------------------------------- */
2028 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
2029 NSView
*view = FRAME_NS_VIEW
(f
);
2030 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
2035 NSTRACE
(ns_clear_frame_area
);
2037 r
= NSIntersectionRect
(r
, [view frame
]);
2038 ns_focus
(f
, &r
, 1);
2039 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
2041 #ifdef NS_IMPL_COCOA
2043 /* clip out the resize handle */
2044 NSWindow
*window
= [FRAME_NS_VIEW
(f
) window
];
2046 = [view convertRect
: ns_resize_handle_rect
(window
) fromView
: nil
];
2048 ir
= NSIntersectionRect
(r
, ir
);
2049 if (NSIsEmptyRect
(ir
))
2055 #ifdef NS_IMPL_COCOA
2059 NSRect r1
= r
, r2
= r
; /* upper and lower non-intersecting */
2060 r1.
size.height
-= ir.
size.height
;
2061 r2.origin.y
+= r1.
size.height
;
2062 r2.
size.width
-= ir.
size.width
;
2063 r2.
size.height
= ir.
size.height
;
2076 ns_scroll_run
(struct window
*w
, struct run
*run
)
2077 /* --------------------------------------------------------------------------
2078 External (RIF): Insert or delete n lines at line vpos
2079 -------------------------------------------------------------------------- */
2081 struct frame
*f
= XFRAME
(w
->frame
);
2082 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2084 NSTRACE
(ns_scroll_run
);
2086 /* begin copy from other terms */
2087 /* Get frame-relative bounding box of the text display area of W,
2088 without mode lines. Include in this box the left and right
2090 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2092 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2093 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2094 bottom_y
= y
+ height
;
2098 /* Scrolling up. Make sure we don't copy part of the mode
2099 line at the bottom. */
2100 if (from_y
+ run
->height
> bottom_y
)
2101 height
= bottom_y
- from_y
;
2103 height
= run
->height
;
2107 /* Scrolling down. Make sure we don't copy over the mode line.
2109 if (to_y
+ run
->height
> bottom_y
)
2110 height
= bottom_y
- to_y
;
2112 height
= run
->height
;
2114 /* end copy from other terms */
2125 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2126 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2127 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2129 ns_focus
(f
, &dstRect
, 1);
2130 NSCopyBits
(0, srcRect
, dstOrigin
);
2139 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2140 /* --------------------------------------------------------------------------
2141 External (RIF): preparatory to fringe update after text was updated
2142 -------------------------------------------------------------------------- */
2144 struct window
*w
= updated_window
;
2148 NSTRACE
(ns_after_update_window_line
);
2150 /* begin copy from other terms */
2153 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2154 desired_row
->redraw_fringe_bitmaps_p
= 1;
2156 /* When a window has disappeared, make sure that no rest of
2157 full-width rows stays visible in the internal border.
2158 Under NS this is drawn inside the fringes. */
2159 if (windows_or_buffers_changed
2160 && (f
= XFRAME
(w
->frame
),
2161 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2163 && (height
= desired_row
->visible_height
,
2166 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2168 /* Internal border is drawn below the tool bar. */
2169 if (WINDOWP
(f
->tool_bar_window
)
2170 && w
== XWINDOW
(f
->tool_bar_window
))
2172 /* end copy from other terms */
2175 if (!desired_row
->full_width_p
)
2177 int x1
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2178 + WINDOW_LEFT_FRINGE_WIDTH
(w
);
2179 int x2
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2180 + FRAME_PIXEL_WIDTH
(f
) - NS_SCROLL_BAR_WIDTH
(f
)
2181 - WINDOW_RIGHT_FRINGE_WIDTH
(w
)
2182 - FRAME_INTERNAL_BORDER_WIDTH
(f
);
2183 ns_clear_frame_area
(f
, x1
, y
, width
, height
);
2184 ns_clear_frame_area
(f
, x2
, y
, width
, height
);
2192 ns_shift_glyphs_for_insert
(struct frame
*f
,
2193 int x
, int y
, int width
, int height
,
2195 /* --------------------------------------------------------------------------
2196 External (RIF): copy an area horizontally, don't worry about clearing src
2197 -------------------------------------------------------------------------- */
2199 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2200 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2201 NSPoint dstOrigin
= dstRect.origin
;
2203 NSTRACE
(ns_shift_glyphs_for_insert
);
2205 ns_focus
(f
, &dstRect
, 1);
2206 NSCopyBits
(0, srcRect
, dstOrigin
);
2212 /* ==========================================================================
2214 Character encoding and metrics
2216 ========================================================================== */
2220 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2221 /* --------------------------------------------------------------------------
2222 External (RIF); compute left/right overhang of whole string and set in s
2223 -------------------------------------------------------------------------- */
2225 struct face
*face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2226 struct font
*font
= s
->font
; /*face->font; */
2230 struct font_metrics metrics
;
2231 unsigned int codes
[2];
2232 codes
[0] = *(s
->char2b
);
2233 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2235 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2236 s
->left_overhang
= -metrics.lbearing
;
2238 = metrics.rbearing
> metrics.width
2239 ? metrics.rbearing
- metrics.width
: 0;
2243 s
->left_overhang
= 0;
2244 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2245 FONT_HEIGHT
(font
) * 0.2 : 0;
2251 /* ==========================================================================
2253 Fringe and cursor drawing
2255 ========================================================================== */
2258 extern int max_used_fringe_bitmap
;
2260 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2261 struct draw_fringe_bitmap_params
*p
)
2262 /* --------------------------------------------------------------------------
2263 External (RIF); fringe-related
2264 -------------------------------------------------------------------------- */
2266 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2267 struct face
*face
= p
->face
;
2269 static EmacsImage
**bimgs
= NULL;
2270 static int nBimgs
= 0;
2271 /* NS-specific: move internal border inside fringe */
2272 int x
= p
->bx
< 0 ? p
->x
: p
->bx
;
2273 int wd
= p
->bx
< 0 ? p
->wd
: p
->nx
;
2274 BOOL fringeOnVeryLeft
2275 = x
- WINDOW_LEFT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
)
2276 - FRAME_INTERNAL_BORDER_WIDTH
(f
) < 10;
2277 BOOL fringeOnVeryRight
2278 = FRAME_PIXEL_WIDTH
(f
) - x
- wd
- FRAME_INTERNAL_BORDER_WIDTH
(f
)
2279 - WINDOW_RIGHT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
) < 10;
2280 int xAdjust
= FRAME_INTERNAL_BORDER_WIDTH
(f
) *
2281 (fringeOnVeryLeft ?
-1 : (fringeOnVeryRight ?
1 : 0));
2283 /* grow bimgs if needed */
2284 if (nBimgs
< max_used_fringe_bitmap
)
2286 EmacsImage
**newBimgs
2287 = xmalloc
(max_used_fringe_bitmap
* sizeof
(EmacsImage
*));
2288 memset
(newBimgs
, 0, max_used_fringe_bitmap
* sizeof
(EmacsImage
*));
2292 memcpy
(newBimgs
, bimgs
, nBimgs
* sizeof
(EmacsImage
*));
2297 nBimgs
= max_used_fringe_bitmap
;
2300 /* Must clip because of partially visible lines. */
2301 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2302 ns_clip_to_row
(w
, row
, -1, YES
);
2304 if (p
->bx
>= 0 && !p
->overlay_p
)
2306 int yAdjust
= rowY
- FRAME_INTERNAL_BORDER_WIDTH
(f
) < 5 ?
2307 -FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0;
2308 int yIncr
= FRAME_PIXEL_HEIGHT
(f
) - (p
->by
+yAdjust
+ p
->ny
) < 5 ?
2309 FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0
2310 + (yAdjust ? FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0);
2311 NSRect r
= NSMakeRect
(p
->bx
+xAdjust
, p
->by
+yAdjust
, p
->nx
, p
->ny
+yIncr
);
2313 [ns_lookup_indexed_color
(face
->background
, f
) set];
2319 NSRect r
= NSMakeRect
(p
->x
+xAdjust
, p
->y
, p
->wd
, p
->h
);
2320 NSPoint pt
= r.origin
;
2321 EmacsImage
*img
= bimgs
[p
->which - 1];
2325 unsigned short
*bits
= p
->bits
+ p
->dh
;
2328 unsigned
char *cbits
= xmalloc
(len
);
2330 for (i
=0; i
<len
; i
++)
2331 cbits
[i
] = ~
(bits
[i
] & 0xff);
2332 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2334 bimgs
[p
->which - 1] = img
;
2339 /* Since we composite the bitmap instead of just blitting it, we need
2340 to erase the whole background. */
2341 [ns_lookup_indexed_color
(face
->background
, f
) set];
2344 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2345 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2352 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2353 int x
, int y
, int cursor_type
, int cursor_width
,
2354 int on_p
, int active_p
)
2355 /* --------------------------------------------------------------------------
2356 External call (RIF): draw cursor.
2357 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2358 -------------------------------------------------------------------------- */
2361 int fx
, fy
, h
, cursor_height
;
2362 struct frame
*f
= WINDOW_XFRAME
(w
);
2363 struct glyph
*phys_cursor_glyph
;
2365 struct glyph
*cursor_glyph
;
2367 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2369 /* If cursor is out of bounds, don't draw garbage. This can happen
2370 in mini-buffer windows when switching between echo area glyphs
2373 NSTRACE
(dumpcursor
);
2378 w
->phys_cursor_type
= cursor_type
;
2379 w
->phys_cursor_on_p
= on_p
;
2381 if (cursor_type
== NO_CURSOR
)
2383 w
->phys_cursor_width
= 0;
2387 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2389 if (glyph_row
->exact_window_width_line_p
2390 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2392 glyph_row
->cursor_in_fringe_p
= 1;
2393 draw_fringe_bitmap
(w
, glyph_row
, 0);
2398 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2399 (other terminals do it the other way round). We must set
2400 w->phys_cursor_width to the cursor width. For bar cursors, that
2401 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2402 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2404 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2405 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2406 if (cursor_type
== BAR_CURSOR
)
2408 if (cursor_width
< 1)
2409 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2410 w
->phys_cursor_width
= cursor_width
;
2412 /* If we have an HBAR, "cursor_width" MAY specify height. */
2413 else if (cursor_type
== HBAR_CURSOR
)
2415 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2416 fy
+= h
- cursor_height
;
2420 r.origin.x
= fx
, r.origin.y
= fy
;
2422 r.
size.width
= w
->phys_cursor_width
;
2424 /* FIXME: if we overwrite the internal border area, it does not get erased;
2425 fix by truncating cursor, but better would be to erase properly */
2426 overspill
= r.origin.x
+ r.
size.width
-
2427 WINDOW_TEXT_TO_FRAME_PIXEL_X
(w
, WINDOW_BOX_RIGHT_EDGE_X
(w
)
2428 - WINDOW_TOTAL_FRINGE_WIDTH
(w
) - FRAME_INTERNAL_BORDER_WIDTH
(f
));
2430 r.
size.width
-= overspill
;
2432 /* TODO: only needed in rare cases with last-resort font in HELLO..
2433 should we do this more efficiently? */
2434 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2437 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2438 if (face
&& NS_FACE_BACKGROUND
(face
)
2439 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2441 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2442 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2445 [FRAME_CURSOR_COLOR
(f
) set];
2447 #ifdef NS_IMPL_COCOA
2448 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2449 atomic. Cleaner ways of doing this should be investigated.
2450 One way would be to set a global variable DRAWING_CURSOR
2451 when making the call to draw_phys..(), don't focus in that
2452 case, then move the ns_unfocus() here after that call. */
2453 NSDisableScreenUpdates
();
2456 switch (cursor_type
)
2460 case FILLED_BOX_CURSOR
:
2463 case HOLLOW_BOX_CURSOR
:
2466 NSRectFill
(NSInsetRect
(r
, 1, 1));
2467 [FRAME_CURSOR_COLOR
(f
) set];
2474 /* If the character under cursor is R2L, draw the bar cursor
2475 on the right of its glyph, rather than on the left. */
2476 cursor_glyph
= get_phys_cursor_glyph
(w
);
2477 if ((cursor_glyph
->resolved_level
& 1) != 0)
2478 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2485 /* draw the character under the cursor */
2486 if (cursor_type
!= NO_CURSOR
)
2487 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2489 #ifdef NS_IMPL_COCOA
2490 NSEnableScreenUpdates
();
2497 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2498 /* --------------------------------------------------------------------------
2499 External (RIF): Draw a vertical line.
2500 -------------------------------------------------------------------------- */
2502 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2504 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2506 NSTRACE
(ns_draw_vertical_window_border
);
2508 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2510 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2512 ns_focus
(f
, &r
, 1);
2519 show_hourglass
(struct atimer
*timer
)
2521 if (hourglass_shown_p
)
2526 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2528 hourglass_shown_p
= 1;
2534 hide_hourglass
(void
)
2536 if (!hourglass_shown_p
)
2541 /* TODO: remove NSProgressIndicator from all frames */
2543 hourglass_shown_p
= 0;
2549 /* ==========================================================================
2551 Glyph drawing operations
2553 ========================================================================== */
2556 static inline NSRect
2557 ns_fix_rect_ibw
(NSRect r
, int fibw
, int frame_pixel_width
)
2558 /* --------------------------------------------------------------------------
2559 Under NS we draw internal borders inside fringes, and want full-width
2560 rendering to go all the way to edge. This function makes that correction.
2561 -------------------------------------------------------------------------- */
2563 if (r.origin.y
<= fibw
+1)
2565 r.
size.height
+= r.origin.y
;
2568 if (r.origin.x
<= fibw
+1)
2570 r.
size.width
+= r.origin.x
;
2573 if (frame_pixel_width
- (r.origin.x
+r.
size.width
) <= fibw
+1)
2574 r.
size.width
+= fibw
;
2581 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2582 /* --------------------------------------------------------------------------
2583 Wrapper utility to account for internal border width on full-width lines,
2584 and allow top full-width rows to hit the frame top. nr should be pointer
2585 to two successive NSRects. Number of rects actually used is returned.
2586 -------------------------------------------------------------------------- */
2588 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2589 if (s
->row
->full_width_p
)
2591 *nr
= ns_fix_rect_ibw
(*nr
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2592 FRAME_PIXEL_WIDTH
(s
->f
));
2594 *nr
= ns_fix_rect_ibw
(*(nr
+1), FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2595 FRAME_PIXEL_WIDTH
(s
->f
));
2601 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2602 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2603 /* --------------------------------------------------------------------------
2604 Draw underline, overline, and strike-through on glyph string s.
2605 -------------------------------------------------------------------------- */
2607 if (s
->for_overlaps
)
2611 if (face
->underline_p
)
2614 unsigned
long thickness
, position
;
2616 /* If the prev was underlined, match its appearance. */
2617 if (s
->prev
&& s
->prev
->face
->underline_p
2618 && s
->prev
->underline_thickness
> 0)
2620 thickness
= s
->prev
->underline_thickness
;
2621 position
= s
->prev
->underline_position
;
2626 unsigned
long descent
;
2629 descent
= s
->y
+ s
->height
- s
->ybase
;
2631 /* Use underline thickness of font, defaulting to 1. */
2632 thickness
= (font
&& font
->underline_thickness
> 0)
2633 ? font
->underline_thickness
: 1;
2635 /* Determine the offset of underlining from the baseline. */
2636 if (x_underline_at_descent_line
)
2637 position
= descent
- thickness
;
2638 else if (x_use_underline_position_properties
2639 && font
&& font
->underline_position
>= 0)
2640 position
= font
->underline_position
;
2642 position
= lround
(font
->descent
/ 2);
2644 position
= underline_minimum_offset
;
2646 position
= max (position
, underline_minimum_offset
);
2648 /* Ensure underlining is not cropped. */
2649 if (descent
<= position
)
2651 position
= descent
- 1;
2654 else if (descent
< position
+ thickness
)
2658 s
->underline_thickness
= thickness
;
2659 s
->underline_position
= position
;
2661 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2663 if (face
->underline_defaulted_p
)
2666 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2670 /* Do overline. We follow other terms in using a thickness of 1
2671 and ignoring overline_margin. */
2672 if (face
->overline_p
)
2675 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2677 if (face
->overline_color_defaulted_p
)
2680 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2684 /* Do strike-through. We follow other terms for thickness and
2685 vertical position.*/
2686 if (face
->strike_through_p
)
2691 dy
= lrint
((s
->height
- 1) / 2);
2692 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2694 if (face
->strike_through_color_defaulted_p
)
2697 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2703 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2704 /* --------------------------------------------------------------------------
2705 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2706 Note we can't just use an NSDrawRect command, because of the possibility
2707 of some sides not being drawn, and because the rect will be filled.
2708 -------------------------------------------------------------------------- */
2714 s.
size.height
= thickness
;
2716 s.origin.y
+= r.
size.height
- thickness
;
2719 s.
size.height
= r.
size.height
;
2720 s.origin.y
= r.origin.y
;
2722 /* left, right (optional) */
2723 s.
size.width
= thickness
;
2728 s.origin.x
+= r.
size.width
- thickness
;
2735 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2736 char top_p
, char bottom_p
, char left_p
, char right_p
,
2737 struct glyph_string
*s
)
2738 /* --------------------------------------------------------------------------
2739 Draw a relief rect inside r, optionally leaving some sides open.
2740 Note we can't just use an NSDrawBezel command, because of the possibility
2741 of some sides not being drawn, and because the rect will be filled.
2742 -------------------------------------------------------------------------- */
2744 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2745 NSColor
*newBaseCol
= nil
;
2748 NSTRACE
(ns_draw_relief
);
2752 if (s
->face
->use_box_color_for_shadows_p
)
2754 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2756 /* else if (s->first_glyph->type == IMAGE_GLYPH
2758 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2760 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2764 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2767 if (newBaseCol
== nil
)
2768 newBaseCol
= [NSColor grayColor
];
2770 if (newBaseCol
!= baseCol
) /* TODO: better check */
2773 baseCol
= [newBaseCol retain
];
2775 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2777 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2780 [(raised_p ? lightCol
: darkCol
) set];
2782 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2785 sr.
size.height
= thickness
;
2786 if (top_p
) NSRectFill
(sr
);
2789 sr.
size.height
= r.
size.height
;
2790 sr.
size.width
= thickness
;
2791 if (left_p
) NSRectFill
(sr
);
2793 [(raised_p ? darkCol
: lightCol
) set];
2796 sr.
size.width
= r.
size.width
;
2797 sr.
size.height
= thickness
;
2798 sr.origin.y
+= r.
size.height
- thickness
;
2799 if (bottom_p
) NSRectFill
(sr
);
2802 sr.
size.height
= r.
size.height
;
2803 sr.origin.y
= r.origin.y
;
2804 sr.
size.width
= thickness
;
2805 sr.origin.x
+= r.
size.width
- thickness
;
2806 if (right_p
) NSRectFill
(sr
);
2811 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2812 /* --------------------------------------------------------------------------
2813 Function modeled after x_draw_glyph_string_box ().
2814 Sets up parameters for drawing.
2815 -------------------------------------------------------------------------- */
2817 int right_x
, last_x
;
2818 char left_p
, right_p
;
2819 struct glyph
*last_glyph
;
2824 if (s
->hl
== DRAW_MOUSE_FACE
)
2826 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2828 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2833 thickness
= face
->box_line_width
;
2835 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2837 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2838 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2839 : window_box_right
(s
->w
, s
->area
));
2840 last_glyph
= (s
->cmp || s
->img
2841 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2843 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2844 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2846 left_p
= (s
->first_glyph
->left_box_line_p
2847 ||
(s
->hl
== DRAW_MOUSE_FACE
2848 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2849 right_p
= (last_glyph
->right_box_line_p
2850 ||
(s
->hl
== DRAW_MOUSE_FACE
2851 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2853 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2855 /* expand full-width row over internal borders */
2856 if (s
->row
->full_width_p
)
2857 r
= ns_fix_rect_ibw
(r
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2858 FRAME_PIXEL_WIDTH
(s
->f
));
2860 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2861 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2863 ns_draw_box
(r
, abs (thickness
),
2864 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2869 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2870 1, 1, left_p
, right_p
, s
);
2876 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2877 /* --------------------------------------------------------------------------
2878 Modeled after x_draw_glyph_string_background, which draws BG in
2879 certain cases. Others are left to the text rendering routine.
2880 -------------------------------------------------------------------------- */
2882 NSTRACE
(ns_maybe_dumpglyphs_background
);
2884 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2886 int box_line_width
= max (s
->face
->box_line_width
, 0);
2887 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2888 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2891 if (s
->hl
== DRAW_MOUSE_FACE
)
2893 face
= FACE_FROM_ID
(s
->f
,
2894 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2896 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2899 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2901 [(NS_FACE_BACKGROUND
(face
) != 0
2902 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2903 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2906 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2907 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2910 if (s
->hl
!= DRAW_CURSOR
)
2912 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2913 s
->background_width
,
2914 s
->height
-2*box_line_width
);
2916 /* expand full-width row over internal borders */
2917 if (s
->row
->full_width_p
)
2919 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
2920 if (r.origin.y
<= fibw
+1 + box_line_width
)
2922 r.
size.height
+= r.origin.y
;
2925 if (r.origin.x
<= fibw
+1)
2927 r.
size.width
+= 2*r.origin.x
;
2930 if (FRAME_PIXEL_WIDTH
(s
->f
) - (r.origin.x
+ r.
size.width
)
2932 r.
size.width
+= fibw
;
2938 s
->background_filled_p
= 1;
2945 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2946 /* --------------------------------------------------------------------------
2947 Renders an image and associated borders.
2948 -------------------------------------------------------------------------- */
2950 EmacsImage
*img
= s
->img
->pixmap
;
2951 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2952 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2953 int bg_x
, bg_y
, bg_height
;
2960 NSTRACE
(ns_dumpglyphs_image
);
2962 if (s
->face
->box
!= FACE_NO_BOX
2963 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
2964 x
+= abs (s
->face
->box_line_width
);
2967 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
2968 bg_height
= s
->height
;
2969 /* other terms have this, but was causing problems w/tabbar mode */
2970 /* - 2 * box_line_vwidth; */
2972 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
2973 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
2975 /* Draw BG: if we need larger area than image itself cleared, do that,
2976 otherwise, since we composite the image under NS (instead of mucking
2977 with its background color), we must clear just the image area. */
2978 if (s
->hl
== DRAW_MOUSE_FACE
)
2980 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2982 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2985 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2987 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
2989 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
2990 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
2992 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
2993 s
->background_filled_p
= 1;
2997 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3000 /* expand full-width row over internal borders */
3001 if (s
->row
->full_width_p
)
3003 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
3004 if (br.origin.y
<= fibw
+1 + box_line_vwidth
)
3006 br.
size.height
+= br.origin.y
;
3009 if (br.origin.x
<= fibw
+1 + box_line_vwidth
)
3011 br.
size.width
+= br.origin.x
;
3014 if (FRAME_PIXEL_WIDTH
(s
->f
) - (br.origin.x
+ br.
size.width
) <= fibw
+1)
3015 br.
size.width
+= fibw
;
3020 /* Draw the image.. do we need to draw placeholder if img ==nil? */
3022 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
3023 operation
: NSCompositeSourceOver
];
3025 if (s
->hl
== DRAW_CURSOR
)
3027 [FRAME_CURSOR_COLOR
(s
->f
) set];
3028 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3029 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3031 /* Currently on NS img->mask is always 0. Since
3032 get_window_cursor_type specifies a hollow box cursor when on
3033 a non-masked image we never reach this clause. But we put it
3034 in in anticipation of better support for image masks on
3036 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3040 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3043 /* Draw underline, overline, strike-through. */
3044 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3046 /* Draw relief, if requested */
3047 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3049 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3051 th
= tool_bar_button_relief
>= 0 ?
3052 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3053 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3057 th
= abs (s
->img
->relief
);
3058 raised_p
= (s
->img
->relief
> 0);
3061 r.origin.x
= x
- th
;
3062 r.origin.y
= y
- th
;
3063 r.
size.width
= s
->slice.width
+ 2*th
-1;
3064 r.
size.height
= s
->slice.height
+ 2*th
-1;
3065 ns_draw_relief
(r
, th
, raised_p
,
3067 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3069 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3072 /* If there is no mask, the background won't be seen,
3073 so draw a rectangle on the image for the cursor.
3074 Do this for all images, getting transparency right is not reliable. */
3075 if (s
->hl
== DRAW_CURSOR
)
3077 int thickness
= abs (s
->img
->relief
);
3078 if (thickness
== 0) thickness
= 1;
3079 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3085 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3090 NSColor
*fgCol
, *bgCol
;
3092 if (!s
->background_filled_p
)
3094 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3095 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3097 ns_focus
(s
->f
, r
, n
);
3099 if (s
->hl
== DRAW_MOUSE_FACE
)
3101 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3103 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3106 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3108 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3109 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3113 if (!s
->row
->full_width_p
)
3115 int overrun
, leftoverrun
;
3117 /* truncate to avoid overwriting fringe and/or scrollbar */
3118 overrun
= max (0, (s
->x
+ s
->background_width
)
3119 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3120 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3121 r
[i
].
size.width
-= overrun
;
3123 /* truncate to avoid overwriting to left of the window box */
3124 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3125 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3127 if (leftoverrun
> 0)
3129 r
[i
].origin.x
+= leftoverrun
;
3130 r
[i
].
size.width
-= leftoverrun
;
3133 /* XXX: Try to work between problem where a stretch glyph on
3134 a partially-visible bottom row will clear part of the
3135 modeline, and another where list-buffers headers and similar
3136 rows erroneously have visible_height set to 0. Not sure
3137 where this is coming from as other terms seem not to show. */
3138 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3141 /* expand full-width rows over internal borders */
3144 r
[i
] = ns_fix_rect_ibw
(r
[i
], FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
3145 FRAME_PIXEL_WIDTH
(s
->f
));
3150 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3151 overwriting cursor (usually when cursor on a tab) */
3152 if (s
->hl
== DRAW_CURSOR
)
3157 width
= s
->w
->phys_cursor_width
;
3158 r
[i
].
size.width
-= width
;
3159 r
[i
].origin.x
+= width
;
3163 /* Draw overlining, etc. on the cursor. */
3164 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3165 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3167 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3174 /* Draw overlining, etc. on the stretch glyph (or the part
3175 of the stretch glyph after the cursor). */
3176 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3180 s
->background_filled_p
= 1;
3186 ns_draw_glyph_string
(struct glyph_string
*s
)
3187 /* --------------------------------------------------------------------------
3188 External (RIF): Main draw-text call.
3189 -------------------------------------------------------------------------- */
3191 /* TODO (optimize): focus for box and contents draw */
3194 char box_drawn_p
= 0;
3196 NSTRACE
(ns_draw_glyph_string
);
3198 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3201 struct glyph_string
*next
;
3203 for (width
= 0, next
= s
->next
;
3204 next
&& width
< s
->right_overhang
;
3205 width
+= next
->width
, next
= next
->next
)
3206 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3208 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3210 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3211 ns_focus
(s
->f
, r
, n
);
3212 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3217 ns_dumpglyphs_stretch
(s
->next
);
3219 next
->num_clips
= 0;
3223 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3224 && (s
->first_glyph
->type == CHAR_GLYPH
3225 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3227 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3228 ns_focus
(s
->f
, r
, n
);
3229 ns_maybe_dumpglyphs_background
(s
, 1);
3230 ns_dumpglyphs_box_or_relief
(s
);
3235 switch (s
->first_glyph
->type)
3239 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3240 ns_focus
(s
->f
, r
, n
);
3241 ns_dumpglyphs_image
(s
, r
[0]);
3246 ns_dumpglyphs_stretch
(s
);
3250 case COMPOSITE_GLYPH
:
3251 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3252 ns_focus
(s
->f
, r
, n
);
3254 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3255 && ! s
->first_glyph
->u.cmp.automatic
))
3256 s
->background_filled_p
= 1;
3258 ns_maybe_dumpglyphs_background
3259 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3261 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3262 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3263 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3264 NS_DUMPGLYPH_NORMAL
));
3265 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3266 if (ns_tmp_font
== NULL)
3267 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3269 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3271 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3272 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3273 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3276 ns_tmp_font
->font.driver
->draw
3277 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3278 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3279 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
3281 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3283 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3284 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3285 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3291 case GLYPHLESS_GLYPH
:
3292 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3293 ns_focus
(s
->f
, r
, n
);
3295 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3296 && ! s
->first_glyph
->u.cmp.automatic
))
3297 s
->background_filled_p
= 1;
3299 ns_maybe_dumpglyphs_background
3300 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3302 /* Not yet implemented. */
3311 /* Draw box if not done already. */
3312 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3314 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3315 ns_focus
(s
->f
, r
, n
);
3316 ns_dumpglyphs_box_or_relief
(s
);
3325 /* ==========================================================================
3329 ========================================================================== */
3333 ns_send_appdefined
(int value
)
3334 /* --------------------------------------------------------------------------
3335 Internal: post an appdefined event which EmacsApp-sendEvent will
3336 recognize and take as a command to halt the event loop.
3337 -------------------------------------------------------------------------- */
3339 /*NSTRACE (ns_send_appdefined); */
3341 /* Only post this event if we haven't already posted one. This will end
3342 the [NXApp run] main loop after having processed all events queued at
3344 if (send_appdefined
)
3348 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3349 send_appdefined
= NO
;
3351 /* Don't need wakeup timer any more */
3354 [timed_entry invalidate
];
3355 [timed_entry release
];
3359 /* Ditto for file descriptor poller */
3362 [fd_entry invalidate
];
3367 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3368 location
: NSMakePoint
(0, 0)
3371 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3372 context
: [NSApp context
]
3377 /* Post an application defined event on the event queue. When this is
3378 received the [NXApp run] will return, thus having processed all
3379 events which are currently queued. */
3380 [NSApp postEvent
: nxev atStart
: NO
];
3386 ns_read_socket
(struct terminal *terminal, int expected
,
3387 struct input_event
*hold_quit
)
3388 /* --------------------------------------------------------------------------
3389 External (hook): Post an event to ourself and keep reading events until
3390 we read it back again. In effect process all events which were waiting.
3391 From 21+ we have to manage the event buffer ourselves.
3392 -------------------------------------------------------------------------- */
3394 struct input_event ev
;
3397 /* NSTRACE (ns_read_socket); */
3399 if (interrupt_input_blocked
)
3401 interrupt_input_pending
= 1;
3403 pending_signals
= 1;
3408 interrupt_input_pending
= 0;
3410 pending_signals
= pending_atimers
;
3414 n_emacs_events_pending
= 0;
3417 q_event_ptr
= hold_quit
;
3419 /* we manage autorelease pools by allocate/reallocate each time around
3420 the loop; strict nesting is occasionally violated but seems not to
3421 matter.. earlier methods using full nesting caused major memory leaks */
3422 [outerpool release
];
3423 outerpool
= [[NSAutoreleasePool alloc
] init
];
3425 /* If have pending open-file requests, attend to the next one of those. */
3426 if (ns_pending_files
&& [ns_pending_files count
] != 0
3427 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3429 [ns_pending_files removeObjectAtIndex
: 0];
3431 /* Deal with pending service requests. */
3432 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3434 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3435 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3437 [ns_pending_service_names removeObjectAtIndex
: 0];
3438 [ns_pending_service_args removeObjectAtIndex
: 0];
3442 /* Run and wait for events. We must always send one NX_APPDEFINED event
3443 to ourself, otherwise [NXApp run] will never exit. */
3444 send_appdefined
= YES
;
3446 /* If called via ns_select, this is called once with expected=1,
3447 because we expect either the timeout or file descriptor activity.
3448 In this case the first event through will either be real input or
3449 one of these. read_avail_input() then calls once more with expected=0
3450 and in that case we need to return quickly if there is nothing.
3451 If we're being called outside of that, it's also OK to return quickly
3452 after one iteration through the event loop, since other terms do
3453 this and emacs expects it. */
3454 if (!(inNsSelect
&& expected
))
3456 /* Post an application defined event on the event queue. When this is
3457 received the [NXApp run] will return, thus having processed all
3458 events which are currently queued, if any. */
3459 ns_send_appdefined
(-1);
3465 nevents
= n_emacs_events_pending
;
3466 n_emacs_events_pending
= 0;
3467 emacs_event
= q_event_ptr
= NULL;
3475 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3476 fd_set
*exceptfds
, struct timeval
*timeout
)
3477 /* --------------------------------------------------------------------------
3478 Replacement for select, checking for events
3479 -------------------------------------------------------------------------- */
3484 /* NSTRACE (ns_select); */
3486 if (NSApp
== nil || inNsSelect
== 1 /* || ([NSApp isActive] == NO &&
3487 [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil
3488 inMode:NSDefaultRunLoopMode dequeue:NO] == nil) */)
3489 return select
(nfds
, readfds
, writefds
, exceptfds
, timeout
);
3491 /* Save file descriptor set, which gets overwritten in calls to select ()
3492 Note, this is called from process.c, and only readfds is ever set */
3495 memcpy
(&select_readfds
, readfds
, sizeof
(fd_set
));
3501 /* Try an initial select for pending data on input files */
3502 select_timeout.tv_sec
= select_timeout.tv_usec
= 0;
3503 result
= select
(nfds
, readfds
, writefds
, exceptfds
, &select_timeout
);
3507 /* if (!timeout || timed_entry || fd_entry)
3508 fprintf (stderr, "assertion failed: timeout null or timed_entry/fd_entry non-null in ns_select\n"); */
3510 /* set a timeout and run the main AppKit event loop while continuing
3511 to monitor the files */
3512 time
= ((double) timeout
->tv_sec
) + ((double) timeout
->tv_usec
)/1000000.0;
3513 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3515 selector
: @selector
(timeout_handler
:)
3517 repeats
: YES
] /* for safe removal */
3520 /* set a periodic task to try the select () again */
3521 fd_entry
= [[NSTimer scheduledTimerWithTimeInterval
: 0.1
3523 selector
: @selector
(fd_handler
:)
3528 /* Let Application dispatch events until it receives an event of the type
3529 NX_APPDEFINED, which should only be sent by timeout_handler.
3530 We tell read_avail_input() that input is "expected" because we do expect
3531 either the timeout or fd handler to fire, and if they don't, the original
3532 call from process.c that got us here expects us to wait until some input
3536 ev
= last_appdefined_event
;
3542 if ([ev
type] != NSApplicationDefined
)
3546 last_appdefined_event
= 0;
3550 /* The NX_APPDEFINED event we received was a timeout. */
3555 /* The NX_APPDEFINED event we received was the result of
3556 at least one real input event arriving. */
3562 /* Received back from select () in fd_handler; copy the results */
3564 memcpy
(readfds
, &select_readfds
, sizeof
(fd_set
));
3568 /* never reached, shut compiler up */
3574 /* ==========================================================================
3578 ========================================================================== */
3582 ns_set_vertical_scroll_bar
(struct window
*window
,
3583 int portion
, int whole
, int position
)
3584 /* --------------------------------------------------------------------------
3585 External (hook): Update or add scrollbar
3586 -------------------------------------------------------------------------- */
3590 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3591 EmacsView
*view = FRAME_NS_VIEW
(f
);
3592 int window_y
, window_height
;
3593 BOOL barOnVeryLeft
, barOnVeryRight
;
3594 int top
, left
, height
, width
, sb_width
, sb_left
;
3596 static int count
= 0;
3598 /* optimization; display engine sends WAY too many of these.. */
3599 if (!NILP
(window
->vertical_scroll_bar
))
3601 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3602 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3604 if (view->scrollbarsNeedingUpdate
== 0)
3606 if (!windows_or_buffers_changed
)
3610 view->scrollbarsNeedingUpdate
--;
3614 NSTRACE
(ns_set_vertical_scroll_bar
);
3616 /* Get dimensions. */
3617 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3619 height
= window_height
;
3620 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3621 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3623 if (top
< 5) /* top scrollbar adjustment */
3625 top
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3626 height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3629 /* allow for displaying a skinnier scrollbar than char area allotted */
3630 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3631 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3633 barOnVeryLeft
= left
< 5;
3634 barOnVeryRight
= FRAME_PIXEL_WIDTH
(f
) - left
- width
< 5;
3635 sb_left
= left
+ FRAME_INTERNAL_BORDER_WIDTH
(f
)
3636 * (barOnVeryLeft ?
-1 : (barOnVeryRight ?
1 : 0));
3638 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3639 /* the parent view is flipped, so we need to flip y value */
3641 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3643 XSETWINDOW
(win
, window
);
3646 /* we want at least 5 lines to display a scrollbar */
3647 if (WINDOW_TOTAL_LINES
(window
) < 5)
3649 if (!NILP
(window
->vertical_scroll_bar
))
3651 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3652 [bar removeFromSuperview
];
3653 window
->vertical_scroll_bar
= Qnil
;
3655 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3660 if (NILP
(window
->vertical_scroll_bar
))
3662 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3663 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3664 window
->vertical_scroll_bar
= make_save_value
(bar, 0);
3669 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3670 oldRect
= [bar frame
];
3671 r.
size.width
= oldRect.
size.width
;
3672 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3674 if (oldRect.origin.x
!= r.origin.x
)
3675 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3680 [bar setPosition
: position portion
: portion whole
: whole
];
3686 ns_condemn_scroll_bars
(struct frame
*f
)
3687 /* --------------------------------------------------------------------------
3688 External (hook): arrange for all frame's scrollbars to be removed
3689 at next call to judge_scroll_bars, except for those redeemed.
3690 -------------------------------------------------------------------------- */
3694 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3696 NSTRACE
(ns_condemn_scroll_bars
);
3698 for (i
=[subviews count
]-1; i
>= 0; i
--)
3700 view = [subviews objectAtIndex
: i
];
3701 if ([view isKindOfClass
: [EmacsScroller
class]])
3708 ns_redeem_scroll_bar
(struct window
*window
)
3709 /* --------------------------------------------------------------------------
3710 External (hook): arrange to spare this window's scrollbar
3711 at next call to judge_scroll_bars.
3712 -------------------------------------------------------------------------- */
3715 NSTRACE
(ns_redeem_scroll_bar
);
3716 if (!NILP
(window
->vertical_scroll_bar
))
3718 bar =XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3725 ns_judge_scroll_bars
(struct frame
*f
)
3726 /* --------------------------------------------------------------------------
3727 External (hook): destroy all scrollbars on frame that weren't
3728 redeemed after call to condemn_scroll_bars.
3729 -------------------------------------------------------------------------- */
3733 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3734 NSTRACE
(ns_judge_scroll_bars
);
3735 for (i
=[subviews count
]-1; i
>= 0; i
--)
3737 view = [subviews objectAtIndex
: i
];
3738 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3745 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3747 /* XXX irrelevant under NS */
3752 /* ==========================================================================
3756 ========================================================================== */
3759 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3761 NSScreen
*screen
= [NSScreen mainScreen
];
3762 return [screen frame
].
size.height
;
3766 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3768 NSScreen
*screen
= [NSScreen mainScreen
];
3769 return [screen frame
].
size.width
;
3773 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3774 /* --------------------------------------------------------------------------
3775 Convert modifier name to lisp symbol
3776 -------------------------------------------------------------------------- */
3778 if (!strncmp
(SDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3780 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3782 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3784 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3786 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3788 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3795 static Lisp_Object ns_mod_to_lisp
(int m
)
3796 /* --------------------------------------------------------------------------
3797 Convert modifier code (see lisp.h) to lisp symbol
3798 -------------------------------------------------------------------------- */
3802 else if (m
== CHAR_SUPER
)
3804 else if (m
== CHAR_CTL
)
3806 else if (m
== CHAR_ALT
)
3808 else if (m
== CHAR_HYPER
)
3810 else /* if (m == 0) */
3816 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3817 Lisp_Object yesval
, Lisp_Object noval
,
3818 BOOL is_float
, BOOL is_modstring
)
3819 /* --------------------------------------------------------------------------
3820 Check a parameter value in user's preferences
3821 -------------------------------------------------------------------------- */
3823 const
char *value
= ns_get_defaults_value
(parameter
);
3829 if (strcasecmp
(value
, "YES"
) == 0)
3831 else if (strcasecmp
(value
, "NO"
) == 0)
3833 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3834 *result
= make_float
(f
);
3835 else if (is_modstring
&& value
)
3836 *result
= ns_string_to_lispmod
(value
);
3837 else fprintf (stderr
,
3838 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3844 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3845 /* --------------------------------------------------------------------------
3846 Initialize global info and storage for display.
3847 -------------------------------------------------------------------------- */
3849 NSScreen
*screen
= [NSScreen mainScreen
];
3850 NSWindowDepth depth
= [screen depth
];
3851 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
3853 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3854 dpyinfo
->resy
= 72.27;
3855 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3856 NSColorSpaceFromDepth
(depth
)]
3857 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3858 NSColorSpaceFromDepth
(depth
)];
3859 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3860 dpyinfo
->image_cache
= make_image_cache
();
3861 dpyinfo
->color_table
3862 = (struct ns_color_table
*)xmalloc
(sizeof
(struct ns_color_table
));
3863 dpyinfo
->color_table
->colors
= NULL;
3864 dpyinfo
->root_window
= 42; /* a placeholder.. */
3866 hlinfo
->mouse_face_mouse_frame
= NULL;
3867 hlinfo
->mouse_face_deferred_gc
= 0;
3868 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
3869 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
3870 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3871 hlinfo
->mouse_face_window
= hlinfo
->mouse_face_overlay
= Qnil
;
3872 hlinfo
->mouse_face_hidden
= 0;
3874 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
3875 hlinfo
->mouse_face_defer
= 0;
3877 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3879 dpyinfo
->n_fonts
= 0;
3880 dpyinfo
->smallest_font_height
= 1;
3881 dpyinfo
->smallest_char_width
= 1;
3885 /* This and next define (many of the) public functions in this file. */
3886 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3887 with using despite presence in the "system dependent" redisplay
3888 interface. In addition, many of the ns_ methods have code that is
3889 shared with all terms, indicating need for further refactoring. */
3890 extern frame_parm_handler ns_frame_parm_handlers
[];
3891 static
struct redisplay_interface ns_redisplay_interface
=
3893 ns_frame_parm_handlers
,
3897 x_clear_end_of_line
,
3899 ns_after_update_window_line
,
3900 ns_update_window_begin
,
3901 ns_update_window_end
,
3904 0, /* flush_display_optional */
3905 x_clear_window_mouse_face
,
3906 x_get_glyph_overhangs
,
3907 x_fix_overlapping_area
,
3908 ns_draw_fringe_bitmap
,
3909 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3910 0, /* destroy_fringe_bitmap */
3911 ns_compute_glyph_string_overhangs
,
3912 ns_draw_glyph_string
, /* interface to nsfont.m */
3913 ns_define_frame_cursor
,
3914 ns_clear_frame_area
,
3915 ns_draw_window_cursor
,
3916 ns_draw_vertical_window_border
,
3917 ns_shift_glyphs_for_insert
3922 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3928 /* This function is called when the last frame on a display is deleted. */
3930 ns_delete_terminal
(struct terminal *terminal)
3932 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3935 /* Protect against recursive calls. delete_frame in
3936 delete_terminal calls us back when it deletes our last frame. */
3937 if (!terminal->name
)
3942 x_destroy_all_bitmaps
(dpyinfo
);
3943 ns_delete_display
(dpyinfo
);
3948 static
struct terminal *
3949 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3950 /* --------------------------------------------------------------------------
3951 Set up use of NS before we make the first connection.
3952 -------------------------------------------------------------------------- */
3954 struct terminal *terminal;
3956 NSTRACE
(ns_create_terminal
);
3958 terminal = create_terminal
();
3960 terminal->type = output_ns
;
3961 terminal->display_info.ns
= dpyinfo
;
3962 dpyinfo
->terminal = terminal;
3964 terminal->rif
= &ns_redisplay_interface
;
3966 terminal->clear_frame_hook
= ns_clear_frame
;
3967 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
3968 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
3969 terminal->ring_bell_hook
= ns_ring_bell
;
3970 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
3971 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
3972 terminal->update_begin_hook
= ns_update_begin
;
3973 terminal->update_end_hook
= ns_update_end
;
3974 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
3975 terminal->read_socket_hook
= ns_read_socket
;
3976 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
3977 terminal->mouse_position_hook
= ns_mouse_position
;
3978 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
3979 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
3981 terminal->fullscreen_hook
= 0; /* see XTfullscreen_hook */
3983 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
3984 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
3985 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
3986 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
3988 terminal->delete_frame_hook
= x_destroy_window
;
3989 terminal->delete_terminal_hook
= ns_delete_terminal
;
3991 terminal->scroll_region_ok
= 1;
3992 terminal->char_ins_del_ok
= 1;
3993 terminal->line_ins_del_ok
= 1;
3994 terminal->fast_clear_end_of_line
= 1;
3995 terminal->memory_below_frame
= 0;
4001 struct ns_display_info
*
4002 ns_term_init
(Lisp_Object display_name
)
4003 /* --------------------------------------------------------------------------
4004 Start the Application and get things rolling.
4005 -------------------------------------------------------------------------- */
4007 struct terminal *terminal;
4008 struct ns_display_info
*dpyinfo
;
4009 static int ns_initialized
= 0;
4012 NSTRACE
(ns_term_init
);
4014 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
4015 /*GSDebugAllocationActive (YES); */
4017 handling_signal
= 0;
4019 if (!ns_initialized
)
4022 Fset_input_interrupt_mode
(Qnil
);
4026 ns_pending_files
= [[NSMutableArray alloc
] init
];
4027 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
4028 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
4030 /* Start app and create the main menu, window, view.
4031 Needs to be here because ns_initialize_display_info () uses AppKit classes.
4032 The view will then ask the NSApp to stop and return to Emacs. */
4033 [EmacsApp sharedApplication
];
4036 [NSApp setDelegate
: NSApp
];
4038 /* debugging: log all notifications */
4039 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4040 selector: @selector (logNotification:)
4041 name: nil object: nil]; */
4043 dpyinfo
= (struct ns_display_info
*)xmalloc
(sizeof
(struct ns_display_info
));
4044 memset
(dpyinfo
, 0, sizeof
(struct ns_display_info
));
4046 ns_initialize_display_info
(dpyinfo
);
4047 terminal = ns_create_terminal
(dpyinfo
);
4049 terminal->kboard
= (KBOARD
*) xmalloc
(sizeof
(KBOARD
));
4050 init_kboard
(terminal->kboard
);
4051 KVAR
(terminal->kboard
, Vwindow_system
) = Qns
;
4052 terminal->kboard
->next_kboard
= all_kboards
;
4053 all_kboards
= terminal->kboard
;
4054 /* Don't let the initial kboard remain current longer than necessary.
4055 That would cause problems if a file loaded on startup tries to
4056 prompt in the mini-buffer. */
4057 if (current_kboard
== initial_kboard
)
4058 current_kboard
= terminal->kboard
;
4059 terminal->kboard
->reference_count
++;
4061 dpyinfo
->next
= x_display_list
;
4062 x_display_list
= dpyinfo
;
4064 /* Put it on ns_display_name_list */
4065 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
4066 ns_display_name_list
);
4067 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
4069 /* Set the name of the terminal. */
4070 terminal->name
= (char *) xmalloc
(SBYTES
(display_name
) + 1);
4071 strncpy
(terminal->name
, SDATA
(display_name
), SBYTES
(display_name
));
4072 terminal->name
[SBYTES
(display_name
)] = 0;
4076 if (!inhibit_x_resources
)
4078 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4081 /* this is a standard variable */
4082 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4083 make_float
(10.0), make_float
(6.0), YES
, NO
);
4084 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4087 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
4088 stringForKey
: @"AppleHighlightColor"
];
4089 if (ns_selection_color
== nil
)
4090 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
4093 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4097 Lisp_Object color_file
, color_map
, color
;
4102 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4103 Fsymbol_value
(intern
("data
-directory"
)));
4104 if (NILP
(Ffile_readable_p
(color_file
)))
4105 fatal
("Could not
find %s.\n", SDATA (color_file));
4107 color_map
= Fx_load_color_file
(color_file
);
4108 if (NILP
(color_map
))
4109 fatal
("Could not read
%s.\n", SDATA (color_file));
4111 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4112 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4114 color
= XCAR
(color_map
);
4115 name
= SDATA
(XCAR
(color
));
4116 c
= XINT
(XCDR
(color
));
4118 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4119 green
: GREEN_FROM_ULONG
(c
) / 255.0
4120 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4122 forKey
: [NSString stringWithUTF8String
: name
]];
4124 [cl writeToFile
: nil
];
4130 #ifdef NS_IMPL_GNUSTEP
4131 strncpy
(c
, gnustep_base_version
, sizeof
(c
));
4133 /*PSnextrelease (128, c); */
4134 snprintf
(c
, sizeof
(c
), "
%g", NSAppKitVersionNumber);
4136 Vwindow_system_version
= build_string
(c
);
4139 delete_keyboard_wait_descriptor
(0);
4141 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4143 /* Set up OS X app menu */
4144 #ifdef NS_IMPL_COCOA
4148 /* set up the application menu */
4149 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4150 [svcsMenu setAutoenablesItems
: NO
];
4151 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4152 [appMenu setAutoenablesItems
: NO
];
4153 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4154 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4156 [appMenu insertItemWithTitle
: @"About Emacs"
4157 action
: @selector
(orderFrontStandardAboutPanel
:)
4160 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4161 [appMenu insertItemWithTitle
: @"Preferences..."
4162 action
: @selector
(showPreferencesWindow
:)
4165 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4166 item
= [appMenu insertItemWithTitle
: @"Services"
4167 action
: @selector
(menuDown
:)
4170 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4171 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4172 [appMenu insertItemWithTitle
: @"Hide Emacs"
4173 action
: @selector
(hide
:)
4176 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4177 action
: @selector
(hideOtherApplications
:)
4180 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4181 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4182 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4183 action
: @selector
(terminate
:)
4187 item
= [mainMenu insertItemWithTitle
: ns_app_name
4188 action
: @selector
(menuDown
:)
4191 [mainMenu setSubmenu
: appMenu forItem
: item
];
4192 [dockMenu insertItemWithTitle
: @"New Frame"
4193 action
: @selector
(newFrame
:)
4197 [NSApp setMainMenu
: mainMenu
];
4198 [NSApp setAppleMenu
: appMenu
];
4199 [NSApp setServicesMenu
: svcsMenu
];
4200 /* Needed at least on Cocoa, to get dock menu to show windows */
4201 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4203 [[NSNotificationCenter defaultCenter
]
4204 addObserver
: mainMenu
4205 selector
: @selector
(trackingNotification
:)
4206 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4207 [[NSNotificationCenter defaultCenter
]
4208 addObserver
: mainMenu
4209 selector
: @selector
(trackingNotification
:)
4210 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4212 #endif
/* MAC OS X menu setup */
4221 ns_term_shutdown
(int sig
)
4223 [[NSUserDefaults standardUserDefaults
] synchronize
];
4225 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4226 if (STRINGP
(Vauto_save_list_file_name
))
4227 unlink
(SDATA
(Vauto_save_list_file_name
));
4229 if (sig
== 0 || sig
== SIGTERM
)
4231 [NSApp terminate
: NSApp
];
4233 else // force a stack
trace to happen
4240 /* ==========================================================================
4242 EmacsApp implementation
4244 ========================================================================== */
4247 @implementation EmacsApp
4249 - (void
)logNotification
: (NSNotification
*)notification
4251 const
char *name
= [[notification name
] UTF8String
];
4252 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4253 && !strstr
(name
, "WindowNumber"
))
4254 NSLog
(@"notification
: '%@'"
, [notification name
]);
4258 - (void
)sendEvent
: (NSEvent
*)theEvent
4259 /* --------------------------------------------------------------------------
4260 Called when NSApp is running for each event received. Used to stop
4261 the loop when we choose, since there's no way to just run one iteration.
4262 -------------------------------------------------------------------------- */
4264 int
type = [theEvent
type];
4265 NSWindow
*window
= [theEvent window
];
4266 /* NSTRACE (sendEvent); */
4267 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4269 #ifdef NS_IMPL_COCOA
4270 if (type == NSApplicationDefined
4271 && [theEvent data2
] == NSAPP_DATA2_RUNASSCRIPT
)
4279 if (type == NSCursorUpdate
&& window
== nil
)
4281 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4285 #ifdef NS_IMPL_COCOA
4286 /* pass mouse down in resize handle and subsequent drags directly to
4287 EmacsWindow so we can generate continuous redisplays */
4290 if (type == NSLeftMouseDragged
)
4292 [window mouseDragged
: theEvent
];
4295 else if (type == NSLeftMouseUp
)
4297 [window mouseUp
: theEvent
];
4301 else if (type == NSLeftMouseDown
)
4303 NSRect r
= ns_resize_handle_rect
(window
);
4304 if (NSPointInRect
([theEvent locationInWindow
], r
))
4307 [window mouseDown
: theEvent
];
4313 if (type == NSApplicationDefined
)
4315 /* Events posted by ns_send_appdefined interrupt the run loop here.
4316 But, if a modal window is up, an appdefined can still come through,
4317 (e.g., from a makeKeyWindow event) but stopping self also stops the
4318 modal loop. Just defer it until later. */
4319 if ([NSApp modalWindow
] == nil
)
4321 last_appdefined_event
= theEvent
;
4326 send_appdefined
= YES
;
4330 [super sendEvent
: theEvent
];
4334 - (void
)showPreferencesWindow
: (id
)sender
4336 struct frame
*emacsframe
= SELECTED_FRAME
();
4337 NSEvent
*theEvent
= [NSApp currentEvent
];
4341 emacs_event
->kind
= NS_NONKEY_EVENT
;
4342 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4343 emacs_event
->modifiers
= 0;
4344 EV_TRAILER
(theEvent
);
4348 - (void
)newFrame
: (id
)sender
4350 struct frame
*emacsframe
= SELECTED_FRAME
();
4351 NSEvent
*theEvent
= [NSApp currentEvent
];
4355 emacs_event
->kind
= NS_NONKEY_EVENT
;
4356 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4357 emacs_event
->modifiers
= 0;
4358 EV_TRAILER
(theEvent
);
4362 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4363 - (BOOL
) openFile
: (NSString
*)fileName
4365 struct frame
*emacsframe
= SELECTED_FRAME
();
4366 NSEvent
*theEvent
= [NSApp currentEvent
];
4371 emacs_event
->kind
= NS_NONKEY_EVENT
;
4372 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4373 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4374 ns_input_line
= Qnil
; /* can be start or cons start,end */
4375 emacs_event
->modifiers
=0;
4376 EV_TRAILER
(theEvent
);
4382 /* **************************************************************************
4384 EmacsApp delegate implementation
4386 ************************************************************************** */
4388 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4389 /* --------------------------------------------------------------------------
4390 When application is loaded, terminate event loop in ns_term_init
4391 -------------------------------------------------------------------------- */
4393 NSTRACE
(applicationDidFinishLaunching
);
4394 [NSApp setServicesProvider
: NSApp
];
4395 ns_send_appdefined
(-2);
4399 /* Termination sequences:
4402 MenuBar | File | Exit:
4403 Select Quit from App menubar:
4405 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4408 Select Quit from Dock menu:
4411 Cancel -> Nothing else
4415 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4420 - (void
) terminate
: (id
)sender
4422 struct frame
*emacsframe
= SELECTED_FRAME
();
4427 emacs_event
->kind
= NS_NONKEY_EVENT
;
4428 emacs_event
->code
= KEY_NS_POWER_OFF
;
4429 emacs_event
->arg
= Qt
; /* mark as non-key event */
4430 EV_TRAILER
((id
)nil
);
4434 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4438 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4439 return NSTerminateNow
;
4441 ret
= NSRunAlertPanel
(ns_app_name
,
4442 [NSString stringWithUTF8String
:"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
],
4443 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4445 if (ret
== NSAlertDefaultReturn
)
4446 return NSTerminateNow
;
4447 else if (ret
== NSAlertAlternateReturn
)
4448 return NSTerminateCancel
;
4449 return NSTerminateNow
; /* just in case */
4453 /* Notification from the Workspace to open a file */
4454 - (BOOL
)application
: sender openFile
: (NSString
*)file
4456 [ns_pending_files addObject
: file
];
4461 /* Open a file as a temporary file */
4462 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4464 [ns_pending_files addObject
: file
];
4469 /* Notification from the Workspace to open a file noninteractively (?) */
4470 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4472 [ns_pending_files addObject
: file
];
4477 /* Notification from the Workspace to open multiple files */
4478 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4480 NSEnumerator
*files
= [fileList objectEnumerator
];
4482 while ((file
= [files nextObject
]) != nil
)
4483 [ns_pending_files addObject
: file
];
4485 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4490 /* Handle dock menu requests. */
4491 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4497 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4498 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4500 //ns_app_active
=YES
;
4502 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4504 NSTRACE
(applicationDidBecomeActive
);
4506 //ns_app_active
=YES
;
4508 ns_update_auto_hide_menu_bar
();
4509 // No constraining takes place when the application is not active.
4510 ns_constrain_all_frames
();
4512 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4515 ns_send_appdefined
(-1);
4520 /* ==========================================================================
4522 EmacsApp aux handlers for managing event loop
4524 ========================================================================== */
4527 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4528 /* --------------------------------------------------------------------------
4529 The timeout specified to ns_select has passed.
4530 -------------------------------------------------------------------------- */
4532 /*NSTRACE (timeout_handler); */
4533 ns_send_appdefined
(-2);
4536 - (void
)fd_handler
: (NSTimer
*) fdEntry
4537 /* --------------------------------------------------------------------------
4538 Check data waiting on file descriptors and terminate if so
4539 -------------------------------------------------------------------------- */
4542 /* NSTRACE (fd_handler); */
4544 if (select_nfds
== 0)
4547 memcpy
(&t_readfds
, &select_readfds
, sizeof
(fd_set
));
4549 select_timeout.tv_sec
= select_timeout.tv_usec
= 0;
4550 result
= select
(select_nfds
, &t_readfds
, (SELECT_TYPE
*)0, (SELECT_TYPE
*)0,
4554 memcpy
(&select_readfds
, &t_readfds
, sizeof
(fd_set
));
4555 ns_send_appdefined
(result
);
4561 /* ==========================================================================
4565 ========================================================================== */
4567 /* called from system: queue for next pass through event loop */
4568 - (void
)requestService
: (NSPasteboard
*)pboard
4569 userData
: (NSString
*)userData
4570 error: (NSString
**)error
4572 [ns_pending_service_names addObject
: userData
];
4573 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4574 SDATA
(ns_string_from_pasteboard
(pboard
))]];
4578 /* called from ns_read_socket to clear queue */
4579 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4581 struct frame
*emacsframe
= SELECTED_FRAME
();
4582 NSEvent
*theEvent
= [NSApp currentEvent
];
4587 emacs_event
->kind
= NS_NONKEY_EVENT
;
4588 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4589 ns_input_spi_name
= build_string
([name UTF8String
]);
4590 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4591 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4592 EV_TRAILER
(theEvent
);
4602 /* ==========================================================================
4604 EmacsView implementation
4606 ========================================================================== */
4609 @implementation EmacsView
4611 /* needed to inform when window closed from LISP */
4612 - (void
) setWindowClosing
: (BOOL
)closing
4614 windowClosing
= closing
;
4620 NSTRACE
(EmacsView_dealloc
);
4626 /* called on font panel selection */
4627 - (void
)changeFont
: (id
)sender
4629 NSEvent
*e
=[[self window
] currentEvent
];
4630 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4634 NSTRACE
(changeFont
);
4638 if (newFont
= [sender convertFont
:
4639 ((struct nsfont_info
*)face
->font
)->nsfont
])
4641 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4643 emacs_event
->kind
= NS_NONKEY_EVENT
;
4644 emacs_event
->modifiers
= 0;
4645 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4647 size = [newFont pointSize
];
4648 ns_input_fontsize
= make_number
(lrint
(size));
4649 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4655 - (BOOL
)acceptsFirstResponder
4657 NSTRACE
(acceptsFirstResponder
);
4662 - (void
)resetCursorRects
4664 NSRect visible
= [self visibleRect
];
4665 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4666 NSTRACE
(resetCursorRects
);
4668 if (currentCursor
== nil
)
4669 currentCursor
= [NSCursor arrowCursor
];
4671 if (!NSIsEmptyRect
(visible
))
4672 [self addCursorRect
: visible cursor
: currentCursor
];
4673 [currentCursor setOnMouseEntered
: YES
];
4678 /*****************************************************************************/
4679 /* Keyboard handling. */
4682 - (void
)keyDown
: (NSEvent
*)theEvent
4684 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
4686 unsigned fnKeysym
= 0;
4688 static NSMutableArray
*nsEvArray
;
4689 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4690 static BOOL firstTime
= YES
;
4696 /* Rhapsody and OS X give up and down events for the arrow keys */
4697 if (ns_fake_keydown
== YES
)
4698 ns_fake_keydown
= NO
;
4699 else if ([theEvent
type] != NSKeyDown
)
4705 if (![[self window
] isKeyWindow
]
4706 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4707 /* we must avoid an infinite loop here. */
4708 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4710 /* XXX: There is an occasional condition in which, when Emacs display
4711 updates a different frame from the current one, and temporarily
4712 selects it, then processes some interrupt-driven input
4713 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4714 for some reason that window has its first responder set to the NSView
4715 most recently updated (I guess), which is not the correct one. */
4716 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4720 if (nsEvArray
== nil
)
4721 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4723 [NSCursor setHiddenUntilMouseMoves
: YES
];
4725 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4727 clear_mouse_face
(hlinfo
);
4728 hlinfo
->mouse_face_hidden
= 1;
4731 if (!processingCompose
)
4733 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4734 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4735 /* (Carbon way: [theEvent keyCode]) */
4737 /* is it a "function key"? */
4738 fnKeysym
= ns_convert_key
(code
);
4741 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4742 because Emacs treats Delete and KP-Delete same (in simple.el). */
4743 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4744 code
= 0xFF08; /* backspace */
4749 /* are there modifiers? */
4750 emacs_event
->modifiers
= 0;
4751 flags
= [theEvent modifierFlags
];
4753 if (flags
& NSHelpKeyMask
)
4754 emacs_event
->modifiers |
= hyper_modifier
;
4756 if (flags
& NSShiftKeyMask
)
4757 emacs_event
->modifiers |
= shift_modifier
;
4759 if ((flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
)
4760 emacs_event
->modifiers |
= parse_solitary_modifier
4761 (EQ
(ns_right_command_modifier
, Qleft
)
4762 ? ns_command_modifier
4763 : ns_right_command_modifier
);
4765 if ((flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
)
4767 emacs_event
->modifiers |
= parse_solitary_modifier
4768 (ns_command_modifier
);
4770 /* if super (default), take input manager's word so things like
4771 dvorak / qwerty layout work */
4772 if (EQ
(ns_command_modifier
, Qsuper
)
4774 && [[theEvent characters
] length] != 0)
4776 /* XXX: the code we get will be unshifted, so if we have
4777 a shift modifier, must convert ourselves */
4778 if (!(flags
& NSShiftKeyMask
))
4779 code
= [[theEvent characters
] characterAtIndex
: 0];
4781 /* this is ugly and also requires linking w/Carbon framework
4782 (for LMGetKbdType) so for now leave this rare (?) case
4783 undealt with.. in future look into CGEvent methods */
4786 long smv
= GetScriptManagerVariable
(smKeyScript
);
4787 Handle uchrHandle
= GetResource
4788 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4790 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4791 [[theEvent characters
] characterAtIndex
: 0],
4792 kUCKeyActionDisplay
,
4793 (flags
& ~NSCommandKeyMask
) >> 8,
4794 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4795 &dummy
, 1, &dummy
, &code
);
4802 if ((flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
)
4803 emacs_event
->modifiers |
= parse_solitary_modifier
4804 (EQ
(ns_right_control_modifier
, Qleft
)
4805 ? ns_control_modifier
4806 : ns_right_control_modifier
);
4808 if ((flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
)
4809 emacs_event
->modifiers |
= parse_solitary_modifier
4810 (ns_control_modifier
);
4812 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4813 emacs_event
->modifiers |
=
4814 parse_solitary_modifier
(ns_function_modifier
);
4816 left_is_none
= NILP
(ns_alternate_modifier
)
4817 || EQ
(ns_alternate_modifier
, Qnone
);
4819 if ((flags
& NSRightAlternateKeyMask
) == NSRightAlternateKeyMask
)
4821 if ((NILP
(ns_right_alternate_modifier
)
4822 || EQ
(ns_right_alternate_modifier
, Qnone
)
4823 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
4825 { /* accept pre-interp alt comb */
4826 if ([[theEvent characters
] length] > 0)
4827 code
= [[theEvent characters
] characterAtIndex
: 0];
4828 /*HACK: clear lone shift modifier to stop next if from firing */
4829 if (emacs_event
->modifiers
== shift_modifier
)
4830 emacs_event
->modifiers
= 0;
4833 emacs_event
->modifiers |
= parse_solitary_modifier
4834 (EQ
(ns_right_alternate_modifier
, Qleft
)
4835 ? ns_alternate_modifier
4836 : ns_right_alternate_modifier
);
4839 if ((flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
) /* default = meta */
4841 if (left_is_none
&& !fnKeysym
)
4842 { /* accept pre-interp alt comb */
4843 if ([[theEvent characters
] length] > 0)
4844 code
= [[theEvent characters
] characterAtIndex
: 0];
4845 /*HACK: clear lone shift modifier to stop next if from firing */
4846 if (emacs_event
->modifiers
== shift_modifier
)
4847 emacs_event
->modifiers
= 0;
4850 emacs_event
->modifiers |
=
4851 parse_solitary_modifier
(ns_alternate_modifier
);
4855 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4856 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4858 /* if it was a function key or had modifiers, pass it directly to emacs */
4859 if (fnKeysym ||
(emacs_event
->modifiers
4860 && (emacs_event
->modifiers
!= shift_modifier
)
4861 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4862 /*[[theEvent characters] length] */
4864 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4866 code |
= (1<<28)|
(3<<16);
4867 else if (code
== 0x7f)
4868 code |
= (1<<28)|
(3<<16);
4870 emacs_event
->kind
= code
> 0xFF
4871 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4873 emacs_event
->code
= code
;
4874 EV_TRAILER
(theEvent
);
4880 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4881 /* if we get here we should send the key for input manager processing */
4882 if (firstTime
&& [[NSInputManager currentInputManager
]
4883 wantsToDelayTextChangeNotifications
] == NO
)
4885 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
4888 if (NS_KEYLOG
&& !processingCompose
)
4889 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
4891 processingCompose
= YES
;
4892 [nsEvArray addObject
: theEvent
];
4893 [self interpretKeyEvents
: nsEvArray
];
4894 [nsEvArray removeObject
: theEvent
];
4898 #ifdef NS_IMPL_COCOA
4899 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
4900 decided not to send key-down for.
4901 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
4902 This only applies on Tiger and earlier.
4903 If it matches one of these, send it on to keyDown. */
4904 -(void
)keyUp
: (NSEvent
*)theEvent
4906 int flags
= [theEvent modifierFlags
];
4907 int code
= [theEvent keyCode
];
4908 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
4909 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
4912 fprintf (stderr
, "keyUp
: passed test"
);
4913 ns_fake_keydown
= YES
;
4914 [self keyDown
: theEvent
];
4920 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
4923 /* <NSTextInput>: called when done composing;
4924 NOTE: also called when we delete over working text, followed immed.
4925 by doCommandBySelector: deleteBackward: */
4926 - (void
)insertText
: (id
)aString
4929 int len
= [(NSString
*)aString
length];
4933 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
4934 processingCompose
= NO
;
4939 /* first, clear any working text */
4940 if (workingText
!= nil
)
4941 [self deleteWorkingText
];
4943 /* now insert the string as keystrokes */
4944 for (i
=0; i
<len
; i
++)
4946 code
= [aString characterAtIndex
: i
];
4947 /* TODO: still need this? */
4949 code
= '~'; /* 0x7E */
4950 emacs_event
->modifiers
= 0;
4952 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4953 emacs_event
->code
= code
;
4954 EV_TRAILER
((id
)nil
);
4959 /* <NSTextInput>: inserts display of composing characters */
4960 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
4962 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
4963 [aString string
] : aString
;
4965 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
4966 selRange.
length, selRange.location
);
4968 if (workingText
!= nil
)
4969 [self deleteWorkingText
];
4970 if ([str
length] == 0)
4976 processingCompose
= YES
;
4977 workingText
= [str copy
];
4978 ns_working_text
= build_string
([workingText UTF8String
]);
4980 emacs_event
->kind
= NS_TEXT_EVENT
;
4981 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
4982 EV_TRAILER
((id
)nil
);
4986 /* delete display of composing characters [not in <NSTextInput>] */
4987 - (void
)deleteWorkingText
4989 if (workingText
== nil
)
4992 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
4993 [workingText release
];
4995 processingCompose
= NO
;
5000 emacs_event
->kind
= NS_TEXT_EVENT
;
5001 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5002 EV_TRAILER
((id
)nil
);
5006 - (BOOL
)hasMarkedText
5008 return workingText
!= nil
;
5012 - (NSRange
)markedRange
5014 NSRange rng
= workingText
!= nil
5015 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5017 NSLog
(@"markedRange request"
);
5025 NSLog
(@"unmark
(accept
) text"
);
5026 [self deleteWorkingText
];
5027 processingCompose
= NO
;
5031 /* used to position char selection windows, etc. */
5032 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5036 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5038 NSLog
(@"firstRectForCharRange request"
);
5040 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5041 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5042 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5043 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5044 +FRAME_LINE_HEIGHT
(emacsframe
));
5046 pt
= [self convertPoint
: pt toView
: nil
];
5047 pt
= [[self window
] convertBaseToScreen
: pt
];
5053 - (long)conversationIdentifier
5059 - (void
)doCommandBySelector
: (SEL
)aSelector
5062 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5064 if (aSelector
== @selector
(deleteBackward
:))
5066 /* happens when user backspaces over an ongoing composition:
5067 throw a 'delete' into the event queue */
5070 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5071 emacs_event
->code
= 0xFF08;
5072 EV_TRAILER
((id
)nil
);
5076 - (NSArray
*)validAttributesForMarkedText
5078 static NSArray
*arr
= nil
;
5079 if (arr
== nil
) arr
= [NSArray new
];
5080 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5084 - (NSRange
)selectedRange
5087 NSLog
(@"selectedRange request"
);
5088 return NSMakeRange
(NSNotFound
, 0);
5091 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5094 NSLog
(@"characterIndexForPoint request"
);
5098 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5100 static NSAttributedString
*str
= nil
;
5101 if (str
== nil
) str
= [NSAttributedString new
];
5103 NSLog
(@"attributedSubstringFromRange request"
);
5107 /* End <NSTextInput> impl. */
5108 /*****************************************************************************/
5111 /* This is what happens when the user presses a mouse button. */
5112 - (void
)mouseDown
: (NSEvent
*)theEvent
5114 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5117 NSTRACE
(mouseDown
);
5119 [self deleteWorkingText
];
5124 last_mouse_frame
= emacsframe
;
5125 /* appears to be needed to prevent spurious movement events generated on
5127 last_mouse_frame
->mouse_moved
= 0;
5129 if ([theEvent
type] == NSScrollWheel
)
5131 float delta
= [theEvent deltaY
];
5132 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5135 emacs_event
->kind
= WHEEL_EVENT
;
5136 emacs_event
->code
= 0;
5137 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5138 ((delta
> 0) ? up_modifier
: down_modifier
);
5142 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5143 emacs_event
->code
= EV_BUTTON
(theEvent
);
5144 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5145 | EV_UDMODIFIERS
(theEvent
);
5147 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5148 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5149 EV_TRAILER
(theEvent
);
5153 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5155 NSTRACE
(rightMouseDown
);
5156 [self mouseDown
: theEvent
];
5160 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5162 NSTRACE
(otherMouseDown
);
5163 [self mouseDown
: theEvent
];
5167 - (void
)mouseUp
: (NSEvent
*)theEvent
5170 [self mouseDown
: theEvent
];
5174 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5176 NSTRACE
(rightMouseUp
);
5177 [self mouseDown
: theEvent
];
5181 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5183 NSTRACE
(otherMouseUp
);
5184 [self mouseDown
: theEvent
];
5188 - (void
) scrollWheel
: (NSEvent
*)theEvent
5190 NSTRACE
(scrollWheel
);
5191 [self mouseDown
: theEvent
];
5195 /* Tell emacs the mouse has moved. */
5196 - (void
)mouseMoved
: (NSEvent
*)e
5198 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5201 // NSTRACE
(mouseMoved
);
5203 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5204 last_mouse_motion_position
5205 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5207 /* update any mouse face */
5208 if (hlinfo
->mouse_face_hidden
)
5210 hlinfo
->mouse_face_hidden
= 0;
5211 clear_mouse_face
(hlinfo
);
5214 /* tooltip handling */
5215 previous_help_echo_string
= help_echo_string
;
5216 help_echo_string
= Qnil
;
5218 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
5219 last_mouse_motion_position.y
))
5220 help_echo_string
= previous_help_echo_string
;
5222 XSETFRAME
(frame
, emacsframe
);
5223 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5225 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5226 (note_mouse_highlight), which is called through the
5227 note_mouse_movement () call above */
5228 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5229 help_echo_object
, help_echo_pos
);
5233 help_echo_string
= Qnil
;
5234 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5237 if (emacsframe
->mouse_moved
&& send_appdefined
)
5238 ns_send_appdefined
(-1);
5242 - (void
)mouseDragged
: (NSEvent
*)e
5244 NSTRACE
(mouseDragged
);
5245 [self mouseMoved
: e
];
5249 - (void
)rightMouseDragged
: (NSEvent
*)e
5251 NSTRACE
(rightMouseDragged
);
5252 [self mouseMoved
: e
];
5256 - (void
)otherMouseDragged
: (NSEvent
*)e
5258 NSTRACE
(otherMouseDragged
);
5259 [self mouseMoved
: e
];
5263 - (BOOL
)windowShouldClose
: (id
)sender
5265 NSEvent
*e
=[[self window
] currentEvent
];
5267 NSTRACE
(windowShouldClose
);
5268 windowClosing
= YES
;
5271 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5272 emacs_event
->modifiers
= 0;
5273 emacs_event
->code
= 0;
5275 /* Don't close this window, let this be done from lisp code. */
5280 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5281 /* normalize frame to gridded text size */
5283 NSTRACE
(windowWillResize
);
5284 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5286 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5287 #ifdef NS_IMPL_GNUSTEP
5288 frameSize.width
+ 3);
5292 if (cols
< MINWIDTH
)
5295 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5296 #ifdef NS_IMPL_GNUSTEP
5297 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5298 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5300 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5301 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5303 if (rows
< MINHEIGHT
)
5305 #ifdef NS_IMPL_COCOA
5307 /* this sets window title to have size in it; the wm does this under GS */
5308 NSRect r
= [[self window
] frame
];
5309 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5320 NSWindow
*window
= [self window
];
5323 const
char *t
= [[[self window
] title] UTF8String
];
5324 char *pos
= strstr
(t
, " — "
);
5327 old_title
= (char *) xmalloc
(strlen
(t
) + 1);
5328 strcpy
(old_title
, t
);
5330 size_title
= xmalloc
(strlen
(old_title
) + 40);
5331 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5332 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5337 #endif
/* NS_IMPL_COCOA */
5338 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5344 - (void
)windowDidResize
: (NSNotification
*)notification
5346 NSWindow
*theWindow
= [notification object
];
5348 #ifdef NS_IMPL_GNUSTEP
5349 /* in GNUstep, at least currently, it's possible to get a didResize
5350 without getting a willResize.. therefore we need to act as if we got
5351 the willResize now */
5352 NSSize sz
= [theWindow frame
].
size;
5353 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5354 #endif
/* NS_IMPL_GNUSTEP */
5356 NSTRACE
(windowDidResize
);
5357 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5359 #ifdef NS_IMPL_COCOA
5365 #endif
/* NS_IMPL_COCOA */
5367 /* Avoid loop under GNUstep due to call at beginning of this function.
5368 (x_set_window_size causes a resize which causes
5369 a "windowDidResize" which calls x_set_window_size). */
5370 #ifndef NS_IMPL_GNUSTEP
5371 if (cols
> 0 && rows
> 0)
5374 x_set_window_size
(emacsframe
, 0, cols
, rows
);
5377 NSWindow
*window
= [self window
];
5378 NSRect wr
= [window frame
];
5379 FRAME_PIXEL_WIDTH
(emacsframe
) = (int
)wr.
size.width
5380 - emacsframe
->border_width
;
5381 FRAME_PIXEL_HEIGHT
(emacsframe
) = (int
)wr.
size.height
5382 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5383 - FRAME_TOOLBAR_HEIGHT
(emacsframe
);
5384 change_frame_size
(emacsframe
, rows
, cols
, 0, 0, 1);
5385 SET_FRAME_GARBAGED
(emacsframe
);
5386 cancel_mouse_face
(emacsframe
);
5391 ns_send_appdefined
(-1);
5395 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5396 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5398 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5399 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5401 NSTRACE
(windowDidBecomeKey
);
5403 if (emacsframe
!= old_focus
)
5404 dpyinfo
->x_focus_frame
= emacsframe
;
5406 ns_frame_rehighlight
(emacsframe
);
5410 emacs_event
->kind
= FOCUS_IN_EVENT
;
5411 EV_TRAILER
((id
)nil
);
5416 - (void
)windowDidResignKey
: (NSNotification
*)notification
5417 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5419 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5420 NSTRACE
(windowDidResignKey
);
5422 if (dpyinfo
->x_focus_frame
== emacsframe
)
5423 dpyinfo
->x_focus_frame
= 0;
5425 ns_frame_rehighlight
(emacsframe
);
5427 /* FIXME: for some reason needed on second and subsequent clicks away
5428 from sole-frame Emacs to get hollow box to show */
5429 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5431 x_update_cursor
(emacsframe
, 1);
5432 x_set_frame_alpha
(emacsframe
);
5437 [self deleteWorkingText
];
5438 emacs_event
->kind
= FOCUS_IN_EVENT
;
5439 EV_TRAILER
((id
)nil
);
5444 - (void
)windowWillMiniaturize
: sender
5446 NSTRACE
(windowWillMiniaturize
);
5462 - initFrameFromEmacs
: (struct frame
*)f
5467 NSButton
*toggleButton
;
5468 int vbextra
= NS_SCROLL_BAR_WIDTH
(f
);
5473 NSTRACE
(initFrameFromEmacs
);
5476 processingCompose
= NO
;
5477 scrollbarsNeedingUpdate
= 0;
5479 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5481 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5482 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5483 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5484 [self initWithFrame
: r
];
5485 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5487 FRAME_NS_VIEW
(f
) = self
;
5491 win
= [[EmacsWindow alloc
]
5492 initWithContentRect
: r
5493 styleMask
: (NSResizableWindowMask |
5494 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5495 NSTitledWindowMask |
5497 NSMiniaturizableWindowMask |
5498 NSClosableWindowMask
)
5499 backing
: NSBackingStoreBuffered
5503 f
->border_width
= wr.
size.width
- r.
size.width
;
5504 FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
5506 [win setAcceptsMouseMovedEvents
: YES
];
5507 [win setDelegate
: self
];
5508 [win useOptimizedDrawing
: YES
];
5510 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5511 sz.height
= FRAME_LINE_HEIGHT
(f
);
5512 [win setResizeIncrements
: sz
];
5514 [[win contentView
] addSubview
: self
];
5517 [self registerForDraggedTypes
: ns_drag_types
];
5520 name
= [NSString stringWithUTF8String
:
5521 NILP
(tem
) ?
(unsigned
char *)"Emacs"
: SDATA
(tem
)];
5522 [win setTitle
: name
];
5524 /* toolbar support */
5525 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
5526 [NSString stringWithFormat
: @"Emacs Frame
%d",
5528 [win setToolbar
: toolbar
];
5529 [toolbar setVisible
: NO
];
5530 #ifdef NS_IMPL_COCOA
5531 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
5532 [toggleButton setTarget
: self
];
5533 [toggleButton setAction
: @selector
(toggleToolbar
: )];
5535 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5539 [win setMiniwindowTitle
:
5540 [NSString stringWithUTF8String
: SDATA
(tem
)]];
5543 NSScreen
*screen
= [win screen
];
5546 [win setFrameTopLeftPoint
: NSMakePoint
5547 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
5548 IN_BOUND
(-SCREENMAX
,
5549 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
5552 [win makeFirstResponder
: self
];
5554 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5555 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
5556 [win setBackgroundColor
: col
];
5557 if ([col alphaComponent
] != 1.0)
5558 [win setOpaque
: NO
];
5560 [self allocateGState
];
5562 [NSApp registerServicesMenuSendTypes
: ns_send_types
5570 - (void
)windowDidMove
: sender
5572 NSWindow
*win
= [self window
];
5573 NSRect r
= [win frame
];
5574 NSArray
*screens
= [NSScreen screens
];
5575 NSScreen
*screen
= [screens objectAtIndex
: 0];
5577 NSTRACE
(windowDidMove
);
5579 if (!emacsframe
->output_data.ns
)
5583 emacsframe
->left_pos
= r.origin.x
;
5584 emacsframe
->top_pos
=
5585 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
5590 /* Called AFTER method below, but before our windowWillResize call there leads
5591 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
5592 location so set_window_size moves the frame. */
5593 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5595 emacsframe
->output_data.ns
->zooming
= 1;
5600 /* Override to do something slightly nonstandard, but nice. First click on
5601 zoom button will zoom vertically. Second will zoom completely. Third
5602 returns to original. */
5603 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5604 defaultFrame
:(NSRect
)defaultFrame
5606 NSRect result
= [sender frame
];
5608 NSTRACE
(windowWillUseStandardFrame
);
5610 if (abs (defaultFrame.
size.height
- result.
size.height
)
5611 > FRAME_LINE_HEIGHT
(emacsframe
))
5614 ns_userRect
= result
;
5615 result.
size.height
= defaultFrame.
size.height
;
5616 result.origin.y
= defaultFrame.origin.y
;
5620 if (abs (defaultFrame.
size.width
- result.
size.width
)
5621 > FRAME_COLUMN_WIDTH
(emacsframe
))
5622 result
= defaultFrame
; /* second click */
5626 result
= ns_userRect.
size.height ? ns_userRect
: result
;
5627 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5631 [self windowWillResize
: sender toSize
: result.
size];
5636 - (void
)windowDidDeminiaturize
: sender
5638 NSTRACE
(windowDidDeminiaturize
);
5639 if (!emacsframe
->output_data.ns
)
5641 emacsframe
->async_iconified
= 0;
5642 emacsframe
->async_visible
= 1;
5643 windows_or_buffers_changed
++;
5647 emacs_event
->kind
= ICONIFY_EVENT
;
5648 EV_TRAILER
((id
)nil
);
5653 - (void
)windowDidExpose
: sender
5655 NSTRACE
(windowDidExpose
);
5656 if (!emacsframe
->output_data.ns
)
5658 emacsframe
->async_visible
= 1;
5659 SET_FRAME_GARBAGED
(emacsframe
);
5661 if (send_appdefined
)
5662 ns_send_appdefined
(-1);
5666 - (void
)windowDidMiniaturize
: sender
5668 NSTRACE
(windowDidMiniaturize
);
5669 if (!emacsframe
->output_data.ns
)
5672 emacsframe
->async_iconified
= 1;
5673 emacsframe
->async_visible
= 0;
5677 emacs_event
->kind
= ICONIFY_EVENT
;
5678 EV_TRAILER
((id
)nil
);
5683 - (void
)mouseEntered
: (NSEvent
*)theEvent
5685 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5686 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5687 NSTRACE
(mouseEntered
);
5689 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5693 - (void
)mouseExited
: (NSEvent
*)theEvent
5695 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5697 Mouse_HLInfo
*hlinfo
= emacsframe ? MOUSE_HL_INFO
(emacsframe
) : NULL;
5699 NSTRACE
(mouseExited
);
5704 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5706 if (emacsframe
== hlinfo
->mouse_face_mouse_frame
)
5708 clear_mouse_face
(hlinfo
);
5709 hlinfo
->mouse_face_mouse_frame
= 0;
5717 if (context_menu_value
== -1)
5718 context_menu_value
= [sender tag
];
5720 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
5721 emacsframe
->menu_bar_vector
,
5722 (void
*)[sender tag
]);
5723 ns_send_appdefined
(-1);
5728 - (EmacsToolbar
*)toolbar
5734 /* this gets called on toolbar button click */
5735 - toolbarClicked
: (id
)item
5738 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
5740 NSTRACE
(toolbarClicked
);
5745 /* send first event (for some reason two needed) */
5746 theEvent
= [[self window
] currentEvent
];
5747 emacs_event
->kind
= TOOL_BAR_EVENT
;
5748 XSETFRAME
(emacs_event
->arg
, emacsframe
);
5749 EV_TRAILER
(theEvent
);
5751 emacs_event
->kind
= TOOL_BAR_EVENT
;
5752 /* XSETINT (emacs_event->code, 0); */
5753 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
5754 idx
+ TOOL_BAR_ITEM_KEY
);
5755 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5756 EV_TRAILER
(theEvent
);
5761 - toggleToolbar
: (id
)sender
5766 emacs_event
->kind
= NS_NONKEY_EVENT
;
5767 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
5768 EV_TRAILER
((id
)nil
);
5773 - (void
)drawRect
: (NSRect
)rect
5775 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
5776 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
5780 if (!emacsframe ||
!emacsframe
->output_data.ns || ns_in_resize
)
5783 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
5784 expose_frame
(emacsframe
, x
, y
, width
, height
);
5787 drawRect: may be called (at least in OS X 10.5) for invisible
5788 views as well for some reason. Thus, do not infer visibility
5791 emacsframe->async_visible = 1;
5792 emacsframe->async_iconified = 0;
5797 /* NSDraggingDestination protocol methods. Actually this is not really a
5798 protocol, but a category of Object. O well... */
5800 -(NSUInteger
) draggingEntered
: (id
<NSDraggingInfo
>) sender
5802 NSTRACE
(draggingEntered
);
5803 return NSDragOperationGeneric
;
5807 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
5813 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
5818 NSEvent
*theEvent
= [[self window
] currentEvent
];
5821 NSTRACE
(performDragOperation
);
5826 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
5827 x
= lrint
(position.x
); y
= lrint
(position.y
);
5829 pb
= [sender draggingPasteboard
];
5830 type = [pb availableTypeFromArray
: ns_drag_types
];
5835 else if ([type isEqualToString
: NSFilenamesPboardType
])
5838 NSEnumerator
*fenum
;
5841 if (!(files
= [pb propertyListForType
: type]))
5844 fenum
= [files objectEnumerator
];
5845 while ( (file
= [fenum nextObject
]) )
5847 emacs_event
->kind
= NS_NONKEY_EVENT
;
5848 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5849 XSETINT
(emacs_event
->x
, x
);
5850 XSETINT
(emacs_event
->y
, y
);
5851 ns_input_file
= append2
(ns_input_file
,
5852 build_string
([file UTF8String
]));
5853 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5854 EV_TRAILER
(theEvent
);
5858 else if ([type isEqualToString
: NSURLPboardType
])
5863 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
5864 [fileURL isFileURL
] == NO
)
5867 file
= [fileURL
path];
5868 emacs_event
->kind
= NS_NONKEY_EVENT
;
5869 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5870 XSETINT
(emacs_event
->x
, x
);
5871 XSETINT
(emacs_event
->y
, y
);
5872 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
5873 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5874 EV_TRAILER
(theEvent
);
5877 else if ([type isEqualToString
: NSStringPboardType
]
5878 ||
[type isEqualToString
: NSTabularTextPboardType
])
5882 if (! (data
= [pb stringForType
: type]))
5885 emacs_event
->kind
= NS_NONKEY_EVENT
;
5886 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
5887 XSETINT
(emacs_event
->x
, x
);
5888 XSETINT
(emacs_event
->y
, y
);
5889 ns_input_text
= build_string
([data UTF8String
]);
5890 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5891 EV_TRAILER
(theEvent
);
5894 else if ([type isEqualToString
: NSColorPboardType
])
5896 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
5897 emacs_event
->kind
= NS_NONKEY_EVENT
;
5898 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
5899 XSETINT
(emacs_event
->x
, x
);
5900 XSETINT
(emacs_event
->y
, y
);
5901 ns_input_color
= ns_color_to_lisp
(c
);
5902 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5903 EV_TRAILER
(theEvent
);
5906 else if ([type isEqualToString
: NSFontPboardType
])
5908 /* impl based on GNUstep NSTextView.m */
5909 NSData
*data
= [pb dataForType
: NSFontPboardType
];
5910 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
5911 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
5917 emacs_event
->kind
= NS_NONKEY_EVENT
;
5918 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
5919 XSETINT
(emacs_event
->x
, x
);
5920 XSETINT
(emacs_event
->y
, y
);
5921 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
5922 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
5923 ns_input_fontsize
= build_string
(fontSize
);
5924 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5925 EV_TRAILER
(theEvent
);
5930 error ("Invalid data
type in dragging pasteboard."
);
5936 - (id
) validRequestorForSendType
: (NSString
*)typeSent
5937 returnType
: (NSString
*)typeReturned
5939 NSTRACE
(validRequestorForSendType
);
5940 if (typeSent
!= nil
&& [ns_send_types indexOfObject
: typeSent
] != NSNotFound
5941 && typeReturned
== nil
)
5943 if (! NILP
(ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
)))
5947 return [super validRequestorForSendType
: typeSent
5948 returnType
: typeReturned
];
5952 /* The next two methods are part of NSServicesRequests informal protocol,
5953 supposedly called when a services menu item is chosen from this app.
5954 But this should not happen because we override the services menu with our
5955 own entries which call ns-perform-service.
5956 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
5957 So let's at least stub them out until further investigation can be done. */
5959 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
5961 /* we could call ns_string_from_pasteboard(pboard) here but then it should
5962 be written into the buffer in place of the existing selection..
5963 ordinary service calls go through functions defined in ns-win.el */
5967 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
5969 NSArray
*typesDeclared
;
5972 /* We only support NSStringPboardType */
5973 if ([types containsObject
:NSStringPboardType
] == NO
) {
5977 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
5978 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
5981 if (CONSP
(val
) && NILP
(XCDR
(val
)))
5984 if (! STRINGP
(val
))
5987 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
5988 [pb declareTypes
:typesDeclared owner
:nil
];
5989 ns_string_to_pasteboard
(pb
, val
);
5994 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
5995 (gives a miniaturized version of the window); currently we use the latter for
5996 frames whose active buffer doesn't correspond to any file
5997 (e.g., '*scratch*') */
5998 - setMiniwindowImage
: (BOOL
) setMini
6000 id
image = [[self window
] miniwindowImage
];
6001 NSTRACE
(setMiniwindowImage
);
6003 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6004 about "AppleDockIconEnabled" notwithstanding, however the set message
6005 below has its effect nonetheless. */
6006 if (image != emacsframe
->output_data.ns
->miniimage
)
6008 if (image && [image isKindOfClass
: [EmacsImage
class]])
6010 [[self window
] setMiniwindowImage
:
6011 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6018 - (void
) setRows
: (int
) r andColumns
: (int
) c
6024 @
end /* EmacsView */
6028 /* ==========================================================================
6030 EmacsWindow implementation
6032 ========================================================================== */
6034 @implementation EmacsWindow
6036 /* If we have multiple monitors, one above the other, we don't want to
6037 restrict the height to just one monitor. So we override this. */
6038 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6040 /* When making the frame visible for the first time, we want to
6041 constrain. Other times not. */
6042 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6043 NSTRACE
(constrainFrameRect
);
6045 if (f
->output_data.ns
->dont_constrain
6046 || ns_menu_bar_should_be_hidden
())
6049 f
->output_data.ns
->dont_constrain
= 1;
6050 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6054 /* called only on resize clicks by special case in EmacsApp-sendEvent */
6055 - (void
)mouseDown
: (NSEvent
*)theEvent
6059 NSSize
size = [[theEvent window
] frame
].
size;
6060 grabOffset
= [theEvent locationInWindow
];
6061 grabOffset.x
= size.width
- grabOffset.x
;
6064 [super mouseDown
: theEvent
];
6069 - (void
)mouseUp
: (NSEvent
*)theEvent
6073 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6075 ns_set_name_as_filename
(f
);
6077 ns_send_appdefined
(-1);
6080 [super mouseUp
: theEvent
];
6084 /* send resize events */
6085 - (void
)mouseDragged
: (NSEvent
*)theEvent
6089 NSPoint p
= [theEvent locationInWindow
];
6090 NSSize
size, vettedSize
, origSize
= [self frame
].
size;
6092 size.width
= p.x
+ grabOffset.x
;
6093 size.height
= origSize.height
- p.y
+ grabOffset.y
;
6095 if (size.width
== origSize.width
&& size.height
== origSize.height
)
6098 vettedSize
= [[self delegate
] windowWillResize
: self toSize
: size];
6099 [[NSNotificationCenter defaultCenter
]
6100 postNotificationName
: NSWindowDidResizeNotification
6104 [super mouseDragged
: theEvent
];
6107 @
end /* EmacsWindow */
6110 /* ==========================================================================
6112 EmacsScroller implementation
6114 ========================================================================== */
6117 @implementation EmacsScroller
6119 /* for repeat button push */
6120 #define SCROLL_BAR_FIRST_DELAY
0.5
6121 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6123 + (CGFloat
) scrollerWidth
6125 /* TODO: if we want to allow variable widths, this is the place to do it,
6126 however neither GNUstep nor Cocoa support it very well */
6127 return [NSScroller scrollerWidth
];
6131 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
6133 NSTRACE
(EmacsScroller_initFrame
);
6135 r.
size.width
= [EmacsScroller scrollerWidth
];
6136 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
6137 [self setContinuous
: YES
];
6138 [self setEnabled
: YES
];
6140 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
6141 locked against the top and bottom edges, and right edge on OS X, where
6142 scrollers are on right. */
6143 #ifdef NS_IMPL_GNUSTEP
6144 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
6146 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
6151 pixel_height
= NSHeight
(r
);
6152 if (pixel_height
== 0) pixel_height
= 1;
6153 min_portion
= 20 / pixel_height
;
6155 frame
= XFRAME
(XWINDOW
(win
)->frame
);
6156 if (FRAME_LIVE_P
(frame
))
6159 EmacsView
*view = FRAME_NS_VIEW
(frame
);
6160 NSView
*sview
= [[view window
] contentView
];
6161 NSArray
*subs
= [sview subviews
];
6163 /* disable optimization stopping redraw of other scrollbars */
6164 view->scrollbarsNeedingUpdate
= 0;
6165 for (i
=[subs count
]-1; i
>= 0; i
--)
6166 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
6167 view->scrollbarsNeedingUpdate
++;
6168 [sview addSubview
: self
];
6171 /* [self setFrame: r]; */
6177 - (void
)setFrame
: (NSRect
)newRect
6179 NSTRACE
(EmacsScroller_setFrame
);
6181 pixel_height
= NSHeight
(newRect
);
6182 if (pixel_height
== 0) pixel_height
= 1;
6183 min_portion
= 20 / pixel_height
;
6184 [super setFrame
: newRect
];
6186 /* UNBLOCK_INPUT; */
6192 NSTRACE
(EmacsScroller_dealloc
);
6194 XWINDOW
(win
)->vertical_scroll_bar
= Qnil
;
6222 /* ensure other scrollbar updates after deletion */
6223 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6225 view->scrollbarsNeedingUpdate
++;
6226 [self removeFromSuperview
];
6234 - (void
)resetCursorRects
6236 NSRect visible
= [self visibleRect
];
6237 NSTRACE
(resetCursorRects
);
6239 if (!NSIsEmptyRect
(visible
))
6240 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
6241 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
6245 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
6248 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
6249 && portion
!= whole
; /* needed for resize empty buf */
6253 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
6255 NSTRACE
(setPosition
);
6257 em_position
= position
;
6258 em_portion
= portion
;
6261 if (portion
>= whole
)
6263 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6264 [self setKnobProportion
: 1.0];
6265 [self setDoubleValue
: 1.0];
6267 [self setFloatValue
: 0.0 knobProportion
: 1.0];
6273 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
6274 pos
= (float
)position
/ (whole
- portion
);
6275 por
= (float
)portion
/whole
;
6276 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6277 [self setKnobProportion
: por
];
6278 [self setDoubleValue
: pos
];
6280 [self setFloatValue
: pos knobProportion
: por
];
6286 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
6287 drag events will go directly to the EmacsScroller. Leaving in for now. */
6288 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
6289 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
6291 *part
= last_hit_part
;
6293 XSETINT
(*y
, pixel_height
);
6294 if ([self floatValue
] > 0.999)
6295 XSETINT
(*x
, pixel_height
);
6297 XSETINT
(*x
, pixel_height
* [self floatValue
]);
6301 /* set up emacs_event */
6302 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
6307 emacs_event
->part
= last_hit_part
;
6308 emacs_event
->code
= 0;
6309 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
6310 emacs_event
->frame_or_window
= win
;
6311 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
6312 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
6313 emacs_event
->arg
= Qnil
;
6314 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
6315 XSETINT
(emacs_event
->y
, pixel_height
-20);
6317 n_emacs_events_pending
++;
6318 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
6319 EVENT_INIT
(*emacs_event
);
6320 ns_send_appdefined
(-1);
6324 /* called manually thru timer to implement repeated button action w/hold-down */
6325 - repeatScroll
: (NSTimer
*)scrollEntry
6327 NSEvent
*e
= [[self window
] currentEvent
];
6328 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
6329 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
6331 /* clear timer if need be */
6332 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
6334 [scroll_repeat_entry invalidate
];
6335 [scroll_repeat_entry release
];
6336 scroll_repeat_entry
= nil
;
6342 = [[NSTimer scheduledTimerWithTimeInterval
:
6343 SCROLL_BAR_CONTINUOUS_DELAY
6345 selector
: @selector
(repeatScroll
:)
6351 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
6356 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
6357 mouseDragged events without going into a modal loop. */
6358 - (void
)mouseDown
: (NSEvent
*)e
6361 /* hitPart is only updated AFTER event is passed on */
6362 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6363 double inc
= 0.0, loc
, kloc
, pos
;
6366 NSTRACE
(EmacsScroller_mouseDown
);
6370 case NSScrollerDecrementPage
:
6371 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6372 case NSScrollerIncrementPage
:
6373 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6374 case NSScrollerDecrementLine
:
6375 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6376 case NSScrollerIncrementLine
:
6377 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6378 case NSScrollerKnob
:
6379 last_hit_part
= scroll_bar_handle
; break;
6380 case NSScrollerKnobSlot
: /* GNUstep-only */
6381 last_hit_part
= scroll_bar_move_ratio
; break;
6382 default
: /* NSScrollerNoPart? */
6383 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
6390 pos
= 0; /* ignored */
6392 /* set a timer to repeat, as we can't let superclass do this modally */
6394 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
6396 selector
: @selector
(repeatScroll
:)
6403 /* handle, or on GNUstep possibly slot */
6404 NSEvent
*fake_event
;
6406 /* compute float loc in slot and mouse offset on knob */
6407 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6409 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6415 else if (loc
>= NSHeight
(sr
))
6417 loc
= NSHeight
(sr
);
6425 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6427 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6429 last_mouse_offset
= kloc
;
6431 /* if knob, tell emacs a location offset by knob pos
6432 (to indicate top of handle) */
6433 if (part
== NSScrollerKnob
)
6434 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6436 /* else this is a slot click on GNUstep: go straight there */
6437 pos
= loc
/ NSHeight
(sr
);
6439 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6440 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6441 location
: [e locationInWindow
]
6442 modifierFlags
: [e modifierFlags
]
6443 timestamp
: [e timestamp
]
6444 windowNumber
: [e windowNumber
]
6445 context
: [e context
]
6446 eventNumber
: [e eventNumber
]
6447 clickCount
: [e clickCount
]
6448 pressure
: [e pressure
]];
6449 [super mouseUp
: fake_event
];
6452 if (part
!= NSScrollerKnob
)
6453 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6457 /* Called as we manually track scroller drags, rather than superclass. */
6458 - (void
)mouseDragged
: (NSEvent
*)e
6464 NSTRACE
(EmacsScroller_mouseDragged
);
6466 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6468 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6475 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6477 loc
= NSHeight
(sr
) + last_mouse_offset
;
6481 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6482 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6486 - (void
)mouseUp
: (NSEvent
*)e
6488 if (scroll_repeat_entry
)
6490 [scroll_repeat_entry invalidate
];
6491 [scroll_repeat_entry release
];
6492 scroll_repeat_entry
= nil
;
6498 /* treat scrollwheel events in the bar as though they were in the main window */
6499 - (void
) scrollWheel
: (NSEvent
*)theEvent
6501 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6502 [view mouseDown
: theEvent
];
6505 @
end /* EmacsScroller */
6510 /* ==========================================================================
6512 Font-related functions; these used to be in nsfaces.m
6514 ========================================================================== */
6518 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6520 struct font
*font
= XFONT_OBJECT
(font_object
);
6523 fontset
= fontset_from_font
(font_object
);
6524 FRAME_FONTSET
(f
) = fontset
;
6526 if (FRAME_FONT
(f
) == font
)
6527 /* This font is already set in frame F. There's nothing more to
6531 FRAME_FONT
(f
) = font
;
6533 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6534 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6535 FRAME_SPACE_WIDTH
(f
) = font
->space_width
;
6536 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6538 compute_fringe_widths
(f
, 1);
6540 /* Compute the scroll bar width in character columns. */
6541 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6543 int wid
= FRAME_COLUMN_WIDTH
(f
);
6544 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6545 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6549 int wid
= FRAME_COLUMN_WIDTH
(f
);
6550 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6553 /* Now make the frame display the given font. */
6554 if (FRAME_NS_WINDOW
(f
) != 0)
6555 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6561 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6562 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6566 ns_xlfd_to_fontname
(const
char *xlfd
)
6567 /* --------------------------------------------------------------------------
6568 Convert an X font name (XLFD) to an NS font name.
6569 Only family is used.
6570 The string returned is temporarily allocated.
6571 -------------------------------------------------------------------------- */
6573 char *name
= xmalloc
(180);
6577 if (!strncmp
(xlfd
, "
--"
, 2))
6578 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
6580 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
6582 /* stopgap for malformed XLFD input */
6583 if (strlen
(name
) == 0)
6584 strcpy
(name
, "Monaco"
);
6586 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
6587 also uppercase after '-' or ' ' */
6588 name
[0] = toupper
(name
[0]);
6589 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
6595 name
[i
+1] = toupper
(name
[i
+1]);
6597 else if (name
[i
] == '_')
6601 name
[i
+1] = toupper
(name
[i
+1]);
6604 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
6605 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
6612 syms_of_nsterm
(void
)
6614 NSTRACE
(syms_of_nsterm
);
6616 ns_antialias_threshold
= 10.0;
6618 /* from 23+ we need to tell emacs what modifiers there are.. */
6619 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
6620 DEFSYM
(Qalt
, "alt"
);
6621 DEFSYM
(Qhyper
, "hyper"
);
6622 DEFSYM
(Qmeta
, "
meta"
);
6623 DEFSYM
(Qsuper
, "super"
);
6624 DEFSYM
(Qcontrol
, "control"
);
6625 DEFSYM
(Qnone
, "none"
);
6626 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
6628 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
6629 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
6630 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
6631 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
6632 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
6634 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
6635 "The file specified in the last NS event."
);
6636 ns_input_file
=Qnil
;
6638 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
6639 "The data received in the last NS
text drag event."
);
6640 ns_input_text
=Qnil
;
6642 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
6643 "String
for visualizing working composition sequence."
);
6644 ns_working_text
=Qnil
;
6646 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
6647 "The font specified in the last NS event."
);
6648 ns_input_font
=Qnil
;
6650 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
6651 "The fontsize specified in the last NS event."
);
6652 ns_input_fontsize
=Qnil
;
6654 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
6655 "The
line specified in the last NS event."
);
6656 ns_input_line
=Qnil
;
6658 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
6659 "The color specified in the last NS event."
);
6660 ns_input_color
=Qnil
;
6662 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
6663 "The service name specified in the last NS event."
);
6664 ns_input_spi_name
=Qnil
;
6666 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
6667 "The service argument specified in the last NS event."
);
6668 ns_input_spi_arg
=Qnil
;
6670 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
6671 "This variable describes the behavior of the alternate or option key.
\n\
6672 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6673 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
6674 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6675 ns_alternate_modifier
= Qmeta
;
6677 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
6678 "This variable describes the behavior of the right alternate or option key.
\n\
6679 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6680 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
6681 Set to none means that the alternate / option key is not interpreted by Emacs\n\
6682 at all, allowing it to be used at a lower level for accented character entry.");
6683 ns_right_alternate_modifier = Qleft;
6685 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
6686 "This variable describes the behavior of the command key.\n\
6687 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
6688 ns_command_modifier = Qsuper;
6690 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
6691 "This variable describes the behavior of the right command key.\n\
6692 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6693 Set to left means be the same key as `ns-command-modifier'.
\n\
6694 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
6695 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6696 ns_right_command_modifier
= Qleft
;
6698 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
6699 "This variable describes the behavior of the control key.
\n\
6700 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
6701 ns_control_modifier
= Qcontrol
;
6703 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
6704 "This variable describes the behavior of the right control key.
\n\
6705 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6706 Set to left means be the same key as `ns
-control
-modifier
'.\n\
6707 Set to none means that the control / option key is not interpreted by Emacs\n\
6708 at all, allowing it to be used at a lower level for accented character entry.");
6709 ns_right_control_modifier = Qleft;
6711 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
6712 "This variable describes the behavior of the function key (on laptops).\n\
6713 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6714 Set to none means that the function key is not interpreted by Emacs at all,\n\
6715 allowing it to be used at a lower level for accented character entry.");
6716 ns_function_modifier = Qnone;
6718 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
6719 "Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above.");
6720 ns_antialias_text = Qt;
6722 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
6723 "Whether to confirm application quit using dialog.");
6724 ns_confirm_quit = Qnil;
6726 staticpro (&ns_display_name_list);
6727 ns_display_name_list = Qnil;
6729 staticpro (&last_mouse_motion_frame);
6730 last_mouse_motion_frame = Qnil;
6732 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
6733 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
6734 Only works on OSX 10.6 or later. */);
6735 ns_auto_hide_menu_bar = Qnil;
6737 /* TODO: move to common code */
6738 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
6739 doc: /* Which toolkit scroll bars Emacs uses, if any.
6740 A value of nil means Emacs doesn't use toolkit scroll bars.
6741 With the X Window system
, the value is a symbol describing the
6742 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
6743 With MS Windows or Nextstep
, the value is t. */
);
6744 Vx_toolkit_scroll_bars
= Qt
;
6746 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
6747 x_use_underline_position_properties
,
6748 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
6749 A value of nil means ignore them. If you encounter fonts with bogus
6750 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
6751 to 4.1, set this to nil. */);
6752 x_use_underline_position_properties
= 0;
6754 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
6755 x_underline_at_descent_line
,
6756 doc: /* Non-nil means to draw the underline at the same place as the descent line.
6757 A value of nil means to draw the underline according to the value of the
6758 variable `x-use-underline-position-properties', which is usually at the
6759 baseline level. The default value is nil. */);
6760 x_underline_at_descent_line
= 0;
6762 /* Tell emacs about this window system. */
6763 Fprovide
(intern
("ns"
), Qnil
);