nsterm.h 44.6 KB
Newer Older
1
/* Definitions and headers for communication with NeXT/Open/GNUstep API.
2
   Copyright (C) 1989, 1993, 2005, 2008-2020 Free Software Foundation,
3
   Inc.
4 5 6

This file is part of GNU Emacs.

7
GNU Emacs is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9 10
the Free Software Foundation, either version 3 of the License, or (at
your option) any later version.
11 12 13 14 15 16 17

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
18
along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
19

20 21 22 23 24

#include "dispextern.h"
#include "frame.h"
#include "character.h"
#include "font.h"
25
#include "sysselect.h"
26
#include "sysstdio.h"
27 28 29 30

#ifdef HAVE_NS
#ifdef __OBJC__

Glenn Morris's avatar
Glenn Morris committed
31
/* CGFloat on GNUstep may be 4 or 8 byte, but functions expect float* for some
32
   versions.
33
   On Cocoa >= 10.5, functions expect CGFloat *.  Make compatible type.  */
34 35 36
#ifdef NS_IMPL_COCOA
typedef CGFloat EmacsCGFloat;
#elif GNUSTEP_GUI_MAJOR_VERSION > 0 || GNUSTEP_GUI_MINOR_VERSION >= 22
37 38 39 40 41
typedef CGFloat EmacsCGFloat;
#else
typedef float EmacsCGFloat;
#endif

42 43 44 45 46 47
/* ==========================================================================

   Trace support

   ========================================================================== */

48
/* Uncomment the following line to enable trace.
49

50 51
   Uncomment suitable NSTRACE_GROUP_xxx lines to trace more.

52 53 54 55
   Hint: keep the trailing whitespace -- the version control system
   will reject accidental commits. */

/* #define NSTRACE_ENABLED 1          */
56 57


Paul Eggert's avatar
Paul Eggert committed
58
/* When non-zero, trace output is enabled for all parts, except those
59 60 61 62 63 64 65 66 67 68 69 70
   explicitly disabled. */
/* #define NSTRACE_ALL_GROUPS     1     */

/* When non-zero, trace output is enabled in the corresponding part. */
/* #define NSTRACE_GROUP_EVENTS  1     */
/* #define NSTRACE_GROUP_UPDATES 1     */
/* #define NSTRACE_GROUP_FRINGE  1     */
/* #define NSTRACE_GROUP_COLOR   1     */
/* #define NSTRACE_GROUP_GLYPHS  1     */
/* #define NSTRACE_GROUP_FOCUS   1     */


71 72 73 74 75 76 77 78 79 80 81 82 83 84
/* Print a call tree containing all annotated functions.

   The call structure of the functions is represented using
   indentation and vertical lines.  Extra information is printed using
   horizontal lines that connect to the vertical line.

   The return value is represented using the arrow "->>".  For simple
   functions, the arrow can be printed on the same line as the
   function name.  If more output is printed, it is connected to the
   vertical line of the function.

   The first column contains the file name, the second the line
   number, and the third a number increasing for each trace line.

85 86 87 88
   Note, when trace output from several threads are mixed, the output
   can become misaligned, as all threads (currently) share one state.
   This is post prominent when the EVENTS part is enabled.

89
   Note that the trace system, when enabled, uses the GCC/Clang
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
   "cleanup" extension. */

/*   For example, the following is the output of `M-x
     toggle-frame-maximized RET'.

     (Long lines manually split to reduced width):

nsterm.m  : 1608: [  354]  ns_fullscreen_hook
nsterm.m  : 7180: [  355]  | [EmacsView handleFS]
nsterm.m  : 7209: [  356]  | +--- FULLSCREEN_MAXIMIZED
nsterm.m  : 7706: [  357]  | | [EmacsWindow performZoom:]
nsterm.m  : 7715: [  358]  | | | [EmacsWindow zoom:]
nsterm.m  :  882: [  359]  | | | | ns_update_auto_hide_menu_bar
nsterm.m  : 6752: [  360]  | | | |
  [EmacsView windowWillUseStandardFrame:defaultFrame:(X:0 Y:0)/(W:1600 H:1177)]
nsterm.m  : 6753: [  361]  | | | | +--- fs_state: FULLSCREEN_NONE
nsterm.m  : 6754: [  362]  | | | | +--- fs_before_fs: -1
nsterm.m  : 6755: [  363]  | | | | +--- next_maximized: FULLSCREEN_MAXIMIZED
nsterm.m  : 6756: [  364]  | | | | +--- ns_userRect: (X:0 Y:0)/(W:0 H:0)
nsterm.m  : 6757: [  365]  | | | | +---
                                      [sender frame]: (X:0 Y:626)/(W:595 H:551)
nsterm.m  : 6781: [  366]  | | | | +---
                                     ns_userRect (2): (X:0 Y:626)/(W:595 H:551)
nsterm.m  : 6821: [  367]  | | | | +--- FULLSCREEN_MAXIMIZED
nsterm.m  : 7232: [  368]  | | | | |
                                    [EmacsView setFSValue:FULLSCREEN_MAXIMIZED]
nsterm.m  : 6848: [  369]  | | | | +---
                                   Final ns_userRect: (X:0 Y:626)/(W:595 H:551)
nsterm.m  : 6849: [  370]  | | | | +--- Final maximized_width: 1600
nsterm.m  : 6850: [  371]  | | | | +--- Final maximized_height: 1177
nsterm.m  : 6851: [  372]  | | | | +--- Final next_maximized: -1
nsterm.m  : 6322: [  373]  | | | | |
                           [EmacsView windowWillResize:toSize: (W:1600 H:1177)]
nsterm.m  : 6323: [  374]  | | | | | +---
                                      [sender frame]: (X:0 Y:626)/(W:595 H:551)
nsterm.m  : 6324: [  375]  | | | | | +--- fs_state: FULLSCREEN_MAXIMIZED
nsterm.m  : 7027: [  376]  | | | | | | [EmacsView isFullscreen]
nsterm.m  : 6387: [  377]  | | | | | +--- cols: 223  rows: 79
nsterm.m  : 6412: [  378]  | | | | | +->> (W:1596 H:1167)
nsterm.m  : 6855: [  379]  | | | | +->> (X:0 Y:0)/(W:1600 H:1177)
*/
131 132 133 134 135 136

#ifndef NSTRACE_ENABLED
#define NSTRACE_ENABLED 0
#endif

#if NSTRACE_ENABLED
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168

#ifndef NSTRACE_ALL_GROUPS
#define NSTRACE_ALL_GROUPS 0
#endif

#ifndef NSTRACE_GROUP_EVENTS
#define NSTRACE_GROUP_EVENTS NSTRACE_ALL_GROUPS
#endif

#ifndef NSTRACE_GROUP_UPDATES
#define NSTRACE_GROUP_UPDATES NSTRACE_ALL_GROUPS
#endif

#ifndef NSTRACE_GROUP_FRINGE
#define NSTRACE_GROUP_FRINGE NSTRACE_ALL_GROUPS
#endif

#ifndef NSTRACE_GROUP_COLOR
#define NSTRACE_GROUP_COLOR NSTRACE_ALL_GROUPS
#endif

