root/src/nsterm.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. NSColor

     1 /* -*- objc -*- */
     2 /* Definitions and headers for communication with NeXT/Open/GNUstep API.
     3    Copyright (C) 1989, 1993, 2005, 2008-2023 Free Software Foundation,
     4    Inc.
     5 
     6 This file is part of GNU Emacs.
     7 
     8 GNU Emacs is free software: you can redistribute it and/or modify
     9 it under the terms of the GNU General Public License as published by
    10 the Free Software Foundation, either version 3 of the License, or (at
    11 your option) any later version.
    12 
    13 GNU Emacs is distributed in the hope that it will be useful,
    14 but WITHOUT ANY WARRANTY; without even the implied warranty of
    15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16 GNU General Public License for more details.
    17 
    18 You should have received a copy of the GNU General Public License
    19 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    20 
    21 
    22 #include "dispextern.h"
    23 #include "frame.h"
    24 #include "character.h"
    25 #include "font.h"
    26 #include "sysselect.h"
    27 #include "sysstdio.h"
    28 
    29 #ifdef HAVE_NS
    30 #ifdef __OBJC__
    31 
    32 /* CGFloat on GNUstep may be 4 or 8 byte, but functions expect float* for some
    33    versions.
    34    On Cocoa >= 10.5, functions expect CGFloat *.  Make compatible type.  */
    35 #ifdef NS_IMPL_COCOA
    36 typedef CGFloat EmacsCGFloat;
    37 #elif GNUSTEP_GUI_MAJOR_VERSION > 0 || GNUSTEP_GUI_MINOR_VERSION >= 22
    38 typedef CGFloat EmacsCGFloat;
    39 #else
    40 typedef float EmacsCGFloat;
    41 #endif
    42 
    43 /* NSFilenamesPboardType is deprecated in macOS 10.14, but
    44    NSPasteboardTypeFileURL is only available in 10.13 (and GNUstep
    45    probably lacks it too). */
    46 #if defined NS_IMPL_COCOA && MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
    47 #define NS_USE_NSPasteboardTypeFileURL 1
    48 #else
    49 #define NS_USE_NSPasteboardTypeFileURL 0
    50 #endif
    51 
    52 /* ==========================================================================
    53 
    54    Trace support
    55 
    56    ========================================================================== */
    57 
    58 /* Uncomment the following line to enable trace.
    59 
    60    Uncomment suitable NSTRACE_GROUP_xxx lines to trace more.
    61 
    62    Hint: keep the trailing whitespace -- the version control system
    63    will reject accidental commits. */
    64 
    65 /* #define NSTRACE_ENABLED 1          */
    66 
    67 
    68 /* When non-zero, trace output is enabled for all parts, except those
    69    explicitly disabled. */
    70 /* #define NSTRACE_ALL_GROUPS     1     */
    71 
    72 /* When non-zero, trace output is enabled in the corresponding part. */
    73 /* #define NSTRACE_GROUP_EVENTS  1     */
    74 /* #define NSTRACE_GROUP_UPDATES 1     */
    75 /* #define NSTRACE_GROUP_FRINGE  1     */
    76 /* #define NSTRACE_GROUP_COLOR   1     */
    77 /* #define NSTRACE_GROUP_GLYPHS  1     */
    78 /* #define NSTRACE_GROUP_FOCUS   1     */
    79 
    80 
    81 /* Print a call tree containing all annotated functions.
    82 
    83    The call structure of the functions is represented using
    84    indentation and vertical lines.  Extra information is printed using
    85    horizontal lines that connect to the vertical line.
    86 
    87    The return value is represented using the arrow "->>".  For simple
    88    functions, the arrow can be printed on the same line as the
    89    function name.  If more output is printed, it is connected to the
    90    vertical line of the function.
    91 
    92    The first column contains the file name, the second the line
    93    number, and the third a number increasing for each trace line.
    94 
    95    Note, when trace output from several threads are mixed, the output
    96    can become misaligned, as all threads (currently) share one state.
    97    This is post prominent when the EVENTS part is enabled.
    98 
    99    Note that the trace system, when enabled, uses the GCC/Clang
   100    "cleanup" extension. */
   101 
   102 /*   For example, the following is the output of `M-x
   103      toggle-frame-maximized RET'.
   104 
   105      (Long lines manually split to reduced width):
   106 
   107 nsterm.m  : 1608: [  354]  ns_fullscreen_hook
   108 nsterm.m  : 7180: [  355]  | [EmacsView handleFS]
   109 nsterm.m  : 7209: [  356]  | +--- FULLSCREEN_MAXIMIZED
   110 nsterm.m  : 7706: [  357]  | | [EmacsWindow performZoom:]
   111 nsterm.m  : 7715: [  358]  | | | [EmacsWindow zoom:]
   112 nsterm.m  :  882: [  359]  | | | | ns_update_auto_hide_menu_bar
   113 nsterm.m  : 6752: [  360]  | | | |
   114   [EmacsView windowWillUseStandardFrame:defaultFrame:(X:0 Y:0)/(W:1600 H:1177)]
   115 nsterm.m  : 6753: [  361]  | | | | +--- fs_state: FULLSCREEN_NONE
   116 nsterm.m  : 6754: [  362]  | | | | +--- fs_before_fs: -1
   117 nsterm.m  : 6755: [  363]  | | | | +--- next_maximized: FULLSCREEN_MAXIMIZED
   118 nsterm.m  : 6756: [  364]  | | | | +--- ns_userRect: (X:0 Y:0)/(W:0 H:0)
   119 nsterm.m  : 6757: [  365]  | | | | +---
   120                                       [sender frame]: (X:0 Y:626)/(W:595 H:551)
   121 nsterm.m  : 6781: [  366]  | | | | +---
   122                                      ns_userRect (2): (X:0 Y:626)/(W:595 H:551)
   123 nsterm.m  : 6821: [  367]  | | | | +--- FULLSCREEN_MAXIMIZED
   124 nsterm.m  : 7232: [  368]  | | | | |
   125                                     [EmacsView setFSValue:FULLSCREEN_MAXIMIZED]
   126 nsterm.m  : 6848: [  369]  | | | | +---
   127                                    Final ns_userRect: (X:0 Y:626)/(W:595 H:551)
   128 nsterm.m  : 6849: [  370]  | | | | +--- Final maximized_width: 1600
   129 nsterm.m  : 6850: [  371]  | | | | +--- Final maximized_height: 1177
   130 nsterm.m  : 6851: [  372]  | | | | +--- Final next_maximized: -1
   131 nsterm.m  : 6322: [  373]  | | | | |
   132                            [EmacsView windowWillResize:toSize: (W:1600 H:1177)]
   133 nsterm.m  : 6323: [  374]  | | | | | +---
   134                                       [sender frame]: (X:0 Y:626)/(W:595 H:551)
   135 nsterm.m  : 6324: [  375]  | | | | | +--- fs_state: FULLSCREEN_MAXIMIZED
   136 nsterm.m  : 7027: [  376]  | | | | | | [EmacsView isFullscreen]
   137 nsterm.m  : 6387: [  377]  | | | | | +--- cols: 223  rows: 79
   138 nsterm.m  : 6412: [  378]  | | | | | +->> (W:1596 H:1167)
   139 nsterm.m  : 6855: [  379]  | | | | +->> (X:0 Y:0)/(W:1600 H:1177)
   140 */
   141 
   142 #ifndef NSTRACE_ENABLED
   143 #define NSTRACE_ENABLED 0
   144 #endif
   145 
   146 #if NSTRACE_ENABLED
   147 
   148 #ifndef NSTRACE_ALL_GROUPS
   149 #define NSTRACE_ALL_GROUPS 0
   150 #endif
   151 
   152 #ifndef NSTRACE_GROUP_EVENTS
   153 #define NSTRACE_GROUP_EVENTS NSTRACE_ALL_GROUPS
   154 #endif
   155 
   156 #ifndef NSTRACE_GROUP_UPDATES
   157 #define NSTRACE_GROUP_UPDATES NSTRACE_ALL_GROUPS
   158 #endif
   159 
   160 #ifndef NSTRACE_GROUP_FRINGE
   161 #define NSTRACE_GROUP_FRINGE NSTRACE_ALL_GROUPS
   162 #endif
   163 
   164 #ifndef NSTRACE_GROUP_COLOR
   165 #define NSTRACE_GROUP_COLOR NSTRACE_ALL_GROUPS
   166 #endif
   167 
   168 #ifndef NSTRACE_GROUP_GLYPHS
   169 #define NSTRACE_GROUP_GLYPHS NSTRACE_ALL_GROUPS
   170 #endif
   171 
   172 #ifndef NSTRACE_GROUP_FOCUS
   173 #define NSTRACE_GROUP_FOCUS NSTRACE_ALL_GROUPS
   174 #endif
   175 
   176 extern volatile int nstrace_num;
   177 extern volatile int nstrace_depth;
   178 extern volatile int nstrace_enabled_global;
   179 
   180 void nstrace_leave(int *);
   181 void nstrace_restore_global_trace_state(int *);
   182 char const * nstrace_fullscreen_type_name (int);
   183 
   184 /* printf-style trace output.  Output is aligned with contained heading.  */
   185 #define NSTRACE_MSG_NO_DASHES(...)                                          \
   186   do                                                                        \
   187     {                                                                       \
   188       if (nstrace_enabled)                                                  \
   189         {                                                                   \
   190           fprintf (stderr, "%-10s:%5d: [%5d]%.*s",                          \
   191                    __FILE__, __LINE__, nstrace_num++,                       \
   192                    2*nstrace_depth, "  | | | | | | | | | | | | | | | ..");  \
   193           fprintf (stderr, __VA_ARGS__);                                    \
   194           putc ('\n', stderr);                                              \
   195         }                                                                   \
   196     }                                                                       \
   197   while(0)
   198 
   199 #define NSTRACE_MSG(...) NSTRACE_MSG_NO_DASHES("+--- " __VA_ARGS__)
   200 
   201 
   202 
   203 /* Macros for printing complex types.
   204 
   205    NSTRACE_FMT_what     -- Printf format string for "what".
   206    NSTRACE_ARG_what(x)  -- Printf argument for "what".  */
   207 
   208 #define NSTRACE_FMT_SIZE        "(W:%.0f H:%.0f)"
   209 #define NSTRACE_ARG_SIZE(elt)   (elt).width, (elt).height
   210 
   211 #define NSTRACE_FMT_POINT       "(X:%.0f Y:%.0f)"
   212 #define NSTRACE_ARG_POINT(elt)  (elt).x, (elt).y
   213 
   214 #define NSTRACE_FMT_RECT        NSTRACE_FMT_POINT "/" NSTRACE_FMT_SIZE
   215 #define NSTRACE_ARG_RECT(elt)   \
   216   NSTRACE_ARG_POINT((elt).origin), NSTRACE_ARG_SIZE((elt).size)
   217 
   218 #define NSTRACE_FMT_FSTYPE      "%s"
   219 #define NSTRACE_ARG_FSTYPE(elt) nstrace_fullscreen_type_name(elt)
   220 
   221 
   222 /* Macros for printing complex types as extra information.  */
   223 
   224 #define NSTRACE_SIZE(str,size)                                          \
   225   NSTRACE_MSG (str ": " NSTRACE_FMT_SIZE,                               \
   226                NSTRACE_ARG_SIZE (size));
   227 
   228 #define NSTRACE_POINT(str,point)                                        \
   229   NSTRACE_MSG (str ": " NSTRACE_FMT_POINT,                              \
   230                NSTRACE_ARG_POINT (point));
   231 
   232 #define NSTRACE_RECT(str,rect)                                          \
   233   NSTRACE_MSG (str ": " NSTRACE_FMT_RECT,                               \
   234                NSTRACE_ARG_RECT (rect));
   235 
   236 #define NSTRACE_FSTYPE(str,fs_type)                                     \
   237   NSTRACE_MSG (str ": " NSTRACE_FMT_FSTYPE,                             \
   238                NSTRACE_ARG_FSTYPE (fs_type));
   239 
   240 
   241 /* Return value macros.
   242 
   243    NSTRACE_RETURN(fmt, ...) - Print a return value, support printf-style
   244                               format string and arguments.
   245 
   246    NSTRACE_RETURN_what(obj) - Print a return value of kind WHAT.
   247 
   248    NSTRACE_FMT_RETURN - A string literal representing a returned
   249                         value.  Useful when creating a format string
   250                         to printf-like constructs like NSTRACE().  */
   251 
   252 #define NSTRACE_FMT_RETURN "->>"
   253 
   254 #define NSTRACE_RETURN(...) \
   255   NSTRACE_MSG_NO_DASHES ("+" NSTRACE_FMT_RETURN " " __VA_ARGS__)
   256 
   257 #define NSTRACE_RETURN_SIZE(size) \
   258   NSTRACE_RETURN(NSTRACE_FMT_SIZE, NSTRACE_ARG_SIZE(size))
   259 
   260 #define NSTRACE_RETURN_POINT(point) \
   261   NSTRACE_RETURN(NSTRACE_FMT_POINT, NSTRACE_ARG_POINT(point))
   262 
   263 #define NSTRACE_RETURN_RECT(rect) \
   264   NSTRACE_RETURN(NSTRACE_FMT_RECT, NSTRACE_ARG_RECT(rect))
   265 
   266 
   267 /* Function enter macros.
   268 
   269    NSTRACE (fmt, ...) -- Enable trace output in current block
   270                          (typically a function).  Accepts printf-style
   271                          arguments.
   272 
   273    NSTRACE_WHEN (cond, fmt, ...) -- Enable trace output when COND is true.
   274 
   275    NSTRACE_UNLESS (cond, fmt, ...) -- Enable trace output unless COND is
   276                                       true.  */
   277 
   278 
   279 
   280 #define NSTRACE_WHEN(cond, ...)                                         \
   281   __attribute__((cleanup(nstrace_restore_global_trace_state)))          \
   282   int nstrace_saved_enabled_global = nstrace_enabled_global;            \
   283   __attribute__((cleanup(nstrace_leave)))                               \
   284   int nstrace_enabled = nstrace_enabled_global && (cond);               \
   285   if (nstrace_enabled) { ++nstrace_depth; }                             \
   286   else { nstrace_enabled_global = 0; }                                  \
   287   NSTRACE_MSG_NO_DASHES(__VA_ARGS__);
   288 
   289 /* Unsilence called functions.
   290 
   291    Concretely, this us used to allow "event" functions to be silenced
   292    while trace output can be printed for functions they call.  */
   293 #define NSTRACE_UNSILENCE() do { nstrace_enabled_global = 1; } while(0)
   294 
   295 #endif /* NSTRACE_ENABLED */
   296 
   297 #define NSTRACE(...)              NSTRACE_WHEN(1, __VA_ARGS__)
   298 #define NSTRACE_UNLESS(cond, ...) NSTRACE_WHEN(!(cond), __VA_ARGS__)
   299 
   300 /* Non-trace replacement versions.  */
   301 #ifndef NSTRACE_WHEN
   302 #define NSTRACE_WHEN(...)
   303 #endif
   304 
   305 #ifndef NSTRACE_MSG
   306 #define NSTRACE_MSG(...)
   307 #endif
   308 
   309 #ifndef NSTRACE_SIZE
   310 #define NSTRACE_SIZE(str,size)
   311 #endif
   312 
   313 #ifndef NSTRACE_POINT
   314 #define NSTRACE_POINT(str,point)
   315 #endif
   316 
   317 #ifndef NSTRACE_RECT
   318 #define NSTRACE_RECT(str,rect)
   319 #endif
   320 
   321 #ifndef NSTRACE_FSTYPE
   322 #define NSTRACE_FSTYPE(str,fs_type)
   323 #endif
   324 
   325 #ifndef NSTRACE_RETURN_SIZE
   326 #define NSTRACE_RETURN_SIZE(size)
   327 #endif
   328 
   329 #ifndef NSTRACE_RETURN_POINT
   330 #define NSTRACE_RETURN_POINT(point)
   331 #endif
   332 
   333 #ifndef NSTRACE_RETURN_RECT
   334 #define NSTRACE_RETURN_RECT(rect)
   335 #endif
   336 
   337 #ifndef NSTRACE_RETURN_FSTYPE
   338 #define NSTRACE_RETURN_FSTYPE(fs_type)
   339 #endif
   340 
   341 #ifndef NSTRACE_UNSILENCE
   342 #define NSTRACE_UNSILENCE()
   343 #endif
   344 
   345 
   346 /* If the compiler doesn't support instancetype, map it to id.  */
   347 #ifndef NATIVE_OBJC_INSTANCETYPE
   348 typedef id instancetype;
   349 #endif
   350 
   351 
   352 /* ==========================================================================
   353 
   354    NSColor, EmacsColor category.
   355 
   356    ========================================================================== */
   357 @interface NSColor (EmacsColor)
   358 + (NSColor *)colorForEmacsRed:(CGFloat)red green:(CGFloat)green
   359                          blue:(CGFloat)blue alpha:(CGFloat)alpha;
   360 + (NSColor *)colorWithUnsignedLong:(unsigned long)c;
   361 - (NSColor *)colorUsingDefaultColorSpace;
   362 - (unsigned long)unsignedLong;
   363 @end
   364 
   365 
   366 @interface NSString (EmacsString)
   367 + (NSString *)stringWithLispString:(Lisp_Object)string;
   368 - (Lisp_Object)lispString;
   369 @end
   370 
   371 /* ==========================================================================
   372 
   373    The Emacs application
   374 
   375    ========================================================================== */
   376 
   377 /* We override sendEvent: as a means to stop/start the event loop.  */
   378 @interface EmacsApp : NSApplication
   379 {
   380 #ifdef NS_IMPL_COCOA
   381   BOOL shouldKeepRunning;
   382   BOOL isFirst;
   383 #endif
   384 #ifdef NS_IMPL_GNUSTEP
   385   BOOL applicationDidFinishLaunchingCalled;
   386 #endif
   387 @public
   388   int nextappdefined;
   389 }
   390 - (void)logNotification: (NSNotification *)notification;
   391 - (void)antialiasThresholdDidChange:(NSNotification *)notification;
   392 - (void)sendEvent: (NSEvent *)theEvent;
   393 - (void)showPreferencesWindow: (id)sender;
   394 - (BOOL) openFile: (NSString *)fileName;
   395 - (void)fd_handler: (id)unused;
   396 - (void)timeout_handler: (NSTimer *)timedEntry;
   397 - (BOOL)fulfillService: (NSString *)name withArg: (NSString *)arg;
   398 #ifdef NS_IMPL_GNUSTEP
   399 - (void)sendFromMainThread:(id)unused;
   400 #endif
   401 @end
   402 
   403 #ifdef NS_IMPL_GNUSTEP
   404 /* Dummy class to get rid of startup warnings.  */
   405 @interface EmacsDocument : NSDocument
   406 {
   407 }
   408 @end
   409 #endif
   410 
   411 enum ns_return_frame_mode
   412   {
   413     RETURN_FRAME_NEVER,
   414     RETURN_FRAME_EVENTUALLY,
   415     RETURN_FRAME_NOW,
   416   };
   417 
   418 /* EmacsWindow  */
   419 @interface EmacsWindow : NSWindow
   420 {
   421   NSPoint grabOffset;
   422   NSEvent *last_drag_event;
   423   NSDragOperation drag_op;
   424   NSDragOperation selected_op;
   425 
   426   struct frame *dnd_return_frame;
   427   enum ns_return_frame_mode dnd_mode;
   428   BOOL dnd_allow_same_frame;
   429   BOOL dnd_move_tooltip_with_frame;
   430 }
   431 
   432 #ifdef NS_IMPL_GNUSTEP
   433 - (NSInteger) orderedIndex;
   434 #endif
   435 
   436 - (instancetype) initWithEmacsFrame: (struct frame *) f;
   437 - (instancetype) initWithEmacsFrame: (struct frame *) f
   438                          fullscreen: (BOOL) fullscreen
   439                              screen: (NSScreen *) screen;
   440 - (void) createToolbar: (struct frame *) f;
   441 - (void) setParentChildRelationships;
   442 - (NSInteger) borderWidth;
   443 - (BOOL) restackWindow: (NSWindow *) win above: (BOOL) above;
   444 - (void) setAppearance;
   445 - (void) setLastDragEvent: (NSEvent *) event;
   446 - (NSDragOperation) beginDrag: (NSDragOperation) op
   447                 forPasteboard: (NSPasteboard *) pasteboard
   448                      withMode: (enum ns_return_frame_mode) mode
   449                 returnFrameTo: (struct frame **) frame_return
   450                  prohibitSame: (BOOL) prohibit_same_frame
   451                 followTooltip: (BOOL) follow_tooltip;
   452 - (BOOL) mustNotDropOn: (NSView *) receiver;
   453 @end
   454 
   455 
   456 /* ==========================================================================
   457 
   458    The main Emacs view
   459 
   460    ========================================================================== */
   461 
   462 @class EmacsToolbar;
   463 @class EmacsLayer;
   464 
   465 #ifdef NS_IMPL_COCOA
   466 @interface EmacsView : NSView <NSTextInput, NSWindowDelegate>
   467 #else
   468 @interface EmacsView : NSView <NSTextInput>
   469 #endif
   470 {
   471 #ifdef NS_IMPL_COCOA
   472   char *old_title;
   473   BOOL maximizing_resize;
   474 #endif
   475   BOOL font_panel_active;
   476   NSFont *font_panel_result;
   477   BOOL windowClosing;
   478   NSString *workingText;
   479   BOOL processingCompose;
   480   int fs_state, fs_before_fs, next_maximized;
   481   int maximized_width, maximized_height;
   482   EmacsWindow *nonfs_window;
   483   BOOL fs_is_native;
   484 @public
   485   struct frame *emacsframe;
   486   int scrollbarsNeedingUpdate;
   487   NSRect ns_userRect;
   488 }
   489 
   490 /* AppKit-side interface */
   491 - (instancetype)menuDown: (id)sender;
   492 - (instancetype)toolbarClicked: (id)item;
   493 - (instancetype)toggleToolbar: (id)sender;
   494 - (void)keyDown: (NSEvent *)theEvent;
   495 - (void)mouseDown: (NSEvent *)theEvent;
   496 - (void)mouseUp: (NSEvent *)theEvent;
   497 - (instancetype)setMiniwindowImage: (BOOL)setMini;
   498 
   499 /* Emacs-side interface */
   500 - (instancetype) initFrameFromEmacs: (struct frame *) f;
   501 - (void) setWindowClosing: (BOOL)closing;
   502 - (void) deleteWorkingText;
   503 - (void) handleFS;
   504 - (void) setFSValue: (int)value;
   505 - (void) toggleFullScreen: (id) sender;
   506 - (BOOL) fsIsNative;
   507 - (BOOL) isFullscreen;
   508 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
   509 - (void) updateCollectionBehavior;
   510 #endif
   511 
   512 #ifdef NS_IMPL_GNUSTEP
   513 - (void)windowDidMove: (id)sender;
   514 #endif
   515 - (Lisp_Object) showFontPanel;
   516 - (int)fullscreenState;
   517 
   518 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
   519 - (void)lockFocus;
   520 - (void)unlockFocus;
   521 #endif
   522 - (void)copyRect:(NSRect)srcRect to:(NSPoint)dest;
   523 
   524 /* Non-notification versions of NSView methods. Used for direct calls.  */
   525 - (void)windowWillEnterFullScreen;
   526 - (void)windowDidEnterFullScreen;
   527 - (void)windowWillExitFullScreen;
   528 - (void)windowDidExitFullScreen;
   529 - (void)windowDidBecomeKey;
   530 @end
   531 
   532 
   533 /* ==========================================================================
   534 
   535    The main menu implementation
   536 
   537    ========================================================================== */
   538 
   539 @interface EmacsMenu : NSMenu  <NSMenuDelegate>
   540 {
   541   BOOL needsUpdate;
   542 }
   543 
   544 - (void)menuNeedsUpdate: (NSMenu *)menu; /* (delegate method) */
   545 - (NSMenuItem *)addItemWithWidgetValue: (void *)wvptr
   546                             attributes: (NSDictionary *)attributes;
   547 - (void)fillWithWidgetValue: (void *)wvptr;
   548 - (EmacsMenu *)addSubmenuWithTitle: (const char *)title;
   549 - (void) removeAllItems;
   550 - (Lisp_Object)runMenuAt: (NSPoint)p forFrame: (struct frame *)f
   551                  keymaps: (bool)keymaps;
   552 @end
   553 
   554 
   555 /* ==========================================================================
   556 
   557    Toolbar
   558 
   559    ========================================================================== */
   560 
   561 @class EmacsImage;
   562 
   563 #ifdef NS_IMPL_COCOA
   564 @interface EmacsToolbar : NSToolbar <NSToolbarDelegate>
   565 #else
   566 @interface EmacsToolbar : NSToolbar
   567 #endif
   568    {
   569      EmacsView *emacsView;
   570      NSMutableDictionary *identifierToItem;
   571      NSMutableArray *activeIdentifiers;
   572      NSArray *prevIdentifiers;
   573      unsigned long enablement, prevEnablement;
   574    }
   575 - (instancetype) initForView: (EmacsView *)view withIdentifier: (NSString *)identifier;
   576 - (void) clearActive;
   577 - (void) clearAll;
   578 - (BOOL) changed;
   579 - (void) addDisplayItemWithImage: (EmacsImage *)img
   580                              idx: (int)idx
   581                              tag: (int)tag
   582                        labelText: (NSString *)label
   583                         helpText: (NSString *)help
   584                          enabled: (BOOL)enabled;
   585 
   586 /* delegate methods */
   587 - (NSToolbarItem *)toolbar: (NSToolbar *)toolbar
   588      itemForItemIdentifier: (NSString *)itemIdentifier
   589  willBeInsertedIntoToolbar: (BOOL)flag;
   590 - (NSArray *)toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar;
   591 - (NSArray *)toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar;
   592 @end
   593 
   594 
   595 /* ==========================================================================
   596 
   597    Message / question windows
   598 
   599    ========================================================================== */
   600 
   601 @interface EmacsDialogPanel : NSPanel
   602 {
   603   NSTextField *command;
   604   NSTextField *title;
   605   NSMatrix *matrix;
   606   int rows, cols;
   607   BOOL timer_fired, window_closed;
   608   Lisp_Object dialog_return;
   609 }
   610 
   611 - (instancetype) initWithTitle: (char *) title_str
   612                     isQuestion: (BOOL) is_question;
   613 - (void) processMenuItems: (Lisp_Object) menu_items
   614                      used: (ptrdiff_t) menu_items_used
   615           withErrorOutput: (const char **) error_name;
   616 
   617 - (void) addButton: (char *) str
   618              value: (NSInteger) tag
   619                row: (int) row
   620             enable: (BOOL) enable;
   621 - (void) addString: (char *) str
   622                row: (int) row;
   623 - (void) addSplit;
   624 - (void) resizeBoundsPriorToDisplay;
   625 
   626 - (Lisp_Object) runDialogAt: (NSPoint) p;
   627 - (void) timeout_handler: (NSTimer *) timedEntry;
   628 @end
   629 
   630 #ifdef NS_IMPL_COCOA
   631 @interface EmacsTooltip : NSObject <NSWindowDelegate>
   632 #else
   633 @interface EmacsTooltip : NSObject
   634 #endif
   635 {
   636   NSWindow *win;
   637   NSTextField *textField;
   638   NSTimer *timer;
   639 }
   640 
   641 - (instancetype) init;
   642 - (void) setText: (char *) text;
   643 - (void) setBackgroundColor: (NSColor *) col;
   644 - (void) setForegroundColor: (NSColor *) col;
   645 - (void) showAtX: (int) x Y: (int) y for: (int) seconds;
   646 - (void) hide;
   647 - (BOOL) isActive;
   648 - (NSRect) frame;
   649 - (void) moveTo: (NSPoint) screen_point;
   650 @end
   651 
   652 
   653 @interface EmacsFileDelegate : NSObject
   654 {
   655 }
   656 - (BOOL)panel: (id)sender isValidFilename: (NSString *)filename;
   657 - (BOOL)panel: (id)sender shouldShowFilename: (NSString *)filename;
   658 - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
   659           confirmed: (BOOL)okFlag;
   660 @end
   661 
   662 
   663 /* ==========================================================================
   664 
   665    Images and stippling
   666 
   667    ========================================================================== */
   668 
   669 @interface EmacsImage : NSImage
   670 {
   671   NSBitmapImageRep *bmRep; /* used for accessing pixel data */
   672   unsigned char *pixmapData[5]; /* shortcut to access pixel data */
   673   NSColor *stippleMask;
   674 @public
   675   NSAffineTransform *transform;
   676   BOOL smoothing;
   677 }
   678 + (instancetype)allocInitFromFile: (Lisp_Object)file;
   679 - (void)dealloc;
   680 - (instancetype)initFromXBM: (unsigned char *)bits width: (int)w height: (int)h
   681                          fg: (unsigned long)fg bg: (unsigned long)bg
   682                reverseBytes: (BOOL)reverse;
   683 - (instancetype)initForXPMWithDepth: (int)depth width: (int)width height: (int)height;
   684 - (void)setPixmapData;
   685 - (unsigned long)getPixelAtX: (int)x Y: (int)y;
   686 - (void)setPixelAtX: (int)x Y: (int)y toRed: (unsigned char)r
   687                green: (unsigned char)g blue: (unsigned char)b
   688               alpha:(unsigned char)a;
   689 - (void)setAlphaAtX: (int)x Y: (int)y to: (unsigned char)a;
   690 - (NSColor *)stippleMask;
   691 - (Lisp_Object)getMetadata;
   692 - (BOOL)setFrame: (unsigned int) index;
   693 - (void)setTransform: (double[3][3]) m;
   694 - (void)setSmoothing: (BOOL)s;
   695 - (size_t)sizeInBytes;
   696 @end
   697 
   698 
   699 /* ==========================================================================
   700 
   701    Scrollbars
   702 
   703    ========================================================================== */
   704 
   705 @interface EmacsScroller : NSScroller
   706   {
   707    struct window *window;
   708    struct frame *frame;
   709    NSResponder *prevResponder;
   710 
   711    /* offset to the bottom of knob of last mouse down */
   712    CGFloat last_mouse_offset;
   713    float min_portion;
   714    int pixel_length;
   715    enum scroll_bar_part last_hit_part;
   716 
   717    BOOL condemned;
   718 
   719    BOOL horizontal;
   720 
   721    /* optimize against excessive positioning calls generated by emacs */
   722    int em_position;
   723    int em_portion;
   724    int em_whole;
   725    }
   726 
   727 - (void) mark;
   728 - (instancetype) initFrame: (NSRect )r window: (Lisp_Object)win;
   729 - (void)setFrame: (NSRect)r;
   730 
   731 - (instancetype) setPosition: (int) position portion: (int) portion whole: (int) whole;
   732 - (int) checkSamePosition: (int)position portion: (int)portion
   733                     whole: (int)whole;
   734 - (void) sendScrollEventAtLoc: (float)loc fromEvent: (NSEvent *)e;
   735 - (instancetype)repeatScroll: (NSTimer *)sender;
   736 - (instancetype)condemn;
   737 - (instancetype)reprieve;
   738 - (bool)judge;
   739 + (CGFloat)scrollerWidth;
   740 @end
   741 
   742 #if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
   743 @interface EmacsLayer : CALayer
   744 {
   745   NSMutableArray *cache;
   746   CGColorSpaceRef colorSpace;
   747   IOSurfaceRef currentSurface;
   748   CGContextRef context;
   749 }
   750 - (id) initWithColorSpace: (CGColorSpaceRef)cs;
   751 - (void) setColorSpace: (CGColorSpaceRef)cs;
   752 - (CGContextRef) getContext;
   753 @end
   754 #endif
   755 
   756 
   757 /* ==========================================================================
   758 
   759    Rendering
   760 
   761    ========================================================================== */
   762 
   763 extern NSArray *ns_send_types, *ns_return_types;
   764 extern NSString *ns_app_name;
   765 extern EmacsMenu *svcsMenu;
   766 
   767 /* Apple removed the declaration, but kept the implementation.  */
   768 #if defined (NS_IMPL_COCOA)
   769 @interface NSApplication (EmacsApp)
   770 - (void)setAppleMenu: (NSMenu *)menu;
   771 @end
   772 #endif
   773 
   774 #endif  /* __OBJC__ */
   775 
   776 
   777 
   778 /* ==========================================================================
   779 
   780    Non-OO stuff
   781 
   782    ========================================================================== */
   783 
   784 /* Special keycodes that we pass down the event chain */
   785 #define KEY_NS_POWER_OFF               ((1<<28)|(0<<16)|1)
   786 #define KEY_NS_OPEN_FILE               ((1<<28)|(0<<16)|2)
   787 #define KEY_NS_OPEN_TEMP_FILE          ((1<<28)|(0<<16)|3)
   788 #define KEY_NS_CHANGE_FONT             ((1<<28)|(0<<16)|7)
   789 #define KEY_NS_OPEN_FILE_LINE          ((1<<28)|(0<<16)|8)
   790 #define KEY_NS_PUT_WORKING_TEXT        ((1<<28)|(0<<16)|9)
   791 #define KEY_NS_UNPUT_WORKING_TEXT      ((1<<28)|(0<<16)|10)
   792 #define KEY_NS_SPI_SERVICE_CALL        ((1<<28)|(0<<16)|11)
   793 #define KEY_NS_NEW_FRAME               ((1<<28)|(0<<16)|12)
   794 #define KEY_NS_TOGGLE_TOOLBAR          ((1<<28)|(0<<16)|13)
   795 #define KEY_NS_SHOW_PREFS              ((1<<28)|(0<<16)|14)
   796 
   797 /* Could use list to store these, but rest of emacs has a big infrastructure
   798    for managing a table of bitmap "records".  */
   799 struct ns_bitmap_record
   800 {
   801 #ifdef __OBJC__
   802   EmacsImage *img;
   803 #else
   804   void *img;
   805 #endif
   806   char *file;
   807   int refcount;
   808   int height, width, depth;
   809 };
   810 
   811 #ifdef NS_IMPL_GNUSTEP
   812 /* this extends font backend font */
   813 struct nsfont_info
   814 {
   815   struct font font;
   816 
   817   char *name;  /* PostScript name, uniquely identifies on NS systems */
   818 
   819   /* The following metrics are stored as float rather than int.  */
   820 
   821   float width;  /* Maximum advance for the font.  */
   822   float height;
   823   float underpos;
   824   float underwidth;
   825   float size;
   826 #ifdef __OBJC__
   827   NSFont *nsfont;
   828 #else /* ! OBJC */
   829   void *nsfont;
   830 #endif
   831   char bold, ital;  /* convenience flags */
   832   char synthItal;
   833   XCharStruct max_bounds;
   834   /* We compute glyph codes and metrics on-demand in blocks of 256 indexed
   835      by hibyte, lobyte.  */
   836   unsigned int **glyphs; /* map Unicode index to glyph */
   837   struct font_metrics **metrics;
   838 };
   839 #endif
   840 
   841 /* Initialized in ns_initialize_display_info ().  */
   842 struct ns_display_info
   843 {
   844   /* Chain of all ns_display_info structures.  */
   845   struct ns_display_info *next;
   846 
   847   /* The generic display parameters corresponding to this NS display.  */
   848   struct terminal *terminal;
   849 
   850   /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).  */
   851   Lisp_Object name_list_element;
   852 
   853   /* The number of fonts loaded.  */
   854   int n_fonts;
   855 
   856   /* Minimum width over all characters in all fonts in font_table.  */
   857   int smallest_char_width;
   858 
   859   /* Minimum font height over all fonts in font_table.  */
   860   int smallest_font_height;
   861 
   862   struct ns_bitmap_record *bitmaps;
   863   ptrdiff_t bitmaps_size;
   864   ptrdiff_t bitmaps_last;
   865 
   866   /* DPI resolution of this screen */
   867   double resx, resy;
   868 
   869   /* Mask of things that cause the mouse to be grabbed */
   870   int grabbed;
   871 
   872   int n_planes;
   873 
   874   int color_p;
   875 
   876   Window root_window;
   877 
   878   /* Xism */
   879   Lisp_Object rdb;
   880 
   881   /* The cursor to use for vertical scroll bars.  */
   882   Emacs_Cursor vertical_scroll_bar_cursor;
   883 
   884   /* The cursor to use for horizontal scroll bars.  */
   885   Emacs_Cursor horizontal_scroll_bar_cursor;
   886 
   887   /* Information about the range of text currently shown in
   888      mouse-face.  */
   889   Mouse_HLInfo mouse_highlight;
   890 
   891   struct frame *highlight_frame;
   892   struct frame *ns_focus_frame;
   893 
   894   /* The frame where the mouse was last time we reported a mouse event.  */
   895   struct frame *last_mouse_frame;
   896 
   897   /* The frame where the mouse was last time we reported a mouse motion.  */
   898   struct frame *last_mouse_motion_frame;
   899 
   900   /* Position where the mouse was last time we reported a motion.
   901      This is a position on last_mouse_motion_frame.  */
   902   int last_mouse_motion_x;
   903   int last_mouse_motion_y;
   904 
   905   /* Where the mouse was last time we reported a mouse position.  */
   906   NSRect last_mouse_glyph;
   907 
   908   /* Time of last mouse movement.  */
   909   Time last_mouse_movement_time;
   910 
   911   /* The scroll bar in which the last motion event occurred.  */
   912 #ifdef __OBJC__
   913   EmacsScroller *last_mouse_scroll_bar;
   914 #else
   915   void *last_mouse_scroll_bar;
   916 #endif
   917 };
   918 
   919 /* This is a chain of structures for all the NS displays currently in use.  */
   920 extern struct ns_display_info *x_display_list;
   921 
   922 struct ns_output
   923 {
   924 #ifdef __OBJC__
   925   EmacsView *view;
   926   id miniimage;
   927   NSColor *cursor_color;
   928   NSColor *foreground_color;
   929   NSColor *background_color;
   930   NSColor *relief_background_color;
   931   NSColor *light_relief_color;
   932   NSColor *dark_relief_color;
   933   EmacsToolbar *toolbar;
   934 #else
   935   void *view;
   936   void *miniimage;
   937   void *cursor_color;
   938   void *foreground_color;
   939   void *background_color;
   940   void *relief_background_color;
   941   void *light_relief_color;
   942   void *dark_relief_color;
   943   void *toolbar;
   944 #endif
   945 
   946   /* NSCursors are initialized in initFrameFromEmacs.  */
   947   Emacs_Cursor text_cursor;
   948   Emacs_Cursor nontext_cursor;
   949   Emacs_Cursor modeline_cursor;
   950   Emacs_Cursor hand_cursor;
   951   Emacs_Cursor hourglass_cursor;
   952   Emacs_Cursor horizontal_drag_cursor;
   953   Emacs_Cursor vertical_drag_cursor;
   954   Emacs_Cursor left_edge_cursor;
   955   Emacs_Cursor top_left_corner_cursor;
   956   Emacs_Cursor top_edge_cursor;
   957   Emacs_Cursor top_right_corner_cursor;
   958   Emacs_Cursor right_edge_cursor;
   959   Emacs_Cursor bottom_right_corner_cursor;
   960   Emacs_Cursor bottom_edge_cursor;
   961   Emacs_Cursor bottom_left_corner_cursor;
   962 
   963   /* NS-specific */
   964   Emacs_Cursor current_pointer;
   965 
   966   /* lord knows why Emacs needs to know about our Window ids.. */
   967   Window window_desc, parent_desc;
   968   char explicit_parent;
   969 
   970   struct font *font;
   971   int baseline_offset;
   972 
   973   /* If a fontset is specified for this frame instead of font, this
   974      value contains an ID of the fontset, else -1.  */
   975   int fontset; /* only used with font_backend */
   976 
   977   int icon_top;
   978   int icon_left;
   979 
   980   /* The size of the extra width currently allotted for vertical
   981      scroll bars, in pixels.  */
   982   int vertical_scroll_bar_extra;
   983 
   984   /* The height of the titlebar decoration (included in NSWindow's frame).  */
   985   int titlebar_height;
   986 
   987   /* The height of the toolbar if displayed, else 0.  */
   988   int toolbar_height;
   989 
   990   /* This is the Emacs structure for the NS display this frame is on.  */
   991   struct ns_display_info *display_info;
   992 
   993   /* Non-zero if we are zooming (maximizing) the frame.  */
   994   int zooming;
   995 
   996   /* Non-zero if we are doing an animation, e.g. toggling the tool bar.  */
   997   int in_animation;
   998 
   999 #ifdef NS_IMPL_GNUSTEP
  1000   /* Zero if this is the first time a toolbar has been updated on this
  1001      frame. */
  1002   int tool_bar_adjusted;
  1003 #endif
  1004 };
  1005 
  1006 /* This dummy declaration needed to support TTYs.  */
  1007 struct x_output
  1008 {
  1009   int unused;
  1010 };
  1011 
  1012 
  1013 /* This gives the ns_display_info structure for the display F is on.  */
  1014 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.ns->display_info)
  1015 #define FRAME_OUTPUT_DATA(f) ((f)->output_data.ns)
  1016 #define FRAME_NS_WINDOW(f) ((f)->output_data.ns->window_desc)
  1017 #define FRAME_NATIVE_WINDOW(f) FRAME_NS_WINDOW (f)
  1018 
  1019 #define FRAME_FOREGROUND_COLOR(f) ((f)->output_data.ns->foreground_color)
  1020 #define FRAME_BACKGROUND_COLOR(f) ((f)->output_data.ns->background_color)
  1021 
  1022 #define NS_FACE_FOREGROUND(f) ((f)->foreground)
  1023 #define NS_FACE_BACKGROUND(f) ((f)->background)
  1024 
  1025 #define FRAME_DEFAULT_FACE(f) FACE_FROM_ID_OR_NULL (f, DEFAULT_FACE_ID)
  1026 
  1027 #define FRAME_NS_VIEW(f) ((f)->output_data.ns->view)
  1028 #define FRAME_CURSOR_COLOR(f) ((f)->output_data.ns->cursor_color)
  1029 #define FRAME_POINTER_TYPE(f) ((f)->output_data.ns->current_pointer)
  1030 
  1031 #define FRAME_FONT(f) ((f)->output_data.ns->font)
  1032 
  1033 #ifdef __OBJC__
  1034 #define XNS_SCROLL_BAR(vec) ((id) xmint_pointer (vec))
  1035 #else
  1036 #define XNS_SCROLL_BAR(vec) xmint_pointer (vec)
  1037 #endif
  1038 
  1039 /* Compute pixel height of the frame's titlebar.  */
  1040 #define FRAME_NS_TITLEBAR_HEIGHT(f)                                     \
  1041   (NSHeight([FRAME_NS_VIEW (f) frame]) == 0 ?                           \
  1042    0                                                                    \
  1043    : (int)(NSHeight([FRAME_NS_VIEW (f) window].frame)                   \
  1044            - NSHeight([NSWindow contentRectForFrameRect:                \
  1045                        [[FRAME_NS_VIEW (f) window] frame]               \
  1046                        styleMask:[[FRAME_NS_VIEW (f) window] styleMask]])))
  1047 
  1048 /* Compute pixel height of the toolbar.  */
  1049 #define FRAME_TOOLBAR_HEIGHT(f)                                         \
  1050   (([[FRAME_NS_VIEW (f) window] toolbar] == nil                         \
  1051     || ! [[FRAME_NS_VIEW (f) window] toolbar].isVisible) ?              \
  1052    0                                                                    \
  1053    : (int)(NSHeight([NSWindow contentRectForFrameRect:                  \
  1054                      [[FRAME_NS_VIEW (f) window] frame]                 \
  1055                      styleMask:[[FRAME_NS_VIEW (f) window] styleMask]]) \
  1056            - NSHeight([[[FRAME_NS_VIEW (f) window] contentView] frame])))
  1057 
  1058 /* Compute pixel size for vertical scroll bars.  */
  1059 #define NS_SCROLL_BAR_WIDTH(f)                                          \
  1060   (FRAME_HAS_VERTICAL_SCROLL_BARS (f)                                   \
  1061    ? rint (FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0                        \
  1062            ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f)                          \
  1063            : (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f)))      \
  1064    : 0)
  1065 
  1066 /* Compute pixel size for horizontal scroll bars.  */
  1067 #define NS_SCROLL_BAR_HEIGHT(f)                                         \
  1068   (FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)                                 \
  1069    ? rint (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0                       \
  1070            ? FRAME_CONFIG_SCROLL_BAR_HEIGHT (f)                         \
  1071            : (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f)))      \
  1072    : 0)
  1073 
  1074 /* Difference between char-column-calculated and actual SB widths.
  1075    This is only a concern for rendering when SB on left.  */
  1076 #define NS_SCROLL_BAR_ADJUST(w, f)                              \
  1077   (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w) ?                 \
  1078    (FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f)          \
  1079     - NS_SCROLL_BAR_WIDTH (f)) : 0)
  1080 
  1081 /* Difference between char-line-calculated and actual SB heights.
  1082    This is only a concern for rendering when SB on top.  */
  1083 #define NS_SCROLL_BAR_ADJUST_HORIZONTALLY(w, f)         \
  1084   (WINDOW_HAS_HORIZONTAL_SCROLL_BARS (w) ?              \
  1085    (FRAME_SCROLL_BAR_LINES (f) * FRAME_LINE_HEIGHT (f)  \
  1086     - NS_SCROLL_BAR_HEIGHT (f)) : 0)
  1087 
  1088 #define FRAME_NS_FONT_TABLE(f) (FRAME_DISPLAY_INFO (f)->font_table)
  1089 
  1090 #define FRAME_FONTSET(f) ((f)->output_data.ns->fontset)
  1091 
  1092 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.ns->baseline_offset)
  1093 #define BLACK_PIX_DEFAULT(f) 0x000000
  1094 #define WHITE_PIX_DEFAULT(f) 0xFFFFFF
  1095 
  1096 /* First position where characters can be shown (instead of scrollbar, if
  1097    it is on left.  */
  1098 #define FIRST_CHAR_POSITION(f)                          \
  1099   (! (FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f)) ? 0   \
  1100    : FRAME_SCROLL_BAR_COLS (f))
  1101 
  1102 extern struct ns_display_info *ns_term_init (Lisp_Object display_name);
  1103 extern void ns_term_shutdown (int sig);
  1104 
  1105 /* constants for text rendering */
  1106 #define NS_DUMPGLYPH_NORMAL             0
  1107 #define NS_DUMPGLYPH_CURSOR             1
  1108 #define NS_DUMPGLYPH_FOREGROUND         2
  1109 #define NS_DUMPGLYPH_MOUSEFACE          3
  1110 
  1111 
  1112 #ifdef NS_IMPL_GNUSTEP
  1113 /* In nsfont, called from fontset.c */
  1114 extern void nsfont_make_fontset_for_font (Lisp_Object name,
  1115                                          Lisp_Object font_object);
  1116 
  1117 /* In nsfont, for debugging */
  1118 struct glyph_string;
  1119 void ns_dump_glyphstring (struct glyph_string *s) EXTERNALLY_VISIBLE;
  1120 #endif
  1121 
  1122 /* Implemented in nsterm, published in or needed from nsfns.  */
  1123 extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern,
  1124                                   int size, int maxnames);
  1125 extern void ns_clear_frame (struct frame *f);
  1126 
  1127 extern void ns_set_offset (struct frame *f, int xoff, int yoff,
  1128                            int change_grav);
  1129 
  1130 extern const char *ns_xlfd_to_fontname (const char *xlfd);
  1131 
  1132 extern Lisp_Object ns_map_event_to_object (void);
  1133 #ifdef __OBJC__
  1134 extern Lisp_Object ns_string_from_pasteboard (id pb);
  1135 extern void ns_string_to_pasteboard (id pb, Lisp_Object str);
  1136 #endif
  1137 extern Lisp_Object ns_get_local_selection (Lisp_Object selection_name,
  1138                                            Lisp_Object target_type);
  1139 extern void nxatoms_of_nsselect (void);
  1140 extern void ns_set_doc_edited (void);
  1141 
  1142 extern bool
  1143 ns_defined_color (struct frame *f,
  1144                   const char *name,
  1145                   Emacs_Color *color_def, bool alloc,
  1146                   bool makeIndex);
  1147 
  1148 #ifdef __OBJC__
  1149 extern int ns_lisp_to_color (Lisp_Object color, NSColor **col);
  1150 extern const char *ns_get_pending_menu_title (void);
  1151 #endif
  1152 
  1153 /* Implemented in nsfns, published in nsterm.  */
  1154 #ifdef __OBJC__
  1155 extern void ns_move_tooltip_to_mouse_location (NSPoint);
  1156 #endif
  1157 extern void ns_implicitly_set_name (struct frame *f, Lisp_Object arg,
  1158                                     Lisp_Object oldval);
  1159 extern void ns_set_scroll_bar_default_width (struct frame *f);
  1160 extern void ns_set_scroll_bar_default_height (struct frame *f);
  1161 extern void ns_change_tab_bar_height (struct frame *f, int height);
  1162 extern const char *ns_get_string_resource (void *_rdb,
  1163                                            const char *name,
  1164                                            const char *class);
  1165 
  1166 /* C access to ObjC functionality */
  1167 extern void  ns_release_object (void *obj);
  1168 extern void  ns_retain_object (void *obj);
  1169 extern void *ns_alloc_autorelease_pool (void);
  1170 extern void ns_release_autorelease_pool (void *);
  1171 extern const char *ns_get_defaults_value (const char *key);
  1172 extern void ns_init_locale (void);
  1173 
  1174 /* in nsmenu */
  1175 extern void update_frame_tool_bar (struct frame *f);
  1176 #ifdef __OBJC__
  1177 extern void update_frame_tool_bar_1 (struct frame *f, EmacsToolbar *toolbar);
  1178 #endif
  1179 
  1180 extern void free_frame_tool_bar (struct frame *f);
  1181 extern Lisp_Object find_and_return_menu_selection (struct frame *f,
  1182                                                    bool keymaps,
  1183                                                    void *client_data);
  1184 extern Lisp_Object ns_popup_dialog (struct frame *, Lisp_Object header,
  1185                                     Lisp_Object contents);
  1186 
  1187 extern void ns_free_frame_resources (struct frame *);
  1188 
  1189 #define NSAPP_DATA2_RUNASSCRIPT 10
  1190 extern void ns_run_ascript (void);
  1191 
  1192 #define NSAPP_DATA2_RUNFILEDIALOG 11
  1193 extern void ns_run_file_dialog (void);
  1194 
  1195 extern const char *ns_relocate (const char *epath);
  1196 extern void syms_of_nsterm (void);
  1197 extern void syms_of_nsfns (void);
  1198 extern void syms_of_nsmenu (void);
  1199 extern void syms_of_nsselect (void);
  1200 
  1201 /* From nsimage.m, needed in image.c */
  1202 struct image;
  1203 extern bool ns_can_use_native_image_api (Lisp_Object type);
  1204 extern void *ns_image_from_XBM (char *bits, int width, int height,
  1205                                 unsigned long fg, unsigned long bg);
  1206 extern void *ns_image_for_XPM (int width, int height, int depth);
  1207 extern void *ns_image_from_file (Lisp_Object file);
  1208 extern bool ns_load_image (struct frame *f, struct image *img,
  1209                            Lisp_Object spec_file, Lisp_Object spec_data);
  1210 extern int ns_image_width (void *img);
  1211 extern int ns_image_height (void *img);
  1212 extern void ns_image_set_size (void *img, int width, int height);
  1213 extern void ns_image_set_transform (void *img, double m[3][3]);
  1214 extern void ns_image_set_smoothing (void *img, bool smooth);
  1215 extern unsigned long ns_get_pixel (void *img, int x, int y);
  1216 extern void ns_put_pixel (void *img, int x, int y, unsigned long argb);
  1217 extern void ns_set_alpha (void *img, int x, int y, unsigned char a);
  1218 
  1219 extern int ns_display_pixel_height (struct ns_display_info *);
  1220 extern int ns_display_pixel_width (struct ns_display_info *);
  1221 extern size_t ns_image_size_in_bytes (void *img);
  1222 
  1223 /* This in nsterm.m */
  1224 extern float ns_antialias_threshold;
  1225 extern void ns_make_frame_visible (struct frame *f);
  1226 extern void ns_make_frame_invisible (struct frame *f);
  1227 extern void ns_iconify_frame (struct frame *f);
  1228 extern void ns_set_undecorated (struct frame *f, Lisp_Object new_value,
  1229                                 Lisp_Object old_value);
  1230 extern void ns_set_parent_frame (struct frame *f, Lisp_Object new_value,
  1231                                  Lisp_Object old_value);
  1232 extern void ns_set_no_focus_on_map (struct frame *f, Lisp_Object new_value,
  1233                                     Lisp_Object old_value);
  1234 extern void ns_set_no_accept_focus (struct frame *f, Lisp_Object new_value,
  1235                                     Lisp_Object old_value);
  1236 extern void ns_set_z_group (struct frame *f, Lisp_Object new_value,
  1237                             Lisp_Object old_value);
  1238 #ifdef NS_IMPL_COCOA
  1239 extern void ns_set_appearance (struct frame *f, Lisp_Object new_value,
  1240                                Lisp_Object old_value);
  1241 extern void ns_set_transparent_titlebar (struct frame *f,
  1242                                          Lisp_Object new_value,
  1243                                          Lisp_Object old_value);
  1244 #endif
  1245 extern int ns_select (int nfds, fd_set *readfds, fd_set *writefds,
  1246                       fd_set *exceptfds, struct timespec *timeout,
  1247                       sigset_t *sigmask);
  1248 #ifdef HAVE_PTHREAD
  1249 extern void ns_run_loop_break (void);
  1250 #endif
  1251 extern unsigned long ns_get_rgb_color (struct frame *f,
  1252                                        float r, float g, float b, float a);
  1253 
  1254 struct input_event;
  1255 extern void ns_init_events (struct input_event *);
  1256 extern void ns_finish_events (void);
  1257 
  1258 extern double ns_frame_scale_factor (struct frame *);
  1259 
  1260 #ifdef NS_IMPL_GNUSTEP
  1261 extern char gnustep_base_version[];  /* version tracking */
  1262 #endif
  1263 
  1264 #define MINWIDTH 10
  1265 #define MINHEIGHT 10
  1266 
  1267 /* Screen max coordinate -- using larger coordinates causes
  1268    movewindow/placewindow to abort.  */
  1269 #define SCREENMAX 16000
  1270 
  1271 #define NS_SCROLL_BAR_WIDTH_DEFAULT     [EmacsScroller scrollerWidth]
  1272 #define NS_SCROLL_BAR_HEIGHT_DEFAULT    [EmacsScroller scrollerHeight]
  1273 /* This is to match emacs on other platforms, ugly though it is.  */
  1274 #define NS_SELECTION_BG_COLOR_DEFAULT   @"LightGoldenrod2";
  1275 #define NS_SELECTION_FG_COLOR_DEFAULT   @"Black";
  1276 #define RESIZE_HANDLE_SIZE 12
  1277 
  1278 /* Little utility macros */
  1279 #define IN_BOUND(min, x, max) (((x) < (min)) \
  1280                                 ? (min) : (((x)>(max)) ? (max) : (x)))
  1281 #define SCREENMAXBOUND(x) (IN_BOUND (-SCREENMAX, x, SCREENMAX))
  1282 
  1283 
  1284 #ifdef NS_IMPL_COCOA
  1285 /* Add some required AppKit version numbers if they're not defined.  */
  1286 #ifndef NSAppKitVersionNumber10_7
  1287 #define NSAppKitVersionNumber10_7 1138
  1288 #endif
  1289 
  1290 #ifndef NSAppKitVersionNumber10_10
  1291 #define NSAppKitVersionNumber10_10 1343
  1292 #endif
  1293 #endif /* NS_IMPL_COCOA */
  1294 
  1295 
  1296 /* macOS 10.7 introduces some new constants.  */
  1297 #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_7)
  1298 #define NSFullScreenWindowMask                      (1 << 14)
  1299 #define NSWindowCollectionBehaviorFullScreenPrimary (1 << 7)
  1300 #define NSWindowCollectionBehaviorFullScreenAuxiliary (1 << 8)
  1301 #define NSApplicationPresentationFullScreen         (1 << 10)
  1302 #define NSApplicationPresentationAutoHideToolbar    (1 << 11)
  1303 #define NSAppKitVersionNumber10_7                   1138
  1304 #endif /* !defined (MAC_OS_X_VERSION_10_7) */
  1305 
  1306 /* macOS 10.12 deprecates a bunch of constants.  */
  1307 #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_12)
  1308 #define NSEventModifierFlagCommand         NSCommandKeyMask
  1309 #define NSEventModifierFlagControl         NSControlKeyMask
  1310 #define NSEventModifierFlagHelp            NSHelpKeyMask
  1311 #define NSEventModifierFlagNumericPad      NSNumericPadKeyMask
  1312 #define NSEventModifierFlagOption          NSAlternateKeyMask
  1313 #define NSEventModifierFlagShift           NSShiftKeyMask
  1314 #define NSCompositingOperationSourceOver   NSCompositeSourceOver
  1315 #define NSEventMaskApplicationDefined      NSApplicationDefinedMask
  1316 #define NSEventTypeApplicationDefined      NSApplicationDefined
  1317 #define NSEventTypeCursorUpdate            NSCursorUpdate
  1318 #define NSEventTypeMouseMoved              NSMouseMoved
  1319 #define NSEventTypeLeftMouseDown           NSLeftMouseDown
  1320 #define NSEventTypeRightMouseDown          NSRightMouseDown
  1321 #define NSEventTypeOtherMouseDown          NSOtherMouseDown
  1322 #define NSEventTypeLeftMouseUp             NSLeftMouseUp
  1323 #define NSEventTypeRightMouseUp            NSRightMouseUp
  1324 #define NSEventTypeOtherMouseUp            NSOtherMouseUp
  1325 #define NSEventTypeLeftMouseDragged        NSLeftMouseDragged
  1326 #define NSEventTypeRightMouseDragged       NSRightMouseDragged
  1327 #define NSEventTypeOtherMouseDragged       NSOtherMouseDragged
  1328 #define NSEventTypeScrollWheel             NSScrollWheel
  1329 #define NSEventTypeKeyDown                 NSKeyDown
  1330 #define NSEventTypeKeyUp                   NSKeyUp
  1331 #define NSEventTypeFlagsChanged            NSFlagsChanged
  1332 #define NSEventMaskAny                     NSAnyEventMask
  1333 #define NSEventTypeSystemDefined           NSSystemDefined
  1334 #define NSWindowStyleMaskBorderless        NSBorderlessWindowMask
  1335 #define NSWindowStyleMaskClosable          NSClosableWindowMask
  1336 #define NSWindowStyleMaskFullScreen        NSFullScreenWindowMask
  1337 #define NSWindowStyleMaskMiniaturizable    NSMiniaturizableWindowMask
  1338 #define NSWindowStyleMaskResizable         NSResizableWindowMask
  1339 #define NSWindowStyleMaskTitled            NSTitledWindowMask
  1340 #define NSWindowStyleMaskUtilityWindow     NSUtilityWindowMask
  1341 #define NSAlertStyleCritical               NSCriticalAlertStyle
  1342 #define NSControlSizeRegular               NSRegularControlSize
  1343 #define NSCompositingOperationCopy         NSCompositeCopy
  1344 #define NSTextAlignmentRight               NSRightTextAlignment
  1345 
  1346 /* And adds NSWindowStyleMask.  */
  1347 #ifdef __OBJC__
  1348 typedef NSUInteger NSWindowStyleMask;
  1349 #endif
  1350 
  1351 /* Window tabbing mode enums are new too.  */
  1352 enum NSWindowTabbingMode
  1353   {
  1354     NSWindowTabbingModeAutomatic,
  1355     NSWindowTabbingModePreferred,
  1356     NSWindowTabbingModeDisallowed
  1357   };
  1358 #endif /* !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_12)  */
  1359 
  1360 #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_13)
  1361 /* Deprecated in macOS 10.13.  */
  1362 #define NSPasteboardNameGeneral NSGeneralPboard
  1363 #define NSPasteboardNameDrag NSDragPboard
  1364 #endif
  1365 
  1366 #if !defined (NS_IMPL_COCOA) || !defined (MAC_OS_X_VERSION_10_14)
  1367 /* Deprecated in macOS 10.14.  */
  1368 /* FIXME: Some of these new names, if not all, are actually available
  1369    in some recent version of GNUstep.  */
  1370 #define NSPasteboardTypeString NSStringPboardType
  1371 #define NSPasteboardTypeTabularText NSTabularTextPboardType
  1372 #define NSPasteboardTypeURL NSURLPboardType
  1373 #define NSPasteboardTypeHTML NSHTMLPboardType
  1374 #define NSPasteboardTypePDF NSPDFPboardType
  1375 #define NSPasteboardTypeRTF NSRTFPboardType
  1376 #define NSPasteboardTypeRTFD NSRTFDPboardType
  1377 #define NSPasteboardTypeTIFF NSTIFFPboardType
  1378 #define NSControlStateValueOn NSOnState
  1379 #define NSControlStateValueOff NSOffState
  1380 #define NSBezelStyleRounded NSRoundedBezelStyle
  1381 #define NSButtonTypeMomentaryPushIn NSMomentaryPushInButton
  1382 #endif
  1383 
  1384 extern void mark_nsterm (void);
  1385 
  1386 #endif  /* HAVE_NS */

/* [<][>][^][v][top][bottom][index][help] */