Support resizing frames and windows pixelwise.
[bpt/emacs.git] / src / nsterm.h
1 /* Definitions and headers for communication with NeXT/Open/GNUstep API.
2 Copyright (C) 1989, 1993, 2005, 2008-2013 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_4
31 #define MAC_OS_X_VERSION_10_4 1040
32 #endif
33 #ifndef MAC_OS_X_VERSION_10_5
34 #define MAC_OS_X_VERSION_10_5 1050
35 #endif
36 #ifndef MAC_OS_X_VERSION_10_6
37 #define MAC_OS_X_VERSION_10_6 1060
38 #endif
39 #ifndef MAC_OS_X_VERSION_10_7
40 #define MAC_OS_X_VERSION_10_7 1070
41 #endif
42 #ifndef MAC_OS_X_VERSION_10_8
43 #define MAC_OS_X_VERSION_10_8 1080
44 #endif
45
46 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
47 #define HAVE_NATIVE_FS
48 #endif
49
50 #endif /* NS_IMPL_COCOA */
51
52 #ifdef __OBJC__
53
54 /* CGFloat on GNUStep may be 4 or 8 byte, but functions expect float* for some
55 versions.
56 On Cocoa >= 10.5, functions expect CGFloat*. Make compatible type. */
57 #ifdef NS_IMPL_COCOA
58
59 #ifndef NS_HAVE_NSINTEGER
60 #if defined (__LP64__) && __LP64__
61 typedef double CGFloat;
62 typedef long NSInteger;
63 typedef unsigned long NSUInteger;
64 #else
65 typedef float CGFloat;
66 typedef int NSInteger;
67 typedef unsigned int NSUInteger;
68 #endif /* not LP64 */
69 #endif /* not NS_HAVE_NSINTEGER */
70
71 typedef CGFloat EmacsCGFloat;
72
73 #elif GNUSTEP_GUI_MAJOR_VERSION > 0 || GNUSTEP_GUI_MINOR_VERSION >= 22
74 typedef CGFloat EmacsCGFloat;
75 #else
76 typedef float EmacsCGFloat;
77 #endif
78
79 /* ==========================================================================
80
81 The Emacs application
82
83 ========================================================================== */
84
85 /* We override sendEvent: as a means to stop/start the event loop */
86 @interface EmacsApp : NSApplication
87 {
88 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9
89 BOOL shouldKeepRunning;
90 BOOL isFirst;
91 #endif
92 #ifdef NS_IMPL_GNUSTEP
93 @public
94 int nextappdefined;
95 #endif
96 }
97 - (void)logNotification: (NSNotification *)notification;
98 - (void)sendEvent: (NSEvent *)theEvent;
99 - (void)showPreferencesWindow: (id)sender;
100 - (BOOL) openFile: (NSString *)fileName;
101 - (void)fd_handler: (id)unused;
102 - (void)timeout_handler: (NSTimer *)timedEntry;
103 - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg;
104 #ifdef NS_IMPL_GNUSTEP
105 - (void)sendFromMainThread:(id)unused;
106 #endif
107 @end
108
109 #ifdef NS_IMPL_GNUSTEP
110 /* Dummy class to get rid of startup warnings. */
111 @interface EmacsDocument : NSDocument
112 {
113 }
114 @end
115 #endif
116
117 /* ==========================================================================
118
119 The main Emacs view
120
121 ========================================================================== */
122
123 @class EmacsToolbar;
124
125 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
126 @interface EmacsView : NSView <NSTextInput, NSWindowDelegate>
127 #else
128 @interface EmacsView : NSView <NSTextInput>
129 #endif
130 {
131 #ifdef NS_IMPL_COCOA
132 char *old_title;
133 BOOL maximizing_resize;
134 #endif
135 BOOL windowClosing;
136 NSString *workingText;
137 BOOL processingCompose;
138 int fs_state, fs_before_fs, next_maximized;
139 int tibar_height, tobar_height, bwidth;
140 int maximized_width, maximized_height;
141 NSWindow *nonfs_window;
142 BOOL fs_is_native;
143 @public
144 struct frame *emacsframe;
145 int rows, cols;
146 int scrollbarsNeedingUpdate;
147 EmacsToolbar *toolbar;
148 NSRect ns_userRect;
149 }
150
151 /* AppKit-side interface */
152 - menuDown: (id)sender;
153 - toolbarClicked: (id)item;
154 - toggleToolbar: (id)sender;
155 - (void)keyDown: (NSEvent *)theEvent;
156 - (void)mouseDown: (NSEvent *)theEvent;
157 - (void)mouseUp: (NSEvent *)theEvent;
158 - setMiniwindowImage: (BOOL)setMini;
159
160 /* Emacs-side interface */
161 - initFrameFromEmacs: (struct frame *) f;
162 - (void) setRows: (int) r andColumns: (int) c;
163 - (void) setWindowClosing: (BOOL)closing;
164 - (EmacsToolbar *) toolbar;
165 - (void) deleteWorkingText;
166 - (void) updateFrameSize: (BOOL) delay;
167 - (void) handleFS;
168 - (void) setFSValue: (int)value;
169 - (void) toggleFullScreen: (id) sender;
170 - (BOOL) fsIsNative;
171 - (BOOL) isFullscreen;
172 #ifdef HAVE_NATIVE_FS
173 - (void) updateCollectionBehaviour;
174 #endif
175
176 #ifdef NS_IMPL_GNUSTEP
177 - (void)windowDidMove: (id)sender;
178 #endif
179 @end
180
181
182 /* Small utility used for processing resize events under Cocoa. */
183 @interface EmacsWindow : NSWindow
184 {
185 NSPoint grabOffset;
186 }
187 @end
188
189
190 /* Fullscreen version of the above. */
191 @interface EmacsFSWindow : EmacsWindow
192 {
193 }
194 @end
195
196 /* ==========================================================================
197
198 The main menu implementation
199
200 ========================================================================== */
201
202 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
203 @interface EmacsMenu : NSMenu <NSMenuDelegate>
204 #else
205 @interface EmacsMenu : NSMenu
206 #endif
207 {
208 struct frame *frame;
209 unsigned long keyEquivModMask;
210 }
211
212 - initWithTitle: (NSString *)title frame: (struct frame *)f;
213 - (void)setFrame: (struct frame *)f;
214 - (void)menuNeedsUpdate: (NSMenu *)menu; /* (delegate method) */
215 - (NSString *)parseKeyEquiv: (const char *)key;
216 - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr;
217 - (void)fillWithWidgetValue: (void *)wvptr;
218 - (void)fillWithWidgetValue: (void *)wvptr frame: (struct frame *)f;
219 - (EmacsMenu *)addSubmenuWithTitle: (const char *)title forFrame: (struct frame *)f;
220 - (void) clear;
221 - (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f
222 keymaps: (bool)keymaps;
223 @end
224
225
226 /* ==========================================================================
227
228 Toolbar
229
230 ========================================================================== */
231
232 @class EmacsImage;
233
234 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
235 @interface EmacsToolbar : NSToolbar <NSToolbarDelegate>
236 #else
237 @interface EmacsToolbar : NSToolbar
238 #endif
239 {
240 EmacsView *emacsView;
241 NSMutableDictionary *identifierToItem;
242 NSMutableArray *activeIdentifiers;
243 NSArray *prevIdentifiers;
244 unsigned long enablement, prevEnablement;
245 }
246 - initForView: (EmacsView *)view withIdentifier: (NSString *)identifier;
247 - (void) clearActive;
248 - (void) clearAll;
249 - (BOOL) changed;
250 - (void) addDisplayItemWithImage: (EmacsImage *)img
251 idx: (int)idx
252 tag: (int)tag
253 helpText: (const char *)help
254 enabled: (BOOL)enabled;
255
256 /* delegate methods */
257 - (NSToolbarItem *)toolbar: (NSToolbar *)toolbar
258 itemForItemIdentifier: (NSString *)itemIdentifier
259 willBeInsertedIntoToolbar: (BOOL)flag;
260 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar;
261 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar;
262 @end
263
264
265 /* ==========================================================================
266
267 Message / question windows
268
269 ========================================================================== */
270
271 @interface EmacsDialogPanel : NSPanel
272 {
273 NSTextField *command;
274 NSTextField *title;
275 NSMatrix *matrix;
276 int rows, cols;
277 BOOL timer_fired, window_closed;
278 Lisp_Object dialog_return;
279 Lisp_Object *button_values;
280 }
281 - initFromContents: (Lisp_Object)menu isQuestion: (BOOL)isQ;
282 - (void)process_dialog: (Lisp_Object)list;
283 - (void)addButton: (char *)str value: (int)tag row: (int)row;
284 - (void)addString: (char *)str row: (int)row;
285 - (void)addSplit;
286 - (Lisp_Object)runDialogAt: (NSPoint)p;
287 - (void)timeout_handler: (NSTimer *)timedEntry;
288 @end
289
290 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
291 @interface EmacsTooltip : NSObject <NSWindowDelegate>
292 #else
293 @interface EmacsTooltip : NSObject
294 #endif
295 {
296 NSWindow *win;
297 NSTextField *textField;
298 NSTimer *timer;
299 }
300 - init;
301 - (void) setText: (char *)text;
302 - (void) showAtX: (int)x Y: (int)y for: (int)seconds;
303 - (void) hide;
304 - (BOOL) isActive;
305 - (NSRect) frame;
306 @end
307
308
309 /* ==========================================================================
310
311 File open/save panels
312 This and next override methods to handle keyboard input in panels.
313
314 ========================================================================== */
315
316 @interface EmacsSavePanel : NSSavePanel
317 {
318 }
319 @end
320 @interface EmacsOpenPanel : NSOpenPanel
321 {
322 }
323 @end
324
325 @interface EmacsFileDelegate : NSObject
326 {
327 }
328 - (BOOL)panel: (id)sender isValidFilename: (NSString *)filename;
329 - (BOOL)panel: (id)sender shouldShowFilename: (NSString *)filename;
330 - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
331 confirmed: (BOOL)okFlag;
332 @end
333
334
335 /* ==========================================================================
336
337 Images and stippling
338
339 ========================================================================== */
340
341 @interface EmacsImage : NSImage
342 {
343 id imageListNext;
344 int refCount;
345 NSBitmapImageRep *bmRep; /* used for accessing pixel data */
346 unsigned char *pixmapData[5]; /* shortcut to access pixel data */
347 NSColor *stippleMask;
348 }
349 + allocInitFromFile: (Lisp_Object)file;
350 - reference;
351 - imageListSetNext: (id)arg;
352 - imageListNext;
353 - (void)dealloc;
354 - initFromXBM: (unsigned char *)bits width: (int)w height: (int)h
355 flip: (BOOL)flip;
356 - initFromSkipXBM: (unsigned char *)bits width: (int)w height: (int)h
357 flip: (BOOL)flip length: (int)length;
358 - setXBMColor: (NSColor *)color;
359 - initForXPMWithDepth: (int)depth width: (int)width height: (int)height;
360 - (void)setPixmapData;
361 - (unsigned long)getPixelAtX: (int)x Y: (int)y;
362 - (void)setPixelAtX: (int)x Y: (int)y toRed: (unsigned char)r
363 green: (unsigned char)g blue: (unsigned char)b
364 alpha:(unsigned char)a;
365 - (void)setAlphaAtX: (int)x Y: (int)y to: (unsigned char)a;
366 - (NSColor *)stippleMask;
367 @end
368
369
370 /* ==========================================================================
371
372 Scrollbars
373
374 ========================================================================== */
375
376 @interface EmacsScroller : NSScroller
377 {
378 Lisp_Object win;
379 struct frame *frame;
380 NSResponder *prevResponder;
381
382 /* offset to the bottom of knob of last mouse down */
383 CGFloat last_mouse_offset;
384 float min_portion;
385 int pixel_height;
386 int last_hit_part;
387
388 BOOL condemned;
389
390 /* optimize against excessive positioning calls generated by emacs */
391 int em_position;
392 int em_portion;
393 int em_whole;
394 }
395
396 - initFrame: (NSRect )r window: (Lisp_Object)win;
397 - (void)setFrame: (NSRect)r;
398 - (void)dealloc;
399
400 - setPosition: (int) position portion: (int) portion whole: (int) whole;
401 - (int) checkSamePosition: (int)position portion: (int)portion
402 whole: (int)whole;
403 - (void) getMouseMotionPart: (int *)part window: (Lisp_Object *)window
404 x: (Lisp_Object *)x y: ( Lisp_Object *)y;
405 - (void) sendScrollEventAtLoc: (float)loc fromEvent: (NSEvent *)e;
406 - repeatScroll: (NSTimer *)sender;
407 - condemn;
408 - reprieve;
409 - judge;
410 @end
411
412
413 /* ==========================================================================
414
415 Rendering
416
417 ========================================================================== */
418
419 #ifdef NS_IMPL_COCOA
420 /* rendering util */
421 @interface EmacsGlyphStorage : NSObject <NSGlyphStorage>
422 {
423 @public
424 NSAttributedString *attrStr;
425 NSMutableDictionary *dict;
426 CGGlyph *cglyphs;
427 unsigned long maxChar, maxGlyph;
428 long i, len;
429 }
430 - initWithCapacity: (unsigned long) c;
431 - (void) setString: (NSString *)str font: (NSFont *)font;
432 @end
433 #endif /* NS_IMPL_COCOA */
434
435 extern NSArray *ns_send_types, *ns_return_types;
436 extern NSString *ns_app_name;
437 extern EmacsMenu *mainMenu, *svcsMenu, *dockMenu;
438
439 /* Apple removed the declaration, but kept the implementation */
440 #if defined (NS_IMPL_COCOA)
441 @interface NSApplication (EmacsApp)
442 - (void)setAppleMenu: (NSMenu *)menu;
443 @end
444 #endif
445
446 #endif /* __OBJC__ */
447
448
449
450 /* ==========================================================================
451
452 Non-OO stuff
453
454 ========================================================================== */
455
456 /* Special keycodes that we pass down the event chain */
457 #define KEY_NS_POWER_OFF ((1<<28)|(0<<16)|1)
458 #define KEY_NS_OPEN_FILE ((1<<28)|(0<<16)|2)
459 #define KEY_NS_OPEN_TEMP_FILE ((1<<28)|(0<<16)|3)
460 #define KEY_NS_DRAG_FILE ((1<<28)|(0<<16)|4)
461 #define KEY_NS_DRAG_COLOR ((1<<28)|(0<<16)|5)
462 #define KEY_NS_DRAG_TEXT ((1<<28)|(0<<16)|6)
463 #define KEY_NS_CHANGE_FONT ((1<<28)|(0<<16)|7)
464 #define KEY_NS_OPEN_FILE_LINE ((1<<28)|(0<<16)|8)
465 #define KEY_NS_PUT_WORKING_TEXT ((1<<28)|(0<<16)|9)
466 #define KEY_NS_UNPUT_WORKING_TEXT ((1<<28)|(0<<16)|10)
467 #define KEY_NS_SPI_SERVICE_CALL ((1<<28)|(0<<16)|11)
468 #define KEY_NS_NEW_FRAME ((1<<28)|(0<<16)|12)
469 #define KEY_NS_TOGGLE_TOOLBAR ((1<<28)|(0<<16)|13)
470 #define KEY_NS_SHOW_PREFS ((1<<28)|(0<<16)|14)
471
472 /* could use list to store these, but rest of emacs has a big infrastructure
473 for managing a table of bitmap "records" */
474 struct ns_bitmap_record
475 {
476 #ifdef __OBJC__
477 EmacsImage *img;
478 #else
479 void *img;
480 #endif
481 char *file;
482 int refcount;
483 int height, width, depth;
484 };
485
486 /* this to map between emacs color indices and NSColor objects */
487 struct ns_color_table
488 {
489 ptrdiff_t size;
490 ptrdiff_t avail;
491 #ifdef __OBJC__
492 NSColor **colors;
493 NSMutableSet *empty_indices;
494 #else
495 void **items;
496 void *availIndices;
497 #endif
498 };
499 #define NS_COLOR_CAPACITY 256
500
501 #define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
502 #define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
503
504 #define ALPHA_FROM_ULONG(color) ((color) >> 24)
505 #define RED_FROM_ULONG(color) (((color) >> 16) & 0xff)
506 #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
507 #define BLUE_FROM_ULONG(color) ((color) & 0xff)
508
509 /* Do not change `* 0x101' in the following lines to `<< 8'. If
510 changed, image masks in 1-bit depth will not work. */
511 #define RED16_FROM_ULONG(color) (RED_FROM_ULONG(color) * 0x101)
512 #define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
513 #define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)
514
515 /* this extends font backend font */
516 struct nsfont_info
517 {
518 struct font font;
519
520 char *name; /* PostScript name, uniquely identifies on NS systems */
521
522 /* The following metrics are stored as float rather than int. */
523
524 float width; /* Maximum advance for the font. */
525 float height;
526 float underpos;
527 float underwidth;
528 float size;
529 #ifdef __OBJC__
530 NSFont *nsfont;
531 #if defined (NS_IMPL_COCOA)
532 CGFontRef cgfont;
533 #else /* GNUstep */
534 void *cgfont;
535 #endif
536 #else /* ! OBJC */
537 void *nsfont;
538 void *cgfont;
539 #endif
540 char bold, ital; /* convenience flags */
541 char synthItal;
542 XCharStruct max_bounds;
543 /* we compute glyph codes and metrics on-demand in blocks of 256 indexed
544 by hibyte, lobyte */
545 unsigned short **glyphs; /* map Unicode index to glyph */
546 struct font_metrics **metrics;
547 };
548
549
550 /* init'd in ns_initialize_display_info () */
551 struct ns_display_info
552 {
553 /* Chain of all ns_display_info structures. */
554 struct ns_display_info *next;
555
556 /* The generic display parameters corresponding to this NS display. */
557 struct terminal *terminal;
558
559 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). */
560 Lisp_Object name_list_element;
561
562 /* The number of fonts loaded. */
563 int n_fonts;
564
565 /* Minimum width over all characters in all fonts in font_table. */
566 int smallest_char_width;
567
568 /* Minimum font height over all fonts in font_table. */
569 int smallest_font_height;
570
571 struct ns_bitmap_record *bitmaps;
572 ptrdiff_t bitmaps_size;
573 ptrdiff_t bitmaps_last;
574
575 struct ns_color_table *color_table;
576
577 /* DPI resolution of this screen */
578 double resx, resy;
579
580 /* Mask of things that cause the mouse to be grabbed */
581 int grabbed;
582
583 int n_planes;
584
585 int color_p;
586
587 Window root_window;
588
589 /* Xism */
590 XrmDatabase xrdb;
591
592 /* The cursor to use for vertical scroll bars. */
593 Cursor vertical_scroll_bar_cursor;
594
595 /* Information about the range of text currently shown in
596 mouse-face. */
597 Mouse_HLInfo mouse_highlight;
598
599 struct frame *x_highlight_frame;
600 struct frame *x_focus_frame;
601
602 /* The frame where the mouse was last time we reported a mouse event. */
603 struct frame *last_mouse_frame;
604
605 /* The frame where the mouse was last time we reported a mouse motion. */
606 struct frame *last_mouse_motion_frame;
607
608 /* Position where the mouse was last time we reported a motion.
609 This is a position on last_mouse_motion_frame. */
610 int last_mouse_motion_x;
611 int last_mouse_motion_y;
612
613 /* Where the mouse was last time we reported a mouse position. */
614 NSRect last_mouse_glyph;
615
616 /* Time of last mouse movement. */
617 Time last_mouse_movement_time;
618
619 /* The scroll bar in which the last motion event occurred. */
620 #ifdef __OBJC__
621 EmacsScroller *last_mouse_scroll_bar;
622 #else
623 void *last_mouse_scroll_bar;
624 #endif
625 };
626
627 /* This is a chain of structures for all the NS displays currently in use. */
628 extern struct ns_display_info *x_display_list;
629
630 extern struct ns_display_info *ns_display_info_for_name (Lisp_Object name);
631
632 struct ns_output
633 {
634 #ifdef __OBJC__
635 EmacsView *view;
636 id miniimage;
637 NSColor *cursor_color;
638 NSColor *foreground_color;
639 NSColor *background_color;
640 EmacsToolbar *toolbar;
641 #else
642 void *view;
643 void *miniimage;
644 void *cursor_color;
645 void *foreground_color;
646 void *background_color;
647 void *toolbar;
648 #endif
649
650 /* NSCursors init'ed in initFrameFromEmacs */
651 Cursor text_cursor;
652 Cursor nontext_cursor;
653 Cursor modeline_cursor;
654 Cursor hand_cursor;
655 Cursor hourglass_cursor;
656 Cursor horizontal_drag_cursor;
657 Cursor vertical_drag_cursor;
658
659 /* NS-specific */
660 Cursor current_pointer;
661
662 /* lord knows why Emacs needs to know about our Window ids.. */
663 Window window_desc, parent_desc;
664 char explicit_parent;
665
666 struct font *font;
667 int baseline_offset;
668
669 /* If a fontset is specified for this frame instead of font, this
670 value contains an ID of the fontset, else -1. */
671 int fontset; /* only used with font_backend */
672
673 Lisp_Object icon_top;
674 Lisp_Object icon_left;
675
676 /* The size of the extra width currently allotted for vertical
677 scroll bars, in pixels. */
678 int vertical_scroll_bar_extra;
679
680 /* The height of the titlebar decoration (included in NSWindow's frame). */
681 int titlebar_height;
682
683 /* The height of the toolbar if displayed, else 0. */
684 int toolbar_height;
685
686 /* This is the Emacs structure for the NS display this frame is on. */
687 struct ns_display_info *display_info;
688
689 /* Non-zero if we want to constrain the frame to the screen. */
690 int dont_constrain;
691
692 /* Non-zero if we are zooming (maximizing) the frame. */
693 int zooming;
694 };
695
696 /* this dummy decl needed to support TTYs */
697 struct x_output
698 {
699 int unused;
700 };
701
702
703 /* This gives the ns_display_info structure for the display F is on. */
704 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.ns->display_info)
705 #define FRAME_X_OUTPUT(f) ((f)->output_data.ns)
706 #define FRAME_NS_WINDOW(f) ((f)->output_data.ns->window_desc)
707 #define FRAME_X_WINDOW(f) ((f)->output_data.ns->window_desc)
708
709 /* This is the `Display *' which frame F is on. */
710 #define FRAME_NS_DISPLAY(f) (0)
711 #define FRAME_X_DISPLAY(f) (0)
712 #define FRAME_X_SCREEN(f) (0)
713 #define FRAME_X_VISUAL(f) FRAME_DISPLAY_INFO(f)->visual
714
715 #define FRAME_FOREGROUND_COLOR(f) ((f)->output_data.ns->foreground_color)
716 #define FRAME_BACKGROUND_COLOR(f) ((f)->output_data.ns->background_color)
717
718 #define NS_FACE_FOREGROUND(f) ((f)->foreground)
719 #define NS_FACE_BACKGROUND(f) ((f)->background)
720 #define FRAME_NS_TITLEBAR_HEIGHT(f) ((f)->output_data.ns->titlebar_height)
721 #define FRAME_TOOLBAR_HEIGHT(f) ((f)->output_data.ns->toolbar_height)
722
723 #define FONT_WIDTH(f) ((f)->max_width)
724 #define FONT_HEIGHT(f) ((f)->height)
725 #define FONT_BASE(f) ((f)->ascent)
726 #define FONT_DESCENT(f) ((f)->descent)
727
728 #define FRAME_DEFAULT_FACE(f) FACE_FROM_ID (f, DEFAULT_FACE_ID)
729
730 #define FRAME_NS_VIEW(f) ((f)->output_data.ns->view)
731 #define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
732 #define FRAME_POINTER_TYPE(f) ((f)->output_data.ns->current_pointer)
733
734 #define FRAME_FONT(f) ((f)->output_data.ns->font)
735
736 #ifdef __OBJC__
737 #define XNS_SCROLL_BAR(vec) ((id) XSAVE_POINTER (vec, 0))
738 #else
739 #define XNS_SCROLL_BAR(vec) XSAVE_POINTER (vec, 0)
740 #endif
741
742 /* Compute pixel size for vertical scroll bars */
743 #define NS_SCROLL_BAR_WIDTH(f) \
744 (FRAME_HAS_VERTICAL_SCROLL_BARS (f) \
745 ? rint (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0 \
746 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f) \
747 : (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f))) \
748 : 0)
749
750 /* Difference btwn char-column-calculated and actual SB widths.
751 This is only a concern for rendering when SB on left. */
752 #define NS_SCROLL_BAR_ADJUST(w, f) \
753 (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) ? \
754 (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f) \
755 - NS_SCROLL_BAR_WIDTH (f)) : 0)
756
757 /* XXX: fix for GNUstep inconsistent accounting for titlebar */
758 #ifdef NS_IMPL_GNUSTEP
759 #define NS_TOP_POS(f) ((f)->top_pos + 18)
760 #else
761 #define NS_TOP_POS(f) ((f)->top_pos)
762 #endif
763
764 #define FRAME_NS_FONT_TABLE(f) (FRAME_DISPLAY_INFO (f)->font_table)
765
766 #define FRAME_FONTSET(f) ((f)->output_data.ns->fontset)
767
768 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.ns->baseline_offset)
769 #define BLACK_PIX_DEFAULT(f) 0x000000
770 #define WHITE_PIX_DEFAULT(f) 0xFFFFFF
771
772 /* First position where characters can be shown (instead of scrollbar, if
773 it is on left. */
774 #define FIRST_CHAR_POSITION(f) \
775 (! (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) ? 0 \
776 : FRAME_SCROLL_BAR_COLS (f))
777
778 extern struct ns_display_info *ns_term_init (Lisp_Object display_name);
779 extern void ns_term_shutdown (int sig);
780
781 /* constants for text rendering */
782 #define NS_DUMPGLYPH_NORMAL 0
783 #define NS_DUMPGLYPH_CURSOR 1
784 #define NS_DUMPGLYPH_FOREGROUND 2
785 #define NS_DUMPGLYPH_MOUSEFACE 3
786
787
788
789 /* In nsfont, called from fontset.c */
790 extern void nsfont_make_fontset_for_font (Lisp_Object name,
791 Lisp_Object font_object);
792
793 /* In nsfont, for debugging */
794 struct glyph_string;
795 void ns_dump_glyphstring (struct glyph_string *s);
796
797 /* Implemented in nsterm, published in or needed from nsfns. */
798 extern Lisp_Object Qfontsize;
799 extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern,
800 int size, int maxnames);
801 extern void ns_clear_frame (struct frame *f);
802
803 extern const char *ns_xlfd_to_fontname (const char *xlfd);
804
805 extern Lisp_Object ns_map_event_to_object (void);
806 #ifdef __OBJC__
807 extern Lisp_Object ns_string_from_pasteboard (id pb);
808 extern void ns_string_to_pasteboard (id pb, Lisp_Object str);
809 #endif
810 extern Lisp_Object ns_get_local_selection (Lisp_Object selection_name,
811 Lisp_Object target_type);
812 extern void nxatoms_of_nsselect (void);
813 extern int ns_lisp_to_cursor_type (Lisp_Object arg);
814 extern Lisp_Object ns_cursor_type_to_lisp (int arg);
815 extern void ns_set_name_as_filename (struct frame *f);
816 extern void ns_set_doc_edited (struct frame *f, Lisp_Object arg);
817
818 extern bool
819 ns_defined_color (struct frame *f,
820 const char *name,
821 XColor *color_def, bool alloc,
822 bool makeIndex);
823 extern void
824 ns_query_color (void *col, XColor *color_def, int setPixel);
825
826 #ifdef __OBJC__
827 extern Lisp_Object ns_color_to_lisp (NSColor *col);
828 extern int ns_lisp_to_color (Lisp_Object color, NSColor **col);
829 extern NSColor *ns_lookup_indexed_color (unsigned long idx, struct frame *f);
830 extern unsigned long ns_index_color (NSColor *color, struct frame *f);
831 extern void ns_free_indexed_color (unsigned long idx, struct frame *f);
832 extern const char *ns_get_pending_menu_title (void);
833 extern void ns_check_menu_open (NSMenu *menu);
834 extern void ns_check_pending_open_menu (void);
835 #endif
836
837 /* C access to ObjC functionality */
838 extern void ns_release_object (void *obj);
839 extern void ns_retain_object (void *obj);
840 extern void *ns_alloc_autorelease_pool (void);
841 extern void ns_release_autorelease_pool (void *);
842 extern const char *ns_get_defaults_value (const char *key);
843
844 /* in nsmenu */
845 extern void update_frame_tool_bar (struct frame *f);
846 extern void free_frame_tool_bar (struct frame *f);
847 extern void find_and_call_menu_selection (struct frame *f,
848 int menu_bar_items_used, Lisp_Object vector, void *client_data);
849 extern Lisp_Object find_and_return_menu_selection (struct frame *f,
850 bool keymaps,
851 void *client_data);
852 extern Lisp_Object ns_popup_dialog (Lisp_Object position, Lisp_Object header,
853 Lisp_Object contents);
854
855 #define NSAPP_DATA2_RUNASSCRIPT 10
856 extern void ns_run_ascript (void);
857
858 #define NSAPP_DATA2_RUNFILEDIALOG 11
859 extern void ns_run_file_dialog (void);
860
861 extern const char *ns_etc_directory (void);
862 extern const char *ns_exec_path (void);
863 extern const char *ns_load_path (void);
864 extern void syms_of_nsterm (void);
865 extern void syms_of_nsfns (void);
866 extern void syms_of_nsmenu (void);
867 extern void syms_of_nsselect (void);
868
869 /* From nsimage.m, needed in image.c */
870 struct image;
871 extern void *ns_image_from_XBM (unsigned char *bits, int width, int height);
872 extern void *ns_image_for_XPM (int width, int height, int depth);
873 extern void *ns_image_from_file (Lisp_Object file);
874 extern bool ns_load_image (struct frame *f, struct image *img,
875 Lisp_Object spec_file, Lisp_Object spec_data);
876 extern int ns_image_width (void *img);
877 extern int ns_image_height (void *img);
878 extern unsigned long ns_get_pixel (void *img, int x, int y);
879 extern void ns_put_pixel (void *img, int x, int y, unsigned long argb);
880 extern void ns_set_alpha (void *img, int x, int y, unsigned char a);
881
882 extern int x_display_pixel_height (struct ns_display_info *);
883 extern int x_display_pixel_width (struct ns_display_info *);
884
885 /* This in nsterm.m */
886 extern void x_destroy_window (struct frame *f);
887 extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds,
888 fd_set *exceptfds, struct timespec const *timeout,
889 sigset_t const *sigmask);
890 extern unsigned long ns_get_rgb_color (struct frame *f,
891 float r, float g, float b, float a);
892
893 /* From nsterm.m, needed in nsfont.m. */
894 #ifdef __OBJC__
895 extern void
896 ns_draw_text_decoration (struct glyph_string *s, struct face *face,
897 NSColor *defaultCol, CGFloat width, CGFloat x);
898 #endif
899
900 #ifdef NS_IMPL_GNUSTEP
901 extern char gnustep_base_version[]; /* version tracking */
902 #endif
903
904 #define MINWIDTH 10
905 #define MINHEIGHT 10
906
907 /* Screen max coordinate
908 Using larger coordinates causes movewindow/placewindow to abort */
909 #define SCREENMAX 16000
910
911 #define NS_SCROLL_BAR_WIDTH_DEFAULT [EmacsScroller scrollerWidth]
912 /* This is to match emacs on other platforms, ugly though it is. */
913 #define NS_SELECTION_BG_COLOR_DEFAULT @"LightGoldenrod2";
914 #define NS_SELECTION_FG_COLOR_DEFAULT @"Black";
915 #define RESIZE_HANDLE_SIZE 12
916
917 /* Little utility macros */
918 #define IN_BOUND(min, x, max) (((x) < (min)) \
919 ? (min) : (((x)>(max)) ? (max) : (x)))
920 #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
921
922 #endif /* HAVE_NS */