#ifndef NSTRACE_GROUP_GLYPHS
#define NSTRACE_GROUP_GLYPHS NSTRACE_ALL_GROUPS
#endif

#ifndef NSTRACE_GROUP_FOCUS
#define NSTRACE_GROUP_FOCUS NSTRACE_ALL_GROUPS
#endif

extern volatile int nstrace_num;
extern volatile int nstrace_depth;
extern volatile int nstrace_enabled_global;
169 170

void nstrace_leave(int *);
171 172
void nstrace_restore_global_trace_state(int *);
char const * nstrace_fullscreen_type_name (int);
173

174
/* printf-style trace output.  Output is aligned with contained heading.  */
175 176 177 178 179 180
#define NSTRACE_MSG_NO_DASHES(...)                                          \
  do                                                                        \
    {                                                                       \
      if (nstrace_enabled)                                                  \
        {                                                                   \
          fprintf (stderr, "%-10s:%5d: [%5d]%.*s",                          \
181
                   __FILE__, __LINE__, nstrace_num++,                       \
182 183
                   2*nstrace_depth, "  | | | | | | | | | | | | | | | ..");  \
          fprintf (stderr, __VA_ARGS__);                                    \
184
	  putc ('\n', stderr);						    \
185 186 187 188 189 190 191 192 193 194 195
        }                                                                   \
    }                                                                       \
  while(0)

#define NSTRACE_MSG(...) NSTRACE_MSG_NO_DASHES("+--- " __VA_ARGS__)



/* Macros for printing complex types.

   NSTRACE_FMT_what     -- Printf format string for "what".
196
   NSTRACE_ARG_what(x)  -- Printf argument for "what".  */
197 198 199 200 201 202 203 204 205 206 207

#define NSTRACE_FMT_SIZE        "(W:%.0f H:%.0f)"
#define NSTRACE_ARG_SIZE(elt)   (elt).width, (elt).height

#define NSTRACE_FMT_POINT       "(X:%.0f Y:%.0f)"
#define NSTRACE_ARG_POINT(elt)  (elt).x, (elt).y

#define NSTRACE_FMT_RECT        NSTRACE_FMT_POINT "/" NSTRACE_FMT_SIZE
#define NSTRACE_ARG_RECT(elt)   \
  NSTRACE_ARG_POINT((elt).origin), NSTRACE_ARG_SIZE((elt).size)

208 209 210
#define NSTRACE_FMT_FSTYPE      "%s"
#define NSTRACE_ARG_FSTYPE(elt) nstrace_fullscreen_type_name(elt)

211

212
/* Macros for printing complex types as extra information.  */
213 214 215 216 217 218 219 220 221 222 223 224 225 226

#define NSTRACE_SIZE(str,size)                                          \
  NSTRACE_MSG (str ": " NSTRACE_FMT_SIZE,                               \
               NSTRACE_ARG_SIZE (size));

#define NSTRACE_POINT(str,point)                                        \
  NSTRACE_MSG (str ": " NSTRACE_FMT_POINT,                              \
               NSTRACE_ARG_POINT (point));

#define NSTRACE_RECT(str,rect)                                          \
  NSTRACE_MSG (str ": " NSTRACE_FMT_RECT,                               \
               NSTRACE_ARG_RECT (rect));

#define NSTRACE_FSTYPE(str,fs_type)                                     \
227 228
  NSTRACE_MSG (str ": " NSTRACE_FMT_FSTYPE,                             \
               NSTRACE_ARG_FSTYPE (fs_type));
229 230 231 232 233 234 235 236 237 238 239


/* Return value macros.

   NSTRACE_RETURN(fmt, ...) - Print a return value, support printf-style
                              format string and arguments.

   NSTRACE_RETURN_what(obj) - Print a return value of kind WHAT.

   NSTRACE_FMT_RETURN - A string literal representing a returned
                        value.  Useful when creating a format string
240
                        to printf-like constructs like NSTRACE().  */
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258

#define NSTRACE_FMT_RETURN "->>"

#define NSTRACE_RETURN(...) \
  NSTRACE_MSG_NO_DASHES ("+" NSTRACE_FMT_RETURN " " __VA_ARGS__)

#define NSTRACE_RETURN_SIZE(size) \
  NSTRACE_RETURN(NSTRACE_FMT_SIZE, NSTRACE_ARG_SIZE(size))

#define NSTRACE_RETURN_POINT(point) \
  NSTRACE_RETURN(NSTRACE_FMT_POINT, NSTRACE_ARG_POINT(point))

#define NSTRACE_RETURN_RECT(rect) \
  NSTRACE_RETURN(NSTRACE_FMT_RECT, NSTRACE_ARG_RECT(rect))


/* Function enter macros.

Paul Eggert's avatar
Paul Eggert committed
259
   NSTRACE (fmt, ...) -- Enable trace output in current block
260 261 262 263 264 265
                         (typically a function).  Accepts printf-style
                         arguments.

   NSTRACE_WHEN (cond, fmt, ...) -- Enable trace output when COND is true.

   NSTRACE_UNLESS (cond, fmt, ...) -- Enable trace output unless COND is
266
                                      true.  */
267 268 269 270



#define NSTRACE_WHEN(cond, ...)                                         \
271 272
  __attribute__((cleanup(nstrace_restore_global_trace_state)))          \
  int nstrace_saved_enabled_global = nstrace_enabled_global;            \
273
  __attribute__((cleanup(nstrace_leave)))                               \
274
  int nstrace_enabled = nstrace_enabled_global && (cond);               \
275
  if (nstrace_enabled) { ++nstrace_depth; }                             \
276
  else { nstrace_enabled_global = 0; }                                  \
277 278
  NSTRACE_MSG_NO_DASHES(__VA_ARGS__);

279 280 281
/* Unsilence called functions.

   Concretely, this us used to allow "event" functions to be silenced
282
   while trace output can be printed for functions they call.  */
283 284
#define NSTRACE_UNSILENCE() do { nstrace_enabled_global = 1; } while(0)

285 286 287 288 289
#endif /* NSTRACE_ENABLED */

#define NSTRACE(...)              NSTRACE_WHEN(1, __VA_ARGS__)
#define NSTRACE_UNLESS(cond, ...) NSTRACE_WHEN(!(cond), __VA_ARGS__)

290
/* Non-trace replacement versions.  */
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
#ifndef NSTRACE_WHEN
#define NSTRACE_WHEN(...)
#endif

#ifndef NSTRACE_MSG
#define NSTRACE_MSG(...)
#endif

#ifndef NSTRACE_SIZE
#define NSTRACE_SIZE(str,size)
#endif

#ifndef NSTRACE_POINT
#define NSTRACE_POINT(str,point)
#endif

#ifndef NSTRACE_RECT
#define NSTRACE_RECT(str,rect)
#endif

#ifndef NSTRACE_FSTYPE
#define NSTRACE_FSTYPE(str,fs_type)
#endif

#ifndef NSTRACE_RETURN_SIZE
#define NSTRACE_RETURN_SIZE(size)
#endif

#ifndef NSTRACE_RETURN_POINT
#define NSTRACE_RETURN_POINT(point)
#endif

