Allow 'browse-url-emacs' to fetch URL in the selected window
[emacs.git] / src / nsterm.h
blob8b985930ecb3791b9b508c0c9f8f0347f9a11ad6
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) setBackgroundColor: (NSColor *)col;
589 - (void) setForegroundColor: (NSColor *)col;
590 - (void) showAtX: (int)x Y: (int)y for: (int)seconds;
591 - (void) hide;
592 - (BOOL) isActive;
593 - (NSRect) frame;
594 @end
597 /* ==========================================================================
599 File open/save panels
600 This and next override methods to handle keyboard input in panels.
602 ========================================================================== */
604 @interface EmacsSavePanel : NSSavePanel
607 @end
608 @interface EmacsOpenPanel : NSOpenPanel
611 @end
613 @interface EmacsFileDelegate : NSObject
616 - (BOOL)panel: (id)sender isValidFilename: (NSString *)filename;
617 - (BOOL)panel: (id)sender shouldShowFilename: (NSString *)filename;
618 - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
619 confirmed: (BOOL)okFlag;
620 @end
623 /* ==========================================================================
625 Images and stippling
627 ========================================================================== */
629 @interface EmacsImage : NSImage
631 NSBitmapImageRep *bmRep; /* used for accessing pixel data */
632 unsigned char *pixmapData[5]; /* shortcut to access pixel data */
633 NSColor *stippleMask;
634 unsigned long xbm_fg;
636 + (instancetype)allocInitFromFile: (Lisp_Object)file;
637 - (void)dealloc;
638 - (instancetype)initFromXBM: (unsigned char *)bits width: (int)w height: (int)h
639 fg: (unsigned long)fg bg: (unsigned long)bg;
640 - (instancetype)setXBMColor: (NSColor *)color;
641 - (instancetype)initForXPMWithDepth: (int)depth width: (int)width height: (int)height;
642 - (void)setPixmapData;
643 - (unsigned long)getPixelAtX: (int)x Y: (int)y;
644 - (void)setPixelAtX: (int)x Y: (int)y toRed: (unsigned char)r
645 green: (unsigned char)g blue: (unsigned char)b
646 alpha:(unsigned char)a;
647 - (void)setAlphaAtX: (int)x Y: (int)y to: (unsigned char)a;
648 - (NSColor *)stippleMask;
649 - (Lisp_Object)getMetadata;
650 - (BOOL)setFrame: (unsigned int) index;
651 - (void)setSizeFromSpec: (Lisp_Object) spec;
652 - (instancetype)rotate: (double)rotation;
653 @end
656 /* ==========================================================================
658 Scrollbars
660 ========================================================================== */
662 @interface EmacsScroller : NSScroller
664 struct window *window;
665 struct frame *frame;
666 NSResponder *prevResponder;
668 /* offset to the bottom of knob of last mouse down */
669 CGFloat last_mouse_offset;
670 float min_portion;
671 int pixel_length;
672 enum scroll_bar_part last_hit_part;
674 BOOL condemned;
676 BOOL horizontal;
678 /* optimize against excessive positioning calls generated by emacs */
679 int em_position;
680 int em_portion;
681 int em_whole;
684 - (instancetype) initFrame: (NSRect )r window: (Lisp_Object)win;
685 - (void)setFrame: (NSRect)r;
687 - (instancetype) setPosition: (int) position portion: (int) portion whole: (int) whole;
688 - (int) checkSamePosition: (int)position portion: (int)portion
689 whole: (int)whole;
690 - (void) sendScrollEventAtLoc: (float)loc fromEvent: (NSEvent *)e;
691 - (instancetype)repeatScroll: (NSTimer *)sender;
692 - (instancetype)condemn;
693 - (instancetype)reprieve;
694 - (bool)judge;
695 + (CGFloat)scrollerWidth;
696 @end
699 /* ==========================================================================
701 Rendering
703 ========================================================================== */
705 #ifdef NS_IMPL_COCOA
706 /* rendering util */
707 @interface EmacsGlyphStorage : NSObject <NSGlyphStorage>
709 @public
710 NSAttributedString *attrStr;
711 NSMutableDictionary *dict;
712 CGGlyph *cglyphs;
713 unsigned long maxChar, maxGlyph;
714 long i, len;
716 - (instancetype)initWithCapacity: (unsigned long) c;
717 - (void) setString: (NSString *)str font: (NSFont *)font;
718 @end
719 #endif /* NS_IMPL_COCOA */
721 extern NSArray *ns_send_types, *ns_return_types;
722 extern NSString *ns_app_name;
723 extern EmacsMenu *svcsMenu;
725 /* Apple removed the declaration, but kept the implementation */
726 #if defined (NS_IMPL_COCOA)
727 @interface NSApplication (EmacsApp)
728 - (void)setAppleMenu: (NSMenu *)menu;
729 @end
730 #endif
732 #endif /* __OBJC__ */
736 /* ==========================================================================
738 Non-OO stuff
740 ========================================================================== */
742 /* Special keycodes that we pass down the event chain */
743 #define KEY_NS_POWER_OFF ((1<<28)|(0<<16)|1)
744 #define KEY_NS_OPEN_FILE ((1<<28)|(0<<16)|2)
745 #define KEY_NS_OPEN_TEMP_FILE ((1<<28)|(0<<16)|3)
746 #define KEY_NS_CHANGE_FONT ((1<<28)|(0<<16)|7)
747 #define KEY_NS_OPEN_FILE_LINE ((1<<28)|(0<<16)|8)
748 #define KEY_NS_PUT_WORKING_TEXT ((1<<28)|(0<<16)|9)
749 #define KEY_NS_UNPUT_WORKING_TEXT ((1<<28)|(0<<16)|10)
750 #define KEY_NS_SPI_SERVICE_CALL ((1<<28)|(0<<16)|11)
751 #define KEY_NS_NEW_FRAME ((1<<28)|(0<<16)|12)
752 #define KEY_NS_TOGGLE_TOOLBAR ((1<<28)|(0<<16)|13)
753 #define KEY_NS_SHOW_PREFS ((1<<28)|(0<<16)|14)
755 /* could use list to store these, but rest of emacs has a big infrastructure
756 for managing a table of bitmap "records" */
757 struct ns_bitmap_record
759 #ifdef __OBJC__
760 EmacsImage *img;
761 #else
762 void *img;
763 #endif
764 char *file;
765 int refcount;
766 int height, width, depth;
769 /* this to map between emacs color indices and NSColor objects */
770 struct ns_color_table
772 ptrdiff_t size;
773 ptrdiff_t avail;
774 #ifdef __OBJC__
775 NSColor **colors;
776 NSMutableSet *empty_indices;
777 #else
778 void **items;
779 void *availIndices;
780 #endif
782 #define NS_COLOR_CAPACITY 256
784 #define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
785 #define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
787 #define ALPHA_FROM_ULONG(color) ((color) >> 24)
788 #define RED_FROM_ULONG(color) (((color) >> 16) & 0xff)
789 #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
790 #define BLUE_FROM_ULONG(color) ((color) & 0xff)
792 /* Do not change `* 0x101' in the following lines to `<< 8'. If
793 changed, image masks in 1-bit depth will not work. */
794 #define RED16_FROM_ULONG(color) (RED_FROM_ULONG(color) * 0x101)
795 #define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
796 #define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)
798 /* this extends font backend font */
799 struct nsfont_info
801 struct font font;
803 char *name; /* PostScript name, uniquely identifies on NS systems */
805 /* The following metrics are stored as float rather than int. */
807 float width; /* Maximum advance for the font. */
808 float height;
809 float underpos;
810 float underwidth;
811 float size;
812 #ifdef __OBJC__
813 NSFont *nsfont;
814 #if defined (NS_IMPL_COCOA)
815 CGFontRef cgfont;
816 #else /* GNUstep */
817 void *cgfont;
818 #endif
819 #else /* ! OBJC */
820 void *nsfont;
821 void *cgfont;
822 #endif
823 char bold, ital; /* convenience flags */
824 char synthItal;
825 XCharStruct max_bounds;
826 /* we compute glyph codes and metrics on-demand in blocks of 256 indexed
827 by hibyte, lobyte */
828 unsigned short **glyphs; /* map Unicode index to glyph */
829 struct font_metrics **metrics;
833 /* init'd in ns_initialize_display_info () */
834 struct ns_display_info
836 /* Chain of all ns_display_info structures. */
837 struct ns_display_info *next;
839 /* The generic display parameters corresponding to this NS display. */
840 struct terminal *terminal;
842 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
843 Lisp_Object name_list_element;
845 /* The number of fonts loaded. */
846 int n_fonts;
848 /* Minimum width over all characters in all fonts in font_table. */
849 int smallest_char_width;
851 /* Minimum font height over all fonts in font_table. */
852 int smallest_font_height;
854 struct ns_bitmap_record *bitmaps;
855 ptrdiff_t bitmaps_size;
856 ptrdiff_t bitmaps_last;
858 struct ns_color_table *color_table;
860 /* DPI resolution of this screen */
861 double resx, resy;
863 /* Mask of things that cause the mouse to be grabbed */
864 int grabbed;
866 int n_planes;
868 int color_p;
870 Window root_window;
872 /* Xism */
873 XrmDatabase xrdb;
875 /* The cursor to use for vertical scroll bars. */
876 Cursor vertical_scroll_bar_cursor;
878 /* The cursor to use for horizontal scroll bars. */
879 Cursor horizontal_scroll_bar_cursor;
881 /* Information about the range of text currently shown in
882 mouse-face. */
883 Mouse_HLInfo mouse_highlight;
885 struct frame *x_highlight_frame;
886 struct frame *x_focus_frame;
888 /* The frame where the mouse was last time we reported a mouse event. */
889 struct frame *last_mouse_frame;
891 /* The frame where the mouse was last time we reported a mouse motion. */
892 struct frame *last_mouse_motion_frame;
894 /* Position where the mouse was last time we reported a motion.
895 This is a position on last_mouse_motion_frame. */
896 int last_mouse_motion_x;
897 int last_mouse_motion_y;
899 /* Where the mouse was last time we reported a mouse position. */
900 NSRect last_mouse_glyph;
902 /* Time of last mouse movement. */
903 Time last_mouse_movement_time;
905 /* The scroll bar in which the last motion event occurred. */
906 #ifdef __OBJC__
907 EmacsScroller *last_mouse_scroll_bar;
908 #else
909 void *last_mouse_scroll_bar;
910 #endif
913 /* This is a chain of structures for all the NS displays currently in use. */
914 extern struct ns_display_info *x_display_list;
916 struct ns_output
918 #ifdef __OBJC__
919 EmacsView *view;
920 id miniimage;
921 NSColor *cursor_color;
922 NSColor *foreground_color;
923 NSColor *background_color;
924 EmacsToolbar *toolbar;
925 #else
926 void *view;
927 void *miniimage;
928 void *cursor_color;
929 void *foreground_color;
930 void *background_color;
931 void *toolbar;
932 #endif
934 /* NSCursors init'ed in initFrameFromEmacs */
935 Cursor text_cursor;
936 Cursor nontext_cursor;
937 Cursor modeline_cursor;
938 Cursor hand_cursor;
939 Cursor hourglass_cursor;
940 Cursor horizontal_drag_cursor;
941 Cursor vertical_drag_cursor;
942 Cursor left_edge_cursor;
943 Cursor top_left_corner_cursor;
944 Cursor top_edge_cursor;
945 Cursor top_right_corner_cursor;
946 Cursor right_edge_cursor;
947 Cursor bottom_right_corner_cursor;
948 Cursor bottom_edge_cursor;
949 Cursor bottom_left_corner_cursor;
951 /* NS-specific */
952 Cursor current_pointer;
954 /* lord knows why Emacs needs to know about our Window ids.. */
955 Window window_desc, parent_desc;
956 char explicit_parent;
958 struct font *font;
959 int baseline_offset;
961 /* If a fontset is specified for this frame instead of font, this
962 value contains an ID of the fontset, else -1. */
963 int fontset; /* only used with font_backend */
965 int icon_top;
966 int icon_left;
968 /* The size of the extra width currently allotted for vertical
969 scroll bars, in pixels. */
970 int vertical_scroll_bar_extra;
972 /* The height of the titlebar decoration (included in NSWindow's frame). */
973 int titlebar_height;
975 /* The height of the toolbar if displayed, else 0. */
976 int toolbar_height;
978 /* This is the Emacs structure for the NS display this frame is on. */
979 struct ns_display_info *display_info;
981 /* Non-zero if we are zooming (maximizing) the frame. */
982 int zooming;
984 /* Non-zero if we are doing an animation, e.g. toggling the tool bar. */
985 int in_animation;
988 /* this dummy decl needed to support TTYs */
989 struct x_output
991 int unused;
995 /* This gives the ns_display_info structure for the display F is on. */
996 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.ns->display_info)
997 #define FRAME_X_OUTPUT(f) ((f)->output_data.ns)
998 #define FRAME_NS_WINDOW(f) ((f)->output_data.ns->window_desc)
999 #define FRAME_X_WINDOW(f) ((f)->output_data.ns->window_desc)
1001 /* This is the `Display *' which frame F is on. */
1002 #define FRAME_NS_DISPLAY(f) (0)
1003 #define FRAME_X_DISPLAY(f) (0)
1004 #define FRAME_X_SCREEN(f) (0)
1005 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO(f)->visual
1007 #define FRAME_FOREGROUND_COLOR(f) ((f)->output_data.ns->foreground_color)
1008 #define FRAME_BACKGROUND_COLOR(f) ((f)->output_data.ns->background_color)
1010 #define NS_FACE_FOREGROUND(f) ((f)->foreground)
1011 #define NS_FACE_BACKGROUND(f) ((f)->background)
1013 #define FRAME_DEFAULT_FACE(f) FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID)
1015 #define FRAME_NS_VIEW(f) ((f)->output_data.ns->view)
1016 #define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
1017 #define FRAME_POINTER_TYPE(f) ((f)->output_data.ns->current_pointer)
1019 #define FRAME_FONT(f) ((f)->output_data.ns->font)
1021 #ifdef __OBJC__
1022 #define XNS_SCROLL_BAR(vec) ((id) XSAVE_POINTER (vec, 0))
1023 #else
1024 #define XNS_SCROLL_BAR(vec) XSAVE_POINTER (vec, 0)
1025 #endif
1027 /* Compute pixel height of the frame's titlebar. */
1028 #define FRAME_NS_TITLEBAR_HEIGHT(f) \
1029 (NSHeight([FRAME_NS_VIEW (f) frame]) == 0 ? \
1031 : (int)(NSHeight([FRAME_NS_VIEW (f) window].frame) \
1032 - NSHeight([NSWindow contentRectForFrameRect: \
1033 [[FRAME_NS_VIEW (f) window] frame] \
1034 styleMask:[[FRAME_NS_VIEW (f) window] styleMask]])))
1036 /* Compute pixel height of the toolbar. */
1037 #define FRAME_TOOLBAR_HEIGHT(f) \
1038 (([[FRAME_NS_VIEW (f) window] toolbar] == nil \
1039 || ! [[FRAME_NS_VIEW (f) window] toolbar].isVisible) ? \
1041 : (int)(NSHeight([NSWindow contentRectForFrameRect: \
1042 [[FRAME_NS_VIEW (f) window] frame] \
1043 styleMask:[[FRAME_NS_VIEW (f) window] styleMask]]) \
1044 - NSHeight([[[FRAME_NS_VIEW (f) window] contentView] frame])))
1046 /* Compute pixel size for vertical scroll bars */
1047 #define NS_SCROLL_BAR_WIDTH(f) \
1048 (FRAME_HAS_VERTICAL_SCROLL_BARS (f) \
1049 ? rint (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0 \
1050 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f) \
1051 : (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f))) \
1052 : 0)
1054 /* Compute pixel size for horizontal scroll bars */
1055 #define NS_SCROLL_BAR_HEIGHT(f) \
1056 (FRAME_HAS_HORIZONTAL_SCROLL_BARS (f) \
1057 ? rint (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0 \
1058 ? FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) \
1059 : (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f))) \
1060 : 0)
1062 /* Difference btwn char-column-calculated and actual SB widths.
1063 This is only a concern for rendering when SB on left. */
1064 #define NS_SCROLL_BAR_ADJUST(w, f) \
1065 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) ? \
1066 (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f) \
1067 - NS_SCROLL_BAR_WIDTH (f)) : 0)
1069 /* Difference btwn char-line-calculated and actual SB heights.
1070 This is only a concern for rendering when SB on top. */
1071 #define NS_SCROLL_BAR_ADJUST_HORIZONTALLY(w, f) \
1072 (WINDOW_HAS_HORIZONTAL_SCROLL_BARS (w) ? \
1073 (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f) \
1074 - NS_SCROLL_BAR_HEIGHT (f)) : 0)
1076 /* Calculate system coordinates of the left and top of the parent
1077 window or, if there is no parent window, the screen. */
1078 #define NS_PARENT_WINDOW_LEFT_POS(f) \
1079 (FRAME_PARENT_FRAME (f) != NULL \
1080 ? [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.origin.x : 0)
1081 #define NS_PARENT_WINDOW_TOP_POS(f) \
1082 (FRAME_PARENT_FRAME (f) != NULL \
1083 ? ([FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.origin.y \
1084 + [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.size.height \
1085 - FRAME_NS_TITLEBAR_HEIGHT (FRAME_PARENT_FRAME (f))) \
1086 : [[[NSScreen screens] objectAtIndex: 0] frame].size.height)
1088 #define FRAME_NS_FONT_TABLE(f) (FRAME_DISPLAY_INFO (f)->font_table)
1090 #define FRAME_FONTSET(f) ((f)->output_data.ns->fontset)
1092 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.ns->baseline_offset)
1093 #define BLACK_PIX_DEFAULT(f) 0x000000
1094 #define WHITE_PIX_DEFAULT(f) 0xFFFFFF
1096 /* First position where characters can be shown (instead of scrollbar, if
1097 it is on left. */
1098 #define FIRST_CHAR_POSITION(f) \
1099 (! (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) ? 0 \
1100 : FRAME_SCROLL_BAR_COLS (f))
1102 extern struct ns_display_info *ns_term_init (Lisp_Object display_name);
1103 extern void ns_term_shutdown (int sig);
1105 /* constants for text rendering */
1106 #define NS_DUMPGLYPH_NORMAL 0
1107 #define NS_DUMPGLYPH_CURSOR 1
1108 #define NS_DUMPGLYPH_FOREGROUND 2
1109 #define NS_DUMPGLYPH_MOUSEFACE 3
1113 /* In nsfont, called from fontset.c */
1114 extern void nsfont_make_fontset_for_font (Lisp_Object name,
1115 Lisp_Object font_object);
1117 /* In nsfont, for debugging */
1118 struct glyph_string;
1119 void ns_dump_glyphstring (struct glyph_string *s) EXTERNALLY_VISIBLE;
1121 /* Implemented in nsterm, published in or needed from nsfns. */
1122 extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern,
1123 int size, int maxnames);
1124 extern void ns_clear_frame (struct frame *f);
1126 extern const char *ns_xlfd_to_fontname (const char *xlfd);
1128 extern Lisp_Object ns_map_event_to_object (void);
1129 #ifdef __OBJC__
1130 extern Lisp_Object ns_string_from_pasteboard (id pb);
1131 extern void ns_string_to_pasteboard (id pb, Lisp_Object str);
1132 #endif
1133 extern Lisp_Object ns_get_local_selection (Lisp_Object selection_name,
1134 Lisp_Object target_type);
1135 extern void nxatoms_of_nsselect (void);
1136 extern void ns_set_doc_edited (void);
1138 extern bool
1139 ns_defined_color (struct frame *f,
1140 const char *name,
1141 XColor *color_def, bool alloc,
1142 bool makeIndex);
1143 extern void
1144 ns_query_color (void *col, XColor *color_def, int setPixel);
1146 #ifdef __OBJC__
1147 extern int ns_lisp_to_color (Lisp_Object color, NSColor **col);
1148 extern NSColor *ns_lookup_indexed_color (unsigned long idx, struct frame *f);
1149 extern unsigned long ns_index_color (NSColor *color, struct frame *f);
1150 extern const char *ns_get_pending_menu_title (void);
1151 extern void ns_check_menu_open (NSMenu *menu);
1152 extern void ns_check_pending_open_menu (void);
1153 #endif
1155 /* C access to ObjC functionality */
1156 extern void ns_release_object (void *obj);
1157 extern void ns_retain_object (void *obj);
1158 extern void *ns_alloc_autorelease_pool (void);
1159 extern void ns_release_autorelease_pool (void *);
1160 extern const char *ns_get_defaults_value (const char *key);
1161 extern void ns_init_locale (void);
1164 /* in nsmenu */
1165 extern void update_frame_tool_bar (struct frame *f);
1166 extern void free_frame_tool_bar (struct frame *f);
1167 extern Lisp_Object find_and_return_menu_selection (struct frame *f,
1168 bool keymaps,
1169 void *client_data);
1170 extern Lisp_Object ns_popup_dialog (struct frame *, Lisp_Object header,
1171 Lisp_Object contents);
1173 #define NSAPP_DATA2_RUNASSCRIPT 10
1174 extern void ns_run_ascript (void);
1176 #define NSAPP_DATA2_RUNFILEDIALOG 11
1177 extern void ns_run_file_dialog (void);
1179 extern const char *ns_etc_directory (void);
1180 extern const char *ns_exec_path (void);
1181 extern const char *ns_load_path (void);
1182 extern void syms_of_nsterm (void);
1183 extern void syms_of_nsfns (void);
1184 extern void syms_of_nsmenu (void);
1185 extern void syms_of_nsselect (void);
1187 /* From nsimage.m, needed in image.c */
1188 struct image;
1189 extern void *ns_image_from_XBM (char *bits, int width, int height,
1190 unsigned long fg, unsigned long bg);
1191 extern void *ns_image_for_XPM (int width, int height, int depth);
1192 extern void *ns_image_from_file (Lisp_Object file);
1193 extern bool ns_load_image (struct frame *f, struct image *img,
1194 Lisp_Object spec_file, Lisp_Object spec_data);
1195 extern int ns_image_width (void *img);
1196 extern int ns_image_height (void *img);
1197 extern unsigned long ns_get_pixel (void *img, int x, int y);
1198 extern void ns_put_pixel (void *img, int x, int y, unsigned long argb);
1199 extern void ns_set_alpha (void *img, int x, int y, unsigned char a);
1201 extern int x_display_pixel_height (struct ns_display_info *);
1202 extern int x_display_pixel_width (struct ns_display_info *);
1204 /* This in nsterm.m */
1205 extern float ns_antialias_threshold;
1206 extern void x_destroy_window (struct frame *f);
1207 extern void x_set_undecorated (struct frame *f, Lisp_Object new_value,
1208 Lisp_Object old_value);
1209 extern void x_set_parent_frame (struct frame *f, Lisp_Object new_value,
1210 Lisp_Object old_value);
1211 extern void x_set_no_focus_on_map (struct frame *f, Lisp_Object new_value,
1212 Lisp_Object old_value);
1213 extern void x_set_no_accept_focus (struct frame *f, Lisp_Object new_value,
1214 Lisp_Object old_value);
1215 extern void x_set_z_group (struct frame *f, Lisp_Object new_value,
1216 Lisp_Object old_value);
1217 #ifdef NS_IMPL_COCOA
1218 extern void ns_set_appearance (struct frame *f, Lisp_Object new_value,
1219 Lisp_Object old_value);
1220 extern void ns_set_transparent_titlebar (struct frame *f,
1221 Lisp_Object new_value,
1222 Lisp_Object old_value);
1223 #endif
1224 extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds,
1225 fd_set *exceptfds, struct timespec *timeout,
1226 sigset_t *sigmask);
1227 #ifdef HAVE_PTHREAD
1228 extern void ns_run_loop_break (void);
1229 #endif
1230 extern unsigned long ns_get_rgb_color (struct frame *f,
1231 float r, float g, float b, float a);
1233 struct input_event;
1234 extern void ns_init_events (struct input_event *);
1235 extern void ns_finish_events (void);
1237 #ifdef __OBJC__
1238 /* Needed in nsfns.m. */
1239 extern void
1240 ns_set_represented_filename (struct frame *f);
1242 #endif
1244 #ifdef NS_IMPL_GNUSTEP
1245 extern char gnustep_base_version[]; /* version tracking */
1246 #endif
1248 #define MINWIDTH 10
1249 #define MINHEIGHT 10
1251 /* Screen max coordinate
1252 Using larger coordinates causes movewindow/placewindow to abort */
1253 #define SCREENMAX 16000
1255 #define NS_SCROLL_BAR_WIDTH_DEFAULT [EmacsScroller scrollerWidth]
1256 #define NS_SCROLL_BAR_HEIGHT_DEFAULT [EmacsScroller scrollerHeight]
1257 /* This is to match emacs on other platforms, ugly though it is. */
1258 #define NS_SELECTION_BG_COLOR_DEFAULT @"LightGoldenrod2";
1259 #define NS_SELECTION_FG_COLOR_DEFAULT @"Black";
1260 #define RESIZE_HANDLE_SIZE 12
1262 /* Little utility macros */
1263 #define IN_BOUND(min, x, max) (((x) < (min)) \
1264 ? (min) : (((x)>(max)) ? (max) : (x)))
1265 #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
1267 /* macOS 10.7 introduces some new constants. */
1268 #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_7)
1269 #define NSFullScreenWindowMask (1 << 14)
1270 #define NSWindowCollectionBehaviorFullScreenPrimary (1 << 7)
1271 #define NSApplicationPresentationFullScreen (1 << 10)
1272 #define NSApplicationPresentationAutoHideToolbar (1 << 11)
1273 #define NSAppKitVersionNumber10_7 1138
1274 #endif /* !defined (MAC_OS_X_VERSION_10_7) */
1276 /* macOS 10.12 deprecates a bunch of constants. */
1277 #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_12)
1278 #define NSEventModifierFlagCommand NSCommandKeyMask
1279 #define NSEventModifierFlagControl NSControlKeyMask
1280 #define NSEventModifierFlagHelp NSHelpKeyMask
1281 #define NSEventModifierFlagNumericPad NSNumericPadKeyMask
1282 #define NSEventModifierFlagOption NSAlternateKeyMask
1283 #define NSEventModifierFlagShift NSShiftKeyMask
1284 #define NSCompositingOperationSourceOver NSCompositeSourceOver
1285 #define NSEventMaskApplicationDefined NSApplicationDefinedMask
1286 #define NSEventTypeApplicationDefined NSApplicationDefined
1287 #define NSEventTypeCursorUpdate NSCursorUpdate
1288 #define NSEventTypeMouseMoved NSMouseMoved
1289 #define NSEventTypeLeftMouseDown NSLeftMouseDown
1290 #define NSEventTypeRightMouseDown NSRightMouseDown
1291 #define NSEventTypeOtherMouseDown NSOtherMouseDown
1292 #define NSEventTypeLeftMouseUp NSLeftMouseUp
1293 #define NSEventTypeRightMouseUp NSRightMouseUp
1294 #define NSEventTypeOtherMouseUp NSOtherMouseUp
1295 #define NSEventTypeLeftMouseDragged NSLeftMouseDragged
1296 #define NSEventTypeRightMouseDragged NSRightMouseDragged
1297 #define NSEventTypeOtherMouseDragged NSOtherMouseDragged
1298 #define NSEventTypeScrollWheel NSScrollWheel
1299 #define NSEventTypeKeyDown NSKeyDown
1300 #define NSEventTypeKeyUp NSKeyUp
1301 #define NSEventTypeFlagsChanged NSFlagsChanged
1302 #define NSEventMaskAny NSAnyEventMask
1303 #define NSEventTypeSystemDefined NSSystemDefined
1304 #define NSWindowStyleMaskBorderless NSBorderlessWindowMask
1305 #define NSWindowStyleMaskClosable NSClosableWindowMask
1306 #define NSWindowStyleMaskFullScreen NSFullScreenWindowMask
1307 #define NSWindowStyleMaskMiniaturizable NSMiniaturizableWindowMask
1308 #define NSWindowStyleMaskResizable NSResizableWindowMask
1309 #define NSWindowStyleMaskTitled NSTitledWindowMask
1310 #define NSWindowStyleMaskUtilityWindow NSUtilityWindowMask
1311 #define NSAlertStyleCritical NSCriticalAlertStyle
1312 #define NSControlSizeRegular NSRegularControlSize
1313 #define NSCompositingOperationCopy NSCompositeCopy
1315 /* And adds NSWindowStyleMask. */
1316 #ifdef __OBJC__
1317 typedef NSUInteger NSWindowStyleMask;
1318 #endif
1320 /* Window tabbing mode enums are new too. */
1321 enum NSWindowTabbingMode
1323 NSWindowTabbingModeAutomatic,
1324 NSWindowTabbingModePreferred,
1325 NSWindowTabbingModeDisallowed
1327 #endif /* !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_12) */
1329 #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_13)
1330 /* Deprecated in macOS 10.13. */
1331 #define NSPasteboardNameGeneral NSGeneralPboard
1332 #endif
1333 #endif /* HAVE_NS */