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