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
>
40 #include
<c
-strcase.h
>
48 #include "blockinput.h"
49 #include "sysselect.h"
52 #include "character.h"
54 #include "composite.h"
57 #include "termhooks.h"
67 int term_trace_num
= 0;
68 #define NSTRACE
(x
) fprintf (stderr
, "
%s:%d: [%d] " #x "\n", \
69 __FILE__
, __LINE__
, ++term_trace_num
)
74 #
if defined
(NS_IMPL_COCOA
) && \
75 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
79 extern NSString
*NSMenuDidBeginTrackingNotification
;
81 /* ==========================================================================
85 ========================================================================== */
87 /* Convert a symbol indexed with an NSxxx value to a value as defined
88 in keyboard.c (lispy_function_key). I hope this is a correct way
90 static unsigned convert_ns_to_X_keysym
[] =
92 NSHomeFunctionKey
, 0x50,
93 NSLeftArrowFunctionKey
, 0x51,
94 NSUpArrowFunctionKey
, 0x52,
95 NSRightArrowFunctionKey
, 0x53,
96 NSDownArrowFunctionKey
, 0x54,
97 NSPageUpFunctionKey
, 0x55,
98 NSPageDownFunctionKey
, 0x56,
99 NSEndFunctionKey
, 0x57,
100 NSBeginFunctionKey
, 0x58,
101 NSSelectFunctionKey
, 0x60,
102 NSPrintFunctionKey
, 0x61,
103 NSExecuteFunctionKey
, 0x62,
104 NSInsertFunctionKey
, 0x63,
105 NSUndoFunctionKey
, 0x65,
106 NSRedoFunctionKey
, 0x66,
107 NSMenuFunctionKey
, 0x67,
108 NSFindFunctionKey
, 0x68,
109 NSHelpFunctionKey
, 0x6A,
110 NSBreakFunctionKey
, 0x6B,
112 NSF1FunctionKey
, 0xBE,
113 NSF2FunctionKey
, 0xBF,
114 NSF3FunctionKey
, 0xC0,
115 NSF4FunctionKey
, 0xC1,
116 NSF5FunctionKey
, 0xC2,
117 NSF6FunctionKey
, 0xC3,
118 NSF7FunctionKey
, 0xC4,
119 NSF8FunctionKey
, 0xC5,
120 NSF9FunctionKey
, 0xC6,
121 NSF10FunctionKey
, 0xC7,
122 NSF11FunctionKey
, 0xC8,
123 NSF12FunctionKey
, 0xC9,
124 NSF13FunctionKey
, 0xCA,
125 NSF14FunctionKey
, 0xCB,
126 NSF15FunctionKey
, 0xCC,
127 NSF16FunctionKey
, 0xCD,
128 NSF17FunctionKey
, 0xCE,
129 NSF18FunctionKey
, 0xCF,
130 NSF19FunctionKey
, 0xD0,
131 NSF20FunctionKey
, 0xD1,
132 NSF21FunctionKey
, 0xD2,
133 NSF22FunctionKey
, 0xD3,
134 NSF23FunctionKey
, 0xD4,
135 NSF24FunctionKey
, 0xD5,
137 NSBackspaceCharacter
, 0x08, /* 8: Not on some KBs. */
138 NSDeleteCharacter
, 0xFF, /* 127: Big 'delete' key upper right. */
139 NSDeleteFunctionKey
, 0x9F, /* 63272: Del forw key off main array. */
141 NSTabCharacter
, 0x09,
142 0x19, 0x09, /* left tab->regular since pass shift */
143 NSCarriageReturnCharacter
, 0x0D,
144 NSNewlineCharacter
, 0x0D,
145 NSEnterCharacter
, 0x8D,
147 0x1B, 0x1B /* escape */
150 static Lisp_Object Qmodifier_value
;
151 Lisp_Object Qalt
, Qcontrol
, Qhyper
, Qmeta
, Qsuper
;
152 extern Lisp_Object Qcursor_color
, Qcursor_type
, Qns
, Qleft
;
154 static Lisp_Object QUTF8_STRING
;
156 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
157 the maximum font size to NOT antialias. On GNUstep there is currently
158 no way to control this behavior. */
159 float ns_antialias_threshold
;
161 /* Used to pick up AppleHighlightColor on OS X */
162 NSString
*ns_selection_color
;
164 NSArray
*ns_send_types
=0, *ns_return_types
=0, *ns_drag_types
=0;
165 NSString
*ns_app_name
= @"Emacs"
; /* default changed later */
167 /* Display variables */
168 struct ns_display_info
*x_display_list
; /* Chain of existing displays */
169 Lisp_Object ns_display_name_list
;
170 long context_menu_value
= 0;
173 NSPoint last_mouse_motion_position
;
174 static NSRect last_mouse_glyph
;
175 static Time last_mouse_movement_time
= 0;
176 static Lisp_Object last_mouse_motion_frame
;
177 static EmacsScroller
*last_mouse_scroll_bar
= nil
;
178 static
struct frame
*ns_updating_frame
;
179 static NSView
*focus_view
= NULL;
180 static int ns_window_num
= 0;
181 #ifdef NS_IMPL_GNUSTEP
184 static BOOL gsaved
= NO
;
185 static BOOL ns_fake_keydown
= NO
;
186 int ns_tmp_flags
; /* FIXME */
187 struct nsfont_info
*ns_tmp_font
; /* FIXME */
188 static BOOL ns_menu_bar_is_hidden
= NO
;
189 /*static int debug_lock = 0; */
192 static BOOL send_appdefined
= YES
;
193 static NSEvent
*last_appdefined_event
= 0;
194 static NSTimer
*timed_entry
= 0;
195 static NSTimer
*scroll_repeat_entry
= nil
;
196 static fd_set select_readfds
, select_writefds
;
197 enum
{ SELECT_HAVE_READ
= 1, SELECT_HAVE_WRITE
= 2, SELECT_HAVE_TMO
= 4 };
198 static int select_nfds
= 0, select_valid
= 0;
199 static EMACS_TIME select_timeout
= { 0, 0 };
200 static int selfds
[2] = { -1, -1 };
201 static pthread_mutex_t select_mutex
;
202 static int apploopnr
= 0;
203 static NSAutoreleasePool
*outerpool
;
204 static
struct input_event
*emacs_event
= NULL;
205 static
struct input_event
*q_event_ptr
= NULL;
206 static int n_emacs_events_pending
= 0;
207 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
208 *ns_pending_service_args
;
209 static BOOL ns_do_open_file
= NO
;
211 /* Convert modifiers in a NeXTstep event to emacs style modifiers. */
212 #define NS_FUNCTION_KEY_MASK
0x800000
213 #define NSLeftControlKeyMask
(0x000001 | NSControlKeyMask
)
214 #define NSRightControlKeyMask
(0x002000 | NSControlKeyMask
)
215 #define NSLeftCommandKeyMask
(0x000008 | NSCommandKeyMask
)
216 #define NSRightCommandKeyMask
(0x000010 | NSCommandKeyMask
)
217 #define NSLeftAlternateKeyMask
(0x000020 | NSAlternateKeyMask
)
218 #define NSRightAlternateKeyMask
(0x000040 | NSAlternateKeyMask
)
219 #define EV_MODIFIERS
(e
) \
220 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
221 hyper_modifier
: 0) \
222 |
(!EQ
(ns_right_alternate_modifier
, Qleft
) && \
223 (([e modifierFlags
] & NSRightAlternateKeyMask
) \
224 == NSRightAlternateKeyMask
) ? \
225 parse_solitary_modifier
(ns_right_alternate_modifier
) : 0) \
226 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
227 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
228 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
229 shift_modifier
: 0) \
230 |
(!EQ
(ns_right_control_modifier
, Qleft
) && \
231 (([e modifierFlags
] & NSRightControlKeyMask
) \
232 == NSRightControlKeyMask
) ? \
233 parse_solitary_modifier
(ns_right_control_modifier
) : 0) \
234 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
235 parse_solitary_modifier
(ns_control_modifier
) : 0) \
236 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
237 parse_solitary_modifier
(ns_function_modifier
) : 0) \
238 |
(!EQ
(ns_right_command_modifier
, Qleft
) && \
239 (([e modifierFlags
] & NSRightCommandKeyMask
) \
240 == NSRightCommandKeyMask
) ? \
241 parse_solitary_modifier
(ns_right_command_modifier
) : 0) \
242 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
243 parse_solitary_modifier
(ns_command_modifier
):0))
245 #define EV_UDMODIFIERS
(e
) \
246 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
247 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
248 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
249 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
250 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
251 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
252 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
253 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
254 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
256 #define EV_BUTTON
(e
) \
257 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
258 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
259 [e buttonNumber
] - 1)
261 /* Convert the time field to a timestamp in milliseconds. */
262 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
264 /* This is a piece of code which is common to all the event handling
265 methods. Maybe it should even be a function. */
266 #define EV_TRAILER
(e
) \
268 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
269 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
272 n_emacs_events_pending
++; \
273 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
276 kbd_buffer_store_event
(emacs_event
); \
277 EVENT_INIT
(*emacs_event
); \
278 ns_send_appdefined
(-1); \
281 void x_set_cursor_type
(struct frame
*, Lisp_Object
, Lisp_Object
);
283 /* TODO: get rid of need for these forward declarations */
284 static void ns_condemn_scroll_bars
(struct frame
*f
);
285 static void ns_judge_scroll_bars
(struct frame
*f
);
286 void x_set_frame_alpha
(struct frame
*f
);
289 /* ==========================================================================
293 ========================================================================== */
297 append2
(Lisp_Object list
, Lisp_Object item
)
298 /* --------------------------------------------------------------------------
299 Utility to append to a list
300 -------------------------------------------------------------------------- */
302 Lisp_Object array
[2];
304 array
[1] = Fcons
(item
, Qnil
);
305 return Fnconc
(2, &array
[0]);
310 ns_etc_directory
(void
)
311 /* If running as a self-contained app bundle, return as a string the
312 filename of the etc directory, if present; else nil. */
314 NSBundle
*bundle
= [NSBundle mainBundle
];
315 NSString
*resourceDir
= [bundle resourcePath
];
316 NSString
*resourcePath
;
317 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
320 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
321 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
323 if (isDir
) return [resourcePath UTF8String
];
331 /* If running as a self-contained app bundle, return as a path string
332 the filenames of the libexec and bin directories, ie libexec:bin.
333 Otherwise, return nil.
334 Normally, Emacs does not add its own bin/ directory to the PATH.
335 However, a self-contained NS build has a different layout, with
336 bin/ and libexec/ subdirectories in the directory that contains
338 We put libexec first, because init_callproc_1 uses the first
339 element to initialize exec-directory. An alternative would be
340 for init_callproc to check for invocation-directory/libexec.
343 NSBundle
*bundle
= [NSBundle mainBundle
];
344 NSString
*resourceDir
= [bundle resourcePath
];
345 NSString
*binDir
= [bundle bundlePath
];
346 NSString
*resourcePath
, *resourcePaths
;
348 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
349 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
351 NSEnumerator
*pathEnum
;
354 range
= [resourceDir rangeOfString
: @"Contents"
];
355 if (range.location
!= NSNotFound
)
357 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
359 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
363 paths
= [binDir stringsByAppendingPaths
:
364 [NSArray arrayWithObjects
: @"libexec"
, @"bin"
, nil
]];
365 pathEnum
= [paths objectEnumerator
];
368 while ((resourcePath
= [pathEnum nextObject
]))
370 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
373 if ([resourcePaths
length] > 0)
375 = [resourcePaths stringByAppendingString
: pathSeparator
];
377 = [resourcePaths stringByAppendingString
: resourcePath
];
380 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
388 /* If running as a self-contained app bundle, return as a path string
389 the filenames of the site-lisp, lisp and leim directories.
390 Ie, site-lisp:lisp:leim. Otherwise, return nil. */
392 NSBundle
*bundle
= [NSBundle mainBundle
];
393 NSString
*resourceDir
= [bundle resourcePath
];
394 NSString
*resourcePath
, *resourcePaths
;
395 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
396 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
398 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
399 [NSArray arrayWithObjects
:
400 @"site
-lisp"
, @"lisp"
, @"leim"
, nil
]];
401 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
404 /* Hack to skip site-lisp. */
405 if (no_site_lisp
) resourcePath
= [pathEnum nextObject
];
407 while ((resourcePath
= [pathEnum nextObject
]))
409 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
412 if ([resourcePaths
length] > 0)
414 = [resourcePaths stringByAppendingString
: pathSeparator
];
416 = [resourcePaths stringByAppendingString
: resourcePath
];
419 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
425 ns_timeout
(int usecs
)
426 /* --------------------------------------------------------------------------
427 Blocking timer utility used by ns_ring_bell
428 -------------------------------------------------------------------------- */
430 EMACS_TIME wakeup
= add_emacs_time
(current_emacs_time
(),
431 make_emacs_time
(0, usecs
* 1000));
433 /* Keep waiting until past the time wakeup. */
436 EMACS_TIME timeout
, now
= current_emacs_time
();
437 if (EMACS_TIME_LE
(wakeup
, now
))
439 timeout
= sub_emacs_time
(wakeup
, now
);
441 /* Try to wait that long--but we might wake up sooner. */
442 pselect
(0, NULL, NULL, NULL, &timeout
, NULL);
448 ns_release_object
(void
*obj
)
449 /* --------------------------------------------------------------------------
450 Release an object (callable from C)
451 -------------------------------------------------------------------------- */
458 ns_retain_object
(void
*obj
)
459 /* --------------------------------------------------------------------------
460 Retain an object (callable from C)
461 -------------------------------------------------------------------------- */
468 ns_alloc_autorelease_pool
(void
)
469 /* --------------------------------------------------------------------------
470 Allocate a pool for temporary objects (callable from C)
471 -------------------------------------------------------------------------- */
473 return [[NSAutoreleasePool alloc
] init
];
478 ns_release_autorelease_pool
(void
*pool
)
479 /* --------------------------------------------------------------------------
480 Free a pool and temporary objects it refers to (callable from C)
481 -------------------------------------------------------------------------- */
483 ns_release_object
(pool
);
488 /* ==========================================================================
490 Focus (clipping) and screen update
492 ========================================================================== */
495 // Window constraining
496 // -------------------
498 // To ensure that the windows are not placed under the
menu bar, they
499 // are typically moved by the call
-back constrainFrameRect. However
,
500 // by overriding it
, it
's possible to inhibit this, leaving the window
501 // in it's original position.
503 // It
's possible to hide the menu bar. However, technically, it's only
504 // possible to hide it when the application is active. To ensure that
505 // this work properly
, the
menu bar and window constraining are
506 // deferred until the application becomes active.
508 // Even though it
's not possible to manually move a window above the
509 // top of the screen, it is allowed if it's done programmatically
,
510 // when the
menu is
hidden. This allows the editable area to cover the
511 // full screen height.
516 // Use the following extra files
:
519 // ;; Hide
menu and place frame slightly above the top of the screen.
520 // (setq ns
-auto
-hide
-menu-bar t
)
521 // (set-frame
-position
(selected
-frame
) 0 -20)
525 // emacs
-Q
-l init.el
527 // Result
: No
menu bar, and the
title bar should be above the screen.
533 // Result
: Menu bar visible
, frame placed immediately below the
menu.
537 ns_constrain_all_frames
(void
)
539 Lisp_Object tail
, frame
;
541 FOR_EACH_FRAME
(tail
, frame
)
543 struct frame
*f
= XFRAME
(frame
);
546 NSView
*view = FRAME_NS_VIEW
(f
);
547 /* This no-op will trigger the default window placing
548 * constraint system. */
549 f
->output_data.ns
->dont_constrain
= 0;
550 [[view window
] setFrameOrigin
:[[view window
] frame
].origin
];
556 /* True, if the menu bar should be hidden. */
559 ns_menu_bar_should_be_hidden
(void
)
561 return !NILP
(ns_auto_hide_menu_bar
)
562 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)];
566 /* Show or hide the menu bar, based on user setting. */
569 ns_update_auto_hide_menu_bar
(void
)
572 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
575 NSTRACE
(ns_update_auto_hide_menu_bar
);
579 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)])
581 // Note
, "setPresentationOptions" triggers an
error unless the
582 // application is active.
583 BOOL menu_bar_should_be_hidden
= ns_menu_bar_should_be_hidden
();
585 if (menu_bar_should_be_hidden
!= ns_menu_bar_is_hidden
)
587 NSApplicationPresentationOptions options
588 = NSApplicationPresentationAutoHideDock
;
590 if (menu_bar_should_be_hidden
)
591 options |
= NSApplicationPresentationAutoHideMenuBar
;
593 [NSApp setPresentationOptions
: options
];
595 ns_menu_bar_is_hidden
= menu_bar_should_be_hidden
;
597 if (!ns_menu_bar_is_hidden
)
599 ns_constrain_all_frames
();
611 ns_update_begin
(struct frame
*f
)
612 /* --------------------------------------------------------------------------
613 Prepare for a grouped sequence of drawing calls
614 external (RIF) call; whole frame, called before update_window_begin
615 -------------------------------------------------------------------------- */
617 NSView
*view = FRAME_NS_VIEW
(f
);
618 NSRect r
= [view frame
];
620 NSTRACE
(ns_update_begin
);
622 ns_update_auto_hide_menu_bar
();
624 ns_updating_frame
= f
;
627 /* drawRect may have been called for say the minibuffer, and then clip path
628 is for the minibuffer. But the display engine may draw more because
629 we have set the frame as garbaged. So reset clip path to the whole
631 bp
= [[NSBezierPath bezierPathWithRect
: r
] retain
];
635 #ifdef NS_IMPL_GNUSTEP
636 uRect
= NSMakeRect
(0, 0, 0, 0);
642 ns_update_window_begin
(struct window
*w
)
643 /* --------------------------------------------------------------------------
644 Prepare for a grouped sequence of drawing calls
645 external (RIF) call; for one window, called after update_begin
646 -------------------------------------------------------------------------- */
648 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
649 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
650 NSTRACE
(ns_update_window_begin
);
652 set_output_cursor
(&w
->cursor
);
656 if (f
== hlinfo
->mouse_face_mouse_frame
)
658 /* Don't do highlighting for mouse motion during the update. */
659 hlinfo
->mouse_face_defer
= 1;
661 /* If the frame needs to be redrawn,
662 simply forget about any prior mouse highlighting. */
663 if (FRAME_GARBAGED_P
(f
))
664 hlinfo
->mouse_face_window
= Qnil
;
666 /* (further code for mouse faces ifdef'd out in other terms elided) */
674 ns_update_window_end
(struct window
*w
, int cursor_on_p
,
675 int mouse_face_overwritten_p
)
676 /* --------------------------------------------------------------------------
677 Finished a grouped sequence of drawing calls
678 external (RIF) call; for one window called before update_end
679 -------------------------------------------------------------------------- */
681 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(XFRAME
(w
->frame
));
683 /* note: this fn is nearly identical in all terms */
684 if (!w
->pseudo_window_p
)
689 display_and_set_cursor
(w
, 1,
690 output_cursor.hpos
, output_cursor.vpos
,
691 output_cursor.x
, output_cursor.y
);
693 if (draw_window_fringes
(w
, 1))
694 x_draw_vertical_border
(w
);
699 /* If a row with mouse-face was overwritten, arrange for
700 frame_up_to_date to redisplay the mouse highlight. */
701 if (mouse_face_overwritten_p
)
703 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
704 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
705 hlinfo
->mouse_face_window
= Qnil
;
708 updated_window
= NULL;
709 NSTRACE
(update_window_end
);
714 ns_update_end
(struct frame
*f
)
715 /* --------------------------------------------------------------------------
716 Finished a grouped sequence of drawing calls
717 external (RIF) call; for whole frame, called after update_window_end
718 -------------------------------------------------------------------------- */
720 NSView
*view = FRAME_NS_VIEW
(f
);
722 /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
723 MOUSE_HL_INFO
(f
)->mouse_face_defer
= 0;
727 #ifdef NS_IMPL_GNUSTEP
728 /* trigger flush only in the rectangle we tracked as being drawn */
729 [view unlockFocusNeedsFlush
: NO
];
730 /*fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", uRect.origin.x, uRect.origin.y, uRect.size.width, uRect.size.height); */
731 [view lockFocusInRect
: uRect
];
735 [[view window
] flushWindow
];
738 ns_updating_frame
= NULL;
739 NSTRACE
(ns_update_end
);
744 ns_flush
(struct frame
*f
)
745 /* --------------------------------------------------------------------------
747 NS impl is no-op since currently we flush in ns_update_end and elsewhere
748 -------------------------------------------------------------------------- */
755 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
756 /* --------------------------------------------------------------------------
757 Internal: Focus on given frame. During small local updates this is used to
758 draw, however during large updates, ns_update_begin and ns_update_end are
759 called to wrap the whole thing, in which case these calls are stubbed out.
760 Except, on GNUstep, we accumulate the rectangle being drawn into, because
761 the back end won't do this automatically, and will just end up flushing
763 -------------------------------------------------------------------------- */
765 // NSTRACE
(ns_focus
);
766 #ifdef NS_IMPL_GNUSTEP
769 u
= NSUnionRect
(r
[0], r
[1]);
774 fprintf (stderr, "focus: %d", c++);
775 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
776 fprintf (stderr, "\n"); */
778 if (f
!= ns_updating_frame
)
780 NSView
*view = FRAME_NS_VIEW
(f
);
781 if (view != focus_view
)
783 if (focus_view
!= NULL)
785 [focus_view unlockFocus
];
786 [[focus_view window
] flushWindow
];
791 #ifdef NS_IMPL_GNUSTEP
792 r ?
[view lockFocusInRect
: u
] : [view lockFocus
];
797 /*if (view) debug_lock++; */
799 #ifdef NS_IMPL_GNUSTEP
802 /* more than one rect being drawn into */
805 [view unlockFocus
]; /* add prev rect to redraw list */
806 [view lockFocusInRect
: u
]; /* focus for draw in new rect */
811 #ifdef NS_IMPL_GNUSTEP
814 /* in batch mode, but in GNUstep must still track rectangles explicitly */
815 uRect
= (r ? NSUnionRect
(uRect
, u
) : [FRAME_NS_VIEW
(f
) visibleRect
]);
822 [[NSGraphicsContext currentContext
] saveGraphicsState
];
824 NSRectClipList
(r
, 2);
833 ns_unfocus
(struct frame
*f
)
834 /* --------------------------------------------------------------------------
835 Internal: Remove focus on given frame
836 -------------------------------------------------------------------------- */
838 // NSTRACE
(ns_unfocus
);
842 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
846 if (f
!= ns_updating_frame
)
848 if (focus_view
!= NULL)
850 [focus_view unlockFocus
];
851 [[focus_view window
] flushWindow
];
860 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
, int area
, BOOL gc
)
861 /* --------------------------------------------------------------------------
862 Internal (but parallels other terms): Focus drawing on given row
863 -------------------------------------------------------------------------- */
865 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
867 int window_x
, window_y
, window_width
;
869 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
871 clip_rect.origin.x
= window_x
;
872 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
873 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
874 clip_rect.
size.width
= window_width
;
875 clip_rect.
size.height
= row
->visible_height
;
877 ns_focus
(f
, &clip_rect
, 1);
882 ns_ring_bell
(struct frame
*f
)
883 /* --------------------------------------------------------------------------
885 -------------------------------------------------------------------------- */
887 NSTRACE
(ns_ring_bell
);
890 NSAutoreleasePool
*pool
;
891 struct frame
*frame
= SELECTED_FRAME
();
895 pool
= [[NSAutoreleasePool alloc
] init
];
897 view = FRAME_NS_VIEW
(frame
);
901 NSPoint dim
= NSMakePoint
(128, 128);
904 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
905 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
906 r.
size.width
= dim.x
;
907 r.
size.height
= dim.y
;
908 surr
= NSInsetRect
(r
, -2, -2);
909 ns_focus
(frame
, &surr
, 1);
910 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
911 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
912 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
914 [[view window
] flushWindow
];
916 [[view window
] restoreCachedImage
];
917 [[view window
] flushWindow
];
931 ns_reset_terminal_modes
(struct terminal *terminal)
932 /* Externally called as hook */
934 NSTRACE
(ns_reset_terminal_modes
);
939 ns_set_terminal_modes
(struct terminal *terminal)
940 /* Externally called as hook */
942 NSTRACE
(ns_set_terminal_modes
);
947 /* ==========================================================================
949 Frame / window manager related functions
951 ========================================================================== */
955 ns_raise_frame
(struct frame
*f
)
956 /* --------------------------------------------------------------------------
957 Bring window to foreground and make it active
958 -------------------------------------------------------------------------- */
960 NSView
*view = FRAME_NS_VIEW
(f
);
963 FRAME_SAMPLE_VISIBILITY
(f
);
964 if (FRAME_VISIBLE_P
(f
))
966 [[view window
] makeKeyAndOrderFront
: NSApp
];
973 ns_lower_frame
(struct frame
*f
)
974 /* --------------------------------------------------------------------------
976 -------------------------------------------------------------------------- */
978 NSView
*view = FRAME_NS_VIEW
(f
);
981 [[view window
] orderBack
: NSApp
];
987 ns_frame_raise_lower
(struct frame
*f
, int raise
)
988 /* --------------------------------------------------------------------------
990 -------------------------------------------------------------------------- */
992 NSTRACE
(ns_frame_raise_lower
);
1002 ns_frame_rehighlight
(struct frame
*frame
)
1003 /* --------------------------------------------------------------------------
1004 External (hook): called on things like window switching within frame
1005 -------------------------------------------------------------------------- */
1007 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(frame
);
1008 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1010 NSTRACE
(ns_frame_rehighlight
);
1011 if (dpyinfo
->x_focus_frame
)
1013 dpyinfo
->x_highlight_frame
1014 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1015 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1016 : dpyinfo
->x_focus_frame
);
1017 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
1019 fset_focus_frame
(dpyinfo
->x_focus_frame
, Qnil
);
1020 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1024 dpyinfo
->x_highlight_frame
= 0;
1026 if (dpyinfo
->x_highlight_frame
&&
1027 dpyinfo
->x_highlight_frame
!= old_highlight
)
1031 x_update_cursor
(old_highlight
, 1);
1032 x_set_frame_alpha
(old_highlight
);
1034 if (dpyinfo
->x_highlight_frame
)
1036 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
1037 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
1044 x_make_frame_visible
(struct frame
*f
)
1045 /* --------------------------------------------------------------------------
1046 External: Show the window (X11 semantics)
1047 -------------------------------------------------------------------------- */
1049 NSTRACE
(x_make_frame_visible
);
1050 /* XXX: at some points in past this was not needed, as the only place that
1051 called this (frame.c:Fraise_frame ()) also called raise_lower;
1052 if this ends up the case again, comment this out again. */
1053 if (!FRAME_VISIBLE_P
(f
))
1055 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(f
);
1056 f
->async_visible
= 1;
1060 /* Making a new frame from a fullscreen frame will make the new frame
1061 fullscreen also. So skip handleFS as this will print an error. */
1062 if (f
->want_fullscreen
== FULLSCREEN_BOTH
1063 && ([[view window
] styleMask
] & NSFullScreenWindowMask
) != 0)
1066 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
1077 x_make_frame_invisible
(struct frame
*f
)
1078 /* --------------------------------------------------------------------------
1079 External: Hide the window (X11 semantics)
1080 -------------------------------------------------------------------------- */
1082 NSView
* view = FRAME_NS_VIEW
(f
);
1083 NSTRACE
(x_make_frame_invisible
);
1085 [[view window
] orderOut
: NSApp
];
1086 f
->async_visible
= 0;
1087 f
->async_iconified
= 0;
1092 x_iconify_frame
(struct frame
*f
)
1093 /* --------------------------------------------------------------------------
1094 External: Iconify window
1095 -------------------------------------------------------------------------- */
1097 NSView
* view = FRAME_NS_VIEW
(f
);
1098 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1099 NSTRACE
(x_iconify_frame
);
1102 if (dpyinfo
->x_highlight_frame
== f
)
1103 dpyinfo
->x_highlight_frame
= 0;
1105 if ([[view window
] windowNumber
] <= 0)
1107 /* the window is still deferred. Make it very small, bring it
1108 on screen and order it out. */
1109 NSRect s
= { { 100, 100}, {0, 0} };
1111 t
= [[view window
] frame
];
1112 [[view window
] setFrame
: s display
: NO
];
1113 [[view window
] orderBack
: NSApp
];
1114 [[view window
] orderOut
: NSApp
];
1115 [[view window
] setFrame
: t display
: NO
];
1117 [[view window
] miniaturize
: NSApp
];
1120 /* Free X resources of frame F. */
1123 x_free_frame_resources
(struct frame
*f
)
1125 NSView
*view = FRAME_NS_VIEW
(f
);
1126 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1127 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1128 NSTRACE
(x_free_frame_resources
);
1131 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1135 free_frame_menubar
(f
);
1137 if (FRAME_FACE_CACHE
(f
))
1138 free_frame_faces
(f
);
1140 if (f
== dpyinfo
->x_focus_frame
)
1141 dpyinfo
->x_focus_frame
= 0;
1142 if (f
== dpyinfo
->x_highlight_frame
)
1143 dpyinfo
->x_highlight_frame
= 0;
1144 if (f
== hlinfo
->mouse_face_mouse_frame
)
1146 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1147 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1148 hlinfo
->mouse_face_window
= Qnil
;
1149 hlinfo
->mouse_face_deferred_gc
= 0;
1150 hlinfo
->mouse_face_mouse_frame
= 0;
1153 if (f
->output_data.ns
->miniimage
!= nil
)
1154 [f
->output_data.ns
->miniimage release
];
1156 [[view window
] close];
1159 xfree
(f
->output_data.ns
);
1165 x_destroy_window
(struct frame
*f
)
1166 /* --------------------------------------------------------------------------
1167 External: Delete the window
1168 -------------------------------------------------------------------------- */
1170 NSTRACE
(x_destroy_window
);
1172 x_free_frame_resources
(f
);
1178 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1179 /* --------------------------------------------------------------------------
1180 External: Position the window
1181 -------------------------------------------------------------------------- */
1183 NSView
*view = FRAME_NS_VIEW
(f
);
1184 NSArray
*screens
= [NSScreen screens
];
1185 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1186 NSScreen
*screen
= [[view window
] screen
];
1188 NSTRACE
(x_set_offset
);
1195 if (view != nil
&& screen
&& fscreen
)
1197 f
->left_pos
= f
->size_hint_flags
& XNegative
1198 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1200 /* We use visibleFrame here to take menu bar into account.
1201 Ideally we should also adjust left/top with visibleFrame.origin. */
1203 f
->top_pos
= f
->size_hint_flags
& YNegative
1204 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1205 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1206 - FRAME_TOOLBAR_HEIGHT
(f
))
1208 #ifdef NS_IMPL_GNUSTEP
1209 if (f
->left_pos
< 100)
1210 f
->left_pos
= 100; /* don't overlap menu */
1212 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1214 f
->output_data.ns
->dont_constrain
= 0;
1215 [[view window
] setFrameTopLeftPoint
:
1216 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1217 SCREENMAXBOUND
([fscreen frame
].
size.height
1218 - NS_TOP_POS
(f
)))];
1219 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1227 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1228 /* --------------------------------------------------------------------------
1229 Adjust window pixel size based on given character grid size
1230 Impl is a bit more complex than other terms, need to do some
1232 -------------------------------------------------------------------------- */
1234 EmacsView
*view = FRAME_NS_VIEW
(f
);
1235 NSWindow
*window
= [view window
];
1236 NSRect wr
= [window frame
];
1237 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1238 int pixelwidth
, pixelheight
;
1240 NSTRACE
(x_set_window_size
);
1245 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1249 check_frame_size
(f
, &rows
, &cols
);
1251 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1252 compute_fringe_widths
(f
, 0);
1254 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1255 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1257 /* If we have a toolbar, take its height into account. */
1259 /* NOTE: previously this would generate wrong result if toolbar not
1260 yet displayed and fixing toolbar_height=32 helped, but
1261 now (200903) seems no longer needed */
1262 FRAME_TOOLBAR_HEIGHT
(f
) =
1263 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1264 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1266 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1268 wr.
size.width
= pixelwidth
+ f
->border_width
;
1269 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1270 + FRAME_TOOLBAR_HEIGHT
(f
);
1272 /* Do not try to constrain to this screen. We may have multiple
1273 screens, and want Emacs to span those. Constraining to screen
1274 prevents that, and that is not nice to the user. */
1275 if (f
->output_data.ns
->zooming
)
1276 f
->output_data.ns
->zooming
= 0;
1278 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1280 [view setRows
: rows andColumns
: cols
];
1281 [window setFrame
: wr display
: YES
];
1283 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1285 /* This is a trick to compensate for Emacs' managing the scrollbar area
1286 as a fixed number of standard character columns. Instead of leaving
1287 blank space for the extra, we chopped it off above. Now for
1288 left-hand scrollbars, we shift all rendering to the left by the
1289 difference between the real width and Emacs' imagined one. For
1290 right-hand bars, don't worry about it since the extra is never used.
1291 (Obviously doesn't work for vertically split windows tho..) */
1293 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1294 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1295 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1296 : NSMakePoint
(0, 0);
1297 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1298 [view setBoundsOrigin
: origin
];
1301 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1302 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1303 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1304 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1306 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1307 cancel_mouse_face
(f
);
1314 ns_fullscreen_hook
(FRAME_PTR f
)
1316 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(f
);
1318 if (! f
->async_visible
) return;
1319 #ifndef NEW_STYLE_FS
1320 if (f
->want_fullscreen
== FULLSCREEN_BOTH
)
1322 /* Old style fs don't initiate correctly if created from
1323 init/default-frame alist, so use a timer (not nice...).
1325 [NSTimer scheduledTimerWithTimeInterval
: 0.5 target
: view
1326 selector
: @selector
(handleFS
)
1327 userInfo
: nil repeats
: NO
];
1337 /* ==========================================================================
1341 ========================================================================== */
1345 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1347 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1348 if (idx
< 1 || idx
>= color_table
->avail
)
1350 return color_table
->colors
[idx
];
1355 ns_index_color
(NSColor
*color
, struct frame
*f
)
1357 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1361 if (!color_table
->colors
)
1363 color_table
->size = NS_COLOR_CAPACITY
;
1364 color_table
->avail
= 1; /* skip idx=0 as marker */
1365 color_table
->colors
= xmalloc
(color_table
->size * sizeof
(NSColor
*));
1366 color_table
->colors
[0] = nil
;
1367 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1370 /* do we already have this color ? */
1371 for (i
= 1; i
< color_table
->avail
; i
++)
1372 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1375 if ([color_table
->empty_indices count
] > 0)
1377 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1378 [color_table
->empty_indices removeObject
: index
];
1379 idx
= [index unsignedLongValue
];
1383 if (color_table
->avail
== color_table
->size)
1384 color_table
->colors
=
1385 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1386 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1387 idx
= color_table
->avail
++;
1390 color_table
->colors
[idx
] = color
;
1392 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1398 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1400 struct ns_color_table
*color_table
;
1407 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1409 if (idx
<= 0 || idx
>= color_table
->size) {
1410 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1414 index
= [NSNumber numberWithUnsignedInt
: idx
];
1415 if ([color_table
->empty_indices containsObject
: index
]) {
1416 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1420 color
= color_table
->colors
[idx
];
1422 color_table
->colors
[idx
] = nil
;
1423 [color_table
->empty_indices addObject
: index
];
1424 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1429 ns_get_color
(const
char *name
, NSColor
**col
)
1430 /* --------------------------------------------------------------------------
1432 -------------------------------------------------------------------------- */
1433 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1434 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1435 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1438 static
char hex
[20];
1440 float r
= -1.0, g
, b
;
1441 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1443 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1446 if ([nsname isEqualToString
: @"ns_selection_color"
])
1448 nsname
= ns_selection_color
;
1449 name
= [ns_selection_color UTF8String
];
1452 /* First, check for some sort of numeric specification. */
1455 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1457 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1458 [scanner scanFloat
: &r
];
1459 [scanner scanFloat
: &g
];
1460 [scanner scanFloat
: &b
];
1462 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1463 scaling
= (snprintf
(hex
, sizeof hex
, "
%s", name + 4) - 2) / 3;
1464 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1466 int len
= (strlen
(name
) - 1);
1467 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1469 scaling
= strlen
(name
+start
) / 3;
1470 for (i
= 0; i
< 3; i
++)
1471 sprintf (hex
+ i
* (scaling
+ 1), "
%.*s/", scaling,
1472 name
+ start
+ i
* scaling
);
1473 hex
[3 * (scaling
+ 1) - 1] = '\0';
1479 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1480 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1490 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1495 /* Otherwise, color is expected to be from a list */
1497 NSEnumerator
*lenum
, *cenum
;
1501 #ifdef NS_IMPL_GNUSTEP
1502 /* XXX: who is wrong, the requestor or the implementation? */
1503 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1505 nsname
= @"highlightColor"
;
1508 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1509 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1511 cenum
= [[clist allKeys
] objectEnumerator
];
1512 while ( (name
= [cenum nextObject
]) && new
== nil
)
1514 if ([name compare
: nsname
1515 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1516 new
= [clist colorWithKey
: name
];
1522 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1529 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1530 /* --------------------------------------------------------------------------
1531 Convert a Lisp string object to a NS color
1532 -------------------------------------------------------------------------- */
1534 NSTRACE
(ns_lisp_to_color
);
1535 if (STRINGP
(color
))
1536 return ns_get_color
(SSDATA
(color
), col
);
1537 else if (SYMBOLP
(color
))
1538 return ns_get_color
(SSDATA
(SYMBOL_NAME
(color
)), col
);
1544 ns_color_to_lisp
(NSColor
*col
)
1545 /* --------------------------------------------------------------------------
1546 Convert a color to a lisp string with the RGB equivalent
1547 -------------------------------------------------------------------------- */
1549 CGFloat red
, green
, blue
, alpha
, gray;
1552 NSTRACE
(ns_color_to_lisp
);
1555 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1557 if ((str
=[[col colorNameComponent
] UTF8String
]))
1560 return build_string
((char *)str
);
1563 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1564 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1565 if (red
==green
&& red
==blue
)
1567 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1568 getWhite
: &gray alpha
: &alpha
];
1569 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1570 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1572 return build_string
(buf
);
1575 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1576 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1579 return build_string
(buf
);
1584 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1585 /* --------------------------------------------------------------------------
1586 Get ARGB values out of NSColor col and put them into color_def.
1587 If setPixel, set the pixel to a concatenated version.
1588 and set color_def pixel to the resulting index.
1589 -------------------------------------------------------------------------- */
1593 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1594 color_def
->red
= r
* 65535;
1595 color_def
->green
= g
* 65535;
1596 color_def
->blue
= b
* 65535;
1598 if (setPixel
== YES
)
1600 = ARGB_TO_ULONG
((int
)(a
*255),
1601 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1606 ns_defined_color
(struct frame
*f
,
1611 /* --------------------------------------------------------------------------
1612 Return true if named color found, and set color_def rgb accordingly.
1613 If makeIndex and alloc are nonzero put the color in the color_table,
1614 and set color_def pixel to the resulting index.
1615 If makeIndex is zero, set color_def pixel to ARGB.
1616 Return false if not found
1617 -------------------------------------------------------------------------- */
1620 NSTRACE
(ns_defined_color
);
1623 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1628 if (makeIndex
&& alloc
)
1629 color_def
->pixel
= ns_index_color
(col
, f
);
1630 ns_query_color
(col
, color_def
, !makeIndex
);
1637 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1638 /* --------------------------------------------------------------------------
1639 return an autoreleased RGB color
1640 -------------------------------------------------------------------------- */
1642 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1643 if (r
< 0.0) r
= 0.0;
1644 else if (r
> 1.0) r
= 1.0;
1645 if (g
< 0.0) g
= 0.0;
1646 else if (g
> 1.0) g
= 1.0;
1647 if (b
< 0.0) b
= 0.0;
1648 else if (b
> 1.0) b
= 1.0;
1649 if (a
< 0.0) a
= 0.0;
1650 else if (a
> 1.0) a
= 1.0;
1651 return (unsigned
long) ns_index_color
(
1652 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1657 x_set_frame_alpha
(struct frame
*f
)
1658 /* --------------------------------------------------------------------------
1659 change the entire-frame transparency
1660 -------------------------------------------------------------------------- */
1662 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1663 EmacsView
*view = FRAME_NS_VIEW
(f
);
1665 double alpha_min
= 1.0;
1667 if (dpyinfo
->x_highlight_frame
== f
)
1668 alpha
= f
->alpha
[0];
1670 alpha
= f
->alpha
[1];
1672 if (FLOATP
(Vframe_alpha_lower_limit
))
1673 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1674 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1675 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1679 else if (1.0 < alpha
)
1681 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1684 #ifdef NS_IMPL_COCOA
1685 [[view window
] setAlphaValue
: alpha
];
1690 /* ==========================================================================
1694 ========================================================================== */
1698 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1699 /* --------------------------------------------------------------------------
1700 Programmatically reposition mouse pointer in pixel coordinates
1701 -------------------------------------------------------------------------- */
1703 NSTRACE
(x_set_mouse_pixel_position
);
1706 /* FIXME: this does not work, and what about GNUstep? */
1707 #ifdef NS_IMPL_COCOA
1708 [FRAME_NS_VIEW
(f
) lockFocus
];
1709 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1710 [FRAME_NS_VIEW
(f
) unlockFocus
];
1717 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1718 /* --------------------------------------------------------------------------
1719 Programmatically reposition mouse pointer in character coordinates
1720 -------------------------------------------------------------------------- */
1724 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1725 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1727 if (pix_x
< 0) pix_x
= 0;
1728 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1730 if (pix_y
< 0) pix_y
= 0;
1731 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1733 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1738 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1739 /* ------------------------------------------------------------------------
1740 Called by EmacsView on mouseMovement events. Passes on
1741 to emacs mainstream code if we moved off of a rect of interest
1742 known as last_mouse_glyph.
1743 ------------------------------------------------------------------------ */
1745 // NSTRACE
(note_mouse_movement
);
1747 XSETFRAME
(last_mouse_motion_frame
, frame
);
1749 /* Note, this doesn't get called for enter/leave, since we don't have a
1750 position. Those are taken care of in the corresponding NSView methods. */
1752 /* has movement gone beyond last rect we were tracking? */
1753 if (x
< last_mouse_glyph.origin.x ||
1754 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1755 y
< last_mouse_glyph.origin.y ||
1756 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1758 ns_update_begin
(frame
);
1759 frame
->mouse_moved
= 1;
1760 note_mouse_highlight
(frame
, x
, y
);
1761 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1762 ns_update_end
(frame
);
1771 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1772 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1774 /* --------------------------------------------------------------------------
1775 External (hook): inform emacs about mouse position and hit parts.
1776 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1777 x & y should be position in the scrollbar (the whole bar, not the handle)
1778 and length of scrollbar respectively
1779 -------------------------------------------------------------------------- */
1783 Lisp_Object frame
, tail
;
1785 struct ns_display_info
*dpyinfo
;
1787 NSTRACE
(ns_mouse_position
);
1791 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1795 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1799 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1801 /* TODO: we do not use this path at the moment because drag events will
1802 go directly to the EmacsScroller. Leaving code in for now. */
1803 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1805 if (time
) *time
= last_mouse_movement_time
;
1806 last_mouse_scroll_bar
= nil
;
1810 /* Clear the mouse-moved flag for every frame on this display. */
1811 FOR_EACH_FRAME
(tail
, frame
)
1812 if (FRAME_NS_P
(XFRAME
(frame
))
1813 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1814 XFRAME
(frame
)->mouse_moved
= 0;
1816 last_mouse_scroll_bar
= nil
;
1817 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1818 f
= last_mouse_frame
;
1820 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1821 : SELECTED_FRAME
();
1823 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1825 view = FRAME_NS_VIEW
(*fp
);
1827 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1828 position
= [view convertPoint
: position fromView
: nil
];
1829 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1830 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1832 if (bar_window
) *bar_window
= Qnil
;
1833 if (part
) *part
= 0; /*scroll_bar_handle; */
1835 if (x
) XSETINT
(*x
, lrint
(position.x
));
1836 if (y
) XSETINT
(*y
, lrint
(position.y
));
1837 if (time
) *time
= last_mouse_movement_time
;
1847 ns_frame_up_to_date
(struct frame
*f
)
1848 /* --------------------------------------------------------------------------
1849 External (hook): Fix up mouse highlighting right after a full update.
1850 Some highlighting was deferred if GC was happening during
1851 note_mouse_highlight (), while other highlighting was deferred for update.
1852 -------------------------------------------------------------------------- */
1854 NSTRACE
(ns_frame_up_to_date
);
1858 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1859 if ((hlinfo
->mouse_face_deferred_gc || f
==hlinfo
->mouse_face_mouse_frame
)
1860 /*&& hlinfo->mouse_face_mouse_frame*/)
1864 if (hlinfo
->mouse_face_mouse_frame
)
1865 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1866 hlinfo
->mouse_face_mouse_x
,
1867 hlinfo
->mouse_face_mouse_y
);
1868 hlinfo
->mouse_face_deferred_gc
= 0;
1877 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1878 /* --------------------------------------------------------------------------
1879 External (RIF): set frame mouse pointer type.
1880 -------------------------------------------------------------------------- */
1882 NSTRACE
(ns_define_frame_cursor
);
1883 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1885 EmacsView
*view = FRAME_NS_VIEW
(f
);
1886 FRAME_POINTER_TYPE
(f
) = cursor
;
1887 [[view window
] invalidateCursorRectsForView
: view];
1888 /* Redisplay assumes this function also draws the changed frame
1889 cursor, but this function doesn't, so do it explicitly. */
1890 x_update_cursor
(f
, 1);
1896 /* ==========================================================================
1900 ========================================================================== */
1904 ns_convert_key
(unsigned code
)
1905 /* --------------------------------------------------------------------------
1906 Internal call used by NSView-keyDown.
1907 -------------------------------------------------------------------------- */
1909 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1910 / sizeof
(convert_ns_to_X_keysym
[0]));
1912 /* An array would be faster, but less easy to read. */
1913 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1914 if (code
== convert_ns_to_X_keysym
[keysym
])
1915 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1917 /* if decide to use keyCode and Carbon table, use this line:
1918 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1923 x_get_keysym_name
(int keysym
)
1924 /* --------------------------------------------------------------------------
1925 Called by keyboard.c. Not sure if the return val is important, except
1927 -------------------------------------------------------------------------- */
1929 static
char value
[16];
1930 NSTRACE
(x_get_keysym_name
);
1931 sprintf (value
, "
%d", keysym);
1937 /* ==========================================================================
1939 Block drawing operations
1941 ========================================================================== */
1945 ns_redraw_scroll_bars
(struct frame
*f
)
1949 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1950 NSTRACE
(ns_redraw_scroll_bars
);
1951 for (i
=[subviews count
]-1; i
>= 0; i
--)
1953 view = [subviews objectAtIndex
: i
];
1954 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
1961 ns_clear_frame
(struct frame
*f
)
1962 /* --------------------------------------------------------------------------
1963 External (hook): Erase the entire frame
1964 -------------------------------------------------------------------------- */
1966 NSView
*view = FRAME_NS_VIEW
(f
);
1969 NSTRACE
(ns_clear_frame
);
1971 /* comes on initial frame because we have
1972 after-make-frame-functions = select-frame */
1973 if (!FRAME_DEFAULT_FACE
(f
))
1976 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
1978 output_cursor.hpos
= output_cursor.vpos
= 0;
1979 output_cursor.x
= -1;
1984 ns_focus
(f
, &r
, 1);
1985 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
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];
2022 ns_scroll_run
(struct window
*w
, struct run
*run
)
2023 /* --------------------------------------------------------------------------
2024 External (RIF): Insert or delete n lines at line vpos
2025 -------------------------------------------------------------------------- */
2027 struct frame
*f
= XFRAME
(w
->frame
);
2028 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2030 NSTRACE
(ns_scroll_run
);
2032 /* begin copy from other terms */
2033 /* Get frame-relative bounding box of the text display area of W,
2034 without mode lines. Include in this box the left and right
2036 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2038 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2039 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2040 bottom_y
= y
+ height
;
2044 /* Scrolling up. Make sure we don't copy part of the mode
2045 line at the bottom. */
2046 if (from_y
+ run
->height
> bottom_y
)
2047 height
= bottom_y
- from_y
;
2049 height
= run
->height
;
2053 /* Scrolling down. Make sure we don't copy over the mode line.
2055 if (to_y
+ run
->height
> bottom_y
)
2056 height
= bottom_y
- to_y
;
2058 height
= run
->height
;
2060 /* end copy from other terms */
2071 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2072 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2073 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2075 ns_focus
(f
, &dstRect
, 1);
2076 NSCopyBits
(0, srcRect
, dstOrigin
);
2085 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2086 /* --------------------------------------------------------------------------
2087 External (RIF): preparatory to fringe update after text was updated
2088 -------------------------------------------------------------------------- */
2090 struct window
*w
= updated_window
;
2094 NSTRACE
(ns_after_update_window_line
);
2096 /* begin copy from other terms */
2099 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2100 desired_row
->redraw_fringe_bitmaps_p
= 1;
2102 /* When a window has disappeared, make sure that no rest of
2103 full-width rows stays visible in the internal border. */
2104 if (windows_or_buffers_changed
2105 && desired_row
->full_width_p
2106 && (f
= XFRAME
(w
->frame
),
2107 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2109 && (height
= desired_row
->visible_height
,
2112 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2115 ns_clear_frame_area
(f
, 0, y
, width
, height
);
2116 ns_clear_frame_area
(f
,
2117 FRAME_PIXEL_WIDTH
(f
) - width
,
2125 ns_shift_glyphs_for_insert
(struct frame
*f
,
2126 int x
, int y
, int width
, int height
,
2128 /* --------------------------------------------------------------------------
2129 External (RIF): copy an area horizontally, don't worry about clearing src
2130 -------------------------------------------------------------------------- */
2132 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2133 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2134 NSPoint dstOrigin
= dstRect.origin
;
2136 NSTRACE
(ns_shift_glyphs_for_insert
);
2138 ns_focus
(f
, &dstRect
, 1);
2139 NSCopyBits
(0, srcRect
, dstOrigin
);
2145 /* ==========================================================================
2147 Character encoding and metrics
2149 ========================================================================== */
2153 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2154 /* --------------------------------------------------------------------------
2155 External (RIF); compute left/right overhang of whole string and set in s
2156 -------------------------------------------------------------------------- */
2158 struct font
*font
= s
->font
;
2162 struct font_metrics metrics
;
2163 unsigned int codes
[2];
2164 codes
[0] = *(s
->char2b
);
2165 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2167 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2168 s
->left_overhang
= -metrics.lbearing
;
2170 = metrics.rbearing
> metrics.width
2171 ? metrics.rbearing
- metrics.width
: 0;
2175 s
->left_overhang
= 0;
2176 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2177 FONT_HEIGHT
(font
) * 0.2 : 0;
2183 /* ==========================================================================
2185 Fringe and cursor drawing
2187 ========================================================================== */
2190 extern int max_used_fringe_bitmap
;
2192 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2193 struct draw_fringe_bitmap_params
*p
)
2194 /* --------------------------------------------------------------------------
2195 External (RIF); fringe-related
2196 -------------------------------------------------------------------------- */
2198 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2199 struct face
*face
= p
->face
;
2201 static EmacsImage
**bimgs
= NULL;
2202 static int nBimgs
= 0;
2204 /* grow bimgs if needed */
2205 if (nBimgs
< max_used_fringe_bitmap
)
2207 bimgs
= xrealloc
(bimgs
, max_used_fringe_bitmap
* sizeof
*bimgs
);
2208 memset
(bimgs
+ nBimgs
, 0,
2209 (max_used_fringe_bitmap
- nBimgs
) * sizeof
*bimgs
);
2210 nBimgs
= max_used_fringe_bitmap
;
2213 /* Must clip because of partially visible lines. */
2214 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2215 ns_clip_to_row
(w
, row
, -1, YES
);
2219 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
2221 /* If the fringe is adjacent to the left (right) scroll bar of a
2222 leftmost (rightmost, respectively) window, then extend its
2223 background to the gap between the fringe and the bar. */
2224 if ((WINDOW_LEFTMOST_P
(w
)
2225 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(w
))
2226 ||
(WINDOW_RIGHTMOST_P
(w
)
2227 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT
(w
)))
2229 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH
(w
);
2233 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X
(w
);
2234 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS
(w
)
2235 * FRAME_COLUMN_WIDTH
(f
));
2239 /* Bitmap fills the fringe. */
2240 if (bar_area_x
+ bar_area_width
== p
->x
)
2241 bx
= bar_area_x
+ sb_width
;
2242 else if (p
->x
+ p
->wd
== bar_area_x
)
2246 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT
(w
);
2248 nx
= bar_area_width
- sb_width
;
2249 by
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (header_line_height
,
2251 ny
= row
->visible_height
;
2256 if (bar_area_x
+ bar_area_width
== bx
)
2258 bx
= bar_area_x
+ sb_width
;
2259 nx
+= bar_area_width
- sb_width
;
2261 else if (bx
+ nx
== bar_area_x
)
2262 nx
+= bar_area_width
- sb_width
;
2267 if (bx
>= 0 && nx
> 0)
2269 NSRect r
= NSMakeRect
(bx
, by
, nx
, ny
);
2271 [ns_lookup_indexed_color
(face
->background
, f
) set];
2278 NSRect r
= NSMakeRect
(p
->x
, p
->y
, p
->wd
, p
->h
);
2279 EmacsImage
*img
= bimgs
[p
->which - 1];
2283 unsigned short
*bits
= p
->bits
+ p
->dh
;
2286 unsigned
char *cbits
= xmalloc
(len
);
2288 for (i
= 0; i
< len
; i
++)
2289 cbits
[i
] = ~
(bits
[i
] & 0xff);
2290 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2292 bimgs
[p
->which - 1] = img
;
2297 /* Since we composite the bitmap instead of just blitting it, we need
2298 to erase the whole background. */
2299 [ns_lookup_indexed_color
(face
->background
, f
) set];
2301 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2302 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
2304 fromRect
: NSZeroRect
2305 operation
: NSCompositeSourceOver
2311 NSPoint pt
= r.origin
;
2313 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2322 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2323 int x
, int y
, int cursor_type
, int cursor_width
,
2324 int on_p
, int active_p
)
2325 /* --------------------------------------------------------------------------
2326 External call (RIF): draw cursor.
2327 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2328 -------------------------------------------------------------------------- */
2331 int fx
, fy
, h
, cursor_height
;
2332 struct frame
*f
= WINDOW_XFRAME
(w
);
2333 struct glyph
*phys_cursor_glyph
;
2335 struct glyph
*cursor_glyph
;
2337 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2339 /* If cursor is out of bounds, don't draw garbage. This can happen
2340 in mini-buffer windows when switching between echo area glyphs
2343 NSTRACE
(dumpcursor
);
2348 w
->phys_cursor_type
= cursor_type
;
2349 w
->phys_cursor_on_p
= on_p
;
2351 if (cursor_type
== NO_CURSOR
)
2353 w
->phys_cursor_width
= 0;
2357 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2359 if (glyph_row
->exact_window_width_line_p
2360 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2362 glyph_row
->cursor_in_fringe_p
= 1;
2363 draw_fringe_bitmap
(w
, glyph_row
, 0);
2368 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2369 (other terminals do it the other way round). We must set
2370 w->phys_cursor_width to the cursor width. For bar cursors, that
2371 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2372 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2374 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2375 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2376 if (cursor_type
== BAR_CURSOR
)
2378 if (cursor_width
< 1)
2379 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2380 w
->phys_cursor_width
= cursor_width
;
2382 /* If we have an HBAR, "cursor_width" MAY specify height. */
2383 else if (cursor_type
== HBAR_CURSOR
)
2385 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2386 fy
+= h
- cursor_height
;
2390 r.origin.x
= fx
, r.origin.y
= fy
;
2392 r.
size.width
= w
->phys_cursor_width
;
2394 /* TODO: only needed in rare cases with last-resort font in HELLO..
2395 should we do this more efficiently? */
2396 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2399 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2400 if (face
&& NS_FACE_BACKGROUND
(face
)
2401 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2403 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2404 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2407 [FRAME_CURSOR_COLOR
(f
) set];
2409 #ifdef NS_IMPL_COCOA
2410 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2411 atomic. Cleaner ways of doing this should be investigated.
2412 One way would be to set a global variable DRAWING_CURSOR
2413 when making the call to draw_phys..(), don't focus in that
2414 case, then move the ns_unfocus() here after that call. */
2415 NSDisableScreenUpdates
();
2418 switch (cursor_type
)
2422 case FILLED_BOX_CURSOR
:
2425 case HOLLOW_BOX_CURSOR
:
2428 NSRectFill
(NSInsetRect
(r
, 1, 1));
2429 [FRAME_CURSOR_COLOR
(f
) set];
2436 /* If the character under cursor is R2L, draw the bar cursor
2437 on the right of its glyph, rather than on the left. */
2438 cursor_glyph
= get_phys_cursor_glyph
(w
);
2439 if ((cursor_glyph
->resolved_level
& 1) != 0)
2440 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2447 /* draw the character under the cursor */
2448 if (cursor_type
!= NO_CURSOR
)
2449 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2451 #ifdef NS_IMPL_COCOA
2452 NSEnableScreenUpdates
();
2459 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2460 /* --------------------------------------------------------------------------
2461 External (RIF): Draw a vertical line.
2462 -------------------------------------------------------------------------- */
2464 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2466 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2468 NSTRACE
(ns_draw_vertical_window_border
);
2470 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2472 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2474 ns_focus
(f
, &r
, 1);
2481 show_hourglass
(struct atimer
*timer
)
2483 if (hourglass_shown_p
)
2488 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2490 hourglass_shown_p
= 1;
2496 hide_hourglass
(void
)
2498 if (!hourglass_shown_p
)
2503 /* TODO: remove NSProgressIndicator from all frames */
2505 hourglass_shown_p
= 0;
2511 /* ==========================================================================
2513 Glyph drawing operations
2515 ========================================================================== */
2518 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2519 /* --------------------------------------------------------------------------
2520 Wrapper utility to account for internal border width on full-width lines,
2521 and allow top full-width rows to hit the frame top. nr should be pointer
2522 to two successive NSRects. Number of rects actually used is returned.
2523 -------------------------------------------------------------------------- */
2525 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2529 /* --------------------------------------------------------------------
2530 Draw a wavy line under glyph string s. The wave fills wave_height
2537 wave_height = 3 | * * * *
2538 --------------------------------------------------------------------- */
2541 ns_draw_underwave
(struct glyph_string
*s
, CGFloat width
, CGFloat x
)
2543 int wave_height
= 3, wave_length
= 3;
2544 int y
, dx
, dy
, odd
, xmax
;
2549 dy
= wave_height
- 1;
2553 /* Find and set clipping rectangle */
2554 waveClip
= NSMakeRect
(x
, y
, width
, wave_height
);
2555 [[NSGraphicsContext currentContext
] saveGraphicsState
];
2556 NSRectClip
(waveClip
);
2558 /* Draw the waves */
2559 a.x
= x
- ((int
)(x
) % dx);
2561 odd
= (int
)(a.x
/dx
) % 2;
2571 [NSBezierPath strokeLineFromPoint
:a toPoint
:b
];
2572 a.x
= b.x
, a.y
= b.y
;
2573 b.x
+= dx
, b.y
= y
+ odd
*dy
;
2577 /* Restore previous clipping rectangle(s) */
2578 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
2584 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2585 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2586 /* --------------------------------------------------------------------------
2587 Draw underline, overline, and strike-through on glyph string s.
2588 -------------------------------------------------------------------------- */
2590 if (s
->for_overlaps
)
2594 if (face
->underline_p
)
2596 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2598 if (face
->underline_defaulted_p
)
2601 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2603 ns_draw_underwave
(s
, width
, x
);
2605 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2609 unsigned
long thickness
, position
;
2611 /* If the prev was underlined, match its appearance. */
2612 if (s
->prev
&& s
->prev
->face
->underline_p
2613 && s
->prev
->underline_thickness
> 0)
2615 thickness
= s
->prev
->underline_thickness
;
2616 position
= s
->prev
->underline_position
;
2621 unsigned
long descent
;
2624 descent
= s
->y
+ s
->height
- s
->ybase
;
2626 /* Use underline thickness of font, defaulting to 1. */
2627 thickness
= (font
&& font
->underline_thickness
> 0)
2628 ? font
->underline_thickness
: 1;
2630 /* Determine the offset of underlining from the baseline. */
2631 if (x_underline_at_descent_line
)
2632 position
= descent
- thickness
;
2633 else if (x_use_underline_position_properties
2634 && font
&& font
->underline_position
>= 0)
2635 position
= font
->underline_position
;
2637 position
= lround
(font
->descent
/ 2);
2639 position
= underline_minimum_offset
;
2641 position
= max (position
, underline_minimum_offset
);
2643 /* Ensure underlining is not cropped. */
2644 if (descent
<= position
)
2646 position
= descent
- 1;
2649 else if (descent
< position
+ thickness
)
2653 s
->underline_thickness
= thickness
;
2654 s
->underline_position
= position
;
2656 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2658 if (face
->underline_defaulted_p
)
2661 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2665 /* Do overline. We follow other terms in using a thickness of 1
2666 and ignoring overline_margin. */
2667 if (face
->overline_p
)
2670 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2672 if (face
->overline_color_defaulted_p
)
2675 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2679 /* Do strike-through. We follow other terms for thickness and
2680 vertical position.*/
2681 if (face
->strike_through_p
)
2686 dy
= lrint
((s
->height
- 1) / 2);
2687 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2689 if (face
->strike_through_color_defaulted_p
)
2692 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2698 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2699 /* --------------------------------------------------------------------------
2700 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2701 Note we can't just use an NSDrawRect command, because of the possibility
2702 of some sides not being drawn, and because the rect will be filled.
2703 -------------------------------------------------------------------------- */
2709 s.
size.height
= thickness
;
2711 s.origin.y
+= r.
size.height
- thickness
;
2714 s.
size.height
= r.
size.height
;
2715 s.origin.y
= r.origin.y
;
2717 /* left, right (optional) */
2718 s.
size.width
= thickness
;
2723 s.origin.x
+= r.
size.width
- thickness
;
2730 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2731 char top_p
, char bottom_p
, char left_p
, char right_p
,
2732 struct glyph_string
*s
)
2733 /* --------------------------------------------------------------------------
2734 Draw a relief rect inside r, optionally leaving some sides open.
2735 Note we can't just use an NSDrawBezel command, because of the possibility
2736 of some sides not being drawn, and because the rect will be filled.
2737 -------------------------------------------------------------------------- */
2739 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2740 NSColor
*newBaseCol
= nil
;
2743 NSTRACE
(ns_draw_relief
);
2747 if (s
->face
->use_box_color_for_shadows_p
)
2749 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2751 /* else if (s->first_glyph->type == IMAGE_GLYPH
2753 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2755 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2759 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2762 if (newBaseCol
== nil
)
2763 newBaseCol
= [NSColor grayColor
];
2765 if (newBaseCol
!= baseCol
) /* TODO: better check */
2768 baseCol
= [newBaseCol retain
];
2770 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2772 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2775 [(raised_p ? lightCol
: darkCol
) set];
2777 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2780 sr.
size.height
= thickness
;
2781 if (top_p
) NSRectFill
(sr
);
2784 sr.
size.height
= r.
size.height
;
2785 sr.
size.width
= thickness
;
2786 if (left_p
) NSRectFill
(sr
);
2788 [(raised_p ? darkCol
: lightCol
) set];
2791 sr.
size.width
= r.
size.width
;
2792 sr.
size.height
= thickness
;
2793 sr.origin.y
+= r.
size.height
- thickness
;
2794 if (bottom_p
) NSRectFill
(sr
);
2797 sr.
size.height
= r.
size.height
;
2798 sr.origin.y
= r.origin.y
;
2799 sr.
size.width
= thickness
;
2800 sr.origin.x
+= r.
size.width
- thickness
;
2801 if (right_p
) NSRectFill
(sr
);
2806 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2807 /* --------------------------------------------------------------------------
2808 Function modeled after x_draw_glyph_string_box ().
2809 Sets up parameters for drawing.
2810 -------------------------------------------------------------------------- */
2812 int right_x
, last_x
;
2813 char left_p
, right_p
;
2814 struct glyph
*last_glyph
;
2819 if (s
->hl
== DRAW_MOUSE_FACE
)
2821 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2823 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2828 thickness
= face
->box_line_width
;
2830 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2832 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2833 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2834 : window_box_right
(s
->w
, s
->area
));
2835 last_glyph
= (s
->cmp || s
->img
2836 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2838 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2839 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2841 left_p
= (s
->first_glyph
->left_box_line_p
2842 ||
(s
->hl
== DRAW_MOUSE_FACE
2843 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2844 right_p
= (last_glyph
->right_box_line_p
2845 ||
(s
->hl
== DRAW_MOUSE_FACE
2846 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2848 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2850 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2851 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2853 ns_draw_box
(r
, abs (thickness
),
2854 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2859 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2860 1, 1, left_p
, right_p
, s
);
2866 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2867 /* --------------------------------------------------------------------------
2868 Modeled after x_draw_glyph_string_background, which draws BG in
2869 certain cases. Others are left to the text rendering routine.
2870 -------------------------------------------------------------------------- */
2872 NSTRACE
(ns_maybe_dumpglyphs_background
);
2874 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2876 int box_line_width
= max (s
->face
->box_line_width
, 0);
2877 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2878 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2881 if (s
->hl
== DRAW_MOUSE_FACE
)
2883 face
= FACE_FROM_ID
(s
->f
,
2884 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2886 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2889 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2891 [(NS_FACE_BACKGROUND
(face
) != 0
2892 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2893 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2896 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2897 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2900 if (s
->hl
!= DRAW_CURSOR
)
2902 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2903 s
->background_width
,
2904 s
->height
-2*box_line_width
);
2908 s
->background_filled_p
= 1;
2915 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2916 /* --------------------------------------------------------------------------
2917 Renders an image and associated borders.
2918 -------------------------------------------------------------------------- */
2920 EmacsImage
*img
= s
->img
->pixmap
;
2921 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2922 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2923 int bg_x
, bg_y
, bg_height
;
2930 NSTRACE
(ns_dumpglyphs_image
);
2932 if (s
->face
->box
!= FACE_NO_BOX
2933 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
2934 x
+= abs (s
->face
->box_line_width
);
2937 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
2938 bg_height
= s
->height
;
2939 /* other terms have this, but was causing problems w/tabbar mode */
2940 /* - 2 * box_line_vwidth; */
2942 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
2943 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
2945 /* Draw BG: if we need larger area than image itself cleared, do that,
2946 otherwise, since we composite the image under NS (instead of mucking
2947 with its background color), we must clear just the image area. */
2948 if (s
->hl
== DRAW_MOUSE_FACE
)
2950 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2952 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2955 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2957 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
2959 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
2960 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
2962 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
2963 s
->background_filled_p
= 1;
2967 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
2972 /* Draw the image.. do we need to draw placeholder if img ==nil? */
2975 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
2976 NSRect dr
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
2977 NSRect ir
= NSMakeRect
(s
->slice.x
, s
->slice.y
,
2978 s
->slice.width
, s
->slice.height
);
2981 operation
: NSCompositeSourceOver
2986 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
2987 operation
: NSCompositeSourceOver
];
2991 if (s
->hl
== DRAW_CURSOR
)
2993 [FRAME_CURSOR_COLOR
(s
->f
) set];
2994 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
2995 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
2997 /* Currently on NS img->mask is always 0. Since
2998 get_window_cursor_type specifies a hollow box cursor when on
2999 a non-masked image we never reach this clause. But we put it
3000 in in anticipation of better support for image masks on
3002 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3006 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3009 /* Draw underline, overline, strike-through. */
3010 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3012 /* Draw relief, if requested */
3013 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3015 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3017 th
= tool_bar_button_relief
>= 0 ?
3018 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3019 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3023 th
= abs (s
->img
->relief
);
3024 raised_p
= (s
->img
->relief
> 0);
3027 r.origin.x
= x
- th
;
3028 r.origin.y
= y
- th
;
3029 r.
size.width
= s
->slice.width
+ 2*th
-1;
3030 r.
size.height
= s
->slice.height
+ 2*th
-1;
3031 ns_draw_relief
(r
, th
, raised_p
,
3033 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3035 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3038 /* If there is no mask, the background won't be seen,
3039 so draw a rectangle on the image for the cursor.
3040 Do this for all images, getting transparency right is not reliable. */
3041 if (s
->hl
== DRAW_CURSOR
)
3043 int thickness
= abs (s
->img
->relief
);
3044 if (thickness
== 0) thickness
= 1;
3045 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3051 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3056 NSColor
*fgCol
, *bgCol
;
3058 if (!s
->background_filled_p
)
3060 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3061 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3063 ns_focus
(s
->f
, r
, n
);
3065 if (s
->hl
== DRAW_MOUSE_FACE
)
3067 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3069 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3072 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3074 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3075 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3077 for (i
= 0; i
< n
; ++i
)
3079 if (!s
->row
->full_width_p
)
3081 int overrun
, leftoverrun
;
3083 /* truncate to avoid overwriting fringe and/or scrollbar */
3084 overrun
= max (0, (s
->x
+ s
->background_width
)
3085 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3086 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3087 r
[i
].
size.width
-= overrun
;
3089 /* truncate to avoid overwriting to left of the window box */
3090 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3091 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3093 if (leftoverrun
> 0)
3095 r
[i
].origin.x
+= leftoverrun
;
3096 r
[i
].
size.width
-= leftoverrun
;
3099 /* XXX: Try to work between problem where a stretch glyph on
3100 a partially-visible bottom row will clear part of the
3101 modeline, and another where list-buffers headers and similar
3102 rows erroneously have visible_height set to 0. Not sure
3103 where this is coming from as other terms seem not to show. */
3104 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3109 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3110 overwriting cursor (usually when cursor on a tab) */
3111 if (s
->hl
== DRAW_CURSOR
)
3116 width
= s
->w
->phys_cursor_width
;
3117 r
[i
].
size.width
-= width
;
3118 r
[i
].origin.x
+= width
;
3122 /* Draw overlining, etc. on the cursor. */
3123 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3124 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3126 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3133 /* Draw overlining, etc. on the stretch glyph (or the part
3134 of the stretch glyph after the cursor). */
3135 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3139 s
->background_filled_p
= 1;
3145 ns_draw_glyph_string
(struct glyph_string
*s
)
3146 /* --------------------------------------------------------------------------
3147 External (RIF): Main draw-text call.
3148 -------------------------------------------------------------------------- */
3150 /* TODO (optimize): focus for box and contents draw */
3153 char box_drawn_p
= 0;
3155 NSTRACE
(ns_draw_glyph_string
);
3157 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3160 struct glyph_string
*next
;
3162 for (width
= 0, next
= s
->next
;
3163 next
&& width
< s
->right_overhang
;
3164 width
+= next
->width
, next
= next
->next
)
3165 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3167 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3169 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3170 ns_focus
(s
->f
, r
, n
);
3171 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3176 ns_dumpglyphs_stretch
(s
->next
);
3178 next
->num_clips
= 0;
3182 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3183 && (s
->first_glyph
->type == CHAR_GLYPH
3184 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3186 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3187 ns_focus
(s
->f
, r
, n
);
3188 ns_maybe_dumpglyphs_background
(s
, 1);
3189 ns_dumpglyphs_box_or_relief
(s
);
3194 switch (s
->first_glyph
->type)
3198 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3199 ns_focus
(s
->f
, r
, n
);
3200 ns_dumpglyphs_image
(s
, r
[0]);
3205 ns_dumpglyphs_stretch
(s
);
3209 case COMPOSITE_GLYPH
:
3210 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3211 ns_focus
(s
->f
, r
, n
);
3213 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3214 && ! s
->first_glyph
->u.cmp.automatic
))
3215 s
->background_filled_p
= 1;
3217 ns_maybe_dumpglyphs_background
3218 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3220 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3221 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3222 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3223 NS_DUMPGLYPH_NORMAL
));
3224 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3225 if (ns_tmp_font
== NULL)
3226 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3228 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3230 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3231 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3232 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3235 ns_tmp_font
->font.driver
->draw
3236 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3237 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3238 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
3240 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3242 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3243 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3244 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3250 case GLYPHLESS_GLYPH
:
3251 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3252 ns_focus
(s
->f
, r
, n
);
3254 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3255 && ! s
->first_glyph
->u.cmp.automatic
))
3256 s
->background_filled_p
= 1;
3258 ns_maybe_dumpglyphs_background
3259 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3261 /* Not yet implemented. */
3270 /* Draw box if not done already. */
3271 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3273 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3274 ns_focus
(s
->f
, r
, n
);
3275 ns_dumpglyphs_box_or_relief
(s
);
3284 /* ==========================================================================
3288 ========================================================================== */
3292 ns_send_appdefined
(int value
)
3293 /* --------------------------------------------------------------------------
3294 Internal: post an appdefined event which EmacsApp-sendEvent will
3295 recognize and take as a command to halt the event loop.
3296 -------------------------------------------------------------------------- */
3298 /*NSTRACE (ns_send_appdefined); */
3300 /* Only post this event if we haven't already posted one. This will end
3301 the [NXApp run] main loop after having processed all events queued at
3303 if (send_appdefined
)
3307 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3308 send_appdefined
= NO
;
3310 /* Don't need wakeup timer any more */
3313 [timed_entry invalidate
];
3314 [timed_entry release
];
3318 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3319 location
: NSMakePoint
(0, 0)
3322 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3323 context
: [NSApp context
]
3328 /* Post an application defined event on the event queue. When this is
3329 received the [NXApp run] will return, thus having processed all
3330 events which are currently queued. */
3331 [NSApp postEvent
: nxev atStart
: NO
];
3336 ns_read_socket
(struct terminal *terminal, struct input_event
*hold_quit
)
3337 /* --------------------------------------------------------------------------
3338 External (hook): Post an event to ourself and keep reading events until
3339 we read it back again. In effect process all events which were waiting.
3340 From 21+ we have to manage the event buffer ourselves.
3341 -------------------------------------------------------------------------- */
3343 struct input_event ev
;
3346 /* NSTRACE (ns_read_socket); */
3348 if ([NSApp modalWindow
] != nil
)
3352 n_emacs_events_pending
= 0;
3355 q_event_ptr
= hold_quit
;
3357 /* we manage autorelease pools by allocate/reallocate each time around
3358 the loop; strict nesting is occasionally violated but seems not to
3359 matter.. earlier methods using full nesting caused major memory leaks */
3360 [outerpool release
];
3361 outerpool
= [[NSAutoreleasePool alloc
] init
];
3363 /* If have pending open-file requests, attend to the next one of those. */
3364 if (ns_pending_files
&& [ns_pending_files count
] != 0
3365 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3367 [ns_pending_files removeObjectAtIndex
: 0];
3369 /* Deal with pending service requests. */
3370 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3372 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3373 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3375 [ns_pending_service_names removeObjectAtIndex
: 0];
3376 [ns_pending_service_args removeObjectAtIndex
: 0];
3380 /* Run and wait for events. We must always send one NX_APPDEFINED event
3381 to ourself, otherwise [NXApp run] will never exit. */
3382 send_appdefined
= YES
;
3383 ns_send_appdefined
(-1);
3385 if (++apploopnr
!= 1)
3393 nevents
= n_emacs_events_pending
;
3394 n_emacs_events_pending
= 0;
3395 emacs_event
= q_event_ptr
= NULL;
3403 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3404 fd_set
*exceptfds
, EMACS_TIME
*timeout
, sigset_t
*sigmask
)
3405 /* --------------------------------------------------------------------------
3406 Replacement for select, checking for events
3407 -------------------------------------------------------------------------- */
3412 struct input_event event
;
3415 /* NSTRACE (ns_select); */
3417 for (k
= 0; readfds
&& k
< nfds
+1; k
++)
3418 if (FD_ISSET
(k
, readfds
)) ++nr
;
3421 ||
(timeout
&& timeout
->tv_sec
== 0 && timeout
->tv_nsec
== 0))
3422 return pselect
(nfds
, readfds
, writefds
, exceptfds
, timeout
, sigmask
);
3424 [outerpool release
];
3425 outerpool
= [[NSAutoreleasePool alloc
] init
];
3428 send_appdefined
= YES
;
3431 pthread_mutex_lock
(&select_mutex
);
3436 select_readfds
= *readfds
;
3437 select_valid
+= SELECT_HAVE_READ
;
3441 select_writefds
= *writefds
;
3442 select_valid
+= SELECT_HAVE_WRITE
;
3447 select_timeout
= *timeout
;
3448 select_valid
+= SELECT_HAVE_TMO
;
3451 pthread_mutex_unlock
(&select_mutex
);
3453 /* Inform fd_handler that select should be called */
3455 write
(selfds
[1], &c
, 1);
3457 else if (nr
== 0 && timeout
)
3459 /* No file descriptor, just a timeout, no need to wake fd_handler */
3460 double time
= EMACS_TIME_TO_DOUBLE
(*timeout
);
3461 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3464 @selector
(timeout_handler
:)
3469 else /* No timeout and no file descriptors, can this happen? */
3471 /* Send appdefined so we exit from the loop */
3472 ns_send_appdefined
(-1);
3477 emacs_event
= &event
;
3478 if (++apploopnr
!= 1)
3485 if (nr
> 0 && readfds
)
3488 write
(selfds
[1], &c
, 1);
3492 ev
= last_appdefined_event
;
3497 if ([ev
type] != NSApplicationDefined
)
3501 last_appdefined_event
= 0;
3505 /* The NX_APPDEFINED event we received was a timeout. */
3510 /* The NX_APPDEFINED event we received was the result of
3511 at least one real input event arriving. */
3517 /* Received back from select () in fd_handler; copy the results */
3518 pthread_mutex_lock
(&select_mutex
);
3519 if (readfds
) *readfds
= select_readfds
;
3520 if (writefds
) *writefds
= select_writefds
;
3521 if (timeout
) *timeout
= select_timeout
;
3522 pthread_mutex_unlock
(&select_mutex
);
3532 /* ==========================================================================
3536 ========================================================================== */
3540 ns_set_vertical_scroll_bar
(struct window
*window
,
3541 int portion
, int whole
, int position
)
3542 /* --------------------------------------------------------------------------
3543 External (hook): Update or add scrollbar
3544 -------------------------------------------------------------------------- */
3548 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3549 EmacsView
*view = FRAME_NS_VIEW
(f
);
3550 int window_y
, window_height
;
3551 int top
, left
, height
, width
, sb_width
, sb_left
;
3553 BOOL fringe_extended_p
;
3555 /* optimization; display engine sends WAY too many of these.. */
3556 if (!NILP
(window
->vertical_scroll_bar
))
3558 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3559 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3561 if (view->scrollbarsNeedingUpdate
== 0)
3563 if (!windows_or_buffers_changed
)
3567 view->scrollbarsNeedingUpdate
--;
3571 NSTRACE
(ns_set_vertical_scroll_bar
);
3573 /* Get dimensions. */
3574 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3576 height
= window_height
;
3577 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3578 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3580 /* allow for displaying a skinnier scrollbar than char area allotted */
3581 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3582 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3585 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3586 /* the parent view is flipped, so we need to flip y value */
3588 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3590 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(window
))
3591 fringe_extended_p
= (WINDOW_LEFTMOST_P
(window
)
3592 && WINDOW_LEFT_FRINGE_WIDTH
(window
)
3593 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3594 || WINDOW_LEFT_MARGIN_COLS
(window
) == 0));
3596 fringe_extended_p
= (WINDOW_RIGHTMOST_P
(window
)
3597 && WINDOW_RIGHT_FRINGE_WIDTH
(window
)
3598 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3599 || WINDOW_RIGHT_MARGIN_COLS
(window
) == 0));
3601 XSETWINDOW
(win
, window
);
3604 /* we want at least 5 lines to display a scrollbar */
3605 if (WINDOW_TOTAL_LINES
(window
) < 5)
3607 if (!NILP
(window
->vertical_scroll_bar
))
3609 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3610 [bar removeFromSuperview
];
3611 wset_vertical_scroll_bar
(window
, Qnil
);
3613 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3618 if (NILP
(window
->vertical_scroll_bar
))
3620 if (width
> 0 && height
> 0)
3622 if (fringe_extended_p
)
3623 ns_clear_frame_area
(f
, sb_left
, top
, sb_width
, height
);
3625 ns_clear_frame_area
(f
, left
, top
, width
, height
);
3628 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3629 wset_vertical_scroll_bar
(window
, make_save_value
(bar, 0));
3634 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3635 oldRect
= [bar frame
];
3636 r.
size.width
= oldRect.
size.width
;
3637 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3639 if (oldRect.origin.x
!= r.origin.x
)
3640 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3645 [bar setPosition
: position portion
: portion whole
: whole
];
3651 ns_condemn_scroll_bars
(struct frame
*f
)
3652 /* --------------------------------------------------------------------------
3653 External (hook): arrange for all frame's scrollbars to be removed
3654 at next call to judge_scroll_bars, except for those redeemed.
3655 -------------------------------------------------------------------------- */
3659 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3661 NSTRACE
(ns_condemn_scroll_bars
);
3663 for (i
=[subviews count
]-1; i
>= 0; i
--)
3665 view = [subviews objectAtIndex
: i
];
3666 if ([view isKindOfClass
: [EmacsScroller
class]])
3673 ns_redeem_scroll_bar
(struct window
*window
)
3674 /* --------------------------------------------------------------------------
3675 External (hook): arrange to spare this window's scrollbar
3676 at next call to judge_scroll_bars.
3677 -------------------------------------------------------------------------- */
3680 NSTRACE
(ns_redeem_scroll_bar
);
3681 if (!NILP
(window
->vertical_scroll_bar
))
3683 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3690 ns_judge_scroll_bars
(struct frame
*f
)
3691 /* --------------------------------------------------------------------------
3692 External (hook): destroy all scrollbars on frame that weren't
3693 redeemed after call to condemn_scroll_bars.
3694 -------------------------------------------------------------------------- */
3698 EmacsView
*eview
= FRAME_NS_VIEW
(f
);
3699 NSArray
*subviews
= [[eview superview
] subviews
];
3702 NSTRACE
(ns_judge_scroll_bars
);
3703 for (i
= [subviews count
]-1; i
>= 0; --i
)
3705 view = [subviews objectAtIndex
: i
];
3706 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3712 [eview updateFrameSize
: NO
];
3717 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3719 /* XXX irrelevant under NS */
3724 /* ==========================================================================
3728 ========================================================================== */
3731 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3733 NSScreen
*screen
= [NSScreen mainScreen
];
3734 return [screen frame
].
size.height
;
3738 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3740 NSScreen
*screen
= [NSScreen mainScreen
];
3741 return [screen frame
].
size.width
;
3745 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3746 /* --------------------------------------------------------------------------
3747 Convert modifier name to lisp symbol
3748 -------------------------------------------------------------------------- */
3750 if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3752 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3754 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3756 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3758 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3760 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3768 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3769 Lisp_Object yesval
, Lisp_Object noval
,
3770 BOOL is_float
, BOOL is_modstring
)
3771 /* --------------------------------------------------------------------------
3772 Check a parameter value in user's preferences
3773 -------------------------------------------------------------------------- */
3775 const
char *value
= ns_get_defaults_value
(parameter
);
3781 if (c_strcasecmp
(value
, "YES"
) == 0)
3783 else if (c_strcasecmp
(value
, "NO"
) == 0)
3785 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3786 *result
= make_float
(f
);
3787 else if (is_modstring
&& value
)
3788 *result
= ns_string_to_lispmod
(value
);
3789 else fprintf (stderr
,
3790 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3796 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3797 /* --------------------------------------------------------------------------
3798 Initialize global info and storage for display.
3799 -------------------------------------------------------------------------- */
3801 NSScreen
*screen
= [NSScreen mainScreen
];
3802 NSWindowDepth depth
= [screen depth
];
3803 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
3805 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3806 dpyinfo
->resy
= 72.27;
3807 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3808 NSColorSpaceFromDepth
(depth
)]
3809 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3810 NSColorSpaceFromDepth
(depth
)];
3811 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3812 dpyinfo
->image_cache
= make_image_cache
();
3813 dpyinfo
->color_table
= xmalloc
(sizeof
*dpyinfo
->color_table
);
3814 dpyinfo
->color_table
->colors
= NULL;
3815 dpyinfo
->root_window
= 42; /* a placeholder.. */
3817 hlinfo
->mouse_face_mouse_frame
= NULL;
3818 hlinfo
->mouse_face_deferred_gc
= 0;
3819 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
3820 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
3821 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3822 hlinfo
->mouse_face_window
= hlinfo
->mouse_face_overlay
= Qnil
;
3823 hlinfo
->mouse_face_hidden
= 0;
3825 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
3826 hlinfo
->mouse_face_defer
= 0;
3828 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3830 dpyinfo
->n_fonts
= 0;
3831 dpyinfo
->smallest_font_height
= 1;
3832 dpyinfo
->smallest_char_width
= 1;
3836 /* This and next define (many of the) public functions in this file. */
3837 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3838 with using despite presence in the "system dependent" redisplay
3839 interface. In addition, many of the ns_ methods have code that is
3840 shared with all terms, indicating need for further refactoring. */
3841 extern frame_parm_handler ns_frame_parm_handlers
[];
3842 static
struct redisplay_interface ns_redisplay_interface
=
3844 ns_frame_parm_handlers
,
3848 x_clear_end_of_line
,
3850 ns_after_update_window_line
,
3851 ns_update_window_begin
,
3852 ns_update_window_end
,
3855 0, /* flush_display_optional */
3856 x_clear_window_mouse_face
,
3857 x_get_glyph_overhangs
,
3858 x_fix_overlapping_area
,
3859 ns_draw_fringe_bitmap
,
3860 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3861 0, /* destroy_fringe_bitmap */
3862 ns_compute_glyph_string_overhangs
,
3863 ns_draw_glyph_string
, /* interface to nsfont.m */
3864 ns_define_frame_cursor
,
3865 ns_clear_frame_area
,
3866 ns_draw_window_cursor
,
3867 ns_draw_vertical_window_border
,
3868 ns_shift_glyphs_for_insert
3873 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3879 /* This function is called when the last frame on a display is deleted. */
3881 ns_delete_terminal
(struct terminal *terminal)
3883 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3885 /* Protect against recursive calls. delete_frame in
3886 delete_terminal calls us back when it deletes our last frame. */
3887 if (!terminal->name
)
3892 x_destroy_all_bitmaps
(dpyinfo
);
3893 ns_delete_display
(dpyinfo
);
3898 static
struct terminal *
3899 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3900 /* --------------------------------------------------------------------------
3901 Set up use of NS before we make the first connection.
3902 -------------------------------------------------------------------------- */
3904 struct terminal *terminal;
3906 NSTRACE
(ns_create_terminal
);
3908 terminal = create_terminal
();
3910 terminal->type = output_ns
;
3911 terminal->display_info.ns
= dpyinfo
;
3912 dpyinfo
->terminal = terminal;
3914 terminal->rif
= &ns_redisplay_interface
;
3916 terminal->clear_frame_hook
= ns_clear_frame
;
3917 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
3918 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
3919 terminal->ring_bell_hook
= ns_ring_bell
;
3920 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
3921 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
3922 terminal->update_begin_hook
= ns_update_begin
;
3923 terminal->update_end_hook
= ns_update_end
;
3924 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
3925 terminal->read_socket_hook
= ns_read_socket
;
3926 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
3927 terminal->mouse_position_hook
= ns_mouse_position
;
3928 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
3929 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
3931 terminal->fullscreen_hook
= ns_fullscreen_hook
;
3933 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
3934 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
3935 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
3936 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
3938 terminal->delete_frame_hook
= x_destroy_window
;
3939 terminal->delete_terminal_hook
= ns_delete_terminal
;
3941 terminal->scroll_region_ok
= 1;
3942 terminal->char_ins_del_ok
= 1;
3943 terminal->line_ins_del_ok
= 1;
3944 terminal->fast_clear_end_of_line
= 1;
3945 terminal->memory_below_frame
= 0;
3951 struct ns_display_info
*
3952 ns_term_init
(Lisp_Object display_name
)
3953 /* --------------------------------------------------------------------------
3954 Start the Application and get things rolling.
3955 -------------------------------------------------------------------------- */
3957 struct terminal *terminal;
3958 struct ns_display_info
*dpyinfo
;
3959 static int ns_initialized
= 0;
3962 if (ns_initialized
) return x_display_list
;
3965 NSTRACE
(ns_term_init
);
3967 [outerpool release
];
3968 outerpool
= [[NSAutoreleasePool alloc
] init
];
3970 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
3971 /*GSDebugAllocationActive (YES); */
3975 Fset_input_interrupt_mode
(Qnil
);
3977 if (selfds
[0] == -1)
3979 if (pipe
(selfds
) == -1)
3981 fprintf (stderr
, "Failed to create pipe
: %s\n",
3982 emacs_strerror
(errno
));
3986 fcntl
(selfds
[0], F_SETFL
, O_NONBLOCK|fcntl
(selfds
[0], F_GETFL
));
3987 FD_ZERO
(&select_readfds
);
3988 FD_ZERO
(&select_writefds
);
3989 pthread_mutex_init
(&select_mutex
, NULL);
3992 ns_pending_files
= [[NSMutableArray alloc
] init
];
3993 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
3994 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
3996 /* Start app and create the main menu, window, view.
3997 Needs to be here because ns_initialize_display_info () uses AppKit classes.
3998 The view will then ask the NSApp to stop and return to Emacs. */
3999 [EmacsApp sharedApplication
];
4002 [NSApp setDelegate
: NSApp
];
4004 /* Start the select thread. */
4005 [NSThread detachNewThreadSelector
:@selector
(fd_handler
:)
4009 /* debugging: log all notifications */
4010 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4011 selector: @selector (logNotification:)
4012 name: nil object: nil]; */
4014 dpyinfo
= xzalloc
(sizeof
*dpyinfo
);
4016 ns_initialize_display_info
(dpyinfo
);
4017 terminal = ns_create_terminal
(dpyinfo
);
4019 terminal->kboard
= xmalloc
(sizeof
*terminal->kboard
);
4020 init_kboard
(terminal->kboard
);
4021 kset_window_system
(terminal->kboard
, Qns
);
4022 terminal->kboard
->next_kboard
= all_kboards
;
4023 all_kboards
= terminal->kboard
;
4024 /* Don't let the initial kboard remain current longer than necessary.
4025 That would cause problems if a file loaded on startup tries to
4026 prompt in the mini-buffer. */
4027 if (current_kboard
== initial_kboard
)
4028 current_kboard
= terminal->kboard
;
4029 terminal->kboard
->reference_count
++;
4031 dpyinfo
->next
= x_display_list
;
4032 x_display_list
= dpyinfo
;
4034 /* Put it on ns_display_name_list */
4035 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
4036 ns_display_name_list
);
4037 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
4039 terminal->name
= xstrdup
(SSDATA
(display_name
));
4043 if (!inhibit_x_resources
)
4045 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4048 /* this is a standard variable */
4049 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4050 make_float
(10.0), make_float
(6.0), YES
, NO
);
4051 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4054 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
4055 stringForKey
: @"AppleHighlightColor"
];
4056 if (ns_selection_color
== nil
)
4057 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
4060 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4064 Lisp_Object color_file
, color_map
, color
;
4068 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4069 Fsymbol_value
(intern
("data
-directory"
)));
4070 if (NILP
(Ffile_readable_p
(color_file
)))
4071 fatal
("Could not
find %s.\n", SDATA (color_file));
4073 color_map
= Fx_load_color_file
(color_file
);
4074 if (NILP
(color_map
))
4075 fatal
("Could not read
%s.\n", SDATA (color_file));
4077 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4078 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4080 color
= XCAR
(color_map
);
4081 name
= SSDATA
(XCAR
(color
));
4082 c
= XINT
(XCDR
(color
));
4084 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4085 green
: GREEN_FROM_ULONG
(c
) / 255.0
4086 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4088 forKey
: [NSString stringWithUTF8String
: name
]];
4090 [cl writeToFile
: nil
];
4095 #ifdef NS_IMPL_GNUSTEP
4096 Vwindow_system_version
= build_string
(gnustep_base_version
);
4098 /*PSnextrelease (128, c); */
4099 char c
[DBL_BUFSIZE_BOUND
];
4100 int len
= dtoastr
(c
, sizeof c
, 0, 0, NSAppKitVersionNumber
);
4101 Vwindow_system_version
= make_unibyte_string
(c
, len
);
4105 delete_keyboard_wait_descriptor
(0);
4107 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4109 /* Set up OS X app menu */
4110 #ifdef NS_IMPL_COCOA
4114 /* set up the application menu */
4115 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4116 [svcsMenu setAutoenablesItems
: NO
];
4117 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4118 [appMenu setAutoenablesItems
: NO
];
4119 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4120 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4122 [appMenu insertItemWithTitle
: @"About Emacs"
4123 action
: @selector
(orderFrontStandardAboutPanel
:)
4126 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4127 [appMenu insertItemWithTitle
: @"Preferences..."
4128 action
: @selector
(showPreferencesWindow
:)
4131 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4132 item
= [appMenu insertItemWithTitle
: @"Services"
4133 action
: @selector
(menuDown
:)
4136 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4137 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4138 [appMenu insertItemWithTitle
: @"Hide Emacs"
4139 action
: @selector
(hide
:)
4142 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4143 action
: @selector
(hideOtherApplications
:)
4146 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4147 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4148 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4149 action
: @selector
(terminate
:)
4153 item
= [mainMenu insertItemWithTitle
: ns_app_name
4154 action
: @selector
(menuDown
:)
4157 [mainMenu setSubmenu
: appMenu forItem
: item
];
4158 [dockMenu insertItemWithTitle
: @"New Frame"
4159 action
: @selector
(newFrame
:)
4163 [NSApp setMainMenu
: mainMenu
];
4164 [NSApp setAppleMenu
: appMenu
];
4165 [NSApp setServicesMenu
: svcsMenu
];
4166 /* Needed at least on Cocoa, to get dock menu to show windows */
4167 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4169 [[NSNotificationCenter defaultCenter
]
4170 addObserver
: mainMenu
4171 selector
: @selector
(trackingNotification
:)
4172 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4173 [[NSNotificationCenter defaultCenter
]
4174 addObserver
: mainMenu
4175 selector
: @selector
(trackingNotification
:)
4176 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4178 #endif
/* MAC OS X menu setup */
4180 /* Register our external input/output types, used for determining
4181 applicable services and also drag/drop eligibility. */
4182 ns_send_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
] retain
];
4183 ns_return_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
]
4185 ns_drag_types
= [[NSArray arrayWithObjects
:
4187 NSTabularTextPboardType
,
4188 NSFilenamesPboardType
,
4191 NSFontPboardType
, nil
] retain
];
4193 #ifndef NEW_STYLE_FS
4194 /* If fullscreen is in init/default-frame-alist, focus isn't set
4195 right for fullscreen windows, so set this. */
4196 [NSApp activateIgnoringOtherApps
:YES
];
4200 ns_do_open_file
= YES
;
4206 ns_term_shutdown
(int sig
)
4208 [[NSUserDefaults standardUserDefaults
] synchronize
];
4210 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4211 if (STRINGP
(Vauto_save_list_file_name
))
4212 unlink
(SSDATA
(Vauto_save_list_file_name
));
4214 if (sig
== 0 || sig
== SIGTERM
)
4216 [NSApp terminate
: NSApp
];
4218 else // force a stack
trace to happen
4225 /* ==========================================================================
4227 EmacsApp implementation
4229 ========================================================================== */
4232 @implementation EmacsApp
4234 - (void
)logNotification
: (NSNotification
*)notification
4236 const
char *name
= [[notification name
] UTF8String
];
4237 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4238 && !strstr
(name
, "WindowNumber"
))
4239 NSLog
(@"notification
: '%@'"
, [notification name
]);
4243 - (void
)sendEvent
: (NSEvent
*)theEvent
4244 /* --------------------------------------------------------------------------
4245 Called when NSApp is running for each event received. Used to stop
4246 the loop when we choose, since there's no way to just run one iteration.
4247 -------------------------------------------------------------------------- */
4249 int
type = [theEvent
type];
4250 NSWindow
*window
= [theEvent window
];
4251 /* NSTRACE (sendEvent); */
4252 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4254 #ifdef NS_IMPL_COCOA
4255 if (type == NSApplicationDefined
4256 && [theEvent data2
] == NSAPP_DATA2_RUNASSCRIPT
)
4264 if (type == NSCursorUpdate
&& window
== nil
)
4266 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4270 if (type == NSApplicationDefined
)
4272 /* Events posted by ns_send_appdefined interrupt the run loop here.
4273 But, if a modal window is up, an appdefined can still come through,
4274 (e.g., from a makeKeyWindow event) but stopping self also stops the
4275 modal loop. Just defer it until later. */
4276 if ([NSApp modalWindow
] == nil
)
4278 last_appdefined_event
= theEvent
;
4283 send_appdefined
= YES
;
4287 [super sendEvent
: theEvent
];
4291 - (void
)showPreferencesWindow
: (id
)sender
4293 struct frame
*emacsframe
= SELECTED_FRAME
();
4294 NSEvent
*theEvent
= [NSApp currentEvent
];
4298 emacs_event
->kind
= NS_NONKEY_EVENT
;
4299 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4300 emacs_event
->modifiers
= 0;
4301 EV_TRAILER
(theEvent
);
4305 - (void
)newFrame
: (id
)sender
4307 struct frame
*emacsframe
= SELECTED_FRAME
();
4308 NSEvent
*theEvent
= [NSApp currentEvent
];
4312 emacs_event
->kind
= NS_NONKEY_EVENT
;
4313 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4314 emacs_event
->modifiers
= 0;
4315 EV_TRAILER
(theEvent
);
4319 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4320 - (BOOL
) openFile
: (NSString
*)fileName
4322 struct frame
*emacsframe
= SELECTED_FRAME
();
4323 NSEvent
*theEvent
= [NSApp currentEvent
];
4328 emacs_event
->kind
= NS_NONKEY_EVENT
;
4329 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4330 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4331 ns_input_line
= Qnil
; /* can be start or cons start,end */
4332 emacs_event
->modifiers
=0;
4333 EV_TRAILER
(theEvent
);
4339 /* **************************************************************************
4341 EmacsApp delegate implementation
4343 ************************************************************************** */
4345 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4346 /* --------------------------------------------------------------------------
4347 When application is loaded, terminate event loop in ns_term_init
4348 -------------------------------------------------------------------------- */
4350 NSTRACE
(applicationDidFinishLaunching
);
4351 [NSApp setServicesProvider
: NSApp
];
4352 ns_send_appdefined
(-2);
4356 /* Termination sequences:
4359 MenuBar | File | Exit:
4360 Select Quit from App menubar:
4362 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4365 Select Quit from Dock menu:
4368 Cancel -> Nothing else
4372 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4377 - (void
) terminate
: (id
)sender
4379 struct frame
*emacsframe
= SELECTED_FRAME
();
4384 emacs_event
->kind
= NS_NONKEY_EVENT
;
4385 emacs_event
->code
= KEY_NS_POWER_OFF
;
4386 emacs_event
->arg
= Qt
; /* mark as non-key event */
4387 EV_TRAILER
((id
)nil
);
4391 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4395 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4396 return NSTerminateNow
;
4398 ret
= NSRunAlertPanel
(ns_app_name
,
4399 @"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
,
4400 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4402 if (ret
== NSAlertDefaultReturn
)
4403 return NSTerminateNow
;
4404 else if (ret
== NSAlertAlternateReturn
)
4405 return NSTerminateCancel
;
4406 return NSTerminateNow
; /* just in case */
4410 not_in_argv
(NSString
*arg
)
4413 const
char *a
= [arg UTF8String
];
4414 for (k
= 1; k
< initial_argc
; ++k
)
4415 if (strcmp (a
, initial_argv
[k
]) == 0) return 0;
4419 /* Notification from the Workspace to open a file */
4420 - (BOOL
)application
: sender openFile
: (NSString
*)file
4422 if (ns_do_open_file || not_in_argv
(file
))
4423 [ns_pending_files addObject
: file
];
4428 /* Open a file as a temporary file */
4429 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4431 if (ns_do_open_file || not_in_argv
(file
))
4432 [ns_pending_files addObject
: file
];
4437 /* Notification from the Workspace to open a file noninteractively (?) */
4438 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4440 if (ns_do_open_file || not_in_argv
(file
))
4441 [ns_pending_files addObject
: file
];
4445 /* Notification from the Workspace to open multiple files */
4446 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4448 NSEnumerator
*files
= [fileList objectEnumerator
];
4450 /* Don't open files from the command line unconditionally,
4451 Cocoa parses the command line wrong, --option value tries to open value
4452 if --option is the last option. */
4453 while ((file
= [files nextObject
]) != nil
)
4454 if (ns_do_open_file || not_in_argv
(file
))
4455 [ns_pending_files addObject
: file
];
4457 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4462 /* Handle dock menu requests. */
4463 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4469 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4470 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4472 //ns_app_active
=YES
;
4474 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4476 NSTRACE
(applicationDidBecomeActive
);
4478 //ns_app_active
=YES
;
4480 ns_update_auto_hide_menu_bar
();
4481 // No constraining takes place when the application is not active.
4482 ns_constrain_all_frames
();
4484 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4487 ns_send_appdefined
(-1);
4492 /* ==========================================================================
4494 EmacsApp aux handlers for managing event loop
4496 ========================================================================== */
4499 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4500 /* --------------------------------------------------------------------------
4501 The timeout specified to ns_select has passed.
4502 -------------------------------------------------------------------------- */
4504 /*NSTRACE (timeout_handler); */
4505 ns_send_appdefined
(-2);
4508 - (void
)fd_handler
:(id
)unused
4509 /* --------------------------------------------------------------------------
4510 Check data waiting on file descriptors and terminate if so
4511 -------------------------------------------------------------------------- */
4514 int waiting
= 1, nfds
;
4517 SELECT_TYPE readfds
, writefds
, *wfds
;
4518 EMACS_TIME timeout
, *tmo
;
4519 NSAutoreleasePool
*pool
= nil
;
4521 /* NSTRACE (fd_handler); */
4526 pool
= [[NSAutoreleasePool alloc
] init
];
4532 FD_SET
(selfds
[0], &fds
);
4533 result
= select
(selfds
[0]+1, &fds
, NULL, NULL, NULL);
4536 read
(selfds
[0], &c
, 1);
4537 if (c
== 'g') waiting
= 0;
4542 pthread_mutex_lock
(&select_mutex
);
4545 if (select_valid
& SELECT_HAVE_READ
)
4546 readfds
= select_readfds
;
4550 if (select_valid
& SELECT_HAVE_WRITE
)
4552 writefds
= select_writefds
;
4557 if (select_valid
& SELECT_HAVE_TMO
)
4559 timeout
= select_timeout
;
4565 pthread_mutex_unlock
(&select_mutex
);
4567 FD_SET
(selfds
[0], &readfds
);
4568 if (selfds
[0] >= nfds
) nfds
= selfds
[0]+1;
4570 result
= pselect
(nfds
, &readfds
, wfds
, NULL, tmo
, NULL);
4573 ns_send_appdefined
(-2);
4574 else if (result
> 0)
4576 if (FD_ISSET
(selfds
[0], &readfds
))
4578 read
(selfds
[0], &c
, 1);
4579 if (c
== 's') waiting
= 1;
4583 pthread_mutex_lock
(&select_mutex
);
4584 if (select_valid
& SELECT_HAVE_READ
)
4585 select_readfds
= readfds
;
4586 if (select_valid
& SELECT_HAVE_WRITE
)
4587 select_writefds
= writefds
;
4588 if (select_valid
& SELECT_HAVE_TMO
)
4589 select_timeout
= timeout
;
4590 pthread_mutex_unlock
(&select_mutex
);
4592 ns_send_appdefined
(result
);
4602 /* ==========================================================================
4606 ========================================================================== */
4608 /* called from system: queue for next pass through event loop */
4609 - (void
)requestService
: (NSPasteboard
*)pboard
4610 userData
: (NSString
*)userData
4611 error: (NSString
**)error
4613 [ns_pending_service_names addObject
: userData
];
4614 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4615 SSDATA
(ns_string_from_pasteboard
(pboard
))]];
4619 /* called from ns_read_socket to clear queue */
4620 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4622 struct frame
*emacsframe
= SELECTED_FRAME
();
4623 NSEvent
*theEvent
= [NSApp currentEvent
];
4628 emacs_event
->kind
= NS_NONKEY_EVENT
;
4629 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4630 ns_input_spi_name
= build_string
([name UTF8String
]);
4631 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4632 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4633 EV_TRAILER
(theEvent
);
4643 /* ==========================================================================
4645 EmacsView implementation
4647 ========================================================================== */
4650 @implementation EmacsView
4652 /* needed to inform when window closed from LISP */
4653 - (void
) setWindowClosing
: (BOOL
)closing
4655 windowClosing
= closing
;
4661 NSTRACE
(EmacsView_dealloc
);
4663 if (fs_state
== FULLSCREEN_BOTH
)
4664 [nonfs_window release
];
4669 /* called on font panel selection */
4670 - (void
)changeFont
: (id
)sender
4672 NSEvent
*e
=[[self window
] currentEvent
];
4673 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4677 NSTRACE
(changeFont
);
4681 if ((newFont
= [sender convertFont
:
4682 ((struct nsfont_info
*)face
->font
)->nsfont
]))
4684 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4686 emacs_event
->kind
= NS_NONKEY_EVENT
;
4687 emacs_event
->modifiers
= 0;
4688 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4690 size = [newFont pointSize
];
4691 ns_input_fontsize
= make_number
(lrint
(size));
4692 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4698 - (BOOL
)acceptsFirstResponder
4700 NSTRACE
(acceptsFirstResponder
);
4705 - (void
)resetCursorRects
4707 NSRect visible
= [self visibleRect
];
4708 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4709 NSTRACE
(resetCursorRects
);
4711 if (currentCursor
== nil
)
4712 currentCursor
= [NSCursor arrowCursor
];
4714 if (!NSIsEmptyRect
(visible
))
4715 [self addCursorRect
: visible cursor
: currentCursor
];
4716 [currentCursor setOnMouseEntered
: YES
];
4721 /*****************************************************************************/
4722 /* Keyboard handling. */
4725 - (void
)keyDown
: (NSEvent
*)theEvent
4727 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
4729 unsigned fnKeysym
= 0;
4731 static NSMutableArray
*nsEvArray
;
4732 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4733 static BOOL firstTime
= YES
;
4739 /* Rhapsody and OS X give up and down events for the arrow keys */
4740 if (ns_fake_keydown
== YES
)
4741 ns_fake_keydown
= NO
;
4742 else if ([theEvent
type] != NSKeyDown
)
4748 if (![[self window
] isKeyWindow
]
4749 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4750 /* we must avoid an infinite loop here. */
4751 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4753 /* XXX: There is an occasional condition in which, when Emacs display
4754 updates a different frame from the current one, and temporarily
4755 selects it, then processes some interrupt-driven input
4756 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4757 for some reason that window has its first responder set to the NSView
4758 most recently updated (I guess), which is not the correct one. */
4759 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4763 if (nsEvArray
== nil
)
4764 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4766 [NSCursor setHiddenUntilMouseMoves
: YES
];
4768 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4770 clear_mouse_face
(hlinfo
);
4771 hlinfo
->mouse_face_hidden
= 1;
4774 if (!processingCompose
)
4776 /* When using screen sharing, no left or right information is sent,
4777 so use Left key in those cases. */
4778 int is_left_key
, is_right_key
;
4780 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4781 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4783 /* (Carbon way: [theEvent keyCode]) */
4785 /* is it a "function key"? */
4786 fnKeysym
= ns_convert_key
(code
);
4789 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4790 because Emacs treats Delete and KP-Delete same (in simple.el). */
4791 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4792 code
= 0xFF08; /* backspace */
4797 /* are there modifiers? */
4798 emacs_event
->modifiers
= 0;
4799 flags
= [theEvent modifierFlags
];
4801 if (flags
& NSHelpKeyMask
)
4802 emacs_event
->modifiers |
= hyper_modifier
;
4804 if (flags
& NSShiftKeyMask
)
4805 emacs_event
->modifiers |
= shift_modifier
;
4807 is_right_key
= (flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
;
4808 is_left_key
= (flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
4809 ||
(! is_right_key
&& (flags
& NSCommandKeyMask
) == NSCommandKeyMask
);
4812 emacs_event
->modifiers |
= parse_solitary_modifier
4813 (EQ
(ns_right_command_modifier
, Qleft
)
4814 ? ns_command_modifier
4815 : ns_right_command_modifier
);
4819 emacs_event
->modifiers |
= parse_solitary_modifier
4820 (ns_command_modifier
);
4822 /* if super (default), take input manager's word so things like
4823 dvorak / qwerty layout work */
4824 if (EQ
(ns_command_modifier
, Qsuper
)
4826 && [[theEvent characters
] length] != 0)
4828 /* XXX: the code we get will be unshifted, so if we have
4829 a shift modifier, must convert ourselves */
4830 if (!(flags
& NSShiftKeyMask
))
4831 code
= [[theEvent characters
] characterAtIndex
: 0];
4833 /* this is ugly and also requires linking w/Carbon framework
4834 (for LMGetKbdType) so for now leave this rare (?) case
4835 undealt with.. in future look into CGEvent methods */
4838 long smv
= GetScriptManagerVariable
(smKeyScript
);
4839 Handle uchrHandle
= GetResource
4840 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4842 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4843 [[theEvent characters
] characterAtIndex
: 0],
4844 kUCKeyActionDisplay
,
4845 (flags
& ~NSCommandKeyMask
) >> 8,
4846 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4847 &dummy
, 1, &dummy
, &code
);
4854 is_right_key
= (flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
;
4855 is_left_key
= (flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
4856 ||
(! is_right_key
&& (flags
& NSControlKeyMask
) == NSControlKeyMask
);
4859 emacs_event
->modifiers |
= parse_solitary_modifier
4860 (EQ
(ns_right_control_modifier
, Qleft
)
4861 ? ns_control_modifier
4862 : ns_right_control_modifier
);
4865 emacs_event
->modifiers |
= parse_solitary_modifier
4866 (ns_control_modifier
);
4868 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4869 emacs_event
->modifiers |
=
4870 parse_solitary_modifier
(ns_function_modifier
);
4872 left_is_none
= NILP
(ns_alternate_modifier
)
4873 || EQ
(ns_alternate_modifier
, Qnone
);
4875 is_right_key
= (flags
& NSRightAlternateKeyMask
)
4876 == NSRightAlternateKeyMask
;
4877 is_left_key
= (flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
4879 && (flags
& NSAlternateKeyMask
) == NSAlternateKeyMask
);
4883 if ((NILP
(ns_right_alternate_modifier
)
4884 || EQ
(ns_right_alternate_modifier
, Qnone
)
4885 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
4887 { /* accept pre-interp alt comb */
4888 if ([[theEvent characters
] length] > 0)
4889 code
= [[theEvent characters
] characterAtIndex
: 0];
4890 /*HACK: clear lone shift modifier to stop next if from firing */
4891 if (emacs_event
->modifiers
== shift_modifier
)
4892 emacs_event
->modifiers
= 0;
4895 emacs_event
->modifiers |
= parse_solitary_modifier
4896 (EQ
(ns_right_alternate_modifier
, Qleft
)
4897 ? ns_alternate_modifier
4898 : ns_right_alternate_modifier
);
4901 if (is_left_key
) /* default = meta */
4903 if (left_is_none
&& !fnKeysym
)
4904 { /* accept pre-interp alt comb */
4905 if ([[theEvent characters
] length] > 0)
4906 code
= [[theEvent characters
] characterAtIndex
: 0];
4907 /*HACK: clear lone shift modifier to stop next if from firing */
4908 if (emacs_event
->modifiers
== shift_modifier
)
4909 emacs_event
->modifiers
= 0;
4912 emacs_event
->modifiers |
=
4913 parse_solitary_modifier
(ns_alternate_modifier
);
4917 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4918 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4920 /* if it was a function key or had modifiers, pass it directly to emacs */
4921 if (fnKeysym ||
(emacs_event
->modifiers
4922 && (emacs_event
->modifiers
!= shift_modifier
)
4923 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4924 /*[[theEvent characters] length] */
4926 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4928 code |
= (1<<28)|
(3<<16);
4929 else if (code
== 0x7f)
4930 code |
= (1<<28)|
(3<<16);
4932 emacs_event
->kind
= code
> 0xFF
4933 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4935 emacs_event
->code
= code
;
4936 EV_TRAILER
(theEvent
);
4942 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4943 /* if we get here we should send the key for input manager processing */
4944 if (firstTime
&& [[NSInputManager currentInputManager
]
4945 wantsToDelayTextChangeNotifications
] == NO
)
4947 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
4950 if (NS_KEYLOG
&& !processingCompose
)
4951 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
4953 processingCompose
= YES
;
4954 [nsEvArray addObject
: theEvent
];
4955 [self interpretKeyEvents
: nsEvArray
];
4956 [nsEvArray removeObject
: theEvent
];
4960 #ifdef NS_IMPL_COCOA
4961 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
4962 decided not to send key-down for.
4963 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
4964 This only applies on Tiger and earlier.
4965 If it matches one of these, send it on to keyDown. */
4966 -(void
)keyUp
: (NSEvent
*)theEvent
4968 int flags
= [theEvent modifierFlags
];
4969 int code
= [theEvent keyCode
];
4970 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
4971 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
4974 fprintf (stderr
, "keyUp
: passed test"
);
4975 ns_fake_keydown
= YES
;
4976 [self keyDown
: theEvent
];
4982 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
4985 /* <NSTextInput>: called when done composing;
4986 NOTE: also called when we delete over working text, followed immed.
4987 by doCommandBySelector: deleteBackward: */
4988 - (void
)insertText
: (id
)aString
4991 int len
= [(NSString
*)aString
length];
4995 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
4996 processingCompose
= NO
;
5001 /* first, clear any working text */
5002 if (workingText
!= nil
)
5003 [self deleteWorkingText
];
5005 /* now insert the string as keystrokes */
5006 for (i
=0; i
<len
; i
++)
5008 code
= [aString characterAtIndex
: i
];
5009 /* TODO: still need this? */
5011 code
= '~'; /* 0x7E */
5012 if (code
!= 32) /* Space */
5013 emacs_event
->modifiers
= 0;
5015 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
5016 emacs_event
->code
= code
;
5017 EV_TRAILER
((id
)nil
);
5022 /* <NSTextInput>: inserts display of composing characters */
5023 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
5025 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
5026 [aString string
] : aString
;
5028 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
5029 selRange.
length, selRange.location
);
5031 if (workingText
!= nil
)
5032 [self deleteWorkingText
];
5033 if ([str
length] == 0)
5039 processingCompose
= YES
;
5040 workingText
= [str copy
];
5041 ns_working_text
= build_string
([workingText UTF8String
]);
5043 emacs_event
->kind
= NS_TEXT_EVENT
;
5044 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
5045 EV_TRAILER
((id
)nil
);
5049 /* delete display of composing characters [not in <NSTextInput>] */
5050 - (void
)deleteWorkingText
5052 if (workingText
== nil
)
5055 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
5056 [workingText release
];
5058 processingCompose
= NO
;
5063 emacs_event
->kind
= NS_TEXT_EVENT
;
5064 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5065 EV_TRAILER
((id
)nil
);
5069 - (BOOL
)hasMarkedText
5071 return workingText
!= nil
;
5075 - (NSRange
)markedRange
5077 NSRange rng
= workingText
!= nil
5078 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5080 NSLog
(@"markedRange request"
);
5088 NSLog
(@"unmark
(accept
) text"
);
5089 [self deleteWorkingText
];
5090 processingCompose
= NO
;
5094 /* used to position char selection windows, etc. */
5095 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5099 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5101 NSLog
(@"firstRectForCharRange request"
);
5103 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5104 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5105 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5106 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5107 +FRAME_LINE_HEIGHT
(emacsframe
));
5109 pt
= [self convertPoint
: pt toView
: nil
];
5110 pt
= [[self window
] convertBaseToScreen
: pt
];
5116 - (NSInteger
)conversationIdentifier
5118 return (NSInteger
)self
;
5122 - (void
)doCommandBySelector
: (SEL
)aSelector
5125 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5127 if (aSelector
== @selector
(deleteBackward
:))
5129 /* happens when user backspaces over an ongoing composition:
5130 throw a 'delete' into the event queue */
5133 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5134 emacs_event
->code
= 0xFF08;
5135 EV_TRAILER
((id
)nil
);
5139 - (NSArray
*)validAttributesForMarkedText
5141 static NSArray
*arr
= nil
;
5142 if (arr
== nil
) arr
= [NSArray new
];
5143 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5147 - (NSRange
)selectedRange
5150 NSLog
(@"selectedRange request"
);
5151 return NSMakeRange
(NSNotFound
, 0);
5154 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5157 NSLog
(@"characterIndexForPoint request"
);
5161 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5163 static NSAttributedString
*str
= nil
;
5164 if (str
== nil
) str
= [NSAttributedString new
];
5166 NSLog
(@"attributedSubstringFromRange request"
);
5170 /* End <NSTextInput> impl. */
5171 /*****************************************************************************/
5174 /* This is what happens when the user presses a mouse button. */
5175 - (void
)mouseDown
: (NSEvent
*)theEvent
5177 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5179 NSTRACE
(mouseDown
);
5181 [self deleteWorkingText
];
5186 last_mouse_frame
= emacsframe
;
5187 /* appears to be needed to prevent spurious movement events generated on
5189 last_mouse_frame
->mouse_moved
= 0;
5191 if ([theEvent
type] == NSScrollWheel
)
5193 float delta
= [theEvent deltaY
];
5194 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5197 emacs_event
->kind
= WHEEL_EVENT
;
5198 emacs_event
->code
= 0;
5199 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5200 ((delta
> 0) ? up_modifier
: down_modifier
);
5204 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5205 emacs_event
->code
= EV_BUTTON
(theEvent
);
5206 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5207 | EV_UDMODIFIERS
(theEvent
);
5209 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5210 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5211 EV_TRAILER
(theEvent
);
5215 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5217 NSTRACE
(rightMouseDown
);
5218 [self mouseDown
: theEvent
];
5222 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5224 NSTRACE
(otherMouseDown
);
5225 [self mouseDown
: theEvent
];
5229 - (void
)mouseUp
: (NSEvent
*)theEvent
5232 [self mouseDown
: theEvent
];
5236 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5238 NSTRACE
(rightMouseUp
);
5239 [self mouseDown
: theEvent
];
5243 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5245 NSTRACE
(otherMouseUp
);
5246 [self mouseDown
: theEvent
];
5250 - (void
) scrollWheel
: (NSEvent
*)theEvent
5252 NSTRACE
(scrollWheel
);
5253 [self mouseDown
: theEvent
];
5257 /* Tell emacs the mouse has moved. */
5258 - (void
)mouseMoved
: (NSEvent
*)e
5260 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5263 // NSTRACE
(mouseMoved
);
5265 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5266 last_mouse_motion_position
5267 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5269 /* update any mouse face */
5270 if (hlinfo
->mouse_face_hidden
)
5272 hlinfo
->mouse_face_hidden
= 0;
5273 clear_mouse_face
(hlinfo
);
5276 /* tooltip handling */
5277 previous_help_echo_string
= help_echo_string
;
5278 help_echo_string
= Qnil
;
5280 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
5281 last_mouse_motion_position.y
))
5282 help_echo_string
= previous_help_echo_string
;
5284 XSETFRAME
(frame
, emacsframe
);
5285 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5287 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5288 (note_mouse_highlight), which is called through the
5289 note_mouse_movement () call above */
5290 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5291 help_echo_object
, help_echo_pos
);
5295 help_echo_string
= Qnil
;
5296 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5299 if (emacsframe
->mouse_moved
&& send_appdefined
)
5300 ns_send_appdefined
(-1);
5304 - (void
)mouseDragged
: (NSEvent
*)e
5306 NSTRACE
(mouseDragged
);
5307 [self mouseMoved
: e
];
5311 - (void
)rightMouseDragged
: (NSEvent
*)e
5313 NSTRACE
(rightMouseDragged
);
5314 [self mouseMoved
: e
];
5318 - (void
)otherMouseDragged
: (NSEvent
*)e
5320 NSTRACE
(otherMouseDragged
);
5321 [self mouseMoved
: e
];
5325 - (BOOL
)windowShouldClose
: (id
)sender
5327 NSEvent
*e
=[[self window
] currentEvent
];
5329 NSTRACE
(windowShouldClose
);
5330 windowClosing
= YES
;
5333 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5334 emacs_event
->modifiers
= 0;
5335 emacs_event
->code
= 0;
5337 /* Don't close this window, let this be done from lisp code. */
5341 - (void
) updateFrameSize
: (BOOL
) delay
;
5343 NSWindow
*window
= [self window
];
5344 NSRect wr
= [window frame
];
5345 #ifdef NS_IMPL_GNUSTEP
5351 int oldc
= cols
, oldr
= rows
;
5352 int oldw
= FRAME_PIXEL_WIDTH
(emacsframe
),
5353 oldh
= FRAME_PIXEL_HEIGHT
(emacsframe
);
5356 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
, wr.
size.width
+ extra
);
5358 if (cols
< MINWIDTH
)
5361 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
5362 (emacsframe
, wr.
size.height
5363 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + extra
5364 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5366 if (rows
< MINHEIGHT
)
5369 neww
= (int
)wr.
size.width
- emacsframe
->border_width
;
5370 newh
= ((int
)wr.
size.height
5371 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5372 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5374 if (oldr
!= rows || oldc
!= cols || neww
!= oldw || newh
!= oldh
)
5376 NSView
*view = FRAME_NS_VIEW
(emacsframe
);
5377 FRAME_PIXEL_WIDTH
(emacsframe
) = neww
;
5378 FRAME_PIXEL_HEIGHT
(emacsframe
) = newh
;
5379 change_frame_size
(emacsframe
, rows
, cols
, 0, delay
, 0);
5380 SET_FRAME_GARBAGED
(emacsframe
);
5381 cancel_mouse_face
(emacsframe
);
5382 [view setFrame
: NSMakeRect
(0, 0, neww
, newh
)];
5383 [self windowDidMove
:nil
]; // Update top
/left.
5387 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5388 /* normalize frame to gridded text size */
5390 NSTRACE
(windowWillResize
);
5391 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5393 if (fs_state
== FULLSCREEN_MAXIMIZED
5394 && (maximized_width
!= (int
)frameSize.width
5395 || maximized_height
!= (int
)frameSize.height
))
5396 [self setFSValue
: FULLSCREEN_NONE
];
5397 else if (fs_state
== FULLSCREEN_WIDTH
5398 && maximized_width
!= (int
)frameSize.width
)
5399 [self setFSValue
: FULLSCREEN_NONE
];
5400 else if (fs_state
== FULLSCREEN_HEIGHT
5401 && maximized_height
!= (int
)frameSize.height
)
5402 [self setFSValue
: FULLSCREEN_NONE
];
5403 if (fs_state
== FULLSCREEN_NONE
)
5404 maximized_width
= maximized_height
= -1;
5406 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5407 #ifdef NS_IMPL_GNUSTEP
5408 frameSize.width
+ 3);
5412 if (cols
< MINWIDTH
)
5415 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5416 #ifdef NS_IMPL_GNUSTEP
5417 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5418 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5420 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5421 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5423 if (rows
< MINHEIGHT
)
5425 #ifdef NS_IMPL_COCOA
5427 /* this sets window title to have size in it; the wm does this under GS */
5428 NSRect r
= [[self window
] frame
];
5429 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5440 NSWindow
*window
= [self window
];
5443 const
char *t
= [[[self window
] title] UTF8String
];
5444 char *pos
= strstr
(t
, " — "
);
5447 old_title
= xstrdup
(t
);
5449 size_title
= xmalloc
(strlen
(old_title
) + 40);
5450 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5451 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5456 #endif
/* NS_IMPL_COCOA */
5457 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5463 - (void
)windowDidResize
: (NSNotification
*)notification
5466 #
if !defined
(NEW_STYLE_FS
) && ! defined
(NS_IMPL_GNUSTEP
)
5467 NSWindow
*theWindow
= [notification object
];
5468 /* We can get notification on the non-FS window when in fullscreen mode. */
5469 if ([self window
] != theWindow
) return;
5472 #ifdef NS_IMPL_GNUSTEP
5473 NSWindow
*theWindow
= [notification object
];
5475 /* In GNUstep, at least currently, it's possible to get a didResize
5476 without getting a willResize.. therefore we need to act as if we got
5477 the willResize now */
5478 NSSize sz
= [theWindow frame
].
size;
5479 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5480 #endif
/* NS_IMPL_GNUSTEP */
5482 NSTRACE
(windowDidResize
);
5483 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5485 #ifdef NS_IMPL_COCOA
5491 #endif
/* NS_IMPL_COCOA */
5493 if (cols
> 0 && rows
> 0)
5495 [self updateFrameSize
: YES
];
5498 ns_send_appdefined
(-1);
5502 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5503 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5505 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5506 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5508 NSTRACE
(windowDidBecomeKey
);
5510 if (emacsframe
!= old_focus
)
5511 dpyinfo
->x_focus_frame
= emacsframe
;
5513 ns_frame_rehighlight
(emacsframe
);
5517 emacs_event
->kind
= FOCUS_IN_EVENT
;
5518 EV_TRAILER
((id
)nil
);
5523 - (void
)windowDidResignKey
: (NSNotification
*)notification
5524 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5526 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5527 NSTRACE
(windowDidResignKey
);
5529 if (dpyinfo
->x_focus_frame
== emacsframe
)
5530 dpyinfo
->x_focus_frame
= 0;
5532 ns_frame_rehighlight
(emacsframe
);
5534 /* FIXME: for some reason needed on second and subsequent clicks away
5535 from sole-frame Emacs to get hollow box to show */
5536 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5538 x_update_cursor
(emacsframe
, 1);
5539 x_set_frame_alpha
(emacsframe
);
5544 [self deleteWorkingText
];
5545 emacs_event
->kind
= FOCUS_IN_EVENT
;
5546 EV_TRAILER
((id
)nil
);
5551 - (void
)windowWillMiniaturize
: sender
5553 NSTRACE
(windowWillMiniaturize
);
5569 - initFrameFromEmacs
: (struct frame
*)f
5574 NSButton
*toggleButton
;
5579 NSTRACE
(initFrameFromEmacs
);
5582 processingCompose
= NO
;
5583 scrollbarsNeedingUpdate
= 0;
5584 fs_state
= FULLSCREEN_NONE
;
5585 fs_before_fs
= next_maximized
= -1;
5586 maximized_width
= maximized_height
= -1;
5589 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5591 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5592 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5593 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5594 [self initWithFrame
: r
];
5595 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5597 FRAME_NS_VIEW
(f
) = self
;
5601 win
= [[EmacsWindow alloc
]
5602 initWithContentRect
: r
5603 styleMask
: (NSResizableWindowMask |
5604 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5605 NSTitledWindowMask |
5607 NSMiniaturizableWindowMask |
5608 NSClosableWindowMask
)
5609 backing
: NSBackingStoreBuffered
5613 [win setCollectionBehavior
:NSWindowCollectionBehaviorFullScreenPrimary
];
5617 bwidth
= f
->border_width
= wr.
size.width
- r.
size.width
;
5618 tibar_height
= FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
5620 [win setAcceptsMouseMovedEvents
: YES
];
5621 [win setDelegate
: self
];
5622 [win useOptimizedDrawing
: YES
];
5624 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5625 sz.height
= FRAME_LINE_HEIGHT
(f
);
5626 [win setResizeIncrements
: sz
];
5628 [[win contentView
] addSubview
: self
];
5631 [self registerForDraggedTypes
: ns_drag_types
];
5634 name
= [NSString stringWithUTF8String
:
5635 NILP
(tem
) ? "Emacs"
: SSDATA
(tem
)];
5636 [win setTitle
: name
];
5638 /* toolbar support */
5639 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
5640 [NSString stringWithFormat
: @"Emacs Frame
%d",
5642 [win setToolbar
: toolbar
];
5643 [toolbar setVisible
: NO
];
5644 #ifdef NS_IMPL_COCOA
5645 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
5646 [toggleButton setTarget
: self
];
5647 [toggleButton setAction
: @selector
(toggleToolbar
: )];
5649 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5653 [win setMiniwindowTitle
:
5654 [NSString stringWithUTF8String
: SSDATA
(tem
)]];
5657 NSScreen
*screen
= [win screen
];
5660 [win setFrameTopLeftPoint
: NSMakePoint
5661 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
5662 IN_BOUND
(-SCREENMAX
,
5663 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
5666 [win makeFirstResponder
: self
];
5668 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5669 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
5670 [win setBackgroundColor
: col
];
5671 if ([col alphaComponent
] != 1.0)
5672 [win setOpaque
: NO
];
5674 [self allocateGState
];
5676 [NSApp registerServicesMenuSendTypes
: ns_send_types
5684 - (void
)windowDidMove
: sender
5686 NSWindow
*win
= [self window
];
5687 NSRect r
= [win frame
];
5688 NSArray
*screens
= [NSScreen screens
];
5689 NSScreen
*screen
= [screens objectAtIndex
: 0];
5691 NSTRACE
(windowDidMove
);
5693 if (!emacsframe
->output_data.ns
)
5697 emacsframe
->left_pos
= r.origin.x
;
5698 emacsframe
->top_pos
=
5699 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
5704 /* Called AFTER method below, but before our windowWillResize call there leads
5705 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
5706 location so set_window_size moves the frame. */
5707 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5709 emacsframe
->output_data.ns
->zooming
= 1;
5714 /* Override to do something slightly nonstandard, but nice. First click on
5715 zoom button will zoom vertically. Second will zoom completely. Third
5716 returns to original. */
5717 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5718 defaultFrame
:(NSRect
)defaultFrame
5720 NSRect result
= [sender frame
];
5722 NSTRACE
(windowWillUseStandardFrame
);
5724 if (fs_before_fs
!= -1) /* Entering fullscreen */
5726 result
= defaultFrame
;
5728 else if (next_maximized
== FULLSCREEN_HEIGHT
5729 ||
(next_maximized
== -1
5730 && abs (defaultFrame.
size.height
- result.
size.height
)
5731 > FRAME_LINE_HEIGHT
(emacsframe
)))
5734 ns_userRect
= result
;
5735 maximized_height
= result.
size.height
= defaultFrame.
size.height
;
5736 maximized_width
= -1;
5737 result.origin.y
= defaultFrame.origin.y
;
5738 [self setFSValue
: FULLSCREEN_HEIGHT
];
5740 else if (next_maximized
== FULLSCREEN_WIDTH
)
5742 ns_userRect
= result
;
5743 maximized_width
= result.
size.width
= defaultFrame.
size.width
;
5744 maximized_height
= -1;
5745 result.origin.x
= defaultFrame.origin.x
;
5746 [self setFSValue
: FULLSCREEN_WIDTH
];
5748 else if (next_maximized
== FULLSCREEN_MAXIMIZED
5749 ||
(next_maximized
== -1
5750 && abs (defaultFrame.
size.width
- result.
size.width
)
5751 > FRAME_COLUMN_WIDTH
(emacsframe
)))
5753 result
= defaultFrame
; /* second click */
5754 maximized_width
= result.
size.width
;
5755 maximized_height
= result.
size.height
;
5756 [self setFSValue
: FULLSCREEN_MAXIMIZED
];
5761 result
= ns_userRect.
size.height ? ns_userRect
: result
;
5762 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5763 [self setFSValue
: FULLSCREEN_NONE
];
5764 maximized_width
= maximized_width
= -1;
5767 if (fs_before_fs
== -1) next_maximized
= -1;
5768 [self windowWillResize
: sender toSize
: result.
size];
5773 - (void
)windowDidDeminiaturize
: sender
5775 NSTRACE
(windowDidDeminiaturize
);
5776 if (!emacsframe
->output_data.ns
)
5778 emacsframe
->async_iconified
= 0;
5779 emacsframe
->async_visible
= 1;
5780 windows_or_buffers_changed
++;
5784 emacs_event
->kind
= ICONIFY_EVENT
;
5785 EV_TRAILER
((id
)nil
);
5790 - (void
)windowDidExpose
: sender
5792 NSTRACE
(windowDidExpose
);
5793 if (!emacsframe
->output_data.ns
)
5795 emacsframe
->async_visible
= 1;
5796 SET_FRAME_GARBAGED
(emacsframe
);
5798 if (send_appdefined
)
5799 ns_send_appdefined
(-1);
5803 - (void
)windowDidMiniaturize
: sender
5805 NSTRACE
(windowDidMiniaturize
);
5806 if (!emacsframe
->output_data.ns
)
5809 emacsframe
->async_iconified
= 1;
5810 emacsframe
->async_visible
= 0;
5814 emacs_event
->kind
= ICONIFY_EVENT
;
5815 EV_TRAILER
((id
)nil
);
5819 - (void
)windowWillEnterFullScreen
:(NSNotification
*)notification
5821 fs_before_fs
= fs_state
;
5824 - (void
)windowDidEnterFullScreen
:(NSNotification
*)notification
5826 [self setFSValue
: FULLSCREEN_BOTH
];
5828 // Fix bad background.
5829 if ([toolbar isVisible
])
5831 [toolbar setVisible
:NO
];
5832 [toolbar setVisible
:YES
];
5835 [self windowDidBecomeKey
:notification
];
5836 [nonfs_window orderOut
:self
];
5840 - (void
)windowWillExitFullScreen
:(NSNotification
*)notification
5842 if (next_maximized
!= -1)
5843 fs_before_fs
= next_maximized
;
5846 - (void
)windowDidExitFullScreen
:(NSNotification
*)notification
5848 [self setFSValue
: fs_before_fs
];
5850 if (next_maximized
!= -1)
5851 [[self window
] performZoom
:self
];
5854 - (void
)toggleFullScreen
: (id
)sender
5857 [[self window
] toggleFullScreen
:sender
];
5859 NSWindow
*w
= [self window
], *fw
;
5860 BOOL onFirstScreen
= [[w screen
]
5861 isEqual:[[NSScreen screens
] objectAtIndex
:0]];
5862 struct frame
*f
= emacsframe
;
5864 NSRect r
, wr
= [w frame
];
5865 NSColor
*col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5866 (FRAME_DEFAULT_FACE
(f
)),
5869 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5870 sz.height
= FRAME_LINE_HEIGHT
(f
);
5872 if (fs_state
!= FULLSCREEN_BOTH
)
5874 /* Hide dock and menubar if we are on the primary screen. */
5877 #
if defined
(NS_IMPL_COCOA
) && \
5878 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
5879 NSApplicationPresentationOptions options
5880 = NSApplicationPresentationAutoHideDock
5881 | NSApplicationPresentationAutoHideMenuBar
;
5883 [NSApp setPresentationOptions
: options
];
5885 [NSMenu setMenuBarVisible
:NO
];
5889 fw
= [[EmacsFSWindow alloc
]
5890 initWithContentRect
:[w contentRectForFrameRect
:wr
]
5891 styleMask
:NSBorderlessWindowMask
5892 backing
:NSBackingStoreBuffered
5896 [fw setContentView
:[w contentView
]];
5897 [fw setTitle
:[w
title]];
5898 [fw setDelegate
:self
];
5899 [fw setAcceptsMouseMovedEvents
: YES
];
5900 [fw useOptimizedDrawing
: YES
];
5901 [fw setResizeIncrements
: sz
];
5902 [fw setBackgroundColor
: col
];
5903 if ([col alphaComponent
] != 1.0)
5906 f
->border_width
= 0;
5907 FRAME_NS_TITLEBAR_HEIGHT
(f
) = 0;
5908 tobar_height
= FRAME_TOOLBAR_HEIGHT
(f
);
5909 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5910 FRAME_EXTERNAL_TOOL_BAR
(f
) = 0;
5914 [self windowWillEnterFullScreen
:nil
];
5915 [fw makeKeyAndOrderFront
:NSApp
];
5916 [fw makeFirstResponder
:self
];
5918 r
= [fw frameRectForContentRect
:[[fw screen
] frame
]];
5919 [fw setFrame
: r display
:YES animate
:YES
];
5920 [self windowDidEnterFullScreen
:nil
];
5931 #
if defined
(NS_IMPL_COCOA
) && \
5932 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
5933 [NSApp setPresentationOptions
: NSApplicationPresentationDefault
];
5935 [NSMenu setMenuBarVisible
:YES
];
5939 [w setContentView
:[fw contentView
]];
5940 [w setResizeIncrements
: sz
];
5941 [w setBackgroundColor
: col
];
5942 if ([col alphaComponent
] != 1.0)
5945 f
->border_width
= bwidth
;
5946 FRAME_NS_TITLEBAR_HEIGHT
(f
) = tibar_height
;
5947 FRAME_TOOLBAR_HEIGHT
(f
) = tobar_height
;
5949 FRAME_EXTERNAL_TOOL_BAR
(f
) = 1;
5951 [self windowWillExitFullScreen
:nil
];
5952 [fw setFrame
: [w frame
] display
:YES animate
:YES
];
5954 [w makeKeyAndOrderFront
:NSApp
];
5955 [self windowDidExitFullScreen
:nil
];
5962 if (fs_state
!= emacsframe
->want_fullscreen
)
5964 if (fs_state
== FULLSCREEN_BOTH
)
5966 [self toggleFullScreen
:self
];
5969 switch (emacsframe
->want_fullscreen
)
5971 case FULLSCREEN_BOTH
:
5972 [self toggleFullScreen
:self
];
5974 case FULLSCREEN_WIDTH
:
5975 next_maximized
= FULLSCREEN_WIDTH
;
5976 if (fs_state
!= FULLSCREEN_BOTH
)
5977 [[self window
] performZoom
:self
];
5979 case FULLSCREEN_HEIGHT
:
5980 next_maximized
= FULLSCREEN_HEIGHT
;
5981 if (fs_state
!= FULLSCREEN_BOTH
)
5982 [[self window
] performZoom
:self
];
5984 case FULLSCREEN_MAXIMIZED
:
5985 next_maximized
= FULLSCREEN_MAXIMIZED
;
5986 if (fs_state
!= FULLSCREEN_BOTH
)
5987 [[self window
] performZoom
:self
];
5989 case FULLSCREEN_NONE
:
5990 if (fs_state
!= FULLSCREEN_BOTH
)
5992 next_maximized
= FULLSCREEN_NONE
;
5993 [[self window
] performZoom
:self
];
5998 emacsframe
->want_fullscreen
= FULLSCREEN_NONE
;
6003 - (void
) setFSValue
: (int
)value
6005 Lisp_Object lval
= Qnil
;
6008 case FULLSCREEN_BOTH
:
6011 case FULLSCREEN_WIDTH
:
6014 case FULLSCREEN_HEIGHT
:
6017 case FULLSCREEN_MAXIMIZED
:
6021 store_frame_param
(emacsframe
, Qfullscreen
, lval
);
6025 - (void
)mouseEntered
: (NSEvent
*)theEvent
6027 NSTRACE
(mouseEntered
);
6028 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
6032 - (void
)mouseExited
: (NSEvent
*)theEvent
6034 Mouse_HLInfo
*hlinfo
= emacsframe ? MOUSE_HL_INFO
(emacsframe
) : NULL;
6036 NSTRACE
(mouseExited
);
6041 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
6043 if (emacsframe
== hlinfo
->mouse_face_mouse_frame
)
6045 clear_mouse_face
(hlinfo
);
6046 hlinfo
->mouse_face_mouse_frame
= 0;
6054 if (context_menu_value
== -1)
6055 context_menu_value
= [sender tag
];
6058 NSInteger tag
= [sender tag
];
6059 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
6060 emacsframe
->menu_bar_vector
,
6064 ns_send_appdefined
(-1);
6069 - (EmacsToolbar
*)toolbar
6075 /* this gets called on toolbar button click */
6076 - toolbarClicked
: (id
)item
6079 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
6081 NSTRACE
(toolbarClicked
);
6086 /* send first event (for some reason two needed) */
6087 theEvent
= [[self window
] currentEvent
];
6088 emacs_event
->kind
= TOOL_BAR_EVENT
;
6089 XSETFRAME
(emacs_event
->arg
, emacsframe
);
6090 EV_TRAILER
(theEvent
);
6092 emacs_event
->kind
= TOOL_BAR_EVENT
;
6093 /* XSETINT (emacs_event->code, 0); */
6094 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
6095 idx
+ TOOL_BAR_ITEM_KEY
);
6096 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6097 EV_TRAILER
(theEvent
);
6102 - toggleToolbar
: (id
)sender
6107 emacs_event
->kind
= NS_NONKEY_EVENT
;
6108 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
6109 EV_TRAILER
((id
)nil
);
6114 - (void
)drawRect
: (NSRect
)rect
6116 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
6117 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
6121 if (!emacsframe ||
!emacsframe
->output_data.ns
)
6124 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
6125 expose_frame
(emacsframe
, x
, y
, width
, height
);
6128 drawRect: may be called (at least in OS X 10.5) for invisible
6129 views as well for some reason. Thus, do not infer visibility
6132 emacsframe->async_visible = 1;
6133 emacsframe->async_iconified = 0;
6138 /* NSDraggingDestination protocol methods. Actually this is not really a
6139 protocol, but a category of Object. O well... */
6141 -(NSUInteger
) draggingEntered
: (id
<NSDraggingInfo
>) sender
6143 NSTRACE
(draggingEntered
);
6144 return NSDragOperationGeneric
;
6148 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
6154 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
6159 NSEvent
*theEvent
= [[self window
] currentEvent
];
6162 NSTRACE
(performDragOperation
);
6167 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
6168 x
= lrint
(position.x
); y
= lrint
(position.y
);
6170 pb
= [sender draggingPasteboard
];
6171 type = [pb availableTypeFromArray
: ns_drag_types
];
6176 else if ([type isEqualToString
: NSFilenamesPboardType
])
6179 NSEnumerator
*fenum
;
6182 if (!(files
= [pb propertyListForType
: type]))
6185 fenum
= [files objectEnumerator
];
6186 while ( (file
= [fenum nextObject
]) )
6188 emacs_event
->kind
= NS_NONKEY_EVENT
;
6189 emacs_event
->code
= KEY_NS_DRAG_FILE
;
6190 XSETINT
(emacs_event
->x
, x
);
6191 XSETINT
(emacs_event
->y
, y
);
6192 ns_input_file
= append2
(ns_input_file
,
6193 build_string
([file UTF8String
]));
6194 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6195 EV_TRAILER
(theEvent
);
6199 else if ([type isEqualToString
: NSURLPboardType
])
6204 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
6205 [fileURL isFileURL
] == NO
)
6208 file
= [fileURL
path];
6209 emacs_event
->kind
= NS_NONKEY_EVENT
;
6210 emacs_event
->code
= KEY_NS_DRAG_FILE
;
6211 XSETINT
(emacs_event
->x
, x
);
6212 XSETINT
(emacs_event
->y
, y
);
6213 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
6214 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6215 EV_TRAILER
(theEvent
);
6218 else if ([type isEqualToString
: NSStringPboardType
]
6219 ||
[type isEqualToString
: NSTabularTextPboardType
])
6223 if (! (data
= [pb stringForType
: type]))
6226 emacs_event
->kind
= NS_NONKEY_EVENT
;
6227 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
6228 XSETINT
(emacs_event
->x
, x
);
6229 XSETINT
(emacs_event
->y
, y
);
6230 ns_input_text
= build_string
([data UTF8String
]);
6231 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6232 EV_TRAILER
(theEvent
);
6235 else if ([type isEqualToString
: NSColorPboardType
])
6237 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
6238 emacs_event
->kind
= NS_NONKEY_EVENT
;
6239 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
6240 XSETINT
(emacs_event
->x
, x
);
6241 XSETINT
(emacs_event
->y
, y
);
6242 ns_input_color
= ns_color_to_lisp
(c
);
6243 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6244 EV_TRAILER
(theEvent
);
6247 else if ([type isEqualToString
: NSFontPboardType
])
6249 /* impl based on GNUstep NSTextView.m */
6250 NSData
*data
= [pb dataForType
: NSFontPboardType
];
6251 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
6252 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
6258 emacs_event
->kind
= NS_NONKEY_EVENT
;
6259 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
6260 XSETINT
(emacs_event
->x
, x
);
6261 XSETINT
(emacs_event
->y
, y
);
6262 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
6263 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
6264 ns_input_fontsize
= build_string
(fontSize
);
6265 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6266 EV_TRAILER
(theEvent
);
6271 error ("Invalid data
type in dragging pasteboard."
);
6277 - (id
) validRequestorForSendType
: (NSString
*)typeSent
6278 returnType
: (NSString
*)typeReturned
6280 NSTRACE
(validRequestorForSendType
);
6281 if (typeSent
!= nil
&& [ns_send_types indexOfObject
: typeSent
] != NSNotFound
6282 && typeReturned
== nil
)
6284 if (! NILP
(ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
)))
6288 return [super validRequestorForSendType
: typeSent
6289 returnType
: typeReturned
];
6293 /* The next two methods are part of NSServicesRequests informal protocol,
6294 supposedly called when a services menu item is chosen from this app.
6295 But this should not happen because we override the services menu with our
6296 own entries which call ns-perform-service.
6297 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
6298 So let's at least stub them out until further investigation can be done. */
6300 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
6302 /* we could call ns_string_from_pasteboard(pboard) here but then it should
6303 be written into the buffer in place of the existing selection..
6304 ordinary service calls go through functions defined in ns-win.el */
6308 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
6310 NSArray
*typesDeclared
;
6313 /* We only support NSStringPboardType */
6314 if ([types containsObject
:NSStringPboardType
] == NO
) {
6318 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6319 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
6322 if (CONSP
(val
) && NILP
(XCDR
(val
)))
6325 if (! STRINGP
(val
))
6328 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
6329 [pb declareTypes
:typesDeclared owner
:nil
];
6330 ns_string_to_pasteboard
(pb
, val
);
6335 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
6336 (gives a miniaturized version of the window); currently we use the latter for
6337 frames whose active buffer doesn't correspond to any file
6338 (e.g., '*scratch*') */
6339 - setMiniwindowImage
: (BOOL
) setMini
6341 id
image = [[self window
] miniwindowImage
];
6342 NSTRACE
(setMiniwindowImage
);
6344 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6345 about "AppleDockIconEnabled" notwithstanding, however the set message
6346 below has its effect nonetheless. */
6347 if (image != emacsframe
->output_data.ns
->miniimage
)
6349 if (image && [image isKindOfClass
: [EmacsImage
class]])
6351 [[self window
] setMiniwindowImage
:
6352 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6359 - (void
) setRows
: (int
) r andColumns
: (int
) c
6365 @
end /* EmacsView */
6369 /* ==========================================================================
6371 EmacsWindow implementation
6373 ========================================================================== */
6375 @implementation EmacsWindow
6377 #ifdef NS_IMPL_COCOA
6378 - (id
)accessibilityAttributeValue
:(NSString
*)attribute
6380 Lisp_Object str
= Qnil
;
6381 struct frame
*f
= SELECTED_FRAME
();
6382 struct buffer
*curbuf
= XBUFFER
(XWINDOW
(f
->selected_window
)->buffer
);
6384 if ([attribute isEqualToString
:NSAccessibilityRoleAttribute
])
6385 return NSAccessibilityTextFieldRole
;
6387 if ([attribute isEqualToString
:NSAccessibilitySelectedTextAttribute
]
6388 && curbuf
&& ! NILP
(BVAR
(curbuf
, mark_active
)))
6390 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6392 else if (curbuf
&& [attribute isEqualToString
:NSAccessibilityValueAttribute
])
6394 if (! NILP
(BVAR
(curbuf
, mark_active
)))
6395 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6399 ptrdiff_t start_byte
= BUF_BEGV_BYTE
(curbuf
);
6400 ptrdiff_t byte_range
= BUF_ZV_BYTE
(curbuf
) - start_byte
;
6401 ptrdiff_t range
= BUF_ZV
(curbuf
) - BUF_BEGV
(curbuf
);
6403 if (! NILP
(BVAR
(curbuf
, enable_multibyte_characters
)))
6404 str
= make_uninit_multibyte_string
(range
, byte_range
);
6406 str
= make_uninit_string
(range
);
6407 /* To check: This returns emacs-utf-8, which is a superset of utf-8.
6408 Is this a problem? */
6409 memcpy
(SDATA
(str
), BYTE_POS_ADDR
(start_byte
), byte_range
);
6416 if (CONSP
(str
) && SYMBOLP
(XCAR
(str
)))
6419 if (CONSP
(str
) && NILP
(XCDR
(str
)))
6424 const
char *utfStr
= SSDATA
(str
);
6425 NSString
*nsStr
= [NSString stringWithUTF8String
: utfStr
];
6430 return [super accessibilityAttributeValue
:attribute
];
6432 #endif
/* NS_IMPL_COCOA */
6434 /* If we have multiple monitors, one above the other, we don't want to
6435 restrict the height to just one monitor. So we override this. */
6436 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6438 /* When making the frame visible for the first time or if there is just
6439 one screen, we want to constrain. Other times not. */
6440 NSUInteger nr_screens
= [[NSScreen screens
] count
];
6441 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6442 NSTRACE
(constrainFrameRect
);
6444 if (nr_screens
== 1)
6446 NSRect r
= [super constrainFrameRect
:frameRect toScreen
:screen
];
6450 if (f
->output_data.ns
->dont_constrain
6451 || ns_menu_bar_should_be_hidden
())
6454 f
->output_data.ns
->dont_constrain
= 1;
6455 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6458 @
end /* EmacsWindow */
6461 @implementation EmacsFSWindow
6463 - (BOOL
)canBecomeKeyWindow
6468 - (BOOL
)canBecomeMainWindow
6475 /* ==========================================================================
6477 EmacsScroller implementation
6479 ========================================================================== */
6482 @implementation EmacsScroller
6484 /* for repeat button push */
6485 #define SCROLL_BAR_FIRST_DELAY
0.5
6486 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6488 + (CGFloat
) scrollerWidth
6490 /* TODO: if we want to allow variable widths, this is the place to do it,
6491 however neither GNUstep nor Cocoa support it very well */
6492 return [NSScroller scrollerWidth
];
6496 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
6498 NSTRACE
(EmacsScroller_initFrame
);
6500 r.
size.width
= [EmacsScroller scrollerWidth
];
6501 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
6502 [self setContinuous
: YES
];
6503 [self setEnabled
: YES
];
6505 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
6506 locked against the top and bottom edges, and right edge on OS X, where
6507 scrollers are on right. */
6508 #ifdef NS_IMPL_GNUSTEP
6509 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
6511 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
6516 pixel_height
= NSHeight
(r
);
6517 if (pixel_height
== 0) pixel_height
= 1;
6518 min_portion
= 20 / pixel_height
;
6520 frame
= XFRAME
(XWINDOW
(win
)->frame
);
6521 if (FRAME_LIVE_P
(frame
))
6524 EmacsView
*view = FRAME_NS_VIEW
(frame
);
6525 NSView
*sview
= [[view window
] contentView
];
6526 NSArray
*subs
= [sview subviews
];
6528 /* disable optimization stopping redraw of other scrollbars */
6529 view->scrollbarsNeedingUpdate
= 0;
6530 for (i
=[subs count
]-1; i
>= 0; i
--)
6531 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
6532 view->scrollbarsNeedingUpdate
++;
6533 [sview addSubview
: self
];
6536 /* [self setFrame: r]; */
6542 - (void
)setFrame
: (NSRect
)newRect
6544 NSTRACE
(EmacsScroller_setFrame
);
6545 /* block_input (); */
6546 pixel_height
= NSHeight
(newRect
);
6547 if (pixel_height
== 0) pixel_height
= 1;
6548 min_portion
= 20 / pixel_height
;
6549 [super setFrame
: newRect
];
6551 /* unblock_input (); */
6557 NSTRACE
(EmacsScroller_dealloc
);
6559 wset_vertical_scroll_bar
(XWINDOW
(win
), Qnil
);
6587 /* ensure other scrollbar updates after deletion */
6588 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6590 view->scrollbarsNeedingUpdate
++;
6591 [self removeFromSuperview
];
6599 - (void
)resetCursorRects
6601 NSRect visible
= [self visibleRect
];
6602 NSTRACE
(resetCursorRects
);
6604 if (!NSIsEmptyRect
(visible
))
6605 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
6606 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
6610 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
6613 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
6614 && portion
!= whole
; /* needed for resize empty buf */
6618 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
6620 NSTRACE
(setPosition
);
6622 em_position
= position
;
6623 em_portion
= portion
;
6626 if (portion
>= whole
)
6628 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6629 [self setKnobProportion
: 1.0];
6630 [self setDoubleValue
: 1.0];
6632 [self setFloatValue
: 0.0 knobProportion
: 1.0];
6638 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
6639 pos
= (float
)position
/ (whole
- portion
);
6640 por
= (float
)portion
/whole
;
6641 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6642 [self setKnobProportion
: por
];
6643 [self setDoubleValue
: pos
];
6645 [self setFloatValue
: pos knobProportion
: por
];
6651 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
6652 drag events will go directly to the EmacsScroller. Leaving in for now. */
6653 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
6654 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
6656 *part
= last_hit_part
;
6658 XSETINT
(*y
, pixel_height
);
6659 if ([self floatValue
] > 0.999)
6660 XSETINT
(*x
, pixel_height
);
6662 XSETINT
(*x
, pixel_height
* [self floatValue
]);
6666 /* set up emacs_event */
6667 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
6672 emacs_event
->part
= last_hit_part
;
6673 emacs_event
->code
= 0;
6674 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
6675 emacs_event
->frame_or_window
= win
;
6676 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
6677 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
6678 emacs_event
->arg
= Qnil
;
6679 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
6680 XSETINT
(emacs_event
->y
, pixel_height
-20);
6684 n_emacs_events_pending
++;
6685 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
6688 kbd_buffer_store_event
(emacs_event
);
6689 EVENT_INIT
(*emacs_event
);
6690 ns_send_appdefined
(-1);
6694 /* called manually thru timer to implement repeated button action w/hold-down */
6695 - repeatScroll
: (NSTimer
*)scrollEntry
6697 NSEvent
*e
= [[self window
] currentEvent
];
6698 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
6699 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
6701 /* clear timer if need be */
6702 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
6704 [scroll_repeat_entry invalidate
];
6705 [scroll_repeat_entry release
];
6706 scroll_repeat_entry
= nil
;
6712 = [[NSTimer scheduledTimerWithTimeInterval
:
6713 SCROLL_BAR_CONTINUOUS_DELAY
6715 selector
: @selector
(repeatScroll
:)
6721 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
6726 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
6727 mouseDragged events without going into a modal loop. */
6728 - (void
)mouseDown
: (NSEvent
*)e
6731 /* hitPart is only updated AFTER event is passed on */
6732 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6733 double inc
= 0.0, loc
, kloc
, pos
;
6736 NSTRACE
(EmacsScroller_mouseDown
);
6740 case NSScrollerDecrementPage
:
6741 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6742 case NSScrollerIncrementPage
:
6743 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6744 case NSScrollerDecrementLine
:
6745 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6746 case NSScrollerIncrementLine
:
6747 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6748 case NSScrollerKnob
:
6749 last_hit_part
= scroll_bar_handle
; break;
6750 case NSScrollerKnobSlot
: /* GNUstep-only */
6751 last_hit_part
= scroll_bar_move_ratio
; break;
6752 default
: /* NSScrollerNoPart? */
6753 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
6760 pos
= 0; /* ignored */
6762 /* set a timer to repeat, as we can't let superclass do this modally */
6764 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
6766 selector
: @selector
(repeatScroll
:)
6773 /* handle, or on GNUstep possibly slot */
6774 NSEvent
*fake_event
;
6776 /* compute float loc in slot and mouse offset on knob */
6777 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6779 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6785 else if (loc
>= NSHeight
(sr
))
6787 loc
= NSHeight
(sr
);
6795 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6797 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6799 last_mouse_offset
= kloc
;
6801 /* if knob, tell emacs a location offset by knob pos
6802 (to indicate top of handle) */
6803 if (part
== NSScrollerKnob
)
6804 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6806 /* else this is a slot click on GNUstep: go straight there */
6807 pos
= loc
/ NSHeight
(sr
);
6809 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6810 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6811 location
: [e locationInWindow
]
6812 modifierFlags
: [e modifierFlags
]
6813 timestamp
: [e timestamp
]
6814 windowNumber
: [e windowNumber
]
6815 context
: [e context
]
6816 eventNumber
: [e eventNumber
]
6817 clickCount
: [e clickCount
]
6818 pressure
: [e pressure
]];
6819 [super mouseUp
: fake_event
];
6822 if (part
!= NSScrollerKnob
)
6823 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6827 /* Called as we manually track scroller drags, rather than superclass. */
6828 - (void
)mouseDragged
: (NSEvent
*)e
6834 NSTRACE
(EmacsScroller_mouseDragged
);
6836 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6838 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6845 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6847 loc
= NSHeight
(sr
) + last_mouse_offset
;
6851 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6852 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6856 - (void
)mouseUp
: (NSEvent
*)e
6858 if (scroll_repeat_entry
)
6860 [scroll_repeat_entry invalidate
];
6861 [scroll_repeat_entry release
];
6862 scroll_repeat_entry
= nil
;
6868 /* treat scrollwheel events in the bar as though they were in the main window */
6869 - (void
) scrollWheel
: (NSEvent
*)theEvent
6871 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6872 [view mouseDown
: theEvent
];
6875 @
end /* EmacsScroller */
6880 /* ==========================================================================
6882 Font-related functions; these used to be in nsfaces.m
6884 ========================================================================== */
6888 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6890 struct font
*font
= XFONT_OBJECT
(font_object
);
6893 fontset
= fontset_from_font
(font_object
);
6894 FRAME_FONTSET
(f
) = fontset
;
6896 if (FRAME_FONT
(f
) == font
)
6897 /* This font is already set in frame F. There's nothing more to
6901 FRAME_FONT
(f
) = font
;
6903 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6904 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6905 FRAME_SPACE_WIDTH
(f
) = font
->space_width
;
6906 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6908 compute_fringe_widths
(f
, 1);
6910 /* Compute the scroll bar width in character columns. */
6911 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6913 int wid
= FRAME_COLUMN_WIDTH
(f
);
6914 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6915 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6919 int wid
= FRAME_COLUMN_WIDTH
(f
);
6920 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6923 /* Now make the frame display the given font. */
6924 if (FRAME_NS_WINDOW
(f
) != 0)
6925 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6931 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6932 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6936 ns_xlfd_to_fontname
(const
char *xlfd
)
6937 /* --------------------------------------------------------------------------
6938 Convert an X font name (XLFD) to an NS font name.
6939 Only family is used.
6940 The string returned is temporarily allocated.
6941 -------------------------------------------------------------------------- */
6943 char *name
= xmalloc
(180);
6947 if (!strncmp
(xlfd
, "
--"
, 2))
6948 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
6950 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
6952 /* stopgap for malformed XLFD input */
6953 if (strlen
(name
) == 0)
6954 strcpy
(name
, "Monaco"
);
6956 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
6957 also uppercase after '-' or ' ' */
6958 name
[0] = c_toupper
(name
[0]);
6959 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
6965 name
[i
+1] = c_toupper
(name
[i
+1]);
6967 else if (name
[i
] == '_')
6971 name
[i
+1] = c_toupper
(name
[i
+1]);
6974 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
6975 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
6982 syms_of_nsterm
(void
)
6984 NSTRACE
(syms_of_nsterm
);
6986 ns_antialias_threshold
= 10.0;
6988 /* from 23+ we need to tell emacs what modifiers there are.. */
6989 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
6990 DEFSYM
(Qalt
, "alt"
);
6991 DEFSYM
(Qhyper
, "hyper"
);
6992 DEFSYM
(Qmeta
, "
meta"
);
6993 DEFSYM
(Qsuper
, "super"
);
6994 DEFSYM
(Qcontrol
, "control"
);
6995 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
6997 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
6998 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
6999 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
7000 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
7001 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
7003 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
7004 "The file specified in the last NS event."
);
7005 ns_input_file
=Qnil
;
7007 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
7008 "The data received in the last NS
text drag event."
);
7009 ns_input_text
=Qnil
;
7011 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
7012 "String
for visualizing working composition sequence."
);
7013 ns_working_text
=Qnil
;
7015 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
7016 "The font specified in the last NS event."
);
7017 ns_input_font
=Qnil
;
7019 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
7020 "The fontsize specified in the last NS event."
);
7021 ns_input_fontsize
=Qnil
;
7023 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
7024 "The
line specified in the last NS event."
);
7025 ns_input_line
=Qnil
;
7027 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
7028 "The color specified in the last NS event."
);
7029 ns_input_color
=Qnil
;
7031 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
7032 "The service name specified in the last NS event."
);
7033 ns_input_spi_name
=Qnil
;
7035 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
7036 "The service argument specified in the last NS event."
);
7037 ns_input_spi_arg
=Qnil
;
7039 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
7040 "This variable describes the behavior of the alternate or option key.
\n\
7041 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7042 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
7043 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7044 ns_alternate_modifier
= Qmeta
;
7046 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
7047 "This variable describes the behavior of the right alternate or option key.
\n\
7048 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7049 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
7050 Set to none means that the alternate / option key is not interpreted by Emacs\n\
7051 at all, allowing it to be used at a lower level for accented character entry.");
7052 ns_right_alternate_modifier = Qleft;
7054 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
7055 "This variable describes the behavior of the command key.\n\
7056 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
7057 ns_command_modifier = Qsuper;
7059 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
7060 "This variable describes the behavior of the right command key.\n\
7061 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7062 Set to left means be the same key as `ns-command-modifier'.
\n\
7063 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
7064 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7065 ns_right_command_modifier
= Qleft
;
7067 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
7068 "This variable describes the behavior of the control key.
\n\
7069 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
7070 ns_control_modifier
= Qcontrol
;
7072 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
7073 "This variable describes the behavior of the right control key.
\n\
7074 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7075 Set to left means be the same key as `ns
-control
-modifier
'.\n\
7076 Set to none means that the control / option key is not interpreted by Emacs\n\
7077 at all, allowing it to be used at a lower level for accented character entry.");
7078 ns_right_control_modifier = Qleft;
7080 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
7081 "This variable describes the behavior of the function key (on laptops).\n\
7082 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7083 Set to none means that the function key is not interpreted by Emacs at all,\n\
7084 allowing it to be used at a lower level for accented character entry.");
7085 ns_function_modifier = Qnone;
7087 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
7088 "Non-nil (the default) means to render text antialiased.");
7089 ns_antialias_text = Qt;
7091 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
7092 "Whether to confirm application quit using dialog.");
7093 ns_confirm_quit = Qnil;
7095 staticpro (&ns_display_name_list);
7096 ns_display_name_list = Qnil;
7098 staticpro (&last_mouse_motion_frame);
7099 last_mouse_motion_frame = Qnil;
7101 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
7102 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
7103 Only works on OSX 10.6 or later. */);
7104 ns_auto_hide_menu_bar = Qnil;
7106 /* TODO: move to common code */
7107 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
7108 doc: /* Which toolkit scroll bars Emacs uses, if any.
7109 A value of nil means Emacs doesn't use toolkit scroll bars.
7110 With the X Window system
, the value is a symbol describing the
7111 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
7112 With MS Windows or Nextstep
, the value is t. */
);
7113 Vx_toolkit_scroll_bars
= Qt
;
7115 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
7116 x_use_underline_position_properties
,
7117 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
7118 A value of nil means ignore them. If you encounter fonts with bogus
7119 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
7120 to 4.1, set this to nil. */);
7121 x_use_underline_position_properties
= 0;
7123 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
7124 x_underline_at_descent_line
,
7125 doc: /* Non-nil means to draw the underline at the same place as the descent line.
7126 A value of nil means to draw the underline according to the value of the
7127 variable `x-use-underline-position-properties', which is usually at the
7128 baseline level. The default value is nil. */);
7129 x_underline_at_descent_line
= 0;
7131 /* Tell emacs about this window system. */
7132 Fprovide
(intern
("ns"
), Qnil
);