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