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