]> code.delx.au - gnu-emacs/blob - src/nsterm.h
7828af73f68a4340d8f355f8618b7a8781fcc027
[gnu-emacs] / src / nsterm.h
1 /* Definitions and headers for communication with NeXT/Open/GNUstep API.
2 Copyright (C) 1989, 1993, 2005, 2008-2015 Free Software Foundation,
3 Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
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.
16
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/>. */
19
20
21 #include "dispextern.h"
22 #include "frame.h"
23 #include "character.h"
24 #include "font.h"
25 #include "sysselect.h"
26
27 #ifdef HAVE_NS
28
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
42
43 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
44 #define HAVE_NATIVE_FS
45 #endif
46
47 #endif /* NS_IMPL_COCOA */
48
49 #ifdef __OBJC__
50
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
61
62 /* ==========================================================================
63
64 Trace support
65
66 ========================================================================== */
67
68 /* Uncomment the following line to enable trace.
69
70 Hint: keep the trailing whitespace -- the version control system
71 will reject accidental commits. */
72
73 /* #define NSTRACE_ENABLED 1 */
74
75
76 /* Print a call tree containing all annotated functions.
77
78 The call structure of the functions is represented using
79 indentation and vertical lines. Extra information is printed using
80 horizontal lines that connect to the vertical line.
81
82 The return value is represented using the arrow "->>". For simple
83 functions, the arrow can be printed on the same line as the
84 function name. If more output is printed, it is connected to the
85 vertical line of the function.
86
87 The first column contains the file name, the second the line
88 number, and the third a number increasing for each trace line.
89
90 Note that the trace system, when enabled, use the GCC/Clang
91 "cleanup" extension.
92
93 For example (long lines manually split to reduce width):
94
95 nsterm.m : 1600: [ 4428] ns_fullscreen_hook
96 nsterm.m : 7006: [ 4429] | handleFS
97 nsterm.m : 7035: [ 4430] | +--- FULLSCREEN_MAXIMIZED
98 nsterm.m : 7627: [ 4431] | | performZoom
99 nsterm.m : 7636: [ 4432] | | | zoom
100 nsterm.m : 874: [ 4433] | | | | ns_update_auto_hide_menu_bar
101 nsterm.m : 6615: [ 4434] | | | | [windowWillUseStandardFrame:
102 defaultFrame:(X:0 Y:0)/(W:1600 H:1177)]
103 nsterm.m : 99: [ 4435] | | | | +--- fs_state: FULLSCREEN_NONE
104 nsterm.m : 119: [ 4436] | | | | +--- fs_before_fs: -1
105 nsterm.m : 115: [ 4437] | | | | +--- next_maximized: FULLSCREEN_MAXIMIZED
106 nsterm.m : 6619: [ 4438] | | | | +--- ns_userRect: (X:0 Y:0)/(W:0 H:0)
107 nsterm.m : 6620: [ 4439] | | | | +--- [sender frame]:
108 (X:0 Y:626)/(W:595 H:551)
109 nsterm.m : 6644: [ 4440] | | | | +--- ns_userRect (2):
110 (X:0 Y:626)/(W:595 H:551)
111 nsterm.m : 6684: [ 4441] | | | | +--- FULLSCREEN_MAXIMIZED
112 nsterm.m : 7057: [ 4442] | | | | | setFSValue
113 nsterm.m : 115: [ 4443] | | | | | +--- value: FULLSCREEN_MAXIMIZED
114 nsterm.m : 6711: [ 4444] | | | | +--- Final ns_userRect:
115 (X:0 Y:626)/(W:595 H:551)
116 nsterm.m : 6712: [ 4445] | | | | +--- Final maximized_width: 1600
117 nsterm.m : 6713: [ 4446] | | | | +--- Final maximized_height: 1177
118 nsterm.m : 119: [ 4447] | | | | +--- Final next_maximized: -1
119 nsterm.m : 6209: [ 4448] | | | | | windowWillResize: toSize: (W:1600 H:1177)
120 nsterm.m : 6210: [ 4449] | | | | | +--- [sender frame]:
121 (X:0 Y:626)/(W:595 H:551)
122 nsterm.m : 115: [ 4450] | | | | | +--- fs_state: FULLSCREEN_MAXIMIZED
123 nsterm.m : 6274: [ 4451] | | | | | +--- cols: 223 rows: 79
124 nsterm.m : 6299: [ 4452] | | | | | +->> (W:1596 H:1167)
125 nsterm.m : 6718: [ 4453] | | | | +->> (X:0 Y:0)/(W:1600 H:1177)
126
127 Here, "ns_fullscreen_hook" calls "handleFS", which is turn calls
128 "performZoom". This function calls "[super performZoom]", which
129 isn't annotated (so it doesn't show up in the trace). However, it
130 calls "zoom" which is annotated so it is part of the call trace.
131 Later, the method "windowWillUseStandardFrame" and the function
132 "setFSValue" are called. The lines with "+---" contain extra
133 information and lines containing "->>" represent return values. */
134
135 #ifndef NSTRACE_ENABLED
136 #define NSTRACE_ENABLED 0
137 #endif
138
139 #if NSTRACE_ENABLED
140 extern int nstrace_num;
141 extern int nstrace_depth;
142
143 void nstrace_leave(int *);
144
145 /* printf-style trace output. Output is aligned with contained heading. */
146 #define NSTRACE_MSG_NO_DASHES(...) \
147 do \
148 { \
149 if (nstrace_enabled) \
150 { \
151 fprintf (stderr, "%-10s:%5d: [%5d]%.*s", \
152 __FILE__, __LINE__, ++nstrace_num, \
153 2*nstrace_depth, " | | | | | | | | | | | | | | | .."); \
154 fprintf (stderr, __VA_ARGS__); \
155 fprintf (stderr, "\n"); \
156 } \
157 } \
158 while(0)
159
160 #define NSTRACE_MSG(...) NSTRACE_MSG_NO_DASHES("+--- " __VA_ARGS__)
161
162
163
164 /* Macros for printing complex types.
165
166 NSTRACE_FMT_what -- Printf format string for "what".
167 NSTRACE_ARG_what(x) -- Printf argument for "what". */
168
169 #define NSTRACE_FMT_SIZE "(W:%.0f H:%.0f)"
170 #define NSTRACE_ARG_SIZE(elt) (elt).width, (elt).height
171
172 #define NSTRACE_FMT_POINT "(X:%.0f Y:%.0f)"
173 #define NSTRACE_ARG_POINT(elt) (elt).x, (elt).y
174
175 #define NSTRACE_FMT_RECT NSTRACE_FMT_POINT "/" NSTRACE_FMT_SIZE
176 #define NSTRACE_ARG_RECT(elt) \
177 NSTRACE_ARG_POINT((elt).origin), NSTRACE_ARG_SIZE((elt).size)
178
179
180 /* Macros for printing complex types as extra information. */
181
182 #define NSTRACE_SIZE(str,size) \
183 NSTRACE_MSG (str ": " NSTRACE_FMT_SIZE, \
184 NSTRACE_ARG_SIZE (size));
185
186 #define NSTRACE_POINT(str,point) \
187 NSTRACE_MSG (str ": " NSTRACE_FMT_POINT, \
188 NSTRACE_ARG_POINT (point));
189
190 #define NSTRACE_RECT(str,rect) \
191 NSTRACE_MSG (str ": " NSTRACE_FMT_RECT, \
192 NSTRACE_ARG_RECT (rect));
193
194 #define NSTRACE_FSTYPE(str,fs_type) \
195 do \
196 { \
197 if (nstrace_enabled) \
198 { \
199 ns_print_fullscreen_type_name(str, fs_type); \
200 } \
201 } \
202 while(0)
203
204
205 /* Return value macros.
206
207 NSTRACE_RETURN(fmt, ...) - Print a return value, support printf-style
208 format string and arguments.
209
210 NSTRACE_RETURN_what(obj) - Print a return value of kind WHAT.
211
212 NSTRACE_FMT_RETURN - A string literal representing a returned
213 value. Useful when creating a format string
214 to printf-like constructs like NSTRACE(). */
215
216 #define NSTRACE_FMT_RETURN "->>"
217
218 #define NSTRACE_RETURN(...) \
219 NSTRACE_MSG_NO_DASHES ("+" NSTRACE_FMT_RETURN " " __VA_ARGS__)
220
221 #define NSTRACE_RETURN_SIZE(size) \
222 NSTRACE_RETURN(NSTRACE_FMT_SIZE, NSTRACE_ARG_SIZE(size))
223
224 #define NSTRACE_RETURN_POINT(point) \
225 NSTRACE_RETURN(NSTRACE_FMT_POINT, NSTRACE_ARG_POINT(point))
226
227 #define NSTRACE_RETURN_RECT(rect) \
228 NSTRACE_RETURN(NSTRACE_FMT_RECT, NSTRACE_ARG_RECT(rect))
229
230
231 /* Function enter macros.
232
233 NSTRACE (fmt, ...) -- Enable trace output in current block
234 (typically a function). Accepts printf-style
235 arguments.
236
237 NSTRACE_WHEN (cond, fmt, ...) -- Enable trace output when COND is true.
238
239 NSTRACE_UNLESS (cond, fmt, ...) -- Enable trace output unless COND is
240 true. */
241
242
243
244 #define NSTRACE_WHEN(cond, ...) \
245 __attribute__((cleanup(nstrace_leave))) \
246 int nstrace_enabled = (cond); \
247 if (nstrace_enabled) { ++nstrace_depth; } \
248 NSTRACE_MSG_NO_DASHES(__VA_ARGS__);
249
250 #endif /* NSTRACE_ENABLED */
251
252 #define NSTRACE(...) NSTRACE_WHEN(1, __VA_ARGS__)
253 #define NSTRACE_UNLESS(cond, ...) NSTRACE_WHEN(!(cond), __VA_ARGS__)
254
255
256 /* Non-trace replacement versions. */
257 #ifndef NSTRACE_WHEN
258 #define NSTRACE_WHEN(...)
259 #endif
260
261 #ifndef NSTRACE_MSG
262 #define NSTRACE_MSG(...)
263 #endif
264
265 #ifndef NSTRACE_SIZE
266 #define NSTRACE_SIZE(str,size)
267 #endif
268
269 #ifndef NSTRACE_POINT
270 #define NSTRACE_POINT(str,point)
271 #endif
272
273 #ifndef NSTRACE_RECT
274 #define NSTRACE_RECT(str,rect)
275 #endif
276
277 #ifndef NSTRACE_FSTYPE
278 #define NSTRACE_FSTYPE(str,fs_type)
279 #endif
280
281 #ifndef NSTRACE_RETURN_SIZE
282 #define NSTRACE_RETURN_SIZE(size)
283 #endif
284
285 #ifndef NSTRACE_RETURN_POINT
286 #define NSTRACE_RETURN_POINT(point)
287 #endif
288
289 #ifndef NSTRACE_RETURN_RECT
290 #define NSTRACE_RETURN_RECT(rect)
291 #endif
292
293 #ifndef NSTRACE_RETURN_FSTYPE
294 #define NSTRACE_RETURN_FSTYPE(fs_type)
295 #endif
296
297
298
299 /* ==========================================================================
300
301 NSColor, EmacsColor category.
302
303 ========================================================================== */
304 @interface NSColor (EmacsColor)
305 + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
306 blue:(CGFloat)blue alpha:(CGFloat)alpha;
307 - (NSColor *)colorUsingDefaultColorSpace;
308
309 @end
310
311 /* ==========================================================================
312
313 The Emacs application
314
315 ========================================================================== */
316
317 /* We override sendEvent: as a means to stop/start the event loop */
318 @interface EmacsApp : NSApplication
319 {
320 #ifdef NS_IMPL_COCOA
321 BOOL shouldKeepRunning;
322 BOOL isFirst;
323 #endif
324 #ifdef NS_IMPL_GNUSTEP
325 BOOL applicationDidFinishLaunchingCalled;
326 @public
327 int nextappdefined;
328 #endif
329 }
330 - (void)logNotification: (NSNotification *)notification;
331 - (void)antialiasThresholdDidChange:(NSNotification *)notification;
332 - (void)sendEvent: (NSEvent *)theEvent;
333 - (void)showPreferencesWindow: (id)sender;
334 - (BOOL) openFile: (NSString *)fileName;
335 - (void)fd_handler: (id)unused;
336 - (void)timeout_handler: (NSTimer *)timedEntry;
337 - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg;
338 #ifdef NS_IMPL_GNUSTEP
339 - (void)sendFromMainThread:(id)unused;
340 #endif
341 @end
342
343 #ifdef NS_IMPL_GNUSTEP
344 /* Dummy class to get rid of startup warnings. */
345 @interface EmacsDocument : NSDocument
346 {
347 }
348 @end
349 #endif
350
351 /* ==========================================================================
352
353 The main Emacs view
354
355 ========================================================================== */
356
357 @class EmacsToolbar;
358
359 #ifdef NS_IMPL_COCOA
360 @interface EmacsView : NSView <NSTextInput, NSWindowDelegate>
361 #else
362 @interface EmacsView : NSView <NSTextInput>
363 #endif
364 {
365 #ifdef NS_IMPL_COCOA
366 char *old_title;
367 BOOL maximizing_resize;
368 #endif
369 BOOL windowClosing;
370 NSString *workingText;
371 BOOL processingCompose;
372 int fs_state, fs_before_fs, next_maximized;
373 int tibar_height, tobar_height, bwidth;
374 int maximized_width, maximized_height;
375 NSWindow *nonfs_window;
376 BOOL fs_is_native;
377 @public
378 struct frame *emacsframe;
379 int rows, cols;
380 int scrollbarsNeedingUpdate;
381 EmacsToolbar *toolbar;
382 NSRect ns_userRect;
383 BOOL wait_for_tool_bar;
384 }
385
386 /* AppKit-side interface */
387 - menuDown: (id)sender;
388 - toolbarClicked: (id)item;
389 - toggleToolbar: (id)sender;
390 - (void)keyDown: (NSEvent *)theEvent;
391 - (void)mouseDown: (NSEvent *)theEvent;
392 - (void)mouseUp: (NSEvent *)theEvent;
393 - setMiniwindowImage: (BOOL)setMini;
394
395 /* Emacs-side interface */
396 - initFrameFromEmacs: (struct frame *) f;
397 - (void) setRows: (int) r andColumns: (int) c;
398 - (void) setWindowClosing: (BOOL)closing;
399 - (EmacsToolbar *) toolbar;
400 - (void) deleteWorkingText;
401 - (void) updateFrameSize: (BOOL) delay;
402 - (void) handleFS;
403 - (void) setFSValue: (int)value;
404 - (void) toggleFullScreen: (id) sender;
405 - (BOOL) fsIsNative;
406 - (BOOL) isFullscreen;
407 #ifdef HAVE_NATIVE_FS
408 - (void) updateCollectionBehavior;
409 #endif
410
411 #ifdef NS_IMPL_GNUSTEP
412 - (void)windowDidMove: (id)sender;
413 #endif
414 - (int)fullscreenState;
415
416 /* Non-notification versions of NSView methods. Used for direct calls. */
417 - (void)windowWillEnterFullScreen;
418 - (void)windowDidEnterFullScreen;
419 - (void)windowWillExitFullScreen;
420 - (void)windowDidExitFullScreen;
421 - (void)windowDidBecomeKey;
422 @end
423
424
425 /* Small utility used for processing resize events under Cocoa. */
426 @interface EmacsWindow : NSWindow
427 {
428 NSPoint grabOffset;
429 }
430 @end
431
432
433 /* Fullscreen version of the above. */
434 @interface EmacsFSWindow : EmacsWindow
435 {
436 }
437 @end
438
439 /* ==========================================================================
440
441 The main menu implementation
442
443 ========================================================================== */
444
445 #ifdef NS_IMPL_COCOA
446 @interface EmacsMenu : NSMenu <NSMenuDelegate>
447 #else
448 @interface EmacsMenu : NSMenu
449 #endif
450 {
451 struct frame *frame;
452 unsigned long keyEquivModMask;
453 }
454
455 - initWithTitle: (NSString *)title frame: (struct frame *)f;
456 - (void)setFrame: (struct frame *)f;
457 - (void)menuNeedsUpdate: (NSMenu *)menu; /* (delegate method) */
458 - (NSString *)parseKeyEquiv: (const char *)key;
459 - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr;
460 - (void)fillWithWidgetValue: (void *)wvptr;
461 - (void)fillWithWidgetValue: (void *)wvptr frame: (struct frame *)f;
462 - (EmacsMenu *)addSubmenuWithTitle: (const char *)title forFrame: (struct frame *)f;
463 - (void) clear;
464 - (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f
465 keymaps: (bool)keymaps;
466 @end
467
468
469 /* ==========================================================================
470
471 Toolbar
472
473 ========================================================================== */
474
475 @class EmacsImage;
476
477 #ifdef NS_IMPL_COCOA
478 @interface EmacsToolbar : NSToolbar <NSToolbarDelegate>
479 #else
480 @interface EmacsToolbar : NSToolbar
481 #endif
482 {
483 EmacsView *emacsView;
484 NSMutableDictionary *identifierToItem;
485 NSMutableArray *activeIdentifiers;
486 NSArray *prevIdentifiers;
487 unsigned long enablement, prevEnablement;
488 }
489 - initForView: (EmacsView *)view withIdentifier: (NSString *)identifier;
490 - (void) clearActive;
491 - (void) clearAll;
492 - (BOOL) changed;
493 - (void) addDisplayItemWithImage: (EmacsImage *)img
494 idx: (int)idx
495 tag: (int)tag
496 helpText: (const char *)help
497 enabled: (BOOL)enabled;
498
499 /* delegate methods */
500 - (NSToolbarItem *)toolbar: (NSToolbar *)toolbar
501 itemForItemIdentifier: (NSString *)itemIdentifier
502 willBeInsertedIntoToolbar: (BOOL)flag;
503 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar;
504 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar;
505 @end
506
507
508 /* ==========================================================================
509
510 Message / question windows
511
512 ========================================================================== */
513
514 @interface EmacsDialogPanel : NSPanel
515 {
516 NSTextField *command;
517 NSTextField *title;
518 NSMatrix *matrix;
519 int rows, cols;
520 BOOL timer_fired, window_closed;
521 Lisp_Object dialog_return;
522 Lisp_Object *button_values;
523 }
524 - initFromContents: (Lisp_Object)menu isQuestion: (BOOL)isQ;
525 - (void)process_dialog: (Lisp_Object)list;
526 - (void)addButton: (char *)str value: (int)tag row: (int)row;
527 - (void)addString: (char *)str row: (int)row;
528 - (void)addSplit;
529 - (Lisp_Object)runDialogAt: (NSPoint)p;
530 - (void)timeout_handler: (NSTimer *)timedEntry;
531 @end
532
533 #ifdef NS_IMPL_COCOA
534 @interface EmacsTooltip : NSObject <NSWindowDelegate>
535 #else
536 @interface EmacsTooltip : NSObject
537 #endif
538 {
539 NSWindow *win;
540 NSTextField *textField;
541 NSTimer *timer;
542 }
543 - init;
544 - (void) setText: (char *)text;
545 - (void) showAtX: (int)x Y: (int)y for: (int)seconds;
546 - (void) hide;
547 - (BOOL) isActive;
548 - (NSRect) frame;
549 @end
550
551
552 /* ==========================================================================
553
554 File open/save panels
555 This and next override methods to handle keyboard input in panels.
556
557 ========================================================================== */
558
559 @interface EmacsSavePanel : NSSavePanel
560 {
561 }
562 @end
563 @interface EmacsOpenPanel : NSOpenPanel
564 {
565 }
566 @end
567
568 @interface EmacsFileDelegate : NSObject
569 {
570 }
571 - (BOOL)panel: (id)sender isValidFilename: (NSString *)filename;
572 - (BOOL)panel: (id)sender shouldShowFilename: (NSString *)filename;
573 - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
574 confirmed: (BOOL)okFlag;
575 @end
576
577
578 /* ==========================================================================
579
580 Images and stippling
581
582 ========================================================================== */
583
584 @interface EmacsImage : NSImage
585 {
586 NSBitmapImageRep *bmRep; /* used for accessing pixel data */
587 unsigned char *pixmapData[5]; /* shortcut to access pixel data */
588 NSColor *stippleMask;
589 unsigned long xbm_fg;
590 }
591 + allocInitFromFile: (Lisp_Object)file;
592 - (void)dealloc;
593 - initFromXBM: (unsigned char *)bits width: (int)w height: (int)h
594 fg: (unsigned long)fg bg: (unsigned long)bg;
595 - setXBMColor: (NSColor *)color;
596 - initForXPMWithDepth: (int)depth width: (int)width height: (int)height;
597 - (void)setPixmapData;
598 - (unsigned long)getPixelAtX: (int)x Y: (int)y;
599 - (void)setPixelAtX: (int)x Y: (int)y toRed: (unsigned char)r
600 green: (unsigned char)g blue: (unsigned char)b
601 alpha:(unsigned char)a;
602 - (void)setAlphaAtX: (int)x Y: (int)y to: (unsigned char)a;
603 - (NSColor *)stippleMask;
604 @end
605
606
607 /* ==========================================================================
608
609 Scrollbars
610
611 ========================================================================== */
612
613 @interface EmacsScroller : NSScroller
614 {
615 struct window *window;
616 struct frame *frame;
617 NSResponder *prevResponder;
618
619 /* offset to the bottom of knob of last mouse down */
620 CGFloat last_mouse_offset;
621 float min_portion;
622 int pixel_height;
623 enum scroll_bar_part last_hit_part;
624
625 BOOL condemned;
626
627 /* optimize against excessive positioning calls generated by emacs */
628 int em_position;
629 int em_portion;
630 int em_whole;
631 }
632
633 - initFrame: (NSRect )r window: (Lisp_Object)win;
634 - (void)setFrame: (NSRect)r;
635
636 - setPosition: (int) position portion: (int) portion whole: (int) whole;
637 - (int) checkSamePosition: (int)position portion: (int)portion
638 whole: (int)whole;
639 - (void) sendScrollEventAtLoc: (float)loc fromEvent: (NSEvent *)e;
640 - repeatScroll: (NSTimer *)sender;
641 - condemn;
642 - reprieve;
643 - (bool)judge;
644 + (CGFloat)scrollerWidth;
645 @end
646
647
648 /* ==========================================================================
649
650 Rendering
651
652 ========================================================================== */
653
654 #ifdef NS_IMPL_COCOA
655 /* rendering util */
656 @interface EmacsGlyphStorage : NSObject <NSGlyphStorage>
657 {
658 @public
659 NSAttributedString *attrStr;
660 NSMutableDictionary *dict;
661 CGGlyph *cglyphs;
662 unsigned long maxChar, maxGlyph;
663 long i, len;
664 }
665 - initWithCapacity: (unsigned long) c;
666 - (void) setString: (NSString *)str font: (NSFont *)font;
667 @end
668 #endif /* NS_IMPL_COCOA */
669
670 extern NSArray *ns_send_types, *ns_return_types;
671 extern NSString *ns_app_name;
672 extern EmacsMenu *mainMenu, *svcsMenu, *dockMenu;
673
674 /* Apple removed the declaration, but kept the implementation */
675 #if defined (NS_IMPL_COCOA)
676 @interface NSApplication (EmacsApp)
677 - (void)setAppleMenu: (NSMenu *)menu;
678 @end
679 #endif
680
681 #endif /* __OBJC__ */
682
683
684
685 /* ==========================================================================
686
687 Non-OO stuff
688
689 ========================================================================== */
690
691 /* Special keycodes that we pass down the event chain */
692 #define KEY_NS_POWER_OFF ((1<<28)|(0<<16)|1)
693 #define KEY_NS_OPEN_FILE ((1<<28)|(0<<16)|2)
694 #define KEY_NS_OPEN_TEMP_FILE ((1<<28)|(0<<16)|3)
695 #define KEY_NS_CHANGE_FONT ((1<<28)|(0<<16)|7)
696 #define KEY_NS_OPEN_FILE_LINE ((1<<28)|(0<<16)|8)
697 #define KEY_NS_PUT_WORKING_TEXT ((1<<28)|(0<<16)|9)
698 #define KEY_NS_UNPUT_WORKING_TEXT ((1<<28)|(0<<16)|10)
699 #define KEY_NS_SPI_SERVICE_CALL ((1<<28)|(0<<16)|11)
700 #define KEY_NS_NEW_FRAME ((1<<28)|(0<<16)|12)
701 #define KEY_NS_TOGGLE_TOOLBAR ((1<<28)|(0<<16)|13)
702 #define KEY_NS_SHOW_PREFS ((1<<28)|(0<<16)|14)
703
704 /* could use list to store these, but rest of emacs has a big infrastructure
705 for managing a table of bitmap "records" */
706 struct ns_bitmap_record
707 {
708 #ifdef __OBJC__
709 EmacsImage *img;
710 #else
711 void *img;
712 #endif
713 char *file;
714 int refcount;
715 int height, width, depth;
716 };
717
718 /* this to map between emacs color indices and NSColor objects */
719 struct ns_color_table
720 {
721 ptrdiff_t size;
722 ptrdiff_t avail;
723 #ifdef __OBJC__
724 NSColor **colors;
725 NSMutableSet *empty_indices;
726 #else
727 void **items;
728 void *availIndices;
729 #endif
730 };
731 #define NS_COLOR_CAPACITY 256
732
733 #define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
734 #define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
735
736 #define ALPHA_FROM_ULONG(color) ((color) >> 24)
737 #define RED_FROM_ULONG(color) (((color) >> 16) & 0xff)
738 #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
739 #define BLUE_FROM_ULONG(color) ((color) & 0xff)
740
741 /* Do not change `* 0x101' in the following lines to `<< 8'. If
742 changed, image masks in 1-bit depth will not work. */
743 #define RED16_FROM_ULONG(color) (RED_FROM_ULONG(color) * 0x101)
744 #define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
745 #define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)
746
747 /* this extends font backend font */
748 struct nsfont_info
749 {
750 struct font font;
751
752 char *name; /* PostScript name, uniquely identifies on NS systems */
753
754 /* The following metrics are stored as float rather than int. */
755
756 float width; /* Maximum advance for the font. */
757 float height;
758 float underpos;
759 float underwidth;
760 float size;
761 #ifdef __OBJC__
762 NSFont *nsfont;
763 #if defined (NS_IMPL_COCOA)
764 CGFontRef cgfont;
765 #else /* GNUstep */
766 void *cgfont;
767 #endif
768 #else /* ! OBJC */
769 void *nsfont;
770 void *cgfont;
771 #endif
772 char bold, ital; /* convenience flags */
773 char synthItal;
774 XCharStruct max_bounds;
775 /* we compute glyph codes and metrics on-demand in blocks of 256 indexed
776 by hibyte, lobyte */
777 unsigned short **glyphs; /* map Unicode index to glyph */
778 struct font_metrics **metrics;
779 };
780
781
782 /* init'd in ns_initialize_display_info () */
783 struct ns_display_info
784 {
785 /* Chain of all ns_display_info structures. */
786 struct ns_display_info *next;
787
788 /* The generic display parameters corresponding to this NS display. */
789 struct terminal *terminal;
790
791 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
792 Lisp_Object name_list_element;
793
794 /* The number of fonts loaded. */
795 int n_fonts;
796
797 /* Minimum width over all characters in all fonts in font_table. */
798 int smallest_char_width;
799
800 /* Minimum font height over all fonts in font_table. */
801 int smallest_font_height;
802
803 struct ns_bitmap_record *bitmaps;
804 ptrdiff_t bitmaps_size;
805 ptrdiff_t bitmaps_last;
806
807 struct ns_color_table *color_table;
808
809 /* DPI resolution of this screen */
810 double resx, resy;
811
812 /* Mask of things that cause the mouse to be grabbed */
813 int grabbed;
814
815 int n_planes;
816
817 int color_p;
818
819 Window root_window;
820
821 /* Xism */
822 XrmDatabase xrdb;
823
824 /* The cursor to use for vertical scroll bars. */
825 Cursor vertical_scroll_bar_cursor;
826
827 /* The cursor to use for horizontal scroll bars. */
828 Cursor horizontal_scroll_bar_cursor;
829
830 /* Information about the range of text currently shown in
831 mouse-face. */
832 Mouse_HLInfo mouse_highlight;
833
834 struct frame *x_highlight_frame;
835 struct frame *x_focus_frame;
836
837 /* The frame where the mouse was last time we reported a mouse event. */
838 struct frame *last_mouse_frame;
839
840 /* The frame where the mouse was last time we reported a mouse motion. */
841 struct frame *last_mouse_motion_frame;
842
843 /* Position where the mouse was last time we reported a motion.
844 This is a position on last_mouse_motion_frame. */
845 int last_mouse_motion_x;
846 int last_mouse_motion_y;
847
848 /* Where the mouse was last time we reported a mouse position. */
849 NSRect last_mouse_glyph;
850
851 /* Time of last mouse movement. */
852 Time last_mouse_movement_time;
853
854 /* The scroll bar in which the last motion event occurred. */
855 #ifdef __OBJC__
856 EmacsScroller *last_mouse_scroll_bar;
857 #else
858 void *last_mouse_scroll_bar;
859 #endif
860 };
861
862 /* This is a chain of structures for all the NS displays currently in use. */
863 extern struct ns_display_info *x_display_list;
864
865 extern struct ns_display_info *ns_display_info_for_name (Lisp_Object name);
866
867 struct ns_output
868 {
869 #ifdef __OBJC__
870 EmacsView *view;
871 id miniimage;
872 NSColor *cursor_color;
873 NSColor *foreground_color;
874 NSColor *background_color;
875 EmacsToolbar *toolbar;
876 #else
877 void *view;
878 void *miniimage;
879 void *cursor_color;
880 void *foreground_color;
881 void *background_color;
882 void *toolbar;
883 #endif
884
885 /* NSCursors init'ed in initFrameFromEmacs */
886 Cursor text_cursor;
887 Cursor nontext_cursor;
888 Cursor modeline_cursor;
889 Cursor hand_cursor;
890 Cursor hourglass_cursor;
891 Cursor horizontal_drag_cursor;
892 Cursor vertical_drag_cursor;
893
894 /* NS-specific */
895 Cursor current_pointer;
896
897 /* lord knows why Emacs needs to know about our Window ids.. */
898 Window window_desc, parent_desc;
899 char explicit_parent;
900
901 struct font *font;
902 int baseline_offset;
903
904 /* If a fontset is specified for this frame instead of font, this
905 value contains an ID of the fontset, else -1. */
906 int fontset; /* only used with font_backend */
907
908 int icon_top;
909 int icon_left;
910
911 /* The size of the extra width currently allotted for vertical
912 scroll bars, in pixels. */
913 int vertical_scroll_bar_extra;
914
915 /* The height of the titlebar decoration (included in NSWindow's frame). */
916 int titlebar_height;
917
918 /* The height of the toolbar if displayed, else 0. */
919 int toolbar_height;
920
921 /* This is the Emacs structure for the NS display this frame is on. */
922 struct ns_display_info *display_info;
923
924 /* Non-zero if we are zooming (maximizing) the frame. */
925 int zooming;
926
927 /* Non-zero if we are doing an animation, e.g. toggling the tool bar. */
928 int in_animation;
929 };
930
931 /* this dummy decl needed to support TTYs */
932 struct x_output
933 {
934 int unused;
935 };
936
937
938 /* This gives the ns_display_info structure for the display F is on. */
939 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.ns->display_info)
940 #define FRAME_X_OUTPUT(f) ((f)->output_data.ns)
941 #define FRAME_NS_WINDOW(f) ((f)->output_data.ns->window_desc)
942 #define FRAME_X_WINDOW(f) ((f)->output_data.ns->window_desc)
943
944 /* This is the `Display *' which frame F is on. */
945 #define FRAME_NS_DISPLAY(f) (0)
946 #define FRAME_X_DISPLAY(f) (0)
947 #define FRAME_X_SCREEN(f) (0)
948 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO(f)->visual
949
950 #define FRAME_FOREGROUND_COLOR(f) ((f)->output_data.ns->foreground_color)
951 #define FRAME_BACKGROUND_COLOR(f) ((f)->output_data.ns->background_color)
952
953 #define NS_FACE_FOREGROUND(f) ((f)->foreground)
954 #define NS_FACE_BACKGROUND(f) ((f)->background)
955 #define FRAME_NS_TITLEBAR_HEIGHT(f) ((f)->output_data.ns->titlebar_height)
956 #define FRAME_TOOLBAR_HEIGHT(f) ((f)->output_data.ns->toolbar_height)
957
958 #define FRAME_DEFAULT_FACE(f) FACE_FROM_ID (f, DEFAULT_FACE_ID)
959
960 #define FRAME_NS_VIEW(f) ((f)->output_data.ns->view)
961 #define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
962 #define FRAME_POINTER_TYPE(f) ((f)->output_data.ns->current_pointer)
963
964 #define FRAME_FONT(f) ((f)->output_data.ns->font)
965
966 #ifdef __OBJC__
967 #define XNS_SCROLL_BAR(vec) ((id) XSAVE_POINTER (vec, 0))
968 #else
969 #define XNS_SCROLL_BAR(vec) XSAVE_POINTER (vec, 0)
970 #endif
971
972 /* Compute pixel size for vertical scroll bars */
973 #define NS_SCROLL_BAR_WIDTH(f) \
974 (FRAME_HAS_VERTICAL_SCROLL_BARS (f) \
975 ? rint (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0 \
976 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f) \
977 : (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f))) \
978 : 0)
979
980 /* Compute pixel size for horizontal scroll bars */
981 #define NS_SCROLL_BAR_HEIGHT(f) \
982 (FRAME_HAS_HORIZONTAL_SCROLL_BARS (f) \
983 ? rint (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0 \
984 ? FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) \
985 : (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f))) \
986 : 0)
987
988 /* Difference btwn char-column-calculated and actual SB widths.
989 This is only a concern for rendering when SB on left. */
990 #define NS_SCROLL_BAR_ADJUST(w, f) \
991 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) ? \
992 (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f) \
993 - NS_SCROLL_BAR_WIDTH (f)) : 0)
994
995 /* Difference btwn char-line-calculated and actual SB heights.
996 This is only a concern for rendering when SB on top. */
997 #define NS_SCROLL_BAR_ADJUST_HORIZONTALLY(w, f) \
998 (WINDOW_HAS_HORIZONTAL_SCROLL_BARS (w) ? \
999 (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f) \
1000 - NS_SCROLL_BAR_HEIGHT (f)) : 0)
1001
1002 /* XXX: fix for GNUstep inconsistent accounting for titlebar */
1003 #ifdef NS_IMPL_GNUSTEP
1004 #define NS_TOP_POS(f) ((f)->top_pos + 18)
1005 #else
1006 #define NS_TOP_POS(f) ((f)->top_pos)
1007 #endif
1008
1009 #define FRAME_NS_FONT_TABLE(f) (FRAME_DISPLAY_INFO (f)->font_table)
1010
1011 #define FRAME_FONTSET(f) ((f)->output_data.ns->fontset)
1012
1013 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.ns->baseline_offset)
1014 #define BLACK_PIX_DEFAULT(f) 0x000000
1015 #define WHITE_PIX_DEFAULT(f) 0xFFFFFF
1016
1017 /* First position where characters can be shown (instead of scrollbar, if
1018 it is on left. */
1019 #define FIRST_CHAR_POSITION(f) \
1020 (! (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) ? 0 \
1021 : FRAME_SCROLL_BAR_COLS (f))
1022
1023 extern struct ns_display_info *ns_term_init (Lisp_Object display_name);
1024 extern void ns_term_shutdown (int sig);
1025
1026 /* constants for text rendering */
1027 #define NS_DUMPGLYPH_NORMAL 0
1028 #define NS_DUMPGLYPH_CURSOR 1
1029 #define NS_DUMPGLYPH_FOREGROUND 2
1030 #define NS_DUMPGLYPH_MOUSEFACE 3
1031
1032
1033
1034 /* In nsfont, called from fontset.c */
1035 extern void nsfont_make_fontset_for_font (Lisp_Object name,
1036 Lisp_Object font_object);
1037
1038 /* In nsfont, for debugging */
1039 struct glyph_string;
1040 void ns_dump_glyphstring (struct glyph_string *s);
1041
1042 /* Implemented in nsterm, published in or needed from nsfns. */
1043 extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern,
1044 int size, int maxnames);
1045 extern void ns_clear_frame (struct frame *f);
1046
1047 extern const char *ns_xlfd_to_fontname (const char *xlfd);
1048
1049 extern Lisp_Object ns_map_event_to_object (void);
1050 #ifdef __OBJC__
1051 extern Lisp_Object ns_string_from_pasteboard (id pb);
1052 extern void ns_string_to_pasteboard (id pb, Lisp_Object str);
1053 #endif
1054 extern Lisp_Object ns_get_local_selection (Lisp_Object selection_name,
1055 Lisp_Object target_type);
1056 extern void nxatoms_of_nsselect (void);
1057 extern int ns_lisp_to_cursor_type (Lisp_Object arg);
1058 extern Lisp_Object ns_cursor_type_to_lisp (int arg);
1059 extern void ns_set_name_as_filename (struct frame *f);
1060 extern void ns_set_doc_edited (void);
1061
1062 extern bool
1063 ns_defined_color (struct frame *f,
1064 const char *name,
1065 XColor *color_def, bool alloc,
1066 bool makeIndex);
1067 extern void
1068 ns_query_color (void *col, XColor *color_def, int setPixel);
1069
1070 #ifdef __OBJC__
1071 extern Lisp_Object ns_color_to_lisp (NSColor *col);
1072 extern int ns_lisp_to_color (Lisp_Object color, NSColor **col);
1073 extern NSColor *ns_lookup_indexed_color (unsigned long idx, struct frame *f);
1074 extern unsigned long ns_index_color (NSColor *color, struct frame *f);
1075 extern void ns_free_indexed_color (unsigned long idx, struct frame *f);
1076 extern const char *ns_get_pending_menu_title (void);
1077 extern void ns_check_menu_open (NSMenu *menu);
1078 extern void ns_check_pending_open_menu (void);
1079 #endif
1080
1081 /* C access to ObjC functionality */
1082 extern void ns_release_object (void *obj);
1083 extern void ns_retain_object (void *obj);
1084 extern void *ns_alloc_autorelease_pool (void);
1085 extern void ns_release_autorelease_pool (void *);
1086 extern const char *ns_get_defaults_value (const char *key);
1087
1088 /* in nsmenu */
1089 extern void update_frame_tool_bar (struct frame *f);
1090 extern void free_frame_tool_bar (struct frame *f);
1091 extern void find_and_call_menu_selection (struct frame *f,
1092 int menu_bar_items_used, Lisp_Object vector, void *client_data);
1093 extern Lisp_Object find_and_return_menu_selection (struct frame *f,
1094 bool keymaps,
1095 void *client_data);
1096 extern Lisp_Object ns_popup_dialog (struct frame *, Lisp_Object header,
1097 Lisp_Object contents);
1098
1099 #define NSAPP_DATA2_RUNASSCRIPT 10
1100 extern void ns_run_ascript (void);
1101
1102 #define NSAPP_DATA2_RUNFILEDIALOG 11
1103 extern void ns_run_file_dialog (void);
1104
1105 extern const char *ns_etc_directory (void);
1106 extern const char *ns_exec_path (void);
1107 extern const char *ns_load_path (void);
1108 extern void syms_of_nsterm (void);
1109 extern void syms_of_nsfns (void);
1110 extern void syms_of_nsmenu (void);
1111 extern void syms_of_nsselect (void);
1112
1113 /* From nsimage.m, needed in image.c */
1114 struct image;
1115 extern void *ns_image_from_XBM (unsigned char *bits, int width, int height,
1116 unsigned long fg, unsigned long bg);
1117 extern void *ns_image_for_XPM (int width, int height, int depth);
1118 extern void *ns_image_from_file (Lisp_Object file);
1119 extern bool ns_load_image (struct frame *f, struct image *img,
1120 Lisp_Object spec_file, Lisp_Object spec_data);
1121 extern int ns_image_width (void *img);
1122 extern int ns_image_height (void *img);
1123 extern unsigned long ns_get_pixel (void *img, int x, int y);
1124 extern void ns_put_pixel (void *img, int x, int y, unsigned long argb);
1125 extern void ns_set_alpha (void *img, int x, int y, unsigned char a);
1126
1127 extern int x_display_pixel_height (struct ns_display_info *);
1128 extern int x_display_pixel_width (struct ns_display_info *);
1129
1130 /* This in nsterm.m */
1131 extern void x_destroy_window (struct frame *f);
1132 extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds,
1133 fd_set *exceptfds, struct timespec const *timeout,
1134 sigset_t const *sigmask);
1135 extern unsigned long ns_get_rgb_color (struct frame *f,
1136 float r, float g, float b, float a);
1137
1138 extern void ns_init_events ();
1139 extern void ns_finish_events ();
1140
1141 #ifdef __OBJC__
1142 /* From nsterm.m, needed in nsfont.m. */
1143 extern void
1144 ns_draw_text_decoration (struct glyph_string *s, struct face *face,
1145 NSColor *defaultCol, CGFloat width, CGFloat x);
1146 /* Needed in nsfns.m. */
1147 extern void
1148 ns_set_represented_filename (NSString* fstr, struct frame *f);
1149
1150 #endif
1151
1152 #ifdef NS_IMPL_GNUSTEP
1153 extern char gnustep_base_version[]; /* version tracking */
1154 #endif
1155
1156 #define MINWIDTH 10
1157 #define MINHEIGHT 10
1158
1159 /* Screen max coordinate
1160 Using larger coordinates causes movewindow/placewindow to abort */
1161 #define SCREENMAX 16000
1162
1163 #define NS_SCROLL_BAR_WIDTH_DEFAULT [EmacsScroller scrollerWidth]
1164 #define NS_SCROLL_BAR_HEIGHT_DEFAULT [EmacsScroller scrollerHeight]
1165 /* This is to match emacs on other platforms, ugly though it is. */
1166 #define NS_SELECTION_BG_COLOR_DEFAULT @"LightGoldenrod2";
1167 #define NS_SELECTION_FG_COLOR_DEFAULT @"Black";
1168 #define RESIZE_HANDLE_SIZE 12
1169
1170 /* Little utility macros */
1171 #define IN_BOUND(min, x, max) (((x) < (min)) \
1172 ? (min) : (((x)>(max)) ? (max) : (x)))
1173 #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
1174
1175 #endif /* HAVE_NS */