1 /* NeXT/Open/GNUstep / MacOSX communication module.
2 Copyright (C) 1989, 1993, 1994, 2005, 2006, 2008, 2009
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 Originally by Carl Edman
22 Updated by Christian Limpach (chris@nice.ch)
23 OpenStep/Rhapsody port by Scott Bender (sbender@harmony-ds.com)
24 MacOSX/Aqua port by Christophe de Dinechin (descubes@earthlink.net)
25 GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
28 /* This should be the first include, as it may set up #defines affecting
29 interpretation of even the system includes. */
33 #include
<sys
/types.h
>
39 #include "blockinput.h"
40 #include "sysselect.h"
43 #include "character.h"
45 #include "composite.h"
48 #include "termhooks.h"
59 int term_trace_num
= 0;
60 #define NSTRACE
(x
) fprintf (stderr
, "
%s:%d: [%d] " #x "\n", \
61 __FILE__
, __LINE__
, ++term_trace_num
)
67 /* ==========================================================================
71 ========================================================================== */
73 /* Convert a symbol indexed with an NSxxx value to a value as defined
74 in keyboard.c (lispy_function_key). I hope this is a correct way
76 static unsigned convert_ns_to_X_keysym
[] =
78 NSHomeFunctionKey
, 0x50,
79 NSLeftArrowFunctionKey
, 0x51,
80 NSUpArrowFunctionKey
, 0x52,
81 NSRightArrowFunctionKey
, 0x53,
82 NSDownArrowFunctionKey
, 0x54,
83 NSPageUpFunctionKey
, 0x55,
84 NSPageDownFunctionKey
, 0x56,
85 NSEndFunctionKey
, 0x57,
86 NSBeginFunctionKey
, 0x58,
87 NSSelectFunctionKey
, 0x60,
88 NSPrintFunctionKey
, 0x61,
89 NSExecuteFunctionKey
, 0x62,
90 NSInsertFunctionKey
, 0x63,
91 NSUndoFunctionKey
, 0x65,
92 NSRedoFunctionKey
, 0x66,
93 NSMenuFunctionKey
, 0x67,
94 NSFindFunctionKey
, 0x68,
95 NSHelpFunctionKey
, 0x6A,
96 NSBreakFunctionKey
, 0x6B,
98 NSF1FunctionKey
, 0xBE,
99 NSF2FunctionKey
, 0xBF,
100 NSF3FunctionKey
, 0xC0,
101 NSF4FunctionKey
, 0xC1,
102 NSF5FunctionKey
, 0xC2,
103 NSF6FunctionKey
, 0xC3,
104 NSF7FunctionKey
, 0xC4,
105 NSF8FunctionKey
, 0xC5,
106 NSF9FunctionKey
, 0xC6,
107 NSF10FunctionKey
, 0xC7,
108 NSF11FunctionKey
, 0xC8,
109 NSF12FunctionKey
, 0xC9,
110 NSF13FunctionKey
, 0xCA,
111 NSF14FunctionKey
, 0xCB,
112 NSF15FunctionKey
, 0xCC,
113 NSF16FunctionKey
, 0xCD,
114 NSF17FunctionKey
, 0xCE,
115 NSF18FunctionKey
, 0xCF,
116 NSF19FunctionKey
, 0xD0,
117 NSF20FunctionKey
, 0xD1,
118 NSF21FunctionKey
, 0xD2,
119 NSF22FunctionKey
, 0xD3,
120 NSF23FunctionKey
, 0xD4,
121 NSF24FunctionKey
, 0xD5,
123 NSBackspaceCharacter
, 0x08, /* 8: Not on some KBs. */
124 NSDeleteCharacter
, 0xFF, /* 127: Big 'delete' key upper right. */
125 NSDeleteFunctionKey
, 0x9F, /* 63272: Del forw key off main array. */
127 NSTabCharacter
, 0x09,
128 0x19, 0x09, /* left tab->regular since pass shift */
129 NSCarriageReturnCharacter
, 0x0D,
130 NSNewlineCharacter
, 0x0D,
131 NSEnterCharacter
, 0x8D,
133 0x1B, 0x1B /* escape */
137 /* Lisp communications */
138 Lisp_Object ns_input_file
, ns_input_font
, ns_input_fontsize
, ns_input_line
;
139 Lisp_Object ns_input_color
, ns_input_text
, ns_working_text
;
140 Lisp_Object ns_input_spi_name
, ns_input_spi_arg
;
141 Lisp_Object Vx_toolkit_scroll_bars
;
142 static Lisp_Object Qmodifier_value
;
143 /* TODO: unsure why these defined in term files, anyway we need in keymap.c */
144 Lisp_Object Qalt
, Qcontrol
, Qhyper
, Qmeta
, Qsuper
;
145 extern Lisp_Object Qcursor_color
, Qcursor_type
, Qns
;
148 /* Some preferences equivalent to those set by X resources under X are
149 managed through the OpenStep defaults system. We depart from X
150 behavior and refuse to read defaults when started under these
153 /* Set in emacs.c. */
156 /* Specifies which emacs modifier should be generated when NS receives
157 the Alternate modifer. May be Qnone or any of the modifier lisp symbols. */
158 Lisp_Object ns_alternate_modifier
;
160 /* Specifies which emacs modifier should be generated when NS receives
161 the Command modifer. May be any of the modifier lisp symbols. */
162 Lisp_Object ns_command_modifier
;
164 /* Specifies which emacs modifier should be generated when NS receives
165 the Control modifer. May be any of the modifier lisp symbols. */
166 Lisp_Object ns_control_modifier
;
168 /* Specifies which emacs modifier should be generated when NS receives
169 the Function modifer (laptops). May be any of the modifier lisp symbols. */
170 Lisp_Object ns_function_modifier
;
172 /* Control via default 'GSFontAntiAlias' on OS X and GNUstep. */
173 Lisp_Object ns_antialias_text
;
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 /* Controls use of an undocumented CG function to do Quickdraw-style font
181 smoothing (less heavy) instead of regular Quartz smoothing. */
182 Lisp_Object ns_use_qd_smoothing
;
184 /* Used to pick up AppleHighlightColor on OS X */
185 NSString
*ns_selection_color
;
187 /* Confirm on exit. */
188 Lisp_Object ns_confirm_quit
;
190 NSArray
*ns_send_types
=0, *ns_return_types
=0, *ns_drag_types
=0;
192 /* Display variables */
193 struct ns_display_info
*x_display_list
; /* Chain of existing displays */
194 Lisp_Object ns_display_name_list
;
195 long context_menu_value
= 0;
198 NSPoint last_mouse_motion_position
;
199 static NSRect last_mouse_glyph
;
200 static unsigned
long last_mouse_movement_time
= 0;
201 static Lisp_Object last_mouse_motion_frame
;
202 static EmacsScroller
*last_mouse_scroll_bar
= nil
;
203 static
struct frame
*ns_updating_frame
;
204 static NSView
*focus_view
= NULL;
205 static int ns_window_num
=0;
207 static BOOL gsaved
= NO
;
208 BOOL ns_in_resize
= NO
;
209 static BOOL ns_fake_keydown
= NO
;
210 int ns_tmp_flags
; /* FIXME */
211 struct nsfont_info
*ns_tmp_font
; /* FIXME */
212 /*static int debug_lock = 0; */
215 /* This undocumented Quartz function controls how fonts are anti-aliased.
216 (Found from code in Mac wxWindows impl, discovered by running `nm' on
218 Mode 0 is normal anti-aliasing, mode 1 is no anti-aliasing, and mode 2 is
219 4-bit pixel-aligned anti-aliasing (the old QuickDraw standard). */
220 extern void CGContextSetFontRenderingMode
(CGContextRef cg
, int v
);
225 static BOOL send_appdefined
= YES
;
226 static NSEvent
*last_appdefined_event
= 0;
227 static NSTimer
*timed_entry
= 0;
228 static NSTimer
*fd_entry
= nil
;
229 static NSTimer
*scroll_repeat_entry
= nil
;
230 static fd_set select_readfds
, t_readfds
;
231 static
struct timeval select_timeout
;
232 static int select_nfds
;
233 static NSAutoreleasePool
*outerpool
;
234 static
struct input_event
*emacs_event
= NULL;
235 static
struct input_event
*q_event_ptr
= NULL;
236 static int n_emacs_events_pending
= 0;
237 static NSMutableArray
*ns_pending_files
, *ns_pending_service_names
,
238 *ns_pending_service_args
;
239 static BOOL inNsSelect
= 0;
241 /* Convert modifiers in a NeXTSTEP event to emacs style modifiers. */
242 #define NS_FUNCTION_KEY_MASK
0x800000
243 #define EV_MODIFIERS
(e
) \
244 ((([e modifierFlags
] & NSHelpKeyMask
) ? \
245 hyper_modifier
: 0) \
246 |
(([e modifierFlags
] & NSAlternateKeyMask
) ? \
247 parse_solitary_modifier
(ns_alternate_modifier
) : 0) \
248 |
(([e modifierFlags
] & NSShiftKeyMask
) ? \
249 shift_modifier
: 0) \
250 |
(([e modifierFlags
] & NSControlKeyMask
) ? \
251 parse_solitary_modifier
(ns_control_modifier
) : 0) \
252 |
(([e modifierFlags
] & NS_FUNCTION_KEY_MASK
) ? \
253 parse_solitary_modifier
(ns_function_modifier
) : 0) \
254 |
(([e modifierFlags
] & NSCommandKeyMask
) ? \
255 parse_solitary_modifier
(ns_command_modifier
):0))
257 #define EV_UDMODIFIERS
(e
) \
258 ((([e
type] == NSLeftMouseDown
) ? down_modifier
: 0) \
259 |
(([e
type] == NSRightMouseDown
) ? down_modifier
: 0) \
260 |
(([e
type] == NSOtherMouseDown
) ? down_modifier
: 0) \
261 |
(([e
type] == NSLeftMouseDragged
) ? down_modifier
: 0) \
262 |
(([e
type] == NSRightMouseDragged
) ? down_modifier
: 0) \
263 |
(([e
type] == NSOtherMouseDragged
) ? down_modifier
: 0) \
264 |
(([e
type] == NSLeftMouseUp
) ? up_modifier
: 0) \
265 |
(([e
type] == NSRightMouseUp
) ? up_modifier
: 0) \
266 |
(([e
type] == NSOtherMouseUp
) ? up_modifier
: 0))
268 #define EV_BUTTON
(e
) \
269 ((([e
type] == NSLeftMouseDown
) ||
([e
type] == NSLeftMouseUp
)) ?
0 : \
270 (([e
type] == NSRightMouseDown
) ||
([e
type] == NSRightMouseUp
)) ?
2 : \
271 [e buttonNumber
] - 1)
273 /* Convert the time field to a timestamp in milliseconds. */
274 #ifdef NS_IMPL_GNUSTEP
275 /* Apple says timestamp is in seconds, but GNUstep seems to be returning msec */
276 #define EV_TIMESTAMP
(e
) ([e timestamp
])
278 #define EV_TIMESTAMP
(e
) ([e timestamp
] * 1000)
279 #endif
/* not gnustep */
281 /* This is a piece of code which is common to all the event handling
282 methods. Maybe it should even be a function. */
283 #define EV_TRAILER
(e
) \
285 XSETFRAME
(emacs_event
->frame_or_window
, emacsframe
); \
286 if (e
) emacs_event
->timestamp
= EV_TIMESTAMP
(e
); \
287 n_emacs_events_pending
++; \
288 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
); \
289 EVENT_INIT
(*emacs_event
); \
290 ns_send_appdefined
(-1); \
293 void x_set_cursor_type
(struct frame
*, Lisp_Object
, Lisp_Object
);
295 /* TODO: get rid of need for these forward declarations */
296 static void ns_condemn_scroll_bars
(struct frame
*f
);
297 static void ns_judge_scroll_bars
(struct frame
*f
);
298 void x_set_frame_alpha
(struct frame
*f
);
300 /* unused variables needed for compatibility reasons */
301 int x_use_underline_position_properties
, x_underline_at_descent_line
;
302 /* FIXME: figure out what to do with underline_minimum_offset. */
305 /* ==========================================================================
309 ========================================================================== */
313 append2
(Lisp_Object list
, Lisp_Object item
)
314 /* --------------------------------------------------------------------------
315 Utility to append to a list
316 -------------------------------------------------------------------------- */
318 Lisp_Object array
[2];
320 array
[1] = Fcons
(item
, Qnil
);
321 return Fnconc
(2, &array
[0]);
327 /* --------------------------------------------------------------------------
328 Used to allow emacs to find its resources under Emacs.app
329 Called from emacs.c at startup.
330 -------------------------------------------------------------------------- */
332 NSBundle
*bundle
= [NSBundle mainBundle
];
333 NSString
*binDir
= [bundle bundlePath
], *resourceDir
= [bundle resourcePath
];
334 NSString
*resourcePath
, *resourcePaths
;
336 BOOL onWindows
= NO
; /* how do I determine this? */
337 NSString
*pathSeparator
= onWindows ? @"
;"
: @"
:"
;
338 NSFileManager
*fileManager
= [NSFileManager defaultManager
];
340 /*NSLog (@"ns_init_paths: '%@'\n%@\n", [[NSBundle mainBundle] bundlePath], [[NSBundle mainBundle] resourcePath]); */
342 /* get bindir from base */
343 range
= [resourceDir rangeOfString
: @"Contents"
];
344 if (range.location
!= NSNotFound
)
346 binDir
= [binDir stringByAppendingPathComponent
: @"Contents"
];
348 binDir
= [binDir stringByAppendingPathComponent
: @"MacOS"
];
352 /* the following based on Andrew Choi's init_mac_osx_environment () */
353 if (!getenv ("EMACSLOADPATH"
))
355 NSArray
*paths
= [resourceDir stringsByAppendingPaths
:
356 [NSArray arrayWithObjects
:
357 @"site
-lisp"
, @"lisp"
, @"leim"
, nil
]];
358 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
360 while (resourcePath
= [pathEnum nextObject
])
362 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
365 if ([resourcePaths
length] > 0)
367 = [resourcePaths stringByAppendingString
: pathSeparator
];
369 = [resourcePaths stringByAppendingString
: resourcePath
];
372 if ([resourcePaths
length] > 0)
373 setenv
("EMACSLOADPATH"
, [resourcePaths UTF8String
], 1);
374 /*NSLog (@"loadPath: '%s'\n", resourcePaths); */
377 if (!getenv ("EMACSPATH"
))
379 NSArray
*paths
= [binDir stringsByAppendingPaths
:
380 [NSArray arrayWithObjects
: @"bin"
,
382 NSEnumerator
*pathEnum
= [paths objectEnumerator
];
384 while (resourcePath
= [pathEnum nextObject
])
386 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
389 if ([resourcePaths
length] > 0)
391 = [resourcePaths stringByAppendingString
: pathSeparator
];
393 = [resourcePaths stringByAppendingString
: resourcePath
];
396 if ([resourcePaths
length] > 0)
397 setenv
("EMACSPATH"
, [resourcePaths UTF8String
], 1);
400 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"etc"
];
401 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
405 if (!getenv ("EMACSDATA"
))
406 setenv
("EMACSDATA"
, [resourcePath UTF8String
], 1);
407 if (!getenv ("EMACSDOC"
))
408 setenv
("EMACSDOC"
, [resourcePath UTF8String
], 1);
412 if (!getenv ("INFOPATH"
))
414 resourcePath
= [resourceDir stringByAppendingPathComponent
: @"
info"
];
415 if ([fileManager fileExistsAtPath
: resourcePath isDirectory
: &isDir
])
417 setenv
("INFOPATH"
, [[resourcePath stringByAppendingString
: @"
:"
]
419 /* Note, extra colon needed to cause merge w/later user additions. */
425 timeval_subtract
(struct timeval
*result
, struct timeval x
, struct timeval y
)
426 /* --------------------------------------------------------------------------
427 Subtract the `struct timeval' values X and Y, storing the result in RESULT.
428 Return 1 if the difference is negative, otherwise 0.
429 -------------------------------------------------------------------------- */
431 /* Perform the carry for the later subtraction by updating y.
432 This is safer because on some systems
433 the tv_sec member is unsigned. */
434 if (x.tv_usec
< y.tv_usec
)
436 int nsec
= (y.tv_usec
- x.tv_usec
) / 1000000 + 1;
437 y.tv_usec
-= 1000000 * nsec
;
440 if (x.tv_usec
- y.tv_usec
> 1000000)
442 int nsec
= (y.tv_usec
- x.tv_usec
) / 1000000;
443 y.tv_usec
+= 1000000 * nsec
;
447 /* Compute the time remaining to wait. tv_usec is certainly positive. */
448 result
->tv_sec
= x.tv_sec
- y.tv_sec
;
449 result
->tv_usec
= x.tv_usec
- y.tv_usec
;
451 /* Return indication of whether the result should be considered negative. */
452 return x.tv_sec
< y.tv_sec
;
456 ns_timeout
(int usecs
)
457 /* --------------------------------------------------------------------------
458 Blocking timer utility used by ns_ring_bell
459 -------------------------------------------------------------------------- */
461 struct timeval wakeup
;
463 EMACS_GET_TIME
(wakeup
);
465 /* Compute time to wait until, propagating carry from usecs. */
466 wakeup.tv_usec
+= usecs
;
467 wakeup.tv_sec
+= (wakeup.tv_usec
/ 1000000);
468 wakeup.tv_usec
%= 1000000;
470 /* Keep waiting until past the time wakeup. */
473 struct timeval timeout
;
475 EMACS_GET_TIME
(timeout
);
477 /* In effect, timeout = wakeup - timeout.
478 Break if result would be negative. */
479 if (timeval_subtract
(&timeout
, wakeup
, timeout
))
482 /* Try to wait that long--but we might wake up sooner. */
483 select
(0, NULL, NULL, NULL, &timeout
);
489 ns_release_object
(void
*obj
)
490 /* --------------------------------------------------------------------------
491 Release an object (callable from C)
492 -------------------------------------------------------------------------- */
499 ns_retain_object
(void
*obj
)
500 /* --------------------------------------------------------------------------
501 Retain an object (callable from C)
502 -------------------------------------------------------------------------- */
509 ns_alloc_autorelease_pool
()
510 /* --------------------------------------------------------------------------
511 Allocate a pool for temporary objects (callable from C)
512 -------------------------------------------------------------------------- */
514 return [[NSAutoreleasePool alloc
] init
];
519 ns_release_autorelease_pool
(void
*pool
)
520 /* --------------------------------------------------------------------------
521 Free a pool and temporary objects it refers to (callable from C)
522 -------------------------------------------------------------------------- */
524 ns_release_object
(pool
);
529 /* ==========================================================================
531 Focus (clipping) and screen update
533 ========================================================================== */
536 ns_resize_handle_rect
(NSWindow
*window
)
538 NSRect r
= [window frame
];
539 r.origin.x
= r.
size.width
- RESIZE_HANDLE_SIZE
;
541 r.
size.width
= r.
size.height
= RESIZE_HANDLE_SIZE
;
547 ns_update_begin
(struct frame
*f
)
548 /* --------------------------------------------------------------------------
549 Prepare for a grouped sequence of drawing calls
550 external (RIF) call; whole frame, called before update_window_begin
551 -------------------------------------------------------------------------- */
553 NSView
*view = FRAME_NS_VIEW
(f
);
554 NSTRACE
(ns_update_begin
);
556 ns_updating_frame
= f
;
559 #ifdef NS_IMPL_GNUSTEP
560 uRect
= NSMakeRect
(0, 0, 0, 0);
566 ns_update_window_begin
(struct window
*w
)
567 /* --------------------------------------------------------------------------
568 Prepare for a grouped sequence of drawing calls
569 external (RIF) call; for one window, called after update_begin
570 -------------------------------------------------------------------------- */
572 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
573 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
574 NSTRACE
(ns_update_window_begin
);
577 set_output_cursor
(&w
->cursor
);
581 if (f
== dpyinfo
->mouse_face_mouse_frame
)
583 /* Don't do highlighting for mouse motion during the update. */
584 dpyinfo
->mouse_face_defer
= 1;
586 /* If the frame needs to be redrawn,
587 simply forget about any prior mouse highlighting. */
588 if (FRAME_GARBAGED_P
(f
))
589 dpyinfo
->mouse_face_window
= Qnil
;
591 /* (further code for mouse faces ifdef'd out in other terms elided) */
599 ns_update_window_end
(struct window
*w
, int cursor_on_p
,
600 int mouse_face_overwritten_p
)
601 /* --------------------------------------------------------------------------
602 Finished a grouped sequence of drawing calls
603 external (RIF) call; for one window called before update_end
604 -------------------------------------------------------------------------- */
606 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(XFRAME
(w
->frame
));
608 /* note: this fn is nearly identical in all terms */
609 if (!w
->pseudo_window_p
)
614 display_and_set_cursor
(w
, 1,
615 output_cursor.hpos
, output_cursor.vpos
,
616 output_cursor.x
, output_cursor.y
);
618 if (draw_window_fringes
(w
, 1))
619 x_draw_vertical_border
(w
);
624 /* If a row with mouse-face was overwritten, arrange for
625 frame_up_to_date to redisplay the mouse highlight. */
626 if (mouse_face_overwritten_p
)
628 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
629 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
630 dpyinfo
->mouse_face_window
= Qnil
;
633 updated_window
= NULL;
634 NSTRACE
(update_window_end
);
639 ns_update_end
(struct frame
*f
)
640 /* --------------------------------------------------------------------------
641 Finished a grouped sequence of drawing calls
642 external (RIF) call; for whole frame, called after update_window_end
643 -------------------------------------------------------------------------- */
645 NSView
*view = FRAME_NS_VIEW
(f
);
647 /* if (f == FRAME_NS_DISPLAY_INFO (f)->mouse_face_mouse_frame) */
648 FRAME_NS_DISPLAY_INFO
(f
)->mouse_face_defer
= 0;
652 #ifdef NS_IMPL_GNUSTEP
653 /* trigger flush only in the rectangle we tracked as being drawn */
654 [view unlockFocusNeedsFlush
: NO
];
655 /*fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", uRect.origin.x, uRect.origin.y, uRect.size.width, uRect.size.height); */
656 [view lockFocusInRect
: uRect
];
660 [[view window
] flushWindow
];
663 ns_updating_frame
= NULL;
664 NSTRACE
(ns_update_end
);
669 ns_flush
(struct frame
*f
)
670 /* --------------------------------------------------------------------------
672 NS impl is no-op since currently we flush in ns_update_end and elsewhere
673 -------------------------------------------------------------------------- */
680 ns_focus
(struct frame
*f
, NSRect
*r
, int n
)
681 /* --------------------------------------------------------------------------
682 Internal: Focus on given frame. During small local updates this is used to
683 draw, however during large updates, ns_update_begin and ns_update_end are
684 called to wrap the whole thing, in which case these calls are stubbed out.
685 Except, on GNUstep, we accumulate the rectangle being drawn into, because
686 the back end won't do this automatically, and will just end up flushing
688 -------------------------------------------------------------------------- */
690 // NSTRACE
(ns_focus
);
691 #ifdef NS_IMPL_GNUSTEP
694 u
= NSUnionRect
(r
[0], r
[1]);
699 fprintf (stderr, "focus: %d", c++);
700 if (r) fprintf (stderr, " (%.0f, %.0f : %.0f x %.0f)", r->origin.x, r->origin.y, r->size.width, r->size.height);
701 fprintf (stderr, "\n"); */
703 if (f
!= ns_updating_frame
)
705 NSView
*view = FRAME_NS_VIEW
(f
);
706 if (view != focus_view
)
708 if (focus_view
!= NULL)
710 [focus_view unlockFocus
];
711 [[focus_view window
] flushWindow
];
716 #ifdef NS_IMPL_GNUSTEP
717 r ?
[view lockFocusInRect
: u
] : [view lockFocus
];
722 /*if (view) debug_lock++; */
724 #ifdef NS_IMPL_GNUSTEP
727 /* more than one rect being drawn into */
730 [view unlockFocus
]; /* add prev rect to redraw list */
731 [view lockFocusInRect
: u
]; /* focus for draw in new rect */
736 #ifdef NS_IMPL_GNUSTEP
739 /* in batch mode, but in GNUstep must still track rectangles explicitly */
740 uRect
= (r ? NSUnionRect
(uRect
, u
) : [FRAME_NS_VIEW
(f
) visibleRect
]);
747 [[NSGraphicsContext currentContext
] saveGraphicsState
];
749 NSRectClipList
(r
, 2);
758 ns_unfocus
(struct frame
*f
)
759 /* --------------------------------------------------------------------------
760 Internal: Remove focus on given frame
761 -------------------------------------------------------------------------- */
763 // NSTRACE
(ns_unfocus
);
767 [[NSGraphicsContext currentContext
] restoreGraphicsState
];
771 if (f
!= ns_updating_frame
)
773 if (focus_view
!= NULL)
775 [focus_view unlockFocus
];
776 [[focus_view window
] flushWindow
];
785 ns_clip_to_row
(struct window
*w
, struct glyph_row
*row
, int area
, BOOL gc
)
786 /* --------------------------------------------------------------------------
787 Internal (but parallels other terms): Focus drawing on given row
788 -------------------------------------------------------------------------- */
790 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
792 int window_x
, window_y
, window_width
;
794 window_box
(w
, area
, &window_x
, &window_y
, &window_width
, 0);
796 clip_rect.origin.x
= window_x
- FRAME_INTERNAL_BORDER_WIDTH
(f
);
797 clip_rect.origin.y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, row
->y
));
798 clip_rect.origin.y
= max (clip_rect.origin.y
, window_y
);
799 clip_rect.
size.width
= window_width
+ 2 * FRAME_INTERNAL_BORDER_WIDTH
(f
);
800 clip_rect.
size.height
= row
->visible_height
;
802 /* allow a full-height row at the top when requested
803 (used to draw fringe all the way through internal border area) */
804 if (gc
&& clip_rect.origin.y
< 5)
806 clip_rect.origin.y
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
807 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
810 /* likewise at bottom */
812 FRAME_PIXEL_HEIGHT
(f
) - (clip_rect.origin.y
+ clip_rect.
size.height
) < 5)
813 clip_rect.
size.height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
815 ns_focus
(f
, &clip_rect
, 1);
821 /* --------------------------------------------------------------------------
823 -------------------------------------------------------------------------- */
825 NSTRACE
(ns_ring_bell
);
828 NSAutoreleasePool
*pool
;
829 struct frame
*frame
= SELECTED_FRAME
();
833 pool
= [[NSAutoreleasePool alloc
] init
];
835 view = FRAME_NS_VIEW
(frame
);
839 NSPoint dim
= NSMakePoint
(128, 128);
842 r.origin.x
+= (r.
size.width
- dim.x
) / 2;
843 r.origin.y
+= (r.
size.height
- dim.y
) / 2;
844 r.
size.width
= dim.x
;
845 r.
size.height
= dim.y
;
846 surr
= NSInsetRect
(r
, -2, -2);
847 ns_focus
(frame
, &surr
, 1);
848 [[view window
] cacheImageInRect
: [view convertRect
: surr toView
:nil
]];
849 [ns_lookup_indexed_color
(NS_FACE_FOREGROUND
850 (FRAME_DEFAULT_FACE
(frame
)), frame
) set];
852 [[view window
] flushWindow
];
854 [[view window
] restoreCachedImage
];
855 [[view window
] flushWindow
];
869 ns_reset_terminal_modes
(struct terminal *terminal)
870 /* Externally called as hook */
872 NSTRACE
(ns_reset_terminal_modes
);
876 ns_set_terminal_modes
(struct terminal *terminal)
877 /* Externally called as hook */
879 NSTRACE
(ns_set_terminal_modes
);
884 /* ==========================================================================
886 Frame / window manager related functions
888 ========================================================================== */
892 ns_raise_frame
(struct frame
*f
)
893 /* --------------------------------------------------------------------------
894 Bring window to foreground and make it active
895 -------------------------------------------------------------------------- */
897 NSView
*view = FRAME_NS_VIEW
(f
);
900 FRAME_SAMPLE_VISIBILITY
(f
);
901 if (FRAME_VISIBLE_P
(f
))
903 [[view window
] makeKeyAndOrderFront
: NSApp
];
910 ns_lower_frame
(struct frame
*f
)
911 /* --------------------------------------------------------------------------
913 -------------------------------------------------------------------------- */
915 NSView
*view = FRAME_NS_VIEW
(f
);
918 [[view window
] orderBack
: NSApp
];
924 ns_frame_raise_lower
(struct frame
*f
, int raise
)
925 /* --------------------------------------------------------------------------
927 -------------------------------------------------------------------------- */
929 NSTRACE
(ns_frame_raise_lower
);
939 ns_frame_rehighlight
(struct frame
*frame
)
940 /* --------------------------------------------------------------------------
941 External (hook): called on things like window switching within frame
942 -------------------------------------------------------------------------- */
944 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(frame
);
945 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
947 NSTRACE
(ns_frame_rehighlight
);
948 if (dpyinfo
->x_focus_frame
)
950 dpyinfo
->x_highlight_frame
951 = (FRAMEP
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
952 ? XFRAME
(FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
))
953 : dpyinfo
->x_focus_frame
);
954 if (!FRAME_LIVE_P
(dpyinfo
->x_highlight_frame
))
956 FRAME_FOCUS_FRAME
(dpyinfo
->x_focus_frame
) = Qnil
;
957 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
961 dpyinfo
->x_highlight_frame
= 0;
963 if (dpyinfo
->x_highlight_frame
&&
964 dpyinfo
->x_highlight_frame
!= old_highlight
)
968 x_update_cursor
(old_highlight
, 1);
969 x_set_frame_alpha
(old_highlight
);
971 if (dpyinfo
->x_highlight_frame
)
973 x_update_cursor
(dpyinfo
->x_highlight_frame
, 1);
974 x_set_frame_alpha
(dpyinfo
->x_highlight_frame
);
981 x_make_frame_visible
(struct frame
*f
)
982 /* --------------------------------------------------------------------------
983 External: Show the window (X11 semantics)
984 -------------------------------------------------------------------------- */
986 NSTRACE
(x_make_frame_visible
);
987 /* XXX: at some points in past this was not needed, as the only place that
988 called this (frame.c:Fraise_frame ()) also called raise_lower;
989 if this ends up the case again, comment this out again. */
990 if (!FRAME_VISIBLE_P
(f
))
992 f
->async_visible
= 1;
999 x_make_frame_invisible
(struct frame
*f
)
1000 /* --------------------------------------------------------------------------
1001 External: Hide the window (X11 semantics)
1002 -------------------------------------------------------------------------- */
1004 NSView
* view = FRAME_NS_VIEW
(f
);
1005 NSTRACE
(x_make_frame_invisible
);
1007 [[view window
] orderOut
: NSApp
];
1008 f
->async_visible
= 0;
1009 f
->async_iconified
= 0;
1014 x_iconify_frame
(struct frame
*f
)
1015 /* --------------------------------------------------------------------------
1016 External: Iconify window
1017 -------------------------------------------------------------------------- */
1019 NSView
* view = FRAME_NS_VIEW
(f
);
1020 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1021 NSTRACE
(x_iconify_frame
);
1024 if (dpyinfo
->x_highlight_frame
== f
)
1025 dpyinfo
->x_highlight_frame
= 0;
1027 if ([[view window
] windowNumber
] <= 0)
1029 /* the window is still deferred. Make it very small, bring it
1030 on screen and order it out. */
1031 NSRect s
= { { 100, 100}, {0, 0} };
1033 t
= [[view window
] frame
];
1034 [[view window
] setFrame
: s display
: NO
];
1035 [[view window
] orderBack
: NSApp
];
1036 [[view window
] orderOut
: NSApp
];
1037 [[view window
] setFrame
: t display
: NO
];
1039 [[view window
] miniaturize
: NSApp
];
1044 x_destroy_window
(struct frame
*f
)
1045 /* --------------------------------------------------------------------------
1046 External: Delete the window
1047 -------------------------------------------------------------------------- */
1049 NSView
*view = FRAME_NS_VIEW
(f
);
1050 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1051 NSTRACE
(x_destroy_window
);
1054 [(EmacsView
*)view setWindowClosing
: YES
]; /* may not have been informed */
1058 free_frame_menubar
(f
);
1060 if (FRAME_FACE_CACHE
(f
))
1061 free_frame_faces
(f
);
1063 if (f
== dpyinfo
->x_focus_frame
)
1064 dpyinfo
->x_focus_frame
= 0;
1065 if (f
== dpyinfo
->x_highlight_frame
)
1066 dpyinfo
->x_highlight_frame
= 0;
1067 if (f
== dpyinfo
->mouse_face_mouse_frame
)
1069 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
1070 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
1071 dpyinfo
->mouse_face_window
= Qnil
;
1072 dpyinfo
->mouse_face_deferred_gc
= 0;
1073 dpyinfo
->mouse_face_mouse_frame
= 0;
1076 xfree
(f
->output_data.ns
);
1078 [[view window
] close];
1087 x_set_offset
(struct frame
*f
, int xoff
, int yoff
, int change_grav
)
1088 /* --------------------------------------------------------------------------
1089 External: Position the window
1090 -------------------------------------------------------------------------- */
1093 NSView
*view = FRAME_NS_VIEW
(f
);
1095 NSTRACE
(x_set_offset
);
1101 #ifdef NS_IMPL_GNUSTEP
1103 f
->left_pos
= 100; /* don't overlap menu */
1105 if (view != nil
&& (screen
= [[view window
] screen
]))
1106 [[view window
] setFrameTopLeftPoint
:
1107 NSMakePoint
(SCREENMAXBOUND
(f
->left_pos
),
1108 SCREENMAXBOUND
([screen frame
].
size.height
1109 - NS_TOP_POS
(f
)))];
1115 x_set_window_size
(struct frame
*f
, int change_grav
, int cols
, int rows
)
1116 /* --------------------------------------------------------------------------
1117 Adjust window pixel size based on given character grid size
1118 Impl is a bit more complex than other terms, need to do some
1119 internal clipping and also pay attention to screen constraints.
1120 -------------------------------------------------------------------------- */
1122 EmacsView
*view = FRAME_NS_VIEW
(f
);
1123 EmacsToolbar
*toolbar
= [view toolbar
];
1124 NSWindow
*window
= [view window
];
1125 NSScreen
*screen
= [window screen
];
1126 NSRect wr
= [window frame
];
1127 int tb
= FRAME_EXTERNAL_TOOL_BAR
(f
);
1128 int pixelwidth
, pixelheight
;
1129 static int oldRows
, oldCols
, oldFontWidth
, oldFontHeight
;
1131 static
struct frame
*oldF
;
1133 NSTRACE
(x_set_window_size
);
1137 && rows
== oldRows
&& cols
== oldCols
1138 && oldFontWidth
== FRAME_COLUMN_WIDTH
(f
)
1139 && oldFontHeight
== FRAME_LINE_HEIGHT
(f
)
1143 /*fprintf (stderr, "\tsetWindowSize: %d x %d, font size %d x %d\n", cols, rows, FRAME_COLUMN_WIDTH (f), FRAME_LINE_HEIGHT (f)); */
1147 check_frame_size
(f
, &rows
, &cols
);
1151 oldFontWidth
= FRAME_COLUMN_WIDTH
(f
);
1152 oldFontHeight
= FRAME_LINE_HEIGHT
(f
);
1155 f
->scroll_bar_actual_width
= NS_SCROLL_BAR_WIDTH
(f
);
1156 compute_fringe_widths
(f
, 0);
1158 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(f
, cols
);
1159 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(f
, rows
);
1161 /* If we have a toolbar, take its height into account. */
1163 FRAME_NS_TOOLBAR_HEIGHT
(f
) =
1164 /* XXX: GNUstep has not yet implemented the first method below, added
1165 in Panther, however the second is incorrect under Cocoa. */
1166 #ifdef NS_IMPL_COCOA
1167 NSHeight
([window frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)])
1168 /* NOTE: previously this would generate wrong result if toolbar not
1169 yet displayed and fixing toolbar_height=32 helped, but
1170 now (200903) seems no longer needed */
1172 NSHeight
([NSWindow frameRectForContentRect
: NSMakeRect
(0, 0, 0, 0)
1173 styleMask
: [window styleMask
]])
1175 - FRAME_NS_TITLEBAR_HEIGHT
(f
);
1177 FRAME_NS_TOOLBAR_HEIGHT
(f
) = 0;
1179 wr.
size.width
= pixelwidth
+ f
->border_width
;
1180 wr.
size.height
= pixelheight
+ FRAME_NS_TITLEBAR_HEIGHT
(f
)
1181 + FRAME_NS_TOOLBAR_HEIGHT
(f
);
1183 /* constrain to screen if we can */
1186 NSSize sz
= [screen visibleFrame
].
size;
1187 NSSize ez
= { wr.
size.width
- sz.width
, wr.
size.height
- sz.height
};
1190 int cr
= ez.width
/ FRAME_COLUMN_WIDTH
(f
) + 1;
1193 wr.
size.width
-= cr
* FRAME_COLUMN_WIDTH
(f
);
1194 pixelwidth
-= cr
* FRAME_COLUMN_WIDTH
(f
);
1198 int rr
= ez.height
/ FRAME_LINE_HEIGHT
(f
) + 1;
1201 wr.
size.height
-= rr
* FRAME_LINE_HEIGHT
(f
);
1202 pixelheight
-= rr
* FRAME_LINE_HEIGHT
(f
);
1204 wr.origin.x
= f
->left_pos
;
1205 wr.origin.y
= [screen frame
].
size.height
- NS_TOP_POS
(f
)
1209 [view setRows
: rows andColumns
: cols
];
1210 [window setFrame
: wr display
: YES
];
1212 /*fprintf (stderr, "\tx_set_window_size %d, %d\t%d, %d\n", cols, rows, pixelwidth, pixelheight); */
1214 /* This is a trick to compensate for Emacs' managing the scrollbar area
1215 as a fixed number of standard character columns. Instead of leaving
1216 blank space for the extra, we chopped it off above. Now for
1217 left-hand scrollbars, we shift all rendering to the left by the
1218 difference between the real width and Emacs' imagined one. For
1219 right-hand bars, don't worry about it since the extra is never used.
1220 (Obviously doesn't work for vertically split windows tho..) */
1221 NSPoint origin
= FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT
(f
)
1222 ? NSMakePoint
(FRAME_SCROLL_BAR_COLS
(f
) * FRAME_COLUMN_WIDTH
(f
)
1223 - NS_SCROLL_BAR_WIDTH
(f
), 0)
1224 : NSMakePoint
(0, 0);
1225 [view setFrame
: NSMakeRect
(0, 0, pixelwidth
, pixelheight
)];
1226 [view setBoundsOrigin
: origin
];
1228 change_frame_size
(f
, rows
, cols
, 0, 1, 0); /* pretend, delay, safe */
1229 FRAME_PIXEL_WIDTH
(f
) = pixelwidth
;
1230 FRAME_PIXEL_HEIGHT
(f
) = pixelheight
;
1231 /* SET_FRAME_GARBAGED (f); // this short-circuits expose call in drawRect */
1233 mark_window_cursors_off
(XWINDOW
(f
->root_window
));
1234 cancel_mouse_face
(f
);
1241 /* ==========================================================================
1245 ========================================================================== */
1249 ns_lookup_indexed_color
(unsigned
long idx
, struct frame
*f
)
1251 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1252 return color_table
->colors
[idx
];
1257 ns_index_color
(NSColor
*color
, struct frame
*f
)
1259 struct ns_color_table
*color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1263 if (!color_table
->colors
)
1265 color_table
->size = NS_COLOR_CAPACITY
;
1266 color_table
->avail
= 1; /* skip idx=0 as marker */
1268 = (NSColor
**)xmalloc
(color_table
->size * sizeof
(NSColor
*));
1269 color_table
->empty_indices
= [[NSMutableSet alloc
] init
];
1272 /* do we already have this color ? */
1275 for (i
= 1; i
< color_table
->avail
; i
++)
1277 if (color_table
->colors
[i
] && [color_table
->colors
[i
] isEqual: color
])
1279 [color_table
->colors
[i
] retain
];
1285 if ([color_table
->empty_indices count
] > 0)
1287 index
= [color_table
->empty_indices anyObject
];
1288 [color_table
->empty_indices removeObject
: index
];
1289 idx
= [index unsignedIntValue
];
1293 if (color_table
->avail
== color_table
->size)
1295 color_table
->size += NS_COLOR_CAPACITY
;
1297 = (NSColor
**)xrealloc
(color_table
->colors
,
1298 color_table
->size * sizeof
(NSColor
*));
1300 idx
= color_table
->avail
++;
1303 color_table
->colors
[idx
] = color
;
1305 /*fprintf(stderr, "color_table: allocated %d\n",idx);*/
1311 ns_free_indexed_color
(unsigned
long idx
, struct frame
*f
)
1313 struct ns_color_table
*color_table
;
1320 color_table
= FRAME_NS_DISPLAY_INFO
(f
)->color_table
;
1322 if (idx
<= 0 || idx
>= color_table
->size) {
1323 message1
("ns_free_indexed_color
: Color index out of range.
\n"
);
1327 index
= [NSNumber numberWithUnsignedInt
: idx
];
1328 if ([color_table
->empty_indices containsObject
: index
]) {
1329 message1
("ns_free_indexed_color
: attempt to free already freed color.
\n"
);
1333 color
= color_table
->colors
[idx
];
1335 color_table
->colors
[idx
] = nil
;
1336 [color_table
->empty_indices addObject
: [NSNumber numberWithUnsignedInt
: idx
]];
1337 /*fprintf(stderr, "color_table: FREED %d\n",idx);*/
1342 ns_get_color
(const
char *name
, NSColor
**col
)
1343 /* --------------------------------------------------------------------------
1345 /* --------------------------------------------------------------------------
1346 /* On *Step, we recognize several color formats, in addition to a catalog
1347 of colors found in the file Emacs.clr. Color formats include:
1348 - #rrggbb or RGBrrggbb where rr, gg, bb specify red, green and blue in hex
1349 - ARGBaarrggbb is similar, with aa being the alpha channel (FF = opaque)
1350 - HSVhhssvv and AHSVaahhssvv (or HSB/AHSB) are similar for hue, saturation,
1352 - CMYKccmmyykk is similar for cyan, magenta, yellow, black. */
1354 NSColor
* new
= nil
;
1355 const
char *hex
= NULL;
1356 enum
{ rgb
, argb
, hsv, ahsv
, cmyk
, gray } color_space
;
1357 NSString
*nsname
= [NSString stringWithUTF8String
: name
];
1359 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1362 if ([nsname isEqualToString
: @"ns_selection_color"
])
1364 nsname
= ns_selection_color
;
1365 name
= [ns_selection_color UTF8String
];
1368 if (name
[0] == '0' || name
[0] == '1' || name
[0] == '.')
1371 NSScanner
*scanner
= [NSScanner scannerWithString
: nsname
];
1373 [scanner scanFloat
: &r
];
1374 [scanner scanFloat
: &g
];
1375 [scanner scanFloat
: &b
];
1376 *col
= [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: 1.0];
1381 /* FIXME: emacs seems to downcase everything before passing it here,
1382 which we can work around, except for GRAY, since gray##, where ## is
1383 decimal between 0 and 99, is also an X11 colorname. */
1384 if (name
[0] == '#') /* X11 format */
1389 else if (!memcmp
(name
, "RGB"
, 3) ||
!memcmp
(name
, "rgb"
, 3))
1394 else if (!memcmp
(name
, "ARGB"
, 4) ||
!memcmp
(name
, "argb"
, 4))
1399 else if (!memcmp
(name
, "
HSV"
, 3) ||
!memcmp
(name
, "
hsv"
, 3) ||
1400 !memcmp
(name
, "HSB"
, 3) ||
!memcmp
(name
, "hsb"
, 3))
1405 else if (!memcmp
(name
, "AHSV"
, 4) ||
!memcmp
(name
, "ahsv"
, 4) ||
1406 !memcmp
(name
, "AHSB"
, 4) ||
!memcmp
(name
, "ahsb"
, 4))
1411 else if (!memcmp
(name
, "CMYK"
, 4) ||
!memcmp
(name
, "cmyk"
, 4))
1416 else if (!memcmp
(name
, "
GRAY"
, 4) /*|| !memcmp (name, "gray", 4)*/)
1422 /* Direct colors (hex values) */
1425 unsigned
long long color
= 0;
1426 if (sscanf (hex
, "
%x", &color))
1428 float f1
, f2
, f3
, f4
;
1429 /* Assume it's either 1 byte or 2 per channel... */
1430 if (strlen
(hex
) > 8) {
1431 f1
= ((color
>> 48) & 0xffff) / 65535.0;
1432 f2
= ((color
>> 32) & 0xffff) / 65535.0;
1433 f3
= ((color
>> 16) & 0xffff) / 65535.0;
1434 f4
= ((color
) & 0xffff) / 65535.0;
1436 f1
= ((color
>> 24) & 0xff) / 255.0;
1437 f2
= ((color
>> 16) & 0xff) / 255.0;
1438 f3
= ((color
>> 8) & 0xff) / 255.0;
1439 f4
= ((color
) & 0xff) / 255.0;
1442 switch (color_space
)
1445 *col
= [NSColor colorWithCalibratedRed
: f2
1451 *col
= [NSColor colorWithCalibratedRed
: f2
1457 *col
= [NSColor colorWithCalibratedHue
: f2
1463 *col
= [NSColor colorWithCalibratedHue
: f2
1469 *col
= [NSColor colorWithCalibratedWhite
: f3 alpha
: f4
];
1472 *col
= [NSColor colorWithDeviceCyan
: f1
1479 *col
= [*col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1485 /* Otherwise, color is expected to be from a list */
1487 NSEnumerator
*lenum
, *cenum
;
1491 #ifdef NS_IMPL_GNUSTEP
1492 /* XXX: who is wrong, the requestor or the implementation? */
1493 if ([nsname compare
: @"Highlight" options
: NSCaseInsensitiveSearch
]
1495 nsname
= @"highlightColor"
;
1498 lenum
= [[NSColorList availableColorLists
] objectEnumerator
];
1499 while ( (clist
= [lenum nextObject
]) && new
== nil
)
1501 cenum
= [[clist allKeys
] objectEnumerator
];
1502 while ( (name
= [cenum nextObject
]) && new
== nil
)
1504 if ([name compare
: nsname
1505 options
: NSCaseInsensitiveSearch
] == NSOrderedSame
)
1506 new
= [clist colorWithKey
: name
];
1512 *col
= [new colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
];
1514 NSLog (@"Failed to find color '%@'", nsname); */
1521 ns_get_color_default
(const
char *name
, NSColor
*dflt
)
1522 /* --------------------------------------------------------------------------
1523 Parse a color or use a default value
1524 -------------------------------------------------------------------------- */
1528 if (ns_get_color
(name
, &col
))
1536 ns_lisp_to_color
(Lisp_Object color
, NSColor
**col
)
1537 /* --------------------------------------------------------------------------
1538 Convert a Lisp string object to a NS color
1539 -------------------------------------------------------------------------- */
1541 NSTRACE
(ns_lisp_to_color
);
1542 if (STRINGP
(color
))
1543 return ns_get_color
(SDATA
(color
), col
);
1544 else if (SYMBOLP
(color
))
1545 return ns_get_color
(SDATA
(SYMBOL_NAME
(color
)), col
);
1551 ns_color_to_lisp
(NSColor
*col
)
1552 /* --------------------------------------------------------------------------
1553 Convert a color to a lisp string with the RGB equivalent
1554 -------------------------------------------------------------------------- */
1556 float red
, green
, blue
, alpha
, gray;
1559 NSTRACE
(ns_color_to_lisp
);
1562 if ([[col colorSpaceName
] isEqualToString
: NSNamedColorSpace
])
1564 if ((str
=[[col colorNameComponent
] UTF8String
]))
1567 return build_string
((char *)str
);
1570 [[col colorUsingColorSpaceName
: NSCalibratedRGBColorSpace
]
1571 getRed
: &red green
: &green blue
: &blue alpha
: &alpha
];
1572 if (red
==green
&& red
==blue
)
1574 [[col colorUsingColorSpaceName
: NSCalibratedWhiteColorSpace
]
1575 getWhite
: &gray alpha
: &alpha
];
1576 snprintf
(buf
, sizeof
(buf
), "
GRAY%02.2lx%02.2lx",
1577 lrint
(gray * 0xff), lrint
(alpha
* 0xff));
1579 return build_string
(buf
);
1582 snprintf
(buf
, sizeof
(buf
), "ARGB
%02.2lx%02.2lx%02.2lx%02.2lx",
1584 lrint
(red
*0xff), lrint
(green
*0xff), lrint
(blue
*0xff));
1587 return build_string
(buf
);
1592 ns_query_color
(void
*col
, XColor
*color_def
, int setPixel
)
1593 /* --------------------------------------------------------------------------
1594 Get ARGB values out of NSColor col and put them into color_def.
1595 If setPixel, set the pixel to a concatenated version.
1596 and set color_def pixel to the resulting index.
1597 -------------------------------------------------------------------------- */
1601 [((NSColor
*)col
) getRed
: &r green
: &g blue
: &b alpha
: &a
];
1602 color_def
->red
= r
* 65535;
1603 color_def
->green
= g
* 65535;
1604 color_def
->blue
= b
* 65535;
1606 if (setPixel
== YES
)
1608 = ARGB_TO_ULONG
((int
)(a
*255),
1609 (int
)(r
*255), (int
)(g
*255), (int
)(b
*255));
1614 ns_defined_color
(struct frame
*f
, char *name
, XColor
*color_def
, int alloc
,
1616 /* --------------------------------------------------------------------------
1617 Return 1 if named color found, and set color_def rgb accordingly.
1618 If makeIndex and alloc are nonzero put the color in the color_table,
1619 and set color_def pixel to the resulting index.
1620 If makeIndex is zero, set color_def pixel to ARGB.
1621 Return 0 if not found
1622 -------------------------------------------------------------------------- */
1625 int notFound
= ns_get_color
(name
, &temp
);
1627 NSTRACE
(ns_defined_color
);
1632 if (makeIndex
&& alloc
)
1633 color_def
->pixel
= ns_index_color
(temp
, f
); /* [temp retain]; */
1635 ns_query_color
(temp
, color_def
, !makeIndex
);
1642 ns_get_rgb_color
(struct frame
*f
, float r
, float g
, float b
, float a
)
1643 /* --------------------------------------------------------------------------
1644 return an autoreleased RGB color
1645 -------------------------------------------------------------------------- */
1647 /*static int c = 1; fprintf (stderr, "color request %d\n", c++); */
1648 if (r
< 0.0) r
= 0.0;
1649 else if (r
> 1.0) r
= 1.0;
1650 if (g
< 0.0) g
= 0.0;
1651 else if (g
> 1.0) g
= 1.0;
1652 if (b
< 0.0) b
= 0.0;
1653 else if (b
> 1.0) b
= 1.0;
1654 if (a
< 0.0) a
= 0.0;
1655 else if (a
> 1.0) a
= 1.0;
1656 return (unsigned
long) ns_index_color
(
1657 [NSColor colorWithCalibratedRed
: r green
: g blue
: b alpha
: a
], f
);
1662 x_set_frame_alpha
(struct frame
*f
)
1663 /* --------------------------------------------------------------------------
1664 change the entire-frame transparency
1665 -------------------------------------------------------------------------- */
1667 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1668 EmacsView
*view = FRAME_NS_VIEW
(f
);
1670 double alpha_min
= 1.0;
1672 if (dpyinfo
->x_highlight_frame
== f
)
1673 alpha
= f
->alpha
[0];
1675 alpha
= f
->alpha
[1];
1677 if (FLOATP
(Vframe_alpha_lower_limit
))
1678 alpha_min
= XFLOAT_DATA
(Vframe_alpha_lower_limit
);
1679 else if (INTEGERP
(Vframe_alpha_lower_limit
))
1680 alpha_min
= (XINT
(Vframe_alpha_lower_limit
)) / 100.0;
1684 else if (1.0 < alpha
)
1686 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
1689 #ifdef NS_IMPL_COCOA
1690 [[view window
] setAlphaValue
: alpha
];
1695 /* ==========================================================================
1699 ========================================================================== */
1703 x_set_mouse_pixel_position
(struct frame
*f
, int pix_x
, int pix_y
)
1704 /* --------------------------------------------------------------------------
1705 Programmatically reposition mouse pointer in pixel coordinates
1706 -------------------------------------------------------------------------- */
1708 NSTRACE
(x_set_mouse_pixel_position
);
1711 /* FIXME: this does not work, and what about GNUstep? */
1712 #ifdef NS_IMPL_COCOA
1713 [FRAME_NS_VIEW
(f
) lockFocus
];
1714 PSsetmouse
((float
)pix_x
, (float
)pix_y
);
1715 [FRAME_NS_VIEW
(f
) unlockFocus
];
1722 x_set_mouse_position
(struct frame
*f
, int h
, int v
)
1723 /* --------------------------------------------------------------------------
1724 Programmatically reposition mouse pointer in character coordinates
1725 -------------------------------------------------------------------------- */
1729 pix_x
= FRAME_COL_TO_PIXEL_X
(f
, h
) + FRAME_COLUMN_WIDTH
(f
) / 2;
1730 pix_y
= FRAME_LINE_TO_PIXEL_Y
(f
, v
) + FRAME_LINE_HEIGHT
(f
) / 2;
1732 if (pix_x
< 0) pix_x
= 0;
1733 if (pix_x
> FRAME_PIXEL_WIDTH
(f
)) pix_x
= FRAME_PIXEL_WIDTH
(f
);
1735 if (pix_y
< 0) pix_y
= 0;
1736 if (pix_y
> FRAME_PIXEL_HEIGHT
(f
)) pix_y
= FRAME_PIXEL_HEIGHT
(f
);
1738 x_set_mouse_pixel_position
(f
, pix_x
, pix_y
);
1743 note_mouse_movement
(struct frame
*frame
, float x
, float y
)
1744 /* ------------------------------------------------------------------------
1745 Called by EmacsView on mouseMovement events. Passes on
1746 to emacs mainstream code if we moved off of a rect of interest
1747 known as last_mouse_glyph.
1748 ------------------------------------------------------------------------ */
1750 // NSTRACE
(note_mouse_movement
);
1752 XSETFRAME
(last_mouse_motion_frame
, frame
);
1754 /* Note, this doesn't get called for enter/leave, since we don't have a
1755 position. Those are taken care of in the corresponding NSView methods. */
1757 /* has movement gone beyond last rect we were tracking? */
1758 if (x
< last_mouse_glyph.origin.x ||
1759 x
>= (last_mouse_glyph.origin.x
+ last_mouse_glyph.
size.width
) ||
1760 y
< last_mouse_glyph.origin.y ||
1761 y
>= (last_mouse_glyph.origin.y
+ last_mouse_glyph.
size.height
))
1763 ns_update_begin
(frame
);
1764 frame
->mouse_moved
= 1;
1765 note_mouse_highlight
(frame
, x
, y
);
1766 remember_mouse_glyph
(frame
, x
, y
, &last_mouse_glyph
);
1767 ns_update_end
(frame
);
1776 ns_mouse_position
(struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
1777 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
1778 unsigned
long *time
)
1779 /* --------------------------------------------------------------------------
1780 External (hook): inform emacs about mouse position and hit parts.
1781 If a scrollbar is being dragged, set bar_window, part, x, y, time.
1782 x & y should be position in the scrollbar (the whole bar, not the handle)
1783 and length of scrollbar respectively
1784 -------------------------------------------------------------------------- */
1789 Lisp_Object frame
, tail
;
1791 struct ns_display_info
*dpyinfo
;
1793 NSTRACE
(ns_mouse_position
);
1797 fprintf (stderr
, "Warning
: ns_mouse_position
() called with
null *fp.
\n"
);
1801 dpyinfo
= FRAME_NS_DISPLAY_INFO
(*fp
);
1805 if (last_mouse_scroll_bar
!= nil
&& insist
== 0)
1807 /* TODO: we do not use this path at the moment because drag events will
1808 go directly to the EmacsScroller. Leaving code in for now. */
1809 [last_mouse_scroll_bar getMouseMotionPart
: (int
*)part window
: bar_window
1811 if (time
) *time
= last_mouse_movement_time
;
1812 last_mouse_scroll_bar
= nil
;
1816 /* Clear the mouse-moved flag for every frame on this display. */
1817 FOR_EACH_FRAME
(tail
, frame
)
1818 if (FRAME_NS_P
(XFRAME
(frame
))
1819 && FRAME_NS_DISPLAY
(XFRAME
(frame
)) == FRAME_NS_DISPLAY
(*fp
))
1820 XFRAME
(frame
)->mouse_moved
= 0;
1822 last_mouse_scroll_bar
= nil
;
1823 if (last_mouse_frame
&& FRAME_LIVE_P
(last_mouse_frame
))
1824 f
= last_mouse_frame
;
1826 f
= dpyinfo
->x_focus_frame ? dpyinfo
->x_focus_frame
1827 : SELECTED_FRAME
();
1829 if (f
&& f
->output_data.ns
) /* TODO: 2nd check no longer needed? */
1831 view = FRAME_NS_VIEW
(*fp
);
1833 position
= [[view window
] mouseLocationOutsideOfEventStream
];
1834 position
= [view convertPoint
: position fromView
: nil
];
1835 remember_mouse_glyph
(f
, position.x
, position.y
, &last_mouse_glyph
);
1836 /*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1838 if (bar_window
) *bar_window
= Qnil
;
1839 if (part
) *part
= 0; /*scroll_bar_handle; */
1841 if (x
) XSETINT
(*x
, lrint
(position.x
));
1842 if (y
) XSETINT
(*y
, lrint
(position.y
));
1843 if (time
) *time
= last_mouse_movement_time
;
1853 ns_frame_up_to_date
(struct frame
*f
)
1854 /* --------------------------------------------------------------------------
1855 External (hook): Fix up mouse highlighting right after a full update.
1856 Some highlighting was deferred if GC was happening during
1857 note_mouse_highlight (), while other highlighting was deferred for update.
1858 -------------------------------------------------------------------------- */
1860 NSTRACE
(ns_frame_up_to_date
);
1864 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(f
);
1865 if ((dpyinfo
->mouse_face_deferred_gc||f
==dpyinfo
->mouse_face_mouse_frame
)
1866 /*&& dpyinfo->mouse_face_mouse_frame*/)
1870 if (dpyinfo
->mouse_face_mouse_frame
)
1871 note_mouse_highlight
(dpyinfo
->mouse_face_mouse_frame
,
1872 dpyinfo
->mouse_face_mouse_x
,
1873 dpyinfo
->mouse_face_mouse_y
);
1874 dpyinfo
->mouse_face_deferred_gc
= 0;
1883 ns_define_frame_cursor
(struct frame
*f
, Cursor cursor
)
1884 /* --------------------------------------------------------------------------
1885 External (RIF): set frame mouse pointer type.
1886 -------------------------------------------------------------------------- */
1888 NSTRACE
(ns_define_frame_cursor
);
1889 if (FRAME_POINTER_TYPE
(f
) != cursor
)
1891 EmacsView
*view = FRAME_NS_VIEW
(f
);
1892 FRAME_POINTER_TYPE
(f
) = cursor
;
1893 [[view window
] invalidateCursorRectsForView
: view];
1899 /* ==========================================================================
1903 ========================================================================== */
1907 ns_convert_key
(unsigned code
)
1908 /* --------------------------------------------------------------------------
1909 Internal call used by NSView-keyDown.
1910 -------------------------------------------------------------------------- */
1912 const unsigned last_keysym
= (sizeof
(convert_ns_to_X_keysym
)
1913 / sizeof
(convert_ns_to_X_keysym
[0]));
1915 /* An array would be faster, but less easy to read. */
1916 for (keysym
= 0; keysym
< last_keysym
; keysym
+= 2)
1917 if (code
== convert_ns_to_X_keysym
[keysym
])
1918 return 0xFF00 | convert_ns_to_X_keysym
[keysym
+1];
1920 /* if decide to use keyCode and Carbon table, use this line:
1921 return code > 0xff ? 0 : 0xFF00 | ns_keycode_to_xkeysym_table[code]; */
1926 x_get_keysym_name
(int keysym
)
1927 /* --------------------------------------------------------------------------
1928 Called by keyboard.c. Not sure if the return val is important, except
1930 -------------------------------------------------------------------------- */
1932 static
char value
[16];
1933 NSTRACE
(x_get_keysym_name
);
1934 sprintf (value
, "
%d", keysym);
1940 /* ==========================================================================
1942 Block drawing operations
1944 ========================================================================== */
1948 ns_redraw_scroll_bars
(struct frame
*f
)
1952 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
1953 NSTRACE
(ns_judge_scroll_bars
);
1954 for (i
=[subviews count
]-1; i
>= 0; i
--)
1956 view = [subviews objectAtIndex
: i
];
1957 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
1964 ns_clear_frame
(struct frame
*f
)
1965 /* --------------------------------------------------------------------------
1966 External (hook): Erase the entire frame
1967 -------------------------------------------------------------------------- */
1969 NSView
*view = FRAME_NS_VIEW
(f
);
1972 NSTRACE
(ns_clear_frame
);
1976 /* comes on initial frame because we have
1977 after-make-frame-functions = select-frame */
1978 if (!FRAME_DEFAULT_FACE
(f
))
1981 mark_window_cursors_off
(XWINDOW
(FRAME_ROOT_WINDOW
(f
)));
1983 output_cursor.hpos
= output_cursor.vpos
= 0;
1984 output_cursor.x
= -1;
1989 ns_focus
(f
, &r
, 1);
1990 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(FRAME_DEFAULT_FACE
(f
)), f
) set];
1994 #ifdef NS_IMPL_COCOA
1995 [[view window
] display
]; /* redraw resize handle */
1998 /* as of 2006/11 or so this is now needed */
1999 ns_redraw_scroll_bars
(f
);
2005 ns_clear_frame_area
(struct frame
*f
, int x
, int y
, int width
, int height
)
2006 /* --------------------------------------------------------------------------
2007 External (RIF): Clear section of frame
2008 -------------------------------------------------------------------------- */
2010 NSRect r
= NSMakeRect
(x
, y
, width
, height
);
2011 NSView
*view = FRAME_NS_VIEW
(f
);
2012 struct face
*face
= FRAME_DEFAULT_FACE
(f
);
2017 NSTRACE
(ns_clear_frame_area
);
2019 r
= NSIntersectionRect
(r
, [view frame
]);
2020 ns_focus
(f
, &r
, 1);
2021 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), f
) set];
2023 #ifdef NS_IMPL_COCOA
2025 /* clip out the resize handle */
2026 NSWindow
*window
= [FRAME_NS_VIEW
(f
) window
];
2028 = [view convertRect
: ns_resize_handle_rect
(window
) fromView
: nil
];
2030 ir
= NSIntersectionRect
(r
, ir
);
2031 if (NSIsEmptyRect
(ir
))
2037 #ifdef NS_IMPL_COCOA
2041 NSRect r1
= r
, r2
= r
; /* upper and lower non-intersecting */
2042 r1.
size.height
-= ir.
size.height
;
2043 r2.origin.y
+= r1.
size.height
;
2044 r2.
size.width
-= ir.
size.width
;
2045 r2.
size.height
= ir.
size.height
;
2058 ns_scroll_run
(struct window
*w
, struct run
*run
)
2059 /* --------------------------------------------------------------------------
2060 External (RIF): Insert or delete n lines at line vpos
2061 -------------------------------------------------------------------------- */
2063 struct frame
*f
= XFRAME
(w
->frame
);
2064 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
2066 NSTRACE
(ns_scroll_run
);
2068 /* begin copy from other terms */
2069 /* Get frame-relative bounding box of the text display area of W,
2070 without mode lines. Include in this box the left and right
2072 window_box
(w
, -1, &x
, &y
, &width
, &height
);
2074 from_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->current_y
);
2075 to_y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, run
->desired_y
);
2076 bottom_y
= y
+ height
;
2080 /* Scrolling up. Make sure we don't copy part of the mode
2081 line at the bottom. */
2082 if (from_y
+ run
->height
> bottom_y
)
2083 height
= bottom_y
- from_y
;
2085 height
= run
->height
;
2089 /* Scolling down. Make sure we don't copy over the mode line.
2091 if (to_y
+ run
->height
> bottom_y
)
2092 height
= bottom_y
- to_y
;
2094 height
= run
->height
;
2096 /* end copy from other terms */
2107 NSRect srcRect
= NSMakeRect
(x
, from_y
, width
, height
);
2108 NSRect dstRect
= NSMakeRect
(x
, to_y
, width
, height
);
2109 NSPoint dstOrigin
= NSMakePoint
(x
, to_y
);
2111 ns_focus
(f
, &dstRect
, 1);
2112 NSCopyBits
(0, srcRect
, dstOrigin
);
2121 ns_after_update_window_line
(struct glyph_row
*desired_row
)
2122 /* --------------------------------------------------------------------------
2123 External (RIF): preparatory to fringe update after text was updated
2124 -------------------------------------------------------------------------- */
2126 struct window
*w
= updated_window
;
2130 NSTRACE
(ns_after_update_window_line
);
2132 /* begin copy from other terms */
2135 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
2136 desired_row
->redraw_fringe_bitmaps_p
= 1;
2138 /* When a window has disappeared, make sure that no rest of
2139 full-width rows stays visible in the internal border.
2140 Under NS this is drawn inside the fringes. */
2141 if (windows_or_buffers_changed
2142 && (f
= XFRAME
(w
->frame
),
2143 width
= FRAME_INTERNAL_BORDER_WIDTH
(f
),
2145 && (height
= desired_row
->visible_height
,
2148 int y
= WINDOW_TO_FRAME_PIXEL_Y
(w
, max (0, desired_row
->y
));
2150 /* Internal border is drawn below the tool bar. */
2151 if (WINDOWP
(f
->tool_bar_window
)
2152 && w
== XWINDOW
(f
->tool_bar_window
))
2154 /* end copy from other terms */
2157 if (!desired_row
->full_width_p
)
2159 int x1
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2160 + WINDOW_LEFT_FRINGE_WIDTH
(w
);
2161 int x2
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH
(w
)
2162 + FRAME_PIXEL_WIDTH
(f
) - NS_SCROLL_BAR_WIDTH
(f
)
2163 - WINDOW_RIGHT_FRINGE_WIDTH
(w
)
2164 - FRAME_INTERNAL_BORDER_WIDTH
(f
);
2165 ns_clear_frame_area
(f
, x1
, y
, width
, height
);
2166 ns_clear_frame_area
(f
, x2
, y
, width
, height
);
2174 ns_shift_glyphs_for_insert
(struct frame
*f
,
2175 int x
, int y
, int width
, int height
,
2177 /* --------------------------------------------------------------------------
2178 External (RIF): copy an area horizontally, don't worry about clearing src
2179 -------------------------------------------------------------------------- */
2181 NSRect srcRect
= NSMakeRect
(x
, y
, width
, height
);
2182 NSRect dstRect
= NSMakeRect
(x
+shift_by
, y
, width
, height
);
2183 NSPoint dstOrigin
= dstRect.origin
;
2185 NSTRACE
(ns_shift_glyphs_for_insert
);
2187 ns_focus
(f
, &dstRect
, 1);
2188 NSCopyBits
(0, srcRect
, dstOrigin
);
2194 /* ==========================================================================
2196 Character encoding and metrics
2198 ========================================================================== */
2202 ns_compute_glyph_string_overhangs
(struct glyph_string
*s
)
2203 /* --------------------------------------------------------------------------
2204 External (RIF); compute left/right overhang of whole string and set in s
2205 -------------------------------------------------------------------------- */
2207 struct face
*face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2208 struct font
*font
= s
->font
; /*face->font; */
2212 struct font_metrics metrics
;
2213 unsigned int codes
[2];
2214 codes
[0] = *(s
->char2b
);
2215 codes
[1] = *(s
->char2b
+ s
->nchars
- 1);
2217 font
->driver
->text_extents
(font
, codes
, 2, &metrics
);
2218 s
->left_overhang
= -metrics.lbearing
;
2220 = metrics.rbearing
> metrics.width
2221 ? metrics.rbearing
- metrics.width
: 0;
2225 s
->left_overhang
= 0;
2226 s
->right_overhang
= ((struct nsfont_info
*)font
)->ital ?
2227 FONT_HEIGHT
(font
) * 0.2 : 0;
2233 /* ==========================================================================
2235 Fringe and cursor drawing
2237 ========================================================================== */
2240 extern int max_used_fringe_bitmap
;
2242 ns_draw_fringe_bitmap
(struct window
*w
, struct glyph_row
*row
,
2243 struct draw_fringe_bitmap_params
*p
)
2244 /* --------------------------------------------------------------------------
2245 External (RIF); fringe-related
2246 -------------------------------------------------------------------------- */
2248 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2249 struct face
*face
= p
->face
;
2251 static EmacsImage
**bimgs
= NULL;
2252 static int nBimgs
= 0;
2253 /* NS-specific: move internal border inside fringe */
2254 int x
= p
->bx
< 0 ? p
->x
: p
->bx
;
2255 int wd
= p
->bx
< 0 ? p
->wd
: p
->nx
;
2256 BOOL fringeOnVeryLeft
2257 = x
- WINDOW_LEFT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
)
2258 - FRAME_INTERNAL_BORDER_WIDTH
(f
) < 10;
2259 BOOL fringeOnVeryRight
2260 = FRAME_PIXEL_WIDTH
(f
) - x
- wd
- FRAME_INTERNAL_BORDER_WIDTH
(f
)
2261 - WINDOW_RIGHT_SCROLL_BAR_COLS
(w
) * WINDOW_FRAME_COLUMN_WIDTH
(w
) < 10;
2262 int xAdjust
= FRAME_INTERNAL_BORDER_WIDTH
(f
) *
2263 (fringeOnVeryLeft ?
-1 : (fringeOnVeryRight ?
1 : 0));
2265 /* grow bimgs if needed */
2266 if (nBimgs
< max_used_fringe_bitmap
)
2268 EmacsImage
**newBimgs
2269 = xmalloc
(max_used_fringe_bitmap
* sizeof
(EmacsImage
*));
2270 bzero
(newBimgs
, max_used_fringe_bitmap
* sizeof
(EmacsImage
*));
2274 bcopy
(bimgs
, newBimgs
, nBimgs
* sizeof
(EmacsImage
*));
2279 nBimgs
= max_used_fringe_bitmap
;
2282 /* Must clip because of partially visible lines. */
2283 rowY
= WINDOW_TO_FRAME_PIXEL_Y
(w
, row
->y
);
2286 /* Adjust position of "bottom aligned" bitmap on partially
2287 visible last row. */
2289 int oldVH
= row
->visible_height
;
2290 row
->visible_height
= p
->h
;
2291 row
->y
-= rowY
- p
->y
;
2292 ns_clip_to_row
(w
, row
, -1, NO
);
2294 row
->visible_height
= oldVH
;
2297 ns_clip_to_row
(w
, row
, -1, YES
);
2299 if (p
->bx
>= 0 && !p
->overlay_p
)
2301 int yAdjust
= rowY
- FRAME_INTERNAL_BORDER_WIDTH
(f
) < 5 ?
2302 -FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0;
2303 int yIncr
= FRAME_PIXEL_HEIGHT
(f
) - (p
->by
+yAdjust
+ p
->ny
) < 5 ?
2304 FRAME_INTERNAL_BORDER_WIDTH
(f
) : 0;
2306 yIncr
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
2307 NSRect r
= NSMakeRect
(p
->bx
+xAdjust
, p
->by
+yAdjust
, p
->nx
, p
->ny
+yIncr
);
2309 [ns_lookup_indexed_color
(face
->background
, f
) set];
2315 NSRect r
= NSMakeRect
(p
->x
+xAdjust
, p
->y
, p
->wd
, p
->h
);
2316 NSPoint pt
= r.origin
;
2317 EmacsImage
*img
= bimgs
[p
->which - 1];
2321 unsigned short
*bits
= p
->bits
+ p
->dh
;
2322 int len
= 8 * p
->h
/8;
2324 unsigned
char *cbits
= xmalloc
(len
);
2326 for (i
=0; i
<len
; i
++)
2327 cbits
[i
] = ~
(bits
[i
] & 0xff);
2328 img
= [[EmacsImage alloc
] initFromXBM
: cbits width
: 8 height
: p
->h
2330 bimgs
[p
->which - 1] = img
;
2335 /* Since we composite the bitmap instead of just blitting it, we need
2336 to erase the whole background. */
2337 [ns_lookup_indexed_color
(face
->background
, f
) set];
2340 [img setXBMColor
: ns_lookup_indexed_color
(face
->foreground
, f
)];
2341 [img compositeToPoint
: pt operation
: NSCompositeSourceOver
];
2348 ns_draw_window_cursor
(struct window
*w
, struct glyph_row
*glyph_row
,
2349 int x
, int y
, int cursor_type
, int cursor_width
,
2350 int on_p
, int active_p
)
2351 /* --------------------------------------------------------------------------
2352 External call (RIF): draw cursor
2353 (modeled after x_draw_window_cursor
2354 FIXME: cursor_width is effectively bogus -- it sometimes gets set
2355 in xdisp.c set_frame_cursor_types, sometimes left uninitialized;
2356 DON'T USE IT (no other terms do)
2357 -------------------------------------------------------------------------- */
2361 struct frame
*f
= WINDOW_XFRAME
(w
);
2362 struct glyph
*phys_cursor_glyph
;
2365 NSTRACE
(dumpcursor
);
2366 //fprintf(stderr
, "drawcursor
(%d,%d) activep = %d\tonp = %d\tc_type = %d\twidth = %d\n",x,y, active_p,on_p,cursor_type,cursor_width);
2371 w
->phys_cursor_type
= cursor_type
;
2372 w
->phys_cursor_on_p
= on_p
;
2374 if (cursor_type
== NO_CURSOR
)
2376 w
->phys_cursor_width
= 0;
2380 if ((phys_cursor_glyph
= get_phys_cursor_glyph
(w
)) == NULL)
2382 if (glyph_row
->exact_window_width_line_p
2383 && w
->phys_cursor.hpos
>= glyph_row
->used
[TEXT_AREA
])
2385 glyph_row
->cursor_in_fringe_p
= 1;
2386 draw_fringe_bitmap
(w
, glyph_row
, 0);
2391 get_phys_cursor_geometry
(w
, glyph_row
, phys_cursor_glyph
, &fx
, &fy
, &h
);
2393 r.origin.x
= fx
, r.origin.y
= fy
;
2395 r.
size.width
= w
->phys_cursor_width
;
2397 /* FIXME: if we overwrite the internal border area, it does not get erased;
2398 fix by truncating cursor, but better would be to erase properly */
2399 overspill
= r.origin.x
+ r.
size.width
-
2400 WINDOW_TEXT_TO_FRAME_PIXEL_X
(w
, WINDOW_BOX_RIGHT_EDGE_X
(w
)
2401 - WINDOW_TOTAL_FRINGE_WIDTH
(w
) - FRAME_INTERNAL_BORDER_WIDTH
(f
));
2403 r.
size.width
-= overspill
;
2405 /* TODO: only needed in rare cases with last-resort font in HELLO..
2406 should we do this more efficiently? */
2407 ns_clip_to_row
(w
, glyph_row
, -1, NO
); /* do ns_focus(f, &r, 1); if remove */
2408 [FRAME_CURSOR_COLOR
(f
) set];
2410 #ifdef NS_IMPL_COCOA
2411 /* TODO: This makes drawing of cursor plus that of phys_cursor_glyph
2412 atomic. Cleaner ways of doing this should be investigated.
2413 One way would be to set a global variable DRAWING_CURSOR
2414 when making the call to draw_phys..(), don't focus in that
2415 case, then move the ns_unfocus() here after that call. */
2416 NSDisableScreenUpdates
();
2419 switch (cursor_type
)
2423 case FILLED_BOX_CURSOR
:
2426 case HOLLOW_BOX_CURSOR
:
2428 [FRAME_BACKGROUND_COLOR
(f
) set];
2429 NSRectFill
(NSInsetRect
(r
, 1, 1));
2430 [FRAME_CURSOR_COLOR
(f
) set];
2434 s.origin.y
+= lrint
(0.75 * s.
size.height
);
2435 s.
size.height
= lrint
(s.
size.height
* 0.25);
2440 s.
size.width
= min (cursor_width
, 2); //FIXME
(see above
)
2446 /* draw the character under the cursor */
2447 if (cursor_type
!= NO_CURSOR
)
2448 draw_phys_cursor_glyph
(w
, glyph_row
, DRAW_CURSOR
);
2450 #ifdef NS_IMPL_COCOA
2451 NSEnableScreenUpdates
();
2458 ns_draw_vertical_window_border
(struct window
*w
, int x
, int y0
, int y1
)
2459 /* --------------------------------------------------------------------------
2460 External (RIF): Draw a vertical line.
2461 -------------------------------------------------------------------------- */
2463 struct frame
*f
= XFRAME
(WINDOW_FRAME
(w
));
2465 NSRect r
= NSMakeRect
(x
, y0
, 1, y1
-y0
);
2467 NSTRACE
(ns_draw_vertical_window_border
);
2469 face
= FACE_FROM_ID
(f
, VERTICAL_BORDER_FACE_ID
);
2471 [ns_lookup_indexed_color
(face
->foreground
, f
) set];
2473 ns_focus
(f
, &r
, 1);
2480 show_hourglass
(struct atimer
*timer
)
2482 if (hourglass_shown_p
)
2487 /* TODO: add NSProgressIndicator to selected frame (see macfns.c) */
2489 hourglass_shown_p
= 1;
2497 if (!hourglass_shown_p
)
2502 /* TODO: remove NSProgressIndicator from all frames */
2504 hourglass_shown_p
= 0;
2510 /* ==========================================================================
2512 Glyph drawing operations
2514 ========================================================================== */
2517 static inline NSRect
2518 ns_fix_rect_ibw
(NSRect r
, int fibw
, int frame_pixel_width
)
2519 /* --------------------------------------------------------------------------
2520 Under NS we draw internal borders inside fringes, and want full-width
2521 rendering to go all the way to edge. This function makes that correction.
2522 -------------------------------------------------------------------------- */
2524 if (r.origin.y
<= fibw
+1)
2526 r.
size.height
+= r.origin.y
;
2529 if (r.origin.x
<= fibw
+1)
2531 r.
size.width
+= r.origin.x
;
2534 if (frame_pixel_width
- (r.origin.x
+r.
size.width
) <= fibw
+1)
2535 r.
size.width
+= fibw
;
2542 ns_get_glyph_string_clip_rect
(struct glyph_string
*s
, NativeRectangle
*nr
)
2543 /* --------------------------------------------------------------------------
2544 Wrapper utility to account for internal border width on full-width lines,
2545 and allow top full-width rows to hit the frame top. nr should be pointer
2546 to two successive NSRects. Number of rects actually used is returned.
2547 -------------------------------------------------------------------------- */
2549 int n
= get_glyph_string_clip_rects
(s
, nr
, 2);
2550 if (s
->row
->full_width_p
)
2552 *nr
= ns_fix_rect_ibw
(*nr
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2553 FRAME_PIXEL_WIDTH
(s
->f
));
2555 *nr
= ns_fix_rect_ibw
(*(nr
+1), FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2556 FRAME_PIXEL_WIDTH
(s
->f
));
2563 ns_draw_box
(NSRect r
, float thickness
, NSColor
*col
, char left_p
, char right_p
)
2564 /* --------------------------------------------------------------------------
2565 Draw an unfilled rect inside r, optionally leaving left and/or right open.
2566 Note we can't just use an NSDrawRect command, because of the possibility
2567 of some sides not being drawn, and because the rect will be filled.
2568 -------------------------------------------------------------------------- */
2574 s.
size.height
= thickness
;
2576 s.origin.y
+= r.
size.height
- thickness
;
2579 s.
size.height
= r.
size.height
;
2580 s.origin.y
= r.origin.y
;
2582 /* left, right (optional) */
2583 s.
size.width
= thickness
;
2588 s.origin.x
+= r.
size.width
- thickness
;
2595 ns_draw_relief
(NSRect r
, int thickness
, char raised_p
,
2596 char top_p
, char bottom_p
, char left_p
, char right_p
,
2597 struct glyph_string
*s
)
2598 /* --------------------------------------------------------------------------
2599 Draw a relief rect inside r, optionally leaving some sides open.
2600 Note we can't just use an NSDrawBezel command, because of the possibility
2601 of some sides not being drawn, and because the rect will be filled.
2602 -------------------------------------------------------------------------- */
2604 static NSColor
*baseCol
= nil
, *lightCol
= nil
, *darkCol
= nil
;
2605 NSColor
*newBaseCol
= nil
;
2608 NSTRACE
(ns_draw_relief
);
2612 if (s
->face
->use_box_color_for_shadows_p
)
2614 newBaseCol
= ns_lookup_indexed_color
(s
->face
->box_color
, s
->f
);
2616 /* else if (s->first_glyph->type == IMAGE_GLYPH
2618 && !IMAGE_BACKGROUND_TRANSPARENT (s->img, s->f, 0))
2620 newBaseCol = IMAGE_BACKGROUND (s->img, s->f, 0);
2624 newBaseCol
= ns_lookup_indexed_color
(s
->face
->background
, s
->f
);
2627 if (newBaseCol
== nil
)
2628 newBaseCol
= [NSColor grayColor
];
2630 if (newBaseCol
!= baseCol
) /* TODO: better check */
2633 baseCol
= [newBaseCol retain
];
2635 lightCol
= [[baseCol highlightWithLevel
: 0.2] retain
];
2637 darkCol
= [[baseCol shadowWithLevel
: 0.3] retain
];
2640 [(raised_p ? lightCol
: darkCol
) set];
2642 /* TODO: mitering. Using NSBezierPath doesn't work because of color switch. */
2645 sr.
size.height
= thickness
;
2646 if (top_p
) NSRectFill
(sr
);
2649 sr.
size.height
= r.
size.height
;
2650 sr.
size.width
= thickness
;
2651 if (left_p
) NSRectFill
(sr
);
2653 [(raised_p ? darkCol
: lightCol
) set];
2656 sr.
size.width
= r.
size.width
;
2657 sr.
size.height
= thickness
;
2658 sr.origin.y
+= r.
size.height
- thickness
;
2659 if (bottom_p
) NSRectFill
(sr
);
2662 sr.
size.height
= r.
size.height
;
2663 sr.origin.y
= r.origin.y
;
2664 sr.
size.width
= thickness
;
2665 sr.origin.x
+= r.
size.width
- thickness
;
2666 if (right_p
) NSRectFill
(sr
);
2671 ns_dumpglyphs_box_or_relief
(struct glyph_string
*s
)
2672 /* --------------------------------------------------------------------------
2673 Function modeled after x_draw_glyph_string_box ().
2674 Sets up parameters for drawing.
2675 -------------------------------------------------------------------------- */
2677 int right_x
, last_x
;
2678 char left_p
, right_p
;
2679 struct glyph
*last_glyph
;
2684 if (s
->hl
== DRAW_MOUSE_FACE
)
2687 (s
->f
, FRAME_NS_DISPLAY_INFO
(s
->f
)->mouse_face_face_id
);
2689 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2694 thickness
= face
->box_line_width
;
2696 NSTRACE
(ns_dumpglyphs_box_or_relief
);
2698 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2699 ? WINDOW_RIGHT_EDGE_X
(s
->w
)
2700 : window_box_right
(s
->w
, s
->area
));
2701 last_glyph
= (s
->cmp || s
->img
2702 ? s
->first_glyph
: s
->first_glyph
+ s
->nchars
-1);
2704 right_x
= ((s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2705 ? last_x
- 1 : min (last_x
, s
->x
+ s
->background_width
) - 1));
2707 left_p
= (s
->first_glyph
->left_box_line_p
2708 ||
(s
->hl
== DRAW_MOUSE_FACE
2709 && (s
->prev
== NULL || s
->prev
->hl
!= s
->hl
)));
2710 right_p
= (last_glyph
->right_box_line_p
2711 ||
(s
->hl
== DRAW_MOUSE_FACE
2712 && (s
->next
== NULL || s
->next
->hl
!= s
->hl
)));
2714 r
= NSMakeRect
(s
->x
, s
->y
, right_x
- s
->x
+ 1, s
->height
);
2716 /* expand full-width row over internal borders */
2717 if (s
->row
->full_width_p
)
2718 r
= ns_fix_rect_ibw
(r
, FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2719 FRAME_PIXEL_WIDTH
(s
->f
));
2721 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2723 xassert
(s
->face
->box_color
!= nil
);
2724 ns_draw_box
(r
, abs (thickness
),
2725 ns_lookup_indexed_color
(face
->box_color
, s
->f
),
2730 ns_draw_relief
(r
, abs (thickness
), s
->face
->box
== FACE_RAISED_BOX
,
2731 1, 1, left_p
, right_p
, s
);
2737 ns_maybe_dumpglyphs_background
(struct glyph_string
*s
, char force_p
)
2738 /* --------------------------------------------------------------------------
2739 Modeled after x_draw_glyph_string_background, which draws BG in
2740 certain cases. Others are left to the text rendering routine.
2741 -------------------------------------------------------------------------- */
2743 NSTRACE
(ns_maybe_dumpglyphs_background
);
2745 if (!s
->background_filled_p
/* || s->hl == DRAW_MOUSE_FACE*/)
2747 int box_line_width
= max (s
->face
->box_line_width
, 0);
2748 if (FONT_HEIGHT
(s
->font
) < s
->height
- 2 * box_line_width
2749 || s
->font_not_found_p || s
->extends_to_end_of_line_p || force_p
)
2752 if (s
->hl
== DRAW_MOUSE_FACE
)
2755 (s
->f
, FRAME_NS_DISPLAY_INFO
(s
->f
)->mouse_face_face_id
);
2757 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2760 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2764 [(NS_FACE_BACKGROUND
(face
) != 0
2765 ? ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
)
2766 : FRAME_BACKGROUND_COLOR
(s
->f
)) set];
2767 #
if 0 /* This is tiling, not stippling. */
2770 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(s
->f
);
2771 [[dpyinfo
->bitmaps
[face
->stipple
-1].img stippleMask
] set];
2775 if (s
->hl
!= DRAW_CURSOR
)
2777 NSRect r
= NSMakeRect
(s
->x
, s
->y
+ box_line_width
,
2778 s
->background_width
,
2779 s
->height
-2*box_line_width
);
2781 /* expand full-width row over internal borders */
2782 if (s
->row
->full_width_p
)
2784 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
2785 if (r.origin.y
<= fibw
+1 + box_line_width
)
2787 r.
size.height
+= r.origin.y
;
2790 if (r.origin.x
<= fibw
+1)
2792 r.
size.width
+= 2*r.origin.x
;
2795 if (FRAME_PIXEL_WIDTH
(s
->f
) - (r.origin.x
+ r.
size.width
)
2797 r.
size.width
+= fibw
;
2803 s
->background_filled_p
= 1;
2810 ns_dumpglyphs_image
(struct glyph_string
*s
, NSRect r
)
2811 /* --------------------------------------------------------------------------
2812 Renders an image and associated borders.
2813 -------------------------------------------------------------------------- */
2815 EmacsImage
*img
= s
->img
->pixmap
;
2816 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2817 int x
= s
->x
, y
= s
->ybase
- image_ascent
(s
->img
, s
->face
, &s
->slice);
2818 int bg_x
, bg_y
, bg_height
;
2824 NSTRACE
(ns_dumpglyphs_image
);
2826 if (s
->face
->box
!= FACE_NO_BOX
2827 && s
->first_glyph
->left_box_line_p
&& s
->slice.x
== 0)
2828 x
+= abs (s
->face
->box_line_width
);
2831 bg_y
= s
->slice.y
== 0 ? s
->y
: s
->y
+ box_line_vwidth
;
2832 bg_height
= s
->height
;
2833 /* other terms have this, but was causing problems w/tabbar mode */
2834 /* - 2 * box_line_vwidth; */
2836 if (s
->slice.x
== 0) x
+= s
->img
->hmargin
;
2837 if (s
->slice.y
== 0) y
+= s
->img
->vmargin
;
2839 /* Draw BG: if we need larger area than image itself cleared, do that,
2840 otherwise, since we composite the image under NS (instead of mucking
2841 with its background color), we must clear just the image area. */
2842 if (s
->hl
== DRAW_MOUSE_FACE
)
2845 (s
->f
, FRAME_NS_DISPLAY_INFO
(s
->f
)->mouse_face_face_id
);
2847 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2850 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2852 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
2854 if (bg_height
> s
->slice.height || s
->img
->hmargin || s
->img
->vmargin
2855 || s
->img
->mask || s
->img
->pixmap
== 0 || s
->width
!= s
->background_width
)
2857 br
= NSMakeRect
(bg_x
, bg_y
, s
->background_width
, bg_height
);
2858 s
->background_filled_p
= 1;
2862 br
= NSMakeRect
(x
, y
, s
->slice.width
, s
->slice.height
);
2865 /* expand full-width row over internal borders */
2866 if (s
->row
->full_width_p
)
2868 int fibw
= FRAME_INTERNAL_BORDER_WIDTH
(s
->f
);
2869 if (br.origin.y
<= fibw
+1 + box_line_vwidth
)
2871 br.
size.height
+= br.origin.y
;
2874 if (br.origin.x
<= fibw
+1 + box_line_vwidth
)
2876 br.
size.width
+= br.origin.x
;
2879 if (FRAME_PIXEL_WIDTH
(s
->f
) - (br.origin.x
+ br.
size.width
) <= fibw
+1)
2880 br.
size.width
+= fibw
;
2885 /* Draw the image.. do we need to draw placeholder if img ==nil? */
2887 [img compositeToPoint
: NSMakePoint
(x
, y
+ s
->slice.height
)
2888 operation
: NSCompositeSourceOver
];
2890 /* Draw relief, if requested */
2891 if (s
->img
->relief || s
->hl
==DRAW_IMAGE_RAISED || s
->hl
==DRAW_IMAGE_SUNKEN
)
2893 if (s
->hl
== DRAW_IMAGE_SUNKEN || s
->hl
== DRAW_IMAGE_RAISED
)
2895 th
= tool_bar_button_relief
>= 0 ?
2896 tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2897 raised_p
= (s
->hl
== DRAW_IMAGE_RAISED
);
2901 th
= abs (s
->img
->relief
);
2902 raised_p
= (s
->img
->relief
> 0);
2905 r.origin.x
= x
- th
;
2906 r.origin.y
= y
- th
;
2907 r.
size.width
= s
->slice.width
+ 2*th
-1;
2908 r.
size.height
= s
->slice.height
+ 2*th
-1;
2909 ns_draw_relief
(r
, th
, raised_p
,
2911 s
->slice.y
+ s
->slice.height
== s
->img
->height
,
2913 s
->slice.x
+ s
->slice.width
== s
->img
->width
, s
);
2919 ns_dumpglyphs_stretch
(struct glyph_string
*s
)
2925 if (!s
->background_filled_p
)
2927 n
= ns_get_glyph_string_clip_rect
(s
, r
);
2928 *r
= NSMakeRect
(s
->x
, s
->y
, s
->background_width
, s
->height
);
2932 if (!s
->row
->full_width_p
)
2934 /* truncate to avoid overwriting fringe and/or scrollbar */
2935 int overrun
= max (0, (s
->x
+ s
->background_width
)
2936 - (WINDOW_BOX_RIGHT_EDGE_X
(s
->w
)
2937 - WINDOW_RIGHT_FRINGE_WIDTH
(s
->w
)));
2938 r
[i
].
size.width
-= overrun
;
2940 /* XXX: Try to work between problem where a stretch glyph on
2941 a partially-visible bottom row will clear part of the
2942 modeline, and another where list-buffers headers and similar
2943 rows erroneously have visible_height set to 0. Not sure
2944 where this is coming from as other terms seem not to show. */
2945 r
[i
].
size.height
= min (s
->height
, s
->row
->visible_height
);
2948 /* expand full-width rows over internal borders */
2951 r
[i
] = ns_fix_rect_ibw
(r
[i
], FRAME_INTERNAL_BORDER_WIDTH
(s
->f
),
2952 FRAME_PIXEL_WIDTH
(s
->f
));
2955 /* NOTE: under NS this is NOT used to draw cursors, but we must avoid
2956 overwriting cursor (usually when cursor on a tab) */
2957 if (s
->hl
== DRAW_CURSOR
)
2959 r
[i
].origin.x
+= s
->width
;
2960 r
[i
].
size.width
-= s
->width
;
2964 ns_focus
(s
->f
, r
, n
);
2966 if (s
->hl
== DRAW_MOUSE_FACE
)
2969 (s
->f
, FRAME_NS_DISPLAY_INFO
(s
->f
)->mouse_face_face_id
);
2971 face
= FACE_FROM_ID
(s
->f
, MOUSE_FACE_ID
);
2974 face
= FACE_FROM_ID
(s
->f
, s
->first_glyph
->face_id
);
2976 [ns_lookup_indexed_color
(NS_FACE_BACKGROUND
(face
), s
->f
) set];
2981 s
->background_filled_p
= 1;
2987 ns_draw_glyph_string
(struct glyph_string
*s
)
2988 /* --------------------------------------------------------------------------
2989 External (RIF): Main draw-text call.
2990 -------------------------------------------------------------------------- */
2992 /* TODO (optimize): focus for box and contents draw */
2995 char box_drawn_p
= 0;
2997 NSTRACE
(ns_draw_glyph_string
);
2999 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
/*&&s->hl!=DRAW_CURSOR*/)
3002 struct glyph_string
*next
;
3004 for (width
= 0, next
= s
->next
;
3005 next
&& width
< s
->right_overhang
;
3006 width
+= next
->width
, next
= next
->next
)
3007 if (next
->first_glyph
->type != IMAGE_GLYPH
)
3009 if (next
->first_glyph
->type != STRETCH_GLYPH
)
3011 n
= ns_get_glyph_string_clip_rect
(s
->next
, r
);
3012 ns_focus
(s
->f
, r
, n
);
3013 ns_maybe_dumpglyphs_background
(s
->next
, 1);
3018 ns_dumpglyphs_stretch
(s
->next
);
3020 next
->num_clips
= 0;
3024 if (!s
->for_overlaps
&& s
->face
->box
!= FACE_NO_BOX
3025 && (s
->first_glyph
->type == CHAR_GLYPH
3026 || s
->first_glyph
->type == COMPOSITE_GLYPH
))
3028 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3029 ns_focus
(s
->f
, r
, n
);
3030 ns_maybe_dumpglyphs_background
(s
, 1);
3031 ns_dumpglyphs_box_or_relief
(s
);
3036 switch (s
->first_glyph
->type)
3040 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3041 ns_focus
(s
->f
, r
, n
);
3042 ns_dumpglyphs_image
(s
, r
[0]);
3047 ns_dumpglyphs_stretch
(s
);
3051 case COMPOSITE_GLYPH
:
3052 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3053 ns_focus
(s
->f
, r
, n
);
3055 if (s
->for_overlaps ||
(s
->cmp_from
> 0
3056 && ! s
->first_glyph
->u.cmp.automatic
))
3057 s
->background_filled_p
= 1;
3059 ns_maybe_dumpglyphs_background
3060 (s
, s
->first_glyph
->type == COMPOSITE_GLYPH
);
3062 ns_tmp_flags
= s
->hl
== DRAW_CURSOR ? NS_DUMPGLYPH_CURSOR
:
3063 (s
->hl
== DRAW_MOUSE_FACE ? NS_DUMPGLYPH_MOUSEFACE
:
3064 (s
->for_overlaps ? NS_DUMPGLYPH_FOREGROUND
:
3065 NS_DUMPGLYPH_NORMAL
));
3066 ns_tmp_font
= (struct nsfont_info
*)s
->face
->font
;
3067 if (ns_tmp_font
== NULL)
3068 ns_tmp_font
= (struct nsfont_info
*)FRAME_FONT
(s
->f
);
3070 ns_tmp_font
->font.driver
->draw
3071 (s
, 0, s
->nchars
, s
->x
, s
->y
,
3072 (ns_tmp_flags
== NS_DUMPGLYPH_NORMAL
&& !s
->background_filled_p
)
3073 || ns_tmp_flags
== NS_DUMPGLYPH_MOUSEFACE
);
3082 /* Draw box if not done already. */
3083 if (!s
->for_overlaps
&& !box_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3085 n
= ns_get_glyph_string_clip_rect
(s
, r
);
3086 ns_focus
(s
->f
, r
, n
);
3087 ns_dumpglyphs_box_or_relief
(s
);
3096 /* ==========================================================================
3100 ========================================================================== */
3104 ns_send_appdefined
(int value
)
3105 /* --------------------------------------------------------------------------
3106 Internal: post an appdefined event which EmacsApp-sendEvent will
3107 recognize and take as a command to halt the event loop.
3108 -------------------------------------------------------------------------- */
3110 /*NSTRACE (ns_send_appdefined); */
3112 /* Only post this event if we haven't already posted one. This will end
3113 the [NXApp run] main loop after having processed all events queued at
3115 if (send_appdefined
)
3119 /* We only need one NX_APPDEFINED event to stop NXApp from running. */
3120 send_appdefined
= NO
;
3122 /* Don't need wakeup timer any more */
3125 [timed_entry invalidate
];
3126 [timed_entry release
];
3130 /* Ditto for file descriptor poller */
3133 [fd_entry invalidate
];
3138 nxev
= [NSEvent otherEventWithType
: NSApplicationDefined
3139 location
: NSMakePoint
(0, 0)
3142 windowNumber
: [[NSApp mainWindow
] windowNumber
]
3143 context
: [NSApp context
]
3148 /* Post an application defined event on the event queue. When this is
3149 received the [NXApp run] will return, thus having processed all
3150 events which are currently queued. */
3151 [NSApp postEvent
: nxev atStart
: NO
];
3157 ns_read_socket
(struct terminal *terminal, int expected
,
3158 struct input_event
*hold_quit
)
3159 /* --------------------------------------------------------------------------
3160 External (hook): Post an event to ourself and keep reading events until
3161 we read it back again. In effect process all events which were waiting.
3162 From 21+ we have to manage the event buffer ourselves.
3163 -------------------------------------------------------------------------- */
3165 struct input_event ev
;
3168 /* NSTRACE (ns_read_socket); */
3170 if (interrupt_input_blocked
)
3172 interrupt_input_pending
= 1;
3174 pending_signals
= 1;
3179 interrupt_input_pending
= 0;
3181 pending_signals
= pending_atimers
;
3185 n_emacs_events_pending
= 0;
3188 q_event_ptr
= hold_quit
;
3190 /* we manage autorelease pools by allocate/reallocate each time around
3191 the loop; strict nesting is occasionally violated but seems not to
3192 matter.. earlier methods using full nesting caused major memory leaks */
3193 [outerpool release
];
3194 outerpool
= [[NSAutoreleasePool alloc
] init
];
3196 /* If have pending open-file requests, attend to the next one of those. */
3197 if (ns_pending_files
&& [ns_pending_files count
] != 0
3198 && [(EmacsApp
*)NSApp openFile
: [ns_pending_files objectAtIndex
: 0]])
3200 [ns_pending_files removeObjectAtIndex
: 0];
3202 /* Deal with pending service requests. */
3203 else if (ns_pending_service_names
&& [ns_pending_service_names count
] != 0
3205 NSApp fulfillService
: [ns_pending_service_names objectAtIndex
: 0]
3206 withArg
: [ns_pending_service_args objectAtIndex
: 0]])
3208 [ns_pending_service_names removeObjectAtIndex
: 0];
3209 [ns_pending_service_args removeObjectAtIndex
: 0];
3213 /* Run and wait for events. We must always send one NX_APPDEFINED event
3214 to ourself, otherwise [NXApp run] will never exit. */
3215 send_appdefined
= YES
;
3217 /* If called via ns_select, this is called once with expected=1,
3218 because we expect either the timeout or file descriptor activity.
3219 In this case the first event through will either be real input or
3220 one of these. read_avail_input() then calls once more with expected=0
3221 and in that case we need to return quickly if there is nothing.
3222 If we're being called outside of that, it's also OK to return quickly
3223 after one iteration through the event loop, since other terms do
3224 this and emacs expects it. */
3225 if (!(inNsSelect
&& expected
)) // (!inNsSelect ||
!expected
)
3227 /* Post an application defined event on the event queue. When this is
3228 received the [NXApp run] will return, thus having processed all
3229 events which are currently queued, if any. */
3230 ns_send_appdefined
(-1);
3236 nevents
= n_emacs_events_pending
;
3237 n_emacs_events_pending
= 0;
3238 emacs_event
= q_event_ptr
= NULL;
3246 ns_select
(int nfds
, fd_set
*readfds
, fd_set
*writefds
,
3247 fd_set
*exceptfds
, struct timeval
*timeout
)
3248 /* --------------------------------------------------------------------------
3249 Replacement for select, checking for events
3250 -------------------------------------------------------------------------- */
3255 /* NSTRACE (ns_select); */
3257 if (NSApp
== nil || inNsSelect
== 1 /* || ([NSApp isActive] == NO &&
3258 [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil
3259 inMode:NSDefaultRunLoopMode dequeue:NO] == nil) */)
3260 return select
(nfds
, readfds
, writefds
, exceptfds
, timeout
);
3262 /* Save file descriptor set, which gets overwritten in calls to select ()
3263 Note, this is called from process.c, and only readfds is ever set */
3266 memcpy
(&select_readfds
, readfds
, sizeof
(fd_set
));
3272 /* Try an initial select for pending data on input files */
3273 select_timeout.tv_sec
= select_timeout.tv_usec
= 0;
3274 result
= select
(nfds
, readfds
, writefds
, exceptfds
, &select_timeout
);
3278 /* if (!timeout || timed_entry || fd_entry)
3279 fprintf (stderr, "assertion failed: timeout null or timed_entry/fd_entry non-null in ns_select\n"); */
3281 /* set a timeout and run the main AppKit event loop while continuing
3282 to monitor the files */
3283 time
= ((double) timeout
->tv_sec
) + ((double) timeout
->tv_usec
)/1000000.0;
3284 timed_entry
= [[NSTimer scheduledTimerWithTimeInterval
: time
3286 selector
: @selector
(timeout_handler
:)
3288 repeats
: YES
] /* for safe removal */
3291 /* set a periodic task to try the select () again */
3292 fd_entry
= [[NSTimer scheduledTimerWithTimeInterval
: 0.1
3294 selector
: @selector
(fd_handler
:)
3299 /* Let Application dispatch events until it receives an event of the type
3300 NX_APPDEFINED, which should only be sent by timeout_handler.
3301 We tell read_avail_input() that input is "expected" because we do expect
3302 either the timeout or fd handler to fire, and if they don't, the original
3303 call from process.c that got us here expects us to wait until some input
3307 ev
= last_appdefined_event
;
3313 if ([ev
type] != NSApplicationDefined
)
3317 last_appdefined_event
= 0;
3321 /* The NX_APPDEFINED event we received was a timeout. */
3326 /* The NX_APPDEFINED event we received was the result of
3327 at least one real input event arriving. */
3333 /* Received back from select () in fd_handler; copy the results */
3335 memcpy
(readfds
, &select_readfds
, sizeof
(fd_set
));
3339 /* never reached, shut compiler up */
3345 /* ==========================================================================
3349 ========================================================================== */
3353 ns_set_vertical_scroll_bar
(struct window
*window
,
3354 int portion
, int whole
, int position
)
3355 /* --------------------------------------------------------------------------
3356 External (hook): Update or add scrollbar
3357 -------------------------------------------------------------------------- */
3361 struct frame
*f
= XFRAME
(WINDOW_FRAME
(window
));
3362 EmacsView
*view = FRAME_NS_VIEW
(f
);
3363 int window_y
, window_height
;
3364 BOOL barOnVeryLeft
, barOnVeryRight
;
3365 int top
, left
, height
, width
, sb_width
, sb_left
;
3367 static int count
= 0;
3369 /* optimization; display engine sends WAY too many of these.. */
3370 if (!NILP
(window
->vertical_scroll_bar
))
3372 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3373 if ([bar checkSamePosition
: position portion
: portion whole
: whole
])
3375 if (view->scrollbarsNeedingUpdate
== 0)
3377 if (!windows_or_buffers_changed
)
3381 view->scrollbarsNeedingUpdate
--;
3385 NSTRACE
(ns_set_vertical_scroll_bar
);
3387 /* Get dimensions. */
3388 window_box
(window
, -1, 0, &window_y
, 0, &window_height
);
3390 height
= window_height
;
3391 width
= WINDOW_CONFIG_SCROLL_BAR_COLS
(window
) * FRAME_COLUMN_WIDTH
(f
);
3392 left
= WINDOW_SCROLL_BAR_AREA_X
(window
);
3394 if (top
< 5) /* top scrollbar adjustment */
3396 top
-= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3397 height
+= FRAME_INTERNAL_BORDER_WIDTH
(f
);
3400 /* allow for displaying a skinnier scrollbar than char area allotted */
3401 sb_width
= (WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) > 0) ?
3402 WINDOW_CONFIG_SCROLL_BAR_WIDTH
(window
) : width
;
3404 barOnVeryLeft
= left
< 5;
3405 barOnVeryRight
= FRAME_PIXEL_WIDTH
(f
) - left
- width
< 5;
3406 sb_left
= left
+ FRAME_INTERNAL_BORDER_WIDTH
(f
)
3407 * (barOnVeryLeft ?
-1 : (barOnVeryRight ?
1 : 0));
3409 r
= NSMakeRect
(sb_left
, top
, sb_width
, height
);
3410 /* the parent view is flipped, so we need to flip y value */
3412 r.origin.y
= (v.
size.height
- r.
size.height
- r.origin.y
);
3414 XSETWINDOW
(win
, window
);
3417 /* we want at least 5 lines to display a scrollbar */
3418 if (WINDOW_TOTAL_LINES
(window
) < 5)
3420 if (!NILP
(window
->vertical_scroll_bar
))
3422 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3423 [bar removeFromSuperview
];
3424 window
->vertical_scroll_bar
= Qnil
;
3426 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3431 if (NILP
(window
->vertical_scroll_bar
))
3433 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3434 bar = [[EmacsScroller alloc
] initFrame
: r window
: win
];
3435 window
->vertical_scroll_bar
= make_save_value
(bar, 0);
3440 bar = XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3441 oldRect
= [bar frame
];
3442 r.
size.width
= oldRect.
size.width
;
3443 if (FRAME_LIVE_P
(f
) && !NSEqualRects
(oldRect
, r
))
3445 if (oldRect.origin.x
!= r.origin.x
)
3446 ns_clear_frame_area
(f
, sb_left
, top
, width
, height
);
3451 [bar setPosition
: position portion
: portion whole
: whole
];
3457 ns_condemn_scroll_bars
(struct frame
*f
)
3458 /* --------------------------------------------------------------------------
3459 External (hook): arrange for all frame's scrollbars to be removed
3460 at next call to judge_scroll_bars, except for those redeemed.
3461 -------------------------------------------------------------------------- */
3465 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3467 NSTRACE
(ns_condemn_scroll_bars
);
3469 for (i
=[subviews count
]-1; i
>= 0; i
--)
3471 view = [subviews objectAtIndex
: i
];
3472 if ([view isKindOfClass
: [EmacsScroller
class]])
3479 ns_redeem_scroll_bar
(struct window
*window
)
3480 /* --------------------------------------------------------------------------
3481 External (hook): arrange to spare this window's scrollbar
3482 at next call to judge_scroll_bars.
3483 -------------------------------------------------------------------------- */
3486 NSTRACE
(ns_redeem_scroll_bar
);
3487 if (!NILP
(window
->vertical_scroll_bar
))
3489 bar =XNS_SCROLL_BAR
(window
->vertical_scroll_bar
);
3496 ns_judge_scroll_bars
(struct frame
*f
)
3497 /* --------------------------------------------------------------------------
3498 External (hook): destroy all scrollbars on frame that weren't
3499 redeemed after call to condemn_scroll_bars.
3500 -------------------------------------------------------------------------- */
3504 NSArray
*subviews
= [[FRAME_NS_VIEW
(f
) superview
] subviews
];
3505 NSTRACE
(ns_judge_scroll_bars
);
3506 for (i
=[subviews count
]-1; i
>= 0; i
--)
3508 view = [subviews objectAtIndex
: i
];
3509 if (![view isKindOfClass
: [EmacsScroller
class]]) continue
;
3516 x_wm_set_icon_position
(struct frame
*f
, int icon_x
, int icon_y
)
3518 /* XXX irrelevant under NS */
3523 /* ==========================================================================
3527 ========================================================================== */
3530 x_display_pixel_height
(dpyinfo
)
3531 struct ns_display_info
*dpyinfo
;
3533 NSScreen
*screen
= [NSScreen mainScreen
];
3534 return [screen frame
].
size.height
;
3538 x_display_pixel_width
(dpyinfo
)
3539 struct ns_display_info
*dpyinfo
;
3541 NSScreen
*screen
= [NSScreen mainScreen
];
3542 return [screen frame
].
size.width
;
3546 static Lisp_Object ns_string_to_lispmod
(const
char *s
)
3547 /* --------------------------------------------------------------------------
3548 Convert modifier name to lisp symbol
3549 -------------------------------------------------------------------------- */
3551 if (!strncmp
(SDATA
(SYMBOL_NAME
(Qmeta
)), s
, 10))
3553 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qsuper
)), s
, 10))
3555 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qcontrol
)), s
, 10))
3557 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qalt
)), s
, 10))
3559 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qhyper
)), s
, 10))
3561 else if (!strncmp
(SDATA
(SYMBOL_NAME
(Qnone
)), s
, 10))
3568 static Lisp_Object ns_mod_to_lisp
(int m
)
3569 /* --------------------------------------------------------------------------
3570 Convert modifier code (see lisp.h) to lisp symbol
3571 -------------------------------------------------------------------------- */
3575 else if (m
== CHAR_SUPER
)
3577 else if (m
== CHAR_CTL
)
3579 else if (m
== CHAR_ALT
)
3581 else if (m
== CHAR_HYPER
)
3583 else /* if (m == 0) */
3589 ns_set_default_prefs
()
3590 /* --------------------------------------------------------------------------
3591 Initialize preference variables to defaults
3592 -------------------------------------------------------------------------- */
3594 ns_alternate_modifier
= Qmeta
;
3595 ns_command_modifier
= Qsuper
;
3596 ns_control_modifier
= Qcontrol
;
3597 ns_function_modifier
= Qnone
;
3598 ns_antialias_text
= Qt
;
3599 ns_antialias_threshold
= 10.0; /* not exposed to lisp side */
3600 ns_use_qd_smoothing
= Qnil
;
3601 ns_confirm_quit
= Qnil
;
3606 ns_default
(const
char *parameter
, Lisp_Object
*result
,
3607 Lisp_Object yesval
, Lisp_Object noval
,
3608 BOOL is_float
, BOOL is_modstring
)
3609 /* --------------------------------------------------------------------------
3610 Check a parameter value in user's preferences
3611 -------------------------------------------------------------------------- */
3615 if ( (value
=[[[NSUserDefaults standardUserDefaults
]
3616 stringForKey
: [NSString stringWithUTF8String
: parameter
]]
3621 if (strcasecmp
(value
, "YES"
) == 0)
3623 else if (strcasecmp
(value
, "NO"
) == 0)
3625 else if (is_float
&& (f
= strtod
(value
, &pos
), pos
!= value
))
3626 *result
= make_float
(f
);
3627 else if (is_modstring
&& value
)
3628 *result
= ns_string_to_lispmod
(value
);
3629 else fprintf (stderr
,
3630 "Bad value
for default
\"%s\": \"%s\"\n", parameter, value);
3636 ns_initialize_display_info
(struct ns_display_info
*dpyinfo
)
3637 /* --------------------------------------------------------------------------
3638 Initialize global info and storage for display.
3639 -------------------------------------------------------------------------- */
3641 NSScreen
*screen
= [NSScreen mainScreen
];
3642 NSWindowDepth depth
= [screen depth
];
3644 dpyinfo
->resx
= 72.27; /* used 75.0, but this makes pt == pixel, expected */
3645 dpyinfo
->resy
= 72.27;
3646 dpyinfo
->color_p
= ![NSDeviceWhiteColorSpace isEqualToString
:
3647 NSColorSpaceFromDepth
(depth
)]
3648 && ![NSCalibratedWhiteColorSpace isEqualToString
:
3649 NSColorSpaceFromDepth
(depth
)];
3650 dpyinfo
->n_planes
= NSBitsPerPixelFromDepth
(depth
);
3651 dpyinfo
->image_cache
= make_image_cache
();
3652 dpyinfo
->color_table
3653 = (struct ns_color_table
*)xmalloc
(sizeof
(struct ns_color_table
));
3654 dpyinfo
->color_table
->colors
= NULL;
3655 dpyinfo
->root_window
= 42; /* a placeholder.. */
3657 dpyinfo
->mouse_face_mouse_frame
= NULL;
3658 dpyinfo
->mouse_face_deferred_gc
= 0;
3659 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
3660 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
3661 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
3662 dpyinfo
->mouse_face_window
= dpyinfo
->mouse_face_overlay
= Qnil
;
3663 dpyinfo
->mouse_face_hidden
= 0;
3665 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
3666 dpyinfo
->mouse_face_defer
= 0;
3668 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
= NULL;
3670 dpyinfo
->n_fonts
= 0;
3671 dpyinfo
->smallest_font_height
= 1;
3672 dpyinfo
->smallest_char_width
= 1;
3676 /* This and next define (many of the) public functions in this file. */
3677 /* x_... are generic versions in xdisp.c that we, and other terms, get away
3678 with using despite presence in the "system dependent" redisplay
3679 interface. In addition, many of the ns_ methods have code that is
3680 shared with all terms, indicating need for further refactoring. */
3681 extern frame_parm_handler ns_frame_parm_handlers
[];
3682 static
struct redisplay_interface ns_redisplay_interface
=
3684 ns_frame_parm_handlers
,
3688 x_clear_end_of_line
,
3690 ns_after_update_window_line
,
3691 ns_update_window_begin
,
3692 ns_update_window_end
,
3695 0, /* flush_display_optional */
3696 x_clear_window_mouse_face
,
3697 x_get_glyph_overhangs
,
3698 x_fix_overlapping_area
,
3699 ns_draw_fringe_bitmap
,
3700 0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
3701 0, /* destroy_fringe_bitmap */
3702 ns_compute_glyph_string_overhangs
,
3703 ns_draw_glyph_string
, /* interface to nsfont.m */
3704 ns_define_frame_cursor
,
3705 ns_clear_frame_area
,
3706 ns_draw_window_cursor
,
3707 ns_draw_vertical_window_border
,
3708 ns_shift_glyphs_for_insert
3713 ns_delete_display
(struct ns_display_info
*dpyinfo
)
3719 /* This function is called when the last frame on a display is deleted. */
3721 ns_delete_terminal
(struct terminal *terminal)
3723 struct ns_display_info
*dpyinfo
= terminal->display_info.ns
;
3726 /* Protect against recursive calls. delete_frame in
3727 delete_terminal calls us back when it deletes our last frame. */
3728 if (!terminal->name
)
3733 x_destroy_all_bitmaps
(dpyinfo
);
3734 ns_delete_display
(dpyinfo
);
3739 static
struct terminal *
3740 ns_create_terminal
(struct ns_display_info
*dpyinfo
)
3741 /* --------------------------------------------------------------------------
3742 Set up use of NS before we make the first connection.
3743 -------------------------------------------------------------------------- */
3745 struct terminal *terminal;
3747 NSTRACE
(ns_create_terminal
);
3749 terminal = create_terminal
();
3751 terminal->type = output_ns
;
3752 terminal->display_info.ns
= dpyinfo
;
3753 dpyinfo
->terminal = terminal;
3755 terminal->rif
= &ns_redisplay_interface
;
3757 terminal->clear_frame_hook
= ns_clear_frame
;
3758 terminal->ins_del_lines_hook
= 0; /* XXX vestigial? */
3759 terminal->delete_glyphs_hook
= 0; /* XXX vestigial? */
3760 terminal->ring_bell_hook
= ns_ring_bell
;
3761 terminal->reset_terminal_modes_hook
= ns_reset_terminal_modes
;
3762 terminal->set_terminal_modes_hook
= ns_set_terminal_modes
;
3763 terminal->update_begin_hook
= ns_update_begin
;
3764 terminal->update_end_hook
= ns_update_end
;
3765 terminal->set_terminal_window_hook
= NULL; /* XXX vestigial? */
3766 terminal->read_socket_hook
= ns_read_socket
;
3767 terminal->frame_up_to_date_hook
= ns_frame_up_to_date
;
3768 terminal->mouse_position_hook
= ns_mouse_position
;
3769 terminal->frame_rehighlight_hook
= ns_frame_rehighlight
;
3770 terminal->frame_raise_lower_hook
= ns_frame_raise_lower
;
3772 terminal->fullscreen_hook
= 0; /* see XTfullscreen_hook */
3774 terminal->set_vertical_scroll_bar_hook
= ns_set_vertical_scroll_bar
;
3775 terminal->condemn_scroll_bars_hook
= ns_condemn_scroll_bars
;
3776 terminal->redeem_scroll_bar_hook
= ns_redeem_scroll_bar
;
3777 terminal->judge_scroll_bars_hook
= ns_judge_scroll_bars
;
3779 terminal->delete_frame_hook
= x_destroy_window
;
3780 terminal->delete_terminal_hook
= ns_delete_terminal
;
3782 terminal->scroll_region_ok
= 1;
3783 terminal->char_ins_del_ok
= 1;
3784 terminal->line_ins_del_ok
= 1;
3785 terminal->fast_clear_end_of_line
= 1;
3786 terminal->memory_below_frame
= 0;
3792 struct ns_display_info
*
3793 ns_term_init
(Lisp_Object display_name
)
3794 /* --------------------------------------------------------------------------
3795 Start the Application and get things rolling.
3796 -------------------------------------------------------------------------- */
3798 struct terminal *terminal;
3799 struct ns_display_info
*dpyinfo
;
3800 static int ns_initialized
= 0;
3803 NSTRACE
(ns_term_init
);
3805 /* count object allocs (About, click icon); on OS X use ObjectAlloc tool */
3806 /*GSDebugAllocationActive (YES); */
3808 handling_signal
= 0;
3810 if (!ns_initialized
)
3813 Fset_input_interrupt_mode
(Qnil
);
3817 ns_pending_files
= [[NSMutableArray alloc
] init
];
3818 ns_pending_service_names
= [[NSMutableArray alloc
] init
];
3819 ns_pending_service_args
= [[NSMutableArray alloc
] init
];
3821 /* Start app and create the main menu, window, view.
3822 Needs to be here because ns_initialize_display_info () uses AppKit classes.
3823 The view will then ask the NSApp to stop and return to Emacs. */
3824 [EmacsApp sharedApplication
];
3827 [NSApp setDelegate
: NSApp
];
3829 /* debugging: log all notifications */
3830 /* [[NSNotificationCenter defaultCenter] addObserver: NSApp
3831 selector: @selector (logNotification:)
3832 name: nil object: nil]; */
3834 dpyinfo
= (struct ns_display_info
*)xmalloc
(sizeof
(struct ns_display_info
));
3835 bzero
(dpyinfo
, sizeof
(struct ns_display_info
));
3837 ns_initialize_display_info
(dpyinfo
);
3838 terminal = ns_create_terminal
(dpyinfo
);
3840 terminal->kboard
= (KBOARD
*) xmalloc
(sizeof
(KBOARD
));
3841 init_kboard
(terminal->kboard
);
3842 terminal->kboard
->Vwindow_system
= Qns
;
3843 terminal->kboard
->next_kboard
= all_kboards
;
3844 all_kboards
= terminal->kboard
;
3845 /* Don't let the initial kboard remain current longer than necessary.
3846 That would cause problems if a file loaded on startup tries to
3847 prompt in the mini-buffer. */
3848 if (current_kboard
== initial_kboard
)
3849 current_kboard
= terminal->kboard
;
3850 terminal->kboard
->reference_count
++;
3852 dpyinfo
->next
= x_display_list
;
3853 x_display_list
= dpyinfo
;
3855 /* Put it on ns_display_name_list */
3856 ns_display_name_list
= Fcons
(Fcons
(display_name
, Qnil
),
3857 ns_display_name_list
);
3858 dpyinfo
->name_list_element
= XCAR
(ns_display_name_list
);
3860 /* Set the name of the terminal. */
3861 terminal->name
= (char *) xmalloc
(SBYTES
(display_name
) + 1);
3862 strncpy
(terminal->name
, SDATA
(display_name
), SBYTES
(display_name
));
3863 terminal->name
[SBYTES
(display_name
)] = 0;
3867 /* Read various user defaults. */
3868 ns_set_default_prefs
();
3869 if (!ns_no_defaults
)
3871 ns_default
("GSFontAntiAlias"
, &ns_antialias_text
,
3874 /* this is a standard variable */
3875 ns_default
("AppleAntiAliasingThreshold"
, &tmp
,
3876 make_float
(10.0), make_float
(6.0), YES
, NO
);
3877 ns_antialias_threshold
= NILP
(tmp
) ?
10.0 : XFLOATINT
(tmp
);
3880 ns_selection_color
= [[NSUserDefaults standardUserDefaults
]
3881 stringForKey
: @"AppleHighlightColor"
];
3882 if (ns_selection_color
== nil
)
3883 ns_selection_color
= NS_SELECTION_COLOR_DEFAULT
;
3886 NSColorList
*cl
= [NSColorList colorListNamed
: @"Emacs"
];
3890 Lisp_Object color_file
, color_map
, color
;
3895 color_file
= Fexpand_file_name
(build_string
("rgb.txt"
),
3896 Fsymbol_value
(intern
("data
-directory"
)));
3897 if (NILP
(Ffile_readable_p
(color_file
)))
3898 fatal
("Could not
find %s.\n", SDATA (color_file));
3900 color_map
= Fx_load_color_file
(color_file
);
3901 if (NILP
(color_map
))
3902 fatal
("Could not read
%s.\n", SDATA (color_file));
3904 cl
= [[NSColorList alloc
] initWithName
: @"Emacs"
];
3905 for ( ; CONSP
(color_map
); color_map
= XCDR
(color_map
))
3907 color
= XCAR
(color_map
);
3908 name
= SDATA
(XCAR
(color
));
3909 c
= XINT
(XCDR
(color
));
3911 [NSColor colorWithCalibratedRed
: RED_FROM_ULONG
(c
) / 255.0
3912 green
: GREEN_FROM_ULONG
(c
) / 255.0
3913 blue
: BLUE_FROM_ULONG
(c
) / 255.0
3915 forKey
: [NSString stringWithUTF8String
: name
]];
3917 [cl writeToFile
: nil
];
3923 #ifdef NS_IMPL_GNUSTEP
3924 strncpy
(c
, gnustep_base_version
, sizeof
(c
));
3926 /*PSnextrelease (128, c); */
3927 snprintf
(c
, sizeof
(c
), "
%g", NSAppKitVersionNumber);
3929 Vwindow_system_version
= build_string
(c
);
3932 delete_keyboard_wait_descriptor
(0);
3934 /* Set up OS X app menu */
3935 #ifdef NS_IMPL_COCOA
3939 /* set up the application menu */
3940 svcsMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Services"
];
3941 [svcsMenu setAutoenablesItems
: NO
];
3942 appMenu
= [[EmacsMenu alloc
] initWithTitle
: @"Emacs"
];
3943 [appMenu setAutoenablesItems
: NO
];
3944 mainMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
3945 dockMenu
= [[EmacsMenu alloc
] initWithTitle
: @""
];
3947 [appMenu insertItemWithTitle
: @"About Emacs"
3948 action
: @selector
(orderFrontStandardAboutPanel
:)
3951 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 1];
3952 [appMenu insertItemWithTitle
: @"Preferences..."
3953 action
: @selector
(showPreferencesWindow
:)
3956 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 3];
3957 item
= [appMenu insertItemWithTitle
: @"Services"
3958 action
: @selector
(menuDown
:)
3961 [appMenu setSubmenu
: svcsMenu forItem
: item
];
3962 /* [svcsMenu setSupercell: item]; */
3963 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 5];
3964 [appMenu insertItemWithTitle
: @"Hide Emacs"
3965 action
: @selector
(hide
:)
3968 item
= [appMenu insertItemWithTitle
: @"Hide Others"
3969 action
: @selector
(hideOtherApplications
:)
3972 [item setKeyEquivalentModifierMask
: NSCommandKeyMask | NSAlternateKeyMask
];
3973 [appMenu insertItem
: [NSMenuItem separatorItem
] atIndex
: 8];
3974 [appMenu insertItemWithTitle
: @"
Quit Emacs"
3975 action
: @selector
(terminate
:)
3979 item
= [mainMenu insertItemWithTitle
: @"Emacs"
3980 action
: @selector
(menuDown
:)
3983 [mainMenu setSubmenu
: appMenu forItem
: item
];
3984 [dockMenu insertItemWithTitle
: @"New Frame"
3985 action
: @selector
(newFrame
:)
3989 [NSApp setMainMenu
: mainMenu
];
3990 [NSApp setAppleMenu
: appMenu
];
3991 [NSApp setServicesMenu
: svcsMenu
];
3992 /* Needed at least on Cocoa, to get dock menu to show windows */
3993 [NSApp setWindowsMenu
: [[NSMenu alloc
] init
]];
3995 #endif
/* MAC OS X menu setup */
4003 extern Lisp_Object Vauto_save_list_file_name
;
4005 ns_term_shutdown
(int sig
)
4007 /* code not reached in emacs.c after this is called by shut_down_emacs: */
4008 if (STRINGP
(Vauto_save_list_file_name
))
4009 unlink
(SDATA
(Vauto_save_list_file_name
));
4011 if (sig
== 0 || sig
== SIGTERM
)
4013 [NSApp terminate
: NSApp
];
4015 else // force a stack
trace to happen
4022 /* ==========================================================================
4024 EmacsApp implementation
4026 ========================================================================== */
4029 @implementation EmacsApp
4031 - (void
)logNotification
: (NSNotification
*)notification
4033 const
char *name
= [[notification name
] UTF8String
];
4034 if (!strstr
(name
, "Update"
) && !strstr
(name
, "NSMenu"
)
4035 && !strstr
(name
, "WindowNumber"
))
4036 NSLog
(@"notification
: '%@'"
, [notification name
]);
4040 - (void
)sendEvent
: (NSEvent
*)theEvent
4041 /* --------------------------------------------------------------------------
4042 Called when NSApp is running for each event received. Used to stop
4043 the loop when we choose, since there's no way to just run one iteration.
4044 -------------------------------------------------------------------------- */
4046 int
type = [theEvent
type];
4047 NSWindow
*window
= [theEvent window
];
4048 /* NSTRACE (sendEvent); */
4049 /*fprintf (stderr, "received event of type %d\t%d\n", type);*/
4051 if (type == NSCursorUpdate
&& window
== nil
)
4053 fprintf (stderr
, "Dropping external cursor update event.
\n"
);
4057 #ifdef NS_IMPL_COCOA
4058 /* pass mouse down in resize handle and subsequent drags directly to
4059 EmacsWindow so we can generate continuous redisplays */
4062 if (type == NSLeftMouseDragged
)
4064 [window mouseDragged
: theEvent
];
4067 else if (type == NSLeftMouseUp
)
4069 [window mouseUp
: theEvent
];
4073 else if (type == NSLeftMouseDown
)
4075 NSRect r
= ns_resize_handle_rect
(window
);
4076 if (NSPointInRect
([theEvent locationInWindow
], r
))
4079 [window mouseDown
: theEvent
];
4085 if (type == NSApplicationDefined
)
4087 /* Events posted by ns_send_appdefined interrupt the run loop here.
4088 But, if a modal window is up, an appdefined can still come through,
4089 (e.g., from a makeKeyWindow event) but stopping self also stops the
4090 modal loop. Just defer it until later. */
4091 if ([NSApp modalWindow
] == nil
)
4093 last_appdefined_event
= theEvent
;
4098 send_appdefined
= YES
;
4102 [super sendEvent
: theEvent
];
4106 - (void
)showPreferencesWindow
: (id
)sender
4108 struct frame
*emacsframe
= SELECTED_FRAME
();
4109 NSEvent
*theEvent
= [NSApp currentEvent
];
4113 emacs_event
->kind
= NS_NONKEY_EVENT
;
4114 emacs_event
->code
= KEY_NS_SHOW_PREFS
;
4115 emacs_event
->modifiers
= 0;
4116 EV_TRAILER
(theEvent
);
4120 - (void
)newFrame
: (id
)sender
4122 struct frame
*emacsframe
= SELECTED_FRAME
();
4123 NSEvent
*theEvent
= [NSApp currentEvent
];
4127 emacs_event
->kind
= NS_NONKEY_EVENT
;
4128 emacs_event
->code
= KEY_NS_NEW_FRAME
;
4129 emacs_event
->modifiers
= 0;
4130 EV_TRAILER
(theEvent
);
4134 /* Open a file (used by below, after going into queue read by ns_read_socket) */
4135 - (BOOL
) openFile
: (NSString
*)fileName
4137 struct frame
*emacsframe
= SELECTED_FRAME
();
4138 NSEvent
*theEvent
= [NSApp currentEvent
];
4143 emacs_event
->kind
= NS_NONKEY_EVENT
;
4144 emacs_event
->code
= KEY_NS_OPEN_FILE_LINE
;
4145 ns_input_file
= append2
(ns_input_file
, build_string
([fileName UTF8String
]));
4146 ns_input_line
= Qnil
; /* can be start or cons start,end */
4147 emacs_event
->modifiers
=0;
4148 EV_TRAILER
(theEvent
);
4154 /* **************************************************************************
4156 EmacsApp delegate implementation
4158 ************************************************************************** */
4160 - (void
)applicationDidFinishLaunching
: (NSNotification
*)notification
4161 /* --------------------------------------------------------------------------
4162 When application is loaded, terminate event loop in ns_term_init
4163 -------------------------------------------------------------------------- */
4165 NSTRACE
(applicationDidFinishLaunching
);
4166 [NSApp setServicesProvider
: NSApp
];
4167 ns_send_appdefined
(-2);
4171 /* Termination sequences:
4174 MenuBar | File | Exit:
4175 Select Quit from App menubar:
4177 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4180 Select Quit from Dock menu:
4183 Cancel -> Nothing else
4187 KEY_NS_POWER_OFF, (save-buffers-kill-emacs)
4192 - (void
) terminate
: (id
)sender
4194 struct frame
*emacsframe
= SELECTED_FRAME
();
4199 emacs_event
->kind
= NS_NONKEY_EVENT
;
4200 emacs_event
->code
= KEY_NS_POWER_OFF
;
4201 emacs_event
->arg
= Qt
; /* mark as non-key event */
4202 EV_TRAILER
((id
)nil
);
4206 - (NSApplicationTerminateReply
)applicationShouldTerminate
: (id
)sender
4210 if (NILP
(ns_confirm_quit
)) // || ns_shutdown_properly
--> TO DO
4211 return NSTerminateNow
;
4213 ret
= NSRunAlertPanel
([[NSProcessInfo processInfo
] processName
],
4214 [NSString stringWithUTF8String
:"Exit requested. Would you like to
Save Buffers and Exit
, or Cancel the request?"
],
4215 @"
Save Buffers and Exit"
, @"Cancel"
, nil
);
4217 if (ret
== NSAlertDefaultReturn
)
4218 return NSTerminateNow
;
4219 else if (ret
== NSAlertAlternateReturn
)
4220 return NSTerminateCancel
;
4221 return NSTerminateNow
; /* just in case */
4225 /* Notification from the Workspace to open a file */
4226 - (BOOL
)application
: sender openFile
: (NSString
*)file
4228 [ns_pending_files addObject
: file
];
4233 /* Open a file as a temporary file */
4234 - (BOOL
)application
: sender openTempFile
: (NSString
*)file
4236 [ns_pending_files addObject
: file
];
4241 /* Notification from the Workspace to open a file noninteractively (?) */
4242 - (BOOL
)application
: sender openFileWithoutUI
: (NSString
*)file
4244 [ns_pending_files addObject
: file
];
4249 /* Notification from the Workspace to open multiple files */
4250 - (void
)application
: sender openFiles
: (NSArray
*)fileList
4252 NSEnumerator
*files
= [fileList objectEnumerator
];
4254 while ((file
= [files nextObject
]) != nil
)
4255 [ns_pending_files addObject
: file
];
4257 /* TODO: when GNUstep implements this (and we require that version of
4258 GNUstep), remove. */
4259 #ifndef NS_IMPL_GNUSTEP
4260 [self replyToOpenOrPrint
: NSApplicationDelegateReplySuccess
];
4261 #endif
/* !NS_IMPL_GNUSTEP */
4266 /* Handle dock menu requests. */
4267 - (NSMenu
*)applicationDockMenu
: (NSApplication
*) sender
4273 /* TODO: these may help w/IO switching btwn terminal and NSApp */
4274 - (void
)applicationWillBecomeActive
: (NSNotification
*)notification
4276 //ns_app_active
=YES
;
4278 - (void
)applicationDidBecomeActive
: (NSNotification
*)notification
4280 //ns_app_active
=YES
;
4282 - (void
)applicationDidResignActive
: (NSNotification
*)notification
4285 ns_send_appdefined
(-1);
4290 /* ==========================================================================
4292 EmacsApp aux handlers for managing event loop
4294 ========================================================================== */
4297 - (void
)timeout_handler
: (NSTimer
*)timedEntry
4298 /* --------------------------------------------------------------------------
4299 The timeout specified to ns_select has passed.
4300 -------------------------------------------------------------------------- */
4302 /*NSTRACE (timeout_handler); */
4303 ns_send_appdefined
(-2);
4306 extern void update_window_cursor
(struct window
*w
, int on
);
4308 - (void
)fd_handler
: (NSTimer
*) fdEntry
4309 /* --------------------------------------------------------------------------
4310 Check data waiting on file descriptors and terminate if so
4311 -------------------------------------------------------------------------- */
4314 /* NSTRACE (fd_handler); */
4316 if (select_nfds
== 0)
4319 memcpy
(&t_readfds
, &select_readfds
, sizeof
(fd_set
));
4321 select_timeout.tv_sec
= select_timeout.tv_usec
= 0;
4322 result
= select
(select_nfds
, &t_readfds
, (SELECT_TYPE
*)0, (SELECT_TYPE
*)0,
4326 memcpy
(&select_readfds
, &t_readfds
, sizeof
(fd_set
));
4327 ns_send_appdefined
(result
);
4333 /* ==========================================================================
4337 ========================================================================== */
4339 /* called from system: queue for next pass through event loop */
4340 - (void
)requestService
: (NSPasteboard
*)pboard
4341 userData
: (NSString
*)userData
4342 error: (NSString
**)error
4344 [ns_pending_service_names addObject
: userData
];
4345 [ns_pending_service_args addObject
: [NSString stringWithUTF8String
:
4346 SDATA
(ns_string_from_pasteboard
(pboard
))]];
4350 /* called from ns_read_socket to clear queue */
4351 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
4353 struct frame
*emacsframe
= SELECTED_FRAME
();
4354 NSEvent
*theEvent
= [NSApp currentEvent
];
4359 emacs_event
->kind
= NS_NONKEY_EVENT
;
4360 emacs_event
->code
= KEY_NS_SPI_SERVICE_CALL
;
4361 ns_input_spi_name
= build_string
([name UTF8String
]);
4362 ns_input_spi_arg
= build_string
([arg UTF8String
]);
4363 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
4364 EV_TRAILER
(theEvent
);
4374 /* ==========================================================================
4376 EmacsView implementation
4378 ========================================================================== */
4381 @implementation EmacsView
4383 /* needed to inform when window closed from LISP */
4384 - (void
) setWindowClosing
: (BOOL
)closing
4386 windowClosing
= closing
;
4392 NSTRACE
(EmacsView_dealloc
);
4398 /* called on font panel selection */
4399 - (void
)changeFont
: (id
)sender
4401 NSEvent
*e
=[[self window
] currentEvent
];
4402 struct face
*face
=FRAME_DEFAULT_FACE
(emacsframe
);
4406 NSTRACE
(changeFont
);
4410 if (newFont
= [sender convertFont
:
4411 ((struct nsfont_info
*)face
->font
)->nsfont
])
4413 SET_FRAME_GARBAGED
(emacsframe
); /* now needed as of 2008/10 */
4415 emacs_event
->kind
= NS_NONKEY_EVENT
;
4416 emacs_event
->modifiers
= 0;
4417 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
4419 size = [newFont pointSize
];
4420 ns_input_fontsize
= make_number
(lrint
(size));
4421 ns_input_font
= build_string
([[newFont familyName
] UTF8String
]);
4427 - (BOOL
)acceptsFirstResponder
4429 NSTRACE
(acceptsFirstResponder
);
4434 - (void
)resetCursorRects
4436 NSRect visible
= [self visibleRect
];
4437 NSCursor
*currentCursor
= FRAME_POINTER_TYPE
(emacsframe
);
4438 NSTRACE
(resetCursorRects
);
4440 if (currentCursor
== nil
)
4441 currentCursor
= [NSCursor arrowCursor
];
4443 if (!NSIsEmptyRect
(visible
))
4444 [self addCursorRect
: visible cursor
: currentCursor
];
4445 [currentCursor setOnMouseEntered
: YES
];
4450 /*****************************************************************************/
4451 /* Keyboard handling. */
4454 - (void
)keyDown
: (NSEvent
*)theEvent
4456 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
4458 unsigned fnKeysym
= 0;
4460 static NSMutableArray
*nsEvArray
;
4461 static BOOL firstTime
= YES
;
4465 /* Rhapsody and OS X give up and down events for the arrow keys */
4466 if (ns_fake_keydown
== YES
)
4467 ns_fake_keydown
= NO
;
4468 else if ([theEvent
type] != NSKeyDown
)
4474 if (![[self window
] isKeyWindow
]
4475 && [[theEvent window
] isKindOfClass
: [EmacsWindow
class]]
4476 /* we must avoid an infinite loop here. */
4477 && (EmacsView
*)[[theEvent window
] delegate
] != self
)
4479 /* XXX: There is an occasional condition in which, when Emacs display
4480 updates a different frame from the current one, and temporarily
4481 selects it, then processes some interrupt-driven input
4482 (dispnew.c:3878), OS will send the event to the correct NSWindow, but
4483 for some reason that window has its first responder set to the NSView
4484 most recently updated (I guess), which is not the correct one. */
4485 [(EmacsView
*)[[theEvent window
] delegate
] keyDown
: theEvent
];
4489 if (nsEvArray
== nil
)
4490 nsEvArray
= [[NSMutableArray alloc
] initWithCapacity
: 1];
4492 [NSCursor setHiddenUntilMouseMoves
: YES
];
4494 if (dpyinfo
->mouse_face_hidden
&& INTEGERP
(Vmouse_highlight
))
4496 clear_mouse_face
(dpyinfo
);
4497 dpyinfo
->mouse_face_hidden
= 1;
4500 if (!processingCompose
)
4502 code
= ([[theEvent charactersIgnoringModifiers
] length] == 0) ?
4503 0 : [[theEvent charactersIgnoringModifiers
] characterAtIndex
: 0];
4504 /* (Carbon way: [theEvent keyCode]) */
4506 /* is it a "function key"? */
4507 fnKeysym
= ns_convert_key
(code
);
4510 /* COUNTERHACK: map 'Delete' on upper-right main KB to 'Backspace',
4511 because Emacs treats Delete and KP-Delete same (in simple.el). */
4512 if (fnKeysym
== 0xFFFF && [theEvent keyCode
] == 0x33)
4513 code
= 0xFF08; /* backspace */
4518 /* are there modifiers? */
4519 emacs_event
->modifiers
= 0;
4520 flags
= [theEvent modifierFlags
];
4522 if (flags
& NSHelpKeyMask
)
4523 emacs_event
->modifiers |
= hyper_modifier
;
4525 if (flags
& NSShiftKeyMask
)
4526 emacs_event
->modifiers |
= shift_modifier
;
4528 if (flags
& NSCommandKeyMask
)
4530 emacs_event
->modifiers |
= parse_solitary_modifier
(ns_command_modifier
);
4531 /* if super (default), take input manager's word so things like
4532 dvorak / qwerty layout work */
4533 if (EQ
(ns_command_modifier
, Qsuper
)
4535 && [[theEvent characters
] length] != 0)
4537 /* XXX: the code we get will be unshifted, so if we have
4538 a shift modifier, must convert ourselves */
4539 if (!(flags
& NSShiftKeyMask
))
4540 code
= [[theEvent characters
] characterAtIndex
: 0];
4542 /* this is ugly and also requires linking w/Carbon framework
4543 (for LMGetKbdType) so for now leave this rare (?) case
4544 undealt with.. in future look into CGEvent methods */
4547 long smv
= GetScriptManagerVariable
(smKeyScript
);
4548 Handle uchrHandle
= GetResource
4549 ('uchr', GetScriptVariable
(smv
, smScriptKeys
));
4551 UCKeyTranslate
((UCKeyboardLayout
*)*uchrHandle
,
4552 [[theEvent characters
] characterAtIndex
: 0],
4553 kUCKeyActionDisplay
,
4554 (flags
& ~NSCommandKeyMask
) >> 8,
4555 LMGetKbdType
(), kUCKeyTranslateNoDeadKeysMask
,
4556 &dummy
, 1, &dummy
, &code
);
4563 if (flags
& NSControlKeyMask
)
4564 emacs_event
->modifiers |
=
4565 parse_solitary_modifier
(ns_control_modifier
);
4567 if (flags
& NS_FUNCTION_KEY_MASK
&& !fnKeysym
)
4568 emacs_event
->modifiers |
=
4569 parse_solitary_modifier
(ns_function_modifier
);
4571 if (flags
& NSAlternateKeyMask
) /* default = meta */
4573 if ((NILP
(ns_alternate_modifier
) || EQ
(ns_alternate_modifier
, Qnone
))
4575 { /* accept pre-interp alt comb */
4576 if ([[theEvent characters
] length] > 0)
4577 code
= [[theEvent characters
] characterAtIndex
: 0];
4578 /*HACK: clear lone shift modifier to stop next if from firing */
4579 if (emacs_event
->modifiers
== shift_modifier
)
4580 emacs_event
->modifiers
= 0;
4583 emacs_event
->modifiers |
=
4584 parse_solitary_modifier
(ns_alternate_modifier
);
4588 fprintf (stderr
, "keyDown
: code
=%x\tfnKey =%x\tflags = %x\tmods = %x\n",
4589 code
, fnKeysym
, flags
, emacs_event
->modifiers
);
4591 /* if it was a function key or had modifiers, pass it directly to emacs */
4592 if (fnKeysym ||
(emacs_event
->modifiers
4593 && [[theEvent charactersIgnoringModifiers
] length] > 0))
4594 /*[[theEvent characters] length] */
4596 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4598 code |
= (1<<28)|
(3<<16);
4599 else if (code
== 0x7f)
4600 code |
= (1<<28)|
(3<<16);
4602 emacs_event
->kind
= code
> 0xFF
4603 ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4605 emacs_event
->code
= code
;
4606 EV_TRAILER
(theEvent
);
4611 /* if we get here we should send the key for input manager processing */
4612 if (firstTime
&& [[NSInputManager currentInputManager
]
4613 wantsToDelayTextChangeNotifications
] == NO
)
4615 "Emacs
: WARNING
: TextInput mgr wants marked
text to be permanent
!\n"
);
4618 if (NS_KEYLOG
&& !processingCompose
)
4619 fprintf (stderr
, "keyDown
: Begin compose sequence.
\n"
);
4621 processingCompose
= YES
;
4622 [nsEvArray addObject
: theEvent
];
4623 [self interpretKeyEvents
: nsEvArray
];
4624 [nsEvArray removeObject
: theEvent
];
4628 #ifdef NS_IMPL_COCOA
4629 /* Needed to pick up Ctrl-tab and possibly other events that OS X has
4630 decided not to send key-down for.
4631 See http://osdir.com/ml/editors.vim.mac/2007-10/msg00141.html
4632 If it matches one of these, send it on to keyDown. */
4633 -(void
)keyUp
: (NSEvent
*)theEvent
4635 int flags
= [theEvent modifierFlags
];
4636 int code
= [theEvent keyCode
];
4637 if (code
== 0x30 && (flags
& NSControlKeyMask
) && !(flags
& NSCommandKeyMask
))
4640 fprintf (stderr
, "keyUp
: passed test"
);
4641 ns_fake_keydown
= YES
;
4642 [self keyDown
: theEvent
];
4648 /* <NSTextInput> implementation (called through super interpretKeyEvents:]). */
4651 /* <NSTextInput>: called when done composing;
4652 NOTE: also called when we delete over working text, followed immed.
4653 by doCommandBySelector: deleteBackward: */
4654 - (void
)insertText
: (id
)aString
4657 int len
= [(NSString
*)aString
length];
4661 NSLog
(@"insertText
'%@'\tlen
= %d", aString, len);
4662 processingCompose
= NO
;
4667 /* first, clear any working text */
4668 if (workingText
!= nil
)
4669 [self deleteWorkingText
];
4671 /* now insert the string as keystrokes */
4672 for (i
=0; i
<len
; i
++)
4674 code
= [aString characterAtIndex
: i
];
4675 /* TODO: still need this? */
4677 code
= '~'; /* 0x7E */
4678 emacs_event
->modifiers
= 0;
4680 = code
> 0xFF ? MULTIBYTE_CHAR_KEYSTROKE_EVENT
: ASCII_KEYSTROKE_EVENT
;
4681 emacs_event
->code
= code
;
4682 EV_TRAILER
((id
)nil
);
4687 /* <NSTextInput>: inserts display of composing characters */
4688 - (void
)setMarkedText
: (id
)aString selectedRange
: (NSRange
)selRange
4690 NSString
*str
= [aString respondsToSelector
: @selector
(string
)] ?
4691 [aString string
] : aString
;
4693 NSLog
(@"setMarkedText
'%@' len
=%d range %d from %d", str, [str length],
4694 selRange.
length, selRange.location
);
4696 if (workingText
!= nil
)
4697 [self deleteWorkingText
];
4698 if ([str
length] == 0)
4704 processingCompose
= YES
;
4705 workingText
= [str copy
];
4706 ns_working_text
= build_string
([workingText UTF8String
]);
4708 emacs_event
->kind
= NS_TEXT_EVENT
;
4709 emacs_event
->code
= KEY_NS_PUT_WORKING_TEXT
;
4710 EV_TRAILER
((id
)nil
);
4714 /* delete display of composing characters [not in <NSTextInput>] */
4715 - (void
)deleteWorkingText
4717 if (workingText
== nil
)
4720 NSLog
(@"deleteWorkingText len
=%d\n", [workingText length]);
4721 [workingText release
];
4723 processingCompose
= NO
;
4728 emacs_event
->kind
= NS_TEXT_EVENT
;
4729 emacs_event
->code
= KEY_NS_UNPUT_WORKING_TEXT
;
4730 EV_TRAILER
((id
)nil
);
4734 - (BOOL
)hasMarkedText
4736 return workingText
!= nil
;
4740 - (NSRange
)markedRange
4742 NSRange rng
= workingText
!= nil
4743 ? NSMakeRange
(0, [workingText
length]) : NSMakeRange
(NSNotFound
, 0);
4745 NSLog
(@"markedRange request"
);
4753 NSLog
(@"unmark
(accept
) text"
);
4754 [self deleteWorkingText
];
4755 processingCompose
= NO
;
4759 /* used to position char selection windows, etc. */
4760 - (NSRect
)firstRectForCharacterRange
: (NSRange
)theRange
4764 struct window
*win
= XWINDOW
(FRAME_SELECTED_WINDOW
(emacsframe
));
4766 NSLog
(@"firstRectForCharRange request"
);
4768 rect.
size.width
= theRange.
length * FRAME_COLUMN_WIDTH
(emacsframe
);
4769 rect.
size.height
= FRAME_LINE_HEIGHT
(emacsframe
);
4770 pt.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X
(win
, win
->phys_cursor.x
);
4771 pt.y
= WINDOW_TO_FRAME_PIXEL_Y
(win
, win
->phys_cursor.y
4772 +FRAME_LINE_HEIGHT
(emacsframe
));
4774 pt
= [self convertPoint
: pt toView
: nil
];
4775 pt
= [[self window
] convertBaseToScreen
: pt
];
4781 - (NSInteger
)conversationIdentifier
4783 return (NSInteger
)self
;
4787 - (void
)doCommandBySelector
: (SEL
)aSelector
4790 NSLog
(@"doCommandBySelector
: %@", NSStringFromSelector (aSelector));
4792 if (aSelector
== @selector
(deleteBackward
:))
4794 /* happens when user backspaces over an ongoing composition:
4795 throw a 'delete' into the event queue */
4798 emacs_event
->kind
= NON_ASCII_KEYSTROKE_EVENT
;
4799 emacs_event
->code
= 0xFF08;
4800 EV_TRAILER
((id
)nil
);
4804 - (NSArray
*)validAttributesForMarkedText
4806 static NSArray
*arr
= nil
;
4807 if (arr
== nil
) arr
= [NSArray new
];
4808 /* [[NSArray arrayWithObject: NSUnderlineStyleAttributeName] retain]; */
4812 - (NSRange
)selectedRange
4815 NSLog
(@"selectedRange request"
);
4816 return NSMakeRange
(NSNotFound
, 0);
4819 - (unsigned int
)characterIndexForPoint
: (NSPoint
)thePoint
4822 NSLog
(@"characterIndexForPoint request"
);
4826 - (NSAttributedString
*)attributedSubstringFromRange
: (NSRange
)theRange
4828 static NSAttributedString
*str
= nil
;
4829 if (str
== nil
) str
= [NSAttributedString new
];
4831 NSLog
(@"attributedSubstringFromRange request"
);
4835 /* End <NSTextInput> impl. */
4836 /*****************************************************************************/
4839 /* This is what happens when the user presses a mouse button. */
4840 - (void
)mouseDown
: (NSEvent
*)theEvent
4842 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
4845 NSTRACE
(mouseDown
);
4847 [self deleteWorkingText
];
4852 last_mouse_frame
= emacsframe
;
4853 /* appears to be needed to prevent spurious movement events generated on
4855 last_mouse_frame
->mouse_moved
= 0;
4857 if ([theEvent
type] == NSScrollWheel
)
4859 float delta
= [theEvent deltaY
];
4860 /* Mac notebooks send wheel events w/delta =0 when trackpad scrolling */
4863 emacs_event
->kind
= WHEEL_EVENT
;
4864 emacs_event
->code
= 0;
4865 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
) |
4866 ((delta
> 0) ? up_modifier
: down_modifier
);
4870 emacs_event
->kind
= MOUSE_CLICK_EVENT
;
4871 emacs_event
->code
= EV_BUTTON
(theEvent
);
4872 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
)
4873 | EV_UDMODIFIERS
(theEvent
);
4875 XSETINT
(emacs_event
->x
, lrint
(p.x
));
4876 XSETINT
(emacs_event
->y
, lrint
(p.y
));
4877 EV_TRAILER
(theEvent
);
4881 - (void
)rightMouseDown
: (NSEvent
*)theEvent
4883 NSTRACE
(rightMouseDown
);
4884 [self mouseDown
: theEvent
];
4888 - (void
)otherMouseDown
: (NSEvent
*)theEvent
4890 NSTRACE
(otherMouseDown
);
4891 [self mouseDown
: theEvent
];
4895 - (void
)mouseUp
: (NSEvent
*)theEvent
4898 [self mouseDown
: theEvent
];
4902 - (void
)rightMouseUp
: (NSEvent
*)theEvent
4904 NSTRACE
(rightMouseUp
);
4905 [self mouseDown
: theEvent
];
4909 - (void
)otherMouseUp
: (NSEvent
*)theEvent
4911 NSTRACE
(otherMouseUp
);
4912 [self mouseDown
: theEvent
];
4916 - (void
) scrollWheel
: (NSEvent
*)theEvent
4918 NSTRACE
(scrollWheel
);
4919 [self mouseDown
: theEvent
];
4923 /* Tell emacs the mouse has moved. */
4924 - (void
)mouseMoved
: (NSEvent
*)e
4926 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
4929 // NSTRACE
(mouseMoved
);
4931 last_mouse_movement_time
= EV_TIMESTAMP
(e
);
4932 last_mouse_motion_position
4933 = [self convertPoint
: [e locationInWindow
] fromView
: nil
];
4935 /* update any mouse face */
4936 if (dpyinfo
->mouse_face_hidden
)
4938 dpyinfo
->mouse_face_hidden
= 0;
4939 clear_mouse_face
(dpyinfo
);
4942 /* tooltip handling */
4943 previous_help_echo_string
= help_echo_string
;
4944 help_echo_string
= Qnil
;
4946 if (!note_mouse_movement
(emacsframe
, last_mouse_motion_position.x
,
4947 last_mouse_motion_position.y
))
4948 help_echo_string
= previous_help_echo_string
;
4950 XSETFRAME
(frame
, emacsframe
);
4951 if (!NILP
(help_echo_string
) ||
!NILP
(previous_help_echo_string
))
4953 /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
4954 (note_mouse_highlight), which is called through the
4955 note_mouse_movement () call above */
4956 gen_help_event
(help_echo_string
, frame
, help_echo_window
,
4957 help_echo_object
, help_echo_pos
);
4961 help_echo_string
= Qnil
;
4962 gen_help_event
(Qnil
, frame
, Qnil
, Qnil
, 0);
4965 if (emacsframe
->mouse_moved
&& send_appdefined
)
4966 ns_send_appdefined
(-1);
4970 - (void
)mouseDragged
: (NSEvent
*)e
4972 NSTRACE
(mouseDragged
);
4973 [self mouseMoved
: e
];
4977 - (void
)rightMouseDragged
: (NSEvent
*)e
4979 NSTRACE
(rightMouseDragged
);
4980 [self mouseMoved
: e
];
4984 - (void
)otherMouseDragged
: (NSEvent
*)e
4986 NSTRACE
(otherMouseDragged
);
4987 [self mouseMoved
: e
];
4991 - (BOOL
)windowShouldClose
: (id
)sender
4993 NSEvent
*e
=[[self window
] currentEvent
];
4995 NSTRACE
(windowShouldClose
);
4996 windowClosing
= YES
;
4999 emacs_event
->kind
= DELETE_WINDOW_EVENT
;
5000 emacs_event
->modifiers
= 0;
5001 emacs_event
->code
= 0;
5003 /* Don't close this window, let this be done from lisp code. */
5008 - (NSSize
)windowWillResize
: (NSWindow
*)sender toSize
: (NSSize
)frameSize
5009 /* normalize frame to gridded text size */
5011 NSTRACE
(windowWillResize
);
5012 /*fprintf (stderr,"Window will resize: %.0f x %.0f\n",frameSize.width,frameSize.height); */
5014 cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS
(emacsframe
,
5015 #ifdef NS_IMPL_GNUSTEP
5016 frameSize.width
+ 3);
5020 if (cols
< MINWIDTH
)
5022 frameSize.width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH
(emacsframe
, cols
);
5024 rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES
(emacsframe
, frameSize.height
5025 #ifdef NS_IMPL_GNUSTEP
5026 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
) + 3
5027 - FRAME_NS_TOOLBAR_HEIGHT
(emacsframe
));
5029 - FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5030 - FRAME_NS_TOOLBAR_HEIGHT
(emacsframe
));
5032 if (rows
< MINHEIGHT
)
5034 frameSize.height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT
(emacsframe
, rows
)
5035 + FRAME_NS_TITLEBAR_HEIGHT
(emacsframe
)
5036 + FRAME_NS_TOOLBAR_HEIGHT
(emacsframe
);
5037 #ifdef NS_IMPL_COCOA
5039 /* this sets window title to have size in it; the wm does this under GS */
5040 NSRect r
= [[self window
] frame
];
5041 if (r.
size.height
== frameSize.height
&& r.
size.width
== frameSize.width
)
5052 NSWindow
*window
= [self window
];
5055 const
char *t
= [[[self window
] title] UTF8String
];
5056 char *pos
= strstr
(t
, " — "
);
5059 old_title
= (char *) xmalloc
(strlen
(t
) + 1);
5060 strcpy
(old_title
, t
);
5062 size_title
= xmalloc
(strlen
(old_title
) + 40);
5063 sprintf (size_title
, "
%s — (%d x %d)", old_title, cols, rows);
5064 [window setTitle
: [NSString stringWithUTF8String
: size_title
]];
5069 #endif
/* NS_IMPL_COCOA */
5070 /*fprintf (stderr," ...size became %.0f x %.0f (%d x %d)\n",frameSize.width,frameSize.height,cols,rows); */
5076 - (void
)windowDidResize
: (NSNotification
*)notification
5078 NSWindow
*theWindow
= [notification object
];
5080 #ifdef NS_IMPL_GNUSTEP
5081 /* in GNUstep, at least currently, it's possible to get a didResize
5082 without getting a willResize.. therefore we need to act as if we got
5083 the willResize now */
5084 NSSize sz
= [theWindow frame
].
size;
5085 sz
= [self windowWillResize
: theWindow toSize
: sz
];
5086 #endif
/* NS_IMPL_GNUSTEP */
5088 NSTRACE
(windowDidResize
);
5089 /*fprintf (stderr,"windowDidResize: %.0f\n",[theWindow frame].size.height); */
5091 #ifdef NS_IMPL_COCOA
5097 #endif
/* NS_IMPL_COCOA */
5099 // Calling x_set_window_size tends to
get us into inf
-loops
5100 // (x_set_window_size causes a resize
which causes
5101 // a "windowDidResize"
which calls x_set_window_size
).
5102 // At least with GNUStep
, don
't know about MacOSX. --Stef
5103 #ifndef NS_IMPL_GNUSTEP
5104 if (cols > 0 && rows > 0)
5105 x_set_window_size (emacsframe, 0, cols, rows);
5108 ns_send_appdefined (-1);
5112 - (void)windowDidBecomeKey: (NSNotification *)notification
5113 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5115 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (emacsframe);
5116 struct frame *old_focus = dpyinfo->x_focus_frame;
5118 NSTRACE (windowDidBecomeKey);
5120 if (emacsframe != old_focus)
5121 dpyinfo->x_focus_frame = emacsframe;
5123 ns_frame_rehighlight (emacsframe);
5127 emacs_event->kind = FOCUS_IN_EVENT;
5128 EV_TRAILER ((id)nil);
5133 - (void)windowDidResignKey: (NSNotification *)notification
5134 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
5136 struct ns_display_info *dpyinfo = FRAME_NS_DISPLAY_INFO (emacsframe);
5137 NSTRACE (windowDidResignKey);
5139 if (dpyinfo->x_focus_frame == emacsframe)
5140 dpyinfo->x_focus_frame = 0;
5142 ns_frame_rehighlight (emacsframe);
5144 /* FIXME: for some reason needed on second and subsequent clicks away
5145 from sole-frame Emacs to get hollow box to show */
5146 if (!windowClosing && [[self window] isVisible] == YES)
5148 x_update_cursor (emacsframe, 1);
5149 x_set_frame_alpha (emacsframe);
5154 [self deleteWorkingText];
5155 emacs_event->kind = FOCUS_IN_EVENT;
5156 EV_TRAILER ((id)nil);
5161 - (void)windowWillMiniaturize: sender
5163 NSTRACE (windowWillMiniaturize);
5179 - initFrameFromEmacs: (struct frame *)f
5184 NSButton *toggleButton;
5185 int vbextra = NS_SCROLL_BAR_WIDTH (f);
5190 NSTRACE (initFrameFromEmacs);
5193 processingCompose = NO;
5194 scrollbarsNeedingUpdate = 0;
5196 /*fprintf (stderr,"init with %d, %d\n",f->text_cols, f->text_lines); */
5198 r = NSMakeRect (0, 0, FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, f->text_cols),
5199 FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, f->text_lines));
5200 [self initWithFrame: r];
5202 FRAME_NS_VIEW (f) = self;
5206 win = [[EmacsWindow alloc]
5207 initWithContentRect: r
5208 styleMask: (NSResizableWindowMask |
5209 NSMiniaturizableWindowMask |
5210 NSClosableWindowMask)
5211 backing: NSBackingStoreBuffered
5215 f->border_width = wr.size.width - r.size.width;
5216 FRAME_NS_TITLEBAR_HEIGHT (f) = wr.size.height - r.size.height;
5218 [win setAcceptsMouseMovedEvents: YES];
5219 [win setDelegate: self];
5220 [win useOptimizedDrawing: YES];
5222 sz.width = FRAME_COLUMN_WIDTH (f);
5223 sz.height = FRAME_LINE_HEIGHT (f);
5224 [win setResizeIncrements: sz];
5226 [[win contentView] addSubview: self];
5229 [self registerForDraggedTypes: ns_drag_types];
5232 name = [NSString stringWithUTF8String:
5233 NILP (tem) ? (unsigned char *)"Emacs" : SDATA (tem)];
5234 [win setTitle: name];
5236 /* toolbar support */
5237 toolbar = [[EmacsToolbar alloc] initForView: self withIdentifier:
5238 [NSString stringWithFormat: @"Emacs Frame %d",
5240 [win setToolbar: toolbar];
5241 [toolbar setVisible: NO];
5242 #ifdef NS_IMPL_COCOA
5243 toggleButton = [win standardWindowButton: NSWindowToolbarButton];
5244 [toggleButton setTarget: self];
5245 [toggleButton setAction: @selector (toggleToolbar: )];
5247 FRAME_NS_TOOLBAR_HEIGHT (f) = 0;
5251 [win setMiniwindowTitle:
5252 [NSString stringWithUTF8String: SDATA (tem)]];
5255 NSScreen *screen = [win screen];
5258 [win setFrameTopLeftPoint: NSMakePoint
5259 (IN_BOUND (-SCREENMAX, f->left_pos, SCREENMAX),
5260 IN_BOUND (-SCREENMAX,
5261 [screen frame].size.height - NS_TOP_POS (f), SCREENMAX))];
5264 [win makeFirstResponder: self];
5266 col = ns_lookup_indexed_color (NS_FACE_BACKGROUND
5267 (FRAME_DEFAULT_FACE (emacsframe)), emacsframe);
5268 [win setBackgroundColor: col];
5269 if ([col alphaComponent] != 1.0)
5270 [win setOpaque: NO];
5272 [self allocateGState];
5279 - (void)windowDidMove: sender
5281 NSWindow *win = [self window];
5282 NSRect r = [win frame];
5283 NSScreen *screen = [win screen];
5284 NSRect sr = [screen frame];
5286 NSTRACE (windowDidMove);
5288 if (!emacsframe->output_data.ns)
5292 emacsframe->left_pos = r.origin.x; /* - sr.origin.x; */
5293 emacsframe->top_pos = sr.size.height -
5294 (r.origin.y + r.size.height); /* + sr.origin.y; */
5298 #ifdef NS_IMPL_COCOA
5299 /* if we don't do this manually
, the window will resize but not move */
5300 - (BOOL
)windowShouldZoom
: (NSWindow
*)sender toFrame
: (NSRect
)newFrame
5302 NSTRACE
(windowShouldZoom
);
5303 [[self window
] setFrame
: newFrame display
: NO
];
5309 /* Override to do something slightly nonstandard, but nice. First click on
5310 zoom button will zoom vertically. Second will zoom completely. Third
5311 returns to original. */
5312 - (NSRect
)windowWillUseStandardFrame
:(NSWindow
*)sender
5313 defaultFrame
:(NSRect
)defaultFrame
5315 NSRect result
= [sender frame
];
5316 NSTRACE
(windowWillUseStandardFrame
);
5318 if (result.
size.height
== defaultFrame.
size.height
) {
5319 result
= defaultFrame
;
5321 result.
size.height
= defaultFrame.
size.height
;
5322 result.origin.y
= defaultFrame.origin.y
;
5325 /* A windowWillResize does not get generated at least on Tiger. */
5326 [self windowWillResize
: sender toSize
: result.
size];
5331 - (void
)windowDidDeminiaturize
: sender
5333 NSTRACE
(windowDidDeminiaturize
);
5334 if (!emacsframe
->output_data.ns
)
5336 emacsframe
->async_iconified
= 0;
5337 emacsframe
->async_visible
= 1;
5338 windows_or_buffers_changed
++;
5342 emacs_event
->kind
= ICONIFY_EVENT
;
5343 EV_TRAILER
((id
)nil
);
5348 - (void
)windowDidExpose
: sender
5350 NSTRACE
(windowDidExpose
);
5351 if (!emacsframe
->output_data.ns
)
5353 emacsframe
->async_visible
= 1;
5354 SET_FRAME_GARBAGED
(emacsframe
);
5356 if (send_appdefined
)
5357 ns_send_appdefined
(-1);
5361 - (void
)windowDidMiniaturize
: sender
5363 NSTRACE
(windowDidMiniaturize
);
5364 if (!emacsframe
->output_data.ns
)
5367 emacsframe
->async_iconified
= 1;
5368 emacsframe
->async_visible
= 0;
5372 emacs_event
->kind
= ICONIFY_EVENT
;
5373 EV_TRAILER
((id
)nil
);
5378 - (void
)mouseEntered
: (NSEvent
*)theEvent
5380 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5381 struct ns_display_info
*dpyinfo
= FRAME_NS_DISPLAY_INFO
(emacsframe
);
5382 NSTRACE
(mouseEntered
);
5384 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5388 - (void
)mouseExited
: (NSEvent
*)theEvent
5390 NSPoint p
= [self convertPoint
: [theEvent locationInWindow
] fromView
: nil
];
5392 struct ns_display_info
*dpyinfo
5393 = emacsframe ? FRAME_NS_DISPLAY_INFO
(emacsframe
) : NULL;
5395 NSTRACE
(mouseExited
);
5397 if (dpyinfo ||
!emacsframe
)
5400 last_mouse_movement_time
= EV_TIMESTAMP
(theEvent
);
5402 if (emacsframe
== dpyinfo
->mouse_face_mouse_frame
)
5404 clear_mouse_face
(dpyinfo
);
5405 dpyinfo
->mouse_face_mouse_frame
= 0;
5413 if (context_menu_value
== -1)
5414 context_menu_value
= [sender tag
];
5416 find_and_call_menu_selection
(emacsframe
, emacsframe
->menu_bar_items_used
,
5417 emacsframe
->menu_bar_vector
,
5418 (void
*)[sender tag
]);
5419 ns_send_appdefined
(-1);
5424 - (EmacsToolbar
*)toolbar
5430 /* this gets called on toolbar button click */
5431 - toolbarClicked
: (id
)item
5434 int idx
= [item tag
] * TOOL_BAR_ITEM_NSLOTS
;
5436 NSTRACE
(toolbarClicked
);
5441 /* send first event (for some reason two needed) */
5442 theEvent
= [[self window
] currentEvent
];
5443 emacs_event
->kind
= TOOL_BAR_EVENT
;
5444 XSETFRAME
(emacs_event
->arg
, emacsframe
);
5445 EV_TRAILER
(theEvent
);
5447 emacs_event
->kind
= TOOL_BAR_EVENT
;
5448 /* XSETINT (emacs_event->code, 0); */
5449 emacs_event
->arg
= AREF
(emacsframe
->tool_bar_items
,
5450 idx
+ TOOL_BAR_ITEM_KEY
);
5451 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5452 EV_TRAILER
(theEvent
);
5457 - toggleToolbar
: (id
)sender
5462 emacs_event
->kind
= NS_NONKEY_EVENT
;
5463 emacs_event
->code
= KEY_NS_TOGGLE_TOOLBAR
;
5464 EV_TRAILER
((id
)nil
);
5469 - (void
)drawRect
: (NSRect
)rect
5471 int x
= NSMinX
(rect
), y
= NSMinY
(rect
);
5472 int width
= NSWidth
(rect
), height
= NSHeight
(rect
);
5476 if (!emacsframe ||
!emacsframe
->output_data.ns || ns_in_resize
)
5479 ns_clear_frame_area
(emacsframe
, x
, y
, width
, height
);
5480 expose_frame
(emacsframe
, x
, y
, width
, height
);
5483 drawRect: may be called (at least in OS X 10.5) for invisible
5484 views as well for some reason. Thus, do not infer visibility
5487 emacsframe->async_visible = 1;
5488 emacsframe->async_iconified = 0;
5493 /* NSDraggingDestination protocol methods. Actually this is not really a
5494 protocol, but a category of Object. O well... */
5496 -(unsigned int
) draggingEntered
: (id
<NSDraggingInfo
>) sender
5498 NSTRACE
(draggingEntered
);
5499 return NSDragOperationGeneric
;
5503 -(BOOL
)prepareForDragOperation
: (id
<NSDraggingInfo
>) sender
5509 -(BOOL
)performDragOperation
: (id
<NSDraggingInfo
>) sender
5514 NSEvent
*theEvent
= [[self window
] currentEvent
];
5517 NSTRACE
(performDragOperation
);
5522 position
= [self convertPoint
: [sender draggingLocation
] fromView
: nil
];
5523 x
= lrint
(position.x
); y
= lrint
(position.y
);
5525 pb
= [sender draggingPasteboard
];
5526 type = [pb availableTypeFromArray
: ns_drag_types
];
5531 else if ([type isEqualToString
: NSFilenamesPboardType
])
5534 NSEnumerator
*fenum
;
5537 if (!(files
= [pb propertyListForType
: type]))
5540 fenum
= [files objectEnumerator
];
5541 while ( (file
= [fenum nextObject
]) )
5543 emacs_event
->kind
= NS_NONKEY_EVENT
;
5544 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5545 XSETINT
(emacs_event
->x
, x
);
5546 XSETINT
(emacs_event
->y
, y
);
5547 ns_input_file
= append2
(ns_input_file
,
5548 build_string
([file UTF8String
]));
5549 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5550 EV_TRAILER
(theEvent
);
5554 else if ([type isEqualToString
: NSURLPboardType
])
5559 if (!(fileURL
= [NSURL URLFromPasteboard
: pb
]) ||
5560 [fileURL isFileURL
] == NO
)
5563 file
= [fileURL
path];
5564 emacs_event
->kind
= NS_NONKEY_EVENT
;
5565 emacs_event
->code
= KEY_NS_DRAG_FILE
;
5566 XSETINT
(emacs_event
->x
, x
);
5567 XSETINT
(emacs_event
->y
, y
);
5568 ns_input_file
= append2
(ns_input_file
, build_string
([file UTF8String
]));
5569 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5570 EV_TRAILER
(theEvent
);
5573 else if ([type isEqualToString
: NSStringPboardType
]
5574 ||
[type isEqualToString
: NSTabularTextPboardType
])
5578 if (! (data
= [pb stringForType
: type]))
5581 emacs_event
->kind
= NS_NONKEY_EVENT
;
5582 emacs_event
->code
= KEY_NS_DRAG_TEXT
;
5583 XSETINT
(emacs_event
->x
, x
);
5584 XSETINT
(emacs_event
->y
, y
);
5585 ns_input_text
= build_string
([data UTF8String
]);
5586 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5587 EV_TRAILER
(theEvent
);
5590 else if ([type isEqualToString
: NSColorPboardType
])
5592 NSColor
*c
= [NSColor colorFromPasteboard
: pb
];
5593 emacs_event
->kind
= NS_NONKEY_EVENT
;
5594 emacs_event
->code
= KEY_NS_DRAG_COLOR
;
5595 XSETINT
(emacs_event
->x
, x
);
5596 XSETINT
(emacs_event
->y
, y
);
5597 ns_input_color
= ns_color_to_lisp
(c
);
5598 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5599 EV_TRAILER
(theEvent
);
5602 else if ([type isEqualToString
: NSFontPboardType
])
5604 /* impl based on GNUstep NSTextView.m */
5605 NSData
*data
= [pb dataForType
: NSFontPboardType
];
5606 NSDictionary
*dict
= [NSUnarchiver unarchiveObjectWithData
: data
];
5607 NSFont
*font
= [dict objectForKey
: NSFontAttributeName
];
5613 emacs_event
->kind
= NS_NONKEY_EVENT
;
5614 emacs_event
->code
= KEY_NS_CHANGE_FONT
;
5615 XSETINT
(emacs_event
->x
, x
);
5616 XSETINT
(emacs_event
->y
, y
);
5617 ns_input_font
= build_string
([[font fontName
] UTF8String
]);
5618 snprintf
(fontSize
, 10, "
%f", [font pointSize]);
5619 ns_input_fontsize
= build_string
(fontSize
);
5620 emacs_event
->modifiers
= EV_MODIFIERS
(theEvent
);
5621 EV_TRAILER
(theEvent
);
5626 error ("Invalid data
type in dragging pasteboard."
);
5632 - validRequestorForSendType
: (NSString
*)typeSent
5633 returnType
: (NSString
*)typeReturned
5635 NSTRACE
(validRequestorForSendType
);
5636 if ([ns_send_types indexOfObjectIdenticalTo
: typeSent
] != NSNotFound
&&
5637 [ns_return_types indexOfObjectIdenticalTo
: typeSent
] != NSNotFound
)
5640 return [super validRequestorForSendType
: typeSent
5641 returnType
: typeReturned
];
5645 /* The next two methods are part of NSServicesRequests informal protocol,
5646 supposedly called when a services menu item is chosen from this app.
5647 But this should not happen because we override the services menu with our
5648 own entries which call ns-perform-service.
5649 Nonetheless, it appeared to happen (under strange circumstances): bug#1435.
5650 So let's at least stub them out until further investigation can be done. */
5652 - (BOOL
) readSelectionFromPasteboard
: (NSPasteboard
*)pb
5654 /* we could call ns_string_from_pasteboard(pboard) here but then it should
5655 be written into the buffer in place of the existing selection..
5656 ordinary service calls go through functions defined in ns-win.el */
5660 - (BOOL
) writeSelectionToPasteboard
: (NSPasteboard
*)pb types
: (NSArray
*)types
5662 /* supposed to write for as many of types as we are able */
5667 /* setMini =YES means set from internal (gives a finder icon), NO means set nil
5668 (gives a miniaturized version of the window); currently we use the latter for
5669 frames whose active buffer doesn't correspond to any file
5670 (e.g., '*scratch*') */
5671 - setMiniwindowImage
: (BOOL
) setMini
5673 id
image = [[self window
] miniwindowImage
];
5674 NSTRACE
(setMiniwindowImage
);
5676 /* NOTE: under Cocoa miniwindowImage always returns nil, documentation
5677 about "AppleDockIconEnabled" notwithstanding, however the set message
5678 below has its effect nonetheless. */
5679 if (image != emacsframe
->output_data.ns
->miniimage
)
5681 if (image && [image isKindOfClass
: [EmacsImage
class]])
5683 [[self window
] setMiniwindowImage
:
5684 setMini ? emacsframe
->output_data.ns
->miniimage
: nil
];
5691 - (void
) setRows
: (int
) r andColumns
: (int
) c
5697 @
end /* EmacsView */
5701 /* ==========================================================================
5703 EmacsWindow implementation
5705 ========================================================================== */
5707 @implementation EmacsWindow
5709 /* called only on resize clicks by special case in EmacsApp-sendEvent */
5710 - (void
)mouseDown
: (NSEvent
*)theEvent
5714 NSSize
size = [[theEvent window
] frame
].
size;
5715 grabOffset
= [theEvent locationInWindow
];
5716 grabOffset.x
= size.width
- grabOffset.x
;
5719 [super mouseDown
: theEvent
];
5724 - (void
)mouseUp
: (NSEvent
*)theEvent
5728 struct frame
*f
= ((EmacsView
*)[self delegate
])->emacsframe
;
5730 ns_set_name_as_filename
(f
);
5732 ns_send_appdefined
(-1);
5735 [super mouseUp
: theEvent
];
5739 /* send resize events */
5740 - (void
)mouseDragged
: (NSEvent
*)theEvent
5744 NSPoint p
= [theEvent locationInWindow
];
5745 NSSize
size, vettedSize
, origSize
= [self frame
].
size;
5747 size.width
= p.x
+ grabOffset.x
;
5748 size.height
= origSize.height
- p.y
+ grabOffset.y
;
5750 if (size.width
== origSize.width
&& size.height
== origSize.height
)
5753 vettedSize
= [[self delegate
] windowWillResize
: self toSize
: size];
5754 if (vettedSize.width
!= size.width || vettedSize.height
!= size.height
)
5756 [[NSNotificationCenter defaultCenter
]
5757 postNotificationName
: NSWindowDidResizeNotification
5762 [super mouseDragged
: theEvent
];
5765 @
end /* EmacsWindow */
5768 /* ==========================================================================
5770 EmacsScroller implementation
5772 ========================================================================== */
5775 @implementation EmacsScroller
5777 /* for repeat button push */
5778 #define SCROLL_BAR_FIRST_DELAY
0.5
5779 #define SCROLL_BAR_CONTINUOUS_DELAY
(1.0 / 15)
5781 + (float
) scrollerWidth
5783 /* TODO: if we want to allow variable widths, this is the place to do it,
5784 however neither GNUstep nor Cocoa support it very well */
5785 return [NSScroller scrollerWidth
];
5789 - initFrame
: (NSRect
)r window
: (Lisp_Object
)nwin
5791 NSTRACE
(EmacsScroller_initFrame
);
5793 r.
size.width
= [EmacsScroller scrollerWidth
];
5794 [super initWithFrame
: r
/*NSMakeRect (0, 0, 0, 0)*/];
5795 [self setContinuous
: YES
];
5796 [self setEnabled
: YES
];
5798 /* Ensure auto resizing of scrollbars occurs within the emacs frame's view
5799 locked against the right, top and bottom edges. */
5800 [self setAutoresizingMask
: NSViewMinXMargin | NSViewHeightSizable
];
5804 pixel_height
= NSHeight
(r
);
5805 min_portion
= 20 / pixel_height
;
5807 frame
= XFRAME
(XWINDOW
(win
)->frame
);
5808 if (FRAME_LIVE_P
(frame
))
5811 EmacsView
*view = FRAME_NS_VIEW
(frame
);
5812 NSView
*sview
= [[view window
] contentView
];
5813 NSArray
*subs
= [sview subviews
];
5815 /* disable optimization stopping redraw of other scrollbars */
5816 view->scrollbarsNeedingUpdate
= 0;
5817 for (i
=[subs count
]-1; i
>= 0; i
--)
5818 if ([[subs objectAtIndex
: i
] isKindOfClass
: [EmacsScroller
class]])
5819 view->scrollbarsNeedingUpdate
++;
5820 [sview addSubview
: self
];
5823 /* [self setFrame: r]; */
5829 - (void
)setFrame
: (NSRect
)newRect
5831 NSTRACE
(EmacsScroller_setFrame
);
5833 pixel_height
= NSHeight
(newRect
);
5834 min_portion
= 20 / pixel_height
;
5835 [super setFrame
: newRect
];
5837 /* UNBLOCK_INPUT; */
5843 NSTRACE
(EmacsScroller_dealloc
);
5845 XWINDOW
(win
)->vertical_scroll_bar
= Qnil
;
5872 /* ensure other scrollbar updates after deletion */
5873 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
5875 view->scrollbarsNeedingUpdate
++;
5876 [self removeFromSuperview
];
5884 - (void
)resetCursorRects
5886 NSRect visible
= [self visibleRect
];
5887 NSTRACE
(resetCursorRects
);
5889 if (!NSIsEmptyRect
(visible
))
5890 [self addCursorRect
: visible cursor
: [NSCursor arrowCursor
]];
5891 [[NSCursor arrowCursor
] setOnMouseEntered
: YES
];
5895 - (int
) checkSamePosition
: (int
) position portion
: (int
) portion
5898 return em_position
==position
&& em_portion
==portion
&& em_whole
==whole
5899 && portion
!= whole
; /* needed for resize empty buf */
5903 - setPosition
: (int
)position portion
: (int
)portion whole
: (int
)whole
5905 NSTRACE
(setPosition
);
5907 em_position
= position
;
5908 em_portion
= portion
;
5911 if (portion
>= whole
)
5912 [self setFloatValue
: 0.0 knobProportion
: 1.0];
5916 portion
= max ((float
)whole
*min_portion
/pixel_height
, portion
);
5917 pos
= (float
)position
/ (whole
- portion
);
5918 por
= (float
)portion
/whole
;
5919 [self setFloatValue
: pos knobProportion
: por
];
5921 #ifdef NS_IMPL_GNUSTEP
5927 /* FIXME: unused at moment (see ns_mouse_position) at the moment because
5928 drag events will go directly to the EmacsScroller. Leaving in for now. */
5929 -(void
)getMouseMotionPart
: (int
*)part window
: (Lisp_Object
*)window
5930 x
: (Lisp_Object
*)x y
: ( Lisp_Object
*)y
5932 *part
= last_hit_part
;
5934 XSETINT
(*y
, pixel_height
);
5935 if ([self floatValue
] > 0.999)
5936 XSETINT
(*x
, pixel_height
);
5938 XSETINT
(*x
, pixel_height
* [self floatValue
]);
5942 /* set up emacs_event */
5943 - (void
) sendScrollEventAtLoc
: (float
)loc fromEvent
: (NSEvent
*)e
5948 emacs_event
->part
= last_hit_part
;
5949 emacs_event
->code
= 0;
5950 emacs_event
->modifiers
= EV_MODIFIERS
(e
) | down_modifier
;
5951 emacs_event
->frame_or_window
= win
;
5952 emacs_event
->timestamp
= EV_TIMESTAMP
(e
);
5953 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5954 emacs_event
->arg
= Qnil
;
5955 XSETINT
(emacs_event
->x
, loc
* pixel_height
);
5956 XSETINT
(emacs_event
->y
, pixel_height
-20);
5958 n_emacs_events_pending
++;
5959 kbd_buffer_store_event_hold
(emacs_event
, q_event_ptr
);
5960 EVENT_INIT
(*emacs_event
);
5961 ns_send_appdefined
(-1);
5965 /* called manually thru timer to implement repeated button action w/hold-down */
5966 - repeatScroll
: (NSTimer
*)scrollEntry
5968 NSEvent
*e
= [[self window
] currentEvent
];
5969 NSPoint p
= [[self window
] mouseLocationOutsideOfEventStream
];
5970 BOOL inKnob
= [self testPart
: p
] == NSScrollerKnob
;
5972 /* clear timer if need be */
5973 if (inKnob ||
[scroll_repeat_entry timeInterval
] == SCROLL_BAR_FIRST_DELAY
)
5975 [scroll_repeat_entry invalidate
];
5976 [scroll_repeat_entry release
];
5977 scroll_repeat_entry
= nil
;
5983 = [[NSTimer scheduledTimerWithTimeInterval
:
5984 SCROLL_BAR_CONTINUOUS_DELAY
5986 selector
: @selector
(repeatScroll
:)
5992 [self sendScrollEventAtLoc
: 0 fromEvent
: e
];
5997 /* Asynchronous mouse tracking for scroller. This allows us to dispatch
5998 mouseDragged events without going into a modal loop. */
5999 - (void
)mouseDown
: (NSEvent
*)e
6002 /* hitPart is only updated AFTER event is passed on */
6003 NSScrollerPart part
= [self testPart
: [e locationInWindow
]];
6004 double inc
= 0.0, loc
, kloc
, pos
;
6007 NSTRACE
(EmacsScroller_mouseDown
);
6011 case NSScrollerDecrementPage
:
6012 last_hit_part
= scroll_bar_above_handle
; inc
= -1.0; break;
6013 case NSScrollerIncrementPage
:
6014 last_hit_part
= scroll_bar_below_handle
; inc
= 1.0; break;
6015 case NSScrollerDecrementLine
:
6016 last_hit_part
= scroll_bar_up_arrow
; inc
= -0.1; break;
6017 case NSScrollerIncrementLine
:
6018 last_hit_part
= scroll_bar_down_arrow
; inc
= 0.1; break;
6019 case NSScrollerKnob
:
6020 last_hit_part
= scroll_bar_handle
; break;
6021 case NSScrollerKnobSlot
: /* GNUstep-only */
6022 last_hit_part
= scroll_bar_move_ratio
; break;
6023 default
: /* NSScrollerNoPart? */
6024 fprintf (stderr
, "EmacsScoller
-mouseDown
: unexpected part
%d\n", part);
6030 pos
= 0; /* ignored */
6032 /* set a timer to repeat, as we can't let superclass do this modally */
6034 = [[NSTimer scheduledTimerWithTimeInterval
: 0.5
6036 selector
: @selector
(repeatScroll
:)
6043 /* handle, or on GNUstep possibly slot */
6044 NSEvent
*fake_event
;
6046 /* compute float loc in slot and mouse offset on knob */
6047 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6049 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6055 else if (loc
>= NSHeight
(sr
))
6057 loc
= NSHeight
(sr
);
6065 kr
= [self convertRect
: [self rectForPart
: NSScrollerKnob
]
6067 kloc
= NSHeight
(kr
) - ([e locationInWindow
].y
- NSMinY
(kr
));
6069 last_mouse_offset
= kloc
;
6071 /* if knob, tell emacs a location offset by knob pos
6072 (to indicate top of handle) */
6073 if (part
== NSScrollerKnob
)
6074 pos
= (loc
- last_mouse_offset
) / NSHeight
(sr
);
6076 /* else this is a slot click on GNUstep: go straight there */
6077 pos
= loc
/ NSHeight
(sr
);
6079 /* send a fake mouse-up to super to preempt modal -trackKnob: mode */
6080 fake_event
= [NSEvent mouseEventWithType
: NSLeftMouseUp
6081 location
: [e locationInWindow
]
6082 modifierFlags
: [e modifierFlags
]
6083 timestamp
: [e timestamp
]
6084 windowNumber
: [e windowNumber
]
6085 context
: [e context
]
6086 eventNumber
: [e eventNumber
]
6087 clickCount
: [e clickCount
]
6088 pressure
: [e pressure
]];
6089 [super mouseUp
: fake_event
];
6092 if (part
!= NSScrollerKnob
)
6093 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6097 /* Called as we manually track scroller drags, rather than superclass. */
6098 - (void
)mouseDragged
: (NSEvent
*)e
6104 NSTRACE
(EmacsScroller_mouseDragged
);
6106 sr
= [self convertRect
: [self rectForPart
: NSScrollerKnobSlot
]
6108 loc
= NSHeight
(sr
) - ([e locationInWindow
].y
- NSMinY
(sr
));
6115 else if (loc
>= NSHeight
(sr
) + last_mouse_offset
)
6117 loc
= NSHeight
(sr
) + last_mouse_offset
;
6121 pos
= /*(edge ? loc :*/ (loc
- last_mouse_offset
) / NSHeight
(sr
);
6122 [self sendScrollEventAtLoc
: pos fromEvent
: e
];
6126 - (void
)mouseUp
: (NSEvent
*)e
6128 if (scroll_repeat_entry
)
6130 [scroll_repeat_entry invalidate
];
6131 [scroll_repeat_entry release
];
6132 scroll_repeat_entry
= nil
;
6138 /* treat scrollwheel events in the bar as though they were in the main window */
6139 - (void
) scrollWheel
: (NSEvent
*)theEvent
6141 EmacsView
*view = (EmacsView
*)FRAME_NS_VIEW
(frame
);
6142 [view mouseDown
: theEvent
];
6145 @
end /* EmacsScroller */
6150 /* ==========================================================================
6152 Font-related functions; these used to be in nsfaces.m
6154 ========================================================================== */
6158 x_new_font
(struct frame
*f
, Lisp_Object font_object
, int fontset
)
6160 struct font
*font
= XFONT_OBJECT
(font_object
);
6163 fontset
= fontset_from_font
(font_object
);
6164 FRAME_FONTSET
(f
) = fontset
;
6166 if (FRAME_FONT
(f
) == font
)
6167 /* This font is already set in frame F. There's nothing more to
6171 FRAME_FONT
(f
) = font
;
6173 FRAME_BASELINE_OFFSET
(f
) = font
->baseline_offset
;
6174 FRAME_COLUMN_WIDTH
(f
) = font
->average_width
;
6175 FRAME_SPACE_WIDTH
(f
) = font
->space_width
;
6176 FRAME_LINE_HEIGHT
(f
) = font
->height
;
6178 compute_fringe_widths
(f
, 1);
6180 /* Compute the scroll bar width in character columns. */
6181 if (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) > 0)
6183 int wid
= FRAME_COLUMN_WIDTH
(f
);
6184 FRAME_CONFIG_SCROLL_BAR_COLS
(f
)
6185 = (FRAME_CONFIG_SCROLL_BAR_WIDTH
(f
) + wid
- 1) / wid
;
6189 int wid
= FRAME_COLUMN_WIDTH
(f
);
6190 FRAME_CONFIG_SCROLL_BAR_COLS
(f
) = (14 + wid
- 1) / wid
;
6193 /* Now make the frame display the given font. */
6194 if (FRAME_NS_WINDOW
(f
) != 0)
6195 x_set_window_size
(f
, 0, FRAME_COLS
(f
), FRAME_LINES
(f
));
6201 /* XLFD: -foundry-family-weight-slant-swidth-adstyle-pxlsz-ptSz-resx-resy-spc-avgWidth-rgstry-encoding */
6202 /* Note: ns_font_to_xlfd and ns_fontname_to_xlfd no longer needed, removed
6206 ns_xlfd_to_fontname
(const
char *xlfd
)
6207 /* --------------------------------------------------------------------------
6208 Convert an X font name (XLFD) to an NS font name.
6209 Only family is used.
6210 The string returned is temporarily allocated.
6211 -------------------------------------------------------------------------- */
6213 char *name
= xmalloc
(180);
6217 if (!strncmp
(xlfd
, "
--"
, 2))
6218 sscanf (xlfd
, "
--%*[^-]-%[^-]179-", name);
6220 sscanf (xlfd
, "
-%*[^-]-%[^-]179-", name);
6222 /* stopgap for malformed XLFD input */
6223 if (strlen
(name
) == 0)
6224 strcpy
(name
, "Monaco"
);
6226 /* undo hack in ns_fontname_to_xlfd, converting '$' to '-', '_' to ' '
6227 also uppercase after '-' or ' ' */
6228 name
[0] = toupper
(name
[0]);
6229 for (len
=strlen
(name
), i
=0; i
<len
; i
++)
6235 name
[i
+1] = toupper
(name
[i
+1]);
6237 else if (name
[i
] == '_')
6241 name
[i
+1] = toupper
(name
[i
+1]);
6244 /*fprintf (stderr, "converted '%s' to '%s'\n",xlfd,name); */
6245 ret
= [[NSString stringWithUTF8String
: name
] UTF8String
];
6254 NSTRACE
(syms_of_nsterm
);
6255 DEFVAR_LISP
("ns
-input-file"
, &ns_input_file
,
6256 "The file specified in the last NS event."
);
6257 ns_input_file
=Qnil
;
6259 DEFVAR_LISP
("ns
-input-text"
, &ns_input_text
,
6260 "The data received in the last NS
text drag event."
);
6261 ns_input_text
=Qnil
;
6263 DEFVAR_LISP
("ns
-working
-text"
, &ns_working_text
,
6264 "String
for visualizing working composition sequence."
);
6265 ns_working_text
=Qnil
;
6267 DEFVAR_LISP
("ns
-input-font"
, &ns_input_font
,
6268 "The font specified in the last NS event."
);
6269 ns_input_font
=Qnil
;
6271 DEFVAR_LISP
("ns
-input-fontsize"
, &ns_input_fontsize
,
6272 "The fontsize specified in the last NS event."
);
6273 ns_input_fontsize
=Qnil
;
6275 DEFVAR_LISP
("ns
-input-line"
, &ns_input_line
,
6276 "The
line specified in the last NS event."
);
6277 ns_input_line
=Qnil
;
6279 DEFVAR_LISP
("ns
-input-color"
, &ns_input_color
,
6280 "The color specified in the last NS event."
);
6281 ns_input_color
=Qnil
;
6283 DEFVAR_LISP
("ns
-input-spi
-name"
, &ns_input_spi_name
,
6284 "The service name specified in the last NS event."
);
6285 ns_input_spi_name
=Qnil
;
6287 DEFVAR_LISP
("ns
-input-spi
-arg"
, &ns_input_spi_arg
,
6288 "The service argument specified in the last NS event."
);
6289 ns_input_spi_arg
=Qnil
;
6291 DEFVAR_LISP
("ns
-alternate
-modifier"
, &ns_alternate_modifier
,
6292 "This variable describes the behavior of the alternate or option key.
\n\
6293 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6294 Set to none means that the alternate
/ option key is not interpreted by Emacs
\n\
6295 at
all, allowing it to be used at a
lower level
for accented character entry."
);
6297 DEFVAR_LISP
("ns
-command
-modifier"
, &ns_command_modifier
,
6298 "This variable describes the behavior of the command key.
\n\
6299 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
6301 DEFVAR_LISP
("ns
-control
-modifier"
, &ns_control_modifier
,
6302 "This variable describes the behavior of the control key.
\n\
6303 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key."
);
6305 DEFVAR_LISP
("ns
-function-modifier"
, &ns_function_modifier
,
6306 "This variable describes the behavior of the
function key
(on laptops
).
\n\
6307 Set to control
, meta, alt
, super
, or hyper means it is taken to be that key.
\n\
6308 Set to none means that the
function key is not interpreted by Emacs at
all,\n\
6309 allowing it to be used at a
lower level
for accented character entry."
);
6311 DEFVAR_LISP
("ns
-antialias
-text"
, &ns_antialias_text
,
6312 "Non
-nil
(the default
) means to render
text antialiased. Only has an effect on OS X Panther and above."
);
6314 DEFVAR_LISP
("ns
-use
-qd
-smoothing"
, &ns_use_qd_smoothing
,
6315 "Whether to render
text using QuickDraw
(less heavy
) antialiasing. Only has an effect on OS X Panther and above. Default is nil
(use Quartz smoothing
)."
);
6317 DEFVAR_LISP
("ns
-confirm
-quit"
, &ns_confirm_quit
,
6318 "Whether to confirm application
quit using
dialog."
);
6320 staticpro
(&ns_display_name_list
);
6321 ns_display_name_list
= Qnil
;
6323 staticpro
(&last_mouse_motion_frame
);
6324 last_mouse_motion_frame
= Qnil
;
6326 /* from 23+ we need to tell emacs what modifiers there are.. */
6327 Qmodifier_value
= intern
("modifier
-value"
);
6328 Qalt
= intern
("alt"
);
6329 Fput
(Qalt
, Qmodifier_value
, make_number
(alt_modifier
));
6330 Qhyper
= intern
("hyper"
);
6331 Fput
(Qhyper
, Qmodifier_value
, make_number
(hyper_modifier
));
6332 Qmeta
= intern
("
meta"
);
6333 Fput
(Qmeta
, Qmodifier_value
, make_number
(meta_modifier
));
6334 Qsuper
= intern
("super"
);
6335 Fput
(Qsuper
, Qmodifier_value
, make_number
(super_modifier
));
6336 Qcontrol
= intern
("control"
);
6337 Fput
(Qcontrol
, Qmodifier_value
, make_number
(ctrl_modifier
));
6339 /* TODO: move to common code */
6340 DEFVAR_LISP
("x
-toolkit
-scroll
-bars"
, &Vx_toolkit_scroll_bars
,
6341 doc: /* If not nil, Emacs uses toolkit scroll bars. */);
6342 #ifdef USE_TOOLKIT_SCROLL_BARS
6343 Vx_toolkit_scroll_bars
= Qt
;
6345 Vx_toolkit_scroll_bars
= Qnil
;
6348 /* these are unsupported but we need the declarations to avoid whining
6349 messages from cus-start.el */
6350 DEFVAR_BOOL
("x
-use
-underline
-position
-properties"
,
6351 &x_use_underline_position_properties
,
6352 doc: /* NOT SUPPORTED UNDER NS.
6353 *Non-nil means make use of UNDERLINE_POSITION font properties.
6354 A value of nil means ignore them. If you encounter fonts with bogus
6355 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
6356 to 4.1, set this to nil.
6358 NOTE: Not supported on Mac yet. */);
6359 x_use_underline_position_properties
= 0;
6361 DEFVAR_BOOL
("x
-underline
-at
-descent
-line"
,
6362 &x_underline_at_descent_line
,
6363 doc: /* NOT SUPPORTED UNDER NS.
6364 *Non-nil means to draw the underline at the same place as the descent line.
6365 A value of nil means to draw the underline according to the value of the
6366 variable `x-use-underline-position-properties', which is usually at the
6367 baseline level. The default value is nil. */);
6368 x_underline_at_descent_line
= 0;
6370 /* Tell emacs about this window system. */
6371 Fprovide
(intern
("ns"
), Qnil
);
6375 // arch
-tag
: 6eaa8f7d
-a69b
-4e1c
-b43d
-ab31defbe0d2