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