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