1 /* NeXT/Open/GNUstep / MacOSX communication module.
3 Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2013 Free Software
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_mouse_frame
= 0;
1192 if (f
->output_data.ns
->miniimage
!= nil
)
1193 [f
->output_data.ns
->miniimage release
];
1195 [[view window
] close];
1198 xfree
(f
->output_data.ns
);
1204 x_destroy_window
(struct frame
*f
)
1205 /* --------------------------------------------------------------------------
1206 External: Delete the window
1207 -------------------------------------------------------------------------- */
1209 NSTRACE
(x_destroy_window
);
1211 x_free_frame_resources
(f
);
1217 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1218 /* --------------------------------------------------------------------------
1219 External: Position the window
1220 -------------------------------------------------------------------------- */
1222 NSView
*view = FRAME_NS_VIEW
(f
);
1223 NSArray
*screens
= [NSScreen screens
];
1224 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1225 NSScreen
*screen
= [[view window
] screen
];
1227 NSTRACE
(x_set_offset
);
1234 if (view != nil
&& screen
&& fscreen
)
1236 f
->left_pos
= f
->size_hint_flags
& XNegative
1237 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1239 /* We use visibleFrame here to take menu bar into account.
1240 Ideally we should also adjust left/top with visibleFrame.origin. */
1242 f
->top_pos
= f
->size_hint_flags
& YNegative
1243 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1244 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1245 - FRAME_TOOLBAR_HEIGHT
(f
))
1247 #ifdef NS_IMPL_GNUSTEP
1248 if (f
->left_pos
< 100)
1249 f
->left_pos
= 100; /* don't overlap menu */
1251 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1253 f
->output_data.ns
->dont_constrain
= 0;
1254 [[view window
] setFrameTopLeftPoint
:
1255 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1256 SCREENMAXBOUND
([fscreen frame
].
size.height
1257 - NS_TOP_POS
(f
)))];
1258 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1266 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1267 /* --------------------------------------------------------------------------
1268 Adjust window pixel size based on given character grid size
1269 Impl is a bit more complex than other terms, need to do some
1271 -------------------------------------------------------------------------- */
1273 EmacsView
*view = FRAME_NS_VIEW
(f
);
1274 NSWindow
*window
= [view window
];
1275 NSRect wr
= [window frame
];
1276 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1277 int pixelwidth
, pixelheight
;
1279 NSTRACE
(x_set_window_size
);
1284 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1288 check_frame_size
(f
, &rows
, &cols
);
1290 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1291 compute_fringe_widths
(f
, 0);
1293 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1294 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1296 /* If we have a toolbar, take its height into account. */
1298 /* NOTE: previously this would generate wrong result if toolbar not
1299 yet displayed and fixing toolbar_height=32 helped, but
1300 now (200903) seems no longer needed */
1301 FRAME_TOOLBAR_HEIGHT
(f
) =
1302 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1303 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1305 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1307 wr.
size.width
= pixelwidth
+ f
->border_width
;
1308 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1309 + FRAME_TOOLBAR_HEIGHT
(f
);
1311 /* Do not try to constrain to this screen. We may have multiple
1312 screens, and want Emacs to span those. Constraining to screen
1313 prevents that, and that is not nice to the user. */
1314 if (f
->output_data.ns
->zooming
)
1315 f
->output_data.ns
->zooming
= 0;
1317 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1319 [view setRows
: rows andColumns
: cols
];
1320 [window setFrame
: wr display
: YES
];
1322 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1324 /* This is a trick to compensate for Emacs' managing the scrollbar area
1325 as a fixed number of standard character columns. Instead of leaving
1326 blank space for the extra, we chopped it off above. Now for
1327 left-hand scrollbars, we shift all rendering to the left by the
1328 difference between the real width and Emacs' imagined one. For
1329 right-hand bars, don't worry about it since the extra is never used.
1330 (Obviously doesn't work for vertically split windows tho..) */
1332 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1333 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1334 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1335 : NSMakePoint
(0, 0);
1336 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1337 [view setBoundsOrigin
: origin
];
1340 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1341 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1342 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1343 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1345 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1346 cancel_mouse_face
(f
);
1353 ns_fullscreen_hook
(FRAME_PTR f
)
1355 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(f
);
1357 if (! f
->async_visible
) return;
1358 #ifndef NEW_STYLE_FS
1359 if (f
->want_fullscreen
== FULLSCREEN_BOTH
)
1361 /* Old style fs don't initiate correctly if created from
1362 init/default-frame alist, so use a timer (not nice...).
1364 [NSTimer scheduledTimerWithTimeInterval
: 0.5 target
: view
1365 selector
: @selector
(handleFS
)
1366 userInfo
: nil repeats
: NO
];
1376 /* ==========================================================================
1380 ========================================================================== */
1384 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1386 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1387 if (idx
< 1 || idx
>= color_table
->avail
)
1389 return color_table
->colors
[idx
];
1394 ns_index_color
(NSColor
*color
, struct frame
*f
)
1396 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1400 if (!color_table
->colors
)
1402 color_table
->size = NS_COLOR_CAPACITY
;
1403 color_table
->avail
= 1; /* skip idx=0 as marker */
1404 color_table
->colors
= xmalloc
(color_table
->size * sizeof
(NSColor
*));
1405 color_table
->colors
[0] = nil
;
1406 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1409 /* do we already have this color ? */
1410 for (i
= 1; i
< color_table
->avail
; i
++)
1411 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1414 if ([color_table
->empty_indices count
] > 0)
1416 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1417 [color_table
->empty_indices removeObject
: index
];
1418 idx
= [index unsignedLongValue
];
1422 if (color_table
->avail
== color_table
->size)
1423 color_table
->colors
=
1424 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1425 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1426 idx
= color_table
->avail
++;
1429 color_table
->colors
[idx
] = color
;
1431 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1437 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1439 struct ns_color_table
*color_table
;
1446 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1448 if (idx
<= 0 || idx
>= color_table
->size) {
1449 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1453 index
= [NSNumber numberWithUnsignedInt
: idx
];
1454 if ([color_table
->empty_indices containsObject
: index
]) {
1455 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1459 color
= color_table
->colors
[idx
];
1461 color_table
->colors
[idx
] = nil
;
1462 [color_table
->empty_indices addObject
: index
];
1463 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1468 ns_get_color
(const
char *name
, NSColor
**col
)
1469 /* --------------------------------------------------------------------------
1471 -------------------------------------------------------------------------- */
1472 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1473 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1474 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1477 static
char hex
[20];
1479 float r
= -1.0, g
, b
;
1480 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1482 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1485 if ([nsname isEqualToString
: @"ns_selection_color"
])
1487 nsname
= ns_selection_color
;
1488 name
= [ns_selection_color UTF8String
];
1491 /* First, check for some sort of numeric specification. */
1494 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1496 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1497 [scanner scanFloat
: &r
];
1498 [scanner scanFloat
: &g
];
1499 [scanner scanFloat
: &b
];
1501 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1502 scaling
= (snprintf
(hex
, sizeof hex
, "
%s", name + 4) - 2) / 3;
1503 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1505 int len
= (strlen
(name
) - 1);
1506 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1508 scaling
= strlen
(name
+start
) / 3;
1509 for (i
= 0; i
< 3; i
++)
1510 sprintf (hex
+ i
* (scaling
+ 1), "
%.*s/", scaling,
1511 name
+ start
+ i
* scaling
);
1512 hex
[3 * (scaling
+ 1) - 1] = '\0';
1518 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1519 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1529 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1534 /* Otherwise, color is expected to be from a list */
1536 NSEnumerator
*lenum
, *cenum
;
1540 #ifdef NS_IMPL_GNUSTEP
1541 /* XXX: who is wrong, the requestor or the implementation? */
1542 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1544 nsname
= @"highlightColor"
;
1547 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1548 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1550 cenum
= [[clist allKeys
] objectEnumerator
];
1551 while ( (name
= [cenum nextObject
]) && new
== nil
)
1553 if ([name compare
: nsname
1554 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1555 new
= [clist colorWithKey
: name
];
1561 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1568 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1569 /* --------------------------------------------------------------------------
1570 Convert a Lisp string object to a NS color
1571 -------------------------------------------------------------------------- */
1573 NSTRACE
(ns_lisp_to_color
);
1574 if (STRINGP
(color
))
1575 return ns_get_color
(SSDATA
(color
), col
);
1576 else if (SYMBOLP
(color
))
1577 return ns_get_color
(SSDATA
(SYMBOL_NAME
(color
)), col
);
1583 ns_color_to_lisp
(NSColor
*col
)
1584 /* --------------------------------------------------------------------------
1585 Convert a color to a lisp string with the RGB equivalent
1586 -------------------------------------------------------------------------- */
1588 CGFloat red
, green
, blue
, alpha
, gray;
1591 NSTRACE
(ns_color_to_lisp
);
1594 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1596 if ((str
=[[col colorNameComponent
] UTF8String
]))
1599 return build_string
((char *)str
);
1602 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1603 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1604 if (red
==green
&& red
==blue
)
1606 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1607 getWhite
: &gray alpha
: &alpha
];
1608 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1609 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1611 return build_string
(buf
);
1614 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1615 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1618 return build_string
(buf
);
1623 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1624 /* --------------------------------------------------------------------------
1625 Get ARGB values out of NSColor col and put them into color_def.
1626 If setPixel, set the pixel to a concatenated version.
1627 and set color_def pixel to the resulting index.
1628 -------------------------------------------------------------------------- */
1632 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1633 color_def
->red
= r
* 65535;
1634 color_def
->green
= g
* 65535;
1635 color_def
->blue
= b
* 65535;
1637 if (setPixel
== YES
)
1639 = ARGB_TO_ULONG
((int
)(a
*255),
1640 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1645 ns_defined_color
(struct frame
*f
,
1650 /* --------------------------------------------------------------------------
1651 Return true if named color found, and set color_def rgb accordingly.
1652 If makeIndex and alloc are nonzero put the color in the color_table,
1653 and set color_def pixel to the resulting index.
1654 If makeIndex is zero, set color_def pixel to ARGB.
1655 Return false if not found
1656 -------------------------------------------------------------------------- */
1659 NSTRACE
(ns_defined_color
);
1662 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1667 if (makeIndex
&& alloc
)
1668 color_def
->pixel
= ns_index_color
(col
, f
);
1669 ns_query_color
(col
, color_def
, !makeIndex
);
1676 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1677 /* --------------------------------------------------------------------------
1678 return an autoreleased RGB color
1679 -------------------------------------------------------------------------- */
1681 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1682 if (r
< 0.0) r
= 0.0;
1683 else if (r
> 1.0) r
= 1.0;
1684 if (g
< 0.0) g
= 0.0;
1685 else if (g
> 1.0) g
= 1.0;
1686 if (b
< 0.0) b
= 0.0;
1687 else if (b
> 1.0) b
= 1.0;
1688 if (a
< 0.0) a
= 0.0;
1689 else if (a
> 1.0) a
= 1.0;
1690 return (unsigned
long) ns_index_color
(
1691 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1696 x_set_frame_alpha
(struct frame
*f
)
1697 /* --------------------------------------------------------------------------
1698 change the entire-frame transparency
1699 -------------------------------------------------------------------------- */
1701 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1702 EmacsView
*view = FRAME_NS_VIEW
(f
);
1704 double alpha_min
= 1.0;
1706 if (dpyinfo
->x_highlight_frame
== f
)
1707 alpha
= f
->alpha
[0];
1709 alpha
= f
->alpha
[1];
1711 if (FLOATP
(Vframe_alpha_lower_limit
))
1712 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1713 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1714 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1718 else if (1.0 < alpha
)
1720 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1723 #ifdef NS_IMPL_COCOA
1724 [[view window
] setAlphaValue
: alpha
];
1729 /* ==========================================================================
1733 ========================================================================== */
1737 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1738 /* --------------------------------------------------------------------------
1739 Programmatically reposition mouse pointer in pixel coordinates
1740 -------------------------------------------------------------------------- */
1742 NSTRACE
(x_set_mouse_pixel_position
);
1745 /* FIXME: this does not work, and what about GNUstep? */
1746 #ifdef NS_IMPL_COCOA
1747 [FRAME_NS_VIEW
(f
) lockFocus
];
1748 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1749 [FRAME_NS_VIEW
(f
) unlockFocus
];
1756 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1757 /* --------------------------------------------------------------------------
1758 Programmatically reposition mouse pointer in character coordinates
1759 -------------------------------------------------------------------------- */
1763 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1764 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1766 if (pix_x
< 0) pix_x
= 0;
1767 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1769 if (pix_y
< 0) pix_y
= 0;
1770 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1772 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1777 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1778 /* ------------------------------------------------------------------------
1779 Called by EmacsView on mouseMovement events. Passes on
1780 to emacs mainstream code if we moved off of a rect of interest
1781 known as last_mouse_glyph.
1782 ------------------------------------------------------------------------ */
1784 // NSTRACE
(note_mouse_movement
);
1786 XSETFRAME
(last_mouse_motion_frame
, frame
);
1788 /* Note, this doesn't get called for enter/leave, since we don't have a
1789 position. Those are taken care of in the corresponding NSView methods. */
1791 /* has movement gone beyond last rect we were tracking? */
1792 if (x
< last_mouse_glyph.origin.x ||
1793 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1794 y
< last_mouse_glyph.origin.y ||
1795 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1797 ns_update_begin
(frame
);
1798 frame
->mouse_moved
= 1;
1799 note_mouse_highlight
(frame
, x
, y
);
1800 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1801 ns_update_end
(frame
);
1810 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1811 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1813 /* --------------------------------------------------------------------------
1814 External (hook): inform emacs about mouse position and hit parts.
1815 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1816 x & y should be position in the scrollbar (the whole bar, not the handle)
1817 and length of scrollbar respectively
1818 -------------------------------------------------------------------------- */
1822 Lisp_Object frame
, tail
;
1824 struct ns_display_info
*dpyinfo
;
1826 NSTRACE
(ns_mouse_position
);
1830 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1834 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1838 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1840 /* TODO: we do not use this path at the moment because drag events will
1841 go directly to the EmacsScroller. Leaving code in for now. */
1842 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1844 if (time
) *time
= last_mouse_movement_time
;
1845 last_mouse_scroll_bar
= nil
;
1849 /* Clear the mouse-moved flag for every frame on this display. */
1850 FOR_EACH_FRAME
(tail
, frame
)
1851 if (FRAME_NS_P
(XFRAME
(frame
))
1852 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1853 XFRAME
(frame
)->mouse_moved
= 0;
1855 last_mouse_scroll_bar
= nil
;
1856 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1857 f
= last_mouse_frame
;
1859 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1860 : SELECTED_FRAME
();
1862 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1864 view = FRAME_NS_VIEW
(*fp
);
1866 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1867 position
= [view convertPoint
: position fromView
: nil
];
1868 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1869 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1871 if (bar_window
) *bar_window
= Qnil
;
1872 if (part
) *part
= 0; /*scroll_bar_handle; */
1874 if (x
) XSETINT
(*x
, lrint
(position.x
));
1875 if (y
) XSETINT
(*y
, lrint
(position.y
));
1876 if (time
) *time
= last_mouse_movement_time
;
1886 ns_frame_up_to_date
(struct frame
*f
)
1887 /* --------------------------------------------------------------------------
1888 External (hook): Fix up mouse highlighting right after a full update.
1889 Can't use FRAME_MOUSE_UPDATE due to ns_frame_begin and ns_frame_end calls.
1890 -------------------------------------------------------------------------- */
1892 NSTRACE
(ns_frame_up_to_date
);
1896 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1897 if (f
== hlinfo
->mouse_face_mouse_frame
)
1901 if (hlinfo
->mouse_face_mouse_frame
)
1902 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1903 hlinfo
->mouse_face_mouse_x
,
1904 hlinfo
->mouse_face_mouse_y
);
1913 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1914 /* --------------------------------------------------------------------------
1915 External (RIF): set frame mouse pointer type.
1916 -------------------------------------------------------------------------- */
1918 NSTRACE
(ns_define_frame_cursor
);
1919 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1921 EmacsView
*view = FRAME_NS_VIEW
(f
);
1922 FRAME_POINTER_TYPE
(f
) = cursor
;
1923 [[view window
] invalidateCursorRectsForView
: view];
1924 /* Redisplay assumes this function also draws the changed frame
1925 cursor, but this function doesn't, so do it explicitly. */
1926 x_update_cursor
(f
, 1);
1932 /* ==========================================================================
1936 ========================================================================== */
1940 ns_convert_key
(unsigned code
)
1941 /* --------------------------------------------------------------------------
1942 Internal call used by NSView-keyDown.
1943 -------------------------------------------------------------------------- */
1945 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1946 / sizeof
(convert_ns_to_X_keysym
[0]));
1948 /* An array would be faster, but less easy to read. */
1949 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1950 if (code
== convert_ns_to_X_keysym
[keysym
])
1951 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1953 /* if decide to use keyCode and Carbon table, use this line:
1954 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1959 x_get_keysym_name
(int keysym
)
1960 /* --------------------------------------------------------------------------
1961 Called by keyboard.c. Not sure if the return val is important, except
1963 -------------------------------------------------------------------------- */
1965 static
char value
[16];
1966 NSTRACE
(x_get_keysym_name
);
1967 sprintf (value
, "
%d", keysym);
1973 /* ==========================================================================
1975 Block drawing operations
1977 ========================================================================== */
1981 ns_redraw_scroll_bars
(struct frame
*f
)
1985 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1986 NSTRACE
(ns_redraw_scroll_bars
);
1987 for (i
=[subviews count
]-1; i
>= 0; i
--)
1989 view = [subviews objectAtIndex
: i
];
1990 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
1997 ns_clear_frame
(struct frame
*f
)
1998 /* --------------------------------------------------------------------------
1999 External (hook): Erase the entire frame
2000 -------------------------------------------------------------------------- */
2002 NSView
*view = FRAME_NS_VIEW
(f
);
2005 NSTRACE
(ns_clear_frame
);
2007 /* comes on initial frame because we have
2008 after-make-frame-functions = select-frame */
2009 if (!FRAME_DEFAULT_FACE
(f
))
2012 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
2014 output_cursor.hpos
= output_cursor.vpos
= 0;
2015 output_cursor.x
= -1;
2020 ns_focus
(f
, &r
, 1);
2021 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
2025 /* as of 2006/11 or so this is now needed */
2026 ns_redraw_scroll_bars
(f
);
2032 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
2033 /* --------------------------------------------------------------------------
2034 External (RIF): Clear section of frame
2035 -------------------------------------------------------------------------- */
2037 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
2038 NSView
*view = FRAME_NS_VIEW
(f
);
2039 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
2044 NSTRACE
(ns_clear_frame_area
);
2046 r
= NSIntersectionRect
(r
, [view frame
]);
2047 ns_focus
(f
, &r
, 1);
2048 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
2058 ns_scroll_run
(struct window
*w
, struct run
*run
)
2059 /* --------------------------------------------------------------------------
2060 External (RIF): Insert or delete n lines at line vpos
2061 -------------------------------------------------------------------------- */
2063 struct frame
*f
= XFRAME
(w
->frame
);
2064 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2066 NSTRACE
(ns_scroll_run
);
2068 /* begin copy from other terms */
2069 /* Get frame-relative bounding box of the text display area of W,
2070 without mode lines. Include in this box the left and right
2072 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2074 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2075 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2076 bottom_y
= y
+ height
;
2080 /* Scrolling up. Make sure we don't copy part of the mode
2081 line at the bottom. */
2082 if (from_y
+ run
->height
> bottom_y
)
2083 height
= bottom_y
- from_y
;
2085 height
= run
->height
;
2089 /* Scrolling down. Make sure we don't copy over the mode line.
2091 if (to_y
+ run
->height
> bottom_y
)
2092 height
= bottom_y
- to_y
;
2094 height
= run
->height
;
2096 /* end copy from other terms */
2107 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2108 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2109 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2111 ns_focus
(f
, &dstRect
, 1);
2112 NSCopyBits
(0, srcRect
, dstOrigin
);
2121 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2122 /* --------------------------------------------------------------------------
2123 External (RIF): preparatory to fringe update after text was updated
2124 -------------------------------------------------------------------------- */
2126 struct window
*w
= updated_window
;
2130 NSTRACE
(ns_after_update_window_line
);
2132 /* begin copy from other terms */
2135 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2136 desired_row
->redraw_fringe_bitmaps_p
= 1;
2138 /* When a window has disappeared, make sure that no rest of
2139 full-width rows stays visible in the internal border. */
2140 if (windows_or_buffers_changed
2141 && desired_row
->full_width_p
2142 && (f
= XFRAME
(w
->frame
),
2143 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2145 && (height
= desired_row
->visible_height
,
2148 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2151 ns_clear_frame_area
(f
, 0, y
, width
, height
);
2152 ns_clear_frame_area
(f
,
2153 FRAME_PIXEL_WIDTH
(f
) - width
,
2161 ns_shift_glyphs_for_insert
(struct frame
*f
,
2162 int x
, int y
, int width
, int height
,
2164 /* --------------------------------------------------------------------------
2165 External (RIF): copy an area horizontally, don't worry about clearing src
2166 -------------------------------------------------------------------------- */
2168 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2169 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2170 NSPoint dstOrigin
= dstRect.origin
;
2172 NSTRACE
(ns_shift_glyphs_for_insert
);
2174 ns_focus
(f
, &dstRect
, 1);
2175 NSCopyBits
(0, srcRect
, dstOrigin
);
2181 /* ==========================================================================
2183 Character encoding and metrics
2185 ========================================================================== */
2189 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2190 /* --------------------------------------------------------------------------
2191 External (RIF); compute left/right overhang of whole string and set in s
2192 -------------------------------------------------------------------------- */
2194 struct font
*font
= s
->font
;
2198 struct font_metrics metrics
;
2199 unsigned int codes
[2];
2200 codes
[0] = *(s
->char2b
);
2201 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2203 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2204 s
->left_overhang
= -metrics.lbearing
;
2206 = metrics.rbearing
> metrics.width
2207 ? metrics.rbearing
- metrics.width
: 0;
2211 s
->left_overhang
= 0;
2212 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2213 FONT_HEIGHT
(font
) * 0.2 : 0;
2219 /* ==========================================================================
2221 Fringe and cursor drawing
2223 ========================================================================== */
2226 extern int max_used_fringe_bitmap
;
2228 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2229 struct draw_fringe_bitmap_params
*p
)
2230 /* --------------------------------------------------------------------------
2231 External (RIF); fringe-related
2232 -------------------------------------------------------------------------- */
2234 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2235 struct face
*face
= p
->face
;
2237 static EmacsImage
**bimgs
= NULL;
2238 static int nBimgs
= 0;
2240 /* grow bimgs if needed */
2241 if (nBimgs
< max_used_fringe_bitmap
)
2243 bimgs
= xrealloc
(bimgs
, max_used_fringe_bitmap
* sizeof
*bimgs
);
2244 memset
(bimgs
+ nBimgs
, 0,
2245 (max_used_fringe_bitmap
- nBimgs
) * sizeof
*bimgs
);
2246 nBimgs
= max_used_fringe_bitmap
;
2249 /* Must clip because of partially visible lines. */
2250 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2251 ns_clip_to_row
(w
, row
, -1, YES
);
2255 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
2257 /* If the fringe is adjacent to the left (right) scroll bar of a
2258 leftmost (rightmost, respectively) window, then extend its
2259 background to the gap between the fringe and the bar. */
2260 if ((WINDOW_LEFTMOST_P
(w
)
2261 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(w
))
2262 ||
(WINDOW_RIGHTMOST_P
(w
)
2263 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT
(w
)))
2265 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH
(w
);
2269 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X
(w
);
2270 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS
(w
)
2271 * FRAME_COLUMN_WIDTH
(f
));
2275 /* Bitmap fills the fringe. */
2276 if (bar_area_x
+ bar_area_width
== p
->x
)
2277 bx
= bar_area_x
+ sb_width
;
2278 else if (p
->x
+ p
->wd
== bar_area_x
)
2282 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT
(w
);
2284 nx
= bar_area_width
- sb_width
;
2285 by
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (header_line_height
,
2287 ny
= row
->visible_height
;
2292 if (bar_area_x
+ bar_area_width
== bx
)
2294 bx
= bar_area_x
+ sb_width
;
2295 nx
+= bar_area_width
- sb_width
;
2297 else if (bx
+ nx
== bar_area_x
)
2298 nx
+= bar_area_width
- sb_width
;
2303 if (bx
>= 0 && nx
> 0)
2305 NSRect r
= NSMakeRect
(bx
, by
, nx
, ny
);
2307 [ns_lookup_indexed_color
(face
->background
, f
) set];
2314 NSRect r
= NSMakeRect
(p
->x
, p
->y
, p
->wd
, p
->h
);
2315 EmacsImage
*img
= bimgs
[p
->which - 1];
2319 unsigned short
*bits
= p
->bits
+ p
->dh
;
2322 unsigned
char *cbits
= xmalloc
(len
);
2324 for (i
= 0; i
< len
; i
++)
2325 cbits
[i
] = ~
(bits
[i
] & 0xff);
2326 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2328 bimgs
[p
->which - 1] = img
;
2333 /* Since we composite the bitmap instead of just blitting it, we need
2334 to erase the whole background. */
2335 [ns_lookup_indexed_color
(face
->background
, f
) set];
2337 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2338 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
2340 fromRect
: NSZeroRect
2341 operation
: NSCompositeSourceOver
2347 NSPoint pt
= r.origin
;
2349 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2358 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2359 int x
, int y
, int cursor_type
, int cursor_width
,
2360 int on_p
, int active_p
)
2361 /* --------------------------------------------------------------------------
2362 External call (RIF): draw cursor.
2363 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2364 -------------------------------------------------------------------------- */
2367 int fx
, fy
, h
, cursor_height
;
2368 struct frame
*f
= WINDOW_XFRAME
(w
);
2369 struct glyph
*phys_cursor_glyph
;
2371 struct glyph
*cursor_glyph
;
2373 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2375 /* If cursor is out of bounds, don't draw garbage. This can happen
2376 in mini-buffer windows when switching between echo area glyphs
2379 NSTRACE
(dumpcursor
);
2384 w
->phys_cursor_type
= cursor_type
;
2385 w
->phys_cursor_on_p
= on_p
;
2387 if (cursor_type
== NO_CURSOR
)
2389 w
->phys_cursor_width
= 0;
2393 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2395 if (glyph_row
->exact_window_width_line_p
2396 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2398 glyph_row
->cursor_in_fringe_p
= 1;
2399 draw_fringe_bitmap
(w
, glyph_row
, 0);
2404 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2405 (other terminals do it the other way round). We must set
2406 w->phys_cursor_width to the cursor width. For bar cursors, that
2407 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2408 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2410 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2411 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2412 if (cursor_type
== BAR_CURSOR
)
2414 if (cursor_width
< 1)
2415 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2416 w
->phys_cursor_width
= cursor_width
;
2418 /* If we have an HBAR, "cursor_width" MAY specify height. */
2419 else if (cursor_type
== HBAR_CURSOR
)
2421 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2422 fy
+= h
- cursor_height
;
2426 r.origin.x
= fx
, r.origin.y
= fy
;
2428 r.
size.width
= w
->phys_cursor_width
;
2430 /* TODO: only needed in rare cases with last-resort font in HELLO..
2431 should we do this more efficiently? */
2432 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2435 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2436 if (face
&& NS_FACE_BACKGROUND
(face
)
2437 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2439 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2440 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2443 [FRAME_CURSOR_COLOR
(f
) set];
2445 #ifdef NS_IMPL_COCOA
2446 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2447 atomic. Cleaner ways of doing this should be investigated.
2448 One way would be to set a global variable DRAWING_CURSOR
2449 when making the call to draw_phys..(), don't focus in that
2450 case, then move the ns_unfocus() here after that call. */
2451 NSDisableScreenUpdates
();
2454 switch (cursor_type
)
2458 case FILLED_BOX_CURSOR
:
2461 case HOLLOW_BOX_CURSOR
:
2464 NSRectFill
(NSInsetRect
(r
, 1, 1));
2465 [FRAME_CURSOR_COLOR
(f
) set];
2472 /* If the character under cursor is R2L, draw the bar cursor
2473 on the right of its glyph, rather than on the left. */
2474 cursor_glyph
= get_phys_cursor_glyph
(w
);
2475 if ((cursor_glyph
->resolved_level
& 1) != 0)
2476 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2483 /* draw the character under the cursor */
2484 if (cursor_type
!= NO_CURSOR
)
2485 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2487 #ifdef NS_IMPL_COCOA
2488 NSEnableScreenUpdates
();
2495 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2496 /* --------------------------------------------------------------------------
2497 External (RIF): Draw a vertical line.
2498 -------------------------------------------------------------------------- */
2500 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2502 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2504 NSTRACE
(ns_draw_vertical_window_border
);
2506 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2508 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2510 ns_focus
(f
, &r
, 1);
2517 show_hourglass
(struct atimer
*timer
)
2519 if (hourglass_shown_p
)
2524 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2526 hourglass_shown_p
= 1;
2532 hide_hourglass
(void
)
2534 if (!hourglass_shown_p
)
2539 /* TODO: remove NSProgressIndicator from all frames */
2541 hourglass_shown_p
= 0;
2547 /* ==========================================================================
2549 Glyph drawing operations
2551 ========================================================================== */
2554 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2555 /* --------------------------------------------------------------------------
2556 Wrapper utility to account for internal border width on full-width lines,
2557 and allow top full-width rows to hit the frame top. nr should be pointer
2558 to two successive NSRects. Number of rects actually used is returned.
2559 -------------------------------------------------------------------------- */
2561 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2565 /* --------------------------------------------------------------------
2566 Draw a wavy line under glyph string s. The wave fills wave_height
2573 wave_height = 3 | * * * *
2574 --------------------------------------------------------------------- */
2577 ns_draw_underwave
(struct glyph_string
*s
, CGFloat width
, CGFloat x
)
2579 int wave_height
= 3, wave_length
= 2;
2580 int y
, dx
, dy
, odd
, xmax
;
2585 dy
= wave_height
- 1;
2586 y
= s
->ybase
- wave_height
+ 3;
2589 /* Find and set clipping rectangle */
2590 waveClip
= NSMakeRect
(x
, y
, width
, wave_height
);
2591 [[NSGraphicsContext currentContext
] saveGraphicsState
];
2592 NSRectClip
(waveClip
);
2594 /* Draw the waves */
2595 a.x
= x
- ((int
)(x
) % dx) + 0.5;
2597 odd
= (int
)(a.x
/dx
) % 2;
2598 a.y
= b.y
= y
+ 0.5;
2607 [NSBezierPath strokeLineFromPoint
:a toPoint
:b
];
2608 a.x
= b.x
, a.y
= b.y
;
2609 b.x
+= dx
, b.y
= y
+ 0.5 + odd
*dy
;
2613 /* Restore previous clipping rectangle(s) */
2614 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
2620 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2621 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2622 /* --------------------------------------------------------------------------
2623 Draw underline, overline, and strike-through on glyph string s.
2624 -------------------------------------------------------------------------- */
2626 if (s
->for_overlaps
)
2630 if (face
->underline_p
)
2632 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2634 if (face
->underline_defaulted_p
)
2637 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2639 ns_draw_underwave
(s
, width
, x
);
2641 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2645 unsigned
long thickness
, position
;
2647 /* If the prev was underlined, match its appearance. */
2648 if (s
->prev
&& s
->prev
->face
->underline_p
2649 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
2650 && s
->prev
->underline_thickness
> 0)
2652 thickness
= s
->prev
->underline_thickness
;
2653 position
= s
->prev
->underline_position
;
2658 unsigned
long descent
;
2661 descent
= s
->y
+ s
->height
- s
->ybase
;
2663 /* Use underline thickness of font, defaulting to 1. */
2664 thickness
= (font
&& font
->underline_thickness
> 0)
2665 ? font
->underline_thickness
: 1;
2667 /* Determine the offset of underlining from the baseline. */
2668 if (x_underline_at_descent_line
)
2669 position
= descent
- thickness
;
2670 else if (x_use_underline_position_properties
2671 && font
&& font
->underline_position
>= 0)
2672 position
= font
->underline_position
;
2674 position
= lround
(font
->descent
/ 2);
2676 position
= underline_minimum_offset
;
2678 position
= max (position
, underline_minimum_offset
);
2680 /* Ensure underlining is not cropped. */
2681 if (descent
<= position
)
2683 position
= descent
- 1;
2686 else if (descent
< position
+ thickness
)
2690 s
->underline_thickness
= thickness
;
2691 s
->underline_position
= position
;
2693 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2695 if (face
->underline_defaulted_p
)
2698 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2702 /* Do overline. We follow other terms in using a thickness of 1
2703 and ignoring overline_margin. */
2704 if (face
->overline_p
)
2707 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2709 if (face
->overline_color_defaulted_p
)
2712 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2716 /* Do strike-through. We follow other terms for thickness and
2717 vertical position.*/
2718 if (face
->strike_through_p
)
2723 dy
= lrint
((s
->height
- 1) / 2);
2724 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2726 if (face
->strike_through_color_defaulted_p
)
2729 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2735 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2736 /* --------------------------------------------------------------------------
2737 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2738 Note we can't just use an NSDrawRect command, because of the possibility
2739 of some sides not being drawn, and because the rect will be filled.
2740 -------------------------------------------------------------------------- */
2746 s.
size.height
= thickness
;
2748 s.origin.y
+= r.
size.height
- thickness
;
2751 s.
size.height
= r.
size.height
;
2752 s.origin.y
= r.origin.y
;
2754 /* left, right (optional) */
2755 s.
size.width
= thickness
;
2760 s.origin.x
+= r.
size.width
- thickness
;
2767 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2768 char top_p
, char bottom_p
, char left_p
, char right_p
,
2769 struct glyph_string
*s
)
2770 /* --------------------------------------------------------------------------
2771 Draw a relief rect inside r, optionally leaving some sides open.
2772 Note we can't just use an NSDrawBezel command, because of the possibility
2773 of some sides not being drawn, and because the rect will be filled.
2774 -------------------------------------------------------------------------- */
2776 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2777 NSColor
*newBaseCol
= nil
;
2780 NSTRACE
(ns_draw_relief
);
2784 if (s
->face
->use_box_color_for_shadows_p
)
2786 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2788 /* else if (s->first_glyph->type == IMAGE_GLYPH
2790 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2792 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2796 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2799 if (newBaseCol
== nil
)
2800 newBaseCol
= [NSColor grayColor
];
2802 if (newBaseCol
!= baseCol
) /* TODO: better check */
2805 baseCol
= [newBaseCol retain
];
2807 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2809 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2812 [(raised_p ? lightCol
: darkCol
) set];
2814 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2817 sr.
size.height
= thickness
;
2818 if (top_p
) NSRectFill
(sr
);
2821 sr.
size.height
= r.
size.height
;
2822 sr.
size.width
= thickness
;
2823 if (left_p
) NSRectFill
(sr
);
2825 [(raised_p ? darkCol
: lightCol
) set];
2828 sr.
size.width
= r.
size.width
;
2829 sr.
size.height
= thickness
;
2830 sr.origin.y
+= r.
size.height
- thickness
;
2831 if (bottom_p
) NSRectFill
(sr
);
2834 sr.
size.height
= r.
size.height
;
2835 sr.origin.y
= r.origin.y
;
2836 sr.
size.width
= thickness
;
2837 sr.origin.x
+= r.
size.width
- thickness
;
2838 if (right_p
) NSRectFill
(sr
);
2843 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2844 /* --------------------------------------------------------------------------
2845 Function modeled after x_draw_glyph_string_box ().
2846 Sets up parameters for drawing.
2847 -------------------------------------------------------------------------- */
2849 int right_x
, last_x
;
2850 char left_p
, right_p
;
2851 struct glyph
*last_glyph
;
2856 if (s
->hl
== DRAW_MOUSE_FACE
)
2858 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2860 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2865 thickness
= face
->box_line_width
;
2867 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2869 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2870 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2871 : window_box_right
(s
->w
, s
->area
));
2872 last_glyph
= (s
->cmp || s
->img
2873 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2875 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2876 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2878 left_p
= (s
->first_glyph
->left_box_line_p
2879 ||
(s
->hl
== DRAW_MOUSE_FACE
2880 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2881 right_p
= (last_glyph
->right_box_line_p
2882 ||
(s
->hl
== DRAW_MOUSE_FACE
2883 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2885 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2887 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2888 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2890 ns_draw_box
(r
, abs (thickness
),
2891 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2896 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2897 1, 1, left_p
, right_p
, s
);
2903 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2904 /* --------------------------------------------------------------------------
2905 Modeled after x_draw_glyph_string_background, which draws BG in
2906 certain cases. Others are left to the text rendering routine.
2907 -------------------------------------------------------------------------- */
2909 NSTRACE
(ns_maybe_dumpglyphs_background
);
2911 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2913 int box_line_width
= max (s
->face
->box_line_width
, 0);
2914 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2915 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2918 if (s
->hl
== DRAW_MOUSE_FACE
)
2920 face
= FACE_FROM_ID
(s
->f
,
2921 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2923 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2926 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2928 [(NS_FACE_BACKGROUND
(face
) != 0
2929 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2930 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2933 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2934 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2937 if (s
->hl
!= DRAW_CURSOR
)
2939 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2940 s
->background_width
,
2941 s
->height
-2*box_line_width
);
2945 s
->background_filled_p
= 1;
2952 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2953 /* --------------------------------------------------------------------------
2954 Renders an image and associated borders.
2955 -------------------------------------------------------------------------- */
2957 EmacsImage
*img
= s
->img
->pixmap
;
2958 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2959 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2960 int bg_x
, bg_y
, bg_height
;
2967 NSTRACE
(ns_dumpglyphs_image
);
2969 if (s
->face
->box
!= FACE_NO_BOX
2970 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
2971 x
+= abs (s
->face
->box_line_width
);
2974 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
2975 bg_height
= s
->height
;
2976 /* other terms have this, but was causing problems w/tabbar mode */
2977 /* - 2 * box_line_vwidth; */
2979 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
2980 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
2982 /* Draw BG: if we need larger area than image itself cleared, do that,
2983 otherwise, since we composite the image under NS (instead of mucking
2984 with its background color), we must clear just the image area. */
2985 if (s
->hl
== DRAW_MOUSE_FACE
)
2987 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2989 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2992 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2994 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
2996 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
2997 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
2999 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
3000 s
->background_filled_p
= 1;
3004 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3009 /* Draw the image.. do we need to draw placeholder if img ==nil? */
3012 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
3013 NSRect dr
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3014 NSRect ir
= NSMakeRect
(s
->slice.x
, s
->slice.y
,
3015 s
->slice.width
, s
->slice.height
);
3018 operation
: NSCompositeSourceOver
3023 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
3024 operation
: NSCompositeSourceOver
];
3028 if (s
->hl
== DRAW_CURSOR
)
3030 [FRAME_CURSOR_COLOR
(s
->f
) set];
3031 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3032 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3034 /* Currently on NS img->mask is always 0. Since
3035 get_window_cursor_type specifies a hollow box cursor when on
3036 a non-masked image we never reach this clause. But we put it
3037 in in anticipation of better support for image masks on
3039 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3043 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3046 /* Draw underline, overline, strike-through. */
3047 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3049 /* Draw relief, if requested */
3050 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3052 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3054 th
= tool_bar_button_relief
>= 0 ?
3055 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3056 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3060 th
= abs (s
->img
->relief
);
3061 raised_p
= (s
->img
->relief
> 0);
3064 r.origin.x
= x
- th
;
3065 r.origin.y
= y
- th
;
3066 r.
size.width
= s
->slice.width
+ 2*th
-1;
3067 r.
size.height
= s
->slice.height
+ 2*th
-1;
3068 ns_draw_relief
(r
, th
, raised_p
,
3070 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3072 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3075 /* If there is no mask, the background won't be seen,
3076 so draw a rectangle on the image for the cursor.
3077 Do this for all images, getting transparency right is not reliable. */
3078 if (s
->hl
== DRAW_CURSOR
)
3080 int thickness
= abs (s
->img
->relief
);
3081 if (thickness
== 0) thickness
= 1;
3082 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3088 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3093 NSColor
*fgCol
, *bgCol
;
3095 if (!s
->background_filled_p
)
3097 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3098 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3100 ns_focus
(s
->f
, r
, n
);
3102 if (s
->hl
== DRAW_MOUSE_FACE
)
3104 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3106 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3109 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3111 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3112 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3114 for (i
= 0; i
< n
; ++i
)
3116 if (!s
->row
->full_width_p
)
3118 int overrun
, leftoverrun
;
3120 /* truncate to avoid overwriting fringe and/or scrollbar */
3121 overrun
= max (0, (s
->x
+ s
->background_width
)
3122 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3123 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3124 r
[i
].
size.width
-= overrun
;
3126 /* truncate to avoid overwriting to left of the window box */
3127 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3128 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3130 if (leftoverrun
> 0)
3132 r
[i
].origin.x
+= leftoverrun
;
3133 r
[i
].
size.width
-= leftoverrun
;
3136 /* XXX: Try to work between problem where a stretch glyph on
3137 a partially-visible bottom row will clear part of the
3138 modeline, and another where list-buffers headers and similar
3139 rows erroneously have visible_height set to 0. Not sure
3140 where this is coming from as other terms seem not to show. */
3141 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3146 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3147 overwriting cursor (usually when cursor on a tab) */
3148 if (s
->hl
== DRAW_CURSOR
)
3153 width
= s
->w
->phys_cursor_width
;
3154 r
[i
].
size.width
-= width
;
3155 r
[i
].origin.x
+= width
;
3159 /* Draw overlining, etc. on the cursor. */
3160 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3161 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3163 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3170 /* Draw overlining, etc. on the stretch glyph (or the part
3171 of the stretch glyph after the cursor). */
3172 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3176 s
->background_filled_p
= 1;
3182 ns_draw_glyph_string
(struct glyph_string
*s
)
3183 /* --------------------------------------------------------------------------
3184 External (RIF): Main draw-text call.
3185 -------------------------------------------------------------------------- */
3187 /* TODO (optimize): focus for box and contents draw */
3190 char box_drawn_p
= 0;
3192 NSTRACE
(ns_draw_glyph_string
);
3194 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3197 struct glyph_string
*next
;
3199 for (width
= 0, next
= s
->next
;
3200 next
&& width
< s
->right_overhang
;
3201 width
+= next
->width
, next
= next
->next
)
3202 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3204 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3206 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3207 ns_focus
(s
->f
, r
, n
);
3208 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3213 ns_dumpglyphs_stretch
(s
->next
);
3215 next
->num_clips
= 0;
3219 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3220 && (s
->first_glyph
->type == CHAR_GLYPH
3221 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3223 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3224 ns_focus
(s
->f
, r
, n
);
3225 ns_maybe_dumpglyphs_background
(s
, 1);
3226 ns_dumpglyphs_box_or_relief
(s
);
3231 switch (s
->first_glyph
->type)
3235 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3236 ns_focus
(s
->f
, r
, n
);
3237 ns_dumpglyphs_image
(s
, r
[0]);
3242 ns_dumpglyphs_stretch
(s
);
3246 case COMPOSITE_GLYPH
:
3247 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3248 ns_focus
(s
->f
, r
, n
);
3250 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3251 && ! s
->first_glyph
->u.cmp.automatic
))
3252 s
->background_filled_p
= 1;
3254 ns_maybe_dumpglyphs_background
3255 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3257 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3258 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3259 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3260 NS_DUMPGLYPH_NORMAL
));
3261 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3262 if (ns_tmp_font
== NULL)
3263 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3265 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3267 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3268 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3269 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3272 ns_tmp_font
->font.driver
->draw
3273 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3274 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3275 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
3277 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3279 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3280 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3281 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3287 case GLYPHLESS_GLYPH
:
3288 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3289 ns_focus
(s
->f
, r
, n
);
3291 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3292 && ! s
->first_glyph
->u.cmp.automatic
))
3293 s
->background_filled_p
= 1;
3295 ns_maybe_dumpglyphs_background
3296 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3298 /* Not yet implemented. */
3307 /* Draw box if not done already. */
3308 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3310 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3311 ns_focus
(s
->f
, r
, n
);
3312 ns_dumpglyphs_box_or_relief
(s
);
3321 /* ==========================================================================
3325 ========================================================================== */
3329 ns_send_appdefined
(int value
)
3330 /* --------------------------------------------------------------------------
3331 Internal: post an appdefined event which EmacsApp-sendEvent will
3332 recognize and take as a command to halt the event loop.
3333 -------------------------------------------------------------------------- */
3335 /*NSTRACE (ns_send_appdefined); */
3337 /* Only post this event if we haven't already posted one. This will end
3338 the [NXApp run] main loop after having processed all events queued at
3340 if (send_appdefined
)
3344 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3345 send_appdefined
= NO
;
3347 /* Don't need wakeup timer any more */
3350 [timed_entry invalidate
];
3351 [timed_entry release
];
3355 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3356 location
: NSMakePoint
(0, 0)
3359 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3360 context
: [NSApp context
]
3365 /* Post an application defined event on the event queue. When this is
3366 received the [NXApp run] will return, thus having processed all
3367 events which are currently queued. */
3368 [NSApp postEvent
: nxev atStart
: NO
];
3373 ns_read_socket
(struct terminal *terminal, struct input_event
*hold_quit
)
3374 /* --------------------------------------------------------------------------
3375 External (hook): Post an event to ourself and keep reading events until
3376 we read it back again. In effect process all events which were waiting.
3377 From 21+ we have to manage the event buffer ourselves.
3378 -------------------------------------------------------------------------- */
3380 struct input_event ev
;
3383 /* NSTRACE (ns_read_socket); */
3385 if ([NSApp modalWindow
] != nil
)
3388 if (hold_event_q.nr
> 0)
3391 for (i
= 0; i
< hold_event_q.nr
; ++i
)
3392 kbd_buffer_store_event_hold
(&hold_event_q.q
[i
], hold_quit
);
3393 hold_event_q.nr
= 0;
3398 n_emacs_events_pending
= 0;
3401 q_event_ptr
= hold_quit
;
3403 /* we manage autorelease pools by allocate/reallocate each time around
3404 the loop; strict nesting is occasionally violated but seems not to
3405 matter.. earlier methods using full nesting caused major memory leaks */
3406 [outerpool release
];
3407 outerpool
= [[NSAutoreleasePool alloc
] init
];
3409 /* If have pending open-file requests, attend to the next one of those. */
3410 if (ns_pending_files
&& [ns_pending_files count
] != 0
3411 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3413 [ns_pending_files removeObjectAtIndex
: 0];
3415 /* Deal with pending service requests. */
3416 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3418 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3419 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3421 [ns_pending_service_names removeObjectAtIndex
: 0];
3422 [ns_pending_service_args removeObjectAtIndex
: 0];
3426 /* Run and wait for events. We must always send one NX_APPDEFINED event
3427 to ourself, otherwise [NXApp run] will never exit. */
3428 send_appdefined
= YES
;
3429 ns_send_appdefined
(-1);
3431 if (++apploopnr
!= 1)
3439 nevents
= n_emacs_events_pending
;
3440 n_emacs_events_pending
= 0;
3441 emacs_event
= q_event_ptr
= NULL;
3449 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3450 fd_set
*exceptfds
, EMACS_TIME
*timeout
, sigset_t
*sigmask
)
3451 /* --------------------------------------------------------------------------
3452 Replacement for select, checking for events
3453 -------------------------------------------------------------------------- */
3457 struct input_event event
;
3460 /* NSTRACE (ns_select); */
3462 if (hold_event_q.nr
> 0)
3464 /* We already have events pending. */
3470 for (k
= 0; k
< nfds
+1; k
++)
3472 if (readfds
&& FD_ISSET
(k
, readfds
)) ++nr
;
3473 if (writefds
&& FD_ISSET
(k
, writefds
)) ++nr
;
3477 ||
(timeout
&& timeout
->tv_sec
== 0 && timeout
->tv_nsec
== 0))
3478 return pselect
(nfds
, readfds
, writefds
, exceptfds
, timeout
, sigmask
);
3480 [outerpool release
];
3481 outerpool
= [[NSAutoreleasePool alloc
] init
];
3484 send_appdefined
= YES
;
3487 pthread_mutex_lock
(&select_mutex
);
3492 select_readfds
= *readfds
;
3493 select_valid
+= SELECT_HAVE_READ
;
3497 select_writefds
= *writefds
;
3498 select_valid
+= SELECT_HAVE_WRITE
;
3503 select_timeout
= *timeout
;
3504 select_valid
+= SELECT_HAVE_TMO
;
3507 pthread_mutex_unlock
(&select_mutex
);
3509 /* Inform fd_handler that select should be called */
3511 emacs_write
(selfds
[1], &c
, 1);
3513 else if (nr
== 0 && timeout
)
3515 /* No file descriptor, just a timeout, no need to wake fd_handler */
3516 double time
= EMACS_TIME_TO_DOUBLE
(*timeout
);
3517 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3520 @selector
(timeout_handler
:)
3525 else /* No timeout and no file descriptors, can this happen? */
3527 /* Send appdefined so we exit from the loop */
3528 ns_send_appdefined
(-1);
3533 emacs_event
= &event
;
3534 if (++apploopnr
!= 1)
3541 if (nr
> 0 && readfds
)
3544 emacs_write
(selfds
[1], &c
, 1);
3548 t
= last_appdefined_event_data
;
3550 if (t
!= NO_APPDEFINED_DATA
)
3552 last_appdefined_event_data
= NO_APPDEFINED_DATA
;
3556 /* The NX_APPDEFINED event we received was a timeout. */
3561 /* The NX_APPDEFINED event we received was the result of
3562 at least one real input event arriving. */
3568 /* Received back from select () in fd_handler; copy the results */
3569 pthread_mutex_lock
(&select_mutex
);
3570 if (readfds
) *readfds
= select_readfds
;
3571 if (writefds
) *writefds
= select_writefds
;
3572 if (timeout
) *timeout
= select_timeout
;
3573 pthread_mutex_unlock
(&select_mutex
);
3583 /* ==========================================================================
3587 ========================================================================== */
3591 ns_set_vertical_scroll_bar
(struct window
*window
,
3592 int portion
, int whole
, int position
)
3593 /* --------------------------------------------------------------------------
3594 External (hook): Update or add scrollbar
3595 -------------------------------------------------------------------------- */
3599 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3600 EmacsView
*view = FRAME_NS_VIEW
(f
);
3601 int window_y
, window_height
;
3602 int top
, left
, height
, width
, sb_width
, sb_left
;
3604 BOOL fringe_extended_p
;
3606 /* optimization; display engine sends WAY too many of these.. */
3607 if (!NILP
(window
->vertical_scroll_bar
))
3609 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3610 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3612 if (view->scrollbarsNeedingUpdate
== 0)
3614 if (!windows_or_buffers_changed
)
3618 view->scrollbarsNeedingUpdate
--;
3622 NSTRACE
(ns_set_vertical_scroll_bar
);
3624 /* Get dimensions. */
3625 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3627 height
= window_height
;
3628 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3629 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3631 /* allow for displaying a skinnier scrollbar than char area allotted */
3632 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3633 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3636 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3637 /* the parent view is flipped, so we need to flip y value */
3639 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3641 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(window
))
3642 fringe_extended_p
= (WINDOW_LEFTMOST_P
(window
)
3643 && WINDOW_LEFT_FRINGE_WIDTH
(window
)
3644 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3645 || WINDOW_LEFT_MARGIN_COLS
(window
) == 0));
3647 fringe_extended_p
= (WINDOW_RIGHTMOST_P
(window
)
3648 && WINDOW_RIGHT_FRINGE_WIDTH
(window
)
3649 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3650 || WINDOW_RIGHT_MARGIN_COLS
(window
) == 0));
3652 XSETWINDOW
(win
, window
);
3655 /* we want at least 5 lines to display a scrollbar */
3656 if (WINDOW_TOTAL_LINES
(window
) < 5)
3658 if (!NILP
(window
->vertical_scroll_bar
))
3660 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3661 [bar removeFromSuperview
];
3662 wset_vertical_scroll_bar
(window
, Qnil
);
3664 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3669 if (NILP
(window
->vertical_scroll_bar
))
3671 if (width
> 0 && height
> 0)
3673 if (fringe_extended_p
)
3674 ns_clear_frame_area
(f
, sb_left
, top
, sb_width
, height
);
3676 ns_clear_frame_area
(f
, left
, top
, width
, height
);
3679 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3680 wset_vertical_scroll_bar
(window
, make_save_value
(bar, 0));
3685 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3686 oldRect
= [bar frame
];
3687 r.
size.width
= oldRect.
size.width
;
3688 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3690 if (oldRect.origin.x
!= r.origin.x
)
3691 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3696 [bar setPosition
: position portion
: portion whole
: whole
];
3702 ns_condemn_scroll_bars
(struct frame
*f
)
3703 /* --------------------------------------------------------------------------
3704 External (hook): arrange for all frame's scrollbars to be removed
3705 at next call to judge_scroll_bars, except for those redeemed.
3706 -------------------------------------------------------------------------- */
3710 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3712 NSTRACE
(ns_condemn_scroll_bars
);
3714 for (i
=[subviews count
]-1; i
>= 0; i
--)
3716 view = [subviews objectAtIndex
: i
];
3717 if ([view isKindOfClass
: [EmacsScroller
class]])
3724 ns_redeem_scroll_bar
(struct window
*window
)
3725 /* --------------------------------------------------------------------------
3726 External (hook): arrange to spare this window's scrollbar
3727 at next call to judge_scroll_bars.
3728 -------------------------------------------------------------------------- */
3731 NSTRACE
(ns_redeem_scroll_bar
);
3732 if (!NILP
(window
->vertical_scroll_bar
))
3734 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3741 ns_judge_scroll_bars
(struct frame
*f
)
3742 /* --------------------------------------------------------------------------
3743 External (hook): destroy all scrollbars on frame that weren't
3744 redeemed after call to condemn_scroll_bars.
3745 -------------------------------------------------------------------------- */
3749 EmacsView
*eview
= FRAME_NS_VIEW
(f
);
3750 NSArray
*subviews
= [[eview superview
] subviews
];
3753 NSTRACE
(ns_judge_scroll_bars
);
3754 for (i
= [subviews count
]-1; i
>= 0; --i
)
3756 view = [subviews objectAtIndex
: i
];
3757 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3763 [eview updateFrameSize
: NO
];
3768 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3770 /* XXX irrelevant under NS */
3775 /* ==========================================================================
3779 ========================================================================== */
3782 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3784 NSScreen
*screen
= [NSScreen mainScreen
];
3785 return [screen frame
].
size.height
;
3789 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3791 NSScreen
*screen
= [NSScreen mainScreen
];
3792 return [screen frame
].
size.width
;
3796 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3797 /* --------------------------------------------------------------------------
3798 Convert modifier name to lisp symbol
3799 -------------------------------------------------------------------------- */
3801 if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3803 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3805 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3807 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3809 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3811 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3819 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3820 Lisp_Object yesval
, Lisp_Object noval
,
3821 BOOL is_float
, BOOL is_modstring
)
3822 /* --------------------------------------------------------------------------
3823 Check a parameter value in user's preferences
3824 -------------------------------------------------------------------------- */
3826 const
char *value
= ns_get_defaults_value
(parameter
);
3832 if (c_strcasecmp
(value
, "YES"
) == 0)
3834 else if (c_strcasecmp
(value
, "NO"
) == 0)
3836 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3837 *result
= make_float
(f
);
3838 else if (is_modstring
&& value
)
3839 *result
= ns_string_to_lispmod
(value
);
3840 else fprintf (stderr
,
3841 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3847 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3848 /* --------------------------------------------------------------------------
3849 Initialize global info and storage for display.
3850 -------------------------------------------------------------------------- */
3852 NSScreen
*screen
= [NSScreen mainScreen
];
3853 NSWindowDepth depth
= [screen depth
];
3854 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
3856 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3857 dpyinfo
->resy
= 72.27;
3858 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3859 NSColorSpaceFromDepth
(depth
)]
3860 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3861 NSColorSpaceFromDepth
(depth
)];
3862 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3863 dpyinfo
->image_cache
= make_image_cache
();
3864 dpyinfo
->color_table
= xmalloc
(sizeof
*dpyinfo
->color_table
);
3865 dpyinfo
->color_table
->colors
= NULL;
3866 dpyinfo
->root_window
= 42; /* a placeholder.. */
3868 hlinfo
->mouse_face_mouse_frame
= NULL;
3869 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
3870 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
3871 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3872 hlinfo
->mouse_face_window
= hlinfo
->mouse_face_overlay
= Qnil
;
3873 hlinfo
->mouse_face_hidden
= 0;
3875 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
3876 hlinfo
->mouse_face_defer
= 0;
3878 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3880 dpyinfo
->n_fonts
= 0;
3881 dpyinfo
->smallest_font_height
= 1;
3882 dpyinfo
->smallest_char_width
= 1;
3886 /* This and next define (many of the) public functions in this file. */
3887 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3888 with using despite presence in the "system dependent" redisplay
3889 interface. In addition, many of the ns_ methods have code that is
3890 shared with all terms, indicating need for further refactoring. */
3891 extern frame_parm_handler ns_frame_parm_handlers
[];
3892 static
struct redisplay_interface ns_redisplay_interface
=
3894 ns_frame_parm_handlers
,
3898 x_clear_end_of_line
,
3900 ns_after_update_window_line
,
3901 ns_update_window_begin
,
3902 ns_update_window_end
,
3905 0, /* flush_display_optional */
3906 x_clear_window_mouse_face
,
3907 x_get_glyph_overhangs
,
3908 x_fix_overlapping_area
,
3909 ns_draw_fringe_bitmap
,
3910 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3911 0, /* destroy_fringe_bitmap */
3912 ns_compute_glyph_string_overhangs
,
3913 ns_draw_glyph_string
, /* interface to nsfont.m */
3914 ns_define_frame_cursor
,
3915 ns_clear_frame_area
,
3916 ns_draw_window_cursor
,
3917 ns_draw_vertical_window_border
,
3918 ns_shift_glyphs_for_insert
3923 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3929 /* This function is called when the last frame on a display is deleted. */
3931 ns_delete_terminal
(struct terminal *terminal)
3933 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3935 /* Protect against recursive calls. delete_frame in
3936 delete_terminal calls us back when it deletes our last frame. */
3937 if (!terminal->name
)
3942 x_destroy_all_bitmaps
(dpyinfo
);
3943 ns_delete_display
(dpyinfo
);
3948 static
struct terminal *
3949 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3950 /* --------------------------------------------------------------------------
3951 Set up use of NS before we make the first connection.
3952 -------------------------------------------------------------------------- */
3954 struct terminal *terminal;
3956 NSTRACE
(ns_create_terminal
);
3958 terminal = create_terminal
();
3960 terminal->type = output_ns
;
3961 terminal->display_info.ns
= dpyinfo
;
3962 dpyinfo
->terminal = terminal;
3964 terminal->rif
= &ns_redisplay_interface
;
3966 terminal->clear_frame_hook
= ns_clear_frame
;
3967 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
3968 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
3969 terminal->ring_bell_hook
= ns_ring_bell
;
3970 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
3971 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
3972 terminal->update_begin_hook
= ns_update_begin
;
3973 terminal->update_end_hook
= ns_update_end
;
3974 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
3975 terminal->read_socket_hook
= ns_read_socket
;
3976 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
3977 terminal->mouse_position_hook
= ns_mouse_position
;
3978 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
3979 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
3981 terminal->fullscreen_hook
= ns_fullscreen_hook
;
3983 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
3984 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
3985 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
3986 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
3988 terminal->delete_frame_hook
= x_destroy_window
;
3989 terminal->delete_terminal_hook
= ns_delete_terminal
;
3991 terminal->scroll_region_ok
= 1;
3992 terminal->char_ins_del_ok
= 1;
3993 terminal->line_ins_del_ok
= 1;
3994 terminal->fast_clear_end_of_line
= 1;
3995 terminal->memory_below_frame
= 0;
4001 struct ns_display_info
*
4002 ns_term_init
(Lisp_Object display_name
)
4003 /* --------------------------------------------------------------------------
4004 Start the Application and get things rolling.
4005 -------------------------------------------------------------------------- */
4007 struct terminal *terminal;
4008 struct ns_display_info
*dpyinfo
;
4009 static int ns_initialized
= 0;
4012 if (ns_initialized
) return x_display_list
;
4015 NSTRACE
(ns_term_init
);
4017 [outerpool release
];
4018 outerpool
= [[NSAutoreleasePool alloc
] init
];
4020 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
4021 /*GSDebugAllocationActive (YES); */
4025 Fset_input_interrupt_mode
(Qnil
);
4027 if (selfds
[0] == -1)
4029 if (pipe
(selfds
) == -1)
4031 fprintf (stderr
, "Failed to create pipe
: %s\n",
4032 emacs_strerror
(errno
));
4036 fcntl
(selfds
[0], F_SETFL
, O_NONBLOCK|fcntl
(selfds
[0], F_GETFL
));
4037 FD_ZERO
(&select_readfds
);
4038 FD_ZERO
(&select_writefds
);
4039 pthread_mutex_init
(&select_mutex
, NULL);
4042 ns_pending_files
= [[NSMutableArray alloc
] init
];
4043 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
4044 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
4046 /* Start app and create the main menu, window, view.
4047 Needs to be here because ns_initialize_display_info () uses AppKit classes.
4048 The view will then ask the NSApp to stop and return to Emacs. */
4049 [EmacsApp sharedApplication
];
4052 [NSApp setDelegate
: NSApp
];
4054 /* Start the select thread. */
4055 [NSThread detachNewThreadSelector
:@selector
(fd_handler
:)
4059 /* debugging: log all notifications */
4060 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4061 selector: @selector (logNotification:)
4062 name: nil object: nil]; */
4064 dpyinfo
= xzalloc
(sizeof
*dpyinfo
);
4066 ns_initialize_display_info
(dpyinfo
);
4067 terminal = ns_create_terminal
(dpyinfo
);
4069 terminal->kboard
= xmalloc
(sizeof
*terminal->kboard
);
4070 init_kboard
(terminal->kboard
);
4071 kset_window_system
(terminal->kboard
, Qns
);
4072 terminal->kboard
->next_kboard
= all_kboards
;
4073 all_kboards
= terminal->kboard
;
4074 /* Don't let the initial kboard remain current longer than necessary.
4075 That would cause problems if a file loaded on startup tries to
4076 prompt in the mini-buffer. */
4077 if (current_kboard
== initial_kboard
)
4078 current_kboard
= terminal->kboard
;
4079 terminal->kboard
->reference_count
++;
4081 dpyinfo
->next
= x_display_list
;
4082 x_display_list
= dpyinfo
;
4084 /* Put it on ns_display_name_list */
4085 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
4086 ns_display_name_list
);
4087 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
4089 terminal->name
= xstrdup
(SSDATA
(display_name
));
4093 if (!inhibit_x_resources
)
4095 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4098 /* this is a standard variable */
4099 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4100 make_float
(10.0), make_float
(6.0), YES
, NO
);
4101 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4104 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
4105 stringForKey
: @"AppleHighlightColor"
];
4106 if (ns_selection_color
== nil
)
4107 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
4110 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4114 Lisp_Object color_file
, color_map
, color
;
4118 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4119 Fsymbol_value
(intern
("data
-directory"
)));
4121 color_map
= Fx_load_color_file
(color_file
);
4122 if (NILP
(color_map
))
4123 fatal
("Could not read
%s.\n", SDATA (color_file));
4125 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4126 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4128 color
= XCAR
(color_map
);
4129 name
= SSDATA
(XCAR
(color
));
4130 c
= XINT
(XCDR
(color
));
4132 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4133 green
: GREEN_FROM_ULONG
(c
) / 255.0
4134 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4136 forKey
: [NSString stringWithUTF8String
: name
]];
4138 [cl writeToFile
: nil
];
4143 #ifdef NS_IMPL_GNUSTEP
4144 Vwindow_system_version
= build_string
(gnustep_base_version
);
4146 /*PSnextrelease (128, c); */
4147 char c
[DBL_BUFSIZE_BOUND
];
4148 int len
= dtoastr
(c
, sizeof c
, 0, 0, NSAppKitVersionNumber
);
4149 Vwindow_system_version
= make_unibyte_string
(c
, len
);
4153 delete_keyboard_wait_descriptor
(0);
4155 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4157 /* Set up OS X app menu */
4158 #ifdef NS_IMPL_COCOA
4162 /* set up the application menu */
4163 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4164 [svcsMenu setAutoenablesItems
: NO
];
4165 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4166 [appMenu setAutoenablesItems
: NO
];
4167 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4168 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4170 [appMenu insertItemWithTitle
: @"About Emacs"
4171 action
: @selector
(orderFrontStandardAboutPanel
:)
4174 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4175 [appMenu insertItemWithTitle
: @"Preferences..."
4176 action
: @selector
(showPreferencesWindow
:)
4179 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4180 item
= [appMenu insertItemWithTitle
: @"Services"
4181 action
: @selector
(menuDown
:)
4184 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4185 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4186 [appMenu insertItemWithTitle
: @"Hide Emacs"
4187 action
: @selector
(hide
:)
4190 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4191 action
: @selector
(hideOtherApplications
:)
4194 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4195 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4196 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4197 action
: @selector
(terminate
:)
4201 item
= [mainMenu insertItemWithTitle
: ns_app_name
4202 action
: @selector
(menuDown
:)
4205 [mainMenu setSubmenu
: appMenu forItem
: item
];
4206 [dockMenu insertItemWithTitle
: @"New Frame"
4207 action
: @selector
(newFrame
:)
4211 [NSApp setMainMenu
: mainMenu
];
4212 [NSApp setAppleMenu
: appMenu
];
4213 [NSApp setServicesMenu
: svcsMenu
];
4214 /* Needed at least on Cocoa, to get dock menu to show windows */
4215 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4217 [[NSNotificationCenter defaultCenter
]
4218 addObserver
: mainMenu
4219 selector
: @selector
(trackingNotification
:)
4220 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4221 [[NSNotificationCenter defaultCenter
]
4222 addObserver
: mainMenu
4223 selector
: @selector
(trackingNotification
:)
4224 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4226 #endif
/* MAC OS X menu setup */
4228 /* Register our external input/output types, used for determining
4229 applicable services and also drag/drop eligibility. */
4230 ns_send_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
] retain
];
4231 ns_return_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
]
4233 ns_drag_types
= [[NSArray arrayWithObjects
:
4235 NSTabularTextPboardType
,
4236 NSFilenamesPboardType
,
4239 NSFontPboardType
, nil
] retain
];
4241 #ifndef NEW_STYLE_FS
4242 /* If fullscreen is in init/default-frame-alist, focus isn't set
4243 right for fullscreen windows, so set this. */
4244 [NSApp activateIgnoringOtherApps
:YES
];
4248 ns_do_open_file
= YES
;
4254 ns_term_shutdown
(int sig
)
4256 [[NSUserDefaults standardUserDefaults
] synchronize
];
4258 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4259 if (STRINGP
(Vauto_save_list_file_name
))
4260 unlink
(SSDATA
(Vauto_save_list_file_name
));
4262 if (sig
== 0 || sig
== SIGTERM
)
4264 [NSApp terminate
: NSApp
];
4266 else // force a stack
trace to happen
4273 /* ==========================================================================
4275 EmacsApp implementation
4277 ========================================================================== */
4280 @implementation EmacsApp
4282 - (void
)logNotification
: (NSNotification
*)notification
4284 const
char *name
= [[notification name
] UTF8String
];
4285 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4286 && !strstr
(name
, "WindowNumber"
))
4287 NSLog
(@"notification
: '%@'"
, [notification name
]);
4291 - (void
)sendEvent
: (NSEvent
*)theEvent
4292 /* --------------------------------------------------------------------------
4293 Called when NSApp is running for each event received. Used to stop
4294 the loop when we choose, since there's no way to just run one iteration.
4295 -------------------------------------------------------------------------- */
4297 int
type = [theEvent
type];
4298 NSWindow
*window
= [theEvent window
];
4299 /* NSTRACE (sendEvent); */
4300 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4302 #ifdef NS_IMPL_COCOA
4303 if (type == NSApplicationDefined
4304 && [theEvent data2
] == NSAPP_DATA2_RUNASSCRIPT
)
4312 if (type == NSCursorUpdate
&& window
== nil
)
4314 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4318 if (type == NSApplicationDefined
)
4320 /* Events posted by ns_send_appdefined interrupt the run loop here.
4321 But, if a modal window is up, an appdefined can still come through,
4322 (e.g., from a makeKeyWindow event) but stopping self also stops the
4323 modal loop. Just defer it until later. */
4324 if ([NSApp modalWindow
] == nil
)
4326 last_appdefined_event_data
= [theEvent data1
];
4331 send_appdefined
= YES
;
4335 [super sendEvent
: theEvent
];
4339 - (void
)showPreferencesWindow
: (id
)sender
4341 struct frame
*emacsframe
= SELECTED_FRAME
();
4342 NSEvent
*theEvent
= [NSApp currentEvent
];
4346 emacs_event
->kind
= NS_NONKEY_EVENT
;
4347 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4348 emacs_event
->modifiers
= 0;
4349 EV_TRAILER
(theEvent
);
4353 - (void
)newFrame
: (id
)sender
4355 struct frame
*emacsframe
= SELECTED_FRAME
();
4356 NSEvent
*theEvent
= [NSApp currentEvent
];
4360 emacs_event
->kind
= NS_NONKEY_EVENT
;
4361 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4362 emacs_event
->modifiers
= 0;
4363 EV_TRAILER
(theEvent
);
4367 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4368 - (BOOL
) openFile
: (NSString
*)fileName
4370 struct frame
*emacsframe
= SELECTED_FRAME
();
4371 NSEvent
*theEvent
= [NSApp currentEvent
];
4376 emacs_event
->kind
= NS_NONKEY_EVENT
;
4377 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4378 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4379 ns_input_line
= Qnil
; /* can be start or cons start,end */
4380 emacs_event
->modifiers
=0;
4381 EV_TRAILER
(theEvent
);
4387 /* **************************************************************************
4389 EmacsApp delegate implementation
4391 ************************************************************************** */
4393 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4394 /* --------------------------------------------------------------------------
4395 When application is loaded, terminate event loop in ns_term_init
4396 -------------------------------------------------------------------------- */
4398 NSTRACE
(applicationDidFinishLaunching
);
4399 [NSApp setServicesProvider
: NSApp
];
4400 ns_send_appdefined
(-2);
4404 /* Termination sequences:
4407 MenuBar | File | Exit:
4408 Select Quit from App menubar:
4410 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4413 Select Quit from Dock menu:
4416 Cancel -> Nothing else
4420 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4425 - (void
) terminate
: (id
)sender
4427 struct frame
*emacsframe
= SELECTED_FRAME
();
4432 emacs_event
->kind
= NS_NONKEY_EVENT
;
4433 emacs_event
->code
= KEY_NS_POWER_OFF
;
4434 emacs_event
->arg
= Qt
; /* mark as non-key event */
4435 EV_TRAILER
((id
)nil
);
4439 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4443 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4444 return NSTerminateNow
;
4446 ret
= NSRunAlertPanel
(ns_app_name
,
4447 @"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
,
4448 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4450 if (ret
== NSAlertDefaultReturn
)
4451 return NSTerminateNow
;
4452 else if (ret
== NSAlertAlternateReturn
)
4453 return NSTerminateCancel
;
4454 return NSTerminateNow
; /* just in case */
4458 not_in_argv
(NSString
*arg
)
4461 const
char *a
= [arg UTF8String
];
4462 for (k
= 1; k
< initial_argc
; ++k
)
4463 if (strcmp (a
, initial_argv
[k
]) == 0) return 0;
4467 /* Notification from the Workspace to open a file */
4468 - (BOOL
)application
: sender openFile
: (NSString
*)file
4470 if (ns_do_open_file || not_in_argv
(file
))
4471 [ns_pending_files addObject
: file
];
4476 /* Open a file as a temporary file */
4477 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4479 if (ns_do_open_file || not_in_argv
(file
))
4480 [ns_pending_files addObject
: file
];
4485 /* Notification from the Workspace to open a file noninteractively (?) */
4486 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4488 if (ns_do_open_file || not_in_argv
(file
))
4489 [ns_pending_files addObject
: file
];
4493 /* Notification from the Workspace to open multiple files */
4494 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4496 NSEnumerator
*files
= [fileList objectEnumerator
];
4498 /* Don't open files from the command line unconditionally,
4499 Cocoa parses the command line wrong, --option value tries to open value
4500 if --option is the last option. */
4501 while ((file
= [files nextObject
]) != nil
)
4502 if (ns_do_open_file || not_in_argv
(file
))
4503 [ns_pending_files addObject
: file
];
4505 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4510 /* Handle dock menu requests. */
4511 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4517 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4518 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4520 //ns_app_active
=YES
;
4522 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4524 NSTRACE
(applicationDidBecomeActive
);
4526 //ns_app_active
=YES
;
4528 ns_update_auto_hide_menu_bar
();
4529 // No constraining takes place when the application is not active.
4530 ns_constrain_all_frames
();
4532 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4535 ns_send_appdefined
(-1);
4540 /* ==========================================================================
4542 EmacsApp aux handlers for managing event loop
4544 ========================================================================== */
4547 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4548 /* --------------------------------------------------------------------------
4549 The timeout specified to ns_select has passed.
4550 -------------------------------------------------------------------------- */
4552 /*NSTRACE (timeout_handler); */
4553 ns_send_appdefined
(-2);
4556 - (void
)fd_handler
:(id
)unused
4557 /* --------------------------------------------------------------------------
4558 Check data waiting on file descriptors and terminate if so
4559 -------------------------------------------------------------------------- */
4562 int waiting
= 1, nfds
;
4565 SELECT_TYPE readfds
, writefds
, *wfds
;
4566 EMACS_TIME timeout
, *tmo
;
4567 NSAutoreleasePool
*pool
= nil
;
4569 /* NSTRACE (fd_handler); */
4574 pool
= [[NSAutoreleasePool alloc
] init
];
4580 FD_SET
(selfds
[0], &fds
);
4581 result
= select
(selfds
[0]+1, &fds
, NULL, NULL, NULL);
4582 if (result
> 0 && read
(selfds
[0], &c
, 1) == 1 && c
== 'g')
4587 pthread_mutex_lock
(&select_mutex
);
4590 if (select_valid
& SELECT_HAVE_READ
)
4591 readfds
= select_readfds
;
4595 if (select_valid
& SELECT_HAVE_WRITE
)
4597 writefds
= select_writefds
;
4602 if (select_valid
& SELECT_HAVE_TMO
)
4604 timeout
= select_timeout
;
4610 pthread_mutex_unlock
(&select_mutex
);
4612 FD_SET
(selfds
[0], &readfds
);
4613 if (selfds
[0] >= nfds
) nfds
= selfds
[0]+1;
4615 result
= pselect
(nfds
, &readfds
, wfds
, NULL, tmo
, NULL);
4618 ns_send_appdefined
(-2);
4619 else if (result
> 0)
4621 if (FD_ISSET
(selfds
[0], &readfds
))
4623 if (read
(selfds
[0], &c
, 1) == 1 && c
== 's')
4628 pthread_mutex_lock
(&select_mutex
);
4629 if (select_valid
& SELECT_HAVE_READ
)
4630 select_readfds
= readfds
;
4631 if (select_valid
& SELECT_HAVE_WRITE
)
4632 select_writefds
= writefds
;
4633 if (select_valid
& SELECT_HAVE_TMO
)
4634 select_timeout
= timeout
;
4635 pthread_mutex_unlock
(&select_mutex
);
4637 ns_send_appdefined
(result
);
4647 /* ==========================================================================
4651 ========================================================================== */
4653 /* called from system: queue for next pass through event loop */
4654 - (void
)requestService
: (NSPasteboard
*)pboard
4655 userData
: (NSString
*)userData
4656 error: (NSString
**)error
4658 [ns_pending_service_names addObject
: userData
];
4659 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4660 SSDATA
(ns_string_from_pasteboard
(pboard
))]];
4664 /* called from ns_read_socket to clear queue */
4665 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4667 struct frame
*emacsframe
= SELECTED_FRAME
();
4668 NSEvent
*theEvent
= [NSApp currentEvent
];
4673 emacs_event
->kind
= NS_NONKEY_EVENT
;
4674 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4675 ns_input_spi_name
= build_string
([name UTF8String
]);
4676 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4677 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4678 EV_TRAILER
(theEvent
);
4688 /* ==========================================================================
4690 EmacsView implementation
4692 ========================================================================== */
4695 @implementation EmacsView
4697 /* needed to inform when window closed from LISP */
4698 - (void
) setWindowClosing
: (BOOL
)closing
4700 windowClosing
= closing
;
4706 NSTRACE
(EmacsView_dealloc
);
4708 if (fs_state
== FULLSCREEN_BOTH
)
4709 [nonfs_window release
];
4714 /* called on font panel selection */
4715 - (void
)changeFont
: (id
)sender
4717 NSEvent
*e
=[[self window
] currentEvent
];
4718 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4722 NSTRACE
(changeFont
);
4726 if ((newFont
= [sender convertFont
:
4727 ((struct nsfont_info
*)face
->font
)->nsfont
]))
4729 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4731 emacs_event
->kind
= NS_NONKEY_EVENT
;
4732 emacs_event
->modifiers
= 0;
4733 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4735 size = [newFont pointSize
];
4736 ns_input_fontsize
= make_number
(lrint
(size));
4737 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4743 - (BOOL
)acceptsFirstResponder
4745 NSTRACE
(acceptsFirstResponder
);
4750 - (void
)resetCursorRects
4752 NSRect visible
= [self visibleRect
];
4753 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4754 NSTRACE
(resetCursorRects
);
4756 if (currentCursor
== nil
)
4757 currentCursor
= [NSCursor arrowCursor
];
4759 if (!NSIsEmptyRect
(visible
))
4760 [self addCursorRect
: visible cursor
: currentCursor
];
4761 [currentCursor setOnMouseEntered
: YES
];
4766 /*****************************************************************************/
4767 /* Keyboard handling. */
4770 - (void
)keyDown
: (NSEvent
*)theEvent
4772 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
4774 unsigned fnKeysym
= 0;
4775 static NSMutableArray
*nsEvArray
;
4776 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4777 static BOOL firstTime
= YES
;
4780 unsigned int flags
= [theEvent modifierFlags
];
4784 /* Rhapsody and OS X give up and down events for the arrow keys */
4785 if (ns_fake_keydown
== YES
)
4786 ns_fake_keydown
= NO
;
4787 else if ([theEvent
type] != NSKeyDown
)
4793 if (![[self window
] isKeyWindow
]
4794 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4795 /* we must avoid an infinite loop here. */
4796 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4798 /* XXX: There is an occasional condition in which, when Emacs display
4799 updates a different frame from the current one, and temporarily
4800 selects it, then processes some interrupt-driven input
4801 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4802 for some reason that window has its first responder set to the NSView
4803 most recently updated (I guess), which is not the correct one. */
4804 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4808 if (nsEvArray
== nil
)
4809 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4811 [NSCursor setHiddenUntilMouseMoves
: YES
];
4813 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4815 clear_mouse_face
(hlinfo
);
4816 hlinfo
->mouse_face_hidden
= 1;
4819 if (!processingCompose
)
4821 /* When using screen sharing, no left or right information is sent,
4822 so use Left key in those cases. */
4823 int is_left_key
, is_right_key
;
4825 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4826 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4828 /* (Carbon way: [theEvent keyCode]) */
4830 /* is it a "function key"? */
4831 fnKeysym
= (code
< 0x00ff && (flags
&NSNumericPadKeyMask
))
4832 ? ns_convert_key
([theEvent keyCode
] | NSNumericPadKeyMask
)
4833 : ns_convert_key
(code
);
4837 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4838 because Emacs treats Delete and KP-Delete same (in simple.el). */
4839 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4840 code
= 0xFF08; /* backspace */
4845 /* are there modifiers? */
4846 emacs_event
->modifiers
= 0;
4848 if (flags
& NSHelpKeyMask
)
4849 emacs_event
->modifiers |
= hyper_modifier
;
4851 if (flags
& NSShiftKeyMask
)
4852 emacs_event
->modifiers |
= shift_modifier
;
4854 is_right_key
= (flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
;
4855 is_left_key
= (flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
4856 ||
(! is_right_key
&& (flags
& NSCommandKeyMask
) == NSCommandKeyMask
);
4859 emacs_event
->modifiers |
= parse_solitary_modifier
4860 (EQ
(ns_right_command_modifier
, Qleft
)
4861 ? ns_command_modifier
4862 : ns_right_command_modifier
);
4866 emacs_event
->modifiers |
= parse_solitary_modifier
4867 (ns_command_modifier
);
4869 /* if super (default), take input manager's word so things like
4870 dvorak / qwerty layout work */
4871 if (EQ
(ns_command_modifier
, Qsuper
)
4873 && [[theEvent characters
] length] != 0)
4875 /* XXX: the code we get will be unshifted, so if we have
4876 a shift modifier, must convert ourselves */
4877 if (!(flags
& NSShiftKeyMask
))
4878 code
= [[theEvent characters
] characterAtIndex
: 0];
4880 /* this is ugly and also requires linking w/Carbon framework
4881 (for LMGetKbdType) so for now leave this rare (?) case
4882 undealt with.. in future look into CGEvent methods */
4885 long smv
= GetScriptManagerVariable
(smKeyScript
);
4886 Handle uchrHandle
= GetResource
4887 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4889 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4890 [[theEvent characters
] characterAtIndex
: 0],
4891 kUCKeyActionDisplay
,
4892 (flags
& ~NSCommandKeyMask
) >> 8,
4893 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4894 &dummy
, 1, &dummy
, &code
);
4901 is_right_key
= (flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
;
4902 is_left_key
= (flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
4903 ||
(! is_right_key
&& (flags
& NSControlKeyMask
) == NSControlKeyMask
);
4906 emacs_event
->modifiers |
= parse_solitary_modifier
4907 (EQ
(ns_right_control_modifier
, Qleft
)
4908 ? ns_control_modifier
4909 : ns_right_control_modifier
);
4912 emacs_event
->modifiers |
= parse_solitary_modifier
4913 (ns_control_modifier
);
4915 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4916 emacs_event
->modifiers |
=
4917 parse_solitary_modifier
(ns_function_modifier
);
4919 left_is_none
= NILP
(ns_alternate_modifier
)
4920 || EQ
(ns_alternate_modifier
, Qnone
);
4922 is_right_key
= (flags
& NSRightAlternateKeyMask
)
4923 == NSRightAlternateKeyMask
;
4924 is_left_key
= (flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
4926 && (flags
& NSAlternateKeyMask
) == NSAlternateKeyMask
);
4930 if ((NILP
(ns_right_alternate_modifier
)
4931 || EQ
(ns_right_alternate_modifier
, Qnone
)
4932 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
4934 { /* accept pre-interp alt comb */
4935 if ([[theEvent characters
] length] > 0)
4936 code
= [[theEvent characters
] characterAtIndex
: 0];
4937 /*HACK: clear lone shift modifier to stop next if from firing */
4938 if (emacs_event
->modifiers
== shift_modifier
)
4939 emacs_event
->modifiers
= 0;
4942 emacs_event
->modifiers |
= parse_solitary_modifier
4943 (EQ
(ns_right_alternate_modifier
, Qleft
)
4944 ? ns_alternate_modifier
4945 : ns_right_alternate_modifier
);
4948 if (is_left_key
) /* default = meta */
4950 if (left_is_none
&& !fnKeysym
)
4951 { /* accept pre-interp alt comb */
4952 if ([[theEvent characters
] length] > 0)
4953 code
= [[theEvent characters
] characterAtIndex
: 0];
4954 /*HACK: clear lone shift modifier to stop next if from firing */
4955 if (emacs_event
->modifiers
== shift_modifier
)
4956 emacs_event
->modifiers
= 0;
4959 emacs_event
->modifiers |
=
4960 parse_solitary_modifier
(ns_alternate_modifier
);
4964 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4965 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4967 /* if it was a function key or had modifiers, pass it directly to emacs */
4968 if (fnKeysym ||
(emacs_event
->modifiers
4969 && (emacs_event
->modifiers
!= shift_modifier
)
4970 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4971 /*[[theEvent characters] length] */
4973 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4975 code |
= (1<<28)|
(3<<16);
4976 else if (code
== 0x7f)
4977 code |
= (1<<28)|
(3<<16);
4979 emacs_event
->kind
= code
> 0xFF
4980 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4982 emacs_event
->code
= code
;
4983 EV_TRAILER
(theEvent
);
4989 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4990 /* if we get here we should send the key for input manager processing */
4991 if (firstTime
&& [[NSInputManager currentInputManager
]
4992 wantsToDelayTextChangeNotifications
] == NO
)
4994 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
4997 if (NS_KEYLOG
&& !processingCompose
)
4998 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
5000 processingCompose
= YES
;
5001 [nsEvArray addObject
: theEvent
];
5002 [self interpretKeyEvents
: nsEvArray
];
5003 [nsEvArray removeObject
: theEvent
];
5007 #ifdef NS_IMPL_COCOA
5008 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
5009 decided not to send key-down for.
5010 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
5011 This only applies on Tiger and earlier.
5012 If it matches one of these, send it on to keyDown. */
5013 -(void
)keyUp
: (NSEvent
*)theEvent
5015 int flags
= [theEvent modifierFlags
];
5016 int code
= [theEvent keyCode
];
5017 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
5018 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
5021 fprintf (stderr
, "keyUp
: passed test"
);
5022 ns_fake_keydown
= YES
;
5023 [self keyDown
: theEvent
];
5029 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
5032 /* <NSTextInput>: called when done composing;
5033 NOTE: also called when we delete over working text, followed immed.
5034 by doCommandBySelector: deleteBackward: */
5035 - (void
)insertText
: (id
)aString
5038 int len
= [(NSString
*)aString
length];
5042 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
5043 processingCompose
= NO
;
5048 /* first, clear any working text */
5049 if (workingText
!= nil
)
5050 [self deleteWorkingText
];
5052 /* now insert the string as keystrokes */
5053 for (i
=0; i
<len
; i
++)
5055 code
= [aString characterAtIndex
: i
];
5056 /* TODO: still need this? */
5058 code
= '~'; /* 0x7E */
5059 if (code
!= 32) /* Space */
5060 emacs_event
->modifiers
= 0;
5062 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
5063 emacs_event
->code
= code
;
5064 EV_TRAILER
((id
)nil
);
5069 /* <NSTextInput>: inserts display of composing characters */
5070 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
5072 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
5073 [aString string
] : aString
;
5075 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
5076 selRange.
length, selRange.location
);
5078 if (workingText
!= nil
)
5079 [self deleteWorkingText
];
5080 if ([str
length] == 0)
5086 processingCompose
= YES
;
5087 workingText
= [str copy
];
5088 ns_working_text
= build_string
([workingText UTF8String
]);
5090 emacs_event
->kind
= NS_TEXT_EVENT
;
5091 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
5092 EV_TRAILER
((id
)nil
);
5096 /* delete display of composing characters [not in <NSTextInput>] */
5097 - (void
)deleteWorkingText
5099 if (workingText
== nil
)
5102 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
5103 [workingText release
];
5105 processingCompose
= NO
;
5110 emacs_event
->kind
= NS_TEXT_EVENT
;
5111 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5112 EV_TRAILER
((id
)nil
);
5116 - (BOOL
)hasMarkedText
5118 return workingText
!= nil
;
5122 - (NSRange
)markedRange
5124 NSRange rng
= workingText
!= nil
5125 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5127 NSLog
(@"markedRange request"
);
5135 NSLog
(@"unmark
(accept
) text"
);
5136 [self deleteWorkingText
];
5137 processingCompose
= NO
;
5141 /* used to position char selection windows, etc. */
5142 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5146 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5148 NSLog
(@"firstRectForCharRange request"
);
5150 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5151 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5152 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5153 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5154 +FRAME_LINE_HEIGHT
(emacsframe
));
5156 pt
= [self convertPoint
: pt toView
: nil
];
5157 pt
= [[self window
] convertBaseToScreen
: pt
];
5163 - (NSInteger
)conversationIdentifier
5165 return (NSInteger
)self
;
5169 - (void
)doCommandBySelector
: (SEL
)aSelector
5172 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5174 if (aSelector
== @selector
(deleteBackward
:))
5176 /* happens when user backspaces over an ongoing composition:
5177 throw a 'delete' into the event queue */
5180 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5181 emacs_event
->code
= 0xFF08;
5182 EV_TRAILER
((id
)nil
);
5186 - (NSArray
*)validAttributesForMarkedText
5188 static NSArray
*arr
= nil
;
5189 if (arr
== nil
) arr
= [NSArray new
];
5190 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5194 - (NSRange
)selectedRange
5197 NSLog
(@"selectedRange request"
);
5198 return NSMakeRange
(NSNotFound
, 0);
5201 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5204 NSLog
(@"characterIndexForPoint request"
);
5208 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5210 static NSAttributedString
*str
= nil
;
5211 if (str
== nil
) str
= [NSAttributedString new
];
5213 NSLog
(@"attributedSubstringFromRange request"
);
5217 /* End <NSTextInput> impl. */
5218 /*****************************************************************************/
5221 /* This is what happens when the user presses a mouse button. */
5222 - (void
)mouseDown
: (NSEvent
*)theEvent
5224 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5226 NSTRACE
(mouseDown
);
5228 [self deleteWorkingText
];
5233 last_mouse_frame
= emacsframe
;
5234 /* appears to be needed to prevent spurious movement events generated on
5236 last_mouse_frame
->mouse_moved
= 0;
5238 if ([theEvent
type] == NSScrollWheel
)
5240 float delta
= [theEvent deltaY
];
5241 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5244 emacs_event
->kind
= WHEEL_EVENT
;
5245 emacs_event
->code
= 0;
5246 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5247 ((delta
> 0) ? up_modifier
: down_modifier
);
5251 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5252 emacs_event
->code
= EV_BUTTON
(theEvent
);
5253 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5254 | EV_UDMODIFIERS
(theEvent
);
5256 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5257 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5258 EV_TRAILER
(theEvent
);
5262 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5264 NSTRACE
(rightMouseDown
);
5265 [self mouseDown
: theEvent
];
5269 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5271 NSTRACE
(otherMouseDown
);
5272 [self mouseDown
: theEvent
];
5276 - (void
)mouseUp
: (NSEvent
*)theEvent
5279 [self mouseDown
: theEvent
];
5283 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5285 NSTRACE
(rightMouseUp
);
5286 [self mouseDown
: theEvent
];
5290 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5292 NSTRACE
(otherMouseUp
);
5293 [self mouseDown
: theEvent
];
5297 - (void
) scrollWheel
: (NSEvent
*)theEvent
5299 NSTRACE
(scrollWheel
);
5300 [self mouseDown
: theEvent
];
5304 /* Tell emacs the mouse has moved. */
5305 - (void
)mouseMoved
: (NSEvent
*)e
5307 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5310 // NSTRACE
(mouseMoved
);
5312 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5313 last_mouse_motion_position
5314 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5316 /* update any mouse face */
5317 if (hlinfo
->mouse_face_hidden
)
5319 hlinfo
->mouse_face_hidden
= 0;
5320 clear_mouse_face
(hlinfo
);
5323 /* tooltip handling */
5324 previous_help_echo_string
= help_echo_string
;
5325 help_echo_string
= Qnil
;
5327 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
5328 last_mouse_motion_position.y
))
5329 help_echo_string
= previous_help_echo_string
;
5331 XSETFRAME
(frame
, emacsframe
);
5332 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5334 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5335 (note_mouse_highlight), which is called through the
5336 note_mouse_movement () call above */
5337 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5338 help_echo_object
, help_echo_pos
);
5342 help_echo_string
= Qnil
;
5343 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5346 if (emacsframe
->mouse_moved
&& send_appdefined
)
5347 ns_send_appdefined
(-1);
5351 - (void
)mouseDragged
: (NSEvent
*)e
5353 NSTRACE
(mouseDragged
);
5354 [self mouseMoved
: e
];
5358 - (void
)rightMouseDragged
: (NSEvent
*)e
5360 NSTRACE
(rightMouseDragged
);
5361 [self mouseMoved
: e
];
5365 - (void
)otherMouseDragged
: (NSEvent
*)e
5367 NSTRACE
(otherMouseDragged
);
5368 [self mouseMoved
: e
];
5372 - (BOOL
)windowShouldClose
: (id
)sender
5374 NSEvent
*e
=[[self window
] currentEvent
];
5376 NSTRACE
(windowShouldClose
);
5377 windowClosing
= YES
;
5380 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5381 emacs_event
->modifiers
= 0;
5382 emacs_event
->code
= 0;
5384 /* Don't close this window, let this be done from lisp code. */
5388 - (void
) updateFrameSize
: (BOOL
) delay
;
5390 NSWindow
*window
= [self window
];
5391 NSRect wr
= [window frame
];
5392 #ifdef NS_IMPL_GNUSTEP
5398 int oldc
= cols
, oldr
= rows
;
5399 int oldw
= FRAME_PIXEL_WIDTH
(emacsframe
),
5400 oldh
= FRAME_PIXEL_HEIGHT
(emacsframe
);
5403 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
, wr.
size.width
+ extra
);
5405 if (cols
< MINWIDTH
)
5408 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
5409 (emacsframe
, wr.
size.height
5410 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + extra
5411 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5413 if (rows
< MINHEIGHT
)
5416 neww
= (int
)wr.
size.width
- emacsframe
->border_width
;
5417 newh
= ((int
)wr.
size.height
5418 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5419 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5421 if (oldr
!= rows || oldc
!= cols || neww
!= oldw || newh
!= oldh
)
5423 NSView
*view = FRAME_NS_VIEW
(emacsframe
);
5424 FRAME_PIXEL_WIDTH
(emacsframe
) = neww
;
5425 FRAME_PIXEL_HEIGHT
(emacsframe
) = newh
;
5426 change_frame_size
(emacsframe
, rows
, cols
, 0, delay
, 0);
5427 SET_FRAME_GARBAGED
(emacsframe
);
5428 cancel_mouse_face
(emacsframe
);
5429 [view setFrame
: NSMakeRect
(0, 0, neww
, newh
)];
5430 [self windowDidMove
:nil
]; // Update top
/left.
5434 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5435 /* normalize frame to gridded text size */
5437 NSTRACE
(windowWillResize
);
5438 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5440 if (fs_state
== FULLSCREEN_MAXIMIZED
5441 && (maximized_width
!= (int
)frameSize.width
5442 || maximized_height
!= (int
)frameSize.height
))
5443 [self setFSValue
: FULLSCREEN_NONE
];
5444 else if (fs_state
== FULLSCREEN_WIDTH
5445 && maximized_width
!= (int
)frameSize.width
)
5446 [self setFSValue
: FULLSCREEN_NONE
];
5447 else if (fs_state
== FULLSCREEN_HEIGHT
5448 && maximized_height
!= (int
)frameSize.height
)
5449 [self setFSValue
: FULLSCREEN_NONE
];
5450 if (fs_state
== FULLSCREEN_NONE
)
5451 maximized_width
= maximized_height
= -1;
5453 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5454 #ifdef NS_IMPL_GNUSTEP
5455 frameSize.width
+ 3);
5459 if (cols
< MINWIDTH
)
5462 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5463 #ifdef NS_IMPL_GNUSTEP
5464 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5465 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5467 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5468 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5470 if (rows
< MINHEIGHT
)
5472 #ifdef NS_IMPL_COCOA
5474 /* this sets window title to have size in it; the wm does this under GS */
5475 NSRect r
= [[self window
] frame
];
5476 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5487 NSWindow
*window
= [self window
];
5490 const
char *t
= [[[self window
] title] UTF8String
];
5491 char *pos
= strstr
(t
, " — "
);
5494 old_title
= xstrdup
(t
);
5496 size_title
= xmalloc
(strlen
(old_title
) + 40);
5497 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5498 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5503 #endif
/* NS_IMPL_COCOA */
5504 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5510 - (void
)windowDidResize
: (NSNotification
*)notification
5513 #
if !defined
(NEW_STYLE_FS
) && ! defined
(NS_IMPL_GNUSTEP
)
5514 NSWindow
*theWindow
= [notification object
];
5515 /* We can get notification on the non-FS window when in fullscreen mode. */
5516 if ([self window
] != theWindow
) return;
5519 #ifdef NS_IMPL_GNUSTEP
5520 NSWindow
*theWindow
= [notification object
];
5522 /* In GNUstep, at least currently, it's possible to get a didResize
5523 without getting a willResize.. therefore we need to act as if we got
5524 the willResize now */
5525 NSSize sz
= [theWindow frame
].
size;
5526 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5527 #endif
/* NS_IMPL_GNUSTEP */
5529 NSTRACE
(windowDidResize
);
5530 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5532 #ifdef NS_IMPL_COCOA
5538 #endif
/* NS_IMPL_COCOA */
5540 if (cols
> 0 && rows
> 0)
5542 [self updateFrameSize
: YES
];
5545 ns_send_appdefined
(-1);
5549 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5550 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5552 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5553 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5555 NSTRACE
(windowDidBecomeKey
);
5557 if (emacsframe
!= old_focus
)
5558 dpyinfo
->x_focus_frame
= emacsframe
;
5560 ns_frame_rehighlight
(emacsframe
);
5564 emacs_event
->kind
= FOCUS_IN_EVENT
;
5565 EV_TRAILER
((id
)nil
);
5570 - (void
)windowDidResignKey
: (NSNotification
*)notification
5571 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5573 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5574 NSTRACE
(windowDidResignKey
);
5576 if (dpyinfo
->x_focus_frame
== emacsframe
)
5577 dpyinfo
->x_focus_frame
= 0;
5579 ns_frame_rehighlight
(emacsframe
);
5581 /* FIXME: for some reason needed on second and subsequent clicks away
5582 from sole-frame Emacs to get hollow box to show */
5583 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5585 x_update_cursor
(emacsframe
, 1);
5586 x_set_frame_alpha
(emacsframe
);
5591 [self deleteWorkingText
];
5592 emacs_event
->kind
= FOCUS_IN_EVENT
;
5593 EV_TRAILER
((id
)nil
);
5598 - (void
)windowWillMiniaturize
: sender
5600 NSTRACE
(windowWillMiniaturize
);
5616 - initFrameFromEmacs
: (struct frame
*)f
5621 NSButton
*toggleButton
;
5626 NSTRACE
(initFrameFromEmacs
);
5629 processingCompose
= NO
;
5630 scrollbarsNeedingUpdate
= 0;
5631 fs_state
= FULLSCREEN_NONE
;
5632 fs_before_fs
= next_maximized
= -1;
5633 maximized_width
= maximized_height
= -1;
5636 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5638 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5639 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5640 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5641 [self initWithFrame
: r
];
5642 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5644 FRAME_NS_VIEW
(f
) = self
;
5648 win
= [[EmacsWindow alloc
]
5649 initWithContentRect
: r
5650 styleMask
: (NSResizableWindowMask |
5651 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5652 NSTitledWindowMask |
5654 NSMiniaturizableWindowMask |
5655 NSClosableWindowMask
)
5656 backing
: NSBackingStoreBuffered
5660 [win setCollectionBehavior
:NSWindowCollectionBehaviorFullScreenPrimary
];
5664 bwidth
= f
->border_width
= wr.
size.width
- r.
size.width
;
5665 tibar_height
= FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
5667 [win setAcceptsMouseMovedEvents
: YES
];
5668 [win setDelegate
: self
];
5669 [win useOptimizedDrawing
: YES
];
5671 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5672 sz.height
= FRAME_LINE_HEIGHT
(f
);
5673 [win setResizeIncrements
: sz
];
5675 [[win contentView
] addSubview
: self
];
5678 [self registerForDraggedTypes
: ns_drag_types
];
5681 name
= [NSString stringWithUTF8String
:
5682 NILP
(tem
) ? "Emacs"
: SSDATA
(tem
)];
5683 [win setTitle
: name
];
5685 /* toolbar support */
5686 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
5687 [NSString stringWithFormat
: @"Emacs Frame
%d",
5689 [win setToolbar
: toolbar
];
5690 [toolbar setVisible
: NO
];
5691 #ifdef NS_IMPL_COCOA
5692 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
5693 [toggleButton setTarget
: self
];
5694 [toggleButton setAction
: @selector
(toggleToolbar
: )];
5696 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5700 [win setMiniwindowTitle
:
5701 [NSString stringWithUTF8String
: SSDATA
(tem
)]];
5704 NSScreen
*screen
= [win screen
];
5707 [win setFrameTopLeftPoint
: NSMakePoint
5708 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
5709 IN_BOUND
(-SCREENMAX
,
5710 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
5713 [win makeFirstResponder
: self
];
5715 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5716 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
5717 [win setBackgroundColor
: col
];
5718 if ([col alphaComponent
] != 1.0)
5719 [win setOpaque
: NO
];
5721 [self allocateGState
];
5723 [NSApp registerServicesMenuSendTypes
: ns_send_types
5731 - (void
)windowDidMove
: sender
5733 NSWindow
*win
= [self window
];
5734 NSRect r
= [win frame
];
5735 NSArray
*screens
= [NSScreen screens
];
5736 NSScreen
*screen
= [screens objectAtIndex
: 0];
5738 NSTRACE
(windowDidMove
);
5740 if (!emacsframe
->output_data.ns
)
5744 emacsframe
->left_pos
= r.origin.x
;
5745 emacsframe
->top_pos
=
5746 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
5751 /* Called AFTER method below, but before our windowWillResize call there leads
5752 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
5753 location so set_window_size moves the frame. */
5754 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5756 emacsframe
->output_data.ns
->zooming
= 1;
5761 /* Override to do something slightly nonstandard, but nice. First click on
5762 zoom button will zoom vertically. Second will zoom completely. Third
5763 returns to original. */
5764 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5765 defaultFrame
:(NSRect
)defaultFrame
5767 NSRect result
= [sender frame
];
5769 NSTRACE
(windowWillUseStandardFrame
);
5771 if (fs_before_fs
!= -1) /* Entering fullscreen */
5773 result
= defaultFrame
;
5775 else if (next_maximized
== FULLSCREEN_HEIGHT
5776 ||
(next_maximized
== -1
5777 && abs (defaultFrame.
size.height
- result.
size.height
)
5778 > FRAME_LINE_HEIGHT
(emacsframe
)))
5781 ns_userRect
= result
;
5782 maximized_height
= result.
size.height
= defaultFrame.
size.height
;
5783 maximized_width
= -1;
5784 result.origin.y
= defaultFrame.origin.y
;
5785 [self setFSValue
: FULLSCREEN_HEIGHT
];
5787 else if (next_maximized
== FULLSCREEN_WIDTH
)
5789 ns_userRect
= result
;
5790 maximized_width
= result.
size.width
= defaultFrame.
size.width
;
5791 maximized_height
= -1;
5792 result.origin.x
= defaultFrame.origin.x
;
5793 [self setFSValue
: FULLSCREEN_WIDTH
];
5795 else if (next_maximized
== FULLSCREEN_MAXIMIZED
5796 ||
(next_maximized
== -1
5797 && abs (defaultFrame.
size.width
- result.
size.width
)
5798 > FRAME_COLUMN_WIDTH
(emacsframe
)))
5800 result
= defaultFrame
; /* second click */
5801 maximized_width
= result.
size.width
;
5802 maximized_height
= result.
size.height
;
5803 [self setFSValue
: FULLSCREEN_MAXIMIZED
];
5808 result
= ns_userRect.
size.height ? ns_userRect
: result
;
5809 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5810 [self setFSValue
: FULLSCREEN_NONE
];
5811 maximized_width
= maximized_width
= -1;
5814 if (fs_before_fs
== -1) next_maximized
= -1;
5815 [self windowWillResize
: sender toSize
: result.
size];
5820 - (void
)windowDidDeminiaturize
: sender
5822 NSTRACE
(windowDidDeminiaturize
);
5823 if (!emacsframe
->output_data.ns
)
5825 emacsframe
->async_iconified
= 0;
5826 emacsframe
->async_visible
= 1;
5827 windows_or_buffers_changed
++;
5831 emacs_event
->kind
= ICONIFY_EVENT
;
5832 EV_TRAILER
((id
)nil
);
5837 - (void
)windowDidExpose
: sender
5839 NSTRACE
(windowDidExpose
);
5840 if (!emacsframe
->output_data.ns
)
5842 emacsframe
->async_visible
= 1;
5843 SET_FRAME_GARBAGED
(emacsframe
);
5845 if (send_appdefined
)
5846 ns_send_appdefined
(-1);
5850 - (void
)windowDidMiniaturize
: sender
5852 NSTRACE
(windowDidMiniaturize
);
5853 if (!emacsframe
->output_data.ns
)
5856 emacsframe
->async_iconified
= 1;
5857 emacsframe
->async_visible
= 0;
5861 emacs_event
->kind
= ICONIFY_EVENT
;
5862 EV_TRAILER
((id
)nil
);
5866 - (void
)windowWillEnterFullScreen
:(NSNotification
*)notification
5868 fs_before_fs
= fs_state
;
5871 - (void
)windowDidEnterFullScreen
:(NSNotification
*)notification
5873 [self setFSValue
: FULLSCREEN_BOTH
];
5875 // Fix bad background.
5876 if ([toolbar isVisible
])
5878 [toolbar setVisible
:NO
];
5879 [toolbar setVisible
:YES
];
5882 [self windowDidBecomeKey
:notification
];
5883 [nonfs_window orderOut
:self
];
5887 - (void
)windowWillExitFullScreen
:(NSNotification
*)notification
5889 if (next_maximized
!= -1)
5890 fs_before_fs
= next_maximized
;
5893 - (void
)windowDidExitFullScreen
:(NSNotification
*)notification
5895 [self setFSValue
: fs_before_fs
];
5897 if (next_maximized
!= -1)
5898 [[self window
] performZoom
:self
];
5901 - (void
)toggleFullScreen
: (id
)sender
5904 [[self window
] toggleFullScreen
:sender
];
5906 NSWindow
*w
= [self window
], *fw
;
5907 BOOL onFirstScreen
= [[w screen
]
5908 isEqual:[[NSScreen screens
] objectAtIndex
:0]];
5909 struct frame
*f
= emacsframe
;
5911 NSRect r
, wr
= [w frame
];
5912 NSColor
*col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5913 (FRAME_DEFAULT_FACE
(f
)),
5916 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5917 sz.height
= FRAME_LINE_HEIGHT
(f
);
5919 if (fs_state
!= FULLSCREEN_BOTH
)
5921 /* Hide dock and menubar if we are on the primary screen. */
5924 #
if defined
(NS_IMPL_COCOA
) && \
5925 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
5926 NSApplicationPresentationOptions options
5927 = NSApplicationPresentationAutoHideDock
5928 | NSApplicationPresentationAutoHideMenuBar
;
5930 [NSApp setPresentationOptions
: options
];
5932 [NSMenu setMenuBarVisible
:NO
];
5936 fw
= [[EmacsFSWindow alloc
]
5937 initWithContentRect
:[w contentRectForFrameRect
:wr
]
5938 styleMask
:NSBorderlessWindowMask
5939 backing
:NSBackingStoreBuffered
5943 [fw setContentView
:[w contentView
]];
5944 [fw setTitle
:[w
title]];
5945 [fw setDelegate
:self
];
5946 [fw setAcceptsMouseMovedEvents
: YES
];
5947 [fw useOptimizedDrawing
: YES
];
5948 [fw setResizeIncrements
: sz
];
5949 [fw setBackgroundColor
: col
];
5950 if ([col alphaComponent
] != 1.0)
5953 f
->border_width
= 0;
5954 FRAME_NS_TITLEBAR_HEIGHT
(f
) = 0;
5955 tobar_height
= FRAME_TOOLBAR_HEIGHT
(f
);
5956 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5957 FRAME_EXTERNAL_TOOL_BAR
(f
) = 0;
5961 [self windowWillEnterFullScreen
:nil
];
5962 [fw makeKeyAndOrderFront
:NSApp
];
5963 [fw makeFirstResponder
:self
];
5965 r
= [fw frameRectForContentRect
:[[fw screen
] frame
]];
5966 [fw setFrame
: r display
:YES animate
:YES
];
5967 [self windowDidEnterFullScreen
:nil
];
5978 #
if defined
(NS_IMPL_COCOA
) && \
5979 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
5980 [NSApp setPresentationOptions
: NSApplicationPresentationDefault
];
5982 [NSMenu setMenuBarVisible
:YES
];
5986 [w setContentView
:[fw contentView
]];
5987 [w setResizeIncrements
: sz
];
5988 [w setBackgroundColor
: col
];
5989 if ([col alphaComponent
] != 1.0)
5992 f
->border_width
= bwidth
;
5993 FRAME_NS_TITLEBAR_HEIGHT
(f
) = tibar_height
;
5994 FRAME_TOOLBAR_HEIGHT
(f
) = tobar_height
;
5996 FRAME_EXTERNAL_TOOL_BAR
(f
) = 1;
5998 [self windowWillExitFullScreen
:nil
];
5999 [fw setFrame
: [w frame
] display
:YES animate
:YES
];
6001 [w makeKeyAndOrderFront
:NSApp
];
6002 [self windowDidExitFullScreen
:nil
];
6009 if (fs_state
!= emacsframe
->want_fullscreen
)
6011 if (fs_state
== FULLSCREEN_BOTH
)
6013 [self toggleFullScreen
:self
];
6016 switch (emacsframe
->want_fullscreen
)
6018 case FULLSCREEN_BOTH
:
6019 [self toggleFullScreen
:self
];
6021 case FULLSCREEN_WIDTH
:
6022 next_maximized
= FULLSCREEN_WIDTH
;
6023 if (fs_state
!= FULLSCREEN_BOTH
)
6024 [[self window
] performZoom
:self
];
6026 case FULLSCREEN_HEIGHT
:
6027 next_maximized
= FULLSCREEN_HEIGHT
;
6028 if (fs_state
!= FULLSCREEN_BOTH
)
6029 [[self window
] performZoom
:self
];
6031 case FULLSCREEN_MAXIMIZED
:
6032 next_maximized
= FULLSCREEN_MAXIMIZED
;
6033 if (fs_state
!= FULLSCREEN_BOTH
)
6034 [[self window
] performZoom
:self
];
6036 case FULLSCREEN_NONE
:
6037 if (fs_state
!= FULLSCREEN_BOTH
)
6039 next_maximized
= FULLSCREEN_NONE
;
6040 [[self window
] performZoom
:self
];
6045 emacsframe
->want_fullscreen
= FULLSCREEN_NONE
;
6050 - (void
) setFSValue
: (int
)value
6052 Lisp_Object lval
= Qnil
;
6055 case FULLSCREEN_BOTH
:
6058 case FULLSCREEN_WIDTH
:
6061 case FULLSCREEN_HEIGHT
:
6064 case FULLSCREEN_MAXIMIZED
:
6068 store_frame_param
(emacsframe
, Qfullscreen
, lval
);
6072 - (void
)mouseEntered
: (NSEvent
*)theEvent
6074 NSTRACE
(mouseEntered
);
6075 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
6079 - (void
)mouseExited
: (NSEvent
*)theEvent
6081 Mouse_HLInfo
*hlinfo
= emacsframe ? MOUSE_HL_INFO
(emacsframe
) : NULL;
6083 NSTRACE
(mouseExited
);
6088 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
6090 if (emacsframe
== hlinfo
->mouse_face_mouse_frame
)
6092 clear_mouse_face
(hlinfo
);
6093 hlinfo
->mouse_face_mouse_frame
= 0;
6101 if (context_menu_value
== -1)
6102 context_menu_value
= [sender tag
];
6105 NSInteger tag
= [sender tag
];
6106 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
6107 emacsframe
->menu_bar_vector
,
6111 ns_send_appdefined
(-1);
6116 - (EmacsToolbar
*)toolbar
6122 /* this gets called on toolbar button click */
6123 - toolbarClicked
: (id
)item
6126 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
6128 NSTRACE
(toolbarClicked
);
6133 /* send first event (for some reason two needed) */
6134 theEvent
= [[self window
] currentEvent
];
6135 emacs_event
->kind
= TOOL_BAR_EVENT
;
6136 XSETFRAME
(emacs_event
->arg
, emacsframe
);
6137 EV_TRAILER
(theEvent
);
6139 emacs_event
->kind
= TOOL_BAR_EVENT
;
6140 /* XSETINT (emacs_event->code, 0); */
6141 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
6142 idx
+ TOOL_BAR_ITEM_KEY
);
6143 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6144 EV_TRAILER
(theEvent
);
6149 - toggleToolbar
: (id
)sender
6154 emacs_event
->kind
= NS_NONKEY_EVENT
;
6155 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
6156 EV_TRAILER
((id
)nil
);
6161 - (void
)drawRect
: (NSRect
)rect
6163 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
6164 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
6168 if (!emacsframe ||
!emacsframe
->output_data.ns
)
6171 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
6172 expose_frame
(emacsframe
, x
, y
, width
, height
);
6175 drawRect: may be called (at least in OS X 10.5) for invisible
6176 views as well for some reason. Thus, do not infer visibility
6179 emacsframe->async_visible = 1;
6180 emacsframe->async_iconified = 0;
6185 /* NSDraggingDestination protocol methods. Actually this is not really a
6186 protocol, but a category of Object. O well... */
6188 -(NSUInteger
) draggingEntered
: (id
<NSDraggingInfo
>) sender
6190 NSTRACE
(draggingEntered
);
6191 return NSDragOperationGeneric
;
6195 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
6201 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
6206 NSEvent
*theEvent
= [[self window
] currentEvent
];
6209 NSTRACE
(performDragOperation
);
6214 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
6215 x
= lrint
(position.x
); y
= lrint
(position.y
);
6217 pb
= [sender draggingPasteboard
];
6218 type = [pb availableTypeFromArray
: ns_drag_types
];
6223 else if ([type isEqualToString
: NSFilenamesPboardType
])
6226 NSEnumerator
*fenum
;
6229 if (!(files
= [pb propertyListForType
: type]))
6232 fenum
= [files objectEnumerator
];
6233 while ( (file
= [fenum nextObject
]) )
6235 emacs_event
->kind
= NS_NONKEY_EVENT
;
6236 emacs_event
->code
= KEY_NS_DRAG_FILE
;
6237 XSETINT
(emacs_event
->x
, x
);
6238 XSETINT
(emacs_event
->y
, y
);
6239 ns_input_file
= append2
(ns_input_file
,
6240 build_string
([file UTF8String
]));
6241 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6242 EV_TRAILER
(theEvent
);
6246 else if ([type isEqualToString
: NSURLPboardType
])
6251 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
6252 [fileURL isFileURL
] == NO
)
6255 file
= [fileURL
path];
6256 emacs_event
->kind
= NS_NONKEY_EVENT
;
6257 emacs_event
->code
= KEY_NS_DRAG_FILE
;
6258 XSETINT
(emacs_event
->x
, x
);
6259 XSETINT
(emacs_event
->y
, y
);
6260 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
6261 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6262 EV_TRAILER
(theEvent
);
6265 else if ([type isEqualToString
: NSStringPboardType
]
6266 ||
[type isEqualToString
: NSTabularTextPboardType
])
6270 if (! (data
= [pb stringForType
: type]))
6273 emacs_event
->kind
= NS_NONKEY_EVENT
;
6274 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
6275 XSETINT
(emacs_event
->x
, x
);
6276 XSETINT
(emacs_event
->y
, y
);
6277 ns_input_text
= build_string
([data UTF8String
]);
6278 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6279 EV_TRAILER
(theEvent
);
6282 else if ([type isEqualToString
: NSColorPboardType
])
6284 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
6285 emacs_event
->kind
= NS_NONKEY_EVENT
;
6286 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
6287 XSETINT
(emacs_event
->x
, x
);
6288 XSETINT
(emacs_event
->y
, y
);
6289 ns_input_color
= ns_color_to_lisp
(c
);
6290 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6291 EV_TRAILER
(theEvent
);
6294 else if ([type isEqualToString
: NSFontPboardType
])
6296 /* impl based on GNUstep NSTextView.m */
6297 NSData
*data
= [pb dataForType
: NSFontPboardType
];
6298 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
6299 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
6305 emacs_event
->kind
= NS_NONKEY_EVENT
;
6306 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
6307 XSETINT
(emacs_event
->x
, x
);
6308 XSETINT
(emacs_event
->y
, y
);
6309 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
6310 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
6311 ns_input_fontsize
= build_string
(fontSize
);
6312 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6313 EV_TRAILER
(theEvent
);
6318 error ("Invalid data
type in dragging pasteboard."
);
6324 - (id
) validRequestorForSendType
: (NSString
*)typeSent
6325 returnType
: (NSString
*)typeReturned
6327 NSTRACE
(validRequestorForSendType
);
6328 if (typeSent
!= nil
&& [ns_send_types indexOfObject
: typeSent
] != NSNotFound
6329 && typeReturned
== nil
)
6331 if (! NILP
(ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
)))
6335 return [super validRequestorForSendType
: typeSent
6336 returnType
: typeReturned
];
6340 /* The next two methods are part of NSServicesRequests informal protocol,
6341 supposedly called when a services menu item is chosen from this app.
6342 But this should not happen because we override the services menu with our
6343 own entries which call ns-perform-service.
6344 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
6345 So let's at least stub them out until further investigation can be done. */
6347 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
6349 /* we could call ns_string_from_pasteboard(pboard) here but then it should
6350 be written into the buffer in place of the existing selection..
6351 ordinary service calls go through functions defined in ns-win.el */
6355 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
6357 NSArray
*typesDeclared
;
6360 /* We only support NSStringPboardType */
6361 if ([types containsObject
:NSStringPboardType
] == NO
) {
6365 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6366 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
6369 if (CONSP
(val
) && NILP
(XCDR
(val
)))
6372 if (! STRINGP
(val
))
6375 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
6376 [pb declareTypes
:typesDeclared owner
:nil
];
6377 ns_string_to_pasteboard
(pb
, val
);
6382 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
6383 (gives a miniaturized version of the window); currently we use the latter for
6384 frames whose active buffer doesn't correspond to any file
6385 (e.g., '*scratch*') */
6386 - setMiniwindowImage
: (BOOL
) setMini
6388 id
image = [[self window
] miniwindowImage
];
6389 NSTRACE
(setMiniwindowImage
);
6391 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6392 about "AppleDockIconEnabled" notwithstanding, however the set message
6393 below has its effect nonetheless. */
6394 if (image != emacsframe
->output_data.ns
->miniimage
)
6396 if (image && [image isKindOfClass
: [EmacsImage
class]])
6398 [[self window
] setMiniwindowImage
:
6399 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6406 - (void
) setRows
: (int
) r andColumns
: (int
) c
6412 @
end /* EmacsView */
6416 /* ==========================================================================
6418 EmacsWindow implementation
6420 ========================================================================== */
6422 @implementation EmacsWindow
6424 #ifdef NS_IMPL_COCOA
6425 - (id
)accessibilityAttributeValue
:(NSString
*)attribute
6427 Lisp_Object str
= Qnil
;
6428 struct frame
*f
= SELECTED_FRAME
();
6429 struct buffer
*curbuf
= XBUFFER
(XWINDOW
(f
->selected_window
)->buffer
);
6431 if ([attribute isEqualToString
:NSAccessibilityRoleAttribute
])
6432 return NSAccessibilityTextFieldRole
;
6434 if ([attribute isEqualToString
:NSAccessibilitySelectedTextAttribute
]
6435 && curbuf
&& ! NILP
(BVAR
(curbuf
, mark_active
)))
6437 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6439 else if (curbuf
&& [attribute isEqualToString
:NSAccessibilityValueAttribute
])
6441 if (! NILP
(BVAR
(curbuf
, mark_active
)))
6442 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6446 ptrdiff_t start_byte
= BUF_BEGV_BYTE
(curbuf
);
6447 ptrdiff_t byte_range
= BUF_ZV_BYTE
(curbuf
) - start_byte
;
6448 ptrdiff_t range
= BUF_ZV
(curbuf
) - BUF_BEGV
(curbuf
);
6450 if (! NILP
(BVAR
(curbuf
, enable_multibyte_characters
)))
6451 str
= make_uninit_multibyte_string
(range
, byte_range
);
6453 str
= make_uninit_string
(range
);
6454 /* To check: This returns emacs-utf-8, which is a superset of utf-8.
6455 Is this a problem? */
6456 memcpy
(SDATA
(str
), BYTE_POS_ADDR
(start_byte
), byte_range
);
6463 if (CONSP
(str
) && SYMBOLP
(XCAR
(str
)))
6466 if (CONSP
(str
) && NILP
(XCDR
(str
)))
6471 const
char *utfStr
= SSDATA
(str
);
6472 NSString
*nsStr
= [NSString stringWithUTF8String
: utfStr
];
6477 return [super accessibilityAttributeValue
:attribute
];
6479 #endif
/* NS_IMPL_COCOA */
6481 /* If we have multiple monitors, one above the other, we don't want to
6482 restrict the height to just one monitor. So we override this. */
6483 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6485 /* When making the frame visible for the first time or if there is just
6486 one screen, we want to constrain. Other times not. */
6487 NSUInteger nr_screens
= [[NSScreen screens
] count
];
6488 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6489 NSTRACE
(constrainFrameRect
);
6491 if (nr_screens
== 1)
6493 NSRect r
= [super constrainFrameRect
:frameRect toScreen
:screen
];
6497 if (f
->output_data.ns
->dont_constrain
6498 || ns_menu_bar_should_be_hidden
())
6501 f
->output_data.ns
->dont_constrain
= 1;
6502 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6505 @
end /* EmacsWindow */
6508 @implementation EmacsFSWindow
6510 - (BOOL
)canBecomeKeyWindow
6515 - (BOOL
)canBecomeMainWindow
6522 /* ==========================================================================
6524 EmacsScroller implementation
6526 ========================================================================== */
6529 @implementation EmacsScroller
6531 /* for repeat button push */
6532 #define SCROLL_BAR_FIRST_DELAY
0.5
6533 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6535 + (CGFloat
) scrollerWidth
6537 /* TODO: if we want to allow variable widths, this is the place to do it,
6538 however neither GNUstep nor Cocoa support it very well */
6539 return [NSScroller scrollerWidth
];
6543 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
6545 NSTRACE
(EmacsScroller_initFrame
);
6547 r.
size.width
= [EmacsScroller scrollerWidth
];
6548 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
6549 [self setContinuous
: YES
];
6550 [self setEnabled
: YES
];
6552 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
6553 locked against the top and bottom edges, and right edge on OS X, where
6554 scrollers are on right. */
6555 #ifdef NS_IMPL_GNUSTEP
6556 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
6558 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
6563 pixel_height
= NSHeight
(r
);
6564 if (pixel_height
== 0) pixel_height
= 1;
6565 min_portion
= 20 / pixel_height
;
6567 frame
= XFRAME
(XWINDOW
(win
)->frame
);
6568 if (FRAME_LIVE_P
(frame
))
6571 EmacsView
*view = FRAME_NS_VIEW
(frame
);
6572 NSView
*sview
= [[view window
] contentView
];
6573 NSArray
*subs
= [sview subviews
];
6575 /* disable optimization stopping redraw of other scrollbars */
6576 view->scrollbarsNeedingUpdate
= 0;
6577 for (i
=[subs count
]-1; i
>= 0; i
--)
6578 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
6579 view->scrollbarsNeedingUpdate
++;
6580 [sview addSubview
: self
];
6583 /* [self setFrame: r]; */
6589 - (void
)setFrame
: (NSRect
)newRect
6591 NSTRACE
(EmacsScroller_setFrame
);
6592 /* block_input (); */
6593 pixel_height
= NSHeight
(newRect
);
6594 if (pixel_height
== 0) pixel_height
= 1;
6595 min_portion
= 20 / pixel_height
;
6596 [super setFrame
: newRect
];
6598 /* unblock_input (); */
6604 NSTRACE
(EmacsScroller_dealloc
);
6606 wset_vertical_scroll_bar
(XWINDOW
(win
), Qnil
);
6634 /* ensure other scrollbar updates after deletion */
6635 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6637 view->scrollbarsNeedingUpdate
++;
6638 [self removeFromSuperview
];
6646 - (void
)resetCursorRects
6648 NSRect visible
= [self visibleRect
];
6649 NSTRACE
(resetCursorRects
);
6651 if (!NSIsEmptyRect
(visible
))
6652 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
6653 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
6657 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
6660 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
6661 && portion
!= whole
; /* needed for resize empty buf */
6665 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
6667 NSTRACE
(setPosition
);
6669 em_position
= position
;
6670 em_portion
= portion
;
6673 if (portion
>= whole
)
6675 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6676 [self setKnobProportion
: 1.0];
6677 [self setDoubleValue
: 1.0];
6679 [self setFloatValue
: 0.0 knobProportion
: 1.0];
6685 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
6686 pos
= (float
)position
/ (whole
- portion
);
6687 por
= (float
)portion
/whole
;
6688 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6689 [self setKnobProportion
: por
];
6690 [self setDoubleValue
: pos
];
6692 [self setFloatValue
: pos knobProportion
: por
];
6696 /* Events may come here even if the event loop is not running.
6697 If we don't enter the event loop, the scroll bar will not update.
6698 So send SIGIO to ourselves. */
6699 if (apploopnr
== 0) raise
(SIGIO
);
6704 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
6705 drag events will go directly to the EmacsScroller. Leaving in for now. */
6706 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
6707 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
6709 *part
= last_hit_part
;
6711 XSETINT
(*y
, pixel_height
);
6712 if ([self floatValue
] > 0.999)
6713 XSETINT
(*x
, pixel_height
);
6715 XSETINT
(*x
, pixel_height
* [self floatValue
]);
6719 /* set up emacs_event */
6720 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
6725 emacs_event
->part
= last_hit_part
;
6726 emacs_event
->code
= 0;
6727 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
6728 emacs_event
->frame_or_window
= win
;
6729 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
6730 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
6731 emacs_event
->arg
= Qnil
;
6732 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
6733 XSETINT
(emacs_event
->y
, pixel_height
-20);
6737 n_emacs_events_pending
++;
6738 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
6741 hold_event
(emacs_event
);
6742 EVENT_INIT
(*emacs_event
);
6743 ns_send_appdefined
(-1);
6747 /* called manually thru timer to implement repeated button action w/hold-down */
6748 - repeatScroll
: (NSTimer
*)scrollEntry
6750 NSEvent
*e
= [[self window
] currentEvent
];
6751 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
6752 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
6754 /* clear timer if need be */
6755 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
6757 [scroll_repeat_entry invalidate
];
6758 [scroll_repeat_entry release
];
6759 scroll_repeat_entry
= nil
;
6765 = [[NSTimer scheduledTimerWithTimeInterval
:
6766 SCROLL_BAR_CONTINUOUS_DELAY
6768 selector
: @selector
(repeatScroll
:)
6774 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
6779 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
6780 mouseDragged events without going into a modal loop. */
6781 - (void
)mouseDown
: (NSEvent
*)e
6784 /* hitPart is only updated AFTER event is passed on */
6785 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6786 double inc
= 0.0, loc
, kloc
, pos
;
6789 NSTRACE
(EmacsScroller_mouseDown
);
6793 case NSScrollerDecrementPage
:
6794 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6795 case NSScrollerIncrementPage
:
6796 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6797 case NSScrollerDecrementLine
:
6798 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6799 case NSScrollerIncrementLine
:
6800 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6801 case NSScrollerKnob
:
6802 last_hit_part
= scroll_bar_handle
; break;
6803 case NSScrollerKnobSlot
: /* GNUstep-only */
6804 last_hit_part
= scroll_bar_move_ratio
; break;
6805 default
: /* NSScrollerNoPart? */
6806 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
6813 pos
= 0; /* ignored */
6815 /* set a timer to repeat, as we can't let superclass do this modally */
6817 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
6819 selector
: @selector
(repeatScroll
:)
6826 /* handle, or on GNUstep possibly slot */
6827 NSEvent
*fake_event
;
6829 /* compute float loc in slot and mouse offset on knob */
6830 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6832 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6838 else if (loc
>= NSHeight
(sr
))
6840 loc
= NSHeight
(sr
);
6848 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6850 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6852 last_mouse_offset
= kloc
;
6854 /* if knob, tell emacs a location offset by knob pos
6855 (to indicate top of handle) */
6856 if (part
== NSScrollerKnob
)
6857 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6859 /* else this is a slot click on GNUstep: go straight there */
6860 pos
= loc
/ NSHeight
(sr
);
6862 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6863 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6864 location
: [e locationInWindow
]
6865 modifierFlags
: [e modifierFlags
]
6866 timestamp
: [e timestamp
]
6867 windowNumber
: [e windowNumber
]
6868 context
: [e context
]
6869 eventNumber
: [e eventNumber
]
6870 clickCount
: [e clickCount
]
6871 pressure
: [e pressure
]];
6872 [super mouseUp
: fake_event
];
6875 if (part
!= NSScrollerKnob
)
6876 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6880 /* Called as we manually track scroller drags, rather than superclass. */
6881 - (void
)mouseDragged
: (NSEvent
*)e
6887 NSTRACE
(EmacsScroller_mouseDragged
);
6889 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6891 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6898 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6900 loc
= NSHeight
(sr
) + last_mouse_offset
;
6904 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6905 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6909 - (void
)mouseUp
: (NSEvent
*)e
6911 if (scroll_repeat_entry
)
6913 [scroll_repeat_entry invalidate
];
6914 [scroll_repeat_entry release
];
6915 scroll_repeat_entry
= nil
;
6921 /* treat scrollwheel events in the bar as though they were in the main window */
6922 - (void
) scrollWheel
: (NSEvent
*)theEvent
6924 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6925 [view mouseDown
: theEvent
];
6928 @
end /* EmacsScroller */
6933 /* ==========================================================================
6935 Font-related functions; these used to be in nsfaces.m
6937 ========================================================================== */
6941 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6943 struct font
*font
= XFONT_OBJECT
(font_object
);
6946 fontset
= fontset_from_font
(font_object
);
6947 FRAME_FONTSET
(f
) = fontset
;
6949 if (FRAME_FONT
(f
) == font
)
6950 /* This font is already set in frame F. There's nothing more to
6954 FRAME_FONT
(f
) = font
;
6956 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6957 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6958 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6960 compute_fringe_widths
(f
, 1);
6962 /* Compute the scroll bar width in character columns. */
6963 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6965 int wid
= FRAME_COLUMN_WIDTH
(f
);
6966 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6967 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6971 int wid
= FRAME_COLUMN_WIDTH
(f
);
6972 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6975 /* Now make the frame display the given font. */
6976 if (FRAME_NS_WINDOW
(f
) != 0)
6977 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6983 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6984 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6988 ns_xlfd_to_fontname
(const
char *xlfd
)
6989 /* --------------------------------------------------------------------------
6990 Convert an X font name (XLFD) to an NS font name.
6991 Only family is used.
6992 The string returned is temporarily allocated.
6993 -------------------------------------------------------------------------- */
6995 char *name
= xmalloc
(180);
6999 if (!strncmp
(xlfd
, "
--"
, 2))
7000 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
7002 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
7004 /* stopgap for malformed XLFD input */
7005 if (strlen
(name
) == 0)
7006 strcpy
(name
, "Monaco"
);
7008 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
7009 also uppercase after '-' or ' ' */
7010 name
[0] = c_toupper
(name
[0]);
7011 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
7017 name
[i
+1] = c_toupper
(name
[i
+1]);
7019 else if (name
[i
] == '_')
7023 name
[i
+1] = c_toupper
(name
[i
+1]);
7026 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
7027 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
7034 syms_of_nsterm
(void
)
7036 NSTRACE
(syms_of_nsterm
);
7038 ns_antialias_threshold
= 10.0;
7040 /* from 23+ we need to tell emacs what modifiers there are.. */
7041 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
7042 DEFSYM
(Qalt
, "alt"
);
7043 DEFSYM
(Qhyper
, "hyper"
);
7044 DEFSYM
(Qmeta
, "
meta"
);
7045 DEFSYM
(Qsuper
, "super"
);
7046 DEFSYM
(Qcontrol
, "control"
);
7047 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
7049 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
7050 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
7051 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
7052 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
7053 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
7055 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
7056 "The file specified in the last NS event."
);
7057 ns_input_file
=Qnil
;
7059 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
7060 "The data received in the last NS
text drag event."
);
7061 ns_input_text
=Qnil
;
7063 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
7064 "String
for visualizing working composition sequence."
);
7065 ns_working_text
=Qnil
;
7067 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
7068 "The font specified in the last NS event."
);
7069 ns_input_font
=Qnil
;
7071 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
7072 "The fontsize specified in the last NS event."
);
7073 ns_input_fontsize
=Qnil
;
7075 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
7076 "The
line specified in the last NS event."
);
7077 ns_input_line
=Qnil
;
7079 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
7080 "The color specified in the last NS event."
);
7081 ns_input_color
=Qnil
;
7083 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
7084 "The service name specified in the last NS event."
);
7085 ns_input_spi_name
=Qnil
;
7087 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
7088 "The service argument specified in the last NS event."
);
7089 ns_input_spi_arg
=Qnil
;
7091 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
7092 "This variable describes the behavior of the alternate or option key.
\n\
7093 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7094 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
7095 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7096 ns_alternate_modifier
= Qmeta
;
7098 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
7099 "This variable describes the behavior of the right alternate or option key.
\n\
7100 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7101 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
7102 Set to none means that the alternate / option key is not interpreted by Emacs\n\
7103 at all, allowing it to be used at a lower level for accented character entry.");
7104 ns_right_alternate_modifier = Qleft;
7106 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
7107 "This variable describes the behavior of the command key.\n\
7108 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
7109 ns_command_modifier = Qsuper;
7111 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
7112 "This variable describes the behavior of the right command key.\n\
7113 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7114 Set to left means be the same key as `ns-command-modifier'.
\n\
7115 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
7116 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7117 ns_right_command_modifier
= Qleft
;
7119 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
7120 "This variable describes the behavior of the control key.
\n\
7121 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
7122 ns_control_modifier
= Qcontrol
;
7124 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
7125 "This variable describes the behavior of the right control key.
\n\
7126 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7127 Set to left means be the same key as `ns
-control
-modifier
'.\n\
7128 Set to none means that the control / option key is not interpreted by Emacs\n\
7129 at all, allowing it to be used at a lower level for accented character entry.");
7130 ns_right_control_modifier = Qleft;
7132 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
7133 "This variable describes the behavior of the function key (on laptops).\n\
7134 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7135 Set to none means that the function key is not interpreted by Emacs at all,\n\
7136 allowing it to be used at a lower level for accented character entry.");
7137 ns_function_modifier = Qnone;
7139 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
7140 "Non-nil (the default) means to render text antialiased.");
7141 ns_antialias_text = Qt;
7143 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
7144 "Whether to confirm application quit using dialog.");
7145 ns_confirm_quit = Qnil;
7147 staticpro (&ns_display_name_list);
7148 ns_display_name_list = Qnil;
7150 staticpro (&last_mouse_motion_frame);
7151 last_mouse_motion_frame = Qnil;
7153 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
7154 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
7155 Only works on OSX 10.6 or later. */);
7156 ns_auto_hide_menu_bar = Qnil;
7158 /* TODO: move to common code */
7159 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
7160 doc: /* Which toolkit scroll bars Emacs uses, if any.
7161 A value of nil means Emacs doesn't use toolkit scroll bars.
7162 With the X Window system
, the value is a symbol describing the
7163 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
7164 With MS Windows or Nextstep
, the value is t. */
);
7165 Vx_toolkit_scroll_bars
= Qt
;
7167 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
7168 x_use_underline_position_properties
,
7169 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
7170 A value of nil means ignore them. If you encounter fonts with bogus
7171 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
7172 to 4.1, set this to nil. */);
7173 x_use_underline_position_properties
= 0;
7175 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
7176 x_underline_at_descent_line
,
7177 doc: /* Non-nil means to draw the underline at the same place as the descent line.
7178 A value of nil means to draw the underline according to the value of the
7179 variable `x-use-underline-position-properties', which is usually at the
7180 baseline level. The default value is nil. */);
7181 x_underline_at_descent_line
= 0;
7183 /* Tell emacs about this window system. */
7184 Fprovide
(intern
("ns"
), Qnil
);