#ifndef NSTRACE_RETURN_RECT
#define NSTRACE_RETURN_RECT(rect)
#endif

#ifndef NSTRACE_RETURN_FSTYPE
#define NSTRACE_RETURN_FSTYPE(fs_type)
#endif

331 332 333
#ifndef NSTRACE_UNSILENCE
#define NSTRACE_UNSILENCE()
#endif
334 335


336
/* If the compiler doesn't support instancetype, map it to id.  */
337 338 339 340 341
#ifndef NATIVE_OBJC_INSTANCETYPE
typedef id instancetype;
#endif


342 343 344 345 346 347 348 349 350 351 352 353
/* ==========================================================================

   NSColor, EmacsColor category.

   ========================================================================== */
@interface NSColor (EmacsColor)
+ (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
                         blue:(CGFloat)blue alpha:(CGFloat)alpha;
- (NSColor *)colorUsingDefaultColorSpace;

@end

354 355 356 357 358 359
/* ==========================================================================

   The Emacs application

   ========================================================================== */

360
/* We override sendEvent: as a means to stop/start the event loop.  */
361 362
@interface EmacsApp : NSApplication
{
Jan Djärv's avatar
Jan Djärv committed
363
#ifdef NS_IMPL_COCOA
364 365 366
  BOOL shouldKeepRunning;
  BOOL isFirst;
#endif
367
#ifdef NS_IMPL_GNUSTEP
368
  BOOL applicationDidFinishLaunchingCalled;
369
#endif
370 371
@public
  int nextappdefined;
372
}
373
- (void)logNotification: (NSNotification *)notification;
374
- (void)antialiasThresholdDidChange:(NSNotification *)notification;
375 376
- (void)sendEvent: (NSEvent *)theEvent;
- (void)showPreferencesWindow: (id)sender;
377
- (BOOL) openFile: (NSString *)fileName;
378
- (void)fd_handler: (id)unused;
379 380
- (void)timeout_handler: (NSTimer *)timedEntry;
- (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg;
381 382 383
#ifdef NS_IMPL_GNUSTEP
- (void)sendFromMainThread:(id)unused;
#endif
384 385
@end

386 387 388 389 390 391 392
#ifdef NS_IMPL_GNUSTEP
/* Dummy class to get rid of startup warnings.  */
@interface EmacsDocument : NSDocument
{
}
@end
#endif
393 394 395 396 397 398 399 400 401

/* ==========================================================================

   The main Emacs view

   ========================================================================== */

@class EmacsToolbar;

402
#ifdef NS_IMPL_COCOA
403 404 405 406
@interface EmacsView : NSView <NSTextInput, NSWindowDelegate>
#else
@interface EmacsView : NSView <NSTextInput>
#endif
407
   {
408
#ifdef NS_IMPL_COCOA
409
   char *old_title;
410 411
   BOOL maximizing_resize;
#endif
412 413 414
   BOOL windowClosing;
   NSString *workingText;
   BOOL processingCompose;
415
   int fs_state, fs_before_fs, next_maximized;
416
   int bwidth;
417 418
   int maximized_width, maximized_height;
   NSWindow *nonfs_window;
419
   BOOL fs_is_native;
420 421 422 423 424
@public
   struct frame *emacsframe;
   int rows, cols;
   int scrollbarsNeedingUpdate;
   EmacsToolbar *toolbar;
425
   NSRect ns_userRect;
426
   BOOL wait_for_tool_bar;
427 428 429
   }

/* AppKit-side interface */
430 431 432
- (instancetype)menuDown: (id)sender;
- (instancetype)toolbarClicked: (id)item;
- (instancetype)toggleToolbar: (id)sender;
433 434 435
- (void)keyDown: (NSEvent *)theEvent;
- (void)mouseDown: (NSEvent *)theEvent;
- (void)mouseUp: (NSEvent *)theEvent;
436
- (instancetype)setMiniwindowImage: (BOOL)setMini;
437 438

/* Emacs-side interface */
439
- (instancetype) initFrameFromEmacs: (struct frame *) f;
440
- (void) createToolbar: (struct frame *)f;
441 442 443 444
- (void) setRows: (int) r andColumns: (int) c;
- (void) setWindowClosing: (BOOL)closing;
- (EmacsToolbar *) toolbar;
- (void) deleteWorkingText;
445
- (void) updateFrameSize: (BOOL) delay;
446 447 448
- (void) handleFS;
- (void) setFSValue: (int)value;
- (void) toggleFullScreen: (id) sender;
449 450
- (BOOL) fsIsNative;
- (BOOL) isFullscreen;
451
#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
Paul Eggert's avatar
Paul Eggert committed
452
- (void) updateCollectionBehavior;
453
#endif
454 455

#ifdef NS_IMPL_GNUSTEP
456
- (void)windowDidMove: (id)sender;
457
#endif
458
- (int)fullscreenState;
459

460
/* Non-notification versions of NSView methods.  Used for direct calls.  */
461 462 463 464 465
- (void)windowWillEnterFullScreen;
- (void)windowDidEnterFullScreen;
- (void)windowWillExitFullScreen;
- (void)windowDidExitFullScreen;
- (void)windowDidBecomeKey;
466 467 468
@end


469
/* Small utility used for processing resize events under Cocoa.  */
470 471 472 473
@interface EmacsWindow : NSWindow
{
  NSPoint grabOffset;
}
474 475

- (void)setAppearance;
476 477 478
@end


479 480 481 482 483 484
/* Fullscreen version of the above.  */
@interface EmacsFSWindow : EmacsWindow
{
}
@end

485 486 487 488 489 490
/* ==========================================================================

   The main menu implementation

   ========================================================================== */

491
#ifdef NS_IMPL_COCOA
492 493 494 495
@interface EmacsMenu : NSMenu  <NSMenuDelegate>
#else
@interface EmacsMenu : NSMenu
#endif
496 497 498 499 500
{
  struct frame *frame;
  unsigned long keyEquivModMask;
}

501
- (instancetype)initWithTitle: (NSString *)title frame: (struct frame *)f;
502 503
- (void)setFrame: (struct frame *)f;
- (void)menuNeedsUpdate: (NSMenu *)menu; /* (delegate method) */
504
- (NSString *)parseKeyEquiv: (const char *)key;
505
- (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr;
506
- (void)fillWithWidgetValue: (void *)wvptr;
Jan Djärv's avatar
Jan Djärv committed
507
- (void)fillWithWidgetValue: (void *)wvptr frame: (struct frame *)f;
508
- (EmacsMenu *)addSubmenuWithTitle: (const char *)title forFrame: (struct frame *)f;
509 510
- (void) clear;
- (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f
511
                 keymaps: (bool)keymaps;
512 513 514 515 516 517 518 519 520 521 522
@end


/* ==========================================================================

   Toolbar

   ========================================================================== */

@class EmacsImage;

523
#ifdef NS_IMPL_COCOA
524 525 526 527
@interface EmacsToolbar : NSToolbar <NSToolbarDelegate>
#else
@interface EmacsToolbar : NSToolbar
#endif
528 529 530 531 532 533 534
   {
     EmacsView *emacsView;
     NSMutableDictionary *identifierToItem;
     NSMutableArray *activeIdentifiers;
     NSArray *prevIdentifiers;
     unsigned long enablement, prevEnablement;
   }
535
- (instancetype) initForView: (EmacsView *)view withIdentifier: (NSString *)identifier;
536
- (void) clearActive;
537
- (void) clearAll;
538
- (BOOL) changed;
539 540 541
- (void) addDisplayItemWithImage: (EmacsImage *)img
                             idx: (int)idx
                             tag: (int)tag
542
                        helpText: (const char *)help
543
                         enabled: (BOOL)enabled;
544

545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
/* delegate methods */
- (NSToolbarItem *)toolbar: (NSToolbar *)toolbar
     itemForItemIdentifier: (NSString *)itemIdentifier
 willBeInsertedIntoToolbar: (BOOL)flag;
- (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar;
- (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar;
@end


/* ==========================================================================

   Message / question windows

   ========================================================================== */

@interface EmacsDialogPanel : NSPanel
   {
   NSTextField *command;
   NSTextField *title;
   NSMatrix *matrix;
   int rows, cols;
566
   BOOL timer_fired, window_closed;
567
   Lisp_Object dialog_return;
568
   Lisp_Object *button_values;
569
   }
570
- (instancetype)initFromContents: (Lisp_Object)menu isQuestion: (BOOL)isQ;
571 572 573 574
- (void)process_dialog: (Lisp_Object)list;
- (void)addButton: (char *)str value: (int)tag row: (int)row;
- (void)addString: (char *)str row: (int)row;
- (void)addSplit;
575
- (Lisp_Object)runDialogAt: (NSPoint)p;
576
- (void)timeout_handler: (NSTimer *)timedEntry;
577 578
@end

579
#ifdef NS_IMPL_COCOA
580 581 582 583
@interface EmacsTooltip : NSObject <NSWindowDelegate>
#else
@interface EmacsTooltip : NSObject
#endif
584 585 586 587 588
  {
    NSWindow *win;
    NSTextField *textField;
    NSTimer *timer;
  }
589
- (instancetype) init;
590
- (void) setText: (char *)text;
591 592
- (void) setBackgroundColor: (NSColor *)col;
- (void) setForegroundColor: (NSColor *)col;
593 594 595 596 597 598 599 600 601 602
- (void) showAtX: (int)x Y: (int)y for: (int)seconds;
- (void) hide;
- (BOOL) isActive;
- (NSRect) frame;
@end


/* ==========================================================================

   File open/save panels
603
   This and next override methods to handle keyboard input in panels.
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636

   ========================================================================== */

@interface EmacsSavePanel : NSSavePanel
{
}
@end
@interface EmacsOpenPanel : NSOpenPanel
{
}
@end

@interface EmacsFileDelegate : NSObject
{
}
- (BOOL)panel: (id)sender isValidFilename: (NSString *)filename;
- (BOOL)panel: (id)sender shouldShowFilename: (NSString *)filename;
- (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
          confirmed: (BOOL)okFlag;
@end


/* ==========================================================================

   Images and stippling

   ========================================================================== */

@interface EmacsImage : NSImage
{
  NSBitmapImageRep *bmRep; /* used for accessing pixel data */
  unsigned char *pixmapData[5]; /* shortcut to access pixel data */
  NSColor *stippleMask;
637
  unsigned long xbm_fg;
638 639
@public
  NSAffineTransform *transform;
640
}
641
+ (instancetype)allocInitFromFile: (Lisp_Object)file;
642
- (void)dealloc;
643
- (instancetype)initFromXBM: (unsigned char *)bits width: (int)w height: (int)h
644 645
                         fg: (unsigned long)fg bg: (unsigned long)bg
               reverseBytes: (BOOL)reverse;
646 647
- (instancetype)setXBMColor: (NSColor *)color;
- (instancetype)initForXPMWithDepth: (int)depth width: (int)width height: (int)height;
648 649 650 651 652 653 654
- (void)setPixmapData;
- (unsigned long)getPixelAtX: (int)x Y: (int)y;
- (void)setPixelAtX: (int)x Y: (int)y toRed: (unsigned char)r
               green: (unsigned char)g blue: (unsigned char)b
              alpha:(unsigned char)a;
- (void)setAlphaAtX: (int)x Y: (int)y to: (unsigned char)a;
- (NSColor *)stippleMask;
655 656
- (Lisp_Object)getMetadata;
- (BOOL)setFrame: (unsigned int) index;
657
- (void)setTransform: (double[3][3]) m;
658 659 660 661 662 663 664 665 666 667 668
@end


/* ==========================================================================

   Scrollbars

   ========================================================================== */

@interface EmacsScroller : NSScroller
  {
669
   struct window *window;
670 671 672 673
   struct frame *frame;
   NSResponder *prevResponder;

   /* offset to the bottom of knob of last mouse down */
674
   CGFloat last_mouse_offset;
675
   float min_portion;
676
   int pixel_length;
677
   enum scroll_bar_part last_hit_part;
678 679 680

   BOOL condemned;

681 682
   BOOL horizontal;

683 684 685 686 687 688
   /* optimize against excessive positioning calls generated by emacs */
   int em_position;
   int em_portion;
   int em_whole;
   }

689
- (instancetype) initFrame: (NSRect )r window: (Lisp_Object)win;
690 691
- (void)setFrame: (NSRect)r;

692
- (instancetype) setPosition: (int) position portion: (int) portion whole: (int) whole;
693 694 695
- (int) checkSamePosition: (int)position portion: (int)portion
                    whole: (int)whole;
- (void) sendScrollEventAtLoc: (float)loc fromEvent: (NSEvent *)e;
696 697 698
- (instancetype)repeatScroll: (NSTimer *)sender;
- (instancetype)condemn;
- (instancetype)reprieve;
699
- (bool)judge;
Jan Djärv's avatar
Jan Djärv committed
700
+ (CGFloat)scrollerWidth;
701 702 703 704 705
@end


/* ==========================================================================

706
   Rendering
707 708 709 710 711 712 713 714 715 716 717 718 719 720

   ========================================================================== */

#ifdef NS_IMPL_COCOA
/* rendering util */
@interface EmacsGlyphStorage : NSObject <NSGlyphStorage>
{
@public
  NSAttributedString *attrStr;
  NSMutableDictionary *dict;
  CGGlyph *cglyphs;
  unsigned long maxChar, maxGlyph;
  long i, len;
}
721
- (instancetype)initWithCapacity: (unsigned long) c;
722 723 724 725 726
- (void) setString: (NSString *)str font: (NSFont *)font;
@end
#endif	/* NS_IMPL_COCOA */

extern NSArray *ns_send_types, *ns_return_types;
727
extern NSString *ns_app_name;
728
extern EmacsMenu *svcsMenu;
729

730
/* Apple removed the declaration, but kept the implementation.  */
731
#if defined (NS_IMPL_COCOA)
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
@interface NSApplication (EmacsApp)
- (void)setAppleMenu: (NSMenu *)menu;
@end
#endif

#endif  /* __OBJC__ */



/* ==========================================================================

   Non-OO stuff

   ========================================================================== */

747 748 749 750 751 752 753 754 755 756 757
/* Special keycodes that we pass down the event chain */
#define KEY_NS_POWER_OFF               ((1<<28)|(0<<16)|1)
#define KEY_NS_OPEN_FILE               ((1<<28)|(0<<16)|2)
#define KEY_NS_OPEN_TEMP_FILE          ((1<<28)|(0<<16)|3)
#define KEY_NS_CHANGE_FONT             ((1<<28)|(0<<16)|7)
#define KEY_NS_OPEN_FILE_LINE          ((1<<28)|(0<<16)|8)
#define KEY_NS_PUT_WORKING_TEXT        ((1<<28)|(0<<16)|9)
#define KEY_NS_UNPUT_WORKING_TEXT      ((1<<28)|(0<<16)|10)
#define KEY_NS_SPI_SERVICE_CALL        ((1<<28)|(0<<16)|11)
#define KEY_NS_NEW_FRAME               ((1<<28)|(0<<16)|12)
#define KEY_NS_TOGGLE_TOOLBAR          ((1<<28)|(0<<16)|13)
758
#define KEY_NS_SHOW_PREFS              ((1<<28)|(0<<16)|14)
759

760 761
/* Could use list to store these, but rest of emacs has a big infrastructure
   for managing a table of bitmap "records".  */
762 763 764 765 766 767 768 769 770 771 772 773
struct ns_bitmap_record
{
#ifdef __OBJC__
  EmacsImage *img;
#else
  void *img;
#endif
  char *file;
  int refcount;
  int height, width, depth;
};

774
/* This maps between emacs color indices and NSColor objects.  */
775 776
struct ns_color_table
{
777 778
  ptrdiff_t size;
  ptrdiff_t avail;
779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
#ifdef __OBJC__
  NSColor **colors;
  NSMutableSet *empty_indices;
#else
  void **items;
  void *availIndices;
#endif
};
#define NS_COLOR_CAPACITY 256

#define RGB_TO_ULONG(r, g, b) (((r) << 16) | ((g) << 8) | (b))
#define ARGB_TO_ULONG(a, r, g, b) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))

#define ALPHA_FROM_ULONG(color) ((color) >> 24)
#define RED_FROM_ULONG(color) (((color) >> 16) & 0xff)
#define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
#define BLUE_FROM_ULONG(color) ((color) & 0xff)

/* Do not change `* 0x101' in the following lines to `<< 8'.  If
798
   changed, image masks in 1-bit depth will not work.  */
799 800 801 802 803 804 805 806 807
#define RED16_FROM_ULONG(color) (RED_FROM_ULONG(color) * 0x101)
#define GREEN16_FROM_ULONG(color) (GREEN_FROM_ULONG(color) * 0x101)
#define BLUE16_FROM_ULONG(color) (BLUE_FROM_ULONG(color) * 0x101)

/* this extends font backend font */
struct nsfont_info
{
  struct font font;

Juanma Barranquero's avatar
Juanma Barranquero committed
808
  char *name;  /* PostScript name, uniquely identifies on NS systems */
809

810
  /* The following metrics are stored as float rather than int.  */
811 812

  float width;  /* Maximum advance for the font.  */
813 814 815 816 817 818
  float height;
  float underpos;
  float underwidth;
  float size;
#ifdef __OBJC__
  NSFont *nsfont;
819
#if defined (NS_IMPL_COCOA)
820
  CGFontRef cgfont;
821
#else /* GNUstep */
822 823 824 825 826 827 828 829
  void *cgfont;
#endif
#else /* ! OBJC */
  void *nsfont;
  void *cgfont;
#endif
  char bold, ital;  /* convenience flags */
  char synthItal;
830
  XCharStruct max_bounds;
831 832
  /* We compute glyph codes and metrics on-demand in blocks of 256 indexed
     by hibyte, lobyte.  */
Juanma Barranquero's avatar
Juanma Barranquero committed
833
  unsigned short **glyphs; /* map Unicode index to glyph */
834 835 836 837
  struct font_metrics **metrics;
};


838
/* Initialized in ns_initialize_display_info ().  */
839 840 841 842 843
struct ns_display_info
{
  /* Chain of all ns_display_info structures.  */
  struct ns_display_info *next;

844
  /* The generic display parameters corresponding to this NS display.  */
845 846
  struct terminal *terminal;

847
  /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).  */
848 849
  Lisp_Object name_list_element;

850
  /* The number of fonts loaded.  */
851 852 853 854 855 856 857 858 859
  int n_fonts;

  /* Minimum width over all characters in all fonts in font_table.  */
  int smallest_char_width;

  /* Minimum font height over all fonts in font_table.  */
  int smallest_font_height;

  struct ns_bitmap_record *bitmaps;
860 861
  ptrdiff_t bitmaps_size;
  ptrdiff_t bitmaps_last;
862 863 864

  struct ns_color_table *color_table;

865
  /* DPI resolution of this screen */
866 867
  double resx, resy;

868
  /* Mask of things that cause the mouse to be grabbed */
869 870 871 872 873 874 875 876
  int grabbed;

  int n_planes;

  int color_p;

  Window root_window;

877
  /* Xism */
878
  Lisp_Object rdb;
879

880
  /* The cursor to use for vertical scroll bars.  */
881
  Emacs_Cursor vertical_scroll_bar_cursor;
882

883
  /* The cursor to use for horizontal scroll bars.  */
884
  Emacs_Cursor horizontal_scroll_bar_cursor;
885

886 887 888
  /* Information about the range of text currently shown in
     mouse-face.  */
  Mouse_HLInfo mouse_highlight;
889

890
  struct frame *highlight_frame;
891
  struct frame *ns_focus_frame;
892 893 894

  /* The frame where the mouse was last time we reported a mouse event.  */
  struct frame *last_mouse_frame;
895 896 897 898 899 900 901 902

  /* The frame where the mouse was last time we reported a mouse motion.  */
  struct frame *last_mouse_motion_frame;

  /* Position where the mouse was last time we reported a motion.
     This is a position on last_mouse_motion_frame.  */
  int last_mouse_motion_x;
  int last_mouse_motion_y;
903 904 905 906 907 908 909 910 911 912 913 914 915

  /* Where the mouse was last time we reported a mouse position.  */
  NSRect last_mouse_glyph;

  /* Time of last mouse movement.  */
  Time last_mouse_movement_time;

  /* The scroll bar in which the last motion event occurred.  */
#ifdef __OBJC__
  EmacsScroller *last_mouse_scroll_bar;
#else
  void *last_mouse_scroll_bar;
#endif
916 917 918
};

/* This is a chain of structures for all the NS displays currently in use.  */
919
extern struct ns_display_info *x_display_list;
920 921 922 923 924 925

struct ns_output
{
#ifdef __OBJC__
  EmacsView *view;
  id miniimage;
926
  NSColor *cursor_color;
927 928 929 930 931 932
  NSColor *foreground_color;
  NSColor *background_color;
  EmacsToolbar *toolbar;
#else
  void *view;
  void *miniimage;
933
  void *cursor_color;
934 935 936 937 938
  void *foreground_color;
  void *background_color;
  void *toolbar;
#endif

939
  /* NSCursors are initialized in initFrameFromEmacs.  */
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
  Emacs_Cursor text_cursor;
  Emacs_Cursor nontext_cursor;
  Emacs_Cursor modeline_cursor;
  Emacs_Cursor hand_cursor;
  Emacs_Cursor hourglass_cursor;
  Emacs_Cursor horizontal_drag_cursor;
  Emacs_Cursor vertical_drag_cursor;
  Emacs_Cursor left_edge_cursor;
  Emacs_Cursor top_left_corner_cursor;
  Emacs_Cursor top_edge_cursor;
  Emacs_Cursor top_right_corner_cursor;
  Emacs_Cursor right_edge_cursor;
  Emacs_Cursor bottom_right_corner_cursor;
  Emacs_Cursor bottom_edge_cursor;
  Emacs_Cursor bottom_left_corner_cursor;
955

956
  /* NS-specific */
957
  Emacs_Cursor current_pointer;
958

959
  /* lord knows why Emacs needs to know about our Window ids.. */
960 961 962 963 964 965 966 967 968 969
  Window window_desc, parent_desc;
  char explicit_parent;

  struct font *font;
  int baseline_offset;

  /* If a fontset is specified for this frame instead of font, this
     value contains an ID of the fontset, else -1.  */
  int fontset; /* only used with font_backend */

970 971
  int icon_top;
  int icon_left;
972 973 974 975 976

  /* The size of the extra width currently allotted for vertical
     scroll bars, in pixels.  */
  int vertical_scroll_bar_extra;

977
  /* The height of the titlebar decoration (included in NSWindow's frame).  */
978 979
  int titlebar_height;

980
  /* The height of the toolbar if displayed, else 0.  */
981 982 983 984
  int toolbar_height;

  /* This is the Emacs structure for the NS display this frame is on.  */
  struct ns_display_info *display_info;
985 986 987

  /* Non-zero if we are zooming (maximizing) the frame.  */
  int zooming;
988

989
  /* Non-zero if we are doing an animation, e.g. toggling the tool bar.  */
990
  int in_animation;
991 992
};

993
/* This dummy declaration needed to support TTYs.  */
994 995
struct x_output
{
996
  int unused;
997 998 999 1000
};


/* This gives the ns_display_info structure for the display F is on.  */
1001
#define FRAME_DISPLAY_INFO(f) ((f)->output_data.ns->display_info)
1002
#define FRAME_OUTPUT_DATA(f) ((f)->output_data.ns)
1003
#define FRAME_NS_WINDOW(f) ((f)->output_data.ns->window_desc)
1004
#define FRAME_NATIVE_WINDOW(f) FRAME_NS_WINDOW (f)
1005 1006 1007 1008 1009 1010 1011

#define FRAME_FOREGROUND_COLOR(f) ((f)->output_data.ns->foreground_color)
#define FRAME_BACKGROUND_COLOR(f) ((f)->output_data.ns->background_color)

#define NS_FACE_FOREGROUND(f) ((f)->foreground)
#define NS_FACE_BACKGROUND(f) ((f)->background)

1012
#define FRAME_DEFAULT_FACE(f) FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID)
1013 1014

#define FRAME_NS_VIEW(f) ((f)->output_data.ns->view)
1015
#define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
1016 1017 1018 1019 1020
#define FRAME_POINTER_TYPE(f) ((f)->output_data.ns->current_pointer)

#define FRAME_FONT(f) ((f)->output_data.ns->font)

#ifdef __OBJC__
1021
#define XNS_SCROLL_BAR(vec) ((id) xmint_pointer (vec))
1022
#else
1023
#define XNS_SCROLL_BAR(vec) xmint_pointer (vec)
1024 1025
#endif

1026
/* Compute pixel height of the frame's titlebar.  */
1027 1028 1029 1030 1031 1032 1033 1034
#define FRAME_NS_TITLEBAR_HEIGHT(f)                                     \
  (NSHeight([FRAME_NS_VIEW (f) frame]) == 0 ?                           \
   0                                                                    \
   : (int)(NSHeight([FRAME_NS_VIEW (f) window].frame)                   \
           - NSHeight([NSWindow contentRectForFrameRect:                \
                       [[FRAME_NS_VIEW (f) window] frame]               \
                       styleMask:[[FRAME_NS_VIEW (f) window] styleMask]])))

1035
/* Compute pixel height of the toolbar.  */
1036 1037 1038 1039 1040 1041 1042 1043 1044
#define FRAME_TOOLBAR_HEIGHT(f)                                         \
  (([[FRAME_NS_VIEW (f) window] toolbar] == nil                         \
    || ! [[FRAME_NS_VIEW (f) window] toolbar].isVisible) ?		\
   0                                                                    \
   : (int)(NSHeight([NSWindow contentRectForFrameRect:                  \
                     [[FRAME_NS_VIEW (f) window] frame]                 \
                     styleMask:[[FRAME_NS_VIEW (f) window] styleMask]]) \
           - NSHeight([[[FRAME_NS_VIEW (f) window] contentView] frame])))

1045
/* Compute pixel size for vertical scroll bars.  */
1046 1047 1048 1049 1050 1051 1052
#define NS_SCROLL_BAR_WIDTH(f)						\
  (FRAME_HAS_VERTICAL_SCROLL_BARS (f)					\
   ? rint (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0			\
	   ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f)				\
	   : (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f)))	\
   : 0)

1053
/* Compute pixel size for horizontal scroll bars.  */
1054 1055 1056 1057 1058 1059
#define NS_SCROLL_BAR_HEIGHT(f)						\
  (FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)					\
   ? rint (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0			\
	   ? FRAME_CONFIG_SCROLL_BAR_HEIGHT (f)				\
	   : (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f)))	\
   : 0)
1060

1061 1062
/* Difference between char-column-calculated and actual SB widths.
   This is only a concern for rendering when SB on left.  */
1063 1064 1065 1066
#define NS_SCROLL_BAR_ADJUST(w, f)				\
  (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) ?			\
   (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f)		\
    - NS_SCROLL_BAR_WIDTH (f)) : 0)
