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"
68 int term_trace_num
= 0;
69 #define NSTRACE
(x
) fprintf (stderr
, "
%s:%d: [%d] " #x "\n", \
70 __FILE__
, __LINE__
, ++term_trace_num
)
75 #
if defined
(NS_IMPL_COCOA
) && \
76 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
80 extern NSString
*NSMenuDidBeginTrackingNotification
;
82 /* ==========================================================================
86 ========================================================================== */
88 /* Convert a symbol indexed with an NSxxx value to a value as defined
89 in keyboard.c (lispy_function_key). I hope this is a correct way
91 static unsigned convert_ns_to_X_keysym
[] =
93 NSHomeFunctionKey
, 0x50,
94 NSLeftArrowFunctionKey
, 0x51,
95 NSUpArrowFunctionKey
, 0x52,
96 NSRightArrowFunctionKey
, 0x53,
97 NSDownArrowFunctionKey
, 0x54,
98 NSPageUpFunctionKey
, 0x55,
99 NSPageDownFunctionKey
, 0x56,
100 NSEndFunctionKey
, 0x57,
101 NSBeginFunctionKey
, 0x58,
102 NSSelectFunctionKey
, 0x60,
103 NSPrintFunctionKey
, 0x61,
104 NSExecuteFunctionKey
, 0x62,
105 NSInsertFunctionKey
, 0x63,
106 NSUndoFunctionKey
, 0x65,
107 NSRedoFunctionKey
, 0x66,
108 NSMenuFunctionKey
, 0x67,
109 NSFindFunctionKey
, 0x68,
110 NSHelpFunctionKey
, 0x6A,
111 NSBreakFunctionKey
, 0x6B,
113 NSF1FunctionKey
, 0xBE,
114 NSF2FunctionKey
, 0xBF,
115 NSF3FunctionKey
, 0xC0,
116 NSF4FunctionKey
, 0xC1,
117 NSF5FunctionKey
, 0xC2,
118 NSF6FunctionKey
, 0xC3,
119 NSF7FunctionKey
, 0xC4,
120 NSF8FunctionKey
, 0xC5,
121 NSF9FunctionKey
, 0xC6,
122 NSF10FunctionKey
, 0xC7,
123 NSF11FunctionKey
, 0xC8,
124 NSF12FunctionKey
, 0xC9,
125 NSF13FunctionKey
, 0xCA,
126 NSF14FunctionKey
, 0xCB,
127 NSF15FunctionKey
, 0xCC,
128 NSF16FunctionKey
, 0xCD,
129 NSF17FunctionKey
, 0xCE,
130 NSF18FunctionKey
, 0xCF,
131 NSF19FunctionKey
, 0xD0,
132 NSF20FunctionKey
, 0xD1,
133 NSF21FunctionKey
, 0xD2,
134 NSF22FunctionKey
, 0xD3,
135 NSF23FunctionKey
, 0xD4,
136 NSF24FunctionKey
, 0xD5,
138 NSBackspaceCharacter
, 0x08, /* 8: Not on some KBs. */
139 NSDeleteCharacter
, 0xFF, /* 127: Big 'delete' key upper right. */
140 NSDeleteFunctionKey
, 0x9F, /* 63272: Del forw key off main array. */
142 NSTabCharacter
, 0x09,
143 0x19, 0x09, /* left tab->regular since pass shift */
144 NSCarriageReturnCharacter
, 0x0D,
145 NSNewlineCharacter
, 0x0D,
146 NSEnterCharacter
, 0x8D,
148 0x1B, 0x1B /* escape */
151 static Lisp_Object Qmodifier_value
;
152 Lisp_Object Qalt
, Qcontrol
, Qhyper
, Qmeta
, Qsuper
;
153 extern Lisp_Object Qcursor_color
, Qcursor_type
, Qns
, Qleft
;
155 static Lisp_Object QUTF8_STRING
;
157 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
158 the maximum font size to NOT antialias. On GNUstep there is currently
159 no way to control this behavior. */
160 float ns_antialias_threshold
;
162 /* Used to pick up AppleHighlightColor on OS X */
163 NSString
*ns_selection_color
;
165 NSArray
*ns_send_types
=0, *ns_return_types
=0, *ns_drag_types
=0;
166 NSString
*ns_app_name
= @"Emacs"
; /* default changed later */
168 /* Display variables */
169 struct ns_display_info
*x_display_list
; /* Chain of existing displays */
170 Lisp_Object ns_display_name_list
;
171 long context_menu_value
= 0;
174 NSPoint last_mouse_motion_position
;
175 static NSRect last_mouse_glyph
;
176 static Time last_mouse_movement_time
= 0;
177 static Lisp_Object last_mouse_motion_frame
;
178 static EmacsScroller
*last_mouse_scroll_bar
= nil
;
179 static
struct frame
*ns_updating_frame
;
180 static NSView
*focus_view
= NULL;
181 static int ns_window_num
= 0;
182 #ifdef NS_IMPL_GNUSTEP
185 static BOOL gsaved
= NO
;
186 static BOOL ns_fake_keydown
= NO
;
187 int ns_tmp_flags
; /* FIXME */
188 struct nsfont_info
*ns_tmp_font
; /* FIXME */
189 static BOOL ns_menu_bar_is_hidden
= NO
;
190 /*static int debug_lock = 0; */
193 static BOOL send_appdefined
= YES
;
194 static NSEvent
*last_appdefined_event
= 0;
195 static NSTimer
*timed_entry
= 0;
196 static NSTimer
*scroll_repeat_entry
= nil
;
197 static fd_set select_readfds
, select_writefds
;
198 enum
{ SELECT_HAVE_READ
= 1, SELECT_HAVE_WRITE
= 2, SELECT_HAVE_TMO
= 4 };
199 static int select_nfds
= 0, select_valid
= 0;
200 static EMACS_TIME select_timeout
= { 0, 0 };
201 static int selfds
[2] = { -1, -1 };
202 static pthread_mutex_t select_mutex
;
203 static int apploopnr
= 0;
204 static NSAutoreleasePool
*outerpool
;
205 static
struct input_event
*emacs_event
= NULL;
206 static
struct input_event
*q_event_ptr
= NULL;
207 static int n_emacs_events_pending
= 0;
208 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
209 *ns_pending_service_args
;
210 static BOOL ns_do_open_file
= NO
;
212 /* Convert modifiers in a NeXTstep event to emacs style modifiers. */
213 #define NS_FUNCTION_KEY_MASK
0x800000
214 #define NSLeftControlKeyMask
(0x000001 | NSControlKeyMask
)
215 #define NSRightControlKeyMask
(0x002000 | NSControlKeyMask
)
216 #define NSLeftCommandKeyMask
(0x000008 | NSCommandKeyMask
)
217 #define NSRightCommandKeyMask
(0x000010 | NSCommandKeyMask
)
218 #define NSLeftAlternateKeyMask
(0x000020 | NSAlternateKeyMask
)
219 #define NSRightAlternateKeyMask
(0x000040 | NSAlternateKeyMask
)
220 #define EV_MODIFIERS
(e
) \
221 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
222 hyper_modifier
: 0) \
223 |
(!EQ
(ns_right_alternate_modifier
, Qleft
) && \
224 (([e modifierFlags
] & NSRightAlternateKeyMask
) \
225 == NSRightAlternateKeyMask
) ? \
226 parse_solitary_modifier
(ns_right_alternate_modifier
) : 0) \
227 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
228 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
229 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
230 shift_modifier
: 0) \
231 |
(!EQ
(ns_right_control_modifier
, Qleft
) && \
232 (([e modifierFlags
] & NSRightControlKeyMask
) \
233 == NSRightControlKeyMask
) ? \
234 parse_solitary_modifier
(ns_right_control_modifier
) : 0) \
235 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
236 parse_solitary_modifier
(ns_control_modifier
) : 0) \
237 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
238 parse_solitary_modifier
(ns_function_modifier
) : 0) \
239 |
(!EQ
(ns_right_command_modifier
, Qleft
) && \
240 (([e modifierFlags
] & NSRightCommandKeyMask
) \
241 == NSRightCommandKeyMask
) ? \
242 parse_solitary_modifier
(ns_right_command_modifier
) : 0) \
243 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
244 parse_solitary_modifier
(ns_command_modifier
):0))
246 #define EV_UDMODIFIERS
(e
) \
247 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
248 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
249 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
250 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
251 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
252 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
253 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
254 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
255 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
257 #define EV_BUTTON
(e
) \
258 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
259 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
260 [e buttonNumber
] - 1)
262 /* Convert the time field to a timestamp in milliseconds. */
263 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
265 /* This is a piece of code which is common to all the event handling
266 methods. Maybe it should even be a function. */
267 #define EV_TRAILER
(e
) \
269 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
270 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
273 n_emacs_events_pending
++; \
274 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
277 kbd_buffer_store_event
(emacs_event
); \
278 EVENT_INIT
(*emacs_event
); \
279 ns_send_appdefined
(-1); \
282 void x_set_cursor_type
(struct frame
*, Lisp_Object
, Lisp_Object
);
284 /* TODO: get rid of need for these forward declarations */
285 static void ns_condemn_scroll_bars
(struct frame
*f
);
286 static void ns_judge_scroll_bars
(struct frame
*f
);
287 void x_set_frame_alpha
(struct frame
*f
);
290 /* ==========================================================================
294 ========================================================================== */
298 append2
(Lisp_Object list
, Lisp_Object item
)
299 /* --------------------------------------------------------------------------
300 Utility to append to a list
301 -------------------------------------------------------------------------- */
303 Lisp_Object array
[2];
305 array
[1] = Fcons
(item
, Qnil
);
306 return Fnconc
(2, &array
[0]);
311 ns_etc_directory
(void
)
312 /* If running as a self-contained app bundle, return as a string the
313 filename of the etc directory, if present; else nil. */
315 NSBundle
*bundle
= [NSBundle mainBundle
];
316 NSString
*resourceDir
= [bundle resourcePath
];
317 NSString
*resourcePath
;
318 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
321 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
322 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
324 if (isDir
) return [resourcePath UTF8String
];
332 /* If running as a self-contained app bundle, return as a path string
333 the filenames of the libexec and bin directories, ie libexec:bin.
334 Otherwise, return nil.
335 Normally, Emacs does not add its own bin/ directory to the PATH.
336 However, a self-contained NS build has a different layout, with
337 bin/ and libexec/ subdirectories in the directory that contains
339 We put libexec first, because init_callproc_1 uses the first
340 element to initialize exec-directory. An alternative would be
341 for init_callproc to check for invocation-directory/libexec.
344 NSBundle
*bundle
= [NSBundle mainBundle
];
345 NSString
*resourceDir
= [bundle resourcePath
];
346 NSString
*binDir
= [bundle bundlePath
];
347 NSString
*resourcePath
, *resourcePaths
;
349 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
350 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
352 NSEnumerator
*pathEnum
;
355 range
= [resourceDir rangeOfString
: @"Contents"
];
356 if (range.location
!= NSNotFound
)
358 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
360 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
364 paths
= [binDir stringsByAppendingPaths
:
365 [NSArray arrayWithObjects
: @"libexec"
, @"bin"
, nil
]];
366 pathEnum
= [paths objectEnumerator
];
369 while ((resourcePath
= [pathEnum nextObject
]))
371 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
374 if ([resourcePaths
length] > 0)
376 = [resourcePaths stringByAppendingString
: pathSeparator
];
378 = [resourcePaths stringByAppendingString
: resourcePath
];
381 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
389 /* If running as a self-contained app bundle, return as a path string
390 the filenames of the site-lisp, lisp and leim directories.
391 Ie, site-lisp:lisp:leim. Otherwise, return nil. */
393 NSBundle
*bundle
= [NSBundle mainBundle
];
394 NSString
*resourceDir
= [bundle resourcePath
];
395 NSString
*resourcePath
, *resourcePaths
;
396 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
397 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
399 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
400 [NSArray arrayWithObjects
:
401 @"site
-lisp"
, @"lisp"
, @"leim"
, nil
]];
402 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
405 /* Hack to skip site-lisp. */
406 if (no_site_lisp
) resourcePath
= [pathEnum nextObject
];
408 while ((resourcePath
= [pathEnum nextObject
]))
410 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
413 if ([resourcePaths
length] > 0)
415 = [resourcePaths stringByAppendingString
: pathSeparator
];
417 = [resourcePaths stringByAppendingString
: resourcePath
];
420 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
426 ns_timeout
(int usecs
)
427 /* --------------------------------------------------------------------------
428 Blocking timer utility used by ns_ring_bell
429 -------------------------------------------------------------------------- */
431 EMACS_TIME wakeup
= add_emacs_time
(current_emacs_time
(),
432 make_emacs_time
(0, usecs
* 1000));
434 /* Keep waiting until past the time wakeup. */
437 EMACS_TIME timeout
, now
= current_emacs_time
();
438 if (EMACS_TIME_LE
(wakeup
, now
))
440 timeout
= sub_emacs_time
(wakeup
, now
);
442 /* Try to wait that long--but we might wake up sooner. */
443 pselect
(0, NULL, NULL, NULL, &timeout
, NULL);
449 ns_release_object
(void
*obj
)
450 /* --------------------------------------------------------------------------
451 Release an object (callable from C)
452 -------------------------------------------------------------------------- */
459 ns_retain_object
(void
*obj
)
460 /* --------------------------------------------------------------------------
461 Retain an object (callable from C)
462 -------------------------------------------------------------------------- */
469 ns_alloc_autorelease_pool
(void
)
470 /* --------------------------------------------------------------------------
471 Allocate a pool for temporary objects (callable from C)
472 -------------------------------------------------------------------------- */
474 return [[NSAutoreleasePool alloc
] init
];
479 ns_release_autorelease_pool
(void
*pool
)
480 /* --------------------------------------------------------------------------
481 Free a pool and temporary objects it refers to (callable from C)
482 -------------------------------------------------------------------------- */
484 ns_release_object
(pool
);
489 /* ==========================================================================
491 Focus (clipping) and screen update
493 ========================================================================== */
496 // Window constraining
497 // -------------------
499 // To ensure that the windows are not placed under the
menu bar, they
500 // are typically moved by the call
-back constrainFrameRect. However
,
501 // by overriding it
, it
's possible to inhibit this, leaving the window
502 // in it's original position.
504 // It
's possible to hide the menu bar. However, technically, it's only
505 // possible to hide it when the application is active. To ensure that
506 // this work properly
, the
menu bar and window constraining are
507 // deferred until the application becomes active.
509 // Even though it
's not possible to manually move a window above the
510 // top of the screen, it is allowed if it's done programmatically
,
511 // when the
menu is
hidden. This allows the editable area to cover the
512 // full screen height.
517 // Use the following extra files
:
520 // ;; Hide
menu and place frame slightly above the top of the screen.
521 // (setq ns
-auto
-hide
-menu-bar t
)
522 // (set-frame
-position
(selected
-frame
) 0 -20)
526 // emacs
-Q
-l init.el
528 // Result
: No
menu bar, and the
title bar should be above the screen.
534 // Result
: Menu bar visible
, frame placed immediately below the
menu.
538 ns_constrain_all_frames
(void
)
540 Lisp_Object tail
, frame
;
542 FOR_EACH_FRAME
(tail
, frame
)
544 struct frame
*f
= XFRAME
(frame
);
547 NSView
*view = FRAME_NS_VIEW
(f
);
548 /* This no-op will trigger the default window placing
549 * constraint system. */
550 f
->output_data.ns
->dont_constrain
= 0;
551 [[view window
] setFrameOrigin
:[[view window
] frame
].origin
];
557 /* True, if the menu bar should be hidden. */
560 ns_menu_bar_should_be_hidden
(void
)
562 return !NILP
(ns_auto_hide_menu_bar
)
563 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)];
567 /* Show or hide the menu bar, based on user setting. */
570 ns_update_auto_hide_menu_bar
(void
)
572 #ifndef MAC_OS_X_VERSION_10_6
573 #define MAC_OS_X_VERSION_10_6
1060
576 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
579 NSTRACE
(ns_update_auto_hide_menu_bar
);
583 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)])
585 // Note
, "setPresentationOptions" triggers an
error unless the
586 // application is active.
587 BOOL menu_bar_should_be_hidden
= ns_menu_bar_should_be_hidden
();
589 if (menu_bar_should_be_hidden
!= ns_menu_bar_is_hidden
)
591 NSApplicationPresentationOptions options
592 = NSApplicationPresentationAutoHideDock
;
594 if (menu_bar_should_be_hidden
)
595 options |
= NSApplicationPresentationAutoHideMenuBar
;
597 [NSApp setPresentationOptions
: options
];
599 ns_menu_bar_is_hidden
= menu_bar_should_be_hidden
;
601 if (!ns_menu_bar_is_hidden
)
603 ns_constrain_all_frames
();
615 ns_update_begin
(struct frame
*f
)
616 /* --------------------------------------------------------------------------
617 Prepare for a grouped sequence of drawing calls
618 external (RIF) call; whole frame, called before update_window_begin
619 -------------------------------------------------------------------------- */
621 NSView
*view = FRAME_NS_VIEW
(f
);
622 NSRect r
= [view frame
];
624 NSTRACE
(ns_update_begin
);
626 ns_update_auto_hide_menu_bar
();
628 ns_updating_frame
= f
;
631 /* drawRect may have been called for say the minibuffer, and then clip path
632 is for the minibuffer. But the display engine may draw more because
633 we have set the frame as garbaged. So reset clip path to the whole
635 bp
= [[NSBezierPath bezierPathWithRect
: r
] retain
];
639 #ifdef NS_IMPL_GNUSTEP
640 uRect
= NSMakeRect
(0, 0, 0, 0);
646 ns_update_window_begin
(struct window
*w
)
647 /* --------------------------------------------------------------------------
648 Prepare for a grouped sequence of drawing calls
649 external (RIF) call; for one window, called after update_begin
650 -------------------------------------------------------------------------- */
652 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
653 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
654 NSTRACE
(ns_update_window_begin
);
656 set_output_cursor
(&w
->cursor
);
660 if (f
== hlinfo
->mouse_face_mouse_frame
)
662 /* Don't do highlighting for mouse motion during the update. */
663 hlinfo
->mouse_face_defer
= 1;
665 /* If the frame needs to be redrawn,
666 simply forget about any prior mouse highlighting. */
667 if (FRAME_GARBAGED_P
(f
))
668 hlinfo
->mouse_face_window
= Qnil
;
670 /* (further code for mouse faces ifdef'd out in other terms elided) */
678 ns_update_window_end
(struct window
*w
, int cursor_on_p
,
679 int mouse_face_overwritten_p
)
680 /* --------------------------------------------------------------------------
681 Finished a grouped sequence of drawing calls
682 external (RIF) call; for one window called before update_end
683 -------------------------------------------------------------------------- */
685 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(XFRAME
(w
->frame
));
687 /* note: this fn is nearly identical in all terms */
688 if (!w
->pseudo_window_p
)
693 display_and_set_cursor
(w
, 1,
694 output_cursor.hpos
, output_cursor.vpos
,
695 output_cursor.x
, output_cursor.y
);
697 if (draw_window_fringes
(w
, 1))
698 x_draw_vertical_border
(w
);
703 /* If a row with mouse-face was overwritten, arrange for
704 frame_up_to_date to redisplay the mouse highlight. */
705 if (mouse_face_overwritten_p
)
707 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
708 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
709 hlinfo
->mouse_face_window
= Qnil
;
712 updated_window
= NULL;
713 NSTRACE
(update_window_end
);
718 ns_update_end
(struct frame
*f
)
719 /* --------------------------------------------------------------------------
720 Finished a grouped sequence of drawing calls
721 external (RIF) call; for whole frame, called after update_window_end
722 -------------------------------------------------------------------------- */
724 NSView
*view = FRAME_NS_VIEW
(f
);
726 /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
727 MOUSE_HL_INFO
(f
)->mouse_face_defer
= 0;
731 #ifdef NS_IMPL_GNUSTEP
732 /* trigger flush only in the rectangle we tracked as being drawn */
733 [view unlockFocusNeedsFlush
: NO
];
734 /*fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", uRect.origin.x, uRect.origin.y, uRect.size.width, uRect.size.height); */
735 [view lockFocusInRect
: uRect
];
739 [[view window
] flushWindow
];
742 ns_updating_frame
= NULL;
743 NSTRACE
(ns_update_end
);
748 ns_flush
(struct frame
*f
)
749 /* --------------------------------------------------------------------------
751 NS impl is no-op since currently we flush in ns_update_end and elsewhere
752 -------------------------------------------------------------------------- */
759 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
760 /* --------------------------------------------------------------------------
761 Internal: Focus on given frame. During small local updates this is used to
762 draw, however during large updates, ns_update_begin and ns_update_end are
763 called to wrap the whole thing, in which case these calls are stubbed out.
764 Except, on GNUstep, we accumulate the rectangle being drawn into, because
765 the back end won't do this automatically, and will just end up flushing
767 -------------------------------------------------------------------------- */
769 // NSTRACE
(ns_focus
);
770 #ifdef NS_IMPL_GNUSTEP
773 u
= NSUnionRect
(r
[0], r
[1]);
778 fprintf (stderr, "focus: %d", c++);
779 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
780 fprintf (stderr, "\n"); */
782 if (f
!= ns_updating_frame
)
784 NSView
*view = FRAME_NS_VIEW
(f
);
785 if (view != focus_view
)
787 if (focus_view
!= NULL)
789 [focus_view unlockFocus
];
790 [[focus_view window
] flushWindow
];
795 #ifdef NS_IMPL_GNUSTEP
796 r ?
[view lockFocusInRect
: u
] : [view lockFocus
];
801 /*if (view) debug_lock++; */
803 #ifdef NS_IMPL_GNUSTEP
806 /* more than one rect being drawn into */
809 [view unlockFocus
]; /* add prev rect to redraw list */
810 [view lockFocusInRect
: u
]; /* focus for draw in new rect */
815 #ifdef NS_IMPL_GNUSTEP
818 /* in batch mode, but in GNUstep must still track rectangles explicitly */
819 uRect
= (r ? NSUnionRect
(uRect
, u
) : [FRAME_NS_VIEW
(f
) visibleRect
]);
826 [[NSGraphicsContext currentContext
] saveGraphicsState
];
828 NSRectClipList
(r
, 2);
837 ns_unfocus
(struct frame
*f
)
838 /* --------------------------------------------------------------------------
839 Internal: Remove focus on given frame
840 -------------------------------------------------------------------------- */
842 // NSTRACE
(ns_unfocus
);
846 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
850 if (f
!= ns_updating_frame
)
852 if (focus_view
!= NULL)
854 [focus_view unlockFocus
];
855 [[focus_view window
] flushWindow
];
864 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
, int area
, BOOL gc
)
865 /* --------------------------------------------------------------------------
866 Internal (but parallels other terms): Focus drawing on given row
867 -------------------------------------------------------------------------- */
869 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
871 int window_x
, window_y
, window_width
;
873 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
875 clip_rect.origin.x
= window_x
;
876 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
877 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
878 clip_rect.
size.width
= window_width
;
879 clip_rect.
size.height
= row
->visible_height
;
881 ns_focus
(f
, &clip_rect
, 1);
886 ns_ring_bell
(struct frame
*f
)
887 /* --------------------------------------------------------------------------
889 -------------------------------------------------------------------------- */
891 NSTRACE
(ns_ring_bell
);
894 NSAutoreleasePool
*pool
;
895 struct frame
*frame
= SELECTED_FRAME
();
899 pool
= [[NSAutoreleasePool alloc
] init
];
901 view = FRAME_NS_VIEW
(frame
);
905 NSPoint dim
= NSMakePoint
(128, 128);
908 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
909 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
910 r.
size.width
= dim.x
;
911 r.
size.height
= dim.y
;
912 surr
= NSInsetRect
(r
, -2, -2);
913 ns_focus
(frame
, &surr
, 1);
914 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
915 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
916 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
918 [[view window
] flushWindow
];
920 [[view window
] restoreCachedImage
];
921 [[view window
] flushWindow
];
935 ns_reset_terminal_modes
(struct terminal *terminal)
936 /* Externally called as hook */
938 NSTRACE
(ns_reset_terminal_modes
);
943 ns_set_terminal_modes
(struct terminal *terminal)
944 /* Externally called as hook */
946 NSTRACE
(ns_set_terminal_modes
);
951 /* ==========================================================================
953 Frame / window manager related functions
955 ========================================================================== */
959 ns_raise_frame
(struct frame
*f
)
960 /* --------------------------------------------------------------------------
961 Bring window to foreground and make it active
962 -------------------------------------------------------------------------- */
964 NSView
*view = FRAME_NS_VIEW
(f
);
967 FRAME_SAMPLE_VISIBILITY
(f
);
968 if (FRAME_VISIBLE_P
(f
))
970 [[view window
] makeKeyAndOrderFront
: NSApp
];
977 ns_lower_frame
(struct frame
*f
)
978 /* --------------------------------------------------------------------------
980 -------------------------------------------------------------------------- */
982 NSView
*view = FRAME_NS_VIEW
(f
);
985 [[view window
] orderBack
: NSApp
];
991 ns_frame_raise_lower
(struct frame
*f
, int raise
)
992 /* --------------------------------------------------------------------------
994 -------------------------------------------------------------------------- */
996 NSTRACE
(ns_frame_raise_lower
);
1006 ns_frame_rehighlight
(struct frame
*frame
)
1007 /* --------------------------------------------------------------------------
1008 External (hook): called on things like window switching within frame
1009 -------------------------------------------------------------------------- */
1011 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(frame
);
1012 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1014 NSTRACE
(ns_frame_rehighlight
);
1015 if (dpyinfo
->x_focus_frame
)
1017 dpyinfo
->x_highlight_frame
1018 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1019 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1020 : dpyinfo
->x_focus_frame
);
1021 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
1023 fset_focus_frame
(dpyinfo
->x_focus_frame
, Qnil
);
1024 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1028 dpyinfo
->x_highlight_frame
= 0;
1030 if (dpyinfo
->x_highlight_frame
&&
1031 dpyinfo
->x_highlight_frame
!= old_highlight
)
1035 x_update_cursor
(old_highlight
, 1);
1036 x_set_frame_alpha
(old_highlight
);
1038 if (dpyinfo
->x_highlight_frame
)
1040 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
1041 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
1048 x_make_frame_visible
(struct frame
*f
)
1049 /* --------------------------------------------------------------------------
1050 External: Show the window (X11 semantics)
1051 -------------------------------------------------------------------------- */
1053 NSTRACE
(x_make_frame_visible
);
1054 /* XXX: at some points in past this was not needed, as the only place that
1055 called this (frame.c:Fraise_frame ()) also called raise_lower;
1056 if this ends up the case again, comment this out again. */
1057 if (!FRAME_VISIBLE_P
(f
))
1059 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(f
);
1060 f
->async_visible
= 1;
1064 /* Making a new frame from a fullscreen frame will make the new frame
1065 fullscreen also. So skip handleFS as this will print an error. */
1066 if (f
->want_fullscreen
== FULLSCREEN_BOTH
1067 && ([[view window
] styleMask
] & NSFullScreenWindowMask
) != 0)
1070 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
1081 x_make_frame_invisible
(struct frame
*f
)
1082 /* --------------------------------------------------------------------------
1083 External: Hide the window (X11 semantics)
1084 -------------------------------------------------------------------------- */
1086 NSView
* view = FRAME_NS_VIEW
(f
);
1087 NSTRACE
(x_make_frame_invisible
);
1089 [[view window
] orderOut
: NSApp
];
1090 f
->async_visible
= 0;
1091 f
->async_iconified
= 0;
1096 x_iconify_frame
(struct frame
*f
)
1097 /* --------------------------------------------------------------------------
1098 External: Iconify window
1099 -------------------------------------------------------------------------- */
1101 NSView
* view = FRAME_NS_VIEW
(f
);
1102 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1103 NSTRACE
(x_iconify_frame
);
1106 if (dpyinfo
->x_highlight_frame
== f
)
1107 dpyinfo
->x_highlight_frame
= 0;
1109 if ([[view window
] windowNumber
] <= 0)
1111 /* the window is still deferred. Make it very small, bring it
1112 on screen and order it out. */
1113 NSRect s
= { { 100, 100}, {0, 0} };
1115 t
= [[view window
] frame
];
1116 [[view window
] setFrame
: s display
: NO
];
1117 [[view window
] orderBack
: NSApp
];
1118 [[view window
] orderOut
: NSApp
];
1119 [[view window
] setFrame
: t display
: NO
];
1121 [[view window
] miniaturize
: NSApp
];
1124 /* Free X resources of frame F. */
1127 x_free_frame_resources
(struct frame
*f
)
1129 NSView
*view = FRAME_NS_VIEW
(f
);
1130 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1131 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1132 NSTRACE
(x_free_frame_resources
);
1135 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1139 free_frame_menubar
(f
);
1141 if (FRAME_FACE_CACHE
(f
))
1142 free_frame_faces
(f
);
1144 if (f
== dpyinfo
->x_focus_frame
)
1145 dpyinfo
->x_focus_frame
= 0;
1146 if (f
== dpyinfo
->x_highlight_frame
)
1147 dpyinfo
->x_highlight_frame
= 0;
1148 if (f
== hlinfo
->mouse_face_mouse_frame
)
1150 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1151 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1152 hlinfo
->mouse_face_window
= Qnil
;
1153 hlinfo
->mouse_face_deferred_gc
= 0;
1154 hlinfo
->mouse_face_mouse_frame
= 0;
1157 if (f
->output_data.ns
->miniimage
!= nil
)
1158 [f
->output_data.ns
->miniimage release
];
1160 [[view window
] close];
1163 xfree
(f
->output_data.ns
);
1169 x_destroy_window
(struct frame
*f
)
1170 /* --------------------------------------------------------------------------
1171 External: Delete the window
1172 -------------------------------------------------------------------------- */
1174 NSTRACE
(x_destroy_window
);
1176 x_free_frame_resources
(f
);
1182 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1183 /* --------------------------------------------------------------------------
1184 External: Position the window
1185 -------------------------------------------------------------------------- */
1187 NSView
*view = FRAME_NS_VIEW
(f
);
1188 NSArray
*screens
= [NSScreen screens
];
1189 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1190 NSScreen
*screen
= [[view window
] screen
];
1192 NSTRACE
(x_set_offset
);
1199 if (view != nil
&& screen
&& fscreen
)
1201 f
->left_pos
= f
->size_hint_flags
& XNegative
1202 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1204 /* We use visibleFrame here to take menu bar into account.
1205 Ideally we should also adjust left/top with visibleFrame.origin. */
1207 f
->top_pos
= f
->size_hint_flags
& YNegative
1208 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1209 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1210 - FRAME_TOOLBAR_HEIGHT
(f
))
1212 #ifdef NS_IMPL_GNUSTEP
1213 if (f
->left_pos
< 100)
1214 f
->left_pos
= 100; /* don't overlap menu */
1216 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1218 f
->output_data.ns
->dont_constrain
= 0;
1219 [[view window
] setFrameTopLeftPoint
:
1220 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1221 SCREENMAXBOUND
([fscreen frame
].
size.height
1222 - NS_TOP_POS
(f
)))];
1223 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1231 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1232 /* --------------------------------------------------------------------------
1233 Adjust window pixel size based on given character grid size
1234 Impl is a bit more complex than other terms, need to do some
1236 -------------------------------------------------------------------------- */
1238 EmacsView
*view = FRAME_NS_VIEW
(f
);
1239 NSWindow
*window
= [view window
];
1240 NSRect wr
= [window frame
];
1241 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1242 int pixelwidth
, pixelheight
;
1244 NSTRACE
(x_set_window_size
);
1249 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1253 check_frame_size
(f
, &rows
, &cols
);
1255 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1256 compute_fringe_widths
(f
, 0);
1258 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1259 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1261 /* If we have a toolbar, take its height into account. */
1263 /* NOTE: previously this would generate wrong result if toolbar not
1264 yet displayed and fixing toolbar_height=32 helped, but
1265 now (200903) seems no longer needed */
1266 FRAME_TOOLBAR_HEIGHT
(f
) =
1267 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1268 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1270 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1272 wr.
size.width
= pixelwidth
+ f
->border_width
;
1273 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1274 + FRAME_TOOLBAR_HEIGHT
(f
);
1276 /* Do not try to constrain to this screen. We may have multiple
1277 screens, and want Emacs to span those. Constraining to screen
1278 prevents that, and that is not nice to the user. */
1279 if (f
->output_data.ns
->zooming
)
1280 f
->output_data.ns
->zooming
= 0;
1282 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1284 [view setRows
: rows andColumns
: cols
];
1285 [window setFrame
: wr display
: YES
];
1287 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1289 /* This is a trick to compensate for Emacs' managing the scrollbar area
1290 as a fixed number of standard character columns. Instead of leaving
1291 blank space for the extra, we chopped it off above. Now for
1292 left-hand scrollbars, we shift all rendering to the left by the
1293 difference between the real width and Emacs' imagined one. For
1294 right-hand bars, don't worry about it since the extra is never used.
1295 (Obviously doesn't work for vertically split windows tho..) */
1297 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1298 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1299 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1300 : NSMakePoint
(0, 0);
1301 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1302 [view setBoundsOrigin
: origin
];
1305 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1306 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1307 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1308 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1310 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1311 cancel_mouse_face
(f
);
1318 ns_fullscreen_hook
(FRAME_PTR f
)
1320 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(f
);
1322 if (! f
->async_visible
) return;
1323 #ifndef NEW_STYLE_FS
1324 if (f
->want_fullscreen
== FULLSCREEN_BOTH
)
1326 /* Old style fs don't initiate correctly if created from
1327 init/default-frame alist, so use a timer (not nice...).
1329 [NSTimer scheduledTimerWithTimeInterval
: 0.5 target
: view
1330 selector
: @selector
(handleFS
)
1331 userInfo
: nil repeats
: NO
];
1341 /* ==========================================================================
1345 ========================================================================== */
1349 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1351 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1352 if (idx
< 1 || idx
>= color_table
->avail
)
1354 return color_table
->colors
[idx
];
1359 ns_index_color
(NSColor
*color
, struct frame
*f
)
1361 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1365 if (!color_table
->colors
)
1367 color_table
->size = NS_COLOR_CAPACITY
;
1368 color_table
->avail
= 1; /* skip idx=0 as marker */
1369 color_table
->colors
= xmalloc
(color_table
->size * sizeof
(NSColor
*));
1370 color_table
->colors
[0] = nil
;
1371 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1374 /* do we already have this color ? */
1375 for (i
= 1; i
< color_table
->avail
; i
++)
1376 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1379 if ([color_table
->empty_indices count
] > 0)
1381 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1382 [color_table
->empty_indices removeObject
: index
];
1383 idx
= [index unsignedLongValue
];
1387 if (color_table
->avail
== color_table
->size)
1388 color_table
->colors
=
1389 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1390 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1391 idx
= color_table
->avail
++;
1394 color_table
->colors
[idx
] = color
;
1396 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1402 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1404 struct ns_color_table
*color_table
;
1411 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1413 if (idx
<= 0 || idx
>= color_table
->size) {
1414 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1418 index
= [NSNumber numberWithUnsignedInt
: idx
];
1419 if ([color_table
->empty_indices containsObject
: index
]) {
1420 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1424 color
= color_table
->colors
[idx
];
1426 color_table
->colors
[idx
] = nil
;
1427 [color_table
->empty_indices addObject
: index
];
1428 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1433 ns_get_color
(const
char *name
, NSColor
**col
)
1434 /* --------------------------------------------------------------------------
1436 -------------------------------------------------------------------------- */
1437 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1438 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1439 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1442 static
char hex
[20];
1444 float r
= -1.0, g
, b
;
1445 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1447 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1450 if ([nsname isEqualToString
: @"ns_selection_color"
])
1452 nsname
= ns_selection_color
;
1453 name
= [ns_selection_color UTF8String
];
1456 /* First, check for some sort of numeric specification. */
1459 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1461 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1462 [scanner scanFloat
: &r
];
1463 [scanner scanFloat
: &g
];
1464 [scanner scanFloat
: &b
];
1466 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1467 scaling
= (snprintf
(hex
, sizeof hex
, "
%s", name + 4) - 2) / 3;
1468 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1470 int len
= (strlen
(name
) - 1);
1471 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1473 scaling
= strlen
(name
+start
) / 3;
1474 for (i
= 0; i
< 3; i
++)
1475 sprintf (hex
+ i
* (scaling
+ 1), "
%.*s/", scaling,
1476 name
+ start
+ i
* scaling
);
1477 hex
[3 * (scaling
+ 1) - 1] = '\0';
1483 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1484 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1494 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1499 /* Otherwise, color is expected to be from a list */
1501 NSEnumerator
*lenum
, *cenum
;
1505 #ifdef NS_IMPL_GNUSTEP
1506 /* XXX: who is wrong, the requestor or the implementation? */
1507 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1509 nsname
= @"highlightColor"
;
1512 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1513 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1515 cenum
= [[clist allKeys
] objectEnumerator
];
1516 while ( (name
= [cenum nextObject
]) && new
== nil
)
1518 if ([name compare
: nsname
1519 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1520 new
= [clist colorWithKey
: name
];
1526 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1533 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1534 /* --------------------------------------------------------------------------
1535 Convert a Lisp string object to a NS color
1536 -------------------------------------------------------------------------- */
1538 NSTRACE
(ns_lisp_to_color
);
1539 if (STRINGP
(color
))
1540 return ns_get_color
(SSDATA
(color
), col
);
1541 else if (SYMBOLP
(color
))
1542 return ns_get_color
(SSDATA
(SYMBOL_NAME
(color
)), col
);
1548 ns_color_to_lisp
(NSColor
*col
)
1549 /* --------------------------------------------------------------------------
1550 Convert a color to a lisp string with the RGB equivalent
1551 -------------------------------------------------------------------------- */
1553 CGFloat red
, green
, blue
, alpha
, gray;
1556 NSTRACE
(ns_color_to_lisp
);
1559 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1561 if ((str
=[[col colorNameComponent
] UTF8String
]))
1564 return build_string
((char *)str
);
1567 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1568 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1569 if (red
==green
&& red
==blue
)
1571 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1572 getWhite
: &gray alpha
: &alpha
];
1573 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1574 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1576 return build_string
(buf
);
1579 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1580 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1583 return build_string
(buf
);
1588 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1589 /* --------------------------------------------------------------------------
1590 Get ARGB values out of NSColor col and put them into color_def.
1591 If setPixel, set the pixel to a concatenated version.
1592 and set color_def pixel to the resulting index.
1593 -------------------------------------------------------------------------- */
1597 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1598 color_def
->red
= r
* 65535;
1599 color_def
->green
= g
* 65535;
1600 color_def
->blue
= b
* 65535;
1602 if (setPixel
== YES
)
1604 = ARGB_TO_ULONG
((int
)(a
*255),
1605 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1610 ns_defined_color
(struct frame
*f
,
1615 /* --------------------------------------------------------------------------
1616 Return true if named color found, and set color_def rgb accordingly.
1617 If makeIndex and alloc are nonzero put the color in the color_table,
1618 and set color_def pixel to the resulting index.
1619 If makeIndex is zero, set color_def pixel to ARGB.
1620 Return false if not found
1621 -------------------------------------------------------------------------- */
1624 NSTRACE
(ns_defined_color
);
1627 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1632 if (makeIndex
&& alloc
)
1633 color_def
->pixel
= ns_index_color
(col
, f
);
1634 ns_query_color
(col
, color_def
, !makeIndex
);
1641 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1642 /* --------------------------------------------------------------------------
1643 return an autoreleased RGB color
1644 -------------------------------------------------------------------------- */
1646 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1647 if (r
< 0.0) r
= 0.0;
1648 else if (r
> 1.0) r
= 1.0;
1649 if (g
< 0.0) g
= 0.0;
1650 else if (g
> 1.0) g
= 1.0;
1651 if (b
< 0.0) b
= 0.0;
1652 else if (b
> 1.0) b
= 1.0;
1653 if (a
< 0.0) a
= 0.0;
1654 else if (a
> 1.0) a
= 1.0;
1655 return (unsigned
long) ns_index_color
(
1656 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1661 x_set_frame_alpha
(struct frame
*f
)
1662 /* --------------------------------------------------------------------------
1663 change the entire-frame transparency
1664 -------------------------------------------------------------------------- */
1666 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1667 EmacsView
*view = FRAME_NS_VIEW
(f
);
1669 double alpha_min
= 1.0;
1671 if (dpyinfo
->x_highlight_frame
== f
)
1672 alpha
= f
->alpha
[0];
1674 alpha
= f
->alpha
[1];
1676 if (FLOATP
(Vframe_alpha_lower_limit
))
1677 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1678 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1679 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1683 else if (1.0 < alpha
)
1685 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1688 #ifdef NS_IMPL_COCOA
1689 [[view window
] setAlphaValue
: alpha
];
1694 /* ==========================================================================
1698 ========================================================================== */
1702 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1703 /* --------------------------------------------------------------------------
1704 Programmatically reposition mouse pointer in pixel coordinates
1705 -------------------------------------------------------------------------- */
1707 NSTRACE
(x_set_mouse_pixel_position
);
1710 /* FIXME: this does not work, and what about GNUstep? */
1711 #ifdef NS_IMPL_COCOA
1712 [FRAME_NS_VIEW
(f
) lockFocus
];
1713 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1714 [FRAME_NS_VIEW
(f
) unlockFocus
];
1721 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1722 /* --------------------------------------------------------------------------
1723 Programmatically reposition mouse pointer in character coordinates
1724 -------------------------------------------------------------------------- */
1728 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1729 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1731 if (pix_x
< 0) pix_x
= 0;
1732 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1734 if (pix_y
< 0) pix_y
= 0;
1735 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1737 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1742 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1743 /* ------------------------------------------------------------------------
1744 Called by EmacsView on mouseMovement events. Passes on
1745 to emacs mainstream code if we moved off of a rect of interest
1746 known as last_mouse_glyph.
1747 ------------------------------------------------------------------------ */
1749 // NSTRACE
(note_mouse_movement
);
1751 XSETFRAME
(last_mouse_motion_frame
, frame
);
1753 /* Note, this doesn't get called for enter/leave, since we don't have a
1754 position. Those are taken care of in the corresponding NSView methods. */
1756 /* has movement gone beyond last rect we were tracking? */
1757 if (x
< last_mouse_glyph.origin.x ||
1758 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1759 y
< last_mouse_glyph.origin.y ||
1760 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1762 ns_update_begin
(frame
);
1763 frame
->mouse_moved
= 1;
1764 note_mouse_highlight
(frame
, x
, y
);
1765 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1766 ns_update_end
(frame
);
1775 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1776 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1778 /* --------------------------------------------------------------------------
1779 External (hook): inform emacs about mouse position and hit parts.
1780 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1781 x & y should be position in the scrollbar (the whole bar, not the handle)
1782 and length of scrollbar respectively
1783 -------------------------------------------------------------------------- */
1787 Lisp_Object frame
, tail
;
1789 struct ns_display_info
*dpyinfo
;
1791 NSTRACE
(ns_mouse_position
);
1795 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1799 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1803 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1805 /* TODO: we do not use this path at the moment because drag events will
1806 go directly to the EmacsScroller. Leaving code in for now. */
1807 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1809 if (time
) *time
= last_mouse_movement_time
;
1810 last_mouse_scroll_bar
= nil
;
1814 /* Clear the mouse-moved flag for every frame on this display. */
1815 FOR_EACH_FRAME
(tail
, frame
)
1816 if (FRAME_NS_P
(XFRAME
(frame
))
1817 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1818 XFRAME
(frame
)->mouse_moved
= 0;
1820 last_mouse_scroll_bar
= nil
;
1821 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1822 f
= last_mouse_frame
;
1824 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1825 : SELECTED_FRAME
();
1827 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1829 view = FRAME_NS_VIEW
(*fp
);
1831 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1832 position
= [view convertPoint
: position fromView
: nil
];
1833 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1834 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1836 if (bar_window
) *bar_window
= Qnil
;
1837 if (part
) *part
= 0; /*scroll_bar_handle; */
1839 if (x
) XSETINT
(*x
, lrint
(position.x
));
1840 if (y
) XSETINT
(*y
, lrint
(position.y
));
1841 if (time
) *time
= last_mouse_movement_time
;
1851 ns_frame_up_to_date
(struct frame
*f
)
1852 /* --------------------------------------------------------------------------
1853 External (hook): Fix up mouse highlighting right after a full update.
1854 Some highlighting was deferred if GC was happening during
1855 note_mouse_highlight (), while other highlighting was deferred for update.
1856 -------------------------------------------------------------------------- */
1858 NSTRACE
(ns_frame_up_to_date
);
1862 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1863 if ((hlinfo
->mouse_face_deferred_gc || f
==hlinfo
->mouse_face_mouse_frame
)
1864 /*&& hlinfo->mouse_face_mouse_frame*/)
1868 if (hlinfo
->mouse_face_mouse_frame
)
1869 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1870 hlinfo
->mouse_face_mouse_x
,
1871 hlinfo
->mouse_face_mouse_y
);
1872 hlinfo
->mouse_face_deferred_gc
= 0;
1881 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1882 /* --------------------------------------------------------------------------
1883 External (RIF): set frame mouse pointer type.
1884 -------------------------------------------------------------------------- */
1886 NSTRACE
(ns_define_frame_cursor
);
1887 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1889 EmacsView
*view = FRAME_NS_VIEW
(f
);
1890 FRAME_POINTER_TYPE
(f
) = cursor
;
1891 [[view window
] invalidateCursorRectsForView
: view];
1892 /* Redisplay assumes this function also draws the changed frame
1893 cursor, but this function doesn't, so do it explicitly. */
1894 x_update_cursor
(f
, 1);
1900 /* ==========================================================================
1904 ========================================================================== */
1908 ns_convert_key
(unsigned code
)
1909 /* --------------------------------------------------------------------------
1910 Internal call used by NSView-keyDown.
1911 -------------------------------------------------------------------------- */
1913 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1914 / sizeof
(convert_ns_to_X_keysym
[0]));
1916 /* An array would be faster, but less easy to read. */
1917 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1918 if (code
== convert_ns_to_X_keysym
[keysym
])
1919 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1921 /* if decide to use keyCode and Carbon table, use this line:
1922 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1927 x_get_keysym_name
(int keysym
)
1928 /* --------------------------------------------------------------------------
1929 Called by keyboard.c. Not sure if the return val is important, except
1931 -------------------------------------------------------------------------- */
1933 static
char value
[16];
1934 NSTRACE
(x_get_keysym_name
);
1935 sprintf (value
, "
%d", keysym);
1941 /* ==========================================================================
1943 Block drawing operations
1945 ========================================================================== */
1949 ns_redraw_scroll_bars
(struct frame
*f
)
1953 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1954 NSTRACE
(ns_redraw_scroll_bars
);
1955 for (i
=[subviews count
]-1; i
>= 0; i
--)
1957 view = [subviews objectAtIndex
: i
];
1958 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
1965 ns_clear_frame
(struct frame
*f
)
1966 /* --------------------------------------------------------------------------
1967 External (hook): Erase the entire frame
1968 -------------------------------------------------------------------------- */
1970 NSView
*view = FRAME_NS_VIEW
(f
);
1973 NSTRACE
(ns_clear_frame
);
1975 /* comes on initial frame because we have
1976 after-make-frame-functions = select-frame */
1977 if (!FRAME_DEFAULT_FACE
(f
))
1980 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
1982 output_cursor.hpos
= output_cursor.vpos
= 0;
1983 output_cursor.x
= -1;
1988 ns_focus
(f
, &r
, 1);
1989 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
1993 /* as of 2006/11 or so this is now needed */
1994 ns_redraw_scroll_bars
(f
);
2000 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
2001 /* --------------------------------------------------------------------------
2002 External (RIF): Clear section of frame
2003 -------------------------------------------------------------------------- */
2005 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
2006 NSView
*view = FRAME_NS_VIEW
(f
);
2007 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
2012 NSTRACE
(ns_clear_frame_area
);
2014 r
= NSIntersectionRect
(r
, [view frame
]);
2015 ns_focus
(f
, &r
, 1);
2016 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
2026 ns_scroll_run
(struct window
*w
, struct run
*run
)
2027 /* --------------------------------------------------------------------------
2028 External (RIF): Insert or delete n lines at line vpos
2029 -------------------------------------------------------------------------- */
2031 struct frame
*f
= XFRAME
(w
->frame
);
2032 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2034 NSTRACE
(ns_scroll_run
);
2036 /* begin copy from other terms */
2037 /* Get frame-relative bounding box of the text display area of W,
2038 without mode lines. Include in this box the left and right
2040 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2042 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2043 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2044 bottom_y
= y
+ height
;
2048 /* Scrolling up. Make sure we don't copy part of the mode
2049 line at the bottom. */
2050 if (from_y
+ run
->height
> bottom_y
)
2051 height
= bottom_y
- from_y
;
2053 height
= run
->height
;
2057 /* Scrolling down. Make sure we don't copy over the mode line.
2059 if (to_y
+ run
->height
> bottom_y
)
2060 height
= bottom_y
- to_y
;
2062 height
= run
->height
;
2064 /* end copy from other terms */
2075 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2076 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2077 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2079 ns_focus
(f
, &dstRect
, 1);
2080 NSCopyBits
(0, srcRect
, dstOrigin
);
2089 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2090 /* --------------------------------------------------------------------------
2091 External (RIF): preparatory to fringe update after text was updated
2092 -------------------------------------------------------------------------- */
2094 struct window
*w
= updated_window
;
2098 NSTRACE
(ns_after_update_window_line
);
2100 /* begin copy from other terms */
2103 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2104 desired_row
->redraw_fringe_bitmaps_p
= 1;
2106 /* When a window has disappeared, make sure that no rest of
2107 full-width rows stays visible in the internal border. */
2108 if (windows_or_buffers_changed
2109 && desired_row
->full_width_p
2110 && (f
= XFRAME
(w
->frame
),
2111 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2113 && (height
= desired_row
->visible_height
,
2116 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2119 ns_clear_frame_area
(f
, 0, y
, width
, height
);
2120 ns_clear_frame_area
(f
,
2121 FRAME_PIXEL_WIDTH
(f
) - width
,
2129 ns_shift_glyphs_for_insert
(struct frame
*f
,
2130 int x
, int y
, int width
, int height
,
2132 /* --------------------------------------------------------------------------
2133 External (RIF): copy an area horizontally, don't worry about clearing src
2134 -------------------------------------------------------------------------- */
2136 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2137 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2138 NSPoint dstOrigin
= dstRect.origin
;
2140 NSTRACE
(ns_shift_glyphs_for_insert
);
2142 ns_focus
(f
, &dstRect
, 1);
2143 NSCopyBits
(0, srcRect
, dstOrigin
);
2149 /* ==========================================================================
2151 Character encoding and metrics
2153 ========================================================================== */
2157 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2158 /* --------------------------------------------------------------------------
2159 External (RIF); compute left/right overhang of whole string and set in s
2160 -------------------------------------------------------------------------- */
2162 struct font
*font
= s
->font
;
2166 struct font_metrics metrics
;
2167 unsigned int codes
[2];
2168 codes
[0] = *(s
->char2b
);
2169 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2171 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2172 s
->left_overhang
= -metrics.lbearing
;
2174 = metrics.rbearing
> metrics.width
2175 ? metrics.rbearing
- metrics.width
: 0;
2179 s
->left_overhang
= 0;
2180 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2181 FONT_HEIGHT
(font
) * 0.2 : 0;
2187 /* ==========================================================================
2189 Fringe and cursor drawing
2191 ========================================================================== */
2194 extern int max_used_fringe_bitmap
;
2196 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2197 struct draw_fringe_bitmap_params
*p
)
2198 /* --------------------------------------------------------------------------
2199 External (RIF); fringe-related
2200 -------------------------------------------------------------------------- */
2202 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2203 struct face
*face
= p
->face
;
2205 static EmacsImage
**bimgs
= NULL;
2206 static int nBimgs
= 0;
2208 /* grow bimgs if needed */
2209 if (nBimgs
< max_used_fringe_bitmap
)
2211 bimgs
= xrealloc
(bimgs
, max_used_fringe_bitmap
* sizeof
*bimgs
);
2212 memset
(bimgs
+ nBimgs
, 0,
2213 (max_used_fringe_bitmap
- nBimgs
) * sizeof
*bimgs
);
2214 nBimgs
= max_used_fringe_bitmap
;
2217 /* Must clip because of partially visible lines. */
2218 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2219 ns_clip_to_row
(w
, row
, -1, YES
);
2223 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
2225 /* If the fringe is adjacent to the left (right) scroll bar of a
2226 leftmost (rightmost, respectively) window, then extend its
2227 background to the gap between the fringe and the bar. */
2228 if ((WINDOW_LEFTMOST_P
(w
)
2229 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(w
))
2230 ||
(WINDOW_RIGHTMOST_P
(w
)
2231 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT
(w
)))
2233 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH
(w
);
2237 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X
(w
);
2238 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS
(w
)
2239 * FRAME_COLUMN_WIDTH
(f
));
2243 /* Bitmap fills the fringe. */
2244 if (bar_area_x
+ bar_area_width
== p
->x
)
2245 bx
= bar_area_x
+ sb_width
;
2246 else if (p
->x
+ p
->wd
== bar_area_x
)
2250 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT
(w
);
2252 nx
= bar_area_width
- sb_width
;
2253 by
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (header_line_height
,
2255 ny
= row
->visible_height
;
2260 if (bar_area_x
+ bar_area_width
== bx
)
2262 bx
= bar_area_x
+ sb_width
;
2263 nx
+= bar_area_width
- sb_width
;
2265 else if (bx
+ nx
== bar_area_x
)
2266 nx
+= bar_area_width
- sb_width
;
2271 if (bx
>= 0 && nx
> 0)
2273 NSRect r
= NSMakeRect
(bx
, by
, nx
, ny
);
2275 [ns_lookup_indexed_color
(face
->background
, f
) set];
2282 NSRect r
= NSMakeRect
(p
->x
, p
->y
, p
->wd
, p
->h
);
2283 EmacsImage
*img
= bimgs
[p
->which - 1];
2287 unsigned short
*bits
= p
->bits
+ p
->dh
;
2290 unsigned
char *cbits
= xmalloc
(len
);
2292 for (i
= 0; i
< len
; i
++)
2293 cbits
[i
] = ~
(bits
[i
] & 0xff);
2294 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2296 bimgs
[p
->which - 1] = img
;
2301 /* Since we composite the bitmap instead of just blitting it, we need
2302 to erase the whole background. */
2303 [ns_lookup_indexed_color
(face
->background
, f
) set];
2305 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2306 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
2308 fromRect
: NSZeroRect
2309 operation
: NSCompositeSourceOver
2315 NSPoint pt
= r.origin
;
2317 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2326 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2327 int x
, int y
, int cursor_type
, int cursor_width
,
2328 int on_p
, int active_p
)
2329 /* --------------------------------------------------------------------------
2330 External call (RIF): draw cursor.
2331 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2332 -------------------------------------------------------------------------- */
2335 int fx
, fy
, h
, cursor_height
;
2336 struct frame
*f
= WINDOW_XFRAME
(w
);
2337 struct glyph
*phys_cursor_glyph
;
2339 struct glyph
*cursor_glyph
;
2341 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2343 /* If cursor is out of bounds, don't draw garbage. This can happen
2344 in mini-buffer windows when switching between echo area glyphs
2347 NSTRACE
(dumpcursor
);
2352 w
->phys_cursor_type
= cursor_type
;
2353 w
->phys_cursor_on_p
= on_p
;
2355 if (cursor_type
== NO_CURSOR
)
2357 w
->phys_cursor_width
= 0;
2361 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2363 if (glyph_row
->exact_window_width_line_p
2364 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2366 glyph_row
->cursor_in_fringe_p
= 1;
2367 draw_fringe_bitmap
(w
, glyph_row
, 0);
2372 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2373 (other terminals do it the other way round). We must set
2374 w->phys_cursor_width to the cursor width. For bar cursors, that
2375 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2376 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2378 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2379 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2380 if (cursor_type
== BAR_CURSOR
)
2382 if (cursor_width
< 1)
2383 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2384 w
->phys_cursor_width
= cursor_width
;
2386 /* If we have an HBAR, "cursor_width" MAY specify height. */
2387 else if (cursor_type
== HBAR_CURSOR
)
2389 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2390 fy
+= h
- cursor_height
;
2394 r.origin.x
= fx
, r.origin.y
= fy
;
2396 r.
size.width
= w
->phys_cursor_width
;
2398 /* TODO: only needed in rare cases with last-resort font in HELLO..
2399 should we do this more efficiently? */
2400 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2403 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2404 if (face
&& NS_FACE_BACKGROUND
(face
)
2405 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2407 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2408 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2411 [FRAME_CURSOR_COLOR
(f
) set];
2413 #ifdef NS_IMPL_COCOA
2414 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2415 atomic. Cleaner ways of doing this should be investigated.
2416 One way would be to set a global variable DRAWING_CURSOR
2417 when making the call to draw_phys..(), don't focus in that
2418 case, then move the ns_unfocus() here after that call. */
2419 NSDisableScreenUpdates
();
2422 switch (cursor_type
)
2426 case FILLED_BOX_CURSOR
:
2429 case HOLLOW_BOX_CURSOR
:
2432 NSRectFill
(NSInsetRect
(r
, 1, 1));
2433 [FRAME_CURSOR_COLOR
(f
) set];
2440 /* If the character under cursor is R2L, draw the bar cursor
2441 on the right of its glyph, rather than on the left. */
2442 cursor_glyph
= get_phys_cursor_glyph
(w
);
2443 if ((cursor_glyph
->resolved_level
& 1) != 0)
2444 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2451 /* draw the character under the cursor */
2452 if (cursor_type
!= NO_CURSOR
)
2453 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2455 #ifdef NS_IMPL_COCOA
2456 NSEnableScreenUpdates
();
2463 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2464 /* --------------------------------------------------------------------------
2465 External (RIF): Draw a vertical line.
2466 -------------------------------------------------------------------------- */
2468 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2470 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2472 NSTRACE
(ns_draw_vertical_window_border
);
2474 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2476 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2478 ns_focus
(f
, &r
, 1);
2485 show_hourglass
(struct atimer
*timer
)
2487 if (hourglass_shown_p
)
2492 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2494 hourglass_shown_p
= 1;
2500 hide_hourglass
(void
)
2502 if (!hourglass_shown_p
)
2507 /* TODO: remove NSProgressIndicator from all frames */
2509 hourglass_shown_p
= 0;
2515 /* ==========================================================================
2517 Glyph drawing operations
2519 ========================================================================== */
2522 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2523 /* --------------------------------------------------------------------------
2524 Wrapper utility to account for internal border width on full-width lines,
2525 and allow top full-width rows to hit the frame top. nr should be pointer
2526 to two successive NSRects. Number of rects actually used is returned.
2527 -------------------------------------------------------------------------- */
2529 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2533 /* --------------------------------------------------------------------
2534 Draw a wavy line under glyph string s. The wave fills wave_height
2541 wave_height = 3 | * * * *
2542 --------------------------------------------------------------------- */
2545 ns_draw_underwave
(struct glyph_string
*s
, CGFloat width
, CGFloat x
)
2547 int wave_height
= 3, wave_length
= 3;
2548 int y
, dx
, dy
, odd
, xmax
;
2553 dy
= wave_height
- 1;
2557 /* Find and set clipping rectangle */
2558 waveClip
= NSMakeRect
(x
, y
, width
, wave_height
);
2559 [[NSGraphicsContext currentContext
] saveGraphicsState
];
2560 NSRectClip
(waveClip
);
2562 /* Draw the waves */
2563 a.x
= x
- ((int
)(x
) % dx);
2565 odd
= (int
)(a.x
/dx
) % 2;
2575 [NSBezierPath strokeLineFromPoint
:a toPoint
:b
];
2576 a.x
= b.x
, a.y
= b.y
;
2577 b.x
+= dx
, b.y
= y
+ odd
*dy
;
2581 /* Restore previous clipping rectangle(s) */
2582 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
2588 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2589 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2590 /* --------------------------------------------------------------------------
2591 Draw underline, overline, and strike-through on glyph string s.
2592 -------------------------------------------------------------------------- */
2594 if (s
->for_overlaps
)
2598 if (face
->underline_p
)
2600 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2602 if (face
->underline_defaulted_p
)
2605 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2607 ns_draw_underwave
(s
, width
, x
);
2609 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2613 unsigned
long thickness
, position
;
2615 /* If the prev was underlined, match its appearance. */
2616 if (s
->prev
&& s
->prev
->face
->underline_p
2617 && s
->prev
->underline_thickness
> 0)
2619 thickness
= s
->prev
->underline_thickness
;
2620 position
= s
->prev
->underline_position
;
2625 unsigned
long descent
;
2628 descent
= s
->y
+ s
->height
- s
->ybase
;
2630 /* Use underline thickness of font, defaulting to 1. */
2631 thickness
= (font
&& font
->underline_thickness
> 0)
2632 ? font
->underline_thickness
: 1;
2634 /* Determine the offset of underlining from the baseline. */
2635 if (x_underline_at_descent_line
)
2636 position
= descent
- thickness
;
2637 else if (x_use_underline_position_properties
2638 && font
&& font
->underline_position
>= 0)
2639 position
= font
->underline_position
;
2641 position
= lround
(font
->descent
/ 2);
2643 position
= underline_minimum_offset
;
2645 position
= max (position
, underline_minimum_offset
);
2647 /* Ensure underlining is not cropped. */
2648 if (descent
<= position
)
2650 position
= descent
- 1;
2653 else if (descent
< position
+ thickness
)
2657 s
->underline_thickness
= thickness
;
2658 s
->underline_position
= position
;
2660 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2662 if (face
->underline_defaulted_p
)
2665 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2669 /* Do overline. We follow other terms in using a thickness of 1
2670 and ignoring overline_margin. */
2671 if (face
->overline_p
)
2674 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2676 if (face
->overline_color_defaulted_p
)
2679 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2683 /* Do strike-through. We follow other terms for thickness and
2684 vertical position.*/
2685 if (face
->strike_through_p
)
2690 dy
= lrint
((s
->height
- 1) / 2);
2691 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2693 if (face
->strike_through_color_defaulted_p
)
2696 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2702 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2703 /* --------------------------------------------------------------------------
2704 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2705 Note we can't just use an NSDrawRect command, because of the possibility
2706 of some sides not being drawn, and because the rect will be filled.
2707 -------------------------------------------------------------------------- */
2713 s.
size.height
= thickness
;
2715 s.origin.y
+= r.
size.height
- thickness
;
2718 s.
size.height
= r.
size.height
;
2719 s.origin.y
= r.origin.y
;
2721 /* left, right (optional) */
2722 s.
size.width
= thickness
;
2727 s.origin.x
+= r.
size.width
- thickness
;
2734 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2735 char top_p
, char bottom_p
, char left_p
, char right_p
,
2736 struct glyph_string
*s
)
2737 /* --------------------------------------------------------------------------
2738 Draw a relief rect inside r, optionally leaving some sides open.
2739 Note we can't just use an NSDrawBezel command, because of the possibility
2740 of some sides not being drawn, and because the rect will be filled.
2741 -------------------------------------------------------------------------- */
2743 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2744 NSColor
*newBaseCol
= nil
;
2747 NSTRACE
(ns_draw_relief
);
2751 if (s
->face
->use_box_color_for_shadows_p
)
2753 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2755 /* else if (s->first_glyph->type == IMAGE_GLYPH
2757 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2759 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2763 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2766 if (newBaseCol
== nil
)
2767 newBaseCol
= [NSColor grayColor
];
2769 if (newBaseCol
!= baseCol
) /* TODO: better check */
2772 baseCol
= [newBaseCol retain
];
2774 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2776 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2779 [(raised_p ? lightCol
: darkCol
) set];
2781 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2784 sr.
size.height
= thickness
;
2785 if (top_p
) NSRectFill
(sr
);
2788 sr.
size.height
= r.
size.height
;
2789 sr.
size.width
= thickness
;
2790 if (left_p
) NSRectFill
(sr
);
2792 [(raised_p ? darkCol
: lightCol
) set];
2795 sr.
size.width
= r.
size.width
;
2796 sr.
size.height
= thickness
;
2797 sr.origin.y
+= r.
size.height
- thickness
;
2798 if (bottom_p
) NSRectFill
(sr
);
2801 sr.
size.height
= r.
size.height
;
2802 sr.origin.y
= r.origin.y
;
2803 sr.
size.width
= thickness
;
2804 sr.origin.x
+= r.
size.width
- thickness
;
2805 if (right_p
) NSRectFill
(sr
);
2810 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2811 /* --------------------------------------------------------------------------
2812 Function modeled after x_draw_glyph_string_box ().
2813 Sets up parameters for drawing.
2814 -------------------------------------------------------------------------- */
2816 int right_x
, last_x
;
2817 char left_p
, right_p
;
2818 struct glyph
*last_glyph
;
2823 if (s
->hl
== DRAW_MOUSE_FACE
)
2825 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2827 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2832 thickness
= face
->box_line_width
;
2834 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2836 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2837 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2838 : window_box_right
(s
->w
, s
->area
));
2839 last_glyph
= (s
->cmp || s
->img
2840 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2842 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2843 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2845 left_p
= (s
->first_glyph
->left_box_line_p
2846 ||
(s
->hl
== DRAW_MOUSE_FACE
2847 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2848 right_p
= (last_glyph
->right_box_line_p
2849 ||
(s
->hl
== DRAW_MOUSE_FACE
2850 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2852 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2854 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2855 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2857 ns_draw_box
(r
, abs (thickness
),
2858 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2863 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2864 1, 1, left_p
, right_p
, s
);
2870 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2871 /* --------------------------------------------------------------------------
2872 Modeled after x_draw_glyph_string_background, which draws BG in
2873 certain cases. Others are left to the text rendering routine.
2874 -------------------------------------------------------------------------- */
2876 NSTRACE
(ns_maybe_dumpglyphs_background
);
2878 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2880 int box_line_width
= max (s
->face
->box_line_width
, 0);
2881 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2882 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2885 if (s
->hl
== DRAW_MOUSE_FACE
)
2887 face
= FACE_FROM_ID
(s
->f
,
2888 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2890 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2893 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2895 [(NS_FACE_BACKGROUND
(face
) != 0
2896 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2897 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2900 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2901 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2904 if (s
->hl
!= DRAW_CURSOR
)
2906 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2907 s
->background_width
,
2908 s
->height
-2*box_line_width
);
2912 s
->background_filled_p
= 1;
2919 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2920 /* --------------------------------------------------------------------------
2921 Renders an image and associated borders.
2922 -------------------------------------------------------------------------- */
2924 EmacsImage
*img
= s
->img
->pixmap
;
2925 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2926 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2927 int bg_x
, bg_y
, bg_height
;
2934 NSTRACE
(ns_dumpglyphs_image
);
2936 if (s
->face
->box
!= FACE_NO_BOX
2937 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
2938 x
+= abs (s
->face
->box_line_width
);
2941 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
2942 bg_height
= s
->height
;
2943 /* other terms have this, but was causing problems w/tabbar mode */
2944 /* - 2 * box_line_vwidth; */
2946 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
2947 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
2949 /* Draw BG: if we need larger area than image itself cleared, do that,
2950 otherwise, since we composite the image under NS (instead of mucking
2951 with its background color), we must clear just the image area. */
2952 if (s
->hl
== DRAW_MOUSE_FACE
)
2954 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2956 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2959 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2961 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
2963 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
2964 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
2966 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
2967 s
->background_filled_p
= 1;
2971 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
2976 /* Draw the image.. do we need to draw placeholder if img ==nil? */
2979 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
2980 NSRect dr
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
2982 fromRect
: NSZeroRect
2983 operation
: NSCompositeSourceOver
2988 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
2989 operation
: NSCompositeSourceOver
];
2993 if (s
->hl
== DRAW_CURSOR
)
2995 [FRAME_CURSOR_COLOR
(s
->f
) set];
2996 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
2997 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
2999 /* Currently on NS img->mask is always 0. Since
3000 get_window_cursor_type specifies a hollow box cursor when on
3001 a non-masked image we never reach this clause. But we put it
3002 in in anticipation of better support for image masks on
3004 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3008 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3011 /* Draw underline, overline, strike-through. */
3012 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3014 /* Draw relief, if requested */
3015 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3017 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3019 th
= tool_bar_button_relief
>= 0 ?
3020 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3021 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3025 th
= abs (s
->img
->relief
);
3026 raised_p
= (s
->img
->relief
> 0);
3029 r.origin.x
= x
- th
;
3030 r.origin.y
= y
- th
;
3031 r.
size.width
= s
->slice.width
+ 2*th
-1;
3032 r.
size.height
= s
->slice.height
+ 2*th
-1;
3033 ns_draw_relief
(r
, th
, raised_p
,
3035 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3037 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3040 /* If there is no mask, the background won't be seen,
3041 so draw a rectangle on the image for the cursor.
3042 Do this for all images, getting transparency right is not reliable. */
3043 if (s
->hl
== DRAW_CURSOR
)
3045 int thickness
= abs (s
->img
->relief
);
3046 if (thickness
== 0) thickness
= 1;
3047 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3053 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3058 NSColor
*fgCol
, *bgCol
;
3060 if (!s
->background_filled_p
)
3062 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3063 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3065 ns_focus
(s
->f
, r
, n
);
3067 if (s
->hl
== DRAW_MOUSE_FACE
)
3069 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3071 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3074 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3076 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3077 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3079 for (i
= 0; i
< n
; ++i
)
3081 if (!s
->row
->full_width_p
)
3083 int overrun
, leftoverrun
;
3085 /* truncate to avoid overwriting fringe and/or scrollbar */
3086 overrun
= max (0, (s
->x
+ s
->background_width
)
3087 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3088 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3089 r
[i
].
size.width
-= overrun
;
3091 /* truncate to avoid overwriting to left of the window box */
3092 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3093 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3095 if (leftoverrun
> 0)
3097 r
[i
].origin.x
+= leftoverrun
;
3098 r
[i
].
size.width
-= leftoverrun
;
3101 /* XXX: Try to work between problem where a stretch glyph on
3102 a partially-visible bottom row will clear part of the
3103 modeline, and another where list-buffers headers and similar
3104 rows erroneously have visible_height set to 0. Not sure
3105 where this is coming from as other terms seem not to show. */
3106 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3111 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3112 overwriting cursor (usually when cursor on a tab) */
3113 if (s
->hl
== DRAW_CURSOR
)
3118 width
= s
->w
->phys_cursor_width
;
3119 r
[i
].
size.width
-= width
;
3120 r
[i
].origin.x
+= width
;
3124 /* Draw overlining, etc. on the cursor. */
3125 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3126 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3128 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3135 /* Draw overlining, etc. on the stretch glyph (or the part
3136 of the stretch glyph after the cursor). */
3137 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3141 s
->background_filled_p
= 1;
3147 ns_draw_glyph_string
(struct glyph_string
*s
)
3148 /* --------------------------------------------------------------------------
3149 External (RIF): Main draw-text call.
3150 -------------------------------------------------------------------------- */
3152 /* TODO (optimize): focus for box and contents draw */
3155 char box_drawn_p
= 0;
3157 NSTRACE
(ns_draw_glyph_string
);
3159 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3162 struct glyph_string
*next
;
3164 for (width
= 0, next
= s
->next
;
3165 next
&& width
< s
->right_overhang
;
3166 width
+= next
->width
, next
= next
->next
)
3167 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3169 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3171 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3172 ns_focus
(s
->f
, r
, n
);
3173 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3178 ns_dumpglyphs_stretch
(s
->next
);
3180 next
->num_clips
= 0;
3184 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3185 && (s
->first_glyph
->type == CHAR_GLYPH
3186 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3188 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3189 ns_focus
(s
->f
, r
, n
);
3190 ns_maybe_dumpglyphs_background
(s
, 1);
3191 ns_dumpglyphs_box_or_relief
(s
);
3196 switch (s
->first_glyph
->type)
3200 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3201 ns_focus
(s
->f
, r
, n
);
3202 ns_dumpglyphs_image
(s
, r
[0]);
3207 ns_dumpglyphs_stretch
(s
);
3211 case COMPOSITE_GLYPH
:
3212 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3213 ns_focus
(s
->f
, r
, n
);
3215 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3216 && ! s
->first_glyph
->u.cmp.automatic
))
3217 s
->background_filled_p
= 1;
3219 ns_maybe_dumpglyphs_background
3220 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3222 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3223 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3224 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3225 NS_DUMPGLYPH_NORMAL
));
3226 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3227 if (ns_tmp_font
== NULL)
3228 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3230 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3232 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3233 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3234 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3237 ns_tmp_font
->font.driver
->draw
3238 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3239 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3240 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
3242 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3244 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3245 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3246 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3252 case GLYPHLESS_GLYPH
:
3253 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3254 ns_focus
(s
->f
, r
, n
);
3256 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3257 && ! s
->first_glyph
->u.cmp.automatic
))
3258 s
->background_filled_p
= 1;
3260 ns_maybe_dumpglyphs_background
3261 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3263 /* Not yet implemented. */
3272 /* Draw box if not done already. */
3273 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3275 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3276 ns_focus
(s
->f
, r
, n
);
3277 ns_dumpglyphs_box_or_relief
(s
);
3286 /* ==========================================================================
3290 ========================================================================== */
3294 ns_send_appdefined
(int value
)
3295 /* --------------------------------------------------------------------------
3296 Internal: post an appdefined event which EmacsApp-sendEvent will
3297 recognize and take as a command to halt the event loop.
3298 -------------------------------------------------------------------------- */
3300 /*NSTRACE (ns_send_appdefined); */
3302 /* Only post this event if we haven't already posted one. This will end
3303 the [NXApp run] main loop after having processed all events queued at
3305 if (send_appdefined
)
3309 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3310 send_appdefined
= NO
;
3312 /* Don't need wakeup timer any more */
3315 [timed_entry invalidate
];
3316 [timed_entry release
];
3320 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3321 location
: NSMakePoint
(0, 0)
3324 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3325 context
: [NSApp context
]
3330 /* Post an application defined event on the event queue. When this is
3331 received the [NXApp run] will return, thus having processed all
3332 events which are currently queued. */
3333 [NSApp postEvent
: nxev atStart
: NO
];
3338 ns_read_socket
(struct terminal *terminal, struct input_event
*hold_quit
)
3339 /* --------------------------------------------------------------------------
3340 External (hook): Post an event to ourself and keep reading events until
3341 we read it back again. In effect process all events which were waiting.
3342 From 21+ we have to manage the event buffer ourselves.
3343 -------------------------------------------------------------------------- */
3345 struct input_event ev
;
3348 /* NSTRACE (ns_read_socket); */
3350 if ([NSApp modalWindow
] != nil
)
3354 n_emacs_events_pending
= 0;
3357 q_event_ptr
= hold_quit
;
3359 /* we manage autorelease pools by allocate/reallocate each time around
3360 the loop; strict nesting is occasionally violated but seems not to
3361 matter.. earlier methods using full nesting caused major memory leaks */
3362 [outerpool release
];
3363 outerpool
= [[NSAutoreleasePool alloc
] init
];
3365 /* If have pending open-file requests, attend to the next one of those. */
3366 if (ns_pending_files
&& [ns_pending_files count
] != 0
3367 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3369 [ns_pending_files removeObjectAtIndex
: 0];
3371 /* Deal with pending service requests. */
3372 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3374 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3375 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3377 [ns_pending_service_names removeObjectAtIndex
: 0];
3378 [ns_pending_service_args removeObjectAtIndex
: 0];
3382 /* Run and wait for events. We must always send one NX_APPDEFINED event
3383 to ourself, otherwise [NXApp run] will never exit. */
3384 send_appdefined
= YES
;
3385 ns_send_appdefined
(-1);
3387 if (++apploopnr
!= 1)
3395 nevents
= n_emacs_events_pending
;
3396 n_emacs_events_pending
= 0;
3397 emacs_event
= q_event_ptr
= NULL;
3405 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3406 fd_set
*exceptfds
, EMACS_TIME
*timeout
, sigset_t
*sigmask
)
3407 /* --------------------------------------------------------------------------
3408 Replacement for select, checking for events
3409 -------------------------------------------------------------------------- */
3414 struct input_event event
;
3417 /* NSTRACE (ns_select); */
3419 for (k
= 0; readfds
&& k
< nfds
+1; k
++)
3420 if (FD_ISSET
(k
, readfds
)) ++nr
;
3423 ||
(timeout
&& timeout
->tv_sec
== 0 && timeout
->tv_nsec
== 0))
3424 return pselect
(nfds
, readfds
, writefds
, exceptfds
, timeout
, sigmask
);
3426 [outerpool release
];
3427 outerpool
= [[NSAutoreleasePool alloc
] init
];
3430 send_appdefined
= YES
;
3433 pthread_mutex_lock
(&select_mutex
);
3438 select_readfds
= *readfds
;
3439 select_valid
+= SELECT_HAVE_READ
;
3443 select_writefds
= *writefds
;
3444 select_valid
+= SELECT_HAVE_WRITE
;
3449 select_timeout
= *timeout
;
3450 select_valid
+= SELECT_HAVE_TMO
;
3453 pthread_mutex_unlock
(&select_mutex
);
3455 /* Inform fd_handler that select should be called */
3457 write
(selfds
[1], &c
, 1);
3459 else if (nr
== 0 && timeout
)
3461 /* No file descriptor, just a timeout, no need to wake fd_handler */
3462 double time
= EMACS_TIME_TO_DOUBLE
(*timeout
);
3463 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3466 @selector
(timeout_handler
:)
3471 else /* No timeout and no file descriptors, can this happen? */
3473 /* Send appdefined so we exit from the loop */
3474 ns_send_appdefined
(-1);
3479 emacs_event
= &event
;
3480 if (++apploopnr
!= 1)
3487 if (nr
> 0 && readfds
)
3490 write
(selfds
[1], &c
, 1);
3494 ev
= last_appdefined_event
;
3499 if ([ev
type] != NSApplicationDefined
)
3503 last_appdefined_event
= 0;
3507 /* The NX_APPDEFINED event we received was a timeout. */
3512 /* The NX_APPDEFINED event we received was the result of
3513 at least one real input event arriving. */
3519 /* Received back from select () in fd_handler; copy the results */
3520 pthread_mutex_lock
(&select_mutex
);
3521 if (readfds
) *readfds
= select_readfds
;
3522 if (writefds
) *writefds
= select_writefds
;
3523 if (timeout
) *timeout
= select_timeout
;
3524 pthread_mutex_unlock
(&select_mutex
);
3534 /* ==========================================================================
3538 ========================================================================== */
3542 ns_set_vertical_scroll_bar
(struct window
*window
,
3543 int portion
, int whole
, int position
)
3544 /* --------------------------------------------------------------------------
3545 External (hook): Update or add scrollbar
3546 -------------------------------------------------------------------------- */
3550 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3551 EmacsView
*view = FRAME_NS_VIEW
(f
);
3552 int window_y
, window_height
;
3553 int top
, left
, height
, width
, sb_width
, sb_left
;
3555 BOOL fringe_extended_p
;
3557 /* optimization; display engine sends WAY too many of these.. */
3558 if (!NILP
(window
->vertical_scroll_bar
))
3560 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3561 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3563 if (view->scrollbarsNeedingUpdate
== 0)
3565 if (!windows_or_buffers_changed
)
3569 view->scrollbarsNeedingUpdate
--;
3573 NSTRACE
(ns_set_vertical_scroll_bar
);
3575 /* Get dimensions. */
3576 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3578 height
= window_height
;
3579 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3580 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3582 /* allow for displaying a skinnier scrollbar than char area allotted */
3583 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3584 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3587 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3588 /* the parent view is flipped, so we need to flip y value */
3590 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3592 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(window
))
3593 fringe_extended_p
= (WINDOW_LEFTMOST_P
(window
)
3594 && WINDOW_LEFT_FRINGE_WIDTH
(window
)
3595 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3596 || WINDOW_LEFT_MARGIN_COLS
(window
) == 0));
3598 fringe_extended_p
= (WINDOW_RIGHTMOST_P
(window
)
3599 && WINDOW_RIGHT_FRINGE_WIDTH
(window
)
3600 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3601 || WINDOW_RIGHT_MARGIN_COLS
(window
) == 0));
3603 XSETWINDOW
(win
, window
);
3606 /* we want at least 5 lines to display a scrollbar */
3607 if (WINDOW_TOTAL_LINES
(window
) < 5)
3609 if (!NILP
(window
->vertical_scroll_bar
))
3611 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3612 [bar removeFromSuperview
];
3613 wset_vertical_scroll_bar
(window
, Qnil
);
3615 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3620 if (NILP
(window
->vertical_scroll_bar
))
3622 if (width
> 0 && height
> 0)
3624 if (fringe_extended_p
)
3625 ns_clear_frame_area
(f
, sb_left
, top
, sb_width
, height
);
3627 ns_clear_frame_area
(f
, left
, top
, width
, height
);
3630 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3631 wset_vertical_scroll_bar
(window
, make_save_value
(bar, 0));
3636 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3637 oldRect
= [bar frame
];
3638 r.
size.width
= oldRect.
size.width
;
3639 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3641 if (oldRect.origin.x
!= r.origin.x
)
3642 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3647 [bar setPosition
: position portion
: portion whole
: whole
];
3653 ns_condemn_scroll_bars
(struct frame
*f
)
3654 /* --------------------------------------------------------------------------
3655 External (hook): arrange for all frame's scrollbars to be removed
3656 at next call to judge_scroll_bars, except for those redeemed.
3657 -------------------------------------------------------------------------- */
3661 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3663 NSTRACE
(ns_condemn_scroll_bars
);
3665 for (i
=[subviews count
]-1; i
>= 0; i
--)
3667 view = [subviews objectAtIndex
: i
];
3668 if ([view isKindOfClass
: [EmacsScroller
class]])
3675 ns_redeem_scroll_bar
(struct window
*window
)
3676 /* --------------------------------------------------------------------------
3677 External (hook): arrange to spare this window's scrollbar
3678 at next call to judge_scroll_bars.
3679 -------------------------------------------------------------------------- */
3682 NSTRACE
(ns_redeem_scroll_bar
);
3683 if (!NILP
(window
->vertical_scroll_bar
))
3685 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3692 ns_judge_scroll_bars
(struct frame
*f
)
3693 /* --------------------------------------------------------------------------
3694 External (hook): destroy all scrollbars on frame that weren't
3695 redeemed after call to condemn_scroll_bars.
3696 -------------------------------------------------------------------------- */
3700 EmacsView
*eview
= FRAME_NS_VIEW
(f
);
3701 NSArray
*subviews
= [[eview superview
] subviews
];
3704 NSTRACE
(ns_judge_scroll_bars
);
3705 for (i
= [subviews count
]-1; i
>= 0; --i
)
3707 view = [subviews objectAtIndex
: i
];
3708 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3714 [eview updateFrameSize
: NO
];
3719 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3721 /* XXX irrelevant under NS */
3726 /* ==========================================================================
3730 ========================================================================== */
3733 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3735 NSScreen
*screen
= [NSScreen mainScreen
];
3736 return [screen frame
].
size.height
;
3740 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3742 NSScreen
*screen
= [NSScreen mainScreen
];
3743 return [screen frame
].
size.width
;
3747 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3748 /* --------------------------------------------------------------------------
3749 Convert modifier name to lisp symbol
3750 -------------------------------------------------------------------------- */
3752 if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3754 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3756 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3758 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3760 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3762 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3770 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3771 Lisp_Object yesval
, Lisp_Object noval
,
3772 BOOL is_float
, BOOL is_modstring
)
3773 /* --------------------------------------------------------------------------
3774 Check a parameter value in user's preferences
3775 -------------------------------------------------------------------------- */
3777 const
char *value
= ns_get_defaults_value
(parameter
);
3783 if (c_strcasecmp
(value
, "YES"
) == 0)
3785 else if (c_strcasecmp
(value
, "NO"
) == 0)
3787 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3788 *result
= make_float
(f
);
3789 else if (is_modstring
&& value
)
3790 *result
= ns_string_to_lispmod
(value
);
3791 else fprintf (stderr
,
3792 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3798 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3799 /* --------------------------------------------------------------------------
3800 Initialize global info and storage for display.
3801 -------------------------------------------------------------------------- */
3803 NSScreen
*screen
= [NSScreen mainScreen
];
3804 NSWindowDepth depth
= [screen depth
];
3805 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
3807 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3808 dpyinfo
->resy
= 72.27;
3809 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3810 NSColorSpaceFromDepth
(depth
)]
3811 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3812 NSColorSpaceFromDepth
(depth
)];
3813 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3814 dpyinfo
->image_cache
= make_image_cache
();
3815 dpyinfo
->color_table
= xmalloc
(sizeof
*dpyinfo
->color_table
);
3816 dpyinfo
->color_table
->colors
= NULL;
3817 dpyinfo
->root_window
= 42; /* a placeholder.. */
3819 hlinfo
->mouse_face_mouse_frame
= NULL;
3820 hlinfo
->mouse_face_deferred_gc
= 0;
3821 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
3822 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
3823 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3824 hlinfo
->mouse_face_window
= hlinfo
->mouse_face_overlay
= Qnil
;
3825 hlinfo
->mouse_face_hidden
= 0;
3827 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
3828 hlinfo
->mouse_face_defer
= 0;
3830 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3832 dpyinfo
->n_fonts
= 0;
3833 dpyinfo
->smallest_font_height
= 1;
3834 dpyinfo
->smallest_char_width
= 1;
3838 /* This and next define (many of the) public functions in this file. */
3839 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3840 with using despite presence in the "system dependent" redisplay
3841 interface. In addition, many of the ns_ methods have code that is
3842 shared with all terms, indicating need for further refactoring. */
3843 extern frame_parm_handler ns_frame_parm_handlers
[];
3844 static
struct redisplay_interface ns_redisplay_interface
=
3846 ns_frame_parm_handlers
,
3850 x_clear_end_of_line
,
3852 ns_after_update_window_line
,
3853 ns_update_window_begin
,
3854 ns_update_window_end
,
3857 0, /* flush_display_optional */
3858 x_clear_window_mouse_face
,
3859 x_get_glyph_overhangs
,
3860 x_fix_overlapping_area
,
3861 ns_draw_fringe_bitmap
,
3862 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3863 0, /* destroy_fringe_bitmap */
3864 ns_compute_glyph_string_overhangs
,
3865 ns_draw_glyph_string
, /* interface to nsfont.m */
3866 ns_define_frame_cursor
,
3867 ns_clear_frame_area
,
3868 ns_draw_window_cursor
,
3869 ns_draw_vertical_window_border
,
3870 ns_shift_glyphs_for_insert
3875 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3881 /* This function is called when the last frame on a display is deleted. */
3883 ns_delete_terminal
(struct terminal *terminal)
3885 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3887 /* Protect against recursive calls. delete_frame in
3888 delete_terminal calls us back when it deletes our last frame. */
3889 if (!terminal->name
)
3894 x_destroy_all_bitmaps
(dpyinfo
);
3895 ns_delete_display
(dpyinfo
);
3900 static
struct terminal *
3901 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3902 /* --------------------------------------------------------------------------
3903 Set up use of NS before we make the first connection.
3904 -------------------------------------------------------------------------- */
3906 struct terminal *terminal;
3908 NSTRACE
(ns_create_terminal
);
3910 terminal = create_terminal
();
3912 terminal->type = output_ns
;
3913 terminal->display_info.ns
= dpyinfo
;
3914 dpyinfo
->terminal = terminal;
3916 terminal->rif
= &ns_redisplay_interface
;
3918 terminal->clear_frame_hook
= ns_clear_frame
;
3919 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
3920 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
3921 terminal->ring_bell_hook
= ns_ring_bell
;
3922 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
3923 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
3924 terminal->update_begin_hook
= ns_update_begin
;
3925 terminal->update_end_hook
= ns_update_end
;
3926 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
3927 terminal->read_socket_hook
= ns_read_socket
;
3928 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
3929 terminal->mouse_position_hook
= ns_mouse_position
;
3930 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
3931 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
3933 terminal->fullscreen_hook
= ns_fullscreen_hook
;
3935 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
3936 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
3937 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
3938 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
3940 terminal->delete_frame_hook
= x_destroy_window
;
3941 terminal->delete_terminal_hook
= ns_delete_terminal
;
3943 terminal->scroll_region_ok
= 1;
3944 terminal->char_ins_del_ok
= 1;
3945 terminal->line_ins_del_ok
= 1;
3946 terminal->fast_clear_end_of_line
= 1;
3947 terminal->memory_below_frame
= 0;
3953 struct ns_display_info
*
3954 ns_term_init
(Lisp_Object display_name
)
3955 /* --------------------------------------------------------------------------
3956 Start the Application and get things rolling.
3957 -------------------------------------------------------------------------- */
3959 struct terminal *terminal;
3960 struct ns_display_info
*dpyinfo
;
3961 static int ns_initialized
= 0;
3964 if (ns_initialized
) return x_display_list
;
3967 NSTRACE
(ns_term_init
);
3969 [outerpool release
];
3970 outerpool
= [[NSAutoreleasePool alloc
] init
];
3972 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
3973 /*GSDebugAllocationActive (YES); */
3977 Fset_input_interrupt_mode
(Qnil
);
3979 if (selfds
[0] == -1)
3981 if (pipe
(selfds
) == -1)
3983 fprintf (stderr
, "Failed to create pipe
: %s\n",
3984 emacs_strerror
(errno
));
3988 fcntl
(selfds
[0], F_SETFL
, O_NONBLOCK|fcntl
(selfds
[0], F_GETFL
));
3989 FD_ZERO
(&select_readfds
);
3990 FD_ZERO
(&select_writefds
);
3991 pthread_mutex_init
(&select_mutex
, NULL);
3994 ns_pending_files
= [[NSMutableArray alloc
] init
];
3995 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
3996 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
3998 /* Start app and create the main menu, window, view.
3999 Needs to be here because ns_initialize_display_info () uses AppKit classes.
4000 The view will then ask the NSApp to stop and return to Emacs. */
4001 [EmacsApp sharedApplication
];
4004 [NSApp setDelegate
: NSApp
];
4006 /* Start the select thread. */
4007 [NSThread detachNewThreadSelector
:@selector
(fd_handler
:)
4011 /* debugging: log all notifications */
4012 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4013 selector: @selector (logNotification:)
4014 name: nil object: nil]; */
4016 dpyinfo
= xzalloc
(sizeof
*dpyinfo
);
4018 ns_initialize_display_info
(dpyinfo
);
4019 terminal = ns_create_terminal
(dpyinfo
);
4021 terminal->kboard
= xmalloc
(sizeof
*terminal->kboard
);
4022 init_kboard
(terminal->kboard
);
4023 kset_window_system
(terminal->kboard
, Qns
);
4024 terminal->kboard
->next_kboard
= all_kboards
;
4025 all_kboards
= terminal->kboard
;
4026 /* Don't let the initial kboard remain current longer than necessary.
4027 That would cause problems if a file loaded on startup tries to
4028 prompt in the mini-buffer. */
4029 if (current_kboard
== initial_kboard
)
4030 current_kboard
= terminal->kboard
;
4031 terminal->kboard
->reference_count
++;
4033 dpyinfo
->next
= x_display_list
;
4034 x_display_list
= dpyinfo
;
4036 /* Put it on ns_display_name_list */
4037 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
4038 ns_display_name_list
);
4039 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
4041 terminal->name
= xstrdup
(SSDATA
(display_name
));
4045 if (!inhibit_x_resources
)
4047 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4050 /* this is a standard variable */
4051 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4052 make_float
(10.0), make_float
(6.0), YES
, NO
);
4053 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4056 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
4057 stringForKey
: @"AppleHighlightColor"
];
4058 if (ns_selection_color
== nil
)
4059 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
4062 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4066 Lisp_Object color_file
, color_map
, color
;
4070 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4071 Fsymbol_value
(intern
("data
-directory"
)));
4072 if (NILP
(Ffile_readable_p
(color_file
)))
4073 fatal
("Could not
find %s.\n", SDATA (color_file));
4075 color_map
= Fx_load_color_file
(color_file
);
4076 if (NILP
(color_map
))
4077 fatal
("Could not read
%s.\n", SDATA (color_file));
4079 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4080 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4082 color
= XCAR
(color_map
);
4083 name
= SSDATA
(XCAR
(color
));
4084 c
= XINT
(XCDR
(color
));
4086 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4087 green
: GREEN_FROM_ULONG
(c
) / 255.0
4088 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4090 forKey
: [NSString stringWithUTF8String
: name
]];
4092 [cl writeToFile
: nil
];
4097 #ifdef NS_IMPL_GNUSTEP
4098 Vwindow_system_version
= build_string
(gnustep_base_version
);
4100 /*PSnextrelease (128, c); */
4101 char c
[DBL_BUFSIZE_BOUND
];
4102 int len
= dtoastr
(c
, sizeof c
, 0, 0, NSAppKitVersionNumber
);
4103 Vwindow_system_version
= make_unibyte_string
(c
, len
);
4107 delete_keyboard_wait_descriptor
(0);
4109 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4111 /* Set up OS X app menu */
4112 #ifdef NS_IMPL_COCOA
4116 /* set up the application menu */
4117 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4118 [svcsMenu setAutoenablesItems
: NO
];
4119 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4120 [appMenu setAutoenablesItems
: NO
];
4121 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4122 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4124 [appMenu insertItemWithTitle
: @"About Emacs"
4125 action
: @selector
(orderFrontStandardAboutPanel
:)
4128 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4129 [appMenu insertItemWithTitle
: @"Preferences..."
4130 action
: @selector
(showPreferencesWindow
:)
4133 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4134 item
= [appMenu insertItemWithTitle
: @"Services"
4135 action
: @selector
(menuDown
:)
4138 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4139 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4140 [appMenu insertItemWithTitle
: @"Hide Emacs"
4141 action
: @selector
(hide
:)
4144 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4145 action
: @selector
(hideOtherApplications
:)
4148 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4149 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4150 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4151 action
: @selector
(terminate
:)
4155 item
= [mainMenu insertItemWithTitle
: ns_app_name
4156 action
: @selector
(menuDown
:)
4159 [mainMenu setSubmenu
: appMenu forItem
: item
];
4160 [dockMenu insertItemWithTitle
: @"New Frame"
4161 action
: @selector
(newFrame
:)
4165 [NSApp setMainMenu
: mainMenu
];
4166 [NSApp setAppleMenu
: appMenu
];
4167 [NSApp setServicesMenu
: svcsMenu
];
4168 /* Needed at least on Cocoa, to get dock menu to show windows */
4169 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4171 [[NSNotificationCenter defaultCenter
]
4172 addObserver
: mainMenu
4173 selector
: @selector
(trackingNotification
:)
4174 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4175 [[NSNotificationCenter defaultCenter
]
4176 addObserver
: mainMenu
4177 selector
: @selector
(trackingNotification
:)
4178 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4180 #endif
/* MAC OS X menu setup */
4182 /* Register our external input/output types, used for determining
4183 applicable services and also drag/drop eligibility. */
4184 ns_send_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
] retain
];
4185 ns_return_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
]
4187 ns_drag_types
= [[NSArray arrayWithObjects
:
4189 NSTabularTextPboardType
,
4190 NSFilenamesPboardType
,
4193 NSFontPboardType
, nil
] retain
];
4195 #ifndef NEW_STYLE_FS
4196 /* If fullscreen is in init/default-frame-alist, focus isn't set
4197 right for fullscreen windows, so set this. */
4198 [NSApp activateIgnoringOtherApps
:YES
];
4202 ns_do_open_file
= YES
;
4208 ns_term_shutdown
(int sig
)
4210 [[NSUserDefaults standardUserDefaults
] synchronize
];
4212 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4213 if (STRINGP
(Vauto_save_list_file_name
))
4214 unlink
(SSDATA
(Vauto_save_list_file_name
));
4216 if (sig
== 0 || sig
== SIGTERM
)
4218 [NSApp terminate
: NSApp
];
4220 else // force a stack
trace to happen
4227 /* ==========================================================================
4229 EmacsApp implementation
4231 ========================================================================== */
4234 @implementation EmacsApp
4236 - (void
)logNotification
: (NSNotification
*)notification
4238 const
char *name
= [[notification name
] UTF8String
];
4239 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4240 && !strstr
(name
, "WindowNumber"
))
4241 NSLog
(@"notification
: '%@'"
, [notification name
]);
4245 - (void
)sendEvent
: (NSEvent
*)theEvent
4246 /* --------------------------------------------------------------------------
4247 Called when NSApp is running for each event received. Used to stop
4248 the loop when we choose, since there's no way to just run one iteration.
4249 -------------------------------------------------------------------------- */
4251 int
type = [theEvent
type];
4252 NSWindow
*window
= [theEvent window
];
4253 /* NSTRACE (sendEvent); */
4254 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4256 #ifdef NS_IMPL_COCOA
4257 if (type == NSApplicationDefined
4258 && [theEvent data2
] == NSAPP_DATA2_RUNASSCRIPT
)
4266 if (type == NSCursorUpdate
&& window
== nil
)
4268 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4272 if (type == NSApplicationDefined
)
4274 /* Events posted by ns_send_appdefined interrupt the run loop here.
4275 But, if a modal window is up, an appdefined can still come through,
4276 (e.g., from a makeKeyWindow event) but stopping self also stops the
4277 modal loop. Just defer it until later. */
4278 if ([NSApp modalWindow
] == nil
)
4280 last_appdefined_event
= theEvent
;
4285 send_appdefined
= YES
;
4289 [super sendEvent
: theEvent
];
4293 - (void
)showPreferencesWindow
: (id
)sender
4295 struct frame
*emacsframe
= SELECTED_FRAME
();
4296 NSEvent
*theEvent
= [NSApp currentEvent
];
4300 emacs_event
->kind
= NS_NONKEY_EVENT
;
4301 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4302 emacs_event
->modifiers
= 0;
4303 EV_TRAILER
(theEvent
);
4307 - (void
)newFrame
: (id
)sender
4309 struct frame
*emacsframe
= SELECTED_FRAME
();
4310 NSEvent
*theEvent
= [NSApp currentEvent
];
4314 emacs_event
->kind
= NS_NONKEY_EVENT
;
4315 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4316 emacs_event
->modifiers
= 0;
4317 EV_TRAILER
(theEvent
);
4321 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4322 - (BOOL
) openFile
: (NSString
*)fileName
4324 struct frame
*emacsframe
= SELECTED_FRAME
();
4325 NSEvent
*theEvent
= [NSApp currentEvent
];
4330 emacs_event
->kind
= NS_NONKEY_EVENT
;
4331 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4332 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4333 ns_input_line
= Qnil
; /* can be start or cons start,end */
4334 emacs_event
->modifiers
=0;
4335 EV_TRAILER
(theEvent
);
4341 /* **************************************************************************
4343 EmacsApp delegate implementation
4345 ************************************************************************** */
4347 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4348 /* --------------------------------------------------------------------------
4349 When application is loaded, terminate event loop in ns_term_init
4350 -------------------------------------------------------------------------- */
4352 NSTRACE
(applicationDidFinishLaunching
);
4353 [NSApp setServicesProvider
: NSApp
];
4354 ns_send_appdefined
(-2);
4358 /* Termination sequences:
4361 MenuBar | File | Exit:
4362 Select Quit from App menubar:
4364 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4367 Select Quit from Dock menu:
4370 Cancel -> Nothing else
4374 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4379 - (void
) terminate
: (id
)sender
4381 struct frame
*emacsframe
= SELECTED_FRAME
();
4386 emacs_event
->kind
= NS_NONKEY_EVENT
;
4387 emacs_event
->code
= KEY_NS_POWER_OFF
;
4388 emacs_event
->arg
= Qt
; /* mark as non-key event */
4389 EV_TRAILER
((id
)nil
);
4393 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4397 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4398 return NSTerminateNow
;
4400 ret
= NSRunAlertPanel
(ns_app_name
,
4401 @"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
,
4402 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4404 if (ret
== NSAlertDefaultReturn
)
4405 return NSTerminateNow
;
4406 else if (ret
== NSAlertAlternateReturn
)
4407 return NSTerminateCancel
;
4408 return NSTerminateNow
; /* just in case */
4412 not_in_argv
(NSString
*arg
)
4415 const
char *a
= [arg UTF8String
];
4416 for (k
= 1; k
< initial_argc
; ++k
)
4417 if (strcmp (a
, initial_argv
[k
]) == 0) return 0;
4421 /* Notification from the Workspace to open a file */
4422 - (BOOL
)application
: sender openFile
: (NSString
*)file
4424 if (ns_do_open_file || not_in_argv
(file
))
4425 [ns_pending_files addObject
: file
];
4430 /* Open a file as a temporary file */
4431 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4433 if (ns_do_open_file || not_in_argv
(file
))
4434 [ns_pending_files addObject
: file
];
4439 /* Notification from the Workspace to open a file noninteractively (?) */
4440 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4442 if (ns_do_open_file || not_in_argv
(file
))
4443 [ns_pending_files addObject
: file
];
4447 /* Notification from the Workspace to open multiple files */
4448 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4450 NSEnumerator
*files
= [fileList objectEnumerator
];
4452 /* Don't open files from the command line unconditionally,
4453 Cocoa parses the command line wrong, --option value tries to open value
4454 if --option is the last option. */
4455 while ((file
= [files nextObject
]) != nil
)
4456 if (ns_do_open_file || not_in_argv
(file
))
4457 [ns_pending_files addObject
: file
];
4459 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4464 /* Handle dock menu requests. */
4465 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4471 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4472 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4474 //ns_app_active
=YES
;
4476 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4478 NSTRACE
(applicationDidBecomeActive
);
4480 //ns_app_active
=YES
;
4482 ns_update_auto_hide_menu_bar
();
4483 // No constraining takes place when the application is not active.
4484 ns_constrain_all_frames
();
4486 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4489 ns_send_appdefined
(-1);
4494 /* ==========================================================================
4496 EmacsApp aux handlers for managing event loop
4498 ========================================================================== */
4501 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4502 /* --------------------------------------------------------------------------
4503 The timeout specified to ns_select has passed.
4504 -------------------------------------------------------------------------- */
4506 /*NSTRACE (timeout_handler); */
4507 ns_send_appdefined
(-2);
4510 - (void
)fd_handler
:(id
)unused
4511 /* --------------------------------------------------------------------------
4512 Check data waiting on file descriptors and terminate if so
4513 -------------------------------------------------------------------------- */
4516 int waiting
= 1, nfds
;
4519 SELECT_TYPE readfds
, writefds
, *wfds
;
4520 EMACS_TIME timeout
, *tmo
;
4521 NSAutoreleasePool
*pool
= nil
;
4523 /* NSTRACE (fd_handler); */
4528 pool
= [[NSAutoreleasePool alloc
] init
];
4534 FD_SET
(selfds
[0], &fds
);
4535 result
= select
(selfds
[0]+1, &fds
, NULL, NULL, NULL);
4538 read
(selfds
[0], &c
, 1);
4539 if (c
== 'g') waiting
= 0;
4544 pthread_mutex_lock
(&select_mutex
);
4547 if (select_valid
& SELECT_HAVE_READ
)
4548 readfds
= select_readfds
;
4552 if (select_valid
& SELECT_HAVE_WRITE
)
4554 writefds
= select_writefds
;
4559 if (select_valid
& SELECT_HAVE_TMO
)
4561 timeout
= select_timeout
;
4567 pthread_mutex_unlock
(&select_mutex
);
4569 FD_SET
(selfds
[0], &readfds
);
4570 if (selfds
[0] >= nfds
) nfds
= selfds
[0]+1;
4572 result
= pselect
(nfds
, &readfds
, wfds
, NULL, tmo
, NULL);
4575 ns_send_appdefined
(-2);
4576 else if (result
> 0)
4578 if (FD_ISSET
(selfds
[0], &readfds
))
4580 read
(selfds
[0], &c
, 1);
4581 if (c
== 's') waiting
= 1;
4585 pthread_mutex_lock
(&select_mutex
);
4586 if (select_valid
& SELECT_HAVE_READ
)
4587 select_readfds
= readfds
;
4588 if (select_valid
& SELECT_HAVE_WRITE
)
4589 select_writefds
= writefds
;
4590 if (select_valid
& SELECT_HAVE_TMO
)
4591 select_timeout
= timeout
;
4592 pthread_mutex_unlock
(&select_mutex
);
4594 ns_send_appdefined
(result
);
4604 /* ==========================================================================
4608 ========================================================================== */
4610 /* called from system: queue for next pass through event loop */
4611 - (void
)requestService
: (NSPasteboard
*)pboard
4612 userData
: (NSString
*)userData
4613 error: (NSString
**)error
4615 [ns_pending_service_names addObject
: userData
];
4616 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4617 SSDATA
(ns_string_from_pasteboard
(pboard
))]];
4621 /* called from ns_read_socket to clear queue */
4622 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4624 struct frame
*emacsframe
= SELECTED_FRAME
();
4625 NSEvent
*theEvent
= [NSApp currentEvent
];
4630 emacs_event
->kind
= NS_NONKEY_EVENT
;
4631 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4632 ns_input_spi_name
= build_string
([name UTF8String
]);
4633 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4634 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4635 EV_TRAILER
(theEvent
);
4645 /* ==========================================================================
4647 EmacsView implementation
4649 ========================================================================== */
4652 @implementation EmacsView
4654 /* needed to inform when window closed from LISP */
4655 - (void
) setWindowClosing
: (BOOL
)closing
4657 windowClosing
= closing
;
4663 NSTRACE
(EmacsView_dealloc
);
4665 if (fs_state
== FULLSCREEN_BOTH
)
4666 [nonfs_window release
];
4671 /* called on font panel selection */
4672 - (void
)changeFont
: (id
)sender
4674 NSEvent
*e
=[[self window
] currentEvent
];
4675 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4679 NSTRACE
(changeFont
);
4683 if ((newFont
= [sender convertFont
:
4684 ((struct nsfont_info
*)face
->font
)->nsfont
]))
4686 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4688 emacs_event
->kind
= NS_NONKEY_EVENT
;
4689 emacs_event
->modifiers
= 0;
4690 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4692 size = [newFont pointSize
];
4693 ns_input_fontsize
= make_number
(lrint
(size));
4694 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4700 - (BOOL
)acceptsFirstResponder
4702 NSTRACE
(acceptsFirstResponder
);
4707 - (void
)resetCursorRects
4709 NSRect visible
= [self visibleRect
];
4710 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4711 NSTRACE
(resetCursorRects
);
4713 if (currentCursor
== nil
)
4714 currentCursor
= [NSCursor arrowCursor
];
4716 if (!NSIsEmptyRect
(visible
))
4717 [self addCursorRect
: visible cursor
: currentCursor
];
4718 [currentCursor setOnMouseEntered
: YES
];
4723 /*****************************************************************************/
4724 /* Keyboard handling. */
4727 - (void
)keyDown
: (NSEvent
*)theEvent
4729 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
4731 unsigned fnKeysym
= 0;
4733 static NSMutableArray
*nsEvArray
;
4734 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4735 static BOOL firstTime
= YES
;
4741 /* Rhapsody and OS X give up and down events for the arrow keys */
4742 if (ns_fake_keydown
== YES
)
4743 ns_fake_keydown
= NO
;
4744 else if ([theEvent
type] != NSKeyDown
)
4750 if (![[self window
] isKeyWindow
]
4751 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4752 /* we must avoid an infinite loop here. */
4753 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4755 /* XXX: There is an occasional condition in which, when Emacs display
4756 updates a different frame from the current one, and temporarily
4757 selects it, then processes some interrupt-driven input
4758 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4759 for some reason that window has its first responder set to the NSView
4760 most recently updated (I guess), which is not the correct one. */
4761 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4765 if (nsEvArray
== nil
)
4766 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4768 [NSCursor setHiddenUntilMouseMoves
: YES
];
4770 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4772 clear_mouse_face
(hlinfo
);
4773 hlinfo
->mouse_face_hidden
= 1;
4776 if (!processingCompose
)
4778 /* When using screen sharing, no left or right information is sent,
4779 so use Left key in those cases. */
4780 int is_left_key
, is_right_key
;
4782 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4783 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4785 /* (Carbon way: [theEvent keyCode]) */
4787 /* is it a "function key"? */
4788 fnKeysym
= ns_convert_key
(code
);
4791 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4792 because Emacs treats Delete and KP-Delete same (in simple.el). */
4793 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4794 code
= 0xFF08; /* backspace */
4799 /* are there modifiers? */
4800 emacs_event
->modifiers
= 0;
4801 flags
= [theEvent modifierFlags
];
4803 if (flags
& NSHelpKeyMask
)
4804 emacs_event
->modifiers |
= hyper_modifier
;
4806 if (flags
& NSShiftKeyMask
)
4807 emacs_event
->modifiers |
= shift_modifier
;
4809 is_right_key
= (flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
;
4810 is_left_key
= (flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
4811 ||
(! is_right_key
&& (flags
& NSCommandKeyMask
) == NSCommandKeyMask
);
4814 emacs_event
->modifiers |
= parse_solitary_modifier
4815 (EQ
(ns_right_command_modifier
, Qleft
)
4816 ? ns_command_modifier
4817 : ns_right_command_modifier
);
4821 emacs_event
->modifiers |
= parse_solitary_modifier
4822 (ns_command_modifier
);
4824 /* if super (default), take input manager's word so things like
4825 dvorak / qwerty layout work */
4826 if (EQ
(ns_command_modifier
, Qsuper
)
4828 && [[theEvent characters
] length] != 0)
4830 /* XXX: the code we get will be unshifted, so if we have
4831 a shift modifier, must convert ourselves */
4832 if (!(flags
& NSShiftKeyMask
))
4833 code
= [[theEvent characters
] characterAtIndex
: 0];
4835 /* this is ugly and also requires linking w/Carbon framework
4836 (for LMGetKbdType) so for now leave this rare (?) case
4837 undealt with.. in future look into CGEvent methods */
4840 long smv
= GetScriptManagerVariable
(smKeyScript
);
4841 Handle uchrHandle
= GetResource
4842 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4844 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4845 [[theEvent characters
] characterAtIndex
: 0],
4846 kUCKeyActionDisplay
,
4847 (flags
& ~NSCommandKeyMask
) >> 8,
4848 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4849 &dummy
, 1, &dummy
, &code
);
4856 is_right_key
= (flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
;
4857 is_left_key
= (flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
4858 ||
(! is_right_key
&& (flags
& NSControlKeyMask
) == NSControlKeyMask
);
4861 emacs_event
->modifiers |
= parse_solitary_modifier
4862 (EQ
(ns_right_control_modifier
, Qleft
)
4863 ? ns_control_modifier
4864 : ns_right_control_modifier
);
4867 emacs_event
->modifiers |
= parse_solitary_modifier
4868 (ns_control_modifier
);
4870 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4871 emacs_event
->modifiers |
=
4872 parse_solitary_modifier
(ns_function_modifier
);
4874 left_is_none
= NILP
(ns_alternate_modifier
)
4875 || EQ
(ns_alternate_modifier
, Qnone
);
4877 is_right_key
= (flags
& NSRightAlternateKeyMask
)
4878 == NSRightAlternateKeyMask
;
4879 is_left_key
= (flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
4881 && (flags
& NSAlternateKeyMask
) == NSAlternateKeyMask
);
4885 if ((NILP
(ns_right_alternate_modifier
)
4886 || EQ
(ns_right_alternate_modifier
, Qnone
)
4887 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
4889 { /* accept pre-interp alt comb */
4890 if ([[theEvent characters
] length] > 0)
4891 code
= [[theEvent characters
] characterAtIndex
: 0];
4892 /*HACK: clear lone shift modifier to stop next if from firing */
4893 if (emacs_event
->modifiers
== shift_modifier
)
4894 emacs_event
->modifiers
= 0;
4897 emacs_event
->modifiers |
= parse_solitary_modifier
4898 (EQ
(ns_right_alternate_modifier
, Qleft
)
4899 ? ns_alternate_modifier
4900 : ns_right_alternate_modifier
);
4903 if (is_left_key
) /* default = meta */
4905 if (left_is_none
&& !fnKeysym
)
4906 { /* accept pre-interp alt comb */
4907 if ([[theEvent characters
] length] > 0)
4908 code
= [[theEvent characters
] characterAtIndex
: 0];
4909 /*HACK: clear lone shift modifier to stop next if from firing */
4910 if (emacs_event
->modifiers
== shift_modifier
)
4911 emacs_event
->modifiers
= 0;
4914 emacs_event
->modifiers |
=
4915 parse_solitary_modifier
(ns_alternate_modifier
);
4919 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4920 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4922 /* if it was a function key or had modifiers, pass it directly to emacs */
4923 if (fnKeysym ||
(emacs_event
->modifiers
4924 && (emacs_event
->modifiers
!= shift_modifier
)
4925 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4926 /*[[theEvent characters] length] */
4928 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4930 code |
= (1<<28)|
(3<<16);
4931 else if (code
== 0x7f)
4932 code |
= (1<<28)|
(3<<16);
4934 emacs_event
->kind
= code
> 0xFF
4935 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4937 emacs_event
->code
= code
;
4938 EV_TRAILER
(theEvent
);
4944 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4945 /* if we get here we should send the key for input manager processing */
4946 if (firstTime
&& [[NSInputManager currentInputManager
]
4947 wantsToDelayTextChangeNotifications
] == NO
)
4949 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
4952 if (NS_KEYLOG
&& !processingCompose
)
4953 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
4955 processingCompose
= YES
;
4956 [nsEvArray addObject
: theEvent
];
4957 [self interpretKeyEvents
: nsEvArray
];
4958 [nsEvArray removeObject
: theEvent
];
4962 #ifdef NS_IMPL_COCOA
4963 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
4964 decided not to send key-down for.
4965 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
4966 This only applies on Tiger and earlier.
4967 If it matches one of these, send it on to keyDown. */
4968 -(void
)keyUp
: (NSEvent
*)theEvent
4970 int flags
= [theEvent modifierFlags
];
4971 int code
= [theEvent keyCode
];
4972 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
4973 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
4976 fprintf (stderr
, "keyUp
: passed test"
);
4977 ns_fake_keydown
= YES
;
4978 [self keyDown
: theEvent
];
4984 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
4987 /* <NSTextInput>: called when done composing;
4988 NOTE: also called when we delete over working text, followed immed.
4989 by doCommandBySelector: deleteBackward: */
4990 - (void
)insertText
: (id
)aString
4993 int len
= [(NSString
*)aString
length];
4997 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
4998 processingCompose
= NO
;
5003 /* first, clear any working text */
5004 if (workingText
!= nil
)
5005 [self deleteWorkingText
];
5007 /* now insert the string as keystrokes */
5008 for (i
=0; i
<len
; i
++)
5010 code
= [aString characterAtIndex
: i
];
5011 /* TODO: still need this? */
5013 code
= '~'; /* 0x7E */
5014 if (code
!= 32) /* Space */
5015 emacs_event
->modifiers
= 0;
5017 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
5018 emacs_event
->code
= code
;
5019 EV_TRAILER
((id
)nil
);
5024 /* <NSTextInput>: inserts display of composing characters */
5025 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
5027 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
5028 [aString string
] : aString
;
5030 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
5031 selRange.
length, selRange.location
);
5033 if (workingText
!= nil
)
5034 [self deleteWorkingText
];
5035 if ([str
length] == 0)
5041 processingCompose
= YES
;
5042 workingText
= [str copy
];
5043 ns_working_text
= build_string
([workingText UTF8String
]);
5045 emacs_event
->kind
= NS_TEXT_EVENT
;
5046 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
5047 EV_TRAILER
((id
)nil
);
5051 /* delete display of composing characters [not in <NSTextInput>] */
5052 - (void
)deleteWorkingText
5054 if (workingText
== nil
)
5057 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
5058 [workingText release
];
5060 processingCompose
= NO
;
5065 emacs_event
->kind
= NS_TEXT_EVENT
;
5066 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5067 EV_TRAILER
((id
)nil
);
5071 - (BOOL
)hasMarkedText
5073 return workingText
!= nil
;
5077 - (NSRange
)markedRange
5079 NSRange rng
= workingText
!= nil
5080 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5082 NSLog
(@"markedRange request"
);
5090 NSLog
(@"unmark
(accept
) text"
);
5091 [self deleteWorkingText
];
5092 processingCompose
= NO
;
5096 /* used to position char selection windows, etc. */
5097 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5101 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5103 NSLog
(@"firstRectForCharRange request"
);
5105 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5106 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5107 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5108 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5109 +FRAME_LINE_HEIGHT
(emacsframe
));
5111 pt
= [self convertPoint
: pt toView
: nil
];
5112 pt
= [[self window
] convertBaseToScreen
: pt
];
5118 - (NSInteger
)conversationIdentifier
5120 return (NSInteger
)self
;
5124 - (void
)doCommandBySelector
: (SEL
)aSelector
5127 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5129 if (aSelector
== @selector
(deleteBackward
:))
5131 /* happens when user backspaces over an ongoing composition:
5132 throw a 'delete' into the event queue */
5135 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5136 emacs_event
->code
= 0xFF08;
5137 EV_TRAILER
((id
)nil
);
5141 - (NSArray
*)validAttributesForMarkedText
5143 static NSArray
*arr
= nil
;
5144 if (arr
== nil
) arr
= [NSArray new
];
5145 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5149 - (NSRange
)selectedRange
5152 NSLog
(@"selectedRange request"
);
5153 return NSMakeRange
(NSNotFound
, 0);
5156 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5159 NSLog
(@"characterIndexForPoint request"
);
5163 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5165 static NSAttributedString
*str
= nil
;
5166 if (str
== nil
) str
= [NSAttributedString new
];
5168 NSLog
(@"attributedSubstringFromRange request"
);
5172 /* End <NSTextInput> impl. */
5173 /*****************************************************************************/
5176 /* This is what happens when the user presses a mouse button. */
5177 - (void
)mouseDown
: (NSEvent
*)theEvent
5179 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5181 NSTRACE
(mouseDown
);
5183 [self deleteWorkingText
];
5188 last_mouse_frame
= emacsframe
;
5189 /* appears to be needed to prevent spurious movement events generated on
5191 last_mouse_frame
->mouse_moved
= 0;
5193 if ([theEvent
type] == NSScrollWheel
)
5195 float delta
= [theEvent deltaY
];
5196 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5199 emacs_event
->kind
= WHEEL_EVENT
;
5200 emacs_event
->code
= 0;
5201 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5202 ((delta
> 0) ? up_modifier
: down_modifier
);
5206 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5207 emacs_event
->code
= EV_BUTTON
(theEvent
);
5208 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5209 | EV_UDMODIFIERS
(theEvent
);
5211 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5212 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5213 EV_TRAILER
(theEvent
);
5217 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5219 NSTRACE
(rightMouseDown
);
5220 [self mouseDown
: theEvent
];
5224 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5226 NSTRACE
(otherMouseDown
);
5227 [self mouseDown
: theEvent
];
5231 - (void
)mouseUp
: (NSEvent
*)theEvent
5234 [self mouseDown
: theEvent
];
5238 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5240 NSTRACE
(rightMouseUp
);
5241 [self mouseDown
: theEvent
];
5245 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5247 NSTRACE
(otherMouseUp
);
5248 [self mouseDown
: theEvent
];
5252 - (void
) scrollWheel
: (NSEvent
*)theEvent
5254 NSTRACE
(scrollWheel
);
5255 [self mouseDown
: theEvent
];
5259 /* Tell emacs the mouse has moved. */
5260 - (void
)mouseMoved
: (NSEvent
*)e
5262 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5265 // NSTRACE
(mouseMoved
);
5267 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5268 last_mouse_motion_position
5269 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5271 /* update any mouse face */
5272 if (hlinfo
->mouse_face_hidden
)
5274 hlinfo
->mouse_face_hidden
= 0;
5275 clear_mouse_face
(hlinfo
);
5278 /* tooltip handling */
5279 previous_help_echo_string
= help_echo_string
;
5280 help_echo_string
= Qnil
;
5282 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
5283 last_mouse_motion_position.y
))
5284 help_echo_string
= previous_help_echo_string
;
5286 XSETFRAME
(frame
, emacsframe
);
5287 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5289 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5290 (note_mouse_highlight), which is called through the
5291 note_mouse_movement () call above */
5292 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5293 help_echo_object
, help_echo_pos
);
5297 help_echo_string
= Qnil
;
5298 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5301 if (emacsframe
->mouse_moved
&& send_appdefined
)
5302 ns_send_appdefined
(-1);
5306 - (void
)mouseDragged
: (NSEvent
*)e
5308 NSTRACE
(mouseDragged
);
5309 [self mouseMoved
: e
];
5313 - (void
)rightMouseDragged
: (NSEvent
*)e
5315 NSTRACE
(rightMouseDragged
);
5316 [self mouseMoved
: e
];
5320 - (void
)otherMouseDragged
: (NSEvent
*)e
5322 NSTRACE
(otherMouseDragged
);
5323 [self mouseMoved
: e
];
5327 - (BOOL
)windowShouldClose
: (id
)sender
5329 NSEvent
*e
=[[self window
] currentEvent
];
5331 NSTRACE
(windowShouldClose
);
5332 windowClosing
= YES
;
5335 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5336 emacs_event
->modifiers
= 0;
5337 emacs_event
->code
= 0;
5339 /* Don't close this window, let this be done from lisp code. */
5343 - (void
) updateFrameSize
: (BOOL
) delay
;
5345 NSWindow
*window
= [self window
];
5346 NSRect wr
= [window frame
];
5347 #ifdef NS_IMPL_GNUSTEP
5353 int oldc
= cols
, oldr
= rows
;
5354 int oldw
= FRAME_PIXEL_WIDTH
(emacsframe
),
5355 oldh
= FRAME_PIXEL_HEIGHT
(emacsframe
);
5358 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
, wr.
size.width
+ extra
);
5360 if (cols
< MINWIDTH
)
5363 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
5364 (emacsframe
, wr.
size.height
5365 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + extra
5366 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5368 if (rows
< MINHEIGHT
)
5371 neww
= (int
)wr.
size.width
- emacsframe
->border_width
;
5372 newh
= ((int
)wr.
size.height
5373 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5374 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5376 if (oldr
!= rows || oldc
!= cols || neww
!= oldw || newh
!= oldh
)
5378 NSView
*view = FRAME_NS_VIEW
(emacsframe
);
5379 FRAME_PIXEL_WIDTH
(emacsframe
) = neww
;
5380 FRAME_PIXEL_HEIGHT
(emacsframe
) = newh
;
5381 change_frame_size
(emacsframe
, rows
, cols
, 0, delay
, 0);
5382 SET_FRAME_GARBAGED
(emacsframe
);
5383 cancel_mouse_face
(emacsframe
);
5384 [view setFrame
: NSMakeRect
(0, 0, neww
, newh
)];
5385 [self windowDidMove
:nil
]; // Update top
/left.
5389 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5390 /* normalize frame to gridded text size */
5392 NSTRACE
(windowWillResize
);
5393 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5395 if (fs_state
== FULLSCREEN_MAXIMIZED
5396 && (maximized_width
!= (int
)frameSize.width
5397 || maximized_height
!= (int
)frameSize.height
))
5398 [self setFSValue
: FULLSCREEN_NONE
];
5399 else if (fs_state
== FULLSCREEN_WIDTH
5400 && maximized_width
!= (int
)frameSize.width
)
5401 [self setFSValue
: FULLSCREEN_NONE
];
5402 else if (fs_state
== FULLSCREEN_HEIGHT
5403 && maximized_height
!= (int
)frameSize.height
)
5404 [self setFSValue
: FULLSCREEN_NONE
];
5405 if (fs_state
== FULLSCREEN_NONE
)
5406 maximized_width
= maximized_height
= -1;
5408 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5409 #ifdef NS_IMPL_GNUSTEP
5410 frameSize.width
+ 3);
5414 if (cols
< MINWIDTH
)
5417 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5418 #ifdef NS_IMPL_GNUSTEP
5419 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5420 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5422 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5423 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5425 if (rows
< MINHEIGHT
)
5427 #ifdef NS_IMPL_COCOA
5429 /* this sets window title to have size in it; the wm does this under GS */
5430 NSRect r
= [[self window
] frame
];
5431 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5442 NSWindow
*window
= [self window
];
5445 const
char *t
= [[[self window
] title] UTF8String
];
5446 char *pos
= strstr
(t
, " — "
);
5449 old_title
= xstrdup
(t
);
5451 size_title
= xmalloc
(strlen
(old_title
) + 40);
5452 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5453 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5458 #endif
/* NS_IMPL_COCOA */
5459 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5465 - (void
)windowDidResize
: (NSNotification
*)notification
5468 #
if !defined
(NEW_STYLE_FS
) && ! defined
(NS_IMPL_GNUSTEP
)
5469 NSWindow
*theWindow
= [notification object
];
5470 /* We can get notification on the non-FS window when in fullscreen mode. */
5471 if ([self window
] != theWindow
) return;
5474 #ifdef NS_IMPL_GNUSTEP
5475 NSWindow
*theWindow
= [notification object
];
5477 /* In GNUstep, at least currently, it's possible to get a didResize
5478 without getting a willResize.. therefore we need to act as if we got
5479 the willResize now */
5480 NSSize sz
= [theWindow frame
].
size;
5481 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5482 #endif
/* NS_IMPL_GNUSTEP */
5484 NSTRACE
(windowDidResize
);
5485 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5487 #ifdef NS_IMPL_COCOA
5493 #endif
/* NS_IMPL_COCOA */
5495 if (cols
> 0 && rows
> 0)
5497 [self updateFrameSize
: YES
];
5500 ns_send_appdefined
(-1);
5504 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5505 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5507 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5508 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5510 NSTRACE
(windowDidBecomeKey
);
5512 if (emacsframe
!= old_focus
)
5513 dpyinfo
->x_focus_frame
= emacsframe
;
5515 ns_frame_rehighlight
(emacsframe
);
5519 emacs_event
->kind
= FOCUS_IN_EVENT
;
5520 EV_TRAILER
((id
)nil
);
5525 - (void
)windowDidResignKey
: (NSNotification
*)notification
5526 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5528 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5529 NSTRACE
(windowDidResignKey
);
5531 if (dpyinfo
->x_focus_frame
== emacsframe
)
5532 dpyinfo
->x_focus_frame
= 0;
5534 ns_frame_rehighlight
(emacsframe
);
5536 /* FIXME: for some reason needed on second and subsequent clicks away
5537 from sole-frame Emacs to get hollow box to show */
5538 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5540 x_update_cursor
(emacsframe
, 1);
5541 x_set_frame_alpha
(emacsframe
);
5546 [self deleteWorkingText
];
5547 emacs_event
->kind
= FOCUS_IN_EVENT
;
5548 EV_TRAILER
((id
)nil
);
5553 - (void
)windowWillMiniaturize
: sender
5555 NSTRACE
(windowWillMiniaturize
);
5571 - initFrameFromEmacs
: (struct frame
*)f
5576 NSButton
*toggleButton
;
5581 NSTRACE
(initFrameFromEmacs
);
5584 processingCompose
= NO
;
5585 scrollbarsNeedingUpdate
= 0;
5586 fs_state
= FULLSCREEN_NONE
;
5587 fs_before_fs
= next_maximized
= -1;
5588 maximized_width
= maximized_height
= -1;
5591 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5593 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5594 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5595 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5596 [self initWithFrame
: r
];
5597 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5599 FRAME_NS_VIEW
(f
) = self
;
5603 win
= [[EmacsWindow alloc
]
5604 initWithContentRect
: r
5605 styleMask
: (NSResizableWindowMask |
5606 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5607 NSTitledWindowMask |
5609 NSMiniaturizableWindowMask |
5610 NSClosableWindowMask
)
5611 backing
: NSBackingStoreBuffered
5615 [win setCollectionBehavior
:NSWindowCollectionBehaviorFullScreenPrimary
];
5619 bwidth
= f
->border_width
= wr.
size.width
- r.
size.width
;
5620 tibar_height
= FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
5622 [win setAcceptsMouseMovedEvents
: YES
];
5623 [win setDelegate
: self
];
5624 [win useOptimizedDrawing
: YES
];
5626 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5627 sz.height
= FRAME_LINE_HEIGHT
(f
);
5628 [win setResizeIncrements
: sz
];
5630 [[win contentView
] addSubview
: self
];
5633 [self registerForDraggedTypes
: ns_drag_types
];
5636 name
= [NSString stringWithUTF8String
:
5637 NILP
(tem
) ? "Emacs"
: SSDATA
(tem
)];
5638 [win setTitle
: name
];
5640 /* toolbar support */
5641 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
5642 [NSString stringWithFormat
: @"Emacs Frame
%d",
5644 [win setToolbar
: toolbar
];
5645 [toolbar setVisible
: NO
];
5646 #ifdef NS_IMPL_COCOA
5647 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
5648 [toggleButton setTarget
: self
];
5649 [toggleButton setAction
: @selector
(toggleToolbar
: )];
5651 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5655 [win setMiniwindowTitle
:
5656 [NSString stringWithUTF8String
: SSDATA
(tem
)]];
5659 NSScreen
*screen
= [win screen
];
5662 [win setFrameTopLeftPoint
: NSMakePoint
5663 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
5664 IN_BOUND
(-SCREENMAX
,
5665 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
5668 [win makeFirstResponder
: self
];
5670 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5671 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
5672 [win setBackgroundColor
: col
];
5673 if ([col alphaComponent
] != 1.0)
5674 [win setOpaque
: NO
];
5676 [self allocateGState
];
5678 [NSApp registerServicesMenuSendTypes
: ns_send_types
5686 - (void
)windowDidMove
: sender
5688 NSWindow
*win
= [self window
];
5689 NSRect r
= [win frame
];
5690 NSArray
*screens
= [NSScreen screens
];
5691 NSScreen
*screen
= [screens objectAtIndex
: 0];
5693 NSTRACE
(windowDidMove
);
5695 if (!emacsframe
->output_data.ns
)
5699 emacsframe
->left_pos
= r.origin.x
;
5700 emacsframe
->top_pos
=
5701 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
5706 /* Called AFTER method below, but before our windowWillResize call there leads
5707 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
5708 location so set_window_size moves the frame. */
5709 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5711 emacsframe
->output_data.ns
->zooming
= 1;
5716 /* Override to do something slightly nonstandard, but nice. First click on
5717 zoom button will zoom vertically. Second will zoom completely. Third
5718 returns to original. */
5719 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5720 defaultFrame
:(NSRect
)defaultFrame
5722 NSRect result
= [sender frame
];
5724 NSTRACE
(windowWillUseStandardFrame
);
5726 if (fs_before_fs
!= -1) /* Entering fullscreen */
5728 result
= defaultFrame
;
5730 else if (next_maximized
== FULLSCREEN_HEIGHT
5731 ||
(next_maximized
== -1
5732 && abs (defaultFrame.
size.height
- result.
size.height
)
5733 > FRAME_LINE_HEIGHT
(emacsframe
)))
5736 ns_userRect
= result
;
5737 maximized_height
= result.
size.height
= defaultFrame.
size.height
;
5738 maximized_width
= -1;
5739 result.origin.y
= defaultFrame.origin.y
;
5740 [self setFSValue
: FULLSCREEN_HEIGHT
];
5742 else if (next_maximized
== FULLSCREEN_WIDTH
)
5744 ns_userRect
= result
;
5745 maximized_width
= result.
size.width
= defaultFrame.
size.width
;
5746 maximized_height
= -1;
5747 result.origin.x
= defaultFrame.origin.x
;
5748 [self setFSValue
: FULLSCREEN_WIDTH
];
5750 else if (next_maximized
== FULLSCREEN_MAXIMIZED
5751 ||
(next_maximized
== -1
5752 && abs (defaultFrame.
size.width
- result.
size.width
)
5753 > FRAME_COLUMN_WIDTH
(emacsframe
)))
5755 result
= defaultFrame
; /* second click */
5756 maximized_width
= result.
size.width
;
5757 maximized_height
= result.
size.height
;
5758 [self setFSValue
: FULLSCREEN_MAXIMIZED
];
5763 result
= ns_userRect.
size.height ? ns_userRect
: result
;
5764 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5765 [self setFSValue
: FULLSCREEN_NONE
];
5766 maximized_width
= maximized_width
= -1;
5769 if (fs_before_fs
== -1) next_maximized
= -1;
5770 [self windowWillResize
: sender toSize
: result.
size];
5775 - (void
)windowDidDeminiaturize
: sender
5777 NSTRACE
(windowDidDeminiaturize
);
5778 if (!emacsframe
->output_data.ns
)
5780 emacsframe
->async_iconified
= 0;
5781 emacsframe
->async_visible
= 1;
5782 windows_or_buffers_changed
++;
5786 emacs_event
->kind
= ICONIFY_EVENT
;
5787 EV_TRAILER
((id
)nil
);
5792 - (void
)windowDidExpose
: sender
5794 NSTRACE
(windowDidExpose
);
5795 if (!emacsframe
->output_data.ns
)
5797 emacsframe
->async_visible
= 1;
5798 SET_FRAME_GARBAGED
(emacsframe
);
5800 if (send_appdefined
)
5801 ns_send_appdefined
(-1);
5805 - (void
)windowDidMiniaturize
: sender
5807 NSTRACE
(windowDidMiniaturize
);
5808 if (!emacsframe
->output_data.ns
)
5811 emacsframe
->async_iconified
= 1;
5812 emacsframe
->async_visible
= 0;
5816 emacs_event
->kind
= ICONIFY_EVENT
;
5817 EV_TRAILER
((id
)nil
);
5821 - (void
)windowWillEnterFullScreen
:(NSNotification
*)notification
5823 fs_before_fs
= fs_state
;
5826 - (void
)windowDidEnterFullScreen
:(NSNotification
*)notification
5828 [self setFSValue
: FULLSCREEN_BOTH
];
5830 // Fix bad background.
5831 if ([toolbar isVisible
])
5833 [toolbar setVisible
:NO
];
5834 [toolbar setVisible
:YES
];
5837 [self windowDidBecomeKey
:notification
];
5838 [nonfs_window orderOut
:self
];
5842 - (void
)windowWillExitFullScreen
:(NSNotification
*)notification
5844 if (next_maximized
!= -1)
5845 fs_before_fs
= next_maximized
;
5848 - (void
)windowDidExitFullScreen
:(NSNotification
*)notification
5850 [self setFSValue
: fs_before_fs
];
5852 if (next_maximized
!= -1)
5853 [[self window
] performZoom
:self
];
5856 - (void
)toggleFullScreen
: (id
)sender
5859 [[self window
] toggleFullScreen
:sender
];
5861 NSWindow
*w
= [self window
], *fw
;
5862 BOOL onFirstScreen
= [[w screen
]
5863 isEqual:[[NSScreen screens
] objectAtIndex
:0]];
5864 struct frame
*f
= emacsframe
;
5866 NSRect r
, wr
= [w frame
];
5867 NSColor
*col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5868 (FRAME_DEFAULT_FACE
(f
)),
5871 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5872 sz.height
= FRAME_LINE_HEIGHT
(f
);
5874 if (fs_state
!= FULLSCREEN_BOTH
)
5876 /* Hide dock and menubar if we are on the primary screen. */
5879 #
if defined
(NS_IMPL_COCOA
) && \
5880 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
5881 NSApplicationPresentationOptions options
5882 = NSApplicationPresentationAutoHideDock
5883 | NSApplicationPresentationAutoHideMenuBar
;
5885 [NSApp setPresentationOptions
: options
];
5887 [NSMenu setMenuBarVisible
:NO
];
5891 fw
= [[EmacsFSWindow alloc
]
5892 initWithContentRect
:[w contentRectForFrameRect
:wr
]
5893 styleMask
:NSBorderlessWindowMask
5894 backing
:NSBackingStoreBuffered
5898 [fw setContentView
:[w contentView
]];
5899 [fw setTitle
:[w
title]];
5900 [fw setDelegate
:self
];
5901 [fw setAcceptsMouseMovedEvents
: YES
];
5902 [fw useOptimizedDrawing
: YES
];
5903 [fw setResizeIncrements
: sz
];
5904 [fw setBackgroundColor
: col
];
5905 if ([col alphaComponent
] != 1.0)
5908 f
->border_width
= 0;
5909 FRAME_NS_TITLEBAR_HEIGHT
(f
) = 0;
5910 tobar_height
= FRAME_TOOLBAR_HEIGHT
(f
);
5911 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5912 FRAME_EXTERNAL_TOOL_BAR
(f
) = 0;
5916 [self windowWillEnterFullScreen
:nil
];
5917 [fw makeKeyAndOrderFront
:NSApp
];
5918 [fw makeFirstResponder
:self
];
5920 r
= [fw frameRectForContentRect
:[[fw screen
] frame
]];
5921 [fw setFrame
: r display
:YES animate
:YES
];
5922 [self windowDidEnterFullScreen
:nil
];
5933 #
if defined
(NS_IMPL_COCOA
) && \
5934 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
5935 [NSApp setPresentationOptions
: NSApplicationPresentationDefault
];
5937 [NSMenu setMenuBarVisible
:YES
];
5941 [w setContentView
:[fw contentView
]];
5942 [w setResizeIncrements
: sz
];
5943 [w setBackgroundColor
: col
];
5944 if ([col alphaComponent
] != 1.0)
5947 f
->border_width
= bwidth
;
5948 FRAME_NS_TITLEBAR_HEIGHT
(f
) = tibar_height
;
5949 FRAME_TOOLBAR_HEIGHT
(f
) = tobar_height
;
5951 FRAME_EXTERNAL_TOOL_BAR
(f
) = 1;
5953 [self windowWillExitFullScreen
:nil
];
5954 [fw setFrame
: [w frame
] display
:YES animate
:YES
];
5956 [w makeKeyAndOrderFront
:NSApp
];
5957 [self windowDidExitFullScreen
:nil
];
5964 if (fs_state
!= emacsframe
->want_fullscreen
)
5966 if (fs_state
== FULLSCREEN_BOTH
)
5968 [self toggleFullScreen
:self
];
5971 switch (emacsframe
->want_fullscreen
)
5973 case FULLSCREEN_BOTH
:
5974 [self toggleFullScreen
:self
];
5976 case FULLSCREEN_WIDTH
:
5977 next_maximized
= FULLSCREEN_WIDTH
;
5978 if (fs_state
!= FULLSCREEN_BOTH
)
5979 [[self window
] performZoom
:self
];
5981 case FULLSCREEN_HEIGHT
:
5982 next_maximized
= FULLSCREEN_HEIGHT
;
5983 if (fs_state
!= FULLSCREEN_BOTH
)
5984 [[self window
] performZoom
:self
];
5986 case FULLSCREEN_MAXIMIZED
:
5987 next_maximized
= FULLSCREEN_MAXIMIZED
;
5988 if (fs_state
!= FULLSCREEN_BOTH
)
5989 [[self window
] performZoom
:self
];
5991 case FULLSCREEN_NONE
:
5992 if (fs_state
!= FULLSCREEN_BOTH
)
5994 next_maximized
= FULLSCREEN_NONE
;
5995 [[self window
] performZoom
:self
];
6000 emacsframe
->want_fullscreen
= FULLSCREEN_NONE
;
6005 - (void
) setFSValue
: (int
)value
6007 Lisp_Object lval
= Qnil
;
6010 case FULLSCREEN_BOTH
:
6013 case FULLSCREEN_WIDTH
:
6016 case FULLSCREEN_HEIGHT
:
6019 case FULLSCREEN_MAXIMIZED
:
6023 store_frame_param
(emacsframe
, Qfullscreen
, lval
);
6027 - (void
)mouseEntered
: (NSEvent
*)theEvent
6029 NSTRACE
(mouseEntered
);
6030 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
6034 - (void
)mouseExited
: (NSEvent
*)theEvent
6036 Mouse_HLInfo
*hlinfo
= emacsframe ? MOUSE_HL_INFO
(emacsframe
) : NULL;
6038 NSTRACE
(mouseExited
);
6043 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
6045 if (emacsframe
== hlinfo
->mouse_face_mouse_frame
)
6047 clear_mouse_face
(hlinfo
);
6048 hlinfo
->mouse_face_mouse_frame
= 0;
6056 if (context_menu_value
== -1)
6057 context_menu_value
= [sender tag
];
6060 NSInteger tag
= [sender tag
];
6061 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
6062 emacsframe
->menu_bar_vector
,
6066 ns_send_appdefined
(-1);
6071 - (EmacsToolbar
*)toolbar
6077 /* this gets called on toolbar button click */
6078 - toolbarClicked
: (id
)item
6081 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
6083 NSTRACE
(toolbarClicked
);
6088 /* send first event (for some reason two needed) */
6089 theEvent
= [[self window
] currentEvent
];
6090 emacs_event
->kind
= TOOL_BAR_EVENT
;
6091 XSETFRAME
(emacs_event
->arg
, emacsframe
);
6092 EV_TRAILER
(theEvent
);
6094 emacs_event
->kind
= TOOL_BAR_EVENT
;
6095 /* XSETINT (emacs_event->code, 0); */
6096 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
6097 idx
+ TOOL_BAR_ITEM_KEY
);
6098 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6099 EV_TRAILER
(theEvent
);
6104 - toggleToolbar
: (id
)sender
6109 emacs_event
->kind
= NS_NONKEY_EVENT
;
6110 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
6111 EV_TRAILER
((id
)nil
);
6116 - (void
)drawRect
: (NSRect
)rect
6118 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
6119 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
6123 if (!emacsframe ||
!emacsframe
->output_data.ns
)
6126 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
6127 expose_frame
(emacsframe
, x
, y
, width
, height
);
6130 drawRect: may be called (at least in OS X 10.5) for invisible
6131 views as well for some reason. Thus, do not infer visibility
6134 emacsframe->async_visible = 1;
6135 emacsframe->async_iconified = 0;
6140 /* NSDraggingDestination protocol methods. Actually this is not really a
6141 protocol, but a category of Object. O well... */
6143 -(NSUInteger
) draggingEntered
: (id
<NSDraggingInfo
>) sender
6145 NSTRACE
(draggingEntered
);
6146 return NSDragOperationGeneric
;
6150 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
6156 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
6161 NSEvent
*theEvent
= [[self window
] currentEvent
];
6164 NSTRACE
(performDragOperation
);
6169 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
6170 x
= lrint
(position.x
); y
= lrint
(position.y
);
6172 pb
= [sender draggingPasteboard
];
6173 type = [pb availableTypeFromArray
: ns_drag_types
];
6178 else if ([type isEqualToString
: NSFilenamesPboardType
])
6181 NSEnumerator
*fenum
;
6184 if (!(files
= [pb propertyListForType
: type]))
6187 fenum
= [files objectEnumerator
];
6188 while ( (file
= [fenum nextObject
]) )
6190 emacs_event
->kind
= NS_NONKEY_EVENT
;
6191 emacs_event
->code
= KEY_NS_DRAG_FILE
;
6192 XSETINT
(emacs_event
->x
, x
);
6193 XSETINT
(emacs_event
->y
, y
);
6194 ns_input_file
= append2
(ns_input_file
,
6195 build_string
([file UTF8String
]));
6196 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6197 EV_TRAILER
(theEvent
);
6201 else if ([type isEqualToString
: NSURLPboardType
])
6206 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
6207 [fileURL isFileURL
] == NO
)
6210 file
= [fileURL
path];
6211 emacs_event
->kind
= NS_NONKEY_EVENT
;
6212 emacs_event
->code
= KEY_NS_DRAG_FILE
;
6213 XSETINT
(emacs_event
->x
, x
);
6214 XSETINT
(emacs_event
->y
, y
);
6215 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
6216 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6217 EV_TRAILER
(theEvent
);
6220 else if ([type isEqualToString
: NSStringPboardType
]
6221 ||
[type isEqualToString
: NSTabularTextPboardType
])
6225 if (! (data
= [pb stringForType
: type]))
6228 emacs_event
->kind
= NS_NONKEY_EVENT
;
6229 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
6230 XSETINT
(emacs_event
->x
, x
);
6231 XSETINT
(emacs_event
->y
, y
);
6232 ns_input_text
= build_string
([data UTF8String
]);
6233 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6234 EV_TRAILER
(theEvent
);
6237 else if ([type isEqualToString
: NSColorPboardType
])
6239 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
6240 emacs_event
->kind
= NS_NONKEY_EVENT
;
6241 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
6242 XSETINT
(emacs_event
->x
, x
);
6243 XSETINT
(emacs_event
->y
, y
);
6244 ns_input_color
= ns_color_to_lisp
(c
);
6245 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6246 EV_TRAILER
(theEvent
);
6249 else if ([type isEqualToString
: NSFontPboardType
])
6251 /* impl based on GNUstep NSTextView.m */
6252 NSData
*data
= [pb dataForType
: NSFontPboardType
];
6253 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
6254 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
6260 emacs_event
->kind
= NS_NONKEY_EVENT
;
6261 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
6262 XSETINT
(emacs_event
->x
, x
);
6263 XSETINT
(emacs_event
->y
, y
);
6264 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
6265 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
6266 ns_input_fontsize
= build_string
(fontSize
);
6267 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6268 EV_TRAILER
(theEvent
);
6273 error ("Invalid data
type in dragging pasteboard."
);
6279 - (id
) validRequestorForSendType
: (NSString
*)typeSent
6280 returnType
: (NSString
*)typeReturned
6282 NSTRACE
(validRequestorForSendType
);
6283 if (typeSent
!= nil
&& [ns_send_types indexOfObject
: typeSent
] != NSNotFound
6284 && typeReturned
== nil
)
6286 if (! NILP
(ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
)))
6290 return [super validRequestorForSendType
: typeSent
6291 returnType
: typeReturned
];
6295 /* The next two methods are part of NSServicesRequests informal protocol,
6296 supposedly called when a services menu item is chosen from this app.
6297 But this should not happen because we override the services menu with our
6298 own entries which call ns-perform-service.
6299 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
6300 So let's at least stub them out until further investigation can be done. */
6302 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
6304 /* we could call ns_string_from_pasteboard(pboard) here but then it should
6305 be written into the buffer in place of the existing selection..
6306 ordinary service calls go through functions defined in ns-win.el */
6310 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
6312 NSArray
*typesDeclared
;
6315 /* We only support NSStringPboardType */
6316 if ([types containsObject
:NSStringPboardType
] == NO
) {
6320 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6321 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
6324 if (CONSP
(val
) && NILP
(XCDR
(val
)))
6327 if (! STRINGP
(val
))
6330 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
6331 [pb declareTypes
:typesDeclared owner
:nil
];
6332 ns_string_to_pasteboard
(pb
, val
);
6337 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
6338 (gives a miniaturized version of the window); currently we use the latter for
6339 frames whose active buffer doesn't correspond to any file
6340 (e.g., '*scratch*') */
6341 - setMiniwindowImage
: (BOOL
) setMini
6343 id
image = [[self window
] miniwindowImage
];
6344 NSTRACE
(setMiniwindowImage
);
6346 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6347 about "AppleDockIconEnabled" notwithstanding, however the set message
6348 below has its effect nonetheless. */
6349 if (image != emacsframe
->output_data.ns
->miniimage
)
6351 if (image && [image isKindOfClass
: [EmacsImage
class]])
6353 [[self window
] setMiniwindowImage
:
6354 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6361 - (void
) setRows
: (int
) r andColumns
: (int
) c
6367 @
end /* EmacsView */
6371 /* ==========================================================================
6373 EmacsWindow implementation
6375 ========================================================================== */
6377 @implementation EmacsWindow
6379 #ifdef NS_IMPL_COCOA
6380 - (id
)accessibilityAttributeValue
:(NSString
*)attribute
6382 Lisp_Object str
= Qnil
;
6383 struct frame
*f
= SELECTED_FRAME
();
6384 struct buffer
*curbuf
= XBUFFER
(XWINDOW
(f
->selected_window
)->buffer
);
6386 if ([attribute isEqualToString
:NSAccessibilityRoleAttribute
])
6387 return NSAccessibilityTextFieldRole
;
6389 if ([attribute isEqualToString
:NSAccessibilitySelectedTextAttribute
]
6390 && curbuf
&& ! NILP
(BVAR
(curbuf
, mark_active
)))
6392 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6394 else if (curbuf
&& [attribute isEqualToString
:NSAccessibilityValueAttribute
])
6396 if (! NILP
(BVAR
(curbuf
, mark_active
)))
6397 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6401 ptrdiff_t start_byte
= BUF_BEGV_BYTE
(curbuf
);
6402 ptrdiff_t byte_range
= BUF_ZV_BYTE
(curbuf
) - start_byte
;
6403 ptrdiff_t range
= BUF_ZV
(curbuf
) - BUF_BEGV
(curbuf
);
6405 if (! NILP
(BVAR
(curbuf
, enable_multibyte_characters
)))
6406 str
= make_uninit_multibyte_string
(range
, byte_range
);
6408 str
= make_uninit_string
(range
);
6409 /* To check: This returns emacs-utf-8, which is a superset of utf-8.
6410 Is this a problem? */
6411 memcpy
(SDATA
(str
), BYTE_POS_ADDR
(start_byte
), byte_range
);
6418 if (CONSP
(str
) && SYMBOLP
(XCAR
(str
)))
6421 if (CONSP
(str
) && NILP
(XCDR
(str
)))
6426 const
char *utfStr
= SSDATA
(str
);
6427 NSString
*nsStr
= [NSString stringWithUTF8String
: utfStr
];
6432 return [super accessibilityAttributeValue
:attribute
];
6434 #endif
/* NS_IMPL_COCOA */
6436 /* If we have multiple monitors, one above the other, we don't want to
6437 restrict the height to just one monitor. So we override this. */
6438 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6440 /* When making the frame visible for the first time or if there is just
6441 one screen, we want to constrain. Other times not. */
6442 NSUInteger nr_screens
= [[NSScreen screens
] count
];
6443 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6444 NSTRACE
(constrainFrameRect
);
6446 if (nr_screens
== 1)
6448 NSRect r
= [super constrainFrameRect
:frameRect toScreen
:screen
];
6452 if (f
->output_data.ns
->dont_constrain
6453 || ns_menu_bar_should_be_hidden
())
6456 f
->output_data.ns
->dont_constrain
= 1;
6457 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6460 @
end /* EmacsWindow */
6463 @implementation EmacsFSWindow
6465 - (BOOL
)canBecomeKeyWindow
6470 - (BOOL
)canBecomeMainWindow
6477 /* ==========================================================================
6479 EmacsScroller implementation
6481 ========================================================================== */
6484 @implementation EmacsScroller
6486 /* for repeat button push */
6487 #define SCROLL_BAR_FIRST_DELAY
0.5
6488 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6490 + (CGFloat
) scrollerWidth
6492 /* TODO: if we want to allow variable widths, this is the place to do it,
6493 however neither GNUstep nor Cocoa support it very well */
6494 return [NSScroller scrollerWidth
];
6498 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
6500 NSTRACE
(EmacsScroller_initFrame
);
6502 r.
size.width
= [EmacsScroller scrollerWidth
];
6503 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
6504 [self setContinuous
: YES
];
6505 [self setEnabled
: YES
];
6507 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
6508 locked against the top and bottom edges, and right edge on OS X, where
6509 scrollers are on right. */
6510 #ifdef NS_IMPL_GNUSTEP
6511 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
6513 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
6518 pixel_height
= NSHeight
(r
);
6519 if (pixel_height
== 0) pixel_height
= 1;
6520 min_portion
= 20 / pixel_height
;
6522 frame
= XFRAME
(XWINDOW
(win
)->frame
);
6523 if (FRAME_LIVE_P
(frame
))
6526 EmacsView
*view = FRAME_NS_VIEW
(frame
);
6527 NSView
*sview
= [[view window
] contentView
];
6528 NSArray
*subs
= [sview subviews
];
6530 /* disable optimization stopping redraw of other scrollbars */
6531 view->scrollbarsNeedingUpdate
= 0;
6532 for (i
=[subs count
]-1; i
>= 0; i
--)
6533 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
6534 view->scrollbarsNeedingUpdate
++;
6535 [sview addSubview
: self
];
6538 /* [self setFrame: r]; */
6544 - (void
)setFrame
: (NSRect
)newRect
6546 NSTRACE
(EmacsScroller_setFrame
);
6547 /* block_input (); */
6548 pixel_height
= NSHeight
(newRect
);
6549 if (pixel_height
== 0) pixel_height
= 1;
6550 min_portion
= 20 / pixel_height
;
6551 [super setFrame
: newRect
];
6553 /* unblock_input (); */
6559 NSTRACE
(EmacsScroller_dealloc
);
6561 wset_vertical_scroll_bar
(XWINDOW
(win
), Qnil
);
6589 /* ensure other scrollbar updates after deletion */
6590 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6592 view->scrollbarsNeedingUpdate
++;
6593 [self removeFromSuperview
];
6601 - (void
)resetCursorRects
6603 NSRect visible
= [self visibleRect
];
6604 NSTRACE
(resetCursorRects
);
6606 if (!NSIsEmptyRect
(visible
))
6607 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
6608 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
6612 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
6615 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
6616 && portion
!= whole
; /* needed for resize empty buf */
6620 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
6622 NSTRACE
(setPosition
);
6624 em_position
= position
;
6625 em_portion
= portion
;
6628 if (portion
>= whole
)
6630 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6631 [self setKnobProportion
: 1.0];
6632 [self setDoubleValue
: 1.0];
6634 [self setFloatValue
: 0.0 knobProportion
: 1.0];
6640 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
6641 pos
= (float
)position
/ (whole
- portion
);
6642 por
= (float
)portion
/whole
;
6643 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6644 [self setKnobProportion
: por
];
6645 [self setDoubleValue
: pos
];
6647 [self setFloatValue
: pos knobProportion
: por
];
6653 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
6654 drag events will go directly to the EmacsScroller. Leaving in for now. */
6655 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
6656 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
6658 *part
= last_hit_part
;
6660 XSETINT
(*y
, pixel_height
);
6661 if ([self floatValue
] > 0.999)
6662 XSETINT
(*x
, pixel_height
);
6664 XSETINT
(*x
, pixel_height
* [self floatValue
]);
6668 /* set up emacs_event */
6669 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
6674 emacs_event
->part
= last_hit_part
;
6675 emacs_event
->code
= 0;
6676 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
6677 emacs_event
->frame_or_window
= win
;
6678 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
6679 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
6680 emacs_event
->arg
= Qnil
;
6681 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
6682 XSETINT
(emacs_event
->y
, pixel_height
-20);
6686 n_emacs_events_pending
++;
6687 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
6690 kbd_buffer_store_event
(emacs_event
);
6691 EVENT_INIT
(*emacs_event
);
6692 ns_send_appdefined
(-1);
6696 /* called manually thru timer to implement repeated button action w/hold-down */
6697 - repeatScroll
: (NSTimer
*)scrollEntry
6699 NSEvent
*e
= [[self window
] currentEvent
];
6700 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
6701 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
6703 /* clear timer if need be */
6704 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
6706 [scroll_repeat_entry invalidate
];
6707 [scroll_repeat_entry release
];
6708 scroll_repeat_entry
= nil
;
6714 = [[NSTimer scheduledTimerWithTimeInterval
:
6715 SCROLL_BAR_CONTINUOUS_DELAY
6717 selector
: @selector
(repeatScroll
:)
6723 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
6728 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
6729 mouseDragged events without going into a modal loop. */
6730 - (void
)mouseDown
: (NSEvent
*)e
6733 /* hitPart is only updated AFTER event is passed on */
6734 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6735 double inc
= 0.0, loc
, kloc
, pos
;
6738 NSTRACE
(EmacsScroller_mouseDown
);
6742 case NSScrollerDecrementPage
:
6743 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6744 case NSScrollerIncrementPage
:
6745 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6746 case NSScrollerDecrementLine
:
6747 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6748 case NSScrollerIncrementLine
:
6749 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6750 case NSScrollerKnob
:
6751 last_hit_part
= scroll_bar_handle
; break;
6752 case NSScrollerKnobSlot
: /* GNUstep-only */
6753 last_hit_part
= scroll_bar_move_ratio
; break;
6754 default
: /* NSScrollerNoPart? */
6755 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
6762 pos
= 0; /* ignored */
6764 /* set a timer to repeat, as we can't let superclass do this modally */
6766 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
6768 selector
: @selector
(repeatScroll
:)
6775 /* handle, or on GNUstep possibly slot */
6776 NSEvent
*fake_event
;
6778 /* compute float loc in slot and mouse offset on knob */
6779 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6781 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6787 else if (loc
>= NSHeight
(sr
))
6789 loc
= NSHeight
(sr
);
6797 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6799 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6801 last_mouse_offset
= kloc
;
6803 /* if knob, tell emacs a location offset by knob pos
6804 (to indicate top of handle) */
6805 if (part
== NSScrollerKnob
)
6806 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6808 /* else this is a slot click on GNUstep: go straight there */
6809 pos
= loc
/ NSHeight
(sr
);
6811 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6812 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6813 location
: [e locationInWindow
]
6814 modifierFlags
: [e modifierFlags
]
6815 timestamp
: [e timestamp
]
6816 windowNumber
: [e windowNumber
]
6817 context
: [e context
]
6818 eventNumber
: [e eventNumber
]
6819 clickCount
: [e clickCount
]
6820 pressure
: [e pressure
]];
6821 [super mouseUp
: fake_event
];
6824 if (part
!= NSScrollerKnob
)
6825 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6829 /* Called as we manually track scroller drags, rather than superclass. */
6830 - (void
)mouseDragged
: (NSEvent
*)e
6836 NSTRACE
(EmacsScroller_mouseDragged
);
6838 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6840 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6847 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6849 loc
= NSHeight
(sr
) + last_mouse_offset
;
6853 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6854 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6858 - (void
)mouseUp
: (NSEvent
*)e
6860 if (scroll_repeat_entry
)
6862 [scroll_repeat_entry invalidate
];
6863 [scroll_repeat_entry release
];
6864 scroll_repeat_entry
= nil
;
6870 /* treat scrollwheel events in the bar as though they were in the main window */
6871 - (void
) scrollWheel
: (NSEvent
*)theEvent
6873 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6874 [view mouseDown
: theEvent
];
6877 @
end /* EmacsScroller */
6882 /* ==========================================================================
6884 Font-related functions; these used to be in nsfaces.m
6886 ========================================================================== */
6890 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6892 struct font
*font
= XFONT_OBJECT
(font_object
);
6895 fontset
= fontset_from_font
(font_object
);
6896 FRAME_FONTSET
(f
) = fontset
;
6898 if (FRAME_FONT
(f
) == font
)
6899 /* This font is already set in frame F. There's nothing more to
6903 FRAME_FONT
(f
) = font
;
6905 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6906 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6907 FRAME_SPACE_WIDTH
(f
) = font
->space_width
;
6908 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6910 compute_fringe_widths
(f
, 1);
6912 /* Compute the scroll bar width in character columns. */
6913 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6915 int wid
= FRAME_COLUMN_WIDTH
(f
);
6916 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6917 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6921 int wid
= FRAME_COLUMN_WIDTH
(f
);
6922 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6925 /* Now make the frame display the given font. */
6926 if (FRAME_NS_WINDOW
(f
) != 0)
6927 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6933 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6934 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6938 ns_xlfd_to_fontname
(const
char *xlfd
)
6939 /* --------------------------------------------------------------------------
6940 Convert an X font name (XLFD) to an NS font name.
6941 Only family is used.
6942 The string returned is temporarily allocated.
6943 -------------------------------------------------------------------------- */
6945 char *name
= xmalloc
(180);
6949 if (!strncmp
(xlfd
, "
--"
, 2))
6950 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
6952 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
6954 /* stopgap for malformed XLFD input */
6955 if (strlen
(name
) == 0)
6956 strcpy
(name
, "Monaco"
);
6958 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
6959 also uppercase after '-' or ' ' */
6960 name
[0] = c_toupper
(name
[0]);
6961 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
6967 name
[i
+1] = c_toupper
(name
[i
+1]);
6969 else if (name
[i
] == '_')
6973 name
[i
+1] = c_toupper
(name
[i
+1]);
6976 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
6977 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
6984 syms_of_nsterm
(void
)
6986 NSTRACE
(syms_of_nsterm
);
6988 ns_antialias_threshold
= 10.0;
6990 /* from 23+ we need to tell emacs what modifiers there are.. */
6991 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
6992 DEFSYM
(Qalt
, "alt"
);
6993 DEFSYM
(Qhyper
, "hyper"
);
6994 DEFSYM
(Qmeta
, "
meta"
);
6995 DEFSYM
(Qsuper
, "super"
);
6996 DEFSYM
(Qcontrol
, "control"
);
6997 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
6999 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
7000 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
7001 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
7002 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
7003 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
7005 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
7006 "The file specified in the last NS event."
);
7007 ns_input_file
=Qnil
;
7009 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
7010 "The data received in the last NS
text drag event."
);
7011 ns_input_text
=Qnil
;
7013 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
7014 "String
for visualizing working composition sequence."
);
7015 ns_working_text
=Qnil
;
7017 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
7018 "The font specified in the last NS event."
);
7019 ns_input_font
=Qnil
;
7021 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
7022 "The fontsize specified in the last NS event."
);
7023 ns_input_fontsize
=Qnil
;
7025 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
7026 "The
line specified in the last NS event."
);
7027 ns_input_line
=Qnil
;
7029 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
7030 "The color specified in the last NS event."
);
7031 ns_input_color
=Qnil
;
7033 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
7034 "The service name specified in the last NS event."
);
7035 ns_input_spi_name
=Qnil
;
7037 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
7038 "The service argument specified in the last NS event."
);
7039 ns_input_spi_arg
=Qnil
;
7041 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
7042 "This variable describes the behavior of the alternate or option key.
\n\
7043 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7044 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
7045 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7046 ns_alternate_modifier
= Qmeta
;
7048 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
7049 "This variable describes the behavior of the right alternate or option key.
\n\
7050 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7051 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
7052 Set to none means that the alternate / option key is not interpreted by Emacs\n\
7053 at all, allowing it to be used at a lower level for accented character entry.");
7054 ns_right_alternate_modifier = Qleft;
7056 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
7057 "This variable describes the behavior of the command key.\n\
7058 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
7059 ns_command_modifier = Qsuper;
7061 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
7062 "This variable describes the behavior of the right command key.\n\
7063 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7064 Set to left means be the same key as `ns-command-modifier'.
\n\
7065 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
7066 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7067 ns_right_command_modifier
= Qleft
;
7069 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
7070 "This variable describes the behavior of the control key.
\n\
7071 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
7072 ns_control_modifier
= Qcontrol
;
7074 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
7075 "This variable describes the behavior of the right control key.
\n\
7076 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7077 Set to left means be the same key as `ns
-control
-modifier
'.\n\
7078 Set to none means that the control / option key is not interpreted by Emacs\n\
7079 at all, allowing it to be used at a lower level for accented character entry.");
7080 ns_right_control_modifier = Qleft;
7082 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
7083 "This variable describes the behavior of the function key (on laptops).\n\
7084 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7085 Set to none means that the function key is not interpreted by Emacs at all,\n\
7086 allowing it to be used at a lower level for accented character entry.");
7087 ns_function_modifier = Qnone;
7089 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
7090 "Non-nil (the default) means to render text antialiased. Only has an effect on OS X Panther and above.");
7091 ns_antialias_text = Qt;
7093 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
7094 "Whether to confirm application quit using dialog.");
7095 ns_confirm_quit = Qnil;
7097 staticpro (&ns_display_name_list);
7098 ns_display_name_list = Qnil;
7100 staticpro (&last_mouse_motion_frame);
7101 last_mouse_motion_frame = Qnil;
7103 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
7104 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
7105 Only works on OSX 10.6 or later. */);
7106 ns_auto_hide_menu_bar = Qnil;
7108 /* TODO: move to common code */
7109 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
7110 doc: /* Which toolkit scroll bars Emacs uses, if any.
7111 A value of nil means Emacs doesn't use toolkit scroll bars.
7112 With the X Window system
, the value is a symbol describing the
7113 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
7114 With MS Windows or Nextstep
, the value is t. */
);
7115 Vx_toolkit_scroll_bars
= Qt
;
7117 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
7118 x_use_underline_position_properties
,
7119 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
7120 A value of nil means ignore them. If you encounter fonts with bogus
7121 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
7122 to 4.1, set this to nil. */);
7123 x_use_underline_position_properties
= 0;
7125 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
7126 x_underline_at_descent_line
,
7127 doc: /* Non-nil means to draw the underline at the same place as the descent line.
7128 A value of nil means to draw the underline according to the value of the
7129 variable `x-use-underline-position-properties', which is usually at the
7130 baseline level. The default value is nil. */);
7131 x_underline_at_descent_line
= 0;
7133 /* Tell emacs about this window system. */
7134 Fprovide
(intern
("ns"
), Qnil
);