Improve responsiveness while in 'replace-buffer-contents'
[emacs.git] / src / nsterm.h
blob588b9fc64431b360ec37ce45dbd0b8f59a6c1248
1 /* Definitions and headers for communication with NeXT/Open/GNUstep API.
2 Copyright (C) 1989, 1993, 2005, 2008-2018 Free Software Foundation,
3 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 (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 <https://www.gnu.org/licenses/>. */
21 #include "dispextern.h"
22 #include "frame.h"
23 #include "character.h"
24 #include "font.h"
25 #include "sysselect.h"
27 #ifdef HAVE_NS
28 #ifdef __OBJC__
30 /* CGFloat on GNUstep may be 4 or 8 byte, but functions expect float* for some
31 versions.
32 On Cocoa >= 10.5, functions expect CGFloat *. Make compatible type. */
33 #ifdef NS_IMPL_COCOA
34 typedef CGFloat EmacsCGFloat;
35 #elif GNUSTEP_GUI_MAJOR_VERSION > 0 || GNUSTEP_GUI_MINOR_VERSION >= 22
36 typedef CGFloat EmacsCGFloat;
37 #else
38 typedef float EmacsCGFloat;
39 #endif
41 /* ==========================================================================
43 Trace support
45 ========================================================================== */
47 /* Uncomment the following line to enable trace.
49 Uncomment suitable NSTRACE_GROUP_xxx lines to trace more.
51 Hint: keep the trailing whitespace -- the version control system
52 will reject accidental commits. */
54 /* #define NSTRACE_ENABLED 1 */
57 /* When non-zero, trace output is enabled for all parts, except those
58 explicitly disabled. */
59 /* #define NSTRACE_ALL_GROUPS 1 */
61 /* When non-zero, trace output is enabled in the corresponding part. */
62 /* #define NSTRACE_GROUP_EVENTS 1 */
63 /* #define NSTRACE_GROUP_UPDATES 1 */
64 /* #define NSTRACE_GROUP_FRINGE 1 */
65 /* #define NSTRACE_GROUP_COLOR 1 */
66 /* #define NSTRACE_GROUP_GLYPHS 1 */
67 /* #define NSTRACE_GROUP_FOCUS 1 */
70 /* Print a call tree containing all annotated functions.
72 The call structure of the functions is represented using
73 indentation and vertical lines. Extra information is printed using
74 horizontal lines that connect to the vertical line.
76 The return value is represented using the arrow "->>". For simple
77 functions, the arrow can be printed on the same line as the
78 function name. If more output is printed, it is connected to the
79 vertical line of the function.
81 The first column contains the file name, the second the line
82 number, and the third a number increasing for each trace line.
84 Note, when trace output from several threads are mixed, the output
85 can become misaligned, as all threads (currently) share one state.
86 This is post prominent when the EVENTS part is enabled.
88 Note that the trace system, when enabled, use the GCC/Clang
89 "cleanup" extension. */
91 /* For example, the following is the output of `M-x
92 toggle-frame-maximized RET'.
94 (Long lines manually split to reduced width):
96 nsterm.m : 1608: [ 354] ns_fullscreen_hook
97 nsterm.m : 7180: [ 355] | [EmacsView handleFS]
98 nsterm.m : 7209: [ 356] | +--- FULLSCREEN_MAXIMIZED
99 nsterm.m : 7706: [ 357] | | [EmacsWindow performZoom:]
100 nsterm.m : 7715: [ 358] | | | [EmacsWindow zoom:]
101 nsterm.m : 882: [ 359] | | | | ns_update_auto_hide_menu_bar
102 nsterm.m : 6752: [ 360] | | | |
103 [EmacsView windowWillUseStandardFrame:defaultFrame:(X:0 Y:0)/(W:1600 H:1177)]
104 nsterm.m : 6753: [ 361] | | | | +--- fs_state: FULLSCREEN_NONE
105 nsterm.m : 6754: [ 362] | | | | +--- fs_before_fs: -1
106 nsterm.m : 6755: [ 363] | | | | +--- next_maximized: FULLSCREEN_MAXIMIZED
107 nsterm.m : 6756: [ 364] | | | | +--- ns_userRect: (X:0 Y:0)/(W:0 H:0)
108 nsterm.m : 6757: [ 365] | | | | +---
109 [sender frame]: (X:0 Y:626)/(W:595 H:551)
110 nsterm.m : 6781: [ 366] | | | | +---
111 ns_userRect (2): (X:0 Y:626)/(W:595 H:551)
112 nsterm.m : 6821: [ 367] | | | | +--- FULLSCREEN_MAXIMIZED
113 nsterm.m : 7232: [ 368] | | | | |
114 [EmacsView setFSValue:FULLSCREEN_MAXIMIZED]
115 nsterm.m : 6848: [ 369] | | | | +---
116 Final ns_userRect: (X:0 Y:626)/(W:595 H:551)
117 nsterm.m : 6849: [ 370] | | | | +--- Final maximized_width: 1600
118 nsterm.m : 6850: [ 371] | | | | +--- Final maximized_height: 1177
119 nsterm.m : 6851: [ 372] | | | | +--- Final next_maximized: -1
120 nsterm.m : 6322: [ 373] | | | | |
121 [EmacsView windowWillResize:toSize: (W:1600 H:1177)]
122 nsterm.m : 6323: [ 374] | | | | | +---
123 [sender frame]: (X:0 Y:626)/(W:595 H:551)
124 nsterm.m : 6324: [ 375] | | | | | +--- fs_state: FULLSCREEN_MAXIMIZED
125 nsterm.m : 7027: [ 376] | | | | | | [EmacsView isFullscreen]
126 nsterm.m : 6387: [ 377] | | | | | +--- cols: 223 rows: 79
127 nsterm.m : 6412: [ 378] | | | | | +->> (W:1596 H:1167)
128 nsterm.m : 6855: [ 379] | | | | +->> (X:0 Y:0)/(W:1600 H:1177)
131 #ifndef NSTRACE_ENABLED
132 #define NSTRACE_ENABLED 0
133 #endif
135 #if NSTRACE_ENABLED
137 #ifndef NSTRACE_ALL_GROUPS
138 #define NSTRACE_ALL_GROUPS 0
139 #endif
141 #ifndef NSTRACE_GROUP_EVENTS
142 #define NSTRACE_GROUP_EVENTS NSTRACE_ALL_GROUPS
143 #endif
145 #ifndef NSTRACE_GROUP_UPDATES
146 #define NSTRACE_GROUP_UPDATES NSTRACE_ALL_GROUPS
147 #endif
149 #ifndef NSTRACE_GROUP_FRINGE
150 #define NSTRACE_GROUP_FRINGE NSTRACE_ALL_GROUPS
151 #endif
153 #ifndef NSTRACE_GROUP_COLOR
154 #define NSTRACE_GROUP_COLOR NSTRACE_ALL_GROUPS
155 #endif
157 #ifndef NSTRACE_GROUP_GLYPHS
158 #define NSTRACE_GROUP_GLYPHS NSTRACE_ALL_GROUPS
159 #endif
161 #ifndef NSTRACE_GROUP_FOCUS
162 #define NSTRACE_GROUP_FOCUS NSTRACE_ALL_GROUPS
163 #endif
165 extern volatile int nstrace_num;
166 extern volatile int nstrace_depth;
167 extern volatile int nstrace_enabled_global;
169 void nstrace_leave(int *);
170 void nstrace_restore_global_trace_state(int *);
171 char const * nstrace_fullscreen_type_name (int);
173 /* printf-style trace output. Output is aligned with contained heading. */
174 #define NSTRACE_MSG_NO_DASHES(...) \
175 do \
177 if (nstrace_enabled) \
179 fprintf (stderr, "%-10s:%5d: [%5d]%.*s", \
180 __FILE__, __LINE__, nstrace_num++, \
181 2*nstrace_depth, " | | | | | | | | | | | | | | | .."); \
182 fprintf (stderr, __VA_ARGS__); \
183 fprintf (stderr, "\n"); \
186 while(0)
188 #define NSTRACE_MSG(...) NSTRACE_MSG_NO_DASHES("+--- " __VA_ARGS__)
192 /* Macros for printing complex types.
194 NSTRACE_FMT_what -- Printf format string for "what".
195 NSTRACE_ARG_what(x) -- Printf argument for "what". */
197 #define NSTRACE_FMT_SIZE "(W:%.0f H:%.0f)"
198 #define NSTRACE_ARG_SIZE(elt) (elt).width, (elt).height
200 #define NSTRACE_FMT_POINT "(X:%.0f Y:%.0f)"
201 #define NSTRACE_ARG_POINT(elt) (elt).x, (elt).y
203 #define NSTRACE_FMT_RECT NSTRACE_FMT_POINT "/" NSTRACE_FMT_SIZE
204 #define NSTRACE_ARG_RECT(elt) \
205 NSTRACE_ARG_POINT((elt).origin), NSTRACE_ARG_SIZE((elt).size)
207 #define NSTRACE_FMT_FSTYPE "%s"
208 #define NSTRACE_ARG_FSTYPE(elt) nstrace_fullscreen_type_name(elt)
211 /* Macros for printing complex types as extra information. */
213 #define NSTRACE_SIZE(str,size) \
214 NSTRACE_MSG (str ": " NSTRACE_FMT_SIZE, \
215 NSTRACE_ARG_SIZE (size));
217 #define NSTRACE_POINT(str,point) \
218 NSTRACE_MSG (str ": " NSTRACE_FMT_POINT, \
219 NSTRACE_ARG_POINT (point));
221 #define NSTRACE_RECT(str,rect) \
222 NSTRACE_MSG (str ": " NSTRACE_FMT_RECT, \
223 NSTRACE_ARG_RECT (rect));
225 #define NSTRACE_FSTYPE(str,fs_type) \
226 NSTRACE_MSG (str ": " NSTRACE_FMT_FSTYPE, \
227 NSTRACE_ARG_FSTYPE (fs_type));
230 /* Return value macros.
232 NSTRACE_RETURN(fmt, ...) - Print a return value, support printf-style
233 format string and arguments.
235 NSTRACE_RETURN_what(obj) - Print a return value of kind WHAT.
237 NSTRACE_FMT_RETURN - A string literal representing a returned
238 value. Useful when creating a format string
239 to printf-like constructs like NSTRACE(). */
241 #define NSTRACE_FMT_RETURN "->>"
243 #define NSTRACE_RETURN(...) \
244 NSTRACE_MSG_NO_DASHES ("+" NSTRACE_FMT_RETURN " " __VA_ARGS__)
246 #define NSTRACE_RETURN_SIZE(size) \
247 NSTRACE_RETURN(NSTRACE_FMT_SIZE, NSTRACE_ARG_SIZE(size))
249 #define NSTRACE_RETURN_POINT(point) \
250 NSTRACE_RETURN(NSTRACE_FMT_POINT, NSTRACE_ARG_POINT(point))
252 #define NSTRACE_RETURN_RECT(rect) \
253 NSTRACE_RETURN(NSTRACE_FMT_RECT, NSTRACE_ARG_RECT(rect))
256 /* Function enter macros.
258 NSTRACE (fmt, ...) -- Enable trace output in current block
259 (typically a function). Accepts printf-style
260 arguments.
262 NSTRACE_WHEN (cond, fmt, ...) -- Enable trace output when COND is true.
264 NSTRACE_UNLESS (cond, fmt, ...) -- Enable trace output unless COND is
265 true. */
269 #define NSTRACE_WHEN(cond, ...) \
270 __attribute__((cleanup(nstrace_restore_global_trace_state))) \
271 int nstrace_saved_enabled_global = nstrace_enabled_global; \
272 __attribute__((cleanup(nstrace_leave))) \
273 int nstrace_enabled = nstrace_enabled_global && (cond); \
274 if (nstrace_enabled) { ++nstrace_depth; } \
275 else { nstrace_enabled_global = 0; } \
276 NSTRACE_MSG_NO_DASHES(__VA_ARGS__);
278 /* Unsilence called functions.
280 Concretely, this us used to allow "event" functions to be silenced
281 while trace output can be printed for functions they call. */
282 #define NSTRACE_UNSILENCE() do { nstrace_enabled_global = 1; } while(0)
284 #endif /* NSTRACE_ENABLED */
286 #define NSTRACE(...) NSTRACE_WHEN(1, __VA_ARGS__)
287 #define NSTRACE_UNLESS(cond, ...) NSTRACE_WHEN(!(cond), __VA_ARGS__)
289 /* Non-trace replacement versions. */
290 #ifndef NSTRACE_WHEN
291 #define NSTRACE_WHEN(...)
292 #endif
294 #ifndef NSTRACE_MSG
295 #define NSTRACE_MSG(...)
296 #endif
298 #ifndef NSTRACE_SIZE
299 #define NSTRACE_SIZE(str,size)
300 #endif
302 #ifndef NSTRACE_POINT
303 #define NSTRACE_POINT(str,point)
304 #endif
306 #ifndef NSTRACE_RECT
307 #define NSTRACE_RECT(str,rect)
308 #endif
310 #ifndef NSTRACE_FSTYPE
311 #define NSTRACE_FSTYPE(str,fs_type)
312 #endif
314 #ifndef NSTRACE_RETURN_SIZE
315 #define NSTRACE_RETURN_SIZE(size)
316 #endif
318 #ifndef NSTRACE_RETURN_POINT
319 #define NSTRACE_RETURN_POINT(point)
320 #endif
322 #ifndef NSTRACE_RETURN_RECT
323 #define NSTRACE_RETURN_RECT(rect)
324 #endif
326 #ifndef NSTRACE_RETURN_FSTYPE
327 #define NSTRACE_RETURN_FSTYPE(fs_type)
328 #endif
330 #ifndef NSTRACE_UNSILENCE
331 #define NSTRACE_UNSILENCE()
332 #endif
335 /* If the compiler doesn't support instancetype, map it to id. */
336 #ifndef NATIVE_OBJC_INSTANCETYPE
337 typedef id instancetype;
338 #endif
341 /* ==========================================================================
343 NSColor, EmacsColor category.
345 ========================================================================== */
346 @interface NSColor (EmacsColor)
347 + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
348 blue:(CGFloat)blue alpha:(CGFloat)alpha;
349 - (NSColor *)colorUsingDefaultColorSpace;
351 @end
353 /* ==========================================================================
355 The Emacs application
357 ========================================================================== */
359 /* We override sendEvent: as a means to stop/start the event loop */
360 @interface EmacsApp : NSApplication
362 #ifdef NS_IMPL_COCOA
363 BOOL shouldKeepRunning;
364 BOOL isFirst;
365 #endif
366 #ifdef NS_IMPL_GNUSTEP
367 BOOL applicationDidFinishLaunchingCalled;
368 #endif
369 @public
370 int nextappdefined;
372 - (void)logNotification: (NSNotification *)notification;
373 - (void)antialiasThresholdDidChange:(NSNotification *)notification;
374 - (void)sendEvent: (NSEvent *)theEvent;
375 - (void)showPreferencesWindow: (id)sender;
376 - (BOOL) openFile: (NSString *)fileName;
377 - (void)fd_handler: (id)unused;
378 - (void)timeout_handler: (NSTimer *)timedEntry;
379 - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg;
380 #ifdef NS_IMPL_GNUSTEP
381 - (void)sendFromMainThread:(id)unused;
382 #endif
383 @end
385 #ifdef NS_IMPL_GNUSTEP
386 /* Dummy class to get rid of startup warnings. */
387 @interface EmacsDocument : NSDocument
390 @end
391 #endif
393 /* ==========================================================================
395 The main Emacs view
397 ========================================================================== */
399 @class EmacsToolbar;
401 #ifdef NS_IMPL_COCOA
402 @interface EmacsView : NSView <NSTextInput, NSWindowDelegate>
403 #else
404 @interface EmacsView : NSView <NSTextInput>
405 #endif
407 #ifdef NS_IMPL_COCOA
408 char *old_title;
409 BOOL maximizing_resize;
410 #endif
411 BOOL windowClosing;
412 NSString *workingText;
413 BOOL processingCompose;
414 int fs_state, fs_before_fs, next_maximized;
415 int bwidth;
416 int maximized_width, maximized_height;
417 NSWindow *nonfs_window;
418 BOOL fs_is_native;
419 @public
420 struct frame *emacsframe;
421 int rows, cols;
422 int scrollbarsNeedingUpdate;
423 EmacsToolbar *toolbar;
424 NSRect ns_userRect;
425 BOOL wait_for_tool_bar;
428 /* AppKit-side interface */
429 - (instancetype)menuDown: (id)sender;
430 - (instancetype)toolbarClicked: (id)item;
431 - (instancetype)toggleToolbar: (id)sender;
432 - (void)keyDown: (NSEvent *)theEvent;
433 - (void)mouseDown: (NSEvent *)theEvent;
434 - (void)mouseUp: (NSEvent *)theEvent;
435 - (instancetype)setMiniwindowImage: (BOOL)setMini;
437 /* Emacs-side interface */
438 - (instancetype) initFrameFromEmacs: (struct frame *) f;
439 - (void) createToolbar: (struct frame *)f;
440 - (void) setRows: (int) r andColumns: (int) c;
441 - (void) setWindowClosing: (BOOL)closing;
442 - (EmacsToolbar *) toolbar;
443 - (void) deleteWorkingText;
444 - (void) updateFrameSize: (BOOL) delay;
445 - (void) handleFS;
446 - (void) setFSValue: (int)value;
447 - (void) toggleFullScreen: (id) sender;
448 - (BOOL) fsIsNative;
449 - (BOOL) isFullscreen;
450 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
451 - (void) updateCollectionBehavior;
452 #endif
454 #ifdef NS_IMPL_GNUSTEP
455 - (void)windowDidMove: (id)sender;
456 #endif
457 - (int)fullscreenState;
459 /* Non-notification versions of NSView methods. Used for direct calls. */
460 - (void)windowWillEnterFullScreen;
461 - (void)windowDidEnterFullScreen;
462 - (void)windowWillExitFullScreen;
463 - (void)windowDidExitFullScreen;
464 - (void)windowDidBecomeKey;
465 @end
468 /* Small utility used for processing resize events under Cocoa. */
469 @interface EmacsWindow : NSWindow
471 NSPoint grabOffset;
473 @end
476 /* Fullscreen version of the above. */
477 @interface EmacsFSWindow : EmacsWindow
480 @end
482 /* ==========================================================================
484 The main menu implementation
486 ========================================================================== */
488 #ifdef NS_IMPL_COCOA
489 @interface EmacsMenu : NSMenu <NSMenuDelegate>
490 #else
491 @interface EmacsMenu : NSMenu
492 #endif
494 struct frame *frame;
495 unsigned long keyEquivModMask;
498 - (instancetype)initWithTitle: (NSString *)title frame: (struct frame *)f;
499 - (void)setFrame: (struct frame *)f;
500 - (void)menuNeedsUpdate: (NSMenu *)menu; /* (delegate method) */
501 - (NSString *)parseKeyEquiv: (const char *)key;
502 - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr;
503 - (void)fillWithWidgetValue: (void *)wvptr;
504 - (void)fillWithWidgetValue: (void *)wvptr frame: (struct frame *)f;
505 - (EmacsMenu *)addSubmenuWithTitle: (const char *)title forFrame: (struct frame *)f;
506 - (void) clear;
507 - (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f
508 keymaps: (bool)keymaps;
509 @end
512 /* ==========================================================================
514 Toolbar
516 ========================================================================== */
518 @class EmacsImage;
520 #ifdef NS_IMPL_COCOA
521 @interface EmacsToolbar : NSToolbar <NSToolbarDelegate>
522 #else
523 @interface EmacsToolbar : NSToolbar
524 #endif
526 EmacsView *emacsView;
527 NSMutableDictionary *identifierToItem;
528 NSMutableArray *activeIdentifiers;
529 NSArray *prevIdentifiers;
530 unsigned long enablement, prevEnablement;
532 - (instancetype) initForView: (EmacsView *)view withIdentifier: (NSString *)identifier;
533 - (void) clearActive;
534 - (void) clearAll;
535 - (BOOL) changed;
536 - (void) addDisplayItemWithImage: (EmacsImage *)img
537 idx: (int)idx
538 tag: (int)tag
539 helpText: (const char *)help
540 enabled: (BOOL)enabled;
542 /* delegate methods */
543 - (NSToolbarItem *)toolbar: (NSToolbar *)toolbar
544 itemForItemIdentifier: (NSString *)itemIdentifier
545 willBeInsertedIntoToolbar: (BOOL)flag;
546 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar;
547 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar;
548 @end
551 /* ==========================================================================
553 Message / question windows
555 ========================================================================== */
557 @interface EmacsDialogPanel : NSPanel
559 NSTextField *command;
560 NSTextField *title;
561 NSMatrix *matrix;
562 int rows, cols;
563 BOOL timer_fired, window_closed;
564 Lisp_Object dialog_return;
565 Lisp_Object *button_values;
567 - (instancetype)initFromContents: (Lisp_Object)menu isQuestion: (BOOL)isQ;
568 - (void)process_dialog: (Lisp_Object)list;
569 - (void)addButton: (char *)str value: (int)tag row: (int)row;
570 - (void)addString: (char *)str row: (int)row;
571 - (void)addSplit;
572 - (Lisp_Object)runDialogAt: (NSPoint)p;
573 - (void)timeout_handler: (NSTimer *)timedEntry;
574 @end
576 #ifdef NS_IMPL_COCOA
577 @interface EmacsTooltip : NSObject <NSWindowDelegate>
578 #else
579 @interface EmacsTooltip : NSObject
580 #endif
582 NSWindow *win;
583 NSTextField *textField;
584 NSTimer *timer;
586 - (instancetype) init;
587 - (void) setText: (char *)text;
588 - (void) showAtX: (int)x Y: (int)y for: (int)seconds;
589 - (void) hide;
590 - (BOOL) isActive;
591 - (NSRect) frame;
592 @end
595 /* ==========================================================================
597 File open/save panels
598 This and next override methods to handle keyboard input in panels.
600 ========================================================================== */
602 @interface EmacsSavePanel : NSSavePanel
605 @end
606 @interface EmacsOpenPanel : NSOpenPanel
609 @end
611 @interface EmacsFileDelegate : NSObject
614 - (BOOL)panel: (id)sender isValidFilename: (NSString *)filename;
615 - (BOOL)panel: (id)sender shouldShowFilename: (NSString *)filename;
616 - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
617 confirmed: (BOOL)okFlag;
618 @end
621 /* ==========================================================================
623 Images and stippling
625 ========================================================================== */
627 @interface EmacsImage : NSImage
629 NSBitmapImageRep *bmRep; /* used for accessing pixel data */
630 unsigned char *pixmapData[5]; /* shortcut to access pixel data */
631 NSColor *stippleMask;
632 unsigned long xbm_fg;
634 + (instancetype)allocInitFromFile: (Lisp_Object)file;
635 - (void)dealloc;
636 - (instancetype)initFromXBM: (unsigned char *)bits width: (int)w height: (int)h
637 fg: (unsigned long)fg bg: (unsigned long)bg;
638 - (instancetype)setXBMColor: (NSColor *)color;
639 - (instancetype)initForXPMWithDepth: (int)depth width: (int)width height: (int)height;
640 - (void)setPixmapData;
641 - (unsigned long)getPixelAtX: (int)x Y: (int)y;
642 - (void)setPixelAtX: (int)x Y: (int)y toRed: (unsigned char)r
643 green: (unsigned char)g blue: (unsigned char)b
644 alpha:(unsigned char)a;
645 - (void)setAlphaAtX: (int)x Y: (int)y to: (unsigned char)a;
646 - (NSColor *)stippleMask;
647 - (Lisp_Object)getMetadata;
648 - (BOOL)setFrame: (unsigned int) index;
649 @end
652 /* ==========================================================================
654 Scrollbars
656 ========================================================================== */
658 @interface EmacsScroller : NSScroller
660 struct window *window;
661 struct frame *frame;
662 NSResponder *prevResponder;
664 /* offset to the bottom of knob of last mouse down */
665 CGFloat last_mouse_offset;
666 float min_portion;
667 int pixel_length;
668 enum scroll_bar_part last_hit_part;
670 BOOL condemned;
672 BOOL horizontal;
674 /* optimize against excessive positioning calls generated by emacs */
675 int em_position;
676 int em_portion;
677 int em_whole;
680 - (instancetype) initFrame: (NSRect )r window: (Lisp_Object)win;
681 - (void)setFrame: (NSRect)r;
683 - (instancetype) setPosition: (int) position portion: (int) portion whole: (int) whole;
684 - (int) checkSamePosition: (int)position portion: (int)portion
685 whole: (int)whole;
686 - (void) sendScrollEventAtLoc: (float)loc fromEvent: (NSEvent *)e;
687 - (instancetype)repeatScroll: (NSTimer *)sender;
688 - (instancetype)condemn;
689 - (instancetype)reprieve;
690 - (bool)judge;
691 + (CGFloat)scrollerWidth;
692 @end
695 /* ==========================================================================
697 Rendering
699 ========================================================================== */
701 #ifdef NS_IMPL_COCOA
702 /* rendering util */
703 @interface EmacsGlyphStorage : NSObject <NSGlyphStorage>
705 @public
706 NSAttributedString *attrStr;
707 NSMutableDictionary *dict;
708 CGGlyph *cglyphs;
709 unsigned long maxChar, maxGlyph;
710 long i, len;
712 - (instancetype)initWithCapacity: (unsigned long) c;
713 - (void) setString: (NSString *)str font: (NSFont *)font;
714 @end
715 #endif /* NS_IMPL_COCOA */
717 extern NSArray *ns_send_types, *ns_return_types;
718 extern NSString *ns_app_name;
719 extern EmacsMenu *svcsMenu;
721 /* Apple removed the declaration, but kept the implementation */
722 #if defined (NS_IMPL_COCOA)
723 @interface NSApplication (EmacsApp)
724 - (void)setAppleMenu: (NSMenu *)menu;
725 @end
726 #endif
728 #endif /* __OBJC__ */
732 /* ==========================================================================
734 Non-OO stuff
736 ========================================================================== */
738 /* Special keycodes that we pass down the event chain */
739 #define KEY_NS_POWER_OFF ((1<<28)|(0<<16)|1)
740 #define KEY_NS_OPEN_FILE ((1<<28)|(0<<16)|2)
741 #define KEY_NS_OPEN_TEMP_FILE ((1<<28)|(0<<16)|3)
742 #define KEY_NS_CHANGE_FONT ((1<<28)|(0<<16)|7)
743 #define KEY_NS_OPEN_FILE_LINE ((1<<28)|(0<<16)|8)
744 #define KEY_NS_PUT_WORKING_TEXT ((1<<28)|(0<<16)|9)
745 #define KEY_NS_UNPUT_WORKING_TEXT ((1<<28)|(0<<16)|10)
746 #define KEY_NS_SPI_SERVICE_CALL ((1<<28)|(0<<16)|11)
747 #define KEY_NS_NEW_FRAME ((1<<28)|(0<<16)|12)
748 #define KEY_NS_TOGGLE_TOOLBAR ((1<<28)|(0<<16)|13)
749 #define KEY_NS_SHOW_PREFS ((1<<28)|(0<<16)|14)
751 /* could use list to store these, but rest of emacs has a big infrastructure
752 for managing a table of bitmap "records" */
753 struct ns_bitmap_record
755 #ifdef __OBJC__
756 EmacsImage *img;
757 #else
758 void *img;
759 #endif
760 char *file;
761 int refcount;
762 int height, width, depth;
765 /* this to map between emacs color indices and NSColor objects */
766 struct ns_color_table
768 ptrdiff_t size;
769 ptrdiff_t avail;
770 #ifdef __OBJC__
771 NSColor **colors;
772 NSMutableSet *empty_indices;
773 #else
774 void **items;
775 void *availIndices;
776 #endif
778 #define NS_COLOR_CAPACITY 256
780 #define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
781 #define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
783 #define ALPHA_FROM_ULONG(color) ((color) >> 24)
784 #define RED_FROM_ULONG(color) (((color) >> 16) & 0xff)
785 #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
786 #define BLUE_FROM_ULONG(color) ((color) & 0xff)
788 /* Do not change `* 0x101' in the following lines to `<< 8'. If
789 changed, image masks in 1-bit depth will not work. */
790 #define RED16_FROM_ULONG(color) (RED_FROM_ULONG(color) * 0x101)
791 #define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
792 #define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)
794 /* this extends font backend font */
795 struct nsfont_info
797 struct font font;
799 char *name; /* PostScript name, uniquely identifies on NS systems */
801 /* The following metrics are stored as float rather than int. */
803 float width; /* Maximum advance for the font. */
804 float height;
805 float underpos;
806 float underwidth;
807 float size;
808 #ifdef __OBJC__
809 NSFont *nsfont;
810 #if defined (NS_IMPL_COCOA)
811 CGFontRef cgfont;
812 #else /* GNUstep */
813 void *cgfont;
814 #endif
815 #else /* ! OBJC */
816 void *nsfont;
817 void *cgfont;
818 #endif
819 char bold, ital; /* convenience flags */
820 char synthItal;
821 XCharStruct max_bounds;
822 /* we compute glyph codes and metrics on-demand in blocks of 256 indexed
823 by hibyte, lobyte */
824 unsigned short **glyphs; /* map Unicode index to glyph */
825 struct font_metrics **metrics;
829 /* init'd in ns_initialize_display_info () */
830 struct ns_display_info
832 /* Chain of all ns_display_info structures. */
833 struct ns_display_info *next;
835 /* The generic display parameters corresponding to this NS display. */
836 struct terminal *terminal;
838 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
839 Lisp_Object name_list_element;
841 /* The number of fonts loaded. */
842 int n_fonts;
844 /* Minimum width over all characters in all fonts in font_table. */
845 int smallest_char_width;
847 /* Minimum font height over all fonts in font_table. */
848 int smallest_font_height;
850 struct ns_bitmap_record *bitmaps;
851 ptrdiff_t bitmaps_size;
852 ptrdiff_t bitmaps_last;
854 struct ns_color_table *color_table;
856 /* DPI resolution of this screen */
857 double resx, resy;
859 /* Mask of things that cause the mouse to be grabbed */
860 int grabbed;
862 int n_planes;
864 int color_p;
866 Window root_window;
868 /* Xism */
869 XrmDatabase xrdb;
871 /* The cursor to use for vertical scroll bars. */
872 Cursor vertical_scroll_bar_cursor;
874 /* The cursor to use for horizontal scroll bars. */
875 Cursor horizontal_scroll_bar_cursor;
877 /* Information about the range of text currently shown in
878 mouse-face. */
879 Mouse_HLInfo mouse_highlight;
881 struct frame *x_highlight_frame;
882 struct frame *x_focus_frame;
884 /* The frame where the mouse was last time we reported a mouse event. */
885 struct frame *last_mouse_frame;
887 /* The frame where the mouse was last time we reported a mouse motion. */
888 struct frame *last_mouse_motion_frame;
890 /* Position where the mouse was last time we reported a motion.
891 This is a position on last_mouse_motion_frame. */
892 int last_mouse_motion_x;
893 int last_mouse_motion_y;
895 /* Where the mouse was last time we reported a mouse position. */
896 NSRect last_mouse_glyph;
898 /* Time of last mouse movement. */
899 Time last_mouse_movement_time;
901 /* The scroll bar in which the last motion event occurred. */
902 #ifdef __OBJC__
903 EmacsScroller *last_mouse_scroll_bar;
904 #else
905 void *last_mouse_scroll_bar;
906 #endif
909 /* This is a chain of structures for all the NS displays currently in use. */
910 extern struct ns_display_info *x_display_list;
912 struct ns_output
914 #ifdef __OBJC__
915 EmacsView *view;
916 id miniimage;
917 NSColor *cursor_color;
918 NSColor *foreground_color;
919 NSColor *background_color;
920 EmacsToolbar *toolbar;
921 #else
922 void *view;
923 void *miniimage;
924 void *cursor_color;
925 void *foreground_color;
926 void *background_color;
927 void *toolbar;
928 #endif
930 /* NSCursors init'ed in initFrameFromEmacs */
931 Cursor text_cursor;
932 Cursor nontext_cursor;
933 Cursor modeline_cursor;
934 Cursor hand_cursor;
935 Cursor hourglass_cursor;
936 Cursor horizontal_drag_cursor;
937 Cursor vertical_drag_cursor;
938 Cursor left_edge_cursor;
939 Cursor top_left_corner_cursor;
940 Cursor top_edge_cursor;
941 Cursor top_right_corner_cursor;
942 Cursor right_edge_cursor;
943 Cursor bottom_right_corner_cursor;
944 Cursor bottom_edge_cursor;
945 Cursor bottom_left_corner_cursor;
947 /* NS-specific */
948 Cursor current_pointer;
950 /* lord knows why Emacs needs to know about our Window ids.. */
951 Window window_desc, parent_desc;
952 char explicit_parent;
954 struct font *font;
955 int baseline_offset;
957 /* If a fontset is specified for this frame instead of font, this
958 value contains an ID of the fontset, else -1. */
959 int fontset; /* only used with font_backend */
961 int icon_top;
962 int icon_left;
964 /* The size of the extra width currently allotted for vertical
965 scroll bars, in pixels. */
966 int vertical_scroll_bar_extra;
968 /* The height of the titlebar decoration (included in NSWindow's frame). */
969 int titlebar_height;
971 /* The height of the toolbar if displayed, else 0. */
972 int toolbar_height;
974 /* This is the Emacs structure for the NS display this frame is on. */
975 struct ns_display_info *display_info;
977 /* Non-zero if we are zooming (maximizing) the frame. */
978 int zooming;
980 /* Non-zero if we are doing an animation, e.g. toggling the tool bar. */
981 int in_animation;
984 /* this dummy decl needed to support TTYs */
985 struct x_output
987 int unused;
991 /* This gives the ns_display_info structure for the display F is on. */
992 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.ns->display_info)
993 #define FRAME_X_OUTPUT(f) ((f)->output_data.ns)
994 #define FRAME_NS_WINDOW(f) ((f)->output_data.ns->window_desc)
995 #define FRAME_X_WINDOW(f) ((f)->output_data.ns->window_desc)
997 /* This is the `Display *' which frame F is on. */
998 #define FRAME_NS_DISPLAY(f) (0)
999 #define FRAME_X_DISPLAY(f) (0)
1000 #define FRAME_X_SCREEN(f) (0)
1001 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO(f)->visual
1003 #define FRAME_FOREGROUND_COLOR(f) ((f)->output_data.ns->foreground_color)
1004 #define FRAME_BACKGROUND_COLOR(f) ((f)->output_data.ns->background_color)
1006 #define NS_FACE_FOREGROUND(f) ((f)->foreground)
1007 #define NS_FACE_BACKGROUND(f) ((f)->background)
1009 #define FRAME_DEFAULT_FACE(f) FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID)
1011 #define FRAME_NS_VIEW(f) ((f)->output_data.ns->view)
1012 #define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
1013 #define FRAME_POINTER_TYPE(f) ((f)->output_data.ns->current_pointer)
1015 #define FRAME_FONT(f) ((f)->output_data.ns->font)
1017 #ifdef __OBJC__
1018 #define XNS_SCROLL_BAR(vec) ((id) XSAVE_POINTER (vec, 0))
1019 #else
1020 #define XNS_SCROLL_BAR(vec) XSAVE_POINTER (vec, 0)
1021 #endif
1023 /* Compute pixel height of the frame's titlebar. */
1024 #define FRAME_NS_TITLEBAR_HEIGHT(f) \
1025 (NSHeight([FRAME_NS_VIEW (f) frame]) == 0 ? \
1027 : (int)(NSHeight([FRAME_NS_VIEW (f) window].frame) \
1028 - NSHeight([NSWindow contentRectForFrameRect: \
1029 [[FRAME_NS_VIEW (f) window] frame] \
1030 styleMask:[[FRAME_NS_VIEW (f) window] styleMask]])))
1032 /* Compute pixel height of the toolbar. */
1033 #define FRAME_TOOLBAR_HEIGHT(f) \
1034 (([[FRAME_NS_VIEW (f) window] toolbar] == nil \
1035 || ! [[FRAME_NS_VIEW (f) window] toolbar].isVisible) ? \
1037 : (int)(NSHeight([NSWindow contentRectForFrameRect: \
1038 [[FRAME_NS_VIEW (f) window] frame] \
1039 styleMask:[[FRAME_NS_VIEW (f) window] styleMask]]) \
1040 - NSHeight([[[FRAME_NS_VIEW (f) window] contentView] frame])))
1042 /* Compute pixel size for vertical scroll bars */
1043 #define NS_SCROLL_BAR_WIDTH(f) \
1044 (FRAME_HAS_VERTICAL_SCROLL_BARS (f) \
1045 ? rint (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0 \
1046 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f) \
1047 : (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f))) \
1048 : 0)
1050 /* Compute pixel size for horizontal scroll bars */
1051 #define NS_SCROLL_BAR_HEIGHT(f) \
1052 (FRAME_HAS_HORIZONTAL_SCROLL_BARS (f) \
1053 ? rint (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0 \
1054 ? FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) \
1055 : (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f))) \
1056 : 0)
1058 /* Difference btwn char-column-calculated and actual SB widths.
1059 This is only a concern for rendering when SB on left. */
1060 #define NS_SCROLL_BAR_ADJUST(w, f) \
1061 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) ? \
1062 (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f) \
1063 - NS_SCROLL_BAR_WIDTH (f)) : 0)
1065 /* Difference btwn char-line-calculated and actual SB heights.
1066 This is only a concern for rendering when SB on top. */
1067 #define NS_SCROLL_BAR_ADJUST_HORIZONTALLY(w, f) \
1068 (WINDOW_HAS_HORIZONTAL_SCROLL_BARS (w) ? \
1069 (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f) \
1070 - NS_SCROLL_BAR_HEIGHT (f)) : 0)
1072 /* Calculate system coordinates of the left and top of the parent
1073 window or, if there is no parent window, the screen. */
1074 #define NS_PARENT_WINDOW_LEFT_POS(f) \
1075 (FRAME_PARENT_FRAME (f) != NULL \
1076 ? [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.origin.x : 0)
1077 #define NS_PARENT_WINDOW_TOP_POS(f) \
1078 (FRAME_PARENT_FRAME (f) != NULL \
1079 ? ([FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.origin.y \
1080 + [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.size.height \
1081 - FRAME_NS_TITLEBAR_HEIGHT (FRAME_PARENT_FRAME (f))) \
1082 : [[[NSScreen screens] objectAtIndex: 0] frame].size.height)
1084 #define FRAME_NS_FONT_TABLE(f) (FRAME_DISPLAY_INFO (f)->font_table)
1086 #define FRAME_FONTSET(f) ((f)->output_data.ns->fontset)
1088 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.ns->baseline_offset)
1089 #define BLACK_PIX_DEFAULT(f) 0x000000
1090 #define WHITE_PIX_DEFAULT(f) 0xFFFFFF
1092 /* First position where characters can be shown (instead of scrollbar, if
1093 it is on left. */
1094 #define FIRST_CHAR_POSITION(f) \
1095 (! (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) ? 0 \
1096 : FRAME_SCROLL_BAR_COLS (f))
1098 extern struct ns_display_info *ns_term_init (Lisp_Object display_name);
1099 extern void ns_term_shutdown (int sig);
1101 /* constants for text rendering */
1102 #define NS_DUMPGLYPH_NORMAL 0
1103 #define NS_DUMPGLYPH_CURSOR 1
1104 #define NS_DUMPGLYPH_FOREGROUND 2
1105 #define NS_DUMPGLYPH_MOUSEFACE 3
1109 /* In nsfont, called from fontset.c */
1110 extern void nsfont_make_fontset_for_font (Lisp_Object name,
1111 Lisp_Object font_object);
1113 /* In nsfont, for debugging */
1114 struct glyph_string;
1115 void ns_dump_glyphstring (struct glyph_string *s) EXTERNALLY_VISIBLE;
1117 /* Implemented in nsterm, published in or needed from nsfns. */
1118 extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern,
1119 int size, int maxnames);
1120 extern void ns_clear_frame (struct frame *f);
1122 extern const char *ns_xlfd_to_fontname (const char *xlfd);
1124 extern Lisp_Object ns_map_event_to_object (void);
1125 #ifdef __OBJC__
1126 extern Lisp_Object ns_string_from_pasteboard (id pb);
1127 extern void ns_string_to_pasteboard (id pb, Lisp_Object str);
1128 #endif
1129 extern Lisp_Object ns_get_local_selection (Lisp_Object selection_name,
1130 Lisp_Object target_type);
1131 extern void nxatoms_of_nsselect (void);
1132 extern void ns_set_doc_edited (void);
1134 extern bool
1135 ns_defined_color (struct frame *f,
1136 const char *name,
1137 XColor *color_def, bool alloc,
1138 bool makeIndex);
1139 extern void
1140 ns_query_color (void *col, XColor *color_def, int setPixel);
1142 #ifdef __OBJC__
1143 extern int ns_lisp_to_color (Lisp_Object color, NSColor **col);
1144 extern NSColor *ns_lookup_indexed_color (unsigned long idx, struct frame *f);
1145 extern unsigned long ns_index_color (NSColor *color, struct frame *f);
1146 extern const char *ns_get_pending_menu_title (void);
1147 extern void ns_check_menu_open (NSMenu *menu);
1148 extern void ns_check_pending_open_menu (void);
1149 #endif
1151 /* C access to ObjC functionality */
1152 extern void ns_release_object (void *obj);
1153 extern void ns_retain_object (void *obj);
1154 extern void *ns_alloc_autorelease_pool (void);
1155 extern void ns_release_autorelease_pool (void *);
1156 extern const char *ns_get_defaults_value (const char *key);
1157 extern void ns_init_locale (void);
1160 /* in nsmenu */
1161 extern void update_frame_tool_bar (struct frame *f);
1162 extern void free_frame_tool_bar (struct frame *f);
1163 extern Lisp_Object find_and_return_menu_selection (struct frame *f,
1164 bool keymaps,
1165 void *client_data);
1166 extern Lisp_Object ns_popup_dialog (struct frame *, Lisp_Object header,
1167 Lisp_Object contents);
1169 #define NSAPP_DATA2_RUNASSCRIPT 10
1170 extern void ns_run_ascript (void);
1172 #define NSAPP_DATA2_RUNFILEDIALOG 11
1173 extern void ns_run_file_dialog (void);
1175 extern const char *ns_etc_directory (void);
1176 extern const char *ns_exec_path (void);
1177 extern const char *ns_load_path (void);
1178 extern void syms_of_nsterm (void);
1179 extern void syms_of_nsfns (void);
1180 extern void syms_of_nsmenu (void);
1181 extern void syms_of_nsselect (void);
1183 /* From nsimage.m, needed in image.c */
1184 struct image;
1185 extern void *ns_image_from_XBM (char *bits, int width, int height,
1186 unsigned long fg, unsigned long bg);
1187 extern void *ns_image_for_XPM (int width, int height, int depth);
1188 extern void *ns_image_from_file (Lisp_Object file);
1189 extern bool ns_load_image (struct frame *f, struct image *img,
1190 Lisp_Object spec_file, Lisp_Object spec_data);
1191 extern int ns_image_width (void *img);
1192 extern int ns_image_height (void *img);
1193 extern unsigned long ns_get_pixel (void *img, int x, int y);
1194 extern void ns_put_pixel (void *img, int x, int y, unsigned long argb);
1195 extern void ns_set_alpha (void *img, int x, int y, unsigned char a);
1197 extern int x_display_pixel_height (struct ns_display_info *);
1198 extern int x_display_pixel_width (struct ns_display_info *);
1200 /* This in nsterm.m */
1201 extern float ns_antialias_threshold;
1202 extern void x_destroy_window (struct frame *f);
1203 extern void x_set_undecorated (struct frame *f, Lisp_Object new_value,
1204 Lisp_Object old_value);
1205 extern void x_set_parent_frame (struct frame *f, Lisp_Object new_value,
1206 Lisp_Object old_value);
1207 extern void x_set_no_focus_on_map (struct frame *f, Lisp_Object new_value,
1208 Lisp_Object old_value);
1209 extern void x_set_no_accept_focus (struct frame *f, Lisp_Object new_value,
1210 Lisp_Object old_value);
1211 extern void x_set_z_group (struct frame *f, Lisp_Object new_value,
1212 Lisp_Object old_value);
1213 #ifdef NS_IMPL_COCOA
1214 extern void ns_set_appearance (struct frame *f, Lisp_Object new_value,
1215 Lisp_Object old_value);
1216 extern void ns_set_transparent_titlebar (struct frame *f,
1217 Lisp_Object new_value,
1218 Lisp_Object old_value);
1219 #endif
1220 extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds,
1221 fd_set *exceptfds, struct timespec *timeout,
1222 sigset_t *sigmask);
1223 #ifdef HAVE_PTHREAD
1224 extern void ns_run_loop_break (void);
1225 #endif
1226 extern unsigned long ns_get_rgb_color (struct frame *f,
1227 float r, float g, float b, float a);
1229 struct input_event;
1230 extern void ns_init_events (struct input_event *);
1231 extern void ns_finish_events (void);
1233 #ifdef __OBJC__
1234 /* Needed in nsfns.m. */
1235 extern void
1236 ns_set_represented_filename (NSString *fstr, struct frame *f);
1238 #endif
1240 #ifdef NS_IMPL_GNUSTEP
1241 extern char gnustep_base_version[]; /* version tracking */
1242 #endif
1244 #define MINWIDTH 10
1245 #define MINHEIGHT 10
1247 /* Screen max coordinate
1248 Using larger coordinates causes movewindow/placewindow to abort */
1249 #define SCREENMAX 16000
1251 #define NS_SCROLL_BAR_WIDTH_DEFAULT [EmacsScroller scrollerWidth]
1252 #define NS_SCROLL_BAR_HEIGHT_DEFAULT [EmacsScroller scrollerHeight]
1253 /* This is to match emacs on other platforms, ugly though it is. */
1254 #define NS_SELECTION_BG_COLOR_DEFAULT @"LightGoldenrod2";
1255 #define NS_SELECTION_FG_COLOR_DEFAULT @"Black";
1256 #define RESIZE_HANDLE_SIZE 12
1258 /* Little utility macros */
1259 #define IN_BOUND(min, x, max) (((x) < (min)) \
1260 ? (min) : (((x)>(max)) ? (max) : (x)))
1261 #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
1263 /* macOS 10.7 introduces some new constants. */
1264 #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_7)
1265 #define NSFullScreenWindowMask (1 << 14)
1266 #define NSWindowCollectionBehaviorFullScreenPrimary (1 << 7)
1267 #define NSApplicationPresentationFullScreen (1 << 10)
1268 #define NSApplicationPresentationAutoHideToolbar (1 << 11)
1269 #define NSAppKitVersionNumber10_7 1138
1270 #endif /* !defined (MAC_OS_X_VERSION_10_7) */
1272 /* macOS 10.12 deprecates a bunch of constants. */
1273 #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_12)
1274 #define NSEventModifierFlagCommand NSCommandKeyMask
1275 #define NSEventModifierFlagControl NSControlKeyMask
1276 #define NSEventModifierFlagHelp NSHelpKeyMask
1277 #define NSEventModifierFlagNumericPad NSNumericPadKeyMask
1278 #define NSEventModifierFlagOption NSAlternateKeyMask
1279 #define NSEventModifierFlagShift NSShiftKeyMask
1280 #define NSCompositingOperationSourceOver NSCompositeSourceOver
1281 #define NSEventMaskApplicationDefined NSApplicationDefinedMask
1282 #define NSEventTypeApplicationDefined NSApplicationDefined
1283 #define NSEventTypeCursorUpdate NSCursorUpdate
1284 #define NSEventTypeMouseMoved NSMouseMoved
1285 #define NSEventTypeLeftMouseDown NSLeftMouseDown
1286 #define NSEventTypeRightMouseDown NSRightMouseDown
1287 #define NSEventTypeOtherMouseDown NSOtherMouseDown
1288 #define NSEventTypeLeftMouseUp NSLeftMouseUp
1289 #define NSEventTypeRightMouseUp NSRightMouseUp
1290 #define NSEventTypeOtherMouseUp NSOtherMouseUp
1291 #define NSEventTypeLeftMouseDragged NSLeftMouseDragged
1292 #define NSEventTypeRightMouseDragged NSRightMouseDragged
1293 #define NSEventTypeOtherMouseDragged NSOtherMouseDragged
1294 #define NSEventTypeScrollWheel NSScrollWheel
1295 #define NSEventTypeKeyDown NSKeyDown
1296 #define NSEventTypeKeyUp NSKeyUp
1297 #define NSEventTypeFlagsChanged NSFlagsChanged
1298 #define NSEventMaskAny NSAnyEventMask
1299 #define NSEventTypeSystemDefined NSSystemDefined
1300 #define NSWindowStyleMaskBorderless NSBorderlessWindowMask
1301 #define NSWindowStyleMaskClosable NSClosableWindowMask
1302 #define NSWindowStyleMaskFullScreen NSFullScreenWindowMask
1303 #define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask
1304 #define NSWindowStyleMaskResizable NSResizableWindowMask
1305 #define NSWindowStyleMaskTitled NSTitledWindowMask
1306 #define NSWindowStyleMaskUtilityWindow NSUtilityWindowMask
1307 #define NSAlertStyleCritical NSCriticalAlertStyle
1308 #define NSControlSizeRegular NSRegularControlSize
1310 /* And adds NSWindowStyleMask. */
1311 #ifdef __OBJC__
1312 typedef NSUInteger NSWindowStyleMask;
1313 #endif
1315 /* Window tabbing mode enums are new too. */
1316 enum NSWindowTabbingMode
1318 NSWindowTabbingModeAutomatic,
1319 NSWindowTabbingModePreferred,
1320 NSWindowTabbingModeDisallowed
1322 #endif
1323 #endif /* HAVE_NS */