1067

1068 1069
/* Difference between char-line-calculated and actual SB heights.
   This is only a concern for rendering when SB on top.  */
1070 1071 1072 1073 1074
#define NS_SCROLL_BAR_ADJUST_HORIZONTALLY(w, f)		\
  (WINDOW_HAS_HORIZONTAL_SCROLL_BARS (w) ?		\
   (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f)	\
    - NS_SCROLL_BAR_HEIGHT (f)) : 0)

1075
/* Calculate system coordinates of the left and top of the parent
1076
   window or, if there is no parent window, the screen.  */
1077 1078
#define NS_PARENT_WINDOW_LEFT_POS(f)                                    \
  (FRAME_PARENT_FRAME (f) != NULL                                       \
1079
   ? [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.origin.x : 0)
1080 1081
#define NS_PARENT_WINDOW_TOP_POS(f)                                     \
  (FRAME_PARENT_FRAME (f) != NULL                                       \
1082 1083
   ? ([FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.origin.y    \
      + [FRAME_NS_VIEW (FRAME_PARENT_FRAME (f)) window].frame.size.height \
1084
      - FRAME_NS_TITLEBAR_HEIGHT (FRAME_PARENT_FRAME (f)))              \
1085
   : [[[NSScreen screens] objectAtIndex: 0] frame].size.height)
1086

1087
#define FRAME_NS_FONT_TABLE(f) (FRAME_DISPLAY_INFO (f)->font_table)
1088 1089 1090 1091 1092 1093 1094 1095

#define FRAME_FONTSET(f) ((f)->output_data.ns->fontset)

#define FRAME_BASELINE_OFFSET(f) ((f)->output_data.ns->baseline_offset)
#define BLACK_PIX_DEFAULT(f) 0x000000
#define WHITE_PIX_DEFAULT(f) 0xFFFFFF

/* First position where characters can be shown (instead of scrollbar, if
1096
   it is on left.  */
1097 1098
#define FIRST_CHAR_POSITION(f)				\
  (! (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) ? 0	\
1099 1100
   : FRAME_SCROLL_BAR_COLS (f))

1101
extern struct ns_display_info *ns_term_init (Lisp_Object display_name);
1102 1103 1104 1105 1106 1107 1108 1109 1110
extern void ns_term_shutdown (int sig);

/* constants for text rendering */
#define NS_DUMPGLYPH_NORMAL             0
#define NS_DUMPGLYPH_CURSOR             1
#define NS_DUMPGLYPH_FOREGROUND         2
#define NS_DUMPGLYPH_MOUSEFACE          3


1111

1112 1113 1114 1115 1116 1117
/* In nsfont, called from fontset.c */
extern void nsfont_make_fontset_for_font (Lisp_Object name,
                                         Lisp_Object font_object);

/* In nsfont, for debugging */
struct glyph_string;
1118
void ns_dump_glyphstring (struct glyph_string *s) EXTERNALLY_VISIBLE;
1119

1120
/* Implemented in nsterm, published in or needed from nsfns.  */
Dmitry Antipov's avatar
Dmitry Antipov committed
1121
extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern,
1122 1123 1124
                                  int size, int maxnames);
extern void ns_clear_frame (struct frame *f);

1125 1126 1127
extern void ns_set_offset (struct frame *f, int xoff, int yoff,
                           int change_grav);

1128 1129
extern const char *ns_xlfd_to_fontname (const char *xlfd);

1130 1131 1132 1133 1134
extern Lisp_Object ns_map_event_to_object (void);
#ifdef __OBJC__
extern Lisp_Object ns_string_from_pasteboard (id pb);
extern void ns_string_to_pasteboard (id pb, Lisp_Object str);
#endif
1135 1136
extern Lisp_Object ns_get_local_selection (Lisp_Object selection_name,
                                           Lisp_Object target_type);
1137
extern void nxatoms_of_nsselect (void);
1138
extern void ns_set_doc_edited (void);
1139

1140
extern bool
1141 1142
ns_defined_color (struct frame *f,
                  const char *name,
1143
                  Emacs_Color *color_def, bool alloc,
1144
                  bool makeIndex);
1145
extern void
1146
ns_query_color (void *col, Emacs_Color *color_def, bool setPixel);
1147 1148 1149 1150 1151

#ifdef __OBJC__
extern int ns_lisp_to_color (Lisp_Object color, NSColor **col);
extern NSColor *ns_lookup_indexed_color (unsigned long idx, struct frame *f);
extern unsigned long ns_index_color (NSColor *color, struct frame *f);
1152
extern const char *ns_get_pending_menu_title (void);
1153
extern void ns_check_menu_open (NSMenu *menu);
1154
extern void ns_check_pending_open_menu (void);
1155 1156
#endif

1157 1158 1159 1160 1161 1162 1163 1164 1165
/* Implemented in nsfns, published in nsterm.  */
extern void ns_implicitly_set_name (struct frame *f, Lisp_Object arg,
                                    Lisp_Object oldval);
extern void ns_set_scroll_bar_default_width (struct frame *f);
extern void ns_set_scroll_bar_default_height (struct frame *f);
extern const char *ns_get_string_resource (void *_rdb,
                                           const char *name,
                                           const char *class);

1166 1167 1168
/* C access to ObjC functionality */
extern void  ns_release_object (void *obj);
extern void  ns_retain_object (void *obj);
1169 1170 1171
extern void *ns_alloc_autorelease_pool (void);
extern void ns_release_autorelease_pool (void *);
extern const char *ns_get_defaults_value (const char *key);
1172 1173
extern void ns_init_locale (void);

1174
/* in nsmenu */
Dmitry Antipov's avatar
Dmitry Antipov committed
1175 1176 1177
extern void update_frame_tool_bar (struct frame *f);
extern void free_frame_tool_bar (struct frame *f);
extern Lisp_Object find_and_return_menu_selection (struct frame *f,
1178
                                                   bool keymaps,
1179
                                                   void *client_data);
1180
extern Lisp_Object ns_popup_dialog (struct frame *, Lisp_Object header,
1181
                                    Lisp_Object contents);
1182

1183 1184
extern void ns_free_frame_resources (struct frame *);

1185 1186 1187
#define NSAPP_DATA2_RUNASSCRIPT 10
extern void ns_run_ascript (void);

1188 1189 1190
#define NSAPP_DATA2_RUNFILEDIALOG 11
extern void ns_run_file_dialog (void);

1191
extern const char *ns_etc_directory (void);
1192
extern const char *ns_exec_path (void);
1193
extern const char *ns_load_path (void);
1194 1195 1196 1197
extern void syms_of_nsterm (void);
extern void syms_of_nsfns (void);
extern void syms_of_nsmenu (void);
extern void syms_of_nsselect (void);
1198 1199 1200

/* From nsimage.m, needed in image.c */
struct image;
1201
extern void *ns_image_from_XBM (char *bits, int width, int height,
1202
                                unsigned long fg, unsigned long bg);
1203 1204
extern void *ns_image_for_XPM (int width, int height, int depth);
extern void *ns_image_from_file (Lisp_Object file);
1205 1206
extern bool ns_load_image (struct frame *f, struct image *img,
			   Lisp_Object spec_file, Lisp_Object spec_data);
1207 1208
extern int ns_image_width (void *img);
extern int ns_image_height (void *img);
1209
extern void ns_image_set_size (void *img, int width, int height);
1210
extern void ns_image_set_transform (void *img, double m[3][3]);
1211 1212 1213 1214
extern unsigned long ns_get_pixel (void *img, int x, int y);
extern void ns_put_pixel (void *img, int x, int y, unsigned long argb);
extern void ns_set_alpha (void *img, int x, int y, unsigned char a);

1215 1216
extern int ns_display_pixel_height (struct ns_display_info *);
extern int ns_display_pixel_width (struct ns_display_info *);
1217

1218
/* This in nsterm.m */
1219
extern float ns_antialias_threshold;
1220 1221 1222
extern void ns_make_frame_visible (struct frame *f);
extern void ns_iconify_frame (struct frame *f);
extern void ns_set_undecorated (struct frame *f, Lisp_Object new_value,
1223
                                Lisp_Object old_value);
1224 1225 1226 1227 1228 1229 1230 1231
extern void ns_set_parent_frame (struct frame *f, Lisp_Object new_value,
                                 Lisp_Object old_value);
extern void ns_set_no_focus_on_map (struct frame *f, Lisp_Object new_value,
                                    Lisp_Object old_value);
extern void ns_set_no_accept_focus (struct frame *f, Lisp_Object new_value,
                                    Lisp_Object old_value);
extern void ns_set_z_group (struct frame *f, Lisp_Object new_value,
                            Lisp_Object old_value);
1232 1233 1234 1235 1236 1237 1238
#ifdef NS_IMPL_COCOA
extern void ns_set_appearance (struct frame *f, Lisp_Object new_value,
                               Lisp_Object old_value);
extern void ns_set_transparent_titlebar (struct frame *f,
                                         Lisp_Object new_value,
                                         Lisp_Object old_value);
#endif
1239
extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds,
1240 1241 1242 1243 1244
		      fd_set *exceptfds, struct timespec *timeout,
		      sigset_t *sigmask);
