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