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. */
36 #include
<sys
/types.h
>
42 #include
<c
-strcase.h
>
46 #include "blockinput.h"
47 #include "sysselect.h"
50 #include "character.h"
52 #include "composite.h"
55 #include "termhooks.h"
65 int term_trace_num
= 0;
66 #define NSTRACE
(x
) fprintf (stderr
, "
%s:%d: [%d] " #x "\n", \
67 __FILE__
, __LINE__
, ++term_trace_num
)
72 #
if defined
(NS_IMPL_COCOA
) && \
73 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
77 extern NSString
*NSMenuDidBeginTrackingNotification
;
79 /* ==========================================================================
83 ========================================================================== */
85 /* Convert a symbol indexed with an NSxxx value to a value as defined
86 in keyboard.c (lispy_function_key). I hope this is a correct way
88 static unsigned convert_ns_to_X_keysym
[] =
90 NSHomeFunctionKey
, 0x50,
91 NSLeftArrowFunctionKey
, 0x51,
92 NSUpArrowFunctionKey
, 0x52,
93 NSRightArrowFunctionKey
, 0x53,
94 NSDownArrowFunctionKey
, 0x54,
95 NSPageUpFunctionKey
, 0x55,
96 NSPageDownFunctionKey
, 0x56,
97 NSEndFunctionKey
, 0x57,
98 NSBeginFunctionKey
, 0x58,
99 NSSelectFunctionKey
, 0x60,
100 NSPrintFunctionKey
, 0x61,
101 NSClearLineFunctionKey
, 0x0B,
102 NSExecuteFunctionKey
, 0x62,
103 NSInsertFunctionKey
, 0x63,
104 NSUndoFunctionKey
, 0x65,
105 NSRedoFunctionKey
, 0x66,
106 NSMenuFunctionKey
, 0x67,
107 NSFindFunctionKey
, 0x68,
108 NSHelpFunctionKey
, 0x6A,
109 NSBreakFunctionKey
, 0x6B,
111 NSF1FunctionKey
, 0xBE,
112 NSF2FunctionKey
, 0xBF,
113 NSF3FunctionKey
, 0xC0,
114 NSF4FunctionKey
, 0xC1,
115 NSF5FunctionKey
, 0xC2,
116 NSF6FunctionKey
, 0xC3,
117 NSF7FunctionKey
, 0xC4,
118 NSF8FunctionKey
, 0xC5,
119 NSF9FunctionKey
, 0xC6,
120 NSF10FunctionKey
, 0xC7,
121 NSF11FunctionKey
, 0xC8,
122 NSF12FunctionKey
, 0xC9,
123 NSF13FunctionKey
, 0xCA,
124 NSF14FunctionKey
, 0xCB,
125 NSF15FunctionKey
, 0xCC,
126 NSF16FunctionKey
, 0xCD,
127 NSF17FunctionKey
, 0xCE,
128 NSF18FunctionKey
, 0xCF,
129 NSF19FunctionKey
, 0xD0,
130 NSF20FunctionKey
, 0xD1,
131 NSF21FunctionKey
, 0xD2,
132 NSF22FunctionKey
, 0xD3,
133 NSF23FunctionKey
, 0xD4,
134 NSF24FunctionKey
, 0xD5,
136 NSBackspaceCharacter
, 0x08, /* 8: Not on some KBs. */
137 NSDeleteCharacter
, 0xFF, /* 127: Big 'delete' key upper right. */
138 NSDeleteFunctionKey
, 0x9F, /* 63272: Del forw key off main array. */
140 NSTabCharacter
, 0x09,
141 0x19, 0x09, /* left tab->regular since pass shift */
142 NSCarriageReturnCharacter
, 0x0D,
143 NSNewlineCharacter
, 0x0D,
144 NSEnterCharacter
, 0x8D,
146 0x41|NSNumericPadKeyMask
, 0xAE, /* KP_Decimal */
147 0x43|NSNumericPadKeyMask
, 0xAA, /* KP_Multiply */
148 0x45|NSNumericPadKeyMask
, 0xAB, /* KP_Add */
149 0x4B|NSNumericPadKeyMask
, 0xAF, /* KP_Divide */
150 0x4E|NSNumericPadKeyMask
, 0xAD, /* KP_Subtract */
151 0x51|NSNumericPadKeyMask
, 0xBD, /* KP_Equal */
152 0x52|NSNumericPadKeyMask
, 0xB0, /* KP_0 */
153 0x53|NSNumericPadKeyMask
, 0xB1, /* KP_1 */
154 0x54|NSNumericPadKeyMask
, 0xB2, /* KP_2 */
155 0x55|NSNumericPadKeyMask
, 0xB3, /* KP_3 */
156 0x56|NSNumericPadKeyMask
, 0xB4, /* KP_4 */
157 0x57|NSNumericPadKeyMask
, 0xB5, /* KP_5 */
158 0x58|NSNumericPadKeyMask
, 0xB6, /* KP_6 */
159 0x59|NSNumericPadKeyMask
, 0xB7, /* KP_7 */
160 0x5B|NSNumericPadKeyMask
, 0xB8, /* KP_8 */
161 0x5C|NSNumericPadKeyMask
, 0xB9, /* KP_9 */
163 0x1B, 0x1B /* escape */
166 static Lisp_Object Qmodifier_value
;
167 Lisp_Object Qalt
, Qcontrol
, Qhyper
, Qmeta
, Qsuper
;
168 extern Lisp_Object Qcursor_color
, Qcursor_type
, Qns
, Qleft
;
170 static Lisp_Object QUTF8_STRING
;
172 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
173 the maximum font size to NOT antialias. On GNUstep there is currently
174 no way to control this behavior. */
175 float ns_antialias_threshold
;
177 /* Used to pick up AppleHighlightColor on OS X */
178 NSString
*ns_selection_color
;
180 NSArray
*ns_send_types
=0, *ns_return_types
=0, *ns_drag_types
=0;
181 NSString
*ns_app_name
= @"Emacs"
; /* default changed later */
183 /* Display variables */
184 struct ns_display_info
*x_display_list
; /* Chain of existing displays */
185 Lisp_Object ns_display_name_list
;
186 long context_menu_value
= 0;
189 NSPoint last_mouse_motion_position
;
190 static NSRect last_mouse_glyph
;
191 static Time last_mouse_movement_time
= 0;
192 static Lisp_Object last_mouse_motion_frame
;
193 static EmacsScroller
*last_mouse_scroll_bar
= nil
;
194 static
struct frame
*ns_updating_frame
;
195 static NSView
*focus_view
= NULL;
196 static int ns_window_num
= 0;
197 #ifdef NS_IMPL_GNUSTEP
200 static BOOL gsaved
= NO
;
201 static BOOL ns_fake_keydown
= NO
;
202 int ns_tmp_flags
; /* FIXME */
203 struct nsfont_info
*ns_tmp_font
; /* FIXME */
204 static BOOL ns_menu_bar_is_hidden
= NO
;
205 /*static int debug_lock = 0; */
208 static BOOL send_appdefined
= YES
;
209 #define NO_APPDEFINED_DATA
(-8)
210 static int last_appdefined_event_data
= NO_APPDEFINED_DATA
;
211 static NSTimer
*timed_entry
= 0;
212 static NSTimer
*scroll_repeat_entry
= nil
;
213 static fd_set select_readfds
, select_writefds
;
214 enum
{ SELECT_HAVE_READ
= 1, SELECT_HAVE_WRITE
= 2, SELECT_HAVE_TMO
= 4 };
215 static int select_nfds
= 0, select_valid
= 0;
216 static EMACS_TIME select_timeout
= { 0, 0 };
217 static int selfds
[2] = { -1, -1 };
218 static pthread_mutex_t select_mutex
;
219 static int apploopnr
= 0;
220 static NSAutoreleasePool
*outerpool
;
221 static
struct input_event
*emacs_event
= NULL;
222 static
struct input_event
*q_event_ptr
= NULL;
223 static int n_emacs_events_pending
= 0;
224 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
225 *ns_pending_service_args
;
226 static BOOL ns_do_open_file
= NO
;
229 struct input_event
*q
;
235 /* Convert modifiers in a NeXTstep event to emacs style modifiers. */
236 #define NS_FUNCTION_KEY_MASK
0x800000
237 #define NSLeftControlKeyMask
(0x000001 | NSControlKeyMask
)
238 #define NSRightControlKeyMask
(0x002000 | NSControlKeyMask
)
239 #define NSLeftCommandKeyMask
(0x000008 | NSCommandKeyMask
)
240 #define NSRightCommandKeyMask
(0x000010 | NSCommandKeyMask
)
241 #define NSLeftAlternateKeyMask
(0x000020 | NSAlternateKeyMask
)
242 #define NSRightAlternateKeyMask
(0x000040 | NSAlternateKeyMask
)
243 #define EV_MODIFIERS
(e
) \
244 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
245 hyper_modifier
: 0) \
246 |
(!EQ
(ns_right_alternate_modifier
, Qleft
) && \
247 (([e modifierFlags
] & NSRightAlternateKeyMask
) \
248 == NSRightAlternateKeyMask
) ? \
249 parse_solitary_modifier
(ns_right_alternate_modifier
) : 0) \
250 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
251 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
252 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
253 shift_modifier
: 0) \
254 |
(!EQ
(ns_right_control_modifier
, Qleft
) && \
255 (([e modifierFlags
] & NSRightControlKeyMask
) \
256 == NSRightControlKeyMask
) ? \
257 parse_solitary_modifier
(ns_right_control_modifier
) : 0) \
258 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
259 parse_solitary_modifier
(ns_control_modifier
) : 0) \
260 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
261 parse_solitary_modifier
(ns_function_modifier
) : 0) \
262 |
(!EQ
(ns_right_command_modifier
, Qleft
) && \
263 (([e modifierFlags
] & NSRightCommandKeyMask
) \
264 == NSRightCommandKeyMask
) ? \
265 parse_solitary_modifier
(ns_right_command_modifier
) : 0) \
266 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
267 parse_solitary_modifier
(ns_command_modifier
):0))
269 #define EV_UDMODIFIERS
(e
) \
270 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
271 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
272 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
273 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
274 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
275 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
276 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
277 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
278 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
280 #define EV_BUTTON
(e
) \
281 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
282 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
283 [e buttonNumber
] - 1)
285 /* Convert the time field to a timestamp in milliseconds. */
286 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
288 /* This is a piece of code which is common to all the event handling
289 methods. Maybe it should even be a function. */
290 #define EV_TRAILER
(e
) \
292 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
293 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
296 n_emacs_events_pending
++; \
297 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
300 hold_event
(emacs_event
); \
301 EVENT_INIT
(*emacs_event
); \
302 ns_send_appdefined
(-1); \
305 void x_set_cursor_type
(struct frame
*, Lisp_Object
, Lisp_Object
);
307 /* TODO: get rid of need for these forward declarations */
308 static void ns_condemn_scroll_bars
(struct frame
*f
);
309 static void ns_judge_scroll_bars
(struct frame
*f
);
310 void x_set_frame_alpha
(struct frame
*f
);
313 /* ==========================================================================
317 ========================================================================== */
320 hold_event
(struct input_event
*event
)
322 if (hold_event_q.nr
== hold_event_q.cap
)
324 if (hold_event_q.cap
== 0) hold_event_q.cap
= 10;
325 else hold_event_q.cap
*= 2;
326 hold_event_q.q
= (struct input_event
*)
327 xrealloc
(hold_event_q.q
, hold_event_q.cap
* sizeof
(*hold_event_q.q
));
330 hold_event_q.q
[hold_event_q.nr
++] = *event
;
331 /* Make sure ns_read_socket is called, i.e. we have input. */
333 send_appdefined
= YES
;
337 append2
(Lisp_Object list
, Lisp_Object item
)
338 /* --------------------------------------------------------------------------
339 Utility to append to a list
340 -------------------------------------------------------------------------- */
342 Lisp_Object array
[2];
344 array
[1] = Fcons
(item
, Qnil
);
345 return Fnconc
(2, &array
[0]);
350 ns_etc_directory
(void
)
351 /* If running as a self-contained app bundle, return as a string the
352 filename of the etc directory, if present; else nil. */
354 NSBundle
*bundle
= [NSBundle mainBundle
];
355 NSString
*resourceDir
= [bundle resourcePath
];
356 NSString
*resourcePath
;
357 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
360 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
361 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
363 if (isDir
) return [resourcePath UTF8String
];
371 /* If running as a self-contained app bundle, return as a path string
372 the filenames of the libexec and bin directories, ie libexec:bin.
373 Otherwise, return nil.
374 Normally, Emacs does not add its own bin/ directory to the PATH.
375 However, a self-contained NS build has a different layout, with
376 bin/ and libexec/ subdirectories in the directory that contains
378 We put libexec first, because init_callproc_1 uses the first
379 element to initialize exec-directory. An alternative would be
380 for init_callproc to check for invocation-directory/libexec.
383 NSBundle
*bundle
= [NSBundle mainBundle
];
384 NSString
*resourceDir
= [bundle resourcePath
];
385 NSString
*binDir
= [bundle bundlePath
];
386 NSString
*resourcePath
, *resourcePaths
;
388 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
389 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
391 NSEnumerator
*pathEnum
;
394 range
= [resourceDir rangeOfString
: @"Contents"
];
395 if (range.location
!= NSNotFound
)
397 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
399 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
403 paths
= [binDir stringsByAppendingPaths
:
404 [NSArray arrayWithObjects
: @"libexec"
, @"bin"
, nil
]];
405 pathEnum
= [paths objectEnumerator
];
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
];
428 /* If running as a self-contained app bundle, return as a path string
429 the filenames of the site-lisp, lisp and leim directories.
430 Ie, site-lisp:lisp:leim. Otherwise, return nil. */
432 NSBundle
*bundle
= [NSBundle mainBundle
];
433 NSString
*resourceDir
= [bundle resourcePath
];
434 NSString
*resourcePath
, *resourcePaths
;
435 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
436 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
438 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
439 [NSArray arrayWithObjects
:
440 @"site
-lisp"
, @"lisp"
, @"leim"
, nil
]];
441 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
444 /* Hack to skip site-lisp. */
445 if (no_site_lisp
) resourcePath
= [pathEnum nextObject
];
447 while ((resourcePath
= [pathEnum nextObject
]))
449 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
452 if ([resourcePaths
length] > 0)
454 = [resourcePaths stringByAppendingString
: pathSeparator
];
456 = [resourcePaths stringByAppendingString
: resourcePath
];
459 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
465 ns_timeout
(int usecs
)
466 /* --------------------------------------------------------------------------
467 Blocking timer utility used by ns_ring_bell
468 -------------------------------------------------------------------------- */
470 EMACS_TIME wakeup
= add_emacs_time
(current_emacs_time
(),
471 make_emacs_time
(0, usecs
* 1000));
473 /* Keep waiting until past the time wakeup. */
476 EMACS_TIME timeout
, now
= current_emacs_time
();
477 if (EMACS_TIME_LE
(wakeup
, now
))
479 timeout
= sub_emacs_time
(wakeup
, now
);
481 /* Try to wait that long--but we might wake up sooner. */
482 pselect
(0, NULL, NULL, NULL, &timeout
, NULL);
488 ns_release_object
(void
*obj
)
489 /* --------------------------------------------------------------------------
490 Release an object (callable from C)
491 -------------------------------------------------------------------------- */
498 ns_retain_object
(void
*obj
)
499 /* --------------------------------------------------------------------------
500 Retain an object (callable from C)
501 -------------------------------------------------------------------------- */
508 ns_alloc_autorelease_pool
(void
)
509 /* --------------------------------------------------------------------------
510 Allocate a pool for temporary objects (callable from C)
511 -------------------------------------------------------------------------- */
513 return [[NSAutoreleasePool alloc
] init
];
518 ns_release_autorelease_pool
(void
*pool
)
519 /* --------------------------------------------------------------------------
520 Free a pool and temporary objects it refers to (callable from C)
521 -------------------------------------------------------------------------- */
523 ns_release_object
(pool
);
528 /* ==========================================================================
530 Focus (clipping) and screen update
532 ========================================================================== */
535 // Window constraining
536 // -------------------
538 // To ensure that the windows are not placed under the
menu bar, they
539 // are typically moved by the call
-back constrainFrameRect. However
,
540 // by overriding it
, it
's possible to inhibit this, leaving the window
541 // in it's original position.
543 // It
's possible to hide the menu bar. However, technically, it's only
544 // possible to hide it when the application is active. To ensure that
545 // this work properly
, the
menu bar and window constraining are
546 // deferred until the application becomes active.
548 // Even though it
's not possible to manually move a window above the
549 // top of the screen, it is allowed if it's done programmatically
,
550 // when the
menu is
hidden. This allows the editable area to cover the
551 // full screen height.
556 // Use the following extra files
:
559 // ;; Hide
menu and place frame slightly above the top of the screen.
560 // (setq ns
-auto
-hide
-menu-bar t
)
561 // (set-frame
-position
(selected
-frame
) 0 -20)
565 // emacs
-Q
-l init.el
567 // Result
: No
menu bar, and the
title bar should be above the screen.
573 // Result
: Menu bar visible
, frame placed immediately below the
menu.
577 ns_constrain_all_frames
(void
)
579 Lisp_Object tail
, frame
;
581 FOR_EACH_FRAME
(tail
, frame
)
583 struct frame
*f
= XFRAME
(frame
);
586 NSView
*view = FRAME_NS_VIEW
(f
);
587 /* This no-op will trigger the default window placing
588 * constraint system. */
589 f
->output_data.ns
->dont_constrain
= 0;
590 [[view window
] setFrameOrigin
:[[view window
] frame
].origin
];
596 /* True, if the menu bar should be hidden. */
599 ns_menu_bar_should_be_hidden
(void
)
601 return !NILP
(ns_auto_hide_menu_bar
)
602 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)];
606 /* Show or hide the menu bar, based on user setting. */
609 ns_update_auto_hide_menu_bar
(void
)
612 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
615 NSTRACE
(ns_update_auto_hide_menu_bar
);
619 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)])
621 // Note
, "setPresentationOptions" triggers an
error unless the
622 // application is active.
623 BOOL menu_bar_should_be_hidden
= ns_menu_bar_should_be_hidden
();
625 if (menu_bar_should_be_hidden
!= ns_menu_bar_is_hidden
)
627 NSApplicationPresentationOptions options
628 = NSApplicationPresentationAutoHideDock
;
630 if (menu_bar_should_be_hidden
)
631 options |
= NSApplicationPresentationAutoHideMenuBar
;
633 [NSApp setPresentationOptions
: options
];
635 ns_menu_bar_is_hidden
= menu_bar_should_be_hidden
;
637 if (!ns_menu_bar_is_hidden
)
639 ns_constrain_all_frames
();
651 ns_update_begin
(struct frame
*f
)
652 /* --------------------------------------------------------------------------
653 Prepare for a grouped sequence of drawing calls
654 external (RIF) call; whole frame, called before update_window_begin
655 -------------------------------------------------------------------------- */
657 NSView
*view = FRAME_NS_VIEW
(f
);
658 NSRect r
= [view frame
];
660 NSTRACE
(ns_update_begin
);
662 ns_update_auto_hide_menu_bar
();
664 ns_updating_frame
= f
;
667 /* drawRect may have been called for say the minibuffer, and then clip path
668 is for the minibuffer. But the display engine may draw more because
669 we have set the frame as garbaged. So reset clip path to the whole
671 bp
= [[NSBezierPath bezierPathWithRect
: r
] retain
];
675 #ifdef NS_IMPL_GNUSTEP
676 uRect
= NSMakeRect
(0, 0, 0, 0);
682 ns_update_window_begin
(struct window
*w
)
683 /* --------------------------------------------------------------------------
684 Prepare for a grouped sequence of drawing calls
685 external (RIF) call; for one window, called after update_begin
686 -------------------------------------------------------------------------- */
688 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
689 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
690 NSTRACE
(ns_update_window_begin
);
692 set_output_cursor
(&w
->cursor
);
696 if (f
== hlinfo
->mouse_face_mouse_frame
)
698 /* Don't do highlighting for mouse motion during the update. */
699 hlinfo
->mouse_face_defer
= 1;
701 /* If the frame needs to be redrawn,
702 simply forget about any prior mouse highlighting. */
703 if (FRAME_GARBAGED_P
(f
))
704 hlinfo
->mouse_face_window
= Qnil
;
706 /* (further code for mouse faces ifdef'd out in other terms elided) */
714 ns_update_window_end
(struct window
*w
, int cursor_on_p
,
715 int mouse_face_overwritten_p
)
716 /* --------------------------------------------------------------------------
717 Finished a grouped sequence of drawing calls
718 external (RIF) call; for one window called before update_end
719 -------------------------------------------------------------------------- */
721 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(XFRAME
(w
->frame
));
723 /* note: this fn is nearly identical in all terms */
724 if (!w
->pseudo_window_p
)
729 display_and_set_cursor
(w
, 1,
730 output_cursor.hpos
, output_cursor.vpos
,
731 output_cursor.x
, output_cursor.y
);
733 if (draw_window_fringes
(w
, 1))
734 x_draw_vertical_border
(w
);
739 /* If a row with mouse-face was overwritten, arrange for
740 frame_up_to_date to redisplay the mouse highlight. */
741 if (mouse_face_overwritten_p
)
743 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
744 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
745 hlinfo
->mouse_face_window
= Qnil
;
748 updated_window
= NULL;
749 NSTRACE
(update_window_end
);
754 ns_update_end
(struct frame
*f
)
755 /* --------------------------------------------------------------------------
756 Finished a grouped sequence of drawing calls
757 external (RIF) call; for whole frame, called after update_window_end
758 -------------------------------------------------------------------------- */
760 NSView
*view = FRAME_NS_VIEW
(f
);
762 /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
763 MOUSE_HL_INFO
(f
)->mouse_face_defer
= 0;
767 #ifdef NS_IMPL_GNUSTEP
768 /* trigger flush only in the rectangle we tracked as being drawn */
769 [view unlockFocusNeedsFlush
: NO
];
770 /*fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", uRect.origin.x, uRect.origin.y, uRect.size.width, uRect.size.height); */
771 [view lockFocusInRect
: uRect
];
775 [[view window
] flushWindow
];
778 ns_updating_frame
= NULL;
779 NSTRACE
(ns_update_end
);
784 ns_flush
(struct frame
*f
)
785 /* --------------------------------------------------------------------------
787 NS impl is no-op since currently we flush in ns_update_end and elsewhere
788 -------------------------------------------------------------------------- */
795 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
796 /* --------------------------------------------------------------------------
797 Internal: Focus on given frame. During small local updates this is used to
798 draw, however during large updates, ns_update_begin and ns_update_end are
799 called to wrap the whole thing, in which case these calls are stubbed out.
800 Except, on GNUstep, we accumulate the rectangle being drawn into, because
801 the back end won't do this automatically, and will just end up flushing
803 -------------------------------------------------------------------------- */
805 // NSTRACE
(ns_focus
);
806 #ifdef NS_IMPL_GNUSTEP
809 u
= NSUnionRect
(r
[0], r
[1]);
814 fprintf (stderr, "focus: %d", c++);
815 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
816 fprintf (stderr, "\n"); */
818 if (f
!= ns_updating_frame
)
820 NSView
*view = FRAME_NS_VIEW
(f
);
821 if (view != focus_view
)
823 if (focus_view
!= NULL)
825 [focus_view unlockFocus
];
826 [[focus_view window
] flushWindow
];
831 #ifdef NS_IMPL_GNUSTEP
832 r ?
[view lockFocusInRect
: u
] : [view lockFocus
];
837 /*if (view) debug_lock++; */
839 #ifdef NS_IMPL_GNUSTEP
842 /* more than one rect being drawn into */
845 [view unlockFocus
]; /* add prev rect to redraw list */
846 [view lockFocusInRect
: u
]; /* focus for draw in new rect */
851 #ifdef NS_IMPL_GNUSTEP
854 /* in batch mode, but in GNUstep must still track rectangles explicitly */
855 uRect
= (r ? NSUnionRect
(uRect
, u
) : [FRAME_NS_VIEW
(f
) visibleRect
]);
862 [[NSGraphicsContext currentContext
] saveGraphicsState
];
864 NSRectClipList
(r
, 2);
873 ns_unfocus
(struct frame
*f
)
874 /* --------------------------------------------------------------------------
875 Internal: Remove focus on given frame
876 -------------------------------------------------------------------------- */
878 // NSTRACE
(ns_unfocus
);
882 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
886 if (f
!= ns_updating_frame
)
888 if (focus_view
!= NULL)
890 [focus_view unlockFocus
];
891 [[focus_view window
] flushWindow
];
900 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
, int area
, BOOL gc
)
901 /* --------------------------------------------------------------------------
902 Internal (but parallels other terms): Focus drawing on given row
903 -------------------------------------------------------------------------- */
905 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
907 int window_x
, window_y
, window_width
;
909 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
911 clip_rect.origin.x
= window_x
;
912 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
913 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
914 clip_rect.
size.width
= window_width
;
915 clip_rect.
size.height
= row
->visible_height
;
917 ns_focus
(f
, &clip_rect
, 1);
922 ns_ring_bell
(struct frame
*f
)
923 /* --------------------------------------------------------------------------
925 -------------------------------------------------------------------------- */
927 NSTRACE
(ns_ring_bell
);
930 NSAutoreleasePool
*pool
;
931 struct frame
*frame
= SELECTED_FRAME
();
935 pool
= [[NSAutoreleasePool alloc
] init
];
937 view = FRAME_NS_VIEW
(frame
);
941 NSPoint dim
= NSMakePoint
(128, 128);
944 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
945 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
946 r.
size.width
= dim.x
;
947 r.
size.height
= dim.y
;
948 surr
= NSInsetRect
(r
, -2, -2);
949 ns_focus
(frame
, &surr
, 1);
950 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
951 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
952 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
954 [[view window
] flushWindow
];
956 [[view window
] restoreCachedImage
];
957 [[view window
] flushWindow
];
971 ns_reset_terminal_modes
(struct terminal *terminal)
972 /* Externally called as hook */
974 NSTRACE
(ns_reset_terminal_modes
);
979 ns_set_terminal_modes
(struct terminal *terminal)
980 /* Externally called as hook */
982 NSTRACE
(ns_set_terminal_modes
);
987 /* ==========================================================================
989 Frame / window manager related functions
991 ========================================================================== */
995 ns_raise_frame
(struct frame
*f
)
996 /* --------------------------------------------------------------------------
997 Bring window to foreground and make it active
998 -------------------------------------------------------------------------- */
1000 NSView
*view = FRAME_NS_VIEW
(f
);
1003 FRAME_SAMPLE_VISIBILITY
(f
);
1004 if (FRAME_VISIBLE_P
(f
))
1006 [[view window
] makeKeyAndOrderFront
: NSApp
];
1013 ns_lower_frame
(struct frame
*f
)
1014 /* --------------------------------------------------------------------------
1016 -------------------------------------------------------------------------- */
1018 NSView
*view = FRAME_NS_VIEW
(f
);
1021 [[view window
] orderBack
: NSApp
];
1027 ns_frame_raise_lower
(struct frame
*f
, int raise
)
1028 /* --------------------------------------------------------------------------
1030 -------------------------------------------------------------------------- */
1032 NSTRACE
(ns_frame_raise_lower
);
1042 ns_frame_rehighlight
(struct frame
*frame
)
1043 /* --------------------------------------------------------------------------
1044 External (hook): called on things like window switching within frame
1045 -------------------------------------------------------------------------- */
1047 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(frame
);
1048 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1050 NSTRACE
(ns_frame_rehighlight
);
1051 if (dpyinfo
->x_focus_frame
)
1053 dpyinfo
->x_highlight_frame
1054 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1055 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1056 : dpyinfo
->x_focus_frame
);
1057 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
1059 fset_focus_frame
(dpyinfo
->x_focus_frame
, Qnil
);
1060 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1064 dpyinfo
->x_highlight_frame
= 0;
1066 if (dpyinfo
->x_highlight_frame
&&
1067 dpyinfo
->x_highlight_frame
!= old_highlight
)
1071 x_update_cursor
(old_highlight
, 1);
1072 x_set_frame_alpha
(old_highlight
);
1074 if (dpyinfo
->x_highlight_frame
)
1076 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
1077 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
1084 x_make_frame_visible
(struct frame
*f
)
1085 /* --------------------------------------------------------------------------
1086 External: Show the window (X11 semantics)
1087 -------------------------------------------------------------------------- */
1089 NSTRACE
(x_make_frame_visible
);
1090 /* XXX: at some points in past this was not needed, as the only place that
1091 called this (frame.c:Fraise_frame ()) also called raise_lower;
1092 if this ends up the case again, comment this out again. */
1093 if (!FRAME_VISIBLE_P
(f
))
1095 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(f
);
1096 f
->async_visible
= 1;
1100 /* Making a new frame from a fullscreen frame will make the new frame
1101 fullscreen also. So skip handleFS as this will print an error. */
1102 if (f
->want_fullscreen
== FULLSCREEN_BOTH
1103 && ([[view window
] styleMask
] & NSFullScreenWindowMask
) != 0)
1106 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
1117 x_make_frame_invisible
(struct frame
*f
)
1118 /* --------------------------------------------------------------------------
1119 External: Hide the window (X11 semantics)
1120 -------------------------------------------------------------------------- */
1122 NSView
* view = FRAME_NS_VIEW
(f
);
1123 NSTRACE
(x_make_frame_invisible
);
1125 [[view window
] orderOut
: NSApp
];
1126 f
->async_visible
= 0;
1127 f
->async_iconified
= 0;
1132 x_iconify_frame
(struct frame
*f
)
1133 /* --------------------------------------------------------------------------
1134 External: Iconify window
1135 -------------------------------------------------------------------------- */
1137 NSView
* view = FRAME_NS_VIEW
(f
);
1138 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1139 NSTRACE
(x_iconify_frame
);
1142 if (dpyinfo
->x_highlight_frame
== f
)
1143 dpyinfo
->x_highlight_frame
= 0;
1145 if ([[view window
] windowNumber
] <= 0)
1147 /* the window is still deferred. Make it very small, bring it
1148 on screen and order it out. */
1149 NSRect s
= { { 100, 100}, {0, 0} };
1151 t
= [[view window
] frame
];
1152 [[view window
] setFrame
: s display
: NO
];
1153 [[view window
] orderBack
: NSApp
];
1154 [[view window
] orderOut
: NSApp
];
1155 [[view window
] setFrame
: t display
: NO
];
1157 [[view window
] miniaturize
: NSApp
];
1160 /* Free X resources of frame F. */
1163 x_free_frame_resources
(struct frame
*f
)
1165 NSView
*view = FRAME_NS_VIEW
(f
);
1166 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1167 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1168 NSTRACE
(x_free_frame_resources
);
1171 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1175 free_frame_menubar
(f
);
1177 if (FRAME_FACE_CACHE
(f
))
1178 free_frame_faces
(f
);
1180 if (f
== dpyinfo
->x_focus_frame
)
1181 dpyinfo
->x_focus_frame
= 0;
1182 if (f
== dpyinfo
->x_highlight_frame
)
1183 dpyinfo
->x_highlight_frame
= 0;
1184 if (f
== hlinfo
->mouse_face_mouse_frame
)
1186 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1187 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1188 hlinfo
->mouse_face_window
= Qnil
;
1189 hlinfo
->mouse_face_deferred_gc
= 0;
1190 hlinfo
->mouse_face_mouse_frame
= 0;
1193 if (f
->output_data.ns
->miniimage
!= nil
)
1194 [f
->output_data.ns
->miniimage release
];
1196 [[view window
] close];
1199 xfree
(f
->output_data.ns
);
1205 x_destroy_window
(struct frame
*f
)
1206 /* --------------------------------------------------------------------------
1207 External: Delete the window
1208 -------------------------------------------------------------------------- */
1210 NSTRACE
(x_destroy_window
);
1212 x_free_frame_resources
(f
);
1218 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1219 /* --------------------------------------------------------------------------
1220 External: Position the window
1221 -------------------------------------------------------------------------- */
1223 NSView
*view = FRAME_NS_VIEW
(f
);
1224 NSArray
*screens
= [NSScreen screens
];
1225 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1226 NSScreen
*screen
= [[view window
] screen
];
1228 NSTRACE
(x_set_offset
);
1235 if (view != nil
&& screen
&& fscreen
)
1237 f
->left_pos
= f
->size_hint_flags
& XNegative
1238 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1240 /* We use visibleFrame here to take menu bar into account.
1241 Ideally we should also adjust left/top with visibleFrame.origin. */
1243 f
->top_pos
= f
->size_hint_flags
& YNegative
1244 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1245 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1246 - FRAME_TOOLBAR_HEIGHT
(f
))
1248 #ifdef NS_IMPL_GNUSTEP
1249 if (f
->left_pos
< 100)
1250 f
->left_pos
= 100; /* don't overlap menu */
1252 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1254 f
->output_data.ns
->dont_constrain
= 0;
1255 [[view window
] setFrameTopLeftPoint
:
1256 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1257 SCREENMAXBOUND
([fscreen frame
].
size.height
1258 - NS_TOP_POS
(f
)))];
1259 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1267 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1268 /* --------------------------------------------------------------------------
1269 Adjust window pixel size based on given character grid size
1270 Impl is a bit more complex than other terms, need to do some
1272 -------------------------------------------------------------------------- */
1274 EmacsView
*view = FRAME_NS_VIEW
(f
);
1275 NSWindow
*window
= [view window
];
1276 NSRect wr
= [window frame
];
1277 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1278 int pixelwidth
, pixelheight
;
1280 NSTRACE
(x_set_window_size
);
1285 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1289 check_frame_size
(f
, &rows
, &cols
);
1291 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1292 compute_fringe_widths
(f
, 0);
1294 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1295 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1297 /* If we have a toolbar, take its height into account. */
1299 /* NOTE: previously this would generate wrong result if toolbar not
1300 yet displayed and fixing toolbar_height=32 helped, but
1301 now (200903) seems no longer needed */
1302 FRAME_TOOLBAR_HEIGHT
(f
) =
1303 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1304 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1306 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1308 wr.
size.width
= pixelwidth
+ f
->border_width
;
1309 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1310 + FRAME_TOOLBAR_HEIGHT
(f
);
1312 /* Do not try to constrain to this screen. We may have multiple
1313 screens, and want Emacs to span those. Constraining to screen
1314 prevents that, and that is not nice to the user. */
1315 if (f
->output_data.ns
->zooming
)
1316 f
->output_data.ns
->zooming
= 0;
1318 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1320 [view setRows
: rows andColumns
: cols
];
1321 [window setFrame
: wr display
: YES
];
1323 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1325 /* This is a trick to compensate for Emacs' managing the scrollbar area
1326 as a fixed number of standard character columns. Instead of leaving
1327 blank space for the extra, we chopped it off above. Now for
1328 left-hand scrollbars, we shift all rendering to the left by the
1329 difference between the real width and Emacs' imagined one. For
1330 right-hand bars, don't worry about it since the extra is never used.
1331 (Obviously doesn't work for vertically split windows tho..) */
1333 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1334 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1335 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1336 : NSMakePoint
(0, 0);
1337 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1338 [view setBoundsOrigin
: origin
];
1341 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1342 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1343 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1344 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1346 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1347 cancel_mouse_face
(f
);
1354 ns_fullscreen_hook
(FRAME_PTR f
)
1356 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(f
);
1358 if (! f
->async_visible
) return;
1359 #ifndef NEW_STYLE_FS
1360 if (f
->want_fullscreen
== FULLSCREEN_BOTH
)
1362 /* Old style fs don't initiate correctly if created from
1363 init/default-frame alist, so use a timer (not nice...).
1365 [NSTimer scheduledTimerWithTimeInterval
: 0.5 target
: view
1366 selector
: @selector
(handleFS
)
1367 userInfo
: nil repeats
: NO
];
1377 /* ==========================================================================
1381 ========================================================================== */
1385 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1387 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1388 if (idx
< 1 || idx
>= color_table
->avail
)
1390 return color_table
->colors
[idx
];
1395 ns_index_color
(NSColor
*color
, struct frame
*f
)
1397 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1401 if (!color_table
->colors
)
1403 color_table
->size = NS_COLOR_CAPACITY
;
1404 color_table
->avail
= 1; /* skip idx=0 as marker */
1405 color_table
->colors
= xmalloc
(color_table
->size * sizeof
(NSColor
*));
1406 color_table
->colors
[0] = nil
;
1407 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1410 /* do we already have this color ? */
1411 for (i
= 1; i
< color_table
->avail
; i
++)
1412 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1415 if ([color_table
->empty_indices count
] > 0)
1417 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1418 [color_table
->empty_indices removeObject
: index
];
1419 idx
= [index unsignedLongValue
];
1423 if (color_table
->avail
== color_table
->size)
1424 color_table
->colors
=
1425 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1426 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1427 idx
= color_table
->avail
++;
1430 color_table
->colors
[idx
] = color
;
1432 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1438 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1440 struct ns_color_table
*color_table
;
1447 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1449 if (idx
<= 0 || idx
>= color_table
->size) {
1450 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1454 index
= [NSNumber numberWithUnsignedInt
: idx
];
1455 if ([color_table
->empty_indices containsObject
: index
]) {
1456 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1460 color
= color_table
->colors
[idx
];
1462 color_table
->colors
[idx
] = nil
;
1463 [color_table
->empty_indices addObject
: index
];
1464 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1469 ns_get_color
(const
char *name
, NSColor
**col
)
1470 /* --------------------------------------------------------------------------
1472 -------------------------------------------------------------------------- */
1473 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1474 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1475 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1478 static
char hex
[20];
1480 float r
= -1.0, g
, b
;
1481 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1483 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1486 if ([nsname isEqualToString
: @"ns_selection_color"
])
1488 nsname
= ns_selection_color
;
1489 name
= [ns_selection_color UTF8String
];
1492 /* First, check for some sort of numeric specification. */
1495 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1497 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1498 [scanner scanFloat
: &r
];
1499 [scanner scanFloat
: &g
];
1500 [scanner scanFloat
: &b
];
1502 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1503 scaling
= (snprintf
(hex
, sizeof hex
, "
%s", name + 4) - 2) / 3;
1504 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1506 int len
= (strlen
(name
) - 1);
1507 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1509 scaling
= strlen
(name
+start
) / 3;
1510 for (i
= 0; i
< 3; i
++)
1511 sprintf (hex
+ i
* (scaling
+ 1), "
%.*s/", scaling,
1512 name
+ start
+ i
* scaling
);
1513 hex
[3 * (scaling
+ 1) - 1] = '\0';
1519 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1520 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1530 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1535 /* Otherwise, color is expected to be from a list */
1537 NSEnumerator
*lenum
, *cenum
;
1541 #ifdef NS_IMPL_GNUSTEP
1542 /* XXX: who is wrong, the requestor or the implementation? */
1543 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1545 nsname
= @"highlightColor"
;
1548 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1549 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1551 cenum
= [[clist allKeys
] objectEnumerator
];
1552 while ( (name
= [cenum nextObject
]) && new
== nil
)
1554 if ([name compare
: nsname
1555 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1556 new
= [clist colorWithKey
: name
];
1562 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1569 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1570 /* --------------------------------------------------------------------------
1571 Convert a Lisp string object to a NS color
1572 -------------------------------------------------------------------------- */
1574 NSTRACE
(ns_lisp_to_color
);
1575 if (STRINGP
(color
))
1576 return ns_get_color
(SSDATA
(color
), col
);
1577 else if (SYMBOLP
(color
))
1578 return ns_get_color
(SSDATA
(SYMBOL_NAME
(color
)), col
);
1584 ns_color_to_lisp
(NSColor
*col
)
1585 /* --------------------------------------------------------------------------
1586 Convert a color to a lisp string with the RGB equivalent
1587 -------------------------------------------------------------------------- */
1589 CGFloat red
, green
, blue
, alpha
, gray;
1592 NSTRACE
(ns_color_to_lisp
);
1595 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1597 if ((str
=[[col colorNameComponent
] UTF8String
]))
1600 return build_string
((char *)str
);
1603 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1604 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1605 if (red
==green
&& red
==blue
)
1607 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1608 getWhite
: &gray alpha
: &alpha
];
1609 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1610 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1612 return build_string
(buf
);
1615 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1616 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1619 return build_string
(buf
);
1624 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1625 /* --------------------------------------------------------------------------
1626 Get ARGB values out of NSColor col and put them into color_def.
1627 If setPixel, set the pixel to a concatenated version.
1628 and set color_def pixel to the resulting index.
1629 -------------------------------------------------------------------------- */
1633 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1634 color_def
->red
= r
* 65535;
1635 color_def
->green
= g
* 65535;
1636 color_def
->blue
= b
* 65535;
1638 if (setPixel
== YES
)
1640 = ARGB_TO_ULONG
((int
)(a
*255),
1641 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1646 ns_defined_color
(struct frame
*f
,
1651 /* --------------------------------------------------------------------------
1652 Return true if named color found, and set color_def rgb accordingly.
1653 If makeIndex and alloc are nonzero put the color in the color_table,
1654 and set color_def pixel to the resulting index.
1655 If makeIndex is zero, set color_def pixel to ARGB.
1656 Return false if not found
1657 -------------------------------------------------------------------------- */
1660 NSTRACE
(ns_defined_color
);
1663 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1668 if (makeIndex
&& alloc
)
1669 color_def
->pixel
= ns_index_color
(col
, f
);
1670 ns_query_color
(col
, color_def
, !makeIndex
);
1677 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1678 /* --------------------------------------------------------------------------
1679 return an autoreleased RGB color
1680 -------------------------------------------------------------------------- */
1682 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1683 if (r
< 0.0) r
= 0.0;
1684 else if (r
> 1.0) r
= 1.0;
1685 if (g
< 0.0) g
= 0.0;
1686 else if (g
> 1.0) g
= 1.0;
1687 if (b
< 0.0) b
= 0.0;
1688 else if (b
> 1.0) b
= 1.0;
1689 if (a
< 0.0) a
= 0.0;
1690 else if (a
> 1.0) a
= 1.0;
1691 return (unsigned
long) ns_index_color
(
1692 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1697 x_set_frame_alpha
(struct frame
*f
)
1698 /* --------------------------------------------------------------------------
1699 change the entire-frame transparency
1700 -------------------------------------------------------------------------- */
1702 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1703 EmacsView
*view = FRAME_NS_VIEW
(f
);
1705 double alpha_min
= 1.0;
1707 if (dpyinfo
->x_highlight_frame
== f
)
1708 alpha
= f
->alpha
[0];
1710 alpha
= f
->alpha
[1];
1712 if (FLOATP
(Vframe_alpha_lower_limit
))
1713 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1714 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1715 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1719 else if (1.0 < alpha
)
1721 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1724 #ifdef NS_IMPL_COCOA
1725 [[view window
] setAlphaValue
: alpha
];
1730 /* ==========================================================================
1734 ========================================================================== */
1738 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1739 /* --------------------------------------------------------------------------
1740 Programmatically reposition mouse pointer in pixel coordinates
1741 -------------------------------------------------------------------------- */
1743 NSTRACE
(x_set_mouse_pixel_position
);
1746 /* FIXME: this does not work, and what about GNUstep? */
1747 #ifdef NS_IMPL_COCOA
1748 [FRAME_NS_VIEW
(f
) lockFocus
];
1749 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1750 [FRAME_NS_VIEW
(f
) unlockFocus
];
1757 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1758 /* --------------------------------------------------------------------------
1759 Programmatically reposition mouse pointer in character coordinates
1760 -------------------------------------------------------------------------- */
1764 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1765 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1767 if (pix_x
< 0) pix_x
= 0;
1768 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1770 if (pix_y
< 0) pix_y
= 0;
1771 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1773 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1778 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1779 /* ------------------------------------------------------------------------
1780 Called by EmacsView on mouseMovement events. Passes on
1781 to emacs mainstream code if we moved off of a rect of interest
1782 known as last_mouse_glyph.
1783 ------------------------------------------------------------------------ */
1785 // NSTRACE
(note_mouse_movement
);
1787 XSETFRAME
(last_mouse_motion_frame
, frame
);
1789 /* Note, this doesn't get called for enter/leave, since we don't have a
1790 position. Those are taken care of in the corresponding NSView methods. */
1792 /* has movement gone beyond last rect we were tracking? */
1793 if (x
< last_mouse_glyph.origin.x ||
1794 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1795 y
< last_mouse_glyph.origin.y ||
1796 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1798 ns_update_begin
(frame
);
1799 frame
->mouse_moved
= 1;
1800 note_mouse_highlight
(frame
, x
, y
);
1801 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1802 ns_update_end
(frame
);
1811 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1812 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1814 /* --------------------------------------------------------------------------
1815 External (hook): inform emacs about mouse position and hit parts.
1816 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1817 x & y should be position in the scrollbar (the whole bar, not the handle)
1818 and length of scrollbar respectively
1819 -------------------------------------------------------------------------- */
1823 Lisp_Object frame
, tail
;
1825 struct ns_display_info
*dpyinfo
;
1827 NSTRACE
(ns_mouse_position
);
1831 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1835 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1839 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1841 /* TODO: we do not use this path at the moment because drag events will
1842 go directly to the EmacsScroller. Leaving code in for now. */
1843 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1845 if (time
) *time
= last_mouse_movement_time
;
1846 last_mouse_scroll_bar
= nil
;
1850 /* Clear the mouse-moved flag for every frame on this display. */
1851 FOR_EACH_FRAME
(tail
, frame
)
1852 if (FRAME_NS_P
(XFRAME
(frame
))
1853 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1854 XFRAME
(frame
)->mouse_moved
= 0;
1856 last_mouse_scroll_bar
= nil
;
1857 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1858 f
= last_mouse_frame
;
1860 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1861 : SELECTED_FRAME
();
1863 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1865 view = FRAME_NS_VIEW
(*fp
);
1867 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1868 position
= [view convertPoint
: position fromView
: nil
];
1869 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1870 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1872 if (bar_window
) *bar_window
= Qnil
;
1873 if (part
) *part
= 0; /*scroll_bar_handle; */
1875 if (x
) XSETINT
(*x
, lrint
(position.x
));
1876 if (y
) XSETINT
(*y
, lrint
(position.y
));
1877 if (time
) *time
= last_mouse_movement_time
;
1887 ns_frame_up_to_date
(struct frame
*f
)
1888 /* --------------------------------------------------------------------------
1889 External (hook): Fix up mouse highlighting right after a full update.
1890 Some highlighting was deferred if GC was happening during
1891 note_mouse_highlight (), while other highlighting was deferred for update.
1892 -------------------------------------------------------------------------- */
1894 NSTRACE
(ns_frame_up_to_date
);
1898 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1899 if ((hlinfo
->mouse_face_deferred_gc || f
==hlinfo
->mouse_face_mouse_frame
)
1900 /*&& hlinfo->mouse_face_mouse_frame*/)
1904 if (hlinfo
->mouse_face_mouse_frame
)
1905 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1906 hlinfo
->mouse_face_mouse_x
,
1907 hlinfo
->mouse_face_mouse_y
);
1908 hlinfo
->mouse_face_deferred_gc
= 0;
1917 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1918 /* --------------------------------------------------------------------------
1919 External (RIF): set frame mouse pointer type.
1920 -------------------------------------------------------------------------- */
1922 NSTRACE
(ns_define_frame_cursor
);
1923 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1925 EmacsView
*view = FRAME_NS_VIEW
(f
);
1926 FRAME_POINTER_TYPE
(f
) = cursor
;
1927 [[view window
] invalidateCursorRectsForView
: view];
1928 /* Redisplay assumes this function also draws the changed frame
1929 cursor, but this function doesn't, so do it explicitly. */
1930 x_update_cursor
(f
, 1);
1936 /* ==========================================================================
1940 ========================================================================== */
1944 ns_convert_key
(unsigned code
)
1945 /* --------------------------------------------------------------------------
1946 Internal call used by NSView-keyDown.
1947 -------------------------------------------------------------------------- */
1949 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1950 / sizeof
(convert_ns_to_X_keysym
[0]));
1952 /* An array would be faster, but less easy to read. */
1953 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1954 if (code
== convert_ns_to_X_keysym
[keysym
])
1955 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1957 /* if decide to use keyCode and Carbon table, use this line:
1958 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1963 x_get_keysym_name
(int keysym
)
1964 /* --------------------------------------------------------------------------
1965 Called by keyboard.c. Not sure if the return val is important, except
1967 -------------------------------------------------------------------------- */
1969 static
char value
[16];
1970 NSTRACE
(x_get_keysym_name
);
1971 sprintf (value
, "
%d", keysym);
1977 /* ==========================================================================
1979 Block drawing operations
1981 ========================================================================== */
1985 ns_redraw_scroll_bars
(struct frame
*f
)
1989 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1990 NSTRACE
(ns_redraw_scroll_bars
);
1991 for (i
=[subviews count
]-1; i
>= 0; i
--)
1993 view = [subviews objectAtIndex
: i
];
1994 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
2001 ns_clear_frame
(struct frame
*f
)
2002 /* --------------------------------------------------------------------------
2003 External (hook): Erase the entire frame
2004 -------------------------------------------------------------------------- */
2006 NSView
*view = FRAME_NS_VIEW
(f
);
2009 NSTRACE
(ns_clear_frame
);
2011 /* comes on initial frame because we have
2012 after-make-frame-functions = select-frame */
2013 if (!FRAME_DEFAULT_FACE
(f
))
2016 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
2018 output_cursor.hpos
= output_cursor.vpos
= 0;
2019 output_cursor.x
= -1;
2024 ns_focus
(f
, &r
, 1);
2025 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
2029 /* as of 2006/11 or so this is now needed */
2030 ns_redraw_scroll_bars
(f
);
2036 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
2037 /* --------------------------------------------------------------------------
2038 External (RIF): Clear section of frame
2039 -------------------------------------------------------------------------- */
2041 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
2042 NSView
*view = FRAME_NS_VIEW
(f
);
2043 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
2048 NSTRACE
(ns_clear_frame_area
);
2050 r
= NSIntersectionRect
(r
, [view frame
]);
2051 ns_focus
(f
, &r
, 1);
2052 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
2062 ns_scroll_run
(struct window
*w
, struct run
*run
)
2063 /* --------------------------------------------------------------------------
2064 External (RIF): Insert or delete n lines at line vpos
2065 -------------------------------------------------------------------------- */
2067 struct frame
*f
= XFRAME
(w
->frame
);
2068 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2070 NSTRACE
(ns_scroll_run
);
2072 /* begin copy from other terms */
2073 /* Get frame-relative bounding box of the text display area of W,
2074 without mode lines. Include in this box the left and right
2076 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2078 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2079 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2080 bottom_y
= y
+ height
;
2084 /* Scrolling up. Make sure we don't copy part of the mode
2085 line at the bottom. */
2086 if (from_y
+ run
->height
> bottom_y
)
2087 height
= bottom_y
- from_y
;
2089 height
= run
->height
;
2093 /* Scrolling down. Make sure we don't copy over the mode line.
2095 if (to_y
+ run
->height
> bottom_y
)
2096 height
= bottom_y
- to_y
;
2098 height
= run
->height
;
2100 /* end copy from other terms */
2111 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2112 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2113 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2115 ns_focus
(f
, &dstRect
, 1);
2116 NSCopyBits
(0, srcRect
, dstOrigin
);
2125 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2126 /* --------------------------------------------------------------------------
2127 External (RIF): preparatory to fringe update after text was updated
2128 -------------------------------------------------------------------------- */
2130 struct window
*w
= updated_window
;
2134 NSTRACE
(ns_after_update_window_line
);
2136 /* begin copy from other terms */
2139 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2140 desired_row
->redraw_fringe_bitmaps_p
= 1;
2142 /* When a window has disappeared, make sure that no rest of
2143 full-width rows stays visible in the internal border. */
2144 if (windows_or_buffers_changed
2145 && desired_row
->full_width_p
2146 && (f
= XFRAME
(w
->frame
),
2147 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2149 && (height
= desired_row
->visible_height
,
2152 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2155 ns_clear_frame_area
(f
, 0, y
, width
, height
);
2156 ns_clear_frame_area
(f
,
2157 FRAME_PIXEL_WIDTH
(f
) - width
,
2165 ns_shift_glyphs_for_insert
(struct frame
*f
,
2166 int x
, int y
, int width
, int height
,
2168 /* --------------------------------------------------------------------------
2169 External (RIF): copy an area horizontally, don't worry about clearing src
2170 -------------------------------------------------------------------------- */
2172 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2173 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2174 NSPoint dstOrigin
= dstRect.origin
;
2176 NSTRACE
(ns_shift_glyphs_for_insert
);
2178 ns_focus
(f
, &dstRect
, 1);
2179 NSCopyBits
(0, srcRect
, dstOrigin
);
2185 /* ==========================================================================
2187 Character encoding and metrics
2189 ========================================================================== */
2193 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2194 /* --------------------------------------------------------------------------
2195 External (RIF); compute left/right overhang of whole string and set in s
2196 -------------------------------------------------------------------------- */
2198 struct font
*font
= s
->font
;
2202 struct font_metrics metrics
;
2203 unsigned int codes
[2];
2204 codes
[0] = *(s
->char2b
);
2205 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2207 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2208 s
->left_overhang
= -metrics.lbearing
;
2210 = metrics.rbearing
> metrics.width
2211 ? metrics.rbearing
- metrics.width
: 0;
2215 s
->left_overhang
= 0;
2216 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2217 FONT_HEIGHT
(font
) * 0.2 : 0;
2223 /* ==========================================================================
2225 Fringe and cursor drawing
2227 ========================================================================== */
2230 extern int max_used_fringe_bitmap
;
2232 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2233 struct draw_fringe_bitmap_params
*p
)
2234 /* --------------------------------------------------------------------------
2235 External (RIF); fringe-related
2236 -------------------------------------------------------------------------- */
2238 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2239 struct face
*face
= p
->face
;
2241 static EmacsImage
**bimgs
= NULL;
2242 static int nBimgs
= 0;
2244 /* grow bimgs if needed */
2245 if (nBimgs
< max_used_fringe_bitmap
)
2247 bimgs
= xrealloc
(bimgs
, max_used_fringe_bitmap
* sizeof
*bimgs
);
2248 memset
(bimgs
+ nBimgs
, 0,
2249 (max_used_fringe_bitmap
- nBimgs
) * sizeof
*bimgs
);
2250 nBimgs
= max_used_fringe_bitmap
;
2253 /* Must clip because of partially visible lines. */
2254 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2255 ns_clip_to_row
(w
, row
, -1, YES
);
2259 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
2261 /* If the fringe is adjacent to the left (right) scroll bar of a
2262 leftmost (rightmost, respectively) window, then extend its
2263 background to the gap between the fringe and the bar. */
2264 if ((WINDOW_LEFTMOST_P
(w
)
2265 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(w
))
2266 ||
(WINDOW_RIGHTMOST_P
(w
)
2267 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT
(w
)))
2269 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH
(w
);
2273 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X
(w
);
2274 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS
(w
)
2275 * FRAME_COLUMN_WIDTH
(f
));
2279 /* Bitmap fills the fringe. */
2280 if (bar_area_x
+ bar_area_width
== p
->x
)
2281 bx
= bar_area_x
+ sb_width
;
2282 else if (p
->x
+ p
->wd
== bar_area_x
)
2286 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT
(w
);
2288 nx
= bar_area_width
- sb_width
;
2289 by
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (header_line_height
,
2291 ny
= row
->visible_height
;
2296 if (bar_area_x
+ bar_area_width
== bx
)
2298 bx
= bar_area_x
+ sb_width
;
2299 nx
+= bar_area_width
- sb_width
;
2301 else if (bx
+ nx
== bar_area_x
)
2302 nx
+= bar_area_width
- sb_width
;
2307 if (bx
>= 0 && nx
> 0)
2309 NSRect r
= NSMakeRect
(bx
, by
, nx
, ny
);
2311 [ns_lookup_indexed_color
(face
->background
, f
) set];
2318 NSRect r
= NSMakeRect
(p
->x
, p
->y
, p
->wd
, p
->h
);
2319 EmacsImage
*img
= bimgs
[p
->which - 1];
2323 unsigned short
*bits
= p
->bits
+ p
->dh
;
2326 unsigned
char *cbits
= xmalloc
(len
);
2328 for (i
= 0; i
< len
; i
++)
2329 cbits
[i
] = ~
(bits
[i
] & 0xff);
2330 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2332 bimgs
[p
->which - 1] = img
;
2337 /* Since we composite the bitmap instead of just blitting it, we need
2338 to erase the whole background. */
2339 [ns_lookup_indexed_color
(face
->background
, f
) set];
2341 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2342 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
2344 fromRect
: NSZeroRect
2345 operation
: NSCompositeSourceOver
2351 NSPoint pt
= r.origin
;
2353 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2362 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2363 int x
, int y
, int cursor_type
, int cursor_width
,
2364 int on_p
, int active_p
)
2365 /* --------------------------------------------------------------------------
2366 External call (RIF): draw cursor.
2367 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2368 -------------------------------------------------------------------------- */
2371 int fx
, fy
, h
, cursor_height
;
2372 struct frame
*f
= WINDOW_XFRAME
(w
);
2373 struct glyph
*phys_cursor_glyph
;
2375 struct glyph
*cursor_glyph
;
2377 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2379 /* If cursor is out of bounds, don't draw garbage. This can happen
2380 in mini-buffer windows when switching between echo area glyphs
2383 NSTRACE
(dumpcursor
);
2388 w
->phys_cursor_type
= cursor_type
;
2389 w
->phys_cursor_on_p
= on_p
;
2391 if (cursor_type
== NO_CURSOR
)
2393 w
->phys_cursor_width
= 0;
2397 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2399 if (glyph_row
->exact_window_width_line_p
2400 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2402 glyph_row
->cursor_in_fringe_p
= 1;
2403 draw_fringe_bitmap
(w
, glyph_row
, 0);
2408 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2409 (other terminals do it the other way round). We must set
2410 w->phys_cursor_width to the cursor width. For bar cursors, that
2411 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2412 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2414 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2415 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2416 if (cursor_type
== BAR_CURSOR
)
2418 if (cursor_width
< 1)
2419 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2420 w
->phys_cursor_width
= cursor_width
;
2422 /* If we have an HBAR, "cursor_width" MAY specify height. */
2423 else if (cursor_type
== HBAR_CURSOR
)
2425 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2426 fy
+= h
- cursor_height
;
2430 r.origin.x
= fx
, r.origin.y
= fy
;
2432 r.
size.width
= w
->phys_cursor_width
;
2434 /* TODO: only needed in rare cases with last-resort font in HELLO..
2435 should we do this more efficiently? */
2436 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2439 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2440 if (face
&& NS_FACE_BACKGROUND
(face
)
2441 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2443 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2444 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2447 [FRAME_CURSOR_COLOR
(f
) set];
2449 #ifdef NS_IMPL_COCOA
2450 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2451 atomic. Cleaner ways of doing this should be investigated.
2452 One way would be to set a global variable DRAWING_CURSOR
2453 when making the call to draw_phys..(), don't focus in that
2454 case, then move the ns_unfocus() here after that call. */
2455 NSDisableScreenUpdates
();
2458 switch (cursor_type
)
2462 case FILLED_BOX_CURSOR
:
2465 case HOLLOW_BOX_CURSOR
:
2468 NSRectFill
(NSInsetRect
(r
, 1, 1));
2469 [FRAME_CURSOR_COLOR
(f
) set];
2476 /* If the character under cursor is R2L, draw the bar cursor
2477 on the right of its glyph, rather than on the left. */
2478 cursor_glyph
= get_phys_cursor_glyph
(w
);
2479 if ((cursor_glyph
->resolved_level
& 1) != 0)
2480 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2487 /* draw the character under the cursor */
2488 if (cursor_type
!= NO_CURSOR
)
2489 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2491 #ifdef NS_IMPL_COCOA
2492 NSEnableScreenUpdates
();
2499 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2500 /* --------------------------------------------------------------------------
2501 External (RIF): Draw a vertical line.
2502 -------------------------------------------------------------------------- */
2504 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2506 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2508 NSTRACE
(ns_draw_vertical_window_border
);
2510 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2512 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2514 ns_focus
(f
, &r
, 1);
2521 show_hourglass
(struct atimer
*timer
)
2523 if (hourglass_shown_p
)
2528 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2530 hourglass_shown_p
= 1;
2536 hide_hourglass
(void
)
2538 if (!hourglass_shown_p
)
2543 /* TODO: remove NSProgressIndicator from all frames */
2545 hourglass_shown_p
= 0;
2551 /* ==========================================================================
2553 Glyph drawing operations
2555 ========================================================================== */
2558 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2559 /* --------------------------------------------------------------------------
2560 Wrapper utility to account for internal border width on full-width lines,
2561 and allow top full-width rows to hit the frame top. nr should be pointer
2562 to two successive NSRects. Number of rects actually used is returned.
2563 -------------------------------------------------------------------------- */
2565 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2569 /* --------------------------------------------------------------------
2570 Draw a wavy line under glyph string s. The wave fills wave_height
2577 wave_height = 3 | * * * *
2578 --------------------------------------------------------------------- */
2581 ns_draw_underwave
(struct glyph_string
*s
, CGFloat width
, CGFloat x
)
2583 int wave_height
= 3, wave_length
= 3;
2584 int y
, dx
, dy
, odd
, xmax
;
2589 dy
= wave_height
- 1;
2593 /* Find and set clipping rectangle */
2594 waveClip
= NSMakeRect
(x
, y
, width
, wave_height
);
2595 [[NSGraphicsContext currentContext
] saveGraphicsState
];
2596 NSRectClip
(waveClip
);
2598 /* Draw the waves */
2599 a.x
= x
- ((int
)(x
) % dx);
2601 odd
= (int
)(a.x
/dx
) % 2;
2611 [NSBezierPath strokeLineFromPoint
:a toPoint
:b
];
2612 a.x
= b.x
, a.y
= b.y
;
2613 b.x
+= dx
, b.y
= y
+ odd
*dy
;
2617 /* Restore previous clipping rectangle(s) */
2618 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
2624 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2625 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2626 /* --------------------------------------------------------------------------
2627 Draw underline, overline, and strike-through on glyph string s.
2628 -------------------------------------------------------------------------- */
2630 if (s
->for_overlaps
)
2634 if (face
->underline_p
)
2636 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2638 if (face
->underline_defaulted_p
)
2641 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2643 ns_draw_underwave
(s
, width
, x
);
2645 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2649 unsigned
long thickness
, position
;
2651 /* If the prev was underlined, match its appearance. */
2652 if (s
->prev
&& s
->prev
->face
->underline_p
2653 && s
->prev
->underline_thickness
> 0)
2655 thickness
= s
->prev
->underline_thickness
;
2656 position
= s
->prev
->underline_position
;
2661 unsigned
long descent
;
2664 descent
= s
->y
+ s
->height
- s
->ybase
;
2666 /* Use underline thickness of font, defaulting to 1. */
2667 thickness
= (font
&& font
->underline_thickness
> 0)
2668 ? font
->underline_thickness
: 1;
2670 /* Determine the offset of underlining from the baseline. */
2671 if (x_underline_at_descent_line
)
2672 position
= descent
- thickness
;
2673 else if (x_use_underline_position_properties
2674 && font
&& font
->underline_position
>= 0)
2675 position
= font
->underline_position
;
2677 position
= lround
(font
->descent
/ 2);
2679 position
= underline_minimum_offset
;
2681 position
= max (position
, underline_minimum_offset
);
2683 /* Ensure underlining is not cropped. */
2684 if (descent
<= position
)
2686 position
= descent
- 1;
2689 else if (descent
< position
+ thickness
)
2693 s
->underline_thickness
= thickness
;
2694 s
->underline_position
= position
;
2696 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2698 if (face
->underline_defaulted_p
)
2701 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2705 /* Do overline. We follow other terms in using a thickness of 1
2706 and ignoring overline_margin. */
2707 if (face
->overline_p
)
2710 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2712 if (face
->overline_color_defaulted_p
)
2715 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2719 /* Do strike-through. We follow other terms for thickness and
2720 vertical position.*/
2721 if (face
->strike_through_p
)
2726 dy
= lrint
((s
->height
- 1) / 2);
2727 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2729 if (face
->strike_through_color_defaulted_p
)
2732 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2738 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2739 /* --------------------------------------------------------------------------
2740 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2741 Note we can't just use an NSDrawRect command, because of the possibility
2742 of some sides not being drawn, and because the rect will be filled.
2743 -------------------------------------------------------------------------- */
2749 s.
size.height
= thickness
;
2751 s.origin.y
+= r.
size.height
- thickness
;
2754 s.
size.height
= r.
size.height
;
2755 s.origin.y
= r.origin.y
;
2757 /* left, right (optional) */
2758 s.
size.width
= thickness
;
2763 s.origin.x
+= r.
size.width
- thickness
;
2770 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2771 char top_p
, char bottom_p
, char left_p
, char right_p
,
2772 struct glyph_string
*s
)
2773 /* --------------------------------------------------------------------------
2774 Draw a relief rect inside r, optionally leaving some sides open.
2775 Note we can't just use an NSDrawBezel command, because of the possibility
2776 of some sides not being drawn, and because the rect will be filled.
2777 -------------------------------------------------------------------------- */
2779 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2780 NSColor
*newBaseCol
= nil
;
2783 NSTRACE
(ns_draw_relief
);
2787 if (s
->face
->use_box_color_for_shadows_p
)
2789 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2791 /* else if (s->first_glyph->type == IMAGE_GLYPH
2793 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2795 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2799 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2802 if (newBaseCol
== nil
)
2803 newBaseCol
= [NSColor grayColor
];
2805 if (newBaseCol
!= baseCol
) /* TODO: better check */
2808 baseCol
= [newBaseCol retain
];
2810 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2812 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2815 [(raised_p ? lightCol
: darkCol
) set];
2817 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2820 sr.
size.height
= thickness
;
2821 if (top_p
) NSRectFill
(sr
);
2824 sr.
size.height
= r.
size.height
;
2825 sr.
size.width
= thickness
;
2826 if (left_p
) NSRectFill
(sr
);
2828 [(raised_p ? darkCol
: lightCol
) set];
2831 sr.
size.width
= r.
size.width
;
2832 sr.
size.height
= thickness
;
2833 sr.origin.y
+= r.
size.height
- thickness
;
2834 if (bottom_p
) NSRectFill
(sr
);
2837 sr.
size.height
= r.
size.height
;
2838 sr.origin.y
= r.origin.y
;
2839 sr.
size.width
= thickness
;
2840 sr.origin.x
+= r.
size.width
- thickness
;
2841 if (right_p
) NSRectFill
(sr
);
2846 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2847 /* --------------------------------------------------------------------------
2848 Function modeled after x_draw_glyph_string_box ().
2849 Sets up parameters for drawing.
2850 -------------------------------------------------------------------------- */
2852 int right_x
, last_x
;
2853 char left_p
, right_p
;
2854 struct glyph
*last_glyph
;
2859 if (s
->hl
== DRAW_MOUSE_FACE
)
2861 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2863 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2868 thickness
= face
->box_line_width
;
2870 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2872 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2873 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2874 : window_box_right
(s
->w
, s
->area
));
2875 last_glyph
= (s
->cmp || s
->img
2876 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2878 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2879 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2881 left_p
= (s
->first_glyph
->left_box_line_p
2882 ||
(s
->hl
== DRAW_MOUSE_FACE
2883 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2884 right_p
= (last_glyph
->right_box_line_p
2885 ||
(s
->hl
== DRAW_MOUSE_FACE
2886 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2888 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2890 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2891 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2893 ns_draw_box
(r
, abs (thickness
),
2894 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2899 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2900 1, 1, left_p
, right_p
, s
);
2906 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2907 /* --------------------------------------------------------------------------
2908 Modeled after x_draw_glyph_string_background, which draws BG in
2909 certain cases. Others are left to the text rendering routine.
2910 -------------------------------------------------------------------------- */
2912 NSTRACE
(ns_maybe_dumpglyphs_background
);
2914 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2916 int box_line_width
= max (s
->face
->box_line_width
, 0);
2917 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2918 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2921 if (s
->hl
== DRAW_MOUSE_FACE
)
2923 face
= FACE_FROM_ID
(s
->f
,
2924 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2926 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2929 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2931 [(NS_FACE_BACKGROUND
(face
) != 0
2932 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2933 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2936 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2937 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2940 if (s
->hl
!= DRAW_CURSOR
)
2942 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2943 s
->background_width
,
2944 s
->height
-2*box_line_width
);
2948 s
->background_filled_p
= 1;
2955 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2956 /* --------------------------------------------------------------------------
2957 Renders an image and associated borders.
2958 -------------------------------------------------------------------------- */
2960 EmacsImage
*img
= s
->img
->pixmap
;
2961 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2962 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2963 int bg_x
, bg_y
, bg_height
;
2970 NSTRACE
(ns_dumpglyphs_image
);
2972 if (s
->face
->box
!= FACE_NO_BOX
2973 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
2974 x
+= abs (s
->face
->box_line_width
);
2977 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
2978 bg_height
= s
->height
;
2979 /* other terms have this, but was causing problems w/tabbar mode */
2980 /* - 2 * box_line_vwidth; */
2982 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
2983 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
2985 /* Draw BG: if we need larger area than image itself cleared, do that,
2986 otherwise, since we composite the image under NS (instead of mucking
2987 with its background color), we must clear just the image area. */
2988 if (s
->hl
== DRAW_MOUSE_FACE
)
2990 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2992 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2995 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2997 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
2999 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
3000 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
3002 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
3003 s
->background_filled_p
= 1;
3007 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3012 /* Draw the image.. do we need to draw placeholder if img ==nil? */
3015 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
3016 NSRect dr
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3017 NSRect ir
= NSMakeRect
(s
->slice.x
, s
->slice.y
,
3018 s
->slice.width
, s
->slice.height
);
3021 operation
: NSCompositeSourceOver
3026 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
3027 operation
: NSCompositeSourceOver
];
3031 if (s
->hl
== DRAW_CURSOR
)
3033 [FRAME_CURSOR_COLOR
(s
->f
) set];
3034 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3035 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3037 /* Currently on NS img->mask is always 0. Since
3038 get_window_cursor_type specifies a hollow box cursor when on
3039 a non-masked image we never reach this clause. But we put it
3040 in in anticipation of better support for image masks on
3042 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3046 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3049 /* Draw underline, overline, strike-through. */
3050 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3052 /* Draw relief, if requested */
3053 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3055 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3057 th
= tool_bar_button_relief
>= 0 ?
3058 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3059 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3063 th
= abs (s
->img
->relief
);
3064 raised_p
= (s
->img
->relief
> 0);
3067 r.origin.x
= x
- th
;
3068 r.origin.y
= y
- th
;
3069 r.
size.width
= s
->slice.width
+ 2*th
-1;
3070 r.
size.height
= s
->slice.height
+ 2*th
-1;
3071 ns_draw_relief
(r
, th
, raised_p
,
3073 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3075 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3078 /* If there is no mask, the background won't be seen,
3079 so draw a rectangle on the image for the cursor.
3080 Do this for all images, getting transparency right is not reliable. */
3081 if (s
->hl
== DRAW_CURSOR
)
3083 int thickness
= abs (s
->img
->relief
);
3084 if (thickness
== 0) thickness
= 1;
3085 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3091 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3096 NSColor
*fgCol
, *bgCol
;
3098 if (!s
->background_filled_p
)
3100 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3101 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3103 ns_focus
(s
->f
, r
, n
);
3105 if (s
->hl
== DRAW_MOUSE_FACE
)
3107 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3109 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3112 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3114 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3115 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3117 for (i
= 0; i
< n
; ++i
)
3119 if (!s
->row
->full_width_p
)
3121 int overrun
, leftoverrun
;
3123 /* truncate to avoid overwriting fringe and/or scrollbar */
3124 overrun
= max (0, (s
->x
+ s
->background_width
)
3125 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3126 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3127 r
[i
].
size.width
-= overrun
;
3129 /* truncate to avoid overwriting to left of the window box */
3130 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3131 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3133 if (leftoverrun
> 0)
3135 r
[i
].origin.x
+= leftoverrun
;
3136 r
[i
].
size.width
-= leftoverrun
;
3139 /* XXX: Try to work between problem where a stretch glyph on
3140 a partially-visible bottom row will clear part of the
3141 modeline, and another where list-buffers headers and similar
3142 rows erroneously have visible_height set to 0. Not sure
3143 where this is coming from as other terms seem not to show. */
3144 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3149 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3150 overwriting cursor (usually when cursor on a tab) */
3151 if (s
->hl
== DRAW_CURSOR
)
3156 width
= s
->w
->phys_cursor_width
;
3157 r
[i
].
size.width
-= width
;
3158 r
[i
].origin.x
+= width
;
3162 /* Draw overlining, etc. on the cursor. */
3163 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3164 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3166 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3173 /* Draw overlining, etc. on the stretch glyph (or the part
3174 of the stretch glyph after the cursor). */
3175 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3179 s
->background_filled_p
= 1;
3185 ns_draw_glyph_string
(struct glyph_string
*s
)
3186 /* --------------------------------------------------------------------------
3187 External (RIF): Main draw-text call.
3188 -------------------------------------------------------------------------- */
3190 /* TODO (optimize): focus for box and contents draw */
3193 char box_drawn_p
= 0;
3195 NSTRACE
(ns_draw_glyph_string
);
3197 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3200 struct glyph_string
*next
;
3202 for (width
= 0, next
= s
->next
;
3203 next
&& width
< s
->right_overhang
;
3204 width
+= next
->width
, next
= next
->next
)
3205 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3207 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3209 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3210 ns_focus
(s
->f
, r
, n
);
3211 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3216 ns_dumpglyphs_stretch
(s
->next
);
3218 next
->num_clips
= 0;
3222 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3223 && (s
->first_glyph
->type == CHAR_GLYPH
3224 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3226 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3227 ns_focus
(s
->f
, r
, n
);
3228 ns_maybe_dumpglyphs_background
(s
, 1);
3229 ns_dumpglyphs_box_or_relief
(s
);
3234 switch (s
->first_glyph
->type)
3238 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3239 ns_focus
(s
->f
, r
, n
);
3240 ns_dumpglyphs_image
(s
, r
[0]);
3245 ns_dumpglyphs_stretch
(s
);
3249 case COMPOSITE_GLYPH
:
3250 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3251 ns_focus
(s
->f
, r
, n
);
3253 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3254 && ! s
->first_glyph
->u.cmp.automatic
))
3255 s
->background_filled_p
= 1;
3257 ns_maybe_dumpglyphs_background
3258 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3260 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3261 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3262 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3263 NS_DUMPGLYPH_NORMAL
));
3264 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3265 if (ns_tmp_font
== NULL)
3266 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3268 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3270 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3271 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3272 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3275 ns_tmp_font
->font.driver
->draw
3276 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3277 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3278 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
3280 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3282 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3283 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3284 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3290 case GLYPHLESS_GLYPH
:
3291 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3292 ns_focus
(s
->f
, r
, n
);
3294 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3295 && ! s
->first_glyph
->u.cmp.automatic
))
3296 s
->background_filled_p
= 1;
3298 ns_maybe_dumpglyphs_background
3299 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3301 /* Not yet implemented. */
3310 /* Draw box if not done already. */
3311 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3313 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3314 ns_focus
(s
->f
, r
, n
);
3315 ns_dumpglyphs_box_or_relief
(s
);
3324 /* ==========================================================================
3328 ========================================================================== */
3332 ns_send_appdefined
(int value
)
3333 /* --------------------------------------------------------------------------
3334 Internal: post an appdefined event which EmacsApp-sendEvent will
3335 recognize and take as a command to halt the event loop.
3336 -------------------------------------------------------------------------- */
3338 /*NSTRACE (ns_send_appdefined); */
3340 /* Only post this event if we haven't already posted one. This will end
3341 the [NXApp run] main loop after having processed all events queued at
3343 if (send_appdefined
)
3347 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3348 send_appdefined
= NO
;
3350 /* Don't need wakeup timer any more */
3353 [timed_entry invalidate
];
3354 [timed_entry release
];
3358 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3359 location
: NSMakePoint
(0, 0)
3362 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3363 context
: [NSApp context
]
3368 /* Post an application defined event on the event queue. When this is
3369 received the [NXApp run] will return, thus having processed all
3370 events which are currently queued. */
3371 [NSApp postEvent
: nxev atStart
: NO
];
3376 ns_read_socket
(struct terminal *terminal, struct input_event
*hold_quit
)
3377 /* --------------------------------------------------------------------------
3378 External (hook): Post an event to ourself and keep reading events until
3379 we read it back again. In effect process all events which were waiting.
3380 From 21+ we have to manage the event buffer ourselves.
3381 -------------------------------------------------------------------------- */
3383 struct input_event ev
;
3386 /* NSTRACE (ns_read_socket); */
3388 if ([NSApp modalWindow
] != nil
)
3391 if (hold_event_q.nr
> 0)
3394 for (i
= 0; i
< hold_event_q.nr
; ++i
)
3395 kbd_buffer_store_event_hold
(&hold_event_q.q
[i
], hold_quit
);
3396 hold_event_q.nr
= 0;
3401 n_emacs_events_pending
= 0;
3404 q_event_ptr
= hold_quit
;
3406 /* we manage autorelease pools by allocate/reallocate each time around
3407 the loop; strict nesting is occasionally violated but seems not to
3408 matter.. earlier methods using full nesting caused major memory leaks */
3409 [outerpool release
];
3410 outerpool
= [[NSAutoreleasePool alloc
] init
];
3412 /* If have pending open-file requests, attend to the next one of those. */
3413 if (ns_pending_files
&& [ns_pending_files count
] != 0
3414 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3416 [ns_pending_files removeObjectAtIndex
: 0];
3418 /* Deal with pending service requests. */
3419 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3421 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3422 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3424 [ns_pending_service_names removeObjectAtIndex
: 0];
3425 [ns_pending_service_args removeObjectAtIndex
: 0];
3429 /* Run and wait for events. We must always send one NX_APPDEFINED event
3430 to ourself, otherwise [NXApp run] will never exit. */
3431 send_appdefined
= YES
;
3432 ns_send_appdefined
(-1);
3434 if (++apploopnr
!= 1)
3442 nevents
= n_emacs_events_pending
;
3443 n_emacs_events_pending
= 0;
3444 emacs_event
= q_event_ptr
= NULL;
3452 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3453 fd_set
*exceptfds
, EMACS_TIME
*timeout
, sigset_t
*sigmask
)
3454 /* --------------------------------------------------------------------------
3455 Replacement for select, checking for events
3456 -------------------------------------------------------------------------- */
3460 struct input_event event
;
3463 /* NSTRACE (ns_select); */
3465 if (hold_event_q.nr
> 0)
3467 /* We already have events pending. */
3473 for (k
= 0; k
< nfds
+1; k
++)
3475 if (readfds
&& FD_ISSET
(k
, readfds
)) ++nr
;
3476 if (writefds
&& FD_ISSET
(k
, writefds
)) ++nr
;
3480 ||
(timeout
&& timeout
->tv_sec
== 0 && timeout
->tv_nsec
== 0))
3481 return pselect
(nfds
, readfds
, writefds
, exceptfds
, timeout
, sigmask
);
3483 [outerpool release
];
3484 outerpool
= [[NSAutoreleasePool alloc
] init
];
3487 send_appdefined
= YES
;
3490 pthread_mutex_lock
(&select_mutex
);
3495 select_readfds
= *readfds
;
3496 select_valid
+= SELECT_HAVE_READ
;
3500 select_writefds
= *writefds
;
3501 select_valid
+= SELECT_HAVE_WRITE
;
3506 select_timeout
= *timeout
;
3507 select_valid
+= SELECT_HAVE_TMO
;
3510 pthread_mutex_unlock
(&select_mutex
);
3512 /* Inform fd_handler that select should be called */
3514 emacs_write
(selfds
[1], &c
, 1);
3516 else if (nr
== 0 && timeout
)
3518 /* No file descriptor, just a timeout, no need to wake fd_handler */
3519 double time
= EMACS_TIME_TO_DOUBLE
(*timeout
);
3520 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3523 @selector
(timeout_handler
:)
3528 else /* No timeout and no file descriptors, can this happen? */
3530 /* Send appdefined so we exit from the loop */
3531 ns_send_appdefined
(-1);
3536 emacs_event
= &event
;
3537 if (++apploopnr
!= 1)
3544 if (nr
> 0 && readfds
)
3547 emacs_write
(selfds
[1], &c
, 1);
3551 t
= last_appdefined_event_data
;
3553 if (t
!= NO_APPDEFINED_DATA
)
3555 last_appdefined_event_data
= NO_APPDEFINED_DATA
;
3559 /* The NX_APPDEFINED event we received was a timeout. */
3564 /* The NX_APPDEFINED event we received was the result of
3565 at least one real input event arriving. */
3571 /* Received back from select () in fd_handler; copy the results */
3572 pthread_mutex_lock
(&select_mutex
);
3573 if (readfds
) *readfds
= select_readfds
;
3574 if (writefds
) *writefds
= select_writefds
;
3575 if (timeout
) *timeout
= select_timeout
;
3576 pthread_mutex_unlock
(&select_mutex
);
3586 /* ==========================================================================
3590 ========================================================================== */
3594 ns_set_vertical_scroll_bar
(struct window
*window
,
3595 int portion
, int whole
, int position
)
3596 /* --------------------------------------------------------------------------
3597 External (hook): Update or add scrollbar
3598 -------------------------------------------------------------------------- */
3602 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3603 EmacsView
*view = FRAME_NS_VIEW
(f
);
3604 int window_y
, window_height
;
3605 int top
, left
, height
, width
, sb_width
, sb_left
;
3607 BOOL fringe_extended_p
;
3609 /* optimization; display engine sends WAY too many of these.. */
3610 if (!NILP
(window
->vertical_scroll_bar
))
3612 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3613 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3615 if (view->scrollbarsNeedingUpdate
== 0)
3617 if (!windows_or_buffers_changed
)
3621 view->scrollbarsNeedingUpdate
--;
3625 NSTRACE
(ns_set_vertical_scroll_bar
);
3627 /* Get dimensions. */
3628 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3630 height
= window_height
;
3631 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3632 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3634 /* allow for displaying a skinnier scrollbar than char area allotted */
3635 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3636 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3639 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3640 /* the parent view is flipped, so we need to flip y value */
3642 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3644 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(window
))
3645 fringe_extended_p
= (WINDOW_LEFTMOST_P
(window
)
3646 && WINDOW_LEFT_FRINGE_WIDTH
(window
)
3647 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3648 || WINDOW_LEFT_MARGIN_COLS
(window
) == 0));
3650 fringe_extended_p
= (WINDOW_RIGHTMOST_P
(window
)
3651 && WINDOW_RIGHT_FRINGE_WIDTH
(window
)
3652 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3653 || WINDOW_RIGHT_MARGIN_COLS
(window
) == 0));
3655 XSETWINDOW
(win
, window
);
3658 /* we want at least 5 lines to display a scrollbar */
3659 if (WINDOW_TOTAL_LINES
(window
) < 5)
3661 if (!NILP
(window
->vertical_scroll_bar
))
3663 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3664 [bar removeFromSuperview
];
3665 wset_vertical_scroll_bar
(window
, Qnil
);
3667 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3672 if (NILP
(window
->vertical_scroll_bar
))
3674 if (width
> 0 && height
> 0)
3676 if (fringe_extended_p
)
3677 ns_clear_frame_area
(f
, sb_left
, top
, sb_width
, height
);
3679 ns_clear_frame_area
(f
, left
, top
, width
, height
);
3682 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3683 wset_vertical_scroll_bar
(window
, make_save_value
(bar, 0));
3688 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3689 oldRect
= [bar frame
];
3690 r.
size.width
= oldRect.
size.width
;
3691 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3693 if (oldRect.origin.x
!= r.origin.x
)
3694 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3699 [bar setPosition
: position portion
: portion whole
: whole
];
3705 ns_condemn_scroll_bars
(struct frame
*f
)
3706 /* --------------------------------------------------------------------------
3707 External (hook): arrange for all frame's scrollbars to be removed
3708 at next call to judge_scroll_bars, except for those redeemed.
3709 -------------------------------------------------------------------------- */
3713 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3715 NSTRACE
(ns_condemn_scroll_bars
);
3717 for (i
=[subviews count
]-1; i
>= 0; i
--)
3719 view = [subviews objectAtIndex
: i
];
3720 if ([view isKindOfClass
: [EmacsScroller
class]])
3727 ns_redeem_scroll_bar
(struct window
*window
)
3728 /* --------------------------------------------------------------------------
3729 External (hook): arrange to spare this window's scrollbar
3730 at next call to judge_scroll_bars.
3731 -------------------------------------------------------------------------- */
3734 NSTRACE
(ns_redeem_scroll_bar
);
3735 if (!NILP
(window
->vertical_scroll_bar
))
3737 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3744 ns_judge_scroll_bars
(struct frame
*f
)
3745 /* --------------------------------------------------------------------------
3746 External (hook): destroy all scrollbars on frame that weren't
3747 redeemed after call to condemn_scroll_bars.
3748 -------------------------------------------------------------------------- */
3752 EmacsView
*eview
= FRAME_NS_VIEW
(f
);
3753 NSArray
*subviews
= [[eview superview
] subviews
];
3756 NSTRACE
(ns_judge_scroll_bars
);
3757 for (i
= [subviews count
]-1; i
>= 0; --i
)
3759 view = [subviews objectAtIndex
: i
];
3760 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3766 [eview updateFrameSize
: NO
];
3771 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3773 /* XXX irrelevant under NS */
3778 /* ==========================================================================
3782 ========================================================================== */
3785 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3787 NSScreen
*screen
= [NSScreen mainScreen
];
3788 return [screen frame
].
size.height
;
3792 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3794 NSScreen
*screen
= [NSScreen mainScreen
];
3795 return [screen frame
].
size.width
;
3799 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3800 /* --------------------------------------------------------------------------
3801 Convert modifier name to lisp symbol
3802 -------------------------------------------------------------------------- */
3804 if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3806 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3808 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3810 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3812 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3814 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3822 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3823 Lisp_Object yesval
, Lisp_Object noval
,
3824 BOOL is_float
, BOOL is_modstring
)
3825 /* --------------------------------------------------------------------------
3826 Check a parameter value in user's preferences
3827 -------------------------------------------------------------------------- */
3829 const
char *value
= ns_get_defaults_value
(parameter
);
3835 if (c_strcasecmp
(value
, "YES"
) == 0)
3837 else if (c_strcasecmp
(value
, "NO"
) == 0)
3839 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3840 *result
= make_float
(f
);
3841 else if (is_modstring
&& value
)
3842 *result
= ns_string_to_lispmod
(value
);
3843 else fprintf (stderr
,
3844 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3850 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3851 /* --------------------------------------------------------------------------
3852 Initialize global info and storage for display.
3853 -------------------------------------------------------------------------- */
3855 NSScreen
*screen
= [NSScreen mainScreen
];
3856 NSWindowDepth depth
= [screen depth
];
3857 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
3859 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3860 dpyinfo
->resy
= 72.27;
3861 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3862 NSColorSpaceFromDepth
(depth
)]
3863 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3864 NSColorSpaceFromDepth
(depth
)];
3865 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3866 dpyinfo
->image_cache
= make_image_cache
();
3867 dpyinfo
->color_table
= xmalloc
(sizeof
*dpyinfo
->color_table
);
3868 dpyinfo
->color_table
->colors
= NULL;
3869 dpyinfo
->root_window
= 42; /* a placeholder.. */
3871 hlinfo
->mouse_face_mouse_frame
= NULL;
3872 hlinfo
->mouse_face_deferred_gc
= 0;
3873 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
3874 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
3875 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3876 hlinfo
->mouse_face_window
= hlinfo
->mouse_face_overlay
= Qnil
;
3877 hlinfo
->mouse_face_hidden
= 0;
3879 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
3880 hlinfo
->mouse_face_defer
= 0;
3882 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3884 dpyinfo
->n_fonts
= 0;
3885 dpyinfo
->smallest_font_height
= 1;
3886 dpyinfo
->smallest_char_width
= 1;
3890 /* This and next define (many of the) public functions in this file. */
3891 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3892 with using despite presence in the "system dependent" redisplay
3893 interface. In addition, many of the ns_ methods have code that is
3894 shared with all terms, indicating need for further refactoring. */
3895 extern frame_parm_handler ns_frame_parm_handlers
[];
3896 static
struct redisplay_interface ns_redisplay_interface
=
3898 ns_frame_parm_handlers
,
3902 x_clear_end_of_line
,
3904 ns_after_update_window_line
,
3905 ns_update_window_begin
,
3906 ns_update_window_end
,
3909 0, /* flush_display_optional */
3910 x_clear_window_mouse_face
,
3911 x_get_glyph_overhangs
,
3912 x_fix_overlapping_area
,
3913 ns_draw_fringe_bitmap
,
3914 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3915 0, /* destroy_fringe_bitmap */
3916 ns_compute_glyph_string_overhangs
,
3917 ns_draw_glyph_string
, /* interface to nsfont.m */
3918 ns_define_frame_cursor
,
3919 ns_clear_frame_area
,
3920 ns_draw_window_cursor
,
3921 ns_draw_vertical_window_border
,
3922 ns_shift_glyphs_for_insert
3927 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3933 /* This function is called when the last frame on a display is deleted. */
3935 ns_delete_terminal
(struct terminal *terminal)
3937 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3939 /* Protect against recursive calls. delete_frame in
3940 delete_terminal calls us back when it deletes our last frame. */
3941 if (!terminal->name
)
3946 x_destroy_all_bitmaps
(dpyinfo
);
3947 ns_delete_display
(dpyinfo
);
3952 static
struct terminal *
3953 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3954 /* --------------------------------------------------------------------------
3955 Set up use of NS before we make the first connection.
3956 -------------------------------------------------------------------------- */
3958 struct terminal *terminal;
3960 NSTRACE
(ns_create_terminal
);
3962 terminal = create_terminal
();
3964 terminal->type = output_ns
;
3965 terminal->display_info.ns
= dpyinfo
;
3966 dpyinfo
->terminal = terminal;
3968 terminal->rif
= &ns_redisplay_interface
;
3970 terminal->clear_frame_hook
= ns_clear_frame
;
3971 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
3972 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
3973 terminal->ring_bell_hook
= ns_ring_bell
;
3974 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
3975 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
3976 terminal->update_begin_hook
= ns_update_begin
;
3977 terminal->update_end_hook
= ns_update_end
;
3978 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
3979 terminal->read_socket_hook
= ns_read_socket
;
3980 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
3981 terminal->mouse_position_hook
= ns_mouse_position
;
3982 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
3983 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
3985 terminal->fullscreen_hook
= ns_fullscreen_hook
;
3987 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
3988 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
3989 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
3990 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
3992 terminal->delete_frame_hook
= x_destroy_window
;
3993 terminal->delete_terminal_hook
= ns_delete_terminal
;
3995 terminal->scroll_region_ok
= 1;
3996 terminal->char_ins_del_ok
= 1;
3997 terminal->line_ins_del_ok
= 1;
3998 terminal->fast_clear_end_of_line
= 1;
3999 terminal->memory_below_frame
= 0;
4005 struct ns_display_info
*
4006 ns_term_init
(Lisp_Object display_name
)
4007 /* --------------------------------------------------------------------------
4008 Start the Application and get things rolling.
4009 -------------------------------------------------------------------------- */
4011 struct terminal *terminal;
4012 struct ns_display_info
*dpyinfo
;
4013 static int ns_initialized
= 0;
4016 if (ns_initialized
) return x_display_list
;
4019 NSTRACE
(ns_term_init
);
4021 [outerpool release
];
4022 outerpool
= [[NSAutoreleasePool alloc
] init
];
4024 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
4025 /*GSDebugAllocationActive (YES); */
4029 Fset_input_interrupt_mode
(Qnil
);
4031 if (selfds
[0] == -1)
4033 if (pipe
(selfds
) == -1)
4035 fprintf (stderr
, "Failed to create pipe
: %s\n",
4036 emacs_strerror
(errno
));
4040 fcntl
(selfds
[0], F_SETFL
, O_NONBLOCK|fcntl
(selfds
[0], F_GETFL
));
4041 FD_ZERO
(&select_readfds
);
4042 FD_ZERO
(&select_writefds
);
4043 pthread_mutex_init
(&select_mutex
, NULL);
4046 ns_pending_files
= [[NSMutableArray alloc
] init
];
4047 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
4048 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
4050 /* Start app and create the main menu, window, view.
4051 Needs to be here because ns_initialize_display_info () uses AppKit classes.
4052 The view will then ask the NSApp to stop and return to Emacs. */
4053 [EmacsApp sharedApplication
];
4056 [NSApp setDelegate
: NSApp
];
4058 /* Start the select thread. */
4059 [NSThread detachNewThreadSelector
:@selector
(fd_handler
:)
4063 /* debugging: log all notifications */
4064 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4065 selector: @selector (logNotification:)
4066 name: nil object: nil]; */
4068 dpyinfo
= xzalloc
(sizeof
*dpyinfo
);
4070 ns_initialize_display_info
(dpyinfo
);
4071 terminal = ns_create_terminal
(dpyinfo
);
4073 terminal->kboard
= xmalloc
(sizeof
*terminal->kboard
);
4074 init_kboard
(terminal->kboard
);
4075 kset_window_system
(terminal->kboard
, Qns
);
4076 terminal->kboard
->next_kboard
= all_kboards
;
4077 all_kboards
= terminal->kboard
;
4078 /* Don't let the initial kboard remain current longer than necessary.
4079 That would cause problems if a file loaded on startup tries to
4080 prompt in the mini-buffer. */
4081 if (current_kboard
== initial_kboard
)
4082 current_kboard
= terminal->kboard
;
4083 terminal->kboard
->reference_count
++;
4085 dpyinfo
->next
= x_display_list
;
4086 x_display_list
= dpyinfo
;
4088 /* Put it on ns_display_name_list */
4089 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
4090 ns_display_name_list
);
4091 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
4093 terminal->name
= xstrdup
(SSDATA
(display_name
));
4097 if (!inhibit_x_resources
)
4099 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4102 /* this is a standard variable */
4103 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4104 make_float
(10.0), make_float
(6.0), YES
, NO
);
4105 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4108 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
4109 stringForKey
: @"AppleHighlightColor"
];
4110 if (ns_selection_color
== nil
)
4111 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
4114 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4118 Lisp_Object color_file
, color_map
, color
;
4122 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4123 Fsymbol_value
(intern
("data
-directory"
)));
4125 color_map
= Fx_load_color_file
(color_file
);
4126 if (NILP
(color_map
))
4127 fatal
("Could not read
%s.\n", SDATA (color_file));
4129 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4130 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4132 color
= XCAR
(color_map
);
4133 name
= SSDATA
(XCAR
(color
));
4134 c
= XINT
(XCDR
(color
));
4136 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4137 green
: GREEN_FROM_ULONG
(c
) / 255.0
4138 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4140 forKey
: [NSString stringWithUTF8String
: name
]];
4142 [cl writeToFile
: nil
];
4147 #ifdef NS_IMPL_GNUSTEP
4148 Vwindow_system_version
= build_string
(gnustep_base_version
);
4150 /*PSnextrelease (128, c); */
4151 char c
[DBL_BUFSIZE_BOUND
];
4152 int len
= dtoastr
(c
, sizeof c
, 0, 0, NSAppKitVersionNumber
);
4153 Vwindow_system_version
= make_unibyte_string
(c
, len
);
4157 delete_keyboard_wait_descriptor
(0);
4159 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4161 /* Set up OS X app menu */
4162 #ifdef NS_IMPL_COCOA
4166 /* set up the application menu */
4167 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4168 [svcsMenu setAutoenablesItems
: NO
];
4169 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4170 [appMenu setAutoenablesItems
: NO
];
4171 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4172 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4174 [appMenu insertItemWithTitle
: @"About Emacs"
4175 action
: @selector
(orderFrontStandardAboutPanel
:)
4178 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4179 [appMenu insertItemWithTitle
: @"Preferences..."
4180 action
: @selector
(showPreferencesWindow
:)
4183 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4184 item
= [appMenu insertItemWithTitle
: @"Services"
4185 action
: @selector
(menuDown
:)
4188 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4189 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4190 [appMenu insertItemWithTitle
: @"Hide Emacs"
4191 action
: @selector
(hide
:)
4194 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4195 action
: @selector
(hideOtherApplications
:)
4198 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4199 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4200 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4201 action
: @selector
(terminate
:)
4205 item
= [mainMenu insertItemWithTitle
: ns_app_name
4206 action
: @selector
(menuDown
:)
4209 [mainMenu setSubmenu
: appMenu forItem
: item
];
4210 [dockMenu insertItemWithTitle
: @"New Frame"
4211 action
: @selector
(newFrame
:)
4215 [NSApp setMainMenu
: mainMenu
];
4216 [NSApp setAppleMenu
: appMenu
];
4217 [NSApp setServicesMenu
: svcsMenu
];
4218 /* Needed at least on Cocoa, to get dock menu to show windows */
4219 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4221 [[NSNotificationCenter defaultCenter
]
4222 addObserver
: mainMenu
4223 selector
: @selector
(trackingNotification
:)
4224 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4225 [[NSNotificationCenter defaultCenter
]
4226 addObserver
: mainMenu
4227 selector
: @selector
(trackingNotification
:)
4228 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4230 #endif
/* MAC OS X menu setup */
4232 /* Register our external input/output types, used for determining
4233 applicable services and also drag/drop eligibility. */
4234 ns_send_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
] retain
];
4235 ns_return_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
]
4237 ns_drag_types
= [[NSArray arrayWithObjects
:
4239 NSTabularTextPboardType
,
4240 NSFilenamesPboardType
,
4243 NSFontPboardType
, nil
] retain
];
4245 #ifndef NEW_STYLE_FS
4246 /* If fullscreen is in init/default-frame-alist, focus isn't set
4247 right for fullscreen windows, so set this. */
4248 [NSApp activateIgnoringOtherApps
:YES
];
4252 ns_do_open_file
= YES
;
4258 ns_term_shutdown
(int sig
)
4260 [[NSUserDefaults standardUserDefaults
] synchronize
];
4262 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4263 if (STRINGP
(Vauto_save_list_file_name
))
4264 unlink
(SSDATA
(Vauto_save_list_file_name
));
4266 if (sig
== 0 || sig
== SIGTERM
)
4268 [NSApp terminate
: NSApp
];
4270 else // force a stack
trace to happen
4277 /* ==========================================================================
4279 EmacsApp implementation
4281 ========================================================================== */
4284 @implementation EmacsApp
4286 - (void
)logNotification
: (NSNotification
*)notification
4288 const
char *name
= [[notification name
] UTF8String
];
4289 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4290 && !strstr
(name
, "WindowNumber"
))
4291 NSLog
(@"notification
: '%@'"
, [notification name
]);
4295 - (void
)sendEvent
: (NSEvent
*)theEvent
4296 /* --------------------------------------------------------------------------
4297 Called when NSApp is running for each event received. Used to stop
4298 the loop when we choose, since there's no way to just run one iteration.
4299 -------------------------------------------------------------------------- */
4301 int
type = [theEvent
type];
4302 NSWindow
*window
= [theEvent window
];
4303 /* NSTRACE (sendEvent); */
4304 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4306 #ifdef NS_IMPL_COCOA
4307 if (type == NSApplicationDefined
4308 && [theEvent data2
] == NSAPP_DATA2_RUNASSCRIPT
)
4316 if (type == NSCursorUpdate
&& window
== nil
)
4318 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4322 if (type == NSApplicationDefined
)
4324 /* Events posted by ns_send_appdefined interrupt the run loop here.
4325 But, if a modal window is up, an appdefined can still come through,
4326 (e.g., from a makeKeyWindow event) but stopping self also stops the
4327 modal loop. Just defer it until later. */
4328 if ([NSApp modalWindow
] == nil
)
4330 last_appdefined_event_data
= [theEvent data1
];
4335 send_appdefined
= YES
;
4339 [super sendEvent
: theEvent
];
4343 - (void
)showPreferencesWindow
: (id
)sender
4345 struct frame
*emacsframe
= SELECTED_FRAME
();
4346 NSEvent
*theEvent
= [NSApp currentEvent
];
4350 emacs_event
->kind
= NS_NONKEY_EVENT
;
4351 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4352 emacs_event
->modifiers
= 0;
4353 EV_TRAILER
(theEvent
);
4357 - (void
)newFrame
: (id
)sender
4359 struct frame
*emacsframe
= SELECTED_FRAME
();
4360 NSEvent
*theEvent
= [NSApp currentEvent
];
4364 emacs_event
->kind
= NS_NONKEY_EVENT
;
4365 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4366 emacs_event
->modifiers
= 0;
4367 EV_TRAILER
(theEvent
);
4371 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4372 - (BOOL
) openFile
: (NSString
*)fileName
4374 struct frame
*emacsframe
= SELECTED_FRAME
();
4375 NSEvent
*theEvent
= [NSApp currentEvent
];
4380 emacs_event
->kind
= NS_NONKEY_EVENT
;
4381 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4382 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4383 ns_input_line
= Qnil
; /* can be start or cons start,end */
4384 emacs_event
->modifiers
=0;
4385 EV_TRAILER
(theEvent
);
4391 /* **************************************************************************
4393 EmacsApp delegate implementation
4395 ************************************************************************** */
4397 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4398 /* --------------------------------------------------------------------------
4399 When application is loaded, terminate event loop in ns_term_init
4400 -------------------------------------------------------------------------- */
4402 NSTRACE
(applicationDidFinishLaunching
);
4403 [NSApp setServicesProvider
: NSApp
];
4404 ns_send_appdefined
(-2);
4408 /* Termination sequences:
4411 MenuBar | File | Exit:
4412 Select Quit from App menubar:
4414 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4417 Select Quit from Dock menu:
4420 Cancel -> Nothing else
4424 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4429 - (void
) terminate
: (id
)sender
4431 struct frame
*emacsframe
= SELECTED_FRAME
();
4436 emacs_event
->kind
= NS_NONKEY_EVENT
;
4437 emacs_event
->code
= KEY_NS_POWER_OFF
;
4438 emacs_event
->arg
= Qt
; /* mark as non-key event */
4439 EV_TRAILER
((id
)nil
);
4443 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4447 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4448 return NSTerminateNow
;
4450 ret
= NSRunAlertPanel
(ns_app_name
,
4451 @"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
,
4452 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4454 if (ret
== NSAlertDefaultReturn
)
4455 return NSTerminateNow
;
4456 else if (ret
== NSAlertAlternateReturn
)
4457 return NSTerminateCancel
;
4458 return NSTerminateNow
; /* just in case */
4462 not_in_argv
(NSString
*arg
)
4465 const
char *a
= [arg UTF8String
];
4466 for (k
= 1; k
< initial_argc
; ++k
)
4467 if (strcmp (a
, initial_argv
[k
]) == 0) return 0;
4471 /* Notification from the Workspace to open a file */
4472 - (BOOL
)application
: sender openFile
: (NSString
*)file
4474 if (ns_do_open_file || not_in_argv
(file
))
4475 [ns_pending_files addObject
: file
];
4480 /* Open a file as a temporary file */
4481 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4483 if (ns_do_open_file || not_in_argv
(file
))
4484 [ns_pending_files addObject
: file
];
4489 /* Notification from the Workspace to open a file noninteractively (?) */
4490 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4492 if (ns_do_open_file || not_in_argv
(file
))
4493 [ns_pending_files addObject
: file
];
4497 /* Notification from the Workspace to open multiple files */
4498 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4500 NSEnumerator
*files
= [fileList objectEnumerator
];
4502 /* Don't open files from the command line unconditionally,
4503 Cocoa parses the command line wrong, --option value tries to open value
4504 if --option is the last option. */
4505 while ((file
= [files nextObject
]) != nil
)
4506 if (ns_do_open_file || not_in_argv
(file
))
4507 [ns_pending_files addObject
: file
];
4509 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4514 /* Handle dock menu requests. */
4515 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4521 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4522 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4524 //ns_app_active
=YES
;
4526 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4528 NSTRACE
(applicationDidBecomeActive
);
4530 //ns_app_active
=YES
;
4532 ns_update_auto_hide_menu_bar
();
4533 // No constraining takes place when the application is not active.
4534 ns_constrain_all_frames
();
4536 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4539 ns_send_appdefined
(-1);
4544 /* ==========================================================================
4546 EmacsApp aux handlers for managing event loop
4548 ========================================================================== */
4551 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4552 /* --------------------------------------------------------------------------
4553 The timeout specified to ns_select has passed.
4554 -------------------------------------------------------------------------- */
4556 /*NSTRACE (timeout_handler); */
4557 ns_send_appdefined
(-2);
4560 - (void
)fd_handler
:(id
)unused
4561 /* --------------------------------------------------------------------------
4562 Check data waiting on file descriptors and terminate if so
4563 -------------------------------------------------------------------------- */
4566 int waiting
= 1, nfds
;
4569 SELECT_TYPE readfds
, writefds
, *wfds
;
4570 EMACS_TIME timeout
, *tmo
;
4571 NSAutoreleasePool
*pool
= nil
;
4573 /* NSTRACE (fd_handler); */
4578 pool
= [[NSAutoreleasePool alloc
] init
];
4584 FD_SET
(selfds
[0], &fds
);
4585 result
= select
(selfds
[0]+1, &fds
, NULL, NULL, NULL);
4586 if (result
> 0 && read
(selfds
[0], &c
, 1) == 1 && c
== 'g')
4591 pthread_mutex_lock
(&select_mutex
);
4594 if (select_valid
& SELECT_HAVE_READ
)
4595 readfds
= select_readfds
;
4599 if (select_valid
& SELECT_HAVE_WRITE
)
4601 writefds
= select_writefds
;
4606 if (select_valid
& SELECT_HAVE_TMO
)
4608 timeout
= select_timeout
;
4614 pthread_mutex_unlock
(&select_mutex
);
4616 FD_SET
(selfds
[0], &readfds
);
4617 if (selfds
[0] >= nfds
) nfds
= selfds
[0]+1;
4619 result
= pselect
(nfds
, &readfds
, wfds
, NULL, tmo
, NULL);
4622 ns_send_appdefined
(-2);
4623 else if (result
> 0)
4625 if (FD_ISSET
(selfds
[0], &readfds
))
4627 if (read
(selfds
[0], &c
, 1) == 1 && c
== 's')
4632 pthread_mutex_lock
(&select_mutex
);
4633 if (select_valid
& SELECT_HAVE_READ
)
4634 select_readfds
= readfds
;
4635 if (select_valid
& SELECT_HAVE_WRITE
)
4636 select_writefds
= writefds
;
4637 if (select_valid
& SELECT_HAVE_TMO
)
4638 select_timeout
= timeout
;
4639 pthread_mutex_unlock
(&select_mutex
);
4641 ns_send_appdefined
(result
);
4651 /* ==========================================================================
4655 ========================================================================== */
4657 /* called from system: queue for next pass through event loop */
4658 - (void
)requestService
: (NSPasteboard
*)pboard
4659 userData
: (NSString
*)userData
4660 error: (NSString
**)error
4662 [ns_pending_service_names addObject
: userData
];
4663 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4664 SSDATA
(ns_string_from_pasteboard
(pboard
))]];
4668 /* called from ns_read_socket to clear queue */
4669 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4671 struct frame
*emacsframe
= SELECTED_FRAME
();
4672 NSEvent
*theEvent
= [NSApp currentEvent
];
4677 emacs_event
->kind
= NS_NONKEY_EVENT
;
4678 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4679 ns_input_spi_name
= build_string
([name UTF8String
]);
4680 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4681 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4682 EV_TRAILER
(theEvent
);
4692 /* ==========================================================================
4694 EmacsView implementation
4696 ========================================================================== */
4699 @implementation EmacsView
4701 /* needed to inform when window closed from LISP */
4702 - (void
) setWindowClosing
: (BOOL
)closing
4704 windowClosing
= closing
;
4710 NSTRACE
(EmacsView_dealloc
);
4712 if (fs_state
== FULLSCREEN_BOTH
)
4713 [nonfs_window release
];
4718 /* called on font panel selection */
4719 - (void
)changeFont
: (id
)sender
4721 NSEvent
*e
=[[self window
] currentEvent
];
4722 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4726 NSTRACE
(changeFont
);
4730 if ((newFont
= [sender convertFont
:
4731 ((struct nsfont_info
*)face
->font
)->nsfont
]))
4733 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4735 emacs_event
->kind
= NS_NONKEY_EVENT
;
4736 emacs_event
->modifiers
= 0;
4737 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4739 size = [newFont pointSize
];
4740 ns_input_fontsize
= make_number
(lrint
(size));
4741 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4747 - (BOOL
)acceptsFirstResponder
4749 NSTRACE
(acceptsFirstResponder
);
4754 - (void
)resetCursorRects
4756 NSRect visible
= [self visibleRect
];
4757 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4758 NSTRACE
(resetCursorRects
);
4760 if (currentCursor
== nil
)
4761 currentCursor
= [NSCursor arrowCursor
];
4763 if (!NSIsEmptyRect
(visible
))
4764 [self addCursorRect
: visible cursor
: currentCursor
];
4765 [currentCursor setOnMouseEntered
: YES
];
4770 /*****************************************************************************/
4771 /* Keyboard handling. */
4774 - (void
)keyDown
: (NSEvent
*)theEvent
4776 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
4778 unsigned fnKeysym
= 0;
4779 static NSMutableArray
*nsEvArray
;
4780 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4781 static BOOL firstTime
= YES
;
4784 unsigned int flags
= [theEvent modifierFlags
];
4788 /* Rhapsody and OS X give up and down events for the arrow keys */
4789 if (ns_fake_keydown
== YES
)
4790 ns_fake_keydown
= NO
;
4791 else if ([theEvent
type] != NSKeyDown
)
4797 if (![[self window
] isKeyWindow
]
4798 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4799 /* we must avoid an infinite loop here. */
4800 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4802 /* XXX: There is an occasional condition in which, when Emacs display
4803 updates a different frame from the current one, and temporarily
4804 selects it, then processes some interrupt-driven input
4805 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4806 for some reason that window has its first responder set to the NSView
4807 most recently updated (I guess), which is not the correct one. */
4808 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4812 if (nsEvArray
== nil
)
4813 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4815 [NSCursor setHiddenUntilMouseMoves
: YES
];
4817 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4819 clear_mouse_face
(hlinfo
);
4820 hlinfo
->mouse_face_hidden
= 1;
4823 if (!processingCompose
)
4825 /* When using screen sharing, no left or right information is sent,
4826 so use Left key in those cases. */
4827 int is_left_key
, is_right_key
;
4829 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4830 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4832 /* (Carbon way: [theEvent keyCode]) */
4834 /* is it a "function key"? */
4835 fnKeysym
= (code
< 0x00ff && (flags
&NSNumericPadKeyMask
))
4836 ? ns_convert_key
([theEvent keyCode
] | NSNumericPadKeyMask
)
4837 : ns_convert_key
(code
);
4841 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4842 because Emacs treats Delete and KP-Delete same (in simple.el). */
4843 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4844 code
= 0xFF08; /* backspace */
4849 /* are there modifiers? */
4850 emacs_event
->modifiers
= 0;
4852 if (flags
& NSHelpKeyMask
)
4853 emacs_event
->modifiers |
= hyper_modifier
;
4855 if (flags
& NSShiftKeyMask
)
4856 emacs_event
->modifiers |
= shift_modifier
;
4858 is_right_key
= (flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
;
4859 is_left_key
= (flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
4860 ||
(! is_right_key
&& (flags
& NSCommandKeyMask
) == NSCommandKeyMask
);
4863 emacs_event
->modifiers |
= parse_solitary_modifier
4864 (EQ
(ns_right_command_modifier
, Qleft
)
4865 ? ns_command_modifier
4866 : ns_right_command_modifier
);
4870 emacs_event
->modifiers |
= parse_solitary_modifier
4871 (ns_command_modifier
);
4873 /* if super (default), take input manager's word so things like
4874 dvorak / qwerty layout work */
4875 if (EQ
(ns_command_modifier
, Qsuper
)
4877 && [[theEvent characters
] length] != 0)
4879 /* XXX: the code we get will be unshifted, so if we have
4880 a shift modifier, must convert ourselves */
4881 if (!(flags
& NSShiftKeyMask
))
4882 code
= [[theEvent characters
] characterAtIndex
: 0];
4884 /* this is ugly and also requires linking w/Carbon framework
4885 (for LMGetKbdType) so for now leave this rare (?) case
4886 undealt with.. in future look into CGEvent methods */
4889 long smv
= GetScriptManagerVariable
(smKeyScript
);
4890 Handle uchrHandle
= GetResource
4891 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4893 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4894 [[theEvent characters
] characterAtIndex
: 0],
4895 kUCKeyActionDisplay
,
4896 (flags
& ~NSCommandKeyMask
) >> 8,
4897 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4898 &dummy
, 1, &dummy
, &code
);
4905 is_right_key
= (flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
;
4906 is_left_key
= (flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
4907 ||
(! is_right_key
&& (flags
& NSControlKeyMask
) == NSControlKeyMask
);
4910 emacs_event
->modifiers |
= parse_solitary_modifier
4911 (EQ
(ns_right_control_modifier
, Qleft
)
4912 ? ns_control_modifier
4913 : ns_right_control_modifier
);
4916 emacs_event
->modifiers |
= parse_solitary_modifier
4917 (ns_control_modifier
);
4919 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4920 emacs_event
->modifiers |
=
4921 parse_solitary_modifier
(ns_function_modifier
);
4923 left_is_none
= NILP
(ns_alternate_modifier
)
4924 || EQ
(ns_alternate_modifier
, Qnone
);
4926 is_right_key
= (flags
& NSRightAlternateKeyMask
)
4927 == NSRightAlternateKeyMask
;
4928 is_left_key
= (flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
4930 && (flags
& NSAlternateKeyMask
) == NSAlternateKeyMask
);
4934 if ((NILP
(ns_right_alternate_modifier
)
4935 || EQ
(ns_right_alternate_modifier
, Qnone
)
4936 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
4938 { /* accept pre-interp alt comb */
4939 if ([[theEvent characters
] length] > 0)
4940 code
= [[theEvent characters
] characterAtIndex
: 0];
4941 /*HACK: clear lone shift modifier to stop next if from firing */
4942 if (emacs_event
->modifiers
== shift_modifier
)
4943 emacs_event
->modifiers
= 0;
4946 emacs_event
->modifiers |
= parse_solitary_modifier
4947 (EQ
(ns_right_alternate_modifier
, Qleft
)
4948 ? ns_alternate_modifier
4949 : ns_right_alternate_modifier
);
4952 if (is_left_key
) /* default = meta */
4954 if (left_is_none
&& !fnKeysym
)
4955 { /* accept pre-interp alt comb */
4956 if ([[theEvent characters
] length] > 0)
4957 code
= [[theEvent characters
] characterAtIndex
: 0];
4958 /*HACK: clear lone shift modifier to stop next if from firing */
4959 if (emacs_event
->modifiers
== shift_modifier
)
4960 emacs_event
->modifiers
= 0;
4963 emacs_event
->modifiers |
=
4964 parse_solitary_modifier
(ns_alternate_modifier
);
4968 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4969 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4971 /* if it was a function key or had modifiers, pass it directly to emacs */
4972 if (fnKeysym ||
(emacs_event
->modifiers
4973 && (emacs_event
->modifiers
!= shift_modifier
)
4974 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4975 /*[[theEvent characters] length] */
4977 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4979 code |
= (1<<28)|
(3<<16);
4980 else if (code
== 0x7f)
4981 code |
= (1<<28)|
(3<<16);
4983 emacs_event
->kind
= code
> 0xFF
4984 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4986 emacs_event
->code
= code
;
4987 EV_TRAILER
(theEvent
);
4993 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4994 /* if we get here we should send the key for input manager processing */
4995 if (firstTime
&& [[NSInputManager currentInputManager
]
4996 wantsToDelayTextChangeNotifications
] == NO
)
4998 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
5001 if (NS_KEYLOG
&& !processingCompose
)
5002 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
5004 processingCompose
= YES
;
5005 [nsEvArray addObject
: theEvent
];
5006 [self interpretKeyEvents
: nsEvArray
];
5007 [nsEvArray removeObject
: theEvent
];
5011 #ifdef NS_IMPL_COCOA
5012 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
5013 decided not to send key-down for.
5014 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
5015 This only applies on Tiger and earlier.
5016 If it matches one of these, send it on to keyDown. */
5017 -(void
)keyUp
: (NSEvent
*)theEvent
5019 int flags
= [theEvent modifierFlags
];
5020 int code
= [theEvent keyCode
];
5021 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
5022 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
5025 fprintf (stderr
, "keyUp
: passed test"
);
5026 ns_fake_keydown
= YES
;
5027 [self keyDown
: theEvent
];
5033 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
5036 /* <NSTextInput>: called when done composing;
5037 NOTE: also called when we delete over working text, followed immed.
5038 by doCommandBySelector: deleteBackward: */
5039 - (void
)insertText
: (id
)aString
5042 int len
= [(NSString
*)aString
length];
5046 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
5047 processingCompose
= NO
;
5052 /* first, clear any working text */
5053 if (workingText
!= nil
)
5054 [self deleteWorkingText
];
5056 /* now insert the string as keystrokes */
5057 for (i
=0; i
<len
; i
++)
5059 code
= [aString characterAtIndex
: i
];
5060 /* TODO: still need this? */
5062 code
= '~'; /* 0x7E */
5063 if (code
!= 32) /* Space */
5064 emacs_event
->modifiers
= 0;
5066 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
5067 emacs_event
->code
= code
;
5068 EV_TRAILER
((id
)nil
);
5073 /* <NSTextInput>: inserts display of composing characters */
5074 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
5076 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
5077 [aString string
] : aString
;
5079 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
5080 selRange.
length, selRange.location
);
5082 if (workingText
!= nil
)
5083 [self deleteWorkingText
];
5084 if ([str
length] == 0)
5090 processingCompose
= YES
;
5091 workingText
= [str copy
];
5092 ns_working_text
= build_string
([workingText UTF8String
]);
5094 emacs_event
->kind
= NS_TEXT_EVENT
;
5095 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
5096 EV_TRAILER
((id
)nil
);
5100 /* delete display of composing characters [not in <NSTextInput>] */
5101 - (void
)deleteWorkingText
5103 if (workingText
== nil
)
5106 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
5107 [workingText release
];
5109 processingCompose
= NO
;
5114 emacs_event
->kind
= NS_TEXT_EVENT
;
5115 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5116 EV_TRAILER
((id
)nil
);
5120 - (BOOL
)hasMarkedText
5122 return workingText
!= nil
;
5126 - (NSRange
)markedRange
5128 NSRange rng
= workingText
!= nil
5129 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5131 NSLog
(@"markedRange request"
);
5139 NSLog
(@"unmark
(accept
) text"
);
5140 [self deleteWorkingText
];
5141 processingCompose
= NO
;
5145 /* used to position char selection windows, etc. */
5146 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5150 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5152 NSLog
(@"firstRectForCharRange request"
);
5154 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5155 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5156 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5157 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5158 +FRAME_LINE_HEIGHT
(emacsframe
));
5160 pt
= [self convertPoint
: pt toView
: nil
];
5161 pt
= [[self window
] convertBaseToScreen
: pt
];
5167 - (NSInteger
)conversationIdentifier
5169 return (NSInteger
)self
;
5173 - (void
)doCommandBySelector
: (SEL
)aSelector
5176 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5178 if (aSelector
== @selector
(deleteBackward
:))
5180 /* happens when user backspaces over an ongoing composition:
5181 throw a 'delete' into the event queue */
5184 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5185 emacs_event
->code
= 0xFF08;
5186 EV_TRAILER
((id
)nil
);
5190 - (NSArray
*)validAttributesForMarkedText
5192 static NSArray
*arr
= nil
;
5193 if (arr
== nil
) arr
= [NSArray new
];
5194 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5198 - (NSRange
)selectedRange
5201 NSLog
(@"selectedRange request"
);
5202 return NSMakeRange
(NSNotFound
, 0);
5205 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5208 NSLog
(@"characterIndexForPoint request"
);
5212 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5214 static NSAttributedString
*str
= nil
;
5215 if (str
== nil
) str
= [NSAttributedString new
];
5217 NSLog
(@"attributedSubstringFromRange request"
);
5221 /* End <NSTextInput> impl. */
5222 /*****************************************************************************/
5225 /* This is what happens when the user presses a mouse button. */
5226 - (void
)mouseDown
: (NSEvent
*)theEvent
5228 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5230 NSTRACE
(mouseDown
);
5232 [self deleteWorkingText
];
5237 last_mouse_frame
= emacsframe
;
5238 /* appears to be needed to prevent spurious movement events generated on
5240 last_mouse_frame
->mouse_moved
= 0;
5242 if ([theEvent
type] == NSScrollWheel
)
5244 float delta
= [theEvent deltaY
];
5245 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5248 emacs_event
->kind
= WHEEL_EVENT
;
5249 emacs_event
->code
= 0;
5250 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5251 ((delta
> 0) ? up_modifier
: down_modifier
);
5255 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5256 emacs_event
->code
= EV_BUTTON
(theEvent
);
5257 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5258 | EV_UDMODIFIERS
(theEvent
);
5260 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5261 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5262 EV_TRAILER
(theEvent
);
5266 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5268 NSTRACE
(rightMouseDown
);
5269 [self mouseDown
: theEvent
];
5273 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5275 NSTRACE
(otherMouseDown
);
5276 [self mouseDown
: theEvent
];
5280 - (void
)mouseUp
: (NSEvent
*)theEvent
5283 [self mouseDown
: theEvent
];
5287 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5289 NSTRACE
(rightMouseUp
);
5290 [self mouseDown
: theEvent
];
5294 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5296 NSTRACE
(otherMouseUp
);
5297 [self mouseDown
: theEvent
];
5301 - (void
) scrollWheel
: (NSEvent
*)theEvent
5303 NSTRACE
(scrollWheel
);
5304 [self mouseDown
: theEvent
];
5308 /* Tell emacs the mouse has moved. */
5309 - (void
)mouseMoved
: (NSEvent
*)e
5311 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5314 // NSTRACE
(mouseMoved
);
5316 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5317 last_mouse_motion_position
5318 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5320 /* update any mouse face */
5321 if (hlinfo
->mouse_face_hidden
)
5323 hlinfo
->mouse_face_hidden
= 0;
5324 clear_mouse_face
(hlinfo
);
5327 /* tooltip handling */
5328 previous_help_echo_string
= help_echo_string
;
5329 help_echo_string
= Qnil
;
5331 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
5332 last_mouse_motion_position.y
))
5333 help_echo_string
= previous_help_echo_string
;
5335 XSETFRAME
(frame
, emacsframe
);
5336 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5338 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5339 (note_mouse_highlight), which is called through the
5340 note_mouse_movement () call above */
5341 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5342 help_echo_object
, help_echo_pos
);
5346 help_echo_string
= Qnil
;
5347 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5350 if (emacsframe
->mouse_moved
&& send_appdefined
)
5351 ns_send_appdefined
(-1);
5355 - (void
)mouseDragged
: (NSEvent
*)e
5357 NSTRACE
(mouseDragged
);
5358 [self mouseMoved
: e
];
5362 - (void
)rightMouseDragged
: (NSEvent
*)e
5364 NSTRACE
(rightMouseDragged
);
5365 [self mouseMoved
: e
];
5369 - (void
)otherMouseDragged
: (NSEvent
*)e
5371 NSTRACE
(otherMouseDragged
);
5372 [self mouseMoved
: e
];
5376 - (BOOL
)windowShouldClose
: (id
)sender
5378 NSEvent
*e
=[[self window
] currentEvent
];
5380 NSTRACE
(windowShouldClose
);
5381 windowClosing
= YES
;
5384 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5385 emacs_event
->modifiers
= 0;
5386 emacs_event
->code
= 0;
5388 /* Don't close this window, let this be done from lisp code. */
5392 - (void
) updateFrameSize
: (BOOL
) delay
;
5394 NSWindow
*window
= [self window
];
5395 NSRect wr
= [window frame
];
5396 #ifdef NS_IMPL_GNUSTEP
5402 int oldc
= cols
, oldr
= rows
;
5403 int oldw
= FRAME_PIXEL_WIDTH
(emacsframe
),
5404 oldh
= FRAME_PIXEL_HEIGHT
(emacsframe
);
5407 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
, wr.
size.width
+ extra
);
5409 if (cols
< MINWIDTH
)
5412 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
5413 (emacsframe
, wr.
size.height
5414 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + extra
5415 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5417 if (rows
< MINHEIGHT
)
5420 neww
= (int
)wr.
size.width
- emacsframe
->border_width
;
5421 newh
= ((int
)wr.
size.height
5422 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5423 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5425 if (oldr
!= rows || oldc
!= cols || neww
!= oldw || newh
!= oldh
)
5427 NSView
*view = FRAME_NS_VIEW
(emacsframe
);
5428 FRAME_PIXEL_WIDTH
(emacsframe
) = neww
;
5429 FRAME_PIXEL_HEIGHT
(emacsframe
) = newh
;
5430 change_frame_size
(emacsframe
, rows
, cols
, 0, delay
, 0);
5431 SET_FRAME_GARBAGED
(emacsframe
);
5432 cancel_mouse_face
(emacsframe
);
5433 [view setFrame
: NSMakeRect
(0, 0, neww
, newh
)];
5434 [self windowDidMove
:nil
]; // Update top
/left.
5438 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5439 /* normalize frame to gridded text size */
5441 NSTRACE
(windowWillResize
);
5442 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5444 if (fs_state
== FULLSCREEN_MAXIMIZED
5445 && (maximized_width
!= (int
)frameSize.width
5446 || maximized_height
!= (int
)frameSize.height
))
5447 [self setFSValue
: FULLSCREEN_NONE
];
5448 else if (fs_state
== FULLSCREEN_WIDTH
5449 && maximized_width
!= (int
)frameSize.width
)
5450 [self setFSValue
: FULLSCREEN_NONE
];
5451 else if (fs_state
== FULLSCREEN_HEIGHT
5452 && maximized_height
!= (int
)frameSize.height
)
5453 [self setFSValue
: FULLSCREEN_NONE
];
5454 if (fs_state
== FULLSCREEN_NONE
)
5455 maximized_width
= maximized_height
= -1;
5457 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5458 #ifdef NS_IMPL_GNUSTEP
5459 frameSize.width
+ 3);
5463 if (cols
< MINWIDTH
)
5466 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5467 #ifdef NS_IMPL_GNUSTEP
5468 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5469 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5471 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5472 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5474 if (rows
< MINHEIGHT
)
5476 #ifdef NS_IMPL_COCOA
5478 /* this sets window title to have size in it; the wm does this under GS */
5479 NSRect r
= [[self window
] frame
];
5480 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5491 NSWindow
*window
= [self window
];
5494 const
char *t
= [[[self window
] title] UTF8String
];
5495 char *pos
= strstr
(t
, " — "
);
5498 old_title
= xstrdup
(t
);
5500 size_title
= xmalloc
(strlen
(old_title
) + 40);
5501 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5502 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5507 #endif
/* NS_IMPL_COCOA */
5508 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5514 - (void
)windowDidResize
: (NSNotification
*)notification
5517 #
if !defined
(NEW_STYLE_FS
) && ! defined
(NS_IMPL_GNUSTEP
)
5518 NSWindow
*theWindow
= [notification object
];
5519 /* We can get notification on the non-FS window when in fullscreen mode. */
5520 if ([self window
] != theWindow
) return;
5523 #ifdef NS_IMPL_GNUSTEP
5524 NSWindow
*theWindow
= [notification object
];
5526 /* In GNUstep, at least currently, it's possible to get a didResize
5527 without getting a willResize.. therefore we need to act as if we got
5528 the willResize now */
5529 NSSize sz
= [theWindow frame
].
size;
5530 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5531 #endif
/* NS_IMPL_GNUSTEP */
5533 NSTRACE
(windowDidResize
);
5534 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5536 #ifdef NS_IMPL_COCOA
5542 #endif
/* NS_IMPL_COCOA */
5544 if (cols
> 0 && rows
> 0)
5546 [self updateFrameSize
: YES
];
5549 ns_send_appdefined
(-1);
5553 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5554 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5556 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5557 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5559 NSTRACE
(windowDidBecomeKey
);
5561 if (emacsframe
!= old_focus
)
5562 dpyinfo
->x_focus_frame
= emacsframe
;
5564 ns_frame_rehighlight
(emacsframe
);
5568 emacs_event
->kind
= FOCUS_IN_EVENT
;
5569 EV_TRAILER
((id
)nil
);
5574 - (void
)windowDidResignKey
: (NSNotification
*)notification
5575 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5577 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5578 NSTRACE
(windowDidResignKey
);
5580 if (dpyinfo
->x_focus_frame
== emacsframe
)
5581 dpyinfo
->x_focus_frame
= 0;
5583 ns_frame_rehighlight
(emacsframe
);
5585 /* FIXME: for some reason needed on second and subsequent clicks away
5586 from sole-frame Emacs to get hollow box to show */
5587 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5589 x_update_cursor
(emacsframe
, 1);
5590 x_set_frame_alpha
(emacsframe
);
5595 [self deleteWorkingText
];
5596 emacs_event
->kind
= FOCUS_IN_EVENT
;
5597 EV_TRAILER
((id
)nil
);
5602 - (void
)windowWillMiniaturize
: sender
5604 NSTRACE
(windowWillMiniaturize
);
5620 - initFrameFromEmacs
: (struct frame
*)f
5625 NSButton
*toggleButton
;
5630 NSTRACE
(initFrameFromEmacs
);
5633 processingCompose
= NO
;
5634 scrollbarsNeedingUpdate
= 0;
5635 fs_state
= FULLSCREEN_NONE
;
5636 fs_before_fs
= next_maximized
= -1;
5637 maximized_width
= maximized_height
= -1;
5640 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5642 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5643 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5644 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5645 [self initWithFrame
: r
];
5646 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5648 FRAME_NS_VIEW
(f
) = self
;
5652 win
= [[EmacsWindow alloc
]
5653 initWithContentRect
: r
5654 styleMask
: (NSResizableWindowMask |
5655 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5656 NSTitledWindowMask |
5658 NSMiniaturizableWindowMask |
5659 NSClosableWindowMask
)
5660 backing
: NSBackingStoreBuffered
5664 [win setCollectionBehavior
:NSWindowCollectionBehaviorFullScreenPrimary
];
5668 bwidth
= f
->border_width
= wr.
size.width
- r.
size.width
;
5669 tibar_height
= FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
5671 [win setAcceptsMouseMovedEvents
: YES
];
5672 [win setDelegate
: self
];
5673 [win useOptimizedDrawing
: YES
];
5675 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5676 sz.height
= FRAME_LINE_HEIGHT
(f
);
5677 [win setResizeIncrements
: sz
];
5679 [[win contentView
] addSubview
: self
];
5682 [self registerForDraggedTypes
: ns_drag_types
];
5685 name
= [NSString stringWithUTF8String
:
5686 NILP
(tem
) ? "Emacs"
: SSDATA
(tem
)];
5687 [win setTitle
: name
];
5689 /* toolbar support */
5690 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
5691 [NSString stringWithFormat
: @"Emacs Frame
%d",
5693 [win setToolbar
: toolbar
];
5694 [toolbar setVisible
: NO
];
5695 #ifdef NS_IMPL_COCOA
5696 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
5697 [toggleButton setTarget
: self
];
5698 [toggleButton setAction
: @selector
(toggleToolbar
: )];
5700 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5704 [win setMiniwindowTitle
:
5705 [NSString stringWithUTF8String
: SSDATA
(tem
)]];
5708 NSScreen
*screen
= [win screen
];
5711 [win setFrameTopLeftPoint
: NSMakePoint
5712 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
5713 IN_BOUND
(-SCREENMAX
,
5714 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
5717 [win makeFirstResponder
: self
];
5719 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5720 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
5721 [win setBackgroundColor
: col
];
5722 if ([col alphaComponent
] != 1.0)
5723 [win setOpaque
: NO
];
5725 [self allocateGState
];
5727 [NSApp registerServicesMenuSendTypes
: ns_send_types
5735 - (void
)windowDidMove
: sender
5737 NSWindow
*win
= [self window
];
5738 NSRect r
= [win frame
];
5739 NSArray
*screens
= [NSScreen screens
];
5740 NSScreen
*screen
= [screens objectAtIndex
: 0];
5742 NSTRACE
(windowDidMove
);
5744 if (!emacsframe
->output_data.ns
)
5748 emacsframe
->left_pos
= r.origin.x
;
5749 emacsframe
->top_pos
=
5750 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
5755 /* Called AFTER method below, but before our windowWillResize call there leads
5756 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
5757 location so set_window_size moves the frame. */
5758 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5760 emacsframe
->output_data.ns
->zooming
= 1;
5765 /* Override to do something slightly nonstandard, but nice. First click on
5766 zoom button will zoom vertically. Second will zoom completely. Third
5767 returns to original. */
5768 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5769 defaultFrame
:(NSRect
)defaultFrame
5771 NSRect result
= [sender frame
];
5773 NSTRACE
(windowWillUseStandardFrame
);
5775 if (fs_before_fs
!= -1) /* Entering fullscreen */
5777 result
= defaultFrame
;
5779 else if (next_maximized
== FULLSCREEN_HEIGHT
5780 ||
(next_maximized
== -1
5781 && abs (defaultFrame.
size.height
- result.
size.height
)
5782 > FRAME_LINE_HEIGHT
(emacsframe
)))
5785 ns_userRect
= result
;
5786 maximized_height
= result.
size.height
= defaultFrame.
size.height
;
5787 maximized_width
= -1;
5788 result.origin.y
= defaultFrame.origin.y
;
5789 [self setFSValue
: FULLSCREEN_HEIGHT
];
5791 else if (next_maximized
== FULLSCREEN_WIDTH
)
5793 ns_userRect
= result
;
5794 maximized_width
= result.
size.width
= defaultFrame.
size.width
;
5795 maximized_height
= -1;
5796 result.origin.x
= defaultFrame.origin.x
;
5797 [self setFSValue
: FULLSCREEN_WIDTH
];
5799 else if (next_maximized
== FULLSCREEN_MAXIMIZED
5800 ||
(next_maximized
== -1
5801 && abs (defaultFrame.
size.width
- result.
size.width
)
5802 > FRAME_COLUMN_WIDTH
(emacsframe
)))
5804 result
= defaultFrame
; /* second click */
5805 maximized_width
= result.
size.width
;
5806 maximized_height
= result.
size.height
;
5807 [self setFSValue
: FULLSCREEN_MAXIMIZED
];
5812 result
= ns_userRect.
size.height ? ns_userRect
: result
;
5813 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5814 [self setFSValue
: FULLSCREEN_NONE
];
5815 maximized_width
= maximized_width
= -1;
5818 if (fs_before_fs
== -1) next_maximized
= -1;
5819 [self windowWillResize
: sender toSize
: result.
size];
5824 - (void
)windowDidDeminiaturize
: sender
5826 NSTRACE
(windowDidDeminiaturize
);
5827 if (!emacsframe
->output_data.ns
)
5829 emacsframe
->async_iconified
= 0;
5830 emacsframe
->async_visible
= 1;
5831 windows_or_buffers_changed
++;
5835 emacs_event
->kind
= ICONIFY_EVENT
;
5836 EV_TRAILER
((id
)nil
);
5841 - (void
)windowDidExpose
: sender
5843 NSTRACE
(windowDidExpose
);
5844 if (!emacsframe
->output_data.ns
)
5846 emacsframe
->async_visible
= 1;
5847 SET_FRAME_GARBAGED
(emacsframe
);
5849 if (send_appdefined
)
5850 ns_send_appdefined
(-1);
5854 - (void
)windowDidMiniaturize
: sender
5856 NSTRACE
(windowDidMiniaturize
);
5857 if (!emacsframe
->output_data.ns
)
5860 emacsframe
->async_iconified
= 1;
5861 emacsframe
->async_visible
= 0;
5865 emacs_event
->kind
= ICONIFY_EVENT
;
5866 EV_TRAILER
((id
)nil
);
5870 - (void
)windowWillEnterFullScreen
:(NSNotification
*)notification
5872 fs_before_fs
= fs_state
;
5875 - (void
)windowDidEnterFullScreen
:(NSNotification
*)notification
5877 [self setFSValue
: FULLSCREEN_BOTH
];
5879 // Fix bad background.
5880 if ([toolbar isVisible
])
5882 [toolbar setVisible
:NO
];
5883 [toolbar setVisible
:YES
];
5886 [self windowDidBecomeKey
:notification
];
5887 [nonfs_window orderOut
:self
];
5891 - (void
)windowWillExitFullScreen
:(NSNotification
*)notification
5893 if (next_maximized
!= -1)
5894 fs_before_fs
= next_maximized
;
5897 - (void
)windowDidExitFullScreen
:(NSNotification
*)notification
5899 [self setFSValue
: fs_before_fs
];
5901 if (next_maximized
!= -1)
5902 [[self window
] performZoom
:self
];
5905 - (void
)toggleFullScreen
: (id
)sender
5908 [[self window
] toggleFullScreen
:sender
];
5910 NSWindow
*w
= [self window
], *fw
;
5911 BOOL onFirstScreen
= [[w screen
]
5912 isEqual:[[NSScreen screens
] objectAtIndex
:0]];
5913 struct frame
*f
= emacsframe
;
5915 NSRect r
, wr
= [w frame
];
5916 NSColor
*col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5917 (FRAME_DEFAULT_FACE
(f
)),
5920 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5921 sz.height
= FRAME_LINE_HEIGHT
(f
);
5923 if (fs_state
!= FULLSCREEN_BOTH
)
5925 /* Hide dock and menubar if we are on the primary screen. */
5928 #
if defined
(NS_IMPL_COCOA
) && \
5929 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
5930 NSApplicationPresentationOptions options
5931 = NSApplicationPresentationAutoHideDock
5932 | NSApplicationPresentationAutoHideMenuBar
;
5934 [NSApp setPresentationOptions
: options
];
5936 [NSMenu setMenuBarVisible
:NO
];
5940 fw
= [[EmacsFSWindow alloc
]
5941 initWithContentRect
:[w contentRectForFrameRect
:wr
]
5942 styleMask
:NSBorderlessWindowMask
5943 backing
:NSBackingStoreBuffered
5947 [fw setContentView
:[w contentView
]];
5948 [fw setTitle
:[w
title]];
5949 [fw setDelegate
:self
];
5950 [fw setAcceptsMouseMovedEvents
: YES
];
5951 [fw useOptimizedDrawing
: YES
];
5952 [fw setResizeIncrements
: sz
];
5953 [fw setBackgroundColor
: col
];
5954 if ([col alphaComponent
] != 1.0)
5957 f
->border_width
= 0;
5958 FRAME_NS_TITLEBAR_HEIGHT
(f
) = 0;
5959 tobar_height
= FRAME_TOOLBAR_HEIGHT
(f
);
5960 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5961 FRAME_EXTERNAL_TOOL_BAR
(f
) = 0;
5965 [self windowWillEnterFullScreen
:nil
];
5966 [fw makeKeyAndOrderFront
:NSApp
];
5967 [fw makeFirstResponder
:self
];
5969 r
= [fw frameRectForContentRect
:[[fw screen
] frame
]];
5970 [fw setFrame
: r display
:YES animate
:YES
];
5971 [self windowDidEnterFullScreen
:nil
];
5982 #
if defined
(NS_IMPL_COCOA
) && \
5983 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
5984 [NSApp setPresentationOptions
: NSApplicationPresentationDefault
];
5986 [NSMenu setMenuBarVisible
:YES
];
5990 [w setContentView
:[fw contentView
]];
5991 [w setResizeIncrements
: sz
];
5992 [w setBackgroundColor
: col
];
5993 if ([col alphaComponent
] != 1.0)
5996 f
->border_width
= bwidth
;
5997 FRAME_NS_TITLEBAR_HEIGHT
(f
) = tibar_height
;
5998 FRAME_TOOLBAR_HEIGHT
(f
) = tobar_height
;
6000 FRAME_EXTERNAL_TOOL_BAR
(f
) = 1;
6002 [self windowWillExitFullScreen
:nil
];
6003 [fw setFrame
: [w frame
] display
:YES animate
:YES
];
6005 [w makeKeyAndOrderFront
:NSApp
];
6006 [self windowDidExitFullScreen
:nil
];
6013 if (fs_state
!= emacsframe
->want_fullscreen
)
6015 if (fs_state
== FULLSCREEN_BOTH
)
6017 [self toggleFullScreen
:self
];
6020 switch (emacsframe
->want_fullscreen
)
6022 case FULLSCREEN_BOTH
:
6023 [self toggleFullScreen
:self
];
6025 case FULLSCREEN_WIDTH
:
6026 next_maximized
= FULLSCREEN_WIDTH
;
6027 if (fs_state
!= FULLSCREEN_BOTH
)
6028 [[self window
] performZoom
:self
];
6030 case FULLSCREEN_HEIGHT
:
6031 next_maximized
= FULLSCREEN_HEIGHT
;
6032 if (fs_state
!= FULLSCREEN_BOTH
)
6033 [[self window
] performZoom
:self
];
6035 case FULLSCREEN_MAXIMIZED
:
6036 next_maximized
= FULLSCREEN_MAXIMIZED
;
6037 if (fs_state
!= FULLSCREEN_BOTH
)
6038 [[self window
] performZoom
:self
];
6040 case FULLSCREEN_NONE
:
6041 if (fs_state
!= FULLSCREEN_BOTH
)
6043 next_maximized
= FULLSCREEN_NONE
;
6044 [[self window
] performZoom
:self
];
6049 emacsframe
->want_fullscreen
= FULLSCREEN_NONE
;
6054 - (void
) setFSValue
: (int
)value
6056 Lisp_Object lval
= Qnil
;
6059 case FULLSCREEN_BOTH
:
6062 case FULLSCREEN_WIDTH
:
6065 case FULLSCREEN_HEIGHT
:
6068 case FULLSCREEN_MAXIMIZED
:
6072 store_frame_param
(emacsframe
, Qfullscreen
, lval
);
6076 - (void
)mouseEntered
: (NSEvent
*)theEvent
6078 NSTRACE
(mouseEntered
);
6079 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
6083 - (void
)mouseExited
: (NSEvent
*)theEvent
6085 Mouse_HLInfo
*hlinfo
= emacsframe ? MOUSE_HL_INFO
(emacsframe
) : NULL;
6087 NSTRACE
(mouseExited
);
6092 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
6094 if (emacsframe
== hlinfo
->mouse_face_mouse_frame
)
6096 clear_mouse_face
(hlinfo
);
6097 hlinfo
->mouse_face_mouse_frame
= 0;
6105 if (context_menu_value
== -1)
6106 context_menu_value
= [sender tag
];
6109 NSInteger tag
= [sender tag
];
6110 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
6111 emacsframe
->menu_bar_vector
,
6115 ns_send_appdefined
(-1);
6120 - (EmacsToolbar
*)toolbar
6126 /* this gets called on toolbar button click */
6127 - toolbarClicked
: (id
)item
6130 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
6132 NSTRACE
(toolbarClicked
);
6137 /* send first event (for some reason two needed) */
6138 theEvent
= [[self window
] currentEvent
];
6139 emacs_event
->kind
= TOOL_BAR_EVENT
;
6140 XSETFRAME
(emacs_event
->arg
, emacsframe
);
6141 EV_TRAILER
(theEvent
);
6143 emacs_event
->kind
= TOOL_BAR_EVENT
;
6144 /* XSETINT (emacs_event->code, 0); */
6145 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
6146 idx
+ TOOL_BAR_ITEM_KEY
);
6147 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6148 EV_TRAILER
(theEvent
);
6153 - toggleToolbar
: (id
)sender
6158 emacs_event
->kind
= NS_NONKEY_EVENT
;
6159 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
6160 EV_TRAILER
((id
)nil
);
6165 - (void
)drawRect
: (NSRect
)rect
6167 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
6168 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
6172 if (!emacsframe ||
!emacsframe
->output_data.ns
)
6175 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
6176 expose_frame
(emacsframe
, x
, y
, width
, height
);
6179 drawRect: may be called (at least in OS X 10.5) for invisible
6180 views as well for some reason. Thus, do not infer visibility
6183 emacsframe->async_visible = 1;
6184 emacsframe->async_iconified = 0;
6189 /* NSDraggingDestination protocol methods. Actually this is not really a
6190 protocol, but a category of Object. O well... */
6192 -(NSUInteger
) draggingEntered
: (id
<NSDraggingInfo
>) sender
6194 NSTRACE
(draggingEntered
);
6195 return NSDragOperationGeneric
;
6199 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
6205 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
6210 NSEvent
*theEvent
= [[self window
] currentEvent
];
6213 NSTRACE
(performDragOperation
);
6218 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
6219 x
= lrint
(position.x
); y
= lrint
(position.y
);
6221 pb
= [sender draggingPasteboard
];
6222 type = [pb availableTypeFromArray
: ns_drag_types
];
6227 else if ([type isEqualToString
: NSFilenamesPboardType
])
6230 NSEnumerator
*fenum
;
6233 if (!(files
= [pb propertyListForType
: type]))
6236 fenum
= [files objectEnumerator
];
6237 while ( (file
= [fenum nextObject
]) )
6239 emacs_event
->kind
= NS_NONKEY_EVENT
;
6240 emacs_event
->code
= KEY_NS_DRAG_FILE
;
6241 XSETINT
(emacs_event
->x
, x
);
6242 XSETINT
(emacs_event
->y
, y
);
6243 ns_input_file
= append2
(ns_input_file
,
6244 build_string
([file UTF8String
]));
6245 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6246 EV_TRAILER
(theEvent
);
6250 else if ([type isEqualToString
: NSURLPboardType
])
6255 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
6256 [fileURL isFileURL
] == NO
)
6259 file
= [fileURL
path];
6260 emacs_event
->kind
= NS_NONKEY_EVENT
;
6261 emacs_event
->code
= KEY_NS_DRAG_FILE
;
6262 XSETINT
(emacs_event
->x
, x
);
6263 XSETINT
(emacs_event
->y
, y
);
6264 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
6265 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6266 EV_TRAILER
(theEvent
);
6269 else if ([type isEqualToString
: NSStringPboardType
]
6270 ||
[type isEqualToString
: NSTabularTextPboardType
])
6274 if (! (data
= [pb stringForType
: type]))
6277 emacs_event
->kind
= NS_NONKEY_EVENT
;
6278 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
6279 XSETINT
(emacs_event
->x
, x
);
6280 XSETINT
(emacs_event
->y
, y
);
6281 ns_input_text
= build_string
([data UTF8String
]);
6282 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6283 EV_TRAILER
(theEvent
);
6286 else if ([type isEqualToString
: NSColorPboardType
])
6288 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
6289 emacs_event
->kind
= NS_NONKEY_EVENT
;
6290 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
6291 XSETINT
(emacs_event
->x
, x
);
6292 XSETINT
(emacs_event
->y
, y
);
6293 ns_input_color
= ns_color_to_lisp
(c
);
6294 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6295 EV_TRAILER
(theEvent
);
6298 else if ([type isEqualToString
: NSFontPboardType
])
6300 /* impl based on GNUstep NSTextView.m */
6301 NSData
*data
= [pb dataForType
: NSFontPboardType
];
6302 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
6303 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
6309 emacs_event
->kind
= NS_NONKEY_EVENT
;
6310 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
6311 XSETINT
(emacs_event
->x
, x
);
6312 XSETINT
(emacs_event
->y
, y
);
6313 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
6314 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
6315 ns_input_fontsize
= build_string
(fontSize
);
6316 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6317 EV_TRAILER
(theEvent
);
6322 error ("Invalid data
type in dragging pasteboard."
);
6328 - (id
) validRequestorForSendType
: (NSString
*)typeSent
6329 returnType
: (NSString
*)typeReturned
6331 NSTRACE
(validRequestorForSendType
);
6332 if (typeSent
!= nil
&& [ns_send_types indexOfObject
: typeSent
] != NSNotFound
6333 && typeReturned
== nil
)
6335 if (! NILP
(ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
)))
6339 return [super validRequestorForSendType
: typeSent
6340 returnType
: typeReturned
];
6344 /* The next two methods are part of NSServicesRequests informal protocol,
6345 supposedly called when a services menu item is chosen from this app.
6346 But this should not happen because we override the services menu with our
6347 own entries which call ns-perform-service.
6348 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
6349 So let's at least stub them out until further investigation can be done. */
6351 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
6353 /* we could call ns_string_from_pasteboard(pboard) here but then it should
6354 be written into the buffer in place of the existing selection..
6355 ordinary service calls go through functions defined in ns-win.el */
6359 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
6361 NSArray
*typesDeclared
;
6364 /* We only support NSStringPboardType */
6365 if ([types containsObject
:NSStringPboardType
] == NO
) {
6369 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6370 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
6373 if (CONSP
(val
) && NILP
(XCDR
(val
)))
6376 if (! STRINGP
(val
))
6379 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
6380 [pb declareTypes
:typesDeclared owner
:nil
];
6381 ns_string_to_pasteboard
(pb
, val
);
6386 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
6387 (gives a miniaturized version of the window); currently we use the latter for
6388 frames whose active buffer doesn't correspond to any file
6389 (e.g., '*scratch*') */
6390 - setMiniwindowImage
: (BOOL
) setMini
6392 id
image = [[self window
] miniwindowImage
];
6393 NSTRACE
(setMiniwindowImage
);
6395 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6396 about "AppleDockIconEnabled" notwithstanding, however the set message
6397 below has its effect nonetheless. */
6398 if (image != emacsframe
->output_data.ns
->miniimage
)
6400 if (image && [image isKindOfClass
: [EmacsImage
class]])
6402 [[self window
] setMiniwindowImage
:
6403 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6410 - (void
) setRows
: (int
) r andColumns
: (int
) c
6416 @
end /* EmacsView */
6420 /* ==========================================================================
6422 EmacsWindow implementation
6424 ========================================================================== */
6426 @implementation EmacsWindow
6428 #ifdef NS_IMPL_COCOA
6429 - (id
)accessibilityAttributeValue
:(NSString
*)attribute
6431 Lisp_Object str
= Qnil
;
6432 struct frame
*f
= SELECTED_FRAME
();
6433 struct buffer
*curbuf
= XBUFFER
(XWINDOW
(f
->selected_window
)->buffer
);
6435 if ([attribute isEqualToString
:NSAccessibilityRoleAttribute
])
6436 return NSAccessibilityTextFieldRole
;
6438 if ([attribute isEqualToString
:NSAccessibilitySelectedTextAttribute
]
6439 && curbuf
&& ! NILP
(BVAR
(curbuf
, mark_active
)))
6441 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6443 else if (curbuf
&& [attribute isEqualToString
:NSAccessibilityValueAttribute
])
6445 if (! NILP
(BVAR
(curbuf
, mark_active
)))
6446 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6450 ptrdiff_t start_byte
= BUF_BEGV_BYTE
(curbuf
);
6451 ptrdiff_t byte_range
= BUF_ZV_BYTE
(curbuf
) - start_byte
;
6452 ptrdiff_t range
= BUF_ZV
(curbuf
) - BUF_BEGV
(curbuf
);
6454 if (! NILP
(BVAR
(curbuf
, enable_multibyte_characters
)))
6455 str
= make_uninit_multibyte_string
(range
, byte_range
);
6457 str
= make_uninit_string
(range
);
6458 /* To check: This returns emacs-utf-8, which is a superset of utf-8.
6459 Is this a problem? */
6460 memcpy
(SDATA
(str
), BYTE_POS_ADDR
(start_byte
), byte_range
);
6467 if (CONSP
(str
) && SYMBOLP
(XCAR
(str
)))
6470 if (CONSP
(str
) && NILP
(XCDR
(str
)))
6475 const
char *utfStr
= SSDATA
(str
);
6476 NSString
*nsStr
= [NSString stringWithUTF8String
: utfStr
];
6481 return [super accessibilityAttributeValue
:attribute
];
6483 #endif
/* NS_IMPL_COCOA */
6485 /* If we have multiple monitors, one above the other, we don't want to
6486 restrict the height to just one monitor. So we override this. */
6487 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6489 /* When making the frame visible for the first time or if there is just
6490 one screen, we want to constrain. Other times not. */
6491 NSUInteger nr_screens
= [[NSScreen screens
] count
];
6492 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6493 NSTRACE
(constrainFrameRect
);
6495 if (nr_screens
== 1)
6497 NSRect r
= [super constrainFrameRect
:frameRect toScreen
:screen
];
6501 if (f
->output_data.ns
->dont_constrain
6502 || ns_menu_bar_should_be_hidden
())
6505 f
->output_data.ns
->dont_constrain
= 1;
6506 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6509 @
end /* EmacsWindow */
6512 @implementation EmacsFSWindow
6514 - (BOOL
)canBecomeKeyWindow
6519 - (BOOL
)canBecomeMainWindow
6526 /* ==========================================================================
6528 EmacsScroller implementation
6530 ========================================================================== */
6533 @implementation EmacsScroller
6535 /* for repeat button push */
6536 #define SCROLL_BAR_FIRST_DELAY
0.5
6537 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6539 + (CGFloat
) scrollerWidth
6541 /* TODO: if we want to allow variable widths, this is the place to do it,
6542 however neither GNUstep nor Cocoa support it very well */
6543 return [NSScroller scrollerWidth
];
6547 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
6549 NSTRACE
(EmacsScroller_initFrame
);
6551 r.
size.width
= [EmacsScroller scrollerWidth
];
6552 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
6553 [self setContinuous
: YES
];
6554 [self setEnabled
: YES
];
6556 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
6557 locked against the top and bottom edges, and right edge on OS X, where
6558 scrollers are on right. */
6559 #ifdef NS_IMPL_GNUSTEP
6560 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
6562 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
6567 pixel_height
= NSHeight
(r
);
6568 if (pixel_height
== 0) pixel_height
= 1;
6569 min_portion
= 20 / pixel_height
;
6571 frame
= XFRAME
(XWINDOW
(win
)->frame
);
6572 if (FRAME_LIVE_P
(frame
))
6575 EmacsView
*view = FRAME_NS_VIEW
(frame
);
6576 NSView
*sview
= [[view window
] contentView
];
6577 NSArray
*subs
= [sview subviews
];
6579 /* disable optimization stopping redraw of other scrollbars */
6580 view->scrollbarsNeedingUpdate
= 0;
6581 for (i
=[subs count
]-1; i
>= 0; i
--)
6582 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
6583 view->scrollbarsNeedingUpdate
++;
6584 [sview addSubview
: self
];
6587 /* [self setFrame: r]; */
6593 - (void
)setFrame
: (NSRect
)newRect
6595 NSTRACE
(EmacsScroller_setFrame
);
6596 /* block_input (); */
6597 pixel_height
= NSHeight
(newRect
);
6598 if (pixel_height
== 0) pixel_height
= 1;
6599 min_portion
= 20 / pixel_height
;
6600 [super setFrame
: newRect
];
6602 /* unblock_input (); */
6608 NSTRACE
(EmacsScroller_dealloc
);
6610 wset_vertical_scroll_bar
(XWINDOW
(win
), Qnil
);
6638 /* ensure other scrollbar updates after deletion */
6639 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6641 view->scrollbarsNeedingUpdate
++;
6642 [self removeFromSuperview
];
6650 - (void
)resetCursorRects
6652 NSRect visible
= [self visibleRect
];
6653 NSTRACE
(resetCursorRects
);
6655 if (!NSIsEmptyRect
(visible
))
6656 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
6657 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
6661 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
6664 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
6665 && portion
!= whole
; /* needed for resize empty buf */
6669 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
6671 NSTRACE
(setPosition
);
6673 em_position
= position
;
6674 em_portion
= portion
;
6677 if (portion
>= whole
)
6679 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6680 [self setKnobProportion
: 1.0];
6681 [self setDoubleValue
: 1.0];
6683 [self setFloatValue
: 0.0 knobProportion
: 1.0];
6689 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
6690 pos
= (float
)position
/ (whole
- portion
);
6691 por
= (float
)portion
/whole
;
6692 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6693 [self setKnobProportion
: por
];
6694 [self setDoubleValue
: pos
];
6696 [self setFloatValue
: pos knobProportion
: por
];
6700 /* Events may come here even if the event loop is not running.
6701 If we don't enter the event loop, the scroll bar will not update.
6702 So send SIGIO to ourselves. */
6703 if (apploopnr
== 0) raise
(SIGIO
);
6708 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
6709 drag events will go directly to the EmacsScroller. Leaving in for now. */
6710 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
6711 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
6713 *part
= last_hit_part
;
6715 XSETINT
(*y
, pixel_height
);
6716 if ([self floatValue
] > 0.999)
6717 XSETINT
(*x
, pixel_height
);
6719 XSETINT
(*x
, pixel_height
* [self floatValue
]);
6723 /* set up emacs_event */
6724 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
6729 emacs_event
->part
= last_hit_part
;
6730 emacs_event
->code
= 0;
6731 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
6732 emacs_event
->frame_or_window
= win
;
6733 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
6734 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
6735 emacs_event
->arg
= Qnil
;
6736 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
6737 XSETINT
(emacs_event
->y
, pixel_height
-20);
6741 n_emacs_events_pending
++;
6742 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
6745 hold_event
(emacs_event
);
6746 EVENT_INIT
(*emacs_event
);
6747 ns_send_appdefined
(-1);
6751 /* called manually thru timer to implement repeated button action w/hold-down */
6752 - repeatScroll
: (NSTimer
*)scrollEntry
6754 NSEvent
*e
= [[self window
] currentEvent
];
6755 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
6756 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
6758 /* clear timer if need be */
6759 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
6761 [scroll_repeat_entry invalidate
];
6762 [scroll_repeat_entry release
];
6763 scroll_repeat_entry
= nil
;
6769 = [[NSTimer scheduledTimerWithTimeInterval
:
6770 SCROLL_BAR_CONTINUOUS_DELAY
6772 selector
: @selector
(repeatScroll
:)
6778 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
6783 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
6784 mouseDragged events without going into a modal loop. */
6785 - (void
)mouseDown
: (NSEvent
*)e
6788 /* hitPart is only updated AFTER event is passed on */
6789 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6790 double inc
= 0.0, loc
, kloc
, pos
;
6793 NSTRACE
(EmacsScroller_mouseDown
);
6797 case NSScrollerDecrementPage
:
6798 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6799 case NSScrollerIncrementPage
:
6800 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6801 case NSScrollerDecrementLine
:
6802 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6803 case NSScrollerIncrementLine
:
6804 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6805 case NSScrollerKnob
:
6806 last_hit_part
= scroll_bar_handle
; break;
6807 case NSScrollerKnobSlot
: /* GNUstep-only */
6808 last_hit_part
= scroll_bar_move_ratio
; break;
6809 default
: /* NSScrollerNoPart? */
6810 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
6817 pos
= 0; /* ignored */
6819 /* set a timer to repeat, as we can't let superclass do this modally */
6821 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
6823 selector
: @selector
(repeatScroll
:)
6830 /* handle, or on GNUstep possibly slot */
6831 NSEvent
*fake_event
;
6833 /* compute float loc in slot and mouse offset on knob */
6834 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6836 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6842 else if (loc
>= NSHeight
(sr
))
6844 loc
= NSHeight
(sr
);
6852 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6854 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6856 last_mouse_offset
= kloc
;
6858 /* if knob, tell emacs a location offset by knob pos
6859 (to indicate top of handle) */
6860 if (part
== NSScrollerKnob
)
6861 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6863 /* else this is a slot click on GNUstep: go straight there */
6864 pos
= loc
/ NSHeight
(sr
);
6866 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6867 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6868 location
: [e locationInWindow
]
6869 modifierFlags
: [e modifierFlags
]
6870 timestamp
: [e timestamp
]
6871 windowNumber
: [e windowNumber
]
6872 context
: [e context
]
6873 eventNumber
: [e eventNumber
]
6874 clickCount
: [e clickCount
]
6875 pressure
: [e pressure
]];
6876 [super mouseUp
: fake_event
];
6879 if (part
!= NSScrollerKnob
)
6880 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6884 /* Called as we manually track scroller drags, rather than superclass. */
6885 - (void
)mouseDragged
: (NSEvent
*)e
6891 NSTRACE
(EmacsScroller_mouseDragged
);
6893 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6895 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6902 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6904 loc
= NSHeight
(sr
) + last_mouse_offset
;
6908 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6909 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6913 - (void
)mouseUp
: (NSEvent
*)e
6915 if (scroll_repeat_entry
)
6917 [scroll_repeat_entry invalidate
];
6918 [scroll_repeat_entry release
];
6919 scroll_repeat_entry
= nil
;
6925 /* treat scrollwheel events in the bar as though they were in the main window */
6926 - (void
) scrollWheel
: (NSEvent
*)theEvent
6928 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6929 [view mouseDown
: theEvent
];
6932 @
end /* EmacsScroller */
6937 /* ==========================================================================
6939 Font-related functions; these used to be in nsfaces.m
6941 ========================================================================== */
6945 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6947 struct font
*font
= XFONT_OBJECT
(font_object
);
6950 fontset
= fontset_from_font
(font_object
);
6951 FRAME_FONTSET
(f
) = fontset
;
6953 if (FRAME_FONT
(f
) == font
)
6954 /* This font is already set in frame F. There's nothing more to
6958 FRAME_FONT
(f
) = font
;
6960 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6961 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6962 FRAME_SPACE_WIDTH
(f
) = font
->space_width
;
6963 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6965 compute_fringe_widths
(f
, 1);
6967 /* Compute the scroll bar width in character columns. */
6968 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6970 int wid
= FRAME_COLUMN_WIDTH
(f
);
6971 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6972 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6976 int wid
= FRAME_COLUMN_WIDTH
(f
);
6977 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6980 /* Now make the frame display the given font. */
6981 if (FRAME_NS_WINDOW
(f
) != 0)
6982 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6988 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6989 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6993 ns_xlfd_to_fontname
(const
char *xlfd
)
6994 /* --------------------------------------------------------------------------
6995 Convert an X font name (XLFD) to an NS font name.
6996 Only family is used.
6997 The string returned is temporarily allocated.
6998 -------------------------------------------------------------------------- */
7000 char *name
= xmalloc
(180);
7004 if (!strncmp
(xlfd
, "
--"
, 2))
7005 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
7007 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
7009 /* stopgap for malformed XLFD input */
7010 if (strlen
(name
) == 0)
7011 strcpy
(name
, "Monaco"
);
7013 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
7014 also uppercase after '-' or ' ' */
7015 name
[0] = c_toupper
(name
[0]);
7016 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
7022 name
[i
+1] = c_toupper
(name
[i
+1]);
7024 else if (name
[i
] == '_')
7028 name
[i
+1] = c_toupper
(name
[i
+1]);
7031 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
7032 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
7039 syms_of_nsterm
(void
)
7041 NSTRACE
(syms_of_nsterm
);
7043 ns_antialias_threshold
= 10.0;
7045 /* from 23+ we need to tell emacs what modifiers there are.. */
7046 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
7047 DEFSYM
(Qalt
, "alt"
);
7048 DEFSYM
(Qhyper
, "hyper"
);
7049 DEFSYM
(Qmeta
, "
meta"
);
7050 DEFSYM
(Qsuper
, "super"
);
7051 DEFSYM
(Qcontrol
, "control"
);
7052 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
7054 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
7055 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
7056 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
7057 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
7058 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
7060 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
7061 "The file specified in the last NS event."
);
7062 ns_input_file
=Qnil
;
7064 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
7065 "The data received in the last NS
text drag event."
);
7066 ns_input_text
=Qnil
;
7068 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
7069 "String
for visualizing working composition sequence."
);
7070 ns_working_text
=Qnil
;
7072 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
7073 "The font specified in the last NS event."
);
7074 ns_input_font
=Qnil
;
7076 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
7077 "The fontsize specified in the last NS event."
);
7078 ns_input_fontsize
=Qnil
;
7080 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
7081 "The
line specified in the last NS event."
);
7082 ns_input_line
=Qnil
;
7084 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
7085 "The color specified in the last NS event."
);
7086 ns_input_color
=Qnil
;
7088 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
7089 "The service name specified in the last NS event."
);
7090 ns_input_spi_name
=Qnil
;
7092 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
7093 "The service argument specified in the last NS event."
);
7094 ns_input_spi_arg
=Qnil
;
7096 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
7097 "This variable describes the behavior of the alternate or option key.
\n\
7098 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7099 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
7100 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7101 ns_alternate_modifier
= Qmeta
;
7103 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
7104 "This variable describes the behavior of the right alternate or option key.
\n\
7105 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7106 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
7107 Set to none means that the alternate / option key is not interpreted by Emacs\n\
7108 at all, allowing it to be used at a lower level for accented character entry.");
7109 ns_right_alternate_modifier = Qleft;
7111 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
7112 "This variable describes the behavior of the command key.\n\
7113 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
7114 ns_command_modifier = Qsuper;
7116 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
7117 "This variable describes the behavior of the right command key.\n\
7118 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7119 Set to left means be the same key as `ns-command-modifier'.
\n\
7120 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
7121 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7122 ns_right_command_modifier
= Qleft
;
7124 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
7125 "This variable describes the behavior of the control key.
\n\
7126 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
7127 ns_control_modifier
= Qcontrol
;
7129 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
7130 "This variable describes the behavior of the right control key.
\n\
7131 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7132 Set to left means be the same key as `ns
-control
-modifier
'.\n\
7133 Set to none means that the control / option key is not interpreted by Emacs\n\
7134 at all, allowing it to be used at a lower level for accented character entry.");
7135 ns_right_control_modifier = Qleft;
7137 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
7138 "This variable describes the behavior of the function key (on laptops).\n\
7139 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7140 Set to none means that the function key is not interpreted by Emacs at all,\n\
7141 allowing it to be used at a lower level for accented character entry.");
7142 ns_function_modifier = Qnone;
7144 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
7145 "Non-nil (the default) means to render text antialiased.");
7146 ns_antialias_text = Qt;
7148 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
7149 "Whether to confirm application quit using dialog.");
7150 ns_confirm_quit = Qnil;
7152 staticpro (&ns_display_name_list);
7153 ns_display_name_list = Qnil;
7155 staticpro (&last_mouse_motion_frame);
7156 last_mouse_motion_frame = Qnil;
7158 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
7159 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
7160 Only works on OSX 10.6 or later. */);
7161 ns_auto_hide_menu_bar = Qnil;
7163 /* TODO: move to common code */
7164 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
7165 doc: /* Which toolkit scroll bars Emacs uses, if any.
7166 A value of nil means Emacs doesn't use toolkit scroll bars.
7167 With the X Window system
, the value is a symbol describing the
7168 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
7169 With MS Windows or Nextstep
, the value is t. */
);
7170 Vx_toolkit_scroll_bars
= Qt
;
7172 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
7173 x_use_underline_position_properties
,
7174 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
7175 A value of nil means ignore them. If you encounter fonts with bogus
7176 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
7177 to 4.1, set this to nil. */);
7178 x_use_underline_position_properties
= 0;
7180 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
7181 x_underline_at_descent_line
,
7182 doc: /* Non-nil means to draw the underline at the same place as the descent line.
7183 A value of nil means to draw the underline according to the value of the
7184 variable `x-use-underline-position-properties', which is usually at the
7185 baseline level. The default value is nil. */);
7186 x_underline_at_descent_line
= 0;
7188 /* Tell emacs about this window system. */
7189 Fprovide
(intern
("ns"
), Qnil
);