#ifdef HAVE_PTHREAD
extern void ns_run_loop_break (void);
#endif
1245 1246 1247
extern unsigned long ns_get_rgb_color (struct frame *f,
                                       float r, float g, float b, float a);

1248 1249 1250
struct input_event;
extern void ns_init_events (struct input_event *);
extern void ns_finish_events (void);
1251

1252

1253 1254 1255 1256 1257 1258 1259
#ifdef NS_IMPL_GNUSTEP
extern char gnustep_base_version[];  /* version tracking */
#endif

#define MINWIDTH 10
#define MINHEIGHT 10

1260 1261
/* Screen max coordinate -- using larger coordinates causes
   movewindow/placewindow to abort.  */
1262 1263 1264
#define SCREENMAX 16000

#define NS_SCROLL_BAR_WIDTH_DEFAULT     [EmacsScroller scrollerWidth]
1265
#define NS_SCROLL_BAR_HEIGHT_DEFAULT    [EmacsScroller scrollerHeight]
1266
/* This is to match emacs on other platforms, ugly though it is.  */
1267 1268
#define NS_SELECTION_BG_COLOR_DEFAULT	@"LightGoldenrod2";
#define NS_SELECTION_FG_COLOR_DEFAULT	@"Black";
1269 1270 1271 1272 1273 1274 1275
#define RESIZE_HANDLE_SIZE 12

