* admin/gitmerge.el (gitmerge-missing):
[emacs.git] / src / nsterm.h
blobc81bf5fb63d84f06dc5f260fd15f516a2cfcfcb4
1 /* Definitions and headers for communication with NeXT/Open/GNUstep API.
2 Copyright (C) 1989, 1993, 2005, 2008-2017 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 - (void)setSizeFromSpec: (Lisp_Object) spec;
650 - (instancetype)rotate: (double)rotation;
651 @end
654 /* ==========================================================================
656 Scrollbars
658 ========================================================================== */
660 @interface EmacsScroller : NSScroller
662 struct window *window;
663 struct frame *frame;
664 NSResponder *prevResponder;
666 /* offset to the bottom of knob of last mouse down */
667 CGFloat last_mouse_offset;
668 float min_portion;
669 int pixel_length;
670 enum scroll_bar_part last_hit_part;
672 BOOL condemned;
674 BOOL horizontal;
676 /* optimize against excessive positioning calls generated by emacs */
677 int em_position;
678 int em_portion;
679 int em_whole;
682 - (instancetype) initFrame: (NSRect )r window: (Lisp_Object)win;
683 - (void)setFrame: (NSRect)r;
685 - (instancetype) setPosition: (int) position portion: (int) portion whole: (int) whole;
686 - (int) checkSamePosition: (int)position portion: (int)portion
687 whole: (int)whole;
688 - (void) sendScrollEventAtLoc: (float)loc fromEvent: (NSEvent *)e;
689 - (instancetype)repeatScroll: (NSTimer *)sender;
690 - (instancetype)condemn;
691 - (instancetype)reprieve;
692 - (bool)judge;
693 + (CGFloat)scrollerWidth;
694 @end
697 /* ==========================================================================
699 Rendering
701 ========================================================================== */
703 #ifdef NS_IMPL_COCOA
704 /* rendering util */
705 @interface EmacsGlyphStorage : NSObject <NSGlyphStorage>
707 @public
708 NSAttributedString *attrStr;
709 NSMutableDictionary *dict;
710 CGGlyph *cglyphs;
711 unsigned long maxChar, maxGlyph;
712 long i, len;
714 - (instancetype)initWithCapacity: (unsigned long) c;
715 - (void) setString: (NSString *)str font: (NSFont *)font;
716 @end
717 #endif /* NS_IMPL_COCOA */
719 extern NSArray *ns_send_types, *ns_return_types;
720 extern NSString *ns_app_name;
721 extern EmacsMenu *svcsMenu;
723 /* Apple removed the declaration, but kept the implementation */
724 #if defined (NS_IMPL_COCOA)
725 @interface NSApplication (EmacsApp)
726 - (void)setAppleMenu: (NSMenu *)menu;
727 @end
728 #endif
730 #endif /* __OBJC__ */
734 /* ==========================================================================
736 Non-OO stuff
738 ========================================================================== */
740 /* Special keycodes that we pass down the event chain */
741 #define KEY_NS_POWER_OFF ((1<<28)|(0<<16)|1)
742 #define KEY_NS_OPEN_FILE ((1<<28)|(0<<16)|2)
743 #define KEY_NS_OPEN_TEMP_FILE ((1<<28)|(0<<16)|3)
744 #define KEY_NS_CHANGE_FONT ((1<<28)|(0<<16)|7)
745 #define KEY_NS_OPEN_FILE_LINE ((1<<28)|(0<<16)|8)
746 #define KEY_NS_PUT_WORKING_TEXT ((1<<28)|(0<<16)|9)
747 #define KEY_NS_UNPUT_WORKING_TEXT ((1<<28)|(0<<16)|10)
748 #define KEY_NS_SPI_SERVICE_CALL ((1<<28)|(0<<16)|11)
749 #define KEY_NS_NEW_FRAME ((1<<28)|(0<<16)|12)
750 #define KEY_NS_TOGGLE_TOOLBAR ((1<<28)|(0<<16)|13)
751 #define KEY_NS_SHOW_PREFS ((1<<28)|(0<<16)|14)
753 /* could use list to store these, but rest of emacs has a big infrastructure
754 for managing a table of bitmap "records" */
755 struct ns_bitmap_record
757 #ifdef __OBJC__
758 EmacsImage *img;
759 #else
760 void *img;
761 #endif
762 char *file;
763 int refcount;
764 int height, width, depth;
767 /* this to map between emacs color indices and NSColor objects */
768 struct ns_color_table
770 ptrdiff_t size;
771 ptrdiff_t avail;
772 #ifdef __OBJC__
773 NSColor **colors;
774 NSMutableSet *empty_indices;
775 #else
776 void **items;
777 void *availIndices;
778 #endif
780 #define NS_COLOR_CAPACITY 256
782 #define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
783 #define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
785 #define ALPHA_FROM_ULONG(color) ((color) >> 24)
786 #define RED_FROM_ULONG(color) (((color) >> 16) & 0xff)
787 #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
788 #define BLUE_FROM_ULONG(color) ((color) & 0xff)
790 /* Do not change `* 0x101' in the following lines to `<< 8'. If
791 changed, image masks in 1-bit depth will not work. */
792 #define RED16_FROM_ULONG(color) (RED_FROM_ULONG(color) * 0x101)
793 #define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
794 #define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)
796 /* this extends font backend font */
797 struct nsfont_info
799 struct font font;
801 char *name; /* PostScript name, uniquely identifies on NS systems */
803 /* The following metrics are stored as float rather than int. */
805 float width; /* Maximum advance for the font. */
806 float height;
807 float underpos;
808 float underwidth;
809 float size;
810 #ifdef __OBJC__
811 NSFont *nsfont;
812 #if defined (NS_IMPL_COCOA)
813 CGFontRef cgfont;
814 #else /* GNUstep */
815 void *cgfont;
816 #endif
817 #else /* ! OBJC */
818 void *nsfont;
819 void *cgfont;
820 #endif
821 char bold, ital; /* convenience flags */
822 char synthItal;
823 XCharStruct max_bounds;
824 /* we compute glyph codes and metrics on-demand in blocks of 256 indexed
825 by hibyte, lobyte */
826 unsigned short **glyphs; /* map Unicode index to glyph */
827 struct font_metrics **metrics;
831 /* init'd in ns_initialize_display_info () */
832 struct ns_display_info
834 /* Chain of all ns_display_info structures. */
835 struct ns_display_info *next;
837 /* The generic display parameters corresponding to this NS display. */
838 struct terminal *terminal;
840 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
841 Lisp_Object name_list_element;
843 /* The number of fonts loaded. */
844 int n_fonts;
846 /* Minimum width over all characters in all fonts in font_table. */
847 int smallest_char_width;
849 /* Minimum font height over all fonts in font_table. */
850 int smallest_font_height;
852 struct ns_bitmap_record *bitmaps;
853 ptrdiff_t bitmaps_size;
854 ptrdiff_t bitmaps_last;
856 struct ns_color_table *color_table;
858 /* DPI resolution of this screen */
859 double resx, resy;
861 /* Mask of things that cause the mouse to be grabbed */
862 int grabbed;
864 int n_planes;
866 int color_p;
868 Window root_window;
870 /* Xism */
871 XrmDatabase xrdb;
873 /* The cursor to use for vertical scroll bars. */
874 Cursor vertical_scroll_bar_cursor;
876 /* The cursor to use for horizontal scroll bars. */
877 Cursor horizontal_scroll_bar_cursor;
879 /* Information about the range of text currently shown in
880 mouse-face. */
881 Mouse_HLInfo mouse_highlight;
883 struct frame *x_highlight_frame;
884 struct frame *x_focus_frame;
886 /* The frame where the mouse was last time we reported a mouse event. */
887 struct frame *last_mouse_frame;
889 /* The frame where the mouse was last time we reported a mouse motion. */
890 struct frame *last_mouse_motion_frame;
892 /* Position where the mouse was last time we reported a motion.
893 This is a position on last_mouse_motion_frame. */
894 int last_mouse_motion_x;
895 int last_mouse_motion_y;
897 /* Where the mouse was last time we reported a mouse position. */
898 NSRect last_mouse_glyph;
900 /* Time of last mouse movement. */
901 Time last_mouse_movement_time;
903 /* The scroll bar in which the last motion event occurred. */
904 #ifdef __OBJC__
905 EmacsScroller *last_mouse_scroll_bar;
906 #else
907 void *last_mouse_scroll_bar;
908 #endif
911 /* This is a chain of structures for all the NS displays currently in use. */
912 extern struct ns_display_info *x_display_list;
914 struct ns_output
916 #ifdef __OBJC__
917 EmacsView *view;
918 id miniimage;
919 NSColor *cursor_color;
920 NSColor *foreground_color;
921 NSColor *background_color;
922 EmacsToolbar *toolbar;
923 #else
924 void *view;
925 void *miniimage;
926 void *cursor_color;
927 void *foreground_color;
928 void *background_color;
929 void *toolbar;
930 #endif
932 /* NSCursors init'ed in initFrameFromEmacs */
933 Cursor text_cursor;
934 Cursor nontext_cursor;
935 Cursor modeline_cursor;
936 Cursor hand_cursor;
937 Cursor hourglass_cursor;
938 Cursor horizontal_drag_cursor;
939 Cursor vertical_drag_cursor;
940 Cursor left_edge_cursor;
941 Cursor top_left_corner_cursor;
942 Cursor top_edge_cursor;
943 Cursor top_right_corner_cursor;
944 Cursor right_edge_cursor;
945 Cursor bottom_right_corner_cursor;
946 Cursor bottom_edge_cursor;
947 Cursor bottom_left_corner_cursor;
949 /* NS-specific */
950 Cursor current_pointer;
952 /* lord knows why Emacs needs to know about our Window ids.. */
953 Window window_desc, parent_desc;
954 char explicit_parent;
956 struct font *font;
957 int baseline_offset;
959 /* If a fontset is specified for this frame instead of font, this
960 value contains an ID of the fontset, else -1. */
961 int fontset; /* only used with font_backend */
963 int icon_top;
964 int icon_left;
966 /* The size of the extra width currently allotted for vertical
967 scroll bars, in pixels. */
968 int vertical_scroll_bar_extra;
970 /* The height of the titlebar decoration (included in NSWindow's frame). */
971 int titlebar_height;
973 /* The height of the toolbar if displayed, else 0. */
974 int toolbar_height;
976 /* This is the Emacs structure for the NS display this frame is on. */
977 struct ns_display_info *display_info;
979 /* Non-zero if we are zooming (maximizing) the frame. */
980 int zooming;
982 /* Non-zero if we are doing an animation, e.g. toggling the tool bar. */
983 int in_animation;
986 /* this dummy decl needed to support TTYs */
987 struct x_output
989 int unused;
993 /* This gives the ns_display_info structure for the display F is on. */
994 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.ns->display_info)
995 #define FRAME_X_OUTPUT(f) ((f)->output_data.ns)
996 #define FRAME_NS_WINDOW(f) ((f)->output_data.ns->window_desc)
997 #define FRAME_X_WINDOW(f) ((f)->output_data.ns->window_desc)
999 /* This is the `Display *' which frame F is on. */
1000 #define FRAME_NS_DISPLAY(f) (0)
1001 #define FRAME_X_DISPLAY(f) (0)
1002 #define FRAME_X_SCREEN(f) (0)
1003 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO(f)->visual
1005 #define FRAME_FOREGROUND_COLOR(f) ((f)->output_data.ns->foreground_color)
1006 #define FRAME_BACKGROUND_COLOR(f) ((f)->output_data.ns->background_color)
1008 #define NS_FACE_FOREGROUND(f) ((f)->foreground)
1009 #define NS_FACE_BACKGROUND(f) ((f)->background)
1011 #define FRAME_DEFAULT_FACE(f) FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID)
1013 #define FRAME_NS_VIEW(f) ((f)->output_data.ns->view)
1014 #define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
1015 #define FRAME_POINTER_TYPE(f) ((f)->output_data.ns->current_pointer)
1017 #define FRAME_FONT(f) ((f)->output_data.ns->font)
1019 #ifdef __OBJC__
1020 #define XNS_SCROLL_BAR(vec) ((id) XSAVE_POINTER (vec, 0))
1021 #else
1022 #define XNS_SCROLL_BAR(vec) XSAVE_POINTER (vec, 0)
1023 #endif
1025 /* Compute pixel height of the frame's titlebar. */
1026 #define FRAME_NS_TITLEBAR_HEIGHT(f) \
1027 (NSHeight([FRAME_NS_VIEW (f) frame]) == 0 ? \
1029 : (int)(NSHeight([FRAME_NS_VIEW (f) window].frame) \
1030 - NSHeight([NSWindow contentRectForFrameRect: \
1031 [[FRAME_NS_VIEW (f) window] frame] \
1032 styleMask:[[FRAME_NS_VIEW (f) window] styleMask]])))
1034 /* Compute pixel height of the toolbar. */
1035 #define FRAME_TOOLBAR_HEIGHT(f) \
1036 (([[FRAME_NS_VIEW (f) window] toolbar] == nil \
1037 || ! [[FRAME_NS_VIEW (f) window] toolbar].isVisible) ? \
1039 : (int)(NSHeight([NSWindow contentRectForFrameRect: \
1040 [[FRAME_NS_VIEW (f) window] frame] \
1041 styleMask:[[FRAME_NS_VIEW (f) window] styleMask]]) \
1042 - NSHeight([[[FRAME_NS_VIEW (f) window] contentView] frame])))
1044 /* Compute pixel size for vertical scroll bars */
1045 #define NS_SCROLL_BAR_WIDTH(f) \
1046 (FRAME_HAS_VERTICAL_SCROLL_BARS (f) \
1047 ? rint (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0 \
1048 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f) \
1049 : (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f))) \
1050 : 0)
1052 /* Compute pixel size for horizontal scroll bars */
1053 #define NS_SCROLL_BAR_HEIGHT(f) \
1054 (FRAME_HAS_HORIZONTAL_SCROLL_BARS (f) \
1055 ? rint (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0 \
1056 ? FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) \
1057 : (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f))) \
1058 : 0)
1060 /* Difference btwn char-column-calculated and actual SB widths.
1061 This is only a concern for rendering when SB on left. */
1062 #define NS_SCROLL_BAR_ADJUST(w, f) \
1063 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) ? \
1064 (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f) \
1065 - NS_SCROLL_BAR_WIDTH (f)) : 0)
1067 /* Difference btwn char-line-calculated and actual SB heights.
1068 This is only a concern for rendering when SB on top. */
1069 #define NS_SCROLL_BAR_ADJUST_HORIZONTALLY(w, f) \
1070 (WINDOW_HAS_HORIZONTAL_SCROLL_BARS (w) ? \
1071 (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f) \
1072 - NS_SCROLL_BAR_HEIGHT (f)) : 0)
1074 /* Calculate system coordinates of the left and top of the parent
1075 window or, if there is no parent window, the screen. */
1076 #define NS_PARENT_WINDOW_LEFT_POS(f) \
1077 (FRAME_PARENT_FRAME (f) != NULL \
1078 ? [[FRAME_NS_VIEW (f) window] parentWindow].frame.origin.x : 0)
1079 #define NS_PARENT_WINDOW_TOP_POS(f) \
1080 (FRAME_PARENT_FRAME (f) != NULL \
1081 ? ([[FRAME_NS_VIEW (f) window] parentWindow].frame.origin.y \
1082 + [[FRAME_NS_VIEW (f) window] parentWindow].frame.size.height \
1083 - FRAME_NS_TITLEBAR_HEIGHT (FRAME_PARENT_FRAME (f))) \
1084 : [[[NSScreen screens] objectAtIndex: 0] frame].size.height)
1086 #define FRAME_NS_FONT_TABLE(f) (FRAME_DISPLAY_INFO (f)->font_table)
1088 #define FRAME_FONTSET(f) ((f)->output_data.ns->fontset)
1090 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.ns->baseline_offset)
1091 #define BLACK_PIX_DEFAULT(f) 0x000000
1092 #define WHITE_PIX_DEFAULT(f) 0xFFFFFF
1094 /* First position where characters can be shown (instead of scrollbar, if
1095 it is on left. */
1096 #define FIRST_CHAR_POSITION(f) \
1097 (! (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) ? 0 \
1098 : FRAME_SCROLL_BAR_COLS (f))
1100 extern struct ns_display_info *ns_term_init (Lisp_Object display_name);
1101 extern void ns_term_shutdown (int sig);
1103 /* constants for text rendering */
1104 #define NS_DUMPGLYPH_NORMAL 0
1105 #define NS_DUMPGLYPH_CURSOR 1
1106 #define NS_DUMPGLYPH_FOREGROUND 2
1107 #define NS_DUMPGLYPH_MOUSEFACE 3
1111 /* In nsfont, called from fontset.c */
1112 extern void nsfont_make_fontset_for_font (Lisp_Object name,
1113 Lisp_Object font_object);
1115 /* In nsfont, for debugging */
1116 struct glyph_string;
1117 void ns_dump_glyphstring (struct glyph_string *s) EXTERNALLY_VISIBLE;
1119 /* Implemented in nsterm, published in or needed from nsfns. */
1120 extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern,
1121 int size, int maxnames);
1122 extern void ns_clear_frame (struct frame *f);
1124 extern const char *ns_xlfd_to_fontname (const char *xlfd);
1126 extern Lisp_Object ns_map_event_to_object (void);
1127 #ifdef __OBJC__
1128 extern Lisp_Object ns_string_from_pasteboard (id pb);
1129 extern void ns_string_to_pasteboard (id pb, Lisp_Object str);
1130 #endif
1131 extern Lisp_Object ns_get_local_selection (Lisp_Object selection_name,
1132 Lisp_Object target_type);
1133 extern void nxatoms_of_nsselect (void);
1134 extern void ns_set_doc_edited (void);
1136 extern bool
1137 ns_defined_color (struct frame *f,
1138 const char *name,
1139 XColor *color_def, bool alloc,
1140 bool makeIndex);
1141 extern void
1142 ns_query_color (void *col, XColor *color_def, int setPixel);
1144 #ifdef __OBJC__
1145 extern int ns_lisp_to_color (Lisp_Object color, NSColor **col);
1146 extern NSColor *ns_lookup_indexed_color (unsigned long idx, struct frame *f);
1147 extern unsigned long ns_index_color (NSColor *color, struct frame *f);
1148 extern const char *ns_get_pending_menu_title (void);
1149 extern void ns_check_menu_open (NSMenu *menu);
1150 extern void ns_check_pending_open_menu (void);
1151 #endif
1153 /* C access to ObjC functionality */
1154 extern void ns_release_object (void *obj);
1155 extern void ns_retain_object (void *obj);
1156 extern void *ns_alloc_autorelease_pool (void);
1157 extern void ns_release_autorelease_pool (void *);
1158 extern const char *ns_get_defaults_value (const char *key);
1159 extern void ns_init_locale (void);
1162 /* in nsmenu */
1163 extern void update_frame_tool_bar (struct frame *f);
1164 extern void free_frame_tool_bar (struct frame *f);
1165 extern Lisp_Object find_and_return_menu_selection (struct frame *f,
1166 bool keymaps,
1167 void *client_data);
1168 extern Lisp_Object ns_popup_dialog (struct frame *, Lisp_Object header,
1169 Lisp_Object contents);
1171 #define NSAPP_DATA2_RUNASSCRIPT 10
1172 extern void ns_run_ascript (void);
1174 #define NSAPP_DATA2_RUNFILEDIALOG 11
1175 extern void ns_run_file_dialog (void);
1177 extern const char *ns_etc_directory (void);
1178 extern const char *ns_exec_path (void);
1179 extern const char *ns_load_path (void);
1180 extern void syms_of_nsterm (void);
1181 extern void syms_of_nsfns (void);
1182 extern void syms_of_nsmenu (void);
1183 extern void syms_of_nsselect (void);
1185 /* From nsimage.m, needed in image.c */
1186 struct image;
1187 extern void *ns_image_from_XBM (char *bits, int width, int height,
1188 unsigned long fg, unsigned long bg);
1189 extern void *ns_image_for_XPM (int width, int height, int depth);
1190 extern void *ns_image_from_file (Lisp_Object file);
1191 extern bool ns_load_image (struct frame *f, struct image *img,
1192 Lisp_Object spec_file, Lisp_Object spec_data);
1193 extern int ns_image_width (void *img);
1194 extern int ns_image_height (void *img);
1195 extern unsigned long ns_get_pixel (void *img, int x, int y);
1196 extern void ns_put_pixel (void *img, int x, int y, unsigned long argb);
1197 extern void ns_set_alpha (void *img, int x, int y, unsigned char a);
1199 extern int x_display_pixel_height (struct ns_display_info *);
1200 extern int x_display_pixel_width (struct ns_display_info *);
1202 /* This in nsterm.m */
1203 extern float ns_antialias_threshold;
1204 extern void x_destroy_window (struct frame *f);
1205 extern void x_set_undecorated (struct frame *f, Lisp_Object new_value,
1206 Lisp_Object old_value);
1207 extern void x_set_parent_frame (struct frame *f, Lisp_Object new_value,
1208 Lisp_Object old_value);
1209 extern void x_set_no_focus_on_map (struct frame *f, Lisp_Object new_value,
1210 Lisp_Object old_value);
1211 extern void x_set_no_accept_focus (struct frame *f, Lisp_Object new_value,
1212 Lisp_Object old_value);
1213 extern void x_set_z_group (struct frame *f, Lisp_Object new_value,
1214 Lisp_Object old_value);
1215 #ifdef NS_IMPL_COCOA
1216 extern void ns_set_appearance (struct frame *f, Lisp_Object new_value,
1217 Lisp_Object old_value);
1218 extern void ns_set_transparent_titlebar (struct frame *f,
1219 Lisp_Object new_value,
1220 Lisp_Object old_value);
1221 #endif
1222 extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds,
1223 fd_set *exceptfds, struct timespec *timeout,
1224 sigset_t *sigmask);
1225 #ifdef HAVE_PTHREAD
1226 extern void ns_run_loop_break (void);
1227 #endif
1228 extern unsigned long ns_get_rgb_color (struct frame *f,
1229 float r, float g, float b, float a);
1231 struct input_event;
1232 extern void ns_init_events (struct input_event *);
1233 extern void ns_finish_events (void);
1235 #ifdef __OBJC__
1236 /* Needed in nsfns.m. */
1237 extern void
1238 ns_set_represented_filename (NSString *fstr, struct frame *f);
1240 #endif
1242 #ifdef NS_IMPL_GNUSTEP
1243 extern char gnustep_base_version[]; /* version tracking */
1244 #endif
1246 #define MINWIDTH 10
1247 #define MINHEIGHT 10
1249 /* Screen max coordinate
1250 Using larger coordinates causes movewindow/placewindow to abort */
1251 #define SCREENMAX 16000
1253 #define NS_SCROLL_BAR_WIDTH_DEFAULT [EmacsScroller scrollerWidth]
1254 #define NS_SCROLL_BAR_HEIGHT_DEFAULT [EmacsScroller scrollerHeight]
1255 /* This is to match emacs on other platforms, ugly though it is. */
1256 #define NS_SELECTION_BG_COLOR_DEFAULT @"LightGoldenrod2";
1257 #define NS_SELECTION_FG_COLOR_DEFAULT @"Black";
1258 #define RESIZE_HANDLE_SIZE 12
1260 /* Little utility macros */
1261 #define IN_BOUND(min, x, max) (((x) < (min)) \
1262 ? (min) : (((x)>(max)) ? (max) : (x)))
1263 #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
1265 /* macOS 10.7 introduces some new constants. */
1266 #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_7)
1267 #define NSFullScreenWindowMask (1 << 14)
1268 #define NSWindowCollectionBehaviorFullScreenPrimary (1 << 7)
1269 #define NSApplicationPresentationFullScreen (1 << 10)
1270 #define NSApplicationPresentationAutoHideToolbar (1 << 11)
1271 #define NSAppKitVersionNumber10_7 1138
1272 #endif /* !defined (MAC_OS_X_VERSION_10_7) */
1274 /* macOS 10.12 deprecates a bunch of constants. */
1275 #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_12)
1276 #define NSEventModifierFlagCommand NSCommandKeyMask
1277 #define NSEventModifierFlagControl NSControlKeyMask
1278 #define NSEventModifierFlagHelp NSHelpKeyMask
1279 #define NSEventModifierFlagNumericPad NSNumericPadKeyMask
1280 #define NSEventModifierFlagOption NSAlternateKeyMask
1281 #define NSEventModifierFlagShift NSShiftKeyMask
1282 #define NSCompositingOperationSourceOver NSCompositeSourceOver
1283 #define NSEventMaskApplicationDefined NSApplicationDefinedMask
1284 #define NSEventTypeApplicationDefined NSApplicationDefined
1285 #define NSEventTypeCursorUpdate NSCursorUpdate
1286 #define NSEventTypeMouseMoved NSMouseMoved
1287 #define NSEventTypeLeftMouseDown NSLeftMouseDown
1288 #define NSEventTypeRightMouseDown NSRightMouseDown
1289 #define NSEventTypeOtherMouseDown NSOtherMouseDown
1290 #define NSEventTypeLeftMouseUp NSLeftMouseUp
1291 #define NSEventTypeRightMouseUp NSRightMouseUp
1292 #define NSEventTypeOtherMouseUp NSOtherMouseUp
1293 #define NSEventTypeLeftMouseDragged NSLeftMouseDragged
1294 #define NSEventTypeRightMouseDragged NSRightMouseDragged
1295 #define NSEventTypeOtherMouseDragged NSOtherMouseDragged
1296 #define NSEventTypeScrollWheel NSScrollWheel
1297 #define NSEventTypeKeyDown NSKeyDown
1298 #define NSEventTypeKeyUp NSKeyUp
1299 #define NSEventTypeFlagsChanged NSFlagsChanged
1300 #define NSEventMaskAny NSAnyEventMask
1301 #define NSEventTypeSystemDefined NSSystemDefined
1302 #define NSWindowStyleMaskBorderless NSBorderlessWindowMask
1303 #define NSWindowStyleMaskClosable NSClosableWindowMask
1304 #define NSWindowStyleMaskFullScreen NSFullScreenWindowMask
1305 #define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask
1306 #define NSWindowStyleMaskResizable NSResizableWindowMask
1307 #define NSWindowStyleMaskTitled NSTitledWindowMask
1308 #define NSWindowStyleMaskUtilityWindow NSUtilityWindowMask
1309 #define NSAlertStyleCritical NSCriticalAlertStyle
1310 #define NSControlSizeRegular NSRegularControlSize
1311 #define NSCompositingOperationCopy NSCompositeCopy
1313 /* And adds NSWindowStyleMask. */
1314 #ifdef __OBJC__
1315 typedef NSUInteger NSWindowStyleMask;
1316 #endif
1318 /* Window tabbing mode enums are new too. */
1319 enum NSWindowTabbingMode
1321 NSWindowTabbingModeAutomatic,
1322 NSWindowTabbingModePreferred,
1323 NSWindowTabbingModeDisallowed
1325 #endif
1326 #endif /* HAVE_NS */