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