/* Little utility macros */
#define IN_BOUND(min, x, max) (((x) < (min)) \
                                ? (min) : (((x)>(max)) ? (max) : (x)))
#define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))

1276
/* macOS 10.7 introduces some new constants.  */
1277 1278 1279 1280 1281 1282 1283 1284
#if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_7)
#define NSFullScreenWindowMask                      (1 << 14)
#define NSWindowCollectionBehaviorFullScreenPrimary (1 << 7)
#define NSApplicationPresentationFullScreen         (1 << 10)
#define NSApplicationPresentationAutoHideToolbar    (1 << 11)
#define NSAppKitVersionNumber10_7                   1138
#endif /* !defined (MAC_OS_X_VERSION_10_7) */

1285
/* macOS 10.12 deprecates a bunch of constants.  */
1286
#if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_12)
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311
#define NSEventModifierFlagCommand         NSCommandKeyMask
#define NSEventModifierFlagControl         NSControlKeyMask
#define NSEventModifierFlagHelp            NSHelpKeyMask
#define NSEventModifierFlagNumericPad      NSNumericPadKeyMask
#define NSEventModifierFlagOption          NSAlternateKeyMask
#define NSEventModifierFlagShift           NSShiftKeyMask
#define NSCompositingOperationSourceOver   NSCompositeSourceOver
#define NSEventMaskApplicationDefined      NSApplicationDefinedMask
#define NSEventTypeApplicationDefined      NSApplicationDefined
#define NSEventTypeCursorUpdate            NSCursorUpdate
#define NSEventTypeMouseMoved              NSMouseMoved
#define NSEventTypeLeftMouseDown           NSLeftMouseDown
#define NSEventTypeRightMouseDown          NSRightMouseDown
#define NSEventTypeOtherMouseDown          NSOtherMouseDown
#define NSEventTypeLeftMouseUp             NSLeftMouseUp
#define NSEventTypeRightMouseUp            NSRightMouseUp
#define NSEventTypeOtherMouseUp            NSOtherMouseUp
#define NSEventTypeLeftMouseDragged        NSLeftMouseDragged
#define NSEventTypeRightMouseDragged       NSRightMouseDragged
#define NSEventTypeOtherMouseDragged       NSOtherMouseDragged
#define NSEventTypeScrollWheel             NSScrollWheel
#define NSEventTypeKeyDown                 NSKeyDown
#define NSEventTypeKeyUp                   NSKeyUp
#define NSEventTypeFlagsChanged            NSFlagsChanged
#define NSEventMaskAny                     NSAnyEventMask
1312
#define NSEventTypeSystemDefined           NSSystemDefined
1313 1314 1315 1316 1317 1318
#define NSWindowStyleMaskBorderless        NSBorderlessWindowMask
#define NSWindowStyleMaskClosable          NSClosableWindowMask
#define NSWindowStyleMaskFullScreen        NSFullScreenWindowMask
#define NSWindowStyleMaskMiniaturizable    NSMiniaturizableWindowMask
#define NSWindowStyleMaskResizable         NSResizableWindowMask
#define NSWindowStyleMaskTitled            NSTitledWindowMask
Alan Third's avatar
Alan Third committed
1319
#define NSWindowStyleMaskUtilityWindow     NSUtilityWindowMask
1320 1321
#define NSAlertStyleCritical               NSCriticalAlertStyle
#define NSControlSizeRegular               NSRegularControlSize
1322
#define NSCompositingOperationCopy         NSCompositeCopy
1323

1324
/* And adds NSWindowStyleMask.  */
1325 1326 1327
#ifdef __OBJC__
typedef NSUInteger NSWindowStyleMask;
#endif
1328

1329
/* Window tabbing mode enums are new too.  */
1330 1331 1332 1333 1334 1335
enum NSWindowTabbingMode
  {
    NSWindowTabbingModeAutomatic,
    NSWindowTabbingModePreferred,
    NSWindowTabbingModeDisallowed
  };
1336 1337 1338 1339 1340
#endif /* !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_12)  */

#if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_13)
/* Deprecated in macOS 10.13.  */
#define NSPasteboardNameGeneral NSGeneralPboard
1341
#endif
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351

#if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_14)
/* Deprecated in macOS 10.14.  */
#define NSPasteboardTypeString NSStringPboardType
#define NSPasteboardTypeTabularText NSTabularTextPboardType
#define NSPasteboardTypeURL NSURLPboardType
#define NSControlStateValueOn NSOnState
#define NSControlStateValueOff NSOffState
#define NSBezelStyleRounded NSRoundedBezelStyle
#endif
1352
#endif	/* HAVE_NS */