image.c, indent.c: Use bool for booleans.
[bpt/emacs.git] / src / nsterm.h
1 /* Definitions and headers for communication with NeXT/Open/GNUstep API.
2 Copyright (C) 1989, 1993, 2005, 2008-2012 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19
20 #include "dispextern.h"
21 #include "frame.h"
22 #include "character.h"
23 #include "font.h"
24 #include "sysselect.h"
25
26 #ifdef HAVE_NS
27
28 #ifdef NS_IMPL_COCOA
29 #ifndef MAC_OS_X_VERSION_10_3
30 #define MAC_OS_X_VERSION_10_3 1030
31 #endif
32 #ifndef MAC_OS_X_VERSION_10_4
33 #define MAC_OS_X_VERSION_10_4 1040
34 #endif
35 #ifndef MAC_OS_X_VERSION_10_5
36 #define MAC_OS_X_VERSION_10_5 1050
37 #endif
38 #ifndef MAC_OS_X_VERSION_10_6
39 #define MAC_OS_X_VERSION_10_6 1060
40 #endif
41 #endif /* NS_IMPL_COCOA */
42
43 #ifdef __OBJC__
44
45 /* ==========================================================================
46
47 The Emacs application
48
49 ========================================================================== */
50
51 /* We override sendEvent: as a means to stop/start the event loop */
52 @interface EmacsApp : NSApplication
53 {
54 }
55 - (void)logNotification: (NSNotification *)notification;
56 - (void)sendEvent: (NSEvent *)theEvent;
57 - (void)showPreferencesWindow: (id)sender;
58 - (BOOL) openFile: (NSString *)fileName;
59 - (void)fd_handler: (id)unused;
60 - (void)timeout_handler: (NSTimer *)timedEntry;
61 - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg;
62 @end
63
64
65 /* ==========================================================================
66
67 The main Emacs view
68
69 ========================================================================== */
70
71 @class EmacsToolbar;
72
73 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
74 @interface EmacsView : NSView <NSTextInput, NSWindowDelegate>
75 #else
76 @interface EmacsView : NSView <NSTextInput>
77 #endif
78 {
79 char *old_title;
80 BOOL windowClosing;
81 NSString *workingText;
82 BOOL processingCompose;
83 @public
84 struct frame *emacsframe;
85 int rows, cols;
86 int scrollbarsNeedingUpdate;
87 EmacsToolbar *toolbar;
88 NSRect ns_userRect;
89 }
90
91 /* AppKit-side interface */
92 - menuDown: (id)sender;
93 - toolbarClicked: (id)item;
94 - toggleToolbar: (id)sender;
95 - (void)keyDown: (NSEvent *)theEvent;
96 - (void)mouseDown: (NSEvent *)theEvent;
97 - (void)mouseUp: (NSEvent *)theEvent;
98 - setMiniwindowImage: (BOOL)setMini;
99
100 /* Emacs-side interface */
101 - initFrameFromEmacs: (struct frame *) f;
102 - (void) setRows: (int) r andColumns: (int) c;
103 - (void) setWindowClosing: (BOOL)closing;
104 - (EmacsToolbar *) toolbar;
105 - (void) deleteWorkingText;
106 - (void) updateFrameSize: (BOOL) delay;
107
108 #ifdef NS_IMPL_GNUSTEP
109 /* Not declared, but useful. */
110 - (void) unlockFocusNeedsFlush: (BOOL)needs;
111 #endif
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
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
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) */
142 - (NSString *)parseKeyEquiv: (const char *)key;
143 - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr;
144 - (void)fillWithWidgetValue: (void *)wvptr;
145 - (EmacsMenu *)addSubmenuWithTitle: (const char *)title forFrame: (struct frame *)f;
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
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
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
176 helpText: (const char *)help
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;
199 BOOL timer_fired, window_closed;
200 Lisp_Object dialog_return;
201 Lisp_Object *button_values;
202 }
203 - initFromContents: (Lisp_Object)menu isQuestion: (BOOL)isQ;
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;
208 - (Lisp_Object)runDialogAt: (NSPoint)p;
209 - (void)timeout_handler: (NSTimer *)timedEntry;
210 @end
211
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
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
359 extern NSArray *ns_send_types, *ns_return_types;
360 extern NSString *ns_app_name;
361 extern EmacsMenu *mainMenu, *svcsMenu, *dockMenu;
362
363 /* Apple removed the declaration, but kept the implementation */
364 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
365 @interface NSApplication (EmacsApp)
366 - (void)setAppleMenu: (NSMenu *)menu;
367 @end
368 #endif
369
370 #ifndef NS_HAVE_NSINTEGER
371 #if defined (__LP64__) && __LP64__
372 typedef double CGFloat;
373 typedef long NSInteger;
374 typedef unsigned long NSUInteger;
375 #else
376 typedef float CGFloat;
377 typedef int NSInteger;
378 typedef unsigned int NSUInteger;
379 #endif /* not LP64 */
380 #endif /* not NS_HAVE_NSINTEGER */
381
382 #endif /* __OBJC__ */
383
384
385
386 /* ==========================================================================
387
388 Non-OO stuff
389
390 ========================================================================== */
391
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)
406 #define KEY_NS_SHOW_PREFS ((1<<28)|(0<<16)|14)
407
408 /* could use list to store these, but rest of emacs has a big infrastructure
409 for managing a table of bitmap "records" */
410 struct 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 */
423 struct ns_color_table
424 {
425 ptrdiff_t size;
426 ptrdiff_t avail;
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 */
452 struct nsfont_info
453 {
454 struct font font;
455
456 char *name; /* PostScript name, uniquely identifies on NS systems */
457
458 /* The following metrics are stored as float rather than int. */
459
460 float width; /* Maximum advance for the font. */
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;
479 XCharStruct max_bounds;
480 /* we compute glyph codes and metrics on-demand in blocks of 256 indexed
481 by hibyte, lobyte */
482 unsigned short **glyphs; /* map Unicode index to glyph */
483 struct font_metrics **metrics;
484 };
485
486
487 /* init'd in ns_initialize_display_info () */
488 struct 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
509 struct ns_bitmap_record *bitmaps;
510 ptrdiff_t bitmaps_size;
511 ptrdiff_t bitmaps_last;
512
513 struct image_cache *image_cache;
514
515 struct ns_color_table *color_table;
516
517 /* DPI resolution of this screen */
518 double resx, resy;
519
520 /* Mask of things that cause the mouse to be grabbed */
521 int grabbed;
522
523 int n_planes;
524
525 int color_p;
526
527 Window root_window;
528
529 /* Xism */
530 XrmDatabase xrdb;
531
532 /* The cursor to use for vertical scroll bars. */
533 Cursor vertical_scroll_bar_cursor;
534
535 /* Information about the range of text currently shown in
536 mouse-face. */
537 Mouse_HLInfo mouse_highlight;
538
539 struct frame *x_highlight_frame;
540 struct frame *x_focus_frame;
541 };
542
543 /* This is a chain of structures for all the NS displays currently in use. */
544 extern struct ns_display_info *x_display_list;
545
546 extern Lisp_Object ns_display_name_list;
547 extern struct ns_display_info *ns_display_info_for_name (Lisp_Object name);
548
549 struct ns_display_info *check_x_display_info (Lisp_Object frame);
550 FRAME_PTR check_x_frame (Lisp_Object frame);
551
552
553 struct ns_output
554 {
555 #ifdef __OBJC__
556 EmacsView *view;
557 id miniimage;
558 NSColor *cursor_color;
559 NSColor *foreground_color;
560 NSColor *background_color;
561 EmacsToolbar *toolbar;
562 #else
563 void *view;
564 void *miniimage;
565 void *cursor_color;
566 void *foreground_color;
567 void *background_color;
568 void *toolbar;
569 #endif
570
571 /* NSCursors init'ed in initFrameFromEmacs */
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
579 /* NS-specific */
580 Cursor current_pointer;
581
582 /* lord knows why Emacs needs to know about our Window ids.. */
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;
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;
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;
614 };
615
616 /* this dummy decl needed to support TTYs */
617 struct 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)
635 #define FRAME_X_SCREEN(f) (0)
636 #define FRAME_X_VISUAL(f) FRAME_NS_DISPLAY_INFO(f)->visual
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)
646 #define FRAME_TOOLBAR_HEIGHT(f) ((f)->output_data.ns->toolbar_height)
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)
658 #define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
659 #define FRAME_POINTER_TYPE(f) ((f)->output_data.ns->current_pointer)
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
684 /* XXX: fix for GNUstep inconsistent accounting for titlebar */
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
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
711 extern struct ns_display_info *ns_term_init (Lisp_Object display_name);
712 extern 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
721
722 /* In nsfont, called from fontset.c */
723 extern void nsfont_make_fontset_for_font (Lisp_Object name,
724 Lisp_Object font_object);
725
726 /* In nsfont, for debugging */
727 struct glyph_string;
728 void ns_dump_glyphstring (struct glyph_string *s);
729
730 /* Implemented in nsterm, published in or needed from nsfns. */
731 extern Lisp_Object Qfontsize;
732 extern Lisp_Object ns_list_fonts (FRAME_PTR f, Lisp_Object pattern,
733 int size, int maxnames);
734 extern void ns_clear_frame (struct frame *f);
735
736 extern const char *ns_xlfd_to_fontname (const char *xlfd);
737
738 extern void check_ns (void);
739 extern Lisp_Object ns_map_event_to_object (void);
740 #ifdef __OBJC__
741 extern Lisp_Object ns_string_from_pasteboard (id pb);
742 extern void ns_string_to_pasteboard (id pb, Lisp_Object str);
743 #endif
744 extern Lisp_Object ns_get_local_selection (Lisp_Object selection_name,
745 Lisp_Object target_type);
746 extern void nxatoms_of_nsselect (void);
747 extern int ns_lisp_to_cursor_type (Lisp_Object arg);
748 extern Lisp_Object ns_cursor_type_to_lisp (int arg);
749 extern void ns_set_name_as_filename (struct frame *f);
750 extern void ns_set_doc_edited (struct frame *f, Lisp_Object arg);
751
752 extern bool
753 ns_defined_color (struct frame *f,
754 const char *name,
755 XColor *color_def, bool alloc,
756 bool makeIndex);
757 extern void
758 ns_query_color (void *col, XColor *color_def, int setPixel);
759
760 #ifdef __OBJC__
761 extern Lisp_Object ns_color_to_lisp (NSColor *col);
762 extern int ns_lisp_to_color (Lisp_Object color, NSColor **col);
763 extern NSColor *ns_lookup_indexed_color (unsigned long idx, struct frame *f);
764 extern unsigned long ns_index_color (NSColor *color, struct frame *f);
765 extern void ns_free_indexed_color (unsigned long idx, struct frame *f);
766 #endif
767
768 /* C access to ObjC functionality */
769 extern void ns_release_object (void *obj);
770 extern void ns_retain_object (void *obj);
771 extern void *ns_alloc_autorelease_pool (void);
772 extern void ns_release_autorelease_pool (void *);
773 extern const char *ns_get_defaults_value (const char *key);
774
775 /* in nsmenu */
776 extern void update_frame_tool_bar (FRAME_PTR f);
777 extern void free_frame_tool_bar (FRAME_PTR f);
778 extern void find_and_call_menu_selection (FRAME_PTR f,
779 int menu_bar_items_used, Lisp_Object vector, void *client_data);
780 extern Lisp_Object find_and_return_menu_selection (FRAME_PTR f,
781 int keymaps,
782 void *client_data);
783 extern Lisp_Object ns_popup_dialog (Lisp_Object position, Lisp_Object contents,
784 Lisp_Object header);
785
786 #define NSAPP_DATA2_RUNASSCRIPT 10
787 extern void ns_run_ascript (void);
788
789 extern const char *ns_etc_directory (void);
790 extern const char *ns_exec_path (void);
791 extern const char *ns_load_path (void);
792 extern void syms_of_nsterm (void);
793 extern void syms_of_nsfns (void);
794 extern void syms_of_nsmenu (void);
795 extern void syms_of_nsselect (void);
796
797 /* From nsimage.m, needed in image.c */
798 struct image;
799 extern void *ns_image_from_XBM (unsigned char *bits, int width, int height);
800 extern void *ns_image_for_XPM (int width, int height, int depth);
801 extern void *ns_image_from_file (Lisp_Object file);
802 extern bool ns_load_image (struct frame *f, struct image *img,
803 Lisp_Object spec_file, Lisp_Object spec_data);
804 extern int ns_image_width (void *img);
805 extern int ns_image_height (void *img);
806 extern unsigned long ns_get_pixel (void *img, int x, int y);
807 extern void ns_put_pixel (void *img, int x, int y, unsigned long argb);
808 extern void ns_set_alpha (void *img, int x, int y, unsigned char a);
809
810 extern int x_display_pixel_height (struct ns_display_info *);
811 extern int x_display_pixel_width (struct ns_display_info *);
812
813 /* This in nsterm.m */
814 extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds,
815 fd_set *exceptfds, EMACS_TIME *timeout,
816 sigset_t *sigmask);
817 extern unsigned long ns_get_rgb_color (struct frame *f,
818 float r, float g, float b, float a);
819 extern NSPoint last_mouse_motion_position;
820
821 /* From nsterm.m, needed in nsfont.m. */
822 #ifdef __OBJC__
823 extern void
824 ns_draw_text_decoration (struct glyph_string *s, struct face *face,
825 NSColor *defaultCol, CGFloat width, CGFloat x);
826 #endif
827
828 #ifdef NS_IMPL_GNUSTEP
829 extern char gnustep_base_version[]; /* version tracking */
830 #endif
831
832 #define MINWIDTH 10
833 #define MINHEIGHT 10
834
835 /* Screen max coordinate
836 Using larger coordinates causes movewindow/placewindow to abort */
837 #define SCREENMAX 16000
838
839 #define NS_SCROLL_BAR_WIDTH_DEFAULT [EmacsScroller scrollerWidth]
840 /* This is to match emacs on other platforms, ugly though it is. */
841 #define NS_SELECTION_COLOR_DEFAULT @"LightGoldenrod2";
842 #define RESIZE_HANDLE_SIZE 12
843
844 /* Little utility macros */
845 #define IN_BOUND(min, x, max) (((x) < (min)) \
846 ? (min) : (((x)>(max)) ? (max) : (x)))
847 #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
848
849 /* needed somewhere... */
850 #define VERTICAL_SCROLL_BAR_WIDTH_TRIM (0)
851
852
853 #endif /* HAVE_NS */