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