1 /* Definitions and headers for communication with NeXT/Open/GNUstep API.
2 Copyright (C) 1989, 1993, 2005, 2008-2015 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
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 #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
43 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
44 #define HAVE_NATIVE_FS
47 #endif /* NS_IMPL_COCOA */
51 /* CGFloat on GNUstep may be 4 or 8 byte, but functions expect float* for some
53 On Cocoa >= 10.5, functions expect CGFloat*. Make compatible type. */
55 typedef CGFloat EmacsCGFloat
;
56 #elif GNUSTEP_GUI_MAJOR_VERSION > 0 || GNUSTEP_GUI_MINOR_VERSION >= 22
57 typedef CGFloat EmacsCGFloat
;
59 typedef float EmacsCGFloat
;
62 /* ==========================================================================
66 ========================================================================== */
68 /* Uncomment the following line to enable trace.
70 Hint: keep the trailing whitespace -- the version control system
71 will reject accidental commits. */
73 /* #define NSTRACE_ENABLED 1 */
76 /* Print a call tree containing all annotated functions.
78 The call structure of the functions is represented using
79 indentation and vertical lines. Extra information is printed using
80 horizontal lines that connect to the vertical line.
82 The return value is represented using the arrow "->>". For simple
83 functions, the arrow can be printed on the same line as the
84 function name. If more output is printed, it is connected to the
85 vertical line of the function.
87 The first column contains the file name, the second the line
88 number, and the third a number increasing for each trace line.
90 Note that the trace system, when enabled, use the GCC/Clang
93 For example (long lines manually split to reduce width):
95 nsterm.m : 1600: [ 4428] ns_fullscreen_hook
96 nsterm.m : 7006: [ 4429] | handleFS
97 nsterm.m : 7035: [ 4430] | +--- FULLSCREEN_MAXIMIZED
98 nsterm.m : 7627: [ 4431] | | performZoom
99 nsterm.m : 7636: [ 4432] | | | zoom
100 nsterm.m : 874: [ 4433] | | | | ns_update_auto_hide_menu_bar
101 nsterm.m : 6615: [ 4434] | | | | [windowWillUseStandardFrame:
102 defaultFrame:(X:0 Y:0)/(W:1600 H:1177)]
103 nsterm.m : 99: [ 4435] | | | | +--- fs_state: FULLSCREEN_NONE
104 nsterm.m : 119: [ 4436] | | | | +--- fs_before_fs: -1
105 nsterm.m : 115: [ 4437] | | | | +--- next_maximized: FULLSCREEN_MAXIMIZED
106 nsterm.m : 6619: [ 4438] | | | | +--- ns_userRect: (X:0 Y:0)/(W:0 H:0)
107 nsterm.m : 6620: [ 4439] | | | | +--- [sender frame]:
108 (X:0 Y:626)/(W:595 H:551)
109 nsterm.m : 6644: [ 4440] | | | | +--- ns_userRect (2):
110 (X:0 Y:626)/(W:595 H:551)
111 nsterm.m : 6684: [ 4441] | | | | +--- FULLSCREEN_MAXIMIZED
112 nsterm.m : 7057: [ 4442] | | | | | setFSValue
113 nsterm.m : 115: [ 4443] | | | | | +--- value: FULLSCREEN_MAXIMIZED
114 nsterm.m : 6711: [ 4444] | | | | +--- Final ns_userRect:
115 (X:0 Y:626)/(W:595 H:551)
116 nsterm.m : 6712: [ 4445] | | | | +--- Final maximized_width: 1600
117 nsterm.m : 6713: [ 4446] | | | | +--- Final maximized_height: 1177
118 nsterm.m : 119: [ 4447] | | | | +--- Final next_maximized: -1
119 nsterm.m : 6209: [ 4448] | | | | | windowWillResize: toSize: (W:1600 H:1177)
120 nsterm.m : 6210: [ 4449] | | | | | +--- [sender frame]:
121 (X:0 Y:626)/(W:595 H:551)
122 nsterm.m : 115: [ 4450] | | | | | +--- fs_state: FULLSCREEN_MAXIMIZED
123 nsterm.m : 6274: [ 4451] | | | | | +--- cols: 223 rows: 79
124 nsterm.m : 6299: [ 4452] | | | | | +->> (W:1596 H:1167)
125 nsterm.m : 6718: [ 4453] | | | | +->> (X:0 Y:0)/(W:1600 H:1177)
127 Here, "ns_fullscreen_hook" calls "handleFS", which is turn calls
128 "performZoom". This function calls "[super performZoom]", which
129 isn't annotated (so it doesn't show up in the trace). However, it
130 calls "zoom" which is annotated so it is part of the call trace.
131 Later, the method "windowWillUseStandardFrame" and the function
132 "setFSValue" are called. The lines with "+---" contain extra
133 information and lines containing "->>" represent return values. */
135 #ifndef NSTRACE_ENABLED
136 #define NSTRACE_ENABLED 0
140 extern int nstrace_num
;
141 extern int nstrace_depth
;
143 void nstrace_leave(int *);
145 /* printf-style trace output. Output is aligned with contained heading. */
146 #define NSTRACE_MSG_NO_DASHES(...) \
149 if (nstrace_enabled) \
151 fprintf (stderr, "%-10s:%5d: [%5d]%.*s", \
152 __FILE__, __LINE__, ++nstrace_num, \
153 2*nstrace_depth, " | | | | | | | | | | | | | | | .."); \
154 fprintf (stderr, __VA_ARGS__); \
155 fprintf (stderr, "\n"); \
160 #define NSTRACE_MSG(...) NSTRACE_MSG_NO_DASHES("+--- " __VA_ARGS__)
164 /* Macros for printing complex types.
166 NSTRACE_FMT_what -- Printf format string for "what".
167 NSTRACE_ARG_what(x) -- Printf argument for "what". */
169 #define NSTRACE_FMT_SIZE "(W:%.0f H:%.0f)"
170 #define NSTRACE_ARG_SIZE(elt) (elt).width, (elt).height
172 #define NSTRACE_FMT_POINT "(X:%.0f Y:%.0f)"
173 #define NSTRACE_ARG_POINT(elt) (elt).x, (elt).y
175 #define NSTRACE_FMT_RECT NSTRACE_FMT_POINT "/" NSTRACE_FMT_SIZE
176 #define NSTRACE_ARG_RECT(elt) \
177 NSTRACE_ARG_POINT((elt).origin), NSTRACE_ARG_SIZE((elt).size)
180 /* Macros for printing complex types as extra information. */
182 #define NSTRACE_SIZE(str,size) \
183 NSTRACE_MSG (str ": " NSTRACE_FMT_SIZE, \
184 NSTRACE_ARG_SIZE (size));
186 #define NSTRACE_POINT(str,point) \
187 NSTRACE_MSG (str ": " NSTRACE_FMT_POINT, \
188 NSTRACE_ARG_POINT (point));
190 #define NSTRACE_RECT(str,rect) \
191 NSTRACE_MSG (str ": " NSTRACE_FMT_RECT, \
192 NSTRACE_ARG_RECT (rect));
194 #define NSTRACE_FSTYPE(str,fs_type) \
197 if (nstrace_enabled) \
199 ns_print_fullscreen_type_name(str, fs_type); \
205 /* Return value macros.
207 NSTRACE_RETURN(fmt, ...) - Print a return value, support printf-style
208 format string and arguments.
210 NSTRACE_RETURN_what(obj) - Print a return value of kind WHAT.
212 NSTRACE_FMT_RETURN - A string literal representing a returned
213 value. Useful when creating a format string
214 to printf-like constructs like NSTRACE(). */
216 #define NSTRACE_FMT_RETURN "->>"
218 #define NSTRACE_RETURN(...) \
219 NSTRACE_MSG_NO_DASHES ("+" NSTRACE_FMT_RETURN " " __VA_ARGS__)
221 #define NSTRACE_RETURN_SIZE(size) \
222 NSTRACE_RETURN(NSTRACE_FMT_SIZE, NSTRACE_ARG_SIZE(size))
224 #define NSTRACE_RETURN_POINT(point) \
225 NSTRACE_RETURN(NSTRACE_FMT_POINT, NSTRACE_ARG_POINT(point))
227 #define NSTRACE_RETURN_RECT(rect) \
228 NSTRACE_RETURN(NSTRACE_FMT_RECT, NSTRACE_ARG_RECT(rect))
231 /* Function enter macros.
233 NSTRACE (fmt, ...) -- Enable trace output in current block
234 (typically a function). Accepts printf-style
237 NSTRACE_WHEN (cond, fmt, ...) -- Enable trace output when COND is true.
239 NSTRACE_UNLESS (cond, fmt, ...) -- Enable trace output unless COND is
244 #define NSTRACE_WHEN(cond, ...) \
245 __attribute__((cleanup(nstrace_leave))) \
246 int nstrace_enabled = (cond); \
247 if (nstrace_enabled) { ++nstrace_depth; } \
248 NSTRACE_MSG_NO_DASHES(__VA_ARGS__);
250 #endif /* NSTRACE_ENABLED */
252 #define NSTRACE(...) NSTRACE_WHEN(1, __VA_ARGS__)
253 #define NSTRACE_UNLESS(cond, ...) NSTRACE_WHEN(!(cond), __VA_ARGS__)
256 /* Non-trace replacement versions. */
258 #define NSTRACE_WHEN(...)
262 #define NSTRACE_MSG(...)
266 #define NSTRACE_SIZE(str,size)
269 #ifndef NSTRACE_POINT
270 #define NSTRACE_POINT(str,point)
274 #define NSTRACE_RECT(str,rect)
277 #ifndef NSTRACE_FSTYPE
278 #define NSTRACE_FSTYPE(str,fs_type)
281 #ifndef NSTRACE_RETURN_SIZE
282 #define NSTRACE_RETURN_SIZE(size)
285 #ifndef NSTRACE_RETURN_POINT
286 #define NSTRACE_RETURN_POINT(point)
289 #ifndef NSTRACE_RETURN_RECT
290 #define NSTRACE_RETURN_RECT(rect)
293 #ifndef NSTRACE_RETURN_FSTYPE
294 #define NSTRACE_RETURN_FSTYPE(fs_type)
299 /* ==========================================================================
301 NSColor, EmacsColor category.
303 ========================================================================== */
304 @interface
NSColor (EmacsColor
)
305 + (NSColor
*)colorForEmacsRed
:(CGFloat
)red green
:(CGFloat
)green
306 blue
:(CGFloat
)blue alpha
:(CGFloat
)alpha
;
307 - (NSColor
*)colorUsingDefaultColorSpace
;
311 /* ==========================================================================
313 The Emacs application
315 ========================================================================== */
317 /* We override sendEvent: as a means to stop/start the event loop */
318 @interface EmacsApp
: NSApplication
321 BOOL shouldKeepRunning
;
324 #ifdef NS_IMPL_GNUSTEP
325 BOOL applicationDidFinishLaunchingCalled
;
330 - (void)logNotification
: (NSNotification
*)notification
;
331 - (void)antialiasThresholdDidChange
:(NSNotification
*)notification
;
332 - (void)sendEvent
: (NSEvent
*)theEvent
;
333 - (void)showPreferencesWindow
: (id
)sender
;
334 - (BOOL
) openFile
: (NSString
*)fileName
;
335 - (void)fd_handler
: (id
)unused
;
336 - (void)timeout_handler
: (NSTimer
*)timedEntry
;
337 - (BOOL
)fulfillService
: (NSString
*)name withArg
: (NSString
*)arg
;
338 #ifdef NS_IMPL_GNUSTEP
339 - (void)sendFromMainThread
:(id
)unused
;
343 #ifdef NS_IMPL_GNUSTEP
344 /* Dummy class to get rid of startup warnings. */
345 @interface EmacsDocument
: NSDocument
351 /* ==========================================================================
355 ========================================================================== */
360 @interface EmacsView
: NSView
<NSTextInput
, NSWindowDelegate
>
362 @interface EmacsView
: NSView
<NSTextInput
>
367 BOOL maximizing_resize
;
370 NSString
*workingText
;
371 BOOL processingCompose
;
372 int fs_state
, fs_before_fs
, next_maximized
;
373 int tibar_height
, tobar_height
, bwidth
;
374 int maximized_width
, maximized_height
;
375 NSWindow
*nonfs_window
;
378 struct frame
*emacsframe
;
380 int scrollbarsNeedingUpdate
;
381 EmacsToolbar
*toolbar
;
383 BOOL wait_for_tool_bar
;
386 /* AppKit-side interface */
387 - menuDown
: (id
)sender
;
388 - toolbarClicked
: (id
)item
;
389 - toggleToolbar
: (id
)sender
;
390 - (void)keyDown
: (NSEvent
*)theEvent
;
391 - (void)mouseDown
: (NSEvent
*)theEvent
;
392 - (void)mouseUp
: (NSEvent
*)theEvent
;
393 - setMiniwindowImage
: (BOOL
)setMini
;
395 /* Emacs-side interface */
396 - initFrameFromEmacs
: (struct frame
*) f
;
397 - (void) setRows
: (int) r andColumns
: (int) c
;
398 - (void) setWindowClosing
: (BOOL
)closing
;
399 - (EmacsToolbar
*) toolbar
;
400 - (void) deleteWorkingText
;
401 - (void) updateFrameSize
: (BOOL
) delay
;
403 - (void) setFSValue
: (int)value
;
404 - (void) toggleFullScreen
: (id
) sender
;
406 - (BOOL
) isFullscreen
;
407 #ifdef HAVE_NATIVE_FS
408 - (void) updateCollectionBehavior
;
411 #ifdef NS_IMPL_GNUSTEP
412 - (void)windowDidMove
: (id
)sender
;
414 - (int)fullscreenState
;
418 /* Small utility used for processing resize events under Cocoa. */
419 @interface EmacsWindow
: NSWindow
426 /* Fullscreen version of the above. */
427 @interface EmacsFSWindow
: EmacsWindow
432 /* ==========================================================================
434 The main menu implementation
436 ========================================================================== */
439 @interface EmacsMenu
: NSMenu
<NSMenuDelegate
>
441 @interface EmacsMenu
: NSMenu
445 unsigned long keyEquivModMask
;
448 - initWithTitle
: (NSString
*)title frame
: (struct frame
*)f
;
449 - (void)setFrame
: (struct frame
*)f
;
450 - (void)menuNeedsUpdate
: (NSMenu
*)menu
; /* (delegate method) */
451 - (NSString
*)parseKeyEquiv
: (const char *)key
;
452 - (NSMenuItem
*)addItemWithWidgetValue
: (void *)wvptr
;
453 - (void)fillWithWidgetValue
: (void *)wvptr
;
454 - (void)fillWithWidgetValue
: (void *)wvptr frame
: (struct frame
*)f
;
455 - (EmacsMenu
*)addSubmenuWithTitle
: (const char *)title forFrame
: (struct frame
*)f
;
457 - (Lisp_Object
)runMenuAt
: (NSPoint
)p forFrame
: (struct frame
*)f
458 keymaps
: (bool)keymaps
;
462 /* ==========================================================================
466 ========================================================================== */
471 @interface EmacsToolbar
: NSToolbar
<NSToolbarDelegate
>
473 @interface EmacsToolbar
: NSToolbar
476 EmacsView
*emacsView
;
477 NSMutableDictionary
*identifierToItem
;
478 NSMutableArray
*activeIdentifiers
;
479 NSArray
*prevIdentifiers
;
480 unsigned long enablement
, prevEnablement
;
482 - initForView
: (EmacsView
*)view withIdentifier
: (NSString
*)identifier
;
483 - (void) clearActive
;
486 - (void) addDisplayItemWithImage
: (EmacsImage
*)img
489 helpText
: (const char *)help
490 enabled
: (BOOL
)enabled
;
492 /* delegate methods */
493 - (NSToolbarItem
*)toolbar
: (NSToolbar
*)toolbar
494 itemForItemIdentifier
: (NSString
*)itemIdentifier
495 willBeInsertedIntoToolbar
: (BOOL
)flag
;
496 - (NSArray
*)toolbarDefaultItemIdentifiers
: (NSToolbar
*)toolbar
;
497 - (NSArray
*)toolbarAllowedItemIdentifiers
: (NSToolbar
*)toolbar
;
501 /* ==========================================================================
503 Message / question windows
505 ========================================================================== */
507 @interface EmacsDialogPanel
: NSPanel
509 NSTextField
*command
;
513 BOOL timer_fired
, window_closed
;
514 Lisp_Object dialog_return
;
515 Lisp_Object
*button_values
;
517 - initFromContents
: (Lisp_Object
)menu isQuestion
: (BOOL
)isQ
;
518 - (void)process_dialog
: (Lisp_Object
)list
;
519 - (void)addButton
: (char *)str value
: (int)tag row
: (int)row
;
520 - (void)addString
: (char *)str row
: (int)row
;
522 - (Lisp_Object
)runDialogAt
: (NSPoint
)p
;
523 - (void)timeout_handler
: (NSTimer
*)timedEntry
;
527 @interface EmacsTooltip
: NSObject
<NSWindowDelegate
>
529 @interface EmacsTooltip
: NSObject
533 NSTextField
*textField
;
537 - (void) setText
: (char *)text
;
538 - (void) showAtX
: (int)x Y
: (int)y
for: (int)seconds
;
545 /* ==========================================================================
547 File open/save panels
548 This and next override methods to handle keyboard input in panels.
550 ========================================================================== */
552 @interface EmacsSavePanel
: NSSavePanel
556 @interface EmacsOpenPanel
: NSOpenPanel
561 @interface EmacsFileDelegate
: NSObject
564 - (BOOL
)panel
: (id
)sender isValidFilename
: (NSString
*)filename
;
565 - (BOOL
)panel
: (id
)sender shouldShowFilename
: (NSString
*)filename
;
566 - (NSString
*)panel
: (id
)sender userEnteredFilename
: (NSString
*)filename
567 confirmed
: (BOOL
)okFlag
;
571 /* ==========================================================================
575 ========================================================================== */
577 @interface EmacsImage
: NSImage
579 NSBitmapImageRep
*bmRep
; /* used for accessing pixel data */
580 unsigned char *pixmapData
[5]; /* shortcut to access pixel data */
581 NSColor
*stippleMask
;
582 unsigned long xbm_fg
;
584 + allocInitFromFile
: (Lisp_Object
)file
;
586 - initFromXBM
: (unsigned char *)bits width
: (int)w height
: (int)h
587 fg
: (unsigned long)fg bg
: (unsigned long)bg
;
588 - setXBMColor
: (NSColor
*)color
;
589 - initForXPMWithDepth
: (int)depth width
: (int)width height
: (int)height
;
590 - (void)setPixmapData
;
591 - (unsigned long)getPixelAtX
: (int)x Y
: (int)y
;
592 - (void)setPixelAtX
: (int)x Y
: (int)y toRed
: (unsigned char)r
593 green
: (unsigned char)g blue
: (unsigned char)b
594 alpha
:(unsigned char)a
;
595 - (void)setAlphaAtX
: (int)x Y
: (int)y to
: (unsigned char)a
;
596 - (NSColor
*)stippleMask
;
600 /* ==========================================================================
604 ========================================================================== */
606 @interface EmacsScroller
: NSScroller
608 struct window
*window
;
610 NSResponder
*prevResponder
;
612 /* offset to the bottom of knob of last mouse down */
613 CGFloat last_mouse_offset
;
616 enum scroll_bar_part last_hit_part
;
620 /* optimize against excessive positioning calls generated by emacs */
626 - initFrame
: (NSRect
)r window
: (Lisp_Object
)win
;
627 - (void)setFrame
: (NSRect
)r
;
629 - setPosition
: (int) position portion
: (int) portion whole
: (int) whole
;
630 - (int) checkSamePosition
: (int)position portion
: (int)portion
632 - (void) sendScrollEventAtLoc
: (float)loc fromEvent
: (NSEvent
*)e
;
633 - repeatScroll
: (NSTimer
*)sender
;
637 + (CGFloat
)scrollerWidth
;
641 /* ==========================================================================
645 ========================================================================== */
649 @interface EmacsGlyphStorage
: NSObject
<NSGlyphStorage
>
652 NSAttributedString
*attrStr
;
653 NSMutableDictionary
*dict
;
655 unsigned long maxChar
, maxGlyph
;
658 - initWithCapacity
: (unsigned long) c
;
659 - (void) setString
: (NSString
*)str font
: (NSFont
*)font
;
661 #endif /* NS_IMPL_COCOA */
663 extern NSArray
*ns_send_types
, *ns_return_types
;
664 extern NSString
*ns_app_name
;
665 extern EmacsMenu
*mainMenu
, *svcsMenu
, *dockMenu
;
667 /* Apple removed the declaration, but kept the implementation */
668 #if defined (NS_IMPL_COCOA)
669 @interface
NSApplication (EmacsApp
)
670 - (void)setAppleMenu
: (NSMenu
*)menu
;
674 #endif /* __OBJC__ */
678 /* ==========================================================================
682 ========================================================================== */
684 /* Special keycodes that we pass down the event chain */
685 #define KEY_NS_POWER_OFF ((1<<28)|(0<<16)|1)
686 #define KEY_NS_OPEN_FILE ((1<<28)|(0<<16)|2)
687 #define KEY_NS_OPEN_TEMP_FILE ((1<<28)|(0<<16)|3)
688 #define KEY_NS_CHANGE_FONT ((1<<28)|(0<<16)|7)
689 #define KEY_NS_OPEN_FILE_LINE ((1<<28)|(0<<16)|8)
690 #define KEY_NS_PUT_WORKING_TEXT ((1<<28)|(0<<16)|9)
691 #define KEY_NS_UNPUT_WORKING_TEXT ((1<<28)|(0<<16)|10)
692 #define KEY_NS_SPI_SERVICE_CALL ((1<<28)|(0<<16)|11)
693 #define KEY_NS_NEW_FRAME ((1<<28)|(0<<16)|12)
694 #define KEY_NS_TOGGLE_TOOLBAR ((1<<28)|(0<<16)|13)
695 #define KEY_NS_SHOW_PREFS ((1<<28)|(0<<16)|14)
697 /* could use list to store these, but rest of emacs has a big infrastructure
698 for managing a table of bitmap "records" */
699 struct ns_bitmap_record
708 int height
, width
, depth
;
711 /* this to map between emacs color indices and NSColor objects */
712 struct ns_color_table
718 NSMutableSet
*empty_indices
;
724 #define NS_COLOR_CAPACITY 256
726 #define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
727 #define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
729 #define ALPHA_FROM_ULONG(color) ((color) >> 24)
730 #define RED_FROM_ULONG(color) (((color) >> 16) & 0xff)
731 #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
732 #define BLUE_FROM_ULONG(color) ((color) & 0xff)
734 /* Do not change `* 0x101' in the following lines to `<< 8'. If
735 changed, image masks in 1-bit depth will not work. */
736 #define RED16_FROM_ULONG(color) (RED_FROM_ULONG(color) * 0x101)
737 #define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
738 #define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)
740 /* this extends font backend font */
745 char *name
; /* PostScript name, uniquely identifies on NS systems */
747 /* The following metrics are stored as float rather than int. */
749 float width
; /* Maximum advance for the font. */
756 #if defined (NS_IMPL_COCOA)
765 char bold
, ital
; /* convenience flags */
767 XCharStruct max_bounds
;
768 /* we compute glyph codes and metrics on-demand in blocks of 256 indexed
770 unsigned short **glyphs
; /* map Unicode index to glyph */
771 struct font_metrics
**metrics
;
775 /* init'd in ns_initialize_display_info () */
776 struct ns_display_info
778 /* Chain of all ns_display_info structures. */
779 struct ns_display_info
*next
;
781 /* The generic display parameters corresponding to this NS display. */
782 struct terminal
*terminal
;
784 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
785 Lisp_Object name_list_element
;
787 /* The number of fonts loaded. */
790 /* Minimum width over all characters in all fonts in font_table. */
791 int smallest_char_width
;
793 /* Minimum font height over all fonts in font_table. */
794 int smallest_font_height
;
796 struct ns_bitmap_record
*bitmaps
;
797 ptrdiff_t bitmaps_size
;
798 ptrdiff_t bitmaps_last
;
800 struct ns_color_table
*color_table
;
802 /* DPI resolution of this screen */
805 /* Mask of things that cause the mouse to be grabbed */
817 /* The cursor to use for vertical scroll bars. */
818 Cursor vertical_scroll_bar_cursor
;
820 /* The cursor to use for horizontal scroll bars. */
821 Cursor horizontal_scroll_bar_cursor
;
823 /* Information about the range of text currently shown in
825 Mouse_HLInfo mouse_highlight
;
827 struct frame
*x_highlight_frame
;
828 struct frame
*x_focus_frame
;
830 /* The frame where the mouse was last time we reported a mouse event. */
831 struct frame
*last_mouse_frame
;
833 /* The frame where the mouse was last time we reported a mouse motion. */
834 struct frame
*last_mouse_motion_frame
;
836 /* Position where the mouse was last time we reported a motion.
837 This is a position on last_mouse_motion_frame. */
838 int last_mouse_motion_x
;
839 int last_mouse_motion_y
;
841 /* Where the mouse was last time we reported a mouse position. */
842 NSRect last_mouse_glyph
;
844 /* Time of last mouse movement. */
845 Time last_mouse_movement_time
;
847 /* The scroll bar in which the last motion event occurred. */
849 EmacsScroller
*last_mouse_scroll_bar
;
851 void *last_mouse_scroll_bar
;
855 /* This is a chain of structures for all the NS displays currently in use. */
856 extern struct ns_display_info
*x_display_list
;
858 extern struct ns_display_info
*ns_display_info_for_name (Lisp_Object name
);
865 NSColor
*cursor_color
;
866 NSColor
*foreground_color
;
867 NSColor
*background_color
;
868 EmacsToolbar
*toolbar
;
873 void *foreground_color
;
874 void *background_color
;
878 /* NSCursors init'ed in initFrameFromEmacs */
880 Cursor nontext_cursor
;
881 Cursor modeline_cursor
;
883 Cursor hourglass_cursor
;
884 Cursor horizontal_drag_cursor
;
885 Cursor vertical_drag_cursor
;
888 Cursor current_pointer
;
890 /* lord knows why Emacs needs to know about our Window ids.. */
891 Window window_desc
, parent_desc
;
892 char explicit_parent
;
897 /* If a fontset is specified for this frame instead of font, this
898 value contains an ID of the fontset, else -1. */
899 int fontset
; /* only used with font_backend */
904 /* The size of the extra width currently allotted for vertical
905 scroll bars, in pixels. */
906 int vertical_scroll_bar_extra
;
908 /* The height of the titlebar decoration (included in NSWindow's frame). */
911 /* The height of the toolbar if displayed, else 0. */
914 /* This is the Emacs structure for the NS display this frame is on. */
915 struct ns_display_info
*display_info
;
917 /* Non-zero if we are zooming (maximizing) the frame. */
920 /* Non-zero if we are doing an animation, e.g. toggling the tool bar. */
924 /* this dummy decl needed to support TTYs */
931 /* This gives the ns_display_info structure for the display F is on. */
932 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.ns->display_info)
933 #define FRAME_X_OUTPUT(f) ((f)->output_data.ns)
934 #define FRAME_NS_WINDOW(f) ((f)->output_data.ns->window_desc)
935 #define FRAME_X_WINDOW(f) ((f)->output_data.ns->window_desc)
937 /* This is the `Display *' which frame F is on. */
938 #define FRAME_NS_DISPLAY(f) (0)
939 #define FRAME_X_DISPLAY(f) (0)
940 #define FRAME_X_SCREEN(f) (0)
941 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO(f)->visual
943 #define FRAME_FOREGROUND_COLOR(f) ((f)->output_data.ns->foreground_color)
944 #define FRAME_BACKGROUND_COLOR(f) ((f)->output_data.ns->background_color)
946 #define NS_FACE_FOREGROUND(f) ((f)->foreground)
947 #define NS_FACE_BACKGROUND(f) ((f)->background)
948 #define FRAME_NS_TITLEBAR_HEIGHT(f) ((f)->output_data.ns->titlebar_height)
949 #define FRAME_TOOLBAR_HEIGHT(f) ((f)->output_data.ns->toolbar_height)
951 #define FRAME_DEFAULT_FACE(f) FACE_FROM_ID (f, DEFAULT_FACE_ID)
953 #define FRAME_NS_VIEW(f) ((f)->output_data.ns->view)
954 #define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
955 #define FRAME_POINTER_TYPE(f) ((f)->output_data.ns->current_pointer)
957 #define FRAME_FONT(f) ((f)->output_data.ns->font)
960 #define XNS_SCROLL_BAR(vec) ((id) XSAVE_POINTER (vec, 0))
962 #define XNS_SCROLL_BAR(vec) XSAVE_POINTER (vec, 0)
965 /* Compute pixel size for vertical scroll bars */
966 #define NS_SCROLL_BAR_WIDTH(f) \
967 (FRAME_HAS_VERTICAL_SCROLL_BARS (f) \
968 ? rint (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0 \
969 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f) \
970 : (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f))) \
973 /* Compute pixel size for horizontal scroll bars */
974 #define NS_SCROLL_BAR_HEIGHT(f) \
975 (FRAME_HAS_HORIZONTAL_SCROLL_BARS (f) \
976 ? rint (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0 \
977 ? FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) \
978 : (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f))) \
981 /* Difference btwn char-column-calculated and actual SB widths.
982 This is only a concern for rendering when SB on left. */
983 #define NS_SCROLL_BAR_ADJUST(w, f) \
984 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) ? \
985 (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f) \
986 - NS_SCROLL_BAR_WIDTH (f)) : 0)
988 /* Difference btwn char-line-calculated and actual SB heights.
989 This is only a concern for rendering when SB on top. */
990 #define NS_SCROLL_BAR_ADJUST_HORIZONTALLY(w, f) \
991 (WINDOW_HAS_HORIZONTAL_SCROLL_BARS (w) ? \
992 (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f) \
993 - NS_SCROLL_BAR_HEIGHT (f)) : 0)
995 /* XXX: fix for GNUstep inconsistent accounting for titlebar */
996 #ifdef NS_IMPL_GNUSTEP
997 #define NS_TOP_POS(f) ((f)->top_pos + 18)
999 #define NS_TOP_POS(f) ((f)->top_pos)
1002 #define FRAME_NS_FONT_TABLE(f) (FRAME_DISPLAY_INFO (f)->font_table)
1004 #define FRAME_FONTSET(f) ((f)->output_data.ns->fontset)
1006 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.ns->baseline_offset)
1007 #define BLACK_PIX_DEFAULT(f) 0x000000
1008 #define WHITE_PIX_DEFAULT(f) 0xFFFFFF
1010 /* First position where characters can be shown (instead of scrollbar, if
1012 #define FIRST_CHAR_POSITION(f) \
1013 (! (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) ? 0 \
1014 : FRAME_SCROLL_BAR_COLS (f))
1016 extern struct ns_display_info
*ns_term_init (Lisp_Object display_name
);
1017 extern void ns_term_shutdown (int sig
);
1019 /* constants for text rendering */
1020 #define NS_DUMPGLYPH_NORMAL 0
1021 #define NS_DUMPGLYPH_CURSOR 1
1022 #define NS_DUMPGLYPH_FOREGROUND 2
1023 #define NS_DUMPGLYPH_MOUSEFACE 3
1027 /* In nsfont, called from fontset.c */
1028 extern void nsfont_make_fontset_for_font (Lisp_Object name
,
1029 Lisp_Object font_object
);
1031 /* In nsfont, for debugging */
1032 struct glyph_string
;
1033 void ns_dump_glyphstring (struct glyph_string
*s
);
1035 /* Implemented in nsterm, published in or needed from nsfns. */
1036 extern Lisp_Object
ns_list_fonts (struct frame
*f
, Lisp_Object pattern
,
1037 int size
, int maxnames
);
1038 extern void ns_clear_frame (struct frame
*f
);
1040 extern const char *ns_xlfd_to_fontname (const char *xlfd
);
1042 extern Lisp_Object
ns_map_event_to_object (void);
1044 extern Lisp_Object
ns_string_from_pasteboard (id pb
);
1045 extern void ns_string_to_pasteboard (id pb
, Lisp_Object str
);
1047 extern Lisp_Object
ns_get_local_selection (Lisp_Object selection_name
,
1048 Lisp_Object target_type
);
1049 extern void nxatoms_of_nsselect (void);
1050 extern int ns_lisp_to_cursor_type (Lisp_Object arg
);
1051 extern Lisp_Object
ns_cursor_type_to_lisp (int arg
);
1052 extern void ns_set_name_as_filename (struct frame
*f
);
1053 extern void ns_set_doc_edited (void);
1056 ns_defined_color (struct frame
*f
,
1058 XColor
*color_def
, bool alloc
,
1061 ns_query_color (void *col
, XColor
*color_def
, int setPixel
);
1064 extern Lisp_Object
ns_color_to_lisp (NSColor
*col
);
1065 extern int ns_lisp_to_color (Lisp_Object color
, NSColor
**col
);
1066 extern NSColor
*ns_lookup_indexed_color (unsigned long idx
, struct frame
*f
);
1067 extern unsigned long ns_index_color (NSColor
*color
, struct frame
*f
);
1068 extern void ns_free_indexed_color (unsigned long idx
, struct frame
*f
);
1069 extern const char *ns_get_pending_menu_title (void);
1070 extern void ns_check_menu_open (NSMenu
*menu
);
1071 extern void ns_check_pending_open_menu (void);
1074 /* C access to ObjC functionality */
1075 extern void ns_release_object (void *obj
);
1076 extern void ns_retain_object (void *obj
);
1077 extern void *ns_alloc_autorelease_pool (void);
1078 extern void ns_release_autorelease_pool (void *);
1079 extern const char *ns_get_defaults_value (const char *key
);
1082 extern void update_frame_tool_bar (struct frame
*f
);
1083 extern void free_frame_tool_bar (struct frame
*f
);
1084 extern void find_and_call_menu_selection (struct frame
*f
,
1085 int menu_bar_items_used
, Lisp_Object vector
, void *client_data
);
1086 extern Lisp_Object
find_and_return_menu_selection (struct frame
*f
,
1089 extern Lisp_Object
ns_popup_dialog (struct frame
*, Lisp_Object header
,
1090 Lisp_Object contents
);
1092 #define NSAPP_DATA2_RUNASSCRIPT 10
1093 extern void ns_run_ascript (void);
1095 #define NSAPP_DATA2_RUNFILEDIALOG 11
1096 extern void ns_run_file_dialog (void);
1098 extern const char *ns_etc_directory (void);
1099 extern const char *ns_exec_path (void);
1100 extern const char *ns_load_path (void);
1101 extern void syms_of_nsterm (void);
1102 extern void syms_of_nsfns (void);
1103 extern void syms_of_nsmenu (void);
1104 extern void syms_of_nsselect (void);
1106 /* From nsimage.m, needed in image.c */
1108 extern void *ns_image_from_XBM (unsigned char *bits
, int width
, int height
,
1109 unsigned long fg
, unsigned long bg
);
1110 extern void *ns_image_for_XPM (int width
, int height
, int depth
);
1111 extern void *ns_image_from_file (Lisp_Object file
);
1112 extern bool ns_load_image (struct frame
*f
, struct image
*img
,
1113 Lisp_Object spec_file
, Lisp_Object spec_data
);
1114 extern int ns_image_width (void *img
);
1115 extern int ns_image_height (void *img
);
1116 extern unsigned long ns_get_pixel (void *img
, int x
, int y
);
1117 extern void ns_put_pixel (void *img
, int x
, int y
, unsigned long argb
);
1118 extern void ns_set_alpha (void *img
, int x
, int y
, unsigned char a
);
1120 extern int x_display_pixel_height (struct ns_display_info
*);
1121 extern int x_display_pixel_width (struct ns_display_info
*);
1123 /* This in nsterm.m */
1124 extern void x_destroy_window (struct frame
*f
);
1125 extern int ns_select (int nfds
, fd_set
*readfds
, fd_set
*writefds
,
1126 fd_set
*exceptfds
, struct timespec
const *timeout
,
1127 sigset_t
const *sigmask
);
1128 extern unsigned long ns_get_rgb_color (struct frame
*f
,
1129 float r
, float g
, float b
, float a
);
1131 extern void ns_init_events ();
1132 extern void ns_finish_events ();
1135 /* From nsterm.m, needed in nsfont.m. */
1137 ns_draw_text_decoration (struct glyph_string
*s
, struct face
*face
,
1138 NSColor
*defaultCol
, CGFloat width
, CGFloat x
);
1139 /* Needed in nsfns.m. */
1141 ns_set_represented_filename (NSString
* fstr
, struct frame
*f
);
1145 #ifdef NS_IMPL_GNUSTEP
1146 extern char gnustep_base_version
[]; /* version tracking */
1150 #define MINHEIGHT 10
1152 /* Screen max coordinate
1153 Using larger coordinates causes movewindow/placewindow to abort */
1154 #define SCREENMAX 16000
1156 #define NS_SCROLL_BAR_WIDTH_DEFAULT [EmacsScroller scrollerWidth]
1157 #define NS_SCROLL_BAR_HEIGHT_DEFAULT [EmacsScroller scrollerHeight]
1158 /* This is to match emacs on other platforms, ugly though it is. */
1159 #define NS_SELECTION_BG_COLOR_DEFAULT @"LightGoldenrod2";
1160 #define NS_SELECTION_FG_COLOR_DEFAULT @"Black";
1161 #define RESIZE_HANDLE_SIZE 12
1163 /* Little utility macros */
1164 #define IN_BOUND(min, x, max) (((x) < (min)) \
1165 ? (min) : (((x)>(max)) ? (max) : (x)))
1166 #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
1168 #endif /* HAVE_NS */