1 /* NeXT/Open/GNUstep / MacOSX communication module.
3 Copyright (C) 1989, 1993-1994, 2005-2006, 2008-2012
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 Originally by Carl Edman
23 Updated by Christian Limpach (chris@nice.ch)
24 OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com)
25 MacOSX/Aqua port by Christophe de Dinechin (descubes@earthlink.net)
26 GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
29 /* This should be the first include, as it may set up #defines affecting
30 interpretation of even the system includes. */
35 #include
<sys
/types.h
>
41 #include
<c
-strcase.h
>
49 #include "blockinput.h"
50 #include "sysselect.h"
53 #include "character.h"
55 #include "composite.h"
58 #include "termhooks.h"
68 int term_trace_num
= 0;
69 #define NSTRACE
(x
) fprintf (stderr
, "
%s:%d: [%d] " #x "\n", \
70 __FILE__
, __LINE__
, ++term_trace_num
)
75 #
if defined
(NS_IMPL_COCOA
) && \
76 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
80 extern NSString
*NSMenuDidBeginTrackingNotification
;
82 /* ==========================================================================
86 ========================================================================== */
88 /* Convert a symbol indexed with an NSxxx value to a value as defined
89 in keyboard.c (lispy_function_key). I hope this is a correct way
91 static unsigned convert_ns_to_X_keysym
[] =
93 NSHomeFunctionKey
, 0x50,
94 NSLeftArrowFunctionKey
, 0x51,
95 NSUpArrowFunctionKey
, 0x52,
96 NSRightArrowFunctionKey
, 0x53,
97 NSDownArrowFunctionKey
, 0x54,
98 NSPageUpFunctionKey
, 0x55,
99 NSPageDownFunctionKey
, 0x56,
100 NSEndFunctionKey
, 0x57,
101 NSBeginFunctionKey
, 0x58,
102 NSSelectFunctionKey
, 0x60,
103 NSPrintFunctionKey
, 0x61,
104 NSClearLineFunctionKey
, 0x0B,
105 NSExecuteFunctionKey
, 0x62,
106 NSInsertFunctionKey
, 0x63,
107 NSUndoFunctionKey
, 0x65,
108 NSRedoFunctionKey
, 0x66,
109 NSMenuFunctionKey
, 0x67,
110 NSFindFunctionKey
, 0x68,
111 NSHelpFunctionKey
, 0x6A,
112 NSBreakFunctionKey
, 0x6B,
114 NSF1FunctionKey
, 0xBE,
115 NSF2FunctionKey
, 0xBF,
116 NSF3FunctionKey
, 0xC0,
117 NSF4FunctionKey
, 0xC1,
118 NSF5FunctionKey
, 0xC2,
119 NSF6FunctionKey
, 0xC3,
120 NSF7FunctionKey
, 0xC4,
121 NSF8FunctionKey
, 0xC5,
122 NSF9FunctionKey
, 0xC6,
123 NSF10FunctionKey
, 0xC7,
124 NSF11FunctionKey
, 0xC8,
125 NSF12FunctionKey
, 0xC9,
126 NSF13FunctionKey
, 0xCA,
127 NSF14FunctionKey
, 0xCB,
128 NSF15FunctionKey
, 0xCC,
129 NSF16FunctionKey
, 0xCD,
130 NSF17FunctionKey
, 0xCE,
131 NSF18FunctionKey
, 0xCF,
132 NSF19FunctionKey
, 0xD0,
133 NSF20FunctionKey
, 0xD1,
134 NSF21FunctionKey
, 0xD2,
135 NSF22FunctionKey
, 0xD3,
136 NSF23FunctionKey
, 0xD4,
137 NSF24FunctionKey
, 0xD5,
139 NSBackspaceCharacter
, 0x08, /* 8: Not on some KBs. */
140 NSDeleteCharacter
, 0xFF, /* 127: Big 'delete' key upper right. */
141 NSDeleteFunctionKey
, 0x9F, /* 63272: Del forw key off main array. */
143 NSTabCharacter
, 0x09,
144 0x19, 0x09, /* left tab->regular since pass shift */
145 NSCarriageReturnCharacter
, 0x0D,
146 NSNewlineCharacter
, 0x0D,
147 NSEnterCharacter
, 0x8D,
149 0x41|NSNumericPadKeyMask
, 0xAE, /* KP_Decimal */
150 0x43|NSNumericPadKeyMask
, 0xAA, /* KP_Multiply */
151 0x45|NSNumericPadKeyMask
, 0xAB, /* KP_Add */
152 0x4B|NSNumericPadKeyMask
, 0xAF, /* KP_Divide */
153 0x4E|NSNumericPadKeyMask
, 0xAD, /* KP_Subtract */
154 0x51|NSNumericPadKeyMask
, 0xBD, /* KP_Equal */
155 0x52|NSNumericPadKeyMask
, 0xB0, /* KP_0 */
156 0x53|NSNumericPadKeyMask
, 0xB1, /* KP_1 */
157 0x54|NSNumericPadKeyMask
, 0xB2, /* KP_2 */
158 0x55|NSNumericPadKeyMask
, 0xB3, /* KP_3 */
159 0x56|NSNumericPadKeyMask
, 0xB4, /* KP_4 */
160 0x57|NSNumericPadKeyMask
, 0xB5, /* KP_5 */
161 0x58|NSNumericPadKeyMask
, 0xB6, /* KP_6 */
162 0x59|NSNumericPadKeyMask
, 0xB7, /* KP_7 */
163 0x5B|NSNumericPadKeyMask
, 0xB8, /* KP_8 */
164 0x5C|NSNumericPadKeyMask
, 0xB9, /* KP_9 */
166 0x1B, 0x1B /* escape */
169 static Lisp_Object Qmodifier_value
;
170 Lisp_Object Qalt
, Qcontrol
, Qhyper
, Qmeta
, Qsuper
;
171 extern Lisp_Object Qcursor_color
, Qcursor_type
, Qns
, Qleft
;
173 static Lisp_Object QUTF8_STRING
;
175 /* On OS X picks up the default NSGlobalDomain AppleAntiAliasingThreshold,
176 the maximum font size to NOT antialias. On GNUstep there is currently
177 no way to control this behavior. */
178 float ns_antialias_threshold
;
180 /* Used to pick up AppleHighlightColor on OS X */
181 NSString
*ns_selection_color
;
183 NSArray
*ns_send_types
=0, *ns_return_types
=0, *ns_drag_types
=0;
184 NSString
*ns_app_name
= @"Emacs"
; /* default changed later */
186 /* Display variables */
187 struct ns_display_info
*x_display_list
; /* Chain of existing displays */
188 Lisp_Object ns_display_name_list
;
189 long context_menu_value
= 0;
192 NSPoint last_mouse_motion_position
;
193 static NSRect last_mouse_glyph
;
194 static Time last_mouse_movement_time
= 0;
195 static Lisp_Object last_mouse_motion_frame
;
196 static EmacsScroller
*last_mouse_scroll_bar
= nil
;
197 static
struct frame
*ns_updating_frame
;
198 static NSView
*focus_view
= NULL;
199 static int ns_window_num
= 0;
200 #ifdef NS_IMPL_GNUSTEP
203 static BOOL gsaved
= NO
;
204 static BOOL ns_fake_keydown
= NO
;
205 int ns_tmp_flags
; /* FIXME */
206 struct nsfont_info
*ns_tmp_font
; /* FIXME */
207 static BOOL ns_menu_bar_is_hidden
= NO
;
208 /*static int debug_lock = 0; */
211 static BOOL send_appdefined
= YES
;
212 #define NO_APPDEFINED_DATA
(-8)
213 static int last_appdefined_event_data
= NO_APPDEFINED_DATA
;
214 static NSTimer
*timed_entry
= 0;
215 static NSTimer
*scroll_repeat_entry
= nil
;
216 static fd_set select_readfds
, select_writefds
;
217 enum
{ SELECT_HAVE_READ
= 1, SELECT_HAVE_WRITE
= 2, SELECT_HAVE_TMO
= 4 };
218 static int select_nfds
= 0, select_valid
= 0;
219 static EMACS_TIME select_timeout
= { 0, 0 };
220 static int selfds
[2] = { -1, -1 };
221 static pthread_mutex_t select_mutex
;
222 static int apploopnr
= 0;
223 static NSAutoreleasePool
*outerpool
;
224 static
struct input_event
*emacs_event
= NULL;
225 static
struct input_event
*q_event_ptr
= NULL;
226 static int n_emacs_events_pending
= 0;
227 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
228 *ns_pending_service_args
;
229 static BOOL ns_do_open_file
= NO
;
232 struct input_event
*q
;
238 /* Convert modifiers in a NeXTstep event to emacs style modifiers. */
239 #define NS_FUNCTION_KEY_MASK
0x800000
240 #define NSLeftControlKeyMask
(0x000001 | NSControlKeyMask
)
241 #define NSRightControlKeyMask
(0x002000 | NSControlKeyMask
)
242 #define NSLeftCommandKeyMask
(0x000008 | NSCommandKeyMask
)
243 #define NSRightCommandKeyMask
(0x000010 | NSCommandKeyMask
)
244 #define NSLeftAlternateKeyMask
(0x000020 | NSAlternateKeyMask
)
245 #define NSRightAlternateKeyMask
(0x000040 | NSAlternateKeyMask
)
246 #define EV_MODIFIERS
(e
) \
247 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
248 hyper_modifier
: 0) \
249 |
(!EQ
(ns_right_alternate_modifier
, Qleft
) && \
250 (([e modifierFlags
] & NSRightAlternateKeyMask
) \
251 == NSRightAlternateKeyMask
) ? \
252 parse_solitary_modifier
(ns_right_alternate_modifier
) : 0) \
253 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
254 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
255 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
256 shift_modifier
: 0) \
257 |
(!EQ
(ns_right_control_modifier
, Qleft
) && \
258 (([e modifierFlags
] & NSRightControlKeyMask
) \
259 == NSRightControlKeyMask
) ? \
260 parse_solitary_modifier
(ns_right_control_modifier
) : 0) \
261 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
262 parse_solitary_modifier
(ns_control_modifier
) : 0) \
263 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
264 parse_solitary_modifier
(ns_function_modifier
) : 0) \
265 |
(!EQ
(ns_right_command_modifier
, Qleft
) && \
266 (([e modifierFlags
] & NSRightCommandKeyMask
) \
267 == NSRightCommandKeyMask
) ? \
268 parse_solitary_modifier
(ns_right_command_modifier
) : 0) \
269 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
270 parse_solitary_modifier
(ns_command_modifier
):0))
272 #define EV_UDMODIFIERS
(e
) \
273 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
274 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
275 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
276 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
277 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
278 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
279 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
280 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
281 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
283 #define EV_BUTTON
(e
) \
284 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
285 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
286 [e buttonNumber
] - 1)
288 /* Convert the time field to a timestamp in milliseconds. */
289 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
291 /* This is a piece of code which is common to all the event handling
292 methods. Maybe it should even be a function. */
293 #define EV_TRAILER
(e
) \
295 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
296 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
299 n_emacs_events_pending
++; \
300 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
303 hold_event
(emacs_event
); \
304 EVENT_INIT
(*emacs_event
); \
305 ns_send_appdefined
(-1); \
308 void x_set_cursor_type
(struct frame
*, Lisp_Object
, Lisp_Object
);
310 /* TODO: get rid of need for these forward declarations */
311 static void ns_condemn_scroll_bars
(struct frame
*f
);
312 static void ns_judge_scroll_bars
(struct frame
*f
);
313 void x_set_frame_alpha
(struct frame
*f
);
316 /* ==========================================================================
320 ========================================================================== */
323 hold_event
(struct input_event
*event
)
325 if (hold_event_q.nr
== hold_event_q.cap
)
327 if (hold_event_q.cap
== 0) hold_event_q.cap
= 10;
328 else hold_event_q.cap
*= 2;
329 hold_event_q.q
= (struct input_event
*)
330 xrealloc
(hold_event_q.q
, hold_event_q.cap
* sizeof
(*hold_event_q.q
));
333 hold_event_q.q
[hold_event_q.nr
++] = *event
;
334 /* Make sure ns_read_socket is called, i.e. we have input. */
339 append2
(Lisp_Object list
, Lisp_Object item
)
340 /* --------------------------------------------------------------------------
341 Utility to append to a list
342 -------------------------------------------------------------------------- */
344 Lisp_Object array
[2];
346 array
[1] = Fcons
(item
, Qnil
);
347 return Fnconc
(2, &array
[0]);
352 ns_etc_directory
(void
)
353 /* If running as a self-contained app bundle, return as a string the
354 filename of the etc directory, if present; else nil. */
356 NSBundle
*bundle
= [NSBundle mainBundle
];
357 NSString
*resourceDir
= [bundle resourcePath
];
358 NSString
*resourcePath
;
359 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
362 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
363 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
365 if (isDir
) return [resourcePath UTF8String
];
373 /* If running as a self-contained app bundle, return as a path string
374 the filenames of the libexec and bin directories, ie libexec:bin.
375 Otherwise, return nil.
376 Normally, Emacs does not add its own bin/ directory to the PATH.
377 However, a self-contained NS build has a different layout, with
378 bin/ and libexec/ subdirectories in the directory that contains
380 We put libexec first, because init_callproc_1 uses the first
381 element to initialize exec-directory. An alternative would be
382 for init_callproc to check for invocation-directory/libexec.
385 NSBundle
*bundle
= [NSBundle mainBundle
];
386 NSString
*resourceDir
= [bundle resourcePath
];
387 NSString
*binDir
= [bundle bundlePath
];
388 NSString
*resourcePath
, *resourcePaths
;
390 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
391 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
393 NSEnumerator
*pathEnum
;
396 range
= [resourceDir rangeOfString
: @"Contents"
];
397 if (range.location
!= NSNotFound
)
399 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
401 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
405 paths
= [binDir stringsByAppendingPaths
:
406 [NSArray arrayWithObjects
: @"libexec"
, @"bin"
, nil
]];
407 pathEnum
= [paths objectEnumerator
];
410 while ((resourcePath
= [pathEnum nextObject
]))
412 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
415 if ([resourcePaths
length] > 0)
417 = [resourcePaths stringByAppendingString
: pathSeparator
];
419 = [resourcePaths stringByAppendingString
: resourcePath
];
422 if ([resourcePaths
length] > 0) return [resourcePaths UTF8String
];
430 /* If running as a self-contained app bundle, return as a path string
431 the filenames of the site-lisp, lisp and leim directories.
432 Ie, site-lisp:lisp:leim. Otherwise, return nil. */
434 NSBundle
*bundle
= [NSBundle mainBundle
];
435 NSString
*resourceDir
= [bundle resourcePath
];
436 NSString
*resourcePath
, *resourcePaths
;
437 NSString
*pathSeparator
= [NSString stringWithFormat
: @"
%c", SEPCHAR];
438 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
440 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
441 [NSArray arrayWithObjects
:
442 @"site
-lisp"
, @"lisp"
, @"leim"
, nil
]];
443 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
446 /* Hack to skip site-lisp. */
447 if (no_site_lisp
) resourcePath
= [pathEnum nextObject
];
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
];
467 ns_timeout
(int usecs
)
468 /* --------------------------------------------------------------------------
469 Blocking timer utility used by ns_ring_bell
470 -------------------------------------------------------------------------- */
472 EMACS_TIME wakeup
= add_emacs_time
(current_emacs_time
(),
473 make_emacs_time
(0, usecs
* 1000));
475 /* Keep waiting until past the time wakeup. */
478 EMACS_TIME timeout
, now
= current_emacs_time
();
479 if (EMACS_TIME_LE
(wakeup
, now
))
481 timeout
= sub_emacs_time
(wakeup
, now
);
483 /* Try to wait that long--but we might wake up sooner. */
484 pselect
(0, NULL, NULL, NULL, &timeout
, NULL);
490 ns_release_object
(void
*obj
)
491 /* --------------------------------------------------------------------------
492 Release an object (callable from C)
493 -------------------------------------------------------------------------- */
500 ns_retain_object
(void
*obj
)
501 /* --------------------------------------------------------------------------
502 Retain an object (callable from C)
503 -------------------------------------------------------------------------- */
510 ns_alloc_autorelease_pool
(void
)
511 /* --------------------------------------------------------------------------
512 Allocate a pool for temporary objects (callable from C)
513 -------------------------------------------------------------------------- */
515 return [[NSAutoreleasePool alloc
] init
];
520 ns_release_autorelease_pool
(void
*pool
)
521 /* --------------------------------------------------------------------------
522 Free a pool and temporary objects it refers to (callable from C)
523 -------------------------------------------------------------------------- */
525 ns_release_object
(pool
);
530 /* ==========================================================================
532 Focus (clipping) and screen update
534 ========================================================================== */
537 // Window constraining
538 // -------------------
540 // To ensure that the windows are not placed under the
menu bar, they
541 // are typically moved by the call
-back constrainFrameRect. However
,
542 // by overriding it
, it
's possible to inhibit this, leaving the window
543 // in it's original position.
545 // It
's possible to hide the menu bar. However, technically, it's only
546 // possible to hide it when the application is active. To ensure that
547 // this work properly
, the
menu bar and window constraining are
548 // deferred until the application becomes active.
550 // Even though it
's not possible to manually move a window above the
551 // top of the screen, it is allowed if it's done programmatically
,
552 // when the
menu is
hidden. This allows the editable area to cover the
553 // full screen height.
558 // Use the following extra files
:
561 // ;; Hide
menu and place frame slightly above the top of the screen.
562 // (setq ns
-auto
-hide
-menu-bar t
)
563 // (set-frame
-position
(selected
-frame
) 0 -20)
567 // emacs
-Q
-l init.el
569 // Result
: No
menu bar, and the
title bar should be above the screen.
575 // Result
: Menu bar visible
, frame placed immediately below the
menu.
579 ns_constrain_all_frames
(void
)
581 Lisp_Object tail
, frame
;
583 FOR_EACH_FRAME
(tail
, frame
)
585 struct frame
*f
= XFRAME
(frame
);
588 NSView
*view = FRAME_NS_VIEW
(f
);
589 /* This no-op will trigger the default window placing
590 * constraint system. */
591 f
->output_data.ns
->dont_constrain
= 0;
592 [[view window
] setFrameOrigin
:[[view window
] frame
].origin
];
598 /* True, if the menu bar should be hidden. */
601 ns_menu_bar_should_be_hidden
(void
)
603 return !NILP
(ns_auto_hide_menu_bar
)
604 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)];
608 /* Show or hide the menu bar, based on user setting. */
611 ns_update_auto_hide_menu_bar
(void
)
614 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
617 NSTRACE
(ns_update_auto_hide_menu_bar
);
621 && [NSApp respondsToSelector
:@selector
(setPresentationOptions
:)])
623 // Note
, "setPresentationOptions" triggers an
error unless the
624 // application is active.
625 BOOL menu_bar_should_be_hidden
= ns_menu_bar_should_be_hidden
();
627 if (menu_bar_should_be_hidden
!= ns_menu_bar_is_hidden
)
629 NSApplicationPresentationOptions options
630 = NSApplicationPresentationAutoHideDock
;
632 if (menu_bar_should_be_hidden
)
633 options |
= NSApplicationPresentationAutoHideMenuBar
;
635 [NSApp setPresentationOptions
: options
];
637 ns_menu_bar_is_hidden
= menu_bar_should_be_hidden
;
639 if (!ns_menu_bar_is_hidden
)
641 ns_constrain_all_frames
();
653 ns_update_begin
(struct frame
*f
)
654 /* --------------------------------------------------------------------------
655 Prepare for a grouped sequence of drawing calls
656 external (RIF) call; whole frame, called before update_window_begin
657 -------------------------------------------------------------------------- */
659 NSView
*view = FRAME_NS_VIEW
(f
);
660 NSRect r
= [view frame
];
662 NSTRACE
(ns_update_begin
);
664 ns_update_auto_hide_menu_bar
();
666 ns_updating_frame
= f
;
669 /* drawRect may have been called for say the minibuffer, and then clip path
670 is for the minibuffer. But the display engine may draw more because
671 we have set the frame as garbaged. So reset clip path to the whole
673 bp
= [[NSBezierPath bezierPathWithRect
: r
] retain
];
677 #ifdef NS_IMPL_GNUSTEP
678 uRect
= NSMakeRect
(0, 0, 0, 0);
684 ns_update_window_begin
(struct window
*w
)
685 /* --------------------------------------------------------------------------
686 Prepare for a grouped sequence of drawing calls
687 external (RIF) call; for one window, called after update_begin
688 -------------------------------------------------------------------------- */
690 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
691 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
692 NSTRACE
(ns_update_window_begin
);
694 set_output_cursor
(&w
->cursor
);
698 if (f
== hlinfo
->mouse_face_mouse_frame
)
700 /* Don't do highlighting for mouse motion during the update. */
701 hlinfo
->mouse_face_defer
= 1;
703 /* If the frame needs to be redrawn,
704 simply forget about any prior mouse highlighting. */
705 if (FRAME_GARBAGED_P
(f
))
706 hlinfo
->mouse_face_window
= Qnil
;
708 /* (further code for mouse faces ifdef'd out in other terms elided) */
716 ns_update_window_end
(struct window
*w
, int cursor_on_p
,
717 int mouse_face_overwritten_p
)
718 /* --------------------------------------------------------------------------
719 Finished a grouped sequence of drawing calls
720 external (RIF) call; for one window called before update_end
721 -------------------------------------------------------------------------- */
723 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(XFRAME
(w
->frame
));
725 /* note: this fn is nearly identical in all terms */
726 if (!w
->pseudo_window_p
)
731 display_and_set_cursor
(w
, 1,
732 output_cursor.hpos
, output_cursor.vpos
,
733 output_cursor.x
, output_cursor.y
);
735 if (draw_window_fringes
(w
, 1))
736 x_draw_vertical_border
(w
);
741 /* If a row with mouse-face was overwritten, arrange for
742 frame_up_to_date to redisplay the mouse highlight. */
743 if (mouse_face_overwritten_p
)
745 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
746 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
747 hlinfo
->mouse_face_window
= Qnil
;
750 updated_window
= NULL;
751 NSTRACE
(update_window_end
);
756 ns_update_end
(struct frame
*f
)
757 /* --------------------------------------------------------------------------
758 Finished a grouped sequence of drawing calls
759 external (RIF) call; for whole frame, called after update_window_end
760 -------------------------------------------------------------------------- */
762 NSView
*view = FRAME_NS_VIEW
(f
);
764 /* if (f == MOUSE_HL_INFO (f)->mouse_face_mouse_frame) */
765 MOUSE_HL_INFO
(f
)->mouse_face_defer
= 0;
769 #ifdef NS_IMPL_GNUSTEP
770 /* trigger flush only in the rectangle we tracked as being drawn */
771 [view unlockFocusNeedsFlush
: NO
];
772 /*fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", uRect.origin.x, uRect.origin.y, uRect.size.width, uRect.size.height); */
773 [view lockFocusInRect
: uRect
];
777 [[view window
] flushWindow
];
780 ns_updating_frame
= NULL;
781 NSTRACE
(ns_update_end
);
786 ns_flush
(struct frame
*f
)
787 /* --------------------------------------------------------------------------
789 NS impl is no-op since currently we flush in ns_update_end and elsewhere
790 -------------------------------------------------------------------------- */
797 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
798 /* --------------------------------------------------------------------------
799 Internal: Focus on given frame. During small local updates this is used to
800 draw, however during large updates, ns_update_begin and ns_update_end are
801 called to wrap the whole thing, in which case these calls are stubbed out.
802 Except, on GNUstep, we accumulate the rectangle being drawn into, because
803 the back end won't do this automatically, and will just end up flushing
805 -------------------------------------------------------------------------- */
807 // NSTRACE
(ns_focus
);
808 #ifdef NS_IMPL_GNUSTEP
811 u
= NSUnionRect
(r
[0], r
[1]);
816 fprintf (stderr, "focus: %d", c++);
817 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
818 fprintf (stderr, "\n"); */
820 if (f
!= ns_updating_frame
)
822 NSView
*view = FRAME_NS_VIEW
(f
);
823 if (view != focus_view
)
825 if (focus_view
!= NULL)
827 [focus_view unlockFocus
];
828 [[focus_view window
] flushWindow
];
833 #ifdef NS_IMPL_GNUSTEP
834 r ?
[view lockFocusInRect
: u
] : [view lockFocus
];
839 /*if (view) debug_lock++; */
841 #ifdef NS_IMPL_GNUSTEP
844 /* more than one rect being drawn into */
847 [view unlockFocus
]; /* add prev rect to redraw list */
848 [view lockFocusInRect
: u
]; /* focus for draw in new rect */
853 #ifdef NS_IMPL_GNUSTEP
856 /* in batch mode, but in GNUstep must still track rectangles explicitly */
857 uRect
= (r ? NSUnionRect
(uRect
, u
) : [FRAME_NS_VIEW
(f
) visibleRect
]);
864 [[NSGraphicsContext currentContext
] saveGraphicsState
];
866 NSRectClipList
(r
, 2);
875 ns_unfocus
(struct frame
*f
)
876 /* --------------------------------------------------------------------------
877 Internal: Remove focus on given frame
878 -------------------------------------------------------------------------- */
880 // NSTRACE
(ns_unfocus
);
884 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
888 if (f
!= ns_updating_frame
)
890 if (focus_view
!= NULL)
892 [focus_view unlockFocus
];
893 [[focus_view window
] flushWindow
];
902 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
, int area
, BOOL gc
)
903 /* --------------------------------------------------------------------------
904 Internal (but parallels other terms): Focus drawing on given row
905 -------------------------------------------------------------------------- */
907 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
909 int window_x
, window_y
, window_width
;
911 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
913 clip_rect.origin.x
= window_x
;
914 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
915 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
916 clip_rect.
size.width
= window_width
;
917 clip_rect.
size.height
= row
->visible_height
;
919 ns_focus
(f
, &clip_rect
, 1);
924 ns_ring_bell
(struct frame
*f
)
925 /* --------------------------------------------------------------------------
927 -------------------------------------------------------------------------- */
929 NSTRACE
(ns_ring_bell
);
932 NSAutoreleasePool
*pool
;
933 struct frame
*frame
= SELECTED_FRAME
();
937 pool
= [[NSAutoreleasePool alloc
] init
];
939 view = FRAME_NS_VIEW
(frame
);
943 NSPoint dim
= NSMakePoint
(128, 128);
946 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
947 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
948 r.
size.width
= dim.x
;
949 r.
size.height
= dim.y
;
950 surr
= NSInsetRect
(r
, -2, -2);
951 ns_focus
(frame
, &surr
, 1);
952 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
953 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
954 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
956 [[view window
] flushWindow
];
958 [[view window
] restoreCachedImage
];
959 [[view window
] flushWindow
];
973 ns_reset_terminal_modes
(struct terminal *terminal)
974 /* Externally called as hook */
976 NSTRACE
(ns_reset_terminal_modes
);
981 ns_set_terminal_modes
(struct terminal *terminal)
982 /* Externally called as hook */
984 NSTRACE
(ns_set_terminal_modes
);
989 /* ==========================================================================
991 Frame / window manager related functions
993 ========================================================================== */
997 ns_raise_frame
(struct frame
*f
)
998 /* --------------------------------------------------------------------------
999 Bring window to foreground and make it active
1000 -------------------------------------------------------------------------- */
1002 NSView
*view = FRAME_NS_VIEW
(f
);
1005 FRAME_SAMPLE_VISIBILITY
(f
);
1006 if (FRAME_VISIBLE_P
(f
))
1008 [[view window
] makeKeyAndOrderFront
: NSApp
];
1015 ns_lower_frame
(struct frame
*f
)
1016 /* --------------------------------------------------------------------------
1018 -------------------------------------------------------------------------- */
1020 NSView
*view = FRAME_NS_VIEW
(f
);
1023 [[view window
] orderBack
: NSApp
];
1029 ns_frame_raise_lower
(struct frame
*f
, int raise
)
1030 /* --------------------------------------------------------------------------
1032 -------------------------------------------------------------------------- */
1034 NSTRACE
(ns_frame_raise_lower
);
1044 ns_frame_rehighlight
(struct frame
*frame
)
1045 /* --------------------------------------------------------------------------
1046 External (hook): called on things like window switching within frame
1047 -------------------------------------------------------------------------- */
1049 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(frame
);
1050 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
1052 NSTRACE
(ns_frame_rehighlight
);
1053 if (dpyinfo
->x_focus_frame
)
1055 dpyinfo
->x_highlight_frame
1056 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1057 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
1058 : dpyinfo
->x_focus_frame
);
1059 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
1061 fset_focus_frame
(dpyinfo
->x_focus_frame
, Qnil
);
1062 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
1066 dpyinfo
->x_highlight_frame
= 0;
1068 if (dpyinfo
->x_highlight_frame
&&
1069 dpyinfo
->x_highlight_frame
!= old_highlight
)
1073 x_update_cursor
(old_highlight
, 1);
1074 x_set_frame_alpha
(old_highlight
);
1076 if (dpyinfo
->x_highlight_frame
)
1078 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
1079 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
1086 x_make_frame_visible
(struct frame
*f
)
1087 /* --------------------------------------------------------------------------
1088 External: Show the window (X11 semantics)
1089 -------------------------------------------------------------------------- */
1091 NSTRACE
(x_make_frame_visible
);
1092 /* XXX: at some points in past this was not needed, as the only place that
1093 called this (frame.c:Fraise_frame ()) also called raise_lower;
1094 if this ends up the case again, comment this out again. */
1095 if (!FRAME_VISIBLE_P
(f
))
1097 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(f
);
1098 f
->async_visible
= 1;
1102 /* Making a new frame from a fullscreen frame will make the new frame
1103 fullscreen also. So skip handleFS as this will print an error. */
1104 if (f
->want_fullscreen
== FULLSCREEN_BOTH
1105 && ([[view window
] styleMask
] & NSFullScreenWindowMask
) != 0)
1108 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
1119 x_make_frame_invisible
(struct frame
*f
)
1120 /* --------------------------------------------------------------------------
1121 External: Hide the window (X11 semantics)
1122 -------------------------------------------------------------------------- */
1124 NSView
* view = FRAME_NS_VIEW
(f
);
1125 NSTRACE
(x_make_frame_invisible
);
1127 [[view window
] orderOut
: NSApp
];
1128 f
->async_visible
= 0;
1129 f
->async_iconified
= 0;
1134 x_iconify_frame
(struct frame
*f
)
1135 /* --------------------------------------------------------------------------
1136 External: Iconify window
1137 -------------------------------------------------------------------------- */
1139 NSView
* view = FRAME_NS_VIEW
(f
);
1140 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1141 NSTRACE
(x_iconify_frame
);
1144 if (dpyinfo
->x_highlight_frame
== f
)
1145 dpyinfo
->x_highlight_frame
= 0;
1147 if ([[view window
] windowNumber
] <= 0)
1149 /* the window is still deferred. Make it very small, bring it
1150 on screen and order it out. */
1151 NSRect s
= { { 100, 100}, {0, 0} };
1153 t
= [[view window
] frame
];
1154 [[view window
] setFrame
: s display
: NO
];
1155 [[view window
] orderBack
: NSApp
];
1156 [[view window
] orderOut
: NSApp
];
1157 [[view window
] setFrame
: t display
: NO
];
1159 [[view window
] miniaturize
: NSApp
];
1162 /* Free X resources of frame F. */
1165 x_free_frame_resources
(struct frame
*f
)
1167 NSView
*view = FRAME_NS_VIEW
(f
);
1168 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1169 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1170 NSTRACE
(x_free_frame_resources
);
1173 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1177 free_frame_menubar
(f
);
1179 if (FRAME_FACE_CACHE
(f
))
1180 free_frame_faces
(f
);
1182 if (f
== dpyinfo
->x_focus_frame
)
1183 dpyinfo
->x_focus_frame
= 0;
1184 if (f
== dpyinfo
->x_highlight_frame
)
1185 dpyinfo
->x_highlight_frame
= 0;
1186 if (f
== hlinfo
->mouse_face_mouse_frame
)
1188 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1189 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1190 hlinfo
->mouse_face_window
= Qnil
;
1191 hlinfo
->mouse_face_deferred_gc
= 0;
1192 hlinfo
->mouse_face_mouse_frame
= 0;
1195 if (f
->output_data.ns
->miniimage
!= nil
)
1196 [f
->output_data.ns
->miniimage release
];
1198 [[view window
] close];
1201 xfree
(f
->output_data.ns
);
1207 x_destroy_window
(struct frame
*f
)
1208 /* --------------------------------------------------------------------------
1209 External: Delete the window
1210 -------------------------------------------------------------------------- */
1212 NSTRACE
(x_destroy_window
);
1214 x_free_frame_resources
(f
);
1220 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1221 /* --------------------------------------------------------------------------
1222 External: Position the window
1223 -------------------------------------------------------------------------- */
1225 NSView
*view = FRAME_NS_VIEW
(f
);
1226 NSArray
*screens
= [NSScreen screens
];
1227 NSScreen
*fscreen
= [screens objectAtIndex
: 0];
1228 NSScreen
*screen
= [[view window
] screen
];
1230 NSTRACE
(x_set_offset
);
1237 if (view != nil
&& screen
&& fscreen
)
1239 f
->left_pos
= f
->size_hint_flags
& XNegative
1240 ?
[screen visibleFrame
].
size.width
+ f
->left_pos
- FRAME_PIXEL_WIDTH
(f
)
1242 /* We use visibleFrame here to take menu bar into account.
1243 Ideally we should also adjust left/top with visibleFrame.origin. */
1245 f
->top_pos
= f
->size_hint_flags
& YNegative
1246 ?
([screen visibleFrame
].
size.height
+ f
->top_pos
1247 - FRAME_PIXEL_HEIGHT
(f
) - FRAME_NS_TITLEBAR_HEIGHT
(f
)
1248 - FRAME_TOOLBAR_HEIGHT
(f
))
1250 #ifdef NS_IMPL_GNUSTEP
1251 if (f
->left_pos
< 100)
1252 f
->left_pos
= 100; /* don't overlap menu */
1254 /* Constrain the setFrameTopLeftPoint so we don't move behind the
1256 f
->output_data.ns
->dont_constrain
= 0;
1257 [[view window
] setFrameTopLeftPoint
:
1258 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1259 SCREENMAXBOUND
([fscreen frame
].
size.height
1260 - NS_TOP_POS
(f
)))];
1261 f
->size_hint_flags
&= ~
(XNegative|YNegative
);
1269 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1270 /* --------------------------------------------------------------------------
1271 Adjust window pixel size based on given character grid size
1272 Impl is a bit more complex than other terms, need to do some
1274 -------------------------------------------------------------------------- */
1276 EmacsView
*view = FRAME_NS_VIEW
(f
);
1277 NSWindow
*window
= [view window
];
1278 NSRect wr
= [window frame
];
1279 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1280 int pixelwidth
, pixelheight
;
1282 NSTRACE
(x_set_window_size
);
1287 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1291 check_frame_size
(f
, &rows
, &cols
);
1293 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1294 compute_fringe_widths
(f
, 0);
1296 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1297 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1299 /* If we have a toolbar, take its height into account. */
1301 /* NOTE: previously this would generate wrong result if toolbar not
1302 yet displayed and fixing toolbar_height=32 helped, but
1303 now (200903) seems no longer needed */
1304 FRAME_TOOLBAR_HEIGHT
(f
) =
1305 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1306 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1308 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
1310 wr.
size.width
= pixelwidth
+ f
->border_width
;
1311 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1312 + FRAME_TOOLBAR_HEIGHT
(f
);
1314 /* Do not try to constrain to this screen. We may have multiple
1315 screens, and want Emacs to span those. Constraining to screen
1316 prevents that, and that is not nice to the user. */
1317 if (f
->output_data.ns
->zooming
)
1318 f
->output_data.ns
->zooming
= 0;
1320 wr.origin.y
+= FRAME_PIXEL_HEIGHT
(f
) - pixelheight
;
1322 [view setRows
: rows andColumns
: cols
];
1323 [window setFrame
: wr display
: YES
];
1325 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1327 /* This is a trick to compensate for Emacs' managing the scrollbar area
1328 as a fixed number of standard character columns. Instead of leaving
1329 blank space for the extra, we chopped it off above. Now for
1330 left-hand scrollbars, we shift all rendering to the left by the
1331 difference between the real width and Emacs' imagined one. For
1332 right-hand bars, don't worry about it since the extra is never used.
1333 (Obviously doesn't work for vertically split windows tho..) */
1335 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1336 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1337 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1338 : NSMakePoint
(0, 0);
1339 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1340 [view setBoundsOrigin
: origin
];
1343 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1344 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1345 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1346 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1348 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1349 cancel_mouse_face
(f
);
1356 ns_fullscreen_hook
(FRAME_PTR f
)
1358 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(f
);
1360 if (! f
->async_visible
) return;
1361 #ifndef NEW_STYLE_FS
1362 if (f
->want_fullscreen
== FULLSCREEN_BOTH
)
1364 /* Old style fs don't initiate correctly if created from
1365 init/default-frame alist, so use a timer (not nice...).
1367 [NSTimer scheduledTimerWithTimeInterval
: 0.5 target
: view
1368 selector
: @selector
(handleFS
)
1369 userInfo
: nil repeats
: NO
];
1379 /* ==========================================================================
1383 ========================================================================== */
1387 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1389 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1390 if (idx
< 1 || idx
>= color_table
->avail
)
1392 return color_table
->colors
[idx
];
1397 ns_index_color
(NSColor
*color
, struct frame
*f
)
1399 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1403 if (!color_table
->colors
)
1405 color_table
->size = NS_COLOR_CAPACITY
;
1406 color_table
->avail
= 1; /* skip idx=0 as marker */
1407 color_table
->colors
= xmalloc
(color_table
->size * sizeof
(NSColor
*));
1408 color_table
->colors
[0] = nil
;
1409 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1412 /* do we already have this color ? */
1413 for (i
= 1; i
< color_table
->avail
; i
++)
1414 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1417 if ([color_table
->empty_indices count
] > 0)
1419 NSNumber
*index
= [color_table
->empty_indices anyObject
];
1420 [color_table
->empty_indices removeObject
: index
];
1421 idx
= [index unsignedLongValue
];
1425 if (color_table
->avail
== color_table
->size)
1426 color_table
->colors
=
1427 xpalloc
(color_table
->colors
, &color_table
->size, 1,
1428 min (ULONG_MAX
, PTRDIFF_MAX
), sizeof
*color_table
->colors
);
1429 idx
= color_table
->avail
++;
1432 color_table
->colors
[idx
] = color
;
1434 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1440 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1442 struct ns_color_table
*color_table
;
1449 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1451 if (idx
<= 0 || idx
>= color_table
->size) {
1452 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1456 index
= [NSNumber numberWithUnsignedInt
: idx
];
1457 if ([color_table
->empty_indices containsObject
: index
]) {
1458 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1462 color
= color_table
->colors
[idx
];
1464 color_table
->colors
[idx
] = nil
;
1465 [color_table
->empty_indices addObject
: index
];
1466 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1471 ns_get_color
(const
char *name
, NSColor
**col
)
1472 /* --------------------------------------------------------------------------
1474 -------------------------------------------------------------------------- */
1475 /* On *Step, we attempt to mimic the X11 platform here, down to installing an
1476 X11 rgb.txt-compatible color list in Emacs.clr (see ns_term_init()).
1477 See: http://thread.gmane.org/gmane.emacs.devel/113050/focus=113272). */
1480 static
char hex
[20];
1482 float r
= -1.0, g
, b
;
1483 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1485 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1488 if ([nsname isEqualToString
: @"ns_selection_color"
])
1490 nsname
= ns_selection_color
;
1491 name
= [ns_selection_color UTF8String
];
1494 /* First, check for some sort of numeric specification. */
1497 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.') /* RGB decimal */
1499 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1500 [scanner scanFloat
: &r
];
1501 [scanner scanFloat
: &g
];
1502 [scanner scanFloat
: &b
];
1504 else if (!strncmp
(name
, "rgb
:"
, 4)) /* A newer X11 format -- rgb:r/g/b */
1505 scaling
= (snprintf
(hex
, sizeof hex
, "
%s", name + 4) - 2) / 3;
1506 else if (name
[0] == '#') /* An old X11 format; convert to newer */
1508 int len
= (strlen
(name
) - 1);
1509 int start
= (len
% 3 == 0) ? 1 : len / 4 + 1;
1511 scaling
= strlen
(name
+start
) / 3;
1512 for (i
= 0; i
< 3; i
++)
1513 sprintf (hex
+ i
* (scaling
+ 1), "
%.*s/", scaling,
1514 name
+ start
+ i
* scaling
);
1515 hex
[3 * (scaling
+ 1) - 1] = '\0';
1521 float fscale
= scaling
== 4 ?
65535.0 : (scaling
== 2 ?
255.0 : 15.0);
1522 if (sscanf (hex
, "
%x/%x/%x", &rr, &gg, &bb))
1532 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1537 /* Otherwise, color is expected to be from a list */
1539 NSEnumerator
*lenum
, *cenum
;
1543 #ifdef NS_IMPL_GNUSTEP
1544 /* XXX: who is wrong, the requestor or the implementation? */
1545 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1547 nsname
= @"highlightColor"
;
1550 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1551 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1553 cenum
= [[clist allKeys
] objectEnumerator
];
1554 while ( (name
= [cenum nextObject
]) && new
== nil
)
1556 if ([name compare
: nsname
1557 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1558 new
= [clist colorWithKey
: name
];
1564 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1571 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1572 /* --------------------------------------------------------------------------
1573 Convert a Lisp string object to a NS color
1574 -------------------------------------------------------------------------- */
1576 NSTRACE
(ns_lisp_to_color
);
1577 if (STRINGP
(color
))
1578 return ns_get_color
(SSDATA
(color
), col
);
1579 else if (SYMBOLP
(color
))
1580 return ns_get_color
(SSDATA
(SYMBOL_NAME
(color
)), col
);
1586 ns_color_to_lisp
(NSColor
*col
)
1587 /* --------------------------------------------------------------------------
1588 Convert a color to a lisp string with the RGB equivalent
1589 -------------------------------------------------------------------------- */
1591 CGFloat red
, green
, blue
, alpha
, gray;
1594 NSTRACE
(ns_color_to_lisp
);
1597 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1599 if ((str
=[[col colorNameComponent
] UTF8String
]))
1602 return build_string
((char *)str
);
1605 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1606 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1607 if (red
==green
&& red
==blue
)
1609 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1610 getWhite
: &gray alpha
: &alpha
];
1611 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1612 lrint
(gray * 0xff), lrint
(gray * 0xff), lrint
(gray * 0xff));
1614 return build_string
(buf
);
1617 snprintf
(buf
, sizeof
(buf
), "#
%2.2lx%2.2lx%2.2lx",
1618 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1621 return build_string
(buf
);
1626 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1627 /* --------------------------------------------------------------------------
1628 Get ARGB values out of NSColor col and put them into color_def.
1629 If setPixel, set the pixel to a concatenated version.
1630 and set color_def pixel to the resulting index.
1631 -------------------------------------------------------------------------- */
1635 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1636 color_def
->red
= r
* 65535;
1637 color_def
->green
= g
* 65535;
1638 color_def
->blue
= b
* 65535;
1640 if (setPixel
== YES
)
1642 = ARGB_TO_ULONG
((int
)(a
*255),
1643 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1648 ns_defined_color
(struct frame
*f
,
1653 /* --------------------------------------------------------------------------
1654 Return true if named color found, and set color_def rgb accordingly.
1655 If makeIndex and alloc are nonzero put the color in the color_table,
1656 and set color_def pixel to the resulting index.
1657 If makeIndex is zero, set color_def pixel to ARGB.
1658 Return false if not found
1659 -------------------------------------------------------------------------- */
1662 NSTRACE
(ns_defined_color
);
1665 if (ns_get_color
(name
, &col
) != 0) /* Color not found */
1670 if (makeIndex
&& alloc
)
1671 color_def
->pixel
= ns_index_color
(col
, f
);
1672 ns_query_color
(col
, color_def
, !makeIndex
);
1679 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1680 /* --------------------------------------------------------------------------
1681 return an autoreleased RGB color
1682 -------------------------------------------------------------------------- */
1684 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1685 if (r
< 0.0) r
= 0.0;
1686 else if (r
> 1.0) r
= 1.0;
1687 if (g
< 0.0) g
= 0.0;
1688 else if (g
> 1.0) g
= 1.0;
1689 if (b
< 0.0) b
= 0.0;
1690 else if (b
> 1.0) b
= 1.0;
1691 if (a
< 0.0) a
= 0.0;
1692 else if (a
> 1.0) a
= 1.0;
1693 return (unsigned
long) ns_index_color
(
1694 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1699 x_set_frame_alpha
(struct frame
*f
)
1700 /* --------------------------------------------------------------------------
1701 change the entire-frame transparency
1702 -------------------------------------------------------------------------- */
1704 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1705 EmacsView
*view = FRAME_NS_VIEW
(f
);
1707 double alpha_min
= 1.0;
1709 if (dpyinfo
->x_highlight_frame
== f
)
1710 alpha
= f
->alpha
[0];
1712 alpha
= f
->alpha
[1];
1714 if (FLOATP
(Vframe_alpha_lower_limit
))
1715 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1716 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1717 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1721 else if (1.0 < alpha
)
1723 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1726 #ifdef NS_IMPL_COCOA
1727 [[view window
] setAlphaValue
: alpha
];
1732 /* ==========================================================================
1736 ========================================================================== */
1740 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1741 /* --------------------------------------------------------------------------
1742 Programmatically reposition mouse pointer in pixel coordinates
1743 -------------------------------------------------------------------------- */
1745 NSTRACE
(x_set_mouse_pixel_position
);
1748 /* FIXME: this does not work, and what about GNUstep? */
1749 #ifdef NS_IMPL_COCOA
1750 [FRAME_NS_VIEW
(f
) lockFocus
];
1751 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1752 [FRAME_NS_VIEW
(f
) unlockFocus
];
1759 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1760 /* --------------------------------------------------------------------------
1761 Programmatically reposition mouse pointer in character coordinates
1762 -------------------------------------------------------------------------- */
1766 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1767 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1769 if (pix_x
< 0) pix_x
= 0;
1770 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1772 if (pix_y
< 0) pix_y
= 0;
1773 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1775 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1780 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1781 /* ------------------------------------------------------------------------
1782 Called by EmacsView on mouseMovement events. Passes on
1783 to emacs mainstream code if we moved off of a rect of interest
1784 known as last_mouse_glyph.
1785 ------------------------------------------------------------------------ */
1787 // NSTRACE
(note_mouse_movement
);
1789 XSETFRAME
(last_mouse_motion_frame
, frame
);
1791 /* Note, this doesn't get called for enter/leave, since we don't have a
1792 position. Those are taken care of in the corresponding NSView methods. */
1794 /* has movement gone beyond last rect we were tracking? */
1795 if (x
< last_mouse_glyph.origin.x ||
1796 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1797 y
< last_mouse_glyph.origin.y ||
1798 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1800 ns_update_begin
(frame
);
1801 frame
->mouse_moved
= 1;
1802 note_mouse_highlight
(frame
, x
, y
);
1803 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1804 ns_update_end
(frame
);
1813 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1814 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1816 /* --------------------------------------------------------------------------
1817 External (hook): inform emacs about mouse position and hit parts.
1818 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1819 x & y should be position in the scrollbar (the whole bar, not the handle)
1820 and length of scrollbar respectively
1821 -------------------------------------------------------------------------- */
1825 Lisp_Object frame
, tail
;
1827 struct ns_display_info
*dpyinfo
;
1829 NSTRACE
(ns_mouse_position
);
1833 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1837 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1841 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1843 /* TODO: we do not use this path at the moment because drag events will
1844 go directly to the EmacsScroller. Leaving code in for now. */
1845 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1847 if (time
) *time
= last_mouse_movement_time
;
1848 last_mouse_scroll_bar
= nil
;
1852 /* Clear the mouse-moved flag for every frame on this display. */
1853 FOR_EACH_FRAME
(tail
, frame
)
1854 if (FRAME_NS_P
(XFRAME
(frame
))
1855 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1856 XFRAME
(frame
)->mouse_moved
= 0;
1858 last_mouse_scroll_bar
= nil
;
1859 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1860 f
= last_mouse_frame
;
1862 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1863 : SELECTED_FRAME
();
1865 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1867 view = FRAME_NS_VIEW
(*fp
);
1869 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1870 position
= [view convertPoint
: position fromView
: nil
];
1871 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1872 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1874 if (bar_window
) *bar_window
= Qnil
;
1875 if (part
) *part
= 0; /*scroll_bar_handle; */
1877 if (x
) XSETINT
(*x
, lrint
(position.x
));
1878 if (y
) XSETINT
(*y
, lrint
(position.y
));
1879 if (time
) *time
= last_mouse_movement_time
;
1889 ns_frame_up_to_date
(struct frame
*f
)
1890 /* --------------------------------------------------------------------------
1891 External (hook): Fix up mouse highlighting right after a full update.
1892 Some highlighting was deferred if GC was happening during
1893 note_mouse_highlight (), while other highlighting was deferred for update.
1894 -------------------------------------------------------------------------- */
1896 NSTRACE
(ns_frame_up_to_date
);
1900 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(f
);
1901 if ((hlinfo
->mouse_face_deferred_gc || f
==hlinfo
->mouse_face_mouse_frame
)
1902 /*&& hlinfo->mouse_face_mouse_frame*/)
1906 if (hlinfo
->mouse_face_mouse_frame
)
1907 note_mouse_highlight
(hlinfo
->mouse_face_mouse_frame
,
1908 hlinfo
->mouse_face_mouse_x
,
1909 hlinfo
->mouse_face_mouse_y
);
1910 hlinfo
->mouse_face_deferred_gc
= 0;
1919 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1920 /* --------------------------------------------------------------------------
1921 External (RIF): set frame mouse pointer type.
1922 -------------------------------------------------------------------------- */
1924 NSTRACE
(ns_define_frame_cursor
);
1925 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1927 EmacsView
*view = FRAME_NS_VIEW
(f
);
1928 FRAME_POINTER_TYPE
(f
) = cursor
;
1929 [[view window
] invalidateCursorRectsForView
: view];
1930 /* Redisplay assumes this function also draws the changed frame
1931 cursor, but this function doesn't, so do it explicitly. */
1932 x_update_cursor
(f
, 1);
1938 /* ==========================================================================
1942 ========================================================================== */
1946 ns_convert_key
(unsigned code
)
1947 /* --------------------------------------------------------------------------
1948 Internal call used by NSView-keyDown.
1949 -------------------------------------------------------------------------- */
1951 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1952 / sizeof
(convert_ns_to_X_keysym
[0]));
1954 /* An array would be faster, but less easy to read. */
1955 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1956 if (code
== convert_ns_to_X_keysym
[keysym
])
1957 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1959 /* if decide to use keyCode and Carbon table, use this line:
1960 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1965 x_get_keysym_name
(int keysym
)
1966 /* --------------------------------------------------------------------------
1967 Called by keyboard.c. Not sure if the return val is important, except
1969 -------------------------------------------------------------------------- */
1971 static
char value
[16];
1972 NSTRACE
(x_get_keysym_name
);
1973 sprintf (value
, "
%d", keysym);
1979 /* ==========================================================================
1981 Block drawing operations
1983 ========================================================================== */
1987 ns_redraw_scroll_bars
(struct frame
*f
)
1991 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1992 NSTRACE
(ns_redraw_scroll_bars
);
1993 for (i
=[subviews count
]-1; i
>= 0; i
--)
1995 view = [subviews objectAtIndex
: i
];
1996 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
2003 ns_clear_frame
(struct frame
*f
)
2004 /* --------------------------------------------------------------------------
2005 External (hook): Erase the entire frame
2006 -------------------------------------------------------------------------- */
2008 NSView
*view = FRAME_NS_VIEW
(f
);
2011 NSTRACE
(ns_clear_frame
);
2013 /* comes on initial frame because we have
2014 after-make-frame-functions = select-frame */
2015 if (!FRAME_DEFAULT_FACE
(f
))
2018 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
2020 output_cursor.hpos
= output_cursor.vpos
= 0;
2021 output_cursor.x
= -1;
2026 ns_focus
(f
, &r
, 1);
2027 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
2031 /* as of 2006/11 or so this is now needed */
2032 ns_redraw_scroll_bars
(f
);
2038 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
2039 /* --------------------------------------------------------------------------
2040 External (RIF): Clear section of frame
2041 -------------------------------------------------------------------------- */
2043 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
2044 NSView
*view = FRAME_NS_VIEW
(f
);
2045 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
2050 NSTRACE
(ns_clear_frame_area
);
2052 r
= NSIntersectionRect
(r
, [view frame
]);
2053 ns_focus
(f
, &r
, 1);
2054 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
2064 ns_scroll_run
(struct window
*w
, struct run
*run
)
2065 /* --------------------------------------------------------------------------
2066 External (RIF): Insert or delete n lines at line vpos
2067 -------------------------------------------------------------------------- */
2069 struct frame
*f
= XFRAME
(w
->frame
);
2070 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2072 NSTRACE
(ns_scroll_run
);
2074 /* begin copy from other terms */
2075 /* Get frame-relative bounding box of the text display area of W,
2076 without mode lines. Include in this box the left and right
2078 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2080 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2081 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2082 bottom_y
= y
+ height
;
2086 /* Scrolling up. Make sure we don't copy part of the mode
2087 line at the bottom. */
2088 if (from_y
+ run
->height
> bottom_y
)
2089 height
= bottom_y
- from_y
;
2091 height
= run
->height
;
2095 /* Scrolling down. Make sure we don't copy over the mode line.
2097 if (to_y
+ run
->height
> bottom_y
)
2098 height
= bottom_y
- to_y
;
2100 height
= run
->height
;
2102 /* end copy from other terms */
2113 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2114 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2115 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2117 ns_focus
(f
, &dstRect
, 1);
2118 NSCopyBits
(0, srcRect
, dstOrigin
);
2127 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2128 /* --------------------------------------------------------------------------
2129 External (RIF): preparatory to fringe update after text was updated
2130 -------------------------------------------------------------------------- */
2132 struct window
*w
= updated_window
;
2136 NSTRACE
(ns_after_update_window_line
);
2138 /* begin copy from other terms */
2141 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2142 desired_row
->redraw_fringe_bitmaps_p
= 1;
2144 /* When a window has disappeared, make sure that no rest of
2145 full-width rows stays visible in the internal border. */
2146 if (windows_or_buffers_changed
2147 && desired_row
->full_width_p
2148 && (f
= XFRAME
(w
->frame
),
2149 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2151 && (height
= desired_row
->visible_height
,
2154 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2157 ns_clear_frame_area
(f
, 0, y
, width
, height
);
2158 ns_clear_frame_area
(f
,
2159 FRAME_PIXEL_WIDTH
(f
) - width
,
2167 ns_shift_glyphs_for_insert
(struct frame
*f
,
2168 int x
, int y
, int width
, int height
,
2170 /* --------------------------------------------------------------------------
2171 External (RIF): copy an area horizontally, don't worry about clearing src
2172 -------------------------------------------------------------------------- */
2174 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2175 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2176 NSPoint dstOrigin
= dstRect.origin
;
2178 NSTRACE
(ns_shift_glyphs_for_insert
);
2180 ns_focus
(f
, &dstRect
, 1);
2181 NSCopyBits
(0, srcRect
, dstOrigin
);
2187 /* ==========================================================================
2189 Character encoding and metrics
2191 ========================================================================== */
2195 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2196 /* --------------------------------------------------------------------------
2197 External (RIF); compute left/right overhang of whole string and set in s
2198 -------------------------------------------------------------------------- */
2200 struct font
*font
= s
->font
;
2204 struct font_metrics metrics
;
2205 unsigned int codes
[2];
2206 codes
[0] = *(s
->char2b
);
2207 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2209 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2210 s
->left_overhang
= -metrics.lbearing
;
2212 = metrics.rbearing
> metrics.width
2213 ? metrics.rbearing
- metrics.width
: 0;
2217 s
->left_overhang
= 0;
2218 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2219 FONT_HEIGHT
(font
) * 0.2 : 0;
2225 /* ==========================================================================
2227 Fringe and cursor drawing
2229 ========================================================================== */
2232 extern int max_used_fringe_bitmap
;
2234 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2235 struct draw_fringe_bitmap_params
*p
)
2236 /* --------------------------------------------------------------------------
2237 External (RIF); fringe-related
2238 -------------------------------------------------------------------------- */
2240 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2241 struct face
*face
= p
->face
;
2243 static EmacsImage
**bimgs
= NULL;
2244 static int nBimgs
= 0;
2246 /* grow bimgs if needed */
2247 if (nBimgs
< max_used_fringe_bitmap
)
2249 bimgs
= xrealloc
(bimgs
, max_used_fringe_bitmap
* sizeof
*bimgs
);
2250 memset
(bimgs
+ nBimgs
, 0,
2251 (max_used_fringe_bitmap
- nBimgs
) * sizeof
*bimgs
);
2252 nBimgs
= max_used_fringe_bitmap
;
2255 /* Must clip because of partially visible lines. */
2256 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2257 ns_clip_to_row
(w
, row
, -1, YES
);
2261 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
2263 /* If the fringe is adjacent to the left (right) scroll bar of a
2264 leftmost (rightmost, respectively) window, then extend its
2265 background to the gap between the fringe and the bar. */
2266 if ((WINDOW_LEFTMOST_P
(w
)
2267 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(w
))
2268 ||
(WINDOW_RIGHTMOST_P
(w
)
2269 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT
(w
)))
2271 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH
(w
);
2275 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X
(w
);
2276 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS
(w
)
2277 * FRAME_COLUMN_WIDTH
(f
));
2281 /* Bitmap fills the fringe. */
2282 if (bar_area_x
+ bar_area_width
== p
->x
)
2283 bx
= bar_area_x
+ sb_width
;
2284 else if (p
->x
+ p
->wd
== bar_area_x
)
2288 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT
(w
);
2290 nx
= bar_area_width
- sb_width
;
2291 by
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (header_line_height
,
2293 ny
= row
->visible_height
;
2298 if (bar_area_x
+ bar_area_width
== bx
)
2300 bx
= bar_area_x
+ sb_width
;
2301 nx
+= bar_area_width
- sb_width
;
2303 else if (bx
+ nx
== bar_area_x
)
2304 nx
+= bar_area_width
- sb_width
;
2309 if (bx
>= 0 && nx
> 0)
2311 NSRect r
= NSMakeRect
(bx
, by
, nx
, ny
);
2313 [ns_lookup_indexed_color
(face
->background
, f
) set];
2320 NSRect r
= NSMakeRect
(p
->x
, p
->y
, p
->wd
, p
->h
);
2321 EmacsImage
*img
= bimgs
[p
->which - 1];
2325 unsigned short
*bits
= p
->bits
+ p
->dh
;
2328 unsigned
char *cbits
= xmalloc
(len
);
2330 for (i
= 0; i
< len
; i
++)
2331 cbits
[i
] = ~
(bits
[i
] & 0xff);
2332 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2334 bimgs
[p
->which - 1] = img
;
2339 /* Since we composite the bitmap instead of just blitting it, we need
2340 to erase the whole background. */
2341 [ns_lookup_indexed_color
(face
->background
, f
) set];
2343 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2344 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
2346 fromRect
: NSZeroRect
2347 operation
: NSCompositeSourceOver
2353 NSPoint pt
= r.origin
;
2355 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2364 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2365 int x
, int y
, int cursor_type
, int cursor_width
,
2366 int on_p
, int active_p
)
2367 /* --------------------------------------------------------------------------
2368 External call (RIF): draw cursor.
2369 Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
2370 -------------------------------------------------------------------------- */
2373 int fx
, fy
, h
, cursor_height
;
2374 struct frame
*f
= WINDOW_XFRAME
(w
);
2375 struct glyph
*phys_cursor_glyph
;
2377 struct glyph
*cursor_glyph
;
2379 NSColor
*hollow_color
= FRAME_BACKGROUND_COLOR
(f
);
2381 /* If cursor is out of bounds, don't draw garbage. This can happen
2382 in mini-buffer windows when switching between echo area glyphs
2385 NSTRACE
(dumpcursor
);
2390 w
->phys_cursor_type
= cursor_type
;
2391 w
->phys_cursor_on_p
= on_p
;
2393 if (cursor_type
== NO_CURSOR
)
2395 w
->phys_cursor_width
= 0;
2399 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2401 if (glyph_row
->exact_window_width_line_p
2402 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2404 glyph_row
->cursor_in_fringe_p
= 1;
2405 draw_fringe_bitmap
(w
, glyph_row
, 0);
2410 /* We draw the cursor (with NSRectFill), then draw the glyph on top
2411 (other terminals do it the other way round). We must set
2412 w->phys_cursor_width to the cursor width. For bar cursors, that
2413 is CURSOR_WIDTH; for box cursors, it is the glyph width. */
2414 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2416 /* The above get_phys_cursor_geometry call set w->phys_cursor_width
2417 to the glyph width; replace with CURSOR_WIDTH for (V)BAR cursors. */
2418 if (cursor_type
== BAR_CURSOR
)
2420 if (cursor_width
< 1)
2421 cursor_width
= max (FRAME_CURSOR_WIDTH
(f
), 1);
2422 w
->phys_cursor_width
= cursor_width
;
2424 /* If we have an HBAR, "cursor_width" MAY specify height. */
2425 else if (cursor_type
== HBAR_CURSOR
)
2427 cursor_height
= (cursor_width
< 1) ? lrint
(0.25 * h
) : cursor_width
;
2428 fy
+= h
- cursor_height
;
2432 r.origin.x
= fx
, r.origin.y
= fy
;
2434 r.
size.width
= w
->phys_cursor_width
;
2436 /* TODO: only needed in rare cases with last-resort font in HELLO..
2437 should we do this more efficiently? */
2438 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2441 face
= FACE_FROM_ID
(f
, phys_cursor_glyph
->face_id
);
2442 if (face
&& NS_FACE_BACKGROUND
(face
)
2443 == ns_index_color
(FRAME_CURSOR_COLOR
(f
), f
))
2445 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), f
) set];
2446 hollow_color
= FRAME_CURSOR_COLOR
(f
);
2449 [FRAME_CURSOR_COLOR
(f
) set];
2451 #ifdef NS_IMPL_COCOA
2452 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2453 atomic. Cleaner ways of doing this should be investigated.
2454 One way would be to set a global variable DRAWING_CURSOR
2455 when making the call to draw_phys..(), don't focus in that
2456 case, then move the ns_unfocus() here after that call. */
2457 NSDisableScreenUpdates
();
2460 switch (cursor_type
)
2464 case FILLED_BOX_CURSOR
:
2467 case HOLLOW_BOX_CURSOR
:
2470 NSRectFill
(NSInsetRect
(r
, 1, 1));
2471 [FRAME_CURSOR_COLOR
(f
) set];
2478 /* If the character under cursor is R2L, draw the bar cursor
2479 on the right of its glyph, rather than on the left. */
2480 cursor_glyph
= get_phys_cursor_glyph
(w
);
2481 if ((cursor_glyph
->resolved_level
& 1) != 0)
2482 s.origin.x
+= cursor_glyph
->pixel_width
- s.
size.width
;
2489 /* draw the character under the cursor */
2490 if (cursor_type
!= NO_CURSOR
)
2491 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2493 #ifdef NS_IMPL_COCOA
2494 NSEnableScreenUpdates
();
2501 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2502 /* --------------------------------------------------------------------------
2503 External (RIF): Draw a vertical line.
2504 -------------------------------------------------------------------------- */
2506 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2508 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2510 NSTRACE
(ns_draw_vertical_window_border
);
2512 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2514 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2516 ns_focus
(f
, &r
, 1);
2523 show_hourglass
(struct atimer
*timer
)
2525 if (hourglass_shown_p
)
2530 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2532 hourglass_shown_p
= 1;
2538 hide_hourglass
(void
)
2540 if (!hourglass_shown_p
)
2545 /* TODO: remove NSProgressIndicator from all frames */
2547 hourglass_shown_p
= 0;
2553 /* ==========================================================================
2555 Glyph drawing operations
2557 ========================================================================== */
2560 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2561 /* --------------------------------------------------------------------------
2562 Wrapper utility to account for internal border width on full-width lines,
2563 and allow top full-width rows to hit the frame top. nr should be pointer
2564 to two successive NSRects. Number of rects actually used is returned.
2565 -------------------------------------------------------------------------- */
2567 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2571 /* --------------------------------------------------------------------
2572 Draw a wavy line under glyph string s. The wave fills wave_height
2579 wave_height = 3 | * * * *
2580 --------------------------------------------------------------------- */
2583 ns_draw_underwave
(struct glyph_string
*s
, CGFloat width
, CGFloat x
)
2585 int wave_height
= 3, wave_length
= 3;
2586 int y
, dx
, dy
, odd
, xmax
;
2591 dy
= wave_height
- 1;
2595 /* Find and set clipping rectangle */
2596 waveClip
= NSMakeRect
(x
, y
, width
, wave_height
);
2597 [[NSGraphicsContext currentContext
] saveGraphicsState
];
2598 NSRectClip
(waveClip
);
2600 /* Draw the waves */
2601 a.x
= x
- ((int
)(x
) % dx);
2603 odd
= (int
)(a.x
/dx
) % 2;
2613 [NSBezierPath strokeLineFromPoint
:a toPoint
:b
];
2614 a.x
= b.x
, a.y
= b.y
;
2615 b.x
+= dx
, b.y
= y
+ odd
*dy
;
2619 /* Restore previous clipping rectangle(s) */
2620 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
2626 ns_draw_text_decoration
(struct glyph_string
*s
, struct face
*face
,
2627 NSColor
*defaultCol
, CGFloat width
, CGFloat x
)
2628 /* --------------------------------------------------------------------------
2629 Draw underline, overline, and strike-through on glyph string s.
2630 -------------------------------------------------------------------------- */
2632 if (s
->for_overlaps
)
2636 if (face
->underline_p
)
2638 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2640 if (face
->underline_defaulted_p
)
2643 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2645 ns_draw_underwave
(s
, width
, x
);
2647 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2651 unsigned
long thickness
, position
;
2653 /* If the prev was underlined, match its appearance. */
2654 if (s
->prev
&& s
->prev
->face
->underline_p
2655 && s
->prev
->underline_thickness
> 0)
2657 thickness
= s
->prev
->underline_thickness
;
2658 position
= s
->prev
->underline_position
;
2663 unsigned
long descent
;
2666 descent
= s
->y
+ s
->height
- s
->ybase
;
2668 /* Use underline thickness of font, defaulting to 1. */
2669 thickness
= (font
&& font
->underline_thickness
> 0)
2670 ? font
->underline_thickness
: 1;
2672 /* Determine the offset of underlining from the baseline. */
2673 if (x_underline_at_descent_line
)
2674 position
= descent
- thickness
;
2675 else if (x_use_underline_position_properties
2676 && font
&& font
->underline_position
>= 0)
2677 position
= font
->underline_position
;
2679 position
= lround
(font
->descent
/ 2);
2681 position
= underline_minimum_offset
;
2683 position
= max (position
, underline_minimum_offset
);
2685 /* Ensure underlining is not cropped. */
2686 if (descent
<= position
)
2688 position
= descent
- 1;
2691 else if (descent
< position
+ thickness
)
2695 s
->underline_thickness
= thickness
;
2696 s
->underline_position
= position
;
2698 r
= NSMakeRect
(x
, s
->ybase
+ position
, width
, thickness
);
2700 if (face
->underline_defaulted_p
)
2703 [ns_lookup_indexed_color
(face
->underline_color
, s
->f
) set];
2707 /* Do overline. We follow other terms in using a thickness of 1
2708 and ignoring overline_margin. */
2709 if (face
->overline_p
)
2712 r
= NSMakeRect
(x
, s
->y
, width
, 1);
2714 if (face
->overline_color_defaulted_p
)
2717 [ns_lookup_indexed_color
(face
->overline_color
, s
->f
) set];
2721 /* Do strike-through. We follow other terms for thickness and
2722 vertical position.*/
2723 if (face
->strike_through_p
)
2728 dy
= lrint
((s
->height
- 1) / 2);
2729 r
= NSMakeRect
(x
, s
->y
+ dy
, width
, 1);
2731 if (face
->strike_through_color_defaulted_p
)
2734 [ns_lookup_indexed_color
(face
->strike_through_color
, s
->f
) set];
2740 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2741 /* --------------------------------------------------------------------------
2742 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2743 Note we can't just use an NSDrawRect command, because of the possibility
2744 of some sides not being drawn, and because the rect will be filled.
2745 -------------------------------------------------------------------------- */
2751 s.
size.height
= thickness
;
2753 s.origin.y
+= r.
size.height
- thickness
;
2756 s.
size.height
= r.
size.height
;
2757 s.origin.y
= r.origin.y
;
2759 /* left, right (optional) */
2760 s.
size.width
= thickness
;
2765 s.origin.x
+= r.
size.width
- thickness
;
2772 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2773 char top_p
, char bottom_p
, char left_p
, char right_p
,
2774 struct glyph_string
*s
)
2775 /* --------------------------------------------------------------------------
2776 Draw a relief rect inside r, optionally leaving some sides open.
2777 Note we can't just use an NSDrawBezel command, because of the possibility
2778 of some sides not being drawn, and because the rect will be filled.
2779 -------------------------------------------------------------------------- */
2781 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2782 NSColor
*newBaseCol
= nil
;
2785 NSTRACE
(ns_draw_relief
);
2789 if (s
->face
->use_box_color_for_shadows_p
)
2791 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2793 /* else if (s->first_glyph->type == IMAGE_GLYPH
2795 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2797 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2801 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2804 if (newBaseCol
== nil
)
2805 newBaseCol
= [NSColor grayColor
];
2807 if (newBaseCol
!= baseCol
) /* TODO: better check */
2810 baseCol
= [newBaseCol retain
];
2812 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2814 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2817 [(raised_p ? lightCol
: darkCol
) set];
2819 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2822 sr.
size.height
= thickness
;
2823 if (top_p
) NSRectFill
(sr
);
2826 sr.
size.height
= r.
size.height
;
2827 sr.
size.width
= thickness
;
2828 if (left_p
) NSRectFill
(sr
);
2830 [(raised_p ? darkCol
: lightCol
) set];
2833 sr.
size.width
= r.
size.width
;
2834 sr.
size.height
= thickness
;
2835 sr.origin.y
+= r.
size.height
- thickness
;
2836 if (bottom_p
) NSRectFill
(sr
);
2839 sr.
size.height
= r.
size.height
;
2840 sr.origin.y
= r.origin.y
;
2841 sr.
size.width
= thickness
;
2842 sr.origin.x
+= r.
size.width
- thickness
;
2843 if (right_p
) NSRectFill
(sr
);
2848 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2849 /* --------------------------------------------------------------------------
2850 Function modeled after x_draw_glyph_string_box ().
2851 Sets up parameters for drawing.
2852 -------------------------------------------------------------------------- */
2854 int right_x
, last_x
;
2855 char left_p
, right_p
;
2856 struct glyph
*last_glyph
;
2861 if (s
->hl
== DRAW_MOUSE_FACE
)
2863 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2865 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2870 thickness
= face
->box_line_width
;
2872 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2874 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2875 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2876 : window_box_right
(s
->w
, s
->area
));
2877 last_glyph
= (s
->cmp || s
->img
2878 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2880 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2881 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2883 left_p
= (s
->first_glyph
->left_box_line_p
2884 ||
(s
->hl
== DRAW_MOUSE_FACE
2885 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2886 right_p
= (last_glyph
->right_box_line_p
2887 ||
(s
->hl
== DRAW_MOUSE_FACE
2888 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2890 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2892 /* TODO: Sometimes box_color is 0 and this seems wrong; should investigate. */
2893 if (s
->face
->box
== FACE_SIMPLE_BOX
&& s
->face
->box_color
)
2895 ns_draw_box
(r
, abs (thickness
),
2896 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2901 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2902 1, 1, left_p
, right_p
, s
);
2908 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2909 /* --------------------------------------------------------------------------
2910 Modeled after x_draw_glyph_string_background, which draws BG in
2911 certain cases. Others are left to the text rendering routine.
2912 -------------------------------------------------------------------------- */
2914 NSTRACE
(ns_maybe_dumpglyphs_background
);
2916 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2918 int box_line_width
= max (s
->face
->box_line_width
, 0);
2919 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2920 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2923 if (s
->hl
== DRAW_MOUSE_FACE
)
2925 face
= FACE_FROM_ID
(s
->f
,
2926 MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2928 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2931 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2933 [(NS_FACE_BACKGROUND
(face
) != 0
2934 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2935 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2938 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2939 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2942 if (s
->hl
!= DRAW_CURSOR
)
2944 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2945 s
->background_width
,
2946 s
->height
-2*box_line_width
);
2950 s
->background_filled_p
= 1;
2957 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2958 /* --------------------------------------------------------------------------
2959 Renders an image and associated borders.
2960 -------------------------------------------------------------------------- */
2962 EmacsImage
*img
= s
->img
->pixmap
;
2963 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2964 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2965 int bg_x
, bg_y
, bg_height
;
2972 NSTRACE
(ns_dumpglyphs_image
);
2974 if (s
->face
->box
!= FACE_NO_BOX
2975 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
2976 x
+= abs (s
->face
->box_line_width
);
2979 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
2980 bg_height
= s
->height
;
2981 /* other terms have this, but was causing problems w/tabbar mode */
2982 /* - 2 * box_line_vwidth; */
2984 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
2985 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
2987 /* Draw BG: if we need larger area than image itself cleared, do that,
2988 otherwise, since we composite the image under NS (instead of mucking
2989 with its background color), we must clear just the image area. */
2990 if (s
->hl
== DRAW_MOUSE_FACE
)
2992 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
2994 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2997 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2999 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
3001 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
3002 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
3004 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
3005 s
->background_filled_p
= 1;
3009 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3014 /* Draw the image.. do we need to draw placeholder if img ==nil? */
3017 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
3018 NSRect dr
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
3019 NSRect ir
= NSMakeRect
(s
->slice.x
, s
->slice.y
,
3020 s
->slice.width
, s
->slice.height
);
3023 operation
: NSCompositeSourceOver
3028 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
3029 operation
: NSCompositeSourceOver
];
3033 if (s
->hl
== DRAW_CURSOR
)
3035 [FRAME_CURSOR_COLOR
(s
->f
) set];
3036 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3037 tdCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3039 /* Currently on NS img->mask is always 0. Since
3040 get_window_cursor_type specifies a hollow box cursor when on
3041 a non-masked image we never reach this clause. But we put it
3042 in in anticipation of better support for image masks on
3044 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3048 tdCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3051 /* Draw underline, overline, strike-through. */
3052 ns_draw_text_decoration
(s
, face
, tdCol
, br.
size.width
, br.origin.x
);
3054 /* Draw relief, if requested */
3055 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
3057 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
3059 th
= tool_bar_button_relief
>= 0 ?
3060 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3061 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
3065 th
= abs (s
->img
->relief
);
3066 raised_p
= (s
->img
->relief
> 0);
3069 r.origin.x
= x
- th
;
3070 r.origin.y
= y
- th
;
3071 r.
size.width
= s
->slice.width
+ 2*th
-1;
3072 r.
size.height
= s
->slice.height
+ 2*th
-1;
3073 ns_draw_relief
(r
, th
, raised_p
,
3075 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
3077 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
3080 /* If there is no mask, the background won't be seen,
3081 so draw a rectangle on the image for the cursor.
3082 Do this for all images, getting transparency right is not reliable. */
3083 if (s
->hl
== DRAW_CURSOR
)
3085 int thickness
= abs (s
->img
->relief
);
3086 if (thickness
== 0) thickness
= 1;
3087 ns_draw_box
(br
, thickness
, FRAME_CURSOR_COLOR
(s
->f
), 1, 1);
3093 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
3098 NSColor
*fgCol
, *bgCol
;
3100 if (!s
->background_filled_p
)
3102 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3103 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
3105 ns_focus
(s
->f
, r
, n
);
3107 if (s
->hl
== DRAW_MOUSE_FACE
)
3109 face
= FACE_FROM_ID
(s
->f
, MOUSE_HL_INFO
(s
->f
)->mouse_face_face_id
);
3111 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
3114 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
3116 bgCol
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
);
3117 fgCol
= ns_lookup_indexed_color
(NS_FACE_FOREGROUND
(face
), s
->f
);
3119 for (i
= 0; i
< n
; ++i
)
3121 if (!s
->row
->full_width_p
)
3123 int overrun
, leftoverrun
;
3125 /* truncate to avoid overwriting fringe and/or scrollbar */
3126 overrun
= max (0, (s
->x
+ s
->background_width
)
3127 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
3128 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
3129 r
[i
].
size.width
-= overrun
;
3131 /* truncate to avoid overwriting to left of the window box */
3132 leftoverrun
= (WINDOW_BOX_LEFT_EDGE_X
(s
->w
)
3133 + WINDOW_LEFT_FRINGE_WIDTH
(s
->w
)) - s
->x
;
3135 if (leftoverrun
> 0)
3137 r
[i
].origin.x
+= leftoverrun
;
3138 r
[i
].
size.width
-= leftoverrun
;
3141 /* XXX: Try to work between problem where a stretch glyph on
3142 a partially-visible bottom row will clear part of the
3143 modeline, and another where list-buffers headers and similar
3144 rows erroneously have visible_height set to 0. Not sure
3145 where this is coming from as other terms seem not to show. */
3146 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
3151 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
3152 overwriting cursor (usually when cursor on a tab) */
3153 if (s
->hl
== DRAW_CURSOR
)
3158 width
= s
->w
->phys_cursor_width
;
3159 r
[i
].
size.width
-= width
;
3160 r
[i
].origin.x
+= width
;
3164 /* Draw overlining, etc. on the cursor. */
3165 if (s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3166 ns_draw_text_decoration
(s
, face
, bgCol
, width
, x
);
3168 ns_draw_text_decoration
(s
, face
, fgCol
, width
, x
);
3175 /* Draw overlining, etc. on the stretch glyph (or the part
3176 of the stretch glyph after the cursor). */
3177 ns_draw_text_decoration
(s
, face
, fgCol
, r
[i
].
size.width
,
3181 s
->background_filled_p
= 1;
3187 ns_draw_glyph_string
(struct glyph_string
*s
)
3188 /* --------------------------------------------------------------------------
3189 External (RIF): Main draw-text call.
3190 -------------------------------------------------------------------------- */
3192 /* TODO (optimize): focus for box and contents draw */
3195 char box_drawn_p
= 0;
3197 NSTRACE
(ns_draw_glyph_string
);
3199 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3202 struct glyph_string
*next
;
3204 for (width
= 0, next
= s
->next
;
3205 next
&& width
< s
->right_overhang
;
3206 width
+= next
->width
, next
= next
->next
)
3207 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3209 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3211 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3212 ns_focus
(s
->f
, r
, n
);
3213 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3218 ns_dumpglyphs_stretch
(s
->next
);
3220 next
->num_clips
= 0;
3224 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3225 && (s
->first_glyph
->type == CHAR_GLYPH
3226 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3228 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3229 ns_focus
(s
->f
, r
, n
);
3230 ns_maybe_dumpglyphs_background
(s
, 1);
3231 ns_dumpglyphs_box_or_relief
(s
);
3236 switch (s
->first_glyph
->type)
3240 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3241 ns_focus
(s
->f
, r
, n
);
3242 ns_dumpglyphs_image
(s
, r
[0]);
3247 ns_dumpglyphs_stretch
(s
);
3251 case COMPOSITE_GLYPH
:
3252 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3253 ns_focus
(s
->f
, r
, n
);
3255 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3256 && ! s
->first_glyph
->u.cmp.automatic
))
3257 s
->background_filled_p
= 1;
3259 ns_maybe_dumpglyphs_background
3260 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3262 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3263 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3264 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3265 NS_DUMPGLYPH_NORMAL
));
3266 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3267 if (ns_tmp_font
== NULL)
3268 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3270 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3272 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3273 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3274 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3277 ns_tmp_font
->font.driver
->draw
3278 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3279 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3280 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
3282 if (s
->hl
== DRAW_CURSOR
&& s
->w
->phys_cursor_type
== FILLED_BOX_CURSOR
)
3284 unsigned
long tmp
= NS_FACE_BACKGROUND
(s
->face
);
3285 NS_FACE_BACKGROUND
(s
->face
) = NS_FACE_FOREGROUND
(s
->face
);
3286 NS_FACE_FOREGROUND
(s
->face
) = tmp
;
3292 case GLYPHLESS_GLYPH
:
3293 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3294 ns_focus
(s
->f
, r
, n
);
3296 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3297 && ! s
->first_glyph
->u.cmp.automatic
))
3298 s
->background_filled_p
= 1;
3300 ns_maybe_dumpglyphs_background
3301 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3303 /* Not yet implemented. */
3312 /* Draw box if not done already. */
3313 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3315 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3316 ns_focus
(s
->f
, r
, n
);
3317 ns_dumpglyphs_box_or_relief
(s
);
3326 /* ==========================================================================
3330 ========================================================================== */
3334 ns_send_appdefined
(int value
)
3335 /* --------------------------------------------------------------------------
3336 Internal: post an appdefined event which EmacsApp-sendEvent will
3337 recognize and take as a command to halt the event loop.
3338 -------------------------------------------------------------------------- */
3340 /*NSTRACE (ns_send_appdefined); */
3342 /* Only post this event if we haven't already posted one. This will end
3343 the [NXApp run] main loop after having processed all events queued at
3345 if (send_appdefined
)
3349 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3350 send_appdefined
= NO
;
3352 /* Don't need wakeup timer any more */
3355 [timed_entry invalidate
];
3356 [timed_entry release
];
3360 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3361 location
: NSMakePoint
(0, 0)
3364 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3365 context
: [NSApp context
]
3370 /* Post an application defined event on the event queue. When this is
3371 received the [NXApp run] will return, thus having processed all
3372 events which are currently queued. */
3373 [NSApp postEvent
: nxev atStart
: NO
];
3378 ns_read_socket
(struct terminal *terminal, struct input_event
*hold_quit
)
3379 /* --------------------------------------------------------------------------
3380 External (hook): Post an event to ourself and keep reading events until
3381 we read it back again. In effect process all events which were waiting.
3382 From 21+ we have to manage the event buffer ourselves.
3383 -------------------------------------------------------------------------- */
3385 struct input_event ev
;
3388 /* NSTRACE (ns_read_socket); */
3390 if ([NSApp modalWindow
] != nil
)
3393 if (hold_event_q.nr
> 0)
3396 for (i
= 0; i
< hold_event_q.nr
; ++i
)
3397 kbd_buffer_store_event_hold
(&hold_event_q.q
[i
], hold_quit
);
3398 hold_event_q.nr
= 0;
3403 n_emacs_events_pending
= 0;
3406 q_event_ptr
= hold_quit
;
3408 /* we manage autorelease pools by allocate/reallocate each time around
3409 the loop; strict nesting is occasionally violated but seems not to
3410 matter.. earlier methods using full nesting caused major memory leaks */
3411 [outerpool release
];
3412 outerpool
= [[NSAutoreleasePool alloc
] init
];
3414 /* If have pending open-file requests, attend to the next one of those. */
3415 if (ns_pending_files
&& [ns_pending_files count
] != 0
3416 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3418 [ns_pending_files removeObjectAtIndex
: 0];
3420 /* Deal with pending service requests. */
3421 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3423 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3424 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3426 [ns_pending_service_names removeObjectAtIndex
: 0];
3427 [ns_pending_service_args removeObjectAtIndex
: 0];
3431 /* Run and wait for events. We must always send one NX_APPDEFINED event
3432 to ourself, otherwise [NXApp run] will never exit. */
3433 send_appdefined
= YES
;
3434 ns_send_appdefined
(-1);
3436 if (++apploopnr
!= 1)
3444 nevents
= n_emacs_events_pending
;
3445 n_emacs_events_pending
= 0;
3446 emacs_event
= q_event_ptr
= NULL;
3454 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3455 fd_set
*exceptfds
, EMACS_TIME
*timeout
, sigset_t
*sigmask
)
3456 /* --------------------------------------------------------------------------
3457 Replacement for select, checking for events
3458 -------------------------------------------------------------------------- */
3462 struct input_event event
;
3465 /* NSTRACE (ns_select); */
3467 for (k
= 0; k
< nfds
+1; k
++)
3469 if (readfds
&& FD_ISSET
(k
, readfds
)) ++nr
;
3470 if (writefds
&& FD_ISSET
(k
, writefds
)) ++nr
;
3474 ||
(timeout
&& timeout
->tv_sec
== 0 && timeout
->tv_nsec
== 0))
3475 return pselect
(nfds
, readfds
, writefds
, exceptfds
, timeout
, sigmask
);
3477 [outerpool release
];
3478 outerpool
= [[NSAutoreleasePool alloc
] init
];
3481 send_appdefined
= YES
;
3484 pthread_mutex_lock
(&select_mutex
);
3489 select_readfds
= *readfds
;
3490 select_valid
+= SELECT_HAVE_READ
;
3494 select_writefds
= *writefds
;
3495 select_valid
+= SELECT_HAVE_WRITE
;
3500 select_timeout
= *timeout
;
3501 select_valid
+= SELECT_HAVE_TMO
;
3504 pthread_mutex_unlock
(&select_mutex
);
3506 /* Inform fd_handler that select should be called */
3508 emacs_write
(selfds
[1], &c
, 1);
3510 else if (nr
== 0 && timeout
)
3512 /* No file descriptor, just a timeout, no need to wake fd_handler */
3513 double time
= EMACS_TIME_TO_DOUBLE
(*timeout
);
3514 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3517 @selector
(timeout_handler
:)
3522 else /* No timeout and no file descriptors, can this happen? */
3524 /* Send appdefined so we exit from the loop */
3525 ns_send_appdefined
(-1);
3530 emacs_event
= &event
;
3531 if (++apploopnr
!= 1)
3538 if (nr
> 0 && readfds
)
3541 emacs_write
(selfds
[1], &c
, 1);
3545 t
= last_appdefined_event_data
;
3547 if (t
!= NO_APPDEFINED_DATA
)
3549 last_appdefined_event_data
= NO_APPDEFINED_DATA
;
3553 /* The NX_APPDEFINED event we received was a timeout. */
3558 /* The NX_APPDEFINED event we received was the result of
3559 at least one real input event arriving. */
3565 /* Received back from select () in fd_handler; copy the results */
3566 pthread_mutex_lock
(&select_mutex
);
3567 if (readfds
) *readfds
= select_readfds
;
3568 if (writefds
) *writefds
= select_writefds
;
3569 if (timeout
) *timeout
= select_timeout
;
3570 pthread_mutex_unlock
(&select_mutex
);
3580 /* ==========================================================================
3584 ========================================================================== */
3588 ns_set_vertical_scroll_bar
(struct window
*window
,
3589 int portion
, int whole
, int position
)
3590 /* --------------------------------------------------------------------------
3591 External (hook): Update or add scrollbar
3592 -------------------------------------------------------------------------- */
3596 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3597 EmacsView
*view = FRAME_NS_VIEW
(f
);
3598 int window_y
, window_height
;
3599 int top
, left
, height
, width
, sb_width
, sb_left
;
3601 BOOL fringe_extended_p
;
3603 /* optimization; display engine sends WAY too many of these.. */
3604 if (!NILP
(window
->vertical_scroll_bar
))
3606 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3607 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3609 if (view->scrollbarsNeedingUpdate
== 0)
3611 if (!windows_or_buffers_changed
)
3615 view->scrollbarsNeedingUpdate
--;
3619 NSTRACE
(ns_set_vertical_scroll_bar
);
3621 /* Get dimensions. */
3622 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3624 height
= window_height
;
3625 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3626 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3628 /* allow for displaying a skinnier scrollbar than char area allotted */
3629 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3630 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3633 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3634 /* the parent view is flipped, so we need to flip y value */
3636 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3638 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT
(window
))
3639 fringe_extended_p
= (WINDOW_LEFTMOST_P
(window
)
3640 && WINDOW_LEFT_FRINGE_WIDTH
(window
)
3641 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3642 || WINDOW_LEFT_MARGIN_COLS
(window
) == 0));
3644 fringe_extended_p
= (WINDOW_RIGHTMOST_P
(window
)
3645 && WINDOW_RIGHT_FRINGE_WIDTH
(window
)
3646 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS
(window
)
3647 || WINDOW_RIGHT_MARGIN_COLS
(window
) == 0));
3649 XSETWINDOW
(win
, window
);
3652 /* we want at least 5 lines to display a scrollbar */
3653 if (WINDOW_TOTAL_LINES
(window
) < 5)
3655 if (!NILP
(window
->vertical_scroll_bar
))
3657 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3658 [bar removeFromSuperview
];
3659 wset_vertical_scroll_bar
(window
, Qnil
);
3661 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3666 if (NILP
(window
->vertical_scroll_bar
))
3668 if (width
> 0 && height
> 0)
3670 if (fringe_extended_p
)
3671 ns_clear_frame_area
(f
, sb_left
, top
, sb_width
, height
);
3673 ns_clear_frame_area
(f
, left
, top
, width
, height
);
3676 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3677 wset_vertical_scroll_bar
(window
, make_save_value
(bar, 0));
3682 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3683 oldRect
= [bar frame
];
3684 r.
size.width
= oldRect.
size.width
;
3685 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3687 if (oldRect.origin.x
!= r.origin.x
)
3688 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3693 [bar setPosition
: position portion
: portion whole
: whole
];
3699 ns_condemn_scroll_bars
(struct frame
*f
)
3700 /* --------------------------------------------------------------------------
3701 External (hook): arrange for all frame's scrollbars to be removed
3702 at next call to judge_scroll_bars, except for those redeemed.
3703 -------------------------------------------------------------------------- */
3707 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3709 NSTRACE
(ns_condemn_scroll_bars
);
3711 for (i
=[subviews count
]-1; i
>= 0; i
--)
3713 view = [subviews objectAtIndex
: i
];
3714 if ([view isKindOfClass
: [EmacsScroller
class]])
3721 ns_redeem_scroll_bar
(struct window
*window
)
3722 /* --------------------------------------------------------------------------
3723 External (hook): arrange to spare this window's scrollbar
3724 at next call to judge_scroll_bars.
3725 -------------------------------------------------------------------------- */
3728 NSTRACE
(ns_redeem_scroll_bar
);
3729 if (!NILP
(window
->vertical_scroll_bar
))
3731 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3738 ns_judge_scroll_bars
(struct frame
*f
)
3739 /* --------------------------------------------------------------------------
3740 External (hook): destroy all scrollbars on frame that weren't
3741 redeemed after call to condemn_scroll_bars.
3742 -------------------------------------------------------------------------- */
3746 EmacsView
*eview
= FRAME_NS_VIEW
(f
);
3747 NSArray
*subviews
= [[eview superview
] subviews
];
3750 NSTRACE
(ns_judge_scroll_bars
);
3751 for (i
= [subviews count
]-1; i
>= 0; --i
)
3753 view = [subviews objectAtIndex
: i
];
3754 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3760 [eview updateFrameSize
: NO
];
3765 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3767 /* XXX irrelevant under NS */
3772 /* ==========================================================================
3776 ========================================================================== */
3779 x_display_pixel_height
(struct ns_display_info
*dpyinfo
)
3781 NSScreen
*screen
= [NSScreen mainScreen
];
3782 return [screen frame
].
size.height
;
3786 x_display_pixel_width
(struct ns_display_info
*dpyinfo
)
3788 NSScreen
*screen
= [NSScreen mainScreen
];
3789 return [screen frame
].
size.width
;
3793 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3794 /* --------------------------------------------------------------------------
3795 Convert modifier name to lisp symbol
3796 -------------------------------------------------------------------------- */
3798 if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3800 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3802 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3804 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3806 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3808 else if (!strncmp
(SSDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3816 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3817 Lisp_Object yesval
, Lisp_Object noval
,
3818 BOOL is_float
, BOOL is_modstring
)
3819 /* --------------------------------------------------------------------------
3820 Check a parameter value in user's preferences
3821 -------------------------------------------------------------------------- */
3823 const
char *value
= ns_get_defaults_value
(parameter
);
3829 if (c_strcasecmp
(value
, "YES"
) == 0)
3831 else if (c_strcasecmp
(value
, "NO"
) == 0)
3833 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3834 *result
= make_float
(f
);
3835 else if (is_modstring
&& value
)
3836 *result
= ns_string_to_lispmod
(value
);
3837 else fprintf (stderr
,
3838 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3844 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3845 /* --------------------------------------------------------------------------
3846 Initialize global info and storage for display.
3847 -------------------------------------------------------------------------- */
3849 NSScreen
*screen
= [NSScreen mainScreen
];
3850 NSWindowDepth depth
= [screen depth
];
3851 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
3853 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3854 dpyinfo
->resy
= 72.27;
3855 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3856 NSColorSpaceFromDepth
(depth
)]
3857 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3858 NSColorSpaceFromDepth
(depth
)];
3859 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3860 dpyinfo
->image_cache
= make_image_cache
();
3861 dpyinfo
->color_table
= xmalloc
(sizeof
*dpyinfo
->color_table
);
3862 dpyinfo
->color_table
->colors
= NULL;
3863 dpyinfo
->root_window
= 42; /* a placeholder.. */
3865 hlinfo
->mouse_face_mouse_frame
= NULL;
3866 hlinfo
->mouse_face_deferred_gc
= 0;
3867 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
3868 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
3869 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3870 hlinfo
->mouse_face_window
= hlinfo
->mouse_face_overlay
= Qnil
;
3871 hlinfo
->mouse_face_hidden
= 0;
3873 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
3874 hlinfo
->mouse_face_defer
= 0;
3876 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3878 dpyinfo
->n_fonts
= 0;
3879 dpyinfo
->smallest_font_height
= 1;
3880 dpyinfo
->smallest_char_width
= 1;
3884 /* This and next define (many of the) public functions in this file. */
3885 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3886 with using despite presence in the "system dependent" redisplay
3887 interface. In addition, many of the ns_ methods have code that is
3888 shared with all terms, indicating need for further refactoring. */
3889 extern frame_parm_handler ns_frame_parm_handlers
[];
3890 static
struct redisplay_interface ns_redisplay_interface
=
3892 ns_frame_parm_handlers
,
3896 x_clear_end_of_line
,
3898 ns_after_update_window_line
,
3899 ns_update_window_begin
,
3900 ns_update_window_end
,
3903 0, /* flush_display_optional */
3904 x_clear_window_mouse_face
,
3905 x_get_glyph_overhangs
,
3906 x_fix_overlapping_area
,
3907 ns_draw_fringe_bitmap
,
3908 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3909 0, /* destroy_fringe_bitmap */
3910 ns_compute_glyph_string_overhangs
,
3911 ns_draw_glyph_string
, /* interface to nsfont.m */
3912 ns_define_frame_cursor
,
3913 ns_clear_frame_area
,
3914 ns_draw_window_cursor
,
3915 ns_draw_vertical_window_border
,
3916 ns_shift_glyphs_for_insert
3921 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3927 /* This function is called when the last frame on a display is deleted. */
3929 ns_delete_terminal
(struct terminal *terminal)
3931 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3933 /* Protect against recursive calls. delete_frame in
3934 delete_terminal calls us back when it deletes our last frame. */
3935 if (!terminal->name
)
3940 x_destroy_all_bitmaps
(dpyinfo
);
3941 ns_delete_display
(dpyinfo
);
3946 static
struct terminal *
3947 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3948 /* --------------------------------------------------------------------------
3949 Set up use of NS before we make the first connection.
3950 -------------------------------------------------------------------------- */
3952 struct terminal *terminal;
3954 NSTRACE
(ns_create_terminal
);
3956 terminal = create_terminal
();
3958 terminal->type = output_ns
;
3959 terminal->display_info.ns
= dpyinfo
;
3960 dpyinfo
->terminal = terminal;
3962 terminal->rif
= &ns_redisplay_interface
;
3964 terminal->clear_frame_hook
= ns_clear_frame
;
3965 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
3966 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
3967 terminal->ring_bell_hook
= ns_ring_bell
;
3968 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
3969 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
3970 terminal->update_begin_hook
= ns_update_begin
;
3971 terminal->update_end_hook
= ns_update_end
;
3972 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
3973 terminal->read_socket_hook
= ns_read_socket
;
3974 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
3975 terminal->mouse_position_hook
= ns_mouse_position
;
3976 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
3977 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
3979 terminal->fullscreen_hook
= ns_fullscreen_hook
;
3981 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
3982 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
3983 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
3984 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
3986 terminal->delete_frame_hook
= x_destroy_window
;
3987 terminal->delete_terminal_hook
= ns_delete_terminal
;
3989 terminal->scroll_region_ok
= 1;
3990 terminal->char_ins_del_ok
= 1;
3991 terminal->line_ins_del_ok
= 1;
3992 terminal->fast_clear_end_of_line
= 1;
3993 terminal->memory_below_frame
= 0;
3999 struct ns_display_info
*
4000 ns_term_init
(Lisp_Object display_name
)
4001 /* --------------------------------------------------------------------------
4002 Start the Application and get things rolling.
4003 -------------------------------------------------------------------------- */
4005 struct terminal *terminal;
4006 struct ns_display_info
*dpyinfo
;
4007 static int ns_initialized
= 0;
4010 if (ns_initialized
) return x_display_list
;
4013 NSTRACE
(ns_term_init
);
4015 [outerpool release
];
4016 outerpool
= [[NSAutoreleasePool alloc
] init
];
4018 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
4019 /*GSDebugAllocationActive (YES); */
4023 Fset_input_interrupt_mode
(Qnil
);
4025 if (selfds
[0] == -1)
4027 if (pipe
(selfds
) == -1)
4029 fprintf (stderr
, "Failed to create pipe
: %s\n",
4030 emacs_strerror
(errno
));
4034 fcntl
(selfds
[0], F_SETFL
, O_NONBLOCK|fcntl
(selfds
[0], F_GETFL
));
4035 FD_ZERO
(&select_readfds
);
4036 FD_ZERO
(&select_writefds
);
4037 pthread_mutex_init
(&select_mutex
, NULL);
4040 ns_pending_files
= [[NSMutableArray alloc
] init
];
4041 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
4042 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
4044 /* Start app and create the main menu, window, view.
4045 Needs to be here because ns_initialize_display_info () uses AppKit classes.
4046 The view will then ask the NSApp to stop and return to Emacs. */
4047 [EmacsApp sharedApplication
];
4050 [NSApp setDelegate
: NSApp
];
4052 /* Start the select thread. */
4053 [NSThread detachNewThreadSelector
:@selector
(fd_handler
:)
4057 /* debugging: log all notifications */
4058 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
4059 selector: @selector (logNotification:)
4060 name: nil object: nil]; */
4062 dpyinfo
= xzalloc
(sizeof
*dpyinfo
);
4064 ns_initialize_display_info
(dpyinfo
);
4065 terminal = ns_create_terminal
(dpyinfo
);
4067 terminal->kboard
= xmalloc
(sizeof
*terminal->kboard
);
4068 init_kboard
(terminal->kboard
);
4069 kset_window_system
(terminal->kboard
, Qns
);
4070 terminal->kboard
->next_kboard
= all_kboards
;
4071 all_kboards
= terminal->kboard
;
4072 /* Don't let the initial kboard remain current longer than necessary.
4073 That would cause problems if a file loaded on startup tries to
4074 prompt in the mini-buffer. */
4075 if (current_kboard
== initial_kboard
)
4076 current_kboard
= terminal->kboard
;
4077 terminal->kboard
->reference_count
++;
4079 dpyinfo
->next
= x_display_list
;
4080 x_display_list
= dpyinfo
;
4082 /* Put it on ns_display_name_list */
4083 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
4084 ns_display_name_list
);
4085 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
4087 terminal->name
= xstrdup
(SSDATA
(display_name
));
4091 if (!inhibit_x_resources
)
4093 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
4096 /* this is a standard variable */
4097 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
4098 make_float
(10.0), make_float
(6.0), YES
, NO
);
4099 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
4102 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
4103 stringForKey
: @"AppleHighlightColor"
];
4104 if (ns_selection_color
== nil
)
4105 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
4108 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
4112 Lisp_Object color_file
, color_map
, color
;
4116 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
4117 Fsymbol_value
(intern
("data
-directory"
)));
4119 color_map
= Fx_load_color_file
(color_file
);
4120 if (NILP
(color_map
))
4121 fatal
("Could not read
%s.\n", SDATA (color_file));
4123 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
4124 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
4126 color
= XCAR
(color_map
);
4127 name
= SSDATA
(XCAR
(color
));
4128 c
= XINT
(XCDR
(color
));
4130 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
4131 green
: GREEN_FROM_ULONG
(c
) / 255.0
4132 blue
: BLUE_FROM_ULONG
(c
) / 255.0
4134 forKey
: [NSString stringWithUTF8String
: name
]];
4136 [cl writeToFile
: nil
];
4141 #ifdef NS_IMPL_GNUSTEP
4142 Vwindow_system_version
= build_string
(gnustep_base_version
);
4144 /*PSnextrelease (128, c); */
4145 char c
[DBL_BUFSIZE_BOUND
];
4146 int len
= dtoastr
(c
, sizeof c
, 0, 0, NSAppKitVersionNumber
);
4147 Vwindow_system_version
= make_unibyte_string
(c
, len
);
4151 delete_keyboard_wait_descriptor
(0);
4153 ns_app_name
= [[NSProcessInfo processInfo
] processName
];
4155 /* Set up OS X app menu */
4156 #ifdef NS_IMPL_COCOA
4160 /* set up the application menu */
4161 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
4162 [svcsMenu setAutoenablesItems
: NO
];
4163 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
4164 [appMenu setAutoenablesItems
: NO
];
4165 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4166 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
4168 [appMenu insertItemWithTitle
: @"About Emacs"
4169 action
: @selector
(orderFrontStandardAboutPanel
:)
4172 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
4173 [appMenu insertItemWithTitle
: @"Preferences..."
4174 action
: @selector
(showPreferencesWindow
:)
4177 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
4178 item
= [appMenu insertItemWithTitle
: @"Services"
4179 action
: @selector
(menuDown
:)
4182 [appMenu setSubmenu
: svcsMenu forItem
: item
];
4183 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
4184 [appMenu insertItemWithTitle
: @"Hide Emacs"
4185 action
: @selector
(hide
:)
4188 item
= [appMenu insertItemWithTitle
: @"Hide Others"
4189 action
: @selector
(hideOtherApplications
:)
4192 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
4193 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
4194 [appMenu insertItemWithTitle
: @"
Quit Emacs"
4195 action
: @selector
(terminate
:)
4199 item
= [mainMenu insertItemWithTitle
: ns_app_name
4200 action
: @selector
(menuDown
:)
4203 [mainMenu setSubmenu
: appMenu forItem
: item
];
4204 [dockMenu insertItemWithTitle
: @"New Frame"
4205 action
: @selector
(newFrame
:)
4209 [NSApp setMainMenu
: mainMenu
];
4210 [NSApp setAppleMenu
: appMenu
];
4211 [NSApp setServicesMenu
: svcsMenu
];
4212 /* Needed at least on Cocoa, to get dock menu to show windows */
4213 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
4215 [[NSNotificationCenter defaultCenter
]
4216 addObserver
: mainMenu
4217 selector
: @selector
(trackingNotification
:)
4218 name
: NSMenuDidBeginTrackingNotification object
: mainMenu
];
4219 [[NSNotificationCenter defaultCenter
]
4220 addObserver
: mainMenu
4221 selector
: @selector
(trackingNotification
:)
4222 name
: NSMenuDidEndTrackingNotification object
: mainMenu
];
4224 #endif
/* MAC OS X menu setup */
4226 /* Register our external input/output types, used for determining
4227 applicable services and also drag/drop eligibility. */
4228 ns_send_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
] retain
];
4229 ns_return_types
= [[NSArray arrayWithObjects
: NSStringPboardType
, nil
]
4231 ns_drag_types
= [[NSArray arrayWithObjects
:
4233 NSTabularTextPboardType
,
4234 NSFilenamesPboardType
,
4237 NSFontPboardType
, nil
] retain
];
4239 #ifndef NEW_STYLE_FS
4240 /* If fullscreen is in init/default-frame-alist, focus isn't set
4241 right for fullscreen windows, so set this. */
4242 [NSApp activateIgnoringOtherApps
:YES
];
4246 ns_do_open_file
= YES
;
4252 ns_term_shutdown
(int sig
)
4254 [[NSUserDefaults standardUserDefaults
] synchronize
];
4256 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4257 if (STRINGP
(Vauto_save_list_file_name
))
4258 unlink
(SSDATA
(Vauto_save_list_file_name
));
4260 if (sig
== 0 || sig
== SIGTERM
)
4262 [NSApp terminate
: NSApp
];
4264 else // force a stack
trace to happen
4271 /* ==========================================================================
4273 EmacsApp implementation
4275 ========================================================================== */
4278 @implementation EmacsApp
4280 - (void
)logNotification
: (NSNotification
*)notification
4282 const
char *name
= [[notification name
] UTF8String
];
4283 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4284 && !strstr
(name
, "WindowNumber"
))
4285 NSLog
(@"notification
: '%@'"
, [notification name
]);
4289 - (void
)sendEvent
: (NSEvent
*)theEvent
4290 /* --------------------------------------------------------------------------
4291 Called when NSApp is running for each event received. Used to stop
4292 the loop when we choose, since there's no way to just run one iteration.
4293 -------------------------------------------------------------------------- */
4295 int
type = [theEvent
type];
4296 NSWindow
*window
= [theEvent window
];
4297 /* NSTRACE (sendEvent); */
4298 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4300 #ifdef NS_IMPL_COCOA
4301 if (type == NSApplicationDefined
4302 && [theEvent data2
] == NSAPP_DATA2_RUNASSCRIPT
)
4310 if (type == NSCursorUpdate
&& window
== nil
)
4312 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4316 if (type == NSApplicationDefined
)
4318 /* Events posted by ns_send_appdefined interrupt the run loop here.
4319 But, if a modal window is up, an appdefined can still come through,
4320 (e.g., from a makeKeyWindow event) but stopping self also stops the
4321 modal loop. Just defer it until later. */
4322 if ([NSApp modalWindow
] == nil
)
4324 last_appdefined_event_data
= [theEvent data1
];
4329 send_appdefined
= YES
;
4333 [super sendEvent
: theEvent
];
4337 - (void
)showPreferencesWindow
: (id
)sender
4339 struct frame
*emacsframe
= SELECTED_FRAME
();
4340 NSEvent
*theEvent
= [NSApp currentEvent
];
4344 emacs_event
->kind
= NS_NONKEY_EVENT
;
4345 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4346 emacs_event
->modifiers
= 0;
4347 EV_TRAILER
(theEvent
);
4351 - (void
)newFrame
: (id
)sender
4353 struct frame
*emacsframe
= SELECTED_FRAME
();
4354 NSEvent
*theEvent
= [NSApp currentEvent
];
4358 emacs_event
->kind
= NS_NONKEY_EVENT
;
4359 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4360 emacs_event
->modifiers
= 0;
4361 EV_TRAILER
(theEvent
);
4365 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4366 - (BOOL
) openFile
: (NSString
*)fileName
4368 struct frame
*emacsframe
= SELECTED_FRAME
();
4369 NSEvent
*theEvent
= [NSApp currentEvent
];
4374 emacs_event
->kind
= NS_NONKEY_EVENT
;
4375 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4376 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4377 ns_input_line
= Qnil
; /* can be start or cons start,end */
4378 emacs_event
->modifiers
=0;
4379 EV_TRAILER
(theEvent
);
4385 /* **************************************************************************
4387 EmacsApp delegate implementation
4389 ************************************************************************** */
4391 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4392 /* --------------------------------------------------------------------------
4393 When application is loaded, terminate event loop in ns_term_init
4394 -------------------------------------------------------------------------- */
4396 NSTRACE
(applicationDidFinishLaunching
);
4397 [NSApp setServicesProvider
: NSApp
];
4398 ns_send_appdefined
(-2);
4402 /* Termination sequences:
4405 MenuBar | File | Exit:
4406 Select Quit from App menubar:
4408 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4411 Select Quit from Dock menu:
4414 Cancel -> Nothing else
4418 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4423 - (void
) terminate
: (id
)sender
4425 struct frame
*emacsframe
= SELECTED_FRAME
();
4430 emacs_event
->kind
= NS_NONKEY_EVENT
;
4431 emacs_event
->code
= KEY_NS_POWER_OFF
;
4432 emacs_event
->arg
= Qt
; /* mark as non-key event */
4433 EV_TRAILER
((id
)nil
);
4437 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4441 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4442 return NSTerminateNow
;
4444 ret
= NSRunAlertPanel
(ns_app_name
,
4445 @"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
,
4446 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4448 if (ret
== NSAlertDefaultReturn
)
4449 return NSTerminateNow
;
4450 else if (ret
== NSAlertAlternateReturn
)
4451 return NSTerminateCancel
;
4452 return NSTerminateNow
; /* just in case */
4456 not_in_argv
(NSString
*arg
)
4459 const
char *a
= [arg UTF8String
];
4460 for (k
= 1; k
< initial_argc
; ++k
)
4461 if (strcmp (a
, initial_argv
[k
]) == 0) return 0;
4465 /* Notification from the Workspace to open a file */
4466 - (BOOL
)application
: sender openFile
: (NSString
*)file
4468 if (ns_do_open_file || not_in_argv
(file
))
4469 [ns_pending_files addObject
: file
];
4474 /* Open a file as a temporary file */
4475 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4477 if (ns_do_open_file || not_in_argv
(file
))
4478 [ns_pending_files addObject
: file
];
4483 /* Notification from the Workspace to open a file noninteractively (?) */
4484 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4486 if (ns_do_open_file || not_in_argv
(file
))
4487 [ns_pending_files addObject
: file
];
4491 /* Notification from the Workspace to open multiple files */
4492 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4494 NSEnumerator
*files
= [fileList objectEnumerator
];
4496 /* Don't open files from the command line unconditionally,
4497 Cocoa parses the command line wrong, --option value tries to open value
4498 if --option is the last option. */
4499 while ((file
= [files nextObject
]) != nil
)
4500 if (ns_do_open_file || not_in_argv
(file
))
4501 [ns_pending_files addObject
: file
];
4503 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4508 /* Handle dock menu requests. */
4509 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4515 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4516 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4518 //ns_app_active
=YES
;
4520 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4522 NSTRACE
(applicationDidBecomeActive
);
4524 //ns_app_active
=YES
;
4526 ns_update_auto_hide_menu_bar
();
4527 // No constraining takes place when the application is not active.
4528 ns_constrain_all_frames
();
4530 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4533 ns_send_appdefined
(-1);
4538 /* ==========================================================================
4540 EmacsApp aux handlers for managing event loop
4542 ========================================================================== */
4545 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4546 /* --------------------------------------------------------------------------
4547 The timeout specified to ns_select has passed.
4548 -------------------------------------------------------------------------- */
4550 /*NSTRACE (timeout_handler); */
4551 ns_send_appdefined
(-2);
4554 - (void
)fd_handler
:(id
)unused
4555 /* --------------------------------------------------------------------------
4556 Check data waiting on file descriptors and terminate if so
4557 -------------------------------------------------------------------------- */
4560 int waiting
= 1, nfds
;
4563 SELECT_TYPE readfds
, writefds
, *wfds
;
4564 EMACS_TIME timeout
, *tmo
;
4565 NSAutoreleasePool
*pool
= nil
;
4567 /* NSTRACE (fd_handler); */
4572 pool
= [[NSAutoreleasePool alloc
] init
];
4578 FD_SET
(selfds
[0], &fds
);
4579 result
= select
(selfds
[0]+1, &fds
, NULL, NULL, NULL);
4580 if (result
> 0 && read
(selfds
[0], &c
, 1) == 1 && c
== 'g')
4585 pthread_mutex_lock
(&select_mutex
);
4588 if (select_valid
& SELECT_HAVE_READ
)
4589 readfds
= select_readfds
;
4593 if (select_valid
& SELECT_HAVE_WRITE
)
4595 writefds
= select_writefds
;
4600 if (select_valid
& SELECT_HAVE_TMO
)
4602 timeout
= select_timeout
;
4608 pthread_mutex_unlock
(&select_mutex
);
4610 FD_SET
(selfds
[0], &readfds
);
4611 if (selfds
[0] >= nfds
) nfds
= selfds
[0]+1;
4613 result
= pselect
(nfds
, &readfds
, wfds
, NULL, tmo
, NULL);
4616 ns_send_appdefined
(-2);
4617 else if (result
> 0)
4619 if (FD_ISSET
(selfds
[0], &readfds
))
4621 if (read
(selfds
[0], &c
, 1) == 1 && c
== 's')
4626 pthread_mutex_lock
(&select_mutex
);
4627 if (select_valid
& SELECT_HAVE_READ
)
4628 select_readfds
= readfds
;
4629 if (select_valid
& SELECT_HAVE_WRITE
)
4630 select_writefds
= writefds
;
4631 if (select_valid
& SELECT_HAVE_TMO
)
4632 select_timeout
= timeout
;
4633 pthread_mutex_unlock
(&select_mutex
);
4635 ns_send_appdefined
(result
);
4645 /* ==========================================================================
4649 ========================================================================== */
4651 /* called from system: queue for next pass through event loop */
4652 - (void
)requestService
: (NSPasteboard
*)pboard
4653 userData
: (NSString
*)userData
4654 error: (NSString
**)error
4656 [ns_pending_service_names addObject
: userData
];
4657 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4658 SSDATA
(ns_string_from_pasteboard
(pboard
))]];
4662 /* called from ns_read_socket to clear queue */
4663 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4665 struct frame
*emacsframe
= SELECTED_FRAME
();
4666 NSEvent
*theEvent
= [NSApp currentEvent
];
4671 emacs_event
->kind
= NS_NONKEY_EVENT
;
4672 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4673 ns_input_spi_name
= build_string
([name UTF8String
]);
4674 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4675 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4676 EV_TRAILER
(theEvent
);
4686 /* ==========================================================================
4688 EmacsView implementation
4690 ========================================================================== */
4693 @implementation EmacsView
4695 /* needed to inform when window closed from LISP */
4696 - (void
) setWindowClosing
: (BOOL
)closing
4698 windowClosing
= closing
;
4704 NSTRACE
(EmacsView_dealloc
);
4706 if (fs_state
== FULLSCREEN_BOTH
)
4707 [nonfs_window release
];
4712 /* called on font panel selection */
4713 - (void
)changeFont
: (id
)sender
4715 NSEvent
*e
=[[self window
] currentEvent
];
4716 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4720 NSTRACE
(changeFont
);
4724 if ((newFont
= [sender convertFont
:
4725 ((struct nsfont_info
*)face
->font
)->nsfont
]))
4727 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4729 emacs_event
->kind
= NS_NONKEY_EVENT
;
4730 emacs_event
->modifiers
= 0;
4731 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4733 size = [newFont pointSize
];
4734 ns_input_fontsize
= make_number
(lrint
(size));
4735 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4741 - (BOOL
)acceptsFirstResponder
4743 NSTRACE
(acceptsFirstResponder
);
4748 - (void
)resetCursorRects
4750 NSRect visible
= [self visibleRect
];
4751 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4752 NSTRACE
(resetCursorRects
);
4754 if (currentCursor
== nil
)
4755 currentCursor
= [NSCursor arrowCursor
];
4757 if (!NSIsEmptyRect
(visible
))
4758 [self addCursorRect
: visible cursor
: currentCursor
];
4759 [currentCursor setOnMouseEntered
: YES
];
4764 /*****************************************************************************/
4765 /* Keyboard handling. */
4768 - (void
)keyDown
: (NSEvent
*)theEvent
4770 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
4772 unsigned fnKeysym
= 0;
4773 static NSMutableArray
*nsEvArray
;
4774 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4775 static BOOL firstTime
= YES
;
4778 unsigned int flags
= [theEvent modifierFlags
];
4782 /* Rhapsody and OS X give up and down events for the arrow keys */
4783 if (ns_fake_keydown
== YES
)
4784 ns_fake_keydown
= NO
;
4785 else if ([theEvent
type] != NSKeyDown
)
4791 if (![[self window
] isKeyWindow
]
4792 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4793 /* we must avoid an infinite loop here. */
4794 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4796 /* XXX: There is an occasional condition in which, when Emacs display
4797 updates a different frame from the current one, and temporarily
4798 selects it, then processes some interrupt-driven input
4799 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4800 for some reason that window has its first responder set to the NSView
4801 most recently updated (I guess), which is not the correct one. */
4802 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4806 if (nsEvArray
== nil
)
4807 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4809 [NSCursor setHiddenUntilMouseMoves
: YES
];
4811 if (hlinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4813 clear_mouse_face
(hlinfo
);
4814 hlinfo
->mouse_face_hidden
= 1;
4817 if (!processingCompose
)
4819 /* When using screen sharing, no left or right information is sent,
4820 so use Left key in those cases. */
4821 int is_left_key
, is_right_key
;
4823 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4824 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4826 /* (Carbon way: [theEvent keyCode]) */
4828 /* is it a "function key"? */
4829 fnKeysym
= (code
< 0x00ff && (flags
&NSNumericPadKeyMask
))
4830 ? ns_convert_key
([theEvent keyCode
] | NSNumericPadKeyMask
)
4831 : ns_convert_key
(code
);
4835 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4836 because Emacs treats Delete and KP-Delete same (in simple.el). */
4837 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4838 code
= 0xFF08; /* backspace */
4843 /* are there modifiers? */
4844 emacs_event
->modifiers
= 0;
4846 if (flags
& NSHelpKeyMask
)
4847 emacs_event
->modifiers |
= hyper_modifier
;
4849 if (flags
& NSShiftKeyMask
)
4850 emacs_event
->modifiers |
= shift_modifier
;
4852 is_right_key
= (flags
& NSRightCommandKeyMask
) == NSRightCommandKeyMask
;
4853 is_left_key
= (flags
& NSLeftCommandKeyMask
) == NSLeftCommandKeyMask
4854 ||
(! is_right_key
&& (flags
& NSCommandKeyMask
) == NSCommandKeyMask
);
4857 emacs_event
->modifiers |
= parse_solitary_modifier
4858 (EQ
(ns_right_command_modifier
, Qleft
)
4859 ? ns_command_modifier
4860 : ns_right_command_modifier
);
4864 emacs_event
->modifiers |
= parse_solitary_modifier
4865 (ns_command_modifier
);
4867 /* if super (default), take input manager's word so things like
4868 dvorak / qwerty layout work */
4869 if (EQ
(ns_command_modifier
, Qsuper
)
4871 && [[theEvent characters
] length] != 0)
4873 /* XXX: the code we get will be unshifted, so if we have
4874 a shift modifier, must convert ourselves */
4875 if (!(flags
& NSShiftKeyMask
))
4876 code
= [[theEvent characters
] characterAtIndex
: 0];
4878 /* this is ugly and also requires linking w/Carbon framework
4879 (for LMGetKbdType) so for now leave this rare (?) case
4880 undealt with.. in future look into CGEvent methods */
4883 long smv
= GetScriptManagerVariable
(smKeyScript
);
4884 Handle uchrHandle
= GetResource
4885 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4887 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4888 [[theEvent characters
] characterAtIndex
: 0],
4889 kUCKeyActionDisplay
,
4890 (flags
& ~NSCommandKeyMask
) >> 8,
4891 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4892 &dummy
, 1, &dummy
, &code
);
4899 is_right_key
= (flags
& NSRightControlKeyMask
) == NSRightControlKeyMask
;
4900 is_left_key
= (flags
& NSLeftControlKeyMask
) == NSLeftControlKeyMask
4901 ||
(! is_right_key
&& (flags
& NSControlKeyMask
) == NSControlKeyMask
);
4904 emacs_event
->modifiers |
= parse_solitary_modifier
4905 (EQ
(ns_right_control_modifier
, Qleft
)
4906 ? ns_control_modifier
4907 : ns_right_control_modifier
);
4910 emacs_event
->modifiers |
= parse_solitary_modifier
4911 (ns_control_modifier
);
4913 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4914 emacs_event
->modifiers |
=
4915 parse_solitary_modifier
(ns_function_modifier
);
4917 left_is_none
= NILP
(ns_alternate_modifier
)
4918 || EQ
(ns_alternate_modifier
, Qnone
);
4920 is_right_key
= (flags
& NSRightAlternateKeyMask
)
4921 == NSRightAlternateKeyMask
;
4922 is_left_key
= (flags
& NSLeftAlternateKeyMask
) == NSLeftAlternateKeyMask
4924 && (flags
& NSAlternateKeyMask
) == NSAlternateKeyMask
);
4928 if ((NILP
(ns_right_alternate_modifier
)
4929 || EQ
(ns_right_alternate_modifier
, Qnone
)
4930 ||
(EQ
(ns_right_alternate_modifier
, Qleft
) && left_is_none
))
4932 { /* accept pre-interp alt comb */
4933 if ([[theEvent characters
] length] > 0)
4934 code
= [[theEvent characters
] characterAtIndex
: 0];
4935 /*HACK: clear lone shift modifier to stop next if from firing */
4936 if (emacs_event
->modifiers
== shift_modifier
)
4937 emacs_event
->modifiers
= 0;
4940 emacs_event
->modifiers |
= parse_solitary_modifier
4941 (EQ
(ns_right_alternate_modifier
, Qleft
)
4942 ? ns_alternate_modifier
4943 : ns_right_alternate_modifier
);
4946 if (is_left_key
) /* default = meta */
4948 if (left_is_none
&& !fnKeysym
)
4949 { /* accept pre-interp alt comb */
4950 if ([[theEvent characters
] length] > 0)
4951 code
= [[theEvent characters
] characterAtIndex
: 0];
4952 /*HACK: clear lone shift modifier to stop next if from firing */
4953 if (emacs_event
->modifiers
== shift_modifier
)
4954 emacs_event
->modifiers
= 0;
4957 emacs_event
->modifiers |
=
4958 parse_solitary_modifier
(ns_alternate_modifier
);
4962 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4963 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4965 /* if it was a function key or had modifiers, pass it directly to emacs */
4966 if (fnKeysym ||
(emacs_event
->modifiers
4967 && (emacs_event
->modifiers
!= shift_modifier
)
4968 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4969 /*[[theEvent characters] length] */
4971 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4973 code |
= (1<<28)|
(3<<16);
4974 else if (code
== 0x7f)
4975 code |
= (1<<28)|
(3<<16);
4977 emacs_event
->kind
= code
> 0xFF
4978 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4980 emacs_event
->code
= code
;
4981 EV_TRAILER
(theEvent
);
4987 #
if !defined
(NS_IMPL_COCOA
) || MAC_OS_X_VERSION_MAX_ALLOWED
< MAC_OS_X_VERSION_10_6
4988 /* if we get here we should send the key for input manager processing */
4989 if (firstTime
&& [[NSInputManager currentInputManager
]
4990 wantsToDelayTextChangeNotifications
] == NO
)
4992 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
4995 if (NS_KEYLOG
&& !processingCompose
)
4996 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
4998 processingCompose
= YES
;
4999 [nsEvArray addObject
: theEvent
];
5000 [self interpretKeyEvents
: nsEvArray
];
5001 [nsEvArray removeObject
: theEvent
];
5005 #ifdef NS_IMPL_COCOA
5006 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
5007 decided not to send key-down for.
5008 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
5009 This only applies on Tiger and earlier.
5010 If it matches one of these, send it on to keyDown. */
5011 -(void
)keyUp
: (NSEvent
*)theEvent
5013 int flags
= [theEvent modifierFlags
];
5014 int code
= [theEvent keyCode
];
5015 if (floor (NSAppKitVersionNumber
) <= 824 /*NSAppKitVersionNumber10_4*/ &&
5016 code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
5019 fprintf (stderr
, "keyUp
: passed test"
);
5020 ns_fake_keydown
= YES
;
5021 [self keyDown
: theEvent
];
5027 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
5030 /* <NSTextInput>: called when done composing;
5031 NOTE: also called when we delete over working text, followed immed.
5032 by doCommandBySelector: deleteBackward: */
5033 - (void
)insertText
: (id
)aString
5036 int len
= [(NSString
*)aString
length];
5040 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
5041 processingCompose
= NO
;
5046 /* first, clear any working text */
5047 if (workingText
!= nil
)
5048 [self deleteWorkingText
];
5050 /* now insert the string as keystrokes */
5051 for (i
=0; i
<len
; i
++)
5053 code
= [aString characterAtIndex
: i
];
5054 /* TODO: still need this? */
5056 code
= '~'; /* 0x7E */
5057 if (code
!= 32) /* Space */
5058 emacs_event
->modifiers
= 0;
5060 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
5061 emacs_event
->code
= code
;
5062 EV_TRAILER
((id
)nil
);
5067 /* <NSTextInput>: inserts display of composing characters */
5068 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
5070 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
5071 [aString string
] : aString
;
5073 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
5074 selRange.
length, selRange.location
);
5076 if (workingText
!= nil
)
5077 [self deleteWorkingText
];
5078 if ([str
length] == 0)
5084 processingCompose
= YES
;
5085 workingText
= [str copy
];
5086 ns_working_text
= build_string
([workingText UTF8String
]);
5088 emacs_event
->kind
= NS_TEXT_EVENT
;
5089 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
5090 EV_TRAILER
((id
)nil
);
5094 /* delete display of composing characters [not in <NSTextInput>] */
5095 - (void
)deleteWorkingText
5097 if (workingText
== nil
)
5100 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
5101 [workingText release
];
5103 processingCompose
= NO
;
5108 emacs_event
->kind
= NS_TEXT_EVENT
;
5109 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
5110 EV_TRAILER
((id
)nil
);
5114 - (BOOL
)hasMarkedText
5116 return workingText
!= nil
;
5120 - (NSRange
)markedRange
5122 NSRange rng
= workingText
!= nil
5123 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
5125 NSLog
(@"markedRange request"
);
5133 NSLog
(@"unmark
(accept
) text"
);
5134 [self deleteWorkingText
];
5135 processingCompose
= NO
;
5139 /* used to position char selection windows, etc. */
5140 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
5144 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
5146 NSLog
(@"firstRectForCharRange request"
);
5148 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
5149 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
5150 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
5151 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
5152 +FRAME_LINE_HEIGHT
(emacsframe
));
5154 pt
= [self convertPoint
: pt toView
: nil
];
5155 pt
= [[self window
] convertBaseToScreen
: pt
];
5161 - (NSInteger
)conversationIdentifier
5163 return (NSInteger
)self
;
5167 - (void
)doCommandBySelector
: (SEL
)aSelector
5170 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
5172 if (aSelector
== @selector
(deleteBackward
:))
5174 /* happens when user backspaces over an ongoing composition:
5175 throw a 'delete' into the event queue */
5178 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
5179 emacs_event
->code
= 0xFF08;
5180 EV_TRAILER
((id
)nil
);
5184 - (NSArray
*)validAttributesForMarkedText
5186 static NSArray
*arr
= nil
;
5187 if (arr
== nil
) arr
= [NSArray new
];
5188 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
5192 - (NSRange
)selectedRange
5195 NSLog
(@"selectedRange request"
);
5196 return NSMakeRange
(NSNotFound
, 0);
5199 - (NSUInteger
)characterIndexForPoint
: (NSPoint
)thePoint
5202 NSLog
(@"characterIndexForPoint request"
);
5206 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
5208 static NSAttributedString
*str
= nil
;
5209 if (str
== nil
) str
= [NSAttributedString new
];
5211 NSLog
(@"attributedSubstringFromRange request"
);
5215 /* End <NSTextInput> impl. */
5216 /*****************************************************************************/
5219 /* This is what happens when the user presses a mouse button. */
5220 - (void
)mouseDown
: (NSEvent
*)theEvent
5222 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5224 NSTRACE
(mouseDown
);
5226 [self deleteWorkingText
];
5231 last_mouse_frame
= emacsframe
;
5232 /* appears to be needed to prevent spurious movement events generated on
5234 last_mouse_frame
->mouse_moved
= 0;
5236 if ([theEvent
type] == NSScrollWheel
)
5238 float delta
= [theEvent deltaY
];
5239 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
5242 emacs_event
->kind
= WHEEL_EVENT
;
5243 emacs_event
->code
= 0;
5244 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
5245 ((delta
> 0) ? up_modifier
: down_modifier
);
5249 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
5250 emacs_event
->code
= EV_BUTTON
(theEvent
);
5251 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
5252 | EV_UDMODIFIERS
(theEvent
);
5254 XSETINT
(emacs_event
->x
, lrint
(p.x
));
5255 XSETINT
(emacs_event
->y
, lrint
(p.y
));
5256 EV_TRAILER
(theEvent
);
5260 - (void
)rightMouseDown
: (NSEvent
*)theEvent
5262 NSTRACE
(rightMouseDown
);
5263 [self mouseDown
: theEvent
];
5267 - (void
)otherMouseDown
: (NSEvent
*)theEvent
5269 NSTRACE
(otherMouseDown
);
5270 [self mouseDown
: theEvent
];
5274 - (void
)mouseUp
: (NSEvent
*)theEvent
5277 [self mouseDown
: theEvent
];
5281 - (void
)rightMouseUp
: (NSEvent
*)theEvent
5283 NSTRACE
(rightMouseUp
);
5284 [self mouseDown
: theEvent
];
5288 - (void
)otherMouseUp
: (NSEvent
*)theEvent
5290 NSTRACE
(otherMouseUp
);
5291 [self mouseDown
: theEvent
];
5295 - (void
) scrollWheel
: (NSEvent
*)theEvent
5297 NSTRACE
(scrollWheel
);
5298 [self mouseDown
: theEvent
];
5302 /* Tell emacs the mouse has moved. */
5303 - (void
)mouseMoved
: (NSEvent
*)e
5305 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO
(emacsframe
);
5308 // NSTRACE
(mouseMoved
);
5310 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
5311 last_mouse_motion_position
5312 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
5314 /* update any mouse face */
5315 if (hlinfo
->mouse_face_hidden
)
5317 hlinfo
->mouse_face_hidden
= 0;
5318 clear_mouse_face
(hlinfo
);
5321 /* tooltip handling */
5322 previous_help_echo_string
= help_echo_string
;
5323 help_echo_string
= Qnil
;
5325 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
5326 last_mouse_motion_position.y
))
5327 help_echo_string
= previous_help_echo_string
;
5329 XSETFRAME
(frame
, emacsframe
);
5330 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
5332 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
5333 (note_mouse_highlight), which is called through the
5334 note_mouse_movement () call above */
5335 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
5336 help_echo_object
, help_echo_pos
);
5340 help_echo_string
= Qnil
;
5341 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
5344 if (emacsframe
->mouse_moved
&& send_appdefined
)
5345 ns_send_appdefined
(-1);
5349 - (void
)mouseDragged
: (NSEvent
*)e
5351 NSTRACE
(mouseDragged
);
5352 [self mouseMoved
: e
];
5356 - (void
)rightMouseDragged
: (NSEvent
*)e
5358 NSTRACE
(rightMouseDragged
);
5359 [self mouseMoved
: e
];
5363 - (void
)otherMouseDragged
: (NSEvent
*)e
5365 NSTRACE
(otherMouseDragged
);
5366 [self mouseMoved
: e
];
5370 - (BOOL
)windowShouldClose
: (id
)sender
5372 NSEvent
*e
=[[self window
] currentEvent
];
5374 NSTRACE
(windowShouldClose
);
5375 windowClosing
= YES
;
5378 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5379 emacs_event
->modifiers
= 0;
5380 emacs_event
->code
= 0;
5382 /* Don't close this window, let this be done from lisp code. */
5386 - (void
) updateFrameSize
: (BOOL
) delay
;
5388 NSWindow
*window
= [self window
];
5389 NSRect wr
= [window frame
];
5390 #ifdef NS_IMPL_GNUSTEP
5396 int oldc
= cols
, oldr
= rows
;
5397 int oldw
= FRAME_PIXEL_WIDTH
(emacsframe
),
5398 oldh
= FRAME_PIXEL_HEIGHT
(emacsframe
);
5401 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
, wr.
size.width
+ extra
);
5403 if (cols
< MINWIDTH
)
5406 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
5407 (emacsframe
, wr.
size.height
5408 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + extra
5409 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5411 if (rows
< MINHEIGHT
)
5414 neww
= (int
)wr.
size.width
- emacsframe
->border_width
;
5415 newh
= ((int
)wr.
size.height
5416 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5417 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5419 if (oldr
!= rows || oldc
!= cols || neww
!= oldw || newh
!= oldh
)
5421 NSView
*view = FRAME_NS_VIEW
(emacsframe
);
5422 FRAME_PIXEL_WIDTH
(emacsframe
) = neww
;
5423 FRAME_PIXEL_HEIGHT
(emacsframe
) = newh
;
5424 change_frame_size
(emacsframe
, rows
, cols
, 0, delay
, 0);
5425 SET_FRAME_GARBAGED
(emacsframe
);
5426 cancel_mouse_face
(emacsframe
);
5427 [view setFrame
: NSMakeRect
(0, 0, neww
, newh
)];
5428 [self windowDidMove
:nil
]; // Update top
/left.
5432 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5433 /* normalize frame to gridded text size */
5435 NSTRACE
(windowWillResize
);
5436 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5438 if (fs_state
== FULLSCREEN_MAXIMIZED
5439 && (maximized_width
!= (int
)frameSize.width
5440 || maximized_height
!= (int
)frameSize.height
))
5441 [self setFSValue
: FULLSCREEN_NONE
];
5442 else if (fs_state
== FULLSCREEN_WIDTH
5443 && maximized_width
!= (int
)frameSize.width
)
5444 [self setFSValue
: FULLSCREEN_NONE
];
5445 else if (fs_state
== FULLSCREEN_HEIGHT
5446 && maximized_height
!= (int
)frameSize.height
)
5447 [self setFSValue
: FULLSCREEN_NONE
];
5448 if (fs_state
== FULLSCREEN_NONE
)
5449 maximized_width
= maximized_height
= -1;
5451 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5452 #ifdef NS_IMPL_GNUSTEP
5453 frameSize.width
+ 3);
5457 if (cols
< MINWIDTH
)
5460 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5461 #ifdef NS_IMPL_GNUSTEP
5462 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5463 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5465 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5466 - FRAME_TOOLBAR_HEIGHT
(emacsframe
));
5468 if (rows
< MINHEIGHT
)
5470 #ifdef NS_IMPL_COCOA
5472 /* this sets window title to have size in it; the wm does this under GS */
5473 NSRect r
= [[self window
] frame
];
5474 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5485 NSWindow
*window
= [self window
];
5488 const
char *t
= [[[self window
] title] UTF8String
];
5489 char *pos
= strstr
(t
, " — "
);
5492 old_title
= xstrdup
(t
);
5494 size_title
= xmalloc
(strlen
(old_title
) + 40);
5495 esprintf
(size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5496 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5501 #endif
/* NS_IMPL_COCOA */
5502 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5508 - (void
)windowDidResize
: (NSNotification
*)notification
5511 #
if !defined
(NEW_STYLE_FS
) && ! defined
(NS_IMPL_GNUSTEP
)
5512 NSWindow
*theWindow
= [notification object
];
5513 /* We can get notification on the non-FS window when in fullscreen mode. */
5514 if ([self window
] != theWindow
) return;
5517 #ifdef NS_IMPL_GNUSTEP
5518 NSWindow
*theWindow
= [notification object
];
5520 /* In GNUstep, at least currently, it's possible to get a didResize
5521 without getting a willResize.. therefore we need to act as if we got
5522 the willResize now */
5523 NSSize sz
= [theWindow frame
].
size;
5524 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5525 #endif
/* NS_IMPL_GNUSTEP */
5527 NSTRACE
(windowDidResize
);
5528 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5530 #ifdef NS_IMPL_COCOA
5536 #endif
/* NS_IMPL_COCOA */
5538 if (cols
> 0 && rows
> 0)
5540 [self updateFrameSize
: YES
];
5543 ns_send_appdefined
(-1);
5547 - (void
)windowDidBecomeKey
: (NSNotification
*)notification
5548 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5550 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5551 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
5553 NSTRACE
(windowDidBecomeKey
);
5555 if (emacsframe
!= old_focus
)
5556 dpyinfo
->x_focus_frame
= emacsframe
;
5558 ns_frame_rehighlight
(emacsframe
);
5562 emacs_event
->kind
= FOCUS_IN_EVENT
;
5563 EV_TRAILER
((id
)nil
);
5568 - (void
)windowDidResignKey
: (NSNotification
*)notification
5569 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5571 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5572 NSTRACE
(windowDidResignKey
);
5574 if (dpyinfo
->x_focus_frame
== emacsframe
)
5575 dpyinfo
->x_focus_frame
= 0;
5577 ns_frame_rehighlight
(emacsframe
);
5579 /* FIXME: for some reason needed on second and subsequent clicks away
5580 from sole-frame Emacs to get hollow box to show */
5581 if (!windowClosing
&& [[self window
] isVisible
] == YES
)
5583 x_update_cursor
(emacsframe
, 1);
5584 x_set_frame_alpha
(emacsframe
);
5589 [self deleteWorkingText
];
5590 emacs_event
->kind
= FOCUS_IN_EVENT
;
5591 EV_TRAILER
((id
)nil
);
5596 - (void
)windowWillMiniaturize
: sender
5598 NSTRACE
(windowWillMiniaturize
);
5614 - initFrameFromEmacs
: (struct frame
*)f
5619 NSButton
*toggleButton
;
5624 NSTRACE
(initFrameFromEmacs
);
5627 processingCompose
= NO
;
5628 scrollbarsNeedingUpdate
= 0;
5629 fs_state
= FULLSCREEN_NONE
;
5630 fs_before_fs
= next_maximized
= -1;
5631 maximized_width
= maximized_height
= -1;
5634 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5636 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5637 r
= NSMakeRect
(0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, f
->text_cols
),
5638 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, f
->text_lines
));
5639 [self initWithFrame
: r
];
5640 [self setAutoresizingMask
: NSViewWidthSizable | NSViewHeightSizable
];
5642 FRAME_NS_VIEW
(f
) = self
;
5646 win
= [[EmacsWindow alloc
]
5647 initWithContentRect
: r
5648 styleMask
: (NSResizableWindowMask |
5649 #
if MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_7
5650 NSTitledWindowMask |
5652 NSMiniaturizableWindowMask |
5653 NSClosableWindowMask
)
5654 backing
: NSBackingStoreBuffered
5658 [win setCollectionBehavior
:NSWindowCollectionBehaviorFullScreenPrimary
];
5662 bwidth
= f
->border_width
= wr.
size.width
- r.
size.width
;
5663 tibar_height
= FRAME_NS_TITLEBAR_HEIGHT
(f
) = wr.
size.height
- r.
size.height
;
5665 [win setAcceptsMouseMovedEvents
: YES
];
5666 [win setDelegate
: self
];
5667 [win useOptimizedDrawing
: YES
];
5669 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5670 sz.height
= FRAME_LINE_HEIGHT
(f
);
5671 [win setResizeIncrements
: sz
];
5673 [[win contentView
] addSubview
: self
];
5676 [self registerForDraggedTypes
: ns_drag_types
];
5679 name
= [NSString stringWithUTF8String
:
5680 NILP
(tem
) ? "Emacs"
: SSDATA
(tem
)];
5681 [win setTitle
: name
];
5683 /* toolbar support */
5684 toolbar
= [[EmacsToolbar alloc
] initForView
: self withIdentifier
:
5685 [NSString stringWithFormat
: @"Emacs Frame
%d",
5687 [win setToolbar
: toolbar
];
5688 [toolbar setVisible
: NO
];
5689 #ifdef NS_IMPL_COCOA
5690 toggleButton
= [win standardWindowButton
: NSWindowToolbarButton
];
5691 [toggleButton setTarget
: self
];
5692 [toggleButton setAction
: @selector
(toggleToolbar
: )];
5694 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5698 [win setMiniwindowTitle
:
5699 [NSString stringWithUTF8String
: SSDATA
(tem
)]];
5702 NSScreen
*screen
= [win screen
];
5705 [win setFrameTopLeftPoint
: NSMakePoint
5706 (IN_BOUND
(-SCREENMAX
, f
->left_pos
, SCREENMAX
),
5707 IN_BOUND
(-SCREENMAX
,
5708 [screen frame
].
size.height
- NS_TOP_POS
(f
), SCREENMAX
))];
5711 [win makeFirstResponder
: self
];
5713 col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5714 (FRAME_DEFAULT_FACE
(emacsframe
)), emacsframe
);
5715 [win setBackgroundColor
: col
];
5716 if ([col alphaComponent
] != 1.0)
5717 [win setOpaque
: NO
];
5719 [self allocateGState
];
5721 [NSApp registerServicesMenuSendTypes
: ns_send_types
5729 - (void
)windowDidMove
: sender
5731 NSWindow
*win
= [self window
];
5732 NSRect r
= [win frame
];
5733 NSArray
*screens
= [NSScreen screens
];
5734 NSScreen
*screen
= [screens objectAtIndex
: 0];
5736 NSTRACE
(windowDidMove
);
5738 if (!emacsframe
->output_data.ns
)
5742 emacsframe
->left_pos
= r.origin.x
;
5743 emacsframe
->top_pos
=
5744 [screen frame
].
size.height
- (r.origin.y
+ r.
size.height
);
5749 /* Called AFTER method below, but before our windowWillResize call there leads
5750 to windowDidResize -> x_set_window_size. Update emacs' notion of frame
5751 location so set_window_size moves the frame. */
5752 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5754 emacsframe
->output_data.ns
->zooming
= 1;
5759 /* Override to do something slightly nonstandard, but nice. First click on
5760 zoom button will zoom vertically. Second will zoom completely. Third
5761 returns to original. */
5762 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5763 defaultFrame
:(NSRect
)defaultFrame
5765 NSRect result
= [sender frame
];
5767 NSTRACE
(windowWillUseStandardFrame
);
5769 if (fs_before_fs
!= -1) /* Entering fullscreen */
5771 result
= defaultFrame
;
5773 else if (next_maximized
== FULLSCREEN_HEIGHT
5774 ||
(next_maximized
== -1
5775 && abs (defaultFrame.
size.height
- result.
size.height
)
5776 > FRAME_LINE_HEIGHT
(emacsframe
)))
5779 ns_userRect
= result
;
5780 maximized_height
= result.
size.height
= defaultFrame.
size.height
;
5781 maximized_width
= -1;
5782 result.origin.y
= defaultFrame.origin.y
;
5783 [self setFSValue
: FULLSCREEN_HEIGHT
];
5785 else if (next_maximized
== FULLSCREEN_WIDTH
)
5787 ns_userRect
= result
;
5788 maximized_width
= result.
size.width
= defaultFrame.
size.width
;
5789 maximized_height
= -1;
5790 result.origin.x
= defaultFrame.origin.x
;
5791 [self setFSValue
: FULLSCREEN_WIDTH
];
5793 else if (next_maximized
== FULLSCREEN_MAXIMIZED
5794 ||
(next_maximized
== -1
5795 && abs (defaultFrame.
size.width
- result.
size.width
)
5796 > FRAME_COLUMN_WIDTH
(emacsframe
)))
5798 result
= defaultFrame
; /* second click */
5799 maximized_width
= result.
size.width
;
5800 maximized_height
= result.
size.height
;
5801 [self setFSValue
: FULLSCREEN_MAXIMIZED
];
5806 result
= ns_userRect.
size.height ? ns_userRect
: result
;
5807 ns_userRect
= NSMakeRect
(0, 0, 0, 0);
5808 [self setFSValue
: FULLSCREEN_NONE
];
5809 maximized_width
= maximized_width
= -1;
5812 if (fs_before_fs
== -1) next_maximized
= -1;
5813 [self windowWillResize
: sender toSize
: result.
size];
5818 - (void
)windowDidDeminiaturize
: sender
5820 NSTRACE
(windowDidDeminiaturize
);
5821 if (!emacsframe
->output_data.ns
)
5823 emacsframe
->async_iconified
= 0;
5824 emacsframe
->async_visible
= 1;
5825 windows_or_buffers_changed
++;
5829 emacs_event
->kind
= ICONIFY_EVENT
;
5830 EV_TRAILER
((id
)nil
);
5835 - (void
)windowDidExpose
: sender
5837 NSTRACE
(windowDidExpose
);
5838 if (!emacsframe
->output_data.ns
)
5840 emacsframe
->async_visible
= 1;
5841 SET_FRAME_GARBAGED
(emacsframe
);
5843 if (send_appdefined
)
5844 ns_send_appdefined
(-1);
5848 - (void
)windowDidMiniaturize
: sender
5850 NSTRACE
(windowDidMiniaturize
);
5851 if (!emacsframe
->output_data.ns
)
5854 emacsframe
->async_iconified
= 1;
5855 emacsframe
->async_visible
= 0;
5859 emacs_event
->kind
= ICONIFY_EVENT
;
5860 EV_TRAILER
((id
)nil
);
5864 - (void
)windowWillEnterFullScreen
:(NSNotification
*)notification
5866 fs_before_fs
= fs_state
;
5869 - (void
)windowDidEnterFullScreen
:(NSNotification
*)notification
5871 [self setFSValue
: FULLSCREEN_BOTH
];
5873 // Fix bad background.
5874 if ([toolbar isVisible
])
5876 [toolbar setVisible
:NO
];
5877 [toolbar setVisible
:YES
];
5880 [self windowDidBecomeKey
:notification
];
5881 [nonfs_window orderOut
:self
];
5885 - (void
)windowWillExitFullScreen
:(NSNotification
*)notification
5887 if (next_maximized
!= -1)
5888 fs_before_fs
= next_maximized
;
5891 - (void
)windowDidExitFullScreen
:(NSNotification
*)notification
5893 [self setFSValue
: fs_before_fs
];
5895 if (next_maximized
!= -1)
5896 [[self window
] performZoom
:self
];
5899 - (void
)toggleFullScreen
: (id
)sender
5902 [[self window
] toggleFullScreen
:sender
];
5904 NSWindow
*w
= [self window
], *fw
;
5905 BOOL onFirstScreen
= [[w screen
]
5906 isEqual:[[NSScreen screens
] objectAtIndex
:0]];
5907 struct frame
*f
= emacsframe
;
5909 NSRect r
, wr
= [w frame
];
5910 NSColor
*col
= ns_lookup_indexed_color
(NS_FACE_BACKGROUND
5911 (FRAME_DEFAULT_FACE
(f
)),
5914 sz.width
= FRAME_COLUMN_WIDTH
(f
);
5915 sz.height
= FRAME_LINE_HEIGHT
(f
);
5917 if (fs_state
!= FULLSCREEN_BOTH
)
5919 /* Hide dock and menubar if we are on the primary screen. */
5922 #
if defined
(NS_IMPL_COCOA
) && \
5923 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
5924 NSApplicationPresentationOptions options
5925 = NSApplicationPresentationAutoHideDock
5926 | NSApplicationPresentationAutoHideMenuBar
;
5928 [NSApp setPresentationOptions
: options
];
5930 [NSMenu setMenuBarVisible
:NO
];
5934 fw
= [[EmacsFSWindow alloc
]
5935 initWithContentRect
:[w contentRectForFrameRect
:wr
]
5936 styleMask
:NSBorderlessWindowMask
5937 backing
:NSBackingStoreBuffered
5941 [fw setContentView
:[w contentView
]];
5942 [fw setTitle
:[w
title]];
5943 [fw setDelegate
:self
];
5944 [fw setAcceptsMouseMovedEvents
: YES
];
5945 [fw useOptimizedDrawing
: YES
];
5946 [fw setResizeIncrements
: sz
];
5947 [fw setBackgroundColor
: col
];
5948 if ([col alphaComponent
] != 1.0)
5951 f
->border_width
= 0;
5952 FRAME_NS_TITLEBAR_HEIGHT
(f
) = 0;
5953 tobar_height
= FRAME_TOOLBAR_HEIGHT
(f
);
5954 FRAME_TOOLBAR_HEIGHT
(f
) = 0;
5955 FRAME_EXTERNAL_TOOL_BAR
(f
) = 0;
5959 [self windowWillEnterFullScreen
:nil
];
5960 [fw makeKeyAndOrderFront
:NSApp
];
5961 [fw makeFirstResponder
:self
];
5963 r
= [fw frameRectForContentRect
:[[fw screen
] frame
]];
5964 [fw setFrame
: r display
:YES animate
:YES
];
5965 [self windowDidEnterFullScreen
:nil
];
5976 #
if defined
(NS_IMPL_COCOA
) && \
5977 MAC_OS_X_VERSION_MAX_ALLOWED
>= MAC_OS_X_VERSION_10_6
5978 [NSApp setPresentationOptions
: NSApplicationPresentationDefault
];
5980 [NSMenu setMenuBarVisible
:YES
];
5984 [w setContentView
:[fw contentView
]];
5985 [w setResizeIncrements
: sz
];
5986 [w setBackgroundColor
: col
];
5987 if ([col alphaComponent
] != 1.0)
5990 f
->border_width
= bwidth
;
5991 FRAME_NS_TITLEBAR_HEIGHT
(f
) = tibar_height
;
5992 FRAME_TOOLBAR_HEIGHT
(f
) = tobar_height
;
5994 FRAME_EXTERNAL_TOOL_BAR
(f
) = 1;
5996 [self windowWillExitFullScreen
:nil
];
5997 [fw setFrame
: [w frame
] display
:YES animate
:YES
];
5999 [w makeKeyAndOrderFront
:NSApp
];
6000 [self windowDidExitFullScreen
:nil
];
6007 if (fs_state
!= emacsframe
->want_fullscreen
)
6009 if (fs_state
== FULLSCREEN_BOTH
)
6011 [self toggleFullScreen
:self
];
6014 switch (emacsframe
->want_fullscreen
)
6016 case FULLSCREEN_BOTH
:
6017 [self toggleFullScreen
:self
];
6019 case FULLSCREEN_WIDTH
:
6020 next_maximized
= FULLSCREEN_WIDTH
;
6021 if (fs_state
!= FULLSCREEN_BOTH
)
6022 [[self window
] performZoom
:self
];
6024 case FULLSCREEN_HEIGHT
:
6025 next_maximized
= FULLSCREEN_HEIGHT
;
6026 if (fs_state
!= FULLSCREEN_BOTH
)
6027 [[self window
] performZoom
:self
];
6029 case FULLSCREEN_MAXIMIZED
:
6030 next_maximized
= FULLSCREEN_MAXIMIZED
;
6031 if (fs_state
!= FULLSCREEN_BOTH
)
6032 [[self window
] performZoom
:self
];
6034 case FULLSCREEN_NONE
:
6035 if (fs_state
!= FULLSCREEN_BOTH
)
6037 next_maximized
= FULLSCREEN_NONE
;
6038 [[self window
] performZoom
:self
];
6043 emacsframe
->want_fullscreen
= FULLSCREEN_NONE
;
6048 - (void
) setFSValue
: (int
)value
6050 Lisp_Object lval
= Qnil
;
6053 case FULLSCREEN_BOTH
:
6056 case FULLSCREEN_WIDTH
:
6059 case FULLSCREEN_HEIGHT
:
6062 case FULLSCREEN_MAXIMIZED
:
6066 store_frame_param
(emacsframe
, Qfullscreen
, lval
);
6070 - (void
)mouseEntered
: (NSEvent
*)theEvent
6072 NSTRACE
(mouseEntered
);
6073 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
6077 - (void
)mouseExited
: (NSEvent
*)theEvent
6079 Mouse_HLInfo
*hlinfo
= emacsframe ? MOUSE_HL_INFO
(emacsframe
) : NULL;
6081 NSTRACE
(mouseExited
);
6086 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
6088 if (emacsframe
== hlinfo
->mouse_face_mouse_frame
)
6090 clear_mouse_face
(hlinfo
);
6091 hlinfo
->mouse_face_mouse_frame
= 0;
6099 if (context_menu_value
== -1)
6100 context_menu_value
= [sender tag
];
6103 NSInteger tag
= [sender tag
];
6104 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
6105 emacsframe
->menu_bar_vector
,
6109 ns_send_appdefined
(-1);
6114 - (EmacsToolbar
*)toolbar
6120 /* this gets called on toolbar button click */
6121 - toolbarClicked
: (id
)item
6124 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
6126 NSTRACE
(toolbarClicked
);
6131 /* send first event (for some reason two needed) */
6132 theEvent
= [[self window
] currentEvent
];
6133 emacs_event
->kind
= TOOL_BAR_EVENT
;
6134 XSETFRAME
(emacs_event
->arg
, emacsframe
);
6135 EV_TRAILER
(theEvent
);
6137 emacs_event
->kind
= TOOL_BAR_EVENT
;
6138 /* XSETINT (emacs_event->code, 0); */
6139 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
6140 idx
+ TOOL_BAR_ITEM_KEY
);
6141 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6142 EV_TRAILER
(theEvent
);
6147 - toggleToolbar
: (id
)sender
6152 emacs_event
->kind
= NS_NONKEY_EVENT
;
6153 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
6154 EV_TRAILER
((id
)nil
);
6159 - (void
)drawRect
: (NSRect
)rect
6161 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
6162 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
6166 if (!emacsframe ||
!emacsframe
->output_data.ns
)
6169 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
6170 expose_frame
(emacsframe
, x
, y
, width
, height
);
6173 drawRect: may be called (at least in OS X 10.5) for invisible
6174 views as well for some reason. Thus, do not infer visibility
6177 emacsframe->async_visible = 1;
6178 emacsframe->async_iconified = 0;
6183 /* NSDraggingDestination protocol methods. Actually this is not really a
6184 protocol, but a category of Object. O well... */
6186 -(NSUInteger
) draggingEntered
: (id
<NSDraggingInfo
>) sender
6188 NSTRACE
(draggingEntered
);
6189 return NSDragOperationGeneric
;
6193 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
6199 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
6204 NSEvent
*theEvent
= [[self window
] currentEvent
];
6207 NSTRACE
(performDragOperation
);
6212 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
6213 x
= lrint
(position.x
); y
= lrint
(position.y
);
6215 pb
= [sender draggingPasteboard
];
6216 type = [pb availableTypeFromArray
: ns_drag_types
];
6221 else if ([type isEqualToString
: NSFilenamesPboardType
])
6224 NSEnumerator
*fenum
;
6227 if (!(files
= [pb propertyListForType
: type]))
6230 fenum
= [files objectEnumerator
];
6231 while ( (file
= [fenum nextObject
]) )
6233 emacs_event
->kind
= NS_NONKEY_EVENT
;
6234 emacs_event
->code
= KEY_NS_DRAG_FILE
;
6235 XSETINT
(emacs_event
->x
, x
);
6236 XSETINT
(emacs_event
->y
, y
);
6237 ns_input_file
= append2
(ns_input_file
,
6238 build_string
([file UTF8String
]));
6239 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6240 EV_TRAILER
(theEvent
);
6244 else if ([type isEqualToString
: NSURLPboardType
])
6249 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
6250 [fileURL isFileURL
] == NO
)
6253 file
= [fileURL
path];
6254 emacs_event
->kind
= NS_NONKEY_EVENT
;
6255 emacs_event
->code
= KEY_NS_DRAG_FILE
;
6256 XSETINT
(emacs_event
->x
, x
);
6257 XSETINT
(emacs_event
->y
, y
);
6258 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
6259 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6260 EV_TRAILER
(theEvent
);
6263 else if ([type isEqualToString
: NSStringPboardType
]
6264 ||
[type isEqualToString
: NSTabularTextPboardType
])
6268 if (! (data
= [pb stringForType
: type]))
6271 emacs_event
->kind
= NS_NONKEY_EVENT
;
6272 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
6273 XSETINT
(emacs_event
->x
, x
);
6274 XSETINT
(emacs_event
->y
, y
);
6275 ns_input_text
= build_string
([data UTF8String
]);
6276 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6277 EV_TRAILER
(theEvent
);
6280 else if ([type isEqualToString
: NSColorPboardType
])
6282 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
6283 emacs_event
->kind
= NS_NONKEY_EVENT
;
6284 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
6285 XSETINT
(emacs_event
->x
, x
);
6286 XSETINT
(emacs_event
->y
, y
);
6287 ns_input_color
= ns_color_to_lisp
(c
);
6288 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6289 EV_TRAILER
(theEvent
);
6292 else if ([type isEqualToString
: NSFontPboardType
])
6294 /* impl based on GNUstep NSTextView.m */
6295 NSData
*data
= [pb dataForType
: NSFontPboardType
];
6296 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
6297 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
6303 emacs_event
->kind
= NS_NONKEY_EVENT
;
6304 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
6305 XSETINT
(emacs_event
->x
, x
);
6306 XSETINT
(emacs_event
->y
, y
);
6307 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
6308 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
6309 ns_input_fontsize
= build_string
(fontSize
);
6310 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
6311 EV_TRAILER
(theEvent
);
6316 error ("Invalid data
type in dragging pasteboard."
);
6322 - (id
) validRequestorForSendType
: (NSString
*)typeSent
6323 returnType
: (NSString
*)typeReturned
6325 NSTRACE
(validRequestorForSendType
);
6326 if (typeSent
!= nil
&& [ns_send_types indexOfObject
: typeSent
] != NSNotFound
6327 && typeReturned
== nil
)
6329 if (! NILP
(ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
)))
6333 return [super validRequestorForSendType
: typeSent
6334 returnType
: typeReturned
];
6338 /* The next two methods are part of NSServicesRequests informal protocol,
6339 supposedly called when a services menu item is chosen from this app.
6340 But this should not happen because we override the services menu with our
6341 own entries which call ns-perform-service.
6342 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
6343 So let's at least stub them out until further investigation can be done. */
6345 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
6347 /* we could call ns_string_from_pasteboard(pboard) here but then it should
6348 be written into the buffer in place of the existing selection..
6349 ordinary service calls go through functions defined in ns-win.el */
6353 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
6355 NSArray
*typesDeclared
;
6358 /* We only support NSStringPboardType */
6359 if ([types containsObject
:NSStringPboardType
] == NO
) {
6363 val
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6364 if (CONSP
(val
) && SYMBOLP
(XCAR
(val
)))
6367 if (CONSP
(val
) && NILP
(XCDR
(val
)))
6370 if (! STRINGP
(val
))
6373 typesDeclared
= [NSArray arrayWithObject
:NSStringPboardType
];
6374 [pb declareTypes
:typesDeclared owner
:nil
];
6375 ns_string_to_pasteboard
(pb
, val
);
6380 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
6381 (gives a miniaturized version of the window); currently we use the latter for
6382 frames whose active buffer doesn't correspond to any file
6383 (e.g., '*scratch*') */
6384 - setMiniwindowImage
: (BOOL
) setMini
6386 id
image = [[self window
] miniwindowImage
];
6387 NSTRACE
(setMiniwindowImage
);
6389 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
6390 about "AppleDockIconEnabled" notwithstanding, however the set message
6391 below has its effect nonetheless. */
6392 if (image != emacsframe
->output_data.ns
->miniimage
)
6394 if (image && [image isKindOfClass
: [EmacsImage
class]])
6396 [[self window
] setMiniwindowImage
:
6397 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
6404 - (void
) setRows
: (int
) r andColumns
: (int
) c
6410 @
end /* EmacsView */
6414 /* ==========================================================================
6416 EmacsWindow implementation
6418 ========================================================================== */
6420 @implementation EmacsWindow
6422 #ifdef NS_IMPL_COCOA
6423 - (id
)accessibilityAttributeValue
:(NSString
*)attribute
6425 Lisp_Object str
= Qnil
;
6426 struct frame
*f
= SELECTED_FRAME
();
6427 struct buffer
*curbuf
= XBUFFER
(XWINDOW
(f
->selected_window
)->buffer
);
6429 if ([attribute isEqualToString
:NSAccessibilityRoleAttribute
])
6430 return NSAccessibilityTextFieldRole
;
6432 if ([attribute isEqualToString
:NSAccessibilitySelectedTextAttribute
]
6433 && curbuf
&& ! NILP
(BVAR
(curbuf
, mark_active
)))
6435 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6437 else if (curbuf
&& [attribute isEqualToString
:NSAccessibilityValueAttribute
])
6439 if (! NILP
(BVAR
(curbuf
, mark_active
)))
6440 str
= ns_get_local_selection
(QPRIMARY
, QUTF8_STRING
);
6444 ptrdiff_t start_byte
= BUF_BEGV_BYTE
(curbuf
);
6445 ptrdiff_t byte_range
= BUF_ZV_BYTE
(curbuf
) - start_byte
;
6446 ptrdiff_t range
= BUF_ZV
(curbuf
) - BUF_BEGV
(curbuf
);
6448 if (! NILP
(BVAR
(curbuf
, enable_multibyte_characters
)))
6449 str
= make_uninit_multibyte_string
(range
, byte_range
);
6451 str
= make_uninit_string
(range
);
6452 /* To check: This returns emacs-utf-8, which is a superset of utf-8.
6453 Is this a problem? */
6454 memcpy
(SDATA
(str
), BYTE_POS_ADDR
(start_byte
), byte_range
);
6461 if (CONSP
(str
) && SYMBOLP
(XCAR
(str
)))
6464 if (CONSP
(str
) && NILP
(XCDR
(str
)))
6469 const
char *utfStr
= SSDATA
(str
);
6470 NSString
*nsStr
= [NSString stringWithUTF8String
: utfStr
];
6475 return [super accessibilityAttributeValue
:attribute
];
6477 #endif
/* NS_IMPL_COCOA */
6479 /* If we have multiple monitors, one above the other, we don't want to
6480 restrict the height to just one monitor. So we override this. */
6481 - (NSRect
)constrainFrameRect
:(NSRect
)frameRect toScreen
:(NSScreen
*)screen
6483 /* When making the frame visible for the first time or if there is just
6484 one screen, we want to constrain. Other times not. */
6485 NSUInteger nr_screens
= [[NSScreen screens
] count
];
6486 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
6487 NSTRACE
(constrainFrameRect
);
6489 if (nr_screens
== 1)
6491 NSRect r
= [super constrainFrameRect
:frameRect toScreen
:screen
];
6495 if (f
->output_data.ns
->dont_constrain
6496 || ns_menu_bar_should_be_hidden
())
6499 f
->output_data.ns
->dont_constrain
= 1;
6500 return [super constrainFrameRect
:frameRect toScreen
:screen
];
6503 @
end /* EmacsWindow */
6506 @implementation EmacsFSWindow
6508 - (BOOL
)canBecomeKeyWindow
6513 - (BOOL
)canBecomeMainWindow
6520 /* ==========================================================================
6522 EmacsScroller implementation
6524 ========================================================================== */
6527 @implementation EmacsScroller
6529 /* for repeat button push */
6530 #define SCROLL_BAR_FIRST_DELAY
0.5
6531 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
6533 + (CGFloat
) scrollerWidth
6535 /* TODO: if we want to allow variable widths, this is the place to do it,
6536 however neither GNUstep nor Cocoa support it very well */
6537 return [NSScroller scrollerWidth
];
6541 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
6543 NSTRACE
(EmacsScroller_initFrame
);
6545 r.
size.width
= [EmacsScroller scrollerWidth
];
6546 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
6547 [self setContinuous
: YES
];
6548 [self setEnabled
: YES
];
6550 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
6551 locked against the top and bottom edges, and right edge on OS X, where
6552 scrollers are on right. */
6553 #ifdef NS_IMPL_GNUSTEP
6554 [self setAutoresizingMask
: NSViewMaxXMargin | NSViewHeightSizable
];
6556 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
6561 pixel_height
= NSHeight
(r
);
6562 if (pixel_height
== 0) pixel_height
= 1;
6563 min_portion
= 20 / pixel_height
;
6565 frame
= XFRAME
(XWINDOW
(win
)->frame
);
6566 if (FRAME_LIVE_P
(frame
))
6569 EmacsView
*view = FRAME_NS_VIEW
(frame
);
6570 NSView
*sview
= [[view window
] contentView
];
6571 NSArray
*subs
= [sview subviews
];
6573 /* disable optimization stopping redraw of other scrollbars */
6574 view->scrollbarsNeedingUpdate
= 0;
6575 for (i
=[subs count
]-1; i
>= 0; i
--)
6576 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
6577 view->scrollbarsNeedingUpdate
++;
6578 [sview addSubview
: self
];
6581 /* [self setFrame: r]; */
6587 - (void
)setFrame
: (NSRect
)newRect
6589 NSTRACE
(EmacsScroller_setFrame
);
6590 /* block_input (); */
6591 pixel_height
= NSHeight
(newRect
);
6592 if (pixel_height
== 0) pixel_height
= 1;
6593 min_portion
= 20 / pixel_height
;
6594 [super setFrame
: newRect
];
6596 /* unblock_input (); */
6602 NSTRACE
(EmacsScroller_dealloc
);
6604 wset_vertical_scroll_bar
(XWINDOW
(win
), Qnil
);
6632 /* ensure other scrollbar updates after deletion */
6633 view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6635 view->scrollbarsNeedingUpdate
++;
6636 [self removeFromSuperview
];
6644 - (void
)resetCursorRects
6646 NSRect visible
= [self visibleRect
];
6647 NSTRACE
(resetCursorRects
);
6649 if (!NSIsEmptyRect
(visible
))
6650 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
6651 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
6655 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
6658 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
6659 && portion
!= whole
; /* needed for resize empty buf */
6663 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
6665 NSTRACE
(setPosition
);
6667 em_position
= position
;
6668 em_portion
= portion
;
6671 if (portion
>= whole
)
6673 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6674 [self setKnobProportion
: 1.0];
6675 [self setDoubleValue
: 1.0];
6677 [self setFloatValue
: 0.0 knobProportion
: 1.0];
6683 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
6684 pos
= (float
)position
/ (whole
- portion
);
6685 por
= (float
)portion
/whole
;
6686 #
if defined
(NS_IMPL_COCOA
) && MAC_OS_X_VERSION_MAX_ALLOWED
> MAC_OS_X_VERSION_10_5
6687 [self setKnobProportion
: por
];
6688 [self setDoubleValue
: pos
];
6690 [self setFloatValue
: pos knobProportion
: por
];
6694 /* Events may come here even if the event loop is not running.
6695 If we don't enter the event loop, the scroll bar will not update.
6696 So send SIGIO to ourselves. */
6697 if (apploopnr
== 0) raise
(SIGIO
);
6702 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
6703 drag events will go directly to the EmacsScroller. Leaving in for now. */
6704 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
6705 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
6707 *part
= last_hit_part
;
6709 XSETINT
(*y
, pixel_height
);
6710 if ([self floatValue
] > 0.999)
6711 XSETINT
(*x
, pixel_height
);
6713 XSETINT
(*x
, pixel_height
* [self floatValue
]);
6717 /* set up emacs_event */
6718 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
6723 emacs_event
->part
= last_hit_part
;
6724 emacs_event
->code
= 0;
6725 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
6726 emacs_event
->frame_or_window
= win
;
6727 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
6728 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
6729 emacs_event
->arg
= Qnil
;
6730 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
6731 XSETINT
(emacs_event
->y
, pixel_height
-20);
6735 n_emacs_events_pending
++;
6736 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
6739 hold_event
(emacs_event
);
6740 EVENT_INIT
(*emacs_event
);
6741 ns_send_appdefined
(-1);
6745 /* called manually thru timer to implement repeated button action w/hold-down */
6746 - repeatScroll
: (NSTimer
*)scrollEntry
6748 NSEvent
*e
= [[self window
] currentEvent
];
6749 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
6750 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
6752 /* clear timer if need be */
6753 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
6755 [scroll_repeat_entry invalidate
];
6756 [scroll_repeat_entry release
];
6757 scroll_repeat_entry
= nil
;
6763 = [[NSTimer scheduledTimerWithTimeInterval
:
6764 SCROLL_BAR_CONTINUOUS_DELAY
6766 selector
: @selector
(repeatScroll
:)
6772 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
6777 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
6778 mouseDragged events without going into a modal loop. */
6779 - (void
)mouseDown
: (NSEvent
*)e
6782 /* hitPart is only updated AFTER event is passed on */
6783 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6784 double inc
= 0.0, loc
, kloc
, pos
;
6787 NSTRACE
(EmacsScroller_mouseDown
);
6791 case NSScrollerDecrementPage
:
6792 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6793 case NSScrollerIncrementPage
:
6794 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6795 case NSScrollerDecrementLine
:
6796 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6797 case NSScrollerIncrementLine
:
6798 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6799 case NSScrollerKnob
:
6800 last_hit_part
= scroll_bar_handle
; break;
6801 case NSScrollerKnobSlot
: /* GNUstep-only */
6802 last_hit_part
= scroll_bar_move_ratio
; break;
6803 default
: /* NSScrollerNoPart? */
6804 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%ld\n",
6811 pos
= 0; /* ignored */
6813 /* set a timer to repeat, as we can't let superclass do this modally */
6815 = [[NSTimer scheduledTimerWithTimeInterval
: SCROLL_BAR_FIRST_DELAY
6817 selector
: @selector
(repeatScroll
:)
6824 /* handle, or on GNUstep possibly slot */
6825 NSEvent
*fake_event
;
6827 /* compute float loc in slot and mouse offset on knob */
6828 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6830 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6836 else if (loc
>= NSHeight
(sr
))
6838 loc
= NSHeight
(sr
);
6846 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6848 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6850 last_mouse_offset
= kloc
;
6852 /* if knob, tell emacs a location offset by knob pos
6853 (to indicate top of handle) */
6854 if (part
== NSScrollerKnob
)
6855 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6857 /* else this is a slot click on GNUstep: go straight there */
6858 pos
= loc
/ NSHeight
(sr
);
6860 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6861 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6862 location
: [e locationInWindow
]
6863 modifierFlags
: [e modifierFlags
]
6864 timestamp
: [e timestamp
]
6865 windowNumber
: [e windowNumber
]
6866 context
: [e context
]
6867 eventNumber
: [e eventNumber
]
6868 clickCount
: [e clickCount
]
6869 pressure
: [e pressure
]];
6870 [super mouseUp
: fake_event
];
6873 if (part
!= NSScrollerKnob
)
6874 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6878 /* Called as we manually track scroller drags, rather than superclass. */
6879 - (void
)mouseDragged
: (NSEvent
*)e
6885 NSTRACE
(EmacsScroller_mouseDragged
);
6887 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6889 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6896 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6898 loc
= NSHeight
(sr
) + last_mouse_offset
;
6902 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6903 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6907 - (void
)mouseUp
: (NSEvent
*)e
6909 if (scroll_repeat_entry
)
6911 [scroll_repeat_entry invalidate
];
6912 [scroll_repeat_entry release
];
6913 scroll_repeat_entry
= nil
;
6919 /* treat scrollwheel events in the bar as though they were in the main window */
6920 - (void
) scrollWheel
: (NSEvent
*)theEvent
6922 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6923 [view mouseDown
: theEvent
];
6926 @
end /* EmacsScroller */
6931 /* ==========================================================================
6933 Font-related functions; these used to be in nsfaces.m
6935 ========================================================================== */
6939 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6941 struct font
*font
= XFONT_OBJECT
(font_object
);
6944 fontset
= fontset_from_font
(font_object
);
6945 FRAME_FONTSET
(f
) = fontset
;
6947 if (FRAME_FONT
(f
) == font
)
6948 /* This font is already set in frame F. There's nothing more to
6952 FRAME_FONT
(f
) = font
;
6954 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6955 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6956 FRAME_SPACE_WIDTH
(f
) = font
->space_width
;
6957 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6959 compute_fringe_widths
(f
, 1);
6961 /* Compute the scroll bar width in character columns. */
6962 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6964 int wid
= FRAME_COLUMN_WIDTH
(f
);
6965 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6966 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6970 int wid
= FRAME_COLUMN_WIDTH
(f
);
6971 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6974 /* Now make the frame display the given font. */
6975 if (FRAME_NS_WINDOW
(f
) != 0)
6976 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6982 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6983 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6987 ns_xlfd_to_fontname
(const
char *xlfd
)
6988 /* --------------------------------------------------------------------------
6989 Convert an X font name (XLFD) to an NS font name.
6990 Only family is used.
6991 The string returned is temporarily allocated.
6992 -------------------------------------------------------------------------- */
6994 char *name
= xmalloc
(180);
6998 if (!strncmp
(xlfd
, "
--"
, 2))
6999 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
7001 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
7003 /* stopgap for malformed XLFD input */
7004 if (strlen
(name
) == 0)
7005 strcpy
(name
, "Monaco"
);
7007 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
7008 also uppercase after '-' or ' ' */
7009 name
[0] = c_toupper
(name
[0]);
7010 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
7016 name
[i
+1] = c_toupper
(name
[i
+1]);
7018 else if (name
[i
] == '_')
7022 name
[i
+1] = c_toupper
(name
[i
+1]);
7025 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
7026 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
7033 syms_of_nsterm
(void
)
7035 NSTRACE
(syms_of_nsterm
);
7037 ns_antialias_threshold
= 10.0;
7039 /* from 23+ we need to tell emacs what modifiers there are.. */
7040 DEFSYM
(Qmodifier_value
, "modifier
-value"
);
7041 DEFSYM
(Qalt
, "alt"
);
7042 DEFSYM
(Qhyper
, "hyper"
);
7043 DEFSYM
(Qmeta
, "
meta"
);
7044 DEFSYM
(Qsuper
, "super"
);
7045 DEFSYM
(Qcontrol
, "control"
);
7046 DEFSYM
(QUTF8_STRING
, "UTF8_STRING"
);
7048 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
7049 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
7050 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
7051 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
7052 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
7054 DEFVAR_LISP
("ns
-input-file"
, ns_input_file
,
7055 "The file specified in the last NS event."
);
7056 ns_input_file
=Qnil
;
7058 DEFVAR_LISP
("ns
-input-text"
, ns_input_text
,
7059 "The data received in the last NS
text drag event."
);
7060 ns_input_text
=Qnil
;
7062 DEFVAR_LISP
("ns
-working
-text"
, ns_working_text
,
7063 "String
for visualizing working composition sequence."
);
7064 ns_working_text
=Qnil
;
7066 DEFVAR_LISP
("ns
-input-font"
, ns_input_font
,
7067 "The font specified in the last NS event."
);
7068 ns_input_font
=Qnil
;
7070 DEFVAR_LISP
("ns
-input-fontsize"
, ns_input_fontsize
,
7071 "The fontsize specified in the last NS event."
);
7072 ns_input_fontsize
=Qnil
;
7074 DEFVAR_LISP
("ns
-input-line"
, ns_input_line
,
7075 "The
line specified in the last NS event."
);
7076 ns_input_line
=Qnil
;
7078 DEFVAR_LISP
("ns
-input-color"
, ns_input_color
,
7079 "The color specified in the last NS event."
);
7080 ns_input_color
=Qnil
;
7082 DEFVAR_LISP
("ns
-input-spi
-name"
, ns_input_spi_name
,
7083 "The service name specified in the last NS event."
);
7084 ns_input_spi_name
=Qnil
;
7086 DEFVAR_LISP
("ns
-input-spi
-arg"
, ns_input_spi_arg
,
7087 "The service argument specified in the last NS event."
);
7088 ns_input_spi_arg
=Qnil
;
7090 DEFVAR_LISP
("ns
-alternate
-modifier"
, ns_alternate_modifier
,
7091 "This variable describes the behavior of the alternate or option key.
\n\
7092 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7093 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
7094 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7095 ns_alternate_modifier
= Qmeta
;
7097 DEFVAR_LISP
("ns
-right
-alternate
-modifier"
, ns_right_alternate_modifier
,
7098 "This variable describes the behavior of the right alternate or option key.
\n\
7099 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7100 Set to left means be the same key as `ns
-alternate
-modifier
'.\n\
7101 Set to none means that the alternate / option key is not interpreted by Emacs\n\
7102 at all, allowing it to be used at a lower level for accented character entry.");
7103 ns_right_alternate_modifier = Qleft;
7105 DEFVAR_LISP ("ns-command-modifier", ns_command_modifier,
7106 "This variable describes the behavior of the command key.\n\
7107 Set to control, meta, alt, super, or hyper means it is taken to be that key.");
7108 ns_command_modifier = Qsuper;
7110 DEFVAR_LISP ("ns-right-command-modifier", ns_right_command_modifier,
7111 "This variable describes the behavior of the right command key.\n\
7112 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7113 Set to left means be the same key as `ns-command-modifier'.
\n\
7114 Set to none means that the command
/ option key is not interpreted by Emacs
\n\
7115 at
all, allowing it to be used at a
lower level
for accented character entry."
);
7116 ns_right_command_modifier
= Qleft
;
7118 DEFVAR_LISP
("ns
-control
-modifier"
, ns_control_modifier
,
7119 "This variable describes the behavior of the control key.
\n\
7120 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
7121 ns_control_modifier
= Qcontrol
;
7123 DEFVAR_LISP
("ns
-right
-control
-modifier"
, ns_right_control_modifier
,
7124 "This variable describes the behavior of the right control key.
\n\
7125 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
7126 Set to left means be the same key as `ns
-control
-modifier
'.\n\
7127 Set to none means that the control / option key is not interpreted by Emacs\n\
7128 at all, allowing it to be used at a lower level for accented character entry.");
7129 ns_right_control_modifier = Qleft;
7131 DEFVAR_LISP ("ns-function-modifier", ns_function_modifier,
7132 "This variable describes the behavior of the function key (on laptops).\n\
7133 Set to control, meta, alt, super, or hyper means it is taken to be that key.\n\
7134 Set to none means that the function key is not interpreted by Emacs at all,\n\
7135 allowing it to be used at a lower level for accented character entry.");
7136 ns_function_modifier = Qnone;
7138 DEFVAR_LISP ("ns-antialias-text", ns_antialias_text,
7139 "Non-nil (the default) means to render text antialiased.");
7140 ns_antialias_text = Qt;
7142 DEFVAR_LISP ("ns-confirm-quit", ns_confirm_quit,
7143 "Whether to confirm application quit using dialog.");
7144 ns_confirm_quit = Qnil;
7146 staticpro (&ns_display_name_list);
7147 ns_display_name_list = Qnil;
7149 staticpro (&last_mouse_motion_frame);
7150 last_mouse_motion_frame = Qnil;
7152 DEFVAR_LISP ("ns-auto-hide-menu-bar", ns_auto_hide_menu_bar,
7153 doc: /* Non-nil means that the menu bar is hidden, but appears when the mouse is near.
7154 Only works on OSX 10.6 or later. */);
7155 ns_auto_hide_menu_bar = Qnil;
7157 /* TODO: move to common code */
7158 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars,
7159 doc: /* Which toolkit scroll bars Emacs uses, if any.
7160 A value of nil means Emacs doesn't use toolkit scroll bars.
7161 With the X Window system
, the value is a symbol describing the
7162 X toolkit. Possible values are
: gtk
, motif
, xaw
, or xaw3d.
7163 With MS Windows or Nextstep
, the value is t. */
);
7164 Vx_toolkit_scroll_bars
= Qt
;
7166 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
7167 x_use_underline_position_properties
,
7168 doc: /*Non-nil means make use of UNDERLINE_POSITION font properties.
7169 A value of nil means ignore them. If you encounter fonts with bogus
7170 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
7171 to 4.1, set this to nil. */);
7172 x_use_underline_position_properties
= 0;
7174 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
7175 x_underline_at_descent_line
,
7176 doc: /* Non-nil means to draw the underline at the same place as the descent line.
7177 A value of nil means to draw the underline according to the value of the
7178 variable `x-use-underline-position-properties', which is usually at the
7179 baseline level. The default value is nil. */);
7180 x_underline_at_descent_line
= 0;
7182 /* Tell emacs about this window system. */
7183 Fprovide
(intern
("ns"
), Qnil
);