custom-buffer-style doc fix
[emacs.git] / src / nsterm.h
blob0aea9cca112e92638bb3f46167583f661bc703a7
1 /* Definitions and headers for communication with NeXT/Open/GNUstep API.
2 Copyright (C) 1989, 1993, 2005, 2008-2016 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 <http://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
29 #ifdef NS_IMPL_COCOA
30 #ifndef MAC_OS_X_VERSION_10_6
31 #define MAC_OS_X_VERSION_10_6 1060
32 #endif
33 #ifndef MAC_OS_X_VERSION_10_7
34 #define MAC_OS_X_VERSION_10_7 1070
35 #endif
36 #ifndef MAC_OS_X_VERSION_10_8
37 #define MAC_OS_X_VERSION_10_8 1080
38 #endif
39 #ifndef MAC_OS_X_VERSION_10_9
40 #define MAC_OS_X_VERSION_10_9 1090
41 #endif
43 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
44 #define HAVE_NATIVE_FS
45 #endif
47 #endif /* NS_IMPL_COCOA */
49 #ifdef __OBJC__
51 /* CGFloat on GNUstep may be 4 or 8 byte, but functions expect float* for some
52 versions.
53 On Cocoa >= 10.5, functions expect CGFloat*. Make compatible type. */
54 #ifdef NS_IMPL_COCOA
55 typedef CGFloat EmacsCGFloat;
56 #elif GNUSTEP_GUI_MAJOR_VERSION > 0 || GNUSTEP_GUI_MINOR_VERSION >= 22
57 typedef CGFloat EmacsCGFloat;
58 #else
59 typedef float EmacsCGFloat;
60 #endif
62 /* ==========================================================================
64 Trace support
66 ========================================================================== */
68 /* Uncomment the following line to enable trace.
70 Uncomment suitable NSTRACE_GROUP_xxx lines to trace more.
72 Hint: keep the trailing whitespace -- the version control system
73 will reject accidental commits. */
75 /* #define NSTRACE_ENABLED 1 */
78 /* When non-zero, trace output is enabled for all parts, except those
79 explicitly disabled. */
80 /* #define NSTRACE_ALL_GROUPS 1 */
82 /* When non-zero, trace output is enabled in the corresponding part. */
83 /* #define NSTRACE_GROUP_EVENTS 1 */
84 /* #define NSTRACE_GROUP_UPDATES 1 */
85 /* #define NSTRACE_GROUP_FRINGE 1 */
86 /* #define NSTRACE_GROUP_COLOR 1 */
87 /* #define NSTRACE_GROUP_GLYPHS 1 */
88 /* #define NSTRACE_GROUP_FOCUS 1 */
91 /* Print a call tree containing all annotated functions.
93 The call structure of the functions is represented using
94 indentation and vertical lines. Extra information is printed using
95 horizontal lines that connect to the vertical line.
97 The return value is represented using the arrow "->>". For simple
98 functions, the arrow can be printed on the same line as the
99 function name. If more output is printed, it is connected to the
100 vertical line of the function.
102 The first column contains the file name, the second the line
103 number, and the third a number increasing for each trace line.
105 Note, when trace output from several threads are mixed, the output
106 can become misaligned, as all threads (currently) share one state.
107 This is post prominent when the EVENTS part is enabled.
109 Note that the trace system, when enabled, use the GCC/Clang
110 "cleanup" extension. */
112 /* For example, the following is the output of `M-x
113 toggle-frame-maximized RET'.
115 (Long lines manually split to reduced width):
117 nsterm.m : 1608: [ 354] ns_fullscreen_hook
118 nsterm.m : 7180: [ 355] | [EmacsView handleFS]
119 nsterm.m : 7209: [ 356] | +--- FULLSCREEN_MAXIMIZED
120 nsterm.m : 7706: [ 357] | | [EmacsWindow performZoom:]
121 nsterm.m : 7715: [ 358] | | | [EmacsWindow zoom:]
122 nsterm.m : 882: [ 359] | | | | ns_update_auto_hide_menu_bar
123 nsterm.m : 6752: [ 360] | | | |
124 [EmacsView windowWillUseStandardFrame:defaultFrame:(X:0 Y:0)/(W:1600 H:1177)]
125 nsterm.m : 6753: [ 361] | | | | +--- fs_state: FULLSCREEN_NONE
126 nsterm.m : 6754: [ 362] | | | | +--- fs_before_fs: -1
127 nsterm.m : 6755: [ 363] | | | | +--- next_maximized: FULLSCREEN_MAXIMIZED
128 nsterm.m : 6756: [ 364] | | | | +--- ns_userRect: (X:0 Y:0)/(W:0 H:0)
129 nsterm.m : 6757: [ 365] | | | | +---
130 [sender frame]: (X:0 Y:626)/(W:595 H:551)
131 nsterm.m : 6781: [ 366] | | | | +---
132 ns_userRect (2): (X:0 Y:626)/(W:595 H:551)
133 nsterm.m : 6821: [ 367] | | | | +--- FULLSCREEN_MAXIMIZED
134 nsterm.m : 7232: [ 368] | | | | |
135 [EmacsView setFSValue:FULLSCREEN_MAXIMIZED]
136 nsterm.m : 6848: [ 369] | | | | +---
137 Final ns_userRect: (X:0 Y:626)/(W:595 H:551)
138 nsterm.m : 6849: [ 370] | | | | +--- Final maximized_width: 1600
139 nsterm.m : 6850: [ 371] | | | | +--- Final maximized_height: 1177
140 nsterm.m : 6851: [ 372] | | | | +--- Final next_maximized: -1
141 nsterm.m : 6322: [ 373] | | | | |
142 [EmacsView windowWillResize:toSize: (W:1600 H:1177)]
143 nsterm.m : 6323: [ 374] | | | | | +---
144 [sender frame]: (X:0 Y:626)/(W:595 H:551)
145 nsterm.m : 6324: [ 375] | | | | | +--- fs_state: FULLSCREEN_MAXIMIZED
146 nsterm.m : 7027: [ 376] | | | | | | [EmacsView isFullscreen]
147 nsterm.m : 6387: [ 377] | | | | | +--- cols: 223 rows: 79
148 nsterm.m : 6412: [ 378] | | | | | +->> (W:1596 H:1167)
149 nsterm.m : 6855: [ 379] | | | | +->> (X:0 Y:0)/(W:1600 H:1177)
152 #ifndef NSTRACE_ENABLED
153 #define NSTRACE_ENABLED 0
154 #endif
156 #if NSTRACE_ENABLED
158 #ifndef NSTRACE_ALL_GROUPS
159 #define NSTRACE_ALL_GROUPS 0
160 #endif
162 #ifndef NSTRACE_GROUP_EVENTS
163 #define NSTRACE_GROUP_EVENTS NSTRACE_ALL_GROUPS
164 #endif
166 #ifndef NSTRACE_GROUP_UPDATES
167 #define NSTRACE_GROUP_UPDATES NSTRACE_ALL_GROUPS
168 #endif
170 #ifndef NSTRACE_GROUP_FRINGE
171 #define NSTRACE_GROUP_FRINGE NSTRACE_ALL_GROUPS
172 #endif
174 #ifndef NSTRACE_GROUP_COLOR
175 #define NSTRACE_GROUP_COLOR NSTRACE_ALL_GROUPS
176 #endif
178 #ifndef NSTRACE_GROUP_GLYPHS
179 #define NSTRACE_GROUP_GLYPHS NSTRACE_ALL_GROUPS
180 #endif
182 #ifndef NSTRACE_GROUP_FOCUS
183 #define NSTRACE_GROUP_FOCUS NSTRACE_ALL_GROUPS
184 #endif
186 extern volatile int nstrace_num;
187 extern volatile int nstrace_depth;
188 extern volatile int nstrace_enabled_global;
190 void nstrace_leave(int *);
191 void nstrace_restore_global_trace_state(int *);
192 char const * nstrace_fullscreen_type_name (int);
194 /* printf-style trace output. Output is aligned with contained heading. */
195 #define NSTRACE_MSG_NO_DASHES(...) \
196 do \
198 if (nstrace_enabled) \
200 fprintf (stderr, "%-10s:%5d: [%5d]%.*s", \
201 __FILE__, __LINE__, nstrace_num++, \
202 2*nstrace_depth, " | | | | | | | | | | | | | | | .."); \
203 fprintf (stderr, __VA_ARGS__); \
204 fprintf (stderr, "\n"); \
207 while(0)
209 #define NSTRACE_MSG(...) NSTRACE_MSG_NO_DASHES("+--- " __VA_ARGS__)
213 /* Macros for printing complex types.
215 NSTRACE_FMT_what -- Printf format string for "what".
216 NSTRACE_ARG_what(x) -- Printf argument for "what". */
218 #define NSTRACE_FMT_SIZE "(W:%.0f H:%.0f)"
219 #define NSTRACE_ARG_SIZE(elt) (elt).width, (elt).height
221 #define NSTRACE_FMT_POINT "(X:%.0f Y:%.0f)"
222 #define NSTRACE_ARG_POINT(elt) (elt).x, (elt).y
224 #define NSTRACE_FMT_RECT NSTRACE_FMT_POINT "/" NSTRACE_FMT_SIZE
225 #define NSTRACE_ARG_RECT(elt) \
226 NSTRACE_ARG_POINT((elt).origin), NSTRACE_ARG_SIZE((elt).size)
228 #define NSTRACE_FMT_FSTYPE "%s"
229 #define NSTRACE_ARG_FSTYPE(elt) nstrace_fullscreen_type_name(elt)
232 /* Macros for printing complex types as extra information. */
234 #define NSTRACE_SIZE(str,size) \
235 NSTRACE_MSG (str ": " NSTRACE_FMT_SIZE, \
236 NSTRACE_ARG_SIZE (size));
238 #define NSTRACE_POINT(str,point) \
239 NSTRACE_MSG (str ": " NSTRACE_FMT_POINT, \
240 NSTRACE_ARG_POINT (point));
242 #define NSTRACE_RECT(str,rect) \
243 NSTRACE_MSG (str ": " NSTRACE_FMT_RECT, \
244 NSTRACE_ARG_RECT (rect));
246 #define NSTRACE_FSTYPE(str,fs_type) \
247 NSTRACE_MSG (str ": " NSTRACE_FMT_FSTYPE, \
248 NSTRACE_ARG_FSTYPE (fs_type));
251 /* Return value macros.
253 NSTRACE_RETURN(fmt, ...) - Print a return value, support printf-style
254 format string and arguments.
256 NSTRACE_RETURN_what(obj) - Print a return value of kind WHAT.
258 NSTRACE_FMT_RETURN - A string literal representing a returned
259 value. Useful when creating a format string
260 to printf-like constructs like NSTRACE(). */
262 #define NSTRACE_FMT_RETURN "->>"
264 #define NSTRACE_RETURN(...) \
265 NSTRACE_MSG_NO_DASHES ("+" NSTRACE_FMT_RETURN " " __VA_ARGS__)
267 #define NSTRACE_RETURN_SIZE(size) \
268 NSTRACE_RETURN(NSTRACE_FMT_SIZE, NSTRACE_ARG_SIZE(size))
270 #define NSTRACE_RETURN_POINT(point) \
271 NSTRACE_RETURN(NSTRACE_FMT_POINT, NSTRACE_ARG_POINT(point))
273 #define NSTRACE_RETURN_RECT(rect) \
274 NSTRACE_RETURN(NSTRACE_FMT_RECT, NSTRACE_ARG_RECT(rect))
277 /* Function enter macros.
279 NSTRACE (fmt, ...) -- Enable trace output in current block
280 (typically a function). Accepts printf-style
281 arguments.
283 NSTRACE_WHEN (cond, fmt, ...) -- Enable trace output when COND is true.
285 NSTRACE_UNLESS (cond, fmt, ...) -- Enable trace output unless COND is
286 true. */
290 #define NSTRACE_WHEN(cond, ...) \
291 __attribute__((cleanup(nstrace_restore_global_trace_state))) \
292 int nstrace_saved_enabled_global = nstrace_enabled_global; \
293 __attribute__((cleanup(nstrace_leave))) \
294 int nstrace_enabled = nstrace_enabled_global && (cond); \
295 if (nstrace_enabled) { ++nstrace_depth; } \
296 else { nstrace_enabled_global = 0; } \
297 NSTRACE_MSG_NO_DASHES(__VA_ARGS__);
299 /* Unsilence called functions.
301 Concretely, this us used to allow "event" functions to be silenced
302 while trace output can be printed for functions they call. */
303 #define NSTRACE_UNSILENCE() do { nstrace_enabled_global = 1; } while(0)
305 #endif /* NSTRACE_ENABLED */
307 #define NSTRACE(...) NSTRACE_WHEN(1, __VA_ARGS__)
308 #define NSTRACE_UNLESS(cond, ...) NSTRACE_WHEN(!(cond), __VA_ARGS__)
310 /* Non-trace replacement versions. */
311 #ifndef NSTRACE_WHEN
312 #define NSTRACE_WHEN(...)
313 #endif
315 #ifndef NSTRACE_MSG
316 #define NSTRACE_MSG(...)
317 #endif
319 #ifndef NSTRACE_SIZE
320 #define NSTRACE_SIZE(str,size)
321 #endif
323 #ifndef NSTRACE_POINT
324 #define NSTRACE_POINT(str,point)
325 #endif
327 #ifndef NSTRACE_RECT
328 #define NSTRACE_RECT(str,rect)
329 #endif
331 #ifndef NSTRACE_FSTYPE
332 #define NSTRACE_FSTYPE(str,fs_type)
333 #endif
335 #ifndef NSTRACE_RETURN_SIZE
336 #define NSTRACE_RETURN_SIZE(size)
337 #endif
339 #ifndef NSTRACE_RETURN_POINT
340 #define NSTRACE_RETURN_POINT(point)
341 #endif
343 #ifndef NSTRACE_RETURN_RECT
344 #define NSTRACE_RETURN_RECT(rect)
345 #endif
347 #ifndef NSTRACE_RETURN_FSTYPE
348 #define NSTRACE_RETURN_FSTYPE(fs_type)
349 #endif
351 #ifndef NSTRACE_UNSILENCE
352 #define NSTRACE_UNSILENCE()
353 #endif
356 /* ==========================================================================
358 NSColor, EmacsColor category.
360 ========================================================================== */
361 @interface NSColor (EmacsColor)
362 + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
363 blue:(CGFloat)blue alpha:(CGFloat)alpha;
364 - (NSColor *)colorUsingDefaultColorSpace;
366 @end
368 /* ==========================================================================
370 The Emacs application
372 ========================================================================== */
374 /* We override sendEvent: as a means to stop/start the event loop */
375 @interface EmacsApp : NSApplication
377 #ifdef NS_IMPL_COCOA
378 BOOL shouldKeepRunning;
379 BOOL isFirst;
380 #endif
381 #ifdef NS_IMPL_GNUSTEP
382 BOOL applicationDidFinishLaunchingCalled;
383 @public
384 int nextappdefined;
385 #endif
387 - (void)logNotification: (NSNotification *)notification;
388 - (void)antialiasThresholdDidChange:(NSNotification *)notification;
389 - (void)sendEvent: (NSEvent *)theEvent;
390 - (void)showPreferencesWindow: (id)sender;
391 - (BOOL) openFile: (NSString *)fileName;
392 - (void)fd_handler: (id)unused;
393 - (void)timeout_handler: (NSTimer *)timedEntry;
394 - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg;
395 #ifdef NS_IMPL_GNUSTEP
396 - (void)sendFromMainThread:(id)unused;
397 #endif
398 @end
400 #ifdef NS_IMPL_GNUSTEP
401 /* Dummy class to get rid of startup warnings. */
402 @interface EmacsDocument : NSDocument
405 @end
406 #endif
408 /* ==========================================================================
410 The main Emacs view
412 ========================================================================== */
414 @class EmacsToolbar;
416 #ifdef NS_IMPL_COCOA
417 @interface EmacsView : NSView <NSTextInput, NSWindowDelegate>
418 #else
419 @interface EmacsView : NSView <NSTextInput>
420 #endif
422 #ifdef NS_IMPL_COCOA
423 char *old_title;
424 BOOL maximizing_resize;
425 #endif
426 BOOL windowClosing;
427 NSString *workingText;
428 BOOL processingCompose;
429 int fs_state, fs_before_fs, next_maximized;
430 int tibar_height, tobar_height, bwidth;
431 int maximized_width, maximized_height;
432 NSWindow *nonfs_window;
433 BOOL fs_is_native;
434 @public
435 struct frame *emacsframe;
436 int rows, cols;
437 int scrollbarsNeedingUpdate;
438 EmacsToolbar *toolbar;
439 NSRect ns_userRect;
440 BOOL wait_for_tool_bar;
443 /* AppKit-side interface */
444 - menuDown: (id)sender;
445 - toolbarClicked: (id)item;
446 - toggleToolbar: (id)sender;
447 - (void)keyDown: (NSEvent *)theEvent;
448 - (void)mouseDown: (NSEvent *)theEvent;
449 - (void)mouseUp: (NSEvent *)theEvent;
450 - setMiniwindowImage: (BOOL)setMini;
452 /* Emacs-side interface */
453 - initFrameFromEmacs: (struct frame *) f;
454 - (void) setRows: (int) r andColumns: (int) c;
455 - (void) setWindowClosing: (BOOL)closing;
456 - (EmacsToolbar *) toolbar;
457 - (void) deleteWorkingText;
458 - (void) updateFrameSize: (BOOL) delay;
459 - (void) handleFS;
460 - (void) setFSValue: (int)value;
461 - (void) toggleFullScreen: (id) sender;
462 - (BOOL) fsIsNative;
463 - (BOOL) isFullscreen;
464 #ifdef HAVE_NATIVE_FS
465 - (void) updateCollectionBehavior;
466 #endif
468 #ifdef NS_IMPL_GNUSTEP
469 - (void)windowDidMove: (id)sender;
470 #endif
471 - (int)fullscreenState;
473 /* Non-notification versions of NSView methods. Used for direct calls. */
474 - (void)windowWillEnterFullScreen;
475 - (void)windowDidEnterFullScreen;
476 - (void)windowWillExitFullScreen;
477 - (void)windowDidExitFullScreen;
478 - (void)windowDidBecomeKey;
479 @end
482 /* Small utility used for processing resize events under Cocoa. */
483 @interface EmacsWindow : NSWindow
485 NSPoint grabOffset;
487 @end
490 /* Fullscreen version of the above. */
491 @interface EmacsFSWindow : EmacsWindow
494 @end
496 /* ==========================================================================
498 The main menu implementation
500 ========================================================================== */
502 #ifdef NS_IMPL_COCOA
503 @interface EmacsMenu : NSMenu <NSMenuDelegate>
504 #else
505 @interface EmacsMenu : NSMenu
506 #endif
508 struct frame *frame;
509 unsigned long keyEquivModMask;
512 - initWithTitle: (NSString *)title frame: (struct frame *)f;
513 - (void)setFrame: (struct frame *)f;
514 - (void)menuNeedsUpdate: (NSMenu *)menu; /* (delegate method) */
515 - (NSString *)parseKeyEquiv: (const char *)key;
516 - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr;
517 - (void)fillWithWidgetValue: (void *)wvptr;
518 - (void)fillWithWidgetValue: (void *)wvptr frame: (struct frame *)f;
519 - (EmacsMenu *)addSubmenuWithTitle: (const char *)title forFrame: (struct frame *)f;
520 - (void) clear;
521 - (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f
522 keymaps: (bool)keymaps;
523 @end
526 /* ==========================================================================
528 Toolbar
530 ========================================================================== */
532 @class EmacsImage;
534 #ifdef NS_IMPL_COCOA
535 @interface EmacsToolbar : NSToolbar <NSToolbarDelegate>
536 #else
537 @interface EmacsToolbar : NSToolbar
538 #endif
540 EmacsView *emacsView;
541 NSMutableDictionary *identifierToItem;
542 NSMutableArray *activeIdentifiers;
543 NSArray *prevIdentifiers;
544 unsigned long enablement, prevEnablement;
546 - initForView: (EmacsView *)view withIdentifier: (NSString *)identifier;
547 - (void) clearActive;
548 - (void) clearAll;
549 - (BOOL) changed;
550 - (void) addDisplayItemWithImage: (EmacsImage *)img
551 idx: (int)idx
552 tag: (int)tag
553 helpText: (const char *)help
554 enabled: (BOOL)enabled;
556 /* delegate methods */
557 - (NSToolbarItem *)toolbar: (NSToolbar *)toolbar
558 itemForItemIdentifier: (NSString *)itemIdentifier
559 willBeInsertedIntoToolbar: (BOOL)flag;
560 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar;
561 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar;
562 @end
565 /* ==========================================================================
567 Message / question windows
569 ========================================================================== */
571 @interface EmacsDialogPanel : NSPanel
573 NSTextField *command;
574 NSTextField *title;
575 NSMatrix *matrix;
576 int rows, cols;
577 BOOL timer_fired, window_closed;
578 Lisp_Object dialog_return;
579 Lisp_Object *button_values;
581 - initFromContents: (Lisp_Object)menu isQuestion: (BOOL)isQ;
582 - (void)process_dialog: (Lisp_Object)list;
583 - (void)addButton: (char *)str value: (int)tag row: (int)row;
584 - (void)addString: (char *)str row: (int)row;
585 - (void)addSplit;
586 - (Lisp_Object)runDialogAt: (NSPoint)p;
587 - (void)timeout_handler: (NSTimer *)timedEntry;
588 @end
590 #ifdef NS_IMPL_COCOA
591 @interface EmacsTooltip : NSObject <NSWindowDelegate>
592 #else
593 @interface EmacsTooltip : NSObject
594 #endif
596 NSWindow *win;
597 NSTextField *textField;
598 NSTimer *timer;
600 - init;
601 - (void) setText: (char *)text;
602 - (void) showAtX: (int)x Y: (int)y for: (int)seconds;
603 - (void) hide;
604 - (BOOL) isActive;
605 - (NSRect) frame;
606 @end
609 /* ==========================================================================
611 File open/save panels
612 This and next override methods to handle keyboard input in panels.
614 ========================================================================== */
616 @interface EmacsSavePanel : NSSavePanel
619 @end
620 @interface EmacsOpenPanel : NSOpenPanel
623 @end
625 @interface EmacsFileDelegate : NSObject
628 - (BOOL)panel: (id)sender isValidFilename: (NSString *)filename;
629 - (BOOL)panel: (id)sender shouldShowFilename: (NSString *)filename;
630 - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
631 confirmed: (BOOL)okFlag;
632 @end
635 /* ==========================================================================
637 Images and stippling
639 ========================================================================== */
641 @interface EmacsImage : NSImage
643 NSBitmapImageRep *bmRep; /* used for accessing pixel data */
644 unsigned char *pixmapData[5]; /* shortcut to access pixel data */
645 NSColor *stippleMask;
646 unsigned long xbm_fg;
648 + allocInitFromFile: (Lisp_Object)file;
649 - (void)dealloc;
650 - initFromXBM: (unsigned char *)bits width: (int)w height: (int)h
651 fg: (unsigned long)fg bg: (unsigned long)bg;
652 - setXBMColor: (NSColor *)color;
653 - initForXPMWithDepth: (int)depth width: (int)width height: (int)height;
654 - (void)setPixmapData;
655 - (unsigned long)getPixelAtX: (int)x Y: (int)y;
656 - (void)setPixelAtX: (int)x Y: (int)y toRed: (unsigned char)r
657 green: (unsigned char)g blue: (unsigned char)b
658 alpha:(unsigned char)a;
659 - (void)setAlphaAtX: (int)x Y: (int)y to: (unsigned char)a;
660 - (NSColor *)stippleMask;
661 @end
664 /* ==========================================================================
666 Scrollbars
668 ========================================================================== */
670 @interface EmacsScroller : NSScroller
672 struct window *window;
673 struct frame *frame;
674 NSResponder *prevResponder;
676 /* offset to the bottom of knob of last mouse down */
677 CGFloat last_mouse_offset;
678 float min_portion;
679 int pixel_height;
680 enum scroll_bar_part last_hit_part;
682 BOOL condemned;
684 /* optimize against excessive positioning calls generated by emacs */
685 int em_position;
686 int em_portion;
687 int em_whole;
690 - initFrame: (NSRect )r window: (Lisp_Object)win;
691 - (void)setFrame: (NSRect)r;
693 - setPosition: (int) position portion: (int) portion whole: (int) whole;
694 - (int) checkSamePosition: (int)position portion: (int)portion
695 whole: (int)whole;
696 - (void) sendScrollEventAtLoc: (float)loc fromEvent: (NSEvent *)e;
697 - repeatScroll: (NSTimer *)sender;
698 - condemn;
699 - reprieve;
700 - (bool)judge;
701 + (CGFloat)scrollerWidth;
702 @end
705 /* ==========================================================================
707 Rendering
709 ========================================================================== */
711 #ifdef NS_IMPL_COCOA
712 /* rendering util */
713 @interface EmacsGlyphStorage : NSObject <NSGlyphStorage>
715 @public
716 NSAttributedString *attrStr;
717 NSMutableDictionary *dict;
718 CGGlyph *cglyphs;
719 unsigned long maxChar, maxGlyph;
720 long i, len;
722 - initWithCapacity: (unsigned long) c;
723 - (void) setString: (NSString *)str font: (NSFont *)font;
724 @end
725 #endif /* NS_IMPL_COCOA */
727 extern NSArray *ns_send_types, *ns_return_types;
728 extern NSString *ns_app_name;
729 extern EmacsMenu *mainMenu, *svcsMenu, *dockMenu;
731 /* Apple removed the declaration, but kept the implementation */
732 #if defined (NS_IMPL_COCOA)
733 @interface NSApplication (EmacsApp)
734 - (void)setAppleMenu: (NSMenu *)menu;
735 @end
736 #endif
738 #endif /* __OBJC__ */
742 /* ==========================================================================
744 Non-OO stuff
746 ========================================================================== */
748 /* Special keycodes that we pass down the event chain */
749 #define KEY_NS_POWER_OFF ((1<<28)|(0<<16)|1)
750 #define KEY_NS_OPEN_FILE ((1<<28)|(0<<16)|2)
751 #define KEY_NS_OPEN_TEMP_FILE ((1<<28)|(0<<16)|3)
752 #define KEY_NS_CHANGE_FONT ((1<<28)|(0<<16)|7)
753 #define KEY_NS_OPEN_FILE_LINE ((1<<28)|(0<<16)|8)
754 #define KEY_NS_PUT_WORKING_TEXT ((1<<28)|(0<<16)|9)
755 #define KEY_NS_UNPUT_WORKING_TEXT ((1<<28)|(0<<16)|10)
756 #define KEY_NS_SPI_SERVICE_CALL ((1<<28)|(0<<16)|11)
757 #define KEY_NS_NEW_FRAME ((1<<28)|(0<<16)|12)
758 #define KEY_NS_TOGGLE_TOOLBAR ((1<<28)|(0<<16)|13)
759 #define KEY_NS_SHOW_PREFS ((1<<28)|(0<<16)|14)
761 /* could use list to store these, but rest of emacs has a big infrastructure
762 for managing a table of bitmap "records" */
763 struct ns_bitmap_record
765 #ifdef __OBJC__
766 EmacsImage *img;
767 #else
768 void *img;
769 #endif
770 char *file;
771 int refcount;
772 int height, width, depth;
775 /* this to map between emacs color indices and NSColor objects */
776 struct ns_color_table
778 ptrdiff_t size;
779 ptrdiff_t avail;
780 #ifdef __OBJC__
781 NSColor **colors;
782 NSMutableSet *empty_indices;
783 #else
784 void **items;
785 void *availIndices;
786 #endif
788 #define NS_COLOR_CAPACITY 256
790 #define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
791 #define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
793 #define ALPHA_FROM_ULONG(color) ((color) >> 24)
794 #define RED_FROM_ULONG(color) (((color) >> 16) & 0xff)
795 #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
796 #define BLUE_FROM_ULONG(color) ((color) & 0xff)
798 /* Do not change `* 0x101' in the following lines to `<< 8'. If
799 changed, image masks in 1-bit depth will not work. */
800 #define RED16_FROM_ULONG(color) (RED_FROM_ULONG(color) * 0x101)
801 #define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
802 #define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)
804 /* this extends font backend font */
805 struct nsfont_info
807 struct font font;
809 char *name; /* PostScript name, uniquely identifies on NS systems */
811 /* The following metrics are stored as float rather than int. */
813 float width; /* Maximum advance for the font. */
814 float height;
815 float underpos;
816 float underwidth;
817 float size;
818 #ifdef __OBJC__
819 NSFont *nsfont;
820 #if defined (NS_IMPL_COCOA)
821 CGFontRef cgfont;
822 #else /* GNUstep */
823 void *cgfont;
824 #endif
825 #else /* ! OBJC */
826 void *nsfont;
827 void *cgfont;
828 #endif
829 char bold, ital; /* convenience flags */
830 char synthItal;
831 XCharStruct max_bounds;
832 /* we compute glyph codes and metrics on-demand in blocks of 256 indexed
833 by hibyte, lobyte */
834 unsigned short **glyphs; /* map Unicode index to glyph */
835 struct font_metrics **metrics;
839 /* init'd in ns_initialize_display_info () */
840 struct ns_display_info
842 /* Chain of all ns_display_info structures. */
843 struct ns_display_info *next;
845 /* The generic display parameters corresponding to this NS display. */
846 struct terminal *terminal;
848 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
849 Lisp_Object name_list_element;
851 /* The number of fonts loaded. */
852 int n_fonts;
854 /* Minimum width over all characters in all fonts in font_table. */
855 int smallest_char_width;
857 /* Minimum font height over all fonts in font_table. */
858 int smallest_font_height;
860 struct ns_bitmap_record *bitmaps;
861 ptrdiff_t bitmaps_size;
862 ptrdiff_t bitmaps_last;
864 struct ns_color_table *color_table;
866 /* DPI resolution of this screen */
867 double resx, resy;
869 /* Mask of things that cause the mouse to be grabbed */
870 int grabbed;
872 int n_planes;
874 int color_p;
876 Window root_window;
878 /* Xism */
879 XrmDatabase xrdb;
881 /* The cursor to use for vertical scroll bars. */
882 Cursor vertical_scroll_bar_cursor;
884 /* The cursor to use for horizontal scroll bars. */
885 Cursor horizontal_scroll_bar_cursor;
887 /* Information about the range of text currently shown in
888 mouse-face. */
889 Mouse_HLInfo mouse_highlight;
891 struct frame *x_highlight_frame;
892 struct frame *x_focus_frame;
894 /* The frame where the mouse was last time we reported a mouse event. */
895 struct frame *last_mouse_frame;
897 /* The frame where the mouse was last time we reported a mouse motion. */
898 struct frame *last_mouse_motion_frame;
900 /* Position where the mouse was last time we reported a motion.
901 This is a position on last_mouse_motion_frame. */
902 int last_mouse_motion_x;
903 int last_mouse_motion_y;
905 /* Where the mouse was last time we reported a mouse position. */
906 NSRect last_mouse_glyph;
908 /* Time of last mouse movement. */
909 Time last_mouse_movement_time;
911 /* The scroll bar in which the last motion event occurred. */
912 #ifdef __OBJC__
913 EmacsScroller *last_mouse_scroll_bar;
914 #else
915 void *last_mouse_scroll_bar;
916 #endif
919 /* This is a chain of structures for all the NS displays currently in use. */
920 extern struct ns_display_info *x_display_list;
922 extern struct ns_display_info *ns_display_info_for_name (Lisp_Object name);
924 struct ns_output
926 #ifdef __OBJC__
927 EmacsView *view;
928 id miniimage;
929 NSColor *cursor_color;
930 NSColor *foreground_color;
931 NSColor *background_color;
932 EmacsToolbar *toolbar;
933 #else
934 void *view;
935 void *miniimage;
936 void *cursor_color;
937 void *foreground_color;
938 void *background_color;
939 void *toolbar;
940 #endif
942 /* NSCursors init'ed in initFrameFromEmacs */
943 Cursor text_cursor;
944 Cursor nontext_cursor;
945 Cursor modeline_cursor;
946 Cursor hand_cursor;
947 Cursor hourglass_cursor;
948 Cursor horizontal_drag_cursor;
949 Cursor vertical_drag_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)
1012 #define FRAME_NS_TITLEBAR_HEIGHT(f) ((f)->output_data.ns->titlebar_height)
1013 #define FRAME_TOOLBAR_HEIGHT(f) ((f)->output_data.ns->toolbar_height)
1015 #define FRAME_DEFAULT_FACE(f) FACE_FROM_ID (f, DEFAULT_FACE_ID)
1017 #define FRAME_NS_VIEW(f) ((f)->output_data.ns->view)
1018 #define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
1019 #define FRAME_POINTER_TYPE(f) ((f)->output_data.ns->current_pointer)
1021 #define FRAME_FONT(f) ((f)->output_data.ns->font)
1023 #ifdef __OBJC__
1024 #define XNS_SCROLL_BAR(vec) ((id) XSAVE_POINTER (vec, 0))
1025 #else
1026 #define XNS_SCROLL_BAR(vec) XSAVE_POINTER (vec, 0)
1027 #endif
1029 /* Compute pixel size for vertical scroll bars */
1030 #define NS_SCROLL_BAR_WIDTH(f) \
1031 (FRAME_HAS_VERTICAL_SCROLL_BARS (f) \
1032 ? rint (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0 \
1033 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f) \
1034 : (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f))) \
1035 : 0)
1037 /* Compute pixel size for horizontal scroll bars */
1038 #define NS_SCROLL_BAR_HEIGHT(f) \
1039 (FRAME_HAS_HORIZONTAL_SCROLL_BARS (f) \
1040 ? rint (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0 \
1041 ? FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) \
1042 : (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f))) \
1043 : 0)
1045 /* Difference btwn char-column-calculated and actual SB widths.
1046 This is only a concern for rendering when SB on left. */
1047 #define NS_SCROLL_BAR_ADJUST(w, f) \
1048 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) ? \
1049 (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f) \
1050 - NS_SCROLL_BAR_WIDTH (f)) : 0)
1052 /* Difference btwn char-line-calculated and actual SB heights.
1053 This is only a concern for rendering when SB on top. */
1054 #define NS_SCROLL_BAR_ADJUST_HORIZONTALLY(w, f) \
1055 (WINDOW_HAS_HORIZONTAL_SCROLL_BARS (w) ? \
1056 (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f) \
1057 - NS_SCROLL_BAR_HEIGHT (f)) : 0)
1059 /* XXX: fix for GNUstep inconsistent accounting for titlebar */
1060 #ifdef NS_IMPL_GNUSTEP
1061 #define NS_TOP_POS(f) ((f)->top_pos + 18)
1062 #else
1063 #define NS_TOP_POS(f) ((f)->top_pos)
1064 #endif
1066 #define FRAME_NS_FONT_TABLE(f) (FRAME_DISPLAY_INFO (f)->font_table)
1068 #define FRAME_FONTSET(f) ((f)->output_data.ns->fontset)
1070 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.ns->baseline_offset)
1071 #define BLACK_PIX_DEFAULT(f) 0x000000
1072 #define WHITE_PIX_DEFAULT(f) 0xFFFFFF
1074 /* First position where characters can be shown (instead of scrollbar, if
1075 it is on left. */
1076 #define FIRST_CHAR_POSITION(f) \
1077 (! (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) ? 0 \
1078 : FRAME_SCROLL_BAR_COLS (f))
1080 extern struct ns_display_info *ns_term_init (Lisp_Object display_name);
1081 extern void ns_term_shutdown (int sig);
1083 /* constants for text rendering */
1084 #define NS_DUMPGLYPH_NORMAL 0
1085 #define NS_DUMPGLYPH_CURSOR 1
1086 #define NS_DUMPGLYPH_FOREGROUND 2
1087 #define NS_DUMPGLYPH_MOUSEFACE 3
1091 /* In nsfont, called from fontset.c */
1092 extern void nsfont_make_fontset_for_font (Lisp_Object name,
1093 Lisp_Object font_object);
1095 /* In nsfont, for debugging */
1096 struct glyph_string;
1097 void ns_dump_glyphstring (struct glyph_string *s);
1099 /* Implemented in nsterm, published in or needed from nsfns. */
1100 extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern,
1101 int size, int maxnames);
1102 extern void ns_clear_frame (struct frame *f);
1104 extern const char *ns_xlfd_to_fontname (const char *xlfd);
1106 extern Lisp_Object ns_map_event_to_object (void);
1107 #ifdef __OBJC__
1108 extern Lisp_Object ns_string_from_pasteboard (id pb);
1109 extern void ns_string_to_pasteboard (id pb, Lisp_Object str);
1110 #endif
1111 extern Lisp_Object ns_get_local_selection (Lisp_Object selection_name,
1112 Lisp_Object target_type);
1113 extern void nxatoms_of_nsselect (void);
1114 extern int ns_lisp_to_cursor_type (Lisp_Object arg);
1115 extern Lisp_Object ns_cursor_type_to_lisp (int arg);
1116 extern void ns_set_name_as_filename (struct frame *f);
1117 extern void ns_set_doc_edited (void);
1119 extern bool
1120 ns_defined_color (struct frame *f,
1121 const char *name,
1122 XColor *color_def, bool alloc,
1123 bool makeIndex);
1124 extern void
1125 ns_query_color (void *col, XColor *color_def, int setPixel);
1127 #ifdef __OBJC__
1128 extern Lisp_Object ns_color_to_lisp (NSColor *col);
1129 extern int ns_lisp_to_color (Lisp_Object color, NSColor **col);
1130 extern NSColor *ns_lookup_indexed_color (unsigned long idx, struct frame *f);
1131 extern unsigned long ns_index_color (NSColor *color, struct frame *f);
1132 extern void ns_free_indexed_color (unsigned long idx, struct frame *f);
1133 extern const char *ns_get_pending_menu_title (void);
1134 extern void ns_check_menu_open (NSMenu *menu);
1135 extern void ns_check_pending_open_menu (void);
1136 #endif
1138 /* C access to ObjC functionality */
1139 extern void ns_release_object (void *obj);
1140 extern void ns_retain_object (void *obj);
1141 extern void *ns_alloc_autorelease_pool (void);
1142 extern void ns_release_autorelease_pool (void *);
1143 extern const char *ns_get_defaults_value (const char *key);
1144 extern void ns_init_locale (void);
1147 /* in nsmenu */
1148 extern void update_frame_tool_bar (struct frame *f);
1149 extern void free_frame_tool_bar (struct frame *f);
1150 extern void find_and_call_menu_selection (struct frame *f,
1151 int menu_bar_items_used, Lisp_Object vector, void *client_data);
1152 extern Lisp_Object find_and_return_menu_selection (struct frame *f,
1153 bool keymaps,
1154 void *client_data);
1155 extern Lisp_Object ns_popup_dialog (struct frame *, Lisp_Object header,
1156 Lisp_Object contents);
1158 #define NSAPP_DATA2_RUNASSCRIPT 10
1159 extern void ns_run_ascript (void);
1161 #define NSAPP_DATA2_RUNFILEDIALOG 11
1162 extern void ns_run_file_dialog (void);
1164 extern const char *ns_etc_directory (void);
1165 extern const char *ns_exec_path (void);
1166 extern const char *ns_load_path (void);
1167 extern void syms_of_nsterm (void);
1168 extern void syms_of_nsfns (void);
1169 extern void syms_of_nsmenu (void);
1170 extern void syms_of_nsselect (void);
1172 /* From nsimage.m, needed in image.c */
1173 struct image;
1174 extern void *ns_image_from_XBM (unsigned char *bits, int width, int height,
1175 unsigned long fg, unsigned long bg);
1176 extern void *ns_image_for_XPM (int width, int height, int depth);
1177 extern void *ns_image_from_file (Lisp_Object file);
1178 extern bool ns_load_image (struct frame *f, struct image *img,
1179 Lisp_Object spec_file, Lisp_Object spec_data);
1180 extern int ns_image_width (void *img);
1181 extern int ns_image_height (void *img);
1182 extern unsigned long ns_get_pixel (void *img, int x, int y);
1183 extern void ns_put_pixel (void *img, int x, int y, unsigned long argb);
1184 extern void ns_set_alpha (void *img, int x, int y, unsigned char a);
1186 extern int x_display_pixel_height (struct ns_display_info *);
1187 extern int x_display_pixel_width (struct ns_display_info *);
1189 /* This in nsterm.m */
1190 extern void x_destroy_window (struct frame *f);
1191 extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds,
1192 fd_set *exceptfds, struct timespec const *timeout,
1193 sigset_t const *sigmask);
1194 extern unsigned long ns_get_rgb_color (struct frame *f,
1195 float r, float g, float b, float a);
1197 extern void ns_init_events ();
1198 extern void ns_finish_events ();
1200 #ifdef __OBJC__
1201 /* From nsterm.m, needed in nsfont.m. */
1202 extern void
1203 ns_draw_text_decoration (struct glyph_string *s, struct face *face,
1204 NSColor *defaultCol, CGFloat width, CGFloat x);
1205 /* Needed in nsfns.m. */
1206 extern void
1207 ns_set_represented_filename (NSString* fstr, struct frame *f);
1209 #endif
1211 #ifdef NS_IMPL_GNUSTEP
1212 extern char gnustep_base_version[]; /* version tracking */
1213 #endif
1215 #define MINWIDTH 10
1216 #define MINHEIGHT 10
1218 /* Screen max coordinate
1219 Using larger coordinates causes movewindow/placewindow to abort */
1220 #define SCREENMAX 16000
1222 #define NS_SCROLL_BAR_WIDTH_DEFAULT [EmacsScroller scrollerWidth]
1223 #define NS_SCROLL_BAR_HEIGHT_DEFAULT [EmacsScroller scrollerHeight]
1224 /* This is to match emacs on other platforms, ugly though it is. */
1225 #define NS_SELECTION_BG_COLOR_DEFAULT @"LightGoldenrod2";
1226 #define NS_SELECTION_FG_COLOR_DEFAULT @"Black";
1227 #define RESIZE_HANDLE_SIZE 12
1229 /* Little utility macros */
1230 #define IN_BOUND(min, x, max) (((x) < (min)) \
1231 ? (min) : (((x)>(max)) ? (max) : (x)))
1232 #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
1234 #endif /* HAVE_NS */