1 /* NeXT/Open/GNUstep / MacOSX communication module.
3 Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2013
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 Originally by Carl Edman
23 Updated by Christian Limpach (chris@nice.ch)
24 OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com)
25 MacOSX/Aqua port by Christophe de Dinechin (descubes@earthlink.net)
26 GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
29 /* This should be the first include, as it may set up #defines affecting
30 interpretation of even the system includes. */
36 #include
<sys
/types.h
>
42 #include
<c
-strcase.h
>
46 #include "blockinput.h"
47 #include "sysselect.h"
50 #include "character.h"
52 #include "composite.h"
55 #include "termhooks.h"
63 #ifdef NS_IMPL_GNUSTEP
68 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_5
75 int term_trace_num
= 0;
76 #define NSTRACE
(x
) fprintf (stderr
, "
%s:%d: [%d] " #x "\n", \
77 __FILE__
, __LINE__
, ++term_trace_num
)
82 /* Detailed tracing. "S" means "size" and "LL" stands for "lower left". */
84 int term_trace_num
= 0;
85 #define NSTRACE_SIZE
(str
,size) fprintf (stderr
, \
87 "
(S
:%.0f x %.0f)\n", \
88 __FILE__
, __LINE__
, ++term_trace_num
,\
91 #define NSTRACE_RECT
(s
,r
) fprintf (stderr
, \
93 "
(LL
:%.0f x %.0f -> S:%.0f x %.0f)\n", \
94 __FILE__
, __LINE__
, ++term_trace_num
,\
100 #define NSTRACE_SIZE
(str
,size)
101 #define NSTRACE_RECT
(s
,r
)
104 extern NSString
*NSMenuDidBeginTrackingNotification
;
106 /* ==========================================================================
110 ========================================================================== */
112 /* Convert a symbol indexed with an NSxxx value to a value as defined
113 in keyboard.c (lispy_function_key). I hope this is a correct way
114 of doing things... */
115 static unsigned convert_ns_to_X_keysym
[] =
117 NSHomeFunctionKey
, 0x50,
118 NSLeftArrowFunctionKey
, 0x51,
119 NSUpArrowFunctionKey
, 0x52,
120 NSRightArrowFunctionKey
, 0x53,
121 NSDownArrowFunctionKey
, 0x54,
122 NSPageUpFunctionKey
, 0x55,
123 NSPageDownFunctionKey
, 0x56,
124 NSEndFunctionKey
, 0x57,
125 NSBeginFunctionKey
, 0x58,
126 NSSelectFunctionKey
, 0x60,
127 NSPrintFunctionKey
, 0x61,
128 NSClearLineFunctionKey
, 0x0B,
129 NSExecuteFunctionKey
, 0x62,
130 NSInsertFunctionKey
, 0x63,
131 NSUndoFunctionKey
, 0x65,
132 NSRedoFunctionKey
, 0x66,
133 NSMenuFunctionKey
, 0x67,
134 NSFindFunctionKey
, 0x68,
135 NSHelpFunctionKey
, 0x6A,
136 NSBreakFunctionKey
, 0x6B,
138 NSF1FunctionKey
, 0xBE,
139 NSF2FunctionKey
, 0xBF,
140 NSF3FunctionKey
, 0xC0,
141 NSF4FunctionKey
, 0xC1,
142 NSF5FunctionKey
, 0xC2,
143 NSF6FunctionKey
, 0xC3,
144 NSF7FunctionKey
, 0xC4,
145 NSF8FunctionKey
, 0xC5,
146 NSF9FunctionKey
, 0xC6,
147 NSF10FunctionKey
, 0xC7,
148 NSF11FunctionKey
, 0xC8,
149 NSF12FunctionKey
, 0xC9,
150 NSF13FunctionKey
, 0xCA,
151 NSF14FunctionKey
, 0xCB,
152 NSF15FunctionKey
, 0xCC,
153 NSF16FunctionKey
, 0xCD,
154 NSF17FunctionKey
, 0xCE,
155 NSF18FunctionKey
, 0xCF,
156 NSF19FunctionKey
, 0xD0,
157 NSF20FunctionKey
, 0xD1,
158 NSF21FunctionKey
, 0xD2,
159 NSF22FunctionKey
, 0xD3,
160 NSF23FunctionKey
, 0xD4,
161 NSF24FunctionKey
, 0xD5,
163 NSBackspaceCharacter
, 0x08, /* 8: Not on some KBs. */
164 NSDeleteCharacter
, 0xFF, /* 127: Big 'delete' key upper right. */
165 NSDeleteFunctionKey
, 0x9F, /* 63272: Del forw key off main array. */
167 NSTabCharacter
, 0x09,
168 0x19, 0x09, /* left tab->regular since pass shift */
169 NSCarriageReturnCharacter
, 0x0D,
170 NSNewlineCharacter
, 0x0D,
171 NSEnterCharacter
, 0x8D,
173 0x41|NSNumericPadKeyMask
, 0xAE, /* KP_Decimal */
174 0x43|NSNumericPadKeyMask
, 0xAA, /* KP_Multiply */
175 0x45|NSNumericPadKeyMask
, 0xAB, /* KP_Add */
176 0x4B|NSNumericPadKeyMask
, 0xAF, /* KP_Divide */
177 0x4E|NSNumericPadKeyMask
, 0xAD, /* KP_Subtract */
178 0x51|NSNumericPadKeyMask
, 0xBD, /* KP_Equal */
179 0x52|NSNumericPadKeyMask
, 0xB0, /* KP_0 */
180 0x53|NSNumericPadKeyMask
, 0xB1, /* KP_1 */
181 0x54|NSNumericPadKeyMask
, 0xB2, /* KP_2 */
182 0x55|NSNumericPadKeyMask
, 0xB3, /* KP_3 */
183 0x56|NSNumericPadKeyMask
, 0xB4, /* KP_4 */
184 0x57|NSNumericPadKeyMask
, 0xB5, /* KP_5 */
185 0x58|NSNumericPadKeyMask
, 0xB6, /* KP_6 */
186 0x59|NSNumericPadKeyMask
, 0xB7, /* KP_7 */
187 0x5B|NSNumericPadKeyMask
, 0xB8, /* KP_8 */
188 0x5C|NSNumericPadKeyMask
, 0xB9, /* KP_9 */
190 0x1B, 0x1B /* escape */
193 static Lisp_Object Qmodifier_value
;
194 Lisp_Object Qalt
, Qcontrol
, Qhyper
, Qmeta
, Qsuper
;
195 extern Lisp_Object Qcursor_color
, Qcursor_type
, Qns
, Qleft
;
197 static Lisp_Object QUTF8_STRING
;
198 static Lisp_Object Qcocoa
, Qgnustep
;
200 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
201 the maximum font size to NOT antialias. On GNUstep there is currently
202 no way to control this behavior. */
203 float ns_antialias_threshold
;
205 NSArray
*ns_send_types
=0, *ns_return_types
=0, *ns_drag_types
=0;
206 NSString
*ns_app_name
= @"Emacs"
; /* default changed later */
208 /* Display variables */
209 struct ns_display_info
*x_display_list
; /* Chain of existing displays */
210 long context_menu_value
= 0;
213 static
struct frame
*ns_updating_frame
;
214 static NSView
*focus_view
= NULL;
215 static int ns_window_num
= 0;
216 #ifdef NS_IMPL_GNUSTEP
219 static BOOL gsaved
= NO
;
220 static BOOL ns_fake_keydown
= NO
;
222 static BOOL ns_menu_bar_is_hidden
= NO
;
224 /*static int debug_lock = 0; */
227 static BOOL send_appdefined
= YES
;
228 #define NO_APPDEFINED_DATA
(-8)
229 static int last_appdefined_event_data
= NO_APPDEFINED_DATA
;
230 static NSTimer
*timed_entry
= 0;
231 static NSTimer
*scroll_repeat_entry
= nil
;
232 static fd_set select_readfds
, select_writefds
;
233 enum
{ SELECT_HAVE_READ
= 1, SELECT_HAVE_WRITE
= 2, SELECT_HAVE_TMO
= 4 };
234 static int select_nfds
= 0, select_valid
= 0;
235 static
struct timespec select_timeout
= { 0, 0 };
236 static int selfds
[2] = { -1, -1 };
237 static pthread_mutex_t select_mutex
;
238 static int apploopnr
= 0;
239 static NSAutoreleasePool
*outerpool
;
240 static
struct input_event
*emacs_event
= NULL;
241 static
struct input_event
*q_event_ptr
= NULL;
242 static int n_emacs_events_pending
= 0;
243 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
244 *ns_pending_service_args
;
245 static BOOL ns_do_open_file
= NO
;
246 static BOOL ns_last_use_native_fullscreen
;
249 struct input_event
*q
;
257 * State for pending menu activation:
258 * MENU_NONE Normal state
259 * MENU_PENDING A menu has been clicked on, but has been canceled so we can
260 * run lisp to update the menu.
261 * MENU_OPENING Menu is up to date, and the click event is redone so the menu
265 #define MENU_PENDING
1
266 #define MENU_OPENING
2
267 static int menu_will_open_state
= MENU_NONE
;
269 /* Saved position for menu click. */
270 static CGPoint menu_mouse_point
;
273 /* Convert modifiers in a NeXTstep event to emacs style modifiers. */
274 #define NS_FUNCTION_KEY_MASK
0x800000
275 #define NSLeftControlKeyMask
(0x000001 | NSControlKeyMask
)
276 #define NSRightControlKeyMask
(0x002000 | NSControlKeyMask
)
277 #define NSLeftCommandKeyMask
(0x000008 | NSCommandKeyMask
)
278 #define NSRightCommandKeyMask
(0x000010 | NSCommandKeyMask
)
279 #define NSLeftAlternateKeyMask
(0x000020 | NSAlternateKeyMask
)
280 #define NSRightAlternateKeyMask
(0x000040 | NSAlternateKeyMask
)
281 #define EV_MODIFIERS
(e
) \
282 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
283 hyper_modifier
: 0) \
284 |
(!EQ
(ns_right_alternate_modifier
, Qleft
) && \
285 (([e modifierFlags
] & NSRightAlternateKeyMask
) \
286 == NSRightAlternateKeyMask
) ? \
287 parse_solitary_modifier
(ns_right_alternate_modifier
) : 0) \
288 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
289 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
290 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
291 shift_modifier
: 0) \
292 |
(!EQ
(ns_right_control_modifier
, Qleft
) && \
293 (([e modifierFlags
] & NSRightControlKeyMask
) \
294 == NSRightControlKeyMask
) ? \
295 parse_solitary_modifier
(ns_right_control_modifier
) : 0) \
296 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
297 parse_solitary_modifier
(ns_control_modifier
) : 0) \
298 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
299 parse_solitary_modifier
(ns_function_modifier
) : 0) \
300 |
(!EQ
(ns_right_command_modifier
, Qleft
) && \
301 (([e modifierFlags
] & NSRightCommandKeyMask
) \
302 == NSRightCommandKeyMask
) ? \
303 parse_solitary_modifier
(ns_right_command_modifier
) : 0) \
304 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
305 parse_solitary_modifier
(ns_command_modifier
):0))
307 #define EV_UDMODIFIERS
(e
) \
308 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
309 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
310 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
311 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
312 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
313 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
314 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
315 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
316 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
318 #define EV_BUTTON
(e
) \
319 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
320 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
321 [e buttonNumber
] - 1)
323 /* Convert the time field to a timestamp in milliseconds. */
324 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
326 /* This is a piece of code which is common to all the event handling
327 methods. Maybe it should even be a function. */
328 #define EV_TRAILER
(e
) \
330 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
334 #define EV_TRAILER2
(e
) \
336 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
339 n_emacs_events_pending
++; \
340 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
343 hold_event
(emacs_event
); \
344 EVENT_INIT
(*emacs_event
); \
345 ns_send_appdefined
(-1); \
348 /* TODO: get rid of need for these forward declarations */
349 static void ns_condemn_scroll_bars
(struct frame
*f
);
350 static void ns_judge_scroll_bars
(struct frame
*f
);
351 void x_set_frame_alpha
(struct frame
*f
);
354 /* ==========================================================================
358 ========================================================================== */
361 hold_event
(struct input_event
*event
)
363 if (hold_event_q.nr
== hold_event_q.cap
)
365 if (hold_event_q.cap
== 0) hold_event_q.cap
= 10;
366 else hold_event_q.cap
*= 2;
368 xrealloc
(hold_event_q.q
, hold_event_q.cap
* sizeof
*hold_event_q.q
);
371 hold_event_q.q
[hold_event_q.nr
++] = *event
;
372 /* Make sure ns_read_socket is called, i.e. we have input. */
374 send_appdefined
= YES
;
378 append2
(Lisp_Object list
, Lisp_Object item
)
379 /* --------------------------------------------------------------------------
380 Utility to append to a list
381 -------------------------------------------------------------------------- */
383 Lisp_Object array
[2];
385 array
[1] = list1
(item
);
386 return Fnconc
(2, &array
[0]);
391 ns_etc_directory
(void
)
392 /* If running as a self-contained app bundle, return as a string the
393 filename of the etc directory, if present; else nil. */
395 NSBundle
*bundle
= [NSBundle mainBundle
];
396 NSString
*resourceDir
= [bundle resourcePath
];
397 NSString
*resourcePath
;
398 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
401 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
402 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
404 if (isDir
) return [resourcePath UTF8String
];
412 /* If running as a self-contained app bundle, return as a path string
413 the filenames of the libexec and bin directories, ie libexec:bin.
414 Otherwise, return nil.
415 Normally, Emacs does not add its own bin/ directory to the PATH.
416 However, a self-contained NS build has a different layout, with
417 bin/ and libexec/ subdirectories in the directory that contains
419 We put libexec first, because init_callproc_1 uses the first
420 element to initialize exec-directory. An alternative would be
421 for init_callproc to check for invocation-directory/libexec.
424 NSBundle
*bundle
= [NSBundle mainBundle
];
425 NSString
*resourceDir
= [bundle resourcePath
];
426 NSString
*binDir
= [bundle bundlePath
];
427 NSString
*resourcePath
, *resourcePaths
;
429 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
430 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
432 NSEnumerator
*pathEnum
;
435 range
= [resourceDir rangeOfString
: @"Contents"
];
436 if (range.location
!= NSNotFound
)
438 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
440 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
444 paths
= [binDir stringsByAppendingPaths
:
445 [NSArray arrayWithObjects
: @"libexec"
, @"bin"
, nil
]];
446 pathEnum
= [paths objectEnumerator
];
449 while ((resourcePath
= [pathEnum nextObject
]))
451 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
454 if ([resourcePaths
length] > 0)
456 = [resourcePaths stringByAppendingString
: pathSeparator
];
458 = [resourcePaths stringByAppendingString
: resourcePath
];
461 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
469 /* If running as a self-contained app bundle, return as a path string
470 the filenames of the site-lisp and lisp directories.
471 Ie, site-lisp:lisp. Otherwise, return nil. */
473 NSBundle
*bundle
= [NSBundle mainBundle
];
474 NSString
*resourceDir
= [bundle resourcePath
];
475 NSString
*resourcePath
, *resourcePaths
;
476 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
477 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
479 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
480 [NSArray arrayWithObjects
:
481 @"site
-lisp"
, @"lisp"
, nil
]];
482 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
485 /* Hack to skip site-lisp. */
486 if (no_site_lisp
) resourcePath
= [pathEnum nextObject
];
488 while ((resourcePath
= [pathEnum nextObject
]))
490 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
493 if ([resourcePaths
length] > 0)
495 = [resourcePaths stringByAppendingString
: pathSeparator
];
497 = [resourcePaths stringByAppendingString
: resourcePath
];
500 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
506 ns_timeout
(int usecs
)
507 /* --------------------------------------------------------------------------
508 Blocking timer utility used by ns_ring_bell
509 -------------------------------------------------------------------------- */
511 struct timespec wakeup
= timespec_add
(current_timespec
(),
512 make_timespec
(0, usecs
* 1000));
514 /* Keep waiting until past the time wakeup. */
517 struct timespec timeout
, now
= current_timespec
();
518 if (timespec_cmp
(wakeup
, now
) <= 0)
520 timeout
= timespec_sub
(wakeup
, now
);
522 /* Try to wait that long--but we might wake up sooner. */
523 pselect
(0, NULL, NULL, NULL, &timeout
, NULL);
529 ns_release_object
(void
*obj
)
530 /* --------------------------------------------------------------------------
531 Release an object (callable from C)
532 -------------------------------------------------------------------------- */
539 ns_retain_object
(void
*obj
)
540 /* --------------------------------------------------------------------------
541 Retain an object (callable from C)
542 -------------------------------------------------------------------------- */
549 ns_alloc_autorelease_pool
(void
)
550 /* --------------------------------------------------------------------------
551 Allocate a pool for temporary objects (callable from C)
552 -------------------------------------------------------------------------- */
554 return [[NSAutoreleasePool alloc
] init
];
559 ns_release_autorelease_pool
(void
*pool
)
560 /* --------------------------------------------------------------------------
561 Free a pool and temporary objects it refers to (callable from C)
562 -------------------------------------------------------------------------- */
564 ns_release_object
(pool
);
569 /* ==========================================================================
571 Focus (clipping) and screen update
573 ========================================================================== */
576 // Window constraining
577 // -------------------
579 // To ensure that the windows are not placed under the
menu bar, they
580 // are typically moved by the call
-back constrainFrameRect. However
,
581 // by overriding it
, it
's possible to inhibit this, leaving the window
582 // in it's original position.
584 // It
's possible to hide the menu bar. However, technically, it's only
585 // possible to hide it when the application is active. To ensure that
586 // this work properly
, the
menu bar and window constraining are
587 // deferred until the application becomes active.
589 // Even though it
's not possible to manually move a window above the
590 // top of the screen, it is allowed if it's done programmatically
,
591 // when the
menu is
hidden. This allows the editable area to cover the
592 // full screen height.
597 // Use the following extra files
:
600 // ;; Hide
menu and place frame slightly above the top of the screen.
601 // (setq ns
-auto
-hide
-menu-bar t
)
602 // (set-frame
-position
(selected
-frame
) 0 -20)
606 // emacs
-Q
-l init.el
608 // Result
: No
menu bar, and the
title bar should be above the screen.
614 // Result
: Menu bar visible
, frame placed immediately below the
menu.
618 ns_constrain_all_frames
(void
)
620 Lisp_Object tail
, frame
;
622 FOR_EACH_FRAME
(tail
, frame
)
624 struct frame
*f
= XFRAME
(frame
);
627 NSView
*view = FRAME_NS_VIEW
(f
);
628 /* This no-op will trigger the default window placing
629 * constraint system. */
630 [[view window
] setFrameOrigin
:[[view window
] frame
].origin
];
636 /* True, if the menu bar should be hidden. */
639 ns_menu_bar_should_be_hidden
(void
)
641 return !NILP
(ns_auto_hide_menu_bar
)
642 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)];
646 /* Show or hide the menu bar, based on user setting. */
649 ns_update_auto_hide_menu_bar
(void
)
652 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
655 NSTRACE
(ns_update_auto_hide_menu_bar
);
657 if (NSApp
!= nil
&& [NSApp isActive
])
659 // Note
, "setPresentationOptions" triggers an
error unless the
660 // application is active.
661 BOOL menu_bar_should_be_hidden
= ns_menu_bar_should_be_hidden
();
663 if (menu_bar_should_be_hidden
!= ns_menu_bar_is_hidden
)
665 NSApplicationPresentationOptions options
666 = NSApplicationPresentationDefault
;
668 if (menu_bar_should_be_hidden
)
669 options |
= NSApplicationPresentationAutoHideMenuBar
670 | NSApplicationPresentationAutoHideDock
;
672 [NSApp setPresentationOptions
: options
];
674 ns_menu_bar_is_hidden
= menu_bar_should_be_hidden
;
676 if (!ns_menu_bar_is_hidden
)
678 ns_constrain_all_frames
();
690 ns_update_begin
(struct frame
*f
)
691 /* --------------------------------------------------------------------------
692 Prepare for a grouped sequence of drawing calls
693 external (RIF) call; whole frame, called before update_window_begin
694 -------------------------------------------------------------------------- */
696 EmacsView
*view = FRAME_NS_VIEW
(f
);
697 NSTRACE
(ns_update_begin
);
699 ns_update_auto_hide_menu_bar
();
702 if ([view isFullscreen
] && [view fsIsNative
])
704 // Fix reappearing tool
bar in fullscreen
for OSX
10.7
705 BOOL tbar_visible
= FRAME_EXTERNAL_TOOL_BAR
(f
) ? YES
: NO
;
706 NSToolbar
*toolbar
= [FRAME_NS_VIEW
(f
) toolbar
];
707 if (! tbar_visible
!= ! [toolbar isVisible
])
708 [toolbar setVisible
: tbar_visible
];
712 ns_updating_frame
= f
;
715 /* drawRect may have been called for say the minibuffer, and then clip path
716 is for the minibuffer. But the display engine may draw more because
717 we have set the frame as garbaged. So reset clip path to the whole
722 NSRect r
= [view frame
];
723 NSRect cr
= [[view window
] frame
];
724 /* If a large frame size is set, r may be larger than the window frame
725 before constrained. In that case don't change the clip path, as we
726 will clear in to the tool bar and title bar. */
728 + FRAME_NS_TITLEBAR_HEIGHT
(f
)
729 + FRAME_TOOLBAR_HEIGHT
(f
) <= cr.
size.height
)
731 bp
= [[NSBezierPath bezierPathWithRect
: r
] retain
];
738 #ifdef NS_IMPL_GNUSTEP
739 uRect
= NSMakeRect
(0, 0, 0, 0);
745 ns_update_window_begin
(struct window
*w
)
746 /* --------------------------------------------------------------------------
747 Prepare for a grouped sequence of drawing calls
748 external (RIF) call; for one window, called after update_begin
749 -------------------------------------------------------------------------- */
751 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
752 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
754 NSTRACE
(ns_update_window_begin
);
755 w
->output_cursor
= w
->cursor
;
759 if (f
== hlinfo
->mouse_face_mouse_frame
)
761 /* Don't do highlighting for mouse motion during the update. */
762 hlinfo
->mouse_face_defer
= 1;
764 /* If the frame needs to be redrawn,
765 simply forget about any prior mouse highlighting. */
766 if (FRAME_GARBAGED_P
(f
))
767 hlinfo
->mouse_face_window
= Qnil
;
769 /* (further code for mouse faces ifdef'd out in other terms elided) */
777 ns_update_window_end
(struct window
*w
, bool cursor_on_p
,
778 bool mouse_face_overwritten_p
)
779 /* --------------------------------------------------------------------------
780 Finished a grouped sequence of drawing calls
781 external (RIF) call; for one window called before update_end
782 -------------------------------------------------------------------------- */
784 /* note: this fn is nearly identical in all terms */
785 if (!w
->pseudo_window_p
)
790 display_and_set_cursor
(w
, 1,
791 w
->output_cursor.hpos
, w
->output_cursor.vpos
,
792 w
->output_cursor.x
, w
->output_cursor.y
);
794 if (draw_window_fringes
(w
, 1))
796 if (WINDOW_RIGHT_DIVIDER_WIDTH
(w
))
797 x_draw_right_divider
(w
);
799 x_draw_vertical_border
(w
);
805 /* If a row with mouse-face was overwritten, arrange for
806 frame_up_to_date to redisplay the mouse highlight. */
807 if (mouse_face_overwritten_p
)
808 reset_mouse_highlight
(MOUSE_HL_INFO
(XFRAME
(w
->frame
)));
810 NSTRACE
(update_window_end
);
815 ns_update_end
(struct frame
*f
)
816 /* --------------------------------------------------------------------------
817 Finished a grouped sequence of drawing calls
818 external (RIF) call; for whole frame, called after update_window_end
819 -------------------------------------------------------------------------- */
821 EmacsView
*view = FRAME_NS_VIEW
(f
);
823 /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
824 MOUSE_HL_INFO
(f
)->mouse_face_defer
= 0;
829 [[view window
] flushWindow
];
832 ns_updating_frame
= NULL;
833 NSTRACE
(ns_update_end
);
837 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
838 /* --------------------------------------------------------------------------
839 Internal: Focus on given frame. During small local updates this is used to
840 draw, however during large updates, ns_update_begin and ns_update_end are
841 called to wrap the whole thing, in which case these calls are stubbed out.
842 Except, on GNUstep, we accumulate the rectangle being drawn into, because
843 the back end won't do this automatically, and will just end up flushing
845 -------------------------------------------------------------------------- */
847 // NSTRACE
(ns_focus
);
849 fprintf (stderr, "focus: %d", c++);
850 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
851 fprintf (stderr, "\n"); */
853 if (f
!= ns_updating_frame
)
855 NSView
*view = FRAME_NS_VIEW
(f
);
856 if (view != focus_view
)
858 if (focus_view
!= NULL)
860 [focus_view unlockFocus
];
861 [[focus_view window
] flushWindow
];
868 /*if (view) debug_lock++; */
875 [[NSGraphicsContext currentContext
] saveGraphicsState
];
877 NSRectClipList
(r
, 2);
886 ns_unfocus
(struct frame
*f
)
887 /* --------------------------------------------------------------------------
888 Internal: Remove focus on given frame
889 -------------------------------------------------------------------------- */
891 // NSTRACE
(ns_unfocus
);
895 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
899 if (f
!= ns_updating_frame
)
901 if (focus_view
!= NULL)
903 [focus_view unlockFocus
];
904 [[focus_view window
] flushWindow
];
913 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
,
914 enum glyph_row_area area
, BOOL gc
)
915 /* --------------------------------------------------------------------------
916 Internal (but parallels other terms): Focus drawing on given row
917 -------------------------------------------------------------------------- */
919 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
921 int window_x
, window_y
, window_width
;
923 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
925 clip_rect.origin.x
= window_x
;
926 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
927 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
928 clip_rect.
size.width
= window_width
;
929 clip_rect.
size.height
= row
->visible_height
;
931 ns_focus
(f
, &clip_rect
, 1);
936 ns_ring_bell
(struct frame
*f
)
937 /* --------------------------------------------------------------------------
939 -------------------------------------------------------------------------- */
941 NSTRACE
(ns_ring_bell
);
944 NSAutoreleasePool
*pool
;
945 struct frame
*frame
= SELECTED_FRAME
();
949 pool
= [[NSAutoreleasePool alloc
] init
];
951 view = FRAME_NS_VIEW
(frame
);
955 NSPoint dim
= NSMakePoint
(128, 128);
958 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
959 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
960 r.
size.width
= dim.x
;
961 r.
size.height
= dim.y
;
962 surr
= NSInsetRect
(r
, -2, -2);
963 ns_focus
(frame
, &surr
, 1);
964 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
965 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
966 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
968 [[view window
] flushWindow
];
970 [[view window
] restoreCachedImage
];
971 [[view window
] flushWindow
];
983 /* ==========================================================================
985 Frame / window manager related functions
987 ========================================================================== */
991 ns_raise_frame
(struct frame
*f
)
992 /* --------------------------------------------------------------------------
993 Bring window to foreground and make it active
994 -------------------------------------------------------------------------- */
997 check_window_system
(f
);
998 view = FRAME_NS_VIEW
(f
);
1000 if (FRAME_VISIBLE_P
(f
))
1001 [[view window
] makeKeyAndOrderFront
: NSApp
];
1007 ns_lower_frame
(struct frame
*f
)
1008 /* --------------------------------------------------------------------------
1010 -------------------------------------------------------------------------- */
1013 check_window_system
(f
);
1014 view = FRAME_NS_VIEW
(f
);
1016 [[view window
] orderBack
: NSApp
];
1022 ns_frame_raise_lower
(struct frame
*f
, int raise
)
1023 /* --------------------------------------------------------------------------
1025 -------------------------------------------------------------------------- */
1027 NSTRACE
(ns_frame_raise_lower
);
1037 ns_frame_rehighlight
(struct frame
*frame
)
1038 /* --------------------------------------------------------------------------
1039 External (hook): called on things like window switching within frame
1040 -------------------------------------------------------------------------- */
1042 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(frame
);
1043 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1045 NSTRACE
(ns_frame_rehighlight
);
1046 if (dpyinfo
->x_focus_frame
)
1048 dpyinfo
->x_highlight_frame
1049 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1050 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1051 : dpyinfo
->x_focus_frame
);
1052 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
1054 fset_focus_frame
(dpyinfo
->x_focus_frame
, Qnil
);
1055 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1059 dpyinfo
->x_highlight_frame
= 0;
1061 if (dpyinfo
->x_highlight_frame
&&
1062 dpyinfo
->x_highlight_frame
!= old_highlight
)
1066 x_update_cursor
(old_highlight
, 1);
1067 x_set_frame_alpha
(old_highlight
);
1069 if (dpyinfo
->x_highlight_frame
)
1071 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
1072 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
1079 x_make_frame_visible
(struct frame
*f
)
1080 /* --------------------------------------------------------------------------
1081 External: Show the window (X11 semantics)
1082 -------------------------------------------------------------------------- */
1084 NSTRACE
(x_make_frame_visible
);
1085 /* XXX: at some points in past this was not needed, as the only place that
1086 called this (frame.c:Fraise_frame ()) also called raise_lower;
1087 if this ends up the case again, comment this out again. */
1088 if (!FRAME_VISIBLE_P
(f
))
1090 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(f
);
1092 SET_FRAME_VISIBLE
(f
, 1);
1095 /* Making a new frame from a fullscreen frame will make the new frame
1096 fullscreen also. So skip handleFS as this will print an error. */
1097 if ([view fsIsNative
] && f
->want_fullscreen
== FULLSCREEN_BOTH
1098 && [view isFullscreen
])
1101 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
1112 x_make_frame_invisible
(struct frame
*f
)
1113 /* --------------------------------------------------------------------------
1114 External: Hide the window (X11 semantics)
1115 -------------------------------------------------------------------------- */
1118 NSTRACE
(x_make_frame_invisible
);
1119 check_window_system
(f
);
1120 view = FRAME_NS_VIEW
(f
);
1121 [[view window
] orderOut
: NSApp
];
1122 SET_FRAME_VISIBLE
(f
, 0);
1123 SET_FRAME_ICONIFIED
(f
, 0);
1128 x_iconify_frame
(struct frame
*f
)
1129 /* --------------------------------------------------------------------------
1130 External: Iconify window
1131 -------------------------------------------------------------------------- */
1134 struct ns_display_info
*dpyinfo
;
1136 NSTRACE
(x_iconify_frame
);
1137 check_window_system
(f
);
1138 view = FRAME_NS_VIEW
(f
);
1139 dpyinfo
= FRAME_DISPLAY_INFO
(f
);
1141 if (dpyinfo
->x_highlight_frame
== f
)
1142 dpyinfo
->x_highlight_frame
= 0;
1144 if ([[view window
] windowNumber
] <= 0)
1146 /* the window is still deferred. Make it very small, bring it
1147 on screen and order it out. */
1148 NSRect s
= { { 100, 100}, {0, 0} };
1150 t
= [[view window
] frame
];
1151 [[view window
] setFrame
: s display
: NO
];
1152 [[view window
] orderBack
: NSApp
];
1153 [[view window
] orderOut
: NSApp
];
1154 [[view window
] setFrame
: t display
: NO
];
1156 [[view window
] miniaturize
: NSApp
];
1159 /* Free X resources of frame F. */
1162 x_free_frame_resources
(struct frame
*f
)
1165 struct ns_display_info
*dpyinfo
;
1166 Mouse_HLInfo
*hlinfo
;
1168 NSTRACE
(x_free_frame_resources
);
1169 check_window_system
(f
);
1170 view = FRAME_NS_VIEW
(f
);
1171 dpyinfo
= FRAME_DISPLAY_INFO
(f
);
1172 hlinfo
= MOUSE_HL_INFO
(f
);
1174 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1178 free_frame_menubar
(f
);
1179 free_frame_faces
(f
);
1181 if (f
== dpyinfo
->x_focus_frame
)
1182 dpyinfo
->x_focus_frame
= 0;
1183 if (f
== dpyinfo
->x_highlight_frame
)
1184 dpyinfo
->x_highlight_frame
= 0;
1185 if (f
== hlinfo
->mouse_face_mouse_frame
)
1186 reset_mouse_highlight
(hlinfo
);
1188 if (f
->output_data.ns
->miniimage
!= nil
)
1189 [f
->output_data.ns
->miniimage release
];
1191 [[view window
] close];
1194 xfree
(f
->output_data.ns
);
1200 x_destroy_window
(struct frame
*f
)
1201 /* --------------------------------------------------------------------------
1202 External: Delete the window
1203 -------------------------------------------------------------------------- */
1205 NSTRACE
(x_destroy_window
);
1206 check_window_system
(f
);
1207 x_free_frame_resources
(f
);
1213 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1214 /* --------------------------------------------------------------------------
1215 External: Position the window
1216 -------------------------------------------------------------------------- */
1218 NSView
*view = FRAME_NS_VIEW
(f
);
1219 NSArray
*screens
= [NSScreen screens
];
1220 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1221 NSScreen
*screen
= [[view window
] screen
];
1223 NSTRACE
(x_set_offset
);
1230 if (view != nil
&& screen
&& fscreen
)
1232 f
->left_pos
= f
->size_hint_flags
& XNegative
1233 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1235 /* We use visibleFrame here to take menu bar into account.
1236 Ideally we should also adjust left/top with visibleFrame.origin. */
1238 f
->top_pos
= f
->size_hint_flags
& YNegative
1239 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1240 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1241 - FRAME_TOOLBAR_HEIGHT
(f
))
1243 #ifdef NS_IMPL_GNUSTEP
1244 if (f
->left_pos
< 100)
1245 f
->left_pos
= 100; /* don't overlap menu */
1247 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1249 [[view window
] setFrameTopLeftPoint
:
1250 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1251 SCREENMAXBOUND
([fscreen frame
].
size.height
1252 - NS_TOP_POS
(f
)))];
1253 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1261 x_set_window_size
(struct frame
*f
,
1266 /* --------------------------------------------------------------------------
1267 Adjust window pixel size based on given character grid size
1268 Impl is a bit more complex than other terms, need to do some
1270 -------------------------------------------------------------------------- */
1272 EmacsView
*view = FRAME_NS_VIEW
(f
);
1273 NSWindow
*window
= [view window
];
1274 NSRect wr
= [window frame
];
1275 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1276 int pixelwidth
, pixelheight
;
1279 NSTRACE
(x_set_window_size
);
1284 /*fprintf (stderr, "\tsetWindowSize: %d x %d, pixelwise %d, font size %d x %d\n", width, height, pixelwise, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f));*/
1288 check_frame_size
(f
, &width
, &height
, pixelwise
);
1290 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1291 compute_fringe_widths
(f
, 0);
1295 pixelwidth
= FRAME_TEXT_TO_PIXEL_WIDTH
(f
, width
);
1296 pixelheight
= FRAME_TEXT_TO_PIXEL_HEIGHT
(f
, height
);
1297 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(f
, pixelwidth
);
1298 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(f
, pixelheight
);
1302 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, width
);
1303 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, height
);
1308 /* If we have a toolbar, take its height into account. */
1309 if (tb
&& ! [view isFullscreen
])
1311 /* NOTE: previously this would generate wrong result if toolbar not
1312 yet displayed and fixing toolbar_height=32 helped, but
1313 now (200903) seems no longer needed */
1314 FRAME_TOOLBAR_HEIGHT
(f
) =
1315 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1316 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1317 #ifdef NS_IMPL_GNUSTEP
1318 FRAME_TOOLBAR_HEIGHT
(f
) -= 3;
1322 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1324 wr.
size.width
= pixelwidth
+ f
->border_width
;
1325 wr.
size.height
= pixelheight
;
1326 if (! [view isFullscreen
])
1327 wr.
size.height
+= FRAME_NS_TITLEBAR_HEIGHT
(f
)
1328 + FRAME_TOOLBAR_HEIGHT
(f
);
1330 /* Do not try to constrain to this screen. We may have multiple
1331 screens, and want Emacs to span those. Constraining to screen
1332 prevents that, and that is not nice to the user. */
1333 if (f
->output_data.ns
->zooming
)
1334 f
->output_data.ns
->zooming
= 0;
1336 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1338 [view setRows
: rows andColumns
: cols
];
1339 [window setFrame
: wr display
: YES
];
1341 /* This is a trick to compensate for Emacs' managing the scrollbar area
1342 as a fixed number of standard character columns. Instead of leaving
1343 blank space for the extra, we chopped it off above. Now for
1344 left-hand scrollbars, we shift all rendering to the left by the
1345 difference between the real width and Emacs' imagined one. For
1346 right-hand bars, don't worry about it since the extra is never used.
1347 (Obviously doesn't work for vertically split windows tho..) */
1349 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1350 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1351 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1352 : NSMakePoint
(0, 0);
1353 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1354 [view setBoundsOrigin
: origin
];
1357 change_frame_size
(f
, width
, height
, 0, 1, 0, pixelwise
);
1358 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1360 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1361 cancel_mouse_face
(f
);
1368 ns_fullscreen_hook
(struct frame
*f
)
1370 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(f
);
1372 if (!FRAME_VISIBLE_P
(f
))
1375 if (! [view fsIsNative
] && f
->want_fullscreen
== FULLSCREEN_BOTH
)
1377 /* Old style fs don't initiate correctly if created from
1378 init/default-frame alist, so use a timer (not nice...).
1380 [NSTimer scheduledTimerWithTimeInterval
: 0.5 target
: view
1381 selector
: @selector
(handleFS
)
1382 userInfo
: nil repeats
: NO
];
1391 /* ==========================================================================
1395 ========================================================================== */
1399 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1401 struct ns_color_table
*color_table
= FRAME_DISPLAY_INFO
(f
)->color_table
;
1402 if (idx
< 1 || idx
>= color_table
->avail
)
1404 return color_table
->colors
[idx
];
1409 ns_index_color
(NSColor
*color
, struct frame
*f
)
1411 struct ns_color_table
*color_table
= FRAME_DISPLAY_INFO
(f
)->color_table
;
1415 if (!color_table
->colors
)
1417 color_table
->size = NS_COLOR_CAPACITY
;
1418 color_table
->avail
= 1; /* skip idx=0 as marker */
1419 color_table
->colors
= xmalloc
(color_table
->size * sizeof
(NSColor
*));
1420 color_table
->colors
[0] = nil
;
1421 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1424 /* Do we already have this color? */
1425 for (i
= 1; i
< color_table
->avail
; i
++)
1426 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1429 if ([color_table
->empty_indices count
] > 0)
1431 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1432 [color_table
->empty_indices removeObject
: index
];
1433 idx
= [index unsignedLongValue
];
1437 if (color_table
->avail
== color_table
->size)
1438 color_table
->colors
=
1439 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1440 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1441 idx
= color_table
->avail
++;
1444 color_table
->colors
[idx
] = color
;
1446 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1452 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1454 struct ns_color_table
*color_table
;
1461 color_table
= FRAME_DISPLAY_INFO
(f
)->color_table
;
1463 if (idx
<= 0 || idx
>= color_table
->size) {
1464 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1468 index
= [NSNumber numberWithUnsignedInt
: idx
];
1469 if ([color_table
->empty_indices containsObject
: index
]) {
1470 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1474 color
= color_table
->colors
[idx
];
1476 color_table
->colors
[idx
] = nil
;
1477 [color_table
->empty_indices addObject
: index
];
1478 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1483 ns_get_color
(const
char *name
, NSColor
**col
)
1484 /* --------------------------------------------------------------------------
1486 -------------------------------------------------------------------------- */
1487 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1488 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1489 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1492 static
char hex
[20];
1494 float r
= -1.0, g
, b
;
1495 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1497 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1500 if ([nsname isEqualToString
: @"ns_selection_bg_color"
])
1502 #ifdef NS_IMPL_COCOA
1503 NSString
*defname
= [[NSUserDefaults standardUserDefaults
]
1504 stringForKey
: @"AppleHighlightColor"
];
1509 if ((new
= [NSColor selectedTextBackgroundColor
]) != nil
)
1511 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1516 nsname
= NS_SELECTION_BG_COLOR_DEFAULT
;
1518 name
= [nsname UTF8String
];
1520 else if ([nsname isEqualToString
: @"ns_selection_fg_color"
])
1522 /* NOTE: OSX applications normally don't set foreground selection, but
1523 text may be unreadable if we don't.
1525 if ((new
= [NSColor selectedTextColor
]) != nil
)
1527 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1532 nsname
= NS_SELECTION_FG_COLOR_DEFAULT
;
1533 name
= [nsname UTF8String
];
1536 /* First, check for some sort of numeric specification. */
1539 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1541 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1542 [scanner scanFloat
: &r
];
1543 [scanner scanFloat
: &g
];
1544 [scanner scanFloat
: &b
];
1546 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1547 scaling
= (snprintf
(hex
, sizeof hex
, "
%s", name + 4) - 2) / 3;
1548 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1550 int len
= (strlen
(name
) - 1);
1551 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1553 scaling
= strlen
(name
+start
) / 3;
1554 for (i
= 0; i
< 3; i
++)
1555 sprintf (hex
+ i
* (scaling
+ 1), "
%.*s/", scaling,
1556 name
+ start
+ i
* scaling
);
1557 hex
[3 * (scaling
+ 1) - 1] = '\0';
1563 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1564 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1574 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1579 /* Otherwise, color is expected to be from a list */
1581 NSEnumerator
*lenum
, *cenum
;
1585 #ifdef NS_IMPL_GNUSTEP
1586 /* XXX: who is wrong, the requestor or the implementation? */
1587 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1589 nsname
= @"highlightColor"
;
1592 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1593 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1595 cenum
= [[clist allKeys
] objectEnumerator
];
1596 while ( (name
= [cenum nextObject
]) && new
== nil
)
1598 if ([name compare
: nsname
1599 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1600 new
= [clist colorWithKey
: name
];
1606 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1613 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1614 /* --------------------------------------------------------------------------
1615 Convert a Lisp string object to a NS color
1616 -------------------------------------------------------------------------- */
1618 NSTRACE
(ns_lisp_to_color
);
1619 if (STRINGP
(color
))
1620 return ns_get_color
(SSDATA
(color
), col
);
1621 else if (SYMBOLP
(color
))
1622 return ns_get_color
(SSDATA
(SYMBOL_NAME
(color
)), col
);
1628 ns_color_to_lisp
(NSColor
*col
)
1629 /* --------------------------------------------------------------------------
1630 Convert a color to a lisp string with the RGB equivalent
1631 -------------------------------------------------------------------------- */
1633 EmacsCGFloat red
, green
, blue
, alpha
, gray;
1636 NSTRACE
(ns_color_to_lisp
);
1639 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1641 if ((str
=[[col colorNameComponent
] UTF8String
]))
1644 return build_string
((char *)str
);
1647 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1648 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1649 if (red
==green
&& red
==blue
)
1651 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1652 getWhite
: &gray alpha
: &alpha
];
1653 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1654 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1656 return build_string
(buf
);
1659 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1660 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1663 return build_string
(buf
);
1668 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1669 /* --------------------------------------------------------------------------
1670 Get ARGB values out of NSColor col and put them into color_def.
1671 If setPixel, set the pixel to a concatenated version.
1672 and set color_def pixel to the resulting index.
1673 -------------------------------------------------------------------------- */
1675 EmacsCGFloat r
, g
, b
, a
;
1677 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1678 color_def
->red
= r
* 65535;
1679 color_def
->green
= g
* 65535;
1680 color_def
->blue
= b
* 65535;
1682 if (setPixel
== YES
)
1684 = ARGB_TO_ULONG
((int
)(a
*255),
1685 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1690 ns_defined_color
(struct frame
*f
,
1695 /* --------------------------------------------------------------------------
1696 Return true if named color found, and set color_def rgb accordingly.
1697 If makeIndex and alloc are nonzero put the color in the color_table,
1698 and set color_def pixel to the resulting index.
1699 If makeIndex is zero, set color_def pixel to ARGB.
1700 Return false if not found
1701 -------------------------------------------------------------------------- */
1704 NSTRACE
(ns_defined_color
);
1707 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1712 if (makeIndex
&& alloc
)
1713 color_def
->pixel
= ns_index_color
(col
, f
);
1714 ns_query_color
(col
, color_def
, !makeIndex
);
1721 x_set_frame_alpha
(struct frame
*f
)
1722 /* --------------------------------------------------------------------------
1723 change the entire-frame transparency
1724 -------------------------------------------------------------------------- */
1726 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(f
);
1728 double alpha_min
= 1.0;
1730 if (dpyinfo
->x_highlight_frame
== f
)
1731 alpha
= f
->alpha
[0];
1733 alpha
= f
->alpha
[1];
1735 if (FLOATP
(Vframe_alpha_lower_limit
))
1736 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1737 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1738 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1742 else if (1.0 < alpha
)
1744 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1747 #ifdef NS_IMPL_COCOA
1749 EmacsView
*view = FRAME_NS_VIEW
(f
);
1750 [[view window
] setAlphaValue
: alpha
];
1756 /* ==========================================================================
1760 ========================================================================== */
1764 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1765 /* --------------------------------------------------------------------------
1766 Programmatically reposition mouse pointer in pixel coordinates
1767 -------------------------------------------------------------------------- */
1769 NSTRACE
(x_set_mouse_pixel_position
);
1772 /* FIXME: this does not work, and what about GNUstep? */
1773 #ifdef NS_IMPL_COCOA
1774 [FRAME_NS_VIEW
(f
) lockFocus
];
1775 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1776 [FRAME_NS_VIEW
(f
) unlockFocus
];
1783 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1784 /* --------------------------------------------------------------------------
1785 Programmatically reposition mouse pointer in character coordinates
1786 -------------------------------------------------------------------------- */
1790 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1791 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1793 if (pix_x
< 0) pix_x
= 0;
1794 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1796 if (pix_y
< 0) pix_y
= 0;
1797 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1799 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1804 note_mouse_movement
(struct frame
*frame
, CGFloat x
, CGFloat y
)
1805 /* ------------------------------------------------------------------------
1806 Called by EmacsView on mouseMovement events. Passes on
1807 to emacs mainstream code if we moved off of a rect of interest
1808 known as last_mouse_glyph.
1809 ------------------------------------------------------------------------ */
1811 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(frame
);
1814 // NSTRACE
(note_mouse_movement
);
1816 dpyinfo
->last_mouse_motion_frame
= frame
;
1817 r
= &dpyinfo
->last_mouse_glyph
;
1819 /* Note, this doesn't get called for enter/leave, since we don't have a
1820 position. Those are taken care of in the corresponding NSView methods. */
1822 /* has movement gone beyond last rect we were tracking? */
1823 if (x
< r
->origin.x || x
>= r
->origin.x
+ r
->size.width
1824 || y
< r
->origin.y || y
>= r
->origin.y
+ r
->size.height
)
1826 ns_update_begin
(frame
);
1827 frame
->mouse_moved
= 1;
1828 note_mouse_highlight
(frame
, x
, y
);
1829 remember_mouse_glyph
(frame
, x
, y
, r
);
1830 ns_update_end
(frame
);
1839 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1840 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1842 /* --------------------------------------------------------------------------
1843 External (hook): inform emacs about mouse position and hit parts.
1844 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1845 x & y should be position in the scrollbar (the whole bar, not the handle)
1846 and length of scrollbar respectively
1847 -------------------------------------------------------------------------- */
1851 Lisp_Object frame
, tail
;
1853 struct ns_display_info
*dpyinfo
;
1855 NSTRACE
(ns_mouse_position
);
1859 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1863 dpyinfo
= FRAME_DISPLAY_INFO
(*fp
);
1867 if (dpyinfo
->last_mouse_scroll_bar
!= nil
&& insist
== 0)
1869 /* TODO: we do not use this path at the moment because drag events will
1870 go directly to the EmacsScroller. Leaving code in for now. */
1871 [dpyinfo
->last_mouse_scroll_bar
1872 getMouseMotionPart
: (int
*)part window
: bar_window x
: x y
: y
];
1874 *time
= dpyinfo
->last_mouse_movement_time
;
1875 dpyinfo
->last_mouse_scroll_bar
= nil
;
1879 /* Clear the mouse-moved flag for every frame on this display. */
1880 FOR_EACH_FRAME
(tail
, frame
)
1881 if (FRAME_NS_P
(XFRAME
(frame
))
1882 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1883 XFRAME
(frame
)->mouse_moved
= 0;
1885 dpyinfo
->last_mouse_scroll_bar
= nil
;
1886 if (dpyinfo
->last_mouse_frame
1887 && FRAME_LIVE_P
(dpyinfo
->last_mouse_frame
))
1888 f
= dpyinfo
->last_mouse_frame
;
1890 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1891 : SELECTED_FRAME
();
1893 if (f
&& FRAME_NS_P
(f
))
1895 view = FRAME_NS_VIEW
(*fp
);
1897 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1898 position
= [view convertPoint
: position fromView
: nil
];
1899 remember_mouse_glyph
(f
, position.x
, position.y
,
1900 &dpyinfo
->last_mouse_glyph
);
1901 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1903 if (bar_window
) *bar_window
= Qnil
;
1904 if (part
) *part
= 0; /*scroll_bar_handle; */
1906 if (x
) XSETINT
(*x
, lrint
(position.x
));
1907 if (y
) XSETINT
(*y
, lrint
(position.y
));
1909 *time
= dpyinfo
->last_mouse_movement_time
;
1919 ns_frame_up_to_date
(struct frame
*f
)
1920 /* --------------------------------------------------------------------------
1921 External (hook): Fix up mouse highlighting right after a full update.
1922 Can't use FRAME_MOUSE_UPDATE due to ns_frame_begin and ns_frame_end calls.
1923 -------------------------------------------------------------------------- */
1925 NSTRACE
(ns_frame_up_to_date
);
1929 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1930 if (f
== hlinfo
->mouse_face_mouse_frame
)
1934 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1935 hlinfo
->mouse_face_mouse_x
,
1936 hlinfo
->mouse_face_mouse_y
);
1945 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1946 /* --------------------------------------------------------------------------
1947 External (RIF): set frame mouse pointer type.
1948 -------------------------------------------------------------------------- */
1950 NSTRACE
(ns_define_frame_cursor
);
1951 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1953 EmacsView
*view = FRAME_NS_VIEW
(f
);
1954 FRAME_POINTER_TYPE
(f
) = cursor
;
1955 [[view window
] invalidateCursorRectsForView
: view];
1956 /* Redisplay assumes this function also draws the changed frame
1957 cursor, but this function doesn't, so do it explicitly. */
1958 x_update_cursor
(f
, 1);
1964 /* ==========================================================================
1968 ========================================================================== */
1972 ns_convert_key
(unsigned code
)
1973 /* --------------------------------------------------------------------------
1974 Internal call used by NSView-keyDown.
1975 -------------------------------------------------------------------------- */
1977 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1978 / sizeof
(convert_ns_to_X_keysym
[0]));
1980 /* An array would be faster, but less easy to read. */
1981 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1982 if (code
== convert_ns_to_X_keysym
[keysym
])
1983 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1985 /* if decide to use keyCode and Carbon table, use this line:
1986 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1991 x_get_keysym_name
(int keysym
)
1992 /* --------------------------------------------------------------------------
1993 Called by keyboard.c. Not sure if the return val is important, except
1995 -------------------------------------------------------------------------- */
1997 static
char value
[16];
1998 NSTRACE
(x_get_keysym_name
);
1999 sprintf (value
, "
%d", keysym);
2005 /* ==========================================================================
2007 Block drawing operations
2009 ========================================================================== */
2013 ns_redraw_scroll_bars
(struct frame
*f
)
2017 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
2018 NSTRACE
(ns_redraw_scroll_bars
);
2019 for (i
=[subviews count
]-1; i
>= 0; i
--)
2021 view = [subviews objectAtIndex
: i
];
2022 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
2029 ns_clear_frame
(struct frame
*f
)
2030 /* --------------------------------------------------------------------------
2031 External (hook): Erase the entire frame
2032 -------------------------------------------------------------------------- */
2034 NSView
*view = FRAME_NS_VIEW
(f
);
2037 NSTRACE
(ns_clear_frame
);
2039 /* comes on initial frame because we have
2040 after-make-frame-functions = select-frame */
2041 if (!FRAME_DEFAULT_FACE
(f
))
2044 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
2049 ns_focus
(f
, &r
, 1);
2050 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
2054 /* as of 2006/11 or so this is now needed */
2055 ns_redraw_scroll_bars
(f
);
2061 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
2062 /* --------------------------------------------------------------------------
2063 External (RIF): Clear section of frame
2064 -------------------------------------------------------------------------- */
2066 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
2067 NSView
*view = FRAME_NS_VIEW
(f
);
2068 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
2073 NSTRACE
(ns_clear_frame_area
);
2075 r
= NSIntersectionRect
(r
, [view frame
]);
2076 ns_focus
(f
, &r
, 1);
2077 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
2087 ns_scroll_run
(struct window
*w
, struct run
*run
)
2088 /* --------------------------------------------------------------------------
2089 External (RIF): Insert or delete n lines at line vpos
2090 -------------------------------------------------------------------------- */
2092 struct frame
*f
= XFRAME
(w
->frame
);
2093 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2095 NSTRACE
(ns_scroll_run
);
2097 /* begin copy from other terms */
2098 /* Get frame-relative bounding box of the text display area of W,
2099 without mode lines. Include in this box the left and right
2101 window_box
(w
, ANY_AREA
, &x
, &y
, &width
, &height
);
2103 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2104 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2105 bottom_y
= y
+ height
;
2109 /* Scrolling up. Make sure we don't copy part of the mode
2110 line at the bottom. */
2111 if (from_y
+ run
->height
> bottom_y
)
2112 height
= bottom_y
- from_y
;
2114 height
= run
->height
;
2118 /* Scrolling down. Make sure we don't copy over the mode line.
2120 if (to_y
+ run
->height
> bottom_y
)
2121 height
= bottom_y
- to_y
;
2123 height
= run
->height
;
2125 /* end copy from other terms */
2135 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2136 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2137 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2139 ns_focus
(f
, &dstRect
, 1);
2140 NSCopyBits
(0, srcRect
, dstOrigin
);
2149 ns_after_update_window_line
(struct window
*w
, struct glyph_row
*desired_row
)
2150 /* --------------------------------------------------------------------------
2151 External (RIF): preparatory to fringe update after text was updated
2152 -------------------------------------------------------------------------- */
2157 NSTRACE
(ns_after_update_window_line
);
2159 /* begin copy from other terms */
2162 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2163 desired_row
->redraw_fringe_bitmaps_p
= 1;
2165 /* When a window has disappeared, make sure that no rest of
2166 full-width rows stays visible in the internal border. */
2167 if (windows_or_buffers_changed
2168 && desired_row
->full_width_p
2169 && (f
= XFRAME
(w
->frame
),
2170 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2172 && (height
= desired_row
->visible_height
,
2175 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2178 ns_clear_frame_area
(f
, 0, y
, width
, height
);
2179 ns_clear_frame_area
(f
,
2180 FRAME_PIXEL_WIDTH
(f
) - width
,
2188 ns_shift_glyphs_for_insert
(struct frame
*f
,
2189 int x
, int y
, int width
, int height
,
2191 /* --------------------------------------------------------------------------
2192 External (RIF): copy an area horizontally, don't worry about clearing src
2193 -------------------------------------------------------------------------- */
2195 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2196 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2197 NSPoint dstOrigin
= dstRect.origin
;
2199 NSTRACE
(ns_shift_glyphs_for_insert
);
2201 ns_focus
(f
, &dstRect
, 1);
2202 NSCopyBits
(0, srcRect
, dstOrigin
);
2208 /* ==========================================================================
2210 Character encoding and metrics
2212 ========================================================================== */
2216 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2217 /* --------------------------------------------------------------------------
2218 External (RIF); compute left/right overhang of whole string and set in s
2219 -------------------------------------------------------------------------- */
2221 struct font
*font
= s
->font
;
2225 struct font_metrics metrics
;
2226 unsigned int codes
[2];
2227 codes
[0] = *(s
->char2b
);
2228 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2230 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2231 s
->left_overhang
= -metrics.lbearing
;
2233 = metrics.rbearing
> metrics.width
2234 ? metrics.rbearing
- metrics.width
: 0;
2238 s
->left_overhang
= 0;
2239 if (EQ
(font
->driver
->type, Qns
))
2240 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2241 FONT_HEIGHT
(font
) * 0.2 : 0;
2243 s
->right_overhang
= 0;
2249 /* ==========================================================================
2251 Fringe and cursor drawing
2253 ========================================================================== */
2256 extern int max_used_fringe_bitmap
;
2258 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2259 struct draw_fringe_bitmap_params
*p
)
2260 /* --------------------------------------------------------------------------
2261 External (RIF); fringe-related
2262 -------------------------------------------------------------------------- */
2264 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2265 struct face
*face
= p
->face
;
2266 static EmacsImage
**bimgs
= NULL;
2267 static int nBimgs
= 0;
2269 /* grow bimgs if needed */
2270 if (nBimgs
< max_used_fringe_bitmap
)
2272 bimgs
= xrealloc
(bimgs
, max_used_fringe_bitmap
* sizeof
*bimgs
);
2273 memset
(bimgs
+ nBimgs
, 0,
2274 (max_used_fringe_bitmap
- nBimgs
) * sizeof
*bimgs
);
2275 nBimgs
= max_used_fringe_bitmap
;
2278 /* Must clip because of partially visible lines. */
2279 ns_clip_to_row
(w
, row
, ANY_AREA
, YES
);
2283 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
2285 /* If the fringe is adjacent to the left (right) scroll bar of a
2286 leftmost (rightmost, respectively) window, then extend its
2287 background to the gap between the fringe and the bar. */
2288 if ((WINDOW_LEFTMOST_P
(w
)
2289 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(w
))
2290 ||
(WINDOW_RIGHTMOST_P
(w
)
2291 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT
(w
)))
2293 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH
(w
);
2297 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X
(w
);
2298 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS
(w
)
2299 * FRAME_COLUMN_WIDTH
(f
));
2303 /* Bitmap fills the fringe. */
2304 if (bar_area_x
+ bar_area_width
== p
->x
)
2305 bx
= bar_area_x
+ sb_width
;
2306 else if (p
->x
+ p
->wd
== bar_area_x
)
2310 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT
(w
);
2312 nx
= bar_area_width
- sb_width
;
2313 by
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (header_line_height
,
2315 ny
= row
->visible_height
;
2320 if (bar_area_x
+ bar_area_width
== bx
)
2322 bx
= bar_area_x
+ sb_width
;
2323 nx
+= bar_area_width
- sb_width
;
2325 else if (bx
+ nx
== bar_area_x
)
2326 nx
+= bar_area_width
- sb_width
;
2331 if (bx
>= 0 && nx
> 0)
2333 NSRect r
= NSMakeRect
(bx
, by
, nx
, ny
);
2335 [ns_lookup_indexed_color
(face
->background
, f
) set];
2342 NSRect r
= NSMakeRect
(p
->x
, p
->y
, p
->wd
, p
->h
);
2343 EmacsImage
*img
= bimgs
[p
->which - 1];
2347 unsigned short
*bits
= p
->bits
+ p
->dh
;
2350 unsigned
char *cbits
= xmalloc
(len
);
2352 for (i
= 0; i
< len
; i
++)
2353 cbits
[i
] = ~
(bits
[i
] & 0xff);
2354 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2356 bimgs
[p
->which - 1] = img
;
2361 /* Since we composite the bitmap instead of just blitting it, we need
2362 to erase the whole background. */
2363 [ns_lookup_indexed_color
(face
->background
, f
) set];
2365 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2366 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
2368 fromRect
: NSZeroRect
2369 operation
: NSCompositeSourceOver
2375 NSPoint pt
= r.origin
;
2377 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2386 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2387 int x
, int y
, enum text_cursor_kinds cursor_type
,
2388 int cursor_width
, bool on_p
, bool active_p
)
2389 /* --------------------------------------------------------------------------
2390 External call (RIF): draw cursor.
2391 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2392 -------------------------------------------------------------------------- */
2395 int fx
, fy
, h
, cursor_height
;
2396 struct frame
*f
= WINDOW_XFRAME
(w
);
2397 struct glyph
*phys_cursor_glyph
;
2398 struct glyph
*cursor_glyph
;
2400 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2402 /* If cursor is out of bounds, don't draw garbage. This can happen
2403 in mini-buffer windows when switching between echo area glyphs
2406 NSTRACE
(dumpcursor
);
2411 w
->phys_cursor_type
= cursor_type
;
2412 w
->phys_cursor_on_p
= on_p
;
2414 if (cursor_type
== NO_CURSOR
)
2416 w
->phys_cursor_width
= 0;
2420 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2422 if (glyph_row
->exact_window_width_line_p
2423 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2425 glyph_row
->cursor_in_fringe_p
= 1;
2426 draw_fringe_bitmap
(w
, glyph_row
, 0);
2431 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2432 (other terminals do it the other way round). We must set
2433 w->phys_cursor_width to the cursor width. For bar cursors, that
2434 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2435 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2437 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2438 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2439 if (cursor_type
== BAR_CURSOR
)
2441 if (cursor_width
< 1)
2442 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2443 w
->phys_cursor_width
= cursor_width
;
2445 /* If we have an HBAR, "cursor_width" MAY specify height. */
2446 else if (cursor_type
== HBAR_CURSOR
)
2448 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2449 fy
+= h
- cursor_height
;
2453 r.origin.x
= fx
, r.origin.y
= fy
;
2455 r.
size.width
= w
->phys_cursor_width
;
2457 /* TODO: only needed in rare cases with last-resort font in HELLO..
2458 should we do this more efficiently? */
2459 ns_clip_to_row
(w
, glyph_row
, ANY_AREA
, NO
); /* do ns_focus(f, &r, 1); if remove */
2462 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2463 if (face
&& NS_FACE_BACKGROUND
(face
)
2464 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2466 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2467 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2470 [FRAME_CURSOR_COLOR
(f
) set];
2472 #ifdef NS_IMPL_COCOA
2473 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2474 atomic. Cleaner ways of doing this should be investigated.
2475 One way would be to set a global variable DRAWING_CURSOR
2476 when making the call to draw_phys..(), don't focus in that
2477 case, then move the ns_unfocus() here after that call. */
2478 NSDisableScreenUpdates
();
2481 switch (cursor_type
)
2485 case FILLED_BOX_CURSOR
:
2488 case HOLLOW_BOX_CURSOR
:
2491 NSRectFill
(NSInsetRect
(r
, 1, 1));
2492 [FRAME_CURSOR_COLOR
(f
) set];
2499 /* If the character under cursor is R2L, draw the bar cursor
2500 on the right of its glyph, rather than on the left. */
2501 cursor_glyph
= get_phys_cursor_glyph
(w
);
2502 if ((cursor_glyph
->resolved_level
& 1) != 0)
2503 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2510 /* draw the character under the cursor */
2511 if (cursor_type
!= NO_CURSOR
)
2512 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2514 #ifdef NS_IMPL_COCOA
2515 NSEnableScreenUpdates
();
2522 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2523 /* --------------------------------------------------------------------------
2524 External (RIF): Draw a vertical line.
2525 -------------------------------------------------------------------------- */
2527 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2529 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2531 NSTRACE
(ns_draw_vertical_window_border
);
2533 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2535 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2537 ns_focus
(f
, &r
, 1);
2544 ns_draw_window_divider
(struct window
*w
, int x0
, int x1
, int y0
, int y1
)
2545 /* --------------------------------------------------------------------------
2546 External (RIF): Draw a window divider.
2547 -------------------------------------------------------------------------- */
2549 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2551 NSRect r
= NSMakeRect
(x0
, y0
, x1
-x0
, y1
-y0
);
2553 NSTRACE
(ns_draw_window_divider
);
2555 face
= FACE_FROM_ID
(f
, WINDOW_DIVIDER_FACE_ID
);
2557 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2559 ns_focus
(f
, &r
, 1);
2566 show_hourglass
(struct atimer
*timer
)
2568 if (hourglass_shown_p
)
2573 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2575 hourglass_shown_p
= 1;
2581 hide_hourglass
(void
)
2583 if (!hourglass_shown_p
)
2588 /* TODO: remove NSProgressIndicator from all frames */
2590 hourglass_shown_p
= 0;
2596 /* ==========================================================================
2598 Glyph drawing operations
2600 ========================================================================== */
2603 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2604 /* --------------------------------------------------------------------------
2605 Wrapper utility to account for internal border width on full-width lines,
2606 and allow top full-width rows to hit the frame top. nr should be pointer
2607 to two successive NSRects. Number of rects actually used is returned.
2608 -------------------------------------------------------------------------- */
2610 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2614 /* --------------------------------------------------------------------
2615 Draw a wavy line under glyph string s. The wave fills wave_height
2622 wave_height = 3 | * * * *
2623 --------------------------------------------------------------------- */
2626 ns_draw_underwave
(struct glyph_string
*s
, EmacsCGFloat width
, EmacsCGFloat x
)
2628 int wave_height
= 3, wave_length
= 2;
2629 int y
, dx
, dy
, odd
, xmax
;
2634 dy
= wave_height
- 1;
2635 y
= s
->ybase
- wave_height
+ 3;
2638 /* Find and set clipping rectangle */
2639 waveClip
= NSMakeRect
(x
, y
, width
, wave_height
);
2640 [[NSGraphicsContext currentContext
] saveGraphicsState
];
2641 NSRectClip
(waveClip
);
2643 /* Draw the waves */
2644 a.x
= x
- ((int
)(x
) % dx) + (EmacsCGFloat) 0.5;
2646 odd
= (int
)(a.x
/dx
) % 2;
2647 a.y
= b.y
= y
+ 0.5;
2656 [NSBezierPath strokeLineFromPoint
:a toPoint
:b
];
2657 a.x
= b.x
, a.y
= b.y
;
2658 b.x
+= dx
, b.y
= y
+ 0.5 + odd
*dy
;
2662 /* Restore previous clipping rectangle(s) */
2663 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
2669 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2670 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2671 /* --------------------------------------------------------------------------
2672 Draw underline, overline, and strike-through on glyph string s.
2673 -------------------------------------------------------------------------- */
2675 if (s
->for_overlaps
)
2679 if (face
->underline_p
)
2681 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2683 if (face
->underline_defaulted_p
)
2686 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2688 ns_draw_underwave
(s
, width
, x
);
2690 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2694 unsigned
long thickness
, position
;
2696 /* If the prev was underlined, match its appearance. */
2697 if (s
->prev
&& s
->prev
->face
->underline_p
2698 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
2699 && s
->prev
->underline_thickness
> 0)
2701 thickness
= s
->prev
->underline_thickness
;
2702 position
= s
->prev
->underline_position
;
2707 unsigned
long descent
;
2710 descent
= s
->y
+ s
->height
- s
->ybase
;
2712 /* Use underline thickness of font, defaulting to 1. */
2713 thickness
= (font
&& font
->underline_thickness
> 0)
2714 ? font
->underline_thickness
: 1;
2716 /* Determine the offset of underlining from the baseline. */
2717 if (x_underline_at_descent_line
)
2718 position
= descent
- thickness
;
2719 else if (x_use_underline_position_properties
2720 && font
&& font
->underline_position
>= 0)
2721 position
= font
->underline_position
;
2723 position
= lround
(font
->descent
/ 2);
2725 position
= underline_minimum_offset
;
2727 position
= max (position
, underline_minimum_offset
);
2729 /* Ensure underlining is not cropped. */
2730 if (descent
<= position
)
2732 position
= descent
- 1;
2735 else if (descent
< position
+ thickness
)
2739 s
->underline_thickness
= thickness
;
2740 s
->underline_position
= position
;
2742 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2744 if (face
->underline_defaulted_p
)
2747 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2751 /* Do overline. We follow other terms in using a thickness of 1
2752 and ignoring overline_margin. */
2753 if (face
->overline_p
)
2756 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2758 if (face
->overline_color_defaulted_p
)
2761 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2765 /* Do strike-through. We follow other terms for thickness and
2766 vertical position.*/
2767 if (face
->strike_through_p
)
2772 dy
= lrint
((s
->height
- 1) / 2);
2773 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2775 if (face
->strike_through_color_defaulted_p
)
2778 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2784 ns_draw_box
(NSRect r
, CGFloat thickness
, NSColor
*col
,
2785 char left_p
, char right_p
)
2786 /* --------------------------------------------------------------------------
2787 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2788 Note we can't just use an NSDrawRect command, because of the possibility
2789 of some sides not being drawn, and because the rect will be filled.
2790 -------------------------------------------------------------------------- */
2796 s.
size.height
= thickness
;
2798 s.origin.y
+= r.
size.height
- thickness
;
2801 s.
size.height
= r.
size.height
;
2802 s.origin.y
= r.origin.y
;
2804 /* left, right (optional) */
2805 s.
size.width
= thickness
;
2810 s.origin.x
+= r.
size.width
- thickness
;
2817 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2818 char top_p
, char bottom_p
, char left_p
, char right_p
,
2819 struct glyph_string
*s
)
2820 /* --------------------------------------------------------------------------
2821 Draw a relief rect inside r, optionally leaving some sides open.
2822 Note we can't just use an NSDrawBezel command, because of the possibility
2823 of some sides not being drawn, and because the rect will be filled.
2824 -------------------------------------------------------------------------- */
2826 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2827 NSColor
*newBaseCol
= nil
;
2830 NSTRACE
(ns_draw_relief
);
2834 if (s
->face
->use_box_color_for_shadows_p
)
2836 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2838 /* else if (s->first_glyph->type == IMAGE_GLYPH
2840 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2842 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2846 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2849 if (newBaseCol
== nil
)
2850 newBaseCol
= [NSColor grayColor
];
2852 if (newBaseCol
!= baseCol
) /* TODO: better check */
2855 baseCol
= [newBaseCol retain
];
2857 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2859 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2862 [(raised_p ? lightCol
: darkCol
) set];
2864 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2867 sr.
size.height
= thickness
;
2868 if (top_p
) NSRectFill
(sr
);
2871 sr.
size.height
= r.
size.height
;
2872 sr.
size.width
= thickness
;
2873 if (left_p
) NSRectFill
(sr
);
2875 [(raised_p ? darkCol
: lightCol
) set];
2878 sr.
size.width
= r.
size.width
;
2879 sr.
size.height
= thickness
;
2880 sr.origin.y
+= r.
size.height
- thickness
;
2881 if (bottom_p
) NSRectFill
(sr
);
2884 sr.
size.height
= r.
size.height
;
2885 sr.origin.y
= r.origin.y
;
2886 sr.
size.width
= thickness
;
2887 sr.origin.x
+= r.
size.width
- thickness
;
2888 if (right_p
) NSRectFill
(sr
);
2893 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2894 /* --------------------------------------------------------------------------
2895 Function modeled after x_draw_glyph_string_box ().
2896 Sets up parameters for drawing.
2897 -------------------------------------------------------------------------- */
2899 int right_x
, last_x
;
2900 char left_p
, right_p
;
2901 struct glyph
*last_glyph
;
2906 if (s
->hl
== DRAW_MOUSE_FACE
)
2908 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2910 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2915 thickness
= face
->box_line_width
;
2917 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2919 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2920 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2921 : window_box_right
(s
->w
, s
->area
));
2922 last_glyph
= (s
->cmp || s
->img
2923 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2925 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2926 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2928 left_p
= (s
->first_glyph
->left_box_line_p
2929 ||
(s
->hl
== DRAW_MOUSE_FACE
2930 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2931 right_p
= (last_glyph
->right_box_line_p
2932 ||
(s
->hl
== DRAW_MOUSE_FACE
2933 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2935 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2937 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2938 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2940 ns_draw_box
(r
, abs (thickness
),
2941 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2946 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2947 1, 1, left_p
, right_p
, s
);
2953 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2954 /* --------------------------------------------------------------------------
2955 Modeled after x_draw_glyph_string_background, which draws BG in
2956 certain cases. Others are left to the text rendering routine.
2957 -------------------------------------------------------------------------- */
2959 NSTRACE
(ns_maybe_dumpglyphs_background
);
2961 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2963 int box_line_width
= max (s
->face
->box_line_width
, 0);
2964 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2965 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2968 if (s
->hl
== DRAW_MOUSE_FACE
)
2970 face
= FACE_FROM_ID
(s
->f
,
2971 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2973 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2976 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2978 [(NS_FACE_BACKGROUND
(face
) != 0
2979 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2980 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2983 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(s
->f
);
2984 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2987 if (s
->hl
!= DRAW_CURSOR
)
2989 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2990 s
->background_width
,
2991 s
->height
-2*box_line_width
);
2995 s
->background_filled_p
= 1;
3002 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
3003 /* --------------------------------------------------------------------------
3004 Renders an image and associated borders.
3005 -------------------------------------------------------------------------- */
3007 EmacsImage
*img
= s
->img
->pixmap
;
3008 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
3009 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
3010 int bg_x
, bg_y
, bg_height
;
3017 NSTRACE
(ns_dumpglyphs_image
);
3019 if (s
->face
->box
!= FACE_NO_BOX
3020 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
3021 x
+= abs (s
->face
->box_line_width
);
3024 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
3025 bg_height
= s
->height
;
3026 /* other terms have this, but was causing problems w/tabbar mode */
3027 /* - 2 * box_line_vwidth; */
3029 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
3030 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
3032 /* Draw BG: if we need larger area than image itself cleared, do that,
3033 otherwise, since we composite the image under NS (instead of mucking
3034 with its background color), we must clear just the image area. */
3035 if (s
->hl
== DRAW_MOUSE_FACE
)
3037 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3039 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3042 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3044 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
3046 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
3047 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
3049 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
3050 s
->background_filled_p
= 1;
3054 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3059 /* Draw the image.. do we need to draw placeholder if img ==nil? */
3062 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
3063 NSRect dr
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3064 NSRect ir
= NSMakeRect
(s
->slice.x
, s
->slice.y
,
3065 s
->slice.width
, s
->slice.height
);
3068 operation
: NSCompositeSourceOver
3073 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
3074 operation
: NSCompositeSourceOver
];
3078 if (s
->hl
== DRAW_CURSOR
)
3080 [FRAME_CURSOR_COLOR
(s
->f
) set];
3081 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3082 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3084 /* Currently on NS img->mask is always 0. Since
3085 get_window_cursor_type specifies a hollow box cursor when on
3086 a non-masked image we never reach this clause. But we put it
3087 in in anticipation of better support for image masks on
3089 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3093 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3096 /* Draw underline, overline, strike-through. */
3097 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3099 /* Draw relief, if requested */
3100 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3102 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3104 th
= tool_bar_button_relief
>= 0 ?
3105 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3106 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3110 th
= abs (s
->img
->relief
);
3111 raised_p
= (s
->img
->relief
> 0);
3114 r.origin.x
= x
- th
;
3115 r.origin.y
= y
- th
;
3116 r.
size.width
= s
->slice.width
+ 2*th
-1;
3117 r.
size.height
= s
->slice.height
+ 2*th
-1;
3118 ns_draw_relief
(r
, th
, raised_p
,
3120 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3122 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3125 /* If there is no mask, the background won't be seen,
3126 so draw a rectangle on the image for the cursor.
3127 Do this for all images, getting transparency right is not reliable. */
3128 if (s
->hl
== DRAW_CURSOR
)
3130 int thickness
= abs (s
->img
->relief
);
3131 if (thickness
== 0) thickness
= 1;
3132 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3138 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3143 NSColor
*fgCol
, *bgCol
;
3145 if (!s
->background_filled_p
)
3147 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3148 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3150 ns_focus
(s
->f
, r
, n
);
3152 if (s
->hl
== DRAW_MOUSE_FACE
)
3154 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3156 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3159 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3161 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3162 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3164 for (i
= 0; i
< n
; ++i
)
3166 if (!s
->row
->full_width_p
)
3168 int overrun
, leftoverrun
;
3170 /* truncate to avoid overwriting fringe and/or scrollbar */
3171 overrun
= max (0, (s
->x
+ s
->background_width
)
3172 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3173 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3174 r
[i
].
size.width
-= overrun
;
3176 /* truncate to avoid overwriting to left of the window box */
3177 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3178 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3180 if (leftoverrun
> 0)
3182 r
[i
].origin.x
+= leftoverrun
;
3183 r
[i
].
size.width
-= leftoverrun
;
3186 /* XXX: Try to work between problem where a stretch glyph on
3187 a partially-visible bottom row will clear part of the
3188 modeline, and another where list-buffers headers and similar
3189 rows erroneously have visible_height set to 0. Not sure
3190 where this is coming from as other terms seem not to show. */
3191 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3196 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3197 overwriting cursor (usually when cursor on a tab) */
3198 if (s
->hl
== DRAW_CURSOR
)
3203 width
= s
->w
->phys_cursor_width
;
3204 r
[i
].
size.width
-= width
;
3205 r
[i
].origin.x
+= width
;
3209 /* Draw overlining, etc. on the cursor. */
3210 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3211 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3213 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3220 /* Draw overlining, etc. on the stretch glyph (or the part
3221 of the stretch glyph after the cursor). */
3222 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3226 s
->background_filled_p
= 1;
3232 ns_draw_glyph_string
(struct glyph_string
*s
)
3233 /* --------------------------------------------------------------------------
3234 External (RIF): Main draw-text call.
3235 -------------------------------------------------------------------------- */
3237 /* TODO (optimize): focus for box and contents draw */
3240 char box_drawn_p
= 0;
3241 struct font
*font
= s
->face
->font
;
3242 if (! font
) font
= FRAME_FONT
(s
->f
);
3244 NSTRACE
(ns_draw_glyph_string
);
3246 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3249 struct glyph_string
*next
;
3251 for (width
= 0, next
= s
->next
;
3252 next
&& width
< s
->right_overhang
;
3253 width
+= next
->width
, next
= next
->next
)
3254 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3256 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3258 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3259 ns_focus
(s
->f
, r
, n
);
3260 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3265 ns_dumpglyphs_stretch
(s
->next
);
3267 next
->num_clips
= 0;
3271 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3272 && (s
->first_glyph
->type == CHAR_GLYPH
3273 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3275 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3276 ns_focus
(s
->f
, r
, n
);
3277 ns_maybe_dumpglyphs_background
(s
, 1);
3278 ns_dumpglyphs_box_or_relief
(s
);
3283 switch (s
->first_glyph
->type)
3287 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3288 ns_focus
(s
->f
, r
, n
);
3289 ns_dumpglyphs_image
(s
, r
[0]);
3294 ns_dumpglyphs_stretch
(s
);
3298 case COMPOSITE_GLYPH
:
3299 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3300 ns_focus
(s
->f
, r
, n
);
3302 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3303 && ! s
->first_glyph
->u.cmp.automatic
))
3304 s
->background_filled_p
= 1;
3306 ns_maybe_dumpglyphs_background
3307 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3309 flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3310 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3311 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3312 NS_DUMPGLYPH_NORMAL
));
3314 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3316 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3317 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3318 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3322 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3323 (flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3324 || flags
== NS_DUMPGLYPH_MOUSEFACE
);
3327 NSColor
*col
= (NS_FACE_FOREGROUND
(s
->face
) != 0
3328 ? ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(s
->face
),
3330 : FRAME_FOREGROUND_COLOR
(s
->f
));
3333 /* Draw underline, overline, strike-through. */
3334 ns_draw_text_decoration
(s
, s
->face
, col
, s
->width
, s
->x
);
3337 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3339 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3340 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3341 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3347 case GLYPHLESS_GLYPH
:
3348 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3349 ns_focus
(s
->f
, r
, n
);
3351 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3352 && ! s
->first_glyph
->u.cmp.automatic
))
3353 s
->background_filled_p
= 1;
3355 ns_maybe_dumpglyphs_background
3356 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3358 /* Not yet implemented. */
3367 /* Draw box if not done already. */
3368 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3370 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3371 ns_focus
(s
->f
, r
, n
);
3372 ns_dumpglyphs_box_or_relief
(s
);
3381 /* ==========================================================================
3385 ========================================================================== */
3389 ns_send_appdefined
(int value
)
3390 /* --------------------------------------------------------------------------
3391 Internal: post an appdefined event which EmacsApp-sendEvent will
3392 recognize and take as a command to halt the event loop.
3393 -------------------------------------------------------------------------- */
3395 /*NSTRACE (ns_send_appdefined); */
3397 #ifdef NS_IMPL_GNUSTEP
3398 // GNUStep needs postEvent to happen on the main thread.
3399 if (! [[NSThread currentThread
] isMainThread
])
3401 EmacsApp
*app
= (EmacsApp
*)NSApp
;
3402 app
->nextappdefined
= value
;
3403 [app performSelectorOnMainThread
:@selector
(sendFromMainThread
:)
3410 /* Only post this event if we haven't already posted one. This will end
3411 the [NXApp run] main loop after having processed all events queued at
3413 if (send_appdefined
)
3417 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3418 send_appdefined
= NO
;
3420 /* Don't need wakeup timer any more */
3423 [timed_entry invalidate
];
3424 [timed_entry release
];
3428 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3429 location
: NSMakePoint
(0, 0)
3432 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3433 context
: [NSApp context
]
3438 /* Post an application defined event on the event queue. When this is
3439 received the [NXApp run] will return, thus having processed all
3440 events which are currently queued. */
3441 [NSApp postEvent
: nxev atStart
: NO
];
3445 #ifdef HAVE_NATIVE_FS
3449 Lisp_Object frame
, tail
;
3451 if (ns_last_use_native_fullscreen
== ns_use_native_fullscreen
)
3454 ns_last_use_native_fullscreen
= ns_use_native_fullscreen
;
3456 FOR_EACH_FRAME
(tail
, frame
)
3458 struct frame
*f
= XFRAME
(frame
);
3461 EmacsView
*view = FRAME_NS_VIEW
(f
);
3462 [view updateCollectionBehaviour
];
3468 /* GNUStep and OSX <= 10.4 does not have cancelTracking. */
3469 #
if defined
(NS_IMPL_COCOA
) && \
3470 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_5
3471 /* Check if menu open should be cancelled or continued as normal. */
3473 ns_check_menu_open
(NSMenu
*menu)
3475 /* Click in menu bar? */
3476 NSArray
*a
= [[NSApp mainMenu
] itemArray
];
3480 if (menu == nil
) // Menu tracking ended.
3482 if (menu_will_open_state
== MENU_OPENING
)
3483 menu_will_open_state
= MENU_NONE
;
3487 for (i
= 0; ! found
&& i
< [a count
]; i
++)
3488 found
= menu == [[a objectAtIndex
:i
] submenu
];
3491 if (menu_will_open_state
== MENU_NONE
&& emacs_event
)
3493 NSEvent
*theEvent
= [NSApp currentEvent
];
3494 struct frame
*emacsframe
= SELECTED_FRAME
();
3496 [menu cancelTracking
];
3497 menu_will_open_state
= MENU_PENDING
;
3498 emacs_event
->kind
= MENU_BAR_ACTIVATE_EVENT
;
3499 EV_TRAILER
(theEvent
);
3501 CGEventRef ourEvent
= CGEventCreate
(NULL);
3502 menu_mouse_point
= CGEventGetLocation
(ourEvent
);
3503 CFRelease
(ourEvent
);
3505 else if (menu_will_open_state
== MENU_OPENING
)
3507 menu_will_open_state
= MENU_NONE
;
3512 /* Redo saved menu click if state is MENU_PENDING. */
3514 ns_check_pending_open_menu
()
3516 if (menu_will_open_state
== MENU_PENDING
)
3518 CGEventSourceRef source
3519 = CGEventSourceCreate
(kCGEventSourceStateHIDSystemState
);
3521 CGEventRef event
= CGEventCreateMouseEvent
(source
,
3522 kCGEventLeftMouseDown
,
3524 kCGMouseButtonLeft
);
3525 CGEventSetType
(event
, kCGEventLeftMouseDown
);
3526 CGEventPost
(kCGHIDEventTap
, event
);
3530 menu_will_open_state
= MENU_OPENING
;
3533 #endif
/* NS_IMPL_COCOA) && >= MAC_OS_X_VERSION_10_5 */
3536 ns_read_socket
(struct terminal *terminal, struct input_event
*hold_quit
)
3537 /* --------------------------------------------------------------------------
3538 External (hook): Post an event to ourself and keep reading events until
3539 we read it back again. In effect process all events which were waiting.
3540 From 21+ we have to manage the event buffer ourselves.
3541 -------------------------------------------------------------------------- */
3543 struct input_event ev
;
3546 /* NSTRACE (ns_read_socket); */
3548 #ifdef HAVE_NATIVE_FS
3552 if ([NSApp modalWindow
] != nil
)
3555 if (hold_event_q.nr
> 0)
3558 for (i
= 0; i
< hold_event_q.nr
; ++i
)
3559 kbd_buffer_store_event_hold
(&hold_event_q.q
[i
], hold_quit
);
3560 hold_event_q.nr
= 0;
3565 n_emacs_events_pending
= 0;
3568 q_event_ptr
= hold_quit
;
3570 /* we manage autorelease pools by allocate/reallocate each time around
3571 the loop; strict nesting is occasionally violated but seems not to
3572 matter.. earlier methods using full nesting caused major memory leaks */
3573 [outerpool release
];
3574 outerpool
= [[NSAutoreleasePool alloc
] init
];
3576 /* If have pending open-file requests, attend to the next one of those. */
3577 if (ns_pending_files
&& [ns_pending_files count
] != 0
3578 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3580 [ns_pending_files removeObjectAtIndex
: 0];
3582 /* Deal with pending service requests. */
3583 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3585 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3586 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3588 [ns_pending_service_names removeObjectAtIndex
: 0];
3589 [ns_pending_service_args removeObjectAtIndex
: 0];
3593 /* Run and wait for events. We must always send one NX_APPDEFINED event
3594 to ourself, otherwise [NXApp run] will never exit. */
3595 send_appdefined
= YES
;
3596 ns_send_appdefined
(-1);
3598 if (++apploopnr
!= 1)
3606 nevents
= n_emacs_events_pending
;
3607 n_emacs_events_pending
= 0;
3608 emacs_event
= q_event_ptr
= NULL;
3616 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3617 fd_set
*exceptfds
, struct timespec const
*timeout
,
3618 sigset_t const
*sigmask
)
3619 /* --------------------------------------------------------------------------
3620 Replacement for select, checking for events
3621 -------------------------------------------------------------------------- */
3625 struct input_event event
;
3628 /* NSTRACE (ns_select); */
3630 #ifdef HAVE_NATIVE_FS
3634 if (hold_event_q.nr
> 0)
3636 /* We already have events pending. */
3642 for (k
= 0; k
< nfds
+1; k
++)
3644 if (readfds
&& FD_ISSET
(k
, readfds
)) ++nr
;
3645 if (writefds
&& FD_ISSET
(k
, writefds
)) ++nr
;
3649 ||
(timeout
&& timeout
->tv_sec
== 0 && timeout
->tv_nsec
== 0))
3650 return pselect
(nfds
, readfds
, writefds
, exceptfds
, timeout
, sigmask
);
3652 [outerpool release
];
3653 outerpool
= [[NSAutoreleasePool alloc
] init
];
3656 send_appdefined
= YES
;
3659 pthread_mutex_lock
(&select_mutex
);
3664 select_readfds
= *readfds
;
3665 select_valid
+= SELECT_HAVE_READ
;
3669 select_writefds
= *writefds
;
3670 select_valid
+= SELECT_HAVE_WRITE
;
3675 select_timeout
= *timeout
;
3676 select_valid
+= SELECT_HAVE_TMO
;
3679 pthread_mutex_unlock
(&select_mutex
);
3681 /* Inform fd_handler that select should be called */
3683 emacs_write_sig
(selfds
[1], &c
, 1);
3685 else if (nr
== 0 && timeout
)
3687 /* No file descriptor, just a timeout, no need to wake fd_handler */
3688 double time
= timespectod
(*timeout
);
3689 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3692 @selector
(timeout_handler
:)
3697 else /* No timeout and no file descriptors, can this happen? */
3699 /* Send appdefined so we exit from the loop */
3700 ns_send_appdefined
(-1);
3705 emacs_event
= &event
;
3706 if (++apploopnr
!= 1)
3713 if (nr
> 0 && readfds
)
3716 emacs_write_sig
(selfds
[1], &c
, 1);
3720 t
= last_appdefined_event_data
;
3722 if (t
!= NO_APPDEFINED_DATA
)
3724 last_appdefined_event_data
= NO_APPDEFINED_DATA
;
3728 /* The NX_APPDEFINED event we received was a timeout. */
3733 /* The NX_APPDEFINED event we received was the result of
3734 at least one real input event arriving. */
3740 /* Received back from select () in fd_handler; copy the results */
3741 pthread_mutex_lock
(&select_mutex
);
3742 if (readfds
) *readfds
= select_readfds
;
3743 if (writefds
) *writefds
= select_writefds
;
3744 pthread_mutex_unlock
(&select_mutex
);
3759 /* ==========================================================================
3763 ========================================================================== */
3767 ns_set_vertical_scroll_bar
(struct window
*window
,
3768 int portion
, int whole
, int position
)
3769 /* --------------------------------------------------------------------------
3770 External (hook): Update or add scrollbar
3771 -------------------------------------------------------------------------- */
3775 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3776 EmacsView
*view = FRAME_NS_VIEW
(f
);
3777 int window_y
, window_height
;
3778 int top
, left
, height
, width
, sb_width
, sb_left
;
3780 BOOL fringe_extended_p
;
3782 /* optimization; display engine sends WAY too many of these.. */
3783 if (!NILP
(window
->vertical_scroll_bar
))
3785 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3786 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3788 if (view->scrollbarsNeedingUpdate
== 0)
3790 if (!windows_or_buffers_changed
)
3794 view->scrollbarsNeedingUpdate
--;
3798 NSTRACE
(ns_set_vertical_scroll_bar
);
3800 /* Get dimensions. */
3801 window_box
(window
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
3803 height
= window_height
;
3804 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3805 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3807 /* allow for displaying a skinnier scrollbar than char area allotted */
3808 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3809 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3812 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3813 /* the parent view is flipped, so we need to flip y value */
3815 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3817 fringe_extended_p
= WINDOW_FRINGE_EXTENDED_P
(window
);
3819 XSETWINDOW
(win
, window
);
3822 /* we want at least 5 lines to display a scrollbar */
3823 if (WINDOW_TOTAL_LINES
(window
) < 5)
3825 if (!NILP
(window
->vertical_scroll_bar
))
3827 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3828 [bar removeFromSuperview
];
3829 wset_vertical_scroll_bar
(window
, Qnil
);
3831 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3836 if (NILP
(window
->vertical_scroll_bar
))
3838 if (width
> 0 && height
> 0)
3840 if (fringe_extended_p
)
3841 ns_clear_frame_area
(f
, sb_left
, top
, sb_width
, height
);
3843 ns_clear_frame_area
(f
, left
, top
, width
, height
);
3846 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3847 wset_vertical_scroll_bar
(window
, make_save_ptr
(bar));
3852 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3853 oldRect
= [bar frame
];
3854 r.
size.width
= oldRect.
size.width
;
3855 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3857 if (oldRect.origin.x
!= r.origin.x
)
3858 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3863 [bar setPosition
: position portion
: portion whole
: whole
];
3869 ns_condemn_scroll_bars
(struct frame
*f
)
3870 /* --------------------------------------------------------------------------
3871 External (hook): arrange for all frame's scrollbars to be removed
3872 at next call to judge_scroll_bars, except for those redeemed.
3873 -------------------------------------------------------------------------- */
3877 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3879 NSTRACE
(ns_condemn_scroll_bars
);
3881 for (i
=[subviews count
]-1; i
>= 0; i
--)
3883 view = [subviews objectAtIndex
: i
];
3884 if ([view isKindOfClass
: [EmacsScroller
class]])
3891 ns_redeem_scroll_bar
(struct window
*window
)
3892 /* --------------------------------------------------------------------------
3893 External (hook): arrange to spare this window's scrollbar
3894 at next call to judge_scroll_bars.
3895 -------------------------------------------------------------------------- */
3898 NSTRACE
(ns_redeem_scroll_bar
);
3899 if (!NILP
(window
->vertical_scroll_bar
))
3901 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3908 ns_judge_scroll_bars
(struct frame
*f
)
3909 /* --------------------------------------------------------------------------
3910 External (hook): destroy all scrollbars on frame that weren't
3911 redeemed after call to condemn_scroll_bars.
3912 -------------------------------------------------------------------------- */
3916 EmacsView
*eview
= FRAME_NS_VIEW
(f
);
3917 NSArray
*subviews
= [[eview superview
] subviews
];
3920 NSTRACE
(ns_judge_scroll_bars
);
3921 for (i
= [subviews count
]-1; i
>= 0; --i
)
3923 view = [subviews objectAtIndex
: i
];
3924 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3930 [eview updateFrameSize
: NO
];
3933 /* ==========================================================================
3937 ========================================================================== */
3940 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3942 NSArray
*screens
= [NSScreen screens
];
3943 NSEnumerator
*enumerator
= [screens objectEnumerator
];
3948 while ((screen
= [enumerator nextObject
]) != nil
)
3949 frame
= NSUnionRect
(frame
, [screen frame
]);
3951 return NSHeight
(frame
);
3955 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3957 NSArray
*screens
= [NSScreen screens
];
3958 NSEnumerator
*enumerator
= [screens objectEnumerator
];
3963 while ((screen
= [enumerator nextObject
]) != nil
)
3964 frame
= NSUnionRect
(frame
, [screen frame
]);
3966 return NSWidth
(frame
);
3970 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3971 /* --------------------------------------------------------------------------
3972 Convert modifier name to lisp symbol
3973 -------------------------------------------------------------------------- */
3975 if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3977 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3979 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3981 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3983 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3985 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3993 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3994 Lisp_Object yesval
, Lisp_Object noval
,
3995 BOOL is_float
, BOOL is_modstring
)
3996 /* --------------------------------------------------------------------------
3997 Check a parameter value in user's preferences
3998 -------------------------------------------------------------------------- */
4000 const
char *value
= ns_get_defaults_value
(parameter
);
4006 if (c_strcasecmp
(value
, "YES"
) == 0)
4008 else if (c_strcasecmp
(value
, "NO"
) == 0)
4010 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
4011 *result
= make_float
(f
);
4012 else if (is_modstring
&& value
)
4013 *result
= ns_string_to_lispmod
(value
);
4014 else fprintf (stderr
,
4015 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
4021 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
4022 /* --------------------------------------------------------------------------
4023 Initialize global info and storage for display.
4024 -------------------------------------------------------------------------- */
4026 NSScreen
*screen
= [NSScreen mainScreen
];
4027 NSWindowDepth depth
= [screen depth
];
4029 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
4030 dpyinfo
->resy
= 72.27;
4031 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
4032 NSColorSpaceFromDepth
(depth
)]
4033 && ![NSCalibratedWhiteColorSpace isEqualToString
:
4034 NSColorSpaceFromDepth
(depth
)];
4035 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
4036 dpyinfo
->color_table
= xmalloc
(sizeof
*dpyinfo
->color_table
);
4037 dpyinfo
->color_table
->colors
= NULL;
4038 dpyinfo
->root_window
= 42; /* a placeholder.. */
4039 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
4040 dpyinfo
->n_fonts
= 0;
4041 dpyinfo
->smallest_font_height
= 1;
4042 dpyinfo
->smallest_char_width
= 1;
4044 reset_mouse_highlight
(&dpyinfo
->mouse_highlight
);
4048 /* This and next define (many of the) public functions in this file. */
4049 /* x_... are generic versions in xdisp.c that we, and other terms, get away
4050 with using despite presence in the "system dependent" redisplay
4051 interface. In addition, many of the ns_ methods have code that is
4052 shared with all terms, indicating need for further refactoring. */
4053 extern frame_parm_handler ns_frame_parm_handlers
[];
4054 static
struct redisplay_interface ns_redisplay_interface
=
4056 ns_frame_parm_handlers
,
4060 x_clear_end_of_line
,
4062 ns_after_update_window_line
,
4063 ns_update_window_begin
,
4064 ns_update_window_end
,
4065 0, /* flush_display */
4066 x_clear_window_mouse_face
,
4067 x_get_glyph_overhangs
,
4068 x_fix_overlapping_area
,
4069 ns_draw_fringe_bitmap
,
4070 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
4071 0, /* destroy_fringe_bitmap */
4072 ns_compute_glyph_string_overhangs
,
4073 ns_draw_glyph_string
,
4074 ns_define_frame_cursor
,
4075 ns_clear_frame_area
,
4076 ns_draw_window_cursor
,
4077 ns_draw_vertical_window_border
,
4078 ns_draw_window_divider
,
4079 ns_shift_glyphs_for_insert
4084 ns_delete_display
(struct ns_display_info
*dpyinfo
)
4090 /* This function is called when the last frame on a display is deleted. */
4092 ns_delete_terminal
(struct terminal *terminal)
4094 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
4096 /* Protect against recursive calls. delete_frame in
4097 delete_terminal calls us back when it deletes our last frame. */
4098 if (!terminal->name
)
4103 x_destroy_all_bitmaps
(dpyinfo
);
4104 ns_delete_display
(dpyinfo
);
4109 static
struct terminal *
4110 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
4111 /* --------------------------------------------------------------------------
4112 Set up use of NS before we make the first connection.
4113 -------------------------------------------------------------------------- */
4115 struct terminal *terminal;
4117 NSTRACE
(ns_create_terminal
);
4119 terminal = create_terminal
();
4121 terminal->type = output_ns
;
4122 terminal->display_info.ns
= dpyinfo
;
4123 dpyinfo
->terminal = terminal;
4125 terminal->rif
= &ns_redisplay_interface
;
4127 terminal->clear_frame_hook
= ns_clear_frame
;
4128 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
4129 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
4130 terminal->ring_bell_hook
= ns_ring_bell
;
4131 terminal->reset_terminal_modes_hook
= NULL;
4132 terminal->set_terminal_modes_hook
= NULL;
4133 terminal->update_begin_hook
= ns_update_begin
;
4134 terminal->update_end_hook
= ns_update_end
;
4135 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
4136 terminal->read_socket_hook
= ns_read_socket
;
4137 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
4138 terminal->mouse_position_hook
= ns_mouse_position
;
4139 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
4140 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
4142 terminal->fullscreen_hook
= ns_fullscreen_hook
;
4144 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
4145 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
4146 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
4147 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
4149 terminal->delete_frame_hook
= x_destroy_window
;
4150 terminal->delete_terminal_hook
= ns_delete_terminal
;
4156 struct ns_display_info
*
4157 ns_term_init
(Lisp_Object display_name
)
4158 /* --------------------------------------------------------------------------
4159 Start the Application and get things rolling.
4160 -------------------------------------------------------------------------- */
4162 struct terminal *terminal;
4163 struct ns_display_info
*dpyinfo
;
4164 static int ns_initialized
= 0;
4167 if (ns_initialized
) return x_display_list
;
4170 NSTRACE
(ns_term_init
);
4172 [outerpool release
];
4173 outerpool
= [[NSAutoreleasePool alloc
] init
];
4175 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
4176 /*GSDebugAllocationActive (YES); */
4180 Fset_input_interrupt_mode
(Qnil
);
4182 if (selfds
[0] == -1)
4184 if (emacs_pipe
(selfds
) != 0)
4186 fprintf (stderr
, "Failed to create pipe
: %s\n",
4187 emacs_strerror
(errno
));
4191 fcntl
(selfds
[0], F_SETFL
, O_NONBLOCK|fcntl
(selfds
[0], F_GETFL
));
4192 FD_ZERO
(&select_readfds
);
4193 FD_ZERO
(&select_writefds
);
4194 pthread_mutex_init
(&select_mutex
, NULL);
4197 ns_pending_files
= [[NSMutableArray alloc
] init
];
4198 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
4199 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
4201 /* Start app and create the main menu, window, view.
4202 Needs to be here because ns_initialize_display_info () uses AppKit classes.
4203 The view will then ask the NSApp to stop and return to Emacs. */
4204 [EmacsApp sharedApplication
];
4207 [NSApp setDelegate
: NSApp
];
4209 /* Start the select thread. */
4210 [NSThread detachNewThreadSelector
:@selector
(fd_handler
:)
4214 /* debugging: log all notifications */
4215 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4216 selector: @selector (logNotification:)
4217 name: nil object: nil]; */
4219 dpyinfo
= xzalloc
(sizeof
*dpyinfo
);
4221 ns_initialize_display_info
(dpyinfo
);
4222 terminal = ns_create_terminal
(dpyinfo
);
4224 terminal->kboard
= allocate_kboard
(Qns
);
4225 /* Don't let the initial kboard remain current longer than necessary.
4226 That would cause problems if a file loaded on startup tries to
4227 prompt in the mini-buffer. */
4228 if (current_kboard
== initial_kboard
)
4229 current_kboard
= terminal->kboard
;
4230 terminal->kboard
->reference_count
++;
4232 dpyinfo
->next
= x_display_list
;
4233 x_display_list
= dpyinfo
;
4235 dpyinfo
->name_list_element
= Fcons
(display_name
, Qnil
);
4237 terminal->name
= xstrdup
(SSDATA
(display_name
));
4241 if (!inhibit_x_resources
)
4243 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4246 /* this is a standard variable */
4247 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4248 make_float
(10.0), make_float
(6.0), YES
, NO
);
4249 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4253 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4257 Lisp_Object color_file
, color_map
, color
;
4261 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4262 Fsymbol_value
(intern
("data
-directory"
)));
4264 color_map
= Fx_load_color_file
(color_file
);
4265 if (NILP
(color_map
))
4266 fatal
("Could not read
%s.\n", SDATA (color_file));
4268 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4269 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4271 color
= XCAR
(color_map
);
4272 name
= SSDATA
(XCAR
(color
));
4273 c
= XINT
(XCDR
(color
));
4275 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4276 green
: GREEN_FROM_ULONG
(c
) / 255.0
4277 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4279 forKey
: [NSString stringWithUTF8String
: name
]];
4281 [cl writeToFile
: nil
];
4286 #ifdef NS_IMPL_GNUSTEP
4287 Vwindow_system_version
= build_string
(gnustep_base_version
);
4289 /*PSnextrelease (128, c); */
4290 char c
[DBL_BUFSIZE_BOUND
];
4291 int len
= dtoastr
(c
, sizeof c
, 0, 0, NSAppKitVersionNumber
);
4292 Vwindow_system_version
= make_unibyte_string
(c
, len
);
4296 delete_keyboard_wait_descriptor
(0);
4298 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4300 /* Set up OS X app menu */
4301 #ifdef NS_IMPL_COCOA
4305 /* set up the application menu */
4306 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4307 [svcsMenu setAutoenablesItems
: NO
];
4308 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4309 [appMenu setAutoenablesItems
: NO
];
4310 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4311 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4313 [appMenu insertItemWithTitle
: @"About Emacs"
4314 action
: @selector
(orderFrontStandardAboutPanel
:)
4317 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4318 [appMenu insertItemWithTitle
: @"Preferences..."
4319 action
: @selector
(showPreferencesWindow
:)
4322 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4323 item
= [appMenu insertItemWithTitle
: @"Services"
4324 action
: @selector
(menuDown
:)
4327 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4328 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4329 [appMenu insertItemWithTitle
: @"Hide Emacs"
4330 action
: @selector
(hide
:)
4333 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4334 action
: @selector
(hideOtherApplications
:)
4337 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4338 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4339 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4340 action
: @selector
(terminate
:)
4344 item
= [mainMenu insertItemWithTitle
: ns_app_name
4345 action
: @selector
(menuDown
:)
4348 [mainMenu setSubmenu
: appMenu forItem
: item
];
4349 [dockMenu insertItemWithTitle
: @"New Frame"
4350 action
: @selector
(newFrame
:)
4354 [NSApp setMainMenu
: mainMenu
];
4355 [NSApp setAppleMenu
: appMenu
];
4356 [NSApp setServicesMenu
: svcsMenu
];
4357 /* Needed at least on Cocoa, to get dock menu to show windows */
4358 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4360 [[NSNotificationCenter defaultCenter
]
4361 addObserver
: mainMenu
4362 selector
: @selector
(trackingNotification
:)
4363 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4364 [[NSNotificationCenter defaultCenter
]
4365 addObserver
: mainMenu
4366 selector
: @selector
(trackingNotification
:)
4367 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4369 #endif
/* MAC OS X menu setup */
4371 /* Register our external input/output types, used for determining
4372 applicable services and also drag/drop eligibility. */
4373 ns_send_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
] retain
];
4374 ns_return_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
]
4376 ns_drag_types
= [[NSArray arrayWithObjects
:
4378 NSTabularTextPboardType
,
4379 NSFilenamesPboardType
,
4382 NSFontPboardType
, nil
] retain
];
4384 /* If fullscreen is in init/default-frame-alist, focus isn't set
4385 right for fullscreen windows, so set this. */
4386 [NSApp activateIgnoringOtherApps
:YES
];
4389 ns_do_open_file
= YES
;
4391 #ifdef NS_IMPL_GNUSTEP
4392 /* GNUstep steals SIGCHLD for use in NSTask, but we don't use NSTask.
4393 We must re-catch it so subprocess works. */
4394 catch_child_signal
();
4401 ns_term_shutdown
(int sig
)
4403 [[NSUserDefaults standardUserDefaults
] synchronize
];
4405 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4406 if (STRINGP
(Vauto_save_list_file_name
))
4407 unlink
(SSDATA
(Vauto_save_list_file_name
));
4409 if (sig
== 0 || sig
== SIGTERM
)
4411 [NSApp terminate
: NSApp
];
4413 else // force a stack
trace to happen
4420 /* ==========================================================================
4422 EmacsApp implementation
4424 ========================================================================== */
4427 @implementation EmacsApp
4431 if (self
= [super init
])
4433 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_9
4434 self
->isFirst
= YES
;
4436 #ifdef NS_IMPL_GNUSTEP
4437 self
->applicationDidFinishLaunchingCalled
= NO
;
4444 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_9
4447 NSAutoreleasePool
*pool
= [[NSAutoreleasePool alloc
] init
];
4449 if (isFirst
) [self finishLaunching
];
4452 shouldKeepRunning
= YES
;
4456 pool
= [[NSAutoreleasePool alloc
] init
];
4459 [self nextEventMatchingMask
:NSAnyEventMask
4460 untilDate
:[NSDate distantFuture
]
4461 inMode
:NSDefaultRunLoopMode
4463 [self sendEvent
:event
];
4464 [self updateWindows
];
4465 } while (shouldKeepRunning
);
4470 - (void
)stop
: (id
)sender
4472 shouldKeepRunning
= NO
;
4473 // Stop possible
dialog also. Noop
if no
dialog present.
4474 // The file
dialog still leaks
7k
- 10k on
10.9 though.
4475 [super stop
:sender
];
4479 - (void
)logNotification
: (NSNotification
*)notification
4481 const
char *name
= [[notification name
] UTF8String
];
4482 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4483 && !strstr
(name
, "WindowNumber"
))
4484 NSLog
(@"notification
: '%@'"
, [notification name
]);
4488 - (void
)sendEvent
: (NSEvent
*)theEvent
4489 /* --------------------------------------------------------------------------
4490 Called when NSApp is running for each event received. Used to stop
4491 the loop when we choose, since there's no way to just run one iteration.
4492 -------------------------------------------------------------------------- */
4494 int
type = [theEvent
type];
4495 NSWindow
*window
= [theEvent window
];
4497 /* NSTRACE (sendEvent); */
4498 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4500 #ifdef NS_IMPL_GNUSTEP
4501 // Keyboard events aren
't propagated to file dialogs for some reason.
4502 if ([NSApp modalWindow] != nil &&
4503 (type == NSKeyDown || type == NSKeyUp || type == NSFlagsChanged))
4505 [[NSApp modalWindow] sendEvent: theEvent];
4510 if (type == NSApplicationDefined)
4512 switch ([theEvent data2])
4514 #ifdef NS_IMPL_COCOA
4515 case NSAPP_DATA2_RUNASSCRIPT:
4520 case NSAPP_DATA2_RUNFILEDIALOG:
4521 ns_run_file_dialog ();
4527 if (type == NSCursorUpdate && window == nil)
4529 fprintf (stderr, "Dropping external cursor update event.\n");
4533 if (type == NSApplicationDefined)
4535 /* Events posted by ns_send_appdefined interrupt the run loop here.
4536 But, if a modal window is up, an appdefined can still come through,
4537 (e.g., from a makeKeyWindow event) but stopping self also stops the
4538 modal loop. Just defer it until later. */
4539 if ([NSApp modalWindow] == nil)
4541 last_appdefined_event_data = [theEvent data1];
4546 send_appdefined = YES;
4551 #ifdef NS_IMPL_COCOA
4552 /* If no dialog and none of our frames have focus and it is a move, skip it.
4553 It is a mouse move in an auxiliary menu, i.e. on the top right on OSX,
4554 such as Wifi, sound, date or similar.
4555 This prevents "spooky" highlighting in the frame under the menu. */
4556 if (type == NSMouseMoved && [NSApp modalWindow] == nil)
4558 struct ns_display_info *di;
4559 BOOL has_focus = NO;
4560 for (di = x_display_list; ! has_focus && di; di = di->next)
4561 has_focus = di->x_focus_frame != 0;
4567 [super sendEvent: theEvent];
4571 - (void)showPreferencesWindow: (id)sender
4573 struct frame *emacsframe = SELECTED_FRAME ();
4574 NSEvent *theEvent = [NSApp currentEvent];
4578 emacs_event->kind = NS_NONKEY_EVENT;
4579 emacs_event->code = KEY_NS_SHOW_PREFS;
4580 emacs_event->modifiers = 0;
4581 EV_TRAILER (theEvent);
4585 - (void)newFrame: (id)sender
4587 struct frame *emacsframe = SELECTED_FRAME ();
4588 NSEvent *theEvent = [NSApp currentEvent];
4592 emacs_event->kind = NS_NONKEY_EVENT;
4593 emacs_event->code = KEY_NS_NEW_FRAME;
4594 emacs_event->modifiers = 0;
4595 EV_TRAILER (theEvent);
4599 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4600 - (BOOL) openFile: (NSString *)fileName
4602 struct frame *emacsframe = SELECTED_FRAME ();
4603 NSEvent *theEvent = [NSApp currentEvent];
4608 emacs_event->kind = NS_NONKEY_EVENT;
4609 emacs_event->code = KEY_NS_OPEN_FILE_LINE;
4610 ns_input_file = append2 (ns_input_file, build_string ([fileName UTF8String]));
4611 ns_input_line = Qnil; /* can be start or cons start,end */
4612 emacs_event->modifiers =0;
4613 EV_TRAILER (theEvent);
4619 /* **************************************************************************
4621 EmacsApp delegate implementation
4623 ************************************************************************** */
4625 - (void)applicationDidFinishLaunching: (NSNotification *)notification
4626 /* --------------------------------------------------------------------------
4627 When application is loaded, terminate event loop in ns_term_init
4628 -------------------------------------------------------------------------- */
4630 NSTRACE (applicationDidFinishLaunching);
4631 #ifdef NS_IMPL_GNUSTEP
4632 ((EmacsApp *)self)->applicationDidFinishLaunchingCalled = YES;
4634 [NSApp setServicesProvider: NSApp];
4635 ns_send_appdefined (-2);
4639 /* Termination sequences:
4642 MenuBar | File | Exit:
4643 Select Quit from App menubar:
4645 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4648 Select Quit from Dock menu:
4651 Cancel -> Nothing else
4655 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4660 - (void) terminate: (id)sender
4662 struct frame *emacsframe = SELECTED_FRAME ();
4667 emacs_event->kind = NS_NONKEY_EVENT;
4668 emacs_event->code = KEY_NS_POWER_OFF;
4669 emacs_event->arg = Qt; /* mark as non-key event */
4670 EV_TRAILER ((id)nil);
4674 - (NSApplicationTerminateReply)applicationShouldTerminate: (id)sender
4678 if (NILP (ns_confirm_quit)) // || ns_shutdown_properly --> TO DO
4679 return NSTerminateNow;
4681 ret = NSRunAlertPanel(ns_app_name,
4682 @"Exit requested. Would you like to Save Buffers and Exit, or Cancel the request?",
4683 @"Save Buffers and Exit", @"Cancel", nil);
4685 if (ret == NSAlertDefaultReturn)
4686 return NSTerminateNow;
4687 else if (ret == NSAlertAlternateReturn)
4688 return NSTerminateCancel;
4689 return NSTerminateNow; /* just in case */
4693 not_in_argv (NSString *arg)
4696 const char *a = [arg UTF8String];
4697 for (k = 1; k < initial_argc; ++k)
4698 if (strcmp (a, initial_argv[k]) == 0) return 0;
4702 /* Notification from the Workspace to open a file */
4703 - (BOOL)application: sender openFile: (NSString *)file
4705 if (ns_do_open_file || not_in_argv (file))
4706 [ns_pending_files addObject: file];
4711 /* Open a file as a temporary file */
4712 - (BOOL)application: sender openTempFile: (NSString *)file
4714 if (ns_do_open_file || not_in_argv (file))
4715 [ns_pending_files addObject: file];
4720 /* Notification from the Workspace to open a file noninteractively (?) */
4721 - (BOOL)application: sender openFileWithoutUI: (NSString *)file
4723 if (ns_do_open_file || not_in_argv (file))
4724 [ns_pending_files addObject: file];
4728 /* Notification from the Workspace to open multiple files */
4729 - (void)application: sender openFiles: (NSArray *)fileList
4731 NSEnumerator *files = [fileList objectEnumerator];
4733 /* Don't open files from the command
line unconditionally
,
4734 Cocoa parses the command
line wrong
, --option value tries to open value
4735 if --option is the last option. */
4736 while ((file
= [files nextObject
]) != nil
)
4737 if (ns_do_open_file || not_in_argv
(file
))
4738 [ns_pending_files addObject
: file
];
4740 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4745 /* Handle dock menu requests. */
4746 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4752 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4753 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4755 //ns_app_active
=YES
;
4757 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4759 NSTRACE
(applicationDidBecomeActive
);
4761 #ifdef NS_IMPL_GNUSTEP
4762 if (! applicationDidFinishLaunchingCalled
)
4763 [self applicationDidFinishLaunching
:notification
];
4765 //ns_app_active
=YES
;
4767 ns_update_auto_hide_menu_bar
();
4768 // No constraining takes place when the application is not active.
4769 ns_constrain_all_frames
();
4771 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4774 ns_send_appdefined
(-1);
4779 /* ==========================================================================
4781 EmacsApp aux handlers for managing event loop
4783 ========================================================================== */
4786 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4787 /* --------------------------------------------------------------------------
4788 The timeout specified to ns_select has passed.
4789 -------------------------------------------------------------------------- */
4791 /*NSTRACE (timeout_handler); */
4792 ns_send_appdefined
(-2);
4795 #ifdef NS_IMPL_GNUSTEP
4796 - (void
)sendFromMainThread
:(id
)unused
4798 ns_send_appdefined
(nextappdefined
);
4802 - (void
)fd_handler
:(id
)unused
4803 /* --------------------------------------------------------------------------
4804 Check data waiting on file descriptors and terminate if so
4805 -------------------------------------------------------------------------- */
4808 int waiting
= 1, nfds
;
4811 fd_set readfds
, writefds
, *wfds
;
4812 struct timespec timeout
, *tmo
;
4813 NSAutoreleasePool
*pool
= nil
;
4815 /* NSTRACE (fd_handler); */
4820 pool
= [[NSAutoreleasePool alloc
] init
];
4826 FD_SET
(selfds
[0], &fds
);
4827 result
= select
(selfds
[0]+1, &fds
, NULL, NULL, NULL);
4828 if (result
> 0 && read
(selfds
[0], &c
, 1) == 1 && c
== 'g')
4833 pthread_mutex_lock
(&select_mutex
);
4836 if (select_valid
& SELECT_HAVE_READ
)
4837 readfds
= select_readfds
;
4841 if (select_valid
& SELECT_HAVE_WRITE
)
4843 writefds
= select_writefds
;
4848 if (select_valid
& SELECT_HAVE_TMO
)
4850 timeout
= select_timeout
;
4856 pthread_mutex_unlock
(&select_mutex
);
4858 FD_SET
(selfds
[0], &readfds
);
4859 if (selfds
[0] >= nfds
) nfds
= selfds
[0]+1;
4861 result
= pselect
(nfds
, &readfds
, wfds
, NULL, tmo
, NULL);
4864 ns_send_appdefined
(-2);
4865 else if (result
> 0)
4867 if (FD_ISSET
(selfds
[0], &readfds
))
4869 if (read
(selfds
[0], &c
, 1) == 1 && c
== 's')
4874 pthread_mutex_lock
(&select_mutex
);
4875 if (select_valid
& SELECT_HAVE_READ
)
4876 select_readfds
= readfds
;
4877 if (select_valid
& SELECT_HAVE_WRITE
)
4878 select_writefds
= writefds
;
4879 if (select_valid
& SELECT_HAVE_TMO
)
4880 select_timeout
= timeout
;
4881 pthread_mutex_unlock
(&select_mutex
);
4883 ns_send_appdefined
(result
);
4893 /* ==========================================================================
4897 ========================================================================== */
4899 /* called from system: queue for next pass through event loop */
4900 - (void
)requestService
: (NSPasteboard
*)pboard
4901 userData
: (NSString
*)userData
4902 error: (NSString
**)error
4904 [ns_pending_service_names addObject
: userData
];
4905 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4906 SSDATA
(ns_string_from_pasteboard
(pboard
))]];
4910 /* called from ns_read_socket to clear queue */
4911 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4913 struct frame
*emacsframe
= SELECTED_FRAME
();
4914 NSEvent
*theEvent
= [NSApp currentEvent
];
4919 emacs_event
->kind
= NS_NONKEY_EVENT
;
4920 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4921 ns_input_spi_name
= build_string
([name UTF8String
]);
4922 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4923 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4924 EV_TRAILER
(theEvent
);
4934 /* ==========================================================================
4936 EmacsView implementation
4938 ========================================================================== */
4941 @implementation EmacsView
4943 /* needed to inform when window closed from LISP */
4944 - (void
) setWindowClosing
: (BOOL
)closing
4946 windowClosing
= closing
;
4952 NSTRACE
(EmacsView_dealloc
);
4954 if (fs_state
== FULLSCREEN_BOTH
)
4955 [nonfs_window release
];
4960 /* called on font panel selection */
4961 - (void
)changeFont
: (id
)sender
4963 NSEvent
*e
= [[self window
] currentEvent
];
4964 struct face
*face
= FRAME_DEFAULT_FACE
(emacsframe
);
4965 struct font
*font
= face
->font
;
4970 NSTRACE
(changeFont
);
4975 if (EQ
(font
->driver
->type, Qns
))
4976 nsfont
= ((struct nsfont_info
*)font
)->nsfont
;
4977 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_5
4979 nsfont
= (NSFont
*) macfont_get_nsctfont
(font
);
4982 if ((newFont
= [sender convertFont
: nsfont
]))
4984 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4986 emacs_event
->kind
= NS_NONKEY_EVENT
;
4987 emacs_event
->modifiers
= 0;
4988 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4990 size = [newFont pointSize
];
4991 ns_input_fontsize
= make_number
(lrint
(size));
4992 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4998 - (BOOL
)acceptsFirstResponder
5000 NSTRACE
(acceptsFirstResponder
);
5005 - (void
)resetCursorRects
5007 NSRect visible
= [self visibleRect
];
5008 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
5009 NSTRACE
(resetCursorRects
);
5011 if (currentCursor
== nil
)
5012 currentCursor
= [NSCursor arrowCursor
];
5014 if (!NSIsEmptyRect
(visible
))
5015 [self addCursorRect
: visible cursor
: currentCursor
];
5016 [currentCursor setOnMouseEntered
: YES
];
5021 /*****************************************************************************/
5022 /* Keyboard handling. */
5025 - (void
)keyDown
: (NSEvent
*)theEvent
5027 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5029 unsigned fnKeysym
= 0;
5030 static NSMutableArray
*nsEvArray
;
5031 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
5032 static BOOL firstTime
= YES
;
5035 unsigned int flags
= [theEvent modifierFlags
];
5039 /* Rhapsody and OS X give up and down events for the arrow keys */
5040 if (ns_fake_keydown
== YES
)
5041 ns_fake_keydown
= NO
;
5042 else if ([theEvent
type] != NSKeyDown
)
5048 if (![[self window
] isKeyWindow
]
5049 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
5050 /* we must avoid an infinite loop here. */
5051 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
5053 /* XXX: There is an occasional condition in which, when Emacs display
5054 updates a different frame from the current one, and temporarily
5055 selects it, then processes some interrupt-driven input
5056 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
5057 for some reason that window has its first responder set to the NSView
5058 most recently updated (I guess), which is not the correct one. */
5059 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
5063 if (nsEvArray
== nil
)
5064 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
5066 [NSCursor setHiddenUntilMouseMoves
: YES
];
5068 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
5070 clear_mouse_face
(hlinfo
);
5071 hlinfo
->mouse_face_hidden
= 1;
5074 if (!processingCompose
)
5076 /* When using screen sharing, no left or right information is sent,
5077 so use Left key in those cases. */
5078 int is_left_key
, is_right_key
;
5080 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
5081 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
5083 /* (Carbon way: [theEvent keyCode]) */
5085 /* is it a "function key"? */
5086 fnKeysym
= (code
< 0x00ff && (flags
&NSNumericPadKeyMask
))
5087 ? ns_convert_key
([theEvent keyCode
] | NSNumericPadKeyMask
)
5088 : ns_convert_key
(code
);
5092 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
5093 because Emacs treats Delete and KP-Delete same (in simple.el). */
5094 if ((fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
5095 #ifdef NS_IMPL_GNUSTEP
5096 /* GNUstep uses incompatible keycodes, even for those that are
5097 supposed to be hardware independent. Just check for delete.
5098 Keypad delete does not have keysym 0xFFFF.
5099 See http://savannah.gnu.org/bugs/?25395
5101 ||
(fnKeysym
== 0xFFFF && code
== 127)
5104 code
= 0xFF08; /* backspace */
5109 /* are there modifiers? */
5110 emacs_event
->modifiers
= 0;
5112 if (flags
& NSHelpKeyMask
)
5113 emacs_event
->modifiers |
= hyper_modifier
;
5115 if (flags
& NSShiftKeyMask
)
5116 emacs_event
->modifiers |
= shift_modifier
;
5118 is_right_key
= (flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
;
5119 is_left_key
= (flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
5120 ||
(! is_right_key
&& (flags
& NSCommandKeyMask
) == NSCommandKeyMask
);
5123 emacs_event
->modifiers |
= parse_solitary_modifier
5124 (EQ
(ns_right_command_modifier
, Qleft
)
5125 ? ns_command_modifier
5126 : ns_right_command_modifier
);
5130 emacs_event
->modifiers |
= parse_solitary_modifier
5131 (ns_command_modifier
);
5133 /* if super (default), take input manager's word so things like
5134 dvorak / qwerty layout work */
5135 if (EQ
(ns_command_modifier
, Qsuper
)
5137 && [[theEvent characters
] length] != 0)
5139 /* XXX: the code we get will be unshifted, so if we have
5140 a shift modifier, must convert ourselves */
5141 if (!(flags
& NSShiftKeyMask
))
5142 code
= [[theEvent characters
] characterAtIndex
: 0];
5144 /* this is ugly and also requires linking w/Carbon framework
5145 (for LMGetKbdType) so for now leave this rare (?) case
5146 undealt with.. in future look into CGEvent methods */
5149 long smv
= GetScriptManagerVariable
(smKeyScript
);
5150 Handle uchrHandle
= GetResource
5151 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
5153 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
5154 [[theEvent characters
] characterAtIndex
: 0],
5155 kUCKeyActionDisplay
,
5156 (flags
& ~NSCommandKeyMask
) >> 8,
5157 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
5158 &dummy
, 1, &dummy
, &code
);
5165 is_right_key
= (flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
;
5166 is_left_key
= (flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
5167 ||
(! is_right_key
&& (flags
& NSControlKeyMask
) == NSControlKeyMask
);
5170 emacs_event
->modifiers |
= parse_solitary_modifier
5171 (EQ
(ns_right_control_modifier
, Qleft
)
5172 ? ns_control_modifier
5173 : ns_right_control_modifier
);
5176 emacs_event
->modifiers |
= parse_solitary_modifier
5177 (ns_control_modifier
);
5179 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
5180 emacs_event
->modifiers |
=
5181 parse_solitary_modifier
(ns_function_modifier
);
5183 left_is_none
= NILP
(ns_alternate_modifier
)
5184 || EQ
(ns_alternate_modifier
, Qnone
);
5186 is_right_key
= (flags
& NSRightAlternateKeyMask
)
5187 == NSRightAlternateKeyMask
;
5188 is_left_key
= (flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
5190 && (flags
& NSAlternateKeyMask
) == NSAlternateKeyMask
);
5194 if ((NILP
(ns_right_alternate_modifier
)
5195 || EQ
(ns_right_alternate_modifier
, Qnone
)
5196 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
5198 { /* accept pre-interp alt comb */
5199 if ([[theEvent characters
] length] > 0)
5200 code
= [[theEvent characters
] characterAtIndex
: 0];
5201 /*HACK: clear lone shift modifier to stop next if from firing */
5202 if (emacs_event
->modifiers
== shift_modifier
)
5203 emacs_event
->modifiers
= 0;
5206 emacs_event
->modifiers |
= parse_solitary_modifier
5207 (EQ
(ns_right_alternate_modifier
, Qleft
)
5208 ? ns_alternate_modifier
5209 : ns_right_alternate_modifier
);
5212 if (is_left_key
) /* default = meta */
5214 if (left_is_none
&& !fnKeysym
)
5215 { /* accept pre-interp alt comb */
5216 if ([[theEvent characters
] length] > 0)
5217 code
= [[theEvent characters
] characterAtIndex
: 0];
5218 /*HACK: clear lone shift modifier to stop next if from firing */
5219 if (emacs_event
->modifiers
== shift_modifier
)
5220 emacs_event
->modifiers
= 0;
5223 emacs_event
->modifiers |
=
5224 parse_solitary_modifier
(ns_alternate_modifier
);
5228 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
5229 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
5231 /* if it was a function key or had modifiers, pass it directly to emacs */
5232 if (fnKeysym ||
(emacs_event
->modifiers
5233 && (emacs_event
->modifiers
!= shift_modifier
)
5234 && [[theEvent charactersIgnoringModifiers
] length] > 0))
5235 /*[[theEvent characters] length] */
5237 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5239 code |
= (1<<28)|
(3<<16);
5240 else if (code
== 0x7f)
5241 code |
= (1<<28)|
(3<<16);
5243 emacs_event
->kind
= code
> 0xFF
5244 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
5246 emacs_event
->code
= code
;
5247 EV_TRAILER
(theEvent
);
5248 processingCompose
= NO
;
5254 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
5255 /* if we get here we should send the key for input manager processing */
5256 /* Disable warning, there is nothing a user can do about it anyway, and
5257 it does not seem to matter. */
5259 if (firstTime
&& [[NSInputManager currentInputManager
]
5260 wantsToDelayTextChangeNotifications
] == NO
)
5262 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
5266 if (NS_KEYLOG
&& !processingCompose
)
5267 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
5269 processingCompose
= YES
;
5270 [nsEvArray addObject
: theEvent
];
5271 [self interpretKeyEvents
: nsEvArray
];
5272 [nsEvArray removeObject
: theEvent
];
5276 #ifdef NS_IMPL_COCOA
5277 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
5278 decided not to send key-down for.
5279 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
5280 This only applies on Tiger and earlier.
5281 If it matches one of these, send it on to keyDown. */
5282 -(void
)keyUp
: (NSEvent
*)theEvent
5284 int flags
= [theEvent modifierFlags
];
5285 int code
= [theEvent keyCode
];
5286 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
5287 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
5290 fprintf (stderr
, "keyUp
: passed test"
);
5291 ns_fake_keydown
= YES
;
5292 [self keyDown
: theEvent
];
5298 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
5301 /* <NSTextInput>: called when done composing;
5302 NOTE: also called when we delete over working text, followed immed.
5303 by doCommandBySelector: deleteBackward: */
5304 - (void
)insertText
: (id
)aString
5307 int len
= [(NSString
*)aString
length];
5311 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
5312 processingCompose
= NO
;
5317 /* first, clear any working text */
5318 if (workingText
!= nil
)
5319 [self deleteWorkingText
];
5321 /* now insert the string as keystrokes */
5322 for (i
=0; i
<len
; i
++)
5324 code
= [aString characterAtIndex
: i
];
5325 /* TODO: still need this? */
5327 code
= '~'; /* 0x7E */
5328 if (code
!= 32) /* Space */
5329 emacs_event
->modifiers
= 0;
5331 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
5332 emacs_event
->code
= code
;
5333 EV_TRAILER
((id
)nil
);
5338 /* <NSTextInput>: inserts display of composing characters */
5339 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
5341 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
5342 [aString string
] : aString
;
5344 NSLog
(@"setMarkedText
'%@' len
=%lu range %lu from %lu",
5345 str
, (unsigned
long)[str
length],
5346 (unsigned
long)selRange.
length,
5347 (unsigned
long)selRange.location
);
5349 if (workingText
!= nil
)
5350 [self deleteWorkingText
];
5351 if ([str
length] == 0)
5357 processingCompose
= YES
;
5358 workingText
= [str copy
];
5359 ns_working_text
= build_string
([workingText UTF8String
]);
5361 emacs_event
->kind
= NS_TEXT_EVENT
;
5362 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
5363 EV_TRAILER
((id
)nil
);
5367 /* delete display of composing characters [not in <NSTextInput>] */
5368 - (void
)deleteWorkingText
5370 if (workingText
== nil
)
5373 NSLog
(@"deleteWorkingText len
=%lu\n", (unsigned long)[workingText length]);
5374 [workingText release
];
5376 processingCompose
= NO
;
5381 emacs_event
->kind
= NS_TEXT_EVENT
;
5382 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5383 EV_TRAILER
((id
)nil
);
5387 - (BOOL
)hasMarkedText
5389 return workingText
!= nil
;
5393 - (NSRange
)markedRange
5395 NSRange rng
= workingText
!= nil
5396 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5398 NSLog
(@"markedRange request"
);
5406 NSLog
(@"unmark
(accept
) text"
);
5407 [self deleteWorkingText
];
5408 processingCompose
= NO
;
5412 /* used to position char selection windows, etc. */
5413 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5417 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5419 NSLog
(@"firstRectForCharRange request"
);
5421 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5422 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5423 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5424 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5425 +FRAME_LINE_HEIGHT
(emacsframe
));
5427 pt
= [self convertPoint
: pt toView
: nil
];
5428 pt
= [[self window
] convertBaseToScreen
: pt
];
5434 - (NSInteger
)conversationIdentifier
5436 return (NSInteger
)self
;
5440 - (void
)doCommandBySelector
: (SEL
)aSelector
5443 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5445 processingCompose
= NO
;
5446 if (aSelector
== @selector
(deleteBackward
:))
5448 /* happens when user backspaces over an ongoing composition:
5449 throw a 'delete' into the event queue */
5452 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5453 emacs_event
->code
= 0xFF08;
5454 EV_TRAILER
((id
)nil
);
5458 - (NSArray
*)validAttributesForMarkedText
5460 static NSArray
*arr
= nil
;
5461 if (arr
== nil
) arr
= [NSArray new
];
5462 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5466 - (NSRange
)selectedRange
5469 NSLog
(@"selectedRange request"
);
5470 return NSMakeRange
(NSNotFound
, 0);
5473 #
if defined
(NS_IMPL_COCOA
) || GNUSTEP_GUI_MAJOR_VERSION
> 0 || \
5474 GNUSTEP_GUI_MINOR_VERSION
> 22
5475 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5477 - (unsigned int
)characterIndexForPoint
: (NSPoint
)thePoint
5481 NSLog
(@"characterIndexForPoint request"
);
5485 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5487 static NSAttributedString
*str
= nil
;
5488 if (str
== nil
) str
= [NSAttributedString new
];
5490 NSLog
(@"attributedSubstringFromRange request"
);
5494 /* End <NSTextInput> impl. */
5495 /*****************************************************************************/
5498 /* This is what happens when the user presses a mouse button. */
5499 - (void
)mouseDown
: (NSEvent
*)theEvent
5501 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(emacsframe
);
5502 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5504 NSTRACE
(mouseDown
);
5506 [self deleteWorkingText
];
5511 dpyinfo
->last_mouse_frame
= emacsframe
;
5512 /* appears to be needed to prevent spurious movement events generated on
5514 emacsframe
->mouse_moved
= 0;
5516 if ([theEvent
type] == NSScrollWheel
)
5518 CGFloat delta
= [theEvent deltaY
];
5519 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5522 delta
= [theEvent deltaX
];
5525 NSTRACE
(deltaIsZero
);
5528 emacs_event
->kind
= HORIZ_WHEEL_EVENT
;
5531 emacs_event
->kind
= WHEEL_EVENT
;
5533 emacs_event
->code
= 0;
5534 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5535 ((delta
> 0) ? up_modifier
: down_modifier
);
5539 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5540 emacs_event
->code
= EV_BUTTON
(theEvent
);
5541 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5542 | EV_UDMODIFIERS
(theEvent
);
5544 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5545 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5546 EV_TRAILER
(theEvent
);
5550 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5552 NSTRACE
(rightMouseDown
);
5553 [self mouseDown
: theEvent
];
5557 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5559 NSTRACE
(otherMouseDown
);
5560 [self mouseDown
: theEvent
];
5564 - (void
)mouseUp
: (NSEvent
*)theEvent
5567 [self mouseDown
: theEvent
];
5571 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5573 NSTRACE
(rightMouseUp
);
5574 [self mouseDown
: theEvent
];
5578 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5580 NSTRACE
(otherMouseUp
);
5581 [self mouseDown
: theEvent
];
5585 - (void
) scrollWheel
: (NSEvent
*)theEvent
5587 NSTRACE
(scrollWheel
);
5588 [self mouseDown
: theEvent
];
5592 /* Tell emacs the mouse has moved. */
5593 - (void
)mouseMoved
: (NSEvent
*)e
5595 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5596 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(emacsframe
);
5600 // NSTRACE
(mouseMoved
);
5602 dpyinfo
->last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5603 pt
= [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5604 dpyinfo
->last_mouse_motion_x
= pt.x
;
5605 dpyinfo
->last_mouse_motion_y
= pt.y
;
5607 /* update any mouse face */
5608 if (hlinfo
->mouse_face_hidden
)
5610 hlinfo
->mouse_face_hidden
= 0;
5611 clear_mouse_face
(hlinfo
);
5614 /* tooltip handling */
5615 previous_help_echo_string
= help_echo_string
;
5616 help_echo_string
= Qnil
;
5618 if (!NILP
(Vmouse_autoselect_window
))
5620 NSTRACE
(mouse_autoselect_window
);
5621 static Lisp_Object last_mouse_window
;
5623 = window_from_coordinates
(emacsframe
, pt.x
, pt.y
, 0, 0);
5625 if (WINDOWP
(window
)
5626 && !EQ
(window
, last_mouse_window
)
5627 && !EQ
(window
, selected_window
)
5628 && (focus_follows_mouse
5629 ||
(EQ
(XWINDOW
(window
)->frame
,
5630 XWINDOW
(selected_window
)->frame
))))
5632 NSTRACE
(in_window
);
5633 emacs_event
->kind
= SELECT_WINDOW_EVENT
;
5634 emacs_event
->frame_or_window
= window
;
5637 /* Remember the last window where we saw the mouse. */
5638 last_mouse_window
= window
;
5641 if (!note_mouse_movement
(emacsframe
, pt.x
, pt.y
))
5642 help_echo_string
= previous_help_echo_string
;
5644 XSETFRAME
(frame
, emacsframe
);
5645 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5647 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5648 (note_mouse_highlight), which is called through the
5649 note_mouse_movement () call above */
5650 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5651 help_echo_object
, help_echo_pos
);
5655 help_echo_string
= Qnil
;
5656 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5659 if (emacsframe
->mouse_moved
&& send_appdefined
)
5660 ns_send_appdefined
(-1);
5664 - (void
)mouseDragged
: (NSEvent
*)e
5666 NSTRACE
(mouseDragged
);
5667 [self mouseMoved
: e
];
5671 - (void
)rightMouseDragged
: (NSEvent
*)e
5673 NSTRACE
(rightMouseDragged
);
5674 [self mouseMoved
: e
];
5678 - (void
)otherMouseDragged
: (NSEvent
*)e
5680 NSTRACE
(otherMouseDragged
);
5681 [self mouseMoved
: e
];
5685 - (BOOL
)windowShouldClose
: (id
)sender
5687 NSEvent
*e
=[[self window
] currentEvent
];
5689 NSTRACE
(windowShouldClose
);
5690 windowClosing
= YES
;
5693 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5694 emacs_event
->modifiers
= 0;
5695 emacs_event
->code
= 0;
5697 /* Don't close this window, let this be done from lisp code. */
5701 - (void
) updateFrameSize
: (BOOL
) delay
;
5703 NSWindow
*window
= [self window
];
5704 NSRect wr
= [window frame
];
5706 int oldc
= cols
, oldr
= rows
;
5707 int oldw
= FRAME_PIXEL_WIDTH
(emacsframe
);
5708 int oldh
= FRAME_PIXEL_HEIGHT
(emacsframe
);
5711 NSTRACE
(updateFrameSize
);
5712 NSTRACE_SIZE
("Original
size"
, NSMakeSize
(oldw
, oldh
));
5714 if (! [self isFullscreen
])
5716 #ifdef NS_IMPL_GNUSTEP
5717 // GNUStep does not always update the tool
bar height. Force it.
5718 if (toolbar
) update_frame_tool_bar
(emacsframe
);
5721 extra
= FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5722 + FRAME_TOOLBAR_HEIGHT
(emacsframe
);
5725 neww
= (int
)wr.
size.width
- emacsframe
->border_width
;
5726 newh
= (int
)wr.
size.height
- extra
;
5728 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
, neww
);
5729 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, newh
);
5731 if (cols
< MINWIDTH
)
5734 if (rows
< MINHEIGHT
)
5737 if (oldr
!= rows || oldc
!= cols || neww
!= oldw || newh
!= oldh
)
5739 NSView
*view = FRAME_NS_VIEW
(emacsframe
);
5740 NSWindow
*win
= [view window
];
5741 NSSize sz
= [win resizeIncrements
];
5743 change_frame_size
(emacsframe
,
5744 FRAME_PIXEL_TO_TEXT_WIDTH
(emacsframe
, neww
),
5745 FRAME_PIXEL_TO_TEXT_HEIGHT
(emacsframe
, newh
),
5747 SET_FRAME_GARBAGED
(emacsframe
);
5748 cancel_mouse_face
(emacsframe
);
5750 // Did resize increments change because of a font change?
5751 if (sz.width
!= FRAME_COLUMN_WIDTH
(emacsframe
) ||
5752 sz.height
!= FRAME_LINE_HEIGHT
(emacsframe
))
5754 sz.width
= FRAME_COLUMN_WIDTH
(emacsframe
);
5755 sz.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5756 [win setResizeIncrements
: sz
];
5758 NSTRACE_SIZE
("New
size"
, NSMakeSize
(neww
, newh
));
5761 [view setFrame
: NSMakeRect
(0, 0, neww
, newh
)];
5762 [self windowDidMove
:nil
]; // Update top
/left.
5766 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5767 /* normalize frame to gridded text size */
5771 NSTRACE
(windowWillResize
);
5772 NSTRACE_SIZE
("Original
size"
, frameSize
);
5773 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5775 if (fs_state
== FULLSCREEN_MAXIMIZED
5776 && (maximized_width
!= (int
)frameSize.width
5777 || maximized_height
!= (int
)frameSize.height
))
5778 [self setFSValue
: FULLSCREEN_NONE
];
5779 else if (fs_state
== FULLSCREEN_WIDTH
5780 && maximized_width
!= (int
)frameSize.width
)
5781 [self setFSValue
: FULLSCREEN_NONE
];
5782 else if (fs_state
== FULLSCREEN_HEIGHT
5783 && maximized_height
!= (int
)frameSize.height
)
5784 [self setFSValue
: FULLSCREEN_NONE
];
5785 if (fs_state
== FULLSCREEN_NONE
)
5786 maximized_width
= maximized_height
= -1;
5788 if (! [self isFullscreen
])
5790 extra
= FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5791 + FRAME_TOOLBAR_HEIGHT
(emacsframe
);
5794 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
, frameSize.width
);
5795 if (cols
< MINWIDTH
)
5798 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
,
5799 frameSize.height
- extra
);
5800 if (rows
< MINHEIGHT
)
5802 #ifdef NS_IMPL_COCOA
5804 /* this sets window title to have size in it; the wm does this under GS */
5805 NSRect r
= [[self window
] frame
];
5806 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5814 else if (fs_state
== FULLSCREEN_NONE
&& ! maximizing_resize
)
5817 NSWindow
*window
= [self window
];
5820 char *t
= strdup
([[[self window
] title] UTF8String
]);
5821 char *pos
= strstr
(t
, " — "
);
5826 size_title
= xmalloc
(strlen
(old_title
) + 40);
5827 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5828 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5833 #endif
/* NS_IMPL_COCOA */
5834 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5840 - (void
)windowDidResize
: (NSNotification
*)notification
5842 if (! [self fsIsNative
])
5844 NSWindow
*theWindow
= [notification object
];
5845 /* We can get notification on the non-FS window when in
5847 if ([self window
] != theWindow
) return;
5850 #ifdef NS_IMPL_GNUSTEP
5851 NSWindow
*theWindow
= [notification object
];
5853 /* In GNUstep, at least currently, it's possible to get a didResize
5854 without getting a willResize.. therefore we need to act as if we got
5855 the willResize now */
5856 NSSize sz
= [theWindow frame
].
size;
5857 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5858 #endif
/* NS_IMPL_GNUSTEP */
5860 NSTRACE
(windowDidResize
);
5861 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5863 if (cols
> 0 && rows
> 0)
5865 [self updateFrameSize
: YES
];
5868 ns_send_appdefined
(-1);
5871 #ifdef NS_IMPL_COCOA
5872 - (void
)viewDidEndLiveResize
5874 [super viewDidEndLiveResize
];
5877 [[self window
] setTitle
: [NSString stringWithUTF8String
: old_title
]];
5881 maximizing_resize
= NO
;
5883 #endif
/* NS_IMPL_COCOA */
5886 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5887 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5889 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(emacsframe
);
5890 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5892 NSTRACE
(windowDidBecomeKey
);
5894 if (emacsframe
!= old_focus
)
5895 dpyinfo
->x_focus_frame
= emacsframe
;
5897 ns_frame_rehighlight
(emacsframe
);
5901 emacs_event
->kind
= FOCUS_IN_EVENT
;
5902 EV_TRAILER
((id
)nil
);
5907 - (void
)windowDidResignKey
: (NSNotification
*)notification
5908 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5910 struct ns_display_info
*dpyinfo
= FRAME_DISPLAY_INFO
(emacsframe
);
5911 BOOL is_focus_frame
= dpyinfo
->x_focus_frame
== emacsframe
;
5912 NSTRACE
(windowDidResignKey
);
5915 dpyinfo
->x_focus_frame
= 0;
5917 ns_frame_rehighlight
(emacsframe
);
5919 /* FIXME: for some reason needed on second and subsequent clicks away
5920 from sole-frame Emacs to get hollow box to show */
5921 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5923 x_update_cursor
(emacsframe
, 1);
5924 x_set_frame_alpha
(emacsframe
);
5927 if (emacs_event
&& is_focus_frame
)
5929 [self deleteWorkingText
];
5930 emacs_event
->kind
= FOCUS_OUT_EVENT
;
5931 EV_TRAILER
((id
)nil
);
5936 - (void
)windowWillMiniaturize
: sender
5938 NSTRACE
(windowWillMiniaturize
);
5954 - initFrameFromEmacs
: (struct frame
*)f
5963 NSTRACE
(initFrameFromEmacs
);
5966 processingCompose
= NO
;
5967 scrollbarsNeedingUpdate
= 0;
5968 fs_state
= FULLSCREEN_NONE
;
5969 fs_before_fs
= next_maximized
= -1;
5970 #ifdef HAVE_NATIVE_FS
5971 fs_is_native
= ns_use_native_fullscreen
;
5975 maximized_width
= maximized_height
= -1;
5978 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5980 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5981 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5982 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5983 [self initWithFrame
: r
];
5984 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5986 FRAME_NS_VIEW
(f
) = self
;
5988 #ifdef NS_IMPL_COCOA
5990 maximizing_resize
= NO
;
5993 win
= [[EmacsWindow alloc
]
5994 initWithContentRect
: r
5995 styleMask
: (NSResizableWindowMask |
5996 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5997 NSTitledWindowMask |
5999 NSMiniaturizableWindowMask |
6000 NSClosableWindowMask
)
6001 backing
: NSBackingStoreBuffered
6004 #ifdef HAVE_NATIVE_FS
6005 [win setCollectionBehavior
:NSWindowCollectionBehaviorFullScreenPrimary
];
6009 bwidth
= f
->border_width
= wr.
size.width
- r.
size.width
;
6010 tibar_height
= FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
6012 [win setAcceptsMouseMovedEvents
: YES
];
6013 [win setDelegate
: self
];
6014 [win useOptimizedDrawing
: YES
];
6016 sz.width
= FRAME_COLUMN_WIDTH
(f
);
6017 sz.height
= FRAME_LINE_HEIGHT
(f
);
6018 [win setResizeIncrements
: sz
];
6020 [[win contentView
] addSubview
: self
];
6023 [self registerForDraggedTypes
: ns_drag_types
];
6026 name
= [NSString stringWithUTF8String
:
6027 NILP
(tem
) ? "Emacs"
: SSDATA
(tem
)];
6028 [win setTitle
: name
];
6030 /* toolbar support */
6031 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
6032 [NSString stringWithFormat
: @"Emacs Frame
%d",
6034 [win setToolbar
: toolbar
];
6035 [toolbar setVisible
: NO
];
6036 #ifdef NS_IMPL_COCOA
6038 NSButton
*toggleButton
;
6039 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
6040 [toggleButton setTarget
: self
];
6041 [toggleButton setAction
: @selector
(toggleToolbar
: )];
6044 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
6048 [win setMiniwindowTitle
:
6049 [NSString stringWithUTF8String
: SSDATA
(tem
)]];
6052 NSScreen
*screen
= [win screen
];
6055 [win setFrameTopLeftPoint
: NSMakePoint
6056 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
6057 IN_BOUND
(-SCREENMAX
,
6058 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
6061 [win makeFirstResponder
: self
];
6063 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
6064 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
6065 [win setBackgroundColor
: col
];
6066 if ([col alphaComponent
] != (EmacsCGFloat
) 1.0)
6067 [win setOpaque
: NO
];
6069 [self allocateGState
];
6071 [NSApp registerServicesMenuSendTypes
: ns_send_types
6079 - (void
)windowDidMove
: sender
6081 NSWindow
*win
= [self window
];
6082 NSRect r
= [win frame
];
6083 NSArray
*screens
= [NSScreen screens
];
6084 NSScreen
*screen
= [screens objectAtIndex
: 0];
6086 NSTRACE
(windowDidMove
);
6088 if (!emacsframe
->output_data.ns
)
6092 emacsframe
->left_pos
= r.origin.x
;
6093 emacsframe
->top_pos
=
6094 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
6099 /* Called AFTER method below, but before our windowWillResize call there leads
6100 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
6101 location so set_window_size moves the frame. */
6102 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
6104 emacsframe
->output_data.ns
->zooming
= 1;
6109 /* Override to do something slightly nonstandard, but nice. First click on
6110 zoom button will zoom vertically. Second will zoom completely. Third
6111 returns to original. */
6112 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
6113 defaultFrame
:(NSRect
)defaultFrame
6115 NSRect result
= [sender frame
];
6117 NSTRACE
(windowWillUseStandardFrame
);
6119 if (fs_before_fs
!= -1) /* Entering fullscreen */
6121 result
= defaultFrame
;
6123 else if (next_maximized
== FULLSCREEN_HEIGHT
6124 ||
(next_maximized
== -1
6125 && abs (defaultFrame.
size.height
- result.
size.height
)
6126 > FRAME_LINE_HEIGHT
(emacsframe
)))
6129 ns_userRect
= result
;
6130 maximized_height
= result.
size.height
= defaultFrame.
size.height
;
6131 maximized_width
= -1;
6132 result.origin.y
= defaultFrame.origin.y
;
6133 [self setFSValue
: FULLSCREEN_HEIGHT
];
6134 #ifdef NS_IMPL_COCOA
6135 maximizing_resize
= YES
;
6138 else if (next_maximized
== FULLSCREEN_WIDTH
)
6140 ns_userRect
= result
;
6141 maximized_width
= result.
size.width
= defaultFrame.
size.width
;
6142 maximized_height
= -1;
6143 result.origin.x
= defaultFrame.origin.x
;
6144 [self setFSValue
: FULLSCREEN_WIDTH
];
6146 else if (next_maximized
== FULLSCREEN_MAXIMIZED
6147 ||
(next_maximized
== -1
6148 && abs (defaultFrame.
size.width
- result.
size.width
)
6149 > FRAME_COLUMN_WIDTH
(emacsframe
)))
6151 result
= defaultFrame
; /* second click */
6152 maximized_width
= result.
size.width
;
6153 maximized_height
= result.
size.height
;
6154 [self setFSValue
: FULLSCREEN_MAXIMIZED
];
6155 #ifdef NS_IMPL_COCOA
6156 maximizing_resize
= YES
;
6162 result
= ns_userRect.
size.height ? ns_userRect
: result
;
6163 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
6164 #ifdef NS_IMPL_COCOA
6165 maximizing_resize
= fs_state
!= FULLSCREEN_NONE
;
6167 [self setFSValue
: FULLSCREEN_NONE
];
6168 maximized_width
= maximized_height
= -1;
6171 if (fs_before_fs
== -1) next_maximized
= -1;
6172 [self windowWillResize
: sender toSize
: result.
size];
6177 - (void
)windowDidDeminiaturize
: sender
6179 NSTRACE
(windowDidDeminiaturize
);
6180 if (!emacsframe
->output_data.ns
)
6183 SET_FRAME_ICONIFIED
(emacsframe
, 0);
6184 SET_FRAME_VISIBLE
(emacsframe
, 1);
6185 windows_or_buffers_changed
= 63;
6189 emacs_event
->kind
= DEICONIFY_EVENT
;
6190 EV_TRAILER
((id
)nil
);
6195 - (void
)windowDidExpose
: sender
6197 NSTRACE
(windowDidExpose
);
6198 if (!emacsframe
->output_data.ns
)
6201 SET_FRAME_VISIBLE
(emacsframe
, 1);
6202 SET_FRAME_GARBAGED
(emacsframe
);
6204 if (send_appdefined
)
6205 ns_send_appdefined
(-1);
6209 - (void
)windowDidMiniaturize
: sender
6211 NSTRACE
(windowDidMiniaturize
);
6212 if (!emacsframe
->output_data.ns
)
6215 SET_FRAME_ICONIFIED
(emacsframe
, 1);
6216 SET_FRAME_VISIBLE
(emacsframe
, 0);
6220 emacs_event
->kind
= ICONIFY_EVENT
;
6221 EV_TRAILER
((id
)nil
);
6225 #ifdef HAVE_NATIVE_FS
6226 - (NSApplicationPresentationOptions
)window
:(NSWindow
*)window
6227 willUseFullScreenPresentationOptions
:
6228 (NSApplicationPresentationOptions
)proposedOptions
6230 return proposedOptions|NSApplicationPresentationAutoHideToolbar
;
6234 - (void
)windowWillEnterFullScreen
:(NSNotification
*)notification
6236 fs_before_fs
= fs_state
;
6239 - (void
)windowDidEnterFullScreen
:(NSNotification
*)notification
6241 [self setFSValue
: FULLSCREEN_BOTH
];
6242 if (! [self fsIsNative
])
6244 [self windowDidBecomeKey
:notification
];
6245 [nonfs_window orderOut
:self
];
6249 BOOL tbar_visible
= FRAME_EXTERNAL_TOOL_BAR
(emacsframe
) ? YES
: NO
;
6250 #ifdef NS_IMPL_COCOA
6251 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
6252 unsigned val
= (unsigned
)[NSApp presentationOptions
];
6254 // OSX
10.7 bug
fix, the
menu won
't appear without this.
6255 // val is non-zero on other OSX versions.
6258 NSApplicationPresentationOptions options
6259 = NSApplicationPresentationAutoHideDock
6260 | NSApplicationPresentationAutoHideMenuBar
6261 | NSApplicationPresentationFullScreen
6262 | NSApplicationPresentationAutoHideToolbar;
6264 [NSApp setPresentationOptions: options];
6268 [toolbar setVisible:tbar_visible];
6272 - (void)windowWillExitFullScreen:(NSNotification *)notification
6274 if (next_maximized != -1)
6275 fs_before_fs = next_maximized;
6278 - (void)windowDidExitFullScreen:(NSNotification *)notification
6280 [self setFSValue: fs_before_fs];
6282 #ifdef HAVE_NATIVE_FS
6283 [self updateCollectionBehaviour];
6285 if (FRAME_EXTERNAL_TOOL_BAR (emacsframe))
6287 [toolbar setVisible:YES];
6288 update_frame_tool_bar (emacsframe);
6289 [self updateFrameSize:YES];
6290 [[self window] display];
6293 [toolbar setVisible:NO];
6295 if (next_maximized != -1)
6296 [[self window] performZoom:self];
6301 return fs_is_native;
6304 - (BOOL)isFullscreen
6306 if (! fs_is_native) return nonfs_window != nil;
6307 #ifdef HAVE_NATIVE_FS
6308 return ([[self window] styleMask] & NSFullScreenWindowMask) != 0;
6314 #ifdef HAVE_NATIVE_FS
6315 - (void)updateCollectionBehaviour
6317 if (! [self isFullscreen])
6319 NSWindow *win = [self window];
6320 NSWindowCollectionBehavior b = [win collectionBehavior];
6321 if (ns_use_native_fullscreen)
6322 b |= NSWindowCollectionBehaviorFullScreenPrimary;
6324 b &= ~NSWindowCollectionBehaviorFullScreenPrimary;
6326 [win setCollectionBehavior: b];
6327 fs_is_native = ns_use_native_fullscreen;
6332 - (void)toggleFullScreen: (id)sender
6343 #ifdef HAVE_NATIVE_FS
6344 [[self window] toggleFullScreen:sender];
6350 onFirstScreen = [[w screen] isEqual:[[NSScreen screens] objectAtIndex:0]];
6353 col = ns_lookup_indexed_color (NS_FACE_BACKGROUND
6354 (FRAME_DEFAULT_FACE (f)),
6357 sz.width = FRAME_COLUMN_WIDTH (f);
6358 sz.height = FRAME_LINE_HEIGHT (f);
6360 if (fs_state != FULLSCREEN_BOTH)
6362 /* Hide dock and menubar if we are on the primary screen. */
6365 #if defined (NS_IMPL_COCOA) && \
6366 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
6367 NSApplicationPresentationOptions options
6368 = NSApplicationPresentationAutoHideDock
6369 | NSApplicationPresentationAutoHideMenuBar;
6371 [NSApp setPresentationOptions: options];
6373 [NSMenu setMenuBarVisible:NO];
6377 fw = [[EmacsFSWindow alloc]
6378 initWithContentRect:[w contentRectForFrameRect:wr]
6379 styleMask:NSBorderlessWindowMask
6380 backing:NSBackingStoreBuffered
6384 [fw setContentView:[w contentView]];
6385 [fw setTitle:[w title]];
6386 [fw setDelegate:self];
6387 [fw setAcceptsMouseMovedEvents: YES];
6388 [fw useOptimizedDrawing: YES];
6389 [fw setResizeIncrements: sz];
6390 [fw setBackgroundColor: col];
6391 if ([col alphaComponent] != (EmacsCGFloat) 1.0)
6394 f->border_width = 0;
6395 FRAME_NS_TITLEBAR_HEIGHT (f) = 0;
6396 tobar_height = FRAME_TOOLBAR_HEIGHT (f);
6397 FRAME_TOOLBAR_HEIGHT (f) = 0;
6401 [self windowWillEnterFullScreen:nil];
6402 [fw makeKeyAndOrderFront:NSApp];
6403 [fw makeFirstResponder:self];
6405 r = [fw frameRectForContentRect:[[fw screen] frame]];
6406 [fw setFrame: r display:YES animate:YES];
6407 [self windowDidEnterFullScreen:nil];
6418 #if defined (NS_IMPL_COCOA) && \
6419 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
6420 [NSApp setPresentationOptions: NSApplicationPresentationDefault];
6422 [NSMenu setMenuBarVisible:YES];
6426 [w setContentView:[fw contentView]];
6427 [w setResizeIncrements: sz];
6428 [w setBackgroundColor: col];
6429 if ([col alphaComponent] != (EmacsCGFloat) 1.0)
6432 f->border_width = bwidth;
6433 FRAME_NS_TITLEBAR_HEIGHT (f) = tibar_height;
6434 if (FRAME_EXTERNAL_TOOL_BAR (f))
6435 FRAME_TOOLBAR_HEIGHT (f) = tobar_height;
6437 [self windowWillExitFullScreen:nil];
6438 [fw setFrame: [w frame] display:YES animate:YES];
6440 [w makeKeyAndOrderFront:NSApp];
6441 [self windowDidExitFullScreen:nil];
6442 [self updateFrameSize:YES];
6448 if (fs_state != emacsframe->want_fullscreen)
6450 if (fs_state == FULLSCREEN_BOTH)
6452 [self toggleFullScreen:self];
6455 switch (emacsframe->want_fullscreen)
6457 case FULLSCREEN_BOTH:
6458 [self toggleFullScreen:self];
6460 case FULLSCREEN_WIDTH:
6461 next_maximized = FULLSCREEN_WIDTH;
6462 if (fs_state != FULLSCREEN_BOTH)
6463 [[self window] performZoom:self];
6465 case FULLSCREEN_HEIGHT:
6466 next_maximized = FULLSCREEN_HEIGHT;
6467 if (fs_state != FULLSCREEN_BOTH)
6468 [[self window] performZoom:self];
6470 case FULLSCREEN_MAXIMIZED:
6471 next_maximized = FULLSCREEN_MAXIMIZED;
6472 if (fs_state != FULLSCREEN_BOTH)
6473 [[self window] performZoom:self];
6475 case FULLSCREEN_NONE:
6476 if (fs_state != FULLSCREEN_BOTH)
6478 next_maximized = FULLSCREEN_NONE;
6479 [[self window] performZoom:self];
6484 emacsframe->want_fullscreen = FULLSCREEN_NONE;
6489 - (void) setFSValue: (int)value
6491 Lisp_Object lval = Qnil;
6494 case FULLSCREEN_BOTH:
6497 case FULLSCREEN_WIDTH:
6500 case FULLSCREEN_HEIGHT:
6503 case FULLSCREEN_MAXIMIZED:
6507 store_frame_param (emacsframe, Qfullscreen, lval);
6511 - (void)mouseEntered: (NSEvent *)theEvent
6513 NSTRACE (mouseEntered);
6515 FRAME_DISPLAY_INFO (emacsframe)->last_mouse_movement_time
6516 = EV_TIMESTAMP (theEvent);
6520 - (void)mouseExited: (NSEvent *)theEvent
6522 Mouse_HLInfo *hlinfo = emacsframe ? MOUSE_HL_INFO (emacsframe) : NULL;
6524 NSTRACE (mouseExited);
6529 FRAME_DISPLAY_INFO (emacsframe)->last_mouse_movement_time
6530 = EV_TIMESTAMP (theEvent);
6532 if (emacsframe == hlinfo->mouse_face_mouse_frame)
6534 clear_mouse_face (hlinfo);
6535 hlinfo->mouse_face_mouse_frame = 0;
6543 if (context_menu_value == -1)
6544 context_menu_value = [sender tag];
6547 NSInteger tag = [sender tag];
6548 find_and_call_menu_selection (emacsframe, emacsframe->menu_bar_items_used,
6549 emacsframe->menu_bar_vector,
6553 ns_send_appdefined (-1);
6558 - (EmacsToolbar *)toolbar
6564 /* this gets called on toolbar button click */
6565 - toolbarClicked: (id)item
6568 int idx = [item tag] * TOOL_BAR_ITEM_NSLOTS;
6570 NSTRACE (toolbarClicked);
6575 /* send first event (for some reason two needed) */
6576 theEvent = [[self window] currentEvent];
6577 emacs_event->kind = TOOL_BAR_EVENT;
6578 XSETFRAME (emacs_event->arg, emacsframe);
6579 EV_TRAILER (theEvent);
6581 emacs_event->kind = TOOL_BAR_EVENT;
6582 /* XSETINT (emacs_event->code, 0); */
6583 emacs_event->arg = AREF (emacsframe->tool_bar_items,
6584 idx + TOOL_BAR_ITEM_KEY);
6585 emacs_event->modifiers = EV_MODIFIERS (theEvent);
6586 EV_TRAILER (theEvent);
6591 - toggleToolbar: (id)sender
6596 emacs_event->kind = NS_NONKEY_EVENT;
6597 emacs_event->code = KEY_NS_TOGGLE_TOOLBAR;
6598 EV_TRAILER ((id)nil);
6603 - (void)drawRect: (NSRect)rect
6605 int x = NSMinX (rect), y = NSMinY (rect);
6606 int width = NSWidth (rect), height = NSHeight (rect);
6610 if (!emacsframe || !emacsframe->output_data.ns)
6613 ns_clear_frame_area (emacsframe, x, y, width, height);
6614 expose_frame (emacsframe, x, y, width, height);
6617 drawRect: may be called (at least in OS X 10.5) for invisible
6618 views as well for some reason. Thus, do not infer visibility
6621 emacsframe->async_visible = 1;
6622 emacsframe->async_iconified = 0;
6627 /* NSDraggingDestination protocol methods. Actually this is not really a
6628 protocol, but a category of Object. O well... */
6630 -(NSUInteger) draggingEntered: (id <NSDraggingInfo>) sender
6632 NSTRACE (draggingEntered);
6633 return NSDragOperationGeneric;
6637 -(BOOL)prepareForDragOperation: (id <NSDraggingInfo>) sender
6643 -(BOOL)performDragOperation: (id <NSDraggingInfo>) sender
6648 NSEvent *theEvent = [[self window] currentEvent];
6651 NSTRACE (performDragOperation);
6656 position = [self convertPoint: [sender draggingLocation] fromView: nil];
6657 x = lrint (position.x); y = lrint (position.y);
6659 pb = [sender draggingPasteboard];
6660 type = [pb availableTypeFromArray: ns_drag_types];
6665 else if ([type isEqualToString: NSFilenamesPboardType])
6668 NSEnumerator *fenum;
6671 if (!(files = [pb propertyListForType: type]))
6674 fenum = [files objectEnumerator];
6675 while ( (file = [fenum nextObject]) )
6677 emacs_event->kind = NS_NONKEY_EVENT;
6678 emacs_event->code = KEY_NS_DRAG_FILE;
6679 XSETINT (emacs_event->x, x);
6680 XSETINT (emacs_event->y, y);
6681 ns_input_file = append2 (ns_input_file,
6682 build_string ([file UTF8String]));
6683 emacs_event->modifiers = EV_MODIFIERS (theEvent);
6684 EV_TRAILER (theEvent);
6688 else if ([type isEqualToString: NSURLPboardType])
6693 if (!(fileURL = [NSURL URLFromPasteboard: pb]) ||
6694 [fileURL isFileURL] == NO)
6697 file = [fileURL path];
6698 emacs_event->kind = NS_NONKEY_EVENT;
6699 emacs_event->code = KEY_NS_DRAG_FILE;
6700 XSETINT (emacs_event->x, x);
6701 XSETINT (emacs_event->y, y);
6702 ns_input_file = append2 (ns_input_file, build_string ([file UTF8String]));
6703 emacs_event->modifiers = EV_MODIFIERS (theEvent);
6704 EV_TRAILER (theEvent);
6707 else if ([type isEqualToString: NSStringPboardType]
6708 || [type isEqualToString: NSTabularTextPboardType])
6712 if (! (data = [pb stringForType: type]))
6715 emacs_event->kind = NS_NONKEY_EVENT;
6716 emacs_event->code = KEY_NS_DRAG_TEXT;
6717 XSETINT (emacs_event->x, x);
6718 XSETINT (emacs_event->y, y);
6719 ns_input_text = build_string ([data UTF8String]);
6720 emacs_event->modifiers = EV_MODIFIERS (theEvent);
6721 EV_TRAILER (theEvent);
6724 else if ([type isEqualToString: NSColorPboardType])
6726 NSColor *c = [NSColor colorFromPasteboard: pb];
6727 emacs_event->kind = NS_NONKEY_EVENT;
6728 emacs_event->code = KEY_NS_DRAG_COLOR;
6729 XSETINT (emacs_event->x, x);
6730 XSETINT (emacs_event->y, y);
6731 ns_input_color = ns_color_to_lisp (c);
6732 emacs_event->modifiers = EV_MODIFIERS (theEvent);
6733 EV_TRAILER (theEvent);
6736 else if ([type isEqualToString: NSFontPboardType])
6738 /* impl based on GNUstep NSTextView.m */
6739 NSData *data = [pb dataForType: NSFontPboardType];
6740 NSDictionary *dict = [NSUnarchiver unarchiveObjectWithData: data];
6741 NSFont *font = [dict objectForKey: NSFontAttributeName];
6747 emacs_event->kind = NS_NONKEY_EVENT;
6748 emacs_event->code = KEY_NS_CHANGE_FONT;
6749 XSETINT (emacs_event->x, x);
6750 XSETINT (emacs_event->y, y);
6751 ns_input_font = build_string ([[font fontName] UTF8String]);
6752 snprintf (fontSize, 10, "%f", [font pointSize]);
6753 ns_input_fontsize = build_string (fontSize);
6754 emacs_event->modifiers = EV_MODIFIERS (theEvent);
6755 EV_TRAILER (theEvent);
6760 error ("Invalid data type in dragging pasteboard.");
6766 - (id) validRequestorForSendType: (NSString *)typeSent
6767 returnType: (NSString *)typeReturned
6769 NSTRACE (validRequestorForSendType);
6770 if (typeSent != nil && [ns_send_types indexOfObject: typeSent] != NSNotFound
6771 && typeReturned == nil)
6773 if (! NILP (ns_get_local_selection (QPRIMARY, QUTF8_STRING)))
6777 return [super validRequestorForSendType: typeSent
6778 returnType: typeReturned];
6782 /* The next two methods are part of NSServicesRequests informal protocol,
6783 supposedly called when a services menu item is chosen from this app.
6784 But this should not happen because we override the services menu with our
6785 own entries which call ns-perform-service.
6786 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
6787 So let's at least stub them out until further investigation can be done. */
6789 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
6791 /* we could call ns_string_from_pasteboard(pboard) here but then it should
6792 be written into the buffer in place of the existing selection..
6793 ordinary service calls go through functions defined in ns-win.el */
6797 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
6799 NSArray
*typesDeclared
;
6802 /* We only support NSStringPboardType */
6803 if ([types containsObject
:NSStringPboardType
] == NO
) {
6807 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6808 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
6811 if (CONSP
(val
) && NILP
(XCDR
(val
)))
6814 if (! STRINGP
(val
))
6817 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
6818 [pb declareTypes
:typesDeclared owner
:nil
];
6819 ns_string_to_pasteboard
(pb
, val
);
6824 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
6825 (gives a miniaturized version of the window); currently we use the latter for
6826 frames whose active buffer doesn't correspond to any file
6827 (e.g., '*scratch*') */
6828 - setMiniwindowImage
: (BOOL
) setMini
6830 id
image = [[self window
] miniwindowImage
];
6831 NSTRACE
(setMiniwindowImage
);
6833 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6834 about "AppleDockIconEnabled" notwithstanding, however the set message
6835 below has its effect nonetheless. */
6836 if (image != emacsframe
->output_data.ns
->miniimage
)
6838 if (image && [image isKindOfClass
: [EmacsImage
class]])
6840 [[self window
] setMiniwindowImage
:
6841 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6848 - (void
) setRows
: (int
) r andColumns
: (int
) c
6854 @
end /* EmacsView */
6858 /* ==========================================================================
6860 EmacsWindow implementation
6862 ========================================================================== */
6864 @implementation EmacsWindow
6866 #ifdef NS_IMPL_COCOA
6867 - (id
)accessibilityAttributeValue
:(NSString
*)attribute
6869 Lisp_Object str
= Qnil
;
6870 struct frame
*f
= SELECTED_FRAME
();
6871 struct buffer
*curbuf
= XBUFFER
(XWINDOW
(f
->selected_window
)->contents
);
6873 if ([attribute isEqualToString
:NSAccessibilityRoleAttribute
])
6874 return NSAccessibilityTextFieldRole
;
6876 if ([attribute isEqualToString
:NSAccessibilitySelectedTextAttribute
]
6877 && curbuf
&& ! NILP
(BVAR
(curbuf
, mark_active
)))
6879 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6881 else if (curbuf
&& [attribute isEqualToString
:NSAccessibilityValueAttribute
])
6883 if (! NILP
(BVAR
(curbuf
, mark_active
)))
6884 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6888 ptrdiff_t start_byte
= BUF_BEGV_BYTE
(curbuf
);
6889 ptrdiff_t byte_range
= BUF_ZV_BYTE
(curbuf
) - start_byte
;
6890 ptrdiff_t range
= BUF_ZV
(curbuf
) - BUF_BEGV
(curbuf
);
6892 if (! NILP
(BVAR
(curbuf
, enable_multibyte_characters
)))
6893 str
= make_uninit_multibyte_string
(range
, byte_range
);
6895 str
= make_uninit_string
(range
);
6896 /* To check: This returns emacs-utf-8, which is a superset of utf-8.
6897 Is this a problem? */
6898 memcpy
(SDATA
(str
), BYTE_POS_ADDR
(start_byte
), byte_range
);
6905 if (CONSP
(str
) && SYMBOLP
(XCAR
(str
)))
6908 if (CONSP
(str
) && NILP
(XCDR
(str
)))
6913 const
char *utfStr
= SSDATA
(str
);
6914 NSString
*nsStr
= [NSString stringWithUTF8String
: utfStr
];
6919 return [super accessibilityAttributeValue
:attribute
];
6921 #endif
/* NS_IMPL_COCOA */
6923 /* If we have multiple monitors, one above the other, we don't want to
6924 restrict the height to just one monitor. So we override this. */
6925 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6927 /* When making the frame visible for the first time or if there is just
6928 one screen, we want to constrain. Other times not. */
6929 NSUInteger nr_screens
= [[NSScreen screens
] count
];
6930 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6931 NSTRACE
(constrainFrameRect
);
6932 NSTRACE_RECT
("
input"
, frameRect
);
6934 if (ns_menu_bar_should_be_hidden
())
6937 /* The default implementation does two things 1) ensure that the top
6938 of the rectangle is below the menu bar (or below the top of the
6939 screen) and 2) resizes windows larger than the screen. As we
6940 don't want the latter, a smaller rectangle is used. */
6941 #define FAKE_HEIGHT
64
6942 float old_top
= frameRect.origin.y
+ frameRect.
size.height
;
6944 r.
size.height
= FAKE_HEIGHT
;
6945 r.
size.width
= frameRect.
size.width
;
6946 r.origin.x
= frameRect.origin.x
;
6947 r.origin.y
= old_top
- FAKE_HEIGHT
;
6949 NSTRACE_RECT
("
input to super"
, r
);
6951 r
= [super constrainFrameRect
:r toScreen
:screen
];
6953 NSTRACE_RECT
("output from super"
, r
);
6955 float new_top
= r.origin.y
+ FAKE_HEIGHT
;
6956 if (new_top
< old_top
)
6958 frameRect.origin.y
= new_top
- frameRect.
size.height
;
6961 NSTRACE_RECT
("output"
, frameRect
);
6967 @
end /* EmacsWindow */
6970 @implementation EmacsFSWindow
6972 - (BOOL
)canBecomeKeyWindow
6977 - (BOOL
)canBecomeMainWindow
6984 /* ==========================================================================
6986 EmacsScroller implementation
6988 ========================================================================== */
6991 @implementation EmacsScroller
6993 /* for repeat button push */
6994 #define SCROLL_BAR_FIRST_DELAY
0.5
6995 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6997 + (CGFloat
) scrollerWidth
6999 /* TODO: if we want to allow variable widths, this is the place to do it,
7000 however neither GNUstep nor Cocoa support it very well */
7001 return [NSScroller scrollerWidth
];
7005 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
7007 NSTRACE
(EmacsScroller_initFrame
);
7009 r.
size.width
= [EmacsScroller scrollerWidth
];
7010 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
7011 [self setContinuous
: YES
];
7012 [self setEnabled
: YES
];
7014 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
7015 locked against the top and bottom edges, and right edge on OS X, where
7016 scrollers are on right. */
7017 #ifdef NS_IMPL_GNUSTEP
7018 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
7020 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
7025 pixel_height
= NSHeight
(r
);
7026 if (pixel_height
== 0) pixel_height
= 1;
7027 min_portion
= 20 / pixel_height
;
7029 frame
= XFRAME
(XWINDOW
(win
)->frame
);
7030 if (FRAME_LIVE_P
(frame
))
7033 EmacsView
*view = FRAME_NS_VIEW
(frame
);
7034 NSView
*sview
= [[view window
] contentView
];
7035 NSArray
*subs
= [sview subviews
];
7037 /* disable optimization stopping redraw of other scrollbars */
7038 view->scrollbarsNeedingUpdate
= 0;
7039 for (i
=[subs count
]-1; i
>= 0; i
--)
7040 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
7041 view->scrollbarsNeedingUpdate
++;
7042 [sview addSubview
: self
];
7045 /* [self setFrame: r]; */
7051 - (void
)setFrame
: (NSRect
)newRect
7053 NSTRACE
(EmacsScroller_setFrame
);
7054 /* block_input (); */
7055 pixel_height
= NSHeight
(newRect
);
7056 if (pixel_height
== 0) pixel_height
= 1;
7057 min_portion
= 20 / pixel_height
;
7058 [super setFrame
: newRect
];
7060 /* unblock_input (); */
7066 NSTRACE
(EmacsScroller_dealloc
);
7068 wset_vertical_scroll_bar
(XWINDOW
(win
), Qnil
);
7096 /* ensure other scrollbar updates after deletion */
7097 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
7099 view->scrollbarsNeedingUpdate
++;
7100 [self removeFromSuperview
];
7108 - (void
)resetCursorRects
7110 NSRect visible
= [self visibleRect
];
7111 NSTRACE
(resetCursorRects
);
7113 if (!NSIsEmptyRect
(visible
))
7114 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
7115 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
7119 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
7122 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
7123 && portion
!= whole
; /* needed for resize empty buf */
7127 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
7129 NSTRACE
(setPosition
);
7131 em_position
= position
;
7132 em_portion
= portion
;
7135 if (portion
>= whole
)
7137 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
7138 [self setKnobProportion
: 1.0];
7139 [self setDoubleValue
: 1.0];
7141 [self setFloatValue
: 0.0 knobProportion
: 1.0];
7148 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
7149 pos
= (float
)position
/ (whole
- portion
);
7150 por
= (CGFloat
)portion
/whole
;
7151 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
7152 [self setKnobProportion
: por
];
7153 [self setDoubleValue
: pos
];
7155 [self setFloatValue
: pos knobProportion
: por
];
7159 /* Events may come here even if the event loop is not running.
7160 If we don't enter the event loop, the scroll bar will not update.
7161 So send SIGIO to ourselves. */
7162 if (apploopnr
== 0) raise
(SIGIO
);
7167 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
7168 drag events will go directly to the EmacsScroller. Leaving in for now. */
7169 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
7170 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
7172 *part
= last_hit_part
;
7174 XSETINT
(*y
, pixel_height
);
7175 if ([self floatValue
] > 0.999F
)
7176 XSETINT
(*x
, pixel_height
);
7178 XSETINT
(*x
, pixel_height
* [self floatValue
]);
7182 /* set up emacs_event */
7183 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
7188 emacs_event
->part
= last_hit_part
;
7189 emacs_event
->code
= 0;
7190 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
7191 emacs_event
->frame_or_window
= win
;
7192 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
7193 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
7194 emacs_event
->arg
= Qnil
;
7195 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
7196 XSETINT
(emacs_event
->y
, pixel_height
-20);
7200 n_emacs_events_pending
++;
7201 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
7204 hold_event
(emacs_event
);
7205 EVENT_INIT
(*emacs_event
);
7206 ns_send_appdefined
(-1);
7210 /* called manually thru timer to implement repeated button action w/hold-down */
7211 - repeatScroll
: (NSTimer
*)scrollEntry
7213 NSEvent
*e
= [[self window
] currentEvent
];
7214 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
7215 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
7217 /* clear timer if need be */
7218 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
7220 [scroll_repeat_entry invalidate
];
7221 [scroll_repeat_entry release
];
7222 scroll_repeat_entry
= nil
;
7228 = [[NSTimer scheduledTimerWithTimeInterval
:
7229 SCROLL_BAR_CONTINUOUS_DELAY
7231 selector
: @selector
(repeatScroll
:)
7237 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
7242 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
7243 mouseDragged events without going into a modal loop. */
7244 - (void
)mouseDown
: (NSEvent
*)e
7247 /* hitPart is only updated AFTER event is passed on */
7248 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
7249 CGFloat inc
= 0.0, loc
, kloc
, pos
;
7252 NSTRACE
(EmacsScroller_mouseDown
);
7256 case NSScrollerDecrementPage
:
7257 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
7258 case NSScrollerIncrementPage
:
7259 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
7260 case NSScrollerDecrementLine
:
7261 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
7262 case NSScrollerIncrementLine
:
7263 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
7264 case NSScrollerKnob
:
7265 last_hit_part
= scroll_bar_handle
; break;
7266 case NSScrollerKnobSlot
: /* GNUstep-only */
7267 last_hit_part
= scroll_bar_move_ratio
; break;
7268 default
: /* NSScrollerNoPart? */
7269 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
7276 pos
= 0; /* ignored */
7278 /* set a timer to repeat, as we can't let superclass do this modally */
7280 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
7282 selector
: @selector
(repeatScroll
:)
7289 /* handle, or on GNUstep possibly slot */
7290 NSEvent
*fake_event
;
7292 /* compute float loc in slot and mouse offset on knob */
7293 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
7295 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
7301 else if (loc
>= NSHeight
(sr
))
7303 loc
= NSHeight
(sr
);
7311 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
7313 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
7315 last_mouse_offset
= kloc
;
7317 /* if knob, tell emacs a location offset by knob pos
7318 (to indicate top of handle) */
7319 if (part
== NSScrollerKnob
)
7320 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
7322 /* else this is a slot click on GNUstep: go straight there */
7323 pos
= loc
/ NSHeight
(sr
);
7325 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
7326 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
7327 location
: [e locationInWindow
]
7328 modifierFlags
: [e modifierFlags
]
7329 timestamp
: [e timestamp
]
7330 windowNumber
: [e windowNumber
]
7331 context
: [e context
]
7332 eventNumber
: [e eventNumber
]
7333 clickCount
: [e clickCount
]
7334 pressure
: [e pressure
]];
7335 [super mouseUp
: fake_event
];
7338 if (part
!= NSScrollerKnob
)
7339 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
7343 /* Called as we manually track scroller drags, rather than superclass. */
7344 - (void
)mouseDragged
: (NSEvent
*)e
7349 NSTRACE
(EmacsScroller_mouseDragged
);
7351 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
7353 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
7359 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
7361 loc
= NSHeight
(sr
) + last_mouse_offset
;
7364 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
7365 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
7369 - (void
)mouseUp
: (NSEvent
*)e
7371 if (scroll_repeat_entry
)
7373 [scroll_repeat_entry invalidate
];
7374 [scroll_repeat_entry release
];
7375 scroll_repeat_entry
= nil
;
7381 /* treat scrollwheel events in the bar as though they were in the main window */
7382 - (void
) scrollWheel
: (NSEvent
*)theEvent
7384 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
7385 [view mouseDown
: theEvent
];
7388 @
end /* EmacsScroller */
7391 #ifdef NS_IMPL_GNUSTEP
7392 /* Dummy class to get rid of startup warnings. */
7393 @implementation EmacsDocument
7399 /* ==========================================================================
7401 Font-related functions; these used to be in nsfaces.m
7403 ========================================================================== */
7407 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
7409 struct font
*font
= XFONT_OBJECT
(font_object
);
7410 EmacsView
*view = FRAME_NS_VIEW
(f
);
7413 fontset
= fontset_from_font
(font_object
);
7414 FRAME_FONTSET
(f
) = fontset
;
7416 if (FRAME_FONT
(f
) == font
)
7417 /* This font is already set in frame F. There's nothing more to
7421 FRAME_FONT
(f
) = font
;
7423 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
7424 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
7425 FRAME_LINE_HEIGHT
(f
) = font
->height
;
7427 compute_fringe_widths
(f
, 1);
7429 /* Compute the scroll bar width in character columns. */
7430 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
7432 int wid
= FRAME_COLUMN_WIDTH
(f
);
7433 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
7434 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
7438 int wid
= FRAME_COLUMN_WIDTH
(f
);
7439 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
7442 /* Now make the frame display the given font. */
7443 if (FRAME_NS_WINDOW
(f
) != 0 && ! [view isFullscreen
])
7444 x_set_window_size
(f
, 0, FRAME_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
),
7445 FRAME_LINES
(f
) * FRAME_LINE_HEIGHT
(f
), 1);
7451 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
7452 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
7456 ns_xlfd_to_fontname
(const
char *xlfd
)
7457 /* --------------------------------------------------------------------------
7458 Convert an X font name (XLFD) to an NS font name.
7459 Only family is used.
7460 The string returned is temporarily allocated.
7461 -------------------------------------------------------------------------- */
7463 char *name
= xmalloc
(180);
7467 if (!strncmp
(xlfd
, "
--"
, 2))
7468 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
7470 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
7472 /* stopgap for malformed XLFD input */
7473 if (strlen
(name
) == 0)
7474 strcpy
(name
, "Monaco"
);
7476 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
7477 also uppercase after '-' or ' ' */
7478 name
[0] = c_toupper
(name
[0]);
7479 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
7485 name
[i
+1] = c_toupper
(name
[i
+1]);
7487 else if (name
[i
] == '_')
7491 name
[i
+1] = c_toupper
(name
[i
+1]);
7494 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
7495 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
7502 syms_of_nsterm
(void
)
7504 NSTRACE
(syms_of_nsterm
);
7506 ns_antialias_threshold
= 10.0;
7508 /* from 23+ we need to tell emacs what modifiers there are.. */
7509 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
7510 DEFSYM
(Qalt
, "alt"
);
7511 DEFSYM
(Qhyper
, "hyper"
);
7512 DEFSYM
(Qmeta
, "
meta"
);
7513 DEFSYM
(Qsuper
, "super"
);
7514 DEFSYM
(Qcontrol
, "control"
);
7515 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
7517 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
7518 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
7519 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
7520 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
7521 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
7523 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
7524 "The file specified in the last NS event."
);
7525 ns_input_file
=Qnil
;
7527 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
7528 "The data received in the last NS
text drag event."
);
7529 ns_input_text
=Qnil
;
7531 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
7532 "String
for visualizing working composition sequence."
);
7533 ns_working_text
=Qnil
;
7535 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
7536 "The font specified in the last NS event."
);
7537 ns_input_font
=Qnil
;
7539 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
7540 "The fontsize specified in the last NS event."
);
7541 ns_input_fontsize
=Qnil
;
7543 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
7544 "The
line specified in the last NS event."
);
7545 ns_input_line
=Qnil
;
7547 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
7548 "The color specified in the last NS event."
);
7549 ns_input_color
=Qnil
;
7551 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
7552 "The service name specified in the last NS event."
);
7553 ns_input_spi_name
=Qnil
;
7555 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
7556 "The service argument specified in the last NS event."
);
7557 ns_input_spi_arg
=Qnil
;
7559 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
7560 "This variable describes the behavior of the alternate or option key.
\n\
7561 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7562 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
7563 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7564 ns_alternate_modifier
= Qmeta
;
7566 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
7567 "This variable describes the behavior of the right alternate or option key.
\n\
7568 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7569 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
7570 Set to none means that the alternate / option key is not interpreted by Emacs\n\
7571 at all, allowing it to be used at a lower level for accented character entry.");
7572 ns_right_alternate_modifier = Qleft;
7574 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
7575 "This variable describes the behavior of the command key.\n\
7576 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
7577 ns_command_modifier = Qsuper;
7579 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
7580 "This variable describes the behavior of the right command key.\n\
7581 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7582 Set to left means be the same key as `ns-command-modifier'.
\n\
7583 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
7584 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7585 ns_right_command_modifier
= Qleft
;
7587 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
7588 "This variable describes the behavior of the control key.
\n\
7589 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
7590 ns_control_modifier
= Qcontrol
;
7592 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
7593 "This variable describes the behavior of the right control key.
\n\
7594 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7595 Set to left means be the same key as `ns
-control
-modifier
'.\n\
7596 Set to none means that the control / option key is not interpreted by Emacs\n\
7597 at all, allowing it to be used at a lower level for accented character entry.");
7598 ns_right_control_modifier = Qleft;
7600 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
7601 "This variable describes the behavior of the function key (on laptops).\n\
7602 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7603 Set to none means that the function key is not interpreted by Emacs at all,\n\
7604 allowing it to be used at a lower level for accented character entry.");
7605 ns_function_modifier = Qnone;
7607 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
7608 "Non-nil (the default) means to render text antialiased.");
7609 ns_antialias_text = Qt;
7611 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
7612 "Whether to confirm application quit using dialog.");
7613 ns_confirm_quit = Qnil;
7615 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
7616 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
7617 Only works on OSX 10.6 or later. */);
7618 ns_auto_hide_menu_bar = Qnil;
7620 DEFVAR_BOOL ("ns-use-native-fullscreen", ns_use_native_fullscreen,
7621 doc: /*Non-nil means to use native fullscreen on OSX >= 10.7.
7622 Nil means use fullscreen the old (< 10.7) way. The old way works better with
7623 multiple monitors, but lacks tool bar. This variable is ignored on OSX < 10.7.
7624 Default is t for OSX >= 10.7, nil otherwise. */);
7625 #ifdef HAVE_NATIVE_FS
7626 ns_use_native_fullscreen = YES;
7628 ns_use_native_fullscreen = NO;
7630 ns_last_use_native_fullscreen = ns_use_native_fullscreen;
7632 /* TODO: move to common code */
7633 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
7634 doc: /* Which toolkit scroll bars Emacs uses, if any.
7635 A value of nil means Emacs doesn't use toolkit scroll bars.
7636 With the X Window system
, the value is a symbol describing the
7637 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
7638 With MS Windows or Nextstep
, the value is t. */
);
7639 Vx_toolkit_scroll_bars
= Qt
;
7641 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
7642 x_use_underline_position_properties
,
7643 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
7644 A value of nil means ignore them. If you encounter fonts with bogus
7645 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
7646 to 4.1, set this to nil. */);
7647 x_use_underline_position_properties
= 0;
7649 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
7650 x_underline_at_descent_line
,
7651 doc: /* Non-nil means to draw the underline at the same place as the descent line.
7652 A value of nil means to draw the underline according to the value of the
7653 variable `x-use-underline-position-properties', which is usually at the
7654 baseline level. The default value is nil. */);
7655 x_underline_at_descent_line
= 0;
7657 /* Tell Emacs about this window system. */
7658 Fprovide
(Qns
, Qnil
);
7660 DEFSYM
(Qcocoa
, "cocoa"
);
7661 DEFSYM
(Qgnustep
, "gnustep"
);
7664 #ifdef NS_IMPL_COCOA
7665 Fprovide
(Qcocoa
, Qnil
);
7666 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= 1050
7670 Fprovide
(Qgnustep
, Qnil
);