1 /* Definitions and headers for communication with NeXT/Open/GNUstep API.
2 Copyright (C) 1989, 1993, 2005, 2008-2016 Free Software Foundation,
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 (at
10 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 #include "dispextern.h"
23 #include "character.h"
25 #include "sysselect.h"
30 #ifndef MAC_OS_X_VERSION_10_6
31 #define MAC_OS_X_VERSION_10_6 1060
33 #ifndef MAC_OS_X_VERSION_10_7
34 #define MAC_OS_X_VERSION_10_7 1070
36 #ifndef MAC_OS_X_VERSION_10_8
37 #define MAC_OS_X_VERSION_10_8 1080
39 #ifndef MAC_OS_X_VERSION_10_9
40 #define MAC_OS_X_VERSION_10_9 1090
42 #ifndef MAC_OS_X_VERSION_10_12
43 #define MAC_OS_X_VERSION_10_12 101200
46 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
47 #define HAVE_NATIVE_FS
50 #endif /* NS_IMPL_COCOA */
54 /* CGFloat on GNUstep may be 4 or 8 byte, but functions expect float* for some
56 On Cocoa >= 10.5, functions expect CGFloat*. Make compatible type. */
58 typedef CGFloat EmacsCGFloat
;
59 #elif GNUSTEP_GUI_MAJOR_VERSION > 0 || GNUSTEP_GUI_MINOR_VERSION >= 22
60 typedef CGFloat EmacsCGFloat
;
62 typedef float EmacsCGFloat
;
65 /* ==========================================================================
69 ========================================================================== */
71 /* Uncomment the following line to enable trace.
73 Uncomment suitable NSTRACE_GROUP_xxx lines to trace more.
75 Hint: keep the trailing whitespace -- the version control system
76 will reject accidental commits. */
78 /* #define NSTRACE_ENABLED 1 */
81 /* When non-zero, trace output is enabled for all parts, except those
82 explicitly disabled. */
83 /* #define NSTRACE_ALL_GROUPS 1 */
85 /* When non-zero, trace output is enabled in the corresponding part. */
86 /* #define NSTRACE_GROUP_EVENTS 1 */
87 /* #define NSTRACE_GROUP_UPDATES 1 */
88 /* #define NSTRACE_GROUP_FRINGE 1 */
89 /* #define NSTRACE_GROUP_COLOR 1 */
90 /* #define NSTRACE_GROUP_GLYPHS 1 */
91 /* #define NSTRACE_GROUP_FOCUS 1 */
94 /* Print a call tree containing all annotated functions.
96 The call structure of the functions is represented using
97 indentation and vertical lines. Extra information is printed using
98 horizontal lines that connect to the vertical line.
100 The return value is represented using the arrow "->>". For simple
101 functions, the arrow can be printed on the same line as the
102 function name. If more output is printed, it is connected to the
103 vertical line of the function.
105 The first column contains the file name, the second the line
106 number, and the third a number increasing for each trace line.
108 Note, when trace output from several threads are mixed, the output
109 can become misaligned, as all threads (currently) share one state.
110 This is post prominent when the EVENTS part is enabled.
112 Note that the trace system, when enabled, use the GCC/Clang
113 "cleanup" extension. */
115 /* For example, the following is the output of `M-x
116 toggle-frame-maximized RET'.
118 (Long lines manually split to reduced width):
120 nsterm.m : 1608: [ 354] ns_fullscreen_hook
121 nsterm.m : 7180: [ 355] | [EmacsView handleFS]
122 nsterm.m : 7209: [ 356] | +--- FULLSCREEN_MAXIMIZED
123 nsterm.m : 7706: [ 357] | | [EmacsWindow performZoom:]
124 nsterm.m : 7715: [ 358] | | | [EmacsWindow zoom:]
125 nsterm.m : 882: [ 359] | | | | ns_update_auto_hide_menu_bar
126 nsterm.m : 6752: [ 360] | | | |
127 [EmacsView windowWillUseStandardFrame:defaultFrame:(X:0 Y:0)/(W:1600 H:1177)]
128 nsterm.m : 6753: [ 361] | | | | +--- fs_state: FULLSCREEN_NONE
129 nsterm.m : 6754: [ 362] | | | | +--- fs_before_fs: -1
130 nsterm.m : 6755: [ 363] | | | | +--- next_maximized: FULLSCREEN_MAXIMIZED
131 nsterm.m : 6756: [ 364] | | | | +--- ns_userRect: (X:0 Y:0)/(W:0 H:0)
132 nsterm.m : 6757: [ 365] | | | | +---
133 [sender frame]: (X:0 Y:626)/(W:595 H:551)
134 nsterm.m : 6781: [ 366] | | | | +---
135 ns_userRect (2): (X:0 Y:626)/(W:595 H:551)
136 nsterm.m : 6821: [ 367] | | | | +--- FULLSCREEN_MAXIMIZED
137 nsterm.m : 7232: [ 368] | | | | |
138 [EmacsView setFSValue:FULLSCREEN_MAXIMIZED]
139 nsterm.m : 6848: [ 369] | | | | +---
140 Final ns_userRect: (X:0 Y:626)/(W:595 H:551)
141 nsterm.m : 6849: [ 370] | | | | +--- Final maximized_width: 1600
142 nsterm.m : 6850: [ 371] | | | | +--- Final maximized_height: 1177
143 nsterm.m : 6851: [ 372] | | | | +--- Final next_maximized: -1
144 nsterm.m : 6322: [ 373] | | | | |
145 [EmacsView windowWillResize:toSize: (W:1600 H:1177)]
146 nsterm.m : 6323: [ 374] | | | | | +---
147 [sender frame]: (X:0 Y:626)/(W:595 H:551)
148 nsterm.m : 6324: [ 375] | | | | | +--- fs_state: FULLSCREEN_MAXIMIZED
149 nsterm.m : 7027: [ 376] | | | | | | [EmacsView isFullscreen]
150 nsterm.m : 6387: [ 377] | | | | | +--- cols: 223 rows: 79
151 nsterm.m : 6412: [ 378] | | | | | +->> (W:1596 H:1167)
152 nsterm.m : 6855: [ 379] | | | | +->> (X:0 Y:0)/(W:1600 H:1177)
155 #ifndef NSTRACE_ENABLED
156 #define NSTRACE_ENABLED 0
161 #ifndef NSTRACE_ALL_GROUPS
162 #define NSTRACE_ALL_GROUPS 0
165 #ifndef NSTRACE_GROUP_EVENTS
166 #define NSTRACE_GROUP_EVENTS NSTRACE_ALL_GROUPS
169 #ifndef NSTRACE_GROUP_UPDATES
170 #define NSTRACE_GROUP_UPDATES NSTRACE_ALL_GROUPS
173 #ifndef NSTRACE_GROUP_FRINGE
174 #define NSTRACE_GROUP_FRINGE NSTRACE_ALL_GROUPS
177 #ifndef NSTRACE_GROUP_COLOR
178 #define NSTRACE_GROUP_COLOR NSTRACE_ALL_GROUPS
181 #ifndef NSTRACE_GROUP_GLYPHS
182 #define NSTRACE_GROUP_GLYPHS NSTRACE_ALL_GROUPS
185 #ifndef NSTRACE_GROUP_FOCUS
186 #define NSTRACE_GROUP_FOCUS NSTRACE_ALL_GROUPS
189 extern volatile int nstrace_num
;
190 extern volatile int nstrace_depth
;
191 extern volatile int nstrace_enabled_global
;
193 void nstrace_leave(int *);
194 void nstrace_restore_global_trace_state(int *);
195 char const * nstrace_fullscreen_type_name (int);
197 /* printf-style trace output. Output is aligned with contained heading. */
198 #define NSTRACE_MSG_NO_DASHES(...) \
201 if (nstrace_enabled) \
203 fprintf (stderr, "%-10s:%5d: [%5d]%.*s", \
204 __FILE__, __LINE__, nstrace_num++, \
205 2*nstrace_depth, " | | | | | | | | | | | | | | | .."); \
206 fprintf (stderr, __VA_ARGS__); \
207 fprintf (stderr, "\n"); \
212 #define NSTRACE_MSG(...) NSTRACE_MSG_NO_DASHES("+--- " __VA_ARGS__)
216 /* Macros for printing complex types.
218 NSTRACE_FMT_what -- Printf format string for "what".
219 NSTRACE_ARG_what(x) -- Printf argument for "what". */
221 #define NSTRACE_FMT_SIZE "(W:%.0f H:%.0f)"
222 #define NSTRACE_ARG_SIZE(elt) (elt).width, (elt).height
224 #define NSTRACE_FMT_POINT "(X:%.0f Y:%.0f)"
225 #define NSTRACE_ARG_POINT(elt) (elt).x, (elt).y
227 #define NSTRACE_FMT_RECT NSTRACE_FMT_POINT "/" NSTRACE_FMT_SIZE
228 #define NSTRACE_ARG_RECT(elt) \
229 NSTRACE_ARG_POINT((elt).origin), NSTRACE_ARG_SIZE((elt).size)
231 #define NSTRACE_FMT_FSTYPE "%s"
232 #define NSTRACE_ARG_FSTYPE(elt) nstrace_fullscreen_type_name(elt)
235 /* Macros for printing complex types as extra information. */
237 #define NSTRACE_SIZE(str,size) \
238 NSTRACE_MSG (str ": " NSTRACE_FMT_SIZE, \
239 NSTRACE_ARG_SIZE (size));
241 #define NSTRACE_POINT(str,point) \
242 NSTRACE_MSG (str ": " NSTRACE_FMT_POINT, \
243 NSTRACE_ARG_POINT (point));
245 #define NSTRACE_RECT(str,rect) \
246 NSTRACE_MSG (str ": " NSTRACE_FMT_RECT, \
247 NSTRACE_ARG_RECT (rect));
249 #define NSTRACE_FSTYPE(str,fs_type) \
250 NSTRACE_MSG (str ": " NSTRACE_FMT_FSTYPE, \
251 NSTRACE_ARG_FSTYPE (fs_type));
254 /* Return value macros.
256 NSTRACE_RETURN(fmt, ...) - Print a return value, support printf-style
257 format string and arguments.
259 NSTRACE_RETURN_what(obj) - Print a return value of kind WHAT.
261 NSTRACE_FMT_RETURN - A string literal representing a returned
262 value. Useful when creating a format string
263 to printf-like constructs like NSTRACE(). */
265 #define NSTRACE_FMT_RETURN "->>"
267 #define NSTRACE_RETURN(...) \
268 NSTRACE_MSG_NO_DASHES ("+" NSTRACE_FMT_RETURN " " __VA_ARGS__)
270 #define NSTRACE_RETURN_SIZE(size) \
271 NSTRACE_RETURN(NSTRACE_FMT_SIZE, NSTRACE_ARG_SIZE(size))
273 #define NSTRACE_RETURN_POINT(point) \
274 NSTRACE_RETURN(NSTRACE_FMT_POINT, NSTRACE_ARG_POINT(point))
276 #define NSTRACE_RETURN_RECT(rect) \
277 NSTRACE_RETURN(NSTRACE_FMT_RECT, NSTRACE_ARG_RECT(rect))
280 /* Function enter macros.
282 NSTRACE (fmt, ...) -- Enable trace output in current block
283 (typically a function). Accepts printf-style
286 NSTRACE_WHEN (cond, fmt, ...) -- Enable trace output when COND is true.
288 NSTRACE_UNLESS (cond, fmt, ...) -- Enable trace output unless COND is
293 #define NSTRACE_WHEN(cond, ...) \
294 __attribute__((cleanup(nstrace_restore_global_trace_state))) \
295 int nstrace_saved_enabled_global = nstrace_enabled_global; \
296 __attribute__((cleanup(nstrace_leave))) \
297 int nstrace_enabled = nstrace_enabled_global && (cond); \
298 if (nstrace_enabled) { ++nstrace_depth; } \
299 else { nstrace_enabled_global = 0; } \
300 NSTRACE_MSG_NO_DASHES(__VA_ARGS__);
302 /* Unsilence called functions.
304 Concretely, this us used to allow "event" functions to be silenced
305 while trace output can be printed for functions they call. */
306 #define NSTRACE_UNSILENCE() do { nstrace_enabled_global = 1; } while(0)
308 #endif /* NSTRACE_ENABLED */
310 #define NSTRACE(...) NSTRACE_WHEN(1, __VA_ARGS__)
311 #define NSTRACE_UNLESS(cond, ...) NSTRACE_WHEN(!(cond), __VA_ARGS__)
313 /* Non-trace replacement versions. */
315 #define NSTRACE_WHEN(...)
319 #define NSTRACE_MSG(...)
323 #define NSTRACE_SIZE(str,size)
326 #ifndef NSTRACE_POINT
327 #define NSTRACE_POINT(str,point)
331 #define NSTRACE_RECT(str,rect)
334 #ifndef NSTRACE_FSTYPE
335 #define NSTRACE_FSTYPE(str,fs_type)
338 #ifndef NSTRACE_RETURN_SIZE
339 #define NSTRACE_RETURN_SIZE(size)
342 #ifndef NSTRACE_RETURN_POINT
343 #define NSTRACE_RETURN_POINT(point)
346 #ifndef NSTRACE_RETURN_RECT
347 #define NSTRACE_RETURN_RECT(rect)
350 #ifndef NSTRACE_RETURN_FSTYPE
351 #define NSTRACE_RETURN_FSTYPE(fs_type)
354 #ifndef NSTRACE_UNSILENCE
355 #define NSTRACE_UNSILENCE()
359 /* ==========================================================================
361 NSColor, EmacsColor category.
363 ========================================================================== */
364 @interface
NSColor (EmacsColor
)
365 + (NSColor
*)colorForEmacsRed
:(CGFloat
)red green
:(CGFloat
)green
366 blue
:(CGFloat
)blue alpha
:(CGFloat
)alpha
;
367 - (NSColor
*)colorUsingDefaultColorSpace
;
371 /* ==========================================================================
373 The Emacs application
375 ========================================================================== */
377 /* We override sendEvent: as a means to stop/start the event loop */
378 @interface EmacsApp
: NSApplication
381 BOOL shouldKeepRunning
;
384 #ifdef NS_IMPL_GNUSTEP
385 BOOL applicationDidFinishLaunchingCalled
;
390 - (void)logNotification
: (NSNotification
*)notification
;
391 - (void)antialiasThresholdDidChange
:(NSNotification
*)notification
;
392 - (void)sendEvent
: (NSEvent
*)theEvent
;
393 - (void)showPreferencesWindow
: (id
)sender
;
394 - (BOOL
) openFile
: (NSString
*)fileName
;
395 - (void)fd_handler
: (id
)unused
;
396 - (void)timeout_handler
: (NSTimer
*)timedEntry
;
397 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
;
398 #ifdef NS_IMPL_GNUSTEP
399 - (void)sendFromMainThread
:(id
)unused
;
403 #ifdef NS_IMPL_GNUSTEP
404 /* Dummy class to get rid of startup warnings. */
405 @interface EmacsDocument
: NSDocument
411 /* ==========================================================================
415 ========================================================================== */
420 @interface EmacsView
: NSView
<NSTextInput
, NSWindowDelegate
>
422 @interface EmacsView
: NSView
<NSTextInput
>
427 BOOL maximizing_resize
;
430 NSString
*workingText
;
431 BOOL processingCompose
;
432 int fs_state
, fs_before_fs
, next_maximized
;
433 int tibar_height
, tobar_height
, bwidth
;
434 int maximized_width
, maximized_height
;
435 NSWindow
*nonfs_window
;
438 struct frame
*emacsframe
;
440 int scrollbarsNeedingUpdate
;
441 EmacsToolbar
*toolbar
;
443 BOOL wait_for_tool_bar
;
446 /* AppKit-side interface */
447 - menuDown
: (id
)sender
;
448 - toolbarClicked
: (id
)item
;
449 - toggleToolbar
: (id
)sender
;
450 - (void)keyDown
: (NSEvent
*)theEvent
;
451 - (void)mouseDown
: (NSEvent
*)theEvent
;
452 - (void)mouseUp
: (NSEvent
*)theEvent
;
453 - setMiniwindowImage
: (BOOL
)setMini
;
455 /* Emacs-side interface */
456 - initFrameFromEmacs
: (struct frame
*) f
;
457 - (void) setRows
: (int) r andColumns
: (int) c
;
458 - (void) setWindowClosing
: (BOOL
)closing
;
459 - (EmacsToolbar
*) toolbar
;
460 - (void) deleteWorkingText
;
461 - (void) updateFrameSize
: (BOOL
) delay
;
463 - (void) setFSValue
: (int)value
;
464 - (void) toggleFullScreen
: (id
) sender
;
466 - (BOOL
) isFullscreen
;
467 #ifdef HAVE_NATIVE_FS
468 - (void) updateCollectionBehavior
;
471 #ifdef NS_IMPL_GNUSTEP
472 - (void)windowDidMove
: (id
)sender
;
474 - (int)fullscreenState
;
476 /* Non-notification versions of NSView methods. Used for direct calls. */
477 - (void)windowWillEnterFullScreen
;
478 - (void)windowDidEnterFullScreen
;
479 - (void)windowWillExitFullScreen
;
480 - (void)windowDidExitFullScreen
;
481 - (void)windowDidBecomeKey
;
485 /* Small utility used for processing resize events under Cocoa. */
486 @interface EmacsWindow
: NSWindow
493 /* Fullscreen version of the above. */
494 @interface EmacsFSWindow
: EmacsWindow
499 /* ==========================================================================
501 The main menu implementation
503 ========================================================================== */
506 @interface EmacsMenu
: NSMenu
<NSMenuDelegate
>
508 @interface EmacsMenu
: NSMenu
512 unsigned long keyEquivModMask
;
515 - initWithTitle
: (NSString
*)title frame
: (struct frame
*)f
;
516 - (void)setFrame
: (struct frame
*)f
;
517 - (void)menuNeedsUpdate
: (NSMenu
*)menu
; /* (delegate method) */
518 - (NSString
*)parseKeyEquiv
: (const char *)key
;
519 - (NSMenuItem
*)addItemWithWidgetValue
: (void *)wvptr
;
520 - (void)fillWithWidgetValue
: (void *)wvptr
;
521 - (void)fillWithWidgetValue
: (void *)wvptr frame
: (struct frame
*)f
;
522 - (EmacsMenu
*)addSubmenuWithTitle
: (const char *)title forFrame
: (struct frame
*)f
;
524 - (Lisp_Object
)runMenuAt
: (NSPoint
)p forFrame
: (struct frame
*)f
525 keymaps
: (bool)keymaps
;
529 /* ==========================================================================
533 ========================================================================== */
538 @interface EmacsToolbar
: NSToolbar
<NSToolbarDelegate
>
540 @interface EmacsToolbar
: NSToolbar
543 EmacsView
*emacsView
;
544 NSMutableDictionary
*identifierToItem
;
545 NSMutableArray
*activeIdentifiers
;
546 NSArray
*prevIdentifiers
;
547 unsigned long enablement
, prevEnablement
;
549 - initForView
: (EmacsView
*)view withIdentifier
: (NSString
*)identifier
;
550 - (void) clearActive
;
553 - (void) addDisplayItemWithImage
: (EmacsImage
*)img
556 helpText
: (const char *)help
557 enabled
: (BOOL
)enabled
;
559 /* delegate methods */
560 - (NSToolbarItem
*)toolbar
: (NSToolbar
*)toolbar
561 itemForItemIdentifier
: (NSString
*)itemIdentifier
562 willBeInsertedIntoToolbar
: (BOOL
)flag
;
563 - (NSArray
*)toolbarDefaultItemIdentifiers
: (NSToolbar
*)toolbar
;
564 - (NSArray
*)toolbarAllowedItemIdentifiers
: (NSToolbar
*)toolbar
;
568 /* ==========================================================================
570 Message / question windows
572 ========================================================================== */
574 @interface EmacsDialogPanel
: NSPanel
576 NSTextField
*command
;
580 BOOL timer_fired
, window_closed
;
581 Lisp_Object dialog_return
;
582 Lisp_Object
*button_values
;
584 - initFromContents
: (Lisp_Object
)menu isQuestion
: (BOOL
)isQ
;
585 - (void)process_dialog
: (Lisp_Object
)list
;
586 - (void)addButton
: (char *)str value
: (int)tag row
: (int)row
;
587 - (void)addString
: (char *)str row
: (int)row
;
589 - (Lisp_Object
)runDialogAt
: (NSPoint
)p
;
590 - (void)timeout_handler
: (NSTimer
*)timedEntry
;
594 @interface EmacsTooltip
: NSObject
<NSWindowDelegate
>
596 @interface EmacsTooltip
: NSObject
600 NSTextField
*textField
;
604 - (void) setText
: (char *)text
;
605 - (void) showAtX
: (int)x Y
: (int)y
for: (int)seconds
;
612 /* ==========================================================================
614 File open/save panels
615 This and next override methods to handle keyboard input in panels.
617 ========================================================================== */
619 @interface EmacsSavePanel
: NSSavePanel
623 @interface EmacsOpenPanel
: NSOpenPanel
628 @interface EmacsFileDelegate
: NSObject
631 - (BOOL
)panel
: (id
)sender isValidFilename
: (NSString
*)filename
;
632 - (BOOL
)panel
: (id
)sender shouldShowFilename
: (NSString
*)filename
;
633 - (NSString
*)panel
: (id
)sender userEnteredFilename
: (NSString
*)filename
634 confirmed
: (BOOL
)okFlag
;
638 /* ==========================================================================
642 ========================================================================== */
644 @interface EmacsImage
: NSImage
646 NSBitmapImageRep
*bmRep
; /* used for accessing pixel data */
647 unsigned char *pixmapData
[5]; /* shortcut to access pixel data */
648 NSColor
*stippleMask
;
649 unsigned long xbm_fg
;
651 + allocInitFromFile
: (Lisp_Object
)file
;
653 - initFromXBM
: (unsigned char *)bits width
: (int)w height
: (int)h
654 fg
: (unsigned long)fg bg
: (unsigned long)bg
;
655 - setXBMColor
: (NSColor
*)color
;
656 - initForXPMWithDepth
: (int)depth width
: (int)width height
: (int)height
;
657 - (void)setPixmapData
;
658 - (unsigned long)getPixelAtX
: (int)x Y
: (int)y
;
659 - (void)setPixelAtX
: (int)x Y
: (int)y toRed
: (unsigned char)r
660 green
: (unsigned char)g blue
: (unsigned char)b
661 alpha
:(unsigned char)a
;
662 - (void)setAlphaAtX
: (int)x Y
: (int)y to
: (unsigned char)a
;
663 - (NSColor
*)stippleMask
;
667 /* ==========================================================================
671 ========================================================================== */
673 @interface EmacsScroller
: NSScroller
675 struct window
*window
;
677 NSResponder
*prevResponder
;
679 /* offset to the bottom of knob of last mouse down */
680 CGFloat last_mouse_offset
;
683 enum scroll_bar_part last_hit_part
;
689 /* optimize against excessive positioning calls generated by emacs */
695 - initFrame
: (NSRect
)r window
: (Lisp_Object
)win
;
696 - (void)setFrame
: (NSRect
)r
;
698 - setPosition
: (int) position portion
: (int) portion whole
: (int) whole
;
699 - (int) checkSamePosition
: (int)position portion
: (int)portion
701 - (void) sendScrollEventAtLoc
: (float)loc fromEvent
: (NSEvent
*)e
;
702 - repeatScroll
: (NSTimer
*)sender
;
706 + (CGFloat
)scrollerWidth
;
710 /* ==========================================================================
714 ========================================================================== */
718 @interface EmacsGlyphStorage
: NSObject
<NSGlyphStorage
>
721 NSAttributedString
*attrStr
;
722 NSMutableDictionary
*dict
;
724 unsigned long maxChar
, maxGlyph
;
727 - initWithCapacity
: (unsigned long) c
;
728 - (void) setString
: (NSString
*)str font
: (NSFont
*)font
;
730 #endif /* NS_IMPL_COCOA */
732 extern NSArray
*ns_send_types
, *ns_return_types
;
733 extern NSString
*ns_app_name
;
734 extern EmacsMenu
*svcsMenu
;
736 /* Apple removed the declaration, but kept the implementation */
737 #if defined (NS_IMPL_COCOA)
738 @interface
NSApplication (EmacsApp
)
739 - (void)setAppleMenu
: (NSMenu
*)menu
;
743 #endif /* __OBJC__ */
747 /* ==========================================================================
751 ========================================================================== */
753 /* Special keycodes that we pass down the event chain */
754 #define KEY_NS_POWER_OFF ((1<<28)|(0<<16)|1)
755 #define KEY_NS_OPEN_FILE ((1<<28)|(0<<16)|2)
756 #define KEY_NS_OPEN_TEMP_FILE ((1<<28)|(0<<16)|3)
757 #define KEY_NS_CHANGE_FONT ((1<<28)|(0<<16)|7)
758 #define KEY_NS_OPEN_FILE_LINE ((1<<28)|(0<<16)|8)
759 #define KEY_NS_PUT_WORKING_TEXT ((1<<28)|(0<<16)|9)
760 #define KEY_NS_UNPUT_WORKING_TEXT ((1<<28)|(0<<16)|10)
761 #define KEY_NS_SPI_SERVICE_CALL ((1<<28)|(0<<16)|11)
762 #define KEY_NS_NEW_FRAME ((1<<28)|(0<<16)|12)
763 #define KEY_NS_TOGGLE_TOOLBAR ((1<<28)|(0<<16)|13)
764 #define KEY_NS_SHOW_PREFS ((1<<28)|(0<<16)|14)
766 /* could use list to store these, but rest of emacs has a big infrastructure
767 for managing a table of bitmap "records" */
768 struct ns_bitmap_record
777 int height
, width
, depth
;
780 /* this to map between emacs color indices and NSColor objects */
781 struct ns_color_table
787 NSMutableSet
*empty_indices
;
793 #define NS_COLOR_CAPACITY 256
795 #define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
796 #define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
798 #define ALPHA_FROM_ULONG(color) ((color) >> 24)
799 #define RED_FROM_ULONG(color) (((color) >> 16) & 0xff)
800 #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
801 #define BLUE_FROM_ULONG(color) ((color) & 0xff)
803 /* Do not change `* 0x101' in the following lines to `<< 8'. If
804 changed, image masks in 1-bit depth will not work. */
805 #define RED16_FROM_ULONG(color) (RED_FROM_ULONG(color) * 0x101)
806 #define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
807 #define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)
809 /* this extends font backend font */
814 char *name
; /* PostScript name, uniquely identifies on NS systems */
816 /* The following metrics are stored as float rather than int. */
818 float width
; /* Maximum advance for the font. */
825 #if defined (NS_IMPL_COCOA)
834 char bold
, ital
; /* convenience flags */
836 XCharStruct max_bounds
;
837 /* we compute glyph codes and metrics on-demand in blocks of 256 indexed
839 unsigned short **glyphs
; /* map Unicode index to glyph */
840 struct font_metrics
**metrics
;
844 /* init'd in ns_initialize_display_info () */
845 struct ns_display_info
847 /* Chain of all ns_display_info structures. */
848 struct ns_display_info
*next
;
850 /* The generic display parameters corresponding to this NS display. */
851 struct terminal
*terminal
;
853 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
854 Lisp_Object name_list_element
;
856 /* The number of fonts loaded. */
859 /* Minimum width over all characters in all fonts in font_table. */
860 int smallest_char_width
;
862 /* Minimum font height over all fonts in font_table. */
863 int smallest_font_height
;
865 struct ns_bitmap_record
*bitmaps
;
866 ptrdiff_t bitmaps_size
;
867 ptrdiff_t bitmaps_last
;
869 struct ns_color_table
*color_table
;
871 /* DPI resolution of this screen */
874 /* Mask of things that cause the mouse to be grabbed */
886 /* The cursor to use for vertical scroll bars. */
887 Cursor vertical_scroll_bar_cursor
;
889 /* The cursor to use for horizontal scroll bars. */
890 Cursor horizontal_scroll_bar_cursor
;
892 /* Information about the range of text currently shown in
894 Mouse_HLInfo mouse_highlight
;
896 struct frame
*x_highlight_frame
;
897 struct frame
*x_focus_frame
;
899 /* The frame where the mouse was last time we reported a mouse event. */
900 struct frame
*last_mouse_frame
;
902 /* The frame where the mouse was last time we reported a mouse motion. */
903 struct frame
*last_mouse_motion_frame
;
905 /* Position where the mouse was last time we reported a motion.
906 This is a position on last_mouse_motion_frame. */
907 int last_mouse_motion_x
;
908 int last_mouse_motion_y
;
910 /* Where the mouse was last time we reported a mouse position. */
911 NSRect last_mouse_glyph
;
913 /* Time of last mouse movement. */
914 Time last_mouse_movement_time
;
916 /* The scroll bar in which the last motion event occurred. */
918 EmacsScroller
*last_mouse_scroll_bar
;
920 void *last_mouse_scroll_bar
;
924 /* This is a chain of structures for all the NS displays currently in use. */
925 extern struct ns_display_info
*x_display_list
;
932 NSColor
*cursor_color
;
933 NSColor
*foreground_color
;
934 NSColor
*background_color
;
935 EmacsToolbar
*toolbar
;
940 void *foreground_color
;
941 void *background_color
;
945 /* NSCursors init'ed in initFrameFromEmacs */
947 Cursor nontext_cursor
;
948 Cursor modeline_cursor
;
950 Cursor hourglass_cursor
;
951 Cursor horizontal_drag_cursor
;
952 Cursor vertical_drag_cursor
;
955 Cursor current_pointer
;
957 /* lord knows why Emacs needs to know about our Window ids.. */
958 Window window_desc
, parent_desc
;
959 char explicit_parent
;
964 /* If a fontset is specified for this frame instead of font, this
965 value contains an ID of the fontset, else -1. */
966 int fontset
; /* only used with font_backend */
971 /* The size of the extra width currently allotted for vertical
972 scroll bars, in pixels. */
973 int vertical_scroll_bar_extra
;
975 /* The height of the titlebar decoration (included in NSWindow's frame). */
978 /* The height of the toolbar if displayed, else 0. */
981 /* This is the Emacs structure for the NS display this frame is on. */
982 struct ns_display_info
*display_info
;
984 /* Non-zero if we are zooming (maximizing) the frame. */
987 /* Non-zero if we are doing an animation, e.g. toggling the tool bar. */
991 /* this dummy decl needed to support TTYs */
998 /* This gives the ns_display_info structure for the display F is on. */
999 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.ns->display_info)
1000 #define FRAME_X_OUTPUT(f) ((f)->output_data.ns)
1001 #define FRAME_NS_WINDOW(f) ((f)->output_data.ns->window_desc)
1002 #define FRAME_X_WINDOW(f) ((f)->output_data.ns->window_desc)
1004 /* This is the `Display *' which frame F is on. */
1005 #define FRAME_NS_DISPLAY(f) (0)
1006 #define FRAME_X_DISPLAY(f) (0)
1007 #define FRAME_X_SCREEN(f) (0)
1008 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO(f)->visual
1010 #define FRAME_FOREGROUND_COLOR(f) ((f)->output_data.ns->foreground_color)
1011 #define FRAME_BACKGROUND_COLOR(f) ((f)->output_data.ns->background_color)
1013 #define NS_FACE_FOREGROUND(f) ((f)->foreground)
1014 #define NS_FACE_BACKGROUND(f) ((f)->background)
1015 #define FRAME_NS_TITLEBAR_HEIGHT(f) ((f)->output_data.ns->titlebar_height)
1016 #define FRAME_TOOLBAR_HEIGHT(f) ((f)->output_data.ns->toolbar_height)
1018 #define FRAME_DEFAULT_FACE(f) FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID)
1020 #define FRAME_NS_VIEW(f) ((f)->output_data.ns->view)
1021 #define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
1022 #define FRAME_POINTER_TYPE(f) ((f)->output_data.ns->current_pointer)
1024 #define FRAME_FONT(f) ((f)->output_data.ns->font)
1027 #define XNS_SCROLL_BAR(vec) ((id) XSAVE_POINTER (vec, 0))
1029 #define XNS_SCROLL_BAR(vec) XSAVE_POINTER (vec, 0)
1032 /* Compute pixel size for vertical scroll bars */
1033 #define NS_SCROLL_BAR_WIDTH(f) \
1034 (FRAME_HAS_VERTICAL_SCROLL_BARS (f) \
1035 ? rint (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0 \
1036 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f) \
1037 : (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f))) \
1040 /* Compute pixel size for horizontal scroll bars */
1041 #define NS_SCROLL_BAR_HEIGHT(f) \
1042 (FRAME_HAS_HORIZONTAL_SCROLL_BARS (f) \
1043 ? rint (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0 \
1044 ? FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) \
1045 : (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f))) \
1048 /* Difference btwn char-column-calculated and actual SB widths.
1049 This is only a concern for rendering when SB on left. */
1050 #define NS_SCROLL_BAR_ADJUST(w, f) \
1051 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) ? \
1052 (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f) \
1053 - NS_SCROLL_BAR_WIDTH (f)) : 0)
1055 /* Difference btwn char-line-calculated and actual SB heights.
1056 This is only a concern for rendering when SB on top. */
1057 #define NS_SCROLL_BAR_ADJUST_HORIZONTALLY(w, f) \
1058 (WINDOW_HAS_HORIZONTAL_SCROLL_BARS (w) ? \
1059 (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f) \
1060 - NS_SCROLL_BAR_HEIGHT (f)) : 0)
1062 /* XXX: fix for GNUstep inconsistent accounting for titlebar */
1063 #ifdef NS_IMPL_GNUSTEP
1064 #define NS_TOP_POS(f) ((f)->top_pos + 18)
1066 #define NS_TOP_POS(f) ((f)->top_pos)
1069 #define FRAME_NS_FONT_TABLE(f) (FRAME_DISPLAY_INFO (f)->font_table)
1071 #define FRAME_FONTSET(f) ((f)->output_data.ns->fontset)
1073 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.ns->baseline_offset)
1074 #define BLACK_PIX_DEFAULT(f) 0x000000
1075 #define WHITE_PIX_DEFAULT(f) 0xFFFFFF
1077 /* First position where characters can be shown (instead of scrollbar, if
1079 #define FIRST_CHAR_POSITION(f) \
1080 (! (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) ? 0 \
1081 : FRAME_SCROLL_BAR_COLS (f))
1083 extern struct ns_display_info
*ns_term_init (Lisp_Object display_name
);
1084 extern void ns_term_shutdown (int sig
);
1086 /* constants for text rendering */
1087 #define NS_DUMPGLYPH_NORMAL 0
1088 #define NS_DUMPGLYPH_CURSOR 1
1089 #define NS_DUMPGLYPH_FOREGROUND 2
1090 #define NS_DUMPGLYPH_MOUSEFACE 3
1094 /* In nsfont, called from fontset.c */
1095 extern void nsfont_make_fontset_for_font (Lisp_Object name
,
1096 Lisp_Object font_object
);
1098 /* In nsfont, for debugging */
1099 struct glyph_string
;
1100 void ns_dump_glyphstring (struct glyph_string
*s
) EXTERNALLY_VISIBLE
;
1102 /* Implemented in nsterm, published in or needed from nsfns. */
1103 extern Lisp_Object
ns_list_fonts (struct frame
*f
, Lisp_Object pattern
,
1104 int size
, int maxnames
);
1105 extern void ns_clear_frame (struct frame
*f
);
1107 extern const char *ns_xlfd_to_fontname (const char *xlfd
);
1109 extern Lisp_Object
ns_map_event_to_object (void);
1111 extern Lisp_Object
ns_string_from_pasteboard (id pb
);
1112 extern void ns_string_to_pasteboard (id pb
, Lisp_Object str
);
1114 extern Lisp_Object
ns_get_local_selection (Lisp_Object selection_name
,
1115 Lisp_Object target_type
);
1116 extern void nxatoms_of_nsselect (void);
1117 extern void ns_set_doc_edited (void);
1120 ns_defined_color (struct frame
*f
,
1122 XColor
*color_def
, bool alloc
,
1125 ns_query_color (void *col
, XColor
*color_def
, int setPixel
);
1128 extern int ns_lisp_to_color (Lisp_Object color
, NSColor
**col
);
1129 extern NSColor
*ns_lookup_indexed_color (unsigned long idx
, struct frame
*f
);
1130 extern unsigned long ns_index_color (NSColor
*color
, struct frame
*f
);
1131 extern const char *ns_get_pending_menu_title (void);
1132 extern void ns_check_menu_open (NSMenu
*menu
);
1133 extern void ns_check_pending_open_menu (void);
1136 /* C access to ObjC functionality */
1137 extern void ns_release_object (void *obj
);
1138 extern void ns_retain_object (void *obj
);
1139 extern void *ns_alloc_autorelease_pool (void);
1140 extern void ns_release_autorelease_pool (void *);
1141 extern const char *ns_get_defaults_value (const char *key
);
1142 extern void ns_init_locale (void);
1146 extern void update_frame_tool_bar (struct frame
*f
);
1147 extern void free_frame_tool_bar (struct frame
*f
);
1148 extern Lisp_Object
find_and_return_menu_selection (struct frame
*f
,
1151 extern Lisp_Object
ns_popup_dialog (struct frame
*, Lisp_Object header
,
1152 Lisp_Object contents
);
1154 #define NSAPP_DATA2_RUNASSCRIPT 10
1155 extern void ns_run_ascript (void);
1157 #define NSAPP_DATA2_RUNFILEDIALOG 11
1158 extern void ns_run_file_dialog (void);
1160 extern const char *ns_etc_directory (void);
1161 extern const char *ns_exec_path (void);
1162 extern const char *ns_load_path (void);
1163 extern void syms_of_nsterm (void);
1164 extern void syms_of_nsfns (void);
1165 extern void syms_of_nsmenu (void);
1166 extern void syms_of_nsselect (void);
1168 /* From nsimage.m, needed in image.c */
1170 extern void *ns_image_from_XBM (char *bits
, int width
, int height
,
1171 unsigned long fg
, unsigned long bg
);
1172 extern void *ns_image_for_XPM (int width
, int height
, int depth
);
1173 extern void *ns_image_from_file (Lisp_Object file
);
1174 extern bool ns_load_image (struct frame
*f
, struct image
*img
,
1175 Lisp_Object spec_file
, Lisp_Object spec_data
);
1176 extern int ns_image_width (void *img
);
1177 extern int ns_image_height (void *img
);
1178 extern unsigned long ns_get_pixel (void *img
, int x
, int y
);
1179 extern void ns_put_pixel (void *img
, int x
, int y
, unsigned long argb
);
1180 extern void ns_set_alpha (void *img
, int x
, int y
, unsigned char a
);
1182 extern int x_display_pixel_height (struct ns_display_info
*);
1183 extern int x_display_pixel_width (struct ns_display_info
*);
1185 /* This in nsterm.m */
1186 extern float ns_antialias_threshold
;
1187 extern void x_destroy_window (struct frame
*f
);
1188 extern int ns_select (int nfds
, fd_set
*readfds
, fd_set
*writefds
,
1189 fd_set
*exceptfds
, struct timespec
const *timeout
,
1190 sigset_t
const *sigmask
);
1191 extern unsigned long ns_get_rgb_color (struct frame
*f
,
1192 float r
, float g
, float b
, float a
);
1195 extern void ns_init_events (struct input_event
*);
1196 extern void ns_finish_events (void);
1199 /* Needed in nsfns.m. */
1201 ns_set_represented_filename (NSString
* fstr
, struct frame
*f
);
1205 #ifdef NS_IMPL_GNUSTEP
1206 extern char gnustep_base_version
[]; /* version tracking */
1210 #define MINHEIGHT 10
1212 /* Screen max coordinate
1213 Using larger coordinates causes movewindow/placewindow to abort */
1214 #define SCREENMAX 16000
1216 #define NS_SCROLL_BAR_WIDTH_DEFAULT [EmacsScroller scrollerWidth]
1217 #define NS_SCROLL_BAR_HEIGHT_DEFAULT [EmacsScroller scrollerHeight]
1218 /* This is to match emacs on other platforms, ugly though it is. */
1219 #define NS_SELECTION_BG_COLOR_DEFAULT @"LightGoldenrod2";
1220 #define NS_SELECTION_FG_COLOR_DEFAULT @"Black";
1221 #define RESIZE_HANDLE_SIZE 12
1223 /* Little utility macros */
1224 #define IN_BOUND(min, x, max) (((x) < (min)) \
1225 ? (min) : (((x)>(max)) ? (max) : (x)))
1226 #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
1228 /* macOS 10.12 deprecates a bunch of constants. */
1229 #if !defined (NS_IMPL_COCOA) || \
1230 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
1231 #define NSEventModifierFlagCommand NSCommandKeyMask
1232 #define NSEventModifierFlagControl NSControlKeyMask
1233 #define NSEventModifierFlagHelp NSHelpKeyMask
1234 #define NSEventModifierFlagNumericPad NSNumericPadKeyMask
1235 #define NSEventModifierFlagOption NSAlternateKeyMask
1236 #define NSEventModifierFlagShift NSShiftKeyMask
1237 #define NSCompositingOperationSourceOver NSCompositeSourceOver
1238 #define NSEventMaskApplicationDefined NSApplicationDefinedMask
1239 #define NSEventTypeApplicationDefined NSApplicationDefined
1240 #define NSEventTypeCursorUpdate NSCursorUpdate
1241 #define NSEventTypeMouseMoved NSMouseMoved
1242 #define NSEventTypeLeftMouseDown NSLeftMouseDown
1243 #define NSEventTypeRightMouseDown NSRightMouseDown
1244 #define NSEventTypeOtherMouseDown NSOtherMouseDown
1245 #define NSEventTypeLeftMouseUp NSLeftMouseUp
1246 #define NSEventTypeRightMouseUp NSRightMouseUp
1247 #define NSEventTypeOtherMouseUp NSOtherMouseUp
1248 #define NSEventTypeLeftMouseDragged NSLeftMouseDragged
1249 #define NSEventTypeRightMouseDragged NSRightMouseDragged
1250 #define NSEventTypeOtherMouseDragged NSOtherMouseDragged
1251 #define NSEventTypeScrollWheel NSScrollWheel
1252 #define NSEventTypeKeyDown NSKeyDown
1253 #define NSEventTypeKeyUp NSKeyUp
1254 #define NSEventTypeFlagsChanged NSFlagsChanged
1255 #define NSEventMaskAny NSAnyEventMask
1256 #define NSWindowStyleMaskBorderless NSBorderlessWindowMask
1257 #define NSWindowStyleMaskClosable NSClosableWindowMask
1258 #define NSWindowStyleMaskFullScreen NSFullScreenWindowMask
1259 #define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask
1260 #define NSWindowStyleMaskResizable NSResizableWindowMask
1261 #define NSWindowStyleMaskTitled NSTitledWindowMask
1262 #define NSAlertStyleCritical NSCriticalAlertStyle
1263 #define NSControlSizeRegular NSRegularControlSize
1266 #endif /* HAVE_NS */