1 /* NeXT/Open/GNUstep / MacOSX communication module.
3 Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2012
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 Originally by Carl Edman
23 Updated by Christian Limpach (chris@nice.ch)
24 OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com)
25 MacOSX/Aqua port by Christophe de Dinechin (descubes@earthlink.net)
26 GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
29 /* This should be the first include, as it may set up #defines affecting
30 interpretation of even the system includes. */
34 #include
<sys
/types.h
>
39 #include
<c
-strcase.h
>
43 #include "blockinput.h"
44 #include "sysselect.h"
47 #include "character.h"
49 #include "composite.h"
52 #include "termhooks.h"
63 int term_trace_num
= 0;
64 #define NSTRACE
(x
) fprintf (stderr
, "
%s:%d: [%d] " #x "\n", \
65 __FILE__
, __LINE__
, ++term_trace_num
)
70 extern NSString
*NSMenuDidBeginTrackingNotification
;
72 /* ==========================================================================
76 ========================================================================== */
78 /* Convert a symbol indexed with an NSxxx value to a value as defined
79 in keyboard.c (lispy_function_key). I hope this is a correct way
81 static unsigned convert_ns_to_X_keysym
[] =
83 NSHomeFunctionKey
, 0x50,
84 NSLeftArrowFunctionKey
, 0x51,
85 NSUpArrowFunctionKey
, 0x52,
86 NSRightArrowFunctionKey
, 0x53,
87 NSDownArrowFunctionKey
, 0x54,
88 NSPageUpFunctionKey
, 0x55,
89 NSPageDownFunctionKey
, 0x56,
90 NSEndFunctionKey
, 0x57,
91 NSBeginFunctionKey
, 0x58,
92 NSSelectFunctionKey
, 0x60,
93 NSPrintFunctionKey
, 0x61,
94 NSExecuteFunctionKey
, 0x62,
95 NSInsertFunctionKey
, 0x63,
96 NSUndoFunctionKey
, 0x65,
97 NSRedoFunctionKey
, 0x66,
98 NSMenuFunctionKey
, 0x67,
99 NSFindFunctionKey
, 0x68,
100 NSHelpFunctionKey
, 0x6A,
101 NSBreakFunctionKey
, 0x6B,
103 NSF1FunctionKey
, 0xBE,
104 NSF2FunctionKey
, 0xBF,
105 NSF3FunctionKey
, 0xC0,
106 NSF4FunctionKey
, 0xC1,
107 NSF5FunctionKey
, 0xC2,
108 NSF6FunctionKey
, 0xC3,
109 NSF7FunctionKey
, 0xC4,
110 NSF8FunctionKey
, 0xC5,
111 NSF9FunctionKey
, 0xC6,
112 NSF10FunctionKey
, 0xC7,
113 NSF11FunctionKey
, 0xC8,
114 NSF12FunctionKey
, 0xC9,
115 NSF13FunctionKey
, 0xCA,
116 NSF14FunctionKey
, 0xCB,
117 NSF15FunctionKey
, 0xCC,
118 NSF16FunctionKey
, 0xCD,
119 NSF17FunctionKey
, 0xCE,
120 NSF18FunctionKey
, 0xCF,
121 NSF19FunctionKey
, 0xD0,
122 NSF20FunctionKey
, 0xD1,
123 NSF21FunctionKey
, 0xD2,
124 NSF22FunctionKey
, 0xD3,
125 NSF23FunctionKey
, 0xD4,
126 NSF24FunctionKey
, 0xD5,
128 NSBackspaceCharacter
, 0x08, /* 8: Not on some KBs. */
129 NSDeleteCharacter
, 0xFF, /* 127: Big 'delete' key upper right. */
130 NSDeleteFunctionKey
, 0x9F, /* 63272: Del forw key off main array. */
132 NSTabCharacter
, 0x09,
133 0x19, 0x09, /* left tab->regular since pass shift */
134 NSCarriageReturnCharacter
, 0x0D,
135 NSNewlineCharacter
, 0x0D,
136 NSEnterCharacter
, 0x8D,
138 0x1B, 0x1B /* escape */
141 static Lisp_Object Qmodifier_value
;
142 Lisp_Object Qalt
, Qcontrol
, Qhyper
, Qmeta
, Qsuper
, Qnone
;
143 extern Lisp_Object Qcursor_color
, Qcursor_type
, Qns
, Qleft
;
145 static Lisp_Object QUTF8_STRING
;
147 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
148 the maximum font size to NOT antialias. On GNUstep there is currently
149 no way to control this behavior. */
150 float ns_antialias_threshold
;
152 /* Used to pick up AppleHighlightColor on OS X */
153 NSString
*ns_selection_color
;
155 NSArray
*ns_send_types
=0, *ns_return_types
=0, *ns_drag_types
=0;
156 NSString
*ns_app_name
= @"Emacs"
; /* default changed later */
158 /* Display variables */
159 struct ns_display_info
*x_display_list
; /* Chain of existing displays */
160 Lisp_Object ns_display_name_list
;
161 long context_menu_value
= 0;
164 NSPoint last_mouse_motion_position
;
165 static NSRect last_mouse_glyph
;
166 static Time last_mouse_movement_time
= 0;
167 static Lisp_Object last_mouse_motion_frame
;
168 static EmacsScroller
*last_mouse_scroll_bar
= nil
;
169 static
struct frame
*ns_updating_frame
;
170 static NSView
*focus_view
= NULL;
171 static int ns_window_num
= 0;
173 static BOOL gsaved
= NO
;
174 BOOL ns_in_resize
= NO
;
175 static BOOL ns_fake_keydown
= NO
;
176 int ns_tmp_flags
; /* FIXME */
177 struct nsfont_info
*ns_tmp_font
; /* FIXME */
178 static BOOL ns_menu_bar_is_hidden
= NO
;
179 /*static int debug_lock = 0; */
182 static BOOL send_appdefined
= YES
;
183 static NSEvent
*last_appdefined_event
= 0;
184 static NSTimer
*timed_entry
= 0;
185 static NSTimer
*fd_entry
= nil
;
186 static NSTimer
*scroll_repeat_entry
= nil
;
187 static fd_set select_readfds
, t_readfds
;
188 static int select_nfds
;
189 static NSAutoreleasePool
*outerpool
;
190 static
struct input_event
*emacs_event
= NULL;
191 static
struct input_event
*q_event_ptr
= NULL;
192 static int n_emacs_events_pending
= 0;
193 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
194 *ns_pending_service_args
;
195 static BOOL inNsSelect
= 0;
197 /* Convert modifiers in a NeXTstep event to emacs style modifiers. */
198 #define NS_FUNCTION_KEY_MASK
0x800000
199 #define NSLeftControlKeyMask
(0x000001 | NSControlKeyMask
)
200 #define NSRightControlKeyMask
(0x002000 | NSControlKeyMask
)
201 #define NSLeftCommandKeyMask
(0x000008 | NSCommandKeyMask
)
202 #define NSRightCommandKeyMask
(0x000010 | NSCommandKeyMask
)
203 #define NSLeftAlternateKeyMask
(0x000020 | NSAlternateKeyMask
)
204 #define NSRightAlternateKeyMask
(0x000040 | NSAlternateKeyMask
)
205 #define EV_MODIFIERS
(e
) \
206 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
207 hyper_modifier
: 0) \
208 |
(!EQ
(ns_right_alternate_modifier
, Qleft
) && \
209 (([e modifierFlags
] & NSRightAlternateKeyMask
) \
210 == NSRightAlternateKeyMask
) ? \
211 parse_solitary_modifier
(ns_right_alternate_modifier
) : 0) \
212 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
213 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
214 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
215 shift_modifier
: 0) \
216 |
(!EQ
(ns_right_control_modifier
, Qleft
) && \
217 (([e modifierFlags
] & NSRightControlKeyMask
) \
218 == NSRightControlKeyMask
) ? \
219 parse_solitary_modifier
(ns_right_control_modifier
) : 0) \
220 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
221 parse_solitary_modifier
(ns_control_modifier
) : 0) \
222 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
223 parse_solitary_modifier
(ns_function_modifier
) : 0) \
224 |
(!EQ
(ns_right_command_modifier
, Qleft
) && \
225 (([e modifierFlags
] & NSRightCommandKeyMask
) \
226 == NSRightCommandKeyMask
) ? \
227 parse_solitary_modifier
(ns_right_command_modifier
) : 0) \
228 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
229 parse_solitary_modifier
(ns_command_modifier
):0))
231 #define EV_UDMODIFIERS
(e
) \
232 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
233 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
234 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
235 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
236 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
237 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
238 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
239 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
240 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
242 #define EV_BUTTON
(e
) \
243 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
244 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
245 [e buttonNumber
] - 1)
247 /* Convert the time field to a timestamp in milliseconds. */
248 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
250 /* This is a piece of code which is common to all the event handling
251 methods. Maybe it should even be a function. */
252 #define EV_TRAILER
(e
) \
254 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
255 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
256 n_emacs_events_pending
++; \
257 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
258 EVENT_INIT
(*emacs_event
); \
259 ns_send_appdefined
(-1); \
262 void x_set_cursor_type
(struct frame
*, Lisp_Object
, Lisp_Object
);
264 /* TODO: get rid of need for these forward declarations */
265 static void ns_condemn_scroll_bars
(struct frame
*f
);
266 static void ns_judge_scroll_bars
(struct frame
*f
);
267 void x_set_frame_alpha
(struct frame
*f
);
270 /* ==========================================================================
274 ========================================================================== */
278 append2
(Lisp_Object list
, Lisp_Object item
)
279 /* --------------------------------------------------------------------------
280 Utility to append to a list
281 -------------------------------------------------------------------------- */
283 Lisp_Object array
[2];
285 array
[1] = Fcons
(item
, Qnil
);
286 return Fnconc
(2, &array
[0]);
291 ns_etc_directory
(void
)
292 /* If running as a self-contained app bundle, return as a string the
293 filename of the etc directory, if present; else nil. */
295 NSBundle
*bundle
= [NSBundle mainBundle
];
296 NSString
*resourceDir
= [bundle resourcePath
];
297 NSString
*resourcePath
;
298 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
301 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
302 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
304 if (isDir
) return [resourcePath UTF8String
];
312 /* If running as a self-contained app bundle, return as a path string
313 the filenames of the libexec and bin directories, ie libexec:bin.
314 Otherwise, return nil.
315 Normally, Emacs does not add its own bin/ directory to the PATH.
316 However, a self-contained NS build has a different layout, with
317 bin/ and libexec/ subdirectories in the directory that contains
319 We put libexec first, because init_callproc_1 uses the first
320 element to initialize exec-directory. An alternative would be
321 for init_callproc to check for invocation-directory/libexec.
324 NSBundle
*bundle
= [NSBundle mainBundle
];
325 NSString
*resourceDir
= [bundle resourcePath
];
326 NSString
*binDir
= [bundle bundlePath
];
327 NSString
*resourcePath
, *resourcePaths
;
329 BOOL onWindows
= NO
; /* FIXME determine this somehow */
330 NSString
*pathSeparator
= onWindows ? @"
;"
: @"
:"
;
331 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
333 NSEnumerator
*pathEnum
;
336 range
= [resourceDir rangeOfString
: @"Contents"
];
337 if (range.location
!= NSNotFound
)
339 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
341 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
345 paths
= [binDir stringsByAppendingPaths
:
346 [NSArray arrayWithObjects
: @"libexec"
, @"bin"
, nil
]];
347 pathEnum
= [paths objectEnumerator
];
350 while (resourcePath
= [pathEnum nextObject
])
352 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
355 if ([resourcePaths
length] > 0)
357 = [resourcePaths stringByAppendingString
: pathSeparator
];
359 = [resourcePaths stringByAppendingString
: resourcePath
];
362 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
370 /* If running as a self-contained app bundle, return as a path string
371 the filenames of the site-lisp, lisp and leim directories.
372 Ie, site-lisp:lisp:leim. Otherwise, return nil. */
374 NSBundle
*bundle
= [NSBundle mainBundle
];
375 NSString
*resourceDir
= [bundle resourcePath
];
376 NSString
*resourcePath
, *resourcePaths
;
377 BOOL onWindows
= NO
; /* FIXME determine this somehow */
378 NSString
*pathSeparator
= onWindows ? @"
;"
: @"
:"
;
379 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
381 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
382 [NSArray arrayWithObjects
:
383 @"site
-lisp"
, @"lisp"
, @"leim"
, nil
]];
384 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
387 /* Hack to skip site-lisp. */
388 if (no_site_lisp
) resourcePath
= [pathEnum nextObject
];
390 while (resourcePath
= [pathEnum nextObject
])
392 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
395 if ([resourcePaths
length] > 0)
397 = [resourcePaths stringByAppendingString
: pathSeparator
];
399 = [resourcePaths stringByAppendingString
: resourcePath
];
402 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
408 ns_timeout
(int usecs
)
409 /* --------------------------------------------------------------------------
410 Blocking timer utility used by ns_ring_bell
411 -------------------------------------------------------------------------- */
413 EMACS_TIME wakeup
= add_emacs_time
(current_emacs_time
(),
414 make_emacs_time
(0, usecs
* 1000));
416 /* Keep waiting until past the time wakeup. */
419 EMACS_TIME timeout
, now
= current_emacs_time
();
420 if (EMACS_TIME_LE
(wakeup
, now
))
422 timeout
= sub_emacs_time
(wakeup
, now
);
424 /* Try to wait that long--but we might wake up sooner. */
425 pselect
(0, NULL, NULL, NULL, &timeout
, NULL);
431 ns_release_object
(void
*obj
)
432 /* --------------------------------------------------------------------------
433 Release an object (callable from C)
434 -------------------------------------------------------------------------- */
441 ns_retain_object
(void
*obj
)
442 /* --------------------------------------------------------------------------
443 Retain an object (callable from C)
444 -------------------------------------------------------------------------- */
451 ns_alloc_autorelease_pool
(void
)
452 /* --------------------------------------------------------------------------
453 Allocate a pool for temporary objects (callable from C)
454 -------------------------------------------------------------------------- */
456 return [[NSAutoreleasePool alloc
] init
];
461 ns_release_autorelease_pool
(void
*pool
)
462 /* --------------------------------------------------------------------------
463 Free a pool and temporary objects it refers to (callable from C)
464 -------------------------------------------------------------------------- */
466 ns_release_object
(pool
);
471 /* ==========================================================================
473 Focus (clipping) and screen update
475 ========================================================================== */
478 ns_resize_handle_rect
(NSWindow
*window
)
480 NSRect r
= [window frame
];
481 r.origin.x
= r.
size.width
- RESIZE_HANDLE_SIZE
;
483 r.
size.width
= r.
size.height
= RESIZE_HANDLE_SIZE
;
489 // Window constraining
490 // -------------------
492 // To ensure that the windows are not placed under the
menu bar, they
493 // are typically moved by the call
-back constrainFrameRect. However
,
494 // by overriding it
, it
's possible to inhibit this, leaving the window
495 // in it's original position.
497 // It
's possible to hide the menu bar. However, technically, it's only
498 // possible to hide it when the application is active. To ensure that
499 // this work properly
, the
menu bar and window constraining are
500 // deferred until the application becomes active.
502 // Even though it
's not possible to manually move a window above the
503 // top of the screen, it is allowed if it's done programmatically
,
504 // when the
menu is
hidden. This allows the editable area to cover the
505 // full screen height.
510 // Use the following extra files
:
513 // ;; Hide
menu and place frame slightly above the top of the screen.
514 // (setq ns
-auto
-hide
-menu-bar t
)
515 // (set-frame
-position
(selected
-frame
) 0 -20)
519 // emacs
-Q
-l init.el
521 // Result
: No
menu bar, and the
title bar should be above the screen.
527 // Result
: Menu bar visible
, frame placed immediately below the
menu.
531 ns_constrain_all_frames
(void
)
533 Lisp_Object tail
, frame
;
535 FOR_EACH_FRAME
(tail
, frame
)
537 struct frame
*f
= XFRAME
(frame
);
540 NSView
*view = FRAME_NS_VIEW
(f
);
541 /* This no-op will trigger the default window placing
542 * constraint system. */
543 f
->output_data.ns
->dont_constrain
= 0;
544 [[view window
] setFrameOrigin
:[[view window
] frame
].origin
];
550 /* True, if the menu bar should be hidden. */
553 ns_menu_bar_should_be_hidden
(void
)
555 return !NILP
(ns_auto_hide_menu_bar
)
556 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)];
560 /* Show or hide the menu bar, based on user setting. */
563 ns_update_auto_hide_menu_bar
(void
)
565 #ifndef MAC_OS_X_VERSION_10_6
566 #define MAC_OS_X_VERSION_10_6
1060
569 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
572 NSTRACE
(ns_update_auto_hide_menu_bar
);
576 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)])
578 // Note
, "setPresentationOptions" triggers an
error unless the
579 // application is active.
580 BOOL menu_bar_should_be_hidden
= ns_menu_bar_should_be_hidden
();
582 if (menu_bar_should_be_hidden
!= ns_menu_bar_is_hidden
)
584 NSApplicationPresentationOptions options
585 = NSApplicationPresentationAutoHideDock
;
587 if (menu_bar_should_be_hidden
)
588 options |
= NSApplicationPresentationAutoHideMenuBar
;
590 [NSApp setPresentationOptions
: options
];
592 ns_menu_bar_is_hidden
= menu_bar_should_be_hidden
;
594 if (!ns_menu_bar_is_hidden
)
596 ns_constrain_all_frames
();
608 ns_update_begin
(struct frame
*f
)
609 /* --------------------------------------------------------------------------
610 Prepare for a grouped sequence of drawing calls
611 external (RIF) call; whole frame, called before update_window_begin
612 -------------------------------------------------------------------------- */
614 NSView
*view = FRAME_NS_VIEW
(f
);
615 NSTRACE
(ns_update_begin
);
617 ns_update_auto_hide_menu_bar
();
619 ns_updating_frame
= f
;
622 #ifdef NS_IMPL_GNUSTEP
623 uRect
= NSMakeRect
(0, 0, 0, 0);
629 ns_update_window_begin
(struct window
*w
)
630 /* --------------------------------------------------------------------------
631 Prepare for a grouped sequence of drawing calls
632 external (RIF) call; for one window, called after update_begin
633 -------------------------------------------------------------------------- */
635 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
636 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
637 NSTRACE
(ns_update_window_begin
);
640 set_output_cursor
(&w
->cursor
);
644 if (f
== hlinfo
->mouse_face_mouse_frame
)
646 /* Don't do highlighting for mouse motion during the update. */
647 hlinfo
->mouse_face_defer
= 1;
649 /* If the frame needs to be redrawn,
650 simply forget about any prior mouse highlighting. */
651 if (FRAME_GARBAGED_P
(f
))
652 hlinfo
->mouse_face_window
= Qnil
;
654 /* (further code for mouse faces ifdef'd out in other terms elided) */
662 ns_update_window_end
(struct window
*w
, int cursor_on_p
,
663 int mouse_face_overwritten_p
)
664 /* --------------------------------------------------------------------------
665 Finished a grouped sequence of drawing calls
666 external (RIF) call; for one window called before update_end
667 -------------------------------------------------------------------------- */
669 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(XFRAME
(w
->frame
));
671 /* note: this fn is nearly identical in all terms */
672 if (!w
->pseudo_window_p
)
677 display_and_set_cursor
(w
, 1,
678 output_cursor.hpos
, output_cursor.vpos
,
679 output_cursor.x
, output_cursor.y
);
681 if (draw_window_fringes
(w
, 1))
682 x_draw_vertical_border
(w
);
687 /* If a row with mouse-face was overwritten, arrange for
688 frame_up_to_date to redisplay the mouse highlight. */
689 if (mouse_face_overwritten_p
)
691 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
692 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
693 hlinfo
->mouse_face_window
= Qnil
;
696 updated_window
= NULL;
697 NSTRACE
(update_window_end
);
702 ns_update_end
(struct frame
*f
)
703 /* --------------------------------------------------------------------------
704 Finished a grouped sequence of drawing calls
705 external (RIF) call; for whole frame, called after update_window_end
706 -------------------------------------------------------------------------- */
708 NSView
*view = FRAME_NS_VIEW
(f
);
710 /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
711 MOUSE_HL_INFO
(f
)->mouse_face_defer
= 0;
715 #ifdef NS_IMPL_GNUSTEP
716 /* trigger flush only in the rectangle we tracked as being drawn */
717 [view unlockFocusNeedsFlush
: NO
];
718 /*fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", uRect.origin.x, uRect.origin.y, uRect.size.width, uRect.size.height); */
719 [view lockFocusInRect
: uRect
];
723 [[view window
] flushWindow
];
726 ns_updating_frame
= NULL;
727 NSTRACE
(ns_update_end
);
732 ns_flush
(struct frame
*f
)
733 /* --------------------------------------------------------------------------
735 NS impl is no-op since currently we flush in ns_update_end and elsewhere
736 -------------------------------------------------------------------------- */
743 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
744 /* --------------------------------------------------------------------------
745 Internal: Focus on given frame. During small local updates this is used to
746 draw, however during large updates, ns_update_begin and ns_update_end are
747 called to wrap the whole thing, in which case these calls are stubbed out.
748 Except, on GNUstep, we accumulate the rectangle being drawn into, because
749 the back end won't do this automatically, and will just end up flushing
751 -------------------------------------------------------------------------- */
753 // NSTRACE
(ns_focus
);
754 #ifdef NS_IMPL_GNUSTEP
757 u
= NSUnionRect
(r
[0], r
[1]);
762 fprintf (stderr, "focus: %d", c++);
763 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
764 fprintf (stderr, "\n"); */
766 if (f
!= ns_updating_frame
)
768 NSView
*view = FRAME_NS_VIEW
(f
);
769 if (view != focus_view
)
771 if (focus_view
!= NULL)
773 [focus_view unlockFocus
];
774 [[focus_view window
] flushWindow
];
779 #ifdef NS_IMPL_GNUSTEP
780 r ?
[view lockFocusInRect
: u
] : [view lockFocus
];
785 /*if (view) debug_lock++; */
787 #ifdef NS_IMPL_GNUSTEP
790 /* more than one rect being drawn into */
793 [view unlockFocus
]; /* add prev rect to redraw list */
794 [view lockFocusInRect
: u
]; /* focus for draw in new rect */
799 #ifdef NS_IMPL_GNUSTEP
802 /* in batch mode, but in GNUstep must still track rectangles explicitly */
803 uRect
= (r ? NSUnionRect
(uRect
, u
) : [FRAME_NS_VIEW
(f
) visibleRect
]);
810 [[NSGraphicsContext currentContext
] saveGraphicsState
];
812 NSRectClipList
(r
, 2);
821 ns_unfocus
(struct frame
*f
)
822 /* --------------------------------------------------------------------------
823 Internal: Remove focus on given frame
824 -------------------------------------------------------------------------- */
826 // NSTRACE
(ns_unfocus
);
830 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
834 if (f
!= ns_updating_frame
)
836 if (focus_view
!= NULL)
838 [focus_view unlockFocus
];
839 [[focus_view window
] flushWindow
];
848 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
, int area
, BOOL gc
)
849 /* --------------------------------------------------------------------------
850 Internal (but parallels other terms): Focus drawing on given row
851 -------------------------------------------------------------------------- */
853 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
855 int window_x
, window_y
, window_width
;
857 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
859 clip_rect.origin.x
= window_x
- FRAME_INTERNAL_BORDER_WIDTH
(f
);
860 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
861 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
862 clip_rect.
size.width
= window_width
+ 2 * FRAME_INTERNAL_BORDER_WIDTH
(f
);
863 clip_rect.
size.height
= row
->visible_height
;
865 /* allow a full-height row at the top when requested
866 (used to draw fringe all the way through internal border area) */
867 if (gc
&& clip_rect.origin.y
< 5)
869 clip_rect.origin.y
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
870 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
873 /* likewise at bottom */
875 FRAME_PIXEL_HEIGHT
(f
) - (clip_rect.origin.y
+ clip_rect.
size.height
) < 5)
876 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
878 ns_focus
(f
, &clip_rect
, 1);
883 ns_ring_bell
(struct frame
*f
)
884 /* --------------------------------------------------------------------------
886 -------------------------------------------------------------------------- */
888 NSTRACE
(ns_ring_bell
);
891 NSAutoreleasePool
*pool
;
892 struct frame
*frame
= SELECTED_FRAME
();
896 pool
= [[NSAutoreleasePool alloc
] init
];
898 view = FRAME_NS_VIEW
(frame
);
902 NSPoint dim
= NSMakePoint
(128, 128);
905 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
906 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
907 r.
size.width
= dim.x
;
908 r.
size.height
= dim.y
;
909 surr
= NSInsetRect
(r
, -2, -2);
910 ns_focus
(frame
, &surr
, 1);
911 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
912 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
913 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
915 [[view window
] flushWindow
];
917 [[view window
] restoreCachedImage
];
918 [[view window
] flushWindow
];
932 ns_reset_terminal_modes
(struct terminal *terminal)
933 /* Externally called as hook */
935 NSTRACE
(ns_reset_terminal_modes
);
940 ns_set_terminal_modes
(struct terminal *terminal)
941 /* Externally called as hook */
943 NSTRACE
(ns_set_terminal_modes
);
948 /* ==========================================================================
950 Frame / window manager related functions
952 ========================================================================== */
956 ns_raise_frame
(struct frame
*f
)
957 /* --------------------------------------------------------------------------
958 Bring window to foreground and make it active
959 -------------------------------------------------------------------------- */
961 NSView
*view = FRAME_NS_VIEW
(f
);
964 FRAME_SAMPLE_VISIBILITY
(f
);
965 if (FRAME_VISIBLE_P
(f
))
967 [[view window
] makeKeyAndOrderFront
: NSApp
];
974 ns_lower_frame
(struct frame
*f
)
975 /* --------------------------------------------------------------------------
977 -------------------------------------------------------------------------- */
979 NSView
*view = FRAME_NS_VIEW
(f
);
982 [[view window
] orderBack
: NSApp
];
988 ns_frame_raise_lower
(struct frame
*f
, int raise
)
989 /* --------------------------------------------------------------------------
991 -------------------------------------------------------------------------- */
993 NSTRACE
(ns_frame_raise_lower
);
1003 ns_frame_rehighlight
(struct frame
*frame
)
1004 /* --------------------------------------------------------------------------
1005 External (hook): called on things like window switching within frame
1006 -------------------------------------------------------------------------- */
1008 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(frame
);
1009 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1011 NSTRACE
(ns_frame_rehighlight
);
1012 if (dpyinfo
->x_focus_frame
)
1014 dpyinfo
->x_highlight_frame
1015 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1016 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1017 : dpyinfo
->x_focus_frame
);
1018 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
1020 FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
) = Qnil
;
1021 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1025 dpyinfo
->x_highlight_frame
= 0;
1027 if (dpyinfo
->x_highlight_frame
&&
1028 dpyinfo
->x_highlight_frame
!= old_highlight
)
1032 x_update_cursor
(old_highlight
, 1);
1033 x_set_frame_alpha
(old_highlight
);
1035 if (dpyinfo
->x_highlight_frame
)
1037 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
1038 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
1045 x_make_frame_visible
(struct frame
*f
)
1046 /* --------------------------------------------------------------------------
1047 External: Show the window (X11 semantics)
1048 -------------------------------------------------------------------------- */
1050 NSTRACE
(x_make_frame_visible
);
1051 /* XXX: at some points in past this was not needed, as the only place that
1052 called this (frame.c:Fraise_frame ()) also called raise_lower;
1053 if this ends up the case again, comment this out again. */
1054 if (!FRAME_VISIBLE_P
(f
))
1056 f
->async_visible
= 1;
1063 x_make_frame_invisible
(struct frame
*f
)
1064 /* --------------------------------------------------------------------------
1065 External: Hide the window (X11 semantics)
1066 -------------------------------------------------------------------------- */
1068 NSView
* view = FRAME_NS_VIEW
(f
);
1069 NSTRACE
(x_make_frame_invisible
);
1071 [[view window
] orderOut
: NSApp
];
1072 f
->async_visible
= 0;
1073 f
->async_iconified
= 0;
1078 x_iconify_frame
(struct frame
*f
)
1079 /* --------------------------------------------------------------------------
1080 External: Iconify window
1081 -------------------------------------------------------------------------- */
1083 NSView
* view = FRAME_NS_VIEW
(f
);
1084 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1085 NSTRACE
(x_iconify_frame
);
1088 if (dpyinfo
->x_highlight_frame
== f
)
1089 dpyinfo
->x_highlight_frame
= 0;
1091 if ([[view window
] windowNumber
] <= 0)
1093 /* the window is still deferred. Make it very small, bring it
1094 on screen and order it out. */
1095 NSRect s
= { { 100, 100}, {0, 0} };
1097 t
= [[view window
] frame
];
1098 [[view window
] setFrame
: s display
: NO
];
1099 [[view window
] orderBack
: NSApp
];
1100 [[view window
] orderOut
: NSApp
];
1101 [[view window
] setFrame
: t display
: NO
];
1103 [[view window
] miniaturize
: NSApp
];
1106 /* Free X resources of frame F. */
1109 x_free_frame_resources
(struct frame
*f
)
1111 NSView
*view = FRAME_NS_VIEW
(f
);
1112 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1113 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1114 NSTRACE
(x_destroy_window
);
1117 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1121 free_frame_menubar
(f
);
1123 if (FRAME_FACE_CACHE
(f
))
1124 free_frame_faces
(f
);
1126 if (f
== dpyinfo
->x_focus_frame
)
1127 dpyinfo
->x_focus_frame
= 0;
1128 if (f
== dpyinfo
->x_highlight_frame
)
1129 dpyinfo
->x_highlight_frame
= 0;
1130 if (f
== hlinfo
->mouse_face_mouse_frame
)
1132 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1133 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1134 hlinfo
->mouse_face_window
= Qnil
;
1135 hlinfo
->mouse_face_deferred_gc
= 0;
1136 hlinfo
->mouse_face_mouse_frame
= 0;
1139 if (f
->output_data.ns
->miniimage
!= nil
)
1140 [f
->output_data.ns
->miniimage release
];
1142 [[view window
] close];
1145 xfree
(f
->output_data.ns
);
1151 x_destroy_window
(struct frame
*f
)
1152 /* --------------------------------------------------------------------------
1153 External: Delete the window
1154 -------------------------------------------------------------------------- */
1156 NSTRACE
(x_destroy_window
);
1158 x_free_frame_resources
(f
);
1164 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1165 /* --------------------------------------------------------------------------
1166 External: Position the window
1167 -------------------------------------------------------------------------- */
1169 NSView
*view = FRAME_NS_VIEW
(f
);
1170 NSArray
*screens
= [NSScreen screens
];
1171 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1172 NSScreen
*screen
= [[view window
] screen
];
1174 NSTRACE
(x_set_offset
);
1181 if (view != nil
&& screen
&& fscreen
)
1183 f
->left_pos
= f
->size_hint_flags
& XNegative
1184 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1186 /* We use visibleFrame here to take menu bar into account.
1187 Ideally we should also adjust left/top with visibleFrame.origin. */
1189 f
->top_pos
= f
->size_hint_flags
& YNegative
1190 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1191 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1192 - FRAME_TOOLBAR_HEIGHT
(f
))
1194 #ifdef NS_IMPL_GNUSTEP
1195 if (f
->left_pos
< 100)
1196 f
->left_pos
= 100; /* don't overlap menu */
1198 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1200 f
->output_data.ns
->dont_constrain
= 0;
1201 [[view window
] setFrameTopLeftPoint
:
1202 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1203 SCREENMAXBOUND
([fscreen frame
].
size.height
1204 - NS_TOP_POS
(f
)))];
1205 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1213 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1214 /* --------------------------------------------------------------------------
1215 Adjust window pixel size based on given character grid size
1216 Impl is a bit more complex than other terms, need to do some
1218 -------------------------------------------------------------------------- */
1220 EmacsView
*view = FRAME_NS_VIEW
(f
);
1221 EmacsToolbar
*toolbar
= [view toolbar
];
1222 NSWindow
*window
= [view window
];
1223 NSRect wr
= [window frame
];
1224 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1225 int pixelwidth
, pixelheight
;
1226 static int oldRows
, oldCols
, oldFontWidth
, oldFontHeight
;
1228 static
struct frame
*oldF
;
1230 NSTRACE
(x_set_window_size
);
1234 && rows
== oldRows
&& cols
== oldCols
1235 && oldFontWidth
== FRAME_COLUMN_WIDTH
(f
)
1236 && oldFontHeight
== FRAME_LINE_HEIGHT
(f
)
1240 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1244 check_frame_size
(f
, &rows
, &cols
);
1248 oldFontWidth
= FRAME_COLUMN_WIDTH
(f
);
1249 oldFontHeight
= FRAME_LINE_HEIGHT
(f
);
1252 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1253 compute_fringe_widths
(f
, 0);
1255 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1256 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1258 /* If we have a toolbar, take its height into account. */
1260 /* NOTE: previously this would generate wrong result if toolbar not
1261 yet displayed and fixing toolbar_height=32 helped, but
1262 now (200903) seems no longer needed */
1263 FRAME_TOOLBAR_HEIGHT
(f
) =
1264 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1265 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1267 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1269 wr.
size.width
= pixelwidth
+ f
->border_width
;
1270 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1271 + FRAME_TOOLBAR_HEIGHT
(f
);
1273 /* Do not try to constrain to this screen. We may have multiple
1274 screens, and want Emacs to span those. Constraining to screen
1275 prevents that, and that is not nice to the user. */
1276 if (f
->output_data.ns
->zooming
)
1277 f
->output_data.ns
->zooming
= 0;
1279 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1281 [view setRows
: rows andColumns
: cols
];
1282 [window setFrame
: wr display
: YES
];
1284 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1286 /* This is a trick to compensate for Emacs' managing the scrollbar area
1287 as a fixed number of standard character columns. Instead of leaving
1288 blank space for the extra, we chopped it off above. Now for
1289 left-hand scrollbars, we shift all rendering to the left by the
1290 difference between the real width and Emacs' imagined one. For
1291 right-hand bars, don't worry about it since the extra is never used.
1292 (Obviously doesn't work for vertically split windows tho..) */
1294 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1295 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1296 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1297 : NSMakePoint
(0, 0);
1298 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1299 [view setBoundsOrigin
: origin
];
1302 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1303 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1304 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1305 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1307 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1308 cancel_mouse_face
(f
);
1315 /* ==========================================================================
1319 ========================================================================== */
1323 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1325 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1326 if (idx
< 1 || idx
>= color_table
->avail
)
1328 return color_table
->colors
[idx
];
1333 ns_index_color
(NSColor
*color
, struct frame
*f
)
1335 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1339 if (!color_table
->colors
)
1341 color_table
->size = NS_COLOR_CAPACITY
;
1342 color_table
->avail
= 1; /* skip idx=0 as marker */
1343 color_table
->colors
= xmalloc
(color_table
->size * sizeof
(NSColor
*));
1344 color_table
->colors
[0] = nil
;
1345 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1348 /* do we already have this color ? */
1349 for (i
= 1; i
< color_table
->avail
; i
++)
1350 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1353 if ([color_table
->empty_indices count
] > 0)
1355 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1356 [color_table
->empty_indices removeObject
: index
];
1357 idx
= [index unsignedLongValue
];
1361 if (color_table
->avail
== color_table
->size)
1362 color_table
->colors
=
1363 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1364 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1365 idx
= color_table
->avail
++;
1368 color_table
->colors
[idx
] = color
;
1370 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1376 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1378 struct ns_color_table
*color_table
;
1385 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1387 if (idx
<= 0 || idx
>= color_table
->size) {
1388 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1392 index
= [NSNumber numberWithUnsignedInt
: idx
];
1393 if ([color_table
->empty_indices containsObject
: index
]) {
1394 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1398 color
= color_table
->colors
[idx
];
1400 color_table
->colors
[idx
] = nil
;
1401 [color_table
->empty_indices addObject
: index
];
1402 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1407 ns_get_color
(const
char *name
, NSColor
**col
)
1408 /* --------------------------------------------------------------------------
1410 -------------------------------------------------------------------------- */
1411 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1412 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1413 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1416 static
char hex
[20];
1418 float r
= -1.0, g
, b
;
1419 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1421 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1424 if ([nsname isEqualToString
: @"ns_selection_color"
])
1426 nsname
= ns_selection_color
;
1427 name
= [ns_selection_color UTF8String
];
1430 /* First, check for some sort of numeric specification. */
1433 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1435 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1436 [scanner scanFloat
: &r
];
1437 [scanner scanFloat
: &g
];
1438 [scanner scanFloat
: &b
];
1440 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1441 scaling
= (snprintf
(hex
, sizeof hex
, "
%s", name + 4) - 2) / 3;
1442 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1444 int len
= (strlen
(name
) - 1);
1445 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1447 scaling
= strlen
(name
+start
) / 3;
1448 for (i
= 0; i
< 3; i
++)
1449 sprintf (hex
+ i
* (scaling
+ 1), "
%.*s/", scaling,
1450 name
+ start
+ i
* scaling
);
1451 hex
[3 * (scaling
+ 1) - 1] = '\0';
1457 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1458 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1468 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1473 /* Otherwise, color is expected to be from a list */
1475 NSEnumerator
*lenum
, *cenum
;
1479 #ifdef NS_IMPL_GNUSTEP
1480 /* XXX: who is wrong, the requestor or the implementation? */
1481 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1483 nsname
= @"highlightColor"
;
1486 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1487 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1489 cenum
= [[clist allKeys
] objectEnumerator
];
1490 while ( (name
= [cenum nextObject
]) && new
== nil
)
1492 if ([name compare
: nsname
1493 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1494 new
= [clist colorWithKey
: name
];
1500 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1507 ns_get_color_default
(const
char *name
, NSColor
*dflt
)
1508 /* --------------------------------------------------------------------------
1509 Parse a color or use a default value
1510 -------------------------------------------------------------------------- */
1514 if (ns_get_color
(name
, &col
))
1522 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1523 /* --------------------------------------------------------------------------
1524 Convert a Lisp string object to a NS color
1525 -------------------------------------------------------------------------- */
1527 NSTRACE
(ns_lisp_to_color
);
1528 if (STRINGP
(color
))
1529 return ns_get_color
(SDATA
(color
), col
);
1530 else if (SYMBOLP
(color
))
1531 return ns_get_color
(SDATA
(SYMBOL_NAME
(color
)), col
);
1537 ns_color_to_lisp
(NSColor
*col
)
1538 /* --------------------------------------------------------------------------
1539 Convert a color to a lisp string with the RGB equivalent
1540 -------------------------------------------------------------------------- */
1542 CGFloat red
, green
, blue
, alpha
, gray;
1545 NSTRACE
(ns_color_to_lisp
);
1548 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1550 if ((str
=[[col colorNameComponent
] UTF8String
]))
1553 return build_string
((char *)str
);
1556 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1557 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1558 if (red
==green
&& red
==blue
)
1560 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1561 getWhite
: &gray alpha
: &alpha
];
1562 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1563 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1565 return build_string
(buf
);
1568 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1569 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1572 return build_string
(buf
);
1577 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1578 /* --------------------------------------------------------------------------
1579 Get ARGB values out of NSColor col and put them into color_def.
1580 If setPixel, set the pixel to a concatenated version.
1581 and set color_def pixel to the resulting index.
1582 -------------------------------------------------------------------------- */
1586 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1587 color_def
->red
= r
* 65535;
1588 color_def
->green
= g
* 65535;
1589 color_def
->blue
= b
* 65535;
1591 if (setPixel
== YES
)
1593 = ARGB_TO_ULONG
((int
)(a
*255),
1594 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1599 ns_defined_color
(struct frame
*f
,
1604 /* --------------------------------------------------------------------------
1605 Return 1 if named color found, and set color_def rgb accordingly.
1606 If makeIndex and alloc are nonzero put the color in the color_table,
1607 and set color_def pixel to the resulting index.
1608 If makeIndex is zero, set color_def pixel to ARGB.
1609 Return 0 if not found
1610 -------------------------------------------------------------------------- */
1613 NSTRACE
(ns_defined_color
);
1616 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1621 if (makeIndex
&& alloc
)
1622 color_def
->pixel
= ns_index_color
(col
, f
);
1623 ns_query_color
(col
, color_def
, !makeIndex
);
1630 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1631 /* --------------------------------------------------------------------------
1632 return an autoreleased RGB color
1633 -------------------------------------------------------------------------- */
1635 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1636 if (r
< 0.0) r
= 0.0;
1637 else if (r
> 1.0) r
= 1.0;
1638 if (g
< 0.0) g
= 0.0;
1639 else if (g
> 1.0) g
= 1.0;
1640 if (b
< 0.0) b
= 0.0;
1641 else if (b
> 1.0) b
= 1.0;
1642 if (a
< 0.0) a
= 0.0;
1643 else if (a
> 1.0) a
= 1.0;
1644 return (unsigned
long) ns_index_color
(
1645 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1650 x_set_frame_alpha
(struct frame
*f
)
1651 /* --------------------------------------------------------------------------
1652 change the entire-frame transparency
1653 -------------------------------------------------------------------------- */
1655 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1656 EmacsView
*view = FRAME_NS_VIEW
(f
);
1658 double alpha_min
= 1.0;
1660 if (dpyinfo
->x_highlight_frame
== f
)
1661 alpha
= f
->alpha
[0];
1663 alpha
= f
->alpha
[1];
1665 if (FLOATP
(Vframe_alpha_lower_limit
))
1666 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1667 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1668 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1672 else if (1.0 < alpha
)
1674 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1677 #ifdef NS_IMPL_COCOA
1678 [[view window
] setAlphaValue
: alpha
];
1683 /* ==========================================================================
1687 ========================================================================== */
1691 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1692 /* --------------------------------------------------------------------------
1693 Programmatically reposition mouse pointer in pixel coordinates
1694 -------------------------------------------------------------------------- */
1696 NSTRACE
(x_set_mouse_pixel_position
);
1699 /* FIXME: this does not work, and what about GNUstep? */
1700 #ifdef NS_IMPL_COCOA
1701 [FRAME_NS_VIEW
(f
) lockFocus
];
1702 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1703 [FRAME_NS_VIEW
(f
) unlockFocus
];
1710 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1711 /* --------------------------------------------------------------------------
1712 Programmatically reposition mouse pointer in character coordinates
1713 -------------------------------------------------------------------------- */
1717 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1718 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1720 if (pix_x
< 0) pix_x
= 0;
1721 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1723 if (pix_y
< 0) pix_y
= 0;
1724 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1726 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1731 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1732 /* ------------------------------------------------------------------------
1733 Called by EmacsView on mouseMovement events. Passes on
1734 to emacs mainstream code if we moved off of a rect of interest
1735 known as last_mouse_glyph.
1736 ------------------------------------------------------------------------ */
1738 // NSTRACE
(note_mouse_movement
);
1740 XSETFRAME
(last_mouse_motion_frame
, frame
);
1742 /* Note, this doesn't get called for enter/leave, since we don't have a
1743 position. Those are taken care of in the corresponding NSView methods. */
1745 /* has movement gone beyond last rect we were tracking? */
1746 if (x
< last_mouse_glyph.origin.x ||
1747 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1748 y
< last_mouse_glyph.origin.y ||
1749 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1751 ns_update_begin
(frame
);
1752 frame
->mouse_moved
= 1;
1753 note_mouse_highlight
(frame
, x
, y
);
1754 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1755 ns_update_end
(frame
);
1764 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1765 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1767 /* --------------------------------------------------------------------------
1768 External (hook): inform emacs about mouse position and hit parts.
1769 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1770 x & y should be position in the scrollbar (the whole bar, not the handle)
1771 and length of scrollbar respectively
1772 -------------------------------------------------------------------------- */
1777 Lisp_Object frame
, tail
;
1779 struct ns_display_info
*dpyinfo
;
1781 NSTRACE
(ns_mouse_position
);
1785 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1789 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1793 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1795 /* TODO: we do not use this path at the moment because drag events will
1796 go directly to the EmacsScroller. Leaving code in for now. */
1797 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1799 if (time
) *time
= last_mouse_movement_time
;
1800 last_mouse_scroll_bar
= nil
;
1804 /* Clear the mouse-moved flag for every frame on this display. */
1805 FOR_EACH_FRAME
(tail
, frame
)
1806 if (FRAME_NS_P
(XFRAME
(frame
))
1807 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1808 XFRAME
(frame
)->mouse_moved
= 0;
1810 last_mouse_scroll_bar
= nil
;
1811 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1812 f
= last_mouse_frame
;
1814 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1815 : SELECTED_FRAME
();
1817 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1819 view = FRAME_NS_VIEW
(*fp
);
1821 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1822 position
= [view convertPoint
: position fromView
: nil
];
1823 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1824 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1826 if (bar_window
) *bar_window
= Qnil
;
1827 if (part
) *part
= 0; /*scroll_bar_handle; */
1829 if (x
) XSETINT
(*x
, lrint
(position.x
));
1830 if (y
) XSETINT
(*y
, lrint
(position.y
));
1831 if (time
) *time
= last_mouse_movement_time
;
1841 ns_frame_up_to_date
(struct frame
*f
)
1842 /* --------------------------------------------------------------------------
1843 External (hook): Fix up mouse highlighting right after a full update.
1844 Some highlighting was deferred if GC was happening during
1845 note_mouse_highlight (), while other highlighting was deferred for update.
1846 -------------------------------------------------------------------------- */
1848 NSTRACE
(ns_frame_up_to_date
);
1852 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1853 if ((hlinfo
->mouse_face_deferred_gc || f
==hlinfo
->mouse_face_mouse_frame
)
1854 /*&& hlinfo->mouse_face_mouse_frame*/)
1858 if (hlinfo
->mouse_face_mouse_frame
)
1859 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1860 hlinfo
->mouse_face_mouse_x
,
1861 hlinfo
->mouse_face_mouse_y
);
1862 hlinfo
->mouse_face_deferred_gc
= 0;
1871 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1872 /* --------------------------------------------------------------------------
1873 External (RIF): set frame mouse pointer type.
1874 -------------------------------------------------------------------------- */
1876 NSTRACE
(ns_define_frame_cursor
);
1877 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1879 EmacsView
*view = FRAME_NS_VIEW
(f
);
1880 FRAME_POINTER_TYPE
(f
) = cursor
;
1881 [[view window
] invalidateCursorRectsForView
: view];
1882 /* Redisplay assumes this function also draws the changed frame
1883 cursor, but this function doesn't, so do it explicitly. */
1884 x_update_cursor
(f
, 1);
1890 /* ==========================================================================
1894 ========================================================================== */
1898 ns_convert_key
(unsigned code
)
1899 /* --------------------------------------------------------------------------
1900 Internal call used by NSView-keyDown.
1901 -------------------------------------------------------------------------- */
1903 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1904 / sizeof
(convert_ns_to_X_keysym
[0]));
1906 /* An array would be faster, but less easy to read. */
1907 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1908 if (code
== convert_ns_to_X_keysym
[keysym
])
1909 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1911 /* if decide to use keyCode and Carbon table, use this line:
1912 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1917 x_get_keysym_name
(int keysym
)
1918 /* --------------------------------------------------------------------------
1919 Called by keyboard.c. Not sure if the return val is important, except
1921 -------------------------------------------------------------------------- */
1923 static
char value
[16];
1924 NSTRACE
(x_get_keysym_name
);
1925 sprintf (value
, "
%d", keysym);
1931 /* ==========================================================================
1933 Block drawing operations
1935 ========================================================================== */
1939 ns_redraw_scroll_bars
(struct frame
*f
)
1943 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1944 NSTRACE
(ns_judge_scroll_bars
);
1945 for (i
=[subviews count
]-1; i
>= 0; i
--)
1947 view = [subviews objectAtIndex
: i
];
1948 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
1955 ns_clear_frame
(struct frame
*f
)
1956 /* --------------------------------------------------------------------------
1957 External (hook): Erase the entire frame
1958 -------------------------------------------------------------------------- */
1960 NSView
*view = FRAME_NS_VIEW
(f
);
1963 NSTRACE
(ns_clear_frame
);
1967 /* comes on initial frame because we have
1968 after-make-frame-functions = select-frame */
1969 if (!FRAME_DEFAULT_FACE
(f
))
1972 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
1974 output_cursor.hpos
= output_cursor.vpos
= 0;
1975 output_cursor.x
= -1;
1980 ns_focus
(f
, &r
, 1);
1981 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
1985 #ifdef NS_IMPL_COCOA
1986 [[view window
] display
]; /* redraw resize handle */
1989 /* as of 2006/11 or so this is now needed */
1990 ns_redraw_scroll_bars
(f
);
1996 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
1997 /* --------------------------------------------------------------------------
1998 External (RIF): Clear section of frame
1999 -------------------------------------------------------------------------- */
2001 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
2002 NSView
*view = FRAME_NS_VIEW
(f
);
2003 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
2008 NSTRACE
(ns_clear_frame_area
);
2010 r
= NSIntersectionRect
(r
, [view frame
]);
2011 ns_focus
(f
, &r
, 1);
2012 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
2014 #ifdef NS_IMPL_COCOA
2016 /* clip out the resize handle */
2017 NSWindow
*window
= [FRAME_NS_VIEW
(f
) window
];
2019 = [view convertRect
: ns_resize_handle_rect
(window
) fromView
: nil
];
2021 ir
= NSIntersectionRect
(r
, ir
);
2022 if (NSIsEmptyRect
(ir
))
2028 #ifdef NS_IMPL_COCOA
2032 NSRect r1
= r
, r2
= r
; /* upper and lower non-intersecting */
2033 r1.
size.height
-= ir.
size.height
;
2034 r2.origin.y
+= r1.
size.height
;
2035 r2.
size.width
-= ir.
size.width
;
2036 r2.
size.height
= ir.
size.height
;
2049 ns_scroll_run
(struct window
*w
, struct run
*run
)
2050 /* --------------------------------------------------------------------------
2051 External (RIF): Insert or delete n lines at line vpos
2052 -------------------------------------------------------------------------- */
2054 struct frame
*f
= XFRAME
(w
->frame
);
2055 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2057 NSTRACE
(ns_scroll_run
);
2059 /* begin copy from other terms */
2060 /* Get frame-relative bounding box of the text display area of W,
2061 without mode lines. Include in this box the left and right
2063 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2065 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2066 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2067 bottom_y
= y
+ height
;
2071 /* Scrolling up. Make sure we don't copy part of the mode
2072 line at the bottom. */
2073 if (from_y
+ run
->height
> bottom_y
)
2074 height
= bottom_y
- from_y
;
2076 height
= run
->height
;
2080 /* Scrolling down. Make sure we don't copy over the mode line.
2082 if (to_y
+ run
->height
> bottom_y
)
2083 height
= bottom_y
- to_y
;
2085 height
= run
->height
;
2087 /* end copy from other terms */
2098 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2099 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2100 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2102 ns_focus
(f
, &dstRect
, 1);
2103 NSCopyBits
(0, srcRect
, dstOrigin
);
2112 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2113 /* --------------------------------------------------------------------------
2114 External (RIF): preparatory to fringe update after text was updated
2115 -------------------------------------------------------------------------- */
2117 struct window
*w
= updated_window
;
2121 NSTRACE
(ns_after_update_window_line
);
2123 /* begin copy from other terms */
2126 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2127 desired_row
->redraw_fringe_bitmaps_p
= 1;
2129 /* When a window has disappeared, make sure that no rest of
2130 full-width rows stays visible in the internal border.
2131 Under NS this is drawn inside the fringes. */
2132 if (windows_or_buffers_changed
2133 && (f
= XFRAME
(w
->frame
),
2134 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2136 && (height
= desired_row
->visible_height
,
2139 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2141 /* Internal border is drawn below the tool bar. */
2142 if (WINDOWP
(f
->tool_bar_window
)
2143 && w
== XWINDOW
(f
->tool_bar_window
))
2145 /* end copy from other terms */
2148 if (!desired_row
->full_width_p
)
2150 int x1
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2151 + WINDOW_LEFT_FRINGE_WIDTH
(w
);
2152 int x2
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2153 + FRAME_PIXEL_WIDTH
(f
) - NS_SCROLL_BAR_WIDTH
(f
)
2154 - WINDOW_RIGHT_FRINGE_WIDTH
(w
)
2155 - FRAME_INTERNAL_BORDER_WIDTH
(f
);
2156 ns_clear_frame_area
(f
, x1
, y
, width
, height
);
2157 ns_clear_frame_area
(f
, x2
, y
, width
, height
);
2165 ns_shift_glyphs_for_insert
(struct frame
*f
,
2166 int x
, int y
, int width
, int height
,
2168 /* --------------------------------------------------------------------------
2169 External (RIF): copy an area horizontally, don't worry about clearing src
2170 -------------------------------------------------------------------------- */
2172 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2173 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2174 NSPoint dstOrigin
= dstRect.origin
;
2176 NSTRACE
(ns_shift_glyphs_for_insert
);
2178 ns_focus
(f
, &dstRect
, 1);
2179 NSCopyBits
(0, srcRect
, dstOrigin
);
2185 /* ==========================================================================
2187 Character encoding and metrics
2189 ========================================================================== */
2193 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2194 /* --------------------------------------------------------------------------
2195 External (RIF); compute left/right overhang of whole string and set in s
2196 -------------------------------------------------------------------------- */
2198 struct face
*face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2199 struct font
*font
= s
->font
; /*face->font; */
2203 struct font_metrics metrics
;
2204 unsigned int codes
[2];
2205 codes
[0] = *(s
->char2b
);
2206 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2208 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2209 s
->left_overhang
= -metrics.lbearing
;
2211 = metrics.rbearing
> metrics.width
2212 ? metrics.rbearing
- metrics.width
: 0;
2216 s
->left_overhang
= 0;
2217 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2218 FONT_HEIGHT
(font
) * 0.2 : 0;
2224 /* ==========================================================================
2226 Fringe and cursor drawing
2228 ========================================================================== */
2231 extern int max_used_fringe_bitmap
;
2233 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2234 struct draw_fringe_bitmap_params
*p
)
2235 /* --------------------------------------------------------------------------
2236 External (RIF); fringe-related
2237 -------------------------------------------------------------------------- */
2239 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2240 struct face
*face
= p
->face
;
2242 static EmacsImage
**bimgs
= NULL;
2243 static int nBimgs
= 0;
2244 /* NS-specific: move internal border inside fringe */
2245 int x
= p
->bx
< 0 ? p
->x
: p
->bx
;
2246 int wd
= p
->bx
< 0 ? p
->wd
: p
->nx
;
2247 BOOL fringeOnVeryLeft
2248 = x
- WINDOW_LEFT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
)
2249 - FRAME_INTERNAL_BORDER_WIDTH
(f
) < 10;
2250 BOOL fringeOnVeryRight
2251 = FRAME_PIXEL_WIDTH
(f
) - x
- wd
- FRAME_INTERNAL_BORDER_WIDTH
(f
)
2252 - WINDOW_RIGHT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
) < 10;
2253 int xAdjust
= FRAME_INTERNAL_BORDER_WIDTH
(f
) *
2254 (fringeOnVeryLeft ?
-1 : (fringeOnVeryRight ?
1 : 0));
2256 /* grow bimgs if needed */
2257 if (nBimgs
< max_used_fringe_bitmap
)
2259 bimgs
= xrealloc
(bimgs
, max_used_fringe_bitmap
* sizeof
*bimgs
);
2260 memset
(bimgs
+ nBimgs
, 0,
2261 (max_used_fringe_bitmap
- nBimgs
) * sizeof
*bimgs
);
2262 nBimgs
= max_used_fringe_bitmap
;
2265 /* Must clip because of partially visible lines. */
2266 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2267 ns_clip_to_row
(w
, row
, -1, YES
);
2269 if (p
->bx
>= 0 && !p
->overlay_p
)
2271 int yAdjust
= rowY
- FRAME_INTERNAL_BORDER_WIDTH
(f
) < 5 ?
2272 -FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0;
2273 int yIncr
= FRAME_PIXEL_HEIGHT
(f
) - (p
->by
+yAdjust
+ p
->ny
) < 5 ?
2274 FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0
2275 + (yAdjust ? FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0);
2276 NSRect r
= NSMakeRect
(p
->bx
+xAdjust
, p
->by
+yAdjust
, p
->nx
, p
->ny
+yIncr
);
2278 [ns_lookup_indexed_color
(face
->background
, f
) set];
2284 NSRect r
= NSMakeRect
(p
->x
+xAdjust
, p
->y
, p
->wd
, p
->h
);
2285 NSPoint pt
= r.origin
;
2286 EmacsImage
*img
= bimgs
[p
->which - 1];
2290 unsigned short
*bits
= p
->bits
+ p
->dh
;
2293 unsigned
char *cbits
= xmalloc
(len
);
2295 for (i
=0; i
<len
; i
++)
2296 cbits
[i
] = ~
(bits
[i
] & 0xff);
2297 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2299 bimgs
[p
->which - 1] = img
;
2304 /* Since we composite the bitmap instead of just blitting it, we need
2305 to erase the whole background. */
2306 [ns_lookup_indexed_color
(face
->background
, f
) set];
2309 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2310 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2317 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2318 int x
, int y
, int cursor_type
, int cursor_width
,
2319 int on_p
, int active_p
)
2320 /* --------------------------------------------------------------------------
2321 External call (RIF): draw cursor.
2322 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2323 -------------------------------------------------------------------------- */
2326 int fx
, fy
, h
, cursor_height
;
2327 struct frame
*f
= WINDOW_XFRAME
(w
);
2328 struct glyph
*phys_cursor_glyph
;
2330 struct glyph
*cursor_glyph
;
2332 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2334 /* If cursor is out of bounds, don't draw garbage. This can happen
2335 in mini-buffer windows when switching between echo area glyphs
2338 NSTRACE
(dumpcursor
);
2343 w
->phys_cursor_type
= cursor_type
;
2344 w
->phys_cursor_on_p
= on_p
;
2346 if (cursor_type
== NO_CURSOR
)
2348 w
->phys_cursor_width
= 0;
2352 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2354 if (glyph_row
->exact_window_width_line_p
2355 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2357 glyph_row
->cursor_in_fringe_p
= 1;
2358 draw_fringe_bitmap
(w
, glyph_row
, 0);
2363 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2364 (other terminals do it the other way round). We must set
2365 w->phys_cursor_width to the cursor width. For bar cursors, that
2366 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2367 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2369 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2370 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2371 if (cursor_type
== BAR_CURSOR
)
2373 if (cursor_width
< 1)
2374 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2375 w
->phys_cursor_width
= cursor_width
;
2377 /* If we have an HBAR, "cursor_width" MAY specify height. */
2378 else if (cursor_type
== HBAR_CURSOR
)
2380 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2381 fy
+= h
- cursor_height
;
2385 r.origin.x
= fx
, r.origin.y
= fy
;
2387 r.
size.width
= w
->phys_cursor_width
;
2389 /* FIXME: if we overwrite the internal border area, it does not get erased;
2390 fix by truncating cursor, but better would be to erase properly */
2391 overspill
= r.origin.x
+ r.
size.width
-
2392 WINDOW_TEXT_TO_FRAME_PIXEL_X
(w
, WINDOW_BOX_RIGHT_EDGE_X
(w
)
2393 - WINDOW_TOTAL_FRINGE_WIDTH
(w
) - FRAME_INTERNAL_BORDER_WIDTH
(f
));
2395 r.
size.width
-= overspill
;
2397 /* TODO: only needed in rare cases with last-resort font in HELLO..
2398 should we do this more efficiently? */
2399 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2402 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2403 if (face
&& NS_FACE_BACKGROUND
(face
)
2404 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2406 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2407 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2410 [FRAME_CURSOR_COLOR
(f
) set];
2412 #ifdef NS_IMPL_COCOA
2413 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2414 atomic. Cleaner ways of doing this should be investigated.
2415 One way would be to set a global variable DRAWING_CURSOR
2416 when making the call to draw_phys..(), don't focus in that
2417 case, then move the ns_unfocus() here after that call. */
2418 NSDisableScreenUpdates
();
2421 switch (cursor_type
)
2425 case FILLED_BOX_CURSOR
:
2428 case HOLLOW_BOX_CURSOR
:
2431 NSRectFill
(NSInsetRect
(r
, 1, 1));
2432 [FRAME_CURSOR_COLOR
(f
) set];
2439 /* If the character under cursor is R2L, draw the bar cursor
2440 on the right of its glyph, rather than on the left. */
2441 cursor_glyph
= get_phys_cursor_glyph
(w
);
2442 if ((cursor_glyph
->resolved_level
& 1) != 0)
2443 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2450 /* draw the character under the cursor */
2451 if (cursor_type
!= NO_CURSOR
)
2452 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2454 #ifdef NS_IMPL_COCOA
2455 NSEnableScreenUpdates
();
2462 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2463 /* --------------------------------------------------------------------------
2464 External (RIF): Draw a vertical line.
2465 -------------------------------------------------------------------------- */
2467 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2469 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2471 NSTRACE
(ns_draw_vertical_window_border
);
2473 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2475 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2477 ns_focus
(f
, &r
, 1);
2484 show_hourglass
(struct atimer
*timer
)
2486 if (hourglass_shown_p
)
2491 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2493 hourglass_shown_p
= 1;
2499 hide_hourglass
(void
)
2501 if (!hourglass_shown_p
)
2506 /* TODO: remove NSProgressIndicator from all frames */
2508 hourglass_shown_p
= 0;
2514 /* ==========================================================================
2516 Glyph drawing operations
2518 ========================================================================== */
2521 static inline NSRect
2522 ns_fix_rect_ibw
(NSRect r
, int fibw
, int frame_pixel_width
)
2523 /* --------------------------------------------------------------------------
2524 Under NS we draw internal borders inside fringes, and want full-width
2525 rendering to go all the way to edge. This function makes that correction.
2526 -------------------------------------------------------------------------- */
2528 if (r.origin.y
<= fibw
+1)
2530 r.
size.height
+= r.origin.y
;
2533 if (r.origin.x
<= fibw
+1)
2535 r.
size.width
+= r.origin.x
;
2538 if (frame_pixel_width
- (r.origin.x
+r.
size.width
) <= fibw
+1)
2539 r.
size.width
+= fibw
;
2546 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2547 /* --------------------------------------------------------------------------
2548 Wrapper utility to account for internal border width on full-width lines,
2549 and allow top full-width rows to hit the frame top. nr should be pointer
2550 to two successive NSRects. Number of rects actually used is returned.
2551 -------------------------------------------------------------------------- */
2553 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2554 if (s
->row
->full_width_p
)
2556 *nr
= ns_fix_rect_ibw
(*nr
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2557 FRAME_PIXEL_WIDTH
(s
->f
));
2559 *nr
= ns_fix_rect_ibw
(*(nr
+1), FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2560 FRAME_PIXEL_WIDTH
(s
->f
));
2565 /* --------------------------------------------------------------------
2566 Draw a wavy line under glyph string s. The wave fills wave_height
2573 wave_height = 3 | * * * *
2574 --------------------------------------------------------------------- */
2577 ns_draw_underwave
(struct glyph_string
*s
, CGFloat width
, CGFloat x
)
2579 int wave_height
= 3, wave_length
= 3;
2580 int y
, dx
, dy
, odd
, xmax
;
2585 dy
= wave_height
- 1;
2589 /* Find and set clipping rectangle */
2590 waveClip
= NSMakeRect
(x
, y
, width
, wave_height
);
2591 [[NSGraphicsContext currentContext
] saveGraphicsState
];
2592 NSRectClip
(waveClip
);
2594 /* Draw the waves */
2595 a.x
= x
- ((int
)(x
) % dx);
2597 odd
= (int
)(a.x
/dx
) % 2;
2607 [NSBezierPath strokeLineFromPoint
:a toPoint
:b
];
2608 a.x
= b.x
, a.y
= b.y
;
2609 b.x
+= dx
, b.y
= y
+ odd
*dy
;
2613 /* Restore previous clipping rectangle(s) */
2614 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
2620 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2621 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2622 /* --------------------------------------------------------------------------
2623 Draw underline, overline, and strike-through on glyph string s.
2624 -------------------------------------------------------------------------- */
2626 if (s
->for_overlaps
)
2630 if (face
->underline_p
)
2632 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2634 if (face
->underline_defaulted_p
)
2637 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2639 ns_draw_underwave
(s
, width
, x
);
2641 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2645 unsigned
long thickness
, position
;
2647 /* If the prev was underlined, match its appearance. */
2648 if (s
->prev
&& s
->prev
->face
->underline_p
2649 && s
->prev
->underline_thickness
> 0)
2651 thickness
= s
->prev
->underline_thickness
;
2652 position
= s
->prev
->underline_position
;
2657 unsigned
long descent
;
2660 descent
= s
->y
+ s
->height
- s
->ybase
;
2662 /* Use underline thickness of font, defaulting to 1. */
2663 thickness
= (font
&& font
->underline_thickness
> 0)
2664 ? font
->underline_thickness
: 1;
2666 /* Determine the offset of underlining from the baseline. */
2667 if (x_underline_at_descent_line
)
2668 position
= descent
- thickness
;
2669 else if (x_use_underline_position_properties
2670 && font
&& font
->underline_position
>= 0)
2671 position
= font
->underline_position
;
2673 position
= lround
(font
->descent
/ 2);
2675 position
= underline_minimum_offset
;
2677 position
= max (position
, underline_minimum_offset
);
2679 /* Ensure underlining is not cropped. */
2680 if (descent
<= position
)
2682 position
= descent
- 1;
2685 else if (descent
< position
+ thickness
)
2689 s
->underline_thickness
= thickness
;
2690 s
->underline_position
= position
;
2692 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2694 if (face
->underline_defaulted_p
)
2697 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2701 /* Do overline. We follow other terms in using a thickness of 1
2702 and ignoring overline_margin. */
2703 if (face
->overline_p
)
2706 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2708 if (face
->overline_color_defaulted_p
)
2711 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2715 /* Do strike-through. We follow other terms for thickness and
2716 vertical position.*/
2717 if (face
->strike_through_p
)
2722 dy
= lrint
((s
->height
- 1) / 2);
2723 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2725 if (face
->strike_through_color_defaulted_p
)
2728 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2734 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2735 /* --------------------------------------------------------------------------
2736 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2737 Note we can't just use an NSDrawRect command, because of the possibility
2738 of some sides not being drawn, and because the rect will be filled.
2739 -------------------------------------------------------------------------- */
2745 s.
size.height
= thickness
;
2747 s.origin.y
+= r.
size.height
- thickness
;
2750 s.
size.height
= r.
size.height
;
2751 s.origin.y
= r.origin.y
;
2753 /* left, right (optional) */
2754 s.
size.width
= thickness
;
2759 s.origin.x
+= r.
size.width
- thickness
;
2766 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2767 char top_p
, char bottom_p
, char left_p
, char right_p
,
2768 struct glyph_string
*s
)
2769 /* --------------------------------------------------------------------------
2770 Draw a relief rect inside r, optionally leaving some sides open.
2771 Note we can't just use an NSDrawBezel command, because of the possibility
2772 of some sides not being drawn, and because the rect will be filled.
2773 -------------------------------------------------------------------------- */
2775 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2776 NSColor
*newBaseCol
= nil
;
2779 NSTRACE
(ns_draw_relief
);
2783 if (s
->face
->use_box_color_for_shadows_p
)
2785 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2787 /* else if (s->first_glyph->type == IMAGE_GLYPH
2789 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2791 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2795 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2798 if (newBaseCol
== nil
)
2799 newBaseCol
= [NSColor grayColor
];
2801 if (newBaseCol
!= baseCol
) /* TODO: better check */
2804 baseCol
= [newBaseCol retain
];
2806 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2808 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2811 [(raised_p ? lightCol
: darkCol
) set];
2813 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2816 sr.
size.height
= thickness
;
2817 if (top_p
) NSRectFill
(sr
);
2820 sr.
size.height
= r.
size.height
;
2821 sr.
size.width
= thickness
;
2822 if (left_p
) NSRectFill
(sr
);
2824 [(raised_p ? darkCol
: lightCol
) set];
2827 sr.
size.width
= r.
size.width
;
2828 sr.
size.height
= thickness
;
2829 sr.origin.y
+= r.
size.height
- thickness
;
2830 if (bottom_p
) NSRectFill
(sr
);
2833 sr.
size.height
= r.
size.height
;
2834 sr.origin.y
= r.origin.y
;
2835 sr.
size.width
= thickness
;
2836 sr.origin.x
+= r.
size.width
- thickness
;
2837 if (right_p
) NSRectFill
(sr
);
2842 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2843 /* --------------------------------------------------------------------------
2844 Function modeled after x_draw_glyph_string_box ().
2845 Sets up parameters for drawing.
2846 -------------------------------------------------------------------------- */
2848 int right_x
, last_x
;
2849 char left_p
, right_p
;
2850 struct glyph
*last_glyph
;
2855 if (s
->hl
== DRAW_MOUSE_FACE
)
2857 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2859 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2864 thickness
= face
->box_line_width
;
2866 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2868 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2869 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2870 : window_box_right
(s
->w
, s
->area
));
2871 last_glyph
= (s
->cmp || s
->img
2872 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2874 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2875 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2877 left_p
= (s
->first_glyph
->left_box_line_p
2878 ||
(s
->hl
== DRAW_MOUSE_FACE
2879 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2880 right_p
= (last_glyph
->right_box_line_p
2881 ||
(s
->hl
== DRAW_MOUSE_FACE
2882 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2884 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2886 /* expand full-width row over internal borders */
2887 if (s
->row
->full_width_p
)
2888 r
= ns_fix_rect_ibw
(r
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2889 FRAME_PIXEL_WIDTH
(s
->f
));
2891 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2892 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2894 ns_draw_box
(r
, abs (thickness
),
2895 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2900 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2901 1, 1, left_p
, right_p
, s
);
2907 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2908 /* --------------------------------------------------------------------------
2909 Modeled after x_draw_glyph_string_background, which draws BG in
2910 certain cases. Others are left to the text rendering routine.
2911 -------------------------------------------------------------------------- */
2913 NSTRACE
(ns_maybe_dumpglyphs_background
);
2915 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2917 int box_line_width
= max (s
->face
->box_line_width
, 0);
2918 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2919 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2922 if (s
->hl
== DRAW_MOUSE_FACE
)
2924 face
= FACE_FROM_ID
(s
->f
,
2925 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2927 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2930 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2932 [(NS_FACE_BACKGROUND
(face
) != 0
2933 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2934 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2937 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2938 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2941 if (s
->hl
!= DRAW_CURSOR
)
2943 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2944 s
->background_width
,
2945 s
->height
-2*box_line_width
);
2947 /* expand full-width row over internal borders */
2948 if (s
->row
->full_width_p
)
2950 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
2951 if (r.origin.y
<= fibw
+1 + box_line_width
)
2953 r.
size.height
+= r.origin.y
;
2956 if (r.origin.x
<= fibw
+1)
2958 r.
size.width
+= 2*r.origin.x
;
2961 if (FRAME_PIXEL_WIDTH
(s
->f
) - (r.origin.x
+ r.
size.width
)
2963 r.
size.width
+= fibw
;
2969 s
->background_filled_p
= 1;
2976 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2977 /* --------------------------------------------------------------------------
2978 Renders an image and associated borders.
2979 -------------------------------------------------------------------------- */
2981 EmacsImage
*img
= s
->img
->pixmap
;
2982 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2983 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2984 int bg_x
, bg_y
, bg_height
;
2991 NSTRACE
(ns_dumpglyphs_image
);
2993 if (s
->face
->box
!= FACE_NO_BOX
2994 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
2995 x
+= abs (s
->face
->box_line_width
);
2998 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
2999 bg_height
= s
->height
;
3000 /* other terms have this, but was causing problems w/tabbar mode */
3001 /* - 2 * box_line_vwidth; */
3003 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
3004 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
3006 /* Draw BG: if we need larger area than image itself cleared, do that,
3007 otherwise, since we composite the image under NS (instead of mucking
3008 with its background color), we must clear just the image area. */
3009 if (s
->hl
== DRAW_MOUSE_FACE
)
3011 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3013 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3016 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3018 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
3020 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
3021 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
3023 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
3024 s
->background_filled_p
= 1;
3028 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3031 /* expand full-width row over internal borders */
3032 if (s
->row
->full_width_p
)
3034 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
3035 if (br.origin.y
<= fibw
+1 + box_line_vwidth
)
3037 br.
size.height
+= br.origin.y
;
3040 if (br.origin.x
<= fibw
+1 + box_line_vwidth
)
3042 br.
size.width
+= br.origin.x
;
3045 if (FRAME_PIXEL_WIDTH
(s
->f
) - (br.origin.x
+ br.
size.width
) <= fibw
+1)
3046 br.
size.width
+= fibw
;
3051 /* Draw the image.. do we need to draw placeholder if img ==nil? */
3053 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
3054 operation
: NSCompositeSourceOver
];
3056 if (s
->hl
== DRAW_CURSOR
)
3058 [FRAME_CURSOR_COLOR
(s
->f
) set];
3059 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3060 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3062 /* Currently on NS img->mask is always 0. Since
3063 get_window_cursor_type specifies a hollow box cursor when on
3064 a non-masked image we never reach this clause. But we put it
3065 in in anticipation of better support for image masks on
3067 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3071 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3074 /* Draw underline, overline, strike-through. */
3075 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3077 /* Draw relief, if requested */
3078 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3080 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3082 th
= tool_bar_button_relief
>= 0 ?
3083 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3084 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3088 th
= abs (s
->img
->relief
);
3089 raised_p
= (s
->img
->relief
> 0);
3092 r.origin.x
= x
- th
;
3093 r.origin.y
= y
- th
;
3094 r.
size.width
= s
->slice.width
+ 2*th
-1;
3095 r.
size.height
= s
->slice.height
+ 2*th
-1;
3096 ns_draw_relief
(r
, th
, raised_p
,
3098 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3100 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3103 /* If there is no mask, the background won't be seen,
3104 so draw a rectangle on the image for the cursor.
3105 Do this for all images, getting transparency right is not reliable. */
3106 if (s
->hl
== DRAW_CURSOR
)
3108 int thickness
= abs (s
->img
->relief
);
3109 if (thickness
== 0) thickness
= 1;
3110 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3116 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3121 NSColor
*fgCol
, *bgCol
;
3123 if (!s
->background_filled_p
)
3125 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3126 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3128 ns_focus
(s
->f
, r
, n
);
3130 if (s
->hl
== DRAW_MOUSE_FACE
)
3132 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3134 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3137 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3139 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3140 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3144 if (!s
->row
->full_width_p
)
3146 int overrun
, leftoverrun
;
3148 /* truncate to avoid overwriting fringe and/or scrollbar */
3149 overrun
= max (0, (s
->x
+ s
->background_width
)
3150 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3151 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3152 r
[i
].
size.width
-= overrun
;
3154 /* truncate to avoid overwriting to left of the window box */
3155 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3156 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3158 if (leftoverrun
> 0)
3160 r
[i
].origin.x
+= leftoverrun
;
3161 r
[i
].
size.width
-= leftoverrun
;
3164 /* XXX: Try to work between problem where a stretch glyph on
3165 a partially-visible bottom row will clear part of the
3166 modeline, and another where list-buffers headers and similar
3167 rows erroneously have visible_height set to 0. Not sure
3168 where this is coming from as other terms seem not to show. */
3169 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3172 /* expand full-width rows over internal borders */
3175 r
[i
] = ns_fix_rect_ibw
(r
[i
], FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
3176 FRAME_PIXEL_WIDTH
(s
->f
));
3181 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3182 overwriting cursor (usually when cursor on a tab) */
3183 if (s
->hl
== DRAW_CURSOR
)
3188 width
= s
->w
->phys_cursor_width
;
3189 r
[i
].
size.width
-= width
;
3190 r
[i
].origin.x
+= width
;
3194 /* Draw overlining, etc. on the cursor. */
3195 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3196 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3198 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3205 /* Draw overlining, etc. on the stretch glyph (or the part
3206 of the stretch glyph after the cursor). */
3207 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3211 s
->background_filled_p
= 1;
3217 ns_draw_glyph_string
(struct glyph_string
*s
)
3218 /* --------------------------------------------------------------------------
3219 External (RIF): Main draw-text call.
3220 -------------------------------------------------------------------------- */
3222 /* TODO (optimize): focus for box and contents draw */
3225 char box_drawn_p
= 0;
3227 NSTRACE
(ns_draw_glyph_string
);
3229 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3232 struct glyph_string
*next
;
3234 for (width
= 0, next
= s
->next
;
3235 next
&& width
< s
->right_overhang
;
3236 width
+= next
->width
, next
= next
->next
)
3237 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3239 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3241 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3242 ns_focus
(s
->f
, r
, n
);
3243 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3248 ns_dumpglyphs_stretch
(s
->next
);
3250 next
->num_clips
= 0;
3254 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3255 && (s
->first_glyph
->type == CHAR_GLYPH
3256 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3258 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3259 ns_focus
(s
->f
, r
, n
);
3260 ns_maybe_dumpglyphs_background
(s
, 1);
3261 ns_dumpglyphs_box_or_relief
(s
);
3266 switch (s
->first_glyph
->type)
3270 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3271 ns_focus
(s
->f
, r
, n
);
3272 ns_dumpglyphs_image
(s
, r
[0]);
3277 ns_dumpglyphs_stretch
(s
);
3281 case COMPOSITE_GLYPH
:
3282 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3283 ns_focus
(s
->f
, r
, n
);
3285 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3286 && ! s
->first_glyph
->u.cmp.automatic
))
3287 s
->background_filled_p
= 1;
3289 ns_maybe_dumpglyphs_background
3290 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3292 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3293 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3294 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3295 NS_DUMPGLYPH_NORMAL
));
3296 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3297 if (ns_tmp_font
== NULL)
3298 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3300 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3302 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3303 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3304 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3307 ns_tmp_font
->font.driver
->draw
3308 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3309 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3310 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
3312 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3314 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3315 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3316 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3322 case GLYPHLESS_GLYPH
:
3323 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3324 ns_focus
(s
->f
, r
, n
);
3326 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3327 && ! s
->first_glyph
->u.cmp.automatic
))
3328 s
->background_filled_p
= 1;
3330 ns_maybe_dumpglyphs_background
3331 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3333 /* Not yet implemented. */
3342 /* Draw box if not done already. */
3343 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3345 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3346 ns_focus
(s
->f
, r
, n
);
3347 ns_dumpglyphs_box_or_relief
(s
);
3356 /* ==========================================================================
3360 ========================================================================== */
3364 ns_send_appdefined
(int value
)
3365 /* --------------------------------------------------------------------------
3366 Internal: post an appdefined event which EmacsApp-sendEvent will
3367 recognize and take as a command to halt the event loop.
3368 -------------------------------------------------------------------------- */
3370 /*NSTRACE (ns_send_appdefined); */
3372 /* Only post this event if we haven't already posted one. This will end
3373 the [NXApp run] main loop after having processed all events queued at
3375 if (send_appdefined
)
3379 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3380 send_appdefined
= NO
;
3382 /* Don't need wakeup timer any more */
3385 [timed_entry invalidate
];
3386 [timed_entry release
];
3390 /* Ditto for file descriptor poller */
3393 [fd_entry invalidate
];
3398 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3399 location
: NSMakePoint
(0, 0)
3402 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3403 context
: [NSApp context
]
3408 /* Post an application defined event on the event queue. When this is
3409 received the [NXApp run] will return, thus having processed all
3410 events which are currently queued. */
3411 [NSApp postEvent
: nxev atStart
: NO
];
3417 ns_read_socket
(struct terminal *terminal, int expected
,
3418 struct input_event
*hold_quit
)
3419 /* --------------------------------------------------------------------------
3420 External (hook): Post an event to ourself and keep reading events until
3421 we read it back again. In effect process all events which were waiting.
3422 From 21+ we have to manage the event buffer ourselves.
3423 -------------------------------------------------------------------------- */
3425 struct input_event ev
;
3428 /* NSTRACE (ns_read_socket); */
3430 if (interrupt_input_blocked
)
3432 interrupt_input_pending
= 1;
3434 pending_signals
= 1;
3439 interrupt_input_pending
= 0;
3441 pending_signals
= pending_atimers
;
3445 n_emacs_events_pending
= 0;
3448 q_event_ptr
= hold_quit
;
3450 /* we manage autorelease pools by allocate/reallocate each time around
3451 the loop; strict nesting is occasionally violated but seems not to
3452 matter.. earlier methods using full nesting caused major memory leaks */
3453 [outerpool release
];
3454 outerpool
= [[NSAutoreleasePool alloc
] init
];
3456 /* If have pending open-file requests, attend to the next one of those. */
3457 if (ns_pending_files
&& [ns_pending_files count
] != 0
3458 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3460 [ns_pending_files removeObjectAtIndex
: 0];
3462 /* Deal with pending service requests. */
3463 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3465 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3466 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3468 [ns_pending_service_names removeObjectAtIndex
: 0];
3469 [ns_pending_service_args removeObjectAtIndex
: 0];
3473 /* Run and wait for events. We must always send one NX_APPDEFINED event
3474 to ourself, otherwise [NXApp run] will never exit. */
3475 send_appdefined
= YES
;
3477 /* If called via ns_select, this is called once with expected=1,
3478 because we expect either the timeout or file descriptor activity.
3479 In this case the first event through will either be real input or
3480 one of these. read_avail_input() then calls once more with expected=0
3481 and in that case we need to return quickly if there is nothing.
3482 If we're being called outside of that, it's also OK to return quickly
3483 after one iteration through the event loop, since other terms do
3484 this and emacs expects it. */
3485 if (!(inNsSelect
&& expected
))
3487 /* Post an application defined event on the event queue. When this is
3488 received the [NXApp run] will return, thus having processed all
3489 events which are currently queued, if any. */
3490 ns_send_appdefined
(-1);
3496 nevents
= n_emacs_events_pending
;
3497 n_emacs_events_pending
= 0;
3498 emacs_event
= q_event_ptr
= NULL;
3506 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3507 fd_set
*exceptfds
, EMACS_TIME
*timeout
, sigset_t
*sigmask
)
3508 /* --------------------------------------------------------------------------
3509 Replacement for select, checking for events
3510 -------------------------------------------------------------------------- */
3515 struct timespec select_timeout
;
3517 /* NSTRACE (ns_select); */
3519 if (NSApp
== nil || inNsSelect
== 1 /* || ([NSApp isActive] == NO &&
3520 [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil
3521 inMode:NSDefaultRunLoopMode dequeue:NO] == nil) */)
3522 return pselect
(nfds
, readfds
, writefds
, exceptfds
, timeout
, sigmask
);
3524 /* Save file descriptor set, which gets overwritten in calls to select ()
3525 Note, this is called from process.c, and only readfds is ever set */
3528 memcpy
(&select_readfds
, readfds
, sizeof
(fd_set
));
3534 /* Try an initial select for pending data on input files */
3535 select_timeout.tv_sec
= select_timeout.tv_nsec
= 0;
3536 result
= pselect
(nfds
, readfds
, writefds
, exceptfds
,
3537 &select_timeout
, sigmask
);
3541 /* if (!timeout || timed_entry || fd_entry)
3542 fprintf (stderr, "assertion failed: timeout null or timed_entry/fd_entry non-null in ns_select\n"); */
3544 /* set a timeout and run the main AppKit event loop while continuing
3545 to monitor the files */
3546 time
= EMACS_TIME_TO_DOUBLE
(*timeout
);
3547 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3549 selector
: @selector
(timeout_handler
:)
3551 repeats
: YES
] /* for safe removal */
3554 /* set a periodic task to try the pselect () again */
3555 fd_entry
= [[NSTimer scheduledTimerWithTimeInterval
: 0.1
3557 selector
: @selector
(fd_handler
:)
3562 /* Let Application dispatch events until it receives an event of the type
3563 NX_APPDEFINED, which should only be sent by timeout_handler.
3564 We tell read_avail_input() that input is "expected" because we do expect
3565 either the timeout or fd handler to fire, and if they don't, the original
3566 call from process.c that got us here expects us to wait until some input
3570 ev
= last_appdefined_event
;
3576 if ([ev
type] != NSApplicationDefined
)
3580 last_appdefined_event
= 0;
3584 /* The NX_APPDEFINED event we received was a timeout. */
3589 /* The NX_APPDEFINED event we received was the result of
3590 at least one real input event arriving. */
3596 /* Received back from pselect () in fd_handler; copy the results */
3598 memcpy
(readfds
, &select_readfds
, sizeof
(fd_set
));
3602 /* never reached, shut compiler up */
3608 /* ==========================================================================
3612 ========================================================================== */
3616 ns_set_vertical_scroll_bar
(struct window
*window
,
3617 int portion
, int whole
, int position
)
3618 /* --------------------------------------------------------------------------
3619 External (hook): Update or add scrollbar
3620 -------------------------------------------------------------------------- */
3624 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3625 EmacsView
*view = FRAME_NS_VIEW
(f
);
3626 int window_y
, window_height
;
3627 BOOL barOnVeryLeft
, barOnVeryRight
;
3628 int top
, left
, height
, width
, sb_width
, sb_left
;
3630 static int count
= 0;
3632 /* optimization; display engine sends WAY too many of these.. */
3633 if (!NILP
(window
->vertical_scroll_bar
))
3635 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3636 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3638 if (view->scrollbarsNeedingUpdate
== 0)
3640 if (!windows_or_buffers_changed
)
3644 view->scrollbarsNeedingUpdate
--;
3648 NSTRACE
(ns_set_vertical_scroll_bar
);
3650 /* Get dimensions. */
3651 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3653 height
= window_height
;
3654 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3655 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3657 if (top
< 5) /* top scrollbar adjustment */
3659 top
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3660 height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3663 /* allow for displaying a skinnier scrollbar than char area allotted */
3664 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3665 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3667 barOnVeryLeft
= left
< 5;
3668 barOnVeryRight
= FRAME_PIXEL_WIDTH
(f
) - left
- width
< 5;
3669 sb_left
= left
+ FRAME_INTERNAL_BORDER_WIDTH
(f
)
3670 * (barOnVeryLeft ?
-1 : (barOnVeryRight ?
1 : 0));
3672 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3673 /* the parent view is flipped, so we need to flip y value */
3675 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3677 XSETWINDOW
(win
, window
);
3680 /* we want at least 5 lines to display a scrollbar */
3681 if (WINDOW_TOTAL_LINES
(window
) < 5)
3683 if (!NILP
(window
->vertical_scroll_bar
))
3685 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3686 [bar removeFromSuperview
];
3687 window
->vertical_scroll_bar
= Qnil
;
3689 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3694 if (NILP
(window
->vertical_scroll_bar
))
3696 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3697 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3698 window
->vertical_scroll_bar
= make_save_value
(bar, 0);
3703 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3704 oldRect
= [bar frame
];
3705 r.
size.width
= oldRect.
size.width
;
3706 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3708 if (oldRect.origin.x
!= r.origin.x
)
3709 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3714 [bar setPosition
: position portion
: portion whole
: whole
];
3720 ns_condemn_scroll_bars
(struct frame
*f
)
3721 /* --------------------------------------------------------------------------
3722 External (hook): arrange for all frame's scrollbars to be removed
3723 at next call to judge_scroll_bars, except for those redeemed.
3724 -------------------------------------------------------------------------- */
3728 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3730 NSTRACE
(ns_condemn_scroll_bars
);
3732 for (i
=[subviews count
]-1; i
>= 0; i
--)
3734 view = [subviews objectAtIndex
: i
];
3735 if ([view isKindOfClass
: [EmacsScroller
class]])
3742 ns_redeem_scroll_bar
(struct window
*window
)
3743 /* --------------------------------------------------------------------------
3744 External (hook): arrange to spare this window's scrollbar
3745 at next call to judge_scroll_bars.
3746 -------------------------------------------------------------------------- */
3749 NSTRACE
(ns_redeem_scroll_bar
);
3750 if (!NILP
(window
->vertical_scroll_bar
))
3752 bar =XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3759 ns_judge_scroll_bars
(struct frame
*f
)
3760 /* --------------------------------------------------------------------------
3761 External (hook): destroy all scrollbars on frame that weren't
3762 redeemed after call to condemn_scroll_bars.
3763 -------------------------------------------------------------------------- */
3767 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3768 NSTRACE
(ns_judge_scroll_bars
);
3769 for (i
=[subviews count
]-1; i
>= 0; i
--)
3771 view = [subviews objectAtIndex
: i
];
3772 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3779 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3781 /* XXX irrelevant under NS */
3786 /* ==========================================================================
3790 ========================================================================== */
3793 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3795 NSScreen
*screen
= [NSScreen mainScreen
];
3796 return [screen frame
].
size.height
;
3800 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3802 NSScreen
*screen
= [NSScreen mainScreen
];
3803 return [screen frame
].
size.width
;
3807 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3808 /* --------------------------------------------------------------------------
3809 Convert modifier name to lisp symbol
3810 -------------------------------------------------------------------------- */
3812 if (!strncmp
(SDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3814 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3816 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3818 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3820 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3822 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3829 static Lisp_Object ns_mod_to_lisp
(int m
)
3830 /* --------------------------------------------------------------------------
3831 Convert modifier code (see lisp.h) to lisp symbol
3832 -------------------------------------------------------------------------- */
3836 else if (m
== CHAR_SUPER
)
3838 else if (m
== CHAR_CTL
)
3840 else if (m
== CHAR_ALT
)
3842 else if (m
== CHAR_HYPER
)
3844 else /* if (m == 0) */
3850 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3851 Lisp_Object yesval
, Lisp_Object noval
,
3852 BOOL is_float
, BOOL is_modstring
)
3853 /* --------------------------------------------------------------------------
3854 Check a parameter value in user's preferences
3855 -------------------------------------------------------------------------- */
3857 const
char *value
= ns_get_defaults_value
(parameter
);
3863 if (c_strcasecmp
(value
, "YES"
) == 0)
3865 else if (c_strcasecmp
(value
, "NO"
) == 0)
3867 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3868 *result
= make_float
(f
);
3869 else if (is_modstring
&& value
)
3870 *result
= ns_string_to_lispmod
(value
);
3871 else fprintf (stderr
,
3872 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3878 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3879 /* --------------------------------------------------------------------------
3880 Initialize global info and storage for display.
3881 -------------------------------------------------------------------------- */
3883 NSScreen
*screen
= [NSScreen mainScreen
];
3884 NSWindowDepth depth
= [screen depth
];
3885 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
3887 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3888 dpyinfo
->resy
= 72.27;
3889 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3890 NSColorSpaceFromDepth
(depth
)]
3891 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3892 NSColorSpaceFromDepth
(depth
)];
3893 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3894 dpyinfo
->image_cache
= make_image_cache
();
3895 dpyinfo
->color_table
= xmalloc
(sizeof
*dpyinfo
->color_table
);
3896 dpyinfo
->color_table
->colors
= NULL;
3897 dpyinfo
->root_window
= 42; /* a placeholder.. */
3899 hlinfo
->mouse_face_mouse_frame
= NULL;
3900 hlinfo
->mouse_face_deferred_gc
= 0;
3901 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
3902 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
3903 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3904 hlinfo
->mouse_face_window
= hlinfo
->mouse_face_overlay
= Qnil
;
3905 hlinfo
->mouse_face_hidden
= 0;
3907 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
3908 hlinfo
->mouse_face_defer
= 0;
3910 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3912 dpyinfo
->n_fonts
= 0;
3913 dpyinfo
->smallest_font_height
= 1;
3914 dpyinfo
->smallest_char_width
= 1;
3918 /* This and next define (many of the) public functions in this file. */
3919 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3920 with using despite presence in the "system dependent" redisplay
3921 interface. In addition, many of the ns_ methods have code that is
3922 shared with all terms, indicating need for further refactoring. */
3923 extern frame_parm_handler ns_frame_parm_handlers
[];
3924 static
struct redisplay_interface ns_redisplay_interface
=
3926 ns_frame_parm_handlers
,
3930 x_clear_end_of_line
,
3932 ns_after_update_window_line
,
3933 ns_update_window_begin
,
3934 ns_update_window_end
,
3937 0, /* flush_display_optional */
3938 x_clear_window_mouse_face
,
3939 x_get_glyph_overhangs
,
3940 x_fix_overlapping_area
,
3941 ns_draw_fringe_bitmap
,
3942 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3943 0, /* destroy_fringe_bitmap */
3944 ns_compute_glyph_string_overhangs
,
3945 ns_draw_glyph_string
, /* interface to nsfont.m */
3946 ns_define_frame_cursor
,
3947 ns_clear_frame_area
,
3948 ns_draw_window_cursor
,
3949 ns_draw_vertical_window_border
,
3950 ns_shift_glyphs_for_insert
3955 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3961 /* This function is called when the last frame on a display is deleted. */
3963 ns_delete_terminal
(struct terminal *terminal)
3965 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3968 /* Protect against recursive calls. delete_frame in
3969 delete_terminal calls us back when it deletes our last frame. */
3970 if (!terminal->name
)
3975 x_destroy_all_bitmaps
(dpyinfo
);
3976 ns_delete_display
(dpyinfo
);
3981 static
struct terminal *
3982 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3983 /* --------------------------------------------------------------------------
3984 Set up use of NS before we make the first connection.
3985 -------------------------------------------------------------------------- */
3987 struct terminal *terminal;
3989 NSTRACE
(ns_create_terminal
);
3991 terminal = create_terminal
();
3993 terminal->type = output_ns
;
3994 terminal->display_info.ns
= dpyinfo
;
3995 dpyinfo
->terminal = terminal;
3997 terminal->rif
= &ns_redisplay_interface
;
3999 terminal->clear_frame_hook
= ns_clear_frame
;
4000 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
4001 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
4002 terminal->ring_bell_hook
= ns_ring_bell
;
4003 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
4004 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
4005 terminal->update_begin_hook
= ns_update_begin
;
4006 terminal->update_end_hook
= ns_update_end
;
4007 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
4008 terminal->read_socket_hook
= ns_read_socket
;
4009 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
4010 terminal->mouse_position_hook
= ns_mouse_position
;
4011 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
4012 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
4014 terminal->fullscreen_hook
= 0; /* see XTfullscreen_hook */
4016 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
4017 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
4018 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
4019 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
4021 terminal->delete_frame_hook
= x_destroy_window
;
4022 terminal->delete_terminal_hook
= ns_delete_terminal
;
4024 terminal->scroll_region_ok
= 1;
4025 terminal->char_ins_del_ok
= 1;
4026 terminal->line_ins_del_ok
= 1;
4027 terminal->fast_clear_end_of_line
= 1;
4028 terminal->memory_below_frame
= 0;
4034 struct ns_display_info
*
4035 ns_term_init
(Lisp_Object display_name
)
4036 /* --------------------------------------------------------------------------
4037 Start the Application and get things rolling.
4038 -------------------------------------------------------------------------- */
4040 struct terminal *terminal;
4041 struct ns_display_info
*dpyinfo
;
4042 static int ns_initialized
= 0;
4045 NSTRACE
(ns_term_init
);
4047 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
4048 /*GSDebugAllocationActive (YES); */
4050 handling_signal
= 0;
4052 if (!ns_initialized
)
4055 Fset_input_interrupt_mode
(Qnil
);
4059 ns_pending_files
= [[NSMutableArray alloc
] init
];
4060 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
4061 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
4063 /* Start app and create the main menu, window, view.
4064 Needs to be here because ns_initialize_display_info () uses AppKit classes.
4065 The view will then ask the NSApp to stop and return to Emacs. */
4066 [EmacsApp sharedApplication
];
4069 [NSApp setDelegate
: NSApp
];
4071 /* debugging: log all notifications */
4072 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4073 selector: @selector (logNotification:)
4074 name: nil object: nil]; */
4076 dpyinfo
= xzalloc
(sizeof
*dpyinfo
);
4078 ns_initialize_display_info
(dpyinfo
);
4079 terminal = ns_create_terminal
(dpyinfo
);
4081 terminal->kboard
= xmalloc
(sizeof
*terminal->kboard
);
4082 init_kboard
(terminal->kboard
);
4083 KVAR
(terminal->kboard
, Vwindow_system
) = Qns
;
4084 terminal->kboard
->next_kboard
= all_kboards
;
4085 all_kboards
= terminal->kboard
;
4086 /* Don't let the initial kboard remain current longer than necessary.
4087 That would cause problems if a file loaded on startup tries to
4088 prompt in the mini-buffer. */
4089 if (current_kboard
== initial_kboard
)
4090 current_kboard
= terminal->kboard
;
4091 terminal->kboard
->reference_count
++;
4093 dpyinfo
->next
= x_display_list
;
4094 x_display_list
= dpyinfo
;
4096 /* Put it on ns_display_name_list */
4097 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
4098 ns_display_name_list
);
4099 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
4101 terminal->name
= xstrdup
(SSDATA
(display_name
));
4105 if (!inhibit_x_resources
)
4107 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4110 /* this is a standard variable */
4111 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4112 make_float
(10.0), make_float
(6.0), YES
, NO
);
4113 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4116 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
4117 stringForKey
: @"AppleHighlightColor"
];
4118 if (ns_selection_color
== nil
)
4119 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
4122 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4126 Lisp_Object color_file
, color_map
, color
;
4131 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4132 Fsymbol_value
(intern
("data
-directory"
)));
4133 if (NILP
(Ffile_readable_p
(color_file
)))
4134 fatal
("Could not
find %s.\n", SDATA (color_file));
4136 color_map
= Fx_load_color_file
(color_file
);
4137 if (NILP
(color_map
))
4138 fatal
("Could not read
%s.\n", SDATA (color_file));
4140 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4141 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4143 color
= XCAR
(color_map
);
4144 name
= SDATA
(XCAR
(color
));
4145 c
= XINT
(XCDR
(color
));
4147 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4148 green
: GREEN_FROM_ULONG
(c
) / 255.0
4149 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4151 forKey
: [NSString stringWithUTF8String
: name
]];
4153 [cl writeToFile
: nil
];
4158 #ifdef NS_IMPL_GNUSTEP
4159 Vwindow_system_version
= build_string
(gnustep_base_version
);
4161 /*PSnextrelease (128, c); */
4162 char c
[DBL_BUFSIZE_BOUND
];
4163 int len
= dtoastr
(c
, sizeof c
, 0, 0, NSAppKitVersionNumber
);
4164 Vwindow_system_version
= make_unibyte_string
(c
, len
);
4168 delete_keyboard_wait_descriptor
(0);
4170 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4172 /* Set up OS X app menu */
4173 #ifdef NS_IMPL_COCOA
4177 /* set up the application menu */
4178 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4179 [svcsMenu setAutoenablesItems
: NO
];
4180 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4181 [appMenu setAutoenablesItems
: NO
];
4182 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4183 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4185 [appMenu insertItemWithTitle
: @"About Emacs"
4186 action
: @selector
(orderFrontStandardAboutPanel
:)
4189 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4190 [appMenu insertItemWithTitle
: @"Preferences..."
4191 action
: @selector
(showPreferencesWindow
:)
4194 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4195 item
= [appMenu insertItemWithTitle
: @"Services"
4196 action
: @selector
(menuDown
:)
4199 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4200 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4201 [appMenu insertItemWithTitle
: @"Hide Emacs"
4202 action
: @selector
(hide
:)
4205 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4206 action
: @selector
(hideOtherApplications
:)
4209 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4210 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4211 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4212 action
: @selector
(terminate
:)
4216 item
= [mainMenu insertItemWithTitle
: ns_app_name
4217 action
: @selector
(menuDown
:)
4220 [mainMenu setSubmenu
: appMenu forItem
: item
];
4221 [dockMenu insertItemWithTitle
: @"New Frame"
4222 action
: @selector
(newFrame
:)
4226 [NSApp setMainMenu
: mainMenu
];
4227 [NSApp setAppleMenu
: appMenu
];
4228 [NSApp setServicesMenu
: svcsMenu
];
4229 /* Needed at least on Cocoa, to get dock menu to show windows */
4230 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4232 [[NSNotificationCenter defaultCenter
]
4233 addObserver
: mainMenu
4234 selector
: @selector
(trackingNotification
:)
4235 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4236 [[NSNotificationCenter defaultCenter
]
4237 addObserver
: mainMenu
4238 selector
: @selector
(trackingNotification
:)
4239 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4241 #endif
/* MAC OS X menu setup */
4250 ns_term_shutdown
(int sig
)
4252 [[NSUserDefaults standardUserDefaults
] synchronize
];
4254 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4255 if (STRINGP
(Vauto_save_list_file_name
))
4256 unlink
(SDATA
(Vauto_save_list_file_name
));
4258 if (sig
== 0 || sig
== SIGTERM
)
4260 [NSApp terminate
: NSApp
];
4262 else // force a stack
trace to happen
4269 /* ==========================================================================
4271 EmacsApp implementation
4273 ========================================================================== */
4276 @implementation EmacsApp
4278 - (void
)logNotification
: (NSNotification
*)notification
4280 const
char *name
= [[notification name
] UTF8String
];
4281 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4282 && !strstr
(name
, "WindowNumber"
))
4283 NSLog
(@"notification
: '%@'"
, [notification name
]);
4287 - (void
)sendEvent
: (NSEvent
*)theEvent
4288 /* --------------------------------------------------------------------------
4289 Called when NSApp is running for each event received. Used to stop
4290 the loop when we choose, since there's no way to just run one iteration.
4291 -------------------------------------------------------------------------- */
4293 int
type = [theEvent
type];
4294 NSWindow
*window
= [theEvent window
];
4295 /* NSTRACE (sendEvent); */
4296 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4298 #ifdef NS_IMPL_COCOA
4299 if (type == NSApplicationDefined
4300 && [theEvent data2
] == NSAPP_DATA2_RUNASSCRIPT
)
4308 if (type == NSCursorUpdate
&& window
== nil
)
4310 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4314 #ifdef NS_IMPL_COCOA
4315 /* pass mouse down in resize handle and subsequent drags directly to
4316 EmacsWindow so we can generate continuous redisplays */
4319 if (type == NSLeftMouseDragged
)
4321 [window mouseDragged
: theEvent
];
4324 else if (type == NSLeftMouseUp
)
4326 [window mouseUp
: theEvent
];
4330 else if (type == NSLeftMouseDown
)
4332 NSRect r
= ns_resize_handle_rect
(window
);
4333 if (NSPointInRect
([theEvent locationInWindow
], r
))
4336 [window mouseDown
: theEvent
];
4342 if (type == NSApplicationDefined
)
4344 /* Events posted by ns_send_appdefined interrupt the run loop here.
4345 But, if a modal window is up, an appdefined can still come through,
4346 (e.g., from a makeKeyWindow event) but stopping self also stops the
4347 modal loop. Just defer it until later. */
4348 if ([NSApp modalWindow
] == nil
)
4350 last_appdefined_event
= theEvent
;
4355 send_appdefined
= YES
;
4359 [super sendEvent
: theEvent
];
4363 - (void
)showPreferencesWindow
: (id
)sender
4365 struct frame
*emacsframe
= SELECTED_FRAME
();
4366 NSEvent
*theEvent
= [NSApp currentEvent
];
4370 emacs_event
->kind
= NS_NONKEY_EVENT
;
4371 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4372 emacs_event
->modifiers
= 0;
4373 EV_TRAILER
(theEvent
);
4377 - (void
)newFrame
: (id
)sender
4379 struct frame
*emacsframe
= SELECTED_FRAME
();
4380 NSEvent
*theEvent
= [NSApp currentEvent
];
4384 emacs_event
->kind
= NS_NONKEY_EVENT
;
4385 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4386 emacs_event
->modifiers
= 0;
4387 EV_TRAILER
(theEvent
);
4391 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4392 - (BOOL
) openFile
: (NSString
*)fileName
4394 struct frame
*emacsframe
= SELECTED_FRAME
();
4395 NSEvent
*theEvent
= [NSApp currentEvent
];
4400 emacs_event
->kind
= NS_NONKEY_EVENT
;
4401 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4402 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4403 ns_input_line
= Qnil
; /* can be start or cons start,end */
4404 emacs_event
->modifiers
=0;
4405 EV_TRAILER
(theEvent
);
4411 /* **************************************************************************
4413 EmacsApp delegate implementation
4415 ************************************************************************** */
4417 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4418 /* --------------------------------------------------------------------------
4419 When application is loaded, terminate event loop in ns_term_init
4420 -------------------------------------------------------------------------- */
4422 NSTRACE
(applicationDidFinishLaunching
);
4423 [NSApp setServicesProvider
: NSApp
];
4424 ns_send_appdefined
(-2);
4428 /* Termination sequences:
4431 MenuBar | File | Exit:
4432 Select Quit from App menubar:
4434 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4437 Select Quit from Dock menu:
4440 Cancel -> Nothing else
4444 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4449 - (void
) terminate
: (id
)sender
4451 struct frame
*emacsframe
= SELECTED_FRAME
();
4456 emacs_event
->kind
= NS_NONKEY_EVENT
;
4457 emacs_event
->code
= KEY_NS_POWER_OFF
;
4458 emacs_event
->arg
= Qt
; /* mark as non-key event */
4459 EV_TRAILER
((id
)nil
);
4463 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4467 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4468 return NSTerminateNow
;
4470 ret
= NSRunAlertPanel
(ns_app_name
,
4471 [NSString stringWithUTF8String
:"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
],
4472 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4474 if (ret
== NSAlertDefaultReturn
)
4475 return NSTerminateNow
;
4476 else if (ret
== NSAlertAlternateReturn
)
4477 return NSTerminateCancel
;
4478 return NSTerminateNow
; /* just in case */
4482 /* Notification from the Workspace to open a file */
4483 - (BOOL
)application
: sender openFile
: (NSString
*)file
4485 [ns_pending_files addObject
: file
];
4490 /* Open a file as a temporary file */
4491 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4493 [ns_pending_files addObject
: file
];
4498 /* Notification from the Workspace to open a file noninteractively (?) */
4499 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4501 [ns_pending_files addObject
: file
];
4506 /* Notification from the Workspace to open multiple files */
4507 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4509 NSEnumerator
*files
= [fileList objectEnumerator
];
4511 while ((file
= [files nextObject
]) != nil
)
4512 [ns_pending_files addObject
: file
];
4514 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4519 /* Handle dock menu requests. */
4520 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4526 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4527 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4529 //ns_app_active
=YES
;
4531 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4533 NSTRACE
(applicationDidBecomeActive
);
4535 //ns_app_active
=YES
;
4537 ns_update_auto_hide_menu_bar
();
4538 // No constraining takes place when the application is not active.
4539 ns_constrain_all_frames
();
4541 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4544 ns_send_appdefined
(-1);
4549 /* ==========================================================================
4551 EmacsApp aux handlers for managing event loop
4553 ========================================================================== */
4556 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4557 /* --------------------------------------------------------------------------
4558 The timeout specified to ns_select has passed.
4559 -------------------------------------------------------------------------- */
4561 /*NSTRACE (timeout_handler); */
4562 ns_send_appdefined
(-2);
4565 - (void
)fd_handler
: (NSTimer
*) fdEntry
4566 /* --------------------------------------------------------------------------
4567 Check data waiting on file descriptors and terminate if so
4568 -------------------------------------------------------------------------- */
4571 struct timespec select_timeout
;
4572 /* NSTRACE (fd_handler); */
4574 if (select_nfds
== 0)
4577 memcpy
(&t_readfds
, &select_readfds
, sizeof
(fd_set
));
4579 select_timeout.tv_sec
= select_timeout.tv_nsec
= 0;
4580 result
= pselect
(select_nfds
, &t_readfds
, NULL, NULL, &select_timeout
, NULL);
4583 memcpy
(&select_readfds
, &t_readfds
, sizeof
(fd_set
));
4584 ns_send_appdefined
(result
);
4590 /* ==========================================================================
4594 ========================================================================== */
4596 /* called from system: queue for next pass through event loop */
4597 - (void
)requestService
: (NSPasteboard
*)pboard
4598 userData
: (NSString
*)userData
4599 error: (NSString
**)error
4601 [ns_pending_service_names addObject
: userData
];
4602 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4603 SDATA
(ns_string_from_pasteboard
(pboard
))]];
4607 /* called from ns_read_socket to clear queue */
4608 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4610 struct frame
*emacsframe
= SELECTED_FRAME
();
4611 NSEvent
*theEvent
= [NSApp currentEvent
];
4616 emacs_event
->kind
= NS_NONKEY_EVENT
;
4617 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4618 ns_input_spi_name
= build_string
([name UTF8String
]);
4619 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4620 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4621 EV_TRAILER
(theEvent
);
4631 /* ==========================================================================
4633 EmacsView implementation
4635 ========================================================================== */
4638 @implementation EmacsView
4640 /* needed to inform when window closed from LISP */
4641 - (void
) setWindowClosing
: (BOOL
)closing
4643 windowClosing
= closing
;
4649 NSTRACE
(EmacsView_dealloc
);
4655 /* called on font panel selection */
4656 - (void
)changeFont
: (id
)sender
4658 NSEvent
*e
=[[self window
] currentEvent
];
4659 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4663 NSTRACE
(changeFont
);
4667 if (newFont
= [sender convertFont
:
4668 ((struct nsfont_info
*)face
->font
)->nsfont
])
4670 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4672 emacs_event
->kind
= NS_NONKEY_EVENT
;
4673 emacs_event
->modifiers
= 0;
4674 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4676 size = [newFont pointSize
];
4677 ns_input_fontsize
= make_number
(lrint
(size));
4678 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4684 - (BOOL
)acceptsFirstResponder
4686 NSTRACE
(acceptsFirstResponder
);
4691 - (void
)resetCursorRects
4693 NSRect visible
= [self visibleRect
];
4694 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4695 NSTRACE
(resetCursorRects
);
4697 if (currentCursor
== nil
)
4698 currentCursor
= [NSCursor arrowCursor
];
4700 if (!NSIsEmptyRect
(visible
))
4701 [self addCursorRect
: visible cursor
: currentCursor
];
4702 [currentCursor setOnMouseEntered
: YES
];
4707 /*****************************************************************************/
4708 /* Keyboard handling. */
4711 - (void
)keyDown
: (NSEvent
*)theEvent
4713 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
4715 unsigned fnKeysym
= 0;
4717 static NSMutableArray
*nsEvArray
;
4718 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4719 static BOOL firstTime
= YES
;
4725 /* Rhapsody and OS X give up and down events for the arrow keys */
4726 if (ns_fake_keydown
== YES
)
4727 ns_fake_keydown
= NO
;
4728 else if ([theEvent
type] != NSKeyDown
)
4734 if (![[self window
] isKeyWindow
]
4735 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4736 /* we must avoid an infinite loop here. */
4737 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4739 /* XXX: There is an occasional condition in which, when Emacs display
4740 updates a different frame from the current one, and temporarily
4741 selects it, then processes some interrupt-driven input
4742 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4743 for some reason that window has its first responder set to the NSView
4744 most recently updated (I guess), which is not the correct one. */
4745 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4749 if (nsEvArray
== nil
)
4750 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4752 [NSCursor setHiddenUntilMouseMoves
: YES
];
4754 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4756 clear_mouse_face
(hlinfo
);
4757 hlinfo
->mouse_face_hidden
= 1;
4760 if (!processingCompose
)
4762 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4763 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4764 /* (Carbon way: [theEvent keyCode]) */
4766 /* is it a "function key"? */
4767 fnKeysym
= ns_convert_key
(code
);
4770 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4771 because Emacs treats Delete and KP-Delete same (in simple.el). */
4772 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4773 code
= 0xFF08; /* backspace */
4778 /* are there modifiers? */
4779 emacs_event
->modifiers
= 0;
4780 flags
= [theEvent modifierFlags
];
4782 if (flags
& NSHelpKeyMask
)
4783 emacs_event
->modifiers |
= hyper_modifier
;
4785 if (flags
& NSShiftKeyMask
)
4786 emacs_event
->modifiers |
= shift_modifier
;
4788 if ((flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
)
4789 emacs_event
->modifiers |
= parse_solitary_modifier
4790 (EQ
(ns_right_command_modifier
, Qleft
)
4791 ? ns_command_modifier
4792 : ns_right_command_modifier
);
4794 if ((flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
)
4796 emacs_event
->modifiers |
= parse_solitary_modifier
4797 (ns_command_modifier
);
4799 /* if super (default), take input manager's word so things like
4800 dvorak / qwerty layout work */
4801 if (EQ
(ns_command_modifier
, Qsuper
)
4803 && [[theEvent characters
] length] != 0)
4805 /* XXX: the code we get will be unshifted, so if we have
4806 a shift modifier, must convert ourselves */
4807 if (!(flags
& NSShiftKeyMask
))
4808 code
= [[theEvent characters
] characterAtIndex
: 0];
4810 /* this is ugly and also requires linking w/Carbon framework
4811 (for LMGetKbdType) so for now leave this rare (?) case
4812 undealt with.. in future look into CGEvent methods */
4815 long smv
= GetScriptManagerVariable
(smKeyScript
);
4816 Handle uchrHandle
= GetResource
4817 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4819 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4820 [[theEvent characters
] characterAtIndex
: 0],
4821 kUCKeyActionDisplay
,
4822 (flags
& ~NSCommandKeyMask
) >> 8,
4823 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4824 &dummy
, 1, &dummy
, &code
);
4831 if ((flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
)
4832 emacs_event
->modifiers |
= parse_solitary_modifier
4833 (EQ
(ns_right_control_modifier
, Qleft
)
4834 ? ns_control_modifier
4835 : ns_right_control_modifier
);
4837 if ((flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
)
4838 emacs_event
->modifiers |
= parse_solitary_modifier
4839 (ns_control_modifier
);
4841 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4842 emacs_event
->modifiers |
=
4843 parse_solitary_modifier
(ns_function_modifier
);
4845 left_is_none
= NILP
(ns_alternate_modifier
)
4846 || EQ
(ns_alternate_modifier
, Qnone
);
4848 if ((flags
& NSRightAlternateKeyMask
) == NSRightAlternateKeyMask
)
4850 if ((NILP
(ns_right_alternate_modifier
)
4851 || EQ
(ns_right_alternate_modifier
, Qnone
)
4852 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
4854 { /* accept pre-interp alt comb */
4855 if ([[theEvent characters
] length] > 0)
4856 code
= [[theEvent characters
] characterAtIndex
: 0];
4857 /*HACK: clear lone shift modifier to stop next if from firing */
4858 if (emacs_event
->modifiers
== shift_modifier
)
4859 emacs_event
->modifiers
= 0;
4862 emacs_event
->modifiers |
= parse_solitary_modifier
4863 (EQ
(ns_right_alternate_modifier
, Qleft
)
4864 ? ns_alternate_modifier
4865 : ns_right_alternate_modifier
);
4868 if ((flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
) /* default = meta */
4870 if (left_is_none
&& !fnKeysym
)
4871 { /* accept pre-interp alt comb */
4872 if ([[theEvent characters
] length] > 0)
4873 code
= [[theEvent characters
] characterAtIndex
: 0];
4874 /*HACK: clear lone shift modifier to stop next if from firing */
4875 if (emacs_event
->modifiers
== shift_modifier
)
4876 emacs_event
->modifiers
= 0;
4879 emacs_event
->modifiers |
=
4880 parse_solitary_modifier
(ns_alternate_modifier
);
4884 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4885 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4887 /* if it was a function key or had modifiers, pass it directly to emacs */
4888 if (fnKeysym ||
(emacs_event
->modifiers
4889 && (emacs_event
->modifiers
!= shift_modifier
)
4890 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4891 /*[[theEvent characters] length] */
4893 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4895 code |
= (1<<28)|
(3<<16);
4896 else if (code
== 0x7f)
4897 code |
= (1<<28)|
(3<<16);
4899 emacs_event
->kind
= code
> 0xFF
4900 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4902 emacs_event
->code
= code
;
4903 EV_TRAILER
(theEvent
);
4909 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4910 /* if we get here we should send the key for input manager processing */
4911 if (firstTime
&& [[NSInputManager currentInputManager
]
4912 wantsToDelayTextChangeNotifications
] == NO
)
4914 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
4917 if (NS_KEYLOG
&& !processingCompose
)
4918 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
4920 processingCompose
= YES
;
4921 [nsEvArray addObject
: theEvent
];
4922 [self interpretKeyEvents
: nsEvArray
];
4923 [nsEvArray removeObject
: theEvent
];
4927 #ifdef NS_IMPL_COCOA
4928 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
4929 decided not to send key-down for.
4930 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
4931 This only applies on Tiger and earlier.
4932 If it matches one of these, send it on to keyDown. */
4933 -(void
)keyUp
: (NSEvent
*)theEvent
4935 int flags
= [theEvent modifierFlags
];
4936 int code
= [theEvent keyCode
];
4937 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
4938 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
4941 fprintf (stderr
, "keyUp
: passed test"
);
4942 ns_fake_keydown
= YES
;
4943 [self keyDown
: theEvent
];
4949 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
4952 /* <NSTextInput>: called when done composing;
4953 NOTE: also called when we delete over working text, followed immed.
4954 by doCommandBySelector: deleteBackward: */
4955 - (void
)insertText
: (id
)aString
4958 int len
= [(NSString
*)aString
length];
4962 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
4963 processingCompose
= NO
;
4968 /* first, clear any working text */
4969 if (workingText
!= nil
)
4970 [self deleteWorkingText
];
4972 /* now insert the string as keystrokes */
4973 for (i
=0; i
<len
; i
++)
4975 code
= [aString characterAtIndex
: i
];
4976 /* TODO: still need this? */
4978 code
= '~'; /* 0x7E */
4979 emacs_event
->modifiers
= 0;
4981 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4982 emacs_event
->code
= code
;
4983 EV_TRAILER
((id
)nil
);
4988 /* <NSTextInput>: inserts display of composing characters */
4989 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
4991 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
4992 [aString string
] : aString
;
4994 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
4995 selRange.
length, selRange.location
);
4997 if (workingText
!= nil
)
4998 [self deleteWorkingText
];
4999 if ([str
length] == 0)
5005 processingCompose
= YES
;
5006 workingText
= [str copy
];
5007 ns_working_text
= build_string
([workingText UTF8String
]);
5009 emacs_event
->kind
= NS_TEXT_EVENT
;
5010 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
5011 EV_TRAILER
((id
)nil
);
5015 /* delete display of composing characters [not in <NSTextInput>] */
5016 - (void
)deleteWorkingText
5018 if (workingText
== nil
)
5021 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
5022 [workingText release
];
5024 processingCompose
= NO
;
5029 emacs_event
->kind
= NS_TEXT_EVENT
;
5030 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5031 EV_TRAILER
((id
)nil
);
5035 - (BOOL
)hasMarkedText
5037 return workingText
!= nil
;
5041 - (NSRange
)markedRange
5043 NSRange rng
= workingText
!= nil
5044 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5046 NSLog
(@"markedRange request"
);
5054 NSLog
(@"unmark
(accept
) text"
);
5055 [self deleteWorkingText
];
5056 processingCompose
= NO
;
5060 /* used to position char selection windows, etc. */
5061 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5065 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5067 NSLog
(@"firstRectForCharRange request"
);
5069 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5070 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5071 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5072 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5073 +FRAME_LINE_HEIGHT
(emacsframe
));
5075 pt
= [self convertPoint
: pt toView
: nil
];
5076 pt
= [[self window
] convertBaseToScreen
: pt
];
5082 - (long)conversationIdentifier
5088 - (void
)doCommandBySelector
: (SEL
)aSelector
5091 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5093 if (aSelector
== @selector
(deleteBackward
:))
5095 /* happens when user backspaces over an ongoing composition:
5096 throw a 'delete' into the event queue */
5099 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5100 emacs_event
->code
= 0xFF08;
5101 EV_TRAILER
((id
)nil
);
5105 - (NSArray
*)validAttributesForMarkedText
5107 static NSArray
*arr
= nil
;
5108 if (arr
== nil
) arr
= [NSArray new
];
5109 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5113 - (NSRange
)selectedRange
5116 NSLog
(@"selectedRange request"
);
5117 return NSMakeRange
(NSNotFound
, 0);
5120 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5123 NSLog
(@"characterIndexForPoint request"
);
5127 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5129 static NSAttributedString
*str
= nil
;
5130 if (str
== nil
) str
= [NSAttributedString new
];
5132 NSLog
(@"attributedSubstringFromRange request"
);
5136 /* End <NSTextInput> impl. */
5137 /*****************************************************************************/
5140 /* This is what happens when the user presses a mouse button. */
5141 - (void
)mouseDown
: (NSEvent
*)theEvent
5143 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5146 NSTRACE
(mouseDown
);
5148 [self deleteWorkingText
];
5153 last_mouse_frame
= emacsframe
;
5154 /* appears to be needed to prevent spurious movement events generated on
5156 last_mouse_frame
->mouse_moved
= 0;
5158 if ([theEvent
type] == NSScrollWheel
)
5160 float delta
= [theEvent deltaY
];
5161 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5164 emacs_event
->kind
= WHEEL_EVENT
;
5165 emacs_event
->code
= 0;
5166 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5167 ((delta
> 0) ? up_modifier
: down_modifier
);
5171 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5172 emacs_event
->code
= EV_BUTTON
(theEvent
);
5173 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5174 | EV_UDMODIFIERS
(theEvent
);
5176 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5177 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5178 EV_TRAILER
(theEvent
);
5182 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5184 NSTRACE
(rightMouseDown
);
5185 [self mouseDown
: theEvent
];
5189 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5191 NSTRACE
(otherMouseDown
);
5192 [self mouseDown
: theEvent
];
5196 - (void
)mouseUp
: (NSEvent
*)theEvent
5199 [self mouseDown
: theEvent
];
5203 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5205 NSTRACE
(rightMouseUp
);
5206 [self mouseDown
: theEvent
];
5210 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5212 NSTRACE
(otherMouseUp
);
5213 [self mouseDown
: theEvent
];
5217 - (void
) scrollWheel
: (NSEvent
*)theEvent
5219 NSTRACE
(scrollWheel
);
5220 [self mouseDown
: theEvent
];
5224 /* Tell emacs the mouse has moved. */
5225 - (void
)mouseMoved
: (NSEvent
*)e
5227 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5230 // NSTRACE
(mouseMoved
);
5232 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5233 last_mouse_motion_position
5234 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5236 /* update any mouse face */
5237 if (hlinfo
->mouse_face_hidden
)
5239 hlinfo
->mouse_face_hidden
= 0;
5240 clear_mouse_face
(hlinfo
);
5243 /* tooltip handling */
5244 previous_help_echo_string
= help_echo_string
;
5245 help_echo_string
= Qnil
;
5247 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
5248 last_mouse_motion_position.y
))
5249 help_echo_string
= previous_help_echo_string
;
5251 XSETFRAME
(frame
, emacsframe
);
5252 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5254 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5255 (note_mouse_highlight), which is called through the
5256 note_mouse_movement () call above */
5257 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5258 help_echo_object
, help_echo_pos
);
5262 help_echo_string
= Qnil
;
5263 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5266 if (emacsframe
->mouse_moved
&& send_appdefined
)
5267 ns_send_appdefined
(-1);
5271 - (void
)mouseDragged
: (NSEvent
*)e
5273 NSTRACE
(mouseDragged
);
5274 [self mouseMoved
: e
];
5278 - (void
)rightMouseDragged
: (NSEvent
*)e
5280 NSTRACE
(rightMouseDragged
);
5281 [self mouseMoved
: e
];
5285 - (void
)otherMouseDragged
: (NSEvent
*)e
5287 NSTRACE
(otherMouseDragged
);
5288 [self mouseMoved
: e
];
5292 - (BOOL
)windowShouldClose
: (id
)sender
5294 NSEvent
*e
=[[self window
] currentEvent
];
5296 NSTRACE
(windowShouldClose
);
5297 windowClosing
= YES
;
5300 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5301 emacs_event
->modifiers
= 0;
5302 emacs_event
->code
= 0;
5304 /* Don't close this window, let this be done from lisp code. */
5309 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5310 /* normalize frame to gridded text size */
5312 NSTRACE
(windowWillResize
);
5313 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5315 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5316 #ifdef NS_IMPL_GNUSTEP
5317 frameSize.width
+ 3);
5321 if (cols
< MINWIDTH
)
5324 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5325 #ifdef NS_IMPL_GNUSTEP
5326 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5327 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5329 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5330 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5332 if (rows
< MINHEIGHT
)
5334 #ifdef NS_IMPL_COCOA
5336 /* this sets window title to have size in it; the wm does this under GS */
5337 NSRect r
= [[self window
] frame
];
5338 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5349 NSWindow
*window
= [self window
];
5352 const
char *t
= [[[self window
] title] UTF8String
];
5353 char *pos
= strstr
(t
, " — "
);
5356 old_title
= xstrdup
(t
);
5358 size_title
= xmalloc
(strlen
(old_title
) + 40);
5359 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5360 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5365 #endif
/* NS_IMPL_COCOA */
5366 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5372 - (void
)windowDidResize
: (NSNotification
*)notification
5374 NSWindow
*theWindow
= [notification object
];
5376 #ifdef NS_IMPL_GNUSTEP
5377 /* in GNUstep, at least currently, it's possible to get a didResize
5378 without getting a willResize.. therefore we need to act as if we got
5379 the willResize now */
5380 NSSize sz
= [theWindow frame
].
size;
5381 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5382 #endif
/* NS_IMPL_GNUSTEP */
5384 NSTRACE
(windowDidResize
);
5385 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5387 #ifdef NS_IMPL_COCOA
5393 #endif
/* NS_IMPL_COCOA */
5395 /* Avoid loop under GNUstep due to call at beginning of this function.
5396 (x_set_window_size causes a resize which causes
5397 a "windowDidResize" which calls x_set_window_size). */
5398 #ifndef NS_IMPL_GNUSTEP
5399 if (cols
> 0 && rows
> 0)
5402 x_set_window_size
(emacsframe
, 0, cols
, rows
);
5405 NSWindow
*window
= [self window
];
5406 NSRect wr
= [window frame
];
5407 FRAME_PIXEL_WIDTH
(emacsframe
) = (int
)wr.
size.width
5408 - emacsframe
->border_width
;
5409 FRAME_PIXEL_HEIGHT
(emacsframe
) = (int
)wr.
size.height
5410 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5411 - FRAME_TOOLBAR_HEIGHT
(emacsframe
);
5412 change_frame_size
(emacsframe
, rows
, cols
, 0, 0, 1);
5413 SET_FRAME_GARBAGED
(emacsframe
);
5414 cancel_mouse_face
(emacsframe
);
5419 ns_send_appdefined
(-1);
5423 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5424 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5426 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5427 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5429 NSTRACE
(windowDidBecomeKey
);
5431 if (emacsframe
!= old_focus
)
5432 dpyinfo
->x_focus_frame
= emacsframe
;
5434 ns_frame_rehighlight
(emacsframe
);
5438 emacs_event
->kind
= FOCUS_IN_EVENT
;
5439 EV_TRAILER
((id
)nil
);
5444 - (void
)windowDidResignKey
: (NSNotification
*)notification
5445 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5447 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5448 NSTRACE
(windowDidResignKey
);
5450 if (dpyinfo
->x_focus_frame
== emacsframe
)
5451 dpyinfo
->x_focus_frame
= 0;
5453 ns_frame_rehighlight
(emacsframe
);
5455 /* FIXME: for some reason needed on second and subsequent clicks away
5456 from sole-frame Emacs to get hollow box to show */
5457 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5459 x_update_cursor
(emacsframe
, 1);
5460 x_set_frame_alpha
(emacsframe
);
5465 [self deleteWorkingText
];
5466 emacs_event
->kind
= FOCUS_IN_EVENT
;
5467 EV_TRAILER
((id
)nil
);
5472 - (void
)windowWillMiniaturize
: sender
5474 NSTRACE
(windowWillMiniaturize
);
5490 - initFrameFromEmacs
: (struct frame
*)f
5495 NSButton
*toggleButton
;
5496 int vbextra
= NS_SCROLL_BAR_WIDTH
(f
);
5501 NSTRACE
(initFrameFromEmacs
);
5504 processingCompose
= NO
;
5505 scrollbarsNeedingUpdate
= 0;
5507 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5509 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5510 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5511 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5512 [self initWithFrame
: r
];
5513 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5515 FRAME_NS_VIEW
(f
) = self
;
5519 win
= [[EmacsWindow alloc
]
5520 initWithContentRect
: r
5521 styleMask
: (NSResizableWindowMask |
5522 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5523 NSTitledWindowMask |
5525 NSMiniaturizableWindowMask |
5526 NSClosableWindowMask
)
5527 backing
: NSBackingStoreBuffered
5531 f
->border_width
= wr.
size.width
- r.
size.width
;
5532 FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
5534 [win setAcceptsMouseMovedEvents
: YES
];
5535 [win setDelegate
: self
];
5536 [win useOptimizedDrawing
: YES
];
5538 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5539 sz.height
= FRAME_LINE_HEIGHT
(f
);
5540 [win setResizeIncrements
: sz
];
5542 [[win contentView
] addSubview
: self
];
5545 [self registerForDraggedTypes
: ns_drag_types
];
5548 name
= [NSString stringWithUTF8String
:
5549 NILP
(tem
) ?
(unsigned
char *)"Emacs"
: SDATA
(tem
)];
5550 [win setTitle
: name
];
5552 /* toolbar support */
5553 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
5554 [NSString stringWithFormat
: @"Emacs Frame
%d",
5556 [win setToolbar
: toolbar
];
5557 [toolbar setVisible
: NO
];
5558 #ifdef NS_IMPL_COCOA
5559 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
5560 [toggleButton setTarget
: self
];
5561 [toggleButton setAction
: @selector
(toggleToolbar
: )];
5563 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5567 [win setMiniwindowTitle
:
5568 [NSString stringWithUTF8String
: SDATA
(tem
)]];
5571 NSScreen
*screen
= [win screen
];
5574 [win setFrameTopLeftPoint
: NSMakePoint
5575 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
5576 IN_BOUND
(-SCREENMAX
,
5577 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
5580 [win makeFirstResponder
: self
];
5582 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5583 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
5584 [win setBackgroundColor
: col
];
5585 if ([col alphaComponent
] != 1.0)
5586 [win setOpaque
: NO
];
5588 [self allocateGState
];
5590 [NSApp registerServicesMenuSendTypes
: ns_send_types
5598 - (void
)windowDidMove
: sender
5600 NSWindow
*win
= [self window
];
5601 NSRect r
= [win frame
];
5602 NSArray
*screens
= [NSScreen screens
];
5603 NSScreen
*screen
= [screens objectAtIndex
: 0];
5605 NSTRACE
(windowDidMove
);
5607 if (!emacsframe
->output_data.ns
)
5611 emacsframe
->left_pos
= r.origin.x
;
5612 emacsframe
->top_pos
=
5613 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
5618 /* Called AFTER method below, but before our windowWillResize call there leads
5619 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
5620 location so set_window_size moves the frame. */
5621 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5623 emacsframe
->output_data.ns
->zooming
= 1;
5628 /* Override to do something slightly nonstandard, but nice. First click on
5629 zoom button will zoom vertically. Second will zoom completely. Third
5630 returns to original. */
5631 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5632 defaultFrame
:(NSRect
)defaultFrame
5634 NSRect result
= [sender frame
];
5636 NSTRACE
(windowWillUseStandardFrame
);
5638 if (abs (defaultFrame.
size.height
- result.
size.height
)
5639 > FRAME_LINE_HEIGHT
(emacsframe
))
5642 ns_userRect
= result
;
5643 result.
size.height
= defaultFrame.
size.height
;
5644 result.origin.y
= defaultFrame.origin.y
;
5648 if (abs (defaultFrame.
size.width
- result.
size.width
)
5649 > FRAME_COLUMN_WIDTH
(emacsframe
))
5650 result
= defaultFrame
; /* second click */
5654 result
= ns_userRect.
size.height ? ns_userRect
: result
;
5655 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5659 [self windowWillResize
: sender toSize
: result.
size];
5664 - (void
)windowDidDeminiaturize
: sender
5666 NSTRACE
(windowDidDeminiaturize
);
5667 if (!emacsframe
->output_data.ns
)
5669 emacsframe
->async_iconified
= 0;
5670 emacsframe
->async_visible
= 1;
5671 windows_or_buffers_changed
++;
5675 emacs_event
->kind
= ICONIFY_EVENT
;
5676 EV_TRAILER
((id
)nil
);
5681 - (void
)windowDidExpose
: sender
5683 NSTRACE
(windowDidExpose
);
5684 if (!emacsframe
->output_data.ns
)
5686 emacsframe
->async_visible
= 1;
5687 SET_FRAME_GARBAGED
(emacsframe
);
5689 if (send_appdefined
)
5690 ns_send_appdefined
(-1);
5694 - (void
)windowDidMiniaturize
: sender
5696 NSTRACE
(windowDidMiniaturize
);
5697 if (!emacsframe
->output_data.ns
)
5700 emacsframe
->async_iconified
= 1;
5701 emacsframe
->async_visible
= 0;
5705 emacs_event
->kind
= ICONIFY_EVENT
;
5706 EV_TRAILER
((id
)nil
);
5711 - (void
)mouseEntered
: (NSEvent
*)theEvent
5713 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5714 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5715 NSTRACE
(mouseEntered
);
5717 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5721 - (void
)mouseExited
: (NSEvent
*)theEvent
5723 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5725 Mouse_HLInfo
*hlinfo
= emacsframe ? MOUSE_HL_INFO
(emacsframe
) : NULL;
5727 NSTRACE
(mouseExited
);
5732 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5734 if (emacsframe
== hlinfo
->mouse_face_mouse_frame
)
5736 clear_mouse_face
(hlinfo
);
5737 hlinfo
->mouse_face_mouse_frame
= 0;
5745 if (context_menu_value
== -1)
5746 context_menu_value
= [sender tag
];
5748 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
5749 emacsframe
->menu_bar_vector
,
5750 (void
*)[sender tag
]);
5751 ns_send_appdefined
(-1);
5756 - (EmacsToolbar
*)toolbar
5762 /* this gets called on toolbar button click */
5763 - toolbarClicked
: (id
)item
5766 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
5768 NSTRACE
(toolbarClicked
);
5773 /* send first event (for some reason two needed) */
5774 theEvent
= [[self window
] currentEvent
];
5775 emacs_event
->kind
= TOOL_BAR_EVENT
;
5776 XSETFRAME
(emacs_event
->arg
, emacsframe
);
5777 EV_TRAILER
(theEvent
);
5779 emacs_event
->kind
= TOOL_BAR_EVENT
;
5780 /* XSETINT (emacs_event->code, 0); */
5781 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
5782 idx
+ TOOL_BAR_ITEM_KEY
);
5783 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5784 EV_TRAILER
(theEvent
);
5789 - toggleToolbar
: (id
)sender
5794 emacs_event
->kind
= NS_NONKEY_EVENT
;
5795 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
5796 EV_TRAILER
((id
)nil
);
5801 - (void
)drawRect
: (NSRect
)rect
5803 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
5804 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
5808 if (!emacsframe ||
!emacsframe
->output_data.ns || ns_in_resize
)
5811 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
5812 expose_frame
(emacsframe
, x
, y
, width
, height
);
5815 drawRect: may be called (at least in OS X 10.5) for invisible
5816 views as well for some reason. Thus, do not infer visibility
5819 emacsframe->async_visible = 1;
5820 emacsframe->async_iconified = 0;
5825 /* NSDraggingDestination protocol methods. Actually this is not really a
5826 protocol, but a category of Object. O well... */
5828 -(NSUInteger
) draggingEntered
: (id
<NSDraggingInfo
>) sender
5830 NSTRACE
(draggingEntered
);
5831 return NSDragOperationGeneric
;
5835 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
5841 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
5846 NSEvent
*theEvent
= [[self window
] currentEvent
];
5849 NSTRACE
(performDragOperation
);
5854 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
5855 x
= lrint
(position.x
); y
= lrint
(position.y
);
5857 pb
= [sender draggingPasteboard
];
5858 type = [pb availableTypeFromArray
: ns_drag_types
];
5863 else if ([type isEqualToString
: NSFilenamesPboardType
])
5866 NSEnumerator
*fenum
;
5869 if (!(files
= [pb propertyListForType
: type]))
5872 fenum
= [files objectEnumerator
];
5873 while ( (file
= [fenum nextObject
]) )
5875 emacs_event
->kind
= NS_NONKEY_EVENT
;
5876 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5877 XSETINT
(emacs_event
->x
, x
);
5878 XSETINT
(emacs_event
->y
, y
);
5879 ns_input_file
= append2
(ns_input_file
,
5880 build_string
([file UTF8String
]));
5881 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5882 EV_TRAILER
(theEvent
);
5886 else if ([type isEqualToString
: NSURLPboardType
])
5891 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
5892 [fileURL isFileURL
] == NO
)
5895 file
= [fileURL
path];
5896 emacs_event
->kind
= NS_NONKEY_EVENT
;
5897 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5898 XSETINT
(emacs_event
->x
, x
);
5899 XSETINT
(emacs_event
->y
, y
);
5900 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
5901 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5902 EV_TRAILER
(theEvent
);
5905 else if ([type isEqualToString
: NSStringPboardType
]
5906 ||
[type isEqualToString
: NSTabularTextPboardType
])
5910 if (! (data
= [pb stringForType
: type]))
5913 emacs_event
->kind
= NS_NONKEY_EVENT
;
5914 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
5915 XSETINT
(emacs_event
->x
, x
);
5916 XSETINT
(emacs_event
->y
, y
);
5917 ns_input_text
= build_string
([data UTF8String
]);
5918 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5919 EV_TRAILER
(theEvent
);
5922 else if ([type isEqualToString
: NSColorPboardType
])
5924 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
5925 emacs_event
->kind
= NS_NONKEY_EVENT
;
5926 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
5927 XSETINT
(emacs_event
->x
, x
);
5928 XSETINT
(emacs_event
->y
, y
);
5929 ns_input_color
= ns_color_to_lisp
(c
);
5930 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5931 EV_TRAILER
(theEvent
);
5934 else if ([type isEqualToString
: NSFontPboardType
])
5936 /* impl based on GNUstep NSTextView.m */
5937 NSData
*data
= [pb dataForType
: NSFontPboardType
];
5938 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
5939 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
5945 emacs_event
->kind
= NS_NONKEY_EVENT
;
5946 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
5947 XSETINT
(emacs_event
->x
, x
);
5948 XSETINT
(emacs_event
->y
, y
);
5949 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
5950 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
5951 ns_input_fontsize
= build_string
(fontSize
);
5952 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5953 EV_TRAILER
(theEvent
);
5958 error ("Invalid data
type in dragging pasteboard."
);
5964 - (id
) validRequestorForSendType
: (NSString
*)typeSent
5965 returnType
: (NSString
*)typeReturned
5967 NSTRACE
(validRequestorForSendType
);
5968 if (typeSent
!= nil
&& [ns_send_types indexOfObject
: typeSent
] != NSNotFound
5969 && typeReturned
== nil
)
5971 if (! NILP
(ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
)))
5975 return [super validRequestorForSendType
: typeSent
5976 returnType
: typeReturned
];
5980 /* The next two methods are part of NSServicesRequests informal protocol,
5981 supposedly called when a services menu item is chosen from this app.
5982 But this should not happen because we override the services menu with our
5983 own entries which call ns-perform-service.
5984 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
5985 So let's at least stub them out until further investigation can be done. */
5987 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
5989 /* we could call ns_string_from_pasteboard(pboard) here but then it should
5990 be written into the buffer in place of the existing selection..
5991 ordinary service calls go through functions defined in ns-win.el */
5995 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
5997 NSArray
*typesDeclared
;
6000 /* We only support NSStringPboardType */
6001 if ([types containsObject
:NSStringPboardType
] == NO
) {
6005 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6006 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
6009 if (CONSP
(val
) && NILP
(XCDR
(val
)))
6012 if (! STRINGP
(val
))
6015 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
6016 [pb declareTypes
:typesDeclared owner
:nil
];
6017 ns_string_to_pasteboard
(pb
, val
);
6022 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
6023 (gives a miniaturized version of the window); currently we use the latter for
6024 frames whose active buffer doesn't correspond to any file
6025 (e.g., '*scratch*') */
6026 - setMiniwindowImage
: (BOOL
) setMini
6028 id
image = [[self window
] miniwindowImage
];
6029 NSTRACE
(setMiniwindowImage
);
6031 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6032 about "AppleDockIconEnabled" notwithstanding, however the set message
6033 below has its effect nonetheless. */
6034 if (image != emacsframe
->output_data.ns
->miniimage
)
6036 if (image && [image isKindOfClass
: [EmacsImage
class]])
6038 [[self window
] setMiniwindowImage
:
6039 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6046 - (void
) setRows
: (int
) r andColumns
: (int
) c
6052 @
end /* EmacsView */
6056 /* ==========================================================================
6058 EmacsWindow implementation
6060 ========================================================================== */
6062 @implementation EmacsWindow
6064 /* If we have multiple monitors, one above the other, we don't want to
6065 restrict the height to just one monitor. So we override this. */
6066 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6068 /* When making the frame visible for the first time or if there is just
6069 one screen, we want to constrain. Other times not. */
6070 NSUInteger nr_screens
= [[NSScreen screens
] count
];
6071 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6072 NSTRACE
(constrainFrameRect
);
6074 if (nr_screens
== 1)
6075 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6077 if (f
->output_data.ns
->dont_constrain
6078 || ns_menu_bar_should_be_hidden
())
6081 f
->output_data.ns
->dont_constrain
= 1;
6082 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6086 /* called only on resize clicks by special case in EmacsApp-sendEvent */
6087 - (void
)mouseDown
: (NSEvent
*)theEvent
6091 NSSize
size = [[theEvent window
] frame
].
size;
6092 grabOffset
= [theEvent locationInWindow
];
6093 grabOffset.x
= size.width
- grabOffset.x
;
6096 [super mouseDown
: theEvent
];
6101 - (void
)mouseUp
: (NSEvent
*)theEvent
6105 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6107 ns_set_name_as_filename
(f
);
6109 ns_send_appdefined
(-1);
6112 [super mouseUp
: theEvent
];
6116 /* send resize events */
6117 - (void
)mouseDragged
: (NSEvent
*)theEvent
6121 NSPoint p
= [theEvent locationInWindow
];
6122 NSSize
size, vettedSize
, origSize
= [self frame
].
size;
6124 size.width
= p.x
+ grabOffset.x
;
6125 size.height
= origSize.height
- p.y
+ grabOffset.y
;
6127 if (size.width
== origSize.width
&& size.height
== origSize.height
)
6130 vettedSize
= [[self delegate
] windowWillResize
: self toSize
: size];
6131 [[NSNotificationCenter defaultCenter
]
6132 postNotificationName
: NSWindowDidResizeNotification
6136 [super mouseDragged
: theEvent
];
6139 @
end /* EmacsWindow */
6142 /* ==========================================================================
6144 EmacsScroller implementation
6146 ========================================================================== */
6149 @implementation EmacsScroller
6151 /* for repeat button push */
6152 #define SCROLL_BAR_FIRST_DELAY
0.5
6153 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6155 + (CGFloat
) scrollerWidth
6157 /* TODO: if we want to allow variable widths, this is the place to do it,
6158 however neither GNUstep nor Cocoa support it very well */
6159 return [NSScroller scrollerWidth
];
6163 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
6165 NSTRACE
(EmacsScroller_initFrame
);
6167 r.
size.width
= [EmacsScroller scrollerWidth
];
6168 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
6169 [self setContinuous
: YES
];
6170 [self setEnabled
: YES
];
6172 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
6173 locked against the top and bottom edges, and right edge on OS X, where
6174 scrollers are on right. */
6175 #ifdef NS_IMPL_GNUSTEP
6176 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
6178 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
6183 pixel_height
= NSHeight
(r
);
6184 if (pixel_height
== 0) pixel_height
= 1;
6185 min_portion
= 20 / pixel_height
;
6187 frame
= XFRAME
(XWINDOW
(win
)->frame
);
6188 if (FRAME_LIVE_P
(frame
))
6191 EmacsView
*view = FRAME_NS_VIEW
(frame
);
6192 NSView
*sview
= [[view window
] contentView
];
6193 NSArray
*subs
= [sview subviews
];
6195 /* disable optimization stopping redraw of other scrollbars */
6196 view->scrollbarsNeedingUpdate
= 0;
6197 for (i
=[subs count
]-1; i
>= 0; i
--)
6198 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
6199 view->scrollbarsNeedingUpdate
++;
6200 [sview addSubview
: self
];
6203 /* [self setFrame: r]; */
6209 - (void
)setFrame
: (NSRect
)newRect
6211 NSTRACE
(EmacsScroller_setFrame
);
6213 pixel_height
= NSHeight
(newRect
);
6214 if (pixel_height
== 0) pixel_height
= 1;
6215 min_portion
= 20 / pixel_height
;
6216 [super setFrame
: newRect
];
6218 /* UNBLOCK_INPUT; */
6224 NSTRACE
(EmacsScroller_dealloc
);
6226 XWINDOW
(win
)->vertical_scroll_bar
= Qnil
;
6254 /* ensure other scrollbar updates after deletion */
6255 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6257 view->scrollbarsNeedingUpdate
++;
6258 [self removeFromSuperview
];
6266 - (void
)resetCursorRects
6268 NSRect visible
= [self visibleRect
];
6269 NSTRACE
(resetCursorRects
);
6271 if (!NSIsEmptyRect
(visible
))
6272 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
6273 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
6277 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
6280 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
6281 && portion
!= whole
; /* needed for resize empty buf */
6285 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
6287 NSTRACE
(setPosition
);
6289 em_position
= position
;
6290 em_portion
= portion
;
6293 if (portion
>= whole
)
6295 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6296 [self setKnobProportion
: 1.0];
6297 [self setDoubleValue
: 1.0];
6299 [self setFloatValue
: 0.0 knobProportion
: 1.0];
6305 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
6306 pos
= (float
)position
/ (whole
- portion
);
6307 por
= (float
)portion
/whole
;
6308 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6309 [self setKnobProportion
: por
];
6310 [self setDoubleValue
: pos
];
6312 [self setFloatValue
: pos knobProportion
: por
];
6318 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
6319 drag events will go directly to the EmacsScroller. Leaving in for now. */
6320 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
6321 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
6323 *part
= last_hit_part
;
6325 XSETINT
(*y
, pixel_height
);
6326 if ([self floatValue
] > 0.999)
6327 XSETINT
(*x
, pixel_height
);
6329 XSETINT
(*x
, pixel_height
* [self floatValue
]);
6333 /* set up emacs_event */
6334 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
6339 emacs_event
->part
= last_hit_part
;
6340 emacs_event
->code
= 0;
6341 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
6342 emacs_event
->frame_or_window
= win
;
6343 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
6344 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
6345 emacs_event
->arg
= Qnil
;
6346 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
6347 XSETINT
(emacs_event
->y
, pixel_height
-20);
6349 n_emacs_events_pending
++;
6350 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
6351 EVENT_INIT
(*emacs_event
);
6352 ns_send_appdefined
(-1);
6356 /* called manually thru timer to implement repeated button action w/hold-down */
6357 - repeatScroll
: (NSTimer
*)scrollEntry
6359 NSEvent
*e
= [[self window
] currentEvent
];
6360 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
6361 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
6363 /* clear timer if need be */
6364 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
6366 [scroll_repeat_entry invalidate
];
6367 [scroll_repeat_entry release
];
6368 scroll_repeat_entry
= nil
;
6374 = [[NSTimer scheduledTimerWithTimeInterval
:
6375 SCROLL_BAR_CONTINUOUS_DELAY
6377 selector
: @selector
(repeatScroll
:)
6383 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
6388 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
6389 mouseDragged events without going into a modal loop. */
6390 - (void
)mouseDown
: (NSEvent
*)e
6393 /* hitPart is only updated AFTER event is passed on */
6394 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6395 double inc
= 0.0, loc
, kloc
, pos
;
6398 NSTRACE
(EmacsScroller_mouseDown
);
6402 case NSScrollerDecrementPage
:
6403 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6404 case NSScrollerIncrementPage
:
6405 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6406 case NSScrollerDecrementLine
:
6407 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6408 case NSScrollerIncrementLine
:
6409 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6410 case NSScrollerKnob
:
6411 last_hit_part
= scroll_bar_handle
; break;
6412 case NSScrollerKnobSlot
: /* GNUstep-only */
6413 last_hit_part
= scroll_bar_move_ratio
; break;
6414 default
: /* NSScrollerNoPart? */
6415 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
6422 pos
= 0; /* ignored */
6424 /* set a timer to repeat, as we can't let superclass do this modally */
6426 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
6428 selector
: @selector
(repeatScroll
:)
6435 /* handle, or on GNUstep possibly slot */
6436 NSEvent
*fake_event
;
6438 /* compute float loc in slot and mouse offset on knob */
6439 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6441 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6447 else if (loc
>= NSHeight
(sr
))
6449 loc
= NSHeight
(sr
);
6457 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6459 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6461 last_mouse_offset
= kloc
;
6463 /* if knob, tell emacs a location offset by knob pos
6464 (to indicate top of handle) */
6465 if (part
== NSScrollerKnob
)
6466 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6468 /* else this is a slot click on GNUstep: go straight there */
6469 pos
= loc
/ NSHeight
(sr
);
6471 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6472 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6473 location
: [e locationInWindow
]
6474 modifierFlags
: [e modifierFlags
]
6475 timestamp
: [e timestamp
]
6476 windowNumber
: [e windowNumber
]
6477 context
: [e context
]
6478 eventNumber
: [e eventNumber
]
6479 clickCount
: [e clickCount
]
6480 pressure
: [e pressure
]];
6481 [super mouseUp
: fake_event
];
6484 if (part
!= NSScrollerKnob
)
6485 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6489 /* Called as we manually track scroller drags, rather than superclass. */
6490 - (void
)mouseDragged
: (NSEvent
*)e
6496 NSTRACE
(EmacsScroller_mouseDragged
);
6498 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6500 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6507 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6509 loc
= NSHeight
(sr
) + last_mouse_offset
;
6513 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6514 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6518 - (void
)mouseUp
: (NSEvent
*)e
6520 if (scroll_repeat_entry
)
6522 [scroll_repeat_entry invalidate
];
6523 [scroll_repeat_entry release
];
6524 scroll_repeat_entry
= nil
;
6530 /* treat scrollwheel events in the bar as though they were in the main window */
6531 - (void
) scrollWheel
: (NSEvent
*)theEvent
6533 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6534 [view mouseDown
: theEvent
];
6537 @
end /* EmacsScroller */
6542 /* ==========================================================================
6544 Font-related functions; these used to be in nsfaces.m
6546 ========================================================================== */
6550 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6552 struct font
*font
= XFONT_OBJECT
(font_object
);
6555 fontset
= fontset_from_font
(font_object
);
6556 FRAME_FONTSET
(f
) = fontset
;
6558 if (FRAME_FONT
(f
) == font
)
6559 /* This font is already set in frame F. There's nothing more to
6563 FRAME_FONT
(f
) = font
;
6565 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6566 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6567 FRAME_SPACE_WIDTH
(f
) = font
->space_width
;
6568 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6570 compute_fringe_widths
(f
, 1);
6572 /* Compute the scroll bar width in character columns. */
6573 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6575 int wid
= FRAME_COLUMN_WIDTH
(f
);
6576 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6577 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6581 int wid
= FRAME_COLUMN_WIDTH
(f
);
6582 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6585 /* Now make the frame display the given font. */
6586 if (FRAME_NS_WINDOW
(f
) != 0)
6587 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6593 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6594 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6598 ns_xlfd_to_fontname
(const
char *xlfd
)
6599 /* --------------------------------------------------------------------------
6600 Convert an X font name (XLFD) to an NS font name.
6601 Only family is used.
6602 The string returned is temporarily allocated.
6603 -------------------------------------------------------------------------- */
6605 char *name
= xmalloc
(180);
6609 if (!strncmp
(xlfd
, "
--"
, 2))
6610 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
6612 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
6614 /* stopgap for malformed XLFD input */
6615 if (strlen
(name
) == 0)
6616 strcpy
(name
, "Monaco"
);
6618 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
6619 also uppercase after '-' or ' ' */
6620 name
[0] = toupper
(name
[0]);
6621 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
6627 name
[i
+1] = toupper
(name
[i
+1]);
6629 else if (name
[i
] == '_')
6633 name
[i
+1] = toupper
(name
[i
+1]);
6636 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
6637 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
6644 syms_of_nsterm
(void
)
6646 NSTRACE
(syms_of_nsterm
);
6648 ns_antialias_threshold
= 10.0;
6650 /* from 23+ we need to tell emacs what modifiers there are.. */
6651 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
6652 DEFSYM
(Qalt
, "alt"
);
6653 DEFSYM
(Qhyper
, "hyper"
);
6654 DEFSYM
(Qmeta
, "
meta"
);
6655 DEFSYM
(Qsuper
, "super"
);
6656 DEFSYM
(Qcontrol
, "control"
);
6657 DEFSYM
(Qnone
, "none"
);
6658 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
6660 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
6661 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
6662 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
6663 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
6664 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
6666 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
6667 "The file specified in the last NS event."
);
6668 ns_input_file
=Qnil
;
6670 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
6671 "The data received in the last NS
text drag event."
);
6672 ns_input_text
=Qnil
;
6674 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
6675 "String
for visualizing working composition sequence."
);
6676 ns_working_text
=Qnil
;
6678 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
6679 "The font specified in the last NS event."
);
6680 ns_input_font
=Qnil
;
6682 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
6683 "The fontsize specified in the last NS event."
);
6684 ns_input_fontsize
=Qnil
;
6686 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
6687 "The
line specified in the last NS event."
);
6688 ns_input_line
=Qnil
;
6690 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
6691 "The color specified in the last NS event."
);
6692 ns_input_color
=Qnil
;
6694 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
6695 "The service name specified in the last NS event."
);
6696 ns_input_spi_name
=Qnil
;
6698 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
6699 "The service argument specified in the last NS event."
);
6700 ns_input_spi_arg
=Qnil
;
6702 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
6703 "This variable describes the behavior of the alternate or option key.
\n\
6704 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6705 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
6706 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6707 ns_alternate_modifier
= Qmeta
;
6709 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
6710 "This variable describes the behavior of the right alternate or option key.
\n\
6711 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6712 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
6713 Set to none means that the alternate / option key is not interpreted by Emacs\n\
6714 at all, allowing it to be used at a lower level for accented character entry.");
6715 ns_right_alternate_modifier = Qleft;
6717 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
6718 "This variable describes the behavior of the command key.\n\
6719 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
6720 ns_command_modifier = Qsuper;
6722 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
6723 "This variable describes the behavior of the right command key.\n\
6724 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6725 Set to left means be the same key as `ns-command-modifier'.
\n\
6726 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
6727 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6728 ns_right_command_modifier
= Qleft
;
6730 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
6731 "This variable describes the behavior of the control key.
\n\
6732 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
6733 ns_control_modifier
= Qcontrol
;
6735 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
6736 "This variable describes the behavior of the right control key.
\n\
6737 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6738 Set to left means be the same key as `ns
-control
-modifier
'.\n\
6739 Set to none means that the control / option key is not interpreted by Emacs\n\
6740 at all, allowing it to be used at a lower level for accented character entry.");
6741 ns_right_control_modifier = Qleft;
6743 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
6744 "This variable describes the behavior of the function key (on laptops).\n\
6745 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
6746 Set to none means that the function key is not interpreted by Emacs at all,\n\
6747 allowing it to be used at a lower level for accented character entry.");
6748 ns_function_modifier = Qnone;
6750 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
6751 "Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above.");
6752 ns_antialias_text = Qt;
6754 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
6755 "Whether to confirm application quit using dialog.");
6756 ns_confirm_quit = Qnil;
6758 staticpro (&ns_display_name_list);
6759 ns_display_name_list = Qnil;
6761 staticpro (&last_mouse_motion_frame);
6762 last_mouse_motion_frame = Qnil;
6764 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
6765 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
6766 Only works on OSX 10.6 or later. */);
6767 ns_auto_hide_menu_bar = Qnil;
6769 /* TODO: move to common code */
6770 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
6771 doc: /* Which toolkit scroll bars Emacs uses, if any.
6772 A value of nil means Emacs doesn't use toolkit scroll bars.
6773 With the X Window system
, the value is a symbol describing the
6774 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
6775 With MS Windows or Nextstep
, the value is t. */
);
6776 Vx_toolkit_scroll_bars
= Qt
;
6778 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
6779 x_use_underline_position_properties
,
6780 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
6781 A value of nil means ignore them. If you encounter fonts with bogus
6782 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
6783 to 4.1, set this to nil. */);
6784 x_use_underline_position_properties
= 0;
6786 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
6787 x_underline_at_descent_line
,
6788 doc: /* Non-nil means to draw the underline at the same place as the descent line.
6789 A value of nil means to draw the underline according to the value of the
6790 variable `x-use-underline-position-properties', which is usually at the
6791 baseline level. The default value is nil. */);
6792 x_underline_at_descent_line
= 0;
6794 /* Tell emacs about this window system. */
6795 Fprovide
(intern
("ns"
), Qnil
);